From: Jason Wang <jasowang@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>, linux-kernel@vger.kernel.org
Cc: virtualization@lists.linux-foundation.org
Subject: Re: [PATCH v2 22/24] vdpa_sim: fix endian-ness of config space
Date: Wed, 5 Aug 2020 14:21:07 +0800 [thread overview]
Message-ID: <dd24f2e6-4aef-4a26-374c-2349fe1e6a66@redhat.com> (raw)
In-Reply-To: <20200803205814.540410-23-mst@redhat.com>
On 2020/8/4 上午5:00, Michael S. Tsirkin wrote:
> VDPA sim accesses config space as native endian - this is
> wrong since it's a modern device and actually uses LE.
>
> It only supports modern guests so we could punt and
> just force LE, but let's use the full virtio APIs since people
> tend to copy/paste code, and this is not data path anyway.
>
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> drivers/vdpa/vdpa_sim/vdpa_sim.c | 31 ++++++++++++++++++++++++++-----
> 1 file changed, 26 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
> index a9bc5e0fb353..fa05e065ff69 100644
> --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
> +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
> @@ -24,6 +24,7 @@
> #include <linux/etherdevice.h>
> #include <linux/vringh.h>
> #include <linux/vdpa.h>
> +#include <linux/virtio_byteorder.h>
> #include <linux/vhost_iotlb.h>
> #include <uapi/linux/virtio_config.h>
> #include <uapi/linux/virtio_net.h>
> @@ -72,6 +73,23 @@ struct vdpasim {
> u64 features;
> };
>
> +/* TODO: cross-endian support */
> +static inline bool vdpasim_is_little_endian(struct vdpasim *vdpasim)
> +{
> + return virtio_legacy_is_little_endian() ||
> + (vdpasim->features & (1ULL << VIRTIO_F_VERSION_1));
> +}
> +
> +static inline u16 vdpasim16_to_cpu(struct vdpasim *vdpasim, __virtio16 val)
> +{
> + return __virtio16_to_cpu(vdpasim_is_little_endian(vdpasim), val);
> +}
> +
> +static inline __virtio16 cpu_to_vdpasim16(struct vdpasim *vdpasim, u16 val)
> +{
> + return __cpu_to_virtio16(vdpasim_is_little_endian(vdpasim), val);
> +}
> +
> static struct vdpasim *vdpasim_dev;
>
> static struct vdpasim *vdpa_to_sim(struct vdpa_device *vdpa)
> @@ -306,7 +324,6 @@ static const struct vdpa_config_ops vdpasim_net_config_ops;
>
> static struct vdpasim *vdpasim_create(void)
> {
> - struct virtio_net_config *config;
> struct vdpasim *vdpasim;
> struct device *dev;
> int ret = -ENOMEM;
> @@ -331,10 +348,7 @@ static struct vdpasim *vdpasim_create(void)
> if (!vdpasim->buffer)
> goto err_iommu;
>
> - config = &vdpasim->config;
> - config->mtu = 1500;
> - config->status = VIRTIO_NET_S_LINK_UP;
> - eth_random_addr(config->mac);
> + eth_random_addr(vdpasim->config.mac);
>
> vringh_set_iotlb(&vdpasim->vqs[0].vring, vdpasim->iommu);
> vringh_set_iotlb(&vdpasim->vqs[1].vring, vdpasim->iommu);
> @@ -448,6 +462,7 @@ static u64 vdpasim_get_features(struct vdpa_device *vdpa)
> static int vdpasim_set_features(struct vdpa_device *vdpa, u64 features)
> {
> struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
> + struct virtio_net_config *config = &vdpasim->config;
>
> /* DMA mapping must be done by driver */
> if (!(features & (1ULL << VIRTIO_F_ACCESS_PLATFORM)))
> @@ -455,6 +470,12 @@ static int vdpasim_set_features(struct vdpa_device *vdpa, u64 features)
>
> vdpasim->features = features & vdpasim_features;
>
> + /* We only know whether guest is using the legacy interface here, so
> + * that's the earliest we can set config fields.
> + */
We check whether or not ACCESS_PLATFORM is set before which is probably
a hint that only modern device is supported. So I wonder just force LE
and fail if VERSION_1 is not set is better?
Thanks
> +
> + config->mtu = cpu_to_vdpasim16(vdpasim, 1500);
> + config->status = cpu_to_vdpasim16(vdpasim, VIRTIO_NET_S_LINK_UP);
> return 0;
> }
>
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
next prev parent reply other threads:[~2020-08-05 6:21 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-03 20:58 [PATCH v2 00/24] virtio: config space endian-ness cleanup Michael S. Tsirkin
2020-08-03 20:58 ` [PATCH v2 01/24] virtio_balloon: fix sparse warning Michael S. Tsirkin
2020-08-03 21:25 ` David Hildenbrand
2020-08-04 14:16 ` Cornelia Huck
2020-08-03 20:58 ` [PATCH v2 02/24] virtio_ring: sparse warning fixup Michael S. Tsirkin
2020-08-04 14:18 ` Cornelia Huck
2020-08-03 20:58 ` [PATCH v2 03/24] virtio: allow __virtioXX, __leXX in config space Michael S. Tsirkin
2020-08-04 14:23 ` Cornelia Huck
2020-08-04 14:28 ` Michael S. Tsirkin
2020-08-05 6:28 ` Jason Wang
2020-08-05 11:45 ` Michael S. Tsirkin
2020-08-06 3:37 ` Jason Wang
2020-08-06 5:58 ` Michael S. Tsirkin
2020-08-07 3:26 ` Jason Wang
2020-08-03 20:58 ` [PATCH v2 04/24] virtio_9p: correct tags for config space fields Michael S. Tsirkin
2020-08-04 14:25 ` Cornelia Huck
2020-08-03 20:58 ` [PATCH v2 05/24] virtio_balloon: " Michael S. Tsirkin
2020-08-03 21:26 ` David Hildenbrand
2020-08-04 14:26 ` Cornelia Huck
2020-08-03 20:58 ` [PATCH v2 06/24] virtio_blk: " Michael S. Tsirkin
2020-08-04 14:29 ` Cornelia Huck
2020-08-03 20:59 ` [PATCH v2 07/24] virtio_console: " Michael S. Tsirkin
2020-08-04 14:31 ` Cornelia Huck
2020-08-03 20:59 ` [PATCH v2 08/24] virtio_crypto: " Michael S. Tsirkin
2020-08-04 14:32 ` Cornelia Huck
2020-08-03 20:59 ` [PATCH v2 09/24] virtio_fs: " Michael S. Tsirkin
2020-08-04 13:36 ` Vivek Goyal
2020-08-04 14:33 ` Cornelia Huck
2020-08-03 20:59 ` [PATCH v2 10/24] virtio_gpu: " Michael S. Tsirkin
2020-08-04 14:34 ` Cornelia Huck
2020-08-03 20:59 ` [PATCH v2 11/24] virtio_input: " Michael S. Tsirkin
2020-08-04 6:01 ` Gerd Hoffmann
2020-08-04 14:35 ` Cornelia Huck
2020-08-03 20:59 ` [PATCH v2 12/24] virtio_iommu: " Michael S. Tsirkin
2020-08-04 8:00 ` Jean-Philippe Brucker
2020-08-04 14:36 ` Cornelia Huck
2020-08-03 20:59 ` [PATCH v2 13/24] virtio_mem: " Michael S. Tsirkin
2020-08-03 21:23 ` David Hildenbrand
2020-08-04 14:37 ` Cornelia Huck
2020-08-03 20:59 ` [PATCH v2 14/24] virtio_net: " Michael S. Tsirkin
2020-08-04 14:44 ` Cornelia Huck
2020-08-05 13:26 ` Michael S. Tsirkin
2020-08-03 20:59 ` [PATCH v2 15/24] virtio_pmem: " Michael S. Tsirkin
2020-08-04 14:46 ` Cornelia Huck
2020-08-03 20:59 ` [PATCH v2 16/24] virtio_scsi: " Michael S. Tsirkin
2020-08-04 14:48 ` Cornelia Huck
2020-08-03 20:59 ` [PATCH v2 17/24] virtio_config: disallow native type fields Michael S. Tsirkin
2020-08-04 14:50 ` Cornelia Huck
2020-08-05 13:29 ` Michael S. Tsirkin
2020-08-03 21:00 ` [PATCH v2 18/24] mlxbf-tmfifo: sparse tags for config access Michael S. Tsirkin
2020-08-04 14:56 ` Cornelia Huck
2020-08-05 13:29 ` Michael S. Tsirkin
2020-08-03 21:00 ` [PATCH v2 19/24] vdpa: make sure set_features in invoked for legacy Michael S. Tsirkin
2020-08-05 6:14 ` Jason Wang
2020-08-05 11:40 ` Michael S. Tsirkin
2020-08-06 3:23 ` Jason Wang
2020-08-06 5:53 ` Michael S. Tsirkin
2020-08-06 7:27 ` Jason Wang
2020-08-06 10:00 ` Michael S. Tsirkin
2020-08-07 3:00 ` Jason Wang
2020-08-03 21:00 ` [PATCH v2 20/24] vhost/vdpa: switch to new helpers Michael S. Tsirkin
2020-08-03 21:00 ` [PATCH v2 21/24] virtio_vdpa: legacy features handling Michael S. Tsirkin
2020-08-03 21:00 ` [PATCH v2 22/24] vdpa_sim: fix endian-ness of config space Michael S. Tsirkin
2020-08-05 6:21 ` Jason Wang [this message]
2020-08-05 11:44 ` Michael S. Tsirkin
2020-08-05 12:06 ` Michael S. Tsirkin
2020-08-06 3:23 ` Jason Wang
2020-08-03 21:00 ` [PATCH v2 23/24] virtio_config: cread/write cleanup Michael S. Tsirkin
2020-08-03 21:00 ` [PATCH v2 24/24] virtio_config: rewrite using _Generic Michael S. Tsirkin
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=dd24f2e6-4aef-4a26-374c-2349fe1e6a66@redhat.com \
--to=jasowang@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mst@redhat.com \
--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).