Message ID | 20231202092113.14141-1-yan.y.zhao@intel.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Sharing KVM TDP to IOMMU | expand |
On Sat, Dec 02, 2023 at 05:21:13PM +0800, Yan Zhao wrote: > @@ -413,11 +422,13 @@ struct iommu_hwpt_arm_smmuv3 { > * @IOMMU_HWPT_DATA_NONE: no data > * @IOMMU_HWPT_DATA_VTD_S1: Intel VT-d stage-1 page table > * @IOMMU_HWPT_DATA_ARM_SMMUV3: ARM SMMUv3 Context Descriptor Table > + * @IOMMU_HWPT_DATA_KVM: KVM managed stage-2 page table > */ > enum iommu_hwpt_data_type { > IOMMU_HWPT_DATA_NONE, > IOMMU_HWPT_DATA_VTD_S1, > IOMMU_HWPT_DATA_ARM_SMMUV3, > + IOMMU_HWPT_DATA_KVM, > }; Definately no, the HWPT_DATA is for the *driver* - it should not be "kvm". Add the kvm fd to the main structure Jason
On Mon, Dec 04, 2023 at 02:29:28PM -0400, Jason Gunthorpe wrote: > On Sat, Dec 02, 2023 at 05:21:13PM +0800, Yan Zhao wrote: > > > @@ -413,11 +422,13 @@ struct iommu_hwpt_arm_smmuv3 { > > * @IOMMU_HWPT_DATA_NONE: no data > > * @IOMMU_HWPT_DATA_VTD_S1: Intel VT-d stage-1 page table > > * @IOMMU_HWPT_DATA_ARM_SMMUV3: ARM SMMUv3 Context Descriptor Table > > + * @IOMMU_HWPT_DATA_KVM: KVM managed stage-2 page table > > */ > > enum iommu_hwpt_data_type { > > IOMMU_HWPT_DATA_NONE, > > IOMMU_HWPT_DATA_VTD_S1, > > IOMMU_HWPT_DATA_ARM_SMMUV3, > > + IOMMU_HWPT_DATA_KVM, > > }; > > Definately no, the HWPT_DATA is for the *driver* - it should not be > "kvm". > > Add the kvm fd to the main structure > Do you mean add a "int kvm_fd" to "struct iommu_hwpt_alloc" ? struct iommu_hwpt_alloc { __u32 size; __u32 flags; __u32 dev_id; __u32 pt_id; __u32 out_hwpt_id; __u32 __reserved; __u32 data_type; __u32 data_len; __aligned_u64 data_uptr; }; Then always create the HWPT as IOMMUFD_OBJ_HWPT_KVM as long as kvm_fd > 0 ?
On Tue, Dec 05, 2023 at 03:08:03PM +0800, Yan Zhao wrote: > On Mon, Dec 04, 2023 at 02:29:28PM -0400, Jason Gunthorpe wrote: > > On Sat, Dec 02, 2023 at 05:21:13PM +0800, Yan Zhao wrote: > > > > > @@ -413,11 +422,13 @@ struct iommu_hwpt_arm_smmuv3 { > > > * @IOMMU_HWPT_DATA_NONE: no data > > > * @IOMMU_HWPT_DATA_VTD_S1: Intel VT-d stage-1 page table > > > * @IOMMU_HWPT_DATA_ARM_SMMUV3: ARM SMMUv3 Context Descriptor Table > > > + * @IOMMU_HWPT_DATA_KVM: KVM managed stage-2 page table > > > */ > > > enum iommu_hwpt_data_type { > > > IOMMU_HWPT_DATA_NONE, > > > IOMMU_HWPT_DATA_VTD_S1, > > > IOMMU_HWPT_DATA_ARM_SMMUV3, > > > + IOMMU_HWPT_DATA_KVM, > > > }; > > > > Definately no, the HWPT_DATA is for the *driver* - it should not be > > "kvm". > > > > Add the kvm fd to the main structure > > > Do you mean add a "int kvm_fd" to "struct iommu_hwpt_alloc" ? > struct iommu_hwpt_alloc { > __u32 size; > __u32 flags; > __u32 dev_id; > __u32 pt_id; > __u32 out_hwpt_id; > __u32 __reserved; > __u32 data_type; > __u32 data_len; > __aligned_u64 data_uptr; > }; > > Then always create the HWPT as IOMMUFD_OBJ_HWPT_KVM as long as kvm_fd > 0 ? Yes, but 0 is a valid FD so you need to add a flag 'kvm_fd valid' Jason
On Tue, Dec 05, 2023 at 10:53:04AM -0400, Jason Gunthorpe wrote: > On Tue, Dec 05, 2023 at 03:08:03PM +0800, Yan Zhao wrote: > > On Mon, Dec 04, 2023 at 02:29:28PM -0400, Jason Gunthorpe wrote: > > > On Sat, Dec 02, 2023 at 05:21:13PM +0800, Yan Zhao wrote: > > > > > > > @@ -413,11 +422,13 @@ struct iommu_hwpt_arm_smmuv3 { > > > > * @IOMMU_HWPT_DATA_NONE: no data > > > > * @IOMMU_HWPT_DATA_VTD_S1: Intel VT-d stage-1 page table > > > > * @IOMMU_HWPT_DATA_ARM_SMMUV3: ARM SMMUv3 Context Descriptor Table > > > > + * @IOMMU_HWPT_DATA_KVM: KVM managed stage-2 page table > > > > */ > > > > enum iommu_hwpt_data_type { > > > > IOMMU_HWPT_DATA_NONE, > > > > IOMMU_HWPT_DATA_VTD_S1, > > > > IOMMU_HWPT_DATA_ARM_SMMUV3, > > > > + IOMMU_HWPT_DATA_KVM, > > > > }; > > > > > > Definately no, the HWPT_DATA is for the *driver* - it should not be > > > "kvm". > > > > > > Add the kvm fd to the main structure > > > > > Do you mean add a "int kvm_fd" to "struct iommu_hwpt_alloc" ? > > struct iommu_hwpt_alloc { > > __u32 size; > > __u32 flags; > > __u32 dev_id; > > __u32 pt_id; > > __u32 out_hwpt_id; > > __u32 __reserved; > > __u32 data_type; > > __u32 data_len; > > __aligned_u64 data_uptr; > > }; > > > > Then always create the HWPT as IOMMUFD_OBJ_HWPT_KVM as long as kvm_fd > 0 ? > > Yes, but 0 is a valid FD so you need to add a flag 'kvm_fd valid' Got it, thanks!
diff --git a/include/uapi/linux/iommufd.h b/include/uapi/linux/iommufd.h index 71c009cc614a4..08570f3a751fc 100644 --- a/include/uapi/linux/iommufd.h +++ b/include/uapi/linux/iommufd.h @@ -390,6 +390,15 @@ struct iommu_hwpt_vtd_s1 { __u32 __reserved; }; +/** + * struct iommu_hwpt_kvm_info - KVM managed stage-2 page table info + * (IOMMU_HWPT_DATA_KVM) + * @fd: The fd of the page table shared from KVM + */ +struct iommu_hwpt_kvm_info { + __aligned_u64 fd; +}; + /** * struct iommu_hwpt_arm_smmuv3 - ARM SMMUv3 Context Descriptor Table info * (IOMMU_HWPT_DATA_ARM_SMMUV3) @@ -413,11 +422,13 @@ struct iommu_hwpt_arm_smmuv3 { * @IOMMU_HWPT_DATA_NONE: no data * @IOMMU_HWPT_DATA_VTD_S1: Intel VT-d stage-1 page table * @IOMMU_HWPT_DATA_ARM_SMMUV3: ARM SMMUv3 Context Descriptor Table + * @IOMMU_HWPT_DATA_KVM: KVM managed stage-2 page table */ enum iommu_hwpt_data_type { IOMMU_HWPT_DATA_NONE, IOMMU_HWPT_DATA_VTD_S1, IOMMU_HWPT_DATA_ARM_SMMUV3, + IOMMU_HWPT_DATA_KVM, }; /** @@ -447,6 +458,10 @@ enum iommu_hwpt_data_type { * must be set to a pre-defined type corresponding to an I/O page table * type supported by the underlying IOMMU hardware. * + * A KVM-managed HWPT will be created if @data_type is IOMMU_HWPT_DATA_KVM. + * @pt_id is not queried if data_type is IOMMU_HWPT_DATA_KVM because KVM-managed + * HWPT doesn't have any IOAS or parent HWPT associated. + * * If the @data_type is set to IOMMU_HWPT_DATA_NONE, @data_len and * @data_uptr should be zero. Otherwise, both @data_len and @data_uptr * must be given.
Add allocation data info iommu_hwpt_kvm_info to allow IOMMUFD to create a KVM managed HWPT via ioctl IOMMU_HWPT_ALLOC. As KVM managed HWPT serves as stage-2 page tables whose paging structure and page mapping/unmapping are managed by KVM, there's no need to connect KVM managed HWPT to IOAS or parent HWPT. Signed-off-by: Yan Zhao <yan.y.zhao@intel.com> --- include/uapi/linux/iommufd.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)