6.6.103-rc1 review
Subsystems (5)
Greg Kroah-Hartman
maintainerPATCH 294/587 scsi: lpfc: Remove redundant assignment to avoid memory leak
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiasheng Jiang <[email protected]>
[ Upstream commit eea6cafb5890db488fce1c69d05464214616d800 ]
Remove the redundant assignment if kzalloc() succeeds to avoid memory leak.
--- drivers/scsi/lpfc/lpfc_debugfs.c | 1 - 1 file changed, 1 deletion(-)
drivers/scsi/lpfc/lpfc_debugfs.c +0 -1
@@ -6291,7 +6291,6 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport) } phba->nvmeio_trc_on =1 ; phba->nvmeio_trc_output_idx =0 ; - phba->nvmeio_trc =NULL ; }else { nvmeio_off: phba->nvmeio_trc_size =0 ;
Signature · 1 line
2.50.1
Greg Kroah-Hartman
maintainerPATCH 295/587 ASoC: fsl_sai: replace regmap_write with regmap_update_bits
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shengjiu Wang <[email protected]>
[ Upstream commit 0e270f32975fd21874185ba53653630dd40bf560 ]
Use the regmap_write() for software reset in fsl_sai_config_disable would cause the FSL_SAI_CSR_BCE bit to be cleared. Refer to
commit 197c53c8ecb34 ("ASoC: fsl_sai: Don't disable bitclock for i.MX8MP") FSL_SAI_CSR_BCE should not be cleared. So need to use regmap_update_bits() instead of regmap_write() for these bit operations.
--- sound/soc/fsl/fsl_sai.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
sound/soc/fsl/fsl_sai.c +10 -10
@@ -768,9 +768,9 @@ static void fsl_sai_config_disable(struct fsl_sai *sai, int dir)* are running concurrently. */ /* Software Reset */ -regmap_write (sai->regmap,FSL_SAI_xCSR (tx, ofs),FSL_SAI_CSR_SR ); +regmap_update_bits (sai->regmap,FSL_SAI_xCSR (tx, ofs),FSL_SAI_CSR_SR ,FSL_SAI_CSR_SR );/* Clear SR bit to finish the reset */ -regmap_write (sai->regmap,FSL_SAI_xCSR (tx, ofs),0 ); +regmap_update_bits (sai->regmap,FSL_SAI_xCSR (tx, ofs),FSL_SAI_CSR_SR ,0 ); } static int fsl_sai_trigger(struct snd_pcm_substream *substream, int cmd,
@@ -889,11 +889,11 @@ static int fsl_sai_dai_probe(struct snd_soc_dai *cpu_dai)unsigned int ofs = sai->soc_data->reg_offset;/* Software Reset for both Tx and Rx */ -regmap_write (sai->regmap,FSL_SAI_TCSR (ofs),FSL_SAI_CSR_SR ); -regmap_write (sai->regmap,FSL_SAI_RCSR (ofs),FSL_SAI_CSR_SR ); +regmap_update_bits (sai->regmap,FSL_SAI_TCSR (ofs),FSL_SAI_CSR_SR ,FSL_SAI_CSR_SR ); +regmap_update_bits (sai->regmap,FSL_SAI_RCSR (ofs),FSL_SAI_CSR_SR ,FSL_SAI_CSR_SR );/* Clear SR bit to finish the reset */ -regmap_write (sai->regmap,FSL_SAI_TCSR (ofs),0 ); -regmap_write (sai->regmap,FSL_SAI_RCSR (ofs),0 ); +regmap_update_bits (sai->regmap,FSL_SAI_TCSR (ofs),FSL_SAI_CSR_SR ,0 ); +regmap_update_bits (sai->regmap,FSL_SAI_RCSR (ofs),FSL_SAI_CSR_SR ,0 ); regmap_update_bits(sai->regmap, FSL_SAI_TCR1(ofs), FSL_SAI_CR1_RFW_MASK(sai->soc_data->fifo_depth),
@@ -1710,11 +1710,11 @@ static int fsl_sai_runtime_resume(struct device *dev)regcache_cache_only (sai->regmap, false);regcache_mark_dirty (sai->regmap); -regmap_write (sai->regmap,FSL_SAI_TCSR (ofs),FSL_SAI_CSR_SR ); -regmap_write (sai->regmap,FSL_SAI_RCSR (ofs),FSL_SAI_CSR_SR ); +regmap_update_bits (sai->regmap,FSL_SAI_TCSR (ofs),FSL_SAI_CSR_SR ,FSL_SAI_CSR_SR ); +regmap_update_bits (sai->regmap,FSL_SAI_RCSR (ofs),FSL_SAI_CSR_SR ,FSL_SAI_CSR_SR );usleep_range (1000 ,2000 ); -regmap_write (sai->regmap,FSL_SAI_TCSR (ofs),0 ); -regmap_write (sai->regmap,FSL_SAI_RCSR (ofs),0 ); +regmap_update_bits (sai->regmap,FSL_SAI_TCSR (ofs),FSL_SAI_CSR_SR ,0 ); +regmap_update_bits (sai->regmap,FSL_SAI_RCSR (ofs),FSL_SAI_CSR_SR ,0 ); ret =regcache_sync (sai->regmap);if (ret)
Signature · 1 line
2.50.1
Greg Kroah-Hartman
maintainerPATCH 296/587 drm/amdgpu: fix incorrect vm flags to map bo
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jack Xiao <[email protected]>
[ Upstream commit 040bc6d0e0e9c814c9c663f6f1544ebaff6824a8 ]
It should use vm flags instead of pte flags
to specify bo vm attributes.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c +2 -2
@@ -89,8 +89,8 @@ int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm, } r =amdgpu_vm_bo_map (adev, *bo_va, csa_addr,0 , size, -AMDGPU_PTE_READABLE |AMDGPU_PTE_WRITEABLE | -AMDGPU_PTE_EXECUTABLE ); +AMDGPU_VM_PAGE_READABLE |AMDGPU_VM_PAGE_WRITEABLE | +AMDGPU_VM_PAGE_EXECUTABLE );if (r) {DRM_ERROR ("failed to do bo_map on static CSA, err=%d\n" , r);
Signature · 1 line
2.50.1
Greg Kroah-Hartman
maintainerPATCH 297/587 cifs: reset iface weights when we cannot find a candidate
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Shyam Prasad N <[email protected]>
commit 9d5eff7821f6d70f7d1b4d8a60680fba4de868a7 upstream.
We now do a weighted selection of server interfaces when allocating new channels. The weights are decided based on the speed advertised. The fulfilled weight for an interface is a counter that is used to track the interface selection. It should be reset back to zero once all interfaces fulfilling their weight.
In cifs_chan_update_iface, this reset logic was missing. As a result when the server interface list changes, the client may not be able to find a new candidate for other channels after all interfaces have been fulfilled.
--- fs/smb/client/sess.c | 9 +++++++++ 1 file changed, 9 insertions(+)
fs/smb/client/sess.c +9 -0
@@ -372,6 +372,7 @@ cifs_chan_update_iface(struct cifs_ses *struct cifs_server_iface *old_iface =NULL ;struct cifs_server_iface *last_iface =NULL ;struct sockaddr_storage ss; +int retry =0 ;spin_lock (&ses->chan_lock); chan_index =cifs_ses_get_chan_index (ses, server);
@@ -400,6 +401,7 @@ cifs_chan_update_iface(struct cifs_ses *return ; } +try_again: last_iface = list_last_entry(&ses->iface_list, struct cifs_server_iface, iface_head); iface_min_speed = last_iface->speed;
@@ -437,6 +439,13 @@ cifs_chan_update_iface(struct cifs_ses * }if (list_entry_is_head (iface, &ses->iface_list, iface_head)) { +list_for_each_entry (iface, &ses->iface_list, iface_head) + iface->weight_fulfilled =0 ; + +/* see if it can be satisfied in second attempt */ +if (!retry++) + goto try_again; + iface =NULL ;cifs_dbg (FYI ,"unable to find a suitable iface\n" ); }
Greg Kroah-Hartman
maintainerPATCH 298/587 iommu/arm-smmu-qcom: Add SM6115 MDSS compatible
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexey Klimov <[email protected]>
commit f7fa8520f30373ce99c436c4d57c76befdacbef3 upstream.
Add the SM6115 MDSS compatible to clients compatible list, as it also needs that workaround.
Without this workaround, for example, QRB4210 RB2 which is based on SM4250/SM6115 generates a lot of smmu unhandled context faults during boot:
arm_smmu_context_fault: 116854 callbacks suppressed arm-smmu c600000.iommu: Unhandled context fault: fsr=0x402, iova=0x5c0ec600, fsynr=0x320021, cbfrsynra=0x420, cb=5
arm-smmu c600000.iommu: FSR = 00000402 [Format=2 TF], SID=0x420
arm-smmu c600000.iommu: FSYNR0 = 00320021 [S1CBNDX=50 PNU PLVL=1] arm-smmu c600000.iommu: Unhandled context fault: fsr=0x402, iova=0x5c0d7800, fsynr=0x320021, cbfrsynra=0x420, cb=5
arm-smmu c600000.iommu: FSR = 00000402 [Format=2 TF], SID=0x420
and also failed initialisation of lontium lt9611uxc, gpu and dpu is observed:
(binding MDSS components triggered by lt9611uxc have failed)
------------[ cut here ]------------ !aspace WARNING: CPU: 6 PID: 324 at drivers/gpu/drm/msm/msm_gem_vma.c:130 msm_gem_vma_init+0x150/0x18c [msm] Modules linked in: ... (long list of modules) CPU: 6 UID: 0 PID: 324 Comm: (udev-worker) Not tainted 6.15.0-03037-gaacc73ceeb8b #4 PREEMPT Hardware name: Qualcomm Technologies, Inc. QRB4210 RB2 (DT) pstate: 80000005 (Nzcv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : msm_gem_vma_init+0x150/0x18c [msm] lr : msm_gem_vma_init+0x150/0x18c [msm] sp : ffff80008144b280 ... Call trace: msm_gem_vma_init+0x150/0x18c [msm] (P) get_vma_locked+0xc0/0x194 [msm] msm_gem_get_and_pin_iova_range+0x4c/0xdc [msm] msm_gem_kernel_new+0x48/0x160 [msm] msm_gpu_init+0x34c/0x53c [msm] adreno_gpu_init+0x1b0/0x2d8 [msm] a6xx_gpu_init+0x1e8/0x9e0 [msm] adreno_bind+0x2b8/0x348 [msm] component_bind_all+0x100/0x230 msm_drm_bind+0x13c/0x3d0 [msm] try_to_bring_up_aggregate_device+0x164/0x1d0 __component_add+0xa4/0x174 component_add+0x14/0x20 dsi_dev_attach+0x20/0x34 [msm] dsi_host_attach+0x58/0x98 [msm] devm_mipi_dsi_attach+0x34/0x90 lt9611uxc_attach_dsi.isra.0+0x94/0x124 [lontium_lt9611uxc] lt9611uxc_probe+0x540/0x5fc [lontium_lt9611uxc] i2c_device_probe+0x148/0x2a8 really_probe+0xbc/0x2c0 __driver_probe_device+0x78/0x120 driver_probe_device+0x3c/0x154 __driver_attach+0x90/0x1a0 bus_for_each_dev+0x68/0xb8 driver_attach+0x24/0x30 bus_add_driver+0xe4/0x208 driver_register+0x68/0x124 i2c_register_driver+0x48/0xcc lt9611uxc_driver_init+0x20/0x1000 [lontium_lt9611uxc] do_one_initcall+0x60/0x1d4 do_init_module+0x54/0x1fc load_module+0x1748/0x1c8c init_module_from_file+0x74/0xa0 __arm64_sys_finit_module+0x130/0x2f8 invoke_syscall+0x48/0x104 el0_svc_common.constprop.0+0xc0/0xe0 do_el0_svc+0x1c/0x28 el0_svc+0x2c/0x80 el0t_64_sync_handler+0x10c/0x138 el0t_64_sync+0x198/0x19c ---[ end trace 0000000000000000 ]--- msm_dpu 5e01000.display-controller: [drm:msm_gpu_init [msm]] *ERROR* could not allocate memptrs: -22 msm_dpu 5e01000.display-controller: failed to load adreno gpu platform a400000.remoteproc:glink-edge:apr:service@7:dais: Adding to iommu group 19 msm_dpu 5e01000.display-controller: failed to bind 5900000.gpu (ops a3xx_ops [msm]): -22 msm_dpu 5e01000.display-controller: adev bind failed: -22 lt9611uxc 0-002b: failed to attach dsi to host lt9611uxc 0-002b: probe with driver lt9611uxc failed with error -22
--- drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c | 1 + 1 file changed, 1 insertion(+)
drivers/iommu/arm/arm-smmu/arm-smmu-qcom.c +1 -0
@@ -255,6 +255,7 @@ static const struct of_device_id qcom_sm { .compatible = "qcom,sdm670-mdss" }, { .compatible = "qcom,sdm845-mdss" }, { .compatible = "qcom,sdm845-mss-pil" }, + { .compatible = "qcom,sm6115-mdss" }, { .compatible = "qcom,sm6350-mdss" }, { .compatible = "qcom,sm6375-mdss" }, { .compatible = "qcom,sm8150-mdss" },
Greg Kroah-Hartman
maintainerPATCH 299/587 iommufd: Report unmapped bytes in the error path of iopt_unmap_iova_range
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolin Chen <[email protected]>
commit b23e09f9997771b4b739c1c694fa832b5fa2de02 upstream.
There are callers that read the unmapped bytes even when rc != 0. Thus, do not forget to report it in the error path too.
--- drivers/iommu/iommufd/io_pagetable.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/iommu/iommufd/io_pagetable.c +5 -2
@@ -524,8 +524,10 @@ again:iommufd_access_notify_unmap (iopt, area_first, length);/* Something is not responding to unmap requests. */ tries++; -if (WARN_ON (tries >100 )) -return -EDEADLOCK ; +if (WARN_ON (tries >100 )) { + rc = -EDEADLOCK ; + goto out_unmapped; + } goto again; }
@@ -547,6 +549,7 @@ again: out_unlock_iova:up_write (&iopt->iova_rwsem);up_read (&iopt->domains_rwsem); +out_unmapped:if (unmapped) *unmapped = unmapped_bytes;return rc;
Greg Kroah-Hartman
maintainerPATCH 300/587 iommufd: Prevent ALIGN() overflow
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jason Gunthorpe <[email protected]>
commit b42497e3c0e74db061eafad41c0cd7243c46436b upstream.
When allocating IOVA the candidate range gets aligned to the target alignment. If the range is close to ULONG_MAX then the ALIGN() can wrap resulting in a corrupted iova.
Open code the ALIGN() using get_add_overflow() to prevent this. This simplifies the checks as we don't need to check for length earlier either.
Consolidate the two copies of this code under a single helper.
This bug would allow userspace to create a mapping that overlaps with some other mapping or a reserved range.
--- drivers/iommu/iommufd/io_pagetable.c | 41 +++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 16 deletions(-)
drivers/iommu/iommufd/io_pagetable.c +25 -16
@@ -69,36 +69,45 @@ struct iopt_area *iopt_area_contig_next(return iter->area; } -static bool __alloc_iova_check_hole (struct interval_tree_double_span_iter *span, -unsigned long length, -unsigned long iova_alignment, -unsigned long page_offset) +static bool __alloc_iova_check_range (unsigned long *start,unsigned long last, +unsigned long length, +unsigned long iova_alignment, +unsigned long page_offset) { -if (span->is_used || span->last_hole - span->start_hole < length -1 ) +unsigned long aligned_start; + +/* ALIGN_UP() */ +if (check_add_overflow (*start, iova_alignment -1 , &aligned_start))return false; + aligned_start &= ~(iova_alignment -1 ); + aligned_start |= page_offset; - span->start_hole =ALIGN (span->start_hole, iova_alignment) | - page_offset; -if (span->start_hole > span->last_hole || - span->last_hole - span->start_hole < length -1 ) +if (aligned_start >= last || last - aligned_start < length -1 )return false; + *start = aligned_start;return true; } -static bool __alloc_iova_check_used (struct interval_tree_span_iter *span, +static bool __alloc_iova_check_hole (struct interval_tree_double_span_iter *span,unsigned long length,unsigned long iova_alignment,unsigned long page_offset) { -if (span->is_hole || span->last_used - span->start_used < length -1 ) +if (span->is_used)return false; +return __alloc_iova_check_range (&span->start_hole, span->last_hole, + length, iova_alignment, page_offset); +} - span->start_used =ALIGN (span->start_used, iova_alignment) | - page_offset; -if (span->start_used > span->last_used || - span->last_used - span->start_used < length -1 ) +static bool __alloc_iova_check_used (struct interval_tree_span_iter *span, +unsigned long length, +unsigned long iova_alignment, +unsigned long page_offset) +{ +if (span->is_hole)return false; -return true; +return __alloc_iova_check_range (&span->start_used, span->last_used, + length, iova_alignment, page_offset); }/*
Greg Kroah-Hartman
maintainerPATCH 301/587 ext4: fix zombie groups in average fragment size lists
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baokun Li <[email protected]>
commit 1c320d8e92925bb7615f83a7b6e3f402a5c2ca63 upstream.
Groups with no free blocks shouldn't be in any average fragment size list. However, when all blocks in a group are allocated(i.e., bb_fragments or bb_free is 0), we currently skip updating the average fragment size, which means the group isn't removed from its previous s_mb_avg_fragment_size[old] list.
This created "zombie" groups that were always skipped during traversal as they couldn't satisfy any block allocation requests, negatively impacting traversal efficiency.
Therefore, when a group becomes completely full, bb_avg_fragment_size_order is now set to -1. If the old order was not -1, a removal operation is performed; if the new order is not -1, an insertion is performed.
--- fs/ext4/mballoc.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-)
fs/ext4/mballoc.c +17 -17
@@ -841,30 +841,30 @@ static void mb_update_avg_fragment_size(struct super_block *sb, struct ext4_group_info *grp) { struct ext4_sb_info *sbi = EXT4_SB(sb); -int new_order; +int new, old; -if (!test_opt2 (sb,MB_OPTIMIZE_SCAN ) || grp->bb_fragments ==0 ) +if (!test_opt2 (sb,MB_OPTIMIZE_SCAN ))return ; - new_order =mb_avg_fragment_size_order (sb, - grp->bb_free / grp->bb_fragments); -if (new_order == grp->bb_avg_fragment_size_order) + old = grp->bb_avg_fragment_size_order; + new = grp->bb_fragments ==0 ?-1 : +mb_avg_fragment_size_order (sb, grp->bb_free / grp->bb_fragments); +if (new == old)return ; -if (grp->bb_avg_fragment_size_order !=-1 ) { -write_lock (&sbi->s_mb_avg_fragment_size_locks[ - grp->bb_avg_fragment_size_order]); +if (old >=0 ) { +write_lock (&sbi->s_mb_avg_fragment_size_locks[old]);list_del (&grp->bb_avg_fragment_size_node); -write_unlock (&sbi->s_mb_avg_fragment_size_locks[ - grp->bb_avg_fragment_size_order]); +write_unlock (&sbi->s_mb_avg_fragment_size_locks[old]); + } + + grp->bb_avg_fragment_size_order = new; +if (new >=0 ) { +write_lock (&sbi->s_mb_avg_fragment_size_locks[new]); +list_add_tail (&grp->bb_avg_fragment_size_node, + &sbi->s_mb_avg_fragment_size[new]); +write_unlock (&sbi->s_mb_avg_fragment_size_locks[new]); } - grp->bb_avg_fragment_size_order = new_order; -write_lock (&sbi->s_mb_avg_fragment_size_locks[ - grp->bb_avg_fragment_size_order]); -list_add_tail (&grp->bb_avg_fragment_size_node, - &sbi->s_mb_avg_fragment_size[grp->bb_avg_fragment_size_order]); -write_unlock (&sbi->s_mb_avg_fragment_size_locks[ - grp->bb_avg_fragment_size_order]); }/*
Greg Kroah-Hartman
maintainerPATCH 302/587 ext4: fix largest free orders lists corruption on mb_optimize_scan switch
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baokun Li <[email protected]>
commit 7d345aa1fac4c2ec9584fbd6f389f2c2368671d5 upstream.
The grp->bb_largest_free_order is updated regardless of whether mb_optimize_scan is enabled. This can lead to inconsistencies between grp->bb_largest_free_order and the actual s_mb_largest_free_orders list index when mb_optimize_scan is repeatedly enabled and disabled via remount.
For example, if mb_optimize_scan is initially enabled, largest free order is 3, and the group is in s_mb_largest_free_orders[3]. Then, mb_optimize_scan is disabled via remount, block allocations occur, updating largest free order to 2. Finally, mb_optimize_scan is re-enabled via remount, more block allocations update largest free order to 1.
At this point, the group would be removed from s_mb_largest_free_orders[3] under the protection of s_mb_largest_free_orders_locks[2]. This lock mismatch can lead to list corruption.
To fix this, whenever grp->bb_largest_free_order changes, we now always attempt to remove the group from its old order list. However, we only insert the group into the new order list if mb_optimize_scan is enabled. This approach helps prevent lock inconsistencies and ensures the data in the order lists remains reliable.
--- fs/ext4/mballoc.c | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-)
fs/ext4/mballoc.c +14 -19
@@ -1150,33 +1150,28 @@ static void mb_set_largest_free_order(struct super_block *sb, struct ext4_group_info *grp) { struct ext4_sb_info *sbi = EXT4_SB(sb); -int i; +int new, old = grp->bb_largest_free_order; -for (i =MB_NUM_ORDERS (sb) -1 ; i >=0 ; i--) -if (grp->bb_counters[i] >0 ) +for (new =MB_NUM_ORDERS (sb) -1 ; new >=0 ; new--) +if (grp->bb_counters[new] >0 )break ; +/* No need to move between order lists? */ -if (!test_opt2 (sb,MB_OPTIMIZE_SCAN ) || - i == grp->bb_largest_free_order) { - grp->bb_largest_free_order = i; +if (new == old)return ; - } -if (grp->bb_largest_free_order >=0 ) { -write_lock (&sbi->s_mb_largest_free_orders_locks[ - grp->bb_largest_free_order]); +if (old >=0 && !list_empty (&grp->bb_largest_free_order_node)) { +write_lock (&sbi->s_mb_largest_free_orders_locks[old]);list_del_init (&grp->bb_largest_free_order_node); -write_unlock (&sbi->s_mb_largest_free_orders_locks[ - grp->bb_largest_free_order]); +write_unlock (&sbi->s_mb_largest_free_orders_locks[old]); } - grp->bb_largest_free_order = i; -if (grp->bb_largest_free_order >=0 && grp->bb_free) { -write_lock (&sbi->s_mb_largest_free_orders_locks[ - grp->bb_largest_free_order]); + + grp->bb_largest_free_order = new; +if (test_opt2 (sb,MB_OPTIMIZE_SCAN ) && new >=0 && grp->bb_free) { +write_lock (&sbi->s_mb_largest_free_orders_locks[new]);list_add_tail (&grp->bb_largest_free_order_node, - &sbi->s_mb_largest_free_orders[grp->bb_largest_free_order]); -write_unlock (&sbi->s_mb_largest_free_orders_locks[ - grp->bb_largest_free_order]); + &sbi->s_mb_largest_free_orders[new]); +write_unlock (&sbi->s_mb_largest_free_orders_locks[new]); } }
Greg Kroah-Hartman
maintainerPATCH 303/587 usb: core: config: Prevent OOB read in SS endpoint companion parsing
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Xinyu Liu <[email protected]>
commit cf16f408364efd8a68f39011a3b073c83a03612d upstream.
usb_parse_ss_endpoint_companion() checks descriptor type before length, enabling a potentially odd read outside of the buffer size.
Fix this up by checking the size first before looking at any of the fields in the descriptor.
--- drivers/usb/core/config.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/usb/core/config.c +8 -2
@@ -81,8 +81,14 @@ static void usb_parse_ss_endpoint_compan*/ desc = (struct usb_ss_ep_comp_descriptor *) buffer; -if (desc->bDescriptorType !=USB_DT_SS_ENDPOINT_COMP || - size <USB_DT_SS_EP_COMP_SIZE ) { +if (size <USB_DT_SS_EP_COMP_SIZE ) { +dev_notice (ddev, +"invalid SuperSpeed endpoint companion descriptor " +"of length %d, skipping\n" , size); +return ; + } + +if (desc->bDescriptorType !=USB_DT_SS_ENDPOINT_COMP ) { dev_notice(ddev, "No SuperSpeed endpoint companion for config %d " " interface %d altsetting %d ep %d: " "using minimum values\n",
Greg Kroah-Hartman
maintainerPATCH 304/587 misc: rtsx: usb: Ensure mmc child device is active when card is present
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricky Wu <[email protected]>
commit 966c5cd72be8989c8a559ddef8e8ff07a37c5eb0 upstream.
When a card is present in the reader, the driver currently defers autosuspend by returning -EAGAIN during the suspend callback to trigger USB remote wakeup signaling. However, this does not guarantee that the mmc child device has been resumed, which may cause issues if it remains suspended while the card is accessible.
This patch ensures that all child devices, including the mmc host controller, are explicitly resumed before returning -EAGAIN. This fixes a corner case introduced by earlier remote wakeup handling, improving reliability of runtime PM when a card is inserted.
--- drivers/misc/cardreader/rtsx_usb.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/misc/cardreader/rtsx_usb.c +9 -7
@@ -698,6 +698,12 @@ static void rtsx_usb_disconnect(struct u }#ifdef CONFIG_PM +static int rtsx_usb_resume_child (struct device *dev,void *data) +{ +pm_request_resume (dev); +return 0 ; +} +static int rtsx_usb_suspend (struct usb_interface *intf,pm_message_t message) { struct rtsx_ucr *ucr =
@@ -713,8 +719,10 @@ static int rtsx_usb_suspend(struct usb_imutex_unlock (&ucr->dev_mutex);/* Defer the autosuspend if card exists */ -if (val & (SD_CD |MS_CD )) +if (val & (SD_CD |MS_CD )) { +device_for_each_child (&intf->dev,NULL , rtsx_usb_resume_child);return -EAGAIN ; + } }else {/* There is an ongoing operation*/ return -EAGAIN ;
@@ -724,12 +732,6 @@ static int rtsx_usb_suspend(struct usb_ireturn 0 ; } -static int rtsx_usb_resume_child (struct device *dev,void *data) -{ -pm_request_resume (dev); -return 0 ; -} -static int rtsx_usb_resume (struct usb_interface *intf) {device_for_each_child (&intf->dev,NULL , rtsx_usb_resume_child);
Greg Kroah-Hartman
maintainerPATCH 305/587 usb: typec: ucsi: Update power_supply on power role change
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myrrh Periwinkle <[email protected]>
commit 7616f006db07017ef5d4ae410fca99279aaca7aa upstream.
The current power direction of an USB-C port also influences the power_supply's online status, so a power role change should also update the power_supply.
Fixes an issue on some systems where plugging in a normal USB device in for the first time after a reboot will cause upower to erroneously consider the system to be connected to AC power.
--- drivers/usb/typec/ucsi/ucsi.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/typec/ucsi/ucsi.c +1 -0
@@ -910,6 +910,7 @@ static void ucsi_handle_connector_changeif (con->status.change &UCSI_CONSTAT_POWER_DIR_CHANGE ) {typec_set_pwr_role (con->port, role); +ucsi_port_psy_changed (con);/* Complete pending power role swap */ if (!completion_done (&con->complete))
Greg Kroah-Hartman
maintainerPATCH 306/587 comedi: fix race between polling and detaching
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Abbott <[email protected]>
commit 35b6fc51c666fc96355be5cd633ed0fe4ccf68b2 upstream.
syzbot reports a use-after-free in comedi in the below link, which is due to comedi gladly removing the allocated async area even though poll requests are still active on the wait_queue_head inside of it. This can cause a use-after-free when the poll entries are later triggered or removed, as the memory for the wait_queue_head has been freed. We need to check there are no tasks queued on any of the subdevices' wait queues before allowing the device to be detached by the COMEDI_DEVCONFIG ioctl.
Tasks will read-lock dev->attach_lock before adding themselves to the subdevice wait queue, so fix the problem in the COMEDI_DEVCONFIG ioctl handler by write-locking dev->attach_lock before checking that all of the subdevices are safe to be deleted. This includes testing for any sleepers on the subdevices' wait queues. It remains locked until the device has been detached. This requires the comedi_device_detach() function to be refactored slightly, moving the bulk of it into new function comedi_device_detach_locked().
Note that the refactor of comedi_device_detach() results in comedi_device_cancel_all() now being called while dev->attach_lock is write-locked, which wasn't the case previously, but that does not matter.
Thanks to Jens Axboe for diagnosing the problem and co-developing this patch.
--- drivers/comedi/comedi_fops.c | 33 +++++++++++++++++++++++++-------- drivers/comedi/comedi_internal.h | 1 + drivers/comedi/drivers.c | 13 ++++++++++--- 3 files changed, 36 insertions(+), 11 deletions(-)
drivers/comedi/comedi_fops.c +25 -8
@@ -787,6 +787,7 @@ static int is_device_busy(struct comedi_struct comedi_subdevice *s;int i; +lockdep_assert_held_write (&dev->attach_lock);lockdep_assert_held (&dev->mutex);if (!dev->attached)return 0 ;
@@ -795,7 +796,16 @@ static int is_device_busy(struct comedi_ s = &dev->subdevices[i];if (s->busy)return 1 ; -if (s->async &&comedi_buf_is_mmapped (s)) +if (!s->async) +continue ; +if (comedi_buf_is_mmapped (s)) +return 1 ; +/* +* There may be tasks still waiting on the subdevice's wait +* queue, although they should already be about to be removed +* from it since the subdevice has no active async command. +*/ +if (wq_has_sleeper (&s->async->wait_head))return 1 ; }
@@ -825,15 +835,22 @@ static int do_devconfig_ioctl(struct comreturn -EPERM ;if (!arg) { -if (is_device_busy (dev)) -return -EBUSY ; -if (dev->attached) { -struct module *driver_module = dev->driver->module; +int rc =0 ; -comedi_device_detach (dev); -module_put (driver_module); +if (dev->attached) { +down_write (&dev->attach_lock); +if (is_device_busy (dev)) { + rc = -EBUSY ; + }else { +struct module *driver_module = + dev->driver->module; + +comedi_device_detach_locked (dev); +module_put (driver_module); + } +up_write (&dev->attach_lock); } -return 0 ; +return rc; }if (copy_from_user (&it, arg,sizeof (it)))
drivers/comedi/comedi_internal.h +1 -0
@@ -50,6 +50,7 @@ extern struct mutex comedi_drivers_list_int insn_inval (struct comedi_device *dev,struct comedi_subdevice *s,struct comedi_insn *insn,unsigned int *data); +void comedi_device_detach_locked (struct comedi_device *dev);void comedi_device_detach (struct comedi_device *dev);int comedi_device_attach (struct comedi_device *dev,struct comedi_devconfig *it);
drivers/comedi/drivers.c +10 -3
@@ -158,7 +158,7 @@ static void comedi_device_detach_cleanupint i;struct comedi_subdevice *s; -lockdep_assert_held (&dev->attach_lock); +lockdep_assert_held_write (&dev->attach_lock);lockdep_assert_held (&dev->mutex);if (dev->subdevices) {for (i =0 ; i < dev->n_subdevices; i++) {
@@ -195,16 +195,23 @@ static void comedi_device_detach_cleanupcomedi_clear_hw_dev (dev); } -void comedi_device_detach (struct comedi_device *dev) +void comedi_device_detach_locked (struct comedi_device *dev) { +lockdep_assert_held_write (&dev->attach_lock);lockdep_assert_held (&dev->mutex);comedi_device_cancel_all (dev); -down_write (&dev->attach_lock); dev->attached = false; dev->detach_count++;if (dev->driver) dev->driver->detach (dev);comedi_device_detach_cleanup (dev); +} + +void comedi_device_detach (struct comedi_device *dev) +{ +lockdep_assert_held (&dev->mutex); +down_write (&dev->attach_lock); +comedi_device_detach_locked (dev);up_write (&dev->attach_lock); }
Greg Kroah-Hartman
maintainerPATCH 307/587 thunderbolt: Fix copy+paste error in match_service_id()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 5cc1f66cb23cccc704e3def27ad31ed479e934a5 upstream.
The second instance of TBSVC_MATCH_PROTOCOL_VERSION seems to have been intended to be TBSVC_MATCH_PROTOCOL_REVISION.
--- drivers/thunderbolt/domain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/thunderbolt/domain.c +1 -1
@@ -36,7 +36,7 @@ static bool match_service_id(const strucreturn false; } -if (id->match_flags &TBSVC_MATCH_PROTOCOL_VERSION ) { +if (id->match_flags &TBSVC_MATCH_PROTOCOL_REVISION ) {if (id->protocol_revision != svc->prtcrevs)return false; }
Greg Kroah-Hartman
maintainerPATCH 308/587 cdc-acm: fix race between initial clearing halt and open
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Neukum <[email protected]>
commit 64690a90cd7c6db16d3af8616be1f4bf8d492850 upstream.
On the devices that need their endpoints to get an initial clear_halt, this needs to be done before the devices can be opened. That means it needs to be before the devices are registered.
--- drivers/usb/class/cdc-acm.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/usb/class/cdc-acm.c +6 -5
@@ -1520,6 +1520,12 @@ skip_countries: goto err_remove_files; } +if (quirks &CLEAR_HALT_CONDITIONS ) { +/* errors intentionally ignored */ +usb_clear_halt (usb_dev, acm->in); +usb_clear_halt (usb_dev, acm->out); + } + tty_dev =tty_port_register_device (&acm->port, acm_tty_driver, minor, &control_interface->dev);if (IS_ERR (tty_dev)) {
@@ -1527,11 +1533,6 @@ skip_countries: goto err_release_data_interface; } -if (quirks &CLEAR_HALT_CONDITIONS ) { -usb_clear_halt (usb_dev, acm->in); -usb_clear_halt (usb_dev, acm->out); - } -dev_info (&intf->dev,"ttyACM%d: USB ACM device\n" , minor);return 0 ;
Greg Kroah-Hartman
maintainerPATCH 309/587 btrfs: zoned: use filesystem size not disk size for reclaim decision
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johannes Thumshirn <[email protected]>
commit 55f7c65b2f69c7e4cb7aa7c1654a228ccf734fd8 upstream.
When deciding if a zoned filesystem is reaching the threshold to reclaim data block groups, look at the size of the filesystem not to potentially total available size of all drives in the filesystem.
Especially if a filesystem was created with mkfs' -b option, constraining it to only a portion of the block device, the numbers won't match and potentially garbage collection is kicking in too late.
--- fs/btrfs/zoned.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/zoned.c +1 -2
@@ -2350,8 +2350,8 @@ bool btrfs_zoned_should_reclaim(struct b {struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;struct btrfs_device *device; +u64 total =btrfs_super_total_bytes (fs_info->super_copy);u64 used =0 ; -u64 total =0 ;u64 factor;ASSERT (btrfs_is_zoned (fs_info));
@@ -2364,7 +2364,6 @@ bool btrfs_zoned_should_reclaim(struct bif (!device->bdev)continue ; - total += device->disk_total_bytes; used += device->bytes_used; }mutex_unlock (&fs_devices->device_list_mutex);
Greg Kroah-Hartman
maintainerPATCH 310/587 btrfs: abort transaction during log replay if walk_log_tree() failed
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
commit 2a5898c4aac67494c2f0f7fe38373c95c371c930 upstream.
If we failed walking a log tree during replay, we have a missing transaction abort to prevent committing a transaction where we didn't fully replay all the changes from a log tree and therefore can leave the respective subvolume tree in some inconsistent state. So add the missing transaction abort.
--- fs/btrfs/tree-log.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
fs/btrfs/tree-log.c +5 -2
@@ -7300,11 +7300,14 @@ again: wc.replay_dest->log_root = log; ret =btrfs_record_root_in_trans (trans, wc.replay_dest); -if (ret) +if (ret) {/* The loop needs to continue due to the root refs */ btrfs_abort_transaction (trans, ret); -else + }else { ret =walk_log_tree (trans, log, &wc); +if (ret) +btrfs_abort_transaction (trans, ret); + }if (!ret && wc.stage ==LOG_WALK_REPLAY_ALL ) { ret = fixup_inode_link_counts(trans, wc.replay_dest,
Greg Kroah-Hartman
maintainerPATCH 311/587 btrfs: zoned: do not remove unwritten non-data block group
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Naohiro Aota <[email protected]>
commit 3061801420469610c8fa6080a950e56770773ef1 upstream.
There are some reports of "unable to find chunk map for logical 2147483648 length 16384" error message appears in dmesg. This means some IOs are occurring after a block group is removed.
When a metadata tree node is cleaned on a zoned setup, we keep that node still dirty and write it out not to create a write hole. However, this can make a block group's used bytes == 0 while there is a dirty region left.
Such an unused block group is moved into the unused_bg list and processed for removal. When the removal succeeds, the block group is removed from the transaction->dirty_bgs list, so the unused dirty nodes in the block group are not sent at the transaction commit time. It will be written at some later time e.g, sync or umount, and causes "unable to find chunk map" errors.
This can happen relatively easy on SMR whose zone size is 256MB. However, calling do_zone_finish() on such block group returns -EAGAIN and keep that block group intact, which is why the issue is hidden until now.
--- fs/btrfs/block-group.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-)
fs/btrfs/block-group.c +25 -2
@@ -34,6 +34,19 @@ int btrfs_should_fragment_free_space(str }#endif +static inline bool has_unwritten_metadata (struct btrfs_block_group *block_group) +{ +/* The meta_write_pointer is available only on the zoned setup. */ +if (!btrfs_is_zoned (block_group->fs_info)) +return false; + +if (block_group->flags &BTRFS_BLOCK_GROUP_DATA ) +return false; + +return block_group->start + block_group->alloc_offset > + block_group->meta_write_pointer; +} +/* * Return target flags in extended format or 0 if restripe for this chunk_type * is not in progress
@@ -1240,6 +1253,15 @@ int btrfs_remove_block_group(struct btrf goto out;spin_lock (&block_group->lock); +/* +* Hitting this WARN means we removed a block group with an unwritten +* region. It will cause "unable to find chunk map for logical" errors. +*/ +if (WARN_ON (has_unwritten_metadata (block_group))) +btrfs_warn (fs_info, +"block group %llu is removed before metadata write out" , + block_group->start); +set_bit (BLOCK_GROUP_FLAG_REMOVED , &block_group->runtime_flags);/*
@@ -1563,8 +1585,9 @@ void btrfs_delete_unused_bgs(struct btrf* needing to allocate extents from the block group. */ used =btrfs_space_info_used (space_info, true); -if (space_info->total_bytes - block_group->length < used && - block_group->zone_unusable < block_group->length) { +if ((space_info->total_bytes - block_group->length < used && + block_group->zone_unusable < block_group->length) || +has_unwritten_metadata (block_group)) {/* * Add a reference for the list, compensate for the ref * drop under the "next" label for the
Greg Kroah-Hartman
maintainerPATCH 312/587 btrfs: clear dirty status from extent buffer on error at insert_new_root()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
commit c0d013495a80cbb53e2288af7ae0ec4170aafd7c upstream.
If we failed to insert the tree mod log operation, we are not removing the dirty status from the allocated and dirtied extent buffer before we free it. Removing the dirty status is needed for several reasons such as to adjust the fs_info->dirty_metadata_bytes counter and remove the dirty status from the respective folios. So add the missing call to btrfs_clear_buffer_dirty().
--- fs/btrfs/ctree.c | 1 + 1 file changed, 1 insertion(+)
fs/btrfs/ctree.c +1 -0
@@ -3049,6 +3049,7 @@ static noinline int insert_new_root(struif (ret <0 ) {int ret2; +btrfs_clear_buffer_dirty (trans, c); ret2 =btrfs_free_tree_block (trans,btrfs_root_id (root), c,0 ,1 );if (ret2 <0 )btrfs_abort_transaction (trans, ret2);
Greg Kroah-Hartman
maintainerPATCH 313/587 btrfs: fix log tree replay failure due to file with 0 links and extents
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Filipe Manana <[email protected]>
commit 0a32e4f0025a74c70dcab4478e9b29c22f5ecf2f upstream.
If we log a new inode (not persisted in a past transaction) that has 0 links and extents, then log another inode with an higher inode number, we end up with failing to replay the log tree with -EINVAL. The steps for this are:
1) create new file A
2) write some data to file A
3) open an fd on file A
4) unlink file A
5) fsync file A using the previously open fd
6) create file B (has higher inode number than file A)
7) fsync file B
8) power fail before current transaction commits
Now when attempting to mount the fs, the log replay will fail with -ENOENT at replay_one_extent() when attempting to replay the first extent of file A. The failure comes when trying to open the inode for file A in the subvolume tree, since it doesn't exist.
Before commit 5f61b961599a ("btrfs: fix inode lookup error handling during log replay"), the returned error was -EIO instead of -ENOENT, since we converted any errors when attempting to read an inode during log replay to -EIO.
The reason for this is that the log replay procedure fails to ignore the current inode when we are at the stage LOG_WALK_REPLAY_ALL, our current inode has 0 links and last inode we processed in the previous stage has a non 0 link count. In other words, the issue is that at replay_one_extent() we only update wc->ignore_cur_inode if the current replay stage is LOG_WALK_REPLAY_INODES.
Fix this by updating wc->ignore_cur_inode whenever we find an inode item regardless of the current replay stage. This is a simple solution and easy to backport, but later we can do other alternatives like avoid logging extents or inode items other than the inode item for inodes with a link count of 0.
The problem with the wc->ignore_cur_inode logic has been around since commit f2d72f42d5fa ("Btrfs: fix warning when replaying log after fsync of a tmpfile") but it only became frequent to hit since the more recent commit 5e85262e542d ("btrfs: fix fsync of files with no hard links not persisting deletion"), because we stopped skipping inodes with a link count of 0 when logging, while before the problem would only be triggered if trying to replay a log tree created with an older kernel which has a logged inode with 0 links.
A test case for fstests will be submitted soon.
--- fs/btrfs/tree-log.c | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-)
fs/btrfs/tree-log.c +30 -18
@@ -326,8 +326,7 @@ struct walk_control {/* * Ignore any items from the inode currently being processed. Needs -* to be set every time we find a BTRFS_INODE_ITEM_KEY and we are in -* the LOG_WALK_REPLAY_INODES stage. +* to be set every time we find a BTRFS_INODE_ITEM_KEY. */ bool ignore_cur_inode;
@@ -2498,23 +2497,30 @@ static int replay_one_buffer(struct btrf nritems =btrfs_header_nritems (eb);for (i =0 ; i < nritems; i++) { -btrfs_item_key_to_cpu (eb, &key, i); +struct btrfs_inode_item *inode_item; -/* inode keys are done during the first stage */ -if (key.type ==BTRFS_INODE_ITEM_KEY && - wc->stage ==LOG_WALK_REPLAY_INODES ) { -struct btrfs_inode_item *inode_item; -u32 mode; +btrfs_item_key_to_cpu (eb, &key, i); - inode_item =btrfs_item_ptr (eb, i, - struct btrfs_inode_item); +if (key.type ==BTRFS_INODE_ITEM_KEY ) { + inode_item = btrfs_item_ptr(eb, i, struct btrfs_inode_item);/* -* If we have a tmpfile (O_TMPFILE) that got fsync'ed -* and never got linked before the fsync, skip it, as -* replaying it is pointless since it would be deleted -* later. We skip logging tmpfiles, but it's always -* possible we are replaying a log created with a kernel -* that used to log tmpfiles. +* An inode with no links is either: +* +* 1) A tmpfile (O_TMPFILE) that got fsync'ed and never +* got linked before the fsync, skip it, as replaying +* it is pointless since it would be deleted later. +* We skip logging tmpfiles, but it's always possible +* we are replaying a log created with a kernel that +* used to log tmpfiles; +* +* 2) A non-tmpfile which got its last link deleted +* while holding an open fd on it and later got +* fsynced through that fd. We always log the +* parent inodes when inode->last_unlink_trans is +* set to the current transaction, so ignore all the +* inode items for this inode. We will delete the +* inode when processing the parent directory with +* replay_dir_deletes(). */ if (btrfs_inode_nlink (eb, inode_item) ==0 ) { wc->ignore_cur_inode = true;
@@ -2522,8 +2528,14 @@ static int replay_one_buffer(struct btrf }else { wc->ignore_cur_inode = false; } - ret =replay_xattr_deletes (wc->trans, root, log, - path, key.objectid); + } + +/* Inode keys are done during the first stage. */ +if (key.type ==BTRFS_INODE_ITEM_KEY && + wc->stage ==LOG_WALK_REPLAY_INODES ) { +u32 mode; + + ret =replay_xattr_deletes (wc->trans, root, log, path, key.objectid);if (ret)break ; mode =btrfs_inode_mode (eb, inode_item);
Greg Kroah-Hartman
maintainerPATCH 314/587 btrfs: zoned: do not select metadata BG as finish target
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Naohiro Aota <[email protected]>
commit 3a931e9b39c7ff8066657042f5f00d3b7e6ad315 upstream.
We call btrfs_zone_finish_one_bg() to zone finish one block group and make room to activate another block group. Currently, we can choose a metadata block group as a target. But, as we reserve an active metadata block group, we no longer want to select a metadata block group. So, skip it in the loop.
--- fs/btrfs/zoned.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/zoned.c +1 -1
@@ -2417,7 +2417,7 @@ int btrfs_zone_finish_one_bg(struct btrfspin_lock (&block_group->lock);if (block_group->reserved || block_group->alloc_offset ==0 || - (block_group->flags &BTRFS_BLOCK_GROUP_SYSTEM ) || + !(block_group->flags &BTRFS_BLOCK_GROUP_DATA ) ||test_bit (BLOCK_GROUP_FLAG_ZONED_DATA_RELOC , &block_group->runtime_flags)) {spin_unlock (&block_group->lock);continue ;
Greg Kroah-Hartman
maintainerPATCH 315/587 btrfs: do not allow relocation of partially dropped subvolumes
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
commit 4289b494ac553e74e86fed1c66b2bf9530bc1082 upstream.
[BUG]
There is an internal report that balance triggered transaction abort, with the following call trace:
item 85 key (594509824 169 0) itemoff 12599 itemsize 33
extent refs 1 gen 197740 flags 2
ref#0: tree block backref root 7
item 86 key (594558976 169 0) itemoff 12566 itemsize 33
extent refs 1 gen 197522 flags 2
ref#0: tree block backref root 7
...
BTRFS error (device loop0): extent item not found for insert, bytenr 594526208 num_bytes 16384 parent 449921024 root_objectid 934 owner 1 offset 0 BTRFS error (device loop0): failed to run delayed ref for logical 594526208 num_bytes 16384 type 182 action 1 ref_mod 1: -117
------------[ cut here ]------------ BTRFS: Transaction aborted (error -117) WARNING: CPU: 1 PID: 6963 at ../fs/btrfs/extent-tree.c:2168 btrfs_run_delayed_refs+0xfa/0x110 [btrfs]
And btrfs check doesn't report anything wrong related to the extent tree.
[CAUSE]
The cause is a little complex, firstly the extent tree indeed doesn't have the backref for 594526208.
The extent tree only have the following two backrefs around that bytenr on-disk:
item 65 key (594509824 METADATA_ITEM 0) itemoff 13880 itemsize 33
refs 1 gen 197740 flags TREE_BLOCK
tree block skinny level 0
(176 0x7) tree block backref root CSUM_TREE
item 66 key (594558976 METADATA_ITEM 0) itemoff 13847 itemsize 33
refs 1 gen 197522 flags TREE_BLOCK
tree block skinny level 0
(176 0x7) tree block backref root CSUM_TREE
But the such missing backref item is not an corruption on disk, as the offending delayed ref belongs to subvolume 934, and that subvolume is being dropped:
item 0 key (934 ROOT_ITEM 198229) itemoff 15844 itemsize 439
generation 198229 root_dirid 256 bytenr 10741039104 byte_limit 0 bytes_used 345571328
last_snapshot 198229 flags 0x1000000000001(RDONLY) refs 0
drop_progress key (206324 EXTENT_DATA 2711650304) drop_level 2
level 2 generation_v2 198229And that offending tree block 594526208 is inside the dropped range of that subvolume. That explains why there is no backref item for that bytenr and why btrfs check is not reporting anything wrong.
But this also shows another problem, as btrfs will do all the orphan subvolume cleanup at a read-write mount.
So half-dropped subvolume should not exist after an RW mount, and balance itself is also exclusive to subvolume cleanup, meaning we shouldn't hit a subvolume half-dropped during relocation.
The root cause is, there is no orphan item for this subvolume. In fact there are 5 subvolumes from around 2021 that have the same problem.
It looks like the original report has some older kernels running, and caused those zombie subvolumes.
Thankfully upstream commit 8d488a8c7ba2 ("btrfs: fix subvolume/snapshot deletion not triggered on mount") has long fixed the bug.
[ENHANCEMENT]
For repairing such old fs, btrfs-progs will be enhanced.
Considering how delayed the problem will show up (at run delayed ref time) and at that time we have to abort transaction already, it is too late.
Instead here we reject any half-dropped subvolume for reloc tree at the earliest time, preventing confusion and extra time wasted on debugging similar bugs.
--- fs/btrfs/relocation.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
fs/btrfs/relocation.c +19 -0
@@ -693,6 +693,25 @@ static struct btrfs_root *create_reloc_rif (root->root_key.objectid == objectid) {u64 commit_root_gen; +/* +* Relocation will wait for cleaner thread, and any half-dropped +* subvolume will be fully cleaned up at mount time. +* So here we shouldn't hit a subvolume with non-zero drop_progress. +* +* If this isn't the case, error out since it can make us attempt to +* drop references for extents that were already dropped before. +*/ +if (unlikely (btrfs_disk_key_objectid (&root->root_item.drop_progress))) { +struct btrfs_key cpu_key; + +btrfs_disk_key_to_cpu (&cpu_key, &root->root_item.drop_progress); +btrfs_err (fs_info, +"cannot relocate partially dropped subvolume %llu, drop progress key (%llu %u %llu)" , + objectid, cpu_key.objectid, cpu_key.type, cpu_key.offset); + ret = -EUCLEAN ; + goto fail; + } +/* called by btrfs_init_reloc_root */ ret =btrfs_copy_root (trans, root, root->commit_root, &eb,BTRFS_TREE_RELOC_OBJECTID );
Greg Kroah-Hartman
maintainerPATCH 316/587 fbdev: Fix vmalloc out-of-bounds write in fast_imageblit
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sravan Kumar Gundu <[email protected]>
commit af0db3c1f898144846d4c172531a199bb3ca375d upstream.
This issue triggers when a userspace program does an ioctl FBIOPUT_CON2FBMAP by passing console number and frame buffer number. Ideally this maps console to frame buffer and updates the screen if console is visible.
As part of mapping it has to do resize of console according to frame buffer info. if this resize fails and returns from vc_do_resize() and continues further. At this point console and new frame buffer are mapped and sets display vars. Despite failure still it continue to proceed updating the screen at later stages where vc_data is related to previous frame buffer and frame buffer info and display vars are mapped to new frame buffer and eventully leading to out-of-bounds write in fast_imageblit(). This bheviour is excepted only when fg_console is equal to requested console which is a visible console and updates screen with invalid struct references in fbcon_putcs().
--- drivers/video/fbdev/core/fbcon.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/video/fbdev/core/fbcon.c +5 -4
@@ -808,7 +808,8 @@ static void con2fb_init_display(struct v fg_vc->vc_rows); } -update_screen (vc_cons[fg_console].d); +if (fg_console != unit) +update_screen (vc_cons[fg_console].d); }/**
@@ -1353,6 +1354,7 @@ static void fbcon_set_disp(struct fb_infstruct vc_data *svc;struct fbcon_ops *ops = info->fbcon_par;int rows, cols; +unsigned long ret =0 ; p = &fb_display[unit];
@@ -1403,11 +1405,10 @@ static void fbcon_set_disp(struct fb_inf rows =FBCON_SWAP (ops->rotate, info->var.yres, info->var.xres); cols /= vc->vc_font.width; rows /= vc->vc_font.height; -vc_resize (vc, cols, rows); + ret =vc_resize (vc, cols, rows); -if (con_is_visible (vc)) { +if (con_is_visible (vc) && !ret)update_screen (vc); - } }static __inline__void ywrap_up (struct vc_data *vc,int count)
Greg Kroah-Hartman
maintainerPATCH 317/587 hv_netvsc: Fix panic during namespace deletion with VF
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haiyang Zhang <[email protected]>
commit 33caa208dba6fa639e8a92fd0c8320b652e5550c upstream.
The existing code move the VF NIC to new namespace when NETDEV_REGISTER is received on netvsc NIC. During deletion of the namespace, default_device_exit_batch() >> default_device_exit_net() is called. When netvsc NIC is moved back and registered to the default namespace, it automatically brings VF NIC back to the default namespace. This will cause the default_device_exit_net() >> for_each_netdev_safe loop unable to detect the list end, and hit NULL ptr:
[ 231.449420] mana 7870:00:00.0 enP30832s1: Moved VF to namespace with: eth0 [ 231.449656] BUG: kernel NULL pointer dereference, address: 0000000000000010 [ 231.450246] #PF: supervisor read access in kernel mode [ 231.450579] #PF: error_code(0x0000) - not-present page [ 231.450916] PGD 17b8a8067 P4D 0 [ 231.451163] Oops: Oops: 0000 [#1] SMP NOPTI [ 231.451450] CPU: 82 UID: 0 PID: 1394 Comm: kworker/u768:1 Not tainted 6.16.0-rc4+ #3 VOLUNTARY [ 231.452042] Hardware name: Microsoft Corporation Virtual Machine/Virtual Machine, BIOS Hyper-V UEFI Release v4.1 11/21/2024 [ 231.452692] Workqueue: netns cleanup_net [ 231.452947] RIP: 0010:default_device_exit_batch+0x16c/0x3f0 [ 231.453326] Code: c0 0c f5 b3 e8 d5 db fe ff 48 85 c0 74 15 48 c7 c2 f8 fd ca b2 be 10 00 00 00 48 8d 7d c0 e8 7b 77 25 00 49 8b 86 28 01 00 00 <48> 8b 50 10 4c 8b 2a 4c 8d 62 f0 49 83 ed 10 4c 39 e0 0f 84 d6 00 [ 231.454294] RSP: 0018:ff75fc7c9bf9fd00 EFLAGS: 00010246 [ 231.454610] RAX: 0000000000000000 RBX: 0000000000000002 RCX: 61c8864680b583eb [ 231.455094] RDX: ff1fa9f71462d800 RSI: ff75fc7c9bf9fd38 RDI: 0000000030766564 [ 231.455686] RBP: ff75fc7c9bf9fd78 R08: 0000000000000000 R09: 0000000000000000 [ 231.456126] R10: 0000000000000001 R11: 0000000000000004 R12: ff1fa9f70088e340 [ 231.456621] R13: ff1fa9f70088e340 R14: ffffffffb3f50c20 R15: ff1fa9f7103e6340 [ 231.457161] FS: 0000000000000000(0000) GS:ff1faa6783a08000(0000) knlGS:0000000000000000 [ 231.457707] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 231.458031] CR2: 0000000000000010 CR3: 0000000179ab2006 CR4: 0000000000b73ef0 [ 231.458434] Call Trace: [ 231.458600] <TASK> [ 231.458777] ops_undo_list+0x100/0x220 [ 231.459015] cleanup_net+0x1b8/0x300 [ 231.459285] process_one_work+0x184/0x340
To fix it, move the ns change to a workqueue, and take rtnl_lock to avoid changing the netdev list when default_device_exit_net() is using it.
--- drivers/net/hyperv/hyperv_net.h | 3 +++ drivers/net/hyperv/netvsc_drv.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-)
drivers/net/hyperv/hyperv_net.h +3 -0
@@ -1061,6 +1061,7 @@ struct net_device_context {struct net_device __rcu *vf_netdev;struct netvsc_vf_pcpu_stats __percpu *vf_stats;struct delayed_work vf_takeover; +struct delayed_work vfns_work;/* 1: allocated, serial number is valid. 0: not allocated */ u32 vf_alloc;
@@ -1075,6 +1076,8 @@ struct net_device_context {struct netvsc_device_info *saved_netvsc_dev_info; }; +void netvsc_vfns_work (struct work_struct *w); +/* Azure hosts don't support non-TCP port numbers in hashing for fragmented * packets. We can use ethtool to change UDP hash level when necessary. */
drivers/net/hyperv/netvsc_drv.c +28 -1
@@ -2513,6 +2513,7 @@ static int netvsc_probe(struct hv_devicespin_lock_init (&net_device_ctx->lock);INIT_LIST_HEAD (&net_device_ctx->reconfig_events);INIT_DELAYED_WORK (&net_device_ctx->vf_takeover, netvsc_vf_setup); +INIT_DELAYED_WORK (&net_device_ctx->vfns_work, netvsc_vfns_work); net_device_ctx->vf_stats = netdev_alloc_pcpu_stats(struct netvsc_vf_pcpu_stats);
@@ -2655,6 +2656,8 @@ static void netvsc_remove(struct hv_devicancel_delayed_work_sync (&ndev_ctx->dwork);rtnl_lock (); +cancel_delayed_work_sync (&ndev_ctx->vfns_work); + nvdev =rtnl_dereference (ndev_ctx->nvdev);if (nvdev) {cancel_work_sync (&nvdev->subchan_work);
@@ -2696,6 +2699,7 @@ static int netvsc_suspend(struct hv_devicancel_delayed_work_sync (&ndev_ctx->dwork);rtnl_lock (); +cancel_delayed_work_sync (&ndev_ctx->vfns_work); nvdev =rtnl_dereference (ndev_ctx->nvdev);if (nvdev ==NULL ) {
@@ -2789,6 +2793,27 @@ static void netvsc_event_set_vf_ns(struc } } +void netvsc_vfns_work (struct work_struct *w) +{ +struct net_device_context *ndev_ctx = + container_of(w, struct net_device_context, vfns_work.work); +struct net_device *ndev; + +if (!rtnl_trylock ()) { +schedule_delayed_work (&ndev_ctx->vfns_work,1 ); +return ; + } + + ndev =hv_get_drvdata (ndev_ctx->device_ctx); +if (!ndev) + goto out; + +netvsc_event_set_vf_ns (ndev); + +out: +rtnl_unlock (); +} +/* * On Hyper-V, every VF interface is matched with a corresponding * synthetic interface. The synthetic interface is presented first
@@ -2799,10 +2824,12 @@ static int netvsc_netdev_event(struct no unsigned long event, void *ptr) { struct net_device *event_dev = netdev_notifier_info_to_dev(ptr); +struct net_device_context *ndev_ctx;int ret =0 ;if (event_dev->netdev_ops == &device_ops && event ==NETDEV_REGISTER ) { -netvsc_event_set_vf_ns (event_dev); + ndev_ctx =netdev_priv (event_dev); +schedule_delayed_work (&ndev_ctx->vfns_work,0 );return NOTIFY_DONE ; }
Greg Kroah-Hartman
maintainerPATCH 318/587 parisc: Makefile: fix a typo in palo.conf
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Randy Dunlap <[email protected]>
commit 963f1b20a8d2a098954606b9725cd54336a2a86c upstream.
Correct "objree" to "objtree". "objree" is not defined.
--- arch/parisc/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/parisc/Makefile +1 -1
@@ -139,7 +139,7 @@ palo lifimage: vmlinuz fi @if test ! -f "$(PALOCONF)"; then \ cp $(srctree)/arch/parisc/defpalo.conf $(objtree)/palo.conf; \ - echo 'A generic palo config file ($(objree)/palo.conf) has been created for you.'; \ + echo 'A generic palo config file ($(objtree)/palo.conf) has been created for you.'; \ echo 'You should check it and re-run "make palo".'; \ echo 'WARNING: the "lifimage" file is now placed in this directory by default!'; \ false; \
Greg Kroah-Hartman
maintainerPATCH 319/587 mm/kmemleak: avoid soft lockup in __kmemleak_do_cleanup()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Waiman Long <[email protected]>
commit d1534ae23c2b6be350c8ab060803fbf6e9682adc upstream.
A soft lockup warning was observed on a relative small system x86-64 system with 16 GB of memory when running a debug kernel with kmemleak enabled.
watchdog: BUG: soft lockup - CPU#8 stuck for 33s! [kworker/8:1:134]
The test system was running a workload with hot unplug happening in parallel. Then kemleak decided to disable itself due to its inability to allocate more kmemleak objects. The debug kernel has its CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE set to 40,000.
The soft lockup happened in kmemleak_do_cleanup() when the existing kmemleak objects were being removed and deleted one-by-one in a loop via a workqueue. In this particular case, there are at least 40,000 objects that need to be processed and given the slowness of a debug kernel and the fact that a raw_spinlock has to be acquired and released in __delete_object(), it could take a while to properly handle all these objects.
As kmemleak has been disabled in this case, the object removal and deletion process can be further optimized as locking isn't really needed. However, it is probably not worth the effort to optimize for such an edge case that should rarely happen. So the simple solution is to call cond_resched() at periodic interval in the iteration loop to avoid soft lockup.
--- mm/kmemleak.c | 5 +++++ 1 file changed, 5 insertions(+)
mm/kmemleak.c +5 -0
@@ -2006,6 +2006,7 @@ static const struct file_operations kmemstatic void __kmemleak_do_cleanup (void ) {struct kmemleak_object *object, *tmp; +unsigned int cnt =0 ;/* * Kmemleak has already been disabled, no need for RCU list traversal
@@ -2014,6 +2015,10 @@ static void __kmemleak_do_cleanup(void)list_for_each_entry_safe (object, tmp, &object_list, object_list) {__remove_object (object);__delete_object (object); + +/* Call cond_resched() once per 64 iterations to avoid soft lockup */ +if (!(++cnt &0x3f )) +cond_resched (); } }
Greg Kroah-Hartman
maintainerPATCH 320/587 mm/kmemleak: avoid deadlock by moving pr_warn() outside kmemleak_lock
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
commit 47b0f6d8f0d2be4d311a49e13d2fd5f152f492b2 upstream.
When netpoll is enabled, calling pr_warn_once() while holding kmemleak_lock in mem_pool_alloc() can cause a deadlock due to lock inversion with the netconsole subsystem. This occurs because pr_warn_once() may trigger netpoll, which eventually leads to __alloc_skb() and back into kmemleak code, attempting to reacquire kmemleak_lock.
This is the path for the deadlock.
mem_pool_alloc()
-> raw_spin_lock_irqsave(&kmemleak_lock, flags);
-> pr_warn_once()
-> netconsole subsystem
-> netpoll
-> __alloc_skb
-> __create_object
-> raw_spin_lock_irqsave(&kmemleak_lock, flags);Fix this by setting a flag and issuing the pr_warn_once() after kmemleak_lock is released.
--- mm/kmemleak.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
mm/kmemleak.c +4 -1
@@ -452,6 +452,7 @@ static struct kmemleak_object *mem_pool_ {unsigned long flags;struct kmemleak_object *object; +bool warn = false;/* try the slab allocator first */ if (object_cache) {
@@ -469,8 +470,10 @@ static struct kmemleak_object *mem_pool_else if (mem_pool_free_count) object = &mem_pool[--mem_pool_free_count];else -pr_warn_once ("Memory pool empty, consider increasing CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE\n" ); + warn = true;raw_spin_unlock_irqrestore (&kmemleak_lock, flags); +if (warn) +pr_warn_once ("Memory pool empty, consider increasing CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE\n" );return object; }
Greg Kroah-Hartman
maintainerPATCH 321/587 media: uvcvideo: Fix 1-byte out-of-bounds read in uvc_parse_format()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Youngjun Lee <[email protected]>
commit 782b6a718651eda3478b1824b37a8b3185d2740c upstream.
The buffer length check before calling uvc_parse_format() only ensured that the buffer has at least 3 bytes (buflen > 2), buf the function accesses buffer[3], requiring at least 4 bytes.
This can lead to an out-of-bounds read if the buffer has exactly 3 bytes.
Fix it by checking that the buffer has at least 4 bytes in uvc_parse_format().
--- drivers/media/usb/uvc/uvc_driver.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/media/usb/uvc/uvc_driver.c +3 -0
@@ -235,6 +235,9 @@ static int uvc_parse_format(struct uvc_dunsigned int i, n;u8 ftype; +if (buflen <4 ) +return -EINVAL ; + format->type = buffer[2 ]; format->index = buffer[3 ]; format->frames = frames;
Greg Kroah-Hartman
maintainerPATCH 322/587 media: venus: Fix OOB read due to missing payload bound check
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vedang Nagar <[email protected]>
commit 06d6770ff0d8cc8dfd392329a8cc03e2a83e7289 upstream.
Currently, The event_seq_changed() handler processes a variable number of properties sent by the firmware. The number of properties is indicated by the firmware and used to iterate over the payload. However, the payload size is not being validated against the actual message length.
This can lead to out-of-bounds memory access if the firmware provides a property count that exceeds the data available in the payload. Such a condition can result in kernel crashes or potential information leaks if memory beyond the buffer is accessed.
Fix this by properly validating the remaining size of the payload before each property access and updating bounds accordingly as properties are parsed.
This ensures that property parsing is safely bounded within the received message buffer and protects against malformed or malicious firmware behavior.
--- drivers/media/platform/qcom/venus/hfi_msgs.c | 83 ++++++++++++++++++--------- 1 file changed, 58 insertions(+), 25 deletions(-)
drivers/media/platform/qcom/venus/hfi_msgs.c +58 -25
@@ -33,8 +33,9 @@ static void event_seq_changed(struct venstruct hfi_buffer_requirements *bufreq;struct hfi_extradata_input_crop *crop;struct hfi_dpb_counts *dpb_count; +u32 ptype, rem_bytes; +u32 size_read =0 ;u8 *data_ptr; -u32 ptype; inst->error =HFI_ERR_NONE ;
@@ -44,86 +45,118 @@ static void event_seq_changed(struct venbreak ;default : inst->error =HFI_ERR_SESSION_INVALID_PARAMETER ; - goto done; + inst->ops->event_notify (inst,EVT_SYS_EVENT_CHANGE , &event); +return ; } event.event_type = pkt->event_data1; num_properties_changed = pkt->event_data2; -if (!num_properties_changed) { - inst->error =HFI_ERR_SESSION_INSUFFICIENT_RESOURCES ; - goto done; - } +if (!num_properties_changed) + goto error; data_ptr = (u8 *)&pkt->ext_event_data[0 ]; + rem_bytes = pkt->shdr.hdr.size -sizeof (*pkt); +do { +if (rem_bytes <sizeof (u32)) + goto error; ptype = *((u32 *)data_ptr); + + data_ptr +=sizeof (u32); + rem_bytes -=sizeof (u32); +switch (ptype) {case HFI_PROPERTY_PARAM_FRAME_SIZE : - data_ptr +=sizeof (u32); +if (rem_bytes <sizeof (struct hfi_framesize )) + goto error; + frame_sz = (struct hfi_framesize *)data_ptr; event.width = frame_sz->width; event.height = frame_sz->height; - data_ptr +=sizeof (*frame_sz); + size_read =sizeof (struct hfi_framesize );break ;case HFI_PROPERTY_PARAM_PROFILE_LEVEL_CURRENT : - data_ptr +=sizeof (u32); +if (rem_bytes <sizeof (struct hfi_profile_level )) + goto error; + profile_level = (struct hfi_profile_level *)data_ptr; event.profile = profile_level->profile; event.level = profile_level->level; - data_ptr +=sizeof (*profile_level); + size_read =sizeof (struct hfi_profile_level );break ;case HFI_PROPERTY_PARAM_VDEC_PIXEL_BITDEPTH : - data_ptr +=sizeof (u32); +if (rem_bytes <sizeof (struct hfi_bit_depth )) + goto error; + pixel_depth = (struct hfi_bit_depth *)data_ptr; event.bit_depth = pixel_depth->bit_depth; - data_ptr +=sizeof (*pixel_depth); + size_read =sizeof (struct hfi_bit_depth );break ;case HFI_PROPERTY_PARAM_VDEC_PIC_STRUCT : - data_ptr +=sizeof (u32); +if (rem_bytes <sizeof (struct hfi_pic_struct )) + goto error; + pic_struct = (struct hfi_pic_struct *)data_ptr; event.pic_struct = pic_struct->progressive_only; - data_ptr +=sizeof (*pic_struct); + size_read =sizeof (struct hfi_pic_struct );break ;case HFI_PROPERTY_PARAM_VDEC_COLOUR_SPACE : - data_ptr +=sizeof (u32); +if (rem_bytes <sizeof (struct hfi_colour_space )) + goto error; + colour_info = (struct hfi_colour_space *)data_ptr; event.colour_space = colour_info->colour_space; - data_ptr +=sizeof (*colour_info); + size_read =sizeof (struct hfi_colour_space );break ;case HFI_PROPERTY_CONFIG_VDEC_ENTROPY : - data_ptr +=sizeof (u32); +if (rem_bytes <sizeof (u32)) + goto error; + event.entropy_mode = *(u32 *)data_ptr; - data_ptr +=sizeof (u32); + size_read =sizeof (u32);break ;case HFI_PROPERTY_CONFIG_BUFFER_REQUIREMENTS : - data_ptr +=sizeof (u32); +if (rem_bytes <sizeof (struct hfi_buffer_requirements )) + goto error; + bufreq = (struct hfi_buffer_requirements *)data_ptr; event.buf_count =hfi_bufreq_get_count_min (bufreq, ver); - data_ptr +=sizeof (*bufreq); + size_read =sizeof (struct hfi_buffer_requirements );break ;case HFI_INDEX_EXTRADATA_INPUT_CROP : - data_ptr +=sizeof (u32); +if (rem_bytes <sizeof (struct hfi_extradata_input_crop )) + goto error; + crop = (struct hfi_extradata_input_crop *)data_ptr; event.input_crop.left = crop->left; event.input_crop.top = crop->top; event.input_crop.width = crop->width; event.input_crop.height = crop->height; - data_ptr +=sizeof (*crop); + size_read =sizeof (struct hfi_extradata_input_crop );break ;case HFI_PROPERTY_PARAM_VDEC_DPB_COUNTS : - data_ptr +=sizeof (u32); +if (rem_bytes <sizeof (struct hfi_dpb_counts )) + goto error; + dpb_count = (struct hfi_dpb_counts *)data_ptr; event.buf_count = dpb_count->fw_min_cnt; - data_ptr +=sizeof (*dpb_count); + size_read =sizeof (struct hfi_dpb_counts );break ;default : + size_read =0 ;break ; } + data_ptr += size_read; + rem_bytes -= size_read; num_properties_changed--; }while (num_properties_changed >0 ); -done: + inst->ops->event_notify (inst,EVT_SYS_EVENT_CHANGE , &event); +return ; + +error: + inst->error =HFI_ERR_SESSION_INSUFFICIENT_RESOURCES ; inst->ops->event_notify (inst,EVT_SYS_EVENT_CHANGE , &event); }
Greg Kroah-Hartman
maintainerPATCH 323/587 media: uvcvideo: Do not mark valid metadata as invalid
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Ribalda <[email protected]>
commit bda2859bff0b9596a19648f3740c697ce4c71496 upstream.
Currently, the driver performs a length check of the metadata buffer before the actual metadata size is known and before the metadata is decided to be copied. This results in valid metadata buffers being incorrectly marked as invalid.
Move the length check to occur after the metadata size is determined and is decided to be copied.
--- drivers/media/usb/uvc/uvc_video.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/media/usb/uvc/uvc_video.c +6 -6
@@ -1414,12 +1414,6 @@ static void uvc_video_decode_meta(structif (!meta_buf || length ==2 )return ; -if (meta_buf->length - meta_buf->bytesused < - length +sizeof (meta->ns) +sizeof (meta->sof)) { - meta_buf->error =1 ; -return ; - } - has_pts = mem[1 ] &UVC_STREAM_PTS ; has_scr = mem[1 ] &UVC_STREAM_SCR ;
@@ -1440,6 +1434,12 @@ static void uvc_video_decode_meta(struct !memcmp(scr, stream->clock.last_scr, 6)))return ; +if (meta_buf->length - meta_buf->bytesused < + length +sizeof (meta->ns) +sizeof (meta->sof)) { + meta_buf->error =1 ; +return ; + } + meta = (struct uvc_meta_buf *)((u8 *)meta_buf->mem + meta_buf->bytesused);local_irq_save (flags); time =uvc_video_get_time ();
Greg Kroah-Hartman
maintainerPATCH 324/587 tools/nolibc: fix spelling of FD_SETBITMASK in FD_* macros
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Willy Tarreau <[email protected]>
commit a477629baa2a0e9991f640af418e8c973a1c08e3 upstream.
While nolibc-test does test syscalls, it doesn't test as much the rest of the macros, and a wrong spelling of FD_SETBITMASK in commit feaf75658783a broke programs using either FD_SET() or FD_CLR() without being noticed. Let's fix these macros.
--- tools/include/nolibc/types.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/include/nolibc/types.h +2 -2
@@ -128,7 +128,7 @@ typedef struct {int __fd = (fd); \if (__fd >=0 ) \ __set->fds[__fd /FD_SETIDXMASK ] &= \ - ~(1U << (__fd &FX_SETBITMASK )); \ + ~(1U << (__fd &FD_SETBITMASK )); \ } while (0)#define FD_SET (fd, set) do { \
@@ -145,7 +145,7 @@ typedef struct {int __r =0 ; \if (__fd >=0 ) \ __r = !!(__set->fds[__fd /FD_SETIDXMASK ] & \ -1U << (__fd &FD_SET_BITMASK )); \ +1U << (__fd &FD_SETBITMASK )); \ __r; \ })
Greg Kroah-Hartman
maintainerPATCH 325/587 RDMA/siw: Fix the sendmsg byte count in siw_tcp_sendpages
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Pedro Falcato <[email protected]>
commit c18646248fed07683d4cee8a8af933fc4fe83c0d upstream.
Ever since commit c2ff29e99a76 ("siw: Inline do_tcp_sendpages()"), we have been doing this:
static int siw_tcp_sendpages(struct socket *s, struct page **page, int offset,
size_t size)
[...]
/* Calculate the number of bytes we need to push, for this page
* specifically */
size_t bytes = min_t(size_t, PAGE_SIZE - offset, size);
/* If we can't splice it, then copy it in, as normal */
if (!sendpage_ok(page[i]))
msg.msg_flags &= ~MSG_SPLICE_PAGES;
/* Set the bvec pointing to the page, with len $bytes */
bvec_set_page(&bvec, page[i], bytes, offset);
/* Set the iter to $size, aka the size of the whole sendpages (!!!) */
iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, &bvec, 1, size);
try_page_again:
lock_sock(sk);
/* Sendmsg with $size size (!!!) */
rv = tcp_sendmsg_locked(sk, &msg, size);This means we've been sending oversized iov_iters and tcp_sendmsg calls for a while. This has a been a benign bug because sendpage_ok() always returned true. With the recent slab allocator changes being slowly introduced into next (that disallow sendpage on large kmalloc allocations), we have recently hit out-of-bounds crashes, due to slight differences in iov_iter behavior between the MSG_SPLICE_PAGES and "regular" copy paths:
(MSG_SPLICE_PAGES)skb_splice_from_iter
iov_iter_extract_pages
iov_iter_extract_bvec_pages
uses i->nr_segs to correctly stop in its tracks before OoB'ing everywhere skb_splice_from_iter gets a "short" read
(!MSG_SPLICE_PAGES)skb_copy_to_page_nocache copy=iov_iter_count
[...]
copy_from_iter
/* this doesn't help */
if (unlikely(iter->count < len))
len = iter->count;
iterate_bvec
... and we run off the bvecsFix this by properly setting the iov_iter's byte count, plus sending the correct byte count to tcp_sendmsg_locked.
--- drivers/infiniband/sw/siw/siw_qp_tx.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/infiniband/sw/siw/siw_qp_tx.c +2 -3
@@ -340,18 +340,17 @@ static int siw_tcp_sendpages(struct sockif (!sendpage_ok (page[i])) msg.msg_flags &= ~MSG_SPLICE_PAGES ;bvec_set_page (&bvec, page[i], bytes, offset); -iov_iter_bvec (&msg.msg_iter,ITER_SOURCE , &bvec,1 , size); +iov_iter_bvec (&msg.msg_iter,ITER_SOURCE , &bvec,1 , bytes); try_page_again:lock_sock (sk); - rv =tcp_sendmsg_locked (sk, &msg, size); + rv =tcp_sendmsg_locked (sk, &msg, bytes);release_sock (sk);if (rv >0 ) { size -= rv; sent += rv;if (rv != bytes) { - offset += rv; bytes -= rv; goto try_page_again; }
Greg Kroah-Hartman
maintainerPATCH 326/587 HID: magicmouse: avoid setting up battery timer when not needed
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aditya Garg <[email protected]>
commit 9bdc30e35cbc1aa78ccf01040354209f1e11ca22 upstream.
Currently, the battery timer is set up for all devices using hid-magicmouse, irrespective of whether they actually need it or not.
The current implementation requires the battery timer for Magic Mouse 2 and Magic Trackpad 2 when connected via USB only. Add checks to ensure that the battery timer is only set up when they are connected via USB.
---
--- drivers/hid/hid-magicmouse.c | 58 ++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 20 deletions(-)
drivers/hid/hid-magicmouse.c +38 -20
@@ -772,16 +772,30 @@ static void magicmouse_enable_mt_work(sthid_err (msc->hdev,"unable to request touch data (%d)\n" , ret); } +static bool is_usb_magicmouse2 (__u32 vendor,__u32 product) +{ +if (vendor !=USB_VENDOR_ID_APPLE ) +return false; +return product ==USB_DEVICE_ID_APPLE_MAGICMOUSE2 ; +} + +static bool is_usb_magictrackpad2 (__u32 vendor,__u32 product) +{ +if (vendor !=USB_VENDOR_ID_APPLE ) +return false; +return product ==USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 || + product ==USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC ; +} +static int magicmouse_fetch_battery (struct hid_device *hdev) {#ifdef CONFIG_HID_BATTERY_STRENGTH struct hid_report_enum *report_enum;struct hid_report *report; -if (!hdev->battery || hdev->vendor !=USB_VENDOR_ID_APPLE || - (hdev->product !=USB_DEVICE_ID_APPLE_MAGICMOUSE2 && - hdev->product !=USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 && - hdev->product !=USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC )) +if (!hdev->battery || + (!is_usb_magicmouse2 (hdev->vendor, hdev->product) && + !is_usb_magictrackpad2 (hdev->vendor, hdev->product)))return -1 ; report_enum = &hdev->report_enum[hdev->battery_report_type];
@@ -843,16 +857,17 @@ static int magicmouse_probe(struct hid_dreturn ret; } -timer_setup (&msc->battery_timer, magicmouse_battery_timer_tick,0 ); -mod_timer (&msc->battery_timer, - jiffies +msecs_to_jiffies (USB_BATTERY_TIMEOUT_MS )); -magicmouse_fetch_battery (hdev); - -if (id->vendor ==USB_VENDOR_ID_APPLE && - (id->product ==USB_DEVICE_ID_APPLE_MAGICMOUSE2 || - ((id->product ==USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 || - id->product ==USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC ) && - hdev->type !=HID_TYPE_USBMOUSE ))) +if (is_usb_magicmouse2 (id->vendor, id->product) || +is_usb_magictrackpad2 (id->vendor, id->product)) { +timer_setup (&msc->battery_timer, magicmouse_battery_timer_tick,0 ); +mod_timer (&msc->battery_timer, + jiffies +msecs_to_jiffies (USB_BATTERY_TIMEOUT_MS )); +magicmouse_fetch_battery (hdev); + } + +if (is_usb_magicmouse2 (id->vendor, id->product) || + (is_usb_magictrackpad2 (id->vendor, id->product) && + hdev->type !=HID_TYPE_USBMOUSE ))return 0 ;if (!msc->input) {
@@ -908,7 +923,10 @@ static int magicmouse_probe(struct hid_dreturn 0 ; err_stop_hw: -del_timer_sync (&msc->battery_timer); +if (is_usb_magicmouse2 (id->vendor, id->product) || +is_usb_magictrackpad2 (id->vendor, id->product)) +del_timer_sync (&msc->battery_timer); +hid_hw_stop (hdev);return ret; }
@@ -919,7 +937,9 @@ static void magicmouse_remove(struct hidif (msc) {cancel_delayed_work_sync (&msc->work); -del_timer_sync (&msc->battery_timer); +if (is_usb_magicmouse2 (hdev->vendor, hdev->product) || +is_usb_magictrackpad2 (hdev->vendor, hdev->product)) +del_timer_sync (&msc->battery_timer); }hid_hw_stop (hdev);
@@ -936,10 +956,8 @@ static __u8 *magicmouse_report_fixup(str* 0x05, 0x01, // Usage Page (Generic Desktop) 0 * 0x09, 0x02, // Usage (Mouse) 2 */ -if (hdev->vendor ==USB_VENDOR_ID_APPLE && - (hdev->product ==USB_DEVICE_ID_APPLE_MAGICMOUSE2 || - hdev->product ==USB_DEVICE_ID_APPLE_MAGICTRACKPAD2 || - hdev->product ==USB_DEVICE_ID_APPLE_MAGICTRACKPAD2_USBC ) && +if ((is_usb_magicmouse2 (hdev->vendor, hdev->product) || +is_usb_magictrackpad2 (hdev->vendor, hdev->product)) && *rsize ==83 && rdesc[46 ] ==0x84 && rdesc[58 ] ==0x85 ) {hid_info (hdev,"fixing up magicmouse battery report descriptor\n" );
Greg Kroah-Hartman
maintainerPATCH 327/587 HID: apple: avoid setting up battery timer for devices without battery
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Aditya Garg <[email protected]>
commit c061046fe9ce3ff31fb9a807144a2630ad349c17 upstream.
Currently, the battery timer is set up for all devices using hid-apple, irrespective of whether they actually have a battery or not.
APPLE_RDESC_BATTERY is a quirk that indicates the device has a battery and needs the battery timer. This patch checks for this quirk before setting up the timer, ensuring that only devices with a battery will have the timer set up.
--- drivers/hid/hid-apple.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/hid/hid-apple.c +8 -5
@@ -858,10 +858,12 @@ static int apple_probe(struct hid_devicereturn ret; } -timer_setup (&asc->battery_timer, apple_battery_timer_tick,0 ); -mod_timer (&asc->battery_timer, - jiffies +msecs_to_jiffies (APPLE_BATTERY_TIMEOUT_MS )); -apple_fetch_battery (hdev); +if (quirks &APPLE_RDESC_BATTERY ) { +timer_setup (&asc->battery_timer, apple_battery_timer_tick,0 ); +mod_timer (&asc->battery_timer, + jiffies +msecs_to_jiffies (APPLE_BATTERY_TIMEOUT_MS )); +apple_fetch_battery (hdev); + }if (quirks &APPLE_BACKLIGHT_CTL )apple_backlight_init (hdev);
@@ -873,7 +875,8 @@ static void apple_remove(struct hid_devi {struct apple_sc *asc =hid_get_drvdata (hdev); -del_timer_sync (&asc->battery_timer); +if (asc->quirks &APPLE_RDESC_BATTERY ) +del_timer_sync (&asc->battery_timer);hid_hw_stop (hdev); }
Greg Kroah-Hartman
maintainerPATCH 328/587 rcu: Fix racy re-initialization of irq_work causing hangs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Frederic Weisbecker <[email protected]>
commit 61399e0c5410567ef60cb1cda34cca42903842e3 upstream.
RCU re-initializes the deferred QS irq work everytime before attempting to queue it. However there are situations where the irq work is attempted to be queued even though it is already queued. In that case re-initializing messes-up with the irq work queue that is about to be handled.
The chances for that to happen are higher when the architecture doesn't support self-IPIs and irq work are then all lazy, such as with the following sequence:
1) rcu_read_unlock() is called when IRQs are disabled and there is a grace period involving blocked tasks on the node. The irq work is then initialized and queued.
2) The related tasks are unblocked and the CPU quiescent state is reported. rdp->defer_qs_iw_pending is reset to DEFER_QS_IDLE, allowing the irq work to be requeued in the future (note the previous one hasn't fired yet).
3) A new grace period starts and the node has blocked tasks.
4) rcu_read_unlock() is called when IRQs are disabled again. The irq work is re-initialized (but it's queued! and its node is cleared) and requeued. Which means it's requeued to itself.
5) The irq work finally fires with the tick. But since it was requeued to itself, it loops and hangs.
Fix this with initializing the irq work only once before the CPU boots.
--- kernel/rcu/tree.c | 2 ++ kernel/rcu/tree.h | 1 + kernel/rcu/tree_plugin.h | 8 ++++++-- 3 files changed, 9 insertions(+), 2 deletions(-)
kernel/rcu/tree.c +2 -0
@@ -4427,6 +4427,8 @@ int rcutree_prepare_cpu(unsigned int cpu rdp->rcu_iw_gp_seq = rdp->gp_seq -1 ;trace_rcu_grace_period (rcu_state.name, rdp->gp_seq,TPS ("cpuonl" ));raw_spin_unlock_irqrestore_rcu_node (rnp, flags); + +rcu_preempt_deferred_qs_init (rdp);rcu_spawn_one_boost_kthread (rnp);rcu_spawn_cpu_nocb_kthread (cpu);WRITE_ONCE (rcu_state.n_online_cpus, rcu_state.n_online_cpus +1 );
kernel/rcu/tree.h +1 -0
@@ -463,6 +463,7 @@ static int rcu_print_task_exp_stall(strustatic void rcu_preempt_check_blocked_tasks (struct rcu_node *rnp);static void rcu_flavor_sched_clock_irq (int user);static void dump_blkd_tasks (struct rcu_node *rnp,int ncheck); +static void rcu_preempt_deferred_qs_init (struct rcu_data *rdp);static void rcu_initiate_boost (struct rcu_node *rnp,unsigned long flags);static void rcu_preempt_boost_start_gp (struct rcu_node *rnp);static bool rcu_is_callbacks_kthread (struct rcu_data *rdp);
kernel/rcu/tree_plugin.h +6 -2
@@ -687,8 +687,6 @@ static void rcu_read_unlock_special(stru cpu_online(rdp->cpu)) {// Get scheduler to re-evaluate and call hooks. // If !IRQ_WORK, FQS scan will eventually IPI. - rdp->defer_qs_iw = -IRQ_WORK_INIT_HARD (rcu_preempt_deferred_qs_handler); rdp->defer_qs_iw_pending =DEFER_QS_PENDING ;irq_work_queue_on (&rdp->defer_qs_iw, rdp->cpu); }
@@ -828,6 +826,10 @@ dump_blkd_tasks(struct rcu_node *rnp, in } } +static void rcu_preempt_deferred_qs_init (struct rcu_data *rdp) +{ + rdp->defer_qs_iw =IRQ_WORK_INIT_HARD (rcu_preempt_deferred_qs_handler); +}#else /* #ifdef CONFIG_PREEMPT_RCU */ /*
@@ -1027,6 +1029,8 @@ dump_blkd_tasks(struct rcu_node *rnp, in WARN_ON_ONCE(!list_empty(&rnp->blkd_tasks)); } +static void rcu_preempt_deferred_qs_init (struct rcu_data *rdp) { } +#endif /* #else #ifdef CONFIG_PREEMPT_RCU */ /*
Greg Kroah-Hartman
maintainerPATCH 329/587 serial: 8250: fix panic due to PSLVERR
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yunhui Cui <[email protected]>
commit 7f8fdd4dbffc05982b96caf586f77a014b2a9353 upstream.
When the PSLVERR_RESP_EN parameter is set to 1, the device generates an error response if an attempt is made to read an empty RBR (Receive Buffer Register) while the FIFO is enabled.
In serial8250_do_startup(), calling serial_port_out(port, UART_LCR, UART_LCR_WLEN8) triggers dw8250_check_lcr(), which invokes dw8250_force_idle() and serial8250_clear_and_reinit_fifos(). The latter function enables the FIFO via serial_out(p, UART_FCR, p->fcr). Execution proceeds to the serial_port_in(port, UART_RX). This satisfies the PSLVERR trigger condition.
When another CPU (e.g., using printk()) is accessing the UART (UART is busy), the current CPU fails the check (value & ~UART_LCR_SPAR) == (lcr & ~UART_LCR_SPAR) in dw8250_check_lcr(), causing it to enter dw8250_force_idle().
Put serial_port_out(port, UART_LCR, UART_LCR_WLEN8) under the port->lock to fix this issue.
Panic backtrace:
[ 0.442336] Oops - unknown exception [#1] [ 0.442343] epc : dw8250_serial_in32+0x1e/0x4a [ 0.442351] ra : serial8250_do_startup+0x2c8/0x88e ... [ 0.442416] console_on_rootfs+0x26/0x70
--- drivers/tty/serial/8250/8250_port.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/tty/serial/8250/8250_port.c +1 -2
@@ -2375,9 +2375,8 @@ int serial8250_do_startup(struct uart_po/* * Now, initialize the UART */ -serial_port_out (port,UART_LCR ,UART_LCR_WLEN8 ); -spin_lock_irqsave (&port->lock, flags); +serial_port_out (port,UART_LCR ,UART_LCR_WLEN8 );if (up->port.flags &UPF_FOURPORT ) {if (!up->port.irq) up->port.mctrl |=TIOCM_OUT1 ;
Greg Kroah-Hartman
maintainerPATCH 330/587 cpufreq: armada-8k: Fix off by one in armada_8k_cpufreq_free_table()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
commit 4a26df233266a628157d7f0285451d8655defdfc upstream.
The freq_tables[] array has num_possible_cpus() elements so, to avoid an out of bounds access, this loop should be capped at "< nb_cpus" instead of "<= nb_cpus". The freq_tables[] array is allocated in armada_8k_cpufreq_init().
--- drivers/cpufreq/armada-8k-cpufreq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/cpufreq/armada-8k-cpufreq.c +1 -1
@@ -103,7 +103,7 @@ static void armada_8k_cpufreq_free_table {int opps_index, nb_cpus =num_possible_cpus (); -for (opps_index =0 ; opps_index <= nb_cpus; opps_index++) { +for (opps_index =0 ; opps_index < nb_cpus; opps_index++) {int i;/* If cpu_dev is NULL then we reached the end of the array */
Greg Kroah-Hartman
maintainerPATCH 331/587 platform/chrome: cros_ec: Unregister notifier in cros_ec_unregister()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tzung-Bi Shih <[email protected]>
commit e2374953461947eee49f69b3e3204ff080ef31b1 upstream.
The blocking notifier is registered in cros_ec_register(); however, it isn't unregistered in cros_ec_unregister().
Fix it.
--- drivers/platform/chrome/cros_ec.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/platform/chrome/cros_ec.c +3 -0
@@ -313,6 +313,9 @@ EXPORT_SYMBOL(cros_ec_register);*/ void cros_ec_unregister (struct cros_ec_device *ec_dev) { +if (ec_dev->mkbp_event_supported) +blocking_notifier_chain_unregister (&ec_dev->event_notifier, + &ec_dev->notifier_ready);platform_device_unregister (ec_dev->pd);platform_device_unregister (ec_dev->ec);mutex_destroy (&ec_dev->lock);
Greg Kroah-Hartman
maintainerPATCH 332/587 m68k: Fix lost column on framebuffer debug console
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Finn Thain <[email protected]>
commit 210a1ce8ed4391b64a888b3fb4b5611a13f5ccc7 upstream.
Move the cursor position rightward after rendering the character, not before. This avoids complications that arise when the recursive console_putc call has to wrap the line and/or scroll the display. This also fixes the linewrap bug that crops off the rightmost column.
When the cursor is at the bottom of the display, a linefeed will not move the cursor position further downward. Instead, the display scrolls upward. Avoid the repeated add/subtract sequence by way of a single subtraction at the initialization of console_struct_num_rows.
--- arch/m68k/kernel/head.S | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-)
arch/m68k/kernel/head.S +21 -10
@@ -3404,6 +3404,7 @@ L(console_clear_loop): movel %d4,%d1 /* screen height in pixels */ divul %a0@(FONT_DESC_HEIGHT),%d1 /* d1 = max num rows */ + subql #1,%d1 /* row range is 0 to num - 1 */ movel %d0,%a2@(Lconsole_struct_num_columns) movel %d1,%a2@(Lconsole_struct_num_rows)
@@ -3550,15 +3551,14 @@ func_start console_putc,%a0/%a1/%d0-%d7 cmpib #10,%d7 jne L(console_not_lf) movel %a0@(Lconsole_struct_cur_row),%d0 - addil #1,%d0 - movel %d0,%a0@(Lconsole_struct_cur_row) movel %a0@(Lconsole_struct_num_rows),%d1 cmpl %d1,%d0 jcs 1f - subil #1,%d0 - movel %d0,%a0@(Lconsole_struct_cur_row) console_scroll + jra L(console_exit) 1: + addql #1,%d0 + movel %d0,%a0@(Lconsole_struct_cur_row) jra L(console_exit) L(console_not_lf):
@@ -3585,12 +3585,6 @@ L(console_not_cr): */ L(console_not_home): movel %a0@(Lconsole_struct_cur_column),%d0 - addql #1,%a0@(Lconsole_struct_cur_column) - movel %a0@(Lconsole_struct_num_columns),%d1 - cmpl %d1,%d0 - jcs 1f - console_putc #'\n' /* recursion is OK! */ -1: movel %a0@(Lconsole_struct_cur_row),%d1 /*
@@ -3637,6 +3631,23 @@ L(console_do_font_scanline): addq #1,%d1 dbra %d7,L(console_read_char_scanline) + /* + * Register usage in the code below: + * a0 = pointer to console globals + * d0 = cursor column + * d1 = cursor column limit + */ + + lea %pc@(L(console_globals)),%a0 + + movel %a0@(Lconsole_struct_cur_column),%d0 + addql #1,%d0 + movel %d0,%a0@(Lconsole_struct_cur_column) /* Update cursor pos */ + movel %a0@(Lconsole_struct_num_columns),%d1 + cmpl %d1,%d0 + jcs L(console_exit) + console_putc #'\n' /* Line wrap using tail recursion */ + L(console_exit): func_return console_putc
Greg Kroah-Hartman
maintainerPATCH 333/587 usb: atm: cxacru: Merge cxacru_upload_firmware() into cxacru_heavy_init()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nathan Chancellor <[email protected]>
commit 8d1b02e5d7e3a6d2acffb1f4c094678fda9e3456 upstream.
After a recent change in clang to expose uninitialized warnings from const variables [1], there is a warning in cxacru_heavy_init():
drivers/usb/atm/cxacru.c:1104:6: error: variable 'bp' is used uninitialized whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
1104 | if (instance->modem_type->boot_rom_patch) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/usb/atm/cxacru.c:1113:39: note: uninitialized use occurs here
1113 | cxacru_upload_firmware(instance, fw, bp);
| ^~
drivers/usb/atm/cxacru.c:1104:2: note: remove the 'if' if its condition is always true
1104 | if (instance->modem_type->boot_rom_patch) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/usb/atm/cxacru.c:1095:32: note: initialize the variable 'bp' to silence this warning
1095 | const struct firmware *fw, *bp;
| ^
| = NULLWhile the warning is technically correct that bp is conditionally passed uninitialized to cxacru_upload_firmware(), it is ultimately a false positive warning on the uninitialized use of bp because the same condition that initializes bp, instance->modem_type->boot_rom_patch, is the same one that gates the use of bp within cxacru_upload_firmware(). As this warning occurs in clang's frontend before inlining occurs, it cannot know that these conditions are indentical to avoid the warning.
Manually inline cxacru_upload_firmware() into cxacru_heavy_init(), as that is its only callsite, so that clang can see that bp is initialized and used under the same condition, clearing up the warning without any functional changes to the code (LLVM was already doing this inlining later).
--- drivers/usb/atm/cxacru.c | 106 +++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 57 deletions(-)
drivers/usb/atm/cxacru.c +49 -57
@@ -980,25 +980,60 @@ cleanup:return ret; } -static void cxacru_upload_firmware (struct cxacru_data *instance, -const struct firmware *fw, -const struct firmware *bp) + +static int cxacru_find_firmware (struct cxacru_data *instance, +char *phase,const struct firmware **fw_p) { -int ret; +struct usbatm_data *usbatm = instance->usbatm; +struct device *dev = &usbatm->usb_intf->dev; +char buf[16 ]; + +sprintf (buf,"cxacru-%s.bin" , phase); +usb_dbg (usbatm,"cxacru_find_firmware: looking for %s\n" , buf); + +if (request_firmware (fw_p, buf, dev)) { +usb_dbg (usbatm,"no stage %s firmware found\n" , phase); +return -ENOENT ; + } + +usb_info (usbatm,"found firmware %s\n" , buf); + +return 0 ; +} + +static int cxacru_heavy_init (struct usbatm_data *usbatm_instance, +struct usb_interface *usb_intf) +{ +const struct firmware *fw, *bp; +struct cxacru_data *instance = usbatm_instance->driver_data;struct usbatm_data *usbatm = instance->usbatm;struct usb_device *usb_dev = usbatm->usb_dev;__le16 signature[] = { usb_dev->descriptor.idVendor, usb_dev->descriptor.idProduct };__le32 val; +int ret; + + ret =cxacru_find_firmware (instance,"fw" , &fw); +if (ret) { +usb_warn (usbatm_instance,"firmware (cxacru-fw.bin) unavailable (system misconfigured?)\n" ); +return ret; + } -usb_dbg (usbatm,"%s\n" , __func__); +if (instance->modem_type->boot_rom_patch) { + ret =cxacru_find_firmware (instance,"bp" , &bp); +if (ret) { +usb_warn (usbatm_instance,"boot ROM patch (cxacru-bp.bin) unavailable (system misconfigured?)\n" ); +release_firmware (fw); +return ret; + } + }/* FirmwarePllFClkValue */ val =cpu_to_le32 (instance->modem_type->pll_f_clk); ret =cxacru_fw (usb_dev,FW_WRITE_MEM ,0x2 ,0x0 ,PLLFCLK_ADDR , (u8 *) &val,4 );if (ret) {usb_err (usbatm,"FirmwarePllFClkValue failed: %d\n" , ret); -return ; + goto done; }/* FirmwarePllBClkValue */
@@ -1006,7 +1041,7 @@ static void cxacru_upload_firmware(struc ret =cxacru_fw (usb_dev,FW_WRITE_MEM ,0x2 ,0x0 ,PLLBCLK_ADDR , (u8 *) &val,4 );if (ret) {usb_err (usbatm,"FirmwarePllBClkValue failed: %d\n" , ret); -return ; + goto done; }/* Enable SDRAM */
@@ -1014,7 +1049,7 @@ static void cxacru_upload_firmware(struc ret =cxacru_fw (usb_dev,FW_WRITE_MEM ,0x2 ,0x0 ,SDRAMEN_ADDR , (u8 *) &val,4 );if (ret) {usb_err (usbatm,"Enable SDRAM failed: %d\n" , ret); -return ; + goto done; }/* Firmware */
@@ -1022,7 +1057,7 @@ static void cxacru_upload_firmware(struc ret =cxacru_fw (usb_dev,FW_WRITE_MEM ,0x2 ,0x0 ,FW_ADDR , fw->data, fw->size);if (ret) {usb_err (usbatm,"Firmware upload failed: %d\n" , ret); -return ; + goto done; }/* Boot ROM patch */
@@ -1031,7 +1066,7 @@ static void cxacru_upload_firmware(struc ret =cxacru_fw (usb_dev,FW_WRITE_MEM ,0x2 ,0x0 ,BR_ADDR , bp->data, bp->size);if (ret) {usb_err (usbatm,"Boot ROM patching failed: %d\n" , ret); -return ; + goto done; } }
@@ -1039,7 +1074,7 @@ static void cxacru_upload_firmware(struc ret =cxacru_fw (usb_dev,FW_WRITE_MEM ,0x2 ,0x0 ,SIG_ADDR , (u8 *) signature,4 );if (ret) {usb_err (usbatm,"Signature storing failed: %d\n" , ret); -return ; + goto done; }usb_info (usbatm,"starting device\n" );
@@ -1051,7 +1086,7 @@ static void cxacru_upload_firmware(struc }if (ret) {usb_err (usbatm,"Passing control to firmware failed: %d\n" , ret); -return ; + goto done; }/* Delay to allow firmware to start up. */
@@ -1065,53 +1100,10 @@ static void cxacru_upload_firmware(struc ret =cxacru_cm (instance,CM_REQUEST_CARD_GET_STATUS ,NULL ,0 ,NULL ,0 );if (ret <0 ) {usb_err (usbatm,"modem failed to initialize: %d\n" , ret); -return ; - } -} - -static int cxacru_find_firmware (struct cxacru_data *instance, -char *phase,const struct firmware **fw_p) -{ -struct usbatm_data *usbatm = instance->usbatm; -struct device *dev = &usbatm->usb_intf->dev; -char buf[16 ]; - -sprintf (buf,"cxacru-%s.bin" , phase); -usb_dbg (usbatm,"cxacru_find_firmware: looking for %s\n" , buf); - -if (request_firmware (fw_p, buf, dev)) { -usb_dbg (usbatm,"no stage %s firmware found\n" , phase); -return -ENOENT ; + goto done; } -usb_info (usbatm,"found firmware %s\n" , buf); - -return 0 ; -} - -static int cxacru_heavy_init (struct usbatm_data *usbatm_instance, -struct usb_interface *usb_intf) -{ -const struct firmware *fw, *bp; -struct cxacru_data *instance = usbatm_instance->driver_data; -int ret =cxacru_find_firmware (instance,"fw" , &fw); - -if (ret) { -usb_warn (usbatm_instance,"firmware (cxacru-fw.bin) unavailable (system misconfigured?)\n" ); -return ret; - } - -if (instance->modem_type->boot_rom_patch) { - ret =cxacru_find_firmware (instance,"bp" , &bp); -if (ret) { -usb_warn (usbatm_instance,"boot ROM patch (cxacru-bp.bin) unavailable (system misconfigured?)\n" ); -release_firmware (fw); -return ret; - } - } - -cxacru_upload_firmware (instance, fw, bp); - +done:if (instance->modem_type->boot_rom_patch)release_firmware (bp);release_firmware (fw);
Greg Kroah-Hartman
maintainerPATCH 334/587 usb: gadget: udc: renesas_usb3: fix device leak at unbind
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 868837b0a94c6b1b1fdbc04d3ba218ca83432393 upstream.
Make sure to drop the reference to the companion device taken during probe when the driver is unbound.
--- drivers/usb/gadget/udc/renesas_usb3.c | 1 + 1 file changed, 1 insertion(+)
drivers/usb/gadget/udc/renesas_usb3.c +1 -0
@@ -2658,6 +2658,7 @@ static void renesas_usb3_remove(struct pstruct renesas_usb3 *usb3 =platform_get_drvdata (pdev);debugfs_remove_recursive (usb3->dentry); +put_device (usb3->host_dev);device_remove_file (&pdev->dev, &dev_attr_role);cancel_work_sync (&usb3->role_work);
Greg Kroah-Hartman
maintainerPATCH 335/587 usb: musb: omap2430: fix device leak at unbind
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 1473e9e7679bd4f5a62d1abccae894fb86de280f upstream.
Make sure to drop the reference to the control device taken by of_find_device_by_node() during probe when the driver is unbound.
--- drivers/usb/musb/omap2430.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
drivers/usb/musb/omap2430.c +9 -5
@@ -400,7 +400,7 @@ static int omap2430_probe(struct platfor ret =platform_device_add_resources (musb, pdev->resource, pdev->num_resources);if (ret) {dev_err (&pdev->dev,"failed to add resources\n" ); - goto err2; + goto err_put_control_otghs; }if (populate_irqs) {
@@ -413,7 +413,7 @@ static int omap2430_probe(struct platfor res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );if (!res) { ret = -EINVAL ; - goto err2; + goto err_put_control_otghs; } musb_res[i].start = res->start;
@@ -441,14 +441,14 @@ static int omap2430_probe(struct platfor ret =platform_device_add_resources (musb, musb_res, i);if (ret) {dev_err (&pdev->dev,"failed to add IRQ resources\n" ); - goto err2; + goto err_put_control_otghs; } } ret =platform_device_add_data (musb, pdata,sizeof (*pdata));if (ret) {dev_err (&pdev->dev,"failed to add platform_data\n" ); - goto err2; + goto err_put_control_otghs; }pm_runtime_enable (glue->dev);
@@ -463,7 +463,9 @@ static int omap2430_probe(struct platfor err3:pm_runtime_disable (glue->dev); - +err_put_control_otghs: +if (!IS_ERR (glue->control_otghs)) +put_device (glue->control_otghs); err2:platform_device_put (musb);
@@ -477,6 +479,8 @@ static void omap2430_remove(struct platfplatform_device_unregister (glue->musb);pm_runtime_disable (glue->dev); +if (!IS_ERR (glue->control_otghs)) +put_device (glue->control_otghs); }#ifdef CONFIG_PM
Greg Kroah-Hartman
maintainerPATCH 336/587 usb: dwc3: meson-g12a: fix device leaks at unbind
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 93b400f4951404d040197943a25d6fef9f8ccabb upstream.
Make sure to drop the references taken to the child devices by of_find_device_by_node() during probe on driver unbind.
--- drivers/usb/dwc3/dwc3-meson-g12a.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/dwc3/dwc3-meson-g12a.c +3 -0
@@ -837,6 +837,9 @@ static void dwc3_meson_g12a_remove(strucusb_role_switch_unregister (priv->role_switch); +put_device (priv->switch_desc.udc); +put_device (priv->switch_desc.usb2_port); +of_platform_depopulate (dev);for (i =0 ; i <PHY_COUNT ; ++i) {
Greg Kroah-Hartman
maintainerPATCH 337/587 bus: mhi: host: Fix endianness of BHI vector table
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Wilhelm <[email protected]>
commit f471578e8b1a90623674433a01a8845110bc76ce upstream.
On big endian platform like PowerPC, the MHI bus (which is little endian) does not start properly. The following example shows the error messages by using QCN9274 WLAN device with ath12k driver:
ath12k_pci 0001:01:00.0: BAR 0: assigned [mem 0xc00000000-0xc001fffff 64bit]
ath12k_pci 0001:01:00.0: MSI vectors: 1
ath12k_pci 0001:01:00.0: Hardware name: qcn9274 hw2.0
ath12k_pci 0001:01:00.0: failed to set mhi state: POWER_ON(2)
ath12k_pci 0001:01:00.0: failed to start mhi: -110
ath12k_pci 0001:01:00.0: failed to power up :-110
ath12k_pci 0001:01:00.0: failed to create soc core: -110
ath12k_pci 0001:01:00.0: failed to init core: -110
ath12k_pci: probe of 0001:01:00.0 failed with error -110The issue seems to be with the incorrect DMA address/size used for transferring the firmware image over BHI. So fix it by converting the DMA address and size of the BHI vector table to little endian format before sending them to the device.
--- drivers/bus/mhi/host/boot.c | 8 ++++---- drivers/bus/mhi/host/internal.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/bus/mhi/host/boot.c +4 -4
@@ -31,8 +31,8 @@ int mhi_rddm_prepare(struct mhi_controllint ret;for (i =0 ; i < img_info->entries -1 ; i++, mhi_buf++, bhi_vec++) { - bhi_vec->dma_addr = mhi_buf->dma_addr; - bhi_vec->size = mhi_buf->len; + bhi_vec->dma_addr =cpu_to_le64 (mhi_buf->dma_addr); + bhi_vec->size =cpu_to_le64 (mhi_buf->len); }dev_dbg (dev,"BHIe programming for RDDM\n" );
@@ -375,8 +375,8 @@ static void mhi_firmware_copy(struct mhiwhile (remainder) { to_cpy =min (remainder, mhi_buf->len);memcpy (mhi_buf->buf, buf, to_cpy); - bhi_vec->dma_addr = mhi_buf->dma_addr; - bhi_vec->size = to_cpy; + bhi_vec->dma_addr =cpu_to_le64 (mhi_buf->dma_addr); + bhi_vec->size =cpu_to_le64 (to_cpy); buf += to_cpy; remainder -= to_cpy;
drivers/bus/mhi/host/internal.h +2 -2
@@ -31,8 +31,8 @@ struct mhi_ctxt { };struct bhi_vec_entry { -u64 dma_addr; -u64 size; +__le64 dma_addr; +__le64 size; };enum mhi_ch_state_type {
Greg Kroah-Hartman
maintainerPATCH 338/587 bus: mhi: host: Detect events pointing to unexpected TREs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Youssef Samir <[email protected]>
commit 5bd398e20f0833ae8a1267d4f343591a2dd20185 upstream.
When a remote device sends a completion event to the host, it contains a pointer to the consumed TRE. The host uses this pointer to process all of the TREs between it and the host's local copy of the ring's read pointer. This works when processing completion for chained transactions, but can lead to nasty results if the device sends an event for a single-element transaction with a read pointer that is multiple elements ahead of the host's read pointer.
For instance, if the host accesses an event ring while the device is updating it, the pointer inside of the event might still point to an old TRE. If the host uses the channel's xfer_cb() to directly free the buffer pointed to by the TRE, the buffer will be double-freed.
This behavior was observed on an ep that used upstream EP stack without 'commit 6f18d174b73d ("bus: mhi: ep: Update read pointer only after buffer is written")'. Where the device updated the events ring pointer before updating the event contents, so it left a window where the host was able to access the stale data the event pointed to, before the device had the chance to update them. The usual pattern was that the host received an event pointing to a TRE that is not immediately after the last processed one, so it got treated as if it was a chained transaction, processing all of the TREs in between the two read pointers.
This commit aims to harden the host by ensuring transactions where the event points to a TRE that isn't local_rp + 1 are chained.
--- drivers/bus/mhi/host/main.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/bus/mhi/host/main.c +11 -1
@@ -603,7 +603,7 @@ static int parse_xfer_event(struct mhi_c {dma_addr_t ptr =MHI_TRE_GET_EV_PTR (event);struct mhi_ring_element *local_rp, *ev_tre; -void *dev_rp; +void *dev_rp, *next_rp;struct mhi_buf_info *buf_info;u16 xfer_len;
@@ -622,6 +622,16 @@ static int parse_xfer_event(struct mhi_c result.dir = mhi_chan->dir; local_rp = tre_ring->rp; + + next_rp = local_rp +1 ; +if (next_rp >= tre_ring->base + tre_ring->len) + next_rp = tre_ring->base; +if (dev_rp != next_rp && !MHI_TRE_DATA_GET_CHAIN (local_rp)) { +dev_err (&mhi_cntrl->mhi_dev->dev, +"Event element points to an unexpected TRE\n" ); +break ; + } +while (local_rp != dev_rp) { buf_info = buf_ring->rp;/* If it's the last TRE, get length from the event */
Greg Kroah-Hartman
maintainerPATCH 339/587 vt: keyboard: Dont process Unicode characters in K_OFF mode
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myrrh Periwinkle <[email protected]>
commit b1cc2092ea7a52e2c435aee6d2b1bcb773202663 upstream.
We don't process Unicode characters if the virtual terminal is in raw mode, so there's no reason why we shouldn't do the same for K_OFF (especially since people would expect K_OFF to actually turn off all VT key processing).
--- drivers/tty/vt/keyboard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/vt/keyboard.c +1 -1
@@ -1496,7 +1496,7 @@ static void kbd_keycode(unsigned int key rc =atomic_notifier_call_chain (&keyboard_notifier_list,KBD_UNICODE , ¶m);if (rc !=NOTIFY_STOP ) -if (down && !raw_mode) +if (down && !(raw_mode || kbd->kbdmode ==VC_OFF ))k_unicode (vc, keysym, !down);return ; }
Greg Kroah-Hartman
maintainerPATCH 340/587 vt: defkeymap: Map keycodes above 127 to K_HOLE
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Myrrh Periwinkle <[email protected]>
commit b43cb4ff85da5cf29c4cd351ef1d7dd8210780f7 upstream.
The maximum number of keycodes got bumped to 256 a very long time ago, but the default keymaps were never adjusted to match. This is causing the kernel to interpret keycodes above 127 as U+0000 if the shipped generated keymap is used.
Fix this by mapping all keycodes above 127 to K_HOLE so the kernel ignores them.
The contents of this patche were generated by rerunning loadkeys --mktable --unicode and only including the changes to map keycodes above 127 to K_HOLE.
--- drivers/tty/vt/defkeymap.c_shipped | 112 +++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+)
drivers/tty/vt/defkeymap.c_shipped +112 -0
@@ -23,6 +23,22 @@ unsigned short plain_map[NR_KEYS] = { 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116, 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, }; static unsigned short shift_map[NR_KEYS] = {
@@ -42,6 +58,22 @@ static unsigned short shift_map[NR_KEYS] 0xf20b, 0xf601, 0xf602, 0xf117, 0xf600, 0xf20a, 0xf115, 0xf116, 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, }; static unsigned short altgr_map[NR_KEYS] = {
@@ -61,6 +93,22 @@ static unsigned short altgr_map[NR_KEYS] 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116, 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, }; static unsigned short ctrl_map[NR_KEYS] = {
@@ -80,6 +128,22 @@ static unsigned short ctrl_map[NR_KEYS] 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116, 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, }; static unsigned short shift_ctrl_map[NR_KEYS] = {
@@ -99,6 +163,22 @@ static unsigned short shift_ctrl_map[NR_ 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116, 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, }; static unsigned short alt_map[NR_KEYS] = {
@@ -118,6 +198,22 @@ static unsigned short alt_map[NR_KEYS] = 0xf118, 0xf210, 0xf211, 0xf117, 0xf600, 0xf119, 0xf115, 0xf116, 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, }; static unsigned short ctrl_alt_map[NR_KEYS] = {
@@ -137,6 +233,22 @@ static unsigned short ctrl_alt_map[NR_KE 0xf118, 0xf601, 0xf602, 0xf117, 0xf600, 0xf119, 0xf115, 0xf20c, 0xf11a, 0xf10c, 0xf10d, 0xf11b, 0xf11c, 0xf110, 0xf311, 0xf11d, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, + 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, 0xf200, }; unsigned short *key_maps[MAX_NR_KEYMAPS] = {
Greg Kroah-Hartman
maintainerPATCH 341/587 lib/crypto: mips/chacha: Fix clang build and remove unneeded byteswap
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit 22375adaa0d9fbba9646c8e2b099c6e87c97bfae upstream.
The MIPS32r2 ChaCha code has never been buildable with the clang assembler. First, clang doesn't support the 'rotl' pseudo-instruction:
error: unknown instruction, did you mean: rol, rotr?
Second, clang requires that both operands of the 'wsbh' instruction be explicitly given:
error: too few operands for instruction
To fix this, align the code with the real instruction set by (1) using the real instruction 'rotr' instead of the nonstandard pseudo- instruction 'rotl', and (2) explicitly giving both operands to 'wsbh'.
To make removing the use of 'rotl' a bit easier, also remove the unnecessary special-casing for big endian CPUs at .Lchacha_mips_xor_bytes. The tail handling is actually endian-independent since it processes one byte at a time. On big endian CPUs the old code byte-swapped SAVED_X, then iterated through it in reverse order. But the byteswap and reverse iteration canceled out.
Tested with chacha20poly1305-selftest in QEMU using "-M malta" with both little endian and big endian mips32r2 kernels.
--- arch/mips/crypto/chacha-core.S | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-)
arch/mips/crypto/chacha-core.S +7 -13
@@ -55,17 +55,13 @@ #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define MSB 0 #define LSB 3 -#define ROTx rotl -#define ROTR(n) rotr n, 24 #define CPU_TO_LE32(n) \ - wsbh n; \ + wsbh n, n; \ rotr n, 16; #else #define MSB 3 #define LSB 0 -#define ROTx rotr #define CPU_TO_LE32(n) -#define ROTR(n) #endif #define FOR_EACH_WORD(x) \
@@ -192,10 +188,10 @@ CONCAT3(.Lchacha_mips_xor_aligned_, PLUS xor X(W), X(B); \ xor X(Y), X(C); \ xor X(Z), X(D); \ - rotl X(V), S; \ - rotl X(W), S; \ - rotl X(Y), S; \ - rotl X(Z), S; + rotr X(V), 32 - S; \ + rotr X(W), 32 - S; \ + rotr X(Y), 32 - S; \ + rotr X(Z), 32 - S; .text .set reorder
@@ -372,21 +368,19 @@ chacha_crypt_arch: /* First byte */ lbu T1, 0(IN) addiu $at, BYTES, 1 - CPU_TO_LE32(SAVED_X) - ROTR(SAVED_X) xor T1, SAVED_X sb T1, 0(OUT) beqz $at, .Lchacha_mips_xor_done /* Second byte */ lbu T1, 1(IN) addiu $at, BYTES, 2 - ROTx SAVED_X, 8 + rotr SAVED_X, 8 xor T1, SAVED_X sb T1, 1(OUT) beqz $at, .Lchacha_mips_xor_done /* Third byte */ lbu T1, 2(IN) - ROTx SAVED_X, 8 + rotr SAVED_X, 8 xor T1, SAVED_X sb T1, 2(OUT) b .Lchacha_mips_xor_done
Greg Kroah-Hartman
maintainerPATCH 342/587 crypto: qat - lower priority for skcipher and aead algorithms
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Giovanni Cabiddu <[email protected]>
commit 8024774190a5ef2af2c5846f60a50b23e0980a32 upstream.
Most kernel applications utilizing the crypto API operate synchronously and on small buffer sizes, therefore do not benefit from QAT acceleration.
Reduce the priority of QAT implementations for both skcipher and aead algorithms, allowing more suitable alternatives to be selected by default.
--- drivers/crypto/intel/qat/qat_common/qat_algs.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/crypto/intel/qat/qat_common/qat_algs.c +6 -6
@@ -1277,7 +1277,7 @@ static struct aead_alg qat_aeads[] = { { .base = { .cra_name = "authenc(hmac(sha1),cbc(aes))", .cra_driver_name = "qat_aes_cbc_hmac_sha1", - .cra_priority = 4001, + .cra_priority = 100, .cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY, .cra_blocksize = AES_BLOCK_SIZE, .cra_ctxsize = sizeof(struct qat_alg_aead_ctx),
@@ -1294,7 +1294,7 @@ static struct aead_alg qat_aeads[] = { { .base = { .cra_name = "authenc(hmac(sha256),cbc(aes))", .cra_driver_name = "qat_aes_cbc_hmac_sha256", - .cra_priority = 4001, + .cra_priority = 100, .cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY, .cra_blocksize = AES_BLOCK_SIZE, .cra_ctxsize = sizeof(struct qat_alg_aead_ctx),
@@ -1311,7 +1311,7 @@ static struct aead_alg qat_aeads[] = { { .base = { .cra_name = "authenc(hmac(sha512),cbc(aes))", .cra_driver_name = "qat_aes_cbc_hmac_sha512", - .cra_priority = 4001, + .cra_priority = 100, .cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY, .cra_blocksize = AES_BLOCK_SIZE, .cra_ctxsize = sizeof(struct qat_alg_aead_ctx),
@@ -1329,7 +1329,7 @@ static struct aead_alg qat_aeads[] = { {static struct skcipher_alg qat_skciphers[] = { { .base.cra_name ="cbc(aes)" , .base.cra_driver_name ="qat_aes_cbc" , - .base.cra_priority =4001 , + .base.cra_priority =100 , .base.cra_flags =CRYPTO_ALG_ASYNC |CRYPTO_ALG_ALLOCATES_MEMORY , .base.cra_blocksize =AES_BLOCK_SIZE , .base.cra_ctxsize =sizeof (struct qat_alg_skcipher_ctx ),
@@ -1347,7 +1347,7 @@ static struct skcipher_alg qat_skciphers }, { .base.cra_name = "ctr(aes)", .base.cra_driver_name = "qat_aes_ctr", - .base.cra_priority = 4001, + .base.cra_priority = 100, .base.cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY, .base.cra_blocksize = 1, .base.cra_ctxsize = sizeof(struct qat_alg_skcipher_ctx),
@@ -1365,7 +1365,7 @@ static struct skcipher_alg qat_skciphers }, { .base.cra_name = "xts(aes)", .base.cra_driver_name = "qat_aes_xts", - .base.cra_priority = 4001, + .base.cra_priority = 100, .base.cra_flags =CRYPTO_ALG_ASYNC |CRYPTO_ALG_NEED_FALLBACK | CRYPTO_ALG_ALLOCATES_MEMORY, .base.cra_blocksize = AES_BLOCK_SIZE,
Greg Kroah-Hartman
maintainerPATCH 343/587 crypto: qat - flush misc workqueue during device shutdown
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Giovanni Cabiddu <[email protected]>
commit 3d4df408ba9bad2b205c7fb8afc1836a6a4ca88a upstream.
Repeated loading and unloading of a device specific QAT driver, for example qat_4xxx, in a tight loop can lead to a crash due to a use-after-free scenario. This occurs when a power management (PM) interrupt triggers just before the device-specific driver (e.g., qat_4xxx.ko) is unloaded, while the core driver (intel_qat.ko) remains loaded.
Since the driver uses a shared workqueue (qat_misc_wq) across all devices and owned by intel_qat.ko, a deferred routine from the device-specific driver may still be pending in the queue. If this routine executes after the driver is unloaded, it can dereference freed memory, resulting in a page fault and kernel crash like the following:
BUG: unable to handle page fault for address: ffa000002e50a01c
#PF: supervisor read access in kernel mode
RIP: 0010:pm_bh_handler+0x1d2/0x250 [intel_qat]
Call Trace:
pm_bh_handler+0x1d2/0x250 [intel_qat]
process_one_work+0x171/0x340
worker_thread+0x277/0x3a0
kthread+0xf0/0x120
ret_from_fork+0x2d/0x50To prevent this, flush the misc workqueue during device shutdown to ensure that all pending work items are completed before the driver is unloaded.
Note: This approach may slightly increase shutdown latency if the workqueue contains jobs from other devices, but it ensures correctness and stability.
--- drivers/crypto/intel/qat/qat_common/adf_common_drv.h | 1 + drivers/crypto/intel/qat/qat_common/adf_init.c | 1 + drivers/crypto/intel/qat/qat_common/adf_isr.c | 5 +++++ 3 files changed, 7 insertions(+)
drivers/crypto/intel/qat/qat_common/adf_common_drv.h +1 -0
@@ -193,6 +193,7 @@ void adf_exit_misc_wq(void);bool adf_misc_wq_queue_work (struct work_struct *work);bool adf_misc_wq_queue_delayed_work (struct delayed_work *work,unsigned long delay); +void adf_misc_wq_flush (void );#if defined(CONFIG_PCI_IOV )int adf_sriov_configure (struct pci_dev *pdev,int numvfs);void adf_disable_sriov (struct adf_accel_dev *accel_dev);
drivers/crypto/intel/qat/qat_common/adf_init.c +1 -0
@@ -381,6 +381,7 @@ static void adf_dev_shutdown(struct adf_ hw_data->exit_admin_comms (accel_dev);adf_cleanup_etr_data (accel_dev); +adf_misc_wq_flush ();adf_dev_restore (accel_dev); }
drivers/crypto/intel/qat/qat_common/adf_isr.c +5 -0
@@ -386,3 +386,8 @@ bool adf_misc_wq_queue_delayed_work(stru {return queue_delayed_work (adf_misc_wq, work, delay); } + +void adf_misc_wq_flush (void ) +{ +flush_workqueue (adf_misc_wq); +}
Greg Kroah-Hartman
maintainerPATCH 344/587 Revert "vgacon: Add check for vc_origin address range in vgacon_scroll()"
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Helge Deller <[email protected]>
commit e4fc307d8e24f122402907ebf585248cad52841d upstream.
This reverts commit 864f9963ec6b4b76d104d595ba28110b87158003.
The patch is wrong as it checks vc_origin against vc_screenbuf, while in text mode it should compare against vga_vram_base.
As such it broke VGA text scrolling, which can be reproduced like this:
(1) boot a kernel that is configured to use text mode VGA-console
(2) type commands: ls -l /usr/bin | less -S
(3) scroll up/down with cursor-down/up keys
--- drivers/video/console/vgacon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/video/console/vgacon.c +1 -1
@@ -1139,7 +1139,7 @@ static bool vgacon_scroll(struct vc_data c->vc_screenbuf_size - delta); c->vc_origin = vga_vram_end - c->vc_screenbuf_size; vga_rolled_over =0 ; - }else if (oldo - delta >= (unsigned long )c->vc_screenbuf) + }else c->vc_origin -= delta; c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size; scr_memsetw((u16 *) (c->vc_origin), c->vc_video_erase_char,
Greg Kroah-Hartman
maintainerPATCH 345/587 ksmbd: fix refcount leak causing resource not released
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ziyan Xu <[email protected]>
commit 89bb430f621124af39bb31763c4a8b504c9651e2 upstream.
When ksmbd_conn_releasing(opinfo->conn) returns true,the refcount was not decremented properly, causing a refcount leak that prevents the count from reaching zero and the memory from being released.
--- fs/smb/server/oplock.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
fs/smb/server/oplock.c +10 -3
@@ -1102,8 +1102,10 @@ void smb_send_parent_lease_break_noti(stif (!atomic_inc_not_zero (&opinfo->refcount))continue ; -if (ksmbd_conn_releasing (opinfo->conn)) +if (ksmbd_conn_releasing (opinfo->conn)) { +opinfo_put (opinfo);continue ; + }oplock_break (opinfo,SMB2_OPLOCK_LEVEL_NONE ,NULL );opinfo_put (opinfo);
@@ -1139,8 +1141,11 @@ void smb_lazy_parent_lease_break_close(sif (!atomic_inc_not_zero (&opinfo->refcount))continue ; -if (ksmbd_conn_releasing (opinfo->conn)) +if (ksmbd_conn_releasing (opinfo->conn)) { +opinfo_put (opinfo);continue ; + } +oplock_break (opinfo,SMB2_OPLOCK_LEVEL_NONE ,NULL );opinfo_put (opinfo); }
@@ -1343,8 +1348,10 @@ void smb_break_all_levII_oplock(struct kif (!atomic_inc_not_zero (&brk_op->refcount))continue ; -if (ksmbd_conn_releasing (brk_op->conn)) +if (ksmbd_conn_releasing (brk_op->conn)) { +opinfo_put (brk_op);continue ; + } if (brk_op->is_lease && (brk_op->o_lease->state & (~(SMB2_LEASE_READ_CACHING_LE |
Greg Kroah-Hartman
maintainerPATCH 346/587 ksmbd: extend the connection limiting mechanism to support IPv6
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Namjae Jeon <[email protected]>
commit c0d41112f1a5828c194b59cca953114bc3776ef2 upstream.
Update the connection tracking logic to handle both IPv4 and IPv6 address families.
--- fs/smb/server/connection.h | 7 ++++++- fs/smb/server/transport_tcp.c | 26 +++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-)
fs/smb/server/connection.h +6 -1
@@ -45,7 +45,12 @@ struct ksmbd_conn {struct mutex srv_mutex;int status;unsigned int cli_cap; -__be32 inet_addr; +union { +__be32 inet_addr; +#if IS_ENABLED (CONFIG_IPV6 ) +u8 inet6_addr[16 ]; +#endif + };char *request_buf;struct ksmbd_transport *transport;struct nls_table *local_nls;
fs/smb/server/transport_tcp.c +23 -3
@@ -87,7 +87,14 @@ static struct tcp_transport *alloc_transreturn NULL ; } +#if IS_ENABLED (CONFIG_IPV6 ) +if (client_sk->sk->sk_family ==AF_INET6 ) +memcpy (&conn->inet6_addr, &client_sk->sk->sk_v6_daddr,16 ); +else + conn->inet_addr =inet_sk (client_sk->sk)->inet_daddr; +#else conn->inet_addr =inet_sk (client_sk->sk)->inet_daddr; +#endif conn->transport =KSMBD_TRANS (t);KSMBD_TRANS (t)->conn = conn;KSMBD_TRANS (t)->ops = &ksmbd_tcp_transport_ops;
@@ -231,7 +238,6 @@ static int ksmbd_kthread_fn(void *p) {struct socket *client_sk =NULL ;struct interface *iface = (struct interface *)p; -struct inet_sock *csk_inet;struct ksmbd_conn *conn;int ret;
@@ -254,13 +260,27 @@ static int ksmbd_kthread_fn(void *p)/* * Limits repeated connections from clients with the same IP. */ - csk_inet =inet_sk (client_sk->sk);down_read (&conn_list_lock); list_for_each_entry(conn, &conn_list, conns_list) -if (csk_inet->inet_daddr == conn->inet_addr) { +#if IS_ENABLED (CONFIG_IPV6 ) +if (client_sk->sk->sk_family ==AF_INET6 ) { +if (memcmp (&client_sk->sk->sk_v6_daddr, + &conn->inet6_addr,16 ) ==0 ) { + ret = -EAGAIN ; +break ; + } + }else if (inet_sk (client_sk->sk)->inet_daddr == + conn->inet_addr) { ret = -EAGAIN ;break ; } +#else +if (inet_sk (client_sk->sk)->inet_daddr == + conn->inet_addr) { + ret = -EAGAIN ; +break ; + } +#endif up_read (&conn_list_lock);if (ret == -EAGAIN )continue ;
Greg Kroah-Hartman
maintainerPATCH 347/587 tracing: fprobe-event: Sanitize wildcard for fprobe event name
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masami Hiramatsu (Google) <[email protected]>
commit ec879e1a0be8007aa232ffedcf6a6445dfc1a3d7 upstream.
Fprobe event accepts wildcards for the target functions, but unless user specifies its event name, it makes an event with the wildcards.
/sys/kernel/tracing # echo 'f mutex*' >> dynamic_events /sys/kernel/tracing # cat dynamic_events f:fprobes/mutex*__entry mutex* /sys/kernel/tracing # ls events/fprobes/
enable filter mutex*__entry
To fix this, replace the wildcard ('*') with an underscore.
--- kernel/trace/trace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace.h +1 -1
@@ -2053,7 +2053,7 @@ static inline bool is_good_system_name(cstatic inline void sanitize_event_name (char *name) {while (*name++ !='\0' ) -if (*name ==':' || *name =='.' ) +if (*name ==':' || *name =='.' || *name =='*' ) *name ='_' ; }
Greg Kroah-Hartman
maintainerPATCH 348/587 ext4: check fast symlink for ea_inode correctly
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andreas Dilger <[email protected]>
commit b4cc4a4077268522e3d0d34de4b2dc144e2330fa upstream.
The check for a fast symlink in the presence of only an external xattr inode is incorrect. If a fast symlink does not have an xattr block (i_file_acl == 0), but does have an external xattr inode that increases inode i_blocks, then the check for a fast symlink will incorrectly fail and __ext4_iget()->ext4_ind_check_inode() will report the inode is corrupt when it "validates" i_data[] on the next read:
# ln -s foo /mnt/tmp/bar
# setfattr -h -n trusted.test \
-v "$(yes | head -n 4000)" /mnt/tmp/bar
# umount /mnt/tmp
# mount /mnt/tmp
# ls -l /mnt/tmp
ls: cannot access '/mnt/tmp/bar': Structure needs cleaning
total 4
? l?????????? ? ? ? ? ? bar
# dmesg | tail -1
EXT4-fs error (device dm-8): __ext4_iget:5098:
inode #24578: block 7303014: comm ls: invalid block(note that "block 7303014" = 0x6f6f66 = "foo" in LE order).
ext4_inode_is_fast_symlink() should check the superblock EXT4_FEATURE_INCOMPAT_EA_INODE feature flag, not the inode EXT4_EA_INODE_FL, since the latter is only set on the xattr inode itself, and not on the inode that uses this xattr.
Reviewed-on: https://review.whamcloud.com/59879
Lustre-bug-id: https://jira.whamcloud.com/browse/LU-19121
--- fs/ext4/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ext4/inode.c +1 -1
@@ -146,7 +146,7 @@ static int ext4_meta_trans_blocks(struct*/ int ext4_inode_is_fast_symlink (struct inode *inode) { -if (!(EXT4_I (inode)->i_flags &EXT4_EA_INODE_FL )) { +if (!ext4_has_feature_ea_inode (inode->i_sb)) {int ea_blocks =EXT4_I (inode)->i_file_acl ?EXT4_CLUSTER_SIZE (inode->i_sb) >>9 :0 ;
Greg Kroah-Hartman
maintainerPATCH 349/587 ext4: fix fsmap end of range reporting with bigalloc
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ojaswin Mujoo <[email protected]>
commit bae76c035bf0852844151e68098c9b7cd63ef238 upstream.
With bigalloc enabled, the logic to report last extent has a bug since we try to use cluster units instead of block units. This can cause an issue where extra incorrect entries might be returned back to the user. This was flagged by generic/365 with 64k bs and -O bigalloc.
** Details of issue **
The issue was noticed on 5G 64k blocksize FS with -O bigalloc which has only 1 bg.
$ xfs_io -c "fsmap -d" /mnt/scratch
0: 253:48 [0..127]: static fs metadata 128 /* sb */
1: 253:48 [128..255]: special 102:1 128 /* gdt */ 3: 253:48 [256..383]: special 102:3 128 /* block bitmap */ 4: 253:48 [384..2303]: unknown 1920 /* flex bg empty space */
5: 253:48 [2304..2431]: special 102:4 128 /* inode bitmap */
6: 253:48 [2432..4351]: unknown 1920 /* flex bg empty space */
7: 253:48 [4352..6911]: inodes 2560
8: 253:48 [6912..538623]: unknown 531712 9: 253:48 [538624..10485759]: free space 9947136
The issue can be seen with:
$ xfs_io -c "fsmap -d 0 3" /mnt/scratch
0: 253:48 [0..127]: static fs metadata 128
1: 253:48 [384..2047]: unknown 1664
Only the first entry was expected to be returned but we get 2. This is because:
ext4_getfsmap_datadev()
first_cluster, last_cluster = 0
...
info->gfi_last = true;
ext4_getfsmap_datadev_helper(sb, end_ag, last_cluster + 1, 0, info);
fsb = C2B(1) = 16
fslen = 0
...
/* Merge in any relevant extents from the meta_list */
list_for_each_entry_safe(p, tmp, &info->gfi_meta_list, fmr_list) {
...
// since fsb = 16, considers all metadata which starts before 16 blockno
iter 1: error = ext4_getfsmap_helper(sb, info, p); // p = sb (0,1), nop
info->gfi_next_fsblk = 1
iter 2: error = ext4_getfsmap_helper(sb, info, p); // p = gdt (1,2), nop
info->gfi_next_fsblk = 2
iter 3: error = ext4_getfsmap_helper(sb, info, p); // p = blk bitmap (2,3), nop
info->gfi_next_fsblk = 3
iter 4: error = ext4_getfsmap_helper(sb, info, p); // p = ino bitmap (18,19)
if (rec_blk > info->gfi_next_fsblk) { // (18 > 3)
// emits an extra entry ** BUG **
}
}Fix this by directly calling ext4_getfsmap_datadev() with a dummy record that has fmr_physical set to (end_fsb + 1) instead of last_cluster + 1. By using the block instead of cluster we get the correct behavior.
Replacing ext4_getfsmap_datadev_helper() with ext4_getfsmap_helper() is okay since the gfi_lastfree and metadata checks in ext4_getfsmap_datadev_helper() are anyways redundant when we only want to emit the last allocated block of the range, as we have already taken care of emitting metadata and any last free blocks.
--- fs/ext4/fsmap.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
fs/ext4/fsmap.c +12 -3
@@ -526,6 +526,7 @@ static int ext4_getfsmap_datadev(structext4_group_t end_ag;ext4_grpblk_t first_cluster;ext4_grpblk_t last_cluster; +struct ext4_fsmap irec;int error =0 ; bofs =le32_to_cpu (sbi->s_es->s_first_data_block);
@@ -609,10 +610,18 @@ static int ext4_getfsmap_datadev(struct goto err; } -/* Report any gaps at the end of the bg */ +/* +* The dummy record below will cause ext4_getfsmap_helper() to report +* any allocated blocks at the end of the range. +*/ + irec.fmr_device =0 ; + irec.fmr_physical = end_fsb +1 ; + irec.fmr_length =0 ; + irec.fmr_owner =EXT4_FMR_OWN_FREE ; + irec.fmr_flags =0 ; + info->gfi_last = true; - error =ext4_getfsmap_datadev_helper (sb, end_ag, last_cluster +1 , -0 , info); + error =ext4_getfsmap_helper (sb, info, &irec);if (error) goto err;
Greg Kroah-Hartman
maintainerPATCH 350/587 ext4: fix reserved gdt blocks handling in fsmap
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ojaswin Mujoo <[email protected]>
commit 3ffbdd1f1165f1b2d6a94d1b1aabef57120deaf7 upstream.
In some cases like small FSes with no meta_bg and where the resize doesn't need extra gdt blocks as it can fit in the current one, s_reserved_gdt_blocks is set as 0, which causes fsmap to emit a 0 length entry, which is incorrect.
$ mkfs.ext4 -b 65536 -O bigalloc /dev/sda 5G $ mount /dev/sda /mnt/scratch $ xfs_io -c "fsmap -d" /mnt/scartch
0: 253:48 [0..127]: static fs metadata 128
1: 253:48 [128..255]: special 102:1 128
2: 253:48 [256..255]: special 102:2 0 <---- 0 len entry
3: 253:48 [256..383]: special 102:3 128Fix this by adding a check for this case.
--- fs/ext4/fsmap.c | 8 ++++++++ 1 file changed, 8 insertions(+)
fs/ext4/fsmap.c +8 -0
@@ -393,6 +393,14 @@ static unsigned int ext4_getfsmap_find_s/* Reserved GDT blocks */ if (!ext4_has_feature_meta_bg (sb) || metagroup < first_meta_bg) { len =le16_to_cpu (sbi->s_es->s_reserved_gdt_blocks); + +/* +* mkfs.ext4 can set s_reserved_gdt_blocks as 0 in some cases, +* check for that. +*/ +if (!len) +return 0 ; + error =ext4_getfsmap_fill (meta_list, fsb, len,EXT4_FMR_OWN_RESV_GDT );if (error)
Greg Kroah-Hartman
maintainerPATCH 351/587 ext4: dont try to clear the orphan_present feature block device is r/o
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Theodore Ts'o <[email protected]>
commit c5e104a91e7b6fa12c1dc2d8bf84abb7ef9b89ad upstream.
When the file system is frozen in preparation for taking an LVM snapshot, the journal is checkpointed and if the orphan_file feature is enabled, and the orphan file is empty, we clear the orphan_present feature flag. But if there are pending inodes that need to be removed the orphan_present feature flag can't be cleared.
The problem comes if the block device is read-only. In that case, we can't process the orphan inode list, so it is skipped in ext4_orphan_cleanup(). But then in ext4_mark_recovery_complete(), this results in the ext4 error "Orphan file not empty on read-only fs" firing and the file system mount is aborted.
Fix this by clearing the needs_recovery flag in the block device is read-only. We do this after the call to ext4_load_and_init-journal() since there are some error checks need to be done in case the journal needs to be replayed and the block device is read-only, or if the block device containing the externa journal is read-only, etc.
--- fs/ext4/super.c | 2 ++ 1 file changed, 2 insertions(+)
fs/ext4/super.c +2 -0
@@ -5398,6 +5398,8 @@ static int __ext4_fill_super(struct fs_c err =ext4_load_and_init_journal (sb, es, ctx);if (err) goto failed_mount3a; +if (bdev_read_only (sb->s_bdev)) + needs_recovery =0 ; }else if (test_opt (sb,NOLOAD ) && !sb_rdonly (sb) &&ext4_has_feature_journal_needs_recovery (sb)) { ext4_msg(sb, KERN_ERR, "required journal recovery "
Greg Kroah-Hartman
maintainerPATCH 352/587 ext4: use kmalloc_array() for array space allocation
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Liao Yuanhong <[email protected]>
commit 76dba1fe277f6befd6ef650e1946f626c547387a upstream.
Replace kmalloc(size * sizeof) with kmalloc_array() for safer memory allocation and overflow prevention.
--- fs/ext4/orphan.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ext4/orphan.c +3 -2
@@ -590,8 +590,9 @@ int ext4_init_orphan_info(struct super_b } oi->of_blocks = inode->i_size >> sb->s_blocksize_bits; oi->of_csum_seed =EXT4_I (inode)->i_csum_seed; - oi->of_binfo =kmalloc (oi->of_blocks*sizeof (struct ext4_orphan_block ), -GFP_KERNEL ); + oi->of_binfo =kmalloc_array (oi->of_blocks, +sizeof (struct ext4_orphan_block ), +GFP_KERNEL );if (!oi->of_binfo) { ret = -ENOMEM ; goto out_put;
Greg Kroah-Hartman
maintainerPATCH 353/587 ext4: fix hole length calculation overflow in non-extent inodes
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Yi <[email protected]>
commit 02c7f7219ac0e2277b3379a3a0e9841ef464b6d4 upstream.
In a filesystem with a block size larger than 4KB, the hole length calculation for a non-extent inode in ext4_ind_map_blocks() can easily exceed INT_MAX. Then it could return a zero length hole and trigger the following waring and infinite in the iomap infrastructure.
------------[ cut here ]------------ WARNING: CPU: 3 PID: 434101 at fs/iomap/iter.c:34 iomap_iter_done+0x148/0x190 CPU: 3 UID: 0 PID: 434101 Comm: fsstress Not tainted 6.16.0-rc7+ #128 PREEMPT(voluntary) Hardware name: QEMU KVM Virtual Machine, BIOS unknown 2/2/2022 pstate: 60400005 (nZCv daif +PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : iomap_iter_done+0x148/0x190 lr : iomap_iter+0x174/0x230 sp : ffff8000880af740 x29: ffff8000880af740 x28: ffff0000db8e6840 x27: 0000000000000000 x26: 0000000000000000 x25: ffff8000880af830 x24: 0000004000000000 x23: 0000000000000002 x22: 000001bfdbfa8000 x21: ffffa6a41c002e48 x20: 0000000000000001 x19: ffff8000880af808 x18: 0000000000000000 x17: 0000000000000000 x16: ffffa6a495ee6cd0 x15: 0000000000000000 x14: 00000000000003d4 x13: 00000000fa83b2da x12: 0000b236fc95f18c x11: ffffa6a4978b9c08 x10: 0000000000001da0 x9 : ffffa6a41c1a2a44 x8 : ffff8000880af5c8 x7 : 0000000001000000 x6 : 0000000000000000 x5 : 0000000000000004 x4 : 000001bfdbfa8000 x3 : 0000000000000000 x2 : 0000000000000000 x1 : 0000004004030000 x0 : 0000000000000000 Call trace: iomap_iter_done+0x148/0x190 (P) iomap_iter+0x174/0x230 iomap_fiemap+0x154/0x1d8 ext4_fiemap+0x110/0x140 [ext4] do_vfs_ioctl+0x4b8/0xbc0 __arm64_sys_ioctl+0x8c/0x120 invoke_syscall+0x6c/0x100 el0_svc_common.constprop.0+0x48/0xf0 do_el0_svc+0x24/0x38 el0_svc+0x38/0x120 el0t_64_sync_handler+0x10c/0x138 el0t_64_sync+0x198/0x1a0 ---[ end trace 0000000000000000 ]---
--- fs/ext4/indirect.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/ext4/indirect.c +2 -2
@@ -539,7 +539,7 @@ int ext4_ind_map_blocks(handle_t *handleint indirect_blks;int blocks_to_boundary =0 ;int depth; -int count =0 ; +u64 count =0 ;ext4_fsblk_t first_block =0 ;trace_ext4_ind_map_blocks_enter (inode, map->m_lblk, map->m_len, flags);
@@ -588,7 +588,7 @@ int ext4_ind_map_blocks(handle_t *handle count++;/* Fill in size of a hole we found */ map->m_pblk =0 ; - map->m_len = min_t(unsigned int, map->m_len, count); + map->m_len =umin (map->m_len, count); goto cleanup; }
Greg Kroah-Hartman
maintainerPATCH 354/587 btrfs: zoned: fix write time activation failure for metadata block group
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Naohiro Aota <[email protected]>
commit 5c4b93f4c8e5c53574c1a48d66a27a2c68b414af upstream.
Since commit 13bb483d32ab ("btrfs: zoned: activate metadata block group on write time"), we activate a metadata block group at the write time. If the zone capacity is small enough, we can allocate the entire region before the first write. Then, we hit the btrfs_zoned_bg_is_full() in btrfs_zone_activate() and the activation fails.
For a data block group, we activate it at the allocation time and we should check the fullness condition in the caller side. Add, a WARN to check the fullness condition.
For a metadata block group, we don't need the fullness check because we activate it at the write time. Instead, activating it once it is written should be invalid. Catch that with a WARN too.
--- fs/btrfs/zoned.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
fs/btrfs/zoned.c +9 -4
@@ -1992,10 +1992,15 @@ bool btrfs_zone_activate(struct btrfs_bl goto out_unlock; } -/* No space left */ -if (btrfs_zoned_bg_is_full (block_group)) { - ret = false; - goto out_unlock; +if (block_group->flags &BTRFS_BLOCK_GROUP_DATA ) { +/* The caller should check if the block group is full. */ +if (WARN_ON_ONCE (btrfs_zoned_bg_is_full (block_group))) { + ret = false; + goto out_unlock; + } + }else { +/* Since it is already written, it should have been active. */ +WARN_ON_ONCE (block_group->meta_write_pointer != block_group->start); }for (i =0 ; i < map->num_stripes; i++) {
Greg Kroah-Hartman
maintainerPATCH 355/587 arm64: dts: ti: k3-pinctrl: Enable Schmitt Trigger by default
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alexander Sverdlin <[email protected]>
commit 5b272127884bded21576a6ddceca13725a351c63 upstream.
Switch Schmitt Trigger functions for PIN_INPUT* macros by default. This is HW PoR configuration, the slew rate requirements without ST enabled are pretty tough for these devices. We've noticed spurious GPIO interrupts even with noise-free edges but not meeting slew rate requirements (3.3E+6 V/s for 3.3v LVCMOS).
It's not obvious why one might want to disable the PoR-enabled ST on any pin. Just enable it by default. As it's not possible to provide OR-able macros to disable the ST, shall anyone require it, provide a set of new macros with _NOST suffix.
--- arch/arm64/boot/dts/ti/k3-pinctrl.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
arch/arm64/boot/dts/ti/k3-pinctrl.h +12 -3
@@ -8,11 +8,16 @@#ifndef DTS_ARM64_TI_K3_PINCTRL_H #define DTS_ARM64_TI_K3_PINCTRL_H +#define ST_EN_SHIFT (14)#define PULLUDEN_SHIFT (16)#define PULLTYPESEL_SHIFT (17)#define RXACTIVE_SHIFT (18)#define DEBOUNCE_SHIFT (11) +/* Schmitt trigger configuration */ +#define ST_DISABLE (0 << ST_EN_SHIFT) +#define ST_ENABLE (1 << ST_EN_SHIFT) +#define PULL_DISABLE (1 << PULLUDEN_SHIFT)#define PULL_ENABLE (0 << PULLUDEN_SHIFT)
@@ -26,9 +31,13 @@#define PIN_OUTPUT (INPUT_DISABLE | PULL_DISABLE)#define PIN_OUTPUT_PULLUP (INPUT_DISABLE | PULL_UP)#define PIN_OUTPUT_PULLDOWN (INPUT_DISABLE | PULL_DOWN) -#define PIN_INPUT (INPUT_EN | PULL_DISABLE) -#define PIN_INPUT_PULLUP (INPUT_EN | PULL_UP) -#define PIN_INPUT_PULLDOWN (INPUT_EN | PULL_DOWN) +#define PIN_INPUT (INPUT_EN | ST_ENABLE | PULL_DISABLE) +#define PIN_INPUT_PULLUP (INPUT_EN | ST_ENABLE | PULL_UP) +#define PIN_INPUT_PULLDOWN (INPUT_EN | ST_ENABLE | PULL_DOWN) +/* Input configurations with Schmitt Trigger disabled */ +#define PIN_INPUT_NOST (INPUT_EN | PULL_DISABLE) +#define PIN_INPUT_PULLUP_NOST (INPUT_EN | PULL_UP) +#define PIN_INPUT_PULLDOWN_NOST (INPUT_EN | PULL_DOWN)#define PIN_DEBOUNCE_DISABLE (0 << DEBOUNCE_SHIFT)#define PIN_DEBOUNCE_CONF1 (1 << DEBOUNCE_SHIFT)
Greg Kroah-Hartman
maintainerPATCH 356/587 arm64: dts: ti: k3-am62a7-sk: fix pinmux for main_uart1
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hong Guan <[email protected]>
commit 8e44ac61abaae56fc6eb537a04ed78b458c5b984 upstream.
main_uart1 reserved for TIFS firmware traces is routed to the onboard FT4232 via a FET switch which is connected to pin A21 and B21 of the SoC and not E17 and C17. Fix it.
--- arch/arm64/boot/dts/ti/k3-am62a7-sk.dts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/boot/dts/ti/k3-am62a7-sk.dts +2 -2
@@ -144,8 +144,8 @@ main_uart1_pins_default: main-uart1-default-pins { pinctrl-single,pins = < - AM62AX_IOPAD(0x01e8, PIN_INPUT, 1) /* (C17) I2C1_SCL.UART1_RXD */ - AM62AX_IOPAD(0x01ec, PIN_OUTPUT, 1) /* (E17) I2C1_SDA.UART1_TXD */ + AM62AX_IOPAD(0x01ac, PIN_INPUT, 2) /* (B21) MCASP0_AFSR.UART1_RXD */ + AM62AX_IOPAD(0x01b0, PIN_OUTPUT, 2) /* (A21) MCASP0_ACLKR.UART1_TXD */ AM62AX_IOPAD(0x0194, PIN_INPUT, 2) /* (C19) MCASP0_AXR3.UART1_CTSn */ AM62AX_IOPAD(0x0198, PIN_OUTPUT, 2) /* (B19) MCASP0_AXR2.UART1_RTSn */ >;
Greg Kroah-Hartman
maintainerPATCH 357/587 arm64: dts: ti: k3-am62-verdin: Enable pull-ups on I2C buses
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Emanuele Ghidoli <[email protected]>
commit bdf4252f736cc1d2a8e3e633c70fe6c728f0756e upstream.
Enable internal bias pull-ups on the SoC-side I2C buses that do not have external pull resistors populated on the SoM. This ensures proper default line levels.
--- arch/arm64/boot/dts/ti/k3-am62-verdin.dtsi | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/arm64/boot/dts/ti/k3-am62-verdin.dtsi +6 -6
@@ -448,16 +448,16 @@ /* Verdin I2C_2_DSI */ pinctrl_i2c2: main-i2c2-default-pins { pinctrl-single,pins = < - AM62X_IOPAD(0x00b0, PIN_INPUT, 1) /* (K22) GPMC0_CSn2.I2C2_SCL */ /* SODIMM 55 */ - AM62X_IOPAD(0x00b4, PIN_INPUT, 1) /* (K24) GPMC0_CSn3.I2C2_SDA */ /* SODIMM 53 */ + AM62X_IOPAD(0x00b0, PIN_INPUT_PULLUP, 1) /* (K22) GPMC0_CSn2.I2C2_SCL */ /* SODIMM 55 */ + AM62X_IOPAD(0x00b4, PIN_INPUT_PULLUP, 1) /* (K24) GPMC0_CSn3.I2C2_SDA */ /* SODIMM 53 */ >; }; /* Verdin I2C_4_CSI */ pinctrl_i2c3: main-i2c3-default-pins { pinctrl-single,pins = < - AM62X_IOPAD(0x01d0, PIN_INPUT, 2) /* (A15) UART0_CTSn.I2C3_SCL */ /* SODIMM 95 */ - AM62X_IOPAD(0x01d4, PIN_INPUT, 2) /* (B15) UART0_RTSn.I2C3_SDA */ /* SODIMM 93 */ + AM62X_IOPAD(0x01d0, PIN_INPUT_PULLUP, 2) /* (A15) UART0_CTSn.I2C3_SCL */ /* SODIMM 95 */ + AM62X_IOPAD(0x01d4, PIN_INPUT_PULLUP, 2) /* (B15) UART0_RTSn.I2C3_SDA */ /* SODIMM 93 */ >; };
@@ -729,8 +729,8 @@ /* Verdin I2C_3_HDMI */ pinctrl_mcu_i2c0: mcu-i2c0-default-pins { pinctrl-single,pins = < - AM62X_MCU_IOPAD(0x0044, PIN_INPUT, 0) /* (A8) MCU_I2C0_SCL */ /* SODIMM 59 */ - AM62X_MCU_IOPAD(0x0048, PIN_INPUT, 0) /* (D10) MCU_I2C0_SDA */ /* SODIMM 57 */ + AM62X_MCU_IOPAD(0x0044, PIN_INPUT_PULLUP, 0) /* (A8) MCU_I2C0_SCL */ /* SODIMM 59 */ + AM62X_MCU_IOPAD(0x0048, PIN_INPUT_PULLUP, 0) /* (D10) MCU_I2C0_SDA */ /* SODIMM 57 */ >; };
Greg Kroah-Hartman
maintainerPATCH 358/587 dt-bindings: display: sprd,sharkl3-dpu: Fix missing clocks constraints
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krzysztof Kozlowski <[email protected]>
commit 934da599e694d476f493d3927a30414e98a81561 upstream.
'minItems' alone does not impose upper bound, unlike 'maxItems' which implies lower bound. Add missing clock constraint so the list will have exact number of items (clocks).
--- Documentation/devicetree/bindings/display/sprd/sprd,sharkl3-dpu.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/devicetree/bindings/display/sprd/sprd,sharkl3-dpu.yaml +1 -1
@@ -25,7 +25,7 @@ properties: maxItems: 1 clocks: - minItems: 2 + maxItems: 2 clock-names: items:
Greg Kroah-Hartman
maintainerPATCH 359/587 dt-bindings: display: sprd,sharkl3-dsi-host: Fix missing clocks constraints
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Krzysztof Kozlowski <[email protected]>
commit 2558df8c13ae3bd6c303b28f240ceb0189519c91 upstream.
'minItems' alone does not impose upper bound, unlike 'maxItems' which implies lower bound. Add missing clock constraint so the list will have exact number of items (clocks).
--- Documentation/devicetree/bindings/display/sprd/sprd,sharkl3-dsi-host.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/devicetree/bindings/display/sprd/sprd,sharkl3-dsi-host.yaml +1 -1
@@ -20,7 +20,7 @@ properties: maxItems: 2 clocks: - minItems: 1 + maxItems: 1 clock-names: items:
Greg Kroah-Hartman
maintainerPATCH 360/587 scsi: mpi3mr: Fix race between config read submit and interrupt completion
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ranjan Kumar <[email protected]>
commit e6327c4acf925bb6d6d387d76fc3bd94471e10d8 upstream.
The "is_waiting" flag was updated after calling complete(), which could lead to a race where the waiting thread wakes up before the flag is cleared. This may cause a missed wakeup or stale state check.
Reorder the operations to update "is_waiting" before signaling completion to ensure consistent state.
--- drivers/scsi/mpi3mr/mpi3mr_fw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/mpi3mr/mpi3mr_fw.c +1 -1
@@ -411,8 +411,8 @@ static void mpi3mr_process_admin_reply_d MPI3MR_SENSE_BUF_SZ); }if (cmdptr->is_waiting) { -complete (&cmdptr->done); cmdptr->is_waiting =0 ; +complete (&cmdptr->done); }else if (cmdptr->callback) cmdptr->callback (mrioc, cmdptr); }
Greg Kroah-Hartman
maintainerPATCH 361/587 ata: libata-scsi: Fix ata_to_sense_error() status handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Damien Le Moal <[email protected]>
commit cf3fc037623c54de48d2ec1a1ee686e2d1de2d45 upstream.
Commit 8ae720449fca ("libata: whitespace fixes in ata_to_sense_error()") inadvertantly added the entry 0x40 (ATA_DRDY) to the stat_table array in the function ata_to_sense_error(). This entry ties a failed qc which has a status filed equal to ATA_DRDY to the sense key ILLEGAL REQUEST with the additional sense code UNALIGNED WRITE COMMAND. This entry will be used to generate a failed qc sense key and sense code when the qc is missing sense data and there is no match for the qc error field in the sense_table array of ata_to_sense_error().
As a result, for a failed qc for which we failed to get sense data (e.g. read log 10h failed if qc is an NCQ command, or REQUEST SENSE EXT command failed for the non-ncq case, the user very often end up seeing the completely misleading "unaligned write command" error, even if qc was not a write command. E.g.:
sd 0:0:0:0: [sda] tag#12 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s sd 0:0:0:0: [sda] tag#12 Sense Key : Illegal Request [current]
sd 0:0:0:0: [sda] tag#12 Add. Sense: Unaligned write command
sd 0:0:0:0: [sda] tag#12 CDB: Read(10) 28 00 00 00 10 00 00 00 08 00
I/O error, dev sda, sector 4096 op 0x0:(READ) flags 0x80700 phys_seg 1 prio class 0
Fix this by removing the ATA_DRDY entry from the stat_table array so that we default to always returning ABORTED COMMAND without any additional sense code, since we do not know any better. The entry 0x08 (ATA_DRQ) is also removed since signaling ABORTED COMMAND with a parity error is also misleading (as a parity error would likely be signaled through a bus error). So for this case, also default to returning ABORTED COMMAND without any additional sense code. With this, the previous example error case becomes:
sd 0:0:0:0: [sda] tag#17 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_OK cmd_age=0s sd 0:0:0:0: [sda] tag#17 Sense Key : Aborted Command [current]
sd 0:0:0:0: [sda] tag#17 Add. Sense: No additional sense information
sd 0:0:0:0: [sda] tag#17 CDB: Read(10) 28 00 00 00 10 00 00 00 08 00
I/O error, dev sda, sector 4096 op 0x0:(READ) flags 0x80700 phys_seg 1 prio class 0
Together with these fixes, refactor stat_table to make it more readable by putting the entries comments in front of the entries and using the defined status bits macros instead of hardcoded values.
--- drivers/ata/libata-scsi.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-)
drivers/ata/libata-scsi.c +8 -12
@@ -856,18 +856,14 @@ static void ata_to_sense_error(unsigned {0xFF, 0xFF, 0xFF, 0xFF}, // END mark };static const unsigned char stat_table[][4 ] = { -/* Must be first because BUSY means no other bits valid */ - {0x80 ,ABORTED_COMMAND ,0x47 ,0x00 }, -// Busy, fake parity for now - {0x40 ,ILLEGAL_REQUEST ,0x21 ,0x04 }, -// Device ready, unaligned write command - {0x20 ,HARDWARE_ERROR ,0x44 ,0x00 }, -// Device fault, internal target failure - {0x08 ,ABORTED_COMMAND ,0x47 ,0x00 }, -// Timed out in xfer, fake parity for now - {0x04 ,RECOVERED_ERROR ,0x11 ,0x00 }, -// Recovered ECC error Medium error, recovered - {0xFF ,0xFF ,0xFF ,0xFF },// END mark +/* Busy: must be first because BUSY means no other bits valid */ + {ATA_BUSY ,ABORTED_COMMAND ,0x00 ,0x00 }, +/* Device fault: INTERNAL TARGET FAILURE */ + {ATA_DF ,HARDWARE_ERROR ,0x44 ,0x00 }, +/* Corrected data error */ + {ATA_CORR ,RECOVERED_ERROR ,0x00 ,0x00 }, + + {0xFF ,0xFF ,0xFF ,0xFF },/* END mark */ };/*
Greg Kroah-Hartman
maintainerPATCH 362/587 scsi: ufs: ufs-pci: Fix hibernate state transition for Intel MTL-like host controllers
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Archana Patni <[email protected]>
commit 4428ddea832cfdb63e476eb2e5c8feb5d36057fe upstream.
UFSHCD core disables the UIC completion interrupt when issuing UIC hibernation commands, and re-enables it afterwards if it was enabled to start with, refer ufshcd_uic_pwr_ctrl(). For Intel MTL-like host controllers, accessing the register to re-enable the interrupt disrupts the state transition.
Use hibern8_notify variant operation to disable the interrupt during the entire hibernation, thereby preventing the disruption.
--- drivers/ufs/host/ufshcd-pci.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+)
drivers/ufs/host/ufshcd-pci.c +27 -0
@@ -213,6 +213,32 @@ out:return ret; } +static void ufs_intel_ctrl_uic_compl (struct ufs_hba *hba,bool enable) +{ +u32 set =ufshcd_readl (hba,REG_INTERRUPT_ENABLE ); + +if (enable) + set |=UIC_COMMAND_COMPL ; +else + set &= ~UIC_COMMAND_COMPL ; +ufshcd_writel (hba, set,REG_INTERRUPT_ENABLE ); +} + +static void ufs_intel_mtl_h8_notify (struct ufs_hba *hba, +enum uic_cmd_dme cmd, +enum ufs_notify_change_status status) +{ +/* +* Disable UIC COMPL INTR to prevent access to UFSHCI after +* checking HCS.UPMCRS +*/ +if (status ==PRE_CHANGE && cmd ==UIC_CMD_DME_HIBER_ENTER ) +ufs_intel_ctrl_uic_compl (hba, false); + +if (status ==POST_CHANGE && cmd ==UIC_CMD_DME_HIBER_EXIT ) +ufs_intel_ctrl_uic_compl (hba, true); +} +#define INTEL_ACTIVELTR 0x804#define INTEL_IDLELTR 0x808
@@ -487,6 +513,7 @@ static struct ufs_hba_variant_ops ufs_in .init = ufs_intel_mtl_init, .exit = ufs_intel_common_exit, .hce_enable_notify = ufs_intel_hce_enable_notify, + .hibern8_notify = ufs_intel_mtl_h8_notify, .link_startup_notify = ufs_intel_link_startup_notify, .resume = ufs_intel_resume, .device_reset = ufs_intel_device_reset,
Greg Kroah-Hartman
maintainerPATCH 363/587 scsi: ufs: ufs-pci: Fix default runtime and system PM levels
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Adrian Hunter <[email protected]>
commit 6de7435e6b81fe52c0ab4c7e181f6b5decd18eb1 upstream.
Intel MTL-like host controllers support auto-hibernate. Using auto-hibernate with manual (driver initiated) hibernate produces more complex operation. For example, the host controller will have to exit auto-hibernate simply to allow the driver to enter hibernate state manually. That is not recommended.
The default rpm_lvl and spm_lvl is 3, which includes manual hibernate.
Change the default values to 2, which does not.
Note, to be simpler to backport to stable kernels, utilize the UFS PCI driver's ->late_init() call back. Recent commits have made it possible to set up a controller-specific default in the regular ->init() call back, but not all stable kernels have those changes.
--- drivers/ufs/host/ufshcd-pci.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
drivers/ufs/host/ufshcd-pci.c +14 -1
@@ -465,10 +465,23 @@ static int ufs_intel_adl_init(struct ufsreturn ufs_intel_common_init (hba); } +static void ufs_intel_mtl_late_init (struct ufs_hba *hba) +{ + hba->rpm_lvl =UFS_PM_LVL_2 ; + hba->spm_lvl =UFS_PM_LVL_2 ; +} +static int ufs_intel_mtl_init (struct ufs_hba *hba) { +struct ufs_host *ufs_host; +int err; + hba->caps |=UFSHCD_CAP_CRYPTO |UFSHCD_CAP_WB_EN ; -return ufs_intel_common_init (hba); + err =ufs_intel_common_init (hba); +/* Get variant after it is set in ufs_intel_common_init() */ + ufs_host =ufshcd_get_variant (hba); + ufs_host->late_init = ufs_intel_mtl_late_init; +return err; }static struct ufs_hba_variant_ops ufs_intel_cnl_hba_vops = {
Greg Kroah-Hartman
maintainerPATCH 364/587 ata: libata-scsi: Fix CDL control
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Igor Pylypiv <[email protected]>
commit 58768b0563916ddcb73d8ed26ede664915f8df31 upstream.
Delete extra checks for the ATA_DFLAG_CDL_ENABLED flag that prevent SET FEATURES command from being issued to a drive when NCQ commands are active.
ata_mselect_control_ata_feature() sets / clears the ATA_DFLAG_CDL_ENABLED flag during the translation of MODE SELECT to SET FEATURES. If SET FEATURES gets deferred due to outstanding NCQ commands, the original MODE SELECT command will be re-queued. When the re-queued MODE SELECT goes through the ata_mselect_control_ata_feature() translation again, SET FEATURES will not be issued because ATA_DFLAG_CDL_ENABLED has been already set or cleared by the initial translation of MODE SELECT.
The ATA_DFLAG_CDL_ENABLED checks in ata_mselect_control_ata_feature() are safe to remove because scsi_cdl_enable() implements a similar logic that avoids enabling CDL if it has been enabled already.
--- drivers/ata/libata-scsi.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/ata/libata-scsi.c +3 -8
@@ -3782,21 +3782,16 @@ static int ata_mselect_control_ata_featu/* Check cdl_ctrl */ switch (buf[0 ] &0x03 ) {case 0 : -/* Disable CDL if it is enabled */ -if (!(dev->flags &ATA_DFLAG_CDL_ENABLED )) -return 0 ; +/* Disable CDL */ ata_dev_dbg (dev,"Disabling CDL\n" ); cdl_action =0 ; dev->flags &= ~ATA_DFLAG_CDL_ENABLED ;break ;case 0x02 :/* -* Enable CDL if not already enabled. Since this is mutually -* exclusive with NCQ priority, allow this only if NCQ priority -* is disabled. +* Enable CDL. Since CDL is mutually exclusive with NCQ +* priority, allow this only if NCQ priority is disabled. */ -if (dev->flags &ATA_DFLAG_CDL_ENABLED ) -return 0 ;if (dev->flags &ATA_DFLAG_NCQ_PRIO_ENABLED ) {ata_dev_err (dev,"NCQ priority must be disabled to enable CDL\n" );
Greg Kroah-Hartman
maintainerPATCH 365/587 soc: qcom: mdt_loader: Ensure we dont read past the ELF header
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bjorn Andersson <[email protected]>
commit 9f9967fed9d066ed3dae9372b45ffa4f6fccfeef upstream.
When the MDT loader is used in remoteproc, the ELF header is sanitized beforehand, but that's not necessary the case for other clients.
Validate the size of the firmware buffer to ensure that we don't read past the end as we iterate over the header. e_phentsize and e_shentsize are validated as well, to ensure that the assumptions about step size in the traversal are valid.
--- drivers/soc/qcom/mdt_loader.c | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
drivers/soc/qcom/mdt_loader.c +43 -0
@@ -17,6 +17,37 @@#include <linux/slab.h> #include <linux/soc/qcom/mdt_loader.h> +static bool mdt_header_valid (const struct firmware *fw) +{ +const struct elf32_hdr *ehdr; +size_t phend; +size_t shend; + +if (fw->size <sizeof (*ehdr)) +return false; + + ehdr = (struct elf32_hdr *)fw->data; + +if (memcmp (ehdr->e_ident,ELFMAG ,SELFMAG )) +return false; + +if (ehdr->e_phentsize !=sizeof (struct elf32_phdr )) +return -EINVAL ; + + phend =size_add (size_mul (sizeof (struct elf32_phdr ), ehdr->e_phnum), ehdr->e_phoff); +if (phend > fw->size) +return false; + +if (ehdr->e_shentsize !=sizeof (struct elf32_shdr )) +return -EINVAL ; + + shend =size_add (size_mul (sizeof (struct elf32_shdr ), ehdr->e_shnum), ehdr->e_shoff); +if (shend > fw->size) +return false; + +return true; +} +static bool mdt_phdr_valid (const struct elf32_phdr *phdr) {if (phdr->p_type !=PT_LOAD )
@@ -84,6 +115,9 @@ ssize_t qcom_mdt_get_size(const struct fphys_addr_t max_addr =0 ;int i; +if (!mdt_header_valid (fw)) +return -EINVAL ; + ehdr = (struct elf32_hdr *)fw->data; phdrs = (struct elf32_phdr *)(fw->data + ehdr->e_phoff);
@@ -136,6 +170,9 @@ void *qcom_mdt_read_metadata(const strucssize_t ret;void *data; +if (!mdt_header_valid (fw)) +return ERR_PTR (-EINVAL ); + ehdr = (struct elf32_hdr *)fw->data; phdrs = (struct elf32_phdr *)(fw->data + ehdr->e_phoff);
@@ -216,6 +253,9 @@ int qcom_mdt_pas_init(struct device *devint ret;int i; +if (!mdt_header_valid (fw)) +return -EINVAL ; + ehdr = (struct elf32_hdr *)fw->data; phdrs = (struct elf32_phdr *)(fw->data + ehdr->e_phoff);
@@ -312,6 +352,9 @@ static int __qcom_mdt_load(struct deviceif (!fw || !mem_region || !mem_phys || !mem_size)return -EINVAL ; +if (!mdt_header_valid (fw)) +return -EINVAL ; + is_split =qcom_mdt_bins_are_split (fw, fw_name); ehdr = (struct elf32_hdr *)fw->data; phdrs = (struct elf32_phdr *)(fw->data + ehdr->e_phoff);
Greg Kroah-Hartman
maintainerPATCH 366/587 zynq_fpga: use sgtable-based scatterlist wrappers
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Marek Szyprowski <[email protected]>
commit 37e00703228ab44d0aacc32a97809a4f6f58df1b upstream.
Use common wrappers operating directly on the struct sg_table objects to fix incorrect use of statterlists related calls. dma_unmap_sg() function has to be called with the number of elements originally passed to the dma_map_sg() function, not the one returned in sgtable's nents.
--- drivers/fpga/zynq-fpga.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/fpga/zynq-fpga.c +2 -2
@@ -406,7 +406,7 @@ static int zynq_fpga_ops_write(struct fp } priv->dma_nelms = -dma_map_sg (mgr->dev.parent, sgt->sgl, sgt->nents,DMA_TO_DEVICE ); +dma_map_sgtable (mgr->dev.parent, sgt,DMA_TO_DEVICE ,0 );if (priv->dma_nelms ==0 ) {dev_err (&mgr->dev,"Unable to DMA map (TO_DEVICE)\n" );return -ENOMEM ;
@@ -478,7 +478,7 @@ out_clk:clk_disable (priv->clk); out_free: -dma_unmap_sg (mgr->dev.parent, sgt->sgl, sgt->nents,DMA_TO_DEVICE ); +dma_unmap_sgtable (mgr->dev.parent, sgt,DMA_TO_DEVICE ,0 );return err; }
Greg Kroah-Hartman
maintainerPATCH 367/587 iio: imu: bno055: fix OOB access of hw_xlate array
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Lechner <[email protected]>
commit 399b883ec828e436f1a721bf8551b4da8727e65b upstream.
Fix a potential out-of-bounds array access of the hw_xlate array in bno055.c.
In bno055_get_regmask(), hw_xlate was iterated over the length of the vals array instead of the length of the hw_xlate array. In the case of bno055_gyr_scale, the vals array is larger than the hw_xlate array, so this could result in an out-of-bounds access. In practice, this shouldn't happen though because a match should always be found which breaks out of the for loop before it iterates beyond the end of the hw_xlate array.
By adding a new hw_xlate_len field to the bno055_sysfs_attr, we can be sure we are iterating over the correct length.
--- drivers/iio/imu/bno055/bno055.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/iio/imu/bno055/bno055.c +8 -3
@@ -118,6 +118,7 @@ struct bno055_sysfs_attr {int len;int *fusion_vals;int *hw_xlate; +int hw_xlate_len;int type; };
@@ -170,20 +171,24 @@ static int bno055_gyr_scale_vals[] = { 1000, 1877467, 2000, 1877467, }; +static int bno055_gyr_scale_hw_xlate[] = {0 ,1 ,2 ,3 ,4 };static struct bno055_sysfs_attr bno055_gyr_scale = { .vals = bno055_gyr_scale_vals, .len =ARRAY_SIZE (bno055_gyr_scale_vals), .fusion_vals = (int []){1 ,900 }, - .hw_xlate = (int []){4 ,3 ,2 ,1 ,0 }, + .hw_xlate = bno055_gyr_scale_hw_xlate, + .hw_xlate_len =ARRAY_SIZE (bno055_gyr_scale_hw_xlate), .type =IIO_VAL_FRACTIONAL , };static int bno055_gyr_lpf_vals[] = {12 ,23 ,32 ,47 ,64 ,116 ,230 ,523 }; +static int bno055_gyr_lpf_hw_xlate[] = {5 ,4 ,7 ,3 ,6 ,2 ,1 ,0 };static struct bno055_sysfs_attr bno055_gyr_lpf = { .vals = bno055_gyr_lpf_vals, .len =ARRAY_SIZE (bno055_gyr_lpf_vals), .fusion_vals = (int []){32 }, - .hw_xlate = (int []){5 ,4 ,7 ,3 ,6 ,2 ,1 ,0 }, + .hw_xlate = bno055_gyr_lpf_hw_xlate, + .hw_xlate_len =ARRAY_SIZE (bno055_gyr_lpf_hw_xlate), .type =IIO_VAL_INT , };
@@ -561,7 +566,7 @@ static int bno055_get_regmask(struct bno idx = (hwval & mask) >> shift;if (attr->hw_xlate) -for (i =0 ; i < attr->len; i++) +for (i =0 ; i < attr->hw_xlate_len; i++)if (attr->hw_xlate[i] == idx) { idx = i;break ;
Greg Kroah-Hartman
maintainerPATCH 368/587 iio: adc: ad_sigma_delta: change to buffer predisable
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: David Lechner <[email protected]>
commit 66d4374d97f85516b5a22418c5e798aed2606dec upstream.
Change the buffer disable callback from postdisable to predisable. This balances the existing posteanble callback. Using postdisable with posteanble can be problematic, for example, if update_scan_mode fails, it would call postdisable without ever having called posteanble, so the drivers using this would be in an unexpected state when postdisable was called.
--- drivers/iio/adc/ad_sigma_delta.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/adc/ad_sigma_delta.c +2 -2
@@ -406,7 +406,7 @@ err_unlock:return ret; } -static int ad_sd_buffer_postdisable (struct iio_dev *indio_dev) +static int ad_sd_buffer_predisable (struct iio_dev *indio_dev) {struct ad_sigma_delta *sigma_delta =iio_device_get_drvdata (indio_dev);
@@ -534,7 +534,7 @@ static bool ad_sd_validate_scan_mask(strstatic const struct iio_buffer_setup_ops ad_sd_buffer_setup_ops = { .postenable = &ad_sd_buffer_postenable, - .postdisable = &ad_sd_buffer_postdisable, + .predisable = &ad_sd_buffer_predisable, .validate_scan_mask = &ad_sd_validate_scan_mask, };
Greg Kroah-Hartman
maintainerPATCH 369/587 wifi: brcmsmac: Remove const from tbl_ptr parameter in wlc_lcnphy_common_read_table()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nathan Chancellor <[email protected]>
commit 81284e86bf8849f8e98e8ead3ff5811926b2107f upstream.
A new warning in clang [1] complains that diq_start in wlc_lcnphy_tx_iqlo_cal() is passed uninitialized as a const pointer to wlc_lcnphy_common_read_table():
drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_lcn.c:2728:13: error: variable 'diq_start' is uninitialized when passed as a const pointer argument here [-Werror,-Wuninitialized-const-pointer]
2728 | &diq_start, 1, 16, 69);
| ^~~~~~~~~
The table pointer passed to wlc_lcnphy_common_read_table() should not be considered constant, as wlc_phy_read_table() is ultimately going to update it. Remove the const qualifier from the tbl_ptr to clear up the warning.
--- drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_lcn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/broadcom/brcm80211/brcmsmac/phy/phy_lcn.c +1 -1
@@ -919,7 +919,7 @@ void wlc_lcnphy_read_table(struct brcms_static void wlc_lcnphy_common_read_table (struct brcms_phy *pi,u32 tbl_id, -const u16 *tbl_ptr,u32 tbl_len, +u16 *tbl_ptr,u32 tbl_len,u32 tbl_width,u32 tbl_offset) {struct phytbl_info tab;
Greg Kroah-Hartman
maintainerPATCH 370/587 wifi: ath12k: fix dest ring-buffer corruption
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 8157ce533a60521f21d466eb4de45d9735b19484 upstream.
Add the missing memory barrier to make sure that destination ring descriptors are read after the head pointers to avoid using stale data on weakly ordered architectures like aarch64.
The barrier is added to the ath12k_hal_srng_access_begin() helper for symmetry with follow-on fixes for source ring buffer corruption which will add barriers to ath12k_hal_srng_access_end().
Tested-on: WCN7850 hw2.0 WLAN.HMT.1.0.c5-00481-QCAHMTSWPL_V1.0_V2.0_SILICONZ-3
--- drivers/net/wireless/ath/ath12k/ce.c | 3 --- drivers/net/wireless/ath/ath12k/hal.c | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-)
drivers/net/wireless/ath/ath12k/ce.c +0 -3
@@ -343,9 +343,6 @@ static int ath12k_ce_completed_recv_next goto err; } -/* Make sure descriptor is read after the head pointer. */ -dma_rmb (); - *nbytes =ath12k_hal_ce_dst_status_get_length (desc); *skb = pipe->dest_ring->skb[sw_index];
drivers/net/wireless/ath/ath12k/hal.c +14 -3
@@ -1728,13 +1728,24 @@ void *ath12k_hal_srng_src_get_next_reapevoid ath12k_hal_srng_access_begin (struct ath12k_base *ab,struct hal_srng *srng) { +u32 hp; +lockdep_assert_held (&srng->lock); -if (srng->ring_dir ==HAL_SRNG_DIR_SRC ) +if (srng->ring_dir ==HAL_SRNG_DIR_SRC ) { srng->u.src_ring.cached_tp = *(volatile u32 *)srng->u.src_ring.tp_addr; -else - srng->u.dst_ring.cached_hp =READ_ONCE (*srng->u.dst_ring.hp_addr); + }else { + hp =READ_ONCE (*srng->u.dst_ring.hp_addr); + +if (hp != srng->u.dst_ring.cached_hp) { + srng->u.dst_ring.cached_hp = hp; +/* Make sure descriptor is read after the head +* pointer. +*/ +dma_rmb (); + } + } }/* Update cached ring head/tail pointers to HW. ath12k_hal_srng_access_begin()
Greg Kroah-Hartman
maintainerPATCH 371/587 wifi: ath12k: fix source ring-buffer corruption
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit e834da4cbd6fe1d24f89368bf0c80adcad212726 upstream.
Add the missing memory barrier to make sure that LMAC source ring descriptors are written before updating the head pointer to avoid passing stale data to the firmware on weakly ordered architectures like aarch64.
Note that non-LMAC rings use MMIO write accessors which have the required write memory barrier.
Tested-on: WCN7850 hw2.0 WLAN.HMT.1.0.c5-00481-QCAHMTSWPL_V1.0_V2.0_SILICONZ-3
--- drivers/net/wireless/ath/ath12k/hal.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath12k/hal.c +9 -1
@@ -1763,7 +1763,11 @@ void ath12k_hal_srng_access_end(struct aif (srng->ring_dir ==HAL_SRNG_DIR_SRC ) { srng->u.src_ring.last_tp = *(volatile u32 *)srng->u.src_ring.tp_addr; - *srng->u.src_ring.hp_addr = srng->u.src_ring.hp; +/* Make sure descriptor is written before updating the +* head pointer. +*/ +dma_wmb (); +WRITE_ONCE (*srng->u.src_ring.hp_addr, srng->u.src_ring.hp); }else { srng->u.dst_ring.last_hp = *srng->u.dst_ring.hp_addr; *srng->u.dst_ring.tp_addr = srng->u.dst_ring.tp;
@@ -1772,6 +1776,10 @@ void ath12k_hal_srng_access_end(struct aif (srng->ring_dir ==HAL_SRNG_DIR_SRC ) { srng->u.src_ring.last_tp = *(volatile u32 *)srng->u.src_ring.tp_addr; +/* Assume implementation use an MMIO write accessor +* which has the required wmb() so that the descriptor +* is written before the updating the head pointer. +*/ ath12k_hif_write32(ab, (unsigned long)srng->u.src_ring.hp_addr - (unsigned long)ab->mem,
Greg Kroah-Hartman
maintainerPATCH 372/587 wifi: ath12k: fix dest ring-buffer corruption when ring is full
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit ed32169be1ccb9b1a295275ba7746dc6bf103e80 upstream.
Add the missing memory barriers to make sure that destination ring descriptors are read before updating the tail pointer (and passing ownership to the device) to avoid memory corruption on weakly ordered architectures like aarch64 when the ring is full.
Tested-on: WCN7850 hw2.0 WLAN.HMT.1.0.c5-00481-QCAHMTSWPL_V1.0_V2.0_SILICONZ-3
--- drivers/net/wireless/ath/ath12k/hal.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath12k/hal.c +9 -2
@@ -1755,7 +1755,6 @@ void ath12k_hal_srng_access_end(struct a {lockdep_assert_held (&srng->lock); -/* TODO: See if we need a write memory barrier here */ if (srng->flags &HAL_SRNG_FLAGS_LMAC_RING ) {/* For LMAC rings, ring pointer updates are done through FW and * hence written to a shared memory location that is read by FW
@@ -1770,7 +1769,11 @@ void ath12k_hal_srng_access_end(struct aWRITE_ONCE (*srng->u.src_ring.hp_addr, srng->u.src_ring.hp); }else { srng->u.dst_ring.last_hp = *srng->u.dst_ring.hp_addr; - *srng->u.dst_ring.tp_addr = srng->u.dst_ring.tp; +/* Make sure descriptor is read before updating the +* tail pointer. +*/ +dma_mb (); +WRITE_ONCE (*srng->u.dst_ring.tp_addr, srng->u.dst_ring.tp); } }else {if (srng->ring_dir ==HAL_SRNG_DIR_SRC ) {
@@ -1786,6 +1789,10 @@ void ath12k_hal_srng_access_end(struct a srng->u.src_ring.hp); }else { srng->u.dst_ring.last_hp = *srng->u.dst_ring.hp_addr; +/* Make sure descriptor is read before updating the +* tail pointer. +*/ +mb (); ath12k_hif_write32(ab, (unsigned long)srng->u.dst_ring.tp_addr - (unsigned long)ab->mem,
Greg Kroah-Hartman
maintainerPATCH 373/587 wifi: ath11k: fix dest ring-buffer corruption
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 8c1ba5091fa9a2d1478da63173b16a701bdf86bb upstream.
Add the missing memory barrier to make sure that destination ring descriptors are read after the head pointers to avoid using stale data on weakly ordered architectures like aarch64.
The barrier is added to the ath11k_hal_srng_access_begin() helper for symmetry with follow-on fixes for source ring buffer corruption which will add barriers to ath11k_hal_srng_access_end().
Tested-on: WCN6855 hw2.1 WLAN.HSP.1.1-03125-QCAHSPSWPL_V1_V2_SILICONZ_LITE-3.6510.41
--- drivers/net/wireless/ath/ath11k/ce.c | 3 --- drivers/net/wireless/ath/ath11k/dp_rx.c | 3 --- drivers/net/wireless/ath/ath11k/hal.c | 12 +++++++++++- 3 files changed, 11 insertions(+), 7 deletions(-)
drivers/net/wireless/ath/ath11k/ce.c +0 -3
@@ -393,9 +393,6 @@ static int ath11k_ce_completed_recv_next goto err; } -/* Make sure descriptor is read after the head pointer. */ -dma_rmb (); - *nbytes =ath11k_hal_ce_dst_status_get_length (desc); *skb = pipe->dest_ring->skb[sw_index];
drivers/net/wireless/ath/ath11k/dp_rx.c +0 -3
@@ -2662,9 +2662,6 @@ int ath11k_dp_process_rx(struct ath11k_b try_again:ath11k_hal_srng_access_begin (ab, srng); -/* Make sure descriptor is read after the head pointer. */ -dma_rmb (); -while (likely (desc = (struct hal_reo_dest_ring *)ath11k_hal_srng_dst_get_next_entry (ab, srng))) {
drivers/net/wireless/ath/ath11k/hal.c +11 -1
@@ -796,13 +796,23 @@ u32 *ath11k_hal_srng_src_peek(struct athvoid ath11k_hal_srng_access_begin (struct ath11k_base *ab,struct hal_srng *srng) { +u32 hp; +lockdep_assert_held (&srng->lock);if (srng->ring_dir ==HAL_SRNG_DIR_SRC ) { srng->u.src_ring.cached_tp = *(volatile u32 *)srng->u.src_ring.tp_addr; }else { - srng->u.dst_ring.cached_hp =READ_ONCE (*srng->u.dst_ring.hp_addr); + hp =READ_ONCE (*srng->u.dst_ring.hp_addr); + +if (hp != srng->u.dst_ring.cached_hp) { + srng->u.dst_ring.cached_hp = hp; +/* Make sure descriptor is read after the head +* pointer. +*/ +dma_rmb (); + }/* Try to prefetch the next descriptor in the ring */ if (srng->flags &HAL_SRNG_FLAGS_CACHED )
Greg Kroah-Hartman
maintainerPATCH 374/587 wifi: ath11k: fix source ring-buffer corruption
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit 6efa0df54022c6c9fd4d294b87622c7fcdc418c8 upstream.
Add the missing memory barrier to make sure that LMAC source ring descriptors are written before updating the head pointer to avoid passing stale data to the firmware on weakly ordered architectures like aarch64.
Note that non-LMAC rings use MMIO write accessors which have the required write memory barrier.
Tested-on: WCN6855 hw2.1 WLAN.HSP.1.1-03125-QCAHSPSWPL_V1_V2_SILICONZ_LITE-3.6510.41
--- drivers/net/wireless/ath/ath11k/hal.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath11k/hal.c +9 -1
@@ -835,7 +835,11 @@ void ath11k_hal_srng_access_end(struct aif (srng->ring_dir ==HAL_SRNG_DIR_SRC ) { srng->u.src_ring.last_tp = *(volatile u32 *)srng->u.src_ring.tp_addr; - *srng->u.src_ring.hp_addr = srng->u.src_ring.hp; +/* Make sure descriptor is written before updating the +* head pointer. +*/ +dma_wmb (); +WRITE_ONCE (*srng->u.src_ring.hp_addr, srng->u.src_ring.hp); }else { srng->u.dst_ring.last_hp = *srng->u.dst_ring.hp_addr; *srng->u.dst_ring.tp_addr = srng->u.dst_ring.tp;
@@ -844,6 +848,10 @@ void ath11k_hal_srng_access_end(struct aif (srng->ring_dir ==HAL_SRNG_DIR_SRC ) { srng->u.src_ring.last_tp = *(volatile u32 *)srng->u.src_ring.tp_addr; +/* Assume implementation use an MMIO write accessor +* which has the required wmb() so that the descriptor +* is written before the updating the head pointer. +*/ ath11k_hif_write32(ab, (unsigned long)srng->u.src_ring.hp_addr - (unsigned long)ab->mem,
Greg Kroah-Hartman
maintainerPATCH 375/587 wifi: ath11k: fix dest ring-buffer corruption when ring is full
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
commit aa6956150f820e6a6deba44be325ddfcb5b10f88 upstream.
Add the missing memory barriers to make sure that destination ring descriptors are read before updating the tail pointer (and passing ownership to the device) to avoid memory corruption on weakly ordered architectures like aarch64 when the ring is full.
Tested-on: WCN6855 hw2.1 WLAN.HSP.1.1-03125-QCAHSPSWPL_V1_V2_SILICONZ_LITE-3.6510.41
--- drivers/net/wireless/ath/ath11k/hal.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/net/wireless/ath/ath11k/hal.c +9 -2
@@ -827,7 +827,6 @@ void ath11k_hal_srng_access_end(struct a {lockdep_assert_held (&srng->lock); -/* TODO: See if we need a write memory barrier here */ if (srng->flags &HAL_SRNG_FLAGS_LMAC_RING ) {/* For LMAC rings, ring pointer updates are done through FW and * hence written to a shared memory location that is read by FW
@@ -842,7 +841,11 @@ void ath11k_hal_srng_access_end(struct aWRITE_ONCE (*srng->u.src_ring.hp_addr, srng->u.src_ring.hp); }else { srng->u.dst_ring.last_hp = *srng->u.dst_ring.hp_addr; - *srng->u.dst_ring.tp_addr = srng->u.dst_ring.tp; +/* Make sure descriptor is read before updating the +* tail pointer. +*/ +dma_mb (); +WRITE_ONCE (*srng->u.dst_ring.tp_addr, srng->u.dst_ring.tp); } }else {if (srng->ring_dir ==HAL_SRNG_DIR_SRC ) {
@@ -858,6 +861,10 @@ void ath11k_hal_srng_access_end(struct a srng->u.src_ring.hp); }else { srng->u.dst_ring.last_hp = *srng->u.dst_ring.hp_addr; +/* Make sure descriptor is read before updating the +* tail pointer. +*/ +mb (); ath11k_hif_write32(ab, (unsigned long)srng->u.dst_ring.tp_addr - (unsigned long)ab->mem,
Greg Kroah-Hartman
maintainerPATCH 376/587 pwm: imx-tpm: Reset counter if CMOD is 0
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Laurentiu Mihalcea <[email protected]>
commit 65c6f742ab14ab1a2679fba72b82dcc0289d96f1 upstream.
As per the i.MX93 TRM, section 67.3.2.1 "MOD register update", the value of the TPM counter does NOT get updated when writing MOD.MOD unless SC.CMOD != 0. Therefore, with the current code, assuming the following sequence:
1) pwm_disable()
2) pwm_apply_might_sleep() /* period is changed here */
3) pwm_enable()
and assuming only one channel is active, if CNT.COUNT is higher than the MOD.MOD value written during the pwm_apply_might_sleep() call then, when re-enabling the PWM during pwm_enable(), the counter will end up resetting after UINT32_MAX - CNT.COUNT + MOD.MOD cycles instead of MOD.MOD cycles as normally expected.
Fix this problem by forcing a reset of the TPM counter before MOD.MOD is written.
--- drivers/pwm/pwm-imx-tpm.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/pwm/pwm-imx-tpm.c +9 -0
@@ -205,6 +205,15 @@ static int pwm_imx_tpm_apply_hw(struct pwritel (val, tpm->base +PWM_IMX_TPM_SC );/* +* if the counter is disabled (CMOD == 0), programming the new +* period length (MOD) will not reset the counter (CNT). If +* CNT.COUNT happens to be bigger than the new MOD value then +* the counter will end up being reset way too late. Therefore, +* manually reset it to 0. +*/ +if (!cmod) +writel (0x0 , tpm->base +PWM_IMX_TPM_CNT ); +/* * set period count: * if the PWM is disabled (CMOD[1:0] = 2b00), then MOD register * is updated when MOD register is written.
Greg Kroah-Hartman
maintainerPATCH 377/587 pwm: mediatek: Handle hardware enable and clock enable separately
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
commit 704d918341c378c5f9505dfdf32d315e256d3846 upstream.
Stop handling the clocks in pwm_mediatek_enable() and pwm_mediatek_disable(). This is a preparing change for the next commit that requires that clocks and the enable bit are handled separately.
Also move these two functions a bit further up in the source file to make them usable in pwm_mediatek_config(), which is needed in the next commit, too.
--- drivers/pwm/pwm-mediatek.c | 60 +++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 32 deletions(-)
drivers/pwm/pwm-mediatek.c +28 -32
@@ -118,6 +118,26 @@ static inline void pwm_mediatek_writel(swritel (value, chip->regs + chip->soc->reg_offset[num] + offset); } +static void pwm_mediatek_enable (struct pwm_chip *chip,struct pwm_device *pwm) +{ +struct pwm_mediatek_chip *pc =to_pwm_mediatek_chip (chip); +u32 value; + + value =readl (pc->regs); + value |=BIT (pwm->hwpwm); +writel (value, pc->regs); +} + +static void pwm_mediatek_disable (struct pwm_chip *chip,struct pwm_device *pwm) +{ +struct pwm_mediatek_chip *pc =to_pwm_mediatek_chip (chip); +u32 value; + + value =readl (pc->regs); + value &= ~BIT (pwm->hwpwm); +writel (value, pc->regs); +} +static int pwm_mediatek_config (struct pwm_chip *chip,struct pwm_device *pwm,int duty_ns,int period_ns) {
@@ -180,35 +200,6 @@ out:return ret; } -static int pwm_mediatek_enable (struct pwm_chip *chip,struct pwm_device *pwm) -{ -struct pwm_mediatek_chip *pc =to_pwm_mediatek_chip (chip); -u32 value; -int ret; - - ret =pwm_mediatek_clk_enable (chip, pwm); -if (ret <0 ) -return ret; - - value =readl (pc->regs); - value |=BIT (pwm->hwpwm); -writel (value, pc->regs); - -return 0 ; -} - -static void pwm_mediatek_disable (struct pwm_chip *chip,struct pwm_device *pwm) -{ -struct pwm_mediatek_chip *pc =to_pwm_mediatek_chip (chip); -u32 value; - - value =readl (pc->regs); - value &= ~BIT (pwm->hwpwm); -writel (value, pc->regs); - -pwm_mediatek_clk_disable (chip, pwm); -} -static int pwm_mediatek_apply (struct pwm_chip *chip,struct pwm_device *pwm,const struct pwm_state *state) {
@@ -218,8 +209,10 @@ static int pwm_mediatek_apply(struct pwmreturn -EINVAL ;if (!state->enabled) { -if (pwm->state.enabled) +if (pwm->state.enabled) {pwm_mediatek_disable (chip, pwm); +pwm_mediatek_clk_disable (chip, pwm); + }return 0 ; }
@@ -228,8 +221,11 @@ static int pwm_mediatek_apply(struct pwmif (err)return err; -if (!pwm->state.enabled) - err =pwm_mediatek_enable (chip, pwm); +if (!pwm->state.enabled) { + err =pwm_mediatek_clk_enable (chip, pwm); +if (!err) +pwm_mediatek_enable (chip, pwm); + }return err; }
Greg Kroah-Hartman
maintainerPATCH 378/587 pwm: mediatek: Fix duty and period setting
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
commit f21d136caf8171f94159d975ea4620c164431bd9 upstream.
The period generated by the hardware is
(PWMDWIDTH + 1) << CLKDIV) / freq
according to my tests with a signal analyser and also the documentation.
The current algorithm doesn't consider the + 1 part and so configures slightly too high periods. The same issue exists for the duty cycle setting. So subtract 1 from both the register values for period and duty cycle. If period is 0, bail out, if duty_cycle is 0, just disable the PWM which results in a constant low output.
--- drivers/pwm/pwm-mediatek.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/pwm/pwm-mediatek.c +14 -7
@@ -167,7 +167,10 @@ static int pwm_mediatek_config(struct pwdo_div (resolution, clk_rate); cnt_period =DIV_ROUND_CLOSEST_ULL ((u64 )period_ns *1000 , resolution); -while (cnt_period >8191 ) { +if (!cnt_period) +return -EINVAL ; + +while (cnt_period >8192 ) { resolution *=2 ; clkdiv++; cnt_period = DIV_ROUND_CLOSEST_ULL((u64)period_ns * 1000,
@@ -190,9 +193,16 @@ static int pwm_mediatek_config(struct pw } cnt_duty =DIV_ROUND_CLOSEST_ULL ((u64 )duty_ns *1000 , resolution); +pwm_mediatek_writel (pc, pwm->hwpwm,PWMCON ,BIT (15 ) | clkdiv); -pwm_mediatek_writel (pc, pwm->hwpwm, reg_width, cnt_period); -pwm_mediatek_writel (pc, pwm->hwpwm, reg_thres, cnt_duty); +pwm_mediatek_writel (pc, pwm->hwpwm, reg_width, cnt_period -1 ); + +if (cnt_duty) { +pwm_mediatek_writel (pc, pwm->hwpwm, reg_thres, cnt_duty -1 ); +pwm_mediatek_enable (chip, pwm); + }else { +pwm_mediatek_disable (chip, pwm); + } out:pwm_mediatek_clk_disable (chip, pwm);
@@ -221,11 +231,8 @@ static int pwm_mediatek_apply(struct pwmif (err)return err; -if (!pwm->state.enabled) { +if (!pwm->state.enabled) err =pwm_mediatek_clk_enable (chip, pwm); -if (!err) -pwm_mediatek_enable (chip, pwm); - }return err; }
Greg Kroah-Hartman
maintainerPATCH 379/587 hwmon: (gsc-hwmon) fix fan pwm setpoint show functions
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Tim Harvey <[email protected]>
commit 9c62e2282900332c8b711d9f9e37af369a8ef71b upstream.
The Linux hwmon sysfs API values for pwmX_auto_pointY_pwm represent an integer value between 0 (0%) to 255 (100%) and the pwmX_auto_pointY_temp represent millidegrees Celcius.
Commit a6d80df47ee2 ("hwmon: (gsc-hwmon) fix fan pwm temperature scaling") properly addressed the incorrect scaling in the pwm_auto_point_temp_store implementation but erroneously scaled the pwm_auto_point_pwm_show (pwm value) instead of the pwm_auto_point_temp_show (temp value) resulting in:
# cat /sys/class/hwmon/hwmon0/pwm1_auto_point6_pwm 25500 # cat /sys/class/hwmon/hwmon0/pwm1_auto_point6_temp 4500
Fix the scaling of these attributes:
# cat /sys/class/hwmon/hwmon0/pwm1_auto_point6_pwm 255 # cat /sys/class/hwmon/hwmon0/pwm1_auto_point6_temp 45000
--- drivers/hwmon/gsc-hwmon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/hwmon/gsc-hwmon.c +2 -2
@@ -65,7 +65,7 @@ static ssize_t pwm_auto_point_temp_show(return ret; ret = regs[0 ] | regs[1 ] <<8 ; -return sprintf (buf,"%d\n" , ret *10 ); +return sprintf (buf,"%d\n" , ret *100 ); } static ssize_t pwm_auto_point_temp_store(struct device *dev,
@@ -100,7 +100,7 @@ static ssize_t pwm_auto_point_pwm_show(s {struct sensor_device_attribute *attr =to_sensor_dev_attr (devattr); -return sprintf (buf,"%d\n" ,255 * (50 + (attr->index *10 ))); +return sprintf (buf,"%d\n" ,255 * (50 + (attr->index *10 )) /100 ); } static SENSOR_DEVICE_ATTR_RO(pwm1_auto_point1_pwm, pwm_auto_point_pwm, 0);
Greg Kroah-Hartman
maintainerPATCH 380/587 mtd: spi-nor: Fix spi_nor_try_unlock_all()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michael Walle <[email protected]>
commit 2e3a7476ec3989e77270b9481e76e137824b17c0 upstream.
Commit ff67592cbdfc ("mtd: spi-nor: Introduce spi_nor_set_mtd_info()") moved all initialization of the mtd fields at the end of spi_nor_scan(). Normally, the mtd info is only needed for the mtd ops on the device, with one exception: spi_nor_try_unlock_all(), which will also make use of the mtd->size parameter. With that commit, the size will always be zero because it is not initialized. Fix that by not using the size of the mtd_info struct, but use the size from struct spi_nor_flash_parameter.
--- drivers/mtd/spi-nor/swp.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-)
drivers/mtd/spi-nor/swp.c +8 -11
@@ -50,7 +50,6 @@ static u64 spi_nor_get_min_prot_length_sstatic void spi_nor_get_locked_range_sr (struct spi_nor *nor,u8 sr,loff_t *ofs,uint64_t *len) { -struct mtd_info *mtd = &nor->mtd;u64 min_prot_len;u8 mask =spi_nor_get_sr_bp_mask (nor);u8 tb_mask =spi_nor_get_sr_tb_mask (nor);
@@ -71,13 +70,13 @@ static void spi_nor_get_locked_range_sr( min_prot_len =spi_nor_get_min_prot_length_sr (nor); *len = min_prot_len << (bp -1 ); -if (*len > mtd->size) - *len = mtd->size; +if (*len > nor->params->size) + *len = nor->params->size;if (nor->flags &SNOR_F_HAS_SR_TB && sr & tb_mask) *ofs =0 ;else - *ofs = mtd->size - *len; + *ofs = nor->params->size - *len; }/*
@@ -153,7 +152,6 @@ static bool spi_nor_is_unlocked_sr(struc*/ static int spi_nor_sr_lock (struct spi_nor *nor,loff_t ofs,uint64_t len) { -struct mtd_info *mtd = &nor->mtd;u64 min_prot_len;int ret, status_old, status_new;u8 mask =spi_nor_get_sr_bp_mask (nor);
@@ -178,7 +176,7 @@ static int spi_nor_sr_lock(struct spi_no can_be_bottom = false;/* If anything above us is unlocked, we can't use 'top' protection */ -if (!spi_nor_is_locked_sr (nor, ofs + len, mtd->size - (ofs + len), +if (!spi_nor_is_locked_sr (nor, ofs + len, nor->params->size - (ofs + len), status_old)) can_be_top = false;
@@ -190,11 +188,11 @@ static int spi_nor_sr_lock(struct spi_no/* lock_len: length of region that should end up locked */ if (use_top) - lock_len = mtd->size - ofs; + lock_len = nor->params->size - ofs;else lock_len = ofs + len; -if (lock_len == mtd->size) { +if (lock_len == nor->params->size) { val = mask; }else { min_prot_len =spi_nor_get_min_prot_length_sr (nor);
@@ -243,7 +241,6 @@ static int spi_nor_sr_lock(struct spi_no*/ static int spi_nor_sr_unlock (struct spi_nor *nor,loff_t ofs,uint64_t len) { -struct mtd_info *mtd = &nor->mtd;u64 min_prot_len;int ret, status_old, status_new;u8 mask =spi_nor_get_sr_bp_mask (nor);
@@ -268,7 +265,7 @@ static int spi_nor_sr_unlock(struct spi_ can_be_top = false;/* If anything above us is locked, we can't use 'bottom' protection */ -if (!spi_nor_is_unlocked_sr (nor, ofs + len, mtd->size - (ofs + len), +if (!spi_nor_is_unlocked_sr (nor, ofs + len, nor->params->size - (ofs + len), status_old)) can_be_bottom = false;
@@ -280,7 +277,7 @@ static int spi_nor_sr_unlock(struct spi_/* lock_len: length of region that should remain locked */ if (use_top) - lock_len = mtd->size - (ofs + len); + lock_len = nor->params->size - (ofs + len);else lock_len = ofs;
Greg Kroah-Hartman
maintainerPATCH 381/587 mtd: spinand: propagate spinand_wait() errors from spinand_write_page()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gabor Juhos <[email protected]>
commit 091d9e35b85b0f8f7e1c73535299f91364a5c73a upstream.
Since commit 3d1f08b032dc ("mtd: spinand: Use the external ECC engine logic") the spinand_write_page() function ignores the errors returned by spinand_wait(). Change the code to propagate those up to the stack as it was done before the offending change.
--- drivers/mtd/nand/spi/core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/mtd/nand/spi/core.c +4 -1
@@ -624,7 +624,10 @@ static int spinand_write_page(struct spiSPINAND_WRITE_INITIAL_DELAY_US ,SPINAND_WRITE_POLL_DELAY_US , &status); -if (!ret && (status &STATUS_PROG_FAILED )) +if (ret) +return ret; + +if (status &STATUS_PROG_FAILED )return -EIO ;return nand_ecc_finish_io_req (nand, (struct nand_page_io_req *)req);
Greg Kroah-Hartman
maintainerPATCH 382/587 mtd: rawnand: fsmc: Add missing check after DMA map
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Fourier <[email protected]>
commit 6c4dab38431fee3d39a841d66ba6f2890b31b005 upstream.
The DMA map functions can fail and should be tested for errors.
Rule: add
--- drivers/mtd/nand/raw/fsmc_nand.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/mtd/nand/raw/fsmc_nand.c +2 -0
@@ -503,6 +503,8 @@ static int dma_xfer(struct fsmc_nand_dat dma_dev = chan->device; dma_addr =dma_map_single (dma_dev->dev, buffer, len, direction); +if (dma_mapping_error (dma_dev->dev, dma_addr)) +return -EINVAL ;if (direction ==DMA_TO_DEVICE ) { dma_src = dma_addr;
Greg Kroah-Hartman
maintainerPATCH 383/587 mtd: rawnand: renesas: Add missing check after DMA map
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thomas Fourier <[email protected]>
commit 79e441ee47949376e3bc20f085cf017b70523d0f upstream.
The DMA map functions can fail and should be tested for errors.
--- drivers/mtd/nand/raw/renesas-nand-controller.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/mtd/nand/raw/renesas-nand-controller.c +6 -0
@@ -426,6 +426,9 @@ static int rnandc_read_page_hw_ecc(struc/* Configure DMA */ dma_addr =dma_map_single (rnandc->dev, rnandc->buf, mtd->writesize,DMA_FROM_DEVICE ); +if (dma_mapping_error (rnandc->dev, dma_addr)) +return -ENOMEM ; +writel (dma_addr, rnandc->regs +DMA_ADDR_LOW_REG );writel (mtd->writesize, rnandc->regs +DMA_CNT_REG );writel (DMA_TLVL_MAX , rnandc->regs +DMA_TLVL_REG );
@@ -606,6 +609,9 @@ static int rnandc_write_page_hw_ecc(stru/* Configure DMA */ dma_addr =dma_map_single (rnandc->dev, (void *)rnandc->buf, mtd->writesize,DMA_TO_DEVICE ); +if (dma_mapping_error (rnandc->dev, dma_addr)) +return -ENOMEM ; +writel (dma_addr, rnandc->regs +DMA_ADDR_LOW_REG );writel (mtd->writesize, rnandc->regs +DMA_CNT_REG );writel (DMA_TLVL_MAX , rnandc->regs +DMA_TLVL_REG );
Greg Kroah-Hartman
maintainerPATCH 384/587 PCI: endpoint: Fix configfs group list head handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Damien Le Moal <[email protected]>
commit d79123d79a8154b4318529b7b2ff7e15806f480b upstream.
Doing a list_del() on the epf_group field of struct pci_epf_driver in pci_epf_remove_cfs() is not correct as this field is a list head, not a list entry. This list_del() call triggers a KASAN warning when an endpoint function driver which has a configfs attribute group is torn down:
==================================================================
BUG: KASAN: slab-use-after-free in pci_epf_remove_cfs+0x17c/0x198 Write of size 8 at addr ffff00010f4a0d80 by task rmmod/319 CPU: 3 UID: 0 PID: 319 Comm: rmmod Not tainted 6.16.0-rc2 #1 NONE Hardware name: Radxa ROCK 5B (DT) Call trace: show_stack+0x2c/0x84 (C) dump_stack_lvl+0x70/0x98 print_report+0x17c/0x538 kasan_report+0xb8/0x190 __asan_report_store8_noabort+0x20/0x2c pci_epf_remove_cfs+0x17c/0x198 pci_epf_unregister_driver+0x18/0x30 nvmet_pci_epf_cleanup_module+0x24/0x30 [nvmet_pci_epf] __arm64_sys_delete_module+0x264/0x424 invoke_syscall+0x70/0x260 el0_svc_common.constprop.0+0xac/0x230 do_el0_svc+0x40/0x58 el0_svc+0x48/0xdc el0t_64_sync_handler+0x10c/0x138 el0t_64_sync+0x198/0x19c
...
Remove this incorrect list_del() call from pci_epf_remove_cfs().
--- drivers/pci/endpoint/pci-epf-core.c | 1 - 1 file changed, 1 deletion(-)
drivers/pci/endpoint/pci-epf-core.c +0 -1
@@ -311,7 +311,6 @@ static void pci_epf_remove_cfs(struct pcmutex_lock (&pci_epf_mutex);list_for_each_entry_safe (group, tmp, &driver->epf_group, group_entry)pci_ep_cfs_remove_epf_group (group); -list_del (&driver->epf_group);mutex_unlock (&pci_epf_mutex); }
Greg Kroah-Hartman
maintainerPATCH 385/587 PCI: endpoint: Fix configfs group removal on driver teardown
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Damien Le Moal <[email protected]>
commit 910bdb8197f9322790c738bb32feaa11dba26909 upstream.
An endpoint driver configfs attributes group is added to the epf_group list of struct pci_epf_driver by pci_epf_add_cfs() but an added group is not removed from this list when the attribute group is unregistered with pci_ep_cfs_remove_epf_group().
Add the missing list_del() call in pci_ep_cfs_remove_epf_group() to correctly remove the attribute group from the driver list.
With this change, once the loop over all attribute groups in pci_epf_remove_cfs() completes, the driver epf_group list should be empty. Add a WARN_ON() to make sure of that.
--- drivers/pci/endpoint/pci-ep-cfs.c | 1 + drivers/pci/endpoint/pci-epf-core.c | 1 + 2 files changed, 2 insertions(+)
drivers/pci/endpoint/pci-ep-cfs.c +1 -0
@@ -683,6 +683,7 @@ void pci_ep_cfs_remove_epf_group(structif (IS_ERR_OR_NULL (group))return ; +list_del (&group->group_entry);configfs_unregister_default_group (group); }EXPORT_SYMBOL (pci_ep_cfs_remove_epf_group);
drivers/pci/endpoint/pci-epf-core.c +1 -0
@@ -311,6 +311,7 @@ static void pci_epf_remove_cfs(struct pcmutex_lock (&pci_epf_mutex);list_for_each_entry_safe (group, tmp, &driver->epf_group, group_entry)pci_ep_cfs_remove_epf_group (group); +WARN_ON (!list_empty (&driver->epf_group));mutex_unlock (&pci_epf_mutex); }
Greg Kroah-Hartman
maintainerPATCH 386/587 vsock/virtio: Validate length in packet header before skb_put()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
commit 0dab92484474587b82e8e0455839eaf5ac7bf894 upstream.
When receiving a vsock packet in the guest, only the virtqueue buffer size is validated prior to virtio_vsock_skb_rx_put(). Unfortunately, virtio_vsock_skb_rx_put() uses the length from the packet header as the length argument to skb_put(), potentially resulting in SKB overflow if the host has gone wonky.
Validate the length as advertised by the packet header before calling virtio_vsock_skb_rx_put().
Message-Id: <[email protected]>
--- net/vmw_vsock/virtio_transport.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
net/vmw_vsock/virtio_transport.c +10 -2
@@ -497,8 +497,9 @@ static void virtio_transport_rx_work(str do { virtqueue_disable_cb(vq); for (;;) { + unsigned int len, payload_len; + struct virtio_vsock_hdr *hdr; struct sk_buff *skb; - unsigned int len; if (!virtio_transport_more_replies(vsock)) { /* Stop rx until the device processes already
@@ -515,11 +516,18 @@ static void virtio_transport_rx_work(str vsock->rx_buf_nr--;/* Drop short/long packets */ -if (unlikely (len <sizeof (struct virtio_vsock_hdr ) || +if (unlikely (len <sizeof (*hdr) || len >virtio_vsock_skb_len (skb))) {kfree_skb (skb);continue ; } + + hdr =virtio_vsock_hdr (skb); + payload_len =le32_to_cpu (hdr->len); +if (unlikely (payload_len > len -sizeof (*hdr))) { +kfree_skb (skb); +continue ; + }virtio_vsock_skb_rx_put (skb);virtio_transport_deliver_tap_pkt (skb);
Greg Kroah-Hartman
maintainerPATCH 387/587 vhost/vsock: Avoid allocating arbitrarily-sized SKBs
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Will Deacon <[email protected]>
commit 10a886aaed293c4db3417951f396827216299e3d upstream.
vhost_vsock_alloc_skb() returns NULL for packets advertising a length larger than VIRTIO_VSOCK_MAX_PKT_BUF_SIZE in the packet header. However, this is only checked once the SKB has been allocated and, if the length in the packet header is zero, the SKB may not be freed immediately.
Hoist the size check before the SKB allocation so that an iovec larger than VIRTIO_VSOCK_MAX_PKT_BUF_SIZE + the header size is rejected outright. The subsequent check on the length field in the header can then simply check that the allocated SKB is indeed large enough to hold the packet.
Message-Id: <[email protected]>
--- drivers/vhost/vsock.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/vhost/vsock.c +4 -2
@@ -340,6 +340,9 @@ vhost_vsock_alloc_skb(struct vhost_virtq len =iov_length (vq->iov, out); +if (len >VIRTIO_VSOCK_MAX_PKT_BUF_SIZE +VIRTIO_VSOCK_SKB_HEADROOM ) +return NULL ; +/* len contains both payload and hdr */ skb =virtio_vsock_alloc_skb (len,GFP_KERNEL );if (!skb)
@@ -363,8 +366,7 @@ vhost_vsock_alloc_skb(struct vhost_virtqreturn skb;/* The pkt is too big or the length in the header is invalid */ -if (payload_len >VIRTIO_VSOCK_MAX_PKT_BUF_SIZE || - payload_len +sizeof (*hdr) > len) { +if (payload_len +sizeof (*hdr) > len) {kfree_skb (skb);return NULL ; }
Greg Kroah-Hartman
maintainerPATCH 388/587 phy: qcom: phy-qcom-m31: Update IPQ5332 M31 USB phy initialization sequence
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kathiravan Thirumoorthy <[email protected]>
commit 4a3556b81b99f0c8c0358f7cc6801a62b4538fe2 upstream.
The current configuration used for the IPQ5332 M31 USB PHY fails the Near End High Speed Signal Quality compliance test. To resolve this, update the initialization sequence as specified in the Hardware Design Document.
--- drivers/phy/qualcomm/phy-qcom-m31.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/phy/qualcomm/phy-qcom-m31.c +10 -4
@@ -58,14 +58,16 @@#define USB2_0_TX_ENABLE BIT(2)#define USB2PHY_USB_PHY_M31_XCFGI_4 0xc8 -#define HSTX_SLEW_RATE_565PS GENMASK(1, 0) +#define HSTX_SLEW_RATE_400PS GENMASK(2, 0)#define PLL_CHARGING_PUMP_CURRENT_35UA GENMASK(4, 3)#define ODT_VALUE_38_02_OHM GENMASK(7, 6)#define USB2PHY_USB_PHY_M31_XCFGI_5 0xcc -#define ODT_VALUE_45_02_OHM BIT(2)#define HSTX_PRE_EMPHASIS_LEVEL_0_55MA BIT(0) +#define USB2PHY_USB_PHY_M31_XCFGI_9 0xdc +#define HSTX_CURRENT_17_1MA_385MV BIT(1) +#define USB2PHY_USB_PHY_M31_XCFGI_11 0xe4#define XCFG_COARSE_TUNE_NUM BIT(1)#define XCFG_FINE_TUNE_NUM BIT(3)
@@ -120,7 +122,7 @@ static struct m31_phy_regs m31_ipq5332_r }, {USB2PHY_USB_PHY_M31_XCFGI_4 , -HSTX_SLEW_RATE_565PS |PLL_CHARGING_PUMP_CURRENT_35UA |ODT_VALUE_38_02_OHM , +HSTX_SLEW_RATE_400PS |PLL_CHARGING_PUMP_CURRENT_35UA |ODT_VALUE_38_02_OHM ,0 }, {
@@ -130,10 +132,14 @@ static struct m31_phy_regs m31_ipq5332_r }, {USB2PHY_USB_PHY_M31_XCFGI_5 , -ODT_VALUE_45_02_OHM |HSTX_PRE_EMPHASIS_LEVEL_0_55MA , +HSTX_PRE_EMPHASIS_LEVEL_0_55MA ,4 }, { +USB2PHY_USB_PHY_M31_XCFGI_9 , +HSTX_CURRENT_17_1MA_385MV , + }, + {USB_PHY_UTMI_CTRL5 ,0x0 ,0
Greg Kroah-Hartman
maintainerPATCH 389/587 f2fs: fix to avoid out-of-boundary access in dnode page
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
commit 77de19b6867f2740cdcb6c9c7e50d522b47847a4 upstream.
As Jiaming Zhang reported:
<TASK> __dump_stack lib/dump_stack.c:94 [inline] dump_stack_lvl+0x1c1/0x2a0 lib/dump_stack.c:120 print_address_description mm/kasan/report.c:378 [inline] print_report+0x17e/0x800 mm/kasan/report.c:480 kasan_report+0x147/0x180 mm/kasan/report.c:593 data_blkaddr fs/f2fs/f2fs.h:3053 [inline] f2fs_data_blkaddr fs/f2fs/f2fs.h:3058 [inline] f2fs_get_dnode_of_data+0x1a09/0x1c40 fs/f2fs/node.c:855 f2fs_reserve_block+0x53/0x310 fs/f2fs/data.c:1195 prepare_write_begin fs/f2fs/data.c:3395 [inline] f2fs_write_begin+0xf39/0x2190 fs/f2fs/data.c:3594 generic_perform_write+0x2c7/0x910 mm/filemap.c:4112 f2fs_buffered_write_iter fs/f2fs/file.c:4988 [inline] f2fs_file_write_iter+0x1ec8/0x2410 fs/f2fs/file.c:5216 new_sync_write fs/read_write.c:593 [inline] vfs_write+0x546/0xa90 fs/read_write.c:686 ksys_write+0x149/0x250 fs/read_write.c:738 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0xf3/0x3d0 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f
The root cause is in the corrupted image, there is a dnode has the same node id w/ its inode, so during f2fs_get_dnode_of_data(), it tries to access block address in dnode at offset 934, however it parses the dnode as inode node, so that get_dnode_addr() returns 360, then it tries to access page address from 360 + 934 * 4 = 4096 w/ 4 bytes.
To fix this issue, let's add sanity check for node id of all direct nodes during f2fs_get_dnode_of_data().
--- fs/f2fs/node.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
fs/f2fs/node.c +10 -0
@@ -799,6 +799,16 @@ int f2fs_get_dnode_of_data(struct dnode_for (i =1 ; i <= level; i++) {bool done = false; +if (nids[i] && nids[i] == dn->inode->i_ino) { + err = -EFSCORRUPTED ; +f2fs_err_ratelimited (sbi, +"inode mapping table is corrupted, run fsck to fix it, " +"ino:%lu, nid:%u, level:%d, offset:%d" , + dn->inode->i_ino, nids[i], level, offset[level]); +set_sbi_flag (sbi,SBI_NEED_FSCK ); + goto release_pages; + } +if (!nids[i] && mode ==ALLOC_NODE ) {/* alloc new node */ if (!f2fs_alloc_nid (sbi, &(nids[i]))) {
Greg Kroah-Hartman
maintainerPATCH 390/587 jbd2: prevent softlockup in jbd2_log_do_checkpoint()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Baokun Li <[email protected]>
commit 9d98cf4632258720f18265a058e62fde120c0151 upstream.
Both jbd2_log_do_checkpoint() and jbd2_journal_shrink_checkpoint_list() periodically release j_list_lock after processing a batch of buffers to avoid long hold times on the j_list_lock. However, since both functions contend for j_list_lock, the combined time spent waiting and processing can be significant.
jbd2_journal_shrink_checkpoint_list() explicitly calls cond_resched() when need_resched() is true to avoid softlockups during prolonged operations. But jbd2_log_do_checkpoint() only exits its loop when need_resched() is true, relying on potentially sleeping functions like __flush_batch() or wait_on_buffer() to trigger rescheduling. If those functions do not sleep, the kernel may hit a softlockup.
watchdog: BUG: soft lockup - CPU#3 stuck for 156s! [kworker/u129:2:373] CPU: 3 PID: 373 Comm: kworker/u129:2 Kdump: loaded Not tainted 6.6.0+ #10 Hardware name: Huawei TaiShan 2280 /BC11SPCD, BIOS 1.27 06/13/2017 Workqueue: writeback wb_workfn (flush-7:2) pstate: 20000005 (nzCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) pc : native_queued_spin_lock_slowpath+0x358/0x418 lr : jbd2_log_do_checkpoint+0x31c/0x438 [jbd2] Call trace: native_queued_spin_lock_slowpath+0x358/0x418 jbd2_log_do_checkpoint+0x31c/0x438 [jbd2] __jbd2_log_wait_for_space+0xfc/0x2f8 [jbd2] add_transaction_credits+0x3bc/0x418 [jbd2] start_this_handle+0xf8/0x560 [jbd2] jbd2__journal_start+0x118/0x228 [jbd2] __ext4_journal_start_sb+0x110/0x188 [ext4] ext4_do_writepages+0x3dc/0x740 [ext4] ext4_writepages+0xa4/0x190 [ext4] do_writepages+0x94/0x228 __writeback_single_inode+0x48/0x318 writeback_sb_inodes+0x204/0x590 __writeback_inodes_wb+0x54/0xf8 wb_writeback+0x2cc/0x3d8 wb_do_writeback+0x2e0/0x2f8 wb_workfn+0x80/0x2a8 process_one_work+0x178/0x3e8 worker_thread+0x234/0x3b8 kthread+0xf0/0x108 ret_from_fork+0x10/0x20
So explicitly call cond_resched() in jbd2_log_do_checkpoint() to avoid softlockup.
--- fs/jbd2/checkpoint.c | 1 + 1 file changed, 1 insertion(+)
fs/jbd2/checkpoint.c +1 -0
@@ -285,6 +285,7 @@ restart: retry:if (batch_count)__flush_batch (journal, &batch_count); +cond_resched ();spin_lock (&journal->j_list_lock); goto restart; }
Greg Kroah-Hartman
maintainerPATCH 391/587 soc/tegra: pmc: Ensure power-domains are in a known state
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jon Hunter <[email protected]>
commit b6bcbce3359619d05bf387d4f5cc3af63668dbaa upstream.
After commit 13a4b7fb6260 ("pmdomain: core: Leave powered-on genpds on until late_initcall_sync") was applied, the Tegra210 Jetson TX1 board failed to boot. Looking into this issue, before this commit was applied, if any of the Tegra power-domains were in 'on' state when the kernel booted, they were being turned off by the genpd core before any driver had chance to request them. This was purely by luck and a consequence of the power-domains being turned off earlier during boot. After this commit was applied, any power-domains in the 'on' state are kept on for longer during boot and therefore, may never transitioned to the off state before they are requested/used. The hang on the Tegra210 Jetson TX1 is caused because devices in some power-domains are accessed without the power-domain being turned off and on, indicating that the power-domain is not in a completely on state.
Quoted 1 line
From reviewing the Tegra PMC driver code, if a power-domain is in the
'on' state there is no guarantee that all the necessary clocks associated with the power-domain are on and even if they are they would not have been requested via the clock framework and so could be turned off later. Some power-domains also have a 'clamping' register that needs to be configured as well. In short, if a power-domain is already 'on' it is difficult to know if it has been configured correctly. Given that the power-domains happened to be switched off during boot previously, to ensure that they are in a good known state on boot, fix this by switching off any power-domains that are on initially when registering the power-domains with the genpd framework.
Note that commit 05cfb988a4d0 ("soc/tegra: pmc: Initialise resets associated with a power partition") updated the tegra_powergate_of_get_resets() function to pass the 'off' to ensure that the resets for the power-domain are in the correct state on boot. However, now that we may power off a domain on boot, if it is on, it is better to move this logic into the tegra_powergate_add() function so that there is a single place where we are handling the initial state of the power-domain.
--- drivers/soc/tegra/pmc.c | 51 +++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 22 deletions(-)
drivers/soc/tegra/pmc.c +29 -22
@@ -1232,7 +1232,7 @@ err: }static int tegra_powergate_of_get_resets (struct tegra_powergate *pg, -struct device_node *np,bool off) +struct device_node *np) {struct device *dev = pg->pmc->dev;int err;
@@ -1247,22 +1247,6 @@ static int tegra_powergate_of_get_resets err =reset_control_acquire (pg->reset);if (err <0 ) {pr_err ("failed to acquire resets: %d\n" , err); - goto out; - } - -if (off) { - err =reset_control_assert (pg->reset); - }else { - err =reset_control_deassert (pg->reset); -if (err <0 ) - goto out; - -reset_control_release (pg->reset); - } - -out: -if (err) { -reset_control_release (pg->reset);reset_control_put (pg->reset); }
@@ -1307,20 +1291,43 @@ static int tegra_powergate_add(struct te goto set_available; } - err =tegra_powergate_of_get_resets (pg, np, off); + err =tegra_powergate_of_get_resets (pg, np);if (err <0 ) {dev_err (dev,"failed to get resets for %pOFn: %d\n" , np, err); goto remove_clks; } -if (!IS_ENABLED (CONFIG_PM_GENERIC_DOMAINS )) { -if (off) -WARN_ON (tegra_powergate_power_up (pg, true)); +/* +* If the power-domain is off, then ensure the resets are asserted. +* If the power-domain is on, then power down to ensure that when is +* it turned on the power-domain, clocks and resets are all in the +* expected state. +*/ +if (off) { + err =reset_control_assert (pg->reset); +if (err) { +pr_err ("failed to assert resets: %d\n" , err); + goto remove_resets; + } + }else { + err =tegra_powergate_power_down (pg); +if (err) { +dev_err (dev,"failed to turn off PM domain %s: %d\n" , + pg->genpd.name, err); + goto remove_resets; + } + } +/* +* If PM_GENERIC_DOMAINS is not enabled, power-on +* the domain and skip the genpd registration. +*/ +if (!IS_ENABLED (CONFIG_PM_GENERIC_DOMAINS )) { +WARN_ON (tegra_powergate_power_up (pg, true)); goto remove_resets; } - err =pm_genpd_init (&pg->genpd,NULL , off); + err =pm_genpd_init (&pg->genpd,NULL , true);if (err <0 ) {dev_err (dev,"failed to initialise PM domain %pOFn: %d\n" , np, err);
Greg Kroah-Hartman
maintainerPATCH 392/587 parisc: Check region is readable by user in raw_copy_from_user()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: John David Anglin <[email protected]>
commit 91428ca9320edbab1211851d82429d33b9cd73ef upstream.
Because of the way the _PAGE_READ is handled in the parisc PTE, an access interruption is not generated when the kernel reads from a region where the _PAGE_READ is zero. The current code was written assuming read access faults would also occur in the kernel.
This change adds user access checks to raw_copy_from_user(). The prober_user() define checks whether user code has read access to a virtual address. Note that page faults are not handled in the exception support for the probe instruction. For this reason, we precede the probe by a ldb access check.
--- arch/parisc/include/asm/special_insns.h | 28 ++++++++++++++++++++++++++++ arch/parisc/lib/memcpy.c | 19 ++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-)
arch/parisc/include/asm/special_insns.h +28 -0
@@ -32,6 +32,34 @@ pa; \ }) +/** +* prober_user() - Probe user read access +* @sr: Space regster. +* @va: Virtual address. +* +* Return: Non-zero if address is accessible. +* +* Due to the way _PAGE_READ is handled in TLB entries, we need +* a special check to determine whether a user address is accessible. +* The ldb instruction does the initial access check. If it is +* successful, the probe instruction checks user access rights. +*/ +#define prober_user (sr, va) ({ \ + unsigned long read_allowed; \ + __asm__ __volatile__( \ + "copy %%r0,%0\n" \ + "8:\tldb 0(%%sr%1,%2),%%r0\n" \ + "\tproberi (%%sr%1,%2),%3,%0\n" \ + "9:\n" \ + ASM_EXCEPTIONTABLE_ENTRY(8b, 9b, \ + "or %%r0,%%r0,%%r0") \ + : "=&r" (read_allowed) \ + : "i" (sr), "r" (va), "i" (PRIV_USER) \ + : "memory" \ + ); \ + read_allowed; \ +}) +#define CR_EIEM 15/* External Interrupt Enable Mask */ #define CR_CR16 16/* CR16 Interval Timer */ #define CR_EIRR 23/* External Interrupt Request Register */
arch/parisc/lib/memcpy.c +18 -1
@@ -12,6 +12,7 @@#include <linux/module.h> #include <linux/compiler.h> #include <linux/uaccess.h> +#include <linux/mm.h> #define get_user_space () mfsp(SR_USER)#define get_kernel_space () SR_KERNEL
@@ -32,9 +33,25 @@ EXPORT_SYMBOL(raw_copy_to_user);unsigned long raw_copy_from_user (void *dst,const void __user *src,unsigned long len) { +unsigned long start = (unsigned long ) src; +unsigned long end = start + len; +unsigned long newlen = len; +mtsp (get_user_space (),SR_TEMP1 );mtsp (get_kernel_space (),SR_TEMP2 ); -return pa_memcpy (dst, (void __force *)src, len); + +/* Check region is user accessible */ +if (start) +while (start < end) { +if (!prober_user (SR_TEMP1 , start)) { + newlen = (start - (unsigned long ) src); +break ; + } + start +=PAGE_SIZE ; +/* align to page boundry which may have different permission */ + start =PAGE_ALIGN_DOWN (start); + } +return len - newlen +pa_memcpy (dst, (void __force *)src, newlen); }EXPORT_SYMBOL (raw_copy_from_user);
Greg Kroah-Hartman
maintainerPATCH 393/587 parisc: Define and use set_pte_at()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: John David Anglin <[email protected]>
commit 802e55488bc2cc1ab6423b720255a785ccac42ce upstream.
When a PTE is changed, we need to flush the PTE. set_pte_at() was lost in the folio update. PA-RISC version is the same as the generic version.
--- arch/parisc/include/asm/pgtable.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
arch/parisc/include/asm/pgtable.h +4 -3
@@ -276,7 +276,7 @@ extern unsigned long *empty_zero_page;#define pte_none (x) (pte_val(x) == 0)#define pte_present (x) (pte_val(x) & _PAGE_PRESENT)#define pte_user (x) (pte_val(x) & _PAGE_USER) -#define pte_clear (mm, addr, xp) set_pte(xp, __pte(0)) +#define pte_clear (mm, addr, xp) set_pte_at((mm), (addr), (xp), __pte(0))#define pmd_flag (x) (pmd_val(x) & PxD_FLAG_MASK)#define pmd_address (x) ((unsigned long)(pmd_val(x) &~ PxD_FLAG_MASK) << PxD_VALUE_SHIFT)
@@ -398,6 +398,7 @@ static inline void set_ptes(struct mm_st } }#define set_ptes set_ptes +#define set_pte_at (mm, addr, ptep, pte) set_ptes(mm, addr, ptep, pte, 1)/* Used for deferring calls to flush_dcache_page() */
@@ -462,7 +463,7 @@ static inline int ptep_test_and_clear_yoif (!pte_young (pte)) {return 0 ; } -set_pte (ptep,pte_mkold (pte)); +set_pte_at (vma->vm_mm, addr, ptep,pte_mkold (pte));return 1 ; }
@@ -472,7 +473,7 @@ pte_t ptep_clear_flush(struct vm_area_ststruct mm_struct ;static inline void ptep_set_wrprotect (struct mm_struct *mm,unsigned long addr,pte_t *ptep) { -set_pte (ptep,pte_wrprotect (*ptep)); +set_pte_at (mm, addr, ptep,pte_wrprotect (*ptep)); }#define pte_same (A ,B ) (pte_val(A) == pte_val(B))
Greg Kroah-Hartman
maintainerPATCH 394/587 parisc: Drop WARN_ON_ONCE() from flush_cache_vmap
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: John David Anglin <[email protected]>
commit 4eab1c27ce1f0e89ab67b01bf1e4e4c75215708a upstream.
I have observed warning to occassionally trigger.
--- arch/parisc/kernel/cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/parisc/kernel/cache.c +1 -1
@@ -841,7 +841,7 @@ void flush_cache_vmap(unsigned long star } vm =find_vm_area ((void *)start); -if (WARN_ON_ONCE (!vm)) { +if (!vm) {flush_cache_all ();return ; }
Greg Kroah-Hartman
maintainerPATCH 395/587 parisc: Makefile: explain that 64BIT requires both 32-bit and 64-bit compilers
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Randy Dunlap <[email protected]>
commit 305ab0a748c52eeaeb01d8cff6408842d19e5cb5 upstream.
For building a 64-bit kernel, both 32-bit and 64-bit VDSO binaries are built, so both 32-bit and 64-bit compilers (and tools) should be in the PATH environment variable.
--- arch/parisc/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
arch/parisc/Makefile +3 -1
@@ -39,7 +39,9 @@ endif export LD_BFD -# Set default 32 bits cross compilers for vdso +# Set default 32 bits cross compilers for vdso. +# This means that for 64BIT, both the 64-bit tools and the 32-bit tools +# need to be in the path. CC_ARCHES_32 = hppa hppa2.0 hppa1.1 CC_SUFFIXES = linux linux-gnu unknown-linux-gnu suse-linux CROSS32_COMPILE := $(call cc-cross-prefix, \
Greg Kroah-Hartman
maintainerPATCH 396/587 parisc: Rename pte_needs_flush() to pte_needs_cache_flush() in cache.c
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: John David Anglin <[email protected]>
commit 52ce9406a9625c4498c4eaa51e7a7ed9dcb9db16 upstream.
The local name used in cache.c conflicts the declaration in include/asm-generic/tlb.h.
--- arch/parisc/kernel/cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/parisc/kernel/cache.c +2 -2
@@ -425,7 +425,7 @@ static inline pte_t *get_ptep(struct mm_return ptep; } -static inline bool pte_needs_flush (pte_t pte) +static inline bool pte_needs_cache_flush (pte_t pte) {return (pte_val (pte) & (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_NO_CACHE)) == (_PAGE_PRESENT | _PAGE_ACCESSED);
@@ -630,7 +630,7 @@ static void flush_cache_page_if_present( ptep =get_ptep (vma->vm_mm, vmaddr);if (ptep) { pte =ptep_get (ptep); - needs_flush =pte_needs_flush (pte); + needs_flush =pte_needs_cache_flush (pte);pte_unmap (ptep); }if (needs_flush)
Greg Kroah-Hartman
maintainerPATCH 397/587 parisc: Revise __get_user() to probe user read access
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: John David Anglin <[email protected]>
commit 89f686a0fb6e473a876a9a60a13aec67a62b9a7e upstream.
Because of the way read access support is implemented, read access interruptions are only triggered at privilege levels 2 and 3. The kernel executes at privilege level 0, so __get_user() never triggers a read access interruption (code 26). Thus, it is currently possible for user code to access a read protected address via a system call.
Fix this by probing read access rights at privilege level 3 (PRIV_USER) and setting __gu_err to -EFAULT (-14) if access isn't allowed.
Note the cmpiclr instruction does a 32-bit compare because COND macro doesn't work inside asm.
--- arch/parisc/include/asm/uaccess.h | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
arch/parisc/include/asm/uaccess.h +18 -3
@@ -42,9 +42,24 @@ __gu_err; \ }) -#define __get_user (val, ptr) \ -({ \ - __get_user_internal(SR_USER, val, ptr); \ +#define __probe_user_internal (sr, error, ptr) \ +({ \ + __asm__("\tproberi (%%sr%1,%2),%3,%0\n" \ + "\tcmpiclr,= 1,%0,%0\n" \ + "\tldi %4,%0\n" \ + : "=r"(error) \ + : "i"(sr), "r"(ptr), "i"(PRIV_USER), \ + "i"(-EFAULT)); \ +}) + +#define __get_user (val, ptr) \ +({ \ + register long __gu_err; \ + \ + __gu_err = __get_user_internal(SR_USER, val, ptr); \ + if (likely(!__gu_err)) \ + __probe_user_internal(SR_USER, __gu_err, ptr); \ + __gu_err; \ })#define __get_user_asm (sr, val, ldx, ptr) \
Greg Kroah-Hartman
maintainerPATCH 398/587 parisc: Revise gateway LWS calls to probe user read access
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: John David Anglin <[email protected]>
commit f6334f4ae9a4e962ba74b026e1d965dfdf8cbef8 upstream.
We use load and stbys,e instructions to trigger memory reference interruptions without writing to memory. Because of the way read access support is implemented, read access interruptions are only triggered at privilege levels 2 and 3. The kernel and gateway page execute at privilege level 0, so this code never triggers a read access interruption. Thus, it is currently possible for user code to execute a LWS compare and swap operation at an address that is read protected at privilege level 3 (PRIV_USER).
Fix this by probing read access rights at privilege level 3 and branching to lws_fault if access isn't allowed.
--- arch/parisc/kernel/syscall.S | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-)
arch/parisc/kernel/syscall.S +21 -9
@@ -613,6 +613,9 @@ lws_compare_and_swap32: lws_compare_and_swap: /* Trigger memory reference interruptions without writing to memory */ 1: ldw 0(%r26), %r28 + proberi (%r26), PRIV_USER, %r28 + comb,=,n %r28, %r0, lws_fault /* backwards, likely not taken */ + nop 2: stbys,e %r0, 0(%r26) /* Calculate 8-bit hash index from virtual address */
@@ -767,6 +770,9 @@ cas2_lock_start: copy %r26, %r28 depi_safe 0, 31, 2, %r28 10: ldw 0(%r28), %r1 + proberi (%r28), PRIV_USER, %r1 + comb,=,n %r1, %r0, lws_fault /* backwards, likely not taken */ + nop 11: stbys,e %r0, 0(%r28) /* Calculate 8-bit hash index from virtual address */
@@ -951,41 +957,47 @@ atomic_xchg_begin: /* 8-bit exchange */ 1: ldb 0(%r24), %r20 + proberi (%r24), PRIV_USER, %r20 + comb,=,n %r20, %r0, lws_fault /* backwards, likely not taken */ + nop copy %r23, %r20 depi_safe 0, 31, 2, %r20 b atomic_xchg_start 2: stbys,e %r0, 0(%r20) - nop - nop - nop /* 16-bit exchange */ 3: ldh 0(%r24), %r20 + proberi (%r24), PRIV_USER, %r20 + comb,=,n %r20, %r0, lws_fault /* backwards, likely not taken */ + nop copy %r23, %r20 depi_safe 0, 31, 2, %r20 b atomic_xchg_start 4: stbys,e %r0, 0(%r20) - nop - nop - nop /* 32-bit exchange */ 5: ldw 0(%r24), %r20 + proberi (%r24), PRIV_USER, %r20 + comb,=,n %r20, %r0, lws_fault /* backwards, likely not taken */ + nop b atomic_xchg_start 6: stbys,e %r0, 0(%r23) nop nop - nop - nop - nop /* 64-bit exchange */ #ifdef CONFIG_64BIT 7: ldd 0(%r24), %r20 + proberi (%r24), PRIV_USER, %r20 + comb,=,n %r20, %r0, lws_fault /* backwards, likely not taken */ + nop 8: stdby,e %r0, 0(%r23) #else 7: ldw 0(%r24), %r20 8: ldw 4(%r24), %r20 + proberi (%r24), PRIV_USER, %r20 + comb,=,n %r20, %r0, lws_fault /* backwards, likely not taken */ + nop copy %r23, %r20 depi_safe 0, 31, 2, %r20 9: stbys,e %r0, 0(%r20)
Greg Kroah-Hartman
maintainerPATCH 399/587 parisc: Try to fixup kernel exception in bad_area_nosemaphore path of do_page_fault()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: John David Anglin <[email protected]>
commit f92a5e36b0c45cd12ac0d1bc44680c0dfae34543 upstream.
--- arch/parisc/mm/fault.c | 4 ++++ 1 file changed, 4 insertions(+)
arch/parisc/mm/fault.c +4 -0
@@ -363,6 +363,10 @@ bad_area:mmap_read_unlock (mm); bad_area_nosemaphore: +if (!user_mode (regs) &&fixup_exception (regs)) { +return ; + } +if (user_mode (regs)) {int signo, si_code;
Greg Kroah-Hartman
maintainerPATCH 400/587 parisc: Update comments in make_insert_tlb
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: John David Anglin <[email protected]>
commit cb22f247f371bd206a88cf0e0c05d80b8b62fb26 upstream.
The following testcase exposed a problem with our read access checks in get_user() and raw_copy_from_user():
#include <stdint.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/mman.h>
#include <sys/types.h>
int main(int argc, char **argv)
{
unsigned long page_size = sysconf(_SC_PAGESIZE); char *p = malloc(3 * page_size);
char *p_aligned;
/* initialize memory region. If not initialized, write syscall below will correctly return EFAULT. */ if (1)
memset(p, 'X', 3 * page_size);
p_aligned = (char *) ((((uintptr_t) p) + (2*page_size - 1)) & ~(page_size - 1)); /* Drop PROT_READ protection. Kernel and userspace should fault when accessing that memory region */ mprotect(p_aligned, page_size, PROT_NONE);
/* the following write() should return EFAULT, since PROT_READ was dropped by previous mprotect() */ int ret = write(2, p_aligned, 1);
if (!ret || errno != EFAULT)
printf("\n FAILURE: write() did not returned expected EFAULT value\n"); return 0;
}
Because of the way _PAGE_READ is handled, kernel code never generates a read access fault when it access a page as the kernel privilege level is always less than PL1 in the PTE.
This patch reworks the comments in the make_insert_tlb macro to try to make this clearer.
--- arch/parisc/kernel/entry.S | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
arch/parisc/kernel/entry.S +12 -5
@@ -499,6 +499,12 @@ * this happens is quite subtle, read below */ .macro make_insert_tlb spc,pte,prot,tmp space_to_prot \spc \prot /* create prot id from space */ + +#if _PAGE_SPECIAL_BIT == _PAGE_DMB_BIT + /* need to drop DMB bit, as it's used as SPECIAL flag */ + depi 0,_PAGE_SPECIAL_BIT,1,\pte +#endif + /* The following is the real subtlety. This is depositing * T <-> _PAGE_REFTRAP * D <-> _PAGE_DIRTY
@@ -511,17 +517,18 @@ * Finally, _PAGE_READ goes in the top bit of PL1 (so we * trigger an access rights trap in user space if the user * tries to read an unreadable page */ -#if _PAGE_SPECIAL_BIT == _PAGE_DMB_BIT - /* need to drop DMB bit, as it's used as SPECIAL flag */ - depi 0,_PAGE_SPECIAL_BIT,1,\pte -#endif depd \pte,8,7,\prot /* PAGE_USER indicates the page can be read with user privileges, * so deposit X1|11 to PL1|PL2 (remember the upper bit of PL1 - * contains _PAGE_READ) */ + * contains _PAGE_READ). While the kernel can't directly write + * user pages which have _PAGE_WRITE zero, it can read pages + * which have _PAGE_READ zero (PL <= PL1). Thus, the kernel + * exception fault handler doesn't trigger when reading pages + * that aren't user read accessible */ extrd,u,*= \pte,_PAGE_USER_BIT+32,1,%r0 depdi 7,11,3,\prot + /* If we're a gateway page, drop PL2 back to zero for promotion * to kernel privilege (so we can execute the page as kernel). * Any privilege promotion page always denys read and write */
Greg Kroah-Hartman
maintainerPATCH 401/587 media: gspca: Add bounds checking to firmware parser
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
commit aef89c0b2417da79cb2062a95476288f9f203ab0 upstream.
This sd_init() function reads the firmware. The firmware data holds a series of records and the function reads each record and sends the data to the device. The request_ihex_firmware() function
calls ihex_validate_fw() which ensures that the total length of all the records won't read out of bounds of the fw->data[].
However, a potential issue is if there is a single very large record (larger than PAGE_SIZE) and that would result in memory corruption. Generally we trust the firmware, but it's always better to double check.
--- drivers/media/usb/gspca/vicam.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/media/usb/gspca/vicam.c +8 -2
@@ -227,6 +227,7 @@ static int sd_init(struct gspca_dev *gspconst struct ihex_binrec *rec;const struct firmware *fw;u8 *firmware_buf; +int len; ret =request_ihex_firmware (&fw,VICAM_FIRMWARE , &gspca_dev->dev->dev);
@@ -241,9 +242,14 @@ static int sd_init(struct gspca_dev *gsp goto exit; }for (rec = (void *)fw->data; rec; rec =ihex_next_binrec (rec)) { -memcpy (firmware_buf, rec->data,be16_to_cpu (rec->len)); + len =be16_to_cpu (rec->len); +if (len >PAGE_SIZE ) { + ret = -EINVAL ; +break ; + } +memcpy (firmware_buf, rec->data, len); ret =vicam_control_msg (gspca_dev,0xff ,0 ,0 , firmware_buf, -be16_to_cpu (rec->len)); + len);if (ret <0 )break ; }
Greg Kroah-Hartman
maintainerPATCH 402/587 media: hi556: correct the test pattern configuration
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bingbu Cao <[email protected]>
commit 020f602b068c9ce18d5056d02c8302199377d98d upstream.
Hynix hi556 support 8 test pattern modes:
hi556_test_pattern_menu[] = {
{
"Disabled",
"Solid Colour",
"100% Colour Bars",
"Fade To Grey Colour Bars",
"PN9",
"Gradient Horizontal",
"Gradient Vertical",
"Check Board",
"Slant Pattern",
}The test pattern is set by a 8-bit register according to the specification.
+--------+-------------------------------+ | BIT[0] | Solid color | +--------+-------------------------------+ | BIT[1] | Color bar | +--------+-------------------------------+ | BIT[2] | Fade to grey color bar | +--------+-------------------------------+ | BIT[3] | PN9 | +--------+-------------------------------+ | BIT[4] | Gradient horizontal | +--------+-------------------------------+ | BIT[5] | Gradient vertical | +--------+-------------------------------+ | BIT[6] | Check board | +--------+-------------------------------+ | BIT[7] | Slant pattern | +--------+-------------------------------+
Based on function above, current test pattern programming is wrong. This patch fixes it by 'BIT(pattern - 1)'. If pattern is 0, driver will disable the test pattern generation and set the pattern to 0.
--- drivers/media/i2c/hi556.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
drivers/media/i2c/hi556.c +15 -13
@@ -689,21 +689,23 @@ static int hi556_test_pattern(struct hi5int ret;u32 val; -if (pattern) { - ret =hi556_read_reg (hi556,HI556_REG_ISP , -HI556_REG_VALUE_08BIT , &val); -if (ret) -return ret; - - ret =hi556_write_reg (hi556,HI556_REG_ISP , -HI556_REG_VALUE_08BIT , - val |HI556_REG_ISP_TPG_EN ); -if (ret) -return ret; - } + ret =hi556_read_reg (hi556,HI556_REG_ISP , +HI556_REG_VALUE_08BIT , &val); +if (ret) +return ret; + + val = pattern ? (val |HI556_REG_ISP_TPG_EN ) : + (val & ~HI556_REG_ISP_TPG_EN ); + + ret =hi556_write_reg (hi556,HI556_REG_ISP , +HI556_REG_VALUE_08BIT , val); +if (ret) +return ret; + + val = pattern ?BIT (pattern -1 ) :0 ;return hi556_write_reg (hi556,HI556_REG_TEST_PATTERN , -HI556_REG_VALUE_08BIT , pattern); +HI556_REG_VALUE_08BIT , val); }static int hi556_set_ctrl (struct v4l2_ctrl *ctrl)
Greg Kroah-Hartman
maintainerPATCH 403/587 media: imx: fix a potential memory leak in imx_media_csc_scaler_device_init()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
commit fc5f8aec77704373ee804b5dba0e0e5029c0f180 upstream.
Add video_device_release() in label 'err_m2m' to release the memory allocated by video_device_alloc() and prevent potential memory leaks. Remove the reduntant code in label 'err_m2m'.
--- drivers/staging/media/imx/imx-media-csc-scaler.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/media/imx/imx-media-csc-scaler.c +1 -1
@@ -914,7 +914,7 @@ imx_media_csc_scaler_device_init(structreturn &priv->vdev; err_m2m: -video_set_drvdata (vfd,NULL ); +video_device_release (vfd); err_vfd:kfree (priv);return ERR_PTR (ret);
Greg Kroah-Hartman
maintainerPATCH 404/587 media: vivid: fix wrong pixel_array control size
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
commit 3e43442d4994c9e1e202c98129a87e330f7faaed upstream.
The pixel_array control size was calculated incorrectly:
the dimensions were swapped (dims[0] should be the height), and the values should be the width or height divided by PIXEL_ARRAY_DIV and rounded up. So don't use roundup, but use DIV_ROUND_UP instead.
This bug is harmless in the sense that nothing will break, except that it consumes way too much memory for this control.
--- drivers/media/test-drivers/vivid/vivid-ctrls.c | 3 ++- drivers/media/test-drivers/vivid/vivid-vid-cap.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/media/test-drivers/vivid/vivid-ctrls.c +2 -1
@@ -240,7 +240,8 @@ static const struct v4l2_ctrl_config viv .min = 0x00, .max = 0xff, .step = 1, - .dims = { 640 / PIXEL_ARRAY_DIV, 360 / PIXEL_ARRAY_DIV }, + .dims = { DIV_ROUND_UP(360, PIXEL_ARRAY_DIV), + DIV_ROUND_UP(640, PIXEL_ARRAY_DIV) }, }; static const struct v4l2_ctrl_config vivid_ctrl_s32_array = {
drivers/media/test-drivers/vivid/vivid-vid-cap.c +2 -2
@@ -460,8 +460,8 @@ void vivid_update_format_cap(struct viviif (keep_controls)return ; - dims[0 ] =roundup (dev->src_rect.width,PIXEL_ARRAY_DIV ); - dims[1 ] =roundup (dev->src_rect.height,PIXEL_ARRAY_DIV ); + dims[0 ] =DIV_ROUND_UP (dev->src_rect.height,PIXEL_ARRAY_DIV ); + dims[1 ] =DIV_ROUND_UP (dev->src_rect.width,PIXEL_ARRAY_DIV );v4l2_ctrl_modify_dimensions (dev->pixel_array, dims); }
Greg Kroah-Hartman
maintainerPATCH 405/587 media: verisilicon: Fix AV1 decoder clock frequency
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nicolas Dufresne <[email protected]>
commit 01350185fe02ae3ea2c12d578e06af0d5186f33e upstream.
The desired clock frequency was correctly set to 400MHz in the device tree but was lowered by the driver to 300MHz breaking 4K 60Hz content playback. Fix the issue by removing the driver call to clk_set_rate(), which reduce the amount of board specific code.
--- drivers/media/platform/verisilicon/rockchip_vpu_hw.c | 9 --------- 1 file changed, 9 deletions(-)
drivers/media/platform/verisilicon/rockchip_vpu_hw.c +0 -9
@@ -17,7 +17,6 @@#define RK3066_ACLK_MAX_FREQ (300 * 1000 * 1000)#define RK3288_ACLK_MAX_FREQ (400 * 1000 * 1000) -#define RK3588_ACLK_MAX_FREQ (300 * 1000 * 1000)#define ROCKCHIP_VPU981_MIN_SIZE 64
@@ -441,13 +440,6 @@ static int rk3066_vpu_hw_init(struct hanreturn 0 ; } -static int rk3588_vpu981_hw_init (struct hantro_dev *vpu) -{ -/* Bump ACLKs to max. possible freq. to improve performance. */ -clk_set_rate (vpu->clocks[0 ].clk,RK3588_ACLK_MAX_FREQ ); -return 0 ; -} -static int rockchip_vpu_hw_init (struct hantro_dev *vpu) {/* Bump ACLK to max. possible freq. to improve performance. */
@@ -808,7 +800,6 @@ const struct hantro_variant rk3588_vpu98 .codec_ops = rk3588_vpu981_codec_ops, .irqs = rk3588_vpu981_irqs, .num_irqs = ARRAY_SIZE(rk3588_vpu981_irqs), - .init = rk3588_vpu981_hw_init, .clk_names = rk3588_vpu981_vpu_clk_names, .num_clocks = ARRAY_SIZE(rk3588_vpu981_vpu_clk_names) };
Greg Kroah-Hartman
maintainerPATCH 406/587 media: v4l2-ctrls: Dont reset handlers error in v4l2_ctrl_handler_free()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sakari Ailus <[email protected]>
commit 5a0400aca5fa7c6b8ba456c311a460e733571c88 upstream.
It's a common pattern in drivers to free the control handler's resources and then return the handler's error code on drivers' error handling paths. Alas, the v4l2_ctrl_handler_free() function also zeroes the error field, effectively indicating successful return to the caller.
There's no apparent need to touch the error field while releasing the control handler's resources and cleaning up stale pointers. Not touching the handler's error field is a more certain way to address this problem than changing all the users, in which case the pattern would be likely to re-emerge in new drivers.
Do just that, don't touch the control handler's error field in v4l2_ctrl_handler_free().
--- drivers/media/v4l2-core/v4l2-ctrls-core.c | 1 - 1 file changed, 1 deletion(-)
drivers/media/v4l2-core/v4l2-ctrls-core.c +0 -1
@@ -1578,7 +1578,6 @@ void v4l2_ctrl_handler_free(struct v4l2_kvfree (hdl->buckets); hdl->buckets =NULL ; hdl->cached =NULL ; - hdl->error =0 ;mutex_unlock (hdl->lock);mutex_destroy (&hdl->_lock); }
Greg Kroah-Hartman
maintainerPATCH 407/587 media: usbtv: Lock resolution while streaming
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ludwig Disterhof <[email protected]>
commit 7e40e0bb778907b2441bff68d73c3eb6b6cd319f upstream.
When an program is streaming (ffplay) and another program (qv4l2) changes the TV standard from NTSC to PAL, the kernel crashes due to trying to copy to unmapped memory.
Changing from NTSC to PAL increases the resolution in the usbtv struct, but the video plane buffer isn't adjusted, so it overflows.
--- drivers/media/usb/usbtv/usbtv-video.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/media/usb/usbtv/usbtv-video.c +4 -0
@@ -73,6 +73,10 @@ static int usbtv_configure_for_norm(stru }if (params) { +if (vb2_is_busy (&usbtv->vb2q) && + (usbtv->width != params->cap_width || + usbtv->height != params->cap_height)) +return -EBUSY ; usbtv->width = params->cap_width; usbtv->height = params->cap_height; usbtv->n_chunks = usbtv->width * usbtv->height
Greg Kroah-Hartman
maintainerPATCH 408/587 media: rainshadow-cec: fix TOCTOU race condition in rain_interrupt()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gui-Dong Han <[email protected]>
commit 7af160aea26c7dc9e6734d19306128cce156ec40 upstream.
In the interrupt handler rain_interrupt(), the buffer full check on rain->buf_len is performed before acquiring rain->buf_lock. This creates a Time-of-Check to Time-of-Use (TOCTOU) race condition, as rain->buf_len is concurrently accessed and modified in the work handler rain_irq_work_handler() under the same lock.
Multiple interrupt invocations can race, with each reading buf_len before it becomes full and then proceeding. This can lead to both interrupts attempting to write to the buffer, incrementing buf_len beyond its capacity (DATA_SIZE) and causing a buffer overflow.
Fix this bug by moving the spin_lock() to before the buffer full check. This ensures that the check and the subsequent buffer modification are performed atomically, preventing the race condition. An corresponding spin_unlock() is added to the overflow path to correctly release the lock.
This possible bug was found by an experimental static analysis tool developed by our team.
--- drivers/media/cec/usb/rainshadow/rainshadow-cec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/cec/usb/rainshadow/rainshadow-cec.c +2 -1
@@ -171,11 +171,12 @@ static irqreturn_t rain_interrupt(struct {struct rain *rain =serio_get_drvdata (serio); +spin_lock (&rain->buf_lock);if (rain->buf_len ==DATA_SIZE ) { +spin_unlock (&rain->buf_lock);dev_warn_once (rain->dev,"buffer overflow\n" );return IRQ_HANDLED ; } -spin_lock (&rain->buf_lock); rain->buf_len++; rain->buf[rain->buf_wr_idx] = data; rain->buf_wr_idx = (rain->buf_wr_idx +1 ) &0xff ;
Greg Kroah-Hartman
maintainerPATCH 409/587 media: ov2659: Fix memory leaks in ov2659_probe()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Shurong <[email protected]>
commit 76142b137b968d47b35cdd8d1dc924677d319c8b upstream.
ov2659_probe() doesn't properly free control handler resources in failure paths, causing memory leaks. Add v4l2_ctrl_handler_free() to prevent these memory leaks and reorder the ctrl_handler assignment for better code flow.
--- drivers/media/i2c/ov2659.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/i2c/ov2659.c +2 -1
@@ -1479,14 +1479,15 @@ static int ov2659_probe(struct i2c_clienV4L2_CID_TEST_PATTERN ,ARRAY_SIZE (ov2659_test_pattern_menu) -1 , 0, 0, ov2659_test_pattern_menu); - ov2659->sd.ctrl_handler = &ov2659->ctrls;if (ov2659->ctrls.error) {dev_err (&client->dev,"%s: control initialization error %d\n" , __func__, ov2659->ctrls.error); +v4l2_ctrl_handler_free (&ov2659->ctrls);return ov2659->ctrls.error; } + ov2659->sd.ctrl_handler = &ov2659->ctrls; sd = &ov2659->sd; client->flags |=I2C_CLIENT_SCCB ;#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
Greg Kroah-Hartman
maintainerPATCH 410/587 media: ivsc: Fix crash at shutdown due to missing mei_cldev_disable() calls
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans de Goede <[email protected]>
commit 0c92c49fc688cfadacc47ae99b06a31237702e9e upstream.
Both the ACE and CSI driver are missing a mei_cldev_disable() call in their remove() function.
This causes the mei_cl client to stay part of the mei_device->file_list list even though its memory is freed by mei_cl_bus_dev_release() calling kfree(cldev->cl).
This leads to a use-after-free when mei_vsc_remove() runs mei_stop() which first removes all mei bus devices calling mei_ace_remove() and mei_csi_remove() followed by mei_cl_bus_dev_release() and then calls mei_cl_all_disconnect() which walks over mei_device->file_list dereferecing the just freed cldev->cl.
And mei_vsc_remove() it self is run at shutdown because of the platform_device_unregister(tp->pdev) in vsc_tp_shutdown()
When building a kernel with KASAN this leads to the following KASAN report:
[ 106.634504] ================================================================== [ 106.634623] BUG: KASAN: slab-use-after-free in mei_cl_set_disconnected (drivers/misc/mei/client.c:783) mei [ 106.634683] Read of size 4 at addr ffff88819cb62018 by task systemd-shutdow/1 [ 106.634729] [ 106.634767] Tainted: [E]=UNSIGNED_MODULE [ 106.634770] Hardware name: Dell Inc. XPS 16 9640/09CK4V, BIOS 1.12.0 02/10/2025 [ 106.634773] Call Trace: [ 106.634777] <TASK> ... [ 106.634871] kasan_report (mm/kasan/report.c:221 mm/kasan/report.c:636) [ 106.634901] mei_cl_set_disconnected (drivers/misc/mei/client.c:783) mei [ 106.634921] mei_cl_all_disconnect (drivers/misc/mei/client.c:2165 (discriminator 4)) mei [ 106.634941] mei_reset (drivers/misc/mei/init.c:163) mei ... [ 106.635042] mei_stop (drivers/misc/mei/init.c:348) mei [ 106.635062] mei_vsc_remove (drivers/misc/mei/mei_dev.h:784 drivers/misc/mei/platform-vsc.c:393) mei_vsc [ 106.635066] platform_remove (drivers/base/platform.c:1424)
Add the missing mei_cldev_disable() calls so that the mei_cl gets removed from mei_device->file_list before it is freed to fix this.
--- drivers/media/pci/intel/ivsc/mei_ace.c | 2 ++ drivers/media/pci/intel/ivsc/mei_csi.c | 2 ++ 2 files changed, 4 insertions(+)
drivers/media/pci/intel/ivsc/mei_ace.c +2 -0
@@ -528,6 +528,8 @@ static void mei_ace_remove(struct mei_clace_set_camera_owner (ace,ACE_CAMERA_IVSC ); +mei_cldev_disable (cldev); +mutex_destroy (&ace->lock); }
drivers/media/pci/intel/ivsc/mei_csi.c +2 -0
@@ -807,6 +807,8 @@ static void mei_csi_remove(struct mei_clpm_runtime_disable (&cldev->dev); +mei_cldev_disable (cldev); +mutex_destroy (&csi->lock); }
Greg Kroah-Hartman
maintainerPATCH 411/587 media: qcom: camss: cleanup media device allocated resource on error path
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladimir Zapolskiy <[email protected]>
commit 69080ec3d0daba8a894025476c98ab16b5a505a4 upstream.
A call to media_device_init() requires media_device_cleanup() counterpart to complete cleanup and release any allocated resources.
This has been done in the driver .remove() right from the beginning, but error paths on .probe() shall also be fixed.
--- drivers/media/platform/qcom/camss/camss.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/media/platform/qcom/camss/camss.c +3 -1
@@ -1660,7 +1660,7 @@ static int camss_probe(struct platform_d ret =v4l2_device_register (camss->dev, &camss->v4l2_dev);if (ret <0 ) {dev_err (dev,"Failed to register V4L2 device: %d\n" , ret); - goto err_genpd_cleanup; + goto err_media_device_cleanup; }v4l2_async_nf_init (&camss->notifier, &camss->v4l2_dev);
@@ -1711,6 +1711,8 @@ err_v4l2_device_unregister:v4l2_device_unregister (&camss->v4l2_dev);v4l2_async_nf_cleanup (&camss->notifier);pm_runtime_disable (dev); +err_media_device_cleanup: +media_device_cleanup (&camss->media_dev); err_genpd_cleanup:camss_genpd_cleanup (camss);
Greg Kroah-Hartman
maintainerPATCH 412/587 media: venus: Add a check for packet size after reading from shared memory
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vedang Nagar <[email protected]>
commit 49befc830daa743e051a65468c05c2ff9e8580e6 upstream.
Add a check to ensure that the packet size does not exceed the number of available words after reading the packet header from shared memory. This ensures that the size provided by the firmware is safe to process and prevent potential out-of-bounds memory access.
--- drivers/media/platform/qcom/venus/hfi_venus.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/media/platform/qcom/venus/hfi_venus.c +4 -0
@@ -239,6 +239,7 @@ static int venus_write_queue(struct venustatic int venus_read_queue (struct venus_hfi_device *hdev,struct iface_queue *queue,void *pkt,u32 *tx_req) { +struct hfi_pkt_hdr *pkt_hdr =NULL ;struct hfi_queue_header *qhdr;u32 dwords, new_rd_idx;u32 rd_idx, wr_idx, type, qsize;
@@ -304,6 +305,9 @@ static int venus_read_queue(struct venusmemcpy (pkt, rd_ptr, len);memcpy (pkt + len, queue->qmem.kva, new_rd_idx <<2 ); } + pkt_hdr = (struct hfi_pkt_hdr *)(pkt); +if ((pkt_hdr->size >>2 ) != dwords) +return -EINVAL ; }else {/* bad packet received, dropping */ new_rd_idx = qhdr->write_idx;
Greg Kroah-Hartman
maintainerPATCH 413/587 media: venus: hfi: explicitly release IRQ during teardown
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jorge Ramirez-Ortiz <[email protected]>
commit 640803003cd903cea73dc6a86bf6963e238e2b3f upstream.
Ensure the IRQ is disabled - and all pending handlers completed - before dismantling the interrupt routing and clearing related pointers.
This prevents any possibility of the interrupt triggering after the handler context has been invalidated.
--- drivers/media/platform/qcom/venus/hfi_venus.c | 1 + 1 file changed, 1 insertion(+)
drivers/media/platform/qcom/venus/hfi_venus.c +1 -0
@@ -1693,6 +1693,7 @@ void venus_hfi_destroy(struct venus_corevenus_interface_queues_release (hdev);mutex_destroy (&hdev->lock);kfree (hdev); +disable_irq (core->irq); core->ops =NULL ; }
Greg Kroah-Hartman
maintainerPATCH 414/587 media: venus: protect against spurious interrupts during probe
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jorge Ramirez-Ortiz <[email protected]>
commit 3200144a2fa4209dc084a19941b9b203b43580f0 upstream.
Make sure the interrupt handler is initialized before the interrupt is registered.
If the IRQ is registered before hfi_create(), it's possible that an interrupt fires before the handler setup is complete, leading to a NULL dereference.
This error condition has been observed during system boot on Rb3Gen2.
--- drivers/media/platform/qcom/venus/core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/media/platform/qcom/venus/core.c +4 -4
@@ -334,13 +334,13 @@ static int venus_probe(struct platform_dINIT_DELAYED_WORK (&core->work, venus_sys_error_handler);init_waitqueue_head (&core->sys_err_done); - ret =devm_request_threaded_irq (dev, core->irq, hfi_isr, venus_isr_thread, -IRQF_TRIGGER_HIGH |IRQF_ONESHOT , -"venus" , core); + ret =hfi_create (core, &venus_core_ops);if (ret) goto err_core_put; - ret =hfi_create (core, &venus_core_ops); + ret =devm_request_threaded_irq (dev, core->irq, hfi_isr, venus_isr_thread, +IRQF_TRIGGER_HIGH |IRQF_ONESHOT , +"venus" , core);if (ret) goto err_core_put;
Greg Kroah-Hartman
maintainerPATCH 415/587 media: venus: vdec: Clamp param smaller than 1fps and bigger than 240.
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Ribalda <[email protected]>
commit 377dc500d253f0b26732b2cb062e89668aef890a upstream.
The driver uses "whole" fps in all its calculations (e.g. in load_per_instance()). Those calculation expect an fps bigger than 1, and not big enough to overflow.
Clamp the value if the user provides a param that will result in an invalid fps.
--- drivers/media/platform/qcom/venus/core.h | 2 ++ drivers/media/platform/qcom/venus/vdec.c | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-)
drivers/media/platform/qcom/venus/core.h +2 -0
@@ -28,6 +28,8 @@#define VIDC_PMDOMAINS_NUM_MAX 3#define VIDC_RESETS_NUM_MAX 2 +#define VENUS_MAX_FPS 240 +extern int venus_fw_debug;struct freq_tbl {
drivers/media/platform/qcom/venus/vdec.c +2 -3
@@ -481,11 +481,10 @@ static int vdec_s_parm(struct file *file us_per_frame = timeperframe->numerator * (u64 )USEC_PER_SEC ;do_div (us_per_frame, timeperframe->denominator); -if (!us_per_frame) -return -EINVAL ; - + us_per_frame =clamp (us_per_frame,1 ,USEC_PER_SEC ); fps = (u64 )USEC_PER_SEC ;do_div (fps, us_per_frame); + fps =min (VENUS_MAX_FPS , fps); inst->fps = fps; inst->timeperframe = *timeperframe;
Greg Kroah-Hartman
maintainerPATCH 416/587 media: venus: venc: Clamp param smaller than 1fps and bigger than 240
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Ribalda <[email protected]>
commit 417c01b92ec278a1118a05c6ad8a796eaa0c9c52 upstream.
The driver uses "whole" fps in all its calculations (e.g. in load_per_instance()). Those calculation expect an fps bigger than 1, and not big enough to overflow.
Clamp the param if the user provides a value that will result in an invalid fps.
--- drivers/media/platform/qcom/venus/venc.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/platform/qcom/venus/venc.c +2 -3
@@ -411,11 +411,10 @@ static int venc_s_parm(struct file *file us_per_frame = timeperframe->numerator * (u64 )USEC_PER_SEC ;do_div (us_per_frame, timeperframe->denominator); -if (!us_per_frame) -return -EINVAL ; - + us_per_frame =clamp (us_per_frame,1 ,USEC_PER_SEC ); fps = (u64 )USEC_PER_SEC ;do_div (fps, us_per_frame); + fps =min (VENUS_MAX_FPS , fps); inst->timeperframe = *timeperframe; inst->fps = fps;
Greg Kroah-Hartman
maintainerPATCH 417/587 drm/amd: Restore cached power limit during resume
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mario Limonciello <[email protected]>
commit ed4efe426a49729952b3dc05d20e33b94409bdd1 upstream.
The power limit will be cached in smu->current_power_limit but if the ASIC goes into S3 this value won't be restored.
Restore the value during SMU resume.
--- drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c +6 -0
@@ -1757,6 +1757,12 @@ static int smu_resume(void *handle) adev->pm.dpm_enabled = true; +if (smu->current_power_limit) { + ret =smu_set_power_limit (smu, smu->current_power_limit); +if (ret && ret != -EOPNOTSUPP ) +return ret; + } +dev_info (adev->dev,"SMU is resumed successfully!\n" );return 0 ;
Greg Kroah-Hartman
maintainerPATCH 418/587 drm/amdgpu: Avoid extra evict-restore process.
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gang Ba <[email protected]>
commit 1f02f2044bda1db1fd995bc35961ab075fa7b5a2 upstream.
If vm belongs to another process, this is fclose after fork,
wait may enable signaling KFD eviction fence and cause parent process queue evicted.
[677852.634569] amdkfd_fence_enable_signaling+0x56/0x70 [amdgpu] [677852.634814] __dma_fence_enable_signaling+0x3e/0xe0 [677852.634820] dma_fence_wait_timeout+0x3a/0x140 [677852.634825] amddma_resv_wait_timeout+0x7f/0xf0 [amdkcl] [677852.634831] amdgpu_vm_wait_idle+0x2d/0x60 [amdgpu] [677852.635026] amdgpu_flush+0x34/0x50 [amdgpu] [677852.635208] filp_flush+0x38/0x90 [677852.635213] filp_close+0x14/0x30 [677852.635216] do_close_on_exec+0xdd/0x130 [677852.635221] begin_new_exec+0x1da/0x490 [677852.635225] load_elf_binary+0x307/0xea0 [677852.635231] ? srso_alias_return_thunk+0x5/0xfbef5 [677852.635235] ? ima_bprm_check+0xa2/0xd0 [677852.635240] search_binary_handler+0xda/0x260 [677852.635245] exec_binprm+0x58/0x1a0 [677852.635249] bprm_execve.part.0+0x16f/0x210 [677852.635254] bprm_execve+0x45/0x80 [677852.635257] do_execveat_common.isra.0+0x190/0x200
--- drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +2 -4
@@ -2125,13 +2125,11 @@ void amdgpu_vm_adjust_size(struct amdgpu*/ long amdgpu_vm_wait_idle (struct amdgpu_vm *vm,long timeout) { - timeout =dma_resv_wait_timeout (vm->root.bo->tbo.base.resv, -DMA_RESV_USAGE_BOOKKEEP , - true, timeout); + timeout =drm_sched_entity_flush (&vm->immediate, timeout);if (timeout <=0 )return timeout; -return dma_fence_wait_timeout (vm->last_unlocked, true, timeout); +return drm_sched_entity_flush (&vm->delayed, timeout); }/**
Greg Kroah-Hartman
maintainerPATCH 419/587 drm/amdgpu: update mmhub 3.0.1 client id mappings
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Alex Deucher <[email protected]>
commit 0bae62cc989fa99ac9cb564eb573aad916d1eb61 upstream.
Update the client id mapping so the correct clients get printed when there is a mmhub page fault.
--- drivers/gpu/drm/amd/amdgpu/mmhub_v3_0_1.c | 57 ++++++++++++++++-------------- 1 file changed, 32 insertions(+), 25 deletions(-)
drivers/gpu/drm/amd/amdgpu/mmhub_v3_0_1.c +32 -25
@@ -36,40 +36,47 @@static const char *mmhub_client_ids_v3_0_1[][2 ] = { [0 ][0 ] ="VMC" , + [1 ][0 ] ="ISPXT" , + [2 ][0 ] ="ISPIXT" , [4 ][0 ] ="DCEDMC" , [5 ][0 ] ="DCEVGA" , [6 ][0 ] ="MP0" , [7 ][0 ] ="MP1" , - [8 ][0 ] ="MPIO" , - [16 ][0 ] ="HDP" , - [17 ][0 ] ="LSDMA" , - [18 ][0 ] ="JPEG" , - [19 ][0 ] ="VCNU0" , - [21 ][0 ] ="VSCH" , - [22 ][0 ] ="VCNU1" , - [23 ][0 ] ="VCN1" , - [32 +20 ][0 ] ="VCN0" , - [2 ][1 ] ="DBGUNBIO" , + [8 ][0 ] ="MPM" , + [12 ][0 ] ="ISPTNR" , + [14 ][0 ] ="ISPCRD0" , + [15 ][0 ] ="ISPCRD1" , + [16 ][0 ] ="ISPCRD2" , + [22 ][0 ] ="HDP" , + [23 ][0 ] ="LSDMA" , + [24 ][0 ] ="JPEG" , + [27 ][0 ] ="VSCH" , + [28 ][0 ] ="VCNU" , + [29 ][0 ] ="VCN" , + [1 ][1 ] ="ISPXT" , + [2 ][1 ] ="ISPIXT" , [3 ][1 ] ="DCEDWB" , [4 ][1 ] ="DCEDMC" , [5 ][1 ] ="DCEVGA" , [6 ][1 ] ="MP0" , [7 ][1 ] ="MP1" , - [8 ][1 ] ="MPIO" , - [10 ][1 ] ="DBGU0" , - [11 ][1 ] ="DBGU1" , - [12 ][1 ] ="DBGU2" , - [13 ][1 ] ="DBGU3" , - [14 ][1 ] ="XDP" , - [15 ][1 ] ="OSSSYS" , - [16 ][1 ] ="HDP" , - [17 ][1 ] ="LSDMA" , - [18 ][1 ] ="JPEG" , - [19 ][1 ] ="VCNU0" , - [20 ][1 ] ="VCN0" , - [21 ][1 ] ="VSCH" , - [22 ][1 ] ="VCNU1" , - [23 ][1 ] ="VCN1" , + [8 ][1 ] ="MPM" , + [10 ][1 ] ="ISPMWR0" , + [11 ][1 ] ="ISPMWR1" , + [12 ][1 ] ="ISPTNR" , + [13 ][1 ] ="ISPSWR" , + [14 ][1 ] ="ISPCWR0" , + [15 ][1 ] ="ISPCWR1" , + [16 ][1 ] ="ISPCWR2" , + [17 ][1 ] ="ISPCWR3" , + [18 ][1 ] ="XDP" , + [21 ][1 ] ="OSSSYS" , + [22 ][1 ] ="HDP" , + [23 ][1 ] ="LSDMA" , + [24 ][1 ] ="JPEG" , + [27 ][1 ] ="VSCH" , + [28 ][1 ] ="VCNU" , + [29 ][1 ] ="VCN" , }; static uint32_t mmhub_v3_0_1_get_invalidate_req(unsigned int vmid,
Greg Kroah-Hartman
maintainerPATCH 420/587 drm/amdkfd: Destroy KFD debugfs after destroy KFD wq
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Amber Lin <[email protected]>
commit 2e58401a24e7b2d4ec619104e1a76590c1284a4c upstream.
Since KFD proc content was moved to kernel debugfs, we can't destroy KFD debugfs before kfd_process_destroy_wq. Move kfd_process_destroy_wq prior to kfd_debugfs_fini to fix a kernel NULL pointer problem. It happens when /sys/kernel/debug/kfd was already destroyed in kfd_debugfs_fini but kfd_process_destroy_wq calls kfd_debugfs_remove_process. This line
debugfs_remove_recursive(entry->proc_dentry);
tries to remove /sys/kernel/debug/kfd/proc/<pid> while /sys/kernel/debug/kfd is already gone. It hangs the kernel by kernel NULL pointer.
--- drivers/gpu/drm/amd/amdkfd/kfd_module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_module.c +1 -1
@@ -78,8 +78,8 @@ err_ioctl:static void kfd_exit (void ) {kfd_cleanup_processes (); -kfd_debugfs_fini ();kfd_process_destroy_wq (); +kfd_debugfs_fini ();kfd_procfs_shutdown ();kfd_topology_shutdown ();kfd_chardev_exit ();
Greg Kroah-Hartman
maintainerPATCH 421/587 drm/amd/display: Add primary plane to commits for correct VRR handling
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Michel Dänzer <[email protected]>
commit 3477c1b0972dc1c8a46f78e8fb1fa6966095b5ec upstream.
amdgpu_dm_commit_planes calls update_freesync_state_on_stream only for the primary plane. If a commit affects a CRTC but not its primary plane, it would previously not trigger a refresh cycle or affect LFC, violating current UAPI semantics.
Fixes e.g. atomic commits affecting only the cursor plane being limited to the minimum refresh rate.
Don't do this for the legacy cursor ioctls though, it would break the UAPI semantics for those.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c +9 -0
@@ -410,6 +410,15 @@ static int dm_crtc_helper_atomic_check(sreturn -EINVAL ; } +if (!state->legacy_cursor_update &&amdgpu_dm_crtc_vrr_active (dm_crtc_state)) { +struct drm_plane_state *primary_state; + +/* Pull in primary plane for correct VRR handling */ + primary_state =drm_atomic_get_plane_state (state, crtc->primary); +if (IS_ERR (primary_state)) +return PTR_ERR (primary_state); + } +/* In some use cases, like reset, no stream is attached */ if (!dm_crtc_state->stream)return 0 ;
Greg Kroah-Hartman
maintainerPATCH 422/587 drm/amd/display: Dont overwrite dce60_clk_mgr
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Timur Kristóf <[email protected]>
commit 4db9cd554883e051df1840d4d58d636043101034 upstream.
dc_clk_mgr_create accidentally overwrites the dce60_clk_mgr with the dce_clk_mgr, causing incorrect behaviour on DCE6. Fix it by removing the extra dce_clk_mgr_construct.
--- drivers/gpu/drm/amd/display/dc/clk_mgr/clk_mgr.c | 1 - 1 file changed, 1 deletion(-)
drivers/gpu/drm/amd/display/dc/clk_mgr/clk_mgr.c +0 -1
@@ -162,7 +162,6 @@ struct clk_mgr *dc_clk_mgr_create(struct return NULL; }dce60_clk_mgr_construct (ctx, clk_mgr); -dce_clk_mgr_construct (ctx, clk_mgr);return &clk_mgr->base; }#endif
Greg Kroah-Hartman
maintainerPATCH 423/587 net, hsr: reject HSR frame if skb cant hold tag
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jakub Acs <[email protected]>
commit 7af76e9d18a9fd6f8611b3313c86c190f9b6a5a7 upstream.
Receiving HSR frame with insufficient space to hold HSR tag in the skb can result in a crash (kernel BUG):
[ 45.390915] skbuff: skb_under_panic: text:ffffffff86f32cac len:26 put:14 head:ffff888042418000 data:ffff888042417ff4 tail:0xe end:0x180 dev:bridge_slave_1 [ 45.392559] ------------[ cut here ]------------ [ 45.392912] kernel BUG at net/core/skbuff.c:211! [ 45.393276] Oops: invalid opcode: 0000 [#1] SMP DEBUG_PAGEALLOC KASAN NOPTI [ 45.393809] CPU: 1 UID: 0 PID: 2496 Comm: reproducer Not tainted 6.15.0 #12 PREEMPT(undef) [ 45.394433] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014 [ 45.395273] RIP: 0010:skb_panic+0x15b/0x1d0
<snip registers, remove unreliable trace>
[ 45.402911] Call Trace: [ 45.403105] <IRQ> [ 45.404470] skb_push+0xcd/0xf0 [ 45.404726] br_dev_queue_push_xmit+0x7c/0x6c0 [ 45.406513] br_forward_finish+0x128/0x260 [ 45.408483] __br_forward+0x42d/0x590 [ 45.409464] maybe_deliver+0x2eb/0x420 [ 45.409763] br_flood+0x174/0x4a0 [ 45.410030] br_handle_frame_finish+0xc7c/0x1bc0 [ 45.411618] br_handle_frame+0xac3/0x1230 [ 45.413674] __netif_receive_skb_core.constprop.0+0x808/0x3df0 [ 45.422966] __netif_receive_skb_one_core+0xb4/0x1f0 [ 45.424478] __netif_receive_skb+0x22/0x170 [ 45.424806] process_backlog+0x242/0x6d0 [ 45.425116] __napi_poll+0xbb/0x630 [ 45.425394] net_rx_action+0x4d1/0xcc0 [ 45.427613] handle_softirqs+0x1a4/0x580 [ 45.427926] do_softirq+0x74/0x90 [ 45.428196] </IRQ>
This issue was found by syzkaller.
The panic happens in br_dev_queue_push_xmit() once it receives a corrupted skb with ETH header already pushed in linear data. When it attempts the skb_push() call, there's not enough headroom and skb_push() panics.
The corrupted skb is put on the queue by HSR layer, which makes a sequence of unintended transformations when it receives a specific corrupted HSR frame (with incomplete TAG).
Fix it by dropping and consuming frames that are not long enough to contain both ethernet and hsr headers.
Alternative fix would be to check for enough headroom before skb_push() in br_dev_queue_push_xmit().
In the reproducer, this is injected via AF_PACKET, but I don't easily see why it couldn't be sent over the wire from adjacent network.
Further Details:
In the reproducer, the following network interface chain is set up:
┌────────────────┐ ┌────────────────┐
│ veth0_to_hsr ├───┤ hsr_slave0 ┼───┐
└────────────────┘ └────────────────┘ │
│ ┌──────┐
├─┤ hsr0 ├───┐
│ └──────┘ │
┌────────────────┐ ┌────────────────┐ │ │┌────────┐
│ veth1_to_hsr ┼───┤ hsr_slave1 ├───┘ └┤ │
└────────────────┘ └────────────────┘ ┌┼ bridge │
││ │
│└────────┘
│
┌───────┐ │
│ ... ├──────┘
└───────┘To trigger the events leading up to crash, reproducer sends a corrupted HSR frame with incomplete TAG, via AF_PACKET socket on 'veth0_to_hsr'.
The first HSR-layer function to process this frame is hsr_handle_frame(). It and then checks if the
protocol is ETH_P_PRP or ETH_P_HSR. If it is, it calls skb_set_network_header(skb, ETH_HLEN + HSR_HLEN), without checking that the skb is long enough. For the crashing frame it is not, and hence the skb->network_header and skb->mac_len fields are set incorrectly, pointing after the end of the linear buffer.
I will call this a BUG#1 and it is what is addressed by this patch. In the crashing scenario before the fix, the skb continues to go down the hsr path as follows.
hsr_handle_frame() then calls this sequencehsr_forward_skb()
fill_frame_info()
hsr->proto_ops->fill_frame_info()
hsr_fill_frame_info()hsr_fill_frame_info() contains a check that intends to check whether the skb actually contains the HSR header. But the check relies on the skb->mac_len field which was erroneously setup due to BUG#1, so the check passes and the execution continues back in the hsr_forward_skb():
hsr_forward_skb()
hsr_forward_do()
hsr->proto_ops->get_untagged_frame()
hsr_get_untagged_frame()
create_stripped_skb_hsr()In create_stripped_skb_hsr(), a copy of the skb is created and is further corrupted by operation that attempts to strip the HSR tag in a call to __pskb_copy().
The skb enters create_stripped_skb_hsr() with ethernet header pushed in linear buffer. The skb_pull(skb_in, HSR_HLEN) thus pulls 6 bytes of ethernet header into the headroom, creating skb_in with a headroom of size 8. The subsequent __pskb_copy() then creates an skb with headroom of just 2 and skb->len of just 12, this is how it looks after the copy:
gdb) p skb->len
$10 = 12
(gdb) p skb->data
$11 = (unsigned char *) 0xffff888041e45382 "\252\252\252\252\252!\210\373", (gdb) p skb->head
$12 = (unsigned char *) 0xffff888041e45380 ""
It seems create_stripped_skb_hsr() assumes that ETH header is pulled in the headroom when it's entered, because it just pulls HSR header on top. But that is not the case in our code-path and we end up with the corrupted skb instead. I will call this BUG#2
*I got confused here because it seems that under no conditions can create_stripped_skb_hsr() work well, the assumption it makes is not true during the processing of hsr frames - since the skb_push() in hsr_handle_frame to skb_pull in hsr_deliver_master(). I wonder whether I missed something here.*
Next, the execution arrives in hsr_deliver_master(). It calls skb_pull(ETH_HLEN), which just returns NULL - the SKB does not have enough space for the pull (as it only has 12 bytes in total at this point).
*The skb_pull() here further suggests that ethernet header is meant to be pushed through the whole hsr processing and create_stripped_skb_hsr() should pull it before doing the HSR header pull.*
hsr_deliver_master() then puts the corrupted skb on the queue, it is then picked up from there by bridge frame handling layer and finally lands in br_dev_queue_push_xmit where it panics.
--- net/hsr/hsr_slave.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
net/hsr/hsr_slave.c +7 -1
@@ -62,8 +62,14 @@ static rx_handler_result_t hsr_handle_frskb_push (skb,ETH_HLEN );skb_reset_mac_header (skb);if ((!hsr->prot_version && protocol ==htons (ETH_P_PRP )) || - protocol ==htons (ETH_P_HSR )) + protocol ==htons (ETH_P_HSR )) { +if (!pskb_may_pull (skb,ETH_HLEN +HSR_HLEN )) { +kfree_skb (skb); + goto finish_consume; + } +skb_set_network_header (skb,ETH_HLEN +HSR_HLEN ); + }skb_reset_mac_len (skb);hsr_forward_skb (skb, port);
Greg Kroah-Hartman
maintainerPATCH 424/587 ipv6: sr: Fix MAC comparison to be constant-time
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Biggers <[email protected]>
commit a458b2902115b26a25d67393b12ddd57d1216aaa upstream.
To prevent timing attacks, MACs need to be compared in constant time. Use the appropriate helper function for this.
--- net/ipv6/seg6_hmac.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
net/ipv6/seg6_hmac.c +2 -1
@@ -35,6 +35,7 @@#include <net/xfrm.h> #include <crypto/hash.h> +#include <crypto/utils.h> #include <net/seg6.h> #include <net/genetlink.h> #include <net/seg6_hmac.h>
@@ -269,7 +270,7 @@ bool seg6_hmac_validate_skb(struct sk_buif (seg6_hmac_compute (hinfo, srh, &ipv6_hdr (skb)->saddr, hmac_output))return false; -if (memcmp (hmac_output, tlv->hmac,SEG6_HMAC_FIELD_LEN ) !=0 ) +if (crypto_memneq (hmac_output, tlv->hmac,SEG6_HMAC_FIELD_LEN ))return false;return true;
Greg Kroah-Hartman
maintainerPATCH 425/587 ACPI: pfr_update: Fix the driver update version check
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chen Yu <[email protected]>
commit 8151320c747efb22d30b035af989fed0d502176e upstream.
The security-version-number check should be used rather than the runtime version check for driver updates.
Otherwise, the firmware update would fail when the update binary had a lower runtime version number than the current one.
--- drivers/acpi/pfr_update.c | 2 +- include/uapi/linux/pfrut.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/acpi/pfr_update.c +1 -1
@@ -310,7 +310,7 @@ static bool applicable_image(const voidif (type ==PFRU_CODE_INJECT_TYPE )return payload_hdr->rt_ver >= cap->code_rt_version; -return payload_hdr->rt_ver >= cap->drv_rt_version; +return payload_hdr->svn_ver >= cap->drv_svn; } static void print_update_debug_info(struct pfru_updated_result *result,
include/uapi/linux/pfrut.h +1 -0
@@ -89,6 +89,7 @@ struct pfru_payload_hdr {__u32 hw_ver;__u32 rt_ver;__u8 platform_id[16 ]; +__u32 svn_ver; };enum pfru_dsm_status {
Greg Kroah-Hartman
maintainerPATCH 426/587 mptcp: drop skb if MPTCP skb extension allocation fails
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Christoph Paasch <[email protected]>
commit ccab044697980c6c01ab51f43f48f13b8a3e5c33 upstream.
When skb_ext_add(skb, SKB_EXT_MPTCP) fails in mptcp_incoming_options(), we used to return true, letting the segment proceed through the TCP receive path without a DSS mapping. Such segments can leave inconsistent mapping state and trigger a mid-stream fallback to TCP, which in testing collapsed (by artificially forcing failures in skb_ext_add) throughput to zero.
Return false instead so the TCP input path drops the skb (see tcp_data_queue() and step-7 processing). This is the safer choice under memory pressure: it preserves MPTCP correctness and provides backpressure to the sender.
Control packets remain unaffected: ACK updates and DATA_FIN handling happen before attempting the extension allocation, and tcp_reset() continues to ignore the return value.
With this change, MPTCP continues to work at high throughput if we artificially inject failures into skb_ext_add.
--- net/mptcp/options.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
net/mptcp/options.c +4 -2
@@ -1117,7 +1117,9 @@ static bool add_addr_hmac_valid(struct mreturn hmac == mp_opt->ahmac; } -/* Return false if a subflow has been reset, else return true */ +/* Return false in case of error (or subflow has been reset), +* else return true. +*/ bool mptcp_incoming_options (struct sock *sk,struct sk_buff *skb) {struct mptcp_subflow_context *subflow =mptcp_subflow_ctx (sk);
@@ -1221,7 +1223,7 @@ bool mptcp_incoming_options(struct sock mpext =skb_ext_add (skb,SKB_EXT_MPTCP );if (!mpext) -return true; +return false;memset (mpext,0 ,sizeof (*mpext));
Greg Kroah-Hartman
maintainerPATCH 427/587 mptcp: pm: kernel: flush: do not reset ADD_ADDR limit
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Matthieu Baerts (NGI0) <[email protected]>
commit 68fc0f4b0d25692940cdc85c68e366cae63e1757 upstream.
A flush of the MPTCP endpoints should not affect the MPTCP limits. In other words, 'ip mptcp endpoint flush' should not change 'ip mptcp limits'.
But it was the case: the MPTCP_PM_ATTR_RCV_ADD_ADDRS (add_addr_accepted) limit was reset by accident. Removing the reset of this counter during a flush fixes this issue.
--- net/mptcp/pm_netlink.c | 1 - 1 file changed, 1 deletion(-)
net/mptcp/pm_netlink.c +0 -1
@@ -1783,7 +1783,6 @@ static void __flush_addrs(struct list_hestatic void __reset_counters (struct pm_nl_pernet *pernet) {WRITE_ONCE (pernet->add_addr_signal_max,0 ); -WRITE_ONCE (pernet->add_addr_accept_max,0 );WRITE_ONCE (pernet->local_addr_max,0 ); pernet->addrs =0 ; }
Greg Kroah-Hartman
maintainerPATCH 428/587 mm: drop the assumption that VM_SHARED always implies writable
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Isaac J. Manjarres" <[email protected]>
From: Lorenzo Stoakes <[email protected]>
[ Upstream commit e8e17ee90eaf650c855adb0a3e5e965fd6692ff1 ]
Patch series "permit write-sealed memfd read-only shared mappings", v4.
The man page for fcntl() describing memfd file seals states the following about F_SEAL_WRITE:-
Furthermore, trying to create new shared, writable memory-mappings via mmap(2) will also fail with EPERM.
With emphasis on 'writable'. In turns out in fact that currently the kernel simply disallows all new shared memory mappings for a memfd with F_SEAL_WRITE applied, rendering this documentation inaccurate.
This matters because users are therefore unable to obtain a shared mapping to a memfd after write sealing altogether, which limits their usefulness. This was reported in the discussion thread [1] originating from a bug report [2].
This is a product of both using the struct address_space->i_mmap_writable atomic counter to determine whether writing may be permitted, and the kernel adjusting this counter when any VM_SHARED mapping is performed and more generally implicitly assuming VM_SHARED implies writable.
It seems sensible that we should only update this mapping if VM_MAYWRITE is specified, i.e. whether it is possible that this mapping could at any point be written to.
If we do so then all we need to do to permit write seals to function as documented is to clear VM_MAYWRITE when mapping read-only. It turns out this functionality already exists for F_SEAL_FUTURE_WRITE - we can therefore simply adapt this logic to do the same for F_SEAL_WRITE.
We then hit a chicken and egg situation in mmap_region() where the check for VM_MAYWRITE occurs before we are able to clear this flag. To work around this, perform this check after we invoke call_mmap(), with careful consideration of error paths.
Thanks to Andy Lutomirski for the suggestion!
[1]:https://lore.kernel.org/all/[email protected]/ [2]:https://bugzilla.kernel.org/show_bug.cgi?id=217238
This patch (of 3):
There is a general assumption that VMAs with the VM_SHARED flag set are writable. If the VM_MAYWRITE flag is not set, then this is simply not the case.
Update those checks which affect the struct address_space->i_mmap_writable field to explicitly test for this by introducing [vma_]is_shared_maywrite() helper functions.
This remains entirely conservative, as the lack of VM_MAYWRITE guarantees that the VMA cannot be written to.
[isaacmanjarres: resolved merge conflicts due to
due to refactoring that happened in upstream commit 5de195060b2e ("mm: resolve faulty mmap_region() error path behaviour")]
--- include/linux/fs.h | 4 ++-- include/linux/mm.h | 11 +++++++++++ kernel/fork.c | 2 +- mm/filemap.c | 2 +- mm/madvise.c | 2 +- mm/mmap.c | 8 ++++---- 6 files changed, 20 insertions(+), 9 deletions(-)
include/linux/fs.h +2 -2
@@ -456,7 +456,7 @@ extern const struct address_space_operat* It is also used to block modification of page cache contents through * memory mappings. * @gfp_mask: Memory allocation flags to use for allocating pages. -* @i_mmap_writable: Number of VM_SHARED mappings. +* @i_mmap_writable: Number of VM_SHARED, VM_MAYWRITE mappings. * @nr_thps: Number of THPs in the pagecache (non-shmem only). * @i_mmap: Tree of private and shared mappings. * @i_mmap_rwsem: Protects @i_mmap and @i_mmap_writable.
@@ -559,7 +559,7 @@ static inline int mapping_mapped(struct/* * Might pages of this file have been modified in userspace? -* Note that i_mmap_writable counts all VM_SHARED vmas: do_mmap +* Note that i_mmap_writable counts all VM_SHARED, VM_MAYWRITE vmas: do_mmap * marks vma as VM_SHARED if it is shared, and the file was opened for * writing i.e. vma may be mprotected writable even if now readonly. *
include/linux/mm.h +11 -0
@@ -941,6 +941,17 @@ static inline bool vma_is_accessible(strreturn vma->vm_flags &VM_ACCESS_FLAGS ; } +static inline bool is_shared_maywrite (vm_flags_t vm_flags) +{ +return (vm_flags & (VM_SHARED |VM_MAYWRITE )) == + (VM_SHARED |VM_MAYWRITE ); +} + +static inline bool vma_is_shared_maywrite (struct vm_area_struct *vma) +{ +return is_shared_maywrite (vma->vm_flags); +} +static inline struct vm_area_struct *vma_find (struct vma_iterator *vmi,unsigned long max) {
kernel/fork.c +1 -1
@@ -739,7 +739,7 @@ static __latent_entropy int dup_mmap(strget_file (file);i_mmap_lock_write (mapping); -if (tmp->vm_flags &VM_SHARED ) +if (vma_is_shared_maywrite (tmp))mapping_allow_writable (mapping);flush_dcache_mmap_lock (mapping);/* insert tmp into the share list, just after mpnt */
mm/filemap.c +1 -1
@@ -3716,7 +3716,7 @@ int generic_file_mmap(struct file *file,*/ int generic_file_readonly_mmap (struct file *file,struct vm_area_struct *vma) { -if ((vma->vm_flags &VM_SHARED ) && (vma->vm_flags &VM_MAYWRITE )) +if (vma_is_shared_maywrite (vma))return -EINVAL ;return generic_file_mmap (file, vma); }
mm/madvise.c +1 -1
@@ -987,7 +987,7 @@ static long madvise_remove(struct vm_arereturn -EINVAL ; } -if ((vma->vm_flags & (VM_SHARED |VM_WRITE )) != (VM_SHARED |VM_WRITE )) +if (!vma_is_shared_maywrite (vma))return -EACCES ; offset = (loff_t)(start - vma->vm_start)
mm/mmap.c +4 -4
@@ -107,7 +107,7 @@ void vma_set_page_prot(struct vm_area_ststatic void __remove_shared_vm_struct (struct vm_area_struct *vma,struct file *file,struct address_space *mapping) { -if (vma->vm_flags &VM_SHARED ) +if (vma_is_shared_maywrite (vma))mapping_unmap_writable (mapping);flush_dcache_mmap_lock (mapping);
@@ -383,7 +383,7 @@ static unsigned long count_vma_pages_ranstatic void __vma_link_file (struct vm_area_struct *vma,struct address_space *mapping) { -if (vma->vm_flags &VM_SHARED ) +if (vma_is_shared_maywrite (vma))mapping_allow_writable (mapping);flush_dcache_mmap_lock (mapping);
@@ -2845,7 +2845,7 @@ cannot_expand: mm->map_count++;if (vma->vm_file) {i_mmap_lock_write (vma->vm_file->f_mapping); -if (vma->vm_flags &VM_SHARED ) +if (vma_is_shared_maywrite (vma))mapping_allow_writable (vma->vm_file->f_mapping);flush_dcache_mmap_lock (vma->vm_file->f_mapping);
@@ -2926,7 +2926,7 @@ unsigned long mmap_region(struct file *freturn -EINVAL ;/* Map writable and ensure this isn't a sealed memfd. */ -if (file && (vm_flags &VM_SHARED )) { +if (file &&is_shared_maywrite (vm_flags)) {int error =mapping_map_writable (file->f_mapping);if (error)
Greg Kroah-Hartman
maintainerPATCH 429/587 mm: update memfd seal write check to include F_SEAL_WRITE
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Isaac J. Manjarres" <[email protected]>
From: Lorenzo Stoakes <[email protected]>
[ Upstream commit 28464bbb2ddc199433383994bcb9600c8034afa1 ]
The seal_check_future_write() function is called by shmem_mmap() or hugetlbfs_file_mmap() to disallow any future writable mappings of an memfd sealed this way.
The F_SEAL_WRITE flag is not checked here, as that is handled via the mapping->i_mmap_writable mechanism and so any attempt at a mapping would fail before this could be run.
However we intend to change this, meaning this check can be performed for F_SEAL_WRITE mappings also.
The logic here is equally applicable to both flags, so update this function to accommodate both and rename it accordingly.
--- fs/hugetlbfs/inode.c | 2 +- include/linux/mm.h | 15 ++++++++------- mm/shmem.c | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-)
fs/hugetlbfs/inode.c +1 -1
@@ -136,7 +136,7 @@ static int hugetlbfs_file_mmap(struct fivm_flags_set (vma,VM_HUGETLB |VM_DONTEXPAND ); vma->vm_ops = &hugetlb_vm_ops; - ret =seal_check_future_write (info->seals, vma); + ret =seal_check_write (info->seals, vma);if (ret)return ret;
include/linux/mm.h +8 -7
@@ -4023,25 +4023,26 @@ static inline void mem_dump_obj(void *ob#endif /** -* seal_check_future_write - Check for F_SEAL_FUTURE_WRITE flag and handle it +* seal_check_write - Check for F_SEAL_WRITE or F_SEAL_FUTURE_WRITE flags and +* handle them. * @seals: the seals to check * @vma: the vma to operate on * -* Check whether F_SEAL_FUTURE_WRITE is set; if so, do proper check/handling on -* the vma flags. Return 0 if check pass, or <0 for errors. +* Check whether F_SEAL_WRITE or F_SEAL_FUTURE_WRITE are set; if so, do proper +* check/handling on the vma flags. Return 0 if check pass, or <0 for errors. */ -static inline int seal_check_future_write (int seals,struct vm_area_struct *vma) +static inline int seal_check_write (int seals,struct vm_area_struct *vma) { -if (seals &F_SEAL_FUTURE_WRITE ) { +if (seals & (F_SEAL_WRITE |F_SEAL_FUTURE_WRITE )) {/* * New PROT_WRITE and MAP_SHARED mmaps are not allowed when -* "future write" seal active. +* write seals are active. */ if ((vma->vm_flags &VM_SHARED ) && (vma->vm_flags &VM_WRITE ))return -EPERM ;/* -* Since an F_SEAL_FUTURE_WRITE sealed memfd can be mapped as +* Since an F_SEAL_[FUTURE_]WRITE sealed memfd can be mapped as * MAP_SHARED and read-only, take care to not allow mprotect to * revert protections on such mappings. Do this only for shared * mappings. For private mappings, don't need to mask
mm/shmem.c +1 -1
@@ -2396,7 +2396,7 @@ static int shmem_mmap(struct file *file,struct shmem_inode_info *info =SHMEM_I (inode);int ret; - ret =seal_check_future_write (info->seals, vma); + ret =seal_check_write (info->seals, vma);if (ret)return ret;
Greg Kroah-Hartman
maintainerPATCH 430/587 mm: reinstate ability to map write-sealed memfd mappings read-only
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Isaac J. Manjarres" <[email protected]>
From: Lorenzo Stoakes <[email protected]>
[ Upstream commit 8ec396d05d1b737c87311fb7311f753b02c2a6b1 ]
Patch series "mm: reinstate ability to map write-sealed memfd mappings read-only".
In commit 158978945f31 ("mm: perform the mapping_map_writable() check after call_mmap()") (and preceding changes in the same series) it became possible to mmap() F_SEAL_WRITE sealed memfd mappings read-only.
Commit 5de195060b2e ("mm: resolve faulty mmap_region() error path behaviour") unintentionally undid this logic by moving the mapping_map_writable() check before the shmem_mmap() hook is invoked, thereby regressing this change.
This series reworks how we both permit write-sealed mappings being mapped read-only and disallow mprotect() from undoing the write-seal, fixing this regression.
We also add a regression test to ensure that we do not accidentally regress this in future.
Thanks to Julian Orth for reporting this regression.
This patch (of 2):
In commit 158978945f31 ("mm: perform the mapping_map_writable() check after call_mmap()") (and preceding changes in the same series) it became possible to mmap() F_SEAL_WRITE sealed memfd mappings read-only.
This was previously unnecessarily disallowed, despite the man page documentation indicating that it would be, thereby limiting the usefulness of F_SEAL_WRITE logic.
We fixed this by adapting logic that existed for the F_SEAL_FUTURE_WRITE seal (one which disallows future writes to the memfd) to also be used for F_SEAL_WRITE.
For background - the F_SEAL_FUTURE_WRITE seal clears VM_MAYWRITE for a read-only mapping to disallow mprotect() from overriding the seal - an operation performed by seal_check_write(), invoked from shmem_mmap(), the f_op->mmap() hook used by shmem mappings.
By extending this to F_SEAL_WRITE and critically - checking mapping_map_writable() to determine if we may map the memfd AFTER we invoke shmem_mmap() - the desired logic becomes possible. This is because mapping_map_writable() explicitly checks for VM_MAYWRITE, which we will have cleared.
Commit 5de195060b2e ("mm: resolve faulty mmap_region() error path behaviour") unintentionally undid this logic by moving the mapping_map_writable() check before the shmem_mmap() hook is invoked, thereby regressing this change.
We reinstate this functionality by moving the check out of shmem_mmap() and instead performing it in do_mmap() at the point at which VMA flags are being determined, which seems in any case to be a more appropriate place in which to make this determination.
In order to achieve this we rework memfd seal logic to allow us access to this information using existing logic and eliminate the clearing of VM_MAYWRITE from seal_check_write() which we are performing in do_mmap() instead.
--- include/linux/memfd.h | 14 ++++++++++++ include/linux/mm.h | 58 ++++++++++++++++++++++++++++++++++---------------- mm/memfd.c | 2 - mm/mmap.c | 4 +++ 4 files changed, 59 insertions(+), 19 deletions(-)
include/linux/memfd.h +14 -0
@@ -6,11 +6,25 @@#ifdef CONFIG_MEMFD_CREATE extern long memfd_fcntl (struct file *file,unsigned int cmd,unsigned int arg); +unsigned int *memfd_file_seals_ptr (struct file *file);#else static inline long memfd_fcntl (struct file *f,unsigned int c,unsigned int a) {return -EINVAL ; } + +static inline unsigned int *memfd_file_seals_ptr (struct file *file) +{ +return NULL ; +}#endif +/* Retrieve memfd seals associated with the file, if any. */ +static inline unsigned int memfd_file_seals (struct file *file) +{ +unsigned int *sealsp =memfd_file_seals_ptr (file); + +return sealsp ? *sealsp :0 ; +} +#endif /* __LINUX_MEMFD_H */
include/linux/mm.h +40 -18
70 lines not on this page · raw message
mm/memfd.c +1 -1
@@ -134,7 +134,7 @@ static int memfd_wait_for_pins(struct adreturn error; } -static unsigned int *memfd_file_seals_ptr (struct file *file) +unsigned int *memfd_file_seals_ptr (struct file *file) {if (shmem_file (file))return &SHMEM_I (file_inode (file))->seals;
mm/mmap.c +4 -0
@@ -47,6 +47,7 @@#include <linux/oom.h> #include <linux/sched/mm.h> #include <linux/ksm.h> +#include <linux/memfd.h> #include <linux/uaccess.h> #include <asm/cacheflush.h>
@@ -1285,6 +1286,7 @@ unsigned long do_mmap(struct file *file,if (file) {struct inode *inode =file_inode (file); +unsigned int seals =memfd_file_seals (file);unsigned long flags_mask;if (!file_mmap_ok (file, inode, pgoff, len))
@@ -1323,6 +1325,8 @@ unsigned long do_mmap(struct file *file, vm_flags |=VM_SHARED |VM_MAYSHARE ;if (!(file->f_mode &FMODE_WRITE )) vm_flags &= ~(VM_MAYWRITE |VM_SHARED ); +else if (is_readonly_sealed (seals, vm_flags)) + vm_flags &= ~VM_MAYWRITE ; fallthrough;case MAP_PRIVATE :if (!(file->f_mode &FMODE_READ ))
Greg Kroah-Hartman
maintainerPATCH 431/587 selftests/memfd: add test for mapping write-sealed memfd read-only
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Isaac J. Manjarres" <[email protected]>
From: Lorenzo Stoakes <[email protected]>
[ Upstream commit ea0916e01d0b0f2cce1369ac1494239a79827270 ]
Now we have reinstated the ability to map F_SEAL_WRITE mappings read-only, assert that we are able to do this in a test to ensure that we do not regress this again.
--- tools/testing/selftests/memfd/memfd_test.c | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+)
tools/testing/selftests/memfd/memfd_test.c +43 -0
@@ -285,6 +285,24 @@ static void *mfd_assert_mmap_shared(intreturn p; } +static void *mfd_assert_mmap_read_shared (int fd) +{ +void *p; + + p =mmap (NULL , + mfd_def_size, +PROT_READ , +MAP_SHARED , + fd, +0 ); +if (p ==MAP_FAILED ) { +printf ("mmap() failed: %m\n" ); +abort (); + } + +return p; +} +static void *mfd_assert_mmap_private (int fd) {void *p;
@@ -986,6 +1004,30 @@ static void test_seal_future_write(void)close (fd); } +static void test_seal_write_map_read_shared (void ) +{ +int fd; +void *p; + +printf ("%s SEAL-WRITE-MAP-READ\n" , memfd_str); + + fd =mfd_assert_new ("kern_memfd_seal_write_map_read" , + mfd_def_size, +MFD_CLOEXEC |MFD_ALLOW_SEALING ); + +mfd_assert_add_seals (fd,F_SEAL_WRITE ); +mfd_assert_has_seals (fd,F_SEAL_WRITE ); + + p =mfd_assert_mmap_read_shared (fd); + +mfd_assert_read (fd); +mfd_assert_read_shared (fd); +mfd_fail_write (fd); + +munmap (p, mfd_def_size); +close (fd); +} +/* * Test SEAL_SHRINK * Test whether SEAL_SHRINK actually prevents shrinking
@@ -1603,6 +1645,7 @@ int main(int argc, char **argv)test_seal_write ();test_seal_future_write (); +test_seal_write_map_read_shared ();test_seal_shrink ();test_seal_grow ();test_seal_resize ();
Greg Kroah-Hartman
maintainerPATCH 432/587 net: Add net_passive_inc() and net_passive_dec().
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuniyuki Iwashima <[email protected]>
[ Upstream commit e57a6320215c3967f51ab0edeff87db2095440e4 ]
net_drop_ns() is NULL when CONFIG_NET_NS is disabled.
The next patch introduces a function that increments and decrements net->passive.
As a prep, let's rename and export net_free() tonet_passive_dec() and add net_passive_inc().
Stable-dep-of: 59b33fab4ca4 ("smb: client: fix netns refcount leak after net_passive changes")
--- include/net/net_namespace.h | 16 ++++++++++++++++ net/core/net_namespace.c | 8 ++++---- 2 files changed, 20 insertions(+), 4 deletions(-)
include/net/net_namespace.h +16 -0
@@ -293,6 +293,7 @@ static inline int check_net(const struct }void net_drop_ns (void *); +void net_passive_dec (struct net *net);#else
@@ -322,8 +323,23 @@ static inline int check_net(const struct }#define net_drop_ns NULL + +static inline void net_passive_dec (struct net *net) +{ +refcount_dec (&net->passive); +}#endif +static inline void net_passive_inc (struct net *net) +{ +refcount_inc (&net->passive); +} + +/* Returns true if the netns initialization is completed successfully */ +static inline bool net_initialized (const struct net *net) +{ +return READ_ONCE (net->list.next); +} static inline void __netns_tracker_alloc(struct net *net, netns_tracker *tracker,
net/core/net_namespace.c +4 -4
@@ -467,7 +467,7 @@ static void net_complete_free(void) } -static void net_free (struct net *net) +void net_passive_dec (struct net *net) {if (refcount_dec_and_test (&net->passive)) {kfree (rcu_access_pointer (net->gen));
@@ -485,7 +485,7 @@ void net_drop_ns(void *p)struct net *net = (struct net *)p;if (net) -net_free (net); +net_passive_dec (net); } struct net *copy_net_ns(unsigned long flags,
@@ -527,7 +527,7 @@ put_userns:key_remove_domain (net->key_domain);#endif put_user_ns (user_ns); -net_free (net); +net_passive_dec (net); dec_ucounts:dec_net_namespaces (ucounts);return ERR_PTR (rv);
@@ -672,7 +672,7 @@ static void cleanup_net(struct work_strukey_remove_domain (net->key_domain);#endif put_user_ns (net->user_ns); -net_free (net); +net_passive_dec (net); } }
Greg Kroah-Hartman
maintainerPATCH 433/587 net: better track kernel sockets lifetime
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit 5c70eb5c593d64d93b178905da215a9fd288a4b5 ]
While kernel sockets are dismantled during pernet_operations->exit(), their freeing can be delayed by any tx packets still held in qdisc or device queues, due to skb_set_owner_w() prior calls.
This then trigger the following warning from ref_tracker_dir_exit() [1]
To fix this, make sure that kernel sockets own a reference on net->passive.
Add sk_net_refcnt_upgrade() helper, used whenever a kernel socket is converted to a refcounted one.
[1]
[ 136.263918][ T35] ref_tracker: net notrefcnt@ffff8880638f01e0 has 1/2 users at [ 136.263918][ T35] sk_alloc+0x2b3/0x370 [ 136.263918][ T35] inet6_create+0x6ce/0x10f0 [ 136.263918][ T35] __sock_create+0x4c0/0xa30 [ 136.263918][ T35] inet_ctl_sock_create+0xc2/0x250 [ 136.263918][ T35] igmp6_net_init+0x39/0x390 [ 136.263918][ T35] ops_init+0x31e/0x590 [ 136.263918][ T35] setup_net+0x287/0x9e0 [ 136.263918][ T35] copy_net_ns+0x33f/0x570 [ 136.263918][ T35] create_new_namespaces+0x425/0x7b0 [ 136.263918][ T35] unshare_nsproxy_namespaces+0x124/0x180 [ 136.263918][ T35] ksys_unshare+0x57d/0xa70 [ 136.263918][ T35] __x64_sys_unshare+0x38/0x40 [ 136.263918][ T35] do_syscall_64+0xf3/0x230 [ 136.263918][ T35] entry_SYSCALL_64_after_hwframe+0x77/0x7f [ 136.263918][ T35] [ 136.343488][ T35] ref_tracker: net notrefcnt@ffff8880638f01e0 has 1/2 users at [ 136.343488][ T35] sk_alloc+0x2b3/0x370 [ 136.343488][ T35] inet6_create+0x6ce/0x10f0 [ 136.343488][ T35] __sock_create+0x4c0/0xa30 [ 136.343488][ T35] inet_ctl_sock_create+0xc2/0x250 [ 136.343488][ T35] ndisc_net_init+0xa7/0x2b0 [ 136.343488][ T35] ops_init+0x31e/0x590 [ 136.343488][ T35] setup_net+0x287/0x9e0 [ 136.343488][ T35] copy_net_ns+0x33f/0x570 [ 136.343488][ T35] create_new_namespaces+0x425/0x7b0 [ 136.343488][ T35] unshare_nsproxy_namespaces+0x124/0x180 [ 136.343488][ T35] ksys_unshare+0x57d/0xa70 [ 136.343488][ T35] __x64_sys_unshare+0x38/0x40 [ 136.343488][ T35] do_syscall_64+0xf3/0x230 [ 136.343488][ T35] entry_SYSCALL_64_after_hwframe+0x77/0x7f
--- include/net/sock.h | 1 + net/core/sock.c | 27 ++++++++++++++++++++++----- net/mptcp/subflow.c | 5 +---- net/netlink/af_netlink.c | 10 ---------- net/rds/tcp.c | 8 ++------ net/smc/af_smc.c | 5 +---- net/sunrpc/svcsock.c | 5 +---- net/sunrpc/xprtsock.c | 8 ++------ 8 files changed, 30 insertions(+), 39 deletions(-)
include/net/sock.h +1 -0
@@ -1859,6 +1859,7 @@ static inline bool sock_allow_reclassifistruct sock *sk_alloc (struct net *net,int family,gfp_t priority,struct proto *prot,int kern);void sk_free (struct sock *sk); +void sk_net_refcnt_upgrade (struct sock *sk);void sk_destruct (struct sock *sk);struct sock *sk_clone_lock (const struct sock *sk,const gfp_t priority);void sk_free_unlock_clone (struct sock *sk);
net/core/sock.c +22 -5
@@ -2159,6 +2159,7 @@ struct sock *sk_alloc(struct net *net, iget_net_track (net, &sk->ns_tracker, priority);sock_inuse_add (net,1 ); }else { +net_passive_inc (net);__netns_tracker_alloc (net, &sk->ns_tracker, false, priority); }
@@ -2183,6 +2184,7 @@ EXPORT_SYMBOL(sk_alloc);static void __sk_destruct (struct rcu_head *head) { struct sock *sk = container_of(head, struct sock, sk_rcu); +struct net *net =sock_net (sk);struct sk_filter *filter;if (sk->sk_destruct)
@@ -2214,14 +2216,28 @@ static void __sk_destruct(struct rcu_heaput_cred (sk->sk_peer_cred);put_pid (sk->sk_peer_pid); -if (likely (sk->sk_net_refcnt)) -put_net_track (sock_net (sk), &sk->ns_tracker); -else -__netns_tracker_free (sock_net (sk), &sk->ns_tracker, false); - +if (likely (sk->sk_net_refcnt)) { +put_net_track (net, &sk->ns_tracker); + }else { +__netns_tracker_free (net, &sk->ns_tracker, false); +net_passive_dec (net); + }sk_prot_free (sk->sk_prot_creator, sk); } +void sk_net_refcnt_upgrade (struct sock *sk) +{ +struct net *net =sock_net (sk); + +WARN_ON_ONCE (sk->sk_net_refcnt); +__netns_tracker_free (net, &sk->ns_tracker, false); +net_passive_dec (net); + sk->sk_net_refcnt =1 ; +get_net_track (net, &sk->ns_tracker,GFP_KERNEL ); +sock_inuse_add (net,1 ); +} +EXPORT_SYMBOL_GPL (sk_net_refcnt_upgrade); +void sk_destruct (struct sock *sk) {bool use_call_rcu =sock_flag (sk,SOCK_RCU_FREE );
@@ -2313,6 +2329,7 @@ struct sock *sk_clone_lock(const struct* is not properly dismantling its kernel sockets at netns * destroy time. */ +net_passive_inc (sock_net (newsk));__netns_tracker_alloc (sock_net (newsk), &newsk->ns_tracker, false, priority); }
net/mptcp/subflow.c +1 -4
@@ -1715,10 +1715,7 @@ int mptcp_subflow_create_socket(struct s* needs it. * Update ns_tracker to current stack trace and refcounted tracker. */ -__netns_tracker_free (net, &sf->sk->ns_tracker, false); - sf->sk->sk_net_refcnt =1 ; -get_net_track (net, &sf->sk->ns_tracker,GFP_KERNEL ); -sock_inuse_add (net,1 ); +sk_net_refcnt_upgrade (sf->sk); err =tcp_set_ulp (sf->sk,"mptcp" ); release_ssk:
net/netlink/af_netlink.c +0 -10
@@ -798,16 +798,6 @@ static int netlink_release(struct socketsock_prot_inuse_add (sock_net (sk), &netlink_proto,-1 ); -/* Because struct net might disappear soon, do not keep a pointer. */ -if (!sk->sk_net_refcnt &&sock_net (sk) != &init_net) { -__netns_tracker_free (sock_net (sk), &sk->ns_tracker, false); -/* Because of deferred_put_nlk_sk and use of work queue, -* it is possible netns will be freed before this socket. -*/ -sock_net_set (sk, &init_net); -__netns_tracker_alloc (&init_net, &sk->ns_tracker, - false,GFP_KERNEL ); - }call_rcu (&nlk->rcu, deferred_put_nlk_sk);return 0 ; }
net/rds/tcp.c +2 -6
@@ -503,12 +503,8 @@ bool rds_tcp_tune(struct socket *sock)release_sock (sk);return false; } -/* Update ns_tracker to current stack trace and refcounted tracker */ -__netns_tracker_free (net, &sk->ns_tracker, false); - - sk->sk_net_refcnt =1 ; -netns_tracker_alloc (net, &sk->ns_tracker,GFP_KERNEL ); -sock_inuse_add (net,1 ); +sk_net_refcnt_upgrade (sk); +put_net (net); } rtn =net_generic (net, rds_tcp_netid);if (rtn->sndbuf_size >0 ) {
net/smc/af_smc.c +1 -4
@@ -3343,10 +3343,7 @@ int smc_create_clcsk(struct net *net, st* which need net ref. */ sk = smc->clcsock->sk; -__netns_tracker_free (net, &sk->ns_tracker, false); - sk->sk_net_refcnt =1 ; -get_net_track (net, &sk->ns_tracker,GFP_KERNEL ); -sock_inuse_add (net,1 ); +sk_net_refcnt_upgrade (sk);return 0 ; }
net/sunrpc/svcsock.c +1 -4
@@ -1579,10 +1579,7 @@ static struct svc_xprt *svc_create_socke newlen = error;if (protocol ==IPPROTO_TCP ) { -__netns_tracker_free (net, &sock->sk->ns_tracker, false); - sock->sk->sk_net_refcnt =1 ; -get_net_track (net, &sock->sk->ns_tracker,GFP_KERNEL ); -sock_inuse_add (net,1 ); +sk_net_refcnt_upgrade (sock->sk);if ((error =kernel_listen (sock,64 )) <0 ) goto bummer; }
net/sunrpc/xprtsock.c +2 -6
@@ -1941,12 +1941,8 @@ static struct socket *xs_create_sock(str goto out; } -if (protocol ==IPPROTO_TCP ) { -__netns_tracker_free (xprt->xprt_net, &sock->sk->ns_tracker, false); - sock->sk->sk_net_refcnt =1 ; -get_net_track (xprt->xprt_net, &sock->sk->ns_tracker,GFP_KERNEL ); -sock_inuse_add (xprt->xprt_net,1 ); - } +if (protocol ==IPPROTO_TCP ) +sk_net_refcnt_upgrade (sock->sk); filp =sock_alloc_file (sock,O_NONBLOCK ,NULL );if (IS_ERR (filp))
Greg Kroah-Hartman
maintainerPATCH 434/587 smb: client: fix netns refcount leak after net_passive changes
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Wang Zhaolong <[email protected]>
[ Upstream commit 59b33fab4ca4d7dacc03367082777627e05d0323 ]
After commit 5c70eb5c593d ("net: better track kernel sockets lifetime"), kernel sockets now use net_passive reference counting. However, commit 95d2b9f693ff ("Revert "smb: client: fix TCP timers deadlock after rmmod"") restored the manual socket refcount manipulation without adapting to this new mechanism, causing a memory leak.
The issue can be reproduced by[1]:
1. Creating a network namespace
2. Mounting and Unmounting CIFS within the namespace
3. Deleting the namespace
Some memory leaks may appear after a period of time following step 3.
unreferenced object 0xffff9951419f6b00 (size 256):
comm "ip", pid 447, jiffies 4294692389 (age 14.730s) hex dump (first 32 bytes):
1b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00 00 00 00 00 00 00 00 80 77 c2 44 51 99 ff ff .........w.DQ...
backtrace:
__kmem_cache_alloc_node+0x30e/0x3d0
__kmalloc+0x52/0x120
net_alloc_generic+0x1d/0x30
copy_net_ns+0x86/0x200
create_new_namespaces+0x117/0x300
unshare_nsproxy_namespaces+0x60/0xa0
ksys_unshare+0x148/0x360
__x64_sys_unshare+0x12/0x20
do_syscall_64+0x59/0x110
entry_SYSCALL_64_after_hwframe+0x78/0xe2...
unreferenced object 0xffff9951442e7500 (size 32):
comm "mount.cifs", pid 475, jiffies 4294693782 (age 13.343s) hex dump (first 32 bytes):
40 c5 38 46 51 99 ff ff 18 01 96 42 51 99 ff ff @.8FQ......BQ...
01 00 00 00 6f 00 c5 07 6f 00 d8 07 00 00 00 00 ....o...o.......
backtrace:
__kmem_cache_alloc_node+0x30e/0x3d0
kmalloc_trace+0x2a/0x90
ref_tracker_alloc+0x8e/0x1d0
sk_alloc+0x18c/0x1c0
inet_create+0xf1/0x370
__sock_create+0xd7/0x1e0
generic_ip_connect+0x1d4/0x5a0 [cifs]
cifs_get_tcp_session+0x5d0/0x8a0 [cifs]
cifs_mount_get_session+0x47/0x1b0 [cifs]
dfs_mount_share+0xfa/0xa10 [cifs]
cifs_mount+0x68/0x2b0 [cifs]
cifs_smb3_do_mount+0x10b/0x760 [cifs]
smb3_get_tree+0x112/0x2e0 [cifs]
vfs_get_tree+0x29/0xf0
path_mount+0x2d4/0xa00
__se_sys_mount+0x165/0x1d0Root cause:
When creating kernel sockets, sk_alloc() calls net_passive_inc() for sockets with sk_net_refcnt=0. The CIFS code manually converts kernel sockets to user sockets by setting sk_net_refcnt=1, but doesn't call the corresponding net_passive_dec(). This creates an imbalance in the net_passive counter, which prevents the network namespace from being destroyed when its last user reference is dropped. As a result, the entire namespace and all its associated resources remain allocated.
Timeline of patches leading to this issue:
- commit ef7134c7fc48 ("smb: client: Fix use-after-free of network namespace.") in v6.12 fixed the original netns UAF by manually managing socket refcounts
- commit e9f2517a3e18 ("smb: client: fix TCP timers deadlock after rmmod") in v6.13 attempted to use kernel sockets but introduced TCP timer issues
- commit 5c70eb5c593d ("net: better track kernel sockets lifetime") in v6.14-rc5 introduced the net_passive mechanism with sk_net_refcnt_upgrade() for proper socket conversion
- commit 95d2b9f693ff ("Revert "smb: client: fix TCP timers deadlock after rmmod"") in v6.15-rc3 reverted to manual refcount management without adapting to the new net_passive changes
Fix this by using sk_net_refcnt_upgrade() which properly handles the net_passive counter when converting kernel sockets to user sockets.
--- fs/smb/client/connect.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
fs/smb/client/connect.c +3 -6
@@ -3162,18 +3162,15 @@ generic_ip_connect(struct TCP_Server_Infstruct net *net =cifs_net_ns (server);struct sock *sk; - rc =__sock_create (net, sfamily,SOCK_STREAM , -IPPROTO_TCP , &server->ssocket,1 ); + rc =sock_create_kern (net, sfamily,SOCK_STREAM , +IPPROTO_TCP , &server->ssocket);if (rc <0 ) {cifs_server_dbg (VFS ,"Error %d creating socket\n" , rc);return rc; } sk = server->ssocket->sk; -__netns_tracker_free (net, &sk->ns_tracker, false); - sk->sk_net_refcnt =1 ; -get_net_track (net, &sk->ns_tracker,GFP_KERNEL ); -sock_inuse_add (net,1 ); +sk_net_refcnt_upgrade (sk);/* BB other socket options to set KEEPALIVE, NODELAY? */ cifs_dbg (FYI ,"Socket created\n" );
Greg Kroah-Hartman
maintainerPATCH 435/587 net_sched: sch_ets: implement lockless ets_dump()
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Eric Dumazet <[email protected]>
[ Upstream commit c5f1dde7f731e7bf2e7c169ca42cb4989fc2f8b9 ]
Instead of relying on RTNL, ets_dump() can use READ_ONCE() annotations, paired with WRITE_ONCE() ones in ets_change().
Stable-dep-of: 87c6efc5ce9c ("net/sched: ets: use old 'nbands' while purging unused classes")
--- net/sched/sch_ets.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
net/sched/sch_ets.c +14 -11
@@ -651,7 +651,7 @@ static int ets_qdisc_change(struct Qdiscsch_tree_lock (sch); - q->nbands = nbands; +WRITE_ONCE (q->nbands, nbands);for (i = nstrict; i < q->nstrict; i++) {if (q->classes[i].qdisc->q.qlen) {list_add_tail (&q->classes[i].alist, &q->active);
@@ -663,11 +663,11 @@ static int ets_qdisc_change(struct Qdisclist_del_init (&q->classes[i].alist);qdisc_purge_queue (q->classes[i].qdisc); } - q->nstrict = nstrict; +WRITE_ONCE (q->nstrict, nstrict);memcpy (q->prio2band, priomap,sizeof (priomap));for (i =0 ; i < q->nbands; i++) - q->classes[i].quantum = quanta[i]; +WRITE_ONCE (q->classes[i].quantum, quanta[i]);for (i = oldbands; i < q->nbands; i++) { q->classes[i].qdisc = queues[i];
@@ -681,7 +681,7 @@ static int ets_qdisc_change(struct Qdiscfor (i = q->nbands; i < oldbands; i++) {qdisc_put (q->classes[i].qdisc); q->classes[i].qdisc =NULL ; - q->classes[i].quantum =0 ; +WRITE_ONCE (q->classes[i].quantum,0 ); q->classes[i].deficit =0 ;gnet_stats_basic_sync_init (&q->classes[i].bstats);memset (&q->classes[i].qstats,0 ,sizeof (q->classes[i].qstats));
@@ -738,6 +738,7 @@ static int ets_qdisc_dump(struct Qdisc *struct ets_sched *q =qdisc_priv (sch);struct nlattr *opts;struct nlattr *nest; +u8 nbands, nstrict;int band;int prio;int err;
@@ -750,21 +751,22 @@ static int ets_qdisc_dump(struct Qdisc *if (!opts) goto nla_err; -if (nla_put_u8 (skb,TCA_ETS_NBANDS , q->nbands)) + nbands =READ_ONCE (q->nbands); +if (nla_put_u8 (skb,TCA_ETS_NBANDS , nbands)) goto nla_err; -if (q->nstrict && -nla_put_u8 (skb,TCA_ETS_NSTRICT , q->nstrict)) + nstrict =READ_ONCE (q->nstrict); +if (nstrict &&nla_put_u8 (skb,TCA_ETS_NSTRICT , nstrict)) goto nla_err; -if (q->nbands > q->nstrict) { +if (nbands > nstrict) { nest =nla_nest_start (skb,TCA_ETS_QUANTA );if (!nest) goto nla_err; -for (band = q->nstrict; band < q->nbands; band++) { +for (band = nstrict; band < nbands; band++) {if (nla_put_u32 (skb,TCA_ETS_QUANTA_BAND , - q->classes[band].quantum)) +READ_ONCE (q->classes[band].quantum))) goto nla_err; }
@@ -776,7 +778,8 @@ static int ets_qdisc_dump(struct Qdisc * goto nla_err;for (prio =0 ; prio <=TC_PRIO_MAX ; prio++) { -if (nla_put_u8 (skb,TCA_ETS_PRIOMAP_BAND , q->prio2band[prio])) +if (nla_put_u8 (skb,TCA_ETS_PRIOMAP_BAND , +READ_ONCE (q->prio2band[prio]))) goto nla_err; }
Greg Kroah-Hartman
maintainerPATCH 436/587 net/sched: ets: use old nbands while purging unused classes
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Davide Caratti <[email protected]>
[ Upstream commit 87c6efc5ce9c126ae4a781bc04504b83780e3650 ]
Shuang reported sch_ets test-case [1] crashing in ets_class_qlen_notify() after recent changes from Lion [2]. The problem is: in ets_qdisc_change() we purge unused DWRR queues; the value of 'q->nbands' is the new one, and the cleanup should be done with the old one. The problem is here since my first attempts to fix ets_qdisc_change(), but it surfaced again after the recent qdisc len accounting fixes. Fix it purging idle DWRR queues before assigning a new value of 'q->nbands', so that all purge operations find a consistent configuration:
- old 'q->nbands' because it's needed by ets_class_find()
- old 'q->nstrict' because it's needed by ets_class_is_strict()
BUG: kernel NULL pointer dereference, address: 0000000000000000 #PF: supervisor read access in kernel mode #PF: error_code(0x0000) - not-present page PGD 0 P4D 0 Oops: Oops: 0000 [#1] SMP NOPTI CPU: 62 UID: 0 PID: 39457 Comm: tc Kdump: loaded Not tainted 6.12.0-116.el10.x86_64 #1 PREEMPT(voluntary) Hardware name: Dell Inc. PowerEdge R640/06DKY5, BIOS 2.12.2 07/09/2021 RIP: 0010:__list_del_entry_valid_or_report+0x4/0x80 Code: ff 4c 39 c7 0f 84 39 19 8e ff b8 01 00 00 00 c3 cc cc cc cc 66 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 90 f3 0f 1e fa <48> 8b 17 48 8b 4f 08 48 85 d2 0f 84 56 19 8e ff 48 85 c9 0f 84 ab RSP: 0018:ffffba186009f400 EFLAGS: 00010202 RAX: 00000000000000d6 RBX: 0000000000000000 RCX: 0000000000000004 RDX: ffff9f0fa29b69c0 RSI: 0000000000000000 RDI: 0000000000000000 RBP: ffffffffc12c2400 R08: 0000000000000008 R09: 0000000000000004 R10: ffffffffffffffff R11: 0000000000000004 R12: 0000000000000000 R13: ffff9f0f8cfe0000 R14: 0000000000100005 R15: 0000000000000000 FS: 00007f2154f37480(0000) GS:ffff9f269c1c0000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000000 CR3: 00000001530be001 CR4: 00000000007726f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 PKRU: 55555554 Call Trace: <TASK> ets_class_qlen_notify+0x65/0x90 [sch_ets] qdisc_tree_reduce_backlog+0x74/0x110 ets_qdisc_change+0x630/0xa40 [sch_ets] __tc_modify_qdisc.constprop.0+0x216/0x7f0 tc_modify_qdisc+0x7c/0x120 rtnetlink_rcv_msg+0x145/0x3f0 netlink_rcv_skb+0x53/0x100 netlink_unicast+0x245/0x390 netlink_sendmsg+0x21b/0x470 ____sys_sendmsg+0x39d/0x3d0 ___sys_sendmsg+0x9a/0xe0 __sys_sendmsg+0x7a/0xd0 do_syscall_64+0x7d/0x160 entry_SYSCALL_64_after_hwframe+0x76/0x7e RIP: 0033:0x7f2155114084 Code: 89 02 b8 ff ff ff ff eb bb 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 f3 0f 1e fa 80 3d 25 f0 0c 00 00 74 13 b8 2e 00 00 00 0f 05 <48> 3d 00 f0 ff ff 77 54 c3 0f 1f 00 48 83 ec 28 89 54 24 1c 48 89 RSP: 002b:00007fff1fd7a988 EFLAGS: 00000202 ORIG_RAX: 000000000000002e RAX: ffffffffffffffda RBX: 0000560ec063e5e0 RCX: 00007f2155114084 RDX: 0000000000000000 RSI: 00007fff1fd7a9f0 RDI: 0000000000000003 RBP: 00007fff1fd7aa60 R08: 0000000000000010 R09: 000000000000003f R10: 0000560ee9b3a010 R11: 0000000000000202 R12: 00007fff1fd7aae0 R13: 000000006891ccde R14: 0000560ec063e5e0 R15: 00007fff1fd7aad0 </TASK>
[1] https://lore.kernel.org/netdev/e08c7f4a6882f260011909a868311c6e9b54f3e4.1639153474.git.dcaratti@redhat.com/
[2] https://lore.kernel.org/netdev/[email protected]/
--- net/sched/sch_ets.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
net/sched/sch_ets.c +6 -5
@@ -651,6 +651,12 @@ static int ets_qdisc_change(struct Qdiscsch_tree_lock (sch); +for (i = nbands; i < oldbands; i++) { +if (i >= q->nstrict && q->classes[i].qdisc->q.qlen) +list_del_init (&q->classes[i].alist); +qdisc_purge_queue (q->classes[i].qdisc); + } +WRITE_ONCE (q->nbands, nbands);for (i = nstrict; i < q->nstrict; i++) {if (q->classes[i].qdisc->q.qlen) {
@@ -658,11 +664,6 @@ static int ets_qdisc_change(struct Qdisc q->classes[i].deficit = quanta[i]; } } -for (i = q->nbands; i < oldbands; i++) { -if (i >= q->nstrict && q->classes[i].qdisc->q.qlen) -list_del_init (&q->classes[i].alist); -qdisc_purge_queue (q->classes[i].qdisc); - }WRITE_ONCE (q->nstrict, nstrict);memcpy (q->prio2band, priomap,sizeof (priomap));
Greg Kroah-Hartman
maintainerPATCH 437/587 leds: flash: leds-qcom-flash: Limit LED current based on thermal condition
In reply to Greg Kroah-Hartman6.6-stable review patch. If anyone has any objections, please let me know.
------------------
From: Fenglin Wu <[email protected]>
[ Upstream commit a0864cf32044233e56247fa0eed3ac660f15db9e ]
The flash module has status bits to indicate different thermal conditions which are called as OTSTx. For each OTSTx status, there is a recommended total flash current for all channels to prevent the flash module entering into higher thermal level. For example, the total flash current should be limited to 1000mA/500mA respectively when the HW reaches the OTST1/OTST2 thermal level.
Stable-dep-of: fab15f57360b ("leds: flash: leds-qcom-flash: Fix registry access after re-bind")
--- drivers/leds/flash/leds-qcom-flash.c | 163 ++++++++++++++++++++++++++++++++++- 1 file changed, 162 insertions(+), 1 deletion(-)
drivers/leds/flash/leds-qcom-flash.c +162 -1
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0-only /* -* Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. +* Copyright (c) 2022, 2024 Qualcomm Innovation Center, Inc. All rights reserved. */ #include <linux/bitfield.h>
@@ -14,6 +14,9 @@#include <media/v4l2-flash-led-class.h> /* registers definitions */ +#define FLASH_REVISION_REG 0x00 +#define FLASH_4CH_REVISION_V0P1 0x01 +#define FLASH_TYPE_REG 0x04#define FLASH_TYPE_VAL 0x18
@@ -73,6 +76,16 @@#define UA_PER_MA 1000 +/* thermal threshold constants */ +#define OTST_3CH_MIN_VAL 3 +#define OTST1_4CH_MIN_VAL 0 +#define OTST1_4CH_V0P1_MIN_VAL 3 +#define OTST2_4CH_MIN_VAL 0 + +#define OTST1_MAX_CURRENT_MA 1000 +#define OTST2_MAX_CURRENT_MA 500 +#define OTST3_MAX_CURRENT_MA 200 +enum hw_type {QCOM_MVFLASH_3CH ,QCOM_MVFLASH_4CH ,
@@ -98,6 +111,9 @@ enum {REG_IRESOLUTION ,REG_CHAN_STROBE ,REG_CHAN_EN , +REG_THERM_THRSH1 , +REG_THERM_THRSH2 , +REG_THERM_THRSH3 , REG_MAX_COUNT, };
@@ -111,6 +127,9 @@ static struct reg_field mvflash_3ch_regsREG_FIELD (0x47 ,0 ,5 ),/* iresolution */ REG_FIELD_ID (0x49 ,0 ,2 ,3 ,1 ),/* chan_strobe */ REG_FIELD (0x4c ,0 ,2 ),/* chan_en */ +REG_FIELD (0x56 ,0 ,2 ),/* therm_thrsh1 */ +REG_FIELD (0x57 ,0 ,2 ),/* therm_thrsh2 */ + REG_FIELD(0x58, 0, 2), /* therm_thrsh3 */ }; static struct reg_field mvflash_4ch_regs[REG_MAX_COUNT] = {
@@ -123,6 +142,8 @@ static struct reg_field mvflash_4ch_regsREG_FIELD (0x49 ,0 ,3 ),/* iresolution */ REG_FIELD_ID (0x4a ,0 ,6 ,4 ,1 ),/* chan_strobe */ REG_FIELD (0x4e ,0 ,3 ),/* chan_en */ +REG_FIELD (0x7a ,0 ,2 ),/* therm_thrsh1 */ + REG_FIELD(0x78, 0, 2), /* therm_thrsh2 */ }; struct qcom_flash_data {
@@ -130,9 +151,11 @@ struct qcom_flash_data {struct regmap_field *r_fields[REG_MAX_COUNT ];struct mutex lock;enum hw_type hw_type; +u32 total_ma;u8 leds_count;u8 max_channels;u8 chan_en_bits; +u8 revision; };struct qcom_flash_led {
@@ -143,6 +166,7 @@ struct qcom_flash_led {u32 max_timeout_ms;u32 flash_current_ma;u32 flash_timeout_ms; +u32 current_in_use_ma;u8 *chan_id;u8 chan_count;bool enabled;
@@ -172,6 +196,127 @@ static int set_flash_module_en(struct qcreturn rc; } +static int update_allowed_flash_current (struct qcom_flash_led *led,u32 *current_ma,bool strobe) +{ +struct qcom_flash_data *flash_data = led->flash_data; +u32 therm_ma, avail_ma, thrsh[3 ], min_thrsh, sts; +int rc =0 ; + +mutex_lock (&flash_data->lock); +/* +* Put previously allocated current into allowed budget in either of these two cases: +* 1) LED is disabled; +* 2) LED is enabled repeatedly +*/ +if (!strobe || led->current_in_use_ma !=0 ) { +if (flash_data->total_ma >= led->current_in_use_ma) + flash_data->total_ma -= led->current_in_use_ma; +else + flash_data->total_ma =0 ; + + led->current_in_use_ma =0 ; +if (!strobe) + goto unlock; + } + +/* +* Cache the default thermal threshold settings, and set them to the lowest levels before +* reading over-temp real time status. If over-temp has been triggered at the lowest +* threshold, it's very likely that it would be triggered at a higher (default) threshold +* when more flash current is requested. Prevent device from triggering over-temp condition +* by limiting the flash current for the new request. +*/ + rc =regmap_field_read (flash_data->r_fields[REG_THERM_THRSH1 ], &thrsh[0 ]); +if (rc <0 ) + goto unlock; + + rc =regmap_field_read (flash_data->r_fields[REG_THERM_THRSH2 ], &thrsh[1 ]); +if (rc <0 ) + goto unlock; + +if (flash_data->hw_type ==QCOM_MVFLASH_3CH ) { + rc =regmap_field_read (flash_data->r_fields[REG_THERM_THRSH3 ], &thrsh[2 ]); +if (rc <0 ) + goto unlock; + } + + min_thrsh =OTST_3CH_MIN_VAL ; +if (flash_data->hw_type ==QCOM_MVFLASH_4CH ) + min_thrsh = (flash_data->revision ==FLASH_4CH_REVISION_V0P1 ) ? +OTST1_4CH_V0P1_MIN_VAL :OTST1_4CH_MIN_VAL ; + + rc =regmap_field_write (flash_data->r_fields[REG_THERM_THRSH1 ], min_thrsh); +if (rc <0 ) + goto unlock; + +if (flash_data->hw_type ==QCOM_MVFLASH_4CH ) + min_thrsh =OTST2_4CH_MIN_VAL ; + +/* +* The default thermal threshold settings have been updated hence +* restore them if any fault happens starting from here. +*/ + rc =regmap_field_write (flash_data->r_fields[REG_THERM_THRSH2 ], min_thrsh); +if (rc <0 ) + goto restore; + +if (flash_data->hw_type ==QCOM_MVFLASH_3CH ) { + rc =regmap_field_write (flash_data->r_fields[REG_THERM_THRSH3 ], min_thrsh); +if (rc <0 ) + goto restore; + } + +/* Read thermal level status to get corresponding derating flash current */ + rc =regmap_field_read (flash_data->r_fields[REG_STATUS2 ], &sts); +if (rc) + goto restore; + + therm_ma =FLASH_TOTAL_CURRENT_MAX_UA /1000 ; +if (flash_data->hw_type ==QCOM_MVFLASH_3CH ) { +if (sts &FLASH_STS_3CH_OTST3 ) + therm_ma =OTST3_MAX_CURRENT_MA ; +else if (sts &FLASH_STS_3CH_OTST2 ) + therm_ma =OTST2_MAX_CURRENT_MA ; +else if (sts &FLASH_STS_3CH_OTST1 ) + therm_ma =OTST1_MAX_CURRENT_MA ; + }else { +if (sts &FLASH_STS_4CH_OTST2 ) + therm_ma =OTST2_MAX_CURRENT_MA ; +else if (sts &FLASH_STS_4CH_OTST1 ) + therm_ma =OTST1_MAX_CURRENT_MA ; + } + +/* Calculate the allowed flash current for the request */ +if (therm_ma <= flash_data->total_ma) + avail_ma =0 ; +else + avail_ma = therm_ma - flash_data->total_ma; + + *current_ma =min_t (u32, *current_ma, avail_ma); + led->current_in_use_ma = *current_ma; + flash_data->total_ma += led->current_in_use_ma; + +dev_dbg (led->flash.led_cdev.dev,"allowed flash current: %dmA, total current: %dmA\n" , + led->current_in_use_ma, flash_data->total_ma); + +restore: +/* Restore to default thermal threshold settings */ + rc =regmap_field_write (flash_data->r_fields[REG_THERM_THRSH1 ], thrsh[0 ]); +if (rc <0 ) + goto unlock; + + rc =regmap_field_write (flash_data->r_fields[REG_THERM_THRSH2 ], thrsh[1 ]); +if (rc <0 ) + goto unlock; + +if (flash_data->hw_type ==QCOM_MVFLASH_3CH ) + rc =regmap_field_write (flash_data->r_fields[REG_THERM_THRSH3 ], thrsh[2 ]); + +unlock: +mutex_unlock (&flash_data->lock); +return rc; +} +static int set_flash_current (struct qcom_flash_led *led,u32 current_ma,enum led_mode mode) {struct qcom_flash_data *flash_data = led->flash_data;
@@ -313,6 +458,10 @@ static int qcom_flash_strobe_set(structif (rc)return rc; + rc =update_allowed_flash_current (led, &led->flash_current_ma, state); +if (rc <0 ) +return rc; + rc =set_flash_current (led, led->flash_current_ma,FLASH_MODE );if (rc)return rc;
@@ -429,6 +578,10 @@ static int qcom_flash_led_brightness_setif (rc)return rc; + rc =update_allowed_flash_current (led, ¤t_ma, enable); +if (rc <0 ) +return rc; + rc =set_flash_current (led, current_ma,TORCH_MODE );if (rc)return rc;
@@ -707,6 +860,14 @@ static int qcom_flash_led_probe(struct p flash_data->hw_type =QCOM_MVFLASH_4CH ; flash_data->max_channels =4 ; regs = mvflash_4ch_regs; + + rc =regmap_read (regmap, reg_base +FLASH_REVISION_REG , &val); +if (rc <0 ) { +dev_err (dev,"Failed to read flash LED module revision, rc=%d\n" , rc); +return rc; + } + + flash_data->revision = val; }else {dev_err (dev,"flash LED subtype %#x is not yet supported\n" , val);return -ENODEV ;