[PATCH v3 7/7] iommu/amd: Do not support IOMMUv2 APIs when SNP is enabled

2022-06-22 Thread Suravee Suthikulpanit via iommu
The IOMMUv2 APIs (for supporting shared virtual memory with PASID) configures the domain with IOMMU v2 page table, and sets DTE[Mode]=0. This configuration cannot be supported on SNP-enabled system. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/init.c | 7 ++- 1 file changed, 6

[PATCH v3 0/7] iommu/amd: Enforce IOMMU restrictions for SNP-enabled system

2022-06-22 Thread Suravee Suthikulpanit via iommu
SNP-enabled system requires IOMMU v1 page table to be configured with non-zero DTE[Mode] for DMA-capable devices. This effects a number of usecases such as IOMMU pass-through mode and AMD IOMMUv2 APIs for binding/unbinding pasid. The series introduce a global variable to check SNP-enabled state du

[PATCH v3 6/7] iommu/amd: Do not support IOMMU_DOMAIN_IDENTITY after SNP is enabled

2022-06-22 Thread Suravee Suthikulpanit via iommu
Once SNP is enabled (by executing SNP_INIT command), IOMMU can no longer support the passthrough domain (i.e. IOMMU_DOMAIN_IDENTITY). The SNP_INIT command is called early in the boot process, and would fail if the kernel is configure to default to passthrough mode. After the system is already boo

[PATCH v3 4/7] iommu/amd: Introduce function to check and enable SNP

2022-06-22 Thread Suravee Suthikulpanit via iommu
From: Brijesh Singh To support SNP, IOMMU needs to be enabled, and prohibits IOMMU configurations where DTE[Mode]=0, which means it cannot be supported with IOMMU passthrough domain (a.k.a IOMMU_DOMAIN_IDENTITY), and when AMD IOMMU driver is configured to not use the IOMMU host (v1) page table. O

[PATCH v3 5/7] iommu/amd: Set translation valid bit only when IO page tables are in use

2022-06-22 Thread Suravee Suthikulpanit via iommu
On AMD system with SNP enabled, IOMMU hardware checks the host translation valid (TV) and guest translation valid (GV) bits in the device table entry (DTE) before accessing the corresponded page tables. However, current IOMMU driver sets the TV bit for all devices regardless of whether the host pa

[PATCH v3 3/7] iommu/amd: Introduce an iommu variable for tracking SNP support status

2022-06-22 Thread Suravee Suthikulpanit via iommu
EFR[SNPSup] needs to be checked early in the boot process, since it is used to determine how IOMMU driver configures other IOMMU features and data structures. This check can be done as soon as the IOMMU driver finishes parsing IVHDs. Introduce a variable for tracking the SNP support status, which

[PATCH v3 1/7] iommu/amd: Warn when found inconsistency EFR mask

2022-06-22 Thread Suravee Suthikulpanit via iommu
The function check_feature_on_all_iommus() checks to ensure if an IOMMU feature support bit is set on the Extended Feature Register (EFR). Current logic iterates through all IOMMU, and returns false when it found the first unset bit. To provide more thorough checking, modify the logic to iterate t

[PATCH v3 2/7] iommu/amd: Process all IVHDs before enabling IOMMU features

2022-06-22 Thread Suravee Suthikulpanit via iommu
The ACPI IVRS table can contain multiple IVHD blocks. Each block contains information used to initialize each IOMMU instance. Currently, init_iommu_all sequentially process IVHD block and initialize IOMMU instance one-by-one. However, certain features require all IOMMUs to be configured in the sam

[PATCH v2 4/7] iommu/amd: Introduce function to check and enable SNP

2022-06-15 Thread Suravee Suthikulpanit via iommu
From: Brijesh Singh To support SNP, IOMMU needs to be enabled, and prohibits IOMMU configurations where DTE[Mode]=0, which means it cannot be supported with IOMMU passthrough domain (a.k.a IOMMU_DOMAIN_IDENTITY), and when AMD IOMMU driver is configured to not use the IOMMU host (v1) page table. O

[PATCH v2 2/7] iommu/amd: Process all IVHDs before enabling IOMMU features

