Skip to contentSkip to conversation

Properly initialize speed/duplex and remove vDPA config updates

PATCH In review Carlos Bilbao 5 participants 13 messages Sep 4, 2024 – Nov 8, 2024

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v3 cover Properly initialize speed/duplex and remove vDPA config updates

From: Carlos Bilbao <[email protected]>

Initialize speed and duplex for virtio_net_config to UNKNOWN (mlx5_vdpa vDPA devices currently do not support VIRTIO_NET_F_SPEED_DUPLEX). Remove ioctl VHOST_VDPA_SET_CONFIG and its related logic as it is not supported;
see: https://docs.oasis-open.org/virtio/virtio/v1.3/virtio-v1.3.html

Carlos:
vdpa/mlx5: Set speed and duplex of vDPA devices to UNKNOWN
vdpa: Remove ioctl VHOST_VDPA_SET_CONFIG per spec compliance

---

Changes since v1:

- Fix prefix of the first commit and add Reviewed-By tag.
- Redo second commit completely: instead of attempting to add support to set configuration fields, remove ioctl and support entirely from vDPA implementations -- because it's not allowed by spec.

Changes since v2:

- Fix first commit by changing 4 spaces for a tab.
- In second commit, ENI is legacy and should keep set_config(). Change it to set_config_legacy() to avoid future confusion and erroneous implementations.

---
 drivers/vdpa/alibaba/eni_vdpa.c    |  2 +-
 drivers/vdpa/ifcvf/ifcvf_main.c    | 10 ----------
 drivers/vdpa/mlx5/net/mlx5_vnet.c  | 19 ++++++++++++-------
 drivers/vdpa/pds/vdpa_dev.c        | 16 ----------------
 drivers/vdpa/solidrun/snet_main.c  | 18 ------------------
 drivers/vdpa/vdpa.c                | 16 ----------------
 drivers/vdpa/vdpa_sim/vdpa_sim.c   | 16 ----------------
 drivers/vdpa/vdpa_sim/vdpa_sim.h   |  1 -
 drivers/vdpa/vdpa_user/vduse_dev.c |  7 -------
 drivers/vdpa/virtio_pci/vp_vdpa.c  | 14 --------------
 drivers/vhost/vdpa.c               | 26 --------------------------
 drivers/virtio/virtio_vdpa.c       |  9 ---------
 include/linux/vdpa.h               |  7 ++++---
 include/uapi/linux/vhost.h         |  8 ++++----
 14 files changed, 21 insertions(+), 148 deletions(-)
#1 lore raw

PATCH v3 1/2 vdpa/mlx5: Set speed and duplex of vDPA devices to UNKNOWN

From: Carlos Bilbao <[email protected]>

Initialize the speed and duplex fields in virtio_net_config to UNKNOWN. This is needed because mlx5_vdpa vDPA devices currently do not support the VIRTIO_NET_F_SPEED_DUPLEX feature which reports speed and duplex. Add needed helper cpu_to_mlx5vdpa32() to convert endianness of speed.

---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/vdpa/mlx5/net/mlx5_vnet.c +12 -0
index b56aae3f7be3..41ca268d43ff 100644
@@ -173,6 +173,11 @@ static __virtio16 cpu_to_mlx5vdpa16(struct mlx5_vdpa_dev *mvdev, u16 val)
 	return __cpu_to_virtio16(mlx5_vdpa_is_little_endian(mvdev), val);
 }
 
+static __virtio32 cpu_to_mlx5vdpa32(struct mlx5_vdpa_dev *mvdev, u32 val)
+{
+	return __cpu_to_virtio32(mlx5_vdpa_is_little_endian(mvdev), val);
+}
+
 static u16 ctrl_vq_idx(struct mlx5_vdpa_dev *mvdev)
 {
 	if (!(mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_MQ)))
@@ -3433,6 +3438,13 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
 	init_rwsem(&ndev->reslock);
 	config = &ndev->config;
 
+	/*
+	 * mlx5_vdpa vDPA devices currently don't support reporting or
+	 * setting the speed or duplex.
+	 */
+	config->speed  = cpu_to_mlx5vdpa32(mvdev, SPEED_UNKNOWN);
+	config->duplex = DUPLEX_UNKNOWN;
+
 	if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)) {
 		err = config_func_mtu(mdev, add_config->net.mtu);
 		if (err)
Signature · 1 line
2.34.1
Acked-by on v3 1/2
#2 lore raw

Re: [PATCH v3 1/2] vdpa/mlx5: Set speed and duplex of vDPA devices to UNKNOWN

Quoted 10 lines · Carlos Bilbao

From: Carlos Bilbao <[email protected]>

Initialize the speed and duplex fields in virtio_net_config to UNKNOWN. This is needed because mlx5_vdpa vDPA devices currently do not support the VIRTIO_NET_F_SPEED_DUPLEX feature which reports speed and duplex. Add needed helper cpu_to_mlx5vdpa32() to convert endianness of speed.

Thanks

Quoted 37 lines
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/vdpa/mlx5/net/mlx5_vnet.c +12 -1
index b56aae3f7be3..41ca268d43ff 100644
@@ -173,6 +173,11 @@ static __virtio16 cpu_to_mlx5vdpa16(struct mlx5_vdpa_dev *mvdev, u16 val)
        return __cpu_to_virtio16(mlx5_vdpa_is_little_endian(mvdev), val);
 }
 
+static __virtio32 cpu_to_mlx5vdpa32(struct mlx5_vdpa_dev *mvdev, u32 val)
+{
+       return __cpu_to_virtio32(mlx5_vdpa_is_little_endian(mvdev), val);
+}
+
 static u16 ctrl_vq_idx(struct mlx5_vdpa_dev *mvdev)
 {
        if (!(mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_MQ)))
@@ -3433,6 +3438,13 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
        init_rwsem(&ndev->reslock);
        config = &ndev->config;
 
+       /*
+        * mlx5_vdpa vDPA devices currently don't support reporting or
+        * setting the speed or duplex.
+        */
+       config->speed  = cpu_to_mlx5vdpa32(mvdev, SPEED_UNKNOWN);
+       config->duplex = DUPLEX_UNKNOWN;
+
        if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)) {
                err = config_func_mtu(mdev, add_config->net.mtu);
                if (err)
--

2.34.1

#3 lore raw

Re: [PATCH v3 1/2] vdpa/mlx5: Set speed and duplex of vDPA devices to UNKNOWN

In reply to Carlos Bilbao
Quoted 5 lines · Carlos Bilbao

From: Carlos Bilbao <[email protected]>

Initialize the speed and duplex fields in virtio_net_config to UNKNOWN. This is needed because mlx5_vdpa vDPA devices currently do not support the VIRTIO_NET_F_SPEED_DUPLEX feature which reports speed and duplex.

I see no logic here. Without this feature bit, guests will not read this field, why do we suddenly need to initialize it?

Quoted 41 lines

Add
needed helper cpu_to_mlx5vdpa32() to convert endianness of speed.

---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/vdpa/mlx5/net/mlx5_vnet.c +12 -0
index b56aae3f7be3..41ca268d43ff 100644
@@ -173,6 +173,11 @@ static __virtio16 cpu_to_mlx5vdpa16(struct mlx5_vdpa_dev *mvdev, u16 val)
 	return __cpu_to_virtio16(mlx5_vdpa_is_little_endian(mvdev), val);
 }
 
+static __virtio32 cpu_to_mlx5vdpa32(struct mlx5_vdpa_dev *mvdev, u32 val)
+{
+	return __cpu_to_virtio32(mlx5_vdpa_is_little_endian(mvdev), val);
+}
+
 static u16 ctrl_vq_idx(struct mlx5_vdpa_dev *mvdev)
 {
 	if (!(mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_MQ)))
