Rust for Linux List
 help / color / mirror / Atom feed
* [PATCH] rust: block: gen_disk: set fops.owner from driver module pointer
@ 2026-08-11  6:51 Alvin Sun
  2026-08-11 12:20 ` Miguel Ojeda
  0 siblings, 1 reply; 3+ messages in thread
From: Alvin Sun @ 2026-08-11  6:51 UTC (permalink / raw)
  To: Andreas Hindborg, Boqun Feng, Miguel Ojeda, Gary Guo,
	Björn Roy Baron, Benno Lossin, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan
  Cc: linux-block, rust-for-linux, Alvin Sun

Set `fops.owner` from the driver module pointer via
`this_module::<T::OwnerModule>().as_ptr()` instead of defaulting to
null, so the module cannot be unloaded while a block device is still
in use.

Signed-off-by: Alvin Sun <alvin.sun@linux.dev>
---
The fops.owner fix series [1] covered DRM, miscdevice, configfs and
binder, but missed the block layer's `GenDisk` abstraction.

This patch was meant to be sent separately, but I forgot to send it.

[1] https://lore.kernel.org/r/20260723-fix-fops-owner-v9-0-c1c3af7f7bcb@linux.dev/
---
 rust/kernel/block/mq/gen_disk.rs | 34 ++++++++++------------------------
 1 file changed, 10 insertions(+), 24 deletions(-)

diff --git a/rust/kernel/block/mq/gen_disk.rs b/rust/kernel/block/mq/gen_disk.rs
index fc97dd8739746..215c407d466df 100644
--- a/rust/kernel/block/mq/gen_disk.rs
+++ b/rust/kernel/block/mq/gen_disk.rs
@@ -125,30 +125,9 @@ pub fn build<T: Operations>(
             )
         })?;
 
-        const TABLE: bindings::block_device_operations = bindings::block_device_operations {
-            submit_bio: None,
-            open: None,
-            release: None,
-            ioctl: None,
-            compat_ioctl: None,
-            check_events: None,
-            unlock_native_capacity: None,
-            getgeo: None,
-            set_read_only: None,
-            swap_slot_free_notify: None,
-            report_zones: None,
-            devnode: None,
-            alternative_gpt_sector: None,
-            get_unique_id: None,
-            // TODO: Set to `THIS_MODULE`.
-            owner: core::ptr::null_mut(),
-            pr_ops: core::ptr::null_mut(),
-            free_disk: None,
-            poll_bio: None,
-        };
-
-        // SAFETY: `gendisk` is a valid pointer as we initialized it above
-        unsafe { (*gendisk).fops = &TABLE };
+        // SAFETY: `gendisk` is a valid pointer. We have exclusive access,
+        // since the disk is not added to the VFS yet.
+        unsafe { (*gendisk).fops = &GenDisk::<T>::VTABLE };
 
         let cleanup_failure = ScopeGuard::new_with_data((gendisk, data), |(gendisk, data)| {
             // SAFETY: `gendisk` came from `__blk_mq_alloc_disk()` above and
@@ -211,6 +190,13 @@ pub struct GenDisk<T: Operations> {
     gendisk: *mut bindings::gendisk,
 }
 
+impl<T: Operations> GenDisk<T> {
+    const VTABLE: bindings::block_device_operations = bindings::block_device_operations {
+        owner: crate::module::this_module::<T::OwnerModule>().as_ptr(),
+        ..pin_init::zeroed()
+    };
+}
+
 // SAFETY: `GenDisk` is an owned pointer to a `struct gendisk` and an `Arc` to a
 // `TagSet` It is safe to send this to other threads as long as T is Send.
 unsafe impl<T: Operations + Send> Send for GenDisk<T> {}

---
base-commit: 2ee859ebf156157609f71060ae472711c8cbc326
change-id: 20260810-fix-gendisk-owner-a84d0725ab2b
prerequisite-patch-id: 347c5a3c6dbef9832bfce8419fc23e6e08ba477f
prerequisite-change-id: 20260519-fix-fops-owner-e3a77bb27c6c:v10
prerequisite-patch-id: 347c5a3c6dbef9832bfce8419fc23e6e08ba477f
prerequisite-patch-id: 190cfd53d3430ade053b15db36cac9e372e2566d
prerequisite-patch-id: fdb2387ea1074c3bf16028b58c3df73e2e1783b1
prerequisite-patch-id: f38222c64f7d29781036ae8673808cf4e9a9d430
prerequisite-patch-id: da94d5d3af25778145b976f65f7eac281dc6ae79
prerequisite-patch-id: e5c034ff639d7eebe730922db0ed02492f401dd0
prerequisite-patch-id: 502035d4e05da3ed939b8bd65801a6fd8a01d788
prerequisite-patch-id: 0ccf22bbdee039964cb064f33a8c7a0925dbd57b
prerequisite-patch-id: e0595d6120868cdf3e87fa335a81e10f0e346c80
prerequisite-patch-id: f27fc645020b296d289c31fc73dbfef993294464
prerequisite-patch-id: 159f88cf73892b94117070090a58c7b68e08b8c1

Best regards,
-- 
Alvin Sun <alvin.sun@linux.dev>



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] rust: block: gen_disk: set fops.owner from driver module pointer
  2026-08-11  6:51 [PATCH] rust: block: gen_disk: set fops.owner from driver module pointer Alvin Sun
@ 2026-08-11 12:20 ` Miguel Ojeda
  2026-08-11 13:53   ` Alvin Sun
  0 siblings, 1 reply; 3+ messages in thread
From: Miguel Ojeda @ 2026-08-11 12:20 UTC (permalink / raw)
  To: Alvin Sun
  Cc: Andreas Hindborg, Boqun Feng, Miguel Ojeda, Gary Guo,
	Björn Roy Baron, Benno Lossin, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, linux-block, rust-for-linux

On Tue, Aug 11, 2026 at 8:51 AM Alvin Sun <alvin.sun@linux.dev> wrote:
>
> This patch was meant to be sent separately, but I forgot to send it.

Do you mean "not separately"? i.e. in the series?

I asked Andreas for his Acked-by.

Cheers,
Miguel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] rust: block: gen_disk: set fops.owner from driver module pointer
  2026-08-11 12:20 ` Miguel Ojeda