2022-06-15 Thread Suravee Suthikulpanit via iommu
The ACPI IVRS table can contain multiple IVHD blocks. Each block contains information used to initialize each IOMMU instance. Currently, init_iommu_all sequentially process IVHD block and initialize IOMMU instance one-by-one. However, certain features require all IOMMUs to be configured in the sam

[PATCH v2 7/7] iommu/amd: Do not support IOMMUv2 APIs when SNP is enabled

2022-06-15 Thread Suravee Suthikulpanit via iommu
The IOMMUv2 APIs (for supporting shared virtual memory with PASID) configures the domain with IOMMU v2 page table, and sets DTE[Mode]=0. This configuration cannot be supported on SNP-enabled system. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/init.c | 7 ++- 1 file changed, 6

[PATCH v2 6/7] iommu/amd: Do not support IOMMU_DOMAIN_IDENTITY after SNP is enabled

2022-06-15 Thread Suravee Suthikulpanit via iommu
Once SNP is enabled (by executing SNP_INIT command), IOMMU can no longer support the passthrough domain (i.e. IOMMU_DOMAIN_IDENTITY). The SNP_INIT command is called early in the boot process, and would fail if the kernel is configure to default to passthrough mode. After the system is already boo

[PATCH v2 3/7] iommu/amd: Introduce an iommu variable for tracking SNP support status

2022-06-15 Thread Suravee Suthikulpanit via iommu
EFR[SNPSup] needs to be checked early in the boot process, since it is used to determine how IOMMU driver configures other IOMMU features and data structures. This check can be done as soon as the IOMMU driver finishes parsing IVHDs. Introduce a variable for tracking the SNP support status, which

[PATCH v2 5/7] iommu/amd: Set translation valid bit only when IO page tables are in use

2022-06-15 Thread Suravee Suthikulpanit via iommu
On AMD system with SNP enabled, IOMMU hardware checks the host translation valid (TV) and guest translation valid (GV) bits in the device table entry (DTE) before accessing the corresponded page tables. However, current IOMMU driver sets the TV bit for all devices regardless of whether the host pa

[PATCH v2 0/7] iommu/amd: Enforce IOMMU restrictions for SNP-enabled system

2022-06-15 Thread Suravee Suthikulpanit via iommu
SNP-enabled system requires IOMMU v1 page table to be configured with non-zero DTE[Mode] for DMA-capable devices. This effects a number of usecases such as IOMMU pass-through mode and AMD IOMMUv2 APIs for binding/unbinding pasid. The series introduce a global variable to check SNP-enabled state du

[PATCH v2 1/7] iommu/amd: Warn when found inconsistency EFR mask

2022-06-15 Thread Suravee Suthikulpanit via iommu
The function check_feature_on_all_iommus() checks to ensure if an IOMMU feature support bit is set on the Extended Feature Register (EFR). Current logic iterates through all IOMMU, and returns false when it found the first unset bit. To provide more thorough checking, modify the logic to iterate t

[PATCH 6/7] iommu/amd: Do not support IOMMU_DOMAIN_IDENTITY when SNP is enabled

2022-06-12 Thread Suravee Suthikulpanit via iommu
Since DTE[Mode]=0 is prohibited on system, which enables SNP, the passthrough domain (IOMMU_DOMAIN_IDENTITY) is not support. Instead, only support IOMMU_DOMAIN_DMA[_FQ] domains. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/iommu.c | 12 1 file changed, 12 insertions(+)

[PATCH 3/7] iommu/amd: Introduce function to check SEV-SNP support

2022-06-12 Thread Suravee Suthikulpanit via iommu
From: Brijesh Singh The SEV-SNP support requires that IOMMU must to enabled. It also prohibits IOMMU configurations where DTE[Mode]=0, which means the SEV-SNP feature is not supported with IOMMU passthrough domain (a.k.a IOMMU_DOMAIN_IDENTITY), or when AMD IOMMU driver is configured to not use th

[PATCH 4/7] iommu/amd: Set translation valid bit only when IO page tables are in use

2022-06-12 Thread Suravee Suthikulpanit via iommu
On AMD system with SNP enabled, IOMMU hardware checks the host translation valid (TV) and guest translation valid (GV) bits in the device table entry (DTE) before accessing the corresponded page tables. However, current IOMMU driver sets the TV bit for all devices regardless of whether the host pa

