Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

Add option to invoke QEMU with SGX support #111

Open
wants to merge 4 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion kraft/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions kraft/plat/runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
11 changes: 10 additions & 1 deletion scripts/qemu-guest
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -674,6 +675,14 @@ EOF
ARG_APPEND="${OPTARG}"
OPT_APPEND=0
;;
X)
QEMU_ARGS+=("-cpu")
QEMU_ARGS+=("host,+sgx1,+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
Expand Down