Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Vitaly Wool" <vitaly.wool@konsulko.se>,
	"Jens Axboe" <axboe@kernel.dk>,
	"Andreas Hindborg" <a.hindborg@kernel.org>
Cc: "Boqun Feng" <boqun@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"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 v2 2/2] rust: block: add rbrd, a RAM backed block driver
Date: Thu, 03 Dec 2026 07:17:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-247279@kernel.org> (raw)
In-Reply-To: <20261202071723.120957-3-vitaly.wool@konsulko.se>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] rbrd: sub-page discard_granularity set in RamDisk::new()
- [Medium] rbrd: lookup_page() returns None instead of retrying on
  try_get_raw() failure
- [Low] rbrd: module name mismatch between Makefile and module! macro
--

commit 20afca209b17f98938d8414e73dc19da06a3330f
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 written in Rust and
configured via 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]
Should the Kbuild module target name match the name declared in module! in
drivers/block/rbrd/rbrd.rs?

Building rbrd_mod.o sets KBUILD_MODNAME to "rbrd_mod" and produces
rbrd_mod.ko, while module! sets the module name to "rbrd".  When built-in
(CONFIG_BLK_DEV_RUST_RAM=y), vmlinux .modinfo entries are prefixed with
"rbrd." while modules.builtin records rbrd_mod.ko, breaking modinfo
lookups.  Since rbrd.rs is in its own directory, this can just be:

  obj-$(CONFIG_BLK_DEV_RUST_RAM) += rbrd.o

> diff --git a/drivers/block/rbrd/rbrd.rs b/drivers/block/rbrd/rbrd.rs
> new file mode 100644
> index 0000000000000..c2095105c6e28
> --- /dev/null
> +++ b/drivers/block/rbrd/rbrd.rs
[ ... ]
> +impl RamDisk {
> +    fn new(name: &CStr, block_size: u32, capacity_mib: u64) -> Result<Arc<GenDisk<Self>>> {
[ ... ]
> +        gen_disk::GenDiskBuilder::new()
> +            .capacity_sectors(capacity_sectors)
> +            .logical_block_size(block_size)?
> +            .physical_block_size(block_size)?
> +            .max_hw_discard_sectors(MAX_DISCARD_SECTORS)
> +            .build(fmt!("{}", name.to_str()?), tagset, storage)
> +    }
> +}

[Severity: Medium]
Does leaving discard_granularity unset (with physical_block_size set to
block_size) advertise a sub-page discard_granularity when block_size <
PAGE_SIZE?

GenDiskBuilder leaves queue_limits.discard_granularity at 0, which
blk_validate_limits() defaults to physical_block_size (512 bytes by
default).  However, Storage::discard() only frees full PAGE_SIZE pages:

drivers/block/rbrd/rbrd.rs:Storage::discard() {
        let start = sector << block::SECTOR_SHIFT;
        let end = start + u64::from(bytes);
        let first = start.div_ceil(PAGE_SIZE as u64);
        let last = end >> PAGE_SHIFT;

Besides reporting a sub-page discard_granularity for which sub-page
discards are no-ops, when a discard larger than MAX_DISCARD_SECTORS (128
MiB) starts at a sector aligned to block_size but not PAGE_SIZE, the block
layer splits it at a block_size boundary rather than a PAGE_SIZE boundary,
leaving the page straddling the split boundary allocated.

[ ... ]

> +    fn lookup_page(slot: &Atomic<*mut Page<Guarded>>) -> Option<ARef<Page<Guarded>>> {
> +        loop {
> +            let ptr = NonNull::new(slot.load(Acquire))?;
> +
> +            // SAFETY: Every non-null pointer stored in a slot came from
> +            // `ARef::into_raw` on a `Page<Guarded>`, whether or not the page is
> +            // (still) owned by this slot. The reference is only dropped, not
> +            // used, unless the re-check below confirms that the slot still
> +            // holds it, and thus that it is still our page.
> +            let page = unsafe { Page::try_get_raw(ptr) }?;

[Severity: Medium]
If Page::try_get_raw(ptr) returns None because the page's refcount just
dropped to zero, shouldn't lookup_page() continue the loop to reload the
slot rather than returning None via '?'?

CPU0                            CPU1                    CPU2
Storage::lookup_page(slot)
  ptr = slot.load(Acquire)
                                Storage::discard()
                                  slot.xchg(null)
                                  drop(ARef) (refcnt -> 0)
                                                        Storage::try_insert_page(slot)
                                                          slot.cmpxchg(null, new_ptr)
  Page::try_get_raw(ptr)?
    --> returns None

If a concurrent discard frees the old page and a writer installs a new
page before Page::try_get_raw(ptr) runs, lookup_page() returns None even
though the slot holds a valid page.  Storage::read_chunk() will then read
from zero_page instead of the installed page, and
Storage::get_or_insert_page() will fall through to try_insert_page() and
perform an unnecessary GFP_NOWAIT allocation (which, if it fails under
memory pressure during Storage::write_chunk(), fails the write with
BLK_STS_IOERR).

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


      reply	other threads:[~2026-12-03  7:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  7:17 [PATCH v2 0/2] rust: block: add rbrd, a RAM backed block driver Vitaly Wool
2026-12-02  7:17 ` [PATCH v2 1/2] rust: page: add guarded pages Vitaly Wool
2026-12-02  7:17 ` [PATCH v2 2/2] rust: block: add rbrd, a RAM backed block driver Vitaly Wool
2026-12-03  7:17   ` sashiko-bot [this message]

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-247279@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