5.4.297-rc1 review
Subsystems (5)
Greg Kroah-Hartman
maintainerPATCH 319/403 USB: storage: Add unusual-devs entry for Novatek NTK96550-based camera
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mael GUERIN <[email protected]>
commit 6ca8af3c8fb584f3424a827f554ff74f898c27cd upstream.
Add the US_FL_BULK_IGNORE_TAG quirk for Novatek NTK96550-based camera to fix USB resets after sending SCSI vendor commands due to CBW and CSW tags difference, leading to undesired slowness while communicating with the device.
Please find below the copy of /sys/kernel/debug/usb/devices with my device plugged in (listed as TechSys USB mass storage here, the underlying chipset being the Novatek NTK96550-based camera):
T: Bus=03 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 3 Spd=480 MxCh= 0 D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 P: Vendor=0603 ProdID=8611 Rev= 0.01 S: Manufacturer=TechSys S: Product=USB Mass Storage S: SerialNumber=966110000000100 C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr=100mA I:* If#= 0 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=usb-storage E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
--- drivers/usb/storage/unusual_devs.h | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/usb/storage/unusual_devs.h +7 -0
@@ -934,6 +934,13 @@ UNUSUAL_DEV( 0x05e3, 0x0723, 0x9451, 0x USB_SC_DEVICE, USB_PR_DEVICE, NULL, US_FL_SANE_SENSE ), +/* Added by Maël GUERIN <[email protected]> */ +UNUSUAL_DEV (0x0603 ,0x8611 ,0x0000 ,0xffff , +"Novatek" , +"NTK96550-based camera" , +USB_SC_SCSI ,USB_PR_BULK ,NULL , + US_FL_BULK_IGNORE_TAG ), +/* * Reported by Hanno Boeck <[email protected]> * Taken from the Lycoris Kernel
Greg Kroah-Hartman
maintainerPATCH 320/403 usb: storage: realtek_cr: Use correct byte order for bcs->Residue
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Thorsten Blum <[email protected]>
commit 98da66a70ad2396e5a508c4245367797ebc052ce upstream.
Since 'bcs->Residue' has the data type '__le32', convert it to the correct byte order of the CPU using this driver when assigning it to the local variable 'residue'.
--- drivers/usb/storage/realtek_cr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/storage/realtek_cr.c +1 -1
@@ -252,7 +252,7 @@ static int rts51x_bulk_transport(structreturn USB_STOR_TRANSPORT_ERROR ; } - residue = bcs->Residue; + residue =le32_to_cpu (bcs->Residue);if (bcs->Tag != us->tag)return USB_STOR_TRANSPORT_ERROR ;
Greg Kroah-Hartman
maintainerPATCH 321/403 USB: storage: Ignore driver CD mode for Realtek multi-mode Wi-Fi dongles
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zenm Chen <[email protected]>
commit a3dc32c635bae0ae569f489e00de0e8f015bfc25 upstream.
Many Realtek USB Wi-Fi dongles released in recent years have two modes:
one is driver CD mode which has Windows driver onboard, another one is Wi-Fi mode. Add the US_FL_IGNORE_DEVICE quirk for these multi-mode devices. Otherwise, usb_modeswitch may fail to switch them to Wi-Fi mode.
Currently there are only two USB IDs known to be used by these multi-mode Wi-Fi dongles: 0bda:1a2b and 0bda:a192.
Information about Mercury MW310UH in /sys/kernel/debug/usb/devices.
T: Bus=02 Lev=01 Prnt=01 Port=01 Cnt=01 Dev#= 12 Spd=480 MxCh= 0 D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 P: Vendor=0bda ProdID=a192 Rev= 2.00 S: Manufacturer=Realtek S: Product=DISK C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=500mA I:* If#= 0 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=(none) E: Ad=8a(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=0b(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
Information about D-Link AX9U rev. A1 in /sys/kernel/debug/usb/devices.
T: Bus=03 Lev=01 Prnt=01 Port=02 Cnt=01 Dev#= 55 Spd=480 MxCh= 0 D: Ver= 2.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1 P: Vendor=0bda ProdID=1a2b Rev= 0.00 S: Manufacturer=Realtek S: Product=DISK C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=500mA I:* If#= 0 Alt= 0 #EPs= 2 Cls=08(stor.) Sub=06 Prot=50 Driver=(none) E: Ad=84(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms E: Ad=05(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
--- drivers/usb/storage/unusual_devs.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/usb/storage/unusual_devs.h +22 -0
@@ -1490,6 +1490,28 @@ UNUSUAL_DEV( 0x0bc2, 0x3332, 0x0000, 0x9 USB_SC_DEVICE, USB_PR_DEVICE, NULL, US_FL_NO_WP_DETECT ), +/* +* Reported by Zenm Chen <[email protected]> +* Ignore driver CD mode, otherwise usb_modeswitch may fail to switch +* the device into Wi-Fi mode. +*/ +UNUSUAL_DEV (0x0bda ,0x1a2b ,0x0000 ,0xffff , +"Realtek" , +"DISK" , +USB_SC_DEVICE ,USB_PR_DEVICE ,NULL , +US_FL_IGNORE_DEVICE ), + +/* +* Reported by Zenm Chen <[email protected]> +* Ignore driver CD mode, otherwise usb_modeswitch may fail to switch +* the device into Wi-Fi mode. +*/ +UNUSUAL_DEV (0x0bda ,0xa192 ,0x0000 ,0xffff , +"Realtek" , +"DISK" , +USB_SC_DEVICE ,USB_PR_DEVICE ,NULL , +US_FL_IGNORE_DEVICE ), + UNUSUAL_DEV( 0x0d49, 0x7310, 0x0000, 0x9999, "Maxtor", "USB to SATA",
Greg Kroah-Hartman
maintainerPATCH 322/403 usb: dwc3: Ignore late xferNotReady event to prevent halt timeout
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Kuen-Han Tsai <[email protected]>
commit 58577118cc7cec9eb7c1836bf88f865ff2c5e3a3 upstream.
During a device-initiated disconnect, the End Transfer command resets the event filter, allowing a new xferNotReady event to be generated before the controller is fully halted. Processing this late event incorrectly triggers a Start Transfer, which prevents the controller from halting and results in a DSTS.DEVCTLHLT bit polling timeout.
Ignore the late xferNotReady event if the controller is already in a disconnected state.
--- drivers/usb/dwc3/gadget.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/usb/dwc3/gadget.c +9 -0
@@ -2937,6 +2937,15 @@ static void dwc3_gadget_endpoint_transfestatic void dwc3_gadget_endpoint_transfer_not_ready (struct dwc3_ep *dep,const struct dwc3_event_depevt *event) { +/* +* During a device-initiated disconnect, a late xferNotReady event can +* be generated after the End Transfer command resets the event filter, +* but before the controller is halted. Ignore it to prevent a new +* transfer from starting. +*/ +if (!dep->dwc->connected) +return ; +dwc3_gadget_endpoint_frame_from_event (dep, event); (void )__dwc3_gadget_start_isoc (dep); }
Greg Kroah-Hartman
maintainerPATCH 323/403 ARM: 9448/1: Use an absolute path to unified.h in KBUILD_AFLAGS
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nathan Chancellor <[email protected]>
commit 87c4e1459e80bf65066f864c762ef4dc932fad4b upstream.
After commit d5c8d6e0fa61 ("kbuild: Update assembler calls to use proper flags and language target"), which updated as-instr to use the 'assembler-with-cpp' language option, the Kbuild version of as-instr always fails internally for arch/arm with
<command-line>: fatal error: asm/unified.h: No such file or directory compilation terminated.
because '-include' flags are now taken into account by the compiler driver and as-instr does not have '$(LINUXINCLUDE)', so unified.h is not found.
This went unnoticed at the time of the Kbuild change because the last use of as-instr in Kbuild that arch/arm could reach was removed in 5.7 by commit 541ad0150ca4 ("arm: Remove 32bit KVM host support") but a stable backport of the Kbuild change to before that point exposed this potential issue if one were to be reintroduced.
Follow the general pattern of '-include' paths throughout the tree and make unified.h absolute using '$(srctree)' to ensure KBUILD_AFLAGS can be used independently.
--- arch/arm/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/Makefile +1 -1
@@ -136,7 +136,7 @@ endif # Need -Uarm for gcc < 3.x KBUILD_CFLAGS +=$(CFLAGS_ABI) $(CFLAGS_ISA) $(arch-y) $(tune-y) $(call cc-option,-mshort-load-bytes,$(call cc-option,-malignment-traps,)) -msoft-float -Uarm -KBUILD_AFLAGS +=$(CFLAGS_ABI) $(AFLAGS_ISA) $(arch-y) $(tune-y) -include asm/unified.h -msoft-float +KBUILD_AFLAGS +=$(CFLAGS_ABI) $(AFLAGS_ISA) $(arch-y) $(tune-y) -include $(srctree)/arch/arm/include/asm/unified.h -msoft-float CHECKFLAGS += -D__arm__
Greg Kroah-Hartman
maintainerPATCH 324/403 kbuild: Update assembler calls to use proper flags and language target
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nick Desaulniers <[email protected]>
commit d5c8d6e0fa61401a729e9eb6a9c7077b2d3aebb0 upstream.
as-instr uses KBUILD_AFLAGS, but as-option uses KBUILD_CFLAGS. This can cause as-option to fail unexpectedly when CONFIG_WERROR is set, because clang will emit -Werror,-Wunused-command-line-argument for various -m and -f flags in KBUILD_CFLAGS for assembler sources.
Callers of as-option and as-instr should be adding flags to KBUILD_AFLAGS / aflags-y, not KBUILD_CFLAGS / cflags-y. Use KBUILD_AFLAGS in all macros to clear up the initial problem.
Unfortunately, -Wunused-command-line-argument can still be triggered with clang by the presence of warning flags or macro definitions because '-x assembler' is used, instead of '-x assembler-with-cpp', which will consume these flags. Switch to '-x assembler-with-cpp' in places where '-x assembler' is used, as the compiler is always used as the driver for out of line assembler sources in the kernel.
Finally, add -Werror to these macros so that they behave consistently whether or not CONFIG_WERROR is set.
[nathan: Reworded and expanded on problems in commit message
Use '-x assembler-with-cpp' in a couple more places]
--- scripts/Kbuild.include | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
scripts/Kbuild.include +4 -4
@@ -99,16 +99,16 @@ try-run = $(shell set -e; \ fi) # as-option -# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) +# Usage: aflags-y += $(call as-option,-Wa$(comma)-isa=foo,) as-option = $(call try-run,\ - $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2)) + $(CC) -Werror $(KBUILD_AFLAGS) $(1) -c -x assembler-with-cpp /dev/null -o "$$TMP",$(1),$(2)) # as-instr -# Usage: cflags-y += $(call as-instr,instr,option1,option2) +# Usage: aflags-y += $(call as-instr,instr,option1,option2) as-instr = $(call try-run,\ - printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3)) + printf "%b\n" "$(1)" | $(CC) -Werror $(KBUILD_AFLAGS) -c -x assembler-with-cpp -o "$$TMP" -,$(2),$(3)) # __cc-option # Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)
Greg Kroah-Hartman
maintainerPATCH 325/403 mips: Include KBUILD_CPPFLAGS in CHECKFLAGS invocation
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nathan Chancellor <[email protected]>
commit 08f6554ff90ef189e6b8f0303e57005bddfdd6a7 upstream.
A future change will move CLANG_FLAGS from KBUILD_{A,C}FLAGS to KBUILD_CPPFLAGS so that '--target' is available while preprocessing. When that occurs, the following error appears when building ARCH=mips with clang (tip of tree error shown):
clang: error: unsupported option '-mabi=' for target 'x86_64-pc-linux-gnu'
Add KBUILD_CPPFLAGS in the CHECKFLAGS invocation to keep everything working after the move.
--- arch/mips/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/mips/Makefile +1 -1
@@ -319,7 +319,7 @@ KBUILD_CFLAGS += -fno-asynchronous-unwin KBUILD_LDFLAGS += -m $(ld-emul) ifdef CONFIG_MIPS -CHECKFLAGS += $(shell $(CC) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ +CHECKFLAGS += $(shell $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -dM -E -x c /dev/null | \ egrep -vw '__GNUC_(MINOR_|PATCHLEVEL_)?_' | \ sed -e "s/^\#define /-D'/" -e "s/ /'='/" -e "s/$$/'/" -e 's/\$$/&&/g') endif
Greg Kroah-Hartman
maintainerPATCH 326/403 kbuild: Add CLANG_FLAGS to as-instr
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nathan Chancellor <[email protected]>
commit cff6e7f50bd315e5b39c4e46c704ac587ceb965f upstream.
A future change will move CLANG_FLAGS from KBUILD_{A,C}FLAGS to KBUILD_CPPFLAGS so that '--target' is available while preprocessing. When that occurs, the following errors appear multiple times when building ARCH=powerpc powernv_defconfig:
ld.lld: error: vmlinux.a(arch/powerpc/kernel/head_64.o):(.text+0x12d4): relocation R_PPC64_ADDR16_HI out of range: -4611686018409717520 is not in [-2147483648, 2147483647]; references '__start___soft_mask_table' ld.lld: error: vmlinux.a(arch/powerpc/kernel/head_64.o):(.text+0x12e8): relocation R_PPC64_ADDR16_HI out of range: -4611686018409717392 is not in [-2147483648, 2147483647]; references '__stop___soft_mask_table'
Diffing the .o.cmd files reveals that -DHAVE_AS_ATHIGH=1 is not present anymore, because as-instr only uses KBUILD_AFLAGS, which will no longer contain '--target'.
Mirror Kconfig's as-instr and add CLANG_FLAGS explicitly to the invocation to ensure the target information is always present.
--- scripts/Kbuild.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Kbuild.include +1 -1
@@ -108,7 +108,7 @@ as-option = $(call try-run,\ # Usage: aflags-y += $(call as-instr,instr,option1,option2) as-instr = $(call try-run,\ - printf "%b\n" "$(1)" | $(CC) -Werror $(KBUILD_AFLAGS) -c -x assembler-with-cpp -o "$$TMP" -,$(2),$(3)) + printf "%b\n" "$(1)" | $(CC) -Werror $(CLANG_FLAGS) $(KBUILD_AFLAGS) -c -x assembler-with-cpp -o "$$TMP" -,$(2),$(3)) # __cc-option # Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)
Greg Kroah-Hartman
maintainerPATCH 327/403 kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Masahiro Yamada <[email protected]>
commit feb843a469fb0ab00d2d23cfb9bcc379791011bb upstream.
When preprocessing arch/*/kernel/vmlinux.lds.S, the target triple is not passed to $(CPP) because we add it only to KBUILD_{C,A}FLAGS.
As a result, the linker script is preprocessed with predefined macros for the build host instead of the target.
Assuming you use an x86 build machine, compare the following:
$ clang -dM -E -x c /dev/null $ clang -dM -E -x c /dev/null -target aarch64-linux-gnu
There is no actual problem presumably because our linker scripts do not rely on such predefined macros, but it is better to define correct ones.
Move $(CLANG_FLAGS) to KBUILD_CPPFLAGS, so that all *.c, *.S, *.lds.S will be processed with the proper target triple.
[Note]
After the patch submission, we got an actual problem that needs this commit. (CBL issue 1859)
--- Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Makefile +1 -2
@@ -568,8 +568,7 @@ ifneq ($(LLVM_IAS),1) CLANG_FLAGS += -no-integrated-as endif CLANG_FLAGS += -Werror=unknown-warning-option -KBUILD_CFLAGS += $(CLANG_FLAGS) -KBUILD_AFLAGS += $(CLANG_FLAGS) +KBUILD_CPPFLAGS += $(CLANG_FLAGS) export CLANG_FLAGS endif
Greg Kroah-Hartman
maintainerPATCH 328/403 kbuild: Add KBUILD_CPPFLAGS to as-option invocation
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Nathan Chancellor <[email protected]>
commit 43fc0a99906e04792786edf8534d8d58d1e9de0c upstream.
After commit feb843a469fb ("kbuild: add $(CLANG_FLAGS) to KBUILD_CPPFLAGS"), there is an error while building certain PowerPC assembly files with clang:
arch/powerpc/lib/copypage_power7.S: Assembler messages:
arch/powerpc/lib/copypage_power7.S:34: Error: junk at end of line: 0b01000' arch/powerpc/lib/copypage_power7.S:35: Error: junk at end of line: 0b01010' arch/powerpc/lib/copypage_power7.S:37: Error: junk at end of line: 0b01000' arch/powerpc/lib/copypage_power7.S:38: Error: junk at end of line: 0b01010' arch/powerpc/lib/copypage_power7.S:40: Error: junk at end of line: `0b01010'
clang: error: assembler command failed with exit code 1 (use -v to see invocation)
as-option only uses KBUILD_AFLAGS, so after removing CLANG_FLAGS from KBUILD_AFLAGS, there is no more '--target=' or '--prefix=' flags. As a result of those missing flags, the host target
will be tested during as-option calls and likely fail, meaning necessary flags may not get added when building assembly files, resulting in errors like seen above.
Add KBUILD_CPPFLAGS to as-option invocations to clear up the errors. This should have been done in commit d5c8d6e0fa61 ("kbuild: Update assembler calls to use proper flags and language target"), which switched from using the assembler target to the assembler-with-cpp target, so flags that affect preprocessing are passed along in all relevant tests. as-option now mirrors cc-option.
--- scripts/Kbuild.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/Kbuild.include +1 -1
@@ -102,7 +102,7 @@ try-run = $(shell set -e; \ # Usage: aflags-y += $(call as-option,-Wa$(comma)-isa=foo,) as-option = $(call try-run,\ - $(CC) -Werror $(KBUILD_AFLAGS) $(1) -c -x assembler-with-cpp /dev/null -o "$$TMP",$(1),$(2)) + $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(1) -c -x assembler-with-cpp /dev/null -o "$$TMP",$(1),$(2)) # as-instr # Usage: aflags-y += $(call as-instr,instr,option1,option2)
Greg Kroah-Hartman
maintainerPATCH 329/403 comedi: Fix initialization of data for instructions that write to subdevice
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Abbott <[email protected]>
[ Upstream commit 46d8c744136ce2454aa4c35c138cc06817f92b8e ]
Some Comedi subdevice instruction handlers are known to access instruction data elements beyond the first insn->n elements in some cases. The do_insn_ioctl() and do_insnlist_ioctl() functions allocate at least MIN_SAMPLES (16) data elements to deal with this, but they do not initialize all of that. For Comedi instruction codes that write to the subdevice, the first insn->n data elements are copied from user-space, but the remaining elements are left uninitialized. That could be a problem if the subdevice instruction handler reads the uninitialized data. Ensure that the first MIN_SAMPLES elements are initialized before calling these instruction handlers, filling the uncopied elements with 0. For do_insnlist_ioctl(), the same data buffer elements are used for handling a list of instructions, so ensure the first MIN_SAMPLES elements are initialized for each instruction that writes to the subdevice.
---
v2: Fixed a patch application error due to fixing up the wrong commit.
--- drivers/staging/comedi/comedi_fops.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
drivers/staging/comedi/comedi_fops.c +12 -2
@@ -1584,21 +1584,27 @@ static int do_insnlist_ioctl(struct come }for (i =0 ; i < insnlist.n_insns; ++i) { +unsigned int n = insns[i].n; +if (insns[i].insn &INSN_MASK_WRITE ) {if (copy_from_user (data, insns[i].data, - insns[i].n *sizeof (unsigned int ))) { + n *sizeof (unsigned int ))) {dev_dbg (dev->class_dev,"copy_from_user failed\n" ); ret = -EFAULT ; goto error; } +if (n <MIN_SAMPLES ) { +memset (&data[n],0 , (MIN_SAMPLES - n) * +sizeof (unsigned int )); + } } ret =parse_insn (dev, insns + i, data, file);if (ret <0 ) goto error;if (insns[i].insn &INSN_MASK_READ ) {if (copy_to_user (insns[i].data, data, - insns[i].n *sizeof (unsigned int ))) { + n *sizeof (unsigned int ))) {dev_dbg (dev->class_dev,"copy_to_user failed\n" ); ret = -EFAULT ;
@@ -1665,6 +1671,10 @@ static int do_insn_ioctl(struct comedi_d ret = -EFAULT ; goto error; } +if (insn.n <MIN_SAMPLES ) { +memset (&data[insn.n],0 , + (MIN_SAMPLES - insn.n) *sizeof (unsigned int )); + } } ret =parse_insn (dev, &insn, data, file);if (ret <0 )
Greg Kroah-Hartman
maintainerPATCH 330/403 comedi: Fail COMEDI_INSNLIST ioctl if n_insns is too large
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ian Abbott <[email protected]>
[ Upstream commit 08ae4b20f5e82101d77326ecab9089e110f224cc ]
The handling of the COMEDI_INSNLIST ioctl allocates a kernel buffer to hold the array of struct comedi_insn, getting the length from the n_insns member of the struct comedi_insnlist supplied by the user. The allocation will fail with a WARNING and a stack dump if it is too large.
Avoid that by failing with an -EINVAL error if the supplied n_insns value is unreasonable.
Define the limit on the n_insns value in the MAX_INSNS macro. Set this to the same value as MAX_SAMPLES (65536), which is the maximum allowed sum of the values of the member n in the array of struct comedi_insn, and sensible comedi instructions will have an n of at least 1.
---
v2: Fixed a build error due to applying a fixup to the wrong commit.
--- drivers/staging/comedi/comedi_compat32.c | 3 +++ drivers/staging/comedi/comedi_fops.c | 13 +++++++++++++ 2 files changed, 16 insertions(+)
drivers/staging/comedi/comedi_compat32.c +3 -0
@@ -360,6 +360,9 @@ static int compat_insnlist(struct file *if (err)return -EFAULT ; +if (n_insns >65536 )/* See MAX_INSNS in comedi_fops.c */ +return -EINVAL ; +/* Allocate user memory to copy insnlist and insns into. */ s =compat_alloc_user_space (offsetof(struct combined_insnlist , insn[n_insns]));
drivers/staging/comedi/comedi_fops.c +13 -0
@@ -1519,6 +1519,16 @@ out:return ret; } +#define MAX_INSNS 65536 +static int check_insnlist_len (struct comedi_device *dev,unsigned int n_insns) +{ +if (n_insns >MAX_INSNS ) { +dev_dbg (dev->class_dev,"insnlist length too large\n" ); +return -EINVAL ; + } +return 0 ; +} +/* * COMEDI_INSNLIST ioctl * synchronous instruction list
@@ -1551,6 +1561,9 @@ static int do_insnlist_ioctl(struct comeif (copy_from_user (&insnlist, arg,sizeof (insnlist)))return -EFAULT ; + ret =check_insnlist_len (dev, insnlist.n_insns); +if (ret) +return ret; insns =kcalloc (insnlist.n_insns,sizeof (*insns),GFP_KERNEL );if (!insns) { ret = -ENOMEM ;
Greg Kroah-Hartman
maintainerPATCH 331/403 ACPI: processor: idle: Check acpi_fetch_acpi_dev() return value
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Li Zhong <[email protected]>
commit 2437513a814b3e93bd02879740a8a06e52e2cf7d upstream.
The return value of acpi_fetch_acpi_dev() could be NULL, which would cause a NULL pointer dereference to occur in acpi_device_hid().
--- drivers/acpi/processor_idle.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/acpi/processor_idle.c +3 -1
@@ -1228,7 +1228,9 @@ static int acpi_processor_get_lpi_info(s status =acpi_get_parent (handle, &pr_ahandle);while (ACPI_SUCCESS (status)) { -acpi_bus_get_device (pr_ahandle, &d); +if (acpi_bus_get_device (pr_ahandle, &d)) +break ; + handle = pr_ahandle;if (strcmp (acpi_device_hid (d),ACPI_PROCESSOR_CONTAINER_HID ))
Greg Kroah-Hartman
maintainerPATCH 332/403 PCI/ACPI: Fix runtime PM ref imbalance on Hot-Plug Capable ports
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lukas Wunner <[email protected]>
commit 6cff20ce3b92ffbf2fc5eb9e5a030b3672aa414a upstream.
pci_bridge_d3_possible() is called from both pcie_portdrv_probe() and pcie_portdrv_remove() to determine whether runtime power management shall be enabled (on probe) or disabled (on remove) on a PCIe port.
The underlying assumption is that pci_bridge_d3_possible() always returns the same value, else a runtime PM reference imbalance would occur. That assumption is not given if the PCIe port is inaccessible on remove due to
hot-unplug: pci_bridge_d3_possible() calls pciehp_is_native(), which accesses Config Space to determine whether the port is Hot-Plug Capable. An inaccessible port returns "all ones", which is converted to "all zeroes" by pcie_capability_read_dword(). Hence the port no longer seems Hot-Plug Capable on remove even though it was on probe.
The resulting runtime PM ref imbalance causes warning messages such as:
pcieport 0000:02:04.0: Runtime PM usage count underflow!
Avoid the Config Space access (and thus the runtime PM ref imbalance) by caching the Hot-Plug Capable bit in struct pci_dev.
The struct already contains an "is_hotplug_bridge" flag, which however is not only set on Hot-Plug Capable PCIe ports, but also Conventional PCI Hot-Plug bridges and ACPI slots. The flag identifies bridges which are allocated additional MMIO and bus number resources to allow for hierarchy expansion.
The kernel is somewhat sloppily using "is_hotplug_bridge" in a number of places to identify Hot-Plug Capable PCIe ports, even though the flag encompasses other devices. Subsequent commits replace these occurrences with the new flag to clearly delineate Hot-Plug Capable PCIe ports from other kinds of hotplug bridges.
Document the existing "is_hotplug_bridge" and the new "is_pciehp" flag and document the (non-obvious) requirement that pci_bridge_d3_possible() always returns the same value across the entire lifetime of a bridge, including its hot-removal.
--- drivers/pci/pci-acpi.c | 4 +--- drivers/pci/pci.c | 8 ++++++-- drivers/pci/probe.c | 2 +- include/linux/pci.h | 1 + 4 files changed, 9 insertions(+), 6 deletions(-)
drivers/pci/pci-acpi.c +1 -3
@@ -791,13 +791,11 @@ int pci_acpi_program_hp_params(struct pcbool pciehp_is_native (struct pci_dev *bridge) {const struct pci_host_bridge *host; -u32 slot_cap;if (!IS_ENABLED (CONFIG_HOTPLUG_PCI_PCIE ))return false; -pcie_capability_read_dword (bridge,PCI_EXP_SLTCAP , &slot_cap); -if (!(slot_cap &PCI_EXP_SLTCAP_HPC )) +if (!bridge->is_pciehp)return false;if (pcie_ports_native)
drivers/pci/pci.c +6 -2
@@ -2646,8 +2646,12 @@ static const struct dmi_system_id bridge* pci_bridge_d3_possible - Is it possible to put the bridge into D3 * @bridge: Bridge to check * -* This function checks if it is possible to move the bridge to D3. -* Currently we only allow D3 for recent enough PCIe ports and Thunderbolt. +* Currently we only allow D3 for some PCIe ports and for Thunderbolt. +* +* Return: Whether it is possible to move the bridge to D3. +* +* The return value is guaranteed to be constant across the entire lifetime +* of the bridge, including its hot-removal. */ bool pci_bridge_d3_possible (struct pci_dev *bridge) {
drivers/pci/probe.c +1 -1
@@ -1479,7 +1479,7 @@ void set_pcie_hotplug_bridge(struct pci_pcie_capability_read_dword (pdev,PCI_EXP_SLTCAP , ®32);if (reg32 &PCI_EXP_SLTCAP_HPC ) - pdev->is_hotplug_bridge =1 ; + pdev->is_hotplug_bridge = pdev->is_pciehp =1 ; }static void set_pcie_thunderbolt (struct pci_dev *dev)
include/linux/pci.h +1 -0
@@ -415,6 +415,7 @@ struct pci_dev { unsigned int is_virtfn:1; unsigned int reset_fn:1; unsigned int is_hotplug_bridge:1; + unsigned int is_pciehp:1; unsigned int shpc_managed:1; /* SHPC owned by shpchp */ unsigned int is_thunderbolt:1; /* Thunderbolt controller *//*
Greg Kroah-Hartman
maintainerPATCH 333/403 net: usbnet: Avoid potential RCU stall on LINK_CHANGE event
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: John Ernberg <[email protected]>
commit 0d9cfc9b8cb17dbc29a98792d36ec39a1cf1395f upstream.
The Gemalto Cinterion PLS83-W modem (cdc_ether) is emitting confusing link up and down events when the WWAN interface is activated on the modem-side.
Interrupt URBs will in consecutive polls grab:
* Link Connected
* Link Disconnected
* Link Connected
Where the last Connected is then a stable link state.
When the system is under load this may cause the unlink_urbs() work in __handle_link_change() to not complete before the next usbnet_link_change() call turns the carrier on again, allowing rx_submit() to queue new SKBs.
In that event the URB queue is filled faster than it can drain, ending up in a RCU stall:
rcu: INFO: rcu_sched detected expedited stalls on CPUs/tasks: { 0-.... } 33108 jiffies s: 201 root: 0x1/.
rcu: blocking rcu_node structures (internal RCU debug):
Sending NMI from CPU 1 to CPUs 0:
NMI backtrace for cpu 0
Call trace:
arch_local_irq_enable+0x4/0x8
local_bh_enable+0x18/0x20
__netdev_alloc_skb+0x18c/0x1cc
rx_submit+0x68/0x1f8 [usbnet]
rx_alloc_submit+0x4c/0x74 [usbnet]
usbnet_bh+0x1d8/0x218 [usbnet]
usbnet_bh_tasklet+0x10/0x18 [usbnet]
tasklet_action_common+0xa8/0x110
tasklet_action+0x2c/0x34
handle_softirqs+0x2cc/0x3a0
__do_softirq+0x10/0x18
____do_softirq+0xc/0x14
call_on_irq_stack+0x24/0x34
do_softirq_own_stack+0x18/0x20
__irq_exit_rcu+0xa8/0xb8
irq_exit_rcu+0xc/0x30
el1_interrupt+0x34/0x48
el1h_64_irq_handler+0x14/0x1c
el1h_64_irq+0x68/0x6c
_raw_spin_unlock_irqrestore+0x38/0x48
xhci_urb_dequeue+0x1ac/0x45c [xhci_hcd]
unlink1+0xd4/0xdc [usbcore]
usb_hcd_unlink_urb+0x70/0xb0 [usbcore]
usb_unlink_urb+0x24/0x44 [usbcore]
unlink_urbs.constprop.0.isra.0+0x64/0xa8 [usbnet]
__handle_link_change+0x34/0x70 [usbnet]
usbnet_deferred_kevent+0x1c0/0x320 [usbnet]
process_scheduled_works+0x2d0/0x48c
worker_thread+0x150/0x1dc
kthread+0xd8/0xe8
ret_from_fork+0x10/0x20Get around the problem by delaying the carrier on to the scheduled work.
This needs a new flag to keep track of the necessary action.
The carrier ok check cannot be removed as it remains required for the LINK_RESET event flow.
--- drivers/net/usb/usbnet.c | 11 ++++++++--- include/linux/usb/usbnet.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-)
drivers/net/usb/usbnet.c +8 -3
@@ -1106,6 +1106,9 @@ static void __handle_link_change(struct* tx queue is stopped by netcore after link becomes off */ }else { +if (test_and_clear_bit (EVENT_LINK_CARRIER_ON , &dev->flags)) +netif_carrier_on (dev->net); +/* submitting URBs for reading packets */ tasklet_schedule (&dev->bh); }
@@ -1978,10 +1981,12 @@ EXPORT_SYMBOL(usbnet_manage_power);void usbnet_link_change (struct usbnet *dev,bool link,bool need_reset) {/* update link after link is reseted */ -if (link && !need_reset) -netif_carrier_on (dev->net); -else +if (link && !need_reset) { +set_bit (EVENT_LINK_CARRIER_ON , &dev->flags); + }else { +clear_bit (EVENT_LINK_CARRIER_ON , &dev->flags);netif_carrier_off (dev->net); + }if (need_reset && link)usbnet_defer_kevent (dev,EVENT_LINK_RESET );
include/linux/usb/usbnet.h +1 -0
@@ -83,6 +83,7 @@ struct usbnet {# define EVENT_LINK_CHANGE 11# define EVENT_SET_RX_MODE 12# define EVENT_NO_IP_ALIGN 13 +# define EVENT_LINK_CARRIER_ON 14u32 rx_speed;/* in bps - NOT Mbps */ u32 tx_speed;/* in bps - NOT Mbps */ };
Greg Kroah-Hartman
maintainerPATCH 334/403 net: usbnet: Fix the wrong netif_carrier_on() call
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ammar Faizi <[email protected]>
commit 8466d393700f9ccef68134d3349f4e0a087679b9 upstream.
The commit referenced in the Fixes tag causes usbnet to malfunction (identified via git bisect). Post-commit, my external RJ45 LAN cable fails to connect. Linus also reported the same issue after pulling that commit.
The code has a logic error: netif_carrier_on() is only called when the link is already on. Fix this by moving the netif_carrier_on() call outside the if-statement entirely. This ensures it is always called when EVENT_LINK_CARRIER_ON is set and properly clears it regardless of the link state.
--- drivers/net/usb/usbnet.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/net/usb/usbnet.c +3 -3
@@ -1097,6 +1097,9 @@ static void __handle_link_change(structif (!test_bit (EVENT_DEV_OPEN , &dev->flags))return ; +if (test_and_clear_bit (EVENT_LINK_CARRIER_ON , &dev->flags)) +netif_carrier_on (dev->net); +if (!netif_carrier_ok (dev->net)) {/* kill URBs for reading packets to save bus bandwidth */ unlink_urbs (dev, &dev->rxq);
@@ -1106,9 +1109,6 @@ static void __handle_link_change(struct* tx queue is stopped by netcore after link becomes off */ }else { -if (test_and_clear_bit (EVENT_LINK_CARRIER_ON , &dev->flags)) -netif_carrier_on (dev->net); -/* submitting URBs for reading packets */ tasklet_schedule (&dev->bh); }
Greg Kroah-Hartman
maintainerPATCH 335/403 ice: Fix a null pointer dereference in ice_copy_and_init_pkg()
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Haoxiang Li <[email protected]>
[ Upstream commit 4ff12d82dac119b4b99b5a78b5af3bf2474c0a36 ]
Add check for the return value of devm_kmemdup()
to prevent potential null pointer dereference.
--- drivers/net/ethernet/intel/ice/ice_flex_pipe.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/intel/ice/ice_flex_pipe.c +2 -0
@@ -753,6 +753,8 @@ enum ice_status ice_copy_and_init_pkg(streturn ICE_ERR_PARAM ; buf_copy =devm_kmemdup (ice_hw_to_dev (hw), buf, len,GFP_KERNEL ); +if (!buf_copy) +return ICE_ERR_NO_MEMORY ; status =ice_init_pkg (hw, buf_copy, len);if (status) {
Greg Kroah-Hartman
maintainerPATCH 336/403 drm/sched: Remove optimization that causes hang when killing dependent jobs
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Lin.Cao" <[email protected]>
[ Upstream commit 15f77764e90a713ee3916ca424757688e4f565b9 ]
When application A submits jobs and application B submits a job with a dependency on A's fence, the normal flow wakes up the scheduler after processing each job. However, the optimization in drm_sched_entity_add_dependency_cb() uses a callback that only clears dependencies without waking up the scheduler.
When application A is killed before its jobs can run, the callback gets triggered but only clears the dependency without waking up the scheduler, causing the scheduler to enter sleep state and application B to hang.
Remove the optimization by deleting drm_sched_entity_clear_dep() and its usage, ensuring the scheduler is always woken up when dependencies are cleared.
--- drivers/gpu/drm/scheduler/sched_entity.c | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-)
drivers/gpu/drm/scheduler/sched_entity.c +2 -21
@@ -328,19 +328,6 @@ void drm_sched_entity_destroy(struct drmEXPORT_SYMBOL (drm_sched_entity_destroy);/** -* drm_sched_entity_clear_dep - callback to clear the entities dependency -*/ -static void drm_sched_entity_clear_dep (struct dma_fence *f, -struct dma_fence_cb *cb) -{ -struct drm_sched_entity *entity = - container_of(cb, struct drm_sched_entity, cb); - - entity->dependency =NULL ; -dma_fence_put (f); -} - -/** * drm_sched_entity_clear_dep - callback to clear the entities dependency and * wake up scheduler */
@@ -350,7 +337,8 @@ static void drm_sched_entity_wakeup(strustruct drm_sched_entity *entity = container_of(cb, struct drm_sched_entity, cb); -drm_sched_entity_clear_dep (f, cb); + entity->dependency =NULL ; +dma_fence_put (f);drm_sched_wakeup (entity->rq->sched); }
@@ -426,13 +414,6 @@ static bool drm_sched_entity_add_depende fence =dma_fence_get (&s_fence->scheduled);dma_fence_put (entity->dependency); entity->dependency = fence; -if (!dma_fence_add_callback (fence, &entity->cb, - drm_sched_entity_clear_dep)) -return true; - -/* Ignore it when it is already scheduled */ -dma_fence_put (fence); -return false; } if (!dma_fence_add_callback(entity->dependency, &entity->cb,
Greg Kroah-Hartman
maintainerPATCH 337/403 mm/zsmalloc.c: convert to use kmem_cache_zalloc in cache_alloc_zspage()
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Miaohe Lin <[email protected]>
[ Upstream commit f0231305acd53375c6cf736971bf5711105dd6bb ]
We always memset the zspage allocated via cache_alloc_zspage. So it's more convenient to use kmem_cache_zalloc in cache_alloc_zspage than caller do it manually.
Stable-dep-of: 694d6b99923e ("mm/zsmalloc: do not pass __GFP_MOVABLE if CONFIG_COMPACTION=n")
--- mm/zsmalloc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
mm/zsmalloc.c +1 -2
@@ -357,7 +357,7 @@ static void cache_free_handle(struct zs_static struct zspage *cache_alloc_zspage (struct zs_pool *pool,gfp_t flags) { -return kmem_cache_alloc (pool->zspage_cachep, +return kmem_cache_zalloc (pool->zspage_cachep, flags & ~(__GFP_HIGHMEM|__GFP_MOVABLE)); }
@@ -1067,7 +1067,6 @@ static struct zspage *alloc_zspage(strucif (!zspage)return NULL ; -memset (zspage,0 ,sizeof (struct zspage )); zspage->magic =ZSPAGE_MAGIC ;migrate_lock_init (zspage);
Greg Kroah-Hartman
maintainerPATCH 338/403 mm/zsmalloc: do not pass __GFP_MOVABLE if CONFIG_COMPACTION=n
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Harry Yoo <[email protected]>
[ Upstream commit 694d6b99923eb05a8fd188be44e26077d19f0e21 ]
Commit 48b4800a1c6a ("zsmalloc: page migration support") added support for migrating zsmalloc pages using the movable_operations migration framework. However, the commit did not take into account that zsmalloc supports migration only when CONFIG_COMPACTION is enabled. Tracing shows that zsmalloc was still passing the __GFP_MOVABLE flag even when compaction is not supported.
This can result in unmovable pages being allocated from movable page blocks (even without stealing page blocks), ZONE_MOVABLE and CMA area.
Possible user visible effects:
- Some ZONE_MOVABLE memory can be not actually movable
- CMA allocation can fail because of this
- Increased memory fragmentation due to ignoring the page mobility grouping feature
I'm not really sure who uses kernels without compaction support, though :(
To fix this, clear the __GFP_MOVABLE flag when
!IS_ENABLED(CONFIG_COMPACTION).
--- mm/zsmalloc.c | 3 +++ 1 file changed, 3 insertions(+)
mm/zsmalloc.c +3 -0
@@ -1067,6 +1067,9 @@ static struct zspage *alloc_zspage(strucif (!zspage)return NULL ; +if (!IS_ENABLED (CONFIG_COMPACTION )) + gfp &= ~__GFP_MOVABLE; + zspage->magic =ZSPAGE_MAGIC ;migrate_lock_init (zspage);
Greg Kroah-Hartman
maintainerPATCH 339/403 f2fs: fix to do sanity check on ino and xnid
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit 061cf3a84bde038708eb0f1d065b31b7c2456533 ]
syzbot reported a f2fs bug as below:
INFO: task syz-executor140:5308 blocked for more than 143 seconds.
Not tainted 6.14.0-rc7-syzkaller-00069-g81e4f8d68c66 #0
"echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
task:syz-executor140 state:D stack:24016 pid:5308 tgid:5308 ppid:5306 task_flags:0x400140 flags:0x00000006
Call Trace:
<TASK>
context_switch kernel/sched/core.c:5378 [inline]
__schedule+0x190e/0x4c90 kernel/sched/core.c:6765
__schedule_loop kernel/sched/core.c:6842 [inline]
schedule+0x14b/0x320 kernel/sched/core.c:6857
io_schedule+0x8d/0x110 kernel/sched/core.c:7690
folio_wait_bit_common+0x839/0xee0 mm/filemap.c:1317
__folio_lock mm/filemap.c:1664 [inline]
folio_lock include/linux/pagemap.h:1163 [inline]
__filemap_get_folio+0x147/0xb40 mm/filemap.c:1917
pagecache_get_page+0x2c/0x130 mm/folio-compat.c:87
find_get_page_flags include/linux/pagemap.h:842 [inline]
f2fs_grab_cache_page+0x2b/0x320 fs/f2fs/f2fs.h:2776
__get_node_page+0x131/0x11b0 fs/f2fs/node.c:1463
read_xattr_block+0xfb/0x190 fs/f2fs/xattr.c:306
lookup_all_xattrs fs/f2fs/xattr.c:355 [inline]
f2fs_getxattr+0x676/0xf70 fs/f2fs/xattr.c:533
__f2fs_get_acl+0x52/0x870 fs/f2fs/acl.c:179
f2fs_acl_create fs/f2fs/acl.c:375 [inline]
f2fs_init_acl+0xd7/0x9b0 fs/f2fs/acl.c:418
f2fs_init_inode_metadata+0xa0f/0x1050 fs/f2fs/dir.c:539
f2fs_add_inline_entry+0x448/0x860 fs/f2fs/inline.c:666
f2fs_add_dentry+0xba/0x1e0 fs/f2fs/dir.c:765
f2fs_do_add_link+0x28c/0x3a0 fs/f2fs/dir.c:808
f2fs_add_link fs/f2fs/f2fs.h:3616 [inline]
f2fs_mknod+0x2e8/0x5b0 fs/f2fs/namei.c:766
vfs_mknod+0x36d/0x3b0 fs/namei.c:4191
unix_bind_bsd net/unix/af_unix.c:1286 [inline]
unix_bind+0x563/0xe30 net/unix/af_unix.c:1379
__sys_bind_socket net/socket.c:1817 [inline]
__sys_bind+0x1e4/0x290 net/socket.c:1848
__do_sys_bind net/socket.c:1853 [inline]
__se_sys_bind net/socket.c:1851 [inline]
__x64_sys_bind+0x7a/0x90 net/socket.c:1851
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xf3/0x230 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x77/0x7fLet's dump and check metadata of corrupted inode, it shows its xattr_nid is the same to its i_ino.
dump.f2fs -i 3 chaseyu.img.rawi_xattr_nid [0x 3 : 3]
So that, during mknod in the corrupted directory, it tries to get and lock inode page twice, result in deadlock.
- f2fs_mknod
- f2fs_add_inline_entry
- f2fs_get_inode_page --- lock dir's inode page
- f2fs_init_acl
- f2fs_acl_create(dir,..)
- __f2fs_get_acl
- f2fs_getxattr
- lookup_all_xattrs
- __get_node_page --- try to lock dir's inode page
In order to fix this, let's add sanity check on ino and xnid.
--- fs/f2fs/inode.c | 7 +++++++ 1 file changed, 7 insertions(+)
fs/f2fs/inode.c +7 -0
@@ -221,6 +221,13 @@ static bool sanity_check_inode(struct inreturn false; } +if (ino_of_node (node_page) == fi->i_xattr_nid) { +set_sbi_flag (sbi,SBI_NEED_FSCK ); +f2fs_warn (sbi,"%s: corrupted inode i_ino=%lx, xnid=%x, run fsck to fix." , + __func__, inode->i_ino, fi->i_xattr_nid); +return false; + } +if (f2fs_sb_has_flexible_inline_xattr (sbi) && !f2fs_has_extra_attr (inode)) {set_sbi_flag (sbi,SBI_NEED_FSCK );
Greg Kroah-Hartman
maintainerPATCH 340/403 iio: hid-sensor-prox: Fix incorrect OFFSET calculation
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Lixu <[email protected]>
[ Upstream commit 79dabbd505210e41c88060806c92c052496dd61c ]
The OFFSET calculation in the prox_read_raw() was incorrectly using the unit exponent, which is intended for SCALE calculations.
Remove the incorrect OFFSET calculation and set it to a fixed value of 0.
--- drivers/iio/light/hid-sensor-prox.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iio/light/hid-sensor-prox.c +1 -2
@@ -103,8 +103,7 @@ static int prox_read_raw(struct iio_dev ret_type = prox_state->scale_precision;break ;case IIO_CHAN_INFO_OFFSET : - *val =hid_sensor_convert_exponent ( - prox_state->prox_attr.unit_expo); + *val =0 ; ret_type =IIO_VAL_INT ;break ;case IIO_CHAN_INFO_SAMP_FREQ :
Greg Kroah-Hartman
maintainerPATCH 341/403 x86/mce/amd: Add default names for MCA banks and blocks
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yazen Ghannam <[email protected]>
[ Upstream commit d66e1e90b16055d2f0ee76e5384e3f119c3c2773 ]
Ensure that sysfs init doesn't fail for new/unrecognized bank types or if a bank has additional blocks available.
Most MCA banks have a single thresholding block, so the block takes the same name as the bank.
Unified Memory Controllers (UMCs) are a special case where there are two blocks and each has a unique name.
However, the microarchitecture allows for five blocks. Any new MCA bank types with more than one block will be missing names for the extra blocks. The MCE sysfs will fail to initialize in this case.
--- arch/x86/kernel/cpu/mce/amd.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
arch/x86/kernel/cpu/mce/amd.c +10 -3
@@ -1180,13 +1180,20 @@ static const char *get_name(unsigned int } bank_type =smca_get_bank_type (bank); -if (bank_type >=N_SMCA_BANK_TYPES ) -return NULL ;if (b && bank_type ==SMCA_UMC ) {if (b->block <ARRAY_SIZE (smca_umc_block_names))return smca_umc_block_names[b->block]; -return NULL ; + } + +if (b && b->block) { +snprintf (buf_mcatype,MAX_MCATYPE_NAME_LEN ,"th_block_%u" , b->block); +return buf_mcatype; + } + +if (bank_type >=N_SMCA_BANK_TYPES ) { +snprintf (buf_mcatype,MAX_MCATYPE_NAME_LEN ,"th_bank_%u" , bank); +return buf_mcatype; }if (smca_banks[bank].hwid->count ==1 )
Greg Kroah-Hartman
maintainerPATCH 342/403 usb: hub: avoid warm port reset during USB3 disconnect
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mathias Nyman <[email protected]>
[ Upstream commit f59f93cd1d720809466c7fd5aa16a236156c672b ]
During disconnect USB-3 ports often go via SS.Inactive link error state before the missing terminations are noticed, and link finally goes to RxDetect state
Avoid immediately warm-resetting ports in SS.Inactive state. Let ports settle for a while and re-read the link status a few times 20ms apart to see if the ports transitions out of SS.Inactive.
According to USB 3.x spec 7.5.2, a port in SS.Inactive should automatically check for missing far-end receiver termination every 12 ms (SSInactiveQuietTimeout)
The futile multiple warm reset retries of a disconnected device takes a lot of time, also the resetting of a removed devices has caused cases where the reset bit got stuck for a long time on xHCI roothub. This lead to issues in detecting new devices connected to the same port shortly after.
Stable-dep-of: 2521106fc732 ("usb: hub: Don't try to recover devices lost during warm reset.")
--- drivers/usb/core/hub.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-)
drivers/usb/core/hub.c +20 -6
@@ -2788,6 +2788,8 @@ static unsigned hub_is_wusb(struct usb_h#define SET_CONFIG_TRIES (2 * (use_both_schemes + 1))#define USE_NEW_SCHEME (i, scheme) ((i) / 2 == (int)(scheme)) +#define DETECT_DISCONNECT_TRIES 5 +#define HUB_ROOT_RESET_TIME 60/* times are in msec */ #define HUB_SHORT_RESET_TIME 10#define HUB_BH_RESET_TIME 50
@@ -5422,6 +5424,7 @@ static void port_event(struct usb_hub *hstruct usb_device *udev = port_dev->child;struct usb_device *hdev = hub->hdev;u16 portstatus, portchange; +int i =0 ; connect_change =test_bit (port1, hub->change_bits);clear_bit (port1, hub->event_bits);
@@ -5498,17 +5501,27 @@ static void port_event(struct usb_hub *h connect_change =1 ;/* -* Warm reset a USB3 protocol port if it's in -* SS.Inactive state. -*/ -if (hub_port_warm_reset_required (hub, port1, portstatus)) { -dev_dbg (&port_dev->dev,"do warm reset\n" ); -if (!udev || !(portstatus &USB_PORT_STAT_CONNECTION ) +* Avoid trying to recover a USB3 SS.Inactive port with a warm reset if +* the device was disconnected. A 12ms disconnect detect timer in +* SS.Inactive state transitions the port to RxDetect automatically. +* SS.Inactive link error state is common during device disconnect. +*/ +while (hub_port_warm_reset_required (hub, port1, portstatus)) { +if ((i++ <DETECT_DISCONNECT_TRIES ) && udev) { +u16 unused; + +msleep (20 ); +hub_port_status (hub, port1, &portstatus, &unused); +dev_dbg (&port_dev->dev,"Wait for inactive link disconnect detect\n" ); +continue ; + }else if (!udev || !(portstatus &USB_PORT_STAT_CONNECTION ) || udev->state ==USB_STATE_NOTATTACHED ) { +dev_dbg (&port_dev->dev,"do warm reset, port only\n" );if (hub_port_reset (hub, port1,NULL ,HUB_BH_RESET_TIME , true) <0 )hub_port_disable (hub, port1,1 ); }else { +dev_dbg (&port_dev->dev,"do warm reset, full device\n" );usb_unlock_port (port_dev);usb_lock_device (udev);usb_reset_device (udev);
@@ -5516,6 +5529,7 @@ static void port_event(struct usb_hub *husb_lock_port (port_dev); connect_change =0 ; } +break ; }if (connect_change)
Greg Kroah-Hartman
maintainerPATCH 343/403 usb: hub: Dont try to recover devices lost during warm reset.
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Mathias Nyman <[email protected]>
[ Upstream commit 2521106fc732b0b75fd3555c689b1ed1d29d273c ]
Hub driver warm-resets ports in SS.Inactive or Compliance mode to recover a possible connected device. The port reset code correctly detects if a connection is lost during reset, but hub driver port_event() fails to take this into account in some cases. port_event() ends up using stale values and assumes there is a connected device, and will try all means to recover it, including power-cycling the port.
Details:
This case was triggered when xHC host was suspended with DbC (Debug Capability) enabled and connected. DbC turns one xHC port into a simple usb debug device, allowing debugging a system with an A-to-A USB debug cable.
xhci DbC code disables DbC when xHC is system suspended to D3, and enables it back during resume.
We essentially end up with two hosts connected to each other during suspend, and, for a short while during resume, until DbC is enabled back. The suspended xHC host notices some activity on the roothub port, but can't train the link due to being suspended, so xHC hardware sets a CAS (Cold Attach Status) flag for this port to inform xhci host driver that the port needs to be warm reset once xHC resumes.
CAS is xHCI specific, and not part of USB specification, so xhci driver tells usb core that the port has a connection and link is in compliance mode. Recovery from complinace mode is similar to CAS recovery.
xhci CAS driver support that fakes a compliance mode connection was added in commit 8bea2bd37df0 ("usb: Add support for root hub port status CAS")
Once xHCI resumes and DbC is enabled back, all activity on the xHC roothub host side port disappears. The hub driver will anyway think port has a connection and link is in compliance mode, and hub driver will try to recover it.
The port power-cycle during recovery seems to cause issues to the active DbC connection.
Fix this by clearing connect_change flag if hub_port_reset() returns -ENOTCONN, thus avoiding the whole unnecessary port recovery and initialization attempt.
--- drivers/usb/core/hub.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/usb/core/hub.c +6 -2
@@ -5425,6 +5425,7 @@ static void port_event(struct usb_hub *hstruct usb_device *hdev = hub->hdev;u16 portstatus, portchange;int i =0 ; +int err; connect_change =test_bit (port1, hub->change_bits);clear_bit (port1, hub->event_bits);
@@ -5517,8 +5518,11 @@ static void port_event(struct usb_hub *h }else if (!udev || !(portstatus &USB_PORT_STAT_CONNECTION ) || udev->state ==USB_STATE_NOTATTACHED ) {dev_dbg (&port_dev->dev,"do warm reset, port only\n" ); -if (hub_port_reset (hub, port1,NULL , -HUB_BH_RESET_TIME , true) <0 ) + err =hub_port_reset (hub, port1,NULL , +HUB_BH_RESET_TIME , true); +if (!udev && err == -ENOTCONN ) + connect_change =0 ; +else if (err <0 )hub_port_disable (hub, port1,1 ); }else {dev_dbg (&port_dev->dev,"do warm reset, full device\n" );
Greg Kroah-Hartman
maintainerPATCH 344/403 tracing: Add down_write(trace_event_sem) when adding trace event
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steven Rostedt <[email protected]>
[ Upstream commit b5e8acc14dcb314a9b61ff19dcd9fdd0d88f70df ]
When a module is loaded, it adds trace events defined by the module. It may also need to modify the modules trace printk formats to replace enum names with their values.
If two modules are loaded at the same time, the adding of the event to the ftrace_events list can corrupt the walking of the list in the code that is modifying the printk format strings and crash the kernel.
The addition of the event should take the trace_event_sem for write while it adds the new event.
Also add a lockdep_assert_held() on that semaphore in __trace_add_event_dirs() as it iterates the list.
--- kernel/trace/trace_events.c | 5 +++++ 1 file changed, 5 insertions(+)
kernel/trace/trace_events.c +5 -0
@@ -2109,7 +2109,10 @@ __register_event(struct trace_event_callif (ret <0 )return ret; +down_write (&trace_event_sem);list_add (&call->list, &ftrace_events); +up_write (&trace_event_sem); + call->mod = mod;return 0 ;
@@ -2489,6 +2492,8 @@ __trace_add_event_dirs(struct trace_arrastruct trace_event_call *call;int ret; +lockdep_assert_held (&trace_event_sem); +list_for_each_entry (call, &ftrace_events, list) { ret =__trace_add_new_event (call, tr);if (ret <0 )
Greg Kroah-Hartman
maintainerPATCH 345/403 pmdomain: governor: Consider CPU latency tolerance from pm_domain_cpu_gov
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Maulik Shah <[email protected]>
[ Upstream commit 500ba33284416255b9a5b50ace24470b6fe77ea5 ]
pm_domain_cpu_gov is selecting a cluster idle state but does not consider latency tolerance of child CPUs. This results in deeper cluster idle state whose latency does not meet latency tolerance requirement.
Select deeper idle state only if global and device latency tolerance of all child CPUs meet.
Test results on SM8750 with 300 usec PM-QoS on CPU0 which is less than domain idle state entry (2150) + exit (1983) usec latency mentioned in devicetree, demonstrate the issue.
# echo 300 > /sys/devices/system/cpu/cpu0/power/pm_qos_resume_latency_us
Before: (Usage is incrementing)
======
# cat /sys/kernel/debug/pm_genpd/power-domain-cluster0/idle_states State Time Spent(ms) Usage Rejected Above Below S0 29817 537 8 270 0
# cat /sys/kernel/debug/pm_genpd/power-domain-cluster0/idle_states State Time Spent(ms) Usage Rejected Above Below S0 30348 542 8 271 0
After: (Usage is not incrementing due to latency tolerance)
======
# cat /sys/kernel/debug/pm_genpd/power-domain-cluster0/idle_states State Time Spent(ms) Usage Rejected Above Below S0 39319 626 14 307 0
# cat /sys/kernel/debug/pm_genpd/power-domain-cluster0/idle_states State Time Spent(ms) Usage Rejected Above Below S0 39319 626 14 307 0
--- drivers/base/power/domain_governor.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/base/power/domain_governor.c +16 -2
@@ -8,6 +8,7 @@#include <linux/pm_domain.h> #include <linux/pm_qos.h> #include <linux/hrtimer.h> +#include <linux/cpu.h> #include <linux/cpuidle.h> #include <linux/cpumask.h> #include <linux/ktime.h>
@@ -254,6 +255,8 @@ static bool cpu_power_down_ok(struct devstruct generic_pm_domain *genpd =pd_to_genpd (pd);struct cpuidle_device *dev;ktime_t domain_wakeup, next_hrtimer; +struct device *cpu_dev; +s64 cpu_constraint, global_constraint;s64 idle_duration_ns;int cpu, i;
@@ -264,6 +267,7 @@ static bool cpu_power_down_ok(struct devif (!(genpd->flags &GENPD_FLAG_CPU_DOMAIN ))return true; + global_constraint =pm_qos_request (PM_QOS_CPU_DMA_LATENCY );/* * Find the next wakeup for any of the online CPUs within the PM domain * and its subdomains. Note, we only need the genpd->cpus, as it already
@@ -277,8 +281,16 @@ static bool cpu_power_down_ok(struct devif (ktime_before (next_hrtimer, domain_wakeup)) domain_wakeup = next_hrtimer; } + + cpu_dev =get_cpu_device (cpu); +if (cpu_dev) { + cpu_constraint =dev_pm_qos_raw_resume_latency (cpu_dev); +if (cpu_constraint < global_constraint) + global_constraint = cpu_constraint; + } } + global_constraint *=NSEC_PER_USEC ;/* The minimum idle duration is from now - until the next wakeup. */ idle_duration_ns =ktime_to_ns (ktime_sub (domain_wakeup,ktime_get ()));if (idle_duration_ns <=0 )
@@ -291,8 +303,10 @@ static bool cpu_power_down_ok(struct dev*/ i = genpd->state_idx; do { - if (idle_duration_ns >= (genpd->states[i].residency_ns + - genpd->states[i].power_off_latency_ns)) { + if ((idle_duration_ns >= (genpd->states[i].residency_ns + + genpd->states[i].power_off_latency_ns)) && + (global_constraint >= (genpd->states[i].power_on_latency_ns + + genpd->states[i].power_off_latency_ns))) { genpd->state_idx = i; return true; }
Greg Kroah-Hartman
maintainerPATCH 346/403 nfsd: handle get_client_locked() failure in nfsd4_setclientid_confirm()
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jeff Layton <[email protected]>
[ Upstream commit 908e4ead7f757504d8b345452730636e298cbf68 ]
Lei Lu recently reported that nfsd4_setclientid_confirm() did not check the return value from get_client_locked(). a SETCLIENTID_CONFIRM could race with a confirmed client expiring and fail to get a reference. That could later lead to a UAF.
Fix this by getting a reference early in the case where there is an extant confirmed client. If that fails then treat it as if there were no confirmed client found at all.
In the case where the unconfirmed client is expiring, just fail and return the result from get_client_locked().
--- fs/nfsd/nfs4state.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
fs/nfsd/nfs4state.c +15 -5
@@ -3956,10 +3956,16 @@ nfsd4_setclientid_confirm(struct svc_rqs } status = nfs_ok;if (conf) {/* case 1: callback update */ - old = unconf; -unhash_client_locked (old); -nfsd4_change_callback (conf, &unconf->cl_cb_conn); - }else {/* case 3: normal case; new or rebooted client */ +if (get_client_locked (conf) == nfs_ok) { + old = unconf; +unhash_client_locked (old); +nfsd4_change_callback (conf, &unconf->cl_cb_conn); + }else { + conf =NULL ; + } + } + +if (!conf) {/* case 3: normal case; new or rebooted client */ old =find_confirmed_client_by_name (&unconf->cl_name, nn);if (old) { status = nfserr_clid_inuse;
@@ -3975,10 +3981,14 @@ nfsd4_setclientid_confirm(struct svc_rqs goto out; } } + status =get_client_locked (unconf); +if (status != nfs_ok) { + old =NULL ; + goto out; + }move_to_confirmed (unconf); conf = unconf; } -get_client_locked (conf);spin_unlock (&nn->client_lock);nfsd4_probe_callback (conf);spin_lock (&nn->client_lock);
Greg Kroah-Hartman
maintainerPATCH 347/403 mm/hmm: move pmd_to_hmm_pfn_flags() to the respective #ifdeffery
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Andy Shevchenko <[email protected]>
[ Upstream commit 188cb385bbf04d486df3e52f28c47b3961f5f0c0 ]
When pmd_to_hmm_pfn_flags() is unused, it prevents kernel builds with clang, make W=1 and CONFIG_TRANSPARENT_HUGEPAGE=n:
mm/hmm.c:186:29: warning: unused function 'pmd_to_hmm_pfn_flags' [-Wunused-function]
Fix this by moving the function to the respective existing ifdeffery for its the only user.
See also:
6863f5643dd7 ("kbuild: allow Clang to find unused static inline functions for W=1 build")
--- mm/hmm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/hmm.c +1 -1
@@ -392,6 +392,7 @@ static int hmm_vma_walk_hole(unsigned loreturn hmm_vma_walk_hole_ (addr, end, fault, write_fault, walk); } +#ifdef CONFIG_TRANSPARENT_HUGEPAGE static inline uint64_t pmd_to_hmm_pfn_flags (struct hmm_range *range,pmd_t pmd) {if (pmd_protnone (pmd))
@@ -401,7 +402,6 @@ static inline uint64_t pmd_to_hmm_pfn_fl range->flags[HMM_PFN_VALID ]; } -#ifdef CONFIG_TRANSPARENT_HUGEPAGE static int hmm_vma_handle_pmd (struct mm_walk *walk,unsigned long addr,unsigned long end,uint64_t *pfns,pmd_t pmd) {
Greg Kroah-Hartman
maintainerPATCH 348/403 x86/fpu: Delay instruction pointer fixup until after warning
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dave Hansen <[email protected]>
[ Upstream commit 1cec9ac2d071cfd2da562241aab0ef701355762a ]
Right now, if XRSTOR fails a console message like this is be printed:
Bad FPU state detected at restore_fpregs_from_fpstate+0x9a/0x170, reinitializing FPU registers.
However, the text location (...+0x9a in this case) is the instruction *AFTER* the XRSTOR. The highlighted instruction in the "Code:" dump also points one instruction late.
The reason is that the "fixup" moves RIP up to pass the bad XRSTOR and keep on running after returning from the #GP handler. But it does this fixup before warning.
The resulting warning output is nonsensical because it looks like the non-FPU-related instruction is #GP'ing.
Do not fix up RIP until after printing the warning. Do this by using the more generic and standard ex_handler_default().
--- arch/x86/mm/extable.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
arch/x86/mm/extable.c +2 -3
@@ -59,13 +59,12 @@ __visible bool ex_handler_fprestore(cons unsigned long error_code, unsigned long fault_addr) { - regs->ip = ex_fixup_addr(fixup); - WARN_ONCE(1, "Bad FPU state detected at %pB, reinitializing FPU registers.", (void *)instruction_pointer(regs));__copy_kernel_to_fpregs (&init_fpstate,-1 ); -return true; + +return ex_handler_default (fixup, regs, trapnr, error_code, fault_addr); }EXPORT_SYMBOL_GPL (ex_handler_fprestore);
Greg Kroah-Hartman
maintainerPATCH 349/403 ALSA: scarlett2: Add retry on -EPROTO from scarlett2_usb_tx()
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Geoffrey D. Bennett" <[email protected]>
[ Upstream commit 8a15ca0ca51399b652b1bbb23b590b220cf03d62 ]
During communication with Focusrite Scarlett Gen 2/3/4 USB audio interfaces, -EPROTO is sometimes returned from scarlett2_usb_tx(), snd_usb_ctl_msg() which can cause initialisation and control operations to fail intermittently.
This patch adds up to 5 retries in scarlett2_usb(), with a delay starting at 5ms and doubling each time. This follows the same approach as the fix for usb_set_interface() in endpoint.c (commit f406005e162b ("ALSA: usb-audio: Add retry on -EPROTO from usb_set_interface()")), which resolved similar -EPROTO issues during device initialisation, and is the same approach as in fcp.c:fcp_usb().
--- sound/usb/mixer_scarlett_gen2.c | 9 +++++++++ 1 file changed, 9 insertions(+)
sound/usb/mixer_scarlett_gen2.c +9 -0
@@ -118,6 +118,8 @@#define SCARLETT2_MIXER_MAX_VALUE \ ((SCARLETT2_MIXER_MAX_DB - SCARLETT2_MIXER_MIN_DB) * 2) +#include <linux/delay.h> +/* map from (dB + 80) * 2 to mixer value * for dB in 0 .. 172: int(8192 * pow(10, ((dB - 160) / 2 / 20))) */
@@ -591,6 +593,8 @@ static int scarlett2_usb(u16 req_buf_size =sizeof (struct scarlett2_usb_packet ) + req_size;u16 resp_buf_size =sizeof (struct scarlett2_usb_packet ) + resp_size;struct scarlett2_usb_packet *req =NULL , *resp =NULL ; +int retries =0 ; +const int max_retries =5 ;int err =0 ; req =kmalloc (req_buf_size,GFP_KERNEL );
@@ -614,6 +618,7 @@ static int scarlett2_usb(if (req_size)memcpy (req->data, req_data, req_size); +retry: err = snd_usb_ctl_msg(mixer->chip->dev, usb_sndctrlpipe(mixer->chip->dev, 0), SCARLETT2_USB_VENDOR_SPECIFIC_CMD_REQ,
@@ -624,6 +629,10 @@ static int scarlett2_usb( req_buf_size);if (err != req_buf_size) { +if (err == -EPROTO && ++retries <= max_retries) { +msleep (5 * (1 << (retries -1 ))); + goto retry; + } usb_audio_err( mixer->chip, "Scarlett Gen 2 USB request result cmd %x was %d\n",
Greg Kroah-Hartman
maintainerPATCH 350/403 mm/kmemleak: turn kmemleak_lock and object->lock to raw_spinlock_t
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: He Zhe <[email protected]>
[ Upstream commit 8c96f1bc6fc49c724c4cdd22d3e99260263b7384 ]
kmemleak_lock as a rwlock on RT can possibly be acquired in atomic context which does work.
Since the kmemleak operation is performed in atomic context make it a raw_spinlock_t so it can also be acquired on RT. This is used for debugging and is not enabled by default in a production like environment (where performance/latency matters) so it makes sense to make it a raw_spinlock_t instead trying to get rid of the atomic context. Turn also the kmemleak_object->lock into raw_spinlock_t which is acquired (nested) while the kmemleak_lock is held.
The time spent in "echo scan > kmemleak" slightly improved on 64core box with this patch applied after boot.
Stable-dep-of: 47b0f6d8f0d2 ("mm/kmemleak: avoid deadlock by moving pr_warn() outside kmemleak_lock")
--- mm/kmemleak.c | 112 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 56 insertions(+), 56 deletions(-)
mm/kmemleak.c +56 -56
@@ -13,7 +13,7 @@* * The following locks and mutexes are used by kmemleak: * -* - kmemleak_lock (rwlock): protects the object_list modifications and +* - kmemleak_lock (raw_spinlock_t): protects the object_list modifications and * accesses to the object_tree_root. The object_list is the main list * holding the metadata (struct kmemleak_object) for the allocated memory * blocks. The object_tree_root is a red black tree used to look-up
@@ -22,13 +22,13 @@* object_tree_root in the create_object() function called from the * kmemleak_alloc() callback and removed in delete_object() called from the * kmemleak_free() callback -* - kmemleak_object.lock (spinlock): protects a kmemleak_object. Accesses to -* the metadata (e.g. count) are protected by this lock. Note that some -* members of this structure may be protected by other means (atomic or -* kmemleak_lock). This lock is also held when scanning the corresponding -* memory block to avoid the kernel freeing it via the kmemleak_free() -* callback. This is less heavyweight than holding a global lock like -* kmemleak_lock during scanning +* - kmemleak_object.lock (raw_spinlock_t): protects a kmemleak_object. +* Accesses to the metadata (e.g. count) are protected by this lock. Note +* that some members of this structure may be protected by other means +* (atomic or kmemleak_lock). This lock is also held when scanning the +* corresponding memory block to avoid the kernel freeing it via the +* kmemleak_free() callback. This is less heavyweight than holding a global +* lock like kmemleak_lock during scanning. * - scan_mutex (mutex): ensures that only one thread may scan the memory for * unreferenced objects at a time. The gray_list contains the objects which * are already referenced or marked as false positives and need to be
@@ -135,7 +135,7 @@ struct kmemleak_scan_area {* (use_count) and freed using the RCU mechanism. */ struct kmemleak_object { -spinlock_t lock; +raw_spinlock_t lock;unsigned int flags;/* object status flags */ struct list_head object_list;struct list_head gray_list;
@@ -191,8 +191,8 @@ static int mem_pool_free_count = ARRAY_Sstatic LIST_HEAD (mem_pool_free_list);/* search tree for object boundaries */ static struct rb_root object_tree_root =RB_ROOT ; -/* rw_lock protecting the access to object_list and object_tree_root */ -static DEFINE_RWLOCK (kmemleak_lock); +/* protecting the access to object_list and object_tree_root */ +static DEFINE_RAW_SPINLOCK (kmemleak_lock);/* allocation caches for kmemleak internal data */ static struct kmem_cache *object_cache;
@@ -426,7 +426,7 @@ static struct kmemleak_object *mem_pool_ }/* slab allocation failed, try the memory pool */ -write_lock_irqsave (&kmemleak_lock, flags); +raw_spin_lock_irqsave (&kmemleak_lock, flags); object =list_first_entry_or_null (&mem_pool_free_list,typeof (*object), object_list);if (object)
@@ -435,7 +435,7 @@ static struct kmemleak_object *mem_pool_ object = &mem_pool[--mem_pool_free_count]; else pr_warn_once("Memory pool empty, consider increasing CONFIG_DEBUG_KMEMLEAK_MEM_POOL_SIZE\n"); -write_unlock_irqrestore (&kmemleak_lock, flags); +raw_spin_unlock_irqrestore (&kmemleak_lock, flags);return object; }
@@ -453,9 +453,9 @@ static void mem_pool_free(struct kmemlea }/* add the object to the memory pool free list */ -write_lock_irqsave (&kmemleak_lock, flags); +raw_spin_lock_irqsave (&kmemleak_lock, flags);list_add (&object->object_list, &mem_pool_free_list); -write_unlock_irqrestore (&kmemleak_lock, flags); +raw_spin_unlock_irqrestore (&kmemleak_lock, flags); }/*
@@ -514,9 +514,9 @@ static struct kmemleak_object *find_and_struct kmemleak_object *object;rcu_read_lock (); -read_lock_irqsave (&kmemleak_lock, flags); +raw_spin_lock_irqsave (&kmemleak_lock, flags); object =lookup_object (ptr, alias); -read_unlock_irqrestore (&kmemleak_lock, flags); +raw_spin_unlock_irqrestore (&kmemleak_lock, flags);/* check whether the object is still available */ if (object && !get_object (object))
@@ -546,11 +546,11 @@ static struct kmemleak_object *find_and_unsigned long flags;struct kmemleak_object *object; -write_lock_irqsave (&kmemleak_lock, flags); +raw_spin_lock_irqsave (&kmemleak_lock, flags); object =lookup_object (ptr, alias);if (object)__remove_object (object); -write_unlock_irqrestore (&kmemleak_lock, flags); +raw_spin_unlock_irqrestore (&kmemleak_lock, flags);return object; }
@@ -585,7 +585,7 @@ static struct kmemleak_object *create_obINIT_LIST_HEAD (&object->object_list);INIT_LIST_HEAD (&object->gray_list);INIT_HLIST_HEAD (&object->area_list); -spin_lock_init (&object->lock); +raw_spin_lock_init (&object->lock);atomic_set (&object->use_count,1 ); object->flags =OBJECT_ALLOCATED ; object->pointer = ptr;
@@ -617,7 +617,7 @@ static struct kmemleak_object *create_ob/* kernel backtrace */ object->trace_len =__save_stack_trace (object->trace); -write_lock_irqsave (&kmemleak_lock, flags); +raw_spin_lock_irqsave (&kmemleak_lock, flags); untagged_ptr = (unsigned long )kasan_reset_tag ((void *)ptr); min_addr =min (min_addr, untagged_ptr);
@@ -649,7 +649,7 @@ static struct kmemleak_object *create_oblist_add_tail_rcu (&object->object_list, &object_list); out: -write_unlock_irqrestore (&kmemleak_lock, flags); +raw_spin_unlock_irqrestore (&kmemleak_lock, flags);return object; }
@@ -667,9 +667,9 @@ static void __delete_object(struct kmeml* Locking here also ensures that the corresponding memory block * cannot be freed when it is being scanned. */ -spin_lock_irqsave (&object->lock, flags); +raw_spin_lock_irqsave (&object->lock, flags); object->flags &= ~OBJECT_ALLOCATED ; -spin_unlock_irqrestore (&object->lock, flags); +raw_spin_unlock_irqrestore (&object->lock, flags);put_object (object); }
@@ -739,9 +739,9 @@ static void paint_it(struct kmemleak_obj {unsigned long flags; -spin_lock_irqsave (&object->lock, flags); +raw_spin_lock_irqsave (&object->lock, flags);__paint_it (object, color); -spin_unlock_irqrestore (&object->lock, flags); +raw_spin_unlock_irqrestore (&object->lock, flags); }static void paint_ptr (unsigned long ptr,int color)
@@ -803,7 +803,7 @@ static void add_scan_area(unsigned longif (scan_area_cache) area =kmem_cache_alloc (scan_area_cache,gfp_kmemleak_mask (gfp)); -spin_lock_irqsave (&object->lock, flags); +raw_spin_lock_irqsave (&object->lock, flags);if (!area) {pr_warn_once ("Cannot allocate a scan area, scanning the full object\n" );/* mark the object for full scan to avoid false positives */
@@ -825,7 +825,7 @@ static void add_scan_area(unsigned longhlist_add_head (&area->node, &object->area_list); out_unlock: -spin_unlock_irqrestore (&object->lock, flags); +raw_spin_unlock_irqrestore (&object->lock, flags);put_object (object); }
@@ -847,9 +847,9 @@ static void object_set_excess_ref(unsignreturn ; } -spin_lock_irqsave (&object->lock, flags); +raw_spin_lock_irqsave (&object->lock, flags); object->excess_ref = excess_ref; -spin_unlock_irqrestore (&object->lock, flags); +raw_spin_unlock_irqrestore (&object->lock, flags);put_object (object); }
@@ -869,9 +869,9 @@ static void object_no_scan(unsigned longreturn ; } -spin_lock_irqsave (&object->lock, flags); +raw_spin_lock_irqsave (&object->lock, flags); object->flags |=OBJECT_NO_SCAN ; -spin_unlock_irqrestore (&object->lock, flags); +raw_spin_unlock_irqrestore (&object->lock, flags);put_object (object); }
@@ -1031,9 +1031,9 @@ void __ref kmemleak_update_trace(const vreturn ; } -spin_lock_irqsave (&object->lock, flags); +raw_spin_lock_irqsave (&object->lock, flags); object->trace_len =__save_stack_trace (object->trace); -spin_unlock_irqrestore (&object->lock, flags); +raw_spin_unlock_irqrestore (&object->lock, flags);put_object (object); }
@@ -1238,7 +1238,7 @@ static void scan_block(void *_start, voiunsigned long flags;unsigned long untagged_ptr; -read_lock_irqsave (&kmemleak_lock, flags); +raw_spin_lock_irqsave (&kmemleak_lock, flags);for (ptr = start; ptr < end; ptr++) {struct kmemleak_object *object;unsigned long pointer;
@@ -1273,7 +1273,7 @@ static void scan_block(void *_start, voi* previously acquired in scan_object(). These locks are * enclosed by scan_mutex. */ -spin_lock_nested (&object->lock,SINGLE_DEPTH_NESTING ); +raw_spin_lock_nested (&object->lock,SINGLE_DEPTH_NESTING );/* only pass surplus references (object already gray) */ if (color_gray (object)) { excess_ref = object->excess_ref;
@@ -1282,7 +1282,7 @@ static void scan_block(void *_start, voi excess_ref =0 ;update_refs (object); } -spin_unlock (&object->lock); +raw_spin_unlock (&object->lock);if (excess_ref) { object =lookup_object (excess_ref,0 );
@@ -1291,12 +1291,12 @@ static void scan_block(void *_start, voiif (object == scanned)/* circular reference, ignore */ continue ; -spin_lock_nested (&object->lock,SINGLE_DEPTH_NESTING ); +raw_spin_lock_nested (&object->lock,SINGLE_DEPTH_NESTING );update_refs (object); -spin_unlock (&object->lock); +raw_spin_unlock (&object->lock); } } -read_unlock_irqrestore (&kmemleak_lock, flags); +raw_spin_unlock_irqrestore (&kmemleak_lock, flags); }/*
@@ -1329,7 +1329,7 @@ static void scan_object(struct kmemleak_* Once the object->lock is acquired, the corresponding memory block * cannot be freed (the same lock is acquired in delete_object). */ -spin_lock_irqsave (&object->lock, flags); +raw_spin_lock_irqsave (&object->lock, flags);if (object->flags &OBJECT_NO_SCAN ) goto out;if (!(object->flags &OBJECT_ALLOCATED ))
@@ -1349,9 +1349,9 @@ static void scan_object(struct kmemleak_if (start >= end)break ; -spin_unlock_irqrestore (&object->lock, flags); +raw_spin_unlock_irqrestore (&object->lock, flags);cond_resched (); -spin_lock_irqsave (&object->lock, flags); +raw_spin_lock_irqsave (&object->lock, flags); }while (object->flags &OBJECT_ALLOCATED ); }else hlist_for_each_entry (area, &object->area_list, node)
@@ -1359,7 +1359,7 @@ static void scan_object(struct kmemleak_ (void *)(area->start + area->size), object); out: -spin_unlock_irqrestore (&object->lock, flags); +raw_spin_unlock_irqrestore (&object->lock, flags); }/*
@@ -1413,7 +1413,7 @@ static void kmemleak_scan(void)/* prepare the kmemleak_object's */ rcu_read_lock ();list_for_each_entry_rcu (object, &object_list, object_list) { -spin_lock_irqsave (&object->lock, flags); +raw_spin_lock_irqsave (&object->lock, flags);#ifdef DEBUG /* * With a few exceptions there should be a maximum of
@@ -1430,7 +1430,7 @@ static void kmemleak_scan(void)if (color_gray (object) &&get_object (object))list_add_tail (&object->gray_list, &gray_list); -spin_unlock_irqrestore (&object->lock, flags); +raw_spin_unlock_irqrestore (&object->lock, flags); }rcu_read_unlock ();
@@ -1498,14 +1498,14 @@ static void kmemleak_scan(void)*/ rcu_read_lock ();list_for_each_entry_rcu (object, &object_list, object_list) { -spin_lock_irqsave (&object->lock, flags); +raw_spin_lock_irqsave (&object->lock, flags);if (color_white (object) && (object->flags &OBJECT_ALLOCATED ) &&update_checksum (object) &&get_object (object)) {/* color it gray temporarily */ object->count = object->min_count;list_add_tail (&object->gray_list, &gray_list); } -spin_unlock_irqrestore (&object->lock, flags); +raw_spin_unlock_irqrestore (&object->lock, flags); }rcu_read_unlock ();
@@ -1525,7 +1525,7 @@ static void kmemleak_scan(void)*/ rcu_read_lock ();list_for_each_entry_rcu (object, &object_list, object_list) { -spin_lock_irqsave (&object->lock, flags); +raw_spin_lock_irqsave (&object->lock, flags);if (unreferenced_object (object) && !(object->flags &OBJECT_REPORTED )) { object->flags |=OBJECT_REPORTED ;
@@ -1535,7 +1535,7 @@ static void kmemleak_scan(void) new_leaks++; } -spin_unlock_irqrestore (&object->lock, flags); +raw_spin_unlock_irqrestore (&object->lock, flags); }rcu_read_unlock ();
@@ -1687,10 +1687,10 @@ static int kmemleak_seq_show(struct seq_struct kmemleak_object *object = v;unsigned long flags; -spin_lock_irqsave (&object->lock, flags); +raw_spin_lock_irqsave (&object->lock, flags);if ((object->flags &OBJECT_REPORTED ) &&unreferenced_object (object))print_unreferenced (seq, object); -spin_unlock_irqrestore (&object->lock, flags); +raw_spin_unlock_irqrestore (&object->lock, flags);return 0 ; }
@@ -1720,9 +1720,9 @@ static int dump_str_object_info(const chreturn -EINVAL ; } -spin_lock_irqsave (&object->lock, flags); +raw_spin_lock_irqsave (&object->lock, flags);dump_object_info (object); -spin_unlock_irqrestore (&object->lock, flags); +raw_spin_unlock_irqrestore (&object->lock, flags);put_object (object);return 0 ;
@@ -1741,11 +1741,11 @@ static void kmemleak_clear(void)rcu_read_lock ();list_for_each_entry_rcu (object, &object_list, object_list) { -spin_lock_irqsave (&object->lock, flags); +raw_spin_lock_irqsave (&object->lock, flags);if ((object->flags &OBJECT_REPORTED ) &&unreferenced_object (object))__paint_it (object,KMEMLEAK_GREY ); -spin_unlock_irqrestore (&object->lock, flags); +raw_spin_unlock_irqrestore (&object->lock, flags); }rcu_read_unlock ();
Greg Kroah-Hartman
maintainerPATCH 351/403 mm/kmemleak: avoid deadlock by moving pr_warn() outside kmemleak_lock
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Breno Leitao <[email protected]>
[ Upstream commit 47b0f6d8f0d2be4d311a49e13d2fd5f152f492b2 ]
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
@@ -417,6 +417,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) {
@@ -434,8 +435,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 352/403 USB: cdc-acm: do not log successful probe on later errors
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 79579411826647fd573dbe301c4d933bc90e4be7 ]
Do not log the successful-probe message until the tty device has been registered.
Stable-dep-of: 64690a90cd7c ("cdc-acm: fix race between initial clearing halt and open")
--- drivers/usb/class/cdc-acm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/class/cdc-acm.c +2 -2
@@ -1520,8 +1520,6 @@ skip_countries: acm->nb_index =0 ; acm->nb_size =0 ; -dev_info (&intf->dev,"ttyACM%d: USB ACM device\n" , minor); - acm->line.dwDTERate =cpu_to_le32 (9600 ); acm->line.bDataBits =8 ;acm_set_line (acm, &acm->line);
@@ -1541,6 +1539,8 @@ skip_countries:usb_clear_halt (usb_dev, acm->out); } +dev_info (&intf->dev,"ttyACM%d: USB ACM device\n" , minor); +return 0 ; alloc_fail6:if (!acm->combined_interfaces) {
Greg Kroah-Hartman
maintainerPATCH 353/403 cdc-acm: fix race between initial clearing halt and open
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Oliver Neukum <[email protected]>
[ Upstream commit 64690a90cd7c6db16d3af8616be1f4bf8d492850 ]
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
@@ -1527,6 +1527,12 @@ skip_countries:usb_driver_claim_interface (&acm_driver, data_interface, acm);usb_set_intfdata (data_interface, acm); +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)) {
@@ -1534,11 +1540,6 @@ skip_countries: goto alloc_fail6; } -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 354/403 usb: typec: fusb302: cache PD RX state
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sebastian Reichel <[email protected]>
[ Upstream commit 1e61f6ab08786d66a11cfc51e13d6f08a6b06c56 ]
This patch fixes a race condition communication error, which ends up in PD hard resets when losing the race. Some systems, like the Radxa ROCK 5B are powered through USB-C without any backup power source and use a FUSB302 chip to do the PD negotiation. This means it is quite important to avoid hard resets, since that effectively kills the system's power-supply.
I've found the following race condition while debugging unplanned power loss during booting the board every now and then:
1. lots of TCPM/FUSB302/PD initialization stuff
2. TCPM ends up in SNK_WAIT_CAPABILITIES (tcpm_set_pd_rx is enabled here)
3. the remote PD source does not send anything, so TCPM does a SOFT RESET
4. TCPM ends up in SNK_WAIT_CAPABILITIES for the second time (tcpm_set_pd_rx is enabled again, even though it is still on)
At this point I've seen broken CRC good messages being send by the FUSB302 with a logic analyzer sniffing the CC lines. Also it looks like messages are being lost and things generally going haywire with one of the two sides doing a hard reset once a broken CRC good message was send to the bus.
I think the system is running into a race condition, that the FIFOs are being cleared and/or the automatic good CRC message generation flag is being updated while a message is already arriving.
Let's avoid this by caching the PD RX enabled state, as we have already processed anything in the FIFOs and are in a good state. As a side effect that this also optimizes I2C bus usage :)
As far as I can tell the problem theoretically also exists when TCPM enters SNK_WAIT_CAPABILITIES the first time, but I believe this is less critical for the following reason:
On devices like the ROCK 5B, which are powered through a TCPM backed USB-C port, the bootloader must have done some prior PD communication (initial communication must happen within 5 seconds after plugging the USB-C plug). This means the first time the kernel TCPM state machine reaches SNK_WAIT_CAPABILITIES, the remote side is not sending messages actively. On other devices a hard reset simply adds some extra delay and things should be good afterwards.
--- drivers/usb/typec/tcpm/fusb302.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/usb/typec/tcpm/fusb302.c +8 -0
@@ -104,6 +104,7 @@ struct fusb302_chip {bool vconn_on;bool vbus_on;bool charge_on; +bool pd_rx_on;bool vbus_present;enum typec_cc_polarity cc_polarity;enum typec_cc_status cc1;
@@ -841,6 +842,11 @@ static int tcpm_set_pd_rx(struct tcpc_deint ret =0 ;mutex_lock (&chip->lock); +if (chip->pd_rx_on == on) { +fusb302_log (chip,"pd is already %s" , on ?"on" :"off" ); + goto done; + } + ret =fusb302_pd_rx_flush (chip);if (ret <0 ) {fusb302_log (chip,"cannot flush pd rx buffer, ret=%d" , ret);
@@ -863,6 +869,8 @@ static int tcpm_set_pd_rx(struct tcpc_de on ? "on" : "off", ret); goto done; } + + chip->pd_rx_on = on;fusb302_log (chip,"pd := %s" , on ?"on" :"off" ); done:mutex_unlock (&chip->lock);
Greg Kroah-Hartman
maintainerPATCH 355/403 NFSv4: Fix nfs4_bitmap_copy_adjust()
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Trond Myklebust <[email protected]>
[ Upstream commit a71029b86752e8d40301af235a6bbf4896cc1402 ]
Don't remove flags from the set retrieved from the cache_validity. We do want to retrieve all attributes that are listed as being invalid, whether or not there is a delegation set.
Stable-dep-of: b01f21cacde9 ("NFS: Fix the setting of capabilities when automounting a new filesystem")
--- fs/nfs/nfs4proc.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-)
fs/nfs/nfs4proc.c +16 -17
@@ -282,7 +282,7 @@ const u32 nfs4_fs_locations_bitmap[3] = };static void nfs4_bitmap_copy_adjust (__u32 *dst,const __u32 *src, -struct inode *inode) +struct inode *inode,unsigned long flags) {unsigned long cache_validity;
@@ -290,22 +290,19 @@ static void nfs4_bitmap_copy_adjust(__u3if (!inode || !nfs4_have_delegation (inode,FMODE_READ ))return ; - cache_validity =READ_ONCE (NFS_I (inode)->cache_validity); -if (!(cache_validity &NFS_INO_REVAL_FORCED )) - cache_validity &= ~(NFS_INO_INVALID_CHANGE - |NFS_INO_INVALID_SIZE ); + cache_validity =READ_ONCE (NFS_I (inode)->cache_validity) | flags; +/* Remove the attributes over which we have full control */ + dst[1 ] &= ~FATTR4_WORD1_RAWDEV ;if (!(cache_validity &NFS_INO_INVALID_SIZE )) dst[0 ] &= ~FATTR4_WORD0_SIZE ;if (!(cache_validity &NFS_INO_INVALID_CHANGE )) dst[0 ] &= ~FATTR4_WORD0_CHANGE ; -} -static void nfs4_bitmap_copy_adjust_setattr (__u32 *dst, -const __u32 *src,struct inode *inode) -{ -nfs4_bitmap_copy_adjust (dst, src, inode); +if (!(cache_validity &NFS_INO_INVALID_OTHER )) + dst[1 ] &= ~(FATTR4_WORD1_MODE |FATTR4_WORD1_OWNER | +FATTR4_WORD1_OWNER_GROUP ); } static void nfs4_setup_readdir(u64 cookie, __be32 *verifier, struct dentry *dentry,
@@ -3333,12 +3330,15 @@ static int nfs4_do_setattr(struct inode .inode = inode, .stateid = &arg.stateid, }; +unsigned long adjust_flags =NFS_INO_INVALID_CHANGE ;int err; +if (sattr->ia_valid & (ATTR_MODE |ATTR_UID |ATTR_GID )) + adjust_flags |=NFS_INO_INVALID_OTHER ; + do { - nfs4_bitmap_copy_adjust_setattr(bitmask, - nfs4_bitmask(server, olabel), - inode); + nfs4_bitmap_copy_adjust(bitmask, nfs4_bitmask(server, olabel), + inode, adjust_flags); err = _nfs4_do_setattr(inode, &arg, &res, cred, ctx); switch (err) {
@@ -4143,8 +4143,7 @@ static int _nfs4_proc_getattr(struct nfs .rpc_resp = &res, }; -nfs4_bitmap_copy_adjust (bitmask,nfs4_bitmask (server, label), inode); - +nfs4_bitmap_copy_adjust (bitmask,nfs4_bitmask (server, label), inode,0 );nfs_fattr_init (fattr);return nfs4_call_sync (server->client, server, &msg, &args.seq_args, &res.seq_res,0 ); }
@@ -4732,8 +4731,8 @@ static int _nfs4_proc_link(struct inode }nfs4_inode_make_writeable (inode); -nfs4_bitmap_copy_adjust_setattr (bitmask,nfs4_bitmask (server, res.label), inode); - +nfs4_bitmap_copy_adjust (bitmask,nfs4_bitmask (server, res.label), inode, +NFS_INO_INVALID_CHANGE ); status =nfs4_call_sync (server->client, server, &msg, &arg.seq_args, &res.seq_res,1 );if (!status) {update_changeattr (dir, &res.cinfo, res.fattr->time_start,0 );
Greg Kroah-Hartman
maintainerPATCH 356/403 NFS: Fix up handling of outstanding layoutcommit in nfs_update_inode()
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Trond Myklebust <[email protected]>
[ Upstream commit 709fa5769914b377af87962bbe4ff81ffb019b2d ]
If there is an outstanding layoutcommit, then the list of attributes whose values are expected to change is not the full set. So let's be explicit about the full list.
Stable-dep-of: b01f21cacde9 ("NFS: Fix the setting of capabilities when automounting a new filesystem")
--- fs/nfs/inode.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/nfs/inode.c +5 -1
@@ -1869,7 +1869,11 @@ static int nfs_update_inode(struct inodenfs_wcc_update_inode (inode, fattr);if (pnfs_layoutcommit_outstanding (inode)) { - nfsi->cache_validity |= save_cache_validity &NFS_INO_INVALID_ATTR ; + nfsi->cache_validity |= + save_cache_validity & + (NFS_INO_INVALID_CHANGE |NFS_INO_INVALID_CTIME | +NFS_INO_INVALID_MTIME |NFS_INO_INVALID_SIZE | +NFS_INO_REVAL_FORCED ); cache_revalidated = false; }
Greg Kroah-Hartman
maintainerPATCH 357/403 NFS: Fix the setting of capabilities when automounting a new filesystem
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Trond Myklebust <[email protected]>
[ Upstream commit b01f21cacde9f2878492cf318fee61bf4ccad323 ]
Capabilities cannot be inherited when we cross into a new filesystem. They need to be reset to the minimal defaults, and then probed for again.
--- fs/nfs/client.c | 44 ++++++++++++++++++++++++++++++++++++++++---- fs/nfs/internal.h | 1 + fs/nfs/nfs4client.c | 13 +------------ fs/nfs/nfs4proc.c | 2 ++ 4 files changed, 44 insertions(+), 16 deletions(-)
fs/nfs/client.c +40 -4
@@ -646,6 +646,42 @@ struct nfs_client *nfs_init_client(struc }EXPORT_SYMBOL_GPL (nfs_init_client); +static void nfs4_server_set_init_caps (struct nfs_server *server) +{ +#if IS_ENABLED (CONFIG_NFS_V4 ) +/* Set the basic capabilities */ + server->caps = server->nfs_client->cl_mvops->init_caps; +if (server->flags &NFS_MOUNT_NORDIRPLUS ) + server->caps &= ~NFS_CAP_READDIRPLUS ; + +/* +* Don't use NFS uid/gid mapping if we're using AUTH_SYS or lower +* authentication. +*/ +if (nfs4_disable_idmapping && + server->client->cl_auth->au_flavor ==RPC_AUTH_UNIX ) + server->caps |=NFS_CAP_UIDGID_NOMAP ; +#endif +} + +void nfs_server_set_init_caps (struct nfs_server *server) +{ +switch (server->nfs_client->rpc_ops->version) { +case 2 : + server->caps =NFS_CAP_HARDLINKS |NFS_CAP_SYMLINKS ; +break ; +case 3 : + server->caps =NFS_CAP_HARDLINKS |NFS_CAP_SYMLINKS ; +if (!(server->flags &NFS_MOUNT_NORDIRPLUS )) + server->caps |=NFS_CAP_READDIRPLUS ; +break ; +default : +nfs4_server_set_init_caps (server); +break ; + } +} +EXPORT_SYMBOL_GPL (nfs_server_set_init_caps); +/* * Create a version 2 or 3 client */
@@ -683,9 +719,6 @@ static int nfs_init_server(struct nfs_se/* Initialise the client representation from the mount data */ server->flags = data->flags; server->options = data->options; - server->caps |=NFS_CAP_HARDLINKS |NFS_CAP_SYMLINKS |NFS_CAP_FILEID | -NFS_CAP_MODE |NFS_CAP_NLINK |NFS_CAP_OWNER |NFS_CAP_OWNER_GROUP | -NFS_CAP_ATIME |NFS_CAP_CTIME |NFS_CAP_MTIME ;if (data->rsize) server->rsize =nfs_block_size (data->rsize,NULL );
@@ -710,6 +743,8 @@ static int nfs_init_server(struct nfs_seif (error <0 ) goto error; +nfs_server_set_init_caps (server); +/* Preserve the values of mount_server-related mount options */ if (data->mount_server.addrlen) { memcpy(&server->mountd_address, &data->mount_server.address,
@@ -834,7 +869,6 @@ void nfs_server_copy_userdata(struct nfs target->acregmax = source->acregmax; target->acdirmin = source->acdirmin; target->acdirmax = source->acdirmax; - target->caps = source->caps; target->options = source->options; target->auth_info = source->auth_info; target->port = source->port;
@@ -1042,6 +1076,8 @@ struct nfs_server *nfs_clone_server(struif (error <0 ) goto out_free_server; +nfs_server_set_init_caps (server); +/* probe the filesystem info for this server filesystem */ error =nfs_probe_fsinfo (server, fh, fattr_fsinfo);if (error <0 )
fs/nfs/internal.h +1 -0
@@ -172,6 +172,7 @@ nfs4_find_client_sessionid(struct net *, struct nfs4_sessionid *, u32);extern struct nfs_server *nfs_create_server (struct nfs_mount_info *,struct nfs_subversion *); +extern void nfs_server_set_init_caps (struct nfs_server *);extern struct nfs_server *nfs4_create_server (struct nfs_mount_info *,struct nfs_subversion *);
fs/nfs/nfs4client.c +1 -12
@@ -1011,18 +1011,7 @@ static int nfs4_server_common_setup(struif (error <0 ) goto out; -/* Set the basic capabilities */ - server->caps |= server->nfs_client->cl_mvops->init_caps; -if (server->flags &NFS_MOUNT_NORDIRPLUS ) - server->caps &= ~NFS_CAP_READDIRPLUS ; -/* -* Don't use NFS uid/gid mapping if we're using AUTH_SYS or lower -* authentication. -*/ -if (nfs4_disable_idmapping && - server->client->cl_auth->au_flavor ==RPC_AUTH_UNIX ) - server->caps |=NFS_CAP_UIDGID_NOMAP ; - +nfs_server_set_init_caps (server);/* Probe the root fh to retrieve its FSID and filehandle */ error =nfs4_get_rootfh (server, mntfh, auth_probe);
fs/nfs/nfs4proc.c +2 -0
@@ -3884,6 +3884,8 @@ int nfs4_server_capabilities(struct nfs_ .interruptible = true, };int err; + +nfs_server_set_init_caps (server); do { err = nfs4_handle_exception(server, _nfs4_server_capabilities(server, fhandle),
Greg Kroah-Hartman
maintainerPATCH 358/403 usb: musb: omap2430: fix device leak at unbind
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Johan Hovold <[email protected]>
[ Upstream commit 1473e9e7679bd4f5a62d1abccae894fb86de280f ]
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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/usb/musb/omap2430.c +7 -3
@@ -476,13 +476,13 @@ static int omap2430_probe(struct platfor ARRAY_SIZE(musb_resources));if (ret) {dev_err (&pdev->dev,"failed to add 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);
@@ -497,7 +497,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);
@@ -511,6 +513,8 @@ static int omap2430_remove(struct platfoplatform_device_unregister (glue->musb);pm_runtime_disable (glue->dev); +if (!IS_ERR (glue->control_otghs)) +put_device (glue->control_otghs);return 0 ; }
Greg Kroah-Hartman
maintainerPATCH 359/403 rtc: ds1307: handle oscillator stop flag (OSF) for ds1341
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Meagan Lloyd <[email protected]>
[ Upstream commit 523923cfd5d622b8f4ba893fdaf29fa6adeb8c3e ]
In using CONFIG_RTC_HCTOSYS, rtc_hctosys() will sync the RTC time to the kernel time as long as rtc_read_time() succeeds. In some power loss situations, our supercapacitor-backed DS1342 RTC comes up with either an unpredictable future time or the default 01/01/00 from the datasheet. The oscillator stop flag (OSF) is set in these scenarios due to the power loss and can be used to determine the validity of the RTC data.
This change expands the oscillator stop flag (OSF) handling that has already been implemented for some chips to the ds1341 chip (DS1341 and DS1342 share a datasheet). This handling manages the validity of the RTC data in .read_time and .set_time based on the OSF.
[ Git was trying to insert the code above the ds_1388 case statement block (in each respective function) which don't exist in the v5.4.296 rtc-ds1307 driver, thus a manual fixup was required. ]
---
Here's the backport of patch 2/2 of the series for v5.4.
--- drivers/rtc/rtc-ds1307.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/rtc/rtc-ds1307.c +11 -0
@@ -252,6 +252,13 @@ static int ds1307_get_time(struct deviceif (tmp &DS1340_BIT_OSF )return -EINVAL ;break ; +case ds_1341: + ret =regmap_read (ds1307->regmap,DS1337_REG_STATUS , &tmp); +if (ret) +return ret; +if (tmp &DS1337_BIT_OSF ) +return -EINVAL ; +break ;case mcp794xx:if (!(tmp &MCP794XX_BIT_ST ))return -EINVAL ;
@@ -343,6 +350,10 @@ static int ds1307_set_time(struct deviceregmap_update_bits (ds1307->regmap,DS1340_REG_FLAG ,DS1340_BIT_OSF ,0 );break ; +case ds_1341: +regmap_update_bits (ds1307->regmap,DS1337_REG_STATUS , +DS1337_BIT_OSF ,0 ); +break ;case mcp794xx:/* * these bits were cleared when preparing the date/time
Greg Kroah-Hartman
maintainerPATCH 360/403 soc: qcom: mdt_loader: Ensure we dont read past the ELF header
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Bjorn Andersson <[email protected]>
[ Upstream commit 9f9967fed9d066ed3dae9372b45ffa4f6fccfeef ]
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 | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
drivers/soc/qcom/mdt_loader.c +41 -0
@@ -12,11 +12,43 @@#include <linux/firmware.h> #include <linux/kernel.h> #include <linux/module.h> +#include <linux/overflow.h> #include <linux/qcom_scm.h> #include <linux/sizes.h> #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 false; + + 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 false; + + 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 )
@@ -46,6 +78,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 *)(ehdr +1 );
@@ -92,6 +127,9 @@ void *qcom_mdt_read_metadata(const strucsize_t ehdr_size;void *data; +if (!mdt_header_valid (fw)) +return ERR_PTR (-EINVAL ); + ehdr = (struct elf32_hdr *)fw->data; phdrs = (struct elf32_phdr *)(ehdr +1 );
@@ -151,6 +189,9 @@ static int __qcom_mdt_load(struct deviceif (!fw || !mem_region || !mem_phys || !mem_size)return -EINVAL ; +if (!mdt_header_valid (fw)) +return -EINVAL ; + ehdr = (struct elf32_hdr *)fw->data; phdrs = (struct elf32_phdr *)(ehdr +1 );
Greg Kroah-Hartman
maintainerPATCH 361/403 ata: Fix SATA_MOBILE_LPM_POLICY description in Kconfig
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Damien Le Moal <[email protected]>
[ Upstream commit ed62a62a18bc144f73eadf866ae46842e8f6606e ]
Improve the description of the possible default SATA link power management policies and add the missing description for policy 5. No functional changes.
--- drivers/ata/Kconfig | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-)
drivers/ata/Kconfig +25 -8
@@ -92,22 +92,39 @@ config SATA_AHCI config SATA_MOBILE_LPM_POLICY int "Default SATA Link Power Management policy for mobile chipsets" - range 0 4 + range 0 5 default 0 depends on SATA_AHCI help Select the Default SATA Link Power Management (LPM) policy to use for mobile / laptop variants of chipsets / "South Bridges". - The value set has the following meanings: + Each policy combines power saving states and features: + - Partial: The Phy logic is powered but is in a reduced power + state. The exit latency from this state is no longer than + 10us). + - Slumber: The Phy logic is powered but is in an even lower power + state. The exit latency from this state is potentially + longer, but no longer than 10ms. + - DevSleep: The Phy logic may be powered down. The exit latency from + this state is no longer than 20 ms, unless otherwise + specified by DETO in the device Identify Device Data log. + - HIPM: Host Initiated Power Management (host automatically + transitions to partial and slumber). + - DIPM: Device Initiated Power Management (device automatically + transitions to partial and slumber). + + The possible values for the default SATA link power management + policies are: 0 => Keep firmware settings - 1 => Maximum performance - 2 => Medium power - 3 => Medium power with Device Initiated PM enabled - 4 => Minimum power + 1 => No power savings (maximum performance) + 2 => HIPM (Partial) + 3 => HIPM (Partial) and DIPM (Partial and Slumber) + 4 => HIPM (Partial and DevSleep) and DIPM (Partial and Slumber) + 5 => HIPM (Slumber and DevSleep) and DIPM (Partial and Slumber) - Note "Minimum power" is known to cause issues, including disk - corruption, with some disks and should not be used. + Excluding the value 0, higher values represent policies with higher + power savings. config SATA_AHCI_PLATFORM tristate "Platform AHCI SATA support"
Greg Kroah-Hartman
maintainerPATCH 362/403 media: v4l2-ctrls: always copy the controls on completion
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Hans Verkuil <[email protected]>
[ Upstream commit c3bf5129f33923c92bf3bddaf4359b7b25ecb4ba ]
When v4l2_ctrl_request_complete() is called and there is no control handler object found in the request, then create such an object so that all controls at completion state can be stored and are available to userspace.
Otherwise any attempt by userspace to read the completed request data will fail.
If allocating the control handler object failed, then indicate that by returning ENOMEM when attempting to get the controls from the completed request instead of returning ENOENT.
Stable-dep-of: 5a0400aca5fa ("media: v4l2-ctrls: Don't reset handler's error in v4l2_ctrl_handler_free()")
--- drivers/media/v4l2-core/v4l2-ctrls.c | 36 +++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-)
drivers/media/v4l2-core/v4l2-ctrls.c +32 -4
@@ -3529,8 +3529,19 @@ v4l2_ctrls_find_req_obj(struct v4l2_ctrl obj =media_request_object_find (req, &req_ops, hdl);if (obj)return obj; +/* +* If there are no controls in this completed request, +* then that can only happen if: +* +* 1) no controls were present in the queued request, and +* 2) v4l2_ctrl_request_complete() could not allocate a +* control handler object to store the completed state in. +* +* So return ENOMEM to indicate that there was an out-of-memory +* error. +*/ if (!set) -return ERR_PTR (-ENOENT ); +return ERR_PTR (-ENOMEM ); new_hdl =kzalloc (sizeof (*new_hdl),GFP_KERNEL );if (!new_hdl)
@@ -3541,8 +3552,8 @@ v4l2_ctrls_find_req_obj(struct v4l2_ctrlif (!ret) ret =v4l2_ctrl_request_bind (req, new_hdl, hdl);if (ret) { +v4l2_ctrl_handler_free (new_hdl);kfree (new_hdl); -return ERR_PTR (ret); }
@@ -4113,8 +4124,25 @@ void v4l2_ctrl_request_complete(struct m* wants to leave the controls unchanged. */ obj =media_request_object_find (req, &req_ops, main_hdl); -if (!obj) -return ; +if (!obj) { +int ret; + +/* Create a new request so the driver can return controls */ + hdl =kzalloc (sizeof (*hdl),GFP_KERNEL ); +if (!hdl) +return ; + + ret =v4l2_ctrl_handler_init (hdl, (main_hdl->nr_of_buckets -1 ) *8 ); +if (!ret) + ret =v4l2_ctrl_request_bind (req, hdl, main_hdl); +if (ret) { +v4l2_ctrl_handler_free (hdl); +kfree (hdl); +return ; + } + hdl->request_is_queued = true; + obj =media_request_object_find (req, &req_ops, main_hdl); + } hdl = container_of(obj, struct v4l2_ctrl_handler, req_obj);list_for_each_entry (ref, &hdl->ctrl_refs, node) {
Greg Kroah-Hartman
maintainerPATCH 363/403 media: v4l2-ctrls: Dont reset handlers error in v4l2_ctrl_handler_free()
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Sakari Ailus <[email protected]>
[ Upstream commit 5a0400aca5fa7c6b8ba456c311a460e733571c88 ]
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.c | 1 - 1 file changed, 1 deletion(-)
drivers/media/v4l2-core/v4l2-ctrls.c +0 -1
@@ -2187,7 +2187,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 364/403 media: rainshadow-cec: fix TOCTOU race condition in rain_interrupt()
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gui-Dong Han <[email protected]>
[ Upstream commit 7af160aea26c7dc9e6734d19306128cce156ec40 ]
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/usb/rainshadow-cec/rainshadow-cec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/media/usb/rainshadow-cec/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 365/403 pwm: mediatek: Implement .apply() callback
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit 758de66f4bd2cac2b1d71db917c65c3d611d4e74 ]
To eventually get rid of all legacy drivers convert this driver to the modern world implementing .apply().
This just pushed a variant of pwm_apply_legacy() into the driver that was slightly simplified because the driver doesn't provide a .set_polarity() callback.
Stable-dep-of: f21d136caf81 ("pwm: mediatek: Fix duty and period setting")
--- drivers/pwm/pwm-mediatek.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-)
drivers/pwm/pwm-mediatek.c +26 -3
@@ -210,10 +210,33 @@ static void pwm_mediatek_disable(structpwm_mediatek_clk_disable (chip, pwm); } +static int pwm_mediatek_apply (struct pwm_chip *chip,struct pwm_device *pwm, +const struct pwm_state *state) +{ +int err; + +if (state->polarity !=PWM_POLARITY_NORMAL ) +return -EINVAL ; + +if (!state->enabled) { +if (pwm->state.enabled) +pwm_mediatek_disable (chip, pwm); + +return 0 ; + } + + err =pwm_mediatek_config (pwm->chip, pwm, state->duty_cycle, state->period); +if (err) +return err; + +if (!pwm->state.enabled) + err =pwm_mediatek_enable (chip, pwm); + +return err; +} +static const struct pwm_ops pwm_mediatek_ops = { - .config = pwm_mediatek_config, - .enable = pwm_mediatek_enable, - .disable = pwm_mediatek_disable, + .apply = pwm_mediatek_apply, .owner =THIS_MODULE , };
Greg Kroah-Hartman
maintainerPATCH 366/403 pwm: mediatek: Handle hardware enable and clock enable separately
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit 704d918341c378c5f9505dfdf32d315e256d3846 ]
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.
Stable-dep-of: f21d136caf81 ("pwm: mediatek: Fix duty and period setting")
--- drivers/pwm/pwm-mediatek.c | 60 +++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 32 deletions(-)
drivers/pwm/pwm-mediatek.c +28 -32
@@ -119,6 +119,26 @@ static inline void pwm_mediatek_writel(swritel (value, chip->regs + pwm_mediatek_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) {
@@ -181,35 +201,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) {
@@ -219,8 +210,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 ; }
@@ -229,8 +222,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 367/403 pwm: mediatek: Fix duty and period setting
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Uwe Kleine-König <[email protected]>
[ Upstream commit f21d136caf8171f94159d975ea4620c164431bd9 ]
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
@@ -168,7 +168,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,
@@ -191,9 +194,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);
@@ -222,11 +232,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 368/403 drm/dp: Change AUX DPCD probe address from DPCD_REV to LANE0_1_STATUS
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Imre Deak <[email protected]>
[ Upstream commit a40c5d727b8111b5db424a1e43e14a1dcce1e77f ]
Reading DPCD registers has side-effects in general. In particular accessing registers outside of the link training register range (0x102-0x106, 0x202-0x207, 0x200c-0x200f, 0x2216) is explicitly forbidden by the DP v2.1 Standard, see
3.6.5.1 DPTX AUX Transaction Handling Mandates 3.6.7.4 128b/132b DP Link Layer LTTPR Link Training Mandates
Based on my tests, accessing the DPCD_REV register during the link training of an UHBR TBT DP tunnel sink leads to link training failures.
Solve the above by using the DP_LANE0_1_STATUS (0x202) register for the DPCD register access quirk.
--- drivers/gpu/drm/drm_dp_helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_dp_helper.c +1 -1
@@ -280,7 +280,7 @@ ssize_t drm_dp_dpcd_read(struct drm_dp_a* We just have to do it before any DPCD access and hope that the * monitor doesn't power down exactly after the throw away read. */ - ret =drm_dp_dpcd_access (aux,DP_AUX_NATIVE_READ ,DP_DPCD_REV , buffer, + ret =drm_dp_dpcd_access (aux,DP_AUX_NATIVE_READ ,DP_LANE0_1_STATUS , buffer,1 );if (ret !=1 ) goto out;
Greg Kroah-Hartman
maintainerPATCH 369/403 media: venus: vdec: Clamp param smaller than 1fps and bigger than 240.
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ricardo Ribalda <[email protected]>
[ Upstream commit 377dc500d253f0b26732b2cb062e89668aef890a ]
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
@@ -16,6 +16,8 @@#define VIDC_CLKS_NUM_MAX 4 +#define VENUS_MAX_FPS 240 +struct freq_tbl {unsigned int load;unsigned long freq;
drivers/media/platform/qcom/venus/vdec.c +2 -3
@@ -418,11 +418,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 370/403 media: qcom: camss: cleanup media device allocated resource on error path
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladimir Zapolskiy <[email protected]>
[ Upstream commit 69080ec3d0daba8a894025476c98ab16b5a505a4 ]
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
@@ -888,7 +888,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_cleanup; + goto err_media_device_cleanup; } ret =camss_register_entities (camss);
@@ -945,6 +945,8 @@ err_register_subdevs:camss_unregister_entities (camss); err_register_entities:v4l2_device_unregister (&camss->v4l2_dev); +err_media_device_cleanup: +media_device_cleanup (&camss->media_dev); err_cleanup:v4l2_async_notifier_cleanup (&camss->notifier); err_free:
Greg Kroah-Hartman
maintainerPATCH 371/403 media: venus: protect against spurious interrupts during probe
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jorge Ramirez-Ortiz <[email protected]>
[ Upstream commit 3200144a2fa4209dc084a19941b9b203b43580f0 ]
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
@@ -267,13 +267,13 @@ static int venus_probe(struct platform_dmutex_init (&core->lock);INIT_DELAYED_WORK (&core->work, venus_sys_error_handler); - ret =devm_request_threaded_irq (dev, core->irq, hfi_isr, hfi_isr_thread, -IRQF_TRIGGER_HIGH |IRQF_ONESHOT , -"venus" , core); + ret =hfi_create (core, &venus_core_ops);if (ret)return ret; - ret =hfi_create (core, &venus_core_ops); + ret =devm_request_threaded_irq (dev, core->irq, hfi_isr, hfi_isr_thread, +IRQF_TRIGGER_HIGH |IRQF_ONESHOT , +"venus" , core);if (ret)return ret;
Greg Kroah-Hartman
maintainerPATCH 372/403 f2fs: fix to avoid out-of-boundary access in dnode page
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Chao Yu <[email protected]>
[ Upstream commit 77de19b6867f2740cdcb6c9c7e50d522b47847a4 ]
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
@@ -764,6 +764,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 (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 373/403 media: venus: hfi: explicitly release IRQ during teardown
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jorge Ramirez-Ortiz <[email protected]>
[ Upstream commit 640803003cd903cea73dc6a86bf6963e238e2b3f ]
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
@@ -1608,6 +1608,7 @@ void venus_hfi_destroy(struct venus_coremutex_destroy (&hdev->lock);kfree (hdev); core->priv =NULL ; +disable_irq (core->irq); core->ops =NULL ; }
Greg Kroah-Hartman
maintainerPATCH 374/403 btrfs: populate otime when logging an inode item
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Qu Wenruo <[email protected]>
[ Upstream commit 1ef94169db0958d6de39f9ea6e063ce887342e2d ]
[TEST FAILURE WITH EXPERIMENTAL FEATURES]
When running test case generic/508, the test case will fail with the new btrfs shutdown support:
generic/508 - output mismatch (see /home/adam/xfstests/results//generic/508.out.bad)
# --- tests/generic/508.out 2022-05-11 11:25:30.806666664 +0930 # +++ /home/adam/xfstests/results//generic/508.out.bad 2025-07-02 14:53:22.401824212 +0930 # @@ -1,2 +1,6 @@ # QA output created by 508 # Silence is golden # +Before: # +After : stat.btime = Thu Jan 1 09:30:00 1970 # +Before: # +After : stat.btime = Wed Jul 2 14:53:22 2025 # ... # (Run 'diff -u /home/adam/xfstests/tests/generic/508.out /home/adam/xfstests/results//generic/508.out.bad' to see the entire diff)
Ran: generic/508
Failures: generic/508
Failed 1 of 1 tests
Please note that the test case requires shutdown support, thus the test case will be skipped using the current upstream kernel, as it doesn't have shutdown ioctl support.
[CAUSE]
The direct cause the 0 time stamp in the log tree:
leaf 30507008 items 2 free space 16057 generation 9 owner TREE_LOG leaf 30507008 flags 0x1(WRITTEN) backref revision 1 checksum stored e522548d
checksum calced e522548d
fs uuid 57d45451-481e-43e4-aa93-289ad707a3a0
chunk uuid d52bd3fd-5163-4337-98a7-7986993ad398
item 0 key (257 INODE_ITEM 0) itemoff 16123 itemsize 160 generation 9 transid 9 size 0 nbytes 0 block group 0 mode 100644 links 1 uid 0 gid 0 rdev 0 sequence 1 flags 0x0(none) atime 1751432947.492000000 (2025-07-02 14:39:07) ctime 1751432947.492000000 (2025-07-02 14:39:07) mtime 1751432947.492000000 (2025-07-02 14:39:07) otime 0.0 (1970-01-01 09:30:00) <<<
But the old fs tree has all the correct time stamp:
btrfs-progs v6.12
fs tree key (FS_TREE ROOT_ITEM 0)
leaf 30425088 items 2 free space 16061 generation 5 owner FS_TREE leaf 30425088 flags 0x1(WRITTEN) backref revision 1 checksum stored 48f6c57e
checksum calced 48f6c57e
fs uuid 57d45451-481e-43e4-aa93-289ad707a3a0
chunk uuid d52bd3fd-5163-4337-98a7-7986993ad398
item 0 key (256 INODE_ITEM 0) itemoff 16123 itemsize 160 generation 3 transid 0 size 0 nbytes 16384 block group 0 mode 40755 links 1 uid 0 gid 0 rdev 0 sequence 0 flags 0x0(none) atime 1751432947.0 (2025-07-02 14:39:07) ctime 1751432947.0 (2025-07-02 14:39:07) mtime 1751432947.0 (2025-07-02 14:39:07) otime 1751432947.0 (2025-07-02 14:39:07) <<<
The root cause is that fill_inode_item() in tree-log.c is only populating a/c/m time, not the otime (or btime in statx output).
Part of the reason is that, the vfs inode only has a/c/m time, no native btime support yet.
[FIX]
Thankfully btrfs has its otime stored in btrfs_inode::i_otime_sec and btrfs_inode::i_otime_nsec.
So what we really need is just fill the otime time stamp in fill_inode_item() of tree-log.c
There is another fill_inode_item() in inode.c, which is doing the proper otime population.
--- fs/btrfs/tree-log.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/btrfs/tree-log.c +5 -0
@@ -3953,6 +3953,11 @@ static void fill_inode_item(struct btrfsbtrfs_set_token_timespec_nsec (leaf, &item->ctime, inode->i_ctime.tv_nsec, &token); +btrfs_set_token_timespec_sec (leaf, &item->otime, +BTRFS_I (inode)->i_otime.tv_sec, &token); +btrfs_set_token_timespec_nsec (leaf, &item->otime, +BTRFS_I (inode)->i_otime.tv_nsec, &token); +btrfs_set_token_inode_nbytes (leaf, item,inode_get_bytes (inode), &token);
Greg Kroah-Hartman
maintainerPATCH 375/403 sch_drr: make drr_qlen_notify() idempotent
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cong Wang <[email protected]>
commit df008598b3a00be02a8051fde89ca0fbc416bd55 upstream.
drr_qlen_notify() always deletes the DRR class from its active list with list_del(), therefore, it is not idempotent and not friendly to its callers, like fq_codel_dequeue().
Let's make it idempotent to ease qdisc_tree_reduce_backlog() callers' life. Also change other list_del()'s to list_del_init() just to be extra safe.
--- net/sched/sch_drr.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/sched/sch_drr.c +4 -3
@@ -111,6 +111,7 @@ static int drr_change_class(struct Qdiscif (cl ==NULL )return -ENOBUFS ; +INIT_LIST_HEAD (&cl->alist); cl->common.classid = classid; cl->quantum = quantum; cl->qdisc = qdisc_create_dflt(sch->dev_queue,
@@ -234,7 +235,7 @@ static void drr_qlen_notify(struct Qdisc {struct drr_class *cl = (struct drr_class *)arg; -list_del (&cl->alist); +list_del_init (&cl->alist); } static int drr_dump_class(struct Qdisc *sch, unsigned long arg,
@@ -401,7 +402,7 @@ static struct sk_buff *drr_dequeue(strucif (unlikely (skb ==NULL )) goto out;if (cl->qdisc->q.qlen ==0 ) -list_del (&cl->alist); +list_del_init (&cl->alist);bstats_update (&cl->bstats, skb);qdisc_bstats_update (sch, skb);
@@ -442,7 +443,7 @@ static void drr_reset_qdisc(struct Qdiscfor (i =0 ; i < q->clhash.hashsize; i++) {hlist_for_each_entry (cl, &q->clhash.hash[i], common.hnode) {if (cl->qdisc->q.qlen) -list_del (&cl->alist); +list_del_init (&cl->alist);qdisc_reset (cl->qdisc); } }
Greg Kroah-Hartman
maintainerPATCH 376/403 sch_hfsc: make hfsc_qlen_notify() idempotent
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cong Wang <[email protected]>
commit 51eb3b65544c9efd6a1026889ee5fb5aa62da3bb upstream.
hfsc_qlen_notify() is not idempotent either and not friendly to its callers, like fq_codel_dequeue(). Let's make it idempotent to ease qdisc_tree_reduce_backlog() callers' life:
1. update_vf() decreases cl->cl_nactive, so we can check whether it is non-zero before calling it.
2. eltree_remove() always removes RB node cl->el_node, but we can use RB_EMPTY_NODE() + RB_CLEAR_NODE() to make it safe.
--- net/sched/sch_hfsc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
net/sched/sch_hfsc.c +6 -2
@@ -209,7 +209,10 @@ eltree_insert(struct hfsc_class *cl)static inline void eltree_remove (struct hfsc_class *cl) { -rb_erase (&cl->el_node, &cl->sched->eligible); +if (!RB_EMPTY_NODE (&cl->el_node)) { +rb_erase (&cl->el_node, &cl->sched->eligible); +RB_CLEAR_NODE (&cl->el_node); + } } static inline void
@@ -1230,7 +1233,8 @@ hfsc_qlen_notify(struct Qdisc *sch, unsi/* vttree is now handled in update_vf() so that update_vf(cl, 0, 0) * needs to be called explicitly to remove a class from vttree. */ -update_vf (cl,0 ,0 ); +if (cl->cl_nactive) +update_vf (cl,0 ,0 );if (cl->cl_flags &HFSC_RSC )eltree_remove (cl); }
Greg Kroah-Hartman
maintainerPATCH 377/403 sch_qfq: make qfq_qlen_notify() idempotent
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cong Wang <[email protected]>
commit 55f9eca4bfe30a15d8656f915922e8c98b7f0728 upstream.
qfq_qlen_notify() always deletes its class from its active list with list_del_init() _and_ calls qfq_deactivate_agg() when the whole list becomes empty.
To make it idempotent, just skip everything when it is not in the active list.
Also change other list_del()'s to list_del_init() just to be extra safe.
--- net/sched/sch_qfq.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/sched/sch_qfq.c +5 -2
@@ -348,7 +348,7 @@ static void qfq_deactivate_class(structstruct qfq_aggregate *agg = cl->agg; -list_del (&cl->alist);/* remove from RR queue of the aggregate */ +list_del_init (&cl->alist);/* remove from RR queue of the aggregate */ if (list_empty (&agg->active))/* agg is now inactive */ qfq_deactivate_agg (q, agg); }
@@ -482,6 +482,7 @@ static int qfq_change_class(struct Qdisc cl->common.classid = classid; cl->deficit = lmax; +INIT_LIST_HEAD (&cl->alist); cl->qdisc =qdisc_create_dflt (sch->dev_queue, &pfifo_qdisc_ops, classid,NULL );
@@ -1001,7 +1002,7 @@ static struct sk_buff *agg_dequeue(struc cl->deficit -= (int ) len;if (cl->qdisc->q.qlen ==0 )/* no more packets, remove from list */ -list_del (&cl->alist); +list_del_init (&cl->alist);else if (cl->deficit <qdisc_pkt_len (cl->qdisc->ops->peek (cl->qdisc))) { cl->deficit += agg->lmax;list_move_tail (&cl->alist, &agg->active);
@@ -1433,6 +1434,8 @@ static void qfq_qlen_notify(struct Qdiscstruct qfq_sched *q =qdisc_priv (sch);struct qfq_class *cl = (struct qfq_class *)arg; +if (list_empty (&cl->alist)) +return ;qfq_deactivate_class (q, cl); }
Greg Kroah-Hartman
maintainerPATCH 378/403 codel: remove sch->q.qlen check before qdisc_tree_reduce_backlog()
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Cong Wang <[email protected]>
commit 342debc12183b51773b3345ba267e9263bdfaaef upstream.
After making all ->qlen_notify() callbacks idempotent, now it is safe to remove the check of qlen!=0 from both fq_codel_dequeue() and codel_qdisc_dequeue().
--- net/sched/sch_codel.c | 5 +---- net/sched/sch_fq_codel.c | 6 ++---- 2 files changed, 3 insertions(+), 8 deletions(-)
net/sched/sch_codel.c +1 -4
@@ -95,10 +95,7 @@ static struct sk_buff *codel_qdisc_deque &q->stats, qdisc_pkt_len, codel_get_enqueue_time, drop_func, dequeue_func); -/* We cant call qdisc_tree_reduce_backlog() if our qlen is 0, -* or HTB crashes. Defer it for next round. -*/ -if (q->stats.drop_count && sch->q.qlen) { +if (q->stats.drop_count) {qdisc_tree_reduce_backlog (sch, q->stats.drop_count, q->stats.drop_len); q->stats.drop_count =0 ; q->stats.drop_len =0 ;
net/sched/sch_fq_codel.c +2 -4
@@ -315,10 +315,8 @@ begin: }qdisc_bstats_update (sch, skb); flow->deficit -=qdisc_pkt_len (skb); -/* We cant call qdisc_tree_reduce_backlog() if our qlen is 0, -* or HTB crashes. Defer it for next round. -*/ -if (q->cstats.drop_count && sch->q.qlen) { + +if (q->cstats.drop_count) {qdisc_tree_reduce_backlog (sch, q->cstats.drop_count, q->cstats.drop_len); q->cstats.drop_count =0 ;
Greg Kroah-Hartman
maintainerPATCH 379/403 mm: drop the assumption that VM_SHARED always implies writable
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
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.
--- 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 | 10 +++++----- 6 files changed, 21 insertions(+), 10 deletions(-)
include/linux/fs.h +2 -2
@@ -430,7 +430,7 @@ int pagecache_write_end(struct file *, s* @host: Owner, either the inode or the block_device. * @i_pages: Cached pages. * @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.
@@ -553,7 +553,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_pgoff +* Note that i_mmap_writable counts all VM_SHARED, VM_MAYWRITE vmas: do_mmap_pgoff * 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
@@ -549,6 +549,17 @@ static inline bool vma_is_anonymous(strureturn !vma->vm_ops; } +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); +} +#ifdef CONFIG_SHMEM /* * The vma_is_shmem is not inline because it is used only by slow
kernel/fork.c +1 -1
@@ -566,7 +566,7 @@ static __latent_entropy int dup_mmap(strif (tmp->vm_flags &VM_DENYWRITE )atomic_dec (&inode->i_writecount);i_mmap_lock_write (mapping); -if (tmp->vm_flags &VM_SHARED ) +if (vma_is_shared_maywrite (tmp))atomic_inc (&mapping->i_mmap_writable);flush_dcache_mmap_lock (mapping);/* insert tmp into the share list, just after mpnt */
mm/filemap.c +1 -1
@@ -2876,7 +2876,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
@@ -839,7 +839,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 +5 -5
@@ -141,7 +141,7 @@ static void __remove_shared_vm_struct(st {if (vma->vm_flags &VM_DENYWRITE )atomic_inc (&file_inode (file)->i_writecount); -if (vma->vm_flags &VM_SHARED ) +if (vma_is_shared_maywrite (vma))mapping_unmap_writable (mapping);flush_dcache_mmap_lock (mapping);
@@ -619,7 +619,7 @@ static void __vma_link_file(struct vm_arif (vma->vm_flags &VM_DENYWRITE )atomic_dec (&file_inode (file)->i_writecount); -if (vma->vm_flags &VM_SHARED ) +if (vma_is_shared_maywrite (vma))atomic_inc (&mapping->i_mmap_writable);flush_dcache_mmap_lock (mapping);
@@ -1785,7 +1785,7 @@ unsigned long mmap_region(struct file *fif (error) goto free_vma; } -if (vm_flags &VM_SHARED ) { +if (is_shared_maywrite (vm_flags)) { error =mapping_map_writable (file->f_mapping);if (error) goto allow_write_and_free_vma;
@@ -1823,7 +1823,7 @@ unsigned long mmap_region(struct file *fvma_link (mm, vma, prev, rb_link, rb_parent);/* Once vma denies write, undo our temporary denial count */ if (file) { -if (vm_flags &VM_SHARED ) +if (is_shared_maywrite (vm_flags))mapping_unmap_writable (file->f_mapping);if (vm_flags &VM_DENYWRITE )allow_write_access (file);
@@ -1864,7 +1864,7 @@ unmap_and_free_vma:/* Undo any partial mapping done by a device driver. */ unmap_region (mm, vma, prev, vma->vm_start, vma->vm_end); -if (vm_flags &VM_SHARED ) +if (is_shared_maywrite (vm_flags))mapping_unmap_writable (file->f_mapping); allow_write_and_free_vma:if (vm_flags &VM_DENYWRITE )
Greg Kroah-Hartman
maintainerPATCH 380/403 mm: update memfd seal write check to include F_SEAL_WRITE
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
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
@@ -152,7 +152,7 @@ static int hugetlbfs_file_mmap(struct fi vma->vm_flags |=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
@@ -2946,25 +2946,26 @@ static inline int pages_identical(struct }/** -* 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
@@ -2215,7 +2215,7 @@ static int shmem_mmap(struct file *file,struct shmem_inode_info *info =SHMEM_I (file_inode (file));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 381/403 mm: perform the mapping_map_writable() check after call_mmap()
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Lorenzo Stoakes <[email protected]>
[ Upstream commit 158978945f3173b8c1a88f8c5684a629736a57ac ]
In order for a F_SEAL_WRITE sealed memfd mapping to have an opportunity to clear VM_MAYWRITE, we must be able to invoke the appropriate vm_ops->mmap() handler to do so. We would otherwise fail the mapping_map_writable() check before we had the opportunity to avoid it.
This patch moves this check after the call_mmap() invocation. Only memfd actively denies write access causing a potential failure here (in memfd_add_seals()), so there should be no impact on non-memfd cases.
This patch makes the userland-visible change that MAP_SHARED, PROT_READ mappings of an F_SEAL_WRITE sealed memfd mapping will now succeed.
There is a delicate situation with cleanup paths assuming that a writable mapping must have occurred in circumstances where it may now not have. In order to ensure we do not accidentally mark a writable file unwritable by mistake, we explicitly track whether we have a writable mapping and unmap only if we do.
[isaacmanjarres: added error handling to cleanup the work done by the mmap() callback and removed unused label.]
--- mm/mmap.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-)
mm/mmap.c +14 -8
@@ -1718,6 +1718,7 @@ unsigned long mmap_region(struct file *f {struct mm_struct *mm = current->mm;struct vm_area_struct *vma, *prev; +bool writable_file_mapping = false;int error;struct rb_node **rb_link, *rb_parent;unsigned long charged =0 ;
@@ -1785,11 +1786,6 @@ unsigned long mmap_region(struct file *fif (error) goto free_vma; } -if (is_shared_maywrite (vm_flags)) { - error =mapping_map_writable (file->f_mapping); -if (error) - goto allow_write_and_free_vma; - }/* ->mmap() can change vma->vm_file, but must guarantee that * vma_link() below can deny write-access if VM_DENYWRITE is set
@@ -1801,6 +1797,14 @@ unsigned long mmap_region(struct file *fif (error) goto unmap_and_free_vma; +if (vma_is_shared_maywrite (vma)) { + error =mapping_map_writable (file->f_mapping); +if (error) + goto close_and_free_vma; + + writable_file_mapping = true; + } +/* Can addr have changed?? * * Answer: Yes, several device drivers can do it in their
@@ -1823,7 +1827,7 @@ unsigned long mmap_region(struct file *fvma_link (mm, vma, prev, rb_link, rb_parent);/* Once vma denies write, undo our temporary denial count */ if (file) { -if (is_shared_maywrite (vm_flags)) +if (writable_file_mapping)mapping_unmap_writable (file->f_mapping);if (vm_flags &VM_DENYWRITE )allow_write_access (file);
@@ -1858,15 +1862,17 @@ out:return addr; +close_and_free_vma: +if (vma->vm_ops && vma->vm_ops->close) + vma->vm_ops->close (vma); unmap_and_free_vma: vma->vm_file =NULL ;fput (file);/* Undo any partial mapping done by a device driver. */ unmap_region (mm, vma, prev, vma->vm_start, vma->vm_end); -if (is_shared_maywrite (vm_flags)) +if (writable_file_mapping)mapping_unmap_writable (file->f_mapping); -allow_write_and_free_vma:if (vm_flags &VM_DENYWRITE )allow_write_access (file); free_vma:
Greg Kroah-Hartman
maintainerPATCH 382/403 net: sched: extract common action counters update code into function
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vlad Buslov <[email protected]>
[ Upstream commit c8ecebd04cbb6badb46d42fe54282e7883ed63cc ]
Currently, all implementations of tc_action_ops->stats_update() callback have almost exactly the same implementation of counters update code (besides gact which also updates drop counter). In order to simplify support for using both percpu-allocated and regular action counters depending on run-time flag in following patches, extract action counters update code into standalone function in act API.
This commit doesn't change functionality.
Stable-dep-of: ca22da2fbd69 ("act_mirred: use the backlog for nested calls to mirred ingress")
--- include/net/act_api.h | 2 ++ net/sched/act_api.c | 14 ++++++++++++++ net/sched/act_ct.c | 6 +----- net/sched/act_gact.c | 10 +--------- net/sched/act_mirred.c | 5 +---- net/sched/act_police.c | 5 +---- net/sched/act_vlan.c | 5 +---- 7 files changed, 21 insertions(+), 26 deletions(-)
include/net/act_api.h +2 -0
@@ -186,6 +186,8 @@ int tcf_action_dump(struct sk_buff *skb, int ref);int tcf_action_dump_old (struct sk_buff *skb,struct tc_action *a,int ,int );int tcf_action_dump_1 (struct sk_buff *skb,struct tc_action *a,int ,int ); +void tcf_action_update_stats (struct tc_action *a,u64 bytes,u32 packets, +bool drop,bool hw);int tcf_action_copy_stats (struct sk_buff *,struct tc_action *,int ); int tcf_action_check_ctrlact(int action, struct tcf_proto *tp,
net/sched/act_api.c +14 -0
@@ -1032,6 +1032,20 @@ err:return err; } +void tcf_action_update_stats (struct tc_action *a,u64 bytes,u32 packets, +bool drop,bool hw) +{ +_bstats_cpu_update (this_cpu_ptr (a->cpu_bstats), bytes, packets); + +if (drop) +this_cpu_ptr (a->cpu_qstats)->drops += packets; + +if (hw) +_bstats_cpu_update (this_cpu_ptr (a->cpu_bstats_hw), + bytes, packets); +} +EXPORT_SYMBOL (tcf_action_update_stats); +int tcf_action_copy_stats (struct sk_buff *skb,struct tc_action *p,int compat_mode) {
net/sched/act_ct.c +1 -5
@@ -917,11 +917,7 @@ static void tcf_stats_update(struct tc_a {struct tcf_ct *c =to_ct (a); -_bstats_cpu_update (this_cpu_ptr (a->cpu_bstats), bytes, packets); - -if (hw) -_bstats_cpu_update (this_cpu_ptr (a->cpu_bstats_hw), - bytes, packets); +tcf_action_update_stats (a, bytes, packets, false, hw); c->tcf_tm.lastuse =max_t (u64, c->tcf_tm.lastuse, lastuse); }
net/sched/act_gact.c +1 -9
@@ -175,15 +175,7 @@ static void tcf_gact_stats_update(structint action =READ_ONCE (gact->tcf_action);struct tcf_t *tm = &gact->tcf_tm; -_bstats_cpu_update (this_cpu_ptr (gact->common.cpu_bstats), bytes, - packets); -if (action ==TC_ACT_SHOT ) -this_cpu_ptr (gact->common.cpu_qstats)->drops += packets; - -if (hw) -_bstats_cpu_update (this_cpu_ptr (gact->common.cpu_bstats_hw), - bytes, packets); - +tcf_action_update_stats (a, bytes, packets, action ==TC_ACT_SHOT , hw); tm->lastuse =max_t (u64, tm->lastuse, lastuse); }
net/sched/act_mirred.c +1 -4
@@ -324,10 +324,7 @@ static void tcf_stats_update(struct tc_astruct tcf_mirred *m =to_mirred (a);struct tcf_t *tm = &m->tcf_tm; -_bstats_cpu_update (this_cpu_ptr (a->cpu_bstats), bytes, packets); -if (hw) -_bstats_cpu_update (this_cpu_ptr (a->cpu_bstats_hw), - bytes, packets); +tcf_action_update_stats (a, bytes, packets, false, hw); tm->lastuse =max_t (u64, tm->lastuse, lastuse); }
net/sched/act_police.c +1 -4
@@ -306,10 +306,7 @@ static void tcf_police_stats_update(strustruct tcf_police *police =to_police (a);struct tcf_t *tm = &police->tcf_tm; -_bstats_cpu_update (this_cpu_ptr (a->cpu_bstats), bytes, packets); -if (hw) -_bstats_cpu_update (this_cpu_ptr (a->cpu_bstats_hw), - bytes, packets); +tcf_action_update_stats (a, bytes, packets, false, hw); tm->lastuse =max_t (u64, tm->lastuse, lastuse); }
net/sched/act_vlan.c +1 -4
@@ -308,10 +308,7 @@ static void tcf_vlan_stats_update(structstruct tcf_vlan *v =to_vlan (a);struct tcf_t *tm = &v->tcf_tm; -_bstats_cpu_update (this_cpu_ptr (a->cpu_bstats), bytes, packets); -if (hw) -_bstats_cpu_update (this_cpu_ptr (a->cpu_bstats_hw), - bytes, packets); +tcf_action_update_stats (a, bytes, packets, false, hw); tm->lastuse =max_t (u64, tm->lastuse, lastuse); }
Greg Kroah-Hartman
maintainerPATCH 383/403 net: sched: extract bstats update code into function
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vlad Buslov <[email protected]>
[ Upstream commit 5e1ad95b630e652d3467d1fd1f0b5e5ea2c441e2 ]
Extract common code that increments cpu_bstats counter into standalone act API function. Change hardware offloaded actions that use percpu counter allocation to use the new function instead of incrementing cpu_bstats directly.
This commit doesn't change functionality.
Stable-dep-of: ca22da2fbd69 ("act_mirred: use the backlog for nested calls to mirred ingress")
--- include/net/act_api.h | 7 +++++++ net/sched/act_csum.c | 2 +- net/sched/act_ct.c | 2 +- net/sched/act_gact.c | 2 +- net/sched/act_mirred.c | 2 +- net/sched/act_tunnel_key.c | 2 +- net/sched/act_vlan.c | 2 +- 7 files changed, 13 insertions(+), 6 deletions(-)
include/net/act_api.h +7 -0
@@ -186,6 +186,13 @@ int tcf_action_dump(struct sk_buff *skb, int ref);int tcf_action_dump_old (struct sk_buff *skb,struct tc_action *a,int ,int );int tcf_action_dump_1 (struct sk_buff *skb,struct tc_action *a,int ,int ); + +static inline void tcf_action_update_bstats (struct tc_action *a, +struct sk_buff *skb) +{ +bstats_cpu_update (this_cpu_ptr (a->cpu_bstats), skb); +} +void tcf_action_update_stats (struct tc_action *a,u64 bytes,u32 packets,bool drop,bool hw);int tcf_action_copy_stats (struct sk_buff *,struct tc_action *,int );
net/sched/act_csum.c +1 -1
@@ -577,7 +577,7 @@ static int tcf_csum_act(struct sk_buff * params =rcu_dereference_bh (p->params);tcf_lastuse_update (&p->tcf_tm); -bstats_cpu_update (this_cpu_ptr (p->common.cpu_bstats), skb); +tcf_action_update_bstats (&p->common, skb); action =READ_ONCE (p->tcf_action);if (unlikely (action ==TC_ACT_SHOT ))
net/sched/act_ct.c +1 -1
@@ -482,7 +482,7 @@ out_push:skb_push_rcsum (skb, nh_ofs); out: -bstats_cpu_update (this_cpu_ptr (a->cpu_bstats), skb); +tcf_action_update_bstats (&c->common, skb);return retval; drop:
net/sched/act_gact.c +1 -1
@@ -159,7 +159,7 @@ static int tcf_gact_act(struct sk_buff * action = gact_rand[ptype](gact); }#endif -bstats_cpu_update (this_cpu_ptr (gact->common.cpu_bstats), skb); +tcf_action_update_bstats (&gact->common, skb);if (action ==TC_ACT_SHOT )qstats_drop_inc (this_cpu_ptr (gact->common.cpu_qstats));
net/sched/act_mirred.c +1 -1
@@ -233,7 +233,7 @@ static int tcf_mirred_act(struct sk_buff }tcf_lastuse_update (&m->tcf_tm); -bstats_cpu_update (this_cpu_ptr (m->common.cpu_bstats), skb); +tcf_action_update_bstats (&m->common, skb); m_mac_header_xmit =READ_ONCE (m->tcfm_mac_header_xmit); m_eaction =READ_ONCE (m->tcfm_eaction);
net/sched/act_tunnel_key.c +1 -1
@@ -31,7 +31,7 @@ static int tunnel_key_act(struct sk_buff params =rcu_dereference_bh (t->params);tcf_lastuse_update (&t->tcf_tm); -bstats_cpu_update (this_cpu_ptr (t->common.cpu_bstats), skb); +tcf_action_update_bstats (&t->common, skb); action =READ_ONCE (t->tcf_action);switch (params->tcft_action) {
net/sched/act_vlan.c +1 -1
@@ -29,7 +29,7 @@ static int tcf_vlan_act(struct sk_buff *u16 tci;tcf_lastuse_update (&v->tcf_tm); -bstats_cpu_update (this_cpu_ptr (v->common.cpu_bstats), skb); +tcf_action_update_bstats (&v->common, skb);/* Ensure 'data' points at mac_header prior calling vlan manipulating * functions.
Greg Kroah-Hartman
maintainerPATCH 384/403 net: sched: extract qstats update code into functions
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vlad Buslov <[email protected]>
[ Upstream commit 26b537a88ca5b7399c7ab0656e06dbd9da9513c1 ]
Extract common code that increments cpu_qstats counters into standalone act API functions. Change hardware offloaded actions that use percpu counter allocation to use the new functions instead of accessing cpu_qstats directly.
This commit doesn't change functionality.
Stable-dep-of: ca22da2fbd69 ("act_mirred: use the backlog for nested calls to mirred ingress")
--- include/net/act_api.h | 16 ++++++++++++++++ net/sched/act_csum.c | 2 +- net/sched/act_ct.c | 2 +- net/sched/act_gact.c | 2 +- net/sched/act_mirred.c | 2 +- net/sched/act_vlan.c | 2 +- 6 files changed, 21 insertions(+), 5 deletions(-)
include/net/act_api.h +16 -0
@@ -193,6 +193,22 @@ static inline void tcf_action_update_bstbstats_cpu_update (this_cpu_ptr (a->cpu_bstats), skb); } +static inline struct gnet_stats_queue * +tcf_action_get_qstats (struct tc_action *a) +{ +return this_cpu_ptr (a->cpu_qstats); +} + +static inline void tcf_action_inc_drop_qstats (struct tc_action *a) +{ +qstats_drop_inc (this_cpu_ptr (a->cpu_qstats)); +} + +static inline void tcf_action_inc_overlimit_qstats (struct tc_action *a) +{ +qstats_overlimit_inc (this_cpu_ptr (a->cpu_qstats)); +} +void tcf_action_update_stats (struct tc_action *a,u64 bytes,u32 packets,bool drop,bool hw);int tcf_action_copy_stats (struct sk_buff *,struct tc_action *,int );
net/sched/act_csum.c +1 -1
@@ -621,7 +621,7 @@ out:return action; drop: -qstats_drop_inc (this_cpu_ptr (p->common.cpu_qstats)); +tcf_action_inc_drop_qstats (&p->common); action =TC_ACT_SHOT ; goto out; }
net/sched/act_ct.c +1 -1
@@ -486,7 +486,7 @@ out:return retval; drop: -qstats_drop_inc (this_cpu_ptr (a->cpu_qstats)); +tcf_action_inc_drop_qstats (&c->common);return TC_ACT_SHOT ; }
net/sched/act_gact.c +1 -1
@@ -161,7 +161,7 @@ static int tcf_gact_act(struct sk_buff *#endif tcf_action_update_bstats (&gact->common, skb);if (action ==TC_ACT_SHOT ) -qstats_drop_inc (this_cpu_ptr (gact->common.cpu_qstats)); +tcf_action_inc_drop_qstats (&gact->common);tcf_lastuse_update (&gact->tcf_tm);
net/sched/act_mirred.c +1 -1
@@ -309,7 +309,7 @@ static int tcf_mirred_act(struct sk_buffif (err) { out: -qstats_overlimit_inc (this_cpu_ptr (m->common.cpu_qstats)); +tcf_action_inc_overlimit_qstats (&m->common);if (tcf_mirred_is_act_redirect (m_eaction)) retval =TC_ACT_SHOT ; }
net/sched/act_vlan.c +1 -1
@@ -88,7 +88,7 @@ out:return action; drop: -qstats_drop_inc (this_cpu_ptr (v->common.cpu_qstats)); +tcf_action_inc_drop_qstats (&v->common);return TC_ACT_SHOT ; }
Greg Kroah-Hartman
maintainerPATCH 385/403 net: sched: dont expose action qstats to skb_tc_reinsert()
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vlad Buslov <[email protected]>
[ Upstream commit ef816f3c49c1c404ababc50e10d4cbe5109da678 ]
Previous commit introduced helper function for updating qstats and refactored set of actions to use the helpers, instead of modifying qstats directly. However, one of the affected action exposes its qstats to skb_tc_reinsert(), which then modifies it.
Refactor skb_tc_reinsert() to return integer error code and don't increment overlimit qstats in case of error, and use the returned error code in tcf_mirred_act() to manually increment the overlimit counter with new helper function.
Stable-dep-of: ca22da2fbd69 ("act_mirred: use the backlog for nested calls to mirred ingress")
--- include/net/sch_generic.h | 12 ++---------- net/sched/act_mirred.c | 4 ++-- 2 files changed, 4 insertions(+), 12 deletions(-)
include/net/sch_generic.h +2 -10
@@ -1320,17 +1320,9 @@ void mini_qdisc_pair_swap(struct mini_Qdvoid mini_qdisc_pair_init (struct mini_Qdisc_pair *miniqp,struct Qdisc *qdisc,struct mini_Qdisc __rcu **p_miniq); -static inline void skb_tc_reinsert (struct sk_buff *skb,struct tcf_result *res) +static inline int skb_tc_reinsert (struct sk_buff *skb,struct tcf_result *res) { -struct gnet_stats_queue *stats = res->qstats; -int ret; - -if (res->ingress) - ret =netif_receive_skb (skb); -else - ret =dev_queue_xmit (skb); -if (ret && stats) -qstats_overlimit_inc (res->qstats); +return res->ingress ?netif_receive_skb (skb) :dev_queue_xmit (skb); }/* Make sure qdisc is no longer in SCHED state. */
net/sched/act_mirred.c +2 -2
@@ -295,8 +295,8 @@ static int tcf_mirred_act(struct sk_buff/* let's the caller reinsert the packet, if possible */ if (use_reinsert) { res->ingress = want_ingress; - res->qstats =this_cpu_ptr (m->common.cpu_qstats); -skb_tc_reinsert (skb, res); +if (skb_tc_reinsert (skb, res)) +tcf_action_inc_overlimit_qstats (&m->common);__this_cpu_dec (mirred_rec_level);return TC_ACT_CONSUMED ; }
Greg Kroah-Hartman
maintainerPATCH 386/403 selftests: forwarding: tc_actions.sh: add matchall mirror test
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jiri Pirko <[email protected]>
[ Upstream commit 075c8aa79d541ea08c67a2e6d955f6457e98c21c ]
Add test for matchall classifier with mirred egress mirror action.
Stable-dep-of: ca22da2fbd69 ("act_mirred: use the backlog for nested calls to mirred ingress")
--- tools/testing/selftests/net/forwarding/tc_actions.sh | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-)
tools/testing/selftests/net/forwarding/tc_actions.sh +18 -8
@@ -2,7 +2,8 @@ # SPDX-License-Identifier: GPL-2.0 ALL_TESTS="gact_drop_and_ok_test mirred_egress_redirect_test \ - mirred_egress_mirror_test gact_trap_test" + mirred_egress_mirror_test matchall_mirred_egress_mirror_test \ + gact_trap_test" NUM_NETIFS=4 source tc_common.sh source lib.sh
@@ -50,6 +51,9 @@ switch_destroy() mirred_egress_test() { local action=$1 + local protocol=$2 + local classifier=$3 + local classifier_args=$4 RET=0
@@ -62,9 +66,9 @@ mirred_egress_test() tc_check_packets "dev $h2 ingress" 101 1 check_fail $? "Matched without redirect rule inserted" - tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \ - $tcflags dst_ip 192.0.2.2 action mirred egress $action \ - dev $swp2 + tc filter add dev $swp1 ingress protocol $protocol pref 1 handle 101 \ + $classifier $tcflags $classifier_args \ + action mirred egress $action dev $swp2 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ -t ip -q
@@ -72,10 +76,11 @@ mirred_egress_test() tc_check_packets "dev $h2 ingress" 101 1 check_err $? "Did not match incoming $action packet" - tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower + tc filter del dev $swp1 ingress protocol $protocol pref 1 handle 101 \ + $classifier tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower - log_test "mirred egress $action ($tcflags)" + log_test "mirred egress $classifier $action ($tcflags)" } gact_drop_and_ok_test()
@@ -187,12 +192,17 @@ cleanup() mirred_egress_redirect_test() { - mirred_egress_test "redirect" + mirred_egress_test "redirect" "ip" "flower" "dst_ip 192.0.2.2" } mirred_egress_mirror_test() { - mirred_egress_test "mirror" + mirred_egress_test "mirror" "ip" "flower" "dst_ip 192.0.2.2" +} + +matchall_mirred_egress_mirror_test() +{ + mirred_egress_test "mirror" "all" "matchall" "" } trap cleanup EXIT
Greg Kroah-Hartman
maintainerPATCH 387/403 net/sched: act_mirred: refactor the handle of xmit
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: wenxu <[email protected]>
[ Upstream commit fa6d639930ee5cd3f932cc314f3407f07a06582d ]
This one is prepare for the next patch.
Stable-dep-of: ca22da2fbd69 ("act_mirred: use the backlog for nested calls to mirred ingress")
--- include/net/sch_generic.h | 5 ----- net/sched/act_mirred.c | 21 +++++++++++++++------ 2 files changed, 15 insertions(+), 11 deletions(-)
include/net/sch_generic.h +0 -5
@@ -1320,11 +1320,6 @@ void mini_qdisc_pair_swap(struct mini_Qdvoid mini_qdisc_pair_init (struct mini_Qdisc_pair *miniqp,struct Qdisc *qdisc,struct mini_Qdisc __rcu **p_miniq); -static inline int skb_tc_reinsert (struct sk_buff *skb,struct tcf_result *res) -{ -return res->ingress ?netif_receive_skb (skb) :dev_queue_xmit (skb); -} -/* Make sure qdisc is no longer in SCHED state. */ static inline void qdisc_synchronize (const struct Qdisc *q) {
net/sched/act_mirred.c +15 -6
@@ -206,6 +206,18 @@ release_idr:return err; } +static int tcf_mirred_forward (bool want_ingress,struct sk_buff *skb) +{ +int err; + +if (!want_ingress) + err =dev_queue_xmit (skb); +else + err =netif_receive_skb (skb); + +return err; +} +static int tcf_mirred_act (struct sk_buff *skb,const struct tc_action *a,struct tcf_result *res) {
@@ -295,18 +307,15 @@ static int tcf_mirred_act(struct sk_buff/* let's the caller reinsert the packet, if possible */ if (use_reinsert) { res->ingress = want_ingress; -if (skb_tc_reinsert (skb, res)) + err =tcf_mirred_forward (res->ingress, skb); +if (err)tcf_action_inc_overlimit_qstats (&m->common);__this_cpu_dec (mirred_rec_level);return TC_ACT_CONSUMED ; } } -if (!want_ingress) - err =dev_queue_xmit (skb2); -else - err =netif_receive_skb (skb2); - + err =tcf_mirred_forward (want_ingress, skb2);if (err) { out:tcf_action_inc_overlimit_qstats (&m->common);
Greg Kroah-Hartman
maintainerPATCH 388/403 net/sched: act_mirred: better wording on protection against excessive stack growth
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Davide Caratti <[email protected]>
[ Upstream commit 78dcdffe0418ac8f3f057f26fe71ccf4d8ed851f ]
with commit e2ca070f89ec ("net: sched: protect against stack overflow in TC act_mirred"), act_mirred protected itself against excessive stack growth using per_cpu counter of nested calls to tcf_mirred_act(), and capping it to MIRRED_RECURSION_LIMIT. However, such protection does not detect recursion/loops in case the packet is enqueued to the backlog (for example, when the mirred target device has RPS or skb timestamping enabled). Change the wording from "recursion" to "nesting" to make it more clear to readers.
Stable-dep-of: ca22da2fbd69 ("act_mirred: use the backlog for nested calls to mirred ingress")
--- net/sched/act_mirred.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
net/sched/act_mirred.c +8 -8
@@ -28,8 +28,8 @@static LIST_HEAD (mirred_list);static DEFINE_SPINLOCK (mirred_list_lock); -#define MIRRED_RECURSION_LIMIT 4 -static DEFINE_PER_CPU(unsigned int, mirred_rec_level); +#define MIRRED_NEST_LIMIT 4 +static DEFINE_PER_CPU(unsigned int, mirred_nest_level);static bool tcf_mirred_is_act_redirect (int action) {
@@ -225,7 +225,7 @@ static int tcf_mirred_act(struct sk_buffstruct sk_buff *skb2 = skb;bool m_mac_header_xmit;struct net_device *dev; -unsigned int rec_level; +unsigned int nest_level;int retval, err =0 ;bool use_reinsert;bool want_ingress;
@@ -236,11 +236,11 @@ static int tcf_mirred_act(struct sk_buffint mac_len;bool at_nh; - rec_level =__this_cpu_inc_return (mirred_rec_level); -if (unlikely (rec_level >MIRRED_RECURSION_LIMIT )) { + nest_level =__this_cpu_inc_return (mirred_nest_level); +if (unlikely (nest_level >MIRRED_NEST_LIMIT )) {net_warn_ratelimited ("Packet exceeded mirred recursion limit on dev %s\n" ,netdev_name (skb->dev)); -__this_cpu_dec (mirred_rec_level); +__this_cpu_dec (mirred_nest_level);return TC_ACT_SHOT ; }
@@ -310,7 +310,7 @@ static int tcf_mirred_act(struct sk_buff err =tcf_mirred_forward (res->ingress, skb);if (err)tcf_action_inc_overlimit_qstats (&m->common); -__this_cpu_dec (mirred_rec_level); +__this_cpu_dec (mirred_nest_level);return TC_ACT_CONSUMED ; } }
@@ -322,7 +322,7 @@ out:if (tcf_mirred_is_act_redirect (m_eaction)) retval =TC_ACT_SHOT ; } -__this_cpu_dec (mirred_rec_level); +__this_cpu_dec (mirred_nest_level);return retval; }
Greg Kroah-Hartman
maintainerPATCH 389/403 act_mirred: use the backlog for nested calls to mirred ingress
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Davide Caratti <[email protected]>
[ Upstream commit ca22da2fbd693b54dc8e3b7b54ccc9f7e9ba3640 ]
William reports kernel soft-lockups on some OVS topologies when TC mirred egress->ingress action is hit by local TCP traffic [1].
The same can also be reproduced with SCTP (thanks Xin for verifying), when client and server reach themselves through mirred egress to ingress, and one of the two peers sends a "heartbeat" packet (from within a timer).
Enqueueing to backlog proved to fix this soft lockup; however, as Cong noticed [2], we should preserve - when possible - the current mirred behavior that counts as "overlimits" any eventual packet drop subsequent to the mirred forwarding action [3]. A compromise solution might use the backlog only when tcf_mirred_act() has a nest level greater than one:
change tcf_mirred_forward() accordingly.
Also, add a kselftest that can reproduce the lockup and verifies TC mirred ability to account for further packet drops after TC mirred egress->ingress (when the nest level is 1).
[1] https://lore.kernel.org/netdev/33dc43f587ec1388ba456b4915c75f02a8aae226.1663945716.git.dcaratti@redhat.com/
[2] https://lore.kernel.org/netdev/Y0w%[email protected]/
[3] such behavior is not guaranteed: for example, if RPS or skb RX
timestamping is enabled on the mirred target device, the kernel
can defer receiving the skb and return NET_RX_SUCCESS inside
tcf_mirred_forward().
--- net/sched/act_mirred.c | 7 ++ tools/testing/selftests/net/forwarding/tc_actions.sh | 48 ++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-)
net/sched/act_mirred.c +7 -0
@@ -206,12 +206,19 @@ release_idr:return err; } +static bool is_mirred_nested (void ) +{ +return unlikely (__this_cpu_read (mirred_nest_level) >1 ); +} +static int tcf_mirred_forward (bool want_ingress,struct sk_buff *skb) {int err;if (!want_ingress) err =dev_queue_xmit (skb); +else if (is_mirred_nested ()) + err =netif_rx (skb);else err =netif_receive_skb (skb);
tools/testing/selftests/net/forwarding/tc_actions.sh +47 -1
60 lines not on this page · raw message
Greg Kroah-Hartman
maintainerPATCH 390/403 Bluetooth: fix use-after-free in device_for_each_child()
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dmitry Antipov <[email protected]>
commit 27aabf27fd014ae037cc179c61b0bee7cff55b3d upstream.
Syzbot has reported the following KASAN splat:
BUG: KASAN: slab-use-after-free in device_for_each_child+0x18f/0x1a0 Read of size 8 at addr ffff88801f605308 by task kbnepd bnep0/4980 CPU: 0 UID: 0 PID: 4980 Comm: kbnepd bnep0 Not tainted 6.12.0-rc4-00161-gae90f6a6170d #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.3-2.fc40 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0x100/0x190 ? device_for_each_child+0x18f/0x1a0 print_report+0x13a/0x4cb ? __virt_addr_valid+0x5e/0x590 ? __phys_addr+0xc6/0x150 ? device_for_each_child+0x18f/0x1a0 kasan_report+0xda/0x110 ? device_for_each_child+0x18f/0x1a0 ? __pfx_dev_memalloc_noio+0x10/0x10 device_for_each_child+0x18f/0x1a0 ? __pfx_device_for_each_child+0x10/0x10 pm_runtime_set_memalloc_noio+0xf2/0x180 netdev_unregister_kobject+0x1ed/0x270 unregister_netdevice_many_notify+0x123c/0x1d80 ? __mutex_trylock_common+0xde/0x250 ? __pfx_unregister_netdevice_many_notify+0x10/0x10 ? trace_contention_end+0xe6/0x140 ? __mutex_lock+0x4e7/0x8f0 ? __pfx_lock_acquire.part.0+0x10/0x10 ? rcu_is_watching+0x12/0xc0 ? unregister_netdev+0x12/0x30 unregister_netdevice_queue+0x30d/0x3f0 ? __pfx_unregister_netdevice_queue+0x10/0x10 ? __pfx_down_write+0x10/0x10 unregister_netdev+0x1c/0x30 bnep_session+0x1fb3/0x2ab0 ? __pfx_bnep_session+0x10/0x10 ? __pfx_lock_release+0x10/0x10 ? __pfx_woken_wake_function+0x10/0x10 ? __kthread_parkme+0x132/0x200 ? __pfx_bnep_session+0x10/0x10 ? kthread+0x13a/0x370 ? __pfx_bnep_session+0x10/0x10 kthread+0x2b7/0x370 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x48/0x80 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x1a/0x30 </TASK> Allocated by task 4974: kasan_save_stack+0x30/0x50 kasan_save_track+0x14/0x30 __kasan_kmalloc+0xaa/0xb0 __kmalloc_noprof+0x1d1/0x440 hci_alloc_dev_priv+0x1d/0x2820 __vhci_create_device+0xef/0x7d0 vhci_write+0x2c7/0x480 vfs_write+0x6a0/0xfc0 ksys_write+0x12f/0x260 do_syscall_64+0xc7/0x250 entry_SYSCALL_64_after_hwframe+0x77/0x7f Freed by task 4979: kasan_save_stack+0x30/0x50 kasan_save_track+0x14/0x30 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x4f/0x70 kfree+0x141/0x490 hci_release_dev+0x4d9/0x600 bt_host_release+0x6a/0xb0 device_release+0xa4/0x240 kobject_put+0x1ec/0x5a0 put_device+0x1f/0x30 vhci_release+0x81/0xf0 __fput+0x3f6/0xb30 task_work_run+0x151/0x250 do_exit+0xa79/0x2c30 do_group_exit+0xd5/0x2a0 get_signal+0x1fcd/0x2210 arch_do_signal_or_restart+0x93/0x780 syscall_exit_to_user_mode+0x140/0x290 do_syscall_64+0xd4/0x250 entry_SYSCALL_64_after_hwframe+0x77/0x7f
In 'hci_conn_del_sysfs()', 'device_unregister()' may be called when an underlying (kobject) reference counter is greater than 1. This means that reparenting (happened when the device is actually freed) is delayed and, during that delay, parent controller device (hciX) may be deleted. Since the latter may create a dangling pointer to freed parent, avoid that scenario by reparenting to NULL explicitly.
[ chanho: Backported from v5.10.y to v5.4.y. device_find_any_child() is not supported in v5.4.y, so changed to use device_find_child() with __match_any ]
--- net/bluetooth/hci_sysfs.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-)
net/bluetooth/hci_sysfs.c +6 -9
@@ -19,14 +19,9 @@ static const struct device_type bt_link .release = bt_link_release, }; -/* -* The rfcomm tty device will possibly retain even when conn -* is down, and sysfs doesn't support move zombie device, -* so we should move the device before conn device is destroyed. -*/ -static int __match_tty (struct device *dev,void *data) +static int __match_any (struct device *dev,void *unused) { -return !strncmp (dev_name (dev),"rfcomm" ,6 ); +return 1 ; }void hci_conn_init_sysfs (struct hci_conn *conn)
@@ -71,10 +66,12 @@ void hci_conn_del_sysfs(struct hci_connreturn ; } +/* If there are devices using the connection as parent reset it to NULL +* before unregistering the device. +*/ while (1 ) {struct device *dev; - - dev =device_find_child (&conn->dev,NULL , __match_tty); + dev =device_find_child (&conn->dev,NULL , __match_any);if (!dev)break ;device_move (dev,NULL ,DPM_ORDER_DEV_LAST );
Greg Kroah-Hartman
maintainerPATCH 391/403 cifs: Fix UAF in cifs_demultiplex_thread()
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Zhang Xiaoxu <[email protected]>
commit d527f51331cace562393a8038d870b3e9916686f upstream.
There is a UAF when xfstests on cifs:
BUG: KASAN: use-after-free in smb2_is_network_name_deleted+0x27/0x160 Read of size 4 at addr ffff88810103fc08 by task cifsd/923 CPU: 1 PID: 923 Comm: cifsd Not tainted 6.1.0-rc4+ #45 ... Call Trace: <TASK> dump_stack_lvl+0x34/0x44 print_report+0x171/0x472 kasan_report+0xad/0x130 kasan_check_range+0x145/0x1a0 smb2_is_network_name_deleted+0x27/0x160 cifs_demultiplex_thread.cold+0x172/0x5a4 kthread+0x165/0x1a0 ret_from_fork+0x1f/0x30 </TASK> Allocated by task 923: kasan_save_stack+0x1e/0x40 kasan_set_track+0x21/0x30 __kasan_slab_alloc+0x54/0x60 kmem_cache_alloc+0x147/0x320 mempool_alloc+0xe1/0x260 cifs_small_buf_get+0x24/0x60 allocate_buffers+0xa1/0x1c0 cifs_demultiplex_thread+0x199/0x10d0 kthread+0x165/0x1a0 ret_from_fork+0x1f/0x30 Freed by task 921: kasan_save_stack+0x1e/0x40 kasan_set_track+0x21/0x30 kasan_save_free_info+0x2a/0x40 ____kasan_slab_free+0x143/0x1b0 kmem_cache_free+0xe3/0x4d0 cifs_small_buf_release+0x29/0x90 SMB2_negotiate+0x8b7/0x1c60 smb2_negotiate+0x51/0x70 cifs_negotiate_protocol+0xf0/0x160 cifs_get_smb_ses+0x5fa/0x13c0 mount_get_conns+0x7a/0x750 cifs_mount+0x103/0xd00 cifs_smb3_do_mount+0x1dd/0xcb0 smb3_get_tree+0x1d5/0x300 vfs_get_tree+0x41/0xf0 path_mount+0x9b3/0xdd0 __x64_sys_mount+0x190/0x1d0 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x46/0xb0
The UAF is because:
mount(pid: 921) | cifsd(pid: 923)
-------------------------------|-------------------------------
| cifs_demultiplex_thread
SMB2_negotiate |
cifs_send_recv |
compound_send_recv |
smb_send_rqst |
wait_for_response |
wait_event_state [1] |
| standard_receive3
| cifs_handle_standard
| handle_mid
| mid->resp_buf = buf; [2]
| dequeue_mid [3]
KILL the process [4] |
resp_iov[i].iov_base = buf |
free_rsp_buf [5] |
| is_network_name_deleted [6]
| callback1. After send request to server, wait the response until
mid->mid_state != SUBMITTED;
2. Receive response from server, and set it to mid;
3. Set the mid state to RECEIVED;
4. Kill the process, the mid state already RECEIVED, get 0;
5. Handle and release the negotiate response;
6. UAF.
It can be easily reproduce with add some delay in [3] - [6].
Only sync call has the problem since async call's callback is executed in cifsd process.
Add an extra state to mark the mid state to READY before wakeup the waitter, then it can get the resp safely.
[fs/cifs was moved to fs/smb/client since38c8a9a52082 ("smb: move client and server files to common directory fs/smb"). We apply the patch to fs/cifs with some minor context changes.]
--- fs/cifs/cifsglob.h | 1 + fs/cifs/transport.c | 34 +++++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-)
fs/cifs/cifsglob.h +1 -0
@@ -1722,6 +1722,7 @@ static inline bool is_retryable_error(in#define MID_RETRY_NEEDED 8/* session closed while this request out */ #define MID_RESPONSE_MALFORMED 0x10#define MID_SHUTDOWN 0x20 +#define MID_RESPONSE_READY 0x40/* ready for other process handle the rsp */ /* Flags */ #define MID_WAIT_CANCELLED 1/* Cancelled while waiting for response */
fs/cifs/transport.c +23 -11
@@ -47,6 +47,8 @@void cifs_wake_up_task (struct mid_q_entry *mid) { +if (mid->mid_state ==MID_RESPONSE_RECEIVED ) + mid->mid_state =MID_RESPONSE_READY ;wake_up_process (mid->callback_data); }
@@ -99,7 +101,8 @@ static void _cifs_mid_q_entry_release(ststruct TCP_Server_Info *server = midEntry->server;if (midEntry->resp_buf && (midEntry->mid_flags &MID_WAIT_CANCELLED ) && - midEntry->mid_state ==MID_RESPONSE_RECEIVED && + (midEntry->mid_state ==MID_RESPONSE_RECEIVED || + midEntry->mid_state ==MID_RESPONSE_READY ) && server->ops->handle_cancelled_mid) server->ops->handle_cancelled_mid (midEntry->resp_buf, server);
@@ -737,7 +740,8 @@ wait_for_response(struct TCP_Server_Infoint error; error =wait_event_freezekillable_unsafe (server->response_q, - midQ->mid_state !=MID_REQUEST_SUBMITTED ); + midQ->mid_state !=MID_REQUEST_SUBMITTED && + midQ->mid_state !=MID_RESPONSE_RECEIVED );if (error <0 )return -ERESTARTSYS ;
@@ -889,7 +893,7 @@ cifs_sync_mid_result(struct mid_q_entryspin_lock (&GlobalMid_Lock);switch (mid->mid_state) { -case MID_RESPONSE_RECEIVED : +case MID_RESPONSE_READY :spin_unlock (&GlobalMid_Lock);return rc;case MID_RETRY_NEEDED :
@@ -987,6 +991,9 @@ cifs_compound_callback(struct mid_q_entr credits.instance = server->reconnect_instance;add_credits (server, &credits, mid->optype); + +if (mid->mid_state ==MID_RESPONSE_RECEIVED ) + mid->mid_state =MID_RESPONSE_READY ; } static void
@@ -1150,7 +1157,8 @@ compound_send_recv(const unsigned int xisend_cancel (server, &rqst[i], midQ[i]);spin_lock (&GlobalMid_Lock); midQ[i]->mid_flags |=MID_WAIT_CANCELLED ; -if (midQ[i]->mid_state ==MID_REQUEST_SUBMITTED ) { +if (midQ[i]->mid_state ==MID_REQUEST_SUBMITTED || + midQ[i]->mid_state ==MID_RESPONSE_RECEIVED ) { midQ[i]->callback = cifs_cancelled_callback; cancelled_mid[i] = true; credits[i].value =0 ;
@@ -1171,7 +1179,7 @@ compound_send_recv(const unsigned int xi }if (!midQ[i]->resp_buf || - midQ[i]->mid_state !=MID_RESPONSE_RECEIVED ) { + midQ[i]->mid_state !=MID_RESPONSE_READY ) { rc = -EIO ;cifs_dbg (FYI ,"Bad MID state?\n" ); goto out;
@@ -1348,7 +1356,8 @@ SendReceive(const unsigned int xid, struif (rc !=0 ) {send_cancel (server, &rqst, midQ);spin_lock (&GlobalMid_Lock); -if (midQ->mid_state ==MID_REQUEST_SUBMITTED ) { +if (midQ->mid_state ==MID_REQUEST_SUBMITTED || + midQ->mid_state ==MID_RESPONSE_RECEIVED ) {/* no longer considered to be "in-flight" */ midQ->callback = DeleteMidQEntry;spin_unlock (&GlobalMid_Lock);
@@ -1365,7 +1374,7 @@ SendReceive(const unsigned int xid, stru }if (!midQ->resp_buf || !out_buf || - midQ->mid_state !=MID_RESPONSE_RECEIVED ) { + midQ->mid_state !=MID_RESPONSE_READY ) { rc = -EIO ;cifs_server_dbg (VFS ,"Bad MID state?\n" ); goto out;
@@ -1485,13 +1494,15 @@ SendReceiveBlockingLock(const unsigned i/* Wait for a reply - allow signals to interrupt. */ rc =wait_event_interruptible (server->response_q, - (!(midQ->mid_state ==MID_REQUEST_SUBMITTED )) || + (!(midQ->mid_state ==MID_REQUEST_SUBMITTED || + midQ->mid_state ==MID_RESPONSE_RECEIVED )) || ((server->tcpStatus != CifsGood) && (server->tcpStatus != CifsNew)));/* Were we interrupted by a signal ? */ if ((rc == -ERESTARTSYS ) && - (midQ->mid_state ==MID_REQUEST_SUBMITTED ) && + (midQ->mid_state ==MID_REQUEST_SUBMITTED || + midQ->mid_state ==MID_RESPONSE_RECEIVED ) && ((server->tcpStatus == CifsGood) || (server->tcpStatus == CifsNew))) {
@@ -1521,7 +1532,8 @@ SendReceiveBlockingLock(const unsigned iif (rc) {send_cancel (server, &rqst, midQ);spin_lock (&GlobalMid_Lock); -if (midQ->mid_state ==MID_REQUEST_SUBMITTED ) { +if (midQ->mid_state ==MID_REQUEST_SUBMITTED || + midQ->mid_state ==MID_RESPONSE_RECEIVED ) {/* no longer considered to be "in-flight" */ midQ->callback = DeleteMidQEntry;spin_unlock (&GlobalMid_Lock);
@@ -1539,7 +1551,7 @@ SendReceiveBlockingLock(const unsigned ireturn rc;/* rcvd frame is ok */ -if (out_buf ==NULL || midQ->mid_state !=MID_RESPONSE_RECEIVED ) { +if (out_buf ==NULL || midQ->mid_state !=MID_RESPONSE_READY ) { rc = -EIO ;cifs_tcon_dbg (VFS ,"Bad MID state?\n" ); goto out;
Greg Kroah-Hartman
maintainerPATCH 392/403 NFS: Fix up commit deadlocks
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Trond Myklebust <[email protected]>
commit 133a48abf6ecc535d7eddc6da1c3e4c972445882 upstream.
If O_DIRECT bumps the commit_info rpcs_out field, then that could lead to fsync() hangs. The fix is to ensure that O_DIRECT calls nfs_commit_end().
--- fs/nfs/direct.c | 2 +- fs/nfs/write.c | 9 ++++++--- include/linux/nfs_fs.h | 1 + 3 files changed, 8 insertions(+), 4 deletions(-)
fs/nfs/direct.c +1 -1
@@ -700,7 +700,7 @@ static void nfs_direct_commit_complete(snfs_unlock_and_release_request (req); } -if (atomic_dec_and_test (&cinfo.mds->rpcs_out)) +if (nfs_commit_end (cinfo.mds))nfs_direct_write_complete (dreq); }
fs/nfs/write.c +6 -3
@@ -1658,10 +1658,13 @@ static void nfs_commit_begin(struct nfs_atomic_inc (&cinfo->rpcs_out); } -static void nfs_commit_end (struct nfs_mds_commit_info *cinfo) +bool nfs_commit_end (struct nfs_mds_commit_info *cinfo) { -if (atomic_dec_and_test (&cinfo->rpcs_out)) +if (atomic_dec_and_test (&cinfo->rpcs_out)) {wake_up_var (&cinfo->rpcs_out); +return true; + } +return false; }void nfs_commitdata_release (struct nfs_commit_data *data)
@@ -1756,6 +1759,7 @@ void nfs_init_commit(struct nfs_commit_d data->res.fattr = &data->fattr; data->res.verf = &data->verf;nfs_fattr_init (&data->fattr); +nfs_commit_begin (cinfo->mds); }EXPORT_SYMBOL_GPL (nfs_init_commit);
@@ -1801,7 +1805,6 @@ nfs_commit_list(struct inode *inode, str/* Set up the argument struct */ nfs_init_commit (data, head,NULL , cinfo); -atomic_inc (&cinfo->mds->rpcs_out);return nfs_initiate_commit (NFS_CLIENT (inode), data,NFS_PROTO (inode), data->mds_ops, how,0 ); }
include/linux/nfs_fs.h +1 -0
@@ -549,6 +549,7 @@ extern int nfs_wb_page_cancel(struct inoextern int nfs_commit_inode (struct inode *,int );extern struct nfs_commit_data *nfs_commitdata_alloc (bool never_fail);extern void nfs_commit_free (struct nfs_commit_data *data); +bool nfs_commit_end (struct nfs_mds_commit_info *cinfo);static inline int nfs_have_writebacks (struct inode *inode)
Greg Kroah-Hartman
maintainerPATCH 393/403 nfs: fix UAF in direct writes
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Josef Bacik <[email protected]>
commit 17f46b803d4f23c66cacce81db35fef3adb8f2af upstream.
In production we have been hitting the following warning consistently
------------[ cut here ]------------ refcount_t: underflow; use-after-free. WARNING: CPU: 17 PID: 1800359 at lib/refcount.c:28 refcount_warn_saturate+0x9c/0xe0 Workqueue: nfsiod nfs_direct_write_schedule_work [nfs] RIP: 0010:refcount_warn_saturate+0x9c/0xe0 PKRU: 55555554 Call Trace: <TASK> ? __warn+0x9f/0x130 ? refcount_warn_saturate+0x9c/0xe0 ? report_bug+0xcc/0x150 ? handle_bug+0x3d/0x70 ? exc_invalid_op+0x16/0x40 ? asm_exc_invalid_op+0x16/0x20 ? refcount_warn_saturate+0x9c/0xe0 nfs_direct_write_schedule_work+0x237/0x250 [nfs] process_one_work+0x12f/0x4a0 worker_thread+0x14e/0x3b0 ? ZSTD_getCParams_internal+0x220/0x220 kthread+0xdc/0x120 ? __btf_name_valid+0xa0/0xa0 ret_from_fork+0x1f/0x30
This is because we're completing the nfs_direct_request twice in a row.
The source of this is when we have our commit requests to submit, we process them and send them off, and then in the completion path for the commit requests we have
if (nfs_commit_end(cinfo.mds))
nfs_direct_write_complete(dreq);
However since we're submitting asynchronous requests we sometimes have one that completes before we submit the next one, so we end up calling complete on the nfs_direct_request twice.
The only other place we use nfs_generic_commit_list() is in __nfs_commit_inode, which wraps this call in a
nfs_commit_begin();nfs_commit_end();
Which is a common pattern for this style of completion handling, one that is also repeated in the direct code with get_dreq()/put_dreq() calls around where we process events as well as in the completion paths.
Fix this by using the same pattern for the commit requests.
Before with my 200 node rocksdb stress running this warning would pop every 10ish minutes. With my patch the stress test has been running for several hours without popping.
[ chanho : Backports v5.4.y, commit 133a48abf6ec (NFS: Fix up commit deadlocks)
is needed to use nfs_commit_end ]
--- fs/nfs/direct.c | 11 +++++++++-- fs/nfs/write.c | 2 +- include/linux/nfs_fs.h | 1 + 3 files changed, 11 insertions(+), 3 deletions(-)
fs/nfs/direct.c +9 -2
@@ -727,10 +727,17 @@ static void nfs_direct_commit_schedule(sLIST_HEAD (mds_list);nfs_init_cinfo_from_dreq (&cinfo, dreq); +nfs_commit_begin (cinfo.mds);nfs_scan_commit (dreq->inode, &mds_list, &cinfo); res =nfs_generic_commit_list (dreq->inode, &mds_list,0 , &cinfo); -if (res <0 )/* res == -ENOMEM */ -nfs_direct_write_reschedule (dreq); +if (res <0 ) {/* res == -ENOMEM */ +spin_lock (&dreq->lock); +if (dreq->flags ==0 ) + dreq->flags =NFS_ODIRECT_RESCHED_WRITES ; +spin_unlock (&dreq->lock); + } +if (nfs_commit_end (cinfo.mds)) +nfs_direct_write_complete (dreq); }static void nfs_direct_write_schedule_work (struct work_struct *work)
fs/nfs/write.c +1 -1
@@ -1653,7 +1653,7 @@ static int wait_on_commit(struct nfs_mds !atomic_read(&cinfo->rpcs_out)); } -static void nfs_commit_begin (struct nfs_mds_commit_info *cinfo) +void nfs_commit_begin (struct nfs_mds_commit_info *cinfo) {atomic_inc (&cinfo->rpcs_out); }
include/linux/nfs_fs.h +1 -0
@@ -549,6 +549,7 @@ extern int nfs_wb_page_cancel(struct inoextern int nfs_commit_inode (struct inode *,int );extern struct nfs_commit_data *nfs_commitdata_alloc (bool never_fail);extern void nfs_commit_free (struct nfs_commit_data *data); +void nfs_commit_begin (struct nfs_mds_commit_info *cinfo);bool nfs_commit_end (struct nfs_mds_commit_info *cinfo); static inline int
Greg Kroah-Hartman
maintainerPATCH 394/403 usb: xhci: Fix slot_id resource race conflict
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Weitao Wang <[email protected]>
commit 2eb03376151bb8585caa23ed2673583107bb5193 upstream.
xHC controller may immediately reuse a slot_id after it's disabled, giving it to a new enumerating device before the xhci driver freed all resources related to the disabled device.
In such a scenario, device-A with slot_id equal to 1 is disconnecting while device-B is enumerating, device-B will fail to enumerate in the follow sequence.
1.[device-A] send disable slot command
2.[device-B] send enable slot command
3.[device-A] disable slot command completed and wakeup waiting thread 4.[device-B] enable slot command completed with slot_id equal to 1 and
wakeup waiting thread
5.[device-B] driver checks that slot_id is still in use (by device-A) in
xhci_alloc_virt_device, and fail to enumerate due to this conflict
6.[device-A] xhci->devs[slot_id] set to NULL in xhci_free_virt_device
To fix driver's slot_id resources conflict, clear xhci->devs[slot_id] and xhci->dcbba->dev_context_ptrs[slot_id] pointers in the interrupt context when disable slot command completes successfully. Simultaneously, adjust function xhci_free_virt_device to accurately handle device release.
[minor smatch warning and commit message fix -Mathias]
--- drivers/usb/host/xhci-hub.c | 3 +-- drivers/usb/host/xhci-mem.c | 22 +++++++++++----------- drivers/usb/host/xhci-ring.c | 9 +++++++-- drivers/usb/host/xhci.c | 18 +++++++++++++----- drivers/usb/host/xhci.h | 3 ++- 5 files changed, 34 insertions(+), 21 deletions(-)
drivers/usb/host/xhci-hub.c +1 -2
@@ -628,8 +628,7 @@ static int xhci_enter_test_mode(struct xif (!xhci->devs[i])continue ; - retval =xhci_disable_slot (xhci, i); -xhci_free_virt_device (xhci, i); + retval =xhci_disable_and_free_slot (xhci, i);if (retval)xhci_err (xhci,"Failed to disable slot %d, %d. Enter test mode anyway\n" , i, retval);
drivers/usb/host/xhci-mem.c +11 -11
@@ -879,21 +879,20 @@ free_tts:* will be manipulated by the configure endpoint, allocate device, or update * hub functions while this function is removing the TT entries from the list. */ -void xhci_free_virt_device (struct xhci_hcd *xhci,int slot_id) +void xhci_free_virt_device (struct xhci_hcd *xhci,struct xhci_virt_device *dev, +int slot_id) { -struct xhci_virt_device *dev;int i;int old_active_eps =0 ;/* Slot ID 0 is reserved */ -if (slot_id ==0 || !xhci->devs[slot_id]) +if (slot_id ==0 || !dev)return ; - dev = xhci->devs[slot_id]; - - xhci->dcbaa->dev_context_ptrs[slot_id] =0 ; -if (!dev) -return ; +/* If device ctx array still points to _this_ device, clear it */ +if (dev->out_ctx && + xhci->dcbaa->dev_context_ptrs[slot_id] ==cpu_to_le64 (dev->out_ctx->dma)) + xhci->dcbaa->dev_context_ptrs[slot_id] =0 ;trace_xhci_free_virt_device (dev);
@@ -932,8 +931,9 @@ void xhci_free_virt_device(struct xhci_hif (dev->udev && dev->udev->slot_id) dev->udev->slot_id =0 ; -kfree (xhci->devs[slot_id]); - xhci->devs[slot_id] =NULL ; +if (xhci->devs[slot_id] == dev) + xhci->devs[slot_id] =NULL ; +kfree (dev); }/*
@@ -975,7 +975,7 @@ static void xhci_free_virt_devices_depth out:/* we are now at a leaf device */ xhci_debugfs_remove_slot (xhci, slot_id); -xhci_free_virt_device (xhci, slot_id); +xhci_free_virt_device (xhci, vdev, slot_id); } int xhci_alloc_virt_device(struct xhci_hcd *xhci, int slot_id,
drivers/usb/host/xhci-ring.c +7 -2
@@ -1258,7 +1258,8 @@ static void xhci_handle_cmd_enable_slot( command->slot_id =0 ; } -static void xhci_handle_cmd_disable_slot (struct xhci_hcd *xhci,int slot_id) +static void xhci_handle_cmd_disable_slot (struct xhci_hcd *xhci,int slot_id, +u32 cmd_comp_code) {struct xhci_virt_device *virt_dev;struct xhci_slot_ctx *slot_ctx;
@@ -1273,6 +1274,10 @@ static void xhci_handle_cmd_disable_slotif (xhci->quirks &XHCI_EP_LIMIT_QUIRK )/* Delete default control endpoint resources */ xhci_free_device_endpoint_resources (xhci, virt_dev, true); +if (cmd_comp_code ==COMP_SUCCESS ) { + xhci->dcbaa->dev_context_ptrs[slot_id] =0 ; + xhci->devs[slot_id] =NULL ; + } } static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id,
@@ -1512,7 +1517,7 @@ static void handle_cmd_completion(structxhci_handle_cmd_enable_slot (xhci, slot_id, cmd, cmd_comp_code);break ;case TRB_DISABLE_SLOT : -xhci_handle_cmd_disable_slot (xhci, slot_id); +xhci_handle_cmd_disable_slot (xhci, slot_id, cmd_comp_code);break ;case TRB_CONFIG_EP :if (!cmd->completion)
drivers/usb/host/xhci.c +13 -5
@@ -3947,7 +3947,7 @@ static void xhci_free_dev(struct usb_hcdxhci_disable_slot (xhci, udev->slot_id);spin_lock_irqsave (&xhci->lock, flags); -xhci_free_virt_device (xhci, udev->slot_id); +xhci_free_virt_device (xhci, virt_dev, udev->slot_id);spin_unlock_irqrestore (&xhci->lock, flags); }
@@ -3996,6 +3996,16 @@ int xhci_disable_slot(struct xhci_hcd *xreturn ret; } +int xhci_disable_and_free_slot (struct xhci_hcd *xhci,u32 slot_id) +{ +struct xhci_virt_device *vdev = xhci->devs[slot_id]; +int ret; + + ret =xhci_disable_slot (xhci, slot_id); +xhci_free_virt_device (xhci, vdev, slot_id); +return ret; +} +/* * Checks if we have enough host controller resources for the default control * endpoint.
@@ -4101,8 +4111,7 @@ int xhci_alloc_dev(struct usb_hcd *hcd,return 1 ; disable_slot: -xhci_disable_slot (xhci, udev->slot_id); -xhci_free_virt_device (xhci, udev->slot_id); +xhci_disable_and_free_slot (xhci, udev->slot_id);return 0 ; }
@@ -4238,8 +4247,7 @@ static int xhci_setup_device(struct usb_dev_warn (&udev->dev,"Device not responding to setup %s.\n" , act);mutex_unlock (&xhci->mutex); - ret =xhci_disable_slot (xhci, udev->slot_id); -xhci_free_virt_device (xhci, udev->slot_id); + ret =xhci_disable_and_free_slot (xhci, udev->slot_id);if (!ret) {if (xhci_alloc_dev (hcd, udev) ==1 )xhci_setup_addressable_virt_dev (xhci, udev);
drivers/usb/host/xhci.h +2 -1
@@ -1997,7 +1997,7 @@ void xhci_dbg_trace(struct xhci_hcd *xhc/* xHCI memory management */ void xhci_mem_cleanup (struct xhci_hcd *xhci);int xhci_mem_init (struct xhci_hcd *xhci,gfp_t flags); -void xhci_free_virt_device (struct xhci_hcd *xhci,int slot_id); +void xhci_free_virt_device (struct xhci_hcd *xhci,struct xhci_virt_device *dev,int slot_id);int xhci_alloc_virt_device (struct xhci_hcd *xhci,int slot_id,struct usb_device *udev,gfp_t flags);int xhci_setup_addressable_virt_dev (struct xhci_hcd *xhci,struct usb_device *udev); void xhci_copy_ep0_dequeue_into_input_ctx(struct xhci_hcd *xhci,
@@ -2087,6 +2087,7 @@ void xhci_reset_bandwidth(struct usb_hcdint xhci_update_hub_device (struct usb_hcd *hcd,struct usb_device *hdev,struct usb_tt *tt,gfp_t mem_flags);int xhci_disable_slot (struct xhci_hcd *xhci,u32 slot_id); +int xhci_disable_and_free_slot (struct xhci_hcd *xhci,u32 slot_id);int xhci_ext_cap_init (struct xhci_hcd *xhci);int xhci_suspend (struct xhci_hcd *xhci,bool do_wakeup);
Greg Kroah-Hartman
maintainerPATCH 395/403 scsi: qla4xxx: Prevent a potential error pointer dereference
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
[ Upstream commit 9dcf111dd3e7ed5fce82bb108e3a3fc001c07225 ]
The qla4xxx_get_ep_fwdb() function is supposed to return NULL on error, but qla4xxx_ep_connect() returns error pointers. Propagating the error pointers will lead to an Oops in the caller, so change the error pointers to NULL.
--- drivers/scsi/qla4xxx/ql4_os.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/scsi/qla4xxx/ql4_os.c +2 -0
@@ -6593,6 +6593,8 @@ static struct iscsi_endpoint *qla4xxx_get_ep_fwdb(struct scsi_qla_host *ha, ep =qla4xxx_ep_connect (ha->host, (struct sockaddr *)dst_addr,0 );vfree (dst_addr); +if (IS_ERR (ep)) +return NULL ;return ep; }
Signature · 1 line
2.50.1
Greg Kroah-Hartman
maintainerPATCH 396/403 ALSA: usb-audio: Fix size validation in convert_chmap_v3()
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Dan Carpenter <[email protected]>
[ Upstream commit 89f0addeee3cb2dc49837599330ed9c4612f05b0 ]
The "p" pointer is void so sizeof(*p) is 1. The intent was to check sizeof(*cs_desc), which is 3, instead.
--- sound/usb/stream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/usb/stream.c +1 -1
@@ -350,7 +350,7 @@ snd_pcm_chmap_elem *convert_chmap_v3(struct uac3_cluster_header_descriptoru16 cs_len;u8 cs_type; -if (len <sizeof (*p)) +if (len <sizeof (*cs_desc))break ; cs_len =le16_to_cpu (cs_desc->wLength);if (len < cs_len)
Signature · 1 line
2.50.1
Greg Kroah-Hartman
maintainerPATCH 397/403 ipv6: sr: validate HMAC algorithm ID in seg6_hmac_info_add
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Minhong He <[email protected]>
[ Upstream commit 84967deee9d9870b15bc4c3acb50f1d401807902 ]
The seg6_genl_sethmac() directly uses the algorithm ID provided by the userspace without verifying whether it is an HMAC algorithm supported by the system.
If an unsupported HMAC algorithm ID is configured, packets using SRv6 HMAC will be dropped during encapsulation or decapsulation.
--- net/ipv6/seg6_hmac.c | 3 +++ 1 file changed, 3 insertions(+)
net/ipv6/seg6_hmac.c +3 -0
@@ -295,6 +295,9 @@ int seg6_hmac_info_add(struct net *net, u32 key, struct seg6_hmac_info *hinfo)struct seg6_pernet_data *sdata =seg6_pernet (net);int err; +if (!__hmac_get_algo (hinfo->alg_id)) +return -EINVAL ; + err =rhashtable_lookup_insert_fast (&sdata->hmac_infos, &hinfo->node, rht_params);
Signature · 1 line
2.50.1
Greg Kroah-Hartman
maintainerPATCH 398/403 ixgbe: xsk: resolve the negative overflow of budget in ixgbe_xmit_zc
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Jason Xing <[email protected]>
[ Upstream commit 4d4d9ef9dfee877d494e5418f68a1016ef08cad6 ]
Resolve the budget negative overflow which leads to returning true in ixgbe_xmit_zc even when the budget of descs are thoroughly consumed.
Before this patch, when the budget is decreased to zero and finishes sending the last allowed desc in ixgbe_xmit_zc, it will always turn back and enter into the while() statement to see if it should keep processing packets, but in the meantime it unexpectedly decreases the value again to 'unsigned int (0--)', namely, UINT_MAX. Finally, the ixgbe_xmit_zc returns true, showing 'we complete cleaning the budget'. That also means 'clean_complete = true' in ixgbe_poll.
The true theory behind this is if that budget number of descs are consumed, it implies that we might have more descs to be done. So we should return false in ixgbe_xmit_zc to tell napi poll to find another chance to start polling to handle the rest of descs. On the contrary, returning true here means job done and we know we finish all the possible descs this time and we don't intend to start a new napi poll.
It is apparently against our expectations. Please also see how ixgbe_clean_tx_irq() handles the problem: it uses do..while() statement to make sure the budget can be decreased to zero at most and the negative overflow never happens.
The patch adds 'likely' because we rarely would not hit the loop condition since the standard budget is 256.
--- drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c +3 -1
@@ -582,7 +582,7 @@ static bool ixgbe_xmit_zc(struct ixgbe_ring *xdp_ring, unsigned int budget)dma_addr_t dma;u32 cmd_type; -while (budget-- >0 ) { +while (likely (budget)) {if (unlikely (!ixgbe_desc_unused (xdp_ring))) { work_done = false;break ;
@@ -619,6 +619,8 @@ static bool ixgbe_xmit_zc(struct ixgbe_ring *xdp_ring, unsigned int budget) xdp_ring->next_to_use++;if (xdp_ring->next_to_use == xdp_ring->count) xdp_ring->next_to_use =0 ; + + budget--; }if (tx_desc) {
Signature · 1 line
2.50.1
Greg Kroah-Hartman
maintainerPATCH 399/403 net/sched: Make cake_enqueue return NET_XMIT_CN when past buffer_limit
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: William Liu <[email protected]>
[ Upstream commit 15de71d06a400f7fdc15bf377a2552b0ec437cf5 ]
The following setup can trigger a WARNING in htb_activate due to the condition: !cl->leaf.q->q.qlen
tc qdisc del dev lo root
tc qdisc add dev lo root handle 1: htb default 1
tc class add dev lo parent 1: classid 1:1 \
htb rate 64bit
tc qdisc add dev lo parent 1:1 handle f: \
cake memlimit 1b
ping -I lo -f -c1 -s64 -W0.001 127.0.0.1
This is because the low memlimit leads to a low buffer_limit, which causes packet dropping. However, cake_enqueue still returns NET_XMIT_SUCCESS, causing htb_enqueue to call htb_activate with an empty child qdisc. We should return NET_XMIT_CN when packets are dropped from the same tin and flow.
I do not believe return value of NET_XMIT_CN is necessary for packet drops in the case of ack filtering, as that is meant to optimize performance, not to signal congestion.
--- net/sched/sch_cake.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
net/sched/sch_cake.c +12 -2
@@ -1725,7 +1725,7 @@ static s32 cake_enqueue(struct sk_buff *skb, struct Qdisc *sch,ktime_t now =ktime_get ();struct cake_tin_data *b;struct cake_flow *flow; -u32 idx; +u32 idx, tin;/* choose flow to insert into */ idx =cake_classify (sch, &b, skb, q->flow_mode, &ret);
@@ -1735,6 +1735,7 @@ static s32 cake_enqueue(struct sk_buff *skb, struct Qdisc *sch,__qdisc_drop (skb, to_free);return ret; } + tin = (u32)(b - q->tins); idx--; flow = &b->flows[idx];
@@ -1904,13 +1905,22 @@ static s32 cake_enqueue(struct sk_buff *skb, struct Qdisc *sch, q->buffer_max_used = q->buffer_used;if (q->buffer_used > q->buffer_limit) { +bool same_flow = false;u32 dropped =0 ; +u32 drop_id;while (q->buffer_used > q->buffer_limit) { dropped++; -cake_drop (sch, to_free); + drop_id =cake_drop (sch, to_free); + +if ((drop_id >>16 ) == tin && + (drop_id &0xFFFF ) == idx) + same_flow = true; } b->drop_overlimit += dropped; + +if (same_flow) +return NET_XMIT_CN ; }return NET_XMIT_SUCCESS ; }
Signature · 1 line
2.50.1
Greg Kroah-Hartman
maintainerPATCH 400/403 net/sched: Remove unnecessary WARNING condition for empty child qdisc in htb_activate
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: William Liu <[email protected]>
[ Upstream commit 2c2192e5f9c7c2892fe2363244d1387f62710d83 ]
The WARN_ON trigger based on !cl->leaf.q->q.qlen is unnecessary in htb_activate. htb_dequeue_tree already accounts for that scenario.
--- net/sched/sch_htb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/sched/sch_htb.c +1 -1
@@ -558,7 +558,7 @@ htb_change_class_mode(struct htb_sched *q, struct htb_class *cl, s64 *diff)*/ static inline void htb_activate (struct htb_sched *q,struct htb_class *cl) { -WARN_ON (cl->level || !cl->leaf.q || !cl->leaf.q->q.qlen); +WARN_ON (cl->level || !cl->leaf.q);if (!cl->prio_activity) { cl->prio_activity =1 << cl->prio;
Signature · 1 line
2.50.1
Greg Kroah-Hartman
maintainerPATCH 401/403 ALSA: usb-audio: Use correct sub-type for UAC3 feature unit validation
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Takashi Iwai <[email protected]>
[ Upstream commit 8410fe81093ff231e964891e215b624dabb734b0 ]
The entry of the validators table for UAC3 feature unit is defined with a wrong sub-type UAC_FEATURE (= 0x06) while it should have been UAC3_FEATURE (= 0x07). This patch corrects the entry value.
--- sound/usb/validate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
sound/usb/validate.c +1 -1
@@ -285,7 +285,7 @@ static const struct usb_desc_validator audio_validators[] = {/* UAC_VERSION_3, UAC3_EXTENDED_TERMINAL: not implemented yet */ FUNC (UAC_VERSION_3 ,UAC3_MIXER_UNIT , validate_mixer_unit),FUNC (UAC_VERSION_3 ,UAC3_SELECTOR_UNIT , validate_selector_unit), -FUNC (UAC_VERSION_3 ,UAC_FEATURE_UNIT , validate_uac3_feature_unit), +FUNC (UAC_VERSION_3 ,UAC3_FEATURE_UNIT , validate_uac3_feature_unit),/* UAC_VERSION_3, UAC3_EFFECT_UNIT: not implemented yet */ FUNC (UAC_VERSION_3 ,UAC3_PROCESSING_UNIT , validate_processing_unit), FUNC(UAC_VERSION_3, UAC3_EXTENSION_UNIT, validate_processing_unit),
Signature · 1 line
2.50.1
Greg Kroah-Hartman
maintainerPATCH 402/403 s390/hypfs: Avoid unnecessary ioctl registration in debugfs
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Oberparleiter <[email protected]>
[ Upstream commit fec7bdfe7f8694a0c39e6c3ec026ff61ca1058b9 ]
Currently, hypfs registers ioctl callbacks for all debugfs files, despite only one file requiring them. This leads to unintended exposure of unused interfaces to user space and can trigger side effects such as restricted access when kernel lockdown is enabled.
Restrict ioctl registration to only those files that implement ioctl functionality to avoid interface clutter and unnecessary access restrictions.
--- arch/s390/hypfs/hypfs_dbfs.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
arch/s390/hypfs/hypfs_dbfs.c +11 -7
@@ -64,24 +64,28 @@ static long dbfs_ioctl(struct file *file, unsigned int cmd, unsigned long arg)long rc;mutex_lock (&df->lock); -if (df->unlocked_ioctl) - rc = df->unlocked_ioctl (file, cmd, arg); -else - rc = -ENOTTY ; + rc = df->unlocked_ioctl (file, cmd, arg);mutex_unlock (&df->lock);return rc; } -static const struct file_operations dbfs_ops = { +static const struct file_operations dbfs_ops_ioctl = { .read = dbfs_read, .llseek = no_llseek, .unlocked_ioctl = dbfs_ioctl, }; +static const struct file_operations dbfs_ops = { + .read = dbfs_read, +}; +void hypfs_dbfs_create_file (struct hypfs_dbfs_file *df) { - df->dentry =debugfs_create_file (df->name,0400 , dbfs_dir, df, - &dbfs_ops); +const struct file_operations *fops = &dbfs_ops; + +if (df->unlocked_ioctl) + fops = &dbfs_ops_ioctl; + df->dentry =debugfs_create_file (df->name,0400 , dbfs_dir, df, fops);mutex_init (&df->lock); }
Signature · 1 line
2.50.1
Greg Kroah-Hartman
maintainerPATCH 403/403 s390/hypfs: Enable limited access during lockdown
In reply to Greg Kroah-Hartman5.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Peter Oberparleiter <[email protected]>
[ Upstream commit 3868f910440c47cd5d158776be4ba4e2186beda7 ]
When kernel lockdown is active, debugfs_locked_down() blocks access to hypfs files that register ioctl callbacks, even if the ioctl interface is not required for a function. This unnecessarily breaks userspace tools that only rely on read operations.
Resolve this by registering a minimal set of file operations during lockdown, avoiding ioctl registration and preserving access for affected tooling.
Note that this change restores hypfs functionality when lockdown is active from early boot (e.g. via lockdown=integrity kernel parameter), but does not apply to scenarios where lockdown is enabled dynamically while Linux is running.
--- arch/s390/hypfs/hypfs_dbfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/s390/hypfs/hypfs_dbfs.c +2 -1
@@ -6,6 +6,7 @@* Author(s): Michael Holzheu <[email protected]> */ +#include <linux/security.h> #include <linux/slab.h> #include "hypfs.h"
@@ -83,7 +84,7 @@ void hypfs_dbfs_create_file(struct hypfs_dbfs_file *df) {const struct file_operations *fops = &dbfs_ops; -if (df->unlocked_ioctl) +if (df->unlocked_ioctl && !security_locked_down (LOCKDOWN_DEBUGFS )) fops = &dbfs_ops_ioctl; df->dentry =debugfs_create_file (df->name,0400 , dbfs_dir, df, fops);mutex_init (&df->lock);
Signature · 1 line
2.50.1
Hi Greg,
Quoted 20 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.4.297 release. There are 403 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu, 28 Aug 2025 11:08:17 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.4.297-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.4.y
and the diffstat can be found below.thanks,
greg k-h
-------------
Pseudo-Shortlog of commits:
...
Quoted 2 lines
Prashant Malani <[email protected]>
cpufreq: CPPC: Mark driver withNEED_UPDATE_LIMITSflag
The above commit is causing the following build failure ...
drivers/cpufreq/cppc_cpufreq.c:410:40: error: ‘CPUFREQ_NEED_UPDATE_LIMITS’ undeclared here (not in a function)
410 | .flags = CPUFREQ_CONST_LOOPS | CPUFREQ_NEED_UPDATE_LIMITS,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [scripts/Makefile.build:262: drivers/cpufreq/cppc_cpufreq.o] Error 1
This is seen with ARM64 but I am guessing will be seen for other targets too.
Jon
Signature · 1 line
nvpublic
Greg Kroah-Hartman
maintainerQuoted 31 lines · Jon Hunter
Hi Greg,
Quoted 20 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.4.297 release. There are 403 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu, 28 Aug 2025 11:08:17 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.4.297-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.4.y
and the diffstat can be found below.thanks,
greg k-h
-------------
Pseudo-Shortlog of commits:...
Quoted 2 lines
Prashant Malani <[email protected]>
cpufreq: CPPC: Mark driver withNEED_UPDATE_LIMITSflagThe above commit is causing the following build failure ...
Quoted 8 lines
drivers/cpufreq/cppc_cpufreq.c:410:40: error: ‘CPUFREQ_NEED_UPDATE_LIMITS’ undeclared here (not in a function)
410 | .flags =CPUFREQ_CONST_LOOPS|CPUFREQ_NEED_UPDATE_LIMITS,| ^~~~~~~~~~~~~~~~~~~~~~~~~~make[2]: *** [
scripts/Makefile.build:262:drivers/cpufreq/cppc_cpufreq.o] Error 1This is seen with ARM64 but I am guessing will be seen for other targets too.
Thanks, somehow this missed my build tests. I've dropped it from the tree now and will push out a -rc2.
greg k-h
Quoted 39 lines · Greg Kroah-Hartman
Quoted 37 lines · Jon Hunter
Hi Greg,
Quoted 20 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.4.297 release. There are 403 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu, 28 Aug 2025 11:08:17 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.4.297-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.4.y
and the diffstat can be found below.thanks,
greg k-h
-------------
Pseudo-Shortlog of commits:...
Quoted 2 lines
Prashant Malani <[email protected]>
cpufreq: CPPC: Mark driver withNEED_UPDATE_LIMITSflagThe above commit is causing the following build failure ...
drivers/cpufreq/cppc_cpufreq.c:410:40: error: ‘CPUFREQ_NEED_UPDATE_LIMITS’ undeclared here (not in a function)
410 | .flags =CPUFREQ_CONST_LOOPS|CPUFREQ_NEED_UPDATE_LIMITS,| ^~~~~~~~~~~~~~~~~~~~~~~~~~make[2]: *** [
scripts/Makefile.build:262:drivers/cpufreq/cppc_cpufreq.o] Error 1
Quoted 5 lines
Quoted 2 lines
This is seen with ARM64 but I am guessing will be seen for other targets too.
Thanks, somehow this missed my build tests. I've dropped it from the tree now and will push out a -rc2.
[for the record]
We also see the following build regression on ARM64 with gcc-12 and clang-20.
Validation is in progress for RC2.
Build Regression: 5.4.297-rc1 arm64 use of undeclared identifier CPUFREQ_NEED_UPDATE_LIMITS
## Build
* kernel: 5.4.297-rc1
* git: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git
* git commit: 8387e34ec6fea83fa8bf03ffa1c8c0144d801c14
* git describe: v5.4.296-404-g8387e34ec6fe
* test details:
https://qa-reports.linaro.org/lkft/linux-stable-rc-linux-5.4.y/build/v5.4.296-404-g8387e34ec6fe
## Test Regressions (compared to v5.4.295-145-g6d1abaaa322e)
* arm64, build
- clang-20-defconfig
- clang-20-defconfig-00b6e174
- clang-20-lkftconfig
- clang-20-lkftconfig-no-kselftest-frag
- clang-nightly-defconfig
- clang-nightly-defconfig-00b6e174
- clang-nightly-lkftconfig
- gcc-12-lkftconfig
/builds/linux/drivers/cpufreq/cppc_cpufreq.c:410:33: error: use of undeclared identifier 'CPUFREQ_NEED_UPDATE_LIMITS'
410 | .flags = CPUFREQ_CONST_LOOPS | CPUFREQ_NEED_UPDATE_LIMITS,
| ^
1 error generated.
make[3]: *** [/builds/linux/scripts/Makefile.build:262:drivers/cpufreq/cppc_cpufreq.o] Error 1
log file: https://qa-reports.linaro.org/api/testruns/29678460/log_file/
Build detailes:
https://regressions.linaro.org/lkft/linux-stable-rc-linux-5.4.y/v5.4.296-404-g8387e34ec6fe/build/clang-20-lkftconfig/
## Metric Regressions (compared to v5.4.295-145-g6d1abaaa322e)
## Test Fixes (compared to v5.4.295-145-g6d1abaaa322e)
## Metric Fixes (compared to v5.4.295-145-g6d1abaaa322e)
## Test result summary
total: 22051, pass: 15817, fail: 1724, skip: 4433, xfail: 77
## Build Summary
* arc: 5 total, 5 passed, 0 failed
* arm: 131 total, 131 passed, 0 failed
* arm64: 31 total, 8 passed, 23 failed
* i386: 18 total, 13 passed, 5 failed
* mips: 25 total, 25 passed, 0 failed
* parisc: 3 total, 0 passed, 3 failed
* powerpc: 26 total, 26 passed, 0 failed
* riscv: 9 total, 3 passed, 6 failed
* s390: 6 total, 6 passed, 0 failed
* sh: 10 total, 10 passed, 0 failed
* sparc: 6 total, 6 passed, 0 failed
* x86_64: 27 total, 27 passed, 0 failed
## Test suites summary
* boot
* kselftest-breakpoints
* kselftest-capabilities
* kselftest-clone3
* kselftest-core
* kselftest-cpu-hotplug
* kselftest-exec
* kselftest-fpu
* kselftest-futex
* kselftest-intel_pstate
* kselftest-kcmp
* kselftest-membarrier
* kselftest-mincore
* kselftest-mqueue
* kselftest-openat2
* kselftest-ptrace
* kselftest-rseq
* kselftest-rtc
* kselftest-sigaltstack
* kselftest-size
* kselftest-timers
* kselftest-tmpfs
* kselftest-tpm2
* kselftest-user_events
* kselftest-vDSO
* kselftest-x86
* kunit
* lava
* libhugetlbfs
* log-parser-build-clang
* log-parser-build-gcc
* log-parser-test
* ltp-capability
* ltp-commands
* ltp-containers
* ltp-controllers
* ltp-cpuhotplug
* ltp-crypto
* ltp-cve
* ltp-dio
* ltp-fcntl-locktests
* ltp-fs
* ltp-fs_bind
* ltp-fs_perms_simple
* ltp-hugetlb
* ltp-math
* ltp-mm
* ltp-nptl
* ltp-pty
* ltp-sched
* ltp-smoke
* ltp-syscalls
* ltp-tracing
* perf
* rcutorture
--
Linaro LKFT
https://lkft.linaro.org
Greg Kroah-Hartman
maintainerQuoted 51 lines · Anders Roxell
Quoted 39 lines · Greg Kroah-Hartman
Quoted 37 lines · Jon Hunter
Hi Greg,
Quoted 20 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.4.297 release. There are 403 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu, 28 Aug 2025 11:08:17 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.4.297-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.4.y
and the diffstat can be found below.thanks,
greg k-h
-------------
Pseudo-Shortlog of commits:...
Quoted 2 lines
Prashant Malani <[email protected]>
cpufreq: CPPC: Mark driver withNEED_UPDATE_LIMITSflagThe above commit is causing the following build failure ...
drivers/cpufreq/cppc_cpufreq.c:410:40: error: ‘CPUFREQ_NEED_UPDATE_LIMITS’ undeclared here (not in a function)
410 | .flags =CPUFREQ_CONST_LOOPS|CPUFREQ_NEED_UPDATE_LIMITS,| ^~~~~~~~~~~~~~~~~~~~~~~~~~make[2]: *** [
scripts/Makefile.build:262:drivers/cpufreq/cppc_cpufreq.o] Error 1Quoted 5 lines
Quoted 2 lines
This is seen with ARM64 but I am guessing will be seen for other targets too.
Thanks, somehow this missed my build tests. I've dropped it from the tree now and will push out a -rc2.
[for the record]
We also see the following build regression on ARM64 with gcc-12 and clang-20.
Quoted 7 lines
Validation is in progress for RC2.
Build Regression: 5.4.297-rc1 arm64 use of undeclared identifier
CPUFREQ_NEED_UPDATE_LIMITS
Should be fixed in -rc2, right?
Quoted 9 lines · Greg Kroah-Hartman
This is the start of the stable review cycle for the 5.4.297 release. There are 403 patches in this series, all will be posted as a response to this one. If anyone has any issues with these being applied, please let me know.
Responses should be made by Thu, 28 Aug 2025 11:08:17 +0000. Anything received after that time might be too late.
The whole patch series can be found in one patch at:
Quoted 8 lines
https://www.kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.4.297-rc1.gzor in the git tree and branch at:
git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.gitlinux-5.4.y
and the diffstat can be found below.thanks,
greg k-h
On ARCH_BRCMSTB using 32-bit and 64-bit ARM kernels, build tested on BMIPS_GENERIC:
Signature · 1 line
Florian
It builds and boots. Can't run any of the usual Librecast network testing as the kernel is too old to support the NICs on our main test system.
Linux auntie 5.4.297-rc1-00404-g8387e34ec6fe #53 SMP Tue Aug 26 17:32:06 -00 2025 x86_64 AMD Ryzen 9 9950X 16-Core Processor AuthenticAMD GNU/Linux