All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Max Kellermann" <max.kellermann@ionos.com>,
	akpm@linux-foundation.org, kasong@tencent.com,
	qi.zheng@linux.dev, shakeel.butt@linux.dev, baohua@kernel.org,
	axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com,
	baoquan.he@linux.dev, baolin.wang@linux.alibaba.com,
	david@kernel.org, ljs@kernel.org, liam@infradead.org,
	vbabka@kernel.org, rppt@kernel.org, surenb@google.com,
	mhocko@suse.com, hannes@cmpxchg.org, linux-mm@kvack.org
Subject: Re: [PATCH v2 1/5] include/linux/rculist_nulls: add hlist_nulls_add_behind_rcu()
Date: Wed, 04 Nov 2026 11:37:37 +0000	[thread overview]
Message-ID: <sashiko-outbox-197181@kernel.org> (raw)
In-Reply-To: <20261103113711.1832834-2-max.kellermann@ionos.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] rculist_nulls: missing next->pprev update in hlist_nulls_add_behind_rcu()
--

commit 32c8749135647f4c1c26a14e364aff3736e91e2e
Author: Max Kellermann <max.kellermann@ionos.com>

include/linux/rculist_nulls: add hlist_nulls_add_behind_rcu()

This commit factors the non-empty tail insertion logic out of
hlist_nulls_add_tail_rcu() into a new hlist_nulls_add_behind_rcu() helper
so callers tracking the last node can append in constant time.

> diff --git a/include/linux/rculist_nulls.h b/include/linux/rculist_nulls.h
> index a97c3bcb1656e..054e477dd0937 100644
> --- a/include/linux/rculist_nulls.h
> +++ b/include/linux/rculist_nulls.h
> @@ -115,6 +115,33 @@ static inline void hlist_nulls_add_head_rcu(struct hlist_nulls_node *n,
>  		WRITE_ONCE(first->pprev, &n->next);
>  }
>  
> +/**
> + * hlist_nulls_add_behind_rcu - append after the last list entry
> + * @n: the new element to add to the hash list.
> + * @last: the last element in the list.
> + *
> + * Adds the specified element after @last while permitting racing RCU
> + * traversals.  @last must be the last list entry, with its next
> + * pointer holding the terminating nulls marker.
> + *
> + * The caller must take whatever precautions are necessary
> + * (such as holding appropriate locks) to avoid racing
> + * with another list-mutation primitive, such as hlist_nulls_add_head_rcu()
> + * or hlist_nulls_del_rcu(), running on this same list.
> + * However, it is perfectly legal to run concurrently with
> + * the _rcu list-traversal primitives, such as
> + * hlist_nulls_for_each_entry_rcu(), used to prevent memory-consistency
> + * problems on Alpha CPUs.  Regardless of the type of CPU, the
> + * list-traversal primitive must be guarded by rcu_read_lock().
> + */
> +static inline void hlist_nulls_add_behind_rcu(struct hlist_nulls_node *n,
> +					      struct hlist_nulls_node *last)
> +{
> +	WRITE_ONCE(n->next, last->next);
> +	WRITE_ONCE(n->pprev, &last->next);
> +	rcu_assign_pointer(hlist_nulls_next_rcu(last), n);
> +}

[Severity: Medium]
Should hlist_nulls_add_behind_rcu() in include/linux/rculist_nulls.h also
update n->next->pprev when !is_a_nulls(n->next), matching
hlist_add_behind_rcu() in include/linux/rculist.h?

In include/linux/rculist.h, hlist_add_behind_rcu() supports inserting behind
any existing node prev in the list by updating the successor's pprev pointer:

include/linux/rculist.h:hlist_add_behind_rcu() {
	n->next = prev->next;
	WRITE_ONCE(n->pprev, &prev->next);
	rcu_assign_pointer(hlist_next_rcu(prev), n);
	if (n->next)
		WRITE_ONCE(n->next->pprev, &n->next);
}

The other *_add_behind() primitives, hlist_add_behind() in
include/linux/list.h and hlist_bl_add_behind() in include/linux/list_bl.h,
similarly update n->next->pprev so they can be used on interior nodes as well
as the tail.

With hlist_nulls_add_behind_rcu() omitting that update, if a caller passes a
node whose next pointer is not a nulls marker (!is_a_nulls(last->next)),
n->next->pprev remains pointing to &last->next instead of &n->next. Removing
the successor via hlist_nulls_del_rcu() -> __hlist_nulls_del() or replacing
it via hlist_nulls_replace_rcu() would then overwrite last->next and silently
drop n from the list, or cause a use-after-free write if last was removed and
freed first.

Could hlist_nulls_add_behind_rcu() check if (!is_a_nulls(n->next)) and set
WRITE_ONCE(n->next->pprev, &n->next) just like hlist_nulls_add_head_rcu() and
hlist_nulls_replace_rcu() in the same file?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261103113711.1832834-1-max.kellermann@ionos.com?part=1


  reply	other threads:[~2026-11-04 11:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-03 11:37 [PATCH v2 0/5] mm: multi-gen LRU: reduce memcg rotation overhead Max Kellermann
2026-11-03 11:37 ` [PATCH v2 1/5] include/linux/rculist_nulls: add hlist_nulls_add_behind_rcu() Max Kellermann
2026-11-04 11:37   ` sashiko-bot [this message]
2026-11-03 11:37 ` [PATCH v2 2/5] mm/vmscan: move code to lru_gen_{add,del}_memcg() Max Kellermann
2026-11-04  3:22   ` Barry Song
2026-11-04  5:29     ` Max Kellermann
2026-11-03 11:37 ` [PATCH v2 3/5] mm/mglru: cache the last memcg node, make tail insertion constant time Max Kellermann
2026-11-04  3:40   ` Barry Song
2026-11-04  7:55     ` Max Kellermann
2026-11-03 11:37 ` [PATCH v2 4/5] mm/mglru: avoid redundant rotations of young memcgs Max Kellermann
2026-11-04  5:17   ` Barry Song
2026-11-04  8:26     ` Max Kellermann
2026-11-04  9:08       ` Barry Song
2026-11-03 11:37 ` [PATCH v2 5/5] mm/mglru: reschedule between memcg reclaim attempts Max Kellermann

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=sashiko-outbox-197181@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=axelrasmussen@google.com \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=baoquan.he@linux.dev \
    --cc=david@kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=kasong@tencent.com \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=max.kellermann@ionos.com \
    --cc=mhocko@suse.com \
    --cc=qi.zheng@linux.dev \
    --cc=rppt@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=shakeel.butt@linux.dev \
    --cc=surenb@google.com \
    --cc=vbabka@kernel.org \
    --cc=weixugc@google.com \
    --cc=yuanchu@google.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 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.