From: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
To: <linux-kernel@vger.kernel.org>, <iommu@lists.linux.dev>
Cc: <joro@8bytes.org>, <robin.murphy@arm.com>, <ashish.kalra@amd.com>,
<thomas.lendacky@amd.com>, <vasant.hegde@amd.com>,
<jon.grimm@amd.com>,
Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Subject: [PATCH 1/4] iommu/amd: Introduce Protection-domain flag VFIO
Date: Tue, 10 Jan 2023 08:31:34 -0600 [thread overview]
Message-ID: <20230110143137.54517-2-suravee.suthikulpanit@amd.com> (raw)
In-Reply-To: <20230110143137.54517-1-suravee.suthikulpanit@amd.com>
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>
---
drivers/iommu/amd/amd_iommu_types.h | 1 +
drivers/iommu/amd/iommu.c | 7 +++++--
2 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h
index 1d0a70c85333..ad124959a26a 100644
--- a/drivers/iommu/amd/amd_iommu_types.h
+++ b/drivers/iommu/amd/amd_iommu_types.h
@@ -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...) \
diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 3847f3bdc568..681ab1fdb7d5 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -2056,6 +2056,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) {
@@ -2130,6 +2132,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))
@@ -2144,7 +2147,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
@@ -2176,7 +2179,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;
--
2.32.0
next prev parent reply other threads:[~2023-01-10 14:32 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-10 14:31 [PATCH 0/4] iommu/amd: Force SNP-enabled VFIO domain to 4K page size Suravee Suthikulpanit
2023-01-10 14:31 ` Suravee Suthikulpanit [this message]
2023-01-11 3:31 ` [PATCH 1/4] iommu/amd: Introduce Protection-domain flag VFIO kernel test robot
2023-01-13 15:33 ` Jason Gunthorpe
2023-01-19 8:54 ` Kalra, Ashish
2023-01-19 17:44 ` Jason Gunthorpe
2023-01-20 15:12 ` Kalra, Ashish
2023-01-20 16:13 ` Jason Gunthorpe
2023-01-20 17:01 ` Kalra, Ashish
2023-01-20 17:50 ` Jason Gunthorpe
2023-01-20 19:55 ` Kalra, Ashish
2023-01-20 22:42 ` Tom Lendacky
2023-01-21 0:09 ` Jason Gunthorpe
2023-01-10 14:31 ` [PATCH 2/4] iommu/amd: Introduce structure amd_iommu_svm_ops.is_snp_guest() Suravee Suthikulpanit
2023-01-10 14:31 ` [PATCH 3/4] iommu: Introduce IOMMU call-back for processing struct KVM assigned to VFIO Suravee Suthikulpanit
2023-01-10 15:11 ` Robin Murphy
2023-01-17 4:20 ` Suthikulpanit, Suravee
2023-01-17 12:51 ` Robin Murphy
2023-01-13 15:35 ` Jason Gunthorpe
2023-01-17 5:31 ` Suthikulpanit, Suravee
2023-01-17 14:19 ` Jason Gunthorpe
2023-01-10 14:31 ` [PATCH 4/4] iommu/amd: Force SNP-enabled VFIO domain to 4K page size Suravee Suthikulpanit
2023-01-17 13:10 ` Eric van Tassell
2023-01-16 13:17 ` [PATCH 0/4] " Eric van Tassell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230110143137.54517-2-suravee.suthikulpanit@amd.com \
--to=suravee.suthikulpanit@amd.com \
--cc=ashish.kalra@amd.com \
--cc=iommu@lists.linux.dev \
--cc=jon.grimm@amd.com \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=thomas.lendacky@amd.com \
--cc=vasant.hegde@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).