Skip to content

Commit

Permalink
Add syslog level configuration and add info logs during startup
Browse files Browse the repository at this point in the history
Syslog level can be specified either via --syslog-level command line
option or SyslogLevel in the JSON configuration.

Signed-off-by: Vikas Tikoo <vikasamar@gmail.com>
  • Loading branch information
vtikoo committed Sep 28, 2022
1 parent f402040 commit 6654c6f
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 7 deletions.
1 change: 1 addition & 0 deletions include/myst/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typedef struct myst_options
myst_fork_mode_t fork_mode;
myst_host_enc_uid_gid_mappings host_enc_uid_gid_mappings;
myst_strace_config_t strace_config;
int syslog_level;
} myst_options_t;

typedef struct myst_final_options
Expand Down
16 changes: 11 additions & 5 deletions kernel/enter.c
Original file line number Diff line number Diff line change
Expand Up @@ -757,11 +757,15 @@ int myst_enter_kernel(myst_kernel_args_t* args)
__myst_kernel_args = *args;
args = &__myst_kernel_args;

/* set the syslog level, depending on whether in TEE debug mode */
if (args->tee_debug_mode)
args->syslog_level = LOG_DEBUG;
else
args->syslog_level = LOG_NOTICE;
/* If no syslog level config was specified set defaults depending on whether
* in TEE debug mode */
if (args->syslog_level == -1)
{
if (args->tee_debug_mode)
args->syslog_level = LOG_DEBUG;
else
args->syslog_level = LOG_NOTICE;
}

/* turn off or reduce various options when TEE is not in debug mode */
if (!args->tee_debug_mode)
Expand Down Expand Up @@ -798,6 +802,8 @@ int myst_enter_kernel(myst_kernel_args_t* args)
if (myst_setup_mman(args->mman_data, args->mman_size) != 0)
ERAISE(-EINVAL);

MYST_ILOG("Entered Mystikos kernel.");

/* call global constructors within the kernel */
myst_call_init_functions();

