public inbox for linux-block@vger.kernel.org
 help / color / mirror / Atom feed
From: Jens Axboe <axboe@kernel.dk>
To: Yu Kuai <yukuai1@huaweicloud.com>, hch@lst.de
Cc: penguin-kernel@I-love.SAKURA.ne.jp, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org, yi.zhang@huawei.com,
	yangerkun@huawei.com, johnny.chenyi@huawei.com,
	"yukuai (C)" <yukuai3@huawei.com>
Subject: Re: [PATCH v2] brd: fix sleeping function called from invalid context in brd_insert_page()
Date: Mon, 30 Jun 2025 21:00:58 -0600	[thread overview]
Message-ID: <c28dd90a-3777-49fa-a662-32c61da22860@kernel.dk> (raw)
In-Reply-To: <773a49cf-3908-85d2-5693-5cbd6530a933@huaweicloud.com>

On 6/30/25 7:28 PM, Yu Kuai wrote:
> Hi,
> 
> ? 2025/06/30 23:28, Jens Axboe ??:
>> On 6/30/25 9:24 AM, Jens Axboe wrote:
>>> On 6/30/25 5:28 AM, Yu Kuai wrote:
>>>> From: Yu Kuai <yukuai3@huawei.com>
>>>>
>>>> __xa_cmpxchg() is called with rcu_read_lock(), and it will allocate
>>>> memory if necessary.
>>>>
>>>> Fix the problem by moving rcu_read_lock() after __xa_cmpxchg(), meanwhile,
>>>> it still should be held before xa_unlock(), prevent returned page to be
>>>> freed by concurrent discard.
>>>
>>> The rcu locking in there is a bit of a mess, imho. What _exactly_ is the
>>> rcu read side locking protecting? Is it only needed around the lookup
>>> and insert? We even hold it over the kmap and copy, which seems very
>>> heavy handed.
>>
>> Gah it's holding the page alive too. Can't we just grab a ref to the
>> page when inserting it, and drop that at free time? It would be a lot
>> better to have only the lookup be RCU protected, having the full
>> copies under it seems kind of crazy.
> 
> In this case, we must grab a ref to the page for each read/write as
> well, I choose RCU because I think it has less performance overhead than
> page ref, which is atomic. BTW, I thought copy at most one page is
> lightweight, if this is not true, I agree page ref is better.

Right, you'd need to grab a ref. I do think that is (by far) the better
solution. Yes if you microbenchmark I'm sure the current approach will
look fine, but it's a heavy section inside an rcu read lock and will
hold off the grace period.

So yeah, I do think it'd be a lot better to do proper page references on
lookup+free, and have just the lookup be behind rcu.

-- 
Jens Axboe

  reply	other threads:[~2025-07-01  3:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-30 11:28 [PATCH v2] brd: fix sleeping function called from invalid context in brd_insert_page() Yu Kuai
2025-06-30 15:24 ` Jens Axboe
2025-06-30 15:28   ` Jens Axboe
2025-07-01  1:28     ` Yu Kuai
2025-07-01  3:00       ` Jens Axboe [this message]
2025-07-01  7:38         ` Yu Kuai
2025-07-01 14:01           ` Jens Axboe
2025-07-01 14:14 ` Jens Axboe

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=c28dd90a-3777-49fa-a662-32c61da22860@kernel.dk \
    --to=axboe@kernel.dk \
    --cc=hch@lst.de \
    --cc=johnny.chenyi@huawei.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai1@huaweicloud.com \
    --cc=yukuai3@huawei.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