[PATCH v6 06/22] intel_iommu: Implement get_viommu_flags() callback

Zhenzhong Duan posted 22 patches 1 month, 3 weeks ago
Maintainers: Yi Liu <yi.l.liu@intel.com>, Eric Auger <eric.auger@redhat.com>, Zhenzhong Duan <zhenzhong.duan@intel.com>, "Michael S. Tsirkin" <mst@redhat.com>, Jason Wang <jasowang@redhat.com>, "Clément Mathieu--Drif" <clement.mathieu--drif@eviden.com>, Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <richard.henderson@linaro.org>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Alex Williamson <alex.williamson@redhat.com>, "Cédric Le Goater" <clg@redhat.com>, Fabiano Rosas <farosas@suse.de>, Laurent Vivier <lvivier@redhat.com>
There is a newer version of this series
[PATCH v6 06/22] intel_iommu: Implement get_viommu_flags() callback
Posted by Zhenzhong Duan 1 month, 3 weeks ago
Implement get_viommu_flags() callback and expose a request for nesting
parent HWPT for now.

VFIO uses it to create nesting parent HWPT which is further used to create
nested HWPT in vIOMMU. All these will be implemented in following patches.

Suggested-by: Yi Liu <yi.l.liu@intel.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
---
 hw/i386/intel_iommu.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index a47482ba9d..83c40975cc 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -24,6 +24,7 @@
 #include "qemu/main-loop.h"
 #include "qapi/error.h"
 #include "hw/sysbus.h"
+#include "hw/iommu.h"
 #include "intel_iommu_internal.h"
 #include "hw/pci/pci.h"
 #include "hw/pci/pci_bus.h"
@@ -4412,6 +4413,16 @@ static void vtd_dev_unset_iommu_device(PCIBus *bus, void *opaque, int devfn)
     vtd_iommu_unlock(s);
 }
 
+static uint64_t vtd_get_viommu_flags(void *opaque)
+{
+    IntelIOMMUState *s = opaque;
+    uint64_t caps;
+
+    caps = s->fsts ? VIOMMU_FLAG_WANT_NESTING_PARENT : 0;
+
+    return caps;
+}
+
 /* Unmap the whole range in the notifier's scope. */
 static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n)
 {
@@ -4842,6 +4853,7 @@ static PCIIOMMUOps vtd_iommu_ops = {
     .register_iotlb_notifier = vtd_register_iotlb_notifier,
     .unregister_iotlb_notifier = vtd_unregister_iotlb_notifier,
     .ats_request_translation = vtd_ats_request_translation,
+    .get_viommu_flags = vtd_get_viommu_flags,
 };
 
 static bool vtd_decide_config(IntelIOMMUState *s, Error **errp)
-- 
2.47.1
Re: [PATCH v6 06/22] intel_iommu: Implement get_viommu_flags() callback
Posted by Yi Liu 1 month ago
On 2025/9/18 16:57, Zhenzhong Duan wrote:
> Implement get_viommu_flags() callback and expose a request for nesting
> parent HWPT for now.
> 
> VFIO uses it to create nesting parent HWPT which is further used to create
> nested HWPT in vIOMMU. All these will be implemented in following patches.
> 
> Suggested-by: Yi Liu <yi.l.liu@intel.com>
> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
> Reviewed-by: Eric Auger <eric.auger@redhat.com>
> Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
> ---
>   hw/i386/intel_iommu.c | 12 ++++++++++++
>   1 file changed, 12 insertions(+)
> 
> diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
> index a47482ba9d..83c40975cc 100644
> --- a/hw/i386/intel_iommu.c
> +++ b/hw/i386/intel_iommu.c
> @@ -24,6 +24,7 @@
>   #include "qemu/main-loop.h"
>   #include "qapi/error.h"
>   #include "hw/sysbus.h"
> +#include "hw/iommu.h"
>   #include "intel_iommu_internal.h"
>   #include "hw/pci/pci.h"
>   #include "hw/pci/pci_bus.h"
> @@ -4412,6 +4413,16 @@ static void vtd_dev_unset_iommu_device(PCIBus *bus, void *opaque, int devfn)
>       vtd_iommu_unlock(s);
>   }
>   
> +static uint64_t vtd_get_viommu_flags(void *opaque)
> +{
> +    IntelIOMMUState *s = opaque;
> +    uint64_t caps;

s/caps/flags

> +
> +    caps = s->fsts ? VIOMMU_FLAG_WANT_NESTING_PARENT : 0;
> +
> +    return caps;
> +}
> +
>   /* Unmap the whole range in the notifier's scope. */
>   static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n)
>   {
> @@ -4842,6 +4853,7 @@ static PCIIOMMUOps vtd_iommu_ops = {
>       .register_iotlb_notifier = vtd_register_iotlb_notifier,
>       .unregister_iotlb_notifier = vtd_unregister_iotlb_notifier,
>       .ats_request_translation = vtd_ats_request_translation,
> +    .get_viommu_flags = vtd_get_viommu_flags,
>   };
>   
>   static bool vtd_decide_config(IntelIOMMUState *s, Error **errp)

Reviewed-by: Yi Liu <yi.l.liu@intel.com>

Regards,
Yi Liu
RE: [PATCH v6 06/22] intel_iommu: Implement get_viommu_flags() callback
Posted by Duan, Zhenzhong 1 month ago

>-----Original Message-----
>From: Liu, Yi L <yi.l.liu@intel.com>
>Subject: Re: [PATCH v6 06/22] intel_iommu: Implement get_viommu_flags()
>callback
>
>On 2025/9/18 16:57, Zhenzhong Duan wrote:
>> Implement get_viommu_flags() callback and expose a request for nesting
>> parent HWPT for now.
>>
>> VFIO uses it to create nesting parent HWPT which is further used to create
>> nested HWPT in vIOMMU. All these will be implemented in following
>patches.
>>
>> Suggested-by: Yi Liu <yi.l.liu@intel.com>
>> Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
>> Reviewed-by: Eric Auger <eric.auger@redhat.com>
>> Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
>> ---
>>   hw/i386/intel_iommu.c | 12 ++++++++++++
>>   1 file changed, 12 insertions(+)
>>
>> diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
>> index a47482ba9d..83c40975cc 100644
>> --- a/hw/i386/intel_iommu.c
>> +++ b/hw/i386/intel_iommu.c
>> @@ -24,6 +24,7 @@
>>   #include "qemu/main-loop.h"
>>   #include "qapi/error.h"
>>   #include "hw/sysbus.h"
>> +#include "hw/iommu.h"
>>   #include "intel_iommu_internal.h"
>>   #include "hw/pci/pci.h"
>>   #include "hw/pci/pci_bus.h"
>> @@ -4412,6 +4413,16 @@ static void
>vtd_dev_unset_iommu_device(PCIBus *bus, void *opaque, int devfn)
>>       vtd_iommu_unlock(s);
>>   }
>>
>> +static uint64_t vtd_get_viommu_flags(void *opaque)
>> +{
>> +    IntelIOMMUState *s = opaque;
>> +    uint64_t caps;
>
>s/caps/flags

done

Thanks
Zhenzhong