@ 2026-08-11 13:53   ` Alvin Sun
  0 siblings, 0 replies; 3+ messages in thread
From: Alvin Sun @ 2026-08-11 13:53 UTC (permalink / raw)
  To: Miguel Ojeda
  Cc: Andreas Hindborg, Boqun Feng, Miguel Ojeda, Gary Guo,
	Björn Roy Baron, Benno Lossin, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Daniel Almeida, Tamir Duberstein,
	Alexandre Courbot, Onur Özkan, linux-block, rust-for-linux


On 8/11/26 20:20, Miguel Ojeda wrote:
> On Tue, Aug 11, 2026 at 8:51 AM Alvin Sun <alvin.sun@linux.dev> wrote:
>> This patch was meant to be sent separately, but I forgot to send it.
> Do you mean "not separately"? i.e. in the series?

Hi Miguel,

Thanks for taking a look.

To clarify: when I sent the fops.owner series, I did indeed overlook
`GenDisk`. After the series was out, I realized the gap, prepared this
patch, and privately asked Andreas (back in late June) for his
thoughts. He suggested sending it standalone with the series as a
dependency. I then got sidetracked by other things and forgot to send
it out.

Best regards,
Alvin

>
> I asked Andreas for his Acked-by.
>
> Cheers,
> Miguel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-11 13:54 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-11  6:51 [PATCH] rust: block: gen_disk: set fops.owner from driver module pointer Alvin Sun
2026-08-11 12:20 ` Miguel Ojeda
2026-08-11 13:53   ` Alvin Sun

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox