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: add get_config callback in vdpasim_dev_attr

The get_config callback can be used by the device to fill the
config structure.
The callback will be invoked in vdpasim_get_config() before copying
bytes into caller buffer.

Move vDPA-net config updates from vdpasim_set_features() in the
new vdpasim_net_get_config() callback.
This is safe since in vdpa_get_config() we already check that
.set_features() callback is called before .get_config().

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

authored by

Stefano Garzarella and committed by
Michael S. Tsirkin
65b70958 f37cbbc6

+21 -14
+21 -14
drivers/vdpa/vdpa_sim/vdpa_sim.c
··· 68 68 #define VDPASIM_NET_FEATURES (VDPASIM_FEATURES | \ 69 69 (1ULL << VIRTIO_NET_F_MAC)) 70 70 71 + struct vdpasim; 72 + 71 73 struct vdpasim_dev_attr { 72 74 u64 supported_features; 73 75 size_t config_size; ··· 77 75 u32 id; 78 76 79 77 work_func_t work_fn; 78 + void (*get_config)(struct vdpasim *vdpasim, void *config); 80 79 }; 81 80 82 81 /* State of each vdpasim device */ ··· 533 530 static int vdpasim_set_features(struct vdpa_device *vdpa, u64 features) 534 531 { 535 532 struct vdpasim *vdpasim = vdpa_to_sim(vdpa); 536 - struct virtio_net_config *config = 537 - (struct virtio_net_config *)vdpasim->config; 538 533 539 534 /* DMA mapping must be done by driver */ 540 535 if (!(features & (1ULL << VIRTIO_F_ACCESS_PLATFORM))) 541 536 return -EINVAL; 542 537 543 538 vdpasim->features = features & vdpasim->dev_attr.supported_features; 544 - 545 - /* We generally only know whether guest is using the legacy interface 546 - * here, so generally that's the earliest we can set config fields. 547 - * Note: We actually require VIRTIO_F_ACCESS_PLATFORM above which 548 - * implies VIRTIO_F_VERSION_1, but let's not try to be clever here. 549 - */ 550 - 551 - config->mtu = cpu_to_vdpasim16(vdpasim, 1500); 552 - config->status = cpu_to_vdpasim16(vdpasim, VIRTIO_NET_S_LINK_UP); 553 - memcpy(config->mac, macaddr_buf, ETH_ALEN); 554 539 555 540 return 0; 556 541 } ··· 594 603 { 595 604 struct vdpasim *vdpasim = vdpa_to_sim(vdpa); 596 605 597 - if (offset + len < vdpasim->dev_attr.config_size) 598 - memcpy(buf, vdpasim->config + offset, len); 606 + if (offset + len > vdpasim->dev_attr.config_size) 607 + return; 608 + 609 + if (vdpasim->dev_attr.get_config) 610 + vdpasim->dev_attr.get_config(vdpasim, vdpasim->config); 611 + 612 + memcpy(buf, vdpasim->config + offset, len); 599 613 } 600 614 601 615 static void vdpasim_set_config(struct vdpa_device *vdpa, unsigned int offset, ··· 743 747 .free = vdpasim_free, 744 748 }; 745 749 750 + static void vdpasim_net_get_config(struct vdpasim *vdpasim, void *config) 751 + { 752 + struct virtio_net_config *net_config = 753 + (struct virtio_net_config *)config; 754 + 755 + net_config->mtu = cpu_to_vdpasim16(vdpasim, 1500); 756 + net_config->status = cpu_to_vdpasim16(vdpasim, VIRTIO_NET_S_LINK_UP); 757 + memcpy(net_config->mac, macaddr_buf, ETH_ALEN); 758 + } 759 + 746 760 static int __init vdpasim_dev_init(void) 747 761 { 748 762 struct vdpasim_dev_attr dev_attr = {}; ··· 761 755 dev_attr.supported_features = VDPASIM_NET_FEATURES; 762 756 dev_attr.nvqs = VDPASIM_VQ_NUM; 763 757 dev_attr.config_size = sizeof(struct virtio_net_config); 758 + dev_attr.get_config = vdpasim_net_get_config; 764 759 dev_attr.work_fn = vdpasim_net_work; 765 760 766 761 vdpasim_dev = vdpasim_create(&dev_attr);