Linux virtualization list
 help / color / mirror / Atom feed
From: Nilay Shroff <nilay@linux.ibm.com>
To: yukuai@fygo.io, "Yu Kuai" <yukuai@kernel.org>,
	"Jens Axboe" <axboe@kernel.dk>, "Tejun Heo" <tj@kernel.org>,
	"Josef Bacik" <josef@toxicpanda.com>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Michal Koutný" <mkoutny@suse.com>
Cc: Christoph Hellwig <hch@lst.de>, Tao Cui <cui.tao@linux.dev>,
	Jan Kara <jack@suse.cz>, Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>, Coly Li <colyli@fygo.io>,
	Kent Overstreet <kent.overstreet@linux.dev>,
	Alasdair Kergon <agk@redhat.com>,
	Mike Snitzer <snitzer@kernel.org>,
	Mikulas Patocka <mpatocka@redhat.com>,
	Benjamin Marzinski <bmarzins@redhat.com>,
	Song Liu <song@kernel.org>, Li Nan <magiclinan@didiglobal.com>,
	Xiao Ni <xiao@kernel.org>,
	Pankaj Gupta <pankaj.gupta.linux@gmail.com>,
	Dan Williams <djbw@kernel.org>,
	Vishal Verma <vishal.l.verma@intel.com>,
	Dave Jiang <dave.jiang@intel.com>,
	Alison Schofield <alison.schofield@intel.com>,
	Ira Weiny <iweiny@kernel.org>,
	Andreas Gruenbacher <agruenba@redhat.com>,
	Matthew Wilcox <willy@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Chris Li <chrisl@kernel.org>, Kairui Song <kasong@tencent.com>,
	Kemeng Shi <shikemeng@huaweicloud.com>,
	Nhat Pham <nphamcs@gmail.com>, Baoquan He <baoquan.he@linux.dev>,
	Barry Song <baohua@kernel.org>,
	Youngjun Park <youngjun.park@lge.com>,
	cgroups@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-block@vger.kernel.org,
	linux-bcache@vger.kernel.org, dm-devel@lists.linux.dev,
	linux-raid@vger.kernel.org, nvdimm@lists.linux.dev,
	virtualization@lists.linux.dev, gfs2@lists.linux.dev,
	linux-fsdevel@vger.kernel.org, linux-mm@kvack.org
Subject: Re: [PATCH 2/3] blk-cgroup: store blkcg in bio instead of blkg
Date: Mon, 7 Sep 2026 11:32:18 +0530	[thread overview]
Message-ID: <a123f309-6ec7-470f-b5b0-f08cca6d2627@linux.ibm.com> (raw)
In-Reply-To: <befbc177-f7f5-4c44-b02e-20a99fc64c0c@fygo.io>

