From: "Christian König" <christian.koenig@amd.com>
To: Matthew Wilcox <willy@infradead.org>,
Jan Sokolowski <jan.sokolowski@intel.com>
Cc: linux-kernel@vger.kernel.org,
Andrew Morton <akpm@linux-foundation.org>,
linux-fsdevel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [RFC PATCH 1/1] idr: do not create idr if new id would be outside given range
Date: Thu, 27 Nov 2025 15:03:20 +0100 [thread overview]
Message-ID: <06dbd4f8-ef5f-458c-a8b4-8a8fb2a7877c@amd.com> (raw)
In-Reply-To: <aShYJta2EHh1d8az@casper.infradead.org>
On 11/27/25 14:54, Matthew Wilcox wrote:
> On Thu, Nov 27, 2025 at 10:27:32AM +0100, Jan Sokolowski wrote:
>> A scenario was found where trying to add id in range 0,1
>> would return an id of 2, which is outside the range and thus
>> now what the user would expect.
>
> Can you do a bit better with this bug report? Under what circumstances
> does this happen? Preferably answer in the form of a test case for the
> IDR test suite. Here's my attempt to recreate your situation based on
> what I read in that thread. It doesn't show a problem, so clearly I got
> something wrong.
According to Jan the observation he has is that this code:
idr_init_base(&idr, 1);
id = idr_alloc(&idr, dummy_ptr, 0, 1, GFP_KERNEL);
Gives him id=2 in return.
That clearly seems to be problematic considering that start=0 and end=1 should either give you id=0 or an error because idr->idr_base should be initialized to 1.
But I'm still not sure if Jan's observation is actually correct, cause I also don't see how that possible happen.
Regards,
Christian.
> To run the test suite, apply this patch, then
>
> $ make -C tools/testing/radix-tree
> $ ./tools/testing/radix-tree/idr-test
>
> diff --git a/tools/testing/radix-tree/idr-test.c b/tools/testing/radix-tree/idr-test.c
> index 2f830ff8396c..774c0c9c141f 100644
> --- a/tools/testing/radix-tree/idr-test.c
> +++ b/tools/testing/radix-tree/idr-test.c
> @@ -57,6 +57,21 @@ void idr_alloc_test(void)
> idr_destroy(&idr);
> }
>
> +void idr_alloc2_test(void)
> +{
> + int id;
> + DEFINE_IDR(idr);
> +
> + id = idr_alloc(&idr, idr_alloc2_test, 0, 1, GFP_KERNEL);
> + printf("id = %d\n", id);
> + assert(id == 0);
> + id = idr_alloc(&idr, idr_alloc2_test, 0, 1, GFP_KERNEL);
> + printf("id = %d\n", id);
> + assert(id == -ENOSPC);
> +
> + idr_destroy(&idr);
> +}
> +
> void idr_replace_test(void)
> {
> DEFINE_IDR(idr);
> @@ -409,6 +424,7 @@ void idr_checks(void)
>
> idr_replace_test();
> idr_alloc_test();
> + idr_alloc2_test();
> idr_null_test();
> idr_nowait_test();
> idr_get_next_test(0);
next prev parent reply other threads:[~2025-11-27 14:03 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-27 9:27 [RFC PATCH 0/1] IDR fix for potential id mismatch Jan Sokolowski
2025-11-27 9:27 ` [RFC PATCH 1/1] idr: do not create idr if new id would be outside given range Jan Sokolowski
2025-11-27 13:38 ` Matthew Wilcox
2025-11-27 13:54 ` Matthew Wilcox
2025-11-27 14:03 ` Christian König [this message]
2025-11-27 14:11 ` Matthew Wilcox
2025-11-27 14:55 ` Matthew Wilcox
2025-11-27 15:02 ` Christian König
2025-11-28 9:03 ` Sokolowski, Jan
2025-11-28 15:52 ` Matthew Wilcox
2025-11-28 16:47 ` Sokolowski, Jan
2025-11-28 17:50 ` Matthew Wilcox
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=06dbd4f8-ef5f-458c-a8b4-8a8fb2a7877c@amd.com \
--to=christian.koenig@amd.com \
--cc=akpm@linux-foundation.org \
--cc=jan.sokolowski@intel.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=willy@infradead.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