[PATCH 7/7] iommu/amd: Do not support IOMMUv2 APIs when SNP is enabled

2022-06-12 Thread Suravee Suthikulpanit via iommu
The IOMMUv2 APIs (for supporting shared virtual memory with PASID) configures the domain with IOMMU v2 page table, and sets DTE[Mode]=0. This configuration cannot be supported on SNP-enabled system. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/init.c | 7 ++- 1 file changed, 6

[PATCH 1/7] iommu/amd: Process all IVHDs before enabling IOMMU features

2022-06-12 Thread Suravee Suthikulpanit via iommu
The ACPI IVRS table can contain multiple IVHD blocks. Each block contains information used to initialize each IOMMU instance. Currently, init_iommu_all sequentially process IVHD block and initialize IOMMU instance one-by-one. However, certain features require all IOMMUs to be configured in the sam

[PATCH 2/7] iommu/amd: Introduce a global variable for tracking SNP enable status

2022-06-12 Thread Suravee Suthikulpanit via iommu
IOMMU support for SNP feature is detected via the EFR[SNPSup] bit. Also, it is required that EFR[SNPSup] are consistent across all IOMMU instances. This information is needed early in the boot process, since it is used to determine how IOMMU driver configures several other IOMMU features and data

[PATCH 5/7] iommu: Add domain_type_supported() callback in iommu_ops

2022-06-12 Thread Suravee Suthikulpanit via iommu
When user requests to change IOMMU domain to a new type, IOMMU generic layer checks the requested type against the default domain type returned by vendor-specific IOMMU driver. However, there is only one default domain type, and current mechanism does not allow if the requested type does not match

[PATCH 0/7] iommu/amd: Enforce IOMMU restrictions for SNP-enabled system

2022-06-12 Thread Suravee Suthikulpanit via iommu
SNP-enabled system requires IOMMU v1 page table to be configured with non-zero DTE[Mode] for DMA-capable devices. This effects a number of usecases such as IOMMU pass-through mode and AMD IOMMUv2 APIs for binding/unbinding pasid. The series introduce a global variable to check SNP-enabled state du

Re: [PATCH RFC 10/19] iommu/amd: Add unmap_read_dirty() support

2022-05-31 Thread Suravee Suthikulpanit via iommu
On 4/29/22 4:09 AM, Joao Martins wrote: AMD implementation of unmap_read_dirty() is pretty simple as mostly reuses unmap code with the extra addition of marshalling the dirty bit into the bitmap as it walks the to-be-unmapped IOPTE. Extra care is taken though, to switch over to cmpxchg as opp

Re: [PATCH RFC 09/19] iommu/amd: Access/Dirty bit support in IOPTEs

