From: Zhu Lingshan <lingshan.zhu@intel.com>
To: jasowang@redhat.com, mst@redhat.com
Cc: virtualization@lists.linux-foundation.org,
netdev@vger.kernel.org, kvm@vger.kernel.org,
Zhu Lingshan <lingshan.zhu@intel.com>
Subject: [RFC 3/4] vDPA: detect device endian in _net_config_fill() and _fill_stats_rec()
Date: Thu, 1 Sep 2022 18:16:00 +0800 [thread overview]
Message-ID: <20220901101601.61420-4-lingshan.zhu@intel.com> (raw)
In-Reply-To: <20220901101601.61420-1-lingshan.zhu@intel.com>
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@intel.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
next prev parent reply other threads:[~2022-09-01 10:25 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-01 10:15 [RFC 0/4] vDPA: support VHOST_GET/SET_VRING_ENDIAN Zhu Lingshan
2022-09-01 10:15 ` [RFC 1/4] vDPA/ifcvf: add get/set_vq_endian support for vDPA Zhu Lingshan
2022-09-05 8:34 ` Jason Wang
2022-09-06 2:12 ` Zhu, Lingshan
2022-09-01 10:15 ` [RFC 2/4] vDPA: support ioctl VHOST_GET/SET_VRING_ENDIAN Zhu Lingshan
2022-09-01 10:16 ` Zhu Lingshan [this message]
2022-09-01 10:16 ` [RFC 4/4] vDPA: report device endian-ness to userspace through netlink Zhu Lingshan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220901101601.61420-4-lingshan.zhu@intel.com \
--to=lingshan.zhu@intel.com \
--cc=jasowang@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=virtualization@lists.linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).