You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Then I do run.sh. I'm in a VM now, and need to prepare the env:
export PATH=... # the same as I have on my host
export PYTHONPATH=... # the same as I have on my host
mkdir /dev/sgx/
ln -s /dev/sgx_enclave /dev/sgx/enclave
Now I can test some SGX workload:
# go to helloworld built on host
cd /home/dimakuv/gramineproject/gramine/CI-Examples/helloworld/
gramine-sgx helloworld
To test the dummy device, I need to insmod it:
# build it on host using `make`
cd /home/dimakuv/tmp/device-testing-tools/gramine-device-testing-module
insmod gramine-testing-dev.ko
# now check that the guest VM has it
ls /dev
... gramine_test_dev ...
This is in case your host uses the DCAP driver (which is my case; yes, my kernel is 5.15 which already should have the in-kernel SGX driver, but I use the DCAP driver for well reasons).
If you use DCAP driver, then it should create that file for you, why do you need to create a symlink?
"It" means the VM? Well, it's not created. Why would it be? The kernel inside the VM queries the (virtualized by QEMU/KVM) CPUID, and finds out that SGX is supported, so this guest kernel creates /dev/sgx_enclave.
Now the problem is that I'm using Gramine binaries from the host which were generated against the DCAP OOT driver. So this Gramine is mirrored inside the guest VM, and gramine-sgx expects /dev/sgx/enclave.
This is because in e.g. Debian 12, the config virtio_pci is specified as CONFIG_VIRTIO_PCI=m. Which means that it is a loadable module, not started by default when the Linux kernel starts. And since we're reusing the same Linux kernel inside the guest VM as runs on the host, we end up with a non-virtio-PCI guest kernel. This led to errors like this:
9pnet_virtio: no channels available for device hostfs
mount: mounting hostfs on /hostfs failed: No such file or directory
Kernel panic - not syncing: Attempted to kill init! exitcode=0x0000ff00
Why didn't we catch this error before? Because previously we re-built our own version of the Linux kernel (that was because previous versions of Debian didn't have SGX config at all, so we had to re-build manually). As part of that manual change of the kernel config, we set not only the SGX config but also all the virtio/9p configs to y (load unconditionally and immediately). That meant that even the guest Linux kernel already had everything loaded-in, including virtio_pci.
Now that we updated to a stock Debian 12, we do not re-build the Linux kernel. But now we need to correctly insert all required kernel modules. And that's why we got this error.
What should be done on a clean Debian 12 host
The host must install the relevant kernel modules, to be able to share the file system using 9pnet-virtio protocol and pseudo-device:
Activity
boryspoplawski commentedon Jun 20, 2022
Don't do this. Unstead
adduser username sgxand change group ownership of that file tosgxDon't make your kernel world writable.
chmod o+ris enough.Yeah, adding your user to
kvmgroup is the way.Why do you need these steps???
dimakuv commentedon Jun 20, 2022
This is in case your host uses the DCAP driver (which is my case; yes, my kernel is 5.15 which already should have the in-kernel SGX driver, but I use the DCAP driver for well reasons).
boryspoplawski commentedon Jun 20, 2022
If you use DCAP driver, then it should create that file for you, why do you need to create a symlink?
dimakuv commentedon Jun 20, 2022
"It" means the VM? Well, it's not created. Why would it be? The kernel inside the VM queries the (virtualized by QEMU/KVM) CPUID, and finds out that SGX is supported, so this guest kernel creates
/dev/sgx_enclave.Now the problem is that I'm using Gramine binaries from the host which were generated against the DCAP OOT driver. So this Gramine is mirrored inside the guest VM, and
gramine-sgxexpects/dev/sgx/enclave.boryspoplawski commentedon Jun 20, 2022
Why don't you use OOT driver inside VM?
Don't these drivers differ? Is the only difference really just a different path?
dimakuv commentedon Jun 20, 2022
No, they do not differ (in any way meaningful to Gramine). So the only Gramine-relevant diff is a different path, yes.
boryspoplawski commentedon Jun 20, 2022
Then why don't we have a simple check in Gramine for both paths instead of hardcoding one?
dimakuv commentedon Jan 4, 2023
Just some additional steps, after testing on a clean Ubuntu 22.04:
sudo chmod 0660 /dev/sgx_vepc, so that thesgxgroup users can also spawn SGX-based VMs.dimakuv commentedon Aug 25, 2023
Update notes, found while debugging on Debian 12 and QEMU 7.2.4.
The QEMU run command should be modified like this
Explanations:
loglevel=7and removingquiethelps in debugging the output of Linux kernel boot.readonly=onwithreadonly-- because that's how-virtfsoption works, see here.-device 'virtio-9p-pci ...'because there must be only one option: either-virtfsor the combination of-fsdev -device, see here.sgx-epc.0.node=0-- this is a new thing in QEMU 7.2, it isn't required in e.g. QEMU 6.2The list of loaded kernel modules should be modified like this
This is because in e.g. Debian 12, the config virtio_pci is specified as
CONFIG_VIRTIO_PCI=m. Which means that it is a loadable module, not started by default when the Linux kernel starts. And since we're reusing the same Linux kernel inside the guest VM as runs on the host, we end up with a non-virtio-PCI guest kernel. This led to errors like this:Why didn't we catch this error before? Because previously we re-built our own version of the Linux kernel (that was because previous versions of Debian didn't have SGX config at all, so we had to re-build manually). As part of that manual change of the kernel config, we set not only the SGX config but also all the virtio/9p configs to
y(load unconditionally and immediately). That meant that even the guest Linux kernel already had everything loaded-in, includingvirtio_pci.Now that we updated to a stock Debian 12, we do not re-build the Linux kernel. But now we need to correctly insert all required kernel modules. And that's why we got this error.
What should be done on a clean Debian 12 host
The host must install the relevant kernel modules, to be able to share the file system using
9pnet-virtioprotocol and pseudo-device: