public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/6] soc: qcom: socinfo: Convert to Rust
@ 2026-02-03 15:46 Matthew Maurer
  2026-02-03 15:46 ` [PATCH v2 1/6] rust: Add sparse_array! helper macro Matthew Maurer
                   ` (5 more replies)
  0 siblings, 6 replies; 32+ messages in thread
From: Matthew Maurer @ 2026-02-03 15:46 UTC (permalink / raw)
  To: Bjorn Andersson, Konrad Dybcio, Satya Durga Srinivasu Prabhala,
	Miguel Ojeda, Boqun Feng, Gary Guo, Björn Roy Baron,
	Benno Lossin, Andreas Hindborg, Alice Ryhl, Trevor Gross,
	Danilo Krummrich, Daniel Almeida, Greg Kroah-Hartman,
	Rafael J. Wysocki, David Airlie, Simona Vetter, Michal Wilczynski,
	Dave Ertman, Ira Weiny, Leon Romanovsky
  Cc: Trilok Soni, linux-kernel, linux-arm-msm, rust-for-linux,
	driver-core, dri-devel, linux-pwm, Matthew Maurer

This series converts the Qualcomm Socinfo driver to Rust to improve its
robustness.

The previous driver suffered from CVE-2024-58007, which would have been
prevented by the enforced bounds-checking present in Rust.

It's taken a while to get all the interfaces in place, but at this
point, the only place it needs `unsafe` is to define an abstraction
over the qcom-smem driver.

Feedback on v1 of the patch showed how Rust can help to identify
assumptions being made about APIs by requiring that reasoning be
attached to `unsafe` blocks. Specifically, this identified:

1. The regions being returned by `qcom_smem_get` are not memory regions,
   they are IO mapped memory.
2. These regions will be unmapped if the `smem` device is unloaded.
3. For versions in particular, the behavior of re-reading the version
   info from the IO region when displaying outputs is load-bearing, not
   an implementation detail - these regions are *expected* to change.

The previous driver accessed IO mapped regions through regular C memory
accesses. This was possible without warning because the `qcom_smem_get` 
API exposes pointers stripped of their `__iomem` annotation. This is
unlikely to cause trouble in practice, but goes against the
recommendation of kernel documentation [1].

The previous driver did not have a direct mechanism to ensure it was
being probed as a child of a `qcom-smem` device. While it was only ever
probed correctly (from the `qcom-smem` device), the new implementation
is robust to being probed improperly by other devices.

Since we are now using the IO subsystem, it's now much clearer when we
are intentionally choosing to do an IO read during a DebugFS
implementation.

I have tested this on a SM8650-HDK by diffing the contents of the
exported DebugFS and examining the files under /sys/bus/soc/devices/soc0

While I believe I have everything correctly exported via DebugFS, I have
not checked equivalence across a large swath of devices, only the one.

This driver is currently quirk-compatible in DebugFS-exported values. If
the maintainers do not believe that maintaining the exact formats is a
benefit, we could simplify the code further by dropping some of the
custom formatting functions used to match the output.

I didn't touch MAINTAINERS because the existing socinfo.c is covered by
a blanket directory maintainer, which would automatically cover the new
Rust implementation. If it would be helpful, I would be willing to
assist with this particular driver in the future.

Since it was a surprise in the previous series, I will explicitly call
out that this series is built on driver-core-next plus my patches to
load randomness [2] and derive FromBytes / AsBytes [3]. If you use b4,
this series should have appropriate metadata to recreate the tree for
you.

[1]: https://docs.kernel.org/driver-api/device-io.html#accessing-the-device
[2]: https://lore.kernel.org/all/20260102-add-entropy-v5-1-6b38a7a4a9ee@google.com/
[3]: https://lore.kernel.org/all/20251226-transmute-v3-0-c69a81bf8621@google.com/

Signed-off-by: Matthew Maurer <mmaurer@google.com>
---
Changes in v2:
- Rebase onto updated deps
- Use sparse_array! macro to define PMIC_MODELS
- Migrate to using auxdev
- Add `qcom_smem_get_aux` to help enforce that we are a child device
- Access IO mapped regions through the IO subsystem
- Leverage `Devres` to ensure that the smem device is still present when
  accessing IO regions.
- Switch to new kernel import style
- Switch to c"foo" literals where possible
- Link to v1: https://lore.kernel.org/r/20251213-qcom-socinfo-v1-1-5daa7f5f2a85@google.com

