Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vitaly Wool" <vitaly.wool@konsulko.se>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Jens Axboe" <axboe@kernel.dk>, "Miguel Ojeda" <ojeda@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>
Cc: "Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Liam R . Howlett" <liam@infradead.org>,
	linux-mm@kvack.org
Subject: Re: [PATCH 3/3] rust: block: add rbrd, a RAM backed block driver
Date: Wed, 18 Nov 2026 23:36:25 +0000	[thread overview]
Message-ID: <sashiko-outbox-222198@kernel.org> (raw)
In-Reply-To: <20261117233211.3137168-4-vitaly.wool@konsulko.se>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] rbrd: dropping speculative page in lookup_page() calls
  __free_pages()
- [Medium] rbrd: lookup_page() returns None instead of retrying on
  try_get_raw() failure
- [Low] rbrd: Kbuild module name rbrd_mod mismatches module! macro name
  rbrd
--

commit b57d882ab6ffa2969530912dd82ffe3996588b30
Author: Vitaly Wool <vitaly.wool@konsulko.se>

rust: block: add rbrd, a RAM backed block driver

This commit adds a RAM-backed block device driver in Rust that allocates
backing pages on first write, tracks them in a flat array of atomic
pointers, and exposes device configuration through configfs.

> diff --git a/drivers/block/rbrd/Makefile b/drivers/block/rbrd/Makefile
> new file mode 100644
> index 0000000000000..b5e0c10b4beaf
> --- /dev/null
> +++ b/drivers/block/rbrd/Makefile
> @@ -0,0 +1,2 @@
> +obj-$(CONFIG_BLK_DEV_RUST_RAM) += rbrd_mod.o
> +rbrd_mod-y := rbrd.o

[Severity: Low]
Does naming the Kbuild target rbrd_mod.o mismatch the module! declaration
in drivers/block/rbrd/rbrd.rs, which sets name: "rbrd"?

That sets KBUILD_MODNAME to rbrd_mod and RUST_MODFILE to
drivers/block/rbrd/rbrd_mod, so loadable builds produce rbrd_mod.ko while
built-in builds emit .modinfo entries prefixed with rbrd. that do not match
the rbrd_mod name recorded in modules.builtin.

> diff --git a/drivers/block/rbrd/rbrd.rs b/drivers/block/rbrd/rbrd.rs
> new file mode 100644
> index 0000000000000..e5e6981725074
> --- /dev/null
> +++ b/drivers/block/rbrd/rbrd.rs

[ ... ]

> +    fn lookup_page(&self, index: usize) -> Option<Page> {
> +        let slot = self.pages.slot(index)?;
> +
> +        loop {
> +            let ptr = NonNull::new(slot.load(Acquire))?;
> +
> +            // SAFETY: Every non-null pointer stored in a slot came from
> +            // `Page::into_raw`, i.e. is a `struct page` pointer; `struct page`
> +            // objects are never freed or reused for anything else, so `ptr`
> +            // always points at a valid one, whether or not it is (still)
> +            // actually owned by this slot.
> +            let Some(page) = (unsafe { Page::try_get_raw(ptr) }) else {
> +                // The page's last reference was already dropped concurrently.
> +                return None;
> +            };

[Severity: Medium]
Should lookup_page() continue the loop instead of returning None when
Page::try_get_raw(ptr) fails?

CPU0                      CPU1                      CPU2
lookup_page(index)
  ptr = slot.load()
                          discard()
                            slot.xchg(null)
                            drop(page1)
                                                    try_insert_page(index)
                                                      slot.cmpxchg(null, page2)
  Page::try_get_raw(ptr)
    -> None
  return None  <-- misses page2 in slot

If page1 is discarded and page2 is inserted into the same slot before CPU0
calls Page::try_get_raw(ptr), lookup_page() returns None even though the
slot holds page2.  read_chunk() then zeroes the buffer instead of reading
page2, and write_chunk() calls try_insert_page() and performs an extra
GFP_NOWAIT page allocation that can fail with ENOMEM.

> +
> +            if slot.load(Relaxed) == ptr.as_ptr() {
> +                return Some(page);
> +            }
> +
> +            // The slot was concurrently emptied, or now holds a different
> +            // page; `page` is not (or no longer) ours to use. Drop our
> +            // reference and retry.
> +            drop(page);
> +        }
> +    }

[Severity: Medium]
Can dropping the speculative Page reference here free a reallocated page
with __free_pages(page, 0) instead of put_page()?

CPU0                           CPU1                      CPU2
lookup_page(index)
  ptr = slot.load()
                               discard()
                                 slot.xchg(null)
                                 drop(page)
                                                         (reallocates ptr as a
                                                          compound or LRU folio)
  Page::try_get_raw(ptr)
    get_page_unless_zero(ptr)
                                                         folio_put()
  slot.load() != ptr
  drop(page)
    __free_pages(ptr, 0)  <-- bypasses __folio_put() / wrong order

rust/kernel/page.rs:<Page as Drop>::drop() {
	unsafe { bindings::__free_pages(self.page.as_ptr(), 0) };
}

Once discard() frees the page back to the page allocator, another subsystem
can reallocate that struct page as an LRU, memcg-charged, hugetlb, or
higher-order compound folio before Page::try_get_raw() increments its
refcount.  If the new owner drops its reference before CPU0 re-checks the
slot, drop(page) releases the last reference via __free_pages(ptr, 0)
rather than put_page(ptr), bypassing __folio_put() and triggering
VM_BUG_ON_PAGE() / bad_page() or corrupting the page allocator.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117233211.3137168-1-vitaly.wool@konsulko.se?part=3


  reply	other threads:[~2026-11-18 23:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 23:32 [PATCH 0/3] rust: block: add rbrd, a RAM backed block driver Vitaly Wool
2026-11-17 23:32 ` [PATCH 1/3] rust: block: add bio segment iteration and request accessors Vitaly Wool
2026-11-18 15:19   ` Andreas Hindborg
2026-11-18 23:36   ` sashiko-bot
2026-11-17 23:32 ` [PATCH 2/3] rust: page: add reference counting, raw pointers and a private bit lock Vitaly Wool
2026-11-18 15:23   ` Andreas Hindborg
2026-11-18 23:36   ` sashiko-bot
2026-11-17 23:32 ` [PATCH 3/3] rust: block: add rbrd, a RAM backed block driver Vitaly Wool
2026-11-18 23:36   ` sashiko-bot [this message]
2026-11-18 11:43 ` [PATCH 0/3] " Jan Engelhardt
2026-11-18 14:48   ` Vitaly Wool

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=sashiko-outbox-222198@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=axboe@kernel.dk \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=gary@garyguo.net \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=vitaly.wool@konsulko.se \
    --cc=work@onurozkan.dev \
    /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