>-----Original Message-----
>From: Eric Auger <eric.au...@redhat.com>
>Subject: Re: [PATCH rfcv2 07/20] iommufd: Implement query of
>HOST_IOMMU_DEVICE_CAP_[NESTING|FS1GP]
>
>
>
>
>On 2/19/25 9:22 AM, Zhenzhong Duan wrote:
>> Implement query of HOST_IOMMU_DEVICE_CAP_[NESTING|FS1GP] for
>IOMMUFD
>> backed host IOMMU device.
>>
>> Query on these two capabilities is not supported for legacy backend
>> because there is no plan to support nesting with leacy backend backed
>> host device.
>>
>> Signed-off-by: Zhenzhong Duan <zhenzhong.d...@intel.com>
>> ---
>> hw/i386/intel_iommu_internal.h | 1 +
>> backends/iommufd.c | 4 ++++
>> hw/vfio/iommufd.c | 11 +++++++++++
>> 3 files changed, 16 insertions(+)
>>
>> diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h
>> index e8b211e8b0..2cda744786 100644
>> --- a/hw/i386/intel_iommu_internal.h
>> +++ b/hw/i386/intel_iommu_internal.h
>> @@ -191,6 +191,7 @@
>> #define VTD_ECAP_PT (1ULL << 6)
>> #define VTD_ECAP_SC (1ULL << 7)
>> #define VTD_ECAP_MHMV (15ULL << 20)
>> +#define VTD_ECAP_NEST (1ULL << 26)
>> #define VTD_ECAP_SRS (1ULL << 31)
>> #define VTD_ECAP_PASID (1ULL << 40)
>> #define VTD_ECAP_SMTS (1ULL << 43)
>> diff --git a/backends/iommufd.c b/backends/iommufd.c
>> index 574f330c27..0a1a40cbba 100644
>> --- a/backends/iommufd.c
>> +++ b/backends/iommufd.c
>> @@ -370,6 +370,10 @@ static int hiod_iommufd_get_cap(HostIOMMUDevice
>*hiod, int cap, Error **errp)
>> return caps->type;
>> case HOST_IOMMU_DEVICE_CAP_AW_BITS:
>> return vfio_device_get_aw_bits(hiod->agent);
>> + case HOST_IOMMU_DEVICE_CAP_NESTING:
>> + return caps->nesting;
>> + case HOST_IOMMU_DEVICE_CAP_FS1GP:
>> + return caps->fs1gp;
>this is vtd specific so those caps shouldn't be return for other iommus, no?
vIOMMU should not query a CAP it doesn't recognize, even if that happen,
zero is returned hinting that CAP isn't supported for this vIOMMU.
Thanks
Zhenzhong
>
>Eric
>> default:
>> error_setg(errp, "%s: unsupported capability %x", hiod->name, cap);
>> return -EINVAL;
>> diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
>> index 175c4fe1f4..df6a12d200 100644
>> --- a/hw/vfio/iommufd.c
>> +++ b/hw/vfio/iommufd.c
>> @@ -26,6 +26,7 @@
>> #include "qemu/chardev_open.h"
>> #include "pci.h"
>> #include "exec/ram_addr.h"
>> +#include "hw/i386/intel_iommu_internal.h"
>>
>> static int iommufd_cdev_map(const VFIOContainerBase *bcontainer, hwaddr
>iova,
>> ram_addr_t size, void *vaddr, bool readonly)
>> @@ -843,6 +844,16 @@ static bool
>hiod_iommufd_vfio_realize(HostIOMMUDevice *hiod, void *opaque,
>> caps->type = type;
>> caps->hw_caps = hw_caps;
>>
>> + switch (type) {
>> + case IOMMU_HW_INFO_TYPE_INTEL_VTD:
>> + caps->nesting = !!(data.vtd.ecap_reg & VTD_ECAP_NEST);
>> + caps->fs1gp = !!(data.vtd.cap_reg & VTD_CAP_FS1GP);
>> + break;
>> + case IOMMU_HW_INFO_TYPE_ARM_SMMUV3:
>> + case IOMMU_HW_INFO_TYPE_NONE:
>> + break;
>> + }
>> +
>> return true;
>> }
>>