Skip to contentSkip to conversation

vdpa/mlx5: Add debugfs subtree and fixes

PATCH Superseded Eli Cohen 3 participants 25 messages Nov 13, 2022 – Nov 24, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Eli Cohen

author
#0 lore raw

cover vdpa/mlx5: Add debugfs subtree and fixes

This series is a resend of previously sent patch list. It adds a few fixes so I treat as a v0 of a new series.

It adds a kernel config param CONFIG_MLX5_VDPA_STEERING_DEBUG that when eabled allows to read rx unicast and multicast counters per tagged or untagged traffic.

Examples:

$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-0/rx/untagged/mcast/packets
$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-0/rx/untagged/ucast/bytes

Eli Cohen (7):
vdpa/mlx5: Fix rule forwarding VLAN to TIR vdpa/mlx5: Fix wrong mac address deletion vdpa/mlx5: Move some definitions to a new header file vdpa/mlx5: Add debugfs subtree
vdpa/mlx5: Add RX counters to debugfs vdpa/mlx5: Avoid using reslock in event_handler vdpa/mlx5: Avoid overwriting CVQ iotlb

 drivers/vdpa/Kconfig               |  12 ++
 drivers/vdpa/mlx5/Makefile         |   2 +-
 drivers/vdpa/mlx5/core/mlx5_vdpa.h |   5 +-
 drivers/vdpa/mlx5/core/mr.c        |  44 ++---
 drivers/vdpa/mlx5/net/debug.c      | 152 ++++++++++++++++++
 drivers/vdpa/mlx5/net/mlx5_vnet.c  | 248 ++++++++++++++---------------
 drivers/vdpa/mlx5/net/mlx5_vnet.h  |  94 +++++++++++
 7 files changed, 411 insertions(+), 146 deletions(-)
 create mode 100644 drivers/vdpa/mlx5/net/debug.c
 create mode 100644 drivers/vdpa/mlx5/net/mlx5_vnet.h
Signature · 1 line
2.38.1
author
#1 lore raw

PATCH 1/7 vdpa/mlx5: Fix rule forwarding VLAN to TIR

Set the VLAN id to the header values field instead of overwriting the headers criteria field.

Before this fix, VLAN filtering would not really work and tagged packets would be forwarded unfiltered to the TIR.

In addition modify the logic so that VLAN filtering is enforced only when VIRTIO_NET_F_CTRL_VLAN is negotiated. When not negotiated, all incoming traffic is accepted as long as it is targeting the net device's MAC address.

Fixes baf2ad3f6a98 ("vdpa/mlx5: Add RX MAC VLAN filter support")
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +8 -3
index 90913365def4..ea95081eca0c 100644
@@ -1468,11 +1468,13 @@ static int mlx5_vdpa_add_mac_vlan_rules(struct mlx5_vdpa_net *ndev, u8 *mac,
 	dmac_v = MLX5_ADDR_OF(fte_match_param, headers_v, outer_headers.dmac_47_16);
 	eth_broadcast_addr(dmac_c);
 	ether_addr_copy(dmac_v, mac);
-	MLX5_SET(fte_match_set_lyr_2_4, headers_c, cvlan_tag, 1);
+	if (ndev->mvdev.actual_features & VIRTIO_NET_F_CTRL_VLAN) {
+		MLX5_SET(fte_match_set_lyr_2_4, headers_c, cvlan_tag, 1);
+		MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c, first_vid);
+	}
 	if (tagged) {
 		MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag, 1);
-		MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c, first_vid);
-		MLX5_SET(fte_match_set_lyr_2_4, headers_c, first_vid, vid);
+		MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_vid, vid);
 	}
 	flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
 	dest.type = MLX5_FLOW_DESTINATION_TYPE_TIR;
@@ -1821,6 +1823,9 @@ static virtio_net_ctrl_ack handle_ctrl_vlan(struct mlx5_vdpa_dev *mvdev, u8 cmd)
 	size_t read;
 	u16 id;
 
+	if (!(ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_CTRL_VLAN)))
+		return status;
+
 	switch (cmd) {
 	case VIRTIO_NET_CTRL_VLAN_ADD:
 		read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->riov, &vlan, sizeof(vlan));
Signature · 1 line
2.38.1
author
#6 lore raw

PATCH 2/7 vdpa/mlx5: Fix wrong mac address deletion

In reply to Eli Cohen

Delete the old MAC from the table and not the new one which is not there yet.

Fixes baf2ad3f6a98 ("vdpa/mlx5: Add RX MAC VLAN filter support")
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
index ea95081eca0c..c54d5088ed4f 100644
@@ -1686,7 +1686,7 @@ static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd)
 
 		/* Need recreate the flow table entry, so that the packet could forward back
 		 */
-		mac_vlan_del(ndev, ndev->config.mac, 0, false);
+		mac_vlan_del(ndev, mac_back, 0, false);
 
 		if (mac_vlan_add(ndev, ndev->config.mac, 0, false)) {
 			mlx5_vdpa_warn(mvdev, "failed to insert forward rules, try to restore\n");
Signature · 1 line
2.38.1
author
#8 lore raw

PATCH 3/7 vdpa/mlx5: Move some definitions to a new header file

In reply to Eli Cohen

Move some definitions from mlx5_vnet.c to newly added header file mlx5_vnet.h. We need these definitions for the following patches that add debugfs tree to expose information vital for debug.

---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 45 +------------------------
 drivers/vdpa/mlx5/net/mlx5_vnet.h | 55 +++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 44 deletions(-)
 create mode 100644 drivers/vdpa/mlx5/net/mlx5_vnet.h
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -44
index c54d5088ed4f..e45b83527b41 100644
@@ -18,15 +18,12 @@
 #include <linux/mlx5/mlx5_ifc_vdpa.h>
 #include <linux/mlx5/mpfs.h>
 #include "mlx5_vdpa.h"
+#include "mlx5_vnet.h"
 
 MODULE_AUTHOR("Eli Cohen <[email protected]>");
 MODULE_DESCRIPTION("Mellanox VDPA driver");
 MODULE_LICENSE("Dual BSD/GPL");
 
-#define to_mlx5_vdpa_ndev(__mvdev)                                             \
-	container_of(__mvdev, struct mlx5_vdpa_net, mvdev)
-#define to_mvdev(__vdev) container_of((__vdev), struct mlx5_vdpa_dev, vdev)
-
 #define VALID_FEATURES_MASK                                                                        \
 	(BIT_ULL(VIRTIO_NET_F_CSUM) | BIT_ULL(VIRTIO_NET_F_GUEST_CSUM) |                                   \
 	 BIT_ULL(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) | BIT_ULL(VIRTIO_NET_F_MTU) | BIT_ULL(VIRTIO_NET_F_MAC) |   \
@@ -50,14 +47,6 @@ MODULE_LICENSE("Dual BSD/GPL");
 
 #define MLX5V_UNTAGGED 0x1000
 
-struct mlx5_vdpa_net_resources {
-	u32 tisn;
-	u32 tdn;
-	u32 tirn;
-	u32 rqtn;
-	bool valid;
-};
-
 struct mlx5_vdpa_cq_buf {
 	struct mlx5_frag_buf_ctrl fbc;
 	struct mlx5_frag_buf frag_buf;
@@ -146,38 +135,6 @@ static bool is_index_valid(struct mlx5_vdpa_dev *mvdev, u16 idx)
 	return idx <= mvdev->max_idx;
 }
 
-#define MLX5V_MACVLAN_SIZE 256
-
-struct mlx5_vdpa_net {
-	struct mlx5_vdpa_dev mvdev;
-	struct mlx5_vdpa_net_resources res;
-	struct virtio_net_config config;
-	struct mlx5_vdpa_virtqueue *vqs;
-	struct vdpa_callback *event_cbs;
-
-	/* Serialize vq resources creation and destruction. This is required
-	 * since memory map might change and we need to destroy and create
-	 * resources while driver in operational.
-	 */
-	struct rw_semaphore reslock;
-	struct mlx5_flow_table *rxft;
-	bool setup;
-	u32 cur_num_vqs;
-	u32 rqt_size;
-	bool nb_registered;
-	struct notifier_block nb;
-	struct vdpa_callback config_cb;
-	struct mlx5_vdpa_wq_ent cvq_ent;
-	struct hlist_head macvlan_hash[MLX5V_MACVLAN_SIZE];
-};
-
-struct macvlan_node {
-	struct hlist_node hlist;
-	struct mlx5_flow_handle *ucast_rule;
-	struct mlx5_flow_handle *mcast_rule;
-	u64 macvlan;
-};
-
 static void free_resources(struct mlx5_vdpa_net *ndev);
 static void init_mvqs(struct mlx5_vdpa_net *ndev);
 static int setup_driver(struct mlx5_vdpa_dev *mvdev);
drivers/vdpa/mlx5/net/mlx5_vnet.h new file +55 -0

55 lines not on this page · raw message

Signature · 1 line
2.38.1
author
#10 lore raw

PATCH 4/7 vdpa/mlx5: Add debugfs subtree

In reply to Eli Cohen

Add debugfs subtree and expose flow table ID and TIR number. This information can be used by external tools to do extended troubleshooting.

The information can be retrieved like so:

$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-0/rx/table_id
$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-0/rx/tirn
---
 drivers/vdpa/mlx5/Makefile        |  2 +-
 drivers/vdpa/mlx5/net/debug.c     | 66 +++++++++++++++++++++++++++++++
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 11 ++++++
 drivers/vdpa/mlx5/net/mlx5_vnet.h |  9 +++++
 4 files changed, 87 insertions(+), 1 deletion(-)
 create mode 100644 drivers/vdpa/mlx5/net/debug.c
drivers/vdpa/mlx5/Makefile +1 -1
index f717978c83bf..e791394c33e3 100644
@@ -1,4 +1,4 @@
 subdir-ccflags-y += -I$(srctree)/drivers/vdpa/mlx5/core
 
 obj-$(CONFIG_MLX5_VDPA_NET) += mlx5_vdpa.o
-mlx5_vdpa-$(CONFIG_MLX5_VDPA_NET) += net/mlx5_vnet.o core/resources.o core/mr.o
+mlx5_vdpa-$(CONFIG_MLX5_VDPA_NET) += net/mlx5_vnet.o core/resources.o core/mr.o net/debug.o
drivers/vdpa/mlx5/net/debug.c new file +66 -0

66 lines not on this page · raw message

drivers/vdpa/mlx5/net/mlx5_vnet.c +11 -0
index e45b83527b41..ce2f478a93f5 100644
@@ -1388,11 +1388,16 @@ static int create_tir(struct mlx5_vdpa_net *ndev)
 
 	err = mlx5_vdpa_create_tir(&ndev->mvdev, in, &ndev->res.tirn);
 	kfree(in);
+	if (err)
+		return err;
+
+	mlx5_vdpa_add_tirn(ndev);
 	return err;
 }
 
 static void destroy_tir(struct mlx5_vdpa_net *ndev)
 {
+	mlx5_vdpa_remove_tirn(ndev);
 	mlx5_vdpa_destroy_tir(&ndev->mvdev, ndev->res.tirn);
 }
 
@@ -1578,6 +1583,7 @@ static int setup_steering(struct mlx5_vdpa_net *ndev)
 		mlx5_vdpa_warn(&ndev->mvdev, "failed to create flow table\n");
 		return PTR_ERR(ndev->rxft);
 	}
