7.3.6-rc1 review
Subsystems (4)
Greg Kroah-Hartman
maintainerPATCH 1617/2651 ALSA: virtio: reset I/O message fill level on prepare
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ting-Han Hou <[email protected]>
[ Upstream commit f0e9db0f84249b65a72b5fba43e91212281ad378 ]
Since commit fe981e67568c ("ALSA: virtio: use ack callback"), an I/O message is only queued to the device once the application has filled the whole period: virtsnd_pcm_msg_send() accumulates the transferred bytes in msg->length and queues the message when it reaches period_bytes. msg->length is reset to 0 only when the device completes the message.
If the substream is stopped (e.g. snd_pcm_drop()) while a period is only partially filled, the corresponding message is never queued and keeps its partial length. virtsnd_pcm_prepare() resets msg_count, hw_ptr and the indirect PCM state, but not msg->length. After the next start, the stale length is added to the new data, the sum never equals period_bytes, and the message is never sent again. Playback then stalls once hw_ptr reaches that period: writes fail with -EIO ("DMA or IRQ trouble") and drain fails with -EIO. Capture is affected the same way after a partial read.
Clear the fill level of all messages in prepare. Outside of the resume path, virtsnd_pcm_prepare() already refuses to run while I/O messages are pending, so no message is owned by the device at this point and the reset does not race with message completion.
Reproduced in QEMU (virtio-sound-pci, wav audiodev): prepare, write 1.5 periods, drop, prepare, write 16 full periods, drain. Without this patch WRITEI returns -EIO after 14 periods and DRAIN fails; with it all 16 periods are played and DRAIN succeeds. Period-aligned prefill works in both cases. The same sequence on capture (read 1.5 periods, drop, prepare, read 16 periods) fails with -EIO after 10 periods without this patch and reads all 16 with it.
Found by code inspection, confirmed with the reproducer above.
--- sound/virtio/virtio_pcm.h | 2 ++ sound/virtio/virtio_pcm_msg.c | 19 +++++++++++++++++++ sound/virtio/virtio_pcm_ops.c | 1 + 3 files changed, 22 insertions(+)
sound/virtio/virtio_pcm.h +2 -0
@@ -118,6 +118,8 @@ int virtsnd_pcm_msg_alloc(struct virtio_pcm_substream *vss,void virtsnd_pcm_msg_free (struct virtio_pcm_substream *vss); +void virtsnd_pcm_msg_reset (struct virtio_pcm_substream *vss); +int virtsnd_pcm_msg_send (struct virtio_pcm_substream *vss,unsigned long offset,unsigned long bytes);
sound/virtio/virtio_pcm_msg.c +19 -0
@@ -182,6 +182,25 @@ void virtsnd_pcm_msg_free(struct virtio_pcm_substream *vss) vss->nmsgs =0 ; } +/** +* virtsnd_pcm_msg_reset() - Reset the fill level of all I/O messages. +* @vss: VirtIO PCM substream. +* +* Messages that were only partially filled by the application when the +* substream was stopped are never sent to the device, so their length must be +* cleared before the substream is started again. +* +* Context: Any context. Takes and releases the VirtIO substream spinlock. +*/ +void virtsnd_pcm_msg_reset (struct virtio_pcm_substream *vss) +{ +unsigned int i; + +guard (spinlock_irqsave)(&vss->lock); +for (i =0 ; vss->msgs && i < vss->nmsgs; ++i) + vss->msgs[i]->length =0 ; +} +/** * virtsnd_pcm_msg_send() - Send asynchronous I/O messages. * @vss: VirtIO PCM substream.
sound/virtio/virtio_pcm_ops.c +1 -0
@@ -299,6 +299,7 @@ static int virtsnd_pcm_prepare(struct snd_pcm_substream *substream) vss->xfer_xrun = false; vss->suspended = false; vss->msg_count =0 ; +virtsnd_pcm_msg_reset (vss);memset (&vss->pcm_indirect,0 ,sizeof (vss->pcm_indirect)); vss->pcm_indirect.sw_buffer_size =
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1618/2651 RDMA/mlx5: Cancel deferred page-fault EQ work before teardown
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Prathamesh Deshpande <[email protected]>
[ Upstream commit aea64024ac37d29e99b82b315a56a9145dc0bc23 ]
Page-fault EQ work can remain queued after the notifier is disabled. Destroying the EQ before cancelling that work can let the worker access freed EQ memory.
Cancel the deferred work before destroying the EQ.
--- drivers/infiniband/hw/mlx5/odp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/infiniband/hw/mlx5/odp.c +1 -1
@@ -1885,8 +1885,8 @@ mlx5_ib_odp_destroy_eq(struct mlx5_ib_dev *dev, struct mlx5_ib_pf_eq *eq)if (!eq->core)return 0 ;mlx5_eq_disable (dev->mdev, eq->core, &eq->irq_nb); - err =mlx5_eq_destroy_generic (dev->mdev, eq->core);cancel_work_sync (&eq->work); + err =mlx5_eq_destroy_generic (dev->mdev, eq->core);destroy_workqueue (eq->wq);mempool_destroy (eq->pool);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1619/2651 RDMA/mlx5: Cancel software CQ notifications before teardown
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Prathamesh Deshpande <[email protected]>
[ Upstream commit a0ab2bb269e7fd8523f87950b91a42a36c7f8f2a ]
GSI completions queue notify_work to invoke the CQ completion handler. CQ destruction drains hardware events and core polling, but does not cancel this software notifier.
--- drivers/infiniband/hw/mlx5/cq.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/infiniband/hw/mlx5/cq.c +3 -0
@@ -1117,6 +1117,9 @@ int mlx5_ib_pre_destroy_cq(struct ib_cq *cq)struct mlx5_ib_dev *dev =to_mdev (cq->device);struct mlx5_ib_cq *mcq =to_mcq (cq); +if (!cq->uobject) +cancel_work_sync (&mcq->notify_work); +return mlx5_core_destroy_cq (dev->mdev, &mcq->mcq); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1620/2651 bpf: Reject BTF ids with the same address in tracing_multi link
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexei Starovoitov <[email protected]>
[ Upstream commit 87bfa22937000db29a9a09ec826ab7227eaf9e8c ]
check_dup_ids() rejects equal BTF ids, but different ids can resolve to the same address. Aliases:
ffffffff8161b6b0 t __do_sys_munlockall
ffffffff8161b6b0 T __ia32_sys_munlockall
ffffffff8161b6b0 T __x64_sys_munlockall
or several BTF_KIND_FUNC with the same name that vmlinux BTF has when CONFIG_DEBUG_INFO_BTF_INLINE is set.
Each id gets its own trampoline and register_fentry_multi() adds them to data->reg with the same ip. update_ftrace_direct_add() checks that new entries are not in direct_functions, but doesn't compare them with each other, so the attach succeeds. At detach update_ftrace_direct_del() sees that 'direct' of one of the entries doesn't match and returns -EINVAL:
WARNING: kernel/bpf/trampoline.c:1845 at bpf_trampoline_multi_detach+0x24c/0x280 Call Trace: bpf_link_free+0x51/0x110 bpf_link_release+0x18/0x20 __fput+0x103/0x2d0 __x64_sys_close+0x3d/0x80
The images are freed anyway, while ftrace still calls them:
Oops: int3: 0000 [#1] SMP NOPTI RIP: 0010:0xffffffffc042b201 Call Trace: ? __audit_syscall_exit+0x9/0x100 ? do_syscall_64+0x5ab/0x5e0 entry_SYSCALL_64_after_hwframe+0x77/0x7f Kernel panic - not syncing: Fatal exception in interrupt
Return -EINVAL from register_fentry_multi() when ip is already in data->reg. When such ids are attached via different links the second attach already fails with -EINVAL in update_ftrace_direct_add().
Move the declaration of ftrace_lookup_ip() to include/linux/ftrace.h.
The lookup adds 60 msec to the attach of 64480 functions in tracing_multi_bench_attach: 1.34 -> 1.40 sec.
--- include/linux/ftrace.h | 1 + kernel/bpf/trampoline.c | 8 ++++++++ kernel/trace/trace.h | 3 --- 3 files changed, 9 insertions(+), 3 deletions(-)
include/linux/ftrace.h +1 -0
@@ -416,6 +416,7 @@ void free_ftrace_hash(struct ftrace_hash *hash);struct ftrace_func_entry *add_ftrace_hash_entry_direct (struct ftrace_hash *hash,unsigned long ip,unsigned long direct);void add_ftrace_hash_entry (struct ftrace_hash *hash,struct ftrace_func_entry *entry); +struct ftrace_func_entry *ftrace_lookup_ip (struct ftrace_hash *hash,unsigned long ip);void ftrace_hash_remove (struct ftrace_hash *hash);/* The hash used to know what functions callbacks trace */
kernel/bpf/trampoline.c +8 -0
@@ -1638,6 +1638,14 @@ static int register_fentry_multi(struct bpf_trampoline *tr, struct bpf_tramp_imaunsigned long ip =ftrace_location (tr->ip);struct bpf_tracing_multi_data *data = ptr; +/* +* Different BTF ids get different trampolines, but they can still +* resolve to the same address (aliases, functions of the same name). +* There's only one call site to attach to. +*/ +if (ftrace_lookup_ip (data->reg, ip)) +return -EINVAL ; +if (bpf_trampoline_use_jmp (tr->flags)) addr =ftrace_jmp_set (addr);
kernel/trace/trace.h +0 -3
@@ -1006,9 +1006,6 @@ struct ftrace_hash {struct rcu_head rcu; }; -struct ftrace_func_entry * -ftrace_lookup_ip (struct ftrace_hash *hash,unsigned long ip); - static __always_inline bool ftrace_hash_empty(struct ftrace_hash *hash) {return !hash || !(hash->count || (hash->flags &FTRACE_HASH_FL_MOD ));
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1621/2651 selftests/namespaces: Wait for thread exit via pidfd in active-ref tests
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo B. Marlière (SUSE) <[email protected]>
[ Upstream commit 123dcfe87d5f8c9a2ff489545e85c0345de9e21c ]
pthread_join() returns once exit_mm() wakes the CLEARTID futex, but the exiting thread drops its namespace reference later, in exit_nsproxy_namespaces(). The joining thread can therefore still see the namespace as active, making the final open_by_handle_at() check in thread_ns_inactive_after_exit and thread_ns_fd_keeps_active fail intermittently.
Have the thread open a PIDFD_THREAD pidfd on itself and poll it before pthread_join(). A pidfd becomes readable from exit_notify(), which runs after exit_nsproxy_namespaces().
--- .../selftests/namespaces/ns_active_ref_test.c | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+)
tools/testing/selftests/namespaces/ns_active_ref_test.c +29 -0
@@ -8,6 +8,7 @@#include <stdlib.h> #include <string.h> #include <linux/nsfs.h> +#include <poll.h> #include <sys/mount.h> #include <sys/socket.h> #include <sys/stat.h>
@@ -20,6 +21,10 @@#include "../filesystems/utils.h" #include "wrappers.h" +#ifndef PIDFD_THREAD +#define PIDFD_THREAD O_EXCL +#endif +#ifndef FD_NSFS_ROOT #define FD_NSFS_ROOT -10003/* Root of the nsfs filesystem */ #endif
@@ -2120,6 +2125,7 @@ TEST(ns_mixed_types_same_owner)/* Thread test helpers and structures */ struct thread_ns_info {__u64 ns_id; +int pidfd;int pipefd;int syncfd_read;int syncfd_write;
@@ -2152,6 +2158,13 @@ static void *thread_create_namespace(void *arg)return NULL ; } +/* Open a pidfd so the main thread can later poll it to detect actual thread exit. */ + info->pidfd =syscall (__NR_pidfd_open,gettid (),PIDFD_THREAD ); +if (info->pidfd <0 ) { + info->exit_code =6 ; +return NULL ; + } +/* Send namespace ID to main thread */ if (write (info->pipefd, &info->ns_id,sizeof (info->ns_id)) !=sizeof (info->ns_id)) { info->exit_code =4 ;
@@ -2169,6 +2182,20 @@ static void *thread_create_namespace(void *arg)return NULL ; } +/* +* pthread_join() returns once exit_mm() wakes the CLEARTID futex, before +* exit_nsproxy_namespaces() drops the namespace reference. A pidfd becomes +* readable only from exit_notify(), after that point. +*/ +static int wait_thread_exited (int pidfd) +{ +struct pollfd pfd = { .fd = pidfd, .events =POLLIN }; +int ret =poll (&pfd,1 ,-1 ); + +close (pidfd); +return ret; +} +/* * Test that namespace becomes inactive after thread exits. * This verifies active reference counting works with threads, not just processes.
@@ -2234,6 +2261,7 @@ TEST(thread_ns_inactive_after_exit)close (syncpipe[1 ]);/* Wait for thread to exit */ +ASSERT_EQ (wait_thread_exited (info.pidfd),1 );ASSERT_EQ (pthread_join (thread,NULL ),0 );close (pipefd[0 ]);close (pipefd[1 ]);
@@ -2317,6 +2345,7 @@ TEST(thread_ns_fd_keeps_active)close (syncpipe[1 ]);/* Wait for thread to exit */ +ASSERT_EQ (wait_thread_exited (info.pidfd),1 );pthread_join (thread,NULL );close (pipefd[0 ]);close (pipefd[1 ]);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1622/2651 bpftool: Fix out-of-bounds read in kprobe_multi link info dump
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuan Chen <[email protected]>
[ Upstream commit 0d5e3fc78a6f2522e6339743b8e5ecc02351a9dd ]
show_kprobe_multi_{plain,json}() walk the sorted kallsyms array against the sorted addr/cookie array with j as a cursor into the latter. The loop terminating condition is checked after the cursor has already been used to access the array:
if (j++ == info->kprobe_multi.count)
break;After all count entries have been printed, j has been bumped to count, but the loop keeps running and dereferences data[count] -- one element past the end of the calloc(count, sizeof(*data)) allocation -- while comparing every remaining kallsyms symbol. If the out-of-bounds value happens to match a symbol address, a bogus entry with a garbage addr/cookie pair is printed to boot.
Fix the off-by-one by advancing the cursor before the comparison, so the loop terminates as soon as the last entry has been printed.
Verified with an ASAN build of bpftool against a live kprobe_multi link of 3 symbols:
before: ERROR: AddressSanitizer: heap-buffer-overflow READ of size 8
at link.c:860 (show_kprobe_multi_plain) and link.c:352 (show_kprobe_multi_json), 0 bytes after the 48-byte get_addr_cookie_array() allocation
after: clean output, no ASAN report
--- tools/bpf/bpftool/link.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/bpf/bpftool/link.c +2 -2
@@ -364,7 +364,7 @@ show_kprobe_multi_json(struct bpf_link_info *info, json_writer_t *wtr) }jsonw_uint_field (json_wtr,"cookie" , data[j].cookie);jsonw_end_object (json_wtr); -if (j++ == info->kprobe_multi.count) +if (++j == info->kprobe_multi.count)break ; }jsonw_end_array (json_wtr);
@@ -867,7 +867,7 @@ static void show_kprobe_multi_plain(struct bpf_link_info *info)else printf (" " ); -if (j++ == info->kprobe_multi.count) +if (++j == info->kprobe_multi.count)break ; } error:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1623/2651 dm-snapshot: make the chunk list sorted by the chunk number
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mikulas Patocka <[email protected]>
[ Upstream commit bbd6f974d0386036e560af332b6b8cdd17010a72 ]
Commit 8581b19eb2c5 ("dm-snapshot: fix 'scheduling while atomic' on real-time kernels") replaced hlist_bl_for_each_entry with hlist_for_each_entry, but the two iteration macros differ after the loop
ends: hlist_bl_for_each_entry leaves "e" pointing at the last element, while hlist_for_each_entry() sets it to NULL.
The result is that the list is no longer sorted by chunk number as it was intended to be. This bug doesn't cause data corruption because dm_lookup_exception walks the full list.
Restore the invariant by tracking the list tail in the "prev" variable and appending after it with hlist_add_behind.
--- drivers/md/dm-snap.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/md/dm-snap.c +10 -8
@@ -766,7 +766,7 @@ static void dm_insert_exception(struct dm_exception_table *eh, struct dm_exception *new_e) {struct hlist_head *l; -struct dm_exception *e =NULL ; +struct dm_exception *e =NULL , *prev =NULL ; l = &eh->table[exception_hash (eh, new_e->old_chunk)].head;
@@ -798,21 +798,23 @@ static void dm_insert_exception(struct dm_exception_table *eh,if (new_e->old_chunk < e->old_chunk)break ; + + prev = e; } out: -if (!e) { +if (e && new_e->old_chunk < e->old_chunk) { +/* Add before an existing exception */ +hlist_add_before (&new_e->hash_list, &e->hash_list); + }else if (prev) { +/* Add to l's tail: prev is the last exception in this slot */ +hlist_add_behind (&new_e->hash_list, &prev->hash_list); + }else {/* * Either the table doesn't support consecutive chunks or slot * l is empty. */ hlist_add_head (&new_e->hash_list, l); - }else if (new_e->old_chunk < e->old_chunk) { -/* Add before an existing exception */ -hlist_add_before (&new_e->hash_list, &e->hash_list); - }else { -/* Add to l's tail: e is the last exception in this slot */ -hlist_add_behind (&new_e->hash_list, &e->hash_list); } }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1624/2651 net: devmem: replace gen_pool with freelist
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanislav Fomichev <[email protected]>
[ Upstream commit 083e64a3af7717363d1918baede5757235f94a87 ]
devmem only needs fixed-size net_iov allocations for each dma-buf binding. The gen_pool tracks the same free set indirectly through DMA addresses, which makes devmem depend on the generic allocator even though the users are fixed-size net_iov chunks.
Mirror the io_uring zcrx model more closely by keeping a binding-level freelist protected by spin_lock_bh(). Use a single net_iov_area owner for the binding, populate each net_iov's DMA address while walking the SG table, and check at teardown that all net_iovs have returned to the freelist.
Validate the DMA-BUF size against the net_iov size up front and derive the RX and TX entry count from it, avoiding a separate SG-table pass.
Drop the NET_DEVMEM select of GENERIC_ALLOCATOR now that devmem no longer calls gen_pool APIs.
Stable-dep-of: 3a82195416fd ("net: devmem: check uid and netns in net_devmem_get_binding()")
--- net/Kconfig | 1 - net/core/devmem.c | 182 +++++++++++++++++++++------------------------- net/core/devmem.h | 15 ++-- 3 files changed, 88 insertions(+), 110 deletions(-)
net/Kconfig +0 -1
@@ -68,7 +68,6 @@ config SKB_EXTENSIONS config NET_DEVMEM def_bool y - select GENERIC_ALLOCATOR depends on DMA_SHARED_BUFFER depends on PAGE_POOL
net/core/devmem.c +82 -100
280 lines not on this page · raw message
net/core/devmem.h +6 -9
@@ -14,6 +14,7 @@#include <net/netdev_netlink.h> struct netlink_ext_ack ; +struct dmabuf_genpool_chunk_owner ;struct net_devmem_dmabuf_binding {struct dma_buf *dmabuf;
@@ -26,7 +27,7 @@ struct net_devmem_dmabuf_binding {* dereferenced. */ void *vdev; -struct gen_pool *chunk_pool; +struct dmabuf_genpool_chunk_owner *chunk_owner;/* Protect dev */ struct mutex lock;
@@ -57,6 +58,10 @@ struct net_devmem_dmabuf_binding {/* rxq's this binding is active on. */ struct xarray bound_rxqs; +spinlock_t freelist_lock____cacheline_aligned_in_smp ; +size_t free_count; +struct net_iov **freelist; +/* ID of this binding. Globally unique to all bindings currently * active. */
@@ -77,17 +82,9 @@ struct net_devmem_dmabuf_binding { };#if defined(CONFIG_NET_DEVMEM ) -/* Owner of the dma-buf chunks inserted into the gen pool. Each scatterlist -* entry from the dmabuf is inserted into the genpool as a chunk, and needs -* this owner struct to keep track of some metadata necessary to create -* allocations from this chunk. -*/ struct dmabuf_genpool_chunk_owner {struct net_iov_area area;struct net_devmem_dmabuf_binding *binding; - -/* dma_addr of the start of the chunk. */ -dma_addr_t base_dma_addr; };void __net_devmem_dmabuf_binding_free (struct work_struct *wq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1625/2651 net: devmem: embed net_iov_area in binding
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stanislav Fomichev <[email protected]>
[ Upstream commit 13648ba787223c88086b383beead242427e5747a ]
After replacing the gen_pool with a binding-level freelist, devmem no longer needs a separate chunk owner object. There is only one net_iov_area for the binding, so store it directly in struct net_devmem_dmabuf_binding.
Derive the binding from net_iov_owner() with container_of(), matching the pattern used by io_uring zcrx. This removes the leftover dmabuf_genpool_chunk_owner wrapper and its allocation/free path.
Stable-dep-of: 3a82195416fd ("net: devmem: check uid and netns in net_devmem_get_binding()")
--- net/core/devmem.c | 61 ++++++++++++++--------------------------------- net/core/devmem.h | 25 +++++-------------- 2 files changed, 24 insertions(+), 62 deletions(-)
net/core/devmem.c +18 -43
@@ -29,15 +29,6 @@ static DEFINE_XARRAY_FLAGS(net_devmem_dmabuf_bindings, XA_FLAGS_ALLOC1);static const struct memory_provider_ops dmabuf_devmem_ops; -static void -net_devmem_dmabuf_free_chunk_owner (struct dmabuf_genpool_chunk_owner *owner) -{ -if (owner) { -kvfree (owner->area.niovs); -kfree (owner); - } -} -static void net_devmem_dmabuf_binding_release (struct percpu_ref *ref) { struct net_devmem_dmabuf_binding *binding =
@@ -52,12 +43,11 @@ void __net_devmem_dmabuf_binding_free(struct work_struct *wq)struct net_devmem_dmabuf_binding *binding =container_of (wq,typeof (*binding), unbind_w);if (binding->freelist) -WARN (binding->free_count != binding->chunk_owner->area.num_niovs, +WARN (binding->free_count != binding->area.num_niovs,"destroying dmabuf binding with outstanding net_iovs: total=%zu, free=%zu" , - binding->chunk_owner->area.num_niovs, - binding->free_count); + binding->area.num_niovs, binding->free_count); -net_devmem_dmabuf_free_chunk_owner (binding->chunk_owner); +kvfree (binding->area.niovs);dma_buf_unmap_attachment_unlocked (binding->attachment, binding->sgt, binding->direction);dma_buf_detach (binding->dmabuf, binding->attachment);
@@ -94,8 +84,7 @@ void net_devmem_free_dmabuf(struct net_iov *niov)struct net_devmem_dmabuf_binding *binding =net_devmem_iov_binding (niov);spin_lock_bh (&binding->freelist_lock); -if (WARN_ON_ONCE (binding->free_count >= - binding->chunk_owner->area.num_niovs)) { +if (WARN_ON_ONCE (binding->free_count >= binding->area.num_niovs)) {spin_unlock_bh (&binding->freelist_lock);return ; }
@@ -175,13 +164,11 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, struct netlink_ext_ack *extack) {struct net_devmem_dmabuf_binding *binding; -struct dmabuf_genpool_chunk_owner *owner;size_t niov_size =1UL << niov_shift;static u32 id_alloc_next;struct scatterlist *sg;struct dma_buf *dmabuf;unsigned int sg_idx; -size_t total_niovs;size_t niov_idx;size_t i;int err;
@@ -241,16 +228,18 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, goto err_unmap; } - total_niovs = dmabuf->size >> niov_shift; + binding->area.base_virtual =0 ; + binding->area.num_niovs = dmabuf->size >> niov_shift;if (direction ==DMA_TO_DEVICE ) { - binding->tx_vec = kvmalloc_objs(struct net_iov *, total_niovs); + binding->tx_vec = kvmalloc_objs(struct net_iov *, + binding->area.num_niovs);if (!binding->tx_vec) { err = -ENOMEM ; goto err_unmap; } }else {spin_lock_init (&binding->freelist_lock); - binding->freelist =kvmalloc_array (total_niovs, + binding->freelist =kvmalloc_array (binding->area.num_niovs,sizeof (binding->freelist[0 ]),GFP_KERNEL );if (!binding->freelist) {
@@ -258,24 +247,13 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, goto err_unmap; } } - owner =kzalloc_node (sizeof (*owner),GFP_KERNEL , -dev_to_node (&dev->dev)); -if (!owner) { + binding->area.niovs =kvmalloc_objs (*binding->area.niovs, + binding->area.num_niovs); +if (!binding->area.niovs) { err = -ENOMEM ; goto err_free_freelist; } - owner->area.base_virtual =0 ; - owner->area.num_niovs = total_niovs; - owner->binding = binding; - owner->area.niovs =kvmalloc_objs (*owner->area.niovs, - owner->area.num_niovs); -if (!owner->area.niovs) { - err = -ENOMEM ; - goto err_free_owner; - } - binding->chunk_owner = owner; - niov_idx =0 ;for_each_sgtable_dma_sg (binding->sgt, sg, sg_idx) {dma_addr_t dma_addr =sg_dma_address (sg);
@@ -289,13 +267,13 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,NL_SET_ERR_MSG_FMT (extack,"dmabuf sg entry (addr=%pad, len=%zu) not aligned to niov size %zu" , &dma_addr, len, niov_size); - goto err_free_chunk_owner; + goto err_free_niovs; } nr_niovs = len >> niov_shift;for (i =0 ; i < nr_niovs; i++, niov_idx++) { - niov = &owner->area.niovs[niov_idx]; -net_iov_init (niov, &owner->area,NET_IOV_DMABUF ); + niov = &binding->area.niovs[niov_idx]; +net_iov_init (niov, &binding->area,NET_IOV_DMABUF );page_pool_set_dma_addr_netmem (net_iov_to_netmem (niov), dma_addr);if (direction ==DMA_TO_DEVICE )
@@ -310,17 +288,14 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, binding, xa_limit_32b, &id_alloc_next, GFP_KERNEL);if (err <0 ) - goto err_free_chunk_owner; + goto err_free_niovs;list_add (&binding->list, &priv->bindings);return binding; -err_free_chunk_owner: -net_devmem_dmabuf_free_chunk_owner (binding->chunk_owner); - goto err_free_freelist; -err_free_owner: -kfree (owner); +err_free_niovs: +kvfree (binding->area.niovs); err_free_freelist:kvfree (binding->freelist);kvfree (binding->tx_vec);
net/core/devmem.h +6 -19
@@ -14,9 +14,9 @@#include <net/netdev_netlink.h> struct netlink_ext_ack ; -struct dmabuf_genpool_chunk_owner ;struct net_devmem_dmabuf_binding { +struct net_iov_area area;struct dma_buf *dmabuf;struct dma_buf_attachment *attachment;struct sg_table *sgt;
@@ -27,7 +27,6 @@ struct net_devmem_dmabuf_binding {* dereferenced. */ void *vdev; -struct dmabuf_genpool_chunk_owner *chunk_owner;/* Protect dev */ struct mutex lock;
@@ -82,11 +81,6 @@ struct net_devmem_dmabuf_binding { };#if defined(CONFIG_NET_DEVMEM ) -struct dmabuf_genpool_chunk_owner { -struct net_iov_area area; -struct net_devmem_dmabuf_binding *binding; -}; -void __net_devmem_dmabuf_binding_free (struct work_struct *wq);struct net_devmem_dmabuf_binding * net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,
@@ -101,18 +95,11 @@ int net_devmem_bind_dmabuf_to_queue(struct net_device *dev, u32 rxq_idx,struct net_devmem_dmabuf_binding *binding, struct netlink_ext_ack *extack); -static inline struct dmabuf_genpool_chunk_owner * -net_devmem_iov_to_chunk_owner (const struct net_iov *niov) -{ -struct net_iov_area *owner =net_iov_owner (niov); - - return container_of(owner, struct dmabuf_genpool_chunk_owner, area); -} -static inline struct net_devmem_dmabuf_binding *net_devmem_iov_binding (const struct net_iov *niov) { -return net_devmem_iov_to_chunk_owner (niov)->binding; +return container_of (net_iov_owner (niov), + struct net_devmem_dmabuf_binding, area); }static inline u32 net_devmem_iov_binding_id (const struct net_iov *niov)
@@ -122,11 +109,11 @@ static inline u32 net_devmem_iov_binding_id(const struct net_iov *niov)static inline unsigned long net_iov_virtual_addr (const struct net_iov *niov) { -struct dmabuf_genpool_chunk_owner *co = -net_devmem_iov_to_chunk_owner (niov); +struct net_devmem_dmabuf_binding *binding = +net_devmem_iov_binding (niov);return net_iov_owner (niov)->base_virtual + - ((unsigned long )net_iov_idx (niov) << co->binding->niov_shift); + ((unsigned long )net_iov_idx (niov) << binding->niov_shift); } static inline bool
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1626/2651 net: devmem: check uid and netns in net_devmem_get_binding()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kaifeng Wang <[email protected]>
[ Upstream commit 3a82195416fd71fdd6cb4ff80f611ec28073be16 ]
NETDEV_CMD_BIND_TX is unprivileged, and dmabuf binding IDs are allocated from a single global xarray. Currently net_devmem_get_binding() looks up the binding by ID without checking whether the sending socket belongs to the same user or network namespace that created the binding.
Record the creating netlink socket's network namespace and UID on the binding, and verify both in net_devmem_get_binding() before checking the route destination device. Return -EINVAL on mismatch so callers cannot distinguish non-existent IDs from bindings owned by other users.
--- net/core/devmem.c | 7 ++++++- net/core/devmem.h | 5 +++++ net/core/netdev-genl.c | 5 +++-- 3 files changed, 14 insertions(+), 3 deletions(-)
net/core/devmem.c +6 -1
@@ -161,6 +161,7 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,enum dma_data_direction direction, unsigned int dmabuf_fd, unsigned int niov_shift, struct netdev_nl_sock *priv, + const struct sock *nl_sk, struct netlink_ext_ack *extack) { struct net_devmem_dmabuf_binding *binding;
@@ -191,6 +192,8 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev, binding->dev = dev; binding->vdev = vdev; +write_pnet (&binding->net,sock_net (nl_sk)); + binding->uid =sk_uid (nl_sk); binding->niov_shift = niov_shift;xa_init_flags (&binding->bound_rxqs,XA_FLAGS_ALLOC );
@@ -347,7 +350,9 @@ struct net_devmem_dmabuf_binding *net_devmem_get_binding(struct sock *sk,int err =0 ; binding =net_devmem_lookup_dmabuf (dmabuf_id); -if (!binding || !binding->tx_vec) { +if (!binding || !binding->tx_vec || + !net_eq (sock_net (sk),read_pnet (&binding->net)) || + !uid_eq (sk_uid (sk), binding->uid)) { err = -EINVAL ; goto out_err; }
net/core/devmem.h +5 -0
@@ -10,6 +10,7 @@#ifndef _NET_DEVMEM_H#define _NET_DEVMEM_H +#include <net/net_namespace.h> #include <net/netmem.h> #include <net/netdev_netlink.h>
@@ -27,6 +28,8 @@ struct net_devmem_dmabuf_binding {* dereferenced. */ void *vdev; +possible_net_t net; +kuid_t uid;/* Protect dev */ struct mutex lock;
@@ -88,6 +91,7 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,enum dma_data_direction direction, unsigned int dmabuf_fd, unsigned int niov_shift, struct netdev_nl_sock *priv, + const struct sock *nl_sk, struct netlink_ext_ack *extack);struct net_devmem_dmabuf_binding *net_devmem_lookup_dmabuf (u32 id);void net_devmem_unbind_dmabuf (struct net_devmem_dmabuf_binding *binding);
@@ -165,6 +169,7 @@ net_devmem_bind_dmabuf(struct net_device *dev, void *vdev,unsigned int dmabuf_fd, unsigned int niov_shift, struct netdev_nl_sock *priv, + const struct sock *nl_sk, struct netlink_ext_ack *extack) { return ERR_PTR(-EOPNOTSUPP);
net/core/netdev-genl.c +3 -2
@@ -1094,7 +1094,7 @@ int netdev_nl_bind_rx_doit(struct sk_buff *skb, struct genl_info *info) binding =net_devmem_bind_dmabuf (netdev,NULL , dma_dev,DMA_FROM_DEVICE , dmabuf_fd, niov_shift, priv, - info->extack); +NETLINK_CB (skb).sk, info->extack);if (IS_ERR (binding)) { err =PTR_ERR (binding); goto err_rxq_bitmap;
@@ -1243,7 +1243,8 @@ int netdev_nl_bind_tx_doit(struct sk_buff *skb, struct genl_info *info) binding =net_devmem_bind_dmabuf (bind_dev, bind_dev != netdev ? netdev :NULL , dma_dev,DMA_TO_DEVICE , dmabuf_fd, -PAGE_SHIFT , priv, info->extack); +PAGE_SHIFT , priv,NETLINK_CB (skb).sk, + info->extack);if (IS_ERR (binding)) { err =PTR_ERR (binding); goto err_unlock_bind_dev;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1627/2651 ALSA: control_led: Fix deadlock between sysfs writes and card disconnect
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ali Ahmet Memiş <[email protected]>
[ Upstream commit 682d6bb5f783adea7fa2a5b05166bff01b338081 ]
snd_ctl_led_disconnect() removes the ctl-led sysfs files while holding card->controls_rwsem. device_unregister() waits for running sysfs callbacks which can deadlock when a concurrent write causes the attach or detach callback to wait for controls_rwsem.
Break kernfs active protection in the attach, detach and list callbacks and hold a module reference instead.
--- sound/core/control_led.c | 62 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 5 deletions(-)
sound/core/control_led.c +57 -5
@@ -563,12 +563,43 @@ static ssize_t set_led_id(struct snd_ctl_led_card *led_card, const char *buf, sireturn count; } +/* +* snd_ctl_led_disconnect() removes these files with card->controls_rwsem +* held. so don't let the removal wait for a callback that takes it. +*/ +static struct kernfs_node *snd_ctl_led_sysfs_enter (struct device *dev, +struct device_attribute *attr) +{ +struct kernfs_node *kn; + +if (!try_module_get (THIS_MODULE )) +return NULL ; + kn =sysfs_break_active_protection (&dev->kobj, &attr->attr); +if (!kn) +module_put (THIS_MODULE ); +return kn; +} + +static void snd_ctl_led_sysfs_exit (struct kernfs_node *kn) +{ +sysfs_unbreak_active_protection (kn); +module_put (THIS_MODULE ); +} +static ssize_t attach_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t count) { struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev); -return set_led_id (led_card, buf, count, true); +struct kernfs_node *kn; +ssize_t ret; + + kn =snd_ctl_led_sysfs_enter (dev, attr); +if (!kn) +return -ENODEV ; + ret =set_led_id (led_card, buf, count, true); +snd_ctl_led_sysfs_exit (kn); +return ret; } static ssize_t detach_store(struct device *dev,
@@ -576,7 +607,15 @@ static ssize_t detach_store(struct device *dev, const char *buf, size_t count) { struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev); -return set_led_id (led_card, buf, count, false); +struct kernfs_node *kn; +ssize_t ret; + + kn =snd_ctl_led_sysfs_enter (dev, attr); +if (!kn) +return -ENODEV ; + ret =set_led_id (led_card, buf, count, false); +snd_ctl_led_sysfs_exit (kn); +return ret; } static ssize_t reset_store(struct device *dev,
@@ -594,10 +633,8 @@ static ssize_t reset_store(struct device *dev,return count; } -static ssize_t list_show (struct device *dev, -struct device_attribute *attr,char *buf) +static ssize_t snd_ctl_led_list (struct snd_ctl_led_card *led_card,char *buf) { - struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev);struct snd_ctl_led_ctl *lctl;size_t l =0 ; struct snd_card *card __free(snd_card_unref) =
@@ -620,6 +657,21 @@ static ssize_t list_show(struct device *dev,return l; } +static ssize_t list_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ + struct snd_ctl_led_card *led_card = container_of(dev, struct snd_ctl_led_card, dev); +struct kernfs_node *kn; +ssize_t ret; + + kn =snd_ctl_led_sysfs_enter (dev, attr); +if (!kn) +return -ENODEV ; + ret =snd_ctl_led_list (led_card, buf); +snd_ctl_led_sysfs_exit (kn); +return ret; +} +static DEVICE_ATTR_WO (attach);static DEVICE_ATTR_WO (detach);static DEVICE_ATTR_WO (reset);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1628/2651 drm/panfrost: Move shrinker initialization and unplug one level down
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrián Larumbe <[email protected]>
[ Upstream commit 80c4ff19d938a170bf487a11a1d7291c493ba22a ]
Since the moment we call drm_dev_register() the device should be in a position to accept jobs, so it's best if the shrinker is already initialized by then.
On top of that, make shrinker functions take an panfrost_device pointer like other functions in the same sequence and rename them accordingly.
Essentially mimic the init/fini behaviour in Panthor.
Stable-dep-of: e9672bf9382f ("drm/panfrost: Fix PM refcnt and autosuspend issues at device probe/remove")
--- drivers/gpu/drm/panfrost/panfrost_device.c | 8 +++++- drivers/gpu/drm/panfrost/panfrost_drv.c | 6 ----- drivers/gpu/drm/panfrost/panfrost_gem.c | 26 +++++++++++-------- drivers/gpu/drm/panfrost/panfrost_gem.h | 7 ++--- .../gpu/drm/panfrost/panfrost_gem_shrinker.c | 8 ++---- 5 files changed, 28 insertions(+), 27 deletions(-)
drivers/gpu/drm/panfrost/panfrost_device.c +7 -1
@@ -281,9 +281,14 @@ int panfrost_device_init(struct panfrost_device *pfdev)if (err) goto out_job; -panfrost_gem_init (pfdev); + err =panfrost_gem_init (pfdev); +if (err) + goto out_perfcnt;return 0 ; + +out_perfcnt: +panfrost_perfcnt_fini (pfdev); out_job:panfrost_jm_fini (pfdev); out_mmu:
@@ -305,6 +310,7 @@ int panfrost_device_init(struct panfrost_device *pfdev)void panfrost_device_fini (struct panfrost_device *pfdev) { +panfrost_gem_fini (pfdev);panfrost_perfcnt_fini (pfdev);panfrost_jm_fini (pfdev);panfrost_mmu_fini (pfdev);
drivers/gpu/drm/panfrost/panfrost_drv.c +0 -6
@@ -1003,14 +1003,9 @@ static int panfrost_probe(struct platform_device *pdev)if (err <0 ) goto err_out1; - err =panfrost_gem_shrinker_init (&pfdev->base); -if (err) - goto err_out2;return 0 ; -err_out2: -drm_dev_unregister (&pfdev->base); err_out1:pm_runtime_disable (pfdev->base.dev);panfrost_device_fini (pfdev);
@@ -1024,7 +1019,6 @@ static void panfrost_remove(struct platform_device *pdev)struct panfrost_device *pfdev =platform_get_drvdata (pdev);drm_dev_unregister (&pfdev->base); -panfrost_gem_shrinker_cleanup (&pfdev->base);pm_runtime_get_sync (pfdev->base.dev);pm_runtime_disable (pfdev->base.dev);
drivers/gpu/drm/panfrost/panfrost_gem.c +15 -11
@@ -15,20 +15,24 @@#include "panfrost_gem.h" #include "panfrost_mmu.h" -void panfrost_gem_init (struct panfrost_device *pfdev) +int panfrost_gem_init (struct panfrost_device *pfdev) { -int err; +if (IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE ) && panfrost_transparent_hugepage) { +int err =drm_gem_huge_mnt_create (&pfdev->base,"within_size" ); + +if (drm_gem_get_huge_mnt (&pfdev->base)) +drm_info (&pfdev->base,"Using Transparent Hugepage\n" ); +else if (err) +drm_warn (&pfdev->base,"Can't use Transparent Hugepage (%d)\n" , + err); + } -if (IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE ) && - !panfrost_transparent_hugepage) -return ; +return panfrost_gem_shrinker_init (pfdev); +} - err =drm_gem_huge_mnt_create (&pfdev->base,"within_size" ); -if (drm_gem_get_huge_mnt (&pfdev->base)) -drm_info (&pfdev->base,"Using Transparent Hugepage\n" ); -else if (err) -drm_warn (&pfdev->base,"Can't use Transparent Hugepage (%d)\n" , - err); +void panfrost_gem_fini (struct panfrost_device *pfdev) +{ +panfrost_gem_shrinker_fini (pfdev); }#ifdef CONFIG_DEBUG_FS
drivers/gpu/drm/panfrost/panfrost_gem.h +4 -3
@@ -129,7 +129,8 @@ drm_mm_node_to_panfrost_mapping(struct drm_mm_node *node) return container_of(node, struct panfrost_gem_mapping, mmnode); } -void panfrost_gem_init (struct panfrost_device *pfdev); +int panfrost_gem_init (struct panfrost_device *pfdev); +void panfrost_gem_fini (struct panfrost_device *pfdev);struct drm_gem_object *panfrost_gem_create_object (struct drm_device *dev,size_t size);
@@ -154,8 +155,8 @@ panfrost_gem_mapping_get(struct panfrost_gem_object *bo,void panfrost_gem_mapping_put (struct panfrost_gem_mapping *mapping);void panfrost_gem_teardown_mappings_locked (struct panfrost_gem_object *bo); -int panfrost_gem_shrinker_init (struct drm_device *dev); -void panfrost_gem_shrinker_cleanup (struct drm_device *dev); +int panfrost_gem_shrinker_init (struct panfrost_device *pfdev); +void panfrost_gem_shrinker_fini (struct panfrost_device *pfdev);void panfrost_gem_set_label (struct drm_gem_object *obj,const char *label); int panfrost_gem_sync(struct drm_gem_object *obj, u32 type,
drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c +2 -6
@@ -95,10 +95,8 @@ panfrost_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc)* * This function registers and sets up the panfrost shrinker. */ -int panfrost_gem_shrinker_init (struct drm_device *dev) +int panfrost_gem_shrinker_init (struct panfrost_device *pfdev) { -struct panfrost_device *pfdev =to_panfrost_device (dev); - pfdev->shrinker =shrinker_alloc (0 ,"drm-panfrost" );if (!pfdev->shrinker)return -ENOMEM ;
@@ -118,10 +116,8 @@ int panfrost_gem_shrinker_init(struct drm_device *dev)* * This function unregisters the panfrost shrinker. */ -void panfrost_gem_shrinker_cleanup (struct drm_device *dev) +void panfrost_gem_shrinker_fini (struct panfrost_device *pfdev) { -struct panfrost_device *pfdev =to_panfrost_device (dev); -if (pfdev->shrinker)shrinker_free (pfdev->shrinker); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1629/2651 drm/panfrost: Fix PM refcnt and autosuspend issues at device probe/remove
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrián Larumbe <[email protected]>
[ Upstream commit e9672bf9382ff80be21d586f88e50339b85f5766 ]
During device probe(), failure to do a PM get() will leave the usage_count set to 0, which is the value assigned at device creation time. That means when the autosuspend delay expires, runtime suspend callback won't be invoked, so the device will remain powered on forever.
On top of that, failure to call PM put() during device unplug means Panfrost device's PM usage_count increases monotonically for every new module reload.
The outcome of both of the above meant that:
- Devfreq OPP transition notifications would be printed all the time, even when no jobs are being submitted. This quickly fills the kernel ring buffer with junk.
- Because MMU interrupts are only enabled when the device is reset, the very first job targeting the tiler heap BO after device probe() would always time out, since the driver's PM runtime resume callback would not be invoked.
To fix the above:
- Manually adjust the PM refcnt at device probe and removal time.
- Ensure pm_runtime_dont_use_autosuspend is called in the wind-down path.
- Call pm_runtime_put_autosuspend() when device is ready to accept jobs
--- drivers/gpu/drm/panfrost/panfrost_drv.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/gpu/drm/panfrost/panfrost_drv.c +11 -0
@@ -989,6 +989,11 @@ static int panfrost_probe(struct platform_device *pdev) goto err_out0; } +/* The reason we must manually set the PM status and usage counter is +* we have just powered the device up but did not go through the PM +* runtime resume callback, so we need to update these ourselves. +*/ +pm_runtime_get_noresume (pfdev->base.dev);pm_runtime_set_active (pfdev->base.dev);pm_runtime_mark_last_busy (pfdev->base.dev);pm_runtime_enable (pfdev->base.dev);
@@ -1003,13 +1008,16 @@ static int panfrost_probe(struct platform_device *pdev)if (err <0 ) goto err_out1; +pm_runtime_put_autosuspend (pfdev->base.dev);return 0 ; err_out1: +pm_runtime_dont_use_autosuspend (pfdev->base.dev);pm_runtime_disable (pfdev->base.dev);panfrost_device_fini (pfdev);pm_runtime_set_suspended (pfdev->base.dev); +pm_runtime_put_noidle (pfdev->base.dev); err_out0:return err; }
@@ -1021,9 +1029,12 @@ static void panfrost_remove(struct platform_device *pdev)drm_dev_unregister (&pfdev->base);pm_runtime_get_sync (pfdev->base.dev); +pm_runtime_dont_use_autosuspend (pfdev->base.dev);pm_runtime_disable (pfdev->base.dev);panfrost_device_fini (pfdev);pm_runtime_set_suspended (pfdev->base.dev); +pm_runtime_put_noidle (pfdev->base.dev); + } static ssize_t profiling_show(struct device *dev,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1630/2651 drm/panfrost: Explicitly enable MMU interrupts at device init
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrián Larumbe <[email protected]>
[ Upstream commit 8a597d099b8b2f25df655cbe8e30765013784fed ]
Because the device must be in a position to accept jobs between the time drm_dev_register() is called and autosuspend first kicks in, there's a very narrow window inbetween during which jobs targeting the tiler buffer object would time out, since the device's PM status is 'Active', but no MMU interrupts were enabled at device initialisation time.
--- drivers/gpu/drm/panfrost/panfrost_mmu.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/gpu/drm/panfrost/panfrost_mmu.c +9 -2
@@ -336,6 +336,12 @@ void panfrost_mmu_as_put(struct panfrost_device *pfdev, struct panfrost_mmu *mmuWARN_ON (atomic_read (&mmu->as_count) <0 ); } +static void panfrost_mmu_enable_interrupts (struct panfrost_device *pfdev) +{ +mmu_write (pfdev,MMU_INT_CLEAR , ~0 ); +mmu_write (pfdev,MMU_INT_MASK , ~0 ); +} +void panfrost_mmu_reset (struct panfrost_device *pfdev) {struct panfrost_mmu *mmu, *mmu_tmp;
@@ -355,8 +361,7 @@ void panfrost_mmu_reset(struct panfrost_device *pfdev)spin_unlock (&pfdev->as_lock); -mmu_write (pfdev,MMU_INT_CLEAR , ~0 ); -mmu_write (pfdev,MMU_INT_MASK , ~0 ); +panfrost_mmu_enable_interrupts (pfdev); }static size_t get_pgsize (u64 addr,size_t size,size_t *count)
@@ -970,6 +975,8 @@ int panfrost_mmu_init(struct panfrost_device *pfdev)return err; } +panfrost_mmu_enable_interrupts (pfdev); +return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1631/2651 drm/panfrost: Move lock and modparam initialisations into their subsystems
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrián Larumbe <[email protected]>
[ Upstream commit ab2867234fa392f471ba27a6e1099260bce3d344 ]
The device init function feels a bit cluttered with things that should be done in the specific subsystems where those locks and lists are being used. Same goes for module parameters, it's best to limit them to the subsystems where they're relevant.
Then we can also discard panfrost_drv.h since the transparent_huge_page doesn't need to be accessed elsewhere. We can also simplify the creation of a mount point, because drm_gem_get_huge_mnt() would never return NULL if drm_gem_huge_mnt_create() returns 0 when kernel is built with support for transparent huge pages.
Stable-dep-of: 9944dd07f3cf ("drm/panfrost: Fix races between perfcnt and reset sequence")
--- drivers/gpu/drm/panfrost/panfrost_device.c | 7 ------- drivers/gpu/drm/panfrost/panfrost_drv.c | 10 ---------- drivers/gpu/drm/panfrost/panfrost_drv.h | 9 --------- drivers/gpu/drm/panfrost/panfrost_gem.c | 19 +++++++++++++------ .../gpu/drm/panfrost/panfrost_gem_shrinker.c | 3 +++ drivers/gpu/drm/panfrost/panfrost_gpu.c | 2 ++ drivers/gpu/drm/panfrost/panfrost_job.c | 1 + drivers/gpu/drm/panfrost/panfrost_mmu.c | 3 +++ 8 files changed, 22 insertions(+), 32 deletions(-) delete mode 100644 drivers/gpu/drm/panfrost/panfrost_drv.h
drivers/gpu/drm/panfrost/panfrost_device.c +0 -7
@@ -217,13 +217,6 @@ int panfrost_device_init(struct panfrost_device *pfdev) {int err; -mutex_init (&pfdev->sched_lock); -INIT_LIST_HEAD (&pfdev->as_lru_list); - -spin_lock_init (&pfdev->as_lock); - -spin_lock_init (&pfdev->cycle_counter.lock); -#ifdef CONFIG_DEBUG_FS mutex_init (&pfdev->debugfs.gems_lock);INIT_LIST_HEAD (&pfdev->debugfs.gems_list);
drivers/gpu/drm/panfrost/panfrost_drv.c +0 -10
@@ -21,7 +21,6 @@#include <drm/drm_timeout.h> #include "panfrost_device.h" -#include "panfrost_drv.h" #include "panfrost_gem.h" #include "panfrost_mmu.h" #include "panfrost_job.h"
@@ -955,12 +954,6 @@ static const struct drm_driver panfrost_drm_driver = {#endif }; -#ifdef CONFIG_TRANSPARENT_HUGEPAGE -bool panfrost_transparent_hugepage = true; -module_param_named (transparent_hugepage, panfrost_transparent_hugepage, bool,0400 ); -MODULE_PARM_DESC (transparent_hugepage,"Use a dedicated tmpfs mount point with Transparent Hugepage enabled (true = default)" ); -#endif -static int panfrost_probe (struct platform_device *pdev) {struct panfrost_device *pfdev;
@@ -979,9 +972,6 @@ static int panfrost_probe(struct platform_device *pdev) pfdev->coherent =device_get_dma_attr (&pdev->dev) ==DEV_DMA_COHERENT ; -mutex_init (&pfdev->shrinker_lock); -INIT_LIST_HEAD (&pfdev->shrinker_list); - err =panfrost_device_init (pfdev);if (err) {if (err != -EPROBE_DEFER )
drivers/gpu/drm/panfrost/panfrost_drv.h deleted +0 -9
@@ -1,9 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 or MIT */ -/* Copyright 2025 Amazon.com, Inc. or its affiliates */ - -#ifndef __PANFROST_DRV_H__ -#define __PANFROST_DRV_H__ - -extern bool panfrost_transparent_hugepage; - -#endif
drivers/gpu/drm/panfrost/panfrost_gem.c +13 -6
@@ -11,20 +11,27 @@#include <drm/panfrost_drm.h> #include <drm/drm_print.h> #include "panfrost_device.h" -#include "panfrost_drv.h" #include "panfrost_gem.h" #include "panfrost_mmu.h" +#ifdef CONFIG_TRANSPARENT_HUGEPAGE +static bool panfrost_transparent_hugepage = true; +module_param_named (transparent_hugepage, panfrost_transparent_hugepage, bool,0400 ); +MODULE_PARM_DESC (transparent_hugepage,"Use a dedicated tmpfs mount point with Transparent Hugepage enabled (true = default)" ); +#else +#define panfrost_transparent_hugepage false +#endif +int panfrost_gem_init (struct panfrost_device *pfdev) { -if (IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE ) && panfrost_transparent_hugepage) { +if (panfrost_transparent_hugepage) {int err =drm_gem_huge_mnt_create (&pfdev->base,"within_size" ); -if (drm_gem_get_huge_mnt (&pfdev->base)) +if (err) +drm_warn (&pfdev->base, +"Can't use Transparent Hugepage (%d)\n" , err); +else drm_info (&pfdev->base,"Using Transparent Hugepage\n" ); -else if (err) -drm_warn (&pfdev->base,"Can't use Transparent Hugepage (%d)\n" , - err); }return panfrost_gem_shrinker_init (pfdev);
drivers/gpu/drm/panfrost/panfrost_gem_shrinker.c +3 -0
@@ -97,6 +97,9 @@ panfrost_gem_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc)*/ int panfrost_gem_shrinker_init (struct panfrost_device *pfdev) { +mutex_init (&pfdev->shrinker_lock); +INIT_LIST_HEAD (&pfdev->shrinker_list); + pfdev->shrinker =shrinker_alloc (0 ,"drm-panfrost" );if (!pfdev->shrinker)return -ENOMEM ;
drivers/gpu/drm/panfrost/panfrost_gpu.c +2 -0
@@ -516,6 +516,8 @@ int panfrost_gpu_init(struct panfrost_device *pfdev) {int err; +spin_lock_init (&pfdev->cycle_counter.lock); + err =panfrost_gpu_soft_reset (pfdev);if (err)return err;
drivers/gpu/drm/panfrost/panfrost_job.c +1 -0
@@ -874,6 +874,7 @@ int panfrost_jm_init(struct panfrost_device *pfdev)INIT_WORK (&pfdev->reset.work, panfrost_reset_work);spin_lock_init (&js->job_lock); +mutex_init (&pfdev->sched_lock); js->irq =platform_get_irq_byname (to_platform_device (pfdev->base.dev),"job" );if (js->irq <0 )
drivers/gpu/drm/panfrost/panfrost_mmu.c +3 -0
@@ -960,6 +960,9 @@ int panfrost_mmu_init(struct panfrost_device *pfdev) {int err; +INIT_LIST_HEAD (&pfdev->as_lru_list); +spin_lock_init (&pfdev->as_lock); + pfdev->mmu_irq =platform_get_irq_byname (to_platform_device (pfdev->base.dev),"mmu" );if (pfdev->mmu_irq <0 )return pfdev->mmu_irq;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1632/2651 drm/panfrost: Move perfcnt GPU disable sequence into a helper
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrián Larumbe <[email protected]>
[ Upstream commit a2858e0f33eaba1c4a1976ba0ddebb1d83e21545 ]
Just for the sake of avoiding repetition.
Stable-dep-of: 9944dd07f3cf ("drm/panfrost: Fix races between perfcnt and reset sequence")
--- drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 31 +++++++++------------ 1 file changed, 13 insertions(+), 18 deletions(-)
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +13 -18
@@ -35,6 +35,16 @@ struct panfrost_perfcnt {struct completion dump_comp; }; +static void panfrost_perfcnt_hw_disable (struct panfrost_device *pfdev) +{ +gpu_write (pfdev,GPU_PERFCNT_CFG , +GPU_PERFCNT_CFG_MODE (GPU_PERFCNT_CFG_MODE_OFF )); +gpu_write (pfdev,GPU_PRFCNT_JM_EN ,0x0 ); +gpu_write (pfdev,GPU_PRFCNT_SHADER_EN ,0x0 ); +gpu_write (pfdev,GPU_PRFCNT_MMU_L2_EN ,0x0 ); +gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 ); +} +void panfrost_perfcnt_clean_cache_done (struct panfrost_device *pfdev) {complete (&pfdev->perfcnt->dump_comp);
@@ -193,12 +203,7 @@ static int panfrost_perfcnt_disable_locked(struct panfrost_device *pfdev,if (user != perfcnt->user)return -EINVAL ; -gpu_write (pfdev,GPU_PRFCNT_JM_EN ,0x0 ); -gpu_write (pfdev,GPU_PRFCNT_SHADER_EN ,0x0 ); -gpu_write (pfdev,GPU_PRFCNT_MMU_L2_EN ,0x0 ); -gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 ); -gpu_write (pfdev,GPU_PERFCNT_CFG , -GPU_PERFCNT_CFG_MODE (GPU_PERFCNT_CFG_MODE_OFF )); +panfrost_perfcnt_hw_disable (pfdev); perfcnt->user =NULL ;drm_gem_vunmap (&perfcnt->mapping->obj->base.base, &map);
@@ -327,12 +332,7 @@ int panfrost_perfcnt_init(struct panfrost_device *pfdev) perfcnt->bosize = size;/* Start with everything disabled. */ -gpu_write (pfdev,GPU_PERFCNT_CFG , -GPU_PERFCNT_CFG_MODE (GPU_PERFCNT_CFG_MODE_OFF )); -gpu_write (pfdev,GPU_PRFCNT_JM_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_SHADER_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_MMU_L2_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 ); +panfrost_perfcnt_hw_disable (pfdev);init_completion (&perfcnt->dump_comp);mutex_init (&perfcnt->lock);
@@ -344,10 +344,5 @@ int panfrost_perfcnt_init(struct panfrost_device *pfdev)void panfrost_perfcnt_fini (struct panfrost_device *pfdev) {/* Disable everything before leaving. */ -gpu_write (pfdev,GPU_PERFCNT_CFG , -GPU_PERFCNT_CFG_MODE (GPU_PERFCNT_CFG_MODE_OFF )); -gpu_write (pfdev,GPU_PRFCNT_JM_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_SHADER_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_MMU_L2_EN ,0 ); -gpu_write (pfdev,GPU_PRFCNT_TILER_EN ,0 ); +panfrost_perfcnt_hw_disable (pfdev); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1633/2651 drm/panfrost: Skip cache flush/invalidate when enabling perfcnt
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrián Larumbe <[email protected]>
[ Upstream commit 711a34a56d64d235ff74dbe53ba488ecd54e5570 ]
The GPU cache flush/invalidate operation is unnecessary. In the usual case, before a perfcnt dump is requested, there will be no stale lines in GPU caches for the sample BO's physmem pages, since their memory had not recently been addressed by the GPU.
However, in the off-chance that the sample BO reuses memory that the GPU had recently addressed and for which it contains stale lines in its caches, there already was a FLUSH_PT command being issued as part of the buffer GPU mapping procedure, so by the time panfrost_gem_open() comes back at perfcnt session enable, stale GPU cache lines should've already been evicted.
In either case, forcing a GPU cache clean when enabling a new session makes no difference, and removing it simplifies handling of the error path.
Stable-dep-of: 9944dd07f3cf ("drm/panfrost: Fix races between perfcnt and reset sequence")
--- drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +2 -13
@@ -124,21 +124,10 @@ static int panfrost_perfcnt_enable_locked(struct panfrost_device *pfdev,panfrost_gem_internal_set_label (&bo->base,"Perfcnt sample buffer" );/* -* Invalidate the cache and clear the counters to start from a fresh -* state. +* Clear the counters to start from a fresh state. */ -reinit_completion (&pfdev->perfcnt->dump_comp); -gpu_write (pfdev,GPU_INT_CLEAR , -GPU_IRQ_CLEAN_CACHES_COMPLETED | -GPU_IRQ_PERFCNT_SAMPLE_COMPLETED ); +gpu_write (pfdev,GPU_INT_CLEAR ,GPU_IRQ_PERFCNT_SAMPLE_COMPLETED );gpu_write (pfdev,GPU_CMD ,GPU_CMD_PERFCNT_CLEAR ); -gpu_write (pfdev,GPU_CMD ,GPU_CMD_CLEAN_INV_CACHES ); - ret =wait_for_completion_timeout (&pfdev->perfcnt->dump_comp, -msecs_to_jiffies (1000 )); -if (!ret) { - ret = -ETIMEDOUT ; - goto err_vunmap; - } ret =panfrost_mmu_as_get (pfdev, perfcnt->mapping->mmu);if (ret <0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1634/2651 drm/panfrost: Introduce a reset lock
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrián Larumbe <[email protected]>
[ Upstream commit 38fb4f01d7ee3a4dd7f8936ff2cb9dc0d0529f1a ]
In order to avoid accessing HW register while a reset is ongoing, a read/write semaphore that envelopes the reset sequence will help driver entry points avoid racing with it. For now, the only such racy entry point is the ioctl that returns the current GPU timestamp.
Stable-dep-of: 9944dd07f3cf ("drm/panfrost: Fix races between perfcnt and reset sequence")
--- drivers/gpu/drm/panfrost/panfrost_device.c | 2 ++ drivers/gpu/drm/panfrost/panfrost_device.h | 1 + drivers/gpu/drm/panfrost/panfrost_drv.c | 9 ++++++--- drivers/gpu/drm/panfrost/panfrost_job.c | 1 + 4 files changed, 10 insertions(+), 3 deletions(-)
drivers/gpu/drm/panfrost/panfrost_device.c +2 -0
@@ -417,6 +417,8 @@ bool panfrost_exception_needs_reset(const struct panfrost_device *pfdev,void panfrost_device_reset (struct panfrost_device *pfdev,bool enable_job_int) { +guard (rwsem_write)(&pfdev->reset.lock); +panfrost_gpu_soft_reset (pfdev);panfrost_gpu_power_on (pfdev);
drivers/gpu/drm/panfrost/panfrost_device.h +1 -0
@@ -165,6 +165,7 @@ struct panfrost_device {struct {struct workqueue_struct *wq;struct work_struct work; +struct rw_semaphore lock;atomic_t pending; } reset;
drivers/gpu/drm/panfrost/panfrost_drv.c +6 -3
@@ -41,9 +41,12 @@ static int panfrost_ioctl_query_timestamp(struct panfrost_device *pfdev,if (ret)return ret; -panfrost_cycle_counter_get (pfdev); - *arg =panfrost_timestamp_read (pfdev); -panfrost_cycle_counter_put (pfdev); +/* We should not read timestamp register while the GPU is being reset */ + scoped_guard(rwsem_read, &pfdev->reset.lock) { +panfrost_cycle_counter_get (pfdev); + *arg =panfrost_timestamp_read (pfdev); +panfrost_cycle_counter_put (pfdev); + }pm_runtime_put (pfdev->base.dev);return 0 ;
drivers/gpu/drm/panfrost/panfrost_job.c +1 -0
@@ -875,6 +875,7 @@ int panfrost_jm_init(struct panfrost_device *pfdev)INIT_WORK (&pfdev->reset.work, panfrost_reset_work);spin_lock_init (&js->job_lock);mutex_init (&pfdev->sched_lock); +init_rwsem (&pfdev->reset.lock); js->irq =platform_get_irq_byname (to_platform_device (pfdev->base.dev),"job" );if (js->irq <0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1635/2651 drm/panfrost: Fix races between perfcnt and reset sequence
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrián Larumbe <[email protected]>
[ Upstream commit 9944dd07f3cf7b6c19d65c2585147887ca06677c ]
Formerly, the reset sequence would race with panfrost_mmu_as_put() when tearing down a perfcnt session. On top of that, poking GPU registers to program a perfcnt session or obtaining a dump might lead to undefined behaviour when done at the same time a reset was ongoing.
Use the reset r/w semaphore when disabling and re-enabling perfcnt configuration, and also in the sections inside the 'enable'and 'dump' ioctls where device registers are being accessed.
On top of that, expand the DRM uAPI for the perfcnt DUMP operation so that user space can be made aware of a reset having happened, whether it succeeded or failed to restore the original configuration. UM needs to know about this condition because counter data is inaccurate after a reset, so the best approach might be simply to try again.
Finally, update driver uAPI documentation to explain the meaning of the new perfcnt dump ioctl's state flags, and bump DRM driver minor number to reflect the new DUMP IOCTL req field.
--- drivers/gpu/drm/panfrost/panfrost_device.c | 2 + drivers/gpu/drm/panfrost/panfrost_drv.c | 3 +- drivers/gpu/drm/panfrost/panfrost_perfcnt.c | 274 ++++++++++++++------ drivers/gpu/drm/panfrost/panfrost_perfcnt.h | 1 + include/uapi/drm/panfrost_drm.h | 29 ++- 5 files changed, 223 insertions(+), 86 deletions(-)
drivers/gpu/drm/panfrost/panfrost_device.c +2 -0
@@ -427,6 +427,8 @@ void panfrost_device_reset(struct panfrost_device *pfdev, bool enable_job_int)panfrost_jm_reset_interrupts (pfdev);if (enable_job_int)panfrost_jm_enable_interrupts (pfdev); + +panfrost_perfcnt_reset (pfdev); }static int panfrost_device_runtime_resume (struct device *dev)
drivers/gpu/drm/panfrost/panfrost_drv.c +2 -1
@@ -935,6 +935,7 @@ static void panfrost_debugfs_init(struct drm_minor *minor)* - 1.6 - adds PANFROST_BO_MAP_WB, PANFROST_IOCTL_SYNC_BO, * PANFROST_IOCTL_QUERY_BO_INFO and * DRM_PANFROST_PARAM_SELECTED_COHERENCY +* - 1.7 - adds PERFCNT_DUMP state field */ static const struct drm_driver panfrost_drm_driver = { .driver_features =DRIVER_RENDER |DRIVER_GEM |DRIVER_SYNCOBJ ,
@@ -947,7 +948,7 @@ static const struct drm_driver panfrost_drm_driver = { .name = "panfrost", .desc = "panfrost DRM", .major = 1, - .minor = 6, + .minor = 7, .gem_create_object = panfrost_gem_create_object, .gem_prime_import = panfrost_gem_prime_import,
drivers/gpu/drm/panfrost/panfrost_perfcnt.c +190 -84
378 lines not on this page · raw message
drivers/gpu/drm/panfrost/panfrost_perfcnt.h +1 -0
@@ -14,5 +14,6 @@ int panfrost_ioctl_perfcnt_enable(struct drm_device *dev, void *data, struct drm_file *file_priv);int panfrost_ioctl_perfcnt_dump (struct drm_device *dev,void *data,struct drm_file *file_priv); +void panfrost_perfcnt_reset (struct panfrost_device *pfdev);#endif
include/uapi/drm/panfrost_drm.h +28 -1
@@ -47,7 +47,7 @@ extern "C" {* them for anything but debugging purpose. */ #define DRM_IOCTL_PANFROST_PERFCNT_ENABLE DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_ENABLE, struct drm_panfrost_perfcnt_enable) -#define DRM_IOCTL_PANFROST_PERFCNT_DUMP DRM_IOW(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_DUMP, struct drm_panfrost_perfcnt_dump) +#define DRM_IOCTL_PANFROST_PERFCNT_DUMP DRM_IOWR(DRM_COMMAND_BASE + DRM_PANFROST_PERFCNT_DUMP, struct drm_panfrost_perfcnt_dump)#define PANFROST_JD_REQ_FS (1 << 0)#define PANFROST_JD_REQ_CYCLE_COUNT (1 << 1)
@@ -270,8 +270,35 @@ struct drm_panfrost_perfcnt_enable {__u32 counterset; }; +/* +* The next two flags describe the state of a perfcnt dump request +* as influenced by a device reset. They are the only values the +* perfcnt_dump ioctl state field can take on. +* Only certain state and ioctl retval combinations are legitimate. +*/ + +/* A new perfcnt_enable ioctl should be issued before requesting +* more dumps, because a HW reset failed to recreate perfcnt's +* original state. Otherwise further perfcnt_dump's will fail. +* This flag being set means ioctl's retval is always -EIO. +*/ +#define PANFROST_PERFCNT_SESSION_DEAD (1 << 0) + +/* A HW reset happened before or during a sample request, and +* perfcnt's internal state was successfully restored. There +* are two possible outcomes depending on the ioctl's retval: +* 0: A reset happened before a dump was requested, but did +* nonetheless succeed. Counter values are relative to last reset. +* -EAGAIN: A reset happened when a counter values sampling +* request was ongoing. Values are undefined so a new dump ioctl +* should be issued. +*/ +#define PANFROST_PERFCNT_SESSION_INTERRUPTED_BY_RESET (1 << 1) +struct drm_panfrost_perfcnt_dump {__u64 buf_ptr; +__u32 state; +__u32 pad;/* MBZ */ };/* madvise provides a way to tell the kernel in case a buffers contents
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1636/2651 ACPI: PCI: pci_link: clear driver_data before free
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
[ Upstream commit 691c33289b4d7a50b6fe1e03918bfbc21d4641c5 ]
acpi_pci_link_remove() frees the link object without clearing the ACPI device's driver_data pointer. The ACPI device survives hot-removal and can later be retrieved by acpi_fetch_acpi_dev(), leaving callers with a dangling pointer.
Clear driver_data before freeing the link.
--- drivers/acpi/pci_link.c | 1 + 1 file changed, 1 insertion(+)
drivers/acpi/pci_link.c +1 -0
@@ -787,6 +787,7 @@ static void acpi_pci_link_remove(struct acpi_device *device)list_del (&link->list);mutex_unlock (&acpi_link_lock); + device->driver_data =NULL ;kfree (link); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1637/2651 drm/rockchip: dw_hdmi_qp: Fix invalid drvdata access in PM ops
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cristian Ciocaltea <[email protected]>
[ Upstream commit b6e19848c9db535d81d6db85c7cc1324e6611791 ]
The system-sleep PM callbacks fetch the driver state via dev_get_drvdata() and dereference it unconditionally. However, the platform device is bound by ->probe(), which merely registers a component, hence the callbacks may well run when no valid state is available:
- Before the aggregate driver calls ->bind(), e.g. when the system suspends while probing is still deferred waiting for the VOP, dev_get_drvdata() returns NULL.
- After ->unbind(), or when ->bind() fails past platform_set_drvdata(), drvdata is left pointing to memory obtained via drmm_kzalloc(), which is released together with the DRM device, while this platform device remains bound and PM-capable.
Publish the driver data only after ->bind() completes successfully, and clear it in ->unbind(). This ensures that a non-NULL drvdata always represents live state, allowing each PM callback to rely on a single NULL check.
--- drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +9 -3
@@ -683,8 +683,6 @@ static int dw_hdmi_qp_rockchip_bind(struct device *dev, struct device *master,if (ret)return dev_err_probe (hdmi->dev, ret,"Failed to init encoder" ); -platform_set_drvdata (pdev, hdmi); - hdmi->hdmi =dw_hdmi_qp_bind (pdev, encoder, &plat_data);if (IS_ERR (hdmi->hdmi)) return dev_err_probe(hdmi->dev, PTR_ERR(hdmi->hdmi),
@@ -695,6 +693,8 @@ static int dw_hdmi_qp_rockchip_bind(struct device *dev, struct device *master,return dev_err_probe (hdmi->dev,PTR_ERR (connector),"Failed to init bridge connector\n" ); +platform_set_drvdata (pdev, hdmi); +return 0 ; }
@@ -704,6 +704,8 @@ static void dw_hdmi_qp_rockchip_unbind(struct device *dev, {struct rockchip_hdmi_qp *hdmi =dev_get_drvdata (dev); +dev_set_drvdata (dev,NULL ); +cancel_delayed_work_sync (&hdmi->hpd_work); }
@@ -726,7 +728,8 @@ static int __maybe_unused dw_hdmi_qp_rockchip_suspend(struct device *dev) {struct rockchip_hdmi_qp *hdmi =dev_get_drvdata (dev); -dw_hdmi_qp_suspend (dev, hdmi->hdmi); +if (hdmi) +dw_hdmi_qp_suspend (dev, hdmi->hdmi);return 0 ; }
@@ -735,6 +738,9 @@ static int __maybe_unused dw_hdmi_qp_rockchip_resume(struct device *dev) {struct rockchip_hdmi_qp *hdmi =dev_get_drvdata (dev); +if (!hdmi) +return 0 ; + hdmi->ctrl_ops->io_init (hdmi);dw_hdmi_qp_resume (dev, hdmi->hdmi);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1638/2651 drm/rockchip: dw_hdmi_qp: Cancel pending HPD work on suspend
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cristian Ciocaltea <[email protected]>
[ Upstream commit 5d0aa771a5308f6a6c83eeaa89351a472ae580c3 ]
The HPD threaded handler debounces hotplug events by delaying hdmi->hpd_work for 150 ms. Nothing discards that work when the system goes to sleep: drm_kms_helper_poll_disable() only disables the HPD IRQ line via the bridge .hpd_disable() op, and disable_irq() merely waits for the threaded handler, which has already returned after arming the timer.
If the debounce expires during suspend, its non-freezable work may probe the connector and read the EDID over DDC. Since genpd powers off the HDMI controller's power domain in ->suspend_noirq(), this access may hit unpowered hardware and hang the system.
Cancel the work in the suspend callback. The DRM device is registered as a consumer of the HDMI device, so it always suspends first and the HPD IRQ is already disabled by that point, meaning nothing can re-arm the work behind our back. No counterpart is needed on resume, as the work gets scheduled again on the next hotplug interrupt.
--- drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +6 -2
@@ -728,8 +728,12 @@ static int __maybe_unused dw_hdmi_qp_rockchip_suspend(struct device *dev) {struct rockchip_hdmi_qp *hdmi =dev_get_drvdata (dev); -if (hdmi) -dw_hdmi_qp_suspend (dev, hdmi->hdmi); +if (!hdmi) +return 0 ; + +cancel_delayed_work_sync (&hdmi->hpd_work); + +dw_hdmi_qp_suspend (dev, hdmi->hdmi);return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1639/2651 drm/rockchip: dw_hdmi_qp: Add missing newlines in dev_err_probe() messages
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cristian Ciocaltea <[email protected]>
[ Upstream commit 7554a1cb23148a3ab0b74c7edd47356c26b40ead ]
Add the missing trailing newlines to a couple of dev_err_probe() calls in dw_hdmi_qp_rockchip_bind().
--- drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/rockchip/dw_hdmi_qp-rockchip.c +2 -2
@@ -681,12 +681,12 @@ static int dw_hdmi_qp_rockchip_bind(struct device *dev, struct device *master,drm_encoder_helper_add (encoder, &dw_hdmi_qp_rockchip_encoder_helper_funcs); ret =drmm_encoder_init (drm, encoder,NULL ,DRM_MODE_ENCODER_TMDS ,NULL );if (ret) -return dev_err_probe (hdmi->dev, ret,"Failed to init encoder" ); +return dev_err_probe (hdmi->dev, ret,"Failed to init encoder\n" ); hdmi->hdmi =dw_hdmi_qp_bind (pdev, encoder, &plat_data);if (IS_ERR (hdmi->hdmi))return dev_err_probe (hdmi->dev,PTR_ERR (hdmi->hdmi), -"Failed to bind dw-hdmi-qp" ); +"Failed to bind dw-hdmi-qp\n" ); connector =drm_bridge_connector_init (drm, encoder);if (IS_ERR (connector))
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1640/2651 block: use iomap_dirty_folio for block devices
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tal Zussman <[email protected]>
[ Upstream commit be1e33eda3e6699e57ed3fe6e34078f115b4a1ec ]
With CONFIG_BUFFER_HEAD=n, block devices are written back through iomap, but def_blk_aops uses filemap_dirty_folio, which only sets PG_dirty. It does not set the per-block dirty bits in the folio's iomap_folio_state, so iomap_writeback_folio() finds no dirty range, submits no I/O and clears PG_dirty, resulting in data loss.
Other iomap users set .dirty_folio to iomap_dirty_folio, which marks the folio's blocks dirty before calling filemap_dirty_folio().
This is only observable with block size < folio size. With a single block there is no iomap_folio_state to get out of sync and iomap_writeback_folio() marks the whole folio dirty itself. For a page-aligned device, this may require using the BLKBSZSET ioctl to set the block size, which requires CAP_SYS_ADMIN. A device whose size is not page aligned already gets a sub-page block size from set_init_blocksize(), so no ioctl and no privilege is needed.
To reproduce, on a device with a sub-page block size, write a known pattern with O_DIRECT, mmap the same range, store to it, msync() and fsync(), then read it back with O_DIRECT. A reproducer is available at [1].
[1] https://gist.github.com/tzussman/18ab05cba4b3fdc79cce0a69d1fd05b4
--- block/fops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/fops.c +1 -1
@@ -565,7 +565,7 @@ static int blkdev_writepages(struct address_space *mapping, }const struct address_space_operations def_blk_aops = { - .dirty_folio = filemap_dirty_folio, + .dirty_folio = iomap_dirty_folio, .release_folio = iomap_release_folio, .invalidate_folio = iomap_invalidate_folio, .read_folio = blkdev_read_folio,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1641/2651 block: skip redundant flush for O_DSYNC direct writes
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhenxian Ma <[email protected]>
[ Upstream commit bec7d36a6514153ded6ffe1323ab14912ced42df ]
For an O_DIRECT | O_DSYNC write, dio_bio_write_op() adds REQ_FUA to the bio, so the data is durable once the direct I/O returns. The unconditional generic_write_sync() in blkdev_write_iter() then issues a REQ_PREFLUSH that is redundant.
Skip it when the direct path already provided durability via FUA. A need_sync flag, clear by default, is set only for buffered writes and for the buffered fallback after a partial direct write.
Measured on a Seagate ST20000NM007D (20 TB, 7200 rpm, fua=1, write_cache=write back), Linux v7.2.0-rc7, single-threaded pwrite() loop opening the raw block device with O_WRONLY | O_DIRECT | O_DSYNC, 4 KiB writes for 60 s:
Sequential 4 KiB writes:
baseline patched
IOPS 119.7 7497.0
avg latency (us) 8357 133
p50 latency (us) 8346 127
p99 latency (us) 8368 395
p99.9 latency (us) 8728 569Random 4 KiB writes (100 GiB span):
baseline patched
IOPS 156.1 666.4
avg latency (us) 6405 1500
p50 latency (us) 6186 1450
p99 latency (us) 16133 2285
p99.9 latency (us) 17250 9916Stable-dep-of: 2fec4fd97cc3 ("block: take i_rwsem for the direct I/O write fallback")
--- block/fops.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
block/fops.c +6 -2
@@ -733,6 +733,7 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)bool atomic = iocb->ki_flags &IOCB_ATOMIC ;loff_t size =bdev_nr_bytes (bdev);size_t shorted =0 ; +bool need_sync = false;ssize_t ret;if (bdev_read_only (bdev))
@@ -770,9 +771,11 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)if (iocb->ki_flags &IOCB_DIRECT ) { ret =blkdev_direct_write (iocb, from); -if (ret >=0 &&iov_iter_count (from)) +if (ret >=0 &&iov_iter_count (from)) { ret =direct_write_fallback (iocb, from, ret,blkdev_buffered_write (iocb, from)); + need_sync = true; + } }else {/* * Take i_rwsem and invalidate_lock to avoid racing with
@@ -782,9 +785,10 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)inode_lock_shared (bd_inode); ret =blkdev_buffered_write (iocb, from);inode_unlock_shared (bd_inode); + need_sync = true; } -if (ret >0 ) +if (ret >0 && need_sync) ret =generic_write_sync (iocb, ret);iov_iter_reexpand (from,iov_iter_count (from) + shorted);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1642/2651 block: only use REQ_FUA for direct writes if the device supports it
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhenxian Ma <[email protected]>
[ Upstream commit 0d492f40c4ad7af7b1625fd81dd58a7978ab97f6 ]
When a block device does not support FUA natively, the block layer emulates it by adding a cache flush to every write bio. An O_DSYNC direct write that spans N bios then costs N flushes, rather than the single generic_write_sync() issued after the write completes.
Introduce blkdev_dio_fua() to decide when REQ_FUA is set. A synchronous write can rely on generic_write_sync() when the device lacks FUA, so it sets REQ_FUA only when bdev_fua() is true. An asynchronous write completes in blkdev_bio_end_io() and cannot call the blocking generic_write_sync(), so it keeps REQ_FUA (emulated when needed) to stay durable.
Stable-dep-of: 2fec4fd97cc3 ("block: take i_rwsem for the direct I/O write fallback")
--- block/fops.c | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-)
block/fops.c +27 -5
@@ -26,12 +26,26 @@ static inline struct inode *bdev_file_inode(struct file *file)return file->f_mapping->host; } -static blk_opf_t dio_bio_write_op (struct kiocb *iocb) +static bool blkdev_dio_fua (struct kiocb *iocb,struct block_device *bdev) +{ +if (!iocb_is_dsync (iocb)) +return false; +/* +* Async writes cannot fall back to generic_write_sync(), so they must +* use FUA (emulated if needed); sync writes only need it when the +* device supports FUA natively. +*/ +if (!is_sync_kiocb (iocb)) +return true; +return bdev_fua (bdev); +} + +static blk_opf_t dio_bio_write_op (struct kiocb *iocb,struct block_device *bdev) {blk_opf_t opf =REQ_OP_WRITE |REQ_SYNC |REQ_IDLE ;/* avoid the need for a I/O completion work item */ -if (iocb_is_dsync (iocb)) +if (blkdev_dio_fua (iocb, bdev)) opf |=REQ_FUA ;return opf; }
@@ -75,7 +89,8 @@ static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb,if (user_backed_iter (iter)) should_dirty = true; }else { -bio_init (&bio, bdev, vecs, nr_pages,dio_bio_write_op (iocb)); +bio_init (&bio, bdev, vecs, nr_pages, +dio_bio_write_op (iocb, bdev)); } bio.bi_iter.bi_sector = pos >>SECTOR_SHIFT ; bio.bi_write_hint =file_inode (iocb->ki_filp)->i_write_hint;
@@ -179,7 +194,7 @@ static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *iter,struct blkdev_dio *dio;struct bio *bio;bool is_read = (iov_iter_rw (iter) ==READ ), is_sync; -blk_opf_t opf = is_read ?REQ_OP_READ :dio_bio_write_op (iocb); +blk_opf_t opf = is_read ?REQ_OP_READ :dio_bio_write_op (iocb, bdev);loff_t pos = iocb->ki_pos;int ret =0 ;
@@ -325,7 +340,7 @@ static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, unsigned int nr_pages) {bool is_read =iov_iter_rw (iter) ==READ ; -blk_opf_t opf = is_read ?REQ_OP_READ :dio_bio_write_op (iocb); +blk_opf_t opf = is_read ?REQ_OP_READ :dio_bio_write_op (iocb, bdev);struct blkdev_dio *dio;struct bio *bio;loff_t pos = iocb->ki_pos;
@@ -775,6 +790,13 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) ret =direct_write_fallback (iocb, from, ret,blkdev_buffered_write (iocb, from)); need_sync = true; + }else if (ret >0 && !blkdev_dio_fua (iocb, bdev)) { +/* +* The device does not support FUA, so REQ_FUA was not +* set and the O_DSYNC direct write still needs a flush +* to be made durable. +*/ + need_sync = true; } }else {/*
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1643/2651 block: take i_rwsem for the direct I/O write fallback
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tal Zussman <[email protected]>
[ Upstream commit 2fec4fd97cc3ce32283aac03b6882d3d36cbd4bb ]
Commit c0e473a0d226 ("block: fix race between set_blocksize and read paths") closed a race between set_blocksize() and block device I/O: with large sector size support, set_blocksize() can change i_blkbits and the mapping's minimum folio order while a concurrent reader still holds a folio of the old, smaller order, leading to crashes. In particular, it made blkdev_write_iter() wrap buffered writes in inode_lock_shared().
However, the direct I/O fallback path was missed in that conversion. blkdev_write_iter() passes blkdev_buffered_write() as an argument to direct_write_fallback() with no lock held. A direct write that completes only partially then finishes as a buffered write with no protection.
This can cause a BUG by racing partial direct writes against ioctl(BLKBSZSET). Writer threads issue O_DIRECT pwritev() with a two-segment iovec whose second segment is an unreadable PROT_NONE mapping. The direct path then writes the first segment, fails to pin the second, and returns short, entering the fallback. A second thread keeps toggling the second segment's protection so that some fallbacks get past fault_in_iov_iter_readable() and reach the page cache, a third thread populates the page cache with folios of the current block size via pread() and readahead(), and a fourth thread toggles the block size between 512 bytes and 64K with BLKBSZSET. The minimum folio order only moves with block sizes above PAGE_SIZE, i.e. with CONFIG_TRANSPARENT_HUGEPAGE raising BLK_MAX_BLOCK_SIZE to 64K.
On a CONFIG_DEBUG_VM kernel this yields the following BUG:
page dumped because: VM_BUG_ON_FOLIO(folio_order(folio) < mapping_min_folio_order(mapping)) kernel BUG at mm/filemap.c:858! Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI RIP: 0010:__filemap_add_folio+0x860/0x8d0 Call Trace: filemap_add_folio+0xc9/0x1f0 __filemap_get_folio_mpol+0x240/0x660 iomap_write_begin+0xa87/0xd70 iomap_file_buffered_write+0x304/0x6a0 blkdev_write_iter+0x255/0x510 do_iter_readv_writev+0x23d/0x3c0 vfs_writev+0x211/0x7d0 do_pwritev+0x121/0x190 do_syscall_64+0x121/0x630 entry_SYSCALL_64_after_hwframe+0x77/0x7f
The same workload also trips WARN_ON_ONCE(pos >= folio_pos(folio) + fsize) in iomap_trim_folio_range().
Fix this by calling blkdev_buffered_write() in the fallback path under inode_lock_shared(), matching the plain buffered-write branch. With the fix the same workload runs clean.
A short IOCB_NOWAIT direct write reaches the same fallback. Taking i_rwsem there can now block behind set_blocksize(), and the fallback already blocks on writeback of the data it copied in direct_write_fallback(). blkdev_write_iter() already rejects a purely buffered IOCB_NOWAIT write with -EOPNOTSUPP, so do not enter the fallback for IOCB_NOWAIT at all: return the bytes the direct path already wrote, or -EAGAIN if none, and let the caller retry.
The reproducer used was written by an LLM, and is available at [1].
[1] https://gist.github.com/tzussman/69d06bc57d42a42989eb038b1b5aeb74
--- block/fops.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
block/fops.c +22 -3
@@ -787,9 +787,28 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)if (iocb->ki_flags &IOCB_DIRECT ) { ret =blkdev_direct_write (iocb, from);if (ret >=0 &&iov_iter_count (from)) { - ret =direct_write_fallback (iocb, from, ret, -blkdev_buffered_write (iocb, from)); - need_sync = true; +if (iocb->ki_flags &IOCB_NOWAIT ) { +/* +* The buffered fallback blocks on i_rwsem and +* on writeback of the data it copied: return +* the short direct write instead and let the +* caller retry. The bytes already written +* still need a flush if REQ_FUA was not set. +*/ +if (!ret) + ret = -EAGAIN ; +else if (!blkdev_dio_fua (iocb, bdev)) + need_sync = true; + }else { +ssize_t ret2; + +inode_lock_shared (bd_inode); + ret2 =blkdev_buffered_write (iocb, from); +inode_unlock_shared (bd_inode); + ret =direct_write_fallback (iocb, from, ret, + ret2); + need_sync = true; + } }else if (ret >0 && !blkdev_dio_fua (iocb, bdev)) {/* * The device does not support FUA, so REQ_FUA was not
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1644/2651 block: take i_rwsem for the splice read path
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tal Zussman <[email protected]>
[ Upstream commit 5574b81c642e83d962732e86399020517f5f15af ]
def_blk_fops wires ->splice_read directly to filemap_splice_read(), which allocates folios based on mapping_min_folio_order() without any lock against set_blocksize(). A splice from a block device can race set_blocksize() raising the minimum folio order and insert a folio that is too small for the mapping. blkdev_read_iter() wraps filemap_read() in inode_lock_shared() for this reason, but the splice path was missed.
Splicing from a block device while toggling the block size between 512 bytes and 64K with BLKBSZSET hits this within seconds on a CONFIG_DEBUG_VM kernel:
page dumped because: VM_BUG_ON_FOLIO(folio_order(folio) < mapping_min_folio_order(mapping)) kernel BUG at mm/filemap.c:858! Oops: invalid opcode: 0000 [#1] SMP NOPTI RIP: 0010:__filemap_add_folio+0x51c/0x570 Call Trace: filemap_add_folio+0x64/0x140 page_cache_ra_order+0x1dd/0x3d0 filemap_get_pages+0x153/0x760 filemap_splice_read+0x13f/0x300 splice_file_to_pipe+0xc0/0xd0 do_splice+0x6a8/0x890 __do_splice+0xb0/0x210 __x64_sys_splice+0x80/0x100 do_syscall_64+0x10e/0x520 entry_SYSCALL_64_after_hwframe+0x77/0x7f
Take inode_lock_shared() around filemap_splice_read(), like the read path does.
--- block/fops.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
block/fops.c +17 -1
@@ -888,6 +888,22 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)return ret; } +/* +* Take i_rwsem to avoid racing with set_blocksize changing i_blkbits/folio +* order and punching out the pagecache. +*/ +static ssize_t blkdev_splice_read (struct file *in,loff_t *ppos, +struct pipe_inode_info *pipe,size_t len,unsigned int flags) +{ +struct inode *bd_inode =bdev_file_inode (in); +ssize_t ret; + +inode_lock_shared (bd_inode); + ret =filemap_splice_read (in, ppos, pipe, len, flags); +inode_unlock_shared (bd_inode); +return ret; +} +#define BLKDEV_FALLOC_FL_SUPPORTED \ (FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | \ FALLOC_FL_ZERO_RANGE | FALLOC_FL_WRITE_ZEROES)
@@ -989,7 +1005,7 @@ const struct file_operations def_blk_fops = {#ifdef CONFIG_COMPAT .compat_ioctl = compat_blkdev_ioctl, #endif - .splice_read = filemap_splice_read, + .splice_read = blkdev_splice_read, .splice_write = iter_file_splice_write, .fallocate = blkdev_fallocate, .uring_cmd = blkdev_uring_cmd,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1645/2651 block: honor IOCB_NOWAIT in the block device buffered read path
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tal Zussman <[email protected]>
[ Upstream commit d16519a561f4ccc2cebbf52831435833cac1fec6 ]
blkdev_read_iter() takes inode_lock_shared() unconditionally around filemap_read(). Unlike blkdev_write_iter(), it does not reject IOCB_NOWAIT for buffered I/O, so a non-blocking read, or the buffered tail of a short IOCB_NOWAIT direct read, blocks behind set_blocksize() holding i_rwsem across sync_blockdev().
A preadv2(RWF_NOWAIT) issued while another thread changes the block size with a dirty page cache blocks for as long as sync_blockdev() takes, 4 to 6 seconds on a scsi_debug device with delay=5.
Use inode_trylock_shared() for IOCB_NOWAIT and return the bytes the direct path already read, or -EAGAIN if none, when the lock is contended, preserving NOWAIT semantics.
--- block/fops.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
block/fops.c +9 -1
@@ -878,7 +878,15 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)* Take i_rwsem and invalidate_lock to avoid racing with set_blocksize * changing i_blkbits/folio order and punching out the pagecache. */ -inode_lock_shared (bd_inode); +if (iocb->ki_flags &IOCB_NOWAIT ) { +if (!inode_trylock_shared (bd_inode)) { +if (!ret) + ret = -EAGAIN ; + goto reexpand; + } + }else { +inode_lock_shared (bd_inode); + } ret =filemap_read (iocb, to, ret);inode_unlock_shared (bd_inode);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1646/2651 block: dont fall back to buffered I/O for atomic writes
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tal Zussman <[email protected]>
[ Upstream commit 9fd1afea19fa7c4ba438a1d162739e0832073a4c ]
blkdev_direct_write() turns an -EBUSY from page cache invalidation into a 0 return, so an IOCB_ATOMIC write is retried in full through blkdev_buffered_write(), with no atomicity guarantee.
Skip the buffered fallback in blkdev_write_iter() for IOCB_ATOMIC, as it already does for IOCB_NOWAIT, so the -EBUSY case returns -EAGAIN and the caller retries, matching __iomap_dio_rw().
ext4 has the same fallback and only warns in it. For block devices the fallback can be skipped before any I/O is submitted, so fail early instead.
--- block/fops.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
block/fops.c +3 -2
@@ -787,10 +787,11 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)if (iocb->ki_flags &IOCB_DIRECT ) { ret =blkdev_direct_write (iocb, from);if (ret >=0 &&iov_iter_count (from)) { -if (iocb->ki_flags &IOCB_NOWAIT ) { +if (iocb->ki_flags & (IOCB_NOWAIT |IOCB_ATOMIC )) {/* * The buffered fallback blocks on i_rwsem and -* on writeback of the data it copied: return +* on writeback of the data it copied, and +* can't provide torn-write protection: return * the short direct write instead and let the * caller retry. The bytes already written * still need a flush if REQ_FUA was not set.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1647/2651 block: unpin all pages of a bvec in bio_iov_iter_align_down()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tal Zussman <[email protected]>
[ Upstream commit b91a661514f3a3ce5add42fc1f2eb17b61eacaca ]
bio_iov_iter_align_down() drops trailing bvecs with unpin_user_page(), but a bvec built by iov_iter_extract_bvecs() can span several pages of one folio, each with its own pin. All but the first pin leak.
The partially trimmed bvec has the same problem. Shrinking bv_len does not release the pins for the pages cut off by the trim, and __bio_release_pages() only unpins the pages bv_len still covers at completion.
Both issues occur only with a logical block size above PAGE_SIZE and a large folio backing the user buffer. On a device with a 64K logical block size, an O_DIRECT pwritev() from a hugetlb mapping that ends 16K past a block boundary leaks one huge page per call, whether the remainder is its own bvec or the tail of a larger one.
Unpin all pages of a dropped bvec with bvec_unpin(), and unpin the pages trimmed off the last bvec as well. Move bvec_unpin() up and split its page count into a helper so both sites share it.
--- block/bio.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-)
block/bio.c +27 -12
@@ -1197,6 +1197,21 @@ bool bio_iov_iter_set(struct bio *bio, const struct iov_iter *iter)return true; } +static unsigned int bvec_nr_pages (const struct bio_vec *bv) +{ +return (bv->bv_offset + bv->bv_len -1 ) /PAGE_SIZE - + bv->bv_offset /PAGE_SIZE +1 ; +} + +static void bvec_unpin (struct bio_vec *bv,bool mark_dirty) +{ +struct folio *folio =bvec_folio (bv); + +if (mark_dirty) +folio_mark_dirty_lock (folio); +unpin_user_folio (folio,bvec_nr_pages (bv)); +} +/* * Aligns the bio size to the len_align_mask, releasing excessive bio vecs that * __bio_iov_iter_get_pages may have inserted, and reverts the trimmed length
@@ -1206,6 +1221,7 @@ static int bio_iov_iter_align_down(struct bio *bio, struct iov_iter *iter, struct bio_vec *bv, unsigned len_align_mask) { size_t nbytes = bio->bi_iter.bi_size & len_align_mask; +unsigned int npages;if (!nbytes)return 0 ;
@@ -1214,14 +1230,24 @@ static int bio_iov_iter_align_down(struct bio *bio, struct iov_iter *iter, bio->bi_iter.bi_size -= nbytes;while (nbytes >= bv->bv_len) {if (bio_flagged (bio,BIO_PAGE_PINNED )) -unpin_user_page (bv->bv_page); +bvec_unpin (bv, false);if (!--bio->bi_vcnt)return -EFAULT ; nbytes -= bv->bv_len; bv--; } + +/* +* __bio_release_pages() only unpins the pages still covered by +* the trimmed bv_len. Count the pages spanned before and after +* the trim and unpin the difference. +*/ + npages =bvec_nr_pages (bv); bv->bv_len -= nbytes; + npages -=bvec_nr_pages (bv); +if (npages &&bio_flagged (bio,BIO_PAGE_PINNED )) +unpin_user_folio (bvec_folio (bv), npages);return 0 ; }
@@ -1499,17 +1525,6 @@ int bio_iov_iter_bounce(struct bio *bio, struct iov_iter *iter, size_t maxlen,return bio_iov_iter_bounce_read (bio, iter, maxlen, minsize); } -static void bvec_unpin (struct bio_vec *bv,bool mark_dirty) -{ -struct folio *folio =bvec_folio (bv); -size_t nr_pages = (bv->bv_offset + bv->bv_len -1 ) /PAGE_SIZE - - bv->bv_offset /PAGE_SIZE +1 ; - -if (mark_dirty) -folio_mark_dirty_lock (folio); -unpin_user_folio (folio, nr_pages); -} -static void bio_iov_iter_unbounce_read (struct bio *bio,bool is_error,bool mark_dirty) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1648/2651 accel/amdxdna: Reject device heap BO when dev_mem_size is not set
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Zhang <[email protected]>
[ Upstream commit 3e32932d3626d0279f9b3531bd648f8c0a16cb08 ]
NPU3 devices do not set dev_mem_size, since they do not use a device heap. Creating an AMDXDNA_BO_DEV_HEAP BO on such a device hits the WARN_ON(!is_power_of_2(dev_mem_size)) check, which any user with access to the device node can trigger.
Return -EOPNOTSUPP when dev_mem_size is 0.
--- drivers/accel/amdxdna/amdxdna_gem.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/accel/amdxdna/amdxdna_gem.c +5 -0
@@ -1140,6 +1140,11 @@ amdxdna_drm_create_dev_heap_bo(struct drm_device *dev,struct amdxdna_gem_obj *abo;int ret; +if (!xdna->dev_info->dev_mem_size) { +XDNA_DBG (xdna,"Device heap is not supported" ); +return ERR_PTR (-EOPNOTSUPP ); + } +WARN_ON (!is_power_of_2 (xdna->dev_info->dev_mem_size));XDNA_DBG (xdna,"Requested dev heap size 0x%llx" , args->size);if (!args->size || !IS_ALIGNED (args->size, xdna->dev_info->dev_mem_size)) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1649/2651 net: stmmac: set real_num_tx_queues to max(offset + count)
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Bianconi <[email protected]>
[ Upstream commit d128212667593c548a3c67d30031063ed46c29b7 ]
tc_setup_dwmac510_mqprio() computes the number of real TX queues as the sum of the per-TC queue counts. mqprio_validate_queue_counts() only rejects out-of-bounds or overlapping ranges, so layouts with gaps or a non-zero first offset are accepted, and in those cases the sum is smaller than the highest queue referenced by the netdev TC map.
netif_set_real_num_tx_queues() then passes this too-small count to netif_setup_tc(). However stmmac_set_ndev_tcs() has already zeroed dev->prio_tc_map() through netdev_reset_tc(), so when netif_setup_tc() runs every priority maps to TC0 and only the TC0 range is checked. A layout whose TC0 range fits but where a later TC references a queue beyond the new real_num_tx_queues is left with num_tc set and its TC map pointing at queues that are no longer real, without any warning; only when TC0 itself is out of range is the mapping disabled. The real prio_tc_map is programmed later by the qdisc, after this call, so the driver cannot rely on netif_setup_tc() to catch those cases.
Compute num_tx_queues as the maximum of offset[i] + count[i] instead of the sum of the counts, so real_num_tx_queues always covers the highest queue referenced by the TC map. This is a no-op for the contiguous channel-mode layouts where offset[i] == i and count[i] == 1.
The issue has been reported by sashiko and the patch has been tested on Qualcomm RB3-Gen2 board.
--- drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c +2 -1
@@ -1303,7 +1303,8 @@ static int tc_setup_dwmac510_mqprio(struct stmmac_priv *priv, .count = qopt->count[i], .offset = qopt->offset[i], }; - num_tx_queues += qopt->count[i]; + num_tx_queues =max (num_tx_queues, + qopt->offset[i] + qopt->count[i]); } err =stmmac_set_ndev_tcs (ndev, qopt->num_tc, tc_to_txq);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1650/2651 net: stmmac: align real_num_tx_queues to mqprio configuration
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Bianconi <[email protected]>
[ Upstream commit ac1ca0c3e139a2ebef2fc6c570af6647329726f1 ]
stmmac_hw_setup() unconditionally sets the number of real TX queues to plat->tx_queues_to_use on every device open. When a tc-mqprio qdisc is offloaded the driver reduces netif_set_real_num_tx_queues() to the number of queues enabled by the offload, but the next device open reverts it to plat->tx_queues_to_use while the netdev TC map is still the one programmed by the qdisc, leaving the two inconsistent.
Track the number of TX queues enabled by the current qdisc configuration in the per-qdisc state (priv->xmit_qdisc.num_tx_queues) and use it in stmmac_hw_setup(). The field defaults to plat->tx_queues_to_use at probe time and when the mqprio qdisc is destroyed, meaning no offload is active and the number of real TX queues must match the number of queues the driver allocated, and it is updated to the offloaded queue count on a successful mqprio setup.
mqprio only validates the requested queue ranges against dev->real_num_tx_queues, which can be larger than plat->tx_queues_to_use while the interface has not been opened yet. Reject a qopt whose highest referenced queue (offset + count) exceeds plat->tx_queues_to_use, so xmit_qdisc.num_tx_queues can never be larger than the number of TX queues the driver provisions. Otherwise stmmac_hw_setup() would expose TX queues without an allocated DMA ring.
Refuse to lower the number of TX queues below the count required by the active mqprio offload in stmmac_reinit_queues(), otherwise netif_set_real_num_tx_queues() would leave real_num_tx_queues inconsistent with the netdev TC map.
The issue has been reported by sashiko and the patch has been tested on a Qualcomm RB3-Gen2 board.
--- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 6 ++++++ drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 12 +++++++++++- drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c | 13 +++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-)
drivers/net/ethernet/stmicro/stmmac/stmmac.h +6 -0
@@ -299,6 +299,12 @@ struct stmmac_priv {/* Protect est parameters */ struct mutex est_lock;struct stmmac_est *est; + +struct { +bool enabled; +u32 num_tx_queues; + } xmit_qdisc; +struct dma_features dma_cap;struct stmmac_counters mmc;int hw_cap_support;
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +11 -1
@@ -3747,7 +3747,7 @@ static int stmmac_hw_setup(struct net_device *dev)/* Configure real RX and TX queues */ netif_set_real_num_rx_queues (dev, priv->plat->rx_queues_to_use); -netif_set_real_num_tx_queues (dev, priv->plat->tx_queues_to_use); +netif_set_real_num_tx_queues (dev, priv->xmit_qdisc.num_tx_queues);/* Start the ball rolling... */ stmmac_start_all_dma (priv);
@@ -7627,6 +7627,10 @@ int stmmac_reinit_queues(struct net_device *dev, u8 rx_cnt, u8 tx_cnt)struct stmmac_priv *priv =netdev_priv (dev);int ret =0 , i; +if (priv->xmit_qdisc.enabled && + tx_cnt < priv->xmit_qdisc.num_tx_queues) +return -EINVAL ; +if (netif_running (dev))stmmac_release (dev);
@@ -7634,6 +7638,9 @@ int stmmac_reinit_queues(struct net_device *dev, u8 rx_cnt, u8 tx_cnt) priv->plat->rx_queues_to_use = rx_cnt; priv->plat->tx_queues_to_use = tx_cnt; +if (!priv->xmit_qdisc.enabled) + priv->xmit_qdisc.num_tx_queues = tx_cnt; +if (!netif_is_rxfh_configured (dev))for (i =0 ; i <ARRAY_SIZE (priv->rss.table); i++) priv->rss.table[i] = ethtool_rxfh_indir_default(i,
@@ -7946,6 +7953,9 @@ static int __stmmac_dvr_probe(struct device *device, ndev->xdp_features =NETDEV_XDP_ACT_BASIC |NETDEV_XDP_ACT_REDIRECT |NETDEV_XDP_ACT_XSK_ZEROCOPY ; +/* Default qdisc num_tx_queues */ + priv->xmit_qdisc.num_tx_queues = priv->plat->tx_queues_to_use; + ret =stmmac_tc_init (priv, priv);if (!ret) { ndev->hw_features |=NETIF_F_HW_TC ;
drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c +13 -0
@@ -1266,6 +1266,9 @@ static int stmmac_reset_tc_mqprio(struct net_device *ndev, {struct stmmac_priv *priv =netdev_priv (ndev); + priv->xmit_qdisc.num_tx_queues = priv->plat->tx_queues_to_use; + priv->xmit_qdisc.enabled = false; +netdev_reset_tc (ndev);netif_set_real_num_tx_queues (ndev, priv->plat->tx_queues_to_use);
@@ -1299,6 +1302,13 @@ static int tc_setup_dwmac510_mqprio(struct stmmac_priv *priv, ndev_prio_tc_map[i] =READ_ONCE (ndev->prio_tc_map[i]);for (i =0 ; i < qopt->num_tc; i++) { +if (qopt->offset[i] + qopt->count[i] > + priv->plat->tx_queues_to_use) { +NL_SET_ERR_MSG_MOD (extack, +"Queues exceed hw TX queues" ); +return -EINVAL ; + } + tc_to_txq[i] = (struct netdev_tc_txq ) { .count = qopt->count[i], .offset = qopt->offset[i],
@@ -1321,6 +1331,9 @@ static int tc_setup_dwmac510_mqprio(struct stmmac_priv *priv,if (err) goto error_reset_num_tx_queues; + priv->xmit_qdisc.num_tx_queues = num_tx_queues; + priv->xmit_qdisc.enabled = true; +return 0 ; error_reset_num_tx_queues:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1651/2651 btrfs: roll back sprout setup after device add failure
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guanghui Yang <[email protected]>
[ Upstream commit f5166f53b60b4d1ee9957c0baccd3b09735001d4 ]
btrfs_init_new_device() calls btrfs_setup_sprout() before creating the first writable chunks for a seed filesystem. That moves the seed devices out of fs_info->fs_devices, clears the seeding state and installs a new fsid for the sprout filesystem.
If a later step fails, the error path removes the new device but leaves fs_info->fs_devices in the partially initialized sprout state. The mounted filesystem can then be left with no open devices after the failed device add.
Add the inverse of btrfs_setup_sprout() and use it from the error path so the mounted seed filesystem is restored before the temporary seed_devices copy is released.
[ Fix a conflict with per-profile available space, revert sprout before
updating per-profile available space estimation. ]
--- fs/btrfs/volumes.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
fs/btrfs/volumes.c +37 -0
@@ -2814,6 +2814,41 @@ static void btrfs_setup_sprout(struct btrfs_fs_info *fs_info,btrfs_set_super_flags (disk_super, super_flags); } +static void btrfs_rollback_sprout (struct btrfs_fs_info *fs_info, +struct btrfs_fs_devices *seed_devices) +{ +struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; +struct btrfs_super_block *disk_super = fs_info->super_copy; +struct btrfs_device *device; +u64 super_flags; + +lockdep_assert_held (&uuid_mutex); +lockdep_assert_held (&fs_devices->device_list_mutex); + +list_del_init (&seed_devices->seed_list); +list_splice_init_rcu (&seed_devices->devices, &fs_devices->devices, synchronize_rcu); +list_for_each_entry (device, &fs_devices->devices, dev_list) { + device->fs_devices = fs_devices; + } + + fs_devices->seeding = true; + fs_devices->num_devices = seed_devices->num_devices; + fs_devices->open_devices = seed_devices->open_devices; + fs_devices->missing_devices = seed_devices->missing_devices; + fs_devices->rotating = seed_devices->rotating; + fs_devices->latest_dev = seed_devices->latest_dev; + +memcpy (fs_devices->fsid, seed_devices->fsid,BTRFS_FSID_SIZE ); +memcpy (fs_devices->metadata_uuid, seed_devices->metadata_uuid,BTRFS_FSID_SIZE ); +memcpy (disk_super->fsid, seed_devices->fsid,BTRFS_FSID_SIZE ); + + super_flags = (btrfs_super_flags (disk_super) |BTRFS_SUPER_FLAG_SEEDING ); +btrfs_set_super_flags (disk_super, super_flags); + + seed_devices->opened =0 ; +free_fs_devices (seed_devices); +} +/* * Store the expected generation for seed devices in device items. */
@@ -3165,6 +3200,8 @@ int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path orig_super_total_bytes);btrfs_set_super_num_devices (fs_info->super_copy, orig_super_num_devices); +if (seeding_dev) +btrfs_rollback_sprout (fs_info, seed_devices);btrfs_update_per_profile_avail (fs_info);mutex_unlock (&fs_info->chunk_mutex);mutex_unlock (&fs_info->fs_devices->device_list_mutex);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1652/2651 btrfs: refactor read_key_bytes() to remove the dest_folio parameter
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
[ Upstream commit fdf56b9d03d475881d73b75afbdbe4058db04ffc ]
The function read_key_bytes() have 3 call sites:
- For BTRFS_VERITY_DESC_ITEM_KEY offset 0 inside btrfs_get_verity_descriptor()
- For BTRFS_VERITY_DESC_ITEM_KEY offset 1 inside btrfs_get_verity_descriptor() Those are to read the description items, which are pretty small with fixed item size.
Those call sites do not utilize the @dest_folio parameter.
- For btrfs_read_merkle_tree_page()
This is to read the BTRFS_VERITY_MERKLE_ITEM_KEY, which can be pretty large and split into multiple items.
This is the only call site utilizing the @dest_folio parameter.
Just for the only btrfs_read_merkle_tree_page() call site, we have a complex scheme for @dest and @dest_folio parameters.
Since @dest can be NULL, it means if we pass @dest as NULL, then no matter if @dest_folio is provided, the merkle data will not be loaded into that @dest_folio.
This can lead to a bug where a highmem folio is not mapped, then we pass folio_address(folio), which is NULL, into read_key_bytes(), causing no data to be written into @dest_folio.
To address the complex scheme between @dest and @dest_folio, remove the @dest_folio parameter completely, and let the only caller to map the folio and pass the mapped kernel address into read_key_bytes() instead.
This not only reduces the parameter list, but also make it much clear on the @dest parameter handling.
The only downside is a longer duration of locally mapped page, but this should still be fine, as kmap_local_folio() can survive context switch.
--- fs/btrfs/verity.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-)
fs/btrfs/verity.c +14 -17
@@ -286,21 +286,17 @@ static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,* @dest: Buffer to read into. This parameter has slightly tricky * semantics. If it is NULL, the function will not do any copying * and will just return the size of all the items up to len bytes. -* If dest_page is passed, then the function will kmap_local the -* page and ignore dest, but it must still be non-NULL to avoid the -* counting-only behavior. * @len: length in bytes to read -* @dest_folio: copy into this folio instead of the dest buffer * * Helper function to read items from the btree. This returns the number of * bytes read or < 0 for errors. We can return short reads if the items don't * exist on disk or aren't big enough to fill the desired length. Supports -* reading into a provided buffer (dest) or into the page cache +* reading into a provided buffer (dest). * * Returns number of bytes read or a negative error code on failure. */ static int read_key_bytes (struct btrfs_inode *inode,u8 key_type,u64 offset, -char *dest,u64 len,struct folio *dest_folio) +char *dest,u64 len) {BTRFS_PATH_AUTO_FREE (path);struct btrfs_root *root = inode->root;
@@ -320,7 +316,11 @@ static int read_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,if (!path)return -ENOMEM ; -if (dest_folio) +/* +* Merkle items can be large and split across multiple items, so enable +* readahead for such cases. +*/ +if (key_type ==BTRFS_VERITY_MERKLE_ITEM_KEY ) path->reada =READA_FORWARD ; key.objectid =btrfs_ino (inode);
@@ -364,7 +364,7 @@ static int read_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,break ; } -/* desc = NULL to just sum all the item lengths */ +/* dest == NULL to just sum all the item lengths */ if (!dest) copy_end = item_end;else
@@ -377,16 +377,10 @@ static int read_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset, copy_offset = offset - key.offset;if (dest) { -if (dest_folio) - kaddr =kmap_local_folio (dest_folio,0 ); - data =btrfs_item_ptr (leaf, path->slots[0 ], void);read_extent_buffer (leaf, kaddr + dest_offset, (unsigned long )data + copy_offset, copy_bytes); - -if (dest_folio) -kunmap_local (kaddr); } offset += copy_bytes;
@@ -678,7 +672,7 @@ int btrfs_get_verity_descriptor(struct inode *inode, void *buf, size_t buf_size)memset (&item,0 ,sizeof (item)); ret =read_key_bytes (BTRFS_I (inode),BTRFS_VERITY_DESC_ITEM_KEY ,0 , - (char *)&item,sizeof (item),NULL ); + (char *)&item,sizeof (item));if (ret <0 )return ret;
@@ -695,7 +689,7 @@ int btrfs_get_verity_descriptor(struct inode *inode, void *buf, size_t buf_size)return -ERANGE ; ret =read_key_bytes (BTRFS_I (inode),BTRFS_VERITY_DESC_ITEM_KEY ,1 , - buf, buf_size,NULL ); + buf, buf_size);if (ret <0 )return ret;if (ret != true_size)
@@ -721,6 +715,7 @@ static struct page *btrfs_read_merkle_tree_page(struct inode *inode,struct folio *folio;u64 off = (u64 )index <<PAGE_SHIFT ;loff_t merkle_pos =merkle_file_pos (inode); +void *kaddr;int ret;if (merkle_pos <0 )
@@ -764,6 +759,7 @@ static struct page *btrfs_read_merkle_tree_page(struct inode *inode, } read_folio: + kaddr =kmap_local_folio (folio,0 );/* * Merkle item keys are indexed from byte 0 in the merkle tree. * They have the form:
@@ -771,7 +767,8 @@ static struct page *btrfs_read_merkle_tree_page(struct inode *inode,* [ inode objectid, BTRFS_MERKLE_ITEM_KEY, offset in bytes ] */ ret =read_key_bytes (BTRFS_I (inode),BTRFS_VERITY_MERKLE_ITEM_KEY , off, -folio_address (folio),PAGE_SIZE , folio); + kaddr,PAGE_SIZE ); +kunmap_local (kaddr);if (ret <0 ) {folio_unlock (folio);folio_put (folio);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1653/2651 btrfs: fix off by one super block end offset calculation when writing super blocks
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
[ Upstream commit 7884a8f3279c28ff990e2eacd5c2479bb1c930d0 ]
We are skipping the write of a super block mirror if its end offset matches exactly the device's end offset. This happens because we are using a greater than or equals comparison instead of just a greater than comparison.
--- fs/btrfs/disk-io.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/btrfs/disk-io.c +2 -4
@@ -3909,8 +3909,7 @@ static int write_dev_supers(struct btrfs_device *device,atomic_inc (&device->sb_write_errors);continue ; } -if (bytenr +BTRFS_SUPER_INFO_SIZE >= - device->commit_total_bytes) +if (bytenr +BTRFS_SUPER_INFO_SIZE > device->commit_total_bytes)break ;btrfs_set_super_bytenr (sb, bytenr_orig);
@@ -3988,8 +3987,7 @@ static int wait_dev_supers(struct btrfs_device *device, int max_mirrors) primary_failed = true;continue ; } -if (bytenr +BTRFS_SUPER_INFO_SIZE >= - device->commit_total_bytes) +if (bytenr +BTRFS_SUPER_INFO_SIZE > device->commit_total_bytes)break ; folio = filemap_get_folio(device->bdev->bd_mapping,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1654/2651 btrfs: fix dangling nodes in tree-mod-log after error in btrfs_tree_mod_log_insert_root()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
[ Upstream commit 057e3c350a9185df598c88b4081168ed047c9247 ]
If in btrfs_tree_mod_log_insert_root() there is an error in the call to tree_mod_log_insert() (the only possible error is -EEXIST, which means we have a bug or some memory corruption maybe) we free all the nodes in the 'tm_list' array but we don't remove them from the tree-mod-log rbtree, which can result in use-after-free bugs later.
So make sure we remove the nodes from the rbtree before freeing them after an error.
--- fs/btrfs/tree-mod-log.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
fs/btrfs/tree-mod-log.c +10 -3
@@ -483,10 +483,17 @@ int btrfs_tree_mod_log_insert_root(struct extent_buffer *old_root, goto out_unlock; } -if (tm_list) +if (tm_list) { ret =tree_mod_log_free_eb (fs_info, tm_list, nritems); -if (!ret) - ret =tree_mod_log_insert (fs_info, tm); +if (ret) + goto out_unlock; + } + + ret =tree_mod_log_insert (fs_info, tm); +if (ret && tm_list) { +for (i =0 ; i < nritems; i++) +rb_erase (&tm_list[i]->node, &fs_info->tree_mod_log); + } out_unlock:write_unlock (&fs_info->tree_mod_log_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1655/2651 btrfs: zoned: fix double list add in btrfs_load_block_group_zone_info
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Thumshirn <[email protected]>
[ Upstream commit 9bdef63e2b5d4a88810329a1cab3642d6378a895 ]
For DUP and RAID profiles with zones in a mismatching active state, i.e. due to one of the zones of the block-group being on a conventional zone, btrfs_zone_activate() has already put the block group on the list.
This leads to a double list add and refcounting problems.
--- fs/btrfs/zoned.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
fs/btrfs/zoned.c +5 -3
@@ -2005,10 +2005,12 @@ int btrfs_load_block_group_zone_info(struct btrfs_block_group *cache, bool new)if (!ret) { cache->meta_write_pointer = cache->alloc_offset + cache->start;if (test_bit (BLOCK_GROUP_FLAG_ZONE_IS_ACTIVE , &cache->runtime_flags)) { -btrfs_get_block_group (cache);spin_lock (&fs_info->zone_active_bgs_lock); -list_add_tail (&cache->active_bg_list, - &fs_info->zone_active_bgs); +if (list_empty (&cache->active_bg_list)) { +btrfs_get_block_group (cache); +list_add_tail (&cache->active_bg_list, + &fs_info->zone_active_bgs); + }spin_unlock (&fs_info->zone_active_bgs_lock); } }else {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1656/2651 btrfs: fix incomplete iteration over fs state when logging messages
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
[ Upstream commit d1d74665ab9a8971d42177ca865cfbe2897c1fc7 ]
In btrfs_state_to_string() we iterate over all the bits set in fs_info->fs_state using for_each_set_bit(), which requires its third argument to match the number of bits, but we pass it the number of bytes of the type used by fs_info->fs_state, an unsigned long, which is 8 on 64 bits platforms and 4 on 32 bits platforms. This means we are not iterating over bits in the ranges [8, 63] or [4, 31].
Fix this by passing BTRFS_FS_STATE_COUNT instead of sizeof(fs_state). Note that we could pass BITS_PER_TYPE(fs_state), but since BTRFS_FS_STATE_COUNT is 11 and we have no bits beyond that, it would cause pointless iterations over fs_state.
This also makes pointless the checks for the bit being inside the limit of BTRFS_FS_STATE_COUNT inside the loop.
--- fs/btrfs/messages.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
fs/btrfs/messages.c +2 -3
@@ -42,9 +42,8 @@ static void btrfs_state_to_string(const struct btrfs_fs_info *info, char *buf) states_printed = true; } -for_each_set_bit (bit, &fs_state,sizeof (fs_state)) { -WARN_ON_ONCE (bit >=BTRFS_FS_STATE_COUNT ); -if ((bit <BTRFS_FS_STATE_COUNT ) && fs_state_chars[bit]) { +for_each_set_bit (bit, &fs_state,BTRFS_FS_STATE_COUNT ) { +if (fs_state_chars[bit]) { *curr++ = fs_state_chars[bit]; states_printed = true; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1657/2651 btrfs: fix duplicated code in fs state string in logged messages
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
[ Upstream commit 3edda5249553b708c378a0d766018976315c63ad ]
We are using the code 'E' when the fs is in an error state (transaction aborted) and when it's in the emergency shutdown state, which is confusing and not intentional. Fix this by using an unused code such as 'H' for the emergency shutdown state and add a comment over the fs_state_chars array to warn to not use 'E' as its use is not defined in the array but instead in the function btrfs_state_to_string(), since the fs state error is not defined as a bit but as an error code in fs_info->fs_error.
--- fs/btrfs/messages.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/btrfs/messages.c +3 -1
@@ -13,6 +13,8 @@/* * Characters to print to indicate error conditions or uncommon filesystem state. * RO is not an error. +* Don't use 'E' because that's used to signal that there's an error stored in +* fs_info->fs_error (see btrfs_state_to_string() below). */ static const char fs_state_chars[] = { [BTRFS_FS_STATE_REMOUNTING ] ='M' ,
@@ -24,7 +26,7 @@ static const char fs_state_chars[] = { [BTRFS_FS_STATE_NO_DATA_CSUMS] = 'C', [BTRFS_FS_STATE_SKIP_META_CSUMS] = 'S', [BTRFS_FS_STATE_LOG_CLEANUP_ERROR] = 'L', - [BTRFS_FS_STATE_EMERGENCY_SHUTDOWN] = 'E', + [BTRFS_FS_STATE_EMERGENCY_SHUTDOWN] = 'H', };static void btrfs_state_to_string (const struct btrfs_fs_info *info,char *buf)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1658/2651 btrfs: fix off-by-one end offset check in report_setget_bounds()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
[ Upstream commit 08f750d9f8930e4ca053913b5ca3fd49fd9268c9 ]
The addressable range with an extent buffer goes from byte 0 to byte eb->len - 1, so if a byte address matches eb->len, it's already beyond the addressable range and we should log that it's bad start address and not end address.
--- fs/btrfs/accessors.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/accessors.c +1 -1
@@ -16,7 +16,7 @@ static void __cold report_setget_bounds(const struct extent_buffer *eb,btrfs_warn (eb->fs_info,"bad eb member %s: ptr 0x%lx start %llu member offset %lu size %d" , - (member_offset > eb->len ?"start" :"end" ), + (member_offset >= eb->len ?"start" :"end" ), (unsigned long )ptr, eb->start, member_offset, size); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1659/2651 btrfs: qgroup: do not treat "ret > 0" as error when deleting a qgroup
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
[ Upstream commit dd906477cc2c33c82ec17e6301bd4be4ea588565 ]
[BUG]
There is a bug report that when removing a child qgroup, if removing the qgroup requires a rescan, it will delete the on-disk relation and qgroup items but not the in-memory qgroup rb entry.
This makes all later qgroup rescan to fail.
[CAUSE]
The call chain looks like the following:
btrfs_remove_qgroup()
|- __del_qgroup_relation() | |- quick_update_accounting() | Which returns 1, showing this operation will require | a qgroup rescan |- if (ret) goto out;
Which skips the del_qgroup_rb() call, leaving the in-memory qgroup rb entry still intact.
Then later qgroup rescan/update will always fail and mark qgroup inconsistent:
btrfs_run_qgroups()
|- update_qgroup_info_item() | |- btrfs_search_slot() | Which returns -ENOENT, as the qgroup info item is already | deleted. |- qgroup_mark_inconsistent() |- return -ENOENT;
[FIX]
Do not treat "ret > 0" as an error.
--- fs/btrfs/qgroup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/qgroup.c +1 -1
@@ -1845,7 +1845,7 @@ int btrfs_remove_qgroup(struct btrfs_trans_handle *trans, u64 qgroupid) struct btrfs_qgroup_list, next_group); ret =__del_qgroup_relation (trans, qgroupid, list->group->qgroupid); -if (ret) +if (ret <0 ) goto out; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1660/2651 btrfs: qgroup: fix swapped blocks existence check when tracing after COW
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
[ Upstream commit 0388b5bd3a6eb8bcb20208c3b6dbee96fd30bbe0 ]
In btrfs_qgroup_trace_subtree_after_cow(), after we erase the swapped block, iterate over all possible tree levels to check if we sill have other swapped blocks. However the check is wrong, it considers that there are other swapped blocks if any rbtree for any level is empty, instead of not empty. As a consequence we set blocks->swapped to true basically every time since we always find an empty rbtree at least at level 7, since in practice it's nearly impossible to find such a huge btree. This makes every future call to btrfs_qgroup_trace_subtree_after_cow() do an unnecessary rbtree search instead of returning immediately.
Fix this by updating the condition to set swapped to true if we find an rbtree that is not empty.
--- fs/btrfs/ctree.h | 2 +- fs/btrfs/qgroup.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/ctree.h +1 -1
@@ -160,7 +160,7 @@ enum {*/ struct btrfs_qgroup_swapped_blocks {spinlock_t lock; -/* RM_EMPTY_ROOT() of above blocks[] */ +/* True if any of the rbtrees in the blocks array below is not empty. */ bool swapped;struct rb_root blocks[BTRFS_MAX_LEVEL ]; };
fs/btrfs/qgroup.c +1 -1
@@ -4887,7 +4887,7 @@ int btrfs_qgroup_trace_subtree_after_cow(struct btrfs_trans_handle *trans,/* Found one, remove it from @blocks first and update blocks->swapped */ rb_erase (&block->node, &blocks->blocks[level]);for (i =0 ; i <BTRFS_MAX_LEVEL ; i++) { -if (RB_EMPTY_ROOT (&blocks->blocks[i])) { +if (!RB_EMPTY_ROOT (&blocks->blocks[i])) { swapped = true;break ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1661/2651 btrfs: fix lost error return value in btrfs_alloc_logged_file_extent()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
[ Upstream commit 784cd5a83476c6c720521f21350fb823928555ff ]
If we fail to allocate a reserved file extent we then call btrfs_record_squota_delta() and assign its return value to 'ret', discarding the error from the failed allocation attempt and allowing log replay to proceed as if no errors happened, resulting in some replayed file extent item to point to an unallocated extent. At the moment btrfs_record_squota_delta() always returns 0 (success).
--- fs/btrfs/extent-tree.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/extent-tree.c +2 -1
@@ -5227,7 +5227,8 @@ int btrfs_alloc_logged_file_extent(struct btrfs_trans_handle *trans, offset, ins, 1, root_objectid);if (ret)btrfs_pin_extent (trans, ins->objectid, ins->offset); - ret =btrfs_record_squota_delta (fs_info, &delta); +else + ret =btrfs_record_squota_delta (fs_info, &delta);btrfs_put_block_group (block_group);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1662/2651 btrfs: defrag: fix check to see if next extent can be defragged too
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
[ Upstream commit eb55bc2bfe204e6bfccfe179226d7fb5024cb010 ]
We want to check if the next extent is at maximum capacity but we are passing the current extent map to get_extent_max_capacity() and not the next extent map. For example if the current extent is compressed (its maximum capacity is 128K) and the next extent is uncompressed (its maximum capacity is 128M), then we can bail out and not defrag the next extent too - when for example the next extent as a size of 128K, is uncompressed, and the extent threshold is >= 256K.
--- fs/btrfs/defrag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/defrag.c +1 -1
@@ -815,7 +815,7 @@ static bool defrag_check_next_extent(struct inode *inode, struct extent_map *em,* If the next extent is at its max capacity, defragging current extent * makes no sense, as the total number of extents won't change. */ -if (next->len >=get_extent_max_capacity (fs_info, em)) +if (next->len >=get_extent_max_capacity (fs_info, next)) goto out;/* Skip older extent */ if (next->generation < newer_than)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1663/2651 power: supply: generic-adc-battery: Propagate charged GPIO errors
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit 36b0abe904ac9cbdce6161d9c7c0bcac963bb3fe ]
devm_gpiod_get_optional() may return an error pointer such as -EPROBE_DEFER, but gab_probe() only checks for NULL. The error pointer is then passed to gpiod_to_irq() and the original error, including -EPROBE_DEFER, is lost.
Check the return value and propagate errors from the charged GPIO lookup.
--- drivers/power/supply/generic-adc-battery.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/power/supply/generic-adc-battery.c +3 -0
@@ -243,6 +243,9 @@ static int gab_probe(struct platform_device *pdev)return dev_err_probe (&pdev->dev, ret,"Failed to register delayed work\n" ); adc_bat->charge_finished =devm_gpiod_get_optional (&pdev->dev,"charged" ,GPIOD_IN ); +if (IS_ERR (adc_bat->charge_finished)) +return dev_err_probe (&pdev->dev,PTR_ERR (adc_bat->charge_finished), +"failed to get charged GPIO\n" );if (adc_bat->charge_finished) {int irq;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1664/2651 mtd: rawnand: pl353: fix clk reference leak in pl35x_nfc_setup_interface()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haotian Zhang <[email protected]>
[ Upstream commit 1ce45f0e74d60e8279ed380c97047e6c351aee1b ]
pl35x_nfc_setup_interface() obtains a reference to the SMC "memclk" with of_clk_get_by_name() and only uses it to read the clock rate. The reference is never released: the function has many early return paths and no clk_put() call anywhere, so the clock reference is leaked.
The hook is invoked repeatedly by the NAND core (nand_reset(), nand_setup_interface() and the NAND_DATA_IFACE_CHECK_ONLY mode probing loops), so the reference count keeps growing.
Release the clock reference with clk_put() as soon as its rate has been read.
--- drivers/mtd/nand/raw/pl35x-nand-controller.c | 1 + 1 file changed, 1 insertion(+)
drivers/mtd/nand/raw/pl35x-nand-controller.c +1 -0
@@ -807,6 +807,7 @@ static int pl35x_nfc_setup_interface(struct nand_chip *chip, int cs,* macro to convert from one to the other. */ period_ns =NSEC_PER_SEC /clk_get_rate (mclk); +clk_put (mclk);/* * PL35X SMC needs one extra read cycle in SDR Mode 5. This is not
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1665/2651 nfs: set gencount on protocol-specific remove
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Roberto Bergantinos Corpas <[email protected]>
[ Upstream commit 8c955dacf45f8964b98f26910ffecb5e26c02e31 ]
commit bd4928ec799b ("NFS: Avoid changing nlink when file removes and attribute updates race") avoids races on attribute cache with any inflight RPC that may modify inode attributes (and gencount) during i.e. REMOVE.
However it does not take into account that REMOVE may trigger a delegation return which also advances gencount (via the attribute refresh during delegation return), and in that case the gencount mismatch is not due to an inflight RPC that already reflected the removal.
Push the setting of gencount under each version-specific layer, reordering correctly for nfsv4 case after the delegation returns.
This fixes LTP/inotify04 failure after bd4928ec799b.
--- fs/nfs/dir.c | 13 +++---------- fs/nfs/internal.h | 1 + fs/nfs/nfs3proc.c | 8 ++++++++ fs/nfs/nfs4proc.c | 5 +++++ fs/nfs/proc.c | 8 ++++++++ 5 files changed, 25 insertions(+), 10 deletions(-)
fs/nfs/dir.c +3 -10
@@ -1935,7 +1935,7 @@ static int nfs_dentry_delete(const struct dentry *dentry) }/* Ensure that we revalidate inode->i_nlink */ -static void nfs_drop_nlink (struct inode *inode,unsigned long gencount) +void nfs_drop_nlink (struct inode *inode,unsigned long gencount) {struct nfs_inode *nfsi =NFS_I (inode);
@@ -1949,6 +1949,7 @@ static void nfs_drop_nlink(struct inode *inode, unsigned long gencount) NFS_INO_INVALID_NLINK);spin_unlock (&inode->i_lock); } +EXPORT_SYMBOL_GPL (nfs_drop_nlink);/* * Called when the dentry loses inode.
@@ -2556,7 +2557,6 @@ EXPORT_SYMBOL_GPL(nfs_rmdir);static int nfs_safe_remove (struct dentry *dentry) {struct inode *dir =d_inode (dentry->d_parent); -struct inode *inode =d_inode (dentry);int error = -EBUSY ;dfprintk (VFS ,"NFS: safe_remove(%pd2)\n" , dentry);
@@ -2568,14 +2568,7 @@ static int nfs_safe_remove(struct dentry *dentry) }trace_nfs_remove_enter (dir, dentry); -if (inode !=NULL ) { -unsigned long gencount =READ_ONCE (NFS_I (inode)->attr_gencount); - - error =NFS_PROTO (dir)->remove (dir, dentry); -if (error ==0 ) -nfs_drop_nlink (inode, gencount); - }else - error =NFS_PROTO (dir)->remove (dir, dentry); + error =NFS_PROTO (dir)->remove (dir, dentry);if (error == -ENOENT )nfs_dentry_handle_enoent (dentry);trace_nfs_remove_exit (dir, dentry, error);
fs/nfs/internal.h +1 -0
@@ -394,6 +394,7 @@ extern unsigned long nfs_access_cache_count(struct shrinker *shrink, struct shrink_control *sc);extern unsigned long nfs_access_cache_scan (struct shrinker *shrink,struct shrink_control *sc); +extern void nfs_drop_nlink (struct inode *inode,unsigned long gencount);struct dentry *nfs_lookup (struct inode *,struct dentry *,unsigned int );void nfs_d_prune_case_insensitive_aliases (struct inode *inode); int nfs_create(struct mnt_idmap *, struct inode *, struct dentry *,
fs/nfs/nfs3proc.c +8 -0
@@ -448,13 +448,21 @@ nfs3_proc_remove(struct inode *dir, struct dentry *dentry) .rpc_resp = &res, };int status = -ENOMEM ; +struct inode *inode =d_inode (dentry); +unsigned long gencount;dprintk ("NFS call remove %pd2\n" , dentry); res.dir_attr =nfs_alloc_fattr ();if (res.dir_attr ==NULL ) goto out; +if (inode) + gencount =READ_ONCE (NFS_I (inode)->attr_gencount); + status =rpc_call_sync (NFS_CLIENT (dir), &msg,0 ); +if (status ==0 && inode) +nfs_drop_nlink (inode, gencount); +nfs_post_op_update_inode (dir, res.dir_attr);nfs_free_fattr (res.dir_attr); out:
fs/nfs/nfs4proc.c +5 -0
@@ -4969,12 +4969,14 @@ static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) };struct inode *inode =d_inode (dentry);int err; +unsigned long gencount;if (inode) {if (inode->i_nlink ==1 )nfs4_inode_return_delegation (inode);else nfs4_inode_make_writeable (inode); + gencount =READ_ONCE (NFS_I (inode)->attr_gencount); } do { err = _nfs4_proc_remove(dir, &dentry->d_name, NF4REG);
@@ -4982,6 +4984,9 @@ static int nfs4_proc_remove(struct inode *dir, struct dentry *dentry) err =nfs4_handle_exception (NFS_SERVER (dir), err, &exception); }while (exception.retry); + +if (err ==0 && inode) +nfs_drop_nlink (inode, gencount);return err; }
fs/nfs/proc.c +8 -0
@@ -323,9 +323,17 @@ nfs_proc_remove(struct inode *dir, struct dentry *dentry) .rpc_argp = &arg, };int status; +struct inode *inode =d_inode (dentry); +unsigned long gencount;dprintk ("NFS call remove %pd2\n" ,dentry); +if (inode) + gencount =READ_ONCE (NFS_I (inode)->attr_gencount); + status =rpc_call_sync (NFS_CLIENT (dir), &msg,0 ); +if (status ==0 && inode) +nfs_drop_nlink (inode, gencount); +nfs_mark_for_revalidate (dir);dprintk ("NFS reply remove: %d\n" , status);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1666/2651 accel/rocket: Dont tear down the scheduler when drm_sched_init() fails
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sidong Yang <[email protected]>
[ Upstream commit a6709a58a01c8fc357e316bee31f369c2ea56235 ]
drm_sched_init() cleans up after itself when it fails, but rocket_job_init() then calls drm_sched_fini() on the same scheduler. That wakes a wait queue that was never initialised, dereferencing a NULL pointer, and can destroy the submit workqueue a second time.
Only destroy the reset workqueue on this path.
--- drivers/accel/rocket/rocket_job.c | 2 -- 1 file changed, 2 deletions(-)
drivers/accel/rocket/rocket_job.c +0 -2
@@ -494,8 +494,6 @@ int rocket_job_init(struct rocket_core *core)return 0 ; err_sched: -drm_sched_fini (&core->sched); -destroy_workqueue (core->reset.wq);return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1667/2651 PCI: Update saved Max Payload Size in pcie_set_mps()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
[ Upstream commit 581cf67cb6f66eabc6bcd7f61dd64b2559270507 ]
pcie_set_mps() changes the Max Payload Size (MPS) in the Device Control register but leaves the copy saved by pci_save_state() alone, so the next pci_restore_state() puts back the old value.
The PCI core does change the MPS of devices whose state has already been
saved: pci_configure_mps() reduces a Root Port's MPS when a device with a smaller MPS Supported is hot-added directly below it (commit 9f0e89359775 ("PCI: Match Root Port's MPS to endpoint's MPSS as necessary")), and with "pci=pcie_bus_safe", pcie_bus_configure_settings() can do the same when pciehp calls it after a hot-add. The Root Port's state was saved when it was added and again when portdrv probed it.
Since commit 3fc686d550f6 ("PCI/ERR: Add support for resetting the Root Ports in a platform-specific way"), pcibios_reset_secondary_bus() restores that saved state, without saving it first, after host->reset_root_port() has reset the Root Port, e.g. during AER recovery or on Link Down with the qcom and Rockchip DWC drivers. The Root Port then goes back to the old, larger MPS while the device below it is restored to the smaller one, so the Root Port may send TLPs that the device treats as Malformed.
Update the saved copy of Device Control when pcie_set_mps() changes the MPS, like commit 909f7bf9b080 ("PCI: Update saved_config_space upon resource assignment") does for BARs.
--- drivers/pci/pci.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
drivers/pci/pci.c +23 -1
@@ -1743,6 +1743,24 @@ static void pci_restore_pcie_state(struct pci_dev *dev)pcie_capability_write_word (dev,PCI_EXP_SLTCTL2 , cap[i++]); } +/* +* Update the saved copy of the Device Control register after changing it, so +* that pci_restore_state() doesn't put back a stale value. Device Control is +* the first register saved by pci_save_pcie_state(). +*/ +static void pcie_update_saved_devctl (struct pci_dev *dev,u16 clear,u16 set) +{ +struct pci_cap_saved_state *save_state; +u16 *devctl; + + save_state =pci_find_saved_cap (dev,PCI_CAP_ID_EXP ); +if (!save_state) +return ; + + devctl = (u16 *)&save_state->cap.data[0 ]; + *devctl = (*devctl & ~clear) | set; +} +static int pci_save_pcix_state (struct pci_dev *dev) {int pos;
@@ -5998,8 +6016,12 @@ int pcie_set_mps(struct pci_dev *dev, int mps) ret =pcie_capability_clear_and_set_word (dev,PCI_EXP_DEVCTL ,PCI_EXP_DEVCTL_PAYLOAD , v); +if (ret) +return pcibios_err_to_errno (ret); -return pcibios_err_to_errno (ret); +pcie_update_saved_devctl (dev,PCI_EXP_DEVCTL_PAYLOAD , v); + +return 0 ; }EXPORT_SYMBOL (pcie_set_mps);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1668/2651 ASoC: codecs: rt5659: propagate GPIO errors
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: bui duc phuc <[email protected]>
[ Upstream commit c1e321bd5ce6ae3702db65837cfe0c792634d603 ]
devm_gpiod_get_optional() may return an error pointer, including -EPROBE_DEFER, but rt5659_i2c_probe() does not handle these errors for the ldo1-en GPIO and does not check for errors for the reset GPIO.
Check the return values and propagate GPIO lookup errors.
--- sound/soc/codecs/rt5659.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
sound/soc/codecs/rt5659.c +5 -1
@@ -4111,10 +4111,14 @@ static int rt5659_i2c_probe(struct i2c_client *i2c) rt5659->gpiod_ldo1_en =devm_gpiod_get_optional (&i2c->dev,"ldo1-en" ,GPIOD_OUT_HIGH );if (IS_ERR (rt5659->gpiod_ldo1_en)) -dev_warn (&i2c->dev,"Request ldo1-en GPIO failed\n" ); +return dev_err_probe (&i2c->dev,PTR_ERR (rt5659->gpiod_ldo1_en), +"failed to get ldo1-en GPIO\n" ); rt5659->gpiod_reset =devm_gpiod_get_optional (&i2c->dev,"reset" ,GPIOD_OUT_HIGH ); +if (IS_ERR (rt5659->gpiod_reset)) +return dev_err_probe (&i2c->dev,PTR_ERR (rt5659->gpiod_reset), +"failed to get reset GPIO\n" );/* Sleep for 300 ms minimum */ msleep (300 );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1669/2651 ASoC: codecs: wcd939x: read the SoundWire port switches per channel
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joonhoe Kim <[email protected]>
[ Upstream commit e7860dc5d8d45f6a0e98bfe542c7b776c5ede2a4 ]
The "HPHL/HPHR", "ADCn" and "DMICn" switches are channels of shared SoundWire ports (ADC1-4 are channels 0-3 of the ADC_1_4 port), but wcd939x_get_swr_port() reports a per-port flag. Once one channel of a port is switched on, every switch on that port reads back as on:
amixer cset name='ADC1 Switch' on -> ADC1..ADC4 Switch all read "on"
Setting one of the others then looks like a no-op to userspace, and "alsactl store" saves all of them as on, so a later "alsactl restore" really enables the unused channels of the port.
Read the channel's own bit in the port's channel mask instead, drop the now unused port_enable[] and return 0 from the put handler when the switch does not change, as ALSA expects.
--- sound/soc/codecs/wcd939x.c | 10 +++++++--- sound/soc/codecs/wcd939x.h | 1 - 2 files changed, 7 insertions(+), 4 deletions(-)
sound/soc/codecs/wcd939x.c +7 -3
@@ -1794,8 +1794,9 @@ static int wcd939x_get_swr_port(struct snd_kcontrol *kcontrol,struct wcd939x_priv *wcd939x =snd_soc_component_get_drvdata (comp);struct wcd939x_sdw_priv *wcd = wcd939x->sdw_priv[mixer->shift];unsigned int portidx = wcd->ch_info[mixer->reg].port_num; +u8 ch_mask = wcd->ch_info[mixer->reg].ch_mask; - ucontrol->value.integer.value[0 ] = wcd->port_enable[portidx] ?1 :0 ; + ucontrol->value.integer.value[0 ] = !!(wcd->port_config[portidx -1 ].ch_mask & ch_mask);return 0 ; }
@@ -1821,10 +1822,13 @@ static int wcd939x_set_swr_port(struct snd_kcontrol *kcontrol,struct wcd939x_priv *wcd939x =snd_soc_component_get_drvdata (comp);struct wcd939x_sdw_priv *wcd = wcd939x->sdw_priv[mixer->shift];unsigned int portidx = wcd->ch_info[mixer->reg].port_num; +u8 ch_mask = wcd->ch_info[mixer->reg].ch_mask; +bool enable = !!ucontrol->value.integer.value[0 ]; - wcd->port_enable[portidx] = !!ucontrol->value.integer.value[0 ]; +if (enable == !!(wcd->port_config[portidx -1 ].ch_mask & ch_mask)) +return 0 ; -wcd939x_connect_port (wcd, portidx, mixer->reg, wcd->port_enable[portidx]); +wcd939x_connect_port (wcd, portidx, mixer->reg, enable);return 1 ; }
sound/soc/codecs/wcd939x.h +0 -1
@@ -899,7 +899,6 @@ struct wcd939x_sdw_priv {struct sdw_stream_runtime *sruntime;struct sdw_port_config port_config[WCD939X_MAX_SWR_PORTS ];const struct wcd_sdw_ch_info *ch_info; -bool port_enable[WCD939X_MAX_SWR_CH_IDS ];int active_ports;bool is_tx;struct wcd939x_priv *wcd939x;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1670/2651 srcu: Use IRQ_WORK_INIT_HARD for srcus irq_work
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Andrzej Siewior <[email protected]>
[ Upstream commit f8d95888093348be1235815946359f9cbc2f7012 ]
The irq_work in srcu is used to schedule a delayed work. The work item is not scheduled directly because it is not always possible wake a thread directly.
On PREEMPT_RT the default irq_work is initialized with IRQ_WORK_LAZY and is delayed to the irq_work thread. A system booted with the command line "trace_event=…" will freeze during boot because the irq_work thread is not yet deployed (and tracing uses synchronize_srcu() in tp_rcu_cond_sync()).
The irq_work performs just a wakeup a thread, there is nothing wrong with doing this from hardirq context on PREEMPT_RT.
Use IRQ_WORK_INIT_HARD for srcu's irq_work.
--- kernel/rcu/srcutree.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/rcu/srcutree.c +6 -1
@@ -218,7 +218,12 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)mutex_init (&ssp->srcu_sup->srcu_barrier_mutex);atomic_set (&ssp->srcu_sup->srcu_barrier_cpu_cnt,0 );INIT_DELAYED_WORK (&ssp->srcu_sup->work, process_srcu); -init_irq_work (&ssp->srcu_sup->irq_work, srcu_irq_work); +/* +* trace events started on the command line require SRCU before +* the irq_work kthread starts. Since all it does is a simple +* wakeup, having it as a hard irq, even on PREEMPT_RT is fine. +*/ + ssp->srcu_sup->irq_work =IRQ_WORK_INIT_HARD (srcu_irq_work); ssp->srcu_sup->sda_is_static = is_static;if (!is_static) { ssp->sda = alloc_percpu(struct srcu_data);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1671/2651 rcutorture: Fix divide-by-zero with fwd_progress_div=1
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kunwu Chan <[email protected]>
[ Upstream commit 5b748d8aa6833f2dec3f545311be69a2064bc6d1 ]
When fwd_progress_div=1, the forward-progress test computes:
sd4 = (sd + div - 1) / div = sd
dur = sd4 + torture_random(&trs) % (sd - sd4) = sd4 + % 0
The modulo operation with a zero divisor triggers an integer division by zero (undefined behavior at the C level, #DE trap on x86), causing a kernel Oops and panic. On x86_64, this manifests as:
rcu_torture_fwd_prog_nr: Starting forward-progress test 0
Oops: divide error: 0000 [#1] SMP PTI RIP: 0010:rcu_torture_fwd_prog+0x90b/0x1160 R12: 0000000000000000
The existing guard only handles non-positive values. However, fwd_progress_div=1 also makes the random range empty because sd4 == sd.
Change the guard to reject values below 2. The forward-progress test only reaches this calculation when stall_dur() is positive, so sd = stall_dur() + 1 >= 2. For fwd_progress_div >= 2, sd4 < sd, ensuring that sd - sd4 is at least 1.
Keep the existing fallback to the default value of 4 for invalid values.
Verified with QEMU/KVM: a 138-second run with fwd_progress_div=1 completed 81 forward-progress test cycles without a crash.
--- kernel/rcu/rcutorture.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/rcu/rcutorture.c +1 -1
@@ -3856,7 +3856,7 @@ static int __init rcu_torture_fwd_prog_init(void) }if (fwd_progress_holdoff <=0 ) fwd_progress_holdoff =1 ; -if (fwd_progress_div <=0 ) +if (fwd_progress_div <2 ) fwd_progress_div =4 ; rfp =kzalloc_objs (*rfp, fwd_progress); fwd_prog_tasks =kzalloc_objs (*fwd_prog_tasks, fwd_progress);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1672/2651 wifi: ath12k: Fix NAPI resource leaks in AHB external IRQ paths
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aaradhana Sahu <[email protected]>
[ Upstream commit ebc938ba1d5ff33652013b99c7b9a74f05690336 ]
Currently, NAPI instances and their associated netdevs allocated for AHB external IRQ groups are not released when external IRQ configuration fails. They are also not freed when arch_init() fails after ath12k_ahb_config_irq() succeeds during probe, or when the driver is unloaded.
Fix this by adding a common cleanup helper to release the NAPI instances and associated netdevs. Call it from the external IRQ configuration error path, probe error path, and driver cleanup path.
Tested-on: IPQ5332 hw1.0 AHB WLAN.WBE.1.6-01275-QCAHKSWPL_SILICONZ-1
--- drivers/net/wireless/ath/ath12k/ahb.c | 41 ++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 4 deletions(-)
drivers/net/wireless/ath/ath12k/ahb.c +37 -4
@@ -191,6 +191,26 @@ static void __ath12k_ahb_ext_irq_disable(struct ath12k_base *ab) } } +static void ath12k_ahb_free_napi_for_group (struct ath12k_ext_irq_grp *irq_grp) +{ +netif_napi_del (&irq_grp->napi); +free_netdev (irq_grp->napi_ndev); + irq_grp->napi_ndev =NULL ; +} + +static void ath12k_ahb_free_napi (struct ath12k_base *ab,int num_ext_irq_grp) +{ +int i; + +for (i =0 ; i < num_ext_irq_grp; i++) +ath12k_ahb_free_napi_for_group (&ab->ext_irq_grp[i]); +} + +static void ath12k_ahb_free_ext_napi (struct ath12k_base *ab) +{ +ath12k_ahb_free_napi (ab,ATH12K_EXT_IRQ_GRP_NUM_MAX ); +} +static void ath12k_ahb_ext_grp_enable (struct ath12k_ext_irq_grp *irq_grp) {int i;
@@ -594,8 +614,10 @@ static int ath12k_ahb_config_ext_irq(struct ath12k_base *ab) irq_grp->grp_id = i; irq_grp->napi_ndev =alloc_netdev_dummy (0 ); -if (!irq_grp->napi_ndev) -return -ENOMEM ; +if (!irq_grp->napi_ndev) { + ret = -ENOMEM ; + goto free_napi_ndev; + }netif_napi_add (irq_grp->napi_ndev, &irq_grp->napi, ath12k_ahb_ext_grp_napi_poll);
@@ -647,12 +669,19 @@ static int ath12k_ahb_config_ext_irq(struct ath12k_base *ab) ath12k_ahb_ext_interrupt_handler,IRQF_TRIGGER_RISING , irq_name[irq_idx], irq_grp); -if (ret) +if (ret) {ath12k_warn (ab,"failed request_irq for %d\n" , irq); +ath12k_ahb_free_napi_for_group (irq_grp); + goto free_napi_ndev; + } } }return 0 ; + +free_napi_ndev: +ath12k_ahb_free_napi (ab, i); +return ret; }static int ath12k_ahb_config_irq (struct ath12k_base *ab)
@@ -1229,7 +1258,7 @@ static int ath12k_ahb_probe(struct platform_device *pdev) ret = ab_ahb->device_family_ops->arch_init (ab);if (ret) {ath12k_err (ab,"AHB arch_init failed %d\n" , ret); - goto err_rproc_deconfigure; + goto err_free_ext_napi; } ret =ath12k_core_init (ab);
@@ -1243,6 +1272,9 @@ static int ath12k_ahb_probe(struct platform_device *pdev) err_deinit_arch: ab_ahb->device_family_ops->arch_deinit (ab); +err_free_ext_napi: +ath12k_ahb_free_ext_napi (ab); + err_rproc_deconfigure:mutex_lock (&ath12k_rproc_info_lock);ath12k_ahb_deconfigure_rproc (ab);
@@ -1285,6 +1317,7 @@ static void ath12k_ahb_free_resources(struct ath12k_base *ab)struct platform_device *pdev = ab->pdev;struct ath12k_ahb *ab_ahb =ath12k_ab_to_ahb (ab); +ath12k_ahb_free_ext_napi (ab);ath12k_hal_srng_deinit (ab);ath12k_ce_free_pipes (ab);ath12k_ahb_resource_deinit (ab);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1673/2651 wifi: ath10k: avoid IDR mutation during TX cleanup
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
[ Upstream commit 1c1a208e65a08191901cfded3bbccc4a54e4a75c ]
ath10k_htt_flush_tx_queue() walks pending_tx with idr_for_each(). Its callback calls ath10k_txrx_tx_unref(), which removes the current entry from pending_tx through ath10k_htt_tx_free_msdu_id().
idr_for_each() keeps radix-tree iterator state across the callback. Removing the current entry can therefore invalidate that state and make the remaining walk unsafe.
Use idr_for_each_entry(), which starts a fresh lookup after each callback. The current entry can then be removed safely, while the following idr_destroy() continues to release the IDR itself.
--- drivers/net/wireless/ath/ath10k/htt_tx.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/net/wireless/ath/ath10k/htt_tx.c +7 -5
@@ -505,9 +505,8 @@ int ath10k_htt_tx_start(struct ath10k_htt *htt)return ret; } -static int ath10k_htt_tx_clean_up_pending (int msdu_id,void *skb,void *ctx) +static void ath10k_htt_tx_clean_up_pending (int msdu_id,struct ath10k *ar) { -struct ath10k *ar = ctx;struct ath10k_htt *htt = &ar->htt;struct htt_tx_done tx_done = {};
@@ -517,8 +516,6 @@ static int ath10k_htt_tx_clean_up_pending(int msdu_id, void *skb, void *ctx) tx_done.status =HTT_TX_COMPL_STATE_DISCARD ;ath10k_txrx_tx_unref (htt, &tx_done); - -return 0 ; }void ath10k_htt_tx_destroy (struct ath10k_htt *htt)
@@ -535,8 +532,13 @@ void ath10k_htt_tx_destroy(struct ath10k_htt *htt)static void ath10k_htt_flush_tx_queue (struct ath10k_htt *htt) { +struct sk_buff *msdu; +int msdu_id; +ath10k_htc_stop_hl (htt->ar); -idr_for_each (&htt->pending_tx, ath10k_htt_tx_clean_up_pending, htt->ar); + +idr_for_each_entry (&htt->pending_tx, msdu, msdu_id) +ath10k_htt_tx_clean_up_pending (msdu_id, htt->ar); }void ath10k_htt_tx_stop (struct ath10k_htt *htt)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1674/2651 wifi: ath11k: avoid IDR mutation during pending mgmt TX cleanup
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
[ Upstream commit 3e7f5d362b2b3a21b3adb4b860aad14b69a896ad ]
The pending management TX cleanup walks txmgmt_idr with idr_for_each(), and its callback removes the current entry. This can invalidate the radix-tree iterator retained by idr_for_each().
Use idr_for_each_entry() so every iteration starts with a fresh lookup. Continue to remove each entry under txmgmt_idr_lock before freeing its skb, preventing concurrent TX completion from finding a stale skb pointer.
--- drivers/net/wireless/ath/ath11k/core.c | 3 +-- drivers/net/wireless/ath/ath11k/mac.c | 12 ++++++------ drivers/net/wireless/ath/ath11k/mac.h | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-)
drivers/net/wireless/ath/ath11k/core.c +1 -2
@@ -2448,8 +2448,7 @@ void ath11k_core_pre_reconfigure_recovery(struct ath11k_base *ab)complete (&ar->thermal.wmi_sync);wake_up (&ar->dp.tx_empty_waitq); -idr_for_each (&ar->txmgmt_idr, - ath11k_mac_tx_mgmt_pending_free, ar); +ath11k_mac_tx_mgmt_pending_free (ar);idr_destroy (&ar->txmgmt_idr);wake_up (&ar->txmgmt_empty_waitq);
drivers/net/wireless/ath/ath11k/mac.c +6 -6
@@ -6167,13 +6167,13 @@ static void ath11k_mac_tx_mgmt_free(struct ath11k *ar, int buf_id)ath11k_mgmt_over_wmi_tx_drop (ar, msdu); } -int ath11k_mac_tx_mgmt_pending_free (int buf_id,void *skb,void *ctx) +void ath11k_mac_tx_mgmt_pending_free (struct ath11k *ar) { -struct ath11k *ar = ctx; - -ath11k_mac_tx_mgmt_free (ar, buf_id); +struct sk_buff *msdu; +int buf_id; -return 0 ; +idr_for_each_entry (&ar->txmgmt_idr, msdu, buf_id) +ath11k_mac_tx_mgmt_free (ar, buf_id); }static int ath11k_mac_vif_txmgmt_idr_remove (int buf_id,void *skb,void *ctx)
@@ -10418,7 +10418,7 @@ static void __ath11k_mac_unregister(struct ath11k *ar)ieee80211_unregister_hw (ar->hw); -idr_for_each (&ar->txmgmt_idr, ath11k_mac_tx_mgmt_pending_free, ar); +ath11k_mac_tx_mgmt_pending_free (ar);idr_destroy (&ar->txmgmt_idr);kfree (ar->mac.sbands[NL80211_BAND_2GHZ ].channels);
drivers/net/wireless/ath/ath11k/mac.h +1 -1
@@ -162,7 +162,7 @@ struct ath11k *ath11k_mac_get_ar_by_pdev_id(struct ath11k_base *ab, u32 pdev_id)void ath11k_mac_drain_tx (struct ath11k *ar);void ath11k_mac_peer_cleanup_all (struct ath11k *ar); -int ath11k_mac_tx_mgmt_pending_free (int buf_id,void *skb,void *ctx); +void ath11k_mac_tx_mgmt_pending_free (struct ath11k *ar);u8 ath11k_mac_bw_to_mac80211_bw (u8 bw);enum nl80211_he_gi ath11k_mac_he_gi_to_nl80211_he_gi (u8 sgi);enum nl80211_he_ru_alloc ath11k_mac_phy_he_ru_to_nl80211_he_ru_alloc (u16 ru_phy);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1675/2651 wifi: ath11k: avoid IDR mutation during vif mgmt TX cleanup
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
[ Upstream commit dc29226dada34a6d19af77b4b51e90f8a3a8de34 ]
ath11k_mac_op_remove_interface() walks txmgmt_idr with idr_for_each(), and its callback removes each entry belonging to the interface. Removing the current entry can invalidate the radix-tree iterator retained by idr_for_each().
Move the walk into a helper that uses idr_for_each_entry(). It performs a fresh lookup for every iteration, so each matching entry can be removed through the locked removal helper without retaining iterator state across the removal.
--- drivers/net/wireless/ath/ath11k/mac.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/net/wireless/ath/ath11k/mac.c +11 -10
@@ -6176,16 +6176,18 @@ void ath11k_mac_tx_mgmt_pending_free(struct ath11k *ar)ath11k_mac_tx_mgmt_free (ar, buf_id); } -static int ath11k_mac_vif_txmgmt_idr_remove (int buf_id,void *skb,void *ctx) +static void ath11k_mac_vif_txmgmt_cleanup (struct ath11k *ar, +struct ieee80211_vif *vif) { -struct ieee80211_vif *vif = ctx; -struct ath11k_skb_cb *skb_cb =ATH11K_SKB_CB ((struct sk_buff *)skb); -struct ath11k *ar = skb_cb->ar; - -if (skb_cb->vif == vif) -ath11k_mac_tx_mgmt_free (ar, buf_id); +struct ath11k_skb_cb *skb_cb; +struct sk_buff *skb; +int buf_id; -return 0 ; +idr_for_each_entry (&ar->txmgmt_idr, skb, buf_id) { + skb_cb =ATH11K_SKB_CB (skb); +if (skb_cb->vif == vif) +ath11k_mac_tx_mgmt_free (ar, buf_id); + } } static int ath11k_mac_mgmt_tx_wmi(struct ath11k *ar, struct ath11k_vif *arvif,
@@ -7417,8 +7419,7 @@ static void ath11k_mac_op_remove_interface(struct ieee80211_hw *hw,ath11k_peer_cleanup (ar, arvif->vdev_id); -idr_for_each (&ar->txmgmt_idr, - ath11k_mac_vif_txmgmt_idr_remove, vif); +ath11k_mac_vif_txmgmt_cleanup (ar, vif);for (i =0 ; i < ab->hw_params.hal_params->num_tx_rings; i++) {spin_lock_bh (&ab->dp.tx_ring[i].tx_idr_lock);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1676/2651 wifi: ath12k: avoid IDR mutation during pending mgmt TX cleanup
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
[ Upstream commit 94c7b50351fd30e1dfe1b4051197a1445d8547e1 ]
The pending management TX cleanup walks txmgmt_idr with idr_for_each(), and its callback removes the current entry. This can invalidate the radix-tree iterator retained by idr_for_each().
Use idr_for_each_entry() so every iteration starts with a fresh lookup. Continue to remove each entry under txmgmt_idr_lock before freeing its skb, preventing concurrent TX completion from finding a stale skb pointer.
--- drivers/net/wireless/ath/ath12k/core.c | 3 +-- drivers/net/wireless/ath/ath12k/mac.c | 12 ++++++------ drivers/net/wireless/ath/ath12k/mac.h | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-)
drivers/net/wireless/ath/ath12k/core.c +1 -2
@@ -1516,8 +1516,7 @@ static void ath12k_core_pre_reconfigure_recovery(struct ath12k_base *ab)complete_all (&ar->thermal.wmi_sync);wake_up (&ar->dp.tx_empty_waitq); -idr_for_each (&ar->txmgmt_idr, - ath12k_mac_tx_mgmt_pending_free, ar); +ath12k_mac_tx_mgmt_pending_free (ar);idr_destroy (&ar->txmgmt_idr);wake_up (&ar->txmgmt_empty_waitq);
drivers/net/wireless/ath/ath12k/mac.c +6 -6
@@ -9194,13 +9194,13 @@ static void ath12k_mac_tx_mgmt_free(struct ath12k *ar, int buf_id)ath12k_mgmt_over_wmi_tx_drop (ar, msdu); } -int ath12k_mac_tx_mgmt_pending_free (int buf_id,void *skb,void *ctx) +void ath12k_mac_tx_mgmt_pending_free (struct ath12k *ar) { -struct ath12k *ar = ctx; - -ath12k_mac_tx_mgmt_free (ar, buf_id); +struct sk_buff *msdu; +int buf_id; -return 0 ; +idr_for_each_entry (&ar->txmgmt_idr, msdu, buf_id) +ath12k_mac_tx_mgmt_free (ar, buf_id); }static int ath12k_mac_vif_txmgmt_idr_remove (int buf_id,void *skb,void *ctx)
@@ -14735,7 +14735,7 @@ static struct wiphy_iftype_ext_capab ath12k_iftypes_ext_capa[] = {static void ath12k_mac_cleanup_unregister (struct ath12k *ar) { -idr_for_each (&ar->txmgmt_idr, ath12k_mac_tx_mgmt_pending_free, ar); +ath12k_mac_tx_mgmt_pending_free (ar);idr_destroy (&ar->txmgmt_idr);kfree (ar->mac.sbands[NL80211_BAND_2GHZ ].channels);
drivers/net/wireless/ath/ath12k/mac.h +1 -1
@@ -173,7 +173,7 @@ struct ath12k *ath12k_mac_get_ar_by_pdev_id(struct ath12k_base *ab, u32 pdev_id)void ath12k_mac_drain_tx (struct ath12k *ar);void ath12k_mac_peer_cleanup_all (struct ath12k *ar);void ath12k_mac_dp_peer_cleanup (struct ath12k_hw *ah); -int ath12k_mac_tx_mgmt_pending_free (int buf_id,void *skb,void *ctx); +void ath12k_mac_tx_mgmt_pending_free (struct ath12k *ar);enum rate_info_bw ath12k_mac_bw_to_mac80211_bw (enum ath12k_supported_bw bw);enum ath12k_supported_bw ath12k_mac_mac80211_bw_to_ath12k_bw (enum rate_info_bw bw);enum hal_encrypt_type ath12k_dp_tx_get_encrypt_type (u32 cipher);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1677/2651 wifi: ath12k: avoid IDR mutation during vif mgmt TX cleanup
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
[ Upstream commit 4aa45334eb23d40bf31c43405daea9b73469f2a6 ]
ath12k_mac_vdev_delete() walks txmgmt_idr with idr_for_each(), and its callback removes each entry belonging to the interface. Removing the current entry can invalidate the radix-tree iterator retained by idr_for_each().
Move the walk into a helper that uses idr_for_each_entry(). It performs a fresh lookup for every iteration, so each matching entry can be removed through the locked removal helper without retaining iterator state across the removal.
--- drivers/net/wireless/ath/ath12k/mac.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/net/wireless/ath/ath12k/mac.c +11 -10
@@ -9203,16 +9203,18 @@ void ath12k_mac_tx_mgmt_pending_free(struct ath12k *ar)ath12k_mac_tx_mgmt_free (ar, buf_id); } -static int ath12k_mac_vif_txmgmt_idr_remove (int buf_id,void *skb,void *ctx) +static void ath12k_mac_vif_txmgmt_cleanup (struct ath12k *ar, +struct ieee80211_vif *vif) { -struct ieee80211_vif *vif = ctx; -struct ath12k_skb_cb *skb_cb =ATH12K_SKB_CB (skb); -struct ath12k *ar = skb_cb->ar; - -if (skb_cb->vif == vif) -ath12k_mac_tx_mgmt_free (ar, buf_id); +struct ath12k_skb_cb *skb_cb; +struct sk_buff *skb; +int buf_id; -return 0 ; +idr_for_each_entry (&ar->txmgmt_idr, skb, buf_id) { + skb_cb =ATH12K_SKB_CB (skb); +if (skb_cb->vif == vif) +ath12k_mac_tx_mgmt_free (ar, buf_id); + } } static int ath12k_mac_mgmt_tx_wmi(struct ath12k *ar, struct ath12k_link_vif *arvif,
@@ -10977,8 +10979,7 @@ static int ath12k_mac_vdev_delete(struct ath12k *ar, struct ath12k_link_vif *arvath12k_peer_cleanup (ar, arvif->vdev_id);ath12k_ahvif_put_link_cache (ahvif, arvif->link_id); -idr_for_each (&ar->txmgmt_idr, - ath12k_mac_vif_txmgmt_idr_remove, vif); +ath12k_mac_vif_txmgmt_cleanup (ar, vif);ath12k_mac_vif_unref (ath12k_ab_to_dp (ab), vif);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1678/2651 smb: client: log the selected security type on session setup failure
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Paulo Alcantara <[email protected]>
[ Upstream commit a4111beeade900346726acb2746f22a6313aeaf0 ]
When mounting without an explicit sec= option, ses->sectype stays Unspecified while the real mechanism is chosen later through ->select_sectype(), so a failed session setup logs a useless name:
CIFS: VFS: \\server failed to create a new SMB session with Unknown: -13
Resolve the mechanism through ->select_sectype() before formatting it, as cifs_debug.c already does, so the message names the actual security type.
--- fs/smb/client/connect.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/smb/client/connect.c +5 -1
@@ -4184,8 +4184,12 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,if (rc) {if (new_ses) { +enum securityEnum sectype; + + sectype = server->ops->select_sectype (server, + ses->sectype);cifs_server_dbg (VFS ,"failed to create a new SMB session with %s: %d\n" , -get_security_type_str (ses->sectype), rc); +get_security_type_str (sectype), rc); }spin_lock (&ses->ses_lock);if (ses->ses_status ==SES_IN_SETUP )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1679/2651 selftests/damon: stop kdamond on error exits of no-op commit test
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zenghui Yu (Huawei) <[email protected]>
[ Upstream commit 65c7e923ed1afa7329f8b910327ebf6ae10a5fb6 ]
Patch series "mm/damon: misc improvements in tests and documents".
Add various improvements to DAMON tests and documents.
Patch 1 and 2 from Zenghui Yu (Huawei) let DAMON selftest to clean up its state and output after running the tests. Patch 3 from Eva Kurchatova makes a few selftest be able to run with Python's safe path mode. Patch 4 from Kunwu Chan improves coverage of DAMON kunit tests. Finally, patches 5 and 6 from Liew Rui Yan clarify and fix typos on documents for DAMOS quota behaviors.
Below are notes that can be removed in the final commit message.
This is a batched repost of DAMON patches that were individually posted. Please refer to each patch for changelog.
This patch (of 6):
The sysfs_no_op_commit_break test starts a kdamond via sysfs, but its error paths (e.g., drgn not installed) exit without stopping it. The leaked kdamond then makes subsequent tests, e.g. lru_sort.sh and reclaim.sh, skip with "Another kdamond is running".
Wrap the post-start logic in try-finally so that kdamonds.stop() is executed on every exit path.
--- .../damon/sysfs_no_op_commit_break.py | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-)
tools/testing/selftests/damon/sysfs_no_op_commit_break.py +18 -17
@@ -47,26 +47,27 @@ def main(): print('kdamond start failed: %s' % err) exit(1) - before_commit_status, err = \ - dump_damon_status_dict(kdamonds.kdamonds[0].pid) - if err is not None: - print('before-commit status dump failed: %s' % err) - exit(1) + try: + before_commit_status, err = \ + dump_damon_status_dict(kdamonds.kdamonds[0].pid) + if err is not None: + print('before-commit status dump failed: %s' % err) + exit(1) - kdamonds.kdamonds[0].commit() + kdamonds.kdamonds[0].commit() - after_commit_status, err = \ - dump_damon_status_dict(kdamonds.kdamonds[0].pid) - if err is not None: - print('after-commit status dump failed: %s' % err) - exit(1) - - if before_commit_status != after_commit_status: - print(f'before: {json.dumps(before_commit_status, indent=2)}') - print(f'after: {json.dumps(after_commit_status, indent=2)}') - exit(1) + after_commit_status, err = \ + dump_damon_status_dict(kdamonds.kdamonds[0].pid) + if err is not None: + print('after-commit status dump failed: %s' % err) + exit(1) - kdamonds.stop() + if before_commit_status != after_commit_status: + print(f'before: {json.dumps(before_commit_status, indent=2)}') + print(f'after: {json.dumps(after_commit_status, indent=2)}') + exit(1) + finally: + kdamonds.stop() if __name__ == '__main__': main()
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1680/2651 selftests/cgroup: ignore memory.reclaim -EAGAIN for zswap writeback test
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harry Yoo (Meta) <[email protected]>
[ Upstream commit adbb0adb434d55bd02b18c8de6356f954a077c79 ]
The zswap_writeback_enabled test fails when a write to memory.reclaim returns -EAGAIN, which means less than the requested amount was reclaimed. attempt_writeback() propagates the -EAGAIN to the caller, and the test case is marked as failed even when zswap writeback did happen.
This heavily depends on the performance of the backing swap device. Reclaim does not wait for writeback (on cgroup v2), does not count pages that are under writeback as reclaimed, and memory.reclaim gives up after MAX_RECLAIM_RETRIES passes without making progress. On a slow device where reclaim does not make any progress before writeback completes, a write to memory.reclaim fails.
On a VM with zswap enabled, where IO delay was injected via dm-delay, the success rate of the zswap writeback test drops dramatically once the delay reaches 11 ms: 7% failures at 10 ms and 79% failures at 11 ms, n = 100.
When zswap writeback is enabled, ignore -EAGAIN from memory.reclaim and determine pass/fail based on the zswpwb counter because that is what zswap_writeback_enabled actually wants to test.
With this change, the test reliably passes even on a slow swap device (tested up to 1000 ms delay). This makes the test resilient against the performance of the swap device.
--- tools/testing/selftests/cgroup/test_zswap.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
tools/testing/selftests/cgroup/test_zswap.c +10 -1
@@ -346,7 +346,16 @@ static int attempt_writeback(const char *cgroup, void *arg)* it can't writeback to swap. */ ret =cg_write_numeric (cgroup,"memory.reclaim" , memsize); -if (!wb_enabled) + +/* +* When writeback is enabled, memory.reclaim may still fail to reclaim +* the requested amount of memory due to a slow swap device. +* Ignore -EAGAIN here. The caller determines pass/fail based on the +* zswap writeback counter. +*/ +if (wb_enabled && ret == -EAGAIN ) + ret =0 ; +else if (!wb_enabled) ret = (ret == -EAGAIN ) ?0 :-1 ; out:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1681/2651 mm/hmm/test: reject overflowing page counts
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
[ Upstream commit b59925301211ccc351d98d70b11f6d1b2c63150f ]
The number of pages comes directly from userspace. Shifting a value larger than ULONG_MAX >> PAGE_SHIFT discards its high bits before the existing end-address check. A request for a huge number of pages can therefore be accepted and processed as a much smaller request.
Reject page counts that cannot be represented as a byte size before performing the shift.
So far as ChatGPT and I can tell this doesn't cause an issue in practice but preventing this integer overflow is the correct thing to do.
--- lib/test_hmm.c | 2 ++ 1 file changed, 2 insertions(+)
lib/test_hmm.c +2 -0
@@ -1624,6 +1624,8 @@ static long dmirror_fops_unlocked_ioctl(struct file *filp,if (cmd.addr & ~PAGE_MASK )return -EINVAL ; +if (cmd.npages >ULONG_MAX >>PAGE_SHIFT ) +return -EINVAL ;if (cmd.addr >= (cmd.addr + (cmd.npages <<PAGE_SHIFT )))return -EINVAL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1682/2651 ALSA: jack: Remove debugfs before freeing unregistered jacks
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit d3b59d50e1ff206aa519ed5c13bf6907f97dd6a6 ]
Jack debugfs files store a raw snd_jack_kctl pointer, so their callbacks must be drained before the attachment is freed. snd_jack_dev_free() unlinks and frees the attachments before calling snd_jack_dev_disconnect(). Its late snd_jack_remove_debugfs() call then has no entries left to traverse.
With CONFIG_SND_JACK_INJECTION_DEBUG and input support enabled, an HDA codec rebind on a live card can publish a non-phantom jack's type file while its component is still in SNDRV_DEV_BUILD. A later jack-control allocation failure permits the following order:
1. hda_codec_driver_probe() creates a jack and publishes its debugfs files before reaching snd_card_register().
2. A later control-build failure calls snd_hda_codec_cleanup_for_unbind(), then snd_hda_jack_tbl_clear() and snd_device_free(). __snd_device_disconnect() skips BUILD components. snd_jack_dev_free() frees the attachment before its late disconnect, leaving the debugfs files published.
3. After cleanup, a reader opens the surviving type file and jack_type_read() dereferences the freed attachment's jack pointer.
The card's debugfs root remains live throughout this sequence. The result is a use-after-free even without an overlapping read. An already admitted callback is also not drained by this cleanup.
Call snd_jack_remove_debugfs() before unlinking any controls in the free callback. The existing debugfs_remove() rundown blocks new accesses and waits for active callbacks while the attachment, control and jack remain valid. Roots cleared by an earlier disconnect are NULL, so repeating the removal is harmless.
KASAN report as below:
==================================================================
BUG: KASAN: slab-use-after-free in jack_type_read+0x1da/0x1f0
Read of size 8 at addr ffff8881085f9da0 by task python3/429
CPU: 2 UID: 0 PID: 429 Comm: python3 Not tainted 7.2.0-rc6-pmb-alsa-functional-v2+ #1 PREEMPT(lazy)
Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
? jack_type_read+0x1da/0x1f0
? srso_alias_return_thunk+0x5/0xfbef5
? __virt_addr_valid+0x20d/0x410
? jack_type_read+0x1da/0x1f0
kasan_report+0xe0/0x110
? jack_type_read+0x1da/0x1f0
jack_type_read+0x1da/0x1f0
? __pfx_jack_type_read+0x10/0x10
? __pfx___debugfs_file_get+0x10/0x10
? __pfx_cp_new_stat+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? srso_alias_return_thunk+0x5/0xfbef5
? selinux_file_permission+0x122/0x570
full_proxy_read+0x11f/0x180
? __pfx_full_proxy_read+0x10/0x10
vfs_read+0x1a0/0xc20
? __pfx_vfs_read+0x10/0x10
? srso_alias_return_thunk+0x5/0xfbef5
? __do_sys_newfstat+0xa6/0x100
? find_held_lock+0x2b/0x80
? __pfx___do_sys_newfstat+0x10/0x10
ksys_read+0x111/0x200
? __pfx_ksys_read+0x10/0x10
? full_proxy_llseek+0x11e/0x170
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f7e392e7687
Code: 48 89 fa 4c 89 df e8 58 b3 00 00 8b 93 08 03 00 00 59 5e 48 83 f8 fc 74 1a 5b c3 0f 1f 84 00 00 00 00 00 48 8b 44 24 10 0f 05 <5b> c3 0f 1f 80 00 00 00 00 83 e2 39 83 fa 08 75 de e8 23 ff ff ff
RSP: 002b:00007fff5f7b9180 EFLAGS: 00000202 ORIG_RAX: 0000000000000000
RAX: ffffffffffffffda RBX: 00007f7e39253780 RCX: 00007f7e392e7687
RDX: 0000000000002000 RSI: 000000003d2e9b00 RDI: 0000000000000003
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000202 R12: 00007f7e39253700
R13: 0000000000002000 R14: 00007f7e38d7e2c0 R15: 0000000000a55b98
</TASK>
Allocated by task 425:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_kmalloc+0xaa/0xb0
__kmalloc_cache_noprof+0x251/0x610
snd_jack_kctl_new+0x80/0x180
snd_jack_new+0x4b/0x490
snd_hda_jack_add_kctl_mst+0x19b/0x610
add_jack_kctl+0x204/0x320
snd_hda_jack_add_kctls+0x212/0x910
snd_hda_gen_build_controls+0x233/0x600
snd_hda_codec_build_controls+0x2e4/0x9f0
hda_codec_driver_probe+0x26e/0x590
really_probe+0x21f/0xa90
__driver_probe_device+0x1ec/0x490
device_driver_attach+0xdc/0x210
bind_store+0xec/0x180
drv_attr_store+0x79/0xb0
sysfs_kf_write+0xed/0x140
kernfs_fop_write_iter+0x34b/0x500
vfs_write+0x637/0x1010
ksys_write+0x111/0x200
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 425:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
kfree+0x307/0x580
snd_jack_kctl_private_free+0x153/0x200
__snd_ctl_remove+0x29f/0x3b0
snd_ctl_remove+0x46/0x70
snd_jack_dev_free+0x1b1/0x370
__snd_device_free+0x193/0x3f0
snd_device_free+0xcf/0x190
snd_hda_jack_tbl_clear+0x159/0x2e0
snd_hda_codec_cleanup_for_unbind+0x37e/0x9c0
hda_codec_driver_probe+0x3ae/0x590
really_probe+0x21f/0xa90
__driver_probe_device+0x1ec/0x490
device_driver_attach+0xdc/0x210
bind_store+0xec/0x180
drv_attr_store+0x79/0xb0
sysfs_kf_write+0xed/0x140
kernfs_fop_write_iter+0x34b/0x500
vfs_write+0x637/0x1010
ksys_write+0x111/0x200
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
The buggy address belongs to the object at ffff8881085f9d80
which belongs to the cache kmalloc-64 of size 64
The buggy address is located 32 bytes inside of
freed 64-byte region [ffff8881085f9d80, ffff8881085f9dc0)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1085f9
flags: 0x200000000000000(node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000000 ffff8881000428c0 dead000000000100 dead000000000122
raw: 0000000000000000 0000000000200020 00000000f5000000 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff8881085f9c80: 00 00 00 00 00 00 00 00 fc fc fc fc fc fc fc fc
ffff8881085f9d00: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
>ffff8881085f9d80: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
^
ffff8881085f9e00: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff8881085f9e80: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
==================================================================--- sound/core/jack.c | 3 +++ 1 file changed, 3 insertions(+)
sound/core/jack.c +3 -0
@@ -68,6 +68,9 @@ static int snd_jack_dev_free(struct snd_device *device)struct snd_card *card = device->card;struct snd_jack_kctl *jack_kctl, *tmp_jack_kctl; +/* Remove debugfs while the controls are still linked. */ +snd_jack_remove_debugfs (jack); +list_for_each_entry_safe (jack_kctl, tmp_jack_kctl, &jack->kctl_list, list) {list_del_init (&jack_kctl->list);snd_ctl_remove (card, jack_kctl->kctl);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1683/2651 ALSA: hda: intel: Dont free card in the probe work
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ali Ahmet Memiş <[email protected]>
[ Upstream commit fbaccb1b19c79e79220e3bcc5bb18ca54ffb017b ]
If the delayed probe fails, azx_probe_work() frees the card and clears the drvdata. azx_remove() reads the card before it waits for the probe work with cancel_delayed_work_sync() so when the device is removed while the probe work is running, it frees the card again after the work has already freed it.
Only disconnect the card in the work so that its slot is released right away and leave freeing it to azx_remove().
--- sound/hda/controllers/intel.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
sound/hda/controllers/intel.c +6 -1
@@ -1737,7 +1737,12 @@ static void azx_check_snoop_available(struct azx *chip)static void azx_probe_work (struct work_struct *work) { struct hda_intel *hda = container_of(work, struct hda_intel, probe_work.work); -azx_probe_continue (&hda->chip, true); + +if (azx_probe_continue (&hda->chip, false) <0 ) { + hda->init_failed =1 ; +complete_all (&hda->probe_wait); +snd_card_disconnect (hda->chip.card); + } }static int default_bdl_pos_adj (struct azx *chip)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1684/2651 platform/x86/amd/pmf: fix compat ioctl handling
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnd Bergmann <[email protected]>
[ Upstream commit 655d731c391ec3912503b91ecf6269883b13e0c2 ]
Build testing with -Wpadded shows a structure that is incompatible between 32-bit and 64-bit x86 userspace:
./usr/include/linux/amd-pmf.h:202:1: error: padding struct size to alignment boundary with 4 bytes [-Werror=padded]
Use the 64-bit padded on all architectures here to avoid both the warning and allow compat ioctl handling.
--- drivers/platform/x86/amd/pmf/util.c | 1 + include/uapi/linux/amd-pmf.h | 3 +++ 2 files changed, 4 insertions(+)
drivers/platform/x86/amd/pmf/util.c +1 -0
@@ -123,6 +123,7 @@ static const struct file_operations pmf_if_ops = { .owner = THIS_MODULE, .open = amd_pmf_open, .unlocked_ioctl = amd_pmf_set_ioctl, + .compat_ioctl = compat_ptr_ioctl, };static struct miscdevice amd_pmf_util_if = {
include/uapi/linux/amd-pmf.h +3 -0
@@ -199,6 +199,9 @@ struct amd_pmf_info {/* BIOS parameters */ __u32 bios_input[AMD_PMF_BIOS_PARAMS_MAX ];__u32 bios_output[AMD_PMF_BIOS_PARAMS_MAX ]; + +/* align to 64 bit boundary */ + __u32 __pad; };#endif /* _UAPI_LINUX_AMD_PMF_H */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1685/2651 platform/surface: aggregator_registry: Remove sensors device for Surface Pro 11
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dale Whinham <[email protected]>
[ Upstream commit f1db1b80190b6a9f96e1171e2d7eac51ed4e28ca ]
Remove ssam_node_hid_sam_sensors as this device is not present on Surface Pro 11. This fixes a probe failure in dmesg:
surface_hid 01:15:01:06:00: unexpected descriptor length: got 0, expected 9 surface_hid 01:15:01:06:00: probe with driver surface_hid failed with error -71
--- drivers/platform/surface/surface_aggregator_registry.c | 1 - 1 file changed, 1 deletion(-)
drivers/platform/surface/surface_aggregator_registry.c +0 -1
@@ -415,7 +415,6 @@ static const struct software_node *ssam_node_group_sp11[] = { &ssam_node_hid_kip_penstash, &ssam_node_hid_kip_touchpad, &ssam_node_hid_kip_fwupd, - &ssam_node_hid_sam_sensors, &ssam_node_kip_tablet_switch, NULL, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1686/2651 platform/surface: aggregator_registry: Fix tablet-mode detection on Surface Pro 11
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dale Whinham <[email protected]>
[ Upstream commit ee2e7315dedcdd934139237f820582f9b6ce7842 ]
Replace ssam_node_kip_tablet_switch with ssam_node_pos_tablet_switch, as Surface Pro 11 reports tablet-mode via the POS ('posture') subsystem and not the KIP subsystem.
The KIP-based driver would remain stuck in a 'folded-back' state after suspend/resume, whereas the POS-based device reports its state correctly even after suspend/resume.
This fixes the type cover keyboard/mouse being ignored by desktop environments after resume from sleep due to the erroneous 'folded-back' state.
--- drivers/platform/surface/surface_aggregator_registry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/surface/surface_aggregator_registry.c +1 -1
@@ -415,7 +415,7 @@ static const struct software_node *ssam_node_group_sp11[] = { &ssam_node_hid_kip_penstash, &ssam_node_hid_kip_touchpad, &ssam_node_hid_kip_fwupd, - &ssam_node_kip_tablet_switch, + &ssam_node_pos_tablet_switch, NULL, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1687/2651 platform/x86: asus-wmi: validate custom fan curves on enable
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ahmed Yaseen <[email protected]>
[ Upstream commit bcbdfe03566ad0d01c6af3b5476e8cadffe4d3df ]
Custom fan curves reach firmware unchecked, so a curve whose temperature or PWM decreases from one point to the next is accepted. The firmware does not respect such a curve: a first point of 100% followed by 50% leaves every point running at 100%. The kernel keeps reporting the points that were written, so sysfs stops describing what the fans are actually doing.
Check the curve when enabling and reject it if it is invalid. Validation is done on enable rather than on write because fan curves are written one point at a time and are inconsistent mid-write.
--- drivers/platform/x86/asus-wmi.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
drivers/platform/x86/asus-wmi.c +32 -0
@@ -3739,6 +3739,33 @@ static int fan_curve_write(struct asus_wmi *asus, arg1, arg2, arg3, arg4, &ret); } +/* +* A fan curve is a set of points the firmware interpolates between, so it +* only makes sense if neither temperature nor PWM ever decreases along it. +*/ +static int fan_curve_validate (struct device *dev,struct fan_curve_data *data) +{ +u8 *percents = data->percents; +u8 *temps = data->temps; +int i; + +for (i =1 ; i <FAN_CURVE_POINTS ; i++) { +if (temps[i] < temps[i -1 ]) { +dev_warn (dev,"fan curve: temperature decreases at point %d (%u < %u)\n" , + i, temps[i], temps[i -1 ]); +return -EINVAL ; + } + +if (percents[i] < percents[i -1 ]) { +dev_warn (dev,"fan curve: pwm decreases at point %d (%u < %u)\n" , + i, percents[i], percents[i -1 ]); +return -EINVAL ; + } + } + +return 0 ; +} +static ssize_t fan_curve_store (struct device *dev,struct device_attribute *attr,const char *buf,size_t count)
@@ -3823,6 +3850,11 @@ static ssize_t fan_curve_enable_store(struct device *dev, }if (data->enabled) { + err =fan_curve_validate (dev, data); +if (err) { + data->enabled = false; +return err; + } err =fan_curve_write (asus, data);if (err)return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1688/2651 platform/x86: msi-ec: Report valid charge thresholds when unset
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Daasaradhi Mannava <[email protected]>
[ Upstream commit a102207eaf4a18c60c2ffbdc421ad3d30bfed591 ]
The charge thresholds are computed by subtracting a fixed offset from the raw EC value. When no charge limit has been set, the EC can hold a value below range_min (0x80 on an MSI GL65 Leopard 9SCXK), and reading the sysfs attributes returns nonsense:
charge_control_start_threshold: -10
charge_control_end_threshold: 0
Both attributes are documented to be within 0 - 100, and an end threshold of 0 wrongly suggests that charging is disabled.
The store path already rejects values outside range_min..range_max. Apply the same range to the show path and report the maximum threshold for any value outside of it.
Tested on an MSI GL65 Leopard 9SCXK (EC firmware 16U8EMS2.100) with the EC holding 0x80: the attributes now read 90 and 100.
--- drivers/platform/x86/msi-ec.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/platform/x86/msi-ec.c +9 -0
@@ -1279,6 +1279,15 @@ static ssize_t charge_control_threshold_show(u8 offset,if (result <0 )return result; +/* +* The EC may hold an out-of-range value (e.g. 0x80) when no charge +* limit has been set. Report the maximum threshold instead of a +* meaningless (possibly negative) percentage. +*/ +if (rdata < conf.charge_control.range_min || + rdata > conf.charge_control.range_max) + rdata = conf.charge_control.range_max; +return sysfs_emit (buf,"%i\n" , rdata - offset); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1689/2651 platform/x86/amd: pmc: Drop scratch_reg from amd_1ah_m80_cpu_info
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mario Limonciello <[email protected]>
[ Upstream commit c84f2e1518d052f8699031330f1cc90cbf68740a ]
This platform does no longer populate this register.
--- drivers/platform/x86/amd/pmc/pmc.c | 1 - 1 file changed, 1 deletion(-)
drivers/platform/x86/amd/pmc/pmc.c +0 -1
@@ -183,7 +183,6 @@ static const struct amd_pmc_cpu_info amd_1ah_m80_cpu_info = { .smu_arg = AMD_PMC_REGISTER_ARG_1AH_80H, .smu_rsp = AMD_PMC_REGISTER_RSP_1AH_80H, .num_ips = ARRAY_SIZE(soc15_ip_blk_v3), - .scratch_reg = AMD_PMC_SCRATCH_REG_1AH, .ips_ptr = soc15_ip_blk_v3, .os_hint = MSG_OS_HINT_RN, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1690/2651 platform/x86/intel/pmc: Fix stale NVL PCD-S S0ix_LPM telemetry constants
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xi Pardee <[email protected]>
[ Upstream commit 2ac40383e9b70bae67ff4cdbb2108c006bf1b5e5 ]
The Nova Lake PCD-S S0ix_LPM telemetry layout changed. The PCD-S telemetry GUID was changed to reflect the layout change, per the client GUID revision rule.
nvl_pcds_d3_status_1_map[] was correctly updated, but two companion constants were never updated to match:
1. NVL_PCDS_NUM_S0IX_BLOCKER (core.h) is 71 instead of the actual
number of blk == 1 entries across nvl_pcds_blk_maps.
2. PCDS_LPM_REQ_GUID (nvl.c) is still 0x01091102. It was never
bumped to 0x01091103 to reflect the S0ix_LPM telemetry metadata
layout change.Both constants describe the same S0ix_LPM/blocker telemetry region for PCD-S, so fix them together in one change.
--- drivers/platform/x86/intel/pmc/core.h | 2 +- drivers/platform/x86/intel/pmc/nvl.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/platform/x86/intel/pmc/core.h +1 -1
@@ -323,7 +323,7 @@ enum ppfear_regs {#define NVL_LPM_LIVE_STATUS_OFFSET 0x1760#define NVL_LPM_NUM_MAPS 15#define NVL_PCDH_NUM_S0IX_BLOCKER 107 -#define NVL_PCDS_NUM_S0IX_BLOCKER 71 +#define NVL_PCDS_NUM_S0IX_BLOCKER 70#define NVL_PCHS_NUM_S0IX_BLOCKER 54#define NVL_PCDS_PMC_LTR_RESERVED 0x1bac#define NVL_PCDH_BLK_REQ_OFFSET 53
drivers/platform/x86/intel/pmc/nvl.c +1 -1
@@ -14,7 +14,7 @@/* PMC SSRAM PMT Telemetry GUIDS */ #define PCDH_LPM_REQ_GUID 0x01093101#define PCHS_LPM_REQ_GUID 0x01092101 -#define PCDS_LPM_REQ_GUID 0x01091102 +#define PCDS_LPM_REQ_GUID 0x01091103/* * Die Mapping to Product.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1691/2651 platform/x86/intel: power-domains: Handle failed init in tpmi_get_linux_die_id()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kristen Carlson Accardi <[email protected]>
[ Upstream commit e7aa0a21a38afd3063fd9b4bf31025a882537d95 ]
tpmi_init() returns early with -ENODEV on CPU models that are not in tpmi_cpu_ids, before domain_die_map is allocated. When the driver is built in, tpmi_get_linux_die_id() remains callable after the failed init and dereferences the NULL domain_die_map.
This is reachable from user space: uncore-frequency-tpmi calls tpmi_get_linux_die_id() from the show function of the world-readable die_id sysfs attribute. The attribute is created on multi-die packages for clusters with the core agent type, so reading it on such a CPU that is missing from tpmi_cpu_ids oopses.
Likewise, if cpuhp_setup_state() fails, the error path frees domain_die_map but leaves the pointer set, so a later call would read freed memory.
Return -ENODEV when the map was not allocated, and clear the pointer wherever it is freed.
tpmi_get_linux_cpu_number(), tpmi_get_punit_core_number() and tpmi_get_power_domain_id() read only the static per-CPU data and hash table, so they are safe after a failed init. tpmi_get_power_domain_mask() has the same problem as this helper but no callers, so it is handled separately.
--- drivers/platform/x86/intel/tpmi_power_domains.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/platform/x86/intel/tpmi_power_domains.c +9 -0
@@ -156,6 +156,13 @@ EXPORT_SYMBOL_NS_GPL(tpmi_get_power_domain_mask, "INTEL_TPMI_POWER_DOMAIN");int tpmi_get_linux_die_id (int pkg_id,int domain_id) { +/* +* When built in, this stays callable after tpmi_init() failed +* before allocating the map. +*/ +if (!domain_die_map) +return -ENODEV ; +if (pkg_id >=topology_max_packages () || domain_id >=MAX_POWER_DOMAINS )return -EINVAL ;
@@ -245,6 +252,7 @@ static int __init tpmi_init(void) free_domain_map:kfree (domain_die_map); + domain_die_map =NULL ; free_domain_mask:kfree (tpmi_power_domain_mask);
@@ -258,6 +266,7 @@ static void __exit tpmi_exit(void)cpuhp_remove_state (tpmi_hp_state);kfree (tpmi_power_domain_mask);kfree (domain_die_map); + domain_die_map =NULL ; }module_exit (tpmi_exit)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1692/2651 platform/x86: intel_telemetry: initialize default trace verbosity
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aleksandrova Alyona <[email protected]>
[ Upstream commit 1b55ec81926eb7f6e4fad692fa4040a569e9daf7 ]
telemetry_def_get_trace_verbosity() returns success without initializing the output verbosity value.
The default telemetry operations are installed when the core driver is initialized and again by telemetry_clear_pltdata() when the platform driver is removed. The telemetry debugfs files can remain available after the platform driver removal.
A subsequent read of pss_trace_verbosity or ioss_trace_verbosity calls telemetry_get_trace_verbosity(), which may use the default callback and return success without setting verbosity. The uninitialized value is then passed to seq_printf().
Validate the output pointer and initialize the default verbosity to zero so callers never use an uninitialized value after a successful call.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
--- drivers/platform/x86/intel/telemetry/core.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/platform/x86/intel/telemetry/core.c +4 -0
@@ -24,6 +24,10 @@ static struct telemetry_core_config telm_core_conf;static int telemetry_def_get_trace_verbosity (enum telemetry_unit telem_unit,u32 *verbosity) { +if (!verbosity) +return -EINVAL ; + + *verbosity =0 ;return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1693/2651 platform/olpc: Reserve space for a string terminator
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiale Yao <[email protected]>
[ Upstream commit 1fe88b1741ff655bb59e4fd78178fe2c557b9185 ]
ec_dbgfs_cmd_write() copies user input into a zero-initialized stack buffer and passes it to sscanf(). A write that overwrites the entire buffer leaves no terminator, so the subsequent parsing can read beyond the buffer.
Limit the copy to leave room for the trailing NUL.
--- drivers/platform/olpc/olpc-ec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/platform/olpc/olpc-ec.c +1 -1
@@ -269,7 +269,7 @@ static ssize_t ec_dbgfs_cmd_write(struct file *file, const char __user *buf,mutex_lock (&ec_dbgfs_lock); - size =simple_write_to_buffer (cmdbuf,sizeof (cmdbuf), ppos, buf, size); + size =simple_write_to_buffer (cmdbuf,sizeof (cmdbuf) -1 , ppos, buf, size); m = sscanf(cmdbuf, "%x:%u %x %x %x %x %x", &ec_cmd_int[0], &ec_dbgfs_resp_bytes, &ec_cmd_int[1], &ec_cmd_int[2],
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1694/2651 platform/x86: msi-wmi: Fix hotkeys dropped with vendor backlight
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Patryk Pilichowski <[email protected]>
[ Upstream commit 3e0193dc381468589e597c9e5144eb050d36f016 ]
Commit dee82409a883 ("platform/x86: msi-wmi: Reformat msi_wmi_notify()") turned the condition for reporting a hotkey into an early return, but only negated the brightness key comparisons, not the backlight check. As a result, when the driver registers its own backlight device, all WMI hotkeys are now dropped, instead of all of them being reported as before.
Restore the original behavior: only drop the brightness keys, and only when brightness is handled by the ACPI video driver.
This was found by code inspection. It is not tested on hardware that uses the vendor backlight; on an MSI Katana 15 B13VFK (no vendor backlight) hotkey handling is unchanged.
--- drivers/platform/x86/msi-wmi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/platform/x86/msi-wmi.c +3 -3
@@ -236,9 +236,9 @@ static void msi_wmi_notify(union acpi_object *obj, void *context) }/* Brightness is served via acpi video driver */ -if (key->type ==KE_KEY && - (backlight || (key->code ==MSI_KEY_BRIGHTNESSUP || - key->code ==MSI_KEY_BRIGHTNESSDOWN ))) +if (key->type ==KE_KEY && !backlight && + (key->code ==MSI_KEY_BRIGHTNESSUP || + key->code ==MSI_KEY_BRIGHTNESSDOWN ))return ;pr_debug ("Send key: 0x%X - Input layer keycode: %d\n" , key->code, key->keycode);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1695/2651 platform/x86/amd/pmc: clear devm-managed pointers on remove to prevent stale reuse
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shyam Sundar S K <[email protected]>
[ Upstream commit c9ba86f5411730ebd333d94b9e1aa8f652dc743f ]
The driver stores its state in a single file-scope static struct amd_pmc_dev, which is reused on every bind. Its regbase, smu_virt_addr, stb_virt_addr and fch_virt_addr members are MMIO mappings created with devm_ioremap().
On unbind the driver core unmaps these mappings, but it does not clear the pointers in the static struct. Since the struct is not freed, the members keep pointing at the now-unmapped addresses.
On the next bind, the probe path re-maps a region only when its pointer is still NULL, so the stale pointer is reused and the following memcpy_fromio()/ioread32() touches freed MMIO, causing use-after-unmap crash. Clear these pointers in amd_pmc_remove() so the next probe re-maps them instead of reusing stale ones.
--- drivers/platform/x86/amd/pmc/pmc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/platform/x86/amd/pmc/pmc.c +4 -0
@@ -957,6 +957,10 @@ static void amd_pmc_remove(struct platform_device *pdev)pci_dev_put (dev->rdev);if (IS_ENABLED (CONFIG_AMD_MP2_STB ))amd_mp2_stb_deinit (dev); + dev->regbase =NULL ; + dev->smu_virt_addr =NULL ; + dev->stb_virt_addr =NULL ; + dev->fch_virt_addr =NULL ; }static const struct acpi_device_id amd_pmc_acpi_ids[] = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1696/2651 platform: arm64: qcom-hamoa-ec: Disable the SCI IRQ during suspend
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abel Vesa <[email protected]>
[ Upstream commit d21c5d267ec0ccae7e629286d3ef51224494267c ]
EC SCI events require I2C transfers to retrieve the event information. During system resume, an SCI interrupt can be delivered before the I2C controller is ready to handle transfers, resulting in failed event reads:
geni_i2c a84000.i2c: error turning SE resources:-13 qcom-hamoa-ec 3-0076: Failed to read EC SCI Event: -13
Keep SCI interrupt handling disabled across system sleep so that EC events are processed only while the I2C controller is available. This prevents event reads from racing with the controller's suspend and resume transitions.
--- drivers/platform/arm64/qcom-hamoa-ec.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/platform/arm64/qcom-hamoa-ec.c +15 -4
@@ -331,17 +331,28 @@ static const struct thermal_cooling_device_ops qcom_ec_thermal_ops = {static int qcom_ec_resume (struct device *dev) {struct i2c_client *client =to_i2c_client (dev); +int ret; + + ret =i2c_smbus_write_byte_data (client,EC_MODERN_STANDBY_CMD , +EC_MODERN_STANDBY_EXIT ); +enable_irq (client->irq); -return i2c_smbus_write_byte_data (client,EC_MODERN_STANDBY_CMD , -EC_MODERN_STANDBY_EXIT ); +return ret; }static int qcom_ec_suspend (struct device *dev) {struct i2c_client *client =to_i2c_client (dev); +int ret; + +/* Keep SCI reads from racing the I2C controller's system sleep. */ +disable_irq (client->irq); + ret =i2c_smbus_write_byte_data (client,EC_MODERN_STANDBY_CMD , +EC_MODERN_STANDBY_ENTER ); +if (ret) +enable_irq (client->irq); -return i2c_smbus_write_byte_data (client,EC_MODERN_STANDBY_CMD , -EC_MODERN_STANDBY_ENTER ); +return ret; }static int qcom_ec_probe (struct i2c_client *client)
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1697/2651 fbdev: gxt4500: Release WC setup on probe failure
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myeonghun Pak <[email protected]>
[ Upstream commit b71e0bb7ad40c005b167e9b48be3af5a3fa51974 ]
gxt4500_probe() adds a write-combining range before allocating the cmap and registering the framebuffer. If a later step fails, the range is not released. Add the missing cleanup before unmapping the framebuffer, matching the successful remove path.
This issue was identified during our ongoing static-analysis research while reviewing kernel code.
--- drivers/video/fbdev/gxt4500.c | 1 + 1 file changed, 1 insertion(+)
drivers/video/fbdev/gxt4500.c +1 -0
@@ -719,6 +719,7 @@ static int gxt4500_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err_free_cmap:fb_dealloc_cmap (&info->cmap); err_unmap_all: +arch_phys_wc_del (par->wc_cookie);iounmap (info->screen_base); err_unmap_regs:iounmap (par->regs);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1698/2651 fbdev: atafb: fix sparse warnings
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Helge Deller <[email protected]>
[ Upstream commit ec4eb034cf8f38fe1ee1e9df07850953c0c2ec0e ]
Fix two sparse warnings:
- atafb.c:1092: sparse: Using plain integer as NULL pointer
Use NULL instead of 0 when assigning a pointer.
- atafb.c:2824: sparse: switch with no cases
FBCMD_GET_CURRENTPAR and and FBCMD_SET_CURRENTPAR seem to be historic defines, which are not any longer in the kernel, and as such the code isn't built any longer and may be dropped.
--- drivers/video/fbdev/atafb.c | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-)
drivers/video/fbdev/atafb.c +1 -25
@@ -1089,7 +1089,7 @@ static int falcon_decode_var(struct fb_info *info, struct fb_var_screeninfo *var/* Choose largest pixelclock <= wanted clock */ int i;unsigned long pcl =ULONG_MAX ; - pclock =0 ; + pclock =NULL ;for (i =1 ; i <=4 ; i *=2 ) {if (f25.t * i >= var->pixclock && f25.t * i < pcl) {
@@ -2818,29 +2818,6 @@ static void atafb_imageblit(struct fb_info *info, const struct fb_image *image) } } -static int -atafb_ioctl (struct fb_info *info,unsigned int cmd,unsigned long arg) -{ -switch (cmd) { -#ifdef FBCMD_GET_CURRENTPAR -case FBCMD_GET_CURRENTPAR : -if (copy_to_user ((void *)arg, ¤t_par, -sizeof (struct atafb_par ))) -return -EFAULT ; -return 0 ; -#endif -#ifdef FBCMD_SET_CURRENTPAR -case FBCMD_SET_CURRENTPAR : -if (copy_from_user (¤t_par, (void *)arg, -sizeof (struct atafb_par ))) -return -EFAULT ; -ata_set_par (¤t_par); -return 0 ; -#endif - } -return -EINVAL ; -} -/* (un)blank/poweroff * 0 = unblank * 1 = blank
@@ -2922,7 +2899,6 @@ static struct fb_ops atafb_ops = { .fb_fillrect = atafb_fillrect, .fb_copyarea = atafb_copyarea, .fb_imageblit = atafb_imageblit, - .fb_ioctl = atafb_ioctl, __FB_DEFAULT_IOMEM_OPS_MMAP, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1699/2651 fbdev: atafb: avoid cast when assigning buffer address pointer
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Helge Deller <[email protected]>
[ Upstream commit 111a4137edd2c4caad413efa5ebb8a37067c172c ]
The sparse tool complains that the "cast removes the address space '__iomem' of expression".
Avoid the cast by using the screen_buffer pointer instead of the screen_base pointer from the union.
--- drivers/video/fbdev/atafb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/fbdev/atafb.c +1 -1
@@ -2454,7 +2454,7 @@ static void svblit_fillrect(struct fb_info *info, ((u32 *)info->pseudo_palette)[rect->color] : rect->color;/* draw the first line with the CPU ... */ - line = (u8 *)info->screen_base + rect->dy * pitch + + line = info->screen_buffer + rect->dy * pitch + rect->dx * bytespp;switch (bytespp) {case 1 :
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1700/2651 ALSA: rawmidi: Drain input work before freeing the runtime
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 8c3529f0a8faaac7d73333486f69da1617ecc579 ]
The input runtime embeds event_work, so the work must be drained before close_substream() frees the runtime. The cancellation in snd_rawmidi_input_trigger() runs before close clears substream->opened, leaving a window for snd_rawmidi_receive() to enqueue more work.
With a sequencer subscription to a USB MIDI input port, an in-flight completion can overlap the last subscription's midisynth_unsubscribe():
1. snd_usbmidi_input_data() observes input_triggered and is delayed before calling snd_rawmidi_receive().
2. Unsubscribe enters close_substream(), clears input_triggered through the provider trigger callback and returns from cancel_work_sync(). The substream is still opened.
3. The completion resumes. snd_rawmidi_receive() takes substream->lock, sees opened set and queues runtime->event_work before dropping the lock.
4. Close clears opened under that lock, closes the provider and frees the runtime. Stopping USB URBs does not drain the raw-MIDI work.
5. The queued work runs and snd_rawmidi_input_event_work() reads event or substream from the freed runtime, causing a use-after-free.
Cancel input event_work again after clearing opened, before closing the provider or releasing the runtime's private data. Receive holds substream->lock through its opened check and work enqueue, so once close has cleared opened under that lock, no further receive can queue work. The final cancellation therefore drains any late work before the runtime is freed. Keep it outside the spinlock so a running callback can finish.
--- sound/core/rawmidi.c | 3 +++ 1 file changed, 3 insertions(+)
sound/core/rawmidi.c +3 -0
@@ -557,6 +557,9 @@ static void close_substream(struct snd_rawmidi *rmidi, substream->opened =0 ; substream->append =0 ; } +/* Drain input work queued after the earlier cancellation. */ +if (substream->stream ==SNDRV_RAWMIDI_STREAM_INPUT ) +cancel_work_sync (&substream->runtime->event_work); substream->ops->close (substream);if (substream->runtime->private_free) substream->runtime->private_free (substream);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1701/2651 ALSA: pcm: Protect delay DMA sync against concurrent HW_FREE
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cen Zhang <[email protected]>
[ Upstream commit 50f413b83b31ea8d8ee4276165ab95ed5ab0e10f ]
A PCM DMA buffer must remain allocated until explicit DMA synchronization finishes. snd_pcm_delay() calls snd_pcm_dma_buffer_sync() after dropping the stream lock, without participating in the buffer-access exclusion used by HW_FREE.
With a managed NONCONTIG buffer requiring explicit sync, HW_PARAMS can allocate a separate runtime descriptor when the requested ring exceeds the preallocation. In PREPARED state with mmap_count zero, concurrent HWSYNC and HW_FREE calls on the same open PCM file can interleave:
1. HWSYNC checks the state in snd_pcm_delay() under the stream lock and releases that lock.
2. The sync helper fetches runtime->dma_buffer_p and enters snd_dma_noncontig_sync() with that descriptor.
3. HW_FREE takes the negative buffer-access count, checks PREPARED under the stream lock, releases the lock, and frees the DMA allocation and dynamic descriptor through snd_pcm_lib_free_pages().
4. The sync callback resumes and reads the freed descriptor.
The stream lock does not cover the allocation's release, and the sync operation has no positive buffer-access count to prevent it. The stale read causes a use-after-free in snd_dma_noncontig_sync(). DELAY uses the same snd_pcm_delay() path.
Take a positive buffer-access count before checking the state and keep it until the DMA sync finishes, as the transfer and mmap paths already do. HW_FREE then returns -EBUSY while this access is active. If a buffer writer has already entered, snd_pcm_delay() returns -EBUSY before using the buffer. Keep the sync outside the stream lock and balance the count on the state-error path as well.
KASAN report as below:
BUG: KASAN: slab-use-after-free in snd_dma_noncontig_sync+0x295/0x310 [snd_pcm]
Read of size 4 at addr ffff888108f58584 by task pcm-uaf-fixture/487
CPU: 1 UID: 0 PID: 487 Comm: pcm-uaf-fixture Not tainted 7.2.0-rc6-pmb-alsa-functional-v2+ #1 PREEMPT(lazy)
Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
Call Trace:
<TASK>
dump_stack_lvl+0x93/0xd0
print_report+0xce/0x630
? snd_dma_noncontig_sync+0x295/0x310 [snd_pcm]
? srso_alias_return_thunk+0x5/0xfbef5
? __virt_addr_valid+0x20d/0x410
? snd_dma_noncontig_sync+0x295/0x310 [snd_pcm]
kasan_report+0xe0/0x110
? snd_dma_noncontig_sync+0x295/0x310 [snd_pcm]
? __pfx_snd_dma_noncontig_sync+0x10/0x10 [snd_pcm]
snd_dma_noncontig_sync+0x295/0x310 [snd_pcm]
? __pfx_snd_dma_noncontig_sync+0x10/0x10 [snd_pcm]
snd_dma_buffer_sync+0xc9/0x110 [snd_pcm]
snd_pcm_delay+0x3bd/0x550 [snd_pcm]
snd_pcm_common_ioctl+0x1e7/0x3aa0 [snd_pcm]
? srso_alias_return_thunk+0x5/0xfbef5
? do_vfs_ioctl+0x1f5/0x1280
? __pfx_do_vfs_ioctl+0x10/0x10
? ioctl_has_perm.constprop.0.isra.0+0x34f/0x500
? __pfx_snd_pcm_common_ioctl+0x10/0x10 [snd_pcm]
? srso_alias_return_thunk+0x5/0xfbef5
snd_pcm_ioctl+0x76/0xb0 [snd_pcm]
? __pfx_snd_pcm_ioctl+0x10/0x10 [snd_pcm]
__x64_sys_ioctl+0x163/0x1d0
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f1cae7ab91b
Code: 00 48 89 44 24 18 31 c0 48 8d 44 24 60 c7 04 24 10 00 00 00 48 89 44 24 08 48 8d 44 24 20 48 89 44 24 10 b8 10 00 00 00 0f 05 <89> c2 3d 00 f0 ff ff 77 1c 48 8b 44 24 18 64 48 2b 04 25 28 00 00
RSP: 002b:00007ffe12d544f0 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000004 RCX: 00007f1cae7ab91b
RDX: 0000000000000000 RSI: 0000000000004122 RDI: 0000000000000003
RBP: 00000000000001ee R08: 0000000000000073 R09: 00000000ffffffff
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000003
R13: 0000000000000001 R14: 00005584f32b1398 R15: 00005584f32b2ce8
</TASK>
Allocated by task 487:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
__kasan_kmalloc+0xaa/0xb0
__kmalloc_cache_noprof+0x251/0x610
snd_pcm_lib_malloc_pages+0x27c/0x9f0 [snd_pcm]
snd_pcm_hw_params+0x171c/0x1d10 [snd_pcm]
snd_pcm_common_ioctl+0x1f62/0x3aa0 [snd_pcm]
snd_pcm_ioctl+0x76/0xb0 [snd_pcm]
__x64_sys_ioctl+0x163/0x1d0
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Freed by task 499:
kasan_save_stack+0x33/0x60
kasan_save_track+0x14/0x30
kasan_save_free_info+0x3b/0x60
__kasan_slab_free+0x5f/0x80
kfree+0x307/0x580
snd_pcm_lib_free_pages+0x1c9/0x420 [snd_pcm]
snd_pcm_common_ioctl+0x2bd3/0x3aa0 [snd_pcm]
snd_pcm_ioctl+0x76/0xb0 [snd_pcm]
__x64_sys_ioctl+0x163/0x1d0
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
The buggy address belongs to the object at ffff888108f58580
which belongs to the cache kmalloc-64 of size 64
The buggy address is located 4 bytes inside of
freed 64-byte region [ffff888108f58580, ffff888108f585c0)
The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x108f58
flags: 0x200000000000000(node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000000 ffff8881000428c0 dead000000000100 dead000000000122
raw: 0000000000000000 0000000000200020 00000000f5000000 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff888108f58480: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff888108f58500: 00 00 00 00 00 06 fc fc fc fc fc fc fc fc fc fc
>ffff888108f58580: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
^
ffff888108f58600: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
ffff888108f58680: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
==================================================================
Disabling lock debugging due to kernel taint
------------[ cut here ]------------
kernel BUG at kernel/dma/mapping.c:417!
Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI
CPU: 1 UID: 0 PID: 487 Comm: pcm-uaf-fixture Tainted: G B 7.2.0-rc6-pmb-alsa-functional-v2+ #1 PREEMPT(lazy)
Tainted: [B]=BAD_PAGE
Hardware name: QEMU Ubuntu 24.04 PC v2 (i440FX + PIIX, arch_caps fix, 1996), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
RIP: 0010:__dma_sync_sg_for_cpu+0x230/0x360
Code: df 48 c1 e8 03 80 3c 10 00 0f 85 fa 00 00 00 4c 8b 35 d4 6b 7a 09 e8 7f e2 17 00 83 fd 02 0f 86 39 fe ff ff e8 71 e2 17 00 90 <0f> 0b e8 69 e2 17 00 be 08 00 00 00 4c 89 ff e8 bc 5f 77 00 4c 89
RSP: 0018:ffff888111f3fc50 EFLAGS: 00010293
RAX: 0000000000000000 RBX: ffffffffc0250d10 RCX: ffffffff816d395f
RDX: ffff88810836ba00 RSI: ffff888108f58580 RDI: ffffffffc02510d8
RBP: 00000000ffff8881 R08: 0000000000000000 R09: fffffbfff804a239
R10: ffffffffc02511cf R11: 6e696c6261736944 R12: ffff888108f58580
R13: 0000000002ce00e5 R14: ffffffffc0258720 R15: 0000000000000000
FS: 00007f1cae69c780(0000) GS:ffff8881fd861000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000055d1affa2480 CR3: 0000000108fc0003 CR4: 0000000000770ef0
PKRU: 55555554
Call Trace:
<TASK>
snd_dma_noncontig_sync+0x15a/0x310 [snd_pcm]
? __pfx_snd_dma_noncontig_sync+0x10/0x10 [snd_pcm]
snd_dma_buffer_sync+0xc9/0x110 [snd_pcm]
snd_pcm_delay+0x3bd/0x550 [snd_pcm]
snd_pcm_common_ioctl+0x1e7/0x3aa0 [snd_pcm]
? srso_alias_return_thunk+0x5/0xfbef5
? do_vfs_ioctl+0x1f5/0x1280
? __pfx_do_vfs_ioctl+0x10/0x10
? ioctl_has_perm.constprop.0.isra.0+0x34f/0x500
? __pfx_snd_pcm_common_ioctl+0x10/0x10 [snd_pcm]
? srso_alias_return_thunk+0x5/0xfbef5
snd_pcm_ioctl+0x76/0xb0 [snd_pcm]
? __pfx_snd_pcm_ioctl+0x10/0x10 [snd_pcm]
__x64_sys_ioctl+0x163/0x1d0
do_syscall_64+0x115/0x6a0
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7f1cae7ab91b
Code: 00 48 89 44 24 18 31 c0 48 8d 44 24 60 c7 04 24 10 00 00 00 48 89 44 24 08 48 8d 44 24 20 48 89 44 24 10 b8 10 00 00 00 0f 05 <89> c2 3d 00 f0 ff ff 77 1c 48 8b 44 24 18 64 48 2b 04 25 28 00 00
RSP: 002b:00007ffe12d544f0 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
RAX: ffffffffffffffda RBX: 0000000000000004 RCX: 00007f1cae7ab91b
RDX: 0000000000000000 RSI: 0000000000004122 RDI: 0000000000000003
RBP: 00000000000001ee R08: 0000000000000073 R09: 00000000ffffffff
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000003
R13: 0000000000000001 R14: 00005584f32b1398 R15: 00005584f32b2ce8
</TASK>
Modules linked in: snd_pcmtest snd_pcm
---[ end trace 0000000000000000 ]---
RIP: 0010:__dma_sync_sg_for_cpu+0x230/0x360
Code: df 48 c1 e8 03 80 3c 10 00 0f 85 fa 00 00 00 4c 8b 35 d4 6b 7a 09 e8 7f e2 17 00 83 fd 02 0f 86 39 fe ff ff e8 71 e2 17 00 90 <0f> 0b e8 69 e2 17 00 be 08 00 00 00 4c 89 ff e8 bc 5f 77 00 4c 89
RSP: 0018:ffff888111f3fc50 EFLAGS: 00010293
RAX: 0000000000000000 RBX: ffffffffc0250d10 RCX: ffffffff816d395f
RDX: ffff88810836ba00 RSI: ffff888108f58580 RDI: ffffffffc02510d8
RBP: 00000000ffff8881 R08: 0000000000000000 R09: fffffbfff804a239
R10: ffffffffc02511cf R11: 6e696c6261736944 R12: ffff888108f58580
R13: 0000000002ce00e5 R14: ffffffffc0258720 R15: 0000000000000000
FS: 00007f1cae69c780(0000) GS:ffff8881fd861000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 000055d1affa2480 CR3: 0000000108fc0003 CR4: 0000000000770ef0
PKRU: 55555554
Kernel panic - not syncing: Fatal exception
Kernel Offset: disabled
Rebooting in 1 seconds..--- sound/core/pcm_native.c | 5 +++++ 1 file changed, 5 insertions(+)
sound/core/pcm_native.c +5 -0
@@ -3110,14 +3110,19 @@ static snd_pcm_sframes_t snd_pcm_forward(struct snd_pcm_substream *substream,static int snd_pcm_delay (struct snd_pcm_substream *substream,snd_pcm_sframes_t *delay) { +struct snd_pcm_runtime *runtime = substream->runtime;int err; +/* Keep the DMA buffer alive through the sync below. */ +if (!atomic_inc_unless_negative (&runtime->buffer_accessing)) +return -EBUSY ; scoped_guard(pcm_stream_lock_irq, substream) { err =do_pcm_hwsync (substream);if (delay && !err) *delay =snd_pcm_calc_delay (substream); }snd_pcm_dma_buffer_sync (substream,SNDRV_DMA_SYNC_CPU ); +atomic_dec (&runtime->buffer_accessing);return err; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1702/2651 bnge: skip dev_addr when building the VNIC unicast list
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vikas Gupta <[email protected]>
[ Upstream commit 0b3fc7fe6f3f68569b9f9139893491b61a4b45b9 ]
The default VNIC programs the device's MAC as L2 filter 0 in bnge_init_chip() via bnge_hwrm_set_vnic_filter(bn, 0, 0, dev_addr). bnge_cfg_rx_mode() then walks dev->uc and programs each unicast address as a further L2 filter, without excluding dev_addr.
Skip dev_addr when building uc_list, since it is already installed as filter 0. As dev_addr now takes neither a uc_list slot nor an l2_filters[] slot, count only the non-dev_addr entries for the uc_list overflow check too, otherwise an input such as {dev_addr, A, B, C} would needlessly fall back to promiscuous mode even though A, B and C fit in exact-match filters. bnge_uc_list_updated() applies the same skip and count so the change detection stays consistent and does not loop.
This issue was caught by Sashiko (nipa).
Tested on Thor Ultra device.
--- .../net/ethernet/broadcom/bnge/bnge_netdev.c | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-)
drivers/net/ethernet/broadcom/bnge/bnge_netdev.c +20 -8
@@ -2182,19 +2182,21 @@ static bool bnge_uc_list_updated(struct bnge_net *bn, const struct netdev_hw_addr_list *uc) {struct bnge_vnic_info *vnic = &bn->vnic_info[BNGE_VNIC_DEFAULT ]; +struct net_device *dev = bn->netdev;struct netdev_hw_addr *ha; -int off =0 ; - -if (netdev_hw_addr_list_count (uc) != (vnic->uc_filter_count -1 )) -return true; +int off =0 , count =0 ;netdev_hw_addr_list_for_each (ha, uc) { +if (ether_addr_equal (ha->addr, dev->dev_addr)) +continue ; +if (count >= vnic->uc_filter_count -1 ) +return true;if (!ether_addr_equal (ha->addr, vnic->uc_list + off))return true; - off +=ETH_ALEN ; + count++; } -return false; +return count != vnic->uc_filter_count -1 ; }static bool bnge_promisc_ok (struct bnge_net *bn)
@@ -2207,9 +2209,9 @@ static int bnge_cfg_rx_mode(struct bnge_net *bn, struct netdev_hw_addr_list *uc, {struct bnge_vnic_info *vnic = &bn->vnic_info[BNGE_VNIC_DEFAULT ];struct net_device *dev = bn->netdev; +int i, off =0 , rc, uc_count =0 ;struct bnge_dev *bd = bn->bd;struct netdev_hw_addr *ha; -int i, off =0 , rc;if (!uc_update) goto skip_uc;
@@ -2225,10 +2227,20 @@ static int bnge_cfg_rx_mode(struct bnge_net *bn, struct netdev_hw_addr_list *uc,if (!snapshot)netif_addr_lock_bh (dev); -if (netdev_hw_addr_list_count (uc) > (BNGE_MAX_UC_ADDRS -1 )) { +/* dev_addr is already programmed as L2 filter 0, so it takes neither a +* uc_list slot nor an l2_filters[] slot. Count only the entries that +* will actually be programmed so the overflow check matches the fill +* loop below (and bnge_uc_list_updated()). +*/ +netdev_hw_addr_list_for_each (ha, uc) +if (!ether_addr_equal (ha->addr, dev->dev_addr)) + uc_count++; +if (uc_count >BNGE_MAX_UC_ADDRS -1 ) { vnic->rx_mask |=CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS ; }else {netdev_hw_addr_list_for_each (ha, uc) { +if (ether_addr_equal (ha->addr, dev->dev_addr)) +continue ;memcpy (vnic->uc_list + off, ha->addr,ETH_ALEN ); off +=ETH_ALEN ; vnic->uc_filter_count++;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1703/2651 PCI: qcom: Honor IOMMU providers #iommu-cells in qcom_pcie_config_sid_1_9_0()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Manivannan Sadhasivam <[email protected]>
[ Upstream commit 5121d76cb9dde74662962cd5678a64abeaf3b3e4 ]
qcom_pcie_config_sid_1_9_0() reads the "iommu-map" property as an array of fixed four-word {rid-base, phandle, sid, rid-len} entries to program the BDF to SID translation table. But that layout only holds for an IOMMU with '#iommu-cells = <1>'. The PCIe SMMUs on these SoCs use '#iommu-cells = <2>' (SID and mask), so per the pci-iommu binding each entry is really five cells long.
This used to work only because the DTs were themselves broken. They described iommu-map with four-cell entries that omitted the SID mask, which of_map_id() tolerated via its of_check_bad_map() fallback, and the four-word parsing coincidentally matched that malformed shape.
Since commit ccb2fd725d41 ("of: Respect #{iommu,msi}-cells in maps") the OF core parses such maps correctly, so the device trees were converted to proper five-cell entries, e.g. commit c41749e9554d ("arm64: dts:
qcom: sm8250: Fix the PCIe iommu-map entries"). With five-cell entries the fixed four-word stride slips by one cell for each entry after the first, so qcom_pcie_config_sid_1_9_0() reads the endpoint mapping's RID from the preceding entry's length cell and its SID from the phandle cell. As the RID is the hash key, the endpoint's real RID is never programmed into the BDF to SID table. Its DMA then hashes to an unprogrammed slot, gets tagged with SID 0 and the SMMU faults like below on QCS8300:
arm-smmu 15200000.iommu: Unhandled context fault: fsr=0x402, iova=0xffa00000, cbfrsynra=0x0, cb=1
To fix this, walk the map with a stride of 3 + '#iommu-cells' of the referenced IOMMU and take the SID from the first specifier cell, which is all the BDF to SID table needs. Validate the layout instead of trusting the array size. Also, preserve the legacy behavior of the old DTs by detecting the same pattern that of_check_bad_map() recognizes and falling back to a stride of four.
--- drivers/pci/controller/dwc/pcie-qcom.c | 90 ++++++++++++++++++-------- 1 file changed, 64 insertions(+), 26 deletions(-)
drivers/pci/controller/dwc/pcie-qcom.c +64 -26
@@ -1143,50 +1143,90 @@ static void qcom_pcie_deinit_2_7_0(struct qcom_pcie *pcie)static int qcom_pcie_config_sid_1_9_0 (struct qcom_pcie *pcie) { -/* iommu map structure */ -struct { -u32 bdf; -u32 phandle; -u32 smmu_sid; -u32 smmu_sid_len; - } *map;void __iomem *bdf_to_sid_base = pcie->parf +PARF_BDF_TO_SID_TABLE_N ;struct device *dev = pcie->pci->dev; +struct device_node *iommu_np;u8 qcom_pcie_crc8_table[CRC8_TABLE_SIZE ]; -int i, nr_map, size =0 ; -u32 smmu_sid_base; +const __be32 *map; +u32 iommu_cells, entry_cells, phandle, smmu_sid_base; +int i, nr_cells, nr_map, size =0 ;u32 val; -of_get_property (dev->of_node,"iommu-map" , &size); -if (!size) + map =of_get_property (dev->of_node,"iommu-map" , &size); +if (!map || !size)return 0 ; +if (size %sizeof (*map)) { +dev_err (dev,"Malformed iommu-map property\n" ); +return -EINVAL ; + } + nr_cells = size /sizeof (*map); + +/* +* Each iommu-map entry is: rid-base (1 cell), phandle (1 cell), +* IOMMU specifier (#iommu-cells cells), length (1 cell). Read +* #iommu-cells from the IOMMU provider referenced by the first +* entry to compute the per-entry stride. +*/ + phandle =be32_to_cpu (map[1 ]); + iommu_np =of_find_node_by_phandle (phandle); +if (!iommu_np) { +dev_err (dev,"Failed to find IOMMU node in iommu-map\n" ); +return -ENODEV ; + } + +if (of_property_read_u32 (iommu_np,"#iommu-cells" , &iommu_cells)) + iommu_cells =1 ; +of_node_put (iommu_np); + + entry_cells =3 + iommu_cells; + +/* +* Retain backward compatibility with DTs that describe iommu-map +* with 4-cell entries against an IOMMU declaring #iommu-cells = 2, +* matching the fallback in drivers/of/base.c::of_check_bad_map(). +*/ +if (iommu_cells ==2 && !(nr_cells %4 )) { +bool legacy = true; + +for (i =0 ; i < nr_cells; i +=4 ) { +if (be32_to_cpu (map[i +1 ]) != phandle || +be32_to_cpu (map[i +3 ]) !=1 ) { + legacy = false; +break ; + } + } + +if (legacy) { +dev_warn_once (dev,"iommu-map has 1-cell entries with #iommu-cells=2, using 1-cell\n" ); + entry_cells =4 ; + } + } + +if (nr_cells % entry_cells) { +dev_err (dev,"Malformed iommu-map property\n" ); +return -EINVAL ; + } + nr_map = nr_cells / entry_cells; +/* Enable BDF to SID translation by disabling bypass mode (default) */ val =readl (pcie->parf +PARF_BDF_TO_SID_CFG ); val &= ~BDF_TO_SID_BYPASS ;writel (val, pcie->parf +PARF_BDF_TO_SID_CFG ); - map =kzalloc (size,GFP_KERNEL ); -if (!map) -return -ENOMEM ; - -of_property_read_u32_array (dev->of_node,"iommu-map" , (u32 *)map, - size /sizeof (u32)); - - nr_map = size / (sizeof (*map)); -crc8_populate_msb (qcom_pcie_crc8_table,QCOM_PCIE_CRC8_POLYNOMIAL );/* Registers need to be zero out first */ memset_io (bdf_to_sid_base,0 ,CRC8_TABLE_SIZE *sizeof (u32));/* Extract the SMMU SID base from the first entry of iommu-map */ - smmu_sid_base = map[0 ].smmu_sid; + smmu_sid_base =be32_to_cpu (map[2 ]);/* Look for an available entry to hold the mapping */ for (i =0 ; i < nr_map; i++) { -__be16 bdf_be =cpu_to_be16 (map[i].bdf); -u32 val; +u32 bdf =be32_to_cpu (map[i * entry_cells]); +u32 sid =be32_to_cpu (map[i * entry_cells +2 ]); +__be16 bdf_be =cpu_to_be16 (bdf);u8 hash; hash =crc8 (qcom_pcie_crc8_table, (u8 *)&bdf_be,sizeof (bdf_be),0 );
@@ -1208,12 +1248,10 @@ static int qcom_pcie_config_sid_1_9_0(struct qcom_pcie *pcie) }/* BDF [31:16] | SID [15:8] | NEXT [7:0] */ - val = map[i].bdf <<16 | (map[i].smmu_sid - smmu_sid_base) <<8 |0 ; + val = bdf <<16 | (sid - smmu_sid_base) <<8 |0 ;writel (val, bdf_to_sid_base + hash *sizeof (u32)); } -kfree (map); -return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1704/2651 calipso: hash the cache key, not the option start, in calipso_cache_add()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joas Antonio dos Santos <[email protected]>
[ Upstream commit d538cc3ec0bc4cb7b40981b3213a6c6671959ed5 ]
calipso_cache_add() stores calipso_ptr + 2 as the cache key, but computes entry->hash over calipso_ptr, i.e. starting two bytes earlier at the option type and length. calipso_opt_getattr() looks entries up with calipso_cache_check(calipso + 2, calipso[1], ...), which hashes the key itself.
The two hashes only match on a jhash collision, so the CALIPSO label cache never hits and every labelled packet takes the full DOI lookup and category conversion path. The memcmp() on the key keeps lookups correct, so this is a performance bug only.
Hash the stored key, as cipso_v4_cache_add() does for CIPSO.
--- net/ipv6/calipso.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/ipv6/calipso.c +1 -1
@@ -283,7 +283,7 @@ static int calipso_cache_add(const unsigned char *calipso_ptr, goto cache_add_failure; } entry->key_len = calipso_ptr_len; - entry->hash =calipso_map_cache_hash (calipso_ptr, calipso_ptr_len); + entry->hash =calipso_map_cache_hash (entry->key, calipso_ptr_len);refcount_inc (&secattr->cache->refcount); entry->lsm_data = secattr->cache;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1705/2651 clocksource/drivers/timer-mediatek: Fix random crash at boot
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Luca Leonardo Scorcia <[email protected]>
[ Upstream commit 8496a1d234e8cf9cb15c4282cb3a11c6550bd242 ]
MediaTek bootloaders generally enable APXGPT timers at boot. This means that a timer IRQ can sometimes happen between the IRQ line request and the configuration of the clock event handler. This leads to a hard crash with an instruction abort, branch to pc 0x0 in mtk_gpt_interrupt handler as clkevt is null.
To avoid this issue request the IRQ with IRQF_NO_AUTOEN and enable it explicitly after the clock event is configured.
Issue was reported and fix tested on the Lenovo Tab E7 (TB-7104F, mt8167).
--- drivers/clocksource/timer-mediatek.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/clocksource/timer-mediatek.c +3 -1
@@ -277,7 +277,7 @@ static struct timer_of to = { }, .of_irq = { - .flags = IRQF_TIMER | IRQF_IRQPOLL, + .flags = IRQF_TIMER | IRQF_IRQPOLL | IRQF_NO_AUTOEN, }, };
@@ -298,6 +298,7 @@ static int __init mtk_syst_init(struct device_node *node)clockevents_config_and_register (&to.clkevt,timer_of_rate (&to),TIMER_SYNC_TICKS ,0xffffffff ); +enable_irq (timer_of_irq (&to));return 0 ; }
@@ -334,6 +335,7 @@ static int __init mtk_gpt_init(struct device_node *node) TIMER_SYNC_TICKS, 0xffffffff);mtk_gpt_enable_irq (&to,TIMER_CLK_EVT ); +enable_irq (timer_of_irq (&to));return 0 ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1706/2651 RDMA/siw: Enforce IB_ACCESS_REMOTE_READ for read responses
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haitam Lazaar <[email protected]>
[ Upstream commit f74eac4fc6c56274fb96c2c44ffad8f01c325f17 ]
When generating an RDMA READ response (SIW_OP_READ_RESPONSE), siw_check_sgl_tx() unconditionally passes 0 as the required permission mask:
/* Reference memory to be tx'd w/o checking access for LOCAL_READ */
rv = siw_check_sgl_tx(qp->pd, wqe, 0);Because perms is 0, siw_check_mem()'s authorization test:
if ((mem->perms & perms) < perms)
evaluates to (mem->perms & 0) < 0, which is always false. Consequently, an untrusted remote peer can issue an RDMA Read targeting any valid STag in the Protection Domain, even if the memory was registered strictly as write-only (IB_ACCESS_REMOTE_WRITE) without IB_ACCESS_REMOTE_READ.
Enforce that the target memory region was granted IB_ACCESS_REMOTE_READ when answering SIW_OP_READ_RESPONSE work queue entries, while preserving perms = 0 for standard local sends.
--- drivers/infiniband/sw/siw/siw_qp_tx.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/infiniband/sw/siw/siw_qp_tx.c +11 -7
@@ -805,17 +805,21 @@ static int siw_qp_sq_proc_tx(struct siw_qp *qp, struct siw_wqe *wqe)if (wqe->wr_status ==SIW_WR_QUEUED ) {if (!(wqe->sqe.flags &SIW_WQE_INLINE )) { -if (tx_type (wqe) ==SIW_OP_READ_RESPONSE ) - wqe->sqe.num_sge =1 ; -if (tx_type (wqe) !=SIW_OP_READ &&tx_type (wqe) !=SIW_OP_READ_LOCAL_INV ) { +enum ib_access_flags perms =0 ; +/* -* Reference memory to be tx'd w/o checking -* access for LOCAL_READ permission, since -* not defined in RDMA core. +* Local READ permission doesn't exist in RDMA core. +* A READ RESPONSE source is read by the remote peer, +* so it must be checked for REMOTE_READ permission. */ - rv =siw_check_sgl_tx (qp->pd, wqe,0 ); +if (tx_type (wqe) ==SIW_OP_READ_RESPONSE ) { + perms =IB_ACCESS_REMOTE_READ ; + wqe->sqe.num_sge =1 ; + } + + rv =siw_check_sgl_tx (qp->pd, wqe, perms);if (rv <0 ) {if (tx_type (wqe) ==SIW_OP_READ_RESPONSE )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1707/2651 RDMA/efa: Fix race between admin command timeout and completion
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yonatan Nachum <[email protected]>
[ Upstream commit 466612f8a8020c6b3af6377c730775a4c630f12c ]
An admin command that times out can race with the interrupt handler processing its completion, in two ways.
The timeout path releases the completion context without synchronizing against the handler. A handler that has already seen the command as submitted then copies the CQE into the caller's response buffer after the waiter returned and that buffer went out of scope.
The waiter can also observe the command as completed before the CQE was copied, since the status is published first. It decodes its own uninitialized response buffer, returns success with garbage contents and leaks stack data to the caller. Both wait paths read the status without the CQ lock.
Add a timed-out state and publish it under the CQ lock in both wait paths before returning, so the handler, which only completes commands in submitted state, cannot act on an abandoned context. In the interrupt wait path test the return value of the wait instead of the status: the handler signals the completion after copying the CQE, so a successful wait implies a valid response. Read the status in the polling wait path inside the critical section that drains the CQ, which also lets a completion arriving on the last iteration be honored instead of reported as a timeout.
--- drivers/infiniband/hw/efa/efa_com.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)
drivers/infiniband/hw/efa/efa_com.c +20 -8
@@ -41,6 +41,7 @@ enum efa_cmd_status {EFA_CMD_ALLOCATED ,EFA_CMD_SUBMITTED ,EFA_CMD_COMPLETED , + EFA_CMD_TIMED_OUT, }; struct efa_comp_ctx {
@@ -591,6 +592,7 @@ static int efa_com_comp_status_to_errno(u8 comp_status)static int efa_com_wait_and_process_admin_cq_polling (struct efa_comp_ctx *comp_ctx,struct efa_com_admin_queue *aq) { +bool comp_timeout = false;unsigned long timeout;unsigned long flags;
@@ -599,12 +601,19 @@ static int efa_com_wait_and_process_admin_cq_polling(struct efa_comp_ctx *comp_cwhile (1 ) {spin_lock_irqsave (&aq->cq.lock, flags);efa_com_handle_admin_completion (aq); -spin_unlock_irqrestore (&aq->cq.lock, flags); - -if (comp_ctx->status !=EFA_CMD_SUBMITTED ) +if (comp_ctx->status !=EFA_CMD_SUBMITTED ) { +spin_unlock_irqrestore (&aq->cq.lock, flags);break ; + }if (time_is_before_jiffies (timeout)) { + comp_ctx->status =EFA_CMD_TIMED_OUT ; + comp_timeout = true; + } + +spin_unlock_irqrestore (&aq->cq.lock, flags); + +if (comp_timeout) {ibdev_err_ratelimited ( aq->efa_dev,"Wait for completion (polling) timeout\n" );
@@ -625,10 +634,11 @@ static int efa_com_wait_and_process_admin_cq_polling(struct efa_comp_ctx *comp_cstatic int efa_com_wait_and_process_admin_cq_interrupts (struct efa_comp_ctx *comp_ctx,struct efa_com_admin_queue *aq) { -unsigned long flags; +unsigned long flags, remaining_jiffies; +bool completed; -wait_for_completion_timeout (&comp_ctx->wait_event, -usecs_to_jiffies (aq->completion_timeout)); + remaining_jiffies =wait_for_completion_timeout ( + &comp_ctx->wait_event,usecs_to_jiffies (aq->completion_timeout));/* * In case the command wasn't completed find out the root cause.
@@ -636,14 +646,16 @@ static int efa_com_wait_and_process_admin_cq_interrupts(struct efa_comp_ctx *com* 1) No completion (timeout reached) * 2) There is completion but the device didn't get any msi-x interrupt. */ -if (comp_ctx->status ==EFA_CMD_SUBMITTED ) { +if (remaining_jiffies ==0 ) {spin_lock_irqsave (&aq->cq.lock, flags);efa_com_handle_admin_completion (aq); + completed = (comp_ctx->status ==EFA_CMD_COMPLETED ); + comp_ctx->status =EFA_CMD_TIMED_OUT ;spin_unlock_irqrestore (&aq->cq.lock, flags);atomic64_inc (&aq->stats.no_completion); -if (comp_ctx->status ==EFA_CMD_COMPLETED ) +if (completed) ibdev_err_ratelimited( aq->efa_dev, "The device sent a completion but the driver didn't receive any MSI-X interrupt for admin cmd %s(%d) status %d (id: %d, sq producer: %d, sq consumer: %d, cq consumer: %d)\n",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1708/2651 wifi: mac80211: fix encryption tailroom
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chien Wong <[email protected]>
[ Upstream commit c49f54fd2abff08964677db8fdc1674c713ab42c ]
BIP-CMAC-256 and BIP-GMAC append a 26-byte MME but mac80211 currently reserves only 18 bytes of encryption tailroom.
Generating 26-byte MME may happen to work because the actual skb tailroom can exceed the requested amount. For example, dev_alloc_skb() rounds the allocation to kmalloc size buckets or alignment boundaries, and the extra space may cover the 8-byte shortfall.
Reserve enough tailroom for the 26-byte MME.
--- net/mac80211/ieee80211_i.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/mac80211/ieee80211_i.h +1 -1
@@ -52,7 +52,7 @@ struct ieee80211_mesh_fast_tx;/* Required encryption head and tailroom */ #define IEEE80211_ENCRYPT_HEADROOM 8 -#define IEEE80211_ENCRYPT_TAILROOM 18 +#define IEEE80211_ENCRYPT_TAILROOM 26/* current max: GMAC/CMAC-256 MME */ /* power level hasn't been configured (or set to automatic) */ #define IEEE80211_UNSET_POWER_LEVEL INT_MIN
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1709/2651 wifi: mac80211: reserve MME tailroom for protected beacons
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chien Wong <[email protected]>
[ Upstream commit 48002331da85c7c962cfbc09c8bd84d219a6fe1c ]
Beacon protection appends an MME to beacons, but the skb allocation does not reserve tailroom for it. If the available tailroom is too small, the crypto path drops the beacon.
Two factors often mask this: the 256-byte TIM reservation is rarely fully used, and dev_alloc_skb() may round up the allocation, leaving extra tailroom. Neither guarantees enough room for the MME.
Reserve enough room for the largest MME.
--- net/mac80211/tx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/mac80211/tx.c +2 -1
@@ -5769,7 +5769,8 @@ __ieee80211_beacon_get_ap(struct ieee80211_hw *hw, skb =dev_alloc_skb (local->tx_headroom + beacon->head_len + beacon->tail_len +256 + - local->hw.extra_beacon_tailroom + mbssid_len); + local->hw.extra_beacon_tailroom + mbssid_len + +IEEE80211_ENCRYPT_TAILROOM );if (!skb)return NULL ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1710/2651 wifi: mwifiex: append hotfix number to firmware version string
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Chen <[email protected]>
[ Upstream commit 958f20d5aa0aa645068454fdb62ebc625ac9a115 ]
mwifiex_ret_get_hw_spec() parses and logs the FW_HOTFIX_VER_ID TLV, but the hotfix value is not stored in the adapter structure. As a result, the hotfix number never appears in the firmware version string returned by mwifiex_drv_get_driver_version().
Store the hotfix version from FW_HOTFIX_VER_ID and append it to the firmware version string.
--- drivers/net/wireless/marvell/mwifiex/cmdevt.c | 10 ++++++++-- drivers/net/wireless/marvell/mwifiex/fw.h | 6 ++++++ drivers/net/wireless/marvell/mwifiex/init.c | 1 + drivers/net/wireless/marvell/mwifiex/main.h | 1 + drivers/net/wireless/marvell/mwifiex/sta_ioctl.c | 3 ++- 5 files changed, 18 insertions(+), 3 deletions(-)
drivers/net/wireless/marvell/mwifiex/cmdevt.c +8 -2
@@ -1594,11 +1594,17 @@ int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv, api_rev->major_ver, api_rev->minor_ver);break ; -case FW_HOTFIX_VER_ID : +case FW_HOTFIX_VER_ID : { +struct hw_spec_fw_hotfix_ver *hf; + + hf = (void *)tlv; + adapter->fw_hotfix_ver = +le16_to_cpu (hf->hotfix_ver);mwifiex_dbg (adapter,INFO ,"Firmware hotfix version %d\n" , - api_rev->major_ver); + adapter->fw_hotfix_ver);break ; + }default : mwifiex_dbg(adapter, FATAL, "Unknown api_id: %d\n",
drivers/net/wireless/marvell/mwifiex/fw.h +6 -0
@@ -1104,6 +1104,12 @@ struct hw_spec_api_rev {u8 minor_ver; } __packed; +struct hw_spec_fw_hotfix_ver { +struct mwifiex_ie_types_header header; +__le16 api_id; +__le16 hotfix_ver; +} __packed; +struct host_cmd_ds_get_hw_spec {__le16 hw_if_version;__le16 version;
drivers/net/wireless/marvell/mwifiex/init.c +1 -0
@@ -296,6 +296,7 @@ static void mwifiex_init_adapter(struct mwifiex_adapter *adapter) adapter->config_bands =0 ; adapter->adhoc_start_band =0 ; adapter->fw_release_number =0 ; + adapter->fw_hotfix_ver =0 ; adapter->fw_cap_info =0 ;memset (&adapter->upld_buf,0 ,sizeof (adapter->upld_buf)); adapter->event_cause =0 ;
drivers/net/wireless/marvell/mwifiex/main.h +1 -0
@@ -1003,6 +1003,7 @@ struct mwifiex_adapter {bool host_mlme_enabled;struct ieee80211_txrx_stypes mwifiex_mgmt_stypes[NUM_NL80211_IFTYPES ];u8 fw_api_ver; +u16 fw_hotfix_ver;u8 key_api_major_ver, key_api_minor_ver;u8 max_p2p_conn, max_sta_conn;struct memory_type_mapping *mem_type_mapping_tbl;
drivers/net/wireless/marvell/mwifiex/sta_ioctl.c +2 -1
@@ -1144,7 +1144,8 @@ mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter, char *version,char fw_ver[32 ]; ver.l =cpu_to_le32 (adapter->fw_release_number); -sprintf (fw_ver,"%u.%u.%u.p%u" , ver.c[2 ], ver.c[1 ], ver.c[0 ], ver.c[3 ]); +sprintf (fw_ver,"%u.%u.%u.p%u.%u" , ver.c[2 ], ver.c[1 ], + ver.c[0 ], ver.c[3 ], adapter->fw_hotfix_ver);snprintf (version, max_len, driver_version, fw_ver);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1711/2651 serial: qcom-geni: power the console back up on system resume
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Heidelberg <[email protected]>
[ Upstream commit e95442c31ae65b57ddffdfa609531c549055f308 ]
The console holds a runtime PM reference on its port, which keeps the port powered while the tty is closed. On system suspend pm_runtime_force_suspend() powers the port down regardless, but a single reference makes pm_runtime_need_not_resume() report the port as not in use, so it is marked runtime suspended instead of being flagged for pm_runtime_force_resume(). On system resume the port therefore stays powered down while uart_resume_port() goes on to program the termios settings and re-enable the console.
If the tty has been opened before, uart_resume_port() ends up in startup(), whose runtime PM reference powers the port up again, and only the register writes made before that are lost. If the tty has never been opened (no getty on the port, /dev/console backed by another console), nothing powers the port back up and the console stays dead after the first suspend.
Resume the port explicitly before uart_resume_port() when the console was force suspended.
--- drivers/tty/serial/qcom_geni_serial.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/tty/serial/qcom_geni_serial.c +6 -0
@@ -2128,6 +2128,12 @@ static int qcom_geni_serial_resume(struct device *dev)return ret; } +if (console_suspend_enabled &&uart_console (uport)) { + ret =pm_runtime_resume (dev); +if (ret <0 ) +return ret; + } + ret =uart_resume_port (private_data->drv, uport);if (uart_console (uport)) {geni_icc_set_tag (&port->se,QCOM_ICC_TAG_ALWAYS );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1712/2651 tcp_bic: fix divide by zero on max_increment == 0
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit 8edbf6c23363563e508a61f3f26f4e4b6eec9dd5 ]
max_increment is how many packets cwnd can grow per RTT, so 0 makes no sense, and bictcp_update() divides by it.
Reject values below 1 when the parameter is written.
--- net/ipv4/tcp_bic.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
net/ipv4/tcp_bic.c +12 -2
@@ -27,15 +27,25 @@*/ static int fast_convergence =1 ; -static int max_increment =16 ; +static unsigned int max_increment =16 ;static int low_window =14 ;static int beta =819 ;/* = 819/1024 (BICTCP_BETA_SCALE) */ static int initial_ssthresh;static int smooth_part =20 ; +static int max_increment_set (const char *val,const struct kernel_param *kp) +{ +return param_set_uint_minmax (val, kp,1 ,INT_MAX ); +} + +static const struct kernel_param_ops max_increment_ops = { + .set = max_increment_set, + .get = param_get_uint, +}; +module_param (fast_convergence, int,0644 );MODULE_PARM_DESC (fast_convergence,"turn on/off fast convergence" ); -module_param (max_increment, int,0644 ); +module_param_cb (max_increment, &max_increment_ops, &max_increment,0644 );MODULE_PARM_DESC (max_increment,"Limit on increment allowed during binary search" );module_param (low_window, int,0644 );MODULE_PARM_DESC (low_window,"lower bound on congestion window (for TCP friendliness)" );
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1713/2651 tcp_hybla: fix divide by zero on rtt0 == 0
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit f09eb97322b16a6f709a47599c95b62f786905f9 ]
rtt0 is the reference RTT in ms, so 0 makes no sense, and hybla_recalc_param() divides by it right from hybla_init().
Reject values below 1 when the parameter is written. Also cap it at U32_MAX / USEC_PER_MSEC, since rtt0 * USEC_PER_MSEC can wrap to 0 on 32-bit. An rtt0 above that (about 71 minutes) makes no sense anyway.
--- net/ipv4/tcp_hybla.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
net/ipv4/tcp_hybla.c +14 -2
@@ -26,8 +26,20 @@ struct hybla { };/* Hybla reference round trip time (default= 1/40 sec = 25 ms), in ms */ -static int rtt0 =25 ; -module_param (rtt0, int,0644 ); +static unsigned int rtt0 =25 ; + +static int rtt0_set (const char *val,const struct kernel_param *kp) +{ +/* avoid rtt0 * USEC_PER_MSEC overflow */ +return param_set_uint_minmax (val, kp,1 ,U32_MAX /USEC_PER_MSEC ); +} + +static const struct kernel_param_ops rtt0_ops = { + .set = rtt0_set, + .get = param_get_uint, +}; + +module_param_cb (rtt0, &rtt0_ops, &rtt0,0644 );MODULE_PARM_DESC (rtt0,"reference rout trip time (ms)" );/* This is called to refresh values for hybla parameters */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1714/2651 tcp_cubic: fix divide by zero and endless loop on bad module params
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiayuan Chen <[email protected]>
[ Upstream commit 7d52b5d16afc1cf8484ae321658e217a80e3ff4d ]
beta_scale and cube_factor are computed once at module init, and beta == 1024 or bic_scale == 0 is a divide by zero right there. Other out of range values give garbage: negative beta can make beta_scale 0, and bic_scale * 10 can overflow. Reject them. Read beta once, as it can be written through sysfs before the init function runs.
A small beta also gives a small beta_scale, and (cwnd * beta_scale) >> 3 truncates to 0 for a tiny cwnd, so the TCP friendliness loop never ends. Rather than testing delta on every ACK, make sure beta_scale is at least 8 at init, so delta is >= 1 within the cwnd < 1 million packets limit this code is designed for. This slows the TCP friendly estimate for beta < 512, a backoff harder than Reno's 0.5, which is not a setting anyone should use.
--- net/ipv4/tcp_cubic.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
net/ipv4/tcp_cubic.c +12 -2
@@ -500,16 +500,26 @@ static const struct btf_kfunc_id_set tcp_cubic_kfunc_set = {static int __init cubictcp_register (void ) { +int b =READ_ONCE (beta);int ret;BUILD_BUG_ON (sizeof (struct bictcp ) >ICSK_CA_PRIV_SIZE ); +if (b <0 || b >=BICTCP_BETA_SCALE || + bic_scale <=0 || bic_scale >INT_MAX /10 ) { +pr_err ("tcp_cubic: invalid beta %d or bic_scale %d\n" , + b, bic_scale); +return -EINVAL ; + } +/* Precompute a bunch of the scaling factors that are used per-packet * based on SRTT of 100ms */ - beta_scale =8 *(BICTCP_BETA_SCALE +beta) /3 - / (BICTCP_BETA_SCALE - beta); + beta_scale =8 * (BICTCP_BETA_SCALE + b) /3 + / (BICTCP_BETA_SCALE - b); +/* bictcp_update() needs (cwnd * beta_scale) >> 3 to be >= 1 */ + beta_scale =max (beta_scale,8U ); cube_rtt_scale = (bic_scale *10 );/* 1024*c/rtt */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1715/2651 serial: max310x: dont clobber the TX break bit in set_termios
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tapio Reijonen <[email protected]>
[ Upstream commit 3b2de448ec0332c1cb8c38b4c5ff0c8e860befbc ]
A TX break asserted with TIOCSBRK ends early, with no error reported, as soon as any termios change lands on the port: a break is a state that must hold until TIOCCBRK, but max310x_set_termios() overwrites the whole LCR register, and LCR also carries the TX break bit that break_ctl() drives. No concurrency is required - a baud or parity change from the same process ends the break just as well, and break-led protocols lose their break with nothing in the logs.
Update only the LCR bits that are derived from termios and leave the TX break and RTS pin control bits untouched. Since nothing clears a break when a port is closed with the break still asserted - the tty core sends no break-off on release, and the unconditional write here was the accidental recovery - clear TXBREAK in startup(), the same way 8250 does.
--- drivers/tty/serial/max310x.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/tty/serial/max310x.c +15 -2
@@ -156,6 +156,8 @@#define MAX310X_LCR_FORCEPARITY_BIT (1 << 5)/* 9-bit multidrop parity */ #define MAX310X_LCR_TXBREAK_BIT (1 << 6)/* TX break enable */ #define MAX310X_LCR_RTS_BIT (1 << 7)/* RTS pin control */ +/* LCR bits owned by termios; TX break and RTS are driven elsewhere */ +#define MAX310X_LCR_TERMIOS_MASK GENMASK(5, 0)/* IRDA register bits */ #define MAX310X_IRDA_IRDAEN_BIT (1 << 0)/* IRDA mode enable */
@@ -971,8 +973,12 @@ static void max310x_set_termios(struct uif (termios->c_cflag &CSTOPB ) lcr |=MAX310X_LCR_STOPLEN_BIT ;/* 2 stops */ -/* Update LCR register */ -max310x_port_write (port,MAX310X_LCR_REG , lcr); +/* +* Update LCR register. Leave the TX break bit alone: it is driven by +* break_ctl(), and a whole-register write here would end a break in +* progress. +*/ +max310x_port_update (port,MAX310X_LCR_REG ,MAX310X_LCR_TERMIOS_MASK , lcr);/* Set read status mask */ port->read_status_mask =MAX310X_LSR_RXOVR_BIT ;
@@ -1090,6 +1096,13 @@ static int max310x_startup(struct uart_pmax310x_power (port,1 ); +/* +* Clear a latched break: nothing clears TXBREAK when a port is +* closed with a break still asserted, and set_termios() no longer +* rewrites it. +*/ +max310x_port_update (port,MAX310X_LCR_REG ,MAX310X_LCR_TXBREAK_BIT ,0 ); +/* Configure MODE1 register */ max310x_port_update (port,MAX310X_MODE1_REG ,MAX310X_MODE1_TRNSCVCTRL_BIT ,0 );
Greg Kroah-Hartman
maintainerPATCH 1716/2651 serial: max310x: fix breaks not reaching the wire in RS485 mode
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tapio Reijonen <[email protected]>
[ Upstream commit 4efacb600bf98b13e0659f05afa4549795277e35 ]
The chip's auto-RTS (MODE1.TRNSCVCTRL) asserts the RS485 transceiver only while FIFO data is shifting out, and a break is not FIFO data: on an RS485 port a requested break sets the TX break bit but the transceiver is never enabled, so the break never reaches the wire. Break-led protocols cannot work at all.
Disable auto-RTS for the break duration and drive RTS manually via the LCR RTS bit, then restore auto-RTS when the break ends. Track the break in tx_break and leave MODE1 alone in the rs485-config worker while it is set - a TIOCSRS485 arriving mid-break would otherwise re-enable auto-RTS on top of the manual RTS and release the transceiver before the break ends; break_ctl() restores auto-RTS from the then-current configuration when the break completes. The worker runs under port->mutex - break_ctl() and set_termios() already do - so the tx_break test and the MODE1 write cannot straddle a break starting or ending, and startup() clears tx_break alongside the latched TXBREAK bit, since a port can be closed with a break still asserted.
Only the break assertion is gated on RS485 being enabled; the restore at break end runs unconditionally and derives MODE1 from the current configuration. Returning early for a port whose RS485 was disabled mid-break - that reconfigure is deferred like any other - would leak the manually driven RTS and leave the transceiver holding the bus indefinitely after the break ends. On a non-RS485 port the restore is a no-op: nothing else writes the LCR RTS bit.
--- drivers/tty/serial/max310x.c | 49 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-)
drivers/tty/serial/max310x.c +47 -2
@@ -296,6 +296,7 @@ struct max310x_one {struct work_struct md_work;struct work_struct rs_work;struct regmap *regmap; +bool tx_break;/* break_ctl() owns the transceiver */ u8 rx_buf[MAX310X_FIFO_SIZE ]; };
@@ -680,6 +681,12 @@ static void max310x_batch_read(struct uaregmap_noinc_read (one->regmap,MAX310X_RHR_REG , rxbuf, len); } +static void max310x_rts_ctl (struct uart_port *port,bool rts_state) +{ +max310x_port_update (port,MAX310X_LCR_REG ,MAX310X_LCR_RTS_BIT , + rts_state ?MAX310X_LCR_RTS_BIT :0 ); +} +static void max310x_handle_rx (struct uart_port *port,unsigned int rxlen) {struct max310x_one *one =to_max310x_port (port);
@@ -931,9 +938,32 @@ static void max310x_set_mctrl(struct uarstatic void max310x_break_ctl (struct uart_port *port,int break_state) { +struct max310x_one *one =to_max310x_port (port); + + one->tx_break = break_state; +max310x_port_update (port,MAX310X_LCR_REG ,MAX310X_LCR_TXBREAK_BIT , break_state ?MAX310X_LCR_TXBREAK_BIT :0 ); + +/* +* The chip's auto-RTS asserts the transceiver only while FIFO data is +* shifting out, and a break is not FIFO data. Disable auto-RTS for the +* break duration and drive RTS manually so the break reaches the wire; +* restore auto-RTS when the break ends. +*/ +if (break_state) { +if (!(port->rs485.flags &SER_RS485_ENABLED )) +return ; +max310x_port_update (port,MAX310X_MODE1_REG , +MAX310X_MODE1_TRNSCVCTRL_BIT ,0 ); + }else { +max310x_port_update (port,MAX310X_MODE1_REG , +MAX310X_MODE1_TRNSCVCTRL_BIT , + (port->rs485.flags &SER_RS485_ENABLED ) ? +MAX310X_MODE1_TRNSCVCTRL_BIT :0 ); + } +max310x_rts_ctl (port, break_state); } static void max310x_set_termios(struct uart_port *port,
@@ -1057,6 +1087,13 @@ static void max310x_rs_proc(struct work_ struct max310x_one *one = container_of(ws, struct max310x_one, rs_work);unsigned int delay, mode1 =0 , mode2 =0 ; +/* +* Serialize against break_ctl() and set_termios(), which run under +* port->mutex: the tx_break test below and the MODE1 write must not +* straddle a break starting or ending. +*/ +guard (mutex)(&one->port.state->port.mutex); + delay = (one->port.rs485.delay_rts_before_send <<4 ) | one->port.rs485.delay_rts_after_send;max310x_port_write (&one->port,MAX310X_HDPIXDELAY_REG , delay);
@@ -1068,8 +1105,14 @@ static void max310x_rs_proc(struct work_ mode2 =MAX310X_MODE2_ECHOSUPR_BIT ; } -max310x_port_update (&one->port,MAX310X_MODE1_REG , -MAX310X_MODE1_TRNSCVCTRL_BIT , mode1); +/* +* A break owns the transceiver: break_ctl() disabled auto-RTS and +* drives RTS manually, and restores it when the break ends. Leave +* MODE1 alone meanwhile or the break goes undriven mid-way. +*/ +if (!one->tx_break) +max310x_port_update (&one->port,MAX310X_MODE1_REG , +MAX310X_MODE1_TRNSCVCTRL_BIT , mode1);max310x_port_update (&one->port,MAX310X_MODE2_REG ,MAX310X_MODE2_ECHOSUPR_BIT , mode2); }
@@ -1092,6 +1135,7 @@ static int max310x_rs485_config(struct ustatic int max310x_startup (struct uart_port *port) { +struct max310x_one *one =to_max310x_port (port);unsigned int val;max310x_power (port,1 );
@@ -1101,6 +1145,7 @@ static int max310x_startup(struct uart_p* closed with a break still asserted, and set_termios() no longer * rewrites it. */ + one->tx_break = false;max310x_port_update (port,MAX310X_LCR_REG ,MAX310X_LCR_TXBREAK_BIT ,0 );/* Configure MODE1 register */
Greg Kroah-Hartman
maintainerPATCH 1717/2651 serial: max310x: centralize the RS485 transceiver programming
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tapio Reijonen <[email protected]>
[ Upstream commit 56051740bf9720335a1a56e87a99e3491c33ce54 ]
The HDPIXDELAY RTS delays and the MODE1 auto-transceiver enable are programmed in three places - the rs485-config worker, startup() and break_ctl()'s break-off restore - each with its own copy of the register sequence. Move the sequence into a helper, max310x_set_rts_ctl_params(), together with the tx_break guard that keeps the MODE1 write away from a break in progress; the break-off restore reapplies the current configuration through the same helper.
No functional change intended. The copies differed only in that startup() clamped the delays to the 4-bit field while the worker wrote them unclamped; the helper clamps, and the difference is unreachable while rs485_config() still rejects delays above 15 ms with -ERANGE. Break-off additionally rewrites HDPIXDELAY with the values it already holds, a no-op on the wire.
Stable-dep-of: 7784d6aee59a ("serial: max310x: fix RS485 delays being programmed as bit-times")
--- drivers/tty/serial/max310x.c | 85 +++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 38 deletions(-)
drivers/tty/serial/max310x.c +47 -38
@@ -936,6 +936,38 @@ static void max310x_set_mctrl(struct uarschedule_work (&one->md_work); } +/* +* Program the chip's RS485 RTS timing (HDPIXDELAY) and the auto +* transceiver control (MODE1) from the current configuration. The +* rs485-config worker, startup() and break_ctl()'s break-off restore +* each carried their own copy of this sequence. +*/ +static void max310x_set_rts_ctl_params (struct max310x_one *one) +{ +struct uart_port *port = &one->port; +unsigned int delay; +u8 mode1 =0 ; + + delay = (clamp (port->rs485.delay_rts_before_send,0U ,15U ) <<4 ) | +clamp (port->rs485.delay_rts_after_send,0U ,15U ); +max310x_port_write (port,MAX310X_HDPIXDELAY_REG , delay); + +if (port->rs485.flags &SER_RS485_ENABLED ) + mode1 =MAX310X_MODE1_TRNSCVCTRL_BIT ; + +/* +* A break owns the transceiver: break_ctl() disabled auto-RTS and +* drives RTS manually, and restores it from the current +* configuration when the break ends. Touching MODE1 here would +* release the transceiver mid-break. +*/ +if (one->tx_break) +return ; + +max310x_port_update (port,MAX310X_MODE1_REG , +MAX310X_MODE1_TRNSCVCTRL_BIT , mode1); +} +static void max310x_break_ctl (struct uart_port *port,int break_state) {struct max310x_one *one =to_max310x_port (port);
@@ -958,10 +990,7 @@ static void max310x_break_ctl(struct uarmax310x_port_update (port,MAX310X_MODE1_REG ,MAX310X_MODE1_TRNSCVCTRL_BIT ,0 ); }else { -max310x_port_update (port,MAX310X_MODE1_REG , -MAX310X_MODE1_TRNSCVCTRL_BIT , - (port->rs485.flags &SER_RS485_ENABLED ) ? -MAX310X_MODE1_TRNSCVCTRL_BIT :0 ); +max310x_set_rts_ctl_params (one); }max310x_rts_ctl (port, break_state); }
@@ -1085,36 +1114,23 @@ static void max310x_set_termios(struct ustatic void max310x_rs_proc (struct work_struct *ws) { struct max310x_one *one = container_of(ws, struct max310x_one, rs_work); -unsigned int delay, mode1 =0 , mode2 =0 ; +unsigned int mode2 =0 ;/* * Serialize against break_ctl() and set_termios(), which run under -* port->mutex: the tx_break test below and the MODE1 write must not +* port->mutex: the tx_break-guarded register writes must not * straddle a break starting or ending. */ guard (mutex)(&one->port.state->port.mutex); - delay = (one->port.rs485.delay_rts_before_send <<4 ) | - one->port.rs485.delay_rts_after_send; -max310x_port_write (&one->port,MAX310X_HDPIXDELAY_REG , delay); - -if (one->port.rs485.flags &SER_RS485_ENABLED ) { - mode1 =MAX310X_MODE1_TRNSCVCTRL_BIT ; +max310x_set_rts_ctl_params (one); -if (!(one->port.rs485.flags &SER_RS485_RX_DURING_TX )) - mode2 =MAX310X_MODE2_ECHOSUPR_BIT ; - } +if (one->port.rs485.flags &SER_RS485_ENABLED && + !(one->port.rs485.flags &SER_RS485_RX_DURING_TX )) + mode2 =MAX310X_MODE2_ECHOSUPR_BIT ; -/* -* A break owns the transceiver: break_ctl() disabled auto-RTS and -* drives RTS manually, and restores it when the break ends. Leave -* MODE1 alone meanwhile or the break goes undriven mid-way. -*/ -if (!one->tx_break) -max310x_port_update (&one->port,MAX310X_MODE1_REG , -MAX310X_MODE1_TRNSCVCTRL_BIT , mode1);max310x_port_update (&one->port,MAX310X_MODE2_REG , -MAX310X_MODE2_ECHOSUPR_BIT , mode2); +MAX310X_MODE2_ECHOSUPR_BIT , mode2); } static int max310x_rs485_config(struct uart_port *port, struct ktermios *termios,
@@ -1158,21 +1174,14 @@ static int max310x_startup(struct uart_pmax310x_port_update (port,MAX310X_MODE2_REG ,MAX310X_MODE2_FIFORST_BIT ,0 ); -/* Configure mode1/mode2 to have rs485/rs232 enabled at startup */ - val = (clamp (port->rs485.delay_rts_before_send,0U ,15U ) <<4 ) | -clamp (port->rs485.delay_rts_after_send,0U ,15U ); -max310x_port_write (port,MAX310X_HDPIXDELAY_REG , val); - -if (port->rs485.flags &SER_RS485_ENABLED ) { -max310x_port_update (port,MAX310X_MODE1_REG , -MAX310X_MODE1_TRNSCVCTRL_BIT , -MAX310X_MODE1_TRNSCVCTRL_BIT ); +/* Configure the RS485 RTS timing and the RS485/RS232 mode bits. */ +max310x_set_rts_ctl_params (one); -if (!(port->rs485.flags &SER_RS485_RX_DURING_TX )) -max310x_port_update (port,MAX310X_MODE2_REG , -MAX310X_MODE2_ECHOSUPR_BIT , -MAX310X_MODE2_ECHOSUPR_BIT ); - } +if (port->rs485.flags &SER_RS485_ENABLED && + !(port->rs485.flags &SER_RS485_RX_DURING_TX )) +max310x_port_update (port,MAX310X_MODE2_REG , +MAX310X_MODE2_ECHOSUPR_BIT , +MAX310X_MODE2_ECHOSUPR_BIT );/* * Configure flow control levels:
Greg Kroah-Hartman
maintainerPATCH 1718/2651 serial: max310x: fix RS485 delays being programmed as bit-times
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tapio Reijonen <[email protected]>
[ Upstream commit 7784d6aee59a142505072b3fbea97932b2fd1fa0 ]
The HDPIXDELAY register counts the RTS setup and hold delays in bit-times, four bits per direction, but the driver has been writing the struct serial_rs485 delay_rts_before_send/delay_rts_after_send values into it unconverted - and the uapi expresses those in milliseconds. A requested 9 ms setup delay is programmed as 9 bit-times, which at 9600 baud is 0.94 ms, roughly a tenth of what userspace asked for; the error grows with the baud rate.
Cache the baud rate in set_termios() and convert the delays to bit-times at the current rate, rounding up so the delay on the wire is never shorter than requested, and capping at the 15 bit-times the 4-bit field can hold. The conversion lives in max310x_set_rts_ctl_params(); set_termios() now calls it as well, since the conversion depends on the baud rate.
The delays a 4-bit bit-time field can represent still fall well short of the milliseconds the uapi can express; requests beyond 15 bit-times are capped, and the -ERANGE rejection of values above 15 ms remains in place for now.
--- drivers/tty/serial/max310x.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-)
drivers/tty/serial/max310x.c +31 -9
@@ -163,6 +163,10 @@#define MAX310X_IRDA_IRDAEN_BIT (1 << 0)/* IRDA mode enable */ #define MAX310X_IRDA_SIR_BIT (1 << 1)/* SIR mode enable */ +/* HDPIXDELAY accessor macros */ +#define MAX310X_HDPIXDELAY_SETUP (val) (((val) & 0x0f) << 4) +#define MAX310X_HDPIXDELAY_HOLD (val) ((val) & 0x0f) +/* Flow control trigger level register masks */ #define MAX310X_FLOWLVL_HALT_MASK GENMASK(3, 0)/* Flow control halt level */ #define MAX310X_FLOWLVL_RES_MASK GENMASK(7, 4)/* Flow control resume level */
@@ -296,6 +300,7 @@ struct max310x_one {struct work_struct md_work;struct work_struct rs_work;struct regmap *regmap; +unsigned int baud;bool tx_break;/* break_ctl() owns the transceiver */ u8 rx_buf[MAX310X_FIFO_SIZE ];
@@ -937,23 +942,33 @@ static void max310x_set_mctrl(struct uar }/* -* Program the chip's RS485 RTS timing (HDPIXDELAY) and the auto -* transceiver control (MODE1) from the current configuration. The -* rs485-config worker, startup() and break_ctl()'s break-off restore -* each carried their own copy of this sequence. +* Program the chip's RS485 RTS timing. The HDPIXDELAY setup and hold fields +* count bit-times, four bits per direction, while the uapi expresses the +* delays in milliseconds: convert at the current baud rate, rounding up, and +* cap at the field maximum. */ static void max310x_set_rts_ctl_params (struct max310x_one *one) { +const unsigned int max_bit_dly =15 ;struct uart_port *port = &one->port; -unsigned int delay; +unsigned int setup =0 , hold =0 ;u8 mode1 =0 ; - delay = (clamp (port->rs485.delay_rts_before_send,0U ,15U ) <<4 ) | -clamp (port->rs485.delay_rts_after_send,0U ,15U ); -max310x_port_write (port,MAX310X_HDPIXDELAY_REG , delay); +if (port->rs485.flags &SER_RS485_ENABLED ) { +/* Convert milliseconds to bit-times, rounding up. */ + setup =DIV_ROUND_UP (one->baud * port->rs485.delay_rts_before_send, +MSEC_PER_SEC ); + hold =DIV_ROUND_UP (one->baud * port->rs485.delay_rts_after_send, +MSEC_PER_SEC ); + setup =min (setup, max_bit_dly); + hold =min (hold, max_bit_dly); -if (port->rs485.flags &SER_RS485_ENABLED ) mode1 =MAX310X_MODE1_TRNSCVCTRL_BIT ; + } + +max310x_port_write (port,MAX310X_HDPIXDELAY_REG , +MAX310X_HDPIXDELAY_SETUP (setup) | +MAX310X_HDPIXDELAY_HOLD (hold));/* * A break owns the transceiver: break_ctl() disabled auto-RTS and
@@ -1109,6 +1124,13 @@ static void max310x_set_termios(struct u/* Update timeout according to new baud rate */ uart_update_timeout (port, termios->c_cflag, baud); + +/* +* Cache the new baud rate and reprogram the RS485 RTS delays, whose +* millisecond-to-bit-time conversion depends on it. +*/ +to_max310x_port (port)->baud = baud; +max310x_set_rts_ctl_params (to_max310x_port (port)); }static void max310x_rs_proc (struct work_struct *ws)
Greg Kroah-Hartman
maintainerPATCH 1719/2651 serial: max310x: dont power down the port mid-transmission on close
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tapio Reijonen <[email protected]>
[ Upstream commit c3ad42ccd303113a08bd0b441fb5b3380f29c5bf ]
max310x_shutdown() powers the port down regardless of what the transmitter is doing. The power-off stops the UART clock mid-character, truncating the final frame, and on the auto-RTS path it freezes the RTS output at its current level: a close() with data still queued leaves the RS485 transceiver asserted until the next open, which also emits the interrupted character corrupted.
Waiting for the data to drain is no better: the tty layer's wait-until-sent is bounded by closing_wait, configurable to none, and a hangup arrives with no wait at all, so draining a full FIFO blocks close() in uninterruptible sleep for seconds at low baud rates - and forever when CTS flow control blocks the FIFO.
Instead, set MODE1 TxDisabl: the character in flight completes and the transmitter ceases with TX_ at idle. Give that character one character time (the chip has no transmitter-idle status), then reset the FIFOs so the auto-RTS engine sees the transmitter empty and releases RTS within the configured after-send hold; wait that hold plus one bit time before powering off. Abandoned data was explicitly not waited for, and startup() resets the FIFOs and TxDisabl on open anyway.
Measured on a MAX14830: a truncating close() at 50 baud takes 0.23 s, RTS releases one character plus the hold after the last stop bit on both polarities, and the reopen corruption is gone.
--- drivers/tty/serial/max310x.c | 44 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-)
drivers/tty/serial/max310x.c +40 -4
@@ -300,6 +300,7 @@ struct max310x_one {struct work_struct md_work;struct work_struct rs_work;struct regmap *regmap; +unsigned int char_time_us;unsigned int baud;bool tx_break;/* break_ctl() owns the transceiver */
@@ -1014,6 +1015,7 @@ static void max310x_set_termios(struct ustruct ktermios *termios, const struct ktermios *old) { + unsigned int frame_bits = tty_get_frame_size(termios->c_cflag);unsigned int lcr =0 , flow =0 ;int baud;
@@ -1126,10 +1128,13 @@ static void max310x_set_termios(struct uuart_update_timeout (port, termios->c_cflag, baud);/* -* Cache the new baud rate and reprogram the RS485 RTS delays, whose -* millisecond-to-bit-time conversion depends on it. +* Cache the new baud rate and the time it takes to clock out one +* character before reprogramming the RS485 RTS delays: the +* millisecond-to-bit-time conversion divides by the baud rate. */ to_max310x_port (port)->baud = baud; +to_max310x_port (port)->char_time_us = +DIV_ROUND_UP (USEC_PER_SEC * frame_bits, baud);max310x_set_rts_ctl_params (to_max310x_port (port)); }
@@ -1186,9 +1191,10 @@ static int max310x_startup(struct uart_p one->tx_break = false;max310x_port_update (port,MAX310X_LCR_REG ,MAX310X_LCR_TXBREAK_BIT ,0 ); -/* Configure MODE1 register */ +/* Configure MODE1: re-enable the transmitter shutdown() stopped */ max310x_port_update (port,MAX310X_MODE1_REG , -MAX310X_MODE1_TRNSCVCTRL_BIT ,0 ); +MAX310X_MODE1_TRNSCVCTRL_BIT | +MAX310X_MODE1_TXDIS_BIT ,0 );/* Configure MODE2 register & Reset FIFOs*/ val =MAX310X_MODE2_RXEMPTINV_BIT |MAX310X_MODE2_FIFORST_BIT ;
@@ -1225,9 +1231,39 @@ static int max310x_startup(struct uart_pstatic void max310x_shutdown (struct uart_port *port) { +struct max310x_one *one =to_max310x_port (port); +/* Disable all interrupts */ max310x_port_write (port,MAX310X_IRQEN_REG ,0 ); +/* +* Stop the transmitter: the character in flight completes, data +* still queued is abandoned (the next startup() resets the FIFOs). +*/ +max310x_port_update (port,MAX310X_MODE1_REG , +MAX310X_MODE1_TXDIS_BIT ,MAX310X_MODE1_TXDIS_BIT ); + +/* +* Let the character in flight finish (the chip has no +* transmitter-idle status), then empty the FIFO: auto-RTS releases +* only once the transmitter is empty, and the power-off below +* would freeze an asserted pin until the next open. +*/ +fsleep (one->char_time_us); +max310x_port_update (port,MAX310X_MODE2_REG , +MAX310X_MODE2_FIFORST_BIT , +MAX310X_MODE2_FIFORST_BIT ); +max310x_port_update (port,MAX310X_MODE2_REG , +MAX310X_MODE2_FIFORST_BIT ,0 ); +if (port->rs485.flags &SER_RS485_ENABLED && one->baud) { +unsigned int hold =DIV_ROUND_UP (one->baud * + port->rs485.delay_rts_after_send, +MSEC_PER_SEC ); + +fsleep (max (DIV_ROUND_UP ((hold +1 ) *USEC_PER_SEC , + one->baud),100U )); + } +max310x_power (port,0 ); }
Greg Kroah-Hartman
maintainerPATCH 1720/2651 serial: max310x: support active-low RTS on the hardware path
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tapio Reijonen <[email protected]>
[ Upstream commit 7b07356e820e9543cb5b64d009c345303aad0c65 ]
The chip's auto-RTS engine asserts the RTS_ pin high while data is shifting out, so a transceiver with an active-low driver-enable could not use the hardware RS485 path at all: SER_RS485_RTS_AFTER_SEND is not in the supported flags and the core normalizes it away with "invalid RTS setting, using RTS_ON_SEND instead".
The output stage is invertible: program IRDA.RTSINVERT when the requested polarity is active-low and advertise SER_RS485_RTS_AFTER_SEND in rs485_supported. A break already drives break_state onto the RTS bit unadjusted, which remains correct because RTSINVERT inverts the output stage itself, not the register value.
Stable-dep-of: 33632215e1bb ("serial: max310x: drive RTS in software when hardware delays are too short")
--- drivers/tty/serial/max310x.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/tty/serial/max310x.c +15 -3
@@ -162,6 +162,7 @@/* IRDA register bits */ #define MAX310X_IRDA_IRDAEN_BIT (1 << 0)/* IRDA mode enable */ #define MAX310X_IRDA_SIR_BIT (1 << 1)/* SIR mode enable */ +#define MAX310X_IRDA_RTSINVERT_BIT (1 << 2)/* Invert RTS output */ /* HDPIXDELAY accessor macros */ #define MAX310X_HDPIXDELAY_SETUP (val) (((val) & 0x0f) << 4)
@@ -953,7 +954,7 @@ static void max310x_set_rts_ctl_params(sconst unsigned int max_bit_dly =15 ;struct uart_port *port = &one->port;unsigned int setup =0 , hold =0 ; -u8 mode1 =0 ; +u8 mode1 =0 , irda =0 ;if (port->rs485.flags &SER_RS485_ENABLED ) {/* Convert milliseconds to bit-times, rounding up. */
@@ -965,6 +966,12 @@ static void max310x_set_rts_ctl_params(s hold =min (hold, max_bit_dly); mode1 =MAX310X_MODE1_TRNSCVCTRL_BIT ; +/* +* The auto-RTS engine asserts RTS high on send; for an +* active-low RTS let IRDA.RTSINVERT invert the output stage. +*/ +if (!(port->rs485.flags &SER_RS485_RTS_ON_SEND )) + irda =MAX310X_IRDA_RTSINVERT_BIT ; } max310x_port_write(port, MAX310X_HDPIXDELAY_REG,
@@ -982,6 +989,8 @@ static void max310x_set_rts_ctl_params(smax310x_port_update (port,MAX310X_MODE1_REG ,MAX310X_MODE1_TRNSCVCTRL_BIT , mode1); +max310x_port_update (port,MAX310X_IRDA_REG , +MAX310X_IRDA_RTSINVERT_BIT , irda); }static void max310x_break_ctl (struct uart_port *port,int break_state)
@@ -998,7 +1007,9 @@ static void max310x_break_ctl(struct uar* The chip's auto-RTS asserts the transceiver only while FIFO data is * shifting out, and a break is not FIFO data. Disable auto-RTS for the * break duration and drive RTS manually so the break reaches the wire; -* restore auto-RTS when the break ends. +* restore auto-RTS when the break ends. For an active-low RTS, +* IRDA.RTSINVERT already inverts the RTS_ output stage, so break_state +* is driven as it is. */ if (break_state) {if (!(port->rs485.flags &SER_RS485_ENABLED ))
@@ -1429,7 +1440,8 @@ static int max310x_gpio_set_config(struc#endif static const struct serial_rs485 max310x_rs485_supported = { - .flags =SER_RS485_ENABLED |SER_RS485_RTS_ON_SEND |SER_RS485_RX_DURING_TX , + .flags =SER_RS485_ENABLED |SER_RS485_RTS_ON_SEND | +SER_RS485_RTS_AFTER_SEND |SER_RS485_RX_DURING_TX , .delay_rts_before_send =1 , .delay_rts_after_send =1 , };
Greg Kroah-Hartman
maintainerPATCH 1721/2651 serial: max310x: drive RTS in software when hardware delays are too short
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tapio Reijonen <[email protected]>
[ Upstream commit 33632215e1bbc6109173b761e0c9bc5c4fcdbeee ]
The chip's auto-RTS path can express at most 15 bit-times of RTS setup and hold delay - a fraction of a millisecond at typical baud rates - while the uapi expresses the delays in milliseconds up to the UART core's RS485_MAX_RTS_DELAY. Requests beyond the field were rejected with -ERANGE, which makes the core silently wipe port->rs485 and disable RS485; a device tree asking for a 20 ms setup delay ends up with no RS485 at all and an unusable bus.
Add a software-driven RTS path that takes over whenever the hardware cannot represent the requested timing, and clamp the delays to RS485_MAX_RTS_DELAY instead of rejecting them.
max310x_set_rts_ctl_params() picks the path: software if either delay exceeds what 15 bit-times encode at the current baud rate, or if the requested RTS polarity combination cannot be produced by the auto-RTS engine; hardware otherwise, as before.
On the software path the RTS envelope is driven by a single hrtimer, re-used for the before- and after-send phases (tracked in tx_state), plus a single rts_work that toggles RTS. start_tx() begins the envelope; rts_work asserts RTS and only then arms the before-send timer, so data is never shifted before RTS is on the wire. The timer expiry kicks tx_work; once the chip FIFO drains, the same timer is re-armed for one character (the byte still in the shift register) plus the after-send delay, after which rts_work releases RTS. One timer and one work keep the phases mutually exclusive and the RTS toggles ordered. A start_tx() landing while the envelope is already in its send phase only pumps the new data: rewinding it to the before-send phase would insert a spurious setup delay mid-stream.
Teardown is interlocked: shutdown() and an RS485-disabling TIOCSRS485 set tx_teardown under port->lock before cancelling the timer and works, and start_tx() checks it on entry and again after the hrtimer_try_to_cancel(-1) path retakes the dropped lock - otherwise a write racing the teardown could re-arm the timer or queue rts_work against a port being shut down, leaving the transceiver driving the bus after close. The rs485-disable path additionally kicks tx_work afterwards, since a racing write may have queued data with no envelope left to pump it, and shutdown() now also cancels tx_work, which was previously cancelled only in remove(). The interlock also fences the adoption path below, so a reconfigure racing a teardown cannot re-enable the cancelled timer, and an RS485 disable flushes a queued rts_work before the pin is settled: one already past its tx_state read would re-assert RTS after the settle.
set_rts_ctl_params() publishes sw_rts_during_tx with a single store and settles the RTS idle level only while tx_state is off, because serial_core calls set_termios() without port->lock and rs485_config() schedules a reconfigure on every TIOCSRS485 - either could otherwise release the transceiver mid-envelope. The settle also re-checks tx_state after its write and requeues rts_work if an envelope started
meanwhile: the state read and the register write are not atomic, and rts_work re-derives the level from tx_state, so this converges without locking. shutdown() gates first - the
interlock is set and the interrupts are masked before any wait, so nothing can start a new envelope or requeue tx_work behind the cancels
- then honours a running after-send hold, bounded by the after-send delay plus two character times (the transmitter is already stopped by this point), and cancels the timer and works unconditionally: a TIOCSRS485 can clear sw_rts_during_tx while an envelope is still in flight, and neither may outlive the port. A hold that did not complete within the bound is settled by the final release below regardless. break_ctl() on the software path applies the
configured RTS polarity itself.
A reconfigure can also move the port off the hardware path while the chip's auto-RTS still owns a transmission in flight - a termios change or TIOCSRS485 pushing a delay above what the hardware can time at the new rate. Such transfers are invisible to tx_state, so the idle settle would release RTS and the MODE1 write would disable auto-RTS mid-transfer, shifting the rest of the data out with the transceiver released and no error reported anywhere. Adopt the transfer instead when the chip TX FIFO or the xmit buffer is not empty: enter MAX310X_TX_SEND and drive RTS manually before auto-RTS is disabled, so the pin is never released across the handover, and the normal drain path arms the after-send hold - or the adoption arms it directly if the FIFO drained while this raced the TX-empty worker. A transfer whose last character has already left the FIFO for the transmit shift register is still invisible and keeps the old behavior: at most one character of early release.
The reverse move strands state instead: a reconfigure onto the hardware path mid-envelope left tx_state set, because nothing reset it in that direction and the TX-empty hold arming only ran while the software path was selected. A later reconfigure back off the hardware path then trusted the stale tx_state, skipped both the adoption and the idle settle, and disabled auto-RTS with the RTS register released
- the rest of the transfer in flight shifted out with the transceiver off, again with no error reported (hit twice in 79 in-flight reconfigures under a multi-process stress test). The TX-empty unwind now runs regardless of the selected path - it is a no-op outside an envelope - and the reconfigure asserts RTS for any transfer it believes exists, stale or live, before auto-RTS is disabled. The hold is armed only once no transmittable data remains, so that assert cannot cut a burst short when it lands in a FIFO refill window; output that is stopped still releases through the hold.
rts_work also derives the level from tx_break: a break can begin while the previous envelope's after-send hold is still armed - TIOCSBRK waits for the output to drain, which lands the break exactly there - and the expiring hold would otherwise release the transceiver mid-break. With break ownership in the derivation the hold expiry becomes an idempotent re-assert, and break-off restores the idle state as it already does.
shutdown() gives its final RTS release one bit time, and at least 100 us, to reach the pin before powering the port down. The power-off stops the UART channel clock, and the RTS output stage is clocked by it: a release written immediately before the clock stops reaches the register but never moves the pin, which stays asserted until the next startup restarts the clock - a close racing the after-send hold expiry left the transceiver driving the bus, with the register reading released and the pin high. The measured propagation is about one tick of the 16x oversampling clock - below 50 us at 1200 baud - so one bit time keeps a 16x margin and scales with the clock the output stage runs on; the floor covers rates where a bit is shorter than the measured bound. Handing the pin to the chip's auto-RTS engine instead was tried and rejected on the wire:
the pin level is RTSINVERT xor the selected source, so for an active-low RTS every single-register step of that handover drives the pin to the asserted level, and the same clock stop can freeze it there.
--- drivers/tty/serial/max310x.c | 484 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 434 insertions(+), 50 deletions(-)
drivers/tty/serial/max310x.c +434 -50
@@ -15,6 +15,7 @@#include <linux/delay.h> #include <linux/device.h> #include <linux/gpio/driver.h> +#include <linux/hrtimer.h> #include <linux/i2c.h> #include <linux/module.h> #include <linux/property.h>
@@ -295,15 +296,29 @@ struct max310x_devtype {u8 power_bit;/* Bit for sleep or power-off mode (active high). */ }; +/* Software-timed RS485 RTS envelope phase */ +enum max310x_tx_state { +MAX310X_TX_OFF ,/* idle, RTS released */ +MAX310X_TX_WAIT_BEFORE_SEND ,/* RTS asserted, before-send delay */ +MAX310X_TX_SEND ,/* data in flight, awaiting TX-empty */ +MAX310X_TX_WAIT_AFTER_SEND ,/* data drained, after-send hold */ +}; +struct max310x_one {struct uart_port port;struct work_struct tx_work;struct work_struct md_work;struct work_struct rs_work; +struct work_struct rts_work; +struct hrtimer tx_delay_tmr;struct regmap *regmap;unsigned int char_time_us;unsigned int baud; +bool sw_rts_during_tx; +bool cancel_tx_delay_tmr; +bool tx_teardown;/* envelope being torn down */ bool tx_break;/* break_ctl() owns the transceiver */ +enum max310x_tx_state tx_state;u8 rx_buf[MAX310X_FIFO_SIZE ]; };
@@ -694,6 +709,38 @@ static void max310x_rts_ctl(struct uart_ rts_state ? MAX310X_LCR_RTS_BIT : 0); } +/* RTS level for the transmitting or the idle phase of an RS485 envelope */ +static bool max310x_rts_level (struct uart_port *port,bool active) +{ +return active ? (port->rs485.flags &SER_RS485_RTS_ON_SEND ) : + (port->rs485.flags &SER_RS485_RTS_AFTER_SEND ); +} + +/* +* Drive the RS485 RTS line to match the current tx_state and break +* ownership. This is the only place that touches RTS, and it reads the +* state rather than a fixed assert/deassert intent, so a newer assert is +* never clobbered by a stale release and an expiring after-send hold never +* releases a break in progress. It also arms the before-send timer once the +* RTS edge is on the wire, so data is never shifted before RTS is asserted. +*/ +static void max310x_rts_work_proc (struct work_struct *ws) +{ + struct max310x_one *one = container_of(ws, struct max310x_one, rts_work); +struct uart_port *port = &one->port; +bool rts_on =READ_ONCE (one->tx_state) !=MAX310X_TX_OFF || +READ_ONCE (one->tx_break); + +max310x_rts_ctl (port,max310x_rts_level (port, rts_on)); + +guard (spinlock_irqsave)(&port->lock); +if (READ_ONCE (one->tx_state) ==MAX310X_TX_WAIT_BEFORE_SEND && + !one->cancel_tx_delay_tmr && !hrtimer_active (&one->tx_delay_tmr)) +hrtimer_start (&one->tx_delay_tmr, +ms_to_ktime (port->rs485.delay_rts_before_send), +HRTIMER_MODE_REL ); +} +static void max310x_handle_rx (struct uart_port *port,unsigned int rxlen) {struct max310x_one *one =to_max310x_port (port);
@@ -790,6 +837,77 @@ static void max310x_handle_rx(struct uartty_flip_buffer_push (&port->state->port); } +static enum hrtimer_restart max310x_tmr_tx (struct hrtimer *timer) +{ + struct max310x_one *one = container_of(timer, struct max310x_one, + tx_delay_tmr); + +guard (spinlock_irqsave)(&one->port.lock); +if (!one->cancel_tx_delay_tmr) { +if (READ_ONCE (one->tx_state) ==MAX310X_TX_WAIT_AFTER_SEND ) { +/* After-send hold elapsed: drop RTS via the rts worker. */ +WRITE_ONCE (one->tx_state,MAX310X_TX_OFF ); +schedule_work (&one->rts_work); + }else { +WRITE_ONCE (one->tx_state,MAX310X_TX_SEND ); +schedule_work (&one->tx_work); + } + } + +return HRTIMER_NORESTART ; +} + +static void max310x_delayed_stop_tx (struct uart_port *port) +{ +struct max310x_one *one =to_max310x_port (port); +unsigned int txlvl; + +if (READ_ONCE (one->tx_state) ==MAX310X_TX_OFF ) +return ; + +/* +* Data still queued for transmission defers the hold: a refill is +* coming and the envelope is not over. Stopped output does not +* count - it drains nowhere, and the envelope must end. +*/ +if (!kfifo_is_empty (&port->state->port.xmit_fifo) && + !uart_tx_stopped (port)) +return ; + +/* +* The kfifo can be empty while the chip TX FIFO is still draining, so arm +* the after-send hold only once the chip FIFO is empty too - the TX-empty +* interrupt re-invokes us then. Otherwise the hold starts early and RTS +* drops mid-character, clipping the last byte(s). +*/ + txlvl =max310x_port_read (port,MAX310X_TXFIFOLVL_REG ); +if (txlvl) +return ; + +/* +* Runs from tx_work without port->lock, so re-check the state under it: +* shutdown() may have cancelled the envelope meanwhile. Only +* MAX310X_TX_SEND may arm the hold. +*/ +guard (spinlock_irqsave)(&one->port.lock); +if (one->cancel_tx_delay_tmr || +READ_ONCE (one->tx_state) !=MAX310X_TX_SEND ) +return ; + +if (!hrtimer_active (&one->tx_delay_tmr)) { +/* +* Add one character for the byte still in the shift register - +* TX-empty fires as it enters, not as it leaves. +*/ +ktime_t delay =us_to_ktime (one->char_time_us + + port->rs485.delay_rts_after_send * +USEC_PER_MSEC ); + +WRITE_ONCE (one->tx_state,MAX310X_TX_WAIT_AFTER_SEND ); +hrtimer_start (&one->tx_delay_tmr, delay,HRTIMER_MODE_REL ); + } +} +static void max310x_handle_tx (struct uart_port *port) {struct tty_port *tport = &port->state->port;
@@ -801,8 +919,16 @@ static void max310x_handle_tx(struct uarreturn ; } -if (kfifo_is_empty (&tport->xmit_fifo) ||uart_tx_stopped (port)) +if (kfifo_is_empty (&tport->xmit_fifo) ||uart_tx_stopped (port)) { +/* +* Unwind the envelope even if a reconfigure has moved the +* port to the hardware path mid-envelope: a stranded +* tx_state would make a later reconfigure believe a +* software envelope still owns RTS. +*/ +max310x_delayed_stop_tx (port);return ; + }/* * It's a circ buffer -- wrap around.
@@ -827,11 +953,64 @@ static void max310x_handle_tx(struct uaruart_write_wakeup (port); } +/* +* Begin a software-timed RTS envelope: set the before-send phase and queue the +* rts worker to assert RTS. tx_state is set synchronously here (start_tx() holds +* port.lock) so close()/shutdown can see an envelope is in flight; rts_work then +* asserts RTS and arms the before-send timer (see there). +*/ +static void max310x_delayed_start_tx (struct uart_port *port) +{ +struct max310x_one *one =to_max310x_port (port); + +WRITE_ONCE (one->tx_state,MAX310X_TX_WAIT_BEFORE_SEND ); + one->cancel_tx_delay_tmr = false; +schedule_work (&one->rts_work); +} + +/* called with port.lock taken and irqs off */ static void max310x_start_tx (struct uart_port *port) {struct max310x_one *one =to_max310x_port (port); -schedule_work (&one->tx_work); +/* A teardown is in progress; nothing may start an envelope or TX. */ +if (one->tx_teardown) +return ; + +if (READ_ONCE (one->sw_rts_during_tx)) { +/* +* The before- and after-send phases share one delay timer. If an +* after-send release is pending, cancel it before starting a new +* TX so the just-asserted RTS is not yanked; re-arming the timer +* for the before-send phase then supersedes the release. +*/ +int res =0 ; + +if (READ_ONCE (one->tx_state) ==MAX310X_TX_WAIT_AFTER_SEND ) + res =hrtimer_try_to_cancel (&one->tx_delay_tmr); +if (unlikely (res ==-1 )) { + one->cancel_tx_delay_tmr = true; +uart_port_unlock (port); +hrtimer_cancel (&one->tx_delay_tmr); +uart_port_lock (port); +/* +* The lock was dropped: a teardown may have run to +* completion meanwhile. Re-check before starting. +*/ +if (one->tx_teardown) +return ; + } + +/* Already sending: pump the new data, don't rewind. */ +if (READ_ONCE (one->tx_state) ==MAX310X_TX_SEND ) { +schedule_work (&one->tx_work); +return ; + } + +max310x_delayed_start_tx (port); + }else { +schedule_work (&one->tx_work); + } }static irqreturn_t max310x_port_irq (struct max310x_port *s,int portno)
@@ -944,10 +1123,39 @@ static void max310x_set_mctrl(struct uar }/* -* Program the chip's RS485 RTS timing. The HDPIXDELAY setup and hold fields -* count bit-times, four bits per direction, while the uapi expresses the -* delays in milliseconds: convert at the current baud rate, rounding up, and -* cap at the field maximum. +* A reconfigure can move the port off the hardware RTS path while the chip's +* auto-RTS still owns a transmission in flight; tx_state does not track +* those. Take such a transfer over before auto-RTS is disabled: enter +* MAX310X_TX_SEND, so the caller keeps RTS driven across the handover and +* the normal drain path arms the after-send hold. Returns true when a +* transmission owns RTS - adopted here or started concurrently - and false +* when the line is really idle. +*/ +static bool max310x_adopt_hw_tx (struct max310x_one *one) +{ +struct uart_port *port = &one->port; + +if (!max310x_port_read (port,MAX310X_TXFIFOLVL_REG ) && +kfifo_is_empty (&port->state->port.xmit_fifo)) +return false; + + scoped_guard(spinlock_irqsave, &port->lock) { +if (one->tx_teardown) +return false; +if (READ_ONCE (one->tx_state) !=MAX310X_TX_OFF ) +return true; +WRITE_ONCE (one->tx_state,MAX310X_TX_SEND ); + one->cancel_tx_delay_tmr = false; + } + +return true; +} + +/* +* Pick hardware or software RTS timing for the current port. The chip can +* deliver up to 15 bit-times of setup/hold delay via HDPIXDELAY; anything +* longer (or any RTS polarity the chip cannot produce automatically) must +* be driven by software via tx_delay_tmr and rts_work. */ static void max310x_set_rts_ctl_params (struct max310x_one *one) {
@@ -955,25 +1163,35 @@ static void max310x_set_rts_ctl_params(sstruct uart_port *port = &one->port;unsigned int setup =0 , hold =0 ;u8 mode1 =0 , irda =0 ; +bool sw_rts = false; -if (port->rs485.flags &SER_RS485_ENABLED ) { -/* Convert milliseconds to bit-times, rounding up. */ - setup =DIV_ROUND_UP (one->baud * port->rs485.delay_rts_before_send, -MSEC_PER_SEC ); - hold =DIV_ROUND_UP (one->baud * port->rs485.delay_rts_after_send, -MSEC_PER_SEC ); - setup =min (setup, max_bit_dly); - hold =min (hold, max_bit_dly); +if (!(port->rs485.flags &SER_RS485_ENABLED )) + goto out; - mode1 =MAX310X_MODE1_TRNSCVCTRL_BIT ; -/* -* The auto-RTS engine asserts RTS high on send; for an -* active-low RTS let IRDA.RTSINVERT invert the output stage. -*/ -if (!(port->rs485.flags &SER_RS485_RTS_ON_SEND )) - irda =MAX310X_IRDA_RTSINVERT_BIT ; +/* Convert milliseconds to bit-times, rounding up. */ + setup =DIV_ROUND_UP (one->baud * port->rs485.delay_rts_before_send, +MSEC_PER_SEC ); + hold =DIV_ROUND_UP (one->baud * port->rs485.delay_rts_after_send, +MSEC_PER_SEC ); + +/* +* Compare in bit-times: a delay of exactly max_bit_dly bit-times +* must stay on the hardware path, which a nanosecond ceiling +* computed from the truncated per-bit time would reject. Without +* a baud rate the conversion is meaningless - use software. +*/ +if (!one->baud || setup > max_bit_dly || hold > max_bit_dly || + !!(port->rs485.flags &SER_RS485_RTS_ON_SEND ) == + !!(port->rs485.flags &SER_RS485_RTS_AFTER_SEND )) { + sw_rts = true; + setup =0 ; + hold =0 ; } +out: +/* Assign once; a transient false would be seen by other readers. */ +WRITE_ONCE (one->sw_rts_during_tx, sw_rts); +max310x_port_write (port,MAX310X_HDPIXDELAY_REG ,MAX310X_HDPIXDELAY_SETUP (setup) |MAX310X_HDPIXDELAY_HOLD (hold));
@@ -981,12 +1199,66 @@ static void max310x_set_rts_ctl_params(s/* * A break owns the transceiver: break_ctl() disabled auto-RTS and * drives RTS manually, and restores it from the current -* configuration when the break ends. Touching MODE1 here would +* configuration when the break ends. Touching them here would * release the transceiver mid-break. */ if (one->tx_break)return ; +if (port->rs485.flags &SER_RS485_ENABLED ) { +if (sw_rts) { +/* +* Only settle RTS at idle when no transmission owns it. +* A reconfigure while one is in flight - rs_work runs +* on every TIOCSRS485 - would otherwise release the +* transceiver mid-character. A transfer the hardware +* path owns is invisible to tx_state - adopt it +* instead of settling. The reverse strand also +* exists: an envelope the hardware path inherited +* mid-envelope leaves tx_state set with nothing +* driving the pin. +*/ +if (READ_ONCE (one->tx_state) !=MAX310X_TX_OFF || +max310x_adopt_hw_tx (one)) { +/* +* The transfer may be running under auto-RTS: +* assert before auto-RTS is disabled below so +* the pin is never released under it, and arm +* the after-send hold - with the chip FIFO +* already drained no TX-empty interrupt +* arrives to arm it. +*/ +max310x_rts_ctl (port, +max310x_rts_level (port, true)); +max310x_delayed_stop_tx (port); + }else { +max310x_rts_ctl (port, +max310x_rts_level (port, false)); +/* +* serial_core calls set_termios() without +* port->lock, so an envelope may have started +* while the idle level was written and the +* settle can land after its RTS assert. +* rts_work re-derives the level from +* tx_state; requeue it to converge. +*/ +if (READ_ONCE (one->tx_state) !=MAX310X_TX_OFF ) +schedule_work (&one->rts_work); + } + }else { + mode1 =MAX310X_MODE1_TRNSCVCTRL_BIT ; +/* +* The auto-RTS engine asserts RTS high on send; for an +* active-low RTS let IRDA.RTSINVERT invert the output +* stage. +*/ +if (!(port->rs485.flags &SER_RS485_RTS_ON_SEND )) + irda =MAX310X_IRDA_RTSINVERT_BIT ; + } + }else { +max310x_rts_ctl (port,0 ); + } +max310x_port_update (port,MAX310X_MODE1_REG ,MAX310X_MODE1_TRNSCVCTRL_BIT , mode1); max310x_port_update(port, MAX310X_IRDA_REG,
@@ -1014,12 +1286,27 @@ static void max310x_break_ctl(struct uarif (break_state) {if (!(port->rs485.flags &SER_RS485_ENABLED ))return ; -max310x_port_update (port,MAX310X_MODE1_REG , -MAX310X_MODE1_TRNSCVCTRL_BIT ,0 ); +if (READ_ONCE (one->sw_rts_during_tx)) { +max310x_rts_ctl (port,max310x_rts_level (port,1 )); + }else { +max310x_port_update (port,MAX310X_MODE1_REG , +MAX310X_MODE1_TRNSCVCTRL_BIT ,0 ); +max310x_rts_ctl (port,1 ); + } }else { +/* +* Reapply the current configuration: a reconfigure that +* arrived during the break was deferred by the tx_break +* guard, and RS485 may have been disabled outright - the +* manually driven RTS must not leak past the break. On the +* software path the helper also settles the idle level; on +* the hardware path release the manual RTS - auto-RTS owns +* the pin again. +*/ max310x_set_rts_ctl_params (one); +if (!READ_ONCE (one->sw_rts_during_tx)) +max310x_rts_ctl (port,0 ); } -max310x_rts_ctl (port, break_state); } static void max310x_set_termios(struct uart_port *port,
@@ -1061,9 +1348,10 @@ static void max310x_set_termios(struct u lcr |=MAX310X_LCR_STOPLEN_BIT ;/* 2 stops */ /* -* Update LCR register. Leave the TX break bit alone: it is driven by -* break_ctl(), and a whole-register write here would end a break in -* progress. +* Update LCR register. Leave the TX break and RTS bits alone: they are +* driven by break_ctl() and by the software-timed RS485 RTS, and a +* whole-register write here would end a break in progress or release +* the transceiver mid-character. */ max310x_port_update (port,MAX310X_LCR_REG ,MAX310X_LCR_TERMIOS_MASK , lcr);
@@ -1141,7 +1429,9 @@ static void max310x_set_termios(struct u/* * Cache the new baud rate and the time it takes to clock out one * character before reprogramming the RS485 RTS delays: the -* millisecond-to-bit-time conversion divides by the baud rate. +* millisecond-to-bit-time conversion divides by the baud rate, and +* taking over an in-flight transfer arms the after-send hold from +* the character time. */ to_max310x_port (port)->baud = baud; to_max310x_port(port)->char_time_us =
@@ -1161,6 +1451,10 @@ static void max310x_rs_proc(struct work_*/ guard (mutex)(&one->port.state->port.mutex); +/* Flush an rts_work that read tx_state before the disable cleared it. */ +if (!(one->port.rs485.flags &SER_RS485_ENABLED )) +cancel_work_sync (&one->rts_work); +max310x_set_rts_ctl_params (one); if (one->port.rs485.flags & SER_RS485_ENABLED &&
@@ -1171,14 +1465,37 @@ static void max310x_rs_proc(struct work_ MAX310X_MODE2_ECHOSUPR_BIT, mode2); } +/* called with port.lock taken and irqs off */ static int max310x_rs485_config (struct uart_port *port,struct ktermios *termios,struct serial_rs485 *rs485) {struct max310x_one *one =to_max310x_port (port); -if ((rs485->delay_rts_before_send >0x0f ) || - (rs485->delay_rts_after_send >0x0f )) -return -ERANGE ; + rs485->delay_rts_before_send =min (rs485->delay_rts_before_send,100U ); + rs485->delay_rts_after_send =min (rs485->delay_rts_after_send,100U ); + +/* +* Make sure no SW-timed RTS toggle survives an RS485 disable, even +* if the delay timer happens to be running right now. +*/ +if (!(rs485->flags &SER_RS485_ENABLED )) { + one->tx_teardown = true; + one->cancel_tx_delay_tmr = true; +if (hrtimer_try_to_cancel (&one->tx_delay_tmr) ==-1 ) { +uart_port_unlock (port); +hrtimer_cancel (&one->tx_delay_tmr); +uart_port_lock (port); + } +WRITE_ONCE (one->tx_state,MAX310X_TX_OFF ); + one->tx_teardown = false; +/* +* The port stays alive, and a write that raced the teardown +* may have left data queued with no envelope left to pump it. +* Kick tx_work; RS485 is disabled, so the plain path is right. +*/ +if (!kfifo_is_empty (&port->state->port.xmit_fifo)) +schedule_work (&one->tx_work); + } port->rs485 = *rs485;
@@ -1213,7 +1530,15 @@ static int max310x_startup(struct uart_pmax310x_port_update (port,MAX310X_MODE2_REG ,MAX310X_MODE2_FIFORST_BIT ,0 ); -/* Configure the RS485 RTS timing and the RS485/RS232 mode bits. */ + one->tx_teardown = false; + +/* +* Configure the RS485 RTS timing (HW auto-RTS vs software-driven) and +* the RS485/RS232 mode bits. Don't hardcode HW auto-RTS here - let +* max310x_set_rts_ctl_params() pick HW or SW per the configured +* delays, otherwise the chip's auto-RTS would override the software +* RTS hold and the after-send delay is lost. +*/ max310x_set_rts_ctl_params (one); if (port->rs485.flags & SER_RS485_ENABLED &&
@@ -1244,7 +1569,15 @@ static void max310x_shutdown(struct uart {struct max310x_one *one =to_max310x_port (port); -/* Disable all interrupts */ +/* +* Gate new transmissions and interrupts first: a concurrent +* start_tx() either sees the interlock or happens-before it, and +* nothing below may start a new envelope. The timer and the works +* stay live for now - they are what completes a running after-send +* hold. +*/ +scoped_guard (spinlock_irqsave, &port->lock) + one->tx_teardown = true;max310x_port_write (port,MAX310X_IRQEN_REG ,0 );/*
@@ -1254,25 +1587,69 @@ static void max310x_shutdown(struct uartmax310x_port_update (port,MAX310X_MODE1_REG ,MAX310X_MODE1_TXDIS_BIT ,MAX310X_MODE1_TXDIS_BIT ); +if (READ_ONCE (one->sw_rts_during_tx)) { +/* +* Honour a running after-send hold before the port is +* powered down. The bound covers the final character - +* tx_empty() cannot see the transmit shift register - plus +* the hold itself. Data beyond that is abandoned: it is +* only still queued when the tty layer was told not to +* wait, and the release below drives RTS to idle +* regardless. +*/ +unsigned int tries = port->rs485.delay_rts_after_send + +2 *DIV_ROUND_UP (one->char_time_us,USEC_PER_MSEC ); + +while (READ_ONCE (one->tx_state) !=MAX310X_TX_OFF && tries-- >0 ) +fsleep (USEC_PER_MSEC ); + }else { +/* +* Let the character in flight finish (the chip has no +* transmitter-idle status), then empty the FIFO: auto-RTS +* releases only once the transmitter is empty, and the +* power-off below would freeze an asserted pin until the +* next open. The hold is at most 15 bit-times. +*/ +fsleep (one->char_time_us); +max310x_port_update (port,MAX310X_MODE2_REG , +MAX310X_MODE2_FIFORST_BIT , +MAX310X_MODE2_FIFORST_BIT ); +max310x_port_update (port,MAX310X_MODE2_REG , +MAX310X_MODE2_FIFORST_BIT ,0 ); +if (port->rs485.flags &SER_RS485_ENABLED && one->baud) { +unsigned int hold =DIV_ROUND_UP (one->baud * + port->rs485.delay_rts_after_send, +MSEC_PER_SEC ); + +fsleep (max (DIV_ROUND_UP ((hold +1 ) *USEC_PER_SEC , + one->baud),100U )); + } + } +/* -* Let the character in flight finish (the chip has no -* transmitter-idle status), then empty the FIFO: auto-RTS releases -* only once the transmitter is empty, and the power-off below -* would freeze an asserted pin until the next open. +* The wind-down is over: cancel unconditionally. The SW/HW decision +* is recomputed on every reconfigure, so a TIOCSRS485 can clear +* sw_rts_during_tx while an envelope is still in flight, and +* neither the timer nor the works may outlive the port. */ -fsleep (one->char_time_us); -max310x_port_update (port,MAX310X_MODE2_REG , -MAX310X_MODE2_FIFORST_BIT , -MAX310X_MODE2_FIFORST_BIT ); -max310x_port_update (port,MAX310X_MODE2_REG , -MAX310X_MODE2_FIFORST_BIT ,0 ); -if (port->rs485.flags &SER_RS485_ENABLED && one->baud) { -unsigned int hold =DIV_ROUND_UP (one->baud * - port->rs485.delay_rts_after_send, -MSEC_PER_SEC ); +scoped_guard (spinlock_irqsave, &port->lock) + one->cancel_tx_delay_tmr = true; +cancel_work_sync (&one->tx_work); +hrtimer_cancel (&one->tx_delay_tmr); +cancel_work_sync (&one->rts_work); +WRITE_ONCE (one->tx_state,MAX310X_TX_OFF ); -fsleep (max (DIV_ROUND_UP ((hold +1 ) *USEC_PER_SEC , - one->baud),100U )); +if (READ_ONCE (one->sw_rts_during_tx)) { +max310x_rts_ctl (port,max310x_rts_level (port, false)); +/* +* The power-off below stops the UART clock that moves the +* RTS pin: released too late, the write reaches the register +* but the pin stays at its old level until the next startup +* restarts the clock. Give the release one bit time (at +* least 100 us) to reach the pin - the measured propagation +* is about one tick of the 16x oversampling clock. +*/ +fsleep (max (one->char_time_us /10 ,100U )); }max310x_power (port,0 );
@@ -1568,6 +1945,11 @@ static int max310x_probe(struct device *INIT_WORK (&s->p[i].md_work, max310x_md_proc);/* Initialize queue for changing RS485 mode */ INIT_WORK (&s->p[i].rs_work, max310x_rs_proc); +/* Initialize queue for software-driven RTS toggling */ +INIT_WORK (&s->p[i].rts_work, max310x_rts_work_proc); +hrtimer_setup (&s->p[i].tx_delay_tmr, max310x_tmr_tx, +CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); + s->p[i].tx_state =MAX310X_TX_OFF ; }#ifdef CONFIG_GPIOLIB
@@ -1679,6 +2061,8 @@ static void max310x_remove(struct deviceint i;for (i =0 ; i < s->devtype->nr; i++) { +hrtimer_cancel (&s->p[i].tx_delay_tmr); +cancel_work_sync (&s->p[i].rts_work);cancel_work_sync (&s->p[i].tx_work);cancel_work_sync (&s->p[i].md_work);cancel_work_sync (&s->p[i].rs_work);
Greg Kroah-Hartman
maintainerPATCH 1722/2651 serial: max310x: dont transmit while an RS485 reconfigure is pending
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tapio Reijonen <[email protected]>
[ Upstream commit ae588038e31c9dbd6836cb12bbdd82af0271c373 ]
TIOCSRS485 applies its register changes asynchronously: rs485_config() stores the new configuration and schedules rs_work, which programs HDPIXDELAY, MODE1.TRNSCVCTRL and the RTS path. A write() issued right after the ioctl therefore transmits against the old, half-switched state. On a single core the ordering is even deterministic: start_tx() picks the stale path first, then rs_work reprograms the chip, then tx_work pumps the data - with the transceiver already released. A TIOCSRS485 switching from the hardware to the software RTS path followed immediately by a write puts the whole transfer on the wire with the transceiver disabled: nothing reaches the bus and no error is reported anywhere. The inverse direction is as old as the asynchronous reconfigure itself: enabling RS485 and writing immediately shifts the first bytes out before rs_work has enabled the chip's auto-RTS.
Defer instead: rs485_config() marks the reconfigure pending under port->lock, start_tx() leaves the data in the kfifo while the mark is set, and rs_work restarts the transmission itself once the new configuration is fully applied. The rs485-disable path's direct tx_work kick is replaced by the same mechanism, which also orders that flush after the reconfigure instead of before it.
The restart kick also checks port->x_char: uart_send_xchar() reaches start_tx() too, and a lone x_char deferred by the pending gate leaves the kfifo empty, so the kick would otherwise skip it and nothing else would ever send it - an idle chip FIFO raises no TXEMPTY interrupt. And start_tx() re-checks the pending mark after the hrtimer_try_to_cancel(-1) path retakes the dropped lock, mirroring the tx_teardown re-check there: a TIOCSRS485 posted inside that window would otherwise let the transmission proceed on the stale path.
rs_work takes port->lock for that restart through uart_port_lock_irqsave(): start_tx() may drop and retake the lock through the uart_port API on its hrtimer_try_to_cancel(-1) path, and a raw spinlock guard around the call would unbalance the nbcon console handling underneath.
The restart also rewinds a send state adopted for the deferred write
itself: set_rts_ctl_params() cannot tell data the pending gate deferred apart from an in-flight transfer's refill by the xmit buffer alone, and a deferred write pumped in the adopted send phase would skip the configured before-send delay. With the chip FIFO empty the adopted state can only be the deferred write: rewind it and let the restart run the full envelope.
The chip-FIFO check for that rewind is deliberately lock-free, so a TX-empty refill can land between the read and the lock and the rewind can hit a live envelope. The consequence is bounded: the rewind runs under port->lock in a state the RTS worker reads as asserted, so the envelope pauses one before-send delay with the transceiver held - the same pause the unconditional rewind produced before patch 8's guard.
--- drivers/tty/serial/max310x.c | 51 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 42 insertions(+), 9 deletions(-)
drivers/tty/serial/max310x.c +42 -9
@@ -317,6 +317,7 @@ struct max310x_one {bool sw_rts_during_tx;bool cancel_tx_delay_tmr;bool tx_teardown;/* envelope being torn down */ +bool rs485_pending;/* rs_work not yet applied */ bool tx_break;/* break_ctl() owns the transceiver */ enum max310x_tx_state tx_state;
@@ -977,6 +978,16 @@ static void max310x_start_tx(struct uartif (one->tx_teardown)return ; +/* +* An RS485 reconfigure is scheduled but not applied yet: transmitting +* now would use the old path against half-programmed registers - a +* TIOCSRS485 switching paths followed immediately by a write puts the +* data on the wire with the transceiver released. Leave the data in +* the kfifo; rs_work restarts TX once the configuration is applied. +*/ +if (one->rs485_pending) +return ; +if (READ_ONCE (one->sw_rts_during_tx)) {/* * The before- and after-send phases share one delay timer. If an
@@ -995,9 +1006,10 @@ static void max310x_start_tx(struct uartuart_port_lock (port);/* * The lock was dropped: a teardown may have run to -* completion meanwhile. Re-check before starting. +* completion or a reconfigure may have been posted +* meanwhile. Re-check before starting. */ -if (one->tx_teardown) +if (one->tx_teardown || one->rs485_pending)return ; }
@@ -1443,6 +1455,8 @@ static void max310x_rs_proc(struct work_ { struct max310x_one *one = container_of(ws, struct max310x_one, rs_work);unsigned int mode2 =0 ; +unsigned long flags; +bool chip_tx_empty;/* * Serialize against break_ctl() and set_termios(), which run under
@@ -1463,6 +1477,31 @@ static void max310x_rs_proc(struct work_max310x_port_update (&one->port,MAX310X_MODE2_REG ,MAX310X_MODE2_ECHOSUPR_BIT , mode2); + +/* +* The configuration is applied: release any TX that start_tx() +* deferred while the reconfigure was pending, now on the right +* path. start_tx() can drop and retake the lock through the +* uart_port API - a raw spinlock guard here would unbalance it. +*/ + chip_tx_empty = !max310x_port_read (&one->port, +MAX310X_TXFIFOLVL_REG ); + +uart_port_lock_irqsave (&one->port, &flags); + one->rs485_pending = false; +if (one->port.x_char || + !kfifo_is_empty (&one->port.state->port.xmit_fifo)) { +/* +* A send state adopted without chip data is the deferred +* write itself: restart it as a fresh envelope so the +* before-send delay is honoured. +*/ +if (chip_tx_empty && +READ_ONCE (one->tx_state) ==MAX310X_TX_SEND ) +WRITE_ONCE (one->tx_state,MAX310X_TX_OFF ); +max310x_start_tx (&one->port); + } +uart_port_unlock_irqrestore (&one->port, flags); }/* called with port.lock taken and irqs off */
@@ -1488,17 +1527,11 @@ static int max310x_rs485_config(struct u }WRITE_ONCE (one->tx_state,MAX310X_TX_OFF ); one->tx_teardown = false; -/* -* The port stays alive, and a write that raced the teardown -* may have left data queued with no envelope left to pump it. -* Kick tx_work; RS485 is disabled, so the plain path is right. -*/ -if (!kfifo_is_empty (&port->state->port.xmit_fifo)) -schedule_work (&one->tx_work); } port->rs485 = *rs485; + one->rs485_pending = true;schedule_work (&one->rs_work);return 0 ;
Greg Kroah-Hartman
maintainerPATCH 1723/2651 fs/ntfs3: fix ntfs_fnd leak when compare function is missing
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: liyouhong <[email protected]>
[ Upstream commit 86ba91170c03e02eee767d82a9a7f2048e51a5e4 ]
indx_insert_entry(), indx_delete_entry() and indx_update_dup() take a finder via fnd_get() before calling get_cmp_func(). If no compare function is available they return -EINVAL and never release the finder.
Jump to the existing out path so fnd_put() still runs.
--- fs/ntfs3/index.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
fs/ntfs3/index.c +6 -3
@@ -2058,7 +2058,8 @@ int indx_insert_entry(struct ntfs_index *indx, struct ntfs_inode *ni, cmp =get_cmp_func (root);if (unlikely (!cmp)) {WARN_ON_ONCE (1 ); -return -EINVAL ; + err = -EINVAL ; + goto out; }if (fnd_is_empty (fnd)) {
@@ -2415,7 +2416,8 @@ int indx_delete_entry(struct ntfs_index *indx, struct ntfs_inode *ni, cmp =get_cmp_func (root);if (unlikely (!cmp)) {WARN_ON_ONCE (1 ); -return -EINVAL ; + err = -EINVAL ; + goto out; }/* Locate the entry to remove. */
@@ -2806,7 +2808,8 @@ int indx_update_dup(struct ntfs_inode *ni, struct ntfs_sb_info *sbi, cmp =get_cmp_func (root);if (unlikely (!cmp)) {WARN_ON_ONCE (1 ); -return -EINVAL ; + err = -EINVAL ; + goto out; }/* Find entry in directory. */
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1724/2651 fs/ntfs3: do not mark frame pages uptodate on read error
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weiming Shi <[email protected]>
[ Upstream commit 80218408836fa6fc91a9c26a9c014f81abf9e41f ]
ni_read_frame() ends with a loop that marks every page of a compressed frame uptodate regardless of whether the read succeeded:
out:
for (i = 0; i < pages_per_frame; i++) {
pg = pages[i];
SetPageUptodate(pg);
}Non-critical frame pages come from __filemap_get_folio(FGP_CREAT) and are not zeroed. On an error path that reaches out: before frame_mem is written, these pages keep uninitialized page-allocator contents but are still marked uptodate. A later read() is then served from the page cache and returns that stale kernel memory to user space.
For an unprivileged user mounting a crafted NTFS image this is a repeatable kernel memory disclosure.
Mark the pages uptodate only on success; on error leave them !uptodate so the read path re-reads them or reports the error.
--- fs/ntfs3/frecord.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
fs/ntfs3/frecord.c +4 -6
@@ -2290,7 +2290,6 @@ int ni_read_frame(struct ntfs_inode *ni, u64 frame_vbo, struct page **pages,u64 vbo_disk;size_t unc_size =0 ;u32 frame_size, i, ondisk_size; -struct page *pg;struct ATTRIB *attr;CLST frame, clst_data;
@@ -2522,11 +2521,10 @@ int ni_read_frame(struct ntfs_inode *ni, u64 frame_vbo, struct page **pages,#endif vunmap (frame_mem); out: -for (i =0 ; i < pages_per_frame; i++) { - pg = pages[i]; -if (err) -clear_highpage (pg); -SetPageUptodate (pg); +if (!err) { +for (i =0 ; i < pages_per_frame; i++) { +SetPageUptodate (pages[i]); + } }return err;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1725/2651 net: alacritech: fix dma_free_coherent() in error path
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Fourier <[email protected]>
[ Upstream commit 05b5019b01fb9443b09ae4ed34af1135a80a84c8 ]
In slic_init_stat_queue(), a series of coherent buffers is allocated with the length size. The size is then stored in stq->mem_size for normal deallocation. However, in the error path, stq->mem_size is also used but is not initialized. This error may leave the freed buffers mapped, leaking a resource and allowing the device to access freed memory.
Change the length in error path to size.
--- drivers/net/ethernet/alacritech/slicoss.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/alacritech/slicoss.c +1 -1
@@ -813,7 +813,7 @@ static int slic_init_stat_queue(struct slic_device *sdev) free_descs:while (i--) { -dma_free_coherent (&sdev->pdev->dev, stq->mem_size, +dma_free_coherent (&sdev->pdev->dev, size, stq->descs[i] - stq->addr_offset[i], stq->paddr[i] - stq->addr_offset[i]); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1726/2651 comedi: comedi_parport: validate the IRQ supplied by userspace
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yogesh Gaur <[email protected]>
[ Upstream commit 790ea6844593bcd03b0379986fc821d8c511746e ]
comedi boards are configured through the COMEDI_DEVCONFIG ioctl, so it->options[1] is a number chosen by userspace. comedi_parport passes it to request_irq() without checking it first, which lets an interrupt owned by another irqdomain -- a PCI device's IO-APIC GSI, for instance -- be claimed for this board. When the owner of that interrupt is later released the descriptor is freed while this driver's handler is still installed on it.
A parallel port asserts a legacy ISA interrupt, so the ISA range is the right bound; it is also sufficient, because mp_chip_data->isa_irq is set only by alloc_isa_irq_from_domain() and mp_unmap_irq() returns early when it is set.
syzbot hit this one:
remove_proc_entry: removing non-empty directory 'irq/20', leaking at least 'comedi_parport' WARNING: fs/proc/generic.c:747 at remove_proc_entry+0x4e7/0x610 fs/proc/generic.c:747 Call Trace: <TASK> unregister_irq_proc+0x206/0x2a0 kernel/irq/proc.c:406 free_desc+0x89/0x330 kernel/irq/irqdesc.c:482 irq_free_descs+0x84/0xc0 kernel/irq/irqdesc.c:865 irq_domain_free_irqs+0x46a/0x5c0 kernel/irq/irqdomain.c:1917 mp_unmap_irq+0xf8/0x130 arch/x86/kernel/apic/io_apic.c:1061 acpi_unregister_gsi_ioapic+0x40/0x60 arch/x86/kernel/acpi/boot.c:722 acpi_pci_irq_disable+0x275/0x360 drivers/acpi/pci_irq.c:517 pci_disable_device+0x130/0x270 drivers/pci/pci.c:2206 pci_device_remove+0xb2/0x1d0 drivers/pci/pci-driver.c:512 device_release_driver_internal+0x44e/0x620 drivers/base/dd.c:1372 unbind_store+0xf8/0x110 drivers/base/bus.c:244 </TASK>
The leaked /proc entry the warning names is the mild part. mp_chip_data->count tracks GSI mappings rather than request_irq() users, and __setup_irq() takes no reference on the descriptor, so the irq_desc is freed with the comedi irqaction still attached to it.
Bound the value before requesting it, as das16m1.c already does. An out-of-range value is ignored rather than rejected, so the board still attaches without interrupt support, exactly as it does today when request_irq() fails.
--- drivers/comedi/drivers/comedi_parport.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/comedi/drivers/comedi_parport.c +2 -1
@@ -243,7 +243,8 @@ static int parport_attach(struct comedi_device *dev,outb (0 , dev->iobase +PARPORT_DATA_REG );outb (0 , dev->iobase +PARPORT_CTRL_REG ); -if (it->options[1 ]) { +/* only ISA interrupts are valid on a parallel port */ +if (it->options[1 ] >=1 && it->options[1 ] <=15 ) { ret =request_irq (it->options[1 ], parport_interrupt,0 , dev->board_name, dev);if (ret ==0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1727/2651 comedi: ni_atmio16d: validate the IRQ supplied by userspace
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yogesh Gaur <[email protected]>
[ Upstream commit 71424db0ebb5f484fa3f386910f8ce9da95b8b2e ]
comedi boards are configured through the COMEDI_DEVCONFIG ioctl, so it->options[1] is a number chosen by userspace. ni_atmio16d passes it to request_irq() without checking it first, which lets an interrupt owned by another irqdomain -- a PCI device's IO-APIC GSI, for instance -- be claimed for this board. When the owner of that interrupt is later released the descriptor is freed while this driver's handler is still installed on it.
The driver already documents which interrupts the board can assert -- "0 == no irq; or 3,4,5,6,7,9,10,11,12,14,15" -- so use exactly that set rather than the whole ISA range.
Bound the value before requesting it, as das16m1.c already does. An out-of-range value is ignored rather than rejected, so the board still attaches without interrupt support, exactly as it does today when request_irq() fails.
--- drivers/comedi/drivers/ni_atmio16d.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/comedi/drivers/ni_atmio16d.c +3 -1
@@ -593,7 +593,9 @@ static int atmio16d_attach(struct comedi_device *dev,/* reset the atmio16d hardware */ reset_atmio16d (dev); -if (it->options[1 ]) { +/* only irqs 3, 4, 5, 6, 7, 9, 10, 11, 12, 14, and 15 are valid */ +if (it->options[1 ] >=3 && it->options[1 ] <=15 && + (1 << it->options[1 ]) &0xdef8 ) { ret =request_irq (it->options[1 ], atmio16d_interrupt,0 , dev->board_name, dev);if (ret ==0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1728/2651 comedi: dt2814: validate the IRQ supplied by userspace
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yogesh Gaur <[email protected]>
[ Upstream commit 81026c2b3f9096cdfdfa02918f94865629fb7f90 ]
comedi boards are configured through the COMEDI_DEVCONFIG ioctl, so it->options[1] is a number chosen by userspace. dt2814 passes it to request_irq() without checking it first, which lets an interrupt owned by another irqdomain -- a PCI device's IO-APIC GSI, for instance -- be claimed for this board. When the owner of that interrupt is later released the descriptor is freed while this driver's handler is still installed on it.
Every interrupt this board can assert is a legacy ISA one, so the ISA range is the right bound; it is also sufficient, because mp_chip_data->isa_irq is set only by alloc_isa_irq_from_domain() and mp_unmap_irq() returns early when it is set.
Bound the value before requesting it, as das16m1.c already does. An out-of-range value is ignored rather than rejected, so the board still attaches without interrupt support, exactly as it does today when request_irq() fails.
--- drivers/comedi/drivers/dt2814.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/comedi/drivers/dt2814.c +2 -1
@@ -316,7 +316,8 @@ static int dt2814_attach(struct comedi_device *dev, struct comedi_devconfig *it)return -EIO ; } -if (it->options[1 ]) { +/* only ISA interrupts are valid on this board */ +if (it->options[1 ] >=1 && it->options[1 ] <=15 ) { ret =request_irq (it->options[1 ], dt2814_interrupt,0 , dev->board_name, dev);if (ret ==0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1729/2651 comedi: dmm32at: validate the IRQ supplied by userspace
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yogesh Gaur <[email protected]>
[ Upstream commit 797d56d7f90864e67424f8e82639a9b3aedf37e0 ]
comedi boards are configured through the COMEDI_DEVCONFIG ioctl, so it->options[1] is a number chosen by userspace. dmm32at passes it to request_irq() without checking it first, which lets an interrupt owned by another irqdomain -- a PCI device's IO-APIC GSI, for instance -- be claimed for this board. When the owner of that interrupt is later released the descriptor is freed while this driver's handler is still installed on it.
Every interrupt this board can assert is a legacy ISA one, so the ISA range is the right bound; it is also sufficient, because mp_chip_data->isa_irq is set only by alloc_isa_irq_from_domain() and mp_unmap_irq() returns early when it is set.
Bound the value before requesting it, as das16m1.c already does. An out-of-range value is ignored rather than rejected, so the board still attaches without interrupt support, exactly as it does today when request_irq() fails.
--- drivers/comedi/drivers/dmm32at.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/comedi/drivers/dmm32at.c +2 -1
@@ -600,7 +600,8 @@ static int dmm32at_attach(struct comedi_device *dev,return ret; } -if (it->options[1 ]) { +/* only ISA interrupts are valid on this board */ +if (it->options[1 ] >=1 && it->options[1 ] <=15 ) { ret =request_irq (it->options[1 ], dmm32at_isr,0 , dev->board_name, dev);if (ret ==0 )
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1730/2651 comedi: pcmmio: validate the IRQ supplied by userspace
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yogesh Gaur <[email protected]>
[ Upstream commit 23c6fc62e754f8bc412ceb5c0d9aaa14f2c9ff31 ]
comedi boards are configured through the COMEDI_DEVCONFIG ioctl, so it->options[1] is a number chosen by userspace. pcmmio passes it to request_irq() without checking it first, which lets an interrupt owned by another irqdomain -- a PCI device's IO-APIC GSI, for instance -- be claimed for this board. When the owner of that interrupt is later released the descriptor is freed while this driver's handler is still installed on it.
The board's interrupt is routed in software rather than jumpered, and the driver notes that "any IRQ from 1-15 is OK", so the ISA range is exactly the right bound.
Bound the value before requesting it, as das16m1.c already does. An out-of-range value is ignored rather than rejected, so the board still attaches without interrupt support, exactly as it does today when request_irq() fails.
--- drivers/comedi/drivers/pcmmio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/comedi/drivers/pcmmio.c +2 -1
@@ -684,7 +684,8 @@ static int pcmmio_attach(struct comedi_device *dev, struct comedi_devconfig *it)pcmmio_reset (dev); -if (it->options[1 ]) { +/* the irq is configured in software, so any ISA irq is OK */ +if (it->options[1 ] >=1 && it->options[1 ] <=15 ) { ret =request_irq (it->options[1 ], interrupt_pcmmio,0 , dev->board_name, dev);if (ret ==0 ) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1731/2651 comedi: pcmuio: validate the IRQs supplied by userspace
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yogesh Gaur <[email protected]>
[ Upstream commit 9c325b21bba99e597771137fc11b9427c86618d8 ]
comedi boards are configured through the COMEDI_DEVCONFIG ioctl, so it->options[1] is a number chosen by userspace. pcmuio passes it to request_irq() without checking it first, which lets an interrupt owned by another irqdomain -- a PCI device's IO-APIC GSI, for instance -- be claimed for this board. When the owner of that interrupt is later released the descriptor is freed while this driver's handler is still installed on it.
Every interrupt this board can assert is a legacy ISA one, so the ISA range is the right bound; it is also sufficient, because mp_chip_data->isa_irq is set only by alloc_isa_irq_from_domain() and mp_unmap_irq() returns early when it is set.
Bound the value before requesting it, as das16m1.c already does. An out-of-range value is ignored rather than rejected, so the board still attaches without interrupt support, exactly as it does today when request_irq() fails.
This board takes two interrupts, one per ASIC, so options[1] and options[2] both need the check. The existing options[2] == dev->irq case is left alone: it covers both ASICs sharing one interrupt and neither having one, and by then options[1] has already been validated.
--- drivers/comedi/drivers/pcmuio.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/comedi/drivers/pcmuio.c +3 -2
@@ -546,7 +546,8 @@ static int pcmuio_attach(struct comedi_device *dev, struct comedi_devconfig *it)pcmuio_reset (dev); -if (it->options[1 ]) { +/* only ISA interrupts are valid on this board */ +if (it->options[1 ] >=1 && it->options[1 ] <=15 ) {/* request the irq for the 1st asic */ ret =request_irq (it->options[1 ], pcmuio_interrupt,0 , dev->board_name, dev);
@@ -558,7 +559,7 @@ static int pcmuio_attach(struct comedi_device *dev, struct comedi_devconfig *it)if (it->options[2 ] == dev->irq) {/* the same irq (or none) is used by both asics */ devpriv->irq2 = it->options[2 ]; - }else if (it->options[2 ]) { + }else if (it->options[2 ] >=1 && it->options[2 ] <=15 ) {/* request the irq for the 2nd asic */ ret =request_irq (it->options[2 ], pcmuio_interrupt,0 , dev->board_name, dev);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1732/2651 perf test attr: Source setup_python.sh instead of calling python
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Arnaldo Carvalho de Melo <[email protected]>
[ Upstream commit 3b05843302202598a6d25f3e2543c8182e6a930c ]
The "Perf attribute expectations test" (perf test 82) fails on machines that don't ship a bare 'python' binary, i.e. distributions that provide only python3 unless python-is-python3 or an equivalent is installed. Namhyung Kim hit this and posted the fix applied here in <[email protected]>:
/home/namhyung/project/linux/tools/perf/tests/shell/attr.sh: line 20: python: command not found ---- end(-1) ----
82: Perf attribute expectations test : FAILED!
attr.sh is the only shell test that still invokes python directly; do what the others do: source lib/setup_python.sh, which prefers python3, falls back to python and skips the test when no interpreter is found, then run $PYTHON.
--- tools/perf/tests/shell/attr.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/perf/tests/shell/attr.sh +5 -1
@@ -4,6 +4,10 @@ err=0 +shelldir=$(dirname "$0") +# shellcheck source=lib/setup_python.sh +. "${shelldir}"/lib/setup_python.sh + cleanup() { trap - EXIT TERM INT }
@@ -17,7 +21,7 @@ trap trap_cleanup EXIT TERM INT shelldir=$(dirname "$0") perf_path=$(which perf) -python "${shelldir}"/lib/attr.py -d "${shelldir}"/attr -v -p "$perf_path" +$PYTHON "${shelldir}"/lib/attr.py -d "${shelldir}"/attr -v -p "$perf_path" err=$? cleanup exit $err
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1733/2651 thermal/drivers/qcom-spmi-temp-alarm: Fix temp_map indexing
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Georgi Djakov <[email protected]>
[ Upstream commit 51c262cf2aa9dfd97591e570d4e82af493ad1689 ]
Fix the following issue noticed when booting on the db845c-dragonboard:
BUG: KASAN: global-out-of-bounds in qpnp_tm_sync_thresholds+0x11c/0x180 [qcom_spmi_temp_alarm] Read of size 24 at addr ffffdd2495f01200 by task (udev-worker)/371 CPU: 3 UID: 0 PID: 371 Comm: (udev-worker) Not tainted 7.3.0-rc3 #116 PREEMPT Hardware name: Thundercomm Dragonboard 845c (DT) Call trace: show_stack+0x18/0x24 (C) dump_stack_lvl+0xa4/0xf4 print_report+0x1f4/0x5ac kasan_report+0x84/0xcc kasan_check_range+0xf0/0x1a4 memcpy+0x3c/0xa4 qpnp_tm_sync_thresholds+0x11c/0x180 [qcom_spmi_temp_alarm] qpnp_tm_probe+0x3dc/0xae8 [qcom_spmi_temp_alarm] platform_probe+0xc4/0x18c really_probe+0x17c/0x4fc ... The buggy address belongs to the variable: temp_map_gen1+0x60/0xc4 [qcom_spmi_temp_alarm]
It looks like temp_map is a pointer to the complete temperature map. Indexing it directly advances the entire map, rather than selecting a threshold row.
Fix this by dereferencing the temp_map before indexing it to select the requested threshold row.
--- drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/thermal/qcom/qcom-spmi-temp-alarm.c +4 -4
@@ -345,8 +345,8 @@ static int qpnp_tm_update_critical_trip_temp(struct qpnp_tm_chip *chip, } skip: -memcpy (chip->temp_thresh_map, chip->data->temp_map[threshold], -sizeof (chip->temp_thresh_map)); +memcpy (chip->temp_thresh_map, (*chip->data->temp_map)[threshold], +sizeof (chip->temp_thresh_map)); reg |= threshold;if (disable_stage2_shutdown && !chip->require_stage2_shutdown) reg |=SHUTDOWN_CTRL1_OVERRIDE_STAGE2 ;
@@ -535,8 +535,8 @@ static int qpnp_tm_sync_thresholds(struct qpnp_tm_chip *chip)return ret; threshold = reg &SHUTDOWN_CTRL1_THRESHOLD_MASK ; -memcpy (chip->temp_thresh_map, chip->data->temp_map[threshold], -sizeof (chip->temp_thresh_map)); +memcpy (chip->temp_thresh_map, (*chip->data->temp_map)[threshold], +sizeof (chip->temp_thresh_map));return ret; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1734/2651 thermal/drivers/ti-soc-thermal: Cancel pending alert work on remove
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weigang He <[email protected]>
[ Upstream commit aaa6c8dec49339710f9fd2a2af5646cf4111dbd4 ]
On a threshold crossing, the talert IRQ handler calls ti_thermal_report_sensor_temperature(), which queues the work embedded in the sensor's ti_thermal_data on the system workqueue. Nothing ever cancels or flushes that work.
ti_bandgap_remove() frees the talert IRQ last. free_irq() waits for a running handler, but not for the work the handler has queued. When remove returns, devres unregisters and frees the thermal zones and then frees the devm-allocated ti_thermal_data, so a work item that is still pending runs ti_thermal_work() on freed memory:
ti_thermal_work() data = container_of(work, struct ti_thermal_data, thermal_wq); thermal_zone_device_update(data->ti_thermal, ...);
Free the talert IRQ before removing the sensors, so that no new work can be queued, and cancel the work in ti_thermal_remove_sensor().
This needs an OMAP4460/4470 or OMAP5 SoC (DRA7 has TALERT but no ->report_temperature, so it never queues the work), a threshold crossing just before the driver is unbound or unloaded, and the work still pending when devres frees the data.
Found by static analysis tool CodeQL.
--- drivers/thermal/ti-soc-thermal/ti-bandgap.c | 7 ++++--- drivers/thermal/ti-soc-thermal/ti-thermal-common.c | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-)
drivers/thermal/ti-soc-thermal/ti-bandgap.c +4 -3
@@ -1077,6 +1077,10 @@ void ti_bandgap_remove(struct platform_device *pdev)if (!soc_device_match (soc_no_cpu_notifier))cpu_pm_unregister_notifier (&bgp->nb); +/* Stop the alerts first: they queue work on the sensors' data */ +if (TI_BANDGAP_HAS (bgp,TALERT )) +free_irq (bgp->irq, bgp); +/* Remove sensor interfaces */ for (i =0 ; i < bgp->conf->sensor_count; i++) {if (bgp->conf->sensors[i].unregister_cooling)
@@ -1093,9 +1097,6 @@ void ti_bandgap_remove(struct platform_device *pdev)clk_put (bgp->fclock);clk_put (bgp->div_clk); -if (TI_BANDGAP_HAS (bgp,TALERT )) -free_irq (bgp->irq, bgp); -if (TI_BANDGAP_HAS (bgp,TSHUT ))free_irq (gpiod_to_irq (bgp->tshut_gpiod),NULL ); }
drivers/thermal/ti-soc-thermal/ti-thermal-common.c +4 -0
@@ -195,6 +195,10 @@ int ti_thermal_remove_sensor(struct ti_bandgap *bgp, int id) data =ti_bandgap_get_sensor_data (bgp, id); +/* Work queued by the talert IRQ must not outlive the data */ +if (!IS_ERR_OR_NULL (data)) +cancel_work_sync (&data->thermal_wq); +if (!IS_ERR_OR_NULL (data) && data->ti_thermal) {if (data->our_zone)thermal_zone_device_unregister (data->ti_thermal);
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1735/2651 tools: hv: remove unused rte_smp_mb()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
[ Upstream commit b67eeae485e22893b678229169024a73b87cf113 ]
rte_smp_mb() has never been used, and its "static inline __always_inline" declares inline twice, so clang warns:
vmbus_bufring.c:61:15: warning: duplicate 'inline' declaration specifier [-Wduplicate-decl-specifier] vmbus_bufring.c:62:1: warning: unused function 'rte_smp_mb' [-Wunused-function]
Remove it.
--- tools/hv/vmbus_bufring.c | 6 ------ 1 file changed, 6 deletions(-)
tools/hv/vmbus_bufring.c +0 -6
@@ -58,12 +58,6 @@ void vmbus_br_setup(struct vmbus_br *br, void *buf, unsigned int blen) br->dsize = blen -sizeof (struct vmbus_bufring ); } -static inline __always_inline void -rte_smp_mb (void ) -{ - asmvolatile ("lock addl $0, -128(%%rsp); " :::"memory" ); -} -static inline int rte_atomic32_cmpset (volatile uint32_t *dst,uint32_t exp,uint32_t src) {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1736/2651 char: scx200_gpio: check cdev_add() return value
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linkai Gong <[email protected]>
[ Upstream commit fe26c195c265c033e474d015061a0183c7a02193 ]
cdev_add() can fail. The driver currently ignores the return value and reports probe success even when the cdev was not registered, leaving a chrdev region allocated with no working file operations.
Check the return value, emit an error, and unwind the chrdev region and platform device on failure.
--- drivers/char/scx200_gpio.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/char/scx200_gpio.c +7 -1
@@ -107,10 +107,16 @@ static int __init scx200_gpio_init(void) }cdev_init (&scx200_gpio_cdev, &scx200_gpio_fileops); -cdev_add (&scx200_gpio_cdev, devid,MAX_PINS ); + rc =cdev_add (&scx200_gpio_cdev, devid,MAX_PINS ); +if (rc) { +dev_err (&pdev->dev,"cdev_add err: %d\n" , rc); + goto undo_chrdev_region; + }return 0 ;/* succeed */ +undo_chrdev_region: +unregister_chrdev_region (devid,MAX_PINS ); undo_platform_device_add:platform_device_del (pdev); undo_malloc:
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1737/2651 bus: arm-cci: Drop CPU node reference in cci_ace_init_ports()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuho Choi <[email protected]>
[ Upstream commit 41d6c0fcd4d75bf78c304c6660d60fcf757885ce ]
cci_ace_init_ports() looks up each possible CPU's node with of_get_cpu_node(), which returns the node with its reference count raised, but never releases it: neither when the CPU has no ACE port nor after the port has been recorded. Before the commit below the loop used for_each_child_of_node(), which manages the references itself.
The node is only needed for the port lookup, so drop the reference right after __cci_ace_get_port().
--- drivers/bus/arm-cci.c | 1 + 1 file changed, 1 insertion(+)
drivers/bus/arm-cci.c +1 -0
@@ -199,6 +199,7 @@ static void cci_ace_init_ports(void)continue ; port =__cci_ace_get_port (cpun,ACE_PORT ); +of_node_put (cpun);if (port <0 )continue ;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1738/2651 bus: arm-cci: Drop cci-control-port node reference in __cci_ace_get_port()
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yuho Choi <[email protected]>
[ Upstream commit 810ccc792193909ba9bbb4246e0eb0de14dad724 ]
__cci_ace_get_port() looks up the device's "cci-control-port" node with of_parse_phandle(), which returns the node with its reference count raised, and only compares the pointer against the probed ports. Neither the match nor the no-match return releases it.
Drop the reference on both paths once the comparison is done.
--- drivers/bus/arm-cci.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/bus/arm-cci.c +4 -1
@@ -167,9 +167,12 @@ static int __cci_ace_get_port(struct device_node *dn, int type) cci_portn =of_parse_phandle (dn,"cci-control-port" ,0 );for (i =0 ; i < nb_cci_ports; i++) { ace_match = ports[i].type == type; -if (ace_match && cci_portn == ports[i].dn) +if (ace_match && cci_portn == ports[i].dn) { +of_node_put (cci_portn);return i; + } } +of_node_put (cci_portn);return -ENODEV ; }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1739/2651 soc: mpfs: use kref cleanup on probe failure
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
[ Upstream commit 6f77194e1147d85c10b4964edee7091c701a25c2 ]
After kref_init(), the device_get_match_data() failure path frees the mailbox channel and sys_controller directly, bypassing the matching kref_put() for the initial reference.
Use mpfs_sys_controller_put() on this path so that the initial reference established by kref_init() is released through the existing kref release callback.
Rename the error label to reflect that cleanup is now performed through the kref helper.
This issue was found by manual code inspection.
--- drivers/soc/microchip/mpfs-sys-controller.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/soc/microchip/mpfs-sys-controller.c +4 -3
@@ -159,7 +159,7 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev) of_data = (struct mpfs_syscon_config *)device_get_match_data (dev);if (!of_data) { ret =dev_err_probe (dev, -EINVAL ,"Error getting match data\n" ); - goto out_free_channel; + goto out_put; }for (i =0 ; i < of_data->nb_subdevs; i++) {
@@ -173,8 +173,9 @@ static int mpfs_sys_controller_probe(struct platform_device *pdev)return 0 ; -out_free_channel: -mbox_free_channel (sys_controller->chan); +out_put: +mpfs_sys_controller_put (sys_controller); +return ret; out_free:kfree (sys_controller);return ret;
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1740/2651 clk: qcom: gcc-eliza: Tie the CX power domain to controller
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abel Vesa <[email protected]>
[ Upstream commit e8d919bc9a4cb27793d2aae12bb81f432c3f71a0 ]
Enable runtime PM for the controller, allowing CX to be powered down once all GCC consumers have released their clocks and GDSCs.
--- drivers/clk/qcom/gcc-eliza.c | 1 + 1 file changed, 1 insertion(+)
drivers/clk/qcom/gcc-eliza.c +1 -0
@@ -3068,6 +3068,7 @@ static const struct qcom_cc_desc gcc_eliza_desc = { .num_resets = ARRAY_SIZE(gcc_eliza_resets), .gdscs = gcc_eliza_gdscs, .num_gdscs = ARRAY_SIZE(gcc_eliza_gdscs), + .use_rpm = true, .driver_data = &gcc_eliza_driver_data, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1741/2651 clk: qcom: gcc-kaanapali: Tie the CX power domain to controller
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abel Vesa <[email protected]>
[ Upstream commit b080163dce8ce06167fa7c88eaefd4282955f616 ]
Enable runtime PM for the controller, allowing CX to be powered down once all GCC consumers have released their clocks and GDSCs.
--- drivers/clk/qcom/gcc-kaanapali.c | 1 + 1 file changed, 1 insertion(+)
drivers/clk/qcom/gcc-kaanapali.c +1 -0
@@ -3502,6 +3502,7 @@ static const struct qcom_cc_desc gcc_kaanapali_desc = { .num_resets = ARRAY_SIZE(gcc_kaanapali_resets), .gdscs = gcc_kaanapali_gdscs, .num_gdscs = ARRAY_SIZE(gcc_kaanapali_gdscs), + .use_rpm = true, .driver_data = &gcc_kaanapali_driver_data, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1742/2651 clk: qcom: gcc: Fix GPLL enable register offset for Nord SoC
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Taniya Das <[email protected]>
[ Upstream commit e297cf5b7601b7a41693eba2d9bc8f036e417bf7 ]
The GPLLs in the North-East, North-West and South-East global clock controllers on the Qualcomm Nord SoC were registered with a placeholder enable register offset of 0x0. As a result the shared PLL voting register was never programmed, leaving the PLLs' enable state uncontrolled.
Point each GPLL at its actual GPLL_ENABLE register (0x57010 for the North-East and South-East controllers, 0x76008 for the North-West controller). Each PLL continues to select its own vote bit through enable_mask.
--- drivers/clk/qcom/negcc-nord.c | 4 ++-- drivers/clk/qcom/nwgcc-nord.c | 2 +- drivers/clk/qcom/segcc-nord.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-)
drivers/clk/qcom/negcc-nord.c +2 -2
@@ -46,7 +46,7 @@ static struct clk_alpha_pll ne_gcc_gpll0 = { .offset = 0x0, .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID_OLE], .clkr = { - .enable_reg = 0x0, + .enable_reg = 0x57010, .enable_mask = BIT(0), .hw.init = &(const struct clk_init_data) { .name = "ne_gcc_gpll0",
@@ -85,7 +85,7 @@ static struct clk_alpha_pll ne_gcc_gpll2 = { .offset = 0x2000, .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID_OLE], .clkr = { - .enable_reg = 0x0, + .enable_reg = 0x57010, .enable_mask = BIT(2), .hw.init = &(const struct clk_init_data) { .name = "ne_gcc_gpll2",
drivers/clk/qcom/nwgcc-nord.c +1 -1
@@ -36,7 +36,7 @@ static struct clk_alpha_pll nw_gcc_gpll0 = { .offset = 0x0, .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID_OLE], .clkr = { - .enable_reg = 0x0, + .enable_reg = 0x76008, .enable_mask = BIT(0), .hw.init = &(const struct clk_init_data) { .name = "nw_gcc_gpll0",
drivers/clk/qcom/segcc-nord.c +4 -4
@@ -39,7 +39,7 @@ static struct clk_alpha_pll se_gcc_gpll0 = { .offset = 0x0, .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID_OLE], .clkr = { - .enable_reg = 0x0, + .enable_reg = 0x57010, .enable_mask = BIT(0), .hw.init = &(const struct clk_init_data) { .name = "se_gcc_gpll0",
@@ -78,7 +78,7 @@ static struct clk_alpha_pll se_gcc_gpll2 = { .offset = 0x2000, .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID_OLE], .clkr = { - .enable_reg = 0x0, + .enable_reg = 0x57010, .enable_mask = BIT(2), .hw.init = &(const struct clk_init_data) { .name = "se_gcc_gpll2",
@@ -95,7 +95,7 @@ static struct clk_alpha_pll se_gcc_gpll4 = { .offset = 0x4000, .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID_OLE], .clkr = { - .enable_reg = 0x0, + .enable_reg = 0x57010, .enable_mask = BIT(4), .hw.init = &(const struct clk_init_data) { .name = "se_gcc_gpll4",
@@ -112,7 +112,7 @@ static struct clk_alpha_pll se_gcc_gpll5 = { .offset = 0x5000, .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_LUCID_OLE], .clkr = { - .enable_reg = 0x0, + .enable_reg = 0x57010, .enable_mask = BIT(5), .hw.init = &(const struct clk_init_data) { .name = "se_gcc_gpll5",
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1743/2651 clk: qcom: rpmhcc: Add LNBB clocks support for Glymur
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jagadeesh Kona <[email protected]>
[ Upstream commit 1ebab545ee3acbbee22adecb858d5d1d001de0af ]
Add support for rpmh LN_BB_CLK2 and LN_BB_CLK3 clocks on Qualcomm Glymur platform.
--- drivers/clk/qcom/clk-rpmh.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/clk/qcom/clk-rpmh.c +5 -0
@@ -393,6 +393,7 @@ DEFINE_CLK_RPMH_VRM(clk2, _a1_e0, "C2A_E0", 1);DEFINE_CLK_RPMH_VRM (clk3, _a1_e0,"C3A_E0" ,1 );DEFINE_CLK_RPMH_VRM (clk4, _a1_e0,"C4A_E0" ,1 );DEFINE_CLK_RPMH_VRM (clk5, _a1_e0,"C5A_E0" ,1 ); +DEFINE_CLK_RPMH_VRM (clk7, _a1_e0,"C7A_E0" ,1 );DEFINE_CLK_RPMH_VRM (clk8, _a1_e0,"C8A_E0" ,1 );DEFINE_CLK_RPMH_VRM (clk3, _a2_e0,"C3A_E0" ,2 );
@@ -902,6 +903,10 @@ static struct clk_hw *glymur_rpmh_clocks[] = { [RPMH_RF_CLK4_A] = &clk_rpmh_clk4_a1_e0_ao.hw, [RPMH_RF_CLK5] = &clk_rpmh_clk5_a1_e0.hw, [RPMH_RF_CLK5_A] = &clk_rpmh_clk5_a1_e0_ao.hw, + [RPMH_LN_BB_CLK2] = &clk_rpmh_clk7_a1_e0.hw, + [RPMH_LN_BB_CLK2_A] = &clk_rpmh_clk7_a1_e0_ao.hw, + [RPMH_LN_BB_CLK3] = &clk_rpmh_clk8_a1_e0.hw, + [RPMH_LN_BB_CLK3_A] = &clk_rpmh_clk8_a1_e0_ao.hw, };static const struct clk_rpmh_desc clk_rpmh_glymur = {
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1744/2651 clk: qcom: gcc-glymur: Use clk_regmap_phy_mux_ops for GCC UFS muxes
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jagadeesh Kona <[email protected]>
[ Upstream commit 20b77a88fc6e410b69bc98d3d61c035a8618fb90 ]
Use clk_regmap_phy_mux_ops for GCC UFS muxes so these muxes are automatically switched to UFS external symbol clocks during enable and safely parked at XO clk during disable.
--- drivers/clk/qcom/gcc-glymur.c | 69 +++++++++-------------------------- 1 file changed, 18 insertions(+), 51 deletions(-)
drivers/clk/qcom/gcc-glymur.c +18 -51
@@ -481,36 +481,6 @@ static const struct clk_parent_data gcc_parent_data_17[] = { { .hw = &gcc_gpll0_out_even.clkr.hw }, }; -static const struct parent_map gcc_parent_map_18[] = { - {P_UFS_PHY_RX_SYMBOL_0_CLK ,0 }, - {P_BI_TCXO ,2 }, -}; - -static const struct clk_parent_data gcc_parent_data_18[] = { - { .index =DT_UFS_PHY_RX_SYMBOL_0_CLK }, - { .index =DT_BI_TCXO }, -}; - -static const struct parent_map gcc_parent_map_19[] = { - {P_UFS_PHY_RX_SYMBOL_1_CLK ,0 }, - {P_BI_TCXO ,2 }, -}; - -static const struct clk_parent_data gcc_parent_data_19[] = { - { .index =DT_UFS_PHY_RX_SYMBOL_1_CLK }, - { .index =DT_BI_TCXO }, -}; - -static const struct parent_map gcc_parent_map_20[] = { - {P_UFS_PHY_TX_SYMBOL_0_CLK ,0 }, - {P_BI_TCXO ,2 }, -}; - -static const struct clk_parent_data gcc_parent_data_20[] = { - { .index =DT_UFS_PHY_TX_SYMBOL_0_CLK }, - { .index =DT_BI_TCXO }, -}; -static const struct parent_map gcc_parent_map_21[] = { {P_GCC_USB3_PRIM_PHY_PIPE_CLK_SRC ,0 }, { P_USB4_0_PHY_GCC_USB4RTR_MAX_PIPE_CLK, 1 },
@@ -907,47 +877,44 @@ static struct clk_regmap_phy_mux gcc_pcie_6_pipe_clk_src = { }, }; -static struct clk_regmap_mux gcc_ufs_phy_rx_symbol_0_clk_src = { +static struct clk_regmap_phy_mux gcc_ufs_phy_rx_symbol_0_clk_src = { .reg =0x7706c , - .shift =0 , - .width =2 , - .parent_map = gcc_parent_map_18, .clkr = { .hw.init = &(const struct clk_init_data ) { .name ="gcc_ufs_phy_rx_symbol_0_clk_src" , - .parent_data = gcc_parent_data_18, - .num_parents =ARRAY_SIZE (gcc_parent_data_18), - .ops = &clk_regmap_mux_closest_ops, + .parent_data = &(const struct clk_parent_data ){ + .index =DT_UFS_PHY_RX_SYMBOL_0_CLK , + }, + .num_parents =1 , + .ops = &clk_regmap_phy_mux_ops, }, }, }; -static struct clk_regmap_mux gcc_ufs_phy_rx_symbol_1_clk_src = { +static struct clk_regmap_phy_mux gcc_ufs_phy_rx_symbol_1_clk_src = { .reg =0x770f0 , - .shift =0 , - .width =2 , - .parent_map = gcc_parent_map_19, .clkr = { .hw.init = &(const struct clk_init_data ) { .name ="gcc_ufs_phy_rx_symbol_1_clk_src" , - .parent_data = gcc_parent_data_19, - .num_parents =ARRAY_SIZE (gcc_parent_data_19), - .ops = &clk_regmap_mux_closest_ops, + .parent_data = &(const struct clk_parent_data ){ + .index =DT_UFS_PHY_RX_SYMBOL_1_CLK , + }, + .num_parents =1 , + .ops = &clk_regmap_phy_mux_ops, }, }, }; -static struct clk_regmap_mux gcc_ufs_phy_tx_symbol_0_clk_src = { +static struct clk_regmap_phy_mux gcc_ufs_phy_tx_symbol_0_clk_src = { .reg =0x7705c , - .shift =0 , - .width =2 , - .parent_map = gcc_parent_map_20, .clkr = { .hw.init = &(const struct clk_init_data ) { .name ="gcc_ufs_phy_tx_symbol_0_clk_src" , - .parent_data = gcc_parent_data_20, - .num_parents =ARRAY_SIZE (gcc_parent_data_20), - .ops = &clk_regmap_mux_closest_ops, + .parent_data = &(const struct clk_parent_data ){ + .index =DT_UFS_PHY_TX_SYMBOL_0_CLK , + }, + .num_parents =1 , + .ops = &clk_regmap_phy_mux_ops, }, }, };
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1745/2651 clk: qcom: gcc-x1e80100: Dont poll the status bit of GCC_USB4_n_SYS_CLK
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Konrad Dybcio <[email protected]>
[ Upstream commit d42e0c55e6db7b8282e8dc63f7e70595da0f72f5 ]
These clocks are PHY-sourced and their halt bits seem not to update reliably. Ignore it to prevent spurious warnings.
--- drivers/clk/qcom/gcc-x1e80100.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/clk/qcom/gcc-x1e80100.c +3 -3
@@ -6049,7 +6049,7 @@ static struct clk_branch gcc_usb4_0_sb_if_clk = {static struct clk_branch gcc_usb4_0_sys_clk = { .halt_reg =0x9f054 , - .halt_check =BRANCH_HALT , + .halt_check =BRANCH_HALT_SKIP , .clkr = { .enable_reg =0x9f054 , .enable_mask =BIT (0 ),
@@ -6266,7 +6266,7 @@ static struct clk_branch gcc_usb4_1_sb_if_clk = {static struct clk_branch gcc_usb4_1_sys_clk = { .halt_reg =0x2b054 , - .halt_check =BRANCH_HALT , + .halt_check =BRANCH_HALT_SKIP , .clkr = { .enable_reg =0x2b054 , .enable_mask =BIT (0 ),
@@ -6483,7 +6483,7 @@ static struct clk_branch gcc_usb4_2_sb_if_clk = {static struct clk_branch gcc_usb4_2_sys_clk = { .halt_reg =0x11054 , - .halt_check =BRANCH_HALT , + .halt_check =BRANCH_HALT_SKIP , .clkr = { .enable_reg =0x11054 , .enable_mask =BIT (0 ),
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1746/2651 clk: qcom: gcc-ipq5424: Fix TME reset register offsets
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abel Vesa <[email protected]>
[ Upstream commit 3732dccb8d75b2cddc8857f3944cb7482ef4b46a ]
The GCC_TME_BCR and GCC_TME_SEC_BUS_BCR offsets exceed the regmap maximum of 0x3f024. Regmap therefore rejects accesses to both registers, leaving the resets ineffective while the reset operations report success.
The offsets appear to contain typographical errors. Use 0x10000 for GCC_TME_BCR, matching the offset used on IPQ9574 and the surrounding register layout. Use 0x1a030 for GCC_TME_SEC_BUS_BCR, placing it in the same register block as GCC_SEC_CTRL_BCR at 0x1a000.
--- drivers/clk/qcom/gcc-ipq5424.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/qcom/gcc-ipq5424.c +2 -2
@@ -2949,7 +2949,7 @@ static const struct qcom_reset_map gcc_ipq5424_resets[] = { [GCC_QUPV3_SPI0_BCR] = { 0x04000, 0 }, [GCC_QUPV3_SPI1_BCR] = { 0x05000, 0 }, [GCC_IMEM_BCR] = { 0x0e000, 0 }, - [GCC_TME_BCR] = { 0x100000, 0 }, + [GCC_TME_BCR] = { 0x10000, 0 }, [GCC_DDRSS_BCR] = { 0x11000, 0 }, [GCC_PRNG_BCR] = { 0x13020, 0 }, [GCC_BOOT_ROM_BCR] = { 0x13028, 0 },
@@ -2960,7 +2960,7 @@ static const struct qcom_reset_map gcc_ipq5424_resets[] = { [GCC_UNIPHY2_BCR] = { 0x17064, 0 }, [GCC_WCSS_BCR] = { 0x18004, 0 }, [GCC_SEC_CTRL_BCR] = { 0x1a000, 0 }, - [GCC_TME_SEC_BUS_BCR] = { 0xa1030, 0 }, + [GCC_TME_SEC_BUS_BCR] = { 0x1a030, 0 }, [GCC_ADSS_BCR] = { 0x1c000, 0 }, [GCC_LPASS_BCR] = { 0x27000, 0 }, [GCC_PCIE0_BCR] = { 0x28000, 0 },
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1747/2651 clk: qcom: mmcc-msm8996: Fix FD AHB clock register offset
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abel Vesa <[email protected]>
[ Upstream commit 7cb2d65286b817d8d7e26f454a9c374d65e87072 ]
The FD AHB clock branch register is at offset 0x3b74, not 0x3ba74. The incorrect offset exceeds the regmap maximum of 0xb008, so regmap rejects accesses to it and the clock cannot be enabled.
Correct both the enable and halt register offsets so the driver can enable the branch and check its status.
--- drivers/clk/qcom/mmcc-msm8996.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/qcom/mmcc-msm8996.c +2 -2
@@ -3133,9 +3133,9 @@ static struct clk_branch fd_core_uar_clk = { };static struct clk_branch fd_ahb_clk = { - .halt_reg =0x3ba74 , + .halt_reg =0x3b74 , .clkr = { - .enable_reg =0x3ba74 , + .enable_reg =0x3b74 , .enable_mask =BIT (0 ), .hw.init = &(struct clk_init_data ){ .name ="fd_ahb_clk" ,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1748/2651 clk: qcom: mmcc-sdm660: Fix MDSS AHB clock HWCG register offset
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abel Vesa <[email protected]>
[ Upstream commit c5f338329a2d0d60f7874aa7a1addaa0e4e75a3b ]
The MDSS AHB clock HWCG bit resides in the same register as the branch enable and halt status bits, at offset 0x2308. The current HWCG register offset of 0x8a004 exceeds the regmap maximum of 0x40000, so regmap rejects the read in clk_branch_in_hwcg_mode(). Since the read error is ignored, the helper uses an uninitialized value to decide whether to skip the halt status check.
Correct the HWCG register offset so the helper reads the actual hardware clock gating state.
--- drivers/clk/qcom/mmcc-sdm660.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/qcom/mmcc-sdm660.c +1 -1
@@ -2017,7 +2017,7 @@ static struct clk_branch csiphy_ahb2crif_clk = {static struct clk_branch mdss_ahb_clk = { .halt_reg =0x2308 , .halt_check =BRANCH_HALT , - .hwcg_reg =0x8a004 , + .hwcg_reg =0x2308 , .hwcg_bit =1 , .clkr = { .enable_reg =0x2308 ,
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1749/2651 clk: qcom: mmcc-msm8960: Configure PLL15 only on APQ8064
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abel Vesa <[email protected]>
[ Upstream commit 342db3b6cf7bad2a53ccd5e2d844faf260953d9d ]
PLL15 is specific to APQ8064, but the shared probe function configures it unconditionally, including on MSM8960. Its configuration registers at offsets 0x33c through 0x348 exceed the MSM8960 regmap maximum of 0x334, so regmap rejects these accesses. The PLL configuration helper ignores the errors and probe continues.
Only configure PLL15 when the selected descriptor is for APQ8064, matching the existing variant check for the GFX3D clock adjustments.
--- drivers/clk/qcom/mmcc-msm8960.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/clk/qcom/mmcc-msm8960.c +2 -1
@@ -3170,7 +3170,8 @@ static int mmcc_msm8960_probe(struct platform_device *pdev)if (IS_ERR (regmap))return PTR_ERR (regmap); -clk_pll_configure_sr (&pll15, regmap, &pll15_config, false); +if (desc == &mmcc_apq8064_desc) +clk_pll_configure_sr (&pll15, regmap, &pll15_config, false);return qcom_cc_really_probe (&pdev->dev, desc, regmap); }
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1750/2651 clk: qcom: rcg2: Initialize shared floor clock state
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Konrad Dybcio <[email protected]>
[ Upstream commit 72f34d429f6e51b0ef8c43ab7667c4fb4099dd46 ]
Shared floor RCGs use the cached parked_cfg whenever CCF considers the clock disabled. Unlike the other shared RCG variants, their ops do not initialize that cache, leaving it zeroed until the first disable or rate change. This can make registration report an undivided XO configuration instead of the boot-programmed parent and divider.
Initialize parked_cfg from CFG_REG without parking or otherwise changing the hardware. Propagate read failures so a clock with unknown initial state is not registered.
--- drivers/clk/qcom/clk-rcg2.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
drivers/clk/qcom/clk-rcg2.c +13 -13
@@ -1555,7 +1555,20 @@ const struct clk_ops clk_rcg2_shared_ops = { };EXPORT_SYMBOL_GPL (clk_rcg2_shared_ops); +static int clk_rcg2_shared_no_init_park (struct clk_hw *hw) +{ +struct clk_rcg2 *rcg =to_clk_rcg2 (hw); + +/* +* Read the config register so that the parent is properly mapped at +* registration time. +*/ +return regmap_read (rcg->clkr.regmap, rcg->cmd_rcgr +CFG_REG , + &rcg->parked_cfg); +} +const struct clk_ops clk_rcg2_shared_floor_ops = { + .init = clk_rcg2_shared_no_init_park, .enable = clk_rcg2_shared_enable, .disable = clk_rcg2_shared_disable, .get_parent = clk_rcg2_shared_get_parent,
@@ -1567,19 +1580,6 @@ const struct clk_ops clk_rcg2_shared_floor_ops = { };EXPORT_SYMBOL_GPL (clk_rcg2_shared_floor_ops); -static int clk_rcg2_shared_no_init_park (struct clk_hw *hw) -{ -struct clk_rcg2 *rcg =to_clk_rcg2 (hw); - -/* -* Read the config register so that the parent is properly mapped at -* registration time. -*/ -regmap_read (rcg->clkr.regmap, rcg->cmd_rcgr +CFG_REG , &rcg->parked_cfg); - -return 0 ; -} -/* * Like clk_rcg2_shared_ops but skip the init so that the clk frequency is left * unchanged at registration time.
Signature · 1 line
2.53.0
Greg Kroah-Hartman
maintainerPATCH 1751/2651 clk: qcom: rcg2: Propagate force-enable status errors
In reply to Greg Kroah-Hartman7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Konrad Dybcio <[email protected]>
[ Upstream commit 8c0f93e10fa9e34009817bd37bb75c1b5a691fa2 ]
clk_rcg2_is_enabled() returns either a hardware status or a negative regmap error. The force-enable polling loop treats every nonzero return as an enabled clock, so a failed status read is incorrectly reported as success and clock reconfiguration can continue with unknown hardware state.
Check for negative returns before testing the enabled status and propagate the read error to the caller.
--- drivers/clk/qcom/clk-rcg2.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/clk/qcom/clk-rcg2.c +4 -1
@@ -1332,7 +1332,10 @@ static int clk_rcg2_set_force_enable(struct clk_hw *hw)/* wait for RCG to turn ON */ for (count =500 ; count >0 ; count--) { -if (clk_rcg2_is_enabled (hw)) + ret =clk_rcg2_is_enabled (hw); +if (ret <0 ) +return ret; +if (ret)return 0 ;udelay (1 );
Signature · 1 line
2.53.0