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

Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost

Pull virtio updates from Michael Tsirkin:
"virtio,vdpa,qemu_fw_cfg: features, cleanups, and fixes.

- partial support for < MAX_ORDER - 1 granularity for virtio-mem

- driver_override for vdpa

- sysfs ABI documentation for vdpa

- multiqueue config support for mlx5 vdpa

- and misc fixes, cleanups"

* tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost: (42 commits)
vdpa/mlx5: Fix tracking of current number of VQs
vdpa/mlx5: Fix is_index_valid() to refer to features
vdpa: Protect vdpa reset with cf_mutex
vdpa: Avoid taking cf_mutex lock on get status
vdpa/vdpa_sim_net: Report max device capabilities
vdpa: Use BIT_ULL for bit operations
vdpa/vdpa_sim: Configure max supported virtqueues
vdpa/mlx5: Report max device capabilities
vdpa: Support reporting max device capabilities
vdpa/mlx5: Restore cur_num_vqs in case of failure in change_num_qps()
vdpa: Add support for returning device configuration information
vdpa/mlx5: Support configuring max data virtqueue
vdpa/mlx5: Fix config_attr_mask assignment
vdpa: Allow to configure max data virtqueues
vdpa: Read device configuration only if FEATURES_OK
vdpa: Sync calls set/get config/status with cf_mutex
vdpa/mlx5: Distribute RX virtqueues in RQT object
vdpa: Provide interface to read driver features
vdpa: clean up get_config_size ret value handling
virtio_ring: mark ring unused on error
...

