[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v11 07/10] memory: Add interface to set iommu page size mask
From: |
Jean-Philippe Brucker |
Subject: |
[PATCH v11 07/10] memory: Add interface to set iommu page size mask |
Date: |
Fri, 30 Oct 2020 19:05:07 +0100 |
From: Bharat Bhushan <bbhushan2@marvell.com>
Allow to set the page size mask supported by an iommu memory region.
This enables a vIOMMU to communicate the page size granule supported by
an assigned device, on hosts that use page sizes greater than 4kB.
Acked-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Bharat Bhushan <bbhushan2@marvell.com>
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
v11: improve comment
---
include/exec/memory.h | 38 ++++++++++++++++++++++++++++++++++++++
softmmu/memory.c | 13 +++++++++++++
2 files changed, 51 insertions(+)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index aff6ef76053..0f3e6bcd5e7 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -397,6 +397,32 @@ struct IOMMUMemoryRegionClass {
* @iommu: the IOMMUMemoryRegion
*/
int (*num_indexes)(IOMMUMemoryRegion *iommu);
+
+ /**
+ * @iommu_set_page_size_mask:
+ *
+ * Restrict the page size mask that can be supported with a given IOMMU
+ * memory region. Used for example to propagate host physical IOMMU page
+ * size mask limitations to the virtual IOMMU.
+ *
+ * Optional method: if this method is not provided, then the default global
+ * page mask is used.
+ *
+ * @iommu: the IOMMUMemoryRegion
+ *
+ * @page_size_mask: a bitmask of supported page sizes. At least one bit,
+ * representing the smallest page size, must be set. Additional set bits
+ * represent supported block sizes. For example a host physical IOMMU that
+ * uses page tables with a page size of 4kB, and supports 2MB and 4GB
+ * blocks, will set mask 0x40201000. A granule of 4kB with indiscriminate
+ * block sizes is specified with mask 0xfffffffffffff000.
+ *
+ * Returns 0 on success, or a negative error. In case of failure, the error
+ * object must be created.
+ */
+ int (*iommu_set_page_size_mask)(IOMMUMemoryRegion *iommu,
+ uint64_t page_size_mask,
+ Error **errp);
};
typedef struct CoalescedMemoryRange CoalescedMemoryRange;
@@ -1409,6 +1435,18 @@ int memory_region_iommu_attrs_to_index(IOMMUMemoryRegion
*iommu_mr,
*/
int memory_region_iommu_num_indexes(IOMMUMemoryRegion *iommu_mr);
+/**
+ * memory_region_iommu_set_page_size_mask: set the supported page
+ * sizes for a given IOMMU memory region
+ *
+ * @iommu_mr: IOMMU memory region
+ * @page_size_mask: supported page size mask
+ * @errp: pointer to Error*, to store an error if it happens.
+ */
+int memory_region_iommu_set_page_size_mask(IOMMUMemoryRegion *iommu_mr,
+ uint64_t page_size_mask,
+ Error **errp);
+
/**
* memory_region_name: get a memory region's name
*
diff --git a/softmmu/memory.c b/softmmu/memory.c
index ee4a6bc1685..bb40d2a1d8b 100644
--- a/softmmu/memory.c
+++ b/softmmu/memory.c
@@ -1841,6 +1841,19 @@ static int
memory_region_update_iommu_notify_flags(IOMMUMemoryRegion *iommu_mr,
return ret;
}
+int memory_region_iommu_set_page_size_mask(IOMMUMemoryRegion *iommu_mr,
+ uint64_t page_size_mask,
+ Error **errp)
+{
+ IOMMUMemoryRegionClass *imrc = IOMMU_MEMORY_REGION_GET_CLASS(iommu_mr);
+ int ret = 0;
+
+ if (imrc->iommu_set_page_size_mask) {
+ ret = imrc->iommu_set_page_size_mask(iommu_mr, page_size_mask, errp);
+ }
+ return ret;
+}
+
int memory_region_register_iommu_notifier(MemoryRegion *mr,
IOMMUNotifier *n, Error **errp)
{
--
2.29.1
- [PATCH v11 00/10] virtio-iommu: VFIO integration, Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 01/10] virtio-iommu: Fix virtio_iommu_mr(), Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 04/10] virtio-iommu: Call memory notifiers in attach/detach, Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 03/10] virtio-iommu: Add memory notifiers for map/unmap, Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 06/10] virtio-iommu: Add notify_flag_changed() memory region callback, Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 02/10] virtio-iommu: Store memory region in endpoint struct, Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 09/10] virtio-iommu: Set supported page size mask, Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 08/10] vfio: Set IOMMU page size as per host supported page size, Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 10/10] vfio: Don't issue full 2^64 unmap, Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 05/10] virtio-iommu: Add replay() memory region callback, Jean-Philippe Brucker, 2020/10/30
- [PATCH v11 07/10] memory: Add interface to set iommu page size mask,
Jean-Philippe Brucker <=