@@ -3433,6 +3438,13 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
 	init_rwsem(&ndev->reslock);
 	config = &ndev->config;
 
+	/*
+	 * mlx5_vdpa vDPA devices currently don't support reporting or
+	 * setting the speed or duplex.
+	 */
+	config->speed  = cpu_to_mlx5vdpa32(mvdev, SPEED_UNKNOWN);
+	config->duplex = DUPLEX_UNKNOWN;
+
 	if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)) {
 		err = config_func_mtu(mdev, add_config->net.mtu);
 		if (err)
Signature · 1 line
2.34.1
maintainer
#4 lore raw

Re: [PATCH v3 1/2] vdpa/mlx5: Set speed and duplex of vDPA devices to UNKNOWN

Quoted 10 lines · Michael S. Tsirkin
Quoted 5 lines · Carlos Bilbao

From: Carlos Bilbao <[email protected]>

Initialize the speed and duplex fields in virtio_net_config to UNKNOWN. This is needed because mlx5_vdpa vDPA devices currently do not support the VIRTIO_NET_F_SPEED_DUPLEX feature which reports speed and duplex.

I see no logic here. Without this feature bit, guests will not read this field, why do we suddenly need to initialize it?

IIRC, Carlos was reading data via ioctl VHOST_VDPA_GET_CONFIG which calls .get_config() directly, always exposing the speed and duplex config fields [0]. Carlos, was this the case?

[0] https://lore.kernel.org/lkml/[email protected]/T/

Thanks,
Dragos

Quoted 42 lines
Quoted 41 lines

Add
needed helper cpu_to_mlx5vdpa32() to convert endianness of speed.

---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/vdpa/mlx5/net/mlx5_vnet.c +12 -0
index b56aae3f7be3..41ca268d43ff 100644
@@ -173,6 +173,11 @@ static __virtio16 cpu_to_mlx5vdpa16(struct mlx5_vdpa_dev *mvdev, u16 val)
 	return __cpu_to_virtio16(mlx5_vdpa_is_little_endian(mvdev), val);
 }
 
+static __virtio32 cpu_to_mlx5vdpa32(struct mlx5_vdpa_dev *mvdev, u32 val)
+{
+	return __cpu_to_virtio32(mlx5_vdpa_is_little_endian(mvdev), val);
+}
+
 static u16 ctrl_vq_idx(struct mlx5_vdpa_dev *mvdev)
 {
 	if (!(mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_MQ)))
@@ -3433,6 +3438,13 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
 	init_rwsem(&ndev->reslock);
 	config = &ndev->config;
 
+	/*
+	 * mlx5_vdpa vDPA devices currently don't support reporting or
+	 * setting the speed or duplex.
+	 */
+	config->speed  = cpu_to_mlx5vdpa32(mvdev, SPEED_UNKNOWN);
+	config->duplex = DUPLEX_UNKNOWN;
+
 	if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)) {
 		err = config_func_mtu(mdev, add_config->net.mtu);
 		if (err)
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH v3 1/2] vdpa/mlx5: Set speed and duplex of vDPA devices to UNKNOWN

Quoted 13 lines · Dragos Tatulea
Quoted 10 lines · Michael S. Tsirkin
Quoted 5 lines · Carlos Bilbao

From: Carlos Bilbao <[email protected]>

Initialize the speed and duplex fields in virtio_net_config to UNKNOWN. This is needed because mlx5_vdpa vDPA devices currently do not support the VIRTIO_NET_F_SPEED_DUPLEX feature which reports speed and duplex.

I see no logic here. Without this feature bit, guests will not read this field, why do we suddenly need to initialize it?

Quoted 8 lines

IIRC, Carlos was reading data via ioctl VHOST_VDPA_GET_CONFIG which calls .get_config() directly, always exposing the speed and duplex config fields [0]. Carlos, was this the case?

[0] https://lore.kernel.org/lkml/[email protected]/T/

Thanks,
Dragos

Basically, driver should ignore these if feature is not set.

Quoted 42 lines
Quoted 42 lines
Quoted 41 lines

Add
needed helper cpu_to_mlx5vdpa32() to convert endianness of speed.

---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/vdpa/mlx5/net/mlx5_vnet.c +12 -0
index b56aae3f7be3..41ca268d43ff 100644
@@ -173,6 +173,11 @@ static __virtio16 cpu_to_mlx5vdpa16(struct mlx5_vdpa_dev *mvdev, u16 val)
 	return __cpu_to_virtio16(mlx5_vdpa_is_little_endian(mvdev), val);
 }
 
+static __virtio32 cpu_to_mlx5vdpa32(struct mlx5_vdpa_dev *mvdev, u32 val)
+{
+	return __cpu_to_virtio32(mlx5_vdpa_is_little_endian(mvdev), val);
+}
+
 static u16 ctrl_vq_idx(struct mlx5_vdpa_dev *mvdev)
 {
 	if (!(mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_MQ)))
@@ -3433,6 +3438,13 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
 	init_rwsem(&ndev->reslock);
 	config = &ndev->config;
 
+	/*
+	 * mlx5_vdpa vDPA devices currently don't support reporting or
+	 * setting the speed or duplex.
+	 */
+	config->speed  = cpu_to_mlx5vdpa32(mvdev, SPEED_UNKNOWN);
+	config->duplex = DUPLEX_UNKNOWN;
+
 	if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)) {
 		err = config_func_mtu(mdev, add_config->net.mtu);
 		if (err)
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH v3 1/2] vdpa/mlx5: Set speed and duplex of vDPA devices to UNKNOWN

Hello,

Quoted 16 lines · Michael S. Tsirkin
Quoted 15 lines · Dragos Tatulea
Quoted 9 lines · Michael S. Tsirkin
Quoted 5 lines · Carlos Bilbao

From: Carlos Bilbao <[email protected]>

Initialize the speed and duplex fields in virtio_net_config to UNKNOWN. This is needed because mlx5_vdpa vDPA devices currently do not support the VIRTIO_NET_F_SPEED_DUPLEX feature which reports speed and duplex.

I see no logic here. Without this feature bit, guests will not read this field, why do we suddenly need to initialize it?

IIRC, Carlos was reading data via ioctl VHOST_VDPA_GET_CONFIG which calls .get_config() directly, always exposing the speed and duplex config fields [0]. Carlos, was this the case?

Quoted 5 lines
Quoted 4 lines

[0] https://lore.kernel.org/lkml/[email protected]/T/

Thanks,
Dragos

Basically, driver should ignore these if feature is not set.

There _is_ a chance the guest could read this field; As Dragos mentioned, I was using the VHOST_VDPA_GET_CONFIG ioctl from userspace, and the incorrect field initialization led me to believe I was in half-duplex mode -- something people told me they hadn't seen since the 80s. But as Andrew (CCed) mentioned, "If the speed is 0, does duplex even matter?".

I also tried to remove the pointless ioctl call altogether to avoid further confusion [0] but that wasn't viable due to spec compliance.

Initializing the fields seems the simple solution here (and, IMHO, more generally, it's as a good programming practice)

Thanks for looking into this!

Best,
Carlos

[0] https://lore.kernel.org/lkml/CACGkMEvfdUYLjx-Z+oB11XW-54ErJsQMKcnu2p=dsj5N_BiEKw@mail.gmail.com/

Quoted 43 lines
Quoted 43 lines
Quoted 43 lines
Quoted 43 lines

Add
needed helper cpu_to_mlx5vdpa32() to convert endianness of speed.

---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/vdpa/mlx5/net/mlx5_vnet.c +12 -0
index b56aae3f7be3..41ca268d43ff 100644
@@ -173,6 +173,11 @@ static __virtio16 cpu_to_mlx5vdpa16(struct mlx5_vdpa_dev *mvdev, u16 val)
 	return __cpu_to_virtio16(mlx5_vdpa_is_little_endian(mvdev), val);
 }
 
