netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] tun: fix ethtool_ops get_msglvl and set_msglvl handlers
@ 2020-03-03  8:22 Michal Kubecek
  2020-03-03 22:59 ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Michal Kubecek @ 2020-03-03  8:22 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski, netdev; +Cc: linux-kernel

The get_msglvl and setmsglvl handlers only work as expected if TUN_DEBUG
is defined (which required editing the source). Otherwise tun_get_msglvl()
returns -EOPNOTSUPP but as this handler is not supposed to return error
code, it is not recognized as one and passed to userspace as is, resulting
in bogus output of ethtool command. The set_msglvl handler ignores its
argument and does nothing if TUN_DEBUG is left undefined.

The way to return EOPNOTSUPP to userspace for both requests is not to
provide these ethtool_ops callbacks at all if TUN_DEBUG is left undefined.

Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
---
 drivers/net/tun.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 650c937ed56b..0aae2d208398 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -3557,23 +3557,21 @@ static void tun_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info
 	}
 }
 
+#ifdef TUN_DEBUG
 static u32 tun_get_msglevel(struct net_device *dev)
 {
-#ifdef TUN_DEBUG
 	struct tun_struct *tun = netdev_priv(dev);
+
 	return tun->debug;
-#else
-	return -EOPNOTSUPP;
-#endif
 }
 
 static void tun_set_msglevel(struct net_device *dev, u32 value)
 {
-#ifdef TUN_DEBUG
 	struct tun_struct *tun = netdev_priv(dev);
+
 	tun->debug = value;
-#endif
 }
+#endif /* TUN_DEBUG */
 
 static int tun_get_coalesce(struct net_device *dev,
 			    struct ethtool_coalesce *ec)
@@ -3600,8 +3598,10 @@ static int tun_set_coalesce(struct net_device *dev,
 
 static const struct ethtool_ops tun_ethtool_ops = {
 	.get_drvinfo	= tun_get_drvinfo,
+#ifdef TUN_DEBUG
 	.get_msglevel	= tun_get_msglevel,
 	.set_msglevel	= tun_set_msglevel,
+#endif
 	.get_link	= ethtool_op_get_link,
 	.get_ts_info	= ethtool_op_get_ts_info,
 	.get_coalesce   = tun_get_coalesce,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net] tun: fix ethtool_ops get_msglvl and set_msglvl handlers
  2020-03-03  8:22 [PATCH net] tun: fix ethtool_ops get_msglvl and set_msglvl handlers Michal Kubecek
@ 2020-03-03 22:59 ` David Miller
  2020-03-04  6:57   ` Michal Kubecek
  0 siblings, 1 reply; 3+ messages in thread
From: David Miller @ 2020-03-03 22:59 UTC (permalink / raw)
  To: mkubecek; +Cc: kuba, netdev, linux-kernel

From: Michal Kubecek <mkubecek@suse.cz>
Date: Tue,  3 Mar 2020 09:22:52 +0100 (CET)

> The get_msglvl and setmsglvl handlers only work as expected if TUN_DEBUG
> is defined (which required editing the source). Otherwise tun_get_msglvl()
> returns -EOPNOTSUPP but as this handler is not supposed to return error
> code, it is not recognized as one and passed to userspace as is, resulting
> in bogus output of ethtool command. The set_msglvl handler ignores its
> argument and does nothing if TUN_DEBUG is left undefined.
> 
> The way to return EOPNOTSUPP to userspace for both requests is not to
> provide these ethtool_ops callbacks at all if TUN_DEBUG is left undefined.
> 
> Signed-off-by: Michal Kubecek <mkubecek@suse.cz>

I agree with your analysis.

But this TUN_DEBUG thing stands outside of what we let drivers do.  Either
this tracing is not so useful and can be deleted, or the tracing should
be available unconditionally so that it can be turned on by the vast
majority of users who do not edit the source.

I suspect making the TUN_DEBUG code unconditional is that way to go here.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net] tun: fix ethtool_ops get_msglvl and set_msglvl handlers
  2020-03-03 22:59 ` David Miller
@ 2020-03-04  6:57   ` Michal Kubecek
  0 siblings, 0 replies; 3+ messages in thread
From: Michal Kubecek @ 2020-03-04  6:57 UTC (permalink / raw)
  To: David Miller; +Cc: kuba, netdev, linux-kernel

On Tue, Mar 03, 2020 at 02:59:16PM -0800, David Miller wrote:
> From: Michal Kubecek <mkubecek@suse.cz>
> Date: Tue,  3 Mar 2020 09:22:52 +0100 (CET)
> 
> > The get_msglvl and setmsglvl handlers only work as expected if TUN_DEBUG
> > is defined (which required editing the source). Otherwise tun_get_msglvl()
> > returns -EOPNOTSUPP but as this handler is not supposed to return error
> > code, it is not recognized as one and passed to userspace as is, resulting
> > in bogus output of ethtool command. The set_msglvl handler ignores its
> > argument and does nothing if TUN_DEBUG is left undefined.
> > 
> > The way to return EOPNOTSUPP to userspace for both requests is not to
> > provide these ethtool_ops callbacks at all if TUN_DEBUG is left undefined.
> > 
> > Signed-off-by: Michal Kubecek <mkubecek@suse.cz>
> 
> I agree with your analysis.
> 
> But this TUN_DEBUG thing stands outside of what we let drivers do.  Either
> this tracing is not so useful and can be deleted, or the tracing should
> be available unconditionally so that it can be turned on by the vast
> majority of users who do not edit the source.
> 
> I suspect making the TUN_DEBUG code unconditional is that way to go here.

I started to think in this direction too and ended up with

  - DBG1() macro checks a variable which is never set; it's also used
    only in one place which doesn't seem to differ from others where
    tun_debug() is used
  - many tun_debug() calls can be dropped as they only inform about
    entering a function and sometimes show some if its arguments; we
    have ftrace and kprobes for that
  - the rest should be rewritten to netif_info()
  - the two tun_debug() in packet processing path could use netif_dbg()
    to avoid overhead when not turned on

...which is where I stopped and went with the quick fix instead.

On the other hand, there is no rush, the issue seems to exist since
before git. And unlike some other drivers doing strange things for
debugging, tun is widely used so it deserves a cleanup.

I'll send a patch (or patches) with proper cleanup for net-next.

Michal

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-04  6:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-03  8:22 [PATCH net] tun: fix ethtool_ops get_msglvl and set_msglvl handlers Michal Kubecek
2020-03-03 22:59 ` David Miller
2020-03-04  6:57   ` Michal Kubecek

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).