Expand Down
1 change: 1 addition & 0 deletions kernel/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,7 @@ int myst_exec(
if (callback)
(*callback)(callback_arg);

MYST_ILOG("Entering CRT.");
/* enter the C-runtime on the target thread descriptor */
(*enter)(sp, dynv, myst_syscall, crt_args);

Expand Down
28 changes: 28 additions & 0 deletions tools/myst/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <myst/kernel.h>
#include <myst/round.h>
#include <stdlib.h>
#include <syslog.h>
#include <unistd.h>

#include "config.h"
Expand Down Expand Up @@ -432,6 +433,32 @@ static json_result_t _json_read_callback(
else
CONFIG_RAISE(JSON_TYPE_MISMATCH);
}
else if (json_match(parser, "SyslogLevel") == JSON_OK)
{
if (type == JSON_TYPE_STRING)
{
if (strcmp(un->string, "emerg") == 0)
parsed_data->syslog_level = LOG_EMERG;
else if (strcmp(un->string, "alert") == 0)
parsed_data->syslog_level = LOG_ALERT;
else if (strcmp(un->string, "crit") == 0)
parsed_data->syslog_level = LOG_CRIT;
else if (strcmp(un->string, "err") == 0)
parsed_data->syslog_level = LOG_ERR;
else if (strcmp(un->string, "warning") == 0)
parsed_data->syslog_level = LOG_WARNING;
else if (strcmp(un->string, "notice") == 0)
parsed_data->syslog_level = LOG_NOTICE;
else if (strcmp(un->string, "info") == 0)
parsed_data->syslog_level = LOG_INFO;
else if (strcmp(un->string, "debug") == 0)
parsed_data->syslog_level = LOG_DEBUG;
else
CONFIG_RAISE(JSON_UNKNOWN_VALUE);
}
else
CONFIG_RAISE(JSON_TYPE_MISMATCH);
}
else
{
// Ignore everything we dont understand
Expand Down Expand Up @@ -513,6 +540,7 @@ int parse_config(config_parsed_data_t* parsed_data)
parsed_data->oe_num_stack_pages = ENCLAVE_STACK_SIZE / PAGE_SIZE;
parsed_data->oe_create_zero_base = ENCLAVE_CREATE_ZERO_BASE_ENCLAVE;
parsed_data->oe_start_address = ENCLAVE_START_ADDRESS;
parsed_data->syslog_level = -1;
}

if ((ret = json_parser_init(
Expand Down
1 change: 1 addition & 0 deletions tools/myst/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ typedef struct _config_parsed_data_t
bool exec_stack;
bool unhandled_syscall_enosys;
bool host_uds;
int syslog_level;

size_t main_stack_size;
size_t thread_stack_size;
Expand Down
5 changes: 3 additions & 2 deletions tools/myst/enc/enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ static uint64_t _forward_exception_as_signal_to_kernel(
// convention as myst_handle_host_signal is expected to be called
oe_context->rsp = (rsp & -16) - 8;
oe_context->rbp = rbp;
oe_context->rdi = (__typeof(oe_context->rdi))&siginfo;
oe_context->rsi = (__typeof(oe_context->rsi))&mcontext;
oe_context->rdi = (__typeof(oe_context->rdi)) & siginfo;
oe_context->rsi = (__typeof(oe_context->rsi)) & mcontext;

return OE_EXCEPTION_CONTINUE_EXECUTION;
}
Expand Down Expand Up @@ -694,6 +694,7 @@ static long _enter(void* arg_)
: MYST_PROCESS_INIT_STACK_SIZE;
_kargs.thread_stack_size = final_options.base.thread_stack_size;
_kargs.host_uds = final_options.base.host_uds;
_kargs.syslog_level = final_options.base.syslog_level;

/* whether user-space FSGSBASE instructions are supported */
_kargs.have_fsgsbase_instructions =
Expand Down
9 changes: 9 additions & 0 deletions tools/myst/host/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ Options:\n\
from the output. Can be used in conjunction with any of the above filters \n\
E.g: To filter by pid=101, specify - \n\
--strace-filter-pid=101\n\
--syslog-level=<emerg|alert|crit|err|warning|notice|info|debug>\n\
\n"

int exec_action(int argc, const char* argv[], const char* envp[])
Expand Down Expand Up @@ -575,6 +576,14 @@ int exec_action(int argc, const char* argv[], const char* envp[])
return 1;
}

if (get_syslog_level_opts(&argc, argv, &options.syslog_level) != 0)
_err(
"%s: invalid --syslog-level option. Should be one of - "
"\"emerg\", "
"\"alert\", \"crit\", \"err\", \"warning\", \"notice\", "
"\"info\", \"debug\".",
argv[0]);

/* Get MYST_MEMCHECK environment variable */
{
const char* env;
Expand Down
9 changes: 9 additions & 0 deletions tools/myst/host/exec_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ Options:\n\
from the output. Can be used in conjunction with any of the above filters \n\
E.g: To filter by pid=101, specify - \n\
--strace-filter-pid=101\n\
--syslog-level=<emerg|alert|crit|err|warning|notice|info|debug>\n\
\n\
"

Expand Down Expand Up @@ -204,6 +205,13 @@ static void _get_options(
"supported\n",
argv[0]);

if (get_syslog_level_opts(argc, argv, &opts->syslog_level) != 0)
_err(
"%s: invalid --syslog-level option. Should be one of - \"emerg\", "
"\"alert\", \"crit\", \"err\", \"warning\", \"notice\", \"info\", "
"\"debug\".",
argv[0]);

/* Get --max-affinity-cpus */
{
const char* arg = NULL;
Expand Down Expand Up @@ -542,6 +550,7 @@ static int _enter_kernel(
kernel_args.exec_stack = final_options.base.exec_stack;
kernel_args.perf = final_options.base.perf;
kernel_args.host_uds = final_options.base.host_uds;
kernel_args.syslog_level = final_options.base.syslog_level;

/* check whether FSGSBASE instructions are supported */
if (test_user_space_fsgsbase() == 0)
Expand Down
60 changes: 60 additions & 0 deletions tools/myst/host/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <syslog.h>
#include <unistd.h>

#include <myst/args.h>
Expand Down Expand Up @@ -302,3 +303,62 @@ int get_fork_mode_opts(

return 0;
}

/* if --syslog-level=<arg> option present and arg is one of the valid values - 0
* through 7, returns 0 and sets the syslog_level pointer. For other values of
* arg, returns -1. If --syslog-level option not present, sets syslog_level to
* -1.
*/
int get_syslog_level_opts(int* argc, const char* argv[], int* syslog_level)
{
const char* arg = NULL;

if (syslog_level == 0)
return -1;

*syslog_level = -1;

if (cli_getopt(argc, argv, "--syslog-level", &arg) == 0)
{
if (arg == NULL)
return -1;

if (strcmp(arg, "emerg") == 0)
{
*syslog_level = LOG_EMERG;
}
else if (strcmp(arg, "alert") == 0)
{
*syslog_level = LOG_ALERT;
}
else if (strcmp(arg, "crit") == 0)
{
*syslog_level = LOG_CRIT;
}
else if (strcmp(arg, "err") == 0)
{
*syslog_level = LOG_ERR;
}
else if (strcmp(arg, "warning") == 0)
{
*syslog_level = LOG_WARNING;
}
else if (strcmp(arg, "notice") == 0)
{
*syslog_level = LOG_NOTICE;
}
else if (strcmp(arg, "info") == 0)
{
*syslog_level = LOG_INFO;
}
else if (strcmp(arg, "debug") == 0)
{
*syslog_level = LOG_DEBUG;
}
else
// unknown syslog level
return -1;
}

return 0;
}
2 changes: 2 additions & 0 deletions tools/myst/host/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ int get_fork_mode_opts(
const char* argv[],
myst_fork_mode_t* fork_mode);

int get_syslog_level_opts(int* argc, const char* argv[], int* syslog_level);

long myst_add_symbol_file_by_path(
const char* path,
const void* text_data,
Expand Down
1 change: 1 addition & 0 deletions tools/myst/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ long determine_final_options(
final_opts->base.unhandled_syscall_enosys =
parsed_config->unhandled_syscall_enosys;
final_opts->base.host_uds = parsed_config->host_uds;
final_opts->base.syslog_level = parsed_config->syslog_level;

// Some options should not be enabled unless running in debug mode
if (tee_debug_mode)
Expand Down

0 comments on commit 6654c6f

Please sign in to comment.