* [PATCH] iommu/amd: Do not reallocate GA log buffers on resume
@ 2026-08-19 3:23 Karl Mehltretter
2026-08-20 9:07 ` Ankit Soni
2026-08-25 10:28 ` Vasant Hegde
0 siblings, 2 replies; 4+ messages in thread
From: Karl Mehltretter @ 2026-08-19 3:23 UTC (permalink / raw)
To: Joerg Roedel (AMD), Will Deacon
Cc: Karl Mehltretter, Suravee Suthikulpanit, Vasant Hegde,
Robin Murphy, iommu, linux-kernel
Commit c5e1a1eb9279 ("iommu/amd: Simplify and Consolidate Virtual APIC
(AVIC) Enablement") moved the GA log allocation from iommu_init_pci()
to enable_iommus_vapic(), which is called on every resume.
iommu_init_ga_log() assigns iommu->ga_log and iommu->ga_log_tail
unconditionally. Each resume therefore replaces the boot-time pointers
and leaks both old allocations. The function also uses GFP_KERNEL from a
syscore resume callback, where interrupts are disabled and the non-boot
CPUs are offline.
Return early if both buffers are already allocated. Clear the pointers
in free_ga_log() so a partial allocation failure cannot leave ga_log
dangling.
Fixes: c5e1a1eb9279 ("iommu/amd: Simplify and Consolidate Virtual APIC (AVIC) Enablement")
Assisted-by: Claude:claude-opus-5
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
Tested with custom QEMU with GA log emulation. Stock QEMU does not
advertise GAMSup and cannot reach this path. After five pm_test=core
cycles, nr_iommu_pages increased from 17 to 25 without the patch.
Testing on AVIC-capable hardware would be welcome.
drivers/iommu/amd/init.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
index 40726dfef2733..c6b106d5921e 100644
--- a/drivers/iommu/amd/init.c
+++ b/drivers/iommu/amd/init.c
@@ -909,7 +909,9 @@ static void free_ga_log(struct amd_iommu *iommu)
{
#ifdef CONFIG_IRQ_REMAP
iommu_free_pages(iommu->ga_log);
+ iommu->ga_log = NULL;
iommu_free_pages(iommu->ga_log_tail);
+ iommu->ga_log_tail = NULL;
#endif
}
@@ -956,6 +958,9 @@ static int iommu_init_ga_log(struct amd_iommu *iommu)
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;
base-commit: 4477a78374a57c3809b172ad30cceabda48c47c6
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] iommu/amd: Do not reallocate GA log buffers on resume
2026-08-19 3:23 [PATCH] iommu/amd: Do not reallocate GA log buffers on resume Karl Mehltretter
@ 2026-08-20 9:07 ` Ankit Soni
2026-08-25 10:28 ` Vasant Hegde
1 sibling, 0 replies; 4+ messages in thread
From: Ankit Soni @ 2026-08-20 9:07 UTC (permalink / raw)
To: Karl Mehltretter
Cc: Joerg Roedel (AMD), Will Deacon, Suravee Suthikulpanit,
Vasant Hegde, Robin Murphy, iommu, linux-kernel
On Wed, Aug 19, 2026 at 05:23:49AM +0200, Karl Mehltretter wrote:
> Commit c5e1a1eb9279 ("iommu/amd: Simplify and Consolidate Virtual APIC
> (AVIC) Enablement") moved the GA log allocation from iommu_init_pci()
> to enable_iommus_vapic(), which is called on every resume.
>
> iommu_init_ga_log() assigns iommu->ga_log and iommu->ga_log_tail
> unconditionally. Each resume therefore replaces the boot-time pointers
> and leaks both old allocations. The function also uses GFP_KERNEL from a
> syscore resume callback, where interrupts are disabled and the non-boot
> CPUs are offline.
>
> Return early if both buffers are already allocated. Clear the pointers
> in free_ga_log() so a partial allocation failure cannot leave ga_log
> dangling.
>
> Fixes: c5e1a1eb9279 ("iommu/amd: Simplify and Consolidate Virtual APIC (AVIC) Enablement")
> Assisted-by: Claude:claude-opus-5
> Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
Reviewed-by: Ankit Soni <Ankit.Soni@amd.com>
Thanks,
Ankit
> ---
> Tested with custom QEMU with GA log emulation. Stock QEMU does not
> advertise GAMSup and cannot reach this path. After five pm_test=core
> cycles, nr_iommu_pages increased from 17 to 25 without the patch.
>
> Testing on AVIC-capable hardware would be welcome.
>
> drivers/iommu/amd/init.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
> index 40726dfef2733..c6b106d5921e 100644
> --- a/drivers/iommu/amd/init.c
> +++ b/drivers/iommu/amd/init.c
> @@ -909,7 +909,9 @@ static void free_ga_log(struct amd_iommu *iommu)
> {
> #ifdef CONFIG_IRQ_REMAP
> iommu_free_pages(iommu->ga_log);
> + iommu->ga_log = NULL;
> iommu_free_pages(iommu->ga_log_tail);
> + iommu->ga_log_tail = NULL;
> #endif
> }
>
> @@ -956,6 +958,9 @@ static int iommu_init_ga_log(struct amd_iommu *iommu)
> 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;
>
> base-commit: 4477a78374a57c3809b172ad30cceabda48c47c6
> --
> 2.53.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] iommu/amd: Do not reallocate GA log buffers on resume
2026-08-19 3:23 [PATCH] iommu/amd: Do not reallocate GA log buffers on resume Karl Mehltretter
2026-08-20 9:07 ` Ankit Soni
@ 2026-08-25 10:28 ` Vasant Hegde
2026-08-25 12:21 ` Vasant Hegde
1 sibling, 1 reply; 4+ messages in thread
From: Vasant Hegde @ 2026-08-25 10:28 UTC (permalink / raw)
To: Karl Mehltretter, Joerg Roedel (AMD), Will Deacon
Cc: Suravee Suthikulpanit, Robin Murphy, iommu, linux-kernel
On 8/19/2026 8:53 AM, Karl Mehltretter wrote:
> [You don't often get email from kmehltretter@gmail.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
>
> Commit c5e1a1eb9279 ("iommu/amd: Simplify and Consolidate Virtual APIC
> (AVIC) Enablement") moved the GA log allocation from iommu_init_pci()
> to enable_iommus_vapic(), which is called on every resume.
>
> iommu_init_ga_log() assigns iommu->ga_log and iommu->ga_log_tail
> unconditionally. Each resume therefore replaces the boot-time pointers
> and leaks both old allocations. The function also uses GFP_KERNEL from a
> syscore resume callback, where interrupts are disabled and the non-boot
> CPUs are offline.
>
> Return early if both buffers are already allocated. Clear the pointers
> in free_ga_log() so a partial allocation failure cannot leave ga_log
> dangling.
>
> Fixes: c5e1a1eb9279 ("iommu/amd: Simplify and Consolidate Virtual APIC (AVIC) Enablement")
> Assisted-by: Claude:claude-opus-5
> Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
@Joerg, I think we should pick this for -rc.
-Vasant
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] iommu/amd: Do not reallocate GA log buffers on resume
2026-08-25 10:28 ` Vasant Hegde
@ 2026-08-25 12:21 ` Vasant Hegde
0 siblings, 0 replies; 4+ messages in thread
From: Vasant Hegde @ 2026-08-25 12:21 UTC (permalink / raw)
To: Karl Mehltretter, Joerg Roedel (AMD), Will Deacon
Cc: Suravee Suthikulpanit, Robin Murphy, iommu, linux-kernel
On 8/25/2026 3:58 PM, Vasant Hegde wrote:
>
>
> On 8/19/2026 8:53 AM, Karl Mehltretter wrote:
>>
>> Commit c5e1a1eb9279 ("iommu/amd: Simplify and Consolidate Virtual APIC
>> (AVIC) Enablement") moved the GA log allocation from iommu_init_pci()
>> to enable_iommus_vapic(), which is called on every resume.
>>
>> iommu_init_ga_log() assigns iommu->ga_log and iommu->ga_log_tail
>> unconditionally. Each resume therefore replaces the boot-time pointers
>> and leaks both old allocations. The function also uses GFP_KERNEL from a
>> syscore resume callback, where interrupts are disabled and the non-boot
>> CPUs are offline.
>>
>> Return early if both buffers are already allocated. Clear the pointers
>> in free_ga_log() so a partial allocation failure cannot leave ga_log
>> dangling.
>>
>> Fixes: c5e1a1eb9279 ("iommu/amd: Simplify and Consolidate Virtual APIC (AVIC) Enablement")
>> Assisted-by: Claude:claude-opus-5
>> Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
>
> Reviewed-by: Vasant Hegde <vasant.hegde@amd.com>
>
> @Joerg, I think we should pick this for -rc.
Just to be clear, I have a patch to remove all these checks in iommu_init_ga_log
and re-arrange a code bit. But its slightly bigger change and backporting to
stable becomes difficult.
Hence I'd say lets apply this patch. I will send my patches on top of this patch.
-Vasant
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-08-25 12:21 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-19 3:23 [PATCH] iommu/amd: Do not reallocate GA log buffers on resume Karl Mehltretter
2026-08-20 9:07 ` Ankit Soni
2026-08-25 10:28 ` Vasant Hegde
2026-08-25 12:21 ` Vasant Hegde
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox