From: Vincent MAILHOL <mailhol.vincent@wanadoo.fr>
To: Jiri Pirko <jiri@nvidia.com>
Cc: netdev@vger.kernel.org, "David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] net: devlink: devlink_nl_info_fill: populate default information
Date: Wed, 23 Nov 2022 20:00:44 +0900 [thread overview]
Message-ID: <CAMZ6Rq+jG=iAHCfFED7SE3jP8EnSSCWc2LLFv+YDKAf0ABe0YA@mail.gmail.com> (raw)
In-Reply-To: <Y33sD/atEWBTPinG@nanopsycho>
On Wed. 23 nov. 2022 à 18:46, Jiri Pirko <jiri@nvidia.com> wrote:
> Tue, Nov 22, 2022 at 04:49:34PM CET, mailhol.vincent@wanadoo.fr wrote:
> >Some piece of information are common to the vast majority of the
> >devices. Examples are:
> >
> > * the driver name.
> > * the serial number of a USB device.
> >
> >Modify devlink_nl_info_fill() to retrieve those information so that
> >the drivers do not have to. Rationale: factorize code.
> >
> >Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
> >---
> >I am sending this as an RFC because I just started to study devlink.
> >
> >I can see a parallel with ethtool for which the core will fill
> >whatever it can. c.f.:
> >commit f20a0a0519f3 ("ethtool: doc: clarify what drivers can implement in their get_drvinfo()")
> >Link: https://git.kernel.org/netdev/net-next/c/f20a0a0519f3
> >
> >I think that devlink should do the same.
> >
> >Right now, I identified two fields. If this RFC receive positive
> >feedback, I will iron it up and try to see if there is more that can
> >be filled by default.
> >
> >Thank you for your comments.
> >---
> > net/core/devlink.c | 36 ++++++++++++++++++++++++++++++++++++
> > 1 file changed, 36 insertions(+)
> >
> >diff --git a/net/core/devlink.c b/net/core/devlink.c
> >index 7f789bbcbbd7..1908b360caf7 100644
> >--- a/net/core/devlink.c
> >+++ b/net/core/devlink.c
> >@@ -18,6 +18,7 @@
> > #include <linux/netdevice.h>
> > #include <linux/spinlock.h>
> > #include <linux/refcount.h>
> >+#include <linux/usb.h>
> > #include <linux/workqueue.h>
> > #include <linux/u64_stats_sync.h>
> > #include <linux/timekeeping.h>
> >@@ -6685,12 +6686,37 @@ int devlink_info_version_running_put_ext(struct devlink_info_req *req,
> > }
> > EXPORT_SYMBOL_GPL(devlink_info_version_running_put_ext);
> >
> >+static int devlink_nl_driver_info_get(struct device_driver *drv,
> >+ struct devlink_info_req *req)
> >+{
> >+ if (!drv)
> >+ return 0;
> >+
> >+ if (drv->name[0])
> >+ return devlink_info_driver_name_put(req, drv->name);
>
> Make sure that this provides the same value for all existing drivers
> using devlink.
There are 21 drivers so far which reports the driver name through devlink. c.f.:
$ git grep "devlink_info_driver_name_put(" drivers | wc -l
Out of those 21, there is only one: the mlxsw which seems to report
something different than device_driver::name. Instead it reports some
bus_info:
https://elixir.bootlin.com/linux/v6.1-rc1/source/drivers/net/ethernet/mellanox/mlxsw/core.c#L1462
https://elixir.bootlin.com/linux/v6.1-rc1/source/drivers/net/ethernet/mellanox/mlxsw/core.h#L504
I am not sure what the bus_info is here, but it looks like a misuse of
the field here.
>
> >+
> >+ return 0;
> >+}
> >+
> >+static int devlink_nl_usb_info_get(struct usb_device *udev,
> >+ struct devlink_info_req *req)
> >+{
> >+ if (!udev)
> >+ return 0;
> >+
> >+ if (udev->serial[0])
> >+ return devlink_info_serial_number_put(req, udev->serial);
> >+
> >+ return 0;
> >+}
> >+
> > static int
> > devlink_nl_info_fill(struct sk_buff *msg, struct devlink *devlink,
> > enum devlink_command cmd, u32 portid,
> > u32 seq, int flags, struct netlink_ext_ack *extack)
> > {
> > struct devlink_info_req req = {};
> >+ struct device *dev = devlink_to_dev(devlink);
> > void *hdr;
> > int err;
> >
> >@@ -6707,6 +6733,16 @@ devlink_nl_info_fill(struct sk_buff *msg, struct devlink *devlink,
> > if (err)
> > goto err_cancel_msg;
> >
> >+ err = devlink_nl_driver_info_get(dev->driver, &req);
> >+ if (err)
> >+ goto err_cancel_msg;
> >+
> >+ if (!strcmp(dev->parent->type->name, "usb_device")) {
>
> Comparing to string does not seem correct here.
There is a is_usb_device() which does the check:
https://elixir.bootlin.com/linux/v6.1-rc1/source/drivers/usb/core/usb.h#L152
but this macro is not exposed outside of the usb core. The string
comparison was the only solution I found.
Do you have any other ideas? If not and if this goes further than the
RFC stage, I will ask the USB folks if there is a better way.
>
> >+ err = devlink_nl_usb_info_get(to_usb_device(dev->parent), &req);
>
> As Jakub pointed out, you have to make sure that driver does not put the
> same attrs again. You have to introduce this functionality with removing
> the fill-ups in drivers atomically, in a single patch.
Either this, either track if the attribute is already set. I would
prefer to remove all drivers fill-ups but this is not feasible for the
serial number. c.f. my reply to Jacub in this thread:
https://lore.kernel.org/netdev/CAMZ6RqJ8_=h1SS7WmBeEB=75wsvVUZrb-8ELCDtpZb0gSs=2+A@mail.gmail.com/
> >+ if (err)
> >+ goto err_cancel_msg;
> >+ }
> >+
> > genlmsg_end(msg, hdr);
> > return 0;
> >
> >--
> >2.37.4
> >
next prev parent reply other threads:[~2022-11-23 11:04 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-22 15:49 [RFC PATCH] net: devlink: devlink_nl_info_fill: populate default information Vincent Mailhol
2022-11-23 4:12 ` Jakub Kicinski
2022-11-23 9:42 ` Vincent MAILHOL
2022-11-24 3:06 ` Jakub Kicinski
2022-11-24 5:33 ` Vincent MAILHOL
2022-11-24 8:53 ` Jiri Pirko
2022-11-28 18:43 ` Jakub Kicinski
2022-11-28 23:14 ` Vincent MAILHOL
2022-11-23 9:46 ` Jiri Pirko
2022-11-23 11:00 ` Vincent MAILHOL [this message]
2022-11-23 12:10 ` Jiri Pirko
2022-11-23 16:08 ` Vincent MAILHOL
2022-11-23 16:26 ` Jiri Pirko
2022-11-24 16:20 ` Vincent MAILHOL
2022-11-27 8:15 ` [PATCH net-next v2 0/5] net: devlink: return the driver name in devlink_nl_info_fill Vincent Mailhol
2022-11-27 8:16 ` [PATCH net-next v2 1/5] mlxsw: minimal: fix mlxsw_m_module_get_drvinfo() to correctly report driver name Vincent Mailhol
2022-11-27 8:16 ` [PATCH net-next v2 2/5] mlxsw: core: fix mlxsw_devlink_info_get() " Vincent Mailhol
2022-11-27 8:16 ` [PATCH net-next v2 3/5] net: devlink: let the core report the driver name instead of the drivers Vincent Mailhol
2022-11-27 8:16 ` [PATCH net-next v2 4/5] net: devlink: remove devlink_info_driver_name_put() Vincent Mailhol
2022-11-27 12:01 ` kernel test robot
2022-11-27 12:11 ` kernel test robot
2022-11-27 8:16 ` [PATCH net-next v2 5/5] net: devlink: make the devlink_ops::info_get() callback optional Vincent Mailhol
2022-11-27 13:09 ` [PATCH net-next v3 0/5] net: devlink: return the driver name in devlink_nl_info_fill Vincent Mailhol
2022-11-27 13:09 ` [PATCH net-next v3 1/5] mlxsw: minimal: fix mlxsw_m_module_get_drvinfo() to correctly report driver name Vincent Mailhol
2022-11-27 16:14 ` Ido Schimmel
2022-11-27 13:09 ` [PATCH net-next v3 2/5] mlxsw: core: fix mlxsw_devlink_info_get() " Vincent Mailhol
2022-11-27 16:17 ` Ido Schimmel
2022-11-28 1:42 ` Vincent MAILHOL
2022-11-27 13:09 ` [PATCH net-next v3 3/5] net: devlink: let the core report the driver name instead of the drivers Vincent Mailhol
2022-11-27 13:09 ` [PATCH net-next v3 4/5] net: devlink: remove devlink_info_driver_name_put() Vincent Mailhol
2022-11-27 13:09 ` [PATCH net-next v3 5/5] net: devlink: make the devlink_ops::info_get() callback optional Vincent Mailhol
2022-11-28 4:15 ` [PATCH net-next v4 0/3] net: devlink: return the driver name in devlink_nl_info_fill Vincent Mailhol
2022-11-28 4:15 ` [PATCH net-next v4 1/3] net: devlink: let the core report the driver name instead of the drivers Vincent Mailhol
2022-11-28 11:49 ` Ido Schimmel
2022-11-28 4:15 ` [PATCH net-next v4 2/3] net: devlink: remove devlink_info_driver_name_put() Vincent Mailhol
2022-11-28 4:15 ` [PATCH net-next v4 3/3] net: devlink: make the devlink_ops::info_get() callback optional Vincent Mailhol
2022-11-28 18:42 ` Jakub Kicinski
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='CAMZ6Rq+jG=iAHCfFED7SE3jP8EnSSCWc2LLFv+YDKAf0ABe0YA@mail.gmail.com' \
--to=mailhol.vincent@wanadoo.fr \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jiri@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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;
as well as URLs for NNTP newsgroup(s).