Commit Graph

433 Commits

Author SHA1 Message Date
Alice Ryhl
5a41bb32dd ANDROID: rust_binder: rework process cleanup
Rust Binder cleanup is reworked to match the order in which C Binder
cleans up things. A few notes on the changes:

* Actually dropping thread objects is done at the very end because they
  contain a call to synchronize_rcu() which is slow. This ensures that
  death notifications are sent without waiting for those calls. This
  avoids failures in rustBinderTest. (The test is already flaky, but
  this extra sleep makes the flake much more likely to happen.)

* We now free refs on remote nodes in release explicitly. Previously
  that only happened implicitly when everything keeping the ref alive
  has been dropped. To avoid spurious warnings from this, the warning
  print about dropping a ref that doesn't exist is only printed if the
  process is alive.

Bug: 431914626
Change-Id: I3d1f4f15ffac7587d1bb0113a41330b2aea69b3d
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-08-11 10:10:26 -07:00
Alice Ryhl
6e80d044b3 FROMGIT: rust: uaccess: add UserSliceReader::strcpy_into_buf
This patch adds a more convenient method for reading C strings from
userspace. Logic is added to NUL-terminate the buffer when necessary so
that a &CStr can be returned.

Note that we treat attempts to read past `self.length` as a fault, so
this returns EFAULT if that limit is exceeded before `buf.len()` is
reached.

Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Link: https://lore.kernel.org/r/20250616-strncpy-from-user-v5-2-2d3fb0e1f5af@google.com
[ Use `from_mut` to clean `clippy::ref_as_ptr` lint. Reworded
  title. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Bug: 414339114
(cherry picked from commit 17bbbefbf6715a543ff4713e26f7b8e6b7a876d6
 https://github.com/Rust-for-Linux/linux.git rust-next)
Change-Id: I285c99788ff2e2bc3f9f9b6bbc2746dd454002f5
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-15 11:45:55 -07:00
Alice Ryhl
0cb01a7d86 FROMGIT: rust: uaccess: add strncpy_from_user
This patch adds a direct wrapper around the C function of the same name.
It's not really intended for direct use by Rust code since
strncpy_from_user has a somewhat unfortunate API where it only
nul-terminates the buffer if there's space for the nul-terminator. This
means that a direct Rust wrapper around it could not return a &CStr
since the buffer may not be a cstring. However, we still add the method
to build more convenient APIs on top of it, which will happen in
subsequent patches.

Reviewed-by: Danilo Krummrich <dakr@kernel.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20250616-strncpy-from-user-v5-1-2d3fb0e1f5af@google.com
[ Reworded title. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Bug: 414339114
(cherry picked from commit 8da881d39c1b7fd4a211587ba40f1c936909a11a
 https://github.com/Rust-for-Linux/linux.git rust-next)
Change-Id: I1455d14afbec4a4af1386618985f01a21b6dcf97
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-15 11:45:55 -07:00
Alice Ryhl
bd6df18cfd Revert "ANDROID: ashmem: use strncpy_from_user in set_name"
This reverts commit ba971cd36a.

Bug: 414339114
Change-Id: If44d5a7516c7dfdda68272f629ce30d74c84694f
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-15 11:45:55 -07:00
Alice Ryhl
6a2be11026 UPSTREAM: task: rust: rework how current is accessed
Introduce a new type called `CurrentTask` that lets you perform various
operations that are only safe on the `current` task.  Use the new type to
provide a way to access the current mm without incrementing its refcount.

With this change, you can write stuff such as

	let vma = current!().mm().lock_vma_under_rcu(addr);

without incrementing any refcounts.

This replaces the existing abstractions for accessing the current pid
namespace.  With the old approach, every field access to current involves
both a macro and a unsafe helper function.  The new approach simplifies
that to a single safe function on the `CurrentTask` type.  This makes it
less heavy-weight to add additional current accessors in the future.

That said, creating a `CurrentTask` type like the one in this patch
requires that we are careful to ensure that it cannot escape the current
task or otherwise access things after they are freed.  To do this, I
declared that it cannot escape the current "task context" where I defined
a "task context" as essentially the region in which `current` remains
unchanged.  So e.g., release_task() or begin_new_exec() would leave the
task context.

If a userspace thread returns to userspace and later makes another
syscall, then I consider the two syscalls to be different task contexts.
This allows values stored in that task to be modified between syscalls,
even if they're guaranteed to be immutable during a syscall.

Ensuring correctness of `CurrentTask` is slightly tricky if we also want
the ability to have a safe `kthread_use_mm()` implementation in Rust.  To
support that safely, there are two patterns we need to ensure are safe:

	// Case 1: current!() called inside the scope.
	let mm;
	kthread_use_mm(some_mm, || {
	    mm = current!().mm();
	});
	drop(some_mm);
	mm.do_something(); // UAF

and:

	// Case 2: current!() called before the scope.
	let mm;
	let task = current!();
	kthread_use_mm(some_mm, || {
	    mm = task.mm();
	});
	drop(some_mm);
	mm.do_something(); // UAF

The existing `current!()` abstraction already natively prevents the first
case: The `&CurrentTask` would be tied to the inner scope, so the
borrow-checker ensures that no reference derived from it can escape the
scope.

Fixing the second case is a bit more tricky.  The solution is to
essentially pretend that the contents of the scope execute on an different
thread, which means that only thread-safe types can cross the boundary.
Since `CurrentTask` is marked `NotThreadSafe`, attempts to move it to
another thread will fail, and this includes our fake pretend thread
boundary.

This has the disadvantage that other types that aren't thread-safe for
reasons unrelated to `current` also cannot be moved across the
`kthread_use_mm()` boundary.  I consider this an acceptable tradeoff.

Link: https://lkml.kernel.org/r/20250408-vma-v16-8-d8b446e885d9@google.com
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Cc: Alex Gaynor <alex.gaynor@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Balbir Singh <balbirs@nvidia.com>
Cc: Benno Lossin <benno.lossin@proton.me>
Cc: Björn Roy Baron <bjorn3_gh@protonmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jann Horn <jannh@google.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Trevor Gross <tmgross@umich.edu>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bug: 429146594
(cherry picked from commit 6acb75ad7b9e1548ae7f7532312295f74e48c973)
Change-Id: I40422349633c5c125a5d4d8611efc5ca5c2cd484
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:08:23 +00:00
Christian Brauner
602e2300de UPSTREAM: rust: add PidNamespace
The lifetime of `PidNamespace` is bound to `Task` and `struct pid`.

The `PidNamespace` of a `Task` doesn't ever change once the `Task` is
alive. A `unshare(CLONE_NEWPID)` or `setns(fd_pidns/pidfd, CLONE_NEWPID)`
will not have an effect on the calling `Task`'s pid namespace. It will
only effect the pid namespace of children created by the calling `Task`.
This invariant guarantees that after having acquired a reference to a
`Task`'s pid namespace it will remain unchanged.

When a task has exited and been reaped `release_task()` will be called.
This will set the `PidNamespace` of the task to `NULL`. So retrieving
the `PidNamespace` of a task that is dead will return `NULL`. Note, that
neither holding the RCU lock nor holding a referencing count to the
`Task` will prevent `release_task()` being called.

In order to retrieve the `PidNamespace` of a `Task` the
`task_active_pid_ns()` function can be used. There are two cases to
consider:

(1) retrieving the `PidNamespace` of the `current` task (2) retrieving
the `PidNamespace` of a non-`current` task

From system call context retrieving the `PidNamespace` for case (1) is
always safe and requires neither RCU locking nor a reference count to be
held. Retrieving the `PidNamespace` after `release_task()` for current
will return `NULL` but no codepath like that is exposed to Rust.

Retrieving the `PidNamespace` from system call context for (2) requires
RCU protection. Accessing `PidNamespace` outside of RCU protection
requires a reference count that must've been acquired while holding the
RCU lock. Note that accessing a non-`current` task means `NULL` can be
returned as the non-`current` task could have already passed through
`release_task()`.

To retrieve (1) the `current_pid_ns!()` macro should be used which
ensure that the returned `PidNamespace` cannot outlive the calling
scope. The associated `current_pid_ns()` function should not be called
directly as it could be abused to created an unbounded lifetime for
`PidNamespace`. The `current_pid_ns!()` macro allows Rust to handle the
common case of accessing `current`'s `PidNamespace` without RCU
protection and without having to acquire a reference count.

For (2) the `task_get_pid_ns()` method must be used. This will always
acquire a reference on `PidNamespace` and will return an `Option` to
force the caller to explicitly handle the case where `PidNamespace` is
`None`, something that tends to be forgotten when doing the equivalent
operation in `C`. Missing RCU primitives make it difficult to perform
operations that are otherwise safe without holding a reference count as
long as RCU protection is guaranteed. But it is not important currently.
But we do want it in the future.

Note for (2) the required RCU protection around calling
`task_active_pid_ns()` synchronizes against putting the last reference
of the associated `struct pid` of `task->thread_pid`. The `struct pid`
stored in that field is used to retrieve the `PidNamespace` of the
caller. When `release_task()` is called `task->thread_pid` will be
`NULL`ed and `put_pid()` on said `struct pid` will be delayed in
`free_pid()` via `call_rcu()` allowing everyone with an RCU protected
access to the `struct pid` acquired from `task->thread_pid` to finish.

Link: https://lore.kernel.org/r/20241002-brauner-rust-pid_namespace-v5-1-a90e70d44fde@kernel.org
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>

Bug: 429146594
(cherry picked from commit e0020ba6cbcbfbaaa50c3d4b610c7caa36459624)
Change-Id: Ib7d3b257fe9b6f11f8171924e2a146abb52b9bb7
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:08:23 +00:00
Alice Ryhl
12dfc1d9cb UPSTREAM: rust: miscdevice: add mmap support
Add the ability to write a file_operations->mmap hook in Rust when using
the miscdevice abstraction.  The `vma` argument to the `mmap` hook uses
the `VmaNew` type from the previous commit; this type provides the correct
set of operations for a file_operations->mmap hook.

Link: https://lkml.kernel.org/r/20250408-vma-v16-7-d8b446e885d9@google.com
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Cc: Alex Gaynor <alex.gaynor@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Balbir Singh <balbirs@nvidia.com>
Cc: Benno Lossin <benno.lossin@proton.me>
Cc: Björn Roy Baron <bjorn3_gh@protonmail.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Jann Horn <jannh@google.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Trevor Gross <tmgross@umich.edu>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bug: 429146594
(cherry picked from commit f8c78198816f04619da6eebfc5b67741bff56325)
Change-Id: Ib8965aa5d000da6a97650eb04be61df3c21bd85a
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:08:23 +00:00
Alice Ryhl
8e67cb756f UPSTREAM: mm: rust: add VmaNew for f_ops->mmap()
This type will be used when setting up a new vma in an f_ops->mmap() hook.
Using a separate type from VmaRef allows us to have a separate set of
operations that you are only able to use during the mmap() hook.  For
example, the VM_MIXEDMAP flag must not be changed after the initial setup
that happens during the f_ops->mmap() hook.

To avoid setting invalid flag values, the methods for clearing VM_MAYWRITE
and similar involve a check of VM_WRITE, and return an error if VM_WRITE
is set.  Trying to use `try_clear_maywrite` without checking the return
value results in a compilation error because the `Result` type is marked

For now, there's only a method for VM_MIXEDMAP and not VM_PFNMAP.  When we
add a VM_PFNMAP method, we will need some way to prevent you from setting
both VM_MIXEDMAP and VM_PFNMAP on the same vma.

Link: https://lkml.kernel.org/r/20250408-vma-v16-6-d8b446e885d9@google.com
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Reviewed-by: Jann Horn <jannh@google.com>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Cc: Alex Gaynor <alex.gaynor@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Balbir Singh <balbirs@nvidia.com>
Cc: Benno Lossin <benno.lossin@proton.me>
Cc: Björn Roy Baron <bjorn3_gh@protonmail.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Gary Guo <gary@garyguo.net>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Trevor Gross <tmgross@umich.edu>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bug: 429146594
(cherry picked from commit dcb81aeab406e417bc0b4cf68de6eb07a1d2e6ce)
Change-Id: I195a63f4ae613192ccf9be5f4805263fb5b42170
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:08:22 +00:00
Alice Ryhl
bd140ddf75 UPSTREAM: mm: rust: add mmput_async support
Adds an MmWithUserAsync type that uses mmput_async when dropped but is
otherwise identical to MmWithUser.  This has to be done using a separate
type because the thing we are changing is the destructor.

Rust Binder needs this to avoid a certain deadlock.  See commit
9a9ab0d963 ("binder: fix race between mmput() and do_exit()") for
details.  It's also needed in the shrinker to avoid cleaning up the mm in
the shrinker's context.

Link: https://lkml.kernel.org/r/20250408-vma-v16-5-d8b446e885d9@google.com
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Cc: Alex Gaynor <alex.gaynor@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Balbir Singh <balbirs@nvidia.com>
Cc: Benno Lossin <benno.lossin@proton.me>
Cc: Björn Roy Baron <bjorn3_gh@protonmail.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jann Horn <jannh@google.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Trevor Gross <tmgross@umich.edu>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bug: 429146594
(cherry picked from commit 114ba9b9e8191925438365089c0d300f4f1b6fb1)
Change-Id: Iad1464e84163d33320d9ce1e87f5e29f16da5dae
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:08:22 +00:00
Alice Ryhl
0c50773076 UPSTREAM: mm: rust: add lock_vma_under_rcu
Currently, the binder driver always uses the mmap lock to make changes to
its vma.  Because the mmap lock is global to the process, this can involve
significant contention.  However, the kernel has a feature called per-vma
locks, which can significantly reduce contention.  For example, you can
take a vma lock in parallel with an mmap write lock.  This is important
because contention on the mmap lock has been a long-term recurring
challenge for the Binder driver.

This patch introduces support for using `lock_vma_under_rcu` from Rust.
The Rust Binder driver will be able to use this to reduce contention on
the mmap lock.

Link: https://lkml.kernel.org/r/20250408-vma-v16-4-d8b446e885d9@google.com
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Reviewed-by: Jann Horn <jannh@google.com>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Cc: Alex Gaynor <alex.gaynor@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Balbir Singh <balbirs@nvidia.com>
Cc: Benno Lossin <benno.lossin@proton.me>
Cc: Björn Roy Baron <bjorn3_gh@protonmail.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Trevor Gross <tmgross@umich.edu>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bug: 429146594
(cherry picked from commit 3105f8f391ce00153c553bfe89efbb30b120d858)
Change-Id: Ib997fa4e4e3fff46ccaa98cd7dd4e881a60324bb
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:08:22 +00:00
Alice Ryhl
0b5465bb31 UPSTREAM: mm: rust: add vm_insert_page
The vm_insert_page method is only usable on vmas with the VM_MIXEDMAP
flag, so we introduce a new type to keep track of such vmas.

The approach used in this patch assumes that we will not need to encode
many flag combinations in the type.  I don't think we need to encode more
than VM_MIXEDMAP and VM_PFNMAP as things are now.  However, if that
becomes necessary, using generic parameters in a single type would scale
better as the number of flags increases.

Link: https://lkml.kernel.org/r/20250408-vma-v16-3-d8b446e885d9@google.com
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Cc: Alex Gaynor <alex.gaynor@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Balbir Singh <balbirs@nvidia.com>
Cc: Benno Lossin <benno.lossin@proton.me>
Cc: Björn Roy Baron <bjorn3_gh@protonmail.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jann Horn <jannh@google.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Trevor Gross <tmgross@umich.edu>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bug: 429146594
(cherry picked from commit bf3d331bb80749542cf299f94c471f611fb113b1)
Change-Id: I6f8b796cfa216af7b2d5ca29c3ad7c770e3ce9ee
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:08:22 +00:00
Alice Ryhl
d7f52612c5 UPSTREAM: mm: rust: add vm_area_struct methods that require read access
This adds a type called VmaRef which is used when referencing a vma that
you have read access to.  Here, read access means that you hold either the
mmap read lock or the vma read lock (or stronger).

Additionally, a vma_lookup method is added to the mmap read guard, which
enables you to obtain a &VmaRef in safe Rust code.

This patch only provides a way to lock the mmap read lock, but a follow-up
patch also provides a way to just lock the vma read lock.

Link: https://lkml.kernel.org/r/20250408-vma-v16-2-d8b446e885d9@google.com
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Reviewed-by: Jann Horn <jannh@google.com>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Cc: Alex Gaynor <alex.gaynor@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Balbir Singh <balbirs@nvidia.com>
Cc: Benno Lossin <benno.lossin@proton.me>
Cc: Björn Roy Baron <bjorn3_gh@protonmail.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Trevor Gross <tmgross@umich.edu>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bug: 429146594
(cherry picked from commit 040f404b731207935ed644b14bcc2bb8b8488d00)
Change-Id: I87c6ccb0f6fe99e492040babed1cc0ca6f482374
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:08:22 +00:00
Alice Ryhl
f03d4f7490 UPSTREAM: mm: rust: add abstraction for struct mm_struct
Patch series "Rust support for mm_struct, vm_area_struct, and mmap", v16.

This updates the vm_area_struct support to use the approach we discussed
at LPC where there are several different Rust wrappers for vm_area_struct
depending on the kind of access you have to the vma.  Each case allows a
different set of operations on the vma.

This includes an MM MAINTAINERS entry as proposed by Lorenzo:
https://lore.kernel.org/all/33e64b12-aa07-4e78-933a-b07c37ff1d84@lucifer.local/

This patch (of 9):

These abstractions allow you to reference a `struct mm_struct` using both
mmgrab and mmget refcounts.  This is done using two Rust types:

* Mm - represents an mm_struct where you don't know anything about the
  value of mm_users.
* MmWithUser - represents an mm_struct where you know at compile time
  that mm_users is non-zero.

This allows us to encode in the type system whether a method requires that
mm_users is non-zero or not.  For instance, you can always call
`mmget_not_zero` but you can only call `mmap_read_lock` when mm_users is
non-zero.

The struct is called Mm to keep consistency with the C side.

The ability to obtain `current->mm` is added later in this series.

The mm module is defined to only exist when CONFIG_MMU is set.  This
avoids various errors due to missing types and functions when CONFIG_MMU
is disabled.  More fine-grained cfgs can be considered in the future.  See
the thread at [1] for more info.

Link: https://lkml.kernel.org/r/20250408-vma-v16-9-d8b446e885d9@google.com
Link: https://lkml.kernel.org/r/20250408-vma-v16-1-d8b446e885d9@google.com
Link: https://lore.kernel.org/all/202503091916.QousmtcY-lkp@intel.com/
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Acked-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Acked-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Acked-by: Balbir Singh <balbirs@nvidia.com>
Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
Reviewed-by: Gary Guo <gary@garyguo.net>
Cc: Alex Gaynor <alex.gaynor@gmail.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Benno Lossin <benno.lossin@proton.me>
Cc: Björn Roy Baron <bjorn3_gh@protonmail.com>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jann Horn <jannh@google.com>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Trevor Gross <tmgross@umich.edu>
Cc: Vlastimil Babka <vbabka@suse.cz>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Bug: 429146594
(cherry picked from commit 5bb9ed6cdfeb75883652fd0ed3e3885083a92b4b)
Change-Id: I33a9a37795ec426c051abb881a0425ab545c8cad
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:08:21 +00:00
Alice Ryhl
2ef6dbc73e BACKPORT: rust: miscdevice: change how f_ops vtable is constructed
I was helping someone with writing a new Rust abstraction, and we were
using the miscdevice abstraction as an example. While doing this, it
became clear to me that the way I implemented the f_ops vtable is
confusing to new Rust users, and that the approach used by the block
abstractions is less confusing.

Thus, update the miscdevice abstractions to use the same approach as
rust/kernel/block/mq/operations.rs.

Sorry about the large diff. This changes the indentation of a large
amount of code.

Reviewed-by: Christian Schrefl <chrisi.schrefl@gmail.com>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20250227-miscdevice-fops-change-v1-1-c9e9b75d67eb@google.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Bug: 429146594
[ aliceryhl: also adjust llseek and similar to new style ]
(cherry picked from commit 74fc34937d72d04e89e4f75ea66147cdc9b785f5)
Change-Id: Ie87c5015d483a4c5a27ab17ae8a836a8956d1092
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:08:21 +00:00
Alice Ryhl
1acd3b312f Revert "FROMLIST: mm: rust: add abstraction for struct mm_struct"
This reverts commit 4deea7dce7.

Bug: 429146594
Change-Id: Ide43b384264dc8b69cf0a3c5bb1d8b71fe4742a7
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:08:18 +00:00
Alice Ryhl
a012c15566 Revert "FROMLIST: mm: rust: add vm_area_struct methods that require read access"
This reverts commit 84aa9d6318.

Bug: 429146594
Change-Id: Iff6a420abd6dcdbb0589cc3714b84c2013930545
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:08:03 +00:00
Alice Ryhl
3be00a9bf8 Revert "FROMLIST: mm: rust: add vm_insert_page"
This reverts commit 5fd689f0d4.

Bug: 429146594
Change-Id: I6b5db9de36f2e44aaf4f1ac85dd2292e3d99d2bf
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:08:01 +00:00
Alice Ryhl
3aed88205e Revert "FROMLIST: mm: rust: add lock_vma_under_rcu"
This reverts commit b2e4a698fc.

Bug: 429146594
Change-Id: Icb2794ad170600ac87b8466d64ddc5925b8cd893
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:07:59 +00:00
Alice Ryhl
a121b6e72f Revert "FROMLIST: mm: rust: add mmput_async support"
This reverts commit a259f04a68.

Bug: 429146594
Change-Id: Iee469177018f32b802d6be2029d389ea7ed5b261
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:07:57 +00:00
Alice Ryhl
9248564a81 Revert "FROMLIST: mm: rust: add VmAreaNew for f_ops->mmap()"
This reverts commit 7d1983ce89.

Bug: 429146594
Change-Id: I4d01e34d4ae0f24ca5ddbb64bac219c6f9b48fc3
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:07:52 +00:00
Alice Ryhl
6de3ace5b5 Revert "FROMLIST: rust: miscdevice: add mmap support"
This reverts commit 88a4dfa30b.

Bug: 429146594
Change-Id: Ia75f9f7f9706971fe47e6ab74a8f0009876396af
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:07:49 +00:00
Alice Ryhl
b7f54dd23b Revert "BACKPORT: FROMLIST: task: rust: rework how current is accessed"
This reverts commit 98c8011159.

Bug: 429146594
Change-Id: Ib6968a1a63aafb9fea3e485c39d451b70cf320b4
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-07-02 13:07:45 +00:00
Alice Ryhl
3744083cdb ANDROID: rust: miscdevice: fix formatting
An import was removed from these imports during an LTS merge, which
means that rustfmt now prefers a different formatting of these imports.

Fixes: b3fb80bdc6 ("Merge 6.12.19 into android16-6.12")
Change-Id: I14bbe861e738767a6057a320cbe8cf5cf50f5d05
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-06-30 04:49:20 -07:00
Alice Ryhl
2a0e6416e5 FROMLIST: poll: rust: allow poll_table ptrs to be null
It's possible for a poll_table to be null. This can happen if an
end-user just wants to know if a resource has events right now without
registering a waiter for when events become available. Furthermore,
these null pointers should be handled transparently by the API, so we
should not change `from_ptr` to return an `Option`. Thus, change
`PollTable` to wrap a raw pointer rather than use a reference so that
you can pass null.

Comments mentioning `struct poll_table` are changed to just `poll_table`
since `poll_table` is a typedef. (It's a typedef because it's supposed
to be opaque.)

Reviewed-by: Benno Lossin <lossin@kernel.org>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>

Bug: 426545861
Link: https://lore.kernel.org/r/20250623-poll-table-null-v2-1-7561174bae7a@google.com
Change-Id: Idf965e16d699f29f7adc81710de02e4e2ec658c6
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-06-30 00:21:53 -07:00
Greg Kroah-Hartman
651f2e4fca Merge 6.12.29 into android16-6.12-lts
GKI (arm64) relevant 44 out of 185 changes, affecting 54 files +634/-365
  b32411f045 dm: add missing unlock on in dm_keyslot_evict() [1 file, +2/-1]
  61e0fc3312 fs/erofs/fileio: call erofs_onlinefolio_split() after bio_add_folio() [1 file, +2/-2]
  14ee85b748 firmware: arm_scmi: Fix timeout checks on polling path [1 file, +8/-5]
  98cd7ed927 sch_htb: make htb_deactivate() idempotent [1 file, +6/-9]
  35be4c0cdf gre: Fix again IPv6 link-local address generation. [1 file, +9/-6]
  c33927f385 can: gw: fix RCU/BH usage in cgw_create_job() [1 file, +90/-59]
  4555c4a13a wifi: mac80211: fix the type of status_code for negotiated TID to Link Mapping [2 files, +7/-7]
  64385c0d02 erofs: ensure the extra temporary copy is valid for shortened bvecs [1 file, +14/-17]
  b37e54259c bpf: Scrub packet on bpf_redirect_peer [1 file, +1/-0]
  bb8f86f40e net: export a helper for adding up queue stats [2 files, +56/-19]
  302a0cd0bb Input: xpad - fix Share button on Xbox One controllers [1 file, +20/-15]
  bf239d3835 Input: xpad - add support for 8BitDo Ultimate 2 Wireless Controller [1 file, +1/-0]
  38bb0170d6 Input: xpad - fix two controller table values [1 file, +2/-2]
  2910019b04 mm: vmalloc: support more granular vrealloc() sizing [2 files, +25/-7]
  6166c3cf40 mm/huge_memory: fix dereferencing invalid pmd migration entry [1 file, +8/-3]
  b543a5a73b mm/userfaultfd: fix uninitialized output field for -EAGAIN race [1 file, +22/-6]
  7f37e31483 io_uring: ensure deferred completions are flushed for multishot [1 file, +8/-0]
  abbc99e898 arm64: cpufeature: Move arm64_use_ng_mappings to the .data section to prevent wrong idmap generation [1 file, +8/-1]
  d66a22f6a4 memblock: Accept allocated memory before use in memblock_double_array() [1 file, +8/-1]
  d63851049f module: ensure that kobject_put() is safe for module type kobjects [1 file, +3/-1]
  75f23e49ad usb: gadget: f_ecm: Add get_status callback [1 file, +7/-0]
  d1c8fa4c6e usb: gadget: Use get_status callback to set remote wakeup capability [1 file, +5/-7]
  3366a19948 usb: typec: tcpm: delay SNK_TRY_WAIT_DEBOUNCE to SRC_TRYWAIT transition [1 file, +1/-1]
  5ad298d6d4 usb: typec: ucsi: displayport: Fix NULL pointer access [1 file, +2/-0]
  afe8849597 types: Complement the aligned types with signed 64-bit one [2 files, +3/-1]
  02a77b3020 loop: Use bdev limit helpers for configuring discard [1 file, +4/-4]
  722f6dece7 loop: Simplify discard granularity calc [1 file, +1/-2]
  0558ce095b loop: Fix ABBA locking race [1 file, +15/-15]
  5e1470b276 loop: refactor queue limits updates [1 file, +20/-16]
  a781ffe410 loop: factor out a loop_assign_backing_file helper [1 file, +10/-10]
  184b147b9f loop: Add sanity check for read/write_iter [1 file, +23/-0]
  19fa2a4830 nvme: unblock ctrl state transition for firmware update [1 file, +2/-1]
  3edac2949e io_uring/sqpoll: Increase task_work submission batch size [1 file, +1/-1]
  cd010271a9 do_umount(): add missing barrier before refcount checks in sync case [1 file, +2/-1]
  2482f7705b io_uring: always arm linked timeouts prior to issue [1 file, +15/-35]
  564d25b1a6 mm: page_alloc: don't steal single pages from biggest buddy [1 file, +34/-46]
  16bae58f73 mm: page_alloc: speed up fallbacks in rmqueue_bulk() [1 file, +80/-33]
  86b37810fa sched/eevdf: Fix se->slice being set to U64_MAX and resulting crash [1 file, +1/-3]
  2a3915e861 arm64: insn: Add support for encoding DSB [2 files, +38/-23]
  ec5bca57af arm64: proton-pack: Expose whether the platform is mitigated by firmware [2 files, +6/-0]
  f2aebb8ec6 arm64: proton-pack: Expose whether the branchy loop k value [2 files, +6/-0]
  38c345fd54 arm64: bpf: Add BHB mitigation to the epilogue for cBPF programs [3 files, +52/-5]
  e5f5100f1c arm64: bpf: Only mitigate cBPF programs loaded by unprivileged users [1 file, +3/-0]
  2176530849 arm64: proton-pack: Add new CPUs 'k' values for branch mitigation [2 files, +3/-0]

Changes in 6.12.29
	dm: add missing unlock on in dm_keyslot_evict()
	fs/erofs/fileio: call erofs_onlinefolio_split() after bio_add_folio()
	Revert "btrfs: canonicalize the device path before adding it"
	arm64: dts: imx8mm-verdin: Link reg_usdhc2_vqmmc to usdhc2
	firmware: arm_scmi: Fix timeout checks on polling path
	can: mcan: m_can_class_unregister(): fix order of unregistration calls
	s390/pci: Fix missing check for zpci_create_device() error return
	wifi: cfg80211: fix out-of-bounds access during multi-link element defragmentation
	vfio/pci: Align huge faults to order
	s390/pci: Fix duplicate pci_dev_put() in disable_slot() when PF has child VFs
	can: mcp251xfd: mcp251xfd_remove(): fix order of unregistration calls
	can: rockchip_canfd: rkcanfd_remove(): fix order of unregistration calls
	ksmbd: prevent rename with empty string
	ksmbd: prevent out-of-bounds stream writes by validating *pos
	ksmbd: Fix UAF in __close_file_table_ids
	openvswitch: Fix unsafe attribute parsing in output_userspace()
	ksmbd: fix memory leak in parse_lease_state()
	s390/entry: Fix last breaking event handling in case of stack corruption
	sch_htb: make htb_deactivate() idempotent
	virtio_net: xsk: bind/unbind xsk for tx
	virtio-net: free xsk_buffs on error in virtnet_xsk_pool_enable()
	gre: Fix again IPv6 link-local address generation.
	net: ethernet: mtk_eth_soc: reset all TX queues on DMA free
	net: ethernet: mtk_eth_soc: do not reset PSE when setting FE
	can: m_can: m_can_class_allocate_dev(): initialize spin lock on device probe
	can: mcp251xfd: fix TDC setting for low data bit rates
	can: gw: fix RCU/BH usage in cgw_create_job()
	wifi: mac80211: fix the type of status_code for negotiated TID to Link Mapping
	ice: Initial support for E825C hardware in ice_adapter
	ice: use DSN instead of PCI BDF for ice_adapter index
	erofs: ensure the extra temporary copy is valid for shortened bvecs
	ipvs: fix uninit-value for saddr in do_output_route4
	netfilter: ipset: fix region locking in hash types
	bpf: Scrub packet on bpf_redirect_peer
	net: dsa: b53: allow leaky reserved multicast
	net: dsa: b53: keep CPU port always tagged again
	net: dsa: b53: fix clearing PVID of a port
	net: dsa: b53: fix flushing old pvid VLAN on pvid change
	net: dsa: b53: fix VLAN ID for untagged vlan on bridge leave
	net: dsa: b53: always rejoin default untagged VLAN on bridge leave
	net: dsa: b53: do not allow to configure VLAN 0
	net: dsa: b53: do not program vlans when vlan filtering is off
	net: dsa: b53: fix toggling vlan_filtering
	net: dsa: b53: fix learning on VLAN unaware bridges
	net: dsa: b53: do not set learning and unicast/multicast on up
	fbnic: Fix initialization of mailbox descriptor rings
	fbnic: Gate AXI read/write enabling on FW mailbox
	fbnic: Actually flush_tx instead of stalling out
	fbnic: Improve responsiveness of fbnic_mbx_poll_tx_ready
	fbnic: Pull fbnic_fw_xmit_cap_msg use out of interrupt context
	fbnic: Do not allow mailbox to toggle to ready outside fbnic_mbx_poll_tx_ready
	net: export a helper for adding up queue stats
	virtio-net: fix total qstat values
	Input: cyttsp5 - ensure minimum reset pulse width
	Input: cyttsp5 - fix power control issue on wakeup
	Input: mtk-pmic-keys - fix possible null pointer dereference
	Input: xpad - fix Share button on Xbox One controllers
	Input: xpad - add support for 8BitDo Ultimate 2 Wireless Controller
	Input: xpad - fix two controller table values
	Input: synaptics - enable InterTouch on Dynabook Portege X30-D
	Input: synaptics - enable InterTouch on Dynabook Portege X30L-G
	Input: synaptics - enable InterTouch on Dell Precision M3800
	Input: synaptics - enable SMBus for HP Elitebook 850 G1
	Input: synaptics - enable InterTouch on TUXEDO InfinityBook Pro 14 v5
	rust: clean Rust 1.88.0's `unnecessary_transmutes` lint
	objtool/rust: add one more `noreturn` Rust function for Rust 1.87.0
	rust: clean Rust 1.88.0's warning about `clippy::disallowed_macros` configuration
	staging: iio: adc: ad7816: Correct conditional logic for store mode
	staging: bcm2835-camera: Initialise dev in v4l2_dev
	staging: axis-fifo: Remove hardware resets for user errors
	staging: axis-fifo: Correct handling of tx_fifo_depth for size validation
	x86/mm: Eliminate window where TLB flushes may be inadvertently skipped
	mm: fix folio_pte_batch() on XEN PV
	mm: vmalloc: support more granular vrealloc() sizing
	mm/huge_memory: fix dereferencing invalid pmd migration entry
	mm/userfaultfd: fix uninitialized output field for -EAGAIN race
	selftests/mm: compaction_test: support platform with huge mount of memory
	selftests/mm: fix a build failure on powerpc
	KVM: SVM: Forcibly leave SMM mode on SHUTDOWN interception
	drm/amd/display: Shift DMUB AUX reply command if necessary
	io_uring: ensure deferred completions are flushed for multishot
	iio: adc: ad7606: fix serial register access
	iio: adc: rockchip: Fix clock initialization sequence
	iio: adis16201: Correct inclinometer channel resolution
	iio: imu: inv_mpu6050: align buffer for timestamp
	iio: imu: st_lsm6dsx: fix possible lockup in st_lsm6dsx_read_fifo
	iio: imu: st_lsm6dsx: fix possible lockup in st_lsm6dsx_read_tagged_fifo
	drm/v3d: Add job to pending list if the reset was skipped
	drm/xe: Add page queue multiplier
	drm/amdgpu/vcn: using separate VCN1_AON_SOC offset
	drm/amd/display: Fix invalid context error in dml helper
	drm/amd/display: more liberal vmin/vmax update for freesync
	drm/amd/display: Fix the checking condition in dmub aux handling
	drm/amd/display: Remove incorrect checking in dmub aux handler
	drm/amd/display: Fix wrong handling for AUX_DEFER case
	drm/amd/display: Copy AUX read reply data whenever length > 0
	drm/amdgpu/hdp4: use memcfg register to post the write for HDP flush
	drm/amdgpu/hdp5.2: use memcfg register to post the write for HDP flush
	drm/amdgpu/hdp5: use memcfg register to post the write for HDP flush
	drm/amdgpu/hdp6: use memcfg register to post the write for HDP flush
	drm/amdgpu/hdp7: use memcfg register to post the write for HDP flush
	usb: uhci-platform: Make the clock really optional
	smb: client: Avoid race in open_cached_dir with lease breaks
	xen: swiotlb: Use swiotlb bouncing if kmalloc allocation demands it
	xenbus: Use kref to track req lifetime
	accel/ivpu: Increase state dump msg timeout
	arm64: cpufeature: Move arm64_use_ng_mappings to the .data section to prevent wrong idmap generation
	clocksource/i8253: Use raw_spinlock_irqsave() in clockevent_i8253_disable()
	memblock: Accept allocated memory before use in memblock_double_array()
	module: ensure that kobject_put() is safe for module type kobjects
	x86/microcode: Consolidate the loader enablement checking
	ocfs2: fix the issue with discontiguous allocation in the global_bitmap
	ocfs2: switch osb->disable_recovery to enum
	ocfs2: implement handshaking with ocfs2 recovery thread
	ocfs2: stop quota recovery before disabling quotas
	usb: dwc3: gadget: Make gadget_wakeup asynchronous
	usb: cdnsp: Fix issue with resuming from L1
	usb: cdnsp: fix L1 resume issue for RTL_REVISION_NEW_LPM version
	usb: gadget: f_ecm: Add get_status callback
	usb: gadget: tegra-xudc: ACK ST_RC after clearing CTRL_RUN
	usb: gadget: Use get_status callback to set remote wakeup capability
	usb: host: tegra: Prevent host controller crash when OTG port is used
	usb: misc: onboard_usb_dev: fix support for Cypress HX3 hubs
	usb: typec: tcpm: delay SNK_TRY_WAIT_DEBOUNCE to SRC_TRYWAIT transition
	usb: typec: ucsi: displayport: Fix NULL pointer access
	USB: usbtmc: use interruptible sleep in usbtmc_read
	usb: usbtmc: Fix erroneous get_stb ioctl error returns
	usb: usbtmc: Fix erroneous wait_srq ioctl return
	usb: usbtmc: Fix erroneous generic_read ioctl return
	iio: accel: adxl367: fix setting odr for activity time update
	iio: temp: maxim-thermocouple: Fix potential lack of DMA safe buffer.
	types: Complement the aligned types with signed 64-bit one
	iio: accel: adxl355: Make timestamp 64-bit aligned using aligned_s64
	iio: adc: dln2: Use aligned_s64 for timestamp
	MIPS: Fix MAX_REG_OFFSET
	riscv: misaligned: Add handling for ZCB instructions
	loop: Use bdev limit helpers for configuring discard
	loop: Simplify discard granularity calc
	loop: Fix ABBA locking race
	loop: refactor queue limits updates
	loop: factor out a loop_assign_backing_file helper
	loop: Add sanity check for read/write_iter
	drm/panel: simple: Update timings for AUO G101EVN010
	nvme: unblock ctrl state transition for firmware update
	riscv: misaligned: factorize trap handling
	riscv: misaligned: enable IRQs while handling misaligned accesses
	drm/xe/tests/mocs: Update xe_force_wake_get() return handling
	drm/xe/tests/mocs: Hold XE_FORCEWAKE_ALL for LNCF regs
	io_uring/sqpoll: Increase task_work submission batch size
	do_umount(): add missing barrier before refcount checks in sync case
	Revert "um: work around sched_yield not yielding in time-travel mode"
	rust: allow Rust 1.87.0's `clippy::ptr_eq` lint
	rust: clean Rust 1.88.0's `clippy::uninlined_format_args` lint
	io_uring: always arm linked timeouts prior to issue
	Bluetooth: btmtk: Remove resetting mt7921 before downloading the fw
	Bluetooth: btmtk: Remove the resetting step before downloading the fw
	mm: page_alloc: don't steal single pages from biggest buddy
	mm: page_alloc: speed up fallbacks in rmqueue_bulk()
	sched/eevdf: Fix se->slice being set to U64_MAX and resulting crash
	arm64: insn: Add support for encoding DSB
	arm64: proton-pack: Expose whether the platform is mitigated by firmware
	arm64: proton-pack: Expose whether the branchy loop k value
	arm64: bpf: Add BHB mitigation to the epilogue for cBPF programs
	arm64: bpf: Only mitigate cBPF programs loaded by unprivileged users
	arm64: proton-pack: Add new CPUs 'k' values for branch mitigation
	x86/bpf: Call branch history clearing sequence on exit
	x86/bpf: Add IBHF call at end of classic BPF
	x86/bhi: Do not set BHI_DIS_S in 32-bit mode
	x86/speculation: Simplify and make CALL_NOSPEC consistent
	x86/speculation: Add a conditional CS prefix to CALL_NOSPEC
	x86/speculation: Remove the extra #ifdef around CALL_NOSPEC
	Documentation: x86/bugs/its: Add ITS documentation
	x86/its: Enumerate Indirect Target Selection (ITS) bug
	x86/its: Add support for ITS-safe indirect thunk
	x86/its: Add support for ITS-safe return thunk
	x86/its: Enable Indirect Target Selection mitigation
	x86/its: Add "vmexit" option to skip mitigation on some CPUs
	x86/its: Add support for RSB stuffing mitigation
	x86/its: Align RETs in BHB clear sequence to avoid thunking
	x86/ibt: Keep IBT disabled during alternative patching
	x86/its: Use dynamic thunks for indirect branches
	selftest/x86/bugs: Add selftests for ITS
	x86/its: Fix build errors when CONFIG_MODULES=n
	x86/its: FineIBT-paranoid vs ITS
	Linux 6.12.29

Change-Id: I00ff9cc212474331d43028ec90a190dcd1dfa697
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2025-06-05 11:52:13 +00:00
Greg Kroah-Hartman
db596bb60e Merge 6.12.26 into android16-6.12-lts
GKI (arm64) relevant 69 out of 278 changes, affecting 88 files +585/-290
  0b603e7759 tracing: Add __print_dynamic_array() helper [3 files, +15/-1]
  0312735402 tracing: Verify event formats that have "%*p.." [2 files, +13/-2]
  1c9798bf81 mm/vmscan: don't try to reclaim hwpoison folio [1 file, +7/-0]
  db3b3964af PM: EM: use kfree_rcu() to simplify the code [1 file, +1/-9]
  9d5752b853 PM: EM: Address RCU-related sparse warnings [2 files, +26/-25]
  3e12e8c273 block: remove the write_hint field from struct request [4 files, +13/-12]
  ed7535b141 block: remove the ioprio field from struct request [4 files, +11/-15]
  2afa5ea7c4 block: make sure ->nr_integrity_segments is cloned in blk_rq_prep_clone [1 file, +1/-0]
  46d3575209 PCI/MSI: Handle the NOMASK flag correctly for all PCI/MSI backends [1 file, +6/-12]
  35ba7b2d4d PCI/MSI: Add an option to write MSIX ENTRY_DATA before any reads [2 files, +5/-0]
  16c8aa5de1 dma/contiguous: avoid warning about unused size_bytes [1 file, +1/-2]
  7ccfadfb25 cpufreq: scmi: Fix null-ptr-deref in scmi_cpufreq_get_rate() [1 file, +8/-2]
  28fbd7b13b cpufreq: scpi: Fix null-ptr-deref in scpi_cpufreq_get_rate() [1 file, +10/-3]
  7d002f5914 scsi: ufs: mcq: Add NULL check in ufshcd_mcq_abort() [1 file, +5/-7]
  5d92e582d1 cgroup/cpuset-v1: Add missing support for cpuset_v2_mode [1 file, +29/-0]
  29daa63f2c scsi: core: Clear flags for scsi_cmnd that did not complete [1 file, +5/-1]
  eeab661803 scsi: ufs: core: Add NULL check in ufshcd_mcq_compl_pending_transfer() [1 file, +2/-0]
  41143e7105 net: phy: leds: fix memory leak [1 file, +13/-10]
  0ceef62a32 tipc: fix NULL pointer dereference in tipc_mon_reinit_self() [1 file, +2/-1]
  a61afd5482 fix a couple of races in MNT_TREE_BENEATH handling by do_move_mount() [1 file, +36/-33]
  7f24ea6a46 block: never reduce ra_pages in blk_apply_bdi_limits [1 file, +7/-1]
  3decda1a3c splice: remove duplicate noinline from pipe_clear_nowait [1 file, +1/-1]
  30c0d6e778 virtio_console: fix missing byte order handling for cols and rows [1 file, +4/-3]
  c2a6b4d78c net: selftests: initialize TCP header and skb payload with zero [1 file, +13/-5]
  3939d6f29d irqchip/gic-v2m: Prevent use after free of gicv2m_get_fwnode() [1 file, +1/-1]
  7a8a6b627f io_uring: fix 'sync' handling of io_fallback_tw() [1 file, +7/-6]
  1f439fe4d8 scsi: Improve CDL control [1 file, +24/-12]
  3670dee376 char: misc: register chrdev region with all possible minors [1 file, +1/-1]
  ea0d806b94 USB: serial: ftdi_sio: add support for Abacus Electrics Optical Probe [2 files, +7/-0]
  1777714865 xhci: Limit time spent with xHC interrupts disabled during bus resume [3 files, +20/-16]
  bce3055b08 usb: xhci: Fix invalid pointer dereference in Etron workaround [1 file, +1/-1]
  52a7c9d930 usb: dwc3: gadget: check that event count does not exceed event buffer length [1 file, +6/-0]
  9924ee1bcd usb: quirks: add DELAY_INIT quirk for Silicon Motion Flash Drive [1 file, +3/-0]
  d85b7af3bd usb: quirks: Add delay init quirk for SanDisk 3.2Gen1 Flash Drive [1 file, +3/-0]
  3e52ae347e USB: VLI disk crashes if LPM is used [1 file, +3/-0]
  0486de3c1b crypto: null - Use spin lock instead of mutex [1 file, +26/-13]
  7758e308ae bpf: Fix kmemleak warning for percpu hashmap [1 file, +3/-3]
  c5c833f637 bpf: Fix deadlock between rcu_tasks_trace and event_mutex. [1 file, +4/-3]
  4139072087 clk: check for disabled clock-provider in of_clk_get_hw_from_clkspec() [1 file, +4/-0]
  4131411f42 bpf: Only fails the busy counter check in bpf_cgrp_storage_get if it creates storage [1 file, +6/-5]
  b817d2bfd6 bpf: Reject attaching fexit/fmod_ret to __noreturn functions [1 file, +32/-0]
  2ecae00138 usb: dwc3: gadget: Refactor loop to avoid NULL endpoints [1 file, +18/-4]
  cbfa55bda1 usb: xhci: Complete 'error mid TD' transfers when handling Missed Service [1 file, +5/-1]
  16a7a8e6c4 usb: xhci: Fix isochronous Ring Underrun/Overrun event handling [1 file, +14/-6]
  635be13606 xhci: Handle spurious events on Etron host isoc enpoints [2 files, +27/-13]
  9ff59cb815 usb: xhci: Avoid Stop Endpoint retry loop if the endpoint seems Running [1 file, +7/-4]
  0485bdf88f objtool, panic: Disable SMAP in __stack_chk_fail() [2 files, +10/-1]
  c548f95688 9p/net: fix improper handling of bogus negative read/write replies [1 file, +16/-14]
  18296b5951 9p/trans_fd: mark concurrent read and writes to p9_conn->err [1 file, +10/-7]
  3568fd9e44 io_uring: always do atomic put from iowq [2 files, +8/-1]
  90dc6c1e3b perf/core: Fix WARN_ON(!ctx) in __free_event() for partial init [1 file, +3/-3]
  24ede35eb2 nvme: requeue namespace scan on missed AENs [1 file, +4/-0]
  b9c89c97d7 nvme: re-read ANA log page after ns scan completes [1 file, +5/-0]
  ee5521176a nvme: multipath: fix return value of nvme_available_path [1 file, +1/-1]
  5e58b93a12 gpiolib: of: Move Atmel HSMCI quirk up out of the regulator comment [1 file, +3/-3]
  9f8eeac3a6 timekeeping: Add a lockdep override in tick_freeze() [1 file, +22/-0]
  b14d986413 iommu: Clear iommu-dma ops on cleanup [1 file, +3/-0]
  b626bc3c1d ext4: make block validity check resistent to sb bh corruption [2 files, +6/-6]
  2ef6eea2ef netfs: Only create /proc/fs/netfs with CONFIG_PROC_FS [1 file, +4/-0]
  d53b2d49a8 iomap: skip unnecessary ifs_block_is_uptodate check [1 file, +1/-1]
  bfc66c4c28 Revert "drivers: core: synchronize really_probe() and dev_uevent()" [1 file, +0/-3]
  de7c24febd usb: typec: class: Fix NULL pointer access [2 files, +14/-2]
  45314999f9 ext4: goto right label 'out_mmap_sem' in ext4_setattr() [1 file, +1/-1]
  40966fc993 usb: typec: class: Invalidate USB device pointers on partner unregistration [1 file, +6/-2]
  4833d0a92b iommu: Handle race with default domain setup [1 file, +5/-0]
  1042d22942 nvme: fixup scan failure for non-ANA multipath controllers [1 file, +1/-1]
  1b7647efad usb: xhci: Fix Short Packet handling rework ignoring errors [1 file, +1/-1]
  ab5281d21e usb: typec: class: Unlocked on error in typec_register_partner() [1 file, +1/-0]
  6b9ebcbd31 mq-deadline: don't call req_get_ioprio from the I/O completion handler [1 file, +4/-9]

Changes in 6.12.26
	module: sign with sha512 instead of sha1 by default
	tracing: Add __print_dynamic_array() helper
	tracing: Verify event formats that have "%*p.."
	mm/vmscan: don't try to reclaim hwpoison folio
	soc: qcom: ice: introduce devm_of_qcom_ice_get
	mmc: sdhci-msm: fix dev reference leaked through of_qcom_ice_get
	PM: EM: use kfree_rcu() to simplify the code
	PM: EM: Address RCU-related sparse warnings
	media: i2c: imx214: Use subdev active state
	media: i2c: imx214: Simplify with dev_err_probe()
	media: i2c: imx214: Convert to CCI register access helpers
	media: i2c: imx214: Replace register addresses with macros
	media: i2c: imx214: Check number of lanes from device tree
	media: i2c: imx214: Fix link frequency validation
	media: ov08x40: Move ov08x40_identify_module() function up
	media: ov08x40: Add missing ov08x40_identify_module() call on stream-start
	block: remove the write_hint field from struct request
	block: remove the ioprio field from struct request
	block: make sure ->nr_integrity_segments is cloned in blk_rq_prep_clone
	net: dsa: mv88e6xxx: fix VTU methods for 6320 family
	iio: adc: ad7768-1: Move setting of val a bit later to avoid unnecessary return value check
	iio: adc: ad7768-1: Fix conversion result sign
	arm64: dts: ti: Refactor J784s4 SoC files to a common file
	arm64: dts: ti: k3-j784s4-j742s2-main-common: Fix serdes_ln_ctrl reg-masks
	of: resolver: Simplify of_resolve_phandles() using __free()
	of: resolver: Fix device node refcount leakage in of_resolve_phandles()
	scsi: ufs: qcom: fix dev reference leaked through of_qcom_ice_get
	PCI/MSI: Convert pci_msi_ignore_mask to per MSI domain flag
	PCI/MSI: Handle the NOMASK flag correctly for all PCI/MSI backends
	PCI/MSI: Add an option to write MSIX ENTRY_DATA before any reads
	accel/ivpu: Add auto selection logic for job scheduler
	accel/ivpu: Fix the NPU's DPU frequency calculation
	ksmbd: use __GFP_RETRY_MAYFAIL
	ksmbd: add netdev-up/down event debug print
	ksmbd: browse interfaces list on FSCTL_QUERY_INTERFACE_INFO IOCTL
	ksmbd: fix use-after-free in __smb2_lease_break_noti()
	scsi: ufs: exynos: Remove empty drv_init method
	scsi: ufs: exynos: Remove superfluous function parameter
	scsi: ufs: exynos: Add gs101_ufs_drv_init() hook and enable WriteBooster
	scsi: ufs: exynos: Move UFS shareability value to drvdata
	scsi: ufs: exynos: Disable iocc if dma-coherent property isn't set
	net/niu: Niu requires MSIX ENTRY_DATA fields touch before entry reads
	drm/xe/bmg: Add one additional PCI ID
	drm/amd/display: Fix unnecessary cast warnings from checkpatch
	drm/amd/display/dml2: use vzalloc rather than kzalloc
	lib/Kconfig.ubsan: Remove 'default UBSAN' from UBSAN_INTEGER_WRAP
	ceph: Fix incorrect flush end position calculation
	cpufreq: sun50i: prevent out-of-bounds access
	dma/contiguous: avoid warning about unused size_bytes
	cpufreq: apple-soc: Fix null-ptr-deref in apple_soc_cpufreq_get_rate()
	cpufreq: scmi: Fix null-ptr-deref in scmi_cpufreq_get_rate()
	cpufreq: scpi: Fix null-ptr-deref in scpi_cpufreq_get_rate()
	scsi: ufs: mcq: Add NULL check in ufshcd_mcq_abort()
	cpufreq: cppc: Fix invalid return value in .get() callback
	cpufreq: Do not enable by default during compile testing
	cpufreq: fix compile-test defaults
	btrfs: avoid page_lockend underflow in btrfs_punch_hole_lock_range()
	btrfs: zoned: return EIO on RAID1 block group write pointer mismatch
	cgroup/cpuset-v1: Add missing support for cpuset_v2_mode
	vhost-scsi: Add better resource allocation failure handling
	vhost-scsi: Fix vhost_scsi_send_bad_target()
	vhost-scsi: Fix vhost_scsi_send_status()
	net/mlx5: Fix null-ptr-deref in mlx5_create_{inner_,}ttc_table()
	net/mlx5: Move ttc allocation after switch case to prevent leaks
	scsi: core: Clear flags for scsi_cmnd that did not complete
	scsi: ufs: core: Add NULL check in ufshcd_mcq_compl_pending_transfer()
	net: lwtunnel: disable BHs when required
	net: phy: leds: fix memory leak
	tipc: fix NULL pointer dereference in tipc_mon_reinit_self()
	net: ethernet: mtk_eth_soc: net: revise NETSYSv3 hardware configuration
	fix a couple of races in MNT_TREE_BENEATH handling by do_move_mount()
	net_sched: hfsc: Fix a UAF vulnerability in class handling
	net_sched: hfsc: Fix a potential UAF in hfsc_dequeue() too
	net: dsa: mt7530: sync driver-specific behavior of MT7531 variants
	pds_core: Prevent possible adminq overflow/stuck condition
	pds_core: handle unsupported PDS_CORE_CMD_FW_CONTROL result
	pds_core: Remove unnecessary check in pds_client_adminq_cmd()
	pds_core: make wait_context part of q_info
	block: never reduce ra_pages in blk_apply_bdi_limits
	iommu/amd: Return an error if vCPU affinity is set for non-vCPU IRTE
	riscv: Replace function-like macro by static inline function
	riscv: uprobes: Add missing fence.i after building the XOL buffer
	splice: remove duplicate noinline from pipe_clear_nowait
	bpf: Add namespace to BPF internal symbols
	perf/x86: Fix non-sampling (counting) events on certain x86 platforms
	LoongArch: Select ARCH_USE_MEMTEST
	LoongArch: Make regs_irqs_disabled() more clear
	LoongArch: Make do_xyz() exception handlers more robust
	KVM: SVM: Disable AVIC on SNP-enabled system without HvInUseWrAllowed feature
	netfilter: fib: avoid lookup if socket is available
	virtio_console: fix missing byte order handling for cols and rows
	sched_ext: Use kvzalloc for large exit_dump allocation
	crypto: atmel-sha204a - Set hwrng quality to lowest possible
	xen-netfront: handle NULL returned by xdp_convert_buff_to_frame()
	net: selftests: initialize TCP header and skb payload with zero
	net: phy: microchip: force IRQ polling mode for lan88xx
	scsi: mpi3mr: Fix pending I/O counter
	rust: firmware: Use `ffi::c_char` type in `FwFunc`
	drm: panel: jd9365da: fix reset signal polarity in unprepare
	drm/amd/display: Fix gpu reset in multidisplay config
	drm/amd/display: Force full update in gpu reset
	x86/insn: Fix CTEST instruction decoding
	irqchip/gic-v2m: Prevent use after free of gicv2m_get_fwnode()
	LoongArch: Handle fp, lsx, lasx and lbt assembly symbols
	LoongArch: Return NULL from huge_pte_offset() for invalid PMD
	LoongArch: Remove a bogus reference to ZONE_DMA
	LoongArch: KVM: Fully clear some CSRs when VM reboot
	LoongArch: KVM: Fix PMU pass-through issue if VM exits to host finally
	io_uring: fix 'sync' handling of io_fallback_tw()
	KVM: SVM: Allocate IR data using atomic allocation
	cxl/core/regs.c: Skip Memory Space Enable check for RCD and RCH Ports
	mcb: fix a double free bug in chameleon_parse_gdd()
	ata: libata-scsi: Improve CDL control
	ata: libata-scsi: Fix ata_mselect_control_ata_feature() return type
	ata: libata-scsi: Fix ata_msense_control_ata_feature()
	USB: storage: quirk for ADATA Portable HDD CH94
	scsi: Improve CDL control
	mei: me: add panther lake H DID
	mei: vsc: Fix fortify-panic caused by invalid counted_by() use
	KVM: x86: Explicitly treat routing entry type changes as changes
	KVM: x86: Reset IRTE to host control if *new* route isn't postable
	KVM: x86: Take irqfds.lock when adding/deleting IRQ bypass producer
	char: misc: register chrdev region with all possible minors
	misc: microchip: pci1xxxx: Fix Kernel panic during IRQ handler registration
	misc: microchip: pci1xxxx: Fix incorrect IRQ status handling during ack
	firmware: stratix10-svc: Add of_platform_default_populate()
	tty: Require CAP_SYS_ADMIN for all usages of TIOCL_SELMOUSEREPORT
	serial: msm: Configure correct working mode before starting earlycon
	serial: sifive: lock port in startup()/shutdown() callbacks
	USB: serial: ftdi_sio: add support for Abacus Electrics Optical Probe
	USB: serial: option: add Sierra Wireless EM9291
	USB: serial: simple: add OWON HDS200 series oscilloscope support
	xhci: Limit time spent with xHC interrupts disabled during bus resume
	usb: xhci: Fix invalid pointer dereference in Etron workaround
	usb: cdns3: Fix deadlock when using NCM gadget
	usb: chipidea: ci_hdrc_imx: fix usbmisc handling
	usb: chipidea: ci_hdrc_imx: fix call balance of regulator routines
	usb: chipidea: ci_hdrc_imx: implement usb_phy_init() error handling
	USB: OHCI: Add quirk for LS7A OHCI controller (rev 0x02)
	usb: dwc3: gadget: check that event count does not exceed event buffer length
	usb: dwc3: xilinx: Prevent spike in reset signal
	usb: quirks: add DELAY_INIT quirk for Silicon Motion Flash Drive
	usb: quirks: Add delay init quirk for SanDisk 3.2Gen1 Flash Drive
	USB: VLI disk crashes if LPM is used
	USB: wdm: handle IO errors in wdm_wwan_port_start
	USB: wdm: close race between wdm_open and wdm_wwan_port_stop
	USB: wdm: wdm_wwan_port_tx_complete mutex in atomic context
	USB: wdm: add annotation
	selftests/bpf: Fix stdout race condition in traffic monitor
	pinctrl: renesas: rza2: Fix potential NULL pointer dereference
	pinctrl: mcp23s08: Get rid of spurious level interrupts
	MIPS: cm: Detect CM quirks from device tree
	crypto: ccp - Add support for PCI device 0x1134
	crypto: lib/Kconfig - Fix lib built-in failure when arch is modular
	crypto: null - Use spin lock instead of mutex
	bpf: Fix kmemleak warning for percpu hashmap
	bpf: Fix deadlock between rcu_tasks_trace and event_mutex.
	clk: check for disabled clock-provider in of_clk_get_hw_from_clkspec()
	parisc: PDT: Fix missing prototype warning
	s390/sclp: Add check for get_zeroed_page()
	s390/tty: Fix a potential memory leak bug
	bpf: bpftool: Setting error code in do_loader()
	bpf: Only fails the busy counter check in bpf_cgrp_storage_get if it creates storage
	bpf: Reject attaching fexit/fmod_ret to __noreturn functions
	mailbox: pcc: Fix the possible race in updation of chan_in_use flag
	mailbox: pcc: Always clear the platform ack interrupt first
	usb: host: max3421-hcd: Add missing spi_device_id table
	fs/ntfs3: Keep write operations atomic
	fs/ntfs3: Fix WARNING in ntfs_extend_initialized_size
	usb: dwc3: gadget: Refactor loop to avoid NULL endpoints
	usb: dwc3: gadget: Avoid using reserved endpoints on Intel Merrifield
	sound/virtio: Fix cancel_sync warnings on uninitialized work_structs
	usb: xhci: Complete 'error mid TD' transfers when handling Missed Service
	usb: xhci: Fix isochronous Ring Underrun/Overrun event handling
	xhci: Handle spurious events on Etron host isoc enpoints
	i3c: master: svc: Add support for Nuvoton npcm845 i3c
	dmaengine: dmatest: Fix dmatest waiting less when interrupted
	usb: xhci: Avoid Stop Endpoint retry loop if the endpoint seems Running
	phy: rockchip: usbdp: Avoid call hpd_event_trigger in dp_phy_init
	usb: gadget: aspeed: Add NULL pointer check in ast_vhub_init_dev()
	usb: host: xhci-plat: mvebu: use ->quirks instead of ->init_quirk() func
	thunderbolt: Scan retimers after device router has been enumerated
	um: work around sched_yield not yielding in time-travel mode
	objtool: Silence more KCOV warnings
	objtool, panic: Disable SMAP in __stack_chk_fail()
	objtool, ASoC: codecs: wcd934x: Remove potential undefined behavior in wcd934x_slim_irq_handler()
	objtool, regulator: rk808: Remove potential undefined behavior in rk806_set_mode_dcdc()
	objtool, lkdtm: Obfuscate the do_nothing() pointer
	qibfs: fix _another_ leak
	ntb: reduce stack usage in idt_scan_mws
	ntb_hw_amd: Add NTB PCI ID for new gen CPU
	9p/net: fix improper handling of bogus negative read/write replies
	9p/trans_fd: mark concurrent read and writes to p9_conn->err
	rtc: pcf85063: do a SW reset if POR failed
	io_uring: always do atomic put from iowq
	kbuild: add dependency from vmlinux to sorttable
	sched/isolation: Make CONFIG_CPU_ISOLATION depend on CONFIG_SMP
	KVM: s390: Don't use %pK through tracepoints
	KVM: s390: Don't use %pK through debug printing
	cgroup/cpuset: Don't allow creation of local partition over a remote one
	selftests: ublk: fix test_stripe_04
	perf/core: Fix WARN_ON(!ctx) in __free_event() for partial init
	xen: Change xen-acpi-processor dom0 dependency
	nvme: requeue namespace scan on missed AENs
	ACPI: EC: Set ec_no_wakeup for Lenovo Go S
	ACPI PPTT: Fix coding mistakes in a couple of sizeof() calls
	drm/amdgpu: Increase KIQ invalidate_tlbs timeout
	drm/xe/xe3lpg: Apply Wa_14022293748, Wa_22019794406
	nvme: re-read ANA log page after ns scan completes
	nvme: multipath: fix return value of nvme_available_path
	objtool: Stop UNRET validation on UD2
	gpiolib: of: Move Atmel HSMCI quirk up out of the regulator comment
	x86/xen: disable CPU idle and frequency drivers for PVH dom0
	selftests/mincore: Allow read-ahead pages to reach the end of the file
	x86/bugs: Use SBPB in write_ibpb() if applicable
	x86/bugs: Don't fill RSB on VMEXIT with eIBRS+retpoline
	x86/bugs: Don't fill RSB on context switch with eIBRS
	nvmet-fc: take tgtport reference only once
	nvmet-fc: put ref when assoc->del_work is already scheduled
	cifs: Fix encoding of SMB1 Session Setup Kerberos Request in non-UNICODE mode
	timekeeping: Add a lockdep override in tick_freeze()
	cifs: Fix querying of WSL CHR and BLK reparse points over SMB1
	iommu: Clear iommu-dma ops on cleanup
	ext4: make block validity check resistent to sb bh corruption
	scsi: hisi_sas: Fix I/O errors caused by hardware port ID changes
	scsi: ufs: exynos: Ensure pre_link() executes before exynos_ufs_phy_init()
	scsi: ufs: exynos: Enable PRDT pre-fetching with UFSHCD_CAP_CRYPTO
	scsi: ufs: exynos: Move phy calls to .exit() callback
	scsi: ufs: exynos: gs101: Put UFS device in reset on .suspend()
	scsi: pm80xx: Set phy_attached to zero when device is gone
	ASoC: fsl_asrc_dma: get codec or cpu dai from backend
	x86/i8253: Call clockevent_i8253_disable() with interrupts disabled
	netfs: Only create /proc/fs/netfs with CONFIG_PROC_FS
	iomap: skip unnecessary ifs_block_is_uptodate check
	riscv: Provide all alternative macros all the time
	ksmbd: fix WARNING "do not call blocking ops when !TASK_RUNNING"
	spi: tegra210-quad: use WARN_ON_ONCE instead of WARN_ON for timeouts
	spi: tegra210-quad: add rate limiting and simplify timeout error message
	ubsan: Fix panic from test_ubsan_out_of_bounds
	x86/cpu: Add CPU model number for Bartlett Lake CPUs with Raptor Cove cores
	md/raid1: Add check for missing source disk in process_checks()
	drm/amdgpu: use a dummy owner for sysfs triggered cleaner shaders v4
	drm/amdgpu: Use the right function for hdp flush
	spi: spi-imx: Add check for spi_imx_setupxfer()
	Revert "drivers: core: synchronize really_probe() and dev_uevent()"
	driver core: introduce device_set_driver() helper
	driver core: fix potential NULL pointer dereference in dev_uevent()
	xfs: do not check NEEDSREPAIR if ro,norecovery mount.
	xfs: Do not allow norecovery mount with quotacheck
	xfs: rename xfs_iomap_swapfile_activate to xfs_vm_swap_activate
	xfs: flush inodegc before swapon
	selftests/bpf: fix bpf_map_redirect call for cpu map test
	selftests/bpf: make xdp_cpumap_attach keep redirect prog attached
	selftests/bpf: check program redirect in xdp_cpumap_attach
	selftests/bpf: Adjust data size to have ETH_HLEN
	usb: typec: class: Fix NULL pointer access
	vmxnet3: Fix malformed packet sizing in vmxnet3_process_xdp
	comedi: jr3_pci: Fix synchronous deletion of timer
	ext4: goto right label 'out_mmap_sem' in ext4_setattr()
	usb: typec: class: Invalidate USB device pointers on partner unregistration
	Revert "net: dsa: mv88e6xxx: fix internal PHYs for 6320 family"
	net: dsa: mv88e6xxx: fix atu_move_port_mask for 6341 family
	net: dsa: mv88e6xxx: enable PVT for 6321 switch
	net: dsa: mv88e6xxx: enable .port_set_policy() for 6320 family
	net: dsa: mv88e6xxx: enable STU methods for 6320 family
	iommu: Handle race with default domain setup
	crypto: lib/Kconfig - Hide arch options from user
	media: i2c: imx214: Fix uninitialized variable in imx214_set_ctrl()
	MIPS: cm: Fix warning if MIPS_CM is disabled
	nvme: fixup scan failure for non-ANA multipath controllers
	usb: xhci: Fix Short Packet handling rework ignoring errors
	objtool: Ignore end-of-section jumps for KCOV/GCOV
	objtool: Silence more KCOV warnings, part 2
	usb: typec: class: Unlocked on error in typec_register_partner()
	crypto: Kconfig - Select LIB generic option
	arm64: dts: ti: k3-j784s4-j742s2-main-common: Correct the GICD size
	mq-deadline: don't call req_get_ioprio from the I/O completion handler
	Linux 6.12.26

Change-Id: Iff5be8c388b8b915652fafb787156a4653f060aa
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
2025-05-20 16:37:12 +00:00
Miguel Ojeda
6b0383a21d rust: clean Rust 1.88.0's clippy::uninlined_format_args lint
commit 211dcf77856db64c73e0c3b9ce0c624ec855daca upstream.

Starting with Rust 1.88.0 (expected 2025-06-26) [1], `rustc` may move
back the `uninlined_format_args` to `style` from `pedantic` (it was
there waiting for rust-analyzer suppotr), and thus we will start to see
lints like:

    warning: variables can be used directly in the `format!` string
       --> rust/macros/kunit.rs:105:37
        |
    105 |         let kunit_wrapper_fn_name = format!("kunit_rust_wrapper_{}", test);
        |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
        |
    105 -         let kunit_wrapper_fn_name = format!("kunit_rust_wrapper_{}", test);
    105 +         let kunit_wrapper_fn_name = format!("kunit_rust_wrapper_{test}");

There is even a case that is a pure removal:

    warning: variables can be used directly in the `format!` string
      --> rust/macros/module.rs:51:13
       |
    51 |             format!("{field}={content}\0", field = field, content = content)
       |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
    help: change this to
       |
    51 -             format!("{field}={content}\0", field = field, content = content)
    51 +             format!("{field}={content}\0")

The lints all seem like nice cleanups, thus just apply them.

We may want to disable `allow-mixed-uninlined-format-args` in the future.

Cc: stable@vger.kernel.org # Needed in 6.12.y and later (Rust is pinned in older LTSs).
Link: https://github.com/rust-lang/rust-clippy/pull/14160 [1]
Acked-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Tamir Duberstein <tamird@gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20250502140237.1659624-6-ojeda@kernel.org
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-05-18 08:24:57 +02:00
Miguel Ojeda
1c25723831 rust: allow Rust 1.87.0's clippy::ptr_eq lint
commit a39f3087092716f2bd531d6fdc20403c3dc2a879 upstream.

Starting with Rust 1.87.0 (expected 2025-05-15) [1], Clippy may expand
the `ptr_eq` lint, e.g.:

    error: use `core::ptr::eq` when comparing raw pointers
       --> rust/kernel/list.rs:438:12
        |
    438 |         if self.first == item {
        |            ^^^^^^^^^^^^^^^^^^ help: try: `core::ptr::eq(self.first, item)`
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_eq
        = note: `-D clippy::ptr-eq` implied by `-D warnings`
        = help: to override `-D warnings` add `#[allow(clippy::ptr_eq)]`

It is expected that a PR to relax the lint will be backported [2] by
the time Rust 1.87.0 releases, since the lint was considered too eager
(at least by default) [3].

Thus allow the lint temporarily just in case.

Cc: stable@vger.kernel.org # Needed in 6.12.y and later (Rust is pinned in older LTSs).
Link: https://github.com/rust-lang/rust-clippy/pull/14339 [1]
Link: https://github.com/rust-lang/rust-clippy/pull/14526 [2]
Link: https://github.com/rust-lang/rust-clippy/issues/14525 [3]
Link: https://lore.kernel.org/r/20250502140237.1659624-3-ojeda@kernel.org
[ Converted to `allow`s since backport was confirmed. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2025-05-18 08:24:57 +02:00
Alice Ryhl
bf40001347 ANDROID: rust_binder: add back tracepoints
Tracepoints were removed from the the vendor module version of Rust
Binder as it required either fixing b/394605825 or hard-coding the
tracepoint declarations as created by bindgen.

As we are moving Rust Binder back into common/, this no longer depends
on invoking bindgen from the DDK. Thus, revert these changes.

Bug: 394605825
Bug: 388786466
Change-Id: I81fe5b2b4c92826c6478606cd78c8fccd8a5c7e4
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
Alice Ryhl
8313296331 FROMGIT: rust: alloc: add Vec::insert_within_capacity
This adds a variant of Vec::insert that does not allocate memory. This
makes it safe to use this function while holding a spinlock. Rust Binder
uses it for the range allocator fast path.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Link: https://lore.kernel.org/r/20250502-vec-methods-v5-7-06d20ad9366f@google.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Bug: 414994413
(cherry picked from commit 771c5a7d9843643b035938624050e7769133b9cc
 https://github.com/Rust-for-Linux/linux.git alloc-next)
Change-Id: I5661d5ee9ff239a92c4a640e334ad6d60196ad25
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
Alice Ryhl
c28afde01d FROMGIT: rust: alloc: add Vec::remove
This is needed by Rust Binder in the range allocator, and by upcoming
GPU drivers during firmware initialization.

Panics in the kernel are best avoided when possible, so an error is
returned if the index is out of bounds. An error type is used rather
than just returning Option<T> to let callers handle errors with ?.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Link: https://lore.kernel.org/r/20250502-vec-methods-v5-6-06d20ad9366f@google.com
[ Remove `# Panics` section; `Vec::remove() handles the error properly.`
  - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Bug: 414994413
(cherry picked from commit 294a7ecbdf0a5d65c6df1287c5d56241e9331cf2
 https://github.com/Rust-for-Linux/linux.git alloc-next)
Change-Id: I80a8925910f234cccd325614634aa8a12e85ea1c
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
Alice Ryhl
e1da60354a FROMGIT: rust: alloc: add Vec::retain
This adds a common Vec method called `retain` that removes all elements
that don't match a certain condition. Rust Binder uses it to find all
processes that match a given pid.

The stdlib retain method takes &T rather than &mut T and has a separate
retain_mut for the &mut T case. However, this is considered an API
mistake that can't be fixed now due to backwards compatibility. There's
no reason for us to repeat that mistake.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Link: https://lore.kernel.org/r/20250502-vec-methods-v5-5-06d20ad9366f@google.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Bug: 414994413
(cherry picked from commit 9f140894e72735f034fdc0e963d0550ef03c6f44
 https://github.com/Rust-for-Linux/linux.git alloc-next)
Change-Id: I1a126b3a847142eaa90794789280abb91e000b58
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
Alice Ryhl
1e01dcf3be FROMGIT: rust: alloc: add Vec::drain_all
This is like the stdlib method drain, except that it's hard-coded to use
the entire vector's range. Rust Binder uses it in the range allocator to
take ownership of everything in a vector in a case where reusing the
vector is desirable.

Implementing `DrainAll` in terms of `slice::IterMut` lets us reuse some
nice optimizations in core for the case where T is a ZST.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Link: https://lore.kernel.org/r/20250502-vec-methods-v5-4-06d20ad9366f@google.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Bug: 414994413
(cherry picked from commit 088bf14a886e1e746c961a862ebccbb76d7cbd4e
 https://github.com/Rust-for-Linux/linux.git alloc-next)
Change-Id: I65ab0823980a15a0c18f960f9ab7ff6fa621c06a
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
Alice Ryhl
1a17ca097d FROMGIT: rust: alloc: add Vec::push_within_capacity
This introduces a new method called `push_within_capacity` for appending
to a vector without attempting to allocate if the capacity is full. Rust
Binder will use this in various places to safely push to a vector while
holding a spinlock.

The implementation is moved to a push_within_capacity_unchecked method.
This is preferred over having push() call push_within_capacity()
followed by an unwrap_unchecked() for simpler unsafe.

Panics in the kernel are best avoided when possible, so an error is
returned if the vector does not have sufficient capacity. An error type
is used rather than just returning Result<(),T> to make it more
convenient for callers (i.e. they can use ? or unwrap).

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Link: https://lore.kernel.org/r/20250502-vec-methods-v5-3-06d20ad9366f@google.com
[ Remove public visibility from `Vec::push_within_capacity_unchecked()`.
  - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Bug: 414994413
(cherry picked from commit 9def0d0a2a1c62d7970f4ce5ad5557968c98f637
 https://github.com/Rust-for-Linux/linux.git alloc-next)
Change-Id: Ib01be654536651a8189b28fddc9f8f332ffbcbfb
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
Alice Ryhl
75c0948156 FROMGIT: rust: alloc: add Vec::pop
This introduces a basic method that our custom Vec is missing. I expect
that it will be used in many places, but at the time of writing, Rust
Binder has six calls to Vec::pop.

Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Link: https://lore.kernel.org/r/20250502-vec-methods-v5-2-06d20ad9366f@google.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Bug: 414994413
(cherry picked from commit f2b4dd7093438e4884cb01a783212abfbc9cc40b
 https://github.com/Rust-for-Linux/linux.git alloc-next)
Change-Id: I81085d4a5fc7fe9377c3857e8f0adca8aabd8984
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
Alice Ryhl
ed2019e2c4 FROMGIT: rust: alloc: add Vec::clear
Our custom Vec type is missing the stdlib method `clear`, thus add it.
It will be used in the miscdevice sample.

Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Tamir Duberstein <tamird@gmail.com>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/r/20250502-vec-methods-v5-1-06d20ad9366f@google.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Bug: 414994413
(cherry picked from commit a1e4d5c9d708d7a0e7071015a120a4489404128f
 https://github.com/Rust-for-Linux/linux.git alloc-next)
Change-Id: If3e0171d6b2298807dbf7abc36f110a5457ff4f9
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
Tamir Duberstein
04d685ecf9 FROMGIT: rust: alloc: replace Vec::set_len with inc_len
Rename `set_len` to `inc_len` and simplify its safety contract.

Note that the usage in `CString::try_from_fmt` remains correct as the
receiver is known to have `len == 0`.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
Link: https://lore.kernel.org/r/20250416-vec-set-len-v4-4-112b222604cd@gmail.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Bug: 414994413
(cherry picked from commit 88d5d6a38d5161228fbfe017eb94d777d5e8a0e4
 https://github.com/Rust-for-Linux/linux.git alloc-next)
Change-Id: If8c9311fed95246e2329818589e0c9104d5d0685
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
Tamir Duberstein
597ebe7c32 FROMGIT: rust: alloc: refactor Vec::truncate using dec_len
Use `checked_sub` to satisfy the safety requirements of `dec_len` and
replace nearly the whole body of `truncate` with a call to `dec_len`.

Reviewed-by: Andrew Ballance <andrewjballance@gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
Link: https://lore.kernel.org/r/20250416-vec-set-len-v4-3-112b222604cd@gmail.com
[ Remove #[expect(unused)] from dec_len(). - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Bug: 414994413
(cherry picked from commit 1b04b466c873f62413bf65a05a558f036660aedc
 https://github.com/Rust-for-Linux/linux.git alloc-next)
Change-Id: I7b1137306936289037bd315d32bb4ca893d38419
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
Tamir Duberstein
8a1546ee71 FROMGIT: rust: alloc: add Vec::dec_len
Add `Vec::dec_len` that reduces the length of the receiver. This method
is intended to be used from methods that remove elements from `Vec` such
as `truncate`, `pop`, `remove`, and others. This method is intentionally
not `pub`.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
Link: https://lore.kernel.org/r/20250416-vec-set-len-v4-2-112b222604cd@gmail.com
[ Add #[expect(unused)] to dec_len(). - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Bug: 414994413
(cherry picked from commit dbb0b840a0cd2ebabbc94a0040e366c7f1a70f7b
 https://github.com/Rust-for-Linux/linux.git alloc-next)
Change-Id: I14c7692950758094895ee7376568f6c89c73e852
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
Tamir Duberstein
48080570b0 FROMGIT: rust: alloc: add Vec::len() <= Vec::capacity invariant
Document the invariant that the vector's length is always less than or
equal to its capacity. This is already implied by these other
invariants:

- `self.len` always represents the exact number of elements stored in
  the vector.
- `self.layout` represents the absolute number of elements that can be
  stored within the vector without re-allocation.

but it doesn't hurt to spell it out. Note that the language references
`self.capacity` rather than `self.layout.len` as the latter is zero for
a vector of ZSTs.

Update a safety comment touched by this patch to correctly reference
`realloc` rather than `alloc` and replace "leaves" with "leave" to
improve grammar.

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
Link: https://lore.kernel.org/r/20250416-vec-set-len-v4-1-112b222604cd@gmail.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Bug: 414994413
(cherry picked from commit 47a17a63f9e23f7e8f39d0965bcda8fee6c322f8
 https://github.com/Rust-for-Linux/linux.git alloc-next)
Change-Id: Ie6a0d80271a65126b37d50c525a3757fcedb0a38
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
Alexandre Courbot
7907fdcba6 FROMGIT: rust: alloc: allow coercion from Box<T> to Box<dyn U> if T implements U
This enables the creation of trait objects backed by a Box, similarly to
what can be done with the standard library.

Suggested-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Signed-off-by: Alexandre Courbot <acourbot@nvidia.com>
Link: https://lore.kernel.org/r/20250412-box_trait_objs-v3-1-f67ced62d520@nvidia.com
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Bug: 414994413
(cherry picked from commit 85f8e98dbb0135d2bc1999c6015cd374fe2c69fa
 https://github.com/Rust-for-Linux/linux.git alloc-next)
Change-Id: I550e1c61e9fde0a6215de12d5f3d81da000f9338
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
Tamir Duberstein
9de29f7183 FROMGIT: rust: alloc: use spare_capacity_mut to reduce unsafe
Use `spare_capacity_mut` in the implementation of `push` to reduce the
use of `unsafe`. Both methods were added in commit 2aac4cd7dae3 ("rust:
alloc: implement kernel `Vec` type").

Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Link: https://lore.kernel.org/r/20250318-vec-push-use-spare-v3-1-68741671d1af@gmail.com
Signed-off-by: Tamir Duberstein <tamird@gmail.com>
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Bug: 414994413
(cherry picked from commit c3152988c047a7b6abb10d4dc5e24fafbabe8b7e
 https://github.com/Rust-for-Linux/linux.git alloc-next)
Change-Id: I01756699c6a7ee59ad4dfba8d700b25aae9143f8
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
Andrew Ballance
c40401d665 FROMGIT: rust: alloc: add Vec::resize method
Implement the equivalent of the rust std's Vec::resize on the kernel's
Vec type.

Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reviewed-by: Tamir Duberstein <tamird@gmail.com>
Link: https://lore.kernel.org/r/20250316111644.154602-3-andrewjballance@gmail.com
Signed-off-by: Andrew Ballance <andrewjballance@gmail.com>
[ Use checked_sub(), as suggested by Tamir. - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Bug: 414994413
(cherry picked from commit 1679b7159379d11100e4ab7d1de23c8cd7765aa1
 https://github.com/Rust-for-Linux/linux.git alloc-next)
Change-Id: I34b82e880ca6335038461be0de38fbb1a6854cba
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
Andrew Ballance
9d37907c65 FROMGIT: rust: alloc: add Vec::truncate method
Implement the equivalent to the std's Vec::truncate on the kernel's Vec
type.

Link: https://lore.kernel.org/r/20250316111644.154602-2-andrewjballance@gmail.com
Signed-off-by: Andrew Ballance <andrewjballance@gmail.com>
[ Rewrote safety comment of set_len(). - Danilo ]
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Bug: 414994413
(cherry picked from commit 81e1c4dab5d0c508907722f18b028102454d52e6
 https://github.com/Rust-for-Linux/linux.git alloc-next)
Change-Id: I466b7379d22f3c319acd9781da624b3751944a4f
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
Danilo Krummrich
f037ab7a73 FROMGIT: rust: alloc: add missing invariant in Vec::set_len()
When setting a new length, we have to justify that the set length
represents the exact number of elements stored in the vector.

Reviewed-by: Benno Lossin <benno.lossin@proton.me>
Reported-by: Alice Ryhl <aliceryhl@google.com>
Closes: https://lore.kernel.org/rust-for-linux/20250311-iov-iter-v1-4-f6c9134ea824@google.com
Fixes: 2aac4cd7dae3 ("rust: alloc: implement kernel `Vec` type")
Link: https://lore.kernel.org/r/20250315154436.65065-2-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>

Bug: 414994413
(cherry picked from commit fb1bf1067de979c89ae33589e0466d6ce0dde204
 https://github.com/Rust-for-Linux/linux.git alloc-next)
Change-Id: Ib9a4889aa2144197ce7da035e45f78520b12e397
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
José Expósito
025e0fc417 UPSTREAM: rust: kunit: allow to know if we are in a test
In some cases, we need to call test-only code from outside the test
case, for example, to mock a function or a module.

In order to check whether we are in a test or not, we need to test if
`CONFIG_KUNIT` is set.
Unfortunately, we cannot rely only on this condition because:
- a test could be running in another thread,
- some distros compile KUnit in production kernels, so checking at runtime
  that `current->kunit_test != NULL` is required.

Forturately, KUnit provides an optimised check in
`kunit_get_current_test()`, which checks CONFIG_KUNIT, a global static
key, and then the current thread's running KUnit test.

Add a safe wrapper function around this to know whether or not we are in
a KUnit test and examples showing how to mock a function and a module.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
Co-developed-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Co-developed-by: David Gow <davidgow@google.com>
Signed-off-by: David Gow <davidgow@google.com>
Link: https://lore.kernel.org/r/20250307090103.918788-4-davidgow@google.com
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Bug: 414994413
(cherry picked from commit 100af58c8d5822750ef9ba65f5d5ea3367c669de)
Change-Id: I2810872e70593e1bae0c259c495006beba14d1e3
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
José Expósito
86603276f4 UPSTREAM: rust: macros: add macro to easily run KUnit tests
Add a new procedural macro (`#[kunit_tests(kunit_test_suit_name)]`) to
run KUnit tests using a user-space like syntax.

The macro, that should be used on modules, transforms every `#[test]`
in a `kunit_case!` and adds a `kunit_unsafe_test_suite!` registering
all of them.

The only difference with user-space tests is that instead of using
`#[cfg(test)]`, `#[kunit_tests(kunit_test_suit_name)]` is used.

Note that `#[cfg(CONFIG_KUNIT)]` is added so the test module is not
compiled when `CONFIG_KUNIT` is set to `n`.

Reviewed-by: David Gow <davidgow@google.com>
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
Co-developed-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Co-developed-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Reviewed-by: Tamir Duberstein <tamird@gmail.com>
Signed-off-by: David Gow <davidgow@google.com>
Link: https://lore.kernel.org/r/20250307090103.918788-3-davidgow@google.com
[ Removed spurious (in rendered form) newline in docs. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Bug: 414994413
(cherry picked from commit c0010452893e07e032427e88f6b7b4bf7ac42e95)
Change-Id: Idca8e95fd327be46fec1d868453689ad9a1de59a
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
José Expósito
f8c704efd6 BACKPORT: rust: kunit: add KUnit case and suite macros
Add a couple of Rust const functions and macros to allow to develop
KUnit tests without relying on generated C code:

 - The `kunit_unsafe_test_suite!` Rust macro is similar to the
   `kunit_test_suite` C macro. It requires a NULL-terminated array of
   test cases (see below).
 - The `kunit_case` Rust function is similar to the `KUNIT_CASE` C macro.
   It generates as case from the name and function.
 - The `kunit_case_null` Rust function generates a NULL test case, which
   is to be used as delimiter in `kunit_test_suite!`.

While these functions and macros can be used on their own, a future
patch will introduce another macro to create KUnit tests using a
user-space like syntax.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
Co-developed-by: Matt Gilbride <mattgilbride@google.com>
Signed-off-by: Matt Gilbride <mattgilbride@google.com>
Co-developed-by: Miguel Ojeda <ojeda@kernel.org>
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Co-developed-by: David Gow <davidgow@google.com>
Signed-off-by: David Gow <davidgow@google.com>
Link: https://lore.kernel.org/r/20250307090103.918788-2-davidgow@google.com
[ Applied Markdown in comment. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Bug: 414994413
(cherry picked from commit 22097b966f5d2be93b315c791a26d4ed9b37f195)
Change-Id: Id89f51d6c684efcf72ddf76915281319adf170f9
[ aliceryhl: add __kabi_reserved1 fields ]
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
Filipe Xavier
615a5b6d7e UPSTREAM: rust: uaccess: generalize userSliceReader to support any Vec
The UserSliceReader::read_all function is currently restricted to use
only Vec with the kmalloc allocator. However, there is no reason for
this limitation.

This patch generalizes the function to accept any Vec regardless of the
allocator used.

There's a use-case for a KVVec in Binder to avoid maximum sizes for a
certain array.

Link: https://github.com/Rust-for-Linux/linux/issues/1136
Signed-off-by: Filipe Xavier <felipeaggger@gmail.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Reviewed-by: Boqun Feng <boqun.feng@gmail.com>
Link: https://lore.kernel.org/r/20250107-gen-userslice-readall-alloc-v2-1-d7fe4d19241a@gmail.com
[ Reflowed and slightly reworded title. - Miguel ]
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>

Bug: 414994413
(cherry picked from commit c80dd3fc45d573458bc763d599d97c82cf5dc212)
Change-Id: Idecc14884233ada0eeae3e4adefcd1205fdbf0fb
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
2025-05-16 10:31:04 -07:00
Carlos Llamas
e7b9281897 ANDROID: rust: allow zero init for KABI members
Allow all-zero initialization for structures that have KABI padding
added. Otherwise, the new __kabi_reserved* fields would need to be
individually initialized. This fixes reported errors such as:

  error[E0063]: missing field `__kabi_reserved1` in initializer of `blk_mq_ops`
     --> /proc/self/cwd/common/rust/kernel/block/mq/operations.rs:216:42
      |
  216 |     const VTABLE: bindings::blk_mq_ops = bindings::blk_mq_ops {
      |                                          ^^^^^^^^^^^^^^^^^^^^ missing `__kabi_reserved1`

Bug: 151154716
Cc: Alice Ryhl <aliceryhl@google.com>
Cc: Matthew Maurer <mmaurer@google.com>
Cc: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: If7996037e95b3947eb3b3afa9513cff18f4be116
Signed-off-by: Carlos Llamas <cmllamas@google.com>
2025-05-16 12:18:11 +00:00