[PATCH v9 0/8] File abstractions needed by Rust Binder

Alice Ryhl posted 8 patches 1 year, 6 months ago
There is a newer version of this series
fs/file.c                       |   7 +
rust/bindings/bindings_helper.h |   6 +
rust/helpers.c                  |  86 ++++++++
rust/kernel/cred.rs             |  85 ++++++++
rust/kernel/fs.rs               |   8 +
rust/kernel/fs/file.rs          | 461 ++++++++++++++++++++++++++++++++++++++++
rust/kernel/lib.rs              |   3 +
rust/kernel/security.rs         |  74 +++++++
rust/kernel/sync.rs             |   1 +
rust/kernel/sync/lock.rs        |  13 +-
rust/kernel/sync/poll.rs        | 121 +++++++++++
rust/kernel/task.rs             |  91 +++++++-
rust/kernel/types.rs            |  29 +++
13 files changed, 973 insertions(+), 12 deletions(-)
[PATCH v9 0/8] File abstractions needed by Rust Binder
Posted by Alice Ryhl 1 year, 6 months ago
This patchset contains the file abstractions needed by the Rust
implementation of the Binder driver.

Please see the Rust Binder RFC for usage examples:
https://lore.kernel.org/rust-for-linux/20231101-rust-binder-v1-0-08ba9197f637@google.com/

Users of "rust: types: add `NotThreadSafe`":
	[PATCH 5/9] rust: file: add `FileDescriptorReservation`

Users of "rust: task: add `Task::current_raw`":
	[PATCH 7/9] rust: file: add `Kuid` wrapper
	[PATCH 8/9] rust: file: add `DeferredFdCloser`

Users of "rust: file: add Rust abstraction for `struct file`":
	[PATCH RFC 02/20] rust_binder: add binderfs support to Rust binder
	[PATCH RFC 03/20] rust_binder: add threading support

Users of "rust: cred: add Rust abstraction for `struct cred`":
	[PATCH RFC 05/20] rust_binder: add nodes and context managers
	[PATCH RFC 06/20] rust_binder: add oneway transactions
	[PATCH RFC 11/20] rust_binder: send nodes in transaction
	[PATCH RFC 13/20] rust_binder: add BINDER_TYPE_FD support

Users of "rust: security: add abstraction for secctx":
	[PATCH RFC 06/20] rust_binder: add oneway transactions

Users of "rust: file: add `FileDescriptorReservation`":
	[PATCH RFC 13/20] rust_binder: add BINDER_TYPE_FD support
	[PATCH RFC 14/20] rust_binder: add BINDER_TYPE_FDA support

Users of "rust: file: add `Kuid` wrapper":
	[PATCH RFC 05/20] rust_binder: add nodes and context managers
	[PATCH RFC 06/20] rust_binder: add oneway transactions

Users of "rust: file: add abstraction for `poll_table`":
	[PATCH RFC 07/20] rust_binder: add epoll support

This patchset has some uses of read_volatile in place of READ_ONCE.
Please see the following rfc for context on this:
https://lore.kernel.org/all/20231025195339.1431894-1-boqun.feng@gmail.com/

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
Changes in v9:
- Rebase on top of v6.11-rc2.
- Reorder things in file.rs
- Fix minor typo in file.rs
- Add Reviewed-bys.
- Link to v8: https://lore.kernel.org/r/20240725-alice-file-v8-0-55a2e80deaa8@google.com

Changes in v8:
- Rename File::from_ptr to File::from_raw_file.
- Mention that NotThreadSafe also affects Sync.
- Fix copyright lines.
- Move rust/kernel/file.rs to rust/kernel/fs/file.rs to reduce conflicts
  with Wedson's vfs patches.
- Link to v7: https://lore.kernel.org/r/20240628-alice-file-v7-0-4d701f6335f3@google.com

Changes in v7:
- Replace file sharing modes with File / LocalFile.
- Link to v6: https://lore.kernel.org/r/20240517-alice-file-v6-0-b25bafdc9b97@google.com

Changes in v6:
- Introduce file sharing modes.
- Rewrite most documentation for `struct file` wrapper.
- Drop `DeferredFdCloser`. It will be sent later when it can be placed
  somewhere where only Rust Binder can use it.