---
Matthew Maurer (6):
      rust: Add sparse_array! helper macro
      rust: io: Support copying arrays and slices
      rust: device: Support testing devices for equality
      rust: auxiliary: Support accessing raw aux pointer
      rust: debugfs: Allow access to device in Devres-wrapped scopes
      soc: qcom: socinfo: Convert to Rust

 drivers/soc/qcom/Kconfig             |   1 +
 drivers/soc/qcom/Makefile            |   2 +-
 drivers/soc/qcom/smem.c              |  42 +-
 drivers/soc/qcom/socinfo.c           | 931 -----------------------------------
 drivers/soc/qcom/socinfo/Makefile    |   2 +
 drivers/soc/qcom/socinfo/bindings.rs | 123 +++++
 drivers/soc/qcom/socinfo/data.rs     | 438 ++++++++++++++++
 drivers/soc/qcom/socinfo/socinfo.rs  | 446 +++++++++++++++++
 include/linux/soc/qcom/smem.h        |   4 +
 rust/bindgen_parameters              |   1 +
 rust/bindings/bindings_helper.h      |   6 +
 rust/kernel/auxiliary.rs             |   6 +-
 rust/kernel/debugfs.rs               |  40 ++
 rust/kernel/device.rs                |   8 +
 rust/kernel/devres.rs                |   2 +-
 rust/kernel/drm/driver.rs            |   2 +-
 rust/kernel/io.rs                    |  72 ++-
 rust/kernel/pwm.rs                   |   2 +-
 rust/kernel/slice.rs                 |  37 ++
 19 files changed, 1220 insertions(+), 945 deletions(-)
---
base-commit: 559ac491542c00e2389f8cfc49661527b3b0d8a0
change-id: 20251029-qcom-socinfo-d8387c7fdb1c
prerequisite-change-id: 20251029-add-entropy-f57e12ebe110:v5
prerequisite-patch-id: f1e8f8f557aa3df7510bd90beb1edf62faa117da
prerequisite-change-id: 20251212-transmute-8ab6076700a8:v3
prerequisite-patch-id: 4f5f7cb002d02d232083ab5c3ce6b3cb90650bd6
prerequisite-patch-id: fcdcb6cfedd70cdc41d2d27244ea2a588ed40eb9
prerequisite-patch-id: f6bc9ae84b31e2400749c0db10e6aa4216b3858b
prerequisite-patch-id: 95a7f946b6533ec4ccafee355626bb24a9be8f70

Best regards,
-- 
Matthew Maurer <mmaurer@google.com>


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

end of thread, other threads:[~2026-02-04  8:40 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-03 15:46 [PATCH v2 0/6] soc: qcom: socinfo: Convert to Rust Matthew Maurer
2026-02-03 15:46 ` [PATCH v2 1/6] rust: Add sparse_array! helper macro Matthew Maurer
2026-02-03 15:46 ` [PATCH v2 2/6] rust: io: Support copying arrays and slices Matthew Maurer
2026-02-03 15:53   ` Danilo Krummrich
2026-02-03 15:46 ` [PATCH v2 3/6] rust: device: Support testing devices for equality Matthew Maurer
2026-02-03 15:56   ` Danilo Krummrich
2026-02-03 16:05   ` Gary Guo
2026-02-03 16:15   ` Greg Kroah-Hartman
2026-02-03 16:17   ` Greg Kroah-Hartman
2026-02-03 16:29     ` Danilo Krummrich
2026-02-03 16:40       ` Greg Kroah-Hartman
2026-02-03 16:46         ` Danilo Krummrich
2026-02-03 17:17           ` Matthew Maurer
2026-02-03 15:46 ` [PATCH v2 4/6] rust: auxiliary: Support accessing raw aux pointer Matthew Maurer
2026-02-03 15:55   ` Danilo Krummrich
2026-02-03 15:46 ` [PATCH v2 5/6] rust: debugfs: Allow access to device in Devres-wrapped scopes Matthew Maurer
2026-02-03 15:59   ` Danilo Krummrich
2026-02-03 16:47   ` Gary Guo
2026-02-03 16:58     ` Danilo Krummrich
2026-02-03 18:04     ` Matthew Maurer
2026-02-03 15:46 ` [PATCH v2 6/6] soc: qcom: socinfo: Convert to Rust Matthew Maurer
2026-02-03 16:28   ` Greg Kroah-Hartman
2026-02-03 16:35     ` Danilo Krummrich
2026-02-03 16:48       ` Greg Kroah-Hartman
2026-02-03 16:56         ` Danilo Krummrich
2026-02-03 17:17           ` Gary Guo
2026-02-03 17:26             ` Matthew Maurer
2026-02-03 17:59             ` Danilo Krummrich
2026-02-03 17:37     ` Matthew Maurer
2026-02-04  8:38       ` Greg Kroah-Hartman
2026-02-03 20:27   ` Bjorn Andersson
2026-02-04  8:40     ` Greg Kroah-Hartman

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