Netdev List
 help / color / mirror / Atom feed
From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
To: netdev@vger.kernel.org
Cc: Tony Nguyen <anthony.l.nguyen@intel.com>,
	Aleksandr Loktionov <aleksandr.loktionov@intel.com>,
	Michal Schmidt <mschmidt@redhat.com>,
	Jakub Kicinski <kuba@kernel.org>,
	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, jtornosm@redhat.com, ohartoov@nvidia.com,
	Przemek Kitszel <przemyslaw.kitszel@intel.com>
Subject: [PATCH net-next v3 14/15] devlink: add devlink_alloc_drv()
Date: Thu, 15 Oct 2026 20:51:25 +0200	[thread overview]
Message-ID: <20261015185454.6332-15-przemyslaw.kitszel@intel.com> (raw)
In-Reply-To: <20261015185454.6332-1-przemyslaw.kitszel@intel.com>

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.

Signed-off-by: Przemek Kitszel <przemyslaw.kitszel@intel.com>
---
v3:
 * new patch
---
 include/net/devlink.h |  4 ++++
 net/devlink/core.c    | 20 ++++++++++++++++++++
 2 files changed, 24 insertions(+)

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 bddbbbf000fe..8590a22b0d93 100644
--- a/net/devlink/core.c
+++ b/net/devlink/core.c
@@ -531,6 +531,26 @@ 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.
+ *
+ * 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


  parent reply	other threads:[~2026-10-15 18:55 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15 18:51 [PATCH net-next v3 00/15] devlink, mlx5, iavf, ice: XLVF for iavf Przemek Kitszel
2026-10-15 18:51 ` [PATCH net-next v3 01/15] devlink, mlx5: add init/fini ops for shared devlink Przemek Kitszel
2026-10-19 18:50   ` Tariq Toukan
2026-10-15 18:51 ` [PATCH net-next v3 02/15] ice: use shared devlink to store ice_adapters instead of custom xarray Przemek Kitszel
2026-10-15 18:51 ` [PATCH net-next v3 03/15] ice: add VF queue ena/dis helper functions Przemek Kitszel
2026-10-15 18:51 ` [PATCH net-next v3 04/15] ice: add helpers for Global RSS LUT alloc, free, vsi_update Przemek Kitszel
2026-10-15 18:51 ` [PATCH net-next v3 05/15] ice: rename ICE_MAX_RSS_QS_PER_VF to ICE_MAX_QS_PER_VF_VCV1 Przemek Kitszel
2026-10-15 18:51 ` [PATCH net-next v3 06/15] ice: bump to 256qs for VF Przemek Kitszel
2026-10-15 18:51 ` [PATCH net-next v3 07/15] iavf: extend iavf_configure_queues() to support more queues Przemek Kitszel
2026-10-15 18:51 ` [PATCH net-next v3 08/15] iavf: temporary rename of IAVF_MAX_REQ_QUEUES to IAVF_MAX_REQ_QUEUES_VCV1 Przemek Kitszel
2026-10-15 18:51 ` [PATCH net-next v3 09/15] iavf: increase max number of queues to 256 Przemek Kitszel
2026-10-15 18:51 ` [PATCH net-next v3 10/15] iavf: use new opcodes to request more than 16 queues Przemek Kitszel
2026-10-15 18:51 ` [PATCH net-next v3 11/15] ice: introduce handling of virtchnl LARGE VF opcodes Przemek Kitszel
2026-10-15 18:51 ` [PATCH net-next v3 12/15] devlink: give user option to allocate resources Przemek Kitszel
2026-10-21  3:20   ` Jakub Kicinski
2026-10-15 18:51 ` [PATCH net-next v3 13/15] ice: represent RSS LUTs as devlink resources Przemek Kitszel
2026-10-21  3:20   ` Jakub Kicinski
2026-10-15 18:51 ` Przemek Kitszel [this message]
2026-10-15 18:51 ` [PATCH net-next v3 15/15] ice: support up to 256 VF queues Przemek Kitszel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261015185454.6332-15-przemyslaw.kitszel@intel.com \
    --to=przemyslaw.kitszel@intel.com \
    --cc=aleksandr.loktionov@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=anthony.l.nguyen@intel.com \
    --cc=anzaki@gmail.com \
    --cc=brett.creeley@amd.com \
    --cc=corbet@lwn.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=jacob.e.keller@intel.com \
    --cc=jedrzej.jagielski@intel.com \
    --cc=jiri@resnulli.us \
    --cc=jtornosm@redhat.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=mbloch@nvidia.com \
    --cc=mschmidt@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=ohartoov@nvidia.com \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=saeedm@nvidia.com \
    --cc=skhan@linuxfoundation.org \
    --cc=tariqt@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox