From 95d14671170a714570d5fc956511867631acfabe Mon Sep 17 00:00:00 2001 From: "Sean T. Allen" Date: Thu, 24 Sep 2020 13:49:23 +0000 Subject: [PATCH 1/3] Remove unneeded init_clock_res Closes #816 --- sgx-lkl-musl | 2 +- src/enclave/enclave_init.c | 6 ++---- user/enter.c | 2 -- user/userargs.h | 3 --- 4 files changed, 3 insertions(+), 10 deletions(-) diff --git a/sgx-lkl-musl b/sgx-lkl-musl index cd8ba32e1..fce48dab7 160000 --- a/sgx-lkl-musl +++ b/sgx-lkl-musl @@ -1 +1 @@ -Subproject commit cd8ba32e13cb1c75945e972fcf417463949e79bd +Subproject commit fce48dab72992e801747cbd1566a792f471fad76 diff --git a/src/enclave/enclave_init.c b/src/enclave/enclave_init.c index 4c1df4805..c1efe1fd8 100644 --- a/src/enclave/enclave_init.c +++ b/src/enclave/enclave_init.c @@ -131,7 +131,6 @@ static void _enter_user_space( args.num_ethreads = num_ethreads; args.sw_debug_mode = sgxlkl_in_sw_debug_mode(); args.__gdb_load_debug_symbols_alive_ptr = &__gdb_load_debug_symbols_alive; - memcpy(args.clock_res, clock_res, sizeof(args.clock_res)); (*proc)(&args, sizeof(args)); } @@ -245,14 +244,13 @@ int __libc_init_enclave(int argc, char** argv) tmp[i].tv_sec = hex_to_int(cfg->clock_res[i].resolution, 8); tmp[i].tv_nsec = hex_to_int(cfg->clock_res[i].resolution + 8, 8); } - init_clock_res(tmp); size_t max_lthreads = cfg->max_user_threads * sizeof(*__scheduler_queue.buffer); max_lthreads = next_power_of_2(max_lthreads); newmpmcq(&__scheduler_queue, max_lthreads, 0); - + init_ethread_tp(); size_t espins = cfg->espins; @@ -262,7 +260,7 @@ int __libc_init_enclave(int argc, char** argv) SGXLKL_VERBOSE("calling _lthread_sched_init()\n"); _lthread_sched_init(cfg->stacksize); - + /* Run startmain() in a new lthread */ { static startmain_args_t args; diff --git a/user/enter.c b/user/enter.c index 8ab196045..62f4966a4 100644 --- a/user/enter.c +++ b/user/enter.c @@ -72,8 +72,6 @@ void sgxlkl_user_enter(sgxlkl_userargs_t* args, size_t args_size) init_sysconf(args->num_ethreads, args->num_ethreads); - init_clock_res((struct timespec*)args->clock_res); - __init_libc(args->argv + args->argc + 1, args->argv[0]); __libc_start_init(); _barrier(); diff --git a/user/userargs.h b/user/userargs.h index 818aa8122..ed42a07d0 100644 --- a/user/userargs.h +++ b/user/userargs.h @@ -36,9 +36,6 @@ typedef struct sgxlkl_userargs const void* elf64_hdr; size_t num_ethreads; - /* to be passed to init_clock_res() */ - struct sgxlkl_user_timespec clock_res[8]; - /* where in debug mode or not */ bool sw_debug_mode; From 9a5570e22dc072c4582e1f762cbfb9b4c2fd86a2 Mon Sep 17 00:00:00 2001 From: "Sean T. Allen" Date: Thu, 24 Sep 2020 17:54:07 +0000 Subject: [PATCH 2/3] Remove from config --- src/enclave/enclave_init.c | 15 +----- src/main-oe/serialize_enclave_config.c | 17 +------ src/main-oe/sgxlkl_run_oe.c | 29 ------------ src/shared/sgxlkl_enclave_config.c | 17 ++----- .../create/enclave-config-complete-ref.json | 26 ---------- tools/schemas/enclave-config.schema.json | 47 ------------------- 6 files changed, 6 insertions(+), 145 deletions(-) diff --git a/src/enclave/enclave_init.c b/src/enclave/enclave_init.c index c1efe1fd8..f601bf6b8 100644 --- a/src/enclave/enclave_init.c +++ b/src/enclave/enclave_init.c @@ -105,8 +105,7 @@ static void _enter_user_space( int argc, char** argv, void* stack, - size_t num_ethreads, - struct timespec clock_res[4]) + size_t num_ethreads) { extern void* __oe_get_isolated_image_entry_point(void); extern const void* __oe_get_isolated_image_base(); @@ -139,7 +138,6 @@ typedef struct startmain_args { int argc; char** argv; - struct timespec clock_res[8]; } startmain_args_t; @@ -164,8 +162,7 @@ static int app_main_thread(void* args_) args->argc, args->argv, &sgxlkl_enclave_state.elf64_stack, - sgxlkl_enclave_state.config->ethreads, - args->clock_res); + sgxlkl_enclave_state.config->ethreads); #else /* Launch stage 3 dynamic linker, passing in top of stack to overwrite. * The dynamic linker will then load the application proper; here goes! */ @@ -238,13 +235,6 @@ int __libc_init_enclave(int argc, char** argv) init_sysconf(cfg->ethreads, cfg->ethreads); - struct timespec tmp[8] = {0}; - for (size_t i = 0; i < 8; i++) - { - tmp[i].tv_sec = hex_to_int(cfg->clock_res[i].resolution, 8); - tmp[i].tv_nsec = hex_to_int(cfg->clock_res[i].resolution + 8, 8); - } - size_t max_lthreads = cfg->max_user_threads * sizeof(*__scheduler_queue.buffer); max_lthreads = next_power_of_2(max_lthreads); @@ -266,7 +256,6 @@ int __libc_init_enclave(int argc, char** argv) static startmain_args_t args; args.argc = argc; args.argv = argv; - memcpy(args.clock_res, tmp, sizeof(args.clock_res)); if (lthread_create(<, NULL, kernel_main_thread, &args) != 0) sgxlkl_fail("Failed to create lthread for kernel_main_thread()\n"); diff --git a/src/main-oe/serialize_enclave_config.c b/src/main-oe/serialize_enclave_config.c index 2943c2913..4cf735fee 100644 --- a/src/main-oe/serialize_enclave_config.c +++ b/src/main-oe/serialize_enclave_config.c @@ -136,20 +136,6 @@ static json_obj_t* encode_string_array( return res; } -static json_obj_t* encode_clock_res( - const char* key, - const sgxlkl_clock_res_config_t* clock_res) -{ - json_obj_t* res = create_json_array(key, 8); - for (size_t i = 0; i < 8; i++) - { - res->array[i] = create_json_objects(NULL, 1); - res->array[i]->objects[0] = - create_json_string("resolution", clock_res[i].resolution); - } - return res; -} - static json_obj_t* encode_root( const char* key, const sgxlkl_enclave_root_config_t* root) @@ -449,7 +435,7 @@ void serialize_enclave_config( // Catch modifications to sgxlkl_enclave_config_t early. If this fails, // the code above/below needs adjusting for the added/removed settings. _Static_assert( - sizeof(sgxlkl_enclave_config_t) == 464, + sizeof(sgxlkl_enclave_config_t) == 328, "sgxlkl_enclave_config_t size has changed"); #define FPFBOOL(N) root->objects[cnt++] = encode_boolean(#N, config->N) @@ -484,7 +470,6 @@ void serialize_enclave_config( FPFU64(espins); FPFU64(esleep); FPFU64(ethreads); - root->objects[cnt++] = encode_clock_res("clock_res", config->clock_res); FPFBOOL(fsgsbase); FPFBOOL(verbose); diff --git a/src/main-oe/sgxlkl_run_oe.c b/src/main-oe/sgxlkl_run_oe.c index e30cb84ad..9de35eb76 100644 --- a/src/main-oe/sgxlkl_run_oe.c +++ b/src/main-oe/sgxlkl_run_oe.c @@ -792,34 +792,6 @@ void get_libsgxlkl_user_path(char* path_buf, size_t len) find_lib("libsgxlkl-user.so", path_buf, len); } -void mk_clock_res_string(int clock) -{ - sgxlkl_enclave_config_t* econf = &sgxlkl_host_state.enclave_config; - size_t sz = sizeof(sgxlkl_clock_res_config_t); - struct timespec tmpt; - char tmps[8 * 2 * 2 + 1]; - clock_getres(clock, &tmpt); - snprintf(tmps, sizeof(tmps), "%08lx%08lx", tmpt.tv_sec, tmpt.tv_nsec); - memcpy(econf->clock_res[clock].resolution, tmps, sz); -} - -void set_clock_res(bool have_enclave_config) -{ - /* The enclave config file has a specified default for these settings, - * so we auto-detect them only if we don't have an enclave config file. - */ - - if (!have_enclave_config) - { - mk_clock_res_string(CLOCK_REALTIME); - mk_clock_res_string(CLOCK_MONOTONIC); - mk_clock_res_string(CLOCK_MONOTONIC_RAW); - mk_clock_res_string(CLOCK_REALTIME_COARSE); - mk_clock_res_string(CLOCK_MONOTONIC_COARSE); - mk_clock_res_string(CLOCK_BOOTTIME); - } -} - static void rdfsbase_sigill_handler(int sig, siginfo_t* si, void* data) { rdfsbase_caused_sigill = 1; @@ -1883,7 +1855,6 @@ int main(int argc, char* argv[], char* envp[]) econf->kernel_cmd); bool have_enclave_config_file = enclave_config_path != NULL; - set_clock_res(have_enclave_config_file); sgxlkl_host_state.shared_memory.env = envp; set_tls(have_enclave_config_file); register_hds(root_hd); diff --git a/src/shared/sgxlkl_enclave_config.c b/src/shared/sgxlkl_enclave_config.c index df49bfea4..4cda4bfc6 100644 --- a/src/shared/sgxlkl_enclave_config.c +++ b/src/shared/sgxlkl_enclave_config.c @@ -301,7 +301,7 @@ static json_result_t json_read_callback( else if (MATCH("wg.peers")) ALLOC_ARRAY( wg.num_peers, wg.peers, sgxlkl_enclave_wg_peer_config_t); - else if (!(MATCH("clock_res"))) + else FAIL("unknown json array '%s'\n", make_path(parser)); break; case JSON_REASON_END_ARRAY: @@ -359,17 +359,6 @@ static json_result_t json_read_callback( JU64("espins", cfg->espins); JU64("esleep", cfg->esleep); - JPATHT("clock_res.resolution", JSON_TYPE_STRING, { - if (strlen(un->string) != 16) - FAIL("invalid length of value for clock_res item"); - i = json_get_array_index(parser); - if (i == -1) - FAIL("invalid array index\n"); - if (i >= 8) - FAIL("too many values for clock_res"); - memcpy(&cfg->clock_res[i].resolution, un->string, 17); - }); - JPATHT("mode", JSON_TYPE_STRING, { cfg->mode = string_to_sgxlkl_enclave_mode_t(un->string); }); @@ -481,7 +470,7 @@ void sgxlkl_read_enclave_config( // Catch modifications to sgxlkl_enclave_config_t early. If this fails, // the code above/below needs adjusting for the added/removed settings. _Static_assert( - sizeof(sgxlkl_enclave_config_t) == 464, + sizeof(sgxlkl_enclave_config_t) == 328, "sgxlkl_enclave_config_t size has changed"); if (!from) @@ -589,4 +578,4 @@ void sgxlkl_free_enclave_config(sgxlkl_enclave_config_t* config) bool is_encrypted(sgxlkl_enclave_mount_config_t* cfg) { return cfg->key || cfg->key_id || cfg->fresh_key; -} \ No newline at end of file +} diff --git a/tests/tools/sgx-lkl-cfg/create/enclave-config-complete-ref.json b/tests/tools/sgx-lkl-cfg/create/enclave-config-complete-ref.json index 1c48f1d14..008fc1c15 100644 --- a/tests/tools/sgx-lkl-cfg/create/enclave-config-complete-ref.json +++ b/tests/tools/sgx-lkl-cfg/create/enclave-config-complete-ref.json @@ -41,32 +41,6 @@ "max_user_threads": 256, "espins": 500, "esleep": 16000, - "clock_res": [ - { - "resolution": "0000000000000001" - }, - { - "resolution": "0000000000000001" - }, - { - "resolution": "0000000000000000" - }, - { - "resolution": "0000000000000000" - }, - { - "resolution": "0000000000000001" - }, - { - "resolution": "00000000003d0900" - }, - { - "resolution": "00000000003d0900" - }, - { - "resolution": "0000000000000001" - } - ], "stacksize": 524288, "mmap_files": "shared", "oe_heap_pagecount": 8192, diff --git a/tools/schemas/enclave-config.schema.json b/tools/schemas/enclave-config.schema.json index 9bfd78628..ec5d3f02d 100644 --- a/tools/schemas/enclave-config.schema.json +++ b/tools/schemas/enclave-config.schema.json @@ -81,18 +81,6 @@ "EXIT_STATUS_NONE" ] }, - "sgxlkl_clock_res_config_t": { - "type": "object", - "properties": { - "resolution": { - "type": "string", - "minLength": 16, - "maxLength": 16, - "pattern": "^[0-9A-Fa-f]+$", - "default": "0000000000000000" - } - } - }, "sgxlkl_enclave_mount_config_t": { "type": "object", "description": "Disk configuration", @@ -394,41 +382,6 @@ "default": 16000, "overridable": "SGXLKL_ESLEEP" }, - "clock_res": { - "type": "array", - "description": "", - "minLength": 8, - "maxLength": 8, - "items": { - "$ref": "#/definitions/sgxlkl_clock_res_config_t" - }, - "default": [ - { - "resolution": "0000000000000001" - }, - { - "resolution": "0000000000000001" - }, - { - "resolution": "0000000000000000" - }, - { - "resolution": "0000000000000000" - }, - { - "resolution": "0000000000000001" - }, - { - "resolution": "00000000003d0900" - }, - { - "resolution": "00000000003d0900" - }, - { - "resolution": "0000000000000001" - } - ] - }, "stacksize": { "$ref": "#/definitions/safe_size_t", "description": "Stack size of in-enclave user-level threads.", From 267b65bc903c4928a691dce6aec6ea32838d5ae3 Mon Sep 17 00:00:00 2001 From: "Sean T. Allen" Date: Mon, 28 Sep 2020 12:31:53 +0000 Subject: [PATCH 3/3] Bump sgx-lkl-musl --- sgx-lkl-musl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sgx-lkl-musl b/sgx-lkl-musl index fce48dab7..1673c3e1b 160000 --- a/sgx-lkl-musl +++ b/sgx-lkl-musl @@ -1 +1 @@ -Subproject commit fce48dab72992e801747cbd1566a792f471fad76 +Subproject commit 1673c3e1b6f8fb162ce60bebcd7869ff1a0b1f04