All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/4] rust: Add safe pointer formatting support
@ 2025-12-26 14:07 Ke Sun
  2025-12-26 14:07 ` [PATCH v5 1/4] lib/vsprintf: Export ptr_to_hashval for Rust use Ke Sun
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Ke Sun @ 2025-12-26 14:07 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.

---
v5:
- 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                        | 240 +++++++++++++++++++++-
 7 files changed, 475 insertions(+), 5 deletions(-)
 create mode 100644 Documentation/rust/pointer-formatting.rst
 create mode 100644 rust/helpers/fmt.c

-- 
2.43.0


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

end of thread, other threads:[~2025-12-27  2:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-26 14:07 [PATCH v5 0/4] rust: Add safe pointer formatting support Ke Sun
2025-12-26 14:07 ` [PATCH v5 1/4] lib/vsprintf: Export ptr_to_hashval for Rust use Ke Sun
2025-12-26 14:07 ` [PATCH v5 2/4] rust: kernel: Add pointer wrapper types for safe pointer formatting Ke Sun
2025-12-26 15:10   ` Dirk Behme
2025-12-27  2:02     ` Ke Sun
2025-12-26 14:07 ` [PATCH v5 3/4] rust: fmt: Default raw pointer formatting to HashedPtr Ke Sun
2025-12-26 14:07 ` [PATCH v5 4/4] docs: rust: Add pointer formatting documentation Ke Sun

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.