+	mlx5_vdpa_add_rx_flow_table(ndev);
 
 	err = mac_vlan_add(ndev, ndev->config.mac, 0, false);
 	if (err)
@@ -1586,6 +1592,7 @@ static int setup_steering(struct mlx5_vdpa_net *ndev)
 	return 0;
 
 err_add:
+	mlx5_vdpa_remove_rx_flow_table(ndev);
 	mlx5_destroy_flow_table(ndev->rxft);
 	return err;
 }
@@ -1593,6 +1600,7 @@ static int setup_steering(struct mlx5_vdpa_net *ndev)
 static void teardown_steering(struct mlx5_vdpa_net *ndev)
 {
 	clear_mac_vlan_table(ndev);
+	mlx5_vdpa_remove_rx_flow_table(ndev);
 	mlx5_destroy_flow_table(ndev->rxft);
 }
 
@@ -3172,6 +3180,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
 	if (err)
 		goto err_reg;
 
+	mlx5_vdpa_add_debugfs(ndev);
 	mgtdev->ndev = ndev;
 	return 0;
 
@@ -3198,6 +3207,8 @@ static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
 	struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
 	struct workqueue_struct *wq;
 
+	mlx5_vdpa_remove_debugfs(ndev->debugfs);
+	ndev->debugfs = NULL;
 	if (ndev->nb_registered) {
 		mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);
 		ndev->nb_registered = false;
drivers/vdpa/mlx5/net/mlx5_vnet.h +9 -0
index 6691c879a6ca..f2cef3925e5b 100644
@@ -16,6 +16,7 @@ struct mlx5_vdpa_net_resources {
 	u32 tirn;
 	u32 rqtn;
 	bool valid;
+	struct dentry *tirn_dent;
 };
 
 #define MLX5V_MACVLAN_SIZE 256
@@ -43,6 +44,7 @@ struct mlx5_vdpa_net {
 	struct vdpa_callback config_cb;
 	struct mlx5_vdpa_wq_ent cvq_ent;
 	struct hlist_head macvlan_hash[MLX5V_MACVLAN_SIZE];
+	struct dentry *debugfs;
 };
 
 struct macvlan_node {
@@ -52,4 +54,11 @@ struct macvlan_node {
 	u64 macvlan;
 };
 
+void mlx5_vdpa_add_debugfs(struct mlx5_vdpa_net *ndev);
+void mlx5_vdpa_remove_debugfs(struct dentry *dbg);
+void mlx5_vdpa_add_rx_flow_table(struct mlx5_vdpa_net *ndev);
+void mlx5_vdpa_remove_rx_flow_table(struct mlx5_vdpa_net *ndev);
+void mlx5_vdpa_add_tirn(struct mlx5_vdpa_net *ndev);
+void mlx5_vdpa_remove_tirn(struct mlx5_vdpa_net *ndev);
+
 #endif /* __MLX5_VNET_H__ */
Signature · 1 line
2.38.1
author
#12 lore raw

PATCH 5/7 vdpa/mlx5: Add RX counters to debugfs

In reply to Eli Cohen

For each interface, either VLAN tagged or untagged, add two hardware
counters: one for unicast and another for multicast. The counters count RX packets and bytes and can be read through debugfs:

$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-0/rx/untagged/mcast/packets
$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-0/rx/untagged/ucast/bytes

This feature is controlled via the config option MLX5_VDPA_STEERING_DEBUG. It is off by default as it may have some impact on performance.

---
 drivers/vdpa/Kconfig              |  12 +++
 drivers/vdpa/mlx5/net/debug.c     |  86 ++++++++++++++++++++++
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 118 +++++++++++++++++++++++-------
 drivers/vdpa/mlx5/net/mlx5_vnet.h |  30 ++++++++
 4 files changed, 218 insertions(+), 28 deletions(-)
drivers/vdpa/Kconfig +12 -0
index 50f45d037611..43b716ec2d18 100644
@@ -71,6 +71,18 @@ config MLX5_VDPA_NET
 	  be executed by the hardware. It also supports a variety of stateless
 	  offloads depending on the actual device used and firmware version.
 
+config MLX5_VDPA_STEERING_DEBUG
+	bool "expose steering counters on debugfs"
+	select MLX5_VDPA
+	help
+	  Expose RX steering counters in debugfs to aid in debugging. For each VLAN
+	  or non VLAN interface, two hardware counters are added to the RX flow
+	  table: one for unicast and one for multicast.
+	  The counters counts the number of packets and bytes and exposes them in
+	  debugfs. Once can read the counters using, e.g.:
+	  cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-0/rx/untagged/ucast/packets
+	  cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-0/rx/untagged/mcast/bytes
+
 config VP_VDPA
 	tristate "Virtio PCI bridge vDPA driver"
 	select VIRTIO_PCI_LIB
drivers/vdpa/mlx5/net/debug.c +86 -0

92 lines not on this page · raw message

drivers/vdpa/mlx5/net/mlx5_vnet.c +90 -28

201 lines not on this page · raw message

drivers/vdpa/mlx5/net/mlx5_vnet.h +30 -0
index f2cef3925e5b..c90a89e1de4d 100644
@@ -21,6 +21,11 @@ struct mlx5_vdpa_net_resources {
 
 #define MLX5V_MACVLAN_SIZE 256
 
+static inline u16 key2vid(u64 key)
+{
+	return (u16)(key >> 48) & 0xfff;
+}
+
 struct mlx5_vdpa_net {
 	struct mlx5_vdpa_dev mvdev;
 	struct mlx5_vdpa_net_resources res;
@@ -47,11 +52,24 @@ struct mlx5_vdpa_net {
 	struct dentry *debugfs;
 };
 
+struct mlx5_vdpa_counter {
+	struct mlx5_fc *counter;
+	struct dentry *dent;
+	struct mlx5_core_dev *mdev;
+};
+
 struct macvlan_node {
 	struct hlist_node hlist;
 	struct mlx5_flow_handle *ucast_rule;
 	struct mlx5_flow_handle *mcast_rule;
 	u64 macvlan;
+	struct mlx5_vdpa_net *ndev;
+	bool tagged;
+#if defined(CONFIG_MLX5_VDPA_STEERING_DEBUG)
+	struct dentry *dent;
+	struct mlx5_vdpa_counter ucast_counter;
+	struct mlx5_vdpa_counter mcast_counter;
+#endif
 };
 
 void mlx5_vdpa_add_debugfs(struct mlx5_vdpa_net *ndev);
@@ -60,5 +78,17 @@ void mlx5_vdpa_add_rx_flow_table(struct mlx5_vdpa_net *ndev);
 void mlx5_vdpa_remove_rx_flow_table(struct mlx5_vdpa_net *ndev);
 void mlx5_vdpa_add_tirn(struct mlx5_vdpa_net *ndev);
 void mlx5_vdpa_remove_tirn(struct mlx5_vdpa_net *ndev);
+#if defined(CONFIG_MLX5_VDPA_STEERING_DEBUG)
+void mlx5_vdpa_add_rx_counters(struct mlx5_vdpa_net *ndev,
+			       struct macvlan_node *node);
+void mlx5_vdpa_remove_rx_counters(struct mlx5_vdpa_net *ndev,
+				  struct macvlan_node *node);
+#else
+static inline void mlx5_vdpa_add_rx_counters(struct mlx5_vdpa_net *ndev,
+					     struct macvlan_node *node) {}
+static inline void mlx5_vdpa_remove_rx_counters(struct mlx5_vdpa_net *ndev,
+						struct macvlan_node *node) {}
+#endif
+
 
 #endif /* __MLX5_VNET_H__ */
Signature · 1 line
2.38.1
author
#15 lore raw

PATCH 6/7 vdpa/mlx5: Avoid using reslock in event_handler

In reply to Eli Cohen

event_handler runs under atomic context and may not acquire reslock. We can still guarantee that the handler won't be called after suspend by clearing nb_registered, unregistering the handler and flushing the workqueue.

---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +3 -11
index 6e6490c85be2..bebfba530247 100644
@@ -2872,8 +2872,8 @@ static int mlx5_vdpa_suspend(struct vdpa_device *vdev)
 	int i;
 
 	down_write(&ndev->reslock);
-	mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);
 	ndev->nb_registered = false;
+	mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);
 	flush_workqueue(ndev->mvdev.wq);
 	for (i = 0; i < ndev->cur_num_vqs; i++) {
 		mvq = &ndev->vqs[i];
@@ -3051,7 +3051,7 @@ static void update_carrier(struct work_struct *work)
 	else
 		ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP);
 
-	if (ndev->config_cb.callback)
+	if (ndev->nb_registered && ndev->config_cb.callback)
 		ndev->config_cb.callback(ndev->config_cb.private);
 
 	kfree(wqent);
@@ -3068,21 +3068,13 @@ static int event_handler(struct notifier_block *nb, unsigned long event, void *p
 		switch (eqe->sub_type) {
 		case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
 		case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
-			down_read(&ndev->reslock);
-			if (!ndev->nb_registered) {
-				up_read(&ndev->reslock);
-				return NOTIFY_DONE;
-			}
 			wqent = kzalloc(sizeof(*wqent), GFP_ATOMIC);
-			if (!wqent) {
-				up_read(&ndev->reslock);
+			if (!wqent)
 				return NOTIFY_DONE;
-			}
 
 			wqent->mvdev = &ndev->mvdev;
 			INIT_WORK(&wqent->work, update_carrier);
 			queue_work(ndev->mvdev.wq, &wqent->work);
-			up_read(&ndev->reslock);
 			ret = NOTIFY_OK;
 			break;
 		default:
Signature · 1 line
2.38.1
author
#20 lore raw

PATCH 7/7 vdpa/mlx5: Avoid overwriting CVQ iotlb

In reply to Eli Cohen

When qemu uses different address spaces for data and control virtqueues, the current code would overwrite the control virtqueue iotlb through the dup_iotlb call. Fix this by referring to the address space identifier and the group to asid mapping to determine which mapping needs to be updated. We also move the address space logic from mlx5 net to core directory.

---
 drivers/vdpa/mlx5/core/mlx5_vdpa.h |  5 +--
 drivers/vdpa/mlx5/core/mr.c        | 44 ++++++++++++++++-----------
 drivers/vdpa/mlx5/net/mlx5_vnet.c  | 49 ++++++------------------------
 3 files changed, 39 insertions(+), 59 deletions(-)
drivers/vdpa/mlx5/core/mlx5_vdpa.h +3 -2
index 6af9fdbb86b7..058fbe28107e 100644
@@ -116,8 +116,9 @@ int mlx5_vdpa_create_mkey(struct mlx5_vdpa_dev *mvdev, u32 *mkey, u32 *in,
 			  int inlen);
 int mlx5_vdpa_destroy_mkey(struct mlx5_vdpa_dev *mvdev, u32 mkey);
 int mlx5_vdpa_handle_set_map(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
-			     bool *change_map);
-int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb);
+			     bool *change_map, unsigned int asid);
+int mlx5_vdpa_create_mr(struct mlx5_vdpa_dev *mvdev, struct vhost_iotlb *iotlb,
+			unsigned int asid);
 void mlx5_vdpa_destroy_mr(struct mlx5_vdpa_dev *mvdev);
 
 #define mlx5_vdpa_warn(__dev, format, ...)                                                         \
drivers/vdpa/mlx5/core/mr.c +26 -18

82 lines not on this page · raw message

drivers/vdpa/mlx5/net/mlx5_vnet.c +10 -39

95 lines not on this page · raw message

Signature · 1 line
2.38.1
#21 lore raw
In reply to Eli Cohen
Quoted 9 lines · Eli Cohen

This series is a resend of previously sent patch list. It adds a few fixes so I treat as a v0 of a new series.

It adds a kernel config param CONFIG_MLX5_VDPA_STEERING_DEBUG that when eabled allows to read rx unicast and multicast counters per tagged or untagged traffic.

Examples:

$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-0/rx/untagged/mcast/packets
$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-0/rx/untagged/ucast/bytes

Thanks!
Is this patchset intended for 6.2 then?

Quoted 10 lines

Eli Cohen (7):
vdpa/mlx5: Fix rule forwarding VLAN to TIR vdpa/mlx5: Fix wrong mac address deletion vdpa/mlx5: Move some definitions to a new header file vdpa/mlx5: Add debugfs subtree
vdpa/mlx5: Add RX counters to debugfs vdpa/mlx5: Avoid using reslock in event_handler vdpa/mlx5: Avoid overwriting CVQ iotlb

Quoted 13 lines
 drivers/vdpa/Kconfig               |  12 ++
 drivers/vdpa/mlx5/Makefile         |   2 +-
 drivers/vdpa/mlx5/core/mlx5_vdpa.h |   5 +-
 drivers/vdpa/mlx5/core/mr.c        |  44 ++---
 drivers/vdpa/mlx5/net/debug.c      | 152 ++++++++++++++++++
 drivers/vdpa/mlx5/net/mlx5_vnet.c  | 248 ++++++++++++++---------------
 drivers/vdpa/mlx5/net/mlx5_vnet.h  |  94 +++++++++++
 7 files changed, 411 insertions(+), 146 deletions(-)
 create mode 100644 drivers/vdpa/mlx5/net/debug.c
 create mode 100644 drivers/vdpa/mlx5/net/mlx5_vnet.h
Signature · 1 line
2.38.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#22 lore raw
Quoted 19 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Sunday, 13 November 2022 15:52
To: Eli Cohen <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 0/7] vdpa/mlx5: Add debugfs subtree and fixes