2022-05-31 Thread Suravee Suthikulpanit via iommu
Joao, On 4/29/22 4:09 AM, Joao Martins wrote: . +static int amd_iommu_set_dirty_tracking(struct iommu_domain *domain, + bool enable) +{ + struct protection_domain *pdomain = to_pdomain(domain); + struct iommu_dev_data *dev_data; + bool

Re: [PATCH v2] iommu/amd: Set translation valid bit only when IO page tables are in used

2022-05-25 Thread Suravee Suthikulpanit via iommu
Joerg, On 5/20/22 3:09 PM, Joerg Roedel wrote: Hi Suravee, On Mon, May 16, 2022 at 07:27:51PM +0700, Suravee Suthikulpanit wrote: - Also, it seems that the current iommu v2 page table use case, where GVA->GPA=SPA will no longer be supported on system w/ SNPSup=1. Any thoughts? Support for

Re: [PATCH v2] iommu/amd: Set translation valid bit only when IO page tables are in used

2022-05-16 Thread Suravee Suthikulpanit via iommu
Joerg, On 5/13/22 8:07 PM, Joerg Roedel wrote: On Mon, May 09, 2022 at 02:48:15AM -0500, Suravee Suthikulpanit wrote: On AMD system with SNP enabled, IOMMU hardware checks the host translation valid (TV) and guest translation valid (GV) bits in the device table entry (DTE) before accessing the

[PATCH v2] iommu/amd: Set translation valid bit only when IO page tables are in used

2022-05-09 Thread Suravee Suthikulpanit via iommu
On AMD system with SNP enabled, IOMMU hardware checks the host translation valid (TV) and guest translation valid (GV) bits in the device table entry (DTE) before accessing the corresponded page tables. However, current IOMMU driver sets the TV bit for all devices regardless of whether the host pa

Re: [PATCH] iommu/amd: Set translation valid bit only when IO page tables are in used

2022-04-28 Thread Suravee Suthikulpanit via iommu
On 4/20/22 6:29 PM, Suravee Suthikulpanit wrote: On AMD system with SNP enabled, IOMMU hardware checks the host translation valid (TV) and guest translation valid (GV) bits in the device table entry (DTE) before accessing the corresponded page tables. However, current IOMMU driver sets the TV

[PATCH] iommu/amd: Set translation valid bit only when IO page tables are in used

2022-04-20 Thread Suravee Suthikulpanit via iommu
On AMD system with SNP enabled, IOMMU hardware checks the host translation valid (TV) and guest translation valid (GV) bits in the device table entry (DTE) before accessing the corresponded page tables. However, current IOMMU driver sets the TV bit for all devices regardless of whether the host pa

[PATCH] iommu/amd: Do not call sleep while holding spinlock

2022-03-13 Thread Suravee Suthikulpanit via iommu
Smatch static checker warns: drivers/iommu/amd/iommu_v2.c:133 free_device_state() warn: sleeping in atomic context Fixes by storing the list of struct device_state in a temporary list, and then free the memory after releasing the spinlock. Reported-by: Dan Carpenter Fixes: dc6a70

[PATCH] iommu/amd: Fix I/O page table memory leak

2022-02-10 Thread Suravee Suthikulpanit via iommu
The current logic updates the I/O page table mode for the domain before calling the logic to free memory used for the page table. This results in IOMMU page table memory leak, and can be observed when launching VM w/ pass-through devices. Fix by freeing the memory used for page table before updati

[PATCH 3/3] iommu/amd: Remove iommu_init_ga()

2021-08-20 Thread Suravee Suthikulpanit via iommu
Since the function has been simplified and only call iommu_init_ga_log(), remove the function and replace with iommu_init_ga_log() instead. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/init.c | 17 - 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/dri

[PATCH 1/3] iommu/amd: Introduce helper function to check feature bit on all IOMMUs

2021-08-20 Thread Suravee Suthikulpanit via iommu
IOMMU advertises feature via Extended Features Register (EFR). The helper function checks if the specified feature bit is set across all IOMMUs. Signed-off-by: Suravee Suthikulpanit --- drivers/iommu/amd/init.c | 13 + 1 file changed, 13 insertions(+) diff --git a/drivers/iommu/amd/

[PATCH 2/3] iommu/amd: Relocate GAMSup check to early_enable_iommus

2021-08-20 Thread Suravee Suthikulpanit via iommu
From: Wei Huang Currently, iommu_init_ga() checks and disables IOMMU VAPIC support (i.e. AMD AVIC support in IOMMU) when GAMSup feature bit is not set. However it forgets to clear IRQ_POSTING_CAP from the previously set amd_iommu_irq_ops.capability. This triggers an invalid page fault bug during

[PATCH 0/3] iommu/amd: Fix unable to handle page fault due to AVIC

2021-08-20 Thread Suravee Suthikulpanit via iommu
This bug is triggered when rebooting VM on a system which SVM AVIC is enabled but IOMMU AVIC is disabled in the BIOS. The series reworks interrupt remapping intialiation to check for IOMMU AVIC support (GAMSup) at earlier stage using EFR provided by IVRS table instead of the PCI MMIO register, whi

[PATCH] MAINTAINERS: Add Suravee Suthikulpanit as Reviewer for AMD IOMMU (AMD-Vi)

2021-07-14 Thread Suravee Suthikulpanit via iommu
To help review changes related to AMD IOMMU. Signed-off-by: Suravee Suthikulpanit --- MAINTAINERS | 1 + 1 file changed, 1 insertion(+) diff --git a/MAINTAINERS b/MAINTAINERS index b80e6f7..8022dbd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -933,6 +933,7 @@ F: drivers/video/fbdev/geode/