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

Kernel command line: add support for arbitrary configuration settings #1983

Merged
merged 6 commits into from
Dec 15, 2023
Merged
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 klib/cloud_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static enum cloud cloud_detect(void)

static int cloud_init_parse_vector(value config, int (*parse_each)(tuple, vector), vector tasks)
{
if (!(is_tuple(config) || is_vector(config)))
if (!is_composite(config))
return KLIB_INIT_FAILED;
/* allow parsing either tuple or vector for backward compatibility with older ops/tfs... */
value v;
Expand Down
2 changes: 1 addition & 1 deletion klib/firewall.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ int init(status_handler complete)
value rules = get(config, sym(rules));
if (!rules)
return KLIB_INIT_OK;
if (!(is_tuple(rules) || is_vector(rules))) {
if (!is_composite(rules)) {
rprintf("invalid firewall rules\n");
return KLIB_INIT_FAILED;
}
Expand Down
63 changes: 23 additions & 40 deletions platform/pc/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,6 @@ static void __attribute__((noinline)) init_service_new_stack()
{
kernel_heaps kh = get_kernel_heaps();
early_init_debug("in init_service_new_stack");
bytes pagesize = is_low_memory_machine() ? PAGESIZE : PAGESIZE_2M;
init_integers(locking_heap_wrapper(heap_general(kh),
allocate_tagged_region(kh, tag_integer, pagesize)));
init_tuples(locking_heap_wrapper(heap_general(kh),
allocate_tagged_region(kh, tag_table_tuple, pagesize)));
init_symbols(allocate_tagged_region(kh, tag_symbol, pagesize), heap_locked(kh));
heap vh = allocate_tagged_region(kh, tag_vector, pagesize);
init_vectors(locking_heap_wrapper(heap_general(kh), vh), heap_locked(kh));
heap sh = allocate_tagged_region(kh, tag_string, pagesize);
init_strings(locking_heap_wrapper(heap_general(kh), sh), heap_locked(kh));

for_regions(e) {
switch (e->type) {
Expand All @@ -265,7 +255,6 @@ static void __attribute__((noinline)) init_service_new_stack()
}
}

init_management(allocate_tagged_region(kh, tag_function_tuple, pagesize), heap_general(kh));
early_init_debug("init_hwrand");
init_hwrand();

Expand Down Expand Up @@ -332,15 +321,10 @@ id_heap init_physical_id_heap(heap h)
early_init_debug("physical memory:");
for_regions(e) {
if (e->type == REGION_PHYSICAL) {
/* Align for 2M pages */
u64 base = e->base;
u64 end = base + e->length;
u64 page2m_mask = MASK(PAGELOG_2M);
base = (base + page2m_mask) & ~page2m_mask;
end &= ~MASK(PAGELOG);
if (base >= end)
u64 length = e->length;
if (length == 0)
continue;
u64 length = end - base;
#ifdef INIT_DEBUG
early_debug("INIT: [");
early_debug_u64(base);
Expand Down Expand Up @@ -405,26 +389,6 @@ static inline void jump_to_virtual(void) {
1: \n");
}

static void cmdline_parse(const char *cmdline)
{
early_init_debug("parsing cmdline");
const char *opt_end, *prefix_end;
while (*cmdline) {
opt_end = runtime_strchr(cmdline, ' ');
if (!opt_end)
opt_end = cmdline + runtime_strlen(cmdline);
prefix_end = runtime_strchr(cmdline, '.');
if (prefix_end && (prefix_end < opt_end)) {
int prefix_len = prefix_end - cmdline;
if ((prefix_len == sizeof("virtio_mmio") - 1) &&
!runtime_memcmp(cmdline, "virtio_mmio", prefix_len))
virtio_mmio_parse(get_kernel_heaps(), prefix_end + 1,
opt_end - (prefix_end + 1));
}
cmdline = opt_end + 1;
}
}

extern void *READONLY_END;

/* Returns the number of pages have been allocated from the temporary page table region. */
Expand Down Expand Up @@ -495,7 +459,6 @@ void init_service(u64 rdi, u64 rsi)
*/
assert(u64_from_pointer(params) + cmdline_size < MBR_ADDRESS);
runtime_memcpy(params, cmdline, cmdline_size);
params[cmdline_size] = '\0';
cmdline = (char *)params;
}

Expand All @@ -512,7 +475,7 @@ void init_service(u64 rdi, u64 rsi)
init_page_initial_map(pointer_from_u64(PAGES_BASE), initial_pages);
init_kernel_heaps();
if (cmdline)
cmdline_parse(cmdline);
create_region(u64_from_pointer(cmdline), cmdline_size, REGION_CMDLINE);
u64 stack_size = 32*PAGESIZE;
u64 stack_location = allocate_u64((heap)heap_page_backed(get_kernel_heaps()), stack_size);
stack_location += stack_size - STACK_ALIGNMENT;
Expand Down Expand Up @@ -623,3 +586,23 @@ void detect_devices(kernel_heaps kh, storage_attach sa)
init_virtio_balloon(kh);
init_virtio_rng(kh);
}

void cmdline_consume(const char *opt_name, cmdline_handler h)
{
for_regions(e) {
if (e->type == REGION_CMDLINE) {
e->length = cmdline_parse(pointer_from_u64(e->base), e->length, opt_name, h);
return;
}
}
}

void boot_params_apply(tuple t)
{
for_regions(e) {
if (e->type == REGION_CMDLINE) {
cmdline_apply(pointer_from_u64(e->base), e->length, t);
return;
}
}
}
13 changes: 1 addition & 12 deletions platform/riscv-virt/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ id_heap init_physical_id_heap(heap h)
u64 end = PHYSMEM_BASE + mem_size;
u64 bootstrap_size = init_bootstrap_heap(end - base);
map(BOOTSTRAP_BASE, base, bootstrap_size, pageflags_writable(pageflags_memory()));
base = pad(base + bootstrap_size, PAGESIZE_2M);
base += bootstrap_size;
init_debug("\nfree base ");
init_debug_u64(base);
init_debug("\nend ");
Expand Down Expand Up @@ -102,17 +102,6 @@ static void __attribute__((noinline)) init_service_new_stack(void)
{
init_debug("in init_service_new_stack\n");
kernel_heaps kh = get_kernel_heaps();
bytes pagesize = is_low_memory_machine() ? PAGESIZE : PAGESIZE_2M;
init_integers(locking_heap_wrapper(heap_general(kh),
allocate_tagged_region(kh, tag_integer, pagesize)));
init_tuples(locking_heap_wrapper(heap_general(kh),
allocate_tagged_region(kh, tag_table_tuple, pagesize)));
init_symbols(allocate_tagged_region(kh, tag_symbol, pagesize), heap_locked(kh));
heap vh = allocate_tagged_region(kh, tag_vector, pagesize);
init_vectors(locking_heap_wrapper(heap_general(kh), vh), heap_locked(kh));
heap sh = allocate_tagged_region(kh, tag_string, pagesize);
init_strings(locking_heap_wrapper(heap_general(kh), sh), heap_locked(kh));
init_management(allocate_tagged_region(kh, tag_function_tuple, pagesize), heap_general(kh));
init_debug("calling runtime init\n");
kernel_runtime_init(kh);
while(1);
Expand Down
16 changes: 1 addition & 15 deletions platform/virt/service.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ static void add_heap_range_internal(id_heap h, range r, range *remainder)
r = *remainder;
*remainder = tmp;
}
r.start = pad(r.start, PAGESIZE_2M);
if (r.start >= r.end)
return;
init_debug("adding range [0x");
init_debug_u64(r.start);
init_debug(" 0x");
Expand Down Expand Up @@ -198,7 +195,7 @@ id_heap init_physical_id_heap(heap h)
u64 end = base + get_memory_size(pointer_from_u64(DEVICETREE_BLOB_BASE));
u64 bootstrap_size = init_bootstrap_heap(end - base);
map(BOOTSTRAP_BASE, base, bootstrap_size, pageflags_writable(pageflags_memory()));
base = pad(base + bootstrap_size, PAGESIZE_2M);
base += bootstrap_size;
init_debug("\nfree base ");
init_debug_u64(base);
init_debug("\nend ");
Expand Down Expand Up @@ -247,17 +244,6 @@ static void __attribute__((noinline)) init_service_new_stack(void)
{
init_debug("in init_service_new_stack\n");
kernel_heaps kh = get_kernel_heaps();
bytes pagesize = is_low_memory_machine() ? PAGESIZE : PAGESIZE_2M;
init_integers(locking_heap_wrapper(heap_general(kh),
allocate_tagged_region(kh, tag_integer, pagesize)));
init_tuples(locking_heap_wrapper(heap_general(kh),
allocate_tagged_region(kh, tag_table_tuple, pagesize)));
init_symbols(allocate_tagged_region(kh, tag_symbol, pagesize), heap_locked(kh));
heap vh = allocate_tagged_region(kh, tag_vector, pagesize);
init_vectors(locking_heap_wrapper(heap_general(kh), vh), heap_locked(kh));
heap sh = allocate_tagged_region(kh, tag_string, pagesize);
init_strings(locking_heap_wrapper(heap_general(kh), sh), heap_locked(kh));
init_management(allocate_tagged_region(kh, tag_function_tuple, pagesize), heap_general(kh));
init_debug("calling runtime init\n");
kernel_runtime_init(kh);
while(1);
Expand Down
2 changes: 1 addition & 1 deletion src/aarch64/kernel_machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static u64 tag_alloc(heap h, bytes s)
return a;
}

heap allocate_tagged_region(kernel_heaps kh, u64 tag, bytes pagesize)
heap allocate_tagged_region(kernel_heaps kh, u64 tag, bytes pagesize, boolean locking)
{
heap h = heap_locked(kh);
struct tagheap *th = allocate(h, sizeof(struct tagheap));
Expand Down
3 changes: 3 additions & 0 deletions src/aarch64/kernel_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ static inline void wait_for_interrupt(void)
enable_interrupts();
}

#define cmdline_consume(o, h) (void)(h)
#define boot_params_apply(t)

/* locking constructs */
#include <mutex.h>

Expand Down
2 changes: 1 addition & 1 deletion src/drivers/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void config_console(tuple root)
value v = get(root, sym(consoles));
if (v == 0)
return;
if (!(is_vector(v) || is_tuple(v))) {
if (!is_composite(v)) {
msg_err("consoles config is neither vector nor tuple\n");
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/fs/tlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ closure_function(2, 1, void, log_switch_complete,
if (is_ok(s))
table_foreach(old_tl->dictionary, k, v) {
(void)v;
if ((is_tuple(k) || is_vector(k)) && !table_find(new_tl->dictionary, k)) {
if (is_composite(k) && !table_find(new_tl->dictionary, k)) {
tlog_debug(" destroying value %p\n", __func__, k);
destruct_value(k, false);
}
Expand Down Expand Up @@ -842,7 +842,7 @@ closure_function(4, 1, void, log_read_complete,
table newdict = allocate_table(tl->h, identity_key, pointer_equal);
table_foreach(tl->dictionary, k, v) {
tlog_debug(" dict swap: k %p, v %p, type %d\n", k, v, tagof(v));
assert(is_tuple(v) || is_symbol(v) || is_vector(v));
assert(is_composite(v) || is_symbol(v));
table_set(newdict, v, k);
}
deallocate_table(tl->dictionary);
Expand Down
Loading