Skip to contentSkip to conversation

ovpn-dco: fix kernel 6.1 compile issue in ovpn_peer_create

PATCH Superseded John Thomson 2 participants 5 messages Oct 22, 2022 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ovpn-dco: fix kernel 6.1 compile issue in ovpn_peer_create

Linux 5.19 replaces netif_tx_napi_add, but maintains a definition to the new function in: 58caed3dacb4 ("netdev: reshuffle netif_napi_add() APIs to allow dropping weigh") [0]

Linux 6.1 removes netif_tx_napi_add in c3f760ef1287 ("net: remove netif_tx_napi_add()") [1]

[0]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=58caed3dacb4354a25a1aa8d2febc3e9648ba1f4
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c3f760ef128789252e7c4f10d3c1721422dceba9

---
compile test only, on kernel 6.1rc1

---
 drivers/net/ovpn-dco/peer.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/net/ovpn-dco/peer.c +4 -0
index 5838286..c460976 100644
@@ -88,8 +88,12 @@ static struct ovpn_peer *ovpn_peer_create(struct ovpn_struct *ovpn, u32 id)
 	}
 
 	/* configure and start NAPI */
+#if(LINUX_VERSION_CODE < KERNEL_VERSION(5,19,0))
 	netif_tx_napi_add(ovpn->dev, &peer->napi, ovpn_napi_poll,
 			  NAPI_POLL_WEIGHT);
+#else
+	netif_napi_add_tx(ovpn->dev, &peer->napi, ovpn_napi_poll);
+#endif
 	napi_enable(&peer->napi);
 
 	dev_hold(ovpn->dev);
Signature · 1 line
2.37.2
#1 lore raw

Hi John,

Thanks a lot for your contribution!

However, we can't have #ifs like that in the middle of the code, as this code is expected to go upstream (and #ifs on the kernel version are not allowed).

The code should always work with the latest kernel version, while any magic compatibility trick should be hidden in compat.h (i.e. implement netif_napi_add_tx() so that it calls netif_tx_napi_add(..., NAPI_POLL_WEIGHT)).

Cheers,

Quoted 34 lines · John Thomson

Linux 5.19 replaces netif_tx_napi_add, but maintains a definition to the new function in: 58caed3dacb4 ("netdev: reshuffle netif_napi_add() APIs to allow dropping weigh") [0]

Linux 6.1 removes netif_tx_napi_add in c3f760ef1287 ("net: remove netif_tx_napi_add()") [1]

[0]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=58caed3dacb4354a25a1aa8d2febc3e9648ba1f4
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c3f760ef128789252e7c4f10d3c1721422dceba9

---
compile test only, on kernel 6.1rc1

---
  drivers/net/ovpn-dco/peer.c | 4 ++++
  1 file changed, 4 insertions(+)
drivers/net/ovpn-dco/peer.c +4 -0
index 5838286..c460976 100644
@@ -88,8 +88,12 @@ static struct ovpn_peer *ovpn_peer_create(struct ovpn_struct *ovpn, u32 id)
  	}
 
  	/* configure and start NAPI */
+#if(LINUX_VERSION_CODE < KERNEL_VERSION(5,19,0))
  	netif_tx_napi_add(ovpn->dev, &peer->napi, ovpn_napi_poll,
  			  NAPI_POLL_WEIGHT);
+#else
+	netif_napi_add_tx(ovpn->dev, &peer->napi, ovpn_napi_poll);
+#endif
  	napi_enable(&peer->napi);
 
  	dev_hold(ovpn->dev);
Signature · 1 line
Antonio Quartulli
#2 lore raw

PATCH v2 1/1 ovpn-dco: fix kernel 6.1 compile issue in ovpn_peer_create

Linux 5.19 replaces netif_tx_napi_add, but maintains a definition to the new function in: 58caed3dacb4 ("netdev: reshuffle netif_napi_add() APIs to allow dropping weigh") [0]

Linux 6.1 removes netif_tx_napi_add in c3f760ef1287 ("net: remove netif_tx_napi_add()") [1]