Quoted 4 lines · Eli Cohen

This series is a resend of previously sent patch list. It adds a few fixes so I treat as a v0 of a new series.

It adds a kernel config param CONFIG_MLX5_VDPA_STEERING_DEBUG that

when

Quoted 1 line

eabled allows to read rx unicast and multicast counters per tagged or

untagged traffic.

Quoted 3 lines

Examples:

$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-
Quoted 8 lines

0/rx/untagged/mcast/packets

Quoted 1 line
$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-

0/rx/untagged/ucast/bytes

Thanks!
Is this patchset intended for 6.2 then?

The debugfs part can go to 6.2 but maybe the fixes should go to 6.1.

Quoted 23 lines
Quoted 23 lines

Eli Cohen (7):
vdpa/mlx5: Fix rule forwarding VLAN to TIR vdpa/mlx5: Fix wrong mac address deletion vdpa/mlx5: Move some definitions to a new header file vdpa/mlx5: Add debugfs subtree
vdpa/mlx5: Add RX counters to debugfs vdpa/mlx5: Avoid using reslock in event_handler vdpa/mlx5: Avoid overwriting CVQ iotlb

 drivers/vdpa/Kconfig               |  12 ++
 drivers/vdpa/mlx5/Makefile         |   2 +-
 drivers/vdpa/mlx5/core/mlx5_vdpa.h |   5 +-
 drivers/vdpa/mlx5/core/mr.c        |  44 ++---
 drivers/vdpa/mlx5/net/debug.c      | 152 ++++++++++++++++++
 drivers/vdpa/mlx5/net/mlx5_vnet.c  | 248 ++++++++++++++---------------
 drivers/vdpa/mlx5/net/mlx5_vnet.h  |  94 +++++++++++
 7 files changed, 411 insertions(+), 146 deletions(-)
 create mode 100644 drivers/vdpa/mlx5/net/debug.c
 create mode 100644 drivers/vdpa/mlx5/net/mlx5_vnet.h

--
2.38.1

#23 lore raw
Quoted 21 lines · Eli Cohen
Quoted 21 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Sunday, 13 November 2022 15:52
To: Eli Cohen <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 0/7] vdpa/mlx5: Add debugfs subtree and fixes

Quoted 4 lines · Eli Cohen

This series is a resend of previously sent patch list. It adds a few fixes so I treat as a v0 of a new series.

It adds a kernel config param CONFIG_MLX5_VDPA_STEERING_DEBUG that

when

Quoted 1 line

eabled allows to read rx unicast and multicast counters per tagged or

untagged traffic.

Quoted 3 lines

Examples:

$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-

0/rx/untagged/mcast/packets

Quoted 1 line
$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-
Quoted 8 lines
Quoted 6 lines

0/rx/untagged/ucast/bytes

Thanks!
Is this patchset intended for 6.2 then?

The debugfs part can go to 6.2 but maybe the fixes should go to 6.1.

Tat's fine - do they apply cleanly if I just drop 4/7?

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines

Eli Cohen (7):
vdpa/mlx5: Fix rule forwarding VLAN to TIR vdpa/mlx5: Fix wrong mac address deletion vdpa/mlx5: Move some definitions to a new header file vdpa/mlx5: Add debugfs subtree
vdpa/mlx5: Add RX counters to debugfs vdpa/mlx5: Avoid using reslock in event_handler vdpa/mlx5: Avoid overwriting CVQ iotlb

 drivers/vdpa/Kconfig               |  12 ++
 drivers/vdpa/mlx5/Makefile         |   2 +-
 drivers/vdpa/mlx5/core/mlx5_vdpa.h |   5 +-
 drivers/vdpa/mlx5/core/mr.c        |  44 ++---
 drivers/vdpa/mlx5/net/debug.c      | 152 ++++++++++++++++++
 drivers/vdpa/mlx5/net/mlx5_vnet.c  | 248 ++++++++++++++---------------
 drivers/vdpa/mlx5/net/mlx5_vnet.h  |  94 +++++++++++
 7 files changed, 411 insertions(+), 146 deletions(-)
 create mode 100644 drivers/vdpa/mlx5/net/debug.c
 create mode 100644 drivers/vdpa/mlx5/net/mlx5_vnet.h
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

--
2.38.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#24 lore raw
Quoted 34 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Sunday, 13 November 2022 15:58
To: Eli Cohen <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 0/7] vdpa/mlx5: Add debugfs subtree and fixes

Quoted 8 lines · Eli Cohen
Quoted 8 lines

From: Michael S. Tsirkin <[email protected]>
Sent: Sunday, 13 November 2022 15:52
To: Eli Cohen <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 0/7] vdpa/mlx5: Add debugfs subtree and fixes

Quoted 5 lines
Quoted 5 lines · Eli Cohen
Quoted 4 lines

This series is a resend of previously sent patch list. It adds a few fixes so I treat as a v0 of a new series.

It adds a kernel config param CONFIG_MLX5_VDPA_STEERING_DEBUG

that

Quoted 11 lines
Quoted 11 lines

when

Quoted 1 line

eabled allows to read rx unicast and multicast counters per tagged or

untagged traffic.

Quoted 3 lines

Examples:

$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-

