提交 9db83ab7 编写于 作者: E Eric Auger 提交者: Zheng Zengkai

iommu: Introduce bind/unbind_guest_msi

virt inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I401IF
CVE: NA

------------------------------

On ARM, MSI are translated by the SMMU. An IOVA is allocated
for each MSI doorbell. If both the host and the guest are exposed
with SMMUs, we end up with 2 different IOVAs allocated by each.
guest allocates an IOVA (gIOVA) to map onto the guest MSI
doorbell (gDB). The Host allocates another IOVA (hIOVA) to map
onto the physical doorbell (hDB).

So we end up with 2 untied mappings:
         S1            S2
gIOVA    ->    gDB
              hIOVA    ->    hDB

Currently the PCI device is programmed by the host with hIOVA
as MSI doorbell. So this does not work.

This patch introduces an API to pass gIOVA/gDB to the host so
that gIOVA can be reused by the host instead of re-allocating
a new IOVA. So the goal is to create the following nested mapping:

         S1            S2
gIOVA    ->    gDB     ->    hDB

and program the PCI device with gIOVA MSI doorbell.

In case we have several devices attached to this nested domain
(devices belonging to the same group), they cannot be isolated
on guest side either. So they should also end up in the same domain
on guest side. We will enforce that all the devices attached to
the host iommu domain use the same physical doorbell and similarly
a single virtual doorbell mapping gets registered (1 single
virtual doorbell is used on guest as well).
Signed-off-by: NEric Auger <eric.auger@redhat.com>
Signed-off-by: Kunkun Jiang<jiangkunkun@huawei.com>
Reviewed-by: NKeqian Zhu <zhukeqian1@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 dbb4844d
......@@ -2424,6 +2424,43 @@ static void __iommu_detach_device(struct iommu_domain *domain,
trace_detach_device_from_domain(dev);
}
/**
* iommu_bind_guest_msi - Passes the stage1 GIOVA/GPA mapping of a
* virtual doorbell
*
* @domain: iommu domain the stage 1 mapping will be attached to
* @iova: iova allocated by the guest
* @gpa: guest physical address of the virtual doorbell
* @size: granule size used for the mapping
*
* The associated IOVA can be reused by the host to create a nested
* stage2 binding mapping translating into the physical doorbell used
* by the devices attached to the domain.
*
* All devices within the domain must share the same physical doorbell.
* A single MSI GIOVA/GPA mapping can be attached to an iommu_domain.
*/
int iommu_bind_guest_msi(struct iommu_domain *domain,
dma_addr_t giova, phys_addr_t gpa, size_t size)
{
if (unlikely(!domain->ops->bind_guest_msi))
return -ENODEV;
return domain->ops->bind_guest_msi(domain, giova, gpa, size);
}
EXPORT_SYMBOL_GPL(iommu_bind_guest_msi);
void iommu_unbind_guest_msi(struct iommu_domain *domain,
dma_addr_t giova)
{
if (unlikely(!domain->ops->unbind_guest_msi))
return;
domain->ops->unbind_guest_msi(domain, giova);
}
EXPORT_SYMBOL_GPL(iommu_unbind_guest_msi);
void iommu_detach_device(struct iommu_domain *domain, struct device *dev)
{
struct iommu_group *group;
......
......@@ -245,6 +245,8 @@ struct iommu_iotlb_gather {
* @sva_unbind_gpasid: unbind guest pasid and mm
* @attach_pasid_table: attach a pasid table
* @detach_pasid_table: detach the pasid table
* @bind_guest_msi: provides a stage1 giova/gpa MSI doorbell mapping
* @unbind_guest_msi: withdraw a stage1 giova/gpa MSI doorbell mapping
* @def_domain_type: device default domain type, return value:
* - IOMMU_DOMAIN_IDENTITY: must use an identity domain
* - IOMMU_DOMAIN_DMA: must use a dma domain
......@@ -342,6 +344,10 @@ struct iommu_ops {
int (*def_domain_type)(struct device *dev);
int (*bind_guest_msi)(struct iommu_domain *domain,
dma_addr_t giova, phys_addr_t gpa, size_t size);
void (*unbind_guest_msi)(struct iommu_domain *domain, dma_addr_t giova);
unsigned long pgsize_bitmap;
struct module *owner;
};
......@@ -487,6 +493,10 @@ extern int iommu_attach_pasid_table(struct iommu_domain *domain,
extern int iommu_uapi_attach_pasid_table(struct iommu_domain *domain,
void __user *udata);
extern void iommu_detach_pasid_table(struct iommu_domain *domain);
extern int iommu_bind_guest_msi(struct iommu_domain *domain,
dma_addr_t giova, phys_addr_t gpa, size_t size);
extern void iommu_unbind_guest_msi(struct iommu_domain *domain,
dma_addr_t giova);
extern struct iommu_domain *iommu_get_domain_for_dev(struct device *dev);
extern struct iommu_domain *iommu_get_dma_domain(struct device *dev);
extern size_t iommu_pgsize(struct iommu_domain *domain,
......@@ -1193,6 +1203,14 @@ iommu_sva_bind_group(struct iommu_group *group, struct mm_struct *mm,
return NULL;
}
int iommu_bind_guest_msi(struct iommu_domain *domain,
dma_addr_t giova, phys_addr_t gpa, size_t size)
{
return -ENODEV;
}
static inline
void iommu_unbind_guest_msi(struct iommu_domain *domain, dma_addr_t giova) {}
#endif /* CONFIG_IOMMU_API */
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册