Skip to contentSkip to conversation

interrupts: fix number of bytes read for vdev

PATCH In review [email protected] 2 participants 6 messages Oct 7, 2024 – Oct 9, 2024 Network drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 interrupts: fix number of bytes read for vdev

From: Satha Rao <[email protected]>

Correct the number of bytes to read during vdev interrupt processing. The driver sets this value, and the rxtx interrupt handling already performs this correctly.

Fixes 99998feec90 ("eal/linux: add interrupt type for vdev")
---
 lib/eal/linux/eal_interrupts.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/eal/linux/eal_interrupts.c +4 -0
index 6436f796eb..80eef7ec4b 100644
@@ -949,6 +949,10 @@ eal_intr_process_interrupts(struct epoll_event *events, int nfds)
 			break;
 #endif
 		case RTE_INTR_HANDLE_VDEV:
+			/* For vdev, number of bytes to read is set by driver */
+			bytes_read = rte_intr_efd_counter_size_get(src->intr_handle);
+			call = true;
+			break;
 		case RTE_INTR_HANDLE_EXT:
 			bytes_read = 0;
 			call = true;
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/5 net/virtio-user: get link duplex and speed

From: Satha Rao <[email protected]>

This patch extends the virtio_user_read_dev_config API to retrieve link speed and duplex settings if the device features support VIRTIO_NET_F_SPEED_DUPLEX.

---
 .../net/virtio/virtio_user/virtio_user_dev.c  | 22 ++++++++++++++++++-
 .../net/virtio/virtio_user/virtio_user_dev.h  |  2 ++
 drivers/net/virtio/virtio_user_ethdev.c       |  6 +++++
 3 files changed, 29 insertions(+), 1 deletion(-)
drivers/net/virtio/virtio_user/virtio_user_dev.c +21 -1
index 2997d2bd26..91ad1312f7 100644
@@ -468,6 +468,25 @@ virtio_user_dev_init_mac(struct virtio_user_dev *dev, const char *mac)
 	PMD_DRV_LOG(INFO, "(%s) MAC %s specified", dev->path, buf);
 }
 
+int
+virtio_user_dev_get_speed_duplex_config(struct virtio_user_dev *dev, void *dst, size_t offset,
+					int length)
+{
+	int ret = 0;
+
+	if (!(dev->device_features & (1ULL << VIRTIO_NET_F_SPEED_DUPLEX)))
+		return -ENOTSUP;
+
+	if (!dev->ops->get_config)
+		return -ENOTSUP;
+
+	ret = dev->ops->get_config(dev, dst, offset, length);
+	if (ret)
+		PMD_DRV_LOG(ERR, "(%s) Failed to get speed/duplex config in device", dev->path);
+
+	return ret;
+}
+
 static int
 virtio_user_dev_init_notify(struct virtio_user_dev *dev)
 {
@@ -726,7 +745,8 @@ virtio_user_free_vrings(struct virtio_user_dev *dev)
 	 1ULL << VIRTIO_F_RING_PACKED		|	\
 	 1ULL << VIRTIO_F_NOTIFICATION_DATA	|	\
 	 1ULL << VIRTIO_F_ORDER_PLATFORM        |       \
-	 1ULL << VIRTIO_NET_F_RSS)
+	 1ULL << VIRTIO_NET_F_RSS               |       \
+	 1ULL << VIRTIO_NET_F_SPEED_DUPLEX)
 
 int
 virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues,
drivers/net/virtio/virtio_user/virtio_user_dev.h +2 -0
index 66400b3b62..57d75d1c53 100644
@@ -87,6 +87,8 @@ int virtio_user_dev_set_mac(struct virtio_user_dev *dev);
 int virtio_user_dev_get_mac(struct virtio_user_dev *dev);
 int virtio_user_dev_get_rss_config(struct virtio_user_dev *dev, void *dst, size_t offset,
 				   int length);
+int virtio_user_dev_get_speed_duplex_config(struct virtio_user_dev *dev, void *dst,
+					    size_t offset, int length);
 void virtio_user_dev_delayed_disconnect_handler(void *param);
 int virtio_user_dev_server_reconnect(struct virtio_user_dev *dev);
 extern const char * const virtio_user_backend_strings[];
drivers/net/virtio/virtio_user_ethdev.c +6 -0
index bf29f0dacd..d431b4521b 100644
@@ -55,6 +55,12 @@ virtio_user_read_dev_config(struct virtio_hw *hw, size_t offset,
 
 	if (offset >= offsetof(struct virtio_net_config, rss_max_key_size))
 		virtio_user_dev_get_rss_config(dev, dst, offset, length);
+
+	if (offset == offsetof(struct virtio_net_config, speed))
+		virtio_user_dev_get_speed_duplex_config(dev, dst, offset, length);
+
+	if (offset == offsetof(struct virtio_net_config, duplex))
+		virtio_user_dev_get_speed_duplex_config(dev, dst, offset, length);
 }
 
 static void
Signature · 1 line
2.25.1
#2 lore raw

