From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A46921AAE28 for ; Thu, 1 Jan 2026 05:21:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767244890; cv=none; b=ojDCkCzK9yKVYuWGpBbSI1elRi5zNspFk/XmYqde1ZROrZP4dWeix3c6WKnCryXtf8tPTGkJ0/OQtOvDxUFlzj72bkvOhui83Y5P5fQQbHUe8ulLGrB30686lhKZphiM01L/Wdj2e8uwhx0HZnGqKgghZStx5lOLyBagTTlXkLA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767244890; c=relaxed/simple; bh=d750XEbNBh45WZEXvFp98QPRpIEawpP16SYsmo3jXHs=; h=From:Subject:Date:Message-Id:MIME-Version:Content-Type:To:Cc; b=dtPApBxUxu8X/Yy5OWrEO+TZ7qzK6cY+EI3B+5NeQQbeWZhCpNeVzkp1BdTnx7Hy9mznHOi5LQFAcYxsKK5ZmVuXoVWosexK/LyNldHXcE+/ksOS9uBxIZA5FARp1sprBB15YPS7yjXbXfW4WHKHMpPrOtC3OXieJ3oeWCn1/5Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Yd39Agof; arc=none smtp.client-ip=209.85.167.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Yd39Agof" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-595819064cdso17720539e87.0 for ; Wed, 31 Dec 2025 21:21:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767244887; x=1767849687; darn=vger.kernel.org; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:from:to:cc:subject:date:message-id:reply-to; bh=TGdE5vkNreRWa+aNq/2mpC1URjTiZenF177VT5Zv0EE=; b=Yd39AgofIXGH/YdYcExZu7uKRrRNq8Hqb2I73dkxdU35M4sazmWa2nvIdmZSpVxg3v hSOhpca6jmoWep3UMYyzApISgWaeITdkxs1o/KuAzCRmglYxgbpcZpRqSga3xkxGX/NA Vbx89xmWMIpvlkMEc1o4yo5r40TazJaisG+0iHpB/FexoX7l9fTswaxGCSpP7FgwyS2e rOk3GEZJ5PJjSEW97pstIU5Eo9hkk5leIlWf8xpKHi1PAiAYXuW/QGgYKvXCvx9n4XO/ RAA8a7RJweg9lxA/eeFUEnBAIcEkOpLRK9o5lGbMYPc2RCZUcWbCwkH+uWRvInRmRtDd ga0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767244887; x=1767849687; h=cc:to:content-transfer-encoding:mime-version:message-id:date :subject:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=TGdE5vkNreRWa+aNq/2mpC1URjTiZenF177VT5Zv0EE=; b=LKG9X3bZD+wOPAX3gQ20xIw25Q9RXMgSTg84HsQEcnAgHw5PJi6Tj8iy6uUnbx8/rR 2fo5X8j2U6+NPg34bKaeZJxhfWEXm+BkX+KwNLUIb+UXn9fxPEt7qNZpnurp+EjwRC0w qFAYJZdOfhkZ5/rzYFy05SOffDu3af1Oyhl4kTXdfv5aYHaGXWkYqz5Wxo+Ev7YL7Sj9 3ad0xPtMqEuhRa37WWS6kLV43v86+Iz4x9G2iHFZy0/czuVObhRGLnleDGLZb+MeGeFo ivw6RTMDl0CpXC+2/J/9RKZzjp8tW1dhM5KTH8mkskv5b/m0WU1HI4IQQ5jSJFFXGcUE AMfg== X-Forwarded-Encrypted: i=1; AJvYcCX33GS1DAvirsJBweRLM07wORLmnAPy3vJxqyExtceg2IMr7MezDTMriEoaU+9iKaV5FJRl28aEb4iLhK02lw==@vger.kernel.org X-Gm-Message-State: AOJu0Yzo4x00z9J7m8RbiX/upZA/mbixqOZxB6jV6k32ZGzt/K3qpOrW +nyI0h1yBIVwvgaaWm8eyr9m/lx2FJRhmYyb9qveSWgegFvTSgQkvohd X-Gm-Gg: AY/fxX7pzns7q0ZI1pJDR1TAZrUzClBlnMh4V9tvYF01SvuipJOdS7E9S1BR34O972f 8OS0gU+md3DXdX+7JUgNqF3hAeiTHtfoAOkEXjm3gzlePlIQ894JpOwwfAY3t6BSRAzhj9GRbB1 vwUE1pwQVbPWNyBzw/LhtkrthO14nGVj7+7jt4TVApwpzHaIDFB8g6sGg2A/HLjRZpKuHe2Q0Jb /WbW1VIdc4IjHg/r6pVWmHQ9DEpYO1S/pc5oio9i6JwX314wguf+TeuVJ3q7QN643C4jtMsufpl LVJnq0zCW8LaDflUO1oQp2vsNtGv0/5+RmnULgUcR6rGQpxXtar6kUvvXVPZuoWryrFKqIWLE3K +FfLHOna0vEdahZnQojoPCRzAeofDI2k1C0pl0vqzCw+kjJoNKOneU2caTtymW2iD7JdCh/qjN8 pj/TY8hcLc6UMwuxwVU2NrmnAEfAOODOFWoFPxjWwu/0VBygTdeXhPxxBCOyJ/pYbPVI/WJiBNm /mj9Q== X-Google-Smtp-Source: AGHT+IHZriBBr0PXhxXKR/y0BJsmhFkS1LQ/QqrrbeetrOZFLiHUhJOxalDrHlDyEkiA2LnHaYPv7Q== X-Received: by 2002:a05:6512:2399:b0:595:83d5:7b47 with SMTP id 2adb3069b0e04-59a124dcbd8mr14238581e87.5.1767244886425; Wed, 31 Dec 2025 21:21:26 -0800 (PST) Received: from LT-5CG5341NQ4.nordic.imtech.com (84-253-216-54.bb.dnainternet.fi. [84.253.216.54]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-382861ef4ccsm37064921fa.23.2025.12.31.21.21.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Dec 2025 21:21:24 -0800 (PST) From: Kari Argillander Subject: [PATCH RFC 0/6] rust: Reimplement ThisModule to fix ownership problems Date: Thu, 01 Jan 2026 07:20:44 +0200 Message-Id: <20260101-this_module_fix-v1-0-46ae3e5605a0@gmail.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-B4-Tracking: v=1; b=H4sIACwEVmkC/6tWKk4tykwtVrJSqFYqSi3LLM7MzwNyDHUUlJIzE vPSU3UzU4B8JSMDI1NDI2MD3ZKMzOL43PyU0pzU+LTMCt1EY0uDpLQ0IxMLS3MloK6ColSgMNj EaKUgN2el2NpaABg32XxmAAAA X-Change-ID: 20251230-this_module_fix-a390bff24897 To: Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Alexandre Courbot Cc: Greg Kroah-Hartman , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-modules@vger.kernel.org, Luis Chamberlain , Petr Pavlu , Daniel Gomez , Sami Tolvanen , Aaron Tomlin , Jens Axboe , Kari Argillander , Andreas Hindborg X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1767244881; l=5943; i=kari.argillander@gmail.com; s=20251219; h=from:subject:message-id; bh=d750XEbNBh45WZEXvFp98QPRpIEawpP16SYsmo3jXHs=; b=bpVBBl8wPyL5ukIFKh5IWfBK/k3UXg02rMEPOWGVp2PgKPwgwaeWsxbbw/lK9S1rPGw8SYbfJ fw3WuPigsHPCPrzKEmOnjAWzGSkzRhSk2KOUxSLERbRynPypr+VDxbk X-Developer-Key: i=kari.argillander@gmail.com; a=ed25519; pk=RwSxyhTpE3z4sywdDbIkC3q33ZQLNyhYWxT44iTY6r4= This is RFC and just first patch is ready. First I wanna discuss if this is right way to go. I also need to implement this so that build does not break and do better splitting. There is missing signed-off-by's and commit messages so no need to comment those kind of things. Feel free to cc more people if needed. So currently we have problem that we are not always filling .owner field for file_operations. I think we can enable const_refs_to_static already as that is in 1.78 and is stable in 1.83. So that fits perfecly for us. This also seems to be quite request feature but I did not found that no one has ever suggested that we just enable this. So basic idea is that we will have ThisModule trait which is used kernel side. Module side usually just pass this trait forward if needed. Or they can use THIS_MODULE impl which is now completly private impl for each module and kernel create does not see this. So we can think if we wanna pass other module data which have through this. This could also be used to give local module storage without using static. There is also some of github issues for ThisModule handling: > MiscDevice missing module reference counting causes use-after-free crashes [1]. This will be tested and fixed in this series > Ensure ThisModule invariants hold Yeap. Now it would be really hard for kernel create to create this by accident. Binder is still using .as_ptr() but that is easily solvable and after that we can make .as_ptr() private so it will be nice that kernel create can just use .as_ptr() modules can just use. > Add ThisModule::this_module() > > Add a new function ThisModule::this_module() -> &'static ThisModule > that is only available when MODULE is set. It should return a static > reference to bindings::__this_module. [3] I do not this is actually good idea. But here we take little bit different approx so basically this is done also. > Suggested that ThisModule should have name() parameter. [4] And that was good idea. We can remove whole ModuleMetadata and usage is lot nicer. It is also possible that we could have example trait PciModule. which THIS_MODULE impl based on type but that is think for another time. > Initialise the owner field in struct file_operations. [5] Yeap. After this is totally possible to do everywhere. This series will already address most of those. [1]: https://github.com/Rust-for-Linux/linux/issues/1182 [2]: https://github.com/Rust-for-Linux/linux/issues/212 [3]: https://github.com/Rust-for-Linux/linux/issues/1176 [4]: https://github.com/Rust-for-Linux/linux/issues/720 [5]: https://github.com/Rust-for-Linux/linux/issues/720 To: Miguel Ojeda To: Boqun Feng To: Gary Guo To: Björn Roy Baron To: Benno Lossin To: Andreas Hindborg To: Alice Ryhl To: Trevor Gross To: Danilo Krummrich To: Alexandre Courbot Cc: Luis Chamberlain Cc: Petr Pavlu Cc: Daniel Gomez Cc: Sami Tolvanen Cc: Aaron Tomlin Cc: Andreas Hindborg Cc: Jens Axboe Signed-off-by: Kari Argillander --- Kari Argillander (6): rust: Enable const_refs_to_static feature rust: WIP: Introduce ThisModule trait and THIS_MODULE impl rust: WIP: use ThisModule trait for initializing rust: WIP: use ThisModule trait to fix some missing owners rust: debugfs: WIP: Use owner for file_operations rust: WIP: Replace ModuleMetadata with THIS_MODULE drivers/android/binder/rust_binder_main.rs | 4 +- drivers/block/rnull/configfs.rs | 2 +- drivers/block/rnull/rnull.rs | 3 +- drivers/gpu/drm/nova/driver.rs | 1 + drivers/gpu/drm/tyr/driver.rs | 1 + drivers/gpu/nova-core/nova_core.rs | 2 +- lib/find_bit_benchmark_rust.rs | 2 +- rust/kernel/auxiliary.rs | 15 +++--- rust/kernel/block/mq/gen_disk.rs | 31 ++---------- rust/kernel/block/mq/operations.rs | 12 +++++ rust/kernel/configfs.rs | 19 ++++--- rust/kernel/debugfs.rs | 79 ++++++++++++++++-------------- rust/kernel/debugfs/file_ops.rs | 50 ++++++++++++++----- rust/kernel/driver.rs | 19 ++----- rust/kernel/drm/device.rs | 2 +- rust/kernel/drm/driver.rs | 3 ++ rust/kernel/drm/gem/mod.rs | 4 +- rust/kernel/firmware.rs | 2 +- rust/kernel/i2c.rs | 10 ++-- rust/kernel/lib.rs | 78 ++++++++++++++++++----------- rust/kernel/miscdevice.rs | 4 ++ rust/kernel/net/phy.rs | 16 +++--- rust/kernel/pci.rs | 11 ++--- rust/kernel/platform.rs | 11 ++--- rust/kernel/usb.rs | 11 ++--- rust/macros/module.rs | 43 +++++++++------- samples/rust/rust_configfs.rs | 2 +- samples/rust/rust_debugfs.rs | 6 +-- samples/rust/rust_driver_auxiliary.rs | 8 +-- samples/rust/rust_driver_faux.rs | 2 +- samples/rust/rust_minimal.rs | 2 +- samples/rust/rust_misc_device.rs | 3 +- samples/rust/rust_print_main.rs | 2 +- 33 files changed, 245 insertions(+), 215 deletions(-) --- base-commit: cc3aa43b44bdb43dfbac0fcb51c56594a11338a8 change-id: 20251230-this_module_fix-a390bff24897 Best regards, -- Kari Argillander