On 9/6/26 5:09 PM, yu kuai wrote:
> Hi,
> 
> 在 2026/9/6 18:56, Nilay Shroff 写道:
>> On 8/23/26 7:00 PM, Yu Kuai wrote:
>>> @@ -257,20 +262,21 @@ static inline bool
>>> bio_issue_as_root_blkg(struct bio *bio)
>>>     * @blkcg: blkcg of interest
>>>     * @q: request_queue of interest
>>>     *
>>>     * Lookup a blkg for the @blkcg - @q pair, whether it is online or
>>> dying.
>>>     *
>>> - * Must be called in a RCU critical section.
>>> + * Must be called with either RCU read lock or queue_lock held.
>>>     *
>>>     * This does not acquire a reference.  The caller must already hold
>>> one, or
>>>     * have the blkg pinned by I/O.
>>>     */
>>>    static inline struct blkcg_gq *blkg_lookup_any(struct blkcg *blkcg,
>>>                               struct request_queue *q)
>>>    {
>>> -    RCU_LOCKDEP_WARN(!rcu_read_lock_held(),
>>> -             "blkg_lookup_any() requires an RCU read lock");
>>> +    RCU_LOCKDEP_WARN(!rcu_read_lock_held() &&
>>> +             !lockdep_is_held(&q->queue_lock),
>>> +             "blkg_lookup_any() requires an RCU read lock or
>>> queue_lock");
>>>          return rhashtable_lookup(&q->blkg_hash, &blkcg->css.id,
>>>                     blkg_hash_params);
>>>    }
>>
>> The changes look good to me. However, rhashtable_lookup() is annotated
>> with __must_hold_shared(RCU). Since we now officially support Clang
>> context annotations in the block layer, compiling with the latest
>> Clang/LLVM generates a number of context warnings, for example:
>>
>> block/blk-cgroup.h:277:9: warning: calling function 'rhashtable_lookup'
>> requires holding __ctx_lock_RCU 'RCU' [-Wthread-safety-analysis]
>>    277 |         return rhashtable_lookup(&q->blkg_hash, &blkcg->css.id,
>>        |                ^
>>
>> The same warning is reported from several other block layer source
>> files that include blk-cgroup.h.
>>
>> This indicates that rhashtable_lookup() requires the RCU read lock
>> from Clang's context-analysis perspective. Looking at the call paths of
>> blkg_lookup_any(), it appears that not all callers hold
>> rcu_read_lock() when invoking it.
> 
> I was not aware of the above clang warning, this should not be a real problem
> because queue_lock should have the same protection as rcu, and I was trying
> not to make this patch too complex.
> 
I agree that this is not a runtime correctness issue when the lookup is already
protected by q->queue_lock.

> I add the rcu_read_lock() in the following patch to covert queue_lock to blkcg_mutex:
> 
> [RFC PATCH v3 3/6] blk-cgroup: protect blkgs with blkcg_mutex - Yu Kuai <https://lore.kernel.org/all/20260823152926.1043863-4-yukuai@kernel.org/>
> 
> Since this is related to compile warning, I'll move the rcu protection to this
> patch.
> 
Since rhashtable_lookup() is annotated with __must_hold_shared(RCU), Clang's
context analysis still reports warnings for these call paths. While this
doesn't cause a build failure (and only generates warning) when CONFIG_WERROR
is not enabled, it could do so for configurations that enable CONFIG_WERROR=y.

So IMO, moving the rcu_read_lock() protection into this patch makes sense.
This would avoid introducing the Clang warnings/errors in this patch, and then
you may accordingly adjust your subsequent series where the q->queue_lock protection
is removed and the blkg lookup paths are protected by RCU.

I also noticed that some paths already take q->queue_lock followed by rcu_read_lock(),
so adding the RCU protection here should be consistent with those existing paths.

Thanks,
--Nilay

  reply	other threads:[~2026-09-07  6:03 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-23 13:30 [PATCH 0/3] blk-cgroup: store blkcg in bio before blkcg_mutex conversion Yu Kuai
2026-08-23 13:30 ` [PATCH 1/3] blk-cgroup: use a request_queue rhashtable for blkg lookup Yu Kuai
2026-09-06 11:03   ` Nilay Shroff
2026-08-23 13:30 ` [PATCH 2/3] blk-cgroup: store blkcg in bio instead of blkg Yu Kuai
2026-09-02 13:49   ` Christoph Hellwig
2026-09-06 10:56   ` Nilay Shroff
2026-09-06 11:39     ` yu kuai
2026-09-07  6:02       ` Nilay Shroff [this message]
2026-08-23 13:30 ` [PATCH 3/3] blk-cgroup: move async bio punt state to blkcg Yu Kuai
2026-09-02 13:49   ` Christoph Hellwig
2026-09-06 11:01   ` Nilay Shroff
2026-09-06 11:41     ` yu kuai

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=a123f309-6ec7-470f-b5b0-f08cca6d2627@linux.ibm.com \
    --to=nilay@linux.ibm.com \
    --cc=agk@redhat.com \
    --cc=agruenba@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=alison.schofield@intel.com \
    --cc=axboe@kernel.dk \
    --cc=baohua@kernel.org \
    --cc=baoquan.he@linux.dev \
    --cc=bmarzins@redhat.com \
    --cc=cgroups@vger.kernel.org \
    --cc=chrisl@kernel.org \
    --cc=colyli@fygo.io \
    --cc=corbet@lwn.net \
    --cc=cui.tao@linux.dev \
    --cc=dave.jiang@intel.com \
    --cc=djbw@kernel.org \
    --cc=dm-devel@lists.linux.dev \
    --cc=gfs2@lists.linux.dev \
    --cc=hannes@cmpxchg.org \
    --cc=hch@lst.de \
    --cc=iweiny@kernel.org \
    --cc=jack@suse.cz \
    --cc=josef@toxicpanda.com \
    --cc=kasong@tencent.com \
    --cc=kent.overstreet@linux.dev \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-raid@vger.kernel.org \
    --cc=magiclinan@didiglobal.com \
    --cc=mkoutny@suse.com \
    --cc=mpatocka@redhat.com \
    --cc=nphamcs@gmail.com \
    --cc=nvdimm@lists.linux.dev \
    --cc=pankaj.gupta.linux@gmail.com \
    --cc=shikemeng@huaweicloud.com \
    --cc=skhan@linuxfoundation.org \
    --cc=snitzer@kernel.org \
    --cc=song@kernel.org \
    --cc=tj@kernel.org \
    --cc=virtualization@lists.linux.dev \
    --cc=vishal.l.verma@intel.com \
    --cc=willy@infradead.org \
    --cc=xiao@kernel.org \
    --cc=youngjun.park@lge.com \
    --cc=yukuai@fygo.io \
    --cc=yukuai@kernel.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