public inbox for rust-for-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 0/4] rust: Add safe pointer formatting support
@ 2025-12-27  3:39 Ke Sun
  2025-12-27  3:39 ` [PATCH v6 1/4] lib/vsprintf: Export ptr_to_hashval for Rust use Ke Sun
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Ke Sun @ 2025-12-27  3:39 UTC (permalink / raw)
  To: Dirk Behme, Miguel Ojeda, Petr Mladek, Steven Rostedt, Timur Tabi,
	Danilo Krummrich, Benno Lossin
  Cc: Boqun Feng, Gary Guo, Björn Roy Baron, Andreas Hindborg,
	Alice Ryhl, Trevor Gross, Tamir Duberstein, Ke Sun,
	rust-for-linux, Ke Sun

This patch series adds safe pointer formatting support for Rust kernel code,
providing three pointer wrapper types (HashedPtr, RawPtr, RestrictedPtr) that
correspond to C kernel's printk format specifiers %p, %px, and %pK.

The implementation ensures that raw pointers are automatically hashed when
formatted with {:p}, providing safe default behavior that prevents information
leaks about kernel memory layout. Users can also explicitly use wrapper types
when they need specific formatting behavior.

---
v6:
- Fix placeholder formatting to use `f.pad()` instead of `f.write_str()` in
  format_hashed_ptr(), ensuring width, alignment, and padding options are
  correctly applied to PTR_PLACEHOLDER

v5: https://lore.kernel.org/rust-for-linux/20251226140751.2215563-1-sunke@kylinos.cn/
- Format use statements in rust/kernel/ptr.rs and rust/kernel/fmt.rs using kernel
  vertical style with alphabetical ordering
- Remove unnecessary SAFETY comment in rust/kernel/ptr.rs (addressed Clippy warning)
- Update type ordering to alphabetical (HashedPtr, RawPtr, RestrictedPtr) in
  fmt.rs macro invocation

v4: https://lore.kernel.org/rust-for-linux/20251225225709.3944255-1-sunke@kylinos.cn/
- Use Pointer::fmt() instead of write!(f, "{:p}", ...) to preserve formatting
  options (width, alignment, padding characters)
- Improve code structure: reduce unsafe block scope, use early return pattern
- Add doctests with formatting option tests for all pointer wrapper types
- Enhance documentation with detailed formatting options section, including
  examples for width, alignment, and padding
- Fix RestrictedPtr example to use pr_info! instead of seq_print! in docs

v3: https://lore.kernel.org/rust-for-linux/20251224081315.729684-1-sunke@kylinos.cn/
- Export ptr_to_hashval() from lib/vsprintf.c for Rust pointer hashing
- Add three pointer wrapper types (HashedPtr, RestrictedPtr, RawPtr) in
  rust/kernel/ptr.rs corresponding to %p, %pK, and %px
- Make raw pointers automatically use HashedPtr when formatted with {:p}
- Add documentation for pointer wrapper types

v2: https://lore.kernel.org/rust-for-linux/20251223033018.2814732-1-sunke@kylinos.cn/
- Disabled {:p} raw pointer printing by default to prevent accidental
  information leaks

v1: https://lore.kernel.org/rust-for-linux/20251218032709.2184890-1-sunke@kylinos.cn/
- Initial implementation that directly printed raw pointers
---

Ke Sun (4):
  lib/vsprintf: Export ptr_to_hashval for Rust use
  rust: kernel: Add pointer wrapper types for safe pointer formatting
  rust: fmt: Default raw pointer formatting to HashedPtr
  docs: rust: Add pointer formatting documentation

 Documentation/rust/index.rst              |   1 +
 Documentation/rust/pointer-formatting.rst | 101 +++++++++
 lib/vsprintf.c                            |   1 +
 rust/helpers/fmt.c                        |  65 ++++++
 rust/helpers/helpers.c                    |   3 +-
 rust/kernel/fmt.rs                        |  69 ++++++-
 rust/kernel/ptr.rs                        | 241 +++++++++++++++++++++-
 7 files changed, 476 insertions(+), 5 deletions(-)
 create mode 100644 Documentation/rust/pointer-formatting.rst
 create mode 100644 rust/helpers/fmt.c

base-commit: 9448598b22c50c8a5bb77a9103e2d49f134c9578
-- 
2.43.0


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

end of thread, other threads:[~2025-12-29  7:38 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-27  3:39 [PATCH v6 0/4] rust: Add safe pointer formatting support Ke Sun
2025-12-27  3:39 ` [PATCH v6 1/4] lib/vsprintf: Export ptr_to_hashval for Rust use Ke Sun
2025-12-27  3:39 ` [PATCH v6 2/4] rust: kernel: Add pointer wrapper types for safe pointer formatting Ke Sun
2025-12-27  5:56   ` Boqun Feng
2025-12-29  7:38     ` Ke Sun
2025-12-29  6:44   ` Dirk Behme
2025-12-29  7:34     ` Ke Sun
2025-12-27  3:39 ` [PATCH v6 3/4] rust: fmt: Default raw pointer formatting to HashedPtr Ke Sun
2025-12-27  3:39 ` [PATCH v6 4/4] docs: rust: Add pointer formatting documentation Ke Sun
2025-12-27  9:12 ` [PATCH v6 0/4] rust: Add safe pointer formatting support Dirk Behme

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