diff mbox series

[v5,net-next,04/36] net/tls: expose get_netdev_for_sock

Message ID 20210722110325.371-5-borisp@nvidia.com
State New
Headers show
Series nvme-tcp receive and tarnsmit offloads | expand

Commit Message

Boris Pismenny July 22, 2021, 11:02 a.m. UTC
From: Boris Pismenny <borisp@mellanox.com>

get_netdev_for_sock is a utility that is used to obtain
the net_device structure from a connected socket.

Later patches will use this for nvme-tcp DDP and DDP DDGST offloads.

Signed-off-by: Boris Pismenny <borisp@mellanox.com>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
---
 include/net/sock.h   | 17 +++++++++++++++++
 net/tls/tls_device.c | 20 ++------------------
 2 files changed, 19 insertions(+), 18 deletions(-)

Comments

Christoph Hellwig July 23, 2021, 6:06 a.m. UTC | #1
On Thu, Jul 22, 2021 at 02:02:53PM +0300, Boris Pismenny wrote:
> From: Boris Pismenny <borisp@mellanox.com>

> 

> get_netdev_for_sock is a utility that is used to obtain

> the net_device structure from a connected socket.

> 

> Later patches will use this for nvme-tcp DDP and DDP DDGST offloads.

> 

> Signed-off-by: Boris Pismenny <borisp@mellanox.com>

> Reviewed-by: Sagi Grimberg <sagi@grimberg.me>


I don't think this should be an inline.  Please move it to net/core/dev.c,
andd add an EXPORT_SYMBOL_GPL and a kerneldoc comment.
Or Gerlitz Aug. 4, 2021, 1:26 p.m. UTC | #2
On Fri, Jul 23, 2021 at 9:09 AM Christoph Hellwig <hch@lst.de> wrote:
>

> On Thu, Jul 22, 2021 at 02:02:53PM +0300, Boris Pismenny wrote:

> > From: Boris Pismenny <borisp@mellanox.com>

> >

> > get_netdev_for_sock is a utility that is used to obtain

> > the net_device structure from a connected socket.

> >

> > Later patches will use this for nvme-tcp DDP and DDP DDGST offloads.

> >

> > Signed-off-by: Boris Pismenny <borisp@mellanox.com>

> > Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

>

> I don't think this should be an inline.  Please move it to net/core/dev.c,

> andd add an EXPORT_SYMBOL_GPL and a kerneldoc comment.


Jakub,

What's your preference here?

Or.
Or Gerlitz Aug. 4, 2021, 3:07 p.m. UTC | #3
On Wed, Aug 4, 2021 at 5:29 PM Jakub Kicinski <kuba@kernel.org> wrote:
>

> On Wed, 4 Aug 2021 16:26:31 +0300 Or Gerlitz wrote:

> > On Fri, Jul 23, 2021 at 9:09 AM Christoph Hellwig <hch@lst.de> wrote:

> > > On Thu, Jul 22, 2021 at 02:02:53PM +0300, Boris Pismenny wrote:

> > > > From: Boris Pismenny <borisp@mellanox.com>

> > > >

> > > > get_netdev_for_sock is a utility that is used to obtain

> > > > the net_device structure from a connected socket.

> > > >

> > > > Later patches will use this for nvme-tcp DDP and DDP DDGST offloads.

> > > >

> > > > Signed-off-by: Boris Pismenny <borisp@mellanox.com>

> > > > Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

> > >

> > > I don't think this should be an inline.  Please move it to net/core/dev.c,

> > > andd add an EXPORT_SYMBOL_GPL and a kerneldoc comment.

> >

> > Jakub,

> >

> > What's your preference here?

>

> Fine either way.


copying the list and few ppl
Or Gerlitz Aug. 10, 2021, 1:25 p.m. UTC | #4
On Wed, Aug 4, 2021 at 6:07 PM Or Gerlitz <gerlitz.or@gmail.com> wrote:
> On Wed, Aug 4, 2021 at 5:29 PM Jakub Kicinski <kuba@kernel.org> wrote:

