From: "Lorenz (xha)" Subject: Re: sysctl(2): make sysctl_int{,_lower}() mp-safe and unlock KERN_HOSTID To: Vitaliy Makkoveev Cc: tech@openbsd.org Date: Wed, 14 Aug 2024 06:58:37 +0200 hi, On Tue, Aug 13, 2024 at 02:24:34PM +0300, Vitaliy Makkoveev wrote: > Make sysctl_int() mp-safe in the sysctl_int_bounded() way and unlock > KERN_HOSTID. Except bootstrap called clockattach() of sparc64, `hostid' > never used outside kern_sysctl(). > > mp-safe sysctl_int() is meaningless for sysctl_int_lower(), so rework it > too. This time all affected paths are kernel locked, but this doesn't > make sysctl_int_lower() worse. > > ok? > > Index: sys/kern/kern_sysctl.c > =================================================================== > RCS file: /cvs/src/sys/kern/kern_sysctl.c,v > diff -u -p -r1.437 kern_sysctl.c > --- sys/kern/kern_sysctl.c 11 Aug 2024 15:10:53 -0000 1.437 > +++ sys/kern/kern_sysctl.c 13 Aug 2024 11:03:24 -0000 > @@ -507,6 +507,10 @@ kern_sysctl(int *name, u_int namelen, vo > return (sysctl_rdstring(oldp, oldlenp, newp, version)); > case KERN_NUMVNODES: /* XXX numvnodes is a long */ > return (sysctl_rdint(oldp, oldlenp, newp, numvnodes)); > + case KERN_HOSTID: > + /* XXX assumes sizeof long >= sizeof int */ the C standard specifies that this is the case, for example in C99: 6.2.5 Types: "For any two integer types with the same signedness and different integer conversion rank (see 6.3.2.1), the range of values of the type with smaller integer conversion rank is a subrange of the values of the other type."