Skip to content

Commit

Permalink
iommu/amd: Introduce Protection-domain flag VFIO
Browse files Browse the repository at this point in the history
Currently, to detect if a domain is enabled with VFIO support, the driver
checks if the domain has devices attached and check if the domain type is
IOMMU_DOMAIN_UNMANAGED.

To be more explicit, introduce protection-domain flag PD_VFIO_MASK
to signify an VFIO-enabled  domain is enabled with VFIO support.

Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
  • Loading branch information
ssuthiku-amd authored and intel-lab-lkp committed Jan 10, 2023
1 parent e806e22 commit ea80bf7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions drivers/iommu/amd/amd_iommu_types.h
Expand Up @@ -439,6 +439,7 @@
translation */
#define PD_IOMMUV2_MASK (1UL << 3) /* domain has gcr3 table */
#define PD_GIOV_MASK (1UL << 4) /* domain enable GIOV support */
#define PD_VFIO_MASK (1UL << 5) /* domain enable VFIO support */

extern bool amd_iommu_dump;
#define DUMP_printk(format, arg...) \
Expand Down
7 changes: 5 additions & 2 deletions drivers/iommu/amd/iommu.c
Expand Up @@ -2057,6 +2057,8 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
mode = PAGE_MODE_NONE;
} else if (type == IOMMU_DOMAIN_UNMANAGED) {
pgtable = AMD_IOMMU_V1;
/* Mark unmanaged domain for VFIO */
domain->flags |= PD_VFIO_MASK;
}

switch (pgtable) {
Expand Down Expand Up @@ -2131,6 +2133,7 @@ static void amd_iommu_detach_device(struct iommu_domain *dom,
struct device *dev)
{
struct iommu_dev_data *dev_data = dev_iommu_priv_get(dev);
struct protection_domain *domain = to_pdomain(dom);
struct amd_iommu *iommu;

if (!check_device(dev))
Expand All @@ -2145,7 +2148,7 @@ static void amd_iommu_detach_device(struct iommu_domain *dom,

#ifdef CONFIG_IRQ_REMAP
if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir) &&
(dom->type == IOMMU_DOMAIN_UNMANAGED))
(domain->flags & PD_VFIO_MASK))
dev_data->use_vapic = 0;
#endif

Expand Down Expand Up @@ -2177,7 +2180,7 @@ static int amd_iommu_attach_device(struct iommu_domain *dom,

#ifdef CONFIG_IRQ_REMAP
if (AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)) {
if (dom->type == IOMMU_DOMAIN_UNMANAGED)
if (domain->flags & PD_VFIO_MASK)
dev_data->use_vapic = 1;
else
dev_data->use_vapic = 0;
Expand Down

0 comments on commit ea80bf7

Please sign in to comment.