From 87053bff816722fed0eac87af6aa4d7cd1bc6f9a Mon Sep 17 00:00:00 2001 From: Xiangyi Meng Date: Tue, 3 May 2022 18:03:57 +0800 Subject: [PATCH 1/4] const: Add `x86_64-sgx` constant. Signed-off-by: Xiangyi Meng --- kraft/const.py | 1 + 1 file changed, 1 insertion(+) diff --git a/kraft/const.py b/kraft/const.py index 55d796bd..26058e49 100644 --- a/kraft/const.py +++ b/kraft/const.py @@ -168,6 +168,7 @@ UK_CORE_ARCHS = [ 'x86_64', + 'x86_64-sgx' 'arm64', 'arm', ] From 2c570f09eef0f6c4c4a39a7f41c56c7edccbd7bd Mon Sep 17 00:00:00 2001 From: Xiangyi Meng Date: Tue, 3 May 2022 22:02:06 +0800 Subject: [PATCH 2/4] Revert "const: Add `x86_64-sgx` constant." This reverts commit 87053bff816722fed0eac87af6aa4d7cd1bc6f9a. Signed-off-by: Xiangyi Meng --- kraft/const.py | 1 - 1 file changed, 1 deletion(-) diff --git a/kraft/const.py b/kraft/const.py index 26058e49..55d796bd 100644 --- a/kraft/const.py +++ b/kraft/const.py @@ -168,7 +168,6 @@ UK_CORE_ARCHS = [ 'x86_64', - 'x86_64-sgx' 'arm64', 'arm', ] From a280fe894ee14da587341f825cc35d1aad556aac Mon Sep 17 00:00:00 2001 From: Xiangyi Meng Date: Wed, 4 May 2022 15:07:10 +0800 Subject: [PATCH 3/4] app,plat/runner,script/qemu-guest: Add qemu commamd line arguments for SGX Signed-off-by: Xiangyi Meng --- kraft/app/app.py | 5 ++++- kraft/plat/runner/runner.py | 5 +++++ scripts/qemu-guest | 11 ++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/kraft/app/app.py b/kraft/app/app.py index b937beb5..144b14d5 100644 --- a/kraft/app/app.py +++ b/kraft/app/app.py @@ -513,7 +513,7 @@ def init(self, create_makefile=False, force_create=False): def run(self, target=None, initrd=None, background=False, # noqa: C901 paused=False, gdb=4123, dbg=False, virtio_nic=None, bridge=None, interface=None, dry_run=False, args=None, memory=64, cpu_sockets=1, - cpu_cores=1): + cpu_cores=1, epc_size=64): if target is None: raise KraftError('Target not set') @@ -554,6 +554,9 @@ def run(self, target=None, initrd=None, background=False, # noqa: C901 if cpu_cores: runner.set_cpu_cores(cpu_cores) + if epc_size: + runner.add_sgx(epc_size) + for volume in self.config.volumes.all(): if volume.driver is VolumeDriver.VOL_9PFS: path = os.path.join(self.localdir, volume.name) diff --git a/kraft/plat/runner/runner.py b/kraft/plat/runner/runner.py index 0ef9b81b..0562d4e3 100644 --- a/kraft/plat/runner/runner.py +++ b/kraft/plat/runner/runner.py @@ -201,6 +201,11 @@ def set_cpu_cores(self, cpu_cores=None): if cpu_cores and isinstance(cpu_cores, int): self._cmd.extend(('-c', cpu_cores)) + def add_sgx(self, epc_size=None): + if epc_size and isinstance(epc_size, int): + self._cmd.extend(('-X', '%d' % epc_size)) + + def execute(self, extra_args=None, background=False, paused=False, dry_run=False): raise RunnerError('Using undefined runner driver') diff --git a/scripts/qemu-guest b/scripts/qemu-guest index 52f32eaf..c8f48ab0 100755 --- a/scripts/qemu-guest +++ b/scripts/qemu-guest @@ -504,6 +504,7 @@ usage() echo " -k [KERNEL] Enable direct kernel boot with KERNEL" echo " -i [INITRD] Init-ramdisk INITRD for -k" echo " -a [ARGUMENTS] Kernel arguments for -k" + echo " -X [SGX-EPC-SIZE] Enable Intel SGX and set EPC size" echo " -l Enable virtio-balloon" echo " -r Enable virtio-rng" echo " -C Do not terminate guest with CTRL-C" @@ -520,7 +521,7 @@ usage() echo " $0 -c 2 -m 2048 -b virbr0 -b virbr1 -q root.qcow2 -d /dev/sdb -d /dev/sdc" } -while getopts :hnN:b:V:f:G:d:q:S:I:e:k:i:a:c:m:v:lrs:p:HxCDG:g:PT:WQ:M:t: OPT; do +while getopts :hnN:b:V:f:G:d:q:S:I:e:k:i:a:X:c:m:v:lrs:p:HxCDG:g:PT:WQ:M:t: OPT; do case ${OPT} in v) OPT_VIDEOVNC=0 @@ -674,6 +675,14 @@ EOF ARG_APPEND="${OPTARG}" OPT_APPEND=0 ;; + X) + QEMU_ARGS+=("-cpu") + QEMU_ARGS+=("host,+sgx-provisionkey") + QEMU_ARGS+=("-object") + QEMU_ARGS+=("memory-backend-epc,id=mem1,size=${OPTARG}M,prealloc=on") + QEMU_ARGS+=("-M") + QEMU_ARGS+=("sgx-epc.0.memdev=mem1,sgx-epc.0.node=0") + ;; p) ARG_VCPUPIN=$( _expand_num_list "${OPTARG}" ) if [ $? -ne 0 -o -z "${ARG_VCPUPIN}" ]; then From 28fe574f2b798067372770983e9f8282dd67445e Mon Sep 17 00:00:00 2001 From: Xiangyi Meng Date: Thu, 2 Jun 2022 13:42:12 +0800 Subject: [PATCH 4/4] scrippts/qemu-guest: add `+sgx1` cpu option to qemu-sgx Signed-off-by: Xiangyi Meng --- scripts/qemu-guest | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/qemu-guest b/scripts/qemu-guest index c8f48ab0..a121d246 100755 --- a/scripts/qemu-guest +++ b/scripts/qemu-guest @@ -677,7 +677,7 @@ EOF ;; X) QEMU_ARGS+=("-cpu") - QEMU_ARGS+=("host,+sgx-provisionkey") + QEMU_ARGS+=("host,+sgx1,+sgx-provisionkey") QEMU_ARGS+=("-object") QEMU_ARGS+=("memory-backend-epc,id=mem1,size=${OPTARG}M,prealloc=on") QEMU_ARGS+=("-M")