7.2.5-rc1 review
Greg Kroah-Hartman
maintainerPATCH 122/556 irqchip/stm32mp-exti: Fix the unit of the hwspinlock timeout
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ju Nan <[email protected]>
commit d31fbbade43f880b7e59e2b3a72722fe2725d93f upstream.
HWSPNLCK_TIMEOUT is passed to hwspin_lock_timeout_in_atomic(), whose timeout argument is in milliseconds, not microseconds:
atomic_delay += HWSPINLOCK_RETRY_DELAY_US;
if (atomic_delay > to * 1000)
return -ETIMEDOUT;So stm32mp_exti_set_type() asks for a 1 second timeout where the comment next to the macro says it wants 1 millisecond. The semaphore is polled with udelay() from a section that holds chip_data->rlock, a raw_spinlock_t, so preemption stays disabled for the whole wait on every configuration, PREEMPT_RT included.
The hwspinlock core documents this explicitly:
If the mode is HWLOCK_IN_ATOMIC (called from an atomic context) the timeout is handled with busy-waiting delays, hence shall not exceed few msecs.
--- drivers/irqchip/irq-stm32mp-exti.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/irqchip/irq-stm32mp-exti.c +2 -2
@@ -22,7 +22,7 @@#define IRQS_PER_BANK 32 -#define HWSPNLCK_TIMEOUT 1000/* usec */ +#define HWSPNLCK_TIMEOUT_MS 1#define EXTI_EnCIDCFGR (n) (0x180 + (n) * 4)#define EXTI_HWCFGR1 0x3f0
@@ -376,7 +376,7 @@ static int stm32mp_exti_set_type(structraw_spin_lock (&chip_data->rlock);if (hwlock) { - err =hwspin_lock_timeout_in_atomic (hwlock,HWSPNLCK_TIMEOUT ); + err =hwspin_lock_timeout_in_atomic (hwlock,HWSPNLCK_TIMEOUT_MS );if (err) {pr_err ("%s can't get hwspinlock (%d)\n" , __func__, err); goto unlock;
Greg Kroah-Hartman
maintainerPATCH 123/556 kprobes: Protect kprobe_blacklist with RCU
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
commit 0c4256196b3a105307e2235fbfd85e768bbcdd0f upstream.
__within_kprobe_blacklist() traverses kprobe_blacklist without holding kprobe_mutex. When a module is unloaded, kprobe_remove_area_blacklist() removes blacklist entries and immediately frees them with kfree(). A concurrent call to within_kprobe_blacklist() can therefore dereference freed memory.
Furthermore, within_kprobe_blacklist() can be called in atomic or non-preemptible contexts where the sleeping kprobe_mutex cannot be taken.
Protect kprobe_blacklist with RCU. Use guard(rcu)() and list_for_each_entry_rcu() for traversal, list_add_tail_rcu() for insertions, list_del_rcu() for deletions, and kfree_rcu() to reclaim entries safely after a grace period.
--- include/linux/kprobes.h | 1 + kernel/kprobes.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-)
include/linux/kprobes.h +1 -0
@@ -181,6 +181,7 @@ struct kprobe_blacklist_entry {struct list_head list;unsigned long start_addr;unsigned long end_addr; +struct rcu_head rcu; };#ifdef CONFIG_KPROBES
kernel/kprobes.c +10 -4
@@ -1447,8 +1447,14 @@ static bool __within_kprobe_blacklist(un/* * If 'kprobe_blacklist' is defined, check the address and * reject any probe registration in the prohibited area. +* Note: this can return true during transition period where +* (start_addr, end_addr) in the black list is shrinking +* but old entry has not been removed yet. This is acceptable +* because the worst case is that we reject more probes than +* we should. */ -list_for_each_entry (ent, &kprobe_blacklist, list) { +guard (rcu)(); +list_for_each_entry_rcu (ent, &kprobe_blacklist, list) {if (addr >= ent->start_addr && addr < ent->end_addr)return true; }
@@ -2509,7 +2515,7 @@ int kprobe_add_ksym_blacklist(unsigned l ent->start_addr = entry; ent->end_addr = entry + size;INIT_LIST_HEAD (&ent->list); -list_add_tail (&ent->list, &kprobe_blacklist); +list_add_tail_rcu (&ent->list, &kprobe_blacklist);return (int )size; }
@@ -2603,8 +2609,8 @@ static void kprobe_remove_area_blacklistlist_for_each_entry_safe (ent, n, &kprobe_blacklist, list) {if (ent->start_addr < start || ent->start_addr >= end)continue ; -list_del (&ent->list); -kfree (ent); +list_del_rcu (&ent->list); +kfree_rcu (ent, rcu); } }
Greg Kroah-Hartman
maintainerPATCH 124/556 misc: fastrpc: dont publish fd before copy_to_user() succeeds
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baineng Shou <[email protected]>
commit a4a1a2bfcb29785292d634d7787edc6fb550714d upstream.
fastrpc_ioctl_alloc_dmabuf() calls dma_buf_fd() which installs the fd into the caller's fd table before copy_to_user() copies the fd number back to userspace. If copy_to_user() fails, the fd is already visible to other threads in the same process but the ioctl returns -EFAULT. The existing comment in the code even acknowledges the problem:
"The usercopy failed, but we can't do much about it, as dma_buf_fd()
already called fd_install()..."
Now that dma_buf_fd_install() is available (introduced to fix the same issue in dma-heap), apply the same pattern here: reserve the fd with get_unused_fd_flags(), attempt copy_to_user(), and only on success call dma_buf_fd_install() to publish it atomically with the tracepoint. On copy_to_user() failure, put_unused_fd() and dma_buf_put() cleanly unwind without any user-visible side effects.
--- drivers/misc/fastrpc.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/misc/fastrpc.c +6 -10
@@ -1712,24 +1712,20 @@ static int fastrpc_dmabuf_alloc(struct freturn err; } - bp.fd =dma_buf_fd (buf->dmabuf,O_ACCMODE ); + bp.fd =get_unused_fd_flags (O_ACCMODE );if (bp.fd <0 ) {dma_buf_put (buf->dmabuf); -return -EINVAL ; +return bp.fd; }if (copy_to_user (argp, &bp,sizeof (bp))) { -/* -* The usercopy failed, but we can't do much about it, as -* dma_buf_fd() already called fd_install() and made the -* file descriptor accessible for the current process. It -* might already be closed and dmabuf no longer valid when -* we reach this point. Therefore "leak" the fd and rely on -* the process exit path to do any required cleanup. -*/ +put_unused_fd (bp.fd); +dma_buf_put (buf->dmabuf);return -EFAULT ; } +dma_buf_fd_install (buf->dmabuf, bp.fd); +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 125/556 mm/huge_memory: transfer the pmd dirty bit to the folio on zap
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Usama Arif <[email protected]>
commit fe6cf984939d8e12cb33a99673c8d026c5135e68 upstream.
zap_huge_pmd_folio() propagates the pmd young bit to the folio for the file case, but not the dirty bit. The pte path does propagate it, in zap_present_folio_ptes() and so does the pmd split path, in __split_huge_pmd_locked().
For most file mappings the omission is harmless, because writing to a shared file mapping goes through page_mkwrite(), which dirties the folio. tmpfs is different: it has no page_mkwrite(), and vma_wants_writenotify() is false for it, so a *read* fault on a MAP_SHARED tmpfs mapping installs a writable pmd via do_read_fault(). do_read_fault() does not call fault_dirty_shared_page(), so subsequent stores through that mapping set only the hardware dirty bit in the pmd and never call folio_mark_dirty(). A shmem folio allocated by a fault is marked uptodate but not dirty (see the clear: block in shmem_get_folio_gfp()), so PG_dirty is never set at all.
Unmapping such a folio - munmap(), or exit_mmap() when the process dies - then loses the only record that it was written, because zap_huge_pmd() drops the pmd without transferring the dirty bit. Reclaim afterwards sees a clean shmem folio: the whole swap-out block in shrink_folio_list() is inside "if (folio_test_dirty(folio))", so pageout() is skipped and the folio falls into __remove_mapping(). There, folio_is_file_lru() is false for a swapbacked folio, so no shadow entry is created and __filemap_remove_folio(folio, NULL) simply empties the i_pages slot. The data is freed without ever being written to swap, and the next fault on that index returns a freshly zeroed folio.
This is silent data loss for any process that keeps state in a MAP_SHARED tmpfs segment across an unmap - for example a cache handed from one process generation to the next through /dev/shm. It requires the folio to be PMD-mapped, so it only shows up once shmem THP is enabled (which is what we did in Meta fleet and started noticing crashes); with THP off the pte path transfers the dirty bit correctly. It also only becomes visible when swap is enabled, because with no swap device shmem folios (which are on the anon LRU) are not scanned by reclaim at all, so the clean folio is never dropped.
Reproduced on x86_64 with a tmpfs mounted huge=within_size: read-fault a 2MB-backed region, write a known pattern through the resulting mapping, munmap, force reclaim of the cgroup, then re-map and read back. Without this patch the region reads back as zeros and vmstat shows zswpout 0 - the data was discarded rather than swapped. With this patch the region reads back correctly and the pages are swapped out as expected. With huge=never, or when the first touch is a write, the test passes either way.
--- mm/huge_memory.c | 2 ++ 1 file changed, 2 insertions(+)
mm/huge_memory.c +2 -0
@@ -2414,6 +2414,8 @@ static void zap_huge_pmd_folio(struct mmadd_mm_counter (mm,mm_counter_file (folio), -HPAGE_PMD_NR ); +if (is_present &&pmd_dirty (pmdval)) +folio_mark_dirty (folio);if (is_present &&pmd_young (pmdval) &&likely (vma_has_recency (vma)))folio_mark_accessed (folio);
Greg Kroah-Hartman
maintainerPATCH 126/556 mm/mempolicy: fix sleeping allocation in alloc_pages_bulk_weighted_interleave()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 540e583b66d6402bf556fde5e53c817a54c1afe5 upstream.
syzbot reported a sleeping function called from invalid context splat in bucket_table_alloc().
When rhashtable_insert_slow() rehashes the table under rcu_read_lock(), it calls bucket_table_alloc(..., GFP_ATOMIC | __GFP_NOWARN). If the bucket table allocation uses vmalloc, __vmalloc_node_range_noprof() invokes vm_area_alloc_pages() -> alloc_pages_bulk_mempolicy_noprof() with the passed GFP_ATOMIC flags.
If the current task has an MPOL_WEIGHTED_INTERLEAVE mempolicy, alloc_pages_bulk_weighted_interleave() is called and currently hardcodes GFP_KERNEL when allocating the temporary weights array, triggering a might_alloc() splat in atomic/RCU contexts.
Pass the gfp flags (masked with GFP_RECLAIM_MASK to strip page-allocator zone modifiers like __GFP_HIGHMEM) received by alloc_pages_bulk_weighted_interleave() to kmalloc() instead of hardcoding GFP_KERNEL. Since the weights buffer is immediately initialized in full, kmalloc() is sufficient.
--- mm/mempolicy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/mempolicy.c +1 -1
@@ -2676,7 +2676,7 @@ static unsigned long alloc_pages_bulk_we prev_node = node;/* create a local copy of node weights to operate on outside rcu */ - weights =kzalloc (nr_node_ids,GFP_KERNEL ); + weights =kmalloc (nr_node_ids, gfp &GFP_RECLAIM_MASK );if (!weights)return total_allocated;
Greg Kroah-Hartman
maintainerPATCH 127/556 memcg: keep folios objcg same as its node
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shakeel Butt <[email protected]>
commit bf4ade7dbd76d4ec8697840e4ebb15ed77c5ec26 upstream.
memcg_reparent_objcgs() has an inherent assumption that a folio's objcg is the objcg of the folio's node. Folio migration across nodes breaks that
assumption: the new folio simply inherits the old folio's objcg while living on a different node.
Once the assumption is broken, the reparenting of the folio's objcg and the reparenting of the folio's LRU list are no longer atomic. memcg_reparent_objcgs() handles one node per iteration and drops all the locks in between, so the objcg gets reparented in the iteration for the objcg's node while the LRU list gets spliced in the iteration for the folio's node. Any LRU operation on that folio in between resolves its lruvec through the objcg, and thus takes the lru_lock of the wrong memcg, not the lru_lock of the list the folio is actually on.
Fix this by selecting the objcg by folio_nid() at charge time, and by re-deriving it for the destination node in mem_cgroup_migrate() and mem_cgroup_replace_folio().
--- mm/memcontrol.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 83 insertions(+), 17 deletions(-)
mm/memcontrol.c +83 -17
@@ -2907,10 +2907,9 @@ struct mem_cgroup *mem_cgroup_from_virt(return folio_memcg_check (virt_to_folio (p)); } -static struct obj_cgroup *__get_obj_cgroup_from_memcg (struct mem_cgroup *memcg) +static struct obj_cgroup *__get_obj_cgroup_from_memcg (struct mem_cgroup *memcg, +int nid) { -int nid =numa_node_id (); -for (; memcg; memcg =parent_mem_cgroup (memcg)) {struct obj_cgroup *objcg =rcu_dereference (memcg->nodeinfo[nid]->objcg);
@@ -2921,12 +2920,13 @@ static struct obj_cgroup *__get_obj_cgroreturn NULL ; } -static inline struct obj_cgroup *get_obj_cgroup_from_memcg (struct mem_cgroup *memcg) +static inline struct obj_cgroup *get_obj_cgroup_from_memcg (struct mem_cgroup *memcg, +int nid) {struct obj_cgroup *objcg;rcu_read_lock (); - objcg =__get_obj_cgroup_from_memcg (memcg); + objcg =__get_obj_cgroup_from_memcg (memcg, nid);rcu_read_unlock ();return objcg;
@@ -2970,7 +2970,7 @@ static struct obj_cgroup *current_objcg_rcu_read_lock (); memcg =mem_cgroup_from_task (current); - objcg =__get_obj_cgroup_from_memcg (memcg); + objcg =__get_obj_cgroup_from_memcg (memcg,numa_node_id ());rcu_read_unlock ();/*
@@ -5133,7 +5133,7 @@ static int charge_memcg(struct folio *foint ret =0 ;struct obj_cgroup *objcg; - objcg =get_obj_cgroup_from_memcg (memcg); + objcg =get_obj_cgroup_from_memcg (memcg,folio_nid (folio));/* Do not account at the root objcg level. */ if (!obj_cgroup_is_root (objcg)) ret =try_charge_memcg (memcg, gfp,folio_nr_pages (folio));
@@ -5332,6 +5332,46 @@ void __mem_cgroup_uncharge_folios(structuncharge_batch (&ug); } +/* +* An LRU folio must hold the objcg belonging to its own node. +* +* memcg_reparent_objcgs() reparents a dying cgroup one node at a time: the +* folios on that node's LRU lists move to the parent and that node's objcg is +* redirected to the parent, atomically under the node's lru_lock. +* folio_lruvec_lock() relies on this to provide a stable folio<->lruvec +* binding. If a folio holds another node's objcg, its list membership and its +* lruvec resolution change in separate lock sections, and an LRU operation in +* between can re-add the folio to, and strand it on, the LRU list of a dead +* memcg. +* +* So when migration transfers the memcg state to a folio on another node, +* re-derive the objcg for the destination node. If the memcg is dying and the +* destination node has already been reparented, the lookup walks up to the +* nearest live ancestor - which is also where that node's LRU lists went. +* +* Returns the objcg to commit to @new, with a reference for the caller. +*/ +static struct obj_cgroup *get_migration_objcg (struct folio *old, +struct folio *new) +{ +struct obj_cgroup *old_objcg, *new_objcg; +int new_nid =folio_nid (new); + + old_objcg =get_obj_cgroup_from_folio (old); + +if (folio_nid (old) == new_nid) +return old_objcg; + +rcu_read_lock (); + new_objcg =__get_obj_cgroup_from_memcg (obj_cgroup_memcg (old_objcg), + new_nid); +rcu_read_unlock (); + +obj_cgroup_put (old_objcg); + +return new_objcg; +} +/** * mem_cgroup_replace_folio - Charge a folio's replacement. * @old: Currently circulating folio.
@@ -5360,21 +5400,28 @@ void mem_cgroup_replace_folio(struct folif (folio_memcg_charged (new))return ; - objcg =folio_objcg (old); -VM_WARN_ON_ONCE_FOLIO (!objcg, old); -if (!objcg) +VM_WARN_ON_ONCE_FOLIO (!folio_objcg (old), old); +if (!folio_objcg (old))return ; + objcg =get_migration_objcg (old, new); +rcu_read_lock (); memcg =obj_cgroup_memcg (objcg); -/* Force-charge the new page. The old one will be freed soon */ + +/* +* Force-charge the new page. The old one will be freed soon. +* +* The rootness of the committed objcg decides whether the final +* uncharge of @new goes through the page counters (see +* uncharge_folio()); charge them only if the uncharge will. +*/ if (!obj_cgroup_is_root (objcg)) {page_counter_charge (&memcg->memory, nr_pages);if (do_memsw_account ())page_counter_charge (&memcg->memsw, nr_pages); } -obj_cgroup_get (objcg);commit_charge (new, objcg);memcg1_commit_charge (new, memcg);rcu_read_unlock ();
@@ -5386,14 +5433,15 @@ void mem_cgroup_replace_folio(struct fol* @new: Replacement folio. * * Transfer the memcg data from the old folio to the new folio for migration. -* The old folio's data info will be cleared. Note that the memory counters -* will remain unchanged throughout the process. +* The old folio's data info will be cleared. The memory counters remain +* unchanged, unless the charge moves out of a fully reparented ancestry +* and has to be settled (see below). * * Both folios must be locked, @new->mapping must be set up. */ void mem_cgroup_migrate (struct folio *old,struct folio *new) { -struct obj_cgroup *objcg; +struct obj_cgroup *objcg, *new_objcg;VM_BUG_ON_FOLIO (!folio_test_locked (old), old);VM_BUG_ON_FOLIO (!folio_test_locked (new), new);
@@ -5414,12 +5462,30 @@ void mem_cgroup_migrate(struct folio *olif (!objcg)return ; -/* Transfer the charge and the objcg ref */ -commit_charge (new, objcg); + new_objcg =get_migration_objcg (old, new); + +/* +* @old was charged through a non-root objcg, so its charge is in the +* page counters. If the re-derivation walked up to the root objcg - +* @old's entire ancestry is dying and already reparented - the final +* uncharge of @new will skip the page counters (see uncharge_folio()). +* Settle them now: this is @old's eventual uncharge, moved up to the +* point where its charge record ends. +*/ +if (obj_cgroup_is_root (new_objcg) && !obj_cgroup_is_root (objcg)) { +rcu_read_lock (); +memcg_uncharge (obj_cgroup_memcg (objcg),folio_nr_pages (old)); +rcu_read_unlock (); + } + +commit_charge (new, new_objcg);/* Warning should never happen, so don't worry about refcount non-0 */ WARN_ON_ONCE (folio_unqueue_deferred_split (old)); old->memcg_data =0 ; + +/* @new holds its own reference now, drop @old's */ +obj_cgroup_put (objcg); }DEFINE_STATIC_KEY_FALSE (memcg_sockets_enabled_key);
Greg Kroah-Hartman
maintainerPATCH 128/556 memcg: bypass the reclaim and oom killer for dying tasks once oom_reaper is done
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shakeel Butt <[email protected]>
commit 6b0d1083364fc8e7cc2f7d1f93ee3ee78f4d52f7 upstream.
At Meta, we are seeing instances where an OOM killed job is stuck in the exit path for several hours. In one particular case, the job was stuck for more than 8 hours and I had to manually remove the memory.max limits to allow the process to exit.
The job was a single process job and had ~55 GiB memory.max and zswap enabled. It had almost 0 anon in memory and ~111 GiB in zswap compressed to ~51 GiB zswap pool (i.e. almost all of memory.current was zswap). Nothing was left on the LRUs to reclaim.
On further inspection, I observed ~20k threads of that process stuck with the following stack:
[<0>] mem_cgroup_out_of_memory+0x4e/0xa0 [<0>] charge_memcg+0x8bf/0x990 [<0>] mem_cgroup_swapin_charge_folio+0x4e/0x80 [<0>] __read_swap_cache_async+0x10c/0x260 [<0>] swapin_readahead+0x116/0x3f0 [<0>] do_swap_page+0x13c/0x1ce0 [<0>] handle_mm_fault+0x61d/0x11f0 [<0>] do_user_addr_fault+0x3e7/0x6d0 [<0>] exc_page_fault+0x8f/0x110 [<0>] asm_exc_page_fault+0x22/0x30 [<0>] __get_user_8+0x14/0x20 [<0>] futex_cleanup+0x27/0x1c0 [<0>] futex_exit_release+0x47/0x60 [<0>] do_exit+0x107/0x940 [<0>] do_group_exit+0x81/0xa0 [<0>] get_signal+0x2b1/0x6e0 [<0>] arch_do_signal_or_restart+0x1a/0x1c0 [<0>] exit_to_user_mode_loop+0xa8/0x1c0 [<0>] do_syscall_64+0x152/0x250 [<0>] entry_SYSCALL_64_after_hwframe+0x4b/0x53
In addition the dmesg was filled with "Out of memory and no killable processes..." messages.
I have no idea why oom reaper was not able to reap/unmap the process. My guess is that since oom reaper tries to acquire mmap_lock in read mode limited number of times and then gives up, there might be a thread of that process which had mmap_lock in write mode at that time.
My initial suspicion was the futex_cleanup and kernel page fault causing infinite fault and charge retries but that was put to rest in previous discussions happened on similar problem [1].
My current theory is that it is just a simple slow serialization behind the oom_lock. Unlike page allocator, memcg charge code takes the oom_lock without the "try". Though memcg oom code uses mutex_lock_killable(), note that in the call stack get_signal() consumes SIGKILL (or sigdelset(SIGKILL)) before calling do_group_exit(). So this mutex_lock_killable() is just a mutex_lock() here. Therefore 10s of thousands of threads are waiting on oom_lock and one by one they get -EFAULT from get_user() in the futex cleanup code and bails out.
Discussion from [1] led to commit a75ffa26122b ("memcg, oom: do not bypass oom killer for dying tasks") which routes dying tasks into the OOM path precisely so the oom_reaper can reap their mm and free the memory asynchronously. But the reaper is best-effort and one-shot: if it cannot take mmap_lock for read (e.g. a sibling thread holds it for write) it sets MMF_OOM_SKIP and never retries, leaving only the glacial oom_lock-serialized synchronous drain.
Once MMF_OOM_SKIP is set there is no more asynchronous reclaim coming for the mm, so a dying task charging against it has nothing left to wait for:
it frees its memory only once it finishes exiting. Running reclaim and the (no-victim) OOM killer for it is then pointless, and doing it for 10s of thousands of exiting threads is what serializes them behind oom_lock. So before reclaim, if current is an OOM victim whose reaper is done, fail the charge.
Reproduced with 20k threads, each parking a robust futex head on its own zswapped page, OOM-group-killed while a sibling holds mmap_lock for write so the reaper gives up and sets MMF_OOM_SKIP. Tested on next-20260728 and baseline show ~90 seconds exit time while with the patch the exit time reduced to ~3 seconds.
--- mm/memcontrol.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
mm/memcontrol.c +13 -0
@@ -2648,6 +2648,19 @@ retry:if (!gfpflags_allow_blocking (gfp_mask)) goto nomem; +/* +* OOM victim still needs to charge memory to exit. OOM reaper should +* help but it might fail on mmap_lock contention. If the victim is a +* large thread group then all exiting threads might compete on oom_lock +* just to learn that there is nothing really killable anymore. Bail +* out early and fail the charge to expedite their exit. They are +* considered fully reclaimed by the oom reaper and they shouldn't +* contribute further charges. +*/ +if (tsk_is_oom_victim (current) && +mm_flags_test (MMF_OOM_SKIP , current->signal->oom_mm)) + goto nomem; +__memcg_memory_event (mem_over_limit,MEMCG_MAX , allow_spinning); raised_max_event = true;
Greg Kroah-Hartman
maintainerPATCH 129/556 memcg: make the v1 soft limit knob inert
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shakeel Butt <[email protected]>
commit a3417097fb107cea3358b19bcbb4eb655fd67f8c upstream.
The v1 soft limit has been deprecated since v6.12 and nobody has reported depending on it. Start the removal by decoupling the interface from the
implementation: keep memory.soft_limit_in_bytes, but ignore writes to it and always report the maximum value on read similar to what memory.kmem.limit_in_bytes already does.
Writes are still parsed, so malformed input keeps returning -EINVAL. The knob now also behaves the same everywhere: it used to return -EOPNOTSUPP on PREEMPT_RT, where soft limit reclaim has always been disabled.
This also fixes the syzbot report linked below. Soft limit reclaim is the only caller that runs shrink_lruvec() from kswapd against a specific memcg, so it is the only way to reach lru_gen_shrink_lruvec() and in turn set_mm_walk(), which warns when called from kswapd.
--- Documentation/admin-guide/cgroup-v1/memory.rst | 49 +++---------------------- mm/memcontrol-v1.c | 43 +++++++++++++-------- 2 files changed, 32 insertions(+), 60 deletions(-)
Documentation/admin-guide/cgroup-v1/memory.rst +6 -43
@@ -47,7 +47,6 @@ Features: - pages are linked to per-memcg LRU exclusively, and there is no global LRU. - optionally, memory+swap usage can be accounted and limited. - hierarchical accounting - - soft limit - moving (recharging) account at moving a task is selectable. - usage threshold notifier - memory pressure notifier
@@ -76,10 +75,9 @@ Brief summary of control files. memory.memsw.failcnt show the number of memory+Swap hits limits memory.max_usage_in_bytes show max memory usage recorded memory.memsw.max_usage_in_bytes show max memory+Swap usage recorded - memory.soft_limit_in_bytes set/show soft limit of memory usage - This knob is not available on CONFIG_PREEMPT_RT systems. - This knob is deprecated and shouldn't be - used. + memory.soft_limit_in_bytes This knob is deprecated and has no effect. + Writes are ignored and reads always + return the maximum value. memory.stat show various statistics memory.use_hierarchy set/show hierarchical account enabled This knob is deprecated and shouldn't be
@@ -340,9 +338,6 @@ memory.kmem.usage_in_bytes, or in a sepa The main "kmem" counter is fed into the main counter, so kmem charges will also be visible from the user counter. -Currently no soft limit is implemented for kernel memory. It is future work -to trigger slab reclaim when those limits are reached. - 2.7.1 Current Kernel Memory resources accounted -----------------------------------------------
@@ -710,42 +705,10 @@ For compatibility reasons writing 1 to m THIS IS DEPRECATED! -Soft limits allow for greater sharing of memory. The idea behind soft limits -is to allow control groups to use as much of the memory as needed, provided - -a. There is no memory contention -b. They do not exceed their hard limit - -When the system detects memory contention or low memory, control groups -are pushed back to their soft limits. If the soft limit of each control -group is very high, they are pushed back as much as possible to make -sure that one control group does not starve the others of memory. - -Please note that soft limits is a best-effort feature; it comes with -no guarantees, but it does its best to make sure that when memory is -heavily contended for, memory is allocated based on the soft limit -hints/setup. Currently soft limit based reclaim is set up such that -it gets invoked from balance_pgdat (kswapd). - -7.1 Interface -------------- +Writing to memory.soft_limit_in_bytes has no effect and reading it will +always return the maximum value. -Soft limits can be setup by using the following commands (in this example we -assume a soft limit of 256 MiB):: - - # echo 256M > memory.soft_limit_in_bytes - -If we want to change this to 1G, we can at any time use:: - - # echo 1G > memory.soft_limit_in_bytes - -.. note:: - Soft limits take effect over a long period of time, since they involve - reclaiming memory for balancing between memory cgroups - -.. note:: - It is recommended to set the soft limit always below the hard limit, - otherwise the hard limit will take precedence. +Use memory.low and memory.min in cgroup v2 instead. .. _cgroup-v1-memory-move-charges:
mm/memcontrol-v1.c +26 -17
73 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 130/556 rtc: rzn1: Handle EPROBE_DEFER for optional pps interrupt
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lad Prabhakar <[email protected]>
commit 708546aa39560a11cf44c7ba99492c8395a6c2fb upstream.
Check for -EPROBE_DEFER from platform_get_irq_byname_optional() and handle the deferred probe request properly.
Although the "pps" interrupt is optional, an error code of -EPROBE_DEFER indicates that the interrupt subsystem is not yet ready. Intercept this specific error condition, assign it to the return value, and jump to the dis_runtime_pm label to avoid ignoring a valid probe deferral.
--- drivers/rtc/rtc-rzn1.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/rtc/rtc-rzn1.c +4 -0
@@ -464,6 +464,10 @@ static int rzn1_rtc_probe(struct platfor } irq =platform_get_irq_byname_optional (pdev,"pps" ); +if (irq == -EPROBE_DEFER ) { + ret = irq; + goto dis_runtime_pm; + }if (irq >=0 ) ret =devm_request_irq (&pdev->dev, irq, rzn1_rtc_1s_irq,0 ,"RZN1 RTC 1s" , rtc);
Greg Kroah-Hartman
maintainerPATCH 131/556 rtc: rzn1: Fix weekday underflow when alarm crosses month boundary
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lad Prabhakar <[email protected]>
commit 022a2839a52006531804a8db55d3228084400b48 upstream.
rzn1_rtc_set_alarm() calculates the alarm weekday from the difference between the alarm day and the current day of the month. When the alarm crosses a month boundary, this difference can become negative. Since days_ahead is unsigned, it underflows and results in an incorrect weekday being programmed into RZN1_RTC_ALW.
The RTC core already provides a fully populated struct rtc_time for the alarm, including the correct tm_wday. Use tm->tm_wday directly instead of recalculating the weekday from the day-of-month.
This avoids the underflow and ensures alarms scheduled across a month boundary use the correct weekday.
--- drivers/rtc/rtc-rzn1.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
drivers/rtc/rtc-rzn1.c +1 -6
@@ -260,7 +260,6 @@ static int rzn1_rtc_set_alarm(struct devstruct rzn1_rtc *rtc =dev_get_drvdata (dev);struct rtc_time *tm = &alrm->time, tm_now;unsigned long alarm, farest; -unsigned int days_ahead, wday;int ret; ret =rzn1_rtc_read_time (dev, &tm_now);
@@ -273,13 +272,9 @@ static int rzn1_rtc_set_alarm(struct devif (time_after (alarm, farest))return -ERANGE ; -/* Convert alarm day into week day */ - days_ahead = tm->tm_mday - tm_now.tm_mday; - wday = (tm_now.tm_wday + days_ahead) %7 ; -writel (bin2bcd (tm->tm_min), rtc->base +RZN1_RTC_ALM );writel (bin2bcd (tm->tm_hour), rtc->base +RZN1_RTC_ALH ); -writel (BIT (wday), rtc->base +RZN1_RTC_ALW ); +writel (BIT (tm->tm_wday), rtc->base +RZN1_RTC_ALW ); rtc->tm_alarm = alrm->time;
Greg Kroah-Hartman
maintainerPATCH 132/556 rtc: rzn1: Handle unset alarm weekday in rzn1_rtc_read_alarm
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lad Prabhakar <[email protected]>
commit 457b5dbce31209e65e1184716ed3af59cb1c0372 upstream.
RZN1_RTC_ALW is a weekday bitmask where bit N represents weekday N. When no alarm has been configured, the register has its power-on-reset value of zero.
rzn1_rtc_read_alarm() uses fls() to convert the weekday bitmask into a weekday number. When RZN1_RTC_ALW is zero, fls(0) returns zero and fls(wday) - 1 evaluates to -1. This invalid weekday is then used to calculate the alarm date and can either leave tm_wday set to -1 or produce a fabricated alarm date.
Treat a zero RZN1_RTC_ALW value as an unset alarm weekday and return without calculating the alarm date. Move reading RZN1_RTC_CTL1 before this check so that alrm->enabled is updated for both configured and unconfigured alarms.
--- drivers/rtc/rtc-rzn1.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
drivers/rtc/rtc-rzn1.c +12 -4
@@ -234,13 +234,24 @@ static int rzn1_rtc_read_alarm(struct deif (ret)return ret; + ctl1 =readl (rtc->base +RZN1_RTC_CTL1 ); + alrm->enabled = !!(ctl1 & (RZN1_RTC_CTL1_ALME |RZN1_RTC_CTL1_1SE )); + min =readl (rtc->base +RZN1_RTC_ALM ); hour =readl (rtc->base +RZN1_RTC_ALH ); - wday =readl (rtc->base +RZN1_RTC_ALW ); tm->tm_sec =0 ; tm->tm_min =bcd2bin (min); tm->tm_hour =bcd2bin (hour); + +/* +* If wday is zero, no bit is set in RZN1_RTC_ALW. This is the +* register's power-on reset value. +*/ + wday =readl (rtc->base +RZN1_RTC_ALW ); +if (!wday) +return 0 ; + delta_days = ((fls (wday) -1 ) - tm->tm_wday +7 ) %7 ; tm->tm_wday =fls (wday) -1 ;
@@ -249,9 +260,6 @@ static int rzn1_rtc_read_alarm(struct dertc_time64_to_tm (alarm, tm); } - ctl1 =readl (rtc->base +RZN1_RTC_CTL1 ); - alrm->enabled = !!(ctl1 & (RZN1_RTC_CTL1_ALME |RZN1_RTC_CTL1_1SE )); -return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 133/556 rtc: rzn1: Disable alarm interrupt before reprogramming alarm registers
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lad Prabhakar <[email protected]>
commit 51458d5b0a1cfb1b6013400abc95aadf16ed2a57 upstream.
rzn1_rtc_set_alarm() updates RZN1_RTC_ALM, RZN1_RTC_ALH and RZN1_RTC_ALW using separate MMIO writes without first disabling the alarm interrupt. If a previous alarm is still enabled, the interrupt can fire while the alarm registers contain a mixture of old and newly written values.
Fix this by disabling the alarm interrupt before reprogramming ALM, ALH and ALW with a call to rzn1_rtc_alarm_irq_enable().
--- drivers/rtc/rtc-rzn1.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/rtc/rtc-rzn1.c +5 -0
@@ -280,6 +280,11 @@ static int rzn1_rtc_set_alarm(struct devif (time_after (alarm, farest))return -ERANGE ; +/* Disable alarm interrupts before reprogramming the alarm. */ + ret =rzn1_rtc_alarm_irq_enable (dev,0 ); +if (ret) +return ret; +writel (bin2bcd (tm->tm_min), rtc->base +RZN1_RTC_ALM );writel (bin2bcd (tm->tm_hour), rtc->base +RZN1_RTC_ALH );writel (BIT (tm->tm_wday), rtc->base +RZN1_RTC_ALW );
Greg Kroah-Hartman
maintainerPATCH 134/556 perf/x86/intel: Fix kernel address leakages in LBR stack
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dapeng Mi <[email protected]>
commit e2b0575900ff72aa82748af96e7bd564ade5157a upstream.
Before Arch LBR gained CPL filtering support, a user-only branch stack could still contain kernel addresses. As a result, kernel branch records may be exposed to user space even when PERF_SAMPLE_BRANCH_USER is requested.
For example, on Intel Tiger Lake, the following command can still report SYSRET/ERET entries with kernel-space from addresses:
$ ./perf record -e cycles:p -o - --branch-filter any,save_type,u -- \
./perf bench syscall basic --loop 1000 | \
./perf script -i - --fields brstack|tr ' ' '\n'| \
grep -E '0x[89a-f][0-9a-f]{15}' Total time: 0.000 [sec]
0.219000 usecs/op
4,566,210 ops/sec[ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.551 MB - ] 0xffffffff93c001c8/0x7f12a2b1d647/P/-/-/16959/SYSRET/- 0xffffffff93c001c8/0x7f12a2b1d5c2/P/-/-/17535/SYSRET/- 0xffffffff93c01928/0x7f12a2861000/P/-/-/6719/ERET/- 0xffffffff93c01928/0x7f12a297a000/P/-/-/8575/ERET/-
The problem is that intel_pmu_lbr_filter() does not fully validate the privilege level of sampled entries. It filters some mismatches based on the branch type and the to address, but it does not reject entries whose from address violates the requested branch privilege filter.
Fix this by extending software filtering to validate both from and to addresses against br_sel. Any LBR entry contains kernel address does not match the requested user filter is dropped. This prevents kernel addresses from appearing in user-only branch stacks.
--- arch/x86/events/intel/lbr.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-)
arch/x86/events/intel/lbr.c +9 -3
@@ -1213,7 +1213,7 @@ intel_pmu_lbr_filter(struct cpu_hw_event {u64 from, to;int br_sel = cpuc->br_sel; -int i, j, type, to_plm; +int i, j, type, from_plm, to_plm;bool compress = false;/* if sampling all branches, then nothing to filter */
@@ -1245,8 +1245,14 @@ intel_pmu_lbr_filter(struct cpu_hw_event type |=X86_BR_NO_TX ; } -/* if type does not correspond, then discard */ -if (type ==X86_BR_NONE || (br_sel & type) != type) { + from_plm =kernel_ip (from) ?X86_BR_KERNEL :X86_BR_USER ; +/* +* If type does not correspond, then discard. +* Specifically reject entries whose from address is in +* kernel space when only X86_BR_USER is requested. +*/ +if (type ==X86_BR_NONE || (br_sel & type) != type || + (!(br_sel &X86_BR_KERNEL ) && (from_plm &X86_BR_KERNEL ))) { cpuc->lbr_entries[i].from =0 ; compress = true; }
Greg Kroah-Hartman
maintainerPATCH 135/556 perf/x86/intel: Remove anythread_deprecated bit from perf_capabilities
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dapeng Mi <[email protected]>
commit 8767b4d73018bd3143f4c55b672064fad292f11b upstream.
AnyThread mode deprecation is enumerated by CPUID.0AH:EDX[15] instead of PERF_CAPABILITIES MSR. It's not a good practice to define a bit to represent "anythread deprecation" in perf_capabilities. It leads to the anythread_deprecated bit could be overwritten by the real value of PERF_CAPABILITIES MSR, just like the below code in update_pmu_cap() does.
if (!intel_pmu_broken_perf_cap()) {
/* Perf Metric (Bit 15) and PEBS via PT (Bit 16) are hybrid enumeration */
rdmsrq(MSR_IA32_PERF_CAPABILITIES, hybrid(pmu, intel_cap).capabilities);
}It leads to the anythread_deprecated bit is cleared to 0 and the "any" attribute is incorrectly shown in the /sys/devices/cpu/format/ folder on these support Perfmon v6 platforms, like Clearwater Forest.
$ grep . /sys/devices/cpu/format/* /sys/devices/cpu/format/acr_mask:config2:0-63 /sys/devices/cpu/format/any:config:21 /sys/devices/cpu/format/cmask:config:24-31
So remove the anythread_deprecated bit from perf_capabilities structure and directly depends on CPUID.0AH:EDX[15] to judge if anythread is deprecated.
--- arch/x86/events/intel/core.c | 10 +++------- arch/x86/events/perf_event.h | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-)
arch/x86/events/intel/core.c +3 -7
@@ -7947,12 +7947,6 @@ __init int intel_pmu_init(void)x86_add_quirk (intel_arch_events_quirk);/* Install first, so it runs last */ -if (version >=5 ) { - x86_pmu.intel_cap.anythread_deprecated = edx.split.anythread_deprecated; -if (x86_pmu.intel_cap.anythread_deprecated) -pr_cont (" AnyThread deprecated, " ); - } -/* The perf side of core PMU is ready to support the mediated vPMU. */ x86_get_pmu (smp_processor_id ())->capabilities |=PERF_PMU_CAP_MEDIATED_VPMU ;
@@ -8829,8 +8823,10 @@ __init int intel_pmu_init(void) &x86_pmu.intel_ctrl);/* AnyThread may be deprecated on arch perfmon v5 or later */ -if (x86_pmu.intel_cap.anythread_deprecated) +if (version >=5 && edx.split.anythread_deprecated) { x86_pmu.format_attrs = intel_arch_formats_attr; +pr_cont ("AnyThread deprecated, " ); + }intel_pmu_check_event_constraints_all (NULL );
arch/x86/events/perf_event.h +1 -1
@@ -668,7 +668,7 @@ union perf_capabilities { u64 perf_metrics:1; u64 pebs_output_pt_available:1; u64 pebs_timing_info:1; - u64 anythread_deprecated:1; + u64 __reserved:1; u64 rdpmc_metrics_clear:1; };u64 capabilities;
Greg Kroah-Hartman
maintainerPATCH 136/556 perf trace: Factor out BPF loop body
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Viktor Malik <[email protected]>
commit acff3e1a9cc29a6a039b76b81a438c56016bc0e3 upstream.
The BPF program in augmented_raw_syscalls uses a for loop to iterate all syscall arguments. The loop body is quite complex and often poses problems for the BPF verifier. As a preparation step for addressing this issue, factor out the loop body into a separate function.
--- tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c | 128 ++++++++++-------- 1 file changed, 73 insertions(+), 55 deletions(-)
tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c +73 -55
@@ -429,15 +429,80 @@ static bool pid_filter__has(struct pids_return bpf_map_lookup_elem (pids, &pid) !=NULL ; } +/* +* Determine what type of argument and how many bytes to read from user space, using the +* value in the beauty_map. This is the relation of parameter type and its corresponding +* value in the beauty map, and how many bytes we read eventually: +* +* string: 1 -> size of string +* struct: size of struct -> size of struct +* buffer: -1 * (index of paired len) -> value of paired len (maximum: TRACE_AUG_MAX_BUF) +*/ +static inline int augment_arg (struct syscall_enter_args *args,int i, +unsigned int *beauty_map, +struct augmented_arg *payload_offset) +{ +int index, value_size =sizeof (struct augmented_arg ) - offsetof(struct augmented_arg , value); +s64 aug_size, size; +bool augmented; +void *arg; + + arg = (void *)args->args[i]; + augmented = false; + size = beauty_map[i]; + aug_size = size;/* size of the augmented data read from user space */ + +if (size ==0 || arg ==NULL ) +return 0 ; + +if (size ==1 ) {/* string */ + aug_size =bpf_probe_read_user_str (payload_offset->value, value_size, arg); +/* minimum of 0 to pass the verifier */ +if (aug_size <0 ) + aug_size =0 ; + + augmented = true; + }else if (size >0 && size <= value_size) {/* struct */ +if (!bpf_probe_read_user (payload_offset->value, size, arg)) + augmented = true; + }else if ((int )size <0 && size >=-6 ) {/* buffer */ + index = -(size +1 ); +barrier_var (index);// Prevent clang (noticed with v18) from removing the &= 7 trick. + index &=7 ;// Satisfy the bounds checking with the verifier in some kernels. + aug_size = args->args[index] >TRACE_AUG_MAX_BUF ?TRACE_AUG_MAX_BUF : args->args[index]; + +if (aug_size >0 ) { +if (!bpf_probe_read_user (payload_offset->value, aug_size, arg)) + augmented = true; + } + } + +/* Augmented data size is limited to sizeof(augmented_arg->unnamed union with value field) */ +if (aug_size > value_size) + aug_size = value_size; + +/* write data to payload */ +if (augmented) { +int written = offsetof(struct augmented_arg , value) + aug_size; + +if (written <0 || written >sizeof (struct augmented_arg )) +return -1 ; + + payload_offset->size = aug_size; +return written; + } + +return 0 ; +} +static int augment_sys_enter (void *ctx,struct syscall_enter_args *args) { -bool augmented, do_output = false; -int zero =0 , index, value_size =sizeof (struct augmented_arg ) - offsetof(struct augmented_arg , value); +bool do_output = false; +int zero =0 , written;u64 output =0 ;/* has to be u64, otherwise it won't pass the verifier */ -s64 aug_size, size;unsigned int nr, *beauty_map;struct beauty_payload_enter *payload; -void *arg, *payload_offset; +void *payload_offset;/* fall back to do predefined tail call */ if (args ==NULL )
@@ -457,58 +522,11 @@ static int augment_sys_enter(void *ctx,/* copy the sys_enter header, which has the syscall_nr */ __builtin_memcpy (&payload->args, args,sizeof (struct syscall_enter_args )); -/* -* Determine what type of argument and how many bytes to read from user space, using the -* value in the beauty_map. This is the relation of parameter type and its corresponding -* value in the beauty map, and how many bytes we read eventually: -* -* string: 1 -> size of string -* struct: size of struct -> size of struct -* buffer: -1 * (index of paired len) -> value of paired len (maximum: TRACE_AUG_MAX_BUF) -*/ for (int i =0 ; i <6 ; i++) { - arg = (void *)args->args[i]; - augmented = false; - size = beauty_map[i]; - aug_size = size;/* size of the augmented data read from user space */ - -if (size ==0 || arg ==NULL ) -continue ; - -if (size ==1 ) {/* string */ - aug_size =bpf_probe_read_user_str (((struct augmented_arg *)payload_offset)->value, value_size, arg); -/* minimum of 0 to pass the verifier */ -if (aug_size <0 ) - aug_size =0 ; - - augmented = true; - }else if (size >0 && size <= value_size) {/* struct */ -if (!bpf_probe_read_user (((struct augmented_arg *)payload_offset)->value, size, arg)) - augmented = true; - }else if ((int )size <0 && size >=-6 ) {/* buffer */ - index = -(size +1 ); -barrier_var (index);// Prevent clang (noticed with v18) from removing the &= 7 trick. - index &=7 ;// Satisfy the bounds checking with the verifier in some kernels. - aug_size = args->args[index] >TRACE_AUG_MAX_BUF ?TRACE_AUG_MAX_BUF : args->args[index]; - -if (aug_size >0 ) { -if (!bpf_probe_read_user (((struct augmented_arg *)payload_offset)->value, aug_size, arg)) - augmented = true; - } - } - -/* Augmented data size is limited to sizeof(augmented_arg->unnamed union with value field) */ -if (aug_size > value_size) - aug_size = value_size; - -/* write data to payload */ -if (augmented) { -int written = offsetof(struct augmented_arg , value) + aug_size; - -if (written <0 || written >sizeof (struct augmented_arg )) -return 1 ; - - ((struct augmented_arg *)payload_offset)->size = aug_size; + written =augment_arg (args, i, beauty_map, (struct augmented_arg *)payload_offset); +if (written <0 ) +return 1 ; +if (written >0 ) { output += written; payload_offset += written; do_output = true;
Greg Kroah-Hartman
maintainerPATCH 137/556 perf trace: Refactor augmented_raw_syscalls using bpf_for
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Viktor Malik <[email protected]>
commit ea6992784d65ef2c01f3525217dbf3a44afa9917 upstream.
The loop for processing syscall args in augment_raw_syscalls has a history of breaking with Clang updates, see e.g. commit 013eb043f37b ("perf trace: Fix BPF loading failure (-E2BIG)") from Clang 15 to 16.
Now, a similar thing happened between Clang 21 and 22. While the issue is mitigated on the main line by a recent verifier update, it remains broken on the 6.12 and 6.18 stable branches:
[linux-6.18.y]# sudo perf trace true
libbpf: prog 'sys_enter': BPF program load failed: -E2BIG
libbpf: prog 'sys_enter': -- BEGIN PROG LOAD LOG --
[...]
BPF program is too large. Processed 1000001 insn
processed 1000001 insns (limit 1000000) max_states_per_insn 40 total_states 37941 peak_states 232 mark_read 0 -- END PROG LOAD LOG --
libbpf: prog 'sys_enter': failed to load: -E2BIG
libbpf: failed to load object 'augmented_raw_syscalls_bpf'
libbpf: failed to load BPF skeleton 'augmented_raw_syscalls_bpf': -E2BIG
Error: failed to get syscall or beauty map fd
[...]
The reason is that the loop is quite complex and the BPF verifier often struggles to prove that it terminates.
Fix the issue by replacing the standard for loop with the bpf_for macro, which uses a numeric BPF iterator. This should prevent future breakages of this kind since the verifier has a much easier job proving that the loop terminates.
Small adjustments were necessary for the loop to make it work. The main problem is that the verifier sometimes has problems with bpf_for loops that use a carry-over state, such as the payload_offset and output vars here, since the verifier tries to track their values too precisely and cannot prove loop convergence. To resolve the issue, we (1) explicitly recompute payload_offset in every iteration and (2) use a trick with adding a global zero to output to help the verifier forget its precise state and use a range instead.
Finally, to keep backwards compatibility with older kernel versions that don't have bpf_for (i.e. numeric iterators), fall back to standard loop.
--- tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c | 47 +++++++++++++----- 1 file changed, 35 insertions(+), 12 deletions(-)
tools/perf/util/bpf_skel/augmented_raw_syscalls.bpf.c +35 -12
@@ -429,6 +429,8 @@ static bool pid_filter__has(struct pids_return bpf_map_lookup_elem (pids, &pid) !=NULL ; } +u64 ZERO =0 ; +/* * Determine what type of argument and how many bytes to read from user space, using the * value in the beauty_map. This is the relation of parameter type and its corresponding
@@ -440,9 +442,10 @@ static bool pid_filter__has(struct pids_*/ static inline int augment_arg (struct syscall_enter_args *args,int i,unsigned int *beauty_map, -struct augmented_arg *payload_offset) +struct beauty_payload_enter *payload,u64 offset) {int index, value_size =sizeof (struct augmented_arg ) - offsetof(struct augmented_arg , value); +struct augmented_arg *payload_offset;s64 aug_size, size;bool augmented;void *arg;
@@ -455,6 +458,12 @@ static inline int augment_arg(struct sysif (size ==0 || arg ==NULL )return 0 ; +/* bounds check for the verifier */ +if (offset >sizeof (payload->aug_args) -sizeof (payload->aug_args[0 ])) +return -1 ; +barrier_var (offset); + payload_offset = (struct augmented_arg *)((void *)&payload->aug_args + offset); +if (size ==1 ) {/* string */ aug_size =bpf_probe_read_user_str (payload_offset->value, value_size, arg);/* minimum of 0 to pass the verifier */
@@ -498,11 +507,10 @@ static inline int augment_arg(struct sysstatic int augment_sys_enter (void *ctx,struct syscall_enter_args *args) {bool do_output = false; -int zero =0 , written; +int i, zero =0 , written;u64 output =0 ;/* has to be u64, otherwise it won't pass the verifier */ unsigned int nr, *beauty_map;struct beauty_payload_enter *payload; -void *payload_offset;/* fall back to do predefined tail call */ if (args ==NULL )
@@ -514,7 +522,6 @@ static int augment_sys_enter(void *ctx,/* set up payload for output */ payload =bpf_map_lookup_elem (&beauty_payload_enter_map, &zero); - payload_offset = (void *)&payload->aug_args;if (beauty_map ==NULL || payload ==NULL )return 1 ;
@@ -522,14 +529,30 @@ static int augment_sys_enter(void *ctx,/* copy the sys_enter header, which has the syscall_nr */ __builtin_memcpy (&payload->args, args,sizeof (struct syscall_enter_args )); -for (int i =0 ; i <6 ; i++) { - written =augment_arg (args, i, beauty_map, (struct augmented_arg *)payload_offset); -if (written <0 ) -return 1 ; -if (written >0 ) { - output += written; - payload_offset += written; - do_output = true; +if (bpf_ksym_exists (bpf_iter_num_new)) { + bpf_for(i, 0, 6) { + written =augment_arg (args, i, beauty_map, payload, output); +if (written <0 ) +return 1 ; +if (written >0 ) { + output += written; +/* +* guide the verifier to forget range of `output`, which +* helps to prove convergence of the loop +*/ + output +=ZERO ; + do_output = true; + } + } + }else { +for (i =0 ; i <6 ; i++) { + written =augment_arg (args, i, beauty_map, payload, output); +if (written <0 ) +return 1 ; +if (written >0 ) { + output += written; + do_output = true; + } } }
Greg Kroah-Hartman
maintainerPATCH 138/556 perf hisi-ptt: Fix PTT trace TLP header parsing
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sizhe Liu <[email protected]>
commit 2b8a2e5d424f0b3369054305d0bf6a5b9faee6c1 upstream.
TLP Headers traced by HiSilicon PCIe tune and trace device (PTT) in 4DW format are shown in the document as below:
bits [31:30] [ 29:25 ][24][23][22][21][ 20:11 ][ 10:0 ]
|-----|---------|---|---|---|---|-------------|-------------|
DW0 [ Fmt ][ Type ][T9][T8][TH][SO][ Length ][ Time ]
DW1 [ Header DW1 ]
DW2 [ Header DW2 ]
DW3 [ Header DW3 ]Problem:
The DW0 bit field layout of the hisi_ptt_4dw union does not match the actual bit ordering in little-endian memory, causing incorrect field decoding.
Test on Kunpeng 930 SOC, generating data flow with iperf commands:
- server side:
iperf -s
- client side:
iperf -c $ip_addr -t 30
Trace the TLP headers with hisi_ptt on server side at the same time:
perf record -e hisi_ptt12_0/type=4,filter=0x05101,direction=2,format=0/ \
--max-size 50M -o perf.data &
The trace aims to capture completion TLPs, learn more in the document:
https://docs.kernel.org/trace/hisi-ptt.html
Decode perf.data with hisi_ptt decoder:
perf report -D
The hisi_ptt decoder produces the following result:
[...perf headers and other information]
. ... HISI PTT data: size 8388608 bytes
. 00000000: 68 87 20 94 Format 3 Type 1a T9 0 T8 1 TH 1 SO 1 Length 10 Time 4a1 . 00000004: 40 00 00 00 Header DW1 . 00000008: 40 00 01 51 Header DW2 . 0000000c: 00 00 00 00 Header DW3
[...other hisi_ptt TLP headers]
According to PCIe r5.0 sec 2.2.1, the Fmt & Type of Cpl/CplD is supposed to be 8b'00001010' / 8b'01001010'
However, the Format & Type decoder analyzing result is 8b'01111010'. It does not match field encodings of any TLP.
Correct decoder result should be:
[...perf headers and other information]
. ... HISI PTT data: size 8388608 bytes
. 00000000: 94 20 87 68 Format 2 Type a T9 0 T8 0 TH 0 SO 1 Length 10 Time 768 . 00000004: 00 00 00 40 Header DW1 . 00000008: 51 01 00 40 Header DW2 . 0000000c: 00 00 00 00 Header DW3
[...other hisi_ptt TLP headers]
To solve the problem:
1. Drop the union and C bitfield struct, store the raw DW value in a plain uint32_t, and extract the fields with FIELD_GET() against GENMASK/BIT masks declared in the header so they can be reused by other translation units. The masks are portable across endianness and compilers.
2. Print all DW hex values in big-endian byte order for readability, matching the bit field layout shown in the 4DW format diagram.
3. Read the DW value with get_unaligned_le32() instead of an unaligned pointer cast, avoiding both strict-aliasing violations and alignment hazards on hosts that do not support unaligned access.
--- Documentation/trace/hisi-ptt.rst | 28 ++++----- tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c | 47 ++++++++-------- tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.h | 12 ++++ 3 files changed, 50 insertions(+), 37 deletions(-)
Documentation/trace/hisi-ptt.rst +14 -14
@@ -285,20 +285,20 @@ according to the format described previo [...perf headers and other information] . ... HISI PTT data: size 4194304 bytes . 00000000: 00 00 00 00 Prefix - . 00000004: 01 00 00 60 Header DW0 - . 00000008: 0f 1e 00 01 Header DW1 - . 0000000c: 04 00 00 00 Header DW2 - . 00000010: 40 00 81 02 Header DW3 - . 00000014: 33 c0 04 00 Time + . 00000004: 60 00 00 01 Header DW0 + . 00000008: 01 00 1e 0f Header DW1 + . 0000000c: 00 00 00 04 Header DW2 + . 00000010: 02 81 00 40 Header DW3 + . 00000014: 00 04 c0 33 Time . 00000020: 00 00 00 00 Prefix - . 00000024: 01 00 00 60 Header DW0 - . 00000028: 0f 1e 00 01 Header DW1 - . 0000002c: 04 00 00 00 Header DW2 - . 00000030: 40 00 81 02 Header DW3 - . 00000034: 02 00 00 00 Time + . 00000024: 60 00 00 01 Header DW0 + . 00000028: 01 00 1e 0f Header DW1 + . 0000002c: 00 00 00 04 Header DW2 + . 00000030: 02 81 00 40 Header DW3 + . 00000034: 00 00 00 02 Time . 00000040: 00 00 00 00 Prefix - . 00000044: 01 00 00 60 Header DW0 - . 00000048: 0f 1e 00 01 Header DW1 - . 0000004c: 04 00 00 00 Header DW2 - . 00000050: 40 00 81 02 Header DW3 + . 00000044: 60 00 00 01 Header DW0 + . 00000048: 01 00 1e 0f Header DW1 + . 0000004c: 00 00 00 04 Header DW2 + . 00000050: 02 81 00 40 Header DW3 [...]
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.c +24 -23
81 lines not on this page · raw message
tools/perf/util/hisi-ptt-decoder/hisi-ptt-pkt-decoder.h +12 -0
@@ -9,12 +9,24 @@#include <stddef.h> #include <stdint.h> +#include <linux/bits.h> +#include <linux/bitfield.h> #define HISI_PTT_8DW_CHECK_MASK GENMASK(31, 11)#define HISI_PTT_IS_8DW_PKT GENMASK(31, 11)#define HISI_PTT_MAX_SPACE_LEN 10#define HISI_PTT_FIELD_LENTH 4 +/* Header DW0 fields for 4DW format */ +#define HISI_PTT_HEAD0_4DW_TIME GENMASK_U32(10, 0) +#define HISI_PTT_HEAD0_4DW_LEN GENMASK_U32(20, 11) +#define HISI_PTT_HEAD0_4DW_SO BIT_U32(21) +#define HISI_PTT_HEAD0_4DW_TH BIT_U32(22) +#define HISI_PTT_HEAD0_4DW_T8 BIT_U32(23) +#define HISI_PTT_HEAD0_4DW_T9 BIT_U32(24) +#define HISI_PTT_HEAD0_4DW_TYPE GENMASK_U32(29, 25) +#define HISI_PTT_HEAD0_4DW_FORMAT GENMASK_U32(31, 30) +enum hisi_ptt_pkt_type {HISI_PTT_4DW_PKT ,HISI_PTT_8DW_PKT ,
Greg Kroah-Hartman
maintainerPATCH 139/556 perf build: Add clang and rust target flags for LoongArch
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haiyong Sun <[email protected]>
commit a2628ce4ddb6873e35380a42396d17a66e704a1a upstream.
Add missing CLANG_TARGET_FLAGS_loongarch and RUST_TARGET_FLAGS_loongarch so that perf can be built with clang and enable rust cross compilation.
--- tools/perf/Makefile.config | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/Makefile.config +2 -0
@@ -27,6 +27,7 @@ CFLAGS += -fno-strict-aliasing ifeq ($(CC_NO_CLANG), 0) CLANG_TARGET_FLAGS_arm := arm-linux-gnueabi CLANG_TARGET_FLAGS_arm64 := aarch64-linux-gnu + CLANG_TARGET_FLAGS_loongarch := loongarch64-linux-gnu CLANG_TARGET_FLAGS_m68k := m68k-linux-gnu CLANG_TARGET_FLAGS_mips := mipsel-linux-gnu CLANG_TARGET_FLAGS_powerpc := powerpc64le-linux-gnu
@@ -1142,6 +1143,7 @@ ifndef NO_RUST ifneq ($(CROSS_COMPILE),) RUST_TARGET_FLAGS_arm := arm-unknown-linux-gnueabi RUST_TARGET_FLAGS_arm64 := aarch64-unknown-linux-gnu + RUST_TARGET_FLAGS_loongarch := loongarch64-unknown-linux-gnu RUST_TARGET_FLAGS_m68k := m68k-unknown-linux-gnu RUST_TARGET_FLAGS_mips := mipsel-unknown-linux-gnu RUST_TARGET_FLAGS_powerpc := powerpc64le-unknown-linux-gnu
Greg Kroah-Hartman
maintainerPATCH 140/556 perf: Fix use-after-free when perf mmap() revival races with the last munmap()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yilin Zhang <[email protected]>
commit 58a8108bc73de0740d5b88150465d6690ea5f85f upstream.
perf_mmap_close() drops rb->mmap_count *without* holding event->mmap_mutex (the refcount_dec_and_test() right before the refcount_dec_and_mutex_lock() of event->mmap_count). A concurrent perf_mmap_rb() can slot its entire "revival" path into that window (perf_mmap holds event->mmap_mutex for its whole duration, including rb_alloc):
munmap side (perf_mmap_close) mmap side (perf_mmap_rb)
----------------------------------- --------------------------------
rb->mmap_count 1 -> 0 (no lock) (holds event->mmap_mutex)
inc_not_zero(rb->mmap_count) fails
ring_buffer_attach(event, NULL)
rb_alloc() + attach new rb
refcount_set(&event->mmap_count, 1) lock; event->mmap_count 1 -> 0
ring_buffer_attach(event, NULL)
ring_buffer_put() -> frees the *new* rb
The revival's refcount_set(&event->mmap_count, 1) is an invisible 1 -> 1 write: the close frees the just-revived buffer although the other process still has it mapped -- a page-level use-after-free allowing local privilege escalation to root by any unprivileged user (default kernel.perf_event_paranoid=2).
Swap the order of the two counter updates: event->mmap_count is dropped first via refcount_dec_and_mutex_lock(), so its 1 -> 0 transition and the ring_buffer_attach() stay serialized with perf_mmap(). rb->mmap_count == 0 then implies every event using the buffer is detached already, so the result of the rb->mmap_count drop can gate the remaining teardown directly and detach_rest is no longer needed.
An earlier fix for this race from Kyle Zeng and David Lee takes event->mmap_mutex around both counter updates [0]; here the not-last close stays lockless.
--- kernel/events/core.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
kernel/events/core.c +10 -10
@@ -7029,7 +7029,6 @@ static void perf_mmap_close(struct vm_armapped_f unmapped =get_mapped (event, event_unmapped);struct perf_buffer *rb =ring_buffer_get (event);struct user_struct *mmap_user = rb->mmap_user; -bool detach_rest = false;/* FIXIES vs perf_pmu_unregister() */ if (unmapped)
@@ -7060,17 +7059,18 @@ static void perf_mmap_close(struct vm_armutex_unlock (&rb->aux_mutex); } -if (refcount_dec_and_test (&rb->mmap_count)) - detach_rest = true; - -if (!refcount_dec_and_mutex_lock (&event->mmap_count, &event->mmap_mutex)) - goto out_put; - -ring_buffer_attach (event,NULL ); -mutex_unlock (&event->mmap_mutex); +/* +* Drop references in reverse order of perf_mmap() to prevent +* rb revival after rb->mmap_count reaches zero. +*/ +if (refcount_dec_and_mutex_lock (&event->mmap_count, + &event->mmap_mutex)) { +ring_buffer_attach (event,NULL ); +mutex_unlock (&event->mmap_mutex); + }/* If there's still other mmap()s of this buffer, we're done. */ -if (!detach_rest) +if (!refcount_dec_and_test (&rb->mmap_count)) goto out_put;/*
Greg Kroah-Hartman
maintainerPATCH 141/556 i2c: designware: Enable interrupt mask workaround for HJMC3001
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hongbo Yao <[email protected]>
commit 77549d01edecc20da73c8599e14648877198ce9b upstream.
On HJMicro ARM64 servers, the DesignWare I2C controller does not retrigger a pending interrupt if the interrupt status changes after the current status bits have been cleared.
The issue is exposed under heavy system load when the corresponding SPI is routed across sockets to a core in the remote socket. The interrupt is then lost and the I2C transfer times out.
Enable ACCESS_INTR_MASK for HJMC3001. This toggles DW_IC_INTR_MASK before returning from the interrupt handler and retriggers any pending interrupt.
--- drivers/i2c/busses/i2c-designware-platdrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/i2c/busses/i2c-designware-platdrv.c +1 -1
@@ -272,7 +272,7 @@ static const struct acpi_device_id dw_i2 { "HISI02A1", 0 }, { "HISI02A2", 0 }, { "HISI02A3", 0 }, - { "HJMC3001", 0 }, + { "HJMC3001", ACCESS_INTR_MASK }, { "HYGO0010", ACCESS_INTR_MASK }, { "INT33C2", 0 }, { "INT33C3", 0 },
Greg Kroah-Hartman
maintainerPATCH 142/556 i2c: qcom-geni: update frequency table to fix timing parameters
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kathiravan Thirumoorthy <[email protected]>
commit a4f3fbccb65de757569686baaf2b72e329096aba upstream.
In IPQ5424, to meet the setup and hold timing requirements in the standard mode, update the frequency table with the values recommended by HW design team.
Also remove the stray space in the I2C_MAX_FAST_MODE_FREQ entry.
--- drivers/i2c/busses/i2c-qcom-geni.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/i2c/busses/i2c-qcom-geni.c +2 -2
@@ -177,8 +177,8 @@ static const struct geni_i2c_clk_fld gen/* source_clock = 32 MHz */ static const struct geni_i2c_clk_fld geni_i2c_clk_map_32mhz[] = { - {I2C_MAX_STANDARD_MODE_FREQ ,8 ,14 ,18 ,38 }, - {I2C_MAX_FAST_MODE_FREQ ,4 ,3 ,9 ,19 }, + {I2C_MAX_STANDARD_MODE_FREQ ,12 ,9 ,10 ,26 }, + {I2C_MAX_FAST_MODE_FREQ ,4 ,3 ,9 ,19 }, {I2C_MAX_FAST_MODE_PLUS_FREQ ,2 ,3 ,5 ,15 }, {} };
Greg Kroah-Hartman
maintainerPATCH 143/556 i2c: core: fix debugfs UAF on adapter removal
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vasileios Almpanis <[email protected]>
commit b15b548d52b43ba8ac4652bc2c7244a8dd1e9622 upstream.
i2c_del_adapter() frees the adapter's debugfs directory before it unregisters the adapter device, but the new_device sysfs attribute stays writable until device_del(). A write racing with removal still reaches i2c_device_probe(), which passes the freed adap->debugfs to debugfs_create_dir() as the new client's parent:
BUG: KASAN: slab-use-after-free in lookup_noperm_common+0x407/0x430 Read of size 4 at addr ffff88803ef87810 by task syz.0.61/6090 lookup_noperm_common+0x407/0x430 simple_start_creating+0x9c/0x110 debugfs_start_creating+0xdb/0x1a0 debugfs_create_dir+0x24/0x350 i2c_device_probe+0x814/0xbf0
It's technically possible to create a client after i2c_deregister_clients has run. That client will never be unregistered and make wait_for_completion hang.
Close the window by removing the new_device attribute at the start of i2c_del_adapter(). device_remove_file() will drain any clients left.
--- drivers/i2c/i2c-core-base.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/i2c/i2c-core-base.c +6 -0
@@ -1815,6 +1815,12 @@ void i2c_del_adapter(struct i2c_adapterreturn ; } +/* +* This drains any in-flight writers, so all +* clients will be caught by i2c_deregister_clients(). +*/ +device_remove_file (&adap->dev, &dev_attr_new_device); +i2c_acpi_remove_space_handler (adap);i2c_deregister_clients (adap);
Greg Kroah-Hartman
maintainerPATCH 144/556 i2c: mux: Fix channel node leak on adapter add failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ahmad Byagowi <[email protected]>
commit 385c7af4e3b95d0769fd211831674e83b16a2ebf upstream.
i2c_mux_add_adapter() takes a reference to the Device Tree channel node before registering the new adapter. If adapter registration fails, the error path frees the private data without dropping that reference.
Release the channel node before freeing the private data.
--- drivers/i2c/i2c-mux.c | 1 + 1 file changed, 1 insertion(+)
drivers/i2c/i2c-mux.c +1 -0
@@ -408,6 +408,7 @@ int i2c_mux_add_adapter(struct i2c_mux_creturn 0 ; err_free_priv: +of_node_put (priv->adap.dev.of_node);kfree (priv);return ret; }
Greg Kroah-Hartman
maintainerPATCH 145/556 i2c: qcom-cci: fix autosuspend cleanup
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Guangshuo Li <[email protected]>
commit f98d4986482151a835b521a734722fe8dc5ca37d upstream.
cci_probe() calls pm_runtime_use_autosuspend(), but the remove path does not call the matching pm_runtime_dont_use_autosuspend() before disabling runtime PM.
If the autosuspend delay is set to a negative value while autosuspend is enabled, the runtime PM core increments usage_count to prevent runtime suspend. Without undoing the autosuspend setting during teardown, this reference is not dropped and usage_count remains unbalanced.
Use devm_pm_runtime_set_active_enabled() to manage the runtime PM state. Its managed cleanup disables autosuspend and runtime PM and restores the suspended state on probe failure and driver removal. Remove the now redundant manual runtime PM cleanup.
This issue was found by manual code inspection.
--- drivers/i2c/busses/i2c-qcom-cci.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/i2c/busses/i2c-qcom-cci.c +4 -7
@@ -595,9 +595,11 @@ static int cci_probe(struct platform_dev goto disable_clocks;pm_runtime_set_autosuspend_delay (dev,MSEC_PER_SEC ); + ret =devm_pm_runtime_set_active_enabled (dev); +if (ret) + goto disable_clocks; +pm_runtime_use_autosuspend (dev); -pm_runtime_set_active (dev); -pm_runtime_enable (dev);for (i =0 ; i < cci->data->num_masters; i++) {if (!cci->master[i].cci)
@@ -613,8 +615,6 @@ static int cci_probe(struct platform_devreturn 0 ; error_i2c: -pm_runtime_disable (dev); -pm_runtime_dont_use_autosuspend (dev);for (--i ; i >=0 ; i--) {if (cci->master[i].cci) {
@@ -640,9 +640,6 @@ static void cci_remove(struct platform_dcci_halt (cci, i); } } - -pm_runtime_disable (&pdev->dev); -pm_runtime_set_suspended (&pdev->dev); }static const struct cci_data cci_v1_data = {
Greg Kroah-Hartman
maintainerPATCH 146/556 arm64: mm: Fix the lockless page-table walk in show_pte()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Karl Mehltretter <[email protected]>
commit a77644d009dece1104b6fcc6e322b0e4503db0d6 upstream.
show_pte() walks page tables locklessly and can run with interrupts enabled. A concurrent teardown can free a table page while it is being walked. It can also clear a parent entry after show_pte() checked it; the regular pXd_offset() helpers then reread the cleared entry and can derive a bogus lower-level pointer and fault again.
Use the lockless offset helpers with the saved parent entries, as gup_fast() does, and pass the saved PMD to pte_offset_map().
For task page tables, arm64 selects MMU_GATHER_RCU_TABLE_FREE. Disable local interrupts around the walk to hold off RCU-deferred table frees and block the tlb_remove_table_sync_one() IPI until the walk is finished.
Place the IRQ guard after the header print. This does not make the output a consistent snapshot, but prevents the task page-table walk from dereferencing a released table page or deriving a pointer from a different parent value.
--- arch/arm64/mm/fault.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
arch/arm64/mm/fault.c +8 -4
@@ -16,6 +16,7 @@#include <linux/mm.h> #include <linux/hardirq.h> #include <linux/init.h> +#include <linux/irqflags.h> #include <linux/kasan.h> #include <linux/kprobes.h> #include <linux/uaccess.h>
@@ -154,6 +155,9 @@ static void show_pte(unsigned long addr)pr_alert ("%s pgtable: %luk pages, %llu-bit VAs, pgdp=%016lx\n" , mm == &init_mm ?"swapper" :"user" ,PAGE_SIZE /SZ_1K , vabits_actual,mm_to_pgd_phys (mm)); + +guard (irqsave)(); + pgdp =pgd_offset (mm, addr); pgd =READ_ONCE (*pgdp);pr_alert ("[%016lx] pgd=%016llx" , addr,pgd_val (pgd));
@@ -167,25 +171,25 @@ static void show_pte(unsigned long addr)if (pgd_none (pgd) ||pgd_bad (pgd))break ; - p4dp =p4d_offset (pgdp, addr); + p4dp =p4d_offset_lockless (pgdp, pgd, addr); p4d =READ_ONCE (*p4dp);pr_cont (", p4d=%016llx" ,p4d_val (p4d));if (p4d_none (p4d) ||p4d_bad (p4d))break ; - pudp =pud_offset (p4dp, addr); + pudp =pud_offset_lockless (p4dp, p4d, addr); pud =READ_ONCE (*pudp);pr_cont (", pud=%016llx" ,pud_val (pud));if (pud_none (pud) ||pud_bad (pud))break ; - pmdp =pmd_offset (pudp, addr); + pmdp =pmd_offset_lockless (pudp, pud, addr); pmd =READ_ONCE (*pmdp);pr_cont (", pmd=%016llx" ,pmd_val (pmd));if (pmd_none (pmd) ||pmd_bad (pmd))break ; - ptep =pte_offset_map (pmdp, addr); + ptep =pte_offset_map (&pmd, addr);if (!ptep)break ;
Greg Kroah-Hartman
maintainerPATCH 147/556 arm64: Dont read GMID_EL1 when MTE is disabled
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fuad Tabba <[email protected]>
commit 5445d64199626974269fcdf347769ad44b0bb53b upstream.
__cpuinfo_store_cpu() gates the GMID_EL1 read on the raw ID_AA64PFR1_EL1, so it reads the register even when the kernel has disabled MTE (CONFIG_ARM64_MTE=n or arm64.nomte). KVM sets HCR_EL2.TID5 in that case, and pKVM injects an UNDEF the host cannot handle:
Internal error: Oops - Undefined instruction: 0000000002000000 [#1] SMP pc : __cpuinfo_store_cpu+0xf4/0x264 Kernel panic - not syncing: Attempted to kill the idle task!
Only pKVM reaches it, and only after a CPU is offlined and brought back
online: its CPU_ON relay sets the host HCR before the CPU enters EL1, while plain nVHE sets it at CPUHP_AP_KVM_ONLINE.
Gate the read on the CPU's own ID_AA64PFR1_EL1 with the command-line override applied, and on CONFIG_ARM64_MTE, which no register reflects. The boot CPU stores its registers before init_cpu_features() strips an unsafe override, so clamp against the hardware value here too.
--- arch/arm64/include/asm/cpu.h | 1 + arch/arm64/include/asm/cpufeature.h | 7 ------- arch/arm64/kernel/cpufeature.c | 33 +++++++++++++++++++++++++++++---- arch/arm64/kernel/cpuinfo.c | 2 +- 4 files changed, 31 insertions(+), 12 deletions(-)
arch/arm64/include/asm/cpu.h +1 -0
@@ -78,5 +78,6 @@ void __init cpuinfo_store_boot_cpu(void)void __init init_cpu_features (struct cpuinfo_arm64 *info);void update_cpu_features (int cpu,struct cpuinfo_arm64 *info,struct cpuinfo_arm64 *boot); +bool gmid_el1_accessible (const struct cpuinfo_arm64 *info);#endif /* __ASM_CPU_H */
arch/arm64/include/asm/cpufeature.h +0 -7
@@ -627,13 +627,6 @@ static inline bool id_aa64pfr1_mpamfrac(return val >0 ; } -static inline bool id_aa64pfr1_mte (u64 pfr1) -{ -u32 val =cpuid_feature_extract_unsigned_field (pfr1,ID_AA64PFR1_EL1_MTE_SHIFT ); - -return val >=ID_AA64PFR1_EL1_MTE_MTE2 ; -} -void __init setup_boot_cpu_features (void );void __init setup_system_features (void );void __init setup_user_features (void );
arch/arm64/kernel/cpufeature.c +29 -4
@@ -1176,6 +1176,33 @@ static bool detect_ftr_has_mpam(void)return id_aa64pfr0_mpam (pfr0) ||id_aa64pfr1_mpamfrac (pfr1); } +bool gmid_el1_accessible (const struct cpuinfo_arm64 *info) +{ +const struct arm64_ftr_bits *ftrp; +s64 mte, ovr; +u64 ftr_mask; + +/* No ID register reflects CONFIG_ARM64_MTE. */ +if (!IS_ENABLED (CONFIG_ARM64_MTE )) +return false; + +for (ftrp = ftr_id_aa64pfr1; ftrp->width; ftrp++) { +if (ftrp->shift ==ID_AA64PFR1_EL1_MTE_SHIFT ) +break ; + } + + ftr_mask =arm64_ftr_mask (ftrp); + mte =arm64_ftr_value (ftrp, info->reg_id_aa64pfr1); + +/* The boot CPU runs before init_cpu_ftr_reg() strips unsafe overrides. */ +if ((id_aa64pfr1_override.mask & ftr_mask) == ftr_mask) { + ovr =arm64_ftr_value (ftrp, id_aa64pfr1_override.val); + mte =arm64_ftr_safe_value (ftrp, ovr, mte); + } + +return mte >=ID_AA64PFR1_EL1_MTE_MTE2 ; +} +void __init init_cpu_features (struct cpuinfo_arm64 *info) {/* Before we start using the tables, make sure it is sorted */
@@ -1228,7 +1255,7 @@ void __init init_cpu_features(struct cpuinit_cpu_ftr_reg (SYS_MPAMIDR_EL1 , info->reg_mpamidr); } -if (id_aa64pfr1_mte (info->reg_id_aa64pfr1)) +if (gmid_el1_accessible (info))init_cpu_ftr_reg (SYS_GMID_EL1 , info->reg_gmid); }
@@ -1490,11 +1517,9 @@ void update_cpu_features(int cpu,* they read/write depends on the GMID_EL1.BS field. Check that the * value is the same on all CPUs. */ -if (IS_ENABLED (CONFIG_ARM64_MTE ) && -id_aa64pfr1_mte (info->reg_id_aa64pfr1)) { +if (gmid_el1_accessible (info)) taint |=check_update_ftr_reg (SYS_GMID_EL1 , cpu, info->reg_gmid, boot->reg_gmid); - }/* * If we don't have AArch32 at all then skip the checks entirely
arch/arm64/kernel/cpuinfo.c +1 -1
@@ -502,7 +502,7 @@ static void __cpuinfo_store_cpu(struct c info->reg_id_aa64smfr0 =read_cpuid (ID_AA64SMFR0_EL1 ); info->reg_id_aa64fpfr0 =read_cpuid (ID_AA64FPFR0_EL1 ); -if (id_aa64pfr1_mte (info->reg_id_aa64pfr1)) +if (gmid_el1_accessible (info)) info->reg_gmid =read_cpuid (GMID_EL1 );if (id_aa64pfr0_32bit_el0 (info->reg_id_aa64pfr0))
Greg Kroah-Hartman
maintainerPATCH 148/556 arm64: errata: pass REVIDR when matching target implementation CPUs
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Khushit Shah <[email protected]>
commit 5541432e09dc2031978188f3e8a00b9fc78cf097 upstream.
When target implementation CPUs are provided, is_affected_midr_range() accidentally passed the MIDR as both arguments to __is_affected_midr_range(), so the REVIDR mask check operated on the wrong register.
Pass REVIDR as intended.
--- arch/arm64/kernel/cpu_errata.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kernel/cpu_errata.c +1 -1
@@ -82,7 +82,7 @@ is_affected_midr_range(const struct arm6for (i =0 ; i < target_impl_cpu_num; i++) {if (__is_affected_midr_range (entry, target_impl_cpus[i].midr, - target_impl_cpus[i].midr)) + target_impl_cpus[i].revidr))return true; }return false;
Greg Kroah-Hartman
maintainerPATCH 149/556 ALSA: rawmidi: Return the error from snd_rawmidi_input_params()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: HyeongJun An <[email protected]>
commit f4a23e17d84fd2a152d9e12369761934e1af0ee8 upstream.
The snd_rawmidi_input_params() computes err for the three invalid mode combinations and for resize_runtime_buffer(), applies the new framing and clock type only when err is zero, and then returns 0 anyway. A caller that asked for parameters the kernel rejected is told the change succeeded, and the substream keeps its old buffer.
The open_mutex conversion turned the early returns into assignments. It handled the output sibling correctly, which still returns err, and left this one behind.
--- sound/core/rawmidi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/core/rawmidi.c +1 -1
@@ -782,7 +782,7 @@ int snd_rawmidi_input_params(struct snd_ substream->framing = framing; substream->clock_type = clock_type; } -return 0 ; +return err; }EXPORT_SYMBOL (snd_rawmidi_input_params);
Greg Kroah-Hartman
maintainerPATCH 150/556 ALSA: harmony: initialize locks before requesting IRQ
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit 33abb7491e89285a41565670945293dda841afc4 upstream.
snd_harmony_create() registers the IRQ before initializing h->lock and h->mixer_lock. A pending interrupt can invoke the handler while these locks are uninitialized.
Initialize both locks before requesting the IRQ so the handler always sees valid lock state.
--- sound/parisc/harmony.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
sound/parisc/harmony.c +3 -3
@@ -868,6 +868,9 @@ snd_harmony_create(struct snd_card *card goto free_and_ret; } +spin_lock_init (&h->mixer_lock); +spin_lock_init (&h->lock); + err =request_irq (padev->irq, snd_harmony_interrupt,0 ,"harmony" , h);if (err) {
@@ -877,9 +880,6 @@ snd_harmony_create(struct snd_card *card } h->irq = padev->irq; -spin_lock_init (&h->mixer_lock); -spin_lock_init (&h->lock); - err =snd_device_new (card,SNDRV_DEV_LOWLEVEL , h, &ops);if (err <0 ) goto free_and_ret;
Greg Kroah-Hartman
maintainerPATCH 151/556 ALSA: pcm: Fix race between non-atomic ops and trigger-start
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
commit acac7b5e07349a9d10d78873afb4b93cd1dc721f upstream.
We protect the races of the concurrent state transitions between atomic PCM ops, but the checks between the non-atomic ops (hw_params, hw_free and prepare) and the atomic ops aren't perfect; there is a check of the conflicting PCM state at the beginning of hw_params & co, but the atomic PCM ops can be still issued during the non-atomic PCM operations. An example such scenario is that a thread A re-issues the PREPARE or HW_PARAMS for the already prepared stream, while another thread B triggers the PCM start in the middle of the prepare operation. Although this usually doesn't lead to much serious issues, it can give some inconsistency as reported by syzkaller (such as ODEBUG warning).
There are various atomic PCM ops, and basically the only problem is the PCM start as it operates from the PREPARED state. Other trigger commands (stop, etc) are for the running or the other special state, hence they are filtered as pre-condition.
This patch is for preventing the PCM trigger-start during the non- atomic operations in order to address the problems above. Fortunately, the hw_params, hw_free and prepare operations call snd_pcm_buffer_access_lock(), and this can be used for checking the concurrent operations at the PCM trigger -- which sets the runtime->buffer_accessing to a negative (if possible), so the PCM trigger just needs to check the runtime->buffer_accessing value; if it's negative, it means the concurrent non-atomic PCM ops is running.
--- sound/core/pcm_native.c | 2 ++ 1 file changed, 2 insertions(+)
sound/core/pcm_native.c +2 -0
@@ -1468,6 +1468,8 @@ static int snd_pcm_pre_start(struct snd_struct snd_pcm_runtime *runtime = substream->runtime;if (runtime->state !=SNDRV_PCM_STATE_PREPARED )return -EBADFD ; +if (atomic_read (&runtime->buffer_accessing) <0 ) +return -EBADFD ;/* during hw_params, hw_free or prepare */ if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK && !snd_pcm_playback_data (substream))return -EPIPE ;
Greg Kroah-Hartman
maintainerPATCH 152/556 ring-buffer: Allow splice reads on static buffers
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vincent Donnefort <[email protected]>
commit 6365c44a824ff138e7926413932bb5c2e28a4c8c upstream.
ring_buffer_read_page() rejects splice (full=1) reads on static buffers (that is user-mapped, persistent or remote) because !read check assumes unread pages must be swapped. However for those buffers we have no other choice than memcpy the data.
For the memcpy case, only return an error when the writer is still on the reader page for the splice interface to wait.
--- kernel/trace/ring_buffer.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
kernel/trace/ring_buffer.c +2 -9
@@ -7182,15 +7182,8 @@ int ring_buffer_read_page(struct trace_bunsigned int event_size;unsigned int flags =0 ; -/* -* If a full page is expected, this can still be returned -* if there's been a previous partial read and the -* rest of the page can be read and the commit page is off -* the reader page. -*/ -if (full && - (!read || (len < (size - read)) || - cpu_buffer->reader_page == cpu_buffer->commit_page)) +/* If a full page is requested, it cannot be the commit page */ +if (full && cpu_buffer->reader_page == cpu_buffer->commit_page)return -1 ;if (len > (size - read))
Greg Kroah-Hartman
maintainerPATCH 153/556 accel/amdxdna: return early from a zero-length flush
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Taimuraz Kaitmazov <[email protected]>
commit dc14753664240cedf669623b27ae9922b0618b25 upstream.
SYNC_BO does not constrain its size, so a request for zero bytes reaches drm_clflush_virt_range(), which ends with an unconditional clflushopt(end - 1). For an empty range that is the byte before the mapping, and abo->mem.kva comes from vmap(), so the access lands in the guard page below the vmalloc area and faults:
BUG: unable to handle page fault for address: ffffd16fbbc70fff #PF: supervisor read access in kernel mode Oops: Oops: 0000 [#1] SMP NOPTI CPU: 7 UID: 1000 Comm: sync_bo_probe RIP: 0010:drm_clflush_virt_range+0x3c/0x70 Call Trace: amdxdna_drm_sync_bo_ioctl+0x124/0x430 [amdxdna] drm_ioctl+0x301/0x4c0 __x64_sys_ioctl+0x115/0x2f0 do_syscall_64+0xa6/0x3d0
Any process that can open the render node can do this. Reproduced 3 of 3 times on a Strix Point NPU (1022:17f0), by calling SYNC_BO with size 0 on an AMDXDNA_BO_SHARE object. The import arm takes the same request but flushes the whole scatterlist, so it survives it.
Nothing needs flushing for an empty range, so answer before choosing a path.
--- drivers/accel/amdxdna/amdxdna_gem.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/accel/amdxdna/amdxdna_gem.c +3 -0
@@ -1247,6 +1247,9 @@ static int amdxdna_flush_bo(struct amdxdreturn -EINVAL ; size =min (abo->mem.size, end) - offset; +if (!size) +return 0 ; +if (is_import_bo (abo))drm_clflush_sg (abo->base.sgt);else if (amdxdna_gem_vmap (abo))
Greg Kroah-Hartman
maintainerPATCH 154/556 accel/ethosu: check MMIO mapping errors in probe
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: GuoHan Zhao <[email protected]>
commit 7ab64476a610fe65858fdc37c7a30caa13e334ac upstream.
devm_platform_ioremap_resource() returns an error pointer when the register resource cannot be mapped. ethosu_probe() stores it and continues until initialization dereferences it through MMIO accessors.
Return the mapping error before initializing the device.
--- drivers/accel/ethosu/ethosu_drv.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/accel/ethosu/ethosu_drv.c +2 -0
@@ -342,6 +342,8 @@ static int ethosu_probe(struct platform_device *pdev)dma_set_mask_and_coherent (&pdev->dev,DMA_BIT_MASK (40 )); ethosudev->regs =devm_platform_ioremap_resource (pdev,0 ); +if (IS_ERR (ethosudev->regs)) +return PTR_ERR (ethosudev->regs); ethosudev->num_clks =devm_clk_bulk_get_all (&pdev->dev, ðosudev->clks);if (ethosudev->num_clks <0 )
Signature · 1 line
2.55.0
Greg Kroah-Hartman
maintainerPATCH 155/556 accel/ethosu: fix job completion fence cleanup
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: GuoHan Zhao <[email protected]>
commit 2d2a3adc91950f9a18829dadc7317fb5180a15c5 upstream.
ethosu_ioctl_submit_job() allocates done_fence before validating buffer handles. Errors after allocation call ethosu_job_err_cleanup(), which frees the job but leaks the uninitialized fence.
A scheduler dependency error also lets ethosu_job_run() return before dma_fence_init(). Normal cleanup then passes a zeroed refcount to dma_fence_put().
Release done_fence in the common cleanup path and use dma_fence_was_initialized() to distinguish initialized fences from raw allocations.
--- drivers/accel/ethosu/ethosu_job.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/accel/ethosu/ethosu_job.c +8 -2
@@ -152,6 +152,13 @@ static void ethosu_job_err_cleanup(struct ethosu_job *job)drm_gem_object_put (job->cmd_bo); +if (job->done_fence) { +if (dma_fence_was_initialized (job->done_fence)) +dma_fence_put (job->done_fence); +else +dma_fence_free (job->done_fence); + } +kfree (job); }
@@ -162,7 +169,6 @@ static void ethosu_job_cleanup(struct kref *ref)pm_runtime_put_autosuspend (job->dev->base.dev); -dma_fence_put (job->done_fence);dma_fence_put (job->inference_done_fence);ethosu_job_err_cleanup (job);
@@ -393,7 +399,7 @@ static int ethosu_ioctl_submit_job(struct drm_device *dev, struct drm_file *file ejob->done_fence =kzalloc_obj (*ejob->done_fence);if (!ejob->done_fence) { ret = -ENOMEM ; - goto out_cleanup_job; + goto out_put_job; } ret = drm_sched_job_init(&ejob->base,
Signature · 1 line
2.55.0
Greg Kroah-Hartman
maintainerPATCH 156/556 nvme-fabrics: fix DHCHAP secret leak on parse failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
commit afdee49a1b88ed9bb44e2b30e855297c169bcc53 upstream.
nvmf_parse_options() duplicates dhchap_secret and dhchap_ctrl_secret with match_strdup() before validating the DHHC-1: representation.
If validation fails, the parser returns -EINVAL before the temporary string in p is assigned to opts->dhchap_secret or opts->dhchap_ctrl_secret. nvmf_create_ctrl() subsequently frees opts, but nvmf_free_options() cannot release the unassigned temporary string. Each rejected option therefore leaks one allocation.
This is easy to miss because valid secrets transfer ownership to opts and are freed normally, while the malformed-secret path still returns the expected -EINVAL to userspace.
With CONFIG_NVME_HOST_AUTH enabled, the leak is reachable before the required-option checks and transport lookup. No NVMe-oF target or working transport connection is required; for example, repeatedly writing
dhchap_secret=BAD
or
dhchap_ctrl_secret=BAD
to /dev/nvme-fabrics deterministically takes the leaking parse path.
Free the temporary string before leaving both validation error paths. Use kfree_sensitive() because the copied option may contain secret material even when its representation is rejected, matching the sensitive cleanup used for stored DHCHAP secrets.
--- drivers/nvme/host/fabrics.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/nvme/host/fabrics.c +2 -0
@@ -1028,6 +1028,7 @@ static int nvmf_parse_options(struct nvm }if (strlen (p) <11 ||strncmp (p,"DHHC-1:" ,7 )) {pr_err ("Invalid DH-CHAP secret %s\n" , p); +kfree_sensitive (p); ret = -EINVAL ; goto out; }
@@ -1042,6 +1043,7 @@ static int nvmf_parse_options(struct nvm }if (strlen (p) <11 ||strncmp (p,"DHHC-1:" ,7 )) {pr_err ("Invalid DH-CHAP secret %s\n" , p); +kfree_sensitive (p); ret = -EINVAL ; goto out; }
Greg Kroah-Hartman
maintainerPATCH 157/556 nvme-fc: fix double free of fabrics options when nvme_add_ctrl() fails
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Niklas Cassel <[email protected]>
commit 56e6279266f6962bb2d38a54397e3c605165b0c5 upstream.
nvmf_create_ctrl() owns the fabrics options and frees them whenever ->create_ctrl() returns an error, so a transport must not free them on its own error paths. nvme-fc tracks this by testing ctrl->ctrl.opts in nvme_fc_ctrl_free(), which requires nvme_fc_init_ctrl() to clear that pointer on every error exit.
The coupling is implicit, and commit 1a9e218195a5 ("nvme: split device add from initialization") broke it by adding a second error exit. When nvme_add_ctrl() fails, nvme_fc_init_ctrl() jumps to out_put_ctrl:, past the "ctrl->ctrl.opts = NULL" that only sits on the fail_ctrl: path, so nvme_fc_ctrl_free() frees the options and nvmf_create_ctrl() frees them a second time:
BUG: KASAN: slab-use-after-free in nvmf_free_options+0x30/0x190 nvmf_free_options+0x30/0x190 drivers/nvme/host/fabrics.c:1284 nvmf_create_ctrl drivers/nvme/host/fabrics.c:1374 [inline] Freed by task 5534: nvme_fc_ctrl_free drivers/nvme/host/fc.c:2374 [inline] nvme_fc_init_ctrl+0xe17/0x1450 drivers/nvme/host/fc.c:3605
nvme_add_ctrl() fails when dev_set_name() cannot allocate, so this is reachable under memory pressure or fault injection. Without KASAN the options are freed twice.
Rather than clear the pointer on the second exit as well, derive ownership the way nvme-tcp, nvme-rdma and nvme-loop do, from list
membership: their free_ctrl leaves the options alone unless the controller made it onto the transport list.
The list cannot simply be populated on the success path as it is there. nvme-fc runs the initial connect synchronously via flush_delayed_work(), and the controller has to be reachable on rport->ctrl_list for the whole of it: nvme_fc_unregister_remoteport() needs to find it to signal connectivity loss, nvme_fc_match_disconn_ls() matches an incoming Disconnect Association LS against ctrl->association_id, which is only assigned during that window, nvme_fc_resume_controller() needs it on remoteport re-registration, and nvme_fc_existing_controller() uses it to reject a duplicate connect racing the one in flight.
Keep the insertion where it is and add a fail_unlist: label, falling into fail_ctrl:, for the error paths that run after it. The earlier error paths never reach the insertion and keep using fail_ctrl:
directly, so the list is only touched where the controller is actually on it.
nvme_fc_ctrl_free() cannot use the plain "goto free_ctrl" the other transports use, because it still has to put_device(), release the rport reference and free the ida entry for resources taken before the insertion. Sample list_empty() under rport->lock instead.
ctrl->ctrl.opts also stays valid for the whole teardown now. That is not the bug being fixed, but it removes some fragility around the old
idiom: nvme_free_ctrl() calls nvme_auth_free() before ->free_ctrl(), and ctrl_max_dhchaps() dereferences ctrl->opts without a NULL check when ctrl->dhchap_ctxs is set, which nvme-fc permits since NVMF_ALLOWED_OPTS allows the dhchap options. The nvme sysfs attributes that dereference ctrl->opts, such as hostnqn and address, evaluate their is_visible() test once at device_add() time and stay readable until cdev_device_del().
--- drivers/nvme/host/fc.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
drivers/nvme/host/fc.c +20 -6
@@ -2358,9 +2358,15 @@ nvme_fc_ctrl_free(struct kref *ref)struct nvme_fc_ctrl *ctrl = container_of(ref, struct nvme_fc_ctrl, ref);unsigned long flags; +bool owns_opts; -/* remove from rport list */ +/* +* Presence on the rport list means nvme_fc_init_ctrl() completed, +* and with it ownership of the fabrics options passed to it. If it +* failed instead, the options still belong to nvmf_create_ctrl(). +*/ spin_lock_irqsave (&ctrl->rport->lock, flags); + owns_opts = !list_empty (&ctrl->ctrl_list);list_del (&ctrl->ctrl_list);spin_unlock_irqrestore (&ctrl->rport->lock, flags);
@@ -2370,7 +2376,7 @@ nvme_fc_ctrl_free(struct kref *ref)nvme_fc_rport_put (ctrl->rport);ida_free (&nvme_fc_ctrl_cnt, ctrl->cnum); -if (ctrl->ctrl.opts) +if (owns_opts)nvmf_free_options (ctrl->ctrl.opts);kfree (ctrl); }
@@ -3569,14 +3575,14 @@ nvme_fc_init_ctrl(struct device *dev, stif (!nvme_change_ctrl_state (&ctrl->ctrl,NVME_CTRL_CONNECTING )) {dev_err (ctrl->ctrl.device,"NVME-FC{%d}: failed to init ctrl state\n" , ctrl->cnum); - goto fail_ctrl; + goto fail_unlist; }if (!queue_delayed_work (nvme_wq, &ctrl->connect_work,0 )) {dev_err (ctrl->ctrl.device,"NVME-FC{%d}: failed to schedule initial connect\n" , ctrl->cnum); - goto fail_ctrl; + goto fail_unlist; }flush_delayed_work (&ctrl->connect_work);
@@ -3587,14 +3593,22 @@ nvme_fc_init_ctrl(struct device *dev, streturn &ctrl->ctrl; +fail_unlist: +/* +* Leaving the list hands the options back to nvmf_create_ctrl(); +* see nvme_fc_ctrl_free(). Re-init so that list_empty() there +* reports the controller as unlisted. +*/ +spin_lock_irqsave (&rport->lock, flags); +list_del_init (&ctrl->ctrl_list); +spin_unlock_irqrestore (&rport->lock, flags); + fail_ctrl:nvme_change_ctrl_state (&ctrl->ctrl,NVME_CTRL_DELETING );cancel_work_sync (&ctrl->ioerr_work);cancel_work_sync (&ctrl->ctrl.reset_work);cancel_delayed_work_sync (&ctrl->connect_work); - ctrl->ctrl.opts =NULL ; -if (ctrl->ctrl.admin_tagset)nvme_remove_admin_tag_set (&ctrl->ctrl);/* initiate nvme ctrl ref counting teardown */
Greg Kroah-Hartman
maintainerPATCH 158/556 nvme-tcp: check the data direction of a C2HData PDU
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yehyeong Lee <[email protected]>
commit f83af377c148f6ad94b41c0e8313f12adf45e1c1 upstream.
nvme_tcp_handle_c2h_data() finds the request by command id and checks that it has a payload, but it does not check that the command asked for data to be read. A controller that answers a write command with C2HData therefore reaches nvme_tcp_recv_data(), where _copy_to_iter() hits WARN_ON_ONCE(i->data_source) and returns 0. The receive path turns that into -EFAULT and resets the controller.
No data is copied, so this is not memory corruption. What a controller gets is a kernel warning it can raise at will, which is fatal on a host booted with panic_on_warn.
The send path already knows the direction - it consults rq_data_dir() when it builds a command - and nvme_tcp_handle_r2t() checks the length and the offset of the request it names. The C2HData path does not check the direction at all.
Reject a C2HData PDU whose command is not a read. Rejecting it fails the command and resets the controller, as the neighbouring check in this function does; what goes away is the warning.
[ 6.885580] ------------[ cut here ]------------ [ 6.886457] WARNING: lib/iov_iter.c:193 at _copy_to_iter+0x289/0x1330, CPU#0: kworker/0:1H/71 [ 6.888137] CPU: 0 UID: 0 PID: 71 Comm: kworker/0:1H Not tainted 7.2.0-rc5-NVMETCP-gf5098b6bae76 #1 PREEMPT(lazy) [ 6.891165] Workqueue: nvme_tcp_wq nvme_tcp_io_work [ 6.891875] RIP: 0010:_copy_to_iter+0x289/0x1330 [ 6.903739] Call Trace: [ 6.904085] <TASK> [ 6.909254] __skb_datagram_iter+0x433/0x820 [ 6.911026] skb_copy_datagram_iter+0x37/0x120 [ 6.911622] nvme_tcp_recv_skb+0xa07/0x4320 [ 6.913378] __tcp_read_sock+0x1ab/0x810 [ 6.915788] nvme_tcp_try_recv+0x152/0x1e0 [ 6.918222] nvme_tcp_io_work+0x1e4/0x6c0 [ 6.926906] </TASK> [ 6.927226] ---[ end trace 0000000000000000 ]--- [ 6.927878] nvme nvme0: queue 1 failed to copy request 0x71 data [ 6.928709] nvme nvme0: receive failed: -14
--- drivers/nvme/host/tcp.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/nvme/host/tcp.c +7 -0
@@ -682,6 +682,13 @@ static int nvme_tcp_handle_c2h_data(strureturn -ENOENT ; } +if (rq_data_dir (rq) !=READ ) { +dev_err (queue->ctrl->ctrl.device, +"queue %d tag %#x unexpected data for a write\n" , +nvme_tcp_queue_id (queue), rq->tag); +return -EIO ; + } + req =blk_mq_rq_to_pdu (rq);if (!blk_rq_payload_bytes (rq) || !req->curr_bio || !req->data_len) { dev_err(queue->ctrl->ctrl.device,
Greg Kroah-Hartman
maintainerPATCH 159/556 nvme: add missing SRCU grace period in error path
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tristan Madani <[email protected]>
commit ef248d5de4469fb6bbaf8dbe0c4c47800080d648 upstream.
nvme_alloc_ns() error path at out_unlink_ns removes ns from the namespace head siblings list with list_del_rcu(&ns->siblings) but does not wait for SRCU readers before freeing the namespace struct. Multipath code iterates the head->list under srcu_read_lock() in nvme_find_path() and nvme_mpath_revalidate_paths(), so a concurrent reader can still hold a reference to ns when kfree(ns) runs.
The normal removal path in nvme_ns_remove() correctly calls synchronize_srcu(&ns->head->srcu) after list_del_rcu() to wait for in-progress readers. Add the same grace period in the error path.
--- drivers/nvme/host/core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/nvme/host/core.c +3 -0
@@ -4295,6 +4295,9 @@ static void nvme_alloc_ns(struct nvme_ct last_path = true; }mutex_unlock (&ctrl->subsys->lock); + +/* guarantee not available in head->list */ +synchronize_srcu (&ns->head->srcu);if (last_path)nvme_put_ns_head (ns->head);nvme_put_ns_head (ns->head);
Greg Kroah-Hartman
maintainerPATCH 160/556 nvme: skip the zoned limits update if the zone info query failed
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Shi <[email protected]>
commit 3838e80fcfb32e62baffb63c6dc0a60153665a4d upstream.
nvme_query_zone_info() returns either a negative errno or a positive NVMe status code, but nvme_update_ns_info_block() only tests for the negative case:
ret = nvme_query_zone_info(ns, lbaf, &zi); if (ret < 0) goto out;
If the device fails the Identify Namespace (I/O Command Set specific) command, or the Identify Controller command issued by nvme_set_max_append(), the positive status falls through and setup continues with the zero-initialized zone info. nvme_update_zone_info() then marks the queue zoned with chunk_sectors and ns->head->zsze set to zero.
blk_validate_zoned_limits() does not check chunk_sectors, so the limits commit succeeds. blk_revalidate_disk_zones() does reject the zero zone size, but by then the limits are live and nothing rolls them back, so I/O keeps being submitted to a zoned queue with a zero zone size and disk_zone_no() shifts by ilog2(0):
nvme0n1: Invalid non power of two zone size (0)
UBSAN: shift-out-of-bounds in include/linux/blkdev.h:747:16 shift exponent -1 is negative disk_zone_no include/linux/blkdev.h:747 [inline] bio_straddles_zones include/linux/blkdev.h:1058 [inline] blk_zone_wplug_handle_write block/blk-zoned.c:1423 [inline] blk_zone_plug_bio.cold+0x25/0x1c8 block/blk-zoned.c:1605 blk_mq_submit_bio+0x18fb/0x2870 block/blk-mq.c:3196 submit_bh_wbc+0x575/0x740 fs/buffer.c:2824 __block_write_full_folio+0x728/0xdd0 fs/buffer.c:1933
Any device, firmware or NVMe-oF target that fails this one command reaches this.
Skip the zoned limits update in that case, and log which of the two things happened: during a revalidation the queue keeps the zone geometry it was last validated with, and on a first scan the namespace is registered without zoned limits, so that it is still available as a handle for admin commands. Neither of the paths in nvme_query_zone_info() that return a positive status logs anything, so the failure would otherwise be silent.
zi.zone_size is an exact indicator: every path that returns a positive status returns before it is assigned, and after that the only failure left is -ENODEV, which the caller already handles.
Found by FuzzNvme.
--- drivers/nvme/host/core.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +19 -2
@@ -2447,9 +2447,26 @@ static int nvme_update_ns_info_block(strif (!nvme_update_disk_info (ns, id, nvm, &lim)) capacity =0 ; +/* +* A failed zone info query leaves zi zero-initialized, so skip the +* zoned limits update instead of configuring the queue from it. +* During a revalidation that keeps the zone geometry the queue was +* last validated with; on a first scan the namespace is registered +* without zoned limits, so that it is still available as a handle +* for admin commands. +*/ if (IS_ENABLED (CONFIG_BLK_DEV_ZONED ) && - ns->head->ids.csi ==NVME_CSI_ZNS ) -nvme_update_zone_info (ns, &lim, &zi); + ns->head->ids.csi ==NVME_CSI_ZNS ) { +if (zi.zone_size) +nvme_update_zone_info (ns, &lim, &zi); +else +dev_warn (ns->ctrl->device, +"zone info query failed for nsid %u, %s\n" , + ns->head->ns_id, +blk_queue_is_zoned (ns->disk->queue) ? +"keeping the previous zone limits" : +"not enabling zoned mode" ); + }if ((ns->ctrl->vwc &NVME_CTRL_VWC_PRESENT ) && !info->no_vwc) lim.features |=BLK_FEAT_WRITE_CACHE |BLK_FEAT_FUA ;
Greg Kroah-Hartman
maintainerPATCH 161/556 nvmet-auth: Synchronize timeout work during SQ teardown
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kazuki Hanai <[email protected]>
commit eaa948c0e19b1bb2d93262207bca0c3d19cc3406 upstream.
nvmet_auth_sq_free() cancels auth_expired_work with cancel_delayed_work(). If the work has already started, cancellation does not wait for the callback. Transport teardown can consequently free or reuse the queue containing struct nvmet_sq while nvmet_auth_expired_work() still accesses that SQ.
Add a teardown-specific helper that synchronously drains the delayed work before freeing authentication state, and use it from nvmet_sq_destroy(). Keep the non-synchronous helper for in-band authentication state cleanup, where the SQ owner remains alive.
--- drivers/nvme/target/auth.c | 6 ++++++ drivers/nvme/target/core.c | 2 +- drivers/nvme/target/nvmet.h | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-)
drivers/nvme/target/auth.c +6 -0
@@ -238,6 +238,12 @@ void nvmet_auth_sq_free(struct nvmet_sq sq->dhchap_skey =NULL ; } +void nvmet_auth_sq_destroy (struct nvmet_sq *sq) +{ +cancel_delayed_work_sync (&sq->auth_expired_work); +nvmet_auth_sq_free (sq); +} +void nvmet_destroy_auth (struct nvmet_ctrl *ctrl) { ctrl->shash_id =0 ;
drivers/nvme/target/core.c +1 -1
@@ -977,7 +977,7 @@ void nvmet_sq_destroy(struct nvmet_sq *swait_for_completion (&sq->confirm_done);wait_for_completion (&sq->free_done);percpu_ref_exit (&sq->ref); -nvmet_auth_sq_free (sq); +nvmet_auth_sq_destroy (sq);nvmet_cq_put (sq->cq);/*
drivers/nvme/target/nvmet.h +2 -0
@@ -915,6 +915,7 @@ u8 nvmet_setup_auth(struct nvmet_ctrl *cvoid nvmet_auth_sq_init (struct nvmet_sq *sq);void nvmet_destroy_auth (struct nvmet_ctrl *ctrl);void nvmet_auth_sq_free (struct nvmet_sq *sq); +void nvmet_auth_sq_destroy (struct nvmet_sq *sq);int nvmet_setup_dhgroup (struct nvmet_ctrl *ctrl,u8 dhgroup_id);bool nvmet_check_auth_status (struct nvmet_req *req); int nvmet_auth_host_hash(struct nvmet_req *req, u8 *response,
@@ -941,6 +942,7 @@ static inline void nvmet_auth_sq_init(st }static inline void nvmet_destroy_auth (struct nvmet_ctrl *ctrl) {};static inline void nvmet_auth_sq_free (struct nvmet_sq *sq) {}; +static inline void nvmet_auth_sq_destroy (struct nvmet_sq *sq) {};static inline bool nvmet_check_auth_status (struct nvmet_req *req) {return true;
Greg Kroah-Hartman
maintainerPATCH 162/556 nvmet-tcp: fix out-of-bounds write when receiving an over-long PDU
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shivam Kumar <[email protected]>
commit 14cc5a7e77731497d5bea70f3bb05df7eda982e4 upstream.
nvmet_tcp_try_recv_pdu() reads a PDU header into the fixed 128-byte queue->pdu union, then computes the remaining payload length as
queue->left = hdr->hlen - queue->offset + hdgst;
and reads that many more bytes into &queue->pdu + queue->offset, without ever bounding the result against sizeof(queue->pdu).
A struct nvme_tcp_icreq_pdu is itself 128 bytes, exactly the size of the union. Once a header digest has been negotiated (hdgst = 4), a second ICReq passes the hlen == nvmet_tcp_pdu_size() check but yields queue->left = 128 - 8 + 4 = 124, so bytes 8..132 are written into the 128-byte buffer -- 4 bytes past its end, over queue->hdr_digest and queue->data_digest. Those bytes are attacker-controlled (an ICReq carries no digest), and the duplicate ICReq is only rejected later, after the overflow. A remote unauthenticated host can thus corrupt kernel memory adjacent to the receive buffer.
Reject any PDU whose declared length would read past the end of queue->pdu before the second recv.
--- drivers/nvme/target/tcp.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/nvme/target/tcp.c +2 -0
@@ -1244,6 +1244,8 @@ recv: } queue->left = hdr->hlen - queue->offset + hdgst; +if (queue->left >sizeof (queue->pdu) - queue->offset) +return -EPROTO ; goto recv; }
Greg Kroah-Hartman
maintainerPATCH 163/556 nvmet-tcp: reject unsolicited H2CData PDUs
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shivam Kumar <[email protected]>
commit db62b35cbca052860c519cbcabe7650708528738 upstream.
nvmet_tcp_handle_h2c_data_pdu() accepts an H2CData PDU after only checking that its TTAG is a valid in-range command index and that the command's data buffers are mapped. It never checks that the target has actually solicited that data by sending an R2T for the command.
A remote host can abuse this. It submits a write command that takes the R2T path and, before the target transmits the R2T, sends an H2CData PDU for that command's tag. The data completes the command early, and when the command then fails synchronously (e.g. a length mismatch caught by nvmet_check_transfer_len()), it is completed a second time. Each completion calls nvmet_tcp_queue_response(), so the same command is added to queue->resp_list twice while it is still linked; the second llist_add() makes the node point to itself (lentry->next == lentry).
nvmet_tcp_process_resp_list() then walks that self-referential node and adds the command to resp_send_list twice. With CONFIG_DEBUG_LIST this trips the "list_add double add" check (kernel BUG); without it the loop never terminates and the nvmet_tcp workqueue wedges (soft-lockup). It is remotely triggerable and needs no authentication on an allow_any_host subsystem.
Track whether an R2T has been transmitted for a command and reject an H2CData PDU that arrives before it. The flag is cleared on command reuse (nvmet_tcp_get_cmd() zeroes cmd->flags) and stays set across the multiple H2CData PDUs of a single solicited transfer.
--- drivers/nvme/target/tcp.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/nvme/target/tcp.c +8 -0
@@ -103,6 +103,7 @@ enum nvmet_tcp_recv_state {enum {NVMET_TCP_F_INIT_FAILED = (1 <<0 ), +NVMET_TCP_F_R2T_SENT = (1 <<1 ), };struct nvmet_tcp_cmd {
@@ -776,6 +777,7 @@ static int nvmet_try_send_r2t(struct nvmreturn -EAGAIN ; cmd->queue->snd_cmd =NULL ; + cmd->flags |=NVMET_TCP_F_R2T_SENT ;return 1 ; }
@@ -1009,6 +1011,12 @@ static int nvmet_tcp_handle_h2c_data_pdu cmd = &queue->connect; } +if (unlikely (!(cmd->flags &NVMET_TCP_F_R2T_SENT ))) { +pr_err ("queue %d: unsolicited H2CData (ttag %u)\n" , + queue->idx, data->ttag); + goto err_proto; + } +if (le32_to_cpu (data->data_offset) != cmd->rbytes_done) { pr_err("ttag %u unexpected data offset %u (expected %u)\n", data->ttag, le32_to_cpu(data->data_offset),
Greg Kroah-Hartman
maintainerPATCH 164/556 pmdomain: airoha: fix unselectable AIROHA_CPU_PM_DOMAIN kconfig
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christian Marangi <[email protected]>
commit 6d94c47a2e3a38170a0a141547e4c52fbe232cc3 upstream.
The AIROHA_CPU_PM_DOMAIN config was wrongly guarded under the Mediatek PM Domains menu and was unselectable.
Move it outside the menu so it's now visible and correctly selectable by default on Airoha SoC.
--- drivers/pmdomain/mediatek/Kconfig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/pmdomain/mediatek/Kconfig +3 -2
@@ -43,9 +43,12 @@ config MTK_MFG_PM_DOMAIN This driver is required for the Mali GPU to work at all on MT8196 and MT6991. +endmenu + config AIROHA_CPU_PM_DOMAIN tristate "Airoha CPU power domain" default ARCH_AIROHA + depends on ARCH_AIROHA || COMPILE_TEST depends on HAVE_ARM_SMCCC depends on PM select PM_GENERIC_DOMAINS
@@ -54,5 +57,3 @@ config AIROHA_CPU_PM_DOMAIN CPU frequency and power is controlled by ATF with SMC command to set performance states. - -endmenu
Greg Kroah-Hartman
maintainerPATCH 165/556 Revert "irqchip/mbigen: Fix mbigen node address layout"
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: caina <[email protected]>
commit e67091609cf85962f64391c1b0f93d4cbfcd4e22 upstream.
This reverts commit 6be6cba9c4371d27f78d900ccfe34bb880d9ee20.
Commit 6be6cba9c437 ("irqchip/mbigen: Fix mbigen node address layout") appears to cause a regression on Hi1616.
On-board hns NIC has two ports, enahisic2i0 and enahisic2i1, both behind mbigen-v2. Port 0 works; port 1 cannot pass any traffic.
Their interrupt pins fall on different mbigen nodes:
enahisic2i0: pins 1152-1198 -> all in node 9
enahisic2i1: pins 1200-1246 -> node 9 (1200-1215) + node 10 (1216-1246)
(nid = (hwirq - 64) / 128 + 1; pin 1215 = node 9, pin 1216 = node 10)
/proc/interrupts shows the break happens exactly at the node boundary:
enahisic2i1-rx0 pin 1200 count 102 <- node 9 enahisic2i1-rx5 pin 1215 count 1 <- node 9, last pin enahisic2i1-tx5 pin 1216 count 0 <- node 10, first pin enahisic2i1-rx6 pin 1218 count 0 <- node 10
...all node 10 pins stay at zero.
Port 0 (entirely node 9) is unaffected. Reverting the commit restores normal operation.
The commit assumes CLEAR occupies a full 4 KB page at [0xa000, 0xb000) and collides with node 10, so node 10+ gets shifted by 0x1000.
But get_mbigen_clear_reg() uses flat, chip-wide addressing -- it never multiplies by the node ID:
*addr = (hwirq / 32) * 4 + REG_MBIGEN_CLEAR_OFFSET; /* 0xa000 */
Over the valid hwirq range [64, 1407], CLEAR only spans 0xa008-0xa0af (168 bytes). Node 10's registers are:
TYPE: 0xa000-0xa00f (16 B) overlaps CLEAR by 8 B (0xa008-0xa00f)
VEC: 0xa200-0xa3ff (512 B) no overlap with CLEARShifting the whole page moves VEC from 0xa200 to 0xb200. The hardware reads the event ID from the fixed silicon address 0xa200 on interrupt firing, but software wrote it to 0xb200 -- so the hardware gets an uninitialised value and the interrupt is lost.
The only real overlap is 8 bytes of TYPE. It can only trigger when a single mbigen instance has devices on both node 1 (CLEAR 0xa008) and node 10 (TYPE 0xa008). On Hi1616 those nodes are on separate mbigen instances, so it never triggers.
--- drivers/irqchip/irq-mbigen.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-)
drivers/irqchip/irq-mbigen.c +4 -16
@@ -64,20 +64,6 @@ struct mbigen_device {void __iomem *base; }; -static inline unsigned int get_mbigen_node_offset (unsigned int nid) -{ -unsigned int offset = nid *MBIGEN_NODE_OFFSET ; - -/* -* To avoid touched clear register in unexpected way, we need to directly -* skip clear register when access to more than 10 mbigen nodes. -*/ -if (nid >= (REG_MBIGEN_CLEAR_OFFSET /MBIGEN_NODE_OFFSET )) - offset +=MBIGEN_NODE_OFFSET ; - -return offset; -} -static inline unsigned int get_mbigen_vec_reg (irq_hw_number_t hwirq) {unsigned int nid, pin;
@@ -86,7 +72,8 @@ static inline unsigned int get_mbigen_ve nid = hwirq /IRQS_PER_MBIGEN_NODE +1 ; pin = hwirq %IRQS_PER_MBIGEN_NODE ; -return pin *4 +get_mbigen_node_offset (nid) +REG_MBIGEN_VEC_OFFSET ; +return pin *4 + nid *MBIGEN_NODE_OFFSET + +REG_MBIGEN_VEC_OFFSET ; } static inline void get_mbigen_type_reg(irq_hw_number_t hwirq,
@@ -101,7 +88,8 @@ static inline void get_mbigen_type_reg(i *mask =1 << (irq_ofst %32 ); ofst = irq_ofst /32 *4 ; - *addr = ofst +get_mbigen_node_offset (nid) +REG_MBIGEN_TYPE_OFFSET ; + *addr = ofst + nid *MBIGEN_NODE_OFFSET + +REG_MBIGEN_TYPE_OFFSET ; } static inline void get_mbigen_clear_reg(irq_hw_number_t hwirq,
Greg Kroah-Hartman
maintainerPATCH 166/556 Revert "once: dont use a work queue to reset sleepable static key"
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
commit 0ba6912f7e974045dcdd170f022cba19247e00bc upstream.
This reverts commit e8eef69a99f185e75909adb24ab93d706e07bf27.
While DO_ONCE_SLEEPABLE() is used from sleepable/process context, callers may still be holding arbitrary subsystem locks.
For instance, __inet_hash_connect() uses get_random_sleepable_once() which invokes DO_ONCE_SLEEPABLE() while holding the socket lock (sk_lock):
lock_sock(sk)
__inet_hash_connect()
get_random_sleepable_once()
DO_ONCE_SLEEPABLE()
__do_once_sleepable_done()
static_branch_disable()
static_key_disable()
cpus_read_lock()Calling static_branch_disable() directly from __do_once_sleepable_done() causes static_key_disable() to synchronously acquire cpus_read_lock() (cpu_hotplug_lock) and jump_label_mutex inside the caller's lock context.
This introduces an unwanted lockdep dependency:
sk_lock -> cpu_hotplug_lock
Because cpu_hotplug_lock depends on fs_reclaim (via workqueue CPU bringup allocating memory with GFP_KERNEL), and storage/block layers (such as NVMe-TCP) acquire sk_lock during I/O dispatch, lockdep reports circular locking dependencies:
set->srcu -> sk_lock -> cpu_hotplug_lock -> fs_reclaim -> q_usage_counter -> elevator_lock -> set->srcu
This false positive previously prompted commit 19bdb70c77d3 ("nvme-tcp:
lockdep: use dynamic lockdep keys per socket instance") to work around the warning using per-socket dynamic keys in NVMe-TCP. That in turn broke asynchronous socket teardown and caused syzbot warnings in tcp_tsq_handler().
Restoring once_disable_jump() in __do_once_sleepable_done() ensures that static_branch_disable() is executed asynchronously from a system workqueue without holding the caller's locks.
--- lib/once.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/once.c +1 -1
@@ -93,6 +93,6 @@ void __do_once_sleepable_done(bool *done { *done = true;mutex_unlock (&once_mutex); -static_branch_disable (once_key); +once_disable_jump (once_key, mod); }EXPORT_SYMBOL (__do_once_sleepable_done);
Greg Kroah-Hartman
maintainerPATCH 167/556 Revert "pmdomain: qcom: rpmhpd: Add missing MXC and MMCX power domains for Eliza"
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Abel Vesa <[email protected]>
commit 9fca7779ad18538188d640b1fdcfea924459542c upstream.
This reverts commit b48a0a0a76ccecec60f0568e2af4d89994b08bec, which wrongfully added the MXC and MMCX power domains on Eliza.
Even though they are indeed available in cmd-db, which has been the source of information for adding these two, at hardware level they are not actually wired up. Therefore they need to be dropped.
--- drivers/pmdomain/qcom/rpmhpd.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/pmdomain/qcom/rpmhpd.c +0 -4
@@ -245,13 +245,9 @@ static struct rpmhpd *eliza_rpmhpds[] = [RPMHPD_GFX] = &gfx, [RPMHPD_LCX] = &lcx, [RPMHPD_LMX] = &lmx, - [RPMHPD_MMCX] = &mmcx, - [RPMHPD_MMCX_AO] = &mmcx_ao, [RPMHPD_MSS] = &mss, [RPMHPD_MX] = &mx, [RPMHPD_MX_AO] = &mx_ao, - [RPMHPD_MXC] = &mxc, - [RPMHPD_MXC_AO] = &mxc_ao, [RPMHPD_NSP] = &nsp, };
Greg Kroah-Hartman
maintainerPATCH 168/556 mm: fix incorrect vm_flags usage when checking allowable orders for tmpfs
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baolin Wang <[email protected]>
commit 2fd4e7693674b17807a6d082feb01a3fbf86f5f8 upstream.
Lance reported that when nothing else causes the mm to be considered for khugepaged collapse, an MADV_HUGEPAGE-advised tmpfs VMA alone does not trigger scanning.
After commit 6beeab870e70 ("mm: shmem: move shmem_huge_global_enabled() into shmem_allowable_huge_orders()"), the shmem/tmpfs allowable order check reads vma->flags directly. However, when MADV_HUGEPAGE is handled, khugepaged_enter_vma() is called before the VMA's flags have been updated, so the check uses stale flags and incorrectly rejects the VMA for collapse. As a result, khugepaged does not collapse the tmpfs file into PMD order in time.
Fix this by calling khugepaged_enter_vma() with the new VMA flags in madvise_update_vma(). Meanwhile we can remove the khugepaged_enter_vma() in hugepage_madvise().
--- mm/khugepaged.c | 6 ------ mm/madvise.c | 8 ++++++++ 2 files changed, 8 insertions(+), 6 deletions(-)
mm/khugepaged.c +0 -6
@@ -452,12 +452,6 @@ int hugepage_madvise(struct vm_area_strucase MADV_HUGEPAGE : *vm_flags &= ~VM_NOHUGEPAGE ; *vm_flags |=VM_HUGEPAGE ; -/* -* If the vma become good for khugepaged to scan, -* register it here without waiting a page fault that -* may not happen any time soon. -*/ -khugepaged_enter_vma (vma, *vm_flags);break ;case MADV_NOHUGEPAGE : *vm_flags &= ~VM_HUGEPAGE ;
mm/madvise.c +8 -0
@@ -177,6 +177,14 @@ static int madvise_update_vma(vm_flags_t/* vm_flags is protected by the mmap_lock held in write mode. */ vma_start_write (vma); vma->flags = new_vma_flags; +/* +* If the vma become good for khugepaged to scan, +* register it here without waiting a page fault that +* may not happen any time soon. +*/ +if (vma_flags_test (&new_vma_flags,VMA_HUGEPAGE_BIT )) +khugepaged_enter_vma (vma,vma_flags_to_legacy (new_vma_flags)); +if (set_new_anon_name)return replace_anon_vma_name (vma, anon_name);
Greg Kroah-Hartman
maintainerPATCH 169/556 mm/migrate_device: avoid out-of-bounds writes for compound folios
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hui Su <[email protected]>
commit dc41e961a269f2ca4196e669d6d8e05480899cd4 upstream.
migrate_device_range() and migrate_device_pfns() clear the entries following a compound folio so that the PFN arrays retain their page-granular representation.
If a compound folio extends beyond the end of the caller-provided range, the loops clear all following folio entries without limiting them to the number of slots remaining in the npages-sized array, causing an out-of-bounds write.
Do not proceed with a compound folio if its page-granular representation does not fit entirely in the remaining PFN array. If this happens, drop any reference and lock acquired for the folio, clear the remaining entries, and stop collecting.
Observed with a KASAN x86 QEMU kernel using the HMM migrate_anon_huge_zero selftest. Closing /dev/hmm_dmirror0 after migrating an anonymous huge page to device memory exercises:
dmirror_fops_release()
-> dmirror_device_evict_chunk()
-> migrate_device_range()--- mm/migrate_device.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
mm/migrate_device.c +18 -0
@@ -1413,6 +1413,15 @@ int migrate_device_range(unsigned long * src_pfns[i] =migrate_device_pfn_lock (pfn); nr =folio_nr_pages (folio); +if (nr > npages - i) { +if (src_pfns[i] &MIGRATE_PFN_MIGRATE ) { +folio_unlock (folio); +folio_put (folio); + } +memset (&src_pfns[i],0 , + (npages - i) *sizeof (*src_pfns)); +break ; + }if (nr >1 ) { src_pfns[i] |=MIGRATE_PFN_COMPOUND ;for (j =1 ; j < nr; j++)
@@ -1447,6 +1456,15 @@ int migrate_device_pfns(unsigned long *s src_pfns[i] =migrate_device_pfn_lock (src_pfns[i]); nr =folio_nr_pages (folio); +if (nr > npages - i) { +if (src_pfns[i] &MIGRATE_PFN_MIGRATE ) { +folio_unlock (folio); +folio_put (folio); + } +memset (&src_pfns[i],0 , + (npages - i) *sizeof (*src_pfns)); +break ; + }if (nr >1 ) { src_pfns[i] |=MIGRATE_PFN_COMPOUND ;for (j =1 ; j < nr; j++)
Greg Kroah-Hartman
maintainerPATCH 170/556 mm/hugetlb: fix missing migratable flag on same-node hugetlb migration
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wupeng Ma <[email protected]>
commit 8ee1ef0f2f8ce29338f4ab00a3d344c010208058 upstream.
Commit ba23f58de896 ("mm/migrate: don't call folio_putback_active_hugetlb() on dst hugetlb folio") moved setting of the migratable flag and active-list placement from folio_putback_active_hugetlb(dst) into move_hugetlb_state(), so that the freshly allocated destination folio is handled where allocation is known to have succeeded.
Unfortunately, the new code was appended after the existing temporary-folio block in move_hugetlb_state(), which contains an early return added earlier by commit 5af1ab1d24e08 ("mm/hugetlb: optimize the surplus state transfer code in move_hugetlb_state()"):
if (folio_test_hugetlb_temporary(new_folio)) {
...
if (new_nid == old_nid)
return; <-- skips the new code
...
}
/* added by ba23f58 */
folio_set_hugetlb_migratable(new_folio);
list_move_tail(&new_folio->lru, ...&h->hugepage_activelist);When the destination folio is temporary (i.e. the hugetlb pool was exhausted and the migration callback fell back to alloc_migrate_hugetlb_folio()) and the migration does not cross a node -- the common case, and always true on a single-NUMA system -- move_hugetlb_state() returns before setting the migratable flag or adding the new folio to the active list. The destination folio is then installed in the page table but cannot be isolated afterwards, since folio_isolate_hugetlb() rejects folios without the migratable flag; a subsequent soft-offline, hard-offline or memory-hotplug offline of that folio fails with -EBUSY.
This was reproduced on a single-NUMA arm64 VM: a second MADV_SOFT_OFFLINE on an already-migrated hugetlb page returned EBUSY and logged "hugepage isolation failed".
Keep the surplus adjustment, which is the only part that depends on the node crossing, guarded by `if (new_nid != old_nid)', while making the migratable flag and active-list placement unconditional. This preserves the cleanup intent of ba23f58 and closes the early-return hole.
--- mm/hugetlb.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
mm/hugetlb.c +7 -7
@@ -7243,14 +7243,14 @@ void move_hugetlb_state(struct folio *ol* There is no need to transfer the per-node surplus state * when we do not cross the node. */ -if (new_nid == old_nid) -return ; -spin_lock_irq (&hugetlb_lock); -if (h->surplus_huge_pages_node[old_nid]) { - h->surplus_huge_pages_node[old_nid]--; - h->surplus_huge_pages_node[new_nid]++; +if (new_nid != old_nid) { +spin_lock_irq (&hugetlb_lock); +if (h->surplus_huge_pages_node[old_nid]) { + h->surplus_huge_pages_node[old_nid]--; + h->surplus_huge_pages_node[new_nid]++; + } +spin_unlock_irq (&hugetlb_lock); } -spin_unlock_irq (&hugetlb_lock); }/*
Greg Kroah-Hartman
maintainerPATCH 171/556 mm/hugetlb_cma: fix null nodemask dereference in hugetlb_cma_alloc_frozen_folio
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sourav Panda <[email protected]>
commit 7b8a8ae4dd176a232e973017d2aa3c536a7275e2 upstream.
alloc_buddy_hugetlb_folio_with_mpol() can pass a NULL nodemask to alloc_fresh_hugetlb_folio() as a fallback to allocate from all nodes. If order is gigantic, alloc_fresh_hugetlb_folio() propagates the NULL nodemask down to hugetlb_cma_alloc_frozen_folio() via alloc_gigantic_frozen_folio().
Additionally, hugetlb_cma_alloc_frozen_folio() previously attempted allocation on hugetlb_cma[nid] without verifying if nid is included in the caller's nodemask. Adding a node_isset(nid, *nodemask) check ensures the initial preferred node allocation honors the memory policy / nodemask.
However, hugetlb_cma_alloc_frozen_folio() dereferences the nodemask in node_isset(nid, *nodemask) and for_each_node_mask(node, *nodemask), leading to a null pointer dereference kernel panic when nodemask is NULL.
Fix this by checking if nodemask is NULL in hugetlb_cma_alloc_frozen_folio() and defaulting it to cpuset_current_mems_allowed. Enclose the allocation attempts within the cpuset seqcount retry loop so that if the cpuset changes concurrently during allocation, the attempts are retried using the updated nodemask. This ensures that the initial node check and fallback loop safely honor the task's cpuset without violating cpuset constraints or causing NULL pointer dereferences or unexpected allocation failures.
Quoted 1 line
From a userspace perspective, this bug allows an unprivileged user to
crash the kernel (trigger a panic) by requesting a gigantic hugepage allocation with MPOL_PREFERRED_MANY on a system where CMA is only configured on a subset of NUMA nodes.
This can be reproduced by booting a VM with two NUMA nodes, restricting CMA to Node 1 (e.g., hugetlb_cma=1:1G default_hugepagesz=1G hugepagesz=1G hugepages=0), and running a program that allocates a 1GB hugepage area without reserving, restricts allocation to Node 0 using mbind() with MPOL_PREFERRED_MANY, and triggers a page fault:
void *ptr = mmap(NULL, 1UL << 30, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_HUGE_1GB | MAP_NORESERVE, -1, 0);
unsigned long nodemask = 1; /* Node 0 */ mbind(ptr, 1UL << 30, MPOL_PREFERRED_MANY, &nodemask,
sizeof(nodemask) * 8, 0);
memset(ptr, 0, 1UL << 30); /* Trigger fault */
This results in a NULL pointer dereference:
BUG: kernel NULL pointer dereference, address: 0000000000000000 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page Oops: Oops: 0000 [#1] SMP NOPTI RIP: 0010:hugetlb_cma_alloc_frozen_folio+0x75/0x120 Call Trace: <TASK> only_alloc_fresh_hugetlb_folio.isra.0+0x2c/0x160 alloc_surplus_hugetlb_folio+0x6d/0x100 alloc_hugetlb_folio+0x3c5/0x660 hugetlb_no_page+0x3d9/0x650
--- mm/hugetlb_cma.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
mm/hugetlb_cma.c +18 -3
@@ -3,6 +3,7 @@#include <linux/mm.h> #include <linux/cma.h> #include <linux/compiler.h> +#include <linux/cpuset.h> #include <linux/mm_inline.h> #include <asm/page.h>
@@ -30,15 +31,25 @@ struct folio *hugetlb_cma_alloc_frozen_fint node;struct folio *folio;struct page *page =NULL ; +const nodemask_t *nmask; +unsigned int cpuset_mems_cookie;if (!hugetlb_cma_size)return NULL ; -if (hugetlb_cma[nid]) +retry_cpuset: +if (!nodemask) { + cpuset_mems_cookie =read_mems_allowed_begin (); + nmask = &cpuset_current_mems_allowed; + }else { + nmask = nodemask; + } + +if (hugetlb_cma[nid] &&node_isset (nid, *nmask)) page =cma_alloc_frozen_compound (hugetlb_cma[nid], order);if (!page && !(gfp_mask & __GFP_THISNODE)) { -for_each_node_mask (node, *nodemask) { +for_each_node_mask (node, *nmask) {if (node == nid || !hugetlb_cma[node])continue ;
@@ -48,8 +59,12 @@ struct folio *hugetlb_cma_alloc_frozen_f } } -if (!page) +if (!page) { +if (!nodemask && +unlikely (read_mems_allowed_retry (cpuset_mems_cookie))) + goto retry_cpuset;return NULL ; + } folio =page_folio (page);folio_set_hugetlb_cma (folio);
Greg Kroah-Hartman
maintainerPATCH 172/556 mm/hugetlb: keep max_huge_pages when dissolving surplus folios
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Longlong Xia <[email protected]>
commit 267bede12d3b108ca29997ce280e927a570ec97f upstream.
dissolve_free_hugetlb_folio() can remove a free folio as surplus when its node has surplus pages. In that case remove_hugetlb_folio() decrements both nr_huge_pages and surplus_huge_pages, leaving the persistent pool size unchanged.
Updating max_huge_pages as if a persistent folio had been removed can therefore corrupt the persistent pool target and underflow it when max_huge_pages is zero. Keep max_huge_pages unchanged for surplus folios, including the vmemmap restoration rollback path.
--- mm/hugetlb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
mm/hugetlb.c +4 -2
@@ -2002,7 +2002,8 @@ retry:if (h->surplus_huge_pages_node[folio_nid (folio)]) adjust_surplus = true;remove_hugetlb_folio (h, folio, adjust_surplus); - h->max_huge_pages--; +if (!adjust_surplus) + h->max_huge_pages--;spin_unlock_irq (&hugetlb_lock);/*
@@ -2022,7 +2023,8 @@ retry:if (rc) {spin_lock_irq (&hugetlb_lock);add_hugetlb_folio (h, folio, adjust_surplus); - h->max_huge_pages++; +if (!adjust_surplus) + h->max_huge_pages++; goto out; } }else {
Greg Kroah-Hartman
maintainerPATCH 173/556 mm/hugetlb_cgroup: call page_counter_set_max() outside VM_BUG_ON()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Narek Jilavyan <[email protected]>
commit eedc8474d469a2e88f4dc61f8cfe05c147478b43 upstream.
hugetlb_cgroup_css_alloc() rounds the counter limit down to a multiple of the huge page size and then applies it inside an assertion:
VM_BUG_ON(page_counter_set_max(fault, limit)); VM_BUG_ON(page_counter_set_max(rsvd, limit));
With CONFIG_DEBUG_VM=n, VM_BUG_ON(cond) is BUILD_BUG_ON_INVALID(cond), i.e. ((void)(sizeof((__force long)(cond)))), whose operand is never evaluated. page_counter_set_max() is not a predicate - it performs xchg(&counter->max, nr_pages) - so on every non-debug kernel the limit is never applied and the counters keep page_counter_init()'s PAGE_COUNTER_MAX.
That is user-visible, because hugetlb_cgroup_read_u64_max() recomputes the same rounded value and uses equality as its "unlimited" sentinel. PAGE_COUNTER_MAX is LONG_MAX / PAGE_SIZE = 2251799813685247, which is odd, so round_down() really does change it and the two sides disagree. With CONFIG_DEBUG_VM=n:
$ cat /sys/fs/cgroup/t/hugetlb.2MB.max 9223372036854771712
and with this patch:
$ cat /sys/fs/cgroup/t/hugetlb.2MB.max max
A debug option should not change cgroup output.
Call the function, then assert the result, as v6.12 did. Use VM_WARN_ON_ONCE() rather than restoring VM_BUG_ON(): the two are identical under CONFIG_DEBUG_VM=n, and checkpatch asks that new code not use BUG() variants.
--- mm/hugetlb_cgroup.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
mm/hugetlb_cgroup.c +5 -2
@@ -97,6 +97,7 @@ static void hugetlb_cgroup_init(struct hstruct page_counter *fault, *fault_parent =NULL ;struct page_counter *rsvd, *rsvd_parent =NULL ;unsigned long limit; +int ret;if (parent_h_cgroup) { fault_parent = hugetlb_cgroup_counter_from_cgroup(
@@ -118,8 +119,10 @@ static void hugetlb_cgroup_init(struct h limit =round_down (PAGE_COUNTER_MAX ,pages_per_huge_page (&hstates[idx])); -VM_BUG_ON (page_counter_set_max (fault, limit)); -VM_BUG_ON (page_counter_set_max (rsvd, limit)); + ret =page_counter_set_max (fault, limit); +VM_WARN_ON_ONCE (ret); + ret =page_counter_set_max (rsvd, limit); +VM_WARN_ON_ONCE (ret); } }
Greg Kroah-Hartman
maintainerPATCH 174/556 nvdimm/btt: reject an arena whose nfree is below the lane count
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bryam Vargas <[email protected]>
commit 6a1f2e5ed9267ca19187038ac635393c165213ac upstream.
The BTT info block's nfree field, the number of reserve free blocks, is read from the medium without validation. btt_freelist_init() and btt_rtt_init() size the per-lane freelist[] and rtt[] arrays by nfree, but the I/O path indexes them by the lane from nd_region_acquire_lane(), which is bounded by nd_region->num_lanes (ND_MAX_LANES), not by nfree. A crafted or foreign arena whose nfree is below the lane count makes freelist[lane]/rtt[lane] run past the allocation: an out-of-bounds write.
btt.rst documents the nlanes = min(nfree, num_cpus) invariant, which the code does not currently honor: num_lanes is ND_MAX_LANES regardless of nfree. Reject an arena whose nfree is below num_lanes at discovery, before the per-lane arrays are allocated, enforcing that invariant.
--- drivers/nvdimm/btt.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/nvdimm/btt.c +8 -0
@@ -883,6 +883,14 @@ static int discover_arenas(struct btt *b arena->external_lba_start = cur_nlba;parse_arena_meta (arena, super, cur_off); +if (arena->nfree < btt->nd_region->num_lanes) { +dev_err (to_dev (arena), +"nfree %u smaller than lane count %d\n" , + arena->nfree, btt->nd_region->num_lanes); + ret = -ENODEV ; + goto out; + } + ret =log_set_indices (arena);if (ret) { dev_err(to_dev(arena),
Greg Kroah-Hartman
maintainerPATCH 175/556 parisc: eisa: Fix infinite loop when parsing invalid IRQ value
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pei Xiao <[email protected]>
commit 8b585431a16cfb9d8f2955a9fa0787ce3dceb3c2 upstream.
When an invalid value is passed via the "eisa_irq_edge=" kernel command line parameter (e.g. "eisa_irq_edge=16,5"), eisa_irq_setup() prints an error message and continues without advancing the current position. As a result the same invalid value is parsed again and again, causing an infinite loop while the kernel boots.
Advance to the next comma-separated entry, or stop parsing when there is no next entry, before continuing so that the remaining entries are processed normally.
--- drivers/parisc/eisa.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/parisc/eisa.c +5 -0
@@ -442,6 +442,11 @@ static int __init eisa_irq_setup(char *s val = (int )simple_strtoul (cur, &pe,0 );if (val >15 || val <0 ) {printk (KERN_ERR "eisa: EISA irq value are 0-15\n" ); + cur =strchr (cur,',' ); +if (cur) + cur++; +else +break ;continue ; }if (val ==2 ) {
Greg Kroah-Hartman
maintainerPATCH 176/556 parisc: Fix alignment of asm statements in head.S
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Helge Deller <[email protected]>
commit 04cf68c9a76e3c6b67ad056a66a14923abf85925 upstream.
All assembler statements need to be 4-byte aligned. Prevent a possible misalignment if someone changes the preceeding string and it's length is then suddenly not a multiple of 4 any longer.
--- arch/parisc/kernel/head.S | 1 + 1 file changed, 1 insertion(+)
arch/parisc/kernel/head.S +1 -0
@@ -105,6 +105,7 @@ $iodc_panic: or %r10,%r10,%r10 /* qemu idle sleep */ msg1: .ascii "Can't boot kernel which was built for PA8x00 CPUs on this machine.\r\n" msg1_end: + .align 4 $cpu_ok: #endif
Greg Kroah-Hartman
maintainerPATCH 177/556 powerpc/kexec_file: Fix null-ptr-def in extra size calculation
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jinjie Ruan <[email protected]>
commit 761eda315a6e1fda3e8e2185b28430771fb1ac29 upstream.
A static Sashiko AI review identified a potential NULL pointer dereference in kexec_extra_fdt_size_ppc64().
On platforms without any reserved memory regions, get_reserved_memory_ranges() can return 0 while leaving 'rmem' unallocated as NULL. Passing it directly leads to a kernel panic when evaluating 'rmem->nr_ranges'.
Add a NULL check for 'rmem' to prevent this crash.
--- arch/powerpc/kexec/file_load_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kexec/file_load_64.c +1 -1
@@ -664,7 +664,7 @@ unsigned int kexec_extra_fdt_size_ppc64( extra_size += (cpu_nodes - boot_cpu_node_count) *cpu_node_size ();/* Consider extra space for reserved memory ranges if any */ -if (rmem->nr_ranges >0 ) +if (rmem && rmem->nr_ranges >0 ) extra_size +=sizeof (struct fdt_reserve_entry ) * rmem->nr_ranges;return extra_size +kdump_extra_fdt_size_ppc64 (image, cpu_nodes);
Greg Kroah-Hartman
maintainerPATCH 178/556 powerpc/kexec_file: Prevent kexec range truncation
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jinjie Ruan <[email protected]>
commit fa40f9dbdd4af53e7445d9135b5b207eb8adf372 upstream.
Sashiko AI review pointed out the following issue.
The __merge_memory_ranges() function incorrectly handles overlapping memory ranges when merging them. Although sort_memory_ranges() sorts all ranges by their start address in ascending order beforehand, the merge logic remains defective in two ways:
1. It compares the current range's start against the previous element (i-1) instead of the running target index (idx)
2. It unconditionally overwrites 'ranges[idx].end' with 'ranges[i].end'.
This logic flaw leads to critical memory truncation when a larger memory range completely subsumes subsequent smaller ranges.
For example, consider a sorted input array with three ranges:
Range A (idx=0): [0x1000 - 0x9000]
Range B (i=1): [0x2000 - 0x5000] (completely inside Range A)
Range C (i=2): [0x6000 - 0x8000] (completely inside Range A)
1. When i=1 (Range B):
ranges[1].start (0x2000) <= ranges[0].end + 1 (0x9001) is TRUE. The code executes: ranges[0].end = ranges[1].end, which erroneously shrinks Range A's end from 0x9000 down to 0x5000.
2. When i=2 (Range C):
ranges[2].start (0x6000) <= ranges[1].end + 1 (0x5001) is FALSE. The code falls into the else block, creating a broken new range.
As a result, valid memory fragments [0x5001 - 0x5fff] and [0x8001 - 0x9000] are completely lost from the kexec exclude lists, potentially allowing the crash kernel to overwrite active memory, causing data corruption or crashes.
Fix this by ensuring the start of the current range is compared against the end of the active merged range (idx), and use max() to safely prevent the outer boundary from being truncated.
--- arch/powerpc/kexec/ranges.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
arch/powerpc/kexec/ranges.c +5 -7
@@ -21,6 +21,7 @@#include <linux/of.h> #include <linux/slab.h> #include <linux/memblock.h> +#include <linux/minmax.h> #include <linux/crash_core.h> #include <asm/sections.h> #include <asm/kexec_ranges.h>
@@ -105,19 +106,16 @@ static void __merge_memory_ranges(structstruct range *ranges;int i, idx; -if (!mem_rngs) +if (!mem_rngs || mem_rngs->nr_ranges <=1 )return ; idx =0 ; - ranges = &(mem_rngs->ranges[0 ]); + ranges = mem_rngs->ranges;for (i =1 ; i < mem_rngs->nr_ranges; i++) { -if (ranges[i].start <= (ranges[i-1 ].end +1 )) - ranges[idx].end = ranges[i].end; +if (ranges[i].start <= (ranges[idx].end +1 )) + ranges[idx].end =max (ranges[idx].end, ranges[i].end);else { idx++; -if (i == idx) -continue ; - ranges[idx] = ranges[i]; } }
Greg Kroah-Hartman
maintainerPATCH 179/556 powerpc/mm: fix wrong addr_pfn tracking in compound vmemmap population
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Muchun Song <[email protected]>
commit 89a4ae32764172468dea303eb6ae90fe6c859712 upstream.
vmemmap_populate_compound_pages() uses addr_pfn to determine the PFN offset within a compound page and to decide whether the current vmemmap slot should be populated as a head page mapping or should reuse a tail page mapping.
However, addr_pfn is advanced manually in parallel with addr. The loop itself progresses in vmemmap address space, so each PAGE_SIZE step in addr covers PAGE_SIZE / sizeof(struct page) struct page slots. Since addr_pfn is compared against nr_pages in data-PFN units, it should advance by the same number of PFNs. The existing manual increments do not match that and therefore do not reliably track the PFN corresponding to the current addr.
As a result, pfn_offset can be computed from the wrong PFN and the code can make the head/tail decision for the wrong compound-page position.
Fix this by deriving addr_pfn directly from the current vmemmap address instead of carrying it as loop state.
--- arch/powerpc/mm/book3s64/radix_pgtable.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
arch/powerpc/mm/book3s64/radix_pgtable.c +1 -6
@@ -1314,7 +1314,6 @@ int __meminit vmemmap_populate_compound_* covering out both edges. */ unsigned long addr; -unsigned long addr_pfn = start_pfn;unsigned long next;pgd_t *pgd;p4d_t *p4d;
@@ -1335,7 +1334,6 @@ int __meminit vmemmap_populate_compound_if (pmd_leaf (READ_ONCE (*pmd))) {/* existing huge mapping. Skip the range */ - addr_pfn += (PMD_SIZE >>PAGE_SHIFT ); next =pmd_addr_end (addr, end);continue ; }
@@ -1348,11 +1346,11 @@ int __meminit vmemmap_populate_compound_* page whose VMEMMAP_RESERVE_NR pages were mapped and * this request fall in those pages. */ - addr_pfn +=1 ; next = addr +PAGE_SIZE ;continue ; }else {unsigned long nr_pages =pgmap_vmemmap_nr (pgmap); +unsigned long addr_pfn =page_to_pfn ((struct page *)addr);unsigned long pfn_offset = addr_pfn -ALIGN_DOWN (addr_pfn, nr_pages);pte_t *tail_page_pte;
@@ -1376,7 +1374,6 @@ int __meminit vmemmap_populate_compound_if (!pte)return -ENOMEM ; - addr_pfn +=2 ; next = addr +2 *PAGE_SIZE ;continue ; }
@@ -1392,7 +1389,6 @@ int __meminit vmemmap_populate_compound_return -ENOMEM ;vmemmap_verify (pte, node, addr, addr +PAGE_SIZE ); - addr_pfn +=1 ; next = addr +PAGE_SIZE ;continue ; }
@@ -1402,7 +1398,6 @@ int __meminit vmemmap_populate_compound_return -ENOMEM ;vmemmap_verify (pte, node, addr, addr +PAGE_SIZE ); - addr_pfn +=1 ; next = addr +PAGE_SIZE ;continue ; }
Greg Kroah-Hartman
maintainerPATCH 180/556 powerpc/pseries: Handle and log pseries-wdt registration failures
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sourabh Jain <[email protected]>
commit e65b526affa621b50646cafdf6b06505af07032e upstream.
The pseries watchdog initialization registers the pseries-wdt platform device using platform_device_register_simple(), but currently ignores its return value.
Check the returned pointer for errors, log a descriptive error message when registration fails, and propagate the failure code to the caller. This avoids silently ignoring platform device registration failures.
--- arch/powerpc/platforms/pseries/setup.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
arch/powerpc/platforms/pseries/setup.c +12 -2
@@ -191,8 +191,18 @@ static void __init fwnmi_init(void)*/ static __init int pseries_wdt_init (void ) { -if (firmware_has_feature (FW_FEATURE_WATCHDOG )) -platform_device_register_simple ("pseries-wdt" ,0 ,NULL ,0 ); +struct platform_device *pdev; + +if (!firmware_has_feature (FW_FEATURE_WATCHDOG )) +return 0 ; + + pdev =platform_device_register_simple ("pseries-wdt" ,0 ,NULL ,0 ); + +if (IS_ERR (pdev)) { +pr_err ("Failed to register pseries-wdt platform device\n" ); +return PTR_ERR (pdev); + } +return 0 ; }machine_subsys_initcall (pseries, pseries_wdt_init);
Greg Kroah-Hartman
maintainerPATCH 181/556 powerpc/pseries: Move H_WATCHDOG definitions to a common header
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sourabh Jain <[email protected]>
commit 516a254918453ec99660201263d01189c082332c upstream.
The H_WATCHDOG input and output definitions are currently local to the pseries watchdog driver. The next patch in this series also needs these definitions to issue H_WATCHDOG hypercalls outside the watchdog driver.
Move the H_WATCHDOG definitions to a new common header, asm/papr-watchdog.h, so they can be shared without duplicating the PAPR watchdog definitions.
No functional changes.
--- arch/powerpc/include/asm/papr-watchdog.h | 58 +++++++++++++++++++++++++++++++ drivers/watchdog/pseries-wdt.c | 53 ---------------------------- 2 files changed, 59 insertions(+), 52 deletions(-) create mode 100644 arch/powerpc/include/asm/papr-watchdog.h
arch/powerpc/include/asm/papr-watchdog.h new file +58 -0
@@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _ASM_POWERPC_PAPR_WATCHDOG_H +#define _ASM_POWERPC_PAPR_WATCHDOG_H + +/* +* H_WATCHDOG Input +* +* R4: "flags": +* +* Bits 48-55: "operation" +*/ +#define PSERIES_WDTF_OP_START 0x100UL/* start timer */ +#define PSERIES_WDTF_OP_STOP 0x200UL/* stop timer */ +#define PSERIES_WDTF_OP_QUERY 0x300UL/* query timer capabilities */ + +/* +* Bits 56-63: "timeoutAction" (for "Start Watchdog" only) +*/ +#define PSERIES_WDTF_ACTION_HARD_POWEROFF 0x1UL/* poweroff */ +#define PSERIES_WDTF_ACTION_HARD_RESTART 0x2UL/* restart */ +#define PSERIES_WDTF_ACTION_DUMP_RESTART 0x3UL/* dump + restart */ + +/* +* H_WATCHDOG Output +* +* R3: Return code +* +* H_SUCCESS The operation completed. +* +* H_BUSY The hypervisor is too busy; retry the operation. +* +* H_PARAMETER The given "flags" are somehow invalid. Either the +* "operation" or "timeoutAction" is invalid, or a +* reserved bit is set. +* +* H_P2 The given "watchdogNumber" is zero or exceeds the +* supported maximum value. +* +* H_P3 The given "timeoutInMs" is below the supported +* minimum value. +* +* H_NOOP The given "watchdogNumber" is already stopped. +* +* H_HARDWARE The operation failed for ineffable reasons. +* +* H_FUNCTION The H_WATCHDOG hypercall is not supported by this +* hypervisor. +* +* R4: +* +* - For the "Query Watchdog Capabilities" operation, a 64-bit +* structure: +*/ +#define PSERIES_WDTQ_MIN_TIMEOUT (cap) (((cap) >> 48) & 0xffff) +#define PSERIES_WDTQ_MAX_NUMBER (cap) (((cap) >> 32) & 0xffff) + +#endif /* _ASM_POWERPC_PAPR_WATCHDOG_H */
drivers/watchdog/pseries-wdt.c +1 -52
62 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 182/556 powerpc/crash: stop watchdogs before booting kdump kernel
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sourabh Jain <[email protected]>
commit fb43ba4256543ce18ca0540fc37022bda438a293 upstream.
On pseries LPAR systems, watchdog timers configured from userspace can remain active after a kernel panic. When a panic triggers kdump, the crashing kernel jumps directly to the kdump kernel without stopping active watchdogs. As a result, the watchdogs remain active after the kdump kernel starts.
If dump capture takes longer than the watchdog timeout, PHYP resets the LPAR before the dump is fully captured, causing dump capture to fail.
Fix this by issuing the H_WATCHDOG hcall during the crash shutdown sequence to stop all active watchdogs before booting the kdump kernel.
--- arch/powerpc/include/asm/papr-watchdog.h | 6 ++++++ arch/powerpc/platforms/pseries/setup.c | 14 ++++++++++++++ 2 files changed, 20 insertions(+)
arch/powerpc/include/asm/papr-watchdog.h +6 -0
@@ -22,6 +22,12 @@#define PSERIES_WDTF_ACTION_DUMP_RESTART 0x3UL/* dump + restart */ /* +* R5: "watchdogNumber": +* PAPR says use -1 (all ones) to stop all watchdogs. +*/ +#define PSERIES_WDT_NUM_ALL ((unsigned long)-1) + +/* * H_WATCHDOG Output * * R3: Return code
arch/powerpc/platforms/pseries/setup.c +14 -0
@@ -77,6 +77,7 @@#include <asm/dtl.h> #include <asm/hvconsole.h> #include <asm/setup.h> +#include <asm/papr-watchdog.h> #include "pseries.h"
@@ -185,6 +186,16 @@ static void __init fwnmi_init(void)#endif } +static void pseries_crash_stop_watchdogs (void ) +{ +long rc; + + rc =plpar_hcall_norets_notrace (H_WATCHDOG ,PSERIES_WDTF_OP_STOP , +PSERIES_WDT_NUM_ALL ); +if (rc !=H_SUCCESS && rc !=H_NOOP ) +pr_warn ("Could not stop watchdogs before kdump rc=%ld\n" , rc); +} +/* * Affix a device for the first timer to the platform bus if * we have firmware support for the H_WATCHDOG hypercall.
@@ -203,6 +214,9 @@ static __init int pseries_wdt_init(void)return PTR_ERR (pdev); } +if (crash_shutdown_register (pseries_crash_stop_watchdogs)) +pr_warn ("Could not register watchdog crash shutdown handler\n" ); +return 0 ; }machine_subsys_initcall (pseries, pseries_wdt_init);
Greg Kroah-Hartman
maintainerPATCH 183/556 s390/vfio-ap: fix stale pqap_hook pointer on error in vfio_ap_mdev_set_kvm()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anthony Krowiak <[email protected]>
commit 4400270ec0348d05dc0439d8f0130853ce7f9e20 upstream.
In vfio_ap_mdev_set_kvm(), kvm->arch.crypto.pqap_hook is set to &matrix_mdev->pqap_hook before the update locks are acquired and the mdev list is checked for a conflicting assignment. If another mdev is already attached to the same KVM instance, the function returns -EPERM without restoring the hook pointer, leaving kvm->arch.crypto.pqap_hook pointing at the failing matrix_mdev instead of the mdev that legitimately owns the KVM.
Since matrix_mdev->kvm is never set on this error path, vfio_ap_mdev_unset_kvm() will not clean up the hook when matrix_mdev is later closed. If matrix_mdev is subsequently freed, any PQAP instruction executed by the guest will dereference the stale pointer through pqap_hook_rwsem, resulting in a use-after-free.
Since kvm->arch.crypto.pqap_hook is only set in the vfio_ap_mdev_set_kvm() function and is cleared in the vfio_ap_mdev_unset_kvm() function, a check for 'kvm->arch.crypto.pqap_hook != NULL' is all that is needed to determine whether it belongs to another mdev. This will alleviate the need to iterate the matrix_dev->mdev_list list to see if the kvm object is assigned to another mdev.This was introduced in v3 to alleviate the need to take the mdevs_lock while iterating the list; however, this did not prevent a potential race condition.
The pqap_hook_rwsem(write) is now performed inside get_update_locks_for_kvm(), which is updated to acquire pqap_hook_rwsem(write) between kvm->lock and mdevs_lock. This ordering is consistent with the PQAP intercept path, which acquires pqap_hook_rwsem in read mode while srcu is held under vcpu->mutex, establishing the
dependency: kvm->lock -> vcpu->mutex -> srcu -> pqap_hook_rwsem(read).
The pqap_hook_rwsem is now released inside the release_update_locks_for_kvm(), which is updated to release pqap_hook_rwsem(write) between mdevs_lock and kvm->lock.
Additionally, kvm_put_kvm() in vfio_ap_mdev_unset_kvm() is moved after release_update_locks_for_kvm(). Previously it was called while kvm->lock was held; if it were ever the last reference, kvm_destroy_vm() would run under kvm->lock, which would deadlock.
Message-ID: <[email protected]>
--- drivers/s390/crypto/vfio_ap_ops.c | 45 ++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 25 deletions(-)
drivers/s390/crypto/vfio_ap_ops.c +20 -25
@@ -48,15 +48,19 @@ static void vfio_ap_mdev_reset_queue(str* 1. matrix_dev->guests_lock: required to use the KVM pointer to update a KVM * guest's APCB. * 2. kvm->lock: required to update a guest's APCB -* 3. matrix_dev->mdevs_lock: required to access data stored in a matrix_mdev +* 3. kvm->arch.crypto.pqap_hook_rwsem: required to update pqap_hook and +* serialize against PQAP intercepts +* 4. matrix_dev->mdevs_lock: required to access data stored in a matrix_mdev * -* Note: If @kvm is NULL, the KVM lock will not be taken. +* Note: If @kvm is NULL, the KVM lock and pqap_hook_rwsem will not be taken. */ static inline void get_update_locks_for_kvm (struct kvm *kvm) {mutex_lock (&matrix_dev->guests_lock); -if (kvm) +if (kvm) {mutex_lock (&kvm->lock); +down_write (&kvm->arch.crypto.pqap_hook_rwsem); + }mutex_lock (&matrix_dev->mdevs_lock); }
@@ -68,16 +72,19 @@ static inline void get_update_locks_for_* * The proper unlocking order is: * 1. matrix_dev->mdevs_lock -* 2. kvm->lock -* 3. matrix_dev->guests_lock +* 2. kvm->arch.crypto.pqap_hook_rwsem +* 3. kvm->lock +* 4. matrix_dev->guests_lock * -* Note: If @kvm is NULL, the KVM lock will not be released. +* Note: If @kvm is NULL, the KVM lock and pqap_hook_rwsem will not be released. */ static inline void release_update_locks_for_kvm (struct kvm *kvm) {mutex_unlock (&matrix_dev->mdevs_lock); -if (kvm) +if (kvm) { +up_write (&kvm->arch.crypto.pqap_hook_rwsem);mutex_unlock (&kvm->lock); + }mutex_unlock (&matrix_dev->guests_lock); }
@@ -1821,26 +1828,17 @@ static const struct attribute_group *vfistatic int vfio_ap_mdev_set_kvm (struct ap_matrix_mdev *matrix_mdev,struct kvm *kvm) { -struct ap_matrix_mdev *m; -if (kvm->arch.crypto.crycbd) { -down_write (&kvm->arch.crypto.pqap_hook_rwsem); - kvm->arch.crypto.pqap_hook = &matrix_mdev->pqap_hook; -up_write (&kvm->arch.crypto.pqap_hook_rwsem); -get_update_locks_for_kvm (kvm); - -list_for_each_entry (m, &matrix_dev->mdev_list, node) { -if (m != matrix_mdev && m->kvm == kvm) { -release_update_locks_for_kvm (kvm); -return -EPERM ; - } +if (kvm->arch.crypto.pqap_hook) { +release_update_locks_for_kvm (kvm); +return -EPERM ; } + kvm->arch.crypto.pqap_hook = &matrix_mdev->pqap_hook;kvm_get_kvm (kvm); matrix_mdev->kvm = kvm;vfio_ap_mdev_update_guest_apcb (matrix_mdev); -release_update_locks_for_kvm (kvm); }
@@ -1883,18 +1881,15 @@ static void vfio_ap_mdev_unset_kvm(strucstruct kvm *kvm = matrix_mdev->kvm;if (kvm && kvm->arch.crypto.crycbd) { -down_write (&kvm->arch.crypto.pqap_hook_rwsem); - kvm->arch.crypto.pqap_hook =NULL ; -up_write (&kvm->arch.crypto.pqap_hook_rwsem); -get_update_locks_for_kvm (kvm); + kvm->arch.crypto.pqap_hook =NULL ;kvm_arch_crypto_clear_masks (kvm);vfio_ap_mdev_reset_queues (matrix_mdev); -kvm_put_kvm (kvm); matrix_mdev->kvm =NULL ;release_update_locks_for_kvm (kvm); +kvm_put_kvm (kvm); } }
Greg Kroah-Hartman
maintainerPATCH 184/556 s390/vfio-ap: Fix stale do_remove flag across iterations in vfio_ap_mdev_cfg_remove
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anthony Krowiak <[email protected]>
commit b1f092d94f621307927f145e3cc31893da51fc08 upstream.
The do_remove flag in vfio_ap_mdev_cfg_remove() is initialised to zero before the loop that iterates over the list of matrix mdevs, but is never reset at the start of each iteration. Since do_remove is OR-accumulated across iterations, a positive result from one mdev carries over to subsequent mdevs.
The fix is to set the do_remove flag with the first call to bitmap_and; for example: do_remove = bitmap_an rather than do_remove |= bitmap_and.
--- drivers/s390/crypto/vfio_ap_ops.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/s390/crypto/vfio_ap_ops.c +4 -4
@@ -2598,15 +2598,15 @@ static void vfio_ap_mdev_cfg_remove(unsiDECLARE_BITMAP (aprem,AP_DEVICES );DECLARE_BITMAP (aqrem,AP_DOMAINS );DECLARE_BITMAP (cdrem,AP_DOMAINS ); -int do_remove =0 ; +int do_remove;list_for_each_entry (matrix_mdev, &matrix_dev->mdev_list, node) {mutex_lock (&matrix_mdev->kvm->lock);mutex_lock (&matrix_dev->mdevs_lock); - do_remove |=bitmap_and (aprem, ap_remove, - matrix_mdev->matrix.apm, -AP_DEVICES ); + do_remove =bitmap_and (aprem, ap_remove, + matrix_mdev->matrix.apm, +AP_DEVICES ); do_remove |=bitmap_and (aqrem, aq_remove, matrix_mdev->matrix.aqm,AP_DOMAINS );
Greg Kroah-Hartman
maintainerPATCH 185/556 s390/vfio-ap: Fix control domain removal in vfio_ap_mdev_cfg_remove
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anthony Krowiak <[email protected]>
commit 6b8a02e216f6b520cc029e43ddc83956605135d5 upstream.
The vfio_ap_config_remove function uses the bitmap_andnot function to clear bits from the matrix_mdev->matrix.adm bitmap (specifies the control domains assigned to the mdev). This prevents the explicitly unplugged control domains from being removed the KVM guest. The bitmap_and function is used instead.
--- drivers/s390/crypto/vfio_ap_ops.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/s390/crypto/vfio_ap_ops.c +3 -3
@@ -2610,9 +2610,9 @@ static void vfio_ap_mdev_cfg_remove(unsi do_remove |=bitmap_and (aqrem, aq_remove, matrix_mdev->matrix.aqm,AP_DOMAINS ); - do_remove |=bitmap_andnot (cdrem, cd_remove, - matrix_mdev->matrix.adm, -AP_DOMAINS ); + do_remove |=bitmap_and (cdrem, cd_remove, + matrix_mdev->matrix.adm, +AP_DOMAINS );if (do_remove) vfio_ap_mdev_hot_unplug_cfg(matrix_mdev, aprem, aqrem,
Greg Kroah-Hartman
maintainerPATCH 186/556 s390/vfio-ap: Fix dereference matrix_mdev->kvm without checking for NULL
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anthony Krowiak <[email protected]>
commit d50346801b4f144e42b49cd4f1496010498ab114 upstream.
The ap_driver structure has two fields which are function pointers to callbacks:
* .on_config_changed: called at the start of the AP bus scan function to notify the device driver that the host AP configuration has changed and the associated AP devices will be added or removed accordingly. This gives the implementor a chance to evaluate the configuration changes and respond to them before the associated devices are added or removed.
* .on_scan_complete: Called at the end of the AP bus scan function to notify the device driver that the host AP configuration has changed and the AP devices have been added or removed accordingly. This gives the implementor the opportunity to respond to the changes after the associated devices are added or removed.
These two callbacks are implemented in the vfio_ap device driver via the vfio_ap_on_cfg_changed and vfio_ap_on_scan_complete functions respectively.
Within the call stack of these two callback functions the matrix_mdev->kvm->lock mutex is taken without checking whether matrix_mdev->kvm is NULL or not. If matrix_mdev->kvm has never been set, trying to take the lock will trigger a NULL pointer dereference. This patch adds checks for matrix_mdev->kvm == NULL before taking the matrix_mdev->kvm->lock mutex.
Note that the matrix_mdev->kvm->lock mutex taken in the vfio_ap_mdev_hot_plug_config function is moved to the calling function along with the matrix_dev->mdevs_lock which is needed there to access the fields of the matrix_mdev. It makes little sense to make the change the check for matrix_mdev->kvm there before taking the kvm->lock mutex only to have to move it out via another patch, so it is done in this patch.
It is important to make note of the following:
1. The matrix_dev->guests_lock is acquired at the start of both callback functions. This ensures that matrix_mdev will not be removed via the vfio_ap_mdev_remove function because it too takes matrix_dev_guests_lock before removing the object; so, matrix_mdev will be available for the duration of the callback functions.
2. The matrix_dev->mdevs_lock mutex must be taken in order to access fields within the matrix_mdev structure
3. matrix_mdev->kvm->lock mutex must be taken before the matrix_dev->mdevs_lock to prevent a lockdep splat.
4: The kvm->lock must be held while plugging the guest's AP configuration
into its SIE state description via the vfio_ap_mdev_update_guest_apcb function.
5. The vfio_ap_mdev_update_guest_apcb checks matrix_mdev->kvm to verify it is not NULL before doing the hot plug of the guest's AP configuration.
--- drivers/s390/crypto/vfio_ap_ops.c | 39 +++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-)
drivers/s390/crypto/vfio_ap_ops.c +30 -9
@@ -2600,8 +2600,20 @@ static void vfio_ap_mdev_cfg_remove(unsiDECLARE_BITMAP (cdrem,AP_DOMAINS );int do_remove; +/* +* It is safe to traverse this list here because the +* required guard - matrix_dev->guests_lock - is taken in the +* vfio_ap_on_cfg_changed function prior to this function getting +* called. +*/ list_for_each_entry (matrix_mdev, &matrix_dev->mdev_list, node) { -mutex_lock (&matrix_mdev->kvm->lock); +/* +* The mdevs_lock must be held to access fields within matrix_mdev, +* and kvm->lock must be taken before mdevs_lock to satisfy the lock +* ordering requirement and prevent a lockdep splat. +*/ +if (matrix_mdev->kvm) +mutex_lock (&matrix_mdev->kvm->lock);mutex_lock (&matrix_dev->mdevs_lock); do_remove = bitmap_and(aprem, ap_remove,
@@ -2619,7 +2631,8 @@ static void vfio_ap_mdev_cfg_remove(unsi cdrem);mutex_unlock (&matrix_dev->mdevs_lock); -mutex_unlock (&matrix_mdev->kvm->lock); +if (matrix_mdev->kvm) +mutex_unlock (&matrix_mdev->kvm->lock); } }
@@ -2816,9 +2829,6 @@ static void vfio_ap_mdev_hot_plug_cfg(stDECLARE_BITMAP (apm_filtered,AP_DEVICES );bool filter_domains, filter_adapters, filter_cdoms, do_hotplug = false; -mutex_lock (&matrix_mdev->kvm->lock); -mutex_lock (&matrix_dev->mdevs_lock); - filter_adapters =bitmap_intersects (matrix_mdev->matrix.apm, matrix_mdev->apm_add,AP_DEVICES ); filter_domains = bitmap_intersects(matrix_mdev->matrix.aqm,
@@ -2836,9 +2846,6 @@ static void vfio_ap_mdev_hot_plug_cfg(stvfio_ap_mdev_update_guest_apcb (matrix_mdev);reset_queues_for_apids (matrix_mdev, apm_filtered); - -mutex_unlock (&matrix_dev->mdevs_lock); -mutex_unlock (&matrix_mdev->kvm->lock); } void vfio_ap_on_scan_complete(struct ap_config_info *new_config_info,
@@ -2849,15 +2856,29 @@ void vfio_ap_on_scan_complete(struct ap_mutex_lock (&matrix_dev->guests_lock);list_for_each_entry (matrix_mdev, &matrix_dev->mdev_list, node) { +/* +* The mdevs_lock must be held to access fields within matrix_mdev, +* and kvm->lock must be taken before mdevs_lock to satisfy the lock +* ordering requirement and prevent a lockdep splat. +*/ +if (matrix_mdev->kvm) +mutex_lock (&matrix_mdev->kvm->lock); +mutex_lock (&matrix_dev->mdevs_lock); +if (bitmap_empty (matrix_mdev->apm_add,AP_DEVICES ) &&bitmap_empty (matrix_mdev->aqm_add,AP_DOMAINS ) &&bitmap_empty (matrix_mdev->adm_add,AP_DOMAINS )) -continue ; + goto do_unlock;vfio_ap_mdev_hot_plug_cfg (matrix_mdev);bitmap_clear (matrix_mdev->apm_add,0 ,AP_DEVICES );bitmap_clear (matrix_mdev->aqm_add,0 ,AP_DOMAINS );bitmap_clear (matrix_mdev->adm_add,0 ,AP_DOMAINS ); + +do_unlock: +mutex_unlock (&matrix_dev->mdevs_lock); +if (matrix_mdev->kvm) +mutex_unlock (&matrix_mdev->kvm->lock); }mutex_unlock (&matrix_dev->guests_lock);
Greg Kroah-Hartman
maintainerPATCH 187/556 s390/vfio-ap: Fix hot-unplug skipped when last AP adapter or domain removed
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anthony Krowiak <[email protected]>
commit 917f509bfb88048094dbb85c4e9dbc4d6fe4a886 upstream.
The vfio_ap_mdev_hot_unplug_cfg() function uses the return value of bitmap_andnot() to determine whether the guest APCB needs to be updated. However, bitmap_andnot() returns false when the resulting destination bitmap is empty. This means that if the only adapter, domain or control domain assigned to an mdev is removed from the host's AP configuration, the bit is correctly cleared from the shadow APCB, but bitmap_andnot() returns false because the result is an empty bitmap. Consequently, do_hotplug remains 0 and vfio_ap_mdev_update_guest_apcb() is never called, leaving the KVM guest with stale hardware access to the unplugged AP devices.
Fix this by replacing the bitmap_andnot() return value check with bitmap_intersects() to determine whether the shadow APCB actually overlaps with the removal mask. If there is an intersection, call bitmap_andnot() solely for its side effect of clearing the bits, then unconditionally set do_hotplug to trigger the guest APCB update.
--- drivers/s390/crypto/vfio_ap_ops.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-)
drivers/s390/crypto/vfio_ap_ops.c +17 -13
@@ -2554,24 +2554,28 @@ static void vfio_ap_mdev_hot_unplug_cfg(unsigned long *aqrem, unsigned long *cdrem) { - int do_hotplug = 0; + bool do_hotplug = false; -if (!bitmap_empty (aprem,AP_DEVICES )) { - do_hotplug |=bitmap_andnot (matrix_mdev->shadow_apcb.apm, - matrix_mdev->shadow_apcb.apm, - aprem,AP_DEVICES ); +if (bitmap_intersects (matrix_mdev->shadow_apcb.apm, aprem,AP_DEVICES )) { +bitmap_andnot (matrix_mdev->shadow_apcb.apm, + matrix_mdev->shadow_apcb.apm, + aprem,AP_DEVICES ); + do_hotplug = true; } -if (!bitmap_empty (aqrem,AP_DOMAINS )) { - do_hotplug |=bitmap_andnot (matrix_mdev->shadow_apcb.aqm, - matrix_mdev->shadow_apcb.aqm, - aqrem,AP_DEVICES ); +if (bitmap_intersects (matrix_mdev->shadow_apcb.aqm, aqrem,AP_DOMAINS )) { +bitmap_andnot (matrix_mdev->shadow_apcb.aqm, + matrix_mdev->shadow_apcb.aqm, + aqrem,AP_DOMAINS ); + do_hotplug = true; } -if (!bitmap_empty (cdrem,AP_DOMAINS )) - do_hotplug |=bitmap_andnot (matrix_mdev->shadow_apcb.adm, - matrix_mdev->shadow_apcb.adm, - cdrem,AP_DOMAINS ); +if (bitmap_intersects (matrix_mdev->shadow_apcb.adm, cdrem,AP_DOMAINS )) { +bitmap_andnot (matrix_mdev->shadow_apcb.adm, + matrix_mdev->shadow_apcb.adm, + cdrem,AP_DOMAINS ); + do_hotplug = true; + }if (do_hotplug)vfio_ap_mdev_update_guest_apcb (matrix_mdev);
Greg Kroah-Hartman
maintainerPATCH 188/556 s390/vfio-ap: Fix missing lock required to access list of ap_matrix_mdev objects
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anthony Krowiak <[email protected]>
commit 7fa61c29850d05e40ca9ed41bfdf57673023f581 upstream.
In order to traverse or add/remove ap_matrix_mdev objects in the matrix_dev->mdev_list, the matrix_dev->guests_lock mutex must be held. There are two functions that access the list without holding the mutex:
vfio_ap_mdev_probe function
~~~~~~~~~~~~~~~~~~~~~~~~~~~
The vfio_ap_mdev_probe function uses the matrix_dev->mdevs_lock mutex to guard the add of a newly created ap_matrix_mdev object to the matrix_dev->mdev_list. This mutex does not protect list access; its purpose is to guard against concurrent access to fields contained in an ap_matrix_mdev object. This could lead to kernel memory corruption or use-after-free if another mdev is created or removed concurrently.
The adding of an ap_matrix_mdev object to matrix_dev->mdev_list is now guarded by the matrix_dev->guests_lock which is the correct way to protect against concurrent mdev_list access.
Also removed the following two lines of code because the matrix_mdev is allocated via vfio_alloc_device macro which uses kzalloc, so req_trigger and cfg_chg_trigger are already zero-initialised when the struct is allocated before the call to vfio_register_emulated_iommu_dev. This prevents a window whereby these triggers are set to NULL after the device is exposed to userspace.
matrix_mdev->req_trigger = NULL;matrix_mdev->cfg_chg_trigger = NULL;
vfio_ap_mdev_for_queue function
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The status_show function that supports display of the status attribute of the devices in /sys/bus/ap/devices calls the vfio_ap_mdev_for_queue function which iterates the matrix_dev->mdev_list to find the object representing the queue device whose status is to be displayed. In order to traverse this list, the matrix_dev->guests_lock mutex must be held.
To fix this, the guests_lock mutex is taken prior to taking the matrix_dev->mdevs_lock mutex in the status_show function. It is taken there rather than the vfio_ap_mdev_for_queue function - where it is needed - because it must be taken prior to the mdevs_lock mutex in order to adhere to the proper locking order and prevent a lockdep splat; also because the mdevs_lock is needed there to access fields within the matrix_mdev object in that function.
See the vfio-ap-locking.rst in the linux kernel tree.
--- drivers/s390/crypto/vfio_ap_ops.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-)
drivers/s390/crypto/vfio_ap_ops.c +23 -4
@@ -807,12 +807,17 @@ static int vfio_ap_mdev_probe(struct mde ret =vfio_register_emulated_iommu_dev (&matrix_mdev->vdev);if (ret) goto err_put_vdev; - matrix_mdev->req_trigger =NULL ; - matrix_mdev->cfg_chg_trigger =NULL ; + +/* +* Take the matrix_dev->guests_lock mutex before adding the matrix_mdev +* to the mdev_list. All functions that traverse the list must also hold +* this lock to guard against additions to or removals from the list +* while it is being traversed. +*/ +mutex_lock (&matrix_dev->guests_lock);dev_set_drvdata (&mdev->dev, matrix_mdev); -mutex_lock (&matrix_dev->mdevs_lock);list_add (&matrix_mdev->node, &matrix_dev->mdev_list); -mutex_unlock (&matrix_dev->mdevs_lock); +mutex_unlock (&matrix_dev->guests_lock);return 0 ; err_put_vdev:
@@ -2292,6 +2297,8 @@ static struct ap_matrix_mdev *vfio_ap_mdunsigned long apid =AP_QID_CARD (q->apqn);unsigned long apqi =AP_QID_QUEUE (q->apqn); +lockdep_assert_held (&matrix_dev->guests_lock); +list_for_each_entry (matrix_mdev, &matrix_dev->mdev_list, node) {if (test_bit_inv (apid, matrix_mdev->matrix.apm) &&test_bit_inv (apqi, matrix_mdev->matrix.aqm))
@@ -2311,6 +2318,7 @@ static ssize_t status_show(struct devicestruct ap_matrix_mdev *matrix_mdev;struct ap_device *apdev =to_ap_dev (dev); +mutex_lock (&matrix_dev->guests_lock);mutex_lock (&matrix_dev->mdevs_lock); q =dev_get_drvdata (&apdev->device); matrix_mdev =vfio_ap_mdev_for_queue (q);
@@ -2338,6 +2346,7 @@ static ssize_t status_show(struct device }mutex_unlock (&matrix_dev->mdevs_lock); +mutex_unlock (&matrix_dev->guests_lock);return nchars; }
@@ -2760,6 +2769,12 @@ static void vfio_ap_mdev_cfg_add(unsignevfio_ap_filter_apid_by_qtype (apm_add, aqm_add); +/* +* It is safe to traverse this list here because the +* required guard - matrix_dev->guests_lock - is taken in the +* vfio_ap_on_cfg_changed function prior to this function getting +* called. +*/ list_for_each_entry (matrix_mdev, &matrix_dev->mdev_list, node) {bitmap_and (matrix_mdev->apm_add, matrix_mdev->matrix.apm, apm_add,AP_DEVICES );
@@ -2819,6 +2834,10 @@ void vfio_ap_on_cfg_changed(struct ap_coif (!cur_cfg_info || !prev_cfg_info)return ; +/* +* Take the guests_lock mutex here to guard access to the +* matrix_dev->mdev_list in the two functions called below. +*/ mutex_lock (&matrix_dev->guests_lock);vfio_ap_mdev_on_cfg_remove (cur_cfg_info, prev_cfg_info);
Greg Kroah-Hartman
maintainerPATCH 189/556 s390/vfio-ap: Fix NULL deref in status_show() during queue probe
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anthony Krowiak <[email protected]>
commit dd6f4ef6f8a37412909ad787c837332fb070159c upstream.
When vfio_ap_mdev_probe_queue() creates the sysfs attribute group, the queue's driver data has not yet been set. A concurrent read of the 'status' attribute can therefore call dev_get_drvdata() and get NULL, which is then passed directly to vfio_ap_mdev_for_queue() where q->apqn is unconditionally dereferenced, causing a NULL pointer dereference.
Fix this by acquiring the update locks before calling sysfs_create_group(). The status_show() function acquires guests_lock before reading the driver data, so any concurrent read will block until after dev_set_drvdata() has been called and the update locks are released.
As a bonus, the APQN no longer needs to be read from the queue struct after allocation — it can be read directly from apdev before allocation and stored in a local variable, which is then assigned to q->apqn once the allocation succeeds.
--- drivers/s390/crypto/vfio_ap_ops.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-)
drivers/s390/crypto/vfio_ap_ops.c +29 -4
@@ -2321,6 +2321,23 @@ static ssize_t status_show(struct devicemutex_lock (&matrix_dev->guests_lock);mutex_lock (&matrix_dev->mdevs_lock); q =dev_get_drvdata (&apdev->device); + +/* +* Make sure the drvdata has been set before proceeding. There is a +* possibility that the drvdata was not set if the vfio_ap_queue object +* could not be allocated when the queue device was probed. In that case, +* the locks used in vfio_ap_mdev_probe_queue() are released prior to +* removing the sysfs status attribute to avoid a lockdep +* splat. That opens a very small window where the status attribute is +* still available without the vfio_ap_queue object having been +* stored in the device drvdata. In that case, indicate the queue is not +* assigned. +*/ +if (!q) { + nchars =sysfs_emit (buf,"%s\n" ,AP_QUEUE_UNASSIGNED ); + goto done; + } + matrix_mdev =vfio_ap_mdev_for_queue (q);/* If the queue is assigned to the matrix mediated device, then
@@ -2345,6 +2362,7 @@ static ssize_t status_show(struct device nchars =sysfs_emit (buf,"%s\n" ,AP_QUEUE_UNASSIGNED ); } +done:mutex_unlock (&matrix_dev->mdevs_lock);mutex_unlock (&matrix_dev->guests_lock);
@@ -2419,14 +2437,17 @@ void vfio_ap_mdev_unregister(void)int vfio_ap_mdev_probe_queue (struct ap_device *apdev) { -int ret; +int ret, apqn;struct vfio_ap_queue *q;DECLARE_BITMAP (apm_filtered,AP_DEVICES );struct ap_matrix_mdev *matrix_mdev; + apqn =to_ap_queue (&apdev->device)->qid; + matrix_mdev =get_update_locks_by_apqn (apqn); + ret =sysfs_create_group (&apdev->device.kobj, &vfio_queue_attr_group);if (ret) -return ret; + goto err_release_locks; q =kzalloc_obj (*q);if (!q) {
@@ -2434,11 +2455,10 @@ int vfio_ap_mdev_probe_queue(struct ap_d goto err_remove_group; } - q->apqn =to_ap_queue (&apdev->device)->qid; + q->apqn = apqn; q->saved_isc =VFIO_AP_ISC_INVALID ;memset (&q->reset_status,0 ,sizeof (q->reset_status));INIT_WORK (&q->reset_work, apq_reset_check); - matrix_mdev =get_update_locks_by_apqn (q->apqn);if (matrix_mdev) {vfio_ap_mdev_link_queue (matrix_mdev, q);
@@ -2467,8 +2487,13 @@ done:return ret; err_remove_group: +release_update_locks_for_mdev (matrix_mdev);sysfs_remove_group (&apdev->device.kobj, &vfio_queue_attr_group);return ret; + +err_release_locks: +release_update_locks_for_mdev (matrix_mdev); +return ret; }void vfio_ap_mdev_remove_queue (struct ap_device *apdev)
Greg Kroah-Hartman
maintainerPATCH 190/556 s390/vfio-ap: fix potential use of uninitialized apm_filtered bitmap
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anthony Krowiak <[email protected]>
commit bf09b9d7cd7890bc3a3b7eb63d5ece15f88bfde7 upstream.
The DECLARE_BITMAP(apm_filtered, AP_DEVICES) macro allocates the bitmap on the stack without zero-initializing it.
In vfio_ap_mdev_hot_plug_cfg(), the vfio_ap_mdev_filter_matrix() function is only called to initialize and populate apm_filtered if either filter_adapters or filter_domains is true. If the hot plug configuration change only adds control domains (meaning filter_cdoms is true, but filter_adapters and filter_domains are both false), vfio_ap_mdev_filter_matrix() is bypassed.
Consequently, apm_filtered is passed to reset_queues_for_apids() with uninitialized stack garbage. This can cause reset_queues_for_apids() to interpret arbitrary stack garbage bits as valid APIDs to reset, potentially performing unintended guest hardware queue resets.
Fix this by zero-initializing the apm_filtered bitmap at the beginning of vfio_ap_mdev_hot_plug_cfg() using bitmap_zero().
--- drivers/s390/crypto/vfio_ap_ops.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/s390/crypto/vfio_ap_ops.c +9 -0
@@ -2877,6 +2877,15 @@ static void vfio_ap_mdev_hot_plug_cfg(stDECLARE_BITMAP (apm_filtered,AP_DEVICES );bool filter_domains, filter_adapters, filter_cdoms, do_hotplug = false; +/* +* Zero out the apm_filtered bitmap in case there are no adapters or +* domains to be added, but only control domains. In that case, +* vfio_ap_mdev_filter_matrix() - which initializes apm_filtered - will +* not get called and the reset_queues_for_apids will crash because it +* will access an uninitialized bitmap. +*/ +bitmap_zero (apm_filtered,AP_DEVICES ); + filter_adapters =bitmap_intersects (matrix_mdev->matrix.apm, matrix_mdev->apm_add,AP_DEVICES ); filter_domains = bitmap_intersects(matrix_mdev->matrix.aqm,
Greg Kroah-Hartman
maintainerPATCH 191/556 s390/vfio-ap: Fix required lock not held during update of ap_matrix_mdev object
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Anthony Krowiak <[email protected]>
commit 5883528250be57fa92270459b33603ff52de0a91 upstream.
In the vfio_ap_mdev_cfg_add function, the apm_add, aqm_add and adm_add fields of an ap_matrix_mdev object fields are modified while not holding the matrix_dev->mdevs_lock. This lock must be held while making these to guard against a race condition with another caller that may be concurrently modifying these fields or any of the fields in the matrix_mdev->matrix.
--- drivers/s390/crypto/vfio_ap_ops.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/s390/crypto/vfio_ap_ops.c +8 -0
@@ -2801,12 +2801,20 @@ static void vfio_ap_mdev_cfg_add(unsigne* called. */ list_for_each_entry (matrix_mdev, &matrix_dev->mdev_list, node) { +/* +* The mdevs_lock must be held in order to access fields +* within matrix_mdev +*/ +mutex_lock (&matrix_dev->mdevs_lock); +bitmap_and (matrix_mdev->apm_add, matrix_mdev->matrix.apm, apm_add,AP_DEVICES );bitmap_and (matrix_mdev->aqm_add, matrix_mdev->matrix.aqm, aqm_add,AP_DOMAINS );bitmap_and (matrix_mdev->adm_add, matrix_mdev->matrix.adm, adm_add,AP_DEVICES ); + +mutex_unlock (&matrix_dev->mdevs_lock); } }
Greg Kroah-Hartman
maintainerPATCH 192/556 mtd: afs: validate v2 image info bounds
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
commit e9290031f736e99ad17c25c00311c92c266843b7 upstream.
The AFS v2 parser uses footer[8] to locate the image information block inside the current erase block, then uses the image information region_count to walk entries from a fixed local array. The footer offset and region count come from flash contents and are not checked against the erase block or the local image-info array before use.
Reject v2 entries whose image information offset would underflow the erase block calculation, and reject region counts that cannot fit in the local image-info array before walking region entries.
--- drivers/mtd/parsers/afs.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/mtd/parsers/afs.c +7 -0
@@ -235,6 +235,9 @@ static int afs_parse_v2_partition(structpr_debug ("Parsing v2 partition @%08x-%08x\n" , off, off + mtd->erasesize); +if (mtd->erasesize <sizeof (footer)) +return -EINVAL ; +/* First read the footer */ ptr = off + mtd->erasesize -sizeof (footer); ret =mtd_read (mtd, ptr,sizeof (footer), &sz, (u_char *)footer);
@@ -245,6 +248,8 @@ static int afs_parse_v2_partition(struct } name = (char *) &footer[0 ]; version = footer[9 ]; +if (footer[8 ] > mtd->erasesize -sizeof (footer)) +return -EINVAL ; ptr = off + mtd->erasesize -sizeof (footer) - footer[8 ]; pr_debug("found image \"%s\", version %08x, info @%08x\n",
@@ -278,6 +283,8 @@ static int afs_parse_v2_partition(struct entrypoint = imginfo[pad]; attributes = imginfo[pad+1 ]; region_count = imginfo[pad+2 ]; +if (region_count > (ARRAY_SIZE (imginfo) - pad -3 ) /4 ) +return -EINVAL ; block_start = imginfo[20 ]; block_end = imginfo[21 ];
Greg Kroah-Hartman
maintainerPATCH 193/556 mtd: mtdoops: free page bitmap when the backing MTD is removed
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xu Rao <[email protected]>
commit 956e7da12c114f13c63d126ab1d79c3b6a819060 upstream.
mtdoops_notify_add() allocates oops_page_used when the configured MTD device is registered. mtdoops_notify_remove() detaches from that device but leaves the bitmap allocated. If the same MTD device is later registered again, the add path allocates a new bitmap and overwrites the old pointer, leaking one vmalloc allocation per remove/add cycle.
This is only visible when the backing MTD device can disappear and be registered again while mtdoops remains loaded, so the usual static MTD case does not expose it.
Free the bitmap after unregistering the dumper and flushing the pending workers, then clear the pointer and page count before a later attach can allocate fresh state. Clearing the pointer also keeps the module exit path from freeing the same bitmap a second time after a remove event.
--- drivers/mtd/mtdoops.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mtd/mtdoops.c +3 -0
@@ -392,6 +392,9 @@ static void mtdoops_notify_remove(struct cxt->mtd =NULL ;flush_work (&cxt->work_erase);flush_work (&cxt->work_write); +vfree (cxt->oops_page_used); + cxt->oops_page_used =NULL ; + cxt->oops_pages =0 ; }
Greg Kroah-Hartman
maintainerPATCH 194/556 mtd: nand: realtek-ecc: add missing MODULE_DEVICE_TABLE()
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
commit 5b2444b4d575d8117809c57801562ef37ca2d4af upstream.
The Realtek external ECC engine driver has an OF match table wired into its platform driver, but the table is not exported with MODULE_DEVICE_TABLE().
When the driver is built as a module, the missing OF module alias prevents automatic module loading from the compatible string.
Add the missing MODULE_DEVICE_TABLE() entry.
--- drivers/mtd/nand/ecc-realtek.c | 1 + 1 file changed, 1 insertion(+)
drivers/mtd/nand/ecc-realtek.c +1 -0
@@ -450,6 +450,7 @@ static const struct of_device_id rtl_ecc }, { /* sentinel */ }, }; +MODULE_DEVICE_TABLE (of, rtl_ecc_of_ids);static struct platform_driver rtl_ecc_driver = { .driver = {
Greg Kroah-Hartman
maintainerPATCH 195/556 mtd: rawnand: pl353: Make sure we use the monolithic helpers for raw accesses
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miquel Raynal (DAVE) <[email protected]>
commit 80ecacd054ffeb60cd28e46ed5cd6bd0d2de318b upstream.
Any access not using the hardware ECC engine should be monolithic because the controller has its very own way of handling the end of a transaction during operation configuration, so we cannot easily make repeated reads.
This has the side effect of fixing support for software ECC engines.
--- drivers/mtd/nand/raw/pl35x-nand-controller.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/mtd/nand/raw/pl35x-nand-controller.c +3 -2
@@ -914,7 +914,6 @@ static int pl35x_nand_init_hw_ecc_contro chip->ecc.steps = mtd->writesize / chip->ecc.size; chip->ecc.read_page = pl35x_nand_read_page_hwecc; chip->ecc.write_page = pl35x_nand_write_page_hwecc; - chip->ecc.write_page_raw = nand_monolithic_write_page_raw;pl35x_smc_set_ecc_pg_size (nfc, chip, mtd->writesize); nfc->ecc_buf = devm_kmalloc(nfc->dev, chip->ecc.bytes * chip->ecc.steps,
@@ -981,7 +980,6 @@ static int pl35x_nand_attach_chip(structcase NAND_ECC_ENGINE_TYPE_NONE :case NAND_ECC_ENGINE_TYPE_SOFT :dev_dbg (nfc->dev,"Using software ECC (Hamming 1-bit/512B)\n" ); - chip->ecc.write_page_raw = nand_monolithic_write_page_raw;break ;case NAND_ECC_ENGINE_TYPE_ON_HOST :dev_dbg (nfc->dev,"Using hardware ECC\n" );
@@ -995,6 +993,9 @@ static int pl35x_nand_attach_chip(structreturn -EINVAL ; } + chip->ecc.read_page_raw = nand_monolithic_read_page_raw; + chip->ecc.write_page_raw = nand_monolithic_write_page_raw; +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 196/556 mtd: rawnand: sunxi: group controller delay tables
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Hilliard <[email protected]>
commit 9f2e033754c6c023150f184b4e72bbcc5d6eea13 upstream.
The tWB and tRHW timing field encodings are controller properties, but they currently live in standalone lookup tables.
Group them in a timing descriptor selected through the controller capability data. Point every existing controller at the legacy values so this is a pure preparation change.
--- drivers/mtd/nand/raw/sunxi_nand.c | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-)
drivers/mtd/nand/raw/sunxi_nand.c +28 -8
@@ -237,6 +237,14 @@ struct sunxi_nand_hw_ecc {u32 ecc_ctl; }; +#define SUNXI_NFC_TIMING_STEPS 4 + +/* Delay arrays contain internal NDFC clock cycles for field values 0 to 3. */ +struct sunxi_nfc_timings { +s32 tWB[SUNXI_NFC_TIMING_STEPS ]; +s32 tRHW[SUNXI_NFC_TIMING_STEPS ]; +}; +/** * struct sunxi_nand_chip - stores NAND chip device related information *
@@ -301,6 +309,7 @@ static inline struct sunxi_nand_chip *to* bytes to write * @nuser_data_tab: Size of @user_data_len_tab * @sram_size: Size of the NAND controller SRAM +* @timings: Controller timing characteristics */ struct sunxi_nfc_caps {bool has_mdma;
@@ -327,6 +336,7 @@ struct sunxi_nfc_caps {unsigned int nuser_data_tab;unsigned int max_ecc_steps;int sram_size; +const struct sunxi_nfc_timings *timings; };/**
@@ -1667,8 +1677,10 @@ static int sunxi_nfc_hw_ecc_write_oob(streturn nand_prog_page_end_op (nand); } -static const s32 tWB_lut[] = {6 ,12 ,16 ,20 }; -static const s32 tRHW_lut[] = {4 ,8 ,12 ,20 }; +static const struct sunxi_nfc_timings sun4i_a10_nfc_timings = { + .tWB = {6 ,12 ,16 ,20 }, + .tRHW = {4 ,8 ,12 ,20 }, +};static int _sunxi_nand_lookup_timing (const s32 *lut,int lut_size,u32 duration,u32 clk_period)
@@ -1693,6 +1705,7 @@ static int sunxi_nfc_setup_interface(str {struct sunxi_nand_chip *sunxi_nand =to_sunxi_nand (nand);struct sunxi_nfc *nfc =to_sunxi_nfc (sunxi_nand->nand.controller); +const struct sunxi_nfc_timings *nfc_timings = nfc->caps->timings;const struct nand_sdr_timings *timings;u32 min_clk_period =0 ;s32 tWB, tADL, tWHR, tRHW, tCAD;
@@ -1763,8 +1776,10 @@ static int sunxi_nfc_setup_interface(str min_clk_period =DIV_ROUND_UP (timings->tWC_min,2 );/* T16 - T19 + tCAD */ -if (timings->tWB_max > (min_clk_period *20 )) - min_clk_period =DIV_ROUND_UP (timings->tWB_max,20 ); +if (timings->tWB_max > + (min_clk_period * nfc_timings->tWB[SUNXI_NFC_TIMING_STEPS -1 ])) + min_clk_period =DIV_ROUND_UP (timings->tWB_max, + nfc_timings->tWB[SUNXI_NFC_TIMING_STEPS -1 ]);if (timings->tADL_min > (min_clk_period *32 )) min_clk_period =DIV_ROUND_UP (timings->tADL_min,32 );
@@ -1772,8 +1787,10 @@ static int sunxi_nfc_setup_interface(strif (timings->tWHR_min > (min_clk_period *32 )) min_clk_period =DIV_ROUND_UP (timings->tWHR_min,32 ); -if (timings->tRHW_min > (min_clk_period *20 )) - min_clk_period =DIV_ROUND_UP (timings->tRHW_min,20 ); +if (timings->tRHW_min > + (min_clk_period * nfc_timings->tRHW[SUNXI_NFC_TIMING_STEPS -1 ])) + min_clk_period =DIV_ROUND_UP (timings->tRHW_min, + nfc_timings->tRHW[SUNXI_NFC_TIMING_STEPS -1 ]);/* * In non-EDO, tREA should be less than tRP to guarantee that the
@@ -1789,7 +1806,7 @@ static int sunxi_nfc_setup_interface(strif (timings->tREA_max > min_clk_period && !timings->tRLOH_min) min_clk_period = timings->tREA_max; - tWB =sunxi_nand_lookup_timing (tWB_lut, timings->tWB_max, + tWB =sunxi_nand_lookup_timing (nfc_timings->tWB, timings->tWB_max, min_clk_period);if (tWB <0 ) {dev_err (nfc->dev,"unsupported tWB\n" );
@@ -1808,7 +1825,7 @@ static int sunxi_nfc_setup_interface(strreturn -EINVAL ; } - tRHW =sunxi_nand_lookup_timing (tRHW_lut, timings->tRHW_min, + tRHW =sunxi_nand_lookup_timing (nfc_timings->tRHW, timings->tRHW_min, min_clk_period);if (tRHW <0 ) {dev_err (nfc->dev,"unsupported tRHW\n" );
@@ -2595,6 +2612,7 @@ static const struct sunxi_nfc_caps sunxi .nstrengths = ARRAY_SIZE(sunxi_ecc_strengths_a10), .max_ecc_steps = 16, .sram_size = 1024, + .timings = &sun4i_a10_nfc_timings, };static const struct sunxi_nfc_caps sunxi_nfc_a23_caps = {
@@ -2617,6 +2635,7 @@ static const struct sunxi_nfc_caps sunxi .nstrengths = ARRAY_SIZE(sunxi_ecc_strengths_a10), .max_ecc_steps = 16, .sram_size = 1024, + .timings = &sun4i_a10_nfc_timings, };static const struct sunxi_nfc_caps sunxi_nfc_h616_caps = {
@@ -2641,6 +2660,7 @@ static const struct sunxi_nfc_caps sunxi .nuser_data_tab = ARRAY_SIZE(sunxi_user_data_len_h6), .max_ecc_steps = 32, .sram_size = 8192, + .timings = &sun4i_a10_nfc_timings, };static const struct of_device_id sunxi_nfc_ids[] = {
Greg Kroah-Hartman
maintainerPATCH 197/556 mtd: rawnand: sunxi: describe tADL and tWHR delays
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Hilliard <[email protected]>
commit 147f2a5743f8864bfc265654b1856af11c8c0031 upstream.
The tADL and tWHR timing fields use four encoded delays, but the driver currently derives their values with a shift. This hides the actual controller timing characteristics and lets the clock solver select a 32-cycle delay that the fields cannot encode.
Describe the legacy 7, 15, 23 and 31 cycle thresholds explicitly and use the tables for both clock selection and field lookup. This prepares the driver for controllers with different encodings.
--- drivers/mtd/nand/raw/sunxi_nand.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)
drivers/mtd/nand/raw/sunxi_nand.c +21 -11
@@ -242,6 +242,8 @@ struct sunxi_nand_hw_ecc {/* Delay arrays contain internal NDFC clock cycles for field values 0 to 3. */ struct sunxi_nfc_timings {s32 tWB[SUNXI_NFC_TIMING_STEPS ]; +s32 tADL[SUNXI_NFC_TIMING_STEPS ]; +s32 tWHR[SUNXI_NFC_TIMING_STEPS ];s32 tRHW[SUNXI_NFC_TIMING_STEPS ]; };
@@ -1679,6 +1681,8 @@ static int sunxi_nfc_hw_ecc_write_oob(ststatic const struct sunxi_nfc_timings sun4i_a10_nfc_timings = { .tWB = {6 ,12 ,16 ,20 }, + .tADL = {7 ,15 ,23 ,31 }, + .tWHR = {7 ,15 ,23 ,31 }, .tRHW = {4 ,8 ,12 ,20 }, };
@@ -1781,11 +1785,15 @@ static int sunxi_nfc_setup_interface(str min_clk_period =DIV_ROUND_UP (timings->tWB_max, nfc_timings->tWB[SUNXI_NFC_TIMING_STEPS -1 ]); -if (timings->tADL_min > (min_clk_period *32 )) - min_clk_period =DIV_ROUND_UP (timings->tADL_min,32 ); - -if (timings->tWHR_min > (min_clk_period *32 )) - min_clk_period =DIV_ROUND_UP (timings->tWHR_min,32 ); +if (timings->tADL_min > + (min_clk_period * nfc_timings->tADL[SUNXI_NFC_TIMING_STEPS -1 ])) + min_clk_period =DIV_ROUND_UP (timings->tADL_min, + nfc_timings->tADL[SUNXI_NFC_TIMING_STEPS -1 ]); + +if (timings->tWHR_min > + (min_clk_period * nfc_timings->tWHR[SUNXI_NFC_TIMING_STEPS -1 ])) + min_clk_period =DIV_ROUND_UP (timings->tWHR_min, + nfc_timings->tWHR[SUNXI_NFC_TIMING_STEPS -1 ]);if (timings->tRHW_min > (min_clk_period * nfc_timings->tRHW[SUNXI_NFC_TIMING_STEPS -1 ]))
@@ -1813,16 +1821,18 @@ static int sunxi_nfc_setup_interface(strreturn tWB; } - tADL =DIV_ROUND_UP (timings->tADL_min, min_clk_period) >>3 ; -if (tADL >3 ) { + tADL =sunxi_nand_lookup_timing (nfc_timings->tADL, + timings->tADL_min, min_clk_period); +if (tADL <0 ) {dev_err (nfc->dev,"unsupported tADL\n" ); -return -EINVAL ; +return tADL; } - tWHR =DIV_ROUND_UP (timings->tWHR_min, min_clk_period) >>3 ; -if (tWHR >3 ) { + tWHR =sunxi_nand_lookup_timing (nfc_timings->tWHR, + timings->tWHR_min, min_clk_period); +if (tWHR <0 ) {dev_err (nfc->dev,"unsupported tWHR\n" ); -return -EINVAL ; +return tWHR; } tRHW = sunxi_nand_lookup_timing(nfc_timings->tRHW, timings->tRHW_min,
Greg Kroah-Hartman
maintainerPATCH 198/556 mtd: rawnand: sunxi: fix H6/H616 controller timings
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: James Hilliard <[email protected]>
commit 15a3cbce32994141252bb4ecfe3ff3a5d22d0b4f upstream.
The NAND timing calculation assumes that command and address setup and hold intervals T1-T4, T7 and T11 each take one controller clock. It also uses the original A10 delay encodings for tWB, tADL, tWHR and tRHW.
The H6/H616 NDFC defines the setup and hold intervals as two internal clock cycles and uses different delay encodings. Add the H616 timing characteristics and select them through the controller capability data so the clock solver and timing fields match the hardware.
--- drivers/mtd/nand/raw/sunxi_nand.c | 49 +++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 13 deletions(-)
drivers/mtd/nand/raw/sunxi_nand.c +36 -13
@@ -241,6 +241,8 @@ struct sunxi_nand_hw_ecc {/* Delay arrays contain internal NDFC clock cycles for field values 0 to 3. */ struct sunxi_nfc_timings { +/* Internal clock cycles used by T1-T4, T7 and T11. */ +u8 setup_cycles;s32 tWB[SUNXI_NFC_TIMING_STEPS ];s32 tADL[SUNXI_NFC_TIMING_STEPS ];s32 tWHR[SUNXI_NFC_TIMING_STEPS ];
@@ -1680,12 +1682,21 @@ static int sunxi_nfc_hw_ecc_write_oob(st }static const struct sunxi_nfc_timings sun4i_a10_nfc_timings = { + .setup_cycles =1 , .tWB = {6 ,12 ,16 ,20 }, .tADL = {7 ,15 ,23 ,31 }, .tWHR = {7 ,15 ,23 ,31 }, .tRHW = {4 ,8 ,12 ,20 }, }; +static const struct sunxi_nfc_timings sun50i_h616_nfc_timings = { + .setup_cycles =2 , + .tWB = {28 ,44 ,60 ,76 }, + .tADL = {0 ,12 ,28 ,44 }, + .tWHR = {0 ,12 ,28 ,44 }, + .tRHW = {8 ,24 ,40 ,56 }, +}; +static int _sunxi_nand_lookup_timing (const s32 *lut,int lut_size,u32 duration,u32 clk_period) {
@@ -1720,20 +1731,28 @@ static int sunxi_nfc_setup_interface(strreturn -ENOTSUPP ;/* T1 <=> tCLS */ -if (timings->tCLS_min > min_clk_period) - min_clk_period = timings->tCLS_min; +if (timings->tCLS_min > + min_clk_period * nfc_timings->setup_cycles) + min_clk_period =DIV_ROUND_UP (timings->tCLS_min, + nfc_timings->setup_cycles);/* T2 <=> tCLH */ -if (timings->tCLH_min > min_clk_period) - min_clk_period = timings->tCLH_min; +if (timings->tCLH_min > + min_clk_period * nfc_timings->setup_cycles) + min_clk_period =DIV_ROUND_UP (timings->tCLH_min, + nfc_timings->setup_cycles);/* T3 <=> tCS */ -if (timings->tCS_min > min_clk_period) - min_clk_period = timings->tCS_min; +if (timings->tCS_min > + min_clk_period * nfc_timings->setup_cycles) + min_clk_period =DIV_ROUND_UP (timings->tCS_min, + nfc_timings->setup_cycles);/* T4 <=> tCH */ -if (timings->tCH_min > min_clk_period) - min_clk_period = timings->tCH_min; +if (timings->tCH_min > + min_clk_period * nfc_timings->setup_cycles) + min_clk_period =DIV_ROUND_UP (timings->tCH_min, + nfc_timings->setup_cycles);/* T5 <=> tWP */ if (timings->tWP_min > min_clk_period)
@@ -1744,8 +1763,10 @@ static int sunxi_nfc_setup_interface(str min_clk_period = timings->tWH_min;/* T7 <=> tALS */ -if (timings->tALS_min > min_clk_period) - min_clk_period = timings->tALS_min; +if (timings->tALS_min > + min_clk_period * nfc_timings->setup_cycles) + min_clk_period =DIV_ROUND_UP (timings->tALS_min, + nfc_timings->setup_cycles);/* T8 <=> tDS */ if (timings->tDS_min > min_clk_period)
@@ -1760,8 +1781,10 @@ static int sunxi_nfc_setup_interface(str min_clk_period =DIV_ROUND_UP (timings->tRR_min,3 );/* T11 <=> tALH */ -if (timings->tALH_min > min_clk_period) - min_clk_period = timings->tALH_min; +if (timings->tALH_min > + min_clk_period * nfc_timings->setup_cycles) + min_clk_period =DIV_ROUND_UP (timings->tALH_min, + nfc_timings->setup_cycles);/* T12 <=> tRP */ if (timings->tRP_min > min_clk_period)
@@ -2670,7 +2693,7 @@ static const struct sunxi_nfc_caps sunxi .nuser_data_tab = ARRAY_SIZE(sunxi_user_data_len_h6), .max_ecc_steps = 32, .sram_size = 8192, - .timings = &sun4i_a10_nfc_timings, + .timings = &sun50i_h616_nfc_timings, };static const struct of_device_id sunxi_nfc_ids[] = {
Greg Kroah-Hartman
maintainerPATCH 199/556 mtd: rawnand: validate ONFI extended parameter page sections
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pengpeng Hou <[email protected]>
commit e5e415262330bd70f983e091d8919d9dcd99e475 upstream.
nand_flash_detect_ext_param_page() allocates the length declared by the ONFI parameter page, then treats the data as a fixed header followed by variable-length sections. It reads that header and advances over sections without first proving that the fixed page and each current section fit in the allocation.
Reject pages shorter than the fixed header, track the remaining variable area while walking sections, and require the ECC section to contain every field read from struct onfi_ext_ecc_info. Use device-scoped diagnostics that identify the malformed ONFI section.
--- drivers/mtd/nand/raw/nand_onfi.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
drivers/mtd/nand/raw/nand_onfi.c +25 -2
@@ -35,16 +35,21 @@ static int nand_flash_detect_ext_param_p struct nand_onfi_params *p) {struct nand_device *base = &chip->base; +struct mtd_info *mtd =nand_to_mtd (chip);struct nand_ecc_props requirements;struct onfi_ext_param_page *ep;struct onfi_ext_section *s;struct onfi_ext_ecc_info *ecc; +size_t remaining, section_len;uint8_t *cursor;int ret;int len;int i; len =le16_to_cpu (p->ext_param_page_length) *16 ; +if (len <sizeof (*ep)) +return -EINVAL ; + ep =kmalloc (len,GFP_KERNEL );if (!ep)return -ENOMEM ;
@@ -77,11 +82,29 @@ static int nand_flash_detect_ext_param_p/* find the ECC section. */ cursor = (uint8_t *)(ep +1 ); + remaining = len -sizeof (*ep);for (i =0 ; i <ONFI_EXT_SECTION_MAX ; i++) { s = ep->sections + i; -if (s->type ==ONFI_SECTION_TYPE_2 ) + section_len = s->length *16 ; +if (section_len > remaining) { +dev_dbg (&mtd->dev, +"ONFI extended parameter section %d exceeds page\n" , + i); + goto ext_out; + } + +if (s->type ==ONFI_SECTION_TYPE_2 ) { +if (section_len <sizeof (*ecc)) { +dev_dbg (&mtd->dev, +"ONFI extended parameter ECC section %d is too short\n" , + i); + goto ext_out; + }break ; - cursor += s->length *16 ; + } + + cursor += section_len; + remaining -= section_len; }if (i ==ONFI_EXT_SECTION_MAX ) {pr_debug ("We can not find the ECC section.\n" );
Greg Kroah-Hartman
maintainerPATCH 200/556 batman-adv: fix stale receive device on merged fragments
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhiling Zou <[email protected]>
commit ad46c907d7d9975a285c1e89a4adde652eaa93f5 upstream.
Fragment reassembly reuses the skb from the highest-numbered buffered fragment as the merged packet. When that fragment was received on a hard interface which is deleted before the chain completes, the merged skb can re-enter the receive path with a stale skb->dev and skb_iif.
batadv_batman_skb_recv() passes such merged packets through the normal receive handlers again. DAT and bridge loop avoidance both derive the ARP header length from skb->dev, so they can dereference the freed net_device before the packet reaches the local mesh interface.
Refresh the receive device metadata from the current receive device before running the packet handlers. This keeps internally reinjected merged fragments consistent with the normal receive path after hard interface teardown.
--- net/batman-adv/main.c | 4 ++++ 1 file changed, 4 insertions(+)
net/batman-adv/main.c +4 -0
@@ -450,6 +450,10 @@ int batadv_batman_skb_recv(struct sk_bufif (!skb) goto err_put; +/* Merged fragments re-enter here with reused skb metadata. */ + skb->dev = dev; + skb->skb_iif = dev->ifindex; +/* packet should hold at least type and version */ if (unlikely (!pskb_may_pull (skb,2 ))) goto err_free;
Greg Kroah-Hartman
maintainerPATCH 201/556 batman-adv: fix TX priority extraction for BATADV_FORW_MCAST
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 7aedb59b80993c912ab45ce24386a2775150962b upstream.
batadv_mcast_forw_mode_by_count() pushs the skb->data for BATADV_FORW_MCAST forwarding via batadv_mcast_forw_mcsend(). But the batadv_skb_set_priority() expects the ethernet header directly before (skb->data + offset). With the moved skb->data, just some random data would be accessed to get the priority data.
Move the batadv_skb_set_priority() before the decision about the handling multicast packets and potential header modifications.
--- net/batman-adv/mesh-interface.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/batman-adv/mesh-interface.c +5 -2
@@ -260,6 +260,8 @@ static netdev_tx_t batadv_interface_tx(sif (batadv_compare_eth (ethhdr->h_dest, ectp_addr)) goto dropped; +batadv_skb_set_priority (skb,0 ); + gw_mode =READ_ONCE (bat_priv->gw.mode);if (is_multicast_ether_addr (ethhdr->h_dest)) {/* if gw mode is off, broadcast every packet */
@@ -293,6 +295,9 @@ static netdev_tx_t batadv_interface_tx(s send:if (do_bcast && !is_broadcast_ether_addr (ethhdr->h_dest)) { +/* WARNING batadv_mcast_forw_mode might add more headers +* in front of the skb. and might even reallocate the skb +*/ forw_mode =batadv_mcast_forw_mode (bat_priv, skb, vid, &mcast_is_routable);switch (forw_mode) {
@@ -310,8 +315,6 @@ send: } } -batadv_skb_set_priority (skb,0 ); -/* ethernet packet should be broadcasted */ if (do_bcast) { primary_if =batadv_primary_if_get_selected (bat_priv);
Greg Kroah-Hartman
maintainerPATCH 202/556 batman-adv: mcast: ensure unshared skb for multicast packets
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 82bf207f48ebb7a38157f1d91dac884fc9b8cfd8 upstream.
When a packet is transmitted via a batman-adv interface and has already enough room for the header then nothing will make sure that the skbuff is unshared. But it is not allowed to modify a currently shared skbuff.
Always make sure that the pskb_expand_head() is not only called for a too small header but also for shared skbuffs.
--- net/batman-adv/multicast_forw.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
net/batman-adv/multicast_forw.c +1 -2
@@ -1100,8 +1100,7 @@ static int batadv_mcast_forw_expand_headreturn -EINVAL ; } -if (skb_headroom (skb) < hdr_size && -pskb_expand_head (skb, hdr_size,0 ,GFP_ATOMIC ) <0 ) +if (skb_cow (skb, hdr_size) <0 )return -ENOMEM ;return 0 ;
Greg Kroah-Hartman
maintainerPATCH 203/556 batman-adv: mcast: linearize skbuff for packet generation
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 6a30a59e2660afd03c975f1b8eae6a2301161197 upstream.
batadv_mcast_forw_packet() and batadv_mcast_forw_scrape() is not only called (indirectly) by the unsharing+linearizing batadv_recv_mcast_packet() handler. When it is called (indirectly) by batadv_mcast_forw_mcsend() then it will be unshared but not linearized. The SKB_LINEAR_ASSERT() can therefore cause a fatal BUG().
The linearization should happen during the expansion of the head because the scrape function can be hit already during the initial batadv_mcast_forw_mode() selection code:
* batadv_interface_tx
* batadv_mcast_forw_mode
* batadv_mcast_forw_mode_by_count()
* batadv_mcast_forw_push()
-> calls batadv_mcast_forw_expand_head() before everything else
* batadv_mcast_forw_push_tvlvs()
* batadv_mcast_forw_push_dests()
* batadv_mcast_forw_push_adjust_padding()
* batadv_mcast_forw_scrape()
--- net/batman-adv/multicast_forw.c | 4 ++++ 1 file changed, 4 insertions(+)
net/batman-adv/multicast_forw.c +4 -0
@@ -1103,6 +1103,10 @@ static int batadv_mcast_forw_expand_headif (skb_cow (skb, hdr_size) <0 )return -ENOMEM ; +/* batadv_mcast_forw_scrape() + batadv_mcast_forw_packet() require linearized skb */ +if (skb_linearize (skb) <0 ) +return -ENOMEM ; +return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 204/556 batman-adv: dat: avoid unaligned fault in IP extraction
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 0121afa52cdb88cfb4d5d7bd126a23a9100121d8 upstream.
Independent of the alignment of the ARP packet in the SKB, either the batadv_arp_ip_src or the batadv_arp_ip_dst will have an unaligned access (on HW without native unaligned read support).
Use get_unaligned() to handle this properly on all architectures.
--- net/batman-adv/distributed-arp-table.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
net/batman-adv/distributed-arp-table.c +6 -2
@@ -250,7 +250,10 @@ static u8 *batadv_arp_hw_src(struct sk_b*/ static __be32 batadv_arp_ip_src (struct sk_buff *skb,int hdr_size) { -return *(__force __be32 *)(batadv_arp_hw_src (skb, hdr_size) +ETH_ALEN ); +u8 *src =batadv_arp_hw_src (skb, hdr_size) +ETH_ALEN ; +__be32 *ip = (__force __be32 *)src; + +return get_unaligned (ip); }/**
@@ -275,8 +278,9 @@ static u8 *batadv_arp_hw_dst(struct sk_bstatic __be32 batadv_arp_ip_dst (struct sk_buff *skb,int hdr_size) {u8 *dst =batadv_arp_hw_src (skb, hdr_size) +ETH_ALEN *2 +4 ; +__be32 *ip = (__force __be32 *)dst; -return *(__force __be32 *)dst; +return get_unaligned (ip); }/**
Greg Kroah-Hartman
maintainerPATCH 205/556 batman-adv: bla: fix freeing of claims on meshif deletion
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 8d128c932bced74e3b1625ba3d7c78ef122a88a7 upstream.
When the mesh interface is getting deleted, then batadv_bla_del_backbone_claims() (via batadv_bla_purge_backbone_gw()) could make sure that all claims gets removed. But this function is only executed when bat_priv->bla.claim_hash is not NULL. And since batadv_bla_free() is always setting it to NULL before it is (indirectly) called, it was never actually executed.
But the batadv_bla_purge_claims() -> batadv_handle_unclaim() is at the moment too fragile because the BLA code is not handling the rehashing in batadv_bla_update_orig_address(). The stored backbone address doesn't have to be the one actually used for the hash bucket selection during the initial adding of the backbone. The batadv_handle_unclaim() can therefore fail to find the respective backbone for the unclaim and then stop the deletion.
But the actual backbone_gw object is not needed for the unclaim because all relevant information is always provided by the caller. And the check for the existence of the backbone_gw doesn't provide any additional security check for the deletion of a claim.
--- net/batman-adv/bridge_loop_avoidance.c | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-)
net/batman-adv/bridge_loop_avoidance.c +1 -9
@@ -942,26 +942,18 @@ static bool batadv_handle_unclaim(struct const u8 *backbone_addr, const u8 *claim_addr, unsigned short vid) { - struct batadv_bla_backbone_gw *backbone_gw; - /* unclaim in any case if it is our own */ if (primary_if && batadv_compare_eth(backbone_addr, primary_if->net_dev->dev_addr)) batadv_bla_send_claim(bat_priv, claim_addr, vid, BATADV_CLAIM_TYPE_UNCLAIM); - backbone_gw =batadv_backbone_hash_find (bat_priv, backbone_addr, vid); - -if (!backbone_gw) -return true; -/* this must be an UNCLAIM frame */ batadv_dbg (BATADV_DBG_BLA , bat_priv,"%s(): UNCLAIM %pM on vid %d (sent by %pM)...\n" , __func__, - claim_addr,batadv_print_vid (vid), backbone_gw->orig); + claim_addr,batadv_print_vid (vid), backbone_addr);batadv_bla_del_claim (bat_priv, claim_addr, vid); -batadv_backbone_gw_put (backbone_gw);return true; }
Greg Kroah-Hartman
maintainerPATCH 206/556 batman-adv: bla: prevent CRC corruptions after claim flush
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sven Eckelmann <[email protected]>
commit 89f3502ff6878798be96461b2eebd64ba3c3874c upstream.
When batadv_bla_del_backbone_claims() tried to remove all claims of a backbone, it sets the CRC to 0. It assumes that the it had the last reference of the claims because batadv_claim_release() (which runs after the last reference was released), is XORing the crc16 of the claim address with the backbone CRC.
If there would be a parallel holder of any of these references, it could happen that the backbone CRC is (0 ^ crc16(delayed_released_claim)). Which is the wrong starting point for the new claims it may receive when the remote answers the claim request from batadv_bla_send_request().
This reinitializations can be completely dropped to avoid this problem. batadv_claim_release() will take care of fixing the backbone CRC.
--- net/batman-adv/bridge_loop_avoidance.c | 5 ----- 1 file changed, 5 deletions(-)
net/batman-adv/bridge_loop_avoidance.c +0 -5
@@ -324,11 +324,6 @@ batadv_bla_del_backbone_claims(struct ba }spin_unlock_bh (list_lock); } - -/* all claims gone, initialize CRC */ -spin_lock_bh (&backbone_gw->crc_lock); - backbone_gw->crc =BATADV_BLA_CRC_INIT ; -spin_unlock_bh (&backbone_gw->crc_lock); }/**
Greg Kroah-Hartman
maintainerPATCH 207/556 clk: clocking-wizard: fix integer overflow in rate calculation
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pavel Löbl <[email protected]>
commit 4adf593c6fc5aed4639add011f71a074a1bd3966 upstream.
When using driver on Zynq-7000 (32-bit) determine_rate calculation overflows. For instance requesting 32MHz with 100MHz parent clock results in 100000000*(4*1000+0) 32-bit multiplication.
Replace the expression with mult_frac which is already used in clk_wzrd_recalc_ratef.
--- drivers/clk/xilinx/clk-xlnx-clock-wizard.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/xilinx/clk-xlnx-clock-wizard.c +2 -2
@@ -663,8 +663,8 @@ static int clk_wzrd_determine_rate_all(s d = divider->d; o = divider->o; - req->rate =div_u64 (req->best_parent_rate * (m *1000 + divider->m_frac), - d * (o *1000 + divider->o_frac)); + req->rate =mult_frac (req->best_parent_rate, m *1000 + divider->m_frac, + d * (o *1000 + divider->o_frac));return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 208/556 clk: mediatek: mt8196: Select REGMAP_MMIO for vlpckgen
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Akari Tsuyukusa <[email protected]>
commit f63aecdb45e9dd19c340fd62df698374d95b9024 upstream.
The MediaTek MT8196 vlpckgen clock driver uses __devm_regmap_init_mmio_clk() by devm_regmap_init_mmio(), which is defined in drivers/base/regmap/regmap-mmio.c. However, the driver's Kconfig entry does not select REGMAP_MMIO. This causes a linker error when REGMAP_MMIO is not enabled.
Fix this by selecting REGMAP_MMIO in the Kconfig entry.
--- drivers/clk/mediatek/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/clk/mediatek/Kconfig +1 -0
@@ -1006,6 +1006,7 @@ config COMMON_CLK_MT8196 tristate "Clock driver for MediaTek MT8196" depends on ARM64 || COMPILE_TEST select COMMON_CLK_MEDIATEK + select REGMAP_MMIO default ARCH_MEDIATEK help This driver supports MediaTek MT8196 basic clocks.
Greg Kroah-Hartman
maintainerPATCH 209/556 clk: meson: align gxbb_32k_clk_sel number of parents with actual count
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Martin Blumenstingl <[email protected]>
commit 628b6fee9fca292f12d07f0f1bcf1edefa949d81 upstream.
The following out-of-bounds read has been observed by Christian on a GXBB WeTek Hub:
==================================================================
BUG: KASAN: global-out-of-bounds in __clk_register+0x1b70/0x2418
Read of size 8 at addr ffffd66320cf88e0 by task swapper/0/1
CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 7.0.0-rc5 #1 PREEMPT
Hardware name: WeTek Hub (DT)
Call trace:
show_stack+0x14/0x20 (C)
dump_stack_lvl+0x74/0x94
print_report+0x164/0x4b0
kasan_report+0x98/0xd8
__asan_report_load8_noabort+0x1c/0x24
__clk_register+0x1b70/0x2418
devm_clk_hw_register+0x74/0x15c
meson_clkc_init+0xd4/0x20c
meson_clkc_syscon_probe+0x5c/0x94
platform_probe+0xbc/0x17c
really_probe+0x184/0x844
__driver_probe_device+0x154/0x35c
driver_probe_device+0x60/0x188
__driver_attach+0x168/0x4a0
bus_for_each_dev+0xec/0x180
driver_attach+0x38/0x58
bus_add_driver+0x238/0x4c0
driver_register+0x150/0x388
__platform_driver_register+0x54/0x7c
gxbb_clkc_driver_init+0x18/0x20
do_one_initcall+0xb8/0x340
kernel_init_freeable+0x49c/0x52c
kernel_init+0x24/0x148
ret_from_fork+0x10/0x20
The buggy address belongs to the variable:
gxbb_32k_clk_parents+0x60/0x400
The buggy address belongs to a vmalloc virtual mapping
The buggy address belongs to the physical page:
Memory state around the buggy address:
ffffd66320cf8780: 00 00 00 00 f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9
ffffd66320cf8800: 00 04 f9 f9 f9 f9 f9 f9 00 04 f9 f9 f9 f9 f9 f9
>ffffd66320cf8880: 00 00 00 00 00 00 00 00 00 00 00 00 f9 f9 f9 f9
^
ffffd66320cf8900: 00 01 f9 f9 f9 f9 f9 f9 00 06 f9 f9 f9 f9 f9 f9
ffffd66320cf8980: 00 00 02 f9 f9 f9 f9 f9 00 00 02 f9 f9 f9 f9 f9
==================================================================Commit 7915d7d5407c ("clk: amlogic: gxbb: drop non existing 32k clock parent") dropped a non-existing clock parent from the gxbb_32k_clk_sel mux but didn't adjust the hard-coded num_parents field. Fix the actual number of parents of that mux by using ARRAY_SIZE instead (avoiding similar problems in future).
--- drivers/clk/meson/gxbb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/meson/gxbb.c +1 -1
@@ -1393,7 +1393,7 @@ static struct clk_regmap gxbb_32k_clk_se .name = "32k_clk_sel", .ops = &clk_regmap_mux_ops, .parent_data = gxbb_32k_clk_parents, - .num_parents = 4, + .num_parents = ARRAY_SIZE(gxbb_32k_clk_parents), .flags = CLK_SET_RATE_PARENT, }, };
Greg Kroah-Hartman
maintainerPATCH 210/556 clk: microchip: mpfs: fix regmap_update_bits() mask/val order
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pedro Kopper <[email protected]>
commit fbfa013eeac299ecc015cb14fa40e382a23fb489 upstream.
mpfs_cfg_clk_set_rate() passes the mask and value arguments to regmap_update_bits() in the wrong order. The resulting write becomes reg = orig_reg | val, causing bits to not be cleared if the clock divider changes.
Pass the arguments in the correct order so the divider field is updated as intended.
--- drivers/clk/microchip/clk-mpfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/microchip/clk-mpfs.c +1 -1
@@ -285,7 +285,7 @@ static int mpfs_cfg_clk_set_rate(struct mask =clk_div_mask (cfg->width) << cfg->shift; val = divider_setting << cfg->shift; -regmap_update_bits (cfg->map, cfg->map_offset, val, mask); +regmap_update_bits (cfg->map, cfg->map_offset, mask, val);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 211/556 clk: qcom: gcc-msm8916: Fix enable_reg for gcc_blsp1_sleep_clk
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephan Gerhold <[email protected]>
commit c5339edc6abb601ea10df910ea0b1592fa1016f3 upstream.
According to the APQ8016E TRM, the GCC_BLSP1_SLEEP_CBCR register is read-only and only has the CLK_OFF bit to check if the clock is running. This is a shared vote clock, the correct way to enable it is to vote for BLSP1_SLEEP_CLK_ENA (BIT(9)) in GCC_APCS_CLOCK_BRANCH_ENA_VOTE (0x45004).
--- drivers/clk/qcom/gcc-msm8916.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clk/qcom/gcc-msm8916.c +3 -2
@@ -1589,9 +1589,10 @@ static struct clk_branch gcc_blsp1_ahb_cstatic struct clk_branch gcc_blsp1_sleep_clk = { .halt_reg =0x01004 , + .halt_check =BRANCH_HALT_VOTED , .clkr = { - .enable_reg =0x01004 , - .enable_mask =BIT (0 ), + .enable_reg =0x45004 , + .enable_mask =BIT (9 ), .hw.init = &(struct clk_init_data ){ .name ="gcc_blsp1_sleep_clk" , .parent_data = &(const struct clk_parent_data ){
Greg Kroah-Hartman
maintainerPATCH 212/556 clk: qcom: gcc-msm8939: Fix enable_reg for gcc_blsp1_sleep_clk
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephan Gerhold <[email protected]>
commit fc611445b021262b0d4ace6f716a360663816287 upstream.
MSM8939 is similar to MSM8916, where the GCC_BLSP1_SLEEP_CBCR register is read-only and only has the CLK_OFF bit to check if the clock is running. This is a shared vote clock, the correct way to enable it is to vote for BLSP1_SLEEP_CLK_ENA (BIT(9)) in GCC_APCS_CLOCK_BRANCH_ENA_VOTE (0x45004).
--- drivers/clk/qcom/gcc-msm8939.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clk/qcom/gcc-msm8939.c +3 -2
@@ -1929,9 +1929,10 @@ static struct clk_branch gcc_blsp1_ahb_cstatic struct clk_branch gcc_blsp1_sleep_clk = { .halt_reg =0x01004 , + .halt_check =BRANCH_HALT_VOTED , .clkr = { - .enable_reg =0x01004 , - .enable_mask =BIT (0 ), + .enable_reg =0x45004 , + .enable_mask =BIT (9 ), .hw.init = &(struct clk_init_data ){ .name ="gcc_blsp1_sleep_clk" , .ops = &clk_branch2_ops,
Greg Kroah-Hartman
maintainerPATCH 213/556 clk: rockchip: rk3588: Dont change PLL rates when setting dclk_vop2_src
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Heiko Stuebner <[email protected]>
commit 13b10571cc353448275365ede1a5396d20dfe839 upstream.
dclk_vop2_src currently has the CLK_SET_RATE_PARENT flag set, which is very different from dclk_vop0_src or dclk_vop1_src, which don't have it.
With this flag in dclk_vop2_src, actually setting the clock then results in a lot of other peripherals breaking, because setting the rate results in the PLL source getting changed:
[ 14.898718] clk_core_set_rate_nolock: setting rate for dclk_vop2 to 152840000 [ 15.155017] clk_change_rate: setting rate for pll_gpll to 1680000000
[ clk adjusting every gpll user ]
This includes possibly the other vops, i2s, spdif and even the uarts. Among other possible things, this breaks the uart console on a board I use. Sometimes it recovers later on, but there will be a big block of garbled output for a while at least.
Shared PLLs should not be changed by individual users, so drop this flag from dclk_vop2_src.
--- drivers/clk/rockchip/clk-rk3588.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/rockchip/clk-rk3588.c +1 -1
@@ -2102,7 +2102,7 @@ static struct rockchip_clk_branch rk3588COMPOSITE (DCLK_VOP1_SRC ,"dclk_vop1_src" , gpll_cpll_v0pll_aupll_p,0 ,RK3588_CLKSEL_CON (111 ),14 ,2 ,MFLAGS ,9 ,5 ,DFLAGS ,RK3588_CLKGATE_CON (52 ),11 ,GFLAGS ), -COMPOSITE (DCLK_VOP2_SRC ,"dclk_vop2_src" , gpll_cpll_v0pll_aupll_p,CLK_SET_RATE_PARENT |CLK_SET_RATE_NO_REPARENT , +COMPOSITE (DCLK_VOP2_SRC ,"dclk_vop2_src" , gpll_cpll_v0pll_aupll_p,CLK_SET_RATE_NO_REPARENT ,RK3588_CLKSEL_CON (112 ),5 ,2 ,MFLAGS ,0 ,5 ,DFLAGS ,RK3588_CLKGATE_CON (52 ),12 ,GFLAGS ), COMPOSITE_NODIV(DCLK_VOP0, "dclk_vop0", dclk_vop0_p,
Greg Kroah-Hartman
maintainerPATCH 214/556 clk: qcom: gcc-mdm9607: Drop incorrect apss_tcu_clk_src
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephan Gerhold <[email protected]>
commit 38d06956f60675f906dc3f5b70b3b52103b86a7d upstream.
This clock does not exist on the specified address on MDM9607. Reading/writing the registers always results in 0 or crashes. The math in the frequency table is also broken. GPLL2 on MDM9607 runs at 480 MHz, so:
- F(155000000, P_GPLL2, 6, 0, 0), // 480 MHz/6 = 80 MHz, not 155 MHz
- F(310000000, P_GPLL2, 3, 0, 0), // 480 MHz/3 = 160 MHz, not 310 MHz
Presumably, this definition was mistakenly copied as-is from gcc-msm8916 (which uses 930 MHz for GPLL2). There are no branch consumers of this root clock inside gcc-mdm9607 (notably, gcc_apss_tcu_clk has bimc_ddr_clk_src as parent instead of this clock), so we can just drop it.
It seems like this clock does exist on this SoC on a different address, but since there is no user and reference code for it, it is still better to drop it.
--- drivers/clk/qcom/gcc-mdm9607.c | 35 ----------------------------------- 1 file changed, 35 deletions(-)
drivers/clk/qcom/gcc-mdm9607.c +0 -35
@@ -158,20 +158,6 @@ static const struct clk_parent_data gcc_ { .hw = &gpll2.clkr.hw }, }; -static const struct parent_map gcc_xo_gpll0_gpll1_gpll2_map[] = { - {P_XO ,0 }, - {P_GPLL0 ,1 }, - {P_GPLL1 ,2 }, - {P_GPLL2 ,3 }, -}; - -static const struct clk_parent_data gcc_xo_gpll0_gpll1_gpll2[] = { - { .fw_name ="xo" }, - { .hw = &gpll0.clkr.hw }, - { .hw = &gpll1_vote.hw }, - { .hw = &gpll2.clkr.hw }, -}; -static const struct freq_tbl ftbl_apss_ahb_clk[] = {F (19200000 ,P_XO ,1 ,0 ,0 ),F (50000000 ,P_GPLL0 ,16 ,0 ,0 ),
@@ -674,26 +660,6 @@ static struct clk_rcg2 sdcc2_apps_clk_sr }, }; -static const struct freq_tbl ftbl_gcc_apss_tcu_clk[] = { -F (155000000 ,P_GPLL2 ,6 ,0 ,0 ), -F (310000000 ,P_GPLL2 ,3 ,0 ,0 ), -F (400000000 ,P_GPLL0 ,2 ,0 ,0 ), - { } -}; - -static struct clk_rcg2 apss_tcu_clk_src = { - .cmd_rcgr =0x1207c , - .hid_width =5 , - .parent_map = gcc_xo_gpll0_gpll1_gpll2_map, - .freq_tbl = ftbl_gcc_apss_tcu_clk, - .clkr.hw.init = &(struct clk_init_data ){ - .name ="apss_tcu_clk_src" , - .parent_data = gcc_xo_gpll0_gpll1_gpll2, - .num_parents =4 , - .ops = &clk_rcg2_ops, - }, -}; -static const struct freq_tbl ftbl_gcc_usb_hs_system_clk[] = {F (19200000 ,P_XO ,1 ,0 ,0 ),F (57140000 ,P_GPLL0 ,14 ,0 ,0 ),
@@ -1511,7 +1477,6 @@ static struct clk_regmap *gcc_mdm9607_cl [PDM2_CLK_SRC] = &pdm2_clk_src.clkr, [SDCC1_APPS_CLK_SRC] = &sdcc1_apps_clk_src.clkr, [SDCC2_APPS_CLK_SRC] = &sdcc2_apps_clk_src.clkr, - [APSS_TCU_CLK_SRC] = &apss_tcu_clk_src.clkr, [USB_HS_SYSTEM_CLK_SRC] = &usb_hs_system_clk_src.clkr, [GCC_BLSP1_AHB_CLK] = &gcc_blsp1_ahb_clk.clkr, [GCC_BLSP1_SLEEP_CLK] = &gcc_blsp1_sleep_clk.clkr,
Greg Kroah-Hartman
maintainerPATCH 215/556 clk: qcom: gcc-mdm9607: Drop incorrect system_noc_bfdcd_clk_src
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephan Gerhold <[email protected]>
commit 17784427df923a0573a7ea83f9198456ff1ec1a5 upstream.
This clock does not exist on MDM9607. Reading/writing the registers always results in 0.
Presumably, this definition was mistakenly copied from gcc-msm8916. On MSM8916, this root clock is used for multimedia subsystems (camera, display, video). MDM9607 has none of that, so this clock was probably omitted in the hardware.
There are no users inside gcc-mdm9607, so we can just drop it.
--- drivers/clk/qcom/gcc-mdm9607.c | 13 ------------- 1 file changed, 13 deletions(-)
drivers/clk/qcom/gcc-mdm9607.c +0 -13
@@ -240,18 +240,6 @@ static struct clk_rcg2 pcnoc_bfdcd_clk_s }, }; -static struct clk_rcg2 system_noc_bfdcd_clk_src = { - .cmd_rcgr =0x26004 , - .hid_width =5 , - .parent_map = gcc_xo_gpll0_bimc_map, - .clkr.hw.init = &(struct clk_init_data ){ - .name ="system_noc_bfdcd_clk_src" , - .parent_data = gcc_xo_gpll0_bimc, - .num_parents =ARRAY_SIZE (gcc_xo_gpll0_bimc), - .ops = &clk_rcg2_ops, - }, -}; -static const struct freq_tbl ftbl_gcc_blsp1_qup1_6_i2c_apps_clk[] = {F (19200000 ,P_XO ,1 ,0 ,0 ),F (50000000 ,P_GPLL0 ,16 ,0 ,0 ),
@@ -1450,7 +1438,6 @@ static struct clk_regmap *gcc_mdm9607_cl [BIMC_PLL_VOTE] = &bimc_pll_vote, [BIMC_DDR_CLK_SRC] = &bimc_ddr_clk_src.clkr, [PCNOC_BFDCD_CLK_SRC] = &pcnoc_bfdcd_clk_src.clkr, - [SYSTEM_NOC_BFDCD_CLK_SRC] = &system_noc_bfdcd_clk_src.clkr, [APSS_AHB_CLK_SRC] = &apss_ahb_clk_src.clkr, [BLSP1_QUP1_I2C_APPS_CLK_SRC] = &blsp1_qup1_i2c_apps_clk_src.clkr, [BLSP1_QUP1_SPI_APPS_CLK_SRC] = &blsp1_qup1_spi_apps_clk_src.clkr,
Greg Kroah-Hartman
maintainerPATCH 216/556 clk: qcom: gcc-mdm9607: Fix enable_reg for gcc_blsp1_sleep_clk
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephan Gerhold <[email protected]>
commit 944d0fb38cffe57a1d1ebf82c5c077bad82dcdbb upstream.
MDM9607 is similar to MSM8909, where the GCC_BLSP1_SLEEP_CBCR register is read-only and only has the CLK_OFF bit to check if the clock is running. This is a shared vote clock, the correct way to enable it is to vote for BLSP1_SLEEP_CLK_ENA (BIT(9)) in GCC_APCS_CLOCK_BRANCH_ENA_VOTE (0x45004).
--- drivers/clk/qcom/gcc-mdm9607.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/clk/qcom/gcc-mdm9607.c +3 -2
@@ -744,9 +744,10 @@ static struct clk_branch gcc_blsp1_ahb_cstatic struct clk_branch gcc_blsp1_sleep_clk = { .halt_reg =0x1004 , + .halt_check =BRANCH_HALT_VOTED , .clkr = { - .enable_reg =0x1004 , - .enable_mask =BIT (0 ), + .enable_reg =0x45004 , + .enable_mask =BIT (9 ), .hw.init = &(struct clk_init_data ){ .name ="gcc_blsp1_sleep_clk" , .parent_data = &(const struct clk_parent_data ){
Greg Kroah-Hartman
maintainerPATCH 217/556 clk: qcom: gcc-mdm9607: Fix halt_reg for gcc_apss_axi_clk
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephan Gerhold <[email protected]>
commit ca7e6cc30cde4f0cbeff2e205a84bedf431e9156 upstream.
gcc_apss_axi_clk specifies a halt_reg of 0x4601c, but this is already used by gcc_apss_ahb_clk. The correct value according to the downstream driver is 0x46020.
--- drivers/clk/qcom/gcc-mdm9607.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/qcom/gcc-mdm9607.c +1 -1
@@ -1414,7 +1414,7 @@ static struct clk_branch gcc_apss_ahb_cl };static struct clk_branch gcc_apss_axi_clk = { - .halt_reg =0x4601c , + .halt_reg =0x46020 , .halt_check =BRANCH_HALT_VOTED , .clkr = { .enable_reg =0x45004 ,
Greg Kroah-Hartman
maintainerPATCH 218/556 clk: qcom: gcc-mdm9607: Drop incorrect BIMC PLL and related clocks
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Stephan Gerhold <[email protected]>
commit e111ddda092ad961870a634e4c9263c10a3e8485 upstream.
The gcc-mdm9607 driver was originally based on gcc-msm8916, but a closer match nowadays is gcc-msm8909. Looking at the differences between gcc-mdm9607 and gcc-msm8909, there is quite some confusion around the definitions for the BIMC PLL.
It turns out the BIMC PLL on MDM9607 is actually an Alpha PLL just like on MSM8909. We can vote for it using BIT(2), which explains why BIT(3) was used for GPLL2.
In practice, the BIMC PLL is exclusively controlled by the RPM firmware and Linux should not touch it. So far, it was defined to model the full clock hierarchy, but even in read-only mode with CLK_GET_RATE_NOCACHE this is problematic since the RPM will silently change the clock parents without notifying Linux about it. The clock framework reads the clock parent only once during boot, so the resulting rates will still be often wrong.
Follow the example of more recent SoCs and drop the BIMC PLL and all remaining related clocks to avoid reporting stale status data. This means we cannot determine the rate of these clocks anymore. This is not a big problem in practice, since these are NoC-related clocks that are independently managed through the interconnect subsystem.
--- drivers/clk/qcom/gcc-mdm9607.c | 125 ----------------------------------------- 1 file changed, 1 insertion(+), 124 deletions(-)
drivers/clk/qcom/gcc-mdm9607.c +1 -124
@@ -26,7 +26,6 @@enum {P_XO , -P_BIMC ,P_GPLL0 ,P_GPLL1 ,P_GPLL2 ,
@@ -121,7 +120,7 @@ static struct clk_alpha_pll gpll2_early .regs = clk_alpha_pll_regs[CLK_ALPHA_PLL_TYPE_DEFAULT], .clkr = { .enable_reg = 0x45000, - .enable_mask = BIT(3), /* Yeah, apparently it's not 2 */ + .enable_mask = BIT(3), /* BIT(2) is used for BIMC PLL */ .hw.init = &(struct clk_init_data) { .name = "gpll2_early",
@@ -178,68 +177,6 @@ static struct clk_rcg2 apss_ahb_clk_src }, }; -static struct clk_pll bimc_pll = { - .l_reg =0x23004 , - .m_reg =0x23008 , - .n_reg =0x2300c , - .config_reg =0x23010 , - .mode_reg =0x23000 , - .status_reg =0x2301c , - .status_bit =17 , - .clkr.hw.init = &(struct clk_init_data ){ - .name ="bimc_pll" , - .parent_data = &(const struct clk_parent_data ){ - .fw_name ="xo" , - }, - .num_parents =1 , - .ops = &clk_pll_ops, - }, -}; - -static struct clk_regmap bimc_pll_vote = { - .enable_reg =0x45000 , - .enable_mask =BIT (3 ), - .hw.init = &(struct clk_init_data ){ - .name ="bimc_pll_vote" , - .parent_hws = (const struct clk_hw *[]){ &bimc_pll.clkr.hw }, - .num_parents =1 , - .ops = &clk_pll_vote_ops, - }, -}; - -static const struct parent_map gcc_xo_gpll0_bimc_map[] = { - {P_XO ,0 }, - {P_GPLL0 ,1 }, - {P_BIMC ,2 }, -}; - -static const struct clk_parent_data gcc_xo_gpll0_bimc[] = { - { .fw_name ="xo" }, - { .hw = &gpll0.clkr.hw }, - { .hw = &bimc_pll_vote.hw }, -}; - -static const struct freq_tbl ftbl_pcnoc_bfdcd_clk_src[] = { -F (19200000 ,P_XO ,1 ,0 ,0 ), -F (50000000 ,P_GPLL0 ,16 ,0 ,0 ), -F (100000000 ,P_GPLL0 ,8 ,0 ,0 ), - { } -}; - -static struct clk_rcg2 pcnoc_bfdcd_clk_src = { - .cmd_rcgr =0x27000 , - .freq_tbl = ftbl_pcnoc_bfdcd_clk_src, - .hid_width =5 , - .parent_map = gcc_xo_gpll0_bimc_map, - .clkr.hw.init = &(struct clk_init_data ){ - .name ="pcnoc_bfdcd_clk_src" , - .parent_data = gcc_xo_gpll0_bimc, - .num_parents =ARRAY_SIZE (gcc_xo_gpll0_bimc), - .ops = &clk_rcg2_ops, - .flags =CLK_IS_CRITICAL , - }, -}; -static const struct freq_tbl ftbl_gcc_blsp1_qup1_6_i2c_apps_clk[] = {F (19200000 ,P_XO ,1 ,0 ,0 ),F (50000000 ,P_GPLL0 ,16 ,0 ,0 ),
@@ -735,8 +672,6 @@ static struct clk_branch gcc_blsp1_ahb_c .enable_mask = BIT(10), .hw.init = &(struct clk_init_data ){ .name ="gcc_blsp1_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , .ops = &clk_branch2_ops, }, },
@@ -1038,8 +973,6 @@ static struct clk_branch gcc_boot_rom_ah .enable_mask = BIT(7), .hw.init = &(struct clk_init_data ){ .name ="gcc_boot_rom_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , .ops = &clk_branch2_ops, }, },
@@ -1053,9 +986,6 @@ static struct clk_branch gcc_crypto_ahb_ .enable_mask = BIT(0), .hw.init = &(struct clk_init_data ){ .name ="gcc_crypto_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1069,9 +999,6 @@ static struct clk_branch gcc_crypto_axi_ .enable_mask = BIT(1), .hw.init = &(struct clk_init_data ){ .name ="gcc_crypto_axi_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1145,9 +1072,6 @@ static struct clk_branch gcc_mss_cfg_ahb .enable_mask = BIT(0), .hw.init = &(struct clk_init_data ){ .name ="gcc_mss_cfg_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1175,9 +1099,6 @@ static struct clk_branch gcc_pdm_ahb_clk .enable_mask = BIT(0), .hw.init = &(struct clk_init_data ){ .name ="gcc_pdm_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1191,9 +1112,6 @@ static struct clk_branch gcc_prng_ahb_cl .enable_mask = BIT(8), .hw.init = &(struct clk_init_data ){ .name ="gcc_prng_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1206,9 +1124,6 @@ static struct clk_branch gcc_sdcc1_ahb_c .enable_mask = BIT(0), .hw.init = &(struct clk_init_data ){ .name ="gcc_sdcc1_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1236,9 +1151,6 @@ static struct clk_branch gcc_sdcc2_ahb_c .enable_mask = BIT(0), .hw.init = &(struct clk_init_data ){ .name ="gcc_sdcc2_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1259,19 +1171,6 @@ static struct clk_branch gcc_sdcc2_apps_ }, }; -static struct clk_rcg2 bimc_ddr_clk_src = { - .cmd_rcgr =0x32004 , - .hid_width =5 , - .parent_map = gcc_xo_gpll0_bimc_map, - .clkr.hw.init = &(struct clk_init_data ){ - .name ="bimc_ddr_clk_src" , - .parent_data = gcc_xo_gpll0_bimc, - .num_parents =3 , - .ops = &clk_rcg2_ops, - .flags =CLK_GET_RATE_NOCACHE , - }, -}; -static struct clk_branch gcc_mss_q6_bimc_axi_clk = { .halt_reg =0x49004 , .clkr = {
@@ -1279,9 +1178,6 @@ static struct clk_branch gcc_mss_q6_bimc .enable_mask = BIT(0), .hw.init = &(struct clk_init_data ){ .name ="gcc_mss_q6_bimc_axi_clk" , - .parent_hws = (const struct clk_hw *[]){ &bimc_ddr_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1295,8 +1191,6 @@ static struct clk_branch gcc_apss_tcu_cl .enable_mask = BIT(1), .hw.init = &(struct clk_init_data ){ .name ="gcc_apss_tcu_clk" , - .parent_hws = (const struct clk_hw *[]){ &bimc_ddr_clk_src.clkr.hw }, - .num_parents =1 , .ops = &clk_branch2_ops, }, },
@@ -1310,9 +1204,6 @@ static struct clk_branch gcc_smmu_cfg_cl .enable_mask = BIT(12), .hw.init = &(struct clk_init_data ){ .name ="gcc_smmu_cfg_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1360,9 +1251,6 @@ static struct clk_branch gcc_usb_hs_phy_ .enable_mask = BIT(0), .hw.init = &(struct clk_init_data ){ .name ="gcc_usb_hs_phy_cfg_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1375,9 +1263,6 @@ static struct clk_branch gcc_usb_hs_ahb_ .enable_mask = BIT(0), .hw.init = &(struct clk_init_data ){ .name ="gcc_usb_hs_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , - .flags =CLK_SET_RATE_PARENT , .ops = &clk_branch2_ops, }, },
@@ -1406,8 +1291,6 @@ static struct clk_branch gcc_apss_ahb_cl .enable_mask = BIT(14), .hw.init = &(struct clk_init_data ){ .name ="gcc_apss_ahb_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , .ops = &clk_branch2_ops, }, },
@@ -1421,8 +1304,6 @@ static struct clk_branch gcc_apss_axi_cl .enable_mask = BIT(13), .hw.init = &(struct clk_init_data ){ .name ="gcc_apss_axi_clk" , - .parent_hws = (const struct clk_hw *[]){ &pcnoc_bfdcd_clk_src.clkr.hw }, - .num_parents =1 , .ops = &clk_branch2_ops, }, },
@@ -1435,10 +1316,6 @@ static struct clk_regmap *gcc_mdm9607_cl [GPLL1_VOTE] = &gpll1_vote, [GPLL2] = &gpll2.clkr, [GPLL2_EARLY] = &gpll2_early.clkr, - [BIMC_PLL] = &bimc_pll.clkr, - [BIMC_PLL_VOTE] = &bimc_pll_vote, - [BIMC_DDR_CLK_SRC] = &bimc_ddr_clk_src.clkr, - [PCNOC_BFDCD_CLK_SRC] = &pcnoc_bfdcd_clk_src.clkr, [APSS_AHB_CLK_SRC] = &apss_ahb_clk_src.clkr, [BLSP1_QUP1_I2C_APPS_CLK_SRC] = &blsp1_qup1_i2c_apps_clk_src.clkr, [BLSP1_QUP1_SPI_APPS_CLK_SRC] = &blsp1_qup1_spi_apps_clk_src.clkr,
Greg Kroah-Hartman
maintainerPATCH 219/556 i2c: mux: demux-pinctrl: fix OF node leak on kstrdup failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Linkai Gong <[email protected]>
commit 62edb8ca0aa44517cc23cfa26cd8a51f15ea92fe upstream.
of_parse_phandle() takes a reference on the parent node. If a later devm_kstrdup() fails, err_rollback only releases nodes for indices 0..i-1, so the current node is leaked.
of_node_put() the current parent before rolling back.
--- drivers/i2c/muxes/i2c-demux-pinctrl.c | 1 + 1 file changed, 1 insertion(+)
drivers/i2c/muxes/i2c-demux-pinctrl.c +1 -0
@@ -247,6 +247,7 @@ static int i2c_demux_pinctrl_probe(struc props[i].value =devm_kstrdup (&pdev->dev,"ok" ,GFP_KERNEL );if (!props[i].name || !props[i].value) { err = -ENOMEM ; +of_node_put (adap_np); goto err_rollback; } props[i].length =3 ;
Greg Kroah-Hartman
maintainerPATCH 220/556 ASoC: adau1761: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit cc606b6c2328b4864885db6afcad7e78c0ac7a73 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
The table lists the ADAU1761 specific registers (0x4008 and up) before the block shared with the ADAU1381/ADAU1781, which starts at ADAU17X1_CLOCK_CONTROL (0x4000), so bsearch() descends into the wrong half and 28 of the 52 entries are unreachable. regcache_reg_needs_sync() then cannot compare them against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort the table by register address.
--- sound/soc/codecs/adau1761.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
sound/soc/codecs/adau1761.c +17 -17
@@ -68,23 +68,33 @@#define ADAU1761_FIRMWARE "adau1761.bin"static const struct reg_default adau1761_reg_defaults[] = { - {ADAU1761_DEJITTER ,0x03 }, + {ADAU17X1_CLOCK_CONTROL ,0x00 }, + {ADAU17X1_PLL_CONTROL ,0x00 }, {ADAU1761_DIGMIC_JACKDETECT ,0x00 }, + {ADAU17X1_REC_POWER_MGMT ,0x00 }, {ADAU1761_REC_MIXER_LEFT0 ,0x00 }, {ADAU1761_REC_MIXER_LEFT1 ,0x00 }, {ADAU1761_REC_MIXER_RIGHT0 ,0x00 }, {ADAU1761_REC_MIXER_RIGHT1 ,0x00 }, {ADAU1761_LEFT_DIFF_INPUT_VOL ,0x00 }, + {ADAU1761_RIGHT_DIFF_INPUT_VOL ,0x00 }, + {ADAU17X1_MICBIAS ,0x00 }, {ADAU1761_ALC_CTRL0 ,0x00 }, {ADAU1761_ALC_CTRL1 ,0x00 }, {ADAU1761_ALC_CTRL2 ,0x00 }, {ADAU1761_ALC_CTRL3 ,0x00 }, - {ADAU1761_RIGHT_DIFF_INPUT_VOL ,0x00 }, - {ADAU1761_PLAY_LR_MIXER_LEFT ,0x00 }, + {ADAU17X1_SERIAL_PORT0 ,0x00 }, + {ADAU17X1_SERIAL_PORT1 ,0x00 }, + {ADAU17X1_CONVERTER0 ,0x00 }, + {ADAU17X1_CONVERTER1 ,0x00 }, + {ADAU17X1_ADC_CONTROL ,0x00 }, + {ADAU17X1_LEFT_INPUT_DIGITAL_VOL ,0x00 }, + {ADAU17X1_RIGHT_INPUT_DIGITAL_VOL ,0x00 }, {ADAU1761_PLAY_MIXER_LEFT0 ,0x00 }, {ADAU1761_PLAY_MIXER_LEFT1 ,0x00 }, {ADAU1761_PLAY_MIXER_RIGHT0 ,0x00 }, {ADAU1761_PLAY_MIXER_RIGHT1 ,0x00 }, + {ADAU1761_PLAY_LR_MIXER_LEFT ,0x00 }, {ADAU1761_PLAY_LR_MIXER_RIGHT ,0x00 }, {ADAU1761_PLAY_MIXER_MONO ,0x00 }, {ADAU1761_PLAY_HP_LEFT_VOL ,0x00 },
@@ -93,20 +103,6 @@ static const struct reg_default adau1761 { ADAU1761_PLAY_LINE_RIGHT_VOL, 0x00 }, { ADAU1761_PLAY_MONO_OUTPUT_VOL, 0x00 }, { ADAU1761_POP_CLICK_SUPPRESS, 0x00 }, - { ADAU1761_JACK_DETECT_PIN, 0x00 }, - { ADAU1761_CLK_ENABLE0, 0x00 }, - { ADAU1761_CLK_ENABLE1, 0x00 }, - { ADAU17X1_CLOCK_CONTROL, 0x00 }, - { ADAU17X1_PLL_CONTROL, 0x00 }, - { ADAU17X1_REC_POWER_MGMT, 0x00 }, - { ADAU17X1_MICBIAS, 0x00 }, - { ADAU17X1_SERIAL_PORT0, 0x00 }, - { ADAU17X1_SERIAL_PORT1, 0x00 }, - { ADAU17X1_CONVERTER0, 0x00 }, - { ADAU17X1_CONVERTER1, 0x00 }, - { ADAU17X1_LEFT_INPUT_DIGITAL_VOL, 0x00 }, - { ADAU17X1_RIGHT_INPUT_DIGITAL_VOL, 0x00 }, - { ADAU17X1_ADC_CONTROL, 0x00 }, { ADAU17X1_PLAY_POWER_MGMT, 0x00 }, { ADAU17X1_DAC_CONTROL0, 0x00 }, { ADAU17X1_DAC_CONTROL1, 0x00 },
@@ -114,12 +110,16 @@ static const struct reg_default adau1761 { ADAU17X1_SERIAL_PORT_PAD, 0xaa }, { ADAU17X1_CONTROL_PORT_PAD0, 0xaa }, { ADAU17X1_CONTROL_PORT_PAD1, 0x00 }, + { ADAU1761_JACK_DETECT_PIN, 0x00 }, + { ADAU1761_DEJITTER, 0x03 }, { ADAU17X1_DSP_SAMPLING_RATE, 0x01 }, { ADAU17X1_SERIAL_INPUT_ROUTE, 0x00 }, { ADAU17X1_SERIAL_OUTPUT_ROUTE, 0x00 }, { ADAU17X1_DSP_ENABLE, 0x00 }, { ADAU17X1_DSP_RUN, 0x00 }, { ADAU17X1_SERIAL_SAMPLING_RATE, 0x00 }, + { ADAU1761_CLK_ENABLE0, 0x00 }, + { ADAU1761_CLK_ENABLE1, 0x00 }, }; static const DECLARE_TLV_DB_SCALE(adau1761_sing_in_tlv, -1500, 300, 1);
Greg Kroah-Hartman
maintainerPATCH 221/556 ASoC: cs35l33: drain threaded IRQ before runtime suspend
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit e074c12c428c633e079154301207a6079a208583 upstream.
cs35l33_runtime_suspend() currently switches the codec into regcache_cache_only(true) and powers it down without first quiescing the threaded IRQ registered by devm_request_threaded_irq(). That leaves a window where cs35l33_irq_thread() can still run after suspend has closed off live register access.
A running system can reach this during runtime PM while the driver still has critical fault IRQs unmasked. If the threaded handler runs in that window, it reads volatile INT_STATUS_1/2 after cache_only has been enabled, ignores the regmap_read() failures, and can still drive the AMP_SHORT_RLS, CAL_ERR_RLS, OTE_RLS, and OTW_RLS release paths.
Use disable_irq() before entering cache_only/power-off so any in-flight threaded handler is drained and no new IRQ thread can run during the suspended state. Re-enable the IRQ only after runtime_resume() has restored live register access with regcache_sync(). Since probe only warns if devm_request_threaded_irq() fails, track whether the IRQ was actually installed before disabling or re-enabling it.
--- sound/soc/codecs/cs35l33.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
sound/soc/codecs/cs35l33.c +12 -2
@@ -40,6 +40,7 @@ struct cs35l33_private {struct regmap *regmap;struct gpio_desc *reset_gpio;bool amp_cal; +bool irq_requested;int mclk_int;struct regulator_bulk_data core_supplies[2 ];int num_core_supplies;
@@ -881,6 +882,9 @@ static int cs35l33_runtime_resume(struct goto err; } +if (cs35l33->irq_requested) +enable_irq (to_i2c_client (dev)->irq); +return 0 ; err:
@@ -900,6 +904,10 @@ static int cs35l33_runtime_suspend(struc/* redo the calibration in next power up */ cs35l33->amp_cal = false; +/* Drain and block the threaded IRQ before cache_only/power-off. */ +if (cs35l33->irq_requested) +disable_irq (to_i2c_client (dev)->irq); +regcache_cache_only (cs35l33->regmap, true);regcache_mark_dirty (cs35l33->regmap); regulator_bulk_disable(cs35l33->num_core_supplies,
@@ -1154,10 +1162,12 @@ static int cs35l33_i2c_probe(struct i2c_ } ret =devm_request_threaded_irq (&i2c_client->dev, i2c_client->irq,NULL , - cs35l33_irq_thread,IRQF_ONESHOT |IRQF_TRIGGER_LOW , -"cs35l33" , cs35l33); + cs35l33_irq_thread,IRQF_ONESHOT |IRQF_TRIGGER_LOW , +"cs35l33" , cs35l33);if (ret !=0 )dev_warn (&i2c_client->dev,"Failed to request IRQ: %d\n" , ret); +else + cs35l33->irq_requested = true;/* We could issue !RST or skip it based on AMP topology */ cs35l33->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev,
Greg Kroah-Hartman
maintainerPATCH 222/556 ASoC: cs35l34: drain threaded IRQ before runtime suspend
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Runyu Xiao <[email protected]>
commit 4105a4c0678b2808fc8046b60321b4f1cc7dae75 upstream.
cs35l34_runtime_suspend() currently switches the codec into regcache_cache_only(true), asserts reset low, and powers the device off without first quiescing the threaded IRQ registered by devm_request_threaded_irq(). That leaves a window where cs35l34_irq_thread() can still run after suspend has removed live hardware access.
A running system can reach this during runtime PM while the driver still has critical fault IRQs unmasked. If the threaded handler runs in that window, it reads volatile INT_STATUS_1..4 after cache_only has been enabled, ignores the regmap_read() failures, and can still execute the PROT_RELEASE_CTL release sequence or the BST fault power-down writes.
Use disable_irq() before entering cache_only/reset-low/power-off so any in-flight threaded handler is drained and no new IRQ thread can run while the device is suspended. Re-enable the IRQ only after runtime_resume() has restored live register access with regcache_sync(). Since probe only logs request_threaded_irq() failures and keeps going, track whether the IRQ was actually installed before disabling or re-enabling it.
--- sound/soc/codecs/cs35l34.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
sound/soc/codecs/cs35l34.c +12 -2
@@ -45,6 +45,7 @@ struct cs35l34_private {int num_core_supplies;int mclk_int;bool tdm_mode; +bool irq_requested;struct gpio_desc *reset_gpio;/* Active-low reset GPIO */ };
@@ -1032,10 +1033,12 @@ static int cs35l34_i2c_probe(struct i2c_ } ret =devm_request_threaded_irq (&i2c_client->dev, i2c_client->irq,NULL , - cs35l34_irq_thread,IRQF_ONESHOT |IRQF_TRIGGER_LOW , -"cs35l34" , cs35l34); + cs35l34_irq_thread,IRQF_ONESHOT |IRQF_TRIGGER_LOW , +"cs35l34" , cs35l34);if (ret !=0 )dev_err (&i2c_client->dev,"Failed to request IRQ: %d\n" , ret); +else + cs35l34->irq_requested = true; cs35l34->reset_gpio =devm_gpiod_get_optional (&i2c_client->dev,"reset" ,GPIOD_OUT_LOW );
@@ -1140,6 +1143,9 @@ static int cs35l34_runtime_resume(structdev_err (dev,"Failed to restore register cache\n" ); goto err; } + +if (cs35l34->irq_requested) +enable_irq (to_i2c_client (dev)->irq);return 0 ; err:regcache_cache_only (cs35l34->regmap, true);
@@ -1153,6 +1159,10 @@ static int cs35l34_runtime_suspend(struc {struct cs35l34_private *cs35l34 =dev_get_drvdata (dev); +/* Drain and block the threaded IRQ before cache_only/power-off. */ +if (cs35l34->irq_requested) +disable_irq (to_i2c_client (dev)->irq); +regcache_cache_only (cs35l34->regmap, true);regcache_mark_dirty (cs35l34->regmap);
Greg Kroah-Hartman
maintainerPATCH 223/556 ASoC: cx2072x: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit b927853f70078262780a4e623631584a25eb7284 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
The table is grouped by function rather than by address: for every node the amplifier gain registers (0x41c0, 0x45c0, ...) are listed before the power state and stream format registers of the same node (0x4014, 0x4414, ...). This leaves 75 of the 132 entries unreachable. regcache_reg_needs_sync() then cannot compare them against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort the table by register address.
--- sound/soc/codecs/cx2072x.c | 122 ++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 61 deletions(-)
sound/soc/codecs/cx2072x.c +61 -61
@@ -96,51 +96,60 @@ static const struct reg_default cx2072x_ { CX2072X_GPIO_WAKE, 0x00000000 }, { CX2072X_GPIO_UM_ENABLE, 0x00000000 }, { CX2072X_GPIO_STICKY_MASK, 0x00000000 }, - { CX2072X_DAC1_CONVERTER_FORMAT, 0x00000031 }, - { CX2072X_DAC1_AMP_GAIN_RIGHT, 0x0000004a }, - { CX2072X_DAC1_AMP_GAIN_LEFT, 0x0000004a }, { CX2072X_DAC1_POWER_STATE, 0x00000433 }, { CX2072X_DAC1_CONVERTER_STREAM_CHANNEL, 0x00000000 }, { CX2072X_DAC1_EAPD_ENABLE, 0x00000000 }, - { CX2072X_DAC2_CONVERTER_FORMAT, 0x00000031 }, - { CX2072X_DAC2_AMP_GAIN_RIGHT, 0x0000004a }, - { CX2072X_DAC2_AMP_GAIN_LEFT, 0x0000004a }, + { CX2072X_DAC1_AMP_GAIN_RIGHT, 0x0000004a }, + { CX2072X_DAC1_AMP_GAIN_LEFT, 0x0000004a }, + { CX2072X_DAC1_CONVERTER_FORMAT, 0x00000031 }, { CX2072X_DAC2_POWER_STATE, 0x00000433 }, { CX2072X_DAC2_CONVERTER_STREAM_CHANNEL, 0x00000000 }, - { CX2072X_ADC1_CONVERTER_FORMAT, 0x00000031 }, + { CX2072X_DAC2_AMP_GAIN_RIGHT, 0x0000004a }, + { CX2072X_DAC2_AMP_GAIN_LEFT, 0x0000004a }, + { CX2072X_DAC2_CONVERTER_FORMAT, 0x00000031 }, + { CX2072X_ADC1_CONNECTION_SELECT_CONTROL, 0x00000000 }, + { CX2072X_ADC1_POWER_STATE, 0x00000433 }, + { CX2072X_ADC1_CONVERTER_STREAM_CHANNEL, 0x00000000 }, { CX2072X_ADC1_AMP_GAIN_RIGHT_0, 0x0000004a }, - { CX2072X_ADC1_AMP_GAIN_LEFT_0, 0x0000004a }, { CX2072X_ADC1_AMP_GAIN_RIGHT_1, 0x0000004a }, - { CX2072X_ADC1_AMP_GAIN_LEFT_1, 0x0000004a }, { CX2072X_ADC1_AMP_GAIN_RIGHT_2, 0x0000004a }, - { CX2072X_ADC1_AMP_GAIN_LEFT_2, 0x0000004a }, { CX2072X_ADC1_AMP_GAIN_RIGHT_3, 0x0000004a }, - { CX2072X_ADC1_AMP_GAIN_LEFT_3, 0x0000004a }, { CX2072X_ADC1_AMP_GAIN_RIGHT_4, 0x0000004a }, - { CX2072X_ADC1_AMP_GAIN_LEFT_4, 0x0000004a }, { CX2072X_ADC1_AMP_GAIN_RIGHT_5, 0x0000004a }, - { CX2072X_ADC1_AMP_GAIN_LEFT_5, 0x0000004a }, { CX2072X_ADC1_AMP_GAIN_RIGHT_6, 0x0000004a }, + { CX2072X_ADC1_AMP_GAIN_LEFT_0, 0x0000004a }, + { CX2072X_ADC1_AMP_GAIN_LEFT_1, 0x0000004a }, + { CX2072X_ADC1_AMP_GAIN_LEFT_2, 0x0000004a }, + { CX2072X_ADC1_AMP_GAIN_LEFT_3, 0x0000004a }, + { CX2072X_ADC1_AMP_GAIN_LEFT_4, 0x0000004a }, + { CX2072X_ADC1_AMP_GAIN_LEFT_5, 0x0000004a }, { CX2072X_ADC1_AMP_GAIN_LEFT_6, 0x0000004a }, - { CX2072X_ADC1_CONNECTION_SELECT_CONTROL, 0x00000000 }, - { CX2072X_ADC1_POWER_STATE, 0x00000433 }, - { CX2072X_ADC1_CONVERTER_STREAM_CHANNEL, 0x00000000 }, - { CX2072X_ADC2_CONVERTER_FORMAT, 0x00000031 }, + { CX2072X_ADC1_CONVERTER_FORMAT, 0x00000031 }, + { CX2072X_ADC2_CONNECTION_SELECT_CONTROL, 0x00000000 }, + { CX2072X_ADC2_POWER_STATE, 0x00000433 }, + { CX2072X_ADC2_CONVERTER_STREAM_CHANNEL, 0x00000000 }, { CX2072X_ADC2_AMP_GAIN_RIGHT_0, 0x0000004a }, - { CX2072X_ADC2_AMP_GAIN_LEFT_0, 0x0000004a }, { CX2072X_ADC2_AMP_GAIN_RIGHT_1, 0x0000004a }, - { CX2072X_ADC2_AMP_GAIN_LEFT_1, 0x0000004a }, { CX2072X_ADC2_AMP_GAIN_RIGHT_2, 0x0000004a }, + { CX2072X_ADC2_AMP_GAIN_LEFT_0, 0x0000004a }, + { CX2072X_ADC2_AMP_GAIN_LEFT_1, 0x0000004a }, { CX2072X_ADC2_AMP_GAIN_LEFT_2, 0x0000004a }, - { CX2072X_ADC2_CONNECTION_SELECT_CONTROL, 0x00000000 }, - { CX2072X_ADC2_POWER_STATE, 0x00000433 }, - { CX2072X_ADC2_CONVERTER_STREAM_CHANNEL, 0x00000000 }, + { CX2072X_ADC2_CONVERTER_FORMAT, 0x00000031 }, + { CX2072X_MIXER_POWER_STATE, 0x00000433 }, + { CX2072X_MIXER_GAIN_RIGHT_0, 0x0000004a }, + { CX2072X_MIXER_GAIN_RIGHT_1, 0x0000004a }, + { CX2072X_MIXER_GAIN_LEFT_0, 0x0000004a }, + { CX2072X_MIXER_GAIN_LEFT_1, 0x0000004a }, { CX2072X_PORTA_CONNECTION_SELECT_CTRL, 0x00000000 }, { CX2072X_PORTA_POWER_STATE, 0x00000433 }, { CX2072X_PORTA_PIN_CTRL, 0x000000c0 }, { CX2072X_PORTA_UNSOLICITED_RESPONSE, 0x00000000 }, { CX2072X_PORTA_PIN_SENSE, 0x00000000 }, { CX2072X_PORTA_EAPD_BTL, 0x00000002 }, + { CX2072X_PORTG_CONNECTION_SELECT_CTRL, 0x00000000 }, + { CX2072X_PORTG_POWER_STATE, 0x00000433 }, + { CX2072X_PORTG_PIN_CTRL, 0x00000040 }, + { CX2072X_PORTG_EAPD_BTL, 0x00000002 }, { CX2072X_PORTB_POWER_STATE, 0x00000433 }, { CX2072X_PORTB_PIN_CTRL, 0x00000000 }, { CX2072X_PORTB_UNSOLICITED_RESPONSE, 0x00000000 },
@@ -148,43 +157,16 @@ static const struct reg_default cx2072x_ { CX2072X_PORTB_EAPD_BTL, 0x00000002 }, { CX2072X_PORTB_GAIN_RIGHT, 0x00000000 }, { CX2072X_PORTB_GAIN_LEFT, 0x00000000 }, - { CX2072X_PORTC_POWER_STATE, 0x00000433 }, - { CX2072X_PORTC_PIN_CTRL, 0x00000000 }, - { CX2072X_PORTC_GAIN_RIGHT, 0x00000000 }, - { CX2072X_PORTC_GAIN_LEFT, 0x00000000 }, { CX2072X_PORTD_POWER_STATE, 0x00000433 }, { CX2072X_PORTD_PIN_CTRL, 0x00000020 }, { CX2072X_PORTD_UNSOLICITED_RESPONSE, 0x00000000 }, { CX2072X_PORTD_PIN_SENSE, 0x00000000 }, { CX2072X_PORTD_GAIN_RIGHT, 0x00000000 }, { CX2072X_PORTD_GAIN_LEFT, 0x00000000 }, - { CX2072X_PORTE_CONNECTION_SELECT_CTRL, 0x00000000 }, - { CX2072X_PORTE_POWER_STATE, 0x00000433 }, - { CX2072X_PORTE_PIN_CTRL, 0x00000040 }, - { CX2072X_PORTE_UNSOLICITED_RESPONSE, 0x00000000 }, - { CX2072X_PORTE_PIN_SENSE, 0x00000000 }, - { CX2072X_PORTE_EAPD_BTL, 0x00000002 }, - { CX2072X_PORTE_GAIN_RIGHT, 0x00000000 }, - { CX2072X_PORTE_GAIN_LEFT, 0x00000000 }, - { CX2072X_PORTF_POWER_STATE, 0x00000433 }, - { CX2072X_PORTF_PIN_CTRL, 0x00000000 }, - { CX2072X_PORTF_UNSOLICITED_RESPONSE, 0x00000000 }, - { CX2072X_PORTF_PIN_SENSE, 0x00000000 }, - { CX2072X_PORTF_GAIN_RIGHT, 0x00000000 }, - { CX2072X_PORTF_GAIN_LEFT, 0x00000000 }, - { CX2072X_PORTG_POWER_STATE, 0x00000433 }, - { CX2072X_PORTG_PIN_CTRL, 0x00000040 }, - { CX2072X_PORTG_CONNECTION_SELECT_CTRL, 0x00000000 }, - { CX2072X_PORTG_EAPD_BTL, 0x00000002 }, - { CX2072X_PORTM_POWER_STATE, 0x00000433 }, - { CX2072X_PORTM_PIN_CTRL, 0x00000000 }, - { CX2072X_PORTM_CONNECTION_SELECT_CTRL, 0x00000000 }, - { CX2072X_PORTM_EAPD_BTL, 0x00000002 }, - { CX2072X_MIXER_POWER_STATE, 0x00000433 }, - { CX2072X_MIXER_GAIN_RIGHT_0, 0x0000004a }, - { CX2072X_MIXER_GAIN_LEFT_0, 0x0000004a }, - { CX2072X_MIXER_GAIN_RIGHT_1, 0x0000004a }, - { CX2072X_MIXER_GAIN_LEFT_1, 0x0000004a }, + { CX2072X_PORTC_POWER_STATE, 0x00000433 }, + { CX2072X_PORTC_PIN_CTRL, 0x00000000 }, + { CX2072X_PORTC_GAIN_RIGHT, 0x00000000 }, + { CX2072X_PORTC_GAIN_LEFT, 0x00000000 }, { CX2072X_SPKR_DRC_ENABLE_STEP, 0x040065a4 }, { CX2072X_SPKR_DRC_CONTROL, 0x007b0024 }, { CX2072X_SPKR_DRC_TEST, 0x00000000 },
@@ -195,12 +177,15 @@ static const struct reg_default cx2072x_ { CX2072X_I2SPCM_CONTROL3, 0x00000000 }, { CX2072X_I2SPCM_CONTROL4, 0x00000000 }, { CX2072X_I2SPCM_CONTROL5, 0x00000000 }, - { CX2072X_I2SPCM_CONTROL6, 0x00000000 }, { CX2072X_UM_INTERRUPT_CRTL_E, 0x00000000 }, + { CX2072X_I2SPCM_CONTROL6, 0x00000000 }, + { CX2072X_DIGITAL_TEST16, 0x00000021 }, + { CX2072X_DIGITAL_TEST17, 0x00000018 }, + { CX2072X_DIGITAL_TEST18, 0x00000024 }, + { CX2072X_DIGITAL_TEST19, 0x00000001 }, + { CX2072X_DIGITAL_TEST20, 0x00000002 }, { CX2072X_CODEC_TEST2, 0x00000000 }, { CX2072X_CODEC_TEST9, 0x00000004 }, - { CX2072X_CODEC_TEST20, 0x00000600 }, - { CX2072X_CODEC_TEST26, 0x00000208 }, { CX2072X_ANALOG_TEST4, 0x00000000 }, { CX2072X_ANALOG_TEST5, 0x00000000 }, { CX2072X_ANALOG_TEST6, 0x0000059a },
@@ -215,11 +200,26 @@ static const struct reg_default cx2072x_ { CX2072X_DIGITAL_TEST11, 0x00000000 }, { CX2072X_DIGITAL_TEST12, 0x00000084 }, { CX2072X_DIGITAL_TEST15, 0x00000077 }, - { CX2072X_DIGITAL_TEST16, 0x00000021 }, - { CX2072X_DIGITAL_TEST17, 0x00000018 }, - { CX2072X_DIGITAL_TEST18, 0x00000024 }, - { CX2072X_DIGITAL_TEST19, 0x00000001 }, - { CX2072X_DIGITAL_TEST20, 0x00000002 }, + { CX2072X_CODEC_TEST20, 0x00000600 }, + { CX2072X_CODEC_TEST26, 0x00000208 }, + { CX2072X_PORTE_CONNECTION_SELECT_CTRL, 0x00000000 }, + { CX2072X_PORTE_POWER_STATE, 0x00000433 }, + { CX2072X_PORTE_PIN_CTRL, 0x00000040 }, + { CX2072X_PORTE_UNSOLICITED_RESPONSE, 0x00000000 }, + { CX2072X_PORTE_PIN_SENSE, 0x00000000 }, + { CX2072X_PORTE_EAPD_BTL, 0x00000002 }, + { CX2072X_PORTE_GAIN_RIGHT, 0x00000000 }, + { CX2072X_PORTE_GAIN_LEFT, 0x00000000 }, + { CX2072X_PORTF_POWER_STATE, 0x00000433 }, + { CX2072X_PORTF_PIN_CTRL, 0x00000000 }, + { CX2072X_PORTF_UNSOLICITED_RESPONSE, 0x00000000 }, + { CX2072X_PORTF_PIN_SENSE, 0x00000000 }, + { CX2072X_PORTF_GAIN_RIGHT, 0x00000000 }, + { CX2072X_PORTF_GAIN_LEFT, 0x00000000 }, + { CX2072X_PORTM_CONNECTION_SELECT_CTRL, 0x00000000 }, + { CX2072X_PORTM_POWER_STATE, 0x00000433 }, + { CX2072X_PORTM_PIN_CTRL, 0x00000000 }, + { CX2072X_PORTM_EAPD_BTL, 0x00000002 }, };/*
Greg Kroah-Hartman
maintainerPATCH 224/556 ASoC: fsl: mpc5200-i2s: Free DMA resources on probe failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
commit 3a89ddcf0c3d9a068631e8c24d5c9e81d1e6512a upstream.
mpc5200_audio_dma_create() creates the DMA resources before registering the component. If snd_soc_register_component() fails, the function returns directly and leaves the DMA resources allocated.
Call mpc5200_audio_dma_destroy() before returning from this error path.
--- sound/soc/fsl/mpc5200_psc_i2s.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/fsl/mpc5200_psc_i2s.c +1 -0
@@ -170,6 +170,7 @@ static int psc_i2s_of_probe(struct platf psc_i2s_dai, ARRAY_SIZE(psc_i2s_dai));if (rc !=0 ) {pr_err ("Failed to register DAI\n" ); +mpc5200_audio_dma_destroy (op);return rc; }
Greg Kroah-Hartman
maintainerPATCH 225/556 ASoC: fsl_easrc: Use div64_u64 for 64-by-64 division
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: wangdicheng <[email protected]>
commit a46ccc71877e962783e0fffa105e41615904c511 upstream.
Fix a coccinelle warning about do_div() truncating a 64-bit divisor:
sound/soc/fsl/fsl_easrc.c:2061:2-8: WARNING: do_div() does a 64-by-32 division, please consider using div64_u64 instead.
In fsl_easrc_m2m_calc_out_len(), val1 is computed as:
val1 = (u64)in_rate << frac_bits; // frac_bits up to 39 do_div(val1, out_rate); val1 += (s64)ctx_priv->ratio_mod << (frac_bits - 31); val1 = val1 >> 12;
In the worst case (in_rate=384000, out_rate=8000, frac_bits=39):
val1 = 384000 << 39 / 8000 = 26,388,279,068,672
val1 >> 12 = 6,440,497,829 (33 bits, exceeds 32-bit range)
val1 is then used as the divisor in do_div(val2, val1), where do_div() silently truncates it to 32 bits, producing incorrect results. Use div64_u64() to perform a proper 64-by-64 division.
--- sound/soc/fsl/fsl_easrc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/fsl/fsl_easrc.c +1 -1
@@ -2058,7 +2058,7 @@ static int fsl_easrc_m2m_calc_out_len(st/* right shift 12 bit to make ratio in 32bit space */ val2 = (u64 )in_samples << (frac_bits -12 ); val1 = val1 >>12 ; -do_div (val2, val1); + val2 =div64_u64 (val2, val1); out_samples = val2; out_length = out_samples * out_width * channels;
Greg Kroah-Hartman
maintainerPATCH 226/556 ASoC: fsl_easrc: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 84c5d79aebe6c45e12e3112d14e68972f33c210a upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
The four REG_EASRC_RRL() entries are listed as a block before the four REG_EASRC_RRH() ones, but the two registers of a context alternate in the address map (RRL(n) at 0x110 + 8 * n, RRH(n) at 0x114 + 8 * n). This leaves REG_EASRC_RRL(1), REG_EASRC_RRL(2) and REG_EASRC_RRL(3) unreachable. regcache_reg_needs_sync() then cannot compare them against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort the table by register address.
--- sound/soc/fsl/fsl_easrc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
sound/soc/fsl/fsl_easrc.c +3 -3
@@ -1711,12 +1711,12 @@ static const struct reg_default fsl_easr {REG_EASRC_SFS(2), 0x00000000}, {REG_EASRC_SFS(3), 0x00000000}, {REG_EASRC_RRL(0), 0x00000000}, - {REG_EASRC_RRL(1), 0x00000000}, - {REG_EASRC_RRL(2), 0x00000000}, - {REG_EASRC_RRL(3), 0x00000000}, {REG_EASRC_RRH(0), 0x00000000}, + {REG_EASRC_RRL(1), 0x00000000}, {REG_EASRC_RRH(1), 0x00000000}, + {REG_EASRC_RRL(2), 0x00000000}, {REG_EASRC_RRH(2), 0x00000000}, + {REG_EASRC_RRL(3), 0x00000000}, {REG_EASRC_RRH(3), 0x00000000}, {REG_EASRC_RUC(0), 0x00000000}, {REG_EASRC_RUC(1), 0x00000000},
Greg Kroah-Hartman
maintainerPATCH 227/556 ASoC: hdac_hda: Fix hlink refcount leak on component registration failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
commit 6ad4892c4f5cb437a928a02f5b7d37d496aa9268 upstream.
hdac_hda_dev_probe() gets the HDA link with snd_hdac_ext_bus_link_get() before registering the ASoC component. If component registration fails, the function returns without dropping the link reference.
Always call snd_hdac_ext_bus_link_put() after the registration attempt so the reference taken during probe is balanced on both success and failure.
--- sound/soc/codecs/hdac_hda.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
sound/soc/codecs/hdac_hda.c +1 -3
@@ -642,10 +642,8 @@ static int hdac_hda_dev_probe(struct hda &hdac_hda_codec, hdac_hda_dais, ARRAY_SIZE(hdac_hda_dais)); -if (ret <0 ) { +if (ret <0 )dev_err (&hdev->dev,"%s: failed to register HDA codec %d\n" , __func__, ret); -return ret; - }snd_hdac_ext_bus_link_put (hdev->bus, hlink);
Greg Kroah-Hartman
maintainerPATCH 228/556 AsoC: intel: sst: fix PCI device reference leak on probe failure
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
commit 016f29997ebd29d6ab59c8162ce0e7f73bd1e517 upstream.
intel_sst_probe() takes a reference to the PCI device with pci_dev_get(). If sst_platform_get_resources() fails afterwards, the probe error path cleans up the driver context but does not drop the PCI device reference.
Add a pci_dev_put() error path for failures after pci_dev_get().
--- sound/soc/intel/atom/sst/sst_pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/soc/intel/atom/sst/sst_pci.c +3 -1
@@ -130,13 +130,15 @@ static int intel_sst_probe(struct pci_de sst_drv_ctx->pci =pci_dev_get (pci); ret =sst_platform_get_resources (sst_drv_ctx);if (ret <0 ) - goto do_free_drv_ctx; + goto do_put_pci;pci_set_drvdata (pci, sst_drv_ctx);sst_configure_runtime_pm (sst_drv_ctx);return ret; +do_put_pci: +pci_dev_put (sst_drv_ctx->pci); do_free_drv_ctx:sst_context_cleanup (sst_drv_ctx);dev_err (sst_drv_ctx->dev,"Probe failed with %d\n" , ret);
Greg Kroah-Hartman
maintainerPATCH 229/556 ASoC: loongson: Fix error handling in ACPI property parsing
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Binbin Zhou <[email protected]>
commit 0eb0e3c623ac1da8b85d518043fef7660af7805d upstream.
In loongson_card_parse_acpi(), the return value of device_property_read_string() for the codec-dai-name property was ignored. If the property is missing or invalid, an uninitialized pointer would be used later, potentially leading to undefined behavior.
Fix this by checking the return value and propagating the error appropriately.
--- sound/soc/loongson/loongson_card.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
sound/soc/loongson/loongson_card.c +4 -2
@@ -91,7 +91,7 @@ static int loongson_card_parse_acpi(struconst char *codec_dai_name;struct acpi_device *adev;struct device *phy_dev; -int i; +int i, ret;/* fixup platform name based on reference node */ adev =loongson_card_acpi_find_device (card,"cpu" );
@@ -108,7 +108,9 @@ static int loongson_card_parse_acpi(strureturn -ENOENT ;snprintf (codec_name,sizeof (codec_name),"i2c-%s" ,acpi_dev_name (adev)); -device_property_read_string (card->dev,"codec-dai-name" , &codec_dai_name); + ret =device_property_read_string (card->dev,"codec-dai-name" , &codec_dai_name); +if (ret) +return ret;for (i =0 ; i < card->num_links; i++) { loongson_dai_links[i].platforms->name =dev_name (phy_dev);
Greg Kroah-Hartman
maintainerPATCH 230/556 ASoC: max9860: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 5c4cf173b7eba9bd1e8824b75380412cae2e026b upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
MAX9860_PWRMAN (0x10) is listed as the first entry, before MAX9860_INTEN (0x02), which makes MAX9860_INTEN unreachable. regcache_reg_needs_sync() then cannot compare it against its default and reports that a sync is needed, so it is written to the device on every regcache_sync() even when it was never touched.
Sort the table by register address.
--- sound/soc/codecs/max9860.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/max9860.c +1 -1
@@ -48,7 +48,6 @@ static int max9860_dvddio_event(struct n }static const struct reg_default max9860_reg_defaults[] = { - {MAX9860_PWRMAN ,0x00 }, {MAX9860_INTEN ,0x00 }, {MAX9860_SYSCLK ,0x00 }, {MAX9860_AUDIOCLKHIGH ,0x00 },
@@ -62,6 +61,7 @@ static const struct reg_default max9860_ { MAX9860_MICGAIN, 0x00 }, { MAX9860_MICADC, 0x00 }, { MAX9860_NOISEGATE, 0x00 }, + { MAX9860_PWRMAN, 0x00 }, };static bool max9860_readable (struct device *dev,unsigned int reg)
Greg Kroah-Hartman
maintainerPATCH 231/556 ASoC: ml26124: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit d4d0e6e2355a6fe6517e5a0c3d9a0b8ab073b0b6 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
The Mic Select Control register (0xe8) is listed in the analog path control group, between 0x5a and 0x60, which makes it unreachable. regcache_reg_needs_sync() then cannot compare it against its default and reports that a sync is needed, so it is written to the device on every regcache_sync() even when it was never touched.
Move the entry to the end of the table, where it belongs by address.
--- sound/soc/codecs/ml26124.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
sound/soc/codecs/ml26124.c +3 -1
@@ -224,7 +224,6 @@ static const struct reg_default ml26124_/* Analog Path Control Register */ {0x54, 0x00}, /* Speaker AMP Output Control */ {0x5a, 0x00}, /* Mic IF Control */ - {0xe8, 0x01}, /* Mic Select Control *//* Audio Interface Control Register */ {0x60, 0x00}, /* SAI-Trans Control */
@@ -287,6 +286,9 @@ static const struct reg_default ml26124_ {0xd0, 0x01}, /* VIDEO AMP Gain Control */ {0xd2, 0x01}, /* VIDEO AMP Setup 1 */ {0xd4, 0x01}, /* VIDEO AMP Control2 */ + +/* Analog Path Control Register */ + {0xe8, 0x01}, /* Mic Select Control */ };/* Get sampling rate value of sampling rate setting register (0x0) */
Greg Kroah-Hartman
maintainerPATCH 232/556 ASoC: pcm512x: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 767d9ae714e3e9b0ae86237c410fbfca7056570a upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
PCM512x_AUTO_MUTE (page 0, register 59) is listed before PCM512x_ERROR_DETECT (page 0, register 37) and PCM512x_VCOM_CTRL_2 (page 1, register 9) is listed before the page 0 clocking block, so the bsearch() descends into the wrong half of the table. 24 of the 45 entries are unreachable, among them every PLL coefficient and clock divider default. regcache_reg_needs_sync() then cannot compare them against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort the table by register address.
--- sound/soc/codecs/pcm512x.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-)
sound/soc/codecs/pcm512x.c +20 -20
@@ -78,28 +78,10 @@ static const struct reg_default pcm512x_ { PCM512x_POWER, 0x00 }, { PCM512x_MUTE, 0x00 }, { PCM512x_DSP, 0x00 }, - { PCM512x_PLL_REF, 0x00 }, - { PCM512x_DAC_REF, 0x00 }, - { PCM512x_DAC_ROUTING, 0x11 }, - { PCM512x_DSP_PROGRAM, 0x01 }, - { PCM512x_CLKDET, 0x00 }, - { PCM512x_AUTO_MUTE, 0x00 }, - { PCM512x_ERROR_DETECT, 0x00 }, - { PCM512x_DIGITAL_VOLUME_1, 0x00 }, - { PCM512x_DIGITAL_VOLUME_2, 0x30 }, - { PCM512x_DIGITAL_VOLUME_3, 0x30 }, - { PCM512x_DIGITAL_MUTE_1, 0x22 }, - { PCM512x_DIGITAL_MUTE_2, 0x00 }, - { PCM512x_DIGITAL_MUTE_3, 0x07 }, - { PCM512x_OUTPUT_AMPLITUDE, 0x00 }, - { PCM512x_ANALOG_GAIN_CTRL, 0x00 }, - { PCM512x_UNDERVOLTAGE_PROT, 0x00 }, - { PCM512x_ANALOG_MUTE_CTRL, 0x00 }, - { PCM512x_ANALOG_GAIN_BOOST, 0x00 }, - { PCM512x_VCOM_CTRL_1, 0x00 }, - { PCM512x_VCOM_CTRL_2, 0x01 }, { PCM512x_BCLK_LRCLK_CFG, 0x00 }, { PCM512x_MASTER_MODE, 0x7c }, + { PCM512x_PLL_REF, 0x00 }, + { PCM512x_DAC_REF, 0x00 }, { PCM512x_GPIO_DACIN, 0x00 }, { PCM512x_GPIO_PLLIN, 0x00 }, { PCM512x_SYNCHRONIZE, 0x10 },
@@ -117,8 +99,26 @@ static const struct reg_default pcm512x_ { PCM512x_FS_SPEED_MODE, 0x00 }, { PCM512x_IDAC_1, 0x01 }, { PCM512x_IDAC_2, 0x00 }, + { PCM512x_ERROR_DETECT, 0x00 }, { PCM512x_I2S_1, 0x02 }, { PCM512x_I2S_2, 0x00 }, + { PCM512x_DAC_ROUTING, 0x11 }, + { PCM512x_DSP_PROGRAM, 0x01 }, + { PCM512x_CLKDET, 0x00 }, + { PCM512x_AUTO_MUTE, 0x00 }, + { PCM512x_DIGITAL_VOLUME_1, 0x00 }, + { PCM512x_DIGITAL_VOLUME_2, 0x30 }, + { PCM512x_DIGITAL_VOLUME_3, 0x30 }, + { PCM512x_DIGITAL_MUTE_1, 0x22 }, + { PCM512x_DIGITAL_MUTE_2, 0x00 }, + { PCM512x_DIGITAL_MUTE_3, 0x07 }, + { PCM512x_OUTPUT_AMPLITUDE, 0x00 }, + { PCM512x_ANALOG_GAIN_CTRL, 0x00 }, + { PCM512x_UNDERVOLTAGE_PROT, 0x00 }, + { PCM512x_ANALOG_MUTE_CTRL, 0x00 }, + { PCM512x_ANALOG_GAIN_BOOST, 0x00 }, + { PCM512x_VCOM_CTRL_1, 0x00 }, + { PCM512x_VCOM_CTRL_2, 0x01 }, };static bool pcm512x_readable (struct device *dev,unsigned int reg)
Greg Kroah-Hartman
maintainerPATCH 233/556 ASoC: pm4125-sdw: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 8dd18d9956bfd74531bfd7088e59586e3e115789 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
PM4125_SWR_HPHPA_HD2 (0x3090) is listed before PM4125_ANA_HPHPA_SPARE_CTL (0x308e), which makes the latter unreachable. regcache_reg_needs_sync() then cannot compare it against its default and reports that a sync is needed, so it is written to the device on every regcache_sync() even when it was never touched.
Sort the table by register address.
--- sound/soc/codecs/pm4125-sdw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/pm4125-sdw.c +1 -1
@@ -126,8 +126,8 @@ static const struct reg_default pm4125_d { PM4125_ANA_HPHPA_FSM_CLK, 0x12 }, { PM4125_ANA_HPHPA_L_GAIN, 0x00 }, { PM4125_ANA_HPHPA_R_GAIN, 0x00 }, - { PM4125_SWR_HPHPA_HD2, 0x1B }, { PM4125_ANA_HPHPA_SPARE_CTL, 0x02 }, + { PM4125_SWR_HPHPA_HD2, 0x1B }, { PM4125_ANA_SURGE_EN, 0x38 }, { PM4125_ANA_COMBOPA_CTL, 0x35 }, { PM4125_ANA_COMBOPA_CTL_4, 0x84 },
Greg Kroah-Hartman
maintainerPATCH 234/556 ASoC: rt1017-sdca-sdw: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 5b48ce0356b134155722a61f7196516a7c2e66c5 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
rt1017_sdca_reg_defaults[] places the SDCA controls before the lower vendor registers instead, so the binary search does not find 4 of its entries. regcache_reg_needs_sync() then cannot compare those against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort the table by register address.
--- sound/soc/codecs/rt1017-sdca-sdw.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
sound/soc/codecs/rt1017-sdca-sdw.h +5 -5
@@ -165,19 +165,19 @@ static const struct reg_default rt1017_s { 0xdb09, 0x0f }, { 0xdb0a, 0xff }, { 0xdb14, 0x00 }, - - { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1017_SDCA_ENT_UDMPU21, - RT1017_SDCA_CTL_UDMPU_CLUSTER, 0), 0x00 }, { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1017_SDCA_ENT_FU, RT1017_SDCA_CTL_FU_MUTE, 0x01), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1017_SDCA_ENT_XU22, RT1017_SDCA_CTL_BYPASS, 0), 0x01 }, - { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1017_SDCA_ENT_CS21, - RT1017_SDCA_CTL_FS_INDEX, 0), 0x09 }, { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1017_SDCA_ENT_PDE23, RT1017_SDCA_CTL_REQ_POWER_STATE, 0), 0x03 }, { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1017_SDCA_ENT_PDE22, RT1017_SDCA_CTL_REQ_POWER_STATE, 0), 0x03 }, + + { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1017_SDCA_ENT_UDMPU21, + RT1017_SDCA_CTL_UDMPU_CLUSTER, 0), 0x00 }, + { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1017_SDCA_ENT_CS21, + RT1017_SDCA_CTL_FS_INDEX, 0), 0x09 }, }; #endif /* __RT1017_SDW_H__ */
Greg Kroah-Hartman
maintainerPATCH 235/556 ASoC: rt1316-sdw: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 7b48eccfbb9bf15e9b7377a5296bfd01815c62d8 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
rt1316_reg_defaults[] is not in address order, so the binary search does not find one of its entries. regcache_reg_needs_sync() then cannot compare it against its default and reports that a sync is needed, so it is written to the device on every regcache_sync() even when it was never touched.
Sort the table by register address.
--- sound/soc/codecs/rt1316-sdw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/rt1316-sdw.c +1 -1
@@ -59,13 +59,13 @@ static const struct reg_default rt1316_r { 0xd101, 0x00 }, { 0xd102, 0x30 }, { 0xd103, 0x00 }, - { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1316_SDCA_ENT_UDMPU21, RT1316_SDCA_CTL_UDMPU_CLUSTER, 0), 0x00 }, { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1316_SDCA_ENT_FU21, RT1316_SDCA_CTL_FU_MUTE, CH_L), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1316_SDCA_ENT_FU21, RT1316_SDCA_CTL_FU_MUTE, CH_R), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1316_SDCA_ENT_XU24, RT1316_SDCA_CTL_BYPASS, 0), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1316_SDCA_ENT_PDE23, RT1316_SDCA_CTL_REQ_POWER_STATE, 0), 0x03 }, { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1316_SDCA_ENT_PDE22, RT1316_SDCA_CTL_REQ_POWER_STATE, 0), 0x03 }, { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1316_SDCA_ENT_PDE24, RT1316_SDCA_CTL_REQ_POWER_STATE, 0), 0x03 }, + { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1316_SDCA_ENT_UDMPU21, RT1316_SDCA_CTL_UDMPU_CLUSTER, 0), 0x00 }, }; static const struct reg_sequence rt1316_blind_write[] = {
Greg Kroah-Hartman
maintainerPATCH 236/556 ASoC: rt1318-sdw: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 3673b33633a5daf2f52aff03b57f7b25352fe234 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
rt1318_reg_defaults[] is not in address order, so the binary search does not find 3 of its entries. regcache_reg_needs_sync() then cannot compare those against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort the table by register address.
--- sound/soc/codecs/rt1318-sdw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/rt1318-sdw.c +1 -1
@@ -235,10 +235,10 @@ static const struct reg_default rt1318_r { 0xf805, 0x00 }, { 0xf806, 0x07 }, { 0xf807, 0xff }, - { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1318_SDCA_ENT_UDMPU21, RT1318_SDCA_CTL_UDMPU_CLUSTER, 0), 0x00 }, { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1318_SDCA_ENT_FU21, RT1318_SDCA_CTL_FU_MUTE, CH_L), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1318_SDCA_ENT_FU21, RT1318_SDCA_CTL_FU_MUTE, CH_R), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1318_SDCA_ENT_PDE23, RT1318_SDCA_CTL_REQ_POWER_STATE, 0), 0x03 }, + { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1318_SDCA_ENT_UDMPU21, RT1318_SDCA_CTL_UDMPU_CLUSTER, 0), 0x00 }, { SDW_SDCA_CTL(FUNC_NUM_SMART_AMP, RT1318_SDCA_ENT_CS21, RT1318_SDCA_CTL_SAMPLE_FREQ_INDEX, 0), 0x09 }, };
Greg Kroah-Hartman
maintainerPATCH 237/556 ASoC: rt1318: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 2a8e4b7114f6493314348bda7e3d2141d218ef61 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
The 0xdd93 and 0xdd94 entries are listed after 0xddc8 in rt1318_reg[], which leaves them unreachable for the binary search. regcache_reg_needs_sync() then cannot compare them against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort the table by register address.
--- sound/soc/codecs/rt1318.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
sound/soc/codecs/rt1318.c +2 -2
@@ -337,6 +337,8 @@ static const struct reg_default rt1318_r { 0xdd08, 0x40 }, { 0xdd12, 0x00 }, { 0xdd35, 0x00 }, + { 0xdd93, 0x00 }, + { 0xdd94, 0x64 }, { 0xddb5, 0x00 }, { 0xddb6, 0x40 }, { 0xddb7, 0x00 },
@@ -345,8 +347,6 @@ static const struct reg_default rt1318_r { 0xddc6, 0x00 }, { 0xddc7, 0x00 }, { 0xddc8, 0x00 }, - { 0xdd93, 0x00 }, - { 0xdd94, 0x64 }, { 0xdf00, 0x00 }, { 0xdf5f, 0x00 }, { 0xdf60, 0x00 },
Greg Kroah-Hartman
maintainerPATCH 238/556 ASoC: rt274: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 6a147d177819b0d831831d19fbb9c23f08a03734 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
Four entries were appended to the end of rt274_reg[] instead of being inserted at their sorted position, which leaves 7 of the 33 entries unreachable for the binary search. regcache_reg_needs_sync() then cannot compare them against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort the table by register address.
--- sound/soc/codecs/rt274.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
sound/soc/codecs/rt274.c +4 -4
@@ -184,8 +184,10 @@ static const struct reg_default rt274_re { 0x0023a000, 0x00000057 }, { 0x00270500, 0x00000400 }, { 0x00370500, 0x00000400 }, + { 0x00830000, 0x00000097 }, { 0x00870500, 0x00000400 }, { 0x00920000, 0x00000031 }, + { 0x00930000, 0x00000097 }, { 0x00935000, 0x00000097 }, { 0x00936000, 0x00000097 }, { 0x00970500, 0x00000400 },
@@ -195,10 +197,12 @@ static const struct reg_default rt274_re { 0x00c37000, 0x00000400 }, { 0x00c37100, 0x00000400 }, { 0x01270500, 0x00000400 }, + { 0x01270700, 0x00000000 }, { 0x01370500, 0x00000400 }, { 0x01371f00, 0x411111f0 }, { 0x01937000, 0x00000000 }, { 0x01970500, 0x00000400 }, + { 0x01970700, 0x00000020 }, { 0x02050000, 0x0000001b }, { 0x02139000, 0x00000080 }, { 0x0213a000, 0x00000080 },
@@ -207,10 +211,6 @@ static const struct reg_default rt274_re { 0x02170700, 0x00000000 }, { 0x02270100, 0x00000000 }, { 0x02370100, 0x00000000 }, - { 0x01970700, 0x00000020 }, - { 0x00830000, 0x00000097 }, - { 0x00930000, 0x00000097 }, - { 0x01270700, 0x00000000 }, };static bool rt274_volatile_register (struct device *dev,unsigned int reg)
Greg Kroah-Hartman
maintainerPATCH 239/556 ASoC: rt286: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit c30771968b5355617843a0ddfa0b9dcbcfd3ea84 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
Four entries were appended to the end of rt286_reg[] instead of being inserted at their sorted position and the 0x01470100 entry is listed after 0x01470c00, which leaves 7 of the 39 entries unreachable for the binary search. regcache_reg_needs_sync() then cannot compare them against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort the table by register address.
--- sound/soc/codecs/rt286.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
sound/soc/codecs/rt286.c +6 -6
@@ -77,8 +77,10 @@ static const struct reg_default rt286_re { 0x0023a000, 0x0000007f }, { 0x00270500, 0x00000400 }, { 0x00370500, 0x00000400 }, + { 0x00830000, 0x000000c3 }, { 0x00870500, 0x00000400 }, { 0x00920000, 0x00000031 }, + { 0x00930000, 0x000000c3 }, { 0x00935000, 0x000000c3 }, { 0x00936000, 0x000000c3 }, { 0x00970500, 0x00000400 },
@@ -88,16 +90,18 @@ static const struct reg_default rt286_re { 0x00c37000, 0x00000000 }, { 0x00c37100, 0x00000080 }, { 0x01270500, 0x00000400 }, + { 0x01270700, 0x00000000 }, { 0x01370500, 0x00000400 }, { 0x01371f00, 0x411111f0 }, { 0x01439000, 0x00000080 }, { 0x0143a000, 0x00000080 }, - { 0x01470700, 0x00000000 }, + { 0x01470100, 0x00000000 }, { 0x01470500, 0x00000400 }, + { 0x01470700, 0x00000000 }, { 0x01470c00, 0x00000000 }, - { 0x01470100, 0x00000000 }, { 0x01837000, 0x00000000 }, { 0x01870500, 0x00000400 }, + { 0x01870700, 0x00000020 }, { 0x02050000, 0x00000000 }, { 0x02139000, 0x00000080 }, { 0x0213a000, 0x00000080 },
@@ -106,10 +110,6 @@ static const struct reg_default rt286_re { 0x02170700, 0x00000000 }, { 0x02270100, 0x00000000 }, { 0x02370100, 0x00000000 }, - { 0x01870700, 0x00000020 }, - { 0x00830000, 0x000000c3 }, - { 0x00930000, 0x000000c3 }, - { 0x01270700, 0x00000000 }, };static bool rt286_volatile_register (struct device *dev,unsigned int reg)
Greg Kroah-Hartman
maintainerPATCH 240/556 ASoC: rt298: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit aa4c472b0f4a469c2e4599406fa4cff9de3e02bd upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
Four entries were appended to the end of rt298_reg[] instead of being inserted at their sorted position and the 0x01470100 entry is listed after 0x01470c00, which leaves 7 of the 39 entries unreachable for the binary search. regcache_reg_needs_sync() then cannot compare them against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort the table by register address.
--- sound/soc/codecs/rt298.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
sound/soc/codecs/rt298.c +6 -6
@@ -78,8 +78,10 @@ static const struct reg_default rt298_re { 0x0023a000, 0x0000007f }, { 0x00270500, 0x00000400 }, { 0x00370500, 0x00000400 }, + { 0x00830000, 0x000000c3 }, { 0x00870500, 0x00000400 }, { 0x00920000, 0x00000031 }, + { 0x00930000, 0x000000c3 }, { 0x00935000, 0x000000c3 }, { 0x00936000, 0x000000c3 }, { 0x00970500, 0x00000400 },
@@ -89,16 +91,18 @@ static const struct reg_default rt298_re { 0x00c37000, 0x00000000 }, { 0x00c37100, 0x00000080 }, { 0x01270500, 0x00000400 }, + { 0x01270700, 0x00000000 }, { 0x01370500, 0x00000400 }, { 0x01371f00, 0x411111f0 }, { 0x01439000, 0x00000080 }, { 0x0143a000, 0x00000080 }, - { 0x01470700, 0x00000000 }, + { 0x01470100, 0x00000000 }, { 0x01470500, 0x00000400 }, + { 0x01470700, 0x00000000 }, { 0x01470c00, 0x00000000 }, - { 0x01470100, 0x00000000 }, { 0x01837000, 0x00000000 }, { 0x01870500, 0x00000400 }, + { 0x01870700, 0x00000020 }, { 0x02050000, 0x00000000 }, { 0x02139000, 0x00000080 }, { 0x0213a000, 0x00000080 },
@@ -107,10 +111,6 @@ static const struct reg_default rt298_re { 0x02170700, 0x00000000 }, { 0x02270100, 0x00000000 }, { 0x02370100, 0x00000000 }, - { 0x01870700, 0x00000020 }, - { 0x00830000, 0x000000c3 }, - { 0x00930000, 0x000000c3 }, - { 0x01270700, 0x00000000 }, };static bool rt298_volatile_register (struct device *dev,unsigned int reg)
Greg Kroah-Hartman
maintainerPATCH 241/556 ASoC: rt700: drop duplicate reg_default entry
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 90ad6a29809dc53e8c1af23fc51bafe2133da035 upstream.
rt700_reg_defaults[] lists register 0x7303 twice with the same value. The identical rt711 table has the entry only once, so this is a copy-paste error.
Drop the duplicate. No functional change, regcache_lookup_reg() only ever finds one of the two entries.
--- sound/soc/codecs/rt700-sdw.h | 1 - 1 file changed, 1 deletion(-)
sound/soc/codecs/rt700-sdw.h +0 -1
@@ -313,7 +313,6 @@ static const struct reg_default rt700_re { 0x3122, 0x0000 }, { 0x3123, 0x0000 }, { 0x7303, 0x0057 }, - { 0x7303, 0x0057 }, { 0x8383, 0x0057 }, { 0x7308, 0x0097 }, { 0x8388, 0x0097 },
Greg Kroah-Hartman
maintainerPATCH 242/556 ASoC: rt700: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 18f21e34493b812d9c8ab9f083871470b016bed4 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
At the end of rt700_reg_defaults[] the 0x83xx entries are interleaved with the 0x73xx entries they belong to, which leaves 6 of the entries unreachable for the binary search. regcache_reg_needs_sync() then cannot compare them against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort the table by register address.
--- sound/soc/codecs/rt700-sdw.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
sound/soc/codecs/rt700-sdw.h +5 -5
@@ -313,16 +313,16 @@ static const struct reg_default rt700_re { 0x3122, 0x0000 }, { 0x3123, 0x0000 }, { 0x7303, 0x0057 }, - { 0x8383, 0x0057 }, { 0x7308, 0x0097 }, - { 0x8388, 0x0097 }, { 0x7309, 0x0097 }, - { 0x8389, 0x0097 }, { 0x7312, 0x0000 }, - { 0x8392, 0x0000 }, { 0x7313, 0x0000 }, - { 0x8393, 0x0000 }, { 0x7319, 0x0000 }, + { 0x8383, 0x0057 }, + { 0x8388, 0x0097 }, + { 0x8389, 0x0097 }, + { 0x8392, 0x0000 }, + { 0x8393, 0x0000 }, { 0x8399, 0x0000 }, { 0x75201a, 0x8003 }, { 0x752045, 0x5289 },
Greg Kroah-Hartman
maintainerPATCH 243/556 ASoC: rt711-sdca: sort the register default tables
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit b8fdd467bb5d2eb89b665331065e9e3ade964a3e upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
Both tables group the entries by SDCA entity instead: in rt711_sdca_reg_defaults[] the CS01 sample frequency index is listed before the FU05 controls (1 of 54 entries unreachable), and in rt711_sdca_mbq_defaults[] the MIC_ARRAY FU1E volumes are listed before the JACK_CODEC FU0F volumes (2 of 25 entries unreachable). regcache_reg_needs_sync() then cannot compare those against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort both tables by register address.
--- sound/soc/codecs/rt711-sdca-sdw.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
sound/soc/codecs/rt711-sdca-sdw.h +3 -3
@@ -58,12 +58,12 @@ static const struct reg_default rt711_sd { 0x2f0f, 0x00 }, { 0x2f50, 0x03 }, { 0x2f5a, 0x00 }, - { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT711_SDCA_ENT_CS01, RT711_SDCA_CTL_SAMPLE_FREQ_INDEX, 0), 0x09 }, { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT711_SDCA_ENT_USER_FU05, RT711_SDCA_CTL_FU_MUTE, CH_L), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT711_SDCA_ENT_USER_FU05, RT711_SDCA_CTL_FU_MUTE, CH_R), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT711_SDCA_ENT_USER_FU0F, RT711_SDCA_CTL_FU_MUTE, CH_L), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT711_SDCA_ENT_USER_FU0F, RT711_SDCA_CTL_FU_MUTE, CH_R), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT711_SDCA_ENT_PDE28, RT711_SDCA_CTL_REQ_POWER_STATE, 0), 0x03 }, + { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT711_SDCA_ENT_CS01, RT711_SDCA_CTL_SAMPLE_FREQ_INDEX, 0), 0x09 }, { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT711_SDCA_ENT_USER_FU1E, RT711_SDCA_CTL_FU_MUTE, CH_L), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT711_SDCA_ENT_USER_FU1E, RT711_SDCA_CTL_FU_MUTE, CH_R), 0x01 }, };
@@ -86,14 +86,14 @@ static const struct reg_default rt711_sd { 0x610003f, 0xff12 }, { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT711_SDCA_ENT_USER_FU05, RT711_SDCA_CTL_FU_VOLUME, CH_L), 0x00 }, { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT711_SDCA_ENT_USER_FU05, RT711_SDCA_CTL_FU_VOLUME, CH_R), 0x00 }, - { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT711_SDCA_ENT_USER_FU1E, RT711_SDCA_CTL_FU_VOLUME, CH_L), 0x00 }, - { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT711_SDCA_ENT_USER_FU1E, RT711_SDCA_CTL_FU_VOLUME, CH_R), 0x00 }, { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT711_SDCA_ENT_USER_FU0F, RT711_SDCA_CTL_FU_VOLUME, CH_L), 0x00 }, { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT711_SDCA_ENT_USER_FU0F, RT711_SDCA_CTL_FU_VOLUME, CH_R), 0x00 }, { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT711_SDCA_ENT_PLATFORM_FU44, RT711_SDCA_CTL_FU_CH_GAIN, CH_L), 0x00 }, { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT711_SDCA_ENT_PLATFORM_FU44, RT711_SDCA_CTL_FU_CH_GAIN, CH_R), 0x00 }, { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT711_SDCA_ENT_PLATFORM_FU15, RT711_SDCA_CTL_FU_CH_GAIN, CH_L), 0x00 }, { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT711_SDCA_ENT_PLATFORM_FU15, RT711_SDCA_CTL_FU_CH_GAIN, CH_R), 0x00 }, + { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT711_SDCA_ENT_USER_FU1E, RT711_SDCA_CTL_FU_VOLUME, CH_L), 0x00 }, + { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT711_SDCA_ENT_USER_FU1E, RT711_SDCA_CTL_FU_VOLUME, CH_R), 0x00 }, }; #endif /* __RT711_SDW_SDCA_H__ */
Greg Kroah-Hartman
maintainerPATCH 244/556 ASoC: rt711: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 55fe63530772fe95a99abe9497872975f3161a56 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
At the end of rt711_reg_defaults[] the 0x83xx entries are interleaved with the 0x73xx entries they belong to, which leaves 5 of the 269 entries unreachable for the binary search. regcache_reg_needs_sync() then cannot compare them against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort the table by register address.
--- sound/soc/codecs/rt711-sdw.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
sound/soc/codecs/rt711-sdw.h +5 -5
@@ -256,16 +256,16 @@ static const struct reg_default rt711_re { 0x3122, 0x00 }, { 0x3123, 0x00 }, { 0x7303, 0x57 }, - { 0x8383, 0x57 }, { 0x7308, 0x97 }, - { 0x8388, 0x97 }, { 0x7309, 0x97 }, - { 0x8389, 0x97 }, { 0x7312, 0x00 }, - { 0x8392, 0x00 }, { 0x7313, 0x00 }, - { 0x8393, 0x00 }, { 0x7319, 0x00 }, + { 0x8383, 0x57 }, + { 0x8388, 0x97 }, + { 0x8389, 0x97 }, + { 0x8392, 0x00 }, + { 0x8393, 0x00 }, { 0x8399, 0x00 }, { 0x752008, 0xa807 }, { 0x752009, 0x1029 },
Greg Kroah-Hartman
maintainerPATCH 245/556 ASoC: rt712-sdca-dmic: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit b9339ee3fccc79e751a2f7bde42c5dd57b38b2a9 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
rt712_sdca_dmic_reg_defaults[] is grouped by SDCA entity instead, so the binary search does not find 3 of its entries. regcache_reg_needs_sync() then cannot compare those against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort the table by register address.
--- sound/soc/codecs/rt712-sdca-dmic.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
sound/soc/codecs/rt712-sdca-dmic.h +4 -2
@@ -36,6 +36,7 @@ struct rt712_sdca_dmic_kctrl_priv {#define CH_03 0x03#define CH_04 0x04 +/* must stay sorted by register address, regcache_lookup_reg() does a bsearch() */ static const struct reg_default rt712_sdca_dmic_reg_defaults[] = { {0x201a ,0x00 }, {0x201b ,0x00 },
@@ -72,15 +73,16 @@ static const struct reg_default rt712_sd { 0x2f59, 0x07 }, { 0x3201, 0x01 }, { 0x320c, 0x00 }, - { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT712_SDCA_ENT_IT26, RT712_SDCA_CTL_VENDOR_DEF, 0), 0x00 }, { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT712_SDCA_ENT_USER_FU1E, RT712_SDCA_CTL_FU_MUTE, CH_01), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT712_SDCA_ENT_USER_FU1E, RT712_SDCA_CTL_FU_MUTE, CH_02), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT712_SDCA_ENT_USER_FU1E, RT712_SDCA_CTL_FU_MUTE, CH_03), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT712_SDCA_ENT_USER_FU1E, RT712_SDCA_CTL_FU_MUTE, CH_04), 0x01 }, - { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT712_SDCA_ENT_CS1F, RT712_SDCA_CTL_SAMPLE_FREQ_INDEX, 0), 0x09 }, { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT712_SDCA_ENT_CS1C, RT712_SDCA_CTL_SAMPLE_FREQ_INDEX, 0), 0x09 }, + { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT712_SDCA_ENT_CS1F, RT712_SDCA_CTL_SAMPLE_FREQ_INDEX, 0), 0x09 }, + { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT712_SDCA_ENT_IT26, RT712_SDCA_CTL_VENDOR_DEF, 0), 0x00 }, }; +/* must stay sorted by register address, regcache_lookup_reg() does a bsearch() */ static const struct reg_default rt712_sdca_dmic_mbq_defaults[] = { {0x0590001e ,0x0020 }, { 0x06100000, 0x0010 },
Greg Kroah-Hartman
maintainerPATCH 246/556 ASoC: rt712-sdca-sdw: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit efd430c4d0426e60fbec400c5a8ce62d886f6e21 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
rt712_sdca_reg_defaults[] is grouped by SDCA function instead, so the binary search does not find 4 of its entries. regcache_reg_needs_sync() then cannot compare those against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
One of them is the Mic Array Clock Source 0x1C Sample Frequency Index control, which a part without that function rejects:
soundwire_intel.link.0: Msg ignored for Slave 6, addr: 0x8e00
Sort the table by register address.
--- sound/soc/codecs/rt712-sdca-sdw.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
sound/soc/codecs/rt712-sdca-sdw.h +6 -5
@@ -11,21 +11,21 @@#include <linux/regmap.h> #include <linux/soundwire/sdw_registers.h> +/* must stay sorted by register address, regcache_lookup_reg() does a bsearch() */ static const struct reg_default rt712_sdca_reg_defaults[] = { - - {SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT712_SDCA_ENT_CS01 ,RT712_SDCA_CTL_SAMPLE_FREQ_INDEX ,0 ),0x09 }, - {SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT712_SDCA_ENT_CS11 ,RT712_SDCA_CTL_SAMPLE_FREQ_INDEX ,0 ),0x09 }, {SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT712_SDCA_ENT_USER_FU05 ,RT712_SDCA_CTL_FU_MUTE ,CH_01 ),0x01 }, {SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT712_SDCA_ENT_USER_FU05 ,RT712_SDCA_CTL_FU_MUTE ,CH_02 ),0x01 }, {SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT712_SDCA_ENT_USER_FU0F ,RT712_SDCA_CTL_FU_MUTE ,CH_01 ),0x01 }, {SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT712_SDCA_ENT_USER_FU0F ,RT712_SDCA_CTL_FU_MUTE ,CH_02 ),0x01 }, - {SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT712_SDCA_ENT_PDE40 ,RT712_SDCA_CTL_REQ_POWER_STATE ,0 ),0x03 }, {SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT712_SDCA_ENT_PDE12 ,RT712_SDCA_CTL_REQ_POWER_STATE ,0 ),0x03 }, - {SDW_SDCA_CTL (FUNC_NUM_MIC_ARRAY ,RT712_SDCA_ENT_CS1C ,RT712_SDCA_CTL_SAMPLE_FREQ_INDEX ,0 ),0x09 }, + {SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT712_SDCA_ENT_CS01 ,RT712_SDCA_CTL_SAMPLE_FREQ_INDEX ,0 ),0x09 }, + {SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT712_SDCA_ENT_CS11 ,RT712_SDCA_CTL_SAMPLE_FREQ_INDEX ,0 ),0x09 }, + {SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT712_SDCA_ENT_PDE40 ,RT712_SDCA_CTL_REQ_POWER_STATE ,0 ),0x03 }, {SDW_SDCA_CTL (FUNC_NUM_MIC_ARRAY ,RT712_SDCA_ENT_USER_FU1E ,RT712_SDCA_CTL_FU_MUTE ,CH_01 ),0x01 }, {SDW_SDCA_CTL (FUNC_NUM_MIC_ARRAY ,RT712_SDCA_ENT_USER_FU1E ,RT712_SDCA_CTL_FU_MUTE ,CH_02 ),0x01 }, {SDW_SDCA_CTL (FUNC_NUM_MIC_ARRAY ,RT712_SDCA_ENT_USER_FU1E ,RT712_SDCA_CTL_FU_MUTE ,CH_03 ),0x01 }, {SDW_SDCA_CTL (FUNC_NUM_MIC_ARRAY ,RT712_SDCA_ENT_USER_FU1E ,RT712_SDCA_CTL_FU_MUTE ,CH_04 ),0x01 }, + {SDW_SDCA_CTL (FUNC_NUM_MIC_ARRAY ,RT712_SDCA_ENT_CS1C ,RT712_SDCA_CTL_SAMPLE_FREQ_INDEX ,0 ),0x09 }, {SDW_SDCA_CTL (FUNC_NUM_MIC_ARRAY ,RT712_SDCA_ENT_CS1F ,RT712_SDCA_CTL_SAMPLE_FREQ_INDEX ,0 ),0x09 }, {SDW_SDCA_CTL (FUNC_NUM_AMP ,RT712_SDCA_ENT_USER_FU06 ,RT712_SDCA_CTL_FU_MUTE ,CH_01 ),0x01 }, {SDW_SDCA_CTL (FUNC_NUM_AMP ,RT712_SDCA_ENT_USER_FU06 ,RT712_SDCA_CTL_FU_MUTE ,CH_02 ),0x01 },
@@ -34,6 +34,7 @@ static const struct reg_default rt712_sd { SDW_SDCA_CTL(FUNC_NUM_AMP, RT712_SDCA_ENT_OT23, RT712_SDCA_CTL_VENDOR_DEF, 0), 0x00 }, }; +/* must stay sorted by register address, regcache_lookup_reg() does a bsearch() */ static const struct reg_default rt712_sdca_mbq_defaults[] = { {0x2000004 ,0xaa01 }, { 0x200000e, 0x21e0 },
Greg Kroah-Hartman
maintainerPATCH 247/556 ASoC: rt715-sdca: drop duplicate reg_default entries
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit c9875bba469c19ad7f771b91b1e4c6f1c0f0a07d upstream.
The last two entries of rt715_reg_defaults_sdca[] repeat the ADC7_27 volume mute controls for CH_01 and CH_02, which are already listed a few lines above with the same value.
Drop the duplicates. No functional change, regcache_lookup_reg() only ever finds one of the two copies.
--- sound/soc/codecs/rt715-sdca-sdw.h | 4 ---- 1 file changed, 4 deletions(-)
sound/soc/codecs/rt715-sdca-sdw.h +0 -4
@@ -102,10 +102,6 @@ static const struct reg_default rt715_re RT715_SDCA_SMPU_TRIG_EN_CTRL, CH_00), 0x02 }, { SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_SMPU_TRIG_ST_EN, RT715_SDCA_SMPU_TRIG_ST_CTRL, CH_00), 0x00 }, - { SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_FU_ADC7_27_VOL, - RT715_SDCA_FU_MUTE_CTRL, CH_01), 0x01 }, - { SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_FU_ADC7_27_VOL, - RT715_SDCA_FU_MUTE_CTRL, CH_02), 0x01 }, };static const struct reg_default rt715_mbq_reg_defaults_sdca[] = {
Greg Kroah-Hartman
maintainerPATCH 248/556 ASoC: rt715-sdca: sort the register default tables
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 61a0321e4bc2ff9ecb38cda7d5a32ffacef71a75 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
Both tables group the entries by SDCA entity instead: in rt715_reg_defaults_sdca[] the CX_CLK_SEL control is listed before the ADC8_9, ADC10_11 and ADC7_27 mute controls (7 of 78 entries unreachable), and in rt715_mbq_reg_defaults_sdca[] the AMIC_GAIN_EN CH_08 entry is listed before the DMIC_GAIN_EN entries (1 of 32 entries unreachable). regcache_reg_needs_sync() then cannot compare those against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort both tables by register address.
--- sound/soc/codecs/rt715-sdca-sdw.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
sound/soc/codecs/rt715-sdca-sdw.h +4 -4
@@ -76,8 +76,6 @@ static const struct reg_default rt715_re { 0x2f52, 0x01 }, { 0x2f5a, 0x02 }, { 0x2f5b, 0x05 }, - { SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_CX_CLK_SEL_EN, - RT715_SDCA_CX_CLK_SEL_CTRL, CH_00), 0x1 }, { SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_FU_ADC8_9_VOL, RT715_SDCA_FU_MUTE_CTRL, CH_01), 0x01 }, { SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_FU_ADC8_9_VOL,
@@ -98,6 +96,8 @@ static const struct reg_default rt715_re RT715_SDCA_FU_MUTE_CTRL, CH_01), 0x01 }, {SDW_SDCA_CTL (FUN_MIC_ARRAY ,RT715_SDCA_FU_ADC7_27_VOL , RT715_SDCA_FU_MUTE_CTRL, CH_02), 0x01 }, + { SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_CX_CLK_SEL_EN, + RT715_SDCA_CX_CLK_SEL_CTRL, CH_00), 0x1 }, { SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_SMPU_TRIG_ST_EN, RT715_SDCA_SMPU_TRIG_EN_CTRL, CH_00), 0x02 }, { SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_SMPU_TRIG_ST_EN,
@@ -145,8 +145,6 @@ static const struct reg_default rt715_mb RT715_SDCA_FU_DMIC_GAIN_CTRL, CH_06), 0x00 }, {SDW_SDCA_CTL (FUN_MIC_ARRAY ,RT715_SDCA_FU_AMIC_GAIN_EN , RT715_SDCA_FU_DMIC_GAIN_CTRL, CH_07), 0x00 }, - { SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_FU_AMIC_GAIN_EN, - RT715_SDCA_FU_DMIC_GAIN_CTRL, CH_08), 0x00 }, { SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_FU_DMIC_GAIN_EN, RT715_SDCA_FU_DMIC_GAIN_CTRL, CH_01), 0x00 }, { SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_FU_DMIC_GAIN_EN,
@@ -161,6 +159,8 @@ static const struct reg_default rt715_mb RT715_SDCA_FU_DMIC_GAIN_CTRL, CH_06), 0x00 }, { SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_FU_DMIC_GAIN_EN, RT715_SDCA_FU_DMIC_GAIN_CTRL, CH_07), 0x00 }, + { SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_FU_AMIC_GAIN_EN, + RT715_SDCA_FU_DMIC_GAIN_CTRL, CH_08), 0x00 }, { SDW_SDCA_CTL(FUN_MIC_ARRAY, RT715_SDCA_FU_DMIC_GAIN_EN, RT715_SDCA_FU_DMIC_GAIN_CTRL, CH_08), 0x00 }, };
Greg Kroah-Hartman
maintainerPATCH 249/556 ASoC: rt715: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit d729804a92dc4e74b8fb69da162f74660ea64385 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
At the end of rt715_reg_defaults[] the 0x82xx and 0x83xx entries are interleaved with the 0x72xx and 0x73xx entries they belong to, and 0x385e is listed before 0x3859. This leaves 25 of the 323 entries unreachable for the binary search. regcache_reg_needs_sync() then cannot compare them against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort the table by register address.
--- sound/soc/codecs/rt715-sdw.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
sound/soc/codecs/rt715-sdw.h +16 -16
@@ -281,8 +281,8 @@ static const struct reg_default rt715_re { 0x371b, 0x00 }, { 0x371d, 0x00 }, { 0x3729, 0x00 }, - { 0x385e, 0x00 }, { 0x3859, 0x00 }, + { 0x385e, 0x00 }, { 0x4c12, 0x411111f0 }, { 0x4c13, 0x411111f0 }, { 0x4c1d, 0x411111f0 },
@@ -300,36 +300,36 @@ static const struct reg_default rt715_re { 0x4f1d, 0x411111f0 }, { 0x4f29, 0x411111f0 }, { 0x7207, 0x00 }, - { 0x8287, 0x00 }, { 0x7208, 0x00 }, - { 0x8288, 0x00 }, { 0x7209, 0x00 }, - { 0x8289, 0x00 }, { 0x7227, 0x00 }, - { 0x82a7, 0x00 }, { 0x7307, 0x97 }, - { 0x8387, 0x97 }, { 0x7308, 0x97 }, - { 0x8388, 0x97 }, { 0x7309, 0x97 }, - { 0x8389, 0x97 }, { 0x7312, 0x00 }, - { 0x8392, 0x00 }, { 0x7313, 0x00 }, - { 0x8393, 0x00 }, { 0x7318, 0x00 }, - { 0x8398, 0x00 }, { 0x7319, 0x00 }, - { 0x8399, 0x00 }, { 0x731a, 0x00 }, - { 0x839a, 0x00 }, { 0x731b, 0x00 }, - { 0x839b, 0x00 }, { 0x731d, 0x00 }, - { 0x839d, 0x00 }, { 0x7327, 0x97 }, - { 0x83a7, 0x97 }, { 0x7329, 0x00 }, + { 0x8287, 0x00 }, + { 0x8288, 0x00 }, + { 0x8289, 0x00 }, + { 0x82a7, 0x00 }, + { 0x8387, 0x97 }, + { 0x8388, 0x97 }, + { 0x8389, 0x97 }, + { 0x8392, 0x00 }, + { 0x8393, 0x00 }, + { 0x8398, 0x00 }, + { 0x8399, 0x00 }, + { 0x839a, 0x00 }, + { 0x839b, 0x00 }, + { 0x839d, 0x00 }, + { 0x83a7, 0x97 }, { 0x83a9, 0x00 }, { 0x752039, 0xa500 }, };
Greg Kroah-Hartman
maintainerPATCH 250/556 ASoC: rt721-sdca-sdw: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 70e0481c196e4822e683bca384e6bda89d944839 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
rt721_sdca_reg_defaults[] is grouped by SDCA function instead, so the binary search does not find 12 of its entries. regcache_reg_needs_sync() then cannot compare those against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort the table by register address.
--- sound/soc/codecs/rt721-sdca-sdw.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
sound/soc/codecs/rt721-sdca-sdw.h +14 -14
@@ -29,14 +29,6 @@ static const struct reg_default rt721_sd { 0x2f5b, 0x07 }, { 0x2f5c, 0x27 }, { 0x2f5d, 0x07 }, - { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT721_SDCA_ENT_CS01, - RT721_SDCA_CTL_SAMPLE_FREQ_INDEX, 0), 0x09 }, - { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT721_SDCA_ENT_CS11, - RT721_SDCA_CTL_SAMPLE_FREQ_INDEX, 0), 0x09 }, - { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT721_SDCA_ENT_PDE12, - RT721_SDCA_CTL_REQ_POWER_STATE, 0), 0x03 }, - { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT721_SDCA_ENT_PDE40, - RT721_SDCA_CTL_REQ_POWER_STATE, 0), 0x03 }, { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT721_SDCA_ENT_USER_FU05, RT721_SDCA_CTL_FU_MUTE, CH_L), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT721_SDCA_ENT_USER_FU05,
@@ -45,6 +37,14 @@ static const struct reg_default rt721_sd RT721_SDCA_CTL_FU_MUTE, CH_L), 0x01 }, {SDW_SDCA_CTL (FUNC_NUM_JACK_CODEC ,RT721_SDCA_ENT_USER_FU0F , RT721_SDCA_CTL_FU_MUTE, CH_R), 0x01 }, + { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT721_SDCA_ENT_PDE12, + RT721_SDCA_CTL_REQ_POWER_STATE, 0), 0x03 }, + { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT721_SDCA_ENT_CS01, + RT721_SDCA_CTL_SAMPLE_FREQ_INDEX, 0), 0x09 }, + { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT721_SDCA_ENT_CS11, + RT721_SDCA_CTL_SAMPLE_FREQ_INDEX, 0), 0x09 }, + { SDW_SDCA_CTL(FUNC_NUM_JACK_CODEC, RT721_SDCA_ENT_PDE40, + RT721_SDCA_CTL_REQ_POWER_STATE, 0), 0x03 }, { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT721_SDCA_ENT_USER_FU1E, RT721_SDCA_CTL_FU_MUTE, CH_01), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT721_SDCA_ENT_USER_FU1E,
@@ -53,30 +53,30 @@ static const struct reg_default rt721_sd RT721_SDCA_CTL_FU_MUTE, CH_03), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT721_SDCA_ENT_USER_FU1E, RT721_SDCA_CTL_FU_MUTE, CH_04), 0x01 }, + { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT721_SDCA_ENT_PDE2A, + RT721_SDCA_CTL_REQ_POWER_STATE, 0), 0x03 }, { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT721_SDCA_ENT_CS1F, RT721_SDCA_CTL_SAMPLE_FREQ_INDEX, 0), 0x09 }, { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT721_SDCA_ENT_IT26, RT721_SDCA_CTL_VENDOR_DEF, 0), 0x00 }, - { SDW_SDCA_CTL(FUNC_NUM_MIC_ARRAY, RT721_SDCA_ENT_PDE2A, - RT721_SDCA_CTL_REQ_POWER_STATE, 0), 0x03 }, - { SDW_SDCA_CTL(FUNC_NUM_AMP, RT721_SDCA_ENT_CS31, - RT721_SDCA_CTL_SAMPLE_FREQ_INDEX, 0), 0x09 }, { SDW_SDCA_CTL(FUNC_NUM_AMP, RT721_SDCA_ENT_USER_FU06, RT721_SDCA_CTL_FU_MUTE, CH_L), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_AMP, RT721_SDCA_ENT_USER_FU06, RT721_SDCA_CTL_FU_MUTE, CH_R), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_AMP, RT721_SDCA_ENT_PDE23, RT721_SDCA_CTL_REQ_POWER_STATE, 0), 0x03 }, - { SDW_SDCA_CTL(FUNC_NUM_AMP, RT721_SDCA_ENT_OT23, - RT721_SDCA_CTL_VENDOR_DEF, 0), 0x00 }, { SDW_SDCA_CTL(FUNC_NUM_AMP, RT721_SDCA_ENT_PDE23, RT721_SDCA_CTL_FU_MUTE, CH_01), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_AMP, RT721_SDCA_ENT_PDE23, RT721_SDCA_CTL_FU_MUTE, CH_02), 0x01 }, + { SDW_SDCA_CTL(FUNC_NUM_AMP, RT721_SDCA_ENT_CS31, + RT721_SDCA_CTL_SAMPLE_FREQ_INDEX, 0), 0x09 }, { SDW_SDCA_CTL(FUNC_NUM_AMP, RT721_SDCA_ENT_FU55, RT721_SDCA_CTL_FU_MUTE, CH_01), 0x01 }, { SDW_SDCA_CTL(FUNC_NUM_AMP, RT721_SDCA_ENT_FU55, RT721_SDCA_CTL_FU_MUTE, CH_02), 0x01 }, + { SDW_SDCA_CTL(FUNC_NUM_AMP, RT721_SDCA_ENT_OT23, + RT721_SDCA_CTL_VENDOR_DEF, 0), 0x00 }, };static const struct reg_default rt721_sdca_mbq_defaults[] = {
Greg Kroah-Hartman
maintainerPATCH 251/556 ASoC: samsung: aries_audio_probe: double of_node_put due to direct assignment without of_node_get
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: WenTao Liang <[email protected]>
commit fb5d1b1c5f8a920ee697545fa6dee16825085717 upstream.
In aries_audio_probe(), aries_dai[0].platforms->of_node is assigned the same pointer as aries_dai[0].cpus->of_node (from of_parse_phandle) without calling of_node_get(). When the sound card is deregistered, the ASoC framework calls of_node_put() on both cpus->of_node and platforms->of_node, causing a double put on the same node and a refcount underflow.
Add of_node_get(aries_dai[0].cpus->of_node) before the assignment.
--- sound/soc/samsung/aries_wm8994.c | 1 + 1 file changed, 1 insertion(+)
sound/soc/samsung/aries_wm8994.c +1 -0
@@ -658,6 +658,7 @@ static int aries_audio_probe(struct plat goto out; } +of_node_get (aries_dai[0 ].cpus->of_node); aries_dai[0 ].platforms->of_node = aries_dai[0 ].cpus->of_node;/* Set CPU of_node for BT DAI */
Greg Kroah-Hartman
maintainerPATCH 252/556 ASoC: sgtl5000: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 437fbdeb60693b8f2e8250d44d29e513a95df298 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
SGTL5000_CHIP_SHORT_CTRL (0x003c) is listed before SGTL5000_CHIP_ANA_TEST2 (0x003a), which makes the former unreachable. regcache_reg_needs_sync() then cannot compare it against its default and reports that a sync is needed, so it is written to the device on every regcache_sync() even when it was never touched.
Sort the table by register address.
--- sound/soc/codecs/sgtl5000.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/sgtl5000.c +1 -1
@@ -56,8 +56,8 @@ static const struct reg_default sgtl5000 { SGTL5000_CHIP_PLL_CTRL, 0x5000 }, { SGTL5000_CHIP_CLK_TOP_CTRL, 0x0000 }, { SGTL5000_CHIP_ANA_STATUS, 0x0000 }, - { SGTL5000_CHIP_SHORT_CTRL, 0x0000 }, { SGTL5000_CHIP_ANA_TEST2, 0x0000 }, + { SGTL5000_CHIP_SHORT_CTRL, 0x0000 }, { SGTL5000_DAP_CTRL, 0x0000 }, { SGTL5000_DAP_PEQ, 0x0000 }, { SGTL5000_DAP_BASS_ENHANCE, 0x0040 },
Greg Kroah-Hartman
maintainerPATCH 253/556 ASoC: sti-sas: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit bbd73fb224caa1badfe2aa338fe9c9dcf40a6e96 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
STIH407_AUDIO_DAC_CTRL (0xa8) is listed before STIH407_AUDIO_GLUE_CTRL (0xa4), which makes the latter unreachable. regcache_reg_needs_sync() then cannot compare it against its default and reports that a sync is needed, so it is written to the device on every regcache_sync() even when it was never touched.
Sort the table by register address.
--- sound/soc/codecs/sti-sas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/sti-sas.c +1 -1
@@ -44,8 +44,8 @@ enum { };static const struct reg_default stih407_sas_reg_defaults[] = { - {STIH407_AUDIO_DAC_CTRL ,0x000000000 }, {STIH407_AUDIO_GLUE_CTRL ,0x00000040 }, + {STIH407_AUDIO_DAC_CTRL ,0x000000000 }, };struct sti_dac_audio {
Greg Kroah-Hartman
maintainerPATCH 254/556 ASoC: tas2552: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit 1cc0cb62d306bb7c42e3d4649863df7c279ac850 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
TAS2552_OUTPUT_DATA (0x07), TAS2552_PDM_CFG (0x11), TAS2552_PGA_GAIN (0x12) and TAS2552_BOOST_APT_CTRL (0x14) are listed before TAS2552_RESERVED_0D (0x0d), TAS2552_LIMIT_RATE_HYS (0x0e) and TAS2552_CFG_2 (0x02), which leaves 7 of the 21 entries unreachable. regcache_reg_needs_sync() then cannot compare them against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort the table by register address.
--- sound/soc/codecs/tas2552.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
sound/soc/codecs/tas2552.c +7 -7
@@ -31,25 +31,25 @@static const struct reg_default tas2552_reg_defs[] = { {TAS2552_CFG_1 ,0x22 }, + {TAS2552_CFG_2 ,0xef }, {TAS2552_CFG_3 ,0x80 }, {TAS2552_DOUT ,0x00 }, - {TAS2552_OUTPUT_DATA ,0xc0 }, - {TAS2552_PDM_CFG ,0x01 }, - {TAS2552_PGA_GAIN ,0x00 }, - {TAS2552_BOOST_APT_CTRL ,0x0f }, - {TAS2552_RESERVED_0D ,0xbe }, - {TAS2552_LIMIT_RATE_HYS ,0x08 }, - {TAS2552_CFG_2 ,0xef }, {TAS2552_SER_CTRL_1 ,0x00 }, {TAS2552_SER_CTRL_2 ,0x00 }, + {TAS2552_OUTPUT_DATA ,0xc0 }, {TAS2552_PLL_CTRL_1 ,0x10 }, {TAS2552_PLL_CTRL_2 ,0x00 }, {TAS2552_PLL_CTRL_3 ,0x00 }, {TAS2552_BTIP ,0x8f }, {TAS2552_BTS_CTRL ,0x80 }, + {TAS2552_RESERVED_0D ,0xbe }, + {TAS2552_LIMIT_RATE_HYS ,0x08 }, {TAS2552_LIMIT_RELEASE ,0x04 }, {TAS2552_LIMIT_INT_COUNT ,0x00 }, + {TAS2552_PDM_CFG ,0x01 }, + {TAS2552_PGA_GAIN ,0x00 }, {TAS2552_EDGE_RATE_CTRL ,0x40 }, + {TAS2552_BOOST_APT_CTRL ,0x0f }, {TAS2552_VBAT_DATA ,0x00 }, };
Greg Kroah-Hartman
maintainerPATCH 255/556 ASoC: tas2764: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit e7643c3f7eb3292f8a98c2ddbf46ba78d848b83d upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
TAS2764_DVC (0x1a) is listed before TAS2764_CHNL_0 (0x03), which makes it unreachable. regcache_reg_needs_sync() then cannot compare it against its default and reports that a sync is needed, so it is written to the device on every regcache_sync() even when it was never touched.
Sort the table by register address.
--- sound/soc/codecs/tas2764.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/tas2764.c +1 -1
@@ -897,13 +897,13 @@ static const struct reg_default tas2764_ { TAS2764_PAGE, 0x00 }, { TAS2764_SW_RST, 0x00 }, { TAS2764_PWR_CTRL, 0x1a }, - { TAS2764_DVC, 0x00 }, { TAS2764_CHNL_0, 0x28 }, { TAS2764_TDM_CFG0, 0x09 }, { TAS2764_TDM_CFG1, 0x02 }, { TAS2764_TDM_CFG2, 0x0a }, { TAS2764_TDM_CFG3, 0x10 }, { TAS2764_TDM_CFG5, 0x42 }, + { TAS2764_DVC, 0x00 }, { TAS2764_INT_CLK_CFG, 0x19 }, };
Greg Kroah-Hartman
maintainerPATCH 256/556 ASoC: tas2780: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit e725093e9e53db9298e38e7332a44dcaac2fd135 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
TAS2780_DVC (0x1a) is listed before TAS2780_CHNL_0 (0x03), which makes it unreachable. regcache_reg_needs_sync() then cannot compare it against its default and reports that a sync is needed, so it is written to the device on every regcache_sync() even when it was never touched.
Sort the table by register address.
--- sound/soc/codecs/tas2780.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/soc/codecs/tas2780.c +1 -1
@@ -527,13 +527,13 @@ static const struct reg_default tas2780_ { TAS2780_PAGE, 0x00 }, { TAS2780_SW_RST, 0x00 }, { TAS2780_PWR_CTRL, 0x1a }, - { TAS2780_DVC, 0x00 }, { TAS2780_CHNL_0, 0x00 }, { TAS2780_TDM_CFG0, 0x09 }, { TAS2780_TDM_CFG1, 0x02 }, { TAS2780_TDM_CFG2, 0x0a }, { TAS2780_TDM_CFG3, 0x10 }, { TAS2780_TDM_CFG5, 0x42 }, + { TAS2780_DVC, 0x00 }, }; static const struct regmap_range_cfg tas2780_regmap_ranges[] = {
Greg Kroah-Hartman
maintainerPATCH 257/556 ASoC: tas2783-sdw: drop duplicate reg_default entry
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit ceba07ca24fab54e0e38ec96d196fca3e638d671 upstream.
TAS2783_AMP_LEVEL is defined as TASDEV_REG_SDW(0x0, 0x00, 0x03), so tas2783_reg_default[] lists that register twice. Drop the open coded second entry.
--- sound/soc/codecs/tas2783-sdw.c | 1 - 1 file changed, 1 deletion(-)
sound/soc/codecs/tas2783-sdw.c +0 -1
@@ -106,7 +106,6 @@ struct tas2783_prv {static const struct reg_default tas2783_reg_default[] = { {TAS2783_AMP_LEVEL ,0x28 }, - {TASDEV_REG_SDW (0 ,0 ,0x03 ),0x28 }, {TASDEV_REG_SDW (0 ,0 ,0x04 ),0x21 }, {TASDEV_REG_SDW (0 ,0 ,0x05 ),0x41 }, {TASDEV_REG_SDW (0 ,0 ,0x06 ),0x00 },
Greg Kroah-Hartman
maintainerPATCH 258/556 ASoC: tas2783-sdw: sort the register default table
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Ujfalusi <[email protected]>
commit b45fc97ebcfb27ec250025329a4f79ce5e327ec3 upstream.
reg_defaults must be sorted by ascending register address, as regcache_lookup_reg() locates entries in it with bsearch(). See commit fd80df352ba1 ("regcache: Add support for sorting defaults arrays").
tas2783_reg_default[] is grouped by SDCA entity name instead, so the binary search does not find 120 of its 196 entries. regcache_reg_needs_sync() then cannot compare those against their default and reports that a sync is needed, so they are written to the device on every regcache_sync() even when they were never touched.
Sort the table by register address.
--- sound/soc/codecs/tas2783-sdw.c | 170 ++++++++++++++++++++--------------------- 1 file changed, 85 insertions(+), 85 deletions(-)
sound/soc/codecs/tas2783-sdw.c +85 -85
@@ -141,6 +141,7 @@ static const struct reg_default tas2783_ {TASDEV_REG_SDW(0, 0, 0x41), 0x14}, {TASDEV_REG_SDW(0, 0, 0x5c), 0x19}, {TASDEV_REG_SDW(0, 0, 0x5d), 0x80}, + {TASDEV_REG_SDW(0, 0, 0x60), 0x21}, {TASDEV_REG_SDW(0, 0, 0x63), 0x48}, {TASDEV_REG_SDW(0, 0, 0x65), 0x08}, {TASDEV_REG_SDW(0, 0, 0x66), 0xb2},
@@ -156,7 +157,6 @@ static const struct reg_default tas2783_ {TASDEV_REG_SDW(0, 0, 0x73), 0x08}, {TASDEV_REG_SDW(0, 0, 0x75), 0xe0}, {TASDEV_REG_SDW(0, 0, 0x7a), 0x60}, - {TASDEV_REG_SDW(0, 0, 0x60), 0x21}, {TASDEV_REG_SDW(0, 1, 0x02), 0x00}, {TASDEV_REG_SDW(0, 1, 0x17), 0xc0}, {TASDEV_REG_SDW(0, 1, 0x19), 0x60},
@@ -175,63 +175,44 @@ static const struct reg_default tas2783_ {TASDEV_REG_SDW(0, 0xfd, 0x39), 0x00}, {TASDEV_REG_SDW(0, 0xfd, 0x3e), 0x00}, {TASDEV_REG_SDW(0, 0xfd, 0x45), 0x00}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS21, 0x02, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS21, 0x10, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS24, 0x02, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS24, 0x10, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS26, 0x02, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS26, 0x10, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS28, 0x02, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS28, 0x10, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS127, 0x02, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS127, 0x10, 0), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU21, 0x01, 1), 0x1}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU21, 0x02, 1), 0x9c00}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU23, 0x01, 0), 0x1}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU23, 0x01, 1), 0x1}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU23, 0x0b, 1), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU23, 0x10, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU26, 0x01, 1), 0x1}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU26, 0x01, 0), 0x1}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU26, 0x01, 1), 0x1}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU26, 0x0b, 1), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU26, 0x10, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU127, 0x01, 0), 0x1}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU127, 0x01, 1), 0x1}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU127, 0x01, 2), 0x1}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU127, 0x0b, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU127, 0x0b, 1), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU127, 0x0b, 2), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU127, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x01, 0), 0x1}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x06, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x07, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x08, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x09, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x0a, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS24, 0x02, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS21, 0x02, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS26, 0x02, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS28, 0x02, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PDE23, 0x1, 0), 0x3}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_SAPU29, 0x05, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU21, 0x06, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU26, 0x06, 0), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT21, 0x04, 0), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT21, 0x08, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT21, 0x10, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT21, 0x11, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT29, 0x04, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT29, 0x08, 0), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT26, 0x04, 0), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT26, 0x08, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT26, 0x10, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT26, 0x11, 0), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT28, 0x04, 0), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT28, 0x08, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT28, 0x10, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT28, 0x11, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT29, 0x04, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT29, 0x08, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT29, 0x10, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT29, 0x11, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU21, 0x01, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU21, 0x04, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU21, 0x05, 0), 0x1}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU21, 0x08, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU21, 0x10, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU21, 0x11, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU21, 0x12, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU26, 0x01, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU26, 0x04, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU26, 0x05, 0), 0x1}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU26, 0x08, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU26, 0x10, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU26, 0x11, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU26, 0x12, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT24, 0x04, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT24, 0x08, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT23, 0x04, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT23, 0x08, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT25, 0x04, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT25, 0x08, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT28, 0x04, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT28, 0x08, 0), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MU26, 0x01, 0), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MU26, 0x01, 1), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MU26, 0x01, 2), 0x0},
@@ -241,19 +222,60 @@ static const struct reg_default tas2783_ {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MU26, 0x01, 6), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MU26, 0x01, 7), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MU26, 0x06, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT23, 0x04, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT23, 0x08, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT24, 0x04, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT24, 0x08, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT127, 0x04, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT127, 0x08, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU127, 0x01, 0), 0x1}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU127, 0x01, 1), 0x1}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU127, 0x01, 2), 0x1}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU127, 0x0b, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU127, 0x0b, 1), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU127, 0x0b, 2), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS127, 0x02, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU21, 0x01, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU21, 0x04, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU21, 0x05, 0), 0x1}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU21, 0x08, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU26, 0x01, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU26, 0x04, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU26, 0x05, 0), 0x1}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU26, 0x08, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU23, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU26, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x10, 0), 0x1}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x12, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x13, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x14, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x15, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x16, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS24, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS21, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS26, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS28, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PDE23, 0x10, 0), 0x3}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_UDMPU23, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_SAPU29, 0x10, 0), 0x1}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_SAPU29, 0x11, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_SAPU29, 0x12, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU21, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU21, 0x11, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU21, 0x12, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU21, 0x13, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU26, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU26, 0x11, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU26, 0x12, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU26, 0x13, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_TG23, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT21, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT21, 0x11, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT29, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT29, 0x11, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT26, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT26, 0x11, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT28, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_IT28, 0x11, 0), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT24, 0x11, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT25, 0x04, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT25, 0x08, 0), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT25, 0x11, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT28, 0x04, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT28, 0x08, 0), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT28, 0x11, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT127, 0x04, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT127, 0x08, 0), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT127, 0x11, 0), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT127, 0x12, 0), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT127, 0x12, 1), 0x0},
@@ -263,6 +285,14 @@ static const struct reg_default tas2783_ {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT127, 0x12, 5), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT127, 0x12, 6), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT127, 0x12, 7), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_FU127, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_CS127, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU21, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU21, 0x11, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU21, 0x12, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU26, 0x10, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU26, 0x11, 0), 0x0}, + {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_MFPU26, 0x12, 0), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT127, 0x12, 8), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT127, 0x12, 9), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT127, 0x12, 0xa), 0x0},
@@ -271,36 +301,6 @@ static const struct reg_default tas2783_ {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT127, 0x12, 0xd), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT127, 0x12, 0xe), 0x0}, {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_OT127, 0x12, 0xf), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PDE23, 0x1, 0), 0x3}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PDE23, 0x10, 0), 0x3}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU21, 0x06, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU21, 0x10, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU21, 0x11, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU21, 0x12, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU21, 0x13, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU26, 0x06, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU26, 0x10, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU26, 0x11, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU26, 0x12, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_PPU26, 0x13, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_SAPU29, 0x05, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_SAPU29, 0x10, 0), 0x1}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_SAPU29, 0x11, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_SAPU29, 0x12, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_TG23, 0x10, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x01, 0), 0x1}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x06, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x07, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x08, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x09, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x0a, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x10, 0), 0x1}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x12, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x13, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x14, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x15, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_XU22, 0x16, 0), 0x0}, - {SDW_SDCA_CTL(1, TAS2783_SDCA_ENT_UDMPU23, 0x10, 0), 0x0}, }; static const struct reg_sequence tas2783_init_seq[] = {
Greg Kroah-Hartman
maintainerPATCH 259/556 iio: adc: ad4080: configure backend data size
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Antoniu Miclaus <[email protected]>
commit d39afd249d1ef5cb03b6f1dc22a68e6385de413d upstream.
The AXI backend needs to know the ADC word width in order to pack the sample data correctly on the bus. During channel setup, program the backend packet format via iio_backend_data_size_set() using the channel resolution, so the data is transferred according to the device's realbits.
The backend packet format field defaults to 20-bit packing, so the 20-bit parts (AD4080/AD4081/AD4082, AD4880) were unaffected. The 16-bit (AD4083/AD4084/AD4085, AD4884) and 14-bit (AD4086/AD4087/AD4088) parts, however, were left packing data at the wrong width, producing corrupt buffered captures.
--- drivers/iio/adc/ad4080.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/iio/adc/ad4080.c +5 -0
@@ -697,6 +697,11 @@ static int ad4080_setup_channel(struct aif (ret)return ret; + ret =iio_backend_data_size_set (st->back[ch], + st->info->channels[0 ].scan_type.realbits); +if (ret) +return ret; +if (!st->lvds_cnv_en)return 0 ;
Greg Kroah-Hartman
maintainerPATCH 260/556 iio: adc: adi-axi-adc: add data size support for AD408X backend
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Antoniu Miclaus <[email protected]>
commit 60f6f7fd5f89c7f55991c5dc59f3ccc74cd6efd7 upstream.
The AD408X AXI core can pack the sample data on the bus using different word widths. Expose this through the data_size_set backend operation so that frontends can program the packet format field (bits 3:2 of the CNTRL_3 register) according to the ADC resolution: 20-bit, 16-bit and 14-bit map to packet format values 0, 1 and 2 respectively.
--- drivers/iio/adc/adi-axi-adc.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/iio/adc/adi-axi-adc.c +30 -0
@@ -53,6 +53,10 @@#define AXI_AD485X_PACKET_FORMAT_24BIT 0x1#define AXI_AD485X_PACKET_FORMAT_32BIT 0x2#define AXI_AD408X_CNTRL_3_FILTER_EN_MSK BIT(0) +#define AXI_AD408X_CNTRL_3_PACKET_FORMAT_MSK GENMASK(3, 2) +#define AXI_AD408X_PACKET_FORMAT_20BIT 0x0 +#define AXI_AD408X_PACKET_FORMAT_16BIT 0x1 +#define AXI_AD408X_PACKET_FORMAT_14BIT 0x2#define ADI_AXI_ADC_REG_SYNC_STATUS 0x0068#define ADI_AXI_ADC_SYNC_STATUS_ADC_SYNC_MSK BIT(0)
@@ -436,6 +440,31 @@ static int axi_adc_ad408x_filter_type_se AXI_AD408X_CNTRL_3_FILTER_EN_MSK); } +static int axi_adc_ad408x_data_size_set (struct iio_backend *back, +unsigned int size) +{ +struct adi_axi_adc_state *st =iio_backend_get_priv (back); +unsigned int val; + +switch (size) { +case 20 : + val =AXI_AD408X_PACKET_FORMAT_20BIT ; +break ; +case 16 : + val =AXI_AD408X_PACKET_FORMAT_16BIT ; +break ; +case 14 : + val =AXI_AD408X_PACKET_FORMAT_14BIT ; +break ; +default : +return -EINVAL ; + } + +return regmap_update_bits (st->regmap,ADI_AXI_ADC_REG_CNTRL_3 , +AXI_AD408X_CNTRL_3_PACKET_FORMAT_MSK , +FIELD_PREP (AXI_AD408X_CNTRL_3_PACKET_FORMAT_MSK , val)); +} +static int axi_adc_ad408x_interface_data_align (struct iio_backend *back,u32 timeout_us) {
@@ -659,6 +688,7 @@ static const struct iio_backend_ops adi_ .free_buffer = axi_adc_free_buffer, .data_sample_trigger = axi_adc_data_sample_trigger, .filter_type_set = axi_adc_ad408x_filter_type_set, + .data_size_set = axi_adc_ad408x_data_size_set, .interface_data_align = axi_adc_ad408x_interface_data_align, .num_lanes_set = axi_adc_num_lanes_set, .debugfs_reg_access = iio_backend_debugfs_ptr(axi_adc_reg_access),
Greg Kroah-Hartman
maintainerPATCH 261/556 iio: adc: max14001: add missing select REGMAP to Kconfig
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joshua Crofts <[email protected]>
commit b7c969d0d445c415b8e9f32627d7e8f092c7e916 upstream.
The Kconfig entry for the MAX14001 is missing a 'select REGMAP', causing build failures.
--- drivers/iio/adc/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/iio/adc/Kconfig +1 -0
@@ -1076,6 +1076,7 @@ config MAX1363 config MAX14001 tristate "Analog Devices MAX14001/MAX14002 ADC driver" depends on SPI + select REGMAP help Say yes here to build support for Analog Devices MAX14001/MAX14002 Configurable, Isolated 10-bit ADCs for Multi-Range Binary Inputs.
Greg Kroah-Hartman
maintainerPATCH 262/556 iio: adc: max34408: add missing select REGMAP_I2C to Kconfig
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Joshua Crofts <[email protected]>
commit 947f1079074a260ba200419d5cba6b8549d5ac0c upstream.
The Kconfig entry for the MAX34408 is missing a 'select REGMAP_I2C', causing build failures.
--- drivers/iio/adc/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/iio/adc/Kconfig +1 -0
@@ -1087,6 +1087,7 @@ config MAX14001 config MAX34408 tristate "Maxim max34408/max344089 ADC driver" depends on I2C + select REGMAP_I2C help Say yes here to build support for Maxim max34408/max34409 current sense monitor with 8-bits ADC interface with overcurrent delay/threshold and
Greg Kroah-Hartman
maintainerPATCH 263/556 iio: adc: pac1921: fix wrong channel used in trigger handler read
In reply to Greg Kroah-Hartman7.2-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cong Nguyen <[email protected]>
commit 3364c56b20c1c496bdb8c8df32f96a9947dbf98e upstream.
pac1921_trigger_handler() walks the enabled channels with iio_for_each_active_channel(), which yields the scan index (bit) of each active channel, while ch is a separate counter used to pack the samples contiguously into the scan buffer.
The register to read was looked up with the packing counter instead of the scan index:
ret = pac1921_read_res(priv, idev->channels[ch].address, &val);
pac1921_channels[] is ordered by scan index, so channels[bit] is the channel that is actually enabled, whereas channels[ch] is merely the ch-th array entry. These coincide only when the enabled channels form a contiguous prefix (e.g. all channels enabled). With a sparse scan mask - for example when only the power channel (scan index 3) is enabled - the handler reads the wrong register (VBUS instead of VPOWER) and pushes it to userspace as the enabled channel's data.
Index the channel array by the scan index (bit) to read the correct register, keeping ch only for contiguous packing into the scan buffer.
--- drivers/iio/adc/pac1921.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/adc/pac1921.c +1 -1
@@ -1037,7 +1037,7 @@ static irqreturn_t pac1921_trigger_handliio_for_each_active_channel (idev, bit) {u16 val; - ret =pac1921_read_res (priv, idev->channels[ch].address, &val); + ret =pac1921_read_res (priv, idev->channels[bit].address, &val);if (ret) goto done;