🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #13937

[PATCH net-next v5 14/15] devlink: add devlink_alloc_drv()

#13937
From: Przemek Kitszel
Date: Tue, 10 Nov 2026 14:07
105 lines
13850 bytes
devlink_alloc() records the driver bound to @dev at the time of the
call as the owner of the new instance. That fits the common case of
a driver creating an instance for the device it is bound to, but not
a PF driver that creates instances for its VFs, as the VF device could
be:
 * not bound to any driver yet (VF driver not loaded, or
   sriov_drivers_autoprobe disabled), what triggers the WARN_ON() in
   __devlink_alloc();
 * bound to another driver (VF driver, or vfio-pci), which could be
   unloaded while the instance is still registered, leaving the stored
   driver pointer dangling (it is used to report the driver name in
   devlink dev info).

Add devlink_alloc_drv(), a variant of devlink_alloc() that takes the
owning driver explicitly, as devlink_shd_get() already does.

The first user is ice, in the next patch, which creates a devlink
instance for each of its VFs.

Such an instance reports the owning driver in devlink dev info, not the
one bound to the device in sysfs. Document that in devlink-info.rst.

Signed-off-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
---
v5:
 * document @drv lifetime and device lock rules in kernel-doc (me)

v4:
 * document in devlink-info.rst that an instance created for another
   device reports the name of the creating driver (Sashiko)

v3:
 * new patch
---
 .../networking/devlink/devlink-info.rst       |  2 ++
 include/net/devlink.h                         |  4 ++++
 net/devlink/core.c                            | 24 +++++++++++++++++++
 3 files changed, 30 insertions(+)

diff --git a/Documentation/networking/devlink/devlink-info.rst b/Documentation/networking/devlink/devlink-info.rst
index dd6adc4d0559..7ac5625e2934 100644
--- a/Documentation/networking/devlink/devlink-info.rst
+++ b/Documentation/networking/devlink/devlink-info.rst
@@ -25,6 +25,8 @@ versions is generally discouraged - here, and via any other Linux API.
      - Description
    * - ``driver``
      - Name of the currently used device driver, also available through sysfs.
+       For an instance that a driver creates for another device, e.g. a PF
+       driver for its VFs, the name of the creating driver.
 
    * - ``serial_number``
      - Serial number of the device.
diff --git a/include/net/devlink.h b/include/net/devlink.h
index d01128ef393d..5c90edf9a92d 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -1693,6 +1693,10 @@ static inline struct devlink *devlink_alloc(const struct devlink_ops *ops,
 	return devlink_alloc_ns(ops, priv_size, &init_net, dev);
 }
 
+struct devlink *devlink_alloc_drv(const struct devlink_ops *ops,
+				  size_t priv_size, struct device *dev,
+				  const struct device_driver *drv);
+
 int devl_register(struct devlink *devlink);
 void devl_unregister(struct devlink *devlink);
 void devlink_register(struct devlink *devlink);
diff --git a/net/devlink/core.c b/net/devlink/core.c
index 9b844e0c1bd2..e2a7169287ec 100644
--- a/net/devlink/core.c
+++ b/net/devlink/core.c
@@ -531,6 +531,30 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
 }
 EXPORT_SYMBOL_GPL(devlink_alloc_ns);
 
