[RFC PATCH V3 2/2] net: netvsc: Allocate per-device swiotlb bounce buffer for netvsc

From: Tianyu Lan
Date: Thu May 26 2022 - 08:01:35 EST


From: Tianyu Lan <Tianyu.Lan@xxxxxxxxxxxxx>

Netvsc driver allocates device io tlb mem via calling swiotlb_device_
allocate() and set child io tlb mem number according to device queue
number. Child io tlb mem may reduce overhead of single spin lock in
device io tlb mem among multi device queues.

Signed-off-by: Tianyu Lan <Tianyu.Lan@xxxxxxxxxxxxx>
---
drivers/net/hyperv/netvsc.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/drivers/net/hyperv/netvsc.c b/drivers/net/hyperv/netvsc.c
index 9442f751ad3a..26a8f8f84fc4 100644
--- a/drivers/net/hyperv/netvsc.c
+++ b/drivers/net/hyperv/netvsc.c
@@ -23,6 +23,7 @@

#include <asm/sync_bitops.h>
#include <asm/mshyperv.h>
+#include <linux/swiotlb.h>

#include "hyperv_net.h"
#include "netvsc_trace.h"
@@ -98,6 +99,7 @@ static void netvsc_subchan_work(struct work_struct *w)
struct netvsc_device *nvdev =
container_of(w, struct netvsc_device, subchan_work);
struct rndis_device *rdev;
+ struct hv_device *hdev;
int i, ret;

/* Avoid deadlock with device removal already under RTNL */
@@ -108,6 +110,9 @@ static void netvsc_subchan_work(struct work_struct *w)

rdev = nvdev->extension;
if (rdev) {
+ hdev = ((struct net_device_context *)
+ netdev_priv(rdev->ndev))->device_ctx;
+
ret = rndis_set_subchannel(rdev->ndev, nvdev, NULL);
if (ret == 0) {
netif_device_attach(rdev->ndev);
@@ -119,6 +124,10 @@ static void netvsc_subchan_work(struct work_struct *w)
nvdev->max_chn = 1;
nvdev->num_chn = 1;
}
+
+ /* Allocate boucne buffer.*/
+ swiotlb_device_allocate(&hdev->device, nvdev->num_chn,
+ 10 * IO_TLB_BLOCK_UNIT);
}

rtnl_unlock();
@@ -769,6 +778,7 @@ void netvsc_device_remove(struct hv_device *device)

/* Release all resources */
free_netvsc_device_rcu(net_device);
+ swiotlb_device_free(&device->device);
}

#define RING_AVAIL_PERCENT_HIWATER 20
--
2.25.1