Bartosz Golaszewski [Mon, 2 Dec 2024 18:17:03 +0000 (19:17 +0100)]
uio: uio_dmem_genirq: check the return value of devm_kasprintf()
devm_kasprintf() can fail so check its return value and bail-out on no
memory.
Fixes: 52e2dc2ce2d8 ("uio: Convert a few more users to using %pOFn instead of device_node.name") Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Link: https://lore.kernel.org/r/20241202181703.28546-1-brgl@bgdev.pl Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Greg Kroah-Hartman [Thu, 9 Jan 2025 09:56:57 +0000 (10:56 +0100)]
Merge tag 'fpga-for-6.14-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/fpga/linux-fpga into char-misc-next
Xu writes:
FPGA Manager changes for 6.14-rc1
- Peter's change fixes SRIOV problems for Intel DFL device.
All patches have been reviewed on the mailing list, and have been in the
last linux-next releases (as part of our for-next branch).
Signed-off-by: Xu Yilun <yilun.xu@intel.com>
* tag 'fpga-for-6.14-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/fpga/linux-fpga:
fpga: dfl: destroy/recreate feature platform device on port release/assign
fpga: dfl: drop unneeded get_device() and put_device() of feature device
fpga: dfl: remove unneeded function build_info_create_dev()
fpga: dfl: allocate platform device after feature device data
fpga: dfl: store platform device id in feature device data
fpga: dfl: store platform device name in feature device data
fpga: dfl: store MMIO resources in feature device data
fpga: dfl: convert features from flexible array member to separate array
fpga: dfl: factor out feature device data from platform device data
fpga: dfl: factor out feature device registration
fpga: dfl: refactor internal DFL APIs to take/return feature device data
fpga: dfl: store FIU type in feature platform data
fpga: dfl: factor out feature data creation from build_info_commit_dev()
fpga: dfl: pass feature platform data instead of device as argument
fpga: dfl: afu: define local pointer to feature device
fpga: dfl: afu: use parent device to log errors on port enable/disable
fpga: dfl: return platform data from dfl_fpga_inode_to_feature_dev_data()
fpga: dfl: omit unneeded argument pdata from dfl_feature_instance_init()
Greg Kroah-Hartman [Thu, 9 Jan 2025 09:56:11 +0000 (10:56 +0100)]
Merge tag 'socfpga_firmware_update_for_v6.14' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/dinguyen/linux into char-misc-next
Dinh writes:
SoCFPGA Firmware update for v6.14
- Use kthread_run_on_cpu()
* tag 'socfpga_firmware_update_for_v6.14' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/dinguyen/linux:
firmware: stratix10-svc: Use kthread_run_on_cpu()
Lukas Bulwahn [Wed, 8 Jan 2025 12:52:07 +0000 (13:52 +0100)]
scripts/spdxcheck: Handle license identifiers in Jinja comments
Commit 4b132aacb076 ("tools: Add xdrgen") adds a tool, which uses Jinja
template files, i.e., files with the j2 file extension, for its lightweight
code generation.
These template files for this tool have proper headers with the SPDX
License information, which are included as Jinja comments by enclosing the
text with '{#' and '#}'. Sofar, the spdxcheck script does not support to
properly parse this license information in Jinja comments and it reports
back with 'Invalid token: #}'.
Parse Jinja comments properly by stripping the known Jinja comment suffix.
Elizabeth Figura [Fri, 13 Dec 2024 19:35:11 +0000 (13:35 -0600)]
ntsync: No longer depend on BROKEN.
f5b335dc025cfee90957efa90dc72fada0d5abb4 ("misc: ntsync: mark driver as "broken"
to prevent from building") was committed to avoid the driver being used while
only part of its functionality was released. Since the rest of the functionality
has now been committed, revert this.
Signed-off-by: Elizabeth Figura <zfigura@codeweavers.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Arnd Bergmann <arnd@arndb.de> Link: https://lore.kernel.org/r/20241213193511.457338-31-zfigura@codeweavers.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Elizabeth Figura [Fri, 13 Dec 2024 19:35:08 +0000 (13:35 -0600)]
selftests: ntsync: Add a stress test for contended waits.
Test a more realistic usage pattern, and one with heavy contention, in order to
actually exercise ntsync's internal synchronization.
This test has several threads in a tight loop acquiring a mutex, modifying some
shared data, and then releasing the mutex. At the end we check if the data is
consistent.
Elizabeth Figura [Fri, 13 Dec 2024 19:35:04 +0000 (13:35 -0600)]
selftests: ntsync: Add some tests for auto-reset event state.
Test event-specific ioctls NTSYNC_IOC_EVENT_SET, NTSYNC_IOC_EVENT_RESET,
NTSYNC_IOC_EVENT_PULSE, NTSYNC_IOC_EVENT_READ for auto-reset events, and
waiting on auto-reset events.
Elizabeth Figura [Fri, 13 Dec 2024 19:35:03 +0000 (13:35 -0600)]
selftests: ntsync: Add some tests for manual-reset event state.
Test event-specific ioctls NTSYNC_IOC_EVENT_SET, NTSYNC_IOC_EVENT_RESET,
NTSYNC_IOC_EVENT_PULSE, NTSYNC_IOC_EVENT_READ for manual-reset events, and
waiting on manual-reset events.
Elizabeth Figura [Fri, 13 Dec 2024 19:35:02 +0000 (13:35 -0600)]
selftests: ntsync: Add some tests for wakeup signaling with WINESYNC_IOC_WAIT_ALL.
Test contended "wait-for-all" waits, to make sure that scheduling and wakeup
logic works correctly, and that the wait only exits once objects are all
simultaneously signaled.
Elizabeth Figura [Fri, 13 Dec 2024 19:34:59 +0000 (13:34 -0600)]
selftests: ntsync: Add some tests for NTSYNC_IOC_WAIT_ANY.
Test basic synchronous functionality of NTSYNC_IOC_WAIT_ANY, when objects are
considered signaled or not signaled, and how they are affected by a successful
wait.
Elizabeth Figura [Fri, 13 Dec 2024 19:34:57 +0000 (13:34 -0600)]
selftests: ntsync: Add some tests for semaphore state.
Wine has tests for its synchronization primitives, but these are more accessible
to kernel developers, and also allow us to test some edge cases that Wine does
not care about.
This patch adds tests for semaphore-specific ioctls NTSYNC_IOC_SEM_POST and
NTSYNC_IOC_SEM_READ, and waiting on semaphores.
Elizabeth Figura [Fri, 13 Dec 2024 19:34:56 +0000 (13:34 -0600)]
ntsync: Introduce alertable waits.
NT waits can optionally be made "alertable". This is a special channel for
thread wakeup that is mildly similar to SIGIO. A thread has an internal single
bit of "alerted" state, and if a thread is alerted while an alertable wait, the
wait will return a special value, consume the "alerted" state, and will not
consume any of its objects.
Alerts are implemented using events; the user-space NT emulator is expected to
create an internal ntsync event for each thread and pass that event to wait
functions.
Signed-off-by: Elizabeth Figura <zfigura@codeweavers.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Arnd Bergmann <arnd@arndb.de> Link: https://lore.kernel.org/r/20241213193511.457338-16-zfigura@codeweavers.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Elizabeth Figura [Fri, 13 Dec 2024 19:34:52 +0000 (13:34 -0600)]
ntsync: Introduce NTSYNC_IOC_EVENT_PULSE.
This corresponds to the NT syscall NtPulseEvent().
This wakes up any waiters as if the event had been set, but does not set the
event, instead resetting it if it had been signalled. Thus, for a manual-reset
event, all waiters are woken, whereas for an auto-reset event, at most one
waiter is woken.
Signed-off-by: Elizabeth Figura <zfigura@codeweavers.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Arnd Bergmann <arnd@arndb.de> Link: https://lore.kernel.org/r/20241213193511.457338-12-zfigura@codeweavers.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Elizabeth Figura [Fri, 13 Dec 2024 19:34:49 +0000 (13:34 -0600)]
ntsync: Introduce NTSYNC_IOC_CREATE_EVENT.
This correspond to the NT syscall NtCreateEvent().
An NT event holds a single bit of state denoting whether it is signaled or
unsignaled.
There are two types of events: manual-reset and automatic-reset. When an
automatic-reset event is acquired via a wait function, its state is reset to
unsignaled. Manual-reset events are not affected by wait functions.
Whether the event is manual-reset, and its initial state, are specified at
creation time.
Elizabeth Figura [Fri, 13 Dec 2024 19:34:48 +0000 (13:34 -0600)]
ntsync: Introduce NTSYNC_IOC_MUTEX_KILL.
This does not correspond to any NT syscall. Rather, when a thread dies, it
should be called by the NT emulator for each mutex, with the TID of the dying
thread.
NT mutexes are robust (in the pthread sense). When an NT thread dies, any
mutexes it owned are immediately released. Acquisition of those mutexes by other
threads will return a special value indicating that the mutex was abandoned,
like EOWNERDEAD returned from pthread_mutex_lock(), and EOWNERDEAD is indeed
used here for that purpose.
Elizabeth Figura [Fri, 13 Dec 2024 19:34:47 +0000 (13:34 -0600)]
ntsync: Introduce NTSYNC_IOC_MUTEX_UNLOCK.
This corresponds to the NT syscall NtReleaseMutant().
This syscall decrements the mutex's recursion count by one, and returns the
previous value. If the mutex is not owned by the current task, the function
instead fails and returns -EPERM.
Elizabeth Figura [Fri, 13 Dec 2024 19:34:46 +0000 (13:34 -0600)]
ntsync: Introduce NTSYNC_IOC_CREATE_MUTEX.
This corresponds to the NT syscall NtCreateMutant().
An NT mutex is recursive, with a 32-bit recursion counter. When acquired via
NtWaitForMultipleObjects(), the recursion counter is incremented by one. The OS
records the thread which acquired it.
The OS records the thread which acquired it. However, in order to keep this
driver self-contained, the owning thread ID is managed by user-space, and passed
as a parameter to all relevant ioctls.
The initial owner and recursion count, if any, are specified when the mutex is
created.
Elizabeth Figura [Fri, 13 Dec 2024 19:34:45 +0000 (13:34 -0600)]
ntsync: Introduce NTSYNC_IOC_WAIT_ALL.
This is similar to NTSYNC_IOC_WAIT_ANY, but waits until all of the objects are
simultaneously signaled, and then acquires all of them as a single atomic
operation.
Because acquisition of multiple objects is atomic, some complex locking is
required. We cannot simply spin-lock multiple objects simultaneously, as that
may disable preëmption for a problematically long time.
Instead, modifying any object which may be involved in a wait-all operation takes
a device-wide sleeping mutex, "wait_all_lock", instead of the normal object
spinlock.
Because wait-for-all is a rare operation, in order to optimize wait-for-any,
this lock is only taken when necessary. "all_hint" is used to mark objects which
are involved in a wait-for-all operation, and if an object is not, only its
spinlock is taken.
The locking scheme used here was written by Peter Zijlstra.
Elizabeth Figura [Fri, 13 Dec 2024 19:34:44 +0000 (13:34 -0600)]
ntsync: Introduce NTSYNC_IOC_WAIT_ANY.
This corresponds to part of the functionality of the NT syscall
NtWaitForMultipleObjects(). Specifically, it implements the behaviour where
the third argument (wait_any) is TRUE, and it does not handle alertable waits.
Those features have been split out into separate patches to ease review.
This patch therefore implements the wait/wake infrastructure which comprises the
core of ntsync's functionality.
NTSYNC_IOC_WAIT_ANY is a vectored wait function similar to poll(). Unlike
poll(), it "consumes" objects when they are signaled. For semaphores, this means
decreasing one from the internal counter. At most one object can be consumed by
this function.
This wait/wake model is fundamentally different from that used anywhere else in
the kernel, and for that reason ntsync does not use any existing infrastructure,
such as futexes, kernel mutexes or semaphores, or wait_event().
Up to 64 objects can be waited on at once. As soon as one is signaled, the
object with the lowest index is consumed, and that index is returned via the
"index" field.
A timeout is supported. The timeout is passed as a u64 nanosecond value, which
represents absolute time measured against either the MONOTONIC or REALTIME clock
(controlled by the flags argument). If U64_MAX is passed, the ioctl waits
indefinitely.
This ioctl validates that all objects belong to the relevant device. This is not
necessary for any technical reason related to NTSYNC_IOC_WAIT_ANY, but will be
necessary for NTSYNC_IOC_WAIT_ALL introduced in the following patch.
Some padding fields are added for alignment and for fields which will be added
in future patches (split out to ease review).
Costa Shulyupin [Mon, 9 Dec 2024 08:29:57 +0000 (10:29 +0200)]
scripts/tags.sh: Tag timer definitions
For timer definitions like
DEFINE_TIMER(mytimer, mytimer_handler);
ctags generates tags `DEFINE_TIMER` and skips `mytimer`
because it doesn't expand the DEFINE_TIMER macro.
Configure ctags to generate tag for `mytimer`
ans skip the `DEFINE_TIMER` tag in such cases.
Vimal Agrawal [Mon, 21 Oct 2024 13:38:12 +0000 (13:38 +0000)]
misc: misc_minor_alloc to use ida for all dynamic/misc dynamic minors
misc_minor_alloc was allocating id using ida for minor only in case of
MISC_DYNAMIC_MINOR but misc_minor_free was always freeing ids
using ida_free causing a mismatch and following warn:
> > WARNING: CPU: 0 PID: 159 at lib/idr.c:525 ida_free+0x3e0/0x41f
> > ida_free called for id=127 which is not allocated.
> > <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
...
> > [<60941eb4>] ida_free+0x3e0/0x41f
> > [<605ac993>] misc_minor_free+0x3e/0xbc
> > [<605acb82>] misc_deregister+0x171/0x1b3
misc_minor_alloc is changed to allocate id from ida for all minors
falling in the range of dynamic/ misc dynamic minors
Fixes: ab760791c0cf ("char: misc: Increase the maximum number of dynamic misc devices to 1048448") Signed-off-by: Vimal Agrawal <vimal.agrawal@sophos.com> Reviewed-by: Dirk VanDerMerwe <dirk.vandermerwe@sophos.com> Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20241021133812.23703-1-vimal.agrawal@sophos.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Alyssa Ross [Thu, 19 Dec 2024 23:29:57 +0000 (00:29 +0100)]
VMCI: remove unused ioctl definitions
IOCTL_VMCI_SOCKETS_VERSION and IOCTL_VMCI_SOCKETS_GET_AF_VALUE were
never implemented, because VSOCK ended up being implemented as a
generic mechanism with a static AF value. Likewise,
IOCTL_VMCI_SOCKETS_GET_LOCAL_CID ended up being implemented as
IOCTL_VM_SOCKETS_GET_LOCAL_CID.
This isn't a UAPI header, so it should be fine to remove the unused
values. I've left a comment noting IOCTL_VM_SOCKETS_GET_LOCAL_CID is
in the VMCI range to avoid unintentional reuse.
Carlos Llamas [Mon, 6 Jan 2025 19:26:07 +0000 (19:26 +0000)]
binder: fix kernel-doc warning of 'file' member
The 'struct file' member in 'binder_task_work_cb' definition was renamed
to 'file' between patch versions but its kernel-doc reference kept the
old name 'fd'. Update the naming to fix the W=1 build warning.
Li Li [Wed, 18 Dec 2024 21:29:34 +0000 (13:29 -0800)]
binderfs: add new binder devices to binder_devices
When binderfs is not enabled, the binder driver parses the kernel
config to create all binder devices. All of the new binder devices
are stored in the list binder_devices.
When binderfs is enabled, the binder driver creates new binder devices
dynamically when userspace applications call BINDER_CTL_ADD ioctl. But
the devices created in this way are not stored in the same list.
Rodolfo Giometti [Fri, 8 Nov 2024 07:31:12 +0000 (08:31 +0100)]
drivers pps: add PPS generators support
Sometimes one needs to be able not only to catch PPS signals but to
produce them also. For example, running a distributed simulation,
which requires computers' clock to be synchronized very tightly.
This patch adds PPS generators class in order to have a well-defined
interface for these devices.
...followed by more symptoms of corruption, with similar stacks:
refcount_t: underflow; use-after-free.
kernel BUG at lib/list_debug.c:62!
Kernel panic - not syncing: Oops - BUG: Fatal exception
This happens because pps_device_destruct() frees the pps_device with the
embedded cdev immediately after calling cdev_del(), but, as the comment
above cdev_del() notes, fops for previously opened cdevs are still
callable even after cdev_del() returns. I think this bug has always
been there: I can't explain why it suddenly started happening every time
I reboot this particular board.
In commit d953e0e837e6 ("pps: Fix a use-after free bug when
unregistering a source."), George Spelvin suggested removing the
embedded cdev. That seems like the simplest way to fix this, so I've
implemented his suggestion, using __register_chrdev() with pps_idr
becoming the source of truth for which minor corresponds to which
device.
But now that pps_idr defines userspace visibility instead of cdev_add(),
we need to be sure the pps->dev refcount can't reach zero while
userspace can still find it again. So, the idr_remove() call moves to
pps_unregister_cdev(), and pps_idr now holds a reference to pps->dev.
anish kumar [Mon, 30 Dec 2024 14:33:54 +0000 (14:33 +0000)]
MAINTAINERS: add slimbus documentation
In the commit 202318d37613d264e30d71cc32ef442492d6d279
slimbus documentation was added but it missed
the update in this file. Currently get_maintainer script
is missing the main maintainer.
nvmem: rmem: add CRC validation for Mobileye EyeQ5 NVMEM
Mobileye EyeQ5 has a non-volatile memory region which
gets used to store MAC addresses. Its format includes
a prefix 12-byte header and a suffix 4-byte CRC.
Add an optional ->checksum() callback inside match data;
it runs CRC32 onto the content.
nvmem: rmem: make ->reg_read() straight forward code
memory_read_from_buffer() is a weird choice; it:
- is made for iteration with ppos a pointer.
- does futile error checking in our case.
- does NOT ensure we read exactly N bytes.
Replace it by:
1. A check that (offset + bytes) lands inside the region and,
2. a plain memcpy().
Both ->reg_read() and ->reg_write() return values are not easy to
deduce. Explicit that they should return zero on success (and negative
values otherwise).
Such callbacks, in some alternative world, could return the number of
bytes in the success case. That would be translated to errors in the
nvmem core because of checks like:
ret = nvmem->reg_write(nvmem->priv, offset, val, bytes);
if (ret) {
// error case
}
This mistake is not just theoretical, see commit 28b008751aa2 ("nvmem: rmem: Fix return value of rmem_read()").
On Mobileye EyeQ5, the bootloader will put MAC addresses into memory.
Declare that as reserved memory to be used by the kernel, exposing
nvmem cells. That region has a 12-byte header and a 4-byte trailing CRC.
Thomas Weißschuh [Mon, 30 Dec 2024 14:30:25 +0000 (14:30 +0000)]
nvmem: core: constify 'struct bin_attribute'
The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.
Also adapt the dynamic sysfs cell logic to handle the const attributes.
Thomas Weißschuh [Sat, 21 Dec 2024 14:48:15 +0000 (15:48 +0100)]
misc: ds1682: Constify 'struct bin_attribute'
The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.
The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.
The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.
Thomas Weißschuh [Sat, 21 Dec 2024 14:48:12 +0000 (15:48 +0100)]
misc: pch_phub: Constify 'struct bin_attribute'
The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.
Thomas Weißschuh [Sat, 21 Dec 2024 14:48:11 +0000 (15:48 +0100)]
misc: c2port: Constify 'struct bin_attribute'
The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.
Thomas Weißschuh [Sat, 21 Dec 2024 14:48:09 +0000 (15:48 +0100)]
misc: sram: constify 'struct bin_attribute'
The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.
Thomas Weißschuh [Sat, 21 Dec 2024 14:48:08 +0000 (15:48 +0100)]
cxl: Constify 'struct bin_attribute'
The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.
Thomas Weißschuh [Sat, 21 Dec 2024 14:48:07 +0000 (15:48 +0100)]
ocxl: Constify 'struct bin_attribute'
The sysfs core now allows instances of 'struct bin_attribute' to be
moved into read-only memory. Make use of that to protect them against
accidental or malicious modifications.
Carlos Llamas [Tue, 10 Dec 2024 14:31:05 +0000 (14:31 +0000)]
binder: use per-vma lock in page reclaiming
Use per-vma locking in the shrinker's callback when reclaiming pages,
similar to the page installation logic. This minimizes contention with
unrelated vmas improving performance. The mmap_sem is still acquired if
the per-vma lock cannot be obtained.
Carlos Llamas [Tue, 10 Dec 2024 14:31:04 +0000 (14:31 +0000)]
binder: propagate vm_insert_page() errors
Instead of always overriding errors with -ENOMEM, propagate the specific
error code returned by vm_insert_page(). This allows for more accurate
error logs and handling.
Carlos Llamas [Tue, 10 Dec 2024 14:31:03 +0000 (14:31 +0000)]
binder: use per-vma lock in page installation
Use per-vma locking for concurrent page installations, this minimizes
contention with unrelated vmas improving performance. The mmap_lock is
still acquired when needed though, e.g. before get_user_pages_remote().
Many thanks to Barry Song who posted a similar approach [1].
Link: https://lore.kernel.org/all/20240902225009.34576-1-21cnbao@gmail.com/ Cc: Nhat Pham <nphamcs@gmail.com> Cc: Johannes Weiner <hannes@cmpxchg.org> Cc: Barry Song <v-songbaohua@oppo.com> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Hillf Danton <hdanton@sina.com> Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Reviewed-by: Suren Baghdasaryan <surenb@google.com> Signed-off-by: Carlos Llamas <cmllamas@google.com> Link: https://lore.kernel.org/r/20241210143114.661252-8-cmllamas@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Carlos Llamas [Tue, 10 Dec 2024 14:31:02 +0000 (14:31 +0000)]
binder: rename alloc->buffer to vm_start
The alloc->buffer field in struct binder_alloc stores the starting
address of the mapped vma, rename this field to alloc->vm_start to
better reflect its purpose. It also avoids confusion with the binder
buffer concept, e.g. transaction->buffer.
Carlos Llamas [Tue, 10 Dec 2024 14:31:01 +0000 (14:31 +0000)]
binder: replace alloc->vma with alloc->mapped
It is unsafe to use alloc->vma outside of the mmap_sem. Instead, add a
new boolean alloc->mapped to save the vma state (mapped or unmmaped) and
use this as a replacement for alloc->vma to validate several paths.
Using the alloc->vma caused several performance and security issues in
the past. Now that it has been replaced with either vm_lookup() or the
alloc->mapped state, we can finally remove it.
Cc: Minchan Kim <minchan@kernel.org> Cc: Liam R. Howlett <Liam.Howlett@oracle.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Suren Baghdasaryan <surenb@google.com> Reviewed-by: Suren Baghdasaryan <surenb@google.com> Signed-off-by: Carlos Llamas <cmllamas@google.com> Link: https://lore.kernel.org/r/20241210143114.661252-6-cmllamas@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Carlos Llamas [Tue, 10 Dec 2024 14:31:00 +0000 (14:31 +0000)]
binder: store shrinker metadata under page->private
Instead of pre-allocating an entire array of struct binder_lru_page in
alloc->pages, install the shrinker metadata under page->private. This
ensures the memory is allocated and released as needed alongside pages.
By converting the alloc->pages[] into an array of struct page pointers,
we can access these pages directly and only reference the shrinker
metadata where it's being used (e.g. inside the shrinker's callback).
Rename struct binder_lru_page to struct binder_shrinker_mdata to better
reflect its purpose. Add convenience functions that wrap the allocation
and freeing of pages along with their shrinker metadata.
Note I've reworked this patch to avoid using page->lru and page->index
directly, as Matthew pointed out that these are being removed [1].
Carlos Llamas [Tue, 10 Dec 2024 14:30:59 +0000 (14:30 +0000)]
binder: select correct nid for pages in LRU
The numa node id for binder pages is currently being derived from the
lru entry under struct binder_lru_page. However, this object doesn't
reflect the node id of the struct page items allocated separately.
Instead, select the correct node id from the page itself. This was made
possible since commit 0a97c01cd20b ("list_lru: allow explicit memcg and
NUMA node selection").
Carlos Llamas [Tue, 10 Dec 2024 14:30:58 +0000 (14:30 +0000)]
binder: concurrent page installation
Allow multiple callers to install pages simultaneously by switching the
mmap_sem from write-mode to read-mode. Races to the same PTE are handled
using get_user_pages_remote() to retrieve the already installed page.
This method significantly reduces contention in the mmap semaphore.
To ensure safety, vma_lookup() is used (instead of alloc->vma) to avoid
operating on an isolated VMA. In addition, zap_page_range_single() is
called under the alloc->mutex to avoid racing with the shrinker.
Many thanks to Barry Song who posted a similar approach [1].
In preparation for concurrent page installations, restore the original
alloc->mutex which will serialize zap_page_range_single() against page
installations in subsequent patches (instead of the mmap_sem).
Resolved trivial conflicts with commit 2c10a20f5e84a ("binder_alloc: Fix
sleeping function called from invalid context") and commit da0c02516c50
("mm/list_lru: simplify the list_lru walk callback function").
Lee Jones [Mon, 23 Dec 2024 15:18:37 +0000 (15:18 +0000)]
misc: trivial: Remove undesired double space from struct definition
When one is too lazy to use an LSP to conduct look-ups on struct
definitions, one might use the ever useful `struct <name> {` search
string. However this doesn't work with `struct miscdevice {` because
of a stray double space. Assuming that this wasn't intentional, let's
simply remove it.
zhangheng [Fri, 20 Dec 2024 10:23:37 +0000 (18:23 +0800)]
w1: core: use sysfs_emit() instead of sprintf()
Follow the advice in Documentation/filesystems/sysfs.rst:
show() should only use sysfs_emit() or sysfs_emit_at() when formatting
the value to be returned to user space.
Xu Yilun [Wed, 20 Nov 2024 01:10:34 +0000 (20:10 -0500)]
fpga: dfl: destroy/recreate feature platform device on port release/assign
Now that the internal DFL APIs have been converted to consume DFL
enumeration info from a separate structure, dfl_feature_dev_data, which
lifetime is independent of the feature device, proceed to completely
destroy and recreate the feature platform device on port release and
assign, respectively. This resolves a longstanding issue in the use of
platform_device_add(), which states to "not call this routine more than
once for any device structure" and which used to print a kernel warning.
The function feature_dev_unregister() resets the device pointer in the
feature data to NULL to signal that the feature platform device has been
destroyed. This substitutes the previous device_is_registered() checks.
Peter Colberg [Wed, 20 Nov 2024 01:10:33 +0000 (20:10 -0500)]
fpga: dfl: drop unneeded get_device() and put_device() of feature device
The feature device data was originally stored as platform data, hence
the memory allocation was tied to the lifetime of the feature device.
Now that the feature device data is tied to the lifetime of the DFL PCIe
FPGA device instead, get_device() and put_device() are no longer needed.
Signed-off-by: Peter Colberg <peter.colberg@intel.com> Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Reviewed-by: Basheer Ahmed Muddebihal <basheer.ahmed.muddebihal@linux.intel.com> Acked-by: Xu Yilun <yilun.xu@intel.com> Link: https://lore.kernel.org/r/20241120011035.230574-18-peter.colberg@intel.com Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
Peter Colberg [Wed, 20 Nov 2024 01:10:32 +0000 (20:10 -0500)]
fpga: dfl: remove unneeded function build_info_create_dev()
Remove the function build_info_create_dev(), which no longer serves its
original purpose now that the allocation of the platform device has been
moved to feature_dev_register().
Signed-off-by: Peter Colberg <peter.colberg@intel.com> Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Reviewed-by: Basheer Ahmed Muddebihal <basheer.ahmed.muddebihal@linux.intel.com> Acked-by: Xu Yilun <yilun.xu@intel.com> Link: https://lore.kernel.org/r/20241120011035.230574-17-peter.colberg@intel.com Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
Peter Colberg [Wed, 20 Nov 2024 01:10:31 +0000 (20:10 -0500)]
fpga: dfl: allocate platform device after feature device data
Delay calling platform_device_alloc() from build_info_create_dev() to
feature_dev_register(), now that the feature device data contains all
necessary data to create the feature device. This completes the new
function feature_dev_register(), which will be reused in a subsequent
commit to fully recreate the feature device when assigning a port.
In the function feature_dev_unregister(), reset the device pointer in
the feature data to NULL to signal that the platform device has been
destroyed. This will substitute device_is_registered() in a subsequent
commit. Reset the device pointer of each sub feature for consistency.
Convert is_feature_dev_detected() to check whether binfo->type is not
DFL_ID_MAX for deciding whether a feature device was detected during
feature parsing, instead of checking binfo->feature_dev for non-NULL.
Signed-off-by: Peter Colberg <peter.colberg@intel.com> Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Reviewed-by: Basheer Ahmed Muddebihal <basheer.ahmed.muddebihal@linux.intel.com> Acked-by: Xu Yilun <yilun.xu@intel.com> Link: https://lore.kernel.org/r/20241120011035.230574-16-peter.colberg@intel.com Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
Peter Colberg [Wed, 20 Nov 2024 01:10:30 +0000 (20:10 -0500)]
fpga: dfl: store platform device id in feature device data
Delay the feature device id allocation from build_info_create_dev() to
binfo_create_feature_dev_data() and store the id in the feature device
data before copying it to the device. This will allow reusing the same
id in a subsequent commit which completely destroys and recreates the
feature device when releasing and reassigning the corresponding port.
Instead of manually freeing the id when no longer needed, use a
device-managed resource with a custom action to automatically free
the id right before the feature device data is freed. The id registry
is guaranteed to be allocated when dfl_id_free_action() is invoked,
since the DFL PCIe device and its device-managed resources will be
destroyed before dfl_ids_destroy() is called in dfl_fpga_exit().
Signed-off-by: Peter Colberg <peter.colberg@intel.com> Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Reviewed-by: Basheer Ahmed Muddebihal <basheer.ahmed.muddebihal@linux.intel.com> Acked-by: Xu Yilun <yilun.xu@intel.com> Link: https://lore.kernel.org/r/20241120011035.230574-15-peter.colberg@intel.com Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
Peter Colberg [Wed, 20 Nov 2024 01:10:29 +0000 (20:10 -0500)]
fpga: dfl: store platform device name in feature device data
Add a new member, pdev_name, to the structure dfl_feature_dev_data that
holds the platform device name for convenience. A subsequent commit will
completely destroy the platform device during port release, after which
fdata->dev is unavailable, while fdata itself remains available.
Signed-off-by: Peter Colberg <peter.colberg@intel.com> Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Reviewed-by: Basheer Ahmed Muddebihal <basheer.ahmed.muddebihal@linux.intel.com> Acked-by: Xu Yilun <yilun.xu@intel.com> Link: https://lore.kernel.org/r/20241120011035.230574-14-peter.colberg@intel.com Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
Peter Colberg [Wed, 20 Nov 2024 01:10:28 +0000 (20:10 -0500)]
fpga: dfl: store MMIO resources in feature device data
Instead of directly copying the MMIO resource of each feature to the
feature device resources, add a new member to the feature device data
to store the resources and copy them to the feature device using
platform_device_add_resources(). This prepares a subsequent commit
which completely destroys and recreates the feature device when
releasing and reassigning the corresponding port, respectively.
Signed-off-by: Peter Colberg <peter.colberg@intel.com> Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Reviewed-by: Basheer Ahmed Muddebihal <basheer.ahmed.muddebihal@linux.intel.com> Acked-by: Xu Yilun <yilun.xu@intel.com> Link: https://lore.kernel.org/r/20241120011035.230574-13-peter.colberg@intel.com Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
Peter Colberg [Wed, 20 Nov 2024 01:10:27 +0000 (20:10 -0500)]
fpga: dfl: convert features from flexible array member to separate array
Use a separate array allocation for features and substitute a pointer
for the flexible array member in the feature device data. A subsequent
commit will add another array for resources. The current commit converts
the flexible array member to a separate allocation for consistency.
Signed-off-by: Peter Colberg <peter.colberg@intel.com> Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Reviewed-by: Basheer Ahmed Muddebihal <basheer.ahmed.muddebihal@linux.intel.com> Acked-by: Xu Yilun <yilun.xu@intel.com> Link: https://lore.kernel.org/r/20241120011035.230574-12-peter.colberg@intel.com Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
Peter Colberg [Wed, 20 Nov 2024 01:10:26 +0000 (20:10 -0500)]
fpga: dfl: factor out feature device data from platform device data
Add a structure dfl_feature_dev_data to hold the DFL enumeration
info previously held in dfl_feature_platform_data. Allocate the new
structure using device-managed memory whose lifetime is bound to the
lifetime of the physical DFL, e.g., PCIe FPGA device. In a subsequent
commit, this will allow the feature platform device to be completely
destroyed and recreated on port release and assign, respectively, while
retaining the feature data in the new dfl_feature_dev_data structure.
Signed-off-by: Peter Colberg <peter.colberg@intel.com> Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Reviewed-by: Basheer Ahmed Muddebihal <basheer.ahmed.muddebihal@linux.intel.com> Acked-by: Xu Yilun <yilun.xu@intel.com> Link: https://lore.kernel.org/r/20241120011035.230574-11-peter.colberg@intel.com Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
Peter Colberg [Wed, 20 Nov 2024 01:10:25 +0000 (20:10 -0500)]
fpga: dfl: factor out feature device registration
Add separate functions, feature_dev_{register,unregister}(), that wrap
platform_device_add() and platform_device_unregister(), respectively.
These are invoked once per feature device in this commit but will be
reused in a subsequent commit to destroy and recreate the platform
device when the corresponding port is released and reassigned.
The function feature_dev_register() will be extended in subsequent
commits to allocate the platform device, add resources and platform
data, and finally add the platform device to the device hierarchy.
Signed-off-by: Peter Colberg <peter.colberg@intel.com> Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Reviewed-by: Basheer Ahmed Muddebihal <basheer.ahmed.muddebihal@linux.intel.com> Acked-by: Xu Yilun <yilun.xu@intel.com> Link: https://lore.kernel.org/r/20241120011035.230574-10-peter.colberg@intel.com Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
Peter Colberg [Wed, 20 Nov 2024 01:10:24 +0000 (20:10 -0500)]
fpga: dfl: refactor internal DFL APIs to take/return feature device data
This change prepares a subsequent commit which factors out the DFL
enumeration info from the structure dfl_feature_platform_data into
a new structure dfl_feature_dev_data, whose lifetime is independent
of the feature device which will be destroyed during port release.
Add an alias dfl_feature_dev_data for dfl_feature_platform_data, and an
alias to_dfl_feature_dev_data() for dev_get_platdata(), and refactor
internal DFL APIs to take/return dfl_feature_dev_data instead. The
aliases will be replaced with implementations in a subsequent commit.
This change does not introduce any functional changes.
Signed-off-by: Peter Colberg <peter.colberg@intel.com> Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Reviewed-by: Basheer Ahmed Muddebihal <basheer.ahmed.muddebihal@linux.intel.com> Acked-by: Xu Yilun <yilun.xu@intel.com> Link: https://lore.kernel.org/r/20241120011035.230574-9-peter.colberg@intel.com Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
Peter Colberg [Wed, 20 Nov 2024 01:10:23 +0000 (20:10 -0500)]
fpga: dfl: store FIU type in feature platform data
Remove the local function feature_dev_id_type() in favor of persisting
the FIU type in struct dfl_feature_platform_data. Add type to struct
build_feature_devs_info and drop argument to build_info_create_dev().
Signed-off-by: Peter Colberg <peter.colberg@intel.com> Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Reviewed-by: Basheer Ahmed Muddebihal <basheer.ahmed.muddebihal@linux.intel.com> Acked-by: Xu Yilun <yilun.xu@intel.com> Link: https://lore.kernel.org/r/20241120011035.230574-8-peter.colberg@intel.com Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
Peter Colberg [Wed, 20 Nov 2024 01:10:22 +0000 (20:10 -0500)]
fpga: dfl: factor out feature data creation from build_info_commit_dev()
Add a separate function, binfo_create_feature_dev_data(), which allocates
and populates the feature platform data, and call the function from
build_info_commit_dev(), which registers the feature platform device.
Signed-off-by: Peter Colberg <peter.colberg@intel.com> Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Reviewed-by: Basheer Ahmed Muddebihal <basheer.ahmed.muddebihal@linux.intel.com> Acked-by: Xu Yilun <yilun.xu@intel.com> Link: https://lore.kernel.org/r/20241120011035.230574-7-peter.colberg@intel.com Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
Peter Colberg [Wed, 20 Nov 2024 01:10:21 +0000 (20:10 -0500)]
fpga: dfl: pass feature platform data instead of device as argument
For functions which use the feature platform data, instead of invoking
dev_get_platdata() on the device, directly pass the data as an argument.
This patch is part of a refactoring of the internal DFL APIs to move
the feature device data into a new struct dfl_feature_dev_data which
lifetime is independent of the corresponding platform device.
Signed-off-by: Peter Colberg <peter.colberg@intel.com> Reviewed-by: Matthew Gerlach <matthew.gerlach@linux.intel.com> Reviewed-by: Basheer Ahmed Muddebihal <basheer.ahmed.muddebihal@linux.intel.com> Acked-by: Xu Yilun <yilun.xu@intel.com> Link: https://lore.kernel.org/r/20241120011035.230574-6-peter.colberg@intel.com Signed-off-by: Xu Yilun <yilun.xu@linux.intel.com>
Linus Torvalds [Sun, 15 Dec 2024 23:33:41 +0000 (15:33 -0800)]
Merge tag 'efi-fixes-for-v6.13-1' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi
Pull EFI fixes from Ard Biesheuvel:
- Limit EFI zboot to GZIP and ZSTD before it comes in wider use
- Fix inconsistent error when looking up a non-existent file in
efivarfs with a name that does not adhere to the NAME-GUID format
- Drop some unused code
* tag 'efi-fixes-for-v6.13-1' of git://git.kernel.org/pub/scm/linux/kernel/git/efi/efi:
efi/esrt: remove esre_attribute::store()
efivarfs: Fix error on non-existent file
efi/zboot: Limit compression options to GZIP and ZSTD