From: Christoph Hellwig <hch@infradead.org>
To: Yu Kuai <yukuai1@huaweicloud.com>
Cc: axboe@kernel.dk, kbusch@kernel.org, linux-block@vger.kernel.org,
linux-kernel@vger.kernel.org, yukuai3@huawei.com,
yi.zhang@huawei.com, yangerkun@huawei.com,
johnny.chenyi@huawei.com
Subject: Re: [PATCH 1/5] brd: fix oops if write concurrent with discard
Date: Sun, 20 Apr 2025 22:22:12 -0700 [thread overview]
Message-ID: <aAXWBEQ93Y1zteOA@infradead.org> (raw)
In-Reply-To: <20250418093826.3149293-2-yukuai1@huaweicloud.com>
On Fri, Apr 18, 2025 at 05:38:22PM +0800, Yu Kuai wrote:
> copy = min_t(size_t, n, PAGE_SIZE - offset);
> page = brd_lookup_page(brd, sector);
> - BUG_ON(!page);
> -
> - dst = kmap_atomic(page);
> - memcpy(dst + offset, src, copy);
> - kunmap_atomic(dst);
> + if (page) {
> + dst = kmap_local_page(page);
> + memcpy(dst + offset, src, copy);
> + kunmap_local(dst);
> + }
I don't see how this can fix any race, it just narrows down the
race window. To fix the race for real, copy_to_brd_setup needs
to return a page and keep a reference to it for the caller. The
caller then only needs to operate on a single page.
We'll also need to do something similar for brd_lookup_page to
ensure the page reference doesn't go away after the xarray lookup
but before using the page.
> Also fix following checkpatch warnings:
> WARNING: Deprecated use of 'kmap_atomic', prefer 'kmap_local_page' instead
> WARNING: Deprecated use of 'kunmap_atomic', prefer 'kunmap_local' instead
This really should be using bvec_kmap_local. I actually have an
entire series to fix that and clean up some of the surroundings that I
need to send out. Let me dust that off because it might help with the
above mentioned fixes as well.
next prev parent reply other threads:[~2025-04-21 5:22 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-18 9:38 [PATCH 0/5] brd: discard bugfix Yu Kuai
2025-04-18 9:38 ` [PATCH 1/5] brd: fix oops if write concurrent with discard Yu Kuai
2025-04-21 5:22 ` Christoph Hellwig [this message]
2025-04-18 9:38 ` [PATCH 2/5] brd: synchronize using page and free page with rcu Yu Kuai
2025-04-21 5:24 ` Christoph Hellwig
2025-04-21 7:08 ` Yu Kuai
2025-04-18 9:38 ` [PATCH 3/5] brd: fix aligned_sector from brd_do_discard() Yu Kuai
2025-04-21 5:25 ` Christoph Hellwig
2025-04-18 9:38 ` [PATCH 4/5] brd: fix discard end sector Yu Kuai
2025-04-21 5:26 ` Christoph Hellwig
2025-04-18 9:38 ` [PATCH 5/5] brd: zero data for discard that is not aligned to page Yu Kuai
2025-04-21 5:27 ` Christoph Hellwig
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=aAXWBEQ93Y1zteOA@infradead.org \
--to=hch@infradead.org \
--cc=axboe@kernel.dk \
--cc=johnny.chenyi@huawei.com \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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 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.