- Rebase on top of rust-next: 97ab3e8eec0c ("rust: alloc: fix dangling pointer in VecExt<T>::reserve()")
- Link to v5: https://lore.kernel.org/r/20240209-alice-file-v5-0-a37886783025@google.com

Changes in v5:
- Pass a null pointer to task_tgid_nr_ns.
- Fix some typos and other formatting issues.
- Add Reviewed-by where appropriate.
- Link to v4: https://lore.kernel.org/r/20240202-alice-file-v4-0-fc9c2080663b@google.com

Changes in v4:
- Moved the two really simple patches to the beginning of the patchset.
- Update Send safety comments.
- Use srctree relative links.
- Mention that `Credential::euid` is immutable.
- Update some safety comments to mention the invariant on Self.
- Use new name for close_fd_get_file.
- Move safety comments on DeferredFdCloser around and be more explicit
  about how many refcounts we own.
- Reword safety comments related to _qproc.
- Add Reviewed-by where appropriate.
- Link to v3: https://lore.kernel.org/r/20240118-alice-file-v3-0-9694b6f9580c@google.com

Changes in v3:
- Completely rewrite comments about refcounting in the first patch.
  - And add a note to the documentation in fs/file.c.
- Discuss speculation gadgets in commit message for the Kuid wrapper.
- Introduce NotThreadSafe and Task::current_raw patches and use them in
  later patches.
- Improve safety comments in DeferredFdCloser.
- Some other minor changes.
- Link to v2: https://lore.kernel.org/r/20231206-alice-file-v2-0-af617c0d9d94@google.com

Changes in v2:
- Update various docs and safety comments.
- Rename method names to match the C name.
- Use ordinary read instead of READ_ONCE in File::cred.
- Changed null check in secctx.
- Add type alias for PhantomData in FileDescriptorReservation.
- Use Kuid::from_raw in Kuid::current_euid.
- Make DeferredFdCloser fallible if it is unable to schedule a task
  work. And also schedule the task work *before* closing the file.
- Moved PollCondVar to rust/kernel/sync.
- Updated PollCondVar to use wake_up_pollfree.
- Link to v1: https://lore.kernel.org/all/20231129-alice-file-v1-0-f81afe8c7261@google.com/

Link to RFC:
https://lore.kernel.org/all/20230720152820.3566078-1-aliceryhl@google.com/

---
Alice Ryhl (5):
      rust: types: add `NotThreadSafe`
      rust: task: add `Task::current_raw`
      rust: security: add abstraction for secctx
      rust: file: add `Kuid` wrapper
      rust: file: add abstraction for `poll_table`

Wedson Almeida Filho (3):
      rust: file: add Rust abstraction for `struct file`
      rust: cred: add Rust abstraction for `struct cred`
      rust: file: add `FileDescriptorReservation`

 fs/file.c                       |   7 +
 rust/bindings/bindings_helper.h |   6 +
 rust/helpers.c                  |  86 ++++++++
 rust/kernel/cred.rs             |  85 ++++++++
 rust/kernel/fs.rs               |   8 +
 rust/kernel/fs/file.rs          | 461 ++++++++++++++++++++++++++++++++++++++++
 rust/kernel/lib.rs              |   3 +
 rust/kernel/security.rs         |  74 +++++++
 rust/kernel/sync.rs             |   1 +
 rust/kernel/sync/lock.rs        |  13 +-
 rust/kernel/sync/poll.rs        | 121 +++++++++++
 rust/kernel/task.rs             |  91 +++++++-
 rust/kernel/types.rs            |  29 +++
 13 files changed, 973 insertions(+), 12 deletions(-)
---
base-commit: de9c2c66ad8e787abec7c9d7eff4f8c3cdd28aed
change-id: 20231123-alice-file-525b98e8a724

