From: Vasant Hegde <vasant.hegde@amd.com>
To: Ankit Soni <Ankit.Soni@amd.com>, iommu@lists.linux.dev
Cc: suravee.suthikulpanit@amd.com, joro@8bytes.org, will@kernel.org,
robin.murphy@arm.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] iommu/amd: Add HATDis feature support
Date: Wed, 30 Apr 2025 17:05:02 +0530 [thread overview]
Message-ID: <193f5eee-18a9-4b13-a433-ed05f86f8e46@amd.com> (raw)
In-Reply-To: <6282a5c349812a311a67a8522dc5e4aabfe3ec3a.1745389415.git.Ankit.Soni@amd.com>
Hi,
On 4/23/2025 12:20 PM, Ankit Soni wrote:
> Current AMD IOMMU assumes Host Address Translation (HAT) is always
> supported, and Linux kernel enables this capability by default. However,
> in case of emulated and virtualized IOMMU, this might not be the case.
> For example,current QEMU-emulated AMD vIOMMU does not support host
> translation for VFIO pass-through device, but the interrupt remapping
> support is required for x2APIC (i.e. kvm-msi-ext-dest-id is also not
> supported by the guest OS). This would require the guest kernel to boot
> with guest kernel option iommu=pt to by-pass the initialization of> host (v1)
table.
>
> The AMD I/O Virtualization Technology (IOMMU) Specification Rev 3.10 [1]
> introduces a new flag 'HATDis' in the IVHD 11h IOMMU attributes to indicate
> that HAT is not supported on a particular IOMMU instance.
>
> Therefore, modifies the AMD IOMMU driver to detect the new HATDis
> attributes, and disable host translation and switch to use guest
> translation if it is available. Otherwise, the driver will disable DMA
> translation.
>
> [1] https://www.amd.com/content/dam/amd/en/documents/processor-tech-docs/specifications/48882_IOMMU.pdf
>
> Reviewed-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
> Signed-off-by: Ankit Soni <Ankit.Soni@amd.com>
> ---
> drivers/iommu/amd/amd_iommu.h | 1 +
> drivers/iommu/amd/amd_iommu_types.h | 6 +++++-
> drivers/iommu/amd/init.c | 23 +++++++++++++++++++++--
> drivers/iommu/amd/iommu.c | 13 +++++++++++++
> 4 files changed, 40 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h
> index 220c598b7e14..bb14c4800dd0 100644
> --- a/drivers/iommu/amd/amd_iommu.h
> +++ b/drivers/iommu/amd/amd_iommu.h
> @@ -43,6 +43,7 @@ extern int amd_iommu_guest_ir;
> extern enum protection_domain_mode amd_iommu_pgtable;
> extern int amd_iommu_gpt_level;
> extern unsigned long amd_iommu_pgsize_bitmap;
> +extern bool amd_iommu_hatdis;
>
> /* Protection domain ops */
> void amd_iommu_init_identity_domain(void);
> diff --git a/drivers/iommu/amd/amd_iommu_types.h b/drivers/iommu/amd/amd_iommu_types.h
> index 5089b58e528a..284ff4309660 100644
> --- a/drivers/iommu/amd/amd_iommu_types.h
> +++ b/drivers/iommu/amd/amd_iommu_types.h
> @@ -460,6 +460,9 @@
> /* IOMMU Feature Reporting Field (for IVHD type 10h */
> #define IOMMU_FEAT_GASUP_SHIFT 6
>
> +/* IOMMU HATDIS for IVHD type 11h and 40h */
> +#define IOMMU_IVHD_ATTR_HATDIS_SHIFT 0
> +
> /* IOMMU Extended Feature Register (EFR) */
> #define IOMMU_EFR_XTSUP_SHIFT 2
> #define IOMMU_EFR_GASUP_SHIFT 7
> @@ -558,7 +561,8 @@ struct amd_io_pgtable {
> };
>
> enum protection_domain_mode {
> - PD_MODE_V1 = 1,
> + PD_MODE_NONE,
> + PD_MODE_V1,
> PD_MODE_V2,
> };
>
> diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
> index dd9e26b7b718..f71b236c2af2 100644
> --- a/drivers/iommu/amd/init.c
> +++ b/drivers/iommu/amd/init.c
> @@ -151,7 +151,7 @@ struct ivmd_header {
> bool amd_iommu_dump;
> bool amd_iommu_irq_remap __read_mostly;
>
> -enum protection_domain_mode amd_iommu_pgtable = PD_MODE_V1;
> +enum protection_domain_mode amd_iommu_pgtable = PD_MODE_NONE;
Why not keep it as `PD_MODE_V1` (as its our default page table) so that we can
remove explict `PD_MODE_V1` assignment in below hunk?
> /* Guest page table level */
> int amd_iommu_gpt_level = PAGE_MODE_4_LEVEL;
>
> @@ -168,6 +168,9 @@ static int amd_iommu_target_ivhd_type;
> u64 amd_iommu_efr;
> u64 amd_iommu_efr2;
>
> +/* dma translation not supported*/
Host (v2) page table is not supported.
> +bool amd_iommu_hatdis;
> +
> /* SNP is enabled on the system? */
> bool amd_iommu_snp_en;
> EXPORT_SYMBOL(amd_iommu_snp_en);
> @@ -1798,6 +1801,11 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h,
> if (h->efr_reg & BIT(IOMMU_EFR_XTSUP_SHIFT))
> amd_iommu_xt_mode = IRQ_REMAP_X2APIC_MODE;
>
> + if (h->efr_attr & BIT(IOMMU_IVHD_ATTR_HATDIS_SHIFT)) {
> + pr_warn_once("Host Address Translation is not supported.\n");
> + amd_iommu_hatdis = true;
> + }
> +
> early_iommu_features_init(iommu, h);
>
> break;
> @@ -2582,7 +2590,7 @@ static void init_device_table_dma(struct amd_iommu_pci_seg *pci_seg)
> u32 devid;
> struct dev_table_entry *dev_table = pci_seg->dev_table;
>
> - if (dev_table == NULL)
> + if (!dev_table || amd_iommu_pgtable == PD_MODE_NONE)
> return;
>
> for (devid = 0; devid <= pci_seg->last_bdf; ++devid) {
> @@ -3095,6 +3103,17 @@ static int __init early_amd_iommu_init(void)
> }
> }
>
> + if (amd_iommu_hatdis) {
I missed it in the internal review. This introduces ordering dependency (v2 page
table check should be done before this). IMO its worth to add an explicit
comment so that its clear.
-Vasant
next prev parent reply other threads:[~2025-04-30 11:35 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-23 6:50 [PATCH 0/2] iommu/amd: Support for HATdis and HATS features Ankit Soni
2025-04-23 6:50 ` [PATCH 1/2] iommu/amd: Add HATDis feature support Ankit Soni
2025-04-24 12:19 ` Joao Martins
2025-04-25 16:25 ` Ankit Soni
2025-04-30 11:41 ` Joao Martins
2025-05-06 5:12 ` Ankit Soni
2025-05-08 17:03 ` Joao Martins
2025-05-12 6:30 ` Ankit Soni
2025-05-28 12:19 ` Vasant Hegde
2025-05-30 4:32 ` Ankit Soni
2025-04-30 11:52 ` Vasant Hegde
2025-04-30 11:35 ` Vasant Hegde [this message]
2025-05-05 6:30 ` Ankit Soni
2025-04-23 6:50 ` [PATCH 2/2] iommu/amd: Add efr[HATS] max v1 page table level Ankit Soni
2025-04-30 11:57 ` Vasant Hegde
2025-05-06 15:27 ` Jason Gunthorpe
2025-05-07 6:24 ` Vasant Hegde
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=193f5eee-18a9-4b13-a433-ed05f86f8e46@amd.com \
--to=vasant.hegde@amd.com \
--cc=Ankit.Soni@amd.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robin.murphy@arm.com \
--cc=suravee.suthikulpanit@amd.com \
--cc=will@kernel.org \
/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
all inboxes | Powered by JetHome®