From nobody Sat Oct 19 13:04:19 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 4XW1xH5vVPz5b4vm; Sat, 19 Oct 2024 13:04:19 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XW1xH56B2z4QFP; Sat, 19 Oct 2024 13:04:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729343059; 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=5gqohjOUY6iOHVQbuJTXAqXv5d6JVbU9Gcd7/C8EBys=; b=hJVIMe15vxdHpcBfgfZFp/YyqCwzZjZkpXvO/EG7wTnvU2XAvz9jI8wh/6ohz1TcC2Xx+I od/1pcSfo4v7Z93CzQxYxng9IRyiozN2LXo7u9lp6tCsfT32tVTJyBHjWsZPjJPwN9VukE cWT43lCjF0O4Z6NJ8trvvcCX9k7ksnvqfLoaLPQwKREXDZUDQfJ3PN6K+fUanEDEsjct15 4EolBYmSsj1FCS9G7cHijnXWk8vvMVq1N572bs7otf1V3c4HzrTTk5yzCjqmqN4RlXAVH+ vD71an20ymw3+eWFqI+7fadit1kahXOHNS6qYlh2L4Jrd9e55hyCpro0BSNXWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729343059; 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=5gqohjOUY6iOHVQbuJTXAqXv5d6JVbU9Gcd7/C8EBys=; b=AgFQdtWZv3MPtoRNTpgi621bai356M4VD731g808thWdNUoKMc37476yXX+DM3ojnHaQau L1Vzdke7TQSr7RWk0k/2+oW2XAFwcPlj21GOUtBm/O0qHvf60s3NIhRuZrHp1b0srZGmZj zwe5rqVWiFFyLD280Sz4vQeumgw9YZwcs0ZxkzqEDzz4XNPtOWaVNOr98KgPIcQJhVa+8A XnM/ggJ4LLxIJ6Vj7K18KMeDqWNtomB+BYObiDZtFiZDrFvYc9BRwpntMuKVEbQW8RYaWN VK/4pISHDHfBdvyDfGrZYZouVgKTnsb9JofLmBzWswB1DlKv8lX34Vg0O2LFvQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729343059; a=rsa-sha256; cv=none; b=dPFe3zV4plarZ2cvoRdIEGcGLtMx9oVsrIuaVo1cesVY5dHJreApnv5CV01QK+2jmhUoyc Bk5FgohRH2ksyTHcLKkAqHokU8nVl6x6QQfdj2DDxGrvfb3i/uWx2aX9qxJBg32OPAFoyA GSuwg00UmH2HmOzy/8SXo/NCZCN4ek1KbmSUUUWO6gamZduoCPN9mx1knQx6VPZ42s0PIR 87mwJIFDOdlZoIoGQ343NBqE8P3dOTzSyik0fMvlIqvykKREc9uewSM4RPMxVNEcgNwUG5 O4mTqmwHs3KjV6WoEaX9xds5S7syKh+oUgxJBeYy/lg9DvDFvYCjKkkP3gAiFA== 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 4XW1xH4j6mzJFk; Sat, 19 Oct 2024 13:04:19 +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 49JD4JSG084004; Sat, 19 Oct 2024 13:04:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49JD4JoM084001; Sat, 19 Oct 2024 13:04:19 GMT (envelope-from git) Date: Sat, 19 Oct 2024 13:04:19 GMT Message-Id: <202410191304.49JD4JoM084001@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: f4e35c044c89 - main - 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/main X-Git-Reftype: branch X-Git-Commit: f4e35c044c8988b7452cefbdcc417f5fd723e021 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=f4e35c044c8988b7452cefbdcc417f5fd723e021 commit f4e35c044c8988b7452cefbdcc417f5fd723e021 Author: Mark Johnston AuthorDate: 2024-10-19 13:03:56 +0000 Commit: Mark Johnston CommitDate: 2024-10-19 13:03:56 +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 --- 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 70e5e22854f3..eeba75ac574a 100644 --- a/sys/kern/subr_bus.c +++ b/sys/kern/subr_bus.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -2538,10 +2539,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)); } /** @@ -2577,6 +2575,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); @@ -2609,8 +2611,10 @@ device_attach(device_t 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