> Date: Fri, 13 Oct 2023 17:52:07 +0900 > From: Rin Okuyama <rokuyama...@gmail.com> > > It would be really nice if we can find some systematical/reliable methods to > figure out files that really depends on struct syncobj, e.g.. I tried > ctfdump(1) to > *.o for kernel modules, but I cannot extract information better than > ``grep syncobj.h .depend''...
The attached patch removes all use of sys/syncobj.h outside .c files under sys, so we can be reasonably confident userland programs -- except for crash(8), which is kind of special -- are unaffected. However, I'm going to hold off on committing this until the tree's sleepq issues are fixed so our testbed can run again.
>From 7e9e2af19ecc6f4262b928da8a97a49d171c8072 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell <riastr...@netbsd.org> Date: Fri, 13 Oct 2023 11:04:20 +0000 Subject: [PATCH] sys/lwp.h: Nix sys/syncobj.h dependency. Remove it in ddb/db_syncobj.h too. New sys/wchan.h defines wchan_t so that users need not pull in sys/syncobj.h to get it. Sprinkle #include <sys/syncobj.h> in .c files where it is now needed. --- sys/ddb/db_syncobj.h | 2 +- sys/kern/kern_condvar.c | 1 + sys/kern/kern_ktrace.c | 1 + sys/kern/kern_lwp.c | 1 + sys/kern/kern_mutex.c | 1 + sys/kern/kern_rwlock.c | 1 + sys/kern/kern_sleepq.c | 1 + sys/kern/kern_turnstile.c | 1 + sys/kern/sys_lwp.c | 1 + sys/kern/sys_select.c | 1 + sys/sys/lwp.h | 2 +- sys/sys/sleepq.h | 2 +- sys/sys/sleeptab.h | 6 +++++- sys/sys/syncobj.h | 4 ++-- sys/sys/wchan.h | 37 +++++++++++++++++++++++++++++++++++++ 15 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 sys/sys/wchan.h diff --git a/sys/ddb/db_syncobj.h b/sys/ddb/db_syncobj.h index 2c2ad89ba177..dc7594f5163e 100644 --- a/sys/ddb/db_syncobj.h +++ b/sys/ddb/db_syncobj.h @@ -29,7 +29,7 @@ #ifndef _DDB_DB_SYNCOBJ_H #define _DDB_DB_SYNCOBJ_H -#include <sys/syncobj.h> +#include <sys/wchan.h> struct lwp; struct syncobj; diff --git a/sys/kern/kern_condvar.c b/sys/kern/kern_condvar.c index 478c4a35ff2b..c25282e1beb3 100644 --- a/sys/kern/kern_condvar.c +++ b/sys/kern/kern_condvar.c @@ -45,6 +45,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_condvar.c,v 1.59 2023/10/12 23:51:05 ad Exp $") #include <sys/lockdebug.h> #include <sys/cpu.h> #include <sys/kernel.h> +#include <sys/syncobj.h> /* * Accessors for the private contents of the kcondvar_t data type. diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c index 5ad5272af7d8..812be0c2c9ca 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -77,6 +77,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.182 2022/07/01 01:07:56 riastradh #include <sys/callout.h> #include <sys/kauth.h> #include <sys/cpu.h> +#include <sys/syncobj.h> #include <sys/mount.h> #include <sys/syscallargs.h> diff --git a/sys/kern/kern_lwp.c b/sys/kern/kern_lwp.c index 77e43242f0f9..971e0180f1f6 100644 --- a/sys/kern/kern_lwp.c +++ b/sys/kern/kern_lwp.c @@ -253,6 +253,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_lwp.c,v 1.265 2023/10/05 19:41:06 ad Exp $"); #include <sys/kcov.h> #include <sys/cprng.h> #include <sys/futex.h> +#include <sys/syncobj.h> #include <uvm/uvm_extern.h> #include <uvm/uvm_object.h> diff --git a/sys/kern/kern_mutex.c b/sys/kern/kern_mutex.c index 810ea121a0bd..640909bc533e 100644 --- a/sys/kern/kern_mutex.c +++ b/sys/kern/kern_mutex.c @@ -57,6 +57,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_mutex.c,v 1.110 2023/09/23 18:48:04 ad Exp $"); #include <sys/types.h> #include <sys/cpu.h> #include <sys/pserialize.h> +#include <sys/syncobj.h> #include <dev/lockstat.h> diff --git a/sys/kern/kern_rwlock.c b/sys/kern/kern_rwlock.c index 88db7d507b4d..96312874a069 100644 --- a/sys/kern/kern_rwlock.c +++ b/sys/kern/kern_rwlock.c @@ -62,6 +62,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_rwlock.c,v 1.74 2023/10/04 20:39:35 ad Exp $"); #include <sys/atomic.h> #include <sys/lock.h> #include <sys/pserialize.h> +#include <sys/syncobj.h> #include <dev/lockstat.h> diff --git a/sys/kern/kern_sleepq.c b/sys/kern/kern_sleepq.c index e9d39445f75b..bb43e78f6f6b 100644 --- a/sys/kern/kern_sleepq.c +++ b/sys/kern/kern_sleepq.c @@ -49,6 +49,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_sleepq.c,v 1.83 2023/10/08 13:37:26 ad Exp $"); #include <sys/systm.h> #include <sys/sleepq.h> #include <sys/ktrace.h> +#include <sys/syncobj.h> /* * for sleepq_abort: diff --git a/sys/kern/kern_turnstile.c b/sys/kern/kern_turnstile.c index 0cd8886cb6b5..85bdf946c325 100644 --- a/sys/kern/kern_turnstile.c +++ b/sys/kern/kern_turnstile.c @@ -68,6 +68,7 @@ __KERNEL_RCSID(0, "$NetBSD: kern_turnstile.c,v 1.53 2023/10/08 13:23:05 ad Exp $ #include <sys/proc.h> #include <sys/sleepq.h> #include <sys/sleeptab.h> +#include <sys/syncobj.h> #include <sys/systm.h> /* diff --git a/sys/kern/sys_lwp.c b/sys/kern/sys_lwp.c index c71cf1e823d6..108d40641e38 100644 --- a/sys/kern/sys_lwp.c +++ b/sys/kern/sys_lwp.c @@ -51,6 +51,7 @@ __KERNEL_RCSID(0, "$NetBSD: sys_lwp.c,v 1.87 2023/10/08 13:23:05 ad Exp $"); #include <sys/lwpctl.h> #include <sys/cpu.h> #include <sys/pserialize.h> +#include <sys/syncobj.h> #include <uvm/uvm_extern.h> diff --git a/sys/kern/sys_select.c b/sys/kern/sys_select.c index 9719d220e319..16962505663c 100644 --- a/sys/kern/sys_select.c +++ b/sys/kern/sys_select.c @@ -106,6 +106,7 @@ __KERNEL_RCSID(0, "$NetBSD: sys_select.c,v 1.64 2023/10/08 13:23:05 ad Exp $"); #include <sys/sleepq.h> #include <sys/sysctl.h> #include <sys/bitops.h> +#include <sys/syncobj.h> /* Flags for lwp::l_selflag. */ #define SEL_RESET 0 /* awoken, interrupted, or not yet polling */ diff --git a/sys/sys/lwp.h b/sys/sys/lwp.h index 258d8453d600..74b051081faf 100644 --- a/sys/sys/lwp.h +++ b/sys/sys/lwp.h @@ -45,8 +45,8 @@ #include <sys/signalvar.h> #include <sys/sched.h> #include <sys/specificdata.h> -#include <sys/syncobj.h> #include <sys/resource.h> +#include <sys/wchan.h> #if defined(_KERNEL) struct lwp; diff --git a/sys/sys/sleepq.h b/sys/sys/sleepq.h index f79201e48dc0..1e832988ae38 100644 --- a/sys/sys/sleepq.h +++ b/sys/sys/sleepq.h @@ -38,8 +38,8 @@ #include <sys/pool.h> #include <sys/queue.h> #include <sys/sched.h> -#include <sys/syncobj.h> /* XXX remove me */ #include <sys/param.h> +#include <sys/wchan.h> struct syncobj; diff --git a/sys/sys/sleeptab.h b/sys/sys/sleeptab.h index 68a1165fcbc1..5f5eab53e228 100644 --- a/sys/sys/sleeptab.h +++ b/sys/sys/sleeptab.h @@ -33,6 +33,10 @@ #ifndef _SYS_SLEEPTAB_H_ #define _SYS_SLEEPTAB_H_ +#include <sys/wchan.h> + +struct syncobj; + #define SLEEPTAB_HASH_SHIFT 7 #define SLEEPTAB_HASH_SIZE (1 << SLEEPTAB_HASH_SHIFT) #define SLEEPTAB_HASH_MASK (SLEEPTAB_HASH_SIZE - 1) @@ -121,7 +125,7 @@ void turnstile_init(void); turnstile_t *turnstile_lookup(wchan_t); void turnstile_ctor(turnstile_t *); void turnstile_exit(wchan_t); -void turnstile_block(turnstile_t *, int, wchan_t, syncobj_t *); +void turnstile_block(turnstile_t *, int, wchan_t, const struct syncobj *); void turnstile_wakeup(turnstile_t *, int, int, lwp_t *); void turnstile_print(volatile void *, void (*)(const char *, ...) __printflike(1, 2)); diff --git a/sys/sys/syncobj.h b/sys/sys/syncobj.h index 9dc2dc476c55..31939339dcd6 100644 --- a/sys/sys/syncobj.h +++ b/sys/sys/syncobj.h @@ -32,9 +32,9 @@ #if !defined(_SYS_SYNCOBJ_H_) #define _SYS_SYNCOBJ_H_ -struct lwp; +#include <sys/wchan.h> -typedef volatile const void *wchan_t; +struct lwp; #if defined(_KERNEL) || defined(_KMEMUSER) diff --git a/sys/sys/wchan.h b/sys/sys/wchan.h new file mode 100644 index 000000000000..bc5ebceb1096 --- /dev/null +++ b/sys/sys/wchan.h @@ -0,0 +1,37 @@ +/* $NetBSD: syncobj.h,v 1.17 2023/10/08 13:23:05 ad Exp $ */ + +/*- + * Copyright (c) 2007, 2008, 2020, 2023 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Andrew Doran. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_WCHAN_H_ +#define _SYS_WCHAN_H_ + +typedef volatile const void *wchan_t; + +#endif /* _SYS_WCHAN_H_ */