Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unneeded init_clock_res #835

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion sgx-lkl-musl
21 changes: 4 additions & 17 deletions src/enclave/enclave_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -131,7 +130,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));
}
Expand All @@ -140,7 +138,6 @@ typedef struct startmain_args
{
int argc;
char** argv;
struct timespec clock_res[8];
}
startmain_args_t;

Expand All @@ -165,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! */
Expand Down Expand Up @@ -239,20 +235,12 @@ 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);
}
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;
Expand All @@ -262,13 +250,12 @@ 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;
args.argc = argc;
args.argv = argv;
memcpy(args.clock_res, tmp, sizeof(args.clock_res));

if (lthread_create(&lt, NULL, kernel_main_thread, &args) != 0)
sgxlkl_fail("Failed to create lthread for kernel_main_thread()\n");
Expand Down
17 changes: 1 addition & 16 deletions src/main-oe/serialize_enclave_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
29 changes: 0 additions & 29 deletions src/main-oe/sgxlkl_run_oe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 3 additions & 14 deletions src/shared/sgxlkl_enclave_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
}
26 changes: 0 additions & 26 deletions tests/tools/sgx-lkl-cfg/create/enclave-config-complete-ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
47 changes: 0 additions & 47 deletions tools/schemas/enclave-config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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.",
Expand Down
2 changes: 0 additions & 2 deletions user/enter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 0 additions & 3 deletions user/userargs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down