Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 5 Apr 2023 11:23:18 -0700
From:      Gleb Smirnoff <glebius@freebsd.org>
To:        Hans Petter Selasky <hps@selasky.org>
Cc:        Zhenlei Huang <zlei@freebsd.org>, Kristof Provost <kp@freebsd.org>, current@freebsd.org
Subject:   Re: Is it valid to combine CTLFLAG_TUN with CTLFLAG_VNET ?
Message-ID:  <ZC28li9kOc5e4rbc@FreeBSD.org>
In-Reply-To: <9dc65578-9312-1139-932f-396bc42e66b2@selasky.org>
References:  <94C1B333-9C0F-4874-BBB1-3E72F3DF3F6A@FreeBSD.org> <9dc65578-9312-1139-932f-396bc42e66b2@selasky.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Apr 05, 2023 at 07:24:07PM +0200, Hans Petter Selasky wrote:
H> On 4/5/23 19:02, Zhenlei Huang wrote:
H> > While working on https://reviews.freebsd.org/D39375 I noticed some tunables
H> > have sysctl flags CTLFLAG_RWTUN | CTLFLAG_VNET .
H> > 
H> > CTLFLAG_RWTUN is defined as (CTLFLAG_RW | CTLFLAG_TUN) . The CTLFLAG_TUN is
H> > for loader tunable.
H> > 
H> > I expected those loader tunables will have correct value regardless the
H> > CTLFLAG_VNET flag but that is not true.
H> > 
H> > Steps to repeat:
H> > # echo "net.link.bridge.log_stp=1" >> /boot/loader.conf
H> > # reboot
H> > # kldload if_bridge
H> > # sysctl net.link.bridge.log_stp
H> > net.link.bridge.log_stp: 0
H> > 
H> > So is it valid to combine CTLFLAG_TUN with CTLFLAG_VNET ?
H> 
H> You can specify the flags together, but it results in nothing with 
H> regards to loading values from tunables:
H> 
H> >         if ((oidp->oid_kind & CTLTYPE) != CTLTYPE_NODE &&
H> > #ifdef VIMAGE
H> >             (oidp->oid_kind & CTLFLAG_VNET) == 0 &&
H> > #endif
H> >             (oidp->oid_kind & CTLFLAG_TUN) != 0 &&
H> >             (oidp->oid_kind & CTLFLAG_NOFETCH) == 0) {
H> >                 /* only fetch value once */
H> >                 oidp->oid_kind |= CTLFLAG_NOFETCH;
H> >                 /* try to fetch value from kernel environment */
H> >                 sysctl_load_tunable_by_oid_locked(oidp);
H> >         }
H> 
H> If I'm not mistaken, I put the check there, when I added support for 
H> loading default values for sysctls via /boot/loader.conf and kenv to 
H> avoid undefined behaviour. Before that CTLFLAG_TUN existed, but was 
H> coupled with manual variable loading via the kernel environment 
H> functions. Only functions that need values loaded very early during 
H> boot, still use TUNABLE_XXX_FETCH() and the alike.
H> 
H> git blame sys/kern_sysctl.c
H> 
H> I guess that for VNETs you'll have to keep on using TUNABLE_XXX_FETCH() 
H> to get appropriate values into the sysctls . This discussion could also 
H> continue on current@freebsd.org .

What if we remove the CTLFLAG_VNET check from the code you posted above?
I don't see anything going wrong, rather going right :)

CTLFLAG_VNET will not mask away CTLFLAG_TUN.

-- 
Gleb Smirnoff



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?ZC28li9kOc5e4rbc>