All of lore.kernel.org
 help / color / mirror / Atom feed
From: "zhen.ni" <zhen.ni@easystack.cn>
To: sashiko-reviews@lists.linux.dev
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v2 3/6] mm/page_owner: add open-coded page_owner iterator
Date: Wed, 14 Oct 2026 16:01:51 +0800	[thread overview]
Message-ID: <2a605a34-0e0e-4377-9062-6b511e0be503@easystack.cn> (raw)
In-Reply-To: <sashiko-outbox-169742@kernel.org>



在 2026/10/13 20:49, sashiko-bot@kernel.org 写道:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [High] mm: soft lockup in page_owner_next_eligible via BPF iter
> --
> 
> commit b7f01516d35223b7a6800ce695c29a9203809699
> Author: Zhen Ni <zhen.ni@easystack.cn>
> 
> mm/page_owner: add open-coded page_owner iterator
> 
> This patch adds an open-coded bpf_iter over the pages eligible for
> page_owner output, reusing page_owner_next_eligible(). It also provides a
> sleepable BPF program to drive the iterator and retrieve stack traces.
> 
>> diff --git a/mm/page_owner_iter.c b/mm/page_owner_iter.c
>> index 938cb42ab7d79..ac7e69ba0cef3 100644
>> --- a/mm/page_owner_iter.c
>> +++ b/mm/page_owner_iter.c
> [ ... ]
>> @@ -122,3 +123,55 @@ int page_owner_iter_register(void)
>>   
>>   	return bpf_iter_reg_target(&page_owner_iter_reg_info);
>>   }
>> +
>> +/* opaque to BPF programs */
>> +struct bpf_iter_page_owner {
>> +	__u64 __opaque[16];
>> +} __attribute__((aligned(8)));
>> +
>> +struct bpf_iter_page_owner_kern {
>> +	struct page_owner_scan scan;
>> +} __attribute__((aligned(8)));
>> +
>> +__bpf_kfunc_start_defs();
> [ ... ]
>> +__bpf_kfunc struct page_owner_scan *
>> +bpf_iter_page_owner_next(struct bpf_iter_page_owner *it)
>> +{
>> +	struct bpf_iter_page_owner_kern *kit = (void *)it;
>> +
>> +	cond_resched();
>> +
>> +	if (kit->scan.page)
>> +		kit->scan.pfn++;
>> +
>> +	if (!page_owner_next_eligible(&kit->scan))
>> +		return NULL;
> 
> [Severity: High]
> Can this iterator cause a soft lockup or RCU stall?
> 
> If page_owner is disabled, page_ext_get() inside page_owner_next_eligible()
> constantly returns NULL, triggering a continue on every single page up to
> max_pfn:
> 
> mm/page_owner.c:page_owner_next_eligible() {
> 	...
> 	for (; pfn < max_pfn; pfn++) {
> 		...
> 		page_ext = page_ext_get(page);
> 		if (unlikely(!page_ext))
> 			continue;
> 		...
> ext_put_continue:
> 		page_ext_put(page_ext);
> 		cond_resched();
> 	}
> 	...
> }
> 
> Because the continue statement skips the ext_put_continue block, the loop
> never calls cond_resched(). When called from this new sleepable BPF
> iterator, won't it spin over the entire physical memory space in a tight
> loop without yielding?
> 
>> +
>> +	return &kit->scan;
>> +}
> 

The soft lockup / RCU stall doesn't seem critical, since the debugfs
path behaves the same way, but I think it's worth disabling these kfuncs
when page_owner is not enabled. I'll guard them with
static_branch_unlikely(&page_owner_inited).


Thanks,
Zhen

  reply	other threads:[~2026-10-14  8:07 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 12:21 [PATCH v2 0/6] mm/page_owner: add bpf_iter and kfuncs Zhen Ni
2026-10-13 12:21 ` [PATCH v2 1/6] mm/page_owner: extract page_owner_next_eligible() from read loop Zhen Ni
2026-10-13 12:21 ` [PATCH v2 2/6] mm/page_owner: add bpf_iter target "page_owner" Zhen Ni
2026-10-13 13:51   ` bot+bpf-ci
2026-10-13 12:21 ` [PATCH v2 3/6] mm/page_owner: add open-coded page_owner iterator Zhen Ni
2026-10-13 12:49   ` sashiko-bot
2026-10-14  8:01     ` zhen.ni [this message]
2026-10-13 13:51   ` bot+bpf-ci
2026-10-13 12:21 ` [PATCH v2 4/6] mm/page_owner: record the NUMA node in the scan cursor Zhen Ni
2026-10-13 12:36   ` sashiko-bot
2026-10-14  7:39     ` zhen.ni
2026-10-13 12:21 ` [PATCH v2 5/6] mm/page_owner: add bpf_page_owner_get_memcg_info() kfunc Zhen Ni
2026-10-13 12:49   ` sashiko-bot
2026-10-14  7:47     ` zhen.ni
2026-10-13 12:21 ` [PATCH v2 6/6] selftests/bpf: add tests for the page_owner bpf_iter target Zhen Ni
2026-10-13 12:38   ` sashiko-bot
2026-10-14  8:53     ` zhen.ni
2026-10-13 17:17 ` [PATCH v2 0/6] mm/page_owner: add bpf_iter and kfuncs Zi Yan

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=2a605a34-0e0e-4377-9062-6b511e0be503@easystack.cn \
    --to=zhen.ni@easystack.cn \
    --cc=bpf@vger.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 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.