Best regards,
-- 
Alice Ryhl <aliceryhl@google.com>
Re: [PATCH v9 0/8] File abstractions needed by Rust Binder
Posted by Christian Brauner 1 year, 5 months ago
On Thu, 08 Aug 2024 16:15:43 +0000, Alice Ryhl wrote:
> This patchset contains the file abstractions needed by the Rust
> implementation of the Binder driver.
> 
> Please see the Rust Binder RFC for usage examples:
> https://lore.kernel.org/rust-for-linux/20231101-rust-binder-v1-0-08ba9197f637@google.com/
> 
> Users of "rust: types: add `NotThreadSafe`":
> 	[PATCH 5/9] rust: file: add `FileDescriptorReservation`
> 
> [...]

Moving this to vfs.rust.file. This won't show up in -next for quite a while
(until v6.12-rc1 is out).

---

Applied to the vfs.rust.file branch of the vfs/vfs.git tree.
Patches in the vfs.rust.file branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.rust.file

[1/8] rust: types: add `NotThreadSafe`
      https://git.kernel.org/vfs/vfs/c/1fc5fbeff010
[2/8] rust: task: add `Task::current_raw`
      https://git.kernel.org/vfs/vfs/c/dff63ff65920
[3/8] rust: file: add Rust abstraction for `struct file`
      https://git.kernel.org/vfs/vfs/c/3d52041c524e
[4/8] rust: cred: add Rust abstraction for `struct cred`
      https://git.kernel.org/vfs/vfs/c/bd5715551277
[5/8] rust: security: add abstraction for secctx
      https://git.kernel.org/vfs/vfs/c/b94bf604a856
[6/8] rust: file: add `FileDescriptorReservation`
      https://git.kernel.org/vfs/vfs/c/b7af88a7d25d
[7/8] rust: file: add `Kuid` wrapper
      https://git.kernel.org/vfs/vfs/c/73cd06e92529
[8/8] rust: file: add abstraction for `poll_table`
      https://git.kernel.org/vfs/vfs/c/891ad53c3c62
Re: [PATCH v9 0/8] File abstractions needed by Rust Binder
Posted by Christian Brauner 1 year, 5 months ago
On Thu, Aug 08, 2024 at 04:15:43PM GMT, Alice Ryhl wrote:
> This patchset contains the file abstractions needed by the Rust
> implementation of the Binder driver.
> 
> Please see the Rust Binder RFC for usage examples:
> https://lore.kernel.org/rust-for-linux/20231101-rust-binder-v1-0-08ba9197f637@google.com/
> 
> Users of "rust: types: add `NotThreadSafe`":
> 	[PATCH 5/9] rust: file: add `FileDescriptorReservation`
> 
> Users of "rust: task: add `Task::current_raw`":
> 	[PATCH 7/9] rust: file: add `Kuid` wrapper
> 	[PATCH 8/9] rust: file: add `DeferredFdCloser`
> 
> Users of "rust: file: add Rust abstraction for `struct file`":
> 	[PATCH RFC 02/20] rust_binder: add binderfs support to Rust binder
> 	[PATCH RFC 03/20] rust_binder: add threading support
> 
> Users of "rust: cred: add Rust abstraction for `struct cred`":
> 	[PATCH RFC 05/20] rust_binder: add nodes and context managers
> 	[PATCH RFC 06/20] rust_binder: add oneway transactions
> 	[PATCH RFC 11/20] rust_binder: send nodes in transaction
> 	[PATCH RFC 13/20] rust_binder: add BINDER_TYPE_FD support
> 
> Users of "rust: security: add abstraction for secctx":
> 	[PATCH RFC 06/20] rust_binder: add oneway transactions
> 
> Users of "rust: file: add `FileDescriptorReservation`":
> 	[PATCH RFC 13/20] rust_binder: add BINDER_TYPE_FD support
> 	[PATCH RFC 14/20] rust_binder: add BINDER_TYPE_FDA support
> 
> Users of "rust: file: add `Kuid` wrapper":
> 	[PATCH RFC 05/20] rust_binder: add nodes and context managers
> 	[PATCH RFC 06/20] rust_binder: add oneway transactions
> 
> Users of "rust: file: add abstraction for `poll_table`":
> 	[PATCH RFC 07/20] rust_binder: add epoll support
> 
> This patchset has some uses of read_volatile in place of READ_ONCE.
> Please see the following rfc for context on this:
> https://lore.kernel.org/all/20231025195339.1431894-1-boqun.feng@gmail.com/
> 
> Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> ---

