From: Andrew Morton <akpm@linux-foundation.org>
To: Nickolai Zeldovich <nickolai@csail.mit.edu>
Cc: Adam Harshbarger <handyhandyman.adam@gmail.com>,
I Hsin Cheng <richard120310@gmail.com>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH] lib/plist: add a plist_test case for plist_requeue() on the last priority bucket
Date: Sat, 10 Oct 2026 21:18:04 -0700 [thread overview]
Message-ID: <20261010211804.2d8a5f6180c74b08e18ad48a@linux-foundation.org> (raw)
In-Reply-To: <20261011012245.765558-1-nickolai@csail.mit.edu>
On Sat, 10 Oct 2026 21:22:33 -0400 Nickolai Zeldovich <nickolai@csail.mit.edu> wrote:
> The plist_requeue() shortcut inserted the node at the head of the list
> when the node was the first of the last priority bucket and had a
> successor of the same priority, with an earlier bucket present (fixed
> by "lib/plist: fix plist_requeue() corrupting order in the last
> bucket"). The CONFIG_DEBUG_PLIST self-test did not catch it: it only
> requeues nodes it has just added, which are always the last of their
> bucket, so plist_requeue() returned early every time, and
> plist_test_check() only verifies the links, not that the shortcut's
> insertion point is correct.
>
> Add a deterministic case for the failing shape: A(1) B(2) C(2), requeue
> B. plist_test_check() verifies the node_list and prio_list links and
> the ordering, and the new BUG_ON() checks that B ended up at the end of
> the list rather than in front of A.
>
> Before the fix the case produces B(2) A(1) C(2) and the BUG_ON() fires;
> with the fix it produces A(1) C(2) B(2). Verified with the three
> functions transcribed to a userspace harness driving this exact case
> against mainline (fails), the queued fix (passes) and the alternative
> fix I had posted (passes); lib/plist.o builds with CONFIG_DEBUG_PLIST=y
> (LLVM=1 ARCH=riscv).
Thanks.
> Not booted.
err, it should be, If this is wrong, we crash every kernel at boot.
> --- a/lib/plist.c
> +++ b/lib/plist.c
> @@ -283,6 +283,25 @@ static int __init plist_test(void)
> plist_test_check(nr_expect);
> }
>
> + /*
> + * Requeue a node which is the first of the last priority run and has
> + * a successor of the same priority, with an earlier run present: the
> + * shortcut in plist_requeue() must append it at the end of the list,
> + * not in front of the first run. The random test above never
> + * exercises this, since it only requeues nodes it has just added,
> + * which are always the last of their run.
> + */
> + plist_head_init(&test_head);
> + for (i = 0; i < 3; i++) {
> + plist_node_init(test_node + i, i ? 2 : 1);
> + plist_add(test_node + i, &test_head);
> + }
> + plist_test_requeue(test_node + 1);
> + plist_test_check(3);
> + BUG_ON(plist_last(&test_head) != test_node + 1);
No, let's not add a BUG_ON for some selftest. Emit a loud warning and
proceed. If it triggers, someone will report it.
> + for (i = 0; i < 3; i++)
> + plist_del(test_node + i, &test_head);
> +
> printk(KERN_DEBUG "end plist test\n");
>
> /* Worst case test for plist_add() */
This goes in my for-7.4-rcX pile, so no hurry at all.
next prev parent reply other threads:[~2026-10-11 4:18 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-09 5:18 [PATCH] lib/plist: fix plist_requeue() shortcut inserting the node at the list head Nickolai Zeldovich
2026-10-10 23:25 ` Andrew Morton
2026-10-10 23:33 ` Nickolai Zeldovich
2026-10-11 1:10 ` Andrew Morton
2026-10-11 1:22 ` [PATCH] lib/plist: add a plist_test case for plist_requeue() on the last priority bucket Nickolai Zeldovich
2026-10-11 4:18 ` Andrew Morton [this message]
2026-10-11 11:51 ` [PATCH v2] " Nickolai Zeldovich
2026-10-11 11:53 ` [PATCH] " Nickolai Zeldovich
2026-10-11 1:23 ` [PATCH] lib/plist: fix plist_requeue() shortcut inserting the node at the list head Nickolai Zeldovich
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=20261010211804.2d8a5f6180c74b08e18ad48a@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=handyhandyman.adam@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nickolai@csail.mit.edu \
--cc=richard120310@gmail.com \
/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
all inboxes | Powered by JetHome®