From: Jens Axboe <axboe@kernel.dk>
To: linux-block@vger.kernel.org
Cc: hch@infradead.org, Jens Axboe <axboe@kernel.dk>, stable@vger.kernel.org
Subject: [PATCH 3/4] brd: only preload radix tree if we're using a blocking gfp mask
Date: Thu, 16 Feb 2023 08:19:17 -0700 [thread overview]
Message-ID: <20230216151918.319585-4-axboe@kernel.dk> (raw)
In-Reply-To: <20230216151918.319585-1-axboe@kernel.dk>
radix_tree_preload() warns on attempting to call it with an allocation
mask that doesn't allow blocking. While that warning could arguably
be removed, we need to handle radix insertion failures anyway as they
are more likely if we cannot block to get memory.
Remove legacy BUG_ON()'s and turn them into proper errors instead, one
for the allocation failure and one for finding a page that doesn't
match the correct index.
Cc: stable@vger.kernel.org # 5.10+
Signed-off-by: Jens Axboe <axboe@kernel.dk>
---
drivers/block/brd.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/block/brd.c b/drivers/block/brd.c
index 1ddada0cdaca..6019ef23344f 100644
--- a/drivers/block/brd.c
+++ b/drivers/block/brd.c
@@ -84,6 +84,7 @@ static int brd_insert_page(struct brd_device *brd, sector_t sector, gfp_t gfp)
{
pgoff_t idx;
struct page *page;
+ int ret = 0;
page = brd_lookup_page(brd, sector);
if (page)
@@ -93,7 +94,7 @@ static int brd_insert_page(struct brd_device *brd, sector_t sector, gfp_t gfp)
if (!page)
return -ENOMEM;
- if (radix_tree_preload(gfp)) {
+ if (gfpflags_allow_blocking(gfp) && radix_tree_preload(gfp)) {
__free_page(page);
return -ENOMEM;
}
@@ -104,8 +105,10 @@ static int brd_insert_page(struct brd_device *brd, sector_t sector, gfp_t gfp)
if (radix_tree_insert(&brd->brd_pages, idx, page)) {
__free_page(page);
page = radix_tree_lookup(&brd->brd_pages, idx);
- BUG_ON(!page);
- BUG_ON(page->index != idx);
+ if (!page)
+ ret = -ENOMEM;
+ else if (page->index != idx)
+ ret = -EIO;
} else {
brd->brd_nr_pages++;
}
--
2.39.1
next prev parent reply other threads:[~2023-02-16 15:19 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-16 15:19 [PATCH 0/4] Support REQ_NWOAIT in brd Jens Axboe
2023-02-16 15:19 ` [PATCH 1/4] brd: return 0/-error from brd_insert_page() Jens Axboe
2023-02-16 16:05 ` Christoph Hellwig
2023-02-16 16:12 ` Jens Axboe
2023-02-16 16:14 ` Christoph Hellwig
2023-02-16 16:16 ` Jens Axboe
2023-02-17 11:50 ` Johannes Thumshirn
2023-02-16 15:19 ` [PATCH 2/4] brd: check for REQ_NOWAIT and set correct page allocation mask Jens Axboe
2023-02-16 16:06 ` Christoph Hellwig
2023-02-17 11:53 ` Johannes Thumshirn
2023-02-16 15:19 ` Jens Axboe [this message]
2023-02-16 15:25 ` [PATCH 3/4] brd: only preload radix tree if we're using a blocking gfp mask Jens Axboe
2023-02-16 16:07 ` Christoph Hellwig
2023-02-16 16:12 ` Jens Axboe
2023-02-16 19:09 ` kernel test robot
2023-02-16 15:19 ` [PATCH 4/4] brd: mark as nowait compatible 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=20230216151918.319585-4-axboe@kernel.dk \
--to=axboe@kernel.dk \
--cc=hch@infradead.org \
--cc=linux-block@vger.kernel.org \
--cc=stable@vger.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