Skip to contentSkip to conversation

Get DMA information from real IOMMU

PATCH In review Pierre Morel 4 participants 9 messages Jan 9, 2019 – Jan 10, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Get DMA information from real IOMMU

The zPCI driver needs to get specific information from the host IOMMU.
In this patch, the IOMMU DMA start and end usable addresses are retrieved using the VFIO_IOMMU_GET_INFO iotcl by introducing capabilities to the vfio_iommu_type1_info structure.

Pierre Morel (2):
vfio:iommu: Use capabilities do report IOMMU informations vfio:iommu: Get DMA information from real IOMMU

 drivers/vfio/vfio_iommu_type1.c | 43 ++++++++++++++++++++++++++++++++++++++++-
 include/uapi/linux/vfio.h       |  9 +++++++++
 2 files changed, 51 insertions(+), 1 deletion(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/2 vfio:iommu: Use capabilities do report IOMMU informations

We add a new flag, VFIO_IOMMU_INFO_CAPABILITIES, inside the vfio_iommu_type1_info to specify the support for capabilities.

We add a new capability, with id VFIO_IOMMU_INFO_CAP_DMA in the capability list of the VFIO_IOMMU_GET_INFO ioctl.

---
 include/uapi/linux/vfio.h | 9 +++++++++
 1 file changed, 9 insertions(+)
include/uapi/linux/vfio.h +9 -0
index 8131028..54c4fcb 100644
@@ -669,6 +669,15 @@ struct vfio_iommu_type1_info {
 	__u32	flags;
 #define VFIO_IOMMU_INFO_PGSIZES (1 << 0)	/* supported page sizes info */
 	__u64	iova_pgsizes;		/* Bitmap of supported page sizes */
+#define VFIO_IOMMU_INFO_CAPABILITIES (1 << 1)  /* support capabilities info */
+	__u64   cap_offset;     /* Offset within info struct of first cap */
+};
+
+#define VFIO_IOMMU_INFO_CAP_DMA 1
+struct vfio_iommu_cap_dma {
+	struct vfio_info_cap_header header;
+	__u64   dma_start;
+	__u64   dma_end;
 };
 
 #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH v1 1/2] vfio:iommu: Use capabilities do report IOMMU informations

Quoted 21 lines · On Wed, 9 Jan 2019 13:41:53 +0100 Pierre Morel <[email protected]> wrote:

We add a new flag, VFIO_IOMMU_INFO_CAPABILITIES, inside the vfio_iommu_type1_info to specify the support for capabilities.

We add a new capability, with id VFIO_IOMMU_INFO_CAP_DMA in the capability list of the VFIO_IOMMU_GET_INFO ioctl.

---
 include/uapi/linux/vfio.h | 9 +++++++++
 1 file changed, 9 insertions(+)
include/uapi/linux/vfio.h +2 -0
index 8131028..54c4fcb 100644
@@ -669,6 +669,15 @@ struct vfio_iommu_type1_info {
 	__u32	flags;
 #define VFIO_IOMMU_INFO_PGSIZES (1 << 0)	/* supported page sizes info */
 	__u64	iova_pgsizes;		/* Bitmap of supported page sizes */
+#define VFIO_IOMMU_INFO_CAPABILITIES (1 << 1)  /* support capabilities info */
+	__u64   cap_offset;     /* Offset within info struct of first cap */

include/uapi/linux/vfio.h struct vfio_iommu_type1_info { · line 683

Quoted 10 lines
include/uapi/linux/vfio.h +7 -0
+};
+
+#define VFIO_IOMMU_INFO_CAP_DMA 1
+struct vfio_iommu_cap_dma {
+	struct vfio_info_cap_header header;
+	__u64   dma_start;
+	__u64   dma_end;
 };
 
 #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)

Unfortunately for most systems, a simple start and end is not really sufficient to describe the available IOVA space, there are often reserved regions intermixed, so this is not really a complete solution. Shameer tried to solve this last year[1] but we ran into a road block that Intel IGD devices impose a reserved range of IOVA spaces reported to the user that conflict with existing assignment of this device and we haven't figured out yet how to be more selective of the enforcement of those reserved ranges. Thanks,

Alex

[1] https://lkml.org/lkml/2018/4/18/293

#3 lore raw

Re: [PATCH v1 1/2] vfio:iommu: Use capabilities do report IOMMU informations

Quoted 44 lines · Alex Williamson
Quoted 21 lines · On Wed, 9 Jan 2019 13:41:53 +0100 Pierre Morel <[email protected]> wrote:

We add a new flag, VFIO_IOMMU_INFO_CAPABILITIES, inside the vfio_iommu_type1_info to specify the support for capabilities.

We add a new capability, with id VFIO_IOMMU_INFO_CAP_DMA in the capability list of the VFIO_IOMMU_GET_INFO ioctl.

---
  include/uapi/linux/vfio.h | 9 +++++++++
  1 file changed, 9 insertions(+)
include/uapi/linux/vfio.h +2 -0
index 8131028..54c4fcb 100644
@@ -669,6 +669,15 @@ struct vfio_iommu_type1_info {
  	__u32	flags;
  #define VFIO_IOMMU_INFO_PGSIZES (1 << 0)	/* supported page sizes info */
  	__u64	iova_pgsizes;		/* Bitmap of supported page sizes */
+#define VFIO_IOMMU_INFO_CAPABILITIES (1 << 1)  /* support capabilities info */
+	__u64   cap_offset;     /* Offset within info struct of first cap */

include/uapi/linux/vfio.h struct vfio_iommu_type1_info { · line 683

Quoted 10 lines
include/uapi/linux/vfio.h +7 -0
+};
+
+#define VFIO_IOMMU_INFO_CAP_DMA 1
+struct vfio_iommu_cap_dma {
+	struct vfio_info_cap_header header;
+	__u64   dma_start;
+	__u64   dma_end;
  };
 
  #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)

Unfortunately for most systems, a simple start and end is not really sufficient to describe the available IOVA space, there are often reserved regions intermixed, so this is not really a complete solution. Shameer tried to solve this last year[1] but we ran into a road block that Intel IGD devices impose a reserved range of IOVA spaces reported to the user that conflict with existing assignment of this device and we haven't figured out yet how to be more selective of the enforcement of those reserved ranges. Thanks,

Quoted 4 lines

Alex

[1] https://lkml.org/lkml/2018/4/18/293

I understand that some architecture may be more complex and have special needs. However the IOMMU geometry is a constant for all IOMMU devices and is reported by the geometry in the iommu operations.

This makes the IOMMU geometry a special case.
It is also a special case because it is an inclusive description of available memory, to oppose to the exclusive description given by the windows.

Isn't it possible to separate the IOMMU geometry, which is really related to the IOMMU chip, from other windows exclusion related to the system memory mapping?

Retrieving the IOMMU geometry is very important for us because the driver inside the guest must get it and program the IOMMU based on these values.

Regards,
Pierre

Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
#4 lore raw

Re: [PATCH v1 1/2] vfio:iommu: Use capabilities do report IOMMU informations

Quoted 50 lines · On Wed, 9 Jan 2019 18:07:19 +0100 Pierre Morel <[email protected]> wrote:
Quoted 44 lines · Alex Williamson
Quoted 21 lines · On Wed, 9 Jan 2019 13:41:53 +0100 Pierre Morel <[email protected]> wrote:

We add a new flag, VFIO_IOMMU_INFO_CAPABILITIES, inside the vfio_iommu_type1_info to specify the support for capabilities.

We add a new capability, with id VFIO_IOMMU_INFO_CAP_DMA in the capability list of the VFIO_IOMMU_GET_INFO ioctl.

---
  include/uapi/linux/vfio.h | 9 +++++++++
  1 file changed, 9 insertions(+)
include/uapi/linux/vfio.h +2 -0
index 8131028..54c4fcb 100644
@@ -669,6 +669,15 @@ struct vfio_iommu_type1_info {
  	__u32	flags;
  #define VFIO_IOMMU_INFO_PGSIZES (1 << 0)	/* supported page sizes info */
  	__u64	iova_pgsizes;		/* Bitmap of supported page sizes */
+#define VFIO_IOMMU_INFO_CAPABILITIES (1 << 1)  /* support capabilities info */
+	__u64   cap_offset;     /* Offset within info struct of first cap */

include/uapi/linux/vfio.h struct vfio_iommu_type1_info { · line 683

Quoted 10 lines
include/uapi/linux/vfio.h +7 -0
+};
+
+#define VFIO_IOMMU_INFO_CAP_DMA 1
+struct vfio_iommu_cap_dma {
+	struct vfio_info_cap_header header;
+	__u64   dma_start;
+	__u64   dma_end;
  };
 
  #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)  

Unfortunately for most systems, a simple start and end is not really sufficient to describe the available IOVA space, there are often reserved regions intermixed, so this is not really a complete solution. Shameer tried to solve this last year[1] but we ran into a road block that Intel IGD devices impose a reserved range of IOVA spaces reported to the user that conflict with existing assignment of this device and we haven't figured out yet how to be more selective of the enforcement of those reserved ranges. Thanks,

Quoted 4 lines

Alex

[1] https://lkml.org/lkml/2018/4/18/293

Quoted 6 lines

I understand that some architecture may be more complex and have special needs.
However the IOMMU geometry is a constant for all IOMMU devices and is reported by the geometry in the iommu operations.

This makes the IOMMU geometry a special case.

I'm not so sure that the geometry is a constant for all IOMMU devices, nor am I sure how if that were true and it's part of an in-kernel interface that it automatically qualifies it as the right way to expose it to userspace. The fact that we have a reserved region interface to augment a basic contiguous range suggests it's known to be insufficient even for in-kernel use.

Quoted 3 lines

It is also a special case because it is an inclusive description of available memory, to oppose to the exclusive description given by the windows.

Geometry doesn't really have anything to do with available memory, it's the minimum and maximum IOVA aperture. Shameer's proposal gave us an IOVA list, which is based on the IOMMU geometry, from which it excludes various reserved ranges. So if you have a less complex architecture, you might only have one entry in the list, which gives you the start and end of the base geometry. Move complex architectures might have more entries, but the geometry can still be deduced from the absolute highest and lowest addresses within the list. Therefore a basic geometry capability is automatically redundant to the interface that's already been proposed.

Quoted 3 lines

Isn't it possible to separate the IOMMU geometry, which is really related to the IOMMU chip, from other windows exclusion related to the system memory mapping?

Why would we ever have both given the description above?

Quoted 3 lines

Retrieving the IOMMU geometry is very important for us because the driver inside the guest must get it and program the IOMMU based on these values.

So you have motivation to help move the IOVA list proposal forward, or some equally inclusive proposal that isn't just a stop-gap ;) Thanks,

Alex

#5 lore raw

Re: [PATCH v1 1/2] vfio:iommu: Use capabilities do report IOMMU informations

Quoted 53 lines · Alex Williamson
Quoted 50 lines · On Wed, 9 Jan 2019 18:07:19 +0100 Pierre Morel <[email protected]> wrote:
Quoted 48 lines · Alex Williamson
Quoted 21 lines · On Wed, 9 Jan 2019 13:41:53 +0100 Pierre Morel <[email protected]> wrote:

We add a new flag, VFIO_IOMMU_INFO_CAPABILITIES, inside the vfio_iommu_type1_info to specify the support for capabilities.

We add a new capability, with id VFIO_IOMMU_INFO_CAP_DMA in the capability list of the VFIO_IOMMU_GET_INFO ioctl.

---
   include/uapi/linux/vfio.h | 9 +++++++++
   1 file changed, 9 insertions(+)
include/uapi/linux/vfio.h +2 -0
index 8131028..54c4fcb 100644
@@ -669,6 +669,15 @@ struct vfio_iommu_type1_info {
   	__u32	flags;
   #define VFIO_IOMMU_INFO_PGSIZES (1 << 0)	/* supported page sizes info */
   	__u64	iova_pgsizes;		/* Bitmap of supported page sizes */
+#define VFIO_IOMMU_INFO_CAPABILITIES (1 << 1)  /* support capabilities info */
+	__u64   cap_offset;     /* Offset within info struct of first cap */

include/uapi/linux/vfio.h struct vfio_iommu_type1_info { · line 683

Quoted 10 lines
include/uapi/linux/vfio.h +7 -0
+};
+
+#define VFIO_IOMMU_INFO_CAP_DMA 1
+struct vfio_iommu_cap_dma {
+	struct vfio_info_cap_header header;
+	__u64   dma_start;
+	__u64   dma_end;
   };
 
   #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)

Unfortunately for most systems, a simple start and end is not really sufficient to describe the available IOVA space, there are often reserved regions intermixed, so this is not really a complete solution. Shameer tried to solve this last year[1] but we ran into a road block that Intel IGD devices impose a reserved range of IOVA spaces reported to the user that conflict with existing assignment of this device and we haven't figured out yet how to be more selective of the enforcement of those reserved ranges. Thanks,

Alex

[1] https://lkml.org/lkml/2018/4/18/293

Quoted 8 lines
Quoted 6 lines

I understand that some architecture may be more complex and have special needs.
However the IOMMU geometry is a constant for all IOMMU devices and is reported by the geometry in the iommu operations.

This makes the IOMMU geometry a special case.

I'm not so sure that the geometry is a constant for all IOMMU devices,

Sorry, I did not express myself correctly, what I mean is that the IOMMU geometry is independent of the system memory map but is a constant of the IOMMU device. May be different for another IOMMU device, as we can have several different IOMMU device, typically one per PCI device, in the Z architecture.

Quoted 21 lines

nor am I sure how if that were true and it's part of an in-kernel interface that it automatically qualifies it as the right way to expose it to userspace. The fact that we have a reserved region interface to augment a basic contiguous range suggests it's known to be insufficient even for in-kernel use.

Quoted 3 lines

It is also a special case because it is an inclusive description of available memory, to oppose to the exclusive description given by the windows.

Geometry doesn't really have anything to do with available memory, it's the minimum and maximum IOVA aperture. Shameer's proposal gave us an IOVA list, which is based on the IOMMU geometry, from which it excludes various reserved ranges. So if you have a less complex architecture, you might only have one entry in the list, which gives you the start and end of the base geometry. Move complex architectures might have more entries, but the geometry can still be deduced from the absolute highest and lowest addresses within the list. Therefore a basic geometry capability is automatically redundant to the interface that's already been proposed.

Quoted 5 lines
Quoted 3 lines

Isn't it possible to separate the IOMMU geometry, which is really related to the IOMMU chip, from other windows exclusion related to the system memory mapping?

Why would we ever have both given the description above?

My idea for this is based on that restrictions are comming from two different address spaces:
- One address space is the device view before IOMMU (aperture)
- The other is the physical system view (reserved windows)

which, I thought, makes things difficult to merge.
However reading you and Shameer and the pointers you both sent, I understand that there are much more for me to learn, especially about other architectures (Intel / RMRR)

Quoted 11 lines
Quoted 4 lines

Retrieving the IOMMU geometry is very important for us because the driver inside the guest must get it and program the IOMMU based on these values.

So you have motivation to help move the IOVA list proposal forward, or some equally inclusive proposal that isn't just a stop-gap ;) Thanks,

Alex

I will be happy to help.
I will need some time to catch up however.
Thanks for your comments.

Regards,
Pierre

Signature · 2 lines
Pierre Morel
Linux/KVM/QEMU in Böblingen - Germany
#6 lore raw

RE: [PATCH v1 1/2] vfio:iommu: Use capabilities do report IOMMU informations

In reply to Alex Williamson
Quoted 48 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: 09 January 2019 15:37
To: Pierre Morel <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Shameerali Kolothum Thodi <[email protected]>
Subject: Re: [PATCH v1 1/2] vfio:iommu: Use capabilities do report IOMMU informations

Quoted 16 lines · On Wed, 9 Jan 2019 13:41:53 +0100 Pierre Morel <[email protected]> wrote:

We add a new flag, VFIO_IOMMU_INFO_CAPABILITIES, inside the vfio_iommu_type1_info to specify the support for capabilities.

We add a new capability, with id VFIO_IOMMU_INFO_CAP_DMA in the capability list of the VFIO_IOMMU_GET_INFO ioctl.

---
 include/uapi/linux/vfio.h | 9 +++++++++
 1 file changed, 9 insertions(+)
include/uapi/linux/vfio.h +0 -0
index 8131028..54c4fcb 100644

include/uapi/linux/vfio.h struct vfio_iommu_type1_info { · line 670

Quoted 2 lines
include/uapi/linux/vfio.h +0 -0
@@ -669,6 +669,15 @@ struct vfio_iommu_type1_info {
 	__u32	flags;
 #define VFIO_IOMMU_INFO_PGSIZES (1 << 0)	/* supported page sizes

info */

include/uapi/linux/vfio.h struct vfio_iommu_type1_info { · line 672

Quoted 2 lines
include/uapi/linux/vfio.h +1 -0
 	__u64	iova_pgsizes;		/* Bitmap of supported page sizes */
+#define VFIO_IOMMU_INFO_CAPABILITIES (1 << 1)  /* support capabilities

info */

Quoted 10 lines
include/uapi/linux/vfio.h +8 -0
+	__u64   cap_offset;     /* Offset within info struct of first cap */
+};
+
+#define VFIO_IOMMU_INFO_CAP_DMA 1
+struct vfio_iommu_cap_dma {
+	struct vfio_info_cap_header header;
+	__u64   dma_start;
+	__u64   dma_end;
 };
 
Quoted 10 lines

include/uapi/linux/vfio.h struct vfio_iommu_type1_info { · line 683

Quoted 1 line
include/uapi/linux/vfio.h +0 -0
 #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)

Unfortunately for most systems, a simple start and end is not really sufficient to describe the available IOVA space, there are often reserved regions intermixed, so this is not really a complete solution. Shameer tried to solve this last year[1] but we ran into a road block that Intel IGD devices impose a reserved range of IOVA spaces reported to the user that conflict with existing assignment of this device and we haven't figured out yet how to be more selective of the enforcement of those reserved ranges. Thanks,

Right. I had further discussions to unblock this at KVM forum/off-list with Intel folks and was promised some help.

IIRC the discussion was at, Kevin/Ashok will take another look on your proposed approach to exclude the RMRR[1] and see whether that is good enough or not.

Kevin/Ashok,

Please update if you had a chance to look into it.

Thanks,
Shameer

[1]. https://lkml.org/lkml/2018/6/5/897

Quoted 3 lines

Alex

[1] https://lkml.org/lkml/2018/4/18/293

#7 lore raw

RE: [PATCH v1 1/2] vfio:iommu: Use capabilities do report IOMMU informations

Quoted 67 lines

From: Shameerali Kolothum Thodi
[mailto:[email protected]]

Quoted 9 lines

-----Original Message-----
From: Alex Williamson [mailto:[email protected]]
Sent: 09 January 2019 15:37
To: Pierre Morel <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Shameerali Kolothum Thodi <[email protected]>
Subject: Re: [PATCH v1 1/2] vfio:iommu: Use capabilities do report

IOMMU

Quoted 16 lines

informations

Quoted 11 lines · On Wed, 9 Jan 2019 13:41:53 +0100 Pierre Morel <[email protected]> wrote:

We add a new flag, VFIO_IOMMU_INFO_CAPABILITIES, inside the vfio_iommu_type1_info to specify the support for capabilities.

We add a new capability, with id VFIO_IOMMU_INFO_CAP_DMA in the capability list of the VFIO_IOMMU_GET_INFO ioctl.

---
 include/uapi/linux/vfio.h | 9 +++++++++
 1 file changed, 9 insertions(+)
Quoted 7 lines

include/uapi/linux/vfio.h struct vfio_iommu_type1_info { · line 670

Quoted 7 lines
include/uapi/linux/vfio.h +0 -0
index 8131028..54c4fcb 100644
@@ -669,6 +669,15 @@ struct vfio_iommu_type1_info {
 	__u32	flags;
 #define VFIO_IOMMU_INFO_PGSIZES (1 << 0)	/* supported page

sizes

Quoted 2 lines

info */

Quoted 1 line
include/uapi/linux/vfio.h +0 -0
 	__u64	iova_pgsizes;		/* Bitmap of supported page sizes

*/

Quoted 1 line

include/uapi/linux/vfio.h struct vfio_iommu_type1_info { · line 672

Quoted 1 line
include/uapi/linux/vfio.h +1 -0
+#define VFIO_IOMMU_INFO_CAPABILITIES (1 << 1)  /* support

capabilities

Quoted 11 lines

info */

Quoted 10 lines
include/uapi/linux/vfio.h +8 -0
+	__u64   cap_offset;     /* Offset within info struct of first cap */
+};
+
+#define VFIO_IOMMU_INFO_CAP_DMA 1
+struct vfio_iommu_cap_dma {
+	struct vfio_info_cap_header header;
+	__u64   dma_start;
+	__u64   dma_end;
 };
 
Quoted 10 lines

include/uapi/linux/vfio.h struct vfio_iommu_type1_info { · line 683

Quoted 1 line
include/uapi/linux/vfio.h +0 -0
 #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)

Unfortunately for most systems, a simple start and end is not really sufficient to describe the available IOVA space, there are often reserved regions intermixed, so this is not really a complete solution. Shameer tried to solve this last year[1] but we ran into a road block that Intel IGD devices impose a reserved range of IOVA spaces reported to the user that conflict with existing assignment of this device and we haven't figured out yet how to be more selective of the enforcement of those reserved ranges. Thanks,

Right. I had further discussions to unblock this at KVM forum/off-list with Intel folks and was promised some help.

Quoted 7 lines

IIRC the discussion was at, Kevin/Ashok will take another look on your proposed approach to exclude the RMRR[1] and see whether that is good enough or not.

Kevin/Ashok,

Please update if you had a chance to look into it.

+Jacob.

My recent check seems to indicate [1] possibly fine with IGD, but I'll let Ashok/Jacob to double confirm and ack since they are the owner of intel-iommu driver.

Quoted 9 lines

Thanks,
Shameer

[1]. https://lkml.org/lkml/2018/6/5/897

Quoted 3 lines

Alex

[1] https://lkml.org/lkml/2018/4/18/293

#8 lore raw

PATCH 2/2 vfio:iommu: Get DMA information from real IOMMU

In reply to Pierre Morel

We report the real IOMMU geometry through the VFIO_IOMMU_GET_INFO ioctl call when the vfio_iommu_type1_info support capabilities.

---
 drivers/vfio/vfio_iommu_type1.c | 43 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)
drivers/vfio/vfio_iommu_type1.c +42 -1
index d9fd318..0a7746c 100644
@@ -1673,6 +1673,23 @@ static int vfio_domains_have_iommu_cache(struct vfio_iommu *iommu)
 	return ret;
 }
 
+static int vfio_iommu_type1_caps(struct vfio_iommu *iommu,
+				 struct vfio_info_cap *caps)
+{
+	struct vfio_domain *d;
+	struct vfio_iommu_cap_dma info = { .header.id = VFIO_IOMMU_INFO_CAP_DMA,
+					   .header.version = 1 };
+	int ret;
+
+	d = list_first_entry(&iommu->domain_list, struct vfio_domain, next);
+	if (!d || !d->domain)
+		return -ENODEV;
+	info.dma_start = d->domain->geometry.aperture_start;
+	info.dma_end = d->domain->geometry.aperture_end;
+	ret = vfio_info_add_capability(caps, &info.header, sizeof(info));
+	return ret;
+}
+
 static long vfio_iommu_type1_ioctl(void *iommu_data,
 				   unsigned int cmd, unsigned long arg)
 {
@@ -1694,6 +1711,8 @@ static long vfio_iommu_type1_ioctl(void *iommu_data,
 		}
 	} else if (cmd == VFIO_IOMMU_GET_INFO) {
 		struct vfio_iommu_type1_info info;
+		struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
+		int ret;
 
 		minsz = offsetofend(struct vfio_iommu_type1_info, iova_pgsizes);
 
@@ -1703,7 +1722,29 @@ static long vfio_iommu_type1_ioctl(void *iommu_data,
 		if (info.argsz < minsz)
 			return -EINVAL;
 
-		info.flags = VFIO_IOMMU_INFO_PGSIZES;
+		if (info.flags & VFIO_IOMMU_INFO_CAPABILITIES) {
+			ret = vfio_iommu_type1_caps(iommu, &caps);
+			if (ret)
+				return ret;
+		}
+		if (caps.size) {
+			if (info.argsz < sizeof(info) + caps.size) {
+				info.argsz = sizeof(info) + caps.size;
+				info.cap_offset = 0;
+			} else {
+				vfio_info_cap_shift(&caps, sizeof(info));
+				if (copy_to_user((void __user *)arg +
+					sizeof(info), caps.buf,
+					caps.size)) {
+					kfree(caps.buf);
+					return -EFAULT;
+				}
+				info.cap_offset = sizeof(info);
+			}
+			kfree(caps.buf);
+		}
+
+		info.flags |= VFIO_IOMMU_INFO_PGSIZES;
 
 		info.iova_pgsizes = vfio_pgsize_bitmap(iommu);
 
Signature · 1 line
2.7.4