+/**
+ * devlink_alloc_drv - Allocate new devlink instance resources for given driver
+ * @ops: ops
+ * @priv_size: size of user private data
+ * @dev: parent device
+ * @drv: driver that owns the instance
+ *
+ * Variant of devlink_alloc() for a driver that creates an instance for
+ * a device bound to another (or no) driver, e.g. a PF driver for its VFs.
+ *
+ * @drv must not be NULL and must outlive the instance, only a pointer to it
+ * is kept. Operations that take the device lock, like reload, lock @dev,
+ * not a device bound to @drv.
+ *
+ * Return: new devlink instance, NULL on failure.
+ */
+struct devlink *devlink_alloc_drv(const struct devlink_ops *ops,
+				  size_t priv_size, struct device *dev,
+				  const struct device_driver *drv)
+{
+	return __devlink_alloc(ops, priv_size, &init_net, dev, drv);
+}
+EXPORT_SYMBOL_GPL(devlink_alloc_drv);
+
 /**
  *	devlink_free - Free devlink instance resources
  *
-- 
2.51.1
Technical Details
Message-ID: <20261110141534.95614-15-przemyslaw.kitszel@intel.com>
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-360305-linux-kernel-netdev=dewy.ru
References: <20261110141534.95614-1-przemyslaw.kitszel@intel.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!newsfeed.bofh.team!nntp.comgw.net!eternal-september.org!feeder.eternal-september.org!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-360305-linux-kernel-netdev=dewy.ru
From: przemyslaw.kitszel@intel.com (Przemek Kitszel)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next v5 14/15] devlink: add devlink_alloc_drv()
Date: Tue, 10 Nov 2026 15:07:23 +0100
Organization: Usenet Network
Message-ID: <20261110141534.95614-15-przemyslaw.kitszel@intel.com>
References: <20261110141534.95614-1-przemyslaw.kitszel@intel.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="626052"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:3HtscupBxhgsi3pdBjBQucBwXJM= sha256:PM6DNZ+6iFQMIJBBBwcTm3RI5x89zZrS3zDuxNdRD+s=
	sha1:0UOW01sXEF5XQ1X1ObjhCitq+QA= sha256:dMnr0G3KB6s3qMveJTM1oe1qGriijNmeIAlcAZqU4FI=
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 33173113BD1; Tue, 10 Nov 2026 17:24:53 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.051
X-Spam-Status: No, score=-3.051 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=intel.com
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 ZnwEXSFFGWJO;
	Tue, 10 Nov 2026 17:24:48 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-360305-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=intel.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id 8673F113BCF; Tue, 10 Nov 2026 17:24:38 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id CF5F0E5D72; Tue, 10 Nov 2026 14:17:00 +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=1794320177;
	b=sxHJIjgibjvrlR6sAMA2So+BGtOQUTVRnTE67P2+qHEEyhwktBwVjHDHHn9vZJXID9GZ
	 KqTVZUKgDtF2DkxaZgJOL37YxcLPwP01DAdAXDYvVsqpGqIee+5NNNPGSPSnZGX+R6JgM
	 1Jyrz7Z9Y9/urEU6kIdeILBpvDwcDs7Dzsu3nfjKvgPyU8rmXKL2t0JxQNTIbUww2nrTc
	 nr+5lSRw8OBSUje5xB18hWhGuw7xX1Wt+U+DEfg3Gm2naAr7qllWBx9RFaTttP6bB5cY2
	 x2xHGQHtkFNb4+9e3tVz/wQpwuuTRbNp7oux0tk9a7Y3twWVmyjoJETw8t48Ar/SvDA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794320177;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:
	 X-CSE-ConnectionGUID:X-CSE-MsgGUID:X-IronPort-AV:X-IronPort-AV:
	 Received:X-CSE-ConnectionGUID:X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:
	 Received:Received: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-Transfer-Encoding;
	bh=izSUfxKd6dpHrZ2HluV6tGvbB14A6G9yE/pB2+OCf8g=;
	b=khwuZxBEJBl6VCcuv/+ukFhnAJNNqbpRSLNYr595aJJunMMH2IAexO9c6yJVf+mefM5t
	 mbYMABtpP5UeWP5tf2YLrRJPFI5cC4KKOjanToBJdSV1AOYkldLfaR5q3ztq73Wl4lnut
	 XI6UWq57jNvRHCYK4PnERy4wjfx+6h/9jge0z/4EGqFyM6Dn/KN8eKD6YlBMQZyN3VLru
	 a98TctEfocupNH9h8egfJefofsJllngDYngLIXVyNs7rTTrj+FM0fkh+pCoM4WpE7SBgD
	 Lh5JhDTcH+qDQCGVpgmpEr5U19vwJuNF0sOjJJCxxVbF96+yB0tkHHfmx2k6X6Rj6AA==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=ElPj3a1n;
	dmarc=pass header.from=intel.com;
	spf=pass smtp.mailfrom=intel.com;
	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 4687060A383C;
	Tue, 10 Nov 2026 14:16:17 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=ElPj3a1n
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.17
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1794320176;
	b=U1E7tVLyiDGlLIqlQRQhovcK2Tg7yP93PwEEa5rI3vSm5SWp7ocPmqC48wNuDDXa2Ze5
	 ZLGMPPAdInUL+xhZxETTVYnkBnz3QFlh224IBwxxsW4CnpWMv5xpe/Kkhl4nJ34b6mrtg
	 Y6xrPx1YOTqCaGzR/8YCeQG+eKJF+73L42k0UPVJ0Gzgxm1EsUhZJJx9ICEWF/eCIY6zL
	 sUxIhPau8bu6EpV4bfsFmEVdvWLrfUMMBN1U9sVC7y+nFPQrHyePswfxUo3A8HnKe+f4E
	 6lqgjdf5JPqRNQaYBviFlbQeI18RSjT19hGizJJg/6GB3gNwWnv+XZrm5UXWESs3l4g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1794320176;
	h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID:
	 X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID:
	 X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Received:From:To:Cc:
	 Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding;
	bh=izSUfxKd6dpHrZ2HluV6tGvbB14A6G9yE/pB2+OCf8g=;
	b=j4XE2dCzLPDxZZgf1ke7ffeYVbjoz8Mvi1Bg75TcWoRyKxg0QDGw4MxKO1rtpSbEwGzv
	 LnzJtICoXzANjw6SQTe0Dc32kRO96K1+IYeawFDJ5KQCgWwJl+TbsSYI/ot8oBm1VVtno
	 65Bzeqh9q9oCY+gTffhutfJbjVISm29pxlpIHbs10RzqZY1CJ8N75QZo10zLeXD6zTWjR
	 wjb8AtCiqunU+anrFKMdcP9uoWdjuZUHFI5+81dw+BZSxklKLWtqVt3tpZyV2pnuKXNbi
	 vHNjHT2McEG/a2TWvsJoIAfFMrz9d89C+bI2TWenruiBAXa/nxBM55/zgoueT/wmr3g==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=intel.com;
	spf=pass smtp.mailfrom=intel.com;
	dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=ElPj3a1n;
	arc=none smtp.remote-ip=198.175.65.17
X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17])
	(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8B5C760A2621
	for <netdev@vger.kernel.org>; Tue, 10 Nov 2026 14:16:15 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 8B5C760A2621
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
  d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
  t=1794320175; x=1825856175;
  h=from:to:cc:subject:date:message-id:in-reply-to:
   references:mime-version:content-transfer-encoding;
  bh=k5Jwp5jS5CKa8GO7E0EUouk8YBhlJ1hq55LDY4GsRm0=;
  b=ElPj3a1nGFouol41mEG20peLMg3U9+DrqHRmxIO2qEUDfXwtXt2rokGn
   XjrCIdLsl6UJKLiCXB48VFmQLabRUTVczqOTwUQDXBNr8uFveADqH92ez
   PW+QPD0/Nxs+Mkt1eAD4K8Uo0t3bzx0PyFIYiOhGnyytK87kKUqc1EQL+
   fRUV+3FIUKFQ5aT1lkCBZL+B702ZGNnv7Oek6DXKEgRo0WVXd69LH6ob3
   CjejslkX2wS5dtJl+BVEHGZ6ENOfIkmSyBMuEqcevxZxp9FY8TRlJPtVr
   +zeEK8LhK1ddyjTvmnMhP/BWEY8MBzxXO8izmu02icC7D1pGDkPrGofIa
   g==;
X-CSE-ConnectionGUID: AEm/BRcDR92yN0XHpcijZw==
X-CSE-MsgGUID: P9mRluaZQDy+oxfbkauSYA==
X-IronPort-AV: E=McAfee;i="6800,10657,11961"; a="3091223"
X-IronPort-AV: E=Sophos;i="6.27,205,1787036400"; 
   d="scan'208";a="3091223"
X-Received: from fmviesa003.fm.intel.com ([10.60.135.143])
  by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2026 06:16:15 -0800
X-CSE-ConnectionGUID: Yy9r+N9dQpu/JcWf1qyVig==
X-CSE-MsgGUID: Ed+MeENWS+mCw5tLZ2QwyQ==
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="6.27,205,1787036400"; 
   d="scan'208";a="8327672"
X-Received: from irvmail002.ir.intel.com ([10.43.11.120])
  by fmviesa003.fm.intel.com with ESMTP; 10 Nov 2026 06:16:10 -0800
X-Received: from pkitszel-desk.tendawifi.com (unknown [10.245.244.251])
	by irvmail002.ir.intel.com (Postfix) with ESMTP id 5E0652FC5F;
	Tue, 10 Nov 2026 14:16:08 +0000 (GMT)
X-Cc: Tony Nguyen <anthony.l.nguyen@intel.com>,
	Aleksandr Loktionov <aleksandr.loktionov@intel.com>,
	Michal Schmidt <mschmidt@redhat.com>,
	edumazet@kernel.org,
	horms@kernel.org,
	pabeni@redhat.com,
	davem@davemloft.net,
	Jiri Pirko <jiri@resnulli.us>,
	Jonathan Corbet <corbet@lwn.net>,
	skhan@linuxfoundation.org,
	rdunlap@infradead.org,
	andrew+netdev@lunn.ch,
	saeedm@nvidia.com,
	tariqt@nvidia.com,
	leon@kernel.org,
	mbloch@nvidia.com,
	jacob.e.keller@intel.com,
	jedrzej.jagielski@intel.com,
	anzaki@gmail.com,
	brett.creeley@amd.com,
	ohartoov@nvidia.com,
	Petr Oros <poros@redhat.com>,
	Przemek Kitszel <przemyslaw.kitszel@intel.com>
X-Mailer: git-send-email 2.51.1
X-In-Reply-To: <20261110141534.95614-1-przemyslaw.kitszel@intel.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