* [PATCH] iommu/amd: Move GA log allocation to init
@ 2026-09-11 10:43 Vasant Hegde
2026-09-15 14:52 ` Ankit Soni
2026-09-24 11:56 ` Jörg Rödel
0 siblings, 2 replies; 3+ messages in thread
From: Vasant Hegde @ 2026-09-11 10:43 UTC (permalink / raw)
To: iommu, joro; +Cc: will, robin.murphy, suravee.suthikulpanit, Vasant Hegde
Currently GA log buffer allocation is done at the time of enabling ga
log. This mixes capability checking, resource allocation, and hardware
enablement into a single late stage code path.
Move capability checking and buffer allocation to init path:
- check_vapic_support(): Checks AVIC support
- alloc_ga_log(): Rename iommu_init_ga_log() as alloc_ga_log(). It will
allocate the GA log and GA log tail buffers for a given IOMMU. Remove
redundant checks inside alloc_ga_log().
- enable_iommus_vapic() is simplified - it handles enabling GA log and
GAM/SNPAVIC support for IOMMUs.
Finally update iommu_ga_log_enable() return value from int to bool as
return value is used in boolean context only.
Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
---
Base commit: adbd8a08208 from iommu/fixes branch.
-Vasant
drivers/iommu/amd/init.c | 74 +++++++++++++++++++++++-----------------
1 file changed, 42 insertions(+), 32 deletions(-)
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index 8a410d4aa370..3c72701d2306 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -916,13 +916,13 @@ static void free_ga_log(struct amd_iommu *iommu)
}
#ifdef CONFIG_IRQ_REMAP
-static int iommu_ga_log_enable(struct amd_iommu *iommu)
+static bool iommu_ga_log_enable(struct amd_iommu *iommu)
{
u32 status, i;
u64 entry;
if (!iommu->ga_log)
- return -EINVAL;
+ return false;
entry = iommu_virt_to_phys(iommu->ga_log) | GA_LOG_SIZE_512;
memcpy_toio(iommu->mmio_base + MMIO_GA_LOG_BASE_OFFSET,
@@ -946,35 +946,31 @@ static int iommu_ga_log_enable(struct amd_iommu *iommu)
}
if (WARN_ON(i >= MMIO_STATUS_TIMEOUT))
- return -EINVAL;
+ return false;
- return 0;
+ return true;
}
+#endif /* CONFIG_IRQ_REMAP */
-static int iommu_init_ga_log(struct amd_iommu *iommu)
+static int alloc_ga_log(struct amd_iommu *iommu)
{
+#ifdef CONFIG_IRQ_REMAP
int nid = iommu->dev ? dev_to_node(&iommu->dev->dev) : NUMA_NO_NODE;
- if (WARN_ON_ONCE(!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)))
- return -EINVAL;
-
- if (iommu->ga_log && iommu->ga_log_tail)
- return 0;
-
iommu->ga_log = iommu_alloc_pages_node_sz(nid, GFP_KERNEL, GA_LOG_SIZE);
if (!iommu->ga_log)
- goto err_out;
+ return -ENOMEM;
iommu->ga_log_tail = iommu_alloc_pages_node_sz(nid, GFP_KERNEL, 8);
- if (!iommu->ga_log_tail)
- goto err_out;
+ if (!iommu->ga_log_tail) {
+ iommu_free_pages(iommu->ga_log);
+ iommu->ga_log = NULL;
+ return -ENOMEM;
+ }
+#endif
return 0;
-err_out:
- free_ga_log(iommu);
- return -EINVAL;
}
-#endif /* CONFIG_IRQ_REMAP */
static int __init alloc_cwwb_sem(struct amd_iommu *iommu)
{
@@ -2152,6 +2148,27 @@ static void __init late_iommu_features_init(struct amd_iommu *iommu)
}
}
+/* Must be called after SNP support check is complete (iommu_snp_enable()) */
+static bool check_vapic_support(void)
+{
+ if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir))
+ return false;
+
+ if (!check_feature(FEATURE_GAM_VAPIC)) {
+ amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
+ return false;
+ }
+
+ if (amd_iommu_snp_en &&
+ !FEATURE_SNPAVICSUP_GAM(amd_iommu_efr2)) {
+ pr_warn("Force to disable Virtual APIC due to SNP\n");
+ amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
+ return false;
+ }
+
+ return true;
+}
+
static int __init iommu_init_pci(struct amd_iommu *iommu)
{
int cap_ptr = iommu->cap_ptr;
@@ -2196,6 +2213,12 @@ static int __init iommu_init_pci(struct amd_iommu *iommu)
if (check_feature(FEATURE_PPR) && amd_iommu_alloc_ppr_log(iommu))
return -ENOMEM;
+ if (check_vapic_support()) {
+ ret = alloc_ga_log(iommu);
+ if (ret)
+ return ret;
+ }
+
if (iommu->cap & (1UL << IOMMU_CAP_NPCACHE)) {
pr_info("Using strict mode due to virtualization\n");
iommu_set_dma_strict();
@@ -3010,22 +3033,9 @@ static void enable_iommus_vapic(void)
if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir))
return;
- if (!check_feature(FEATURE_GAM_VAPIC)) {
- amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
- return;
- }
-
- if (amd_iommu_snp_en &&
- !FEATURE_SNPAVICSUP_GAM(amd_iommu_efr2)) {
- pr_warn("Force to disable Virtual APIC due to SNP\n");
- amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
- return;
- }
-
/* Enabling GAM and SNPAVIC support */
for_each_iommu(iommu) {
- if (iommu_init_ga_log(iommu) ||
- iommu_ga_log_enable(iommu))
+ if (!iommu_ga_log_enable(iommu))
return;
iommu_feature_enable(iommu, CONTROL_GAM_EN);
--
2.31.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] iommu/amd: Move GA log allocation to init
2026-09-11 10:43 [PATCH] iommu/amd: Move GA log allocation to init Vasant Hegde
@ 2026-09-15 14:52 ` Ankit Soni
2026-09-24 11:56 ` Jörg Rödel
1 sibling, 0 replies; 3+ messages in thread
From: Ankit Soni @ 2026-09-15 14:52 UTC (permalink / raw)
To: Vasant Hegde; +Cc: iommu, joro, will, robin.murphy, suravee.suthikulpanit
On Fri, Sep 11, 2026 at 10:43:17AM +0000, Vasant Hegde wrote:
> Currently GA log buffer allocation is done at the time of enabling ga
> log. This mixes capability checking, resource allocation, and hardware
> enablement into a single late stage code path.
>
> Move capability checking and buffer allocation to init path:
> - check_vapic_support(): Checks AVIC support
>
> - alloc_ga_log(): Rename iommu_init_ga_log() as alloc_ga_log(). It will
> allocate the GA log and GA log tail buffers for a given IOMMU. Remove
> redundant checks inside alloc_ga_log().
>
> - enable_iommus_vapic() is simplified - it handles enabling GA log and
> GAM/SNPAVIC support for IOMMUs.
>
> Finally update iommu_ga_log_enable() return value from int to bool as
> return value is used in boolean context only.
>
Reviewed-by: Ankit Soni <Ankit.Soni@amd.com>
> Signed-off-by: Vasant Hegde <vasant.hegde@amd.com>
> ---
>
> Base commit: adbd8a08208 from iommu/fixes branch.
>
> -Vasant
>
> drivers/iommu/amd/init.c | 74 +++++++++++++++++++++++-----------------
> 1 file changed, 42 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
> index 8a410d4aa370..3c72701d2306 100644
> --- a/drivers/iommu/amd/init.c
> +++ b/drivers/iommu/amd/init.c
> @@ -916,13 +916,13 @@ static void free_ga_log(struct amd_iommu *iommu)
> }
>
> #ifdef CONFIG_IRQ_REMAP
> -static int iommu_ga_log_enable(struct amd_iommu *iommu)
> +static bool iommu_ga_log_enable(struct amd_iommu *iommu)
> {
> u32 status, i;
> u64 entry;
>
> if (!iommu->ga_log)
> - return -EINVAL;
> + return false;
>
> entry = iommu_virt_to_phys(iommu->ga_log) | GA_LOG_SIZE_512;
> memcpy_toio(iommu->mmio_base + MMIO_GA_LOG_BASE_OFFSET,
> @@ -946,35 +946,31 @@ static int iommu_ga_log_enable(struct amd_iommu *iommu)
> }
>
> if (WARN_ON(i >= MMIO_STATUS_TIMEOUT))
> - return -EINVAL;
> + return false;
>
> - return 0;
> + return true;
> }
> +#endif /* CONFIG_IRQ_REMAP */
>
> -static int iommu_init_ga_log(struct amd_iommu *iommu)
> +static int alloc_ga_log(struct amd_iommu *iommu)
> {
> +#ifdef CONFIG_IRQ_REMAP
> int nid = iommu->dev ? dev_to_node(&iommu->dev->dev) : NUMA_NO_NODE;
>
> - if (WARN_ON_ONCE(!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir)))
> - return -EINVAL;
> -
> - if (iommu->ga_log && iommu->ga_log_tail)
> - return 0;
> -
> iommu->ga_log = iommu_alloc_pages_node_sz(nid, GFP_KERNEL, GA_LOG_SIZE);
> if (!iommu->ga_log)
> - goto err_out;
> + return -ENOMEM;
>
> iommu->ga_log_tail = iommu_alloc_pages_node_sz(nid, GFP_KERNEL, 8);
> - if (!iommu->ga_log_tail)
> - goto err_out;
> + if (!iommu->ga_log_tail) {
> + iommu_free_pages(iommu->ga_log);
> + iommu->ga_log = NULL;
> + return -ENOMEM;
> + }
> +#endif
>
> return 0;
> -err_out:
> - free_ga_log(iommu);
> - return -EINVAL;
> }
> -#endif /* CONFIG_IRQ_REMAP */
>
> static int __init alloc_cwwb_sem(struct amd_iommu *iommu)
> {
> @@ -2152,6 +2148,27 @@ static void __init late_iommu_features_init(struct amd_iommu *iommu)
> }
> }
>
> +/* Must be called after SNP support check is complete (iommu_snp_enable()) */
> +static bool check_vapic_support(void)
> +{
> + if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir))
> + return false;
> +
> + if (!check_feature(FEATURE_GAM_VAPIC)) {
> + amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
> + return false;
> + }
> +
> + if (amd_iommu_snp_en &&
> + !FEATURE_SNPAVICSUP_GAM(amd_iommu_efr2)) {
> + pr_warn("Force to disable Virtual APIC due to SNP\n");
> + amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
> + return false;
> + }
> +
> + return true;
> +}
> +
> static int __init iommu_init_pci(struct amd_iommu *iommu)
> {
> int cap_ptr = iommu->cap_ptr;
> @@ -2196,6 +2213,12 @@ static int __init iommu_init_pci(struct amd_iommu *iommu)
> if (check_feature(FEATURE_PPR) && amd_iommu_alloc_ppr_log(iommu))
> return -ENOMEM;
>
> + if (check_vapic_support()) {
> + ret = alloc_ga_log(iommu);
> + if (ret)
> + return ret;
> + }
> +
> if (iommu->cap & (1UL << IOMMU_CAP_NPCACHE)) {
> pr_info("Using strict mode due to virtualization\n");
> iommu_set_dma_strict();
> @@ -3010,22 +3033,9 @@ static void enable_iommus_vapic(void)
> if (!AMD_IOMMU_GUEST_IR_VAPIC(amd_iommu_guest_ir))
> return;
>
> - if (!check_feature(FEATURE_GAM_VAPIC)) {
> - amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
> - return;
> - }
> -
> - if (amd_iommu_snp_en &&
> - !FEATURE_SNPAVICSUP_GAM(amd_iommu_efr2)) {
> - pr_warn("Force to disable Virtual APIC due to SNP\n");
> - amd_iommu_guest_ir = AMD_IOMMU_GUEST_IR_LEGACY_GA;
> - return;
> - }
> -
> /* Enabling GAM and SNPAVIC support */
> for_each_iommu(iommu) {
> - if (iommu_init_ga_log(iommu) ||
> - iommu_ga_log_enable(iommu))
> + if (!iommu_ga_log_enable(iommu))
> return;
>
> iommu_feature_enable(iommu, CONTROL_GAM_EN);
> --
> 2.31.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] iommu/amd: Move GA log allocation to init
2026-09-11 10:43 [PATCH] iommu/amd: Move GA log allocation to init Vasant Hegde
2026-09-15 14:52 ` Ankit Soni
@ 2026-09-24 11:56 ` Jörg Rödel
1 sibling, 0 replies; 3+ messages in thread
From: Jörg Rödel @ 2026-09-24 11:56 UTC (permalink / raw)
To: Vasant Hegde; +Cc: iommu, will, robin.murphy, suravee.suthikulpanit
On Fri, Sep 11, 2026 at 10:43:17AM +0000, Vasant Hegde wrote:
> drivers/iommu/amd/init.c | 74 +++++++++++++++++++++++-----------------
> 1 file changed, 42 insertions(+), 32 deletions(-)
Applied, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-09-24 11:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-11 10:43 [PATCH] iommu/amd: Move GA log allocation to init Vasant Hegde
2026-09-15 14:52 ` Ankit Soni
2026-09-24 11:56 ` Jörg Rödel
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.