This topic describes how to build a confidential computing environment on ECS instances that use Hygon China Secure Virtualization (CSV) technology, called CSV instances. It also demonstrates how to run sample code to verify the CSV feature.
Background information
Hygon China Secure Virtualization (CSV) is an ECS protection technology based on Hygon CPU hardware. The runtime state of a CSV instance, such as memory data, is encrypted and protected by the CPU hardware. Neither cloud providers nor external attackers can monitor or tamper with the internal runtime state of a CSV instance, such as running processes and sensitive data. For more information about Hygon CSV technology, see Hygon Arch.
Hygon CSV provides default security protection for your instances and applications. You can migrate existing applications directly to CSV instances to benefit from CSV protection without redevelopment.
Create a CSV instance
Currently, only the g7h instance family supports the CSV feature. For more information, see g7h general-purpose instance family.
Console
Creating a CSV instance on the console is similar to creating a regular one, but involves a few specific settings. For information about other general configurations, see Create an instance by using the wizard.
Go to ECS console - Instances.
In the upper-left corner of the page, select a region and resource group.
-
Click Create Instance and configure the instance with the following settings.
Parameter
Description
Instance type
Only the following g7h instance types support the CSV feature.
-
ecs.g7h.2xlarge
-
Known issues with the Linux guest kernel SWIOTLB buffer:
-
Less memory is visible to the OS compared to a regular instance. A TDX instance reserves unencrypted memory (SWIOTLB) for peripheral communication. By default, this area is 6% of available memory, up to 1 GiB.
-
Attaching multiple elastic network interfaces (ENIs) to a large instance may cause a crash due to insufficient SWIOTLB memory in multi-queue network card scenarios. Stop the instance on the console and detach ENIs to recover.
-
High-I/O workloads may experience performance degradation from insufficient SWIOTLB. Check with:
dmesg| grep 'swiotlb buffer is full'ImportantIncorrect SWIOTLB settings may cause boot failure. Create a snapshot before proceeding so you can roll back if errors occur.
If this issue occurs, increase the SWIOTLB size:
-
Set the SWIOTLB size to 1 GiB.
grubby --update-kernel=ALL --args=swiotlb=524288 -
For kernel versions later than
5.10.134-18.al8.x86_64, add theanyparameter to support larger SWIOTLB sizes:grubby --update-kernel=ALL --args=swiotlb=2097152,any # Sets SWIOTLB to 4 GiB.NoteCalculate the SWIOTLB parameter value: Target size (in MiB) × 512. See The kernel's command-line parameters.
-
-
-
ecs.g7h.4xlarge
-
ecs.g7h.8xlarge
-
ecs.g7h.16xlarge
Image
Select the Confidential VM checkbox, and then select the Alibaba Cloud Linux 3.2104 LTS 64-bit image.
-
-
Follow the on-screen instructions to finish creating the instance.
API
You can call the RunInstances operation to create an instance. The following table describes the key parameters.
|
Parameter |
Description |
Example |
|
InstanceType |
Select an instance type that supports the CSV feature. The currently supported instance types are:
|
ecs.g7h.2xlarge |
|
ImageId |
Specify the ID of an image that is supported by CSV instances. Currently, only the following image is supported: Alibaba Cloud Linux 3.2104 LTS 64-bit UEFI edition. |
aliyun_3_x64_20G_alibase_20241218.vhd |
|
SecurityOptions.ConfidentialComputingMode |
Set the confidential computing mode. |
CSV |
Verify CSV status
Before you use the CSV confidential computing environment, we recommend that you verify that CSV is enabled.
-
Check if the CSV feature is enabled.
Using MSR
You can check whether the CSV feature is enabled by accessing the CSV_STATUS model-specific register (MSR) at
0xC0010131. This MSR is read-only, and the hypervisor cannot intercept access to it. Run the following commands to perform the check:sudo yum install msr-tools sudo rdmsr 0xC0010131 --bitfield 1:0The following output indicates that the CSV feature is enabled.
[test@iZbp1asmdfbcxxx ~]$ sudo rdmsr 0xC0010131 --bitfield 1:0 1Using the kernel log
For an instance with the CSV feature enabled, the kernel prints a corresponding log entry after the check is complete. You can run the following command to check the log:
dmesg | grep SEVThe following output indicates that the CSV feature is enabled.
[test@iZbp1asmdfc3k4 ~]$ dmesg | grep SEV [ 0.931869] Memory Encryption Features active:AMD SEV -
Check if the CSV-related drivers are installed.
sudo modprobe csv-guest ls -l /dev/csv-guestThe following output indicates that the CSV-related drivers are installed.
[test@iZbp1asmdfbc ~]$ sudo modprobe csv-guest [test@iZbp1asmdfbc ~]$ ls -l /dev/csv-guest crwxrwxrwx 1 root root 10, 125 Jul 31 15:09 /dev/csv-guest
Build and verify the CSV environment
Typically, applications that run in non-CSV environments can be migrated directly to a CSV instance without redevelopment. To fully benefit from the enhanced security of CSV, Alibaba Cloud recommends using the confidential virtual machine features described below.
A CSV attestation report is a data structure that represents the identity of a CSV instance and is generated directly by the Hygon Platform Security Processor (PSP). It contains key information, such as the instance's policy (POLICY), user-defined data (UserData), and virtual machine digest (DIGEST). Its integrity is protected by cryptographic mechanisms. Alibaba Cloud provides a sample tool for you to quickly generate and verify a CSV attestation report.
-
Download the remote attestation sample tool provided by Alibaba Cloud.
wget https://enclave-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/csv/requirements.txt wget https://enclave-cn-hangzhou.oss-cn-hangzhou.aliyuncs.com/csv/csv-attestation.py sudo pip3 install -r requirements.txt chmod +x ./csv-attestation.pyThe following output indicates that the remote attestation sample tool is installed.
[test@iZbp1asmdfbc3k ~]$ sudo pip3 install -r requirements.txt WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead. Requirement already satisfied: requests==2.20.0 in /usr/lib/python3.6/site-packages (from -r requirements.txt (line 1)) Collecting snowland_smx==0.3.1 (from -r requirements.txt (line 2)) Downloading http://mirrors.cloud.aliyuncs.com/pypi/packages/2c/61/f59f0d18b2f305473d6f62550bf668610936f34dc908daf25b1a9237846/snowland_smx-0.3.1-py3-none-any.whl Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/lib/python3.6/site-packages (from requests==2.20.0->-r requirements.txt (line 1)) Requirement already satisfied: idna<2.8,>=2.5 in /usr/lib/python3.6/site-packages (from requests==2.20.0->-r requirements.txt (line 1)) Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/lib/python3.6/site-packages (from requests==2.20.0->-r requirements.txt (line 1)) Installing collected packages: snowland-smx Successfully installed snowland-smx-0.3.1 -
Generate an attestation report for the local instance.
sudo ./csv-attestation.py generate -r ./The following output indicates that the attestation report is successfully saved to the
reportfile in the current directory.[test@iZbp1asmdfbc3k ~]$ sudo ./csv-attestation.py generate -r ./ Attestation report is written to ./report successfully! -
Verify the attestation report.
sudo ./csv-attestation.py verify -r ./reportThe following output is an example. In the
POLICYfield,NODEBUGindicates that the CSV instance is not in debugging mode, andNOKSindicates that the VM's encryption key is exclusive to this instance, indicating a secure, protected mode.[test@iZbp1asmdfbc xxx ~]$ sudo ./csv-attestation.py verify -r ./report ****Verified Attestation Report**** { "PUBKEY_DIGEST": "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "ID": "0000000000000000000000000000", "Version": "00000000000000000000000000000000", "Userdata": "944565eb3160b54d01a346a4d69270393fff543cf903d5ff59b89c8b9027b1410715f322ae2de32799ffa3c52fed4eee272028d1696dbc8f5e", "MNONCE": "666264ff98529ce36e89e2dcxxx", "DIGEST_HEX": "ef0cf845ba33e913b9bf6ce0dbda6750b1f134c8e9966d725eaa8xxx", "CHIP_ID": "THSU67001xxx", "POLICY": "NODEBUG || NOKS || HSK_VERSION-0x0 || CEK_VERSION-0x0 || API_MAJOR-0x0 || API_MINOR-0x0 || API_MINOR-0x0" } -
Generate an attestation report with specific UserData.
When you generate an attestation report, you can specify the
UserDatato include custom data in the report.sudo ./csv-attestation.py generate -r ./ -u your-data-like-pubkey-digest[test@iZbp1asmdfbc3k ~ ~]$ sudo ./csv-attestation.py generate -r ./ -u your-data-like-pubkey-digest Attestation report is written to ./report successfully! [test@iZbp1asmdfbc3k ~ ~]$ sudo ./csv-attestation.py verify -r ./report ****Verified Attestation Report**** { "PUBKEY_DIGEST": "000000000000000000000000000000000000000000000000000000000000000000", "ID": "00000000000000000000000000", "Version": "00000000000000000000000000000000", "Userdata": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx796f75722d646174612d6c696b652d7075622b6b65792d646966696", "MNONCE": "3e1084e25ef82dc34ff34fe0xxx", "DIGEST_HEX": "ef0cf845ba33e913b9bf6ce0dbda6750b1f134c8e99066d725eaa8d561xxx", "CHIP_ID": "THSU670012xxx", "POLICY": "NODEBUG || NOKS || HSK_VERSION-0x0 || CEK_VERSION-0x0 || API_MAJOR-0x0 || API_MINOR-0x0 || API_MINOR-0x0" }
Known limitations
-
When the CSV feature is enabled, the CPU hardware encrypts memory data. This may cause performance degradation compared to regular ECS instances.
-
Image limitations:
-
Only the Alibaba Cloud Linux 3.2104 LTS 64-bit UEFI edition image is supported, and the kernel version must be 5.10.134-16.al8.x86_64 or later.
-
Windows is not currently supported.
-