0/rx/untagged/mcast/packets

Quoted 1 line
$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-

0/rx/untagged/ucast/bytes

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Thanks!
Is this patchset intended for 6.2 then?

The debugfs part can go to 6.2 but maybe the fixes should go to 6.1.

Tat's fine - do they apply cleanly if I just drop 4/7?

Yes, just checked 0002, 0003, and 0007 fixes apply cleanly

Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 24 lines

Eli Cohen (7):
vdpa/mlx5: Fix rule forwarding VLAN to TIR vdpa/mlx5: Fix wrong mac address deletion vdpa/mlx5: Move some definitions to a new header file vdpa/mlx5: Add debugfs subtree
vdpa/mlx5: Add RX counters to debugfs vdpa/mlx5: Avoid using reslock in event_handler vdpa/mlx5: Avoid overwriting CVQ iotlb

 drivers/vdpa/Kconfig               |  12 ++
 drivers/vdpa/mlx5/Makefile         |   2 +-
 drivers/vdpa/mlx5/core/mlx5_vdpa.h |   5 +-
 drivers/vdpa/mlx5/core/mr.c        |  44 ++---
 drivers/vdpa/mlx5/net/debug.c      | 152 ++++++++++++++++++
 drivers/vdpa/mlx5/net/mlx5_vnet.c  | 248 ++++++++++++++---------------
 drivers/vdpa/mlx5/net/mlx5_vnet.h  |  94 +++++++++++
 7 files changed, 411 insertions(+), 146 deletions(-)
 create mode 100644 drivers/vdpa/mlx5/net/debug.c
 create mode 100644 drivers/vdpa/mlx5/net/mlx5_vnet.h

--
2.38.1

Acked-by on v1 1/7
#2 lore raw

Re: [PATCH 1/7] vdpa/mlx5: Fix rule forwarding VLAN to TIR

In reply to Eli Cohen
Quoted 41 lines · Eli Cohen

Set the VLAN id to the header values field instead of overwriting the headers criteria field.

Before this fix, VLAN filtering would not really work and tagged packets would be forwarded unfiltered to the TIR.

In addition modify the logic so that VLAN filtering is enforced only when VIRTIO_NET_F_CTRL_VLAN is negotiated. When not negotiated, all incoming traffic is accepted as long as it is targeting the net device's MAC address.

Fixes baf2ad3f6a98 ("vdpa/mlx5: Add RX MAC VLAN filter support")
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +5 -3
index 90913365def4..ea95081eca0c 100644
@@ -1468,11 +1468,13 @@ static int mlx5_vdpa_add_mac_vlan_rules(struct mlx5_vdpa_net *ndev, u8 *mac,
        dmac_v = MLX5_ADDR_OF(fte_match_param, headers_v, outer_headers.dmac_47_16);
        eth_broadcast_addr(dmac_c);
        ether_addr_copy(dmac_v, mac);
-       MLX5_SET(fte_match_set_lyr_2_4, headers_c, cvlan_tag, 1);
+       if (ndev->mvdev.actual_features & VIRTIO_NET_F_CTRL_VLAN) {
+               MLX5_SET(fte_match_set_lyr_2_4, headers_c, cvlan_tag, 1);
+               MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c, first_vid);
+       }
        if (tagged) {
                MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag, 1);
-               MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c, first_vid);
-               MLX5_SET(fte_match_set_lyr_2_4, headers_c, first_vid, vid);
+               MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_vid, vid);
        }
        flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
        dest.type = MLX5_FLOW_DESTINATION_TYPE_TIR;

drivers/vdpa/mlx5/net/mlx5_vnet.c static virtio_net_ctrl_ack handle_ctrl_vlan(struct mlx5_vdpa_dev *mvdev, u8 cmd) · line 1827

Quoted 5 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +2 -0
@@ -1821,6 +1823,9 @@ static virtio_net_ctrl_ack handle_ctrl_vlan(struct mlx5_vdpa_dev *mvdev, u8 cmd)
        size_t read;
        u16 id;
 
+       if (!(ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_CTRL_VLAN)))
+               return status;

Nit: this seems unrelated to the patch.

Other than this.

Quoted 7 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
+
        switch (cmd) {
        case VIRTIO_NET_CTRL_VLAN_ADD:
                read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->riov, &vlan, sizeof(vlan));
--

2.38.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Acked-by on v1 2/7
#7 lore raw

Re: [PATCH 2/7] vdpa/mlx5: Fix wrong mac address deletion

In reply to Eli Cohen
Quoted 6 lines · Eli Cohen

Delete the old MAC from the table and not the new one which is not there yet.

Fixes baf2ad3f6a98 ("vdpa/mlx5: Add RX MAC VLAN filter support")
Quoted 18 lines
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -2
index ea95081eca0c..c54d5088ed4f 100644
@@ -1686,7 +1686,7 @@ static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd)
 
                /* Need recreate the flow table entry, so that the packet could forward back
                 */