So, this won't make v6.12 anymore. There already were pretty big changes
around files for the coming cycle so I did not also want to throw this
into the mix as well. (Sorry that this had to miss it's birthday, Alice.)

However, I do intend to merge a version for this for v6.13. There's some
wrapping of struct cred and specifically of struct secctx that I can
only handwave at. Ideally you get a nod from the LSM maintainers as well
but if that doesn't come in I don't see much point in making this sit in
limbo indefinitely.
Re: [PATCH v9 0/8] File abstractions needed by Rust Binder
Posted by Alice Ryhl 1 year, 5 months ago
On Mon, Sep 2, 2024 at 10:02 AM Christian Brauner <brauner@kernel.org> wrote:
>
> On Thu, Aug 08, 2024 at 04:15:43PM GMT, Alice Ryhl wrote:
> > This patchset contains the file abstractions needed by the Rust
> > implementation of the Binder driver.
> >
> > Please see the Rust Binder RFC for usage examples:
> > https://lore.kernel.org/rust-for-linux/20231101-rust-binder-v1-0-08ba9197f637@google.com/
> >
> > Users of "rust: types: add `NotThreadSafe`":
> >       [PATCH 5/9] rust: file: add `FileDescriptorReservation`
> >
> > Users of "rust: task: add `Task::current_raw`":
> >       [PATCH 7/9] rust: file: add `Kuid` wrapper
> >       [PATCH 8/9] rust: file: add `DeferredFdCloser`
> >
> > Users of "rust: file: add Rust abstraction for `struct file`":
> >       [PATCH RFC 02/20] rust_binder: add binderfs support to Rust binder
> >       [PATCH RFC 03/20] rust_binder: add threading support
> >
> > Users of "rust: cred: add Rust abstraction for `struct cred`":
> >       [PATCH RFC 05/20] rust_binder: add nodes and context managers
> >       [PATCH RFC 06/20] rust_binder: add oneway transactions
> >       [PATCH RFC 11/20] rust_binder: send nodes in transaction
> >       [PATCH RFC 13/20] rust_binder: add BINDER_TYPE_FD support
> >
> > Users of "rust: security: add abstraction for secctx":
> >       [PATCH RFC 06/20] rust_binder: add oneway transactions
> >
> > Users of "rust: file: add `FileDescriptorReservation`":
> >       [PATCH RFC 13/20] rust_binder: add BINDER_TYPE_FD support
> >       [PATCH RFC 14/20] rust_binder: add BINDER_TYPE_FDA support
> >
> > Users of "rust: file: add `Kuid` wrapper":
> >       [PATCH RFC 05/20] rust_binder: add nodes and context managers
> >       [PATCH RFC 06/20] rust_binder: add oneway transactions
> >
> > Users of "rust: file: add abstraction for `poll_table`":
> >       [PATCH RFC 07/20] rust_binder: add epoll support
> >
> > This patchset has some uses of read_volatile in place of READ_ONCE.
> > Please see the following rfc for context on this:
> > https://lore.kernel.org/all/20231025195339.1431894-1-boqun.feng@gmail.com/
> >
> > Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> > ---
>
> So, this won't make v6.12 anymore. There already were pretty big changes
> around files for the coming cycle so I did not also want to throw this
> into the mix as well. (Sorry that this had to miss it's birthday, Alice.)

This has also gained a conflict with the helpers split [1] in
rust-next, so maybe that is for the best.

I will look into whether any other changes are needed given what is
going in for 6.12 and send a new version. It looks like you already
added it to an vfs.rust.file branch, and it doesn't look like anything
in vfs.file required changes in this series.

[1]: https://lore.kernel.org/r/20240815103016.2771842-1-nmi@metaspace.dk

> However, I do intend to merge a version for this for v6.13. There's some
> wrapping of struct cred and specifically of struct secctx that I can
> only handwave at. Ideally you get a nod from the LSM maintainers as well
> but if that doesn't come in I don't see much point in making this sit in
> limbo indefinitely.

Okay thanks! I can look into that.

Alice