[PATCH v3 0/4] rust: alloc: split `Vec::set_len` into `Vec::{inc,dec}_len`

Tamir Duberstein posted 4 patches 10 months ago
There is a newer version of this series
rust/kernel/alloc/kvec.rs | 85 +++++++++++++++++++++++++++--------------------
rust/kernel/str.rs        |  2 +-
rust/kernel/uaccess.rs    |  2 +-
3 files changed, 51 insertions(+), 38 deletions(-)
[PATCH v3 0/4] rust: alloc: split `Vec::set_len` into `Vec::{inc,dec}_len`
Posted by Tamir Duberstein 10 months ago
This series is the product of a discussion[0] on the safety requirements
of `set_len`.

Link: https://lore.kernel.org/all/20250315154436.65065-1-dakr@kernel.org/ [0]
Link: https://lore.kernel.org/all/20250316111644.154602-2-andrewjballance@gmail.com/ [1]
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
---
Changes in v3:
- Fix compilation (s/ptr/tail/) in "refactor `Vec::truncate` using
  `dec_len`".
- Fix grammar and s/alloc/realloc/ in a safety comment touched by "rust:
  alloc: add Vec::len() <= Vec::capacity invariant".
- Use `if let`. (Alice Ryhl).
- Avoid mutable reference after `drop_in_place`. (Alice Ryhl).
- Rebase on rust/alloc-next.
- Remove dependency on the `Vec::truncate` series which has been merged.
- Link to v2: https://lore.kernel.org/r/20250318-vec-set-len-v2-0-293d55f82d18@gmail.com

Changes in v2:
- Avoid overflow in `set_len`. (Benno Lossin)
- Explained `CString::try_from_fmt` usage of `set_len`. (Benno Lossin,
  Miguel Ojeda, Alice Ryhl)
- Added missing SoB. (Alice Ryhl)
- Prepend a patch documenting `Vec::len() <= Vec::capacity()` invariant.
- Add a patch rewriting `Vec::truncate` in terms of `Vec::dec_len`.
- Link to v1: https://lore.kernel.org/r/20250316-vec-set-len-v1-0-60f98a28723f@gmail.com

---
Tamir Duberstein (4):
      rust: alloc: add Vec::len() <= Vec::capacity invariant
      rust: alloc: add `Vec::dec_len`
      rust: alloc: refactor `Vec::truncate` using `dec_len`
      rust: alloc: replace `Vec::set_len` with `inc_len`

 rust/kernel/alloc/kvec.rs | 85 +++++++++++++++++++++++++++--------------------
 rust/kernel/str.rs        |  2 +-
 rust/kernel/uaccess.rs    |  2 +-
 3 files changed, 51 insertions(+), 38 deletions(-)
---
base-commit: 1679b7159379d11100e4ab7d1de23c8cd7765aa1
change-id: 20250316-vec-set-len-99be6cc48374

Best regards,
-- 
Tamir Duberstein <tamird@gmail.com>
Re: [PATCH v3 0/4] rust: alloc: split `Vec::set_len` into `Vec::{inc,dec}_len`
Posted by Alice Ryhl 9 months, 3 weeks ago
On Mon, Apr 07, 2025 at 10:52:30AM -0400, Tamir Duberstein wrote:
> This series is the product of a discussion[0] on the safety requirements
> of `set_len`.
> 
> Link: https://lore.kernel.org/all/20250315154436.65065-1-dakr@kernel.org/ [0]
> Link: https://lore.kernel.org/all/20250316111644.154602-2-andrewjballance@gmail.com/ [1]
> Signed-off-by: Tamir Duberstein <tamird@gmail.com>

