Article View: linux.kernel.netdev
Article #26339[PATCH v5 30/33] driver core: Allow driver attachment with the device lock held
From: Leon Romanovsky
Date: Thu, 03 Dec 2026 12:03
Date: Thu, 03 Dec 2026 12:03
101 lines
11597 bytes
11597 bytes
From: Leon Romanovsky <leonro@nvidia.com>
USB authorization needs to keep driver attachment and its configuration
result under the same device lock. Dropping the lock to call
device_attach() would let another request change that result before the
authorizing caller can inspect it.
Provide synchronous attachment for callers that already hold the device
lock. Keep asynchronous scheduling outside the lock in the existing path.
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
drivers/base/dd.c | 34 ++++++++++++++++++++++++++++++----
include/linux/device.h | 1 +
2 files changed, 31 insertions(+), 4 deletions(-)
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 4c4723384dc6..2f45b53e5ba9 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -1222,12 +1222,11 @@ static void __device_attach_async_helper(void *_dev, async_cookie_t cookie)
put_device(dev);
}
-static int __device_attach(struct device *dev, bool allow_async)
+static int __device_attach_locked(struct device *dev, bool allow_async,
+ bool *async)
{
int ret = 0;
- bool async = false;
- device_lock(dev);
mutex_lock(&dev->p->driver_lock);
if (dev->p->dead) {
goto out_unlock;
@@ -1265,7 +1264,7 @@ static int __device_attach(struct device *dev, bool allow_async)
*/
dev_dbg(dev, "scheduling asynchronous probe\n");
get_device(dev);
- async = true;
+ *async = true;
} else {
pm_request_idle(dev);
}
@@ -1275,6 +1274,16 @@ static int __device_attach(struct device *dev, bool allow_async)
}
out_unlock:
mutex_unlock(&dev->p->driver_lock);
+ return ret;
+}
+
+static int __device_attach(struct device *dev, bool allow_async)
+{
+ bool async = false;
+ int ret;
+
+ device_lock(dev);
+ ret = __device_attach_locked(dev, allow_async, &async);
device_unlock(dev);
if (async && !async_schedule_dev_nocall(__device_attach_async_helper, dev)) {
put_device(dev);
@@ -1284,6 +1293,23 @@ static int __device_attach(struct device *dev, bool allow_async)
return ret;
}
+/**
+ * device_attach_locked - try to attach a driver with the device locked
+ * @dev: device to attach
+ *
+ * Synchronous device_attach() with the device lock held by the caller.
+ * When called for a USB interface, the parent lock must also be held.
+ * The device lock remains held on return.
+ *
+ * Return: 1 if bound, 0 if no driver bound, or a negative error.
+ */
+int device_attach_locked(struct device *dev)
+{
+ device_lock_assert(dev);
+ return __device_attach_locked(dev, false, NULL);
+}
+EXPORT_SYMBOL_GPL(device_attach_locked);
+
/**
* device_attach - try to attach device to a driver.
* @dev: device.
diff --git a/include/linux/device.h b/include/linux/device.h
index 5c86e7a19e47..3857545f67df 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -1337,6 +1337,7 @@ int __must_check device_driver_attach_unrestricted(
int __must_check device_bind_driver(struct device *dev);
void device_release_driver(struct device *dev);
int __must_check device_attach(struct device *dev);
+int __must_check device_attach_locked(struct device *dev);
int __must_check driver_attach(const struct device_driver *drv);
void device_initial_probe(struct device *dev);
int __must_check device_reprobe(struct device *dev);
--
2.56.1
Technical Details
Message-ID:
<20261203-device-trust-core-v5-30-485cc6eddd46@nvidia.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376564-linux-kernel-netdev=dewy.ruReferences:
<20261203-device-trust-core-v5-0-485cc6eddd46@nvidia.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu.MISMATCH!feed-us-txt.newsdeef.eu!feed-us-ny.newsdeef.eu!srv.newsdeef.eu!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!srl.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-376564-linux-kernel-netdev=dewy.ru From: leon@kernel.org (Leon Romanovsky) Newsgroups: linux.kernel.netdev Subject: [PATCH v5 30/33] driver core: Allow driver attachment with the device lock held Date: Thu, 3 Dec 2026 14:03:52 +0200 Organization: Usenet Network Message-ID: <20261203-device-trust-core-v5-30-485cc6eddd46@nvidia.com> References: <20261203-device-trust-core-v5-0-485cc6eddd46@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Injection-Info: usenet.network; logging-data="2482200"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:l4sagCeNcbnDxWSwngwlJ7WjXD8= sha256:0QIK2luFSFSmNi8Ie0b2R6+LEHOuAKLj8y9bTdF2QVQ= sha1:8G1bpUvg+TMbyly5u8JXdFwx7x0= sha256:m0tj/KyiXFk84dSUHlUb75Gp3XBxS27F/q1ujpzOmDk= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id E359111791C; Thu, 3 Dec 2026 15:10:09 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -2.64 X-Spam-Status: No, score=-2.64 tagged_above=-9999 required=6.31 tests=[DCC_CHECK=1.1, DKIMWL_WL_HIGH=-0.24, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4iWr2vkymhf6; Thu, 3 Dec 2026 15:10:07 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.232.135.74; helo=sto.lore.kernel.org; envelope-from=netdev+bounces-376564-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mail.dewy.ru (Postfix) with ESMTPS id C4A7D117917; Thu, 3 Dec 2026 15:09:56 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sto.lore.kernel.org (Postfix) with ESMTP id E69B4603DF8; Thu, 3 Dec 2026 12:09:55 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796299540; b=goh+5vhiiCsA3V9S3kqMEST39dTi7B8IbU101oikunVB3SGSq2A9wRfmH+Uz7nPaU5Gy Rf2DONwHsdnpk/wSshwYhQFtTvT3cbNqT9roDqwgt0VIE9NJrycq7jrbM06fxIJbv1ErT gHrJIJbt5oTr3Vj5KcGuMYnXPgJ1w56szeeyH7t53RyD5+eMROKtk/h18a4zsjjn64Efy 8LIuOFef7Mvz0B6J3hpK2SltHdu7U8RmXisfZg6EsULDfPXEeipV5rEtDJxyoi/1CBku4 5pFhPVdVsybBOAc5zO3YpZEbg7PTQF2ALuWxWYu2qo5C107OQnEgSkljE1K9irMwQIA== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796299540; h=X-Original-To:Received:Received:DKIM-Signature:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:X-Mailing-List: List-Id:List-Post:List-Help:List-Subscribe:List-Unsubscribe: List-Owner:Precedence:MIME-Version:Content-Type:X-Mailer: Content-Transfer-Encoding; bh=cwf3r85ZZQ4dQFBUbB7R1mqtLuwg531HdWJJlZTABxQ=; b=Sf+gtattjgEefRBg2vmxysu9Yqm3El5ZEMk9ioNesrpVGxAzQPdCUw6dvpaA87F6j622 QCPxzML3uscVtnSH5VHgz4LKUr0Ay1FUq3tV8SM3iAwOjXlNoKY4tYlMoPSP/6SdMnhQJ b1bozK4kSt45apK2KUueEOxBxJIE5X/vzlCMEuEfjO6JL8wBT7bGNv+8xKX9Ys4JC9OVo xGOmx/2Mum1B7AwlD6kxMpCuBGY4odDbSlcEtZBAw1S0f5a63CDcpa8SiJ3wGogjNy6fv HxRMevK60BlmFWjx1Aw2bbG3Ey35BN9YnJmcEKK89OIK7dfwAJ7Ylx7GAk29JJsAq1A== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IYNAM+S0; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D6A62606BCD7; Thu, 3 Dec 2026 12:05:40 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IYNAM+S0 X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796299535; b=UswMiThGklMPowtUgSEYbtUm1sUjrOJA3CWuIcr6HRkGaGaaulxBGI3lyW/kGZdEu47t D3VOZhP/4SBVUbXm8KPy7P88/BDziZsV3dHyhvdZ++RzZnf6jml+EygjH1MHX7V1o3uyY msycuLPjgpwmkxXMXGNNcDI6Pk7spL7d40AMlkd8dMjRSw2HeMLj5WuupGXTaq9+FFH/a rzKjuBQzGvNM+dzRm3yy40bxqcF2YJvpKKmk4rSvDiIm7/RsNSaoPS35Gek7Qe6MHMn7G 87Z7cM9Nq48GKvRLICkR9rNxWc6xGTfH7BDO8+tcP5Owhj/OPzlmYsaymJ0BId1kmYw== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796299535; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Type:X-Mailer: Content-Transfer-Encoding; bh=cwf3r85ZZQ4dQFBUbB7R1mqtLuwg531HdWJJlZTABxQ=; b=WGYx4oxzudX003OMC42/4VL5XxNrr4JbV021iqbVjM9x4PkTrLCDxGSj8eZK6afXiI5t bAHi1deAM/fCZfgV9HVdOibmk0TdLd+zc7vqAF0JxqVlfgYvUzvuBmkexqFKlPwSRE/GZ 4SKmr4A2XsW1gbWrTGxhiFVacBPEI+IA8KAJvRgQwzv8l6T7C86RJczqabCQZYP7GuURY LiWP9cBDitLwqsREVu1hu+dni8M3litoniQIsxl/gQhe3pAok0dSJ+3WUm5ijJa1GXi9k rmgjErg3ZJO2hniGSBeD4nXc2W8Llz/3BbwTHXd9GCc0CWcDCpV9F1FeL+1A6VqAudg== X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=IYNAM+S0; arc=none smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F19E6606BB9B; Thu, 3 Dec 2026 12:05:34 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5DB91F0089B; Thu, 3 Dec 2026 12:05:33 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796299534; bh=cwf3r85ZZQ4dQFBUbB7R1mqtLuwg531HdWJJlZTABxQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IYNAM+S0bQNcFk76XHdYeamksJT66YPgJXFhSDzjUJ6zmwCBVk2QWvsK3lphzYrAE ccdFEdfJ7sEPCKShbZAaamFYUAQmtSybCRtsIzbBoCjUQbqNVnojcO1ZQpT2/tJsA1 cEhTk6IdqP/XBA5MhOtR2mt/2+jhBb3UBWoG6h99wWP7BRI3qq/c05p0PCrj4q2hGY sPm/gDvy1magPWXhBGO4YRUVx7wJsZPDYFoRvvtN/4n5Q0762l8VZPLA+P252609jf va5AtopCbO+eeQHTVNrIPpISmcey0aP7Mbo0Yxy06E1zeAM3DsmLHU1jjQai0Sk/cQ a77CZnEBnaP2w== X-Cc: linux-kernel@vger.kernel.org, driver-core@lists.linux.dev, linux-input@vger.kernel.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, linux-usb@vger.kernel.org, linux-bluetooth@vger.kernel.org, linux-acpi@vger.kernel.org, linux-doc@vger.kernel.org, linux-pci@vger.kernel.org, iommu@lists.linux.dev, linux-coco@lists.linux.dev, Alexey Kardashevskiy <aik@amd.com>, Luiz Augusto von Dentz <luiz.von.dentz@intel.com>, Greg Kroah-Hartman <gregkh@suse.de>, linux-sound@vger.kernel.org, Jason Gunthorpe <jgg@ziepe.ca> X-Mailer: git-send-email 2.56.1 X-In-Reply-To: <20261203-device-trust-core-v5-0-485cc6eddd46@nvidia.com> X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-Mailer: b4 0.17-dev-d2b70