-               mac_vlan_del(ndev, ndev->config.mac, 0, false);
+               mac_vlan_del(ndev, mac_back, 0, false);
 
                if (mac_vlan_add(ndev, ndev->config.mac, 0, false)) {
                        mlx5_vdpa_warn(mvdev, "failed to insert forward rules, try to restore\n");
--
Quoted 2 lines

2.38.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Acked-by on v1 3/7
#9 lore raw

Re: [PATCH 3/7] vdpa/mlx5: Move some definitions to a new header file

In reply to Eli Cohen
Quoted 7 lines · Eli Cohen

Move some definitions from mlx5_vnet.c to newly added header file mlx5_vnet.h. We need these definitions for the following patches that add debugfs tree to expose information vital for debug.

Thanks

Quoted 143 lines
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 45 +------------------------
 drivers/vdpa/mlx5/net/mlx5_vnet.h | 55 +++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 44 deletions(-)
 create mode 100644 drivers/vdpa/mlx5/net/mlx5_vnet.h
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -44
index c54d5088ed4f..e45b83527b41 100644
@@ -18,15 +18,12 @@
 #include <linux/mlx5/mlx5_ifc_vdpa.h>
 #include <linux/mlx5/mpfs.h>
 #include "mlx5_vdpa.h"
+#include "mlx5_vnet.h"
 
 MODULE_AUTHOR("Eli Cohen <[email protected]>");
 MODULE_DESCRIPTION("Mellanox VDPA driver");
 MODULE_LICENSE("Dual BSD/GPL");
 
-#define to_mlx5_vdpa_ndev(__mvdev)                                             \
-       container_of(__mvdev, struct mlx5_vdpa_net, mvdev)
-#define to_mvdev(__vdev) container_of((__vdev), struct mlx5_vdpa_dev, vdev)
-
 #define VALID_FEATURES_MASK                                                                        \
        (BIT_ULL(VIRTIO_NET_F_CSUM) | BIT_ULL(VIRTIO_NET_F_GUEST_CSUM) |                                   \
         BIT_ULL(VIRTIO_NET_F_CTRL_GUEST_OFFLOADS) | BIT_ULL(VIRTIO_NET_F_MTU) | BIT_ULL(VIRTIO_NET_F_MAC) |   \
@@ -50,14 +47,6 @@ MODULE_LICENSE("Dual BSD/GPL");
 
 #define MLX5V_UNTAGGED 0x1000
 
-struct mlx5_vdpa_net_resources {
-       u32 tisn;
-       u32 tdn;
-       u32 tirn;
-       u32 rqtn;
-       bool valid;
-};
-
 struct mlx5_vdpa_cq_buf {
        struct mlx5_frag_buf_ctrl fbc;
        struct mlx5_frag_buf frag_buf;
@@ -146,38 +135,6 @@ static bool is_index_valid(struct mlx5_vdpa_dev *mvdev, u16 idx)
        return idx <= mvdev->max_idx;
 }
 
-#define MLX5V_MACVLAN_SIZE 256
-
-struct mlx5_vdpa_net {
-       struct mlx5_vdpa_dev mvdev;
-       struct mlx5_vdpa_net_resources res;
-       struct virtio_net_config config;
-       struct mlx5_vdpa_virtqueue *vqs;
-       struct vdpa_callback *event_cbs;
-
-       /* Serialize vq resources creation and destruction. This is required
-        * since memory map might change and we need to destroy and create
-        * resources while driver in operational.
-        */
-       struct rw_semaphore reslock;
-       struct mlx5_flow_table *rxft;
-       bool setup;
-       u32 cur_num_vqs;
-       u32 rqt_size;
-       bool nb_registered;
-       struct notifier_block nb;
-       struct vdpa_callback config_cb;
-       struct mlx5_vdpa_wq_ent cvq_ent;
-       struct hlist_head macvlan_hash[MLX5V_MACVLAN_SIZE];
-};
-
-struct macvlan_node {
-       struct hlist_node hlist;
-       struct mlx5_flow_handle *ucast_rule;
-       struct mlx5_flow_handle *mcast_rule;
-       u64 macvlan;
-};
-
 static void free_resources(struct mlx5_vdpa_net *ndev);
 static void init_mvqs(struct mlx5_vdpa_net *ndev);
 static int setup_driver(struct mlx5_vdpa_dev *mvdev);
drivers/vdpa/mlx5/net/mlx5_vnet.h new file +55 -1
new file mode 100644
index 000000000000..6691c879a6ca
@@ -0,0 +1,55 @@
+/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
+/* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
+
+#ifndef __MLX5_VNET_H__
+#define __MLX5_VNET_H__
+
+#include "mlx5_vdpa.h"
+
+#define to_mlx5_vdpa_ndev(__mvdev)                                             \
+       container_of(__mvdev, struct mlx5_vdpa_net, mvdev)
+#define to_mvdev(__vdev) container_of((__vdev), struct mlx5_vdpa_dev, vdev)
+
+struct mlx5_vdpa_net_resources {
+       u32 tisn;
+       u32 tdn;
+       u32 tirn;
+       u32 rqtn;
+       bool valid;
+};
+
+#define MLX5V_MACVLAN_SIZE 256
+
+struct mlx5_vdpa_net {
+       struct mlx5_vdpa_dev mvdev;
+       struct mlx5_vdpa_net_resources res;
+       struct virtio_net_config config;
+       struct mlx5_vdpa_virtqueue *vqs;
+       struct vdpa_callback *event_cbs;
+
+       /* Serialize vq resources creation and destruction. This is required
+        * since memory map might change and we need to destroy and create
+        * resources while driver in operational.
+        */
+       struct rw_semaphore reslock;
+       struct mlx5_flow_table *rxft;
+       struct dentry *rx_dent;
+       struct dentry *rx_table_dent;
+       bool setup;
+       u32 cur_num_vqs;
+       u32 rqt_size;
+       bool nb_registered;
+       struct notifier_block nb;
+       struct vdpa_callback config_cb;
+       struct mlx5_vdpa_wq_ent cvq_ent;
+       struct hlist_head macvlan_hash[MLX5V_MACVLAN_SIZE];
+};
+
+struct macvlan_node {
+       struct hlist_node hlist;
+       struct mlx5_flow_handle *ucast_rule;
+       struct mlx5_flow_handle *mcast_rule;
+       u64 macvlan;
+};
+
+#endif /* __MLX5_VNET_H__ */
--
Quoted 2 lines

2.38.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Acked-by on v1 4/7
#11 lore raw

Re: [PATCH 4/7] vdpa/mlx5: Add debugfs subtree

In reply to Eli Cohen
Quoted 11 lines · Eli Cohen

Add debugfs subtree and expose flow table ID and TIR number. This information can be used by external tools to do extended troubleshooting.

The information can be retrieved like so:

$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-0/rx/table_id
$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-0/rx/tirn
Quoted 185 lines
---
 drivers/vdpa/mlx5/Makefile        |  2 +-
 drivers/vdpa/mlx5/net/debug.c     | 66 +++++++++++++++++++++++++++++++
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 11 ++++++
 drivers/vdpa/mlx5/net/mlx5_vnet.h |  9 +++++
 4 files changed, 87 insertions(+), 1 deletion(-)
 create mode 100644 drivers/vdpa/mlx5/net/debug.c
drivers/vdpa/mlx5/Makefile +1 -1
index f717978c83bf..e791394c33e3 100644
@@ -1,4 +1,4 @@
 subdir-ccflags-y += -I$(srctree)/drivers/vdpa/mlx5/core
 
 obj-$(CONFIG_MLX5_VDPA_NET) += mlx5_vdpa.o
-mlx5_vdpa-$(CONFIG_MLX5_VDPA_NET) += net/mlx5_vnet.o core/resources.o core/mr.o
+mlx5_vdpa-$(CONFIG_MLX5_VDPA_NET) += net/mlx5_vnet.o core/resources.o core/mr.o net/debug.o
drivers/vdpa/mlx5/net/debug.c new file +66 -0
new file mode 100644
index 000000000000..95e4801df211
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+/* Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */
+
+#include <linux/debugfs.h>
+#include <linux/mlx5/fs.h>
+#include "mlx5_vnet.h"
+
+static int tirn_show(struct seq_file *file, void *priv)
+{
+       struct mlx5_vdpa_net *ndev = file->private;
+
+       seq_printf(file, "0x%x\n", ndev->res.tirn);
+       return 0;
+}
+
+DEFINE_SHOW_ATTRIBUTE(tirn);
+
+void mlx5_vdpa_remove_tirn(struct mlx5_vdpa_net *ndev)
+{
+       if (ndev->debugfs)
+               debugfs_remove(ndev->res.tirn_dent);
+}
+
+void mlx5_vdpa_add_tirn(struct mlx5_vdpa_net *ndev)
+{
+       ndev->res.tirn_dent = debugfs_create_file("tirn", 0444, ndev->rx_dent,
+                                                 ndev, &tirn_fops);
+}
+
+static int rx_flow_table_show(struct seq_file *file, void *priv)
+{
+       struct mlx5_vdpa_net *ndev = file->private;
+
+       seq_printf(file, "0x%x\n", mlx5_flow_table_id(ndev->rxft));
+       return 0;
+}
+
+DEFINE_SHOW_ATTRIBUTE(rx_flow_table);
+
+void mlx5_vdpa_remove_rx_flow_table(struct mlx5_vdpa_net *ndev)
+{
+       if (ndev->debugfs)
+               debugfs_remove(ndev->rx_table_dent);
+}
+
+void mlx5_vdpa_add_rx_flow_table(struct mlx5_vdpa_net *ndev)
+{
+       ndev->rx_table_dent = debugfs_create_file("table_id", 0444, ndev->rx_dent,
+                                                 ndev, &rx_flow_table_fops);
+}
+
+void mlx5_vdpa_add_debugfs(struct mlx5_vdpa_net *ndev)
+{
+       struct mlx5_core_dev *mdev;
+
+       mdev = ndev->mvdev.mdev;
+       ndev->debugfs = debugfs_create_dir(dev_name(&ndev->mvdev.vdev.dev),
+                                          mlx5_debugfs_get_dev_root(mdev));
+       if (!IS_ERR(ndev->debugfs))
+               ndev->rx_dent = debugfs_create_dir("rx", ndev->debugfs);
+}
+
+void mlx5_vdpa_remove_debugfs(struct dentry *dbg)
+{
+       debugfs_remove_recursive(dbg);
+}
drivers/vdpa/mlx5/net/mlx5_vnet.c +11 -0
index e45b83527b41..ce2f478a93f5 100644
@@ -1388,11 +1388,16 @@ static int create_tir(struct mlx5_vdpa_net *ndev)
 
        err = mlx5_vdpa_create_tir(&ndev->mvdev, in, &ndev->res.tirn);
        kfree(in);
+       if (err)
+               return err;
+
+       mlx5_vdpa_add_tirn(ndev);
        return err;
 }
 
 static void destroy_tir(struct mlx5_vdpa_net *ndev)
 {
+       mlx5_vdpa_remove_tirn(ndev);
        mlx5_vdpa_destroy_tir(&ndev->mvdev, ndev->res.tirn);
 }
 
@@ -1578,6 +1583,7 @@ static int setup_steering(struct mlx5_vdpa_net *ndev)
                mlx5_vdpa_warn(&ndev->mvdev, "failed to create flow table\n");
                return PTR_ERR(ndev->rxft);
        }
+       mlx5_vdpa_add_rx_flow_table(ndev);
 
        err = mac_vlan_add(ndev, ndev->config.mac, 0, false);
        if (err)
@@ -1586,6 +1592,7 @@ static int setup_steering(struct mlx5_vdpa_net *ndev)
        return 0;
 
 err_add:
+       mlx5_vdpa_remove_rx_flow_table(ndev);
        mlx5_destroy_flow_table(ndev->rxft);
        return err;
 }
@@ -1593,6 +1600,7 @@ static int setup_steering(struct mlx5_vdpa_net *ndev)
 static void teardown_steering(struct mlx5_vdpa_net *ndev)
 {
        clear_mac_vlan_table(ndev);
+       mlx5_vdpa_remove_rx_flow_table(ndev);
        mlx5_destroy_flow_table(ndev->rxft);
 }
 
@@ -3172,6 +3180,7 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
        if (err)
                goto err_reg;
 
+       mlx5_vdpa_add_debugfs(ndev);
        mgtdev->ndev = ndev;
        return 0;
 
@@ -3198,6 +3207,8 @@ static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
        struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
        struct workqueue_struct *wq;
 
+       mlx5_vdpa_remove_debugfs(ndev->debugfs);
+       ndev->debugfs = NULL;
        if (ndev->nb_registered) {
                mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);
                ndev->nb_registered = false;
drivers/vdpa/mlx5/net/mlx5_vnet.h +9 -1
index 6691c879a6ca..f2cef3925e5b 100644
@@ -16,6 +16,7 @@ struct mlx5_vdpa_net_resources {
        u32 tirn;
        u32 rqtn;
        bool valid;
+       struct dentry *tirn_dent;
 };
 
 #define MLX5V_MACVLAN_SIZE 256
@@ -43,6 +44,7 @@ struct mlx5_vdpa_net {
        struct vdpa_callback config_cb;
        struct mlx5_vdpa_wq_ent cvq_ent;
        struct hlist_head macvlan_hash[MLX5V_MACVLAN_SIZE];
+       struct dentry *debugfs;
 };
 
 struct macvlan_node {
@@ -52,4 +54,11 @@ struct macvlan_node {
        u64 macvlan;
 };
 
+void mlx5_vdpa_add_debugfs(struct mlx5_vdpa_net *ndev);
+void mlx5_vdpa_remove_debugfs(struct dentry *dbg);
+void mlx5_vdpa_add_rx_flow_table(struct mlx5_vdpa_net *ndev);
+void mlx5_vdpa_remove_rx_flow_table(struct mlx5_vdpa_net *ndev);
+void mlx5_vdpa_add_tirn(struct mlx5_vdpa_net *ndev);
+void mlx5_vdpa_remove_tirn(struct mlx5_vdpa_net *ndev);
+
 #endif /* __MLX5_VNET_H__ */
--
Quoted 2 lines

2.38.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#3 lore raw

RE: [PATCH 1/7] vdpa/mlx5: Fix rule forwarding VLAN to TIR

In reply to Jason Wang
Quoted 54 lines

From: Jason Wang <[email protected]>
Sent: Monday, 14 November 2022 6:39
To: Eli Cohen <[email protected]>
Cc: [email protected]; [email protected]; [email protected] foundation.org; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/7] vdpa/mlx5: Fix rule forwarding VLAN to TIR

Quoted 12 lines · Eli Cohen

Set the VLAN id to the header values field instead of overwriting the headers criteria field.

Before this fix, VLAN filtering would not really work and tagged packets would be forwarded unfiltered to the TIR.

In addition modify the logic so that VLAN filtering is enforced only when VIRTIO_NET_F_CTRL_VLAN is negotiated. When not negotiated, all incoming traffic is accepted as long as it is targeting the net device's MAC address.

Review

