Skip to contentSkip to conversation

ethtool: ethtool_get_drvinfo: populate drvinfo fields even if callback exits

PATCH Applied Vincent Mailhol 5 participants 16 messages Nov 8, 2022 – Nov 11, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ethtool: ethtool_get_drvinfo: populate drvinfo fields even if callback exits

If ethtool_ops::get_drvinfo() callback isn't set, ethtool_get_drvinfo() will fill the ethtool_drvinfo::name and ethtool_drvinfo::bus_info fields.

However, if the driver provides the callback function, those two fields are not touched. This means that the driver has to fill these itself.

Allow the driver to leave those two fields empty and populate them in such case. This way, the driver can rely on the default values for the name and the bus_info. If the driver provides values, do nothing.

---
 net/ethtool/ioctl.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
net/ethtool/ioctl.c +10 -3
index 57e7238a4136..546f931c3b6c 100644
@@ -713,15 +713,22 @@ static int
 ethtool_get_drvinfo(struct net_device *dev, struct ethtool_devlink_compat *rsp)
 {
 	const struct ethtool_ops *ops = dev->ethtool_ops;
+	struct device *parent = dev->dev.parent;
 
 	rsp->info.cmd = ETHTOOL_GDRVINFO;
 	strscpy(rsp->info.version, UTS_RELEASE, sizeof(rsp->info.version));
 	if (ops->get_drvinfo) {
 		ops->get_drvinfo(dev, &rsp->info);
-	} else if (dev->dev.parent && dev->dev.parent->driver) {
-		strscpy(rsp->info.bus_info, dev_name(dev->dev.parent),
+		if (!rsp->info.bus_info[0] && parent)
+			strscpy(rsp->info.bus_info, dev_name(parent),
+				sizeof(rsp->info.bus_info));
+		if (!rsp->info.driver[0] && parent && parent->driver)
+			strscpy(rsp->info.driver, parent->driver->name,
+				sizeof(rsp->info.driver));
+	} else if (parent && parent->driver) {
+		strscpy(rsp->info.bus_info, dev_name(parent),
 			sizeof(rsp->info.bus_info));
-		strscpy(rsp->info.driver, dev->dev.parent->driver->name,
+		strscpy(rsp->info.driver, parent->driver->name,
 			sizeof(rsp->info.driver));
 	} else if (dev->rtnl_link_ops) {
 		strscpy(rsp->info.driver, dev->rtnl_link_ops->kind,
Signature · 1 line
2.37.4
#1 lore raw
Quoted 7 lines · Vincent Mailhol

If ethtool_ops::get_drvinfo() callback isn't set, ethtool_get_drvinfo() will fill the ethtool_drvinfo::name and ethtool_drvinfo::bus_info fields.

However, if the driver provides the callback function, those two fields are not touched. This means that the driver has to fill these itself.

Can you please point to such drivers? One can argue that they don't need to touch these fields in a first place and ethtool_drvinfo should always overwrite them.

Thanks

maintainer
#2 lore raw
Quoted 10 lines · On Wed, 9 Nov 2022 19:52:13 +0200 Leon Romanovsky wrote:
Quoted 7 lines · Vincent Mailhol

If ethtool_ops::get_drvinfo() callback isn't set, ethtool_get_drvinfo() will fill the ethtool_drvinfo::name and ethtool_drvinfo::bus_info fields.

However, if the driver provides the callback function, those two fields are not touched. This means that the driver has to fill these itself.

Can you please point to such drivers?

What you mean by "such drivers" is not clear from the quoted context, at least to me.

Quoted 2 lines

One can argue that they don't need to touch these fields in a first place and ethtool_drvinfo should always overwrite them.

Quite likely most driver prints to .driver and .bus_info can be dropped with this patch in place. Then again, I'm suspecting it's a bit of a chicken and an egg problem with people adding new drivers not having an incentive to add the print in the core and people who want to add the print in the core not having any driver that would benefit. Therefore I'd lean towards accepting Vincent's patch as is even if the submission can likely be more thorough and strict.

While I'm typing - I've used dev_driver_string() to get the driver name in the past. Perhaps something to consider?

#3 lore raw
Quoted 6 lines · Jakub Kicinski
Quoted 5 lines · On Wed, 9 Nov 2022 19:52:13 +0200 Leon Romanovsky wrote:
Quoted 4 lines · Vincent Mailhol

If ethtool_ops::get_drvinfo() callback isn't set, ethtool_get_drvinfo() will fill the ethtool_drvinfo::name and ethtool_drvinfo::bus_info fields.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

However, if the driver provides the callback function, those two fields are not touched. This means that the driver has to fill these itself.

Can you please point to such drivers?

What you mean by "such drivers" is not clear from the quoted context, at least to me.

An example:
https://elixir.bootlin.com/linux/latest/source/drivers/net/ethernet/broadcom/bnx2.c#L7041

This driver wants to set fw_version but needs to also fill the driver name and bus_info. My patch will enable *such drivers* to only fill the fw_version and delegate the rest to the core.

Quoted 10 lines
Quoted 2 lines

One can argue that they don't need to touch these fields in a first place and ethtool_drvinfo should always overwrite them.

Quite likely most driver prints to .driver and .bus_info can be dropped with this patch in place. Then again, I'm suspecting it's a bit of a chicken and an egg problem with people adding new drivers not having an incentive to add the print in the core and people who want to add the print in the core not having any driver that would benefit. Therefore I'd lean towards accepting Vincent's patch as is even if the submission can likely be more thorough and strict.

If we can agree that no drivers should ever print .driver and .bus_info, then I am fine to send a clean-up patch to remove all this after this one gets accepted. However, I am not willing to invest time for nothing. So would one of you be ready to sign-off such a clean-up patch?

Quoted 2 lines

While I'm typing - I've used dev_driver_string() to get the driver name in the past. Perhaps something to consider?

I am not sure of that one. If dev->dev.parent->driver is not set, it defaults to dev_bus_name() which is .bus_info, isn't it?
https://elixir.bootlin.com/linux/latest/source/drivers/base/core.c#L2181

For the end user, it might be better to display an empty driver name
in 'ethtool -i' rather than reporting the bus_info twice?

I mean, if you ask me for my opinion, then my answer is "I am not sure". If you have confidence that dev_driver_string() is better, then I will send a v2 right away.

Yours sincerely,
Vincent Mailhol

#4 lore raw
Quoted 16 lines · Vincent MAILHOL
Quoted 6 lines · Jakub Kicinski
Quoted 5 lines · On Wed, 9 Nov 2022 19:52:13 +0200 Leon Romanovsky wrote:
Quoted 4 lines · Vincent Mailhol

If ethtool_ops::get_drvinfo() callback isn't set, ethtool_get_drvinfo() will fill the ethtool_drvinfo::name and ethtool_drvinfo::bus_info fields.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

However, if the driver provides the callback function, those two fields are not touched. This means that the driver has to fill these itself.

Can you please point to such drivers?

What you mean by "such drivers" is not clear from the quoted context, at least to me.

Quoted 6 lines

An example:
https://elixir.bootlin.com/linux/latest/source/drivers/net/ethernet/broadcom/bnx2.c#L7041

This driver wants to set fw_version but needs to also fill the driver name and bus_info. My patch will enable *such drivers* to only fill the fw_version and delegate the rest to the core.

Sorry for being misleading, It looks like I typed only part of the sentence which I had in my mind. I wanted to see if any driver exists which prints drv_name and bus_info different from default.

Quoted 12 lines
Quoted 11 lines
Quoted 3 lines

One can argue that they don't need to touch these fields in a first place and ethtool_drvinfo should always overwrite them.

Quite likely most driver prints to .driver and .bus_info can be dropped with this patch in place. Then again, I'm suspecting it's a bit of a chicken and an egg problem with people adding new drivers not having an incentive to add the print in the core and people who want to add the print in the core not having any driver that would benefit. Therefore I'd lean towards accepting Vincent's patch as is even if the submission can likely be more thorough and strict.

Quoted 5 lines

If we can agree that no drivers should ever print .driver and .bus_info, then I am fine to send a clean-up patch to remove all this after this one gets accepted. However, I am not willing to invest time for nothing. So would one of you be ready to sign-off such a clean-up patch?

I will be happy to see such patch and will review it, but can't add sign-off as I'm not netdev maintainer.

Thanks

#5 lore raw
Quoted 40 lines · Leon Romanovsky
Quoted 16 lines · Vincent MAILHOL
Quoted 6 lines · Jakub Kicinski
Quoted 5 lines · On Wed, 9 Nov 2022 19:52:13 +0200 Leon Romanovsky wrote:
Quoted 4 lines · Vincent Mailhol

If ethtool_ops::get_drvinfo() callback isn't set, ethtool_get_drvinfo() will fill the ethtool_drvinfo::name and ethtool_drvinfo::bus_info fields.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

However, if the driver provides the callback function, those two fields are not touched. This means that the driver has to fill these itself.

Can you please point to such drivers?

What you mean by "such drivers" is not clear from the quoted context, at least to me.

Quoted 6 lines

An example:
https://elixir.bootlin.com/linux/latest/source/drivers/net/ethernet/broadcom/bnx2.c#L7041

This driver wants to set fw_version but needs to also fill the driver name and bus_info. My patch will enable *such drivers* to only fill the fw_version and delegate the rest to the core.

Sorry for being misleading, It looks like I typed only part of the sentence which I had in my mind. I wanted to see if any driver exists which prints drv_name and bus_info different from default.

Quoted 12 lines
Quoted 11 lines
Quoted 3 lines

One can argue that they don't need to touch these fields in a first place and ethtool_drvinfo should always overwrite them.

Quite likely most driver prints to .driver and .bus_info can be dropped with this patch in place. Then again, I'm suspecting it's a bit of a chicken and an egg problem with people adding new drivers not having an incentive to add the print in the core and people who want to add the print in the core not having any driver that would benefit. Therefore I'd lean towards accepting Vincent's patch as is even if the submission can likely be more thorough and strict.

Quoted 8 lines
Quoted 5 lines

If we can agree that no drivers should ever print .driver and .bus_info, then I am fine to send a clean-up patch to remove all this after this one gets accepted. However, I am not willing to invest time for nothing. So would one of you be ready to sign-off such a clean-up patch?

I will be happy to see such patch and will review it, but can't add sign-off as I'm not netdev maintainer.

Well, if you want to review, just have a look at:

  $ git grep -W "get_drvinfo(struct"

Unless some driver names their callback function in some non standard way, that should be pretty it. Regardless, this will give you a fair representation of the current situation.

There are a few nuances. For example, some drivers use dev_name() for the .bus_info, while some others use pci_name(). I am not sure if this makes a difference... Also, there are many hardcoded names for .driver and I do not have the courage to check all of them. I am OK to blindly remove all that mess but no more.

Yours sincerely,
Vincent Mailhol

#6 lore raw
Quoted 47 lines · Vincent MAILHOL
Quoted 46 lines · Leon Romanovsky
Quoted 16 lines · Vincent MAILHOL
Quoted 6 lines · Jakub Kicinski
Quoted 5 lines · On Wed, 9 Nov 2022 19:52:13 +0200 Leon Romanovsky wrote:
Quoted 4 lines · Vincent Mailhol

If ethtool_ops::get_drvinfo() callback isn't set, ethtool_get_drvinfo() will fill the ethtool_drvinfo::name and ethtool_drvinfo::bus_info fields.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

However, if the driver provides the callback function, those two fields are not touched. This means that the driver has to fill these itself.

Can you please point to such drivers?

What you mean by "such drivers" is not clear from the quoted context, at least to me.

Quoted 6 lines

An example:
https://elixir.bootlin.com/linux/latest/source/drivers/net/ethernet/broadcom/bnx2.c#L7041

This driver wants to set fw_version but needs to also fill the driver name and bus_info. My patch will enable *such drivers* to only fill the fw_version and delegate the rest to the core.

Sorry for being misleading, It looks like I typed only part of the sentence which I had in my mind. I wanted to see if any driver exists which prints drv_name and bus_info different from default.

Quoted 17 lines
Quoted 11 lines
Quoted 3 lines

One can argue that they don't need to touch these fields in a first place and ethtool_drvinfo should always overwrite them.

Quite likely most driver prints to .driver and .bus_info can be dropped with this patch in place. Then again, I'm suspecting it's a bit of a chicken and an egg problem with people adding new drivers not having an incentive to add the print in the core and people who want to add the print in the core not having any driver that would benefit. Therefore I'd lean towards accepting Vincent's patch as is even if the submission can likely be more thorough and strict.

If we can agree that no drivers should ever print .driver and .bus_info, then I am fine to send a clean-up patch to remove all this after this one gets accepted. However, I am not willing to invest time for nothing. So would one of you be ready to sign-off such a clean-up patch?

Quoted 5 lines
Quoted 2 lines

I will be happy to see such patch and will review it, but can't add sign-off as I'm not netdev maintainer.

Well, if you want to review, just have a look at:

  $ git grep -W "get_drvinfo(struct"

BTW, in some of the callbacks, if driver doesn't exists, they print "N/A", while in your patch it will be empty string.

Thanks

#7 lore raw
Quoted 48 lines · Leon Romanovsky
Quoted 47 lines · Vincent MAILHOL
Quoted 46 lines · Leon Romanovsky
Quoted 16 lines · Vincent MAILHOL
Quoted 6 lines · Jakub Kicinski
Quoted 5 lines · On Wed, 9 Nov 2022 19:52:13 +0200 Leon Romanovsky wrote:
Quoted 4 lines · Vincent Mailhol

If ethtool_ops::get_drvinfo() callback isn't set, ethtool_get_drvinfo() will fill the ethtool_drvinfo::name and ethtool_drvinfo::bus_info fields.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

However, if the driver provides the callback function, those two fields are not touched. This means that the driver has to fill these itself.

Can you please point to such drivers?

What you mean by "such drivers" is not clear from the quoted context, at least to me.

Quoted 6 lines

An example:
https://elixir.bootlin.com/linux/latest/source/drivers/net/ethernet/broadcom/bnx2.c#L7041

This driver wants to set fw_version but needs to also fill the driver name and bus_info. My patch will enable *such drivers* to only fill the fw_version and delegate the rest to the core.

Sorry for being misleading, It looks like I typed only part of the sentence which I had in my mind. I wanted to see if any driver exists which prints drv_name and bus_info different from default.

Quoted 17 lines
Quoted 11 lines
Quoted 3 lines

One can argue that they don't need to touch these fields in a first place and ethtool_drvinfo should always overwrite them.

Quite likely most driver prints to .driver and .bus_info can be dropped with this patch in place. Then again, I'm suspecting it's a bit of a chicken and an egg problem with people adding new drivers not having an incentive to add the print in the core and people who want to add the print in the core not having any driver that would benefit. Therefore I'd lean towards accepting Vincent's patch as is even if the submission can likely be more thorough and strict.

If we can agree that no drivers should ever print .driver and .bus_info, then I am fine to send a clean-up patch to remove all this after this one gets accepted. However, I am not willing to invest time for nothing. So would one of you be ready to sign-off such a clean-up patch?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

I will be happy to see such patch and will review it, but can't add sign-off as I'm not netdev maintainer.

Well, if you want to review, just have a look at:

  $ git grep -W "get_drvinfo(struct"

BTW, in some of the callbacks, if driver doesn't exists, they print "N/A", while in your patch it will be empty string.

Indeed and this is inconsistent. For example, no one sets .erom_version to "N/A". So you will have some of the fields set to "N/A" and some others set to an empty string. The "N/A" thing was a mistake to begin with. I will not change my patch.

#8 lore raw
Quoted 55 lines · Vincent MAILHOL
Quoted 54 lines · Leon Romanovsky
Quoted 52 lines · Vincent MAILHOL
Quoted 40 lines · Leon Romanovsky
Quoted 16 lines · Vincent MAILHOL
Quoted 6 lines · Jakub Kicinski
Quoted 5 lines · On Wed, 9 Nov 2022 19:52:13 +0200 Leon Romanovsky wrote:
Quoted 4 lines · Vincent Mailhol

If ethtool_ops::get_drvinfo() callback isn't set, ethtool_get_drvinfo() will fill the ethtool_drvinfo::name and ethtool_drvinfo::bus_info fields.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

However, if the driver provides the callback function, those two fields are not touched. This means that the driver has to fill these itself.

Can you please point to such drivers?

What you mean by "such drivers" is not clear from the quoted context, at least to me.

Quoted 6 lines

An example:
https://elixir.bootlin.com/linux/latest/source/drivers/net/ethernet/broadcom/bnx2.c#L7041

This driver wants to set fw_version but needs to also fill the driver name and bus_info. My patch will enable *such drivers* to only fill the fw_version and delegate the rest to the core.

Sorry for being misleading, It looks like I typed only part of the sentence which I had in my mind. I wanted to see if any driver exists which prints drv_name and bus_info different from default.

Quoted 12 lines
Quoted 11 lines
Quoted 3 lines

One can argue that they don't need to touch these fields in a first place and ethtool_drvinfo should always overwrite them.

Quite likely most driver prints to .driver and .bus_info can be dropped with this patch in place. Then again, I'm suspecting it's a bit of a chicken and an egg problem with people adding new drivers not having an incentive to add the print in the core and people who want to add the print in the core not having any driver that would benefit. Therefore I'd lean towards accepting Vincent's patch as is even if the submission can likely be more thorough and strict.

Quoted 8 lines
Quoted 5 lines

If we can agree that no drivers should ever print .driver and .bus_info, then I am fine to send a clean-up patch to remove all this after this one gets accepted. However, I am not willing to invest time for nothing. So would one of you be ready to sign-off such a clean-up patch?

I will be happy to see such patch and will review it, but can't add sign-off as I'm not netdev maintainer.

Well, if you want to review, just have a look at:

  $ git grep -W "get_drvinfo(struct"
Quoted 7 lines
Quoted 2 lines

BTW, in some of the callbacks, if driver doesn't exists, they print "N/A", while in your patch it will be empty string.

Indeed and this is inconsistent. For example, no one sets .erom_version to "N/A". So you will have some of the fields set to "N/A" and some others set to an empty string. The "N/A" thing was a mistake to begin with. I will not change my patch.

I don't see anyone asking you to change your patch drastically. This discussion is more about next steps.

Thanks

maintainer
#9 lore raw
In reply to Leon Romanovsky
Quoted 2 lines

I will be happy to see such patch and will review it, but can't add sign-off as I'm not netdev maintainer.

Anybody can review any patch, and give an Acked-by or Reviewed-by. It is up to the Maintainer doing the actual merge to decided if it has any actual weight.

Andrew

maintainer
#10 lore raw
In reply to Leon Romanovsky
Quoted 2 lines · On Thu, 10 Nov 2022 11:11:38 +0200 Leon Romanovsky wrote:

I will be happy to see such patch and will review it, but can't add sign-off as I'm not netdev maintainer.

Did we finish the version removal work? :S

Personally I'd rather direct any effort towards writing a checkpatch / cocci / python check that catches new cases than cleaning up the pile of drivers we have. A lot of which are not actively used..

#11 lore raw
Quoted 5 lines · Jakub Kicinski
Quoted 2 lines · On Thu, 10 Nov 2022 11:11:38 +0200 Leon Romanovsky wrote:

I will be happy to see such patch and will review it, but can't add sign-off as I'm not netdev maintainer.

Did we finish the version removal work? :S

Good point :)

Quoted 4 lines

Personally I'd rather direct any effort towards writing a checkpatch / cocci / python check that catches new cases than cleaning up the pile of drivers we have. A lot of which are not actively used..

I thought about this too, but came to conclusion what first step is to remove "version" from in-kernel API. It will reduce drastically desire to add driver version to new drivers.

"There is no shame in doing the right thing, even if its too late.".

BTW, I hope that we all learned that allowing drivers to return free string to users will always lead to disaster.

Thanks

#12 lore raw
In reply to Jakub Kicinski
Quoted 9 lines · Jakub Kicinski
Quoted 2 lines · On Thu, 10 Nov 2022 11:11:38 +0200 Leon Romanovsky wrote:

I will be happy to see such patch and will review it, but can't add sign-off as I'm not netdev maintainer.

Did we finish the version removal work? :S

Personally I'd rather direct any effort towards writing a checkpatch / cocci / python check that catches new cases than cleaning up the pile of drivers we have. A lot of which are not actively used..

Agree, but I will not work on that (because of other personal priorities). If someone else wants to do it, go ahead :)

What I can do is update the documentation:
https://lore.kernel.org/netdev/[email protected]/

Yours sincerely,
Vincent Mailhol

#13 lore raw
Quoted 5 lines · Vincent MAILHOL
Quoted 4 lines · Jakub Kicinski
Quoted 2 lines · On Thu, 10 Nov 2022 11:11:38 +0200 Leon Romanovsky wrote:

I will be happy to see such patch and will review it, but can't add sign-off as I'm not netdev maintainer.

Quoted 8 lines
Quoted 5 lines

Did we finish the version removal work? :S

Personally I'd rather direct any effort towards writing a checkpatch / cocci / python check that catches new cases than cleaning up the pile of drivers we have. A lot of which are not actively used..

Agree, but I will not work on that (because of other personal priorities). If someone else wants to do it, go ahead :)

It's ok, Jakub referred to me. I sent a lot of patches like this.
https://lore.kernel.org/netdev/5d76f3116ee795071ec044eabb815d6c2bdc7dbd.1649922731.git.leonro@nvidia.com/

Quoted 7 lines

What I can do is update the documentation:
https://lore.kernel.org/netdev/[email protected]/

Yours sincerely,
Vincent Mailhol

maintainer
#14 lore raw
In reply to Vincent MAILHOL
Quoted 6 lines · On Thu, 10 Nov 2022 17:34:55 +0900 Vincent MAILHOL wrote:
Quoted 2 lines

While I'm typing - I've used dev_driver_string() to get the driver name in the past. Perhaps something to consider?

I am not sure of that one. If dev->dev.parent->driver is not set, it defaults to dev_bus_name() which is .bus_info, isn't it?
https://elixir.bootlin.com/linux/latest/source/drivers/base/core.c#L2181

I don't think so? We put dev_name() into bus_info, which is usually the address of the device on the bus (e.g. (D)BDF for PCI, like 0000:00:14.3). The name of the bus is pci. dev_driver_string() will also fall back to printing class name.

Quoted 6 lines

For the end user, it might be better to display an empty driver name
in 'ethtool -i' rather than reporting the bus_info twice?

I mean, if you ask me for my opinion, then my answer is "I am not sure". If you have confidence that dev_driver_string() is better, then I will send a v2 right away.

Well, it doesn't matter. I asked because handful of popular drivers use dev_driver_string(). But.. these are drivers so parent->driver will be set and it ends up not making any difference.

#15 lore raw
In reply to Vincent Mailhol
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Quoted 9 lines · On Tue, 8 Nov 2022 12:57:54 +0900 you wrote:

If ethtool_ops::get_drvinfo() callback isn't set, ethtool_get_drvinfo() will fill the ethtool_drvinfo::name and ethtool_drvinfo::bus_info fields.

However, if the driver provides the callback function, those two fields are not touched. This means that the driver has to fill these itself.

[...]

Here is the summary with links:
- [net-next,v1] ethtool: ethtool_get_drvinfo: populate drvinfo fields even if callback exits

    https://git.kernel.org/netdev/net-next/c/edaf5df22cb8

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html