rust: revocable: Documentation, refactoring and safety refinements
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v8 Latest3 patches 3 repliesIn review
- v73 patches 7 repliesSuperseded
- v63 patches 8 repliesSuperseded
Earlier versions · 3
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v5 | 2 patches | 7 replies | Superseded | |
| v4 | 3 patches | 23 replies | Superseded | |
| v1 | 3 patches | 1 reply | Superseded |
Changes in v8 from the cover letter
- Patch 3 (rust: revocable: Documents RevocableGuard invariants/safety and refine Deref safety) was refined:
- The SAFETY comment in Revocable::try_access was updated, now clearly stating how Self's type invariants and the RCU read-side lock together ensure self.data's validity for reads.
- The redundant line about the RCU read-side lock in RevocableGuard::new's # Safety doc comment was removed.
Patches in v8 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | rust: revocable: Clarify write invariant and update safety commentsrust/ | +15 | 0 replies | |
| 2/3 | rust: revocable: Refactor revocation mechanism to remove generic revoke_internalrust/ | +21 | 0 replies | |
| 3/3 | rust: revocable: Documents RevocableGuard invariants/safety and refine Deref safetyrust/ | +13 | 2 replies |
Reviews trailers per patch
All 3 patches have a Reviewed-by or Acked-by.
| Patch | Benno Lossin | Danilo Krummrich |
|---|---|---|
| 1/3 | R-b | R-b |
| 2/3 | R-b | |
| 3/3 | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v8 0/3] rust: revocable: Documentation, refactoring and safety refinements
This patch series brings documentation and safety refinements to the Revocable type, addressing recent feedback and improving clarity of unsafe operations.
Changes include:
- Clarifying the write invariant and updating associated safety comments for Revocable<T>.
- Splitting the internal revoke_internal function into two distinct functions:
revoke() (safe, synchronizing with RCU) and revoke_nosync() (unsafe, without RCU synchronization), now returning bool to indicate revocation status.
- Documenting RevocableGuard's pointer validity invariants, making its constructor unsafe, and refining its Deref and try_access safety comments.
---
Changelog:
Changes since v7:
- Patch 3 (rust: revocable: Documents RevocableGuard invariants/safety and refine Deref safety) was refined:
- The SAFETY comment in Revocable::try_access was updated, now clearly stating how Self's type invariants and the RCU read-side lock together ensure self.data's validity for reads.
- The redundant line about the RCU read-side lock in RevocableGuard::new's # Safety doc comment was removed.
Link to v7: https://lore.kernel.org/rust-for-linux/[email protected]/T/#t
Changes since v6:
- Patch 3 (rust: revocable: Document RevocableGuard invariants/safety and refine Deref safety) was refined:
- RevocableGuard's invariants were updated to state that data_ref is valid as long as the RCU read-side lock is held, and the redundant RCU invariant was removed.
- The RevocableGuard::new constructor was made unsafe, and a # Safety comment was added specifying caller responsibilities.
- The comment in Revocable::try_access was changed to a SAFETY block, justifying the unsafe call to RevocableGuard::new by Self's type invariants (is_available being true) and the active RCU read-side lock.
- The Deref implementation's SAFETY comment was refined.
Link to v6: https://lore.kernel.org/rust-for-linux/[email protected]/T/#t
Changes since v5:
- Reordered the patch series to apply documentation fixes before the refactoring, as suggested by Benno. The new order is:
1. rust: revocable: Clarify write invariant and update safety comments
2. rust: revocable: Refactor revocation mechanism to remove generic revoke_internal
3. rust: revocable: Document RevocableGuard invariants and refine Deref safety
- Added a new patch, "rust: revocable: Document RevocableGuard invariants and refine Deref safety", which explicitly documents the validity invariant for RevocableGuard's data_ref member and refines the associated Deref SAFETY comment, addressing specific maintainer feedback.
- Updated the SAFETY comment in Deref implementation of RevocableGuard to match common kernel patterns.
Link to v5: https://lore.kernel.org/rust-for-linux/[email protected]/T/#t
Changes since v4:
- Rebased the series onto the latest rfl/rust-next to integrate recent changes, specifically the bool return for revoke() and revoke_nosync().
- Dropped the "rust: revocable: simplify RevocableGuard for internal safety" patch, as the approach of using a direct reference (&'a T) for RevocableGuard was found to be unsound due to Rust's aliasing rules and LLVM's dereferencable attribute guarantees, which require references to remain valid for the entire function call duration, even if the internal RCU guard is dropped earlier.
- Refined the PinnedDrop::drop SAFETY comment based on Benno's and Miguel's feedback, adopting a more concise and standard Kernel-style bullet point format.
Link to v4: https://lore.kernel.org/rust-for-linux/[email protected]/T/#u
Changes since v3:
- Refined the wording of the Revocable<T> invariants to be more
precise about read and write validity conditions, specifically including
RCU read-side lock acquisition timing for reads and RCU grace period
for writes.
- Simplified the try_access_with_guard safety comment for better conciseness.
- Refactored RevocableGuard to use &'a T instead of *const T, removing its internal invariants and unsafe blocks.
- Simplified Revocable::try_access to leverage try_access_with_guard and map.
- Split revoke_internal into revoke() and revoke_nosync() functions, making synchronization behavior explicit.
Link to v3: https://lore.kernel.org/rust-for-linux/CAPZ3m_hTr7BN=zy10m8kWchYiJ04MXKuJAp9wt67Krqw6wH-JQ@mail.gmail.com/
Changes in v2:
- Refined the wording of the Revocable<T> invariants to be
more direct and address feedback regarding the phrase 'must occur'.
- Added '// INVARIANT:' comments in try_access and try_access_with_guard as suggested by reviewers.
- Added the missing invariant for RevocableGuard<'_, T> regarding the validity of data_ref.
- Updated the safety comment in the Deref implementation of RevocableGuard to refer to the new invariant.
Marcelo Moreira (3):
rust: revocable: Clarify write invariant and update safety comments
rust: revocable: Refactor revocation mechanism to remove generic
revoke_internal
rust: revocable: Document RevocableGuard invariants/safety and refine Deref
safety
rust/kernel/revocable.rs | 88 +++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------
1 file changed, 49 insertions(+), 39 deletions(-)