PATCH 3/5 net/virtio: add set config callback

In reply to [email protected]

From: Satha Rao <[email protected]>

This patch enables the set config callback handler.

---
 drivers/net/virtio/virtio_user/vhost.h      |  1 +
 drivers/net/virtio/virtio_user/vhost_vdpa.c | 10 ++++++++++
 2 files changed, 11 insertions(+)
drivers/net/virtio/virtio_user/vhost.h +1 -0
index eee3a4bc47..45ae56e3b5 100644
@@ -92,6 +92,7 @@ struct virtio_user_backend_ops {
 	int (*get_intr_fd)(struct virtio_user_dev *dev);
 	int (*map_notification_area)(struct virtio_user_dev *dev);
 	int (*unmap_notification_area)(struct virtio_user_dev *dev);
+	int (*set_config_call)(struct virtio_user_dev *dev, int fd);
 };
 
 extern struct virtio_user_backend_ops virtio_ops_user;
drivers/net/virtio/virtio_user/vhost_vdpa.c +10 -0
index bc3e2a9af5..5c610664b6 100644
@@ -48,6 +48,7 @@ struct vhost_vdpa_data {
 #define VHOST_VDPA_SET_VRING_ENABLE _IOW(VHOST_VIRTIO, 0x75, struct vhost_vring_state)
 #define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64)
 #define VHOST_GET_BACKEND_FEATURES _IOR(VHOST_VIRTIO, 0x26, __u64)
+#define VHOST_SET_CONFIG_CALL      _IOW(VHOST_VIRTIO, 0x77, int)
 
 /* no alignment requirement */
 struct vhost_iotlb_msg {
@@ -509,6 +510,14 @@ vhost_vdpa_set_config(struct virtio_user_dev *dev, const uint8_t *data, uint32_t
 	return ret;
 }
 
+static int
+vhost_vdpa_set_config_call(struct virtio_user_dev *dev, int fd)
+{
+	struct vhost_vdpa_data *data = dev->backend_data;
+
+	return vhost_vdpa_ioctl(data->vhostfd, VHOST_SET_CONFIG_CALL, &fd);
+}
+
 /**
  * Set up environment to talk with a vhost vdpa backend.
  *
@@ -706,6 +715,7 @@ struct virtio_user_backend_ops virtio_ops_vdpa = {
 	.set_status = vhost_vdpa_set_status,
 	.get_config = vhost_vdpa_get_config,
 	.set_config = vhost_vdpa_set_config,
+	.set_config_call = vhost_vdpa_set_config_call,
 	.cvq_enable = vhost_vdpa_cvq_enable,
 	.enable_qp = vhost_vdpa_enable_queue_pair,
 	.dma_map = vhost_vdpa_dma_map_batch,
Signature · 1 line
2.25.1
#3 lore raw

PATCH 4/5 net/virtio: implement update link state API

In reply to [email protected]

From: Satha Rao <[email protected]>

This patch introduces the vhost_vdpa_update_link_state API to manage the link state updates.

---
 drivers/net/virtio/virtio_user/vhost_vdpa.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/virtio/virtio_user/vhost_vdpa.c +10 -2
index 5c610664b6..e8aea54000 100644
@@ -619,9 +619,17 @@ vhost_vdpa_get_backend_features(uint64_t *features)
 }
 
 static int
-vhost_vdpa_update_link_state(struct virtio_user_dev *dev __rte_unused)
+vhost_vdpa_update_link_state(struct virtio_user_dev *dev)
 {
-	/* Nothing to update (for now?) */
+	uint16_t status;
+	int rc, offset;
+
+	offset = offsetof(struct virtio_net_config, status);
+	rc = vhost_vdpa_get_config(dev, (uint8_t *)&status, offset, sizeof(status));
+	if (rc)
+		return rc;
+	dev->net_status = status & VIRTIO_NET_S_LINK_UP;
+
 	return 0;
 }
 
Signature · 1 line
2.25.1
#4 lore raw

PATCH 5/5 net/virtio-user: support vDPA configuration callback

In reply to [email protected]

From: Satha Rao <[email protected]>

Extended the vhost_vdpa_get_intr_fd API to create an event and register for configuration callbacks with the vDPA backend. This enhancement allows the virtio-user driver to handle configuration changes more effectively.

---
 drivers/net/virtio/virtio_user/vhost_vdpa.c   | 18 ++++++++++--
 .../net/virtio/virtio_user/virtio_user_dev.c  | 29 +++++++++++++++++++
 .../net/virtio/virtio_user/virtio_user_dev.h  |  2 ++
 3 files changed, 46 insertions(+), 3 deletions(-)
drivers/net/virtio/virtio_user/vhost_vdpa.c +15 -3
index e8aea54000..c9eaffce16 100644
@@ -9,6 +9,7 @@
 #include <fcntl.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <sys/eventfd.h>
 
 #include <rte_memory.h>
 
@@ -634,10 +635,21 @@ vhost_vdpa_update_link_state(struct virtio_user_dev *dev)
 }
 
 static int
