Linux Confidential Computing Development
 help / color / mirror / Atom feed
From: Aneesh Kumar K.V <aneesh.kumar@kernel.org>
To: sashiko-reviews@lists.linux.dev, linux-coco@lists.linux.dev,
	Jason Gunthorpe <jgg@nvidia.com>
Cc: media-ci@linuxtv.org, kvmarm@lists.linux.dev,
	dri-devel@lists.freedesktop.org, Oliver Upton <oupton@kernel.org>,
	Marc Zyngier <maz@kernel.org>
Subject: Re: [RFC PATCH v8 08/14] swiotlb: Align shared IO TLB pools to the shared granule size
Date: Tue, 13 Oct 2026 12:16:39 +0530	[thread overview]
Message-ID: <yq5ao6cyqer4.fsf@kernel.org> (raw)
In-Reply-To: <20260924102254.60C431F00893@smtp.kernel.org>

sashiko-bot@kernel.org writes:

> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] mm: infinite loop in swiotlb_init_late() when remap fails
> --
>
> commit 9e7f1b72520615870ee21508117e4c5c7e0eb684
> Author: Aneesh Kumar K.V (Arm) <aneesh.kumar@kernel.org>
>
> swiotlb: Align shared IO TLB pools to the shared granule size
>     
> This commit aligns and sizes the early memblock pool to the common CoCo
> shared granule, leaving the slot count unchanged. It replaces the default
> and dynamic pool set_memory calls with helpers to keep alignment validation
> and architecture dispatch centralized. Pages are intentionally leaked if
> their private state cannot be restored safely.
>
>> diff --git a/kernel/dma/swiotlb.c b/kernel/dma/swiotlb.c
>> index ded7016a46a71..394db93b7eb96 100644
>> --- a/kernel/dma/swiotlb.c
>> +++ b/kernel/dma/swiotlb.c
>
> [ ... ]
>
>> @@ -578,7 +578,7 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
>>  		swiotlb_adjust_nareas(num_possible_cpus());
>>  
>>  retry:
>> -	order = get_order(nslabs << IO_TLB_SHIFT);
>> +	order = get_order(ALIGN(nslabs << IO_TLB_SHIFT, cc_shared_granule_size()));
>>  	nslabs = SLABS_PER_PAGE << order;
>
> [Severity: Medium]
> If remap() fails later in this function, nslabs is halved and the code jumps
> back to the retry label to try a smaller allocation:
>
> kernel/dma/swiotlb.c:swiotlb_init_late() {
>     ...
> 	if (remap)
> 		rc = remap(vstart, nslabs);
> 	if (rc) {
> 		free_pages((unsigned long)vstart, order);
>
> 		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
> 		if (nslabs < IO_TLB_MIN_SLABS)
> 			return rc;
> 		retried = true;
> 		goto retry;
> 	}
>     ...
> }
>
> Does the new ALIGN macro at the retry label risk inflating the halved size
> back to its original value if cc_shared_granule_size() is >= 2MB?
>
> If so, this would restore nslabs to its original failing value, overriding
> the shrinking mechanism and creating an infinite loop.
>

We don't expect cc_shared_granule_size() > 2MB. But i can also add a
check. 

modified    kernel/dma/swiotlb.c
@@ -719,8 +719,13 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
 		free_pages((unsigned long)vstart, order);
 
 		nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
-		if (nslabs < IO_TLB_MIN_SLABS)
-			return rc;
+		if (nslabs <= IO_TLB_MIN_SLABS)
+			return rc;
+
+		/* Avoid infinite loop */
+		if (WARN_ON(nslabs < (cc_shared_granule_size() >> IO_TLB_SHIFT)))
+			return rc;
+
 		retried = true;
 		goto retry;
 	}

  parent reply	other threads:[~2026-10-13  6:46 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-24 10:05 [RFC PATCH v8 00/14] coco: guest: Add a shared-granule allocator for host-shared memory Aneesh Kumar K.V (Arm)
2026-09-24 10:05 ` [RFC PATCH v8 01/14] mm: Add an allocator for CoCo shared memory Aneesh Kumar K.V (Arm)
2026-09-24 10:05 ` [RFC PATCH v8 02/14] mm: Zero memory during shared memory transitions Aneesh Kumar K.V (Arm)
2026-09-25 12:08   ` Kiryl Shutsemau
2026-10-13  5:12     ` Aneesh Kumar K.V
2026-10-13 13:47       ` Kiryl Shutsemau
2026-09-24 10:05 ` [RFC PATCH v8 03/14] irqchip/gic-v3-its: Resolve the default NUMA node explicitly Aneesh Kumar K.V (Arm)
2026-09-24 10:05 ` [RFC PATCH v8 04/14] irqchip/gic-v3-its: Allocate shared tables using CoCo shared memory allocator Aneesh Kumar K.V (Arm)
2026-09-24 10:05 ` [RFC PATCH v8 05/14] dma-contiguous: Derive shared alignment from DMA attributes Aneesh Kumar K.V (Arm)
2026-09-24 10:05 ` [RFC PATCH v8 06/14] dma-pool: Allocate CoCo atomic pools using CoCo shared memory allocator Aneesh Kumar K.V (Arm)
     [not found]   ` <20260924101945.95D7F1F000FF@smtp.kernel.org>
2026-10-13  6:11     ` Aneesh Kumar K.V
2026-09-24 10:05 ` [RFC PATCH v8 07/14] dma-direct: Align CoCo shared DMA allocations to the shared granule size Aneesh Kumar K.V (Arm)
2026-09-24 10:05 ` [RFC PATCH v8 08/14] swiotlb: Align shared IO TLB pools " Aneesh Kumar K.V (Arm)
     [not found]   ` <20260924102254.60C431F00893@smtp.kernel.org>
2026-10-13  6:46     ` Aneesh Kumar K.V [this message]
2026-09-24 10:05 ` [RFC PATCH v8 09/14] swiotlb: Reject misaligned restricted DMA pools for CoCo guests Aneesh Kumar K.V (Arm)
2026-09-24 10:05 ` [RFC PATCH v8 10/14] dma-buf: system_heap: Limit scatterlist entries to the buffer size Aneesh Kumar K.V (Arm)
2026-09-24 10:05 ` [RFC PATCH v8 11/14] dma-buf: system_heap: Allocate shared buffers using CoCo shared memory allocator Aneesh Kumar K.V (Arm)
2026-09-24 10:05 ` [RFC PATCH v8 12/14] swiotlb: Make rounded shared pool capacity allocatable Aneesh Kumar K.V (Arm)
2026-09-24 10:05 ` [RFC PATCH v8 13/14] mm: Assert CoCo shared allocations may sleep Aneesh Kumar K.V (Arm)
2026-09-24 10:05 ` [RFC PATCH v8 14/14] irqchip/gic-v3-its: Preallocate VPE L1 tables Aneesh Kumar K.V (Arm)

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=yq5ao6cyqer4.fsf@kernel.org \
    --to=aneesh.kumar@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=jgg@nvidia.com \
    --cc=kvmarm@lists.linux.dev \
    --cc=linux-coco@lists.linux.dev \
    --cc=maz@kernel.org \
    --cc=media-ci@linuxtv.org \
    --cc=oupton@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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