media: mdp3: Fix resource leaks in of_find_device_by_node
Subsystems (11)
Sasha Levin
maintainerPATCH 1/28 media: mdp3: Fix resource leaks in of_find_device_by_node
From: Lu Hongfei <[email protected]>
[ Upstream commit 35ca8ce495366909b4c2e701d1356570dd40c4e2 ]
Use put_device to release the object get through of_find_device_by_node, avoiding resource leaks.
--- drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/media/platform/mediatek/mdp3/mtk-mdp3-comp.c +2 -0
@@ -892,11 +892,13 @@ static int mdp_get_subsys_id(struct mdp_dev *mdp, struct device *dev, ret =cmdq_dev_get_client_reg (&comp_pdev->dev, &cmdq_reg, index);if (ret !=0 ) {dev_err (&comp_pdev->dev,"cmdq_dev_get_subsys fail!\n" ); +put_device (&comp_pdev->dev);return -EINVAL ; } comp->subsys_id = cmdq_reg.subsys;dev_dbg (&comp_pdev->dev,"subsys id=%d\n" , cmdq_reg.subsys); +put_device (&comp_pdev->dev);return 0 ; }
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 28/28 riscv: Add CFI error handling
From: Sami Tolvanen <[email protected]>
[ Upstream commit af0ead42f69389cd4ed68e1a4c6cde45c0adb35c ]
With CONFIG_CFI_CLANG, the compiler injects a type preamble immediately before each function and a check to validate the target function type before indirect calls:
; type preamble
.word <id>
function:
...
; indirect call check
lw t1, -4(a0)
lui t2, <hi20>
addiw t2, t2, <lo12>
beq t1, t2, .Ltmp0 ebreak
.Ltmp0:
jarl a0
Implement error handling code for the ebreak traps emitted for the checks. This produces the following oops on a CFI failure (generated using lkdtm):
[ 21.177245] CFI failure at lkdtm_indirect_call+0x22/0x32 [lkdtm] (target: lkdtm_increment_int+0x0/0x18 [lkdtm]; expected type: 0x3ad55aca) [ 21.178483] Kernel BUG [#1] [ 21.178671] Modules linked in: lkdtm [ 21.179037] CPU: 1 PID: 104 Comm: sh Not tainted 6.3.0-rc6-00037-g37d5ec6297ab #1 [ 21.179511] Hardware name: riscv-virtio,qemu (DT) [ 21.179818] epc : lkdtm_indirect_call+0x22/0x32 [lkdtm] [ 21.180106] ra : lkdtm_CFI_FORWARD_PROTO+0x48/0x7c [lkdtm] [ 21.180426] epc : ffffffff01387092 ra : ffffffff01386f14 sp : ff20000000453cf0 [ 21.180792] gp : ffffffff81308c38 tp : ff6000000243f080 t0 : ff20000000453b78 [ 21.181157] t1 : 000000003ad55aca t2 : 000000007e0c52a5 s0 : ff20000000453d00 [ 21.181506] s1 : 0000000000000001 a0 : ffffffff0138d170 a1 : ffffffff013870bc [ 21.181819] a2 : b5fea48dd89aa700 a3 : 0000000000000001 a4 : 0000000000000fff [ 21.182169] a5 : 0000000000000004 a6 : 00000000000000b7 a7 : 0000000000000000 [ 21.182591] s2 : ff20000000453e78 s3 : ffffffffffffffea s4 : 0000000000000012 [ 21.183001] s5 : ff600000023c7000 s6 : 0000000000000006 s7 : ffffffff013882a0 [ 21.183653] s8 : 0000000000000008 s9 : 0000000000000002 s10: ffffffff0138d878 [ 21.184245] s11: ffffffff0138d878 t3 : 0000000000000003 t4 : 0000000000000000 [ 21.184591] t5 : ffffffff8133df08 t6 : ffffffff8133df07 [ 21.184858] status: 0000000000000120 badaddr: 0000000000000000 cause: 0000000000000003 [ 21.185415] [<ffffffff01387092>] lkdtm_indirect_call+0x22/0x32 [lkdtm] [ 21.185772] [<ffffffff01386f14>] lkdtm_CFI_FORWARD_PROTO+0x48/0x7c [lkdtm] [ 21.186093] [<ffffffff01383552>] lkdtm_do_action+0x22/0x34 [lkdtm] [ 21.186445] [<ffffffff0138350c>] direct_entry+0x128/0x13a [lkdtm] [ 21.186817] [<ffffffff8033ed8c>] full_proxy_write+0x58/0xb2 [ 21.187352] [<ffffffff801d4fe8>] vfs_write+0x14c/0x33a [ 21.187644] [<ffffffff801d5328>] ksys_write+0x64/0xd4 [ 21.187832] [<ffffffff801d53a6>] sys_write+0xe/0x1a [ 21.188171] [<ffffffff80003996>] ret_from_syscall+0x0/0x2 [ 21.188595] Code: 0513 0f65 a303 ffc5 53b7 7e0c 839b 2a53 0363 0073 (9002) 9582 [ 21.189178] ---[ end trace 0000000000000000 ]--- [ 21.189590] Kernel panic - not syncing: Fatal exception
--- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/cfi.h | 22 ++++++++++ arch/riscv/include/asm/insn.h | 10 +++++ arch/riscv/kernel/Makefile | 2 + arch/riscv/kernel/cfi.c | 77 +++++++++++++++++++++++++++++++++++ arch/riscv/kernel/traps.c | 4 +- 6 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 arch/riscv/include/asm/cfi.h create mode 100644 arch/riscv/kernel/cfi.c
arch/riscv/Kconfig +1 -0
@@ -48,6 +48,7 @@ config RISCV select ARCH_SUPPORTS_PER_VMA_LOCK if MMU select ARCH_USE_MEMTEST select ARCH_USE_QUEUED_RWLOCKS + select ARCH_USES_CFI_TRAPS if CFI_CLANG select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT if MMU select ARCH_WANT_FRAME_POINTERS select ARCH_WANT_GENERAL_HUGETLB if !RISCV_ISA_SVNAPOT
arch/riscv/include/asm/cfi.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_RISCV_CFI_H +#define _ASM_RISCV_CFI_H + +/* +* Clang Control Flow Integrity (CFI) support. +* +* Copyright (C) 2023 Google LLC +*/ + +#include <linux/cfi.h> + +#ifdef CONFIG_CFI_CLANG +enum bug_trap_type handle_cfi_failure (struct pt_regs *regs); +#else +static inline enum bug_trap_type handle_cfi_failure (struct pt_regs *regs) +{ +return BUG_TRAP_TYPE_NONE ; +} +#endif /* CONFIG_CFI_CLANG */ + +#endif /* _ASM_RISCV_CFI_H */
arch/riscv/include/asm/insn.h +10 -0
@@ -63,6 +63,7 @@#define RVG_RS1_OPOFF 15#define RVG_RS2_OPOFF 20#define RVG_RD_OPOFF 7 +#define RVG_RS1_MASK GENMASK(4, 0)#define RVG_RD_MASK GENMASK(4, 0)/* The bit field of immediate value in RVC J instruction */
@@ -130,6 +131,7 @@#define RVC_C2_RS1_OPOFF 7#define RVC_C2_RS2_OPOFF 2#define RVC_C2_RD_OPOFF 7 +#define RVC_C2_RS1_MASK GENMASK(4, 0)/* parts of opcode for RVG*/ #define RVG_OPCODE_FENCE 0x0f
@@ -289,6 +291,10 @@ static __always_inline bool riscv_insn_is_c_jalr(u32 code)#define RV_X (X , s, mask) (((X) >> (s)) & (mask))#define RVC_X (X , s, mask) RV_X(X, s, mask) +#define RV_EXTRACT_RS1_REG (x) \ + ({typeof(x) x_ = (x); \ + (RV_X(x_, RVG_RS1_OPOFF, RVG_RS1_MASK)); }) +#define RV_EXTRACT_RD_REG (x) \ ({typeof(x) x_ = (x); \ (RV_X(x_, RVG_RD_OPOFF, RVG_RD_MASK)); })
@@ -316,6 +322,10 @@ static __always_inline bool riscv_insn_is_c_jalr(u32 code) (RV_X (x_,RV_B_IMM_11_OPOFF ,RV_B_IMM_11_MASK ) <<RV_B_IMM_11_OFF ) | \ (RV_IMM_SIGN(x_) << RV_B_IMM_SIGN_OFF); }) +#define RVC_EXTRACT_C2_RS1_REG (x) \ + ({typeof(x) x_ = (x); \ + (RV_X(x_, RVC_C2_RS1_OPOFF, RVC_C2_RS1_MASK)); }) +#define RVC_EXTRACT_JTYPE_IMM (x) \ ({typeof(x) x_ = (x); \ (RVC_X(x_, RVC_J_IMM_3_1_OPOFF, RVC_J_IMM_3_1_MASK) << RVC_J_IMM_3_1_OFF) | \
arch/riscv/kernel/Makefile +2 -0
@@ -91,6 +91,8 @@ obj-$(CONFIG_CRASH_CORE) += crash_core.o obj-$(CONFIG_JUMP_LABEL) += jump_label.o +obj-$(CONFIG_CFI_CLANG) += cfi.o + obj-$(CONFIG_EFI) += efi.o obj-$(CONFIG_COMPAT) += compat_syscall_table.o obj-$(CONFIG_COMPAT) += compat_signal.o
arch/riscv/kernel/cfi.c new file +77 -0
77 lines not on this page · raw message
arch/riscv/kernel/traps.c +3 -1
@@ -21,6 +21,7 @@#include <asm/asm-prototypes.h> #include <asm/bug.h> +#include <asm/cfi.h> #include <asm/csr.h> #include <asm/processor.h> #include <asm/ptrace.h>
@@ -271,7 +272,8 @@ void handle_break(struct pt_regs *regs) == NOTIFY_STOP)return ;#endif - else if (report_bug(regs->epc, regs) == BUG_TRAP_TYPE_WARN) + else if (report_bug(regs->epc, regs) == BUG_TRAP_TYPE_WARN || + handle_cfi_failure(regs) == BUG_TRAP_TYPE_WARN) regs->epc += get_break_insn_length(regs->epc); else die(regs, "Kernel BUG");
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 2/28 media: dvb-usb-v2: af9035: Fix null-ptr-deref in af9035_i2c_master_xfer
In reply to Sasha LevinFrom: Zhang Shurong <[email protected]>
[ Upstream commit 7bf744f2de0a848fb1d717f5831b03db96feae89 ]
In af9035_i2c_master_xfer, msg is controlled by user. When msg[i].buf is null and msg[i].len is zero, former checks on msg[i].buf would be passed. Malicious data finally reach af9035_i2c_master_xfer. If accessing msg[i].buf[0] without sanity check, null ptr deref would happen. We add check on msg[i].len to prevent crash.
Similar commit:
commit 0ed554fd769a
("media: dvb-usb: az6027: fix null-ptr-deref in az6027_i2c_xfer()")
--- drivers/media/usb/dvb-usb-v2/af9035.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/media/usb/dvb-usb-v2/af9035.c +5 -4
@@ -322,6 +322,8 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, ret = -EOPNOTSUPP ; }else if ((msg[0 ].addr == state->af9033_i2c_addr[0 ]) || (msg[0 ].addr == state->af9033_i2c_addr[1 ])) { +if (msg[0 ].len <3 || msg[1 ].len <1 ) +return -EOPNOTSUPP ;/* demod access via firmware interface */ u32 reg = msg[0 ].buf[0 ] <<16 | msg[0 ].buf[1 ] <<8 | msg[0 ].buf[2 ];
@@ -381,6 +383,8 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap, ret = -EOPNOTSUPP ; }else if ((msg[0 ].addr == state->af9033_i2c_addr[0 ]) || (msg[0 ].addr == state->af9033_i2c_addr[1 ])) { +if (msg[0 ].len <3 ) +return -EOPNOTSUPP ;/* demod access via firmware interface */ u32 reg = msg[0 ].buf[0 ] <<16 | msg[0 ].buf[1 ] <<8 | msg[0 ].buf[2 ];
@@ -388,10 +392,7 @@ static int af9035_i2c_master_xfer(struct i2c_adapter *adap,if (msg[0 ].addr == state->af9033_i2c_addr[1 ]) reg |=0x100000 ; - ret = (msg[0 ].len >=3 ) ?af9035_wr_regs (d, reg, - &msg[0 ].buf[3 ], - msg[0 ].len -3 ) - : -EOPNOTSUPP ; + ret =af9035_wr_regs (d, reg, &msg[0 ].buf[3 ], msg[0 ].len -3 ); }else {/* I2C write */ u8 buf[MAX_XFER_SIZE ];
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 3/28 media: dw2102: Fix null-ptr-deref in dw2102_i2c_transfer()
In reply to Sasha LevinFrom: Zhang Shurong <[email protected]>
[ Upstream commit 5ae544d94abc8ff77b1b9bf8774def3fa5689b5b ]
In dw2102_i2c_transfer, msg is controlled by user. When msg[i].buf is null and msg[i].len is zero, former checks on msg[i].buf would be passed. Malicious data finally reach dw2102_i2c_transfer. If accessing msg[i].buf[0] without sanity check, null ptr deref would happen. We add check on msg[i].len to prevent crash.
Similar commit:
commit 950e252cb469
("[media] dw2102: limit messages to buffer size")
--- drivers/media/usb/dvb-usb/dw2102.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
drivers/media/usb/dvb-usb/dw2102.c +24 -0
@@ -128,6 +128,10 @@ static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],switch (num) {case 2 : +if (msg[0 ].len <1 ) { + num = -EOPNOTSUPP ; +break ; + }/* read stv0299 register */ value = msg[0 ].buf[0 ];/* register */ for (i =0 ; i < msg[1 ].len; i++) {
@@ -139,6 +143,10 @@ static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],case 1 :switch (msg[0 ].addr) {case 0x68 : +if (msg[0 ].len <2 ) { + num = -EOPNOTSUPP ; +break ; + }/* write to stv0299 register */ buf6[0 ] =0x2a ; buf6[1 ] = msg[0 ].buf[0 ];
@@ -148,6 +156,10 @@ static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],break ;case 0x60 :if (msg[0 ].flags ==0 ) { +if (msg[0 ].len <4 ) { + num = -EOPNOTSUPP ; +break ; + }/* write to tuner pll */ buf6[0 ] =0x2c ; buf6[1 ] =5 ;
@@ -159,6 +171,10 @@ static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],dw210x_op_rw (d->udev,0xb2 ,0 ,0 , buf6,7 ,DW210X_WRITE_MSG ); }else { +if (msg[0 ].len <1 ) { + num = -EOPNOTSUPP ; +break ; + }/* read from tuner */ dw210x_op_rw (d->udev,0xb5 ,0 ,0 , buf6,1 ,DW210X_READ_MSG );
@@ -166,12 +182,20 @@ static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], }break ;case (DW2102_RC_QUERY ): +if (msg[0 ].len <2 ) { + num = -EOPNOTSUPP ; +break ; + }dw210x_op_rw (d->udev,0xb8 ,0 ,0 , buf6,2 ,DW210X_READ_MSG ); msg[0 ].buf[0 ] = buf6[0 ]; msg[0 ].buf[1 ] = buf6[1 ];break ;case (DW2102_VOLTAGE_CTRL ): +if (msg[0 ].len <1 ) { + num = -EOPNOTSUPP ; +break ; + } buf6[0 ] =0x30 ; buf6[1 ] = msg[0 ].buf[0 ]; dw210x_op_rw(d->udev, 0xb2, 0, 0,
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 5/28 media: anysee: fix null-ptr-deref in anysee_master_xfer
In reply to Sasha LevinFrom: Zhang Shurong <[email protected]>
[ Upstream commit c30411266fd67ea3c02a05c157231654d5a3bdc9 ]
In anysee_master_xfer, msg is controlled by user. When msg[i].buf is null and msg[i].len is zero, former checks on msg[i].buf would be passed. Malicious data finally reach anysee_master_xfer. If accessing msg[i].buf[0] without sanity check, null ptr deref would happen. We add check on msg[i].len to prevent crash.
Similar commit:
commit 0ed554fd769a
("media: dvb-usb: az6027: fix null-ptr-deref in az6027_i2c_xfer()")
--- drivers/media/usb/dvb-usb-v2/anysee.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/dvb-usb-v2/anysee.c +1 -1
@@ -202,7 +202,7 @@ static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,while (i < num) {if (num > i +1 && (msg[i+1 ].flags &I2C_M_RD )) { -if (msg[i].len >2 || msg[i+1 ].len >60 ) { +if (msg[i].len !=2 || msg[i +1 ].len >60 ) { ret = -EOPNOTSUPP ;break ; }
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 4/28 media: af9005: Fix null-ptr-deref in af9005_i2c_xfer
In reply to Sasha LevinFrom: Zhang Shurong <[email protected]>
[ Upstream commit f4ee84f27625ce1fdf41e8483fa0561a1b837d10 ]
In af9005_i2c_xfer, msg is controlled by user. When msg[i].buf is null and msg[i].len is zero, former checks on msg[i].buf would be passed. Malicious data finally reach af9005_i2c_xfer. If accessing msg[i].buf[0] without sanity check, null ptr deref would happen. We add check on msg[i].len to prevent crash.
Similar commit:
commit 0ed554fd769a
("media: dvb-usb: az6027: fix null-ptr-deref in az6027_i2c_xfer()")
--- drivers/media/usb/dvb-usb/af9005.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/media/usb/dvb-usb/af9005.c +5 -0
@@ -422,6 +422,10 @@ static int af9005_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],if (ret ==0 ) ret =2 ; }else { +if (msg[0 ].len <2 ) { + ret = -EOPNOTSUPP ; + goto unlock; + }/* write one or more registers */ reg = msg[0 ].buf[0 ]; addr = msg[0 ].addr;
@@ -431,6 +435,7 @@ static int af9005_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], ret =1 ; } +unlock:mutex_unlock (&d->i2c_mutex);return ret; }
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 22/28 usb: chipidea: add workaround for chipidea PEC bug
In reply to Sasha LevinFrom: Xu Yang <[email protected]>
[ Upstream commit 12e6ac69cc7e7d3367599ae26a92a0f9a18bc728 ]
Some NXP processors using ChipIdea USB IP have a bug when frame babble is detected.
Issue description:
In USB camera test, our controller is host in HS mode. In ISOC IN, when device sends data across the micro frame, it causes the babble in host controller. This will clear the PE bit. In spec, it also requires to set the PEC bit and then set the PCI bit. Without the PCI interrupt, the software does not know the PE is cleared.
This will add a flag CI_HDRC_HAS_PORTSC_PEC_MISSED to some impacted platform datas. And the ehci host driver will assert PEC by SW when specific conditions are satisfied.
--- drivers/usb/chipidea/ci.h | 1 + drivers/usb/chipidea/ci_hdrc_imx.c | 4 +++- drivers/usb/chipidea/core.c | 2 ++ drivers/usb/chipidea/host.c | 1 + include/linux/usb/chipidea.h | 1 + 5 files changed, 8 insertions(+), 1 deletion(-)
drivers/usb/chipidea/ci.h +1 -0
@@ -257,6 +257,7 @@ struct ci_hdrc {bool id_event;bool b_sess_valid_event;bool imx28_write_fix; +bool has_portsc_pec_bug;bool supports_runtime_pm;bool in_lpm;bool wakeup_int;
drivers/usb/chipidea/ci_hdrc_imx.c +3 -1
@@ -67,11 +67,13 @@ static const struct ci_hdrc_imx_platform_flag imx7d_usb_data = {static const struct ci_hdrc_imx_platform_flag imx7ulp_usb_data = { .flags =CI_HDRC_SUPPORTS_RUNTIME_PM | +CI_HDRC_HAS_PORTSC_PEC_MISSED |CI_HDRC_PMQOS , };static const struct ci_hdrc_imx_platform_flag imx8ulp_usb_data = { - .flags =CI_HDRC_SUPPORTS_RUNTIME_PM , + .flags =CI_HDRC_SUPPORTS_RUNTIME_PM | +CI_HDRC_HAS_PORTSC_PEC_MISSED , };static const struct of_device_id ci_hdrc_imx_dt_ids[] = {
drivers/usb/chipidea/core.c +2 -0
@@ -1045,6 +1045,8 @@ static int ci_hdrc_probe(struct platform_device *pdev) CI_HDRC_IMX28_WRITE_FIX); ci->supports_runtime_pm = !!(ci->platdata->flags &CI_HDRC_SUPPORTS_RUNTIME_PM ); + ci->has_portsc_pec_bug = !!(ci->platdata->flags & +CI_HDRC_HAS_PORTSC_PEC_MISSED );platform_set_drvdata (pdev, ci); ret =hw_device_init (ci, base);
drivers/usb/chipidea/host.c +1 -0
@@ -151,6 +151,7 @@ static int host_start(struct ci_hdrc *ci) ehci->has_hostpc = ci->hw_bank.lpm; ehci->has_tdi_phy_lpm = ci->hw_bank.lpm; ehci->imx28_write_fix = ci->imx28_write_fix; + ehci->has_ci_pec_bug = ci->has_portsc_pec_bug; priv = (struct ehci_ci_priv *)ehci->priv; priv->reg_vbus =NULL ;
include/linux/usb/chipidea.h +1 -0
@@ -63,6 +63,7 @@ struct ci_hdrc_platform_data {#define CI_HDRC_IMX_IS_HSIC BIT(14)#define CI_HDRC_PMQOS BIT(15)#define CI_HDRC_PHY_VBUS_CONTROL BIT(16) +#define CI_HDRC_HAS_PORTSC_PEC_MISSED BIT(17)enum usb_dr_mode dr_mode;#define CI_HDRC_CONTROLLER_RESET_EVENT 0#define CI_HDRC_CONTROLLER_STOPPED_EVENT 1
Signature · 7 lines
2.40.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Sasha Levin
maintainerPATCH 14/28 usb: gadget: fsl_qe_udc: validate endpoint index for ch9 udc
In reply to Sasha LevinFrom: Ma Ke <[email protected]>
[ Upstream commit ce9daa2efc0872a9a68ea51dc8000df05893ef2e ]
We should verify the bound of the array to assure that host may not manipulate the index to point past endpoint array.
--- drivers/usb/gadget/udc/fsl_qe_udc.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/usb/gadget/udc/fsl_qe_udc.c +2 -0
@@ -1959,6 +1959,8 @@ static void ch9getstatus(struct qe_udc *udc, u8 request_type, u16 value, }else if ((request_type &USB_RECIP_MASK ) ==USB_RECIP_ENDPOINT ) {/* Get endpoint status */ int pipe = index &USB_ENDPOINT_NUMBER_MASK ; +if (pipe >=USB_MAX_ENDPOINTS ) + goto stall;struct qe_ep *target_ep = &udc->eps[pipe];u16 usep;
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 7/28 media: dvb-usb-v2: gl861: Fix null-ptr-deref in gl861_i2c_master_xfer
In reply to Sasha LevinFrom: Zhang Shurong <[email protected]>
[ Upstream commit b97719a66970601cd3151a3e2020f4454a1c4ff6 ]
In gl861_i2c_master_xfer, msg is controlled by user. When msg[i].buf is null and msg[i].len is zero, former checks on msg[i].buf would be passed. Malicious data finally reach gl861_i2c_master_xfer. If accessing msg[i].buf[0] without sanity check, null ptr deref would happen. We add check on msg[i].len to prevent crash.
Similar commit:
commit 0ed554fd769a
("media: dvb-usb: az6027: fix null-ptr-deref in az6027_i2c_xfer()")
--- drivers/media/usb/dvb-usb-v2/gl861.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/dvb-usb-v2/gl861.c +1 -1
@@ -120,7 +120,7 @@ static int gl861_i2c_master_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], }else if (num ==2 && !(msg[0 ].flags &I2C_M_RD ) && (msg[1 ].flags &I2C_M_RD )) {/* I2C write + read */ -if (msg[0 ].len >1 || msg[1 ].len >sizeof (ctx->buf)) { +if (msg[0 ].len !=1 || msg[1 ].len >sizeof (ctx->buf)) { ret = -EOPNOTSUPP ; goto err; }
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 6/28 media: az6007: Fix null-ptr-deref in az6007_i2c_xfer()
In reply to Sasha LevinFrom: Zhang Shurong <[email protected]>
[ Upstream commit 1047f9343011f2cedc73c64829686206a7e9fc3f ]
In az6007_i2c_xfer, msg is controlled by user. When msg[i].buf is null and msg[i].len is zero, former checks on msg[i].buf would be passed. Malicious data finally reach az6007_i2c_xfer. If accessing msg[i].buf[0] without sanity check, null ptr deref would happen. We add check on msg[i].len to prevent crash.
Similar commit:
commit 0ed554fd769a
("media: dvb-usb: az6027: fix null-ptr-deref in az6027_i2c_xfer()")
--- drivers/media/usb/dvb-usb-v2/az6007.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/media/usb/dvb-usb-v2/az6007.c +8 -0
@@ -788,6 +788,10 @@ static int az6007_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],if (az6007_xfer_debug)printk (KERN_DEBUG "az6007: I2C W addr=0x%x len=%d\n" , addr, msgs[i].len); +if (msgs[i].len <1 ) { + ret = -EIO ; + goto err; + } req =AZ6007_I2C_WR ; index = msgs[i].buf[0 ]; value = addr | (1 <<8 );
@@ -802,6 +806,10 @@ static int az6007_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[],if (az6007_xfer_debug)printk (KERN_DEBUG "az6007: I2C R addr=0x%x len=%d\n" , addr, msgs[i].len); +if (msgs[i].len <1 ) { + ret = -EIO ; + goto err; + } req =AZ6007_I2C_RD ; index = msgs[i].buf[0 ]; value = addr;
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 9/28 scsi: lpfc: Abort outstanding ELS cmds when mailbox timeout error is detected
In reply to Sasha LevinFrom: Justin Tee <[email protected]>
[ Upstream commit 089ea22e374aa20043e72243c47b5867d5419d38 ]
A mailbox timeout error usually indicates something has gone wrong, and a follow up reset of the HBA is a typical recovery mechanism. Introduce a MBX_TMO_ERR flag to detect such cases and have lpfc_els_flush_cmd abort ELS commands if the MBX_TMO_ERR flag condition was set. This ensures all of the registered SGL resources meant for ELS traffic are not leaked after an HBA reset.
--- drivers/scsi/lpfc/lpfc.h | 1 + drivers/scsi/lpfc/lpfc_els.c | 25 ++++++++++++++++++------- drivers/scsi/lpfc/lpfc_init.c | 20 +++++++++++++++++--- drivers/scsi/lpfc/lpfc_sli.c | 8 +++++++- 4 files changed, 43 insertions(+), 11 deletions(-)
drivers/scsi/lpfc/lpfc.h +1 -0
@@ -872,6 +872,7 @@ enum lpfc_irq_chann_mode {enum lpfc_hba_bit_flags {FABRIC_COMANDS_BLOCKED ,HBA_PCI_ERR , +MBX_TMO_ERR , };struct lpfc_hba {
drivers/scsi/lpfc/lpfc_els.c +18 -7
@@ -9588,11 +9588,13 @@ void lpfc_els_flush_cmd(struct lpfc_vport *vport) {LIST_HEAD (abort_list); +LIST_HEAD (cancel_list);struct lpfc_hba *phba = vport->phba;struct lpfc_sli_ring *pring;struct lpfc_iocbq *tmp_iocb, *piocb;u32 ulp_command;unsigned long iflags =0 ; +bool mbx_tmo_err;lpfc_fabric_abort_vport (vport);
@@ -9614,15 +9616,16 @@ lpfc_els_flush_cmd(struct lpfc_vport *vport)if (phba->sli_rev ==LPFC_SLI_REV4 )spin_lock (&pring->ring_lock); + mbx_tmo_err =test_bit (MBX_TMO_ERR , &phba->bit_flags);/* First we need to issue aborts to outstanding cmds on txcmpl */ list_for_each_entry_safe (piocb, tmp_iocb, &pring->txcmplq, list) { -if (piocb->cmd_flag &LPFC_IO_LIBDFC ) +if (piocb->cmd_flag &LPFC_IO_LIBDFC && !mbx_tmo_err)continue ;if (piocb->vport != vport)continue ; -if (piocb->cmd_flag &LPFC_DRIVER_ABORTED ) +if (piocb->cmd_flag &LPFC_DRIVER_ABORTED && !mbx_tmo_err)continue ;/* On the ELS ring we can have ELS_REQUESTs or
@@ -9641,8 +9644,8 @@ lpfc_els_flush_cmd(struct lpfc_vport *vport)*/ if (phba->link_state ==LPFC_LINK_DOWN ) piocb->cmd_cmpl = lpfc_cmpl_els_link_down; - } -if (ulp_command ==CMD_GEN_REQUEST64_CR ) + }else if (ulp_command ==CMD_GEN_REQUEST64_CR || + mbx_tmo_err)list_add_tail (&piocb->dlist, &abort_list); }
@@ -9654,11 +9657,19 @@ lpfc_els_flush_cmd(struct lpfc_vport *vport)list_for_each_entry_safe (piocb, tmp_iocb, &abort_list, dlist) {spin_lock_irqsave (&phba->hbalock, iflags);list_del_init (&piocb->dlist); -lpfc_sli_issue_abort_iotag (phba, pring, piocb,NULL ); +if (mbx_tmo_err) +list_move_tail (&piocb->list, &cancel_list); +else +lpfc_sli_issue_abort_iotag (phba, pring, piocb,NULL ); +spin_unlock_irqrestore (&phba->hbalock, iflags); } -/* Make sure HBA is alive */ -lpfc_issue_hb_tmo (phba); +if (!list_empty (&cancel_list)) +lpfc_sli_cancel_iocbs (phba, &cancel_list,IOSTAT_LOCAL_REJECT , +IOERR_SLI_ABORTED ); +else +/* Make sure HBA is alive */ +lpfc_issue_hb_tmo (phba);if (!list_empty (&abort_list)) lpfc_printf_vlog(vport, KERN_ERR, LOG_TRACE_EVENT,
drivers/scsi/lpfc/lpfc_init.c +17 -3
@@ -7550,6 +7550,8 @@ lpfc_disable_pci_dev(struct lpfc_hba *phba)void lpfc_reset_hba (struct lpfc_hba *phba) { +int rc =0 ; +/* If resets are disabled then set error state and return. */ if (!phba->cfg_enable_hba_reset) { phba->link_state =LPFC_HBA_ERROR ;
@@ -7560,13 +7562,25 @@ lpfc_reset_hba(struct lpfc_hba *phba)if (phba->sli.sli_flag &LPFC_SLI_ACTIVE ) {lpfc_offline_prep (phba,LPFC_MBX_WAIT ); }else { +if (test_bit (MBX_TMO_ERR , &phba->bit_flags)) { +/* Perform a PCI function reset to start from clean */ + rc =lpfc_pci_function_reset (phba); +lpfc_els_flush_all_cmd (phba); + }lpfc_offline_prep (phba,LPFC_MBX_NO_WAIT );lpfc_sli_flush_io_rings (phba); }lpfc_offline (phba); -lpfc_sli_brdrestart (phba); -lpfc_online (phba); -lpfc_unblock_mgmt_io (phba); +clear_bit (MBX_TMO_ERR , &phba->bit_flags); +if (unlikely (rc)) { +lpfc_printf_log (phba,KERN_ERR ,LOG_SLI , +"8888 PCI function reset failed rc %x\n" , + rc); + }else { +lpfc_sli_brdrestart (phba); +lpfc_online (phba); +lpfc_unblock_mgmt_io (phba); + } }/**
drivers/scsi/lpfc/lpfc_sli.c +7 -1
@@ -3935,6 +3935,8 @@ void lpfc_poll_eratt(struct timer_list *t)uint64_t sli_intr, cnt; phba =from_timer (phba, t, eratt_poll); +if (!(phba->hba_flag &HBA_SETUP )) +return ;/* Here we will also keep track of interrupts per sec of the hba */ sli_intr = phba->sli.slistat.sli_intr;
@@ -7693,7 +7695,9 @@ lpfc_sli4_repost_sgl_list(struct lpfc_hba *phba,spin_unlock_irq (&phba->hbalock); }else {lpfc_printf_log (phba,KERN_ERR ,LOG_TRACE_EVENT , -"3161 Failure to post sgl to port.\n" ); +"3161 Failure to post sgl to port,status %x " +"blkcnt %d totalcnt %d postcnt %d\n" , + status, block_cnt, total_cnt, post_cnt);return -EIO ; }
@@ -8478,6 +8482,7 @@ lpfc_sli4_hba_setup(struct lpfc_hba *phba)spin_unlock_irq (&phba->hbalock); } } + phba->hba_flag &= ~HBA_SETUP ;lpfc_sli4_dip (phba);
@@ -9282,6 +9287,7 @@ lpfc_mbox_timeout_handler(struct lpfc_hba *phba)* would get IOCB_ERROR from lpfc_sli_issue_iocb, allowing * it to fail all outstanding SCSI IO. */ +set_bit (MBX_TMO_ERR , &phba->bit_flags);spin_lock_irq (&phba->pport->work_port_lock); phba->pport->work_port_events &= ~WORKER_MBOX_TMO ;spin_unlock_irq (&phba->pport->work_port_lock);
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 10/28 media: tuners: qt1010: replace BUG_ON with a regular error
In reply to Sasha LevinFrom: Hans Verkuil <[email protected]>
[ Upstream commit ee630b29ea44d1851bb6c903f400956604834463 ]
BUG_ON is unnecessary here, and in addition it confuses smatch. Replacing this with an error return help resolve this smatch warning:
drivers/media/tuners/qt1010.c:350 qt1010_init() error: buffer overflow 'i2c_data' 34 <= 34
--- drivers/media/tuners/qt1010.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/media/tuners/qt1010.c +6 -5
@@ -345,11 +345,12 @@ static int qt1010_init(struct dvb_frontend *fe)else valptr = &tmpval; -BUG_ON (i >=ARRAY_SIZE (i2c_data) -1 ); - - err =qt1010_init_meas1 (priv, i2c_data[i+1 ].reg, - i2c_data[i].reg, - i2c_data[i].val, valptr); +if (i >=ARRAY_SIZE (i2c_data) -1 ) + err = -EIO ; +else + err =qt1010_init_meas1 (priv, i2c_data[i +1 ].reg, + i2c_data[i].reg, + i2c_data[i].val, valptr); i++;break ; }
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 11/28 media: pci: cx23885: replace BUG with error return
In reply to Sasha LevinFrom: Hans Verkuil <[email protected]>
[ Upstream commit 2e1796fd4904fdd6062a8e4589778ea899ea0c8d ]
It was completely unnecessary to use BUG in buffer_prepare(). Just replace it with an error return. This also fixes a smatch warning:
drivers/media/pci/cx23885/cx23885-video.c:422 buffer_prepare() error: uninitialized symbol 'ret'.
--- drivers/media/pci/cx23885/cx23885-video.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/pci/cx23885/cx23885-video.c +1 -1
@@ -413,7 +413,7 @@ static int buffer_prepare(struct vb2_buffer *vb) dev->height >> 1);break ;default : -BUG (); +return -EINVAL ;/* should not happen */ } dprintk(2, "[%p/%d] buffer_init - %dx%d %dbpp 0x%08x - dma=0x%08lx\n", buf, buf->vb.vb2_buf.index,
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 8/28 iio: core: Use min() instead of min_t() to make code more robust
In reply to Sasha LevinFrom: Andy Shevchenko <[email protected]>
[ Upstream commit cb1d17535061ca295903f97f5cb0af9db719c02c ]
min() has strict type checking and preferred over min_t() for unsigned types to avoid overflow. Here it's unclear why min_t() was chosen since both variables are of the same type. In any case update to use min().
--- drivers/iio/industrialio-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/industrialio-core.c +1 -1
@@ -389,7 +389,7 @@ static ssize_t iio_debugfs_write_reg(struct file *file,char buf[80 ];int ret; - count =min_t (size_t, count, (sizeof (buf)-1 )); + count =min (count,sizeof (buf) -1 );if (copy_from_user (buf, userbuf, count))return -EFAULT ;
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 15/28 tools: iio: iio_generic_buffer: Fix some integer type and calculation
In reply to Sasha LevinFrom: Chenyuan Mi <[email protected]>
[ Upstream commit 49d736313d0975ddeb156f4f59801da833f78b30 ]
In function size_from_channelarray(), the return value 'bytes' is defined as int type. However, the calcution of 'bytes' in this function is designed to use the unsigned int type. So it is necessary to change 'bytes' type to unsigned int to avoid integer overflow.
The size_from_channelarray() is called in main() function, its return value is directly multipled by 'buf_len' and then used as the malloc() parameter. The 'buf_len' is completely controllable by user, thus a multiplication overflow may occur here. This could allocate an unexpected small area.
--- tools/iio/iio_generic_buffer.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
tools/iio/iio_generic_buffer.c +13 -4
@@ -51,9 +51,9 @@ enum autochan {* Has the side effect of filling the channels[i].location values used * in processing the buffer output. **/ -static int size_from_channelarray (struct iio_channel_info *channels,int num_channels) +static unsigned int size_from_channelarray (struct iio_channel_info *channels,int num_channels) { -int bytes =0 ; +unsigned int bytes =0 ;int i =0 ;while (i < num_channels) {
@@ -348,7 +348,7 @@ int main(int argc, char **argv)ssize_t read_size;int dev_num =-1 , trig_num =-1 ;char *buffer_access =NULL ; -int scan_size; +unsigned int scan_size;int noevents =0 ;int notrigger =0 ;char *dummy;
@@ -674,7 +674,16 @@ int main(int argc, char **argv) } scan_size =size_from_channelarray (channels, num_channels); - data =malloc (scan_size * buf_len); + +size_t total_buf_len = scan_size * buf_len; + +if (scan_size >0 && total_buf_len / scan_size != buf_len) { + ret = -EFAULT ; +perror ("Integer overflow happened when calculate scan_size * buf_len" ); + goto error; + } + + data =malloc (total_buf_len);if (!data) { ret = -ENOMEM ; goto error;
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 12/28 usb: cdns3: Put the cdns set active part outside the spin lock
In reply to Sasha LevinFrom: Xiaolei Wang <[email protected]>
[ Upstream commit 2319b9c87fe243327285f2fefd7374ffd75a65fc ]
The device may be scheduled during the resume process, so this cannot appear in atomic operations. Since pm_runtime_set_active will resume suppliers, put set active outside the spin lock, which is only used to protect the struct cdns data structure, otherwise the kernel will report the following warning:
BUG: sleeping function called from invalid context at drivers/base/power/runtime.c:1163
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 651, name: sh
preempt_count: 1, expected: 0
RCU nest depth: 0, expected: 0
CPU: 0 PID: 651 Comm: sh Tainted: G WC 6.1.20 #1
Hardware name: Freescale i.MX8QM MEK (DT)
Call trace:
dump_backtrace.part.0+0xe0/0xf0
show_stack+0x18/0x30
dump_stack_lvl+0x64/0x80
dump_stack+0x1c/0x38
__might_resched+0x1fc/0x240
__might_sleep+0x68/0xc0
__pm_runtime_resume+0x9c/0xe0
rpm_get_suppliers+0x68/0x1b0
__pm_runtime_set_status+0x298/0x560
cdns_resume+0xb0/0x1c0
cdns3_controller_resume.isra.0+0x1e0/0x250
cdns3_plat_resume+0x28/0x40--- drivers/usb/cdns3/cdns3-plat.c | 3 ++- drivers/usb/cdns3/cdnsp-pci.c | 3 ++- drivers/usb/cdns3/core.c | 15 +++++++++++---- drivers/usb/cdns3/core.h | 7 +++++-- 4 files changed, 20 insertions(+), 8 deletions(-)
drivers/usb/cdns3/cdns3-plat.c +2 -1
@@ -255,9 +255,10 @@ static int cdns3_controller_resume(struct device *dev, pm_message_t msg)cdns3_set_platform_suspend (cdns->dev, false, false);spin_lock_irqsave (&cdns->lock, flags); -cdns_resume (cdns, !PMSG_IS_AUTO (msg)); +cdns_resume (cdns); cdns->in_lpm = false;spin_unlock_irqrestore (&cdns->lock, flags); +cdns_set_active (cdns, !PMSG_IS_AUTO (msg));if (cdns->wakeup_pending) { cdns->wakeup_pending = false;enable_irq (cdns->wakeup_irq);
drivers/usb/cdns3/cdnsp-pci.c +2 -1
@@ -208,8 +208,9 @@ static int __maybe_unused cdnsp_pci_resume(struct device *dev)int ret;spin_lock_irqsave (&cdns->lock, flags); - ret =cdns_resume (cdns,1 ); + ret =cdns_resume (cdns);spin_unlock_irqrestore (&cdns->lock, flags); +cdns_set_active (cdns,1 );return ret; }
drivers/usb/cdns3/core.c +11 -4
@@ -522,9 +522,8 @@ int cdns_suspend(struct cdns *cdns) }EXPORT_SYMBOL_GPL (cdns_suspend); -int cdns_resume (struct cdns *cdns,u8 set_active) +int cdns_resume (struct cdns *cdns) { -struct device *dev = cdns->dev;enum usb_role real_role;bool role_changed = false;int ret =0 ;
@@ -556,15 +555,23 @@ int cdns_resume(struct cdns *cdns, u8 set_active)if (cdns->roles[cdns->role]->resume) cdns->roles[cdns->role]->resume (cdns,cdns_power_is_lost (cdns)); + return 0; +} +EXPORT_SYMBOL_GPL (cdns_resume); + +void cdns_set_active (struct cdns *cdns,u8 set_active) +{ +struct device *dev = cdns->dev; +if (set_active) {pm_runtime_disable (dev);pm_runtime_set_active (dev);pm_runtime_enable (dev); } - return 0; +return ; } -EXPORT_SYMBOL_GPL (cdns_resume); +EXPORT_SYMBOL_GPL (cdns_set_active);#endif /* CONFIG_PM_SLEEP */ MODULE_AUTHOR ("Peter Chen <[email protected]>" );
drivers/usb/cdns3/core.h +5 -2
@@ -125,10 +125,13 @@ int cdns_init(struct cdns *cdns);int cdns_remove (struct cdns *cdns);#ifdef CONFIG_PM_SLEEP -int cdns_resume (struct cdns *cdns,u8 set_active); +int cdns_resume (struct cdns *cdns);int cdns_suspend (struct cdns *cdns); +void cdns_set_active (struct cdns *cdns,u8 set_active);#else /* CONFIG_PM_SLEEP */ -static inline int cdns_resume (struct cdns *cdns,u8 set_active) +static inline int cdns_resume (struct cdns *cdns) +{return 0 ; } +static inline int cdns_set_active (struct cdns *cdns,u8 set_active) {return 0 ; }static inline int cdns_suspend (struct cdns *cdns) {return 0 ; }
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 13/28 usb: typec: intel_pmc_mux: Add new ACPI ID for Lunar Lake IOM device
In reply to Sasha LevinFrom: Madhu M <[email protected]>
[ Upstream commit e032368e8cb15ab1f11b92f078caa9bae995b8fe ]
Intel Lunar Lake IOM has a different IOM port status offset and size than Intel MTL.
Intel Lunar Lake is the first platform to extend IOM port status from 32bit to 64bit by adding DDI port number into IOM port status.
Added IOM_PORT_STATUS_REGS macro for using platform specific IOM port status offset and size.
--- drivers/usb/typec/mux/intel_pmc_mux.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)
drivers/usb/typec/mux/intel_pmc_mux.c +20 -5
@@ -117,6 +117,16 @@ enum { IOM_PORT_STATUS_DHPD_HPD_STATUS_SHIFT) & \ IOM_PORT_STATUS_DHPD_HPD_STATUS_ASSERT) +/* IOM port status register */ +#define IOM_PORT_STATUS_REGS (_offset_, _size_) ((_offset_) | (_size_)) +#define IOM_PORT_STATUS_REGS_SZ_MASK BIT(0) +#define IOM_PORT_STATUS_REGS_SZ_4 0 +#define IOM_PORT_STATUS_REGS_SZ_8 1 +#define IOM_PORT_STATUS_REGS_OFFSET (_d_) \ + ((_d_) & ~IOM_PORT_STATUS_REGS_SZ_MASK) +#define IOM_PORT_STATUS_REGS_SIZE (_d_) \ + (4 << ((_d_) & IOM_PORT_STATUS_REGS_SZ_MASK)) +struct pmc_usb ;struct pmc_usb_port {
@@ -145,6 +155,7 @@ struct pmc_usb {struct acpi_device *iom_adev;void __iomem *iom_base;u32 iom_port_status_offset; +u8 iom_port_status_size;struct dentry *dentry; };
@@ -160,7 +171,7 @@ static void update_port_status(struct pmc_usb_port *port) port->iom_status =readl (port->pmc->iom_base + port->pmc->iom_port_status_offset + - port_num *sizeof (u32)); + port_num * port->pmc->iom_port_status_size); }static int sbu_orientation (struct pmc_usb_port *port)
@@ -589,13 +600,16 @@ static int pmc_usb_register_port(struct pmc_usb *pmc, int index,/* IOM ACPI IDs and IOM_PORT_STATUS_OFFSET */ static const struct acpi_device_id iom_acpi_ids[] = {/* TigerLake */ - {"INTC1072" ,0x560 , }, + {"INTC1072" ,IOM_PORT_STATUS_REGS (0x560 ,IOM_PORT_STATUS_REGS_SZ_4 ) },/* AlderLake */ - {"INTC1079" ,0x160 , }, + {"INTC1079" ,IOM_PORT_STATUS_REGS (0x160 ,IOM_PORT_STATUS_REGS_SZ_4 ) },/* Meteor Lake */ - {"INTC107A" ,0x160 , }, + {"INTC107A" ,IOM_PORT_STATUS_REGS (0x160 ,IOM_PORT_STATUS_REGS_SZ_4 ) }, + +/* Lunar Lake */ + {"INTC10EA" ,IOM_PORT_STATUS_REGS (0x150 ,IOM_PORT_STATUS_REGS_SZ_8 ) }, {} };
@@ -615,7 +629,8 @@ static int pmc_usb_probe_iom(struct pmc_usb *pmc)if (!adev)return -ENODEV ; - pmc->iom_port_status_offset = (u32 )dev_id->driver_data; + pmc->iom_port_status_offset =IOM_PORT_STATUS_REGS_OFFSET (dev_id->driver_data); + pmc->iom_port_status_size =IOM_PORT_STATUS_REGS_SIZE (dev_id->driver_data);INIT_LIST_HEAD (&resource_list); ret =acpi_dev_get_memory_resources (adev, &resource_list);
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 16/28 scsi: target: iscsi: Fix buffer overflow in lio_target_nacl_info_show()
In reply to Sasha LevinFrom: Konstantin Shelekhin <[email protected]>
[ Upstream commit 801f287c93ff95582b0a2d2163f12870a2f076d4 ]
The function lio_target_nacl_info_show() uses sprintf() in a loop to print details for every iSCSI connection in a session without checking for the buffer length. With enough iSCSI connections it's possible to overflow the buffer provided by configfs and corrupt the memory.
This patch replaces sprintf() with sysfs_emit_at() that checks for buffer boundries.
--- drivers/target/iscsi/iscsi_target_configfs.c | 54 ++++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-)
drivers/target/iscsi/iscsi_target_configfs.c +27 -27
@@ -533,102 +533,102 @@ static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page)spin_lock_bh (&se_nacl->nacl_sess_lock); se_sess = se_nacl->nacl_sess;if (!se_sess) { - rb +=sprintf (page+rb,"No active iSCSI Session for Initiator" + rb +=sysfs_emit_at (page, rb,"No active iSCSI Session for Initiator" " Endpoint: %s\n" , se_nacl->initiatorname); }else { sess = se_sess->fabric_sess_ptr; - rb +=sprintf (page+rb,"InitiatorName: %s\n" , + rb +=sysfs_emit_at (page, rb,"InitiatorName: %s\n" , sess->sess_ops->InitiatorName); - rb +=sprintf (page+rb,"InitiatorAlias: %s\n" , + rb +=sysfs_emit_at (page, rb,"InitiatorAlias: %s\n" , sess->sess_ops->InitiatorAlias); - rb +=sprintf (page+rb, + rb +=sysfs_emit_at (page, rb,"LIO Session ID: %u ISID: 0x%6ph TSIH: %hu " , sess->sid, sess->isid, sess->tsih); - rb +=sprintf (page+rb,"SessionType: %s\n" , + rb +=sysfs_emit_at (page, rb,"SessionType: %s\n" , (sess->sess_ops->SessionType) ?"Discovery" :"Normal" ); - rb +=sprintf (page+rb,"Session State: " ); + rb +=sysfs_emit_at (page, rb,"Session State: " );switch (sess->session_state) {case TARG_SESS_STATE_FREE : - rb +=sprintf (page+rb,"TARG_SESS_FREE\n" ); + rb +=sysfs_emit_at (page, rb,"TARG_SESS_FREE\n" );break ;case TARG_SESS_STATE_ACTIVE : - rb +=sprintf (page+rb,"TARG_SESS_STATE_ACTIVE\n" ); + rb +=sysfs_emit_at (page, rb,"TARG_SESS_STATE_ACTIVE\n" );break ;case TARG_SESS_STATE_LOGGED_IN : - rb +=sprintf (page+rb,"TARG_SESS_STATE_LOGGED_IN\n" ); + rb +=sysfs_emit_at (page, rb,"TARG_SESS_STATE_LOGGED_IN\n" );break ;case TARG_SESS_STATE_FAILED : - rb +=sprintf (page+rb,"TARG_SESS_STATE_FAILED\n" ); + rb +=sysfs_emit_at (page, rb,"TARG_SESS_STATE_FAILED\n" );break ;case TARG_SESS_STATE_IN_CONTINUE : - rb +=sprintf (page+rb,"TARG_SESS_STATE_IN_CONTINUE\n" ); + rb +=sysfs_emit_at (page, rb,"TARG_SESS_STATE_IN_CONTINUE\n" );break ;default : - rb +=sprintf (page+rb,"ERROR: Unknown Session" + rb +=sysfs_emit_at (page, rb,"ERROR: Unknown Session" " State!\n" );break ; } - rb +=sprintf (page+rb,"---------------------[iSCSI Session" + rb +=sysfs_emit_at (page, rb,"---------------------[iSCSI Session" " Values]-----------------------\n" ); - rb +=sprintf (page+rb," CmdSN/WR : CmdSN/WC : ExpCmdSN" + rb +=sysfs_emit_at (page, rb," CmdSN/WR : CmdSN/WC : ExpCmdSN" " : MaxCmdSN : ITT : TTT\n" ); max_cmd_sn = (u32 )atomic_read (&sess->max_cmd_sn); - rb +=sprintf (page+rb," 0x%08x 0x%08x 0x%08x 0x%08x" + rb +=sysfs_emit_at (page, rb," 0x%08x 0x%08x 0x%08x 0x%08x" " 0x%08x 0x%08x\n" , sess->cmdsn_window, (max_cmd_sn - sess->exp_cmd_sn) +1 , sess->exp_cmd_sn, max_cmd_sn, sess->init_task_tag, sess->targ_xfer_tag); - rb +=sprintf (page+rb,"----------------------[iSCSI" + rb +=sysfs_emit_at (page, rb,"----------------------[iSCSI" " Connections]-------------------------\n" );spin_lock (&sess->conn_lock);list_for_each_entry (conn, &sess->sess_conn_list, conn_list) { - rb +=sprintf (page+rb,"CID: %hu Connection" + rb +=sysfs_emit_at (page, rb,"CID: %hu Connection" " State: " , conn->cid);switch (conn->conn_state) {case TARG_CONN_STATE_FREE : - rb +=sprintf (page+rb, + rb +=sysfs_emit_at (page, rb,"TARG_CONN_STATE_FREE\n" );break ;case TARG_CONN_STATE_XPT_UP : - rb +=sprintf (page+rb, + rb +=sysfs_emit_at (page, rb,"TARG_CONN_STATE_XPT_UP\n" );break ;case TARG_CONN_STATE_IN_LOGIN : - rb +=sprintf (page+rb, + rb +=sysfs_emit_at (page, rb,"TARG_CONN_STATE_IN_LOGIN\n" );break ;case TARG_CONN_STATE_LOGGED_IN : - rb +=sprintf (page+rb, + rb +=sysfs_emit_at (page, rb,"TARG_CONN_STATE_LOGGED_IN\n" );break ;case TARG_CONN_STATE_IN_LOGOUT : - rb +=sprintf (page+rb, + rb +=sysfs_emit_at (page, rb,"TARG_CONN_STATE_IN_LOGOUT\n" );break ;case TARG_CONN_STATE_LOGOUT_REQUESTED : - rb +=sprintf (page+rb, + rb +=sysfs_emit_at (page, rb,"TARG_CONN_STATE_LOGOUT_REQUESTED\n" );break ;case TARG_CONN_STATE_CLEANUP_WAIT : - rb +=sprintf (page+rb, + rb +=sysfs_emit_at (page, rb,"TARG_CONN_STATE_CLEANUP_WAIT\n" );break ;default : - rb +=sprintf (page+rb, + rb +=sysfs_emit_at (page, rb,"ERROR: Unknown Connection State!\n" );break ; } - rb +=sprintf (page+rb," Address %pISc %s" , &conn->login_sockaddr, + rb +=sysfs_emit_at (page, rb," Address %pISc %s" , &conn->login_sockaddr, (conn->network_transport ==ISCSI_TCP ) ?"TCP" :"SCTP" ); - rb +=sprintf (page+rb," StatSN: 0x%08x\n" , + rb +=sysfs_emit_at (page, rb," StatSN: 0x%08x\n" , conn->stat_sn); }spin_unlock (&sess->conn_lock);
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 24/28 kobject: Add sanity check for kset->kobj.ktype in kset_register()
In reply to Sasha LevinFrom: Zhen Lei <[email protected]>
[ Upstream commit 4d0fe8c52bb3029d83e323c961221156ab98680b ]
When I register a kset in the following way:
static struct kset my_kset;
kobject_set_name(&my_kset.kobj, "my_kset");
ret = kset_register(&my_kset);A null pointer dereference exception is occurred:
[ 4453.568337] Unable to handle kernel NULL pointer dereference at \ virtual address 0000000000000028 ... ... [ 4453.810361] Call trace: [ 4453.813062] kobject_get_ownership+0xc/0x34 [ 4453.817493] kobject_add_internal+0x98/0x274 [ 4453.822005] kset_register+0x5c/0xb4 [ 4453.825820] my_kobj_init+0x44/0x1000 [my_kset]
... ...
Because I didn't initialize my_kset.kobj.ktype.
According to the description in Documentation/core-api/kobject.rst:
- A ktype is the type of object that embeds a kobject. Every structure that embeds a kobject needs a corresponding ktype.
So add sanity check to make sure kset->kobj.ktype is not NULL.
--- lib/kobject.c | 5 +++++ 1 file changed, 5 insertions(+)
lib/kobject.c +5 -0
@@ -854,6 +854,11 @@ int kset_register(struct kset *k)if (!k)return -EINVAL ; +if (!k->kobj.ktype) { +pr_err ("must have a ktype to be initialized properly!\n" ); +return -EINVAL ; + } +kset_init (k); err =kobject_add_internal (&k->kobj);if (err) {
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 26/28 usb: cdc-acm: move ldisc dcd notification outside of acm's read lock
In reply to Sasha LevinFrom: Dan Drown <[email protected]>
[ Upstream commit f72ae60881ff685004d7de7152517607fcd9968f ]
dcd_change notification call moved outside of the acm->read_lock to protect any future tty ldisc that calls wait_serial_change()
--- drivers/usb/class/cdc-acm.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/usb/class/cdc-acm.c +10 -0
@@ -318,6 +318,16 @@ static void acm_process_notification(struct acm *acm, unsigned char *buf) } difference = acm->ctrlin ^ newctrl; + +if ((difference &USB_CDC_SERIAL_STATE_DCD ) && acm->port.tty) { +struct tty_ldisc *ld =tty_ldisc_ref (acm->port.tty); +if (ld) { +if (ld->ops->dcd_change) + ld->ops->dcd_change (acm->port.tty, newctrl &USB_CDC_SERIAL_STATE_DCD ); +tty_ldisc_deref (ld); + } + } +spin_lock_irqsave (&acm->read_lock, flags); acm->ctrlin = newctrl; acm->oldcount = acm->iocount;
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 18/28 misc: open-dice: make OPEN_DICE depend on HAS_IOMEM
In reply to Sasha LevinFrom: Baoquan He <[email protected]>
[ Upstream commit aefc8b57af7787c80686e49a5841e9289cb11f53 ]
On s390 systems (aka mainframes), it has classic channel devices for networking and permanent storage that are currently even more common than PCI devices. Hence it could have a fully functional s390 kernel with CONFIG_PCI=n, then the relevant iomem mapping functions [including ioremap(), devm_ioremap(), etc.] are not available.
Here let OPEN_DICE depend on HAS_IOMEM so that it won't be built to cause below compiling error if PCI is unset:
------
ERROR: modpost: "devm_memremap" [drivers/misc/open-dice.ko] undefined!
ERROR: modpost: "devm_memunmap" [drivers/misc/open-dice.ko] undefined!
------
--- drivers/misc/Kconfig | 1 + 1 file changed, 1 insertion(+)
drivers/misc/Kconfig +1 -0
@@ -496,6 +496,7 @@ config HISI_HIKEY_USB config OPEN_DICE tristate "Open Profile for DICE driver" depends on OF_RESERVED_MEM + depends on HAS_IOMEM help This driver exposes a DICE reserved memory region to userspace via a character device. The memory region contains Compound Device
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 20/28 usb: dwc3: dwc3-octeon: Verify clock divider
In reply to Sasha LevinFrom: Ladislav Michl <[email protected]>
[ Upstream commit fb57f829beefd4b3746f1b23d51e80ed5d4bb87b ]
Although valid USB clock divider will be calculated for all valid Octeon core frequencies, make code formally correct limiting divider not to be greater that 7 so it fits into H_CLKDIV_SEL field.
--- arch/mips/cavium-octeon/octeon-usb.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
arch/mips/cavium-octeon/octeon-usb.c +6 -2
@@ -243,11 +243,11 @@ static int dwc3_octeon_get_divider(void)while (div <ARRAY_SIZE (clk_div)) {uint64_t rate =octeon_get_io_clock_rate () / clk_div[div];if (rate <=300000000 && rate >=150000000 ) -break ; +return div; div++; } -return div; +return -EINVAL ; }static int dwc3_octeon_config_power (struct device *dev,void __iomem *base)
@@ -374,6 +374,10 @@ static int dwc3_octeon_clocks_start(struct device *dev, void __iomem *base)/* Step 4b: Select controller clock frequency. */ div =dwc3_octeon_get_divider (); +if (div <0 ) { +dev_err (dev,"clock divider invalid\n" ); +return div; + } val =dwc3_octeon_readq (uctl_ctl_reg); val &= ~USBDRD_UCTL_CTL_H_CLKDIV_SEL ; val |=FIELD_PREP (USBDRD_UCTL_CTL_H_CLKDIV_SEL , div);
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 19/28 workqueue: Call wq_update_unbound_numa() on all CPUs in NUMA node on CPU hotplug
In reply to Sasha LevinFrom: Tejun Heo <[email protected]>
[ Upstream commit 4cbfd3de737b9d00544ff0f673cb75fc37bffb6a ]
When a CPU went online or offline, wq_update_unbound_numa() was called only on the CPU which was going up or down. This works fine because all CPUs on the same NUMA node share the same pool_workqueue slot - one CPU updating it updates it for everyone in the node.
However, future changes will make each CPU use a separate pool_workqueue even when they're sharing the same worker_pool, which requires updating pool_workqueue's for all CPUs which may be sharing the same pool_workqueue on hotplug.
To accommodate the planned changes, this patch updates workqueue_on/offline_cpu() so that they call wq_update_unbound_numa() for all CPUs sharing the same NUMA node as the CPU going up or down. In the current code, the second+ calls would be noops and there shouldn't be any behavior changes.
* As wq_update_unbound_numa() is now called on multiple CPUs per each hotplug event, @cpu is renamed to @hotplug_cpu and another @cpu argument is added. The former indicates the CPU being hot[un]plugged and the latter the CPU whose pool_workqueue is being updated.
* In wq_update_unbound_numa(), cpu_off is renamed to off_cpu for consistency with the new @hotplug_cpu.
--- kernel/workqueue.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-)
kernel/workqueue.c +25 -9
@@ -4448,7 +4448,8 @@ int apply_workqueue_attrs(struct workqueue_struct *wq,/** * wq_update_unbound_numa - update NUMA affinity of a wq for CPU hot[un]plug * @wq: the target workqueue -* @cpu: the CPU coming up or going down +* @cpu: the CPU to update pool association for +* @hotplug_cpu: the CPU coming up or going down * @online: whether @cpu is coming up or going down * * This function is to be called from %CPU_DOWN_PREPARE, %CPU_ONLINE and
@@ -4468,10 +4469,10 @@ int apply_workqueue_attrs(struct workqueue_struct *wq,* CPU_DOWN_PREPARE. */ static void wq_update_unbound_numa (struct workqueue_struct *wq,int cpu, -bool online) +int hotplug_cpu,bool online) {int node =cpu_to_node (cpu); -int cpu_off = online ?-1 : cpu; +int off_cpu = online ?-1 : hotplug_cpu;struct pool_workqueue *old_pwq =NULL , *pwq;struct workqueue_attrs *target_attrs;cpumask_t *cpumask;
@@ -4499,7 +4500,7 @@ static void wq_update_unbound_numa(struct workqueue_struct *wq, int cpu,* and create a new one if they don't match. If the target cpumask * equals the default pwq's, the default pwq should be used. */ -if (wq_calc_node_cpumask (wq->dfl_pwq->pool->attrs, node, cpu_off, cpumask)) { +if (wq_calc_node_cpumask (wq->dfl_pwq->pool->attrs, node, off_cpu, cpumask)) {if (cpumask_equal (cpumask, pwq->pool->attrs->cpumask))return ; }else {
@@ -5530,8 +5531,15 @@ int workqueue_online_cpu(unsigned int cpu) }/* update NUMA affinity of unbound workqueues */ -list_for_each_entry (wq, &workqueues, list) -wq_update_unbound_numa (wq, cpu, true); +list_for_each_entry (wq, &workqueues, list) { +int tcpu; + +for_each_possible_cpu (tcpu) { +if (cpu_to_node (tcpu) ==cpu_to_node (cpu)) { +wq_update_unbound_numa (wq, tcpu, cpu, true); + } + } + }mutex_unlock (&wq_pool_mutex);return 0 ;
@@ -5549,8 +5557,15 @@ int workqueue_offline_cpu(unsigned int cpu)/* update NUMA affinity of unbound workqueues */ mutex_lock (&wq_pool_mutex); -list_for_each_entry (wq, &workqueues, list) -wq_update_unbound_numa (wq, cpu, false); +list_for_each_entry (wq, &workqueues, list) { +int tcpu; + +for_each_possible_cpu (tcpu) { +if (cpu_to_node (tcpu) ==cpu_to_node (cpu)) { +wq_update_unbound_numa (wq, tcpu, cpu, false); + } + } + }mutex_unlock (&wq_pool_mutex);return 0 ;
@@ -6589,7 +6604,8 @@ void __init workqueue_init(void) }list_for_each_entry (wq, &workqueues, list) { -wq_update_unbound_numa (wq,smp_processor_id (), true); +wq_update_unbound_numa (wq,smp_processor_id (),smp_processor_id (), + true);WARN (init_rescuer (wq),"workqueue: failed to create early rescuer for %s" , wq->name);
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 23/28 media: pci: ipu3-cio2: Initialise timing struct to avoid a compiler warning
In reply to Sasha LevinFrom: Sakari Ailus <[email protected]>
[ Upstream commit 9d7531be3085a8f013cf173ccc4e72e3cf493538 ]
Initialise timing struct in cio2_hw_init() to zero in order to avoid a compiler warning. The warning was a false positive.
--- drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/pci/intel/ipu3/ipu3-cio2-main.c +1 -1
@@ -354,7 +354,7 @@ static int cio2_hw_init(struct cio2_device *cio2, struct cio2_queue *q)void __iomem *const base = cio2->base;u8 lanes, csi2bus = q->csi2.port;u8 sensor_vc =SENSOR_VIR_CH_DFLT ; -struct cio2_csi2_timing timing; +struct cio2_csi2_timing timing = {0 };int i, r; fmt =cio2_find_format (NULL , &q->subdev_fmt.code);
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 21/28 usb: ehci: add workaround for chipidea PORTSC.PEC bug
In reply to Sasha LevinFrom: Xu Yang <[email protected]>
[ Upstream commit dda4b60ed70bd670eefda081f70c0cb20bbeb1fa ]
Some NXP processor using chipidea IP has a bug when frame babble is detected.
As per 4.15.1.1.1 Serial Bus Babble:
A babble condition also exists if IN transaction is in progress at
High-speed SOF2 point. This is called frame babble. The host controller must disable the port to which the frame babble is detected.
The USB controller has disabled the port (PE cleared) and has asserted USBERRINT when frame babble is detected, but PEC is not asserted. Therefore, the SW isn't aware that port has been disabled. Then the SW keeps sending packets to this port, but all of the transfers will fail.
This workaround will firstly assert PCD by SW when USBERRINT is detected and then judge whether port change has really occurred or not by polling roothub status. Because the PEC doesn't get asserted in our case, this patch will also assert it by SW when specific conditions are satisfied.
--- drivers/usb/host/ehci-hcd.c | 8 ++++++-- drivers/usb/host/ehci-hub.c | 10 +++++++++- drivers/usb/host/ehci.h | 10 ++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-)
drivers/usb/host/ehci-hcd.c +6 -2
@@ -755,10 +755,14 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)/* normal [4.15.1.2] or error [4.15.1.1] completion */ if (likely ((status & (STS_INT |STS_ERR )) !=0 )) { -if (likely ((status &STS_ERR ) ==0 )) +if (likely ((status &STS_ERR ) ==0 )) {INCR (ehci->stats.normal); -else + }else { +/* Force to check port status */ +if (ehci->has_ci_pec_bug) + status |=STS_PCD ;INCR (ehci->stats.error); + } bh =1 ; }
drivers/usb/host/ehci-hub.c +9 -1
@@ -674,7 +674,8 @@ ehci_hub_status_data (struct usb_hcd *hcd, char *buf)if ((temp & mask) !=0 ||test_bit (i, &ehci->port_c_suspend) || (ehci->reset_done[i] &&time_after_eq ( - jiffies, ehci->reset_done[i]))) { + jiffies, ehci->reset_done[i])) + ||ehci_has_ci_pec_bug (ehci, temp)) {if (i <7 ) buf [0 ] |=1 << (i +1 );else
@@ -875,6 +876,13 @@ int ehci_hub_control(if (temp &PORT_PEC ) status |=USB_PORT_STAT_C_ENABLE <<16 ; +if (ehci_has_ci_pec_bug (ehci, temp)) { + status |=USB_PORT_STAT_C_ENABLE <<16 ; +ehci_info (ehci, +"PE is cleared by HW port:%d PORTSC:%08x\n" , + wIndex +1 , temp); + } +if ((temp &PORT_OCC ) && (!ignore_oc && !ehci->spurious_oc)){ status |=USB_PORT_STAT_C_OVERCURRENT <<16 ;
drivers/usb/host/ehci.h +10 -0
@@ -207,6 +207,7 @@ struct ehci_hcd { /* one per controller */ unsigned has_fsl_port_bug:1; /* FreeScale */ unsigned has_fsl_hs_errata:1; /* Freescale HS quirk */ unsigned has_fsl_susp_errata:1; /* NXP SUSP quirk */ + unsigned has_ci_pec_bug:1; /* ChipIdea PEC bug */ unsigned big_endian_mmio:1; unsigned big_endian_desc:1; unsigned big_endian_capbase:1;
@@ -707,6 +708,15 @@ ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)*/ #define ehci_has_fsl_susp_errata (e) ((e)->has_fsl_susp_errata) +/* +* Some Freescale/NXP processors using ChipIdea IP have a bug in which +* disabling the port (PE is cleared) does not cause PEC to be asserted +* when frame babble is detected. +*/ +#define ehci_has_ci_pec_bug (e, portsc) \ + ((e)->has_ci_pec_bug && ((e)->command & CMD_PSE) \ + && !(portsc & PORT_PEC) && !(portsc & PORT_PE)) +/* * While most USB host controllers implement their registers in * little-endian format, a minority (celleb companion chip) implement
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 25/28 interconnect: Fix locking for runpm vs reclaim
In reply to Sasha LevinFrom: Rob Clark <[email protected]>
[ Upstream commit af42269c3523492d71ebbe11fefae2653e9cdc78 ]
For cases where icc_bw_set() can be called in callbaths that could deadlock against shrinker/reclaim, such as runpm resume, we need to decouple the icc locking. Introduce a new icc_bw_lock for cases where we need to serialize bw aggregation and update to decouple that from paths that require memory allocation such as node/link creation/ destruction.
Fixes this lockdep splat:
======================================================
WARNING: possible circular locking dependency detected 6.2.0-rc8-debug+ #554 Not tainted
------------------------------------------------------
ring0/132 is trying to acquire lock:
ffffff80871916d0 (&gmu->lock){+.+.}-{3:3}, at: a6xx_pm_resume+0xf0/0x234
but task is already holding lock:
ffffffdb5aee57e8 (dma_fence_map){++++}-{0:0}, at: msm_job_run+0x68/0x150
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #4 (dma_fence_map){++++}-{0:0}:
__dma_fence_might_wait+0x74/0xc0
dma_resv_lockdep+0x1f4/0x2f4
do_one_initcall+0x104/0x2bc
kernel_init_freeable+0x344/0x34c
kernel_init+0x30/0x134
ret_from_fork+0x10/0x20-> #3 (mmu_notifier_invalidate_range_start){+.+.}-{0:0}:
fs_reclaim_acquire+0x80/0xa8
slab_pre_alloc_hook.constprop.0+0x40/0x25c
__kmem_cache_alloc_node+0x60/0x1cc
__kmalloc+0xd8/0x100
topology_parse_cpu_capacity+0x8c/0x178
get_cpu_for_node+0x88/0xc4
parse_cluster+0x1b0/0x28c
parse_cluster+0x8c/0x28c
init_cpu_topology+0x168/0x188
smp_prepare_cpus+0x24/0xf8
kernel_init_freeable+0x18c/0x34c
kernel_init+0x30/0x134
ret_from_fork+0x10/0x20-> #2 (fs_reclaim){+.+.}-{0:0}:
__fs_reclaim_acquire+0x3c/0x48
fs_reclaim_acquire+0x54/0xa8
slab_pre_alloc_hook.constprop.0+0x40/0x25c
__kmem_cache_alloc_node+0x60/0x1cc
__kmalloc+0xd8/0x100
kzalloc.constprop.0+0x14/0x20
icc_node_create_nolock+0x4c/0xc4
icc_node_create+0x38/0x58
qcom_icc_rpmh_probe+0x1b8/0x248
platform_probe+0x70/0xc4
really_probe+0x158/0x290
__driver_probe_device+0xc8/0xe0
driver_probe_device+0x44/0x100
__driver_attach+0xf8/0x108
bus_for_each_dev+0x78/0xc4
driver_attach+0x2c/0x38
bus_add_driver+0xd0/0x1d8
driver_register+0xbc/0xf8
__platform_driver_register+0x30/0x3c
qnoc_driver_init+0x24/0x30
do_one_initcall+0x104/0x2bc
kernel_init_freeable+0x344/0x34c
kernel_init+0x30/0x134
ret_from_fork+0x10/0x20-> #1 (icc_lock){+.+.}-{3:3}:
__mutex_lock+0xcc/0x3c8
mutex_lock_nested+0x30/0x44
icc_set_bw+0x88/0x2b4
_set_opp_bw+0x8c/0xd8
_set_opp+0x19c/0x300
dev_pm_opp_set_opp+0x84/0x94
a6xx_gmu_resume+0x18c/0x804
a6xx_pm_resume+0xf8/0x234
adreno_runtime_resume+0x2c/0x38
pm_generic_runtime_resume+0x30/0x44
__rpm_callback+0x15c/0x174
rpm_callback+0x78/0x7c
rpm_resume+0x318/0x524
__pm_runtime_resume+0x78/0xbc
adreno_load_gpu+0xc4/0x17c
msm_open+0x50/0x120
drm_file_alloc+0x17c/0x228
drm_open_helper+0x74/0x118
drm_open+0xa0/0x144
drm_stub_open+0xd4/0xe4
chrdev_open+0x1b8/0x1e4
do_dentry_open+0x2f8/0x38c
vfs_open+0x34/0x40
path_openat+0x64c/0x7b4
do_filp_open+0x54/0xc4
do_sys_openat2+0x9c/0x100
do_sys_open+0x50/0x7c
__arm64_sys_openat+0x28/0x34
invoke_syscall+0x8c/0x128
el0_svc_common.constprop.0+0xa0/0x11c
do_el0_svc+0xac/0xbc
el0_svc+0x48/0xa0
el0t_64_sync_handler+0xac/0x13c
el0t_64_sync+0x190/0x194-> #0 (&gmu->lock){+.+.}-{3:3}:
__lock_acquire+0xe00/0x1060
lock_acquire+0x1e0/0x2f8
__mutex_lock+0xcc/0x3c8
mutex_lock_nested+0x30/0x44
a6xx_pm_resume+0xf0/0x234
adreno_runtime_resume+0x2c/0x38
pm_generic_runtime_resume+0x30/0x44
__rpm_callback+0x15c/0x174
rpm_callback+0x78/0x7c
rpm_resume+0x318/0x524
__pm_runtime_resume+0x78/0xbc
pm_runtime_get_sync.isra.0+0x14/0x20
msm_gpu_submit+0x58/0x178
msm_job_run+0x78/0x150
drm_sched_main+0x290/0x370
kthread+0xf0/0x100
ret_from_fork+0x10/0x20other info that might help us debug this:
Chain exists of:
&gmu->lock --> mmu_notifier_invalidate_range_start --> dma_fence_map
Possible unsafe locking scenario: CPU0 CPU1
---- ----
lock(dma_fence_map);
lock(mmu_notifier_invalidate_range_start);
lock(dma_fence_map);
lock(&gmu->lock);
*** DEADLOCK ***2 locks held by ring0/132:
#0: ffffff8087191170 (&gpu->lock){+.+.}-{3:3}, at: msm_job_run+0x64/0x150
#1: ffffffdb5aee57e8 (dma_fence_map){++++}-{0:0}, at: msm_job_run+0x68/0x150 stack backtrace:
CPU: 7 PID: 132 Comm: ring0 Not tainted 6.2.0-rc8-debug+ #554
Hardware name: Google Lazor (rev1 - 2) with LTE (DT)
Call trace:
dump_backtrace.part.0+0xb4/0xf8
show_stack+0x20/0x38
dump_stack_lvl+0x9c/0xd0
dump_stack+0x18/0x34
print_circular_bug+0x1b4/0x1f0
check_noncircular+0x78/0xac
__lock_acquire+0xe00/0x1060
lock_acquire+0x1e0/0x2f8
__mutex_lock+0xcc/0x3c8
mutex_lock_nested+0x30/0x44
a6xx_pm_resume+0xf0/0x234
adreno_runtime_resume+0x2c/0x38
pm_generic_runtime_resume+0x30/0x44
__rpm_callback+0x15c/0x174
rpm_callback+0x78/0x7c
rpm_resume+0x318/0x524
__pm_runtime_resume+0x78/0xbc
pm_runtime_get_sync.isra.0+0x14/0x20
msm_gpu_submit+0x58/0x178
msm_job_run+0x78/0x150
drm_sched_main+0x290/0x370
kthread+0xf0/0x100
ret_from_fork+0x10/0x20--- drivers/interconnect/core.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/interconnect/core.c +6 -2
@@ -28,6 +28,7 @@ static LIST_HEAD(icc_providers);static int providers_count;static bool synced_state;static DEFINE_MUTEX (icc_lock); +static DEFINE_MUTEX (icc_bw_lock);static struct dentry *icc_debugfs_dir;static void icc_summary_show_one (struct seq_file *s,struct icc_node *n)
@@ -631,7 +632,7 @@ int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw)if (WARN_ON (IS_ERR (path) || !path->num_nodes))return -EINVAL ; -mutex_lock (&icc_lock); +mutex_lock (&icc_bw_lock); old_avg = path->reqs[0 ].avg_bw; old_peak = path->reqs[0 ].peak_bw;
@@ -663,7 +664,7 @@ int icc_set_bw(struct icc_path *path, u32 avg_bw, u32 peak_bw)apply_constraints (path); } -mutex_unlock (&icc_lock); +mutex_unlock (&icc_bw_lock);trace_icc_set_bw_end (path, ret);
@@ -872,6 +873,7 @@ void icc_node_add(struct icc_node *node, struct icc_provider *provider)return ;mutex_lock (&icc_lock); +mutex_lock (&icc_bw_lock); node->provider = provider;list_add_tail (&node->node_list, &provider->nodes);
@@ -900,6 +902,7 @@ void icc_node_add(struct icc_node *node, struct icc_provider *provider) node->avg_bw =0 ; node->peak_bw =0 ; +mutex_unlock (&icc_bw_lock);mutex_unlock (&icc_lock); }EXPORT_SYMBOL_GPL (icc_node_add);
@@ -1025,6 +1028,7 @@ void icc_sync_state(struct device *dev)return ;mutex_lock (&icc_lock); +mutex_lock (&icc_bw_lock); synced_state = true;list_for_each_entry (p, &icc_providers, provider_list) {dev_dbg (p->dev,"interconnect provider is in synced state\n" );
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 27/28 usb: typec: qcom-pmic-typec: register drm_bridge
In reply to Sasha LevinFrom: Dmitry Baryshkov <[email protected]>
[ Upstream commit 4b3cd783808bb327d931bbb1324d6c367443b721 ]
The current approach to handling DP on bridge-enabled platforms requires a chain of DP bridges up to the USB-C connector. Register a last DRM bridge for such chain.
--- drivers/usb/typec/tcpm/Kconfig | 1 + drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+)
drivers/usb/typec/tcpm/Kconfig +1 -0
@@ -79,6 +79,7 @@ config TYPEC_WCOVE config TYPEC_QCOM_PMIC tristate "Qualcomm PMIC USB Type-C Port Controller Manager driver" depends on ARCH_QCOM || COMPILE_TEST + depends on DRM || DRM=n help A Type-C port and Power Delivery driver which aggregates two discrete pieces of silicon in the PM8150b PMIC block: the
drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c +37 -0
@@ -17,6 +17,9 @@#include <linux/usb/role.h> #include <linux/usb/tcpm.h> #include <linux/usb/typec_mux.h> + +#include <drm/drm_bridge.h> +#include "qcom_pmic_typec_pdphy.h" #include "qcom_pmic_typec_port.h"
@@ -33,6 +36,7 @@ struct pmic_typec {struct pmic_typec_port *pmic_typec_port;bool vbus_enabled;struct mutex lock;/* VBUS state serialization */ +struct drm_bridge bridge; };#define tcpc_to_tcpm (_tcpc_) container_of(_tcpc_, struct pmic_typec, tcpc)
@@ -146,6 +150,35 @@ static int qcom_pmic_typec_init(struct tcpc_dev *tcpc)return 0 ; } +#if IS_ENABLED (CONFIG_DRM ) +static int qcom_pmic_typec_attach (struct drm_bridge *bridge, +enum drm_bridge_attach_flags flags) +{ +return flags &DRM_BRIDGE_ATTACH_NO_CONNECTOR ?0 : -EINVAL ; +} + +static const struct drm_bridge_funcs qcom_pmic_typec_bridge_funcs = { + .attach = qcom_pmic_typec_attach, +}; + +static int qcom_pmic_typec_init_drm (struct pmic_typec *tcpm) +{ + tcpm->bridge.funcs = &qcom_pmic_typec_bridge_funcs; +#ifdef CONFIG_OF + tcpm->bridge.of_node =of_get_child_by_name (tcpm->dev->of_node,"connector" ); +#endif + tcpm->bridge.ops =DRM_BRIDGE_OP_HPD ; + tcpm->bridge.type = DRM_MODE_CONNECTOR_DisplayPort; + +return devm_drm_bridge_add (tcpm->dev, &tcpm->bridge); +} +#else +static int qcom_pmic_typec_init_drm (struct pmic_typec *tcpm) +{ +return 0 ; +} +#endif +static int qcom_pmic_typec_probe (struct platform_device *pdev) {struct pmic_typec *tcpm;
@@ -208,6 +241,10 @@ static int qcom_pmic_typec_probe(struct platform_device *pdev)mutex_init (&tcpm->lock);platform_set_drvdata (pdev, tcpm); + ret =qcom_pmic_typec_init_drm (tcpm); +if (ret) +return ret; + tcpm->tcpc.fwnode =device_get_named_child_node (tcpm->dev,"connector" );if (!tcpm->tcpc.fwnode)return -EINVAL ;
Signature · 1 line
2.40.1
Sasha Levin
maintainerPATCH 17/28 serial: cpm_uart: Avoid suspicious locking
In reply to Sasha LevinFrom: Christophe Leroy <[email protected]>
[ Upstream commit 36ef11d311f405e55ad8e848c19b212ff71ef536 ]
CHECK drivers/tty/serial/cpm_uart/cpm_uart_core.cdrivers/tty/serial/cpm_uart/cpm_uart_core.c:1271:39: warning: context imbalance in 'cpm_uart_console_write' - unexpected unlock
Allthough 'nolock' is not expected to change, sparse find the following form suspicious:
if (unlikely(nolock)) {
local_irq_save(flags);
} else {
spin_lock_irqsave(&pinfo->port.lock, flags);
}
cpm_uart_early_write(pinfo, s, count, true);
if (unlikely(nolock)) {
local_irq_restore(flags);
} else {
spin_unlock_irqrestore(&pinfo->port.lock, flags);
}Rewrite it a more obvious form:
if (unlikely(oops_in_progress)) {
local_irq_save(flags);
cpm_uart_early_write(pinfo, s, count, true);
local_irq_restore(flags);
} else {
spin_lock_irqsave(&pinfo->port.lock, flags);
cpm_uart_early_write(pinfo, s, count, true);
spin_unlock_irqrestore(&pinfo->port.lock, flags);
}--- drivers/tty/serial/cpm_uart/cpm_uart_core.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/tty/serial/cpm_uart/cpm_uart_core.c +4 -9
@@ -1255,19 +1255,14 @@ static void cpm_uart_console_write(struct console *co, const char *s, {struct uart_cpm_port *pinfo = &cpm_uart_ports[co->index];unsigned long flags; -int nolock = oops_in_progress; -if (unlikely (nolock)) { +if (unlikely (oops_in_progress)) {local_irq_save (flags); - }else { -spin_lock_irqsave (&pinfo->port.lock, flags); - } - -cpm_uart_early_write (pinfo, s, count, true); - -if (unlikely (nolock)) { +cpm_uart_early_write (pinfo, s, count, true);local_irq_restore (flags); }else { +spin_lock_irqsave (&pinfo->port.lock, flags); +cpm_uart_early_write (pinfo, s, count, true);spin_unlock_irqrestore (&pinfo->port.lock, flags); } }
Signature · 1 line
2.40.1