-vhost_vdpa_get_intr_fd(struct virtio_user_dev *dev __rte_unused)
+vhost_vdpa_get_intr_fd(struct virtio_user_dev *dev)
 {
-	/* No link state interrupt with Vhost-vDPA */
-	return -1;
+	int fd;
+
+	if (dev->cfg_epfd)
+		return dev->cfg_epfd;
+
+	fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
+	if (fd < 0) {
+		PMD_DRV_LOG(ERR, "failed to create fd error, %s", strerror(errno));
+		fd = -1;
+	}
+	dev->cfg_epfd = fd;
+
+	return fd;
 }
 
 static int
drivers/net/virtio/virtio_user/virtio_user_dev.c +29 -0
index 91ad1312f7..ea00eb50f5 100644
@@ -487,6 +487,21 @@ virtio_user_dev_get_speed_duplex_config(struct virtio_user_dev *dev, void *dst,
 	return ret;
 }
 
+int
+virtio_user_dev_set_config_call(struct virtio_user_dev *dev, int fd)
+{
+	int ret = 0;
+
+	if (!dev->ops->set_config_call)
+		return -ENOTSUP;
+
+	ret = dev->ops->set_config_call(dev, fd);
+	if (ret)
+		PMD_DRV_LOG(ERR, "(%s) Failed to set config call in device", dev->path);
+
+	return ret;
+}
+
 static int
 virtio_user_dev_init_notify(struct virtio_user_dev *dev)
 {
@@ -769,6 +784,7 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues,
 	dev->unsupported_features = 0;
 	dev->backend_type = backend_type;
 	dev->ifname = *ifname;
+	dev->cfg_epfd = 0;
 
 	if (virtio_user_dev_setup(dev) < 0) {
 		PMD_INIT_LOG(ERR, "(%s) backend set up fails", dev->path);
@@ -863,6 +879,15 @@ virtio_user_dev_init(struct virtio_user_dev *dev, char *path, uint16_t queues,
 		}
 	}
 
+	/* vhost vdpa register valid fd to handle config callback */
+	if (dev->cfg_epfd) {
+		struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->hw.port_id];
+
+		if (rte_intr_efd_counter_size_set(eth_dev->intr_handle, 8))
+			return -rte_errno;
+		virtio_user_dev_set_config_call(dev, dev->cfg_epfd);
+	}
+
 	*ifname = NULL;
 	return 0;
 
@@ -892,6 +917,10 @@ virtio_user_dev_uninit(struct virtio_user_dev *dev)
 
 	virtio_user_free_vrings(dev);
 
+	if (dev->cfg_epfd) {
+		close(dev->cfg_epfd);
+		dev->cfg_epfd = 0;
+	}
 	free(dev->ifname);
 
 	if (dev->is_server)
drivers/net/virtio/virtio_user/virtio_user_dev.h +2 -0
index 57d75d1c53..1ad93521e3 100644
@@ -31,6 +31,7 @@ struct virtio_user_dev {
 
 	int		*callfds;
 	int		*kickfds;
+	int		cfg_epfd; /* config callback interrupt */
 	int		mac_specified;
 	uint16_t	max_queue_pairs;
 	uint16_t	queue_pairs;
@@ -89,6 +90,7 @@ int virtio_user_dev_get_rss_config(struct virtio_user_dev *dev, void *dst, size_
 				   int length);
 int virtio_user_dev_get_speed_duplex_config(struct virtio_user_dev *dev, void *dst,
 					    size_t offset, int length);
+int virtio_user_dev_set_config_call(struct virtio_user_dev *dev, int fd);
 void virtio_user_dev_delayed_disconnect_handler(void *param);
 int virtio_user_dev_server_reconnect(struct virtio_user_dev *dev);
 extern const char * const virtio_user_backend_strings[];
Signature · 1 line
2.25.1
#5 lore raw
In reply to [email protected]
Quoted 10 lines · On Mon, 7 Oct 2024 20:33:59 +0530 <[email protected]> wrote:

From: Satha Rao <[email protected]>

Correct the number of bytes to read during vdev interrupt processing. The driver sets this value, and the rxtx interrupt handling already performs this correctly.

Fixes 99998feec90 ("eal/linux: add interrupt type for vdev")

Not sure how this works.
The code in eal_handle_interrupts sits on a epoll_wait() waiting for next interrupt.

eal_inter_process_interrupts() is called.
The switch you modified decides what needs to be read to clear the interrupt. If you change RTE_INTR_HANDLE_VDEV to read bytes from the eventfd by setting bytes_read then the code in this function will read the counter value from the event fd immediately.

Then when eal_intr_proc_rxtx_intr() is called it will decide to read again. And since the event is cleared, this read will get EWOULDBLOCK.

What exactly is the issue? How to reproduce it?

Also setting call = true in the switch is wrong.
The code later in eal_intr_process_interrupts that handles bytes_read > 0 already sets call = true if interrupt was cleared from eventfd.