+578 -237
+57
Documentation/ABI/testing/sysfs-bus-vdpa
··· 1 + What: /sys/bus/vdpa/driver_autoprobe 2 + Date: March 2020 3 + Contact: virtualization@lists.linux-foundation.org 4 + Description: 5 + This file determines whether new devices are immediately bound 6 + to a driver after the creation. It initially contains 1, which 7 + means the kernel automatically binds devices to a compatible 8 + driver immediately after they are created. 9 + 10 + Writing "0" to this file disable this feature, any other string 11 + enable it. 12 + 13 + What: /sys/bus/vdpa/driver_probe 14 + Date: March 2020 15 + Contact: virtualization@lists.linux-foundation.org 16 + Description: 17 + Writing a device name to this file will cause the kernel binds 18 + devices to a compatible driver. 19 + 20 + This can be useful when /sys/bus/vdpa/driver_autoprobe is 21 + disabled. 22 + 23 + What: /sys/bus/vdpa/drivers/.../bind 24 + Date: March 2020 25 + Contact: virtualization@lists.linux-foundation.org 26 + Description: 27 + Writing a device name to this file will cause the driver to 28 + attempt to bind to the device. This is useful for overriding 29 + default bindings. 30 + 31 + What: /sys/bus/vdpa/drivers/.../unbind 32 + Date: March 2020 33 + Contact: virtualization@lists.linux-foundation.org 34 + Description: 35 + Writing a device name to this file will cause the driver to 36 + attempt to unbind from the device. This may be useful when 37 + overriding default bindings. 38 + 39 + What: /sys/bus/vdpa/devices/.../driver_override 40 + Date: November 2021 41 + Contact: virtualization@lists.linux-foundation.org 42 + Description: 43 + This file allows the driver for a device to be specified. 44 + When specified, only a driver with a name matching the value 45 + written to driver_override will have an opportunity to bind to 46 + the device. The override is specified by writing a string to the 47 + driver_override file (echo vhost-vdpa > driver_override) and may 48 + be cleared with an empty string (echo > driver_override). 49 + This returns the device to standard matching rules binding. 50 + Writing to driver_override does not automatically unbind the 51 + device from its current driver or make any attempt to 52 + automatically load the specified driver. If no driver with a 53 + matching name is currently loaded in the kernel, the device will 54 + not bind to any driver. This also allows devices to opt-out of 55 + driver binding using a driver_override name such as "none". 56 + Only a single driver may be specified in the override, there is 57 + no support for parsing delimiters.
+1
MAINTAINERS
··· 20377 20377 M: Jason Wang <jasowang@redhat.com> 20378 20378 L: virtualization@lists.linux-foundation.org 20379 20379 S: Maintained 20380 + F: Documentation/ABI/testing/sysfs-bus-vdpa 20380 20381 F: Documentation/devicetree/bindings/virtio/ 20381 20382 F: drivers/block/virtio_blk.c 20382 20383 F: drivers/crypto/virtio/
+1 -1
arch/um/drivers/virt-pci.c
··· 616 616 int i; 617 617 618 618 /* Stop all virtqueues */ 619 - vdev->config->reset(vdev); 619 + virtio_reset_device(vdev); 620 620 vdev->config->del_vqs(vdev); 621 621 622 622 device_set_wakeup_enable(&vdev->dev, false);
+2 -2
drivers/block/virtio_blk.c
··· 976 976 mutex_lock(&vblk->vdev_mutex); 977 977 978 978 /* Stop all the virtqueues. */ 979 - vdev->config->reset(vdev); 979 + virtio_reset_device(vdev); 980 980 981 981 /* Virtqueues are stopped, nothing can use vblk->vdev anymore. */ 982 982 vblk->vdev = NULL; ··· 995 995 struct virtio_blk *vblk = vdev->priv; 996 996 997 997 /* Ensure we don't receive any more interrupts */ 998 - vdev->config->reset(vdev); 998 + virtio_reset_device(vdev); 999 999 1000 1000 /* Make sure no work handler is accessing the device. */ 1001 1001 flush_work(&vblk->config_work);
+1 -1
drivers/bluetooth/virtio_bt.c
··· 367 367 struct hci_dev *hdev = vbt->hdev; 368 368 369 369 hci_unregister_dev(hdev); 370 - vdev->config->reset(vdev); 370 + virtio_reset_device(vdev); 371 371 372 372 hci_free_dev(hdev); 373 373 vbt->hdev = NULL;
+1 -1
drivers/char/hw_random/virtio-rng.c
··· 179 179 vi->data_avail = 0; 180 180 vi->data_idx = 0; 181 181 complete(&vi->have_data); 182 - vdev->config->reset(vdev); 183 182 if (vi->hwrng_register_done) 184 183 hwrng_unregister(&vi->hwrng); 184 + virtio_reset_device(vdev); 185 185 vdev->config->del_vqs(vdev); 186 186 ida_simple_remove(&rng_index_ida, vi->index); 187 187 kfree(vi);
+2 -2
drivers/char/virtio_console.c
··· 1958 1958 spin_unlock_irq(&pdrvdata_lock); 1959 1959 1960 1960 /* Disable interrupts for vqs */ 1961 - vdev->config->reset(vdev); 1961 + virtio_reset_device(vdev); 1962 1962 /* Finish up work that's lined up */ 1963 1963 if (use_multiport(portdev)) 1964 1964 cancel_work_sync(&portdev->control_work); ··· 2148 2148 2149 2149 portdev = vdev->priv; 2150 2150 2151 - vdev->config->reset(vdev); 2151 + virtio_reset_device(vdev); 2152 2152 2153 2153 if (use_multiport(portdev)) 2154 2154 virtqueue_disable_cb(portdev->c_ivq);
+4 -4
drivers/crypto/virtio/virtio_crypto_core.c
··· 404 404 free_engines: 405 405 virtcrypto_clear_crypto_engines(vcrypto); 406 406 free_vqs: 407 - vcrypto->vdev->config->reset(vdev); 407 + virtio_reset_device(vdev); 408 408 virtcrypto_del_vqs(vcrypto); 409 409 free_dev: 410 410 virtcrypto_devmgr_rm_dev(vcrypto); ··· 436 436 437 437 if (virtcrypto_dev_started(vcrypto)) 438 438 virtcrypto_dev_stop(vcrypto); 439 - vdev->config->reset(vdev); 439 + virtio_reset_device(vdev); 440 440 virtcrypto_free_unused_reqs(vcrypto); 441 441 virtcrypto_clear_crypto_engines(vcrypto); 442 442 virtcrypto_del_vqs(vcrypto); ··· 456 456 { 457 457 struct virtio_crypto *vcrypto = vdev->priv; 458 458 459 - vdev->config->reset(vdev); 459 + virtio_reset_device(vdev); 460 460 virtcrypto_free_unused_reqs(vcrypto); 461 461 if (virtcrypto_dev_started(vcrypto)) 462 462 virtcrypto_dev_stop(vcrypto); ··· 492 492 free_engines: 493 493 virtcrypto_clear_crypto_engines(vcrypto); 494 494 free_vqs: 495 - vcrypto->vdev->config->reset(vdev); 495 + virtio_reset_device(vdev); 496 496 virtcrypto_del_vqs(vcrypto); 497 497 return err; 498 498 }
+1 -1
drivers/firmware/arm_scmi/virtio.c
··· 452 452 * outstanding message on any vqueue to be ignored by complete_cb: now 453 453 * we can just stop processing buffers and destroy the vqueues. 454 454 */ 455 - vdev->config->reset(vdev); 455 + virtio_reset_device(vdev); 456 456 vdev->config->del_vqs(vdev); 457 457 /* Ensure scmi_vdev is visible as NULL */ 458 458 smp_store_mb(scmi_vdev, NULL);
+1 -1
drivers/gpio/gpio-virtio.c
··· 450 450 451 451 static void virtio_gpio_free_vqs(struct virtio_device *vdev) 452 452 { 453 - vdev->config->reset(vdev); 453 + virtio_reset_device(vdev); 454 454 vdev->config->del_vqs(vdev); 455 455 } 456 456
+1 -1
drivers/gpu/drm/virtio/virtgpu_kms.c
··· 279 279 flush_work(&vgdev->ctrlq.dequeue_work); 280 280 flush_work(&vgdev->cursorq.dequeue_work); 281 281 flush_work(&vgdev->config_changed_work); 282 - vgdev->vdev->config->reset(vgdev->vdev); 282 + virtio_reset_device(vgdev->vdev); 283 283 vgdev->vdev->config->del_vqs(vgdev->vdev); 284 284 } 285 285
+1 -1
drivers/i2c/busses/i2c-virtio.c
··· 165 165 166 166 static void virtio_i2c_del_vqs(struct virtio_device *vdev) 167 167 { 168 - vdev->config->reset(vdev); 168 + virtio_reset_device(vdev); 169 169 vdev->config->del_vqs(vdev); 170 170 } 171 171
+1 -1
drivers/iommu/virtio-iommu.c
··· 1189 1189 iommu_device_unregister(&viommu->iommu); 1190 1190 1191 1191 /* Stop all virtqueues */ 1192 - vdev->config->reset(vdev); 1192 + virtio_reset_device(vdev); 1193 1193 vdev->config->del_vqs(vdev); 1194 1194 1195 1195 dev_info(&vdev->dev, "device removed\n");
+1 -1
drivers/net/caif/caif_virtio.c
··· 754 754 debugfs_remove_recursive(cfv->debugfs); 755 755 756 756 vringh_kiov_cleanup(&cfv->ctx.riov); 757 - vdev->config->reset(vdev); 757 + virtio_reset_device(vdev); 758 758 vdev->vringh_config->del_vrhs(cfv->vdev); 759 759 cfv->vr_rx = NULL; 760 760 vdev->config->del_vqs(cfv->vdev);
+2 -2
drivers/net/virtio_net.c
··· 3312 3312 return 0; 3313 3313 3314 3314 free_unregister_netdev: 3315 - vi->vdev->config->reset(vdev); 3315 + virtio_reset_device(vdev); 3316 3316 3317 3317 unregister_netdev(dev); 3318 3318 free_failover: ··· 3328 3328 3329 3329 static void remove_vq_common(struct virtnet_info *vi) 3330 3330 { 3331 - vi->vdev->config->reset(vi->vdev); 3331 + virtio_reset_device(vi->vdev); 3332 3332 3333 3333 /* Free unused buffers in both send and recv, if any. */ 3334 3334 free_unused_bufs(vi);
+1 -1
drivers/net/wireless/mac80211_hwsim.c
··· 4498 4498 { 4499 4499 int i; 4500 4500 4501 - vdev->config->reset(vdev); 4501 + virtio_reset_device(vdev); 4502 4502 4503 4503 for (i = 0; i < ARRAY_SIZE(hwsim_vqs); i++) { 4504 4504 struct virtqueue *vq = hwsim_vqs[i];
+1 -1
drivers/nvdimm/virtio_pmem.c
··· 105 105 106 106 nvdimm_bus_unregister(nvdimm_bus); 107 107 vdev->config->del_vqs(vdev); 108 - vdev->config->reset(vdev); 108 + virtio_reset_device(vdev); 109 109 } 110 110 111 111 static struct virtio_driver virtio_pmem_driver = {
+1 -1
drivers/rpmsg/virtio_rpmsg_bus.c
··· 1024 1024 size_t total_buf_space = vrp->num_bufs * vrp->buf_size; 1025 1025 int ret; 1026 1026 1027 - vdev->config->reset(vdev); 1027 + virtio_reset_device(vdev); 1028 1028 1029 1029 ret = device_for_each_child(&vdev->dev, NULL, rpmsg_remove_device); 1030 1030 if (ret)
+1 -1
drivers/scsi/virtio_scsi.c
··· 778 778 static void virtscsi_remove_vqs(struct virtio_device *vdev) 779 779 { 780 780 /* Stop all the virtqueues. */ 781 - vdev->config->reset(vdev); 781 + virtio_reset_device(vdev); 782 782 vdev->config->del_vqs(vdev); 783 783 } 784 784
+12 -16
drivers/vdpa/alibaba/eni_vdpa.c
··· 58 58 return &eni_vdpa->ldev; 59 59 } 60 60 61 - static u64 eni_vdpa_get_features(struct vdpa_device *vdpa) 61 + static u64 eni_vdpa_get_device_features(struct vdpa_device *vdpa) 62 62 { 63 63 struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa); 64 64 u64 features = vp_legacy_get_features(ldev); ··· 69 69 return features; 70 70 } 71 71 72 - static int eni_vdpa_set_features(struct vdpa_device *vdpa, u64 features) 72 + static int eni_vdpa_set_driver_features(struct vdpa_device *vdpa, u64 features) 73 73 { 74 74 struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa); 75 75 ··· 82 82 vp_legacy_set_features(ldev, (u32)features); 83 83 84 84 return 0; 85 + } 86 + 87 + static u64 eni_vdpa_get_driver_features(struct vdpa_device *vdpa) 88 + { 89 + struct virtio_pci_legacy_device *ldev = vdpa_to_ldev(vdpa); 90 + 91 + return vp_legacy_get_driver_features(ldev); 85 92 } 86 93 87 94 static u8 eni_vdpa_get_status(struct vdpa_device *vdpa) ··· 408 401 } 409 402 410 403 static const struct vdpa_config_ops eni_vdpa_ops = { 411 - .get_features = eni_vdpa_get_features, 412 - .set_features = eni_vdpa_set_features, 404 + .get_device_features = eni_vdpa_get_device_features, 405 + .set_driver_features = eni_vdpa_set_driver_features, 406 + .get_driver_features = eni_vdpa_get_driver_features, 413 407 .get_status = eni_vdpa_get_status, 414 408 .set_status = eni_vdpa_set_status, 415 409 .reset = eni_vdpa_reset, ··· 458 450 return num; 459 451 } 460 452 461 - static void eni_vdpa_free_irq_vectors(void *data) 462 - { 463 - pci_free_irq_vectors(data); 464 - } 465 - 466 453 static int eni_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id) 467 454 { 468 455 struct device *dev = &pdev->dev; ··· 490 487 491 488 eni_vdpa->vdpa.dma_dev = &pdev->dev; 492 489 eni_vdpa->queues = eni_vdpa_get_num_queues(eni_vdpa); 493 - 494 - ret = devm_add_action_or_reset(dev, eni_vdpa_free_irq_vectors, pdev); 495 - if (ret) { 496 - ENI_ERR(pdev, 497 - "failed for adding devres for freeing irq vectors\n"); 498 - goto err; 499 - } 500 490 501 491 eni_vdpa->vring = devm_kcalloc(&pdev->dev, eni_vdpa->queues, 502 492 sizeof(*eni_vdpa->vring),
+31 -10
drivers/vdpa/ifcvf/ifcvf_base.c
··· 143 143 IFCVF_DBG(pdev, "hw->isr = %p\n", hw->isr); 144 144 break; 145 145 case VIRTIO_PCI_CAP_DEVICE_CFG: 146 - hw->net_cfg = get_cap_addr(hw, &cap); 147 - IFCVF_DBG(pdev, "hw->net_cfg = %p\n", hw->net_cfg); 146 + hw->dev_cfg = get_cap_addr(hw, &cap); 147 + IFCVF_DBG(pdev, "hw->dev_cfg = %p\n", hw->dev_cfg); 148 148 break; 149 149 } 150 150 ··· 153 153 } 154 154 155 155 if (hw->common_cfg == NULL || hw->notify_base == NULL || 156 - hw->isr == NULL || hw->net_cfg == NULL) { 156 + hw->isr == NULL || hw->dev_cfg == NULL) { 157 157 IFCVF_ERR(pdev, "Incomplete PCI capabilities\n"); 158 158 return -EIO; 159 159 } ··· 174 174 IFCVF_DBG(pdev, 175 175 "PCI capability mapping: common cfg: %p, notify base: %p\n, isr cfg: %p, device cfg: %p, multiplier: %u\n", 176 176 hw->common_cfg, hw->notify_base, hw->isr, 177 - hw->net_cfg, hw->notify_off_multiplier); 177 + hw->dev_cfg, hw->notify_off_multiplier); 178 178 179 179 return 0; 180 180 } ··· 242 242 return 0; 243 243 } 244 244 245 - void ifcvf_read_net_config(struct ifcvf_hw *hw, u64 offset, 245 + u32 ifcvf_get_config_size(struct ifcvf_hw *hw) 246 + { 247 + struct ifcvf_adapter *adapter; 248 + u32 config_size; 249 + 250 + adapter = vf_to_adapter(hw); 251 + switch (hw->dev_type) { 252 + case VIRTIO_ID_NET: 253 + config_size = sizeof(struct virtio_net_config); 254 + break; 255 + case VIRTIO_ID_BLOCK: 256 + config_size = sizeof(struct virtio_blk_config); 257 + break; 258 + default: 259 + config_size = 0; 260 + IFCVF_ERR(adapter->pdev, "VIRTIO ID %u not supported\n", hw->dev_type); 261 + } 262 + 263 + return config_size; 264 + } 265 + 266 + void ifcvf_read_dev_config(struct ifcvf_hw *hw, u64 offset, 246 267 void *dst, int length) 247 268 { 248 269 u8 old_gen, new_gen, *p; 249 270 int i; 250 271 251 - WARN_ON(offset + length > sizeof(struct virtio_net_config)); 272 + WARN_ON(offset + length > hw->config_size); 252 273 do { 253 274 old_gen = ifc_ioread8(&hw->common_cfg->config_generation); 254 275 p = dst; 255 276 for (i = 0; i < length; i++) 256 - *p++ = ifc_ioread8(hw->net_cfg + offset + i); 277 + *p++ = ifc_ioread8(hw->dev_cfg + offset + i); 257 278 258 279 new_gen = ifc_ioread8(&hw->common_cfg->config_generation); 259 280 } while (old_gen != new_gen); 260 281 } 261 282 262 - void ifcvf_write_net_config(struct ifcvf_hw *hw, u64 offset, 283 + void ifcvf_write_dev_config(struct ifcvf_hw *hw, u64 offset, 263 284 const void *src, int length) 264 285 { 265 286 const u8 *p; 266 287 int i; 267 288 268 289 p = src; 269 - WARN_ON(offset + length > sizeof(struct virtio_net_config)); 290 + WARN_ON(offset + length > hw->config_size); 270 291 for (i = 0; i < length; i++) 271 - ifc_iowrite8(*p++, hw->net_cfg + offset + i); 292 + ifc_iowrite8(*p++, hw->dev_cfg + offset + i); 272 293 } 273 294 274 295 static void ifcvf_set_features(struct ifcvf_hw *hw, u64 features)
+6 -3
drivers/vdpa/ifcvf/ifcvf_base.h
··· 71 71 u64 hw_features; 72 72 u32 dev_type; 73 73 struct virtio_pci_common_cfg __iomem *common_cfg; 74 - void __iomem *net_cfg; 74 + void __iomem *dev_cfg; 75 75 struct vring_info vring[IFCVF_MAX_QUEUES]; 76 76 void __iomem * const *base; 77 77 char config_msix_name[256]; 78 78 struct vdpa_callback config_cb; 79 79 unsigned int config_irq; 80 + /* virtio-net or virtio-blk device config size */ 81 + u32 config_size; 80 82 }; 81 83 82 84 struct ifcvf_adapter { ··· 107 105 int ifcvf_start_hw(struct ifcvf_hw *hw); 108 106 void ifcvf_stop_hw(struct ifcvf_hw *hw); 109 107 void ifcvf_notify_queue(struct ifcvf_hw *hw, u16 qid); 110 - void ifcvf_read_net_config(struct ifcvf_hw *hw, u64 offset, 108 + void ifcvf_read_dev_config(struct ifcvf_hw *hw, u64 offset, 111 109 void *dst, int length); 112 - void ifcvf_write_net_config(struct ifcvf_hw *hw, u64 offset, 110 + void ifcvf_write_dev_config(struct ifcvf_hw *hw, u64 offset, 113 111 const void *src, int length); 114 112 u8 ifcvf_get_status(struct ifcvf_hw *hw); 115 113 void ifcvf_set_status(struct ifcvf_hw *hw, u8 status); ··· 122 120 int ifcvf_set_vq_state(struct ifcvf_hw *hw, u16 qid, u16 num); 123 121 struct ifcvf_adapter *vf_to_adapter(struct ifcvf_hw *hw); 124 122 int ifcvf_probed_virtio_net(struct ifcvf_hw *hw); 123 + u32 ifcvf_get_config_size(struct ifcvf_hw *hw); 125 124 #endif /* _IFCVF_H_ */
+16 -24
drivers/vdpa/ifcvf/ifcvf_main.c
··· 169 169 return &adapter->vf; 170 170 } 171 171 172 - static u64 ifcvf_vdpa_get_features(struct vdpa_device *vdpa_dev) 172 + static u64 ifcvf_vdpa_get_device_features(struct vdpa_device *vdpa_dev) 173 173 { 174 174 struct ifcvf_adapter *adapter = vdpa_to_adapter(vdpa_dev); 175 175 struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev); ··· 187 187 return features; 188 188 } 189 189 190 - static int ifcvf_vdpa_set_features(struct vdpa_device *vdpa_dev, u64 features) 190 + static int ifcvf_vdpa_set_driver_features(struct vdpa_device *vdpa_dev, u64 features) 191 191 { 192 192 struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev); 193 193 int ret; ··· 199 199 vf->req_features = features; 200 200 201 201 return 0; 202 + } 203 + 204 + static u64 ifcvf_vdpa_get_driver_features(struct vdpa_device *vdpa_dev) 205 + { 206 + struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev); 207 + 208 + return vf->req_features; 202 209 } 203 210 204 211 static u8 ifcvf_vdpa_get_status(struct vdpa_device *vdpa_dev) ··· 373 366 374 367 static size_t ifcvf_vdpa_get_config_size(struct vdpa_device *vdpa_dev) 375 368 { 376 - struct ifcvf_adapter *adapter = vdpa_to_adapter(vdpa_dev); 377 369 struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev); 378 - struct pci_dev *pdev = adapter->pdev; 379 - size_t size; 380 370 381 - switch (vf->dev_type) { 382 - case VIRTIO_ID_NET: 383 - size = sizeof(struct virtio_net_config); 384 - break; 385 - case VIRTIO_ID_BLOCK: 386 - size = sizeof(struct virtio_blk_config); 387 - break; 388 - default: 389 - size = 0; 390 - IFCVF_ERR(pdev, "VIRTIO ID %u not supported\n", vf->dev_type); 391 - } 392 - 393 - return size; 371 + return vf->config_size; 394 372 } 395 373 396 374 static void ifcvf_vdpa_get_config(struct vdpa_device *vdpa_dev, ··· 384 392 { 385 393 struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev); 386 394 387 - WARN_ON(offset + len > sizeof(struct virtio_net_config)); 388 - ifcvf_read_net_config(vf, offset, buf, len); 395 + ifcvf_read_dev_config(vf, offset, buf, len); 389 396 } 390 397 391 398 static void ifcvf_vdpa_set_config(struct vdpa_device *vdpa_dev, ··· 393 402 { 394 403 struct ifcvf_hw *vf = vdpa_to_vf(vdpa_dev); 395 404 396 - WARN_ON(offset + len > sizeof(struct virtio_net_config)); 397 - ifcvf_write_net_config(vf, offset, buf, len); 405 + ifcvf_write_dev_config(vf, offset, buf, len); 398 406 } 399 407 400 408 static void ifcvf_vdpa_set_config_cb(struct vdpa_device *vdpa_dev, ··· 433 443 * implemented set_map()/dma_map()/dma_unmap() 434 444 */ 435 445 static const struct vdpa_config_ops ifc_vdpa_ops = { 436 - .get_features = ifcvf_vdpa_get_features, 437 - .set_features = ifcvf_vdpa_set_features, 446 + .get_device_features = ifcvf_vdpa_get_device_features, 447 + .set_driver_features = ifcvf_vdpa_set_driver_features, 448 + .get_driver_features = ifcvf_vdpa_get_driver_features, 438 449 .get_status = ifcvf_vdpa_get_status, 439 450 .set_status = ifcvf_vdpa_set_status, 440 451 .reset = ifcvf_vdpa_reset, ··· 533 542 vf->vring[i].irq = -EINVAL; 534 543 535 544 vf->hw_features = ifcvf_get_hw_features(vf); 545 + vf->config_size = ifcvf_get_config_size(vf); 536 546 537 547 adapter->vdpa.mdev = &ifcvf_mgmt_dev->mdev; 538 548 ret = _vdpa_register_device(&adapter->vdpa, vf->nr_vring);
+97 -59
drivers/vdpa/mlx5/net/mlx5_vnet.c
··· 131 131 struct mlx5_vq_restore_info ri; 132 132 }; 133 133 134 - /* We will remove this limitation once mlx5_vdpa_alloc_resources() 135 - * provides for driver space allocation 136 - */ 137 - #define MLX5_MAX_SUPPORTED_VQS 16 138 - 139 134 static bool is_index_valid(struct mlx5_vdpa_dev *mvdev, u16 idx) 140 135 { 141 - if (unlikely(idx > mvdev->max_idx)) 142 - return false; 136 + if (!(mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_MQ))) { 137 + if (!(mvdev->actual_features & BIT_ULL(VIRTIO_NET_F_CTRL_VQ))) 138 + return idx < 2; 139 + else 140 + return idx < 3; 141 + } 143 142 144 - return true; 143 + return idx <= mvdev->max_idx; 145 144 } 146 145 147 146 struct mlx5_vdpa_net { 148 147 struct mlx5_vdpa_dev mvdev; 149 148 struct mlx5_vdpa_net_resources res; 150 149 struct virtio_net_config config; 151 - struct mlx5_vdpa_virtqueue vqs[MLX5_MAX_SUPPORTED_VQS]; 152 - struct vdpa_callback event_cbs[MLX5_MAX_SUPPORTED_VQS + 1]; 150 + struct mlx5_vdpa_virtqueue *vqs; 151 + struct vdpa_callback *event_cbs; 153 152 154 153 /* Serialize vq resources creation and destruction. This is required 155 154 * since memory map might change and we need to destroy and create ··· 875 876 MLX5_SET(virtio_q, vq_ctx, umem_3_id, mvq->umem3.id); 876 877 MLX5_SET(virtio_q, vq_ctx, umem_3_size, mvq->umem3.size); 877 878 MLX5_SET(virtio_q, vq_ctx, pd, ndev->mvdev.res.pdn); 878 - if (MLX5_CAP_DEV_VDPA_EMULATION(ndev->mvdev.mdev, eth_frame_offload_type)) 879 - MLX5_SET(virtio_q, vq_ctx, virtio_version_1_0, 1); 880 879 881 880 err = mlx5_cmd_exec(ndev->mvdev.mdev, in, inlen, out, sizeof(out)); 882 881 if (err) ··· 1215 1218 { 1216 1219 int i; 1217 1220 1218 - for (i = 0; i < MLX5_MAX_SUPPORTED_VQS; i++) 1221 + for (i = 0; i < ndev->mvdev.max_vqs; i++) 1219 1222 suspend_vq(ndev, &ndev->vqs[i]); 1220 1223 } 1221 1224 ··· 1241 1244 void *in; 1242 1245 int i, j; 1243 1246 int err; 1247 + int num; 1244 1248 1245 - max_rqt = min_t(int, MLX5_MAX_SUPPORTED_VQS / 2, 1249 + if (!(ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_MQ))) 1250 + num = 1; 1251 + else 1252 + num = ndev->cur_num_vqs / 2; 1253 + 1254 + max_rqt = min_t(int, roundup_pow_of_two(num), 1246 1255 1 << MLX5_CAP_GEN(ndev->mvdev.mdev, log_max_rqt_size)); 1247 1256 if (max_rqt < 1) 1248 1257 return -EOPNOTSUPP; ··· 1264 1261 MLX5_SET(rqtc, rqtc, list_q_type, MLX5_RQTC_LIST_Q_TYPE_VIRTIO_NET_Q); 1265 1262 MLX5_SET(rqtc, rqtc, rqt_max_size, max_rqt); 1266 1263 list = MLX5_ADDR_OF(rqtc, rqtc, rq_num[0]); 1267 - for (i = 0, j = 0; j < max_rqt; j++) { 1268 - if (!ndev->vqs[j].initialized) 1269 - continue; 1264 + for (i = 0, j = 0; i < max_rqt; i++, j += 2) 1265 + list[i] = cpu_to_be32(ndev->vqs[j % (2 * num)].virtq_id); 1270 1266 1271 - if (!vq_is_tx(ndev->vqs[j].index)) { 1272 - list[i] = cpu_to_be32(ndev->vqs[j].virtq_id); 1273 - i++; 1274 - } 1275 - } 1276 - MLX5_SET(rqtc, rqtc, rqt_actual_size, i); 1277 - 1267 + MLX5_SET(rqtc, rqtc, rqt_actual_size, max_rqt); 1278 1268 err = mlx5_vdpa_create_rqt(&ndev->mvdev, in, inlen, &ndev->res.rqtn); 1279 1269 kfree(in); 1280 1270 if (err) ··· 1288 1292 int i, j; 1289 1293 int err; 1290 1294 1291 - max_rqt = min_t(int, ndev->cur_num_vqs / 2, 1295 + max_rqt = min_t(int, roundup_pow_of_two(ndev->cur_num_vqs / 2), 1292 1296 1 << MLX5_CAP_GEN(ndev->mvdev.mdev, log_max_rqt_size)); 1293 1297 if (max_rqt < 1) 1294 1298 return -EOPNOTSUPP; ··· 1304 1308 MLX5_SET(rqtc, rqtc, list_q_type, MLX5_RQTC_LIST_Q_TYPE_VIRTIO_NET_Q); 1305 1309 1306 1310 list = MLX5_ADDR_OF(rqtc, rqtc, rq_num[0]); 1307 - for (i = 0, j = 0; j < num; j++) { 1308 - if (!ndev->vqs[j].initialized) 1309 - continue; 1311 + for (i = 0, j = 0; i < max_rqt; i++, j += 2) 1312 + list[i] = cpu_to_be32(ndev->vqs[j % num].virtq_id); 1310 1313 1311 - if (!vq_is_tx(ndev->vqs[j].index)) { 1312 - list[i] = cpu_to_be32(ndev->vqs[j].virtq_id); 1313 - i++; 1314 - } 1315 - } 1316 - MLX5_SET(rqtc, rqtc, rqt_actual_size, i); 1314 + MLX5_SET(rqtc, rqtc, rqt_actual_size, max_rqt); 1317 1315 err = mlx5_vdpa_modify_rqt(&ndev->mvdev, in, inlen, ndev->res.rqtn); 1318 1316 kfree(in); 1319 1317 if (err) ··· 1544 1554 return 0; 1545 1555 1546 1556 clean_added: 1547 - for (--i; i >= cur_qps; --i) 1557 + for (--i; i >= 2 * cur_qps; --i) 1548 1558 teardown_vq(ndev, &ndev->vqs[i]); 1559 + 1560 + ndev->cur_num_vqs = 2 * cur_qps; 1549 1561 1550 1562 return err; 1551 1563 } ··· 1572 1580 status = VIRTIO_NET_OK; 1573 1581 break; 1574 1582 } 1575 - 1576 - if (newqps & (newqps - 1)) 1577 - break; 1578 1583 1579 1584 if (!change_num_qps(mvdev, newqps)) 1580 1585 status = VIRTIO_NET_OK; ··· 1869 1880 return result; 1870 1881 } 1871 1882 1872 - static u64 mlx5_vdpa_get_features(struct vdpa_device *vdev) 1883 + static u64 get_supported_features(struct mlx5_core_dev *mdev) 1884 + { 1885 + u64 mlx_vdpa_features = 0; 1886 + u16 dev_features; 1887 + 1888 + dev_features = MLX5_CAP_DEV_VDPA_EMULATION(mdev, device_features_bits_mask); 1889 + mlx_vdpa_features |= mlx_to_vritio_features(dev_features); 1890 + if (MLX5_CAP_DEV_VDPA_EMULATION(mdev, virtio_version_1_0)) 1891 + mlx_vdpa_features |= BIT_ULL(VIRTIO_F_VERSION_1); 1892 + mlx_vdpa_features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM); 1893 + mlx_vdpa_features |= BIT_ULL(VIRTIO_NET_F_CTRL_VQ); 1894 + mlx_vdpa_features |= BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR); 1895 + mlx_vdpa_features |= BIT_ULL(VIRTIO_NET_F_MQ); 1896 + mlx_vdpa_features |= BIT_ULL(VIRTIO_NET_F_STATUS); 1897 + mlx_vdpa_features |= BIT_ULL(VIRTIO_NET_F_MTU); 1898 + 1899 + return mlx_vdpa_features; 1900 + } 1901 + 1902 + static u64 mlx5_vdpa_get_device_features(struct vdpa_device *vdev) 1873 1903 { 1874 1904 struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); 1875 1905 struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); 1876 - u16 dev_features; 1877 - 1878 - dev_features = MLX5_CAP_DEV_VDPA_EMULATION(mvdev->mdev, device_features_bits_mask); 1879 - ndev->mvdev.mlx_features |= mlx_to_vritio_features(dev_features); 1880 - if (MLX5_CAP_DEV_VDPA_EMULATION(mvdev->mdev, virtio_version_1_0)) 1881 - ndev->mvdev.mlx_features |= BIT_ULL(VIRTIO_F_VERSION_1); 1882 - ndev->mvdev.mlx_features |= BIT_ULL(VIRTIO_F_ACCESS_PLATFORM); 1883 - ndev->mvdev.mlx_features |= BIT_ULL(VIRTIO_NET_F_CTRL_VQ); 1884 - ndev->mvdev.mlx_features |= BIT_ULL(VIRTIO_NET_F_CTRL_MAC_ADDR); 1885 - ndev->mvdev.mlx_features |= BIT_ULL(VIRTIO_NET_F_MQ); 1886 - ndev->mvdev.mlx_features |= BIT_ULL(VIRTIO_NET_F_STATUS); 1887 1906 1888 1907 print_features(mvdev, ndev->mvdev.mlx_features, false); 1889 1908 return ndev->mvdev.mlx_features; ··· 1969 1972 } 1970 1973 } 1971 1974 1972 - static int mlx5_vdpa_set_features(struct vdpa_device *vdev, u64 features) 1975 + static int mlx5_vdpa_set_driver_features(struct vdpa_device *vdev, u64 features) 1973 1976 { 1974 1977 struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); 1975 1978 struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev); ··· 1982 1985 return err; 1983 1986 1984 1987 ndev->mvdev.actual_features = features & ndev->mvdev.mlx_features; 1988 + if (ndev->mvdev.actual_features & BIT_ULL(VIRTIO_NET_F_MQ)) 1989 + ndev->cur_num_vqs = 2 * mlx5vdpa16_to_cpu(mvdev, ndev->config.max_virtqueue_pairs); 1990 + else 1991 + ndev->cur_num_vqs = 2; 1992 + 1985 1993 update_cvq_info(mvdev); 1986 1994 return err; 1987 1995 } ··· 2237 2235 clear_vqs_ready(ndev); 2238 2236 mlx5_vdpa_destroy_mr(&ndev->mvdev); 2239 2237 ndev->mvdev.status = 0; 2240 - memset(ndev->event_cbs, 0, sizeof(ndev->event_cbs)); 2238 + ndev->cur_num_vqs = 0; 2239 + memset(ndev->event_cbs, 0, sizeof(*ndev->event_cbs) * (mvdev->max_vqs + 1)); 2241 2240 ndev->mvdev.actual_features = 0; 2242 2241 ++mvdev->generation; 2243 2242 if (MLX5_CAP_GEN(mvdev->mdev, umem_uid_0)) { ··· 2311 2308 } 2312 2309 mlx5_vdpa_free_resources(&ndev->mvdev); 2313 2310 mutex_destroy(&ndev->reslock); 2311 + kfree(ndev->event_cbs); 2312 + kfree(ndev->vqs); 2314 2313 } 2315 2314 2316 2315 static struct vdpa_notification_area mlx5_get_vq_notification(struct vdpa_device *vdev, u16 idx) ··· 2344 2339 return -EOPNOTSUPP; 2345 2340 } 2346 2341 2342 + static u64 mlx5_vdpa_get_driver_features(struct vdpa_device *vdev) 2343 + { 2344 + struct mlx5_vdpa_dev *mvdev = to_mvdev(vdev); 2345 + 2346 + return mvdev->actual_features; 2347 + } 2348 + 2347 2349 static const struct vdpa_config_ops mlx5_vdpa_ops = { 2348 2350 .set_vq_address = mlx5_vdpa_set_vq_address, 2349 2351 .set_vq_num = mlx5_vdpa_set_vq_num, ··· 2363 2351 .get_vq_notification = mlx5_get_vq_notification, 2364 2352 .get_vq_irq = mlx5_get_vq_irq, 2365 2353 .get_vq_align = mlx5_vdpa_get_vq_align, 2366 - .get_features = mlx5_vdpa_get_features, 2367 - .set_features = mlx5_vdpa_set_features, 2354 + .get_device_features = mlx5_vdpa_get_device_features, 2355 + .set_driver_features = mlx5_vdpa_set_driver_features, 2356 + .get_driver_features = mlx5_vdpa_get_driver_features, 2368 2357 .set_config_cb = mlx5_vdpa_set_config_cb, 2369 2358 .get_vq_num_max = mlx5_vdpa_get_vq_num_max, 2370 2359 .get_device_id = mlx5_vdpa_get_device_id, ··· 2558 2545 return -EOPNOTSUPP; 2559 2546 } 2560 2547 2561 - /* we save one virtqueue for control virtqueue should we require it */ 2562 2548 max_vqs = MLX5_CAP_DEV_VDPA_EMULATION(mdev, max_num_virtio_queues); 2563 - max_vqs = min_t(u32, max_vqs, MLX5_MAX_SUPPORTED_VQS); 2549 + if (max_vqs < 2) { 2550 + dev_warn(mdev->device, 2551 + "%d virtqueues are supported. At least 2 are required\n", 2552 + max_vqs); 2553 + return -EAGAIN; 2554 + } 2555 + 2556 + if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP)) { 2557 + if (add_config->net.max_vq_pairs > max_vqs / 2) 2558 + return -EINVAL; 2559 + max_vqs = min_t(u32, max_vqs, 2 * add_config->net.max_vq_pairs); 2560 + } else { 2561 + max_vqs = 2; 2562 + } 2564 2563 2565 2564 ndev = vdpa_alloc_device(struct mlx5_vdpa_net, mvdev.vdev, mdev->device, &mlx5_vdpa_ops, 2566 2565 name, false); 2567 2566 if (IS_ERR(ndev)) 2568 2567 return PTR_ERR(ndev); 2569 2568 2569 + ndev->mvdev.mlx_features = mgtdev->mgtdev.supported_features; 2570 2570 ndev->mvdev.max_vqs = max_vqs; 2571 2571 mvdev = &ndev->mvdev; 2572 2572 mvdev->mdev = mdev; 2573 + 2574 + ndev->vqs = kcalloc(max_vqs, sizeof(*ndev->vqs), GFP_KERNEL); 2575 + ndev->event_cbs = kcalloc(max_vqs + 1, sizeof(*ndev->event_cbs), GFP_KERNEL); 2576 + if (!ndev->vqs || !ndev->event_cbs) { 2577 + err = -ENOMEM; 2578 + goto err_alloc; 2579 + } 2580 + 2573 2581 init_mvqs(ndev); 2574 2582 mutex_init(&ndev->reslock); 2575 2583 config = &ndev->config; ··· 2646 2612 2647 2613 ndev->nb.notifier_call = event_handler; 2648 2614 mlx5_notifier_register(mdev, &ndev->nb); 2649 - ndev->cur_num_vqs = 2 * mlx5_vdpa_max_qps(max_vqs); 2650 2615 mvdev->vdev.mdev = &mgtdev->mgtdev; 2651 - err = _vdpa_register_device(&mvdev->vdev, ndev->cur_num_vqs + 1); 2616 + err = _vdpa_register_device(&mvdev->vdev, 2 * mlx5_vdpa_max_qps(max_vqs) + 1); 2652 2617 if (err) 2653 2618 goto err_reg; 2654 2619 ··· 2667 2634 mlx5_mpfs_del_mac(pfmdev, config->mac); 2668 2635 err_mtu: 2669 2636 mutex_destroy(&ndev->reslock); 2637 + err_alloc: 2670 2638 put_device(&mvdev->vdev.dev); 2671 2639 return err; 2672 2640 } ··· 2710 2676 mgtdev->mgtdev.ops = &mdev_ops; 2711 2677 mgtdev->mgtdev.device = mdev->device; 2712 2678 mgtdev->mgtdev.id_table = id_table; 2713 - mgtdev->mgtdev.config_attr_mask = (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR); 2679 + mgtdev->mgtdev.config_attr_mask = BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MACADDR) | 2680 + BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP); 2681 + mgtdev->mgtdev.max_supported_vqs = 2682 + MLX5_CAP_DEV_VDPA_EMULATION(mdev, max_num_virtio_queues) + 1; 2683 + mgtdev->mgtdev.supported_features = get_supported_features(mdev); 2714 2684 mgtdev->madev = madev; 2715 2685 2716 2686 err = vdpa_mgmtdev_register(&mgtdev->mgtdev);
+145 -18
drivers/vdpa/vdpa.c
··· 21 21 static DEFINE_MUTEX(vdpa_dev_mutex); 22 22 static DEFINE_IDA(vdpa_index_ida); 23 23 24 + void vdpa_set_status(struct vdpa_device *vdev, u8 status) 25 + { 26 + mutex_lock(&vdev->cf_mutex); 27 + vdev->config->set_status(vdev, status); 28 + mutex_unlock(&vdev->cf_mutex); 29 + } 30 + EXPORT_SYMBOL(vdpa_set_status); 31 + 24 32 static struct genl_family vdpa_nl_family; 25 33 26 34 static int vdpa_dev_probe(struct device *d) ··· 60 52 drv->remove(vdev); 61 53 } 62 54 55 + static int vdpa_dev_match(struct device *dev, struct device_driver *drv) 56 + { 57 + struct vdpa_device *vdev = dev_to_vdpa(dev); 58 + 59 + /* Check override first, and if set, only use the named driver */ 60 + if (vdev->driver_override) 61 + return strcmp(vdev->driver_override, drv->name) == 0; 62 + 63 + /* Currently devices must be supported by all vDPA bus drivers */ 64 + return 1; 65 + } 66 + 67 + static ssize_t driver_override_store(struct device *dev, 68 + struct device_attribute *attr, 69 + const char *buf, size_t count) 70 + { 71 + struct vdpa_device *vdev = dev_to_vdpa(dev); 72 + const char *driver_override, *old; 73 + char *cp; 74 + 75 + /* We need to keep extra room for a newline */ 76 + if (count >= (PAGE_SIZE - 1)) 77 + return -EINVAL; 78 + 79 + driver_override = kstrndup(buf, count, GFP_KERNEL); 80 + if (!driver_override) 81 + return -ENOMEM; 82 + 83 + cp = strchr(driver_override, '\n'); 84 + if (cp) 85 + *cp = '\0'; 86 + 87 + device_lock(dev); 88 + old = vdev->driver_override; 89 + if (strlen(driver_override)) { 90 + vdev->driver_override = driver_override; 91 + } else { 92 + kfree(driver_override); 93 + vdev->driver_override = NULL; 94 + } 95 + device_unlock(dev); 96 + 97 + kfree(old); 98 + 99 + return count; 100 + } 101 + 102 + static ssize_t driver_override_show(struct device *dev, 103 + struct device_attribute *attr, char *buf) 104 + { 105 + struct vdpa_device *vdev = dev_to_vdpa(dev); 106 + ssize_t len; 107 + 108 + device_lock(dev); 109 + len = snprintf(buf, PAGE_SIZE, "%s\n", vdev->driver_override); 110 + device_unlock(dev); 111 + 112 + return len; 113 + } 114 + static DEVICE_ATTR_RW(driver_override); 115 + 116 + static struct attribute *vdpa_dev_attrs[] = { 117 + &dev_attr_driver_override.attr, 118 + NULL, 119 + }; 120 + 121 + static const struct attribute_group vdpa_dev_group = { 122 + .attrs = vdpa_dev_attrs, 123 + }; 124 + __ATTRIBUTE_GROUPS(vdpa_dev); 125 + 63 126 static struct bus_type vdpa_bus = { 64 127 .name = "vdpa", 128 + .dev_groups = vdpa_dev_groups, 129 + .match = vdpa_dev_match, 65 130 .probe = vdpa_dev_probe, 66 131 .remove = vdpa_dev_remove, 67 132 }; ··· 149 68 150 69 ida_simple_remove(&vdpa_index_ida, vdev->index); 151 70 mutex_destroy(&vdev->cf_mutex); 71 + kfree(vdev->driver_override); 152 72 kfree(vdev); 153 73 } 154 74 ··· 382 300 } 383 301 EXPORT_SYMBOL_GPL(vdpa_mgmtdev_unregister); 384 302 303 + static void vdpa_get_config_unlocked(struct vdpa_device *vdev, 304 + unsigned int offset, 305 + void *buf, unsigned int len) 306 + { 307 + const struct vdpa_config_ops *ops = vdev->config; 308 + 309 + /* 310 + * Config accesses aren't supposed to trigger before features are set. 311 + * If it does happen we assume a legacy guest. 312 + */ 313 + if (!vdev->features_valid) 314 + vdpa_set_features(vdev, 0, true); 315 + ops->get_config(vdev, offset, buf, len); 316 + } 317 + 385 318 /** 386 319 * vdpa_get_config - Get one or more device configuration fields. 387 320 * @vdev: vdpa device to operate on ··· 407 310 void vdpa_get_config(struct vdpa_device *vdev, unsigned int offset, 408 311 void *buf, unsigned int len) 409 312 { 410 - const struct vdpa_config_ops *ops = vdev->config; 411 - 412 313 mutex_lock(&vdev->cf_mutex); 413 - /* 414 - * Config accesses aren't supposed to trigger before features are set. 415 - * If it does happen we assume a legacy guest. 416 - */ 417 - if (!vdev->features_valid) 418 - vdpa_set_features(vdev, 0); 419 - ops->get_config(vdev, offset, buf, len); 314 + vdpa_get_config_unlocked(vdev, offset, buf, len); 420 315 mutex_unlock(&vdev->cf_mutex); 421 316 } 422 317 EXPORT_SYMBOL_GPL(vdpa_get_config); ··· 503 414 err = -EMSGSIZE; 504 415 goto msg_err; 505 416 } 417 + if (nla_put_u32(msg, VDPA_ATTR_DEV_MGMTDEV_MAX_VQS, 418 + mdev->max_supported_vqs)) { 419 + err = -EMSGSIZE; 420 + goto msg_err; 421 + } 422 + if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_SUPPORTED_FEATURES, 423 + mdev->supported_features, VDPA_ATTR_PAD)) { 424 + err = -EMSGSIZE; 425 + goto msg_err; 426 + } 506 427 507 428 genlmsg_end(msg, hdr); 508 429 return 0; ··· 579 480 return msg->len; 580 481 } 581 482 582 - #define VDPA_DEV_NET_ATTRS_MASK ((1 << VDPA_ATTR_DEV_NET_CFG_MACADDR) | \ 583 - (1 << VDPA_ATTR_DEV_NET_CFG_MTU)) 483 + #define VDPA_DEV_NET_ATTRS_MASK (BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MACADDR) | \ 484 + BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU) | \ 485 + BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP)) 584 486 585 487 static int vdpa_nl_cmd_dev_add_set_doit(struct sk_buff *skb, struct genl_info *info) 586 488 { ··· 600 500 if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACADDR]) { 601 501 macaddr = nla_data(nl_attrs[VDPA_ATTR_DEV_NET_CFG_MACADDR]); 602 502 memcpy(config.net.mac, macaddr, sizeof(config.net.mac)); 603 - config.mask |= (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR); 503 + config.mask |= BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MACADDR); 604 504 } 605 505 if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MTU]) { 606 506 config.net.mtu = 607 507 nla_get_u16(nl_attrs[VDPA_ATTR_DEV_NET_CFG_MTU]); 608 - config.mask |= (1 << VDPA_ATTR_DEV_NET_CFG_MTU); 508 + config.mask |= BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MTU); 509 + } 510 + if (nl_attrs[VDPA_ATTR_DEV_NET_CFG_MAX_VQP]) { 511 + config.net.max_vq_pairs = 512 + nla_get_u16(nl_attrs[VDPA_ATTR_DEV_NET_CFG_MAX_VQP]); 513 + if (!config.net.max_vq_pairs) { 514 + NL_SET_ERR_MSG_MOD(info->extack, 515 + "At least one pair of VQs is required"); 516 + return -EINVAL; 517 + } 518 + config.mask |= BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MAX_VQP); 609 519 } 610 520 611 521 /* Skip checking capability if user didn't prefer to configure any ··· 817 707 { 818 708 u16 val_u16; 819 709 820 - if ((features & (1ULL << VIRTIO_NET_F_MQ)) == 0) 710 + if ((features & BIT_ULL(VIRTIO_NET_F_MQ)) == 0) 821 711 return 0; 822 712 823 713 val_u16 = le16_to_cpu(config->max_virtqueue_pairs); ··· 830 720 u64 features; 831 721 u16 val_u16; 832 722 833 - vdpa_get_config(vdev, 0, &config, sizeof(config)); 723 + vdpa_get_config_unlocked(vdev, 0, &config, sizeof(config)); 834 724 835 725 if (nla_put(msg, VDPA_ATTR_DEV_NET_CFG_MACADDR, sizeof(config.mac), 836 726 config.mac)) ··· 844 734 if (nla_put_u16(msg, VDPA_ATTR_DEV_NET_CFG_MTU, val_u16)) 845 735 return -EMSGSIZE; 846 736 847 - features = vdev->config->get_features(vdev); 737 + features = vdev->config->get_driver_features(vdev); 738 + if (nla_put_u64_64bit(msg, VDPA_ATTR_DEV_NEGOTIATED_FEATURES, features, 739 + VDPA_ATTR_PAD)) 740 + return -EMSGSIZE; 848 741 849 742 return vdpa_dev_net_mq_config_fill(vdev, msg, features, &config); 850 743 } ··· 858 745 { 859 746 u32 device_id; 860 747 void *hdr; 748 + u8 status; 861 749 int err; 750 + 751 + mutex_lock(&vdev->cf_mutex); 752 + status = vdev->config->get_status(vdev); 753 + if (!(status & VIRTIO_CONFIG_S_FEATURES_OK)) { 754 + NL_SET_ERR_MSG_MOD(extack, "Features negotiation not completed"); 755 + err = -EAGAIN; 756 + goto out; 757 + } 862 758 863 759 hdr = genlmsg_put(msg, portid, seq, &vdpa_nl_family, flags, 864 760 VDPA_CMD_DEV_CONFIG_GET); 865 - if (!hdr) 866 - return -EMSGSIZE; 761 + if (!hdr) { 762 + err = -EMSGSIZE; 763 + goto out; 764 + } 867 765 868 766 if (nla_put_string(msg, VDPA_ATTR_DEV_NAME, dev_name(&vdev->dev))) { 869 767 err = -EMSGSIZE; ··· 898 774 if (err) 899 775 goto msg_err; 900 776 777 + mutex_unlock(&vdev->cf_mutex); 901 778 genlmsg_end(msg, hdr); 902 779 return 0; 903 780 904 781 msg_err: 905 782 genlmsg_cancel(msg, hdr); 783 + out: 784 + mutex_unlock(&vdev->cf_mutex); 906 785 return err; 907 786 } 908 787
+15 -6
drivers/vdpa/vdpa_sim/vdpa_sim.c
··· 399 399 return VDPASIM_QUEUE_ALIGN; 400 400 } 401 401 402 - static u64 vdpasim_get_features(struct vdpa_device *vdpa) 402 + static u64 vdpasim_get_device_features(struct vdpa_device *vdpa) 403 403 { 404 404 struct vdpasim *vdpasim = vdpa_to_sim(vdpa); 405 405 406 406 return vdpasim->dev_attr.supported_features; 407 407 } 408 408 409 - static int vdpasim_set_features(struct vdpa_device *vdpa, u64 features) 409 + static int vdpasim_set_driver_features(struct vdpa_device *vdpa, u64 features) 410 410 { 411 411 struct vdpasim *vdpasim = vdpa_to_sim(vdpa); 412 412 ··· 417 417 vdpasim->features = features & vdpasim->dev_attr.supported_features; 418 418 419 419 return 0; 420 + } 421 + 422 + static u64 vdpasim_get_driver_features(struct vdpa_device *vdpa) 423 + { 424 + struct vdpasim *vdpasim = vdpa_to_sim(vdpa); 425 + 426 + return vdpasim->features; 420 427 } 421 428 422 429 static void vdpasim_set_config_cb(struct vdpa_device *vdpa, ··· 620 613 .set_vq_state = vdpasim_set_vq_state, 621 614 .get_vq_state = vdpasim_get_vq_state, 622 615 .get_vq_align = vdpasim_get_vq_align, 623 - .get_features = vdpasim_get_features, 624 - .set_features = vdpasim_set_features, 616 + .get_device_features = vdpasim_get_device_features, 617 + .set_driver_features = vdpasim_set_driver_features, 618 + .get_driver_features = vdpasim_get_driver_features, 625 619 .set_config_cb = vdpasim_set_config_cb, 626 620 .get_vq_num_max = vdpasim_get_vq_num_max, 627 621 .get_device_id = vdpasim_get_device_id, ··· 650 642 .set_vq_state = vdpasim_set_vq_state, 651 643 .get_vq_state = vdpasim_get_vq_state, 652 644 .get_vq_align = vdpasim_get_vq_align, 653 - .get_features = vdpasim_get_features, 654 - .set_features = vdpasim_set_features, 645 + .get_device_features = vdpasim_get_device_features, 646 + .set_driver_features = vdpasim_set_driver_features, 647 + .get_driver_features = vdpasim_get_driver_features, 655 648 .set_config_cb = vdpasim_set_config_cb, 656 649 .get_vq_num_max = vdpasim_get_vq_num_max, 657 650 .get_device_id = vdpasim_get_device_id,
+2
drivers/vdpa/vdpa_sim/vdpa_sim_net.c
··· 191 191 .ops = &vdpasim_net_mgmtdev_ops, 192 192 .config_attr_mask = (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR | 193 193 1 << VDPA_ATTR_DEV_NET_CFG_MTU), 194 + .max_supported_vqs = VDPASIM_NET_VQ_NUM, 195 + .supported_features = VDPASIM_NET_FEATURES, 194 196 }; 195 197 196 198 static int __init vdpasim_net_init(void)
+14 -5
drivers/vdpa/vdpa_user/vduse_dev.c
··· 573 573 return dev->vq_align; 574 574 } 575 575 576 - static u64 vduse_vdpa_get_features(struct vdpa_device *vdpa) 576 + static u64 vduse_vdpa_get_device_features(struct vdpa_device *vdpa) 577 577 { 578 578 struct vduse_dev *dev = vdpa_to_vduse(vdpa); 579 579 580 580 return dev->device_features; 581 581 } 582 582 583 - static int vduse_vdpa_set_features(struct vdpa_device *vdpa, u64 features) 583 + static int vduse_vdpa_set_driver_features(struct vdpa_device *vdpa, u64 features) 584 584 { 585 585 struct vduse_dev *dev = vdpa_to_vduse(vdpa); 586 586 587 587 dev->driver_features = features; 588 588 return 0; 589 + } 590 + 591 + static u64 vduse_vdpa_get_driver_features(struct vdpa_device *vdpa) 592 + { 593 + struct vduse_dev *dev = vdpa_to_vduse(vdpa); 594 + 595 + return dev->driver_features; 589 596 } 590 597 591 598 static void vduse_vdpa_set_config_cb(struct vdpa_device *vdpa, ··· 728 721 .set_vq_state = vduse_vdpa_set_vq_state, 729 722 .get_vq_state = vduse_vdpa_get_vq_state, 730 723 .get_vq_align = vduse_vdpa_get_vq_align, 731 - .get_features = vduse_vdpa_get_features, 732 - .set_features = vduse_vdpa_set_features, 724 + .get_device_features = vduse_vdpa_get_device_features, 725 + .set_driver_features = vduse_vdpa_set_driver_features, 726 + .get_driver_features = vduse_vdpa_get_driver_features, 733 727 .set_config_cb = vduse_vdpa_set_config_cb, 734 728 .get_vq_num_max = vduse_vdpa_get_vq_num_max, 735 729 .get_device_id = vduse_vdpa_get_device_id, ··· 1365 1357 err_str: 1366 1358 vduse_dev_destroy(dev); 1367 1359 err: 1368 - kvfree(config_buf); 1369 1360 return ret; 1370 1361 } 1371 1362 ··· 1415 1408 } 1416 1409 config.name[VDUSE_NAME_MAX - 1] = '\0'; 1417 1410 ret = vduse_create_dev(&config, buf, control->api_version); 1411 + if (ret) 1412 + kvfree(buf); 1418 1413 break; 1419 1414 } 1420 1415 case VDUSE_DESTROY_DEV: {
+12 -4
drivers/vdpa/virtio_pci/vp_vdpa.c
··· 53 53 return &vp_vdpa->mdev; 54 54 } 55 55 56 - static u64 vp_vdpa_get_features(struct vdpa_device *vdpa) 56 + static u64 vp_vdpa_get_device_features(struct vdpa_device *vdpa) 57 57 { 58 58 struct virtio_pci_modern_device *mdev = vdpa_to_mdev(vdpa); 59 59 60 60 return vp_modern_get_features(mdev); 61 61 } 62 62 63 - static int vp_vdpa_set_features(struct vdpa_device *vdpa, u64 features) 63 + static int vp_vdpa_set_driver_features(struct vdpa_device *vdpa, u64 features) 64 64 { 65 65 struct virtio_pci_modern_device *mdev = vdpa_to_mdev(vdpa); 66 66 67 67 vp_modern_set_features(mdev, features); 68 68 69 69 return 0; 70 + } 71 + 72 + static u64 vp_vdpa_get_driver_features(struct vdpa_device *vdpa) 73 + { 74 + struct virtio_pci_modern_device *mdev = vdpa_to_mdev(vdpa); 75 + 76 + return vp_modern_get_driver_features(mdev); 70 77 } 71 78 72 79 static u8 vp_vdpa_get_status(struct vdpa_device *vdpa) ··· 422 415 } 423 416 424 417 static const struct vdpa_config_ops vp_vdpa_ops = { 425 - .get_features = vp_vdpa_get_features, 426 - .set_features = vp_vdpa_set_features, 418 + .get_device_features = vp_vdpa_get_device_features, 419 + .set_driver_features = vp_vdpa_set_driver_features, 420 + .get_driver_features = vp_vdpa_get_driver_features, 427 421 .get_status = vp_vdpa_get_status, 428 422 .set_status = vp_vdpa_set_status, 429 423 .reset = vp_vdpa_reset,
+1
drivers/vhost/test.c
··· 166 166 /* We do an extra flush before freeing memory, 167 167 * since jobs can re-queue themselves. */ 168 168 vhost_test_flush(n); 169 + kfree(n->dev.vqs); 169 170 kfree(n); 170 171 return 0; 171 172 }
+6 -6
drivers/vhost/vdpa.c
··· 170 170 * Userspace shouldn't remove status bits unless reset the 171 171 * status to 0. 172 172 */ 173 - if (status != 0 && (ops->get_status(vdpa) & ~status) != 0) 173 + if (status != 0 && (status_old & ~status) != 0) 174 174 return -EINVAL; 175 175 176 176 if ((status_old & VIRTIO_CONFIG_S_DRIVER_OK) && !(status & VIRTIO_CONFIG_S_DRIVER_OK)) ··· 178 178 vhost_vdpa_unsetup_vq_irq(v, i); 179 179 180 180 if (status == 0) { 181 - ret = ops->reset(vdpa); 181 + ret = vdpa_reset(vdpa); 182 182 if (ret) 183 183 return ret; 184 184 } else 185 - ops->set_status(vdpa, status); 185 + vdpa_set_status(vdpa, status); 186 186 187 187 if ((status & VIRTIO_CONFIG_S_DRIVER_OK) && !(status_old & VIRTIO_CONFIG_S_DRIVER_OK)) 188 188 for (i = 0; i < nvqs; i++) ··· 195 195 struct vhost_vdpa_config *c) 196 196 { 197 197 struct vdpa_device *vdpa = v->vdpa; 198 - long size = vdpa->config->get_config_size(vdpa); 198 + size_t size = vdpa->config->get_config_size(vdpa); 199 199 200 200 if (c->len == 0 || c->off > size) 201 201 return -EINVAL; ··· 262 262 const struct vdpa_config_ops *ops = vdpa->config; 263 263 u64 features; 264 264 265 - features = ops->get_features(vdpa); 265 + features = ops->get_device_features(vdpa); 266 266 267 267 if (copy_to_user(featurep, &features, sizeof(features))) 268 268 return -EFAULT; ··· 286 286 if (copy_from_user(&features, featurep, sizeof(features))) 287 287 return -EFAULT; 288 288 289 - if (vdpa_set_features(vdpa, features)) 289 + if (vdpa_set_features(vdpa, features, false)) 290 290 return -EINVAL; 291 291 292 292 return 0;
+6
drivers/virtio/virtio.c
··· 204 204 } 205 205 EXPORT_SYMBOL_GPL(virtio_finalize_features); 206 206 207 + void virtio_reset_device(struct virtio_device *dev) 208 + { 209 + dev->config->reset(dev); 210 + } 211 + EXPORT_SYMBOL_GPL(virtio_reset_device); 212 + 207 213 static int virtio_dev_probe(struct device *_d) 208 214 { 209 215 int err, i;
+1 -1
drivers/virtio/virtio_balloon.c
··· 1056 1056 return_free_pages_to_mm(vb, ULONG_MAX); 1057 1057 1058 1058 /* Now we reset the device so we can clean up the queues. */ 1059 - vb->vdev->config->reset(vb->vdev); 1059 + virtio_reset_device(vb->vdev); 1060 1060 1061 1061 vb->vdev->config->del_vqs(vb->vdev); 1062 1062 }
+1 -1
drivers/virtio/virtio_input.c
··· 347 347 spin_unlock_irqrestore(&vi->lock, flags); 348 348 349 349 input_unregister_device(vi->idev); 350 - vdev->config->reset(vdev); 350 + virtio_reset_device(vdev); 351 351 while ((buf = virtqueue_detach_unused_buf(vi->sts)) != NULL) 352 352 kfree(buf); 353 353 vdev->config->del_vqs(vdev);
+76 -38
drivers/virtio/virtio_mem.c
··· 20 20 #include <linux/mutex.h> 21 21 #include <linux/bitmap.h> 22 22 #include <linux/lockdep.h> 23 + #include <linux/log2.h> 23 24 24 25 #include <acpi/acpi_numa.h> 25 26 ··· 593 592 return -ENOMEM; 594 593 595 594 mutex_lock(&vm->hotplug_mutex); 596 - if (new_bitmap) 595 + if (vm->sbm.sb_states) 597 596 memcpy(new_bitmap, vm->sbm.sb_states, old_pages * PAGE_SIZE); 598 597 599 598 old_bitmap = vm->sbm.sb_states; ··· 1121 1120 */ 1122 1121 static void virtio_mem_fake_online(unsigned long pfn, unsigned long nr_pages) 1123 1122 { 1124 - const unsigned long max_nr_pages = MAX_ORDER_NR_PAGES; 1123 + unsigned long order = MAX_ORDER - 1; 1125 1124 unsigned long i; 1126 1125 1127 1126 /* 1128 - * We are always called at least with MAX_ORDER_NR_PAGES 1129 - * granularity/alignment (e.g., the way subblocks work). All pages 1130 - * inside such a block are alike. 1127 + * We might get called for ranges that don't cover properly aligned 1128 + * MAX_ORDER - 1 pages; however, we can only online properly aligned 1129 + * pages with an order of MAX_ORDER - 1 at maximum. 1131 1130 */ 1132 - for (i = 0; i < nr_pages; i += max_nr_pages) { 1131 + while (!IS_ALIGNED(pfn | nr_pages, 1 << order)) 1132 + order--; 1133 + 1134 + for (i = 0; i < nr_pages; i += 1 << order) { 1133 1135 struct page *page = pfn_to_page(pfn + i); 1134 1136 1135 1137 /* ··· 1142 1138 * alike. 1143 1139 */ 1144 1140 if (PageDirty(page)) { 1145 - virtio_mem_clear_fake_offline(pfn + i, max_nr_pages, 1146 - false); 1147 - generic_online_page(page, MAX_ORDER - 1); 1141 + virtio_mem_clear_fake_offline(pfn + i, 1 << order, false); 1142 + generic_online_page(page, order); 1148 1143 } else { 1149 - virtio_mem_clear_fake_offline(pfn + i, max_nr_pages, 1150 - true); 1151 - free_contig_range(pfn + i, max_nr_pages); 1152 - adjust_managed_page_count(page, max_nr_pages); 1144 + virtio_mem_clear_fake_offline(pfn + i, 1 << order, true); 1145 + free_contig_range(pfn + i, 1 << order); 1146 + adjust_managed_page_count(page, 1 << order); 1153 1147 } 1154 1148 } 1155 1149 } ··· 1230 1228 page_ref_inc(pfn_to_page(pfn + i)); 1231 1229 } 1232 1230 1233 - static void virtio_mem_online_page_cb(struct page *page, unsigned int order) 1231 + static void virtio_mem_online_page(struct virtio_mem *vm, 1232 + struct page *page, unsigned int order) 1234 1233 { 1235 - const unsigned long addr = page_to_phys(page); 1236 - unsigned long id, sb_id; 1237 - struct virtio_mem *vm; 1234 + const unsigned long start = page_to_phys(page); 1235 + const unsigned long end = start + PFN_PHYS(1 << order); 1236 + unsigned long addr, next, id, sb_id, count; 1238 1237 bool do_online; 1239 1238 1240 - rcu_read_lock(); 1241 - list_for_each_entry_rcu(vm, &virtio_mem_devices, next) { 1242 - if (!virtio_mem_contains_range(vm, addr, PFN_PHYS(1 << order))) 1243 - continue; 1239 + /* 1240 + * We can get called with any order up to MAX_ORDER - 1. If our 1241 + * subblock size is smaller than that and we have a mixture of plugged 1242 + * and unplugged subblocks within such a page, we have to process in 1243 + * smaller granularity. In that case we'll adjust the order exactly once 1244 + * within the loop. 1245 + */ 1246 + for (addr = start; addr < end; ) { 1247 + next = addr + PFN_PHYS(1 << order); 1244 1248 1245 1249 if (vm->in_sbm) { 1246 - /* 1247 - * We exploit here that subblocks have at least 1248 - * MAX_ORDER_NR_PAGES size/alignment - so we cannot 1249 - * cross subblocks within one call. 1250 - */ 1251 1250 id = virtio_mem_phys_to_mb_id(addr); 1252 1251 sb_id = virtio_mem_phys_to_sb_id(vm, addr); 1253 - do_online = virtio_mem_sbm_test_sb_plugged(vm, id, 1254 - sb_id, 1); 1252 + count = virtio_mem_phys_to_sb_id(vm, next - 1) - sb_id + 1; 1253 + 1254 + if (virtio_mem_sbm_test_sb_plugged(vm, id, sb_id, count)) { 1255 + /* Fully plugged. */ 1256 + do_online = true; 1257 + } else if (count == 1 || 1258 + virtio_mem_sbm_test_sb_unplugged(vm, id, sb_id, count)) { 1259 + /* Fully unplugged. */ 1260 + do_online = false; 1261 + } else { 1262 + /* 1263 + * Mixture, process sub-blocks instead. This 1264 + * will be at least the size of a pageblock. 1265 + * We'll run into this case exactly once. 1266 + */ 1267 + order = ilog2(vm->sbm.sb_size) - PAGE_SHIFT; 1268 + do_online = virtio_mem_sbm_test_sb_plugged(vm, id, sb_id, 1); 1269 + continue; 1270 + } 1255 1271 } else { 1256 1272 /* 1257 1273 * If the whole block is marked fake offline, keep ··· 1280 1260 VIRTIO_MEM_BBM_BB_FAKE_OFFLINE; 1281 1261 } 1282 1262 1263 + if (do_online) 1264 + generic_online_page(pfn_to_page(PFN_DOWN(addr)), order); 1265 + else 1266 + virtio_mem_set_fake_offline(PFN_DOWN(addr), 1 << order, 1267 + false); 1268 + addr = next; 1269 + } 1270 + } 1271 + 1272 + static void virtio_mem_online_page_cb(struct page *page, unsigned int order) 1273 + { 1274 + const unsigned long addr = page_to_phys(page); 1275 + struct virtio_mem *vm; 1276 + 1277 + rcu_read_lock(); 1278 + list_for_each_entry_rcu(vm, &virtio_mem_devices, next) { 1283 1279 /* 1284 - * virtio_mem_set_fake_offline() might sleep, we don't need 1285 - * the device anymore. See virtio_mem_remove() how races 1280 + * Pages we're onlining will never cross memory blocks and, 1281 + * therefore, not virtio-mem devices. 1282 + */ 1283 + if (!virtio_mem_contains_range(vm, addr, PFN_PHYS(1 << order))) 1284 + continue; 1285 + 1286 + /* 1287 + * virtio_mem_set_fake_offline() might sleep. We can safely 1288 + * drop the RCU lock at this point because the device 1289 + * cannot go away. See virtio_mem_remove() how races 1286 1290 * between memory onlining and device removal are handled. 1287 1291 */ 1288 1292 rcu_read_unlock(); 1289 1293 1290 - if (do_online) 1291 - generic_online_page(page, order); 1292 - else 1293 - virtio_mem_set_fake_offline(PFN_DOWN(addr), 1 << order, 1294 - false); 1294 + virtio_mem_online_page(vm, page, order); 1295 1295 return; 1296 1296 } 1297 1297 rcu_read_unlock(); ··· 2478 2438 /* 2479 2439 * We want subblocks to span at least MAX_ORDER_NR_PAGES and 2480 2440 * pageblock_nr_pages pages. This: 2481 - * - Simplifies our page onlining code (virtio_mem_online_page_cb) 2482 - * and fake page onlining code (virtio_mem_fake_online). 2483 2441 * - Is required for now for alloc_contig_range() to work reliably - 2484 2442 * it doesn't properly handle smaller granularity on ZONE_NORMAL. 2485 2443 */ ··· 2888 2850 virtio_mem_deinit_hotplug(vm); 2889 2851 2890 2852 /* reset the device and cleanup the queues */ 2891 - vdev->config->reset(vdev); 2853 + virtio_reset_device(vdev); 2892 2854 vdev->config->del_vqs(vdev); 2893 2855 2894 2856 kfree(vm);
+1 -1
drivers/virtio/virtio_pci_legacy.c
··· 138 138 q_pfn = virtqueue_get_desc_addr(vq) >> VIRTIO_PCI_QUEUE_ADDR_SHIFT; 139 139 if (q_pfn >> 32) { 140 140 dev_err(&vp_dev->pci_dev->dev, 141 - "platform bug: legacy virtio-mmio must not be used with RAM above 0x%llxGB\n", 141 + "platform bug: legacy virtio-pci must not be used with RAM above 0x%llxGB\n", 142 142 0x1ULL << (32 + PAGE_SHIFT - 30)); 143 143 err = -E2BIG; 144 144 goto out_del_vq;
+3 -1
drivers/virtio/virtio_pci_legacy_dev.c
··· 45 45 return rc; 46 46 47 47 ldev->ioaddr = pci_iomap(pci_dev, 0, 0); 48 - if (!ldev->ioaddr) 48 + if (!ldev->ioaddr) { 49 + rc = -EIO; 49 50 goto err_iomap; 51 + } 50 52 51 53 ldev->isr = ldev->ioaddr + VIRTIO_PCI_ISR; 52 54
+1 -1
drivers/virtio/virtio_pci_modern_dev.c
··· 345 345 EXPORT_SYMBOL_GPL(vp_modern_probe); 346 346 347 347 /* 348 - * vp_modern_probe: remove and cleanup the modern virtio pci device 348 + * vp_modern_remove: remove and cleanup the modern virtio pci device 349 349 * @mdev: the modern virtio-pci device 350 350 */ 351 351 void vp_modern_remove(struct virtio_pci_modern_device *mdev)
+3 -1
drivers/virtio/virtio_ring.c
··· 1197 1197 if (virtqueue_use_indirect(_vq, total_sg)) { 1198 1198 err = virtqueue_add_indirect_packed(vq, sgs, total_sg, out_sgs, 1199 1199 in_sgs, data, gfp); 1200 - if (err != -ENOMEM) 1200 + if (err != -ENOMEM) { 1201 + END_USE(vq); 1201 1202 return err; 1203 + } 1202 1204 1203 1205 /* fall back on direct */ 1204 1206 }
+3 -4
drivers/virtio/virtio_vdpa.c
··· 91 91 static void virtio_vdpa_set_status(struct virtio_device *vdev, u8 status) 92 92 { 93 93 struct vdpa_device *vdpa = vd_get_vdpa(vdev); 94 - const struct vdpa_config_ops *ops = vdpa->config; 95 94 96 - return ops->set_status(vdpa, status); 95 + return vdpa_set_status(vdpa, status); 97 96 } 98 97 99 98 static void virtio_vdpa_reset(struct virtio_device *vdev) ··· 307 308 struct vdpa_device *vdpa = vd_get_vdpa(vdev); 308 309 const struct vdpa_config_ops *ops = vdpa->config; 309 310 310 - return ops->get_features(vdpa); 311 + return ops->get_device_features(vdpa); 311 312 } 312 313 313 314 static int virtio_vdpa_finalize_features(struct virtio_device *vdev) ··· 317 318 /* Give virtio_ring a chance to accept features. */ 318 319 vring_transport_features(vdev); 319 320 320 - return vdpa_set_features(vdpa, vdev->features); 321 + return vdpa_set_features(vdpa, vdev->features, false); 321 322 } 322 323 323 324 static const char *virtio_vdpa_bus_name(struct virtio_device *vdev)
+2 -2
fs/fuse/virtio_fs.c
··· 891 891 return 0; 892 892 893 893 out_vqs: 894 - vdev->config->reset(vdev); 894 + virtio_reset_device(vdev); 895 895 virtio_fs_cleanup_vqs(vdev, fs); 896 896 kfree(fs->vqs); 897 897 ··· 923 923 list_del_init(&fs->list); 924 924 virtio_fs_stop_all_queues(fs); 925 925 virtio_fs_drain_all_queues_locked(fs); 926 - vdev->config->reset(vdev); 926 + virtio_reset_device(vdev); 927 927 virtio_fs_cleanup_vqs(vdev, fs); 928 928 929 929 vdev->priv = NULL;
+31 -8
include/linux/vdpa.h
··· 64 64 * struct vdpa_device - representation of a vDPA device 65 65 * @dev: underlying device 66 66 * @dma_dev: the actual device that is performing DMA 67 + * @driver_override: driver name to force a match 67 68 * @config: the configuration ops for this device. 68 69 * @cf_mutex: Protects get and set access to configuration layout. 69 70 * @index: device index ··· 77 76 struct vdpa_device { 78 77 struct device dev; 79 78 struct device *dma_dev; 79 + const char *driver_override; 80 80 const struct vdpa_config_ops *config; 81 81 struct mutex cf_mutex; /* Protects get/set config */ 82 82 unsigned int index; ··· 101 99 struct { 102 100 u8 mac[ETH_ALEN]; 103 101 u16 mtu; 102 + u16 max_vq_pairs; 104 103 } net; 105 104 u64 mask; 106 105 }; ··· 158 155 * @vdev: vdpa device 159 156 * @idx: virtqueue index 160 157 * @state: pointer to returned state (last_avail_idx) 161 - * @get_vq_notification: Get the notification area for a virtqueue 158 + * @get_vq_notification: Get the notification area for a virtqueue (optional) 162 159 * @vdev: vdpa device 163 160 * @idx: virtqueue index 164 161 * Returns the notifcation area ··· 172 169 * for the device 173 170 * @vdev: vdpa device 174 171 * Returns virtqueue algin requirement 175 - * @get_features: Get virtio features supported by the device 172 + * @get_device_features: Get virtio features supported by the device 176 173 * @vdev: vdpa device 177 174 * Returns the virtio features support by the 178 175 * device 179 - * @set_features: Set virtio features supported by the driver 176 + * @set_driver_features: Set virtio features supported by the driver 180 177 * @vdev: vdpa device 181 178 * @features: feature support by the driver 182 179 * Returns integer: success (0) or error (< 0) 180 + * @get_driver_features: Get the virtio driver features in action 181 + * @vdev: vdpa device 182 + * Returns the virtio features accepted 183 183 * @set_config_cb: Set the config interrupt callback 184 184 * @vdev: vdpa device 185 185 * @cb: virtio-vdev interrupt callback structure ··· 282 276 283 277 /* Device ops */ 284 278 u32 (*get_vq_align)(struct vdpa_device *vdev); 285 - u64 (*get_features)(struct vdpa_device *vdev); 286 - int (*set_features)(struct vdpa_device *vdev, u64 features); 279 + u64 (*get_device_features)(struct vdpa_device *vdev); 280 + int (*set_driver_features)(struct vdpa_device *vdev, u64 features); 281 + u64 (*get_driver_features)(struct vdpa_device *vdev); 287 282 void (*set_config_cb)(struct vdpa_device *vdev, 288 283 struct vdpa_callback *cb); 289 284 u16 (*get_vq_num_max)(struct vdpa_device *vdev); ··· 392 385 static inline int vdpa_reset(struct vdpa_device *vdev) 393 386 { 394 387 const struct vdpa_config_ops *ops = vdev->config; 388 + int ret; 395 389 390 + mutex_lock(&vdev->cf_mutex); 396 391 vdev->features_valid = false; 397 - return ops->reset(vdev); 392 + ret = ops->reset(vdev); 393 + mutex_unlock(&vdev->cf_mutex); 394 + return ret; 398 395 } 399 396 400 - static inline int vdpa_set_features(struct vdpa_device *vdev, u64 features) 397 + static inline int vdpa_set_features(struct vdpa_device *vdev, u64 features, bool locked) 401 398 { 402 399 const struct vdpa_config_ops *ops = vdev->config; 400 + int ret; 401 + 402 + if (!locked) 403 + mutex_lock(&vdev->cf_mutex); 403 404 404 405 vdev->features_valid = true; 405 - return ops->set_features(vdev, features); 406 + ret = ops->set_driver_features(vdev, features); 407 + if (!locked) 408 + mutex_unlock(&vdev->cf_mutex); 409 + 410 + return ret; 406 411 } 407 412 408 413 void vdpa_get_config(struct vdpa_device *vdev, unsigned int offset, 409 414 void *buf, unsigned int len); 410 415 void vdpa_set_config(struct vdpa_device *dev, unsigned int offset, 411 416 const void *buf, unsigned int length); 417 + void vdpa_set_status(struct vdpa_device *vdev, u8 status); 418 + 412 419 /** 413 420 * struct vdpa_mgmtdev_ops - vdpa device ops 414 421 * @dev_add: Add a vdpa device using alloc and register ··· 459 438 const struct virtio_device_id *id_table; 460 439 u64 config_attr_mask; 461 440 struct list_head list; 441 + u64 supported_features; 442 + u32 max_supported_vqs; 462 443 }; 463 444 464 445 int vdpa_mgmtdev_register(struct vdpa_mgmt_dev *mdev);
+1
include/linux/virtio.h
··· 138 138 int virtio_device_freeze(struct virtio_device *dev); 139 139 int virtio_device_restore(struct virtio_device *dev); 140 140 #endif 141 + void virtio_reset_device(struct virtio_device *dev); 141 142 142 143 size_t virtio_max_dma_size(struct virtio_device *vdev); 143 144
+6
include/uapi/linux/vdpa.h
··· 23 23 enum vdpa_attr { 24 24 VDPA_ATTR_UNSPEC, 25 25 26 + /* Pad attribute for 64b alignment */ 27 + VDPA_ATTR_PAD = VDPA_ATTR_UNSPEC, 28 + 26 29 /* bus name (optional) + dev name together make the parent device handle */ 27 30 VDPA_ATTR_MGMTDEV_BUS_NAME, /* string */ 28 31 VDPA_ATTR_MGMTDEV_DEV_NAME, /* string */ ··· 43 40 VDPA_ATTR_DEV_NET_CFG_MAX_VQP, /* u16 */ 44 41 VDPA_ATTR_DEV_NET_CFG_MTU, /* u16 */ 45 42 43 + VDPA_ATTR_DEV_NEGOTIATED_FEATURES, /* u64 */ 44 + VDPA_ATTR_DEV_MGMTDEV_MAX_VQS, /* u32 */ 45 + VDPA_ATTR_DEV_SUPPORTED_FEATURES, /* u64 */ 46 46 /* new attributes must be added above here */ 47 47 VDPA_ATTR_MAX, 48 48 };
+1 -1
net/9p/trans_virtio.c
··· 721 721 722 722 mutex_unlock(&virtio_9p_lock); 723 723 724 - vdev->config->reset(vdev); 724 + virtio_reset_device(vdev); 725 725 vdev->config->del_vqs(vdev); 726 726 727 727 sysfs_remove_file(&(vdev->dev.kobj), &dev_attr_mount_tag.attr);
+2 -2
net/vmw_vsock/virtio_transport.c
··· 665 665 vsock_for_each_connected_socket(virtio_vsock_reset_sock); 666 666 667 667 /* Stop all work handlers to make sure no one is accessing the device, 668 - * so we can safely call vdev->config->reset(). 668 + * so we can safely call virtio_reset_device(). 669 669 */ 670 670 mutex_lock(&vsock->rx_lock); 671 671 vsock->rx_run = false; ··· 682 682 /* Flush all device writes and interrupts, device will not use any 683 683 * more buffers. 684 684 */ 685 - vdev->config->reset(vdev); 685 + virtio_reset_device(vdev); 686 686 687 687 mutex_lock(&vsock->rx_lock); 688 688 while ((pkt = virtqueue_detach_unused_buf(vsock->vqs[VSOCK_VQ_RX])))
+2 -2
sound/virtio/virtio_card.c
··· 350 350 snd_card_free(snd->card); 351 351 352 352 vdev->config->del_vqs(vdev); 353 - vdev->config->reset(vdev); 353 + virtio_reset_device(vdev); 354 354 355 355 for (i = 0; snd->substreams && i < snd->nsubstreams; ++i) { 356 356 struct virtio_pcm_substream *vss = &snd->substreams[i]; ··· 379 379 virtsnd_ctl_msg_cancel_all(snd); 380 380 381 381 vdev->config->del_vqs(vdev); 382 - vdev->config->reset(vdev); 382 + virtio_reset_device(vdev); 383 383 384 384 for (i = 0; i < snd->nsubstreams; ++i) 385 385 cancel_work_sync(&snd->substreams[i].elapsed_period);