I'm still wondering if the divergence from upstream alloc is worth it...
but the code is okay.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Re: [PATCH v3 0/4] rust: alloc: split `Vec::set_len` into `Vec::{inc,dec}_len`
Posted by Danilo Krummrich 9 months, 3 weeks ago
On 4/16/25 3:28 PM, Alice Ryhl wrote:
> On Mon, Apr 07, 2025 at 10:52:30AM -0400, Tamir Duberstein wrote:
>> This series is the product of a discussion[0] on the safety requirements
>> of `set_len`.
>>
>> Link: https://lore.kernel.org/all/20250315154436.65065-1-dakr@kernel.org/ [0]
>> Link: https://lore.kernel.org/all/20250316111644.154602-2-andrewjballance@gmail.com/ [1]
>> Signed-off-by: Tamir Duberstein <tamird@gmail.com>
> 
> I'm still wondering if the divergence from upstream alloc is worth it...
> but the code is okay.
> 
> Reviewed-by: Alice Ryhl <aliceryhl@google.com>

Does this still apply to patch 1 in v4 [1]?

[1] 
https://lore.kernel.org/rust-for-linux/20250416-vec-set-len-v4-1-112b222604cd@gmail.com/
Re: [PATCH v3 0/4] rust: alloc: split `Vec::set_len` into `Vec::{inc,dec}_len`
Posted by Alice Ryhl 9 months, 2 weeks ago
On Tue, Apr 22, 2025 at 05:42:24PM +0200, Danilo Krummrich wrote:
> On 4/16/25 3:28 PM, Alice Ryhl wrote:
> > On Mon, Apr 07, 2025 at 10:52:30AM -0400, Tamir Duberstein wrote:
> > > This series is the product of a discussion[0] on the safety requirements
> > > of `set_len`.
> > > 
> > > Link: https://lore.kernel.org/all/20250315154436.65065-1-dakr@kernel.org/ [0]
> > > Link: https://lore.kernel.org/all/20250316111644.154602-2-andrewjballance@gmail.com/ [1]
> > > Signed-off-by: Tamir Duberstein <tamird@gmail.com>
> > 
> > I'm still wondering if the divergence from upstream alloc is worth it...
> > but the code is okay.
> > 
> > Reviewed-by: Alice Ryhl <aliceryhl@google.com>
> 
> Does this still apply to patch 1 in v4 [1]?
> 
> [1] https://lore.kernel.org/rust-for-linux/20250416-vec-set-len-v4-1-112b222604cd@gmail.com/

I replied with a new tag.

Alice
Re: [PATCH v3 0/4] rust: alloc: split `Vec::set_len` into `Vec::{inc,dec}_len`
Posted by Tamir Duberstein 10 months ago
On Mon, Apr 7, 2025 at 10:52 AM Tamir Duberstein <tamird@gmail.com> wrote:
>
> This series is the product of a discussion[0] on the safety requirements
> of `set_len`.
>
> Link: https://lore.kernel.org/all/20250315154436.65065-1-dakr@kernel.org/ [0]
> Link: https://lore.kernel.org/all/20250316111644.154602-2-andrewjballance@gmail.com/ [1]

Oops, dangling reference here. I removed the mention of Andrew's
series because it has been merged.
Re: [PATCH v3 0/4] rust: alloc: split `Vec::set_len` into `Vec::{inc,dec}_len`
Posted by Tamir Duberstein 9 months, 4 weeks ago
On Mon, Apr 7, 2025 at 10:53 AM Tamir Duberstein <tamird@gmail.com> wrote:
>
> On Mon, Apr 7, 2025 at 10:52 AM Tamir Duberstein <tamird@gmail.com> wrote:
> >
> > This series is the product of a discussion[0] on the safety requirements
> > of `set_len`.
> >
> > Link: https://lore.kernel.org/all/20250315154436.65065-1-dakr@kernel.org/ [0]
> > Link: https://lore.kernel.org/all/20250316111644.154602-2-andrewjballance@gmail.com/ [1]
>
> Oops, dangling reference here. I removed the mention of Andrew's
> series because it has been merged.

Benno, Alice: did you folks want to take a look?