+static __virtio32 cpu_to_mlx5vdpa32(struct mlx5_vdpa_dev *mvdev, u32 val)
+{
+	return __cpu_to_virtio32(mlx5_vdpa_is_little_endian(mvdev), val);
+}
+
 static u16 ctrl_vq_idx(struct mlx5_vdpa_dev *mvdev)
 {
 	if (!(mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_MQ)))
@@ -3433,6 +3438,13 @@ static int mlx5_vdpa_dev_add(struct vdpa_mgmt_dev *v_mdev, const char *name,
 	init_rwsem(&ndev->reslock);
 	config = &ndev->config;
 
+	/*
+	 * mlx5_vdpa vDPA devices currently don't support reporting or
+	 * setting the speed or duplex.
+	 */
+	config->speed  = cpu_to_mlx5vdpa32(mvdev, SPEED_UNKNOWN);
+	config->duplex = DUPLEX_UNKNOWN;
+
 	if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU)) {
 		err = config_func_mtu(mdev, add_config->net.mtu);
 		if (err)
Signature · 1 line
2.34.1
#7 lore raw

PATCH v3 2/2 vdpa: Remove ioctl VHOST_VDPA_SET_CONFIG per spec compliance

In reply to Carlos Bilbao

From: Carlos Bilbao <[email protected]>

Remove invalid ioctl VHOST_VDPA_SET_CONFIG and all its implementations with vdpa_config_ops->set_config(). This is needed per virtio spec requirements:
virtio-spec v1.3 Sec 5.1.4 states that "All of the device configuration fields are read-only for the driver.". This excludes legacy Alibaba's ENI so make it use vda_config_ops->set_config_legacy() to avoid future confusion.

---
 drivers/vdpa/alibaba/eni_vdpa.c    |  2 +-
 drivers/vdpa/ifcvf/ifcvf_main.c    | 10 ----------
 drivers/vdpa/mlx5/net/mlx5_vnet.c  |  7 -------
 drivers/vdpa/pds/vdpa_dev.c        | 16 ----------------
 drivers/vdpa/solidrun/snet_main.c  | 18 ------------------
 drivers/vdpa/vdpa.c                | 16 ----------------
 drivers/vdpa/vdpa_sim/vdpa_sim.c   | 16 ----------------
 drivers/vdpa/vdpa_sim/vdpa_sim.h   |  1 -
 drivers/vdpa/vdpa_user/vduse_dev.c |  7 -------
 drivers/vdpa/virtio_pci/vp_vdpa.c  | 14 --------------
 drivers/vhost/vdpa.c               | 26 --------------------------
 drivers/virtio/virtio_vdpa.c       |  9 ---------
 include/linux/vdpa.h               |  7 ++++---
 include/uapi/linux/vhost.h         |  8 ++++----
 14 files changed, 9 insertions(+), 148 deletions(-)
drivers/vdpa/alibaba/eni_vdpa.c +1 -1
index cce3d1837104..64b0c0be89ae 100644
@@ -429,7 +429,7 @@ static const struct vdpa_config_ops eni_vdpa_ops = {
 	.get_vq_align	= eni_vdpa_get_vq_align,
 	.get_config_size = eni_vdpa_get_config_size,
 	.get_config	= eni_vdpa_get_config,
-	.set_config	= eni_vdpa_set_config,
+	.set_config_legacy = eni_vdpa_set_config,
 	.set_config_cb  = eni_vdpa_set_config_cb,
 	.get_vq_irq	= eni_vdpa_get_vq_irq,
 };
drivers/vdpa/ifcvf/ifcvf_main.c +0 -10
index e98fa8100f3c..7cbac787ad5f 100644
@@ -568,15 +568,6 @@ static void ifcvf_vdpa_get_config(struct vdpa_device *vdpa_dev,
 	ifcvf_read_dev_config(vf, offset, buf, len);
 }
 
-static void ifcvf_vdpa_set_config(struct vdpa_device *vdpa_dev,
-				  unsigned int offset, const void *buf,
-				  unsigned int len)
-{
-	struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
-
-	ifcvf_write_dev_config(vf, offset, buf, len);
-}
-
 static void ifcvf_vdpa_set_config_cb(struct vdpa_device *vdpa_dev,
 				     struct vdpa_callback *cb)
 {
@@ -640,7 +631,6 @@ static const struct vdpa_config_ops ifc_vdpa_ops = {
 	.get_vq_group	= ifcvf_vdpa_get_vq_group,
 	.get_config_size	= ifcvf_vdpa_get_config_size,
 	.get_config	= ifcvf_vdpa_get_config,
-	.set_config	= ifcvf_vdpa_set_config,
 	.set_config_cb  = ifcvf_vdpa_set_config_cb,
 	.get_vq_notification = ifcvf_get_vq_notification,
 };
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -7
index 41ca268d43ff..35ed46c65b4d 100644
@@ -2918,12 +2918,6 @@ static void mlx5_vdpa_get_config(struct vdpa_device *vdev, unsigned int offset,
 		memcpy(buf, (u8 *)&ndev->config + offset, len);
 }
 
-static void mlx5_vdpa_set_config(struct vdpa_device *vdev, unsigned int offset, const void *buf,
-				 unsigned int len)
-{
-	/* not supported */
-}
-
 static u32 mlx5_vdpa_get_generation(struct vdpa_device *vdev)
 {
 	struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
@@ -3218,7 +3212,6 @@ static const struct vdpa_config_ops mlx5_vdpa_ops = {
 	.reset = mlx5_vdpa_reset,
 	.get_config_size = mlx5_vdpa_get_config_size,
 	.get_config = mlx5_vdpa_get_config,
-	.set_config = mlx5_vdpa_set_config,
 	.get_generation = mlx5_vdpa_get_generation,
 	.set_map = mlx5_vdpa_set_map,
 	.set_group_asid = mlx5_set_group_asid,
drivers/vdpa/pds/vdpa_dev.c +0 -16
index 25c0fe5ec3d5..553dcd2aa065 100644
@@ -553,21 +553,6 @@ static void pds_vdpa_get_config(struct vdpa_device *vdpa_dev,
 	memcpy_fromio(buf, device + offset, len);
 }
 
-static void pds_vdpa_set_config(struct vdpa_device *vdpa_dev,
-				unsigned int offset, const void *buf,
-				unsigned int len)
-{
-	struct pds_vdpa_device *pdsv = vdpa_to_pdsv(vdpa_dev);
-	void __iomem *device;
-
-	if (offset + len > sizeof(struct virtio_net_config)) {
-		WARN(true, "%s: bad read, offset %d len %d\n", __func__, offset, len);
-		return;
-	}
-
-	device = pdsv->vdpa_aux->vd_mdev.device;
-	memcpy_toio(device + offset, buf, len);
-}
 
 static const struct vdpa_config_ops pds_vdpa_ops = {
 	.set_vq_address		= pds_vdpa_set_vq_address,
@@ -595,7 +580,6 @@ static const struct vdpa_config_ops pds_vdpa_ops = {
 	.reset			= pds_vdpa_reset,
 	.get_config_size	= pds_vdpa_get_config_size,
 	.get_config		= pds_vdpa_get_config,
-	.set_config		= pds_vdpa_set_config,
 };
 static struct virtio_device_id pds_vdpa_id_table[] = {
 	{VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID},
drivers/vdpa/solidrun/snet_main.c +0 -18
index 99428a04068d..141740269b6c 100644
@@ -478,23 +478,6 @@ static void snet_get_config(struct vdpa_device *vdev, unsigned int offset,
 		*buf_ptr++ = ioread8(cfg_ptr + i);
 }
 
-static void snet_set_config(struct vdpa_device *vdev, unsigned int offset,
-			    const void *buf, unsigned int len)
-{
-	struct snet *snet = vdpa_to_snet(vdev);
-	void __iomem *cfg_ptr = snet->cfg->virtio_cfg + offset;
-	const u8 *buf_ptr = buf;
-	u32 i;
-
-	/* check for offset error */
-	if (offset + len > snet->cfg->cfg_size)
-		return;
-
-	/* Write into PCI BAR */
-	for (i = 0; i < len; i++)
-		iowrite8(*buf_ptr++, cfg_ptr + i);
-}
-
 static int snet_suspend(struct vdpa_device *vdev)
 {
 	struct snet *snet = vdpa_to_snet(vdev);
@@ -548,7 +531,6 @@ static const struct vdpa_config_ops snet_config_ops = {
 	.get_status             = snet_get_status,
 	.set_status             = snet_set_status,
 	.get_config             = snet_get_config,
-	.set_config             = snet_set_config,
 	.suspend		= snet_suspend,
 	.resume			= snet_resume,
 };
drivers/vdpa/vdpa.c +0 -16
index a7612e0783b3..a9eac31f3757 100644
@@ -401,22 +401,6 @@ void vdpa_get_config(struct vdpa_device *vdev, unsigned int offset,
 }
 EXPORT_SYMBOL_GPL(vdpa_get_config);
 
-/**
- * vdpa_set_config - Set one or more device configuration fields.
- * @vdev: vdpa device to operate on
- * @offset: starting byte offset of the field
- * @buf: buffer pointer to read from
- * @length: length of the configuration fields in bytes
- */
-void vdpa_set_config(struct vdpa_device *vdev, unsigned int offset,
-		     const void *buf, unsigned int length)
-{
-	down_write(&vdev->cf_lock);
-	vdev->config->set_config(vdev, offset, buf, length);
-	up_write(&vdev->cf_lock);
-}
-EXPORT_SYMBOL_GPL(vdpa_set_config);
-
 static bool mgmtdev_handle_match(const struct vdpa_mgmt_dev *mdev,
 				 const char *busname, const char *devname)
 {
drivers/vdpa/vdpa_sim/vdpa_sim.c +0 -16
index 421ab01ef06b..c2e14bcc01f6 100644
@@ -546,20 +546,6 @@ static void vdpasim_get_config(struct vdpa_device *vdpa, unsigned int offset,
 	memcpy(buf, vdpasim->config + offset, len);
 }
 
-static void vdpasim_set_config(struct vdpa_device *vdpa, unsigned int offset,
-			     const void *buf, unsigned int len)
-{
-	struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
-
-	if (offset + len > vdpasim->dev_attr.config_size)
-		return;
-
-	memcpy(vdpasim->config + offset, buf, len);
-
-	if (vdpasim->dev_attr.set_config)
-		vdpasim->dev_attr.set_config(vdpasim, vdpasim->config);
-}
-
 static u32 vdpasim_get_generation(struct vdpa_device *vdpa)
 {
 	struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
@@ -754,7 +740,6 @@ static const struct vdpa_config_ops vdpasim_config_ops = {
 	.resume			= vdpasim_resume,
 	.get_config_size        = vdpasim_get_config_size,
 	.get_config             = vdpasim_get_config,
-	.set_config             = vdpasim_set_config,
 	.get_generation         = vdpasim_get_generation,
 	.get_iova_range         = vdpasim_get_iova_range,
 	.set_group_asid         = vdpasim_set_group_asid,
@@ -792,7 +777,6 @@ static const struct vdpa_config_ops vdpasim_batch_config_ops = {
 	.resume			= vdpasim_resume,
 	.get_config_size        = vdpasim_get_config_size,
 	.get_config             = vdpasim_get_config,
-	.set_config             = vdpasim_set_config,
 	.get_generation         = vdpasim_get_generation,
 	.get_iova_range         = vdpasim_get_iova_range,
 	.set_group_asid         = vdpasim_set_group_asid,
drivers/vdpa/vdpa_sim/vdpa_sim.h +0 -1
index bb137e479763..b48bf954a3bb 100644
@@ -46,7 +46,6 @@ struct vdpasim_dev_attr {
 
 	void (*work_fn)(struct vdpasim *vdpasim);
 	void (*get_config)(struct vdpasim *vdpasim, void *config);
-	void (*set_config)(struct vdpasim *vdpasim, const void *config);
 	int (*get_stats)(struct vdpasim *vdpasim, u16 idx,
 			 struct sk_buff *msg,
 			 struct netlink_ext_ack *extack);
drivers/vdpa/vdpa_user/vduse_dev.c +0 -7
index df7869537ef1..4fe69cb5b156 100644
@@ -698,12 +698,6 @@ static void vduse_vdpa_get_config(struct vdpa_device *vdpa, unsigned int offset,
 	memcpy(buf, dev->config + offset, len);
 }
 
-static void vduse_vdpa_set_config(struct vdpa_device *vdpa, unsigned int offset,
-			const void *buf, unsigned int len)
-{
-	/* Now we only support read-only configuration space */
-}
-
 static int vduse_vdpa_reset(struct vdpa_device *vdpa)
 {
 	struct vduse_dev *dev = vdpa_to_vduse(vdpa);
@@ -790,7 +784,6 @@ static const struct vdpa_config_ops vduse_vdpa_config_ops = {
 	.set_status		= vduse_vdpa_set_status,
 	.get_config_size	= vduse_vdpa_get_config_size,
 	.get_config		= vduse_vdpa_get_config,
-	.set_config		= vduse_vdpa_set_config,
 	.get_generation		= vduse_vdpa_get_generation,
 	.set_vq_affinity	= vduse_vdpa_set_vq_affinity,
 	.get_vq_affinity	= vduse_vdpa_get_vq_affinity,
drivers/vdpa/virtio_pci/vp_vdpa.c +0 -14
index 281287fae89f..5e8ff91475e3 100644
@@ -400,19 +400,6 @@ static void vp_vdpa_get_config(struct vdpa_device *vdpa,
 	} while (old != new);
 }
 
-static void vp_vdpa_set_config(struct vdpa_device *vdpa,
-			       unsigned int offset, const void *buf,
-			       unsigned int len)
-{
-	struct vp_vdpa *vp_vdpa = vdpa_to_vp(vdpa);
-	struct virtio_pci_modern_device *mdev = vp_vdpa_to_mdev(vp_vdpa);
-	const u8 *p = buf;
-	int i;
-
-	for (i = 0; i < len; i++)
-		vp_iowrite8(*p++, mdev->device + offset + i);
-}
-
 static void vp_vdpa_set_config_cb(struct vdpa_device *vdpa,
 				  struct vdpa_callback *cb)
 {
@@ -457,7 +444,6 @@ static const struct vdpa_config_ops vp_vdpa_ops = {
 	.get_vq_align	= vp_vdpa_get_vq_align,
 	.get_config_size = vp_vdpa_get_config_size,
 	.get_config	= vp_vdpa_get_config,
-	.set_config	= vp_vdpa_set_config,
 	.set_config_cb  = vp_vdpa_set_config_cb,
 	.get_vq_irq	= vp_vdpa_get_vq_irq,
 };
drivers/vhost/vdpa.c +0 -26
index fb590e346e43..c6fcd54f59be 100644
@@ -350,29 +350,6 @@ static long vhost_vdpa_get_config(struct vhost_vdpa *v,
 	return 0;
 }
 
-static long vhost_vdpa_set_config(struct vhost_vdpa *v,
-				  struct vhost_vdpa_config __user *c)
-{
-	struct vdpa_device *vdpa = v->vdpa;
-	struct vhost_vdpa_config config;
-	unsigned long size = offsetof(struct vhost_vdpa_config, buf);
-	u8 *buf;
-
-	if (copy_from_user(&config, c, size))
-		return -EFAULT;
-	if (vhost_vdpa_config_validate(v, &config))
-		return -EINVAL;
-
-	buf = vmemdup_user(c->buf, config.len);
-	if (IS_ERR(buf))
-		return PTR_ERR(buf);
-
-	vdpa_set_config(vdpa, config.off, buf, config.len);
-
-	kvfree(buf);
-	return 0;
-}
-
 static bool vhost_vdpa_can_suspend(const struct vhost_vdpa *v)
 {
 	struct vdpa_device *vdpa = v->vdpa;
@@ -719,9 +696,6 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
 	case VHOST_VDPA_GET_CONFIG:
 		r = vhost_vdpa_get_config(v, argp);
 		break;
-	case VHOST_VDPA_SET_CONFIG:
-		r = vhost_vdpa_set_config(v, argp);
-		break;
 	case VHOST_GET_FEATURES:
 		r = vhost_vdpa_get_features(v, argp);
 		break;
drivers/virtio/virtio_vdpa.c +0 -9
index 06ce6d8c2e00..481ded50c916 100644
@@ -62,14 +62,6 @@ static void virtio_vdpa_get(struct virtio_device *vdev, unsigned int offset,
 	vdpa_get_config(vdpa, offset, buf, len);
 }
 
-static void virtio_vdpa_set(struct virtio_device *vdev, unsigned int offset,
-			    const void *buf, unsigned int len)
-{
-	struct vdpa_device *vdpa = vd_get_vdpa(vdev);
-
-	vdpa_set_config(vdpa, offset, buf, len);
-}
-
 static u32 virtio_vdpa_generation(struct virtio_device *vdev)
 {
 	struct vdpa_device *vdpa = vd_get_vdpa(vdev);
@@ -462,7 +454,6 @@ virtio_vdpa_get_vq_affinity(struct virtio_device *vdev, int index)
 
 static const struct virtio_config_ops virtio_vdpa_config_ops = {
 	.get		= virtio_vdpa_get,
-	.set		= virtio_vdpa_set,
 	.generation	= virtio_vdpa_generation,
 	.get_status	= virtio_vdpa_get_status,
 	.set_status	= virtio_vdpa_set_status,
include/linux/vdpa.h +4 -3
index 0e652026b776..9346fa9e3d97 100644
@@ -259,7 +259,8 @@ struct vdpa_map_file {
  *				@buf: buffer used to read to
  *				@len: the length to read from
  *				configuration space
- * @set_config:			Write to device specific configuration space
+ * @set_config_legacy:		Write to device specific configuration space
+ *				Legacy functionality for virtio-spec < v1.3
  *				@vdev: vdpa device
  *				@offset: offset from the beginning of
  *				configuration space
@@ -378,8 +379,8 @@ struct vdpa_config_ops {
 	size_t (*get_config_size)(struct vdpa_device *vdev);
 	void (*get_config)(struct vdpa_device *vdev, unsigned int offset,
 			   void *buf, unsigned int len);
-	void (*set_config)(struct vdpa_device *vdev, unsigned int offset,
-			   const void *buf, unsigned int len);
+	void (*set_config_legacy)(struct vdpa_device *vdev,
+			unsigned int offset, const void *buf, unsigned int len);
 	u32 (*get_generation)(struct vdpa_device *vdev);
 	struct vdpa_iova_range (*get_iova_range)(struct vdpa_device *vdev);
 	int (*set_vq_affinity)(struct vdpa_device *vdev, u16 idx,
include/uapi/linux/vhost.h +4 -4
index f5c48b61ab62..b7977f9ae596 100644
@@ -157,13 +157,13 @@
  */
 #define VHOST_VDPA_GET_STATUS		_IOR(VHOST_VIRTIO, 0x71, __u8)
 #define VHOST_VDPA_SET_STATUS		_IOW(VHOST_VIRTIO, 0x72, __u8)
-/* Get and set the device config. The device config follows the same
- * definition of the device config defined in virtio-spec.
+/* Get the device config. The device config follows the same
+ * definition of the device config defined in virtio-spec. According to
+ * virtio-spec v1.3, all device configuration fields are read-only for the
+ * driver, and thus we do not have VHOST_VDPA_SET_CONFIG.
  */
 #define VHOST_VDPA_GET_CONFIG		_IOR(VHOST_VIRTIO, 0x73, \
 					     struct vhost_vdpa_config)
-#define VHOST_VDPA_SET_CONFIG		_IOW(VHOST_VIRTIO, 0x74, \
-					     struct vhost_vdpa_config)
 /* Enable/disable the ring. */
 #define VHOST_VDPA_SET_VRING_ENABLE	_IOW(VHOST_VIRTIO, 0x75, \
 					     struct vhost_vring_state)
Signature · 1 line
2.34.1
#8 lore raw

Re: [PATCH v3 2/2] vdpa: Remove ioctl VHOST_VDPA_SET_CONFIG per spec compliance

Quoted 7 lines · Carlos Bilbao

From: Carlos Bilbao <[email protected]>

Remove invalid ioctl VHOST_VDPA_SET_CONFIG and all its implementations with vdpa_config_ops->set_config(). This is needed per virtio spec requirements:
virtio-spec v1.3 Sec 5.1.4 states that "All of the device configuration fields are read-only for the driver.".

Just to make sure we are on the same page.

That part is specific to the virtio-net device. Other types of device may have a field that could be written. For example the writeback field of the virtio-blk device when WCE is enabled.

Even for the networking device, it doesn't mean we can't have a writable field in the future.

So I tend to leave the code as-is.

Thanks

Quoted 416 lines

This excludes legacy Alibaba's ENI
so make it use vda_config_ops->set_config_legacy() to avoid future confusion.

---
 drivers/vdpa/alibaba/eni_vdpa.c    |  2 +-
 drivers/vdpa/ifcvf/ifcvf_main.c    | 10 ----------
 drivers/vdpa/mlx5/net/mlx5_vnet.c  |  7 -------
 drivers/vdpa/pds/vdpa_dev.c        | 16 ----------------
 drivers/vdpa/solidrun/snet_main.c  | 18 ------------------
 drivers/vdpa/vdpa.c                | 16 ----------------
 drivers/vdpa/vdpa_sim/vdpa_sim.c   | 16 ----------------
 drivers/vdpa/vdpa_sim/vdpa_sim.h   |  1 -
 drivers/vdpa/vdpa_user/vduse_dev.c |  7 -------
 drivers/vdpa/virtio_pci/vp_vdpa.c  | 14 --------------
 drivers/vhost/vdpa.c               | 26 --------------------------
 drivers/virtio/virtio_vdpa.c       |  9 ---------
 include/linux/vdpa.h               |  7 ++++---
 include/uapi/linux/vhost.h         |  8 ++++----
 14 files changed, 9 insertions(+), 148 deletions(-)
drivers/vdpa/alibaba/eni_vdpa.c +1 -1
index cce3d1837104..64b0c0be89ae 100644
@@ -429,7 +429,7 @@ static const struct vdpa_config_ops eni_vdpa_ops = {
        .get_vq_align   = eni_vdpa_get_vq_align,
        .get_config_size = eni_vdpa_get_config_size,
        .get_config     = eni_vdpa_get_config,
-       .set_config     = eni_vdpa_set_config,
+       .set_config_legacy = eni_vdpa_set_config,
        .set_config_cb  = eni_vdpa_set_config_cb,
        .get_vq_irq     = eni_vdpa_get_vq_irq,
 };
drivers/vdpa/ifcvf/ifcvf_main.c +0 -10
index e98fa8100f3c..7cbac787ad5f 100644
@@ -568,15 +568,6 @@ static void ifcvf_vdpa_get_config(struct vdpa_device *vdpa_dev,
        ifcvf_read_dev_config(vf, offset, buf, len);
 }
 
-static void ifcvf_vdpa_set_config(struct vdpa_device *vdpa_dev,
-                                 unsigned int offset, const void *buf,
-                                 unsigned int len)
-{
-       struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev);
-
-       ifcvf_write_dev_config(vf, offset, buf, len);
-}
-
 static void ifcvf_vdpa_set_config_cb(struct vdpa_device *vdpa_dev,
                                     struct vdpa_callback *cb)
 {
@@ -640,7 +631,6 @@ static const struct vdpa_config_ops ifc_vdpa_ops = {
        .get_vq_group   = ifcvf_vdpa_get_vq_group,
        .get_config_size        = ifcvf_vdpa_get_config_size,
        .get_config     = ifcvf_vdpa_get_config,
-       .set_config     = ifcvf_vdpa_set_config,
        .set_config_cb  = ifcvf_vdpa_set_config_cb,
        .get_vq_notification = ifcvf_get_vq_notification,
 };
drivers/vdpa/mlx5/net/mlx5_vnet.c +0 -7
index 41ca268d43ff..35ed46c65b4d 100644
@@ -2918,12 +2918,6 @@ static void mlx5_vdpa_get_config(struct vdpa_device *vdev, unsigned int offset,
                memcpy(buf, (u8 *)&ndev->config + offset, len);
 }
 
-static void mlx5_vdpa_set_config(struct vdpa_device *vdev, unsigned int offset, const void *buf,
-                                unsigned int len)
-{
-       /* not supported */
-}
-
 static u32 mlx5_vdpa_get_generation(struct vdpa_device *vdev)
 {
        struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev);
@@ -3218,7 +3212,6 @@ static const struct vdpa_config_ops mlx5_vdpa_ops = {
        .reset = mlx5_vdpa_reset,
        .get_config_size = mlx5_vdpa_get_config_size,
        .get_config = mlx5_vdpa_get_config,
-       .set_config = mlx5_vdpa_set_config,
        .get_generation = mlx5_vdpa_get_generation,
        .set_map = mlx5_vdpa_set_map,
        .set_group_asid = mlx5_set_group_asid,
drivers/vdpa/pds/vdpa_dev.c +0 -16
index 25c0fe5ec3d5..553dcd2aa065 100644
@@ -553,21 +553,6 @@ static void pds_vdpa_get_config(struct vdpa_device *vdpa_dev,
        memcpy_fromio(buf, device + offset, len);
 }
 
-static void pds_vdpa_set_config(struct vdpa_device *vdpa_dev,
-                               unsigned int offset, const void *buf,
-                               unsigned int len)
-{
-       struct pds_vdpa_device *pdsv = vdpa_to_pdsv(vdpa_dev);
-       void __iomem *device;
-
-       if (offset + len > sizeof(struct virtio_net_config)) {
-               WARN(true, "%s: bad read, offset %d len %d\n", __func__, offset, len);
-               return;
-       }
-
-       device = pdsv->vdpa_aux->vd_mdev.device;
-       memcpy_toio(device + offset, buf, len);
-}
 
 static const struct vdpa_config_ops pds_vdpa_ops = {
        .set_vq_address         = pds_vdpa_set_vq_address,
@@ -595,7 +580,6 @@ static const struct vdpa_config_ops pds_vdpa_ops = {
        .reset                  = pds_vdpa_reset,
        .get_config_size        = pds_vdpa_get_config_size,
        .get_config             = pds_vdpa_get_config,
-       .set_config             = pds_vdpa_set_config,
 };
 static struct virtio_device_id pds_vdpa_id_table[] = {
        {VIRTIO_ID_NET, VIRTIO_DEV_ANY_ID},
drivers/vdpa/solidrun/snet_main.c +0 -18
index 99428a04068d..141740269b6c 100644
@@ -478,23 +478,6 @@ static void snet_get_config(struct vdpa_device *vdev, unsigned int offset,
                *buf_ptr++ = ioread8(cfg_ptr + i);
 }
 
-static void snet_set_config(struct vdpa_device *vdev, unsigned int offset,
-                           const void *buf, unsigned int len)
-{
-       struct snet *snet = vdpa_to_snet(vdev);
-       void __iomem *cfg_ptr = snet->cfg->virtio_cfg + offset;
-       const u8 *buf_ptr = buf;
-       u32 i;
-
-       /* check for offset error */
-       if (offset + len > snet->cfg->cfg_size)
-               return;
-
-       /* Write into PCI BAR */
-       for (i = 0; i < len; i++)
-               iowrite8(*buf_ptr++, cfg_ptr + i);
-}
-
 static int snet_suspend(struct vdpa_device *vdev)
 {
        struct snet *snet = vdpa_to_snet(vdev);
@@ -548,7 +531,6 @@ static const struct vdpa_config_ops snet_config_ops = {
        .get_status             = snet_get_status,
        .set_status             = snet_set_status,
        .get_config             = snet_get_config,
-       .set_config             = snet_set_config,
        .suspend                = snet_suspend,
        .resume                 = snet_resume,
 };
drivers/vdpa/vdpa.c +0 -16
index a7612e0783b3..a9eac31f3757 100644
@@ -401,22 +401,6 @@ void vdpa_get_config(struct vdpa_device *vdev, unsigned int offset,
 }
 EXPORT_SYMBOL_GPL(vdpa_get_config);
 
-/**
- * vdpa_set_config - Set one or more device configuration fields.
- * @vdev: vdpa device to operate on
- * @offset: starting byte offset of the field
- * @buf: buffer pointer to read from
- * @length: length of the configuration fields in bytes
- */
-void vdpa_set_config(struct vdpa_device *vdev, unsigned int offset,
-                    const void *buf, unsigned int length)
-{
-       down_write(&vdev->cf_lock);
-       vdev->config->set_config(vdev, offset, buf, length);
-       up_write(&vdev->cf_lock);
-}
-EXPORT_SYMBOL_GPL(vdpa_set_config);
-
 static bool mgmtdev_handle_match(const struct vdpa_mgmt_dev *mdev,
                                 const char *busname, const char *devname)
 {
drivers/vdpa/vdpa_sim/vdpa_sim.c +0 -16
index 421ab01ef06b..c2e14bcc01f6 100644
@@ -546,20 +546,6 @@ static void vdpasim_get_config(struct vdpa_device *vdpa, unsigned int offset,
        memcpy(buf, vdpasim->config + offset, len);
 }
 
-static void vdpasim_set_config(struct vdpa_device *vdpa, unsigned int offset,
-                            const void *buf, unsigned int len)
-{
-       struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
-
-       if (offset + len > vdpasim->dev_attr.config_size)
-               return;
-
-       memcpy(vdpasim->config + offset, buf, len);
-
-       if (vdpasim->dev_attr.set_config)
-               vdpasim->dev_attr.set_config(vdpasim, vdpasim->config);
-}
-
 static u32 vdpasim_get_generation(struct vdpa_device *vdpa)
 {
        struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
@@ -754,7 +740,6 @@ static const struct vdpa_config_ops vdpasim_config_ops = {
        .resume                 = vdpasim_resume,
        .get_config_size        = vdpasim_get_config_size,
        .get_config             = vdpasim_get_config,
-       .set_config             = vdpasim_set_config,
        .get_generation         = vdpasim_get_generation,
        .get_iova_range         = vdpasim_get_iova_range,
        .set_group_asid         = vdpasim_set_group_asid,
@@ -792,7 +777,6 @@ static const struct vdpa_config_ops vdpasim_batch_config_ops = {
        .resume                 = vdpasim_resume,
        .get_config_size        = vdpasim_get_config_size,
        .get_config             = vdpasim_get_config,
-       .set_config             = vdpasim_set_config,
        .get_generation         = vdpasim_get_generation,
        .get_iova_range         = vdpasim_get_iova_range,
        .set_group_asid         = vdpasim_set_group_asid,
drivers/vdpa/vdpa_sim/vdpa_sim.h +0 -1
index bb137e479763..b48bf954a3bb 100644
@@ -46,7 +46,6 @@ struct vdpasim_dev_attr {
 
        void (*work_fn)(struct vdpasim *vdpasim);
        void (*get_config)(struct vdpasim *vdpasim, void *config);
-       void (*set_config)(struct vdpasim *vdpasim, const void *config);
        int (*get_stats)(struct vdpasim *vdpasim, u16 idx,
                         struct sk_buff *msg,
                         struct netlink_ext_ack *extack);
drivers/vdpa/vdpa_user/vduse_dev.c +0 -7
index df7869537ef1..4fe69cb5b156 100644
@@ -698,12 +698,6 @@ static void vduse_vdpa_get_config(struct vdpa_device *vdpa, unsigned int offset,
        memcpy(buf, dev->config + offset, len);
 }
 
-static void vduse_vdpa_set_config(struct vdpa_device *vdpa, unsigned int offset,
-                       const void *buf, unsigned int len)
-{
-       /* Now we only support read-only configuration space */
-}
-
 static int vduse_vdpa_reset(struct vdpa_device *vdpa)
 {
        struct vduse_dev *dev = vdpa_to_vduse(vdpa);
@@ -790,7 +784,6 @@ static const struct vdpa_config_ops vduse_vdpa_config_ops = {
        .set_status             = vduse_vdpa_set_status,
        .get_config_size        = vduse_vdpa_get_config_size,
        .get_config             = vduse_vdpa_get_config,
-       .set_config             = vduse_vdpa_set_config,
        .get_generation         = vduse_vdpa_get_generation,
        .set_vq_affinity        = vduse_vdpa_set_vq_affinity,
        .get_vq_affinity        = vduse_vdpa_get_vq_affinity,
drivers/vdpa/virtio_pci/vp_vdpa.c +0 -14
index 281287fae89f..5e8ff91475e3 100644
@@ -400,19 +400,6 @@ static void vp_vdpa_get_config(struct vdpa_device *vdpa,
        } while (old != new);
 }
 
-static void vp_vdpa_set_config(struct vdpa_device *vdpa,
-                              unsigned int offset, const void *buf,
-                              unsigned int len)
-{
-       struct vp_vdpa *vp_vdpa = vdpa_to_vp(vdpa);
-       struct virtio_pci_modern_device *mdev = vp_vdpa_to_mdev(vp_vdpa);
-       const u8 *p = buf;
-       int i;
-
-       for (i = 0; i < len; i++)
-               vp_iowrite8(*p++, mdev->device + offset + i);
-}
-
 static void vp_vdpa_set_config_cb(struct vdpa_device *vdpa,
                                  struct vdpa_callback *cb)
 {
@@ -457,7 +444,6 @@ static const struct vdpa_config_ops vp_vdpa_ops = {
        .get_vq_align   = vp_vdpa_get_vq_align,
        .get_config_size = vp_vdpa_get_config_size,
        .get_config     = vp_vdpa_get_config,
-       .set_config     = vp_vdpa_set_config,
        .set_config_cb  = vp_vdpa_set_config_cb,
        .get_vq_irq     = vp_vdpa_get_vq_irq,
 };
drivers/vhost/vdpa.c +0 -26
index fb590e346e43..c6fcd54f59be 100644
@@ -350,29 +350,6 @@ static long vhost_vdpa_get_config(struct vhost_vdpa *v,
        return 0;
 }
 
-static long vhost_vdpa_set_config(struct vhost_vdpa *v,
-                                 struct vhost_vdpa_config __user *c)
-{
-       struct vdpa_device *vdpa = v->vdpa;
-       struct vhost_vdpa_config config;
-       unsigned long size = offsetof(struct vhost_vdpa_config, buf);
-       u8 *buf;
-
-       if (copy_from_user(&config, c, size))
-               return -EFAULT;
-       if (vhost_vdpa_config_validate(v, &config))
-               return -EINVAL;
-
-       buf = vmemdup_user(c->buf, config.len);
-       if (IS_ERR(buf))
-               return PTR_ERR(buf);
-
-       vdpa_set_config(vdpa, config.off, buf, config.len);
-
-       kvfree(buf);
-       return 0;
-}
-
 static bool vhost_vdpa_can_suspend(const struct vhost_vdpa *v)
 {
        struct vdpa_device *vdpa = v->vdpa;
@@ -719,9 +696,6 @@ static long vhost_vdpa_unlocked_ioctl(struct file *filep,
        case VHOST_VDPA_GET_CONFIG:
                r = vhost_vdpa_get_config(v, argp);
                break;
-       case VHOST_VDPA_SET_CONFIG:
-               r = vhost_vdpa_set_config(v, argp);
-               break;
        case VHOST_GET_FEATURES:
                r = vhost_vdpa_get_features(v, argp);
                break;
drivers/virtio/virtio_vdpa.c +0 -9
index 06ce6d8c2e00..481ded50c916 100644
@@ -62,14 +62,6 @@ static void virtio_vdpa_get(struct virtio_device *vdev, unsigned int offset,
        vdpa_get_config(vdpa, offset, buf, len);
 }
 
-static void virtio_vdpa_set(struct virtio_device *vdev, unsigned int offset,
-                           const void *buf, unsigned int len)
-{
-       struct vdpa_device *vdpa = vd_get_vdpa(vdev);
-
-       vdpa_set_config(vdpa, offset, buf, len);
-}
-
 static u32 virtio_vdpa_generation(struct virtio_device *vdev)
 {
        struct vdpa_device *vdpa = vd_get_vdpa(vdev);
@@ -462,7 +454,6 @@ virtio_vdpa_get_vq_affinity(struct virtio_device *vdev, int index)
 
 static const struct virtio_config_ops virtio_vdpa_config_ops = {
        .get            = virtio_vdpa_get,
-       .set            = virtio_vdpa_set,
        .generation     = virtio_vdpa_generation,
        .get_status     = virtio_vdpa_get_status,
        .set_status     = virtio_vdpa_set_status,
include/linux/vdpa.h +4 -3
index 0e652026b776..9346fa9e3d97 100644
@@ -259,7 +259,8 @@ struct vdpa_map_file {
  *                             @buf: buffer used to read to
  *                             @len: the length to read from
  *                             configuration space
- * @set_config:                        Write to device specific configuration space
+ * @set_config_legacy:         Write to device specific configuration space
+ *                             Legacy functionality for virtio-spec < v1.3
  *                             @vdev: vdpa device
  *                             @offset: offset from the beginning of
  *                             configuration space
@@ -378,8 +379,8 @@ struct vdpa_config_ops {
        size_t (*get_config_size)(struct vdpa_device *vdev);
        void (*get_config)(struct vdpa_device *vdev, unsigned int offset,
                           void *buf, unsigned int len);
-       void (*set_config)(struct vdpa_device *vdev, unsigned int offset,
-                          const void *buf, unsigned int len);
+       void (*set_config_legacy)(struct vdpa_device *vdev,
+                       unsigned int offset, const void *buf, unsigned int len);
        u32 (*get_generation)(struct vdpa_device *vdev);
        struct vdpa_iova_range (*get_iova_range)(struct vdpa_device *vdev);
        int (*set_vq_affinity)(struct vdpa_device *vdev, u16 idx,
include/uapi/linux/vhost.h +4 -5
index f5c48b61ab62..b7977f9ae596 100644
@@ -157,13 +157,13 @@
  */
 #define VHOST_VDPA_GET_STATUS          _IOR(VHOST_VIRTIO, 0x71, __u8)
 #define VHOST_VDPA_SET_STATUS          _IOW(VHOST_VIRTIO, 0x72, __u8)
-/* Get and set the device config. The device config follows the same
- * definition of the device config defined in virtio-spec.
+/* Get the device config. The device config follows the same
+ * definition of the device config defined in virtio-spec. According to
+ * virtio-spec v1.3, all device configuration fields are read-only for the
+ * driver, and thus we do not have VHOST_VDPA_SET_CONFIG.
  */
 #define VHOST_VDPA_GET_CONFIG          _IOR(VHOST_VIRTIO, 0x73, \
                                             struct vhost_vdpa_config)
-#define VHOST_VDPA_SET_CONFIG          _IOW(VHOST_VIRTIO, 0x74, \
-                                            struct vhost_vdpa_config)
 /* Enable/disable the ring. */
 #define VHOST_VDPA_SET_VRING_ENABLE    _IOW(VHOST_VIRTIO, 0x75, \
                                             struct vhost_vring_state)
--

2.34.1

#9 lore raw
In reply to Carlos Bilbao
Quoted 10 lines · Carlos Bilbao

From: Carlos Bilbao <[email protected]>

Initialize speed and duplex for virtio_net_config to UNKNOWN (mlx5_vdpa vDPA devices currently do not support VIRTIO_NET_F_SPEED_DUPLEX). Remove ioctl VHOST_VDPA_SET_CONFIG and its related logic as it is not supported;
see: https://docs.oasis-open.org/virtio/virtio/v1.3/virtio-v1.3.html

Carlos:
vdpa/mlx5: Set speed and duplex of vDPA devices to UNKNOWN
vdpa: Remove ioctl VHOST_VDPA_SET_CONFIG per spec compliance

This will need a rebase. Will apply once you post one. Thanks!

Quoted 32 lines

---

Changes since v1:

- Fix prefix of the first commit and add Reviewed-By tag.
- Redo second commit completely: instead of attempting to add support to set configuration fields, remove ioctl and support entirely from vDPA implementations -- because it's not allowed by spec.

Changes since v2:

- Fix first commit by changing 4 spaces for a tab.
- In second commit, ENI is legacy and should keep set_config(). Change it to set_config_legacy() to avoid future confusion and erroneous implementations.

---
 drivers/vdpa/alibaba/eni_vdpa.c    |  2 +-
 drivers/vdpa/ifcvf/ifcvf_main.c    | 10 ----------
 drivers/vdpa/mlx5/net/mlx5_vnet.c  | 19 ++++++++++++-------
 drivers/vdpa/pds/vdpa_dev.c        | 16 ----------------
 drivers/vdpa/solidrun/snet_main.c  | 18 ------------------
 drivers/vdpa/vdpa.c                | 16 ----------------
 drivers/vdpa/vdpa_sim/vdpa_sim.c   | 16 ----------------
 drivers/vdpa/vdpa_sim/vdpa_sim.h   |  1 -
 drivers/vdpa/vdpa_user/vduse_dev.c |  7 -------
 drivers/vdpa/virtio_pci/vp_vdpa.c  | 14 --------------
 drivers/vhost/vdpa.c               | 26 --------------------------
 drivers/virtio/virtio_vdpa.c       |  9 ---------
 include/linux/vdpa.h               |  7 ++++---
 include/uapi/linux/vhost.h         |  8 ++++----
 14 files changed, 21 insertions(+), 148 deletions(-)
#10 lore raw
Quoted 9 lines · Michael S. Tsirkin
Quoted 7 lines · Carlos Bilbao

From: Carlos Bilbao <[email protected]>

Initialize speed and duplex for virtio_net_config to UNKNOWN (mlx5_vdpa vDPA devices currently do not support VIRTIO_NET_F_SPEED_DUPLEX). Remove ioctl VHOST_VDPA_SET_CONFIG and its related logic as it is not supported;
see: https://docs.oasis-open.org/virtio/virtio/v1.3/virtio-v1.3.html

Quoted 6 lines
Quoted 3 lines

Carlos:
vdpa/mlx5: Set speed and duplex of vDPA devices to UNKNOWN
vdpa: Remove ioctl VHOST_VDPA_SET_CONFIG per spec compliance

This will need a rebase. Will apply once you post one. Thanks!

Note that I think patch 2 is probably not right as we indeed allow config write for some device.

Thanks

#11 lore raw

Hello,

Quoted 9 lines · Jason Wang
Quoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Carlos Bilbao

From: Carlos Bilbao <[email protected]>

Initialize speed and duplex for virtio_net_config to UNKNOWN (mlx5_vdpa vDPA devices currently do not support VIRTIO_NET_F_SPEED_DUPLEX). Remove ioctl VHOST_VDPA_SET_CONFIG and its related logic as it is not supported;
see: https://docs.oasis-open.org/virtio/virtio/v1.3/virtio-v1.3.html

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Carlos:
vdpa/mlx5: Set speed and duplex of vDPA devices to UNKNOWN
vdpa: Remove ioctl VHOST_VDPA_SET_CONFIG per spec compliance

This will need a rebase. Will apply once you post one. Thanks!

Note that I think patch 2 is probably not right as we indeed allow config write for some device.

I'll rebase patch 1 and drop patch 2.

Quoted 3 lines

Thanks

Thanks, Carlos

#12 lore raw
Quoted 17 lines · Carlos Bilbao

Hello,

Quoted 14 lines · Jason Wang
Quoted 13 lines · Michael S. Tsirkin
Quoted 10 lines · Carlos Bilbao

From: Carlos Bilbao <[email protected]>

Initialize speed and duplex for virtio_net_config to UNKNOWN (mlx5_vdpa vDPA devices currently do not support VIRTIO_NET_F_SPEED_DUPLEX). Remove ioctl VHOST_VDPA_SET_CONFIG and its related logic as it is not supported;
see: https://docs.oasis-open.org/virtio/virtio/v1.3/virtio-v1.3.html

Carlos:
vdpa/mlx5: Set speed and duplex of vDPA devices to UNKNOWN
vdpa: Remove ioctl VHOST_VDPA_SET_CONFIG per spec compliance

This will need a rebase. Will apply once you post one. Thanks!

I successfully patched linux-next without any issues. Could you please specify the repo/branch you need me to rebase onto? Thanks in advance

Quoted 10 lines
Quoted 2 lines

Note that I think patch 2 is probably not right as we indeed allow config write for some device.

I'll rebase patch 1 and drop patch 2.

Quoted 2 lines

Thanks

Thanks, Carlos