From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: Junli Liu <liujunli@lixiang.com>,
linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org
Cc: xiang@kernel.org, chao@kernel.org, yangsonghua@lixiang.com
Subject: Re: [PATCH v3] erofs: fix atomic context detection when !CONFIG_DEBUG_LOCK_ALLOC
Date: Tue, 5 Aug 2025 09:43:15 +0800 [thread overview]
Message-ID: <0c1b7ff7-b053-4868-a550-e2044aba300f@linux.alibaba.com> (raw)
In-Reply-To: <20250805011957.911186-1-liujunli@lixiang.com>
On 2025/8/5 09:19, Junli Liu wrote:
> Since EROFS handles decompression in non-atomic contexts due to
> uncontrollable decompression latencies and vmap() usage, it tries
> to detect atomic contexts and only kicks off a kworker on demand
> in order to reduce unnecessary scheduling overhead.
>
> However, the current approach is insufficient and can lead to
> sleeping function calls in invalid contexts, causing kernel
> warnings and potential system instability. See the stacktrace [1]
> and previous discussion [2].
>
> The current implementation only checks rcu_read_lock_any_held(),
> which behaves inconsistently across different kernel configurations:
>
> - When CONFIG_DEBUG_LOCK_ALLOC is enabled: correctly detects
> RCU critical sections by checking rcu_lock_map
> - When CONFIG_DEBUG_LOCK_ALLOC is disabled: compiles to
> "!preemptible()", which only checks preempt_count and misses
> RCU critical sections
>
> This patch introduces z_erofs_in_atomic() to provide comprehensive
> atomic context detection:
>
> 1. Check RCU preemption depth when CONFIG_PREEMPTION is enabled,
> as RCU critical sections may not affect preempt_count but still
> require atomic handling
>
> 2. Always use async processing when CONFIG_PREEMPT_COUNT is disabled,
> as preemption state cannot be reliably determined
>
> 3. Fall back to standard preemptible() check for remaining cases
>
> The function replaces the previous complex condition check and ensures
> that z_erofs always uses (kthread_)work in atomic contexts to minimize
> scheduling overhead and prevent sleeping in invalid contexts.
>
> [1] Problem stacktrace
> BUG: sleeping function called from invalid context at
> kernel/locking/rtmutex_api.c:510
> in_atomic(): 0, irqs_disabled(): 0, non_block: 0, pid: 107,
> name: irq/54-ufshcd
> preempt_count: 0, expected: 0
> RCU nest depth: 2, expected: 0
>
> [2] https://lore.kernel.org/r/58b661d0-0ebb-4b45-a10d-c5927fb791cd@paulmck-laptop
>
> Signed-off-by: Junli Liu <liujunli@lixiang.com>
This version seems applicable to me:
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Thanks,
Gao Xiang
parent reply other threads:[~2025-08-05 1:48 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <20250805011957.911186-1-liujunli@lixiang.com>]
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=0c1b7ff7-b053-4868-a550-e2044aba300f@linux.alibaba.com \
--to=hsiangkao@linux.alibaba.com \
--cc=chao@kernel.org \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liujunli@lixiang.com \
--cc=xiang@kernel.org \
--cc=yangsonghua@lixiang.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®