[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <c32b4030-fccb-3e77-faf0-a53b8a865563@redhat.com>
Date: Mon, 7 Dec 2020 13:22:42 +0800
From: Jason Wang <jasowang@...hat.com>
To: Stefano Garzarella <sgarzare@...hat.com>,
virtualization@...ts.linux-foundation.org
Cc: Stefan Hajnoczi <stefanha@...hat.com>,
"Michael S. Tsirkin" <mst@...hat.com>, Oren Duer <oren@...dia.com>,
Laurent Vivier <lvivier@...hat.com>,
linux-kernel@...r.kernel.org, Max Gurtovoy <mgurtovoy@...dia.com>,
Shahaf Shuler <shahafs@...dia.com>, Eli Cohen <elic@...dia.com>
Subject: Re: [PATCH v3 12/19] vdpa_sim: make 'config' generic and usable for
any device type
On 2020/12/4 上午1:05, Stefano Garzarella wrote:
> Add new 'config_size' attribute in 'vdpasim_dev_attr' and allocates
> 'config' dynamically to support any device types.
>
> Signed-off-by: Stefano Garzarella <sgarzare@...hat.com>
> ---
> drivers/vdpa/vdpa_sim/vdpa_sim.c | 17 +++++++++++++----
> 1 file changed, 13 insertions(+), 4 deletions(-)
Acked-by: Jason Wang <jasowang@...hat.com>
>
> diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
> index 949f4231d08a..fe71ed7890e1 100644
> --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
> +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
> @@ -62,6 +62,7 @@ struct vdpasim_virtqueue {
>
> struct vdpasim_dev_attr {
> u64 supported_features;
> + size_t config_size;
> int nvqs;
> u32 id;
>
> @@ -76,7 +77,8 @@ struct vdpasim {
> struct vdpasim_dev_attr dev_attr;
> /* spinlock to synchronize virtqueue state */
> spinlock_t lock;
> - struct virtio_net_config config;
> + /* virtio config according to device type */
> + void *config;
> struct vhost_iotlb *iommu;
> void *buffer;
> u32 status;
> @@ -376,6 +378,10 @@ static struct vdpasim *vdpasim_create(struct vdpasim_dev_attr *dev_attr)
> goto err_iommu;
> set_dma_ops(dev, &vdpasim_dma_ops);
>
> + vdpasim->config = kzalloc(dev_attr->config_size, GFP_KERNEL);
> + if (!vdpasim->config)
> + goto err_iommu;
> +
> vdpasim->vqs = kcalloc(dev_attr->nvqs, sizeof(struct vdpasim_virtqueue),
> GFP_KERNEL);
> if (!vdpasim->vqs)
> @@ -516,7 +522,8 @@ 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;
> + struct virtio_net_config *config =
> + (struct virtio_net_config *)vdpasim->config;
>
> /* DMA mapping must be done by driver */
> if (!(features & (1ULL << VIRTIO_F_ACCESS_PLATFORM)))
> @@ -588,8 +595,8 @@ static void vdpasim_get_config(struct vdpa_device *vdpa, unsigned int offset,
> {
> struct vdpasim *vdpasim = vdpa_to_sim(vdpa);
>
> - if (offset + len < sizeof(struct virtio_net_config))
> - memcpy(buf, (u8 *)&vdpasim->config + offset, len);
> + if (offset + len < vdpasim->dev_attr.config_size)
> + memcpy(buf, vdpasim->config + offset, len);
> }
>
> static void vdpasim_set_config(struct vdpa_device *vdpa, unsigned int offset,
> @@ -676,6 +683,7 @@ static void vdpasim_free(struct vdpa_device *vdpa)
> if (vdpasim->iommu)
> vhost_iotlb_free(vdpasim->iommu);
> kfree(vdpasim->vqs);
> + kfree(vdpasim->config);
> }
>
> static const struct vdpa_config_ops vdpasim_config_ops = {
> @@ -738,6 +746,7 @@ static int __init vdpasim_dev_init(void)
> dev_attr.id = VIRTIO_ID_NET;
> dev_attr.supported_features = VDPASIM_NET_FEATURES;
> dev_attr.nvqs = VDPASIM_VQ_NUM;
> + dev_attr.config_size = sizeof(struct virtio_net_config);
> dev_attr.work_fn = vdpasim_net_work;
>
> vdpasim_dev = vdpasim_create(&dev_attr);
Powered by blists - more mailing lists