From 45a1a30ecec2c0e3bb0bb1b93a0608e1ffcdf9c4 Mon Sep 17 00:00:00 2001 From: robert Date: Mon, 7 Nov 2022 14:25:44 +0000 Subject: [PATCH] introduce a new kern.autoconf_serial sysctl that can be used by userland to monitor state changes of the kernel device tree input from dnd ok dlg@, deraadt@ --- sys/kern/kern_sysctl.c | 4 +++- sys/kern/subr_autoconf.c | 9 ++++++++- sys/sys/sysctl.h | 6 ++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index abf9cf0ded7..ff42ebb5129 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.407 2022/11/05 19:29:46 cheloha Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.408 2022/11/07 14:25:44 robert Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -126,6 +126,7 @@ extern long numvnodes; extern int allowdt; extern int audio_record_enable; extern int video_record_enable; +extern int autoconf_serial; int allowkmem; @@ -341,6 +342,7 @@ const struct sysctl_bounded_args kern_vars[] = { #ifdef PTRACE {KERN_GLOBAL_PTRACE, &global_ptrace, 0, 1}, #endif + {KERN_AUTOCONF_SERIAL, &autoconf_serial, SYSCTL_INT_READONLY}, }; int diff --git a/sys/kern/subr_autoconf.c b/sys/kern/subr_autoconf.c index a35b2224724..41633140dc6 100644 --- a/sys/kern/subr_autoconf.c +++ b/sys/kern/subr_autoconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_autoconf.c,v 1.96 2022/04/07 09:37:32 tb Exp $ */ +/* $OpenBSD: subr_autoconf.c,v 1.97 2022/11/07 14:25:44 robert Exp $ */ /* $NetBSD: subr_autoconf.c,v 1.21 1996/04/04 06:06:18 cgd Exp $ */ /* @@ -106,6 +106,11 @@ struct mutex autoconf_attdet_mtx = MUTEX_INITIALIZER(IPL_HIGH); */ int autoconf_attdet; +/* + * Versioned state of the devices tree so that changes can be detected. + */ +unsigned int autoconf_serial = 0; + /* * Initialize autoconfiguration data structures. This occurs before console * initialization as that might require use of this subsystem. Furthermore @@ -419,6 +424,7 @@ config_attach(struct device *parent, void *match, void *aux, cfprint_t print) mtx_enter(&autoconf_attdet_mtx); if (--autoconf_attdet == 0) wakeup(&autoconf_attdet); + autoconf_serial++; mtx_leave(&autoconf_attdet_mtx); return (dev); } @@ -642,6 +648,7 @@ done: mtx_enter(&autoconf_attdet_mtx); if (++autoconf_attdet == 0) wakeup(&autoconf_attdet); + autoconf_serial++; mtx_leave(&autoconf_attdet_mtx); return (rv); } diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 84564782931..4fa5afdf6c8 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.h,v 1.230 2022/11/05 19:29:46 cheloha Exp $ */ +/* $OpenBSD: sysctl.h,v 1.231 2022/11/07 14:25:44 robert Exp $ */ /* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */ /* @@ -192,7 +192,8 @@ struct ctlname { #define KERN_UTC_OFFSET 88 /* int: adjust RTC time to UTC */ #define KERN_VIDEO 89 /* struct: video properties */ #define KERN_CLOCKINTR 90 /* node: clockintr */ -#define KERN_MAXID 91 /* number of valid kern ids */ +#define KERN_AUTOCONF_SERIAL 91 /* int: kernel device tree state serial */ +#define KERN_MAXID 92 /* number of valid kern ids */ #define CTL_KERN_NAMES { \ { 0, 0 }, \ @@ -286,6 +287,7 @@ struct ctlname { { "utc_offset", CTLTYPE_INT }, \ { "video", CTLTYPE_STRUCT }, \ { "clockintr", CTLTYPE_NODE }, \ + { "autoconf_serial", CTLTYPE_INT }, \ } /* -- 2.20.1