lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220901101601.61420-4-lingshan.zhu@intel.com>
Date:   Thu,  1 Sep 2022 18:16:00 +0800
From:   Zhu Lingshan <lingshan.zhu@...el.com>
To:     jasowang@...hat.com, mst@...hat.com
Cc:     virtualization@...ts.linux-foundation.org, netdev@...r.kernel.org,
        kvm@...r.kernel.org, Zhu Lingshan <lingshan.zhu@...el.com>
Subject: [RFC 3/4] vDPA: detect device endian in _net_config_fill() and _fill_stats_rec()

This commit detect endian-ness of the device by
vdpa_config_ops.get_vq_endian(), so that functions
vdpa_dev_net_config_fill() and vdpa_fill_stats_rec()
can convert the endian-ness correctly by __virtio16_to_cpu().

Signed-off-by: Zhu Lingshan <lingshan.zhu@...el.com>
---
 drivers/vdpa/vdpa.c | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/drivers/vdpa/vdpa.c b/drivers/vdpa/vdpa.c
index c06c02704461..8a08caf573d1 100644
--- a/drivers/vdpa/vdpa.c
+++ b/drivers/vdpa/vdpa.c
@@ -12,6 +12,7 @@
 #include <linux/slab.h>
 #include <linux/vdpa.h>
 #include <uapi/linux/vdpa.h>
+#include <uapi/linux/vhost.h>
 #include <net/genetlink.h>
 #include <linux/mod_devicetable.h>
 #include <linux/virtio_ids.h>
@@ -814,21 +815,31 @@ static int vdpa_dev_net_mq_config_fill(struct vdpa_device *vdev,
 
 static int vdpa_dev_net_config_fill(struct vdpa_device *vdev, struct sk_buff *msg)
 {
+	const struct vdpa_config_ops *ops = vdev->config;
 	struct virtio_net_config config = {};
 	u64 features;
 	u16 val_u16;
+	u8 le;
 
-	vdpa_get_config_unlocked(vdev, 0, &config, sizeof(config));
+	ops->get_config(vdev, 0, &config, sizeof(config));
+
+	/* endian-ness is a device wide attr, so reading the endian-ness of vq0
+	 * can get the endian-ness of the device config space.
+	 */
+	if (ops->get_vq_endian(vdev, 0) == VHOST_VRING_LITTLE_ENDIAN)
+		le = true;
+	else
+		le = false;
 
 	if (nla_put(msg, VDPA_ATTR_DEV_NET_CFG_MACADDR, sizeof(config.mac),
 		    config.mac))
 		return -EMSGSIZE;
 
-	val_u16 = __virtio16_to_cpu(true, config.status);
+	val_u16 = __virtio16_to_cpu(le, config.status);
 	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_STATUS, val_u16))
 		return -EMSGSIZE;
 
-	val_u16 = __virtio16_to_cpu(true, config.mtu);
+	val_u16 = __virtio16_to_cpu(le, config.mtu);
 	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, val_u16))
 		return -EMSGSIZE;
 
@@ -897,6 +908,7 @@ static int vdpa_fill_stats_rec(struct vdpa_device *vdev, struct sk_buff *msg,
 	u16 max_vqp;
 	u8 status;
 	int err;
+	u8 le;
 
 	status = vdev->config->get_status(vdev);
 	if (!(status & VIRTIO_CONFIG_S_FEATURES_OK)) {
@@ -905,7 +917,15 @@ static int vdpa_fill_stats_rec(struct vdpa_device *vdev, struct sk_buff *msg,
 	}
 	vdpa_get_config_unlocked(vdev, 0, &config, sizeof(config));
 
-	max_vqp = __virtio16_to_cpu(true, config.max_virtqueue_pairs);
+	/* endian-ness is a device wide attr, so reading the endian-ness of vq0
+	 * can get the endian-ness of the device config space.
+	 */
+	if (vdev->config->get_vq_endian(vdev, 0) == VHOST_VRING_LITTLE_ENDIAN)
+		le = true;
+	else
+		le = false;
+
+	max_vqp = __virtio16_to_cpu(le, config.max_virtqueue_pairs);
 	if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MAX_VQP, max_vqp))
 		return -EMSGSIZE;
 
-- 
2.31.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