> > On Wed, 4 Aug 2021 16:26:31 +0300 Or Gerlitz wrote:

> > > On Fri, Jul 23, 2021 at 9:09 AM Christoph Hellwig <hch@lst.de> wrote:

> > > > On Thu, Jul 22, 2021 at 02:02:53PM +0300, Boris Pismenny wrote:

> > > > > From: Boris Pismenny <borisp@mellanox.com>

> > > > >

> > > > > get_netdev_for_sock is a utility that is used to obtain

> > > > > the net_device structure from a connected socket.

> > > > >

> > > > > Later patches will use this for nvme-tcp DDP and DDP DDGST offloads.

> > > > >

> > > > > Signed-off-by: Boris Pismenny <borisp@mellanox.com>

> > > > > Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

> > > >

> > > > I don't think this should be an inline.  Please move it to net/core/dev.c,

> > > > andd add an EXPORT_SYMBOL_GPL and a kerneldoc comment.


> > > Jakub,

> > > What's your preference here?


> > Fine either way.


> copying the list and few ppl


Christoph,

We will add the kdoc.

Prefer to leave it as inline which is fine by the networking maintainer.

Or.
diff mbox series

Patch

diff --git a/include/net/sock.h b/include/net/sock.h
index 8bdd80027ffb..5fa2fd192d18 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2769,4 +2769,21 @@  void sock_set_sndtimeo(struct sock *sk, s64 secs);
 
 int sock_bind_add(struct sock *sk, struct sockaddr *addr, int addr_len);
 
+/* Assume that the socket is already connected */
+static inline struct net_device *get_netdev_for_sock(struct sock *sk, bool hold)
+{
+	struct dst_entry *dst = sk_dst_get(sk);
+	struct net_device *netdev = NULL;
+
+	if (likely(dst)) {
+		netdev = dst->dev;
+		if (hold)
+			dev_hold(netdev);
+	}
+
+	dst_release(dst);
+
+	return netdev;
+}
+
 #endif	/* _SOCK_H */
diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c
index b932469ee69c..06aa5f1e73d1 100644
--- a/net/tls/tls_device.c
+++ b/net/tls/tls_device.c
@@ -107,22 +107,6 @@  static void tls_device_queue_ctx_destruction(struct tls_context *ctx)
 	spin_unlock_irqrestore(&tls_device_lock, flags);
 }
 
-/* We assume that the socket is already connected */
-static struct net_device *get_netdev_for_sock(struct sock *sk)
-{
-	struct dst_entry *dst = sk_dst_get(sk);
-	struct net_device *netdev = NULL;
-
-	if (likely(dst)) {
-		netdev = netdev_sk_get_lowest_dev(dst->dev, sk);
-		dev_hold(netdev);
-	}
-
-	dst_release(dst);
-
-	return netdev;
-}
-
 static void destroy_record(struct tls_record_info *record)
 {
 	int i;
@@ -1118,7 +1102,7 @@  int tls_set_device_offload(struct sock *sk, struct tls_context *ctx)
 	if (skb)
 		TCP_SKB_CB(skb)->eor = 1;
 
-	netdev = get_netdev_for_sock(sk);
+	netdev = get_netdev_for_sock(sk, true);
 	if (!netdev) {
 		pr_err_ratelimited("%s: netdev not found\n", __func__);
 		rc = -EINVAL;
@@ -1194,7 +1178,7 @@  int tls_set_device_offload_rx(struct sock *sk, struct tls_context *ctx)
 	if (ctx->crypto_recv.info.version != TLS_1_2_VERSION)
 		return -EOPNOTSUPP;
 
-	netdev = get_netdev_for_sock(sk);
+	netdev = get_netdev_for_sock(sk, true);
 	if (!netdev) {
 		pr_err_ratelimited("%s: netdev not found\n", __func__);
 		return -EINVAL;