[0]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=58caed3dacb4354a25a1aa8d2febc3e9648ba1f4
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c3f760ef128789252e7c4f10d3c1721422dceba9

---
v2: Do not throw ifdefs into the middle of the code

compile tested only: openwrt toolchain aarch64: kernel v6.1rc1, kernel 5.10

---
 drivers/net/ovpn-dco/peer.c | 2 +-
 linux-compat.h              | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/ovpn-dco/peer.c +1 -1
index 5838286..8fc619c 100644
@@ -88,7 +88,7 @@ static struct ovpn_peer *ovpn_peer_create(struct ovpn_struct *ovpn, u32 id)
 	}
 
 	/* configure and start NAPI */
-	netif_tx_napi_add(ovpn->dev, &peer->napi, ovpn_napi_poll,
+	netif_napi_add_tx_weight(ovpn->dev, &peer->napi, ovpn_napi_poll,
 			  NAPI_POLL_WEIGHT);
 	napi_enable(&peer->napi);
 
linux-compat.h +8 -0
index 3fb0208..b5af7e9 100644
@@ -104,4 +104,12 @@ static inline void dev_sw_netstats_rx_add(struct net_device *dev, unsigned int l
 
 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5, 2, 0) */
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 0)
+/**
+ * commit 58caed3dacb4 renamed to netif_napi_add_tx_weight,
+ * commit c3f760ef1287 removed netif_tx_napi_add
+ */
+#define netif_napi_add_tx_weight netif_tx_napi_add
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(5, 19, 0) */
+
 #endif /* _NET_OVPN_DCO_LINUX_COMPAT_H_ */
Signature · 1 line
2.37.2
#3 lore raw

Hi,

Quoted 11 lines · John Thomson

Linux 5.19 replaces netif_tx_napi_add, but maintains a definition to the new function in: 58caed3dacb4 ("netdev: reshuffle netif_napi_add() APIs to allow dropping weigh") [0]

Linux 6.1 removes netif_tx_napi_add in c3f760ef1287 ("net: remove netif_tx_napi_add()") [1]

[0]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=58caed3dacb4354a25a1aa8d2febc3e9648ba1f4
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c3f760ef128789252e7c4f10d3c1721422dceba9

Thanks a lot for this!
Your patch has been applied to the master branch with a few minor style fixes.

Quoted 4 lines

---
v2: Do not throw ifdefs into the middle of the code

compile tested only: openwrt toolchain aarch64: kernel v6.1rc1, kernel 5.10

Out of curiosity: are you using the openvpn-dev feed for openwqrt? (https://github.com/OpenVPN/openvpn-dev-openwrt)

Cheers,

Signature · 1 line
Antonio Quartulli
#4 lore raw
Quoted 10 lines · Antonio Quartulli

Hi,

Quoted 7 lines · John Thomson

Linux 5.19 replaces netif_tx_napi_add, but maintains a definition to the new function in: 58caed3dacb4 ("netdev: reshuffle netif_napi_add() APIs to allow dropping weigh") [0]

Linux 6.1 removes netif_tx_napi_add in c3f760ef1287 ("net: remove netif_tx_napi_add()") [1]

Quoted 8 lines
Quoted 4 lines

[0]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=58caed3dacb4354a25a1aa8d2febc3e9648ba1f4
[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=c3f760ef128789252e7c4f10d3c1721422dceba9

Thanks a lot for this!
Your patch has been applied to the master branch with a few minor style fixes.

Thank you for the help and quick turnaround.
I really should have found all the #if LINUX_VERSION_CODE in linux-compat myself the first time… Sorry

Quoted 8 lines
Quoted 5 lines

---
v2: Do not throw ifdefs into the middle of the code

compile tested only: openwrt toolchain aarch64: kernel v6.1rc1, kernel 5.10

Out of curiosity: are you using the openvpn-dev feed for openwqrt?
(https://github.com/OpenVPN/openvpn-dev-openwrt)

Not yet, only just learned of it.
I was walking through building all the Openwrt kernel modules with kernel 6.1rc1 and came across ovpn-dco in the Openwrt packages feed.

Cheers,

Signature · 1 line
  John Thomson