Quoted 8 lines
Fixes baf2ad3f6a98 ("vdpa/mlx5: Add RX MAC VLAN filter support")
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/vdpa/mlx5/net/mlx5_vnet.c

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_add_mac_vlan_rules(struct

Quoted 4 lines

index 90913365def4..ea95081eca0c 100644

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1468,11 +1468,13 @@ static int mlx5_vdpa_add_mac_vlan_rules(struct

mlx5_vdpa_net *ndev, u8 *mac,

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_add_mac_vlan_rules(struct · line 1468

Quoted 1 line
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
        dmac_v = MLX5_ADDR_OF(fte_match_param, headers_v,

outer_headers.dmac_47_16);

drivers/vdpa/mlx5/net/mlx5_vnet.c static virtio_net_ctrl_ack handle_ctrl_vlan(struct

Quoted 16 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +5 -3
        eth_broadcast_addr(dmac_c);
        ether_addr_copy(dmac_v, mac);
-       MLX5_SET(fte_match_set_lyr_2_4, headers_c, cvlan_tag, 1);
+       if (ndev->mvdev.actual_features & VIRTIO_NET_F_CTRL_VLAN) {
+               MLX5_SET(fte_match_set_lyr_2_4, headers_c, cvlan_tag, 1);
+               MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c, first_vid);
+       }
        if (tagged) {
                MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag, 1);
-               MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c, first_vid);
-               MLX5_SET(fte_match_set_lyr_2_4, headers_c, first_vid, vid);
+               MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_vid, vid);
        }
        flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
        dest.type = MLX5_FLOW_DESTINATION_TYPE_TIR;
@@ -1821,6 +1823,9 @@ static virtio_net_ctrl_ack handle_ctrl_vlan(struct

mlx5_vdpa_dev *mvdev, u8 cmd)

Quoted 9 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static virtio_net_ctrl_ack handle_ctrl_vlan(struct mlx5_vdpa_dev *mvdev, u8 cmd)

Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -0
        size_t read;
        u16 id;
 
+       if (!(ndev->mvdev.actual_features &

BIT_ULL(VIRTIO_NET_F_CTRL_VLAN)))

drivers/vdpa/mlx5/net/mlx5_vnet.c static virtio_net_ctrl_ack handle_ctrl_vlan(struct mlx5_vdpa_dev *mvdev, u8 cmd) · line 1827

Quoted 1 line
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -0
+               return status;

Nit: this seems unrelated to the patch.

Will put in another patch

Quoted 12 lines

Other than this.

drivers/vdpa/mlx5/net/mlx5_vnet.c static virtio_net_ctrl_ack handle_ctrl_vlan(struct mlx5_vdpa_dev *mvdev, u8 cmd)

Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -0
+
        switch (cmd) {
        case VIRTIO_NET_CTRL_VLAN_ADD:
                read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->riov, &vlan,

sizeof(vlan));

Quoted 3 lines

--
2.38.1

#13 lore raw

Re: [PATCH 5/7] vdpa/mlx5: Add RX counters to debugfs

In reply to Eli Cohen
Quoted 20 lines · Eli Cohen

For each interface, either VLAN tagged or untagged, add two hardware
counters: one for unicast and another for multicast. The counters count RX packets and bytes and can be read through debugfs:

$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-0/rx/untagged/mcast/packets
$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-0/rx/untagged/ucast/bytes

This feature is controlled via the config option MLX5_VDPA_STEERING_DEBUG. It is off by default as it may have some impact on performance.

---
 drivers/vdpa/Kconfig              |  12 +++
 drivers/vdpa/mlx5/net/debug.c     |  86 ++++++++++++++++++++++
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 118 +++++++++++++++++++++++-------
 drivers/vdpa/mlx5/net/mlx5_vnet.h |  30 ++++++++
 4 files changed, 218 insertions(+), 28 deletions(-)

