Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

vdpa_sim: make 'config' generic and usable for any device type

Add new 'config_size' attribute in 'vdpasim_dev_attr' and allocates
'config' dynamically to support any device types.

Acked-by: Jason Wang <jasowang@redhat.com>
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
Link: https://lore.kernel.org/r/20201215144256.155342-12-sgarzare@redhat.com
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

authored by

Stefano Garzarella and committed by
Michael S. Tsirkin
f37cbbc6 cf1a3b35

+13 -4
+13 -4
drivers/vdpa/vdpa_sim/vdpa_sim.c
··· 70 70 71 71 struct vdpasim_dev_attr { 72 72 u64 supported_features; 73 + size_t config_size; 73 74 int nvqs; 74 75 u32 id; 75 76 ··· 85 84 struct vdpasim_dev_attr dev_attr; 86 85 /* spinlock to synchronize virtqueue state */ 87 86 spinlock_t lock; 88 - struct virtio_net_config config; 87 + /* virtio config according to device type */ 88 + void *config; 89 89 struct vhost_iotlb *iommu; 90 90 void *buffer; 91 91 u32 status; ··· 386 384 goto err_iommu; 387 385 set_dma_ops(dev, &vdpasim_dma_ops); 388 386 387 + vdpasim->config = kzalloc(dev_attr->config_size, GFP_KERNEL); 388 + if (!vdpasim->config) 389 + goto err_iommu; 390 + 389 391 vdpasim->vqs = kcalloc(dev_attr->nvqs, sizeof(struct vdpasim_virtqueue), 390 392 GFP_KERNEL); 391 393 if (!vdpasim->vqs) ··· 530 524 static int vdpasim_set_features(struct vdpa_device *vdpa, u64 features) 531 525 { 532 526 struct vdpasim *vdpasim = vdpa_to_sim(vdpa); 533 - struct virtio_net_config *config = &vdpasim->config; 527 + struct virtio_net_config *config = 528 + (struct virtio_net_config *)vdpasim->config; 534 529 535 530 /* DMA mapping must be done by driver */ 536 531 if (!(features & (1ULL << VIRTIO_F_ACCESS_PLATFORM))) ··· 603 596 { 604 597 struct vdpasim *vdpasim = vdpa_to_sim(vdpa); 605 598 606 - if (offset + len < sizeof(struct virtio_net_config)) 607 - memcpy(buf, (u8 *)&vdpasim->config + offset, len); 599 + if (offset + len < vdpasim->dev_attr.config_size) 600 + memcpy(buf, vdpasim->config + offset, len); 608 601 } 609 602 610 603 static void vdpasim_set_config(struct vdpa_device *vdpa, unsigned int offset, ··· 691 684 if (vdpasim->iommu) 692 685 vhost_iotlb_free(vdpasim->iommu); 693 686 kfree(vdpasim->vqs); 687 + kfree(vdpasim->config); 694 688 } 695 689 696 690 static const struct vdpa_config_ops vdpasim_config_ops = { ··· 754 746 dev_attr.id = VIRTIO_ID_NET; 755 747 dev_attr.supported_features = VDPASIM_NET_FEATURES; 756 748 dev_attr.nvqs = VDPASIM_VQ_NUM; 749 + dev_attr.config_size = sizeof(struct virtio_net_config); 757 750 dev_attr.work_fn = vdpasim_net_work; 758 751 759 752 vdpasim_dev = vdpasim_create(&dev_attr);