ASID support in vhost-vdpa net
Subsystems (3)
v3 cover ASID support in vhost-vdpa net
Control VQ is the way net devices use to send changes to the device state, like the number of active queues or its mac address.
QEMU needs to intercept this queue so it can track these changes and is able to migrate the device. It can do it from 1576dbb5bbc4 ("vdpa: Add x-svq to NetdevVhostVDPAOptions"). However, to enable x-svq implies to shadow all VirtIO device's virtqueues, which will damage performance.
This series adds address space isolation, so the device and the guest communicate directly with them (passthrough) and CVQ communication is split in
two: The guest communicates with QEMU and QEMU forwards the commands to the device.
This series is based on [1], and this needs to be applied on top of that. Each one of them adds a feature on isolation and could be merged individually once conflicts are solved.
Comments are welcome. Thanks!
v3:
- Do not return an error but just print a warning if vdpa device initialization returns failure while getting AS num of VQ groups
- Delete extra newline
v2:
- Much as commented on series [1], handle vhost_net backend through NetClientInfo callbacks instead of directly.
- Fix not freeing SVQ properly when device does not support CVQ
- Add BIT_ULL missed checking device's backend feature for _F_ASID.
[1] https://lists.nongnu.org/archive/html/qemu-devel/2022-08/msg00349.html
Eugenio Pérez (7):
linux-headers: Update kernel headers
vdpa: Use v->shadow_vqs_enabled in vhost_vdpa_svqs_start & stop
vdpa: Allocate SVQ unconditionally
vdpa: Add asid parameter to vhost_vdpa_dma_map/unmap
vdpa: Store x-svq parameter in VhostVDPAState
vhost_net: Add NetClientInfo prepare callback
vdpa: Always start CVQ in SVQ mode
include/hw/virtio/vhost-vdpa.h | 8 +- include/net/net.h | 2 + include/standard-headers/asm-x86/bootparam.h | 7 +- include/standard-headers/drm/drm_fourcc.h | 69 +++++++++ include/standard-headers/linux/ethtool.h | 1 + include/standard-headers/linux/input.h | 12 +- include/standard-headers/linux/pci_regs.h | 1 + include/standard-headers/linux/vhost_types.h | 11 +- include/standard-headers/linux/virtio_ids.h | 14 +- linux-headers/asm-arm64/kvm.h | 27 ++++ linux-headers/asm-generic/unistd.h | 4 +- linux-headers/asm-riscv/kvm.h | 20 +++ linux-headers/asm-riscv/unistd.h | 3 +- linux-headers/asm-x86/kvm.h | 11 +- linux-headers/asm-x86/mman.h | 14 -- linux-headers/linux/kvm.h | 56 ++++++- linux-headers/linux/userfaultfd.h | 10 +- linux-headers/linux/vfio.h | 4 +- linux-headers/linux/vhost.h | 26 +++- hw/net/vhost_net.c | 4 + hw/virtio/vhost-vdpa.c | 65 ++++---- net/vhost-vdpa.c | 154 ++++++++++++++++++- hw/virtio/trace-events | 4 +- 23 files changed, 434 insertions(+), 93 deletions(-)
Signature · 1 line
2.31.1
PATCH v3 1/7 linux-headers: Update kernel headers
Main reason is for new vhost_vdpa address space ioctls to be available.
Update kernel headers until9de1f9c8ca51 ("Merge tag 'irq-core-2022-08-01' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip").
--- include/standard-headers/asm-x86/bootparam.h | 7 +- include/standard-headers/drm/drm_fourcc.h | 69 ++++++++++++++++++++ include/standard-headers/linux/ethtool.h | 1 + include/standard-headers/linux/input.h | 12 ++-- include/standard-headers/linux/pci_regs.h | 1 + include/standard-headers/linux/vhost_types.h | 11 +++- include/standard-headers/linux/virtio_ids.h | 14 ++-- linux-headers/asm-arm64/kvm.h | 27 ++++++++ linux-headers/asm-generic/unistd.h | 4 +- linux-headers/asm-riscv/kvm.h | 20 ++++++ linux-headers/asm-riscv/unistd.h | 3 +- linux-headers/asm-x86/kvm.h | 11 ++-- linux-headers/asm-x86/mman.h | 14 ---- linux-headers/linux/kvm.h | 56 +++++++++++++++- linux-headers/linux/userfaultfd.h | 10 ++- linux-headers/linux/vfio.h | 4 +- linux-headers/linux/vhost.h | 26 ++++++-- 17 files changed, 240 insertions(+), 50 deletions(-)
include/standard-headers/asm-x86/bootparam.h +4 -3
@@ -10,12 +10,13 @@#define SETUP_EFI 4#define SETUP_APPLE_PROPERTIES 5#define SETUP_JAILHOUSE 6 +#define SETUP_CC_BLOB 7 +#define SETUP_IMA 8#define SETUP_RNG_SEED 9 +#define SETUP_ENUM_MAX SETUP_RNG_SEED#define SETUP_INDIRECT (1<<31) - -/* SETUP_INDIRECT | max(SETUP_*) */ -#define SETUP_TYPE_MAX (SETUP_INDIRECT | SETUP_JAILHOUSE) +#define SETUP_TYPE_MAX (SETUP_ENUM_MAX | SETUP_INDIRECT)/* ram_size flags */ #define RAMDISK_IMAGE_START_MASK 0x07FF
include/standard-headers/drm/drm_fourcc.h +69 -0
81 lines not on this page · raw message
include/standard-headers/linux/ethtool.h +1 -0
@@ -1691,6 +1691,7 @@ enum ethtool_link_mode_bit_indices { ETHTOOL_LINK_MODE_400000baseCR4_Full_BIT =89 , ETHTOOL_LINK_MODE_100baseFX_Half_BIT =90 , ETHTOOL_LINK_MODE_100baseFX_Full_BIT =91 , + ETHTOOL_LINK_MODE_10baseT1L_Full_BIT =92 ,/* must be last entry */ __ETHTOOL_LINK_MODE_MASK_NBITS };
include/standard-headers/linux/input.h +8 -4
@@ -75,10 +75,13 @@ struct input_id {* Note that input core does not clamp reported values to the * [minimum, maximum] limits, such task is left to userspace. * -* The default resolution for main axes (ABS_X, ABS_Y, ABS_Z) -* is reported in units per millimeter (units/mm), resolution -* for rotational axes (ABS_RX, ABS_RY, ABS_RZ) is reported -* in units per radian. +* The default resolution for main axes (ABS_X, ABS_Y, ABS_Z, +* ABS_MT_POSITION_X, ABS_MT_POSITION_Y) is reported in units +* per millimeter (units/mm), resolution for rotational axes +* (ABS_RX, ABS_RY, ABS_RZ) is reported in units per radian. +* The resolution for the size axes (ABS_MT_TOUCH_MAJOR, +* ABS_MT_TOUCH_MINOR, ABS_MT_WIDTH_MAJOR, ABS_MT_WIDTH_MINOR) +* is reported in units per millimeter (units/mm). * When INPUT_PROP_ACCELEROMETER is set the resolution changes. * The main axes (ABS_X, ABS_Y, ABS_Z) are then reported in * units per g (units/g) and in units per degree per second
@@ -268,6 +271,7 @@ struct input_mask {#define BUS_RMI 0x1D#define BUS_CEC 0x1E#define BUS_INTEL_ISHTP 0x1F +#define BUS_AMD_SFH 0x20/* * MT_TOOL types
include/standard-headers/linux/pci_regs.h +1 -0
@@ -616,6 +616,7 @@#define PCI_EXP_SLTCTL_PWR_OFF 0x0400/* Power Off */ #define PCI_EXP_SLTCTL_EIC 0x0800/* Electromechanical Interlock Control */ #define PCI_EXP_SLTCTL_DLLSCE 0x1000/* Data Link Layer State Changed Enable */ +#define PCI_EXP_SLTCTL_ASPL_DISABLE 0x2000/* Auto Slot Power Limit Disable */ #define PCI_EXP_SLTCTL_IBPD_DISABLE 0x4000/* In-band PD disable */ #define PCI_EXP_SLTSTA 0x1a/* Slot Status */ #define PCI_EXP_SLTSTA_ABP 0x0001/* Attention Button Pressed */
include/standard-headers/linux/vhost_types.h +10 -1
@@ -87,7 +87,7 @@ struct vhost_msg {struct vhost_msg_v2 {uint32_t type; -uint32_t reserved; +uint32_t asid;union {struct vhost_iotlb_msg iotlb;uint8_t padding[64 ];
@@ -153,4 +153,13 @@ struct vhost_vdpa_iova_range {/* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */ #define VHOST_NET_F_VIRTIO_NET_HDR 27 +/* Use message type V2 */ +#define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1 +/* IOTLB can accept batching hints */ +#define VHOST_BACKEND_F_IOTLB_BATCH 0x2 +/* IOTLB can accept address space identifier through V2 type of IOTLB +* message +*/ +#define VHOST_BACKEND_F_IOTLB_ASID 0x3 +#endif
include/standard-headers/linux/virtio_ids.h +7 -7
@@ -73,12 +73,12 @@* Virtio Transitional IDs */ -#define VIRTIO_TRANS_ID_NET 1000/* transitional virtio net */ -#define VIRTIO_TRANS_ID_BLOCK 1001/* transitional virtio block */ -#define VIRTIO_TRANS_ID_BALLOON 1002/* transitional virtio balloon */ -#define VIRTIO_TRANS_ID_CONSOLE 1003/* transitional virtio console */ -#define VIRTIO_TRANS_ID_SCSI 1004/* transitional virtio SCSI */ -#define VIRTIO_TRANS_ID_RNG 1005/* transitional virtio rng */ -#define VIRTIO_TRANS_ID_9P 1009/* transitional virtio 9p console */ +#define VIRTIO_TRANS_ID_NET 0x1000/* transitional virtio net */ +#define VIRTIO_TRANS_ID_BLOCK 0x1001/* transitional virtio block */ +#define VIRTIO_TRANS_ID_BALLOON 0x1002/* transitional virtio balloon */ +#define VIRTIO_TRANS_ID_CONSOLE 0x1003/* transitional virtio console */ +#define VIRTIO_TRANS_ID_SCSI 0x1004/* transitional virtio SCSI */ +#define VIRTIO_TRANS_ID_RNG 0x1005/* transitional virtio rng */ +#define VIRTIO_TRANS_ID_9P 0x1009/* transitional virtio 9p console */ #endif /* _LINUX_VIRTIO_IDS_H */
linux-headers/asm-arm64/kvm.h +27 -0
@@ -139,8 +139,10 @@ struct kvm_guest_debug_arch {__u64 dbg_wvr[KVM_ARM_MAX_DBG_REGS ]; }; +#define KVM_DEBUG_ARCH_HSR_HIGH_VALID (1 << 0)struct kvm_debug_exit_arch {__u32 hsr; +__u32 hsr_high;/* ESR_EL2[61:32] */ __u64 far;/* used for watchpoints */ };
@@ -332,6 +334,31 @@ struct kvm_arm_copy_mte_tags {#define KVM_ARM64_SVE_VLS_WORDS \ ((KVM_ARM64_SVE_VQ_MAX - KVM_ARM64_SVE_VQ_MIN) / 64 + 1) +/* Bitmap feature firmware registers */ +#define KVM_REG_ARM_FW_FEAT_BMAP (0x0016 << KVM_REG_ARM_COPROC_SHIFT) +#define KVM_REG_ARM_FW_FEAT_BMAP_REG (r) (KVM_REG_ARM64 | KVM_REG_SIZE_U64 | \ + KVM_REG_ARM_FW_FEAT_BMAP | \ + ((r) & 0xffff)) + +#define KVM_REG_ARM_STD_BMAP KVM_REG_ARM_FW_FEAT_BMAP_REG(0) + +enum { +KVM_REG_ARM_STD_BIT_TRNG_V1_0 =0 , +}; + +#define KVM_REG_ARM_STD_HYP_BMAP KVM_REG_ARM_FW_FEAT_BMAP_REG(1) + +enum { +KVM_REG_ARM_STD_HYP_BIT_PV_TIME =0 , +}; + +#define KVM_REG_ARM_VENDOR_HYP_BMAP KVM_REG_ARM_FW_FEAT_BMAP_REG(2) + +enum { +KVM_REG_ARM_VENDOR_HYP_BIT_FUNC_FEAT =0 , +KVM_REG_ARM_VENDOR_HYP_BIT_PTP =1 , +}; +/* Device Control API: ARM VGIC */ #define KVM_DEV_ARM_VGIC_GRP_ADDR 0#define KVM_DEV_ARM_VGIC_GRP_DIST_REGS 1
linux-headers/asm-generic/unistd.h +2 -2
@@ -383,7 +383,7 @@ __SYSCALL(__NR_syslog, sys_syslog)/* kernel/ptrace.c */ #define __NR_ptrace 117 -__SYSCALL (__NR_ptrace, sys_ptrace) +__SC_COMP (__NR_ptrace, sys_ptrace, compat_sys_ptrace) /* kernel/sched/core.c */#define __NR_sched_setparam 118
@@ -779,7 +779,7 @@ __SYSCALL(__NR_rseq, sys_rseq)#define __NR_kexec_file_load 294__SYSCALL (__NR_kexec_file_load, sys_kexec_file_load) /* 295 through 402 are unassigned to sync up with generic numbers, don't use */ -#if __BITS_PER_LONG ==32 +#if defined(__SYSCALL_COMPAT) || __BITS_PER_LONG ==32 #define __NR_clock_gettime64 403 __SYSCALL(__NR_clock_gettime64, sys_clock_gettime)#define __NR_clock_settime64 404
linux-headers/asm-riscv/kvm.h +20 -0
@@ -82,6 +82,23 @@ struct kvm_riscv_timer {__u64 state; }; +/* +* ISA extension IDs specific to KVM. This is not the same as the host ISA +* extension IDs as that is internal to the host and should not be exposed +* to the guest. This should always be contiguous to keep the mapping simple +* in KVM implementation. +*/ +enum KVM_RISCV_ISA_EXT_ID { +KVM_RISCV_ISA_EXT_A =0 , +KVM_RISCV_ISA_EXT_C , +KVM_RISCV_ISA_EXT_D , +KVM_RISCV_ISA_EXT_F , +KVM_RISCV_ISA_EXT_H , +KVM_RISCV_ISA_EXT_I , +KVM_RISCV_ISA_EXT_M , +KVM_RISCV_ISA_EXT_MAX , +}; +/* Possible states for kvm_riscv_timer */ #define KVM_RISCV_TIMER_STATE_OFF 0#define KVM_RISCV_TIMER_STATE_ON 1
@@ -123,6 +140,9 @@ struct kvm_riscv_timer {#define KVM_REG_RISCV_FP_D_REG (name) \ (offsetof(struct __riscv_d_ext_state, name) / sizeof(__u64)) +/* ISA Extension registers are mapped as type 7 */ +#define KVM_REG_RISCV_ISA_EXT (0x07 << KVM_REG_RISCV_TYPE_SHIFT) +#endif #endif /* __LINUX_KVM_RISCV_H */
linux-headers/asm-riscv/unistd.h +2 -1
@@ -15,12 +15,13 @@* along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#ifdef __LP64__ +#if defined(__LP64__) && !defined(__SYSCALL_COMPAT)#define __ARCH_WANT_NEW_STAT#define __ARCH_WANT_SET_GET_RLIMIT#endif /* __LP64__ */ #define __ARCH_WANT_SYS_CLONE3 +#define __ARCH_WANT_MEMFD_SECRET#include <asm-generic/unistd.h>
linux-headers/asm-x86/kvm.h +6 -5
@@ -428,11 +428,12 @@ struct kvm_sync_regs {struct kvm_vcpu_events events; }; -#define KVM_X86_QUIRK_LINT0_REENABLED (1 << 0) -#define KVM_X86_QUIRK_CD_NW_CLEARED (1 << 1) -#define KVM_X86_QUIRK_LAPIC_MMIO_HOLE (1 << 2) -#define KVM_X86_QUIRK_OUT_7E_INC_RIP (1 << 3) -#define KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT (1 << 4) +#define KVM_X86_QUIRK_LINT0_REENABLED (1 << 0) +#define KVM_X86_QUIRK_CD_NW_CLEARED (1 << 1) +#define KVM_X86_QUIRK_LAPIC_MMIO_HOLE (1 << 2) +#define KVM_X86_QUIRK_OUT_7E_INC_RIP (1 << 3) +#define KVM_X86_QUIRK_MISC_ENABLE_NO_MWAIT (1 << 4) +#define KVM_X86_QUIRK_FIX_HYPERCALL_INSN (1 << 5)#define KVM_STATE_NESTED_FORMAT_VMX 0#define KVM_STATE_NESTED_FORMAT_SVM 1
linux-headers/asm-x86/mman.h +0 -14
@@ -5,20 +5,6 @@#define MAP_32BIT 0x40/* only give out 32bit addresses */ #ifdef CONFIG_X86_INTEL_MEMORY_PROTECTION_KEYS -/* -* Take the 4 protection key bits out of the vma->vm_flags -* value and turn them in to the bits that we can put in -* to a pte. -* -* Only override these if Protection Keys are available -* (which is only on 64-bit). -*/ -#define arch_vm_get_page_prot (vm_flags) __pgprot( \ - ((vm_flags) & VM_PKEY_BIT0 ? _PAGE_PKEY_BIT0 : 0) | \ - ((vm_flags) & VM_PKEY_BIT1 ? _PAGE_PKEY_BIT1 : 0) | \ - ((vm_flags) & VM_PKEY_BIT2 ? _PAGE_PKEY_BIT2 : 0) | \ - ((vm_flags) & VM_PKEY_BIT3 ? _PAGE_PKEY_BIT3 : 0)) -#define arch_calc_vm_prot_bits (prot, key) ( \ ((key) & 0x1 ? VM_PKEY_BIT0 : 0) | \ ((key) & 0x2 ? VM_PKEY_BIT1 : 0) | \
linux-headers/linux/kvm.h +53 -3
122 lines not on this page · raw message
linux-headers/linux/userfaultfd.h +8 -2
@@ -33,7 +33,8 @@ UFFD_FEATURE_THREAD_ID | \ UFFD_FEATURE_MINOR_HUGETLBFS | \ UFFD_FEATURE_MINOR_SHMEM | \ - UFFD_FEATURE_EXACT_ADDRESS) + UFFD_FEATURE_EXACT_ADDRESS | \ + UFFD_FEATURE_WP_HUGETLBFS_SHMEM)#define UFFD_API_IOCTLS \ ((__u64)1 << _UFFDIO_REGISTER | \ (__u64)1 << _UFFDIO_UNREGISTER | \
@@ -47,7 +48,8 @@#define UFFD_API_RANGE_IOCTLS_BASIC \ ((__u64)1 << _UFFDIO_WAKE | \ (__u64)1 << _UFFDIO_COPY | \ - (__u64)1 << _UFFDIO_CONTINUE) + (__u64)1 << _UFFDIO_CONTINUE | \ + (__u64)1 << _UFFDIO_WRITEPROTECT)/* * Valid ioctl command number range with this API is from 0x00 to
@@ -194,6 +196,9 @@ struct uffdio_api {* UFFD_FEATURE_EXACT_ADDRESS indicates that the exact address of page * faults would be provided and the offset within the page would not be * masked. +* +* UFFD_FEATURE_WP_HUGETLBFS_SHMEM indicates that userfaultfd +* write-protection mode is supported on both shmem and hugetlbfs. */ #define UFFD_FEATURE_PAGEFAULT_FLAG_WP (1<<0)#define UFFD_FEATURE_EVENT_FORK (1<<1)
@@ -207,6 +212,7 @@ struct uffdio_api {#define UFFD_FEATURE_MINOR_HUGETLBFS (1<<9)#define UFFD_FEATURE_MINOR_SHMEM (1<<10)#define UFFD_FEATURE_EXACT_ADDRESS (1<<11) +#define UFFD_FEATURE_WP_HUGETLBFS_SHMEM (1<<12)__u64 features;__u64 ioctls;
linux-headers/linux/vfio.h +2 -2
@@ -643,7 +643,7 @@ enum { };/** -* VFIO_DEVICE_GET_PCI_HOT_RESET_INFO - _IORW(VFIO_TYPE, VFIO_BASE + 12, +* VFIO_DEVICE_GET_PCI_HOT_RESET_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 12, * struct vfio_pci_hot_reset_info) * * Return: 0 on success, -errno on failure:
@@ -770,7 +770,7 @@ struct vfio_device_ioeventfd {#define VFIO_DEVICE_IOEVENTFD _IO(VFIO_TYPE, VFIO_BASE + 16)/** -* VFIO_DEVICE_FEATURE - _IORW(VFIO_TYPE, VFIO_BASE + 17, +* VFIO_DEVICE_FEATURE - _IOWR(VFIO_TYPE, VFIO_BASE + 17, * struct vfio_device_feature) * * Get, set, or probe feature data of the device. The feature is selected
linux-headers/linux/vhost.h +20 -6
@@ -89,11 +89,6 @@/* Set or get vhost backend capability */ -/* Use message type V2 */ -#define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1 -/* IOTLB can accept batching hints */ -#define VHOST_BACKEND_F_IOTLB_BATCH 0x2 -#define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64)#define VHOST_GET_BACKEND_FEATURES _IOR(VHOST_VIRTIO, 0x26, __u64)
@@ -150,11 +145,30 @@/* Get the valid iova range */ #define VHOST_VDPA_GET_IOVA_RANGE _IOR(VHOST_VIRTIO, 0x78, \ struct vhost_vdpa_iova_range) -/* Get the config size */ #define VHOST_VDPA_GET_CONFIG_SIZE _IOR(VHOST_VIRTIO, 0x79, __u32)/* Get the count of all virtqueues */ #define VHOST_VDPA_GET_VQS_COUNT _IOR(VHOST_VIRTIO, 0x80, __u32) +/* Get the number of virtqueue groups. */ +#define VHOST_VDPA_GET_GROUP_NUM _IOR(VHOST_VIRTIO, 0x81, __u32) + +/* Get the number of address spaces. */ +#define VHOST_VDPA_GET_AS_NUM _IOR(VHOST_VIRTIO, 0x7A, unsigned int) + +/* Get the group for a virtqueue: read index, write group in num, +* The virtqueue index is stored in the index field of +* vhost_vring_state. The group for this specific virtqueue is +* returned via num field of vhost_vring_state. +*/ +#define VHOST_VDPA_GET_VRING_GROUP _IOWR(VHOST_VIRTIO, 0x7B, \ + struct vhost_vring_state) +/* Set the ASID for a virtqueue group. The group index is stored in +* the index field of vhost_vring_state, the ASID associated with this +* group is stored at num field of vhost_vring_state. +*/ +#define VHOST_VDPA_SET_GROUP_ASID _IOW(VHOST_VIRTIO, 0x7C, \ + struct vhost_vring_state) +#endif
Signature · 1 line
2.31.1
PATCH v3 2/7 vdpa: Use v->shadow_vqs_enabled in vhost_vdpa_svqs_start & stop
In reply to Eugenio PérezThis function used to trust in v->shadow_vqs != NULL to know if it must start svq or not.
This is not going to be valid anymore, as qemu is going to allocate svq unconditionally (but it will only start them conditionally).
--- hw/virtio/vhost-vdpa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/virtio/vhost-vdpa.c +2 -2
@@ -1025,7 +1025,7 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *dev)Error *err =NULL ;unsigned i; -if (!v->shadow_vqs) { +if (!v->shadow_vqs_enabled) {return true; }
@@ -1078,7 +1078,7 @@ static bool vhost_vdpa_svqs_stop(struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque; -if (!v->shadow_vqs) { +if (!v->shadow_vqs_enabled) {return true; }
Signature · 1 line
2.31.1
PATCH v3 3/7 vdpa: Allocate SVQ unconditionally
In reply to Eugenio PérezSVQ may run or not in a device depending on runtime conditions (for example, if the device can move CVQ to its own group or not).
Allocate the resources unconditionally, and decide later if to use them or not.
--- hw/virtio/vhost-vdpa.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-)
hw/virtio/vhost-vdpa.c +15 -18
@@ -406,6 +406,21 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v,int r;bool ok; + shadow_vqs =g_ptr_array_new_full (hdev->nvqs, vhost_svq_free); +for (unsigned n =0 ; n < hdev->nvqs; ++n) { +g_autoptr (VhostShadowVirtqueue) svq; + + svq =vhost_svq_new (v->iova_tree, v->shadow_vq_ops, + v->shadow_vq_ops_opaque); +if (unlikely (!svq)) { +error_setg (errp,"Cannot create svq %u" , n); +return -1 ; + } +g_ptr_array_add (shadow_vqs,g_steal_pointer (&svq)); + } + + v->shadow_vqs =g_steal_pointer (&shadow_vqs); +if (!v->shadow_vqs_enabled) {return 0 ; }
@@ -422,20 +437,6 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v,return -1 ; } - shadow_vqs =g_ptr_array_new_full (hdev->nvqs, vhost_svq_free); -for (unsigned n =0 ; n < hdev->nvqs; ++n) { -g_autoptr (VhostShadowVirtqueue) svq; - - svq =vhost_svq_new (v->iova_tree, v->shadow_vq_ops, - v->shadow_vq_ops_opaque); -if (unlikely (!svq)) { -error_setg (errp,"Cannot create svq %u" , n); -return -1 ; - } -g_ptr_array_add (shadow_vqs,g_steal_pointer (&svq)); - } - - v->shadow_vqs =g_steal_pointer (&shadow_vqs);return 0 ; }
@@ -576,10 +577,6 @@ static void vhost_vdpa_svq_cleanup(struct vhost_dev *dev)struct vhost_vdpa *v = dev->opaque;size_t idx; -if (!v->shadow_vqs) { -return ; - } -for (idx =0 ; idx < v->shadow_vqs->len; ++idx) {vhost_svq_stop (g_ptr_array_index (v->shadow_vqs, idx)); }
Signature · 1 line
2.31.1
PATCH v3 4/7 vdpa: Add asid parameter to vhost_vdpa_dma_map/unmap
In reply to Eugenio PérezSo the caller can choose which ASID is destined.
No need to update the batch functions as they will always be called from memory listener updates at the moment. Memory listener updates will always update ASID 0, as it's the passthrough ASID.
All vhost devices's ASID are 0 at this moment.
---
v3: Deleted unneeded space
--- include/hw/virtio/vhost-vdpa.h | 8 +++++--- hw/virtio/vhost-vdpa.c | 25 +++++++++++++++---------- net/vhost-vdpa.c | 6 +++--- hw/virtio/trace-events | 4 ++-- 4 files changed, 25 insertions(+), 18 deletions(-)
include/hw/virtio/vhost-vdpa.h +5 -3
@@ -29,6 +29,7 @@ typedef struct vhost_vdpa {int index;uint32_t msg_type;bool iotlb_batch_begin_sent; +uint32_t address_space_id;MemoryListener listener;struct vhost_vdpa_iova_range iova_range;uint64_t acked_features;
@@ -42,8 +43,9 @@ typedef struct vhost_vdpa { VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; } VhostVDPA; -int vhost_vdpa_dma_map (struct vhost_vdpa *v,hwaddr iova,hwaddr size, -void *vaddr,bool readonly); -int vhost_vdpa_dma_unmap (struct vhost_vdpa *v,hwaddr iova,hwaddr size); +int vhost_vdpa_dma_map (struct vhost_vdpa *v,uint32_t asid,hwaddr iova, +hwaddr size,void *vaddr,bool readonly); +int vhost_vdpa_dma_unmap (struct vhost_vdpa *v,uint32_t asid,hwaddr iova, +hwaddr size);#endif
hw/virtio/vhost-vdpa.c +15 -10
@@ -72,22 +72,24 @@ static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *section,return false; } -int vhost_vdpa_dma_map (struct vhost_vdpa *v,hwaddr iova,hwaddr size, -void *vaddr,bool readonly) +int vhost_vdpa_dma_map (struct vhost_vdpa *v,uint32_t asid,hwaddr iova, +hwaddr size,void *vaddr,bool readonly) {struct vhost_msg_v2 msg = {};int fd = v->device_fd;int ret =0 ; msg.type = v->msg_type; + msg.asid = asid; msg.iotlb.iova = iova; msg.iotlb.size = size; msg.iotlb.uaddr = (uint64_t )(uintptr_t )vaddr; msg.iotlb.perm = readonly ?VHOST_ACCESS_RO :VHOST_ACCESS_RW ; msg.iotlb.type =VHOST_IOTLB_UPDATE ; -trace_vhost_vdpa_dma_map (v, fd, msg.type, msg.iotlb.iova, msg.iotlb.size, - msg.iotlb.uaddr, msg.iotlb.perm, msg.iotlb.type); +trace_vhost_vdpa_dma_map (v, fd, msg.type, msg.asid, msg.iotlb.iova, + msg.iotlb.size, msg.iotlb.uaddr, msg.iotlb.perm, + msg.iotlb.type);if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) { error_report("failed to write, fd=%d, errno=%d (%s)",
@@ -98,18 +100,20 @@ int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size,return ret; } -int vhost_vdpa_dma_unmap (struct vhost_vdpa *v,hwaddr iova,hwaddr size) +int vhost_vdpa_dma_unmap (struct vhost_vdpa *v,uint32_t asid,hwaddr iova, +hwaddr size) {struct vhost_msg_v2 msg = {};int fd = v->device_fd;int ret =0 ; msg.type = v->msg_type; + msg.asid = asid; msg.iotlb.iova = iova; msg.iotlb.size = size; msg.iotlb.type =VHOST_IOTLB_INVALIDATE ; -trace_vhost_vdpa_dma_unmap (v, fd, msg.type, msg.iotlb.iova, +trace_vhost_vdpa_dma_unmap (v, fd, msg.type, msg.asid, msg.iotlb.iova, msg.iotlb.size, msg.iotlb.type);if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) {
@@ -229,7 +233,7 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, }vhost_vdpa_iotlb_batch_begin_once (v); - ret =vhost_vdpa_dma_map (v, iova,int128_get64 (llsize), + ret =vhost_vdpa_dma_map (v,0 , iova,int128_get64 (llsize), vaddr, section->readonly);if (ret) {error_report ("vhost vdpa map fail!" );
@@ -299,7 +303,7 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener,vhost_iova_tree_remove (v->iova_tree, result); }vhost_vdpa_iotlb_batch_begin_once (v); - ret =vhost_vdpa_dma_unmap (v, iova,int128_get64 (llsize)); + ret =vhost_vdpa_dma_unmap (v,0 , iova,int128_get64 (llsize));if (ret) {error_report ("vhost_vdpa dma unmap error!" ); }
@@ -890,7 +894,7 @@ static bool vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v, } size =ROUND_UP (result->size,qemu_real_host_page_size ()); - r =vhost_vdpa_dma_unmap (v, result->iova, size); + r =vhost_vdpa_dma_unmap (v, v->address_space_id, result->iova, size);return r ==0 ; }
@@ -932,7 +936,8 @@ static bool vhost_vdpa_svq_map_ring(struct vhost_vdpa *v, DMAMap *needle,return false; } - r =vhost_vdpa_dma_map (v, needle->iova, needle->size +1 , + r =vhost_vdpa_dma_map (v, v->address_space_id, needle->iova, + needle->size +1 , (void *)(uintptr_t )needle->translated_addr, needle->perm ==IOMMU_RO );if (unlikely (r !=0 )) {
net/vhost-vdpa.c +3 -3
@@ -239,7 +239,7 @@ static void vhost_vdpa_cvq_unmap_buf(struct vhost_vdpa *v, void *addr)return ; } - r =vhost_vdpa_dma_unmap (v, map->iova, map->size +1 ); + r =vhost_vdpa_dma_unmap (v, v->address_space_id, map->iova, map->size +1 );if (unlikely (r !=0 )) {error_report ("Device cannot unmap: %s(%d)" ,g_strerror (r), r); }
@@ -288,8 +288,8 @@ static bool vhost_vdpa_cvq_map_buf(struct vhost_vdpa *v,return false; } - r =vhost_vdpa_dma_map (v, map.iova,vhost_vdpa_net_cvq_cmd_page_len (), buf, - !write); + r =vhost_vdpa_dma_map (v, v->address_space_id, map.iova, +vhost_vdpa_net_cvq_cmd_page_len (), buf, !write);if (unlikely (r <0 )) { goto dma_map_err; }
hw/virtio/trace-events +2 -2
@@ -26,8 +26,8 @@ vhost_user_write(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32"" vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p" # vhost-vdpa.c -vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 -vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint64_t iova, uint64_t size, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8 +vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 +vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8 vhost_vdpa_listener_begin_batch(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 vhost_vdpa_listener_commit(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 vhost_vdpa_listener_region_add(void *vdpa, uint64_t iova, uint64_t llend, void *vaddr, bool readonly) "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64" vaddr: %p read-only: %d"
Signature · 1 line
2.31.1
Re: [PATCH v3 4/7] vdpa: Add asid parameter to vhost_vdpa_dma_map/unmap
Quoted 52 lines · Eugenio Pérez
So the caller can choose which ASID is destined.
No need to update the batch functions as they will always be called from memory listener updates at the moment. Memory listener updates will always update ASID 0, as it's the passthrough ASID.
All vhost devices's ASID are 0 at this moment.
Signed-off-by Eugenio Pérez <[email protected]>---
v3: Deleted unneeded space--- include/hw/virtio/vhost-vdpa.h | 8 +++++--- hw/virtio/vhost-vdpa.c | 25 +++++++++++++++---------- net/vhost-vdpa.c | 6 +++--- hw/virtio/trace-events | 4 ++-- 4 files changed, 25 insertions(+), 18 deletions(-)include/hw/virtio/vhost-vdpa.h +5
-3@@ -29,6 +29,7 @@ typedef struct vhost_vdpa {int index;uint32_t msg_type;bool iotlb_batch_begin_sent; +uint32_t address_space_id;MemoryListener listener;struct vhost_vdpa_iova_range iova_range;uint64_t acked_features;@@ -42,8 +43,9 @@ typedef struct vhost_vdpa { VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; } VhostVDPA; -int vhost_vdpa_dma_map (struct vhost_vdpa *v,hwaddr iova,hwaddr size, -void *vaddr,bool readonly); -int vhost_vdpa_dma_unmap (struct vhost_vdpa *v,hwaddr iova,hwaddr size); +int vhost_vdpa_dma_map (struct vhost_vdpa *v,uint32_t asid,hwaddr iova, +hwaddr size,void *vaddr,bool readonly); +int vhost_vdpa_dma_unmap (struct vhost_vdpa *v,uint32_t asid,hwaddr iova, +hwaddr size);#endif hw/virtio/vhost-vdpa.c +0
-1@@ -72,22 +72,24 @@ static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *section,return false; } -int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size,
hw/virtio/vhost-vdpa.c static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *section, · line 83
Quoted 10 lines
hw/virtio/vhost-vdpa.c +3
-1- void *vaddr, bool readonly) +int vhost_vdpa_dma_map (struct vhost_vdpa *v,uint32_t asid,hwaddr iova, +hwaddr size,void *vaddr,bool readonly) {struct vhost_msg_v2 msg = {};int fd = v->device_fd;int ret =0 ; msg.type = v->msg_type; + msg.asid = asid;
I wonder what happens if we're running is a kernel without ASID support.
Does it work since asid will be simply ignored? Can we have a case that we want asid!=0 on old kernel?
Thanks
Quoted 113 lines
hw/virtio/vhost-vdpa.c +12
-8msg.iotlb.iova = iova; msg.iotlb.size = size; msg.iotlb.uaddr = (uint64_t )(uintptr_t )vaddr; msg.iotlb.perm = readonly ?VHOST_ACCESS_RO :VHOST_ACCESS_RW ; msg.iotlb.type =VHOST_IOTLB_UPDATE ; -trace_vhost_vdpa_dma_map (v, fd, msg.type, msg.iotlb.iova, msg.iotlb.size, - msg.iotlb.uaddr, msg.iotlb.perm, msg.iotlb.type); +trace_vhost_vdpa_dma_map (v, fd, msg.type, msg.asid, msg.iotlb.iova, + msg.iotlb.size, msg.iotlb.uaddr, msg.iotlb.perm, + msg.iotlb.type);if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) { error_report("failed to write, fd=%d, errno=%d (%s)",@@ -98,18 +100,20 @@ int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size,return ret; } -int vhost_vdpa_dma_unmap (struct vhost_vdpa *v,hwaddr iova,hwaddr size) +int vhost_vdpa_dma_unmap (struct vhost_vdpa *v,uint32_t asid,hwaddr iova, +hwaddr size) {struct vhost_msg_v2 msg = {};int fd = v->device_fd;int ret =0 ; msg.type = v->msg_type; + msg.asid = asid; msg.iotlb.iova = iova; msg.iotlb.size = size; msg.iotlb.type =VHOST_IOTLB_INVALIDATE ; -trace_vhost_vdpa_dma_unmap (v, fd, msg.type, msg.iotlb.iova, +trace_vhost_vdpa_dma_unmap (v, fd, msg.type, msg.asid, msg.iotlb.iova, msg.iotlb.size, msg.iotlb.type);if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) {@@ -229,7 +233,7 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, }vhost_vdpa_iotlb_batch_begin_once (v); - ret =vhost_vdpa_dma_map (v, iova,int128_get64 (llsize), + ret =vhost_vdpa_dma_map (v,0 , iova,int128_get64 (llsize), vaddr, section->readonly);if (ret) {error_report ("vhost vdpa map fail!" );@@ -299,7 +303,7 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener,vhost_iova_tree_remove (v->iova_tree, result); }vhost_vdpa_iotlb_batch_begin_once (v); - ret =vhost_vdpa_dma_unmap (v, iova,int128_get64 (llsize)); + ret =vhost_vdpa_dma_unmap (v,0 , iova,int128_get64 (llsize));if (ret) {error_report ("vhost_vdpa dma unmap error!" ); }@@ -890,7 +894,7 @@ static bool vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v, } size =ROUND_UP (result->size,qemu_real_host_page_size ()); - r =vhost_vdpa_dma_unmap (v, result->iova, size); + r =vhost_vdpa_dma_unmap (v, v->address_space_id, result->iova, size);return r ==0 ; }@@ -932,7 +936,8 @@ static bool vhost_vdpa_svq_map_ring(struct vhost_vdpa *v, DMAMap *needle,return false; } - r =vhost_vdpa_dma_map (v, needle->iova, needle->size +1 , + r =vhost_vdpa_dma_map (v, v->address_space_id, needle->iova, + needle->size +1 , (void *)(uintptr_t )needle->translated_addr, needle->perm ==IOMMU_RO );if (unlikely (r !=0 )) {net/vhost-vdpa.c +3
-3@@ -239,7 +239,7 @@ static void vhost_vdpa_cvq_unmap_buf(struct vhost_vdpa *v, void *addr)return ; } - r =vhost_vdpa_dma_unmap (v, map->iova, map->size +1 ); + r =vhost_vdpa_dma_unmap (v, v->address_space_id, map->iova, map->size +1 );if (unlikely (r !=0 )) {error_report ("Device cannot unmap: %s(%d)" ,g_strerror (r), r); }@@ -288,8 +288,8 @@ static bool vhost_vdpa_cvq_map_buf(struct vhost_vdpa *v,return false; } - r =vhost_vdpa_dma_map (v, map.iova,vhost_vdpa_net_cvq_cmd_page_len (), buf, - !write); + r =vhost_vdpa_dma_map (v, v->address_space_id, map.iova, +vhost_vdpa_net_cvq_cmd_page_len (), buf, !write);if (unlikely (r <0 )) { goto dma_map_err; }hw/virtio/trace-events +2
-2@@ -26,8 +26,8 @@ vhost_user_write(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32"" vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p" # vhost-vdpa.c -vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 -vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint64_t iova, uint64_t size, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8 +vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 +vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8 vhost_vdpa_listener_begin_batch(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 vhost_vdpa_listener_commit(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 vhost_vdpa_listener_region_add(void *vdpa, uint64_t iova, uint64_t llend, void *vaddr, bool readonly) "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64" vaddr: %p read-only: %d"
Re: [PATCH v3 4/7] vdpa: Add asid parameter to vhost_vdpa_dma_map/unmap
Quoted 63 lines · Jason Wang
Quoted 60 lines · Eugenio Pérez
So the caller can choose which ASID is destined.
No need to update the batch functions as they will always be called from memory listener updates at the moment. Memory listener updates will always update ASID 0, as it's the passthrough ASID.
All vhost devices's ASID are 0 at this moment.
Signed-off-by Eugenio Pérez <[email protected]>---
v3: Deleted unneeded space--- include/hw/virtio/vhost-vdpa.h | 8 +++++--- hw/virtio/vhost-vdpa.c | 25 +++++++++++++++---------- net/vhost-vdpa.c | 6 +++--- hw/virtio/trace-events | 4 ++-- 4 files changed, 25 insertions(+), 18 deletions(-)include/hw/virtio/vhost-vdpa.h +5
-3@@ -29,6 +29,7 @@ typedef struct vhost_vdpa {int index;uint32_t msg_type;bool iotlb_batch_begin_sent; +uint32_t address_space_id;MemoryListener listener;struct vhost_vdpa_iova_range iova_range;uint64_t acked_features;@@ -42,8 +43,9 @@ typedef struct vhost_vdpa { VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; } VhostVDPA; -int vhost_vdpa_dma_map (struct vhost_vdpa *v,hwaddr iova,hwaddr size, -void *vaddr,bool readonly); -int vhost_vdpa_dma_unmap (struct vhost_vdpa *v,hwaddr iova,hwaddr size); +int vhost_vdpa_dma_map (struct vhost_vdpa *v,uint32_t asid,hwaddr iova, +hwaddr size,void *vaddr,bool readonly); +int vhost_vdpa_dma_unmap (struct vhost_vdpa *v,uint32_t asid,hwaddr iova, +hwaddr size);#endif hw/virtio/vhost-vdpa.c +2
-2@@ -72,22 +72,24 @@ static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *section,return false; } -int vhost_vdpa_dma_map (struct vhost_vdpa *v,hwaddr iova,hwaddr size, -void *vaddr,bool readonly) +int vhost_vdpa_dma_map (struct vhost_vdpa *v,uint32_t asid,hwaddr iova, +hwaddr size,void *vaddr,bool readonly) {struct vhost_msg_v2 msg = {};int fd = v->device_fd;int ret =0 ;
Quoted 9 lines
hw/virtio/vhost-vdpa.c static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *section, · line 83
Quoted 2 lines
hw/virtio/vhost-vdpa.c +1
-0msg.type = v->msg_type; + msg.asid = asid;I wonder what happens if we're running is a kernel without ASID support.
Does it work since asid will be simply ignored? Can we have a case that we want asid!=0 on old kernel?
No, it should always be 0 in that case. I can set it conditionally if you prefer.
Thanks!
Quoted 117 lines
Thanks
Quoted 113 lines
hw/virtio/vhost-vdpa.c +12
-8msg.iotlb.iova = iova; msg.iotlb.size = size; msg.iotlb.uaddr = (uint64_t )(uintptr_t )vaddr; msg.iotlb.perm = readonly ?VHOST_ACCESS_RO :VHOST_ACCESS_RW ; msg.iotlb.type =VHOST_IOTLB_UPDATE ; -trace_vhost_vdpa_dma_map (v, fd, msg.type, msg.iotlb.iova, msg.iotlb.size, - msg.iotlb.uaddr, msg.iotlb.perm, msg.iotlb.type); +trace_vhost_vdpa_dma_map (v, fd, msg.type, msg.asid, msg.iotlb.iova, + msg.iotlb.size, msg.iotlb.uaddr, msg.iotlb.perm, + msg.iotlb.type);if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) { error_report("failed to write, fd=%d, errno=%d (%s)",@@ -98,18 +100,20 @@ int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size,return ret; } -int vhost_vdpa_dma_unmap (struct vhost_vdpa *v,hwaddr iova,hwaddr size) +int vhost_vdpa_dma_unmap (struct vhost_vdpa *v,uint32_t asid,hwaddr iova, +hwaddr size) {struct vhost_msg_v2 msg = {};int fd = v->device_fd;int ret =0 ; msg.type = v->msg_type; + msg.asid = asid; msg.iotlb.iova = iova; msg.iotlb.size = size; msg.iotlb.type =VHOST_IOTLB_INVALIDATE ; -trace_vhost_vdpa_dma_unmap (v, fd, msg.type, msg.iotlb.iova, +trace_vhost_vdpa_dma_unmap (v, fd, msg.type, msg.asid, msg.iotlb.iova, msg.iotlb.size, msg.iotlb.type);if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) {@@ -229,7 +233,7 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, }vhost_vdpa_iotlb_batch_begin_once (v); - ret =vhost_vdpa_dma_map (v, iova,int128_get64 (llsize), + ret =vhost_vdpa_dma_map (v,0 , iova,int128_get64 (llsize), vaddr, section->readonly);if (ret) {error_report ("vhost vdpa map fail!" );@@ -299,7 +303,7 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener,vhost_iova_tree_remove (v->iova_tree, result); }vhost_vdpa_iotlb_batch_begin_once (v); - ret =vhost_vdpa_dma_unmap (v, iova,int128_get64 (llsize)); + ret =vhost_vdpa_dma_unmap (v,0 , iova,int128_get64 (llsize));if (ret) {error_report ("vhost_vdpa dma unmap error!" ); }@@ -890,7 +894,7 @@ static bool vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v, } size =ROUND_UP (result->size,qemu_real_host_page_size ()); - r =vhost_vdpa_dma_unmap (v, result->iova, size); + r =vhost_vdpa_dma_unmap (v, v->address_space_id, result->iova, size);return r ==0 ; }@@ -932,7 +936,8 @@ static bool vhost_vdpa_svq_map_ring(struct vhost_vdpa *v, DMAMap *needle,return false; } - r =vhost_vdpa_dma_map (v, needle->iova, needle->size +1 , + r =vhost_vdpa_dma_map (v, v->address_space_id, needle->iova, + needle->size +1 , (void *)(uintptr_t )needle->translated_addr, needle->perm ==IOMMU_RO );if (unlikely (r !=0 )) {net/vhost-vdpa.c +3
-3@@ -239,7 +239,7 @@ static void vhost_vdpa_cvq_unmap_buf(struct vhost_vdpa *v, void *addr)return ; } - r =vhost_vdpa_dma_unmap (v, map->iova, map->size +1 ); + r =vhost_vdpa_dma_unmap (v, v->address_space_id, map->iova, map->size +1 );if (unlikely (r !=0 )) {error_report ("Device cannot unmap: %s(%d)" ,g_strerror (r), r); }@@ -288,8 +288,8 @@ static bool vhost_vdpa_cvq_map_buf(struct vhost_vdpa *v,return false; } - r =vhost_vdpa_dma_map (v, map.iova,vhost_vdpa_net_cvq_cmd_page_len (), buf, - !write); + r =vhost_vdpa_dma_map (v, v->address_space_id, map.iova, +vhost_vdpa_net_cvq_cmd_page_len (), buf, !write);if (unlikely (r <0 )) { goto dma_map_err; }hw/virtio/trace-events +2
-2@@ -26,8 +26,8 @@ vhost_user_write(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32"" vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p" # vhost-vdpa.c -vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 -vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint64_t iova, uint64_t size, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8 +vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 +vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8 vhost_vdpa_listener_begin_batch(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 vhost_vdpa_listener_commit(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 vhost_vdpa_listener_region_add(void *vdpa, uint64_t iova, uint64_t llend, void *vaddr, bool readonly) "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64" vaddr: %p read-only: %d"
Re: [PATCH v3 4/7] vdpa: Add asid parameter to vhost_vdpa_dma_map/unmap
Quoted 71 lines · Eugenio Perez Martin
Quoted 69 lines · Jason Wang
Quoted 52 lines · Eugenio Pérez
So the caller can choose which ASID is destined.
No need to update the batch functions as they will always be called from memory listener updates at the moment. Memory listener updates will always update ASID 0, as it's the passthrough ASID.
All vhost devices's ASID are 0 at this moment.
Signed-off-by Eugenio Pérez <[email protected]>---
v3: Deleted unneeded space--- include/hw/virtio/vhost-vdpa.h | 8 +++++--- hw/virtio/vhost-vdpa.c | 25 +++++++++++++++---------- net/vhost-vdpa.c | 6 +++--- hw/virtio/trace-events | 4 ++-- 4 files changed, 25 insertions(+), 18 deletions(-)include/hw/virtio/vhost-vdpa.h +5
-3@@ -29,6 +29,7 @@ typedef struct vhost_vdpa {int index;uint32_t msg_type;bool iotlb_batch_begin_sent; +uint32_t address_space_id;MemoryListener listener;struct vhost_vdpa_iova_range iova_range;uint64_t acked_features;@@ -42,8 +43,9 @@ typedef struct vhost_vdpa { VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; } VhostVDPA; -int vhost_vdpa_dma_map (struct vhost_vdpa *v,hwaddr iova,hwaddr size, -void *vaddr,bool readonly); -int vhost_vdpa_dma_unmap (struct vhost_vdpa *v,hwaddr iova,hwaddr size); +int vhost_vdpa_dma_map (struct vhost_vdpa *v,uint32_t asid,hwaddr iova, +hwaddr size,void *vaddr,bool readonly); +int vhost_vdpa_dma_unmap (struct vhost_vdpa *v,uint32_t asid,hwaddr iova, +hwaddr size);#endif hw/virtio/vhost-vdpa.c +0
-1@@ -72,22 +72,24 @@ static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *section,return false; } -int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size,hw/virtio/vhost-vdpa.c static bool vhost_vdpa_listener_skipped_section(MemoryRegionSection *section, · line 83
Quoted 10 lines
hw/virtio/vhost-vdpa.c +3
-1- void *vaddr, bool readonly) +int vhost_vdpa_dma_map (struct vhost_vdpa *v,uint32_t asid,hwaddr iova, +hwaddr size,void *vaddr,bool readonly) {struct vhost_msg_v2 msg = {};int fd = v->device_fd;int ret =0 ; msg.type = v->msg_type; + msg.asid = asid;I wonder what happens if we're running is a kernel without ASID support.
Quoted 6 lines
Quoted 3 lines
Does it work since asid will be simply ignored? Can we have a case that we want asid!=0 on old kernel?
No, it should always be 0 in that case. I can set it conditionally if you prefer.
Or having a comment to explain why the unconditional use of asid is safe.
Thanks
Quoted 121 lines
Thanks!
Quoted 117 lines
Thanks
Quoted 113 lines
hw/virtio/vhost-vdpa.c +12
-8msg.iotlb.iova = iova; msg.iotlb.size = size; msg.iotlb.uaddr = (uint64_t )(uintptr_t )vaddr; msg.iotlb.perm = readonly ?VHOST_ACCESS_RO :VHOST_ACCESS_RW ; msg.iotlb.type =VHOST_IOTLB_UPDATE ; -trace_vhost_vdpa_dma_map (v, fd, msg.type, msg.iotlb.iova, msg.iotlb.size, - msg.iotlb.uaddr, msg.iotlb.perm, msg.iotlb.type); +trace_vhost_vdpa_dma_map (v, fd, msg.type, msg.asid, msg.iotlb.iova, + msg.iotlb.size, msg.iotlb.uaddr, msg.iotlb.perm, + msg.iotlb.type);if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) { error_report("failed to write, fd=%d, errno=%d (%s)",@@ -98,18 +100,20 @@ int vhost_vdpa_dma_map(struct vhost_vdpa *v, hwaddr iova, hwaddr size,return ret; } -int vhost_vdpa_dma_unmap (struct vhost_vdpa *v,hwaddr iova,hwaddr size) +int vhost_vdpa_dma_unmap (struct vhost_vdpa *v,uint32_t asid,hwaddr iova, +hwaddr size) {struct vhost_msg_v2 msg = {};int fd = v->device_fd;int ret =0 ; msg.type = v->msg_type; + msg.asid = asid; msg.iotlb.iova = iova; msg.iotlb.size = size; msg.iotlb.type =VHOST_IOTLB_INVALIDATE ; -trace_vhost_vdpa_dma_unmap (v, fd, msg.type, msg.iotlb.iova, +trace_vhost_vdpa_dma_unmap (v, fd, msg.type, msg.asid, msg.iotlb.iova, msg.iotlb.size, msg.iotlb.type);if (write (fd, &msg,sizeof (msg)) !=sizeof (msg)) {@@ -229,7 +233,7 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, }vhost_vdpa_iotlb_batch_begin_once (v); - ret =vhost_vdpa_dma_map (v, iova,int128_get64 (llsize), + ret =vhost_vdpa_dma_map (v,0 , iova,int128_get64 (llsize), vaddr, section->readonly);if (ret) {error_report ("vhost vdpa map fail!" );@@ -299,7 +303,7 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener,vhost_iova_tree_remove (v->iova_tree, result); }vhost_vdpa_iotlb_batch_begin_once (v); - ret =vhost_vdpa_dma_unmap (v, iova,int128_get64 (llsize)); + ret =vhost_vdpa_dma_unmap (v,0 , iova,int128_get64 (llsize));if (ret) {error_report ("vhost_vdpa dma unmap error!" ); }@@ -890,7 +894,7 @@ static bool vhost_vdpa_svq_unmap_ring(struct vhost_vdpa *v, } size =ROUND_UP (result->size,qemu_real_host_page_size ()); - r =vhost_vdpa_dma_unmap (v, result->iova, size); + r =vhost_vdpa_dma_unmap (v, v->address_space_id, result->iova, size);return r ==0 ; }@@ -932,7 +936,8 @@ static bool vhost_vdpa_svq_map_ring(struct vhost_vdpa *v, DMAMap *needle,return false; } - r =vhost_vdpa_dma_map (v, needle->iova, needle->size +1 , + r =vhost_vdpa_dma_map (v, v->address_space_id, needle->iova, + needle->size +1 , (void *)(uintptr_t )needle->translated_addr, needle->perm ==IOMMU_RO );if (unlikely (r !=0 )) {net/vhost-vdpa.c +3
-3@@ -239,7 +239,7 @@ static void vhost_vdpa_cvq_unmap_buf(struct vhost_vdpa *v, void *addr)return ; } - r =vhost_vdpa_dma_unmap (v, map->iova, map->size +1 ); + r =vhost_vdpa_dma_unmap (v, v->address_space_id, map->iova, map->size +1 );if (unlikely (r !=0 )) {error_report ("Device cannot unmap: %s(%d)" ,g_strerror (r), r); }@@ -288,8 +288,8 @@ static bool vhost_vdpa_cvq_map_buf(struct vhost_vdpa *v,return false; } - r =vhost_vdpa_dma_map (v, map.iova,vhost_vdpa_net_cvq_cmd_page_len (), buf, - !write); + r =vhost_vdpa_dma_map (v, v->address_space_id, map.iova, +vhost_vdpa_net_cvq_cmd_page_len (), buf, !write);if (unlikely (r <0 )) { goto dma_map_err; }hw/virtio/trace-events +2
-2@@ -26,8 +26,8 @@ vhost_user_write(uint32_t req, uint32_t flags) "req:%d flags:0x%"PRIx32"" vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p" # vhost-vdpa.c -vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 -vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint64_t iova, uint64_t size, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8 +vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 +vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, uint64_t iova, uint64_t size, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8 vhost_vdpa_listener_begin_batch(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 vhost_vdpa_listener_commit(void *v, int fd, uint32_t msg_type, uint8_t type) "vdpa:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 vhost_vdpa_listener_region_add(void *vdpa, uint64_t iova, uint64_t llend, void *vaddr, bool readonly) "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64" vaddr: %p read-only: %d"
PATCH v3 5/7 vdpa: Store x-svq parameter in VhostVDPAState
In reply to Eugenio PérezCVQ can be shadowed two ways:
- Device has x-svq=on parameter (current way)
- The device can isolate CVQ in its own vq group
QEMU needs to check for the second condition dynamically, because CVQ index is not known at initialization time. Since this is dynamic, the CVQ isolation could vary with different conditions, making it possible to go from "not isolated group" to "isolated".
Saving the cmdline parameter in an extra field so we never disable CVQ SVQ in case the device was started with cmdline.
--- net/vhost-vdpa.c | 4 ++++ 1 file changed, 4 insertions(+)
net/vhost-vdpa.c +4 -0
@@ -36,6 +36,9 @@ typedef struct VhostVDPAState {/* Control commands shadow buffers */ void *cvq_cmd_out_buffer, *cvq_cmd_in_buffer; + +/* The device always have SVQ enabled */ +bool always_svq;bool started; } VhostVDPAState;
@@ -564,6 +567,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.device_fd = vdpa_device_fd; s->vhost_vdpa.index = queue_pair_index; + s->always_svq = svq; s->vhost_vdpa.shadow_vqs_enabled = svq; s->vhost_vdpa.iova_tree = iova_tree;if (!is_datapath) {
Signature · 1 line
2.31.1
PATCH v3 6/7 vhost_net: Add NetClientInfo prepare callback
In reply to Eugenio PérezThis is used by the backend to perform actions before the device is started.
In particular, vdpa will use it to isolate CVQ in its own ASID if possible, and start SVQ unconditionally only in CVQ.
--- include/net/net.h | 2 ++ hw/net/vhost_net.c | 4 ++++ 2 files changed, 6 insertions(+)
include/net/net.h +2 -0
@@ -44,6 +44,7 @@ typedef struct NICConf {typedef void (NetPoll )(NetClientState *,bool enable);typedef bool (NetCanReceive )(NetClientState *); +typedef void (NetPrepare )(NetClientState *);typedef int (NetLoad )(NetClientState *);typedef ssize_t (NetReceive )(NetClientState *,const uint8_t *,size_t );typedef ssize_t (NetReceiveIOV )(NetClientState *,const struct iovec *,int );
@@ -72,6 +73,7 @@ typedef struct NetClientInfo {NetReceive *receive_raw;NetReceiveIOV *receive_iov;NetCanReceive *can_receive; +NetPrepare *prepare;NetLoad *load;NetCleanup *cleanup;LinkStatusChanged *link_status_changed;
hw/net/vhost_net.c +4 -0
@@ -244,6 +244,10 @@ static int vhost_net_start_one(struct vhost_net *net,struct vhost_vring_file file = { };int r; +if (net->nc->info->prepare) { + net->nc->info->prepare (net->nc); + } + r =vhost_dev_enable_notifiers (&net->dev, dev);if (r <0 ) { goto fail_notifiers;
Signature · 1 line
2.31.1
Re: [PATCH v3 6/7] vhost_net: Add NetClientInfo prepare callback
Quoted 37 lines · Eugenio Pérez
This is used by the backend to perform actions before the device is started.
In particular, vdpa will use it to isolate CVQ in its own ASID if possible, and start SVQ unconditionally only in CVQ.
Signed-off-by Eugenio Pérez <[email protected]>--- include/net/net.h | 2 ++ hw/net/vhost_net.c | 4 ++++ 2 files changed, 6 insertions(+)include/net/net.h +2
-0@@ -44,6 +44,7 @@ typedef struct NICConf {typedef void (NetPoll )(NetClientState *,bool enable);typedef bool (NetCanReceive )(NetClientState *); +typedef void (NetPrepare )(NetClientState *);typedef int (NetLoad )(NetClientState *);typedef ssize_t (NetReceive )(NetClientState *,const uint8_t *,size_t );typedef ssize_t (NetReceiveIOV )(NetClientState *,const struct iovec *,int );@@ -72,6 +73,7 @@ typedef struct NetClientInfo {NetReceive *receive_raw;NetReceiveIOV *receive_iov;NetCanReceive *can_receive; +NetPrepare *prepare;NetLoad *load;NetCleanup *cleanup;LinkStatusChanged *link_status_changed;hw/net/vhost_net.c +0
-0
hw/net/vhost_net.c static int vhost_net_start_one(struct vhost_net *net, · line 249
Quoted 6 lines
hw/net/vhost_net.c +3
-0@@ -244,6 +244,10 @@ static int vhost_net_start_one(struct vhost_net *net,struct vhost_vring_file file = { };int r; +if (net->nc->info->prepare) { + net->nc->info->prepare (net->nc); + }
Any chance we can reuse load()?
Thanks
Quoted 4 lines
hw/net/vhost_net.c +1
-0+ r =vhost_dev_enable_notifiers (&net->dev, dev);if (r <0 ) { goto fail_notifiers;
Re: [PATCH v3 6/7] vhost_net: Add NetClientInfo prepare callback
Quoted 43 lines · Jason Wang
Quoted 40 lines · Eugenio Pérez
This is used by the backend to perform actions before the device is started.
In particular, vdpa will use it to isolate CVQ in its own ASID if possible, and start SVQ unconditionally only in CVQ.
Signed-off-by Eugenio Pérez <[email protected]>--- include/net/net.h | 2 ++ hw/net/vhost_net.c | 4 ++++ 2 files changed, 6 insertions(+)include/net/net.h +2
-0@@ -44,6 +44,7 @@ typedef struct NICConf {typedef void (NetPoll )(NetClientState *,bool enable);typedef bool (NetCanReceive )(NetClientState *); +typedef void (NetPrepare )(NetClientState *);typedef int (NetLoad )(NetClientState *);typedef ssize_t (NetReceive )(NetClientState *,const uint8_t *,size_t );typedef ssize_t (NetReceiveIOV )(NetClientState *,const struct iovec *,int );@@ -72,6 +73,7 @@ typedef struct NetClientInfo {NetReceive *receive_raw;NetReceiveIOV *receive_iov;NetCanReceive *can_receive; +NetPrepare *prepare;NetLoad *load;NetCleanup *cleanup;LinkStatusChanged *link_status_changed;hw/net/vhost_net.c +0
-0@@ -244,6 +244,10 @@ static int vhost_net_start_one(struct vhost_net *net,struct vhost_vring_file file = { };int r;
Quoted 7 lines
hw/net/vhost_net.c static int vhost_net_start_one(struct vhost_net *net, · line 249
Quoted 3 lines
hw/net/vhost_net.c +3
-0+if (net->nc->info->prepare) { + net->nc->info->prepare (net->nc); + }Any chance we can reuse
load()?
We would be setting the ASID of CVQ after DRIVER_OK, vring addresses... if we move to load.
Thanks!
Quoted 8 lines
Thanks
Quoted 4 lines
hw/net/vhost_net.c +1
-0+ r =vhost_dev_enable_notifiers (&net->dev, dev);if (r <0 ) { goto fail_notifiers;
Re: [PATCH v3 6/7] vhost_net: Add NetClientInfo prepare callback
Quoted 53 lines · Eugenio Perez Martin
Quoted 43 lines · Jason Wang
Quoted 40 lines · Eugenio Pérez
This is used by the backend to perform actions before the device is started.
In particular, vdpa will use it to isolate CVQ in its own ASID if possible, and start SVQ unconditionally only in CVQ.
Signed-off-by Eugenio Pérez <[email protected]>--- include/net/net.h | 2 ++ hw/net/vhost_net.c | 4 ++++ 2 files changed, 6 insertions(+)include/net/net.h +2
-0@@ -44,6 +44,7 @@ typedef struct NICConf {typedef void (NetPoll )(NetClientState *,bool enable);typedef bool (NetCanReceive )(NetClientState *); +typedef void (NetPrepare )(NetClientState *);typedef int (NetLoad )(NetClientState *);typedef ssize_t (NetReceive )(NetClientState *,const uint8_t *,size_t );typedef ssize_t (NetReceiveIOV )(NetClientState *,const struct iovec *,int );@@ -72,6 +73,7 @@ typedef struct NetClientInfo {NetReceive *receive_raw;NetReceiveIOV *receive_iov;NetCanReceive *can_receive; +NetPrepare *prepare;NetLoad *load;NetCleanup *cleanup;LinkStatusChanged *link_status_changed;hw/net/vhost_net.c +0
-0@@ -244,6 +244,10 @@ static int vhost_net_start_one(struct vhost_net *net,struct vhost_vring_file file = { };int r;Quoted 7 lines
hw/net/vhost_net.c static int vhost_net_start_one(struct vhost_net *net, · line 249
Quoted 3 lines
hw/net/vhost_net.c +3
-0+if (net->nc->info->prepare) { + net->nc->info->prepare (net->nc); + }Any chance we can reuse
load()?
Quoted 2 lines
We would be setting the ASID of CVQ after
DRIVER_OK, vring addresses... if we move to load.
Ok, then this patch should be fine.
Thanks
Quoted 12 lines
Thanks!
Quoted 8 lines
Thanks
Quoted 4 lines
hw/net/vhost_net.c +1
-0+ r =vhost_dev_enable_notifiers (&net->dev, dev);if (r <0 ) { goto fail_notifiers;
PATCH v3 7/7 vdpa: Always start CVQ in SVQ mode
In reply to Eugenio PérezIsolate control virtqueue in its own group, allowing to intercept control commands but letting dataplane run totally passthrough to the guest.
---
v3:
* Make asid related queries print a warning instead of returning an error and stop the start of qemu.
--- hw/virtio/vhost-vdpa.c | 3 +- net/vhost-vdpa.c | 144 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 142 insertions(+), 5 deletions(-)
hw/virtio/vhost-vdpa.c +2 -1
@@ -674,7 +674,8 @@ static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev) {uint64_t features;uint64_t f =0x1ULL <<VHOST_BACKEND_F_IOTLB_MSG_V2 | -0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ; +0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH | +0x1ULL <<VHOST_BACKEND_F_IOTLB_ASID ;int r;if (vhost_vdpa_call (dev,VHOST_GET_BACKEND_FEATURES , &features)) {
net/vhost-vdpa.c +140 -4
210 lines not on this page · raw message
Signature · 1 line
2.31.1
Re: [PATCH v3 7/7] vdpa: Always start CVQ in SVQ mode
Quoted 75 lines · Eugenio Pérez
Isolate control virtqueue in its own group, allowing to intercept control commands but letting dataplane run totally passthrough to the guest.
Signed-off-by Eugenio Pérez <[email protected]>---
v3:
* Make asid related queries print a warning instead of returning an error and stop the start of qemu.--- hw/virtio/vhost-vdpa.c | 3 +- net/vhost-vdpa.c | 144 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 142 insertions(+), 5 deletions(-)hw/virtio/vhost-vdpa.c +2
-1@@ -674,7 +674,8 @@ static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev) {uint64_t features;uint64_t f =0x1ULL <<VHOST_BACKEND_F_IOTLB_MSG_V2 | -0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ; +0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH | +0x1ULL <<VHOST_BACKEND_F_IOTLB_ASID ;int r;if (vhost_vdpa_call (dev,VHOST_GET_BACKEND_FEATURES , &features)) {net/vhost-vdpa.c +26
-0@@ -37,6 +37,9 @@ typedef struct VhostVDPAState {/* Control commands shadow buffers */ void *cvq_cmd_out_buffer, *cvq_cmd_in_buffer; +/* Number of address spaces supported by the device */ +unsigned address_space_num; +/* The device always have SVQ enabled */ bool always_svq;bool started;@@ -100,6 +103,8 @@ static const uint64_t vdpa_svq_device_features =BIT_ULL (VIRTIO_NET_F_RSC_EXT ) |BIT_ULL (VIRTIO_NET_F_STANDBY ); +#define VHOST_VDPA_NET_CVQ_ASID 1 +VHostNetState *vhost_vdpa_get_vhost_net (NetClientState *nc) {VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc);@@ -224,6 +229,101 @@ static NetClientInfo net_vhost_vdpa_info = { .check_peer_type = vhost_vdpa_check_peer_type, }; +static void vhost_vdpa_get_vring_group (int device_fd, +struct vhost_vring_state *state) +{ +int r =ioctl (device_fd,VHOST_VDPA_GET_VRING_GROUP , state); +if (unlikely (r <0 )) { +/* +* Assume all groups are 0, the consequences are the same and we will +* not abort device creation +*/ + state->num =0 ; + } +} + +/** +* Check if all the virtqueues of the virtio device are in a different vq than +* the last vq. VQ group of last group passed in cvq_group. +*/ +static bool vhost_vdpa_cvq_group_is_independent (struct vhost_vdpa *v, +struct vhost_vring_state cvq_group) +{ +struct vhost_dev *dev = v->dev;
net/vhost-vdpa.c static NetClientInfo net_vhost_vdpa_info = { · line 262
Quoted 10 lines
net/vhost-vdpa.c +10
-0+ +for (int i =0 ; i < (dev->vq_index_end -1 ); ++i) { +struct vhost_vring_state vq_group = { + .index = i, + }; + +vhost_vdpa_get_vring_group (v->device_fd, &vq_group); +if (unlikely (vq_group.num == cvq_group.num)) { +warn_report ("CVQ %u group is the same as VQ %u one (%u)" , + cvq_group.index, vq_group.index, cvq_group.num);
I don't get why we need warn here.
Quoted 44 lines
net/vhost-vdpa.c +44
-0+return false; + } + } + +return true; +} + +static int vhost_vdpa_set_address_space_id (struct vhost_vdpa *v, +unsigned vq_group, +unsigned asid_num) +{ +struct vhost_vring_state asid = { + .index = vq_group, + .num = asid_num, + }; +int ret; + + ret =ioctl (v->device_fd,VHOST_VDPA_SET_GROUP_ASID , &asid); +if (unlikely (ret <0 )) { +warn_report ("Can't set vq group %u asid %u, errno=%d (%s)" , + asid.index, asid.num, errno,g_strerror (errno)); + } +return ret; +} + +static void vhost_vdpa_net_prepare (NetClientState *nc) +{ +VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); +struct vhost_vdpa *v = &s->vhost_vdpa; +struct vhost_dev *dev = v->dev; +struct vhost_vring_state cvq_group = { + .index = v->dev->vq_index_end -1 , + }; +int r; + +assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); + +if (dev->nvqs !=1 || dev->vq_index + dev->nvqs != dev->vq_index_end) { +/* Only interested in CVQ */ +return ; + } + +if (s->always_svq) { +/* SVQ is already enabled */
net/vhost-vdpa.c static NetClientInfo net_vhost_vdpa_info = { · line 316
Quoted 10 lines
net/vhost-vdpa.c +10
-0+return ; + } + +if (s->address_space_num <2 ) { + v->shadow_vqs_enabled = false; +return ; + } + +vhost_vdpa_get_vring_group (v->device_fd, &cvq_group); +if (!vhost_vdpa_cvq_group_is_independent (v, cvq_group)) {
If there's no other caller of vhost_vdpa_cvq_group_is_independent(), I'd suggest to unitfy them into a single helper.
(Btw, the name of the function is kind of too long).
Thanks
Quoted 111 lines
net/vhost-vdpa.c +50
-4+ v->shadow_vqs_enabled = false; +return ; + } + + r =vhost_vdpa_set_address_space_id (v, cvq_group.num, +VHOST_VDPA_NET_CVQ_ASID ); + v->shadow_vqs_enabled = r ==0 ; + s->vhost_vdpa.address_space_id = r ==0 ?1 :0 ; +} +static void vhost_vdpa_cvq_unmap_buf (struct vhost_vdpa *v,void *addr) {VhostIOVATree *tree = v->iova_tree;@@ -431,6 +531,7 @@ static NetClientInfo net_vhost_vdpa_cvq_info = { .type = NET_CLIENT_DRIVER_VHOST_VDPA, .size = sizeof(VhostVDPAState), .receive = vhost_vdpa_receive, + .prepare = vhost_vdpa_net_prepare, .load = vhost_vdpa_net_load, .cleanup = vhost_vdpa_cleanup, .has_vnet_hdr = vhost_vdpa_has_vnet_hdr,@@ -541,12 +642,38 @@ static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops = { .avail_handler = vhost_vdpa_net_handle_ctrl_avail, }; +static uint32_t vhost_vdpa_get_as_num (int vdpa_device_fd) +{ +uint64_t features; +unsigned num_as; +int r; + + r =ioctl (vdpa_device_fd,VHOST_GET_BACKEND_FEATURES , &features); +if (unlikely (r <0 )) { +warn_report ("Cannot get backend features" ); +return 1 ; + } + +if (!(features &BIT_ULL (VHOST_BACKEND_F_IOTLB_ASID ))) { +return 1 ; + } + + r =ioctl (vdpa_device_fd,VHOST_VDPA_GET_AS_NUM , &num_as); +if (unlikely (r <0 )) { +warn_report ("Cannot retrieve number of supported ASs" ); +return 1 ; + } + +return num_as; +} +static NetClientState *net_vhost_vdpa_init (NetClientState *peer,const char *device,const char *name,int vdpa_device_fd,int queue_pair_index,int nvqs, +unsigned nas,bool is_datapath,bool svq,VhostIOVATree *iova_tree)@@ -565,6 +692,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,snprintf (nc->info_str,sizeof (nc->info_str),TYPE_VHOST_VDPA ); s =DO_UPCAST (VhostVDPAState, nc, nc); + s->address_space_num = nas; s->vhost_vdpa.device_fd = vdpa_device_fd; s->vhost_vdpa.index = queue_pair_index; s->always_svq = svq;@@ -650,6 +778,8 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,g_autoptr (VhostIOVATree) iova_tree =NULL ;NetClientState *nc;int queue_pairs, r, i =0 , has_cvq =0 ; +unsigned num_as =1 ; +bool svq_cvq;assert (netdev->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); opts = &netdev->u.vhost_vdpa;@@ -674,7 +804,13 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, goto err; } -if (opts->x_svq) { + svq_cvq = opts->x_svq; +if (has_cvq && !opts->x_svq) { + num_as =vhost_vdpa_get_as_num (vdpa_device_fd); + svq_cvq = num_as >1 ; + } + +if (opts->x_svq || svq_cvq) {struct vhost_vdpa_iova_range iova_range; uint64_t invalid_dev_features =@@ -697,15 +833,15 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,for (i =0 ; i < queue_pairs; i++) { ncs[i] =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, - vdpa_device_fd, i,2 , true, opts->x_svq, - iova_tree); + vdpa_device_fd, i,2 , num_as, true, + opts->x_svq, iova_tree);if (!ncs[i]) goto err; }if (has_cvq) { nc =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, - vdpa_device_fd, i,1 , false, + vdpa_device_fd, i,1 , num_as, false, opts->x_svq, iova_tree);if (!nc) goto err;
Re: [PATCH v3 7/7] vdpa: Always start CVQ in SVQ mode
Quoted 83 lines · Jason Wang
Quoted 80 lines · Eugenio Pérez
Isolate control virtqueue in its own group, allowing to intercept control commands but letting dataplane run totally passthrough to the guest.
Signed-off-by Eugenio Pérez <[email protected]>---
v3:
* Make asid related queries print a warning instead of returning an error and stop the start of qemu.--- hw/virtio/vhost-vdpa.c | 3 +- net/vhost-vdpa.c | 144 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 142 insertions(+), 5 deletions(-)hw/virtio/vhost-vdpa.c +2
-1@@ -674,7 +674,8 @@ static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev) {uint64_t features;uint64_t f =0x1ULL <<VHOST_BACKEND_F_IOTLB_MSG_V2 | -0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH ; +0x1ULL <<VHOST_BACKEND_F_IOTLB_BATCH | +0x1ULL <<VHOST_BACKEND_F_IOTLB_ASID ;int r;if (vhost_vdpa_call (dev,VHOST_GET_BACKEND_FEATURES , &features)) {net/vhost-vdpa.c +31
-0@@ -37,6 +37,9 @@ typedef struct VhostVDPAState {/* Control commands shadow buffers */ void *cvq_cmd_out_buffer, *cvq_cmd_in_buffer; +/* Number of address spaces supported by the device */ +unsigned address_space_num; +/* The device always have SVQ enabled */ bool always_svq;bool started;@@ -100,6 +103,8 @@ static const uint64_t vdpa_svq_device_features =BIT_ULL (VIRTIO_NET_F_RSC_EXT ) |BIT_ULL (VIRTIO_NET_F_STANDBY ); +#define VHOST_VDPA_NET_CVQ_ASID 1 +VHostNetState *vhost_vdpa_get_vhost_net (NetClientState *nc) {VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc);@@ -224,6 +229,101 @@ static NetClientInfo net_vhost_vdpa_info = { .check_peer_type = vhost_vdpa_check_peer_type, }; +static void vhost_vdpa_get_vring_group (int device_fd, +struct vhost_vring_state *state) +{ +int r =ioctl (device_fd,VHOST_VDPA_GET_VRING_GROUP , state); +if (unlikely (r <0 )) { +/* +* Assume all groups are 0, the consequences are the same and we will +* not abort device creation +*/ + state->num =0 ; + } +} + +/** +* Check if all the virtqueues of the virtio device are in a different vq than +* the last vq. VQ group of last group passed in cvq_group. +*/ +static bool vhost_vdpa_cvq_group_is_independent (struct vhost_vdpa *v, +struct vhost_vring_state cvq_group) +{ +struct vhost_dev *dev = v->dev; + +for (int i =0 ; i < (dev->vq_index_end -1 ); ++i) { +struct vhost_vring_state vq_group = { + .index = i, + };
Quoted 9 lines
net/vhost-vdpa.c static NetClientInfo net_vhost_vdpa_info = { · line 262
Quoted 5 lines
net/vhost-vdpa.c +5
-0+ +vhost_vdpa_get_vring_group (v->device_fd, &vq_group); +if (unlikely (vq_group.num == cvq_group.num)) { +warn_report ("CVQ %u group is the same as VQ %u one (%u)" , + cvq_group.index, vq_group.index, cvq_group.num);I don't get why we need warn here.
Is not mandatory, but vhost will set a migration blocker and there is no way to trace it back to the cause without it.
Quoted 51 lines
Quoted 51 lines
net/vhost-vdpa.c +50
-0+return false; + } + } + +return true; +} + +static int vhost_vdpa_set_address_space_id (struct vhost_vdpa *v, +unsigned vq_group, +unsigned asid_num) +{ +struct vhost_vring_state asid = { + .index = vq_group, + .num = asid_num, + }; +int ret; + + ret =ioctl (v->device_fd,VHOST_VDPA_SET_GROUP_ASID , &asid); +if (unlikely (ret <0 )) { +warn_report ("Can't set vq group %u asid %u, errno=%d (%s)" , + asid.index, asid.num, errno,g_strerror (errno)); + } +return ret; +} + +static void vhost_vdpa_net_prepare (NetClientState *nc) +{ +VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); +struct vhost_vdpa *v = &s->vhost_vdpa; +struct vhost_dev *dev = v->dev; +struct vhost_vring_state cvq_group = { + .index = v->dev->vq_index_end -1 , + }; +int r; + +assert (nc->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); + +if (dev->nvqs !=1 || dev->vq_index + dev->nvqs != dev->vq_index_end) { +/* Only interested in CVQ */ +return ; + } + +if (s->always_svq) { +/* SVQ is already enabled */ +return ; + } + +if (s->address_space_num <2 ) { + v->shadow_vqs_enabled = false; +return ;
Quoted 9 lines
net/vhost-vdpa.c static NetClientInfo net_vhost_vdpa_info = { · line 316
Quoted 4 lines
net/vhost-vdpa.c +4
-0+ } + +vhost_vdpa_get_vring_group (v->device_fd, &cvq_group); +if (!vhost_vdpa_cvq_group_is_independent (v, cvq_group)) {If there's no other caller of
vhost_vdpa_cvq_group_is_independent(), I'd suggest to unitfy them into a single helper.
Sure, that can be done.
Thanks!
Quoted 117 lines
(Btw, the name of the function is kind of too long).
Thanks
Quoted 111 lines
net/vhost-vdpa.c +50
-4+ v->shadow_vqs_enabled = false; +return ; + } + + r =vhost_vdpa_set_address_space_id (v, cvq_group.num, +VHOST_VDPA_NET_CVQ_ASID ); + v->shadow_vqs_enabled = r ==0 ; + s->vhost_vdpa.address_space_id = r ==0 ?1 :0 ; +} +static void vhost_vdpa_cvq_unmap_buf (struct vhost_vdpa *v,void *addr) {VhostIOVATree *tree = v->iova_tree;@@ -431,6 +531,7 @@ static NetClientInfo net_vhost_vdpa_cvq_info = { .type = NET_CLIENT_DRIVER_VHOST_VDPA, .size = sizeof(VhostVDPAState), .receive = vhost_vdpa_receive, + .prepare = vhost_vdpa_net_prepare, .load = vhost_vdpa_net_load, .cleanup = vhost_vdpa_cleanup, .has_vnet_hdr = vhost_vdpa_has_vnet_hdr,@@ -541,12 +642,38 @@ static const VhostShadowVirtqueueOps vhost_vdpa_net_svq_ops = { .avail_handler = vhost_vdpa_net_handle_ctrl_avail, }; +static uint32_t vhost_vdpa_get_as_num (int vdpa_device_fd) +{ +uint64_t features; +unsigned num_as; +int r; + + r =ioctl (vdpa_device_fd,VHOST_GET_BACKEND_FEATURES , &features); +if (unlikely (r <0 )) { +warn_report ("Cannot get backend features" ); +return 1 ; + } + +if (!(features &BIT_ULL (VHOST_BACKEND_F_IOTLB_ASID ))) { +return 1 ; + } + + r =ioctl (vdpa_device_fd,VHOST_VDPA_GET_AS_NUM , &num_as); +if (unlikely (r <0 )) { +warn_report ("Cannot retrieve number of supported ASs" ); +return 1 ; + } + +return num_as; +} +static NetClientState *net_vhost_vdpa_init (NetClientState *peer,const char *device,const char *name,int vdpa_device_fd,int queue_pair_index,int nvqs, +unsigned nas,bool is_datapath,bool svq,VhostIOVATree *iova_tree)@@ -565,6 +692,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,snprintf (nc->info_str,sizeof (nc->info_str),TYPE_VHOST_VDPA ); s =DO_UPCAST (VhostVDPAState, nc, nc); + s->address_space_num = nas; s->vhost_vdpa.device_fd = vdpa_device_fd; s->vhost_vdpa.index = queue_pair_index; s->always_svq = svq;@@ -650,6 +778,8 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,g_autoptr (VhostIOVATree) iova_tree =NULL ;NetClientState *nc;int queue_pairs, r, i =0 , has_cvq =0 ; +unsigned num_as =1 ; +bool svq_cvq;assert (netdev->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); opts = &netdev->u.vhost_vdpa;@@ -674,7 +804,13 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, goto err; } -if (opts->x_svq) { + svq_cvq = opts->x_svq; +if (has_cvq && !opts->x_svq) { + num_as =vhost_vdpa_get_as_num (vdpa_device_fd); + svq_cvq = num_as >1 ; + } + +if (opts->x_svq || svq_cvq) {struct vhost_vdpa_iova_range iova_range; uint64_t invalid_dev_features =@@ -697,15 +833,15 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,for (i =0 ; i < queue_pairs; i++) { ncs[i] =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, - vdpa_device_fd, i,2 , true, opts->x_svq, - iova_tree); + vdpa_device_fd, i,2 , num_as, true, + opts->x_svq, iova_tree);if (!ncs[i]) goto err; }if (has_cvq) { nc =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, - vdpa_device_fd, i,1 , false, + vdpa_device_fd, i,1 , num_as, false, opts->x_svq, iova_tree);if (!nc) goto err;