[...]

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_add_mac_vlan_rules(struct mlx5_vdpa_net *ndev, u8 *mac, · line 1478

Quoted 10 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +2 -1
+       vid = key2vid(node->macvlan);
        spec->match_criteria_enable = MLX5_MATCH_OUTER_HEADERS;
        headers_c = MLX5_ADDR_OF(fte_match_param, spec->match_criteria, outer_headers);
        headers_v = MLX5_ADDR_OF(fte_match_param, spec->match_value, outer_headers);
@@ -1430,48 +1475,62 @@ static int mlx5_vdpa_add_mac_vlan_rules(struct mlx5_vdpa_net *ndev, u8 *mac,
        dmac_v = MLX5_ADDR_OF(fte_match_param, headers_v, outer_headers.dmac_47_16);
        eth_broadcast_addr(dmac_c);
        ether_addr_copy(dmac_v, mac);
-       if (ndev->mvdev.actual_features & VIRTIO_NET_F_CTRL_VLAN) {
+       if (ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_CTRL_VLAN)) {

This seems like a fix for patch 1? If yes, let's just squash this.

Thanks

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#16 lore raw

Re: [PATCH 6/7] vdpa/mlx5: Avoid using reslock in event_handler

In reply to Eli Cohen
Quoted 16 lines · Eli Cohen

event_handler runs under atomic context and may not acquire reslock. We can still guarantee that the handler won't be called after suspend by clearing nb_registered, unregistering the handler and flushing the workqueue.

---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
index 6e6490c85be2..bebfba530247 100644

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_suspend(struct vdpa_device *vdev) · line 2876

Quoted 6 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
@@ -2872,8 +2872,8 @@ static int mlx5_vdpa_suspend(struct vdpa_device *vdev)
        int i;
 
        down_write(&ndev->reslock);
-       mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);
        ndev->nb_registered = false;
+       mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);

I wonder why this can help anything. And if it does, we have simliar logic in mlx5_vdpa_dev_del() do we need to fix that as well?

Thanks

Quoted 36 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +2 -11
        flush_workqueue(ndev->mvdev.wq);
        for (i = 0; i < ndev->cur_num_vqs; i++) {
                mvq = &ndev->vqs[i];
@@ -3051,7 +3051,7 @@ static void update_carrier(struct work_struct *work)
        else
                ndev->config.status &= cpu_to_mlx5vdpa16(mvdev, ~VIRTIO_NET_S_LINK_UP);
 
-       if (ndev->config_cb.callback)
+       if (ndev->nb_registered && ndev->config_cb.callback)
                ndev->config_cb.callback(ndev->config_cb.private);
 
        kfree(wqent);
@@ -3068,21 +3068,13 @@ static int event_handler(struct notifier_block *nb, unsigned long event, void *p
                switch (eqe->sub_type) {
                case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
                case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
-                       down_read(&ndev->reslock);
-                       if (!ndev->nb_registered) {
-                               up_read(&ndev->reslock);
-                               return NOTIFY_DONE;
-                       }
                        wqent = kzalloc(sizeof(*wqent), GFP_ATOMIC);
-                       if (!wqent) {
-                               up_read(&ndev->reslock);
+                       if (!wqent)
                                return NOTIFY_DONE;
-                       }
 
                        wqent->mvdev = &ndev->mvdev;
                        INIT_WORK(&wqent->work, update_carrier);
                        queue_work(ndev->mvdev.wq, &wqent->work);
-                       up_read(&ndev->reslock);
                        ret = NOTIFY_OK;
                        break;
                default:
--
Quoted 2 lines

2.38.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

#4 lore raw

Re: [PATCH 1/7] vdpa/mlx5: Fix rule forwarding VLAN to TIR

In reply to Eli Cohen
Quoted 57 lines · Eli Cohen
Quoted 57 lines

From: Jason Wang <[email protected]>
Sent: Monday, 14 November 2022 6:39
To: Eli Cohen <[email protected]>
Cc: [email protected]; [email protected]; [email protected] foundation.org; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/7] vdpa/mlx5: Fix rule forwarding VLAN to TIR

Quoted 12 lines · Eli Cohen

Set the VLAN id to the header values field instead of overwriting the headers criteria field.

Before this fix, VLAN filtering would not really work and tagged packets would be forwarded unfiltered to the TIR.

In addition modify the logic so that VLAN filtering is enforced only when VIRTIO_NET_F_CTRL_VLAN is negotiated. When not negotiated, all incoming traffic is accepted as long as it is targeting the net device's MAC address.

Review

Quoted 8 lines
Fixes baf2ad3f6a98 ("vdpa/mlx5: Add RX MAC VLAN filter support")
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
(quoted diff) +0 -0

b/drivers/vdpa/mlx5/net/mlx5_vnet.c

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_add_mac_vlan_rules(struct

Quoted 4 lines

index 90913365def4..ea95081eca0c 100644

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1468,11 +1468,13 @@ static int mlx5_vdpa_add_mac_vlan_rules(struct

mlx5_vdpa_net *ndev, u8 *mac,

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_add_mac_vlan_rules(struct · line 1468

Quoted 1 line
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
        dmac_v = MLX5_ADDR_OF(fte_match_param, headers_v,

outer_headers.dmac_47_16);

drivers/vdpa/mlx5/net/mlx5_vnet.c static virtio_net_ctrl_ack handle_ctrl_vlan(struct

Quoted 16 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +5 -3
        eth_broadcast_addr(dmac_c);
        ether_addr_copy(dmac_v, mac);
-       MLX5_SET(fte_match_set_lyr_2_4, headers_c, cvlan_tag, 1);
+       if (ndev->mvdev.actual_features & VIRTIO_NET_F_CTRL_VLAN) {
+               MLX5_SET(fte_match_set_lyr_2_4, headers_c, cvlan_tag, 1);
+               MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c, first_vid);
+       }
        if (tagged) {
                MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag, 1);
-               MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c, first_vid);
-               MLX5_SET(fte_match_set_lyr_2_4, headers_c, first_vid, vid);
+               MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_vid, vid);
        }
        flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
        dest.type = MLX5_FLOW_DESTINATION_TYPE_TIR;
@@ -1821,6 +1823,9 @@ static virtio_net_ctrl_ack handle_ctrl_vlan(struct

mlx5_vdpa_dev *mvdev, u8 cmd)

Quoted 3 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
        size_t read;
        u16 id;
 
Quoted 7 lines
Quoted 6 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static virtio_net_ctrl_ack handle_ctrl_vlan(struct · line 1826

Quoted 1 line
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -0
+       if (!(ndev->mvdev.actual_features &

BIT_ULL(VIRTIO_NET_F_CTRL_VLAN)))

drivers/vdpa/mlx5/net/mlx5_vnet.c static virtio_net_ctrl_ack handle_ctrl_vlan(struct mlx5_vdpa_dev *mvdev, u8 cmd) · line 1827

Quoted 1 line
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -0
+               return status;

Nit: this seems unrelated to the patch.

Will put in another patch

OK since you are doing a new version, please split fixes and features in two patchsets. Thanks!

Quoted 4 lines
Quoted 4 lines

Other than this.

Quoted 9 lines
Quoted 8 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static virtio_net_ctrl_ack handle_ctrl_vlan(struct mlx5_vdpa_dev *mvdev, u8 cmd)

Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -0
+
        switch (cmd) {
        case VIRTIO_NET_CTRL_VLAN_ADD:
                read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->riov, &vlan,

sizeof(vlan));

Quoted 3 lines

--
2.38.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

author
#14 lore raw

RE: [PATCH 5/7] vdpa/mlx5: Add RX counters to debugfs

In reply to Jason Wang
Quoted 44 lines

From: Jason Wang <[email protected]>
Sent: Monday, 14 November 2022 9:27
To: Eli Cohen <[email protected]>
Cc: [email protected]; [email protected]; [email protected] foundation.org; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 5/7] vdpa/mlx5: Add RX counters to debugfs

Quoted 6 lines · Eli Cohen

For each interface, either VLAN tagged or untagged, add two hardware
counters: one for unicast and another for multicast. The counters count RX packets and bytes and can be read through debugfs:

$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-

0/rx/untagged/mcast/packets

Quoted 1 line
$ cat /sys/kernel/debug/mlx5/mlx5_core.sf.1/vdpa-

0/rx/untagged/ucast/bytes

Quoted 13 lines

This feature is controlled via the config option MLX5_VDPA_STEERING_DEBUG. It is off by default as it may have some impact on performance.

---
 drivers/vdpa/Kconfig              |  12 +++
 drivers/vdpa/mlx5/net/debug.c     |  86 ++++++++++++++++++++++
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 118 +++++++++++++++++++++++-------
 drivers/vdpa/mlx5/net/mlx5_vnet.h |  30 ++++++++
 4 files changed, 218 insertions(+), 28 deletions(-)

[...]

Quoted 3 lines
+       vid = key2vid(node->macvlan);
        spec->match_criteria_enable = MLX5_MATCH_OUTER_HEADERS;
        headers_c = MLX5_ADDR_OF(fte_match_param, spec->match_criteria,

outer_headers);

Quoted 1 line
        headers_v = MLX5_ADDR_OF(fte_match_param, spec->match_value,

outer_headers);

Review static int mlx5_vdpa_add_mac_vlan_rules(struct

Quoted 1 line
(quoted diff) +0 -0
@@ -1430,48 +1475,62 @@ static int mlx5_vdpa_add_mac_vlan_rules(struct

mlx5_vdpa_net *ndev, u8 *mac,

Review static int mlx5_vdpa_add_mac_vlan_rules(struct · line 1475

Quoted 1 line
(quoted diff) +0 -0
        dmac_v = MLX5_ADDR_OF(fte_match_param, headers_v,

outer_headers.dmac_47_16);

Quoted 8 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_add_mac_vlan_rules(struct mlx5_vdpa_net *ndev, u8 *mac,

Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
        eth_broadcast_addr(dmac_c);
        ether_addr_copy(dmac_v, mac);
-       if (ndev->mvdev.actual_features & VIRTIO_NET_F_CTRL_VLAN) {
+       if (ndev->mvdev.actual_features &

BIT_ULL(VIRTIO_NET_F_CTRL_VLAN)) {

This seems like a fix for patch 1? If yes, let's just squash this.

Sure, thanks.

Quoted 2 lines

Thanks

author
#17 lore raw

RE: [PATCH 6/7] vdpa/mlx5: Avoid using reslock in event_handler

In reply to Jason Wang
Quoted 27 lines

From: Jason Wang <[email protected]>
Sent: Monday, 14 November 2022 9:53
To: Eli Cohen <[email protected]>
Cc: [email protected]; [email protected]; [email protected] foundation.org; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 6/7] vdpa/mlx5: Avoid using reslock in event_handler

Quoted 6 lines · Eli Cohen

event_handler runs under atomic context and may not acquire reslock. We can still guarantee that the handler won't be called after suspend by clearing nb_registered, unregistering the handler and flushing the workqueue.

Review

Quoted 6 lines
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
(quoted diff) +0 -0

b/drivers/vdpa/mlx5/net/mlx5_vnet.c

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_suspend(struct vdpa_device

Quoted 4 lines

index 6e6490c85be2..bebfba530247 100644

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -2872,8 +2872,8 @@ static int mlx5_vdpa_suspend(struct vdpa_device

*vdev)

Quoted 8 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_suspend(struct vdpa_device *vdev) · line 2876

Quoted 6 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
        int i;
 
        down_write(&ndev->reslock);
-       mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);
        ndev->nb_registered = false;
+       mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);

I wonder why this can help anything.

I think you were concerned that async events will come when the device was suspended. Since we can't take reslock, I think this guarantees that we won't get any events after suspension.

Quoted 3 lines

And if it does, we have simliar
logic in mlx5_vdpa_dev_del() do we need to fix that as well?

We have the same construct there only that I set nb_registered = false after unregistering the notifier. So I probably need to move it before mlx5_notifier_unregister().

Quoted 43 lines

Thanks

drivers/vdpa/mlx5/net/mlx5_vnet.c static void update_carrier(struct work_struct

Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
        flush_workqueue(ndev->mvdev.wq);
        for (i = 0; i < ndev->cur_num_vqs; i++) {
                mvq = &ndev->vqs[i];
@@ -3051,7 +3051,7 @@ static void update_carrier(struct work_struct

*work)

drivers/vdpa/mlx5/net/mlx5_vnet.c static void update_carrier(struct work_struct · line 3052

Quoted 2 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
        else
                ndev->config.status &= cpu_to_mlx5vdpa16(mvdev,

~VIRTIO_NET_S_LINK_UP);

drivers/vdpa/mlx5/net/mlx5_vnet.c static int event_handler(struct notifier_block

Quoted 7 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
-       if (ndev->config_cb.callback)
+       if (ndev->nb_registered && ndev->config_cb.callback)
                ndev->config_cb.callback(ndev->config_cb.private);
 
        kfree(wqent);
@@ -3068,21 +3068,13 @@ static int event_handler(struct notifier_block

*nb, unsigned long event, void *p

Quoted 25 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -10
                switch (eqe->sub_type) {
                case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
                case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
-                       down_read(&ndev->reslock);
-                       if (!ndev->nb_registered) {
-                               up_read(&ndev->reslock);
-                               return NOTIFY_DONE;
-                       }
                        wqent = kzalloc(sizeof(*wqent), GFP_ATOMIC);
-                       if (!wqent) {
-                               up_read(&ndev->reslock);
+                       if (!wqent)
                                return NOTIFY_DONE;
-                       }
 
                        wqent->mvdev = &ndev->mvdev;
                        INIT_WORK(&wqent->work, update_carrier);
                        queue_work(ndev->mvdev.wq, &wqent->work);
-                       up_read(&ndev->reslock);
                        ret = NOTIFY_OK;
                        break;
                default:
--

2.38.1

author
#5 lore raw

RE: [PATCH 1/7] vdpa/mlx5: Fix rule forwarding VLAN to TIR

In reply to Michael S. Tsirkin
Quoted 78 lines

-----Original Message-----
From: Michael S. Tsirkin <[email protected]>
Sent: Monday, 14 November 2022 10:07
To: Eli Cohen <[email protected]>
Cc: Jason Wang <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/7] vdpa/mlx5: Fix rule forwarding VLAN to TIR

Quoted 4 lines · Eli Cohen
Quoted 4 lines

From: Jason Wang <[email protected]>
Sent: Monday, 14 November 2022 6:39
To: Eli Cohen <[email protected]>
Cc: [email protected]; [email protected];

[email protected]

Quoted 24 lines
Quoted 24 lines

foundation.org; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 1/7] vdpa/mlx5: Fix rule forwarding VLAN to TIR

Quoted 19 lines · Eli Cohen

Set the VLAN id to the header values field instead of overwriting the headers criteria field.

Before this fix, VLAN filtering would not really work and tagged packets would be forwarded unfiltered to the TIR.

In addition modify the logic so that VLAN filtering is enforced only when VIRTIO_NET_F_CTRL_VLAN is negotiated. When not negotiated, all incoming traffic is accepted as long as it is targeting the net device's MAC address.

Fixes baf2ad3f6a98 ("vdpa/mlx5: Add RX MAC VLAN filter support")
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
Quoted 6 lines
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/vdpa/mlx5/net/mlx5_vnet.c

drivers/vdpa/mlx5/net/mlx5_vnet.c static int

Quoted 4 lines

index 90913365def4..ea95081eca0c 100644

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -1468,11 +1468,13 @@ static int

mlx5_vdpa_add_mac_vlan_rules(struct

Quoted 9 lines
Quoted 9 lines

mlx5_vdpa_net *ndev, u8 *mac,

drivers/vdpa/mlx5/net/mlx5_vnet.c static int · line 1468

Quoted 1 line
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
        dmac_v = MLX5_ADDR_OF(fte_match_param, headers_v,

outer_headers.dmac_47_16);

Quoted 6 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +3 -1
        eth_broadcast_addr(dmac_c);
        ether_addr_copy(dmac_v, mac);
-       MLX5_SET(fte_match_set_lyr_2_4, headers_c, cvlan_tag, 1);
+       if (ndev->mvdev.actual_features & VIRTIO_NET_F_CTRL_VLAN) {
+               MLX5_SET(fte_match_set_lyr_2_4, headers_c, cvlan_tag, 1);
+               MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c,

first_vid);

Quoted 4 lines
Quoted 4 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_add_mac_vlan_rules(struct mlx5_vdpa_net *ndev, u8 *mac,

Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
+       }
        if (tagged) {
                MLX5_SET(fte_match_set_lyr_2_4, headers_v, cvlan_tag, 1);
-               MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, headers_c,

first_vid);

Quoted 6 lines
Quoted 6 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static virtio_net_ctrl_ack

Quoted 6 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
-               MLX5_SET(fte_match_set_lyr_2_4, headers_c, first_vid, vid);
+               MLX5_SET(fte_match_set_lyr_2_4, headers_v, first_vid, vid);
        }
        flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST;
        dest.type = MLX5_FLOW_DESTINATION_TYPE_TIR;
@@ -1821,6 +1823,9 @@ static virtio_net_ctrl_ack

handle_ctrl_vlan(struct

Quoted 8 lines
Quoted 8 lines

mlx5_vdpa_dev *mvdev, u8 cmd)

drivers/vdpa/mlx5/net/mlx5_vnet.c static virtio_net_ctrl_ack handle_ctrl_vlan(struct mlx5_vdpa_dev *mvdev, u8 cmd)

Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -0
        size_t read;
        u16 id;
 
+       if (!(ndev->mvdev.actual_features &

BIT_ULL(VIRTIO_NET_F_CTRL_VLAN)))

Quoted 1 line
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -0
+               return status;
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

Nit: this seems unrelated to the patch.

Will put in another patch

OK since you are doing a new version, please split fixes and features in two patchsets. Thanks!

Sure

Quoted 14 lines
Quoted 14 lines
Quoted 13 lines

Other than this.

drivers/vdpa/mlx5/net/mlx5_vnet.c static virtio_net_ctrl_ack handle_ctrl_vlan(struct mlx5_vdpa_dev *mvdev, u8 cmd)

Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -0
+
        switch (cmd) {
        case VIRTIO_NET_CTRL_VLAN_ADD:
                read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->riov, &vlan,

sizeof(vlan));

Quoted 3 lines

--
2.38.1

#18 lore raw

Re: [PATCH 6/7] vdpa/mlx5: Avoid using reslock in event_handler

In reply to Eli Cohen
Quoted 30 lines · Eli Cohen
Quoted 30 lines

From: Jason Wang <[email protected]>
Sent: Monday, 14 November 2022 9:53
To: Eli Cohen <[email protected]>
Cc: [email protected]; [email protected]; [email protected] foundation.org; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 6/7] vdpa/mlx5: Avoid using reslock in event_handler

Quoted 6 lines · Eli Cohen

event_handler runs under atomic context and may not acquire reslock. We can still guarantee that the handler won't be called after suspend by clearing nb_registered, unregistering the handler and flushing the workqueue.

Review

Quoted 6 lines
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
(quoted diff) +0 -0

b/drivers/vdpa/mlx5/net/mlx5_vnet.c

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_suspend(struct vdpa_device

Quoted 4 lines

index 6e6490c85be2..bebfba530247 100644

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -2872,8 +2872,8 @@ static int mlx5_vdpa_suspend(struct vdpa_device

*vdev)

Quoted 2 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
        int i;
 
Quoted 8 lines
Quoted 6 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_suspend(struct vdpa_device *vdev) · line 2876

Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
        down_write(&ndev->reslock);
-       mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);
        ndev->nb_registered = false;
+       mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);

I wonder why this can help anything.

I think you were concerned that async events will come when the device was suspended. Since we can't take reslock, I think this guarantees that we won't get any events after suspension.

Ok, I see.

Quoted 4 lines
Quoted 3 lines

And if it does, we have simliar
logic in mlx5_vdpa_dev_del() do we need to fix that as well?

We have the same construct there only that I set nb_registered = false after unregistering the notifier. So I probably need to move it before mlx5_notifier_unregister().

Right.

Thanks

Quoted 34 lines
Quoted 34 lines

Thanks

drivers/vdpa/mlx5/net/mlx5_vnet.c static void update_carrier(struct work_struct

Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
        flush_workqueue(ndev->mvdev.wq);
        for (i = 0; i < ndev->cur_num_vqs; i++) {
                mvq = &ndev->vqs[i];
@@ -3051,7 +3051,7 @@ static void update_carrier(struct work_struct

*work)

drivers/vdpa/mlx5/net/mlx5_vnet.c static void update_carrier(struct work_struct · line 3052

Quoted 2 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
        else
                ndev->config.status &= cpu_to_mlx5vdpa16(mvdev,

~VIRTIO_NET_S_LINK_UP);

drivers/vdpa/mlx5/net/mlx5_vnet.c static int event_handler(struct notifier_block

Quoted 7 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
-       if (ndev->config_cb.callback)
+       if (ndev->nb_registered && ndev->config_cb.callback)
                ndev->config_cb.callback(ndev->config_cb.private);
 
        kfree(wqent);
@@ -3068,21 +3068,13 @@ static int event_handler(struct notifier_block

*nb, unsigned long event, void *p

Quoted 15 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -8
                switch (eqe->sub_type) {
                case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
                case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
-                       down_read(&ndev->reslock);
-                       if (!ndev->nb_registered) {
-                               up_read(&ndev->reslock);
-                               return NOTIFY_DONE;
-                       }
                        wqent = kzalloc(sizeof(*wqent), GFP_ATOMIC);
-                       if (!wqent) {
-                               up_read(&ndev->reslock);
+                       if (!wqent)
                                return NOTIFY_DONE;
-                       }
 
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -2
                        wqent->mvdev = &ndev->mvdev;
                        INIT_WORK(&wqent->work, update_carrier);
                        queue_work(ndev->mvdev.wq, &wqent->work);
-                       up_read(&ndev->reslock);
                        ret = NOTIFY_OK;
                        break;
                default:
--

2.38.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Acked-by
#19 lore raw

Re: [PATCH 6/7] vdpa/mlx5: Avoid using reslock in event_handler

Quoted 43 lines · Jason Wang
Quoted 30 lines · Eli Cohen
Quoted 30 lines

From: Jason Wang <[email protected]>
Sent: Monday, 14 November 2022 9:53
To: Eli Cohen <[email protected]>
Cc: [email protected]; [email protected]; [email protected] foundation.org; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH 6/7] vdpa/mlx5: Avoid using reslock in event_handler

Quoted 6 lines · Eli Cohen

event_handler runs under atomic context and may not acquire reslock. We can still guarantee that the handler won't be called after suspend by clearing nb_registered, unregistering the handler and flushing the workqueue.

Review

Quoted 6 lines
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 14 +++-----------
 1 file changed, 3 insertions(+), 11 deletions(-)
(quoted diff) +0 -0

b/drivers/vdpa/mlx5/net/mlx5_vnet.c

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_suspend(struct vdpa_device

Quoted 4 lines

index 6e6490c85be2..bebfba530247 100644

drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
@@ -2872,8 +2872,8 @@ static int mlx5_vdpa_suspend(struct vdpa_device

*vdev)

Quoted 2 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
        int i;
 
Quoted 8 lines
Quoted 6 lines

drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_suspend(struct vdpa_device *vdev) · line 2876

Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
        down_write(&ndev->reslock);
-       mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);
        ndev->nb_registered = false;
+       mlx5_notifier_unregister(mvdev->mdev, &ndev->nb);

I wonder why this can help anything.

I think you were concerned that async events will come when the device was suspended. Since we can't take reslock, I think this guarantees that we won't get any events after suspension.

Ok, I see.

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines

And if it does, we have simliar
logic in mlx5_vdpa_dev_del() do we need to fix that as well?

We have the same construct there only that I set nb_registered = false after unregistering the notifier. So I probably need to move it before mlx5_notifier_unregister().

Right.

Thanks

So I'm fine with this patch.

Thanks

Quoted 35 lines
Quoted 35 lines
Quoted 35 lines

Thanks

drivers/vdpa/mlx5/net/mlx5_vnet.c static void update_carrier(struct work_struct

Quoted 4 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
        flush_workqueue(ndev->mvdev.wq);
        for (i = 0; i < ndev->cur_num_vqs; i++) {
                mvq = &ndev->vqs[i];
@@ -3051,7 +3051,7 @@ static void update_carrier(struct work_struct

*work)

drivers/vdpa/mlx5/net/mlx5_vnet.c static void update_carrier(struct work_struct · line 3052

Quoted 2 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -0
        else
                ndev->config.status &= cpu_to_mlx5vdpa16(mvdev,

~VIRTIO_NET_S_LINK_UP);

drivers/vdpa/mlx5/net/mlx5_vnet.c static int event_handler(struct notifier_block

Quoted 7 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -1
-       if (ndev->config_cb.callback)
+       if (ndev->nb_registered && ndev->config_cb.callback)
                ndev->config_cb.callback(ndev->config_cb.private);
 
        kfree(wqent);
@@ -3068,21 +3068,13 @@ static int event_handler(struct notifier_block

*nb, unsigned long event, void *p

Quoted 15 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1 -8
                switch (eqe->sub_type) {
                case MLX5_PORT_CHANGE_SUBTYPE_DOWN:
                case MLX5_PORT_CHANGE_SUBTYPE_ACTIVE:
-                       down_read(&ndev->reslock);
-                       if (!ndev->nb_registered) {
-                               up_read(&ndev->reslock);
-                               return NOTIFY_DONE;
-                       }
                        wqent = kzalloc(sizeof(*wqent), GFP_ATOMIC);
-                       if (!wqent) {
-                               up_read(&ndev->reslock);
+                       if (!wqent)
                                return NOTIFY_DONE;
-                       }
 
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -2
                        wqent->mvdev = &ndev->mvdev;
                        INIT_WORK(&wqent->work, update_carrier);
                        queue_work(ndev->mvdev.wq, &wqent->work);
-                       up_read(&ndev->reslock);
                        ret = NOTIFY_OK;
                        break;
                default:
--

2.38.1

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization