Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Andreas Hindborg" <a.hindborg@kernel.org>,
	"Tamir Duberstein" <tamird@kernel.org>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@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>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	"Onur Özkan" <work@onurozkan.dev>,
	"Matthew Wilcox" <willy@infradead.org>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Lorenzo Stoakes" <ljs@kernel.org>,
	"Liam R. Howlett" <liam@infradead.org>,
	"Vlastimil Babka" <vbabka@kernel.org>,
	"Harry Yoo" <harry@kernel.org>, "Hao Li" <hao.li@linux.dev>,
	"Christoph Lameter" <cl@gentwo.org>,
	"David Rientjes" <rientjes@google.com>,
	"Roman Gushchin" <roman.gushchin@linux.dev>
Cc: linux-mm@kvack.org
Subject: Re: [PATCH v6 09/12] rust: mm: sheaf: allow use of C initialized static caches
Date: Sat, 21 Nov 2026 13:12:25 +0000	[thread overview]
Message-ID: <sashiko-outbox-227049@kernel.org> (raw)
In-Reply-To: <20261120-xarray-entry-send-v6-9-1f69d7385f70@kernel.org>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [Low] rust: mm: sheaf: missing #[inline] on small helpers and
  C-binding wrappers
- [Low] rust: mm: sheaf: non-vertical crate import formatting
- [Low] rust: mm: sheaf: SBox erases cache mode, allowing into_ptr() on
  dynamic caches
- [Low] rust: mm: sheaf: missing INVARIANT comments and raw pointer in
  CacheRef::Static
--

commit c03ff5cdfb00d1a6cfd826320ab8e9750410636a
Author: Andreas Hindborg <a.hindborg@kernel.org>

rust: mm: sheaf: allow use of C initialized static caches

This commit extends the Rust sheaf abstraction to support C-initialized
static slab caches alongside reference-counted dynamic caches, adding raw
pointer conversion helpers for SBox and exporting the underlying C sheaf
functions.

In rust/kernel/mm/sheaf.rs at line 95 (crate imports):

[Severity: Low]
Could the crate import block use the kernel vertical import style, placing
Arc and ArcBorrow on separate lines?

In rust/kernel/mm/sheaf.rs at lines 172, 616, and 717 (KMemCache::sheaf,
CacheRef, and SBox::static_from_ptr):

[Severity: Low]
CacheRef documents an # Invariants section requiring CacheRef::Static to
hold a NonNull pointer to a valid KMemCache<T> with 'static lifetime,
derived from a &'static KMemCache<T> reference, and CacheRef::as_raw()
relies on this invariant in its SAFETY comment. However, neither
KMemCache::sheaf() nor SBox::static_from_ptr() includes an // INVARIANT:
comment when constructing CacheRef::Static, and SBox::static_from_ptr()
constructs CacheRef::Static by casting a raw *mut bindings::kmem_cache
pointer rather than taking a &'static KMemCache<T>. Could both construction
sites document how the CacheRef invariant holds, and could
SBox::static_from_ptr() accept &'static KMemCache<T> directly?

In rust/kernel/mm/sheaf.rs at lines 197, 548, 628, 694, and 717
(KMemCache::from_raw, Sheaf::refill, CacheRef::clone, SBox::into_ptr, and
SBox::static_from_ptr):

[Severity: Low]
Could KMemCache::from_raw(), Sheaf::refill(), CacheRef::clone(),
SBox::into_ptr(), and SBox::static_from_ptr() be marked with #[inline] to
match the other small helpers and C-binding wrappers in this module and
enable cross-crate inlining?

In rust/kernel/mm/sheaf.rs at lines 667 and 694 (SBox and SBox::into_ptr):

[Severity: Low]
Should SBox carry the Static or Dynamic mode parameter A (or encode the
cache reference type via A) so into_ptr() is only callable on static-cache
allocations?

Because Sheaf::alloc() erases A into a runtime CacheRef<T> enum inside
SBox<T>, SBox::into_ptr() is exposed as a safe method on allocations from a
DynamicSheaf as well. Calling into_ptr() on a dynamic allocation triggers
the debug_assert!() in builds with CONFIG_RUST_DEBUG_ASSERTIONS=y (which is
not mentioned in a # Panics doc section and contradicts the doc comment
saying it leaks a reference), and permanently leaks an
Arc<KMemCacheHandle<T>> reference in non-debug builds so the underlying
kmem_cache is never destroyed.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261120-xarray-entry-send-v6-0-1f69d7385f70@kernel.org?part=9


  reply	other threads:[~2026-11-21 13:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 13:10 [PATCH v6 00/12] rust: xarray: add entry API with preloading Andreas Hindborg
2026-11-20 13:10 ` [PATCH v6 01/12] rust: xarray: minor formatting fixes Andreas Hindborg
2026-11-20 13:10 ` [PATCH v6 02/12] rust: xarray: add debug format for `StoreError` Andreas Hindborg
2026-11-20 13:10 ` [PATCH v6 03/12] xarray: move xas_result() and xa_zero_to_null() to the header Andreas Hindborg
2026-11-20 13:10 ` [PATCH v6 04/12] rust: xarray: add `XArrayState` Andreas Hindborg
2026-11-20 13:10 ` [PATCH v6 05/12] rust: xarray: simplify `Guard::load` Andreas Hindborg
2026-11-20 13:10 ` [PATCH v6 06/12] rust: xarray: add `find_next` and `find_next_mut` Andreas Hindborg
2026-11-20 13:10 ` [PATCH v6 07/12] rust: xarray: add entry API Andreas Hindborg
2026-11-21 13:12   ` sashiko-bot
2026-11-20 13:10 ` [PATCH v6 08/12] rust: mm: add abstractions for allocating from a `sheaf` Andreas Hindborg
2026-11-21 13:12   ` sashiko-bot
2026-11-20 13:10 ` [PATCH v6 09/12] rust: mm: sheaf: allow use of C initialized static caches Andreas Hindborg
2026-11-21 13:12   ` sashiko-bot [this message]
2026-11-20 13:10 ` [PATCH v6 10/12] xarray, radix-tree: enable sheaf support for kmem_cache Andreas Hindborg
2026-11-20 13:10 ` [PATCH v6 11/12] rust: xarray: add preload API Andreas Hindborg
2026-11-20 13:10 ` [PATCH v6 12/12] rust: xarray: document `Guard` lock drop semantics Andreas Hindborg

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-227049@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=akpm@linux-foundation.org \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=cl@gentwo.org \
    --cc=dakr@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=gary@garyguo.net \
    --cc=hao.li@linux.dev \
    --cc=harry@kernel.org \
    --cc=liam@infradead.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=lossin@kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rientjes@google.com \
    --cc=roman.gushchin@linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tamird@kernel.org \
    --cc=tmgross@umich.edu \
    --cc=vbabka@kernel.org \
    --cc=willy@infradead.org \
    --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