From nobody Thu Nov 7 14:28:10 2024 X-Original-To: dev-commits-src-all@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 4XkkvH1XvTz5bwPV; Thu, 07 Nov 2024 14:28:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XkkvH0mFjz4r3G; Thu, 7 Nov 2024 14:28:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730989691; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ROBsfNikJS9mWZRfVYMqIXhJLXATZIN1nEeXR3hbs0M=; b=xi6OABrc2SAsLdTCP9RS1MFydJQexx/gytrCmY34++qlcST/q9LiJgleqdLSqPgiKPOJB7 0K16Ufl17qITBwElCrqTAohMAmFAPqg6ZXVqlNw3D8RrKs4lLabOWfGi5LkPHhh4MkK3FP pLXCSmEW1ioPpUboXKUqM0JpGNFPv6VL8SdFstgZwZYFPW1mSO4i+3e/pgLwuKJI1qRPQg ZL4geYqiwJHDa2Kgdy1nwW/14UXa82KqnWV/Ps8ZLp0sBoudM43mqmymPDT4C4Kf19jtAW wyXAT1X1GHLo4i6asOxbvTOZgnVqkoo1ULXC/YC5eycPn3o/xlge2wwuv139Fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730989691; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ROBsfNikJS9mWZRfVYMqIXhJLXATZIN1nEeXR3hbs0M=; b=F7KY5W1B+CRQg9HboaN6rTbOmCccbo9MKDH+8+6fVwO2eI8sBN0t/kVUETwNB6G3T/dSPJ xXRXnRH2bew1qc6x2hfrKsfd/fRTVxc8hE3Hb2clGh0hYnFQrCs0W8yNy7XtyOjscnzelU dVDVZgcY5rIQWUruTS5j7y2gCouOM5uVaiK1ig/Iwn/Q/eX2EWrw0zZpf+esUHeM2IW6KL Eg416e4D6SAQrpe3i/tB/hgxxn896CGz0J2L5dIB8fNXKfYF9PdfguZsu2cpyoOFZt+wAa N2VnaWg7fw8QshfsScpP8FotLzzK+9ZRTYrIxgCqn3r9AEymulc7wxK/PrwQnA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730989691; a=rsa-sha256; cv=none; b=LCHPjyWpH0yZUPfwQ/zhMXOHspwi2ZP9D+CwEi9qeFZyOcKHx26I0c+kvOAjyY27XMfd49 TPoqNLKRicbcdaR+OMIQZ/q4Cp5LAeSATm0u6FfjElc7fKBs835IOPg6GPziBX2F8jfR/J ZpNaSpgVlAEkYmDzW9XNfzufOStxfCZSiJWzvxKIVHchxlQsA6ip8DAnAkjzSPdQbK4ILC UZGI+VDAExvSRgySafqkU6jKf0mapzcnrdqJHyljoXyBIQA4XlLOEiAaUDLd/CBu5xbQkf 6gyYnEcckgUpWh8yOKCy1Z7iY0TC8RRklUYjydBfKoU6DDJGEJ279SFlOzEZOQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XkkvG72zxzplN; Thu, 7 Nov 2024 14:28:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4A7ESAKp031734; Thu, 7 Nov 2024 14:28:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4A7ESAsn031731; Thu, 7 Nov 2024 14:28:10 GMT (envelope-from git) Date: Thu, 7 Nov 2024 14:28:10 GMT Message-Id: <202411071428.4A7ESAsn031731@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 48c59140bd7d - stable/13 - bus: Set the current VNET in device_attach() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 48c59140bd7d82de26966bbc9723a49de95abd94 Auto-Submitted: auto-generated The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=48c59140bd7d82de26966bbc9723a49de95abd94 commit 48c59140bd7d82de26966bbc9723a49de95abd94 Author: Mark Johnston AuthorDate: 2024-10-19 13:03:56 +0000 Commit: Mark Johnston CommitDate: 2024-11-07 14:26:34 +0000 bus: Set the current VNET in device_attach() Some drivers, in particular anything which creates an ifnet during attach, need to have the current VNET set, as if_attach_internal() and its callees access VNET-global variables. device_probe_and_attach() handles this, but this is not the only way to arrive in DEVICE_ATTACH. In particular, bus drivers may invoke device_attach() directly, as does devctl2's DEV_ENABLE ioctl handler. So, set the current VNET in device_attach() instead. I believe it is always safe to use vnet0, as devctl2 ioctls are not permitted within a jail. PR: 282168 Reviewed by: zlei, kevans, bz, imp, glebius MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D47174 (cherry picked from commit f4e35c044c8988b7452cefbdcc417f5fd723e021) (cherry picked from commit 2e80ea70b98ef75f8bea9155944e6f093c0fa828) --- sys/kern/subr_bus.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c index 06c64ef28fba..9b4a4c65190a 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -2984,10 +2985,7 @@ device_probe_and_attach(device_t dev) else if (error != 0) return (error); - CURVNET_SET_QUIET(vnet0); - error = device_attach(dev); - CURVNET_RESTORE(); - return error; + return (device_attach(dev)); } /** @@ -3023,6 +3021,10 @@ device_attach(device_t dev) return (ENXIO); } + KASSERT(IS_DEFAULT_VNET(TD_TO_VNET(curthread)), + ("device_attach: curthread is not in default vnet")); + CURVNET_SET_QUIET(TD_TO_VNET(curthread)); + device_sysctl_init(dev); if (!device_is_quiet(dev)) device_print_child(dev->parent, dev); @@ -3037,8 +3039,10 @@ device_attach(device_t dev) device_sysctl_fini(dev); KASSERT(dev->busy == 0, ("attach failed but busy")); dev->state = DS_NOTPRESENT; + CURVNET_RESTORE(); return (error); } + CURVNET_RESTORE(); dev->flags |= DF_ATTACHED_ONCE; /* We only need the low bits of this time, but ranges from tens to thousands * have been seen, so keep 2 bytes' worth.