From 2286d495bb32a409db63c863415d2e1daad4f98e Mon Sep 17 00:00:00 2001 From: Octavian Purdila Date: Tue, 11 Feb 2025 16:02:17 -0800 Subject: [PATCH 1/4] lkl: fix redundant generic-y build warnings Remove a few redundant generic-y statements. Signed-off-by: Octavian Purdila --- arch/lkl/include/asm/Kbuild | 43 -------------------------------- arch/lkl/include/uapi/asm/Kbuild | 1 - 2 files changed, 44 deletions(-) diff --git a/arch/lkl/include/asm/Kbuild b/arch/lkl/include/asm/Kbuild index 267b80c7300862..091062207bf5b8 100644 --- a/arch/lkl/include/asm/Kbuild +++ b/arch/lkl/include/asm/Kbuild @@ -1,78 +1,35 @@ -generic-y += atomic.h -generic-y += barrier.h -generic-y += bitops.h -generic-y += bug.h -generic-y += bugs.h generic-y += cache.h -generic-y += cacheflush.h -generic-y += checksum.h generic-y += cmpxchg-local.h generic-y += cmpxchg.h -generic-y += compat.h generic-y += cputime.h -generic-y += current.h -generic-y += delay.h -generic-y += device.h -generic-y += div64.h -generic-y += emergency-restart.h generic-y += errno.h generic-y += extable.h -generic-y += exec.h -generic-y += ftrace.h -generic-y += futex.h -generic-y += hardirq.h -generic-y += hw_irq.h generic-y += ioctl.h generic-y += ipcbuf.h -generic-y += irq_regs.h generic-y += irqflags.h -generic-y += irq_work.h -generic-y += kdebug.h generic-y += kmap_types.h -generic-y += linkage.h -generic-y += local.h -generic-y += local64.h generic-y += mcs_spinlock.h -generic-y += mmiowb.h -generic-y += mmu.h -generic-y += module.h generic-y += msgbuf.h generic-y += param.h generic-y += parport.h generic-y += pci_iomap.h -generic-y += percpu.h -generic-y += pgalloc.h generic-y += poll.h -generic-y += preempt.h generic-y += resource.h generic-y += rwsem.h generic-y += scatterlist.h generic-y += seccomp.h -generic-y += sections.h generic-y += segment.h generic-y += sembuf.h -generic-y += serial.h generic-y += shmbuf.h generic-y += signal.h -generic-y += simd.h generic-y += sizes.h generic-y += socket.h generic-y += sockios.h generic-y += stat.h generic-y += statfs.h generic-y += swab.h -generic-y += switch_to.h generic-y += termbits.h generic-y += termios.h generic-y += time.h -generic-y += timex.h -generic-y += tlbflush.h -generic-y += topology.h -generic-y += trace_clock.h -generic-y += unaligned.h generic-y += user.h -generic-y += vga.h -generic-y += word-at-a-time.h -generic-y += kprobes.h -generic-y += uaccess.h generic-y += mman.h diff --git a/arch/lkl/include/uapi/asm/Kbuild b/arch/lkl/include/uapi/asm/Kbuild index 551ae10f1edae6..1e11088dd7096b 100644 --- a/arch/lkl/include/uapi/asm/Kbuild +++ b/arch/lkl/include/uapi/asm/Kbuild @@ -3,7 +3,6 @@ generic-y += elf.h generic-y += kvm_para.h generic-y += shmparam.h -generic-y += siginfo.h generic-y += timex.h generated-y += config.h From 648f7902bcfc8062e4a89c9e983a1e48a6e6ac1a Mon Sep 17 00:00:00 2001 From: Octavian Purdila Date: Tue, 11 Feb 2025 17:16:41 -0800 Subject: [PATCH 2/4] lkl: posix: implement wrapper for timer callback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement a wrapper for the timer callback to fix the following compile warning: lib/posix-host.c:383:42: warning: cast between incompatible \ function types from ‘void (*)(void *)’ to ‘void (*)(union sigval)’ \ [-Wcast-function-type] 383 | .sigev_notify_function = (void (*)(union sigval))fn, | ^ Signed-off-by: Octavian Purdila --- tools/lkl/lib/posix-host.c | 46 ++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/tools/lkl/lib/posix-host.c b/tools/lkl/lib/posix-host.c index 5387ce3f6987d6..76da994337c0de 100644 --- a/tools/lkl/lib/posix-host.c +++ b/tools/lkl/lib/posix-host.c @@ -361,7 +361,6 @@ static void *tls_get(struct lkl_tls_key *key) return __tls_keys[idx].data; } - static unsigned long long time_ns(void) { struct timespec ts; @@ -371,28 +370,46 @@ static unsigned long long time_ns(void) return 1e9*ts.tv_sec + ts.tv_nsec; } +struct lkl_timer { + timer_t timer; + void (*fn)(void *arg); + void *arg; +}; + +static void lkl_timer_callback(union sigval sv) +{ + struct lkl_timer *lt = (struct lkl_timer *)sv.sival_ptr; + + lt->fn(lt->arg); +} + static void *timer_alloc(void (*fn)(void *), void *arg) { int err; - timer_t timer; struct sigevent se = { .sigev_notify = SIGEV_THREAD, - .sigev_value = { - .sival_ptr = arg, - }, - .sigev_notify_function = (void (*)(union sigval))fn, + .sigev_notify_function = lkl_timer_callback, }; + struct lkl_timer *pt; + + + pt = malloc(sizeof(*pt)); + if (!pt) + return NULL; - err = timer_create(CLOCK_REALTIME, &se, &timer); + pt->fn = fn; + pt->arg = arg; + se.sigev_value.sival_ptr = pt; + err = timer_create(CLOCK_REALTIME, &se, &pt->timer); if (err) return NULL; - return (void *)(long)timer; + return pt; } -static int timer_set_oneshot(void *_timer, unsigned long ns) +static int timer_set_oneshot(void *timer, unsigned long ns) { - timer_t timer = (timer_t)(long)_timer; + struct lkl_timer *lt = timer; struct itimerspec ts = { .it_value = { .tv_sec = ns / 1000000000, @@ -400,14 +417,15 @@ static int timer_set_oneshot(void *_timer, unsigned long ns) }, }; - return timer_settime(timer, 0, &ts, NULL); + return timer_settime(lt->timer, 0, &ts, NULL); } -static void timer_free(void *_timer) +static void timer_free(void *timer) { - timer_t timer = (timer_t)(long)_timer; + struct lkl_timer *lt = timer; - timer_delete(timer); + timer_delete(lt->timer); + free(lt); } static void panic(void) From 5ffc613eafd8b54bcc191fea37a368c08b11d611 Mon Sep 17 00:00:00 2001 From: Octavian Purdila Date: Tue, 11 Feb 2025 18:19:40 -0800 Subject: [PATCH 3/4] lkl: posix: add thread wrapper function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add thread wrapper function. Fixes the following compile warning: lib/posix-host.c: In function ‘thread_create’: lib/posix-host.c:195:56: warning: cast between incompatible function \ types from ‘void (*)(void *)’ to ‘void * (*)(void *)’ [-Wcast-function-type] 195 | if (WARN_PTHREAD(pthread_create(&thread, NULL, (void* (*)(void *))fn, arg))) | ^ lib/posix-host.c:77:41: note: in definition of macro ‘WARN_PTHREAD’ 77 | #define WARN_PTHREAD(exp) _warn_pthread(exp, #exp) | ^~~ Signed-off-by: Octavian Purdila --- tools/lkl/lib/posix-host.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tools/lkl/lib/posix-host.c b/tools/lkl/lib/posix-host.c index 76da994337c0de..8cf8eda8013d61 100644 --- a/tools/lkl/lib/posix-host.c +++ b/tools/lkl/lib/posix-host.c @@ -189,10 +189,36 @@ static void mutex_free(struct lkl_mutex *_mutex) free(_mutex); } +struct lkl_thread_wrapper_arg { + void (*fn)(void *arg); + void *arg; +}; + +void *lkl_thread_wrapper(void *arg) +{ + struct lkl_thread_wrapper_arg *lt = arg; + void (*fn)(void *) = lt->fn; + void *fn_arg = lt->arg; + + free(lt); + + fn(fn_arg); + return NULL; +} + static lkl_thread_t thread_create(void (*fn)(void *), void *arg) { pthread_t thread; - if (WARN_PTHREAD(pthread_create(&thread, NULL, (void* (*)(void *))fn, arg))) + struct lkl_thread_wrapper_arg *wrapper_arg; + + wrapper_arg = malloc(sizeof(*wrapper_arg)); + if (!wrapper_arg) + return 0; + wrapper_arg->fn = fn; + wrapper_arg->arg = arg; + + if (WARN_PTHREAD(pthread_create(&thread, NULL, lkl_thread_wrapper, + wrapper_arg))) return 0; else return (lkl_thread_t) thread; From 75f1587578f67cfbe1e92dbce1f52391be77883a Mon Sep 17 00:00:00 2001 From: Octavian Purdila Date: Tue, 11 Feb 2025 18:32:25 -0800 Subject: [PATCH 4/4] lkl: syscalls: use void pointers to store syscall handlers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a bunch of Wcast-function-type compile warnings: arch/lkl/kernel/syscalls.c:27:35: warning: cast between incompatible function types from ‘long int (*)(pid_t, pid_t, int, long unsigned int, long unsigned int)’ {aka ‘long int (*)(int, int, int, long unsigned int, long unsigned int)’} to ‘long int (*)(void)’ [-Wcast-function-type] 27 | #define __SYSCALL(nr, sym) [nr] = (syscall_handler_t)sym, | ^ ./include/uapi/asm-generic/unistd.h:662:1: note: in expansion of macro ‘__SYSCALL’ 662 | __SYSCALL(__NR_kcmp, sys_kcmp) | ^~~~~~~~~ Signed-off-by: Octavian Purdila --- arch/lkl/kernel/syscalls.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/lkl/kernel/syscalls.c b/arch/lkl/kernel/syscalls.c index b408aa20409eb0..cd4431ff245507 100644 --- a/arch/lkl/kernel/syscalls.c +++ b/arch/lkl/kernel/syscalls.c @@ -24,10 +24,10 @@ static asmlinkage long sys_new_thread_group_leader(void); typedef long (*syscall_handler_t)(long arg1, ...); #undef __SYSCALL -#define __SYSCALL(nr, sym) [nr] = (syscall_handler_t)sym, +#define __SYSCALL(nr, sym)[nr] = sym, -syscall_handler_t syscall_table[__NR_syscalls] = { - [0 ... __NR_syscalls - 1] = (syscall_handler_t)sys_ni_syscall, +void *syscall_table[__NR_syscalls] = { + [0 ... __NR_syscalls - 1] = sys_ni_syscall, #include #if __BITS_PER_LONG == 32 @@ -38,12 +38,13 @@ syscall_handler_t syscall_table[__NR_syscalls] = { static long run_syscall(long no, long *params) { long ret; + syscall_handler_t handler = (syscall_handler_t)syscall_table[no]; if (no < 0 || no >= __NR_syscalls) return -ENOSYS; - ret = syscall_table[no](params[0], params[1], params[2], params[3], - params[4], params[5]); + ret = handler(params[0], params[1], params[2], params[3], params[4], + params[5]); task_work_run();