From nobody Wed Apr 05 18:23:18 2023 X-Original-To: current@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PsCgJ6pTdz43xdw for ; Wed, 5 Apr 2023 18:23:24 +0000 (UTC) (envelope-from glebius@freebsd.org) Received: from glebi.us (glebi.us [162.251.186.162]) by mx1.freebsd.org (Postfix) with ESMTP id 4PsCgJ4bG0z46y0; Wed, 5 Apr 2023 18:23:24 +0000 (UTC) (envelope-from glebius@freebsd.org) Authentication-Results: mx1.freebsd.org; none Received: by glebi.us (Postfix, from userid 1000) id 3B3C76DAFB; Wed, 5 Apr 2023 11:23:18 -0700 (PDT) Date: Wed, 5 Apr 2023 11:23:18 -0700 From: Gleb Smirnoff To: Hans Petter Selasky Cc: Zhenlei Huang , Kristof Provost , current@freebsd.org Subject: Re: Is it valid to combine CTLFLAG_TUN with CTLFLAG_VNET ? Message-ID: References: <94C1B333-9C0F-4874-BBB1-3E72F3DF3F6A@FreeBSD.org> <9dc65578-9312-1139-932f-396bc42e66b2@selasky.org> List-Id: Discussions about the use of FreeBSD-current List-Archive: https://lists.freebsd.org/archives/freebsd-current List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-current@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <9dc65578-9312-1139-932f-396bc42e66b2@selasky.org> X-Rspamd-Queue-Id: 4PsCgJ4bG0z46y0 X-Spamd-Bar: ---- X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:27348, ipnet:162.251.186.0/24, country:US] X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-ThisMailContainsUnwantedMimeParts: N 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