Compare

0fa993581aaa58a34ae3dcebebe0fbf593fcb441..0936bbd35a247665c64886135835faa3c3f4f29f

ASoC: stm32: spdifrx: fix synchronization state check

The interrupt handler uses a logical AND to check whether SPDIFRX
was in the SYNC state before clearing errors. Since both SYNC (1)
and ENABLE (3) are nonzero, this also treats ENABLE as SYNC (and
any other non-zero value that might be added).

The logical && basically just converts this to check for != 0.

So errors occurring while SPDIFRX is enabled cause the driver
to retry synch instead of disconnecting the PCM stream.

Fix is to change the logical && to equality (==) and only retry
when exactly in sync state.

Fixes: 0c93c291321f2 ("ASoC: stm32: spdifrx: retry synchronization in sync state")
Signed-off-by: Avi Weiss <thnkslprpt@gmail.com>
Reviewed-by: Olivier Moysan <olivier.moysan@foss.st.com>
Link: https://patch.msgid.link/20261011035459.2289403-1-thnkslprpt@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>

Avi Weiss <thnkslprpt@gmail.com> · 2026-10-11 03:54 UTC · committed by Mark Brown

Browse files
395 files changed, +1767 −10725
modified .mailmap
@@ -101,7 +101,6 @@ Andy Chiu <andybnac@gmail.com> <andy.chiu@sifive.com>
101 101 Andy Chiu <andybnac@gmail.com> <taochiu@synology.com>
102 102 Andy Shevchenko <andy@kernel.org> <andy@smile.org.ua>
103 103 Andy Shevchenko <andy@kernel.org> <ext-andriy.shevchenko@nokia.com>
104 - Andy Yan <andyshrk@163.com> <andy.yan@rock-chips.com>
105 104 Anilkumar Kolli <quic_akolli@quicinc.com> <akolli@codeaurora.org>
106 105 Anirudh Ghayal <quic_aghayal@quicinc.com> <aghayal@codeaurora.org>
107 106 Antoine Tenart <atenart@kernel.org> <antoine.tenart@bootlin.com>
@@ -462,8 +461,7 @@ Johan Hovold <johan@kernel.org> <jhovold@gmail.com>
462 461 Johan Hovold <johan@kernel.org> <johan@hovoldconsulting.com>
463 462 John Crispin <john@phrozen.org> <blogic@openwrt.org>
464 463 John Fastabend <john.fastabend@gmail.com> <john.r.fastabend@intel.com>
465 - John Garry <john.garry@linux.dev> <john.garry@huawei.com>
466 - John Garry <john.garry@linux.dev> <john.g.garry@oracle.com>
464 + John Garry <john.g.garry@oracle.com> <john.garry@huawei.com>
467 465 John Keeping <john@keeping.me.uk> <john@metanate.com>
468 466 John Moon <john@jmoon.dev> <quic_johmoo@quicinc.com>
469 467 John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
@@ -488,7 +486,6 @@ Juha Yrjola <juha.yrjola@nokia.com>
488 486 Juha Yrjola <juha.yrjola@solidboot.com>
489 487 Julien Thierry <julien.thierry.kdev@gmail.com> <julien.thierry@arm.com>
490 488 Justin Iurman <justin.iurman@gmail.com> <justin.iurman@uliege.be>
491 - Imre Kaloz <kaloz@kernel.org> <kaloz@openwrt.org>
492 489 Ira Weiny <iweiny@kernel.org> <ira.weiny@intel.com>
493 490 Iskren Chernev <me@iskren.info> <iskren.chernev@gmail.com>
494 491 Kalle Valo <kvalo@kernel.org> <kvalo@codeaurora.org>
modified Documentation/admin-guide/ext4.rst
@@ -172,8 +172,7 @@ When mounting an ext4 filesystem, the following option are accepted:
172 172 data=journal
173 173 All data are committed into the journal prior to being written into the
174 174 main file system. Enabling this mode will disable delayed allocation
175 - and O_DIRECT support. This feature is deprecated and support
176 - will be removed in January 2028.
175 + and O_DIRECT support.
177 176
178 177 data=ordered (*)
179 178 All data are forced directly out to the main file system prior to its
@@ -419,8 +418,7 @@ There are 3 different data modes:
419 418 consistent state. This mode is the slowest except when data needs to be read
420 419 from and written to disk at the same time where it outperforms all others
421 420 modes. Enabling this mode will disable delayed allocation and O_DIRECT
422 - support. The data=journal feature is deprecated and support will be
423 - removed in January 2028.
421 + support.
424 422
425 423 /proc entries
426 424 =============
modified Documentation/devicetree/bindings/spi/snps,dw-apb-ssi.yaml
@@ -77,7 +77,6 @@ properties:
77 77 - mscc,ocelot-spi
78 78 - mscc,jaguar2-spi
79 79 - sophgo,sg2042-spi
80 - - syna,sl2610-spi
81 80 - thead,th1520-spi
82 81 - ultrarisc,dp1000-spi
83 82 - const: snps,dw-apb-ssi
modified Documentation/filesystems/propagate_umount.txt
@@ -32,12 +32,12 @@ of set. They can be reparented to the place where the bottom of
32 32 stack is attached to a mount that will survive. NOTE: doing that
33 33 will violate a constraint on having no more than one mount with
34 34 the same parent/mountpoint pair; however, the caller (umount_tree())
35 - will immediately remedy that - it detaches every element of the set
36 - from its parent. Since all conflicts created by reparenting have
37 - common parent *not* in the set and one side of the conflict (bottom
38 - of the stack of overmounts) is in the set, it will be resolved.
39 - However, we rely upon umount_tree() doing that pretty much immediately
40 - after the call of propagate_umount().
35 + will immediately remedy that - it may keep unmounted element attached
36 + to parent, but only if the parent itself is unmounted. Since all
37 + conflicts created by reparenting have common parent *not* in the
38 + set and one side of the conflict (bottom of the stack of overmounts)
39 + is in the set, it will be resolved. However, we rely upon umount_tree()
40 + doing that pretty much immediately after the call of propagate_umount().
41 41
42 42 Algorithm is based on two statements:
43 43 1) for any set S, there is a maximal non-shifting subset of S
modified Documentation/filesystems/sharedsubtree.rst
@@ -564,8 +564,8 @@ f) Unmount semantics
564 564 where 'A' is a mount mounted on mount 'B' at dentry 'b'.
565 565
566 566 If mount 'B' is shared, then all most-recently-mounted mounts at dentry
567 - 'b' on mounts that receive propagation from mount 'B' are unmounted as
568 - well, if every mount below them is also unmounted.
567 + 'b' on mounts that receive propagation from mount 'B' and does not have
568 + sub-mounts within them are unmounted.
569 569
570 570 Example: Let's say 'B1', 'B2', 'B3' are shared mounts that propagate to
571 571 each other.
@@ -584,18 +584,10 @@ f) Unmount semantics
584 584
585 585 So all 'C1', 'C2' and 'C3' should be unmounted.
586 586
587 - If any of 'C2' or 'C3' has a child mount that cannot be unmounted
588 - then that mount is not unmounted. But all other mounts are unmounted.
589 - A child mount that is itself unmounted by the same unmount
590 - propagation does not keep its parent mounted. However if 'C1' is
591 - supposed to be unmounted and 'C1' has some sub-mounts, the unmount
592 - fails.
593 -
594 - A lazy umount (MNT_DETACH) takes a whole tree. Every mount of the
595 - tree then propagates its unmount from its own parent as described
596 - above, so the mounts that receive propagation lose the corresponding
597 - trees as well. Documentation/filesystems/propagate_umount.txt has the
598 - precise rules, including the ones for locked mounts.
587 + If any of 'C2' or 'C3' has some child mounts, then that mount is not
588 + unmounted, but all other mounts are unmounted. However if 'C1' is told
589 + to be unmounted and 'C1' has some sub-mounts, the umount operation is
590 + failed entirely.
599 591
600 592 g) Clone Namespace
601 593
modified Documentation/networking/strparser.rst
@@ -77,7 +77,7 @@ Functions
77 77
78 78 strp_done is called to release any resources held by the stream
79 79 parser instance. This must be called after the stream processor
80 - has been stopped. The socket lock must not be held.
80 + has been stopped.
81 81
82 82 ::
83 83
modified MAINTAINERS
@@ -3012,7 +3012,7 @@ F: arch/arm/boot/dts/ti/omap/omap3-igep*
3012 3012
3013 3013 ARM/INTEL IXP4XX ARM ARCHITECTURE
3014 3014 M: Linus Walleij <linusw@kernel.org>
3015 - M: Imre Kaloz <kaloz@kernel.org>
3015 + M: Imre Kaloz <kaloz@openwrt.org>
3016 3016 L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers)
3017 3017 S: Maintained
3018 3018 F: Documentation/devicetree/bindings/arm/intel-ixp4xx.yaml
@@ -9861,7 +9861,7 @@ L: linux-ext4@vger.kernel.org
9861 9861 S: Maintained
9862 9862 W: http://ext4.wiki.kernel.org
9863 9863 Q: http://patchwork.ozlabs.org/project/linux-ext4/list/
9864 - T: git git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git dev
9864 + T: git git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4.git
9865 9865 F: Documentation/filesystems/ext4/
9866 9866 F: fs/ext4/
9867 9867 F: include/trace/events/ext4.h
modified Makefile
@@ -2,7 +2,7 @@
2 2 VERSION = 7
3 3 PATCHLEVEL = 3
4 4 SUBLEVEL = 0
5 - EXTRAVERSION = -rc7
5 + EXTRAVERSION = -rc6
6 6 NAME = Baby Opossum Posse
7 7
8 8 # *DOCUMENTATION*
modified arch/arm64/boot/dts/freescale/fsl-lx216x.dtsi
@@ -1602,7 +1602,7 @@
1602 1602 };
1603 1603
1604 1604 dspi2_miso_mosi_pins: iic5-spi3-pins {
1605 - pinctrl-single,bits = <0x0 (0x3 << 9) (0x7 << 9)>;
1605 + pinctrl-single,bits = <0x3 (0x2 << 9) (0x7 << 9)>;
1606 1606 };
1607 1607
1608 1608 i2c5_pins: iic6-i2c-pins {
@@ -1622,7 +1622,7 @@
1622 1622 };
1623 1623
1624 1624 gpio1_31_28_pins: xspi1-data74-gpio-pins {
1625 - pinctrl-single,bits = <0x0 (0x1 << 15) (0x7 << 15)>;
1625 + pinctrl-single,bits = <0x0 0x1 (0x7 << 15)>;
1626 1626 };
1627 1627
1628 1628 fspi_data30_pins: xspi1-data30-pins {
@@ -1630,7 +1630,7 @@
1630 1630 };
1631 1631
1632 1632 gpio1_27_24_pins: xspi1-data30-gpio-pins {
1633 - pinctrl-single,bits = <0x0 (0x1 << 18) (0x7 << 18)>;
1633 + pinctrl-single,bits = <0x0 0x1 (0x7 << 18)>;
1634 1634 };
1635 1635
1636 1636 fspi_dqs_sck_cs10_pins: xspi1-base-pins {
@@ -1638,7 +1638,7 @@
1638 1638 };
1639 1639
1640 1640 gpio1_23_20_pins: xspi1-base-gpio-pins {
1641 - pinctrl-single,bits = <0x0 (0x1 << 21) (0x7 << 21)>;
1641 + pinctrl-single,bits = <0x0 0x1 (0x7 << 21)>;
1642 1642 };
1643 1643
1644 1644 esdhc0_cmd_data30_clk_vsel_pins: sdhc1-base-sdhc-vsel-pins {
@@ -1687,19 +1687,12 @@
1687 1687 };
1688 1688
1689 1689 /* RCWSR14 */
1690 - /*
1691 - * IIC1_PMUX is a single bit at RCWSR14[10], but bit-per-mux
1692 - * uses the mask for the field to clear before applying the
1693 - * value.
1694 - * So bits 11 and 12, which are reserved, are written as 0
1695 - * on every mux switch, it is harmless.
1696 - */
1697 1690 i2c0_pins: iic1-i2c-pins {
1698 - pinctrl-single,bits = <0x8 0x0 (0x7 << 10)>;
1691 + pinctrl-single,bits = <0x8 0x0 (0x1 << 10)>;
1699 1692 };
1700 1693
1701 1694 gpio0_3_2_pins: iic1-gpio-pins {
1702 - pinctrl-single,bits = <0x8 (0x1 << 10) (0x7 << 10)>;
1695 + pinctrl-single,bits = <0x8 (0x1 << 10) (0x1 << 10)>;
1703 1696 };
1704 1697 };
1705 1698
modified arch/arm64/boot/dts/freescale/imx8mp-var-dart-sonata.dts
@@ -511,7 +511,6 @@
511 511 pinctrl-2 = <&pinctrl_usdhc2_200mhz>, <&pinctrl_usdhc2_gpio>;
512 512 cd-gpios = <&gpio2 12 GPIO_ACTIVE_LOW>;
513 513 vmmc-supply = <&reg_usdhc2_vmmc>;
514 - vqmmc-supply = <&ldo5>;
515 514 bus-width = <4>;
516 515 status = "okay";
517 516 };
modified arch/arm64/boot/dts/qcom/x1-microsoft-denali.dtsi
@@ -863,11 +863,11 @@
863 863 };
864 864
865 865 &lpass_vamacro {
866 - pinctrl-0 = <&dmic01_default>;
866 + pinctrl-0 = <&dmic01_default>, <&dmic23_default>;
867 867 pinctrl-names = "default";
868 868
869 869 vdd-micb-supply = <&vreg_l1b_1p8>;
870 - qcom,dmic-sample-rate = <2400000>;
870 + qcom,dmic-sample-rate = <4800000>;
871 871 };
872 872
873 873 &mdss {
modified arch/arm64/include/asm/el2_setup.h
@@ -421,9 +421,8 @@
421 421 mov x2, xzr
422 422 mrs x1, id_aa64dfr0_el1
423 423 ubfx x1, x1, #ID_AA64DFR0_EL1_PMUVer_SHIFT, #4
424 - cmp x1, #ID_AA64DFR0_EL1_PMUVer_IMP_DEF
425 - ccmp x1, #ID_AA64DFR0_EL1_PMUVer_V3P9, #8, ne
426 - b.lt .Lskip_pmuv3p9_\@ // Skip if < PMUv3p9 or IMP_DEF
424 + cmp x1, #ID_AA64DFR0_EL1_PMUVer_V3P9
425 + b.lt .Lskip_pmuv3p9_\@
427 426
428 427 orr x0, x0, #HDFGRTR2_EL2_nPMICNTR_EL0
429 428 orr x0, x0, #HDFGRTR2_EL2_nPMICFILTR_EL0
modified arch/arm64/kernel/Makefile
@@ -25,9 +25,6 @@ KASAN_SANITIZE_stacktrace.o := n
25 25 KCOV_INSTRUMENT_entry-common.o := n
26 26 KCOV_INSTRUMENT_idle.o := n
27 27
28 - # Softirq stack switching can run outside interrupt context.
29 - KCOV_INSTRUMENT_irq.o := n
30 -
31 28 # Object file lists.
32 29 obj-y := debug-monitors.o entry.o irq.o fpsimd.o \
33 30 entry-common.o process.o ptrace.o \
modified arch/riscv/Kconfig
@@ -453,10 +453,9 @@ config SMP
453 453 config NR_CPUS
454 454 int "Maximum number of CPUs (2-512)"
455 455 depends on SMP
456 - range 2 512 if !RISCV_SBI_V01 && 64BIT
457 - range 2 128 if !RISCV_SBI_V01 && 32BIT
458 - range 2 64 if RISCV_SBI_V01 && 64BIT
456 + range 2 512 if !RISCV_SBI_V01
459 457 range 2 32 if RISCV_SBI_V01 && 32BIT
458 + range 2 64 if RISCV_SBI_V01 && 64BIT
460 459 default "32" if 32BIT
461 460 default "64" if RISCV_SBI_V01 && 64BIT
462 461 default "256" if !RISCV_SBI_V01 && 64BIT
modified arch/riscv/Kconfig.errata
@@ -46,7 +46,7 @@ config ERRATA_MIPS_P8700_PAUSE_OPCODE
46 46
47 47 config ERRATA_SIFIVE
48 48 bool "SiFive errata"
49 - depends on RISCV_ALTERNATIVE && 64BIT
49 + depends on RISCV_ALTERNATIVE
50 50 help
51 51 All SiFive errata Kconfig depend on this Kconfig. Disabling
52 52 this Kconfig will disable all SiFive errata. Please say "Y"
@@ -96,20 +96,6 @@ config ERRATA_STARFIVE_JH7100
96 96 Say "Y" if you want to support the BeagleV Starlight and/or
97 97 StarFive VisionFive V1 boards.
98 98
99 - config ERRATA_SIFIVE_MAL_9092
100 - bool "Apply SiFive HLV/HLVX/HSV fence errata"
101 - depends on ERRATA_SIFIVE && 64BIT
102 - default y
103 - help
104 - This will apply the SiFive MAL-9092 errata to add fence.rw
105 - instructions around all HLV/HLVX/HSV instructions.
106 -
107 - Note: HSTATUS.HU is cleared during KVM initialization. If future
108 - changes enable HSTATUS.HU to allow hypervisor instructions in
109 - U-mode, additional errata handling may be required.
110 -
111 - If you don't know what to do here, say "Y".
112 -
113 99 config ERRATA_THEAD
114 100 bool "T-HEAD errata"
115 101 depends on RISCV_ALTERNATIVE
@@ -160,7 +146,6 @@ config ERRATA_THEAD_PMU
160 146 config ERRATA_THEAD_GHOSTWRITE
161 147 bool "Apply T-Head Ghostwrite errata"
162 148 depends on ERRATA_THEAD && RISCV_ISA_XTHEADVECTOR
163 - select RISCV_ALTERNATIVE_EARLY
164 149 default y
165 150 help
166 151 The T-Head C9xx cores have a vulnerability in the xtheadvector
modified arch/riscv/Kconfig.socs
@@ -34,7 +34,6 @@ config ARCH_RENESAS
34 34 config ARCH_SIFIVE
35 35 bool "SiFive SoCs"
36 36 select ERRATA_SIFIVE
37 - depends on 64BIT
38 37 help
39 38 This enables support for SiFive SoC platform hardware.
40 39
modified arch/riscv/errata/sifive/errata.c
@@ -51,22 +51,6 @@ static bool errata_cip_1200_check_func(unsigned long arch_id, unsigned long imp
51 51 return true;
52 52 }
53 53
54 - static bool errata_mal_9092_check_func(unsigned long arch_id, unsigned long impid)
55 - {
56 - /*
57 - * Affected cores:
58 - * Architecture ID: 0x8000000000000109
59 - * Implementation ID: 0x19251031, 0x19251217, 0x19260320
60 - */
61 -
62 - if (arch_id != 0x8000000000000109)
63 - return false;
64 - if (impid != 0x19251031 && impid != 0x19251217 && impid != 0x19260320)
65 - return false;
66 -
67 - return true;
68 - }
69 -
70 54 static struct errata_info_t errata_list[ERRATA_SIFIVE_NUMBER] = {
71 55 {
72 56 .name = "cip-453",
@@ -76,10 +60,6 @@ static struct errata_info_t errata_list[ERRATA_SIFIVE_NUMBER] = {
76 60 .name = "cip-1200",
77 61 .check_func = errata_cip_1200_check_func
78 62 },
79 - {
80 - .name = "mal-9092",
81 - .check_func = errata_mal_9092_check_func
82 - },
83 63 };
84 64
85 65 static u32 __init_or_module sifive_errata_probe(unsigned long archid,
modified arch/riscv/include/asm/cpufeature.h
@@ -40,8 +40,6 @@ extern u32 thead_vlenb_of;
40 40
41 41 void __init riscv_user_isa_enable(void);
42 42
43 - void riscv_clear_hypervisor_csr(void);
44 -
45 43 #define _RISCV_ISA_EXT_DATA(_name, _id, _subset_exts, _subset_exts_size, _validate) { \
46 44 .name = #_name, \
47 45 .property = #_name, \
modified arch/riscv/include/asm/errata_list_vendors.h
@@ -11,8 +11,7 @@
11 11 #ifdef CONFIG_ERRATA_SIFIVE
12 12 #define ERRATA_SIFIVE_CIP_453 0
13 13 #define ERRATA_SIFIVE_CIP_1200 1
14 - #define ERRATA_SIFIVE_MAL_9092 2
15 - #define ERRATA_SIFIVE_NUMBER 3
14 + #define ERRATA_SIFIVE_NUMBER 2
16 15 #endif
17 16
18 17 #ifdef CONFIG_ERRATA_THEAD
modified arch/riscv/include/asm/futex.h
@@ -40,7 +40,6 @@ arch_futex_atomic_op_inuser(int op, int oparg, int *oval, u32 __user *uaddr)
40 40
41 41 if (!access_ok(uaddr, sizeof(u32)))
42 42 return -EFAULT;
43 - uaddr = untagged_addr(uaddr);
44 43
45 44 switch (op) {
46 45 case FUTEX_OP_SET:
@@ -83,7 +82,6 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
83 82
84 83 if (!access_ok(uaddr, sizeof(u32)))
85 84 return -EFAULT;
86 - uaddr = untagged_addr(uaddr);
87 85
88 86 __enable_user_access();
89 87 __asm__ __volatile__ (
modified arch/riscv/include/asm/insn-def.h
@@ -192,28 +192,18 @@
192 192 INSN_R(OPCODE_SYSTEM, FUNC3(0), FUNC7(49), \
193 193 __RD(0), RS1(gaddr), RS2(vmid))
194 194
195 - #define ALT_SIFIVE_MAL_9092_FENCE \
196 - ALTERNATIVE("nop", "fence rw, rw", SIFIVE_VENDOR_ID, \
197 - ERRATA_SIFIVE_MAL_9092, CONFIG_ERRATA_SIFIVE_MAL_9092)
198 -
199 195 #define HLVX_HU(dest, addr) \
200 - ALT_SIFIVE_MAL_9092_FENCE "\n" \
201 196 INSN_R(OPCODE_SYSTEM, FUNC3(4), FUNC7(50), \
202 - RD(dest), RS1(addr), __RS2(3)) "\n" \
203 - ALT_SIFIVE_MAL_9092_FENCE
197 + RD(dest), RS1(addr), __RS2(3))
204 198
205 199 #define HLV_W(dest, addr) \
206 - ALT_SIFIVE_MAL_9092_FENCE "\n" \
207 200 INSN_R(OPCODE_SYSTEM, FUNC3(4), FUNC7(52), \
208 - RD(dest), RS1(addr), __RS2(0)) "\n" \
209 - ALT_SIFIVE_MAL_9092_FENCE
201 + RD(dest), RS1(addr), __RS2(0))
210 202
211 203 #ifdef CONFIG_64BIT
212 204 #define HLV_D(dest, addr) \
213 - ALT_SIFIVE_MAL_9092_FENCE "\n" \
214 205 INSN_R(OPCODE_SYSTEM, FUNC3(4), FUNC7(54), \
215 - RD(dest), RS1(addr), __RS2(0)) "\n" \
216 - ALT_SIFIVE_MAL_9092_FENCE
206 + RD(dest), RS1(addr), __RS2(0))
217 207 #else
218 208 #define HLV_D(dest, addr) \
219 209 __ASM_STR(.error "hlv.d requires 64-bit support")
modified arch/riscv/include/asm/scs.h
@@ -4,7 +4,6 @@
4 4
5 5 #ifdef __ASSEMBLER__
6 6 #include <asm/asm-offsets.h>
7 - #include <asm/csr.h>
8 7
9 8 #ifdef CONFIG_SHADOW_CALL_STACK
10 9
@@ -23,17 +22,9 @@
23 22 REG_L gp, TASK_TI_SCS_SP(tp)
24 23 .endm
25 24
26 - /*
27 - * Load task_scs_sp(current) to gp, but only when the trap came from U-mode.
28 - * The source privilege level is taken from the saved sstatus.SPP bit (written
29 - * by hardware on trap entry), not by comparing tp. tp is a user-writable
30 - * register, so gating the shadow call stack reload on it let a user task that
31 - * set tp == &current skip the reload and run the kernel with an attacker
32 - * controlled gp (the shadow call stack pointer).
33 - */
34 - .macro scs_load_current_if_from_user status, tmp
35 - andi \tmp, \status, SR_SPP
36 - bnez \tmp, _skip_scs
25 + /* Load task_scs_sp(current) to gp, but only if tp has changed. */
26 + .macro scs_load_current_if_task_changed prev
27 + beq \prev, tp, _skip_scs
37 28 scs_load_current
38 29 _skip_scs:
39 30 .endm
@@ -51,7 +42,7 @@ _skip_scs:
51 42 .endm
52 43 .macro scs_load_current
53 44 .endm
54 - .macro scs_load_current_if_from_user status, tmp
45 + .macro scs_load_current_if_task_changed prev
55 46 .endm
56 47 .macro scs_save_current
57 48 .endm
modified arch/riscv/include/asm/vector.h
@@ -137,8 +137,8 @@ static __always_inline void __vstate_csr_save(struct __riscv_v_ext_state *dest)
137 137 "csrr %0, " __stringify(CSR_VSTART) "\n\t"
138 138 "csrr %1, " __stringify(CSR_VTYPE) "\n\t"
139 139 "csrr %2, " __stringify(CSR_VL) "\n\t"
140 - : "=r" (dest->vstart), "=r" (dest->vtype), "=r" (dest->vl)
141 - : :);
140 + : "=r" (dest->vstart), "=r" (dest->vtype), "=r" (dest->vl),
141 + "=r" (dest->vcsr) : :);
142 142
143 143 if (has_xtheadvector()) {
144 144 unsigned long status;
@@ -230,7 +230,7 @@ static inline void __riscv_v_vstate_save(struct __riscv_v_ext_state *save_to,
230 230 "add %1, %1, %0\n\t"
231 231 "vse8.v v24, (%1)\n\t"
232 232 ".option pop\n\t"
233 - : "=&r" (vl), "+r" (datap) : : "memory");
233 + : "=&r" (vl) : "r" (datap) : "memory");
234 234 }
235 235 riscv_v_disable();
236 236 }
@@ -266,7 +266,7 @@ static inline void __riscv_v_vstate_restore(struct __riscv_v_ext_state *restore_
266 266 "add %1, %1, %0\n\t"
267 267 "vle8.v v24, (%1)\n\t"
268 268 ".option pop\n\t"
269 - : "=&r" (vl), "+r" (datap) : : "memory");
269 + : "=&r" (vl) : "r" (datap) : "memory");
270 270 }
271 271 __vstate_csr_restore(restore_from);
272 272 riscv_v_disable();
modified arch/riscv/include/uapi/asm/vendor/mips.h
@@ -1,5 +1,3 @@
1 1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 2
3 - #include <linux/const.h>
4 -
5 - #define RISCV_HWPROBE_VENDOR_EXT_XMIPSEXECTL _BITULL(0)
3 + #define RISCV_HWPROBE_VENDOR_EXT_XMIPSEXECTL BIT(0)
modified arch/riscv/kernel/cpufeature.c
@@ -1233,18 +1233,6 @@ void __init riscv_user_isa_enable(void)
1233 1233 pr_warn("Zicbop disabled as it is unavailable on some harts\n");
1234 1234 }
1235 1235
1236 - void riscv_clear_hypervisor_csr(void)
1237 - {
1238 - if (!riscv_has_extension_unlikely(RISCV_ISA_EXT_H))
1239 - return;
1240 -
1241 - /*
1242 - * Clear HSTATUS.HU to restrict hypervisor instructions to HS-mode.
1243 - * This prevents user-mode from executing HLV/HSV instructions.
1244 - */
1245 - csr_clear(CSR_HSTATUS, HSTATUS_HU);
1246 - }
1247 -
1248 1236 #ifdef CONFIG_RISCV_ALTERNATIVE
1249 1237 /*
1250 1238 * Alternative patch sites consider 48 bits when determining when to patch
modified arch/riscv/kernel/entry.S
@@ -208,7 +208,7 @@ SYM_CODE_START(handle_exception)
208 208 load_global_pointer
209 209
210 210 /* Load the kernel shadow call stack pointer if coming from userspace */
211 - scs_load_current_if_from_user s1, s5
211 + scs_load_current_if_task_changed s5
212 212
213 213 #ifdef CONFIG_RISCV_ISA_V_PREEMPTIVE
214 214 move a0, sp
modified arch/riscv/kernel/patch.c
@@ -48,7 +48,7 @@ static __always_inline void *patch_map(void *addr, const unsigned int fixmap)
48 48 if (!IS_ENABLED(CONFIG_STRICT_KERNEL_RWX))
49 49 return addr;
50 50 phys = __pa_symbol(addr);
51 - } else if (IS_ENABLED(CONFIG_EXECMEM)) {
51 + } else if (IS_ENABLED(CONFIG_STRICT_MODULE_RWX)) {
52 52 struct page *page = vmalloc_to_page(addr);
53 53
54 54 BUG_ON(!page);
modified arch/riscv/kernel/ptrace.c
@@ -230,7 +230,6 @@ static int riscv_vr_set(struct task_struct *target,
230 230 return -ENODATA;
231 231
232 232 /* Copy rest of the vstate except datap */
233 - memset(&ptrace_vstate, 0, sizeof(ptrace_vstate));
234 233 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &ptrace_vstate, 0,
235 234 sizeof(struct __riscv_v_regset_state));
236 235 if (unlikely(ret))
@@ -300,9 +299,6 @@ static int riscv_cfi_get(struct task_struct *target,
300 299 struct user_cfi_state user_cfi;
301 300 struct pt_regs *regs;
302 301
303 - if (!is_user_lpad_enabled() && !is_user_shstk_enabled())
304 - return -EINVAL;
305 -
306 302 memset(&user_cfi, 0, sizeof(user_cfi));
307 303 regs = task_pt_regs(target);
308 304
@@ -341,12 +337,8 @@ static int riscv_cfi_set(struct task_struct *target,
341 337 struct user_cfi_state user_cfi;
342 338 struct pt_regs *regs;
343 339
344 - if (!is_user_lpad_enabled() && !is_user_shstk_enabled())
345 - return -EINVAL;
346 -
347 340 regs = task_pt_regs(target);
348 341
349 - memset(&user_cfi, 0, sizeof(user_cfi));
350 342 ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &user_cfi, 0, -1);
351 343 if (ret)
352 344 return ret;
modified arch/riscv/kernel/setup.c
@@ -366,8 +366,6 @@ void __init setup_arch(char **cmdline_p)
366 366
367 367 if (!IS_ENABLED(CONFIG_RISCV_ISA_ZBB) || !riscv_isa_extension_available(NULL, ZBB))
368 368 static_branch_disable(&efficient_ffs_key);
369 -
370 - riscv_clear_hypervisor_csr();
371 369 }
372 370
373 371 bool arch_cpu_is_hotpluggable(int cpu)
modified arch/riscv/kernel/smpboot.c
@@ -244,8 +244,6 @@ asmlinkage __visible void smp_callin(void)
244 244
245 245 numa_add_cpu(curr_cpuid);
246 246
247 - riscv_clear_hypervisor_csr();
248 -
249 247 pr_debug("CPU%u: Booted secondary hartid %lu\n", curr_cpuid,
250 248 cpuid_to_hartid_map(curr_cpuid));
251 249
modified arch/riscv/kernel/suspend.c
@@ -43,8 +43,6 @@ void suspend_save_csrs(struct suspend_context *context)
43 43
44 44 void suspend_restore_csrs(struct suspend_context *context)
45 45 {
46 - riscv_clear_hypervisor_csr();
47 -
48 46 csr_write(CSR_SCRATCH, 0);
49 47 if (riscv_has_extension_unlikely(RISCV_ISA_EXT_XLINUXENVCFG))
50 48 csr_write(CSR_ENVCFG, context->envcfg);
modified arch/riscv/lib/strnlen.S
@@ -87,25 +87,9 @@ strnlen_zbb:
87 87 * Aligned boundary. Use the address of the last valid byte
88 88 * (s + count - 1) to avoid loading a word past the count
89 89 * boundary in the loop below. count == 0 is handled above.
90 - *
91 - * Saturate the boundary when s + count would wrap around (very
92 - * large counts, e.g. SIZE_MAX passed by FORTIFY strcat/strlcat
93 - * with a destination whose size is unknown at compile time).
94 - * Without this, the wrapped boundary lands before s and the
95 - * pre-loop guard below always exits, returning a truncated
96 - * length.
97 - *
98 - * Clamping the increment to ~s (== SIZE_MAX - s) keeps the
99 - * computation branchless and wrap-free:
100 - *
101 - * s + min(count - 1, ~s) == saturating_add(s, count - 1)
102 - *
103 - * Saturating makes the scan equivalent to strlen().
104 90 */
105 - addi t4, a1, -1 /* count - 1 */
106 - not t1, a0 /* SIZE_MAX - s */
107 - minu t4, t4, t1 /* clamp, so s + t4 can never wrap */
108 - add t4, a0, t4 /* saturated s + count - 1 */
91 + add t4, a0, a1
92 + addi t4, t4, -1
109 93 andi t4, t4, -SZREG
110 94
111 95 /* Get the first word. */
modified arch/riscv/mm/extable.c
@@ -68,8 +68,8 @@ ex_handler_load_unaligned_zeropad(const struct exception_table_entry *ex,
68 68
69 69 addr = regs_get_gpr(regs, reg_addr * sizeof(unsigned long));
70 70
71 - offset = addr & (sizeof(data) - 1);
72 - addr &= ~(sizeof(data) - 1);
71 + offset = addr & 0x7UL;
72 + addr &= ~0x7UL;
73 73
74 74 data = *(unsigned long *)addr >> (offset * 8);
75 75
modified arch/um/drivers/vector_transports.c
@@ -209,7 +209,6 @@ static int raw_verify_header(
209 209 if ((vheader->flags & VIRTIO_NET_HDR_F_DATA_VALID) > 0)
210 210 return 1;
211 211
212 - skb_set_network_header(skb, ETH_HLEN);
213 212 virtio_net_hdr_to_skb(skb, vheader, virtio_legacy_is_little_endian());
214 213 return 0;
215 214 }
modified arch/x86/include/asm/cpufeatures.h
@@ -477,8 +477,6 @@
477 477 #define X86_FEATURE_NO_NESTED_DATA_BP (20*32+ 0) /* No Nested Data Breakpoints */
478 478 #define X86_FEATURE_WRMSR_XX_BASE_NS (20*32+ 1) /* WRMSR to {FS,GS,KERNEL_GS}_BASE is non-serializing */
479 479 #define X86_FEATURE_LFENCE_RDTSC (20*32+ 2) /* LFENCE always serializing / synchronizes RDTSC */
480 -
481 - #define X86_FEATURE_TLBSYNC_SFW_NO (20*32+ 4) /* TLBI Erratum #1718 fixed in microcode */
482 480 #define X86_FEATURE_VERW_CLEAR (20*32+ 5) /* The memory form of VERW mitigates TSA */
483 481 #define X86_FEATURE_NULL_SEL_CLR_BASE (20*32+ 6) /* Null Selector Clears Base */
484 482
@@ -589,5 +587,4 @@
589 587 #define X86_BUG_TSA X86_BUG( 1*32+ 9) /* "tsa" CPU is affected by Transient Scheduler Attacks */
590 588 #define X86_BUG_VMSCAPE X86_BUG( 1*32+10) /* "vmscape" CPU is affected by VMSCAPE attacks from guests */
591 589 #define X86_BUG_SEAMRET_INVD_VMCS X86_BUG( 1*32+11) /* "seamret_invd_vmcs" SEAMRET from P-SEAMLDR clears the current VMCS */
592 - #define X86_BUG_TLBI X86_BUG( 1*32+12) /* "tlbi" AMD TLBI Erratum #1718 */
593 590 #endif /* _ASM_X86_CPUFEATURES_H */
modified arch/x86/include/asm/tlb.h
@@ -110,12 +110,6 @@ static inline void __tlbsync(void)
110 110
111 111 /* TLBSYNC: supported in binutils >= 0.36. */
112 112 asm volatile(".byte 0x0f, 0x01, 0xff" ::: "memory");
113 -
114 - if (!static_cpu_has_bug(X86_BUG_TLBI))
115 - return;
116 -
117 - /* TLBSYNC: supported in binutils >= 0.36. */
118 - asm volatile(".byte 0x0f, 0x01, 0xff" ::: "memory");
119 113 }
120 114 #else
121 115 /* Some compilers (I'm looking at you clang!) simply can't do DCE */
modified arch/x86/kernel/cpu/amd.c
@@ -1049,10 +1049,6 @@ static void init_amd_zen5(struct cpuinfo_x86 *c)
1049 1049 msr_clear_bit(MSR_AMD64_CPUID_FN_7, 18);
1050 1050 pr_emerg_once("RDSEED32 is broken. Disabling the corresponding CPUID bit.\n");
1051 1051 }
1052 -
1053 - if (cpu_has(c, X86_FEATURE_INVLPGB) &&
1054 - !cpu_has(c, X86_FEATURE_TLBSYNC_SFW_NO))
1055 - set_cpu_bug(c, X86_BUG_TLBI);
1056 1052 }
1057 1053
1058 1054 static void init_amd(struct cpuinfo_x86 *c)
modified drivers/accessibility/braille/braille_console.c
@@ -62,50 +62,14 @@ static void braille_write(u16 *buf)
62 62 {
63 63 static u16 lastwrite[WIDTH];
64 64 unsigned char data[1 + 1 + 2*WIDTH + 2 + 1], csum = 0, *c;
65 - struct nbcon_write_context wctxt = { };
66 - unsigned long flags;
67 65 u16 out;
68 66 int i;
69 67
70 68 if (!braille_co)
71 69 return;
72 70
73 - /*
74 - * Braille console is not registered in console_list. Instead, it
75 - * is integrated with VT and shows what appears on the graphical
76 - * console under console_lock(). From this POV it is a legacy
77 - * console. But it calls serial console driver which might be
78 - * converted to the NBCON API. It is similar to
79 - * nbcon_legacy_emit_next_record() except that we should try
80 - * harder to get the lock. Otherwise, the Braille device won't show
81 - * everything what is displayed on the terminal.
82 - *
83 - * In short, simulate the original locking using NBCON API.
84 - */
85 - if (braille_co->flags & CON_NBCON) {
86 - if (panic_on_this_cpu()) {
87 - /*
88 - * This should be good enough in practice. Most/all
89 - * serial console drivers have the atomic callback.
90 - */
91 - if (!braille_co->write_atomic)
92 - return;
93 -
94 - local_irq_save(flags);
95 - /* NBCON API strictly requires the ownership. */
96 - if (!nbcon_braille_try_acquire(braille_co, &wctxt)) {
97 - local_irq_restore(flags);
98 - return;
99 - }
100 - } else {
101 - braille_co->device_lock(braille_co, &flags);
102 - while (!nbcon_braille_try_acquire(braille_co, &wctxt))
103 - cpu_relax();
104 - }
105 - }
106 -
107 71 if (!memcmp(lastwrite, buf, WIDTH * sizeof(*buf)))
108 - goto unlock_nbcon;
72 + return;
109 73 memcpy(lastwrite, buf, WIDTH * sizeof(*buf));
110 74
111 75 #define SOH 1
@@ -138,24 +102,7 @@ static void braille_write(u16 *buf)
138 102 *c++ = csum;
139 103 *c++ = ETX;
140 104
141 - if (braille_co->flags & CON_NBCON) {
142 - nbcon_write_context_set_buf(&wctxt, (char *)data, c - data);
143 - if (panic_on_this_cpu())
144 - braille_co->write_atomic(braille_co, &wctxt);
145 - else
146 - braille_co->write_thread(braille_co, &wctxt);
147 - } else {
148 - braille_co->write(braille_co, data, c - data);
149 - }
150 -
151 - unlock_nbcon:
152 - if (braille_co->flags & CON_NBCON) {
153 - nbcon_braille_release(&wctxt);
154 - if (panic_on_this_cpu())
155 - local_irq_restore(flags);
156 - else
157 - braille_co->device_unlock(braille_co, flags);
158 - }
105 + braille_co->write(braille_co, data, c - data);
159 106 }
160 107
161 108 /* Follow the VC cursor*/
modified drivers/ata/libata-scsi.c
@@ -3059,15 +3059,10 @@ static void atapi_qc_complete(struct ata_queued_cmd *qc)
3059 3059 if (qc->cdb[0] == ALLOW_MEDIUM_REMOVAL && qc->dev->sdev)
3060 3060 qc->dev->sdev->locked = 0;
3061 3061
3062 - /*
3063 - * Report CHECK CONDITION unless the command was terminated
3064 - * with a host byte set. Only set the status byte, so that the
3065 - * SCSI midlayer internal byte, which scsi_check_sense() may
3066 - * have set from the sense data, is preserved.
3067 - */
3068 - if (get_host_byte(cmd) == DID_OK)
3069 - set_status_byte(cmd, SAM_STAT_CHECK_CONDITION);
3070 - ata_scsi_qc_done(qc, false, 0);
3062 + if (cmd->result)
3063 + ata_scsi_qc_done(qc, false, 0);
3064 + else
3065 + ata_scsi_qc_done(qc, true, SAM_STAT_CHECK_CONDITION);
3071 3066 goto schedule_deferred;
3072 3067 }
3073 3068
modified drivers/block/zloop.c
@@ -800,27 +800,6 @@ static void zloop_cmd_workfn(struct work_struct *work)
800 800 current->flags = orig_flags;
801 801 }
802 802
803 - static void zloop_fill_zero_rq(struct request *rq, unsigned int zero_from)
804 - {
805 - struct req_iterator iter;
806 - struct bio_vec bv;
807 - unsigned int pos = 0;
808 - unsigned int end, off;
809 -
810 - rq_for_each_segment(bv, rq, iter) {
811 - end = pos + bv.bv_len;
812 - if (end > zero_from) {
813 - if (pos < zero_from)
814 - off = zero_from - pos;
815 - else
816 - off = 0;
817 - memzero_page(bv.bv_page, bv.bv_offset + off,
818 - bv.bv_len - off);
819 - }
820 - pos = end;
821 - }
822 - }
823 -
824 803 static void zloop_complete_rq(struct request *rq)
825 804 {
826 805 struct zloop_cmd *cmd = blk_mq_rq_to_pdu(rq);
@@ -835,9 +814,13 @@ static void zloop_complete_rq(struct request *rq)
835 814 pr_err("Zone %u: failed read sector %llu, %llu sectors\n",
836 815 zone_no, cmd->sector, cmd->nr_sectors);
837 816
838 - /* Short read. Zero out the unread tail beyond cmd->ret. */
839 - if (cmd->ret >= 0 && cmd->ret != blk_rq_bytes(rq))
840 - zloop_fill_zero_rq(rq, cmd->ret);
817 + if (cmd->ret >= 0 && cmd->ret != blk_rq_bytes(rq)) {
818 + /* short read */
819 + struct bio *bio;
820 +
821 + __rq_for_each_bio(bio, rq)
822 + zero_fill_bio(bio);
823 + }
841 824 break;
842 825 case REQ_OP_WRITE:
843 826 case REQ_OP_ZONE_APPEND:
modified drivers/bluetooth/btintel_pcie.c
@@ -401,7 +401,7 @@ static int btintel_pcie_send_sync(struct btintel_pcie_data *data,
401 401
402 402 tfd_index = data->ia.tr_hia[BTINTEL_PCIE_TXQ_NUM];
403 403
404 - if (tfd_index >= txq->count)
404 + if (tfd_index > txq->count)
405 405 return -ERANGE;
406 406
407 407 if (skb->len > BTINTEL_PCIE_BUFFER_SIZE - BTINTEL_PCIE_HCI_TYPE_LEN) {
@@ -1777,7 +1777,7 @@ static irqreturn_t btintel_pcie_irq_msix_handler(int irq, void *dev_id)
1777 1777 static int btintel_pcie_setup_irq(struct btintel_pcie_data *data)
1778 1778 {
1779 1779 int err;
1780 - int num_irqs, i, j;
1780 + int num_irqs, i;
1781 1781
1782 1782 for (i = 0; i < BTINTEL_PCIE_MSIX_VEC_MAX; i++)
1783 1783 data->msix_entries[i].entry = i;
@@ -1806,10 +1806,6 @@ static int btintel_pcie_setup_irq(struct btintel_pcie_data *data)
1806 1806 KBUILD_MODNAME,
1807 1807 msix_entry);
1808 1808 if (err) {
1809 - for (j = 0; j < i; j++)
1810 - devm_free_irq(&data->pdev->dev,
1811 - data->msix_entries[j].vector,
1812 - &data->msix_entries[j]);
1813 1809 pci_free_irq_vectors(data->pdev);
1814 1810 data->alloc_vecs = 0;
1815 1811 return err;
@@ -1881,13 +1877,6 @@ static int btintel_pcie_config_pcie(struct pci_dev *pdev,
1881 1877 if (IS_ERR(data->base_addr))
1882 1878 return PTR_ERR(data->base_addr);
1883 1879
1884 - /* Do shared hardware reset to ensure a clean start before
1885 - * configuring interrupts.
1886 - */
1887 - err = btintel_pcie_reset_bt(data);
1888 - if (err)
1889 - return err;
1890 -
1891 1880 err = btintel_pcie_setup_irq(data);
1892 1881 if (err)
1893 1882 return err;
@@ -3149,7 +3138,7 @@ static void btintel_pcie_remove(struct pci_dev *pdev)
3149 3138 struct msix_entry *msix_entry;
3150 3139
3151 3140 msix_entry = &data->msix_entries[i];
3152 - devm_free_irq(&pdev->dev, msix_entry->vector, msix_entry);
3141 + free_irq(msix_entry->vector, msix_entry);
3153 3142 }
3154 3143
3155 3144 pci_free_irq_vectors(pdev);
modified drivers/char/mem.c
@@ -503,7 +503,7 @@ static int mmap_zero_prepare(struct vm_area_desc *desc)
503 503 #ifndef CONFIG_MMU
504 504 return -ENOSYS;
505 505 #endif
506 - if (vma_desc_test(desc, VMA_MAYSHARE_BIT))
506 + if (vma_desc_test(desc, VMA_SHARED_BIT))
507 507 return shmem_zero_setup_desc(desc);
508 508
509 509 /*
modified drivers/clk/qcom/gcc-eliza.c
@@ -3010,6 +3010,8 @@ static const u32 gcc_eliza_critical_cbcrs[] = {
3010 3010 0x26034, /* GCC_CAMERA_XO_CLK */
3011 3011 0x27004, /* GCC_DISP_AHB_CLK */
3012 3012 0x71004, /* GCC_GPU_CFG_AHB_CLK */
3013 + 0x52010, /* GCC_PCIE_RSCC_CFG_AHB_CLK */
3014 + 0x52010, /* GCC_PCIE_RSCC_XO_CLK */
3013 3015 0x32004, /* GCC_VIDEO_AHB_CLK */
3014 3016 0x32038, /* GCC_VIDEO_XO_CLK */
3015 3017 };
@@ -3043,10 +3045,6 @@ static const struct regmap_config gcc_eliza_regmap_config = {
3043 3045
3044 3046 static void clk_eliza_regs_configure(struct device *dev, struct regmap *regmap)
3045 3047 {
3046 - /* Keep clocks always enabled */
3047 - regmap_update_bits(regmap, 0x52010, BIT(20), BIT(20)); /* GCC_PCIE_RSCC_CFG_AHB_CLK */
3048 - regmap_update_bits(regmap, 0x52010, BIT(21), BIT(21)); /* GCC_PCIE_RSCC_XO_CLK */
3049 -
3050 3048 /* FORCE_MEM_CORE_ON for ufs phy ice core and gcc ufs phy axi clocks */
3051 3049 qcom_branch_set_force_mem_core(regmap, gcc_ufs_phy_ice_core_clk, true);
3052 3050 qcom_branch_set_force_mem_core(regmap, gcc_ufs_phy_axi_clk, true);
modified drivers/clk/qcom/gcc-hawi.c
@@ -3692,6 +3692,8 @@ static const u32 gcc_hawi_critical_cbcrs[] = {
3692 3692 0x67084, /* GCC_PCIE_1_RSC_CORE_CLK */
3693 3693 0x43014, /* GCC_PCIE_LINK_XO_CLK */
3694 3694 0x6b088, /* GCC_PCIE_RSC_CORE_CLK */
3695 + 0x52010, /* GCC_PCIE_RSCC_CFG_AHB_CLK */
3696 + 0x52010, /* GCC_PCIE_RSCC_XO_CLK */
3695 3697 0x32004, /* GCC_VIDEO_AHB_CLK */
3696 3698 0x32028, /* GCC_VIDEO_XO_CLK */
3697 3699 };
@@ -3761,10 +3763,6 @@ static const struct regmap_config gcc_hawi_regmap_config = {
3761 3763
3762 3764 static void clk_hawi_regs_configure(struct device *dev, struct regmap *regmap)
3763 3765 {
3764 - /* Keep clocks always enabled */
3765 - regmap_update_bits(regmap, 0x52010, BIT(20), BIT(20)); /* GCC_PCIE_RSCC_CFG_AHB_CLK */
3766 - regmap_update_bits(regmap, 0x52010, BIT(21), BIT(21)); /* GCC_PCIE_RSCC_XO_CLK */
3767 -
3768 3766 /* FORCE_MEM_CORE_ON for ufs phy ice core clocks */
3769 3767 qcom_branch_set_force_mem_core(regmap, gcc_ufs_phy_ice_core_clk, true);
3770 3768 }
modified drivers/clk/qcom/gcc-kaanapali.c
@@ -3464,6 +3464,8 @@ static const u32 gcc_kaanapali_critical_cbcrs[] = {
3464 3464 0x9f004, /* GCC_EVA_AHB_CLK */
3465 3465 0x9f024, /* GCC_EVA_XO_CLK */
3466 3466 0x71004, /* GCC_GPU_CFG_AHB_CLK */
3467 + 0x52010, /* GCC_PCIE_RSCC_CFG_AHB_CLK */
3468 + 0x52010, /* GCC_PCIE_RSCC_XO_CLK */
3467 3469 0x32004, /* GCC_VIDEO_AHB_CLK */
3468 3470 0x32040, /* GCC_VIDEO_XO_CLK */
3469 3471 };
@@ -3478,10 +3480,6 @@ static const struct regmap_config gcc_kaanapali_regmap_config = {
3478 3480
3479 3481 static void clk_kaanapali_regs_configure(struct device *dev, struct regmap *regmap)
3480 3482 {
3481 - /* Keep clocks always enabled */
3482 - regmap_update_bits(regmap, 0x52010, BIT(20), BIT(20)); /* GCC_PCIE_RSCC_CFG_AHB_CLK */
3483 - regmap_update_bits(regmap, 0x52010, BIT(21), BIT(21)); /* GCC_PCIE_RSCC_XO_CLK */
3484 -
3485 3483 /* FORCE_MEM_CORE_ON for ufs phy ice core clocks */
3486 3484 qcom_branch_set_force_mem_core(regmap, gcc_ufs_phy_ice_core_clk, true);
3487 3485 }
modified drivers/clk/qcom/gpucc-glymur.c
@@ -510,7 +510,7 @@ static struct gdsc gpu_cc_cx_gdsc = {
510 510 .name = "gpu_cc_cx_gdsc",
511 511 },
512 512 .pwrsts = PWRSTS_OFF_ON,
513 - .flags = RETAIN_FF_ENABLE | VOTABLE,
513 + .flags = POLL_CFG_GDSCR | RETAIN_FF_ENABLE,
514 514 };
515 515
516 516 static struct clk_regmap *gpu_cc_glymur_clocks[] = {
modified drivers/clk/qcom/gpucc-kaanapali.c
@@ -380,7 +380,7 @@ static struct gdsc gpu_cc_cx_gdsc = {
380 380 .name = "gpu_cc_cx_gdsc",
381 381 },
382 382 .pwrsts = PWRSTS_OFF_ON,
383 - .flags = RETAIN_FF_ENABLE | VOTABLE,
383 + .flags = POLL_CFG_GDSCR | RETAIN_FF_ENABLE,
384 384 };
385 385
386 386 static struct clk_regmap *gpu_cc_kaanapali_clocks[] = {
modified drivers/edac/amd64_edac.c
@@ -2796,13 +2796,13 @@ static inline void decode_bus_error(int node_id, struct mce *m)
2796 2796 * the instance_id. For example, instance_id=0xYXXXXX where Y is the channel
2797 2797 * number.
2798 2798 *
2799 - * For DRAM ECC errors, the Chip Select number is given in bits [1:0] of
2799 + * For DRAM ECC errors, the Chip Select number is given in bits [2:0] of
2800 2800 * the MCA_SYND[ErrorInformation] field.
2801 2801 */
2802 2802 static void umc_get_err_info(struct mce *m, struct err_info *err)
2803 2803 {
2804 2804 err->channel = (m->ipid & GENMASK(31, 0)) >> 20;
2805 - err->csrow = m->synd & 0x3;
2805 + err->csrow = m->synd & 0x7;
2806 2806 }
2807 2807
2808 2808 static void decode_umc_error(int node_id, struct mce *m)
modified drivers/gpio/gpio-exar.c
@@ -199,7 +199,6 @@ static int gpio_exar_probe(struct platform_device *pdev)
199 199 index = ida_alloc(&ida_index, GFP_KERNEL);
200 200 if (index < 0)
201 201 return index;
202 - exar_gpio->index = index;
203 202
204 203 ret = devm_add_action_or_reset(dev, exar_devm_ida_free, exar_gpio);
205 204 if (ret)
@@ -215,6 +214,7 @@ static int gpio_exar_probe(struct platform_device *pdev)
215 214 exar_gpio->gpio_chip.set = exar_set_value;
216 215 exar_gpio->gpio_chip.base = -1;
217 216 exar_gpio->gpio_chip.ngpio = ngpios;
217 + exar_gpio->index = index;
218 218 exar_gpio->first_pin = first_pin;
219 219
220 220 ret = devm_gpiochip_add_data(dev, &exar_gpio->gpio_chip, exar_gpio);
modified drivers/gpio/gpio-mpsse.c
@@ -10,7 +10,6 @@
10 10 #include <linux/cleanup.h>
11 11 #include <linux/gpio/driver.h>
12 12 #include <linux/mutex.h>
13 - #include <linux/rcupdate.h>
14 13 #include <linux/spinlock.h>
15 14 #include <linux/usb.h>
16 15
@@ -25,7 +24,6 @@ struct mpsse_priv {
25 24 raw_spinlock_t irq_spin; /* protects worker list */
26 25 atomic_t irq_type[16]; /* pin -> edge detection type */
27 26 atomic_t irq_enabled;
28 - atomic_t dying; /* no new workers after disconnect */
29 27 int id;
30 28
31 29 u8 gpio_outputs[2]; /* Output states for GPIOs [L, H] */
@@ -48,7 +46,6 @@ struct mpsse_worker {
48 46 atomic_t cancelled;
49 47 struct list_head list; /* linked list */
50 48 struct list_head destroy; /* teardown linked list */
51 - struct rcu_head rcu; /* deferred free for dying path */
52 49 };
53 50
54 51 struct bulk_desc {
@@ -528,24 +525,10 @@ static void gpio_mpsse_irq_enable(struct irq_data *irqd)
528 525 worker->priv = priv;
529 526 INIT_LIST_HEAD(&worker->list);
530 527 INIT_WORK(&worker->work, gpio_mpsse_poll);
528 + schedule_work(&worker->work);
531 529
532 - scoped_guard(raw_spinlock_irqsave, &priv->irq_spin) {
533 - if (atomic_read(&priv->dying)) {
534 - /*
535 - * Cannot kfree() here: this callback
536 - * runs with the IRQ descriptor's raw
537 - * spinlock held and kfree() may sleep
538 - * on PREEMPT_RT. The worker is not
539 - * yet published, so the deferred free
540 - * is unobservable.
541 - */
542 - kfree_rcu(worker, rcu);
543 - return;
544 - }
545 -
530 + scoped_guard(raw_spinlock_irqsave, &priv->irq_spin)
546 531 list_add(&worker->list, &priv->workers);
547 - schedule_work(&worker->work);
548 - }
549 532 }
550 533 }
551 534
@@ -721,9 +704,6 @@ static void gpio_mpsse_disconnect(struct usb_interface *intf)
721 704 {
722 705 struct mpsse_priv *priv = usb_get_intfdata(intf);
723 706
724 - scoped_guard(raw_spinlock_irqsave, &priv->irq_spin)
725 - atomic_set(&priv->dying, 1);
726 -
727 707 /*
728 708 * Lock prevents double-free of worker from here and the teardown
729 709 * step at the beginning of gpio_mpsse_poll
modified drivers/gpio/gpio-xilinx.c
@@ -271,7 +271,14 @@ static void xgpio_save_regs(struct xgpio_instance *chip)
271 271
272 272 static int xgpio_request(struct gpio_chip *chip, unsigned int offset)
273 273 {
274 - return pm_runtime_resume_and_get(chip->parent);
274 + int ret;
275 +
276 + ret = pm_runtime_get_sync(chip->parent);
277 + /*
278 + * If the device is already active pm_runtime_get() will return 1 on
279 + * success, but gpio_request still needs to return 0.
280 + */
281 + return ret < 0 ? ret : 0;
275 282 }
276 283
277 284 static void xgpio_free(struct gpio_chip *chip, unsigned int offset)
modified drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -598,18 +598,14 @@ int amdgpu_amdkfd_get_dmabuf_info(struct amdgpu_device *adev, int dma_buf_fd,
598 598 /* first get metadata_size by buffer = NULL */
599 599 r = amdgpu_bo_get_metadata(bo, NULL, 0,
600 600 metadata_size, NULL);
601 - if (r)
602 - goto out_put;
603 601
604 602 /* user buf_size is bigger than bo metadata_size
605 603 * allocate a buf at kernel space and copy */
606 604 if (*metadata_size <= buffer_size) {
607 605 *metadata_buffer = kzalloc(*metadata_size, GFP_KERNEL);
608 606
609 - if (!*metadata_buffer) {
610 - r = -ENOMEM;
611 - goto out_put;
612 - }
607 + if (!*metadata_buffer)
608 + return -ENOMEM;
613 609
614 610 r = amdgpu_bo_get_metadata(bo, *metadata_buffer, *metadata_size,
615 611 NULL, &metadata_flags);
modified drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
@@ -121,20 +121,6 @@ static int amdgpu_debugfs_process_reg_op(bool read, struct file *f,
121 121
122 122 *pos &= (1UL << 22) - 1;
123 123
124 - if (size > PAGE_SIZE)
125 - return -EINVAL;
126 -
127 - /*
128 - * Access the user buffer only while none of the locks below are held:
129 - * a fault takes mmap_lock, and grbm_idx_mutex and srbm_mutex nest
130 - * inside it.
131 - */
132 - u32 *data __free(kfree) = kmalloc(size, GFP_KERNEL);
133 - if (!data)
134 - return -ENOMEM;
135 - if (!read && copy_from_user(data, buf, size))
136 - return -EFAULT;
137 -
138 124 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
139 125 if (r < 0) {
140 126 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -166,16 +152,28 @@ static int amdgpu_debugfs_process_reg_op(bool read, struct file *f,
166 152 mutex_lock(&adev->pm.mutex);
167 153
168 154 while (size) {
169 - if (read)
170 - data[result >> 2] = RREG32(*pos >> 2);
171 - else
172 - amdgpu_mm_wreg_mmio_rlc(adev, *pos >> 2, data[result >> 2], 0);
155 + uint32_t value;
156 +
157 + if (read) {
158 + value = RREG32(*pos >> 2);
159 + r = put_user(value, (uint32_t *)buf);
160 + } else {
161 + r = get_user(value, (uint32_t *)buf);
162 + if (!r)
163 + amdgpu_mm_wreg_mmio_rlc(adev, *pos >> 2, value, 0);
164 + }
165 + if (r) {
166 + result = r;
167 + goto end;
168 + }
173 169
174 170 result += 4;
171 + buf += 4;
175 172 *pos += 4;
176 173 size -= 4;
177 174 }
178 175
176 + end:
179 177 if (use_bank) {
180 178 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, 0);
181 179 mutex_unlock(&adev->grbm_idx_mutex);
@@ -190,10 +188,6 @@ static int amdgpu_debugfs_process_reg_op(bool read, struct file *f,
190 188 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
191 189
192 190 amdgpu_virt_disable_access_debugfs(adev);
193 -
194 - if (read && copy_to_user(buf, data, result))
195 - return -EFAULT;
196 -
197 191 return result;
198 192 }
199 193
@@ -244,24 +238,11 @@ static ssize_t amdgpu_debugfs_regs2_op(struct file *f, char __user *buf, u32 off
244 238 struct amdgpu_device *adev = rd->adev;
245 239 ssize_t result = 0;
246 240 int r;
241 + uint32_t value;
247 242
248 243 if (size & 0x3 || offset & 0x3)
249 244 return -EINVAL;
250 245
251 - if (size > PAGE_SIZE)
252 - return -EINVAL;
253 -
254 - /*
255 - * Access the user buffer only while none of the locks below are held:
256 - * a fault takes mmap_lock, and grbm_idx_mutex and srbm_mutex nest
257 - * inside it.
258 - */
259 - u32 *data __free(kfree) = kmalloc(size, GFP_KERNEL);
260 - if (!data)
261 - return -ENOMEM;
262 - if (write_en && copy_from_user(data, buf, size))
263 - return -EFAULT;
264 -
265 246 r = pm_runtime_get_sync(adev_to_drm(adev)->dev);
266 247 if (r < 0) {
267 248 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
@@ -300,16 +281,24 @@ static ssize_t amdgpu_debugfs_regs2_op(struct file *f, char __user *buf, u32 off
300 281 mutex_lock(&adev->pm.mutex);
301 282
302 283 while (size) {
303 - if (!write_en)
304 - data[result >> 2] = RREG32(offset >> 2);
305 - else
306 - amdgpu_mm_wreg_mmio_rlc(adev, offset >> 2, data[result >> 2],
307 - rd->id.xcc_id);
284 + if (!write_en) {
285 + value = RREG32(offset >> 2);
286 + r = put_user(value, (uint32_t *)buf);
287 + } else {
288 + r = get_user(value, (uint32_t *)buf);
289 + if (!r)
290 + amdgpu_mm_wreg_mmio_rlc(adev, offset >> 2, value, rd->id.xcc_id);
291 + }
292 + if (r) {
293 + result = r;
294 + goto end;
295 + }
308 296 offset += 4;
309 297 size -= 4;
310 298 result += 4;
299 + buf += 4;
311 300 }
312 -
301 + end:
313 302 if (rd->id.use_grbm) {
314 303 amdgpu_gfx_select_se_sh(adev, 0xffffffff, 0xffffffff, 0xffffffff, rd->id.xcc_id);
315 304 mutex_unlock(&adev->grbm_idx_mutex);
@@ -328,10 +317,6 @@ static ssize_t amdgpu_debugfs_regs2_op(struct file *f, char __user *buf, u32 off
328 317 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
329 318
330 319 amdgpu_virt_disable_access_debugfs(adev);
331 -
332 - if (!write_en && copy_to_user(buf, data, result))
333 - return -EFAULT;
334 -
335 320 return result;
336 321 }
337 322
modified drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c
@@ -1080,17 +1080,20 @@ void amdgpu_gmc_init_vga_resv_regions(struct amdgpu_device *adev)
1080 1080 case CHIP_RENOIR:
1081 1081 adev->mman.keep_stolen_vga_memory = true;
1082 1082 break;
1083 + case CHIP_POLARIS10:
1084 + case CHIP_POLARIS11:
1085 + case CHIP_POLARIS12:
1086 + /* MacBookPros with switchable graphics put VRAM at 0 when
1087 + * the iGPU is enabled which results in cursor issues if
1088 + * the cursor ends up at 0. Reserve vram at 0 in that case.
1089 + */
1090 + if (adev->gmc.vram_start == 0)
1091 + adev->mman.keep_stolen_vga_memory = true;
1092 + break;
1083 1093 default:
1084 1094 adev->mman.keep_stolen_vga_memory = false;
1085 1095 break;
1086 1096 }
1087 - /* MacBookPros with switchable graphics put VRAM at 0 when
1088 - * the iGPU is enabled which results in cursor issues if
1089 - * the cursor ends up at 0. Reserve vram at 0 in that case.
1090 - */
1091 - if ((adev->pdev->subsystem_vendor == PCI_VENDOR_ID_APPLE) &&
1092 - (adev->gmc.vram_start == 0))
1093 - adev->mman.keep_stolen_vga_memory = true;
1094 1097
1095 1098 if (amdgpu_sriov_vf(adev) ||
1096 1099 !amdgpu_device_has_display_hardware(adev)) {
modified drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -30,7 +30,6 @@
30 30 #include <drm/amdgpu_drm.h>
31 31 #include <drm/drm_drv.h>
32 32 #include <drm/drm_fb_helper.h>
33 - #include <drm/drm_vblank.h>
34 33 #include "amdgpu_uvd.h"
35 34 #include "amdgpu_vce.h"
36 35 #include "atom.h"
@@ -1661,9 +1660,6 @@ u32 amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc)
1661 1660 DRM_ERROR("Invalid crtc %u\n", pipe);
1662 1661 return -EINVAL;
1663 1662 }
1664 - if (!down_read_trylock(&adev->reset_domain->sem))
1665 - return drm_crtc_vblank_count(crtc);
1666 -
1667 1663
1668 1664 /* The hw increments its frame counter at start of vsync, not at start
1669 1665 * of vblank, as is required by DRM core vblank counter handling.
@@ -1709,7 +1705,6 @@ u32 amdgpu_get_vblank_counter_kms(struct drm_crtc *crtc)
1709 1705 DRM_DEBUG_VBL("NULL mode info! Returned count may be wrong.\n");
1710 1706 }
1711 1707
1712 - up_read(&adev->reset_domain->sem);
1713 1708 return count;
1714 1709 }
1715 1710
modified drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -472,7 +472,6 @@ amdgpu_userq_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
472 472 u64 doorbell_index;
473 473 struct drm_gem_object *gobj;
474 474 struct amdgpu_userq_obj *db_obj = db_info->db_obj;
475 - struct amdgpu_bo *abo;
476 475 int r, db_size;
477 476
478 477 gobj = drm_gem_object_lookup(filp, db_info->doorbell_handle);
@@ -481,17 +480,7 @@ amdgpu_userq_get_doorbell_index(struct amdgpu_userq_mgr *uq_mgr,
481 480 return -EINVAL;
482 481 }
483 482
484 - /*
485 - * Pinning a regular BO into the doorbell domain would discard its
486 - * contents, possibly those of a buffer shared by another client.
487 - */
488 - abo = gem_to_amdgpu_bo(gobj);
489 - if (!(abo->preferred_domains & AMDGPU_GEM_DOMAIN_DOORBELL)) {
490 - drm_gem_object_put(gobj);
491 - return -EINVAL;
492 - }
493 -
494 - db_obj->obj = amdgpu_bo_ref(abo);
483 + db_obj->obj = amdgpu_bo_ref(gem_to_amdgpu_bo(gobj));
495 484 drm_gem_object_put(gobj);
496 485
497 486 r = amdgpu_bo_reserve(db_obj->obj, true);
modified drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
@@ -361,7 +361,8 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
361 361
362 362 compute_mqd = memdup_user(u64_to_user_ptr(mqd_user->mqd), mqd_user->mqd_size);
363 363 if (IS_ERR(compute_mqd)) {
364 - r = PTR_ERR(compute_mqd);
364 + DRM_ERROR("Failed to read user MQD\n");
365 + r = -ENOMEM;
365 366 goto free_mqd;
366 367 }
367 368
@@ -405,7 +406,8 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
405 406
406 407 mqd_gfx_v11 = memdup_user(u64_to_user_ptr(mqd_user->mqd), mqd_user->mqd_size);
407 408 if (IS_ERR(mqd_gfx_v11)) {
408 - r = PTR_ERR(mqd_gfx_v11);
409 + DRM_ERROR("Failed to read user MQD\n");
410 + r = -ENOMEM;
409 411 goto free_mqd;
410 412 }
411 413
@@ -449,7 +451,8 @@ static int mes_userq_mqd_create(struct amdgpu_usermode_queue *queue,
449 451
450 452 mqd_sdma_v11 = memdup_user(u64_to_user_ptr(mqd_user->mqd), mqd_user->mqd_size);
451 453 if (IS_ERR(mqd_sdma_v11)) {
452 - r = PTR_ERR(mqd_sdma_v11);
454 + DRM_ERROR("Failed to read sdma user MQD\n");
455 + r = -ENOMEM;
453 456 goto free_mqd;
454 457 }
455 458
modified drivers/gpu/drm/amd/amdkfd/kfd_device_queue_manager.c
@@ -572,32 +572,12 @@ static int allocate_doorbell(struct qcm_process_device *qpd,
572 572 * we need the physical sdma engine id in order to get the
573 573 * correct doorbell offset.
574 574 */
575 - u32 engine_base = idx_offset[dev->node_id *
576 - get_num_all_sdma_engines(qpd->dqm) +
577 - q->properties.sdma_engine_id];
578 - u32 valid_id;
579 -
580 - /*
581 - * With the aqua_vanjaram doorbell layout, a shader doorbell
582 - * write whose 32-byte block starts in the previous engine's
583 - * range rings that engine instead. Engine ranges are 10
584 - * indices apart (sdma_doorbell_range = 20 dwords, halved for
585 - * 8-byte doorbells, in aqua_vanjaram_doorbell_index_init()),
586 - * which puts odd engines 2 indices into a shared block.
587 - * Aligning costs at most 2 indices, and 8 queues per engine use
588 - * only 4 of the 10, so the aligned base stays in range. The
589 - * 512-index mirror offset keeps the alignment.
590 - */
591 - if (KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 3) ||
592 - KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 4) ||
593 - KFD_GC_VERSION(dev) == IP_VERSION(9, 5, 0))
594 - engine_base = ALIGN(engine_base,
595 - KFD_SDMA_SHADER_DOORBELL_GRANULARITY);
596 -
597 - valid_id = engine_base +
598 - (q->properties.sdma_queue_id & 1) *
599 - KFD_QUEUE_DOORBELL_MIRROR_OFFSET +
600 - (q->properties.sdma_queue_id >> 1);
575 + uint32_t valid_id = idx_offset[qpd->dqm->dev->node_id *
576 + get_num_all_sdma_engines(qpd->dqm) +
577 + q->properties.sdma_engine_id]
578 + + (q->properties.sdma_queue_id & 1)
579 + * KFD_QUEUE_DOORBELL_MIRROR_OFFSET
580 + + (q->properties.sdma_queue_id >> 1);
601 581
602 582 if (restore_id && *restore_id != valid_id)
603 583 return -EINVAL;
modified drivers/gpu/drm/amd/amdkfd/kfd_priv.h
@@ -133,13 +133,6 @@
133 133 */
134 134 #define KFD_QUEUE_DOORBELL_MIRROR_OFFSET 512
135 135
136 - /*
137 - * On GC 9.4.3, 9.4.4 and 9.5.0, doorbell writes issued from shaders are
138 - * routed to an SDMA engine at 32-byte granularity, i.e. 4 indices with the
139 - * 8-byte SDMA doorbells used on SOC15.
140 - */
141 - #define KFD_SDMA_SHADER_DOORBELL_GRANULARITY 4
142 -
143 136 /**
144 137 * enum kfd_ioctl_flags - KFD ioctl flags
145 138 * Various flags that can be set in &amdkfd_ioctl_desc.flags to control how
modified drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -3708,13 +3708,6 @@ static void amdgpu_dm_enable_self_refresh(struct amdgpu_display_manager *dm,
3708 3708 struct amdgpu_dm_connector *aconn =
3709 3709 (struct amdgpu_dm_connector *)acrtc_state->stream->dm_stream_context;
3710 3710
3711 - if (!acrtc_state->base.async_flip) {
3712 - amdgpu_dm_psr_set_event(dm, acrtc_state->stream, false,
3713 - psr_event_immediate_flip, false);
3714 - amdgpu_dm_replay_set_event(dm, acrtc_state->stream, false,
3715 - replay_event_immediate_flip, false);
3716 - }
3717 -
3718 3711 /* Decrement skip count when SR is enabled and we're doing fast updates. */
3719 3712 if (acrtc_state->update_type == UPDATE_TYPE_FAST &&
3720 3713 (psr->psr_feature_enabled || pr->replay_feature_enabled)) {
@@ -4125,18 +4118,6 @@ static void amdgpu_dm_commit_planes(struct drm_atomic_commit *state,
4125 4118 spin_unlock_irqrestore(&pcrtc->dev->event_lock, flags);
4126 4119 }
4127 4120 mutex_lock(&dm->dc_lock);
4128 - /*
4129 - * Tearing (immediate) flips cannot work with panel self-refresh
4130 - * features. The event is cleared by
4131 - * amdgpu_dm_enable_self_refresh() once async flips stop.
4132 - */
4133 - if (immediate_flip) {
4134 - dc_exit_ips_for_hw_access(dm->dc);
4135 - amdgpu_dm_psr_set_event(dm, acrtc_state->stream, true,
4136 - psr_event_immediate_flip, true);
4137 - amdgpu_dm_replay_set_event(dm, acrtc_state->stream, true,
4138 - replay_event_immediate_flip, true);
4139 - }
4140 4121 update_planes_and_stream_adapter(dm->dc,
4141 4122 acrtc_state->update_type,
4142 4123 planes_count,
modified drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_connector.c
@@ -1012,15 +1012,10 @@ decide_crtc_timing_for_drm_display_mode(struct drm_display_mode *drm_mode,
1012 1012 const struct drm_display_mode *native_mode,
1013 1013 bool scale_enabled)
1014 1014 {
1015 - /* Inserted modes copy the native sync; a sink mode with equal totals may not */
1016 1015 if (scale_enabled || (
1017 1016 native_mode->clock == drm_mode->clock &&
1018 1017 native_mode->htotal == drm_mode->htotal &&
1019 - native_mode->vtotal == drm_mode->vtotal &&
1020 - native_mode->hsync_start == drm_mode->hsync_start &&
1021 - native_mode->hsync_end == drm_mode->hsync_end &&
1022 - native_mode->vsync_start == drm_mode->vsync_start &&
1023 - native_mode->vsync_end == drm_mode->vsync_end)) {
1018 + native_mode->vtotal == drm_mode->vtotal)) {
1024 1019 if (native_mode->crtc_clock)
1025 1020 copy_crtc_timing_for_drm_display_mode(native_mode, drm_mode);
1026 1021 } else {
modified drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
@@ -112,7 +112,25 @@ void amdgpu_dm_plane_fill_blending_from_plane_state(const struct drm_plane_state
112 112
113 113 if (plane_state->pixel_blend_mode == DRM_MODE_BLEND_PREMULTI ||
114 114 plane_state->pixel_blend_mode == DRM_MODE_BLEND_COVERAGE) {
115 - *per_pixel_alpha = plane_state->fb->format->has_alpha;
115 + static const uint32_t alpha_formats[] = {
116 + DRM_FORMAT_ARGB8888,
117 + DRM_FORMAT_RGBA8888,
118 + DRM_FORMAT_ABGR8888,
119 + DRM_FORMAT_ARGB2101010,
120 + DRM_FORMAT_ABGR2101010,
121 + DRM_FORMAT_ARGB16161616,
122 + DRM_FORMAT_ABGR16161616,
123 + DRM_FORMAT_ARGB16161616F,
124 + };
125 + uint32_t format = plane_state->fb->format->format;
126 + unsigned int i;
127 +
128 + for (i = 0; i < ARRAY_SIZE(alpha_formats); ++i) {
129 + if (format == alpha_formats[i]) {
130 + *per_pixel_alpha = true;
131 + break;
132 + }
133 + }
116 134
117 135 if (*per_pixel_alpha && plane_state->pixel_blend_mode == DRM_MODE_BLEND_COVERAGE)
118 136 *pre_multiplied_alpha = false;
modified drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_connector_test.c
@@ -1572,46 +1572,6 @@ static void dm_test_decide_crtc_timing_no_crtc_clock(struct kunit *test)
1572 1572 KUNIT_EXPECT_EQ(test, drm_mode.crtc_hdisplay, 0);
1573 1573 }
1574 1574
1575 - static void dm_test_decide_crtc_timing_sink_mode_same_totals(struct kunit *test)
1576 - {
1577 - struct drm_display_mode native_mode = {
1578 - DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016, 4104,
1579 - 4400, 0, 2160, 2168, 2178, 2250, 0,
1580 - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) };
1581 - struct drm_display_mode drm_mode = {
1582 - DRM_MODE("4096x2160", DRM_MODE_TYPE_DRIVER, 594000, 4096, 4184, 4272,
1583 - 4400, 0, 2160, 2168, 2178, 2250, 0,
1584 - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) };
1585 -
1586 - drm_mode_set_crtcinfo(&native_mode, 0);
1587 - drm_mode_set_crtcinfo(&drm_mode, 0);
1588 -
1589 - decide_crtc_timing_for_drm_display_mode(&drm_mode, &native_mode, false);
1590 -
1591 - KUNIT_EXPECT_EQ(test, drm_mode.crtc_hdisplay, 4096);
1592 - KUNIT_EXPECT_EQ(test, drm_mode.crtc_hsync_start, 4184);
1593 - }
1594 -
1595 - static void dm_test_decide_crtc_timing_inserted_mode(struct kunit *test)
1596 - {
1597 - struct drm_display_mode native_mode = {
1598 - DRM_MODE("3840x2160", DRM_MODE_TYPE_DRIVER, 594000, 3840, 4016, 4104,
1599 - 4400, 0, 2160, 2168, 2178, 2250, 0,
1600 - DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) };
1601 - struct drm_display_mode drm_mode;
1602 -
1603 - drm_mode_set_crtcinfo(&native_mode, 0);
1604 - drm_mode = native_mode;
1605 - drm_mode.hdisplay = 1920;
1606 - drm_mode.vdisplay = 1080;
1607 - drm_mode_set_crtcinfo(&drm_mode, 0);
1608 -
1609 - decide_crtc_timing_for_drm_display_mode(&drm_mode, &native_mode, false);
1610 -
1611 - KUNIT_EXPECT_EQ(test, drm_mode.crtc_hdisplay, 3840);
1612 - KUNIT_EXPECT_EQ(test, drm_mode.crtc_vdisplay, 2160);
1613 - }
1614 -
1615 1575 /* Tests for amdgpu_dm_connector_funcs_reset() */
1616 1576
1617 1577 static const struct drm_connector_funcs dm_test_connector_funcs = {
@@ -5675,8 +5635,6 @@ static struct kunit_case amdgpu_dm_connector_tests[] = {
5675 5635 KUNIT_CASE(dm_test_decide_crtc_timing_matching_mode),
5676 5636 KUNIT_CASE(dm_test_decide_crtc_timing_no_copy),
5677 5637 KUNIT_CASE(dm_test_decide_crtc_timing_no_crtc_clock),
5678 - KUNIT_CASE(dm_test_decide_crtc_timing_sink_mode_same_totals),
5679 - KUNIT_CASE(dm_test_decide_crtc_timing_inserted_mode),
5680 5638 /* amdgpu_dm_connector_funcs_reset */
5681 5639 KUNIT_CASE(dm_test_funcs_reset_sets_defaults),
5682 5640 KUNIT_CASE(dm_test_funcs_reset_edp_abm_level),
modified drivers/gpu/drm/aspeed/aspeed_gfx_drv.c
@@ -189,12 +189,13 @@ static int aspeed_gfx_load(struct drm_device *drm)
189 189 }
190 190 reset_control_deassert(priv->rst);
191 191
192 - priv->clk = devm_clk_get_enabled(drm->dev, NULL);
192 + priv->clk = devm_clk_get(drm->dev, NULL);
193 193 if (IS_ERR(priv->clk)) {
194 194 dev_err(&pdev->dev,
195 - "failed to get and enable clock\n");
195 + "missing or invalid clk device tree entry");
196 196 return PTR_ERR(priv->clk);
197 197 }
198 + clk_prepare_enable(priv->clk);
198 199
199 200 /* Sanitize control registers */
200 201 writel(0, priv->base + CRT_CTRL1);
modified drivers/gpu/drm/bridge/th1520-dw-hdmi.c
@@ -135,8 +135,8 @@ static int th1520_dw_hdmi_probe(struct platform_device *pdev)
135 135 plat_data->priv_data = hdmi;
136 136
137 137 hdmi->dw_hdmi = dw_hdmi_probe(pdev, plat_data);
138 - if (IS_ERR(hdmi->dw_hdmi))
139 - return PTR_ERR(hdmi->dw_hdmi);
138 + if (IS_ERR(hdmi))
139 + return PTR_ERR(hdmi);
140 140
141 141 platform_set_drvdata(pdev, hdmi);
142 142
@@ -145,9 +145,9 @@ static int th1520_dw_hdmi_probe(struct platform_device *pdev)
145 145
146 146 static void th1520_dw_hdmi_remove(struct platform_device *pdev)
147 147 {
148 - struct th1520_hdmi *hdmi = platform_get_drvdata(pdev);
148 + struct dw_hdmi *hdmi = platform_get_drvdata(pdev);
149 149
150 - dw_hdmi_remove(hdmi->dw_hdmi);
150 + dw_hdmi_remove(hdmi);
151 151 }
152 152
153 153 static const struct of_device_id th1520_dw_hdmi_of_table[] = {
modified drivers/gpu/drm/display/drm_dp_helper.c
@@ -4634,9 +4634,7 @@ static int dp_aux_backlight_update_status(struct backlight_device *bd)
4634 4634
4635 4635 if (!backlight_is_blank(bd)) {
4636 4636 if (!bl->enabled) {
4637 - ret = drm_edp_backlight_enable(bl->aux, &bl->info, brightness);
4638 - if (ret)
4639 - return ret;
4637 + drm_edp_backlight_enable(bl->aux, &bl->info, brightness);
4640 4638 bl->enabled = true;
4641 4639 return 0;
4642 4640 }
modified drivers/gpu/drm/drm_bridge.c
@@ -454,10 +454,8 @@ void drm_bridge_add(struct drm_bridge *bridge)
454 454 * in bridge_lingering_list. Remove it or bridge_lingering_list will be
455 455 * corrupted when adding this bridge to bridge_list below.
456 456 */
457 - mutex_lock(&bridge_lock);
458 457 if (!list_empty(&bridge->list))
459 458 list_del_init(&bridge->list);
460 - mutex_unlock(&bridge_lock);
461 459
462 460 mutex_init(&bridge->hpd_state_mutex);
463 461 mutex_init(&bridge->hpd_mutex);
@@ -595,10 +593,8 @@ int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
595 593 if (!bridge->container)
596 594 DRM_WARN("DRM bridge corrupted or not allocated by devm_drm_bridge_alloc()\n");
597 595
598 - scoped_guard(mutex, &bridge_lock) {
599 - if (list_empty(&bridge->list))
600 - DRM_WARN("Missing drm_bridge_add() before attach\n");
601 - }
596 + if (list_empty(&bridge->list))
597 + DRM_WARN("Missing drm_bridge_add() before attach\n");
602 598
603 599 drm_bridge_get(bridge);
604 600
modified drivers/gpu/drm/drm_fb_helper.c
@@ -1724,10 +1724,10 @@ __drm_fb_helper_initial_config_and_unlock(struct drm_fb_helper *fb_helper)
1724 1724
1725 1725 ret = drm_fb_helper_single_fb_probe(fb_helper);
1726 1726 if (ret < 0) {
1727 - /* modesets are probed but fb_helper->fb isn't; defer restore too */
1728 - fb_helper->deferred_setup = true;
1729 - if (ret == -EAGAIN)
1727 + if (ret == -EAGAIN) {
1728 + fb_helper->deferred_setup = true;
1730 1729 ret = 0;
1730 + }
1731 1731 mutex_unlock(&fb_helper->lock);
1732 1732
1733 1733 goto err_drm_fb_helper_release_info;
modified drivers/gpu/drm/gud/gud_pipe.c
@@ -507,7 +507,6 @@ int gud_plane_atomic_check(struct drm_plane *plane,
507 507 for_each_new_connector_in_state(state, connector, connector_state, i) {
508 508 if (connector_state->crtc)
509 509 break;
510 - connector_state = NULL;
511 510 }
512 511
513 512 /*
modified drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c
@@ -1766,7 +1766,6 @@ static int eb_reinit_userptr(struct i915_execbuffer *eb)
1766 1766
1767 1767 static noinline int eb_relocate_parse_slow(struct i915_execbuffer *eb)
1768 1768 {
1769 - const unsigned int count = eb->buffer_count;
1770 1769 bool have_copy = false;
1771 1770 struct eb_vma *ev;
1772 1771 int err = 0;
@@ -1869,6 +1868,7 @@ err:
1869 1868
1870 1869 out:
1871 1870 if (have_copy) {
1871 + const unsigned int count = eb->buffer_count;
1872 1872 unsigned int i;
1873 1873
1874 1874 for (i = 0; i < count; i++) {
modified drivers/gpu/drm/i915/gt/intel_rps.c
@@ -1904,8 +1904,7 @@ static void rps_work(struct work_struct *work)
1904 1904
1905 1905 out:
1906 1906 spin_lock_irq(gt->irq_lock);
1907 - if (intel_rps_is_active(rps))
1908 - gen6_gt_pm_unmask_irq(gt, rps->pm_events);
1907 + gen6_gt_pm_unmask_irq(gt, rps->pm_events);
1909 1908 spin_unlock_irq(gt->irq_lock);
1910 1909 }
1911 1910
modified drivers/gpu/drm/imagination/pvr_mmu.c
@@ -2337,7 +2337,7 @@ void pvr_mmu_op_context_destroy(struct pvr_mmu_op_context *op_ctx)
2337 2337 * @ctx: MMU context associated with owning VM context.
2338 2338 * @sgt: Scatter gather table containing pages pinned for use by this context.
2339 2339 * @device_addr: Virtual device address at the start of the requested mapping.
2340 - * @sgt_offset: Offset into @sgt of the start of the requested mapping.
2340 + * @sgt_offset: Start offset of the requested device-virtual memory mapping.
2341 2341 * @size: Size in bytes of the requested device-virtual memory mapping. For an
2342 2342 * unmapping, this should be zero so that no page tables are allocated.
2343 2343 *
@@ -2350,6 +2350,7 @@ struct pvr_mmu_op_context *
2350 2350 pvr_mmu_op_context_create(struct pvr_mmu_context *ctx, struct sg_table *sgt,
2351 2351 u64 device_addr, u64 sgt_offset, u64 size)
2352 2352 {
2353 + u64 start_addr = device_addr + sgt_offset;
2353 2354 int err;
2354 2355
2355 2356 struct pvr_mmu_op_context *op_ctx = kzalloc_obj(*op_ctx);
@@ -2364,18 +2365,18 @@ pvr_mmu_op_context_create(struct pvr_mmu_context *ctx, struct sg_table *sgt,
2364 2365
2365 2366 if (size) {
2366 2367 /*
2367 - * The page tables needed are set by the device-virtual range
2368 - * being mapped: one level 1 table per 1GiB region and one
2369 - * level 0 table per 2MiB region the range touches. Tables that
2370 - * already exist are not consumed, so this is an upper bound.
2368 + * The number of page table objects we need to prealloc is
2369 + * indicated by the mapping size, start address and the sizes
2370 + * of the areas mapped per PT or PD. The range calculation is
2371 + * identical to that for the index into a table for a device
2372 + * address, so we reuse those functions here.
2371 2373 */
2372 - const u64 last_addr = device_addr + size - 1;
2373 - const u64 l1_count =
2374 - (last_addr >> ROGUE_MMUCTRL_VADDR_PC_INDEX_SHIFT) -
2375 - (device_addr >> ROGUE_MMUCTRL_VADDR_PC_INDEX_SHIFT) + 1;
2376 - const u64 l0_count =
2377 - (last_addr >> ROGUE_MMUCTRL_VADDR_PD_INDEX_SHIFT) -
2378 - (device_addr >> ROGUE_MMUCTRL_VADDR_PD_INDEX_SHIFT) + 1;
2374 + const u32 l1_start_idx = pvr_page_table_l2_idx(start_addr);
2375 + const u32 l1_end_idx = pvr_page_table_l2_idx(start_addr + size);
2376 + const u32 l1_count = l1_end_idx - l1_start_idx + 1;
2377 + const u32 l0_start_idx = pvr_page_table_l1_idx(start_addr);
2378 + const u32 l0_end_idx = pvr_page_table_l1_idx(start_addr + size);
2379 + const u32 l0_count = l0_end_idx - l0_start_idx + 1;
2379 2380
2380 2381 /*
2381 2382 * Alloc and push page table entries until we have enough of
modified drivers/gpu/drm/imagination/pvr_vm.c
@@ -418,8 +418,6 @@ pvr_vm_gpuva_unmap(struct drm_gpuva_op *op, void *op_ctx)
418 418 static int
419 419 pvr_vm_gpuva_remap(struct drm_gpuva_op *op, void *op_ctx)
420 420 {
421 - /* The split parts belong to the object of the mapping being split. */
422 - struct drm_gpuvm_bo *vm_bo = op->remap.unmap->va->vm_bo;
423 421 struct pvr_vm_bind_op *ctx = op_ctx;
424 422 u64 va_start = 0, va_range = 0;
425 423 int err;
@@ -435,12 +433,14 @@ pvr_vm_gpuva_remap(struct drm_gpuva_op *op, void *op_ctx)
435 433 drm_gpuva_remap(&ctx->prev_va->base, &ctx->next_va->base, &op->remap);
436 434
437 435 if (op->remap.prev) {
438 - drm_gpuva_link(&ctx->prev_va->base, vm_bo);
436 + pvr_gem_object_get(gem_to_pvr_gem(ctx->prev_va->base.gem.obj));
437 + drm_gpuva_link(&ctx->prev_va->base, ctx->gpuvm_bo);
439 438 ctx->prev_va = NULL;
440 439 }
441 440
442 441 if (op->remap.next) {
443 - drm_gpuva_link(&ctx->next_va->base, vm_bo);
442 + pvr_gem_object_get(gem_to_pvr_gem(ctx->next_va->base.gem.obj));
443 + drm_gpuva_link(&ctx->next_va->base, ctx->gpuvm_bo);
444 444 ctx->next_va = NULL;
445 445 }
446 446
modified drivers/gpu/drm/nouveau/nouveau_abi16.c
@@ -488,7 +488,7 @@ nouveau_abi16_ioctl_channel_alloc(ABI16_IOCTL_ARGS)
488 488 goto done;
489 489 break;
490 490 case NV_DEVICE_INFO_V0_TURING:
491 - if (engine == NV_DEVICE_HOST_RUNLIST_ENGINES_GR) {
491 + if (engine != NV_DEVICE_HOST_RUNLIST_ENGINES_NVDEC) {
492 492 ret = nvif_object_ctor(&chan->chan->user, "abi16CeWar",
493 493 0, TURING_DMA_COPY_A, NULL, 0,
494 494 &chan->ce);
modified drivers/gpu/drm/nouveau/nvkm/engine/device/user.c
@@ -201,7 +201,7 @@ nvkm_udevice_gcx_ready(struct nvkm_udevice *udev, void *data, u32 size)
201 201 } *args = data;
202 202 int ret = -ENOSYS;
203 203
204 - if (!gsp || !gsp->rm) {
204 + if (!gsp) {
205 205 args->v0.ready = NV_DEVICE_GC6_READY | NV_DEVICE_GCOFF_READY;
206 206 return 0;
207 207 }
modified drivers/gpu/drm/panthor/panthor_sched.c
@@ -3674,9 +3674,6 @@ int panthor_group_create(struct panthor_file *pfile,
3674 3674 hweight64(group_args->tiler_core_mask) < group_args->max_tiler_cores)
3675 3675 return -EINVAL;
3676 3676
3677 - if (group_args->queues.count > sched->cs_slot_count)
3678 - return -EINVAL;
3679 -
3680 3677 group = kzalloc_obj(*group);
3681 3678 if (!group)
3682 3679 return -ENOMEM;
modified drivers/gpu/drm/vc4/vc4_bo.c
@@ -204,7 +204,7 @@ static struct list_head *vc4_get_cache_list_for_size(struct drm_device *dev,
204 204 struct list_head *new_list;
205 205 uint32_t i;
206 206
207 - new_list = kvmalloc_objs(struct list_head, new_size);
207 + new_list = kmalloc_objs(struct list_head, new_size);
208 208 if (!new_list)
209 209 return NULL;
210 210
@@ -224,7 +224,7 @@ static struct list_head *vc4_get_cache_list_for_size(struct drm_device *dev,
224 224 for (i = vc4->bo_cache.size_list_size; i < new_size; i++)
225 225 INIT_LIST_HEAD(&new_list[i]);
226 226
227 - kvfree(vc4->bo_cache.size_list);
227 + kfree(vc4->bo_cache.size_list);
228 228 vc4->bo_cache.size_list = new_list;
229 229 vc4->bo_cache.size_list_size = new_size;
230 230 }
@@ -1052,7 +1052,6 @@ static void vc4_bo_cache_destroy(struct drm_device *dev, void *unused)
1052 1052 cancel_work_sync(&vc4->bo_cache.time_work);
1053 1053
1054 1054 vc4_bo_cache_purge(dev);
1055 - kvfree(vc4->bo_cache.size_list);
1056 1055
1057 1056 for (i = 0; i < vc4->num_labels; i++) {
1058 1057 if (vc4->bo_labels[i].num_allocated) {
modified drivers/gpu/drm/vc4/vc4_drv.c
@@ -360,11 +360,8 @@ static int vc4_drm_bind(struct device *dev)
360 360 }
361 361
362 362 ret = aperture_remove_all_conflicting_devices(driver->name);
363 - if (ret) {
364 - if (firmware)
365 - rpi_firmware_put(firmware);
363 + if (ret)
366 364 goto err;
367 - }
368 365
369 366 if (firmware) {
370 367 ret = rpi_firmware_property(firmware,
modified drivers/gpu/drm/vc4/vc4_drv.h
@@ -1051,7 +1051,7 @@ void vc4_plane_async_set_fb(struct drm_plane *plane,
1051 1051 /* vc4_v3d.c */
1052 1052 extern struct platform_driver vc4_v3d_driver;
1053 1053 extern const struct of_device_id vc4_v3d_dt_match[];
1054 - int vc4_v3d_get_bin_slot(struct vc4_dev *vc4, long timeout);
1054 + int vc4_v3d_get_bin_slot(struct vc4_dev *vc4);
1055 1055 int vc4_v3d_bin_bo_get(struct vc4_dev *vc4, bool *used);
1056 1056 void vc4_v3d_bin_bo_put(struct vc4_dev *vc4);
1057 1057 int vc4_v3d_pm_get(struct vc4_dev *vc4);
modified drivers/gpu/drm/vc4/vc4_gem.c
@@ -877,17 +877,11 @@ vc4_complete_exec(struct drm_device *dev, struct vc4_exec_info *exec)
877 877 drm_gem_object_put(&bo->base.base);
878 878 }
879 879
880 - /* Free up the allocation of any bin slots we used. Jobs that ran to
881 - * completion had their slots released in vc4_irq_finish_render_job().
882 - * Only jobs that never completed still have slots to be released here.
883 - */
880 + /* Free up the allocation of any bin slots we used. */
884 881 spin_lock_irqsave(&vc4->job_lock, irqflags);
885 882 vc4->bin_alloc_used &= ~exec->bin_slots;
886 883 spin_unlock_irqrestore(&vc4->job_lock, irqflags);
887 884
888 - /* Let anyone waiting on the binner pool retry. */
889 - wake_up_all(&vc4->job_wait_queue);
890 -
891 885 /* Release the reference on the binner BO if needed. */
892 886 if (exec->bin_bo_used)
893 887 vc4_v3d_bin_bo_put(vc4);
modified drivers/gpu/drm/vc4/vc4_irq.c
@@ -74,7 +74,7 @@ vc4_overflow_mem_work(struct work_struct *work)
74 74
75 75 bo = vc4->bin_bo;
76 76
77 - bin_bo_slot = vc4_v3d_get_bin_slot(vc4, msecs_to_jiffies(500));
77 + bin_bo_slot = vc4_v3d_get_bin_slot(vc4);
78 78 if (bin_bo_slot < 0) {
79 79 drm_err(&vc4->base, "Couldn't allocate binner overflow mem\n");
80 80 goto complete;
@@ -165,10 +165,6 @@ vc4_irq_finish_render_job(struct drm_device *dev)
165 165 trace_vc4_rcl_end_irq(dev, exec->seqno);
166 166
167 167 vc4->finished_seqno++;
168 -
169 - vc4->bin_alloc_used &= ~exec->bin_slots;
170 - exec->bin_slots = 0;
171 -
172 168 list_move_tail(&exec->head, &vc4->job_done_list);
173 169
174 170 nextbin = vc4_first_bin_job(vc4);
@@ -280,7 +276,7 @@ vc4_irq_disable(struct drm_device *dev)
280 276 V3D_WRITE(V3D_INTCTL, V3D_DRIVER_IRQS);
281 277
282 278 /* Finish any interrupt handler still in flight. */
283 - disable_irq(vc4->irq);
279 + synchronize_irq(vc4->irq);
284 280
285 281 cancel_work_sync(&vc4->overflow_mem_work);
286 282 }
@@ -288,6 +284,7 @@ vc4_irq_disable(struct drm_device *dev)
288 284 int vc4_irq_install(struct drm_device *dev, int irq)
289 285 {
290 286 struct vc4_dev *vc4 = to_vc4_dev(dev);
287 + int ret;
291 288
292 289 if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4))
293 290 return -ENODEV;
@@ -301,8 +298,19 @@ int vc4_irq_install(struct drm_device *dev, int irq)
301 298 init_waitqueue_head(&vc4->job_wait_queue);
302 299 INIT_WORK(&vc4->overflow_mem_work, vc4_overflow_mem_work);
303 300
304 - return devm_request_irq(dev->dev, irq, vc4_irq, IRQF_NO_AUTOEN,
305 - dev_name(dev->dev), dev);
301 + /* Clear any pending interrupts someone might have left around
302 + * for us.
303 + */
304 + V3D_WRITE(V3D_INTCTL, V3D_DRIVER_IRQS);
305 +
306 + ret = devm_request_irq(dev->dev, irq, vc4_irq, 0,
307 + dev_name(dev->dev), dev);
308 + if (ret)
309 + return ret;
310 +
311 + vc4_irq_enable(dev);
312 +
313 + return 0;
306 314 }
307 315
308 316 void vc4_irq_uninstall(struct drm_device *dev)
modified drivers/gpu/drm/vc4/vc4_v3d.c
@@ -9,7 +9,6 @@
9 9 #include <linux/component.h>
10 10 #include <linux/platform_device.h>
11 11 #include <linux/pm_runtime.h>
12 - #include <linux/timer.h>
13 12
14 13 #include <drm/drm_print.h>
15 14
@@ -173,42 +172,46 @@ static void vc4_v3d_init_hw(struct drm_device *dev)
173 172 V3D_WRITE(V3D_VPMBASE, 0);
174 173 }
175 174
176 - static int bin_slot_try_alloc(struct vc4_dev *vc4)
175 + int vc4_v3d_get_bin_slot(struct vc4_dev *vc4)
177 176 {
177 + struct drm_device *dev = &vc4->base;
178 + unsigned long irqflags;
178 179 int slot;
180 + uint64_t seqno = 0;
181 + struct vc4_exec_info *exec;
179 182
180 - guard(spinlock_irqsave)(&vc4->job_lock);
183 + if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4))
184 + return -ENODEV;
181 185
186 + try_again:
187 + spin_lock_irqsave(&vc4->job_lock, irqflags);
182 188 slot = ffs(~vc4->bin_alloc_used);
183 189 if (slot != 0) {
184 190 /* Switch from ffs() bit index to a 0-based index. */
185 191 slot--;
186 192 vc4->bin_alloc_used |= BIT(slot);
187 - } else {
188 - slot = -ENOMEM;
193 + spin_unlock_irqrestore(&vc4->job_lock, irqflags);
194 + return slot;
189 195 }
190 196
191 - return slot;
192 - }
197 + /* Couldn't find an open slot. Wait for render to complete
198 + * and try again.
199 + */
200 + exec = vc4_last_render_job(vc4);
201 + if (exec)
202 + seqno = exec->seqno;
203 + spin_unlock_irqrestore(&vc4->job_lock, irqflags);
193 204
194 - int vc4_v3d_get_bin_slot(struct vc4_dev *vc4, long timeout)
195 - {
196 - int slot;
197 - long ret;
205 + if (seqno) {
206 + int ret = vc4_wait_for_seqno(dev, seqno, ~0ull, true);
198 207
199 - if (WARN_ON_ONCE(vc4->gen > VC4_GEN_4))
200 - return -ENODEV;
208 + if (ret == 0)
209 + goto try_again;
201 210
202 - /* If the pool is full, wait for a job to release its slots. */
203 - ret = wait_event_interruptible_timeout(vc4->job_wait_queue,
204 - (slot = bin_slot_try_alloc(vc4)) >= 0,
205 - timeout);
206 - if (ret < 0)
207 211 return ret;
208 - if (ret == 0)
209 - return -ENOMEM;
212 + }
210 213
211 - return slot;
214 + return -ENOMEM;
212 215 }
213 216
214 217 /*
@@ -393,7 +396,6 @@ static int vc4_v3d_runtime_resume(struct device *dev)
393 396 vc4_v3d_init_hw(&vc4->base);
394 397
395 398 vc4_irq_enable(&vc4->base);
396 - enable_irq(vc4->irq);
397 399
398 400 return 0;
399 401 }
@@ -450,12 +452,6 @@ static int vc4_v3d_bind(struct device *dev, struct device *master, void *data)
450 452 return ret;
451 453 vc4->irq = ret;
452 454
453 - ret = vc4_irq_install(drm, vc4->irq);
454 - if (ret) {
455 - drm_err(drm, "Failed to install IRQ handler\n");
456 - return ret;
457 - }
458 -
459 455 ret = devm_pm_runtime_enable(dev);
460 456 if (ret)
461 457 return ret;
@@ -477,6 +473,12 @@ static int vc4_v3d_bind(struct device *dev, struct device *master, void *data)
477 473 V3D_WRITE(V3D_BPOA, 0);
478 474 V3D_WRITE(V3D_BPOS, 0);
479 475
476 + ret = vc4_irq_install(drm, vc4->irq);
477 + if (ret) {
478 + drm_err(drm, "Failed to install IRQ handler\n");
479 + goto err_put_runtime_pm;
480 + }
481 +
480 482 pm_runtime_use_autosuspend(dev);
481 483 pm_runtime_set_autosuspend_delay(dev, 40); /* a little over 2 frames. */
482 484 pm_runtime_put_autosuspend(dev);
@@ -495,15 +497,8 @@ static void vc4_v3d_unbind(struct device *dev, struct device *master,
495 497 struct drm_device *drm = data;
496 498 struct vc4_dev *vc4 = to_vc4_dev(drm);
497 499
498 - /* A straggler vc4_reset() re-enables the interrupt. */
499 - timer_shutdown_sync(&vc4->hangcheck.timer);
500 - cancel_work_sync(&vc4->hangcheck.reset_work);
501 -
502 500 vc4_irq_uninstall(drm);
503 501
504 - /* Flush rather than cancel, so queued completions release their jobs. */
505 - flush_work(&vc4->job_done_work);
506 -
507 502 /* Disable the binner's overflow memory address, so the next
508 503 * driver probe (if any) doesn't try to reuse our old
509 504 * allocation.
modified drivers/gpu/drm/vc4/vc4_validate.c
@@ -402,7 +402,7 @@ validate_tile_binning_config(VALIDATE_ARGS)
402 402 return -EINVAL;
403 403 }
404 404
405 - bin_slot = vc4_v3d_get_bin_slot(vc4, MAX_SCHEDULE_TIMEOUT);
405 + bin_slot = vc4_v3d_get_bin_slot(vc4);
406 406 if (bin_slot < 0) {
407 407 if (bin_slot != -EINTR && bin_slot != -ERESTARTSYS) {
408 408 drm_err(dev, "Failed to allocate binner memory: %d\n",
modified drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.c
@@ -324,7 +324,6 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf,
324 324 unsigned long kmap_num;
325 325 SVGA3dCopyBox *box;
326 326 u32 box_count;
327 - u64 src_extent;
328 327 void *virtual;
329 328 bool is_iomem;
330 329 struct vmw_dma_cmd {
@@ -336,8 +335,6 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf,
336 335 vmw_surface_get_desc(VMW_CURSOR_SNOOP_FORMAT);
337 336 const u32 image_pitch = VMW_CURSOR_SNOOP_WIDTH * desc->pitchBytesPerBlock;
338 337
339 - BUILD_BUG_ON(sizeof(*srf->snooper.image) != desc->pitchBytesPerBlock);
340 -
341 338 cmd = container_of(header, struct vmw_dma_cmd, header);
342 339
343 340 /* No snooper installed, nothing to copy */
@@ -375,19 +372,8 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf,
375 372 return;
376 373 }
377 374
378 - if (box->w == 0 || box->h == 0)
379 - return;
380 -
381 - src_extent = (u64)(box->h - 1) * cmd->dma.guest.pitch +
382 - (u64)box->w * desc->pitchBytesPerBlock;
383 - if (src_extent > bo->base.size) {
384 - DRM_ERROR("Cursor snoop source of %llu bytes exceeds the %zu byte buffer\n",
385 - src_extent, bo->base.size);
386 - return;
387 - }
388 -
389 375 kmap_offset = cmd->dma.guest.ptr.offset >> PAGE_SHIFT;
390 - kmap_num = PFN_UP(src_extent);
376 + kmap_num = (VMW_CURSOR_SNOOP_HEIGHT * image_pitch) >> PAGE_SHIFT;
391 377
392 378 ret = ttm_bo_reserve(bo, true, false, NULL);
393 379 if (unlikely(ret != 0)) {
@@ -401,16 +387,14 @@ void vmw_kms_cursor_snoop(struct vmw_surface *srf,
401 387
402 388 virtual = ttm_kmap_obj_virtual(&map, &is_iomem);
403 389
404 - if (box->w == VMW_CURSOR_SNOOP_WIDTH &&
405 - box->h == VMW_CURSOR_SNOOP_HEIGHT &&
406 - cmd->dma.guest.pitch == image_pitch) {
390 + if (box->w == VMW_CURSOR_SNOOP_WIDTH && cmd->dma.guest.pitch == image_pitch) {
407 391 memcpy(srf->snooper.image, virtual,
408 392 VMW_CURSOR_SNOOP_HEIGHT * image_pitch);
409 393 } else {
410 - /* The destination stride is in pixels. */
394 + /* Image is unsigned pointer. */
411 395 for (i = 0; i < box->h; i++)
412 - memcpy(srf->snooper.image + i * VMW_CURSOR_SNOOP_WIDTH,
413 - virtual + (size_t)i * cmd->dma.guest.pitch,
396 + memcpy(srf->snooper.image + i * image_pitch,
397 + virtual + i * cmd->dma.guest.pitch,
414 398 box->w * desc->pitchBytesPerBlock);
415 399 }
416 400 srf->snooper.id++;
modified drivers/gpu/drm/vmwgfx/vmwgfx_kms.c
@@ -20,18 +20,10 @@
20 20 #include <drm/drm_rect.h>
21 21 #include <drm/drm_sysfs.h>
22 22 #include <drm/drm_edid.h>
23 - #include <drm/drm_blend.h>
24 23
25 24 void vmw_du_init(struct vmw_display_unit *du)
26 25 {
27 26 vmw_vkms_crtc_init(&du->crtc);
28 - drm_plane_create_blend_mode_property(&du->primary,
29 - BIT(DRM_MODE_BLEND_PIXEL_NONE) |
30 - BIT(DRM_MODE_BLEND_PREMULTI));
31 - // Check that the cursor plane was actually initialized
32 - if (du->crtc.cursor == &du->cursor.base)
33 - drm_plane_create_blend_mode_property(&du->cursor.base,
34 - BIT(DRM_MODE_BLEND_PREMULTI));
35 27 }
36 28
37 29 void vmw_du_cleanup(struct vmw_display_unit *du)
modified drivers/gpu/drm/xe/display/xe_fb_pin.c
@@ -356,7 +356,7 @@ static struct i915_vma *__xe_pin_fb_vma(struct drm_gem_object *obj, bool is_dpt,
356 356 drm_exec_retry_on_contention(&exec);
357 357 xe_validation_retry_on_oom(&ctx, &ret);
358 358 if (!ret)
359 - xe_bo_pin_account(bo);
359 + ttm_bo_pin(&bo->ttm);
360 360 }
361 361 if (ret)
362 362 goto err;
@@ -373,7 +373,7 @@ static struct i915_vma *__xe_pin_fb_vma(struct drm_gem_object *obj, bool is_dpt,
373 373
374 374 err_unpin:
375 375 ttm_bo_reserve(&bo->ttm, false, false, NULL);
376 - xe_bo_unpin_account(bo);
376 + ttm_bo_unpin(&bo->ttm);
377 377 ttm_bo_unreserve(&bo->ttm);
378 378 err:
379 379 kfree(vma);
@@ -393,7 +393,7 @@ static void __xe_unpin_fb_vma(struct i915_vma *vma)
393 393 xe_ggtt_node_remove(vma->node, false);
394 394
395 395 ttm_bo_reserve(&vma->bo->ttm, false, false, NULL);
396 - xe_bo_unpin_account(vma->bo);
396 + ttm_bo_unpin(&vma->bo->ttm);
397 397 ttm_bo_unreserve(&vma->bo->ttm);
398 398 kfree(vma);
399 399 }
modified drivers/gpu/drm/xe/xe_bo.c
@@ -455,100 +455,6 @@ static void xe_ttm_tt_account_subtract(struct xe_device *xe, struct ttm_tt *tt)
455 455 xe_shrinker_mod_pages(xe->mem.shrinker, -(long)tt->num_pages, 0);
456 456 }
457 457
458 - static bool xe_ttm_bo_is_imported(struct ttm_buffer_object *tbo)
459 - {
460 - dma_resv_assert_held(tbo->base.resv);
461 -
462 - return tbo->ttm &&
463 - (tbo->ttm->page_flags & (TTM_TT_FLAG_EXTERNAL | TTM_TT_FLAG_EXTERNAL_MAPPABLE)) ==
464 - TTM_TT_FLAG_EXTERNAL;
465 - }
466 -
467 - /*
468 - * Account @bo's pages as pinned for the shrinker. Removes @bo's pages
469 - * from the shrinker's shrinkable / purgeable counts on the transition
470 - * from unpinned to pinned. Must be called with @bo's dma-resv held,
471 - * after &ttm_buffer_object.pin_count has been incremented by
472 - * ttm_bo_pin(). Safe to call unconditionally regardless of which pin
473 - * path (kernel, external, framebuffer, backup object, ...) is pinning
474 - * @bo, since it only acts on the true 0->1 pin_count transition.
475 - *
476 - * Imported bos (xe_ttm_bo_is_imported()) are excluded: for those,
477 - * xe_ttm_tt_populate() never actually populates the tt or calls
478 - * xe_ttm_tt_account_add(), but TTM core's ttm_tt_populate() still
479 - * unconditionally marks the tt as populated on driver-hook success.
480 - * Relying on ttm_tt_is_populated() for these would subtract pages that
481 - * were never added, underflowing the shrinker's counts.
482 - */
483 - static void xe_bo_account_pin(struct xe_bo *bo)
484 - {
485 - struct xe_device *xe = xe_bo_device(bo);
486 -
487 - if (bo->ttm.pin_count == 1 && bo->ttm.ttm && ttm_tt_is_populated(bo->ttm.ttm) &&
488 - !xe_ttm_bo_is_imported(&bo->ttm))
489 - xe_ttm_tt_account_subtract(xe, bo->ttm.ttm);
490 - }
491 -
492 - /*
493 - * Counterpart to xe_bo_account_pin(). Must be called with @bo's dma-resv
494 - * held, before &ttm_buffer_object.pin_count is decremented by
495 - * ttm_bo_unpin(), so that the check against the true 1->0 transition sees
496 - * the pin count that is about to be released. See xe_bo_account_pin() for
497 - * why imported bos are excluded.
498 - *
499 - * On the true last unpin, also removes @bo from whichever pinned-bo list
500 - * (external or kernel_bo_present) it may currently be linked on, since a
501 - * bo's final unpin can happen through a pin path (e.g. framebuffer,
502 - * backup object) that has no notion of, or ownership over, that list.
503 - * This is safe and list-agnostic: list_del_init() only needs the node
504 - * itself, not knowledge of which list it is threaded through, and is a
505 - * no-op if @bo is not linked.
506 - */
507 - static void xe_bo_account_unpin(struct xe_bo *bo)
508 - {
509 - struct xe_device *xe = xe_bo_device(bo);
510 - bool last_unpin = bo->ttm.pin_count == 1;
511 -
512 - if (last_unpin && !list_empty(&bo->pinned_link)) {
513 - spin_lock(&xe->pinned.lock);
514 - list_del_init(&bo->pinned_link);
515 - spin_unlock(&xe->pinned.lock);
516 - }
517 -
518 - if (last_unpin && bo->ttm.ttm && ttm_tt_is_populated(bo->ttm.ttm) &&
519 - !xe_ttm_bo_is_imported(&bo->ttm))
520 - xe_ttm_tt_account_add(xe, bo->ttm.ttm);
521 - }
522 -
523 - /**
524 - * xe_bo_pin_account() - Pin a bo and account its pages for the shrinker
525 - * @bo: The buffer object to pin.
526 - *
527 - * Pins @bo via ttm_bo_pin() and updates the shrinker's shrinkable /
528 - * purgeable page accounting to match. Must be called with @bo's dma-resv
529 - * held. Safe to call regardless of which pin path (kernel, external,
530 - * framebuffer, backup object, ...) is pinning @bo.
531 - */
532 - void xe_bo_pin_account(struct xe_bo *bo)
533 - {
534 - ttm_bo_pin(&bo->ttm);
535 - xe_bo_account_pin(bo);
536 - }
537 -
538 - /**
539 - * xe_bo_unpin_account() - Unpin a bo and account its pages for the shrinker
540 - * @bo: The buffer object to unpin.
541 - *
542 - * Counterpart to xe_bo_pin_account(). Updates the shrinker's shrinkable /
543 - * purgeable page accounting to match, then unpins @bo via ttm_bo_unpin().
544 - * Must be called with @bo's dma-resv held.
545 - */
546 - void xe_bo_unpin_account(struct xe_bo *bo)
547 - {
548 - xe_bo_account_unpin(bo);
549 - ttm_bo_unpin(&bo->ttm);
550 - }
551 -
552 458 static void update_global_total_pages(struct ttm_device *ttm_dev,
553 459 long num_pages)
554 460 {
@@ -1483,8 +1389,7 @@ int xe_bo_notifier_prepare_pinned(struct xe_bo *bo)
1483 1389 }
1484 1390
1485 1391 backup->parent_obj = xe_bo_get(bo); /* Released by bo_destroy */
1486 - /* Note: XE_BO_FLAG_SYSTEM resolves to XE_PL_TT so already populated. */
1487 - xe_bo_pin_account(backup);
1392 + ttm_bo_pin(&backup->ttm);
1488 1393 bo->backup_obj = backup;
1489 1394 }
1490 1395
@@ -1504,7 +1409,7 @@ int xe_bo_notifier_unprepare_pinned(struct xe_bo *bo)
1504 1409 {
1505 1410 xe_bo_lock(bo, false);
1506 1411 if (bo->backup_obj) {
1507 - xe_bo_unpin_account(bo->backup_obj);
1412 + ttm_bo_unpin(&bo->backup_obj->ttm);
1508 1413 xe_bo_put(bo->backup_obj);
1509 1414 bo->backup_obj = NULL;
1510 1415 }
@@ -1715,7 +1620,7 @@ out_backup:
1715 1620 xe_bo_vunmap(backup);
1716 1621 if (!bo->backup_obj) {
1717 1622 if (xe_bo_is_pinned(backup))
1718 - xe_bo_unpin_account(backup);
1623 + ttm_bo_unpin(&backup->ttm);
1719 1624 xe_bo_put(backup);
1720 1625 }
1721 1626 out_unlock_bo:
@@ -2107,6 +2012,15 @@ static vm_fault_t xe_err_to_fault_t(int err)
2107 2012 return VM_FAULT_SIGBUS;
2108 2013 }
2109 2014
2015 + static bool xe_ttm_bo_is_imported(struct ttm_buffer_object *tbo)
2016 + {
2017 + dma_resv_assert_held(tbo->base.resv);
2018 +
2019 + return tbo->ttm &&
2020 + (tbo->ttm->page_flags & (TTM_TT_FLAG_EXTERNAL | TTM_TT_FLAG_EXTERNAL_MAPPABLE)) ==
2021 + TTM_TT_FLAG_EXTERNAL;
2022 + }
2023 +
2110 2024 static vm_fault_t xe_bo_cpu_fault_fastpath(struct vm_fault *vmf, struct xe_device *xe,
2111 2025 struct xe_bo *bo, bool needs_rpm)
2112 2026 {
@@ -3227,13 +3141,12 @@ uint64_t vram_region_gpu_offset(struct ttm_resource *res)
3227 3141 int xe_bo_pin_external(struct xe_bo *bo, bool in_place, struct drm_exec *exec)
3228 3142 {
3229 3143 struct xe_device *xe = xe_bo_device(bo);
3230 - bool first_pin = !xe_bo_is_pinned(bo);
3231 3144 int err;
3232 3145
3233 3146 xe_assert(xe, !bo->vm);
3234 3147 xe_assert(xe, xe_bo_is_user(bo));
3235 3148
3236 - if (first_pin) {
3149 + if (!xe_bo_is_pinned(bo)) {
3237 3150 if (!in_place) {
3238 3151 err = xe_bo_validate(bo, NULL, false, exec);
3239 3152 if (err)
@@ -3245,7 +3158,9 @@ int xe_bo_pin_external(struct xe_bo *bo, bool in_place, struct drm_exec *exec)
3245 3158 spin_unlock(&xe->pinned.lock);
3246 3159 }
3247 3160
3248 - xe_bo_pin_account(bo);
3161 + ttm_bo_pin(&bo->ttm);
3162 + if (bo->ttm.ttm && ttm_tt_is_populated(bo->ttm.ttm))
3163 + xe_ttm_tt_account_subtract(xe, bo->ttm.ttm);
3249 3164
3250 3165 /*
3251 3166 * FIXME: If we always use the reserve / unreserve functions for locking
@@ -3301,7 +3216,9 @@ int xe_bo_pin(struct xe_bo *bo, struct drm_exec *exec)
3301 3216 spin_unlock(&xe->pinned.lock);
3302 3217 }
3303 3218
3304 - xe_bo_pin_account(bo);
3219 + ttm_bo_pin(&bo->ttm);
3220 + if (bo->ttm.ttm && ttm_tt_is_populated(bo->ttm.ttm))
3221 + xe_ttm_tt_account_subtract(xe, bo->ttm.ttm);
3305 3222
3306 3223 /*
3307 3224 * FIXME: If we always use the reserve / unreserve functions for locking
@@ -3330,7 +3247,14 @@ void xe_bo_unpin_external(struct xe_bo *bo)
3330 3247 xe_assert(xe, xe_bo_is_pinned(bo));
3331 3248 xe_assert(xe, xe_bo_is_user(bo));
3332 3249
3333 - xe_bo_unpin_account(bo);
3250 + spin_lock(&xe->pinned.lock);
3251 + if (bo->ttm.pin_count == 1 && !list_empty(&bo->pinned_link))
3252 + list_del_init(&bo->pinned_link);
3253 + spin_unlock(&xe->pinned.lock);
3254 +
3255 + ttm_bo_unpin(&bo->ttm);
3256 + if (bo->ttm.ttm && ttm_tt_is_populated(bo->ttm.ttm))
3257 + xe_ttm_tt_account_add(xe, bo->ttm.ttm);
3334 3258
3335 3259 /*
3336 3260 * FIXME: If we always use the reserve / unreserve functions for locking
@@ -3348,16 +3272,21 @@ void xe_bo_unpin(struct xe_bo *bo)
3348 3272 xe_assert(xe, xe_bo_is_pinned(bo));
3349 3273
3350 3274 if (mem_type_is_vram(place->mem_type) || bo->flags & XE_BO_FLAG_GGTT) {
3275 + spin_lock(&xe->pinned.lock);
3351 3276 xe_assert(xe, !list_empty(&bo->pinned_link));
3277 + list_del_init(&bo->pinned_link);
3278 + spin_unlock(&xe->pinned.lock);
3352 3279
3353 3280 if (bo->backup_obj) {
3354 3281 if (xe_bo_is_pinned(bo->backup_obj))
3355 - xe_bo_unpin_account(bo->backup_obj);
3282 + ttm_bo_unpin(&bo->backup_obj->ttm);
3356 3283 xe_bo_put(bo->backup_obj);
3357 3284 bo->backup_obj = NULL;
3358 3285 }
3359 3286 }
3360 - xe_bo_unpin_account(bo);
3287 + ttm_bo_unpin(&bo->ttm);
3288 + if (bo->ttm.ttm && ttm_tt_is_populated(bo->ttm.ttm))
3289 + xe_ttm_tt_account_add(xe, bo->ttm.ttm);
3361 3290 }
3362 3291
3363 3292 /**
modified drivers/gpu/drm/xe/xe_bo.h
@@ -229,8 +229,6 @@ int xe_bo_pin_external(struct xe_bo *bo, bool in_place, struct drm_exec *exec);
229 229 int xe_bo_pin(struct xe_bo *bo, struct drm_exec *exec);
230 230 void xe_bo_unpin_external(struct xe_bo *bo);
231 231 void xe_bo_unpin(struct xe_bo *bo);
232 - void xe_bo_pin_account(struct xe_bo *bo);
233 - void xe_bo_unpin_account(struct xe_bo *bo);
234 232 int xe_bo_validate(struct xe_bo *bo, struct xe_vm *vm, bool allow_res_evict,
235 233 struct drm_exec *exec);
236 234
modified drivers/gpu/drm/xe/xe_i2c.c
@@ -324,15 +324,12 @@ static void xe_i2c_remove(void *data)
324 324 xe_i2c_irq_reset(xe);
325 325 xe_amc_exit(i2c);
326 326
327 - /* Stop the notifier from arming the client work before teardown. */
328 - bus_unregister_notifier(&i2c_bus_type, &i2c->bus_notifier);
329 - cancel_work_sync(&i2c->work);
330 -
331 327 for (i = 0; i < XE_I2C_MAX_CLIENTS; i++) {
332 328 i2c_unregister_device(i2c->client[i]);
333 329 i2c->client[i] = NULL;
334 330 }
335 331
332 + bus_unregister_notifier(&i2c_bus_type, &i2c->bus_notifier);
336 333 xe_i2c_unregister_adapter(i2c);
337 334 xe->i2c = NULL;
338 335 }
modified drivers/gpu/drm/xe/xe_lrc.c
@@ -1099,7 +1099,8 @@ static void xe_lrc_finish(struct xe_lrc *lrc)
1099 1099 #define CONTEXT_ACTIVE XE_LRC_CTX_TIMESTAMP_ACTIVE
1100 1100 static ssize_t setup_utilization_wa(struct xe_lrc *lrc,
1101 1101 struct xe_hw_engine *hwe,
1102 - u32 *batch, size_t max_len, bool indirect)
1102 + u32 *batch,
1103 + size_t max_len)
1103 1104 {
1104 1105 u32 *cmd = batch;
1105 1106
@@ -1130,25 +1131,19 @@ static ssize_t setup_utilization_wa(struct xe_lrc *lrc,
1130 1131 }
1131 1132
1132 1133 static ssize_t setup_timestamp_wa(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
1133 - u32 *batch, size_t max_len, bool indirect)
1134 + u32 *batch, size_t max_len)
1134 1135 {
1135 1136 const u32 ts_addr = __xe_lrc_ctx_timestamp_ggtt_addr(lrc);
1136 1137 u32 *cmd = batch;
1137 1138
1138 - if (!XE_GT_WA(lrc->gt, 16010904313))
1139 - return 0;
1140 -
1141 - if (!indirect &&
1142 - !(hwe->class == XE_ENGINE_CLASS_COPY ||
1139 + if (!XE_GT_WA(lrc->gt, 16010904313) ||
1140 + !(hwe->class == XE_ENGINE_CLASS_RENDER ||
1141 + hwe->class == XE_ENGINE_CLASS_COMPUTE ||
1142 + hwe->class == XE_ENGINE_CLASS_COPY ||
1143 1143 hwe->class == XE_ENGINE_CLASS_VIDEO_DECODE ||
1144 1144 hwe->class == XE_ENGINE_CLASS_VIDEO_ENHANCE))
1145 1145 return 0;
1146 1146
1147 - if (indirect &&
1148 - !(hwe->class == XE_ENGINE_CLASS_RENDER ||
1149 - hwe->class == XE_ENGINE_CLASS_COMPUTE))
1150 - return 0;
1151 -
1152 1147 if (xe_gt_WARN_ON(lrc->gt, max_len < 12))
1153 1148 return -ENOSPC;
1154 1149
@@ -1174,8 +1169,7 @@ static ssize_t setup_timestamp_wa(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
1174 1169
1175 1170 static ssize_t setup_configfs_post_ctx_restore_bb(struct xe_lrc *lrc,
1176 1171 struct xe_hw_engine *hwe,
1177 - u32 *batch, size_t max_len,
1178 - bool indirect)
1172 + u32 *batch, size_t max_len)
1179 1173 {
1180 1174 struct xe_device *xe = gt_to_xe(lrc->gt);
1181 1175 const u32 *user_batch;
@@ -1204,8 +1198,7 @@ static ssize_t setup_configfs_post_ctx_restore_bb(struct xe_lrc *lrc,
1204 1198
1205 1199 static ssize_t setup_configfs_mid_ctx_restore_bb(struct xe_lrc *lrc,
1206 1200 struct xe_hw_engine *hwe,
1207 - u32 *batch, size_t max_len,
1208 - bool indirect)
1201 + u32 *batch, size_t max_len)
1209 1202 {
1210 1203 struct xe_device *xe = gt_to_xe(lrc->gt);
1211 1204 const u32 *user_batch;
@@ -1234,8 +1227,7 @@ static ssize_t setup_configfs_mid_ctx_restore_bb(struct xe_lrc *lrc,
1234 1227
1235 1228 static ssize_t setup_invalidate_state_cache_wa(struct xe_lrc *lrc,
1236 1229 struct xe_hw_engine *hwe,
1237 - u32 *batch, size_t max_len,
1238 - bool indirect)
1230 + u32 *batch, size_t max_len)
1239 1231 {
1240 1232 u32 *cmd = batch;
1241 1233
@@ -1255,8 +1247,7 @@ static ssize_t setup_invalidate_state_cache_wa(struct xe_lrc *lrc,
1255 1247
1256 1248 static ssize_t setup_invalidate_auxccs_wa(struct xe_lrc *lrc,
1257 1249 struct xe_hw_engine *hwe,
1258 - u32 *batch, size_t max_len,
1259 - bool indirect)
1250 + u32 *batch, size_t max_len)
1260 1251 {
1261 1252 struct xe_gt *gt = lrc->gt;
1262 1253 u32 *(*emit)(struct xe_gt *gt, u32 *cmd) =
@@ -1273,7 +1264,7 @@ static ssize_t setup_invalidate_auxccs_wa(struct xe_lrc *lrc,
1273 1264
1274 1265 struct bo_setup {
1275 1266 ssize_t (*setup)(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
1276 - u32 *batch, size_t max_size, bool indirect);
1267 + u32 *batch, size_t max_size);
1277 1268 };
1278 1269
1279 1270 struct bo_setup_state {
@@ -1282,7 +1273,6 @@ struct bo_setup_state {
1282 1273 struct xe_hw_engine *hwe;
1283 1274 size_t max_size;
1284 1275 size_t reserve_dw;
1285 - bool indirect;
1286 1276 unsigned int offset;
1287 1277 const struct bo_setup *funcs;
1288 1278 unsigned int num_funcs;
@@ -1308,8 +1298,7 @@ static int setup_bo(struct bo_setup_state *state)
1308 1298
1309 1299 for (size_t i = 0; i < state->num_funcs; i++) {
1310 1300 ssize_t len = state->funcs[i].setup(state->lrc, state->hwe,
1311 - state->ptr, remain,
1312 - state->indirect);
1301 + state->ptr, remain);
1313 1302
1314 1303 remain -= len;
1315 1304
@@ -1415,7 +1404,6 @@ setup_indirect_ctx(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
1415 1404 struct bo_setup_state state = {
1416 1405 .lrc = lrc,
1417 1406 .hwe = hwe,
1418 - .indirect = true,
1419 1407 .max_size = (63 * 64) /* max 63 cachelines */,
1420 1408 .buffer = NULL,
1421 1409 .offset = __xe_lrc_indirect_ctx_offset(lrc),
modified drivers/gpu/drm/xe/xe_mmio.c
@@ -320,7 +320,6 @@ u64 xe_mmio_read64_2x32(struct xe_mmio *mmio, struct xe_reg reg)
320 320 return (u64)udw << 32 | ldw;
321 321 }
322 322
323 - #define __XE_MMIO_WAIT_MAX_BACKOFF_100MS (100 * USEC_PER_MSEC)
324 323 static int __xe_mmio_wait32(struct xe_mmio *mmio, struct xe_reg reg, u32 mask, u32 val,
325 324 u32 timeout_us, u32 *out_val, bool atomic, bool expect_match)
326 325 {
@@ -351,10 +350,10 @@ static int __xe_mmio_wait32(struct xe_mmio *mmio, struct xe_reg reg, u32 mask, u
351 350 wait = ktime_us_delta(end, cur);
352 351
353 352 if (atomic)
354 - udelay(min_t(s64, wait, (MAX_UDELAY_MS * 1000)));
353 + udelay(wait);
355 354 else
356 355 usleep_range(wait, wait << 1);
357 - wait = min_t(s64, wait << 1, __XE_MMIO_WAIT_MAX_BACKOFF_100MS);
356 + wait <<= 1;
358 357 }
359 358
360 359 if (ret != 0) {
modified drivers/gpu/drm/xe/xe_sysctrl_mailbox.c
@@ -19,20 +19,20 @@
19 19 #include "xe_sysctrl_mailbox_types.h"
20 20
21 21 struct xe_sysctrl_mailbox_msg_hdr {
22 - u32 data;
23 - };
22 + __le32 data;
23 + } __packed;
24 24
25 25 #define XE_SYSCTRL_HDR_GROUP_ID(hdr) \
26 - FIELD_GET(SYSCTRL_HDR_GROUP_ID_MASK, (hdr)->data)
26 + FIELD_GET(SYSCTRL_HDR_GROUP_ID_MASK, le32_to_cpu((hdr)->data))
27 27
28 28 #define XE_SYSCTRL_HDR_COMMAND(hdr) \
29 - FIELD_GET(SYSCTRL_HDR_COMMAND_MASK, (hdr)->data)
29 + FIELD_GET(SYSCTRL_HDR_COMMAND_MASK, le32_to_cpu((hdr)->data))
30 30
31 31 #define XE_SYSCTRL_HDR_IS_RESPONSE(hdr) \
32 - FIELD_GET(SYSCTRL_HDR_IS_RESPONSE, (hdr)->data)
32 + FIELD_GET(SYSCTRL_HDR_IS_RESPONSE, le32_to_cpu((hdr)->data))
33 33
34 34 #define XE_SYSCTRL_HDR_RESULT(hdr) \
35 - FIELD_GET(SYSCTRL_HDR_RESULT_MASK, (hdr)->data)
35 + FIELD_GET(SYSCTRL_HDR_RESULT_MASK, le32_to_cpu((hdr)->data))
36 36
37 37 static bool sysctrl_wait_bit_clear(struct xe_sysctrl *sc, u32 bit_mask,
38 38 unsigned int timeout_ms)
@@ -126,8 +126,8 @@ static int sysctrl_prepare_command(struct xe_device *xe,
126 126 return -ENOMEM;
127 127
128 128 hdr = (struct xe_sysctrl_mailbox_msg_hdr *)buffer;
129 - hdr->data = FIELD_PREP(SYSCTRL_HDR_GROUP_ID_MASK, group_id) |
130 - FIELD_PREP(SYSCTRL_HDR_COMMAND_MASK, command);
129 + hdr->data = cpu_to_le32(FIELD_PREP(SYSCTRL_HDR_GROUP_ID_MASK, group_id) |
130 + FIELD_PREP(SYSCTRL_HDR_COMMAND_MASK, command));
131 131
132 132 if (data_in && data_in_len)
133 133 memcpy(buffer + sizeof(*hdr), data_in, data_in_len);
modified drivers/i2c/busses/i2c-qcom-geni.c
@@ -1003,14 +1003,13 @@ static int geni_i2c_xfer(struct i2c_adapter *adap,
1003 1003
1004 1004 ret = gi2c->dev_data->set_rate(&gi2c->se, gi2c->clk_freq_out);
1005 1005 if (ret)
1006 - goto out_pm;
1006 + return ret;
1007 1007
1008 1008 if (gi2c->gpi_mode)
1009 1009 ret = geni_i2c_gpi_xfer(gi2c, msgs, num);
1010 1010 else
1011 1011 ret = geni_i2c_fifo_xfer(gi2c, msgs, num);
1012 1012
1013 - out_pm:
1014 1013 pm_runtime_put_autosuspend(gi2c->se.dev);
1015 1014 gi2c->cur = NULL;
1016 1015 gi2c->err = 0;
modified drivers/input/joystick/xpad.c
@@ -302,8 +302,6 @@ static const struct xpad_device {
302 302 { 0x17ef, 0x6182, "Lenovo Legion Controller for Windows", 0, XTYPE_XBOX360 },
303 303 { 0x1949, 0x041a, "Amazon Game Controller", 0, XTYPE_XBOX360 },
304 304 { 0x1a86, 0xe310, "Legion Go S", 0, XTYPE_XBOX360 },
305 - { 0x1b1c, 0x2b1f, "Corsair Novablade Pro (Wired)", 0, XTYPE_XBOX360 },
306 - { 0x1b1c, 0x2b2b, "Corsair Novablade Pro (2.4 GHz Receiver)", 0, XTYPE_XBOX360 },
307 305 { 0x1bad, 0x0002, "Harmonix Rock Band Guitar", 0, XTYPE_XBOX360 },
308 306 { 0x1bad, 0x0003, "Harmonix Rock Band Drumkit", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
309 307 { 0x1bad, 0x0130, "Ion Drum Rocker", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
@@ -381,7 +379,6 @@ static const struct xpad_device {
381 379 { 0x2993, 0x2001, "TECNO Pocket Go", 0, XTYPE_XBOX360 },
382 380 { 0x2dc8, 0x2000, "8BitDo Pro 2 Wired Controller fox Xbox", 0, XTYPE_XBOXONE },
383 381 { 0x2dc8, 0x200f, "8BitDo Ultimate 3-mode Controller for Xbox", MAP_SHARE_BUTTON, XTYPE_XBOXONE },
384 - { 0x2dc8, 0x201e, "8BitDo Pro 2 Wired Controller for Xbox", MAP_SHARE_BUTTON, XTYPE_XBOXONE },
385 382 { 0x2dc8, 0x3106, "8BitDo Ultimate Wireless / Pro 2 Wired Controller", 0, XTYPE_XBOX360 },
386 383 { 0x2dc8, 0x3109, "8BitDo Ultimate Wireless Bluetooth", 0, XTYPE_XBOX360 },
387 384 { 0x2dc8, 0x310a, "8BitDo Ultimate 2C Wireless Controller", 0, XTYPE_XBOX360 },
@@ -548,7 +545,6 @@ static const struct usb_device_id xpad_table[] = {
548 545 XPAD_XBOX360_VENDOR(0x17ef), /* Lenovo */
549 546 XPAD_XBOX360_VENDOR(0x1949), /* Amazon controllers */
550 547 XPAD_XBOX360_VENDOR(0x1a86), /* Nanjing Qinheng Microelectronics (WCH) */
551 - XPAD_XBOX360_VENDOR(0x1b1c), /* Corsair controllers */
552 548 XPAD_XBOX360_VENDOR(0x1bad), /* Harmonix Rock Band guitar and drums */
553 549 XPAD_XBOX360_VENDOR(0x1ee9), /* ZOTAC Technology Limited */
554 550 XPAD_XBOX360_VENDOR(0x20bc), /* BETOP wireless dongles */
modified drivers/input/misc/ati_remote2.c
@@ -672,7 +672,8 @@ static ssize_t ati_remote2_show_channel_mask(struct device *dev,
672 672 struct device_attribute *attr,
673 673 char *buf)
674 674 {
675 - struct usb_interface *intf = to_usb_interface(dev);
675 + struct usb_device *udev = to_usb_device(dev);
676 + struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
676 677 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
677 678
678 679 return sprintf(buf, "0x%04x\n", ar2->channel_mask);
@@ -682,7 +683,8 @@ static ssize_t ati_remote2_store_channel_mask(struct device *dev,
682 683 struct device_attribute *attr,
683 684 const char *buf, size_t count)
684 685 {
685 - struct usb_interface *intf = to_usb_interface(dev);
686 + struct usb_device *udev = to_usb_device(dev);
687 + struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
686 688 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
687 689 unsigned int mask;
688 690 int r;
@@ -718,7 +720,8 @@ static ssize_t ati_remote2_show_mode_mask(struct device *dev,
718 720 struct device_attribute *attr,
719 721 char *buf)
720 722 {
721 - struct usb_interface *intf = to_usb_interface(dev);
723 + struct usb_device *udev = to_usb_device(dev);
724 + struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
722 725 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
723 726
724 727 return sprintf(buf, "0x%02x\n", ar2->mode_mask);
@@ -728,7 +731,8 @@ static ssize_t ati_remote2_store_mode_mask(struct device *dev,
728 731 struct device_attribute *attr,
729 732 const char *buf, size_t count)
730 733 {
731 - struct usb_interface *intf = to_usb_interface(dev);
734 + struct usb_device *udev = to_usb_device(dev);
735 + struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
732 736 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
733 737 unsigned int mask;
734 738 int err;
modified drivers/iommu/dma-iommu.c
@@ -1228,9 +1228,9 @@ dma_addr_t iommu_dma_map_phys(struct device *dev, phys_addr_t phys, size_t size,
1228 1228 * If both the physical buffer start address and size are page aligned,
1229 1229 * we don't need to use a bounce page.
1230 1230 */
1231 - if (!(attrs & DMA_ATTR_MMIO) && dev_use_swiotlb(dev, size, dir) &&
1231 + if (dev_use_swiotlb(dev, size, dir) &&
1232 1232 iova_unaligned(iovad, phys, size)) {
1233 - if (attrs & DMA_ATTR_REQUIRE_COHERENT)
1233 + if (attrs & (DMA_ATTR_MMIO | DMA_ATTR_REQUIRE_COHERENT))
1234 1234 return DMA_MAPPING_ERROR;
1235 1235
1236 1236 phys = iommu_dma_map_swiotlb(dev, phys, size, dir, attrs);
modified drivers/md/dm-crypt.c
@@ -2894,13 +2894,8 @@ static int crypt_ctr_cipher_new(struct dm_target *ti, char *cipher_in, char *key
2894 2894 }
2895 2895 }
2896 2896
2897 - if (*ivmode && !strcmp(*ivmode, "lmk")) {
2898 - if (crypt_integrity_aead(cc)) {
2899 - ti->error = "AEAD transforms not supported for LMK";
2900 - return -EINVAL;
2901 - }
2897 + if (*ivmode && !strcmp(*ivmode, "lmk"))
2902 2898 cc->tfms_count = 64;
2903 - }
2904 2899
2905 2900 if (*ivmode && !strcmp(*ivmode, "essiv")) {
2906 2901 if (!*ivopts) {
modified drivers/md/dm-integrity.c
@@ -180,7 +180,6 @@ struct dm_integrity_c {
180 180 struct dm_bufio_client *bufio;
181 181 struct workqueue_struct *metadata_wq;
182 182 struct superblock *sb;
183 - struct superblock *sb_copy;
184 183 unsigned int journal_pages;
185 184 unsigned int n_bitmap_blocks;
186 185
@@ -2722,7 +2721,7 @@ static void dm_integrity_inline_recheck(struct work_struct *w)
2722 2721 outgoing_data = dio->integrity_payload + PAGE_SIZE;
2723 2722
2724 2723 while (dio->bio_details.bi_iter.bi_size) {
2725 - char digest[MAX_T(size_t, HASH_MAX_DIGESTSIZE, MAX_TAG_SIZE)];
2724 + char digest[HASH_MAX_DIGESTSIZE];
2726 2725 int r;
2727 2726 struct bio_integrity_payload *bip;
2728 2727 struct bio_vec bv;
@@ -2789,7 +2788,7 @@ static inline bool dm_integrity_check(struct dm_integrity_c *ic, struct dm_integ
2789 2788 unsigned pos = 0;
2790 2789
2791 2790 while (dio->bio_details.bi_iter.bi_size) {
2792 - char digest[MAX_T(size_t, HASH_MAX_DIGESTSIZE, MAX_TAG_SIZE)];
2791 + char digest[HASH_MAX_DIGESTSIZE];
2793 2792 struct bio_vec bv = bio_iter_iovec(bio, dio->bio_details.bi_iter);
2794 2793 char *mem = integrity_kmap(ic, bv.bv_page);
2795 2794 integrity_sector_checksum(ic, &dio->ahash_req, dio->bio_details.bi_iter.bi_sector, mem, bv.bv_offset, digest);
@@ -3859,35 +3858,6 @@ static void dm_integrity_postsuspend(struct dm_target *ti)
3859 3858 ic->journal_uptodate = true;
3860 3859 }
3861 3860
3862 - /*
3863 - * The superblock is re-read from the device on every resume, so that we pick
3864 - * up the flags and the recalculate position. The geometry described by the
3865 - * superblock must not change though - the in-memory structures (and the
3866 - * journal in particular) were sized according to the superblock that was
3867 - * validated in the constructor. Reject a superblock that was modified behind
3868 - * our back.
3869 - *
3870 - * Only the fields that the driver never rewrites may be tested here. In
3871 - * particular, "version" is recalculated by sb_set_version on every superblock
3872 - * write and it depends on SB_FLAG_RECALCULATING and SB_FLAG_DIRTY_BITMAP, and
3873 - * SB_FLAG_DISCARD_KEYED may be set by dm_integrity_resume itself.
3874 - */
3875 - static bool superblock_changed(struct dm_integrity_c *ic)
3876 - {
3877 - const __le32 immutable_flags = cpu_to_le32(SB_FLAG_HAVE_JOURNAL_MAC |
3878 - SB_FLAG_FIXED_PADDING |
3879 - SB_FLAG_FIXED_HMAC |
3880 - SB_FLAG_INLINE);
3881 -
3882 - return memcmp(ic->sb->magic, ic->sb_copy->magic, sizeof(ic->sb->magic)) != 0 ||
3883 - ic->sb->log2_interleave_sectors != ic->sb_copy->log2_interleave_sectors ||
3884 - ic->sb->integrity_tag_size != ic->sb_copy->integrity_tag_size ||
3885 - ic->sb->journal_sections != ic->sb_copy->journal_sections ||
3886 - ic->sb->log2_sectors_per_block != ic->sb_copy->log2_sectors_per_block ||
3887 - ((ic->sb->flags ^ ic->sb_copy->flags) & immutable_flags) != 0 ||
3888 - memcmp(ic->sb->salt, ic->sb_copy->salt, SALT_SIZE) != 0;
3889 - }
3890 -
3891 3861 static void dm_integrity_resume(struct dm_target *ti)
3892 3862 {
3893 3863 struct dm_integrity_c *ic = ti->private;
@@ -3906,18 +3876,6 @@ static void dm_integrity_resume(struct dm_target *ti)
3906 3876 if (r)
3907 3877 dm_integrity_io_error(ic, "reading superblock", r);
3908 3878
3909 - if (unlikely(superblock_changed(ic))) {
3910 - /*
3911 - * Restore the superblock that we validated in the constructor,
3912 - * so that the rest of the driver doesn't operate on values
3913 - * that don't match the in-memory structures.
3914 - */
3915 - memcpy(ic->sb, ic->sb_copy, sizeof(struct superblock));
3916 - DMERR("The superblock was changed while the device was suspended");
3917 - dm_integrity_io_error(ic, "superblock check", -EINVAL);
3918 - goto skip_writes;
3919 - }
3920 -
3921 3879 if (ic->mode == 'R')
3922 3880 goto skip_writes;
3923 3881
@@ -5469,13 +5427,6 @@ try_smaller_buffer:
5469 5427 ic->just_formatted = true;
5470 5428 }
5471 5429
5472 - ic->sb_copy = kmemdup(ic->sb, sizeof(struct superblock), GFP_KERNEL);
5473 - if (!ic->sb_copy) {
5474 - ti->error = "Cannot allocate superblock copy";
5475 - r = -ENOMEM;
5476 - goto bad;
5477 - }
5478 -
5479 5430 if (!ic->meta_dev && ic->mode != 'I') {
5480 5431 r = dm_set_target_max_io_len(ti, 1U << ic->sb->log2_interleave_sectors);
5481 5432 if (r)
@@ -5574,7 +5525,6 @@ static void dm_integrity_dtr(struct dm_target *ti)
5574 5525 kvfree(ic->journal_tree);
5575 5526 if (ic->sb)
5576 5527 free_pages_exact(ic->sb, SB_SECTORS << SECTOR_SHIFT);
5577 - kfree(ic->sb_copy);
5578 5528
5579 5529 if (ic->internal_shash)
5580 5530 crypto_free_shash(ic->internal_shash);
modified drivers/md/dm-ioctl.c
@@ -656,16 +656,10 @@ static void *get_result_buffer(struct dm_ioctl *param, size_t param_size,
656 656 {
657 657 param->data_start = align_ptr(param + 1) - (void *) param;
658 658
659 - if (param->data_start < param_size) {
659 + if (param->data_start < param_size)
660 660 *len = param_size - param->data_start;
661 - } else {
662 - /*
663 - * The buffer can be as small as offsetof(*param, data), which
664 - * is less than sizeof(*param), so don't run off the end of it.
665 - */
661 + else
666 662 *len = 0;
667 - param->data_start = param_size;
668 - }
669 663
670 664 return ((void *) param) + param->data_start;
671 665 }
@@ -1273,7 +1267,6 @@ static int do_resume(struct dm_ioctl *param)
1273 1267 /* Do we need to load a new map ? */
1274 1268 if (new_map) {
1275 1269 sector_t old_size, new_size;
1276 - blk_mode_t new_map_mode;
1277 1270
1278 1271 dm_ima_context_table_op(md, ima_context, DM_IMA_TABLE_SAVE);
1279 1272 /* Suspend if it isn't already suspended */
@@ -1306,7 +1299,6 @@ static int do_resume(struct dm_ioctl *param)
1306 1299 }
1307 1300 }
1308 1301
1309 - new_map_mode = dm_table_get_mode(new_map);
1310 1302 old_size = dm_get_size(md);
1311 1303 old_map = dm_swap_table(md, new_map);
1312 1304 if (IS_ERR(old_map)) {
@@ -1322,7 +1314,7 @@ static int do_resume(struct dm_ioctl *param)
1322 1314 if (old_size && new_size && old_size != new_size)
1323 1315 need_resize_uevent = true;
1324 1316
1325 - if (new_map_mode & BLK_OPEN_WRITE)
1317 + if (dm_table_get_mode(new_map) & BLK_OPEN_WRITE)
1326 1318 set_disk_ro(dm_disk(md), 0);
1327 1319 else
1328 1320 set_disk_ro(dm_disk(md), 1);
modified drivers/md/dm-snap.c
@@ -1292,20 +1292,6 @@ static int snapshot_ctr(struct dm_target *ti, unsigned int argc, char **argv)
1292 1292 goto bad_store;
1293 1293 }
1294 1294
1295 - /*
1296 - * snapshot-merge requires the optional prepare_merge/commit_merge
1297 - * callbacks; the transient exception store does not implement them.
1298 - * The handover path checks this in __validate_exception_handover(),
1299 - * but a directly constructed snapshot-merge never goes through it.
1300 - */
1301 - if (dm_target_is_snapshot_merge(ti) &&
1302 - (!s->store->type->prepare_merge ||
1303 - !s->store->type->commit_merge)) {
1304 - ti->error = "Snapshot exception store does not support snapshot-merge.";
1305 - r = -EINVAL;
1306 - goto bad_hash_tables;
1307 - }
1308 -
1309 1295 argv += args_used;
1310 1296 argc -= args_used;
1311 1297
modified drivers/media/usb/em28xx/em28xx-video.c
@@ -2416,7 +2416,7 @@ static int em28xx_v4l2_fini(struct em28xx *dev)
2416 2416 if (video_is_registered(&v4l2->radio_dev)) {
2417 2417 dev_info(&dev->intf->dev, "V4L2 device %s deregistered\n",
2418 2418 video_device_node_name(&v4l2->radio_dev));
2419 - video_unregister_device(&v4l2->radio_dev);
2419 + vb2_video_unregister_device(&v4l2->radio_dev);
2420 2420 }
2421 2421 if (video_is_registered(&v4l2->vbi_dev)) {
2422 2422 dev_info(&dev->intf->dev, "V4L2 device %s deregistered\n",
@@ -3082,7 +3082,7 @@ unregister_dev:
3082 3082 dev_info(&dev->intf->dev,
3083 3083 "V4L2 device %s deregistered\n",
3084 3084 video_device_node_name(&v4l2->radio_dev));
3085 - video_unregister_device(&v4l2->radio_dev);
3085 + vb2_video_unregister_device(&v4l2->radio_dev);
3086 3086 }
3087 3087 if (video_is_registered(&v4l2->vbi_dev)) {
3088 3088 dev_info(&dev->intf->dev,
modified drivers/memstick/core/memstick.c
@@ -370,7 +370,9 @@ int memstick_set_rw_addr(struct memstick_dev *card)
370 370 {
371 371 card->next_request = h_memstick_set_rw_addr;
372 372 memstick_new_req(card->host);
373 - wait_for_completion(&card->mrq_complete);
373 + if (!wait_for_completion_timeout(&card->mrq_complete,
374 + msecs_to_jiffies(500)))
375 + card->current_mrq.error = -ETIMEDOUT;
374 376
375 377 return card->current_mrq.error;
376 378 }
@@ -403,7 +405,9 @@ static struct memstick_dev *memstick_alloc_card(struct memstick_host *host)
403 405
404 406 card->next_request = h_memstick_read_dev_id;
405 407 memstick_new_req(host);
406 - wait_for_completion(&card->mrq_complete);
408 + if (!wait_for_completion_timeout(&card->mrq_complete,
409 + msecs_to_jiffies(500)))
410 + card->current_mrq.error = -ETIMEDOUT;
407 411
408 412 if (card->current_mrq.error)
409 413 goto err_out;
modified drivers/memstick/host/rtsx_usb_ms.c
@@ -27,6 +27,7 @@ struct rtsx_usb_ms {
27 27 struct memstick_host *msh;
28 28 struct memstick_request *req;
29 29
30 + struct mutex host_mutex;
30 31 struct work_struct handle_req;
31 32 struct delayed_work poll_card;
32 33
@@ -513,13 +514,6 @@ static void rtsx_usb_ms_handle_req(struct work_struct *work)
513 514 struct memstick_host *msh = host->msh;
514 515 int rc;
515 516
516 - /* Fail requests after eject so their waiters are released. */
517 - if (host->eject) {
518 - while (!memstick_next_req(msh, &host->req))
519 - host->req->error = -ENOMEDIUM;
520 - return;
521 - }
522 -
523 517 if (!host->req) {
524 518 pm_runtime_get_sync(ms_dev(host));
525 519 do {
@@ -553,7 +547,8 @@ static void rtsx_usb_ms_request(struct memstick_host *msh)
553 547
554 548 dev_dbg(ms_dev(host), "--> %s\n", __func__);
555 549
556 - schedule_work(&host->handle_req);
550 + if (!host->eject)
551 + schedule_work(&host->handle_req);
557 552 }
558 553
559 554 static int rtsx_usb_ms_set_param(struct memstick_host *msh,
@@ -786,6 +781,7 @@ static int rtsx_usb_ms_drv_probe(struct platform_device *pdev)
786 781 host->power_mode = MEMSTICK_POWER_OFF;
787 782 platform_set_drvdata(pdev, host);
788 783
784 + mutex_init(&host->host_mutex);
789 785 INIT_WORK(&host->handle_req, rtsx_usb_ms_handle_req);
790 786
791 787 INIT_DELAYED_WORK(&host->poll_card, rtsx_usb_ms_poll_card);
@@ -816,12 +812,27 @@ static void rtsx_usb_ms_drv_remove(struct platform_device *pdev)
816 812 {
817 813 struct rtsx_usb_ms *host = platform_get_drvdata(pdev);
818 814 struct memstick_host *msh = host->msh;
815 + int err;
819 816
820 817 host->eject = true;
821 818 msh->removing = true;
822 - flush_work(&host->handle_req);
819 + cancel_work_sync(&host->handle_req);
823 820 cancel_delayed_work_sync(&host->poll_card);
824 821
822 + mutex_lock(&host->host_mutex);
823 + if (host->req) {
824 + dev_dbg(ms_dev(host),
825 + "%s: Controller removed during transfer\n",
826 + dev_name(&msh->dev));
827 + host->req->error = -ENOMEDIUM;
828 + do {
829 + err = memstick_next_req(msh, &host->req);
830 + if (!err)
831 + host->req->error = -ENOMEDIUM;
832 + } while (!err);
833 + }
834 + mutex_unlock(&host->host_mutex);
835 +
825 836 /* Balance possible unbalanced usage count
826 837 * e.g. unconditional module removal
827 838 */
@@ -830,8 +841,6 @@ static void rtsx_usb_ms_drv_remove(struct platform_device *pdev)
830 841
831 842 pm_runtime_disable(ms_dev(host));
832 843 memstick_remove_host(msh);
833 - /* No card, no new requests; wait for the last failed one to finish. */
834 - cancel_work_sync(&host->handle_req);
835 844 dev_dbg(ms_dev(host),
836 845 ": Realtek USB Memstick controller has been removed\n");
837 846 memstick_free_host(msh);
modified drivers/mmc/host/cavium-octeon.c
@@ -295,12 +295,9 @@ static void octeon_mmc_remove(struct platform_device *pdev)
295 295 u64 dma_cfg;
296 296 int i;
297 297
298 - for (i = 0; i < CAVIUM_MAX_MMC; i++) {
298 + for (i = 0; i < CAVIUM_MAX_MMC; i++)
299 299 if (host->slot[i])
300 300 cvm_mmc_of_slot_remove(host->slot[i]);
301 - if (host->slot_pdev[i])
302 - of_platform_device_destroy(&host->slot_pdev[i]->dev, NULL);
303 - }
304 301
305 302 dma_cfg = readq(host->dma_base + MIO_EMM_DMA_CFG(host));
306 303 dma_cfg &= ~MIO_EMM_DMA_CFG_EN;
modified drivers/mmc/host/cavium-thunderx.c
@@ -173,12 +173,9 @@ static void thunder_mmc_remove(struct pci_dev *pdev)
173 173 u64 dma_cfg;
174 174 int i;
175 175
176 - for (i = 0; i < CAVIUM_MAX_MMC; i++) {
176 + for (i = 0; i < CAVIUM_MAX_MMC; i++)
177 177 if (host->slot[i])
178 178 cvm_mmc_of_slot_remove(host->slot[i]);
179 - if (host->slot_pdev[i])
180 - of_platform_device_destroy(&host->slot_pdev[i]->dev, NULL);
181 - }
182 179
183 180 dma_cfg = readq(host->dma_base + MIO_EMM_DMA_CFG(host));
184 181 dma_cfg &= ~MIO_EMM_DMA_CFG_EN;
modified drivers/mmc/host/mtk-sd.c
@@ -3216,7 +3216,6 @@ static void msdc_drv_remove(struct platform_device *pdev)
3216 3216
3217 3217 platform_set_drvdata(pdev, NULL);
3218 3218 mmc_remove_host(mmc);
3219 - cancel_delayed_work_sync(&host->req_timeout);
3220 3219 msdc_deinit_hw(host);
3221 3220 msdc_gate_clock(host);
3222 3221
modified drivers/mmc/host/sdhci-sprd.c
@@ -890,10 +890,6 @@ static void sdhci_sprd_remove(struct platform_device *pdev)
890 890 struct sdhci_host *host = platform_get_drvdata(pdev);
891 891 struct sdhci_sprd_host *sprd_host = TO_SPRD_HOST(host);
892 892
893 - pm_runtime_get_sync(&pdev->dev);
894 - pm_runtime_disable(&pdev->dev);
895 - pm_runtime_put_noidle(&pdev->dev);
896 -
897 893 sdhci_remove_host(host, 0);
898 894
899 895 clk_disable_unprepare(sprd_host->clk_sdio);
modified drivers/net/amt.c
@@ -80,6 +80,15 @@ static struct in6_addr mld2_all_node = MLD2_ALL_NODE_INIT;
80 80 static struct mld2_grec mldv2_zero_grec;
81 81 #endif
82 82
83 + static struct amt_skb_cb *amt_skb_cb(struct sk_buff *skb)
84 + {
85 + BUILD_BUG_ON(sizeof(struct amt_skb_cb) + sizeof(struct tc_skb_cb) >
86 + sizeof_field(struct sk_buff, cb));
87 +
88 + return (struct amt_skb_cb *)((void *)skb->cb +
89 + sizeof(struct tc_skb_cb));
90 + }
91 +
83 92 static void __amt_source_gc_work(void)
84 93 {
85 94 struct amt_source_node *snode;
@@ -782,11 +791,6 @@ out:
782 791 rcu_read_unlock();
783 792 }
784 793
785 - static bool amt_send_membership_query(struct amt_dev *amt,
786 - struct sk_buff *skb,
787 - struct amt_tunnel_list *tunnel,
788 - bool v6);
789 -
790 794 static void amt_send_igmp_gq(struct amt_dev *amt,
791 795 struct amt_tunnel_list *tunnel)
792 796 {
@@ -796,11 +800,8 @@ static void amt_send_igmp_gq(struct amt_dev *amt,
796 800 if (!skb)
797 801 return;
798 802
799 - skb_pull(skb, sizeof(struct ethhdr));
800 - if (amt_send_membership_query(amt, skb, tunnel, false)) {
801 - amt->dev->stats.tx_dropped++;
802 - kfree_skb(skb);
803 - }
803 + amt_skb_cb(skb)->tunnel = tunnel;
804 + dev_queue_xmit(skb);
804 805 }
805 806
806 807 #if IS_ENABLED(CONFIG_IPV6)
@@ -884,11 +885,8 @@ static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel)
884 885 if (!skb)
885 886 return;
886 887
887 - skb_pull(skb, sizeof(struct ethhdr));
888 - if (amt_send_membership_query(amt, skb, tunnel, true)) {
889 - amt->dev->stats.tx_dropped++;
890 - kfree_skb(skb);
891 - }
888 + amt_skb_cb(skb)->tunnel = tunnel;
889 + dev_queue_xmit(skb);
892 890 }
893 891 #else
894 892 static void amt_send_mld_gq(struct amt_dev *amt, struct amt_tunnel_list *tunnel)
@@ -1188,6 +1186,7 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)
1188 1186 #endif
1189 1187 bool report = false;
1190 1188 struct igmphdr *ih;
1189 + bool query = false;
1191 1190 struct iphdr *iph;
1192 1191 bool data = false;
1193 1192 bool v6 = false;
@@ -1205,6 +1204,9 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)
1205 1204 case IGMP_HOST_MEMBERSHIP_REPORT:
1206 1205 report = true;
1207 1206 break;
1207 + case IGMP_HOST_MEMBERSHIP_QUERY:
1208 + query = true;
1209 + break;
1208 1210 default:
1209 1211 goto free;
1210 1212 }
@@ -1226,6 +1228,9 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)
1226 1228 case ICMPV6_MLD2_REPORT:
1227 1229 report = true;
1228 1230 break;
1231 + case ICMPV6_MGM_QUERY:
1232 + query = true;
1233 + break;
1229 1234 default:
1230 1235 goto free;
1231 1236 }
@@ -1256,6 +1261,19 @@ static netdev_tx_t amt_dev_xmit(struct sk_buff *skb, struct net_device *dev)
1256 1261 goto free;
1257 1262 goto unlock;
1258 1263 } else if (amt->mode == AMT_MODE_RELAY) {
1264 + if (query) {
1265 + tunnel = amt_skb_cb(skb)->tunnel;
1266 + if (!tunnel) {
1267 + WARN_ON(1);
1268 + goto free;
1269 + }
1270 +
1271 + /* Do not forward unexpected query */
1272 + if (amt_send_membership_query(amt, skb, tunnel, v6))
1273 + goto free;
1274 + goto unlock;
1275 + }
1276 +
1259 1277 if (!data)
1260 1278 goto free;
1261 1279 list_for_each_entry_rcu(tunnel, &amt->tunnel_list, list) {
modified drivers/net/bareudp.c
@@ -356,7 +356,7 @@ static int bareudp_xmit_skb(struct sk_buff *skb, struct net_device *dev,
356 356 if (err)
357 357 goto free_dst;
358 358
359 - skb_set_inner_protocol(skb, skb->protocol);
359 + skb_set_inner_protocol(skb, bareudp->ethertype);
360 360 udp_tunnel_xmit_skb(rt, sk, skb, saddr, info->key.u.ipv4.dst,
361 361 tos, ttl, df, sport, bareudp->port,
362 362 !net_eq(bareudp->net, dev_net(bareudp->dev)),
@@ -424,7 +424,6 @@ static int bareudp6_xmit_skb(struct sk_buff *skb, struct net_device *dev,
424 424 if (err)
425 425 goto free_dst;
426 426
427 - skb_set_inner_protocol(skb, skb->protocol);
428 427 daddr = info->key.u.ipv6.dst;
429 428 udp_tunnel6_xmit_skb(dst, sk, skb, dev,
430 429 &saddr, &daddr, prio, ttl,
modified drivers/net/bonding/bond_main.c
@@ -5732,12 +5732,12 @@ static int bond_xdp_set(struct net_device *dev, struct bpf_prog *prog,
5732 5732 bpf_prog_inc(prog);
5733 5733 }
5734 5734
5735 - if (prog && !old_prog)
5735 + if (prog) {
5736 5736 static_branch_inc(&bpf_master_redirect_enabled_key);
5737 - else if (!prog && old_prog)
5738 - static_branch_dec(&bpf_master_redirect_enabled_key);
5739 - if (old_prog)
5737 + } else if (old_prog) {
5740 5738 bpf_prog_put(old_prog);
5739 + static_branch_dec(&bpf_master_redirect_enabled_key);
5740 + }
5741 5741
5742 5742 return 0;
5743 5743
modified drivers/net/can/dev/skb.c
@@ -210,10 +210,6 @@ static void init_can_skb(struct sk_buff *skb)
210 210 {
211 211 skb->pkt_type = PACKET_BROADCAST;
212 212 skb->ip_summed = CHECKSUM_UNNECESSARY;
213 -
214 - skb_reset_mac_header(skb);
215 - skb_reset_network_header(skb);
216 - skb_reset_transport_header(skb);
217 213 }
218 214
219 215 struct sk_buff *alloc_can_skb(struct net_device *dev, struct can_frame **cf)
modified drivers/net/can/usb/f81604.c
@@ -169,7 +169,7 @@ struct f81604_int_data {
169 169 u8 rxerr;
170 170 u8 txerr;
171 171 u8 val;
172 - } __packed;
172 + } __packed __aligned(4);
173 173
174 174 struct f81604_sff {
175 175 __be16 id;
modified drivers/net/can/vxcan.c
@@ -79,9 +79,6 @@ static netdev_tx_t vxcan_xmit(struct sk_buff *oskb, struct net_device *dev)
79 79
80 80 /* reset CAN GW hop counter */
81 81 csx->can_gw_hops = 0;
82 - /* start with new CAN skb UID in the other namespace */
83 - csx->can_skb_uid = 0;
84 -
85 82 skb->pkt_type = PACKET_BROADCAST;
86 83 skb->dev = peer;
87 84 skb->ip_summed = CHECKSUM_UNNECESSARY;
modified drivers/net/dsa/microchip/ksz_common.h
@@ -853,7 +853,7 @@ static inline bool ksz_is_sgmii_port(struct ksz_device *dev, int port)
853 853 #define KSZ88_FAMILY_ID 0x88
854 854 #define KSZ8895_FAMILY_ID 0x95
855 855
856 - #define KSZ8_PORT_STATUS_0 0x18
856 + #define KSZ8_PORT_STATUS_0 0x08
857 857 #define KSZ8_PORT_FIBER_MODE BIT(7)
858 858
859 859 #define SW_CHIP_ID_M GENMASK(7, 4)
modified drivers/net/ethernet/airoha/airoha_eth.c
@@ -2800,34 +2800,14 @@ static int airoha_qdma_set_trtcm_param(struct airoha_qdma *qdma, int channel,
2800 2800 FIELD_PREP(TRTCM_METER_GROUP_MASK, group) |
2801 2801 FIELD_PREP(TRTCM_PARAM_INDEX_MASK, idx) |
2802 2802 FIELD_PREP(TRTCM_PARAM_RATE_TYPE_MASK, mode);
2803 - int i;
2804 -
2805 - /*
2806 - * HW might be in the middle of bucket handling and might
2807 - * require an additional try to actually apply the new TRTCM
2808 - * config.
2809 - */
2810 - for (i = 0; i < TRTCM_CONFIG_RETRY_MAX; i++) {
2811 - u32 data = 0;
2812 -
2813 - airoha_qdma_wr(qdma, REG_TRTCM_DATA_LOW(addr), val);
2814 - airoha_qdma_wr(qdma, REG_TRTCM_CFG_PARAM(addr), config);
2815 -
2816 - if (read_poll_timeout(airoha_qdma_rr, data,
2817 - data & TRTCM_PARAM_RW_DONE_MASK,
2818 - USEC_PER_MSEC, 10 * USEC_PER_MSEC,
2819 - true, qdma, REG_TRTCM_CFG_PARAM(addr)))
2820 - continue;
2821 -
2822 - if (airoha_qdma_get_trtcm_param(qdma, channel, addr, param,
2823 - mode, &data, NULL))
2824 - continue;
2825 2803
2826 - if (data == val)
2827 - return 0;
2828 - }
2804 + airoha_qdma_wr(qdma, REG_TRTCM_DATA_LOW(addr), val);
2805 + airoha_qdma_wr(qdma, REG_TRTCM_CFG_PARAM(addr), config);
2829 2806
2830 - return -EBUSY;
2807 + return read_poll_timeout(airoha_qdma_rr, val,
2808 + val & TRTCM_PARAM_RW_DONE_MASK,
2809 + USEC_PER_MSEC, 10 * USEC_PER_MSEC, true,
2810 + qdma, REG_TRTCM_CFG_PARAM(addr));
2831 2811 }
2832 2812
2833 2813 static int airoha_qdma_set_trtcm_config(struct airoha_qdma *qdma, int channel,
modified drivers/net/ethernet/airoha/airoha_eth.h
@@ -171,8 +171,6 @@ enum trtcm_param {
171 171 #define TRTCM_TOKEN_RATE_MASK GENMASK(23, 6)
172 172 #define TRTCM_TOKEN_RATE_FRACTION_MASK GENMASK(5, 0)
173 173
174 - #define TRTCM_CONFIG_RETRY_MAX 2
175 -
176 174 enum airoha_dma_map_type {
177 175 AIROHA_DMA_UNMAPPED,
178 176 AIROHA_DMA_MAP_SINGLE,
modified drivers/net/ethernet/allwinner/sun4i-emac.c
@@ -300,7 +300,7 @@ static int emac_dma_inblk_32bit(struct emac_board_info *db,
300 300 if (!req) {
301 301 dev_err(db->dev, "alloc emac dma req error.\n");
302 302 ret = -ENOMEM;
303 - goto prepare_err;
303 + goto alloc_req_err;
304 304 }
305 305
306 306 desc->callback_param = req;
@@ -319,6 +319,9 @@ static int emac_dma_inblk_32bit(struct emac_board_info *db,
319 319 submit_err:
320 320 emac_free_dma_req(req);
321 321
322 + alloc_req_err:
323 + dmaengine_desc_free(desc);
324 +
322 325 prepare_err:
323 326 dma_unmap_single(db->dev, rxbuf, count, DMA_FROM_DEVICE);
324 327 return ret;
modified drivers/net/ethernet/broadcom/bnxt/bnxt.c
@@ -486,7 +486,7 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
486 486 struct netdev_queue *txq;
487 487 int i;
488 488 dma_addr_t mapping;
489 - unsigned int length;
489 + unsigned int length, pad = 0;
490 490 u32 len, free_size, vlan_tag_flags, cfa_action, flags;
491 491 struct bnxt_ptp_cfg *ptp = bp->ptp_cfg;
492 492 struct pci_dev *pdev = bp->pdev;
@@ -536,16 +536,6 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
536 536 return rc < 0 ? NETDEV_TX_BUSY : NETDEV_TX_OK;
537 537 }
538 538
539 - /* Pad after the SW USO branch: bnxt_sw_udp_gso_xmit() would
540 - * otherwise account the padding as UDP payload.
541 - * Must be done before skb_shinfo(skb)->nr_frags is sampled,
542 - * because skb_put_padto() might linearize the skb.
543 - */
544 - if (skb_put_padto(skb, BNXT_MIN_PKT_SIZE)) {
545 - /* SKB already freed. */
546 - goto tx_kick_pending;
547 - }
548 -
549 539 free_size = bnxt_tx_avail(bp, txr);
550 540 if (unlikely(free_size < skb_shinfo(skb)->nr_frags + 2)) {
551 541 /* We must have raced with NAPI cleanup */
@@ -682,6 +672,14 @@ static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev)
682 672 }
683 673
684 674 normal_tx:
675 + if (length < BNXT_MIN_PKT_SIZE) {
676 + pad = BNXT_MIN_PKT_SIZE - length;
677 + if (skb_pad(skb, pad))
678 + /* SKB already freed. */
679 + goto tx_kick_pending;
680 + length = BNXT_MIN_PKT_SIZE;
681 + }
682 +
685 683 mapping = dma_map_single(&pdev->dev, skb->data, len, DMA_TO_DEVICE);
686 684
687 685 if (unlikely(dma_mapping_error(&pdev->dev, mapping)))
@@ -761,7 +759,10 @@ normal_tx:
761 759 txbd->tx_bd_len_flags_type = cpu_to_le32(flags);
762 760 }
763 761
764 - txbd->tx_bd_len_flags_type |= cpu_to_le32(TX_BD_FLAGS_PACKET_END);
762 + flags &= ~TX_BD_LEN;
763 + txbd->tx_bd_len_flags_type =
764 + cpu_to_le32(((len + pad) << TX_BD_LEN_SHIFT) | flags |
765 + TX_BD_FLAGS_PACKET_END);
765 766
766 767 netdev_tx_sent_queue(txq, skb->len);
767 768
@@ -15546,7 +15547,7 @@ static void bnxt_fw_reset_task(struct work_struct *work)
15546 15547 if (test_and_clear_bit(BNXT_STATE_FW_ACTIVATE_RESET, &bp->state) &&
15547 15548 !test_bit(BNXT_STATE_FW_ACTIVATE, &bp->state))
15548 15549 bnxt_dl_remote_reload(bp);
15549 - if (!pci_is_enabled(bp->pdev) && pci_enable_device(bp->pdev)) {
15550 + if (pci_enable_device(bp->pdev)) {
15550 15551 netdev_err(bp->dev, "Cannot re-enable PCI device\n");
15551 15552 rc = -ENODEV;
15552 15553 goto fw_reset_abort;
@@ -17110,51 +17111,6 @@ void bnxt_print_device_info(struct bnxt *bp)
17110 17111 pcie_print_link_status(bp->pdev);
17111 17112 }
17112 17113
17113 - static void bnxt_clear_bars(struct pci_dev *pdev)
17114 - {
17115 - int off;
17116 -
17117 - for (off = PCI_BASE_ADDRESS_0; off <= PCI_BASE_ADDRESS_5; off += 4)
17118 - pci_write_config_dword(pdev, off, 0);
17119 - }
17120 -
17121 - /* Clear any pending DMA transactions from crash kernel while loading driver in
17122 - * capture kernel.
17123 - */
17124 - static int bnxt_kdump_reset(struct pci_dev *pdev)
17125 - {
17126 - int rc, i;
17127 - u16 cmd;
17128 -
17129 - pci_read_config_word(pdev, PCI_COMMAND, &cmd);
17130 - cmd &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
17131 - pci_write_config_word(pdev, PCI_COMMAND, cmd);
17132 -
17133 - if (pci_save_state(pdev))
17134 - dev_warn(&pdev->dev, "Failed to save PCI state, PCI restore may be incomplete\n");
17135 -
17136 - rc = pcie_flr(pdev);
17137 - if (rc)
17138 - dev_warn(&pdev->dev, "pcie_flr() failed (rc: %d), trying to continue\n",
17139 - rc);
17140 -
17141 - /* In case device is not returning CRS, wait 5 seconds longer */
17142 - for (i = 0; i < 50; i++) {
17143 - pci_read_config_word(pdev, PCI_COMMAND, &cmd);
17144 - if (!PCI_POSSIBLE_ERROR(cmd))
17145 - break;
17146 - msleep(100);
17147 - }
17148 - if (PCI_POSSIBLE_ERROR(cmd)) {
17149 - dev_err(&pdev->dev, "PCI config space inaccessible after FLR, aborting\n");
17150 - return -ENODEV;
17151 - }
17152 -
17153 - bnxt_clear_bars(pdev);
17154 - pci_restore_state(pdev);
17155 - return 0;
17156 - }
17157 -
17158 17114 static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
17159 17115 {
17160 17116 struct bnxt_hw_resc *hw_resc;
@@ -17170,10 +17126,12 @@ static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
17170 17126 return -ENODEV;
17171 17127 }
17172 17128
17129 + /* Clear any pending DMA transactions from crash kernel
17130 + * while loading driver in capture kernel.
17131 + */
17173 17132 if (is_kdump_kernel()) {
17174 - rc = bnxt_kdump_reset(pdev);
17175 - if (rc)
17176 - return rc;
17133 + pci_clear_master(pdev);
17134 + pcie_flr(pdev);
17177 17135 }
17178 17136
17179 17137 max_irqs = bnxt_get_max_irq(pdev);
@@ -17607,8 +17565,10 @@ static pci_ers_result_t bnxt_io_error_detected(struct pci_dev *pdev,
17607 17565 * so we disable bus master to prevent any potential bad DMAs before
17608 17566 * freeing kernel memory.
17609 17567 */
17610 - if (state == pci_channel_io_frozen)
17568 + if (state == pci_channel_io_frozen) {
17569 + set_bit(BNXT_STATE_PCI_CHANNEL_IO_FROZEN, &bp->state);
17611 17570 bnxt_fw_fatal_close(bp);
17571 + }
17612 17572
17613 17573 if (netif_running(netdev))
17614 17574 __bnxt_close_nic(bp, true, true);
@@ -17638,80 +17598,69 @@ static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev)
17638 17598 struct bnxt *bp = netdev_priv(netdev);
17639 17599 int retry = 0;
17640 17600 int err = 0;
17641 - u16 cmd;
17601 + int off;
17642 17602
17643 17603 netdev_info(bp->dev, "PCI Slot Reset\n");
17644 17604
17645 - /* After a PCIe hot reset, the chip should return CRS when the
17646 - * vendor ID config register is read until it is ready. On all
17647 - * chips, this is not happening reliably so add a 5-second delay
17648 - * as a workaround.
17649 - */
17650 - msleep(5000);
17605 + if (test_bit(BNXT_STATE_PCI_CHANNEL_IO_FROZEN, &bp->state)) {
17606 + /* After DPC, the chip should return CRS when the vendor ID
17607 + * config register is read until it is ready. On all chips,
17608 + * this is not happening reliably so add a 5-second delay as a
17609 + * workaround.
17610 + */
17611 + msleep(5000);
17612 + }
17651 17613
17652 17614 netdev_lock(netdev);
17653 17615
17654 - pci_read_config_word(pdev, PCI_COMMAND, &cmd);
17655 - if (PCI_POSSIBLE_ERROR(cmd)) {
17616 + if (pci_enable_device(pdev)) {
17656 17617 dev_err(&pdev->dev,
17657 - "PCI config space inaccessible after reset\n");
17658 - goto reset_exit;
17659 - }
17618 + "Cannot re-enable PCI device after reset.\n");
17619 + } else {
17620 + pci_set_master(pdev);
17621 + /* Upon fatal error, our device internal logic that latches to
17622 + * BAR value is getting reset and will restore only upon
17623 + * rewriting the BARs.
17624 + *
17625 + * As pci_restore_state() does not re-write the BARs if the
17626 + * value is same as saved value earlier, driver needs to
17627 + * write the BARs to 0 to force restore, in case of fatal error.
17628 + */
17629 + if (test_and_clear_bit(BNXT_STATE_PCI_CHANNEL_IO_FROZEN,
17630 + &bp->state)) {
17631 + for (off = PCI_BASE_ADDRESS_0;
17632 + off <= PCI_BASE_ADDRESS_5; off += 4)
17633 + pci_write_config_dword(bp->pdev, off, 0);
17634 + }
17635 + pci_restore_state(pdev);
17660 17636
17661 - /* Upon PCIe error, our device internal logic that latches to
17662 - * BAR value is getting reset and will restore only upon
17663 - * rewriting the BARs.
17664 - *
17665 - * As pci_restore_state() does not re-write the BARs if the
17666 - * value is same as saved value earlier, driver needs to
17667 - * write the BARs to 0 to force restore.
17668 - */
17669 - pci_clear_master(pdev);
17670 - pci_read_config_word(pdev, PCI_COMMAND, &cmd);
17671 - cmd &= ~PCI_COMMAND_MEMORY;
17672 - pci_write_config_word(pdev, PCI_COMMAND, cmd);
17637 + bnxt_inv_fw_health_reg(bp);
17638 + bnxt_try_map_fw_health_reg(bp);
17673 17639
17674 - bnxt_clear_bars(pdev);
17675 - pci_restore_state(pdev);
17640 + /* In some PCIe AER scenarios, firmware may take up to
17641 + * 10 seconds to become ready in the worst case.
17642 + */
17643 + do {
17644 + err = bnxt_try_recover_fw(bp);
17645 + if (!err)
17646 + break;
17647 + retry++;
17648 + } while (retry < BNXT_FW_SLOT_RESET_RETRY);
17676 17649
17677 - if (!pci_is_enabled(pdev) && pci_enable_device(pdev)) {
17678 - dev_err(&pdev->dev,
17679 - "Cannot re-enable PCI device after reset.\n");
17680 - pci_read_config_word(pdev, PCI_COMMAND, &cmd);
17681 - if (!PCI_POSSIBLE_ERROR(cmd)) {
17682 - cmd &= ~(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY);
17683 - pci_write_config_word(pdev, PCI_COMMAND, cmd);
17650 + if (err) {
17651 + dev_err(&pdev->dev, "Firmware not ready\n");
17652 + goto reset_exit;
17684 17653 }
17685 - goto reset_exit;
17686 - }
17687 - pci_set_master(pdev);
17688 17654
17689 - bnxt_inv_fw_health_reg(bp);
17690 - bnxt_try_map_fw_health_reg(bp);
17691 -
17692 - /* In some PCIe AER scenarios, firmware may take up to
17693 - * 10 seconds to become ready in the worst case.
17694 - */
17695 - do {
17696 - err = bnxt_try_recover_fw(bp);
17655 + err = bnxt_hwrm_func_reset(bp);
17697 17656 if (!err)
17698 - break;
17699 - retry++;
17700 - } while (retry < BNXT_FW_SLOT_RESET_RETRY);
17657 + result = PCI_ERS_RESULT_RECOVERED;
17701 17658
17702 - if (err) {
17703 - dev_err(&pdev->dev, "Firmware not ready\n");
17704 - goto reset_exit;
17659 + /* IRQ will be initialized later in bnxt_io_resume */
17660 + bnxt_ulp_irq_stop(bp);
17661 + bnxt_clear_int_mode(bp);
17705 17662 }
17706 17663
17707 - err = bnxt_hwrm_func_reset(bp);
17708 - if (!err)
17709 - result = PCI_ERS_RESULT_RECOVERED;
17710 -
17711 - /* IRQ will be initialized later in bnxt_io_resume */
17712 - bnxt_ulp_irq_stop(bp);
17713 - bnxt_clear_int_mode(bp);
17714 -
17715 17664 reset_exit:
17716 17665 clear_bit(BNXT_STATE_IN_FW_RESET, &bp->state);
17717 17666 bnxt_clear_reservations(bp, true);
modified drivers/net/ethernet/broadcom/bnxt/bnxt.h
@@ -2468,6 +2468,7 @@ struct bnxt {
2468 2468 #define BNXT_STATE_ABORT_ERR 5
2469 2469 #define BNXT_STATE_FW_FATAL_COND 6
2470 2470 #define BNXT_STATE_DRV_REGISTERED 7
2471 + #define BNXT_STATE_PCI_CHANNEL_IO_FROZEN 8
2471 2472 #define BNXT_STATE_NAPI_DISABLED 9
2472 2473 #define BNXT_STATE_FW_ACTIVATE 11
2473 2474 #define BNXT_STATE_RECOVER 12
modified drivers/net/ethernet/broadcom/genet/bcmgenet_wol.c
@@ -253,17 +253,6 @@ int bcmgenet_wol_power_up_cfg(struct bcmgenet_priv *priv,
253 253 reg = bcmgenet_umac_readl(priv, UMAC_CMD);
254 254 reg &= ~CMD_CRC_FWD;
255 255 bcmgenet_umac_writel(priv, reg, UMAC_CMD);
256 -
257 - /*
258 - * Mirror wol_power_down_cfg(). If only UMAC_RX
259 - * is enabled, then we must place the UMAC back
260 - * into SW_RESET.
261 - */
262 - reg = bcmgenet_umac_readl(priv, UMAC_CMD);
263 - if ((reg & CMD_RX_EN) && !(reg & CMD_TX_EN)) {
264 - reg |= CMD_SW_RESET;
265 - bcmgenet_umac_writel(priv, reg, UMAC_CMD);
266 - }
267 256 spin_unlock_bh(&priv->reg_lock);
268 257
269 258 /* Resume link status tracking */
modified drivers/net/ethernet/cadence/macb_main.c
@@ -2421,40 +2421,34 @@ static inline int macb_clear_csum(struct sk_buff *skb)
2421 2421 return 0;
2422 2422 }
2423 2423
2424 - static bool macb_needs_sw_fcs(struct sk_buff *skb, struct net_device *netdev)
2425 - {
2426 - return netdev->features & NETIF_F_HW_CSUM &&
2427 - skb->ip_summed != CHECKSUM_PARTIAL &&
2428 - !skb_shinfo(skb)->gso_size && !ptp_one_step_sync(skb);
2429 - }
2430 -
2431 2424 /* Returns a negative errno, or the FCS bytes appended (0 or ETH_FCS_LEN). */
2432 - static int macb_pad_and_fcs(struct sk_buff **skb, bool add_fcs)
2425 + static int macb_pad_and_fcs(struct sk_buff **skb, struct net_device *netdev)
2433 2426 {
2434 2427 bool cloned = skb_cloned(*skb) || skb_header_cloned(*skb) ||
2435 2428 skb_is_nonlinear(*skb);
2436 2429 int padlen = ETH_ZLEN - (*skb)->len;
2437 2430 int tailroom = skb_tailroom(*skb);
2438 - bool shared = skb_shared(*skb);
2439 2431 struct sk_buff *nskb;
2440 2432 u32 fcs;
2441 2433
2442 - if (!add_fcs)
2434 + if (!(netdev->features & NETIF_F_HW_CSUM) ||
2435 + !((*skb)->ip_summed != CHECKSUM_PARTIAL) ||
2436 + skb_shinfo(*skb)->gso_size || ptp_one_step_sync(*skb))
2443 2437 return 0;
2444 2438
2445 2439 if (padlen <= 0) {
2446 - /* FCS could be appended to tailroom. */
2447 - if (!shared && !skb_is_nonlinear(*skb) &&
2448 - tailroom >= ETH_FCS_LEN)
2440 + /* FCS could be appeded to tailroom. */
2441 + if (tailroom >= ETH_FCS_LEN)
2449 2442 goto add_fcs;
2450 - /* Reallocate with room for the FCS. */
2451 - padlen = ETH_FCS_LEN;
2443 + /* No room for FCS, need to reallocate skb. */
2444 + else
2445 + padlen = ETH_FCS_LEN;
2452 2446 } else {
2453 2447 /* Add room for FCS. */
2454 2448 padlen += ETH_FCS_LEN;
2455 2449 }
2456 2450
2457 - if (shared || cloned || tailroom < padlen) {
2451 + if (cloned || tailroom < padlen) {
2458 2452 nskb = skb_copy_expand(*skb, 0, padlen, GFP_ATOMIC);
2459 2453 if (!nskb)
2460 2454 return -ENOMEM;
@@ -2487,15 +2481,27 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb,
2487 2481 unsigned int desc_cnt, nr_frags, frag_size, f;
2488 2482 struct macb_queue *queue = &bp->queues[q];
2489 2483 netdev_tx_t ret = NETDEV_TX_OK;
2490 - unsigned int hdrlen, tx_len;
2491 - bool add_fcs, is_lso;
2484 + unsigned int hdrlen;
2492 2485 unsigned long flags;
2493 2486 int fcs_len;
2487 + bool is_lso;
2488 +
2489 + if (macb_clear_csum(skb)) {
2490 + dev_kfree_skb_any(skb);
2491 + return ret;
2492 + }
2493 +
2494 + fcs_len = macb_pad_and_fcs(&skb, netdev);
2495 + if (fcs_len < 0) {
2496 + dev_kfree_skb_any(skb);
2497 + return ret;
2498 + }
2499 +
2500 + if (macb_dma_ptp(bp) &&
2501 + (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))
2502 + skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
2494 2503
2495 - add_fcs = macb_needs_sw_fcs(skb, netdev);
2496 2504 is_lso = (skb_shinfo(skb)->gso_size != 0);
2497 - tx_len = add_fcs ? max_t(unsigned int, skb->len, ETH_ZLEN) +
2498 - ETH_FCS_LEN : skb->len;
2499 2505
2500 2506 if (is_lso) {
2501 2507 /* length of headers */
@@ -2509,11 +2515,8 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb,
2509 2515 /* if this is required, would need to copy to single buffer */
2510 2516 return NETDEV_TX_BUSY;
2511 2517 }
2512 - } else if (add_fcs) {
2513 - hdrlen = umin(tx_len, bp->max_tx_length);
2514 - } else {
2518 + } else
2515 2519 hdrlen = umin(skb_headlen(skb), bp->max_tx_length);
2516 - }
2517 2520
2518 2521 #if defined(DEBUG) && defined(VERBOSE_DEBUG)
2519 2522 netdev_vdbg(bp->netdev,
@@ -2528,18 +2531,12 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb,
2528 2531 * socket buffer: skb fragments of jumbo frames may need to be
2529 2532 * split into many buffer descriptors.
2530 2533 */
2531 - if (add_fcs) {
2532 - /* macb_pad_and_fcs() linearizes the skb before adding the FCS. */
2533 - desc_cnt = DIV_ROUND_UP(tx_len, bp->max_tx_length);
2534 - nr_frags = 0;
2535 - } else if (is_lso && (skb_headlen(skb) > hdrlen)) {
2534 + if (is_lso && (skb_headlen(skb) > hdrlen))
2536 2535 /* extra header descriptor if also payload in first buffer */
2537 2536 desc_cnt = DIV_ROUND_UP((skb_headlen(skb) - hdrlen), bp->max_tx_length) + 1;
2538 - nr_frags = skb_shinfo(skb)->nr_frags;
2539 - } else {
2537 + else
2540 2538 desc_cnt = DIV_ROUND_UP(skb_headlen(skb), bp->max_tx_length);
2541 - nr_frags = skb_shinfo(skb)->nr_frags;
2542 - }
2539 + nr_frags = skb_shinfo(skb)->nr_frags;
2543 2540 for (f = 0; f < nr_frags; f++) {
2544 2541 frag_size = skb_frag_size(&skb_shinfo(skb)->frags[f]);
2545 2542 desc_cnt += DIV_ROUND_UP(frag_size, bp->max_tx_length);
@@ -2557,21 +2554,6 @@ static netdev_tx_t macb_start_xmit(struct sk_buff *skb,
2557 2554 goto unlock;
2558 2555 }
2559 2556
2560 - if (macb_clear_csum(skb)) {
2561 - dev_kfree_skb_any(skb);
2562 - goto unlock;
2563 - }
2564 -
2565 - fcs_len = macb_pad_and_fcs(&skb, add_fcs);
2566 - if (fcs_len < 0) {
2567 - dev_kfree_skb_any(skb);
2568 - goto unlock;
2569 - }
2570 -
2571 - if (macb_dma_ptp(bp) &&
2572 - (skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP))
2573 - skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
2574 -
2575 2557 /* Map socket buffer for DMA transfer */
2576 2558 if (macb_tx_map(bp, queue, skb, hdrlen, fcs_len)) {
2577 2559 dev_kfree_skb_any(skb);
modified drivers/net/ethernet/chelsio/inline_crypto/ch_ktls/chcr_ktls.c
@@ -389,7 +389,7 @@ static void chcr_ktls_dev_del(struct net_device *netdev,
389 389 cxgb4_remove_tid(&tx_info->adap->tids, tx_info->tx_chan,
390 390 tx_info->tid, tx_info->ip_family);
391 391
392 - xa_erase_bh(&u_ctx->tid_list, tx_info->tid);
392 + xa_erase(&u_ctx->tid_list, tx_info->tid);
393 393 }
394 394
395 395 port_stats = &tx_info->adap->ch_ktls_stats.ktls_port[tx_info->port_id];
@@ -577,7 +577,7 @@ free_tid:
577 577 cxgb4_remove_tid(&tx_info->adap->tids, tx_info->tx_chan,
578 578 tx_info->tid, tx_info->ip_family);
579 579
580 - xa_erase_bh(&u_ctx->tid_list, tx_info->tid);
580 + xa_erase(&u_ctx->tid_list, tx_info->tid);
581 581
582 582 put_module:
583 583 /* release module refcount */
modified drivers/net/ethernet/google/gve/gve_main.c
@@ -1708,17 +1708,17 @@ static int gve_xsk_pool_disable(struct net_device *dev,
1708 1708 }
1709 1709
1710 1710 napi_rx = &priv->ntfy_blocks[priv->rx[qid].ntfy_id].napi;
1711 - napi_disable_locked(napi_rx); /* make sure current rx poll is done */
1711 + napi_disable(napi_rx); /* make sure current rx poll is done */
1712 1712
1713 1713 tx_qid = gve_xdp_tx_queue_id(priv, qid);
1714 1714 napi_tx = &priv->ntfy_blocks[priv->tx[tx_qid].ntfy_id].napi;
1715 - napi_disable_locked(napi_tx); /* make sure current tx poll is done */
1715 + napi_disable(napi_tx); /* make sure current tx poll is done */
1716 1716
1717 1717 gve_unreg_xsk_pool(priv, qid);
1718 1718 smp_mb(); /* Make sure it is visible to the workers on datapath */
1719 1719
1720 - napi_enable_locked(napi_rx);
1721 - napi_enable_locked(napi_tx);
1720 + napi_enable(napi_rx);
1721 + napi_enable(napi_tx);
1722 1722 if (gve_is_gqi(priv)) {
1723 1723 if (gve_rx_work_pending(&priv->rx[qid]))
1724 1724 napi_schedule(napi_rx);
modified drivers/net/ethernet/google/gve/gve_rx_dqo.c
@@ -113,12 +113,6 @@ static void gve_rx_reset_ring_dqo(struct gve_priv *priv, int idx)
113 113 gve_free_to_page_pool(rx, bs, false);
114 114 else
115 115 gve_free_qpl_page_dqo(bs);
116 -
117 - if (gve_buf_state_is_allocated(rx, bs) &&
118 - bs->xsk_buff) {
119 - xsk_buff_free(bs->xsk_buff);
120 - bs->xsk_buff = NULL;
121 - }
122 116 }
123 117 }
124 118
@@ -842,12 +836,7 @@ static int gve_rx_dqo(struct napi_struct *napi, struct gve_rx_ring *rx,
842 836 }
843 837
844 838 if (unlikely(compl_desc->rx_error)) {
845 - if (buf_state->xsk_buff) {
846 - xsk_buff_free(buf_state->xsk_buff);
847 - gve_free_buf_state(rx, buf_state);
848 - } else {
849 - gve_free_buffer(rx, buf_state);
850 - }
839 + gve_free_buffer(rx, buf_state);
851 840 return -EINVAL;
852 841 }
853 842
modified drivers/net/ethernet/ibm/ibmveth.c
@@ -553,15 +553,10 @@ static int ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter,
553 553
554 554 static void ibmveth_free_tx_ltb(struct ibmveth_adapter *adapter, int idx)
555 555 {
556 - void *ptr = adapter->tx_ltb_ptr[idx];
557 -
558 - if (!ptr)
559 - return;
560 -
561 - adapter->tx_ltb_ptr[idx] = NULL;
562 556 dma_unmap_single(&adapter->vdev->dev, adapter->tx_ltb_dma[idx],
563 557 adapter->tx_ltb_size, DMA_TO_DEVICE);
564 - kfree(ptr);
558 + kfree(adapter->tx_ltb_ptr[idx]);
559 + adapter->tx_ltb_ptr[idx] = NULL;
565 560 }
566 561
567 562 static int ibmveth_allocate_tx_ltb(struct ibmveth_adapter *adapter, int idx)
@@ -672,7 +667,7 @@ static int ibmveth_open(struct net_device *netdev)
672 667
673 668 for (i = 0; i < netdev->real_num_tx_queues; i++) {
674 669 if (ibmveth_allocate_tx_ltb(adapter, i))
675 - goto out_unmap_filter_list;
670 + goto out_free_tx_ltb;
676 671 }
677 672
678 673 adapter->rx_queue.index = 0;
@@ -723,6 +718,10 @@ static int ibmveth_open(struct net_device *netdev)
723 718 if (rc != 0) {
724 719 netdev_err(netdev, "unable to request irq 0x%x, rc %d\n",
725 720 netdev->irq, rc);
721 + do {
722 + lpar_rc = h_free_logical_lan(adapter->vdev->unit_address);
723 + } while (H_IS_LONG_BUSY(lpar_rc) || (lpar_rc == H_BUSY));
724 +
726 725 goto out_free_buffer_pools;
727 726 }
728 727
@@ -738,9 +737,6 @@ static int ibmveth_open(struct net_device *netdev)
738 737 return 0;
739 738
740 739 out_free_buffer_pools:
741 - do {
742 - lpar_rc = h_free_logical_lan(adapter->vdev->unit_address);
743 - } while (H_IS_LONG_BUSY(lpar_rc) || (lpar_rc == H_BUSY));
744 740 while (--i >= 0) {
745 741 if (adapter->rx_buff_pool[i].active)
746 742 ibmveth_free_buffer_pool(adapter,
@@ -750,8 +746,10 @@ out_unmap_filter_list:
750 746 dma_unmap_single(dev, adapter->filter_list_dma, 4096,
751 747 DMA_BIDIRECTIONAL);
752 748
753 - for (i = netdev->real_num_tx_queues - 1; i >= 0; i--)
749 + out_free_tx_ltb:
750 + while (--i >= 0) {
754 751 ibmveth_free_tx_ltb(adapter, i);
752 + }
755 753
756 754 out_unmap_buffer_list:
757 755 dma_unmap_single(dev, adapter->buffer_list_dma, 4096,
modified drivers/net/ethernet/intel/e1000e/netdev.c
@@ -67,13 +67,6 @@ static const struct dmi_system_id disable_k1_list[] = {
67 67 DMI_MATCH(DMI_PRODUCT_NAME, "Dell Pro 16 Plus PB16250"),
68 68 },
69 69 },
70 - {
71 - .ident = "Lenovo ThinkPad P14s Gen 5",
72 - .matches = {
73 - DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
74 - DMI_MATCH(DMI_PRODUCT_VERSION, "ThinkPad P14s Gen 5"),
75 - },
76 - },
77 70 {}
78 71 };
79 72
modified drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
@@ -4943,20 +4943,6 @@ out:
4943 4943 return ret;
4944 4944 }
4945 4945
4946 - /**
4947 - * i40e_setup_vf_trust - Enable/disable VF trust mode without reset
4948 - * @vf: VF to configure
4949 - * @setting: trust setting
4950 - *
4951 - * Update VF flags when changing trust without performing a VF reset.
4952 - * This is only called when it's safe to skip the reset (VF has no advanced
4953 - * features configured that need cleanup).
4954 - */
4955 - static void i40e_setup_vf_trust(struct i40e_vf *vf, bool setting)
4956 - {
4957 - assign_bit(I40E_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps, setting);
4958 - }
4959 -
4960 4946 /**
4961 4947 * i40e_ndo_set_vf_trust
4962 4948 * @netdev: network interface device structure of the pf
@@ -5001,20 +4987,19 @@ int i40e_ndo_set_vf_trust(struct net_device *netdev, int vf_id, bool setting)
5001 4987 set_bit(__I40E_MACVLAN_SYNC_PENDING, pf->state);
5002 4988 pf->vsi[vf->lan_vsi_idx]->flags |= I40E_VSI_FLAG_FILTER_CHANGED;
5003 4989
5004 - /* Reset only if revoking trust and VF has advanced features configured */
5005 - if (!setting &&
5006 - (vf->adq_enabled || vf->num_cloud_filters > 0 ||
5007 - test_bit(I40E_VF_STATE_UC_PROMISC, &vf->vf_states) ||
5008 - test_bit(I40E_VF_STATE_MC_PROMISC, &vf->vf_states))) {
5009 - i40e_vc_reset_vf(vf, true);
5010 - i40e_del_all_cloud_filters(vf);
5011 - } else {
5012 - i40e_setup_vf_trust(vf, setting);
5013 - }
5014 -
4990 + i40e_vc_reset_vf(vf, true);
5015 4991 dev_info(&pf->pdev->dev, "VF %u is now %strusted\n",
5016 4992 vf_id, setting ? "" : "un");
5017 4993
4994 + if (vf->adq_enabled) {
4995 + if (!vf->trusted) {
4996 + dev_info(&pf->pdev->dev,
4997 + "VF %u no longer Trusted, deleting all cloud filters\n",
4998 + vf_id);
4999 + i40e_del_all_cloud_filters(vf);
5000 + }
5001 + }
5002 +
5018 5003 out:
5019 5004 clear_bit(__I40E_VIRTCHNL_OP_PENDING, pf->state);
5020 5005 return ret;
modified drivers/net/ethernet/intel/iavf/iavf.h
@@ -259,6 +259,7 @@ struct iavf_adapter {
259 259 struct work_struct adminq_task;
260 260 struct work_struct finish_config;
261 261 wait_queue_head_t down_waitqueue;
262 + wait_queue_head_t vc_waitqueue;
262 263 struct iavf_q_vector *q_vectors;
263 264 struct list_head vlan_filter_list;
264 265 int num_vlan_filters;
@@ -587,9 +588,8 @@ void iavf_configure_queues(struct iavf_adapter *adapter);
587 588 void iavf_enable_queues(struct iavf_adapter *adapter);
588 589 void iavf_disable_queues(struct iavf_adapter *adapter);
589 590 void iavf_map_queues(struct iavf_adapter *adapter);
590 - int iavf_add_ether_addrs(struct iavf_adapter *adapter);
591 + void iavf_add_ether_addrs(struct iavf_adapter *adapter);
591 592 void iavf_del_ether_addrs(struct iavf_adapter *adapter);
592 - void iavf_mac_add_reject(struct iavf_adapter *adapter);
593 593 void iavf_add_vlans(struct iavf_adapter *adapter);
594 594 void iavf_del_vlans(struct iavf_adapter *adapter);
595 595 void iavf_set_promiscuous(struct iavf_adapter *adapter);
@@ -606,13 +606,6 @@ void iavf_disable_vlan_stripping(struct iavf_adapter *adapter);
606 606 void iavf_virtchnl_completion(struct iavf_adapter *adapter,
607 607 enum virtchnl_ops v_opcode,
608 608 enum iavf_status v_retval, u8 *msg, u16 msglen);
609 - int iavf_poll_virtchnl_response(struct iavf_adapter *adapter,
610 - struct iavf_arq_event_info *event,
611 - bool (*condition)(struct iavf_adapter *adapter,
612 - const void *data,
613 - enum virtchnl_ops v_op),
614 - const void *cond_data,
615 - unsigned int timeout_ms);
616 609 int iavf_config_rss(struct iavf_adapter *adapter);
617 610 void iavf_cfg_queues_bw(struct iavf_adapter *adapter);
618 611 void iavf_cfg_queues_quanta_size(struct iavf_adapter *adapter);
modified drivers/net/ethernet/intel/iavf/iavf_main.c
@@ -1029,60 +1029,6 @@ static bool iavf_is_mac_set_handled(struct net_device *netdev,
1029 1029 return ret;
1030 1030 }
1031 1031
1032 - /**
1033 - * iavf_mac_change_done - Check if MAC change completed
1034 - * @adapter: board private structure
1035 - * @data: MAC address being checked (as const void *)
1036 - * @v_op: virtchnl opcode from processed message
1037 - *
1038 - * Callback for iavf_poll_virtchnl_response() to check if MAC change completed.
1039 - *
1040 - * Return: true if MAC change completed, false otherwise
1041 - */
1042 - static bool iavf_mac_change_done(struct iavf_adapter *adapter,
1043 - const void *data, enum virtchnl_ops v_op)
1044 - {
1045 - const u8 *addr = data;
1046 -
1047 - return iavf_is_mac_set_handled(adapter->netdev, addr);
1048 - }
1049 -
1050 - /**
1051 - * iavf_set_mac_sync - Synchronously change MAC address
1052 - * @adapter: board private structure
1053 - * @addr: MAC address to set
1054 - *
1055 - * Send MAC change request to PF and poll admin queue for response.
1056 - * Caller must hold netdev_lock. This can sleep for up to 2.5 seconds.
1057 - * Event buffer is allocated before sending to avoid state mismatch if
1058 - * allocation fails after message is sent to PF.
1059 - *
1060 - * Return: 0 on success, negative on failure
1061 - */
1062 - static int iavf_set_mac_sync(struct iavf_adapter *adapter, const u8 *addr)
1063 - {
1064 - struct iavf_arq_event_info event;
1065 - int ret;
1066 -
1067 - netdev_assert_locked(adapter->netdev);
1068 -
1069 - event.buf_len = IAVF_MAX_AQ_BUF_SIZE;
1070 - event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
1071 - if (!event.msg_buf)
1072 - return -ENOMEM;
1073 -
1074 - ret = iavf_add_ether_addrs(adapter);
1075 - if (ret)
1076 - goto out;
1077 -
1078 - ret = iavf_poll_virtchnl_response(adapter, &event,
1079 - iavf_mac_change_done, addr, 2500);
1080 -
1081 - out:
1082 - kfree(event.msg_buf);
1083 - return ret;
1084 - }
1085 -
1086 1032 /**
1087 1033 * iavf_set_mac - NDO callback to set port MAC address
1088 1034 * @netdev: network interface device structure
@@ -1100,23 +1046,25 @@ static int iavf_set_mac(struct net_device *netdev, void *p)
1100 1046 return -EADDRNOTAVAIL;
1101 1047
1102 1048 ret = iavf_replace_primary_mac(adapter, addr->sa_data);
1049 +
1103 1050 if (ret)
1104 1051 return ret;
1105 1052
1106 - ret = iavf_set_mac_sync(adapter, addr->sa_data);
1107 - if (ret) {
1108 - /* Rollback only if send failed (message never reached PF).
1109 - * Don't rollback on timeout (-EAGAIN) because the message was
1110 - * sent and PF will eventually respond. When the response arrives,
1111 - * iavf_virtchnl_completion() will handle rollback (on PF error)
1112 - * or acceptance (on PF success) automatically.
1113 - */
1114 - if (ret != -EAGAIN) {
1115 - iavf_mac_add_reject(adapter);
1116 - ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
1117 - }
1053 + ret = wait_event_interruptible_timeout(adapter->vc_waitqueue,
1054 + iavf_is_mac_set_handled(netdev, addr->sa_data),
1055 + msecs_to_jiffies(2500));
1056 +
1057 + /* If ret < 0 then it means wait was interrupted.
1058 + * If ret == 0 then it means we got a timeout.
1059 + * else it means we got response for set MAC from PF,
1060 + * check if netdev MAC was updated to requested MAC,
1061 + * if yes then set MAC succeeded otherwise it failed return -EACCES
1062 + */
1063 + if (ret < 0)
1118 1064 return ret;
1119 - }
1065 +
1066 + if (!ret)
1067 + return -EAGAIN;
1120 1068
1121 1069 if (!ether_addr_equal(netdev->dev_addr, addr->sa_data))
1122 1070 return -EACCES;
@@ -5446,6 +5394,9 @@ static int iavf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
5446 5394 /* Setup the wait queue for indicating transition to down status */
5447 5395 init_waitqueue_head(&adapter->down_waitqueue);
5448 5396
5397 + /* Setup the wait queue for indicating virtchannel events */
5398 + init_waitqueue_head(&adapter->vc_waitqueue);
5399 +
5449 5400 INIT_LIST_HEAD(&adapter->ptp.aq_cmds);
5450 5401 init_waitqueue_head(&adapter->ptp.phc_time_waitqueue);
5451 5402 mutex_init(&adapter->ptp.aq_cmd_lock);
modified drivers/net/ethernet/intel/iavf/iavf_virtchnl.c
@@ -2,7 +2,6 @@
2 2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
3 3
4 4 #include <linux/net/intel/libie/rx.h>
5 - #include <net/netdev_lock.h>
6 5
7 6 #include "iavf.h"
8 7 #include "iavf_ptp.h"
@@ -556,23 +555,20 @@ iavf_set_mac_addr_type(struct virtchnl_ether_addr *virtchnl_ether_addr,
556 555 * @adapter: adapter structure
557 556 *
558 557 * Request that the PF add one or more addresses to our filters.
559 - *
560 - * Return: 0 on success, negative on failure
561 - */
562 - int iavf_add_ether_addrs(struct iavf_adapter *adapter)
558 + **/
559 + void iavf_add_ether_addrs(struct iavf_adapter *adapter)
563 560 {
564 561 struct virtchnl_ether_addr_list *veal;
565 562 struct iavf_mac_filter *f;
566 563 int i = 0, count = 0;
567 564 bool more = false;
568 565 size_t len;
569 - int ret;
570 566
571 567 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
572 568 /* bail because we already have a command pending */
573 569 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
574 570 adapter->current_op);
575 - return -EBUSY;
571 + return;
576 572 }
577 573
578 574 spin_lock_bh(&adapter->mac_vlan_list_lock);
@@ -584,7 +580,7 @@ int iavf_add_ether_addrs(struct iavf_adapter *adapter)
584 580 if (!count) {
585 581 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
586 582 spin_unlock_bh(&adapter->mac_vlan_list_lock);
587 - return 0;
583 + return;
588 584 }
589 585 adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
590 586
@@ -598,9 +594,8 @@ int iavf_add_ether_addrs(struct iavf_adapter *adapter)
598 594
599 595 veal = kzalloc(len, GFP_ATOMIC);
600 596 if (!veal) {
601 - adapter->current_op = VIRTCHNL_OP_UNKNOWN;
602 597 spin_unlock_bh(&adapter->mac_vlan_list_lock);
603 - return -ENOMEM;
598 + return;
604 599 }
605 600
606 601 veal->vsi_id = adapter->vsi_res->vsi_id;
@@ -620,15 +615,8 @@ int iavf_add_ether_addrs(struct iavf_adapter *adapter)
620 615
621 616 spin_unlock_bh(&adapter->mac_vlan_list_lock);
622 617
623 - ret = iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len);
618 + iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len);
624 619 kfree(veal);
625 - if (ret) {
626 - dev_err(&adapter->pdev->dev,
627 - "Unable to send ADD_ETH_ADDR message to PF, error %d\n", ret);
628 - adapter->current_op = VIRTCHNL_OP_UNKNOWN;
629 - }
630 -
631 - return ret;
632 620 }
633 621
634 622 /**
@@ -724,8 +712,8 @@ static void iavf_mac_add_ok(struct iavf_adapter *adapter)
724 712 * @adapter: adapter structure
725 713 *
726 714 * Remove filters from list based on PF response.
727 - */
728 - void iavf_mac_add_reject(struct iavf_adapter *adapter)
715 + **/
716 + static void iavf_mac_add_reject(struct iavf_adapter *adapter)
729 717 {
730 718 struct net_device *netdev = adapter->netdev;
731 719 struct iavf_mac_filter *f, *ftmp;
@@ -2376,6 +2364,7 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,
2376 2364 iavf_mac_add_reject(adapter);
2377 2365 /* restore administratively set MAC address */
2378 2366 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
2367 + wake_up(&adapter->vc_waitqueue);
2379 2368 break;
2380 2369 case VIRTCHNL_OP_DEL_ETH_ADDR:
2381 2370 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
@@ -2566,6 +2555,7 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,
2566 2555 eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2567 2556 netif_addr_unlock_bh(netdev);
2568 2557 }
2558 + wake_up(&adapter->vc_waitqueue);
2569 2559 break;
2570 2560 case VIRTCHNL_OP_GET_STATS: {
2571 2561 struct iavf_eth_stats *stats =
@@ -2960,72 +2950,3 @@ void iavf_virtchnl_completion(struct iavf_adapter *adapter,
2960 2950 } /* switch v_opcode */
2961 2951 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
2962 2952 }
2963 -
2964 - /**
2965 - * iavf_poll_virtchnl_response - Poll admin queue for virtchnl response
2966 - * @adapter: adapter structure
2967 - * @event: pre-allocated event buffer to use for polling
2968 - * @condition: callback to check if desired response received
2969 - * @cond_data: context data passed to condition callback
2970 - * @timeout_ms: maximum time to wait in milliseconds
2971 - *
2972 - * Polls the admin queue and processes all incoming virtchnl messages.
2973 - * After processing each valid message, calls the condition callback to check
2974 - * if the expected response has been received. The callback receives the opcode
2975 - * of the processed message to identify which response was received. Continues
2976 - * polling until the callback returns true or timeout expires.
2977 - *
2978 - * Caller must allocate event buffer before sending any messages to PF to avoid
2979 - * state mismatch if allocation fails after message is sent.
2980 - *
2981 - * Caller must hold netdev_lock. This can sleep for up to timeout_ms while
2982 - * polling hardware.
2983 - *
2984 - * Return: 0 on success (condition met), -EAGAIN on timeout, or error code
2985 - */
2986 - int iavf_poll_virtchnl_response(struct iavf_adapter *adapter,
2987 - struct iavf_arq_event_info *event,
2988 - bool (*condition)(struct iavf_adapter *adapter,
2989 - const void *data,
2990 - enum virtchnl_ops v_op),
2991 - const void *cond_data,
2992 - unsigned int timeout_ms)
2993 - {
2994 - struct iavf_hw *hw = &adapter->hw;
2995 - enum virtchnl_ops received_op;
2996 - unsigned long timeout;
2997 - int ret = -EAGAIN;
2998 - u16 pending = 0;
2999 - u32 v_retval;
3000 -
3001 - netdev_assert_locked(adapter->netdev);
3002 -
3003 - timeout = jiffies + msecs_to_jiffies(timeout_ms);
3004 - do {
3005 - if (!pending)
3006 - usleep_range(50, 75);
3007 -
3008 - if (iavf_clean_arq_element(hw, event, &pending) == IAVF_SUCCESS) {
3009 - received_op = (enum virtchnl_ops)le32_to_cpu(event->desc.cookie_high);
3010 - if (received_op != VIRTCHNL_OP_UNKNOWN) {
3011 - v_retval = le32_to_cpu(event->desc.cookie_low);
3012 -
3013 - iavf_virtchnl_completion(adapter, received_op,
3014 - (enum iavf_status)v_retval,
3015 - event->msg_buf, event->msg_len);
3016 -
3017 - if (condition(adapter, cond_data, received_op)) {
3018 - ret = 0;
3019 - break;
3020 - }
3021 - }
3022 -
3023 - memset(event->msg_buf, 0, IAVF_MAX_AQ_BUF_SIZE);
3024 -
3025 - if (pending)
3026 - continue;
3027 - }
3028 - } while (time_before(jiffies, timeout));
3029 -
3030 - return ret;
3031 - }
modified drivers/net/ethernet/intel/ice/devlink/port.c
@@ -590,8 +590,8 @@ static void ice_dealloc_dynamic_port(struct ice_dynamic_port *dyn_port)
590 590
591 591 xa_erase(&pf->sf_nums, devlink_port->attrs.pci_sf.sf);
592 592 ice_eswitch_detach_sf(pf, dyn_port);
593 - xa_erase(&pf->dyn_ports, dyn_port->vsi->idx);
594 593 ice_vsi_free(dyn_port->vsi);
594 + xa_erase(&pf->dyn_ports, dyn_port->vsi->idx);
595 595 kfree(dyn_port);
596 596 }
597 597
modified drivers/net/ethernet/intel/ice/ice_eswitch.c
@@ -95,7 +95,7 @@ ice_eswitch_release_repr(struct ice_pf *pf, struct ice_repr *repr)
95 95 return;
96 96
97 97 ice_vsi_update_security(vsi, ice_vsi_ctx_set_antispoof);
98 - dst_release(&repr->dst->dst);
98 + metadata_dst_free(repr->dst);
99 99 repr->dst = NULL;
100 100 ice_fltr_add_mac_and_broadcast(vsi, repr->parent_mac,
101 101 ICE_FWD_TO_VSI);
modified drivers/net/ethernet/intel/ice/ice_sriov.c
@@ -1366,20 +1366,6 @@ int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
1366 1366 return __ice_set_vf_mac(ice_netdev_to_pf(netdev), vf_id, mac);
1367 1367 }
1368 1368
1369 - /**
1370 - * ice_setup_vf_trust - Enable/disable VF trust mode without reset
1371 - * @vf: VF to configure
1372 - * @setting: trust setting
1373 - *
1374 - * Update VF flags when changing trust without performing a VF reset.
1375 - * This is only called when it's safe to skip the reset (VF has no advanced
1376 - * features configured that need cleanup).
1377 - */
1378 - static void ice_setup_vf_trust(struct ice_vf *vf, bool setting)
1379 - {
1380 - assign_bit(ICE_VIRTCHNL_VF_CAP_PRIVILEGE, &vf->vf_caps, setting);
1381 - }
1382 -
1383 1369 /**
1384 1370 * ice_set_vf_trust
1385 1371 * @netdev: network interface device structure
@@ -1415,19 +1401,11 @@ int ice_set_vf_trust(struct net_device *netdev, int vf_id, bool trusted)
1415 1401
1416 1402 mutex_lock(&vf->cfg_lock);
1417 1403
1418 - /* Reset only if revoking trust and VF has advanced features configured */
1419 - if (!trusted &&
1420 - (vf->num_mac_lldp > 0 ||
1421 - test_bit(ICE_VF_STATE_UC_PROMISC, vf->vf_states) ||
1422 - test_bit(ICE_VF_STATE_MC_PROMISC, vf->vf_states))) {
1423 - while (vf->num_mac_lldp)
1424 - ice_vf_update_mac_lldp_num(vf, ice_get_vf_vsi(vf), false);
1425 - vf->trusted = trusted;
1426 - ice_reset_vf(vf, ICE_VF_RESET_NOTIFY);
1427 - } else {
1428 - vf->trusted = trusted;
1429 - ice_setup_vf_trust(vf, trusted);
1430 - }
1404 + while (!trusted && vf->num_mac_lldp)
1405 + ice_vf_update_mac_lldp_num(vf, ice_get_vf_vsi(vf), false);
1406 +
1407 + vf->trusted = trusted;
1408 + ice_reset_vf(vf, ICE_VF_RESET_NOTIFY);
1431 1409 dev_info(ice_pf_to_dev(pf), "VF %u is now %strusted\n",
1432 1410 vf_id, trusted ? "" : "un");
1433 1411
modified drivers/net/ethernet/intel/ice/ice_txrx.c
@@ -1561,10 +1561,10 @@ ice_tx_map(struct ice_tx_ring *tx_ring, struct ice_tx_buf *first,
1561 1561 }
1562 1562 }
1563 1563 tstamp_ring->next_to_use = j;
1564 - writel(j, tstamp_ring->tail);
1564 + writel_relaxed(j, tstamp_ring->tail);
1565 1565 } else {
1566 1566 ring_kick:
1567 - writel(i, tx_ring->tail);
1567 + writel_relaxed(i, tx_ring->tail);
1568 1568 }
1569 1569 return;
1570 1570
modified drivers/net/ethernet/mellanox/mlx5/core/en_rx.c
@@ -908,12 +908,10 @@ int mlx5e_poll_ico_cq(struct mlx5e_cq *cq)
908 908 } while (!last_wqe);
909 909 } while ((++i < MLX5E_TX_CQ_POLL_BUDGET) && (cqe = mlx5_cqwq_get_cqe(&cq->wq)));
910 910
911 - mlx5_cqwq_update_db_record(&cq->wq);
911 + sq->cc = sqcc;
912 912
913 - /* ensure cq space is freed before enabling more cqes */
914 - dma_wmb();
913 + mlx5_cqwq_update_db_record(&cq->wq);
915 914
916 - sq->cc = sqcc;
917 915 return i;
918 916 }
919 917
modified drivers/net/ethernet/mellanox/mlx5/core/esw/adj_vport.c
@@ -11,6 +11,26 @@ int mlx5_esw_adj_vport_modify(struct mlx5_core_dev *dev, u16 vport,
11 11
12 12 lockdep_assert_held(&dev->priv.eswitch->state_lock);
13 13
14 + if (MLX5_CAP_ESW(dev, esw_vport_state_max_tx_speed)) {
15 + u8 op_mod = MLX5_VPORT_STATE_OP_MOD_ESW_VPORT;
16 + struct mlx5_vport *esw_vport;
17 + u32 speed = 0;
18 + int err;
19 +
20 + err = mlx5_query_vport_max_tx_speed(dev, op_mod, vport,
21 + true, &speed, NULL);
22 + if (err) {
23 + esw_vport = mlx5_eswitch_get_vport(dev->priv.eswitch,
24 + vport);
25 + speed = IS_ERR(esw_vport) ? 0 :
26 + esw_vport->agg_max_tx_speed;
27 + mlx5_core_dbg(dev,
28 + "Failed to query vport %d max tx speed, err=%d, using cached %u\n",
29 + vport, err, speed);
30 + }
31 + MLX5_SET(modify_vport_state_in, in, max_tx_speed, speed);
32 + }
33 +
14 34 MLX5_SET(modify_vport_state_in, in, opcode,
15 35 MLX5_CMD_OP_MODIFY_VPORT_STATE);
16 36 MLX5_SET(modify_vport_state_in, in, op_mod,
modified drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
@@ -1432,40 +1432,30 @@ static bool mlx5_lag_should_disable_lag(struct mlx5_lag *ldev, bool do_bond)
1432 1432 }
1433 1433
1434 1434 #ifdef CONFIG_MLX5_ESWITCH
1435 - static int mlx5_lag_get_devices_oper_speed(struct mlx5_lag *ldev,
1436 - u32 *sum_speed)
1435 + static int
1436 + mlx5_lag_sum_devices_speed(struct mlx5_lag *ldev, u32 *sum_speed,
1437 + int (*get_speed)(struct mlx5_core_dev *, u32 *))
1437 1438 {
1439 + struct mlx5_core_dev *pf_mdev;
1440 + struct lag_func *pf;
1438 1441 int pf_idx;
1442 + u32 speed;
1443 + int ret;
1439 1444
1440 1445 *sum_speed = 0;
1441 1446 mlx5_ldev_for_each(pf_idx, 0, ldev) {
1442 - u8 opmod = MLX5_VPORT_STATE_OP_MOD_VNIC_VPORT;
1443 - struct mlx5_core_dev *pf_mdev;
1444 - struct lag_func *pf;
1445 - u32 speed;
1446 - u8 state;
1447 - int ret;
1448 -
1449 1447 pf = mlx5_lag_pf(ldev, pf_idx);
1450 1448 if (!pf)
1451 1449 continue;
1452 1450 pf_mdev = pf->dev;
1453 1451 if (!pf_mdev)
1454 1452 continue;
1455 - ret = mlx5_query_vport_max_tx_speed(pf_mdev, opmod, 0, 0,
1456 - &speed, &state);
1457 - if (ret) {
1458 - mlx5_core_dbg(pf_mdev, "State query failed (err=%d)\n",
1459 - ret);
1460 - return ret;
1461 - }
1462 - if (state != VPORT_STATE_UP)
1463 - continue;
1464 1453
1465 - ret = mlx5_port_oper_linkspeed(pf_mdev, &speed);
1454 + ret = get_speed(pf_mdev, &speed);
1466 1455 if (ret) {
1467 1456 mlx5_core_dbg(pf_mdev,
1468 - "Failed to get oper speed (err=%d)\n",
1457 + "Failed to get device speed using %ps. Device %s speed is not available (err=%d)\n",
1458 + get_speed, dev_name(pf_mdev->device),
1469 1459 ret);
1470 1460 return ret;
1471 1461 }
@@ -1476,42 +1466,17 @@ static int mlx5_lag_get_devices_oper_speed(struct mlx5_lag *ldev,
1476 1466 return 0;
1477 1467 }
1478 1468
1479 - static int mlx5_lag_get_devices_max_speed(struct mlx5_lag *ldev, u32 *max_speed)
1469 + static int mlx5_lag_sum_devices_max_speed(struct mlx5_lag *ldev, u32 *max_speed)
1480 1470 {
1481 - bool take_max;
1482 - int pf_idx;
1483 -
1484 - take_max = ldev->tracker.tx_type == NETDEV_LAG_TX_TYPE_ACTIVEBACKUP;
1485 - if (ldev->mode == MLX5_LAG_MODE_MPESW)
1486 - take_max = false;
1487 -
1488 - *max_speed = 0;
1489 - mlx5_ldev_for_each(pf_idx, 0, ldev) {
1490 - struct mlx5_core_dev *pf_mdev;
1491 - struct lag_func *pf;
1492 - u32 speed;
1493 - int ret;
1494 -
1495 - pf = mlx5_lag_pf(ldev, pf_idx);
1496 - if (!pf)
1497 - continue;
1498 - pf_mdev = pf->dev;
1499 - if (!pf_mdev)
1500 - continue;
1501 -
1502 - ret = mlx5_port_max_linkspeed(pf_mdev, &speed);
1503 - if (ret) {
1504 - mlx5_core_dbg(pf_mdev,
1505 - "Failed to get max speed (err=%d)\n",
1506 - ret);
1507 - return ret;
1508 - }
1509 -
1510 - *max_speed = take_max ?
1511 - max(*max_speed, speed) : *max_speed + speed;
1512 - }
1471 + return mlx5_lag_sum_devices_speed(ldev, max_speed,
1472 + mlx5_port_max_linkspeed);
1473 + }
1513 1474
1514 - return 0;
1475 + static int mlx5_lag_sum_devices_oper_speed(struct mlx5_lag *ldev,
1476 + u32 *oper_speed)
1477 + {
1478 + return mlx5_lag_sum_devices_speed(ldev, oper_speed,
1479 + mlx5_port_oper_linkspeed);
1515 1480 }
1516 1481
1517 1482 static void mlx5_lag_modify_device_vports_speed(struct mlx5_core_dev *mdev,
@@ -1560,7 +1525,7 @@ void mlx5_lag_set_vports_agg_speed(struct mlx5_lag *ldev)
1560 1525 int pf_idx;
1561 1526
1562 1527 if (ldev->mode == MLX5_LAG_MODE_MPESW) {
1563 - if (mlx5_lag_get_devices_oper_speed(ldev, &speed))
1528 + if (mlx5_lag_sum_devices_oper_speed(ldev, &speed))
1564 1529 return;
1565 1530 } else {
1566 1531 speed = ldev->tracker.bond_speed_mbps;
@@ -1568,8 +1533,8 @@ void mlx5_lag_set_vports_agg_speed(struct mlx5_lag *ldev)
1568 1533 return;
1569 1534 }
1570 1535
1571 - /* If speed is not set, fall back to the max achievable speed */
1572 - if (!speed && mlx5_lag_get_devices_max_speed(ldev, &speed))
1536 + /* If speed is not set, use the sum of max speeds of all PFs */
1537 + if (!speed && mlx5_lag_sum_devices_max_speed(ldev, &speed))
1573 1538 return;
1574 1539
1575 1540 speed = speed / MLX5_MAX_TX_SPEED_UNIT;
modified drivers/net/ethernet/mellanox/mlx5/core/vport.c
@@ -93,6 +93,30 @@ int mlx5_modify_vport_admin_state(struct mlx5_core_dev *mdev, u8 opmod,
93 93 lockdep_assert_held(&mdev->priv.eswitch->state_lock);
94 94 #endif
95 95
96 + if (MLX5_CAP_ESW(mdev, esw_vport_state_max_tx_speed) &&
97 + opmod == MLX5_VPORT_STATE_OP_MOD_ESW_VPORT &&
98 + vport != MLX5_VPORT_UPLINK) {
99 + u32 speed = 0;
100 + int err;
101 +
102 + err = mlx5_query_vport_max_tx_speed(mdev, opmod, vport,
103 + other_vport, &speed, NULL);
104 + if (err) {
105 + #ifdef CONFIG_MLX5_ESWITCH
106 + struct mlx5_vport *esw_vport;
107 +
108 + esw_vport = mlx5_eswitch_get_vport(mdev->priv.eswitch,
109 + vport);
110 + speed = IS_ERR(esw_vport) ? 0 :
111 + esw_vport->agg_max_tx_speed;
112 + #endif
113 + mlx5_core_dbg(mdev,
114 + "Failed to query vport %d max tx speed, err=%d, using cached %u\n",
115 + vport, err, speed);
116 + }
117 + MLX5_SET(modify_vport_state_in, in, max_tx_speed, speed);
118 + }
119 +
96 120 MLX5_SET(modify_vport_state_in, in, opcode,
97 121 MLX5_CMD_OP_MODIFY_VPORT_STATE);
98 122 MLX5_SET(modify_vport_state_in, in, op_mod, opmod);
modified drivers/net/ethernet/mellanox/mlxsw/spectrum.h
@@ -989,8 +989,6 @@ void mlxsw_sp_acl_ruleset_prio_get(struct mlxsw_sp_acl_ruleset *ruleset,
989 989 struct mlxsw_sp_acl_rule_info *
990 990 mlxsw_sp_acl_rulei_create(struct mlxsw_sp_acl *acl,
991 991 struct mlxsw_afa_block *afa_block);
992 - void mlxsw_sp_acl_rulei_free(struct mlxsw_sp *mlxsw_sp,
993 - const struct mlxsw_sp_acl_rule_info *rulei);
994 992 void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp *mlxsw_sp,
995 993 struct mlxsw_sp_acl_rule_info *rulei);
996 994 int mlxsw_sp_acl_rulei_commit(struct mlxsw_sp_acl_rule_info *rulei);
modified drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c
@@ -340,8 +340,8 @@ err_afa_block_create:
340 340 return ERR_PTR(err);
341 341 }
342 342
343 - void mlxsw_sp_acl_rulei_free(struct mlxsw_sp *mlxsw_sp,
344 - const struct mlxsw_sp_acl_rule_info *rulei)
343 + void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp *mlxsw_sp,
344 + struct mlxsw_sp_acl_rule_info *rulei)
345 345 {
346 346 if (rulei->action_created)
347 347 mlxsw_afa_block_destroy(rulei->act_block);
@@ -351,12 +351,6 @@ void mlxsw_sp_acl_rulei_free(struct mlxsw_sp *mlxsw_sp,
351 351 if (rulei->dst_port_range_reg_valid)
352 352 mlxsw_sp_port_range_reg_put(mlxsw_sp,
353 353 rulei->dst_port_range_reg_index);
354 - }
355 -
356 - void mlxsw_sp_acl_rulei_destroy(struct mlxsw_sp *mlxsw_sp,
357 - struct mlxsw_sp_acl_rule_info *rulei)
358 - {
359 - mlxsw_sp_acl_rulei_free(mlxsw_sp, rulei);
360 354 kfree(rulei);
361 355 }
362 356
modified drivers/net/ethernet/mellanox/mlxsw/spectrum_flower.c
@@ -862,19 +862,14 @@ int mlxsw_sp_flower_tmplt_create(struct mlxsw_sp *mlxsw_sp,
862 862 memset(&rulei, 0, sizeof(rulei));
863 863 err = mlxsw_sp_flower_parse(mlxsw_sp, block, &rulei, f);
864 864 if (err)
865 - goto out;
866 -
865 + return err;
867 866 ruleset = mlxsw_sp_acl_ruleset_get(mlxsw_sp, block,
868 867 f->common.chain_index,
869 868 MLXSW_SP_ACL_PROFILE_FLOWER,
870 869 &rulei.values.elusage);
871 - err = PTR_ERR_OR_ZERO(ruleset);
872 -
873 - out:
874 - mlxsw_sp_acl_rulei_free(mlxsw_sp, &rulei);
875 870
876 871 /* keep the reference to the ruleset */
877 - return err;
872 + return PTR_ERR_OR_ZERO(ruleset);
878 873 }
879 874
880 875 void mlxsw_sp_flower_tmplt_destroy(struct mlxsw_sp *mlxsw_sp,
modified drivers/net/ethernet/microchip/sparx5/sparx5_ptp.c
@@ -622,9 +622,18 @@ int sparx5_ptp_init(struct sparx5 *sparx5)
622 622 sparx5->ptp = 1;
623 623 }
624 624
625 - /* The base, non-PTP-capable lan969x variants need the
626 - * first TOD counter running to forward frames.
627 - */
625 + if (!sparx5->ptp)
626 + return 0;
627 +
628 + for (i = 0; i < SPARX5_PHC_COUNT; ++i) {
629 + err = sparx5_ptp_phc_init(sparx5, i, &sparx5_ptp_clock_info);
630 + if (err)
631 + return err;
632 + }
633 +
634 + spin_lock_init(&sparx5->ptp_clock_lock);
635 + spin_lock_init(&sparx5->ptp_ts_id_lock);
636 + mutex_init(&sparx5->ptp_lock);
628 637
629 638 /* Disable master counters */
630 639 spx5_wr(PTP_PTP_DOM_CFG_PTP_ENA_SET(0), sparx5, PTP_PTP_DOM_CFG);
@@ -648,19 +657,6 @@ int sparx5_ptp_init(struct sparx5 *sparx5)
648 657 /* Enable master counters */
649 658 spx5_wr(PTP_PTP_DOM_CFG_PTP_ENA_SET(0x7), sparx5, PTP_PTP_DOM_CFG);
650 659
651 - if (!sparx5->ptp)
652 - return 0;
653 -
654 - for (i = 0; i < SPARX5_PHC_COUNT; ++i) {
655 - err = sparx5_ptp_phc_init(sparx5, i, &sparx5_ptp_clock_info);
656 - if (err)
657 - return err;
658 - }
659 -
660 - spin_lock_init(&sparx5->ptp_clock_lock);
661 - spin_lock_init(&sparx5->ptp_ts_id_lock);
662 - mutex_init(&sparx5->ptp_lock);
663 -
664 660 for (i = 0; i < sparx5->data->consts->n_ports; i++) {
665 661 port = sparx5->ports[i];
666 662 if (!port)
modified drivers/net/ethernet/microchip/sparx5/sparx5_tc_matchall.c
@@ -160,7 +160,6 @@ static int sparx5_tc_matchall_destroy(struct net_device *ndev,
160 160 }
161 161
162 162 list_del(&entry->list);
163 - kfree(entry);
164 163
165 164 return err;
166 165 }
modified drivers/net/ethernet/microsoft/mana/mana_bpf.c
@@ -91,7 +91,7 @@ u32 mana_run_xdp(struct net_device *ndev, struct mana_rxq *rxq,
91 91 goto out;
92 92
93 93 xdp_init_buff(xdp, PAGE_SIZE, &rxq->xdp_rxq);
94 - xdp_prepare_buff(xdp, buf_va, rxq->headroom, pkt_len, true);
94 + xdp_prepare_buff(xdp, buf_va, XDP_PACKET_HEADROOM, pkt_len, true);
95 95
96 96 act = bpf_prog_run_xdp(prog, xdp);
97 97
@@ -183,9 +183,9 @@ static int mana_xdp_set(struct net_device *ndev, struct bpf_prog *prog,
183 183 if (!old_prog && !prog)
184 184 return 0;
185 185
186 - if (prog && ndev->mtu > MANA_XDP_MTU_MAX(ndev)) {
186 + if (prog && ndev->mtu > MANA_XDP_MTU_MAX) {
187 187 netdev_err(ndev, "XDP: mtu:%u too large, mtu_max:%lu\n",
188 - ndev->mtu, MANA_XDP_MTU_MAX(ndev));
188 + ndev->mtu, MANA_XDP_MTU_MAX);
189 189 NL_SET_ERR_MSG_MOD(extack, "XDP: mtu too large");
190 190
191 191 return -EOPNOTSUPP;
@@ -238,7 +238,7 @@ static int mana_xdp_set(struct net_device *ndev, struct bpf_prog *prog,
238 238 bpf_prog_put(old_prog);
239 239
240 240 if (prog)
241 - ndev->max_mtu = min_t(unsigned int, MANA_XDP_MTU_MAX(ndev),
241 + ndev->max_mtu = min_t(unsigned int, MANA_XDP_MTU_MAX,
242 242 gc->adapter_mtu - ETH_HLEN);
243 243 else
244 244 ndev->max_mtu = gc->adapter_mtu - ETH_HLEN;
modified drivers/net/ethernet/microsoft/mana/mana_en.c
@@ -758,44 +758,6 @@ static void *mana_get_rxbuf_pre(struct mana_rxq *rxq, dma_addr_t *da)
758 758 return va;
759 759 }
760 760
761 - /* Reserve enough headroom to satisfy the skb_cow() in ip_forward() and avoid
762 - * reallocation: the TX path keeps the SGE DMA mappings in struct mana_skb_head
763 - * at skb->head, so the port advertises ndev->needed_headroom = MANA_HEADROOM.
764 - */
765 - static u32 mana_get_rxbuf_headroom(struct mana_port_context *apc)
766 - {
767 - if (mana_xdp_get(apc))
768 - return mana_xdp_headroom(apc->ndev);
769 -
770 - return LL_RESERVED_SPACE(apc->ndev);
771 - }
772 -
773 - static u32 mana_get_rxbuf_size(struct mana_port_context *apc, u32 mtu)
774 - {
775 - u32 len = SKB_DATA_ALIGN(mtu + MANA_RXBUF_PAD +
776 - mana_get_rxbuf_headroom(apc));
777 -
778 - return ALIGN(len, MANA_RX_FRAG_ALIGNMENT);
779 - }
780 -
781 - /* Returns true when one RX buffer per page is already required by XDP or by
782 - * the buffer size implied by the MTU, i.e. regardless of the
783 - * MANA_PRIV_FLAG_USE_FULL_PAGE_RXBUF private flag.
784 - */
785 - bool mana_single_rxbuf_per_page_forced(struct mana_port_context *apc, u32 mtu)
786 - {
787 - /* For xdp make sure only one packet fits per page. */
788 - if (mana_xdp_get(apc))
789 - return true;
790 -
791 - /* Only use the page_pool fragment path when at least two buffers,
792 - * including the headroom each of them has to reserve, actually fit
793 - * into one page. Otherwise the fragment path degenerates into one
794 - * buffer per page while still paying the fragment accounting cost.
795 - */
796 - return PAGE_SIZE / mana_get_rxbuf_size(apc, mtu) < 2;
797 - }
798 -
799 761 static bool
800 762 mana_use_single_rxbuf_per_page(struct mana_port_context *apc, u32 mtu)
801 763 {
@@ -808,27 +770,32 @@ mana_use_single_rxbuf_per_page(struct mana_port_context *apc, u32 mtu)
808 770 if (apc->priv_flags & BIT(MANA_PRIV_FLAG_USE_FULL_PAGE_RXBUF))
809 771 return true;
810 772
811 - return mana_single_rxbuf_per_page_forced(apc, mtu);
773 + /* For xdp and jumbo frames make sure only one packet fits per page. */
774 + if (mtu + MANA_RXBUF_PAD > PAGE_SIZE / 2 || mana_xdp_get(apc))
775 + return true;
776 +
777 + return false;
812 778 }
813 779
814 - /* Get RX buffer's data size, alloc size, headroom and frag count based on MTU */
780 + /* Get RX buffer's data size, alloc size, XDP headroom based on MTU */
815 781 static void mana_get_rxbuf_cfg(struct mana_port_context *apc,
816 782 int mtu, u32 *datasize, u32 *alloc_size,
817 783 u32 *headroom, u32 *frag_count)
818 784 {
819 - u32 buf_size;
785 + u32 len, buf_size;
820 786
821 787 /* Calculate datasize first (consistent across all cases) */
822 788 *datasize = mtu + ETH_HLEN;
823 789
824 - *headroom = mana_get_rxbuf_headroom(apc);
825 -
826 790 if (mana_use_single_rxbuf_per_page(apc, mtu)) {
827 - if (mana_xdp_get(apc))
791 + if (mana_xdp_get(apc)) {
792 + *headroom = XDP_PACKET_HEADROOM;
828 793 *alloc_size = PAGE_SIZE;
829 - else
794 + } else {
795 + *headroom = 0; /* no support for XDP */
830 796 *alloc_size = SKB_DATA_ALIGN(mtu + MANA_RXBUF_PAD +
831 797 *headroom);
798 + }
832 799
833 800 *frag_count = 1;
834 801
@@ -842,7 +809,11 @@ static void mana_get_rxbuf_cfg(struct mana_port_context *apc,
842 809 }
843 810
844 811 /* Standard MTU case - optimize for multiple packets per page */
845 - buf_size = mana_get_rxbuf_size(apc, mtu);
812 + *headroom = 0;
813 +
814 + /* Calculate base buffer size needed */
815 + len = SKB_DATA_ALIGN(mtu + MANA_RXBUF_PAD + *headroom);
816 + buf_size = ALIGN(len, MANA_RX_FRAG_ALIGNMENT);
846 817
847 818 /* Calculate how many packets can fit in a page */
848 819 *frag_count = PAGE_SIZE / buf_size;
modified drivers/net/ethernet/microsoft/mana/mana_ethtool.c
@@ -815,12 +815,12 @@ static int mana_set_priv_flags(struct net_device *ndev, u32 priv_flags)
815 815 if (!apc->port_is_up)
816 816 return 0;
817 817
818 - /* If XDP is attached or the MTU already forces one buffer per
819 - * page, single-buffer-per-page is used regardless of this
820 - * flag. Skip the expensive detach/attach cycle since nothing
821 - * changes.
818 + /* If XDP is attached or MTU is jumbo, single-buffer-per-page
819 + * is already forced regardless of this flag. Skip the
820 + * expensive detach/attach cycle since nothing changes.
822 821 */
823 - if (mana_single_rxbuf_per_page_forced(apc, ndev->mtu))
822 + if (ndev->mtu + MANA_RXBUF_PAD > PAGE_SIZE / 2 ||
823 + mana_xdp_get(apc))
824 824 return 0;
825 825
826 826 /* Block RDMA from grabbing the vport during detach/attach */
modified drivers/net/ethernet/stmicro/stmmac/hwif.h
@@ -633,7 +633,7 @@ struct stmmac_est_ops {
633 633 struct stmmac_vlan_ops {
634 634 /* VLAN */
635 635 void (*update_vlan_hash)(struct mac_device_info *hw, u32 hash,
636 - bool is_svlan);
636 + u16 perfect_match, bool is_double);
637 637 void (*enable_vlan)(struct mac_device_info *hw, u32 type);
638 638 void (*rx_hw_vlan)(struct mac_device_info *hw, struct dma_desc *rx_desc,
639 639 struct sk_buff *skb);
modified drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -344,7 +344,7 @@ struct stmmac_priv {
344 344 void __iomem *ptpaddr;
345 345 void __iomem *estaddr;
346 346 unsigned long active_vlans[BITS_TO_LONGS(VLAN_N_VID)];
347 - unsigned int num_svlans;
347 + unsigned int num_double_vlans;
348 348 int sfty_irq;
349 349 struct stmmac_msi *msi;
350 350
modified drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -6226,13 +6226,6 @@ static netdev_features_t stmmac_fix_features(struct net_device *dev,
6226 6226 if (priv->plat->bugged_jumbo && (dev->mtu > ETH_DATA_LEN))
6227 6227 features &= ~NETIF_F_CSUM_MASK;
6228 6228
6229 - if (priv->plat->core_type == DWMAC_CORE_XGMAC) {
6230 - if (features & NETIF_F_HW_VLAN_CTAG_RX)
6231 - features |= NETIF_F_HW_VLAN_STAG_RX;
6232 - else
6233 - features &= ~NETIF_F_HW_VLAN_STAG_RX;
6234 - }
6235 -
6236 6229 return features;
6237 6230 }
6238 6231
@@ -6857,21 +6850,32 @@ static u32 stmmac_vid_crc32_le(__le16 vid_le)
6857 6850 return crc;
6858 6851 }
6859 6852
6860 - static int stmmac_vlan_update(struct stmmac_priv *priv, bool is_svlan)
6853 + static int stmmac_vlan_update(struct stmmac_priv *priv, bool is_double)
6861 6854 {
6862 6855 u32 crc, hash = 0;
6856 + u16 pmatch = 0;
6857 + int count = 0;
6863 6858 u16 vid = 0;
6864 6859
6865 6860 for_each_set_bit(vid, priv->active_vlans, VLAN_N_VID) {
6866 6861 __le16 vid_le = cpu_to_le16(vid);
6867 6862 crc = bitrev32(~stmmac_vid_crc32_le(vid_le)) >> 28;
6868 6863 hash |= (1 << crc);
6864 + count++;
6865 + }
6866 +
6867 + if (!priv->dma_cap.vlhash) {
6868 + if (count > 2) /* VID = 0 always passes filter */
6869 + return -EOPNOTSUPP;
6870 +
6871 + pmatch = vid;
6872 + hash = 0;
6869 6873 }
6870 6874
6871 6875 if (!netif_running(priv->dev))
6872 6876 return 0;
6873 6877
6874 - return stmmac_update_vlan_hash(priv, priv->hw, hash, is_svlan);
6878 + return stmmac_update_vlan_hash(priv, priv->hw, hash, pmatch, is_double);
6875 6879 }
6876 6880
6877 6881 /* FIXME: This may need RXC to be running, but it may be called with BH
@@ -6880,8 +6884,8 @@ static int stmmac_vlan_update(struct stmmac_priv *priv, bool is_svlan)
6880 6884 static int stmmac_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vid)
6881 6885 {
6882 6886 struct stmmac_priv *priv = netdev_priv(ndev);
6883 - unsigned int num_svlans;
6884 - bool is_svlan = false;
6887 + unsigned int num_double_vlans;
6888 + bool is_double = false;
6885 6889 int ret;
6886 6890
6887 6891 ret = pm_runtime_resume_and_get(priv->device);
@@ -6889,11 +6893,11 @@ static int stmmac_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vid
6889 6893 return ret;
6890 6894
6891 6895 if (be16_to_cpu(proto) == ETH_P_8021AD)
6892 - is_svlan = true;
6896 + is_double = true;
6893 6897
6894 6898 set_bit(vid, priv->active_vlans);
6895 - num_svlans = priv->num_svlans + is_svlan;
6896 - ret = stmmac_vlan_update(priv, num_svlans);
6899 + num_double_vlans = priv->num_double_vlans + is_double;
6900 + ret = stmmac_vlan_update(priv, num_double_vlans);
6897 6901 if (ret) {
6898 6902 clear_bit(vid, priv->active_vlans);
6899 6903 goto err_pm_put;
@@ -6903,12 +6907,12 @@ static int stmmac_vlan_rx_add_vid(struct net_device *ndev, __be16 proto, u16 vid
6903 6907 ret = stmmac_add_hw_vlan_rx_fltr(priv, ndev, priv->hw, proto, vid);
6904 6908 if (ret) {
6905 6909 clear_bit(vid, priv->active_vlans);
6906 - stmmac_vlan_update(priv, priv->num_svlans);
6910 + stmmac_vlan_update(priv, priv->num_double_vlans);
6907 6911 goto err_pm_put;
6908 6912 }
6909 6913 }
6910 6914
6911 - priv->num_svlans = num_svlans;
6915 + priv->num_double_vlans = num_double_vlans;
6912 6916
6913 6917 err_pm_put:
6914 6918 pm_runtime_put(priv->device);
@@ -6922,8 +6926,8 @@ err_pm_put:
6922 6926 static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vid)
6923 6927 {
6924 6928 struct stmmac_priv *priv = netdev_priv(ndev);
6925 - unsigned int num_svlans;
6926 - bool is_svlan = false;
6929 + unsigned int num_double_vlans;
6930 + bool is_double = false;
6927 6931 int ret;
6928 6932
6929 6933 ret = pm_runtime_resume_and_get(priv->device);
@@ -6931,11 +6935,11 @@ static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vi
6931 6935 return ret;
6932 6936
6933 6937 if (be16_to_cpu(proto) == ETH_P_8021AD)
6934 - is_svlan = true;
6938 + is_double = true;
6935 6939
6936 6940 clear_bit(vid, priv->active_vlans);
6937 - num_svlans = priv->num_svlans - is_svlan;
6938 - ret = stmmac_vlan_update(priv, num_svlans);
6941 + num_double_vlans = priv->num_double_vlans - is_double;
6942 + ret = stmmac_vlan_update(priv, num_double_vlans);
6939 6943 if (ret) {
6940 6944 set_bit(vid, priv->active_vlans);
6941 6945 goto del_vlan_error;
@@ -6945,12 +6949,12 @@ static int stmmac_vlan_rx_kill_vid(struct net_device *ndev, __be16 proto, u16 vi
6945 6949 ret = stmmac_del_hw_vlan_rx_fltr(priv, ndev, priv->hw, proto, vid);
6946 6950 if (ret) {
6947 6951 set_bit(vid, priv->active_vlans);
6948 - stmmac_vlan_update(priv, priv->num_svlans);
6952 + stmmac_vlan_update(priv, priv->num_double_vlans);
6949 6953 goto del_vlan_error;
6950 6954 }
6951 6955 }
6952 6956
6953 - priv->num_svlans = num_svlans;
6957 + priv->num_double_vlans = num_double_vlans;
6954 6958
6955 6959 del_vlan_error:
6956 6960 pm_runtime_put(priv->device);
@@ -6966,7 +6970,7 @@ static void stmmac_vlan_restore(struct stmmac_priv *priv)
6966 6970 if (priv->hw->num_vlan)
6967 6971 stmmac_restore_hw_vlan_rx_fltr(priv, priv->dev, priv->hw);
6968 6972
6969 - stmmac_vlan_update(priv, priv->num_svlans);
6973 + stmmac_vlan_update(priv, priv->num_double_vlans);
6970 6974 }
6971 6975
6972 6976 static int stmmac_bpf(struct net_device *dev, struct netdev_bpf *bpf)
@@ -8005,18 +8009,14 @@ static int __stmmac_dvr_probe(struct device *device,
8005 8009 ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
8006 8010 #ifdef STMMAC_VLAN_TAG_USED
8007 8011 /* Both mac100 and gmac support receive VLAN tag detection */
8008 - ndev->features |= NETIF_F_HW_VLAN_CTAG_RX;
8009 - if (priv->plat->core_type == DWMAC_CORE_XGMAC)
8010 - ndev->features |= NETIF_F_HW_VLAN_STAG_RX;
8011 -
8012 + ndev->features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX;
8012 8013 if (dwmac_is_xmac(priv->plat->core_type)) {
8013 8014 ndev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
8014 8015 priv->hw->hw_vlan_en = true;
8015 8016 }
8016 8017 if (priv->dma_cap.vlhash) {
8017 8018 ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
8018 - if (priv->plat->core_type == DWMAC_CORE_XGMAC)
8019 - ndev->features |= NETIF_F_HW_VLAN_STAG_FILTER;
8019 + ndev->features |= NETIF_F_HW_VLAN_STAG_FILTER;
8020 8020 }
8021 8021 if (priv->dma_cap.vlins)
8022 8022 ndev->features |= NETIF_F_HW_VLAN_CTAG_TX;
modified drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -243,7 +243,7 @@ struct stmmac_test_priv {
243 243 int (*func)(struct sk_buff *skb, struct net_device *ndev,
244 244 struct packet_type *pt, struct net_device *orig_ndev);
245 245 bool capture_all;
246 - int svlan;
246 + int double_vlan;
247 247 int vlan_id;
248 248 int ok;
249 249 };
@@ -285,7 +285,7 @@ static int stmmac_test_loopback_validate(struct sk_buff *skb,
285 285 }
286 286
287 287 ihdr = ip_hdr(skb);
288 - if (tpriv->svlan)
288 + if (tpriv->double_vlan)
289 289 ihdr = (struct iphdr *)(skb_network_header(skb) + 4);
290 290
291 291 if (tpriv->packet->tcp) {
@@ -936,7 +936,7 @@ static int stmmac_test_vlan_validate(struct sk_buff *skb,
936 936 struct iphdr *ihdr;
937 937 u16 proto;
938 938
939 - proto = tpriv->svlan ? ETH_P_8021AD : ETH_P_8021Q;
939 + proto = tpriv->double_vlan ? ETH_P_8021AD : ETH_P_8021Q;
940 940
941 941 skb = skb_unshare(skb, GFP_ATOMIC);
942 942 if (!skb)
@@ -963,7 +963,7 @@ static int stmmac_test_vlan_validate(struct sk_buff *skb,
963 963 }
964 964
965 965 ihdr = ip_hdr(skb);
966 - if (tpriv->svlan)
966 + if (tpriv->double_vlan)
967 967 ihdr = (struct iphdr *)(skb_network_header(skb) + 4);
968 968 if (ihdr->protocol != IPPROTO_UDP)
969 969 goto out;
@@ -1080,7 +1080,7 @@ static int stmmac_test_vlanfilt_perfect(struct stmmac_priv *priv)
1080 1080 return ret;
1081 1081 }
1082 1082
1083 - static int __stmmac_test_svlanfilt(struct stmmac_priv *priv)
1083 + static int __stmmac_test_dvlanfilt(struct stmmac_priv *priv)
1084 1084 {
1085 1085 struct stmmac_packet_attrs attr = { };
1086 1086 struct stmmac_test_priv *tpriv;
@@ -1092,7 +1092,7 @@ static int __stmmac_test_svlanfilt(struct stmmac_priv *priv)
1092 1092 return -ENOMEM;
1093 1093
1094 1094 tpriv->ok = false;
1095 - tpriv->svlan = true;
1095 + tpriv->double_vlan = true;
1096 1096 init_completion(&tpriv->comp);
1097 1097
1098 1098 tpriv->pt.type = htons(ETH_P_8021Q);
@@ -1155,15 +1155,15 @@ cleanup:
1155 1155 return ret;
1156 1156 }
1157 1157
1158 - static int stmmac_test_svlanfilt(struct stmmac_priv *priv)
1158 + static int stmmac_test_dvlanfilt(struct stmmac_priv *priv)
1159 1159 {
1160 1160 if (!priv->dma_cap.vlhash)
1161 1161 return -EOPNOTSUPP;
1162 1162
1163 - return __stmmac_test_svlanfilt(priv);
1163 + return __stmmac_test_dvlanfilt(priv);
1164 1164 }
1165 1165
1166 - static int stmmac_test_svlanfilt_perfect(struct stmmac_priv *priv)
1166 + static int stmmac_test_dvlanfilt_perfect(struct stmmac_priv *priv)
1167 1167 {
1168 1168 int ret, prev_cap = priv->dma_cap.vlhash;
1169 1169
@@ -1171,7 +1171,7 @@ static int stmmac_test_svlanfilt_perfect(struct stmmac_priv *priv)
1171 1171 return -EOPNOTSUPP;
1172 1172
1173 1173 priv->dma_cap.vlhash = 0;
1174 - ret = __stmmac_test_svlanfilt(priv);
1174 + ret = __stmmac_test_dvlanfilt(priv);
1175 1175 priv->dma_cap.vlhash = prev_cap;
1176 1176
1177 1177 return ret;
@@ -1372,7 +1372,7 @@ static int stmmac_test_vlanoff_common(struct stmmac_priv *priv, bool svlan)
1372 1372 proto = svlan ? ETH_P_8021AD : ETH_P_8021Q;
1373 1373
1374 1374 tpriv->ok = false;
1375 - tpriv->svlan = svlan;
1375 + tpriv->double_vlan = svlan;
1376 1376 init_completion(&tpriv->comp);
1377 1377
1378 1378 tpriv->pt.type = svlan ? htons(ETH_P_8021Q) : htons(ETH_P_IP);
@@ -1960,11 +1960,11 @@ static const struct stmmac_test {
1960 1960 .name = "VLAN Filtering (perf) ",
1961 1961 .fn = stmmac_test_vlanfilt_perfect,
1962 1962 }, {
1963 - .name = "SVLAN Filtering ",
1964 - .fn = stmmac_test_svlanfilt,
1963 + .name = "Double VLAN Filter ",
1964 + .fn = stmmac_test_dvlanfilt,
1965 1965 }, {
1966 - .name = "SVLAN Filtering (perf) ",
1967 - .fn = stmmac_test_svlanfilt_perfect,
1966 + .name = "Double VLAN Filter (perf) ",
1967 + .fn = stmmac_test_dvlanfilt_perfect,
1968 1968 }, {
1969 1969 .name = "Flexible RX Parser ",
1970 1970 .fn = stmmac_test_rxp,
modified drivers/net/ethernet/stmicro/stmmac/stmmac_vlan.c
@@ -162,7 +162,7 @@ static void vlan_restore_hw_rx_fltr(struct net_device *dev,
162 162 }
163 163
164 164 static void vlan_update_hash(struct mac_device_info *hw, u32 hash,
165 - bool is_svlan)
165 + u16 perfect_match, bool is_double)
166 166 {
167 167 void __iomem *ioaddr = hw->pcsr;
168 168 u32 value;
@@ -173,17 +173,34 @@ static void vlan_update_hash(struct mac_device_info *hw, u32 hash,
173 173
174 174 if (hash) {
175 175 value |= VLAN_VTHM | VLAN_ETV;
176 - if (is_svlan) {
176 + if (is_double) {
177 + value |= VLAN_EDVLP;
177 178 value |= VLAN_ESVL;
178 179 value |= VLAN_DOVLTC;
179 180 } else {
181 + value &= ~VLAN_EDVLP;
180 182 value &= ~VLAN_ESVL;
181 183 value &= ~VLAN_DOVLTC;
182 184 }
183 185
184 186 writel(value, ioaddr + VLAN_TAG);
187 + } else if (perfect_match) {
188 + u32 value = VLAN_ETV;
189 +
190 + if (is_double) {
191 + value |= VLAN_EDVLP;
192 + value |= VLAN_ESVL;
193 + value |= VLAN_DOVLTC;
194 + } else {
195 + value &= ~VLAN_EDVLP;
196 + value &= ~VLAN_ESVL;
197 + value &= ~VLAN_DOVLTC;
198 + }
199 +
200 + writel(value | perfect_match, ioaddr + VLAN_TAG);
185 201 } else {
186 - value &= ~(VLAN_VTHM | VLAN_ETV | VLAN_ESVL);
202 + value &= ~(VLAN_VTHM | VLAN_ETV);
203 + value &= ~(VLAN_EDVLP | VLAN_ESVL);
187 204 value &= ~VLAN_DOVLTC;
188 205 value &= ~VLAN_VID;
189 206
@@ -219,7 +236,6 @@ static void vlan_set_hw_mode(struct mac_device_info *hw)
219 236 void __iomem *ioaddr = hw->pcsr;
220 237 u32 value = readl(ioaddr + VLAN_TAG);
221 238
222 - value |= VLAN_EDVLP;
223 239 value &= ~VLAN_TAG_CTRL_EVLS_MASK;
224 240
225 241 if (hw->hw_vlan_en)
@@ -235,7 +251,7 @@ static void vlan_set_hw_mode(struct mac_device_info *hw)
235 251 }
236 252
237 253 static void dwxgmac2_update_vlan_hash(struct mac_device_info *hw, u32 hash,
238 - bool is_svlan)
254 + u16 perfect_match, bool is_double)
239 255 {
240 256 void __iomem *ioaddr = hw->pcsr;
241 257
@@ -251,16 +267,41 @@ static void dwxgmac2_update_vlan_hash(struct mac_device_info *hw, u32 hash,
251 267 value = readl(ioaddr + VLAN_TAG);
252 268
253 269 value |= VLAN_VTHM | VLAN_ETV;
254 - if (is_svlan) {
270 + if (is_double) {
271 + value |= VLAN_EDVLP;
255 272 value |= VLAN_ESVL;
256 273 value |= VLAN_DOVLTC;
257 274 } else {
275 + value &= ~VLAN_EDVLP;
258 276 value &= ~VLAN_ESVL;
259 277 value &= ~VLAN_DOVLTC;
260 278 }
261 279
262 280 value &= ~VLAN_VID;
263 281 writel(value, ioaddr + VLAN_TAG);
282 + } else if (perfect_match) {
283 + u32 value = readl(ioaddr + XGMAC_PACKET_FILTER);
284 +
285 + value |= XGMAC_FILTER_VTFE;
286 +
287 + writel(value, ioaddr + XGMAC_PACKET_FILTER);
288 +
289 + value = readl(ioaddr + VLAN_TAG);
290 +
291 + value &= ~VLAN_VTHM;
292 + value |= VLAN_ETV;
293 + if (is_double) {
294 + value |= VLAN_EDVLP;
295 + value |= VLAN_ESVL;
296 + value |= VLAN_DOVLTC;
297 + } else {
298 + value &= ~VLAN_EDVLP;
299 + value &= ~VLAN_ESVL;
300 + value &= ~VLAN_DOVLTC;
301 + }
302 +
303 + value &= ~VLAN_VID;
304 + writel(value | perfect_match, ioaddr + VLAN_TAG);
264 305 } else {
265 306 u32 value = readl(ioaddr + XGMAC_PACKET_FILTER);
266 307
@@ -270,7 +311,8 @@ static void dwxgmac2_update_vlan_hash(struct mac_device_info *hw, u32 hash,
270 311
271 312 value = readl(ioaddr + VLAN_TAG);
272 313
273 - value &= ~(VLAN_VTHM | VLAN_ETV | VLAN_ESVL);
314 + value &= ~(VLAN_VTHM | VLAN_ETV);
315 + value &= ~(VLAN_EDVLP | VLAN_ESVL);
274 316 value &= ~VLAN_DOVLTC;
275 317 value &= ~VLAN_VID;
276 318
@@ -278,14 +320,6 @@ static void dwxgmac2_update_vlan_hash(struct mac_device_info *hw, u32 hash,
278 320 }
279 321 }
280 322
281 - static void dwxlgmac2_set_hw_vlan_mode(struct mac_device_info *hw)
282 - {
283 - void __iomem *ioaddr = hw->pcsr;
284 - u32 value = readl(ioaddr + VLAN_TAG);
285 -
286 - writel(value | VLAN_EDVLP, ioaddr + VLAN_TAG);
287 - }
288 -
289 323 const struct stmmac_vlan_ops dwmac_vlan_ops = {
290 324 .update_vlan_hash = vlan_update_hash,
291 325 .enable_vlan = vlan_enable,
@@ -299,7 +333,6 @@ const struct stmmac_vlan_ops dwmac_vlan_ops = {
299 333 const struct stmmac_vlan_ops dwxlgmac2_vlan_ops = {
300 334 .update_vlan_hash = dwxgmac2_update_vlan_hash,
301 335 .enable_vlan = vlan_enable,
302 - .set_hw_vlan_mode = dwxlgmac2_set_hw_vlan_mode,
303 336 };
304 337
305 338 const struct stmmac_vlan_ops dwxgmac210_vlan_ops = {
modified drivers/net/ethernet/xilinx/xilinx_axienet.h
@@ -523,9 +523,8 @@ struct skbuf_dma_descriptor {
523 523 * @stats_work: Work for reading the hardware statistics counters often enough
524 524 * to catch overflows.
525 525 * @dma_err_task: Work structure to process Axi DMA errors
526 - * @stopping: Set when we are about to stop the device: makes @dma_err_task
527 - * a no-op (legacy DMA path) and fences RX descriptor
528 - * resubmission in axienet_dma_rx_cb() (dmaengine path).
526 + * @stopping: Set when @dma_err_task shouldn't do anything because we are
527 + * about to stop the device.
529 528 * @tx_irq: Axidma TX IRQ number
530 529 * @rx_irq: Axidma RX IRQ number
531 530 * @eth_irq: Ethernet core IRQ number
@@ -546,7 +545,6 @@ struct skbuf_dma_descriptor {
546 545 * @tx_ring_tail: TX skb ring buffer tail index.
547 546 * @rx_ring_head: RX skb ring buffer head index.
548 547 * @rx_ring_tail: RX skb ring buffer tail index.
549 - * @rx_submit_lock: Protects RX ring resubmission vs teardown in dmaengine path.
550 548 */
551 549 struct axienet_local {
552 550 struct net_device *ndev;
@@ -628,7 +626,6 @@ struct axienet_local {
628 626 int tx_ring_tail;
629 627 int rx_ring_head;
630 628 int rx_ring_tail;
631 - spinlock_t rx_submit_lock;
632 629 };
633 630
634 631 /**
modified drivers/net/ethernet/xilinx/xilinx_axienet_main.c
@@ -881,7 +881,6 @@ static void axienet_dma_tx_cb(void *data, const struct dmaengine_result *result)
881 881 u64_stats_update_end(&lp->tx_stat_sync);
882 882 dma_unmap_sg(lp->dev, skbuf_dma->sgl, skbuf_dma->sg_len, DMA_TO_DEVICE);
883 883 dev_consume_skb_any(skbuf_dma->skb);
884 - skbuf_dma->skb = NULL;
885 884 netif_txq_completed_wake(txq, 1, len,
886 885 CIRC_SPACE(lp->tx_ring_head, lp->tx_ring_tail, TX_BD_NUM_MAX),
887 886 2);
@@ -1172,7 +1171,6 @@ static void axienet_dma_rx_cb(void *data, const struct dmaengine_result *result)
1172 1171 &meta_max_len);
1173 1172 dma_unmap_single(lp->dev, skbuf_dma->dma_address, lp->max_frm_size,
1174 1173 DMA_FROM_DEVICE);
1175 - skbuf_dma->skb = NULL;
1176 1174
1177 1175 if (IS_ERR(app_metadata)) {
1178 1176 if (net_ratelimit())
@@ -1195,17 +1193,10 @@ static void axienet_dma_rx_cb(void *data, const struct dmaengine_result *result)
1195 1193 u64_stats_update_end(&lp->rx_stat_sync);
1196 1194
1197 1195 rx_submit:
1198 - spin_lock(&lp->rx_submit_lock);
1199 - if (lp->stopping) {
1200 - spin_unlock(&lp->rx_submit_lock);
1201 - return;
1202 - }
1203 -
1204 1196 for (i = 0; i < CIRC_SPACE(lp->rx_ring_head, lp->rx_ring_tail,
1205 1197 RX_BUF_NUM_DEFAULT); i++)
1206 1198 axienet_rx_submit_desc(lp->ndev);
1207 1199 dma_async_issue_pending(lp->rx_chan);
1208 - spin_unlock(&lp->rx_submit_lock);
1209 1200 }
1210 1201
1211 1202 /**
@@ -1550,7 +1541,6 @@ static int axienet_init_dmaengine(struct net_device *ndev)
1550 1541 lp->tx_ring_head = 0;
1551 1542 lp->rx_ring_tail = 0;
1552 1543 lp->rx_ring_head = 0;
1553 - lp->stopping = false;
1554 1544 lp->tx_skb_ring = kzalloc_objs(*lp->tx_skb_ring, TX_BD_NUM_MAX);
1555 1545 if (!lp->tx_skb_ring) {
1556 1546 ret = -ENOMEM;
@@ -1762,42 +1752,20 @@ static int axienet_stop(struct net_device *ndev)
1762 1752 free_irq(lp->rx_irq, ndev);
1763 1753 axienet_dma_bd_release(ndev);
1764 1754 } else {
1765 - struct skbuf_dma_descriptor *skbuf_dma;
1766 -
1767 - spin_lock_bh(&lp->rx_submit_lock);
1768 - lp->stopping = true;
1769 - spin_unlock_bh(&lp->rx_submit_lock);
1770 -
1771 1755 dmaengine_terminate_sync(lp->tx_chan);
1756 + dmaengine_synchronize(lp->tx_chan);
1772 1757 dmaengine_terminate_sync(lp->rx_chan);
1758 + dmaengine_synchronize(lp->rx_chan);
1773 1759
1774 - dma_release_channel(lp->rx_chan);
1775 - dma_release_channel(lp->tx_chan);
1776 -
1777 - /* Unmap and free any buffer the terminate did not reclaim, so it
1778 - * is not leaked; a non-NULL skb marks such a slot.
1779 - */
1780 - for (i = 0; i < TX_BD_NUM_MAX; i++) {
1781 - skbuf_dma = lp->tx_skb_ring[i];
1782 - if (skbuf_dma && skbuf_dma->skb) {
1783 - dma_unmap_sg(lp->dev, skbuf_dma->sgl,
1784 - skbuf_dma->sg_len, DMA_TO_DEVICE);
1785 - dev_kfree_skb_any(skbuf_dma->skb);
1786 - }
1787 - kfree(skbuf_dma);
1788 - }
1760 + for (i = 0; i < TX_BD_NUM_MAX; i++)
1761 + kfree(lp->tx_skb_ring[i]);
1789 1762 kfree(lp->tx_skb_ring);
1790 -
1791 - for (i = 0; i < RX_BUF_NUM_DEFAULT; i++) {
1792 - skbuf_dma = lp->rx_skb_ring[i];
1793 - if (skbuf_dma && skbuf_dma->skb) {
1794 - dma_unmap_single(lp->dev, skbuf_dma->dma_address,
1795 - lp->max_frm_size, DMA_FROM_DEVICE);
1796 - dev_kfree_skb_any(skbuf_dma->skb);
1797 - }
1798 - kfree(skbuf_dma);
1799 - }
1763 + for (i = 0; i < RX_BUF_NUM_DEFAULT; i++)
1764 + kfree(lp->rx_skb_ring[i]);
1800 1765 kfree(lp->rx_skb_ring);
1766 +
1767 + dma_release_channel(lp->rx_chan);
1768 + dma_release_channel(lp->tx_chan);
1801 1769 }
1802 1770
1803 1771 netdev_reset_queue(ndev);
@@ -3097,7 +3065,6 @@ static int axienet_probe(struct platform_device *pdev)
3097 3065
3098 3066 spin_lock_init(&lp->rx_cr_lock);
3099 3067 spin_lock_init(&lp->tx_cr_lock);
3100 - spin_lock_init(&lp->rx_submit_lock);
3101 3068 INIT_WORK(&lp->rx_dim.work, axienet_rx_dim_work);
3102 3069 lp->rx_dim_enabled = true;
3103 3070 lp->rx_dim.profile_ix = 1;
modified drivers/net/pfcp.c
@@ -65,13 +65,6 @@ static int pfcp_encap_recv(struct sock *sk, struct sk_buff *skb)
65 65 goto drop;
66 66
67 67 unparsed = pfcp_hdr(skb);
68 - if (unparsed->flags & PFCP_SEID_FLAG) {
69 - if (unlikely(!pskb_may_pull(skb, PFCP_HLEN +
70 - offsetofend(struct pfcphdr_session,
71 - seid))))
72 - goto drop;
73 - unparsed = pfcp_hdr(skb);
74 - }
75 68
76 69 ip_tunnel_flags_zero(flags);
77 70 tun_dst = udp_tun_rx_dst(skb, sk->sk_family, flags, 0,
modified drivers/net/team/team_core.c
@@ -820,8 +820,7 @@ static struct list_head *__team_get_qom_list(struct team *team, u16 queue_id)
820 820 /*
821 821 * note: already called with rcu_read_lock
822 822 */
823 - static bool team_queue_override_transmit(struct team *team, struct sk_buff *skb,
824 - bool *tx_success)
823 + static bool team_queue_override_transmit(struct team *team, struct sk_buff *skb)
825 824 {
826 825 struct list_head *qom_list;
827 826 struct team_port *port;
@@ -829,11 +828,11 @@ static bool team_queue_override_transmit(struct team *team, struct sk_buff *skb,
829 828 if (!team->queue_override_enabled || !skb->queue_mapping)
830 829 return false;
831 830 qom_list = __team_get_qom_list(team, skb->queue_mapping);
832 - port = list_first_or_null_rcu(qom_list, struct team_port, qom_list);
833 - if (!port)
834 - return false;
835 - *tx_success = !team_dev_queue_xmit(team, port, skb);
836 - return true;
831 + list_for_each_entry_rcu(port, qom_list, qom_list) {
832 + if (!team_dev_queue_xmit(team, port, skb))
833 + return true;
834 + }
835 + return false;
837 836 }
838 837
839 838 static void __team_queue_override_port_del(struct team *team,
@@ -1865,7 +1864,8 @@ static netdev_tx_t team_xmit(struct sk_buff *skb, struct net_device *dev)
1865 1864 bool tx_success;
1866 1865 unsigned int len = skb->len;
1867 1866
1868 - if (!team_queue_override_transmit(team, skb, &tx_success))
1867 + tx_success = team_queue_override_transmit(team, skb);
1868 + if (!tx_success)
1869 1869 tx_success = READ_ONCE(team->ops.transmit)(team, skb);
1870 1870 if (tx_success) {
1871 1871 struct team_pcpu_stats *pcpu_stats;
modified drivers/net/team/team_mode_broadcast.c
@@ -37,8 +37,6 @@ static bool bc_transmit(struct team *team, struct sk_buff *skb)
37 37 ret = !team_dev_queue_xmit(team, last, skb);
38 38 if (!sum_ret)
39 39 sum_ret = ret;
40 - } else {
41 - dev_kfree_skb_any(skb);
42 40 }
43 41 return sum_ret;
44 42 }
modified drivers/net/tun.c
@@ -1897,7 +1897,12 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
1897 1897 }
1898 1898 }
1899 1899
1900 - skb->dev = tun->dev;
1900 + if (tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, &hdr)) {
1901 + atomic_long_inc(&tun->rx_frame_errors);
1902 + err = -EINVAL;
1903 + goto free_skb;
1904 + }
1905 +
1901 1906 switch (tun->flags & TUN_TYPE_MASK) {
1902 1907 case IFF_TUN:
1903 1908 if (tun->flags & IFF_NO_PI) {
@@ -1922,8 +1927,9 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
1922 1927 }
1923 1928 }
1924 1929
1925 - skb_reset_network_header(skb);
1930 + skb_reset_mac_header(skb);
1926 1931 skb->protocol = pi.proto;
1932 + skb->dev = tun->dev;
1927 1933 break;
1928 1934 case IFF_TAP:
1929 1935 if (!pskb_may_pull(skb, ETH_HLEN)) {
@@ -1931,19 +1937,10 @@ static ssize_t tun_get_user(struct tun_struct *tun, struct tun_file *tfile,
1931 1937 drop_reason = SKB_DROP_REASON_HDR_TRUNC;
1932 1938 goto drop;
1933 1939 }
1934 - skb_set_network_header(skb, ETH_HLEN);
1940 + skb->protocol = eth_type_trans(skb, tun->dev);
1935 1941 break;
1936 1942 }
1937 1943
1938 - if (tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, &hdr)) {
1939 - atomic_long_inc(&tun->rx_frame_errors);
1940 - err = -EINVAL;
1941 - goto free_skb;
1942 - }
1943 -
1944 - if ((tun->flags & TUN_TYPE_MASK) == IFF_TAP)
1945 - skb->protocol = eth_type_trans(skb, tun->dev);
1946 -
1947 1944 /* copy skb_ubuf_info for callback when skb has no error */
1948 1945 if (zerocopy) {
1949 1946 skb_zcopy_init(skb, msg_control);
@@ -2603,8 +2600,6 @@ build:
2603 2600
2604 2601 features = tun_vnet_hdr_guest_features(READ_ONCE(tun->vnet_hdr_sz));
2605 2602 tnl_hdr = (struct virtio_net_hdr_v1_hash_tunnel *)gso;
2606 - skb->dev = tun->dev;
2607 - skb_set_network_header(skb, ETH_HLEN);
2608 2603 if (tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, tnl_hdr)) {
2609 2604 atomic_long_inc(&tun->rx_frame_errors);
2610 2605 kfree_skb(skb);
modified drivers/net/usb/ax88179_178a.c
@@ -1457,11 +1457,11 @@ static int ax88179_rx_fixup(struct usbnet *dev, struct sk_buff *skb)
1457 1457 return 1;
1458 1458 }
1459 1459
1460 - ax_skb = netdev_alloc_skb_ip_align(dev->net, pkt_len - 2);
1460 + ax_skb = netdev_alloc_skb_ip_align(dev->net, pkt_len);
1461 1461 if (!ax_skb)
1462 1462 return 0;
1463 - skb_put(ax_skb, pkt_len - 2);
1464 - memcpy(ax_skb->data, skb->data + 2, pkt_len - 2);
1463 + skb_put(ax_skb, pkt_len);
1464 + memcpy(ax_skb->data, skb->data + 2, pkt_len);
1465 1465
1466 1466 ax88179_rx_checksum(ax_skb, pkt_hdr);
1467 1467 usbnet_skb_return(dev, ax_skb);
modified drivers/net/veth.c
@@ -1415,7 +1415,6 @@ static int veth_open(struct net_device *dev)
1415 1415 }
1416 1416
1417 1417 veth_set_xdp_features(dev);
1418 - veth_set_xdp_features(peer);
1419 1418
1420 1419 return 0;
1421 1420 }
modified drivers/net/virtio_net.c
@@ -2515,8 +2515,6 @@ static void virtnet_receive_done(struct virtnet_info *vi, struct receive_queue *
2515 2515 goto frame_err;
2516 2516 }
2517 2517
2518 - skb->dev = dev;
2519 - skb_set_network_header(skb, ETH_HLEN);
2520 2518 if (virtio_net_hdr_tnl_to_skb(skb, &hdr->tnl_hdr, vi->rx_tnl,
2521 2519 vi->rx_tnl_csum,
2522 2520 virtio_is_little_endian(vi->vdev))) {
modified drivers/net/wireguard/noise.c
@@ -784,11 +784,10 @@ wg_noise_handshake_consume_response(struct message_handshake_response *src,
784 784
785 785 /* Success! Copy everything to peer */
786 786 down_write(&handshake->lock);
787 - /* Check that the state is the same and that this is still the
788 - * initiation we started with, while we have an exclusive lock.
787 + /* It's important to check that the state is still the same, while we
788 + * have an exclusive lock.
789 789 */
790 - if (handshake->state != state ||
791 - crypto_memneq(handshake->ephemeral_private, ephemeral_private, NOISE_PUBLIC_KEY_LEN)) {
790 + if (handshake->state != state) {
792 791 up_write(&handshake->lock);
793 792 goto fail;
794 793 }
modified drivers/net/wireguard/queueing.h
@@ -78,14 +78,12 @@ static inline void wg_reset_packet(struct sk_buff *skb, bool encapsulating)
78 78 u8 l4_hash = skb->l4_hash;
79 79 u8 sw_hash = skb->sw_hash;
80 80 u32 hash = skb->hash;
81 - u8 tstamp_type = skb->tstamp_type;
82 81 skb_scrub_packet(skb, true);
83 82 memset(&skb->headers, 0, sizeof(skb->headers));
84 83 if (encapsulating) {
85 84 skb->l4_hash = l4_hash;
86 85 skb->sw_hash = sw_hash;
87 86 skb->hash = hash;
88 - skb->tstamp_type = tstamp_type;
89 87 }
90 88 skb->queue_mapping = 0;
91 89 skb->nohdr = 0;
modified drivers/net/wireless/ath/ath12k/core.c
@@ -1776,6 +1776,29 @@ int ath12k_core_pre_init(struct ath12k_base *ab)
1776 1776 return 0;
1777 1777 }
1778 1778
1779 + static int ath12k_core_panic_handler(struct notifier_block *nb,
1780 + unsigned long action, void *data)
1781 + {
1782 + struct ath12k_base *ab = container_of(nb, struct ath12k_base,
1783 + panic_nb);
1784 +
1785 + return ath12k_hif_panic_handler(ab);
1786 + }
1787 +
1788 + static int ath12k_core_panic_notifier_register(struct ath12k_base *ab)
1789 + {
1790 + ab->panic_nb.notifier_call = ath12k_core_panic_handler;
1791 +
1792 + return atomic_notifier_chain_register(&panic_notifier_list,
1793 + &ab->panic_nb);
1794 + }
1795 +
1796 + static void ath12k_core_panic_notifier_unregister(struct ath12k_base *ab)
1797 + {
1798 + atomic_notifier_chain_unregister(&panic_notifier_list,
1799 + &ab->panic_nb);
1800 + }
1801 +
1779 1802 static inline
1780 1803 bool ath12k_core_hw_group_create_ready(struct ath12k_hw_group *ag)
1781 1804 {
@@ -2191,13 +2214,18 @@ int ath12k_core_init(struct ath12k_base *ab)
2191 2214 struct ath12k_hw_group *ag;
2192 2215 int ret;
2193 2216
2217 + ret = ath12k_core_panic_notifier_register(ab);
2218 + if (ret)
2219 + ath12k_warn(ab, "failed to register panic handler: %d\n", ret);
2220 +
2194 2221 mutex_lock(&ath12k_hw_group_mutex);
2195 2222
2196 2223 ag = ath12k_core_hw_group_assign(ab);
2197 2224 if (!ag) {
2198 2225 mutex_unlock(&ath12k_hw_group_mutex);
2199 2226 ath12k_warn(ab, "unable to get hw group\n");
2200 - return -ENODEV;
2227 + ret = -ENODEV;
2228 + goto err_unregister_notifier;
2201 2229 }
2202 2230
2203 2231 mutex_unlock(&ath12k_hw_group_mutex);
@@ -2222,6 +2250,8 @@ int ath12k_core_init(struct ath12k_base *ab)
2222 2250
2223 2251 err_unassign_hw_group:
2224 2252 ath12k_core_hw_group_unassign(ab);
2253 + err_unregister_notifier:
2254 + ath12k_core_panic_notifier_unregister(ab);
2225 2255
2226 2256 return ret;
2227 2257 }
@@ -2230,6 +2260,7 @@ void ath12k_core_deinit(struct ath12k_base *ab)
2230 2260 {
2231 2261 ath12k_core_hw_group_destroy(ab->ag);
2232 2262 ath12k_core_hw_group_unassign(ab);
2263 + ath12k_core_panic_notifier_unregister(ab);
2233 2264 }
2234 2265
2235 2266 void ath12k_core_free(struct ath12k_base *ab)
modified drivers/net/wireless/ath/ath12k/core.h
@@ -15,6 +15,7 @@
15 15 #include <linux/ctype.h>
16 16 #include <linux/firmware.h>
17 17 #include <linux/of_reserved_mem.h>
18 + #include <linux/panic_notifier.h>
18 19 #include <linux/average.h>
19 20 #include <linux/of.h>
20 21 #include <linux/rhashtable.h>
@@ -1138,6 +1139,8 @@ struct ath12k_base {
1138 1139
1139 1140 #endif /* CONFIG_ACPI */
1140 1141
1142 + struct notifier_block panic_nb;
1143 +
1141 1144 struct ath12k_hw_group *ag;
1142 1145 struct ath12k_wsi_info wsi_info;
1143 1146 enum ath12k_qmi_firmware_mode fw_mode;
modified drivers/net/wireless/ath/ath12k/hif.h
@@ -30,6 +30,7 @@ struct ath12k_hif_ops {
30 30 void (*ce_irq_enable)(struct ath12k_base *ab);
31 31 void (*ce_irq_disable)(struct ath12k_base *ab);
32 32 void (*get_ce_msi_idx)(struct ath12k_base *ab, u32 ce_id, u32 *msi_idx);
33 + int (*panic_handler)(struct ath12k_base *ab);
33 34 void (*coredump_download)(struct ath12k_base *ab);
34 35 };
35 36
@@ -148,6 +149,14 @@ static inline void ath12k_hif_power_down(struct ath12k_base *ab, bool is_suspend
148 149 ab->hif.ops->power_down(ab, is_suspend);
149 150 }
150 151
152 + static inline int ath12k_hif_panic_handler(struct ath12k_base *ab)
153 + {
154 + if (!ab->hif.ops->panic_handler)
155 + return NOTIFY_DONE;
156 +
157 + return ab->hif.ops->panic_handler(ab);
158 + }
159 +
151 160 static inline void ath12k_hif_coredump_download(struct ath12k_base *ab)
152 161 {
153 162 if (ab->hif.ops->coredump_download)
modified drivers/net/wireless/ath/ath12k/pci.c
@@ -1484,6 +1484,13 @@ void ath12k_pci_power_down(struct ath12k_base *ab, bool is_suspend)
1484 1484 ath12k_pci_sw_reset(ab_pci->ab, false);
1485 1485 }
1486 1486
1487 + static int ath12k_pci_panic_handler(struct ath12k_base *ab)
1488 + {
1489 + ath12k_pci_sw_reset(ab, false);
1490 +
1491 + return NOTIFY_OK;
1492 + }
1493 +
1487 1494 static const struct ath12k_hif_ops ath12k_pci_hif_ops = {
1488 1495 .start = ath12k_pci_start,
1489 1496 .stop = ath12k_pci_stop,
@@ -1501,6 +1508,7 @@ static const struct ath12k_hif_ops ath12k_pci_hif_ops = {
1501 1508 .ce_irq_enable = ath12k_pci_hif_ce_irq_enable,
1502 1509 .ce_irq_disable = ath12k_pci_hif_ce_irq_disable,
1503 1510 .get_ce_msi_idx = ath12k_pci_get_ce_msi_idx,
1511 + .panic_handler = ath12k_pci_panic_handler,
1504 1512 #ifdef CONFIG_ATH12K_COREDUMP
1505 1513 .coredump_download = ath12k_pci_coredump_download,
1506 1514 #endif
modified drivers/net/wireless/broadcom/brcm80211/brcmfmac/core.c
@@ -1489,31 +1489,8 @@ void brcmf_detach(struct device *dev)
1489 1489 brcmf_bus_change_state(bus_if, BRCMF_BUS_DOWN);
1490 1490 /* make sure primary interface removed last */
1491 1491 for (i = BRCMF_MAX_IFS - 1; i > -1; i--) {
1492 - struct brcmf_if *ifp = drvr->iflist[i];
1493 -
1494 - if (!ifp)
1495 - continue;
1496 -
1497 - if (ifp->ndev) {
1498 - brcmf_remove_interface(ifp, false);
1499 - continue;
1500 - }
1501 -
1502 - /* The P2P device interface has no netdev. Its removal can
1503 - * race with NL80211_CMD_DEL_INTERFACE issued by a user space
1504 - * process that is exiting (e.g. wpa_supplicant), which ends
1505 - * in brcmf_p2p_del_vif() under RTNL and the wiphy mutex. If
1506 - * both paths remove the interface, the wdev is unregistered
1507 - * twice and the vif is used after being freed. Take the same
1508 - * locks and re-read iflist, so only one path removes it.
1509 - */
1510 - rtnl_lock();
1511 - wiphy_lock(drvr->wiphy);
1512 - ifp = drvr->iflist[i];
1513 - if (ifp)
1514 - brcmf_remove_interface(ifp, true);
1515 - wiphy_unlock(drvr->wiphy);
1516 - rtnl_unlock();
1492 + if (drvr->iflist[i])
1493 + brcmf_remove_interface(drvr->iflist[i], false);
1517 1494 }
1518 1495 brcmf_bus_stop(drvr->bus_if);
1519 1496
modified drivers/net/wireless/marvell/libertas/tx.c
@@ -117,6 +117,13 @@ netdev_tx_t lbs_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
117 117 if (priv->wdev->iftype == NL80211_IFTYPE_MONITOR) {
118 118 struct tx_radiotap_hdr *rtap_hdr = (void *)skb->data;
119 119
120 + if (skb->len < sizeof(*rtap_hdr) + 4 + ETH_ALEN) {
121 + lbs_deb_tx("tx err: short monitor frame %u\n", skb->len);
122 + dev->stats.tx_dropped++;
123 + dev->stats.tx_errors++;
124 + goto free;
125 + }
126 +
120 127 /* set txpd fields from the radiotap header */
121 128 txpd->tx_control = cpu_to_le32(convert_radiotap_rate_to_mv(rtap_hdr->rate));
122 129
modified drivers/net/wireless/mediatek/mt76/mt76.h
@@ -1426,13 +1426,6 @@ mtxq_to_txq(struct mt76_txq *mtxq)
1426 1426 return container_of(ptr, struct ieee80211_txq, drv_priv);
1427 1427 }
1428 1428
1429 - /* peer-wide state uses the wcid of the primary link */
1430 - static inline struct mt76_wcid *
1431 - mt76_wcid_primary(struct mt76_wcid *wcid)
1432 - {
1433 - return wcid->def_wcid ? wcid->def_wcid : wcid;
1434 - }
1435 -
1436 1429 static inline struct ieee80211_sta *
1437 1430 wcid_to_sta(struct mt76_wcid *wcid)
1438 1431 {
modified drivers/net/wireless/mediatek/mt76/mt7603/init.c
@@ -230,7 +230,6 @@ mt7603_mac_init(struct mt7603_dev *dev)
230 230
231 231 eth_broadcast_addr(bc_addr);
232 232 mt7603_wtbl_init(dev, MT7603_WTBL_RESERVED, -1, bc_addr);
233 - mt76_wcid_init(&dev->global_sta.wcid, 0);
234 233 dev->global_sta.wcid.idx = MT7603_WTBL_RESERVED;
235 234 rcu_assign_pointer(dev->mt76.wcid[MT7603_WTBL_RESERVED],
236 235 &dev->global_sta.wcid);
modified drivers/net/wireless/mediatek/mt76/mt7915/init.c
@@ -1238,12 +1238,6 @@ static void mt7915_unregister_ext_phy(struct mt7915_dev *dev)
1238 1238
1239 1239 static void mt7915_stop_hardware(struct mt7915_dev *dev)
1240 1240 {
1241 - int i;
1242 -
1243 - mt76_for_each_q_rx(&dev->mt76, i) {
1244 - if (!mt76_queue_is_wed_rro(&dev->mt76.q_rx[i]))
1245 - napi_disable(&dev->mt76.napi[i]);
1246 - }
1247 1241 mt7915_mcu_exit(dev);
1248 1242 mt76_connac2_tx_token_put(&dev->mt76);
1249 1243 mt7915_dma_cleanup(dev);
modified drivers/net/wireless/mediatek/mt76/mt7915/main.c
@@ -805,7 +805,6 @@ __mt7915_drop_sta(void *ptr, u8 *mac, struct ieee80211_vif *vif)
805 805
806 806 msta = (struct mt7915_sta *)sta->drv_priv;
807 807 mt7915_mcu_add_sta(data->dev, vif, sta, CONN_STATE_DISCONNECT, false);
808 - msta->wcid.tx_info &= ~MT_WCID_TX_INFO_SET;
809 808 msta->wcid.sta_disabled = 1;
810 809 msta->wcid.sta = 0;
811 810 }
@@ -872,7 +871,6 @@ int mt7915_mac_sta_event(struct mt76_dev *mdev, struct ieee80211_vif *vif,
872 871 mutex_unlock(&dev->mt76.mutex);
873 872
874 873 mt7915_mcu_add_sta(dev, vif, sta, CONN_STATE_DISCONNECT, false);
875 - msta->wcid.tx_info &= ~MT_WCID_TX_INFO_SET;
876 874 msta->wcid.sta_disabled = 1;
877 875 msta->wcid.sta = 0;
878 876 return 0;
modified drivers/net/wireless/mediatek/mt76/mt7925/mac.c
@@ -798,8 +798,7 @@ mt7925_mac_write_txwi(struct mt76_dev *dev, __le32 *txwi,
798 798 val = FIELD_PREP(MT_TXD1_WLAN_IDX, wcid->idx) |
799 799 FIELD_PREP(MT_TXD1_OWN_MAC, omac_idx);
800 800
801 - /* 0xff means BAND_AUTO to the firmware, and TGID cannot encode it */
802 - if (band_idx && band_idx != 0xff)
801 + if (band_idx)
803 802 val |= FIELD_PREP(MT_TXD1_TGID, band_idx);
804 803
805 804 txwi[1] = cpu_to_le32(val);
modified drivers/net/wireless/mediatek/mt76/mt7925/main.c
@@ -2294,18 +2294,6 @@ mt7925_change_vif_links(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2294 2294
2295 2295 mvif->valid_links = new_links;
2296 2296
2297 - /* Restore the legacy BSS after disabling MLO */
2298 - if (old_links && !new_links) {
2299 - mt792x_mac_link_bss_remove(dev, &mvif->bss_conf,
2300 - &mvif->sta.deflink);
2301 - err = mt7925_mac_link_bss_add(dev, &vif->bss_conf,
2302 - &mvif->sta.deflink);
2303 - if (err < 0) {
2304 - mt792x_mutex_release(dev);
2305 - return err;
2306 - }
2307 - }
2308 -
2309 2297 mt792x_mutex_release(dev);
2310 2298
2311 2299 return 0;
modified drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.c
@@ -108,98 +108,68 @@ mt792x_asar_acpi_read_mtcl(struct mt792x_dev *dev, u8 **table, u8 *version)
108 108 return ret;
109 109 }
110 110
111 - /* A table's layout is decided by the version byte in MTCL, but some firmware
112 - * labels a version 2 table as version 1. Accept whichever layout the table
113 - * actually has: for every accepted entry count the two do not overlap, since
114 - * one is 6 + 5n bytes and the other 7 + 7n.
115 - */
116 - static bool
117 - mt792x_asar_fits(u8 *table, int len, int prelen, int sarlen, int nr_off,
118 - int min, int max)
119 - {
120 - int tblcnt;
121 -
122 - if (len < prelen || (len - prelen) % sarlen)
123 - return false;
124 -
125 - tblcnt = (len - prelen) / sarlen;
126 - if (tblcnt < min || tblcnt > max)
127 - return false;
128 -
129 - return tblcnt == table[nr_off];
130 - }
131 -
132 111 /* MTDS : Dynamic SAR Power Table */
133 112 static int
134 - mt792x_asar_acpi_read_mtds(struct mt792x_dev *dev, u8 **table, u8 version,
135 - u8 *used)
113 + mt792x_asar_acpi_read_mtds(struct mt792x_dev *dev, u8 **table, u8 version)
136 114 {
137 - int len, ret;
138 - u8 *t;
115 + int len, ret, sarlen, prelen, tblcnt;
116 + bool enable;
139 117
140 118 ret = mt792x_acpi_read(dev, MT792x_ACPI_MTDS, table, &len);
141 119 if (ret)
142 120 return ret;
143 121
144 - t = *table;
145 -
146 122 /* Table content validation */
147 - if (mt792x_asar_fits(t, len, sizeof(struct mt792x_asar_dyn),
148 - sizeof(struct mt792x_asar_dyn_limit),
149 - offsetof(struct mt792x_asar_dyn, nr_tbl),
150 - MT792x_ASAR_MIN_DYN, MT792x_ASAR_MAX_DYN))
151 - *used = 1;
152 - else if (mt792x_asar_fits(t, len, sizeof(struct mt792x_asar_dyn_v2),
153 - sizeof(struct mt792x_asar_dyn_limit_v2),
154 - offsetof(struct mt792x_asar_dyn_v2, nr_tbl),
155 - MT792x_ASAR_MIN_DYN, MT792x_ASAR_MAX_DYN))
156 - *used = 2;
157 - else
123 + switch (version) {
124 + case 1:
125 + enable = ((struct mt792x_asar_dyn *)*table)->enable;
126 + sarlen = sizeof(struct mt792x_asar_dyn_limit);
127 + prelen = sizeof(struct mt792x_asar_dyn);
128 + break;
129 + case 2:
130 + enable = ((struct mt792x_asar_dyn_v2 *)*table)->enable;
131 + sarlen = sizeof(struct mt792x_asar_dyn_limit_v2);
132 + prelen = sizeof(struct mt792x_asar_dyn_v2);
133 + break;
134 + default:
158 135 return -EINVAL;
136 + }
159 137
160 - if (!t[offsetof(struct mt792x_asar_dyn, enable)])
138 + tblcnt = (len - prelen) / sarlen;
139 + if (!enable ||
140 + tblcnt > MT792x_ASAR_MAX_DYN || tblcnt < MT792x_ASAR_MIN_DYN)
161 141 return -EINVAL;
162 142
163 - if (version && *used != version)
164 - dev_info(dev->mt76.dev,
165 - "MTDS is v%u, MTCL says v%u; using v%u\n",
166 - *used, version, *used);
167 -
168 143 return 0;
169 144 }
170 145
171 146 /* MTGS : Geo SAR Power Table */
172 147 static int
173 - mt792x_asar_acpi_read_mtgs(struct mt792x_dev *dev, u8 **table, u8 version,
174 - u8 *used)
148 + mt792x_asar_acpi_read_mtgs(struct mt792x_dev *dev, u8 **table, u8 version)
175 149 {
176 - int len, ret;
177 - u8 *t;
150 + int len, ret, sarlen, prelen, tblcnt;
178 151
179 152 ret = mt792x_acpi_read(dev, MT792x_ACPI_MTGS, table, &len);
180 153 if (ret)
181 154 return ret;
182 155
183 - t = *table;
184 -
185 156 /* Table content validation */
186 - if (mt792x_asar_fits(t, len, sizeof(struct mt792x_asar_geo),
187 - sizeof(struct mt792x_asar_geo_limit),
188 - offsetof(struct mt792x_asar_geo, nr_tbl),
189 - MT792x_ASAR_MIN_GEO, MT792x_ASAR_MAX_GEO))
190 - *used = 1;
191 - else if (mt792x_asar_fits(t, len, sizeof(struct mt792x_asar_geo_v2),
192 - sizeof(struct mt792x_asar_geo_limit_v2),
193 - offsetof(struct mt792x_asar_geo_v2, nr_tbl),
194 - MT792x_ASAR_MIN_GEO, MT792x_ASAR_MAX_GEO))
195 - *used = 2;
196 - else
157 + switch (version) {
158 + case 1:
159 + sarlen = sizeof(struct mt792x_asar_geo_limit);
160 + prelen = sizeof(struct mt792x_asar_geo);
161 + break;
162 + case 2:
163 + sarlen = sizeof(struct mt792x_asar_geo_limit_v2);
164 + prelen = sizeof(struct mt792x_asar_geo_v2);
165 + break;
166 + default:
197 167 return -EINVAL;
168 + }
198 169
199 - if (version && *used != version)
200 - dev_info(dev->mt76.dev,
201 - "MTGS is v%u, MTCL says v%u; using v%u\n",
202 - *used, version, *used);
170 + tblcnt = (len - prelen) / sarlen;
171 + if (tblcnt > MT792x_ASAR_MAX_GEO || tblcnt < MT792x_ASAR_MIN_GEO)
172 + return -EINVAL;
203 173
204 174 return 0;
205 175 }
@@ -235,16 +205,14 @@ int mt792x_init_acpi_sar(struct mt792x_dev *dev)
235 205 asar->countrylist = NULL;
236 206 }
237 207
238 - ret = mt792x_asar_acpi_read_mtds(dev, (u8 **)&asar->dyn, asar->ver,
239 - &asar->dyn_ver);
208 + ret = mt792x_asar_acpi_read_mtds(dev, (u8 **)&asar->dyn, asar->ver);
240 209 if (ret) {
241 210 devm_kfree(dev->mt76.dev, asar->dyn);
242 211 asar->dyn = NULL;
243 212 }
244 213
245 214 /* MTGS is optional */
246 - ret = mt792x_asar_acpi_read_mtgs(dev, (u8 **)&asar->geo, asar->ver,
247 - &asar->geo_ver);
215 + ret = mt792x_asar_acpi_read_mtgs(dev, (u8 **)&asar->geo, asar->ver);
248 216 if (ret) {
249 217 devm_kfree(dev->mt76.dev, asar->geo);
250 218 asar->geo = NULL;
@@ -286,7 +254,7 @@ mt792x_asar_get_geo_pwr(struct mt792x_phy *phy,
286 254 break;
287 255 }
288 256
289 - if (asar->geo_ver == 1) {
257 + if (asar->ver == 1) {
290 258 band_pwr = &asar->geo->tbl[idx].band[0];
291 259 max = ARRAY_SIZE(asar->geo->tbl[idx].band);
292 260 } else {
@@ -311,18 +279,10 @@ mt792x_asar_get_geo_pwr(struct mt792x_phy *phy,
311 279 if (idx >= max)
312 280 return dyn_power;
313 281
314 - band_pwr += idx;
315 -
316 - /* Some OEM tables carry 0xff here; narrowed to s8 that is -1 and
317 - * wins the min() below. Take it as no limit.
318 - */
319 - if (band_pwr->pwr == 0xff)
320 - return dyn_power;
321 -
322 - geo_power = band_pwr->pwr;
282 + geo_power = (band_pwr + idx)->pwr;
283 + dyn_power += (band_pwr + idx)->offset;
323 284
324 - return min_t(int, geo_power,
325 - min_t(int, dyn_power + band_pwr->offset, 127));
285 + return min(geo_power, dyn_power);
326 286 }
327 287
328 288 static s8
@@ -337,7 +297,7 @@ mt792x_asar_range_pwr(struct mt792x_phy *phy,
337 297 if (!capa)
338 298 return 127;
339 299
340 - if (asar->dyn_ver == 1) {
300 + if (asar->ver == 1) {
341 301 limit = &asar->dyn->tbl[0].frp[0];
342 302 max = ARRAY_SIZE(asar->dyn->tbl[0].frp);
343 303 } else {
@@ -355,9 +315,7 @@ mt792x_asar_range_pwr(struct mt792x_phy *phy,
355 315 else
356 316 band = NL80211_BAND_2GHZ;
357 317
358 - /* 0xff: no dynamic limit, see mt792x_asar_get_geo_pwr() */
359 - return mt792x_asar_get_geo_pwr(phy, band,
360 - limit[idx] == 0xff ? 127 : limit[idx]);
318 + return mt792x_asar_get_geo_pwr(phy, band, limit[idx]);
361 319 }
362 320
363 321 int mt792x_init_acpi_sar_power(struct mt792x_phy *phy, bool set_default)
modified drivers/net/wireless/mediatek/mt76/mt792x_acpi_sar.h
@@ -105,8 +105,6 @@ struct mt792x_asar_fg {
105 105
106 106 struct mt792x_acpi_sar {
107 107 u8 ver;
108 - u8 dyn_ver;
109 - u8 geo_ver;
110 108 union {
111 109 struct mt792x_asar_dyn *dyn;
112 110 struct mt792x_asar_dyn_v2 *dyn_v2;
modified drivers/net/wireless/mediatek/mt76/mt7996/init.c
@@ -540,7 +540,6 @@ mt7996_init_wiphy(struct ieee80211_hw *hw, struct mtk_wed_device *wed)
540 540 ieee80211_hw_set(hw, NO_VIRTUAL_MONITOR);
541 541 ieee80211_hw_set(hw, SUPPORTS_MULTI_BSSID);
542 542 ieee80211_hw_set(hw, CHANCTX_STA_CSA);
543 - ieee80211_hw_set(hw, CONNECTION_MONITOR);
544 543
545 544 hw->max_tx_fragments = 4;
546 545 wiphy->txq_memory_limit = 32 << 20; /* 32 MiB */
@@ -1248,7 +1247,7 @@ static int mt7996_variant_fem_init(struct mt7996_dev *dev)
1248 1247 adie_ver = u32_get_bits(regval, MT_ADIE_VERSION_MASK);
1249 1248 idx = MT7976C_EFUSE_OFFSET % MT7996_EEPROM_BLOCK_SIZE;
1250 1249 is_7976c = adie_ver == 0x8a10 || adie_ver == 0x8b00 ||
1251 - adie_ver == 0x8c10 || (!ret && buf[idx] == 0xc);
1250 + adie_ver == 0x8c10 || buf[idx] == 0xc;
1252 1251
1253 1252 adie_id = u32_get_bits(regval, MT_ADIE_CHIP_ID_MASK);
1254 1253 if (adie_id == 0x7975 || adie_id == 0x7979 ||
modified drivers/net/wireless/mediatek/mt76/mt7996/main.c
@@ -310,14 +310,7 @@ int mt7996_vif_link_add(struct mt76_phy *mphy, struct ieee80211_vif *vif,
310 310 if (vif->type == NL80211_IFTYPE_AP)
311 311 return mt7996_mcu_mld_link_oper(dev, link_conf, link,
312 312 true);
313 -
314 - /* update the link address */
315 - ret = mt7996_mcu_add_dev_info(phy, vif, link_conf, mlink, true);
316 - if (ret)
317 - return ret;
318 -
319 - return mt7996_mcu_add_bss_info(phy, vif, link_conf, mlink,
320 - msta_link, true);
313 + return 0;
321 314 }
322 315
323 316 mlink->idx = __ffs64(~dev->mt76.vif_mask);
@@ -1433,7 +1426,6 @@ mt7996_mac_sta_event(struct mt7996_dev *dev, struct ieee80211_vif *vif,
1433 1426 else if (sta->mlo && links == BIT(link_id)) /* last link */
1434 1427 mt7996_mcu_teardown_mld_sta(dev, link,
1435 1428 msta_link);
1436 - msta_link->wcid.tx_info &= ~MT_WCID_TX_INFO_SET;
1437 1429 msta_link->wcid.sta_disabled = 1;
1438 1430 msta_link->wcid.sta = 0;
1439 1431 links = links & ~BIT(link_id);
modified drivers/net/wireless/mediatek/mt76/mt7996/mcu.h
@@ -284,9 +284,6 @@ struct mt7996_mcu_wed_rro_ba_delete_event {
284 284 __le16 len;
285 285
286 286 __le16 session_id;
287 - __le16 wlan_id;
288 - u8 tid;
289 - u8 __rsv1;
290 287 u8 __rsv2[2];
291 288 } __packed;
292 289
modified drivers/net/wireless/mediatek/mt76/tx.c
@@ -234,8 +234,6 @@ mt76_tx_check_non_aql(struct mt76_dev *dev, struct mt76_wcid *wcid,
234 234 if (!wcid || info->tx_time_est)
235 235 return;
236 236
237 - wcid = mt76_wcid_primary(wcid);
238 -
239 237 pending = atomic_dec_return(&wcid->non_aql_packets);
240 238 if (pending < 0)
241 239 atomic_cmpxchg(&wcid->non_aql_packets, pending, 0);
@@ -346,8 +344,7 @@ __mt76_tx_queue_skb(struct mt76_phy *phy, int qid, struct sk_buff *skb,
346 344 if (!non_aql)
347 345 return idx;
348 346
349 - /* the hardware can report the completion on a different link */
350 - pending = atomic_inc_return(&mt76_wcid_primary(wcid)->non_aql_packets);
347 + pending = atomic_inc_return(&wcid->non_aql_packets);
351 348 if (stop && pending >= MT_MAX_NON_AQL_PKT)
352 349 *stop = true;
353 350
@@ -509,8 +506,7 @@ mt76_txq_send_burst(struct mt76_phy *phy, struct mt76_queue *q,
509 506 return 0;
510 507 }
511 508
512 - if (atomic_read(&mt76_wcid_primary(wcid)->non_aql_packets) >=
513 - MT_MAX_NON_AQL_PKT)
509 + if (atomic_read(&wcid->non_aql_packets) >= MT_MAX_NON_AQL_PKT)
514 510 return 0;
515 511
516 512 skb = mt76_txq_dequeue(phy, mtxq);
@@ -607,8 +603,7 @@ mt76_txq_schedule_list(struct mt76_phy *phy, enum mt76_txq_id qid)
607 603 continue;
608 604 }
609 605
610 - if (atomic_read(&mt76_wcid_primary(wcid)->non_aql_packets) >=
611 - MT_MAX_NON_AQL_PKT)
606 + if (atomic_read(&wcid->non_aql_packets) >= MT_MAX_NON_AQL_PKT)
612 607 continue;
613 608 if (dev->queue_ops->tx_cleanup &&
614 609 q->queued + 2 * MT_TXQ_FREE_THR >= q->ndesc) {
@@ -680,8 +675,7 @@ mt76_txq_schedule_pending_wcid(struct mt76_phy *phy, struct mt76_wcid *wcid,
680 675 if ((dev->drv->drv_flags & MT_DRV_HW_MGMT_TXQ) &&
681 676 !(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) &&
682 677 !ieee80211_is_data_present(hdr->frame_control) &&
683 - (!(wcid->tx_info & MT_WCID_TX_INFO_SET) ||
684 - !ieee80211_is_bufferable_mmpdu(skb) ||
678 + (!ieee80211_is_bufferable_mmpdu(skb) ||
685 679 ieee80211_is_deauth(hdr->frame_control) ||
686 680 ieee80211_is_disassoc(hdr->frame_control) ||
687 681 head == &wcid->tx_offchannel))
modified drivers/net/wireless/nxp/nxpwifi/11n.c
@@ -451,7 +451,7 @@ void
451 451 nxpwifi_11n_delete_tx_ba_stream_tbl_entry(struct nxpwifi_private *priv,
452 452 struct nxpwifi_tx_ba_stream_tbl *tbl)
453 453 {
454 - if (!tbl || !nxpwifi_is_tx_ba_stream_ptr_valid(priv, tbl))
454 + if (!tbl || nxpwifi_is_tx_ba_stream_ptr_valid(priv, tbl))
455 455 return;
456 456
457 457 nxpwifi_dbg(priv->adapter, INFO,
modified drivers/net/wireless/nxp/nxpwifi/11n_aggr.c
@@ -168,7 +168,6 @@ nxpwifi_11n_aggregate_pkt(struct nxpwifi_private *priv,
168 168
169 169 if (!nxpwifi_is_ralist_valid(priv, pra_list, ptrindex)) {
170 170 spin_unlock_bh(&priv->wmm.ra_list_spinlock);
171 - nxpwifi_write_data_complete(adapter, skb_aggr, 1, -1);
172 171 return -ENOENT;
173 172 }
174 173
modified drivers/net/wireless/nxp/nxpwifi/11n_rxreorder.c
@@ -205,12 +205,11 @@ void nxpwifi_11n_del_rx_reorder_tbl_by_ta(struct nxpwifi_private *priv, u8 *ta)
205 205 return;
206 206
207 207 for (i = 0; i < MAX_NUM_TID; i++) {
208 - scoped_guard(rcu) {
209 - list_for_each_entry_rcu(tbl, &priv->rx_reorder_tbl_ptr[i], list) {
210 - if (!memcmp(tbl->ta, ta, ETH_ALEN)) {
211 - INIT_LIST_HEAD(&tbl->tmp_list);
212 - list_add_tail(&tbl->tmp_list, &to_delete);
213 - }
208 + guard(rcu)();
209 + list_for_each_entry_rcu(tbl, &priv->rx_reorder_tbl_ptr[i], list) {
210 + if (!memcmp(tbl->ta, ta, ETH_ALEN)) {
211 + INIT_LIST_HEAD(&tbl->tmp_list);
212 + list_add_tail(&tbl->tmp_list, &to_delete);
214 213 }
215 214 }
216 215
modified drivers/net/wireless/nxp/nxpwifi/cfg80211.c
@@ -1539,11 +1539,9 @@ nxpwifi_cfg80211_del_station(struct wiphy *wiphy, struct wireless_dev *wdev,
1539 1539
1540 1540 eth_zero_addr(deauth_mac);
1541 1541
1542 - rcu_read_lock();
1543 1542 sta_node = nxpwifi_get_sta_entry(priv, params->mac);
1544 1543 if (sta_node)
1545 1544 ether_addr_copy(deauth_mac, params->mac);
1546 - rcu_read_unlock();
1547 1545
1548 1546 if (is_valid_ether_addr(deauth_mac)) {
1549 1547 ret = nxpwifi_uap_sta_deauth(priv, deauth_mac);
@@ -3325,7 +3323,6 @@ nxpwifi_cfg80211_authenticate(struct wiphy *wiphy,
3325 3323 struct nxpwifi_adapter *adapter = priv->adapter;
3326 3324 struct sk_buff *skb;
3327 3325 u16 pkt_len, auth_alg;
3328 - size_t frame_len;
3329 3326 int ret;
3330 3327 struct ieee80211_mgmt *mgmt;
3331 3328 struct nxpwifi_txinfo *tx_info;
@@ -3399,25 +3396,13 @@ nxpwifi_cfg80211_authenticate(struct wiphy *wiphy,
3399 3396
3400 3397 nxpwifi_cancel_scan(adapter);
3401 3398
3402 - frame_len = req->ie_len + req->auth_data_len +
3403 - sizeof(struct ieee80211_hdr_3addr) + NXPWIFI_AUTH_BODY_LEN;
3399 + pkt_len = (u16)req->ie_len + req->auth_data_len +
3400 + NXPWIFI_MGMT_HEADER_LEN + NXPWIFI_AUTH_BODY_LEN;
3404 3401
3405 3402 if (req->auth_data_len >= 4)
3406 - frame_len -= 4;
3407 -
3408 - /* nxpwifi_form_mgmt_frame() inserts address4, so the frame handed to
3409 - * the firmware is ETH_ALEN longer than the one built here.
3410 - */
3411 - if (frame_len > U16_MAX - ETH_ALEN) {
3412 - nxpwifi_dbg(adapter, ERROR,
3413 - "auth frame too long: %zu bytes\n", frame_len);
3414 - return -EINVAL;
3415 - }
3416 - pkt_len = frame_len + ETH_ALEN;
3403 + pkt_len -= 4;
3417 3404
3418 - mgmt = kzalloc(frame_len, GFP_KERNEL);
3419 - if (!mgmt)
3420 - return -ENOMEM;
3405 + mgmt = kzalloc(pkt_len, GFP_KERNEL);
3421 3406
3422 3407 skb = dev_alloc_skb(NXPWIFI_MIN_DATA_HEADER_LEN +
3423 3408 NXPWIFI_MGMT_FRAME_HEADER_SIZE +
@@ -3425,7 +3410,6 @@ nxpwifi_cfg80211_authenticate(struct wiphy *wiphy,
3425 3410 if (!skb) {
3426 3411 nxpwifi_dbg(adapter, ERROR,
3427 3412 "allocate skb failed for management frame\n");
3428 - kfree(mgmt);
3429 3413 return -ENOMEM;
3430 3414 }
3431 3415
@@ -3464,7 +3448,7 @@ nxpwifi_cfg80211_authenticate(struct wiphy *wiphy,
3464 3448 memcpy((u8 *)varptr, req->ie, req->ie_len);
3465 3449 }
3466 3450
3467 - nxpwifi_form_mgmt_frame(skb, (const u8 *)mgmt, frame_len);
3451 + nxpwifi_form_mgmt_frame(skb, (const u8 *)mgmt, pkt_len);
3468 3452 kfree(mgmt);
3469 3453 priv->auth_flag = HOST_MLME_AUTH_PENDING;
3470 3454 priv->auth_alg = auth_alg;
@@ -3745,9 +3729,8 @@ int nxpwifi_init_channel_scan_gap(struct nxpwifi_adapter *adapter)
3745 3729 * additional active scan request for hidden SSIDs on passive channels.
3746 3730 */
3747 3731 adapter->num_in_chan_stats = 2 * (n_channels_bg + n_channels_a);
3748 - adapter->chan_stats = kcalloc(adapter->num_in_chan_stats,
3749 - sizeof(*adapter->chan_stats),
3750 - GFP_KERNEL);
3732 + adapter->chan_stats = vmalloc(array_size(sizeof(*adapter->chan_stats),
3733 + adapter->num_in_chan_stats));
3751 3734
3752 3735 if (!adapter->chan_stats)
3753 3736 return -ENOMEM;
modified drivers/net/wireless/nxp/nxpwifi/init.c
@@ -328,7 +328,7 @@ static void nxpwifi_invalidate_lists(struct nxpwifi_adapter *adapter)
328 328 static void
329 329 nxpwifi_adapter_cleanup(struct nxpwifi_adapter *adapter)
330 330 {
331 - timer_delete_sync(&adapter->wakeup_timer);
331 + timer_delete(&adapter->wakeup_timer);
332 332 nxpwifi_cancel_all_pending_cmd(adapter);
333 333 wake_up_interruptible(&adapter->cmd_wait_q.wait);
334 334 wake_up_interruptible(&adapter->hs_activate_wait_q);
modified drivers/net/wireless/nxp/nxpwifi/main.c
@@ -644,7 +644,7 @@ static int _nxpwifi_fw_dpc(const struct firmware *firmware, void *context)
644 644 goto done;
645 645
646 646 err_add_intf:
647 - kfree(adapter->chan_stats);
647 + vfree(adapter->chan_stats);
648 648 err_init_chan_scan:
649 649 wiphy_unregister(adapter->wiphy);
650 650 wiphy_free(adapter->wiphy);
@@ -1384,7 +1384,7 @@ static void nxpwifi_uninit_sw(struct nxpwifi_adapter *adapter)
1384 1384 wiphy_free(adapter->wiphy);
1385 1385 adapter->wiphy = NULL;
1386 1386
1387 - kfree(adapter->chan_stats);
1387 + vfree(adapter->chan_stats);
1388 1388 nxpwifi_free_cmd_buffers(adapter);
1389 1389 }
1390 1390
modified drivers/net/wireless/nxp/nxpwifi/uap_event.c
@@ -75,7 +75,6 @@ nxpwifi_uap_event_sta_deauth(struct nxpwifi_private *priv)
75 75 nxpwifi_del_tx_ba_stream_tbl_by_ra(priv, deauth_mac);
76 76 }
77 77 nxpwifi_wmm_del_peer_ra_list(priv, deauth_mac);
78 - nxpwifi_del_sta_entry(priv, deauth_mac);
79 78
80 79 return 0;
81 80 }
modified drivers/net/wireless/nxp/nxpwifi/util.c
@@ -1041,23 +1041,19 @@ nxpwifi_set_sta_ht_cap(struct nxpwifi_private *priv, const u8 *ies,
1041 1041 }
1042 1042 }
1043 1043
1044 - /* Delete a station from list. */
1044 + /* Delete a station from list; called under cfg80211 mutex. */
1045 1045
1046 1046 void nxpwifi_del_sta_entry(struct nxpwifi_private *priv, const u8 *mac)
1047 1047 {
1048 1048 struct nxpwifi_sta_node *node;
1049 1049
1050 - spin_lock_bh(&priv->sta_list_spinlock);
1051 -
1052 - list_for_each_entry(node, &priv->sta_list, list) {
1050 + list_for_each_entry_rcu(node, &priv->sta_list, list) {
1053 1051 if (!memcmp(node->mac_addr, mac, ETH_ALEN)) {
1054 1052 list_del_rcu(&node->list);
1055 1053 kfree_rcu(node, rcu);
1056 1054 break;
1057 1055 }
1058 1056 }
1059 -
1060 - spin_unlock_bh(&priv->sta_list_spinlock);
1061 1057 }
1062 1058
1063 1059 /* Delete all stations from list. */
modified drivers/net/xen-netfront.c
@@ -1234,16 +1234,8 @@ static int handle_incoming_queue(struct netfront_queue *queue,
1234 1234 while ((skb = __skb_dequeue(rxq)) != NULL) {
1235 1235 int pull_to = NETFRONT_SKB_CB(skb)->pull_to;
1236 1236
1237 - /* pull_to comes from the first slot's length, which the
1238 - * backend controls. Make sure the head holds at least an
1239 - * Ethernet header for eth_type_trans().
1240 - */
1241 - if (!pskb_may_pull(skb, max(pull_to, ETH_HLEN))) {
1242 - kfree_skb(skb);
1243 - packets_dropped++;
1244 - queue->info->netdev->stats.rx_errors++;
1245 - continue;
1246 - }
1237 + if (pull_to > skb_headlen(skb))
1238 + __pskb_pull_tail(skb, pull_to - skb_headlen(skb));
1247 1239
1248 1240 /* Ethernet work: Delayed to here as it peeks the header. */
1249 1241 skb->protocol = eth_type_trans(skb, queue->info->netdev);
@@ -1346,10 +1338,8 @@ err:
1346 1338 skb->data_len = rx->status;
1347 1339 skb->len += rx->status;
1348 1340
1349 - if (unlikely(xennet_fill_frags(queue, skb, &tmpq))) {
1350 - __skb_queue_head(&tmpq, skb);
1341 + if (unlikely(xennet_fill_frags(queue, skb, &tmpq)))
1351 1342 goto err;
1352 - }
1353 1343
1354 1344 if (rx->flags & XEN_NETRXF_csum_blank)
1355 1345 skb->ip_summed = CHECKSUM_PARTIAL;
modified drivers/nvme/host/core.c
@@ -598,7 +598,6 @@ bool nvme_change_ctrl_state(struct nvme_ctrl *ctrl,
598 598 break;
599 599 case NVME_CTRL_RESETTING:
600 600 switch (old_state) {
601 - case NVME_CTRL_NEW:
602 601 case NVME_CTRL_LIVE:
603 602 changed = true;
604 603 atomic_long_inc(&ctrl->nr_reset);
@@ -2617,19 +2616,10 @@ static int nvme_update_ns_info(struct nvme_ns *ns, struct nvme_ns_info *info)
2617 2616 set_capacity_and_notify(ns->head->disk, get_capacity(ns->disk));
2618 2617 set_disk_ro(ns->head->disk, nvme_ns_is_readonly(ns, info));
2619 2618 nvme_mpath_revalidate_paths(ns->head);
2619 + ret = nvme_mpath_revalidate_zones(ns->head);
2620 2620
2621 2621 unfreeze_head_queue:
2622 2622 blk_mq_unfreeze_queue(ns->head->disk->queue, memflags);
2623 -
2624 - /*
2625 - * Wait until the head queue is unfrozen before revalidating
2626 - * its zones. blk_revalidate_disk_zones() takes the queue limits
2627 - * lock and then freezes the queue on its own, so it must not be
2628 - * called with the queue already frozen. This is also what
2629 - * nvme_update_ns_info_block() does for ns->disk.
2630 - */
2631 - if (!ret)
2632 - ret = nvme_mpath_revalidate_zones(ns->head);
2633 2623 }
2634 2624
2635 2625 return ret;
modified drivers/nvme/target/core.c
@@ -1325,7 +1325,7 @@ static int nvmet_req_alloc_p2pmem_sgls(struct pci_dev *p2p_dev,
1325 1325
1326 1326 return 0;
1327 1327 out_free_sg:
1328 - pci_p2pmem_free_sgl(p2p_dev, req->sg);
1328 + pci_p2pmem_free_sgl(req->p2p_dev, req->sg);
1329 1329 out_err:
1330 1330 return -ENOMEM;
1331 1331 }
modified drivers/nvme/target/pr.c
@@ -51,8 +51,6 @@ u16 nvmet_set_feat_resv_notif_mask(struct nvmet_req *req, u32 mask)
51 51
52 52 if (nsid != U32_MAX) {
53 53 status = nvmet_req_find_ns(req);
54 - if (status == (NVME_SC_INVALID_NS | NVME_STATUS_DNR))
55 - return NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;
56 54 if (status)
57 55 return status;
58 56 if (!req->ns->pr.enable)
@@ -77,8 +75,6 @@ u16 nvmet_get_feat_resv_notif_mask(struct nvmet_req *req)
77 75 u16 status;
78 76
79 77 status = nvmet_req_find_ns(req);
80 - if (status == (NVME_SC_INVALID_NS | NVME_STATUS_DNR))
81 - return NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;
82 78 if (status)
83 79 return status;
84 80
modified drivers/pci/pcie/aer.c
@@ -1360,10 +1360,8 @@ static DEFINE_KFIFO(aer_recover_ring, struct aer_recover_entry,
1360 1360
1361 1361 static void aer_recover_work_func(struct work_struct *work)
1362 1362 {
1363 - struct aer_capability_regs *regs;
1364 1363 struct aer_recover_entry entry;
1365 1364 struct pci_dev *pdev;
1366 - u32 err;
1367 1365
1368 1366 while (kfifo_get(&aer_recover_ring, &entry)) {
1369 1367 pdev = pci_get_domain_bus_and_slot(entry.domain, entry.bus,
@@ -1377,12 +1375,6 @@ static void aer_recover_work_func(struct work_struct *work)
1377 1375 }
1378 1376 pci_print_aer(pdev, entry.severity, entry.regs);
1379 1377
1380 - regs = entry.regs;
1381 - if (entry.severity == AER_CORRECTABLE)
1382 - err = regs->cor_status & ~regs->cor_mask;
1383 - else
1384 - err = regs->uncor_status & ~regs->uncor_mask;
1385 -
1386 1378 /*
1387 1379 * Memory for aer_capability_regs(entry.regs) is being
1388 1380 * allocated from the ghes_estatus_pool to protect it from
@@ -1393,14 +1385,12 @@ static void aer_recover_work_func(struct work_struct *work)
1393 1385 ghes_estatus_pool_region_free((unsigned long)entry.regs,
1394 1386 sizeof(struct aer_capability_regs));
1395 1387
1396 - if (err) {
1397 - if (entry.severity == AER_NONFATAL)
1398 - pcie_do_recovery(pdev, pci_channel_io_normal,
1399 - aer_root_reset);
1400 - else if (entry.severity == AER_FATAL)
1401 - pcie_do_recovery(pdev, pci_channel_io_frozen,
1402 - aer_root_reset);
1403 - }
1388 + if (entry.severity == AER_NONFATAL)
1389 + pcie_do_recovery(pdev, pci_channel_io_normal,
1390 + aer_root_reset);
1391 + else if (entry.severity == AER_FATAL)
1392 + pcie_do_recovery(pdev, pci_channel_io_frozen,
1393 + aer_root_reset);
1404 1394 pci_dev_put(pdev);
1405 1395 }
1406 1396 }
modified drivers/pmdomain/imx/imx8m-blk-ctrl.c
@@ -15,7 +15,6 @@
15 15 #include <linux/pm_runtime.h>
16 16 #include <linux/regmap.h>
17 17 #include <linux/clk.h>
18 - #include <linux/mutex.h>
19 18
20 19 #include <dt-bindings/power/imx8mm-power.h>
21 20 #include <dt-bindings/power/imx8mn-power.h>
@@ -35,12 +34,6 @@ struct imx8m_blk_ctrl {
35 34 struct regmap *regmap;
36 35 struct imx8m_blk_ctrl_domain *domains;
37 36 struct genpd_onecell_data onecell_data;
38 - /*
39 - * Serializes the blk-ctrl reset/clock sequence across sibling domains;
40 - * their transitions interact through the shared VPUMIX bus domain,
41 - * VPU_NOC and the not-ack-verified ADB400 handshake (ERR050531).
42 - */
43 - struct mutex power_lock;
44 37 };
45 38
46 39 struct imx8m_blk_ctrl_domain_data {
@@ -105,8 +98,6 @@ static int imx8m_blk_ctrl_power_on(struct generic_pm_domain *genpd)
105 98 struct imx8m_blk_ctrl *bc = domain->bc;
106 99 int ret;
107 100
108 - guard(mutex)(&bc->power_lock);
109 -
110 101 /* make sure bus domain is awake */
111 102 ret = pm_runtime_get_sync(bc->bus_power_dev);
112 103 if (ret < 0) {
@@ -173,8 +164,6 @@ static int imx8m_blk_ctrl_power_off(struct generic_pm_domain *genpd)
173 164 const struct imx8m_blk_ctrl_domain_data *data = domain->data;
174 165 struct imx8m_blk_ctrl *bc = domain->bc;
175 166
176 - guard(mutex)(&bc->power_lock);
177 -
178 167 /* put devices into reset and disable clocks */
179 168 if (data->mipi_phy_rst_mask)
180 169 regmap_clear_bits(bc->regmap, BLK_MIPI_RESET_DIV, data->mipi_phy_rst_mask);
@@ -213,10 +202,6 @@ static int imx8m_blk_ctrl_probe(struct platform_device *pdev)
213 202
214 203 bc->dev = dev;
215 204
216 - ret = devm_mutex_init(dev, &bc->power_lock);
217 - if (ret)
218 - return ret;
219 -
220 205 bc_data = of_device_get_match_data(dev);
221 206
222 207 base = devm_platform_ioremap_resource(pdev, 0);
modified drivers/pmdomain/rockchip/pm-domains.c
@@ -759,19 +759,7 @@ static int rockchip_pd_attach_dev(struct generic_pm_domain *genpd,
759 759 }
760 760
761 761 i = 0;
762 - while (1) {
763 - clk = of_clk_get(dev->of_node, i++);
764 - if (IS_ERR(clk)) {
765 - error = PTR_ERR(clk);
766 - if (error == -ENOENT)
767 - break;
768 -
769 - dev_err(dev, "failed to get clock %d: %d\n", i - 1,
770 - error);
771 - pm_clk_destroy(dev);
772 - return error;
773 - }
774 -
762 + while ((clk = of_clk_get(dev->of_node, i++)) && !IS_ERR(clk)) {
775 763 dev_dbg(dev, "adding clock '%pC' to list of PM clocks\n", clk);
776 764 error = pm_clk_add_clk(dev, clk);
777 765 if (error) {
@@ -854,7 +842,7 @@ static int rockchip_pm_add_one_domain(struct rockchip_pmu *pmu,
854 842 dev_err(pmu->dev,
855 843 "%pOFn: failed to get clk at index %d: %d\n",
856 844 node, i, error);
857 - goto err_put_clocks;
845 + return error;
858 846 }
859 847 }
860 848
@@ -1030,9 +1018,7 @@ static int rockchip_pm_add_subdomain(struct rockchip_pmu *pmu,
1030 1018 parent_domain->name, child_domain->name);
1031 1019 }
1032 1020
1033 - error = rockchip_pm_add_subdomain(pmu, np);
1034 - if (error)
1035 - return error;
1021 + rockchip_pm_add_subdomain(pmu, np);
1036 1022 }
1037 1023
1038 1024 return 0;
modified drivers/power/sequencing/pwrseq-pcie-m2.c
@@ -197,8 +197,6 @@ static const struct pci_device_id pwrseq_m2_pci_ids[] = {
197 197 .driver_data = (kernel_ulong_t)"qcom,wcn6855-bt" },
198 198 { PCI_DEVICE_SUB(PCI_VENDOR_ID_QCOM, 0x1107, PCI_VENDOR_ID_QCOM, 0x337c),
199 199 .driver_data = (kernel_ulong_t)"qcom,wcn7850-bt" },
200 - { PCI_DEVICE_SUB(PCI_VENDOR_ID_QCOM, 0x1107, PCI_VENDOR_ID_LENOVO, 0xe0e9),
201 - .driver_data = (kernel_ulong_t)"qcom,wcn7850-bt" },
202 200 { } /* Sentinel */
203 201 };
204 202
@@ -572,7 +570,6 @@ err_destroy_mutex:
572 570 mutex_destroy(&ctx->list_lock);
573 571 err_free_regulators:
574 572 regulator_bulk_free(ctx->num_vregs, ctx->regs);
575 - kfree(ctx->regs);
576 573
577 574 return ret;
578 575 }
@@ -586,7 +583,6 @@ static void pwrseq_pcie_m2_remove(struct platform_device *pdev)
586 583 mutex_destroy(&ctx->list_lock);
587 584
588 585 regulator_bulk_free(ctx->num_vregs, ctx->regs);
589 - kfree(ctx->regs);
590 586 }
591 587
592 588 static const struct of_device_id pwrseq_pcie_m2_of_match[] = {
modified drivers/ptp/ptp_ocp.c
@@ -1825,7 +1825,7 @@ ptp_ocp_watchdog(struct timer_list *t)
1825 1825 static void
1826 1826 ptp_ocp_estimate_pci_timing(struct ptp_ocp *bp)
1827 1827 {
1828 - ktime_t start, end, delay = KTIME_MAX;
1828 + ktime_t start, end, delay = U64_MAX;
1829 1829 u32 ctrl;
1830 1830 int i;
1831 1831
modified drivers/regulator/ltc3676.c
@@ -232,7 +232,7 @@ static const struct regulator_desc ltc3676_regulators[LTC3676_NUM_REGULATORS] =
232 232 LTC3676_FIXED_REG(LDO4, ldo4, LDOB, 2),
233 233 };
234 234
235 - static bool ltc3676_writeable_reg(struct device *dev, unsigned int reg)
235 + static bool ltc3676_readable_writeable_reg(struct device *dev, unsigned int reg)
236 236 {
237 237 switch (reg) {
238 238 case LTC3676_BUCK1 ... LTC3676_IRQSTAT:
@@ -243,15 +243,6 @@ static bool ltc3676_writeable_reg(struct device *dev, unsigned int reg)
243 243 return false;
244 244 }
245 245
246 - static bool ltc3676_readable_reg(struct device *dev, unsigned int reg)
247 - {
248 - switch (reg) {
249 - case LTC3676_BUCK1 ... LTC3676_IRQSTAT:
250 - return true;
251 - }
252 - return false;
253 - }
254 -
255 246 static bool ltc3676_volatile_reg(struct device *dev, unsigned int reg)
256 247 {
257 248 switch (reg) {
@@ -264,8 +255,8 @@ static bool ltc3676_volatile_reg(struct device *dev, unsigned int reg)
264 255 static const struct regmap_config ltc3676_regmap_config = {
265 256 .reg_bits = 8,
266 257 .val_bits = 8,
267 - .writeable_reg = ltc3676_writeable_reg,
268 - .readable_reg = ltc3676_readable_reg,
258 + .writeable_reg = ltc3676_readable_writeable_reg,
259 + .readable_reg = ltc3676_readable_writeable_reg,
269 260 .volatile_reg = ltc3676_volatile_reg,
270 261 .max_register = LTC3676_CLIRQ,
271 262 .use_single_read = true,
modified drivers/regulator/of_regulator.c
@@ -929,26 +929,21 @@ static int is_supply_name(const char *name)
929 929 * before returning to the caller, and @consumers will not be
930 930 * changed.
931 931 *
932 - * On success the array is allocated here and handed to the caller, which
933 - * owns it from then on: release the regulators with regulator_bulk_free()
934 - * and free the array itself with kfree(). The supply names live in the
935 - * same allocation, so they are gone once the array is freed.
936 - *
937 932 * Return: Number of regulators on success, or a negative error number
938 933 * on failure.
939 934 */
940 935 int of_regulator_bulk_get_all(struct device *dev, struct device_node *np,
941 936 struct regulator_bulk_data **consumers)
942 937 {
943 - int num_consumers = 0, names_len = 0;
938 + int num_consumers = 0;
944 939 struct regulator *tmp;
945 940 struct regulator_bulk_data *_consumers = NULL;
946 941 struct property *prop;
947 - char *names;
948 942 int i, n = 0, ret;
943 + char name[64];
949 944
950 945 /*
951 - * first pass: get numbers of xxx-supply and the room their names take
946 + * first pass: get numbers of xxx-supply
952 947 * second pass: fill consumers
953 948 */
954 949 restart:
@@ -958,19 +953,16 @@ restart:
958 953 continue;
959 954 if (!_consumers) {
960 955 num_consumers++;
961 - names_len += i + 1;
962 956 continue;
963 957 } else {
964 - memcpy(names, prop->name, i);
965 - names[i] = '\0';
966 - tmp = regulator_get(dev, names);
958 + memcpy(name, prop->name, i);
959 + name[i] = '\0';
960 + tmp = regulator_get(dev, name);
967 961 if (IS_ERR(tmp)) {
968 962 ret = PTR_ERR(tmp);
969 963 goto error;
970 964 }
971 - _consumers[n].supply = names;
972 965 _consumers[n].consumer = tmp;
973 - names += i + 1;
974 966 n++;
975 967 continue;
976 968 }
@@ -981,16 +973,9 @@ restart:
981 973 }
982 974 if (num_consumers == 0)
983 975 return 0;
984 - /*
985 - * The supply names are kept in the same allocation as the array, so
986 - * that they share its lifetime and the caller has nothing extra to
987 - * free.
988 - */
989 - _consumers = kzalloc(size_add(size_mul(num_consumers, sizeof(*_consumers)),
990 - names_len), GFP_KERNEL);
976 + _consumers = kmalloc_objs(struct regulator_bulk_data, num_consumers);
991 977 if (!_consumers)
992 978 return -ENOMEM;
993 - names = (char *)(_consumers + num_consumers);
994 979 goto restart;
995 980
996 981 error:
modified drivers/regulator/tps6594-regulator.c
@@ -241,21 +241,21 @@ static const struct regulator_desc tps65224_buck_regs[] = {
241 241 TPS65224_MASK_BUCKS_VSET,
242 242 TPS6594_REG_BUCKX_CTRL(1),
243 243 TPS6594_BIT_BUCK_EN, 0, 0, tps65224_bucks_2_3_4_ranges,
244 - ARRAY_SIZE(tps65224_bucks_2_3_4_ranges), 0, 0, NULL, 0, 0),
244 + 4, 0, 0, NULL, 0, 0),
245 245 TPS6594_REGULATOR("BUCK3", "buck3", TPS6594_BUCK_3,
246 246 REGULATOR_VOLTAGE, tps6594_bucks_ops, TPS65224_MASK_BUCKS_VSET,
247 247 TPS6594_REG_BUCKX_VOUT_1(2),
248 248 TPS65224_MASK_BUCKS_VSET,
249 249 TPS6594_REG_BUCKX_CTRL(2),
250 250 TPS6594_BIT_BUCK_EN, 0, 0, tps65224_bucks_2_3_4_ranges,
251 - ARRAY_SIZE(tps65224_bucks_2_3_4_ranges), 0, 0, NULL, 0, 0),
251 + 4, 0, 0, NULL, 0, 0),
252 252 TPS6594_REGULATOR("BUCK4", "buck4", TPS6594_BUCK_4,
253 253 REGULATOR_VOLTAGE, tps6594_bucks_ops, TPS65224_MASK_BUCKS_VSET,
254 254 TPS6594_REG_BUCKX_VOUT_1(3),
255 255 TPS65224_MASK_BUCKS_VSET,
256 256 TPS6594_REG_BUCKX_CTRL(3),
257 257 TPS6594_BIT_BUCK_EN, 0, 0, tps65224_bucks_2_3_4_ranges,
258 - ARRAY_SIZE(tps65224_bucks_2_3_4_ranges), 0, 0, NULL, 0, 0),
258 + 4, 0, 0, NULL, 0, 0),
259 259 };
260 260
261 261 static const struct tps6594_regulator_irq_type tps6594_buck1_irq_types[] = {
modified drivers/scsi/ch.c
@@ -112,6 +112,7 @@ typedef struct {
112 112 int minor;
113 113 char name[8];
114 114 struct scsi_device *device;
115 + struct scsi_device **dt; /* ptrs to data transfer elements */
115 116 u_int firsts[CH_TYPES];
116 117 u_int counts[CH_TYPES];
117 118 u_int voltags;
@@ -362,10 +363,15 @@ ch_readconfig(scsi_changer *ch)
362 363 vendor_labels[i]);
363 364 }
364 365
365 - /* report the devices of the data transfer elements */
366 - for (elem = 0; elem < ch->counts[CHET_DT]; elem++) {
367 - struct scsi_device *sdev;
366 + /* look up the devices of the data transfer elements */
367 + ch->dt = kzalloc_objs(*ch->dt, ch->counts[CHET_DT]);
368 +
369 + if (!ch->dt) {
370 + kfree(buffer);
371 + return -ENOMEM;
372 + }
368 373
374 + for (elem = 0; elem < ch->counts[CHET_DT]; elem++) {
369 375 id = -1;
370 376 lun = 0;
371 377 if (elem < CH_DT_MAX && -1 != dt_id[elem]) {
@@ -381,8 +387,10 @@ ch_readconfig(scsi_changer *ch)
381 387 VPRINTK(KERN_INFO, "dt 0x%x: ",elem+ch->firsts[CHET_DT]);
382 388 if (data[6] & 0x80) {
383 389 VPRINTK(KERN_CONT, "not this SCSI bus\n");
390 + ch->dt[elem] = NULL;
384 391 } else if (0 == (data[6] & 0x30)) {
385 392 VPRINTK(KERN_CONT, "ID/LUN unknown\n");
393 + ch->dt[elem] = NULL;
386 394 } else {
387 395 id = ch->device->id;
388 396 lun = 0;
@@ -392,16 +400,18 @@ ch_readconfig(scsi_changer *ch)
392 400 }
393 401 if (-1 != id) {
394 402 VPRINTK(KERN_CONT, "ID %i, LUN %i, ",id,lun);
395 - sdev = scsi_device_lookup(ch->device->host,
396 - ch->device->channel,
397 - id, lun);
398 - if (!sdev) {
403 + ch->dt[elem] =
404 + scsi_device_lookup(ch->device->host,
405 + ch->device->channel,
406 + id,lun);
407 + if (!ch->dt[elem]) {
399 408 /* should not happen */
400 409 VPRINTK(KERN_CONT, "Huh? device not found!\n");
401 410 } else {
402 411 VPRINTK(KERN_CONT, "name: %8.8s %16.16s %4.4s\n",
403 - sdev->vendor, sdev->model, sdev->rev);
404 - scsi_device_put(sdev);
412 + ch->dt[elem]->vendor,
413 + ch->dt[elem]->model,
414 + ch->dt[elem]->rev);
405 415 }
406 416 }
407 417 }
@@ -565,6 +575,7 @@ static void ch_destroy(struct kref *ref)
565 575 scsi_changer *ch = container_of(ref, scsi_changer, ref);
566 576
567 577 ch->device = NULL;
578 + kfree(ch->dt);
568 579 kfree(ch);
569 580 }
570 581
modified drivers/scsi/qedi/qedi_main.c
@@ -2652,6 +2652,8 @@ retry_probe:
2652 2652 snprintf(host_buf, sizeof(host_buf), "host_%d", qedi->shost->host_no);
2653 2653 qedi_ops->common->set_name(qedi->cdev, host_buf);
2654 2654
2655 + qedi_ops->register_ops(qedi->cdev, &qedi_cb_ops, qedi);
2656 +
2655 2657 memset(&params, 0, sizeof(params));
2656 2658 params.mtu = DEF_PATH_MTU + IPV6_HDR_LEN + TCP_HDR_LEN;
2657 2659 qedi->ll2_mtu = DEF_PATH_MTU;
@@ -2668,7 +2670,6 @@ retry_probe:
2668 2670 spin_lock_init(&qedi->task_idx_lock);
2669 2671 mutex_init(&qedi->stats_lock);
2670 2672 }
2671 - qedi_ops->register_ops(qedi->cdev, &qedi_cb_ops, qedi);
2672 2673 qedi_ops->ll2->register_cb_ops(qedi->cdev, &qedi_ll2_cb_ops, qedi);
2673 2674 qedi_ops->ll2->start(qedi->cdev, &params);
2674 2675
modified drivers/spi/spi-cadence-quadspi.c
@@ -1056,7 +1056,8 @@ static int cqspi_write_setup(struct cqspi_flash_pdata *f_pdata,
1056 1056 * care of polling the status register.
1057 1057 */
1058 1058 if (cqspi->wr_completion) {
1059 - reg = CQSPI_REG_WR_DISABLE_AUTO_POLL;
1059 + reg = readl(reg_base + CQSPI_REG_WR_COMPLETION_CTRL);
1060 + reg |= CQSPI_REG_WR_DISABLE_AUTO_POLL;
1060 1061 writel(reg, reg_base + CQSPI_REG_WR_COMPLETION_CTRL);
1061 1062 /*
1062 1063 * DAC mode require auto polling as flash needs to be polled
modified drivers/spi/spi-nxp-fspi.c
@@ -898,10 +898,10 @@ static int nxp_fspi_select_mem(struct nxp_fspi *f, struct spi_device *spi,
898 898 dev_dbg(f->dev, "Target device [CS:%x] selected\n", spi_get_chipselect(spi, 0));
899 899
900 900 /*
901 - * Per the FlexSPI reference manual (initialization sequence), MCR0
902 - * should be configured while the module is in stop mode (MCR0[MDIS] = 1).
903 - * Enter stop mode before reconfiguring the RX sample clock source, then
904 - * exit stop mode afterwards.
901 + * Per the FlexSPI reference manual (initialization sequence), MCR0 and
902 + * the DLL control registers should be configured while the module is in
903 + * stop mode (MCR0[MDIS] = 1). Enter stop mode before reconfiguring the
904 + * RX sample clock source and the DLL, then exit stop mode afterwards.
905 905 */
906 906 reg = fspi_readl(f, f->iobase + FSPI_MCR0);
907 907 fspi_writel(f, reg | FSPI_MCR0_MDIS, f->iobase + FSPI_MCR0);
@@ -936,16 +936,6 @@ static int nxp_fspi_select_mem(struct nxp_fspi *f, struct spi_device *spi,
936 936 if (ret)
937 937 return ret;
938 938
939 - /*
940 - * Exit stop mode before running the DLL calibration. The DLL
941 - * reference clock is derived from the module clock domain, which is
942 - * gated while MCR0[MDIS] = 1. Calibrating the DLL in stop mode leaves
943 - * the STS2 lock bits stuck at 0 (the DLL never runs), so clear MDIS
944 - * first and let the module and reference clock run.
945 - */
946 - reg = fspi_readl(f, f->iobase + FSPI_MCR0);
947 - fspi_writel(f, reg & ~FSPI_MCR0_MDIS, f->iobase + FSPI_MCR0);
948 -
949 939 /*
950 940 * If clock rate > 100MHz, then switch from DLL override mode to
951 941 * DLL calibration mode.
@@ -955,6 +945,10 @@ static int nxp_fspi_select_mem(struct nxp_fspi *f, struct spi_device *spi,
955 945 else
956 946 nxp_fspi_dll_override(f);
957 947
948 + /* Exit stop mode now that MCR0 and the DLL have been reconfigured. */
949 + reg = fspi_readl(f, f->iobase + FSPI_MCR0);
950 + fspi_writel(f, reg & ~FSPI_MCR0_MDIS, f->iobase + FSPI_MCR0);
951 +
958 952 f->pre_op_rate = op->max_freq;
959 953
960 954 f->selected = spi_get_chipselect(spi, 0);
modified drivers/spi/spi-sg2044-nor.c
@@ -307,15 +307,15 @@ static ssize_t sg2044_spifmc_tran_cmd(struct sg2044_spifmc *spifmc,
307 307 return 0;
308 308 }
309 309
310 - static int sg2044_spifmc_trans(struct sg2044_spifmc *spifmc,
311 - const struct spi_mem_op *op)
310 + static void sg2044_spifmc_trans(struct sg2044_spifmc *spifmc,
311 + const struct spi_mem_op *op)
312 312 {
313 313 if (op->data.dir == SPI_MEM_DATA_IN)
314 - return sg2044_spifmc_read(spifmc, op);
314 + sg2044_spifmc_read(spifmc, op);
315 315 else if (op->data.dir == SPI_MEM_DATA_OUT)
316 - return sg2044_spifmc_write(spifmc, op);
316 + sg2044_spifmc_write(spifmc, op);
317 317 else
318 - return sg2044_spifmc_tran_cmd(spifmc, op);
318 + sg2044_spifmc_tran_cmd(spifmc, op);
319 319 }
320 320
321 321 static ssize_t sg2044_spifmc_trans_reg(struct sg2044_spifmc *spifmc,
@@ -385,64 +385,29 @@ static ssize_t sg2044_spifmc_trans_reg(struct sg2044_spifmc *spifmc,
385 385 return 0;
386 386 }
387 387
388 - static int sg2044_spifmc_set_speed(struct sg2044_spifmc *spifmc,
389 - unsigned int speed_hz)
390 - {
391 - unsigned long rate = clk_get_rate(spifmc->clk);
392 - u64 div;
393 - u32 reg;
394 -
395 - if (!rate)
396 - return -EINVAL;
397 -
398 - /* SCK = HCLK / (2 * (SckDiv + 1)); round down the resulting SCK. */
399 - div = speed_hz ? DIV_ROUND_UP_ULL(rate, 2ULL * speed_hz) : 1;
400 - if (div > SPIFMC_CTRL_SCK_DIV_MASK + 1)
401 - return -EINVAL;
402 -
403 - reg = readl(spifmc->io_base + SPIFMC_CTRL);
404 - reg &= ~SPIFMC_CTRL_SCK_DIV_MASK;
405 - reg |= div - 1;
406 - writel(reg, spifmc->io_base + SPIFMC_CTRL);
407 -
408 - return 0;
409 - }
410 -
411 388 static int sg2044_spifmc_exec_op(struct spi_mem *mem,
412 389 const struct spi_mem_op *op)
413 390 {
414 391 struct sg2044_spifmc *spifmc;
415 - int ret;
416 392
417 393 spifmc = spi_controller_get_devdata(mem->spi->controller);
418 394
419 395 mutex_lock(&spifmc->lock);
420 396
421 - ret = sg2044_spifmc_set_speed(spifmc, op->max_freq ?
422 - min(op->max_freq, mem->spi->max_speed_hz) :
423 - mem->spi->max_speed_hz);
424 - if (ret)
425 - goto out_unlock;
426 -
427 397 if (op->addr.nbytes == 0)
428 - ret = sg2044_spifmc_trans_reg(spifmc, op);
398 + sg2044_spifmc_trans_reg(spifmc, op);
429 399 else
430 - ret = sg2044_spifmc_trans(spifmc, op);
400 + sg2044_spifmc_trans(spifmc, op);
431 401
432 - out_unlock:
433 402 mutex_unlock(&spifmc->lock);
434 403
435 - return ret;
404 + return 0;
436 405 }
437 406
438 407 static const struct spi_controller_mem_ops sg2044_spifmc_mem_ops = {
439 408 .exec_op = sg2044_spifmc_exec_op,
440 409 };
441 410
442 - static const struct spi_controller_mem_caps sg2044_spifmc_mem_caps = {
443 - .per_op_freq = true,
444 - };
445 -
446 411 static void sg2044_spifmc_init(struct sg2044_spifmc *spifmc)
447 412 {
448 413 u32 tran_csr;
@@ -482,10 +447,6 @@ static int sg2044_spifmc_probe(struct platform_device *pdev)
482 447 if (IS_ERR(spifmc->clk))
483 448 return dev_err_probe(dev, PTR_ERR(spifmc->clk), "Cannot get and enable AHB clock\n");
484 449
485 - ctrl->max_speed_hz = clk_get_rate(spifmc->clk) / 2;
486 - if (!ctrl->max_speed_hz)
487 - return dev_err_probe(dev, -EINVAL, "Invalid AHB clock rate\n");
488 -
489 450 spifmc->dev = &pdev->dev;
490 451 spifmc->ctrl = ctrl;
491 452
@@ -497,7 +458,6 @@ static int sg2044_spifmc_probe(struct platform_device *pdev)
497 458 ctrl->bits_per_word_mask = SPI_BPW_MASK(8);
498 459 ctrl->auto_runtime_pm = false;
499 460 ctrl->mem_ops = &sg2044_spifmc_mem_ops;
500 - ctrl->mem_caps = &sg2044_spifmc_mem_caps;
501 461 ctrl->mode_bits = SPI_RX_DUAL | SPI_TX_DUAL | SPI_RX_QUAD | SPI_TX_QUAD;
502 462
503 463 ret = devm_mutex_init(dev, &spifmc->lock);
modified drivers/tee/optee/ffa_abi.c
@@ -198,8 +198,7 @@ static int to_msg_param_ffa_mem(struct optee_msg_param *mp,
198 198 if (shm) {
199 199 u64 shm_offs = p->u.memref.shm_offs;
200 200
201 - mp->u.fmem.internal_offs = tee_shm_get_page_offset(shm) &
202 - (FFA_PAGE_SIZE - 1);
201 + mp->u.fmem.internal_offs = shm->offset;
203 202
204 203 mp->u.fmem.offs_low = shm_offs;
205 204 mp->u.fmem.offs_high = shm_offs >> 32;
@@ -285,26 +284,14 @@ static int optee_ffa_shm_register(struct tee_context *ctx, struct tee_shm *shm,
285 284 .nattrs = 1,
286 285 };
287 286 struct sg_table sgt;
288 - size_t ffa_offs;
289 287 int rc;
290 288
291 - if (!num_pages)
292 - return -EINVAL;
293 -
294 289 rc = optee_check_mem_type(start, num_pages);
295 290 if (rc)
296 291 return rc;
297 292
298 - /*
299 - * Start the FF-A descriptor at the 4 KiB page containing the shared
300 - * buffer, skipping unused leading 4 KiB pages when PAGE_SIZE is
301 - * larger. Same approach as optee_fill_pages_list() in the SMC ABI.
302 - * This leaves only the offset into that 4 KiB page for internal_offs.
303 - */
304 - ffa_offs = round_down(tee_shm_get_page_offset(shm), FFA_PAGE_SIZE);
305 - rc = sg_alloc_table_from_pages(&sgt, pages, num_pages, ffa_offs,
306 - num_pages * PAGE_SIZE - ffa_offs,
307 - GFP_KERNEL);
293 + rc = sg_alloc_table_from_pages(&sgt, pages, num_pages, 0,
294 + num_pages * PAGE_SIZE, GFP_KERNEL);
308 295 if (rc)
309 296 return rc;
310 297 args.sg = sgt.sgl;
@@ -471,8 +458,7 @@ static void handle_ffa_rpc_func_cmd_shm_alloc(struct tee_context *ctx,
471 458 .attr = OPTEE_MSG_ATTR_TYPE_FMEM_OUTPUT,
472 459 .u.fmem.size = tee_shm_get_size(shm),
473 460 .u.fmem.global_id = shm->sec_world_id,
474 - .u.fmem.internal_offs = tee_shm_get_page_offset(shm) &
475 - (FFA_PAGE_SIZE - 1),
461 + .u.fmem.internal_offs = shm->offset,
476 462 };
477 463
478 464 arg->ret = TEEC_SUCCESS;
@@ -1137,6 +1123,14 @@ static int optee_ffa_probe(struct ffa_device *ffa_dev)
1137 1123
1138 1124 optee_set_dev_group(optee);
1139 1125
1126 + rc = tee_device_register(optee->teedev);
1127 + if (rc)
1128 + goto err_unreg_supp_teedev;
1129 +
1130 + rc = tee_device_register(optee->supp_teedev);
1131 + if (rc)
1132 + goto err_unreg_supp_teedev;
1133 +
1140 1134 rc = rhashtable_init(&optee->ffa.global_ids, &shm_rhash_params);
1141 1135 if (rc)
1142 1136 goto err_unreg_supp_teedev;
@@ -1165,14 +1159,6 @@ static int optee_ffa_probe(struct ffa_device *ffa_dev)
1165 1159 if (optee_ffa_protmem_pool_init(optee, sec_caps))
1166 1160 pr_info("Protected memory service not available\n");
1167 1161
1168 - rc = tee_device_register(optee->teedev);
1169 - if (rc)
1170 - goto err_unregister_devices;
1171 -
1172 - rc = tee_device_register(optee->supp_teedev);
1173 - if (rc)
1174 - goto err_unregister_devices;
1175 -
1176 1162 rc = optee_enumerate_devices(PTA_CMD_GET_DEVICES);
1177 1163 if (rc)
1178 1164 goto err_unregister_devices;
modified drivers/tee/optee/optee_msg.h
@@ -136,8 +136,8 @@ struct optee_msg_param_rmem {
136 136 * struct optee_msg_param_fmem - FF-A memory reference parameter
137 137 * @offs_low: lower bits of offset into shared memory reference
138 138 * @offs_high: higher bits of offset into shared memory reference
139 - * @internal_offs: offset into the first 4 KiB page of the FF-A shared
140 - * memory region
139 + * @internal_offs: internal offset into the first page of shared memory
140 + * reference
141 141 * @size: size of the buffer
142 142 * @global_id: global identifier of the shared memory
143 143 */
modified drivers/tee/optee/smc_abi.c
@@ -1849,6 +1849,14 @@ static int optee_probe(struct platform_device *pdev)
1849 1849
1850 1850 optee_set_dev_group(optee);
1851 1851
1852 + rc = tee_device_register(optee->teedev);
1853 + if (rc)
1854 + goto err_unreg_supp_teedev;
1855 +
1856 + rc = tee_device_register(optee->supp_teedev);
1857 + if (rc)
1858 + goto err_unreg_supp_teedev;
1859 +
1852 1860 optee_cq_init(&optee->call_queue, thread_count);
1853 1861 optee_supp_init(&optee->supp);
1854 1862 optee->smc.memremaped_shm = memremaped_shm;
@@ -1908,14 +1916,6 @@ static int optee_probe(struct platform_device *pdev)
1908 1916 if (optee->smc.sec_caps & OPTEE_SMC_SEC_CAP_DYNAMIC_SHM)
1909 1917 pr_info("dynamic shared memory is enabled\n");
1910 1918
1911 - rc = tee_device_register(optee->teedev);
1912 - if (rc)
1913 - goto err_disable_shm_cache;
1914 -
1915 - rc = tee_device_register(optee->supp_teedev);
1916 - if (rc)
1917 - goto err_disable_shm_cache;
1918 -
1919 1919 rc = optee_enumerate_devices(PTA_CMD_GET_DEVICES);
1920 1920 if (rc)
1921 1921 goto err_disable_shm_cache;
@@ -1942,6 +1942,7 @@ err_supp_uninit:
1942 1942 optee_shm_arg_cache_uninit(optee);
1943 1943 optee_supp_uninit(&optee->supp);
1944 1944 mutex_destroy(&optee->call_queue.mutex);
1945 + err_unreg_supp_teedev:
1945 1946 tee_device_unregister(optee->supp_teedev);
1946 1947 err_unreg_teedev:
1947 1948 tee_device_unregister(optee->teedev);
modified drivers/tee/qcomtee/async.c
@@ -97,10 +97,10 @@ static void qcomtee_get_async_buffer(struct qcomtee_object_invoke_ctx *oic,
97 97 /**
98 98 * async_release() - Process QTEE async release requests.
99 99 * @oic: context used for the current invocation.
100 - * @async_msg: async message for object release.
100 + * @msg: async message for object release.
101 101 * @size: size of the async buffer available.
102 102 *
103 - * Return: Size of the outbound buffer used when processing @async_msg.
103 + * Return: Size of the outbound buffer used when processing @msg.
104 104 */
105 105 static size_t async_release(struct qcomtee_object_invoke_ctx *oic,
106 106 struct qcomtee_async_msg_hdr *async_msg,
modified drivers/tee/qcomtee/qcomtee_msg.h
@@ -112,7 +112,7 @@ union qcomtee_msg_arg {
112 112
113 113 /**
114 114 * struct qcomtee_msg_object_invoke - Direct object invocation message.
115 - * @cxt: object ID hosted in QTEE.
115 + * @ctx: object ID hosted in QTEE.
116 116 * @op: operation for the object.
117 117 * @counts: number of different types of arguments in @args.
118 118 * @args: array of arguments.
modified drivers/tee/qcomtee/qcomtee_object.h
@@ -74,7 +74,6 @@ enum qcomtee_object_type {
74 74 * @QCOMTEE_ARG_TYPE_OO: output object (OO).
75 75 * @QCOMTEE_ARG_TYPE_IB: input buffer (IB).
76 76 * @QCOMTEE_ARG_TYPE_IO: input object (IO).
77 - * @QCOMTEE_ARG_TYPE_NR: number of argument types.
78 77 *
79 78 * Use the invalid type to specify the end of the argument array.
80 79 */
modified drivers/tee/tee_shm.c
@@ -343,10 +343,6 @@ int tee_dyn_shm_alloc_helper(struct tee_shm *shm, size_t size, size_t align,
343 343 unsigned int i;
344 344 int rc = 0;
345 345
346 - /* get_order(0) is undefined and exceeds MAX_PAGE_ORDER. */
347 - if (!nr_pages)
348 - return -EINVAL;
349 -
350 346 /*
351 347 * Ignore alignment since this is already going to be page aligned
352 348 * and there's no need for any larger alignment.
modified drivers/tty/serial/8250/8250_port.c
@@ -3417,11 +3417,8 @@ static void __serial8250_console_write(struct uart_8250_port *up,
3417 3417 * If the console printer did not fully output the previous line, it
3418 3418 * must have been handed or taken over. Insert a newline in order to
3419 3419 * maintain clean output.
3420 - *
3421 - * Braille consoles are an exception. The serial port is not used
3422 - * for printk(). The driver is supposed to write exactly what it gets.
3423 3420 */
3424 - if (unlikely(!up->console_line_ended && !nbcon_write_context_is_braille(wctxt))) {
3421 + if (!up->console_line_ended) {
3425 3422 if (use_fifo)
3426 3423 __serial8250_console_fifo_write(up, wctxt, "\n", 1);
3427 3424 else
modified drivers/tty/serial/amba-pl011.c
@@ -2656,7 +2656,7 @@ pl011_console_write_atomic(struct console *co, struct nbcon_write_context *wctxt
2656 2656 uap, REG_CR);
2657 2657 }
2658 2658
2659 - if (unlikely(!uap->console_line_ended && !nbcon_is_braille(co)))
2659 + if (!uap->console_line_ended)
2660 2660 uart_console_write(&uap->port, "\n", 1, pl011_console_putchar);
2661 2661 uart_console_write(&uap->port, wctxt->outbuf, wctxt->len, pl011_console_putchar);
2662 2662
modified drivers/tty/serial/imx.c
@@ -2136,7 +2136,7 @@ static void imx_uart_console_write_atomic(struct console *co,
2136 2136 imx_uart_writel(sport, ucr1, UCR1);
2137 2137 imx_uart_writel(sport, old_ucr.ucr2 | UCR2_TXEN, UCR2);
2138 2138
2139 - if (unlikely(!sport->last_putchar_was_newline && !nbcon_is_braille(co)))
2139 + if (!sport->last_putchar_was_newline)
2140 2140 uart_console_write(port, "\n", 1, imx_uart_console_putchar);
2141 2141 uart_console_write(port, wctxt->outbuf, wctxt->len,
2142 2142 imx_uart_console_putchar);
modified drivers/tty/serial/sifive.c
@@ -821,7 +821,7 @@ static void sifive_serial_console_write_atomic(struct console *co,
821 821 ier = __ssp_readl(ssp, SIFIVE_SERIAL_IE_OFFS);
822 822 __ssp_writel(0, SIFIVE_SERIAL_IE_OFFS, ssp);
823 823
824 - if (unlikely(!ssp->console_line_ended && !nbcon_is_braille(co)))
824 + if (!ssp->console_line_ended)
825 825 uart_console_write(port, "\n", 1, sifive_serial_console_putchar);
826 826 uart_console_write(port, wctxt->outbuf, wctxt->len,
827 827 sifive_serial_console_putchar);
modified drivers/ufs/core/ufs-mcq.c
@@ -312,24 +312,20 @@ static int ufshcd_mcq_get_tag(struct ufs_hba *hba, struct cq_entry *cqe)
312 312 UFSHCD_NUM_RESERVED;
313 313 }
314 314
315 - static void ufshcd_mcq_compl_cqe(struct ufs_hba *hba, struct cq_entry *cqe)
316 - {
317 - int tag = ufshcd_mcq_get_tag(hba, cqe);
318 -
319 - ufshcd_compl_one_cqe(hba, tag, cqe);
320 - /* After processing the CQE, mark it as an empty (invalid) entry. */
321 - cqe->command_desc_base_addr = 0;
322 - }
323 -
324 315 static void ufshcd_mcq_process_cqe(struct ufs_hba *hba,
325 316 struct ufs_hw_queue *hwq)
326 317 {
327 318 struct cq_entry *cqe = ufshcd_mcq_cur_cqe(hwq);
328 319
329 - if (cqe->command_desc_base_addr)
330 - ufshcd_mcq_compl_cqe(hba, cqe);
331 - else
320 + if (cqe->command_desc_base_addr) {
321 + int tag = ufshcd_mcq_get_tag(hba, cqe);
322 +
323 + ufshcd_compl_one_cqe(hba, tag, cqe);
324 + /* After processed the cqe, mark it empty (invalid) entry */
325 + cqe->command_desc_base_addr = 0;
326 + } else {
332 327 dev_err(hba->dev, "Abnormal CQ entry!\n");
328 + }
333 329 }
334 330
335 331 /*
@@ -337,7 +333,7 @@ static void ufshcd_mcq_process_cqe(struct ufs_hba *hba,
337 333 * controller disabled (HCE = 0). Reading host controller registers, e.g. the
338 334 * CQ tail pointer (CQTPy), may not be safe with the host controller disabled.
339 335 * Hence, iterate over all completion queue entries. This won't result in
340 - * double completions because ufshcd_mcq_compl_cqe() clears a CQE after it
336 + * double completions because ufshcd_mcq_process_cqe() clears a CQE after it
341 337 * has been processed.
342 338 */
343 339 void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba,
@@ -348,13 +344,13 @@ void ufshcd_mcq_compl_all_cqes_lock(struct ufs_hba *hba,
348 344
349 345 spin_lock_irqsave(&hwq->cq_lock, flags);
350 346 while (entries > 0) {
351 - struct cq_entry *cqe = ufshcd_mcq_cur_cqe(hwq);
352 -
353 - if (cqe->command_desc_base_addr)
354 - ufshcd_mcq_compl_cqe(hba, cqe);
347 + ufshcd_mcq_process_cqe(hba, hwq);
355 348 ufshcd_mcq_inc_cq_head_slot(hwq);
356 349 entries--;
357 350 }
351 +
352 + ufshcd_mcq_update_cq_tail_slot(hwq);
353 + hwq->cq_head_slot = hwq->cq_tail_slot;
358 354 spin_unlock_irqrestore(&hwq->cq_lock, flags);
359 355 }
360 356
modified drivers/ufs/core/ufshcd.c
@@ -6044,6 +6044,8 @@ static bool ufshcd_mcq_force_compl_one(struct request *rq, void *priv)
6044 6044 if (blk_mq_is_reserved_rq(rq) || !hwq)
6045 6045 return true;
6046 6046
6047 + ufshcd_mcq_compl_all_cqes_lock(hba, hwq);
6048 +
6047 6049 /*
6048 6050 * For those cmds of which the cqes are not present in the cq, complete
6049 6051 * them explicitly.
@@ -6059,6 +6061,19 @@ static bool ufshcd_mcq_force_compl_one(struct request *rq, void *priv)
6059 6061 return true;
6060 6062 }
6061 6063
6064 + static bool ufshcd_mcq_compl_one(struct request *rq, void *priv)
6065 + {
6066 + struct scsi_device *sdev = rq->q->queuedata;
6067 + struct Scsi_Host *shost = sdev->host;
6068 + struct ufs_hba *hba = shost_priv(shost);
6069 + struct ufs_hw_queue *hwq = ufshcd_mcq_req_to_hwq(hba, rq);
6070 +
6071 + if (!blk_mq_is_reserved_rq(rq) && hwq)
6072 + ufshcd_mcq_poll_cqe_lock(hba, hwq);
6073 +
6074 + return true;
6075 + }
6076 +
6062 6077 /**
6063 6078 * ufshcd_mcq_compl_pending_transfer - MCQ mode function. It is
6064 6079 * invoked from the error handler context or ufshcd_host_reset_and_restore()
@@ -6073,18 +6088,10 @@ static bool ufshcd_mcq_force_compl_one(struct request *rq, void *priv)
6073 6088 static void ufshcd_mcq_compl_pending_transfer(struct ufs_hba *hba,
6074 6089 bool force_compl)
6075 6090 {
6076 - int i;
6077 -
6078 - for (i = 0; i < hba->nr_hw_queues; i++) {
6079 - if (force_compl)
6080 - ufshcd_mcq_compl_all_cqes_lock(hba, &hba->uhq[i]);
6081 - else
6082 - ufshcd_mcq_poll_cqe_lock(hba, &hba->uhq[i]);
6083 - }
6084 -
6085 - if (force_compl)
6086 - blk_mq_tagset_busy_iter(&hba->host->tag_set,
6087 - ufshcd_mcq_force_compl_one, NULL);
6091 + blk_mq_tagset_busy_iter(&hba->host->tag_set,
6092 + force_compl ? ufshcd_mcq_force_compl_one :
6093 + ufshcd_mcq_compl_one,
6094 + NULL);
6088 6095 }
6089 6096
6090 6097 /**
@@ -9549,7 +9556,6 @@ static void ufshcd_async_scan(void *data, async_cookie_t cookie)
9549 9556 ret = ufshcd_add_lus(hba);
9550 9557
9551 9558 out:
9552 - ufshcd_release(hba);
9553 9559 pm_runtime_put_sync(hba->dev);
9554 9560
9555 9561 if (ret)
@@ -11272,9 +11278,6 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
11272 11278
11273 11279 ufshcd_init_clk_gating(hba);
11274 11280
11275 - /* Released by ufshcd_async_scan(), or by out_release on failure. */
11276 - ufshcd_hold(hba);
11277 -
11278 11281 ufshcd_init_clk_scaling(hba);
11279 11282
11280 11283 /*
@@ -11295,7 +11298,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
11295 11298 err = devm_request_irq(dev, irq, ufshcd_intr, IRQF_SHARED, UFSHCD, hba);
11296 11299 if (err) {
11297 11300 dev_err(hba->dev, "request irq failed\n");
11298 - goto out_release;
11301 + goto out_disable;
11299 11302 } else {
11300 11303 hba->is_irq_enabled = true;
11301 11304 }
@@ -11311,7 +11314,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
11311 11314 dev_err(hba->dev, "Host controller enable failed\n");
11312 11315 ufshcd_print_evt_hist(hba);
11313 11316 ufshcd_print_host_state(hba);
11314 - goto out_release;
11317 + goto out_disable;
11315 11318 }
11316 11319
11317 11320 INIT_DELAYED_WORK(&hba->rpm_dev_flush_recheck_work, ufshcd_rpm_dev_flush_recheck_work);
@@ -11325,7 +11328,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
11325 11328
11326 11329 err = ufshcd_add_scsi_host(hba);
11327 11330 if (err)
11328 - goto out_release;
11331 + goto out_disable;
11329 11332
11330 11333 /* Hold auto suspend until async scan completes */
11331 11334 pm_runtime_get_sync(dev);
@@ -11345,7 +11348,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
11345 11348
11346 11349 err = ufshcd_link_startup(hba);
11347 11350 if (err)
11348 - goto out_release;
11351 + goto out_disable;
11349 11352
11350 11353 if (hba->mcq_enabled)
11351 11354 ufshcd_config_mcq(hba);
@@ -11362,23 +11365,23 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
11362 11365 /* Verify device initialization by sending NOP OUT UPIU */
11363 11366 err = ufshcd_verify_dev_init(hba);
11364 11367 if (err)
11365 - goto out_release;
11368 + goto out_disable;
11366 11369
11367 11370 /* Initiate UFS initialization, and waiting until completion */
11368 11371 err = ufshcd_complete_dev_init(hba);
11369 11372 if (err)
11370 - goto out_release;
11373 + goto out_disable;
11371 11374
11372 11375 err = ufshcd_device_params_init(hba);
11373 11376 if (err)
11374 - goto out_release;
11377 + goto out_disable;
11375 11378
11376 11379 err = ufshcd_post_device_init(hba);
11377 11380
11378 11381 initialized:
11379 11382 ufshcd_process_probe_result(hba, probe_start, err);
11380 11383 if (err)
11381 - goto out_release;
11384 + goto out_disable;
11382 11385
11383 11386 ufs_sysfs_add_nodes(hba->dev);
11384 11387 hba->dme_qos_sysfs_handle = sysfs_get_dirent(hba->dev->kobj.sd,
@@ -11389,8 +11392,6 @@ initialized:
11389 11392 ufshcd_pm_qos_init(hba);
11390 11393 return 0;
11391 11394
11392 - out_release:
11393 - ufshcd_release(hba);
11394 11395 out_disable:
11395 11396 hba->is_irq_enabled = false;
11396 11397 ufshcd_hba_exit(hba);
modified drivers/ufs/host/ufs-mediatek.c
@@ -509,7 +509,6 @@ static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on)
509 509 struct ufs_mtk_host *host = ufshcd_get_variant(hba);
510 510 struct phy *mphy = host->mphy;
511 511 struct arm_smccc_res res;
512 - int err;
513 512 int ret = 0;
514 513
515 514 if (!mphy || !(on ^ host->mphy_powered_on))
@@ -524,18 +523,7 @@ static int ufs_mtk_mphy_power_on(struct ufs_hba *hba, bool on)
524 523 usleep_range(200, 210);
525 524 ufs_mtk_va09_pwr_ctrl(res, 1);
526 525 }
527 - ret = phy_power_on(mphy);
528 - if (ret) {
529 - if (ufs_mtk_is_va09_supported(hba)) {
530 - ufs_mtk_va09_pwr_ctrl(res, 0);
531 - err = regulator_disable(host->reg_va09);
532 - if (err)
533 - dev_err(hba->dev,
534 - "failed to unwind va09: %d\n", err);
535 - }
536 - dev_err(hba->dev, "failed to enable mphy: %d\n", ret);
537 - return ret;
538 - }
526 + phy_power_on(mphy);
539 527 } else {
540 528 phy_power_off(mphy);
541 529 if (ufs_mtk_is_va09_supported(hba)) {
@@ -1307,9 +1295,7 @@ static int ufs_mtk_init(struct ufs_hba *hba)
1307 1295 *
1308 1296 * Enable phy clocks specifically here.
1309 1297 */
1310 - err = ufs_mtk_mphy_power_on(hba, true);
1311 - if (err)
1312 - goto out_variant_clear;
1298 + ufs_mtk_mphy_power_on(hba, true);
1313 1299
1314 1300 if (ufs_mtk_is_rtff_mtcmos(hba)) {
1315 1301 /* First Restore here, to avoid backup unexpected value */
modified drivers/usb/mtu3/mtu3_trace.h
@@ -224,7 +224,6 @@ DECLARE_EVENT_CLASS(mtu3_log_ep,
224 224 __field(unsigned int, flags)
225 225 __field(unsigned int, direction)
226 226 __field(struct mtu3_gpd_ring *, gpd_ring)
227 - __field(dma_addr_t, gpd_ring_dma)
228 227 ),
229 228 TP_fast_assign(
230 229 __assign_str(name);
@@ -236,13 +235,12 @@ DECLARE_EVENT_CLASS(mtu3_log_ep,
236 235 __entry->flags = mep->flags;
237 236 __entry->direction = mep->is_in;
238 237 __entry->gpd_ring = &mep->gpd_ring;
239 - __entry->gpd_ring_dma = mep->gpd_ring.dma
240 238 ),
241 239 TP_printk("%s: type %s maxp %d slot %d mult %d burst %d ring %p/%pad flags %c:%c%c%c:%c",
242 240 __get_str(name), usb_ep_type_string(__entry->type),
243 241 __entry->maxp, __entry->slot,
244 242 __entry->mult, __entry->maxburst,
245 - __entry->gpd_ring, &__entry->gpd_ring_dma,
243 + __entry->gpd_ring, &__entry->gpd_ring->dma,
246 244 __entry->flags & MTU3_EP_ENABLED ? 'E' : 'e',
247 245 __entry->flags & MTU3_EP_STALL ? 'S' : 's',
248 246 __entry->flags & MTU3_EP_WEDGE ? 'W' : 'w',
modified fs/btrfs/inode.c
@@ -9623,6 +9623,7 @@ int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode,
9623 9623 struct completion sync_reads;
9624 9624 unsigned long i = 0;
9625 9625 struct btrfs_bio *bbio;
9626 + int ret;
9626 9627
9627 9628 /*
9628 9629 * Fast path for synchronous reads which completes in this call, io_uring
@@ -9669,10 +9670,10 @@ int btrfs_encoded_read_regular_fill_pages(struct btrfs_inode *inode,
9669 9670
9670 9671 if (uring_ctx) {
9671 9672 if (refcount_dec_and_test(&priv->pending_refs)) {
9672 - int error = blk_status_to_errno(READ_ONCE(priv->status));
9673 -
9674 - btrfs_uring_read_extent_endio(uring_ctx, error);
9673 + ret = blk_status_to_errno(READ_ONCE(priv->status));
9674 + btrfs_uring_read_extent_endio(uring_ctx, ret);
9675 9675 kfree(priv);
9676 + return ret;
9676 9677 }
9677 9678
9678 9679 return -EIOCBQUEUED;
modified fs/btrfs/ioctl.c
@@ -4601,7 +4601,7 @@ static void btrfs_uring_read_finished(struct io_tw_req tw_req, io_tw_token_t tw)
4601 4601 size_t page_offset;
4602 4602 ssize_t ret;
4603 4603
4604 - /* The inode lock has already been acquired in btrfs_encoded_read(). */
4604 + /* The inode lock has already been acquired in btrfs_uring_read_extent. */
4605 4605 btrfs_lockdep_inode_acquire(inode, i_rwsem);
4606 4606
4607 4607 if (priv->err) {
@@ -4667,6 +4667,7 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter,
4667 4667 struct iovec *iov, struct io_uring_cmd *cmd)
4668 4668 {
4669 4669 struct btrfs_inode *inode = BTRFS_I(file_inode(iocb->ki_filp));
4670 + struct extent_io_tree *io_tree = &inode->io_tree;
4670 4671 struct page **pages = NULL;
4671 4672 struct btrfs_uring_priv *priv = NULL;
4672 4673 unsigned long nr_pages;
@@ -4722,6 +4723,8 @@ static int btrfs_uring_read_extent(struct kiocb *iocb, struct iov_iter *iter,
4722 4723 return -EIOCBQUEUED;
4723 4724
4724 4725 out_fail:
4726 + btrfs_unlock_extent(io_tree, start, lockend, &cached_state);
4727 + btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED);
4725 4728 kfree(priv);
4726 4729 for (int i = 0; i < nr_pages; i++) {
4727 4730 if (pages[i])
@@ -4834,7 +4837,7 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue
4834 4837 ret = btrfs_encoded_read(&kiocb, &data->iter, &data->args, &cached_state,
4835 4838 &disk_bytenr, &disk_io_size);
4836 4839 if (ret == -EAGAIN)
4837 - goto out_free;
4840 + goto out_acct;
4838 4841 if (ret < 0 && ret != -EIOCBQUEUED)
4839 4842 goto out_free;
4840 4843
@@ -4862,10 +4865,8 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue
4862 4865 cached_state, disk_bytenr, disk_io_size,
4863 4866 count, data->args.compression,
4864 4867 data->iov, cmd);
4865 - if (ret == -EIOCBQUEUED)
4866 - goto out_acct;
4867 - btrfs_unlock_extent(io_tree, start, lockend, &cached_state);
4868 - btrfs_inode_unlock(inode, BTRFS_ILOCK_SHARED);
4868 +
4869 + goto out_acct;
4869 4870 }
4870 4871
4871 4872 out_free:
@@ -4876,10 +4877,8 @@ out_acct:
4876 4877 add_rchar(current, ret);
4877 4878 inc_syscr(current);
4878 4879
4879 - if (ret != -EIOCBQUEUED) {
4880 + if (ret != -EIOCBQUEUED && ret != -EAGAIN)
4880 4881 kfree(data);
4881 - bc->data = NULL;
4882 - }
4883 4882
4884 4883 return ret;
4885 4884 }
@@ -4908,11 +4907,6 @@ static int btrfs_uring_encoded_write(struct io_uring_cmd *cmd, unsigned int issu
4908 4907 goto out_acct;
4909 4908 }
4910 4909
4911 - if (issue_flags & IO_URING_F_NONBLOCK) {
4912 - ret = -EAGAIN;
4913 - goto out_acct;
4914 - }
4915 -
4916 4910 if (!data) {
4917 4911 data = kzalloc_obj(*data, GFP_NOFS);
4918 4912 if (!data) {
@@ -4981,6 +4975,11 @@ static int btrfs_uring_encoded_write(struct io_uring_cmd *cmd, unsigned int issu
4981 4975 }
4982 4976 }
4983 4977
4978 + if (issue_flags & IO_URING_F_NONBLOCK) {
4979 + ret = -EAGAIN;
4980 + goto out_acct;
4981 + }
4982 +
4984 4983 pos = data->args.offset;
4985 4984 ret = rw_verify_area(WRITE, file, &pos, data->args.len);
4986 4985 if (ret < 0)
@@ -5006,8 +5005,8 @@ out_acct:
5006 5005 add_wchar(current, ret);
5007 5006 inc_syscw(current);
5008 5007
5009 - kfree(data);
5010 - bc->data = NULL;
5008 + if (ret != -EAGAIN)
5009 + kfree(data);
5011 5010 return ret;
5012 5011 }
5013 5012
modified fs/btrfs/scrub.c
@@ -536,10 +536,8 @@ static int scrub_print_warning_inode(u64 inum, u64 offset, u64 num_bytes,
536 536 }
537 537 ret = paths_from_inode(inum, ipath);
538 538
539 - if (ret < 0) {
540 - btrfs_put_root(local_root);
539 + if (ret < 0)
541 540 goto err;
542 - }
543 541
544 542 /*
545 543 * we deliberately ignore the bit ipath might have been too small to
modified fs/btrfs/transaction.c
@@ -432,7 +432,6 @@ static int record_root_in_trans(struct btrfs_trans_handle *trans,
432 432 spin_lock(&fs_info->fs_roots_radix_lock);
433 433 if (btrfs_get_root_last_trans(root) == trans->transid && !force) {
434 434 spin_unlock(&fs_info->fs_roots_radix_lock);
435 - clear_bit(BTRFS_ROOT_IN_TRANS_SETUP, &root->state);
436 435 return 0;
437 436 }
438 437 radix_tree_tag_set(&fs_info->fs_roots_radix,
modified fs/btrfs/xattr.c
@@ -161,7 +161,6 @@ int btrfs_setxattr(struct btrfs_trans_handle *trans, struct inode *inode,
161 161 const u16 old_data_len = btrfs_dir_data_len(leaf, di);
162 162 const u32 item_size = btrfs_item_size(leaf, slot);
163 163 const u32 data_size = sizeof(*di) + name_len + size;
164 - unsigned long name_ptr;
165 164 unsigned long data_ptr;
166 165 char *ptr;
167 166
@@ -190,16 +189,8 @@ int btrfs_setxattr(struct btrfs_trans_handle *trans, struct inode *inode,
190 189 ptr = btrfs_item_ptr(leaf, slot, char);
191 190 ptr += btrfs_item_size(leaf, slot) - data_size;
192 191 di = (struct btrfs_dir_item *)ptr;
193 - memzero_extent_buffer(leaf, (unsigned long)ptr +
194 - offsetof(struct btrfs_dir_item, location),
195 - sizeof(struct btrfs_disk_key));
196 - btrfs_set_dir_flags(leaf, di, BTRFS_FT_XATTR);
197 - btrfs_set_dir_transid(leaf, di, trans->transid);
198 - btrfs_set_dir_name_len(leaf, di, name_len);
199 192 btrfs_set_dir_data_len(leaf, di, size);
200 - name_ptr = (unsigned long)(di + 1);
201 193 data_ptr = ((unsigned long)(di + 1)) + name_len;
202 - write_extent_buffer(leaf, name, name_ptr, name_len);
203 194 write_extent_buffer(leaf, value, data_ptr, size);
204 195 } else {
205 196 /*
@@ -329,8 +320,10 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
329 320 if (!size)
330 321 goto next;
331 322
332 - if (!buffer || (name_len + 1) > size_left)
333 - return -ERANGE;
323 + if (!buffer || (name_len + 1) > size_left) {
324 + iter_ret = -ERANGE;
325 + break;
326 + }
334 327
335 328 read_extent_buffer(leaf, buffer, name_ptr, name_len);
336 329 buffer[name_len] = '\0';
modified fs/dcache.c
@@ -1583,8 +1583,6 @@ EXPORT_SYMBOL(path_has_submounts);
1583 1583 *
1584 1584 * Only one of d_invalidate() and d_set_mounted() must succeed. For
1585 1585 * this reason take rename_lock and d_lock on dentry and ancestors.
1586 - * Likewise for dont_mount() which marks a dentry that is being removed
1587 - * under d_lock.
1588 1586 */
1589 1587 int d_set_mounted(struct dentry *dentry)
1590 1588 {
@@ -1601,7 +1599,7 @@ int d_set_mounted(struct dentry *dentry)
1601 1599 spin_unlock(&p->d_lock);
1602 1600 }
1603 1601 spin_lock(&dentry->d_lock);
1604 - if (!d_unlinked(dentry) && !cant_mount(dentry)) {
1602 + if (!d_unlinked(dentry)) {
1605 1603 ret = -EBUSY;
1606 1604 if (!d_mountpoint(dentry)) {
1607 1605 dentry->d_flags |= DCACHE_MOUNTED;
modified fs/ext4/super.c
@@ -5057,7 +5057,6 @@ out:
5057 5057 static int ext4_check_journal_data_mode(struct super_block *sb)
5058 5058 {
5059 5059 if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) {
5060 - printk(KERN_WARNING "EXT4-fs: The data=journal mount option is deprecated and support will be removed in January 2028\n");
5061 5060 printk_once(KERN_WARNING "EXT4-fs: Warning: mounting with "
5062 5061 "data=journal disables delayed allocation, "
5063 5062 "dioread_nolock, O_DIRECT and fast_commit support!\n");
modified fs/fcntl.c
@@ -372,9 +372,6 @@ static long fcntl_set_rw_hint(struct file *file, unsigned long arg)
372 372 u64 __user *argp = (u64 __user *)arg;
373 373 u64 hint;
374 374
375 - /* nothing is ever written to it */
376 - if (IS_IMMUTABLE(inode))
377 - return -EPERM;
378 375 if (!inode_owner_or_capable(file_mnt_idmap(file), inode))
379 376 return -EPERM;
380 377
modified fs/fhandle.c
@@ -298,22 +298,6 @@ static bool capable_wrt_mount(struct mount *mount)
298 298 return mnt_ns && ns_capable(mnt_ns->user_ns, CAP_SYS_ADMIN);
299 299 }
300 300
301 - /*
302 - * Does the caller have an unobstructed way to everything below @root? Only
303 - * if the mount is mounted, the caller is privileged over its mount namespace
304 - * and no locked child covers something below @root->dentry. One answer from
305 - * under mount_lock: an umount in between clears ->mnt_ns and takes the
306 - * children off the mount, the locked ones too.
307 - */
308 - static bool subtree_unobstructed(const struct path *root)
309 - {
310 - struct mount *mnt = real_mount(root->mnt);
311 -
312 - guard(mount_locked_reader)();
313 - return is_mounted(root->mnt) && capable_wrt_mount(mnt) &&
314 - !has_locked_children(mnt, root->dentry);
315 - }
316 -
317 301 static inline int may_decode_fh(struct handle_to_path_ctx *ctx,
318 302 unsigned int o_flags)
319 303 {
@@ -348,7 +332,9 @@ static inline int may_decode_fh(struct handle_to_path_ctx *ctx,
348 332
349 333 if (ns_capable(root->mnt->mnt_sb->s_user_ns, CAP_SYS_ADMIN))
350 334 ctx->flags = HANDLE_CHECK_PERMS;
351 - else if (subtree_unobstructed(root))
335 + else if (is_mounted(root->mnt) &&
336 + capable_wrt_mount(real_mount(root->mnt)) &&
337 + !has_locked_children(real_mount(root->mnt), root->dentry))
352 338 ctx->flags = HANDLE_CHECK_PERMS | HANDLE_CHECK_SUBTREE;
353 339 else
354 340 return -EPERM;
modified fs/file_table.c
@@ -520,8 +520,7 @@ static void __fput(struct file *file)
520 520 dput(dentry);
521 521 if (unlikely(mode & FMODE_NEED_UNMOUNT))
522 522 dissolve_on_fput(mnt);
523 - else
524 - mntput(mnt);
523 + mntput(mnt);
525 524 out:
526 525 file_free(file);
527 526 }
modified fs/fs_context.c
@@ -315,10 +315,6 @@ struct fs_context *fs_context_for_reconfigure(struct dentry *dentry,
315 315 unsigned int sb_flags,
316 316 unsigned int sb_flags_mask)
317 317 {
318 - /* kernel-internal superblocks are nobody's to reconfigure */
319 - if (dentry->d_sb->s_flags & SB_NOUSER)
320 - return ERR_PTR(-EINVAL);
321 -
322 318 return alloc_fs_context(dentry->d_sb->s_type, dentry, sb_flags,
323 319 sb_flags_mask, FS_CONTEXT_FOR_RECONFIGURE);
324 320 }
modified fs/mount.h
@@ -6,8 +6,6 @@
6 6 #include <linux/fs_pin.h>
7 7
8 8 extern struct file_system_type nullfs_fs_type;
9 - extern struct dentry *nullfs_new_file(struct super_block *sb);
10 - extern struct vfsmount *knullfs;
11 9 extern struct list_head notify_list;
12 10
13 11 struct mnt_namespace {
@@ -35,20 +33,16 @@ struct mnt_namespace {
35 33 } __randomize_layout;
36 34
37 35 struct mnt_pcp {
38 - unsigned int mnt_gets;
39 - unsigned int mnt_puts;
36 + int mnt_count;
40 37 int mnt_writers;
41 38 };
42 39
43 40 struct mountpoint {
44 41 struct hlist_node m_hash;
45 42 struct dentry *m_dentry;
46 - struct hlist_head m_list; /* mounts on it and pins */
47 - struct hlist_head m_covers; /* covers of unmounted parents */
43 + struct hlist_head m_list;
48 44 };
49 45
50 - struct mnt_cover;
51 -
52 46 struct mount {
53 47 struct hlist_node mnt_hash;
54 48 struct mount *mnt_parent;
@@ -90,7 +84,7 @@ struct mount {
90 84 struct mountpoint *mnt_mp; /* where is it mounted */
91 85 union {
92 86 struct hlist_node mnt_mp_list; /* list mounts with the same mountpoint */
93 - struct hlist_node mnt_umount; /* on the unmounted list */
87 + struct hlist_node mnt_umount;
94 88 };
95 89 #ifdef CONFIG_FSNOTIFY
96 90 struct fsnotify_mark_connector __rcu *mnt_fsnotify_marks;
@@ -104,8 +98,7 @@ struct mount {
104 98 int mnt_group_id; /* peer group identifier */
105 99 int mnt_expiry_mark; /* true if marked for expiry */
106 100 struct hlist_head mnt_pins;
107 - struct mnt_cover *mnt_cover; /* the one it may leave behind */
108 - struct hlist_head mnt_covers; /* left behind by its unmounted children */
101 + struct hlist_head mnt_stuck_children;
109 102 struct hlist_node mnt_ns_visible; /* link in ns->mnt_visible_mounts */
110 103 struct mount *overmount; /* mounted on ->mnt_root */
111 104 } __randomize_layout;
@@ -240,9 +233,6 @@ static inline struct mnt_namespace *to_mnt_ns(struct ns_common *ns)
240 233 #ifdef CONFIG_FSNOTIFY
241 234 static inline void mnt_notify_add(struct mount *m)
242 235 {
243 - /* queued already under this namespace_sem hold */
244 - if (!list_empty(&m->to_notify))
245 - return;
246 236 /* Optimize the case where there are no watches */
247 237 if ((m->mnt_ns && m->mnt_ns->n_fsnotify_marks) ||
248 238 (m->prev_ns && m->prev_ns->n_fsnotify_marks))
modified fs/namei.c
@@ -2086,33 +2086,6 @@ all_done: // pure jump
2086 2086 return NULL;
2087 2087 }
2088 2088
2089 - /*
2090 - * Be careful in case the dentry is unlinked or renamed. Any mounts
2091 - * stacked on top of it are going away. We need to make sure that we
2092 - * don't reveal the underyling dentry during refwalk. In rcuwalk we
2093 - * catch this via d_seq and another lookup for the name. Give the same
2094 - * guarantee in refwalk.
2095 - */
2096 - static bool unlink_may_reveal(struct nameidata *nd, int flags,
2097 - struct path *path, struct dentry *dentry)
2098 - {
2099 - /* ".." and LOOKUP_DOWN may land on an unhashed directory */
2100 - if (flags & WALK_NOFOLLOW)
2101 - return false;
2102 - if (nd->flags & LOOKUP_REVAL)
2103 - return false;
2104 - /* We crossed onto a mount and the name led us here while it still existed */
2105 - if (path->mnt != nd->path.mnt)
2106 - return false;
2107 - /* only a name on its way out is flagged */
2108 - if (likely(!cant_mount(dentry)))
2109 - return false;
2110 - if (!d_unlinked(dentry))
2111 - return false;
2112 - dput(no_free_ptr(path->dentry));
2113 - return true;
2114 - }
2115 -
2116 2089 /*
2117 2090 * Do we need to follow links? We _really_ want to be able
2118 2091 * to do this check without having to look at inode->i_op,
@@ -2142,8 +2115,6 @@ static noinline const char *step_into_slowpath(struct nameidata *nd, int flags,
2142 2115 if (unlikely(!inode))
2143 2116 return ERR_PTR(-ENOENT);
2144 2117 } else {
2145 - if (unlikely(unlink_may_reveal(nd, flags, &path, dentry)))
2146 - return ERR_PTR(-ESTALE);
2147 2118 dput(nd->path.dentry);
2148 2119 if (nd->path.mnt != path.mnt)
2149 2120 mntput(nd->path.mnt);
modified fs/namespace.c
@@ -80,8 +80,6 @@ static u64 mnt_id_ctr = MNT_UNIQUE_ID_OFFSET;
80 80 static struct hlist_head *mount_hashtable __ro_after_init;
81 81 static struct hlist_head *mountpoint_hashtable __ro_after_init;
82 82 static struct kmem_cache *mnt_cache __ro_after_init;
83 - struct vfsmount *knullfs __ro_after_init; /* private nullfs instance */
84 - static struct vfsmount *knullfs_file __ro_after_init; /* its regular file */
85 83 static DECLARE_RWSEM(namespace_sem);
86 84 static HLIST_HEAD(unmounted); /* protected by namespace_sem */
87 85 static LIST_HEAD(ex_mountpoints); /* protected by namespace_sem */
@@ -132,6 +130,7 @@ static void mnt_ns_release(struct mnt_namespace *ns)
132 130 {
133 131 /* keep alive for {list,stat}mount() */
134 132 if (ns && refcount_dec_and_test(&ns->passive)) {
133 + fsnotify_mntns_delete(ns);
135 134 put_user_ns(ns->user_ns);
136 135 kfree(ns);
137 136 }
@@ -211,19 +210,6 @@ static inline struct hlist_head *mp_hash(struct dentry *dentry)
211 210 return &mountpoint_hashtable[tmp & mp_hash_mask];
212 211 }
213 212
214 - /*
215 - * What an unmounted mount leaves behind at its unmounted parent instead of
216 - * staying attached to it. A lookup on the parent at the mountpoint finds
217 - * a stand-in for as long as the cover is there. The parent frees it.
218 - */
219 - struct mnt_cover {
220 - struct hlist_node node; /* parent->mnt_covers, RCU */
221 - struct hlist_node pin; /* mp->m_covers, keeps the mountpoint */
222 - struct dentry *dentry;
223 - struct mountpoint *mp;
224 - struct rcu_head rcu;
225 - };
226 -
227 213 static int mnt_alloc_id(struct mount *mnt)
228 214 {
229 215 int res;
@@ -263,24 +249,16 @@ void mnt_release_group_id(struct mount *mnt)
263 249 mnt->mnt_group_id = 0;
264 250 }
265 251
266 - static inline void mnt_inc_count(struct mount *mnt)
267 - {
268 - #ifdef CONFIG_SMP
269 - this_cpu_inc(mnt->mnt_pcp->mnt_gets);
270 - #else
271 - preempt_disable();
272 - mnt->mnt_count++;
273 - preempt_enable();
274 - #endif
275 - }
276 -
277 - static inline void mnt_dec_count(struct mount *mnt)
252 + /*
253 + * vfsmount lock must be held for read
254 + */
255 + static inline void mnt_add_count(struct mount *mnt, int n)
278 256 {
279 257 #ifdef CONFIG_SMP
280 - this_cpu_inc(mnt->mnt_pcp->mnt_puts);
258 + this_cpu_add(mnt->mnt_pcp->mnt_count, n);
281 259 #else
282 260 preempt_disable();
283 - mnt->mnt_count--;
261 + mnt->mnt_count += n;
284 262 preempt_enable();
285 263 #endif
286 264 }
@@ -291,17 +269,14 @@ static inline void mnt_dec_count(struct mount *mnt)
291 269 int mnt_get_count(struct mount *mnt)
292 270 {
293 271 #ifdef CONFIG_SMP
294 - unsigned int gets = 0, puts = 0;
272 + int count = 0;
295 273 int cpu;
296 274
297 - /* puts first, so a put counted here has its get counted below */
298 - for_each_possible_cpu(cpu)
299 - puts += per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_puts;
300 - smp_mb(); /* pairs with the smp_wmb() in mntput_no_expire() */
301 - for_each_possible_cpu(cpu)
302 - gets += per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_gets;
275 + for_each_possible_cpu(cpu) {
276 + count += per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_count;
277 + }
303 278
304 - return gets - puts;
279 + return count;
305 280 #else
306 281 return mnt->mnt_count;
307 282 #endif
@@ -313,10 +288,6 @@ static struct mount *alloc_vfsmnt(const char *name)
313 288 if (mnt) {
314 289 int err;
315 290
316 - mnt->mnt_cover = kzalloc_obj(struct mnt_cover, GFP_KERNEL_ACCOUNT);
317 - if (!mnt->mnt_cover)
318 - goto out_free_cache;
319 -
320 291 err = mnt_alloc_id(mnt);
321 292 if (err)
322 293 goto out_free_cache;
@@ -334,7 +305,7 @@ static struct mount *alloc_vfsmnt(const char *name)
334 305 if (!mnt->mnt_pcp)
335 306 goto out_free_devname;
336 307
337 - this_cpu_inc(mnt->mnt_pcp->mnt_gets);
308 + this_cpu_add(mnt->mnt_pcp->mnt_count, 1);
338 309 #else
339 310 mnt->mnt_count = 1;
340 311 mnt->mnt_writers = 0;
@@ -349,11 +320,8 @@ static struct mount *alloc_vfsmnt(const char *name)
349 320 INIT_HLIST_HEAD(&mnt->mnt_slave_list);
350 321 INIT_HLIST_NODE(&mnt->mnt_slave);
351 322 INIT_HLIST_NODE(&mnt->mnt_mp_list);
352 - INIT_HLIST_HEAD(&mnt->mnt_covers);
323 + INIT_HLIST_HEAD(&mnt->mnt_stuck_children);
353 324 INIT_HLIST_NODE(&mnt->mnt_ns_visible);
354 - #ifdef CONFIG_FSNOTIFY
355 - INIT_LIST_HEAD(&mnt->to_notify);
356 - #endif
357 325 RB_CLEAR_NODE(&mnt->mnt_node);
358 326 mnt->mnt.mnt_idmap = &nop_mnt_idmap;
359 327 }
@@ -366,7 +334,6 @@ out_free_devname:
366 334 out_free_id:
367 335 mnt_free_id(mnt);
368 336 out_free_cache:
369 - kfree(mnt->mnt_cover);
370 337 kmem_cache_free(mnt_cache, mnt);
371 338 return NULL;
372 339 }
@@ -758,8 +725,6 @@ int sb_prepare_remount_readonly(struct super_block *sb)
758 725 static void free_vfsmnt(struct mount *mnt)
759 726 {
760 727 mnt_idmap_put(mnt_idmap(&mnt->mnt));
761 - /* NULL if it left it behind */
762 - kfree(mnt->mnt_cover);
763 728 kfree_const(mnt->mnt_devname);
764 729 #ifdef CONFIG_SMP
765 730 free_percpu(mnt->mnt_pcp);
@@ -781,13 +746,13 @@ int __legitimize_mnt(struct vfsmount *bastard, unsigned seq)
781 746 if (bastard == NULL)
782 747 return 0;
783 748 mnt = real_mount(bastard);
784 - mnt_inc_count(mnt);
785 - smp_mb(); /* see mntput_no_expire_slowpath() and do_umount() */
749 + mnt_add_count(mnt, 1);
750 + smp_mb(); // see mntput_no_expire() and do_umount()
786 751 if (likely(!read_seqretry(&mount_lock, seq)))
787 752 return 0;
788 753 lock_mount_hash();
789 754 if (unlikely(bastard->mnt_flags & (MNT_SYNC_UMOUNT | MNT_DOOMED))) {
790 - mnt_dec_count(mnt);
755 + mnt_add_count(mnt, -1);
791 756 unlock_mount_hash();
792 757 return 1;
793 758 }
@@ -816,31 +781,20 @@ static bool legitimize_mnt(struct vfsmount *bastard, unsigned seq)
816 781 * @dentry: dentry of mountpoint
817 782 *
818 783 * If @mnt has a child mount @c mounted on @dentry find and return it.
819 - * If @mnt is unmounted and a child that was unmounted with it left its
820 - * cover behind at @dentry, return the stand-in for it instead: knullfs
821 - * for a directory, its regular file for anything else.
822 784 * Caller must either hold the spinlock component of @mount_lock or
823 785 * hold rcu_read_lock(), sample the seqcount component before the call
824 786 * and recheck it afterwards.
825 787 *
826 - * Return: The child of @mnt mounted on @dentry, a stand-in or %NULL.
788 + * Return: The child of @mnt mounted on @dentry or %NULL.
827 789 */
828 790 struct mount *__lookup_mnt(struct vfsmount *mnt, struct dentry *dentry)
829 791 {
830 792 struct hlist_head *head = m_hash(mnt, dentry);
831 - struct mnt_cover *cover;
832 793 struct mount *p;
833 794
834 795 hlist_for_each_entry_rcu(p, head, mnt_hash)
835 796 if (&p->mnt_parent->mnt == mnt && p->mnt_mountpoint == dentry)
836 797 return p;
837 - /* an unmounted mount keeps the covers its unmounted children left */
838 - /* a lockless caller rechecks mount_lock after a miss, a stale flag is harmless */
839 - if (unlikely(data_race(mnt->mnt_flags) & MNT_UMOUNT)) {
840 - hlist_for_each_entry_rcu(cover, &real_mount(mnt)->mnt_covers, node)
841 - if (cover->dentry == dentry)
842 - return real_mount(d_is_dir(dentry) ? knullfs : knullfs_file);
843 - }
844 798 return NULL;
845 799 }
846 800
@@ -956,7 +910,6 @@ mountpoint:
956 910 mp->m_dentry = dget(dentry);
957 911 hlist_add_head(&mp->m_hash, mp_hash(dentry));
958 912 INIT_HLIST_HEAD(&mp->m_list);
959 - INIT_HLIST_HEAD(&mp->m_covers);
960 913 hlist_add_head(&m->node, &mp->m_list);
961 914 m->mp = no_free_ptr(mp);
962 915 read_sequnlock_excl(&mount_lock);
@@ -969,7 +922,7 @@ mountpoint:
969 922 */
970 923 static void maybe_free_mountpoint(struct mountpoint *mp, struct list_head *list)
971 924 {
972 - if (hlist_empty(&mp->m_list) && hlist_empty(&mp->m_covers)) {
925 + if (hlist_empty(&mp->m_list)) {
973 926 struct dentry *dentry = mp->m_dentry;
974 927 spin_lock(&dentry->d_lock);
975 928 dentry->d_flags &= ~DCACHE_MOUNTED;
@@ -1056,36 +1009,6 @@ static void umount_mnt(struct mount *mnt)
1056 1009 __umount_mnt(mnt, &ex_mountpoints);
1057 1010 }
1058 1011
1059 - /*
1060 - * @mnt is unmounted together with its parent and would have stayed attached
1061 - * to it. Leave its cover behind before it is detached so that a lookup on the
1062 - * parent at the mountpoint keeps finding a mount instead of what @mnt covered.
1063 - *
1064 - * locks: mount_lock[write_seqlock]
1065 - */
1066 - static void leave_cover(struct mount *mnt)
1067 - {
1068 - struct mnt_cover *cover = mnt->mnt_cover;
1069 -
1070 - mnt->mnt_cover = NULL;
1071 - cover->dentry = mnt->mnt_mountpoint;
1072 - cover->mp = mnt->mnt_mp;
1073 - /* keeps the mountpoint once @mnt has let go of it */
1074 - hlist_add_head(&cover->pin, &cover->mp->m_covers);
1075 - hlist_add_head_rcu(&cover->node, &mnt->mnt_parent->mnt_covers);
1076 - }
1077 -
1078 - /*
1079 - * locks: mount_lock[write_seqlock]
1080 - */
1081 - static void drop_cover(struct mnt_cover *cover, struct list_head *shrink_list)
1082 - {
1083 - hlist_del_rcu(&cover->node);
1084 - hlist_del(&cover->pin);
1085 - maybe_free_mountpoint(cover->mp, shrink_list);
1086 - kfree_rcu(cover, rcu);
1087 - }
1088 -
1089 1012 /*
1090 1013 * vfsmount lock must be held for write
1091 1014 */
@@ -1135,10 +1058,7 @@ static void attach_mnt(struct mount *mnt, struct mount *parent,
1135 1058 void mnt_change_mountpoint(struct mount *parent, struct mountpoint *mp, struct mount *mnt)
1136 1059 {
1137 1060 struct mountpoint *old_mp = mnt->mnt_mp;
1138 - struct mount *old_parent = mnt->mnt_parent;
1139 1061
1140 - if (old_parent->overmount == mnt)
1141 - old_parent->overmount = NULL;
1142 1062 list_del_init(&mnt->mnt_child);
1143 1063 hlist_del_init(&mnt->mnt_mp_list);
1144 1064 hlist_del_init_rcu(&mnt->mnt_hash);
@@ -1334,7 +1254,6 @@ static struct mount *clone_mnt(struct mount *old, struct dentry *root,
1334 1254
1335 1255 mnt->mnt.mnt_flags = READ_ONCE(old->mnt.mnt_flags) &
1336 1256 ~MNT_INTERNAL_FLAGS;
1337 - mnt->mnt_t_flags = old->mnt_t_flags & T_UNBINDABLE;
1338 1257
1339 1258 if (flag & (CL_SLAVE | CL_PRIVATE))
1340 1259 mnt->mnt_group_id = 0; /* not a peer of original */
@@ -1377,6 +1296,8 @@ static struct mount *clone_mnt(struct mount *old, struct dentry *root,
1377 1296
1378 1297 static void cleanup_mnt(struct mount *mnt)
1379 1298 {
1299 + struct hlist_node *p;
1300 + struct mount *m;
1380 1301 /*
1381 1302 * The warning here probably indicates that somebody messed
1382 1303 * up a mnt_want/drop_write() pair. If this happens, the
@@ -1387,6 +1308,10 @@ static void cleanup_mnt(struct mount *mnt)
1387 1308 WARN_ON(mnt_get_writers(mnt));
1388 1309 if (unlikely(mnt->mnt_pins.first))
1389 1310 mnt_pin_kill(mnt);
1311 + hlist_for_each_entry_safe(m, p, &mnt->mnt_stuck_children, mnt_umount) {
1312 + hlist_del(&m->mnt_umount);
1313 + mntput(&m->mnt);
1314 + }
1390 1315 fsnotify_vfsmount_delete(&mnt->mnt);
1391 1316 dput(mnt->mnt.mnt_root);
1392 1317 deactivate_super(mnt->mnt.mnt_sb);
@@ -1412,8 +1337,6 @@ static DECLARE_DELAYED_WORK(delayed_mntput_work, delayed_mntput);
1412 1337
1413 1338 static void noinline mntput_no_expire_slowpath(struct mount *mnt)
1414 1339 {
1415 - struct mnt_cover *cover;
1416 - struct hlist_node *n;
1417 1340 LIST_HEAD(list);
1418 1341 int count;
1419 1342
@@ -1424,7 +1347,7 @@ static void noinline mntput_no_expire_slowpath(struct mount *mnt)
1424 1347 * mount_lock, we'll see their refcount increment here.
1425 1348 */
1426 1349 smp_mb();
1427 - mnt_dec_count(mnt);
1350 + mnt_add_count(mnt, -1);
1428 1351 count = mnt_get_count(mnt);
1429 1352 if (count != 0) {
1430 1353 WARN_ON(count < 0);
@@ -1444,10 +1367,13 @@ static void noinline mntput_no_expire_slowpath(struct mount *mnt)
1444 1367 if (unlikely(!list_empty(&mnt->mnt_expire)))
1445 1368 list_del(&mnt->mnt_expire);
1446 1369
1447 - /* nothing stays attached to an unmounted mount */
1448 - VFS_WARN_ON_ONCE(!list_empty(&mnt->mnt_mounts));
1449 - hlist_for_each_entry_safe(cover, n, &mnt->mnt_covers, node)
1450 - drop_cover(cover, &list);
1370 + if (unlikely(!list_empty(&mnt->mnt_mounts))) {
1371 + struct mount *p, *tmp;
1372 + list_for_each_entry_safe(p, tmp, &mnt->mnt_mounts, mnt_child) {
1373 + __umount_mnt(p, &list);
1374 + hlist_add_head(&p->mnt_umount, &mnt->mnt_stuck_children);
1375 + }
1376 + }
1451 1377 unlock_mount_hash();
1452 1378 shrink_dentry_list(&list);
1453 1379
@@ -1478,8 +1404,7 @@ static void mntput_no_expire(struct mount *mnt)
1478 1404 * non-NULL under rcu_read_lock(), the reference
1479 1405 * we are dropping is not the final one.
1480 1406 */
1481 - smp_wmb(); /* pairs with the smp_mb() in mnt_get_count() */
1482 - mnt_dec_count(mnt);
1407 + mnt_add_count(mnt, -1);
1483 1408 rcu_read_unlock();
1484 1409 return;
1485 1410 }
@@ -1501,7 +1426,7 @@ EXPORT_SYMBOL(mntput);
1501 1426 struct vfsmount *mntget(struct vfsmount *mnt)
1502 1427 {
1503 1428 if (mnt)
1504 - mnt_inc_count(real_mount(mnt));
1429 + mnt_add_count(real_mount(mnt), 1);
1505 1430 return mnt;
1506 1431 }
1507 1432 EXPORT_SYMBOL(mntget);
@@ -1812,17 +1737,36 @@ static inline void namespace_lock(void)
1812 1737 enum umount_tree_flags {
1813 1738 UMOUNT_SYNC = 1,
1814 1739 UMOUNT_PROPAGATE = 2,
1815 - UMOUNT_COVER = 4,
1740 + UMOUNT_CONNECTED = 4,
1816 1741 };
1817 1742
1818 - /* Do we need to leave the mountpoint on the parent covered? */
1819 - static bool needs_cover(struct mount *mnt, enum umount_tree_flags how)
1743 + static bool disconnect_mount(struct mount *mnt, enum umount_tree_flags how)
1820 1744 {
1745 + /* Leaving mounts connected is only valid for lazy umounts */
1821 1746 if (how & UMOUNT_SYNC)
1822 - return false;
1747 + return true;
1748 +
1749 + /* A mount without a parent has nothing to be connected to */
1750 + if (!mnt_has_parent(mnt))
1751 + return true;
1752 +
1753 + /* Because the reference counting rules change when mounts are
1754 + * unmounted and connected, umounted mounts may not be
1755 + * connected to mounted mounts.
1756 + */
1823 1757 if (!(mnt->mnt_parent->mnt.mnt_flags & MNT_UMOUNT))
1758 + return true;
1759 +
1760 + /* Has it been requested that the mount remain connected? */
1761 + if (how & UMOUNT_CONNECTED)
1824 1762 return false;
1825 - return (how & UMOUNT_COVER) || IS_MNT_LOCKED(mnt);
1763 +
1764 + /* Is the mount locked such that it needs to remain connected? */
1765 + if (IS_MNT_LOCKED(mnt))
1766 + return false;
1767 +
1768 + /* By default disconnect the mount */
1769 + return true;
1826 1770 }
1827 1771
1828 1772 /*
@@ -1839,8 +1783,6 @@ static void umount_tree(struct mount *mnt, enum umount_tree_flags how)
1839 1783
1840 1784 /* Gather the mounts to umount */
1841 1785 for (p = mnt; p; p = next_mnt(p, mnt)) {
1842 - /* A mount is unmounted once. */
1843 - VFS_WARN_ON_ONCE(p->mnt.mnt_flags & MNT_UMOUNT);
1844 1786 p->mnt.mnt_flags |= MNT_UMOUNT;
1845 1787 if (mnt_ns_attached(p))
1846 1788 move_from_ns(p);
@@ -1860,6 +1802,7 @@ static void umount_tree(struct mount *mnt, enum umount_tree_flags how)
1860 1802
1861 1803 while (!list_empty(&tmp_list)) {
1862 1804 struct mnt_namespace *ns;
1805 + bool disconnect;
1863 1806 p = list_first_entry(&tmp_list, struct mount, mnt_list);
1864 1807 list_del_init(&p->mnt_expire);
1865 1808 list_del_init(&p->mnt_list);
@@ -1872,12 +1815,17 @@ static void umount_tree(struct mount *mnt, enum umount_tree_flags how)
1872 1815 if (how & UMOUNT_SYNC)
1873 1816 p->mnt.mnt_flags |= MNT_SYNC_UMOUNT;
1874 1817
1818 + disconnect = disconnect_mount(p, how);
1875 1819 if (mnt_has_parent(p)) {
1876 - if (needs_cover(p, how))
1877 - leave_cover(p);
1878 - umount_mnt(p);
1820 + if (!disconnect) {
1821 + /* Don't forget about p */
1822 + list_add_tail(&p->mnt_child, &p->mnt_parent->mnt_mounts);
1823 + } else {
1824 + umount_mnt(p);
1825 + }
1879 1826 }
1880 - hlist_add_head(&p->mnt_umount, &unmounted);
1827 + if (disconnect)
1828 + hlist_add_head(&p->mnt_umount, &unmounted);
1881 1829
1882 1830 /*
1883 1831 * At this point p->mnt_ns is NULL, notification will be queued
@@ -2028,16 +1976,11 @@ out:
2028 1976 * detach_mounts allows lazily unmounting those mounts instead of
2029 1977 * leaking them.
2030 1978 *
2031 - * The dentry is unhashed before the mounts go so that no lookup finds
2032 - * what they covered. The caller removes it for good afterwards.
2033 - *
2034 1979 * The caller may hold dentry->d_inode->i_rwsem.
2035 1980 */
2036 1981 void __detach_mounts(struct dentry *dentry)
2037 1982 {
2038 1983 struct pinned_mountpoint mp = {};
2039 - struct mnt_cover *cover;
2040 - struct hlist_node *n;
2041 1984 struct mount *mnt;
2042 1985
2043 1986 guard(namespace_excl)();
@@ -2046,16 +1989,15 @@ void __detach_mounts(struct dentry *dentry)
2046 1989 if (!lookup_mountpoint(dentry, &mp))
2047 1990 return;
2048 1991
2049 - /* the name goes first, what covered it goes second */
2050 - d_drop(dentry);
2051 1992 event++;
2052 1993 while (mp.node.next) {
2053 1994 mnt = hlist_entry(mp.node.next, struct mount, mnt_mp_list);
2054 - umount_tree(mnt, UMOUNT_COVER);
1995 + if (mnt->mnt.mnt_flags & MNT_UMOUNT) {
1996 + umount_mnt(mnt);
1997 + hlist_add_head(&mnt->mnt_umount, &unmounted);
1998 + }
1999 + else umount_tree(mnt, UMOUNT_CONNECTED);
2055 2000 }
2056 - /* the dentry goes away, so do the covers left behind on it */
2057 - hlist_for_each_entry_safe(cover, n, &mp.mp->m_covers, pin)
2058 - drop_cover(cover, &ex_mountpoints);
2059 2001 unpin_mountpoint(&mp);
2060 2002 }
2061 2003
@@ -2352,11 +2294,9 @@ void drop_collected_paths(const struct path *paths, const struct path *prealloc)
2352 2294
2353 2295 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *, bool);
2354 2296
2355 - /* Consumes the caller's reference to @mnt. */
2356 2297 void dissolve_on_fput(struct vfsmount *mnt)
2357 2298 {
2358 - struct vfsmount *p __free(mntput) = mnt;
2359 - struct mount *m = real_mount(p);
2299 + struct mount *m = real_mount(mnt);
2360 2300
2361 2301 /*
2362 2302 * m used to be the root of anon namespace; if it still is one,
@@ -2379,14 +2319,13 @@ void dissolve_on_fput(struct vfsmount *mnt)
2379 2319
2380 2320 emptied_ns = m->mnt_ns;
2381 2321 lock_mount_hash();
2382 - umount_tree(m, UMOUNT_COVER);
2322 + umount_tree(m, UMOUNT_CONNECTED);
2383 2323 unlock_mount_hash();
2384 - mntput(no_free_ptr(p));
2385 2324 }
2386 2325 }
2387 2326
2388 2327 /* locks: namespace_shared && pinned(mnt) || mount_locked_reader */
2389 - bool has_locked_children(struct mount *mnt, struct dentry *dentry)
2328 + static bool __has_locked_children(struct mount *mnt, struct dentry *dentry)
2390 2329 {
2391 2330 struct mount *child;
2392 2331
@@ -2400,16 +2339,10 @@ bool has_locked_children(struct mount *mnt, struct dentry *dentry)
2400 2339 return false;
2401 2340 }
2402 2341
2403 - /* locks: namespace_shared && pinned(mnt) || mount_locked_reader */
2404 - static bool __has_children(struct mount *mnt, struct dentry *dentry)
2342 + bool has_locked_children(struct mount *mnt, struct dentry *dentry)
2405 2343 {
2406 - struct mount *child;
2407 -
2408 - list_for_each_entry(child, &mnt->mnt_mounts, mnt_child) {
2409 - if (is_subdir(child->mnt_mountpoint, dentry))
2410 - return true;
2411 - }
2412 - return false;
2344 + guard(mount_locked_reader)();
2345 + return __has_locked_children(mnt, dentry);
2413 2346 }
2414 2347
2415 2348 /*
@@ -2468,7 +2401,7 @@ struct vfsmount *clone_private_mount(const struct path *path)
2468 2401 if (!ns_capable(old_mnt->mnt_ns->user_ns, CAP_SYS_ADMIN))
2469 2402 return ERR_PTR(-EPERM);
2470 2403
2471 - if (has_locked_children(old_mnt, path->dentry))
2404 + if (__has_locked_children(old_mnt, path->dentry))
2472 2405 return ERR_PTR(-EINVAL);
2473 2406
2474 2407 new_mnt = clone_mnt(old_mnt, path->dentry, CL_PRIVATE);
@@ -2631,11 +2564,11 @@ enum mnt_tree_flags_t {
2631 2564 static int attach_recursive_mnt(struct mount *source_mnt,
2632 2565 const struct pinned_mountpoint *dest)
2633 2566 {
2567 + struct user_namespace *user_ns = current->nsproxy->mnt_ns->user_ns;
2634 2568 struct mount *dest_mnt = dest->parent;
2635 2569 struct mountpoint *dest_mp = dest->mp;
2636 2570 HLIST_HEAD(tree_list);
2637 2571 struct mnt_namespace *ns = dest_mnt->mnt_ns;
2638 - struct user_namespace *user_ns = ns->user_ns;
2639 2572 struct pinned_mountpoint root = {};
2640 2573 struct mountpoint *shorter = NULL;
2641 2574 struct mount *child, *p;
@@ -2644,31 +2577,13 @@ static int attach_recursive_mnt(struct mount *source_mnt,
2644 2577 int err = 0;
2645 2578 bool moving = mnt_has_parent(source_mnt);
2646 2579
2647 - /*
2648 - * A caller in an unprivileged mount namespaces may trigger an
2649 - * automount and propagate locked mounts into privileged mount
2650 - * namespaces. Take ownership from the target mount namespace.
2651 - * It's equivalent for everything but the automount case.
2652 - *
2653 - * Detached trees in anonymous mount namespaces by be handed
2654 - * over via SCM_RIGHTS or inherited in other ways on purpose
2655 - * the attaching task's mount namespace is authoritative, not
2656 - * the creator of the detached tree.
2657 - */
2658 - if (is_anon_ns(ns))
2659 - user_ns = current->nsproxy->mnt_ns->user_ns;
2660 - else
2661 - user_ns = ns->user_ns;
2662 -
2663 2580 /*
2664 2581 * Preallocate a mountpoint in case the new mounts need to be
2665 2582 * mounted beneath mounts on the same mountpoint.
2666 2583 */
2667 - for (top = source_mnt; ; top = top->overmount) {
2584 + for (top = source_mnt; unlikely(top->overmount); top = top->overmount) {
2668 2585 if (!shorter && is_mnt_ns_file(top->mnt.mnt_root))
2669 2586 shorter = top->mnt_mp;
2670 - if (likely(!top->overmount))
2671 - break;
2672 2587 }
2673 2588 err = get_mountpoint(top->mnt.mnt_root, &root);
2674 2589 if (err)
@@ -2739,17 +2654,15 @@ static int attach_recursive_mnt(struct mount *source_mnt,
2739 2654 /*
2740 2655 * If @q was locked it was meant to hide
2741 2656 * whatever was under it. Let @child take over
2742 - * that job and lock it. If @child is the mount
2743 - * the caller placed we can then unlock @q:
2744 - * nothing another namespace does removes it
2745 - * again. A propagated copy goes away when the
2746 - * mounter of the original unmounts it, so @q
2747 - * keeps its lock.
2657 + * that job and lock it, then we can unlock @q.
2658 + * That'll allow another namespace to shed @q
2659 + * and reveal @child. Clearly, that mounter
2660 + * consented to this by not severing the mount
2661 + * relationship. Otherwise, what's the point.
2748 2662 */
2749 2663 if (IS_MNT_LOCKED(q)) {
2750 2664 child->mnt.mnt_flags |= MNT_LOCKED;
2751 - if (child == source_mnt)
2752 - q->mnt.mnt_flags &= ~MNT_LOCKED;
2665 + q->mnt.mnt_flags &= ~MNT_LOCKED;
2753 2666 }
2754 2667 mnt_change_mountpoint(r, mp, q);
2755 2668 }
@@ -2846,11 +2759,6 @@ static void do_lock_mount(const struct path *path,
2846 2759
2847 2760 scoped_guard(mount_locked_reader) {
2848 2761 m = where_to_mount(path, &dentry, beneath);
2849 - /* sticky, so it takes no locks to refuse it */
2850 - if (unlikely(cant_mount(dentry))) {
2851 - res->parent = ERR_PTR(-ENOENT);
2852 - return;
2853 - }
2854 2762 if (&m->mnt != path->mnt) {
2855 2763 mntget(&m->mnt);
2856 2764 dget(dentry);
@@ -3081,14 +2989,7 @@ static struct mount *__do_loopback(const struct path *old_path,
3081 2989 if (!may_copy_tree(old_path))
3082 2990 return ERR_PTR(-EINVAL);
3083 2991
3084 - /* a pseudo dentry is freed without an RCU delay, no walk may find it */
3085 - if (old_path->dentry->d_flags & DCACHE_NORCU)
3086 - return ERR_PTR(-EINVAL);
3087 -
3088 - if (recurse && !old->mnt_ns)
3089 - return ERR_PTR(-EINVAL);
3090 -
3091 - if (!recurse && has_locked_children(old, old_path->dentry))
2992 + if (!recurse && __has_locked_children(old, old_path->dentry))
3092 2993 return ERR_PTR(-EINVAL);
3093 2994
3094 2995 if (recurse)
@@ -3127,11 +3028,7 @@ static int do_loopback(const struct path *path, const char *old_name,
3127 3028 if (IS_ERR(mnt))
3128 3029 return PTR_ERR(mnt);
3129 3030
3130 - /* the copy may carry mount namespace files from below the source */
3131 - if (recurse && !check_for_nsfs_mounts(mnt))
3132 - err = -EINVAL;
3133 - else
3134 - err = graft_tree(mnt, &mp);
3031 + err = graft_tree(mnt, &mp);
3135 3032 if (err) {
3136 3033 lock_mount_hash();
3137 3034 umount_tree(mnt, UMOUNT_SYNC);
@@ -3191,7 +3088,7 @@ static struct file *open_detached_copy(struct path *path, unsigned int flags)
3191 3088 path->mnt = mntget(&ns->root->mnt);
3192 3089 file = dentry_open(path, O_PATH, current_cred());
3193 3090 if (IS_ERR(file))
3194 - dissolve_on_fput(no_free_ptr(path->mnt));
3091 + dissolve_on_fput(path->mnt);
3195 3092 else
3196 3093 file->f_mode |= FMODE_NEED_UNMOUNT;
3197 3094 return file;
@@ -3213,18 +3110,12 @@ static struct mnt_namespace *create_new_namespace(struct path *path,
3213 3110 struct mount *mnt;
3214 3111 unsigned int copy_flags = 0;
3215 3112 bool locked = false, recurse = flags & MOUNT_COPY_RECURSIVE;
3216 - bool foreign = user_ns != ns->user_ns;
3217 3113
3218 3114 if (unlikely(!d_can_lookup(path->dentry)))
3219 3115 return ERR_PTR(-ENOTDIR);
3220 3116
3221 - /*
3222 - * Without privileges over the mount namespace the copy is made from
3223 - * nothing mounted below @path may be left out. It would reveal what
3224 - * it covers. That's what unshare() gives such a caller as well.
3225 - */
3226 - if (foreign)
3227 - copy_flags |= CL_SLAVE | CL_COPY_UNBINDABLE;
3117 + if (user_ns != ns->user_ns)
3118 + copy_flags |= CL_SLAVE;
3228 3119
3229 3120 new_ns = alloc_mnt_ns(user_ns, false);
3230 3121 if (IS_ERR(new_ns))
@@ -3258,14 +3149,10 @@ static struct mnt_namespace *create_new_namespace(struct path *path,
3258 3149 /*
3259 3150 * We don't emulate unshare()ing a mount namespace. We stick to
3260 3151 * the restrictions of creating detached bind-mounts. It has a
3261 - * lot saner and simpler semantics. A caller without privileges
3262 - * over the mount namespace can't leave out any child though.
3152 + * lot saner and simpler semantics.
3263 3153 */
3264 3154 if (flags & MOUNT_COPY_NEW)
3265 3155 mnt = clone_mnt(real_mount(path->mnt), path->dentry, copy_flags);
3266 - else if (foreign && !recurse &&
3267 - __has_children(real_mount(path->mnt), path->dentry))
3268 - mnt = ERR_PTR(-EINVAL);
3269 3156 else
3270 3157 mnt = __do_loopback(path, recurse, copy_flags);
3271 3158 scoped_guard(mount_writer) {
@@ -3282,7 +3169,7 @@ static struct mnt_namespace *create_new_namespace(struct path *path,
3282 3169 * of the real rootfs we created.
3283 3170 */
3284 3171 attach_mnt(mnt, new_ns_root, mp.mp);
3285 - if (foreign)
3172 + if (user_ns != ns->user_ns)
3286 3173 lock_mnt_tree(new_ns_root);
3287 3174 }
3288 3175
@@ -3576,11 +3463,11 @@ static int do_set_group(const struct path *from_path, const struct path *to_path
3576 3463 return -EINVAL;
3577 3464
3578 3465 /* From mount should not have locked children in place of To's root */
3579 - if (has_locked_children(from, to->mnt.mnt_root))
3466 + if (__has_locked_children(from, to->mnt.mnt_root))
3580 3467 return -EINVAL;
3581 3468
3582 3469 /* Setting sharing groups is only allowed on private mounts */
3583 - if (IS_MNT_SHARED(to) || IS_MNT_SLAVE(to) || IS_MNT_UNBINDABLE(to))
3470 + if (IS_MNT_SHARED(to) || IS_MNT_SLAVE(to))
3584 3471 return -EINVAL;
3585 3472
3586 3473 /* From should not be private */
@@ -3856,7 +3743,7 @@ static int do_add_mount(struct mount *newmnt, const struct pinned_mountpoint *mp
3856 3743 if (!(mnt_flags & MNT_SHRINKABLE))
3857 3744 return -EINVAL;
3858 3745 /* ... and for those we'd better have mountpoint still alive */
3859 - if (!is_mounted(&parent->mnt))
3746 + if (!parent->mnt_ns)
3860 3747 return -EINVAL;
3861 3748 }
3862 3749
@@ -4066,8 +3953,6 @@ void mark_mounts_for_expiry(struct list_head *mounts)
4066 3953 list_for_each_entry_safe(mnt, next, mounts, mnt_expire) {
4067 3954 if (!is_mounted(&mnt->mnt))
4068 3955 continue;
4069 - /* lock_mnt_tree() leaves expirable mounts alone */
4070 - VFS_WARN_ON_ONCE(IS_MNT_LOCKED(mnt));
4071 3956 if (!xchg(&mnt->mnt_expiry_mark, 1) ||
4072 3957 propagate_mount_busy(mnt, 1))
4073 3958 continue;
@@ -4075,11 +3960,6 @@ void mark_mounts_for_expiry(struct list_head *mounts)
4075 3960 }
4076 3961 while (!list_empty(&graveyard)) {
4077 3962 mnt = list_first_entry(&graveyard, struct mount, mnt_expire);
4078 - /* an earlier umount_tree() may have moved a busy mount here */
4079 - if (propagate_mount_busy(mnt, 1)) {
4080 - list_move(&mnt->mnt_expire, mounts);
4081 - continue;
4082 - }
4083 3963 touch_mnt_namespace(mnt->mnt_ns);
4084 3964 umount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC);
4085 3965 }
@@ -4087,38 +3967,17 @@ void mark_mounts_for_expiry(struct list_head *mounts)
4087 3967
4088 3968 EXPORT_SYMBOL_GPL(mark_mounts_for_expiry);
4089 3969
4090 - /*
4091 - * Unmount @mnt if it's a shrinkable mount without children that nobody uses.
4092 - *
4093 - * mount_lock must be held for write
4094 - */
4095 - static bool shrink_submount(struct mount *mnt)
4096 - {
4097 - /* not the kernel's to remove either */
4098 - if (IS_MNT_LOCKED(mnt) || propagate_mount_busy(mnt, 1))
4099 - return false;
4100 - touch_mnt_namespace(mnt->mnt_ns);
4101 - umount_tree(mnt, UMOUNT_PROPAGATE|UMOUNT_SYNC);
4102 - return true;
4103 - }
4104 -
4105 3970 /*
4106 3971 * Ripoff of 'select_parent()'
4107 3972 *
4108 - * unmount the shrinkable submounts of @parent that aren't busy, children
4109 - * before their parent, and say whether anything went
4110 - *
4111 - * The cursor into the children of @this_parent survives the umount of a
4112 - * child mount without child mounts. The mounts that get umounted together with
4113 - * it are located under receiving mounts of @this_parent and never under
4114 - * @this_parent itself. The one exception is @this_parent getting unmounted
4115 - * then the walk starts over.
3973 + * search the list of submounts for a given mountpoint, and move any
3974 + * shrinkable submounts to the 'graveyard' list.
4116 3975 */
4117 - static bool __shrink_submounts(struct mount *parent)
3976 + static int select_submounts(struct mount *parent, struct list_head *graveyard)
4118 3977 {
4119 3978 struct mount *this_parent = parent;
4120 3979 struct list_head *next;
4121 - bool shrunk = false;
3980 + int found = 0;
4122 3981
4123 3982 repeat:
4124 3983 next = this_parent->mnt_mounts.next;
@@ -4137,45 +3996,42 @@ resume:
4137 3996 this_parent = mnt;
4138 3997 goto repeat;
4139 3998 }
4140 - if (!shrink_submount(mnt))
4141 - continue;
4142 - shrunk = true;
4143 - if (unlikely(this_parent->mnt.mnt_flags & MNT_UMOUNT))
4144 - return true;
3999 +
4000 + if (!propagate_mount_busy(mnt, 1)) {
4001 + list_move_tail(&mnt->mnt_expire, graveyard);
4002 + found++;
4003 + }
4145 4004 }
4146 4005 /*
4147 4006 * All done at this level ... ascend and resume the search
4148 4007 */
4149 4008 if (this_parent != parent) {
4150 - struct mount *mnt = this_parent;
4151 -
4152 - next = mnt->mnt_child.next;
4153 - this_parent = mnt->mnt_parent;
4154 - /* its children are gone, maybe it can go as well */
4155 - if (shrink_submount(mnt)) {
4156 - shrunk = true;
4157 - if (unlikely(this_parent->mnt.mnt_flags & MNT_UMOUNT))
4158 - return true;
4159 - }
4009 + next = this_parent->mnt_child.next;
4010 + this_parent = this_parent->mnt_parent;
4160 4011 goto resume;
4161 4012 }
4162 - return shrunk;
4013 + return found;
4163 4014 }
4164 4015
4165 4016 /*
4166 - * unmount the shrinkable submounts of @mnt that aren't busy
4167 - *
4168 - * The busy check and the umount of a mount are adjacent. An umount can
4169 - * still empty or move a mount in a part of the tree that was walked
4170 - * already, so walk again until nothing goes.
4017 + * process a list of expirable mountpoints with the intent of discarding any
4018 + * submounts of a specific parent mountpoint
4171 4019 *
4172 4020 * mount_lock must be held for write
4173 4021 */
4174 4022 static void shrink_submounts(struct mount *mnt)
4175 4023 {
4176 - for (;;) {
4177 - if (!__shrink_submounts(mnt))
4178 - break;
4024 + LIST_HEAD(graveyard);
4025 + struct mount *m;
4026 +
4027 + /* extract submounts of 'mountpoint' from the expiration list */
4028 + while (select_submounts(mnt, &graveyard)) {
4029 + while (!list_empty(&graveyard)) {
4030 + m = list_first_entry(&graveyard, struct mount,
4031 + mnt_expire);
4032 + touch_mnt_namespace(m->mnt_ns);
4033 + umount_tree(m, UMOUNT_PROPAGATE|UMOUNT_SYNC);
4034 + }
4179 4035 }
4180 4036 }
4181 4037
@@ -4340,8 +4196,6 @@ static void free_mnt_ns(struct mnt_namespace *ns)
4340 4196 if (!is_anon_ns(ns))
4341 4197 ns_common_free(ns);
4342 4198 dec_mnt_namespaces(ns->ucounts);
4343 - /* the last active reference is gone, no mark can show up anymore */
4344 - fsnotify_mntns_delete(ns);
4345 4199 mnt_ns_tree_remove(ns);
4346 4200 }
4347 4201
@@ -4691,7 +4545,7 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags,
4691 4545 FD_PREPARE(fdf, (flags & FSMOUNT_CLOEXEC) ? O_CLOEXEC : 0,
4692 4546 dentry_open(&new_path, O_PATH, fc->cred));
4693 4547 if (fdf.err) {
4694 - dissolve_on_fput(no_free_ptr(new_path.mnt));
4548 + dissolve_on_fput(new_path.mnt);
4695 4549 return fdf.err;
4696 4550 }
4697 4551
@@ -4843,15 +4697,14 @@ int path_pivot_root(struct path *new, struct path *old)
4843 4697
4844 4698 new_mnt = real_mount(new->mnt);
4845 4699 root_mnt = real_mount(root.mnt);
4846 - /* only a mounted mount has a parent that namespace_sem pins */
4847 - if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
4848 - return -EINVAL;
4849 4700 ex_parent = new_mnt->mnt_parent;
4850 4701 root_parent = root_mnt->mnt_parent;
4851 4702 if (IS_MNT_SHARED(old_mnt) ||
4852 4703 IS_MNT_SHARED(ex_parent) ||
4853 4704 IS_MNT_SHARED(root_parent))
4854 4705 return -EINVAL;
4706 + if (!check_mnt(root_mnt) || !check_mnt(new_mnt))
4707 + return -EINVAL;
4855 4708 if (new_mnt->mnt.mnt_flags & MNT_LOCKED)
4856 4709 return -EINVAL;
4857 4710 if (d_unlinked(new->dentry))
@@ -5102,11 +4955,6 @@ static int do_mount_setattr(const struct path *path, struct mount_kattr *kattr)
5102 4955 * propagation.
5103 4956 */
5104 4957 namespace_lock();
5105 - /* invent_group_ids() walks the tree, only walk a mounted one */
5106 - if (!anon_ns_root(mnt) && !check_mnt(mnt)) {
5107 - namespace_unlock();
5108 - return -EINVAL;
5109 - }
5110 4958 if (kattr->propagation == MS_SHARED) {
5111 4959 err = invent_group_ids(mnt, kattr->kflags & MOUNT_KATTR_RECURSE);
5112 4960 if (err) {
@@ -5119,7 +4967,6 @@ static int do_mount_setattr(const struct path *path, struct mount_kattr *kattr)
5119 4967 err = -EINVAL;
5120 4968 lock_mount_hash();
5121 4969
5122 - /* Checked under namespace_sem already if the propagation changes. */
5123 4970 if (!anon_ns_root(mnt) && !check_mnt(mnt))
5124 4971 goto out;
5125 4972
@@ -5472,25 +5319,15 @@ static void statmount_sb_basic(struct kstatmount *s)
5472 5319 s->sm.sb_flags = sb->s_flags & (SB_RDONLY|SB_SYNCHRONOUS|SB_DIRSYNC|SB_LAZYTIME);
5473 5320 }
5474 5321
5475 - static void statmount_mnt_parent(struct kstatmount *s, const struct mount *m)
5476 - {
5477 - s->sm.mnt_parent_id = m->mnt_parent->mnt_id_unique;
5478 - s->sm.mnt_parent_id_old = m->mnt_parent->mnt_id;
5479 - }
5480 -
5481 5322 static void statmount_mnt_basic(struct kstatmount *s)
5482 5323 {
5483 5324 struct mount *m = real_mount(s->mnt);
5484 5325
5485 5326 s->sm.mask |= STATMOUNT_MNT_BASIC;
5486 5327 s->sm.mnt_id = m->mnt_id_unique;
5328 + s->sm.mnt_parent_id = m->mnt_parent->mnt_id_unique;
5487 5329 s->sm.mnt_id_old = m->mnt_id;
5488 - /* An unmounted mount is cut loose from its parent under mount_lock alone. */
5489 - if (likely(is_mounted(s->mnt)))
5490 - statmount_mnt_parent(s, m);
5491 - else
5492 - scoped_guard(mount_locked_reader)
5493 - statmount_mnt_parent(s, m);
5330 + s->sm.mnt_parent_id_old = m->mnt_parent->mnt_id;
5494 5331 s->sm.mnt_attr = mnt_to_attr_flags(&m->mnt);
5495 5332 s->sm.mnt_propagation = mnt_to_propagation_flags(m);
5496 5333 s->sm.mnt_peer_group = m->mnt_group_id;
@@ -6362,25 +6199,6 @@ static void __init mount_rootfs_on_nullfs(struct vfsmount *mnt,
6362 6199 attach_mnt(real_mount(mnt), mp.parent, mp.mp);
6363 6200 }
6364 6201
6365 - static struct vfsmount *__init knullfs_file_mount(void)
6366 - {
6367 - struct dentry *file;
6368 - struct mount *mnt;
6369 -
6370 - file = nullfs_new_file(knullfs->mnt_sb);
6371 - if (IS_ERR(file))
6372 - return ERR_CAST(file);
6373 - mnt = clone_mnt(real_mount(knullfs), file, CL_PRIVATE);
6374 - dput(file);
6375 - if (IS_ERR(mnt))
6376 - return ERR_CAST(mnt);
6377 - mnt->mnt_ns = MNT_NS_INTERNAL;
6378 - mnt->mnt.mnt_flags |= MNT_INTERNAL;
6379 - mnt->mnt.mnt_flags &= ~MNT_READONLY;
6380 - dont_mount(mnt->mnt.mnt_root);
6381 - return &mnt->mnt;
6382 - }
6383 -
6384 6202 static void __init init_mount_tree(void)
6385 6203 {
6386 6204 struct vfsmount *mnt, *nullfs_mnt;
@@ -6392,14 +6210,10 @@ static void __init init_mount_tree(void)
6392 6210 *
6393 6211 * (1) nullfs with mount id 1
6394 6212 * (2) mutable rootfs with mount id 2
6395 - * (3) private nullfs for kthreads (SB_KERNMOUNT), kept in knullfs
6396 - * (4) a second mount of (3) rooted on a regular file, kept in
6397 - * knullfs_file
6213 + * (3) private nullfs for kthreads (SB_KERNMOUNT)
6398 6214 *
6399 6215 * with (2) mounted on top of (1). The init_task's root and pwd
6400 6216 * are pointed at (3) so all kthreads start isolated in nullfs.
6401 - * A lookup at the cover an unmounted mount left behind finds (3)
6402 - * or (4), see __lookup_mnt().
6403 6217 */
6404 6218 nullfs_mnt = vfs_kern_mount(&nullfs_fs_type, 0, "nullfs", NULL);
6405 6219 if (IS_ERR(nullfs_mnt))
@@ -6431,18 +6245,11 @@ static void __init init_mount_tree(void)
6431 6245 init_mnt_ns.nr_mounts++;
6432 6246 }
6433 6247
6434 - knullfs = kern_mount(&nullfs_fs_type);
6435 - if (IS_ERR(knullfs))
6248 + nullfs_mnt = kern_mount(&nullfs_fs_type);
6249 + if (IS_ERR(nullfs_mnt))
6436 6250 panic("VFS: Failed to create private nullfs instance");
6437 - /* nothing is ever mounted on the root of a kernel thread */
6438 - dont_mount(knullfs->mnt_root);
6439 - /* and nothing is ever written through it */
6440 - knullfs->mnt_flags |= MNT_READONLY;
6441 - knullfs_file = knullfs_file_mount();
6442 - if (IS_ERR(knullfs_file))
6443 - panic("VFS: Failed to create the nullfs file stand-in");
6444 - root.mnt = knullfs;
6445 - root.dentry = knullfs->mnt_root;
6251 + root.mnt = nullfs_mnt;
6252 + root.dentry = nullfs_mnt->mnt_root;
6446 6253
6447 6254 init_task.nsproxy->mnt_ns = &init_mnt_ns;
6448 6255 get_mnt_ns(&init_mnt_ns);
modified fs/notify/mark.c
@@ -903,10 +903,6 @@ static int fsnotify_add_mark_list(struct fsnotify_mark *mark, void *obj,
903 903 if (WARN_ON(!fsnotify_valid_obj_type(obj_type)))
904 904 return -EINVAL;
905 905
906 - /* the filesystem doesn't want its objects watched */
907 - if (sb && (sb->s_type->fs_flags & FS_DISALLOW_NOTIFY))
908 - return -EINVAL;
909 -
910 906 /*
911 907 * Attach the sb info before attaching a connector to any object on sb.
912 908 * The sb info will remain attached as long as sb lives.
modified fs/nullfs.c
@@ -3,8 +3,6 @@
3 3 #include <linux/fs/super_types.h>
4 4 #include <linux/fs_context.h>
5 5 #include <linux/magic.h>
6 - #include <linux/splice.h>
7 - #include <linux/uio.h>
8 6
9 7 #include "mount.h"
10 8
@@ -12,121 +10,6 @@ static const struct super_operations nullfs_super_operations = {
12 10 .statfs = simple_statfs,
13 11 };
14 12
15 - static loff_t nullfs_dir_llseek(struct file *file, loff_t offset, int whence)
16 - {
17 - /* an empty directory has two entries . and .. at offsets 0 and 1 */
18 - return generic_file_llseek_size(file, offset, whence, 2, 2);
19 - }
20 -
21 - static int nullfs_dir_readdir(struct file *file, struct dir_context *ctx)
22 - {
23 - dir_emit_dots(file, ctx);
24 - return 0;
25 - }
26 -
27 - /* the one inode of nullfs is shared by every holder, so no locks on it */
28 - static int nullfs_nolock(struct file *file, int cmd, struct file_lock *fl)
29 - {
30 - return -ENOLCK;
31 - }
32 -
33 - /* what libfs gives an empty directory, plus the refusal of file locks */
34 - static const struct file_operations nullfs_dir_operations = {
35 - .llseek = nullfs_dir_llseek,
36 - .read = generic_read_dir,
37 - .iterate_shared = nullfs_dir_readdir,
38 - .fsync = noop_fsync,
39 - .lock = nullfs_nolock,
40 - .flock = nullfs_nolock,
41 - .fop_flags = FOP_IMMUTABLE,
42 - };
43 -
44 - static ssize_t nullfs_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
45 - {
46 - return 0;
47 - }
48 -
49 - static ssize_t nullfs_file_splice_read(struct file *in, loff_t *ppos,
50 - struct pipe_inode_info *pipe,
51 - size_t len, unsigned int flags)
52 - {
53 - return 0;
54 - }
55 -
56 - static ssize_t nullfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
57 - {
58 - size_t count = iov_iter_count(from);
59 -
60 - iov_iter_advance(from, count);
61 - return count;
62 - }
63 -
64 - static int nullfs_pipe_to_null(struct pipe_inode_info *pipe,
65 - struct pipe_buffer *buf, struct splice_desc *sd)
66 - {
67 - return sd->len;
68 - }
69 -
70 - static ssize_t nullfs_file_splice_write(struct pipe_inode_info *pipe,
71 - struct file *out, loff_t *ppos,
72 - size_t len, unsigned int flags)
73 - {
74 - return splice_from_pipe(pipe, out, ppos, len, flags, nullfs_pipe_to_null);
75 - }
76 -
77 - static int nullfs_file_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
78 - struct iattr *attr)
79 - {
80 - if (attr->ia_valid & (ATTR_MODE | ATTR_UID | ATTR_GID))
81 - return -EPERM;
82 - return 0;
83 - }
84 -
85 - static const struct inode_operations nullfs_file_inode_operations = {
86 - .setattr = nullfs_file_setattr,
87 - };
88 -
89 - static const struct file_operations nullfs_file_operations = {
90 - .llseek = generic_file_llseek,
91 - .read_iter = nullfs_file_read_iter,
92 - .write_iter = nullfs_file_write_iter,
93 - .splice_read = nullfs_file_splice_read,
94 - .splice_write = nullfs_file_splice_write,
95 - .fsync = noop_fsync,
96 - .lock = nullfs_nolock,
97 - .flock = nullfs_nolock,
98 - };
99 -
100 - /*
101 - * An empty regular file on @sb as a dentry of its own, never hashed under
102 - * the root so no lookup finds it.
103 - */
104 - struct dentry *nullfs_new_file(struct super_block *sb)
105 - {
106 - struct dentry *dentry;
107 - struct inode *inode;
108 -
109 - inode = new_inode(sb);
110 - if (!inode)
111 - return ERR_PTR(-ENOMEM);
112 -
113 - /* the root directory is 1 */
114 - inode->i_ino = 2;
115 - inode->i_mode = S_IFREG | 0666;
116 - inode->i_op = &nullfs_file_inode_operations;
117 - inode->i_fop = &nullfs_file_operations;
118 - simple_inode_init_ts(inode);
119 - inode->i_flags |= S_NOATIME;
120 -
121 - dentry = d_alloc_anon(sb);
122 - if (!dentry) {
123 - iput(inode);
124 - return ERR_PTR(-ENOMEM);
125 - }
126 - d_instantiate(dentry, inode);
127 - return dentry;
128 - }
129 -
130 13 static int nullfs_fs_fill_super(struct super_block *s, struct fs_context *fc)
131 14 {
132 15 struct inode *inode;
@@ -147,11 +30,10 @@ static int nullfs_fs_fill_super(struct super_block *s, struct fs_context *fc)
147 30
148 31 /* nullfs is permanently empty... */
149 32 make_empty_dir_inode(inode);
150 - inode->i_fop = &nullfs_dir_operations;
151 33 simple_inode_init_ts(inode);
152 34 inode->i_ino = 1;
153 - /* ... and immutable, reading it leaves no trace either. */
154 - inode->i_flags |= S_IMMUTABLE | S_NOATIME;
35 + /* ... and immutable. */
36 + inode->i_flags |= S_IMMUTABLE;
155 37
156 38 s->s_root = d_make_root(inode);
157 39 if (!s->s_root)
@@ -179,7 +61,6 @@ static int nullfs_init_fs_context(struct fs_context *fc)
179 61
180 62 struct file_system_type nullfs_fs_type = {
181 63 .name = "nullfs",
182 - .fs_flags = FS_DISALLOW_NOTIFY,
183 64 .init_fs_context = nullfs_init_fs_context,
184 65 .kill_sb = kill_anon_super,
185 66 };
modified fs/pnode.c
@@ -410,99 +410,19 @@ bool propagation_would_overmount(const struct mount *from,
410 410 return false;
411 411 }
412 412
413 - /* Does @m receive propagation from @parent? */
414 - static bool receives_from(struct mount *m, struct mount *parent)
415 - {
416 - if (m == parent)
417 - return false;
418 - for (; m; m = m->mnt_master)
419 - if (m == parent || peers(m, parent))
420 - return true;
421 - return false;
422 - }
423 -
424 - /*
425 - * Does @m receive propagation from the victim's parent as well? If so, then
426 - * the mount at the victim's mountpoint inside of @m is a umount candidate as
427 - * well. So it's the next candidate in the chain. Otherwise the chain ends at
428 - * @m.
429 - */
430 - static struct mount *next_candidate(struct mount *m, struct mount *victim)
431 - {
432 - if (!receives_from(m, victim->mnt_parent))
433 - return NULL;
434 - return __lookup_mnt(&m->mnt, victim->mnt_mountpoint);
435 - }
436 -
437 - /*
438 - * Would propagate_umount() pull out a mount of the chain of candidates that
439 - * starts at @c, and does that mount have references beyond its own?
440 - *
441 - * This mirrors how trim_one(), trim_ancestors() and handle_locked() handle a
442 - * synchronous umount:
443 - *
444 - * - single victim
445 - * - without children
446 - * - with MNT_LOCKED already cleared on every candidate by propagate_mount_unlock()
447 - *
448 - * A copy of the victim gets unmounted when each of its children is
449 - * the next candidate in the chain or its overmount, unless the next
450 - * unmount candidate is not its overmount and some unmount candidate further
451 - * down has a child outside the chain. Keep this in sync with
452 - * Documentation/filesystems/propagate_umount.txt.
453 - */
454 - static bool chain_busy(struct mount *c, struct mount *victim)
455 - {
456 - struct mount *m, *n, *next, *deepest = NULL;
457 - bool above;
458 -
459 - /* the deepest candidate with a child outside the chain */
460 - for (m = c; m; m = next) {
461 - next = next_candidate(m, victim);
462 - list_for_each_entry(n, &m->mnt_mounts, mnt_child) {
463 - if (n != next && n != victim) {
464 - deepest = m;
465 - break;
466 - }
467 - }
468 - }
469 -
470 - above = deepest != NULL; /* @deepest is at or below @m */
471 - for (m = c; m; m = next) {
472 - bool goes = true;
473 -
474 - next = next_candidate(m, victim);
475 - list_for_each_entry(n, &m->mnt_mounts, mnt_child) {
476 - if (n != next && n != m->overmount && n != victim) {
477 - goes = false;
478 - break;
479 - }
480 - }
481 - if (goes && next && next != m->overmount && above && m != deepest)
482 - goes = false;
483 - if (m == deepest)
484 - above = false;
485 - if (goes && do_refcount_check(m, 1))
486 - return true;
487 - }
488 - return false;
489 - }
490 -
491 413 /*
492 414 * check if the mount 'mnt' can be unmounted successfully.
493 415 * @mnt: the mount to be checked for unmount
494 416 * NOTE: unmounting 'mnt' would naturally propagate to all
495 417 * other mounts its parent propagates to.
496 - * Check if any of the mounts that propagate_umount() would pull out
497 - * along with it have more references than their own. If so return busy.
418 + * Check if any of these mounts that **do not have submounts**
419 + * have more references than 'refcnt'. If so return busy.
498 420 *
499 421 * vfsmount lock must be held for write
500 422 */
501 423 int propagate_mount_busy(struct mount *mnt, int refcnt)
502 424 {
503 425 struct mount *parent = mnt->mnt_parent;
504 - struct dentry *mp = mnt->mnt_mountpoint;
505 - struct mount *m;
506 426
507 427 /*
508 428 * quickly check if the current mount can be unmounted.
@@ -515,16 +435,24 @@ int propagate_mount_busy(struct mount *mnt, int refcnt)
515 435 if (mnt == parent)
516 436 return 0;
517 437
518 - /* the candidates are the mounts at @mp below the receivers */
519 - for (m = propagation_next(parent, parent); m;
520 - m = propagation_next(m, parent)) {
521 - struct mount *c = __lookup_mnt(&m->mnt, mp);
438 + for (struct mount *m = propagation_next(parent, parent); m;
439 + m = propagation_next(m, parent)) {
440 + struct list_head *head;
441 + struct mount *child = __lookup_mnt(&m->mnt, mnt->mnt_mountpoint);
522 442
523 - /* each chain once, from its top: skip receivers that are candidates */
524 - if (!c || (mnt_has_parent(m) && m->mnt_mountpoint == mp &&
525 - receives_from(m->mnt_parent, parent)))
443 + if (!child)
526 444 continue;
527 - if (chain_busy(c, mnt))
445 +
446 + head = &child->mnt_mounts;
447 + if (!list_empty(head)) {
448 + /*
449 + * a mount that covers child completely wouldn't prevent
450 + * it being pulled out; any other would.
451 + */
452 + if (!list_is_singular(head) || !child->overmount)
453 + continue;
454 + }
455 + if (do_refcount_check(child, 1))
528 456 return 1;
529 457 }
530 458 return 0;
@@ -697,8 +625,8 @@ static void handle_locked(struct mount *m, struct list_head *to_umount)
697 625 * the same parent and mountpoint; that will be remedied as soon as we
698 626 * return from propagate_umount() - its caller (umount_tree()) will detach
699 627 * the stack from the parent it (and now @m) is attached to. umount_tree()
700 - * detaches every unmounted mount from its parent, whether that parent
701 - * remains in the tree or not.
628 + * might choose to keep unmounted pieces stuck to each other, but it always
629 + * detaches them from the mounts that remain in the tree.
702 630 */
703 631 static void reparent(struct mount *m)
704 632 {
modified fs/readdir.c
@@ -87,8 +87,6 @@ EXPORT_SYMBOL(wrap_directory_iterator);
87 87 int iterate_dir(struct file *file, struct dir_context *ctx)
88 88 {
89 89 struct inode *inode = file_inode(file);
90 - /* never an entry, never removed: nothing for the lock to keep still */
91 - bool locked = !(file->f_op->fop_flags & FOP_IMMUTABLE);
92 90 int res = -ENOTDIR;
93 91
94 92 if (!file->f_op->iterate_shared)
@@ -102,11 +100,9 @@ int iterate_dir(struct file *file, struct dir_context *ctx)
102 100 if (res)
103 101 goto out;
104 102
105 - if (locked) {
106 - res = down_read_killable(&inode->i_rwsem);
107 - if (res)
108 - goto out;
109 - }
103 + res = down_read_killable(&inode->i_rwsem);
104 + if (res)
105 + goto out;
110 106
111 107 res = -ENOENT;
112 108 if (!IS_DEADDIR(inode)) {
@@ -116,8 +112,7 @@ int iterate_dir(struct file *file, struct dir_context *ctx)
116 112 fsnotify_access(file);
117 113 file_accessed(file);
118 114 }
119 - if (locked)
120 - inode_unlock_shared(inode);
115 + inode_unlock_shared(inode);
121 116 out:
122 117 return res;
123 118 }
modified fs/verity/fsverity_private.h
@@ -11,7 +11,6 @@
11 11 #define pr_fmt(fmt) "fs-verity: " fmt
12 12
13 13 #include <linux/fsverity.h>
14 - #include <linux/rcupdate.h>
15 14 #include <linux/rhashtable.h>
16 15
17 16 /*
@@ -77,19 +76,7 @@ struct merkle_tree_params {
77 76 struct fsverity_info {
78 77 struct rhash_head rhash_head;
79 78 struct merkle_tree_params tree_params;
80 - union {
81 - u8 root_hash[FS_VERITY_MAX_DIGEST_SIZE];
82 -
83 - /*
84 - * Used for final freeing of the struct, in which case root_hash
85 - * is no longer needed. Specifically, the only fields needed
86 - * besides the rcu_head are those needed by fsverity_free_info()
87 - * itself, and those that can be accessed by fsverity_get_info()
88 - * (rhash_head and inode) during the RCU-protected rhashtable
89 - * chain search trying to find another inode's fsverity_info.
90 - */
91 - struct rcu_head rcu_head;
92 - };
79 + u8 root_hash[FS_VERITY_MAX_DIGEST_SIZE];
93 80 u8 file_digest[FS_VERITY_MAX_DIGEST_SIZE];
94 81 struct inode *inode;
95 82 unsigned long *hash_block_verified;
modified fs/verity/open.c
@@ -399,22 +399,11 @@ void fsverity_free_info(struct fsverity_info *vi)
399 399 kmem_cache_free(fsverity_info_cachep, vi);
400 400 }
401 401
402 - static void fsverity_free_info_rcu(struct rcu_head *head)
403 - {
404 - fsverity_free_info(container_of(head, struct fsverity_info, rcu_head));
405 - }
406 -
407 402 void fsverity_remove_info(struct fsverity_info *vi)
408 403 {
409 404 rhashtable_remove_fast(&fsverity_info_hash, &vi->rhash_head,
410 405 fsverity_info_hash_params);
411 - /*
412 - * The freeing must be RCU-delayed because __fsverity_get_info() for a
413 - * *different* inode's fsverity_info in the same rhashtable hash chain
414 - * can still be accessing *this* fsverity_info's rhash_head and inode
415 - * fields as part of the RCU-protected hash chain search.
416 - */
417 - call_rcu(&vi->rcu_head, fsverity_free_info_rcu);
406 + fsverity_free_info(vi);
418 407 }
419 408
420 409 void fsverity_cleanup_inode(struct inode *inode)
modified fs/xfs/libxfs/xfs_exchmaps.c
@@ -49,7 +49,7 @@ struct xfs_exchmaps_adjacent {
49 49 .right2 = { .br_startblock = HOLESTARTBLOCK }, \
50 50 }
51 51
52 - /* Information to reset CoW fork state after an exchange. */
52 + /* Information to reset reflink flag / CoW fork state after an exchange. */
53 53
54 54 /*
55 55 * If the reflink flag is set on either inode, make sure it has an incore CoW
@@ -127,7 +127,9 @@ xmi_has_more_exchange_work(const struct xfs_exchmaps_intent *xmi)
127 127 static inline bool
128 128 xmi_has_postop_work(const struct xfs_exchmaps_intent *xmi)
129 129 {
130 - return xmi->xmi_flags & __XFS_EXCHMAPS_INO2_SHORTFORM;
130 + return xmi->xmi_flags & (XFS_EXCHMAPS_CLEAR_INO1_REFLINK |
131 + XFS_EXCHMAPS_CLEAR_INO2_REFLINK |
132 + __XFS_EXCHMAPS_INO2_SHORTFORM);
131 133 }
132 134
133 135 /* Check all mappings to make sure we can actually exchange them. */
@@ -523,6 +525,18 @@ free:
523 525 return error;
524 526 }
525 527
528 + /* Clear the reflink flag after an exchange. */
529 + static inline void
530 + xfs_exchmaps_clear_reflink(
531 + struct xfs_trans *tp,
532 + struct xfs_inode *ip)
533 + {
534 + trace_xfs_reflink_unset_inode_flag(ip);
535 +
536 + ip->i_diflags2 &= ~XFS_DIFLAG2_REFLINK;
537 + xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
538 + }
539 +
526 540 /* Finish whatever work might come after an exchange operation. */
527 541 static int
528 542 xfs_exchmaps_do_postop_work(
@@ -543,6 +557,16 @@ xfs_exchmaps_do_postop_work(
543 557 return error;
544 558 }
545 559
560 + if (xmi->xmi_flags & XFS_EXCHMAPS_CLEAR_INO1_REFLINK) {
561 + xfs_exchmaps_clear_reflink(tp, xmi->xmi_ip1);
562 + xmi->xmi_flags &= ~XFS_EXCHMAPS_CLEAR_INO1_REFLINK;
563 + }
564 +
565 + if (xmi->xmi_flags & XFS_EXCHMAPS_CLEAR_INO2_REFLINK) {
566 + xfs_exchmaps_clear_reflink(tp, xmi->xmi_ip2);
567 + xmi->xmi_flags &= ~XFS_EXCHMAPS_CLEAR_INO2_REFLINK;
568 + }
569 +
546 570 return 0;
547 571 }
548 572
@@ -924,14 +948,46 @@ xfs_exchmaps_intent_destroy_cache(void)
924 948 }
925 949
926 950 /*
927 - * Allocate and initialize a new incore intent item from a request.
951 + * Decide if we will exchange the reflink flags between the two files after the
952 + * exchange. The only time we want to do this is if we're exchanging all
953 + * mappings under EOF and the inode reflink flags have different states.
928 954 */
955 + static inline bool
956 + xmi_can_exchange_reflink_flags(
957 + const struct xfs_exchmaps_req *req,
958 + unsigned int reflink_state)
959 + {
960 + struct xfs_mount *mp = req->ip1->i_mount;
961 +
962 + /*
963 + * The INO1_WRITTEN optimization can skip exchanging hole and
964 + * unwritten mappings, which means we cannot guarantee that all
965 + * shared extents actually moved to the other file. Clearing the
966 + * reflink flag of an inode that still holds shared extents breaks
967 + * the CoW write path, so refuse to exchange the flags in that case.
968 + */
969 + if (req->flags & XFS_EXCHMAPS_INO1_WRITTEN)
970 + return false;
971 +
972 + if (hweight32(reflink_state) != 1)
973 + return false;
974 + if (req->startoff1 != 0 || req->startoff2 != 0)
975 + return false;
976 + if (req->blockcount != XFS_B_TO_FSB(mp, req->ip1->i_disk_size))
977 + return false;
978 + if (req->blockcount != XFS_B_TO_FSB(mp, req->ip2->i_disk_size))
979 + return false;
980 + return true;
981 + }
982 +
983 +
984 + /* Allocate and initialize a new incore intent item from a request. */
929 985 struct xfs_exchmaps_intent *
930 986 xfs_exchmaps_init_intent(
931 987 const struct xfs_exchmaps_req *req)
932 988 {
933 989 struct xfs_exchmaps_intent *xmi;
934 - struct xfs_mount *mp = req->ip1->i_mount;
990 + unsigned int rs = 0;
935 991
936 992 xmi = kmem_cache_zalloc(xfs_exchmaps_intent_cache,
937 993 GFP_NOFS | __GFP_NOFAIL);
@@ -949,18 +1005,27 @@ xfs_exchmaps_init_intent(
949 1005 return xmi;
950 1006 }
951 1007
952 - /*
953 - * If the caller wanted, set each file's size to that file's exchange
954 - * offset + length exchanged from the other file because the ranges in
955 - * each file might be different lengths.
956 - */
957 1008 if (req->flags & XFS_EXCHMAPS_SET_SIZES) {
958 - loff_t off1 = XFS_FSB_TO_B(mp, xmi->xmi_startoff1);
959 - loff_t off2 = XFS_FSB_TO_B(mp, xmi->xmi_startoff2);
960 -
961 1009 xmi->xmi_flags |= XFS_EXCHMAPS_SET_SIZES;
962 - xmi->xmi_isize1 = off1 + (req->ip2->i_disk_size - off2);
963 - xmi->xmi_isize2 = off2 + (req->ip1->i_disk_size - off1);
1010 + xmi->xmi_isize1 = req->ip2->i_disk_size;
1011 + xmi->xmi_isize2 = req->ip1->i_disk_size;
1012 + }
1013 +
1014 + /* Record the state of each inode's reflink flag before the op. */
1015 + if (xfs_is_reflink_inode(req->ip1))
1016 + rs |= 1;
1017 + if (xfs_is_reflink_inode(req->ip2))
1018 + rs |= 2;
1019 +
1020 + /*
1021 + * Figure out if we're clearing the reflink flags (which effectively
1022 + * exchanges them) after the operation.
1023 + */
1024 + if (xmi_can_exchange_reflink_flags(req, rs)) {
1025 + if (rs & 1)
1026 + xmi->xmi_flags |= XFS_EXCHMAPS_CLEAR_INO1_REFLINK;
1027 + if (rs & 2)
1028 + xmi->xmi_flags |= XFS_EXCHMAPS_CLEAR_INO2_REFLINK;
964 1029 }
965 1030
966 1031 if (S_ISDIR(VFS_I(xmi->xmi_ip2)->i_mode) ||
modified fs/xfs/libxfs/xfs_log_format.h
@@ -927,8 +927,10 @@ struct xfs_xmi_log_format {
927 927 */
928 928 #define XFS_EXCHMAPS_INO1_WRITTEN (1ULL << 2)
929 929
930 - /* No longer set, but older intents may carry them; keep them valid. */
930 + /* Clear the reflink flag from inode1 after the operation. */
931 931 #define XFS_EXCHMAPS_CLEAR_INO1_REFLINK (1ULL << 3)
932 +
933 + /* Clear the reflink flag from inode2 after the operation. */
932 934 #define XFS_EXCHMAPS_CLEAR_INO2_REFLINK (1ULL << 4)
933 935
934 936 #define XFS_EXCHMAPS_LOGGED_FLAGS (XFS_EXCHMAPS_ATTR_FORK | \
modified fs/xfs/xfs_bmap_util.c
@@ -1544,6 +1544,7 @@ xfs_swap_extents(
1544 1544 struct xfs_bstat *sbp = &sxp->sx_stat;
1545 1545 int src_log_flags, target_log_flags;
1546 1546 int error = 0;
1547 + uint64_t f;
1547 1548 int resblks = 0;
1548 1549 unsigned int flags = 0;
1549 1550 struct timespec64 ctime, mtime;
@@ -1699,12 +1700,14 @@ xfs_swap_extents(
1699 1700 if (error)
1700 1701 goto out_trans_cancel;
1701 1702
1702 - /* Either inode may now own shared blocks; flag both, with CoW forks. */
1703 - if ((ip->i_diflags2 | tip->i_diflags2) & XFS_DIFLAG2_REFLINK) {
1704 - ip->i_diflags2 |= XFS_DIFLAG2_REFLINK;
1705 - tip->i_diflags2 |= XFS_DIFLAG2_REFLINK;
1706 - xfs_ifork_init_cow(ip);
1707 - xfs_ifork_init_cow(tip);
1703 + /* Do we have to swap reflink flags? */
1704 + if ((ip->i_diflags2 & XFS_DIFLAG2_REFLINK) ^
1705 + (tip->i_diflags2 & XFS_DIFLAG2_REFLINK)) {
1706 + f = ip->i_diflags2 & XFS_DIFLAG2_REFLINK;
1707 + ip->i_diflags2 &= ~XFS_DIFLAG2_REFLINK;
1708 + ip->i_diflags2 |= tip->i_diflags2 & XFS_DIFLAG2_REFLINK;
1709 + tip->i_diflags2 &= ~XFS_DIFLAG2_REFLINK;
1710 + tip->i_diflags2 |= f & XFS_DIFLAG2_REFLINK;
1708 1711 }
1709 1712
1710 1713 /* Swap the cow forks. */
modified fs/xfs/xfs_exchrange.c
@@ -290,20 +290,17 @@ retry:
290 290 goto out_unlock;
291 291
292 292 /*
293 - * If the caller wanted, set each file's size to that file's exchange
294 - * offset + length exchanged from the other file because the ranges in
295 - * each file might be different lengths. This should be safe because
296 - * we flushed both files' page caches, exchanged all the mappings, and
297 - * updated the ondisk sizes.
293 + * If the caller wanted us to exchange the contents of two complete
294 + * files of unequal length, exchange the incore sizes now. This should
295 + * be safe because we flushed both files' page caches, exchanged all
296 + * the mappings, and updated the ondisk sizes.
298 297 */
299 298 if (fxr->flags & XFS_EXCHANGE_RANGE_TO_EOF) {
300 - loff_t old_ip1_size = i_size_read(VFS_I(ip1));
301 - loff_t old_ip2_size = i_size_read(VFS_I(ip2));
299 + loff_t temp;
302 300
303 - i_size_write(VFS_I(ip2), fxr->file2_offset +
304 - (old_ip1_size - fxr->file1_offset));
305 - i_size_write(VFS_I(ip1), fxr->file1_offset +
306 - (old_ip2_size - fxr->file2_offset));
301 + temp = i_size_read(VFS_I(ip2));
302 + i_size_write(VFS_I(ip2), i_size_read(VFS_I(ip1)));
303 + i_size_write(VFS_I(ip1), temp);
307 304 }
308 305
309 306 out_unlock:
@@ -448,30 +445,6 @@ xfs_exchange_range_checks(
448 445 return blen == fxr->length ? 0 : -EINVAL;
449 446 }
450 447
451 - /* Flush all relevant dirty pagecache near the range to be exchanged. */
452 - static inline int
453 - xfs_exchange_range_flush(
454 - struct xfs_inode *ip,
455 - const struct xfs_exchrange *fxr,
456 - loff_t offset)
457 - {
458 - /*
459 - * If TO_EOF is set, the ondisk file size update logic depends on the
460 - * ondisk file size matching the incore file size. Flush everything.
461 - */
462 - if (fxr->flags & XFS_EXCHANGE_RANGE_TO_EOF)
463 - return filemap_write_and_wait(VFS_I(ip)->i_mapping);
464 -
465 - /*
466 - * Because we're updating the ondisk mappings, flush all dirty data
467 - * between the ondisk size and the exchange offset to reduce the chance
468 - * of zeroed file contents in that gap after a crash.
469 - */
470 - return filemap_write_and_wait_range(VFS_I(ip)->i_mapping,
471 - min(offset, ip->i_disk_size),
472 - offset + fxr->length - 1);
473 - }
474 -
475 448 /*
476 449 * Check that the two inodes are eligible for range exchanges, the ranges make
477 450 * sense, and then flush all dirty data. Caller must ensure that the inodes
@@ -497,11 +470,15 @@ xfs_exchange_range_prep(
497 470 if (!same_inode)
498 471 inode_dio_wait(inode2);
499 472
500 - error = xfs_exchange_range_flush(XFS_I(inode1), fxr, fxr->file1_offset);
473 + error = filemap_write_and_wait_range(inode1->i_mapping,
474 + fxr->file1_offset,
475 + fxr->file1_offset + fxr->length - 1);
501 476 if (error)
502 477 return error;
503 478
504 - error = xfs_exchange_range_flush(XFS_I(inode2), fxr, fxr->file2_offset);
479 + error = filemap_write_and_wait_range(inode2->i_mapping,
480 + fxr->file2_offset,
481 + fxr->file2_offset + fxr->length - 1);
505 482 if (error)
506 483 return error;
507 484
modified include/linux/can/core.h
@@ -17,7 +17,6 @@
17 17 #include <linux/can.h>
18 18 #include <linux/skbuff.h>
19 19 #include <linux/netdevice.h>
20 - #include <net/can.h>
21 20
22 21 #define DNAME(dev) ((dev) ? (dev)->name : "any")
23 22
@@ -59,7 +58,7 @@ extern void can_rx_unregister(struct net *net, struct net_device *dev,
59 58 void *data);
60 59
61 60 extern int can_send(struct sk_buff *skb, int loop);
62 - void can_set_skb_uid(struct can_skb_ext *csx);
61 + void can_set_skb_uid(struct sk_buff *skb);
63 62 void can_sock_destruct(struct sock *sk);
64 63
65 64 #endif /* !_CAN_CORE_H */
modified include/linux/can/skb.h
@@ -43,10 +43,8 @@ static inline struct can_skb_ext *can_skb_ext_add(struct sk_buff *skb)
43 43 struct can_skb_ext *csx = skb_ext_add(skb, SKB_EXT_CAN);
44 44
45 45 /* skb_ext_add() returns uninitialized space */
46 - if (csx) {
46 + if (csx)
47 47 csx->can_gw_hops = 0;
48 - csx->can_skb_uid = 0;
49 - }
50 48
51 49 return csx;
52 50 }
modified include/linux/console.h
@@ -615,15 +615,6 @@ extern bool nbcon_allow_unsafe_takeover(void);
615 615 extern bool nbcon_kdb_try_acquire(struct console *con,
616 616 struct nbcon_write_context *wctxt);
617 617 extern void nbcon_kdb_release(struct nbcon_write_context *wctxt);
618 - extern bool nbcon_write_context_is_braille(struct nbcon_write_context *wctxt);
619 - extern bool nbcon_braille_try_acquire(struct console *con,
620 - struct nbcon_write_context *wctxt);
621 - extern void nbcon_braille_release(struct nbcon_write_context *wctxt);
622 -
623 - static inline bool nbcon_is_braille(struct console *con)
624 - {
625 - return con && (con->flags & CON_BRL);
626 - }
627 618
628 619 /*
629 620 * Check if the given console is currently capable and allowed to print
@@ -687,14 +678,8 @@ static inline void nbcon_reacquire_nobuf(struct nbcon_write_context *wctxt) { }
687 678 static inline bool nbcon_kdb_try_acquire(struct console *con,
688 679 struct nbcon_write_context *wctxt) { return false; }
689 680 static inline void nbcon_kdb_release(struct nbcon_write_context *wctxt) { }
690 - static inline
691 - bool nbcon_write_context_is_braille(struct nbcon_write_context *wctxt) { return false; }
692 681 static inline bool console_is_usable(struct console *con, short flags,
693 682 bool use_atomic) { return false; }
694 - static inline bool nbcon_braille_try_acquire(struct console *con,
695 - struct nbcon_write_context *wctxt) { return false; }
696 - static inline void nbcon_braille_release(struct nbcon_write_context *wctxt) { }
697 - static inline bool nbcon_is_braille(struct console *con) { return false; }
698 683 #endif
699 684
700 685 extern int console_set_on_cmdline;
modified include/linux/fs.h
@@ -1978,8 +1978,6 @@ struct file_operations {
1978 1978 #define FOP_ASYNC_LOCK ((__force fop_flags_t)(1 << 6))
1979 1979 /* File system supports uncached read/write buffered IO */
1980 1980 #define FOP_DONTCACHE ((__force fop_flags_t)(1 << 7))
1981 - /* Never changes and is never removed, readdir of a directory takes no lock */
1982 - #define FOP_IMMUTABLE ((__force fop_flags_t)(1 << 8))
1983 1981
1984 1982 /* Wrap a directory iterator that needs exclusive inode access */
1985 1983 int wrap_directory_iterator(struct file *, struct dir_context *,
@@ -2298,7 +2296,6 @@ struct file_system_type {
2298 2296 #define FS_POWER_FREEZE 256 /* Always freeze on suspend/hibernate */
2299 2297 #define FS_USERNS_MOUNT_RESTRICTED 512 /* Restrict mount in userns if not already visible */
2300 2298 #define FS_USERNS_DELEGATABLE 1024 /* Can be mounted inside userns from outside */
2301 - #define FS_DISALLOW_NOTIFY 2048 /* No fsnotify marks on its objects */
2302 2299 #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */
2303 2300 int (*init_fs_context)(struct fs_context *);
2304 2301 const struct fs_parameter_spec *parameters;
modified include/linux/io_uring_types.h
@@ -322,8 +322,6 @@ enum {
322 322 IO_RING_F_DRAIN_DISABLED = BIT(10),
323 323 IO_RING_F_COMPAT = BIT(11),
324 324 IO_RING_F_IOWQ_LIMITS_SET = BIT(12),
325 - /* restrictions were inherited from the task that created the ring */
326 - IO_RING_F_RESTRICT_INHERITED = BIT(13),
327 325 };
328 326
329 327 struct iou_ctx {};
modified include/linux/mount.h
@@ -52,7 +52,7 @@ enum mount_flags {
52 52 MNT_ATIME_MASK = MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME,
53 53
54 54 MNT_INTERNAL_FLAGS = MNT_INTERNAL | MNT_DOOMED |
55 - MNT_SYNC_UMOUNT | MNT_LOCKED | MNT_UMOUNT
55 + MNT_SYNC_UMOUNT | MNT_LOCKED
56 56 };
57 57
58 58 struct vfsmount {
modified include/linux/nsproxy.h
@@ -100,7 +100,6 @@ void exit_cred_namespaces(struct task_struct *tsk);
100 100 void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
101 101 int exec_task_namespaces(void);
102 102 void deactivate_nsproxy(struct nsproxy *ns);
103 - void nsproxy_free(struct nsproxy *ns);
104 103 int unshare_nsproxy_namespaces(unsigned long, struct nsproxy **,
105 104 struct cred *, struct fs_struct *);
106 105 int __init nsproxy_cache_init(void);
modified include/linux/nvme.h
@@ -1266,8 +1266,8 @@ enum {
1266 1266 NVME_ZRASF_ZONE_STATE_IMP_OPEN = 0x02,
1267 1267 NVME_ZRASF_ZONE_STATE_EXP_OPEN = 0x03,
1268 1268 NVME_ZRASF_ZONE_STATE_CLOSED = 0x04,
1269 - NVME_ZRASF_ZONE_STATE_FULL = 0x05,
1270 - NVME_ZRASF_ZONE_STATE_READONLY = 0x06,
1269 + NVME_ZRASF_ZONE_STATE_READONLY = 0x05,
1270 + NVME_ZRASF_ZONE_STATE_FULL = 0x06,
1271 1271 NVME_ZRASF_ZONE_STATE_OFFLINE = 0x07,
1272 1272 NVME_REPORT_ZONE_PARTIAL = 1,
1273 1273 };
modified include/linux/sched/ext.h
@@ -207,7 +207,6 @@ struct sched_ext_entity {
207 207 s32 holding_cpu;
208 208 s32 selected_cpu;
209 209 s32 runnable_cpu; /* cpu @p is runnable on, -1 if not */
210 - u32 ops_qseq; /* protected by rq lock */
211 210 struct task_struct *kf_tasks[2]; /* see SCX_CALL_OP_TASK() */
212 211
213 212 struct list_head runnable_node; /* rq->scx.runnable_list */
modified include/linux/virtio_net.h
@@ -111,38 +111,48 @@ static inline int __virtio_net_hdr_to_skb(struct sk_buff *skb,
111 111 p_off = nh_min_len + thlen;
112 112 if (!pskb_may_pull(skb, p_off))
113 113 return -EINVAL;
114 - } else if (gso_type) {
114 + } else {
115 115 /* gso packets without NEEDS_CSUM do not set transport_offset.
116 116 * probe and drop if does not match one of the above types.
117 117 */
118 - struct flow_keys_basic keys;
119 -
120 - if (!skb->protocol) {
121 - skb->protocol = dev_parse_header_protocol(skb);
122 - if (!skb->protocol)
123 - virtio_net_hdr_set_proto(skb, hdr);
124 - }
118 + if (gso_type && skb->network_header) {
119 + struct flow_keys_basic keys;
120 +
121 + if (!skb->protocol) {
122 + __be16 protocol = dev_parse_header_protocol(skb);
123 +
124 + if (!protocol)
125 + virtio_net_hdr_set_proto(skb, hdr);
126 + else if (!virtio_net_hdr_match_proto(protocol,
127 + hdr_gso_type))
128 + return -EINVAL;
129 + else
130 + skb->protocol = protocol;
131 + }
125 132 retry:
126 - if (!skb_flow_dissect_flow_keys_basic(NULL, skb, &keys,
127 - NULL, 0, 0, 0,
128 - 0)) {
129 - /* UFO does not specify ipv4 or 6: try both */
130 - if (gso_type & SKB_GSO_UDP &&
131 - skb->protocol == htons(ETH_P_IP)) {
132 - skb->protocol = htons(ETH_P_IPV6);
133 - goto retry;
133 + if (!skb_flow_dissect_flow_keys_basic(NULL, skb, &keys,
134 + NULL, 0, 0, 0,
135 + 0)) {
136 + /* UFO does not specify ipv4 or 6: try both */
137 + if (gso_type & SKB_GSO_UDP &&
138 + skb->protocol == htons(ETH_P_IP)) {
139 + skb->protocol = htons(ETH_P_IPV6);
140 + goto retry;
141 + }
142 + return -EINVAL;
134 143 }
135 - return -EINVAL;
136 - }
137 144
138 - p_off = keys.control.thoff + thlen;
139 - if (!pskb_may_pull(skb, p_off) ||
140 - keys.basic.ip_proto != ip_proto ||
141 - !virtio_net_hdr_match_proto(keys.basic.n_proto,
142 - hdr_gso_type))
143 - return -EINVAL;
145 + p_off = keys.control.thoff + thlen;
146 + if (!pskb_may_pull(skb, p_off) ||
147 + keys.basic.ip_proto != ip_proto)
148 + return -EINVAL;
144 149
145 - skb_set_transport_header(skb, keys.control.thoff);
150 + skb_set_transport_header(skb, keys.control.thoff);
151 + } else if (gso_type) {
152 + p_off = nh_min_len + thlen;
153 + if (!pskb_may_pull(skb, p_off))
154 + return -EINVAL;
155 + }
146 156 }
147 157
148 158 if (hdr_gso_type != VIRTIO_NET_HDR_GSO_NONE) {
modified include/net/amt.h
@@ -231,6 +231,10 @@ struct amt_relay_headers {
231 231 };
232 232 } __packed;
233 233
234 + struct amt_skb_cb {
235 + struct amt_tunnel_list *tunnel;
236 + };
237 +
234 238 struct amt_tunnel_list {
235 239 struct list_head list;
236 240 /* Protect All resources under an amt_tunne_list */
modified include/net/bluetooth/rfcomm.h
@@ -207,7 +207,6 @@ struct rfcomm_dlc {
207 207 #define RFCOMM_AUTH_REJECT 7
208 208 #define RFCOMM_DEFER_SETUP 8
209 209 #define RFCOMM_ENC_DROP 9
210 - #define RFCOMM_CLOSED 10
211 210
212 211 /* Scheduling flags and events */
213 212 #define RFCOMM_SCHED_WAKEUP 31
modified include/net/can.h
@@ -17,14 +17,12 @@
17 17 * @can_framelen: cached echo CAN frame length for bql
18 18 * @can_gw_hops: can-gw CAN frame time-to-live counter
19 19 * @can_ext_flags: CAN skb extensions flags
20 - * @can_skb_uid: CAN skb UID for raw_rcv and isotp echo handling
21 20 */
22 21 struct can_skb_ext {
23 22 int can_iif;
24 23 u16 can_framelen;
25 24 u8 can_gw_hops;
26 25 u8 can_ext_flags;
27 - u32 can_skb_uid;
28 26 };
29 27
30 28 #endif /* _NET_CAN_H */
modified include/net/ip.h
@@ -74,13 +74,6 @@ static inline unsigned int ip_hdrlen(const struct sk_buff *skb)
74 74 return ip_hdr(skb)->ihl * 4;
75 75 }
76 76
77 - static inline int ip_check_csum_start(const struct sk_buff *skb)
78 - {
79 - if (unlikely(skb->csum_start < skb->network_header + ip_hdrlen(skb)))
80 - return -EINVAL;
81 - return 0;
82 - }
83 -
84 77 struct ipcm_cookie {
85 78 struct sockcm_cookie sockc;
86 79 __be32 addr;
modified include/net/mana/mana.h
@@ -377,18 +377,7 @@ struct mana_recv_buf_oob {
377 377 #define MANA_RXBUF_PAD (SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) \
378 378 + ETH_HLEN)
379 379
380 - /* Headroom an RX buffer has to reserve while XDP is attached: the XDP program
381 - * needs XDP_PACKET_HEADROOM, and the TX path needs LL_RESERVED_SPACE() (see
382 - * mana_get_rxbuf_headroom()). LL_RESERVED_SPACE() grows with MAX_SKB_FRAGS and
383 - * exceeds XDP_PACKET_HEADROOM once CONFIG_MAX_SKB_FRAGS is 19 or more.
384 - */
385 - static inline u32 mana_xdp_headroom(struct net_device *ndev)
386 - {
387 - return max_t(u32, LL_RESERVED_SPACE(ndev), XDP_PACKET_HEADROOM);
388 - }
389 -
390 - #define MANA_XDP_MTU_MAX(ndev) \
391 - (PAGE_SIZE - MANA_RXBUF_PAD - mana_xdp_headroom(ndev))
380 + #define MANA_XDP_MTU_MAX (PAGE_SIZE - MANA_RXBUF_PAD - XDP_PACKET_HEADROOM)
392 381
393 382 struct mana_rxq {
394 383 struct gdma_queue *gdma_rq;
@@ -702,7 +691,6 @@ int mana_query_link_cfg(struct mana_port_context *apc);
702 691 int mana_set_bw_clamp(struct mana_port_context *apc, u32 speed,
703 692 int enable_clamping);
704 693 void mana_query_phy_stats(struct mana_port_context *apc);
705 - bool mana_single_rxbuf_per_page_forced(struct mana_port_context *apc, u32 mtu);
706 694 int mana_pre_alloc_rxbufs(struct mana_port_context *apc, int mtu, int num_queues);
707 695 void mana_pre_dealloc_rxbufs(struct mana_port_context *apc);
708 696 void mana_unmap_skb(struct sk_buff *skb, struct mana_port_context *apc);
modified include/net/strparser.h
@@ -91,11 +91,11 @@ static inline struct strp_msg *strp_msg(struct sk_buff *skb)
91 91 struct strparser {
92 92 struct sock *sk;
93 93
94 - u8 stopped;
95 - u8 paused;
96 - u8 aborted;
97 - u8 interrupted;
98 - u8 unrecov_intr;
94 + u32 stopped : 1;
95 + u32 paused : 1;
96 + u32 aborted : 1;
97 + u32 interrupted : 1;
98 + u32 unrecov_intr : 1;
99 99
100 100 struct sk_buff **skb_nextp;
101 101 struct sk_buff *skb_head;
modified io_uring/cancel.c
@@ -634,11 +634,12 @@ __cold void io_uring_cancel_generic(bool cancel_all, struct io_sq_data *sqd)
634 634 prepare_to_wait(&tctx->wait, &wait, TASK_INTERRUPTIBLE);
635 635 io_run_task_work();
636 636 io_uring_drop_tctx_refs(current);
637 - /* only skip the sleep for local work this task may run */
638 637 xa_for_each(&tctx->xa, index, node) {
639 - if (io_local_work_pending(node->ctx) &&
640 - io_allowed_defer_tw_run(node->ctx))
638 + if (io_local_work_pending(node->ctx)) {
639 + WARN_ON_ONCE(node->ctx->submitter_task &&
640 + node->ctx->submitter_task != current);
641 641 goto end_wait;
642 + }
642 643 }
643 644 /*
644 645 * If we've seen completions, retry without waiting. This
modified io_uring/io_uring.c
@@ -2070,9 +2070,8 @@ int io_submit_sqes(struct io_ring_ctx *ctx, unsigned int nr)
2070 2070
2071 2071 static void io_rings_free(struct io_ring_ctx *ctx)
2072 2072 {
2073 - /* ring memory is not charged to RLIMIT_MEMLOCK, hence no user */
2074 - io_free_region(NULL, &ctx->sq_region);
2075 - io_free_region(NULL, &ctx->ring_region);
2073 + io_free_region(ctx->user, &ctx->sq_region);
2074 + io_free_region(ctx->user, &ctx->ring_region);
2076 2075 ctx->rings = NULL;
2077 2076 RCU_INIT_POINTER(ctx->rings_rcu, NULL);
2078 2077 ctx->sq_sqes = NULL;
@@ -2736,8 +2735,7 @@ static __cold int io_allocate_scq_urings(struct io_ring_ctx *ctx,
2736 2735 rd.user_addr = p->cq_off.user_addr;
2737 2736 rd.flags |= IORING_MEM_REGION_TYPE_USER;
2738 2737 }
2739 - /* ring memory is not charged to RLIMIT_MEMLOCK, hence no user */
2740 - ret = io_create_region(NULL, &ctx->ring_region, &rd, IORING_OFF_CQ_RING);
2738 + ret = io_create_region(ctx, &ctx->ring_region, &rd, IORING_OFF_CQ_RING);
2741 2739 if (ret)
2742 2740 return ret;
2743 2741 ctx->rings = rings = io_region_get_ptr(&ctx->ring_region);
@@ -2751,7 +2749,7 @@ static __cold int io_allocate_scq_urings(struct io_ring_ctx *ctx,
2751 2749 rd.user_addr = p->sq_off.user_addr;
2752 2750 rd.flags |= IORING_MEM_REGION_TYPE_USER;
2753 2751 }
2754 - ret = io_create_region(NULL, &ctx->sq_region, &rd, IORING_OFF_SQES);
2752 + ret = io_create_region(ctx, &ctx->sq_region, &rd, IORING_OFF_SQES);
2755 2753 if (ret) {
2756 2754 io_rings_free(ctx);
2757 2755 return ret;
@@ -2962,8 +2960,7 @@ static void io_ctx_restriction_clone(struct io_ring_ctx *ctx,
2962 2960 if (dst->op_registered)
2963 2961 ctx->int_flags |= IO_RING_F_OP_RESTRICTED;
2964 2962 if (dst->reg_registered)
2965 - ctx->int_flags |= IO_RING_F_REG_RESTRICTED |
2966 - IO_RING_F_RESTRICT_INHERITED;
2963 + ctx->int_flags |= IO_RING_F_REG_RESTRICTED;
2967 2964 }
2968 2965
2969 2966 static __cold int io_uring_create(struct io_ctx_config *config)
modified io_uring/kbuf.c
@@ -459,7 +459,7 @@ static int io_remove_buffers_legacy(struct io_ring_ctx *ctx,
459 459 static void io_put_bl(struct io_ring_ctx *ctx, struct io_buffer_list *bl)
460 460 {
461 461 if (bl->flags & IOBL_BUF_RING)
462 - io_free_region(NULL, &bl->region);
462 + io_free_region(ctx->user, &bl->region);
463 463 else
464 464 io_remove_buffers_legacy(ctx, bl, -1U);
465 465
@@ -676,7 +676,7 @@ int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
676 676 rd.user_addr = reg.ring_addr;
677 677 rd.flags |= IORING_MEM_REGION_TYPE_USER;
678 678 }
679 - ret = io_create_region(NULL, &bl->region, &rd, mmap_offset);
679 + ret = io_create_region(ctx, &bl->region, &rd, mmap_offset);
680 680 if (ret)
681 681 goto fail;
682 682 br = io_region_get_ptr(&bl->region);
@@ -709,7 +709,7 @@ int io_register_pbuf_ring(struct io_ring_ctx *ctx, void __user *arg)
709 709 if (!ret)
710 710 return 0;
711 711 fail:
712 - io_free_region(NULL, &bl->region);
712 + io_free_region(ctx->user, &bl->region);
713 713 kfree(bl);
714 714 return ret;
715 715 }
modified io_uring/memmap.c
@@ -204,7 +204,7 @@ done:
204 204 return 0;
205 205 }
206 206
207 - int io_create_region(struct user_struct *user, struct io_mapped_region *mr,
207 + int io_create_region(struct io_ring_ctx *ctx, struct io_mapped_region *mr,
208 208 struct io_uring_region_desc *reg,
209 209 unsigned long mmap_offset)
210 210 {
@@ -230,8 +230,8 @@ int io_create_region(struct user_struct *user, struct io_mapped_region *mr,
230 230 return -EOVERFLOW;
231 231
232 232 nr_pages = reg->size >> PAGE_SHIFT;
233 - if (user) {
234 - ret = __io_account_mem(user, nr_pages);
233 + if (ctx->user) {
234 + ret = __io_account_mem(ctx->user, nr_pages);
235 235 if (ret)
236 236 return ret;
237 237 }
@@ -240,7 +240,7 @@ int io_create_region(struct user_struct *user, struct io_mapped_region *mr,
240 240 if (reg->flags & IORING_MEM_REGION_TYPE_USER)
241 241 ret = io_region_pin_pages(mr, reg);
242 242 else
243 - ret = io_region_allocate_pages(mr, reg, mmap_offset, user);
243 + ret = io_region_allocate_pages(mr, reg, mmap_offset, ctx->user);
244 244 if (ret)
245 245 goto out_free;
246 246
@@ -249,7 +249,7 @@ int io_create_region(struct user_struct *user, struct io_mapped_region *mr,
249 249 goto out_free;
250 250 return 0;
251 251 out_free:
252 - io_free_region(user, mr);
252 + io_free_region(ctx->user, mr);
253 253 return ret;
254 254 }
255 255
modified io_uring/memmap.h
@@ -18,7 +18,7 @@ unsigned long io_uring_get_unmapped_area(struct file *file, unsigned long addr,
18 18 int io_uring_mmap(struct file *file, struct vm_area_struct *vma);
19 19
20 20 void io_free_region(struct user_struct *user, struct io_mapped_region *mr);
21 - int io_create_region(struct user_struct *user, struct io_mapped_region *mr,
21 + int io_create_region(struct io_ring_ctx *ctx, struct io_mapped_region *mr,
22 22 struct io_uring_region_desc *reg,
23 23 unsigned long mmap_offset);
24 24
modified io_uring/net.c
@@ -7,7 +7,6 @@
7 7 #include <linux/un.h>
8 8 #include <linux/compat.h>
9 9 #include <net/compat.h>
10 - #include <net/ipv6.h>
11 10 #include <linux/io_uring.h>
12 11
13 12 #include <uapi/linux/io_uring.h>
@@ -1742,8 +1741,7 @@ void io_connect_bpf_populate(struct io_uring_bpf_ctx *bctx, struct io_kiocb *req
1742 1741 case AF_INET6: {
1743 1742 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)ss;
1744 1743
1745 - /* The IPv6 stack accepts SIN6_LEN_RFC2133; port and addr are in it. */
1746 - if (conn->addr_len < SIN6_LEN_RFC2133)
1744 + if (conn->addr_len < (int)sizeof(*sin6))
1747 1745 break;
1748 1746 bctx->connect.port = sin6->sin6_port;
1749 1747 memcpy(bctx->connect.v6_addr, &sin6->sin6_addr,
modified io_uring/register.c
@@ -480,9 +480,8 @@ struct io_ring_ctx_rings {
480 480 static void io_register_free_rings(struct io_ring_ctx *ctx,
481 481 struct io_ring_ctx_rings *r)
482 482 {
483 - /* ring memory is not charged to RLIMIT_MEMLOCK, hence no user */
484 - io_free_region(NULL, &r->sq_region);
485 - io_free_region(NULL, &r->ring_region);
483 + io_free_region(ctx->user, &r->sq_region);
484 + io_free_region(ctx->user, &r->ring_region);
486 485 }
487 486
488 487 #define swap_old(ctx, o, n, field) \
@@ -530,7 +529,7 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg)
530 529 rd.user_addr = p->cq_off.user_addr;
531 530 rd.flags |= IORING_MEM_REGION_TYPE_USER;
532 531 }
533 - ret = io_create_region(NULL, &n.ring_region, &rd, IORING_OFF_CQ_RING);
532 + ret = io_create_region(ctx, &n.ring_region, &rd, IORING_OFF_CQ_RING);
534 533 if (ret)
535 534 return ret;
536 535
@@ -560,7 +559,7 @@ static int io_register_resize_rings(struct io_ring_ctx *ctx, void __user *arg)
560 559 rd.user_addr = p->sq_off.user_addr;
561 560 rd.flags |= IORING_MEM_REGION_TYPE_USER;
562 561 }
563 - ret = io_create_region(NULL, &n.sq_region, &rd, IORING_OFF_SQES);
562 + ret = io_create_region(ctx, &n.sq_region, &rd, IORING_OFF_SQES);
564 563 if (ret) {
565 564 io_register_free_rings(ctx, &n);
566 565 return ret;
@@ -731,8 +730,7 @@ static int io_register_mem_region(struct io_ring_ctx *ctx, void __user *uarg)
731 730 !(ctx->flags & IORING_SETUP_R_DISABLED))
732 731 return -EINVAL;
733 732
734 - ret = io_create_region(ctx->user, &region, &rd,
735 - IORING_MAP_OFF_PARAM_REGION);
733 + ret = io_create_region(ctx, &region, &rd, IORING_MAP_OFF_PARAM_REGION);
736 734 if (ret)
737 735 return ret;
738 736 if (copy_to_user(rd_uptr, &rd, sizeof(rd))) {
@@ -766,14 +764,7 @@ static int __io_uring_register(struct io_ring_ctx *ctx, unsigned opcode,
766 764 if (ctx->submitter_task && ctx->submitter_task != current)
767 765 return -EEXIST;
768 766
769 - /*
770 - * A disabled ring is exempt from its own register restrictions, so
771 - * that the creator can set them up and then enable the ring. That
772 - * does not apply to restrictions inherited from the task.
773 - */
774 - if ((ctx->int_flags & IO_RING_F_REG_RESTRICTED) &&
775 - (!(ctx->flags & IORING_SETUP_R_DISABLED) ||
776 - (ctx->int_flags & IO_RING_F_RESTRICT_INHERITED))) {
767 + if ((ctx->int_flags & IO_RING_F_REG_RESTRICTED) && !(ctx->flags & IORING_SETUP_R_DISABLED)) {
777 768 opcode = array_index_nospec(opcode, IORING_REGISTER_LAST);
778 769 if (!test_bit(opcode, ctx->restrictions.register_op))
779 770 return -EACCES;
modified io_uring/zcrx.c
@@ -432,7 +432,7 @@ static int io_allocate_rbuf_ring(struct io_ring_ctx *ctx,
432 432 mmap_offset = IORING_MAP_OFF_ZCRX_REGION;
433 433 mmap_offset += (u64)id << IORING_OFF_ZCRX_SHIFT;
434 434
435 - ret = io_create_region(ctx->user, &ifq->rq_region, rd, mmap_offset);
435 + ret = io_create_region(ctx, &ifq->rq_region, rd, mmap_offset);
436 436 if (ret < 0)
437 437 return ret;
438 438
modified kernel/cgroup/cpuset.c
@@ -152,12 +152,6 @@ static cpumask_var_t isolated_cpus; /* CSCB */
152 152 */
153 153 static bool update_housekeeping; /* RWCS */
154 154
155 - /*
156 - * Set if "cpuset_v2_mode" mount option is used
157 - * Cached at bind time and not lock protected; accessed via {READ,WRITE}_ONCE
158 - */
159 - static bool cpuset_v2_mode;
160 -
161 155 /*
162 156 * Copy of isolated_cpus to be passed to housekeeping_update()
163 157 */
@@ -445,7 +439,8 @@ static inline bool cpuset_v2(void)
445 439 */
446 440 static inline bool is_in_v2_mode(void)
447 441 {
448 - return cpuset_v2() || READ_ONCE(cpuset_v2_mode);
442 + return cpuset_v2() ||
443 + (cpuset_cgrp_subsys.root->flags & CGRP_ROOT_CPUSET_V2_MODE);
449 444 }
450 445
451 446 /**
@@ -518,26 +513,10 @@ static void guarantee_active_cpus(struct task_struct *tsk,
518 513 rcu_read_lock();
519 514 cs = task_cs(tsk);
520 515
521 - while (!cpumask_intersects(cs->effective_cpus, pmask)) {
516 + while (!cpumask_intersects(cs->effective_cpus, pmask))
522 517 cs = parent_cs(cs);
523 - if (unlikely(!cs)) {
524 - /*
525 - * The top cpuset doesn't have any active cpu as a
526 - * consequence of a race between its caller and the cpu
527 - * hotplug operation where cpu_active_mask is updated
528 - * asynchronously before cpuset_handle_hotplug() is
529 - * being called to adjust the effective_cpus of the
530 - * affected cpusets. But we know the top cpuset's
531 - * effective_cpus is on its way to be identical to
532 - * cpu_active_mask minus the exclusive CPUs dedicated
533 - * to other valid cpuset partitions. Just pass back
534 - * the filtered cpu_active_mask in this case.
535 - */
536 - goto out_unlock;
537 - }
538 - }
518 +
539 519 cpumask_and(pmask, pmask, cs->effective_cpus);
540 - out_unlock:
541 520 rcu_read_unlock();
542 521 }
543 522
@@ -3753,8 +3732,6 @@ static void cpuset_bind(struct cgroup_subsys_state *root_css)
3753 3732 mutex_lock(&cpuset_mutex);
3754 3733 spin_lock_irq(&callback_lock);
3755 3734
3756 - WRITE_ONCE(cpuset_v2_mode,
3757 - !!(cpuset_cgrp_subsys.root->flags & CGRP_ROOT_CPUSET_V2_MODE));
3758 3735 if (is_in_v2_mode()) {
3759 3736 cpumask_copy(top_cpuset.cpus_allowed, cpu_possible_mask);
3760 3737 cpumask_copy(top_cpuset.effective_xcpus, cpu_possible_mask);
@@ -4067,16 +4044,15 @@ static void cpuset_handle_hotplug(void)
4067 4044 static cpumask_t new_cpus;
4068 4045 static nodemask_t new_mems;
4069 4046 bool cpus_updated, mems_updated;
4070 - bool on_dfl;
4047 + bool on_dfl = is_in_v2_mode();
4071 4048 struct tmpmasks tmp, *ptmp = NULL;
4072 4049
4073 - lockdep_assert_cpus_held();
4074 - mutex_lock(&cpuset_mutex);
4075 -
4076 - on_dfl = is_in_v2_mode();
4077 4050 if (on_dfl && !alloc_tmpmasks(&tmp))
4078 4051 ptmp = &tmp;
4079 4052
4053 + lockdep_assert_cpus_held();
4054 + mutex_lock(&cpuset_mutex);
4055 +
4080 4056 /* fetch the available cpus/mems and find out which changed how */
4081 4057 cpumask_copy(&new_cpus, cpu_active_mask);
4082 4058 new_mems = node_states[N_MEMORY];
modified kernel/dma/swiotlb.c
@@ -1844,10 +1844,10 @@ phys_addr_t default_swiotlb_base(void)
1844 1844 phys_addr_t default_swiotlb_limit(void)
1845 1845 {
1846 1846 #ifdef CONFIG_SWIOTLB_DYNAMIC
1847 - if (io_tlb_default_mem.can_grow)
1848 - return io_tlb_default_mem.phys_limit;
1849 - #endif
1847 + return io_tlb_default_mem.phys_limit;
1848 + #else
1850 1849 return io_tlb_default_mem.defpool.end - 1;
1850 + #endif
1851 1851 }
1852 1852
1853 1853 #ifdef CONFIG_DEBUG_FS
modified kernel/fork.c
@@ -3317,17 +3317,14 @@ int ksys_unshare(unsigned long unshare_flags)
3317 3317 shm_init_task(current);
3318 3318 }
3319 3319
3320 - if (new_fs) {
3321 - new_fs = switch_fs_struct(new_fs);
3322 - if (new_fs)
3323 - free_fs_struct(no_free_ptr(new_fs));
3324 - }
3325 -
3326 3320 if (new_nsproxy) {
3327 3321 switch_task_namespaces(current, new_nsproxy);
3328 3322 new_nsproxy = NULL;
3329 3323 }
3330 3324
3325 + if (new_fs)
3326 + new_fs = switch_fs_struct(new_fs);
3327 +
3331 3328 if (new_fd) {
3332 3329 guard(task_lock)(current);
3333 3330 swap(current->files, new_fd);
@@ -3343,9 +3340,8 @@ int ksys_unshare(unsigned long unshare_flags)
3343 3340 perf_event_namespaces(current);
3344 3341
3345 3342 bad_unshare_cleanup_nsproxy:
3346 - /* never installed, so no active references to drop */
3347 3343 if (new_nsproxy)
3348 - nsproxy_free(new_nsproxy);
3344 + put_nsproxy(new_nsproxy);
3349 3345 bad_unshare_cleanup_cred:
3350 3346 if (new_cred)
3351 3347 put_cred(new_cred);
modified kernel/nsproxy.c
@@ -61,7 +61,7 @@ static inline struct nsproxy *create_nsproxy(void)
61 61 return nsproxy;
62 62 }
63 63
64 - void nsproxy_free(struct nsproxy *ns)
64 + static inline void nsproxy_free(struct nsproxy *ns)
65 65 {
66 66 put_mnt_ns(ns->mnt_ns);
67 67 put_uts_ns(ns->uts_ns);
modified kernel/printk/nbcon.c
@@ -1887,7 +1887,6 @@ bool nbcon_device_try_acquire(struct console *con)
1887 1887
1888 1888 memset(ctxt, 0, sizeof(*ctxt));
1889 1889 ctxt->console = con;
1890 - /* Keep in sync with nbcon_braille_try_acquire(). */
1891 1890 ctxt->prio = NBCON_PRIO_NORMAL;
1892 1891
1893 1892 if (!nbcon_context_try_acquire(ctxt, false))
@@ -2003,81 +2002,3 @@ void nbcon_kdb_release(struct nbcon_write_context *wctxt)
2003 2002 */
2004 2003 __nbcon_atomic_flush_pending_con(ctxt->console, prb_next_reserve_seq(prb));
2005 2004 }
2006 -
2007 - /**
2008 - * nbcon_is_braille - Checks whether the nbcon write context is using Braille console
2009 - *
2010 - * @wctxt: checked nbcon write context
2011 - *
2012 - * Return: True when the write context is associated with a Braille console.
2013 - * Otherwise, return false.
2014 - *
2015 - * Context: Can be called in any context but only when Braille console is
2016 - * registered and the struct console could not disappear.
2017 - */
2018 - bool nbcon_write_context_is_braille(struct nbcon_write_context *wctxt)
2019 - {
2020 - struct nbcon_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt);
2021 - struct console *con = ctxt->console;
2022 -
2023 - return con && con->flags & CON_BRL;
2024 - }
2025 - EXPORT_SYMBOL_GPL(nbcon_write_context_is_braille);
2026 -
2027 - /**
2028 - * nbcon_braille_try_acquire - Try to acquire nbcon console for braille_write()
2029 - *
2030 - * @con: The nbcon console to acquire
2031 - * @wctxt: The nbcon write context to be used on success
2032 - *
2033 - * Context: braille_write() for emitting a single buffer on Braille console.
2034 - *
2035 - * Return: True if the console was acquired. False otherwise.
2036 - *
2037 - * Braille console is not registered as a proper printk consoles. Instead,
2038 - * it is integrated with the graphical virtual terminal.
2039 - *
2040 - * This function is going to synchronize the Braille write against other
2041 - * operations on the used serial port. The port can be used also for a user
2042 - * input but printk() won't emit the messages there directly. It means
2043 - * the other operations will get synchronized using nbcon_device_try_acquire().
2044 - */
2045 - bool nbcon_braille_try_acquire(struct console *con,
2046 - struct nbcon_write_context *wctxt)
2047 - {
2048 - struct nbcon_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt);
2049 - bool success;
2050 -
2051 - memset(ctxt, 0, sizeof(*ctxt));
2052 - ctxt->console = con;
2053 - /* Keep in sync with nbcon_device_try_acquire(). */
2054 - if (panic_on_this_cpu())
2055 - ctxt->prio = NBCON_PRIO_PANIC;
2056 - else
2057 - ctxt->prio = NBCON_PRIO_NORMAL;
2058 -
2059 - success = nbcon_context_try_acquire(ctxt, false);
2060 - /*
2061 - * Try hard in panic, otherwise the Braille console would
2062 - * miss a text on the related VT.
2063 - */
2064 - if (panic_on_this_cpu() && !success) {
2065 - ctxt->allow_unsafe_takeover = true;
2066 - success = nbcon_context_try_acquire(ctxt, false);
2067 - }
2068 -
2069 - return success;
2070 - }
2071 -
2072 - /**
2073 - * nbcon_braille_release - Release the nbcon console
2074 - *
2075 - * @wctxt: The nbcon write context initialized by a successful
2076 - * nbcon_braille_try_acquire()
2077 - */
2078 - void nbcon_braille_release(struct nbcon_write_context *wctxt)
2079 - {
2080 - struct nbcon_context *ctxt = &ACCESS_PRIVATE(wctxt, ctxt);
2081 -
2082 - nbcon_context_release(ctxt);
2083 - }
modified kernel/rcu/srcutree.c
@@ -704,7 +704,7 @@ void cleanup_srcu_struct(struct srcu_struct *ssp)
704 704 // Call srcu_barrier() before this cleanup_srcu_struct()
705 705 // to avoid triggering this WARN_ON().
706 706 if (WARN_ON(timer_delete_sync(&sdp->delay_work) &&
707 - !rcu_segcblist_empty(&sdp->srcu_cblist)) &&
707 + rcu_segcblist_n_cbs(&sdp->srcu_cblist)) &&
708 708 rcu_cpu_beenfullyonline(sdp->cpu))
709 709 queue_work_on(sdp->cpu, rcu_gp_wq, &sdp->work);
710 710 flush_work(&sdp->work);
modified kernel/sched/ext/ext.c
@@ -2057,14 +2057,8 @@ void scx_do_enqueue_task(struct rq *rq, struct task_struct *p, u64 enq_flags,
2057 2057 if (unlikely(!SCX_HAS_OP(sch, enqueue)))
2058 2058 goto global;
2059 2059
2060 - /*
2061 - * DSQ bypass didn't trigger, enqueue on the BPF scheduler. Wrap the
2062 - * per-task qseq counter where the QSEQ field wraps and skip 0, which is
2063 - * what scx_bpf_dsq_insert() records for a task in NONE or DISPATCHING.
2064 - */
2065 - p->scx.ops_qseq = ((p->scx.ops_qseq + 1) &
2066 - (SCX_OPSS_QSEQ_MASK >> SCX_OPSS_QSEQ_SHIFT)) ?: 1;
2067 - qseq = (unsigned long)p->scx.ops_qseq << SCX_OPSS_QSEQ_SHIFT;
2060 + /* DSQ bypass didn't trigger, enqueue on the BPF scheduler */
2061 + qseq = rq->scx.ops_qseq++ << SCX_OPSS_QSEQ_SHIFT;
2068 2062
2069 2063 WARN_ON_ONCE(atomic_long_read(&p->scx.ops_state) != SCX_OPSS_NONE);
2070 2064 atomic_long_set(&p->scx.ops_state, SCX_OPSS_QUEUEING | qseq);
@@ -2129,8 +2123,8 @@ static void set_task_runnable(struct rq *rq, struct task_struct *p)
2129 2123 }
2130 2124
2131 2125 /*
2132 - * list_add_tail() must be used. scx_bypass() and rq_offline_scx()
2133 - * depend on tasks being appended to the runnable_list.
2126 + * list_add_tail() must be used. scx_bypass() depends on tasks being
2127 + * appended to the runnable_list.
2134 2128 */
2135 2129 list_add_tail(&p->scx.runnable_node, &rq->scx.runnable_list);
2136 2130
@@ -2158,13 +2152,6 @@ static void enqueue_task_scx(struct rq *rq, struct task_struct *p, int core_enq_
2158 2152 int sticky_cpu = p->scx.sticky_cpu;
2159 2153 u64 enq_flags = core_enq_flags | rq->scx.remote_activate_enq_flags;
2160 2154
2161 - /*
2162 - * An SCX-internal migration ends on arrival. Clear sticky_cpu so @p can
2163 - * leave custody when inserted into the destination DSQ.
2164 - */
2165 - if (sticky_cpu >= 0)
2166 - p->scx.sticky_cpu = -1;
2167 -
2168 2155 /*
2169 2156 * SCX_RQ_IN_WAKEUP promises a task_woken_scx() call once this enqueue
2170 2157 * returns. Only the core's wakeup path delivers one. The flags stashed
@@ -2203,6 +2190,9 @@ static void enqueue_task_scx(struct rq *rq, struct task_struct *p, int core_enq_
2203 2190 dl_server_start(&rq->ext_server);
2204 2191
2205 2192 scx_do_enqueue_task(rq, p, enq_flags, sticky_cpu);
2193 +
2194 + if (sticky_cpu >= 0)
2195 + p->scx.sticky_cpu = -1;
2206 2196 out:
2207 2197 rq->scx.flags &= ~SCX_RQ_IN_WAKEUP;
2208 2198
@@ -3741,26 +3731,8 @@ static void rq_online_scx(struct rq *rq)
3741 3731
3742 3732 static void rq_offline_scx(struct rq *rq)
3743 3733 {
3744 - struct task_struct *p, *n;
3745 -
3746 3734 rq->scx.flags &= ~SCX_RQ_ONLINE;
3747 -
3748 - /* sched domain rebuilds call rq_offline with the CPU staying alive */
3749 - if (cpu_active(cpu_of(rq)))
3750 - return;
3751 -
3752 3735 scx_rescue_flush(rq);
3753 -
3754 - /*
3755 - * An offline CPU no longer calls ops.dispatch(). Re-enqueue its tasks
3756 - * onto the local DSQ so that they run here and balance_push() moves
3757 - * them off.
3758 - */
3759 - list_for_each_entry_safe_reverse(p, n, &rq->scx.runnable_list, scx.runnable_node) {
3760 - if (p->scx.dsq == &rq->scx.local_dsq)
3761 - continue;
3762 - guard(sched_change)(p, DEQUEUE_SAVE | DEQUEUE_MOVE | DEQUEUE_NOCLOCK);
3763 - }
3764 3736 }
3765 3737
3766 3738 static bool check_rq_for_timeouts(struct rq *rq)
@@ -6975,9 +6947,9 @@ static void scx_dump_cpu(struct scx_sched *sch, struct seq_buf *s,
6975 6947 seq_buf_init(&ns, buf, avail);
6976 6948
6977 6949 dump_newline(&ns);
6978 - scx_dump_line(&ns, "CPU %-4d: nr_run=%u flags=0x%x cpu_rel=%d ksync=%lu",
6950 + scx_dump_line(&ns, "CPU %-4d: nr_run=%u flags=0x%x cpu_rel=%d ops_qseq=%lu ksync=%lu",
6979 6951 cpu, rq->scx.nr_running, rq->scx.flags, rq->scx.cpu_released,
6980 - rq->scx.kick_sync);
6952 + rq->scx.ops_qseq, rq->scx.kick_sync);
6981 6953 scx_rescue_dump(&ns, rq);
6982 6954 scx_dump_line(&ns, " curr=%s[%d] class=%ps",
6983 6955 rq->curr->comm, rq->curr->pid, rq->curr->sched_class);
modified kernel/sched/ext/inlines.h
@@ -70,13 +70,7 @@ scx_dispatch_sched(struct scx_sched *sch, struct rq *rq,
70 70 #endif /* CONFIG_EXT_SUB_SCHED */
71 71 }
72 72
73 - /*
74 - * scx_rq_online() can't be used. Its cpu_active() test goes false
75 - * before CPU hotplug waits for an RCU grace period, and
76 - * rq_offline_scx() moves this CPU's tasks to the local DSQ only after
77 - * the wait. The grace period can depend on those tasks running.
78 - */
79 - if (unlikely(!SCX_HAS_OP(sch, dispatch)) || !(rq->scx.flags & SCX_RQ_ONLINE))
73 + if (unlikely(!SCX_HAS_OP(sch, dispatch)) || !scx_rq_online(rq))
80 74 return SCX_DSP_NONE;
81 75
82 76 dspc->rq = rq;
modified kernel/sched/ext/internal.h
@@ -1998,11 +1998,6 @@ enum scx_ops_state {
1998 1998 * dequeue/requeue, the dispatcher can tell whether it still has a claim
1999 1999 * on the task being dispatched.
2000 2000 *
2001 - * QSEQ is generated from the per-task p->scx.ops_qseq counter so that
2002 - * it doesn't repeat across QUEUED instances of the same task even if
2003 - * the task moves between rqs. 0 is never used as a valid QSEQ since
2004 - * NONE and DISPATCHING map to this value.
2005 - *
2006 2001 * As some 32bit archs can't do 64bit store_release/load_acquire,
2007 2002 * p->scx.ops_state is atomic_long_t which leaves 30 bits for QSEQ on
2008 2003 * 32bit machines. The dispatch race window QSEQ protects is very narrow
modified kernel/sched/ext/sub.c
@@ -585,6 +585,10 @@ void scx_rescue_flush(struct rq *rq)
585 585
586 586 lockdep_assert_rq_held(rq);
587 587
588 + /* sched domain rebuilds call rq_offline with the CPU staying alive */
589 + if (cpu_active(cpu_of(rq)))
590 + return;
591 +
588 592 /* end the current rescue */
589 593 if (rq->scx.rescue.curr)
590 594 scx_task_slice_ended(rq, rq->scx.rescue.curr);
modified kernel/sched/sched.h
@@ -816,6 +816,7 @@ struct scx_rq {
816 816 #endif
817 817 struct list_head runnable_list; /* runnable tasks on this rq */
818 818 struct list_head ddsp_deferred_locals; /* deferred ddsps from enq */
819 + unsigned long ops_qseq;
819 820 /* both stashed across the activate_task() in move_remote_task_to_local_dsq() */
820 821 u64 remote_activate_enq_flags;
821 822 struct scx_sched *remote_activate_sch;
@@ -4221,9 +4222,8 @@ extern void balance_callbacks(struct rq *rq, struct balance_callback *head);
4221 4222 * after which it is enqueued again.
4222 4223 *
4223 4224 * Typically this must be called while holding task_rq_lock, since most/all
4224 - * properties are serialized under those locks. There are currently two
4225 - * exceptions to this rule in sched/ext which only hold rq->lock: scx_bypass()
4226 - * and rq_offline_scx().
4225 + * properties are serialized under those locks. There is currently one
4226 + * exception to this rule in sched/ext which only holds rq->lock.
4227 4227 */
4228 4228
4229 4229 /*
modified kernel/trace/Makefile
@@ -146,12 +146,11 @@ KASAN_SANITIZE_undefsyms_base.o := y
146 146
147 147 UNDEFINED_ALLOWLIST = __asan __gcov __kasan __kcsan __hwasan __sancov __sanitizer __tsan __ubsan __msan \
148 148 __aeabi_unwind_cpp __s390_indirect_jump __x86_indirect_thunk simple_ring_buffer \
149 - current_thread_info_reg \
150 - $(shell $(NM) -u $(obj)/undefsyms_base.o 2>/dev/null | awk '$$2 {print $$2}')
149 + $(shell $(NM) -u $(obj)/undefsyms_base.o 2>/dev/null | awk '{print $$2}')
151 150
152 151 quiet_cmd_check_undefined = NM $<
153 152 cmd_check_undefined = \
154 - undefsyms=$$($(NM) -u $< | awk '$$2 {print $$2}' | grep -v $(addprefix -e , $(UNDEFINED_ALLOWLIST)) || true); \
153 + undefsyms=$$($(NM) -u $< | grep -v $(addprefix -e , $(UNDEFINED_ALLOWLIST)) || true); \
155 154 if [ -n "$$undefsyms" ]; then \
156 155 echo "Unexpected symbols in $<:" >&2; \
157 156 echo "$$undefsyms" >&2; \
modified kernel/trace/ring_buffer.c
@@ -2380,9 +2380,6 @@ int ring_buffer_meta_seq_init(struct file *file, struct trace_buffer *buffer, in
2380 2380 struct seq_file *m;
2381 2381 int ret;
2382 2382
2383 - if (!cpumask_test_cpu(cpu, buffer->cpumask))
2384 - return -ENODEV;
2385 -
2386 2383 ret = seq_open(file, &rb_meta_seq_ops);
2387 2384 if (ret)
2388 2385 return ret;
@@ -3630,8 +3627,10 @@ static void rb_inc_iter(struct ring_buffer_iter *iter)
3630 3627 /* Return the index into the sub-buffers for a given sub-buffer */
3631 3628 static int rb_meta_subbuf_idx(struct ring_buffer_cpu_meta *meta, void *subbuf)
3632 3629 {
3633 - void *subbuf_array = rb_subbufs_from_meta(meta);
3630 + void *subbuf_array;
3634 3631
3632 + subbuf_array = (void *)meta + sizeof(int) * meta->nr_subbufs;
3633 + subbuf_array = (void *)ALIGN((unsigned long)subbuf_array, meta->subbuf_size);
3635 3634 return (subbuf - subbuf_array) / meta->subbuf_size;
3636 3635 }
3637 3636
modified kernel/trace/trace.c
@@ -5881,7 +5881,7 @@ static int tracing_buffer_meta_open(struct inode *inode, struct file *filp)
5881 5881
5882 5882 ret = ring_buffer_meta_seq_init(filp, tr->array_buffer.buffer, cpu);
5883 5883 if (ret < 0)
5884 - trace_array_put(tr);
5884 + __trace_array_put(tr);
5885 5885 return ret;
5886 5886 }
5887 5887
modified kernel/trace/trace_events_hist.c
@@ -289,7 +289,7 @@ static u64 hist_field_log2(struct hist_field *hist_field,
289 289
290 290 u64 val = hist_fn_call(operand, elt, buffer, rbe, event);
291 291
292 - return order_base_2(val);
292 + return (u64) ilog2(roundup_pow_of_two(val));
293 293 }
294 294
295 295 static u64 hist_field_bucket(struct hist_field *hist_field,
@@ -3090,7 +3090,7 @@ create_field_var_hist(struct hist_trigger_data *target_hist_data,
3090 3090 key_field = hist_data->fields[i];
3091 3091 if (!first)
3092 3092 seq_buf_putc(&s, ',');
3093 - expr_field_str(key_field, &s);
3093 + seq_buf_puts(&s, key_field->field->name);
3094 3094 first = false;
3095 3095 }
3096 3096
modified kernel/trace/undefsyms_base.c
@@ -9,7 +9,6 @@
9 9
10 10 #include <linux/atomic.h>
11 11 #include <linux/string.h>
12 - #include <asm/local.h>
13 12 #include <asm/page.h>
14 13
15 14 void undefsyms_base(void *p, int n);
@@ -19,13 +18,11 @@ static char page[PAGE_SIZE] __aligned(PAGE_SIZE);
19 18 void undefsyms_base(void *p, int n)
20 19 {
21 20 char buffer[256] = { 0 };
22 - u32 u = 0;
23 21
22 + u32 u = 0;
24 23 memset((char * volatile)page, 8, PAGE_SIZE);
25 24 memset((char * volatile)buffer, 8, sizeof(buffer));
26 25 memcpy((void * volatile)p, buffer, sizeof(buffer));
27 26 cmpxchg((u32 * volatile)&u, 0, 8);
28 - cmpxchg((unsigned long *)p, 0, 8);
29 - local_set((local_t *)p, 8);
30 27 WARN_ON(n == 0xdeadbeef);
31 28 }
modified kernel/workqueue.c
@@ -2290,7 +2290,7 @@ static bool is_chained_work(struct workqueue_struct *wq)
2290 2290 * Return %true iff I'm a worker executing a work item on @wq. If
2291 2291 * I'm @worker, it's safe to dereference it without locking.
2292 2292 */
2293 - return worker && worker->current_pwq && worker->current_pwq->wq == wq;
2293 + return worker && worker->current_pwq->wq == wq;
2294 2294 }
2295 2295
2296 2296 /*
modified lib/Kconfig.debug
@@ -2906,21 +2906,6 @@ config LIVEUPDATE_TEST
2906 2906
2907 2907 If unsure, say N
2908 2908
2909 - config DIMLIB_KUNIT_TEST
2910 - tristate "KUnit test for the DIM library" if !KUNIT_ALL_TESTS
2911 - depends on KUNIT && NET
2912 - select DIMLIB
2913 - default KUNIT_ALL_TESTS
2914 - help
2915 - This builds the KUnit test for the Dynamic Interrupt Moderation
2916 - library (lib/dim/), which checks the rate statistics computed by
2917 - dim_calc_stats().
2918 -
2919 - For more information on KUnit and unit tests in general please refer
2920 - to the KUnit documentation in Documentation/dev-tools/kunit/.
2921 -
2922 - If unsure, say N.
2923 -
2924 2909 config CMDLINE_KUNIT_TEST
2925 2910 tristate "KUnit test for cmdline API" if !KUNIT_ALL_TESTS
2926 2911 depends on KUNIT
modified lib/dim/Makefile
@@ -5,5 +5,3 @@
5 5 obj-$(CONFIG_DIMLIB) += dimlib.o
6 6
7 7 dimlib-y := dim.o net_dim.o rdma_dim.o
8 -
9 - obj-$(CONFIG_DIMLIB_KUNIT_TEST) += dim_kunit.o
modified lib/dim/dim.c
@@ -69,15 +69,11 @@ bool dim_calc_stats(const struct dim_sample *start,
69 69 if (!delta_us)
70 70 return false;
71 71
72 - /* u32 * USEC_PER_MSEC overflows a 32-bit long */
73 - curr_stats->ppms = DIV_ROUND_UP_ULL((u64)npkts * USEC_PER_MSEC,
74 - delta_us);
75 - curr_stats->bpms = DIV_ROUND_UP_ULL((u64)nbytes * USEC_PER_MSEC,
76 - delta_us);
72 + curr_stats->ppms = DIV_ROUND_UP(npkts * USEC_PER_MSEC, delta_us);
73 + curr_stats->bpms = DIV_ROUND_UP(nbytes * USEC_PER_MSEC, delta_us);
77 74 curr_stats->epms = DIV_ROUND_UP(DIM_NEVENTS * USEC_PER_MSEC,
78 75 delta_us);
79 - curr_stats->cpms = DIV_ROUND_UP_ULL((u64)ncomps * USEC_PER_MSEC,
80 - delta_us);
76 + curr_stats->cpms = DIV_ROUND_UP(ncomps * USEC_PER_MSEC, delta_us);
81 77 if (curr_stats->epms != 0)
82 78 curr_stats->cpe_ratio = DIV_ROUND_DOWN_ULL(
83 79 curr_stats->cpms * 100, curr_stats->epms);
deleted lib/dim/dim_kunit.c mode 100644
@@ -1,126 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * KUnit tests for the Dynamic Interrupt Moderation library
4 - */
5 -
6 - #include <kunit/test.h>
7 - #include <linux/dim.h>
8 - #include <linux/ktime.h>
9 - #include <linux/module.h>
10 -
11 - struct dim_calc_stats_case {
12 - const char *name;
13 - u32 delta_us;
14 - u32 start_pkts, end_pkts;
15 - u32 start_bytes, end_bytes;
16 - u32 start_comps, end_comps;
17 - int ppms, bpms, cpms;
18 - };
19 -
20 - static const struct dim_calc_stats_case dim_calc_stats_cases[] = {
21 - {
22 - .name = "small",
23 - .delta_us = 1000,
24 - .end_pkts = 640, .end_bytes = 640 * 1500, .end_comps = 64,
25 - .ppms = 640, .bpms = 960000, .cpms = 64,
26 - },
27 - {
28 - .name = "round_up",
29 - .delta_us = 3000,
30 - .end_pkts = 10, .end_bytes = 10, .end_comps = 1,
31 - .ppms = 4, .bpms = 4, .cpms = 1,
32 - },
33 - {
34 - .name = "counter_wrap",
35 - .delta_us = 1000,
36 - .start_pkts = 0xffffff00, .end_pkts = 0x100,
37 - .start_bytes = 0xfffff000, .end_bytes = 0x1000,
38 - .start_comps = 0xfffffff0, .end_comps = 0x10,
39 - .ppms = 0x200, .bpms = 0x2000, .cpms = 0x20,
40 - },
41 - {
42 - /* 30 MB in 10 ms (24 Gbit/s): nbytes * 1000 exceeds 32 bits */
43 - .name = "many_bytes",
44 - .delta_us = 10000,
45 - .end_pkts = 20000, .end_bytes = 30000000, .end_comps = 64,
46 - .ppms = 2000, .bpms = 3000000, .cpms = 7,
47 - },
48 - {
49 - /* 4.3 MB in 16 ms (2.15 Gbit/s), just above the 32-bit limit */
50 - .name = "bytes_32bit_limit",
51 - .delta_us = 16000,
52 - .end_pkts = 2900, .end_bytes = 4300000, .end_comps = 64,
53 - .ppms = 182, .bpms = 268750, .cpms = 4,
54 - },
55 - {
56 - /* 5 MB in 40 ms: a 1 Gbit/s link at line rate */
57 - .name = "gigabit",
58 - .delta_us = 40000,
59 - .end_pkts = 3300, .end_bytes = 5000000, .end_comps = 64,
60 - .ppms = 83, .bpms = 125000, .cpms = 2,
61 - },
62 - {
63 - /* 5 million packets and completions in 2 s */
64 - .name = "many_packets",
65 - .delta_us = 2000000,
66 - .end_pkts = 5000000, .end_bytes = 5000000, .end_comps = 5000000,
67 - .ppms = 2500, .bpms = 2500, .cpms = 2500,
68 - },
69 - };
70 -
71 - static void dim_calc_stats_case_desc(const struct dim_calc_stats_case *t,
72 - char *desc)
73 - {
74 - strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
75 - }
76 -
77 - KUNIT_ARRAY_PARAM(dim_calc_stats, dim_calc_stats_cases,
78 - dim_calc_stats_case_desc);
79 -
80 - static void dim_calc_stats_test(struct kunit *test)
81 - {
82 - const struct dim_calc_stats_case *t = test->param_value;
83 - struct dim_sample start = {}, end = {};
84 - struct dim_stats stats = {};
85 -
86 - dim_update_sample_with_comps(0, t->start_pkts, t->start_bytes,
87 - t->start_comps, &start);
88 - dim_update_sample_with_comps(DIM_NEVENTS, t->end_pkts, t->end_bytes,
89 - t->end_comps, &end);
90 - /* dim_update_sample() stamps ktime_get(); use fixed times instead */
91 - start.time = ktime_set(1000, 0);
92 - end.time = ktime_add_us(start.time, t->delta_us);
93 -
94 - KUNIT_ASSERT_TRUE(test, dim_calc_stats(&start, &end, &stats));
95 - KUNIT_EXPECT_EQ(test, stats.ppms, t->ppms);
96 - KUNIT_EXPECT_EQ(test, stats.bpms, t->bpms);
97 - KUNIT_EXPECT_EQ(test, stats.cpms, t->cpms);
98 - KUNIT_EXPECT_EQ(test, stats.epms,
99 - (int)DIV_ROUND_UP(DIM_NEVENTS * USEC_PER_MSEC,
100 - t->delta_us));
101 - }
102 -
103 - static void dim_calc_stats_no_time_test(struct kunit *test)
104 - {
105 - struct dim_sample sample = {};
106 - struct dim_stats stats = {};
107 -
108 - dim_update_sample_with_comps(0, 100, 1000, 10, &sample);
109 - KUNIT_EXPECT_FALSE(test, dim_calc_stats(&sample, &sample, &stats));
110 - }
111 -
112 - static struct kunit_case dim_test_cases[] = {
113 - KUNIT_CASE_PARAM(dim_calc_stats_test, dim_calc_stats_gen_params),
114 - KUNIT_CASE(dim_calc_stats_no_time_test),
115 - {}
116 - };
117 -
118 - static struct kunit_suite dim_test_suite = {
119 - .name = "dim",
120 - .test_cases = dim_test_cases,
121 - };
122 -
123 - kunit_test_suite(dim_test_suite);
124 -
125 - MODULE_DESCRIPTION("KUnit tests for the DIM library");
126 - MODULE_LICENSE("GPL");
modified mm/mremap.c
@@ -1037,7 +1037,6 @@ static void vrm_stat_account(struct vma_remap_struct *vrm,
1037 1037 }
1038 1038
1039 1039 static bool __check_map_count_against_split(struct mm_struct *mm,
1040 - bool pre_split,
1041 1040 bool before_unmaps)
1042 1041 {
1043 1042 const int sys_map_count = get_sysctl_max_map_count();
@@ -1089,42 +1088,26 @@ static bool __check_map_count_against_split(struct mm_struct *mm,
1089 1088 * Therefore we must check to ensure we have headroom of 2 additional
1090 1089 * VMAs.
1091 1090 */
1092 - map_count += 2;
1093 -
1094 - /* If pre-split, the -1 observed above doesn't apply. */
1095 - if (pre_split)
1096 - map_count++;
1097 -
1098 - return map_count <= sys_map_count;
1099 - }
1100 -
1101 - static bool needs_pre_split(struct vma_remap_struct *vrm)
1102 - {
1103 - /*
1104 - * An MREMAP_DONTUNMAP of a mlock()'d VMA needs to unlock the
1105 - * source VMA, so split in this case.
1106 - */
1107 - return (vrm->flags & MREMAP_DONTUNMAP) &&
1108 - vma_test(vrm->vma, VMA_LOCKED_BIT);
1091 + return map_count + 2 <= sys_map_count;
1109 1092 }
1110 1093
1111 1094 /* Do we violate the map count limit if we split VMAs when moving the VMA? */
1112 - static bool check_map_count_against_split(struct vma_remap_struct *vrm)
1095 + static bool check_map_count_against_split(void)
1113 1096 {
1114 1097 return __check_map_count_against_split(current->mm,
1115 - needs_pre_split(vrm), /*before_unmaps=*/false);
1098 + /*before_unmaps=*/false);
1116 1099 }
1117 1100
1118 1101 /* Do we violate the map count limit if we split VMAs prior to early unmaps? */
1119 - static bool check_map_count_against_split_early(struct vma_remap_struct *vrm)
1102 + static bool check_map_count_against_split_early(void)
1120 1103 {
1121 1104 return __check_map_count_against_split(current->mm,
1122 - vrm->flags & MREMAP_DONTUNMAP, /*before_unmaps=*/true);
1105 + /*before_unmaps=*/true);
1123 1106 }
1124 1107
1125 1108 /*
1126 - * Perform checks and preparation before attempting to write a VMA prior to it
1127 - * being moved.
1109 + * Perform checks before attempting to write a VMA prior to it being
1110 + * moved.
1128 1111 */
1129 1112 static unsigned long prep_move_vma(struct vma_remap_struct *vrm)
1130 1113 {
@@ -1133,17 +1116,19 @@ static unsigned long prep_move_vma(struct vma_remap_struct *vrm)
1133 1116 unsigned long old_addr = vrm->addr;
1134 1117 unsigned long old_len = vrm->old_len;
1135 1118 vm_flags_t dummy = vma->vm_flags;
1136 - const bool split_before = vma->vm_start != old_addr;
1137 - const bool split_after = vma->vm_end != old_addr + old_len;
1138 1119
1139 - /* Avoid failure later on. */
1140 - if (!check_map_count_against_split(vrm))
1120 + /*
1121 + * We'd prefer to avoid failure later on in do_munmap: we copy a VMA,
1122 + * which may not merge, then (if MREMAP_DONTUNMAP is not set) unmap the
1123 + * source, which may split, causing a net increase of 2 mappings.
1124 + */
1125 + if (!check_map_count_against_split())
1141 1126 return -ENOMEM;
1142 1127
1143 1128 if (vma->vm_ops && vma->vm_ops->may_split) {
1144 - if (split_before)
1129 + if (vma->vm_start != old_addr)
1145 1130 err = vma->vm_ops->may_split(vma, old_addr);
1146 - if (!err && split_after)
1131 + if (!err && vma->vm_end != old_addr + old_len)
1147 1132 err = vma->vm_ops->may_split(vma, old_addr + old_len);
1148 1133 if (err)
1149 1134 return err;
@@ -1161,21 +1146,6 @@ static unsigned long prep_move_vma(struct vma_remap_struct *vrm)
1161 1146 if (err)
1162 1147 return err;
1163 1148
1164 - /*
1165 - * To account mlock()'d pages correctly in the MREMAP_DONTUNMAP
1166 - * case perform any split ahead of time for an mlock()'d VMA.
1167 - */
1168 - if (needs_pre_split(vrm)) {
1169 - VMA_ITERATOR(vmi, vma->vm_mm, old_addr);
1170 -
1171 - if (split_before)
1172 - err = split_vma(&vmi, vma, old_addr, 1);
1173 - if (!err && split_after)
1174 - err = split_vma(&vmi, vma, old_addr + old_len, 0);
1175 - vrm->vmi_needs_invalidate = true;
1176 - return err;
1177 - }
1178 -
1179 1149 return 0;
1180 1150 }
1181 1151
@@ -1305,8 +1275,7 @@ static int copy_vma_and_data(struct vma_remap_struct *vrm,
1305 1275 PAGETABLE_MOVE(pmc, NULL, NULL, vrm->addr, vrm->new_addr, vrm->old_len);
1306 1276
1307 1277 new_vma = copy_vma(&vma, vrm->new_addr, vrm->new_len, new_pgoff,
1308 - new_anon_pgoff, &pmc.need_rmap_locks,
1309 - vrm->flags & MREMAP_DONTUNMAP);
1278 + new_anon_pgoff, &pmc.need_rmap_locks);
1310 1279 if (!new_vma) {
1311 1280 vrm_uncharge(vrm);
1312 1281 *new_vma_ptr = NULL;
@@ -1366,9 +1335,6 @@ static void dontunmap_complete(struct vma_remap_struct *vrm,
1366 1335 unsigned long old_start = vma->vm_start;
1367 1336 unsigned long old_end = vma->vm_end;
1368 1337
1369 - /* Self-merge is disallowed. */
1370 - VM_WARN_ON_ONCE(new_vma == vma);
1371 -
1372 1338 /* We always clear VMA_LOCKED[ONFAULT]_BIT on the old VMA. */
1373 1339 vma_clear_flags_mask(vma, VMA_LOCKED_MASK);
1374 1340
@@ -1376,7 +1342,7 @@ static void dontunmap_complete(struct vma_remap_struct *vrm,
1376 1342 * anon_vma links of the old vma is no longer needed after its page
1377 1343 * table has been moved.
1378 1344 */
1379 - if (start == old_start && end == old_end) {
1345 + if (new_vma != vma && start == old_start && end == old_end) {
1380 1346 const pgoff_t pgoff_unfaulted = vma->vm_start >> PAGE_SHIFT;
1381 1347
1382 1348 unlink_anon_vmas(vma);
@@ -2036,7 +2002,7 @@ static unsigned long do_mremap(struct vma_remap_struct *vrm)
2036 2002 return -EINTR;
2037 2003 vrm->mmap_locked = true;
2038 2004
2039 - if (!check_map_count_against_split_early(vrm)) {
2005 + if (!check_map_count_against_split_early()) {
2040 2006 mmap_write_unlock(mm);
2041 2007 return -ENOMEM;
2042 2008 }
modified mm/pgtable-generic.c
@@ -438,30 +438,12 @@ static void kernel_pgtable_work_func(struct work_struct *work)
438 438 __pagetable_free(pt);
439 439 }
440 440
441 - static void schedule_kernel_pgtable_free(void)
442 - {
443 - schedule_work(&kernel_pgtable_work.work);
444 - }
445 -
446 441 void pagetable_free_kernel(struct ptdesc *pt)
447 442 {
448 443 spin_lock(&kernel_pgtable_work.lock);
449 444 list_add(&pt->pt_list, &kernel_pgtable_work.list);
450 445 spin_unlock(&kernel_pgtable_work.lock);
451 446
452 - /*
453 - * The workqueue may not exist yet while the system is booting.
454 - * kernel_pgtable_drain_early() schedules the work once it does.
455 - */
456 - if (system_state != SYSTEM_BOOTING)
457 - schedule_kernel_pgtable_free();
458 - }
459 -
460 - static int __init kernel_pgtable_drain_early(void)
461 - {
462 - /* Free the kernel page tables queued while booting. */
463 - schedule_kernel_pgtable_free();
464 - return 0;
447 + schedule_work(&kernel_pgtable_work.work);
465 448 }
466 - core_initcall(kernel_pgtable_drain_early);
467 449 #endif
modified mm/vma.c
@@ -634,8 +634,8 @@ out_free_vma:
634 634 * Split a vma into two pieces at address 'addr', a new vma is allocated
635 635 * either for the first part or the tail.
636 636 */
637 - int split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
638 - unsigned long addr, int new_below)
637 + static int split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
638 + unsigned long addr, int new_below)
639 639 {
640 640 if (vma->vm_mm->map_count >= get_sysctl_max_map_count())
641 641 return -ENOMEM;
@@ -1943,7 +1943,7 @@ static int vma_link(struct mm_struct *mm, struct vm_area_struct *vma)
1943 1943 */
1944 1944 struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
1945 1945 unsigned long addr, unsigned long len, pgoff_t pgoff,
1946 - pgoff_t anon_pgoff, bool *need_rmap_locks, bool keep_source)
1946 + pgoff_t anon_pgoff, bool *need_rmap_locks)
1947 1947 {
1948 1948 struct vm_area_struct *vma = *vmap;
1949 1949 unsigned long old_vma_start = vma->vm_start;
@@ -1981,21 +1981,6 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
1981 1981 vmg.pgoff = pgoff;
1982 1982 vmg.anon_pgoff = anon_pgoff;
1983 1983 vmg.next = vma_iter_next_rewind(&vmi, NULL);
1984 -
1985 - /*
1986 - * If the original VMA is kept (MREMAP_DONTUNMAP), the source and
1987 - * destination VMA must be treated distinctly.
1988 - *
1989 - * A merge violates this, so in this case disallow a self-merge.
1990 - */
1991 - if (can_self_merge && keep_source) {
1992 - if (vmg.prev == vma)
1993 - vmg.prev = NULL;
1994 - if (vmg.next == vma)
1995 - vmg.next = NULL;
1996 - can_self_merge = false;
1997 - }
1998 -
1999 1984 new_vma = vma_merge_copied_range(&vmg);
2000 1985
2001 1986 if (new_vma) {
modified mm/vma.h
@@ -535,7 +535,7 @@ void unlink_file_vma_batch_add(struct unlink_vma_file_batch *vb,
535 535
536 536 struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
537 537 unsigned long addr, unsigned long len, pgoff_t pgoff,
538 - pgoff_t anon_pgoff, bool *need_rmap_locks, bool keep_source);
538 + pgoff_t anon_pgoff, bool *need_rmap_locks);
539 539
540 540 struct anon_vma *find_mergeable_anon_vma(struct vm_area_struct *vma);
541 541
@@ -556,11 +556,6 @@ int do_brk_flags(struct vma_iterator *vmi, struct vm_area_struct *brkvma,
556 556 unsigned long unmapped_area(struct vm_unmapped_area_info *info);
557 557 unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
558 558
559 - #ifdef CONFIG_MMU
560 - int split_vma(struct vma_iterator *vmi, struct vm_area_struct *vma,
561 - unsigned long addr, int new_below);
562 - #endif
563 -
564 559 static inline bool vma_wants_manual_pte_write_upgrade(struct vm_area_struct *vma)
565 560 {
566 561 /*
modified net/bluetooth/hci_core.c
@@ -4115,11 +4115,9 @@ static int hci_send_cmd_sync(struct hci_dev *hdev, struct sk_buff *skb)
4115 4115
4116 4116 bt_dev_dbg(hdev, "skb %p", skb);
4117 4117
4118 - hci_dev_lock(hdev);
4119 4118 kfree_skb(hdev->sent_cmd);
4120 4119
4121 4120 hdev->sent_cmd = skb_clone(skb, GFP_KERNEL);
4122 - hci_dev_unlock(hdev);
4123 4121 if (!hdev->sent_cmd) {
4124 4122 skb_queue_head(&hdev->cmd_q, skb);
4125 4123 queue_work(hdev->workqueue, &hdev->cmd_work);
@@ -4140,10 +4138,8 @@ static int hci_send_cmd_sync(struct hci_dev *hdev, struct sk_buff *skb)
4140 4138
4141 4139 if (READ_ONCE(hdev->req_status) == HCI_REQ_PEND &&
4142 4140 !hci_dev_test_and_set_flag(hdev, HCI_CMD_PENDING)) {
4143 - hci_dev_lock(hdev);
4144 4141 kfree_skb(hdev->req_skb);
4145 4142 hdev->req_skb = skb_get(hdev->sent_cmd);
4146 - hci_dev_unlock(hdev);
4147 4143 }
4148 4144
4149 4145 return err;
modified net/bluetooth/hci_sock.c
@@ -1223,10 +1223,8 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr_unsized *addr,
1223 1223 */
1224 1224 hdev = hci_pi(sk)->hdev;
1225 1225 if (hdev && hci_dev_test_flag(hdev, HCI_UNREGISTER)) {
1226 - write_lock(&hci_sk_list.lock);
1227 1226 hci_pi(sk)->hdev = NULL;
1228 1227 sk->sk_state = BT_OPEN;
1229 - write_unlock(&hci_sk_list.lock);
1230 1228 hci_dev_put(hdev);
1231 1229 }
1232 1230 hdev = NULL;
modified net/bluetooth/hci_sync.c
@@ -32,10 +32,8 @@ static void hci_cmd_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode,
32 32 WRITE_ONCE(hdev->req_status, HCI_REQ_DONE);
33 33
34 34 /* Free the request command so it is not used as response */
35 - hci_dev_lock(hdev);
36 35 kfree_skb(hdev->req_skb);
37 36 hdev->req_skb = NULL;
38 - hci_dev_unlock(hdev);
39 37
40 38 if (skb) {
41 39 struct sock *sk = hci_skb_sk(skb);
@@ -3066,21 +3064,15 @@ static int hci_le_set_ext_scan_param_sync(struct hci_dev *hdev, u8 type,
3066 3064 */
3067 3065 if (hci_dev_test_flag(hdev, HCI_PA_SYNC)) {
3068 3066 struct hci_cp_le_add_to_accept_list *sent;
3069 - bdaddr_t bdaddr;
3070 3067
3071 - hci_dev_lock(hdev);
3072 3068 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_ACCEPT_LIST);
3073 - if (sent)
3074 - bacpy(&bdaddr, &sent->bdaddr);
3075 - hci_dev_unlock(hdev);
3076 -
3077 3069 if (sent) {
3078 3070 struct hci_conn *conn;
3079 3071
3080 3072 rcu_read_lock();
3081 3073
3082 3074 conn = hci_conn_hash_lookup_ba(hdev, PA_LINK,
3083 - &bdaddr);
3075 + &sent->bdaddr);
3084 3076 if (conn) {
3085 3077 struct bt_iso_qos *qos = &conn->iso_qos;
3086 3078
modified net/bluetooth/iso.c
@@ -61,7 +61,6 @@ enum {
61 61 BT_SK_BIG_SYNC,
62 62 BT_SK_PA_SYNC,
63 63 BT_SK_KILLED,
64 - BT_SK_CONNECTING,
65 64 };
66 65
67 66 struct iso_pinfo {
@@ -351,9 +350,6 @@ static int __iso_chan_add(struct iso_conn *conn, struct sock *sk,
351 350 return -EBUSY;
352 351 }
353 352
354 - if (iso_pi(sk)->conn)
355 - return -EISCONN;
356 -
357 353 if (!conn->hcon) {
358 354 BT_ERR("conn->hcon missing");
359 355 return -EIO;
@@ -414,11 +410,6 @@ static int iso_connect_bis(struct sock *sk)
414 410 hci_dev_lock(hdev);
415 411 lock_sock(sk);
416 412
417 - if (iso_pi(sk)->conn) {
418 - err = -EISCONN;
419 - goto unlock;
420 - }
421 -
422 413 if (!bis_capable(hdev)) {
423 414 err = -EOPNOTSUPP;
424 415 goto unlock;
@@ -571,13 +562,6 @@ static int iso_connect_cis(struct sock *sk)
571 562
572 563 lockdep_assert_held(&hcon->hdev->lock);
573 564
574 - /* The socket lock keeps the current attachment and its hcon stable. */
575 - if (iso_pi(sk)->conn && iso_pi(sk)->conn->hcon != hcon) {
576 - hci_conn_drop(hcon);
577 - err = -EISCONN;
578 - goto unlock;
579 - }
580 -
581 565 conn = iso_conn_add(hcon);
582 566 if (!conn) {
583 567 hci_conn_drop(hcon);
@@ -1285,26 +1269,17 @@ static int iso_sock_connect(struct socket *sock, struct sockaddr_unsized *addr,
1285 1269 addr->sa_family != AF_BLUETOOTH)
1286 1270 return -EINVAL;
1287 1271
1288 - lock_sock(sk);
1289 -
1290 - if ((sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND) ||
1291 - test_bit(BT_SK_CONNECTING, &iso_pi(sk)->flags)) {
1292 - err = -EBADFD;
1293 - goto done;
1294 - }
1272 + if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND)
1273 + return -EBADFD;
1295 1274
1296 - if (sk->sk_type != SOCK_SEQPACKET) {
1297 - err = -EINVAL;
1298 - goto done;
1299 - }
1275 + if (sk->sk_type != SOCK_SEQPACKET)
1276 + return -EINVAL;
1300 1277
1301 1278 /* Check if the address type is of LE type */
1302 - if (!bdaddr_type_is_le(sa->iso_bdaddr_type)) {
1303 - err = -EINVAL;
1304 - goto done;
1305 - }
1279 + if (!bdaddr_type_is_le(sa->iso_bdaddr_type))
1280 + return -EINVAL;
1306 1281
1307 - set_bit(BT_SK_CONNECTING, &iso_pi(sk)->flags);
1282 + lock_sock(sk);
1308 1283
1309 1284 bacpy(&iso_pi(sk)->dst, &sa->iso_bdaddr);
1310 1285 iso_pi(sk)->dst_type = sa->iso_bdaddr_type;
@@ -1316,18 +1291,16 @@ static int iso_sock_connect(struct socket *sock, struct sockaddr_unsized *addr,
1316 1291 else
1317 1292 err = iso_connect_bis(sk);
1318 1293
1319 - lock_sock(sk);
1320 -
1321 - clear_bit(BT_SK_CONNECTING, &iso_pi(sk)->flags);
1322 1294 if (err)
1323 - goto done;
1295 + return err;
1296 +
1297 + lock_sock(sk);
1324 1298
1325 1299 if (!test_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) {
1326 1300 err = bt_sock_wait_state(sk, BT_CONNECTED,
1327 1301 sock_sndtimeo(sk, flags & O_NONBLOCK));
1328 1302 }
1329 1303
1330 - done:
1331 1304 release_sock(sk);
1332 1305 return err;
1333 1306 }
@@ -1367,11 +1340,6 @@ static int iso_listen_bis(struct sock *sk)
1367 1340 hci_dev_lock(hdev);
1368 1341 lock_sock(sk);
1369 1342
1370 - if (sk->sk_state != BT_BOUND || iso_pi(sk)->conn) {
1371 - err = -EBADFD;
1372 - goto unlock;
1373 - }
1374 -
1375 1343 /* Fail if user set invalid QoS */
1376 1344 if (iso_pi(sk)->qos_user_set && !check_bcast_qos(&iso_pi(sk)->qos)) {
1377 1345 iso_pi(sk)->qos = default_qos;
modified net/bluetooth/mgmt.c
@@ -1495,7 +1495,7 @@ static void cmd_complete_rsp(struct mgmt_pending_cmd *cmd, void *data)
1495 1495 return;
1496 1496 }
1497 1497
1498 - cmd_status_rsp(cmd, &match->mgmt_status);
1498 + cmd_status_rsp(cmd, data);
1499 1499 }
1500 1500
1501 1501 static int generic_cmd_complete(struct mgmt_pending_cmd *cmd, u8 status)
modified net/bluetooth/rfcomm/core.c
@@ -62,9 +62,10 @@ static void rfcomm_make_uih(struct sk_buff *skb, u8 addr);
62 62
63 63 static void rfcomm_process_connect(struct rfcomm_session *s);
64 64
65 - static struct socket *rfcomm_session_connect(bdaddr_t *src, bdaddr_t *dst,
66 - u8 sec_level, int *err);
67 - static struct rfcomm_session *rfcomm_session_add(struct socket *sock, int state);
65 + static struct rfcomm_session *rfcomm_session_create(bdaddr_t *src,
66 + bdaddr_t *dst,
67 + u8 sec_level,
68 + int *err);
68 69 static struct rfcomm_session *rfcomm_session_get(bdaddr_t *src, bdaddr_t *dst);
69 70 static struct rfcomm_session *rfcomm_session_del(struct rfcomm_session *s);
70 71
@@ -364,17 +365,28 @@ static int rfcomm_check_channel(u8 channel)
364 365 return channel < 1 || channel > 30;
365 366 }
366 367
367 - static int __rfcomm_dlc_open(struct rfcomm_dlc *d, struct rfcomm_session *s,
368 - u8 channel)
368 + static int __rfcomm_dlc_open(struct rfcomm_dlc *d, bdaddr_t *src, bdaddr_t *dst, u8 channel)
369 369 {
370 + struct rfcomm_session *s;
371 + int err = 0;
370 372 u8 dlci;
371 373
372 - BT_DBG("dlc %p state %ld session %p channel %d",
373 - d, d->state, s, channel);
374 + BT_DBG("dlc %p state %ld %pMR -> %pMR channel %d",
375 + d, d->state, src, dst, channel);
376 +
377 + if (rfcomm_check_channel(channel))
378 + return -EINVAL;
374 379
375 380 if (d->state != BT_OPEN && d->state != BT_CLOSED)
376 381 return 0;
377 382
383 + s = rfcomm_session_get(src, dst);
384 + if (!s) {
385 + s = rfcomm_session_create(src, dst, d->sec_level, &err);
386 + if (!s)
387 + return err;
388 + }
389 +
378 390 dlci = __dlci(__session_dir(s), channel);
379 391
380 392 /* Check if DLCI already exists */
@@ -409,84 +421,14 @@ static int __rfcomm_dlc_open(struct rfcomm_dlc *d, struct rfcomm_session *s,
409 421
410 422 int rfcomm_dlc_open(struct rfcomm_dlc *d, bdaddr_t *src, bdaddr_t *dst, u8 channel)
411 423 {
412 - struct rfcomm_session *s;
413 - struct socket *sock;
414 - int err;
415 -
416 - BT_DBG("dlc %p state %ld %pMR -> %pMR channel %d",
417 - d, d->state, src, dst, channel);
418 -
419 - if (rfcomm_check_channel(channel))
420 - return -EINVAL;
421 -
422 - rfcomm_lock();
423 -
424 - clear_bit(RFCOMM_CLOSED, &d->flags);
425 -
426 - /* Do not page the remote device for a DLC that cannot be opened
427 - * anyway. __rfcomm_dlc_open() looks at the state again once the
428 - * lock has been re-acquired below.
429 - */
430 - if (d->state != BT_OPEN && d->state != BT_CLOSED) {
431 - rfcomm_unlock();
432 - return 0;
433 - }
434 -
435 - s = rfcomm_session_get(src, dst);
436 - if (s) {
437 - err = __rfcomm_dlc_open(d, s, channel);
438 - rfcomm_unlock();
439 - return err;
440 - }
441 - rfcomm_unlock();
442 -
443 - /* There is no session for this pair yet. kernel_connect() ends up in
444 - * l2cap_chan_connect(), which takes hdev->lock, and the HCI event
445 - * path takes rfcomm_mutex while holding hdev->lock, so the socket has
446 - * to be connected with rfcomm_mutex released.
447 - */
448 - sock = rfcomm_session_connect(src, dst, d->sec_level, &err);
449 - if (!sock)
450 - return err;
424 + int r;
451 425
452 426 rfcomm_lock();
453 427
454 - /* The DLC may have been closed while the socket was connecting. It
455 - * was not on a session, so rfcomm_dlc_close() could only mark it;
456 - * attaching it now would leave it with no owner.
457 - */
458 - if (test_bit(RFCOMM_CLOSED, &d->flags)) {
459 - rfcomm_unlock();
460 - sock_release(sock);
461 - return -ECONNRESET;
462 - }
463 -
464 - /* Another opener may have added a session for the same pair in the
465 - * meantime; that one is used and this socket is dropped.
466 - */
467 - s = rfcomm_session_get(src, dst);
468 - if (!s) {
469 - s = rfcomm_session_add(sock, BT_BOUND);
470 - if (s) {
471 - s->initiator = 1;
472 - sock = NULL;
473 - }
474 - }
475 -
476 - err = s ? __rfcomm_dlc_open(d, s, channel) : -ENOMEM;
428 + r = __rfcomm_dlc_open(d, src, dst, channel);
477 429
478 430 rfcomm_unlock();
479 -
480 - if (sock)
481 - sock_release(sock);
482 -
483 - /* Over an existing ACL link the connection can complete before the
484 - * session reaches the list, and that wakeup is then lost, so let
485 - * krfcommd look at the socket state now.
486 - */
487 - rfcomm_schedule();
488 -
489 - return err;
431 + return r;
490 432 }
491 433
492 434 static void __rfcomm_dlc_disconn(struct rfcomm_dlc *d)
@@ -566,14 +508,8 @@ int rfcomm_dlc_close(struct rfcomm_dlc *d, int err)
566 508 rfcomm_lock();
567 509
568 510 s = d->session;
569 - if (!s) {
570 - /* Not on a session yet: rfcomm_dlc_open() may be connecting a
571 - * socket for it with rfcomm_mutex released. Leave a mark so
572 - * that it does not attach the DLC once it holds the lock again.
573 - */
574 - set_bit(RFCOMM_CLOSED, &d->flags);
511 + if (!s)
575 512 goto no_session;
576 - }
577 513
578 514 /* after waiting on the mutex check the session still exists
579 515 * then check the dlc still exists
@@ -821,12 +757,12 @@ static struct rfcomm_session *rfcomm_session_close(struct rfcomm_session *s,
821 757 return rfcomm_session_del(s);
822 758 }
823 759
824 - /* Creates the L2CAP socket a new session will run on and starts connecting
825 - * it. Must be called with rfcomm_mutex released.
826 - */
827 - static struct socket *rfcomm_session_connect(bdaddr_t *src, bdaddr_t *dst,
828 - u8 sec_level, int *err)
760 + static struct rfcomm_session *rfcomm_session_create(bdaddr_t *src,
761 + bdaddr_t *dst,
762 + u8 sec_level,
763 + int *err)
829 764 {
765 + struct rfcomm_session *s = NULL;
830 766 struct sockaddr_l2 addr;
831 767 struct socket *sock;
832 768 struct sock *sk;
@@ -856,16 +792,24 @@ static struct socket *rfcomm_session_connect(bdaddr_t *src, bdaddr_t *dst,
856 792 l2cap_pi(sk)->chan->mode = L2CAP_MODE_ERTM;
857 793 release_sock(sk);
858 794
795 + s = rfcomm_session_add(sock, BT_BOUND);
796 + if (!s) {
797 + *err = -ENOMEM;
798 + goto failed;
799 + }
800 +
801 + s->initiator = 1;
802 +
859 803 bacpy(&addr.l2_bdaddr, dst);
860 804 addr.l2_family = AF_BLUETOOTH;
861 805 addr.l2_psm = cpu_to_le16(L2CAP_PSM_RFCOMM);
862 806 addr.l2_cid = 0;
863 807 addr.l2_bdaddr_type = BDADDR_BREDR;
864 808 *err = kernel_connect(sock, (struct sockaddr_unsized *)&addr, sizeof(addr), O_NONBLOCK);
865 - if (*err && *err != -EINPROGRESS)
866 - goto failed;
809 + if (*err == 0 || *err == -EINPROGRESS)
810 + return s;
867 811
868 - return sock;
812 + return rfcomm_session_del(s);
869 813
870 814 failed:
871 815 sock_release(sock);
modified net/bluetooth/rfcomm/sock.c
@@ -48,11 +48,8 @@ static void rfcomm_sock_kill(struct sock *sk);
48 48 static void rfcomm_sk_data_ready(struct rfcomm_dlc *d, struct sk_buff *skb)
49 49 {
50 50 struct sock *sk = d->owner;
51 -
52 - if (!sk) {
53 - kfree_skb(skb);
51 + if (!sk)
54 52 return;
55 - }
56 53
57 54 atomic_add(skb->len, &sk->sk_rmem_alloc);
58 55 skb_queue_tail(&sk->sk_receive_queue, skb);
modified net/bluetooth/rfcomm/tty.c
@@ -128,7 +128,7 @@ static void rfcomm_dev_shutdown(struct tty_port *port)
128 128 {
129 129 struct rfcomm_dev *dev = container_of(port, struct rfcomm_dev, port);
130 130
131 - if (dev->tty_dev && dev->tty_dev->parent)
131 + if (dev->tty_dev->parent)
132 132 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
133 133
134 134 /* close the dlc */
modified net/bluetooth/sco.c
@@ -84,14 +84,12 @@ static void sco_conn_free(struct kref *ref)
84 84 if (conn->sk)
85 85 sco_pi(conn->sk)->conn = NULL;
86 86
87 - /* hcon->sco_data is cleared and the association's reference on the
88 - * sco_conn is dropped in sco_conn_del() under hdev->lock, and the
89 - * hci_conn is now owned by the socket (held in __sco_chan_add() and
90 - * dropped in sco_chan_del()/sco_sock_destruct()), so there is nothing
91 - * left to release towards hcon here.
92 - */
87 + if (conn->hcon) {
88 + conn->hcon->sco_data = NULL;
89 + hci_conn_drop(conn->hcon);
90 + }
93 91
94 - /* Ensure no more work items will run before the connection is freed */
92 + /* Ensure no more work items will run since hci_conn has been dropped */
95 93 disable_delayed_work_sync(&conn->timeout_work);
96 94
97 95 kfree(conn);
@@ -190,19 +188,25 @@ static void sco_sock_clear_timer(struct sock *sk)
190 188 }
191 189
192 190 /* ---- SCO connections ---- */
193 - /* Returns a new reference the caller must drop with sco_conn_put(). The
194 - * hcon->sco_data association holds its own reference on the sco_conn for the
195 - * connection's lifetime; it is dropped in sco_conn_del() under hdev->lock.
196 - * @hcon is not consumed: the hci_conn reference is taken and owned by the
197 - * socket in __sco_chan_add().
191 + /* Consumes a reference on @hcon, which the returned sco_conn owns until it is
192 + * freed. On failure (NULL return) the reference is left for the caller to drop.
198 193 */
199 194 static struct sco_conn *sco_conn_add(struct hci_conn *hcon)
200 195 {
201 196 struct sco_conn *conn = hcon->sco_data;
202 197
203 198 conn = sco_conn_hold_unless_zero(conn);
204 - if (conn)
199 + if (conn) {
200 + if (!conn->hcon) {
201 + sco_conn_lock(conn);
202 + conn->hcon = hcon;
203 + sco_conn_unlock(conn);
204 + } else {
205 + /* conn already owns a reference on hcon */
206 + hci_conn_drop(hcon);
207 + }
205 208 return conn;
209 + }
206 210
207 211 conn = kzalloc_obj(struct sco_conn);
208 212 if (!conn)
@@ -223,10 +227,7 @@ static struct sco_conn *sco_conn_add(struct hci_conn *hcon)
223 227
224 228 BT_DBG("hcon %p conn %p", hcon, conn);
225 229
226 - /* kref_init() above set the association reference owned by
227 - * hcon->sco_data; hand the caller its own reference.
228 - */
229 - return sco_conn_hold(conn);
230 + return conn;
230 231 }
231 232
232 233 /* Delete channel.
@@ -241,19 +242,6 @@ static void sco_chan_del(struct sock *sk, int err)
241 242 BT_DBG("sk %p, conn %p, err %d", sk, conn, err);
242 243
243 244 if (conn) {
244 - struct hci_conn *hcon;
245 -
246 - sco_conn_lock(conn);
247 - hcon = conn->hcon;
248 - sco_conn_unlock(conn);
249 -
250 - /* Drop the socket's hci_conn reference BEFORE clearing
251 - * conn->sk, so sco_conn_del() on another CPU cannot free
252 - * the hci_conn while we still hold a pointer to it.
253 - */
254 - if (hcon)
255 - hci_conn_drop(hcon);
256 -
257 245 sco_conn_lock(conn);
258 246 conn->sk = NULL;
259 247 sco_conn_unlock(conn);
@@ -278,13 +266,6 @@ static void sco_conn_del(struct hci_conn *hcon, int err)
278 266
279 267 BT_DBG("hcon %p conn %p, err %d", hcon, conn, err);
280 268
281 - /* Detach from the hci_conn and drop the association's reference.
282 - * The caller holds hdev->lock, which serialises this against the
283 - * read of hcon->sco_data in sco_recv_scodata().
284 - */
285 - hcon->sco_data = NULL;
286 - sco_conn_put(conn);
287 -
288 269 sco_conn_lock(conn);
289 270 sk = sco_sock_hold(conn);
290 271 sco_conn_unlock(conn);
@@ -309,11 +290,6 @@ static void __sco_chan_add(struct sco_conn *conn, struct sock *sk,
309 290 sco_pi(sk)->conn = sco_conn_hold(conn);
310 291 conn->sk = sk;
311 292
312 - /* The socket owns an hci_conn reference for as long as it stays
313 - * attached; it is dropped in sco_chan_del()/sco_sock_destruct().
314 - */
315 - hci_conn_hold(conn->hcon);
316 -
317 293 if (parent)
318 294 bt_accept_enqueue(parent, sk, true);
319 295 }
@@ -395,7 +371,6 @@ static int sco_connect(struct sock *sk)
395 371 if (sk->sk_state != BT_OPEN && sk->sk_state != BT_BOUND) {
396 372 release_sock(sk);
397 373 sco_conn_put(conn);
398 - hci_conn_drop(hcon);
399 374 err = -EBADFD;
400 375 goto unlock;
401 376 }
@@ -404,13 +379,9 @@ static int sco_connect(struct sock *sk)
404 379 sco_conn_put(conn);
405 380 if (err) {
406 381 release_sock(sk);
407 - hci_conn_drop(hcon);
408 382 goto unlock;
409 383 }
410 384
411 - /* __sco_chan_add() took its own hci_conn reference; drop ours. */
412 - hci_conn_drop(hcon);
413 -
414 385 /* Update source addr of the socket */
415 386 bacpy(&sco_pi(sk)->src, &hcon->src);
416 387
@@ -524,25 +495,9 @@ static struct sock *sco_get_sock_listen(bdaddr_t *src)
524 495
525 496 static void sco_sock_destruct(struct sock *sk)
526 497 {
527 - struct sco_conn *conn = sco_pi(sk)->conn;
528 -
529 498 BT_DBG("sk %p", sk);
530 499
531 - /* If the channel was not already torn down via sco_chan_del(), drop
532 - * the socket's own references here.
533 - */
534 - if (conn) {
535 - struct hci_conn *hcon;
536 -
537 - sco_conn_lock(conn);
538 - hcon = conn->hcon;
539 - sco_conn_unlock(conn);
540 -
541 - if (hcon)
542 - hci_conn_drop(hcon);
543 - sco_pi(sk)->conn = NULL;
544 - sco_conn_put(conn);
545 - }
500 + sco_conn_put(sco_pi(sk)->conn);
546 501
547 502 skb_queue_purge(&sk->sk_receive_queue);
548 503 skb_queue_purge(&sk->sk_write_queue);
@@ -1556,10 +1511,12 @@ static void sco_connect_cfm(struct hci_conn *hcon, __u8 status)
1556 1511 if (!status) {
1557 1512 struct sco_conn *conn;
1558 1513
1559 - conn = sco_conn_add(hcon);
1514 + conn = sco_conn_add(hci_conn_hold(hcon));
1560 1515 if (conn) {
1561 1516 sco_conn_ready(conn);
1562 1517 sco_conn_put(conn);
1518 + } else {
1519 + hci_conn_drop(hcon);
1563 1520 }
1564 1521 } else
1565 1522 sco_conn_del(hcon, bt_to_errno(status));
modified net/bridge/br_multicast.c
@@ -81,10 +81,6 @@ __br_multicast_add_group(struct net_bridge_mcast *brmctx,
81 81 bool blocked);
82 82 static void br_multicast_find_del_pg(struct net_bridge *br,
83 83 struct net_bridge_port_group *pg);
84 - static void __br_multicast_del_pg(struct net_bridge_mdb_entry *mp,
85 - struct net_bridge_port_group *pg,
86 - struct net_bridge_port_group __rcu **pp,
87 - bool sg_del_exclude_ports);
88 84 static void __br_multicast_stop(struct net_bridge_mcast *brmctx);
89 85
90 86 static int br_mc_disabled_update(struct net_device *dev, bool value,
@@ -462,7 +458,7 @@ static void br_multicast_sg_del_exclude_ports(struct net_bridge_mdb_entry *sgmp)
462 458 for (pp = &sgmp->ports;
463 459 (p = mlock_dereference(*pp, sgmp->br)) != NULL;) {
464 460 if (!(p->flags & MDB_PG_FLAGS_PERMANENT))
465 - __br_multicast_del_pg(sgmp, p, pp, false);
461 + br_multicast_del_pg(sgmp, p, pp);
466 462 else
467 463 pp = &p->next;
468 464 }
@@ -803,10 +799,9 @@ static void br_multicast_destroy_port_group(struct net_bridge_mcast_gc *gc)
803 799 kfree_rcu(pg, rcu);
804 800 }
805 801
806 - static void __br_multicast_del_pg(struct net_bridge_mdb_entry *mp,
807 - struct net_bridge_port_group *pg,
808 - struct net_bridge_port_group __rcu **pp,
809 - bool sg_del_exclude_ports)
802 + void br_multicast_del_pg(struct net_bridge_mdb_entry *mp,
803 + struct net_bridge_port_group *pg,
804 + struct net_bridge_port_group __rcu **pp)
810 805 {
811 806 struct net_bridge *br = pg->key.port->br;
812 807 struct net_bridge_group_src *ent;
@@ -825,8 +820,7 @@ static void __br_multicast_del_pg(struct net_bridge_mdb_entry *mp,
825 820 if (!br_multicast_is_star_g(&mp->addr)) {
826 821 rhashtable_remove_fast(&br->sg_port_tbl, &pg->rhnode,
827 822 br_sg_port_rht_params);
828 - if (sg_del_exclude_ports)
829 - br_multicast_sg_del_exclude_ports(mp);
823 + br_multicast_sg_del_exclude_ports(mp);
830 824 } else {
831 825 br_multicast_star_g_handle_mode(pg, MCAST_INCLUDE);
832 826 }
@@ -838,13 +832,6 @@ static void __br_multicast_del_pg(struct net_bridge_mdb_entry *mp,
838 832 mod_timer(&mp->timer, jiffies);
839 833 }
840 834
841 - void br_multicast_del_pg(struct net_bridge_mdb_entry *mp,
842 - struct net_bridge_port_group *pg,
843 - struct net_bridge_port_group __rcu **pp)
844 - {
845 - __br_multicast_del_pg(mp, pg, pp, true);
846 - }
847 -
848 835 static void br_multicast_find_del_pg(struct net_bridge *br,
849 836 struct net_bridge_port_group *pg)
850 837 {
modified net/bridge/netfilter/nf_conntrack_bridge.c
@@ -39,13 +39,9 @@ static int nf_br_ip_fragment(struct net *net, struct sock *sk,
39 39 int err = 0;
40 40
41 41 /* for offloaded checksums cleanup checksum before fragmentation */
42 - if (skb->ip_summed == CHECKSUM_PARTIAL) {
43 - err = ip_check_csum_start(skb);
44 - if (!err)
45 - err = skb_checksum_help(skb);
46 - if (err)
47 - goto blackhole;
48 - }
42 + if (skb->ip_summed == CHECKSUM_PARTIAL &&
43 + (err = skb_checksum_help(skb)))
44 + goto blackhole;
49 45
50 46 iph = ip_hdr(skb);
51 47
modified net/can/af_can.c
@@ -641,10 +641,13 @@ static int can_rcv_filter(struct can_dev_rcv_lists *dev_rcv_lists, struct sk_buf
641 641 return matches;
642 642 }
643 643
644 - void can_set_skb_uid(struct can_skb_ext *csx)
644 + void can_set_skb_uid(struct sk_buff *skb)
645 645 {
646 - while (!(csx->can_skb_uid))
647 - csx->can_skb_uid = atomic_inc_return(&skbcounter);
646 + /* create non-zero unique skb identifier together with *skb */
647 + while (!(skb->hash))
648 + skb->hash = atomic_inc_return(&skbcounter);
649 +
650 + skb->sw_hash = 1;
648 651 }
649 652 EXPORT_SYMBOL(can_set_skb_uid);
650 653
@@ -659,6 +662,8 @@ static void can_receive(struct sk_buff *skb, struct net_device *dev)
659 662 atomic_long_inc(&pkg_stats->rx_frames);
660 663 atomic_long_inc(&pkg_stats->rx_frames_delta);
661 664
665 + can_set_skb_uid(skb);
666 +
662 667 rcu_read_lock();
663 668
664 669 /* deliver the packet to sockets listening on all devices */
@@ -682,10 +687,8 @@ static void can_receive(struct sk_buff *skb, struct net_device *dev)
682 687 static int can_rcv(struct sk_buff *skb, struct net_device *dev,
683 688 struct packet_type *pt, struct net_device *orig_dev)
684 689 {
685 - struct can_skb_ext *csx = can_skb_ext_find(skb);
686 -
687 690 if (unlikely(dev->type != ARPHRD_CAN || !can_get_ml_priv(dev) ||
688 - !csx || !can_is_can_skb(skb))) {
691 + !can_skb_ext_find(skb) || !can_is_can_skb(skb))) {
689 692 pr_warn_once("PF_CAN: dropped non conform CAN skbuff: dev type %d, len %d\n",
690 693 dev->type, skb->len);
691 694
@@ -693,14 +696,6 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev,
693 696 return NET_RX_DROP;
694 697 }
695 698
696 - /* create unshared CAN skb_extension for netem/mirred skb clones */
697 - csx = skb_ext_add(skb, SKB_EXT_CAN);
698 - if (unlikely(!csx)) {
699 - kfree_skb_reason(skb, SKB_DROP_REASON_NOMEM);
700 - return NET_RX_DROP;
701 - }
702 -
703 - can_set_skb_uid(csx);
704 699 can_receive(skb, dev);
705 700 return NET_RX_SUCCESS;
706 701 }
@@ -708,10 +703,8 @@ static int can_rcv(struct sk_buff *skb, struct net_device *dev,
708 703 static int canfd_rcv(struct sk_buff *skb, struct net_device *dev,
709 704 struct packet_type *pt, struct net_device *orig_dev)
710 705 {
711 - struct can_skb_ext *csx = can_skb_ext_find(skb);
712 -
713 706 if (unlikely(dev->type != ARPHRD_CAN || !can_get_ml_priv(dev) ||
714 - !csx || !can_is_canfd_skb(skb))) {
707 + !can_skb_ext_find(skb) || !can_is_canfd_skb(skb))) {
715 708 pr_warn_once("PF_CAN: dropped non conform CAN FD skbuff: dev type %d, len %d\n",
716 709 dev->type, skb->len);
717 710
@@ -719,14 +712,6 @@ static int canfd_rcv(struct sk_buff *skb, struct net_device *dev,
719 712 return NET_RX_DROP;
720 713 }
721 714
722 - /* create unshared CAN skb_extension for netem/mirred skb clones */
723 - csx = skb_ext_add(skb, SKB_EXT_CAN);
724 - if (unlikely(!csx)) {
725 - kfree_skb_reason(skb, SKB_DROP_REASON_NOMEM);
726 - return NET_RX_DROP;
727 - }
728 -
729 - can_set_skb_uid(csx);
730 715 can_receive(skb, dev);
731 716 return NET_RX_SUCCESS;
732 717 }
@@ -734,10 +719,8 @@ static int canfd_rcv(struct sk_buff *skb, struct net_device *dev,
734 719 static int canxl_rcv(struct sk_buff *skb, struct net_device *dev,
735 720 struct packet_type *pt, struct net_device *orig_dev)
736 721 {
737 - struct can_skb_ext *csx = can_skb_ext_find(skb);
738 -
739 722 if (unlikely(dev->type != ARPHRD_CAN || !can_get_ml_priv(dev) ||
740 - !csx || !can_is_canxl_skb(skb))) {
723 + !can_skb_ext_find(skb) || !can_is_canxl_skb(skb))) {
741 724 pr_warn_once("PF_CAN: dropped non conform CAN XL skbuff: dev type %d, len %d\n",
742 725 dev->type, skb->len);
743 726
@@ -745,14 +728,6 @@ static int canxl_rcv(struct sk_buff *skb, struct net_device *dev,
745 728 return NET_RX_DROP;
746 729 }
747 730
748 - /* create unshared CAN skb_extension for netem/mirred skb clones */
749 - csx = skb_ext_add(skb, SKB_EXT_CAN);
750 - if (unlikely(!csx)) {
751 - kfree_skb_reason(skb, SKB_DROP_REASON_NOMEM);
752 - return NET_RX_DROP;
753 - }
754 -
755 - can_set_skb_uid(csx);
756 731 can_receive(skb, dev);
757 732 return NET_RX_SUCCESS;
758 733 }
modified net/can/gw.c
@@ -527,9 +527,6 @@ static void can_can_gw_rcv(struct sk_buff *skb, void *data)
527 527 /* put the incremented hop counter in the cloned skb */
528 528 ncsx->can_gw_hops = csx->can_gw_hops + 1;
529 529
530 - /* force a new CAN UID generation for the routed frame */
531 - ncsx->can_skb_uid = 0;
532 -
533 530 /* first processing of this CAN frame -> adjust to private hop limit */
534 531 if (gwj->limit_hops && ncsx->can_gw_hops == 1)
535 532 ncsx->can_gw_hops = max_hops - gwj->limit_hops + 1;
modified net/can/isotp.c
@@ -891,7 +891,7 @@ static void isotp_send_cframe(struct isotp_sock *so)
891 891 csx->can_iif = dev->ifindex;
892 892
893 893 /* set uid in tx skb to identify CF echo frames */
894 - can_set_skb_uid(csx);
894 + can_set_skb_uid(skb);
895 895
896 896 cf = (struct canfd_frame *)skb->data;
897 897 skb_put_zero(skb, so->ll.mtu);
@@ -917,7 +917,7 @@ static void isotp_send_cframe(struct isotp_sock *so)
917 917 pr_notice_once("can-isotp: cfecho is %08X != 0\n", old_cfecho);
918 918
919 919 /* set consecutive frame echo tag */
920 - WRITE_ONCE(so->cfecho, csx->can_skb_uid);
920 + WRITE_ONCE(so->cfecho, skb->hash);
921 921
922 922 /* send frame with local echo enabled */
923 923 can_send_ret = can_send(skb, 1);
@@ -969,22 +969,18 @@ static void isotp_rcv_echo(struct sk_buff *skb, void *data)
969 969 {
970 970 struct sock *sk = (struct sock *)data;
971 971 struct isotp_sock *so = isotp_sk(sk);
972 - struct can_skb_ext *csx = can_skb_ext_find(skb);
973 972
974 973 /* only handle my own local echo CF/SF skb's (no FF!) */
975 974 if (skb->sk != sk)
976 975 return;
977 976
978 - if (WARN_ON_ONCE(!csx))
979 - return;
980 -
981 977 /* unlike isotp_rcv_fc()/isotp_rcv_cf(), not already under so->rx_lock
982 978 * (no isotp_rcv() caller here), so take it ourselves
983 979 */
984 980 spin_lock(&so->rx_lock);
985 981
986 982 /* so->cfecho may since belong to a new transfer; recheck under lock */
987 - if (READ_ONCE(so->cfecho) != csx->can_skb_uid)
983 + if (READ_ONCE(so->cfecho) != skb->hash)
988 984 goto out_unlock;
989 985
990 986 /* cancel local echo timeout */
@@ -1226,7 +1222,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
1226 1222 csx->can_iif = dev->ifindex;
1227 1223
1228 1224 /* set uid in tx skb to identify CF echo frames */
1229 - can_set_skb_uid(csx);
1225 + can_set_skb_uid(skb);
1230 1226
1231 1227 so->tx.len = size;
1232 1228 so->tx.idx = 0;
@@ -1265,7 +1261,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
1265 1261 cf->data[ae] |= size;
1266 1262
1267 1263 /* set CF echo tag for isotp_rcv_echo() (SF-mode) */
1268 - WRITE_ONCE(so->cfecho, csx->can_skb_uid);
1264 + WRITE_ONCE(so->cfecho, skb->hash);
1269 1265 } else {
1270 1266 /* send first frame */
1271 1267
@@ -1282,7 +1278,7 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
1282 1278 so->txfc.bs = 0;
1283 1279
1284 1280 /* set CF echo tag for isotp_rcv_echo() (CF-mode) */
1285 - WRITE_ONCE(so->cfecho, csx->can_skb_uid);
1281 + WRITE_ONCE(so->cfecho, skb->hash);
1286 1282 } else {
1287 1283 /* standard flow control check */
1288 1284 new_state = ISOTP_WAIT_FIRST_FC;
modified net/can/raw.c
@@ -77,7 +77,7 @@ MODULE_ALIAS("can-proto-1");
77 77
78 78 struct uniqframe {
79 79 const struct sk_buff *skb;
80 - u32 can_skb_uid;
80 + u32 hash;
81 81 unsigned int join_rx_count;
82 82 };
83 83
@@ -133,16 +133,12 @@ static void raw_rcv(struct sk_buff *oskb, void *data)
133 133 enum skb_drop_reason reason;
134 134 struct sockaddr_can *addr;
135 135 struct sk_buff *skb;
136 - struct can_skb_ext *csx = can_skb_ext_find(oskb);
137 136 unsigned int *pflags;
138 137
139 138 /* check the received tx sock reference */
140 139 if (!ro->recv_own_msgs && oskb->sk == sk)
141 140 return;
142 141
143 - if (WARN_ON_ONCE(!csx))
144 - return;
145 -
146 142 /* make sure to not pass oversized frames to the socket */
147 143 if (!ro->fd_frames && can_is_canfd_skb(oskb))
148 144 return;
@@ -169,7 +165,7 @@ static void raw_rcv(struct sk_buff *oskb, void *data)
169 165
170 166 /* eliminate multiple filter matches for the same skb */
171 167 if (this_cpu_ptr(ro->uniq)->skb == oskb &&
172 - this_cpu_ptr(ro->uniq)->can_skb_uid == csx->can_skb_uid) {
168 + this_cpu_ptr(ro->uniq)->hash == oskb->hash) {
173 169 if (!ro->join_filters)
174 170 return;
175 171
@@ -179,7 +175,7 @@ static void raw_rcv(struct sk_buff *oskb, void *data)
179 175 return;
180 176 } else {
181 177 this_cpu_ptr(ro->uniq)->skb = oskb;
182 - this_cpu_ptr(ro->uniq)->can_skb_uid = csx->can_skb_uid;
178 + this_cpu_ptr(ro->uniq)->hash = oskb->hash;
183 179 this_cpu_ptr(ro->uniq)->join_rx_count = 1;
184 180 /* drop first frame to check all enabled filters? */
185 181 if (ro->join_filters && ro->count > 1)
modified net/core/dev.c
@@ -10364,15 +10364,13 @@ EXPORT_SYMBOL_GPL(dev_xdp_prog_count);
10364 10364
10365 10365 u8 dev_xdp_sb_prog_count(struct net_device *dev)
10366 10366 {
10367 - struct bpf_prog *prog;
10368 10367 u8 count = 0;
10369 10368 int i;
10370 10369
10371 - for (i = 0; i < __MAX_XDP_MODE; i++) {
10372 - prog = dev_xdp_prog(dev, i);
10373 - if (prog && !prog->aux->xdp_has_frags)
10370 + for (i = 0; i < __MAX_XDP_MODE; i++)
10371 + if (dev->xdp_state[i].prog &&
10372 + !dev->xdp_state[i].prog->aux->xdp_has_frags)
10374 10373 count++;
10375 - }
10376 10374 return count;
10377 10375 }
10378 10376
@@ -10752,12 +10750,11 @@ static int bpf_xdp_link_update(struct bpf_link *link, struct bpf_prog *new_prog,
10752 10750 bpf_op = dev_xdp_bpf_op(xdp_link->dev, mode);
10753 10751 err = dev_xdp_install(xdp_link->dev, mode, bpf_op, NULL,
10754 10752 xdp_link->flags, new_prog);
10755 - if (!err)
10756 - old_prog = xchg(&link->prog, new_prog);
10757 10753 netdev_unlock_ops(xdp_link->dev);
10758 10754 if (err)
10759 10755 goto out_unlock;
10760 10756
10757 + old_prog = xchg(&link->prog, new_prog);
10761 10758 bpf_prog_put(old_prog);
10762 10759
10763 10760 out_unlock:
modified net/core/flow_dissector.c
@@ -1023,8 +1023,6 @@ u32 bpf_flow_dissect(struct bpf_prog *prog, struct bpf_flow_dissector *ctx,
1023 1023
1024 1024 result = bpf_prog_run_pin_on_cpu(prog, ctx);
1025 1025
1026 - /* bpf_flow_keys offsets are u16: do not let @hlen be truncated. */
1027 - hlen = min_t(int, hlen, U16_MAX);
1028 1026 flow_keys->nhoff = clamp_t(u16, flow_keys->nhoff, nhoff, hlen);
1029 1027 flow_keys->thoff = clamp_t(u16, flow_keys->thoff,
1030 1028 flow_keys->nhoff, hlen);
@@ -1073,7 +1071,6 @@ bool __skb_flow_dissect(const struct net *net,
1073 1071 int mpls_lse = 0;
1074 1072 int num_hdrs = 0;
1075 1073 u8 ip_proto = 0;
1076 - u32 thoff;
1077 1074 bool ret;
1078 1075
1079 1076 if (!data) {
@@ -1695,13 +1692,7 @@ out_good:
1695 1692 ret = true;
1696 1693
1697 1694 out:
1698 - thoff = min_t(u32, nhoff, skb ? skb->len : hlen);
1699 - if (unlikely(thoff > U16_MAX)) {
1700 - /* Cannot be represented in key_control->thoff. */
1701 - thoff = U16_MAX;
1702 - ret = false;
1703 - }
1704 - key_control->thoff = thoff;
1695 + key_control->thoff = min_t(u16, nhoff, skb ? skb->len : hlen);
1705 1696 key_basic->n_proto = proto;
1706 1697 key_basic->ip_proto = ip_proto;
1707 1698
modified net/core/skbuff.c
@@ -3633,12 +3633,8 @@ __wsum skb_copy_and_csum_bits(const struct sk_buff *skb, int offset,
3633 3633 pos = copy;
3634 3634 }
3635 3635
3636 - if (!skb_frags_readable(skb)) {
3637 - /* Don't hand the caller a buffer with stale bytes in it. */
3638 - if (len > 0)
3639 - memset(to, 0, len);
3636 + if (!skb_frags_readable(skb))
3640 3637 return 0;
3641 - }
3642 3638
3643 3639 for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
3644 3640 int end;
modified net/devlink/core.c
@@ -112,19 +112,13 @@ rel_put:
112 112 return;
113 113
114 114 reschedule_work:
115 - /* The work may have been queued again meanwhile, which took its own
116 - * reference. Drop ours in that case.
117 - */
118 - if (!schedule_delayed_work(&rel->nested_in.notify_work, 1))
119 - __devlink_rel_put(rel);
115 + schedule_delayed_work(&rel->nested_in.notify_work, 1);
120 116 }
121 117
122 118 static void devlink_rel_nested_in_notify_work_schedule(struct devlink_rel *rel)
123 119 {
124 120 __devlink_rel_get(rel);
125 - /* The pending work holds a reference already, drop the new one. */
126 - if (!schedule_delayed_work(&rel->nested_in.notify_work, 0))
127 - __devlink_rel_put(rel);
121 + schedule_delayed_work(&rel->nested_in.notify_work, 0);
128 122 }
129 123
130 124 static struct devlink_rel *devlink_rel_alloc(void)
modified net/ipv4/af_inet.c
@@ -161,7 +161,7 @@ void inet_sock_destruct(struct sock *sk)
161 161 WARN_ON_ONCE(sk->sk_wmem_queued);
162 162 WARN_ON_ONCE(sk->sk_forward_alloc);
163 163
164 - kfree_rcu(rcu_dereference_protected(inet->inet_opt, 1), rcu);
164 + kfree(rcu_dereference_protected(inet->inet_opt, 1));
165 165 dst_release(rcu_dereference_protected(sk->sk_dst_cache, 1));
166 166 dst_release(rcu_dereference_protected(sk->sk_rx_dst, 1));
167 167 psp_sk_assoc_free(sk);
modified net/ipv4/cipso_ipv4.c
@@ -2287,14 +2287,6 @@ int cipso_v4_skbuff_delattr(struct sk_buff *skb)
2287 2287 new_hdr_len - new_hdr_len_actual);
2288 2288
2289 2289 opt->optlen -= hdr_len_delta;
2290 - if (opt->srr > opt->cipso)
2291 - opt->srr -= cipso_len;
2292 - if (opt->rr > opt->cipso)
2293 - opt->rr -= cipso_len;
2294 - if (opt->ts > opt->cipso)
2295 - opt->ts -= cipso_len;
2296 - if (opt->router_alert > opt->cipso)
2297 - opt->router_alert -= cipso_len;
2298 2290 opt->cipso = 0;
2299 2291 opt->is_changed = 1;
2300 2292 if (hdr_len_delta != 0) {
modified net/ipv4/fib_semantics.c
@@ -542,9 +542,6 @@ size_t fib_nlmsg_size(struct fib_info *fi)
542 542 struct fib_nh_common *nhc = fib_info_nhc(fi, i);
543 543 size_t nhsize;
544 544
545 - if (!nhc)
546 - break;
547 -
548 545 nhsize = fib_nexthop_nlmsg_size(nhc, nhs != 1);
549 546
550 547 if (nhs != 1)
modified net/ipv4/fib_trie.c
@@ -1079,6 +1079,8 @@ void fib_alias_hw_flags_set(struct net *net, const struct fib_rt_info *fri)
1079 1079
1080 1080 err = fib_dump_info(skb, 0, 0, RTM_NEWROUTE, fri, 0);
1081 1081 if (err < 0) {
1082 + /* -EMSGSIZE implies BUG in fib_nlmsg_size() */
1083 + WARN_ON(err == -EMSGSIZE);
1082 1084 kfree_skb(skb);
1083 1085 goto errout;
1084 1086 }
modified net/ipv4/ip_output.c
@@ -771,13 +771,9 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
771 771 int err = 0;
772 772
773 773 /* for offloaded checksums cleanup checksum before fragmentation */
774 - if (skb->ip_summed == CHECKSUM_PARTIAL) {
775 - err = ip_check_csum_start(skb);
776 - if (!err)
777 - err = skb_checksum_help(skb);
778 - if (err)
779 - goto fail;
780 - }
774 + if (skb->ip_summed == CHECKSUM_PARTIAL &&
775 + (err = skb_checksum_help(skb)))
776 + goto fail;
781 777
782 778 /*
783 779 * Point into the IP datagram header.
modified net/ipv4/route.c
@@ -1082,8 +1082,6 @@ static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu)
1082 1082
1083 1083 for (nhsel = 0; nhsel < fib_info_num_path(res.fi); nhsel++) {
1084 1084 nhc = fib_info_nhc(res.fi, nhsel);
1085 - if (!nhc)
1086 - break;
1087 1085 update_or_create_fnhe(nhc, fl4->daddr, 0, mtu, lock,
1088 1086 jiffies + net->ipv4.ip_rt_mtu_expires);
1089 1087 }
@@ -3170,9 +3168,6 @@ int fib_dump_info_fnhe(struct sk_buff *skb, struct netlink_callback *cb,
3170 3168 struct fnhe_hash_bucket *bucket;
3171 3169 int err;
3172 3170
3173 - if (!nhc)
3174 - break;
3175 -
3176 3171 if (nhc->nhc_flags & RTNH_F_DEAD)
3177 3172 continue;
3178 3173
modified net/ipv4/tcp.c
@@ -1908,8 +1908,6 @@ static bool can_map_frag(const skb_frag_t *frag)
1908 1908
1909 1909 if (skb_frag_size(frag) != PAGE_SIZE || skb_frag_off(frag))
1910 1910 return false;
1911 - if (skb_frag_is_net_iov(frag))
1912 - return false;
1913 1911
1914 1912 page = skb_frag_page(frag);
1915 1913
modified net/ipv4/tcp_ipv4.c
@@ -1209,7 +1209,7 @@ static int tcp_v4_send_synack(const struct sock *sk, struct dst_entry *dst,
1209 1209 */
1210 1210 static void tcp_v4_reqsk_destructor(struct request_sock *req)
1211 1211 {
1212 - kfree_rcu(rcu_dereference_protected(inet_rsk(req)->ireq_opt, 1), rcu);
1212 + kfree(rcu_dereference_protected(inet_rsk(req)->ireq_opt, 1));
1213 1213 }
1214 1214
1215 1215 #ifdef CONFIG_TCP_MD5SIG
modified net/ipv6/ip6_gre.c
@@ -923,6 +923,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
923 923 {
924 924 struct ip_tunnel_info *tun_info = NULL;
925 925 struct ip6_tnl *t = netdev_priv(dev);
926 + struct dst_entry *dst = skb_dst(skb);
926 927 IP_TUNNEL_DECLARE_FLAGS(flags) = { };
927 928 bool truncate = false;
928 929 int encap_limit = -1;
@@ -1057,6 +1058,12 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
1057 1058 gre_build_header(skb, 8, flags, proto, 0,
1058 1059 htonl(atomic_fetch_inc(&t->o_seqno)));
1059 1060
1061 + /* TooBig packet may have updated dst->dev's mtu */
1062 + if (!t->parms.collect_md && dst) {
1063 + mtu = READ_ONCE(dst_dev(dst)->mtu);
1064 + if (dst_mtu(dst) > mtu)
1065 + dst->ops->update_pmtu(dst, NULL, skb, mtu, false);
1066 + }
1060 1067 err = ip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
1061 1068 NEXTHDR_GRE);
1062 1069 if (err != 0) {
modified net/ipv6/route.c
@@ -6509,6 +6509,8 @@ void fib6_info_hw_flags_set(struct net *net, struct fib6_info *f6i,
6509 6509 err = rt6_fill_node(net, skb, f6i, NULL, NULL, NULL, 0, RTM_NEWROUTE, 0,
6510 6510 0, 0, RT_DEL_REASON_UNSPEC);
6511 6511 if (err < 0) {
6512 + /* -EMSGSIZE implies BUG in rt6_nlmsg_size() */
6513 + WARN_ON(err == -EMSGSIZE);
6512 6514 kfree_skb(skb);
6513 6515 goto errout;
6514 6516 }
modified net/mac80211/airtime.c
@@ -632,22 +632,6 @@ static bool ieee80211_fill_rate_info(struct ieee80211_hw *hw,
632 632 if (!ri || !sband)
633 633 return false;
634 634
635 - /*
636 - * ieee80211_get_rate_duration() only handles these widths. Drivers
637 - * may also report e.g. HE/EHT RU allocations, which cannot be used
638 - * to estimate airtime here.
639 - */
640 - switch (ri->bw) {
641 - case RATE_INFO_BW_20:
642 - case RATE_INFO_BW_40:
643 - case RATE_INFO_BW_80:
644 - case RATE_INFO_BW_160:
645 - case RATE_INFO_BW_320:
646 - break;
647 - default:
648 - return false;
649 - }
650 -
651 635 stat->bw = ri->bw;
652 636 stat->nss = ri->nss;
653 637 stat->rate_idx = ri->mcs;
@@ -786,8 +770,6 @@ u32 ieee80211_rate_expected_tx_airtime(struct ieee80211_hw *hw,
786 770 return ieee80211_calc_rx_airtime(hw, &stat, len) * 1024;
787 771
788 772 duration = ieee80211_get_rate_duration(hw, &stat, &overhead);
789 - if (!duration)
790 - return 0;
791 773
792 774 /*
793 775 * Assume that HT/VHT transmission on any AC except VO will
modified net/netfilter/xt_CHECKSUM.c
@@ -15,7 +15,6 @@
15 15
16 16 #include <linux/netfilter_ipv4/ip_tables.h>
17 17 #include <linux/netfilter_ipv6/ip6_tables.h>
18 - #include <net/ip.h>
19 18
20 19 MODULE_LICENSE("GPL");
21 20 MODULE_AUTHOR("Michael S. Tsirkin <mst@redhat.com>");
@@ -26,11 +25,8 @@ MODULE_ALIAS("ip6t_CHECKSUM");
26 25 static unsigned int
27 26 checksum_tg(struct sk_buff *skb, const struct xt_action_param *par)
28 27 {
29 - if (skb->ip_summed == CHECKSUM_PARTIAL && !skb_is_gso(skb)) {
30 - if (xt_family(par) == NFPROTO_IPV4 && ip_check_csum_start(skb))
31 - return NF_DROP;
28 + if (skb->ip_summed == CHECKSUM_PARTIAL && !skb_is_gso(skb))
32 29 skb_checksum_help(skb);
33 - }
34 30
35 31 return XT_CONTINUE;
36 32 }
modified net/openvswitch/actions.c
@@ -358,12 +358,7 @@ static void set_ip_addr(struct sk_buff *skb, struct iphdr *nh,
358 358 static void update_ipv6_checksum(struct sk_buff *skb, u8 l4_proto,
359 359 __be32 addr[4], const __be32 new_addr[4])
360 360 {
361 - int transport_len;
362 -
363 - if (l4_proto == NEXTHDR_FRAGMENT)
364 - return;
365 -
366 - transport_len = skb->len - skb_transport_offset(skb);
361 + int transport_len = skb->len - skb_transport_offset(skb);
367 362
368 363 if (l4_proto == NEXTHDR_TCP) {
369 364 if (likely(transport_len >= sizeof(struct tcphdr)))
modified net/openvswitch/datapath.c
@@ -1532,12 +1532,6 @@ static int ovs_flow_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
1532 1532 return -ENODEV;
1533 1533 }
1534 1534
1535 - /*
1536 - * Not needed for safety. Stops every spin_unlock_bh() in
1537 - * ovs_flow_stats_get() from running the softirq backlog.
1538 - */
1539 - local_bh_disable();
1540 -
1541 1535 ti = rcu_dereference(dp->table.ti);
1542 1536 for (;;) {
1543 1537 struct sw_flow *flow;
@@ -1558,8 +1552,6 @@ static int ovs_flow_cmd_dump(struct sk_buff *skb, struct netlink_callback *cb)
1558 1552 cb->args[0] = bucket;
1559 1553 cb->args[1] = obj;
1560 1554 }
1561 -
1562 - local_bh_enable();
1563 1555 rcu_read_unlock();
1564 1556 return skb->len;
1565 1557 }
modified net/packet/af_packet.c
@@ -1911,8 +1911,7 @@ static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev,
1911 1911
1912 1912 spkt = &PACKET_SKB_CB(skb)->sa.pkt;
1913 1913
1914 - if (dev_has_header(dev))
1915 - skb_push(skb, skb->data - skb_mac_header(skb));
1914 + skb_push(skb, skb->data - skb_mac_header(skb));
1916 1915
1917 1916 /*
1918 1917 * The SOCK_PACKET socket receives _all_ frames.
@@ -1943,7 +1942,8 @@ static void packet_parse_headers(struct sk_buff *skb, struct socket *sock)
1943 1942 /* On TX skb->data is the L2 header; anchor it for all socket types. */
1944 1943 skb_reset_mac_header(skb);
1945 1944
1946 - if (!skb->protocol && sock->type == SOCK_RAW)
1945 + if ((!skb->protocol || skb->protocol == htons(ETH_P_ALL)) &&
1946 + sock->type == SOCK_RAW)
1947 1947 skb->protocol = dev_parse_header_protocol(skb);
1948 1948
1949 1949 skb_probe_transport_header(skb);
@@ -2613,8 +2613,7 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
2613 2613 struct page *page;
2614 2614 int err;
2615 2615
2616 - if (proto != htons(ETH_P_ALL))
2617 - skb->protocol = proto;
2616 + skb->protocol = proto;
2618 2617 skb->dev = dev;
2619 2618 skb->priority = sockc->priority;
2620 2619 skb->mark = sockc->mark;
@@ -2678,6 +2677,8 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
2678 2677 if (unlikely(!skb->len))
2679 2678 return -EINVAL;
2680 2679
2680 + packet_parse_headers(skb, sock);
2681 +
2681 2682 return tp_len;
2682 2683 }
2683 2684
@@ -2917,12 +2918,8 @@ tpacket_error:
2917 2918 tp_len = -EINVAL;
2918 2919 goto tpacket_error;
2919 2920 }
2920 - }
2921 -
2922 - packet_parse_headers(skb, po->sk.sk_socket);
2923 -
2924 - if (has_vnet_hdr)
2925 2921 virtio_net_hdr_set_proto(skb, &vnet_hdr);
2922 + }
2926 2923
2927 2924 uarg = kmalloc(sizeof(*uarg), GFP_KERNEL);
2928 2925 if (unlikely(!uarg)) {
@@ -3124,8 +3121,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
3124 3121 goto out_free;
3125 3122 }
3126 3123
3127 - if (proto != htons(ETH_P_ALL))
3128 - skb->protocol = proto;
3124 + skb->protocol = proto;
3129 3125 skb->dev = dev;
3130 3126 skb->priority = sockc.priority;
3131 3127 skb->mark = sockc.mark;
@@ -3134,17 +3130,15 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
3134 3130 if (unlikely(extra_len == 4))
3135 3131 skb->no_fcs = 1;
3136 3132
3133 + packet_parse_headers(skb, sock);
3134 +
3137 3135 if (vnet_hdr_sz) {
3138 3136 err = virtio_net_hdr_to_skb(skb, &vnet_hdr, vio_le());
3139 3137 if (err)
3140 3138 goto out_free;
3141 3139 len += vnet_hdr_sz;
3142 - }
3143 -
3144 - packet_parse_headers(skb, sock);
3145 -
3146 - if (vnet_hdr_sz)
3147 3140 virtio_net_hdr_set_proto(skb, &vnet_hdr);
3141 + }
3148 3142
3149 3143 err = packet_xmit(po, skb);
3150 3144
modified net/sched/cls_route.c
@@ -434,12 +434,6 @@ static int route4_set_parms(struct net *net, struct tcf_proto *tp,
434 434 if (handle && (!fold || nhandle == (handle & ~0x7F00)))
435 435 nhandle |= handle & 0x7F00;
436 436
437 - if (fold && !tb[TCA_ROUTE4_TO] && !tb[TCA_ROUTE4_FROM] &&
438 - !tb[TCA_ROUTE4_IIF] && nhandle != fold->handle) {
439 - NL_SET_ERR_MSG(extack, "Routing attributes required");
440 - return -EINVAL;
441 - }
442 -
443 437 if (handle && !fold && nhandle != handle) {
444 438 NL_SET_ERR_MSG_FMT(extack,
445 439 "Handle mismatch constructed: %x (expected: %x)",
modified net/sched/em_text.c
@@ -58,9 +58,6 @@ static int em_text_change(struct net *net, void *data, int len,
58 58 if (len < sizeof(*conf) || len < (sizeof(*conf) + conf->pattern_len))
59 59 return -EINVAL;
60 60
61 - if (!memchr(conf->algo, '\0', sizeof(conf->algo)))
62 - return -EINVAL;
63 -
64 61 if (conf->from_layer > conf->to_layer)
65 62 return -EINVAL;
66 63
modified net/sctp/socket.c
@@ -7569,7 +7569,11 @@ static int sctp_getsockopt_pr_streamstatus(struct sock *sk, int len,
7569 7569 /* Not allocated yet, means all stats are 0 */
7570 7570 params.sprstat_abandoned_unsent = 0;
7571 7571 params.sprstat_abandoned_sent = 0;
7572 - } else if (policy == SCTP_PR_SCTP_ALL) {
7572 + retval = 0;
7573 + goto out;
7574 + }
7575 +
7576 + if (policy == SCTP_PR_SCTP_ALL) {
7573 7577 params.sprstat_abandoned_unsent = 0;
7574 7578 params.sprstat_abandoned_sent = 0;
7575 7579 for (policy = 0; policy <= SCTP_PR_INDEX(MAX); policy++) {
modified net/smc/af_smc.c
@@ -2784,7 +2784,6 @@ int smc_getname(struct socket *sock, struct sockaddr *addr,
2784 2784 int peer)
2785 2785 {
2786 2786 struct smc_sock *smc;
2787 - int rc = -EBADF;
2788 2787
2789 2788 if (peer && (sock->sk->sk_state != SMC_ACTIVE) &&
2790 2789 (sock->sk->sk_state != SMC_APPCLOSEWAIT1))
@@ -2792,11 +2791,7 @@ int smc_getname(struct socket *sock, struct sockaddr *addr,
2792 2791
2793 2792 smc = smc_sk(sock->sk);
2794 2793
2795 - mutex_lock(&smc->clcsock_release_lock);
2796 - if (smc->clcsock)
2797 - rc = smc->clcsock->ops->getname(smc->clcsock, addr, peer);
2798 - mutex_unlock(&smc->clcsock_release_lock);
2799 - return rc;
2794 + return smc->clcsock->ops->getname(smc->clcsock, addr, peer);
2800 2795 }
2801 2796
2802 2797 int smc_sendmsg(struct socket *sock, struct msghdr *msg, size_t len)
modified net/strparser/strparser.c
@@ -505,16 +505,12 @@ void strp_unpause(struct strparser *strp)
505 505 EXPORT_SYMBOL_GPL(strp_unpause);
506 506
507 507 /* strp must already be stopped so that strp_recv will no longer be called.
508 - * Note that strp_done must not be called with the lower socket held.
508 + * Note that strp_done is not called with the lower socket held.
509 509 */
510 510 void strp_done(struct strparser *strp)
511 511 {
512 512 WARN_ON(!strp->stopped);
513 513
514 - lock_sock(strp->sk);
515 - /* sync with pending strp_recv */
516 - release_sock(strp->sk);
517 -
518 514 cancel_delayed_work_sync(&strp->msg_timer_work);
519 515 cancel_work_sync(&strp->work);
520 516
modified net/tipc/node.c
@@ -2421,11 +2421,8 @@ static struct tipc_node *tipc_node_find_by_name(struct net *net,
2421 2421 }
2422 2422 }
2423 2423 tipc_node_read_unlock(n);
2424 - if (found_node) {
2425 - if (!kref_get_unless_zero(&found_node->kref))
2426 - found_node = NULL;
2424 + if (found_node)
2427 2425 break;
2428 - }
2429 2426 }
2430 2427 rcu_read_unlock();
2431 2428
@@ -2510,7 +2507,6 @@ out:
2510 2507 tipc_node_read_unlock(node);
2511 2508 tipc_bearer_xmit(net, bearer_id, &xmitq, &node->links[bearer_id].maddr,
2512 2509 NULL);
2513 - tipc_node_put(node);
2514 2510 return res;
2515 2511 }
2516 2512
@@ -2562,14 +2558,12 @@ int tipc_nl_node_get_link(struct sk_buff *skb, struct genl_info *info)
2562 2558 link = node->links[bearer_id].link;
2563 2559 if (!link) {
2564 2560 tipc_node_read_unlock(node);
2565 - tipc_node_put(node);
2566 2561 err = -EINVAL;
2567 2562 goto err_free;
2568 2563 }
2569 2564
2570 2565 err = __tipc_nl_add_link(net, &msg, link, 0);
2571 2566 tipc_node_read_unlock(node);
2572 - tipc_node_put(node);
2573 2567 if (err)
2574 2568 goto err_free;
2575 2569 }
@@ -2640,13 +2634,11 @@ int tipc_nl_node_reset_link_stats(struct sk_buff *skb, struct genl_info *info)
2640 2634 if (!link) {
2641 2635 spin_unlock_bh(&le->lock);
2642 2636 tipc_node_read_unlock(node);
2643 - tipc_node_put(node);
2644 2637 return -EINVAL;
2645 2638 }
2646 2639 tipc_link_reset_stats(link);
2647 2640 spin_unlock_bh(&le->lock);
2648 2641 tipc_node_read_unlock(node);
2649 - tipc_node_put(node);
2650 2642 return 0;
2651 2643 }
2652 2644
modified net/tipc/topsrv.c
@@ -55,7 +55,7 @@
55 55 /**
56 56 * struct tipc_topsrv - TIPC server structure
57 57 * @conn_idr: identifier set of connection
58 - * @idr_lock: protect the connection identifier set and listener
58 + * @idr_lock: protect the connection identifier set
59 59 * @idr_in_use: amount of allocated identifier entry
60 60 * @net: network namespace instance
61 61 * @awork: accept work item
@@ -218,10 +218,6 @@ static struct tipc_conn *tipc_conn_lookup(struct tipc_topsrv *s, int conid)
218 218 struct tipc_conn *con;
219 219
220 220 spin_lock_bh(&s->idr_lock);
221 - if (!s->listener) {
222 - spin_unlock_bh(&s->idr_lock);
223 - return NULL;
224 - }
225 221 con = idr_find(&s->conn_idr, conid);
226 222 if (!connected(con) || !kref_get_unless_zero(&con->kref))
227 223 con = NULL;
@@ -305,20 +301,10 @@ static void tipc_conn_send_to_sock(struct tipc_conn *con)
305 301 static void tipc_conn_send_work(struct work_struct *work)
306 302 {
307 303 struct tipc_conn *con = container_of(work, struct tipc_conn, swork);
308 - struct tipc_topsrv *srv;
309 -
310 - srv = con->server;
311 - spin_lock_bh(&srv->idr_lock);
312 - if (!srv->listener) {
313 - spin_unlock_bh(&srv->idr_lock);
314 - goto out;
315 - }
316 - spin_unlock_bh(&srv->idr_lock);
317 304
318 305 if (connected(con))
319 306 tipc_conn_send_to_sock(con);
320 307
321 - out:
322 308 conn_put(con);
323 309 }
324 310
@@ -348,14 +334,8 @@ void tipc_topsrv_queue_evt(struct net *net, int conid,
348 334 list_add_tail(&e->list, &con->outqueue);
349 335 spin_unlock_bh(&con->outqueue_lock);
350 336
351 - spin_lock_bh(&srv->idr_lock);
352 - if (srv->listener) {
353 - if (queue_work(srv->send_wq, &con->swork)) {
354 - spin_unlock_bh(&srv->idr_lock);
355 - return;
356 - }
357 - }
358 - spin_unlock_bh(&srv->idr_lock);
337 + if (queue_work(srv->send_wq, &con->swork))
338 + return;
359 339 err:
360 340 conn_put(con);
361 341 }
@@ -366,20 +346,14 @@ err:
366 346 */
367 347 static void tipc_conn_write_space(struct sock *sk)
368 348 {
369 - struct tipc_topsrv *srv;
370 349 struct tipc_conn *con;
371 350
372 351 read_lock_bh(&sk->sk_callback_lock);
373 352 con = sk->sk_user_data;
374 353 if (connected(con)) {
375 - srv = con->server;
376 - spin_lock_bh(&srv->idr_lock);
377 - if (srv->listener) {
378 - conn_get(con);
379 - if (!queue_work(srv->send_wq, &con->swork))
380 - conn_put(con);
381 - }
382 - spin_unlock_bh(&srv->idr_lock);
354 + conn_get(con);
355 + if (!queue_work(con->server->send_wq, &con->swork))
356 + conn_put(con);
383 357 }
384 358 read_unlock_bh(&sk->sk_callback_lock);
385 359 }
@@ -444,17 +418,8 @@ static int tipc_conn_rcv_from_sock(struct tipc_conn *con)
444 418 static void tipc_conn_recv_work(struct work_struct *work)
445 419 {
446 420 struct tipc_conn *con = container_of(work, struct tipc_conn, rwork);
447 - struct tipc_topsrv *srv;
448 421 int count = 0;
449 422
450 - srv = con->server;
451 - spin_lock_bh(&srv->idr_lock);
452 - if (!srv->listener) {
453 - spin_unlock_bh(&srv->idr_lock);
454 - goto out;
455 - }
456 - spin_unlock_bh(&srv->idr_lock);
457 -
458 423 while (connected(con)) {
459 424 if (tipc_conn_rcv_from_sock(con))
460 425 break;
@@ -465,7 +430,6 @@ static void tipc_conn_recv_work(struct work_struct *work)
465 430 count = 0;
466 431 }
467 432 }
468 - out:
469 433 conn_put(con);
470 434 }
471 435
@@ -474,7 +438,6 @@ out:
474 438 */
475 439 static void tipc_conn_data_ready(struct sock *sk)
476 440 {
477 - struct tipc_topsrv *srv;
478 441 struct tipc_conn *con;
479 442
480 443 trace_sk_data_ready(sk);
@@ -482,14 +445,9 @@ static void tipc_conn_data_ready(struct sock *sk)
482 445 read_lock_bh(&sk->sk_callback_lock);
483 446 con = sk->sk_user_data;
484 447 if (connected(con)) {
485 - srv = con->server;
486 - spin_lock_bh(&srv->idr_lock);
487 - if (srv->listener) {
488 - conn_get(con);
489 - if (!queue_work(srv->rcv_wq, &con->rwork))
490 - conn_put(con);
491 - }
492 - spin_unlock_bh(&srv->idr_lock);
448 + conn_get(con);
449 + if (!queue_work(con->server->rcv_wq, &con->rwork))
450 + conn_put(con);
493 451 }
494 452 read_unlock_bh(&sk->sk_callback_lock);
495 453 }
@@ -545,12 +503,8 @@ static void tipc_topsrv_listener_data_ready(struct sock *sk)
545 503
546 504 read_lock_bh(&sk->sk_callback_lock);
547 505 srv = sk->sk_user_data;
548 - if (srv) {
549 - spin_lock_bh(&srv->idr_lock);
550 - if (srv->listener)
551 - queue_work(srv->rcv_wq, &srv->awork);
552 - spin_unlock_bh(&srv->idr_lock);
553 - }
506 + if (srv)
507 + queue_work(srv->rcv_wq, &srv->awork);
554 508 read_unlock_bh(&sk->sk_callback_lock);
555 509 }
556 510
@@ -746,27 +700,23 @@ static void tipc_topsrv_stop(struct net *net)
746 700 struct tipc_conn *con;
747 701 int id;
748 702
749 - spin_lock_bh(&srv->idr_lock);
750 - srv->listener = NULL;
751 - spin_unlock_bh(&srv->idr_lock);
752 - tipc_topsrv_work_stop(srv);
753 -
754 703 spin_lock_bh(&srv->idr_lock);
755 704 for (id = 0; srv->idr_in_use; id++) {
756 705 con = idr_find(&srv->conn_idr, id);
757 706 if (con) {
707 + conn_get(con);
758 708 spin_unlock_bh(&srv->idr_lock);
759 709 tipc_conn_close(con);
710 + conn_put(con);
760 711 spin_lock_bh(&srv->idr_lock);
761 - continue;
762 712 }
763 - spin_unlock_bh(&srv->idr_lock);
764 - spin_lock_bh(&srv->idr_lock);
765 713 }
766 714 __module_get(lsock->ops->owner);
767 715 __module_get(lsock->sk->sk_prot_creator->owner);
716 + srv->listener = NULL;
768 717 spin_unlock_bh(&srv->idr_lock);
769 718
719 + tipc_topsrv_work_stop(srv);
770 720 sock_release(lsock);
771 721 idr_destroy(&srv->conn_idr);
772 722 kfree(srv);
modified net/vmw_vsock/af_vsock.c
@@ -1048,8 +1048,6 @@ static void vsock_sk_destruct(struct sock *sk)
1048 1048 {
1049 1049 struct vsock_sock *vsk = vsock_sk(sk);
1050 1050
1051 - /* Socket buffers may remain in the queue in VMCI datagram mode */
1052 - __skb_queue_purge(&sk->sk_receive_queue);
1053 1051 /* Flush MSG_ZEROCOPY leftovers. */
1054 1052 __skb_queue_purge(&sk->sk_error_queue);
1055 1053
modified net/vmw_vsock/virtio_transport_common.c
@@ -1927,7 +1927,6 @@ int virtio_transport_read_skb(struct vsock_sock *vsk, skb_read_actor_t recv_acto
1927 1927 struct sock *sk = sk_vsock(vsk);
1928 1928 struct virtio_vsock_hdr *hdr;
1929 1929 struct sk_buff *skb;
1930 - u32 bytes_read;
1931 1930 u32 pkt_len;
1932 1931 int off = 0;
1933 1932 int err;
@@ -1947,8 +1946,7 @@ int virtio_transport_read_skb(struct vsock_sock *vsk, skb_read_actor_t recv_acto
1947 1946 vvs->msg_count--;
1948 1947
1949 1948 pkt_len = le32_to_cpu(hdr->len);
1950 - bytes_read = skb->len - VIRTIO_VSOCK_SKB_CB(skb)->offset;
1951 - virtio_transport_dec_rx_pkt(vvs, bytes_read, pkt_len);
1949 + virtio_transport_dec_rx_pkt(vvs, pkt_len, pkt_len);
1952 1950 spin_unlock_bh(&vvs->rx_lock);
1953 1951
1954 1952 virtio_transport_send_credit_update(vsk);
modified net/xfrm/xfrm_output.c
@@ -823,22 +823,16 @@ int xfrm_output(struct sock *sk, struct sk_buff *skb)
823 823 }
824 824
825 825 if (skb->ip_summed == CHECKSUM_PARTIAL) {
826 - if (skb->protocol == htons(ETH_P_IP)) {
827 - err = ip_check_csum_start(skb);
828 - if (err)
829 - goto error;
830 - }
831 826 err = skb_checksum_help(skb);
832 - if (err)
833 - goto error;
827 + if (err) {
828 + XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
829 + kfree_skb(skb);
830 + return err;
831 + }
834 832 }
835 833
836 834 out:
837 835 return xfrm_output2(net, sk, skb);
838 - error:
839 - XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTERROR);
840 - kfree_skb(skb);
841 - return err;
842 836 }
843 837 EXPORT_SYMBOL_GPL(xfrm_output);
844 838
modified security/keys/key.c
@@ -840,6 +840,9 @@ static key_ref_t __key_create_or_update(key_ref_t keyring_ref,
840 840
841 841 key_check(keyring);
842 842
843 + if (!(flags & KEY_ALLOC_BYPASS_RESTRICTION))
844 + restrict_link = keyring->restrict_link;
845 +
843 846 key_ref = ERR_PTR(-ENOTDIR);
844 847 if (keyring->type != &key_type_keyring)
845 848 goto error_put_type;
@@ -877,9 +880,6 @@ static key_ref_t __key_create_or_update(key_ref_t keyring_ref,
877 880 goto error_link_end;
878 881 }
879 882
880 - if (!(flags & KEY_ALLOC_BYPASS_RESTRICTION))
881 - restrict_link = keyring->restrict_link;
882 -
883 883 if (restrict_link && restrict_link->check) {
884 884 ret = restrict_link->check(keyring, index_key.type,
885 885 &prep.payload, restrict_link->key);
modified security/keys/persistent.c
@@ -33,31 +33,25 @@ static int key_create_persistent_register(struct user_namespace *ns)
33 33 }
34 34
35 35 /*
36 - * Get or create the persistent keyring for the specified user.
36 + * Create the persistent keyring for the specified user.
37 37 *
38 38 * Called with the namespace's sem locked for writing.
39 - *
40 - * Returns a boolean indicating whether the keyring already existed,
41 - * or a negative error. On success, *persistent_ref holds a reference
42 - * to the keyring.
43 39 */
44 - static int key_get_or_create_persistent(struct user_namespace *ns, kuid_t uid,
45 - struct keyring_index_key *index_key,
46 - key_ref_t *persistent_ref)
40 + static key_ref_t key_create_persistent(struct user_namespace *ns, kuid_t uid,
41 + struct keyring_index_key *index_key)
47 42 {
48 43 struct key *persistent;
49 - key_ref_t reg_ref;
44 + key_ref_t reg_ref, persistent_ref;
50 45
51 46 if (!ns->persistent_keyring_register) {
52 - int err = key_create_persistent_register(ns);
53 -
47 + long err = key_create_persistent_register(ns);
54 48 if (err < 0)
55 - return err;
49 + return ERR_PTR(err);
56 50 } else {
57 51 reg_ref = make_key_ref(ns->persistent_keyring_register, true);
58 - *persistent_ref = find_key_to_update(reg_ref, index_key);
59 - if (*persistent_ref)
60 - return 1;
52 + persistent_ref = find_key_to_update(reg_ref, index_key);
53 + if (persistent_ref)
54 + return persistent_ref;
61 55 }
62 56
63 57 persistent = keyring_alloc(index_key->description,
@@ -67,10 +61,9 @@ static int key_get_or_create_persistent(struct user_namespace *ns, kuid_t uid,
67 61 KEY_ALLOC_NOT_IN_QUOTA, NULL,
68 62 ns->persistent_keyring_register);
69 63 if (IS_ERR(persistent))
70 - return PTR_ERR(persistent);
64 + return ERR_CAST(persistent);
71 65
72 - *persistent_ref = make_key_ref(persistent, true);
73 - return 0;
66 + return make_key_ref(persistent, true);
74 67 }
75 68
76 69 /*
@@ -85,7 +78,6 @@ static long key_get_persistent(struct user_namespace *ns, kuid_t uid,
85 78 key_ref_t reg_ref, persistent_ref;
86 79 char buf[32];
87 80 long ret;
88 - bool created = false;
89 81
90 82 /* Look in the register if it exists */
91 83 memset(&index_key, 0, sizeof(index_key));
@@ -108,24 +100,23 @@ static long key_get_persistent(struct user_namespace *ns, kuid_t uid,
108 100 * also need to create the register.
109 101 */
110 102 down_write(&ns->keyring_sem);
111 - ret = key_get_or_create_persistent(ns, uid, &index_key,
112 - &persistent_ref);
103 + persistent_ref = key_create_persistent(ns, uid, &index_key);
113 104 up_write(&ns->keyring_sem);
114 - if (ret < 0)
115 - return ret;
116 - created = ret == 0;
105 + if (!IS_ERR(persistent_ref))
106 + goto found;
107 +
108 + return PTR_ERR(persistent_ref);
117 109
118 110 found:
119 - persistent = key_ref_to_ptr(persistent_ref);
120 111 ret = key_task_permission(persistent_ref, current_cred(), KEY_NEED_LINK);
121 - if (ret == 0)
112 + if (ret == 0) {
113 + persistent = key_ref_to_ptr(persistent_ref);
122 114 ret = key_link(key_ref_to_ptr(dest_ref), persistent);
123 -
124 - if (ret == 0 || created)
125 - key_set_timeout(persistent, persistent_keyring_expiry);
126 -
127 - if (ret == 0)
128 - ret = persistent->serial;
115 + if (ret == 0) {
116 + key_set_timeout(persistent, persistent_keyring_expiry);
117 + ret = persistent->serial;
118 + }
119 + }
129 120
130 121 key_ref_put(persistent_ref);
131 122 return ret;
modified security/landlock/domain.h
@@ -242,14 +242,9 @@ struct landlock_domain {
242 242 * to properly handle merged rulesets without
243 243 * overlapping access rights. These layers are set once
244 244 * and never changed for the lifetime of the domain.
245 - *
246 - * Not annotated with __counted_by(num_layers): clang
247 - * miscomputes the counter address for a FAM nested in
248 - * an anonymous struct within a union, which trips
249 - * FORTIFY:
250 - * https://github.com/llvm/llvm-project/pull/228309
251 245 */
252 - struct access_masks handled_masks[];
246 + struct access_masks
247 + handled_masks[] __counted_by(num_layers);
253 248 };
254 249 };
255 250 };
modified security/selinux/avc.c
@@ -578,7 +578,7 @@ static int avc_latest_notif_update(u32 seqno, int is_insert)
578 578 }
579 579 } else {
580 580 if (seqno > selinux_avc.avc_cache.latest_notif)
581 - WRITE_ONCE(selinux_avc.avc_cache.latest_notif, seqno);
581 + selinux_avc.avc_cache.latest_notif = seqno;
582 582 }
583 583 spin_unlock_irqrestore(&notif_lock, flag);
584 584
@@ -1206,6 +1206,5 @@ int avc_has_perm(u32 ssid, u32 tsid, u16 tclass,
1206 1206
1207 1207 u32 avc_policy_seqno(void)
1208 1208 {
1209 - /* Writers hold notif_lock; readers only sample the sequence number. */
1210 - return READ_ONCE(selinux_avc.avc_cache.latest_notif);
1209 + return selinux_avc.avc_cache.latest_notif;
1211 1210 }
modified security/selinux/hooks.c
@@ -690,12 +690,8 @@ static int selinux_set_mnt_opts(struct super_block *sb,
690 690 * will be used for both mounts)
691 691 */
692 692 if ((sbsec->flags & SE_SBINITIALIZED) && (sb->s_type->fs_flags & FS_BINARY_MOUNTDATA)
693 - && !opts) {
694 - if ((kern_flags & SECURITY_LSM_NATIVE_LABELS) &&
695 - sbsec->behavior == SECURITY_FS_USE_NATIVE)
696 - *set_kern_flags |= SECURITY_LSM_NATIVE_LABELS;
693 + && !opts)
697 694 goto out;
698 - }
699 695
700 696 root_isec = backing_inode_security_novalidate(root);
701 697
@@ -739,9 +735,6 @@ static int selinux_set_mnt_opts(struct super_block *sb,
739 735 /* previously mounted with options, but not on this attempt? */
740 736 if ((sbsec->flags & SE_MNTMASK) && !opts)
741 737 goto out_double_mount;
742 - if ((kern_flags & SECURITY_LSM_NATIVE_LABELS) &&
743 - sbsec->behavior == SECURITY_FS_USE_NATIVE)
744 - *set_kern_flags |= SECURITY_LSM_NATIVE_LABELS;
745 738 rc = 0;
746 739 goto out;
747 740 }
modified sound/hda/codecs/realtek/alc269.c
@@ -7646,7 +7646,6 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
7646 7646 SND_PCI_QUIRK(0x103c, 0x8be8, "HP Envy 17", ALC287_FIXUP_CS35L41_I2C_2),
7647 7647 SND_PCI_QUIRK(0x103c, 0x8be9, "HP Envy x360 2-in-1 Laptop 15-fh0xxx", ALC245_FIXUP_HP_ENVY_X360_15_FH0XXX),
7648 7648 SND_PCI_QUIRK(0x103c, 0x8bf0, "HP", ALC236_FIXUP_HP_GPIO_LED),
7649 - SND_PCI_QUIRK(0x103c, 0x8bfd, "HP Pavilion 15-eg3xxx", ALC287_FIXUP_HP_GPIO_LED),
7650 7649 SND_PCI_QUIRK(0x103c, 0x8c15, "HP Spectre x360 2-in-1 Laptop 14-eu0xxx", ALC245_FIXUP_HP_SPECTRE_X360_EU0XXX),
7651 7650 SND_PCI_QUIRK(0x103c, 0x8c16, "HP Spectre x360 2-in-1 Laptop 16-aa0xxx", ALC245_FIXUP_HP_SPECTRE_X360_16_AA0XXX),
7652 7651 SND_PCI_QUIRK(0x103c, 0x8c17, "HP Spectre x360 2-in-1 Laptop 16-aa0xxx", ALC245_FIXUP_HP_SPECTRE_X360_16_AA0XXX),
@@ -8347,7 +8346,6 @@ static const struct hda_quirk alc269_fixup_tbl[] = {
8347 8346 SND_PCI_QUIRK(0x17aa, 0x9e56, "Lenovo ZhaoYang CF4620Z", ALC286_FIXUP_SONY_MIC_NO_PRESENCE),
8348 8347 SND_PCI_QUIRK(0x1849, 0x0269, "Positivo Master C6400", ALC269VB_FIXUP_ASUS_ZENBOOK),
8349 8348 SND_PCI_QUIRK(0x1849, 0x1233, "ASRock NUC Box 1100", ALC233_FIXUP_NO_AUDIO_JACK),
8350 - SND_PCI_QUIRK(0x1849, 0x6256, "ASRock NUC Box 358H", ALC233_FIXUP_NO_AUDIO_JACK),
8351 8349 SND_PCI_QUIRK(0x1849, 0xa233, "Positivo Master C6300", ALC269_FIXUP_HEADSET_MIC),
8352 8350 SND_PCI_QUIRK(0x1854, 0x0440, "LG CQ6", ALC256_FIXUP_HEADPHONE_AMP_VOL),
8353 8351 SND_PCI_QUIRK(0x1854, 0x0441, "LG CQ6 AIO", ALC256_FIXUP_HEADPHONE_AMP_VOL),
modified sound/hda/codecs/side-codecs/tas2781_hda.c
@@ -139,21 +139,9 @@ static void tas2781_apply_calib(struct tasdevice_priv *p)
139 139 */
140 140 crc = crc32(~0, data, 84) ^ ~0;
141 141 if (crc != tmp_val[21]) {
142 - /*
143 - * Some Lenovo BIOSes (e.g. Legion Pro 7 16IRX9H,
144 - * SSID 17aa:38cd) store valid V1 calibration data
145 - * but leave TimeStamp and CRC zeroed.
146 - */
147 - if (!tmp_val[20] && !tmp_val[21] &&
148 - tmp_val[0] && tmp_val[1]) {
149 - dev_warn(p->dev,
150 - "%s: V1 data without CRC, accepting\n",
151 - __func__);
152 - } else {
153 - cali_data->total_sz = 0;
154 - dev_err(p->dev, "%s: V1 CRC error\n", __func__);
155 - return;
156 - }
142 + cali_data->total_sz = 0;
143 + dev_err(p->dev, "%s: V1 CRC error\n", __func__);
144 + return;
157 145 }
158 146
159 147 for (j = p->ndev - 1; j >= 0; j--) {
modified sound/pci/ctxfi/ctdaio.c
@@ -221,18 +221,14 @@ static int dao_set_right_input(struct dao *dao, struct rsc *input)
221 221
222 222 static int dao_clear_input(struct dao *dao, unsigned int start, unsigned int end)
223 223 {
224 - struct imapper *entry;
225 224 unsigned int i;
226 225
227 - entry = dao->imappers[start];
228 - if (!entry)
226 + if (!dao->imappers[start])
229 227 return 0;
230 -
231 228 for (i = start; i < end; i++) {
232 229 dao->mgr->imap_delete(dao->mgr, dao->imappers[i]);
233 230 dao->imappers[i] = NULL;
234 231 }
235 - kfree(entry);
236 232
237 233 return 0;
238 234 }
modified sound/soc/intel/avs/pcm.c
@@ -756,7 +756,7 @@ static int avs_dai_fe_prepare(struct snd_pcm_substream *substream, struct snd_so
756 756 data = snd_soc_dai_get_dma_data(dai, substream);
757 757 host_stream = data->host_stream;
758 758
759 - if (runtime->state == SNDRV_PCM_STATE_XRUN)
759 + if (runtime->state != SNDRV_PCM_STATE_PREPARED)
760 760 hdac_stream(host_stream)->prepared = false;
761 761 if (hdac_stream(host_stream)->prepared)
762 762 return 0;
modified sound/soc/sof/ipc4-topology.c
@@ -2458,11 +2458,14 @@ _sof_ipc4_prepare_copier_module(struct snd_sof_widget *swidget,
2458 2458 ch_map >>= 4;
2459 2459 }
2460 2460
2461 - if (swidget->id == snd_soc_dapm_dai_in && ch_count == out_ref_channels) {
2461 + if ((swidget->id == snd_soc_dapm_dai_in && ch_count == out_ref_channels) ||
2462 + ch_count < blob->alh_cfg.device_count) {
2462 2463 /*
2463 2464 * For playback DAI widgets where the channel number is equal to
2464 - * the output reference channels, set the step = 0 to ensure all
2465 - * the ch_mask is applied to all alh mappings.
2465 + * the output reference channels, or when there are fewer
2466 + * channels than aggregated devices (e.g. a mono capture
2467 + * stream split across multiple links), set step = 0 to
2468 + * ensure all the ch_mask is applied to all alh mappings.
2466 2469 */
2467 2470 mask = ch_mask;
2468 2471 step = 0;
modified sound/soc/sof/sof-client.c
@@ -576,7 +576,7 @@ void sof_client_unregister_ipc_rx_handler(struct sof_client_dev *cdev,
576 576 struct snd_sof_dev *sdev = sof_client_dev_to_sof_dev(cdev);
577 577 struct sof_ipc_event_entry *event;
578 578
579 - guard(mutex)(&sdev->ipc_client_mutex);
579 + guard(mutex)(&sdev->client_event_handler_mutex);
580 580
581 581 list_for_each_entry(event, &sdev->ipc_rx_handler_list, list) {
582 582 if (event->cdev == cdev && event->ipc_msg_type == ipc_msg_type) {
@@ -593,7 +593,7 @@ void sof_client_fw_state_dispatcher(struct snd_sof_dev *sdev)
593 593 {
594 594 struct sof_state_event_entry *event;
595 595
596 - guard(mutex)(&sdev->ipc_client_mutex);
596 + guard(mutex)(&sdev->client_event_handler_mutex);
597 597
598 598 list_for_each_entry(event, &sdev->fw_state_handler_list, list)
599 599 event->callback(event->cdev, sdev->fw_state);
@@ -628,7 +628,7 @@ void sof_client_unregister_fw_state_handler(struct sof_client_dev *cdev)
628 628 struct snd_sof_dev *sdev = sof_client_dev_to_sof_dev(cdev);
629 629 struct sof_state_event_entry *event;
630 630
631 - guard(mutex)(&sdev->ipc_client_mutex);
631 + guard(mutex)(&sdev->client_event_handler_mutex);
632 632
633 633 list_for_each_entry(event, &sdev->fw_state_handler_list, list) {
634 634 if (event->cdev == cdev) {
modified sound/soc/stm/stm32_spdifrx.c
@@ -720,7 +720,7 @@ static irqreturn_t stm32_spdifrx_isr(int irq, void *devid)
720 720
721 721 if (err) {
722 722 regmap_read(spdifrx->regmap, STM32_SPDIFRX_CR, &cr);
723 - sync_state = FIELD_GET(SPDIFRX_CR_SPDIFEN_MASK, cr) &&
723 + sync_state = FIELD_GET(SPDIFRX_CR_SPDIFEN_MASK, cr) ==
724 724 SPDIFRX_SPDIFEN_SYNC;
725 725
726 726 /* SPDIFRX is in STATE_STOP. Disable SPDIFRX to clear errors */
modified sound/usb/quirks.c
@@ -2510,8 +2510,6 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {
2510 2510 QUIRK_FLAG_DSD_RAW),
2511 2511 DEVICE_FLG(0x21b4, 0x0232, /* Ayre QX-5 Twenty */
2512 2512 QUIRK_FLAG_DSD_RAW),
2513 - DEVICE_FLG(0x22e8, 0xca10, /* Cambridge Audio streamers */
2514 - QUIRK_FLAG_DSD_RAW),
2515 2513 DEVICE_FLG(0x2522, 0x0007, /* LH Labs Geek Out HD Audio 1V5 */
2516 2514 QUIRK_FLAG_SET_IFACE_FIRST),
2517 2515 DEVICE_FLG(0x25aa, 0x600b, /* TAE1159 */
modified tools/testing/selftests/Makefile
@@ -43,7 +43,6 @@ TARGETS += filesystems/open_tree_ns
43 43 TARGETS += filesystems/overlayfs
44 44 TARGETS += filesystems/statmount
45 45 TARGETS += filesystems/mount-notify
46 - TARGETS += filesystems/mount_cycle
47 46 TARGETS += filesystems/nsfs
48 47 TARGETS += filesystems/fuse
49 48 TARGETS += filesystems/move_mount
@@ -51,8 +50,6 @@ TARGETS += filesystems/empty_mntns
51 50 TARGETS += filesystems/fsmount_ns
52 51 TARGETS += filesystems/fscontext_ns
53 52 TARGETS += filesystems/xattr
54 - TARGETS += filesystems/mntns_unbindable
55 - TARGETS += filesystems/umount_propagation
56 53 TARGETS += firmware
57 54 TARGETS += fpu
58 55 TARGETS += ftrace
modified tools/testing/selftests/drivers/net/mlxsw/port_range_occ.sh
@@ -9,7 +9,6 @@ lib_dir=$(dirname $0)/../../../net/forwarding
9 9
10 10 ALL_TESTS="
11 11 port_range_occ_test
12 - port_range_occ_tmplt_test
13 12 "
14 13 NUM_NETIFS=2
15 14 source $lib_dir/lib.sh
@@ -102,31 +101,6 @@ port_range_occ_test()
102 101 log_test "port range occupancy"
103 102 }
104 103
105 - port_range_occ_tmplt_test()
106 - {
107 - local occ
108 -
109 - RET=0
110 - occ=$(port_range_occ_get)
111 -
112 - # Addition of a chain template should not impact occupancy.
113 - tc chain add dev "$swp1" ingress chain 1 protocol ip \
114 - flower ip_proto udp src_port 501-600 dst_port 701-800
115 - check_err $? "Could not add chain template"
116 -
117 - (( occ == $(port_range_occ_get) ))
118 - check_err $? "Got occupancy $(port_range_occ_get), expected $occ"
119 -
120 - # And just for completeness sake, neither should deletion.
121 - tc chain del dev "$swp1" ingress chain 1
122 - check_err $? "Could not delete chain template"
123 -
124 - (( occ == $(port_range_occ_get) ))
125 - check_err $? "Got occupancy $(port_range_occ_get), expected $occ"
126 -
127 - log_test "port range occupancy after template create/destroy"
128 - }
129 -
130 104 trap cleanup EXIT
131 105
132 106 setup_prepare
modified tools/testing/selftests/filesystems/.gitignore
@@ -7,4 +7,3 @@ anon_inode_test
7 7 kernfs_test
8 8 idmapped_tmpfile
9 9 ustat_test
10 - rw_hint_test
modified tools/testing/selftests/filesystems/Makefile
@@ -1,7 +1,7 @@
1 1 # SPDX-License-Identifier: GPL-2.0
2 2
3 3 CFLAGS += $(KHDR_INCLUDES)
4 - TEST_GEN_PROGS := devpts_pts file_stressor anon_inode_test kernfs_test fclog ustat_test rw_hint_test
4 + TEST_GEN_PROGS := devpts_pts file_stressor anon_inode_test kernfs_test fclog ustat_test
5 5 TEST_GEN_PROGS += idmapped_tmpfile
6 6 TEST_GEN_PROGS_EXTENDED := dnotify_test
7 7
modified tools/testing/selftests/filesystems/empty_mntns/.gitignore
@@ -2,6 +2,3 @@
2 2 clone3_empty_mntns_test
3 3 empty_mntns_test
4 4 overmount_chroot_test
5 - internal_sb_reconfigure_test
6 - nullfs_atime_test
7 - root_readdir_test
modified tools/testing/selftests/filesystems/empty_mntns/Makefile
@@ -4,14 +4,9 @@ CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES) $(TOOLS_INCLUDES)
4 4 LDLIBS += -lcap
5 5
6 6 TEST_GEN_PROGS := empty_mntns_test overmount_chroot_test clone3_empty_mntns_test
7 - TEST_GEN_PROGS += internal_sb_reconfigure_test nullfs_atime_test root_readdir_test
8 -
9 - LOCAL_HDRS += ../readdir_hold.h
10 7
11 8 include ../../lib.mk
12 9
13 10 $(OUTPUT)/empty_mntns_test: ../utils.c
14 11 $(OUTPUT)/overmount_chroot_test: ../utils.c
15 12 $(OUTPUT)/clone3_empty_mntns_test: ../utils.c
16 - $(OUTPUT)/internal_sb_reconfigure_test: ../utils.c
17 - $(OUTPUT)/root_readdir_test: LDLIBS += -pthread
deleted tools/testing/selftests/filesystems/empty_mntns/internal_sb_reconfigure_test.c mode 100644
@@ -1,108 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0-or-later
2 - /*
3 - * The root of an empty mount namespace is a nullfs mount. Its superblock is
4 - * kernel-internal and shared by every mount namespace. It can't be
5 - * reconfigured, neither through fspick() nor through mount(MS_REMOUNT) nor
6 - * through umount() of the root which remounts it read-only.
7 - */
8 - #define _GNU_SOURCE
9 - #include <errno.h>
10 - #include <fcntl.h>
11 - #include <sched.h>
12 - #include <stdio.h>
13 - #include <string.h>
14 - #include <sys/mount.h>
15 - #include <sys/statfs.h>
16 - #include <sys/statvfs.h>
17 - #include <sys/syscall.h>
18 - #include <sys/vfs.h>
19 - #include <sys/wait.h>
20 - #include <unistd.h>
21 -
22 - #include "../utils.h"
23 - #include "../wrappers.h"
24 - #include "empty_mntns.h"
25 - #include "kselftest_harness.h"
26 -
27 - #ifndef __NR_fspick
28 - #define __NR_fspick 433
29 - #endif
30 -
31 - static int sys_fspick(int dfd, const char *path, unsigned int flags)
32 - {
33 - return syscall(__NR_fspick, dfd, path, flags);
34 - }
35 -
36 - /* Child exit codes. */
37 - enum {
38 - CHILD_OK,
39 - CHILD_USERNS, /* could not create the user namespace */
40 - CHILD_UNSHARE, /* could not create the empty mount namespace */
41 - CHILD_FSPICK, /* fspick() of the root was not refused with EINVAL */
42 - CHILD_REMOUNT, /* mount(MS_REMOUNT) was not refused with EINVAL */
43 - CHILD_UMOUNT, /* umount() of the root succeeded */
44 - CHILD_STATFS, /* statfs() of the root failed */
45 - CHILD_RDONLY, /* the root ended up read-only */
46 - };
47 -
48 - static int empty_mntns_child(void)
49 - {
50 - struct statfs st;
51 -
52 - if (enter_userns())
53 - return CHILD_USERNS;
54 - if (unshare(UNSHARE_EMPTY_MNTNS))
55 - return CHILD_UNSHARE;
56 -
57 - if (sys_fspick(AT_FDCWD, "/", 0) >= 0 || errno != EINVAL)
58 - return CHILD_FSPICK;
59 - if (!mount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL) ||
60 - errno != EINVAL)
61 - return CHILD_REMOUNT;
62 - if (!umount2("/", 0))
63 - return CHILD_UMOUNT;
64 - if (statfs("/", &st))
65 - return CHILD_STATFS;
66 - if (st.f_flags & ST_RDONLY)
67 - return CHILD_RDONLY;
68 - return CHILD_OK;
69 - }
70 -
71 - FIXTURE(internal_sb_reconfigure) {};
72 -
73 - FIXTURE_SETUP(internal_sb_reconfigure)
74 - {
75 - pid_t pid;
76 - int status;
77 -
78 - pid = fork();
79 - ASSERT_GE(pid, 0);
80 - if (pid == 0) {
81 - if (enter_userns())
82 - _exit(1);
83 - if (unshare(UNSHARE_EMPTY_MNTNS))
84 - _exit(1);
85 - _exit(0);
86 - }
87 - ASSERT_EQ(waitpid(pid, &status, 0), pid);
88 - if (!WIFEXITED(status) || WEXITSTATUS(status))
89 - SKIP(return, "UNSHARE_EMPTY_MNTNS not supported");
90 - }
91 -
92 - FIXTURE_TEARDOWN(internal_sb_reconfigure) {}
93 -
94 - TEST_F(internal_sb_reconfigure, nullfs_root)
95 - {
96 - pid_t pid;
97 - int status;
98 -
99 - pid = fork();
100 - ASSERT_GE(pid, 0);
101 - if (pid == 0)
102 - _exit(empty_mntns_child());
103 - ASSERT_EQ(waitpid(pid, &status, 0), pid);
104 - ASSERT_TRUE(WIFEXITED(status));
105 - ASSERT_EQ(WEXITSTATUS(status), CHILD_OK);
106 - }
107 -
108 - TEST_HARNESS_MAIN
deleted tools/testing/selftests/filesystems/empty_mntns/nullfs_atime_test.c mode 100644
@@ -1,129 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * The root of every empty mount namespace is the same nullfs inode. A read
4 - * of it by one user must not change the access time another user sees.
5 - */
6 - #define _GNU_SOURCE
7 - #include <dirent.h>
8 - #include <errno.h>
9 - #include <fcntl.h>
10 - #include <sched.h>
11 - #include <stdio.h>
12 - #include <stdlib.h>
13 - #include <string.h>
14 - #include <unistd.h>
15 - #include <sys/stat.h>
16 - #include <sys/wait.h>
17 -
18 - #include "../../kselftest_harness.h"
19 -
20 - #ifndef UNSHARE_EMPTY_MNTNS
21 - #define UNSHARE_EMPTY_MNTNS 0x00100000
22 - #endif
23 -
24 - enum {
25 - CHILD_OK,
26 - CHILD_UNSUPPORTED,
27 - CHILD_SETUP,
28 - CHILD_CHANGED,
29 - };
30 -
31 - static int wait_byte(int fd)
32 - {
33 - char c;
34 -
35 - return read(fd, &c, 1) == 1 ? 0 : -1;
36 - }
37 -
38 - static int send_byte(int fd)
39 - {
40 - return write(fd, "x", 1) == 1 ? 0 : -1;
41 - }
42 -
43 - static int empty_mntns(void)
44 - {
45 - if (!unshare(UNSHARE_EMPTY_MNTNS))
46 - return 0;
47 - return errno == EINVAL ? CHILD_UNSUPPORTED : CHILD_SETUP;
48 - }
49 -
50 - /* the watcher: stats its root before and after the reader read its own */
51 - static int watcher(int to_reader, int from_reader)
52 - {
53 - struct stat before, after;
54 - int ret;
55 -
56 - ret = empty_mntns();
57 - if (ret)
58 - return ret;
59 - if (stat("/", &before))
60 - return CHILD_SETUP;
61 - if (send_byte(to_reader) || wait_byte(from_reader))
62 - return CHILD_SETUP;
63 - if (stat("/", &after))
64 - return CHILD_SETUP;
65 - if (before.st_atim.tv_sec != after.st_atim.tv_sec ||
66 - before.st_atim.tv_nsec != after.st_atim.tv_nsec)
67 - return CHILD_CHANGED;
68 - return CHILD_OK;
69 - }
70 -
71 - /* the reader: lists its own root, which is the same inode */
72 - static int reader(int to_watcher, int from_watcher)
73 - {
74 - struct dirent *de;
75 - DIR *d;
76 - int ret;
77 -
78 - ret = empty_mntns();
79 - if (ret)
80 - return ret;
81 - if (wait_byte(from_watcher))
82 - return CHILD_SETUP;
83 - d = opendir("/");
84 - if (!d)
85 - return CHILD_SETUP;
86 - while ((de = readdir(d)))
87 - ;
88 - closedir(d);
89 - return send_byte(to_watcher) ? CHILD_SETUP : CHILD_OK;
90 - }
91 -
92 - static int wait_child(pid_t pid)
93 - {
94 - int status;
95 -
96 - if (waitpid(pid, &status, 0) != pid || !WIFEXITED(status))
97 - return -1;
98 - return WEXITSTATUS(status);
99 - }
100 -
101 - TEST(empty_mntns_root_atime)
102 - {
103 - int to_reader[2], to_watcher[2], w, r;
104 - pid_t watcher_pid, reader_pid;
105 -
106 - if (geteuid())
107 - SKIP(return, "test requires root");
108 - ASSERT_EQ(pipe(to_reader), 0);
109 - ASSERT_EQ(pipe(to_watcher), 0);
110 -
111 - watcher_pid = fork();
112 - ASSERT_GE(watcher_pid, 0);
113 - if (watcher_pid == 0)
114 - _exit(watcher(to_reader[1], to_watcher[0]));
115 - reader_pid = fork();
116 - ASSERT_GE(reader_pid, 0);
117 - if (reader_pid == 0)
118 - _exit(reader(to_watcher[1], to_reader[0]));
119 -
120 - r = wait_child(reader_pid);
121 - w = wait_child(watcher_pid);
122 - if (r == CHILD_UNSUPPORTED || w == CHILD_UNSUPPORTED)
123 - SKIP(return, "UNSHARE_EMPTY_MNTNS not supported");
124 - EXPECT_EQ(r, CHILD_OK);
125 - EXPECT_EQ(w, CHILD_OK)
126 - TH_LOG("the access time of the root changed while this namespace did nothing");
127 - }
128 -
129 - TEST_HARNESS_MAIN
deleted tools/testing/selftests/filesystems/empty_mntns/root_readdir_test.c mode 100644
@@ -1,45 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * Reading the root of an empty mount namespace holds nothing that anybody
4 - * else waits for: the directory never has an entry, so a readdir stuck in
5 - * the page fault of its buffer stalls neither a create nor a lookup in it.
6 - */
7 - #define _GNU_SOURCE
8 - #include <errno.h>
9 - #include <fcntl.h>
10 - #include <sched.h>
11 - #include <stdio.h>
12 - #include <stdlib.h>
13 - #include <unistd.h>
14 -
15 - #include "../../kselftest_harness.h"
16 - #include "../readdir_hold.h"
17 - #include "empty_mntns.h"
18 -
19 - TEST(readdir_blocks_nobody)
20 - {
21 - struct readdir_hold hold;
22 - bool stalled;
23 - int dfd;
24 -
25 - if (geteuid())
26 - SKIP(return, "test requires root");
27 - if (readdir_hold_init(&hold))
28 - SKIP(return, "test requires userfaultfd");
29 - if (unshare(UNSHARE_EMPTY_MNTNS)) {
30 - readdir_hold_destroy(&hold);
31 - if (errno == EINVAL)
32 - SKIP(return, "UNSHARE_EMPTY_MNTNS not supported");
33 - ASSERT_TRUE(false)
34 - TH_LOG("unshare(UNSHARE_EMPTY_MNTNS): %m");
35 - }
36 - dfd = open("/", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
37 - ASSERT_GE(dfd, 0);
38 - ASSERT_EQ(readdir_hold_check(&hold, dfd, &stalled), 0);
39 - /* the lookup came back while the readdir was stuck in its fault */
40 - EXPECT_FALSE(stalled);
41 - close(dfd);
42 - readdir_hold_destroy(&hold);
43 - }
44 -
45 - TEST_HARNESS_MAIN
deleted tools/testing/selftests/filesystems/mntns_unbindable/Makefile mode 100644
@@ -1,6 +0,0 @@
1 - # SPDX-License-Identifier: GPL-2.0
2 - TEST_GEN_PROGS := mntns_unbindable_test
3 -
4 - CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES)
5 -
6 - include ../../lib.mk
deleted tools/testing/selftests/filesystems/mntns_unbindable/mntns_unbindable_test.c mode 100644
@@ -1,227 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * An unbindable mount stays unbindable in a cloned mount namespace.
4 - */
5 - #define _GNU_SOURCE
6 - #include <errno.h>
7 - #include <fcntl.h>
8 - #include <sched.h>
9 - #include <stdio.h>
10 - #include <stdlib.h>
11 - #include <string.h>
12 - #include <sys/mount.h>
13 - #include <sys/stat.h>
14 - #include <sys/syscall.h>
15 - #include <sys/wait.h>
16 - #include <unistd.h>
17 -
18 - #include "../../kselftest_harness.h"
19 -
20 - #ifndef OPEN_TREE_CLONE
21 - #define OPEN_TREE_CLONE 1
22 - #endif
23 - #ifndef OPEN_TREE_CLOEXEC
24 - #define OPEN_TREE_CLOEXEC O_CLOEXEC
25 - #endif
26 -
27 - static int sys_open_tree(int dfd, const char *filename, unsigned int flags)
28 - {
29 - return syscall(__NR_open_tree, dfd, filename, flags);
30 - }
31 -
32 - /* Child exit codes. */
33 - enum {
34 - CHILD_OK, /* the operation failed with EINVAL as it must */
35 - CHILD_ALLOWED, /* the operation succeeded: the flag was lost */
36 - CHILD_UNSHARE, /* unshare(CLONE_NEWNS) failed */
37 - CHILD_ERRNO, /* the operation failed with some other errno */
38 - CHILD_MOUNTINFO, /* the mount was not found in mountinfo */
39 - };
40 -
41 - FIXTURE(mntns_unbindable)
42 - {
43 - char base[64];
44 - char src[80];
45 - char dst[80];
46 - bool mounted;
47 - };
48 -
49 - FIXTURE_SETUP(mntns_unbindable)
50 - {
51 - self->mounted = false;
52 -
53 - if (geteuid() != 0)
54 - SKIP(return, "test requires CAP_SYS_ADMIN");
55 -
56 - ASSERT_EQ(unshare(CLONE_NEWNS), 0);
57 - ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
58 -
59 - snprintf(self->base, sizeof(self->base), "/tmp/mntns_unbindable.XXXXXX");
60 - ASSERT_NE(mkdtemp(self->base), NULL);
61 - ASSERT_EQ(mount("tmpfs", self->base, "tmpfs", 0, NULL), 0);
62 - self->mounted = true;
63 -
64 - snprintf(self->src, sizeof(self->src), "%s/src", self->base);
65 - snprintf(self->dst, sizeof(self->dst), "%s/dst", self->base);
66 - ASSERT_EQ(mkdir(self->src, 0755), 0);
67 - ASSERT_EQ(mkdir(self->dst, 0755), 0);
68 -
69 - ASSERT_EQ(mount("tmpfs", self->src, "tmpfs", 0, NULL), 0);
70 - ASSERT_EQ(mount(NULL, self->src, NULL, MS_UNBINDABLE, NULL), 0);
71 - }
72 -
73 - FIXTURE_TEARDOWN(mntns_unbindable)
74 - {
75 - if (self->mounted)
76 - umount2(self->base, MNT_DETACH);
77 - rmdir(self->base);
78 - }
79 -
80 - static int classify(int ret, int err)
81 - {
82 - if (ret >= 0)
83 - return CHILD_ALLOWED;
84 - return err == EINVAL ? CHILD_OK : CHILD_ERRNO;
85 - }
86 -
87 - /* Is the mount on @mountpoint marked unbindable in /proc/self/mountinfo? */
88 - static int mountinfo_unbindable(const char *mountpoint)
89 - {
90 - char line[4096];
91 - FILE *f;
92 - int ret = CHILD_MOUNTINFO;
93 -
94 - f = fopen("/proc/self/mountinfo", "re");
95 - if (!f)
96 - return CHILD_ERRNO;
97 -
98 - while (fgets(line, sizeof(line), f)) {
99 - char *fields[6], *p = line, *opt;
100 - int i;
101 -
102 - for (i = 0; i < 6; i++) {
103 - fields[i] = strsep(&p, " ");
104 - if (!fields[i])
105 - break;
106 - }
107 - if (i < 6 || strcmp(fields[4], mountpoint))
108 - continue;
109 -
110 - /* the optional fields, up to the "-" separator */
111 - ret = CHILD_ALLOWED;
112 - while ((opt = strsep(&p, " ")) && strcmp(opt, "-")) {
113 - if (!strcmp(opt, "unbindable"))
114 - ret = CHILD_OK;
115 - }
116 - break;
117 - }
118 - fclose(f);
119 - return ret;
120 - }
121 -
122 - static int run_in_child(int (*fn)(const char *src, const char *dst),
123 - const char *src, const char *dst)
124 - {
125 - int status;
126 - pid_t pid;
127 -
128 - pid = fork();
129 - if (pid < 0)
130 - return -1;
131 - if (pid == 0)
132 - _exit(fn(src, dst));
133 - if (waitpid(pid, &status, 0) != pid || !WIFEXITED(status))
134 - return -1;
135 - return WEXITSTATUS(status);
136 - }
137 -
138 - static int bind_after_clone(const char *src, const char *dst)
139 - {
140 - int ret;
141 -
142 - if (unshare(CLONE_NEWNS))
143 - return CHILD_UNSHARE;
144 - ret = mount(src, dst, NULL, MS_BIND, NULL);
145 - return classify(ret, errno);
146 - }
147 -
148 - static int rbind_after_clone(const char *src, const char *dst)
149 - {
150 - int ret;
151 -
152 - if (unshare(CLONE_NEWNS))
153 - return CHILD_UNSHARE;
154 - ret = mount(src, dst, NULL, MS_BIND | MS_REC, NULL);
155 - return classify(ret, errno);
156 - }
157 -
158 - static int open_tree_after_clone(const char *src, const char *dst)
159 - {
160 - int ret;
161 -
162 - if (unshare(CLONE_NEWNS))
163 - return CHILD_UNSHARE;
164 - ret = sys_open_tree(AT_FDCWD, src, OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC);
165 - return classify(ret, errno);
166 - }
167 -
168 - static int mountinfo_after_clone(const char *src, const char *dst)
169 - {
170 - if (unshare(CLONE_NEWNS))
171 - return CHILD_UNSHARE;
172 - return mountinfo_unbindable(src);
173 - }
174 -
175 - static int bind_after_two_clones(const char *src, const char *dst)
176 - {
177 - int ret;
178 -
179 - if (unshare(CLONE_NEWNS))
180 - return CHILD_UNSHARE;
181 - if (unshare(CLONE_NEWNS))
182 - return CHILD_UNSHARE;
183 - ret = mount(src, dst, NULL, MS_BIND, NULL);
184 - return classify(ret, errno);
185 - }
186 -
187 - /* The namespace the mount was made unbindable in. */
188 - TEST_F(mntns_unbindable, refuses_bind)
189 - {
190 - int ret = mount(self->src, self->dst, NULL, MS_BIND, NULL);
191 -
192 - ASSERT_EQ(classify(ret, errno), CHILD_OK);
193 - ASSERT_EQ(mountinfo_unbindable(self->src), CHILD_OK);
194 - }
195 -
196 - /* A copy of the namespace must not turn the mount bindable. */
197 - TEST_F(mntns_unbindable, refuses_bind_after_clone)
198 - {
199 - ASSERT_EQ(run_in_child(bind_after_clone, self->src, self->dst), CHILD_OK)
200 - TH_LOG("bind of an unbindable mount allowed in a copied mount namespace");
201 - }
202 -
203 - TEST_F(mntns_unbindable, refuses_rbind_after_clone)
204 - {
205 - ASSERT_EQ(run_in_child(rbind_after_clone, self->src, self->dst), CHILD_OK)
206 - TH_LOG("rbind of an unbindable mount allowed in a copied mount namespace");
207 - }
208 -
209 - TEST_F(mntns_unbindable, refuses_open_tree_after_clone)
210 - {
211 - ASSERT_EQ(run_in_child(open_tree_after_clone, self->src, self->dst), CHILD_OK)
212 - TH_LOG("OPEN_TREE_CLONE of an unbindable mount allowed in a copied mount namespace");
213 - }
214 -
215 - TEST_F(mntns_unbindable, mountinfo_after_clone)
216 - {
217 - ASSERT_EQ(run_in_child(mountinfo_after_clone, self->src, self->dst), CHILD_OK)
218 - TH_LOG("mountinfo does not show the mount as unbindable in a copied mount namespace");
219 - }
220 -
221 - TEST_F(mntns_unbindable, refuses_bind_after_two_clones)
222 - {
223 - ASSERT_EQ(run_in_child(bind_after_two_clones, self->src, self->dst), CHILD_OK)
224 - TH_LOG("bind of an unbindable mount allowed two mount namespace copies down");
225 - }
226 -
227 - TEST_HARNESS_MAIN
deleted tools/testing/selftests/filesystems/mount_cycle/.gitignore mode 100644
@@ -1,8 +0,0 @@
1 - # SPDX-License-Identifier: GPL-2.0-only
2 - loop_cycle_test
3 - unmounted_tree_test
4 - overmount_reparent_test
5 - mount_cover_test
6 - locked_handle_test
7 - nsfs_rbind_loop_test
8 - overmount_ns_file_test
deleted tools/testing/selftests/filesystems/mount_cycle/Makefile mode 100644
@@ -1,12 +0,0 @@
1 - # SPDX-License-Identifier: GPL-2.0
2 - TEST_GEN_PROGS := loop_cycle_test unmounted_tree_test overmount_reparent_test mount_cover_test locked_handle_test
3 - TEST_GEN_PROGS += nsfs_rbind_loop_test overmount_ns_file_test
4 -
5 - CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES)
6 -
7 - LOCAL_HDRS += ../readdir_hold.h
8 -
9 - include ../../lib.mk
10 -
11 - $(OUTPUT)/locked_handle_test: LDLIBS += -pthread
12 - $(OUTPUT)/mount_cover_test: LDLIBS += -pthread
deleted tools/testing/selftests/filesystems/mount_cycle/config mode 100644
@@ -1,39 +0,0 @@
1 - CONFIG_USER_NS=y
2 - CONFIG_TMPFS=y
3 - CONFIG_BLK_DEV_LOOP=y
4 - CONFIG_VFAT_FS=y
5 - CONFIG_MSDOS_FS=y
6 - CONFIG_NLS_CODEPAGE_437=y
7 - CONFIG_NLS_ISO8859_1=y
8 - CONFIG_MINIX_FS=y
9 - CONFIG_AUTOFS_FS=y
10 - CONFIG_ZRAM=y
11 - CONFIG_ZRAM_WRITEBACK=y
12 - CONFIG_KEYS=y
13 - CONFIG_ECRYPT_FS=y
14 - CONFIG_BINFMT_MISC=y
15 - CONFIG_FUSE_FS=y
16 - CONFIG_FUSE_PASSTHROUGH=y
17 - CONFIG_BLK_DEV_ZONED=y
18 - CONFIG_BLK_DEV_ZONED_LOOP=y
19 - CONFIG_CONFIGFS_FS=y
20 - CONFIG_USB_SUPPORT=y
21 - CONFIG_USB=y
22 - CONFIG_USB_STORAGE=y
23 - CONFIG_SCSI=y
24 - CONFIG_BLK_DEV_SD=y
25 - CONFIG_USB_GADGET=y
26 - CONFIG_USB_DUMMY_HCD=y
27 - CONFIG_USB_CONFIGFS=y
28 - CONFIG_USB_CONFIGFS_MASS_STORAGE=y
29 - CONFIG_MD=y
30 - CONFIG_BLK_DEV_MD=y
31 - CONFIG_MD_RAID1=y
32 - CONFIG_MD_BITMAP=y
33 - CONFIG_MD_BITMAP_FILE=y
34 - CONFIG_INOTIFY_USER=y
35 - CONFIG_DNOTIFY=y
36 - CONFIG_FANOTIFY=y
37 - CONFIG_FILE_LOCKING=y
38 - CONFIG_CRYPTO_AES=y
39 - CONFIG_USERFAULTFD=y
deleted tools/testing/selftests/filesystems/mount_cycle/locked_handle_test.c mode 100644
@@ -1,377 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * may_decode_fh() refuses a file handle below a mount with locked children
4 - * to root in a user namespace. That has to hold while the mount is lazily
5 - * unmounted and its children, the locked ones too, are taken off it.
6 - */
7 - #define _GNU_SOURCE
8 - #include <errno.h>
9 - #include <fcntl.h>
10 - #include <pthread.h>
11 - #include <sched.h>
12 - #include <stdatomic.h>
13 - #include <stdbool.h>
14 - #include <stdio.h>
15 - #include <stdlib.h>
16 - #include <string.h>
17 - #include <unistd.h>
18 - #include <sys/mount.h>
19 - #include <sys/prctl.h>
20 - #include <sys/stat.h>
21 - #include <sys/syscall.h>
22 - #include <sys/wait.h>
23 -
24 - #include "../../kselftest_harness.h"
25 -
26 - #ifndef OPEN_TREE_CLONE
27 - #define OPEN_TREE_CLONE 1
28 - #endif
29 - #ifndef OPEN_TREE_CLOEXEC
30 - #define OPEN_TREE_CLOEXEC O_CLOEXEC
31 - #endif
32 - #ifndef AT_RECURSIVE
33 - #define AT_RECURSIVE 0x8000
34 - #endif
35 -
36 - #define DIR_LEN 64
37 - #define PATH_LEN 128
38 -
39 - #define ROUNDS 100 /* lazy umounts raced per test */
40 - #define RACERS 3 /* threads in open_by_handle_at() */
41 - #define EXTRA_MOUNTS 64 /* make umount_tree() hold mount_lock longer */
42 - #define MAX_DELAY_US 3000 /* before the umount */
43 - #define TAIL_US 2000 /* after it */
44 -
45 - struct handle {
46 - struct file_handle fh;
47 - unsigned char buf[MAX_HANDLE_SZ];
48 - };
49 -
50 - /* exit codes of the child */
51 - enum {
52 - CHILD_OK,
53 - CHILD_SETUP,
54 - CHILD_DECODED, /* decoded past a locked child */
55 - CHILD_MOUNTED, /* not refused while mounted */
56 - CHILD_UNMOUNTED, /* not refused once unmounted */
57 - CHILD_ALLOWED, /* refused where nothing is locked */
58 - CHILD_NOUSERNS, /* no user namespace to be had */
59 - };
60 -
61 - static int write_file(const char *path, const char *s)
62 - {
63 - ssize_t n = -1;
64 - int fd;
65 -
66 - fd = open(path, O_WRONLY | O_CLOEXEC);
67 - if (fd >= 0) {
68 - n = write(fd, s, strlen(s));
69 - close(fd);
70 - }
71 - return n == (ssize_t)strlen(s) ? 0 : -1;
72 - }
73 -
74 - /* Become root in a new user namespace with a private mount namespace. */
75 - static int enter_userns(void)
76 - {
77 - uid_t uid = getuid();
78 - gid_t gid = getgid();
79 - char map[32];
80 -
81 - prctl(PR_SET_DUMPABLE, 1);
82 - /* EINVAL: no USER_NS, ENOSPC: user.max_user_namespaces is 0, EPERM: an LSM */
83 - if (unshare(CLONE_NEWUSER | CLONE_NEWNS))
84 - return errno == EINVAL || errno == ENOSPC || errno == EPERM ?
85 - CHILD_NOUSERNS : CHILD_SETUP;
86 - if (write_file("/proc/self/setgroups", "deny") && errno != ENOENT)
87 - return CHILD_SETUP;
88 - snprintf(map, sizeof(map), "0 %d 1", uid);
89 - if (write_file("/proc/self/uid_map", map))
90 - return CHILD_SETUP;
91 - snprintf(map, sizeof(map), "0 %d 1", gid);
92 - if (write_file("/proc/self/gid_map", map))
93 - return CHILD_SETUP;
94 - if (setgid(0) || setuid(0))
95 - return CHILD_SETUP;
96 - if (mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL))
97 - return CHILD_SETUP;
98 - return CHILD_OK;
99 - }
100 -
101 - static int get_handle(const char *path, struct handle *h)
102 - {
103 - int mntid;
104 -
105 - h->fh.handle_bytes = MAX_HANDLE_SZ;
106 - return name_to_handle_at(AT_FDCWD, path, &h->fh, &mntid, 0);
107 - }
108 -
109 - static int decode(int dfd, struct handle *h)
110 - {
111 - return open_by_handle_at(dfd, &h->fh, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
112 - }
113 -
114 - struct race {
115 - int dfd;
116 - struct handle *h;
117 - atomic_int go;
118 - atomic_int stop;
119 - atomic_int won; /* the first decoded descriptor */
120 - };
121 -
122 - static void *racer(void *arg)
123 - {
124 - struct race *r = arg;
125 -
126 - while (!atomic_load(&r->go))
127 - ;
128 - while (!atomic_load(&r->stop)) {
129 - int none = -1;
130 - int fd;
131 -
132 - fd = decode(r->dfd, r->h);
133 - if (fd < 0)
134 - continue;
135 - if (!atomic_compare_exchange_strong(&r->won, &none, fd))
136 - close(fd);
137 - }
138 - return NULL;
139 - }
140 -
141 - /* stop the @n racers started so far and wait for them, they spin on @r */
142 - static void stop_racers(struct race *r, pthread_t *th, int n)
143 - {
144 - int i;
145 -
146 - atomic_store(&r->stop, 1);
147 - atomic_store(&r->go, 1); /* one still waiting for the start sees stop next */
148 - for (i = 0; i < n; i++)
149 - pthread_join(th[i], NULL);
150 - }
151 -
152 - /*
153 - * Bind @h recursively at @w, or take a detached copy of it, and race
154 - * open_by_handle_at() of @inner against the lazy umount. The decoded
155 - * descriptor, if there was one, is left in @won.
156 - */
157 - static int race_round(const char *h, const char *w, struct handle *inner,
158 - bool dissolve, int *won)
159 - {
160 - struct race r = { .h = inner, .won = -1 };
161 - pthread_t th[RACERS];
162 - int treefd = -1, fd, i;
163 -
164 - if (dissolve) {
165 - treefd = syscall(__NR_open_tree, AT_FDCWD, h,
166 - OPEN_TREE_CLONE | AT_RECURSIVE | OPEN_TREE_CLOEXEC);
167 - if (treefd < 0)
168 - return CHILD_SETUP;
169 - /* an ordinary descriptor on the copy, treefd's close dissolves it */
170 - r.dfd = openat(treefd, ".", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
171 - } else {
172 - if (mount(h, w, NULL, MS_BIND | MS_REC, NULL))
173 - return CHILD_SETUP;
174 - r.dfd = open(w, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
175 - }
176 - if (r.dfd < 0)
177 - return CHILD_SETUP;
178 -
179 - fd = decode(r.dfd, inner);
180 - if (fd >= 0 || errno != EPERM) {
181 - if (fd >= 0)
182 - close(fd);
183 - return CHILD_MOUNTED;
184 - }
185 -
186 - for (i = 0; i < RACERS; i++) {
187 - if (pthread_create(&th[i], NULL, racer, &r)) {
188 - stop_racers(&r, th, i);
189 - return CHILD_SETUP;
190 - }
191 - }
192 - atomic_store(&r.go, 1);
193 - usleep(rand() % MAX_DELAY_US);
194 - if (dissolve)
195 - close(treefd);
196 - else if (umount2(w, MNT_DETACH)) {
197 - stop_racers(&r, th, RACERS);
198 - return CHILD_SETUP;
199 - }
200 - usleep(TAIL_US);
201 - stop_racers(&r, th, RACERS);
202 -
203 - fd = decode(r.dfd, inner);
204 - if (fd >= 0) {
205 - close(fd);
206 - return CHILD_UNMOUNTED;
207 - }
208 - close(r.dfd);
209 - *won = atomic_load(&r.won);
210 - return CHILD_OK;
211 - }
212 -
213 - static int race_child(const char *h, const char *w, struct handle *inner,
214 - bool dissolve)
215 - {
216 - int ret, won, i;
217 -
218 - srand(getpid());
219 - ret = enter_userns();
220 - if (ret)
221 - return ret;
222 - for (i = 0; i < ROUNDS; i++) {
223 - ret = race_round(h, w, inner, dissolve, &won);
224 - if (ret)
225 - return ret;
226 - if (won >= 0)
227 - return CHILD_DECODED;
228 - }
229 - return CHILD_OK;
230 - }
231 -
232 - /* a bind without locked children decodes while mounted and not after */
233 - static int allowed_child(const char *plain, const char *w, struct handle *h)
234 - {
235 - int dfd, fd, ret;
236 -
237 - ret = enter_userns();
238 - if (ret)
239 - return ret;
240 - if (mount(plain, w, NULL, MS_BIND | MS_REC, NULL))
241 - return CHILD_SETUP;
242 - dfd = open(w, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
243 - if (dfd < 0)
244 - return CHILD_SETUP;
245 - fd = decode(dfd, h);
246 - if (fd < 0)
247 - return CHILD_ALLOWED;
248 - close(fd);
249 - if (umount2(w, MNT_DETACH))
250 - return CHILD_SETUP;
251 - fd = decode(dfd, h);
252 - if (fd >= 0) {
253 - close(fd);
254 - return CHILD_UNMOUNTED;
255 - }
256 - return errno == EPERM ? CHILD_OK : CHILD_UNMOUNTED;
257 - }
258 -
259 - FIXTURE(locked_handle) {
260 - char base[DIR_LEN];
261 - char h[PATH_LEN]; /* the tree with the covered directory */
262 - char plain[PATH_LEN]; /* a tree with no mount in it */
263 - char w[PATH_LEN]; /* where the child binds either */
264 - struct handle inner; /* h/top/secret/inner, covered */
265 - struct handle uncovered; /* plain/inner */
266 - };
267 -
268 - FIXTURE_SETUP(locked_handle)
269 - {
270 - char p[PATH_LEN], e[PATH_LEN];
271 - int i;
272 -
273 - if (geteuid())
274 - SKIP(return, "test requires root");
275 -
276 - snprintf(self->base, sizeof(self->base), "/tmp/locked_handle.XXXXXX");
277 - ASSERT_NE(mkdtemp(self->base), NULL);
278 - ASSERT_EQ(unshare(CLONE_NEWNS), 0);
279 - ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
280 - ASSERT_EQ(mount("tmpfs", self->base, "tmpfs", 0, NULL), 0);
281 -
282 - snprintf(self->h, sizeof(self->h), "%s/h", self->base);
283 - snprintf(self->plain, sizeof(self->plain), "%s/plain", self->base);
284 - snprintf(self->w, sizeof(self->w), "%s/w", self->base);
285 - ASSERT_EQ(mkdir(self->h, 0755), 0);
286 - ASSERT_EQ(mkdir(self->plain, 0755), 0);
287 - ASSERT_EQ(mkdir(self->w, 0755), 0);
288 - snprintf(p, sizeof(p), "%s/plain/inner", self->base);
289 - ASSERT_EQ(mkdir(p, 0755), 0);
290 - ASSERT_EQ(get_handle(p, &self->uncovered), 0);
291 -
292 - /* the handle is for this filesystem */
293 - ASSERT_EQ(mount("tmpfs", self->h, "tmpfs", 0, NULL), 0);
294 - snprintf(p, sizeof(p), "%s/h/top", self->base);
295 - ASSERT_EQ(mkdir(p, 0755), 0);
296 - snprintf(p, sizeof(p), "%s/h/top/secret", self->base);
297 - ASSERT_EQ(mkdir(p, 0755), 0);
298 - snprintf(p, sizeof(p), "%s/h/top/secret/inner", self->base);
299 - ASSERT_EQ(mkdir(p, 0755), 0);
300 - ASSERT_EQ(get_handle(p, &self->inner), 0);
301 - snprintf(e, sizeof(e), "%s/h/empty", self->base);
302 - ASSERT_EQ(mkdir(e, 0755), 0);
303 -
304 - /* cover it, and some more so the umount takes longer */
305 - snprintf(p, sizeof(p), "%s/h/top/secret", self->base);
306 - ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, NULL), 0);
307 - for (i = 0; i < EXTRA_MOUNTS; i++) {
308 - snprintf(p, sizeof(p), "%s/h/c%d", self->base, i);
309 - ASSERT_EQ(mkdir(p, 0755), 0);
310 - ASSERT_EQ(mount(e, p, NULL, MS_BIND, NULL), 0);
311 - }
312 - }
313 -
314 - FIXTURE_TEARDOWN(locked_handle)
315 - {
316 - umount2(self->base, MNT_DETACH);
317 - rmdir(self->base);
318 - }
319 -
320 - static int wait_child(pid_t pid)
321 - {
322 - int status;
323 -
324 - if (waitpid(pid, &status, 0) != pid || !WIFEXITED(status))
325 - return -1;
326 - return WEXITSTATUS(status);
327 - }
328 -
329 - TEST_F(locked_handle, lazy_umount)
330 - {
331 - pid_t pid;
332 - int ret;
333 -
334 - pid = fork();
335 - ASSERT_GE(pid, 0);
336 - if (pid == 0)
337 - _exit(race_child(self->h, self->w, &self->inner, false));
338 - ret = wait_child(pid);
339 - TH_LOG("child exit code %d", ret);
340 - if (ret == CHILD_NOUSERNS)
341 - SKIP(return, "no user namespaces");
342 - EXPECT_EQ(ret, CHILD_OK);
343 - }
344 -
345 - TEST_F(locked_handle, dissolve)
346 - {
347 - pid_t pid;
348 - int ret;
349 -
350 - pid = fork();
351 - ASSERT_GE(pid, 0);
352 - if (pid == 0)
353 - _exit(race_child(self->h, self->w, &self->inner, true));
354 - ret = wait_child(pid);
355 - TH_LOG("child exit code %d", ret);
356 - if (ret == CHILD_NOUSERNS)
357 - SKIP(return, "no user namespaces");
358 - EXPECT_EQ(ret, CHILD_OK);
359 - }
360 -
361 - TEST_F(locked_handle, allowed_use)
362 - {
363 - pid_t pid;
364 - int ret;
365 -
366 - pid = fork();
367 - ASSERT_GE(pid, 0);
368 - if (pid == 0)
369 - _exit(allowed_child(self->plain, self->w, &self->uncovered));
370 - ret = wait_child(pid);
371 - TH_LOG("child exit code %d", ret);
372 - if (ret == CHILD_NOUSERNS)
373 - SKIP(return, "no user namespaces");
374 - EXPECT_EQ(ret, CHILD_OK);
375 - }
376 -
377 - TEST_HARNESS_MAIN
deleted tools/testing/selftests/filesystems/mount_cycle/loop_cycle_test.c mode 100644
@@ -1,1542 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * A mount that another namespace's rmdir detached, or that went down with
4 - * the detached tree it was in when the tree's last fd was closed, keeps
5 - * its submounts connected, and a connected submount is put by its
6 - * parent's final mntput(). A submount whose filesystem keeps a file open
7 - * on the parent then holds the parent's count above zero for good:
8 - * nothing in userspace refers to either mount any more and nothing can
9 - * release them. A loop device is the simplest such filesystem, its
10 - * backing file sits on the parent.
11 - */
12 - #define _GNU_SOURCE
13 - #include <dirent.h>
14 - #include <errno.h>
15 - #include <fcntl.h>
16 - #include <sched.h>
17 - #include <stdio.h>
18 - #include <stdlib.h>
19 - #include <string.h>
20 - #include <sys/ioctl.h>
21 - #include <sys/mount.h>
22 - #include <sys/stat.h>
23 - #include <stdbool.h>
24 - #include <sys/wait.h>
25 - #include <unistd.h>
26 - #include <linux/fuse.h>
27 - #include <linux/keyctl.h>
28 - #include <linux/major.h>
29 - #include <linux/raid/md_u.h>
30 - #include <linux/raid/md_p.h>
31 - #include <linux/loop.h>
32 - #include <linux/magic.h>
33 - #include <sys/syscall.h>
34 - #include <sys/sysmacros.h>
35 - #include <sys/uio.h>
36 -
37 - #include "../wrappers.h"
38 - #include "../../kselftest_harness.h"
39 -
40 - #define IMAGE_SIZE (1440 * 1024)
41 - #define SECTOR 512
42 -
43 - /*
44 - * The tmpfs of the fixture. A directory of its own from mkdtemp(), so that
45 - * the test needs no writable root directory and two instances don't take
46 - * each other's mounts down.
47 - */
48 - static char base[64];
49 -
50 - /* The configfs directory of the gadget, named after the test process. */
51 - static char gadget[96];
52 -
53 - /* A path below the base directory. Eight of them can be in use at a time. */
54 - static const char *at(const char *rel)
55 - {
56 - static char buf[8][PATH_MAX];
57 - static unsigned int next;
58 - char *p = buf[next++ % 8];
59 -
60 - snprintf(p, PATH_MAX, "%s/%s", base, rel);
61 - return p;
62 - }
63 -
64 - /* A path below the gadget's configfs directory. */
65 - static const char *gat(const char *rel)
66 - {
67 - static char buf[4][PATH_MAX];
68 - static unsigned int next;
69 - char *p = buf[next++ % 4];
70 -
71 - snprintf(p, PATH_MAX, "%s%s", gadget, rel);
72 - return p;
73 - }
74 -
75 - /* The loop devices this process has bound, to release them on every path. */
76 - #define MAX_LOOPS 4
77 - static int bound[MAX_LOOPS];
78 - static int nr_bound;
79 -
80 - /* What a child tells its parent: the loop devices it has bound, -1 for none. */
81 - struct report {
82 - int n[2];
83 - };
84 -
85 - /* A blank FAT12 floppy image: boot sector, two FATs, an empty root directory. */
86 - static int write_fat12(int fd)
87 - {
88 - struct stat st;
89 - unsigned char sector[SECTOR] = {
90 - 0xeb, 0x3c, 0x90, 'M', 'S', 'W', 'I', 'N', '4', '.', '1',
91 - [11] = 0x00, 0x02, /* bytes per sector: 512 */
92 - [13] = 1, /* sectors per cluster */
93 - [14] = 1, 0, /* reserved sectors */
94 - [16] = 2, /* FATs */
95 - [17] = 0xe0, 0x00, /* root directory entries: 224 */
96 - [19] = 0x40, 0x0b, /* total sectors: 2880 */
97 - [21] = 0xf0, /* media descriptor */
98 - [22] = 9, 0, /* sectors per FAT */
99 - [24] = 18, 0, /* sectors per track */
100 - [26] = 2, 0, /* heads */
101 - [38] = 0x29, /* extended boot signature */
102 - [39] = 0x12, 0x34, 0x56, 0x78,
103 - [43] = 'N', 'O', ' ', 'N', 'A', 'M', 'E', ' ', ' ', ' ', ' ',
104 - [54] = 'F', 'A', 'T', '1', '2', ' ', ' ', ' ',
105 - [510] = 0x55, 0xaa,
106 - };
107 - unsigned char fat[SECTOR] = { 0xf0, 0xff, 0xff };
108 -
109 - if (pwrite(fd, sector, SECTOR, 0) != SECTOR)
110 - return -1;
111 - /* the first FAT and the second one, one sector each is enough */
112 - if (pwrite(fd, fat, SECTOR, 1 * SECTOR) != SECTOR ||
113 - pwrite(fd, fat, SECTOR, 10 * SECTOR) != SECTOR)
114 - return -1;
115 - if (fstat(fd, &st) || S_ISBLK(st.st_mode))
116 - return 0;
117 - return ftruncate(fd, IMAGE_SIZE);
118 - }
119 -
120 - /*
121 - * A blank FAT12 image with 4 KiB sectors and @sectors of them, for a device
122 - * with 4 KiB logical blocks (zram) or for a bigger image than a floppy.
123 - */
124 - static int write_fat12_4k(int fd, unsigned int sectors)
125 - {
126 - unsigned int fat_sectors = (sectors * 3 / 2 + 4095) / 4096;
127 - unsigned char sector[4096] = {
128 - 0xeb, 0x3c, 0x90, 'M', 'S', 'W', 'I', 'N', '4', '.', '1',
129 - [11] = 0x00, 0x10, /* bytes per sector: 4096 */
130 - [13] = 1, /* sectors per cluster */
131 - [14] = 1, 0, /* reserved sectors */
132 - [16] = 2, /* FATs */
133 - [17] = 128, 0, /* root directory entries: one sector */
134 - [19] = sectors & 0xff, sectors >> 8,
135 - [21] = 0xf8, /* media descriptor */
136 - [22] = fat_sectors, 0,
137 - [24] = 63, 0, /* sectors per track */
138 - [26] = 255, 0, /* heads */
139 - [38] = 0x29, /* extended boot signature */
140 - [39] = 0x12, 0x34, 0x56, 0x78,
141 - [43] = 'N', 'O', ' ', 'N', 'A', 'M', 'E', ' ', ' ', ' ', ' ',
142 - [54] = 'F', 'A', 'T', '1', '2', ' ', ' ', ' ',
143 - [510] = 0x55, 0xaa,
144 - };
145 - unsigned char fat[4096] = { 0xf8, 0xff, 0xff };
146 - struct stat st;
147 -
148 - if (pwrite(fd, sector, sizeof(sector), 0) != sizeof(sector))
149 - return -1;
150 - if (pwrite(fd, fat, sizeof(fat), 1 * 4096) != sizeof(fat) ||
151 - pwrite(fd, fat, sizeof(fat), (1 + fat_sectors) * 4096) != sizeof(fat))
152 - return -1;
153 - if (fstat(fd, &st) || S_ISBLK(st.st_mode))
154 - return 0;
155 - return ftruncate(fd, (off_t)sectors * 4096);
156 - }
157 -
158 - #define MINIX_BLOCK 1024
159 - #define MINIX_BLOCKS 4096 /* a 4 MiB image */
160 - #define MINIX_INODES 512
161 - #define MINIX_ITABLE (MINIX_INODES * 32 / MINIX_BLOCK)
162 - #define MINIX_FIRSTDATA (2 + 1 + 1 + MINIX_ITABLE) /* boot, super, imap, zmap, inodes */
163 -
164 - /*
165 - * A blank minix v1 image, for the holders that need a FIFO or a device
166 - * node on the dying mount, which vfat can't hold. Superblock in block 1,
167 - * one block each for the inode and zone bitmaps, the inode table, and
168 - * the root directory in the first data zone.
169 - */
170 - static int write_minix(int fd)
171 - {
172 - struct {
173 - __u16 s_ninodes, s_nzones, s_imap_blocks, s_zmap_blocks;
174 - __u16 s_firstdatazone, s_log_zone_size;
175 - __u32 s_max_size;
176 - __u16 s_magic, s_state;
177 - } sb = {
178 - .s_ninodes = MINIX_INODES,
179 - .s_nzones = MINIX_BLOCKS,
180 - .s_imap_blocks = 1,
181 - .s_zmap_blocks = 1,
182 - .s_firstdatazone = MINIX_FIRSTDATA,
183 - .s_max_size = (7 + 512 + 512 * 512) * MINIX_BLOCK,
184 - .s_magic = MINIX_SUPER_MAGIC,
185 - .s_state = 1, /* MINIX_VALID_FS */
186 - };
187 - struct {
188 - __u16 i_mode, i_uid;
189 - __u32 i_size, i_time;
190 - __u8 i_gid, i_nlinks;
191 - __u16 i_zone[9];
192 - } root = {
193 - .i_mode = S_IFDIR | 0755,
194 - .i_size = 2 * 16,
195 - .i_nlinks = 2,
196 - .i_zone = { MINIX_FIRSTDATA },
197 - };
198 - unsigned char imap[MINIX_BLOCK], zmap[MINIX_BLOCK], dir[MINIX_BLOCK] = {};
199 - int i;
200 -
201 - /* bit 0 is reserved in both maps, the root inode and its zone are in use */
202 - memset(imap, 0xff, sizeof(imap));
203 - for (i = 2; i <= MINIX_INODES; i++)
204 - imap[i / 8] &= ~(1 << (i % 8));
205 - memset(zmap, 0xff, sizeof(zmap));
206 - for (i = 2; i <= MINIX_BLOCKS - MINIX_FIRSTDATA; i++)
207 - zmap[i / 8] &= ~(1 << (i % 8));
208 - dir[0] = 1;
209 - dir[2] = '.';
210 - dir[16] = 1;
211 - dir[18] = '.';
212 - dir[19] = '.';
213 -
214 - if (pwrite(fd, &sb, sizeof(sb), 1 * MINIX_BLOCK) != sizeof(sb) ||
215 - pwrite(fd, imap, sizeof(imap), 2 * MINIX_BLOCK) != sizeof(imap) ||
216 - pwrite(fd, zmap, sizeof(zmap), 3 * MINIX_BLOCK) != sizeof(zmap) ||
217 - pwrite(fd, &root, sizeof(root), 4 * MINIX_BLOCK) != sizeof(root) ||
218 - pwrite(fd, dir, sizeof(dir), MINIX_FIRSTDATA * MINIX_BLOCK) != sizeof(dir))
219 - return -1;
220 - return ftruncate(fd, (off_t)MINIX_BLOCKS * MINIX_BLOCK);
221 - }
222 -
223 - static int read_sysfs(const char *path, char *buf, size_t size)
224 - {
225 - ssize_t n;
226 - int fd;
227 -
228 - fd = open(path, O_RDONLY);
229 - if (fd < 0)
230 - return -1;
231 - n = read(fd, buf, size - 1);
232 - close(fd);
233 - if (n < 0)
234 - return -1;
235 - buf[n] = '\0';
236 - return 0;
237 - }
238 -
239 - /* Is @dev the mount source of this line of mountinfo? loop1 is not loop10. */
240 - static bool line_has_source(const char *line, const char *dev)
241 - {
242 - const char *sep, *src, *end;
243 -
244 - sep = strstr(line, " - ");
245 - if (!sep)
246 - return false;
247 - src = strchr(sep + 3, ' '); /* skip the filesystem type */
248 - if (!src)
249 - return false;
250 - src++;
251 - end = strchr(src, ' ');
252 - if (!end)
253 - return false;
254 - return (size_t)(end - src) == strlen(dev) && !strncmp(src, dev, end - src);
255 - }
256 -
257 - /*
258 - * Does a mount namespace of a process that /proc shows have a mount of @dev?
259 - * The mounts under test are in no namespace at this point on any kernel, so
260 - * this only checks that the test got as far as it thinks.
261 - */
262 - static bool mounted_anywhere(const char *dev)
263 - {
264 - char path[PATH_MAX], line[4096];
265 - struct dirent *de;
266 - bool found = false;
267 - DIR *proc;
268 - FILE *f;
269 -
270 - proc = opendir("/proc");
271 - if (!proc)
272 - return false;
273 - while (!found && (de = readdir(proc))) {
274 - if (de->d_name[0] < '0' || de->d_name[0] > '9')
275 - continue;
276 - snprintf(path, sizeof(path), "/proc/%s/mountinfo", de->d_name);
277 - f = fopen(path, "re");
278 - if (!f)
279 - continue;
280 - while (fgets(line, sizeof(line), f)) {
281 - if (line_has_source(line, dev)) {
282 - found = true;
283 - break;
284 - }
285 - }
286 - fclose(f);
287 - }
288 - closedir(proc);
289 - return found;
290 - }
291 -
292 - /* Wait up to @ms milliseconds for the loop device to give up its backing file. */
293 - static bool loop_released(const char *sysfs, int ms)
294 - {
295 - char buf[PATH_MAX];
296 -
297 - for (; ms > 0; ms -= 100) {
298 - if (read_sysfs(sysfs, buf, sizeof(buf)) < 0)
299 - return errno == ENOENT;
300 - usleep(100000);
301 - }
302 - return read_sysfs(sysfs, buf, sizeof(buf)) < 0 && errno == ENOENT;
303 - }
304 -
305 - /* Tell the loop device to give its file up, now or when its last user is gone. */
306 - static void loop_clear(int n)
307 - {
308 - char dev[32];
309 - int lfd;
310 -
311 - if (n < 0)
312 - return;
313 - snprintf(dev, sizeof(dev), "/dev/loop%d", n);
314 - lfd = open(dev, O_RDWR);
315 - if (lfd < 0)
316 - return;
317 - ioctl(lfd, LOOP_CLR_FD);
318 - close(lfd);
319 - }
320 -
321 - FIXTURE(loop_cycle) {
322 - char dev[32]; /* the loop device the child set up */
323 - char sysfs[64]; /* its backing_file attribute */
324 - int loops[MAX_LOOPS]; /* every loop device the case has bound */
325 - int nr_loops;
326 - bool gadget; /* the gadget's configfs directory exists */
327 - };
328 -
329 - static void remember_loop(FIXTURE_DATA(loop_cycle) *self, int n)
330 - {
331 - if (n >= 0 && self->nr_loops < MAX_LOOPS)
332 - self->loops[self->nr_loops++] = n;
333 - }
334 -
335 - FIXTURE_SETUP(loop_cycle)
336 - {
337 - if (geteuid() != 0)
338 - SKIP(return, "test requires CAP_SYS_ADMIN");
339 - if (access("/dev/loop-control", R_OK | W_OK))
340 - SKIP(return, "test requires loop devices");
341 -
342 - ASSERT_EQ(unshare(CLONE_NEWNS), 0);
343 - ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
344 -
345 - snprintf(base, sizeof(base), "/tmp/loop_cycle.XXXXXX");
346 - ASSERT_NE(mkdtemp(base), NULL);
347 - /* a failed assertion in the setup does not run the teardown */
348 - ASSERT_EQ(mount("tmpfs", base, "tmpfs", 0, NULL), 0)
349 - rmdir(base);
350 - snprintf(gadget, sizeof(gadget),
351 - "/sys/kernel/config/usb_gadget/kselftest_cycle_%d", getpid());
352 - self->dev[0] = '\0';
353 - self->nr_loops = 0;
354 - self->gadget = false;
355 - }
356 -
357 - static int mount_configfs(void);
358 - static void gadget_remove(void);
359 -
360 - FIXTURE_TEARDOWN(loop_cycle)
361 - {
362 - if (self->gadget)
363 - gadget_remove();
364 - /* whatever a failed assertion has left bound */
365 - for (int i = 0; i < self->nr_loops; i++)
366 - loop_clear(self->loops[i]);
367 - umount2(base, MNT_DETACH);
368 - rmdir(base);
369 - }
370 -
371 - /* Child exit codes. */
372 - enum {
373 - CHILD_OK,
374 - CHILD_NS, /* could not set up the namespace or the tmpfs */
375 - CHILD_IMAGE, /* could not write the image */
376 - CHILD_LOOP, /* could not set up the loop device */
377 - CHILD_MOUNT, /* could not mount it (vfat and msdos both refused) */
378 - CHILD_PIPE, /* the parent went away */
379 - CHILD_HOLDER, /* could not set the holder up below the mount */
380 - CHILD_SKIP, /* the kernel lacks what the holder needs */
381 - CHILD_NOFS, /* the kernel lacks the filesystem of the image */
382 - };
383 -
384 - /* Bind the loop device that LOOP_CTL_GET_FREE names to @ifd; the device number. */
385 - static int loop_bind_free(int ifd)
386 - {
387 - int cfd, lfd, n;
388 - char dev[32];
389 -
390 - cfd = open("/dev/loop-control", O_RDWR);
391 - if (cfd < 0)
392 - return -1;
393 - n = ioctl(cfd, LOOP_CTL_GET_FREE);
394 - close(cfd);
395 - if (n < 0)
396 - return -1;
397 - snprintf(dev, sizeof(dev), "/dev/loop%d", n);
398 - lfd = open(dev, O_RDWR);
399 - if (lfd < 0)
400 - return -1;
401 - if (ioctl(lfd, LOOP_SET_FD, ifd))
402 - n = -1;
403 - close(lfd);
404 - return n;
405 - }
406 -
407 - /*
408 - * Bind a free loop device to the open image @ifd; the device number. The
409 - * device is free when LOOP_CTL_GET_FREE names it and may be somebody else's
410 - * a moment later, so try again when it is busy.
411 - */
412 - static int loop_bind(int ifd)
413 - {
414 - int n = -1;
415 -
416 - for (int i = 0; i < 64 && n < 0; i++) {
417 - n = loop_bind_free(ifd);
418 - if (n < 0 && errno != EBUSY)
419 - return -1;
420 - }
421 - if (n >= 0 && nr_bound < MAX_LOOPS)
422 - bound[nr_bound++] = n;
423 - return n;
424 - }
425 -
426 - /* Mount a FAT image, as vfat or as msdos; -1 with ENODEV if the kernel has neither. */
427 - static int mount_fat(const char *dev, const char *mp)
428 - {
429 - int err;
430 -
431 - if (!mount(dev, mp, "vfat", 0, NULL))
432 - return 0;
433 - err = errno;
434 - if (!mount(dev, mp, "msdos", 0, NULL))
435 - return 0;
436 - if (err != ENODEV)
437 - errno = err;
438 - return -1;
439 - }
440 -
441 - /*
442 - * A child that gives up has to take down what it has set up: nobody else
443 - * knows about it. Unmount, then tell the loop devices to let go. The mounts
444 - * are released after this process is gone and the devices follow them.
445 - */
446 - static int child_fails(int ret)
447 - {
448 - umount2(at("vol"), MNT_DETACH);
449 - umount2(at("vol2"), MNT_DETACH);
450 - umount2(at("p"), MNT_DETACH);
451 - umount2(at("img"), MNT_DETACH);
452 - for (int i = 0; i < nr_bound; i++)
453 - loop_clear(bound[i]);
454 - return ret;
455 - }
456 -
457 - /* Write an image to @img, bind a loop device to it and mount that at @mp; the device number. */
458 - static int loop_mount(const char *img, const char *mp)
459 - {
460 - char dev[32];
461 - int ifd, n;
462 -
463 - ifd = open(img, O_RDWR | O_CREAT | O_EXCL, 0600);
464 - if (ifd < 0 || write_fat12(ifd))
465 - return -CHILD_IMAGE;
466 - n = loop_bind(ifd);
467 - close(ifd); /* the loop device holds the file from now on */
468 - if (n < 0)
469 - return -CHILD_LOOP;
470 - snprintf(dev, sizeof(dev), "/dev/loop%d", n);
471 - if (mkdir(mp, 0755))
472 - return -CHILD_MOUNT;
473 - if (mount_fat(dev, mp))
474 - return errno == ENODEV ? -CHILD_NOFS : -CHILD_MOUNT;
475 - return n;
476 - }
477 -
478 - /*
479 - * Two tmpfs mounts, each carrying the image of the loop mount below the
480 - * other: the loop mount below vol has its image on vol2 and the other way
481 - * round.
482 - */
483 - static int crossed_child(int to_parent, int from_parent)
484 - {
485 - struct report r;
486 - char c;
487 -
488 - if (unshare(CLONE_NEWNS) || mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL))
489 - return CHILD_NS;
490 - if (mkdir(at("vol"), 0755) || mount("tmpfs", at("vol"), "tmpfs", 0, NULL) ||
491 - mkdir(at("vol2"), 0755) || mount("tmpfs", at("vol2"), "tmpfs", 0, NULL))
492 - return child_fails(CHILD_NS);
493 - r.n[0] = loop_mount(at("vol2/img"), at("vol/mnt"));
494 - if (r.n[0] < 0)
495 - return child_fails(-r.n[0]);
496 - r.n[1] = loop_mount(at("vol/img"), at("vol2/mnt"));
497 - if (r.n[1] < 0)
498 - return child_fails(-r.n[1]);
499 - if (write(to_parent, &r, sizeof(r)) != sizeof(r))
500 - return child_fails(CHILD_PIPE);
501 - if (read(from_parent, &c, 1) != 1)
502 - return child_fails(CHILD_PIPE);
503 - return CHILD_OK;
504 - }
505 -
506 - /*
507 - * In its own mount namespace the child mounts a tmpfs on vol,
508 - * puts a filesystem image on it, binds a loop device to the image and
509 - * mounts that loop device below. The loop device's backing file is a
510 - * reference on the mount the image is on, held by the loop device, held
511 - * by the mounted filesystem, held by the mount below.
512 - */
513 - static int loop_child(int to_parent, int from_parent)
514 - {
515 - struct report r = { { -1, -1 } };
516 - char c;
517 -
518 - if (unshare(CLONE_NEWNS) || mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL))
519 - return CHILD_NS;
520 - if (mkdir(at("vol"), 0755) || mount("tmpfs", at("vol"), "tmpfs", 0, NULL))
521 - return child_fails(CHILD_NS);
522 - r.n[0] = loop_mount(at("vol/img"), at("vol/mnt"));
523 - if (r.n[0] < 0)
524 - return child_fails(-r.n[0]);
525 -
526 - if (write(to_parent, &r, sizeof(r)) != sizeof(r))
527 - return child_fails(CHILD_PIPE);
528 - /* keep the namespace alive while the parent removes the directory */
529 - if (read(from_parent, &c, 1) != 1)
530 - return child_fails(CHILD_PIPE);
531 - return CHILD_OK;
532 - }
533 -
534 - /*
535 - * The child did not report. Skip if the kernel lacks something, fail with
536 - * what the child said otherwise. A child that a signal killed has failed.
537 - */
538 - #define CHILD_GAVE_UP(pid) do { \
539 - int __status; \
540 - \
541 - ASSERT_EQ(waitpid(pid, &__status, 0), pid); \
542 - if (WIFEXITED(__status) && WEXITSTATUS(__status) == CHILD_NOFS) \
543 - SKIP(return, "test requires the filesystem of the image (FAT or minix)"); \
544 - if (WIFEXITED(__status) && WEXITSTATUS(__status) == CHILD_SKIP) \
545 - SKIP(return, "the kernel lacks what this holder needs"); \
546 - ASSERT_TRUE(false) \
547 - TH_LOG("child failed to set up: %s %d", \
548 - WIFEXITED(__status) ? "exit status" : "signal", \
549 - WIFEXITED(__status) ? WEXITSTATUS(__status) : WTERMSIG(__status)); \
550 - } while (0)
551 -
552 - /* The child has to leave by itself and with nothing to complain about. */
553 - #define CHILD_LEFT(pid) do { \
554 - int __status; \
555 - \
556 - ASSERT_EQ(waitpid(pid, &__status, 0), pid); \
557 - ASSERT_TRUE(WIFEXITED(__status)); \
558 - ASSERT_EQ(WEXITSTATUS(__status), CHILD_OK); \
559 - } while (0)
560 -
561 - /*
562 - * An exclusive open of the device fails while a filesystem holds it, and
563 - * the only filesystem that ever did is the one mounted below the dead
564 - * mount. Give a release in flight a moment. Then the device must clear
565 - * right away rather than only be marked for autoclear.
566 - */
567 - static void assert_loop_released(struct __test_metadata *_metadata,
568 - FIXTURE_DATA(loop_cycle) *self)
569 - {
570 - int lfd;
571 -
572 - for (int i = 0; i < 20; i++) {
573 - lfd = open(self->dev, O_RDONLY | O_EXCL);
574 - if (lfd >= 0)
575 - break;
576 - usleep(100000);
577 - }
578 - EXPECT_GE(lfd, 0)
579 - TH_LOG("%s is still held by the loop mount below the dead mount: nothing refers to either mount and nothing can release them",
580 - self->dev);
581 - if (lfd >= 0)
582 - close(lfd);
583 -
584 - lfd = open(self->dev, O_RDWR);
585 - ASSERT_GE(lfd, 0);
586 - ASSERT_EQ(ioctl(lfd, LOOP_CLR_FD), 0);
587 - close(lfd);
588 - ASSERT_TRUE(loop_released(self->sysfs, 5000))
589 - TH_LOG("%s kept its backing file after LOOP_CLR_FD: the filesystem on it is still mounted somewhere nobody can reach",
590 - self->dev);
591 - /* somebody else may bind it from now on, so the teardown leaves it alone */
592 - for (int i = 0; i < self->nr_loops; i++) {
593 - char dev[32];
594 -
595 - snprintf(dev, sizeof(dev), "/dev/loop%d", self->loops[i]);
596 - if (!strcmp(dev, self->dev))
597 - self->loops[i] = -1;
598 - }
599 - }
600 -
601 - /*
602 - * rmdir of vol from here, where it is not a mountpoint, detaches
603 - * the child's tmpfs with the loop mount connected below it. Once the child
604 - * is gone nothing refers to either mount. The loop device must then be
605 - * free to give up its backing file, which only happens when the mounted
606 - * filesystem below the detached tmpfs has been released.
607 - */
608 - TEST_F(loop_cycle, detached_loop_mount_released)
609 - {
610 - int to_parent[2], to_child[2];
611 - struct report r = { { -1, -1 } };
612 - char buf[PATH_MAX];
613 - pid_t pid;
614 -
615 - ASSERT_EQ(pipe(to_parent), 0);
616 - ASSERT_EQ(pipe(to_child), 0);
617 -
618 - pid = fork();
619 - ASSERT_GE(pid, 0);
620 - if (pid == 0) {
621 - close(to_parent[0]);
622 - close(to_child[1]);
623 - _exit(loop_child(to_parent[1], to_child[0]));
624 - }
625 - close(to_parent[1]);
626 - close(to_child[0]);
627 -
628 - if (read(to_parent[0], &r, sizeof(r)) != sizeof(r))
629 - CHILD_GAVE_UP(pid);
630 - remember_loop(self, r.n[0]);
631 - snprintf(self->dev, sizeof(self->dev), "/dev/loop%d", r.n[0]);
632 - snprintf(self->sysfs, sizeof(self->sysfs), "/sys/block/loop%d/loop/backing_file", r.n[0]);
633 - ASSERT_EQ(read_sysfs(self->sysfs, buf, sizeof(buf)), 0);
634 - ASSERT_NE(strstr(buf, "/vol/img"), NULL);
635 -
636 - /* not a mountpoint in this namespace, so the directory can go */
637 - ASSERT_EQ(rmdir(at("vol")), 0);
638 -
639 - /* the child leaves: its namespace and every reference it held are gone */
640 - ASSERT_EQ(write(to_child[1], "", 1), 1);
641 - CHILD_LEFT(pid);
642 - close(to_parent[0]);
643 - close(to_child[1]);
644 -
645 - /* nothing can reach the two mounts any more */
646 - ASSERT_EQ(access(at("vol"), F_OK), -1);
647 - ASSERT_FALSE(mounted_anywhere(self->dev));
648 -
649 - assert_loop_released(_metadata, self);
650 - }
651 -
652 - /*
653 - * The same two mounts in a detached tree: a clone of vol from
654 - * open_tree(), the image opened through the clone so that the loop device
655 - * holds the clone, and the loop mount moved below the clone. The last
656 - * close of the tree's fd dissolves the tree with the loop mount left
657 - * connected below the dead clone, and nothing refers to either afterwards.
658 - */
659 - TEST_F(loop_cycle, dissolved_tree_loop_mount_released)
660 - {
661 - int tfd, ifd, fsfd, mfd, n;
662 - char buf[PATH_MAX];
663 -
664 - fsfd = sys_fsopen("vfat", 0);
665 - if (fsfd < 0)
666 - fsfd = sys_fsopen("msdos", 0);
667 - if (fsfd < 0)
668 - SKIP(return, "test requires a FAT filesystem");
669 -
670 - ASSERT_EQ(mkdir(at("vol"), 0755), 0);
671 - ASSERT_EQ(mount("tmpfs", at("vol"), "tmpfs", 0, NULL), 0);
672 - tfd = sys_open_tree(AT_FDCWD, at("vol"), OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC);
673 - ASSERT_GE(tfd, 0);
674 -
675 - /* the image, opened through the clone: the loop device holds the clone */
676 - ifd = openat(tfd, "img", O_RDWR | O_CREAT | O_EXCL, 0600);
677 - ASSERT_GE(ifd, 0);
678 - ASSERT_EQ(write_fat12(ifd), 0);
679 - n = loop_bind(ifd);
680 - close(ifd);
681 - ASSERT_GE(n, 0);
682 - remember_loop(self, n);
683 - snprintf(self->dev, sizeof(self->dev), "/dev/loop%d", n);
684 - snprintf(self->sysfs, sizeof(self->sysfs), "/sys/block/loop%d/loop/backing_file", n);
685 -
686 - /* the loop mount, moved below the clone */
687 - ASSERT_EQ(mkdirat(tfd, "mnt", 0755), 0);
688 - ASSERT_EQ(sys_fsconfig(fsfd, FSCONFIG_SET_STRING, "source", self->dev, 0), 0);
689 - ASSERT_EQ(sys_fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0), 0);
690 - mfd = sys_fsmount(fsfd, 0, 0);
691 - ASSERT_GE(mfd, 0);
692 - close(fsfd);
693 - ASSERT_EQ(sys_move_mount(mfd, "", tfd, "mnt", MOVE_MOUNT_F_EMPTY_PATH), 0);
694 - close(mfd);
695 -
696 - ASSERT_EQ(read_sysfs(self->sysfs, buf, sizeof(buf)), 0);
697 - ASSERT_NE(strstr(buf, "img"), NULL);
698 -
699 - /* the last fd of the tree: both mounts die, the loop mount connected */
700 - close(tfd);
701 -
702 - /* nothing can reach the two mounts any more */
703 - ASSERT_FALSE(mounted_anywhere(self->dev));
704 -
705 - assert_loop_released(_metadata, self);
706 - }
707 -
708 - /*
709 - * The cycle in two steps: rmdir of vol leaves the loop mount below it
710 - * connected while its image's mount, vol2, is alive; then rmdir of vol2
711 - * takes that one with the loop mount whose image is on the dead vol. Each
712 - * dead mount now owns a loop mount whose filesystem pins the other.
713 - */
714 - TEST_F(loop_cycle, crossed_images_released)
715 - {
716 - int to_parent[2], to_child[2];
717 - struct report r = { { -1, -1 } };
718 - char sysfs[2][64], dev[2][32];
719 - pid_t pid;
720 -
721 - ASSERT_EQ(pipe(to_parent), 0);
722 - ASSERT_EQ(pipe(to_child), 0);
723 -
724 - pid = fork();
725 - ASSERT_GE(pid, 0);
726 - if (pid == 0) {
727 - close(to_parent[0]);
728 - close(to_child[1]);
729 - _exit(crossed_child(to_parent[1], to_child[0]));
730 - }
731 - close(to_parent[1]);
732 - close(to_child[0]);
733 -
734 - if (read(to_parent[0], &r, sizeof(r)) != sizeof(r))
735 - CHILD_GAVE_UP(pid);
736 - for (int i = 0; i < 2; i++) {
737 - remember_loop(self, r.n[i]);
738 - snprintf(dev[i], sizeof(dev[i]), "/dev/loop%d", r.n[i]);
739 - snprintf(sysfs[i], sizeof(sysfs[i]), "/sys/block/loop%d/loop/backing_file", r.n[i]);
740 - }
741 -
742 - /* step one: the mount with the first loop mount below it goes */
743 - ASSERT_EQ(rmdir(at("vol")), 0);
744 -
745 - /* step two: the other one, with the loop mount whose image is on the first */
746 - ASSERT_EQ(rmdir(at("vol2")), 0);
747 -
748 - /* the child leaves: its namespace and every reference it held are gone */
749 - ASSERT_EQ(write(to_child[1], "", 1), 1);
750 - CHILD_LEFT(pid);
751 - close(to_parent[0]);
752 - close(to_child[1]);
753 -
754 - /* nothing can reach the four mounts any more */
755 - for (int i = 0; i < 2; i++) {
756 - ASSERT_FALSE(mounted_anywhere(dev[i]));
757 - strcpy(self->dev, dev[i]);
758 - strcpy(self->sysfs, sysfs[i]);
759 - assert_loop_released(_metadata, self);
760 - }
761 - }
762 -
763 - /*
764 - * The holders. Each keeps a file or a path on a mount P for as long as
765 - * its own filesystem or device lives, and each has that filesystem or
766 - * device mounted at C below P. Once another namespace's rmdir has
767 - * detached P with C connected below it and the child is gone, P is owned
768 - * by nobody, C by P, and P is kept by whatever the holder still holds.
769 - *
770 - * P is a loop mount so that its death can be observed: the loop device
771 - * gives its backing file up when P's superblock goes. The image sits on
772 - * a tmpfs next to P, not above it, so the loop device's own reference is
773 - * not part of the picture.
774 - */
775 - enum holder {
776 - HOLDER_AUTOFS, /* a FIFO on P as the daemon's pipe */
777 - HOLDER_ZRAM, /* a device node on P as the writeback device */
778 - HOLDER_ECRYPTFS, /* a directory on P as the lower directory */
779 - HOLDER_BINFMT_MISC, /* an executable on P as an 'F' interpreter */
780 - HOLDER_FUSE, /* a file on P as a passthrough backing file */
781 - HOLDER_ZLOOP, /* a directory on P for the zone files */
782 - HOLDER_GADGET, /* a file on P as a mass storage LUN, over dummy_hcd */
783 - HOLDER_MD, /* a file on P as an array's bitmap file */
784 - };
785 -
786 - #define HOLDER_IMG at("img/p.img")
787 - #define HOLDER_MNT at("p")
788 - #define HOLDER_BELOW at("p/c")
789 -
790 - static int write_file(const char *path, const char *s)
791 - {
792 - int fd = open(path, O_WRONLY);
793 - ssize_t n;
794 -
795 - if (fd < 0)
796 - return -1;
797 - n = write(fd, s, strlen(s));
798 - close(fd);
799 - return n == (ssize_t)strlen(s) ? 0 : -1;
800 - }
801 -
802 - /* Bind a free loop device to @img; the device number. */
803 - static int loop_attach(const char *img)
804 - {
805 - int ifd, n;
806 -
807 - ifd = open(img, O_RDWR);
808 - if (ifd < 0)
809 - return -1;
810 - n = loop_bind(ifd);
811 - close(ifd);
812 - return n;
813 - }
814 -
815 - static int holder_autofs(void)
816 - {
817 - char opts[64];
818 - int pfd;
819 -
820 - if (mkfifo(at("p/pipe"), 0600))
821 - return CHILD_HOLDER;
822 - pfd = open(at("p/pipe"), O_RDWR);
823 - if (pfd < 0)
824 - return CHILD_HOLDER;
825 - snprintf(opts, sizeof(opts), "fd=%d,minproto=5,maxproto=5", pfd);
826 - if (mount("autofs", HOLDER_BELOW, "autofs", 0, opts))
827 - return errno == ENODEV ? CHILD_SKIP : CHILD_HOLDER;
828 - close(pfd); /* the mount keeps its own */
829 - return CHILD_OK;
830 - }
831 -
832 - /*
833 - * zram's writeback device has to be a block device node, and that node has
834 - * to be on P. Point it at a second loop device.
835 - */
836 - static void zram_reset(void);
837 -
838 - static int holder_zram(void)
839 - {
840 - char dev[32], buf[64];
841 - struct stat st;
842 - int fd, n;
843 -
844 - if (access("/sys/block/zram0/backing_dev", W_OK))
845 - return CHILD_SKIP;
846 - /* somebody else's device, leave it alone */
847 - if (read_sysfs("/sys/block/zram0/initstate", buf, sizeof(buf)) || buf[0] != '0')
848 - return CHILD_SKIP;
849 - fd = open(at("img/wb.img"), O_RDWR | O_CREAT | O_EXCL, 0600);
850 - if (fd < 0 || ftruncate(fd, IMAGE_SIZE))
851 - return CHILD_HOLDER;
852 - close(fd);
853 - n = loop_attach(at("img/wb.img"));
854 - if (n < 0)
855 - return CHILD_HOLDER;
856 - /* the minor is not the number of the device when loop has partitions */
857 - snprintf(dev, sizeof(dev), "/dev/loop%d", n);
858 - if (stat(dev, &st) || mknod(at("p/wbdev"), S_IFBLK | 0600, st.st_rdev))
859 - return CHILD_HOLDER;
860 - if (write_file("/sys/block/zram0/backing_dev", at("p/wbdev")))
861 - return CHILD_HOLDER;
862 - snprintf(buf, sizeof(buf), "%d", 4 * 1024 * 1024);
863 - if (write_file("/sys/block/zram0/disksize", buf))
864 - goto undo;
865 - fd = open("/dev/zram0", O_RDWR);
866 - if (fd < 0)
867 - goto undo;
868 - n = write_fat12_4k(fd, 1024); /* zram has 4 KiB blocks */
869 - close(fd); /* the reset in undo is refused while the device is open */
870 - if (n)
871 - goto undo;
872 - if (mount_fat("/dev/zram0", HOLDER_BELOW)) {
873 - n = errno == ENODEV ? CHILD_NOFS : CHILD_HOLDER;
874 - zram_reset();
875 - return n;
876 - }
877 - return CHILD_OK;
878 - undo:
879 - zram_reset();
880 - return CHILD_HOLDER;
881 - }
882 -
883 - /* Is @alg in /proc/crypto? A module is listed once a request has loaded it. */
884 - static bool crypto_has(const char *alg)
885 - {
886 - char line[256], name[64];
887 - bool found = false;
888 - FILE *f;
889 -
890 - f = fopen("/proc/crypto", "r");
891 - if (!f)
892 - return true; /* no way to tell, assume it is */
893 - while (!found && fgets(line, sizeof(line), f))
894 - found = sscanf(line, "name : %63s", name) == 1 && !strcmp(name, alg);
895 - fclose(f);
896 - return found;
897 - }
898 -
899 - /* The kernel's auth token layout, which userspace has to match byte for byte. */
900 - struct ecryptfs_auth_tok {
901 - __u16 version;
902 - __u16 token_type;
903 - __u32 flags;
904 - struct {
905 - __u32 flags, encrypted_key_size, decrypted_key_size;
906 - __u8 encrypted_key[512], decrypted_key[64];
907 - } session_key;
908 - __u8 reserved[32];
909 - struct {
910 - __u32 password_bytes;
911 - __s32 hash_algo;
912 - __u32 hash_iterations, session_key_encryption_key_bytes, flags;
913 - __u8 session_key_encryption_key[64];
914 - __u8 signature[17];
915 - __u8 salt[8];
916 - } password;
917 - } __attribute__((packed));
918 -
919 - #define ECRYPTFS_SIG "0123456789abcdef"
920 -
921 - static int holder_ecryptfs(void)
922 - {
923 - struct ecryptfs_auth_tok tok = {
924 - .version = 0x0004,
925 - .token_type = 0, /* ECRYPTFS_PASSWORD */
926 - .password.session_key_encryption_key_bytes = 16,
927 - .password.flags = 0x02, /* ECRYPTFS_SESSION_KEY_ENCRYPTION_KEY_SET */
928 - .password.signature = ECRYPTFS_SIG,
929 - };
930 -
931 - /* a session keyring of this child's own, so that the key goes with it */
932 - if (syscall(__NR_keyctl, KEYCTL_JOIN_SESSION_KEYRING, NULL) < 0)
933 - return errno == ENOSYS ? CHILD_SKIP : CHILD_HOLDER;
934 - if (syscall(__NR_add_key, "user", ECRYPTFS_SIG, &tok, sizeof(tok),
935 - KEY_SPEC_SESSION_KEYRING) < 0)
936 - return CHILD_HOLDER;
937 - if (mkdir(at("p/lower"), 0755))
938 - return CHILD_HOLDER;
939 - if (mount(at("p/lower"), HOLDER_BELOW, "ecryptfs", 0,
940 - "ecryptfs_sig=" ECRYPTFS_SIG ",ecryptfs_cipher=aes,ecryptfs_key_bytes=16")) {
941 - /* EINVAL without the cipher; a module is loaded by the attempt */
942 - if (errno == ENODEV || (errno == EINVAL && !crypto_has("aes")))
943 - return CHILD_SKIP;
944 - return CHILD_HOLDER;
945 - }
946 - return CHILD_OK;
947 - }
948 -
949 - /*
950 - * binfmt_misc instances are per user namespace, so the mount below P is
951 - * made from a new one, which gets a copy of P.
952 - */
953 - static int holder_binfmt_misc(void)
954 - {
955 - static const char interp[] = "#!/bin/true\n";
956 - char reg[PATH_MAX];
957 - int out;
958 -
959 - /* 'F' opens the interpreter at registration, nothing runs it here */
960 - out = open(at("p/interp"), O_WRONLY | O_CREAT | O_EXCL, 0755);
961 - if (out < 0 || write(out, interp, sizeof(interp) - 1) != sizeof(interp) - 1)
962 - return CHILD_HOLDER;
963 - close(out);
964 -
965 - /* ENOSPC: user.max_user_namespaces is 0, EPERM: an LSM says no */
966 - if (unshare(CLONE_NEWUSER | CLONE_NEWNS)) {
967 - if (errno == EINVAL || errno == ENOSPC || errno == EPERM)
968 - return CHILD_SKIP;
969 - return CHILD_HOLDER;
970 - }
971 - if (write_file("/proc/self/setgroups", "deny") ||
972 - write_file("/proc/self/uid_map", "0 0 1") ||
973 - write_file("/proc/self/gid_map", "0 0 1"))
974 - return CHILD_HOLDER;
975 - if (mount("binfmt_misc", HOLDER_BELOW, "binfmt_misc", 0, NULL))
976 - return errno == ENODEV ? CHILD_SKIP : CHILD_HOLDER;
977 - snprintf(reg, sizeof(reg), ":cycle:E::cyc::%s:F", at("p/interp"));
978 - if (write_file(at("p/c/register"), reg))
979 - return CHILD_HOLDER;
980 - return CHILD_OK;
981 - }
982 -
983 - /*
984 - * A fuse server that only ever answers FUSE_INIT, with passthrough on, and
985 - * then registers a file on P as a backing file. The registration alone
986 - * makes the fuse superblock hold the file.
987 - */
988 - static int holder_fuse(void)
989 - {
990 - struct fuse_backing_map map = {};
991 - struct fuse_in_header *ih;
992 - struct fuse_init_out init = {
993 - .major = FUSE_KERNEL_VERSION,
994 - .minor = FUSE_KERNEL_MINOR_VERSION,
995 - .flags = FUSE_INIT_EXT,
996 - .flags2 = FUSE_PASSTHROUGH >> 32,
997 - .max_write = 4096,
998 - .max_stack_depth = 1,
999 - };
1000 - struct fuse_out_header oh = { .len = sizeof(oh) + sizeof(init) };
1001 - struct iovec iov[2] = { { &oh, sizeof(oh) }, { &init, sizeof(init) } };
1002 - char opts[64], buf[8192];
1003 - int ffd, bfd;
1004 - ssize_t n;
1005 -
1006 - bfd = open(at("p/backing"), O_RDWR | O_CREAT | O_EXCL, 0600);
1007 - if (bfd < 0)
1008 - return CHILD_HOLDER;
1009 - ffd = open("/dev/fuse", O_RDWR);
1010 - if (ffd < 0)
1011 - return CHILD_SKIP;
1012 - snprintf(opts, sizeof(opts), "fd=%d,rootmode=40000,user_id=0,group_id=0", ffd);
1013 - if (mount("fuse", HOLDER_BELOW, "fuse", 0, opts))
1014 - return errno == ENODEV ? CHILD_SKIP : CHILD_HOLDER;
1015 -
1016 - n = read(ffd, buf, sizeof(buf));
1017 - ih = (void *)buf;
1018 - if (n < (ssize_t)sizeof(*ih) || ih->opcode != FUSE_INIT)
1019 - return CHILD_HOLDER;
1020 - oh.unique = ih->unique;
1021 - if (writev(ffd, iov, 2) != (ssize_t)oh.len)
1022 - return CHILD_HOLDER;
1023 -
1024 - map.fd = bfd;
1025 - if (ioctl(ffd, FUSE_DEV_IOC_BACKING_OPEN, &map) < 0) {
1026 - /* EOPNOTSUPP: no FUSE_PASSTHROUGH, ENOTTY: no such ioctl */
1027 - if (errno == EPERM || errno == EOPNOTSUPP || errno == ENOTTY)
1028 - return CHILD_SKIP;
1029 - return CHILD_HOLDER;
1030 - }
1031 - close(bfd); /* the connection keeps its own */
1032 - return CHILD_OK; /* ffd stays open until the child exits */
1033 - }
1034 -
1035 - /* Wait for a device node the kernel is about to create. */
1036 - static int open_when_there(const char *dev, int flags, int ms)
1037 - {
1038 - int fd;
1039 -
1040 - for (; ms > 0; ms -= 100) {
1041 - fd = open(dev, flags);
1042 - if (fd >= 0)
1043 - return fd;
1044 - usleep(100000);
1045 - }
1046 - return -1;
1047 - }
1048 -
1049 - /*
1050 - * zloop keeps every zone file open. One conventional zone is enough for a
1051 - * FAT image, the sequential one stays empty.
1052 - */
1053 - static int holder_zloop(void)
1054 - {
1055 - char cmd[PATH_MAX];
1056 - int fd, ret = CHILD_HOLDER;
1057 -
1058 - if (access("/dev/zloop-control", W_OK))
1059 - return CHILD_SKIP;
1060 - /* somebody else's device, leave it alone */
1061 - if (!access("/sys/block/zloop0", F_OK))
1062 - return CHILD_SKIP;
1063 - if (mkdir(at("p/zl"), 0755) || mkdir(at("p/zl/0"), 0755))
1064 - return CHILD_HOLDER;
1065 - snprintf(cmd, sizeof(cmd),
1066 - "add id=0,capacity_mb=8,zone_size_mb=4,conv_zones=1,base_dir=%s",
1067 - at("p/zl"));
1068 - if (write_file("/dev/zloop-control", cmd))
1069 - return CHILD_HOLDER;
1070 - fd = open_when_there("/dev/zloop0", O_RDWR, 5000);
1071 - if (fd < 0 || write_fat12_4k(fd, 1024)) /* 4 KiB blocks, like P */
1072 - goto undo;
1073 - close(fd);
1074 - fd = -1;
1075 - if (mount_fat("/dev/zloop0", HOLDER_BELOW)) {
1076 - ret = errno == ENODEV ? CHILD_NOFS : CHILD_HOLDER;
1077 - goto undo;
1078 - }
1079 - return CHILD_OK;
1080 - undo:
1081 - if (fd >= 0)
1082 - close(fd);
1083 - write_file("/dev/zloop-control", "remove id=0");
1084 - return ret;
1085 - }
1086 -
1087 - static int mount_configfs(void)
1088 - {
1089 - if (access("/sys/kernel/config", F_OK))
1090 - return -1;
1091 - if (mount("configfs", "/sys/kernel/config", "configfs", 0, NULL) && errno != EBUSY)
1092 - return -1;
1093 - return 0;
1094 - }
1095 -
1096 - /* Take the gadget out of configfs again, in the reverse order of its creation. */
1097 - static void gadget_remove(void)
1098 - {
1099 - if (mount_configfs())
1100 - return;
1101 - write_file(gat("/functions/mass_storage.0/lun.0/file"), "\n");
1102 - write_file(gat("/UDC"), "\n");
1103 - unlink(gat("/configs/c.1/mass_storage.0"));
1104 - rmdir(gat("/configs/c.1/strings/0x409"));
1105 - rmdir(gat("/configs/c.1"));
1106 - rmdir(gat("/functions/mass_storage.0"));
1107 - rmdir(gat("/strings/0x409"));
1108 - rmdir(gat(""));
1109 - }
1110 -
1111 - /* The disk usb-storage created for the gadget, by the LUN's inquiry string. */
1112 - static int find_gadget_disk(char *dev, size_t len, int ms)
1113 - {
1114 - char path[PATH_MAX], model[64];
1115 - struct dirent *de;
1116 - DIR *d;
1117 -
1118 - for (; ms > 0; ms -= 100, usleep(100000)) {
1119 - d = opendir("/sys/block");
1120 - if (!d)
1121 - return -1;
1122 - while ((de = readdir(d))) {
1123 - if (strncmp(de->d_name, "sd", 2))
1124 - continue;
1125 - snprintf(path, sizeof(path), "/sys/block/%s/device/model", de->d_name);
1126 - if (read_sysfs(path, model, sizeof(model)) ||
1127 - strncmp(model, "File-Stor Gadget", 16))
1128 - continue;
1129 - snprintf(dev, len, "/dev/%s", de->d_name);
1130 - closedir(d);
1131 - return 0;
1132 - }
1133 - closedir(d);
1134 - }
1135 - return -1;
1136 - }
1137 -
1138 - /*
1139 - * A mass storage gadget bound to the dummy UDC, so that this kernel is
1140 - * also the USB host that sees the LUN as a SCSI disk. sd locks the
1141 - * medium on open, which is what keeps the LUN's file from being ejected.
1142 - */
1143 - #define GADGET_STEP(x) do { \
1144 - if (x) { \
1145 - fprintf(stderr, "gadget: %s failed: %s\n", #x, strerror(errno)); \
1146 - gadget_remove(); \
1147 - return CHILD_HOLDER; \
1148 - } \
1149 - } while (0)
1150 -
1151 - static int holder_gadget(void)
1152 - {
1153 - char dev[PATH_MAX];
1154 - int fd;
1155 -
1156 - if (mount_configfs())
1157 - return CHILD_SKIP;
1158 - if (access("/sys/kernel/config/usb_gadget", F_OK) ||
1159 - access("/sys/class/udc/dummy_udc.0", F_OK))
1160 - return CHILD_SKIP;
1161 -
1162 - fd = open(at("p/lun.img"), O_RDWR | O_CREAT | O_EXCL, 0600);
1163 - if (fd < 0 || write_fat12(fd))
1164 - return CHILD_HOLDER;
1165 - close(fd);
1166 -
1167 - GADGET_STEP(mkdir(gat(""), 0755));
1168 - GADGET_STEP(write_file(gat("/idVendor"), "0x1d6b"));
1169 - GADGET_STEP(write_file(gat("/idProduct"), "0x0104"));
1170 - GADGET_STEP(mkdir(gat("/strings/0x409"), 0755));
1171 - GADGET_STEP(write_file(gat("/strings/0x409/serialnumber"), "1"));
1172 - GADGET_STEP(write_file(gat("/strings/0x409/manufacturer"), "kselftest"));
1173 - GADGET_STEP(write_file(gat("/strings/0x409/product"), "cycle"));
1174 - GADGET_STEP(mkdir(gat("/configs/c.1"), 0755));
1175 - GADGET_STEP(mkdir(gat("/configs/c.1/strings/0x409"), 0755));
1176 - GADGET_STEP(write_file(gat("/configs/c.1/strings/0x409/configuration"), "c"));
1177 - GADGET_STEP(mkdir(gat("/functions/mass_storage.0"), 0755));
1178 - GADGET_STEP(write_file(gat("/functions/mass_storage.0/lun.0/removable"), "1"));
1179 - GADGET_STEP(write_file(gat("/functions/mass_storage.0/lun.0/file"), at("p/lun.img")));
1180 - GADGET_STEP(symlink(gat("/functions/mass_storage.0"), gat("/configs/c.1/mass_storage.0")));
1181 - /* EBUSY: the controller is somebody else's, leave it alone */
1182 - if (write_file(gat("/UDC"), "dummy_udc.0")) {
1183 - fd = errno == EBUSY ? CHILD_SKIP : CHILD_HOLDER;
1184 - gadget_remove();
1185 - return fd;
1186 - }
1187 -
1188 - /* usb-storage waits a second before it scans the device */
1189 - if (find_gadget_disk(dev, sizeof(dev), 15000)) {
1190 - /* without usb-storage and sd the LUN never shows up as a disk */
1191 - fd = (access("/sys/bus/usb/drivers/usb-storage", F_OK) ||
1192 - access("/sys/bus/scsi/drivers/sd", F_OK)) ? CHILD_SKIP : CHILD_HOLDER;
1193 - gadget_remove();
1194 - return fd;
1195 - }
1196 - fd = open_when_there(dev, O_RDONLY, 5000);
1197 - GADGET_STEP(fd < 0);
1198 - close(fd);
1199 - if (mount_fat(dev, HOLDER_BELOW)) {
1200 - fd = errno == ENODEV ? CHILD_NOFS : CHILD_HOLDER;
1201 - gadget_remove();
1202 - return fd;
1203 - }
1204 - return CHILD_OK;
1205 - }
1206 -
1207 - #define BITMAP_MAGIC 0x6d746962
1208 -
1209 - /*
1210 - * A RAID1 of one loop device, not persistent, with its bitmap in a file
1211 - * on P. The bitmap file needs a superblock the kernel accepts; sync_size,
1212 - * uuid and events are not looked at for a non-persistent array.
1213 - */
1214 - static int holder_md(void)
1215 - {
1216 - struct {
1217 - __u32 magic, version;
1218 - __u8 uuid[16];
1219 - __u64 events, events_cleared, sync_size;
1220 - __u32 state, chunksize, daemon_sleep, write_behind;
1221 - } bsb = {
1222 - .magic = BITMAP_MAGIC,
1223 - .version = 4,
1224 - .chunksize = 64 * 1024,
1225 - .daemon_sleep = 5,
1226 - };
1227 - mdu_array_info_t info = {
1228 - .level = 1,
1229 - .raid_disks = 1,
1230 - .size = 8 * 1024, /* KiB */
1231 - .not_persistent = 1,
1232 - };
1233 - mdu_disk_info_t disk = {
1234 - .major = 7,
1235 - .state = (1 << MD_DISK_ACTIVE) | (1 << MD_DISK_SYNC),
1236 - };
1237 - int fd, mdfd, bfd, n, ret = CHILD_HOLDER;
1238 - char dev[32], buf[4096];
1239 - struct stat st;
1240 -
1241 - fd = open(at("img/md.img"), O_RDWR | O_CREAT | O_EXCL, 0600);
1242 - if (fd < 0 || ftruncate(fd, 8 * 1024 * 1024))
1243 - return CHILD_HOLDER;
1244 - close(fd);
1245 - n = loop_attach(at("img/md.img"));
1246 - if (n < 0)
1247 - return CHILD_HOLDER;
1248 - /* the minor is not the number of the device when loop has partitions */
1249 - snprintf(dev, sizeof(dev), "/dev/loop%d", n);
1250 - if (stat(dev, &st))
1251 - return CHILD_HOLDER;
1252 - disk.major = major(st.st_rdev);
1253 - disk.minor = minor(st.st_rdev);
1254 -
1255 - bfd = open(at("p/bitmap"), O_RDWR | O_CREAT | O_EXCL, 0600);
1256 - if (bfd < 0 || write(bfd, &bsb, sizeof(bsb)) != sizeof(bsb) || ftruncate(bfd, 4096))
1257 - return CHILD_HOLDER;
1258 -
1259 - if (read_sysfs("/proc/mdstat", buf, sizeof(buf))) {
1260 - fprintf(stderr, "md: no /proc/mdstat\n");
1261 - return CHILD_SKIP;
1262 - }
1263 - if (!strstr(buf, "[raid1]")) {
1264 - fprintf(stderr, "md: no raid1 personality: %s\n", buf);
1265 - return CHILD_SKIP;
1266 - }
1267 - /* a node of our own: /dev may not have one and is not ours to change */
1268 - if (mknod(at("img/md0"), S_IFBLK | 0600, makedev(MD_MAJOR, 0)))
1269 - return CHILD_HOLDER;
1270 - mdfd = open(at("img/md0"), O_RDWR);
1271 - if (mdfd < 0)
1272 - return CHILD_SKIP;
1273 - /* somebody else's array: SET_ARRAY_INFO would say EINVAL, not EBUSY */
1274 - if (!read_sysfs("/sys/block/md0/md/array_state", buf, sizeof(buf)) &&
1275 - strncmp(buf, "clear", 5)) {
1276 - fprintf(stderr, "md: md0 is in use: %s", buf);
1277 - close(mdfd);
1278 - return CHILD_SKIP;
1279 - }
1280 - /* the bitmap ops are only installed once a bitmap type is chosen */
1281 - write_file("/sys/block/md0/md/bitmap_type", "bitmap");
1282 - /* EBUSY: somebody else's array, leave it alone */
1283 - if (ioctl(mdfd, SET_ARRAY_INFO, &info))
1284 - return errno == EBUSY ? CHILD_SKIP : CHILD_HOLDER;
1285 - /* the array is ours from here on and has to be stopped on every path */
1286 - if (ioctl(mdfd, ADD_NEW_DISK, &disk))
1287 - goto undo;
1288 - /* attach the bitmap file before the array runs, the way mdadm does */
1289 - if (ioctl(mdfd, SET_BITMAP_FILE, bfd)) {
1290 - fprintf(stderr, "md: SET_BITMAP_FILE: %s\n", strerror(errno));
1291 - if (errno == EINVAL)
1292 - ret = CHILD_SKIP;
1293 - goto undo;
1294 - }
1295 - close(bfd); /* the array keeps its own */
1296 - if (ioctl(mdfd, RUN_ARRAY, NULL)) {
1297 - fprintf(stderr, "md: RUN_ARRAY: %s\n", strerror(errno));
1298 - goto undo;
1299 - }
1300 - if (write_fat12(mdfd))
1301 - goto undo;
1302 - close(mdfd);
1303 - if (mount_fat(at("img/md0"), HOLDER_BELOW)) {
1304 - ret = errno == ENODEV ? CHILD_NOFS : CHILD_HOLDER;
1305 - mdfd = open(at("img/md0"), O_RDWR);
1306 - goto undo;
1307 - }
1308 - return CHILD_OK;
1309 - undo:
1310 - if (mdfd >= 0) {
1311 - ioctl(mdfd, STOP_ARRAY);
1312 - close(mdfd);
1313 - }
1314 - return ret;
1315 - }
1316 -
1317 - /*
1318 - * A device keeps its file for as long as it is configured, so once nothing
1319 - * below the dead mount is left the device has to be told to let go. With
1320 - * the cycle unbroken C's filesystem still holds the device and every one
1321 - * of these refuses.
1322 - */
1323 - static int holder_let_go_once(enum holder holder)
1324 - {
1325 - int fd, ret;
1326 -
1327 - switch (holder) {
1328 - case HOLDER_ZRAM:
1329 - return write_file("/sys/block/zram0/reset", "1");
1330 - case HOLDER_ZLOOP:
1331 - return write_file("/dev/zloop-control", "remove id=0");
1332 - case HOLDER_GADGET:
1333 - if (mount_configfs())
1334 - return -1;
1335 - /* a zero-length write is a no-op for configfs; a newline ejects */
1336 - return write_file(gat("/functions/mass_storage.0/lun.0/file"), "\n");
1337 - case HOLDER_MD:
1338 - fd = open(at("img/md0"), O_RDONLY);
1339 - if (fd < 0) {
1340 - /* the child's node went with its tmpfs */
1341 - mknod(at("md0"), S_IFBLK | 0600, makedev(MD_MAJOR, 0));
1342 - fd = open(at("md0"), O_RDONLY);
1343 - }
1344 - if (fd < 0)
1345 - return -1;
1346 - ret = ioctl(fd, STOP_ARRAY);
1347 - close(fd);
1348 - return ret;
1349 - default:
1350 - return 0;
1351 - }
1352 - }
1353 -
1354 - static void zram_reset(void)
1355 - {
1356 - holder_let_go_once(HOLDER_ZRAM);
1357 - }
1358 -
1359 - /*
1360 - * In its own mount namespace the child puts the image on a tmpfs next to
1361 - * P, mounts P from a loop device, and sets the holder up with its own
1362 - * filesystem or device mounted at C below P.
1363 - */
1364 - static int holder_child(int to_parent, int from_parent, enum holder holder)
1365 - {
1366 - bool fifo = holder == HOLDER_AUTOFS || holder == HOLDER_ZRAM;
1367 - /* room for a 4 MiB zone file or a floppy image on P */
1368 - bool big = holder == HOLDER_ZLOOP || holder == HOLDER_GADGET;
1369 - struct report r = { { -1, -1 } };
1370 - char dev[32], c;
1371 - int ifd, n, ret;
1372 -
1373 - if (unshare(CLONE_NEWNS) || mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL))
1374 - return CHILD_NS;
1375 - if (mkdir(at("img"), 0755) || mount("tmpfs", at("img"), "tmpfs", 0, NULL))
1376 - return child_fails(CHILD_NS);
1377 -
1378 - ifd = open(HOLDER_IMG, O_RDWR | O_CREAT | O_EXCL, 0600);
1379 - if (ifd < 0 || (fifo ? write_minix(ifd) :
1380 - big ? write_fat12_4k(ifd, 3072) : write_fat12(ifd)))
1381 - return child_fails(CHILD_IMAGE);
1382 - close(ifd);
1383 - n = loop_attach(HOLDER_IMG);
1384 - if (n < 0)
1385 - return child_fails(CHILD_LOOP);
1386 - snprintf(dev, sizeof(dev), "/dev/loop%d", n);
1387 - if (mkdir(HOLDER_MNT, 0755))
1388 - return child_fails(CHILD_MOUNT);
1389 - if (fifo ? mount(dev, HOLDER_MNT, "minix", 0, NULL) : mount_fat(dev, HOLDER_MNT))
1390 - return child_fails(errno == ENODEV ? CHILD_NOFS : CHILD_MOUNT);
1391 - if (mkdir(HOLDER_BELOW, 0755))
1392 - return child_fails(CHILD_MOUNT);
1393 -
1394 - switch (holder) {
1395 - case HOLDER_AUTOFS:
1396 - ret = holder_autofs();
1397 - break;
1398 - case HOLDER_ZRAM:
1399 - ret = holder_zram();
1400 - break;
1401 - case HOLDER_ECRYPTFS:
1402 - ret = holder_ecryptfs();
1403 - break;
1404 - case HOLDER_BINFMT_MISC:
1405 - ret = holder_binfmt_misc();
1406 - break;
1407 - case HOLDER_FUSE:
1408 - ret = holder_fuse();
1409 - break;
1410 - case HOLDER_ZLOOP:
1411 - ret = holder_zloop();
1412 - break;
1413 - case HOLDER_GADGET:
1414 - ret = holder_gadget();
1415 - break;
1416 - case HOLDER_MD:
1417 - ret = holder_md();
1418 - break;
1419 - default:
1420 - ret = CHILD_HOLDER;
1421 - }
1422 - if (ret != CHILD_OK)
1423 - return child_fails(ret);
1424 -
1425 - /* P's device first, then the one the holder has bound for itself */
1426 - r.n[0] = n;
1427 - if (nr_bound > 1)
1428 - r.n[1] = bound[1];
1429 - if (write(to_parent, &r, sizeof(r)) != sizeof(r) ||
1430 - read(from_parent, &c, 1) != 1) {
1431 - /* the parent went away and will not tell the devices to let go */
1432 - umount2(HOLDER_BELOW, MNT_DETACH);
1433 - for (int i = 0; i < 50 && holder_let_go_once(holder); i++)
1434 - usleep(100000);
1435 - if (holder == HOLDER_GADGET)
1436 - gadget_remove();
1437 - return child_fails(CHILD_PIPE);
1438 - }
1439 - return CHILD_OK;
1440 - }
1441 -
1442 - /*
1443 - * The release of C's filesystem may still be in flight when the child is
1444 - * gone, and a device that is still held refuses to let go, so try for a
1445 - * while. With the cycle unbroken it refuses for good.
1446 - */
1447 - static void holder_let_go(enum holder holder)
1448 - {
1449 - for (int i = 0; i < 50; i++) {
1450 - if (!holder_let_go_once(holder))
1451 - return;
1452 - usleep(100000);
1453 - }
1454 - }
1455 -
1456 - /*
1457 - * rmdir of p from here, where it is a plain directory, detaches
1458 - * P in the child's namespace with C connected below it. Once the child is
1459 - * gone the holder's file on P is the only thing left that refers to P,
1460 - * and it is dropped only when C's filesystem dies, which waits for P.
1461 - * The loop device backing P tells whether that resolved.
1462 - */
1463 - static void holder_cycle(struct __test_metadata *_metadata,
1464 - FIXTURE_DATA(loop_cycle) *self, enum holder holder)
1465 - {
1466 - struct report r = { { -1, -1 } };
1467 - int to_parent[2], from_parent[2];
1468 - pid_t pid;
1469 -
1470 - ASSERT_EQ(pipe(to_parent), 0);
1471 - ASSERT_EQ(pipe(from_parent), 0);
1472 - pid = fork();
1473 - ASSERT_GE(pid, 0);
1474 - if (pid == 0) {
1475 - close(to_parent[0]);
1476 - close(from_parent[1]);
1477 - _exit(holder_child(to_parent[1], from_parent[0], holder));
1478 - }
1479 - close(to_parent[1]);
1480 - close(from_parent[0]);
1481 -
1482 - if (read(to_parent[0], &r, sizeof(r)) != sizeof(r))
1483 - CHILD_GAVE_UP(pid);
1484 - self->gadget = holder == HOLDER_GADGET;
1485 - remember_loop(self, r.n[0]);
1486 - remember_loop(self, r.n[1]);
1487 - snprintf(self->dev, sizeof(self->dev), "/dev/loop%d", r.n[0]);
1488 - snprintf(self->sysfs, sizeof(self->sysfs), "/sys/block/loop%d/loop/backing_file", r.n[0]);
1489 -
1490 - ASSERT_EQ(rmdir(HOLDER_MNT), 0);
1491 - ASSERT_EQ(write(from_parent[1], "x", 1), 1);
1492 - CHILD_LEFT(pid);
1493 - close(to_parent[0]);
1494 - close(from_parent[1]);
1495 -
1496 - holder_let_go(holder);
1497 - assert_loop_released(_metadata, self);
1498 - /* the teardown takes the gadget and the holder's own loop device away */
1499 - }
1500 -
1501 - TEST_F(loop_cycle, autofs_pipe_on_dead_mount_released)
1502 - {
1503 - holder_cycle(_metadata, self, HOLDER_AUTOFS);
1504 - }
1505 -
1506 - TEST_F(loop_cycle, zram_writeback_node_on_dead_mount_released)
1507 - {
1508 - holder_cycle(_metadata, self, HOLDER_ZRAM);
1509 - }
1510 -
1511 - TEST_F(loop_cycle, ecryptfs_lower_on_dead_mount_released)
1512 - {
1513 - holder_cycle(_metadata, self, HOLDER_ECRYPTFS);
1514 - }
1515 -
1516 - TEST_F(loop_cycle, binfmt_misc_interpreter_on_dead_mount_released)
1517 - {
1518 - holder_cycle(_metadata, self, HOLDER_BINFMT_MISC);
1519 - }
1520 -
1521 - TEST_F(loop_cycle, fuse_backing_file_on_dead_mount_released)
1522 - {
1523 - holder_cycle(_metadata, self, HOLDER_FUSE);
1524 - }
1525 -
1526 - TEST_F(loop_cycle, zloop_zone_files_on_dead_mount_released)
1527 - {
1528 - holder_cycle(_metadata, self, HOLDER_ZLOOP);
1529 - }
1530 -
1531 - /* up to 15 s for the disk to show up and 12 s for a device that is held */
1532 - TEST_F_TIMEOUT(loop_cycle, mass_storage_lun_on_dead_mount_released, 120)
1533 - {
1534 - holder_cycle(_metadata, self, HOLDER_GADGET);
1535 - }
1536 -
1537 - TEST_F(loop_cycle, md_bitmap_file_on_dead_mount_released)
1538 - {
1539 - holder_cycle(_metadata, self, HOLDER_MD);
1540 - }
1541 -
1542 - TEST_HARNESS_MAIN
deleted tools/testing/selftests/filesystems/mount_cycle/mount_cover_test.c mode 100644
@@ -1,579 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * An unmounted mount that would have stayed attached to its unmounted parent
4 - * leaves a cover behind instead. A lookup on the parent at the mountpoint
5 - * finds knullfs: an empty read-only directory that is shared by every cover
6 - * and every kernel thread, so it can't be watched or locked and nothing can
7 - * be mounted on it. The mount itself is a root from then on. Where a file
8 - * was mounted, the stand-in is an empty regular file of the same instance.
9 - */
10 - #define _GNU_SOURCE
11 - #include <errno.h>
12 - #include <fcntl.h>
13 - #include <sched.h>
14 - #include <stdint.h>
15 - #include <stdio.h>
16 - #include <stdlib.h>
17 - #include <string.h>
18 - #include <unistd.h>
19 - #include <sys/fanotify.h>
20 - #include <sys/file.h>
21 - #include <sys/inotify.h>
22 - #include <sys/mount.h>
23 - #include <sys/prctl.h>
24 - #include <sys/stat.h>
25 - #include <sys/statvfs.h>
26 - #include <sys/syscall.h>
27 - #include <sys/vfs.h>
28 - #include <sys/wait.h>
29 -
30 - #include "../../kselftest_harness.h"
31 - #include "../readdir_hold.h"
32 -
33 - #ifndef NULL_FS_MAGIC
34 - #define NULL_FS_MAGIC 0x4E554C4C
35 - #endif
36 -
37 - #ifndef TMPFS_MAGIC
38 - #define TMPFS_MAGIC 0x01021994
39 - #endif
40 -
41 - #ifndef F_SETDELEG
42 - #define F_SETDELEG (F_SETLEASE + 16)
43 - #endif
44 -
45 - /* struct delegation of <linux/fcntl.h>, which doesn't mix with <fcntl.h> */
46 - struct delegation_req {
47 - uint32_t d_flags;
48 - uint16_t d_type;
49 - uint16_t __pad;
50 - };
51 -
52 - #define DIR_LEN 64
53 - #define PATH_LEN 128
54 -
55 - /* what the parent asks the child to do */
56 - #define CMD_RMDIR 'r'
57 - #define CMD_CLOSE_T 't'
58 - #define CMD_QUIT 'q'
59 -
60 - static int write_file(const char *path, const char *s)
61 - {
62 - ssize_t n = -1;
63 - int fd;
64 -
65 - fd = open(path, O_WRONLY | O_CLOEXEC);
66 - if (fd >= 0) {
67 - n = write(fd, s, strlen(s));
68 - close(fd);
69 - }
70 - return n == (ssize_t)strlen(s) ? 0 : -1;
71 - }
72 -
73 - static int touch(const char *path)
74 - {
75 - int fd;
76 -
77 - fd = open(path, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0644);
78 - if (fd < 0)
79 - return -1;
80 - close(fd);
81 - return 0;
82 - }
83 -
84 - /* Become root in a new user namespace with a private mount namespace. */
85 - static int enter_userns(void)
86 - {
87 - uid_t uid = getuid();
88 - gid_t gid = getgid();
89 - char map[32];
90 -
91 - prctl(PR_SET_DUMPABLE, 1);
92 - if (unshare(CLONE_NEWUSER | CLONE_NEWNS))
93 - return -1;
94 - if (write_file("/proc/self/setgroups", "deny") && errno != ENOENT)
95 - return -1;
96 - snprintf(map, sizeof(map), "0 %d 1", uid);
97 - if (write_file("/proc/self/uid_map", map))
98 - return -1;
99 - snprintf(map, sizeof(map), "0 %d 1", gid);
100 - if (write_file("/proc/self/gid_map", map))
101 - return -1;
102 - if (setgid(0) || setuid(0))
103 - return -1;
104 - return mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL);
105 - }
106 -
107 - /*
108 - * The child mounts P on @base/p, C on P/covered and the file P/src on P/file
109 - * in a mount namespace of its own, binds P a second time at @base/q and hands
110 - * out descriptors on P and on C. rmdir() of @base/p from here unmounts P
111 - * together with C and the file bind. P and C are held by the descriptors and
112 - * the unmounted children leave their covers behind. On request the child
113 - * removes C's mountpoint through the bind.
114 - *
115 - * It also mounts T on @base/t with a child on T/covered, binds T at @base/u
116 - * with a second child on the same dentry and hands out descriptors on T and
117 - * U. rmdir() of both from here leaves two covers on one mountpoint. On request
118 - * the child lets go of T.
119 - */
120 - static int cover_child(const char *base, int to_parent, int from_parent)
121 - {
122 - char p[PATH_LEN], c[PATH_LEN], q[PATH_LEN], qc[PATH_LEN];
123 - char f[PATH_LEN], src[PATH_LEN], t[PATH_LEN], u[PATH_LEN], tc[PATH_LEN];
124 - int fds[4], ret;
125 - char cmd;
126 -
127 - if (unshare(CLONE_NEWNS) || mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL))
128 - return 1;
129 - snprintf(p, sizeof(p), "%s/p", base);
130 - if (mkdir(p, 0755) || mount("tmpfs", p, "tmpfs", 0, NULL))
131 - return 2;
132 - snprintf(c, sizeof(c), "%s/p/covered", base);
133 - if (mkdir(c, 0755) || mount("tmpfs", c, "tmpfs", 0, NULL))
134 - return 3;
135 - snprintf(f, sizeof(f), "%s/p/file", base);
136 - snprintf(src, sizeof(src), "%s/p/src", base);
137 - if (touch(src) || touch(f) || mount(src, f, NULL, MS_BIND, NULL))
138 - return 4;
139 - snprintf(q, sizeof(q), "%s/q", base);
140 - if (mkdir(q, 0755) || mount(p, q, NULL, MS_BIND, NULL))
141 - return 5;
142 - snprintf(t, sizeof(t), "%s/t", base);
143 - if (mkdir(t, 0755) || mount("tmpfs", t, "tmpfs", 0, NULL))
144 - return 6;
145 - snprintf(tc, sizeof(tc), "%s/t/covered", base);
146 - if (mkdir(tc, 0755) || mount("tmpfs", tc, "tmpfs", 0, NULL))
147 - return 7;
148 - snprintf(u, sizeof(u), "%s/u", base);
149 - if (mkdir(u, 0755) || mount(t, u, NULL, MS_BIND, NULL))
150 - return 8;
151 - snprintf(tc, sizeof(tc), "%s/u/covered", base);
152 - if (mount("tmpfs", tc, "tmpfs", 0, NULL))
153 - return 9;
154 - fds[0] = open(p, O_PATH | O_DIRECTORY | O_CLOEXEC);
155 - fds[1] = open(c, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
156 - fds[2] = open(t, O_PATH | O_DIRECTORY | O_CLOEXEC);
157 - fds[3] = open(u, O_PATH | O_DIRECTORY | O_CLOEXEC);
158 - if (fds[0] < 0 || fds[1] < 0 || fds[2] < 0 || fds[3] < 0)
159 - return 10;
160 - if (write(to_parent, fds, sizeof(fds)) != sizeof(fds))
161 - return 11;
162 -
163 - snprintf(qc, sizeof(qc), "%s/q/covered", base);
164 - for (;;) {
165 - if (read(from_parent, &cmd, 1) != 1)
166 - return 12;
167 - switch (cmd) {
168 - case CMD_RMDIR:
169 - ret = rmdir(qc) ? errno : 0;
170 - if (write(to_parent, &ret, sizeof(ret)) != sizeof(ret))
171 - return 13;
172 - break;
173 - case CMD_CLOSE_T:
174 - ret = close(fds[2]) ? errno : 0;
175 - if (write(to_parent, &ret, sizeof(ret)) != sizeof(ret))
176 - return 13;
177 - break;
178 - case CMD_QUIT:
179 - return 0;
180 - default:
181 - return 14;
182 - }
183 - }
184 - }
185 -
186 - FIXTURE(mount_cover) {
187 - char base[DIR_LEN];
188 - pid_t child;
189 - int to_child;
190 - int from_child;
191 - int dfd; /* P, unmounted, held */
192 - int cfd; /* C, unmounted, held */
193 - int fd; /* what a lookup on P finds at C's mountpoint */
194 - int tfd; /* T, unmounted, held */
195 - int ufd; /* U, a bind of T, unmounted, held */
196 - int fan; /* fanotify group from before the user namespace, or -1 */
197 - struct readdir_hold hold; /* likewise from before, uffd -1 without */
198 - };
199 -
200 - /*
201 - * Everything the setup has made. The harness does not run the teardown
202 - * when an assertion of the setup fails, so the setup calls this itself.
203 - */
204 - static void cover_cleanup(FIXTURE_DATA(mount_cover) *self)
205 - {
206 - char cmd = CMD_QUIT;
207 - int status;
208 -
209 - if (self->fd >= 0)
210 - close(self->fd);
211 - if (self->cfd >= 0)
212 - close(self->cfd);
213 - if (self->dfd >= 0)
214 - close(self->dfd);
215 - if (self->tfd >= 0)
216 - close(self->tfd);
217 - if (self->ufd >= 0)
218 - close(self->ufd);
219 - if (self->fan >= 0)
220 - close(self->fan);
221 - readdir_hold_destroy(&self->hold);
222 - if (self->child > 0) {
223 - if (write(self->to_child, &cmd, 1) != 1)
224 - kill(self->child, SIGKILL);
225 - waitpid(self->child, &status, 0);
226 - }
227 - if (self->to_child >= 0)
228 - close(self->to_child);
229 - if (self->from_child >= 0)
230 - close(self->from_child);
231 - umount2(self->base, MNT_DETACH);
232 - rmdir(self->base);
233 - }
234 -
235 - static int same_file(int fd1, int fd2)
236 - {
237 - struct stat st1, st2;
238 -
239 - if (fstat(fd1, &st1) || fstat(fd2, &st2))
240 - return 0;
241 - return st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino;
242 - }
243 -
244 - FIXTURE_SETUP(mount_cover)
245 - {
246 - int to_parent[2], to_child[2], fds[4], pidfd, status;
247 - char dir[PATH_LEN];
248 - struct statfs sf;
249 -
250 - self->child = 0;
251 - self->to_child = self->from_child = -1;
252 - self->dfd = self->cfd = self->fd = self->tfd = self->ufd = -1;
253 -
254 - /*
255 - * A group for plain events takes CAP_SYS_ADMIN in the initial user
256 - * namespace, so get one before that is gone. An inode mark can be
257 - * added to it from anywhere.
258 - */
259 - self->fan = fanotify_init(FAN_CLASS_NOTIF | FAN_CLOEXEC, O_RDONLY);
260 - /* same for the userfaultfd that holds a readdir in its fault */
261 - readdir_hold_init(&self->hold);
262 -
263 - snprintf(self->base, sizeof(self->base), "/tmp/mount_cover.XXXXXX");
264 - ASSERT_NE(mkdtemp(self->base), NULL);
265 - if (enter_userns()) {
266 - cover_cleanup(self);
267 - SKIP(return, "test requires user namespaces");
268 - }
269 - ASSERT_EQ(mount("tmpfs", self->base, "tmpfs", 0, NULL), 0)
270 - cover_cleanup(self);
271 -
272 - snprintf(dir, sizeof(dir), "%s/p", self->base);
273 - ASSERT_EQ(pipe(to_parent), 0)
274 - cover_cleanup(self);
275 - ASSERT_EQ(pipe(to_child), 0)
276 - cover_cleanup(self);
277 - self->child = fork();
278 - ASSERT_GE(self->child, 0)
279 - cover_cleanup(self);
280 - if (self->child == 0) {
281 - close(to_parent[0]);
282 - close(to_child[1]);
283 - _exit(cover_child(self->base, to_parent[1], to_child[0]));
284 - }
285 - close(to_parent[1]);
286 - close(to_child[0]);
287 - self->to_child = to_child[1];
288 - self->from_child = to_parent[0];
289 - if (read(self->from_child, fds, sizeof(fds)) != sizeof(fds)) {
290 - pid_t pid = self->child;
291 -
292 - waitpid(pid, &status, 0);
293 - self->child = 0;
294 - cover_cleanup(self);
295 - ASSERT_TRUE(false)
296 - TH_LOG("child failed to set up: %s %d",
297 - WIFEXITED(status) ? "step" : "signal",
298 - WIFEXITED(status) ? WEXITSTATUS(status) : WTERMSIG(status));
299 - }
300 -
301 - pidfd = syscall(__NR_pidfd_open, self->child, 0);
302 - ASSERT_GE(pidfd, 0)
303 - cover_cleanup(self);
304 - self->dfd = syscall(__NR_pidfd_getfd, pidfd, fds[0], 0);
305 - self->cfd = syscall(__NR_pidfd_getfd, pidfd, fds[1], 0);
306 - self->tfd = syscall(__NR_pidfd_getfd, pidfd, fds[2], 0);
307 - self->ufd = syscall(__NR_pidfd_getfd, pidfd, fds[3], 0);
308 - close(pidfd);
309 - ASSERT_GE(self->dfd, 0)
310 - cover_cleanup(self);
311 - ASSERT_GE(self->cfd, 0)
312 - cover_cleanup(self);
313 - ASSERT_GE(self->tfd, 0)
314 - cover_cleanup(self);
315 - ASSERT_GE(self->ufd, 0)
316 - cover_cleanup(self);
317 -
318 - /* unmounts P and C, C leaves its cover behind */
319 - ASSERT_EQ(rmdir(dir), 0)
320 - cover_cleanup(self);
321 - /* unmounts T and U with their children, two covers on one mountpoint */
322 - snprintf(dir, sizeof(dir), "%s/t", self->base);
323 - ASSERT_EQ(rmdir(dir), 0)
324 - cover_cleanup(self);
325 - snprintf(dir, sizeof(dir), "%s/u", self->base);
326 - ASSERT_EQ(rmdir(dir), 0)
327 - cover_cleanup(self);
328 -
329 - self->fd = openat(self->dfd, "covered", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
330 - ASSERT_GE(self->fd, 0)
331 - cover_cleanup(self);
332 - ASSERT_EQ(fstatfs(self->fd, &sf), 0)
333 - cover_cleanup(self);
334 - ASSERT_EQ(sf.f_type, NULL_FS_MAGIC)
335 - cover_cleanup(self);
336 - }
337 -
338 - FIXTURE_TEARDOWN(mount_cover)
339 - {
340 - cover_cleanup(self);
341 - }
342 -
343 - TEST_F(mount_cover, not_watchable)
344 - {
345 - char p[PATH_LEN];
346 - int ifd;
347 -
348 - snprintf(p, sizeof(p), "/proc/self/fd/%d", self->fd);
349 -
350 - ifd = inotify_init1(IN_CLOEXEC);
351 - if (ifd < 0 && errno == ENOSYS) {
352 - TH_LOG("no inotify in this kernel, skipping that part");
353 - } else {
354 - ASSERT_GE(ifd, 0);
355 - EXPECT_EQ(inotify_add_watch(ifd, p, IN_OPEN), -1);
356 - EXPECT_EQ(errno, EINVAL);
357 - close(ifd);
358 - }
359 -
360 - /* dnotify ends up at the same place */
361 - EXPECT_EQ(fcntl(self->fd, F_NOTIFY, DN_ACCESS), -1);
362 - EXPECT_EQ(errno, EINVAL);
363 -
364 - if (self->fan < 0) {
365 - TH_LOG("no fanotify group without CAP_SYS_ADMIN in the initial user namespace, skipping the fanotify part");
366 - return;
367 - }
368 - EXPECT_EQ(fanotify_mark(self->fan, FAN_MARK_ADD, FAN_OPEN, self->fd, NULL), -1);
369 - EXPECT_EQ(errno, EINVAL);
370 - }
371 -
372 - TEST_F(mount_cover, not_lockable)
373 - {
374 - struct flock fl = {
375 - .l_type = F_RDLCK,
376 - .l_whence = SEEK_SET,
377 - };
378 -
379 - EXPECT_EQ(flock(self->fd, LOCK_EX | LOCK_NB), -1);
380 - EXPECT_EQ(errno, ENOLCK);
381 - EXPECT_EQ(fcntl(self->fd, F_SETLK, &fl), -1);
382 - EXPECT_EQ(errno, ENOLCK);
383 - EXPECT_EQ(fcntl(self->fd, F_GETLK, &fl), -1);
384 - EXPECT_EQ(errno, ENOLCK);
385 - }
386 -
387 - /* a lease is refused for the owner and for everybody else alike */
388 - TEST_F(mount_cover, not_leasable)
389 - {
390 - struct delegation_req deleg = {
391 - .d_type = F_RDLCK,
392 - };
393 -
394 - EXPECT_EQ(fcntl(self->fd, F_SETLEASE, F_RDLCK), -1);
395 - EXPECT_TRUE(errno == EINVAL || errno == EACCES);
396 - EXPECT_EQ(fcntl(self->fd, F_SETDELEG, &deleg), -1);
397 - EXPECT_TRUE(errno == EINVAL || errno == EACCES);
398 - }
399 -
400 - TEST_F(mount_cover, not_mountable)
401 - {
402 - char p[PATH_LEN];
403 -
404 - snprintf(p, sizeof(p), "/proc/self/fd/%d", self->fd);
405 - EXPECT_EQ(mount("tmpfs", p, "tmpfs", 0, NULL), -1);
406 - EXPECT_EQ(errno, ENOENT);
407 - }
408 -
409 - TEST_F(mount_cover, read_only)
410 - {
411 - struct statvfs sv;
412 -
413 - EXPECT_EQ(mkdirat(self->fd, "x", 0755), -1);
414 - EXPECT_EQ(errno, ENOENT);
415 - EXPECT_EQ(fchmod(self->fd, 0777), -1);
416 - EXPECT_EQ(errno, EROFS);
417 - /* the immutable inode is checked before the read-only mount */
418 - EXPECT_EQ(faccessat(self->fd, ".", W_OK, 0), -1);
419 - EXPECT_EQ(errno, EPERM);
420 - ASSERT_EQ(fstatvfs(self->fd, &sv), 0);
421 - EXPECT_TRUE(sv.f_flag & ST_RDONLY);
422 - }
423 -
424 - /* the stand-in is a root of its own, ".." stays put */
425 - TEST_F(mount_cover, island)
426 - {
427 - int fd;
428 -
429 - fd = openat(self->fd, "..", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
430 - ASSERT_GE(fd, 0);
431 - EXPECT_TRUE(same_file(fd, self->fd));
432 - close(fd);
433 - }
434 -
435 - /*
436 - * C is alive for as long as the child holds it, but it can't be reached
437 - * through P anymore and it's a root of its own as well.
438 - */
439 - TEST_F(mount_cover, held_child_detached)
440 - {
441 - struct statfs sf;
442 - int fd;
443 -
444 - ASSERT_EQ(fstatfs(self->cfd, &sf), 0);
445 - EXPECT_EQ(sf.f_type, TMPFS_MAGIC);
446 -
447 - fd = openat(self->cfd, "..", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
448 - ASSERT_GE(fd, 0);
449 - EXPECT_TRUE(same_file(fd, self->cfd));
450 - close(fd);
451 -
452 - fd = openat(self->dfd, "covered", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
453 - ASSERT_GE(fd, 0);
454 - ASSERT_EQ(fstatfs(fd, &sf), 0);
455 - EXPECT_EQ(sf.f_type, NULL_FS_MAGIC);
456 - close(fd);
457 - }
458 -
459 - /*
460 - * The cover goes with its mountpoint: once the child has removed C's
461 - * mountpoint through the bind of P, the name is gone from P as well.
462 - * What was opened through the cover before stays open.
463 - */
464 - TEST_F(mount_cover, cover_goes_with_mountpoint)
465 - {
466 - char cmd = CMD_RMDIR;
467 - struct statfs sf;
468 - int ret;
469 -
470 - ASSERT_EQ(write(self->to_child, &cmd, 1), 1);
471 - ASSERT_EQ(read(self->from_child, &ret, sizeof(ret)), sizeof(ret));
472 - ASSERT_EQ(ret, 0);
473 -
474 - EXPECT_EQ(openat(self->dfd, "covered", O_RDONLY | O_DIRECTORY | O_CLOEXEC), -1);
475 - EXPECT_EQ(errno, ENOENT);
476 - ASSERT_EQ(fstatfs(self->fd, &sf), 0);
477 - EXPECT_EQ(sf.f_type, NULL_FS_MAGIC);
478 - }
479 -
480 - /*
481 - * A readdir of the stand-in holds nothing that others wait for: one holder
482 - * sticks in the page fault of its buffer, and a create and a lookup of
483 - * another come back meanwhile.
484 - */
485 - TEST_F(mount_cover, readdir_blocks_nobody)
486 - {
487 - bool stalled;
488 -
489 - if (self->hold.uffd < 0)
490 - SKIP(return, "test requires userfaultfd");
491 - ASSERT_EQ(readdir_hold_check(&self->hold, self->fd, &stalled), 0);
492 - EXPECT_FALSE(stalled);
493 - }
494 -
495 - /* where a file was mounted, the stand-in is an empty regular file */
496 - TEST_F(mount_cover, file_stand_in)
497 - {
498 - char src[PATH_LEN], p[PATH_LEN];
499 - struct statfs sf;
500 - struct stat st;
501 - char c;
502 - int fd;
503 -
504 - fd = openat(self->dfd, "file", O_RDONLY | O_CLOEXEC);
505 - ASSERT_GE(fd, 0);
506 - ASSERT_EQ(fstat(fd, &st), 0);
507 - EXPECT_TRUE(S_ISREG(st.st_mode));
508 - ASSERT_EQ(fstatfs(fd, &sf), 0);
509 - EXPECT_EQ(sf.f_type, NULL_FS_MAGIC);
510 - /* the two stand-ins are two inodes */
511 - EXPECT_FALSE(same_file(fd, self->fd));
512 - EXPECT_EQ(read(fd, &c, 1), 0);
513 - EXPECT_EQ(flock(fd, LOCK_EX | LOCK_NB), -1);
514 - EXPECT_EQ(errno, ENOLCK);
515 -
516 - snprintf(src, sizeof(src), "%s/src", self->base);
517 - ASSERT_EQ(touch(src), 0);
518 - snprintf(p, sizeof(p), "/proc/self/fd/%d", fd);
519 - EXPECT_EQ(mount(src, p, NULL, MS_BIND, NULL), -1);
520 - EXPECT_EQ(errno, ENOENT);
521 - close(fd);
522 -
523 - /* writes and truncates go nowhere, like /dev/null */
524 - fd = openat(self->dfd, "file", O_WRONLY | O_TRUNC | O_CLOEXEC);
525 - ASSERT_GE(fd, 0);
526 - EXPECT_EQ(write(fd, "xy", 2), 2);
527 - EXPECT_EQ(ftruncate(fd, 4), 0);
528 - ASSERT_EQ(fstat(fd, &st), 0);
529 - EXPECT_EQ(st.st_size, 0);
530 - /* the shared inode keeps its identity */
531 - EXPECT_EQ(fchmod(fd, 0600), -1);
532 - EXPECT_EQ(errno, EPERM);
533 - close(fd);
534 - fd = openat(self->dfd, "file", O_RDONLY | O_CLOEXEC);
535 - ASSERT_GE(fd, 0);
536 - EXPECT_EQ(read(fd, &c, 1), 0);
537 - close(fd);
538 -
539 - EXPECT_EQ(openat(self->dfd, "file", O_RDONLY | O_DIRECTORY | O_CLOEXEC), -1);
540 - EXPECT_EQ(errno, ENOTDIR);
541 - }
542 -
543 - /*
544 - * Two unmounted parents left covers on the same dentry. A lookup on
545 - * either finds a stand-in, and U's cover stays when T goes.
546 - */
547 - TEST_F(mount_cover, shared_mountpoint)
548 - {
549 - char cmd = CMD_CLOSE_T;
550 - struct statfs sf;
551 - int fd, ret;
552 -
553 - fd = openat(self->tfd, "covered", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
554 - ASSERT_GE(fd, 0);
555 - ASSERT_EQ(fstatfs(fd, &sf), 0);
556 - EXPECT_EQ(sf.f_type, NULL_FS_MAGIC);
557 - close(fd);
558 -
559 - fd = openat(self->ufd, "covered", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
560 - ASSERT_GE(fd, 0);
561 - ASSERT_EQ(fstatfs(fd, &sf), 0);
562 - EXPECT_EQ(sf.f_type, NULL_FS_MAGIC);
563 - close(fd);
564 -
565 - /* the last references to T go, with T its cover */
566 - ASSERT_EQ(write(self->to_child, &cmd, 1), 1);
567 - ASSERT_EQ(read(self->from_child, &ret, sizeof(ret)), sizeof(ret));
568 - ASSERT_EQ(ret, 0);
569 - close(self->tfd);
570 - self->tfd = -1;
571 -
572 - fd = openat(self->ufd, "covered", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
573 - ASSERT_GE(fd, 0);
574 - ASSERT_EQ(fstatfs(fd, &sf), 0);
575 - EXPECT_EQ(sf.f_type, NULL_FS_MAGIC);
576 - close(fd);
577 - }
578 -
579 - TEST_HARNESS_MAIN
deleted tools/testing/selftests/filesystems/mount_cycle/nsfs_rbind_loop_test.c mode 100644
@@ -1,193 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * A recursive bind mount of a namespace file that lives in another mount
4 - * namespace copies whatever is stacked on top of it there. If that includes
5 - * the file of the caller's own mount namespace, or of an older one, the copy
6 - * would pin the namespace it is put in forever. The bind mount has to be
7 - * refused, a plain bind mount of the file itself still works.
8 - */
9 - #define _GNU_SOURCE
10 - #include <errno.h>
11 - #include <fcntl.h>
12 - #include <sched.h>
13 - #include <stdio.h>
14 - #include <stdlib.h>
15 - #include <string.h>
16 - #include <unistd.h>
17 - #include <sys/mount.h>
18 - #include <sys/stat.h>
19 - #include <sys/wait.h>
20 -
21 - #include "../../kselftest_harness.h"
22 -
23 - #define DIR_LEN 64
24 - #define PATH_LEN 128
25 -
26 - /* Child exit codes. */
27 - enum {
28 - CHILD_OK,
29 - CHILD_UNSHARE, /* could not create the newer mount namespace */
30 - CHILD_PIPE, /* the parent went away */
31 - CHILD_TMPFS, /* could not mount the tmpfs in the new namespace */
32 - CHILD_REC_ALLOWED, /* the recursive bind mount was not refused */
33 - CHILD_REC_ERRNO, /* it was refused with the wrong error */
34 - CHILD_PLAIN_REFUSED, /* the plain bind mount of the file was refused */
35 - };
36 -
37 - static int write_file(const char *path, const char *s)
38 - {
39 - ssize_t n = -1;
40 - int fd;
41 -
42 - fd = open(path, O_WRONLY | O_CLOEXEC);
43 - if (fd >= 0) {
44 - n = write(fd, s, strlen(s));
45 - close(fd);
46 - }
47 - return n == (ssize_t)strlen(s) ? 0 : -1;
48 - }
49 -
50 - static int create_file(const char *path)
51 - {
52 - int fd = open(path, O_WRONLY | O_CREAT | O_CLOEXEC, 0644);
53 -
54 - if (fd < 0)
55 - return -1;
56 - close(fd);
57 - return 0;
58 - }
59 -
60 - /* Become root in a new user namespace with a private mount namespace. */
61 - static int enter_userns(void)
62 - {
63 - uid_t uid = getuid();
64 - gid_t gid = getgid();
65 - char map[32];
66 -
67 - if (unshare(CLONE_NEWUSER | CLONE_NEWNS))
68 - return -1;
69 - if (write_file("/proc/self/setgroups", "deny") && errno != ENOENT)
70 - return -1;
71 - snprintf(map, sizeof(map), "0 %d 1", uid);
72 - if (write_file("/proc/self/uid_map", map))
73 - return -1;
74 - snprintf(map, sizeof(map), "0 %d 1", gid);
75 - if (write_file("/proc/self/gid_map", map))
76 - return -1;
77 - if (setgid(0) || setuid(0))
78 - return -1;
79 - return mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL);
80 - }
81 -
82 - static int send_msg(int fd, char msg)
83 - {
84 - return write(fd, &msg, 1) == 1 ? 0 : -1;
85 - }
86 -
87 - static char recv_msg(int fd)
88 - {
89 - char msg;
90 -
91 - if (read(fd, &msg, 1) != 1)
92 - return 0;
93 - return msg;
94 - }
95 -
96 - FIXTURE(nsfs_rbind_loop) {
97 - char dir[DIR_LEN];
98 - char x[PATH_LEN];
99 - };
100 -
101 - FIXTURE_SETUP(nsfs_rbind_loop)
102 - {
103 - snprintf(self->dir, sizeof(self->dir), "/tmp/nsfs_rbind_loop.XXXXXX");
104 - ASSERT_NE(mkdtemp(self->dir), NULL);
105 - if (enter_userns()) {
106 - rmdir(self->dir);
107 - SKIP(return, "test requires user namespaces");
108 - }
109 - ASSERT_EQ(mount("tmpfs", self->dir, "tmpfs", 0, NULL), 0);
110 - snprintf(self->x, sizeof(self->x), "%s/x", self->dir);
111 - ASSERT_EQ(create_file(self->x), 0);
112 - }
113 -
114 - FIXTURE_TEARDOWN(nsfs_rbind_loop)
115 - {
116 - umount2(self->dir, MNT_DETACH);
117 - rmdir(self->dir);
118 - }
119 -
120 - /*
121 - * The child in the newer mount namespace binds the network namespace file
122 - * mount of the parent through @fd. Recursively that would copy the mount of
123 - * its own mount namespace file that the parent stacked on top.
124 - */
125 - static int newer_ns_child(const char *dir, int fd, int to_parent, int from_parent)
126 - {
127 - char src[32], y[PATH_LEN];
128 -
129 - if (unshare(CLONE_NEWNS))
130 - return CHILD_UNSHARE;
131 - if (send_msg(to_parent, 'r') || recv_msg(from_parent) != 'g')
132 - return CHILD_PIPE;
133 -
134 - snprintf(y, sizeof(y), "%s/y", dir);
135 - if (mount("tmpfs", y, "tmpfs", 0, NULL))
136 - return CHILD_TMPFS;
137 - snprintf(src, sizeof(src), "/proc/self/fd/%d", fd);
138 - snprintf(y, sizeof(y), "%s/y/f", dir);
139 - if (create_file(y))
140 - return CHILD_TMPFS;
141 -
142 - if (!mount(src, y, NULL, MS_BIND | MS_REC, NULL))
143 - return CHILD_REC_ALLOWED;
144 - if (errno != EINVAL)
145 - return CHILD_REC_ERRNO;
146 - if (mount(src, y, NULL, MS_BIND, NULL))
147 - return CHILD_PLAIN_REFUSED;
148 - umount2(y, MNT_DETACH);
149 - return CHILD_OK;
150 - }
151 -
152 - TEST_F(nsfs_rbind_loop, own_ns_file_below_foreign_source)
153 - {
154 - int to_child[2], to_parent[2], fd, status;
155 - char p[PATH_LEN];
156 - pid_t pid;
157 -
158 - snprintf(p, sizeof(p), "%s/y", self->dir);
159 - ASSERT_EQ(mkdir(p, 0755), 0);
160 -
161 - /* M, a mount of our network namespace file, held by a descriptor */
162 - ASSERT_EQ(mount("/proc/self/ns/net", self->x, NULL, MS_BIND, NULL), 0);
163 - fd = open(self->x, O_PATH | O_CLOEXEC);
164 - ASSERT_GE(fd, 0);
165 -
166 - ASSERT_EQ(pipe(to_child), 0);
167 - ASSERT_EQ(pipe(to_parent), 0);
168 - pid = fork();
169 - ASSERT_GE(pid, 0);
170 - if (pid == 0) {
171 - close(to_child[1]);
172 - close(to_parent[0]);
173 - _exit(newer_ns_child(self->dir, fd, to_parent[1], to_child[0]));
174 - }
175 - close(to_child[0]);
176 - close(to_parent[1]);
177 - ASSERT_EQ(recv_msg(to_parent[0]), 'r');
178 -
179 - /* the child's mount namespace file on top of M */
180 - snprintf(p, sizeof(p), "/proc/%d/ns/mnt", pid);
181 - ASSERT_EQ(mount(p, self->x, NULL, MS_BIND, NULL), 0);
182 -
183 - ASSERT_EQ(send_msg(to_child[1], 'g'), 0);
184 - ASSERT_EQ(waitpid(pid, &status, 0), pid);
185 - ASSERT_TRUE(WIFEXITED(status));
186 - ASSERT_EQ(WEXITSTATUS(status), CHILD_OK);
187 -
188 - close(fd);
189 - ASSERT_EQ(umount2(self->x, MNT_DETACH), 0);
190 - ASSERT_EQ(umount2(self->x, MNT_DETACH), 0);
191 - }
192 -
193 - TEST_HARNESS_MAIN
deleted tools/testing/selftests/filesystems/mount_cycle/overmount_ns_file_test.c mode 100644
@@ -1,190 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * A mount namespace file bind-mounted on top of the mount that is moved
4 - * onto a shared mount isn't copied to the peers and slaves. The mount that
5 - * already sits at the destination in a slave has to end up on top of the
6 - * propagated copy, not below the root of the mount namespace file where no
7 - * path walk ever finds it.
8 - */
9 - #define _GNU_SOURCE
10 - #include <errno.h>
11 - #include <fcntl.h>
12 - #include <sched.h>
13 - #include <signal.h>
14 - #include <stdio.h>
15 - #include <stdlib.h>
16 - #include <string.h>
17 - #include <unistd.h>
18 - #include <sys/mount.h>
19 - #include <sys/stat.h>
20 - #include <sys/syscall.h>
21 - #include <sys/wait.h>
22 -
23 - #include "../wrappers.h"
24 - #include "../../kselftest_harness.h"
25 -
26 - #define DIR_LEN 64
27 - #define PATH_LEN 128
28 -
29 - static int write_file(const char *path, const char *s)
30 - {
31 - ssize_t n = -1;
32 - int fd;
33 -
34 - fd = open(path, O_WRONLY | O_CLOEXEC);
35 - if (fd >= 0) {
36 - n = write(fd, s, strlen(s));
37 - close(fd);
38 - }
39 - return n == (ssize_t)strlen(s) ? 0 : -1;
40 - }
41 -
42 - static int create_file(const char *path, const char *s)
43 - {
44 - ssize_t n = -1;
45 - int fd;
46 -
47 - fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
48 - if (fd >= 0) {
49 - n = write(fd, s, strlen(s));
50 - close(fd);
51 - }
52 - return n == (ssize_t)strlen(s) ? 0 : -1;
53 - }
54 -
55 - /* the first bytes of the file at @path, "" if it can't be read */
56 - static const char *read_file(const char *path, char *buf, size_t len)
57 - {
58 - ssize_t n = -1;
59 - int fd;
60 -
61 - fd = open(path, O_RDONLY | O_CLOEXEC);
62 - if (fd >= 0) {
63 - n = read(fd, buf, len - 1);
64 - close(fd);
65 - }
66 - buf[n > 0 ? n : 0] = '\0';
67 - return buf;
68 - }
69 -
70 - /* Become root in a new user namespace with a private mount namespace. */
71 - static int enter_userns(void)
72 - {
73 - uid_t uid = getuid();
74 - gid_t gid = getgid();
75 - char map[32];
76 -
77 - if (unshare(CLONE_NEWUSER | CLONE_NEWNS))
78 - return -1;
79 - if (write_file("/proc/self/setgroups", "deny") && errno != ENOENT)
80 - return -1;
81 - snprintf(map, sizeof(map), "0 %d 1", uid);
82 - if (write_file("/proc/self/uid_map", map))
83 - return -1;
84 - snprintf(map, sizeof(map), "0 %d 1", gid);
85 - if (write_file("/proc/self/gid_map", map))
86 - return -1;
87 - if (setgid(0) || setuid(0))
88 - return -1;
89 - return mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL);
90 - }
91 -
92 - FIXTURE(overmount_ns_file) {
93 - char dir[DIR_LEN];
94 - pid_t child;
95 - };
96 -
97 - FIXTURE_SETUP(overmount_ns_file)
98 - {
99 - self->child = -1;
100 - snprintf(self->dir, sizeof(self->dir), "/tmp/overmount_ns_file.XXXXXX");
101 - ASSERT_NE(mkdtemp(self->dir), NULL);
102 - if (enter_userns()) {
103 - rmdir(self->dir);
104 - SKIP(return, "test requires user namespaces");
105 - }
106 - ASSERT_EQ(mount("tmpfs", self->dir, "tmpfs", 0, NULL), 0);
107 - }
108 -
109 - FIXTURE_TEARDOWN(overmount_ns_file)
110 - {
111 - if (self->child > 0) {
112 - kill(self->child, SIGKILL);
113 - waitpid(self->child, NULL, 0);
114 - }
115 - umount2(self->dir, MNT_DETACH);
116 - rmdir(self->dir);
117 - }
118 -
119 - /*
120 - * A is a shared tmpfs and B its slave with Q, a bind mount of a file, on
121 - * B/file. S is a bind mount of a file with N, a bind mount of a newer mount
122 - * namespace's file, on top of it. S is moved onto A/file. Its copy S' lands
123 - * on B/file below Q, without N. B/file keeps reading Q and once Q is
124 - * unmounted it reads S'.
125 - */
126 - TEST_F(overmount_ns_file, existing_mount_stays_on_top)
127 - {
128 - char a[PATH_LEN], b[PATH_LEN], s[PATH_LEN], p[PATH_LEN], buf[16];
129 - int fd, pfd[2];
130 - char c;
131 -
132 - snprintf(a, sizeof(a), "%s/A", self->dir);
133 - snprintf(b, sizeof(b), "%s/B", self->dir);
134 - snprintf(s, sizeof(s), "%s/s", self->dir);
135 - ASSERT_EQ(mkdir(a, 0755), 0);
136 - ASSERT_EQ(mkdir(b, 0755), 0);
137 - ASSERT_EQ(mkdir(s, 0755), 0);
138 -
139 - /* A shared, B its slave, Q on B/file */
140 - ASSERT_EQ(mount("tmpfs", a, "tmpfs", 0, NULL), 0);
141 - ASSERT_EQ(mount(NULL, a, NULL, MS_SHARED, NULL), 0);
142 - snprintf(p, sizeof(p), "%s/A/file", self->dir);
143 - ASSERT_EQ(create_file(p, "A"), 0);
144 - ASSERT_EQ(mount(a, b, NULL, MS_BIND, NULL), 0);
145 - ASSERT_EQ(mount(NULL, b, NULL, MS_SLAVE, NULL), 0);
146 - snprintf(p, sizeof(p), "%s/Q", self->dir);
147 - ASSERT_EQ(create_file(p, "Q"), 0);
148 - snprintf(b, sizeof(b), "%s/B/file", self->dir);
149 - ASSERT_EQ(mount(p, b, NULL, MS_BIND, NULL), 0);
150 -
151 - /* S on s/f, pinned by a file descriptor before N goes on top */
152 - ASSERT_EQ(mount("tmpfs", s, "tmpfs", 0, NULL), 0);
153 - snprintf(p, sizeof(p), "%s/s/f", self->dir);
154 - ASSERT_EQ(create_file(p, "f"), 0);
155 - snprintf(s, sizeof(s), "%s/s/S", self->dir);
156 - ASSERT_EQ(create_file(s, "S"), 0);
157 - ASSERT_EQ(mount(s, p, NULL, MS_BIND, NULL), 0);
158 - fd = open(p, O_PATH | O_CLOEXEC);
159 - ASSERT_GE(fd, 0);
160 -
161 - /* a newer mount namespace whose file can be bound */
162 - ASSERT_EQ(pipe(pfd), 0);
163 - self->child = fork();
164 - ASSERT_GE(self->child, 0);
165 - if (self->child == 0) {
166 - close(pfd[0]);
167 - if (unshare(CLONE_NEWNS) || write(pfd[1], "r", 1) != 1)
168 - _exit(1);
169 - pause();
170 - _exit(0);
171 - }
172 - close(pfd[1]);
173 - ASSERT_EQ(read(pfd[0], &c, 1), 1);
174 - close(pfd[0]);
175 - snprintf(s, sizeof(s), "/proc/%d/ns/mnt", self->child);
176 - ASSERT_EQ(mount(s, p, NULL, MS_BIND, NULL), 0);
177 -
178 - ASSERT_STREQ(read_file(b, buf, sizeof(buf)), "Q");
179 -
180 - snprintf(a, sizeof(a), "%s/A/file", self->dir);
181 - ASSERT_EQ(sys_move_mount(fd, "", AT_FDCWD, a, MOVE_MOUNT_F_EMPTY_PATH), 0);
182 - close(fd);
183 -
184 - /* Q is still on top of the copy in B and can be unmounted */
185 - EXPECT_STREQ(read_file(b, buf, sizeof(buf)), "Q");
186 - EXPECT_EQ(umount2(b, 0), 0);
187 - EXPECT_STREQ(read_file(b, buf, sizeof(buf)), "S");
188 - }
189 -
190 - TEST_HARNESS_MAIN
deleted tools/testing/selftests/filesystems/mount_cycle/overmount_reparent_test.c mode 100644
@@ -1,181 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * propagate_umount() slides a surviving overmount off a mount that is being
4 - * unmounted and unmounts that mount right after. If a file descriptor keeps
5 - * the unmounted mount alive its ->overmount is left pointing at the moved
6 - * mount, which is freed on its own schedule. move_mount(MOVE_MOUNT_BENEATH)
7 - * with such a file descriptor as the target walks ->overmount in
8 - * topmost_overmount() before it checks that the target is still mounted and
9 - * must not step into the freed mount.
10 - */
11 - #define _GNU_SOURCE
12 - #include <errno.h>
13 - #include <fcntl.h>
14 - #include <sched.h>
15 - #include <stdio.h>
16 - #include <stdlib.h>
17 - #include <string.h>
18 - #include <unistd.h>
19 - #include <sys/mount.h>
20 - #include <sys/stat.h>
21 - #include <sys/syscall.h>
22 -
23 - #include "../wrappers.h"
24 - #include "../../kselftest_harness.h"
25 -
26 - #ifndef MOVE_MOUNT_BENEATH
27 - #define MOVE_MOUNT_BENEATH 0x00000200
28 - #endif
29 -
30 - #ifndef FSCONFIG_CMD_CREATE
31 - #define FSCONFIG_CMD_CREATE 6
32 - #endif
33 -
34 - #define DIR_LEN 64
35 - #define PATH_LEN 128
36 -
37 - static int write_file(const char *path, const char *s)
38 - {
39 - ssize_t n = -1;
40 - int fd;
41 -
42 - fd = open(path, O_WRONLY | O_CLOEXEC);
43 - if (fd >= 0) {
44 - n = write(fd, s, strlen(s));
45 - close(fd);
46 - }
47 - return n == (ssize_t)strlen(s) ? 0 : -1;
48 - }
49 -
50 - /* Become root in a new user namespace with a private mount namespace. */
51 - static int enter_userns(void)
52 - {
53 - uid_t uid = getuid();
54 - gid_t gid = getgid();
55 - char map[32];
56 -
57 - if (unshare(CLONE_NEWUSER | CLONE_NEWNS))
58 - return -1;
59 - if (write_file("/proc/self/setgroups", "deny") && errno != ENOENT)
60 - return -1;
61 - snprintf(map, sizeof(map), "0 %d 1", uid);
62 - if (write_file("/proc/self/uid_map", map))
63 - return -1;
64 - snprintf(map, sizeof(map), "0 %d 1", gid);
65 - if (write_file("/proc/self/gid_map", map))
66 - return -1;
67 - if (setgid(0) || setuid(0))
68 - return -1;
69 - return mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL);
70 - }
71 -
72 - /* A detached tmpfs mount to serve as the source of a move. */
73 - static int detached_tmpfs(void)
74 - {
75 - int sfd, mfd;
76 -
77 - sfd = sys_fsopen("tmpfs", 0);
78 - if (sfd < 0)
79 - return -1;
80 - if (sys_fsconfig(sfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0)) {
81 - close(sfd);
82 - return -1;
83 - }
84 - mfd = sys_fsmount(sfd, 0, 0);
85 - close(sfd);
86 - return mfd;
87 - }
88 -
89 - FIXTURE(overmount_reparent) {
90 - char dir[DIR_LEN];
91 - };
92 -
93 - FIXTURE_SETUP(overmount_reparent)
94 - {
95 - snprintf(self->dir, sizeof(self->dir), "/tmp/overmount_reparent.XXXXXX");
96 - ASSERT_NE(mkdtemp(self->dir), NULL);
97 - if (enter_userns()) {
98 - rmdir(self->dir);
99 - SKIP(return, "test requires user namespaces");
100 - }
101 - }
102 -
103 - FIXTURE_TEARDOWN(overmount_reparent)
104 - {
105 - char p[PATH_LEN];
106 -
107 - snprintf(p, sizeof(p), "%s/b", self->dir);
108 - umount2(p, MNT_DETACH);
109 - snprintf(p, sizeof(p), "%s/a", self->dir);
110 - umount2(p, MNT_DETACH);
111 - }
112 -
113 - /*
114 - * A shared mount base_a is bind-mounted to base_b as its peer. A mount X on
115 - * base_a/mp propagates a copy X_b onto base_b/mp. A file descriptor pins X_b,
116 - * then X_b is made private and an overmount is stacked on its root.
117 - *
118 - * A lazy unmount of X propagates to X_b: X_b is committed to the unmount while
119 - * its overmount survives, so propagate_umount() reparents the overmount onto
120 - * base_b and unmounts X_b, which the file descriptor keeps alive. Unmounting
121 - * the reparented overmount frees it. X_b->overmount now dangles unless
122 - * mnt_change_mountpoint() reset it.
123 - *
124 - * move_mount(MOVE_MOUNT_BENEATH) through the file descriptor makes
125 - * do_lock_mount() follow X_b->overmount in topmost_overmount() before it
126 - * notices that X_b is no longer mounted. With the pointer reset the move fails
127 - * cleanly with ENOENT; otherwise it reads the freed overmount.
128 - */
129 - TEST_F(overmount_reparent, dead_overmount_holder_not_followed)
130 - {
131 - char a[PATH_LEN], b[PATH_LEN], amp[PATH_LEN], bmp[PATH_LEN];
132 - int fd, mfd, ret;
133 -
134 - snprintf(a, sizeof(a), "%s/a", self->dir);
135 - snprintf(b, sizeof(b), "%s/b", self->dir);
136 - ASSERT_EQ(mkdir(a, 0755), 0);
137 - ASSERT_EQ(mkdir(b, 0755), 0);
138 -
139 - ASSERT_EQ(mount("tmpfs", a, "tmpfs", 0, NULL), 0);
140 - ASSERT_EQ(mount(NULL, a, NULL, MS_SHARED, NULL), 0);
141 - ASSERT_EQ(mount(a, b, NULL, MS_BIND, NULL), 0);
142 -
143 - snprintf(amp, sizeof(amp), "%s/a/mp", self->dir);
144 - snprintf(bmp, sizeof(bmp), "%s/b/mp", self->dir);
145 - /* base_a and base_b share one superblock, so this dir is in both. */
146 - ASSERT_EQ(mkdir(amp, 0755), 0);
147 -
148 - /* X on base_a/mp propagates a copy X_b onto base_b/mp. */
149 - ASSERT_EQ(mount("tmpfs", amp, "tmpfs", 0, NULL), 0);
150 -
151 - /* Pin X_b before anything is stacked on top of it. */
152 - fd = open(bmp, O_PATH | O_CLOEXEC);
153 - ASSERT_GE(fd, 0);
154 -
155 - /* Keep the overmount local to X_b. */
156 - ASSERT_EQ(mount(NULL, bmp, NULL, MS_PRIVATE, NULL), 0);
157 -
158 - /* The overmount on X_b's root: X_b->overmount points at it. */
159 - ASSERT_EQ(mount("tmpfs", bmp, "tmpfs", 0, NULL), 0);
160 -
161 - /* Reparents the overmount onto base_b and unmounts X_b. */
162 - ASSERT_EQ(umount2(amp, MNT_DETACH), 0);
163 -
164 - /* Free the reparented overmount. */
165 - ASSERT_EQ(umount2(bmp, MNT_DETACH), 0);
166 - usleep(100000);
167 -
168 - mfd = detached_tmpfs();
169 - ASSERT_GE(mfd, 0);
170 -
171 - ret = sys_move_mount(mfd, "", fd, "",
172 - MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_T_EMPTY_PATH |
173 - MOVE_MOUNT_BENEATH);
174 - EXPECT_EQ(ret, -1);
175 - EXPECT_EQ(errno, ENOENT);
176 -
177 - close(mfd);
178 - close(fd);
179 - }
180 -
181 - TEST_HARNESS_MAIN
deleted tools/testing/selftests/filesystems/mount_cycle/settings mode 100644
@@ -1 +0,0 @@
1 - timeout=300
deleted tools/testing/selftests/filesystems/mount_cycle/unmounted_tree_test.c mode 100644
@@ -1,484 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * An unmounted mount tree that a file descriptor keeps alive is put and
4 - * vacated behind the root's back, so nothing may walk it under
5 - * namespace_sem: it can't be copied recursively and its propagation can't
6 - * be changed. The mount at its root alone can still be copied and that copy
7 - * is an ordinary mount.
8 - */
9 - #define _GNU_SOURCE
10 - #include <errno.h>
11 - #include <fcntl.h>
12 - #include <sched.h>
13 - #include <stdio.h>
14 - #include <stdlib.h>
15 - #include <string.h>
16 - #include <sys/mount.h>
17 - #include <sys/stat.h>
18 - #include <sys/syscall.h>
19 - #include <sys/wait.h>
20 - #include <unistd.h>
21 - #include <linux/mount.h>
22 -
23 - #include "../wrappers.h"
24 - #include "../../kselftest_harness.h"
25 -
26 - #ifndef __NR_mount_setattr
27 - #define __NR_mount_setattr 442
28 - #endif
29 -
30 - #ifndef __NR_pidfd_open
31 - #define __NR_pidfd_open 434
32 - #endif
33 -
34 - #define PATH_LEN 64
35 -
36 - static inline int sys_mount_setattr(int dfd, const char *path, unsigned int flags,
37 - struct mount_attr *attr, size_t size)
38 - {
39 - return syscall(__NR_mount_setattr, dfd, path, flags, attr, size);
40 - }
41 -
42 - static inline int sys_pidfd_open(pid_t pid, unsigned int flags)
43 - {
44 - return syscall(__NR_pidfd_open, pid, flags);
45 - }
46 -
47 - static int write_file(const char *path, const char *s)
48 - {
49 - ssize_t n = -1;
50 - int fd;
51 -
52 - fd = open(path, O_WRONLY | O_CLOEXEC);
53 - if (fd >= 0) {
54 - n = write(fd, s, strlen(s));
55 - close(fd);
56 - }
57 - return n == (ssize_t)strlen(s) ? 0 : -1;
58 - }
59 -
60 - static int touch(const char *path)
61 - {
62 - int fd;
63 -
64 - fd = open(path, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0644);
65 - if (fd < 0)
66 - return -1;
67 - close(fd);
68 - return 0;
69 - }
70 -
71 - /* Become root in a new user namespace with a private mount namespace. */
72 - static int enter_userns(void)
73 - {
74 - uid_t uid = getuid();
75 - gid_t gid = getgid();
76 - char map[32];
77 -
78 - if (unshare(CLONE_NEWUSER | CLONE_NEWNS))
79 - return -1;
80 - if (write_file("/proc/self/setgroups", "deny") && errno != ENOENT)
81 - return -1;
82 - snprintf(map, sizeof(map), "0 %d 1", uid);
83 - if (write_file("/proc/self/uid_map", map))
84 - return -1;
85 - snprintf(map, sizeof(map), "0 %d 1", gid);
86 - if (write_file("/proc/self/gid_map", map))
87 - return -1;
88 - if (setgid(0) || setuid(0))
89 - return -1;
90 - return mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL);
91 - }
92 -
93 - /* A private mount namespace of our own, all mounts private. */
94 - static int own_mntns(void)
95 - {
96 - if (unshare(CLONE_NEWNS))
97 - return -1;
98 - return mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL);
99 - }
100 -
101 - FIXTURE(unmounted_tree) {
102 - char dir[PATH_LEN];
103 - };
104 -
105 - FIXTURE_SETUP(unmounted_tree)
106 - {
107 - snprintf(self->dir, sizeof(self->dir), "/tmp/unmounted_tree.XXXXXX");
108 - ASSERT_NE(mkdtemp(self->dir), NULL);
109 - if (enter_userns()) {
110 - rmdir(self->dir);
111 - SKIP(return, "test requires user namespaces");
112 - }
113 - ASSERT_EQ(mount("tmpfs", self->dir, "tmpfs", 0, NULL), 0);
114 - }
115 -
116 - FIXTURE_TEARDOWN(unmounted_tree)
117 - {
118 - umount2(self->dir, MNT_DETACH);
119 - rmdir(self->dir);
120 - }
121 -
122 - /* A recursive copy of the mount @fd refers to must fail with EINVAL. */
123 - static void assert_not_walked(struct __test_metadata *_metadata, int fd,
124 - const char *target)
125 - {
126 - char link[PATH_LEN];
127 - int tfd;
128 -
129 - snprintf(link, sizeof(link), "/proc/self/fd/%d", fd);
130 - EXPECT_EQ(mount(link, target, NULL, MS_BIND | MS_REC, NULL), -1);
131 - EXPECT_EQ(errno, EINVAL);
132 -
133 - tfd = sys_open_tree(fd, "", AT_EMPTY_PATH | AT_RECURSIVE | OPEN_TREE_CLONE |
134 - OPEN_TREE_CLOEXEC);
135 - EXPECT_LT(tfd, 0);
136 - EXPECT_EQ(errno, EINVAL);
137 - if (tfd >= 0)
138 - close(tfd);
139 - }
140 -
141 - /* The mount @fd refers to can be copied on its own and mounted on @target. */
142 - static void assert_root_copied(struct __test_metadata *_metadata, int fd,
143 - const char *target)
144 - {
145 - int tfd;
146 -
147 - tfd = sys_open_tree(fd, "", AT_EMPTY_PATH | OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC);
148 - ASSERT_GE(tfd, 0);
149 - ASSERT_EQ(sys_move_mount(tfd, "", AT_FDCWD, target, MOVE_MOUNT_F_EMPTY_PATH), 0);
150 - close(tfd);
151 - ASSERT_EQ(umount2(target, MNT_DETACH), 0);
152 - }
153 -
154 - /*
155 - * A lazily unmounted bind mount of an nsfs file, kept alive by an fd, can't
156 - * be copied recursively anymore. Copying the mount itself still works and
157 - * so does copying a mounted bind mount of the same file.
158 - */
159 - TEST_F(unmounted_tree, detached_nsfs_bind_not_walked)
160 - {
161 - char x[PATH_LEN], y[PATH_LEN], z[PATH_LEN], link[PATH_LEN];
162 - int fd, tfd;
163 -
164 - snprintf(x, sizeof(x), "%s/x", self->dir);
165 - snprintf(y, sizeof(y), "%s/y", self->dir);
166 - snprintf(z, sizeof(z), "%s/z", self->dir);
167 - ASSERT_EQ(touch(x), 0);
168 - ASSERT_EQ(touch(y), 0);
169 - ASSERT_EQ(touch(z), 0);
170 -
171 - ASSERT_EQ(mount("/proc/self/ns/net", x, NULL, MS_BIND, NULL), 0);
172 - fd = open(x, O_PATH | O_CLOEXEC);
173 - ASSERT_GE(fd, 0);
174 - ASSERT_EQ(umount2(x, MNT_DETACH), 0);
175 -
176 - assert_not_walked(_metadata, fd, y);
177 -
178 - snprintf(link, sizeof(link), "/proc/self/fd/%d", fd);
179 - ASSERT_EQ(mount(link, y, NULL, MS_BIND, NULL), 0);
180 - ASSERT_EQ(umount2(y, MNT_DETACH), 0);
181 - assert_root_copied(_metadata, fd, y);
182 - /* opening it is fine too */
183 - tfd = sys_open_tree(fd, "", AT_EMPTY_PATH | OPEN_TREE_CLOEXEC);
184 - ASSERT_GE(tfd, 0);
185 - close(tfd);
186 - close(fd);
187 -
188 - ASSERT_EQ(mount("/proc/self/ns/net", y, NULL, MS_BIND, NULL), 0);
189 - ASSERT_EQ(mount(y, z, NULL, MS_BIND | MS_REC, NULL), 0);
190 - tfd = sys_open_tree(AT_FDCWD, y, AT_RECURSIVE | OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC);
191 - ASSERT_GE(tfd, 0);
192 - close(tfd);
193 - }
194 -
195 - /* Bind-mount the pidfd @pidfd on @target the way pidfd_bind_mount does. */
196 - static int bind_pidfd(int pidfd, const char *target)
197 - {
198 - int tfd, ret;
199 -
200 - tfd = sys_open_tree(pidfd, "", AT_EMPTY_PATH | OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC);
201 - if (tfd < 0)
202 - return -1;
203 - ret = sys_move_mount(tfd, "", AT_FDCWD, target, MOVE_MOUNT_F_EMPTY_PATH);
204 - close(tfd);
205 - return ret;
206 - }
207 -
208 - /* The same for a bind mount of a pidfd. */
209 - TEST_F(unmounted_tree, detached_pidfs_bind_not_walked)
210 - {
211 - char x[PATH_LEN], y[PATH_LEN];
212 - int pidfd, fd, tfd;
213 -
214 - snprintf(x, sizeof(x), "%s/x", self->dir);
215 - snprintf(y, sizeof(y), "%s/y", self->dir);
216 - ASSERT_EQ(touch(x), 0);
217 - ASSERT_EQ(touch(y), 0);
218 -
219 - pidfd = sys_pidfd_open(getpid(), 0);
220 - ASSERT_GE(pidfd, 0);
221 - ASSERT_EQ(bind_pidfd(pidfd, x), 0);
222 - fd = open(x, O_PATH | O_CLOEXEC);
223 - ASSERT_GE(fd, 0);
224 - ASSERT_EQ(umount2(x, MNT_DETACH), 0);
225 -
226 - assert_not_walked(_metadata, fd, y);
227 - assert_root_copied(_metadata, fd, y);
228 - close(fd);
229 -
230 - ASSERT_EQ(bind_pidfd(pidfd, y), 0);
231 - tfd = sys_open_tree(AT_FDCWD, y, AT_RECURSIVE | OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC);
232 - ASSERT_GE(tfd, 0);
233 - close(tfd);
234 - close(pidfd);
235 - }
236 -
237 - /* What a child in its own mount namespace reports back. */
238 - enum {
239 - CHILD_OK,
240 - CHILD_NS, /* could not set up the mount namespace */
241 - CHILD_MOUNT, /* could not set up the mounts */
242 - CHILD_PIPE, /* the parent went away */
243 - CHILD_WALKED, /* the detached tree was copied recursively */
244 - CHILD_ROOT_REFUSED, /* the mount at its root wasn't copied */
245 - CHILD_STILL_MOUNTED, /* the copy survived the unlink of its mountpoint */
246 - CHILD_ERRNO, /* refused, but not with EINVAL */
247 - };
248 -
249 - static const char *child_reason(int code)
250 - {
251 - static const char *const reasons[] = {
252 - [CHILD_OK] = "ok",
253 - [CHILD_NS] = "could not set up the mount namespace",
254 - [CHILD_MOUNT] = "could not set up the mounts",
255 - [CHILD_PIPE] = "the parent went away",
256 - [CHILD_WALKED] = "the detached tree was copied recursively",
257 - [CHILD_ROOT_REFUSED] = "the mount at its root wasn't copied",
258 - [CHILD_STILL_MOUNTED] = "the copy survived the unlink of its mountpoint",
259 - [CHILD_ERRNO] = "refused, but not with EINVAL",
260 - };
261 -
262 - if (code < 0 || code >= (int)(sizeof(reasons) / sizeof(reasons[0])))
263 - return "child died";
264 - return reasons[code];
265 - }
266 -
267 - struct child_args {
268 - const char *x; /* the nsfs bind mount goes here */
269 - const char *s; /* a file to bind on top of it */
270 - const char *y; /* a target to copy to */
271 - };
272 -
273 - /*
274 - * Run @fn in a child in a mount namespace of its own. Once the child
275 - * reports that its mounts are in place, unlink @victim here, where it is a
276 - * plain file, and let the child carry on. Returns what the child reported.
277 - */
278 - static int run_child(struct __test_metadata *_metadata,
279 - int (*fn)(const struct child_args *, int, int),
280 - const struct child_args *a, const char *victim)
281 - {
282 - int to_parent[2], to_child[2], status;
283 - pid_t pid;
284 - char c;
285 -
286 - if (pipe(to_parent) || pipe(to_child))
287 - return -1;
288 - pid = fork();
289 - if (pid < 0)
290 - return -1;
291 - if (pid == 0) {
292 - close(to_parent[0]);
293 - close(to_child[1]);
294 - _exit(fn(a, to_parent[1], to_child[0]));
295 - }
296 - close(to_parent[1]);
297 - close(to_child[0]);
298 - if (read(to_parent[0], &c, 1) == 1) {
299 - /* not a mountpoint in this namespace, so the file can go */
300 - EXPECT_EQ(unlink(victim), 0);
301 - EXPECT_EQ(write(to_child[1], "", 1), 1);
302 - }
303 - close(to_parent[0]);
304 - close(to_child[1]);
305 - if (waitpid(pid, &status, 0) != pid || !WIFEXITED(status))
306 - return -1;
307 - return WEXITSTATUS(status);
308 - }
309 -
310 - /*
311 - * An nsfs bind mount on @x, an fd on it and a bind mount of @s on top. Once
312 - * the parent has unlinked @x underneath, the first mount is detached and the
313 - * second one, which stayed attached to it, has been vacated. The tree may
314 - * not be walked, the mount at its root may still be copied.
315 - */
316 - static int vacant_child(const struct child_args *a, int to_parent, int from_parent)
317 - {
318 - char link[PATH_LEN];
319 - int fd, tfd;
320 - char c;
321 -
322 - if (own_mntns())
323 - return CHILD_NS;
324 - if (mount("/proc/self/ns/net", a->x, NULL, MS_BIND, NULL))
325 - return CHILD_MOUNT;
326 - fd = open(a->x, O_PATH | O_CLOEXEC);
327 - if (fd < 0 || mount(a->s, a->x, NULL, MS_BIND, NULL))
328 - return CHILD_MOUNT;
329 -
330 - if (write(to_parent, "", 1) != 1 || read(from_parent, &c, 1) != 1)
331 - return CHILD_PIPE;
332 -
333 - tfd = sys_open_tree(fd, "", AT_EMPTY_PATH | AT_RECURSIVE | OPEN_TREE_CLONE |
334 - OPEN_TREE_CLOEXEC);
335 - if (tfd >= 0) {
336 - close(tfd);
337 - return CHILD_WALKED;
338 - }
339 - if (errno != EINVAL)
340 - return CHILD_ERRNO;
341 - snprintf(link, sizeof(link), "/proc/self/fd/%d", fd);
342 - if (!mount(link, a->y, NULL, MS_BIND | MS_REC, NULL))
343 - return CHILD_WALKED;
344 - if (errno != EINVAL)
345 - return CHILD_ERRNO;
346 -
347 - tfd = sys_open_tree(fd, "", AT_EMPTY_PATH | OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC);
348 - if (tfd < 0)
349 - return CHILD_ROOT_REFUSED;
350 - close(tfd);
351 - /* the last reference on the detached mount collects the vacant one */
352 - close(fd);
353 - return CHILD_OK;
354 - }
355 -
356 - /*
357 - * unlink() of the child's mountpoint from here, where it is a plain file,
358 - * detaches the child's nsfs bind mount with the mount on top left attached
359 - * to it. The mount on top loses its last reference right there and is
360 - * vacated. The child must not be able to walk that tree.
361 - */
362 - TEST_F(unmounted_tree, vacant_child_not_copied)
363 - {
364 - char x[PATH_LEN], s[PATH_LEN], y[PATH_LEN];
365 - struct child_args a = { .x = x, .s = s, .y = y };
366 - int ret;
367 -
368 - snprintf(x, sizeof(x), "%s/x", self->dir);
369 - snprintf(s, sizeof(s), "%s/s", self->dir);
370 - snprintf(y, sizeof(y), "%s/y", self->dir);
371 - ASSERT_EQ(touch(x), 0);
372 - ASSERT_EQ(touch(s), 0);
373 - ASSERT_EQ(touch(y), 0);
374 -
375 - ret = run_child(_metadata, vacant_child, &a, x);
376 - ASSERT_EQ(ret, CHILD_OK)
377 - TH_LOG("child: %s", child_reason(ret));
378 - }
379 -
380 - /*
381 - * An nsfs bind mount on @x, lazily unmounted but kept alive by an fd, and a
382 - * copy of it on @y. That copy is a mount like any other: once the parent has
383 - * unlinked @y underneath, it is unmounted and its attributes can't be changed
384 - * anymore. A copy that took the flag along is only unhooked, stays in the
385 - * namespace and still takes the change.
386 - */
387 - static int ordinary_copy(const struct child_args *a, int to_parent, int from_parent)
388 - {
389 - struct mount_attr attr = {
390 - .attr_set = MOUNT_ATTR_NOSUID,
391 - };
392 - char link[PATH_LEN];
393 - int fd, fdy;
394 - char c;
395 -
396 - if (own_mntns())
397 - return CHILD_NS;
398 - if (mount("/proc/self/ns/net", a->x, NULL, MS_BIND, NULL))
399 - return CHILD_MOUNT;
400 - fd = open(a->x, O_PATH | O_CLOEXEC);
401 - if (fd < 0 || umount2(a->x, MNT_DETACH))
402 - return CHILD_MOUNT;
403 - snprintf(link, sizeof(link), "/proc/self/fd/%d", fd);
404 - if (mount(link, a->y, NULL, MS_BIND, NULL))
405 - return CHILD_MOUNT;
406 - fdy = open(a->y, O_PATH | O_CLOEXEC);
407 - if (fdy < 0)
408 - return CHILD_MOUNT;
409 -
410 - if (write(to_parent, "", 1) != 1 || read(from_parent, &c, 1) != 1)
411 - return CHILD_PIPE;
412 -
413 - if (!sys_mount_setattr(fdy, "", AT_EMPTY_PATH, &attr, sizeof(attr)))
414 - return CHILD_STILL_MOUNTED;
415 - if (errno != EINVAL)
416 - return CHILD_ERRNO;
417 - close(fdy);
418 - close(fd);
419 - return CHILD_OK;
420 - }
421 -
422 - /*
423 - * A copy of a detached nsfs bind mount must not take after its source and
424 - * read as unmounted. unlink() of its mountpoint from here unmounts it like
425 - * any other mount, so the child can't change its attributes anymore.
426 - */
427 - TEST_F(unmounted_tree, copy_of_detached_bind_is_ordinary)
428 - {
429 - char x[PATH_LEN], y[PATH_LEN];
430 - struct child_args a = { .x = x, .y = y };
431 - int ret;
432 -
433 - snprintf(x, sizeof(x), "%s/x", self->dir);
434 - snprintf(y, sizeof(y), "%s/y", self->dir);
435 - ASSERT_EQ(touch(x), 0);
436 - ASSERT_EQ(touch(y), 0);
437 -
438 - ret = run_child(_metadata, ordinary_copy, &a, y);
439 - ASSERT_EQ(ret, CHILD_OK)
440 - TH_LOG("child: %s", child_reason(ret));
441 - }
442 -
443 - /*
444 - * mount_setattr() may change the propagation of a detached tree while that
445 - * tree is still the root of an anonymous mount namespace, but not once the
446 - * tree has been dissolved and only a second fd keeps its root alive.
447 - */
448 - TEST_F(unmounted_tree, detached_tree_setattr_refused)
449 - {
450 - struct mount_attr attr = {
451 - .propagation = MS_SHARED,
452 - };
453 - char a[PATH_LEN], b[PATH_LEN];
454 - int tfd, fd;
455 -
456 - snprintf(a, sizeof(a), "%s/a", self->dir);
457 - snprintf(b, sizeof(b), "%s/a/b", self->dir);
458 - ASSERT_EQ(mkdir(a, 0755), 0);
459 - ASSERT_EQ(mount("tmpfs", a, "tmpfs", 0, NULL), 0);
460 - ASSERT_EQ(mkdir(b, 0755), 0);
461 - ASSERT_EQ(mount("tmpfs", b, "tmpfs", 0, NULL), 0);
462 -
463 - tfd = sys_open_tree(AT_FDCWD, self->dir, AT_RECURSIVE | OPEN_TREE_CLONE |
464 - OPEN_TREE_CLOEXEC);
465 - ASSERT_GE(tfd, 0);
466 - ASSERT_EQ(sys_mount_setattr(tfd, "", AT_EMPTY_PATH | AT_RECURSIVE, &attr, sizeof(attr)), 0);
467 - attr.propagation = MS_PRIVATE;
468 - ASSERT_EQ(sys_mount_setattr(tfd, "", AT_EMPTY_PATH | AT_RECURSIVE, &attr, sizeof(attr)), 0);
469 -
470 - /* a second reference on the root, then dissolve the tree */
471 - fd = sys_open_tree(tfd, "", AT_EMPTY_PATH | OPEN_TREE_CLOEXEC);
472 - ASSERT_GE(fd, 0);
473 - close(tfd);
474 -
475 - attr.propagation = MS_SHARED;
476 - ASSERT_EQ(sys_mount_setattr(fd, "", AT_EMPTY_PATH | AT_RECURSIVE, &attr, sizeof(attr)), -1);
477 - ASSERT_EQ(errno, EINVAL);
478 - attr.propagation = MS_PRIVATE;
479 - ASSERT_EQ(sys_mount_setattr(fd, "", AT_EMPTY_PATH, &attr, sizeof(attr)), -1);
480 - ASSERT_EQ(errno, EINVAL);
481 - close(fd);
482 - }
483 -
484 - TEST_HARNESS_MAIN
modified tools/testing/selftests/filesystems/open_tree_ns/.gitignore
@@ -1,2 +1 @@
1 1 open_tree_ns_test
2 - open_tree_ns_covered_test
modified tools/testing/selftests/filesystems/open_tree_ns/Makefile
@@ -1,5 +1,5 @@
1 1 # SPDX-License-Identifier: GPL-2.0
2 - TEST_GEN_PROGS := open_tree_ns_test open_tree_ns_covered_test
2 + TEST_GEN_PROGS := open_tree_ns_test
3 3
4 4 CFLAGS += -Wall -O0 -g $(KHDR_INCLUDES) $(TOOLS_INCLUDES)
5 5 LDLIBS := -lcap
deleted tools/testing/selftests/filesystems/open_tree_ns/open_tree_ns_covered_test.c mode 100644
@@ -1,195 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * open_tree(OPEN_TREE_NAMESPACE) by a caller that isn't privileged over the
4 - * mount namespace it copies from must not reveal what the mounts below the
5 - * copied mount cover. Without AT_RECURSIVE the copy is refused when there's
6 - * anything mounted below the requested directory. With AT_RECURSIVE
7 - * unbindable mounts are copied as well.
8 - */
9 - #define _GNU_SOURCE
10 - #include <errno.h>
11 - #include <fcntl.h>
12 - #include <sched.h>
13 - #include <stdio.h>
14 - #include <stdlib.h>
15 - #include <string.h>
16 - #include <unistd.h>
17 - #include <sys/mount.h>
18 - #include <sys/stat.h>
19 - #include <sys/wait.h>
20 -
21 - #include "../wrappers.h"
22 - #include "../../kselftest_harness.h"
23 -
24 - #ifndef OPEN_TREE_NAMESPACE
25 - #define OPEN_TREE_NAMESPACE (1 << 1)
26 - #endif
27 -
28 - #define DIR_LEN 64
29 - #define PATH_LEN 128
30 -
31 - /* Child exit codes. */
32 - enum {
33 - CHILD_OK,
34 - CHILD_USERNS, /* could not create the child user namespace */
35 - CHILD_NONREC_ALLOWED, /* the non-recursive copy was not refused */
36 - CHILD_NONREC_ERRNO, /* it was refused with the wrong error */
37 - CHILD_REC_REFUSED, /* the recursive copy failed */
38 - CHILD_SETNS, /* could not enter the new mount namespace */
39 - CHILD_NO_COVER, /* the covering mount is missing in the copy */
40 - CHILD_REVEALED, /* the covered file is visible in the copy */
41 - };
42 -
43 - static int write_file(const char *path, const char *s)
44 - {
45 - ssize_t n = -1;
46 - int fd;
47 -
48 - fd = open(path, O_WRONLY | O_CLOEXEC);
49 - if (fd >= 0) {
50 - n = write(fd, s, strlen(s));
51 - close(fd);
52 - }
53 - return n == (ssize_t)strlen(s) ? 0 : -1;
54 - }
55 -
56 - static int create_file(const char *path, const char *s)
57 - {
58 - ssize_t n = -1;
59 - int fd;
60 -
61 - fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
62 - if (fd >= 0) {
63 - n = write(fd, s, strlen(s));
64 - close(fd);
65 - }
66 - return n == (ssize_t)strlen(s) ? 0 : -1;
67 - }
68 -
69 - /* Become root in a new user namespace, the uid @uid is mapped to 0. */
70 - static int enter_userns(uid_t uid, gid_t gid)
71 - {
72 - char map[32];
73 -
74 - if (unshare(CLONE_NEWUSER))
75 - return -1;
76 - if (write_file("/proc/self/setgroups", "deny") && errno != ENOENT)
77 - return -1;
78 - snprintf(map, sizeof(map), "0 %d 1", uid);
79 - if (write_file("/proc/self/uid_map", map))
80 - return -1;
81 - snprintf(map, sizeof(map), "0 %d 1", gid);
82 - if (write_file("/proc/self/gid_map", map))
83 - return -1;
84 - return setgid(0) || setuid(0) ? -1 : 0;
85 - }
86 -
87 - FIXTURE(open_tree_ns_covered) {
88 - char dir[DIR_LEN];
89 - char cover[PATH_LEN];
90 - };
91 -
92 - FIXTURE_VARIANT(open_tree_ns_covered) {
93 - int propagation;
94 - };
95 -
96 - FIXTURE_VARIANT_ADD(open_tree_ns_covered, private_cover) {
97 - .propagation = MS_PRIVATE,
98 - };
99 -
100 - FIXTURE_VARIANT_ADD(open_tree_ns_covered, unbindable_cover) {
101 - .propagation = MS_UNBINDABLE,
102 - };
103 -
104 - /*
105 - * Root in a user namespace owns a private mount namespace with a tmpfs
106 - * on @dir and a second tmpfs covering @dir/covered/under.txt.
107 - */
108 - FIXTURE_SETUP(open_tree_ns_covered)
109 - {
110 - char p[PATH_LEN];
111 - int fd;
112 -
113 - snprintf(self->dir, sizeof(self->dir), "/tmp/open_tree_ns_covered.XXXXXX");
114 - ASSERT_NE(mkdtemp(self->dir), NULL);
115 - if (enter_userns(getuid(), getgid()) || unshare(CLONE_NEWNS)) {
116 - rmdir(self->dir);
117 - SKIP(return, "test requires user namespaces");
118 - }
119 - ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
120 - ASSERT_EQ(mount("tmpfs", self->dir, "tmpfs", 0, NULL), 0);
121 -
122 - /* the flag has to exist before its rules can be checked */
123 - fd = sys_open_tree(AT_FDCWD, self->dir,
124 - OPEN_TREE_NAMESPACE | OPEN_TREE_CLOEXEC);
125 - if (fd < 0 && (errno == EINVAL || errno == ENOSYS)) {
126 - umount2(self->dir, MNT_DETACH);
127 - rmdir(self->dir);
128 - SKIP(return, "OPEN_TREE_NAMESPACE not supported");
129 - }
130 - ASSERT_GE(fd, 0);
131 - close(fd);
132 -
133 - snprintf(self->cover, sizeof(self->cover), "%s/covered", self->dir);
134 - ASSERT_EQ(mkdir(self->cover, 0755), 0);
135 - snprintf(p, sizeof(p), "%s/covered/under.txt", self->dir);
136 - ASSERT_EQ(create_file(p, "hidden"), 0);
137 - ASSERT_EQ(mount("tmpfs", self->cover, "tmpfs", 0, NULL), 0);
138 - ASSERT_EQ(mount(NULL, self->cover, NULL, variant->propagation, NULL), 0);
139 - }
140 -
141 - FIXTURE_TEARDOWN(open_tree_ns_covered)
142 - {
143 - umount2(self->dir, MNT_DETACH);
144 - rmdir(self->dir);
145 - }
146 -
147 - /* A caller in a new user namespace that doesn't own the mount namespace. */
148 - static int foreign_child(const char *dir)
149 - {
150 - struct stat st;
151 - int fd;
152 -
153 - if (enter_userns(0, 0))
154 - return CHILD_USERNS;
155 -
156 - fd = sys_open_tree(AT_FDCWD, dir, OPEN_TREE_NAMESPACE | OPEN_TREE_CLOEXEC);
157 - if (fd >= 0)
158 - return CHILD_NONREC_ALLOWED;
159 - if (errno != EINVAL)
160 - return CHILD_NONREC_ERRNO;
161 -
162 - fd = sys_open_tree(AT_FDCWD, dir,
163 - OPEN_TREE_NAMESPACE | OPEN_TREE_CLOEXEC | AT_RECURSIVE);
164 - if (fd < 0)
165 - return CHILD_REC_REFUSED;
166 - if (setns(fd, CLONE_NEWNS))
167 - return CHILD_SETNS;
168 - if (stat("/covered", &st))
169 - return CHILD_NO_COVER;
170 - if (!access("/covered/under.txt", F_OK) || errno != ENOENT)
171 - return CHILD_REVEALED;
172 - return CHILD_OK;
173 - }
174 -
175 - TEST_F(open_tree_ns_covered, foreign_user_namespace)
176 - {
177 - int status, fd;
178 - pid_t pid;
179 -
180 - pid = fork();
181 - ASSERT_GE(pid, 0);
182 - if (pid == 0)
183 - _exit(foreign_child(self->dir));
184 - ASSERT_EQ(waitpid(pid, &status, 0), pid);
185 - ASSERT_TRUE(WIFEXITED(status));
186 - ASSERT_EQ(WEXITSTATUS(status), CHILD_OK);
187 -
188 - /* the owner of the mount namespace keeps bind mount semantics */
189 - fd = sys_open_tree(AT_FDCWD, self->dir,
190 - OPEN_TREE_NAMESPACE | OPEN_TREE_CLOEXEC);
191 - ASSERT_GE(fd, 0);
192 - close(fd);
193 - }
194 -
195 - TEST_HARNESS_MAIN
modified tools/testing/selftests/filesystems/overlayfs/.gitignore
@@ -2,4 +2,3 @@
2 2 dev_in_maps
3 3 set_layers_via_fds
4 4 idmapped_mounts
5 - automount_in_layer
modified tools/testing/selftests/filesystems/overlayfs/Makefile
@@ -9,7 +9,6 @@ LOCAL_HDRS += ../wrappers.h log.h
9 9 TEST_GEN_PROGS := dev_in_maps
10 10 TEST_GEN_PROGS += set_layers_via_fds
11 11 TEST_GEN_PROGS += idmapped_mounts
12 - TEST_GEN_PROGS += automount_in_layer
13 12
14 13 include ../../lib.mk
15 14
deleted tools/testing/selftests/filesystems/overlayfs/automount_in_layer.c mode 100644
@@ -1,174 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * A layer of an overlay is a private clone of the mount it was given and
4 - * belongs to no mount namespace. fanotify hands out descriptors on it. An
5 - * automount triggered through one has no namespace to go into: the open has
6 - * to fail, not oops with namespace_sem held.
7 - */
8 - #define _GNU_SOURCE
9 - #include <dirent.h>
10 - #include <errno.h>
11 - #include <fcntl.h>
12 - #include <poll.h>
13 - #include <sched.h>
14 - #include <stdio.h>
15 - #include <stdlib.h>
16 - #include <string.h>
17 - #include <unistd.h>
18 - #include <linux/magic.h>
19 - #include <sys/fanotify.h>
20 - #include <sys/mount.h>
21 - #include <sys/stat.h>
22 - #include <sys/vfs.h>
23 -
24 - #include "../../kselftest_harness.h"
25 -
26 - #define DIR_LEN 64
27 - #define PATH_LEN 192
28 -
29 - static bool have_fs(const char *name)
30 - {
31 - char line[128];
32 - bool found = false;
33 - FILE *f;
34 -
35 - f = fopen("/proc/filesystems", "re");
36 - if (!f)
37 - return false;
38 - while (fgets(line, sizeof(line), f)) {
39 - char *nl = strchr(line, '\n');
40 - char *tab = strchr(line, '\t');
41 -
42 - if (nl)
43 - *nl = 0;
44 - if (tab && !strcmp(tab + 1, name))
45 - found = true;
46 - }
47 - fclose(f);
48 - return found;
49 - }
50 -
51 - static int mnt_id_of(int fd)
52 - {
53 - char path[64], buf[4096], *p;
54 - ssize_t n;
55 - int info;
56 -
57 - snprintf(path, sizeof(path), "/proc/self/fdinfo/%d", fd);
58 - info = open(path, O_RDONLY | O_CLOEXEC);
59 - if (info < 0)
60 - return -1;
61 - n = read(info, buf, sizeof(buf) - 1);
62 - close(info);
63 - if (n <= 0)
64 - return -1;
65 - buf[n] = 0;
66 - p = strstr(buf, "mnt_id:");
67 - return p ? atoi(p + strlen("mnt_id:")) : -1;
68 - }
69 -
70 - static bool on_debugfs(int fd)
71 - {
72 - struct statfs sf;
73 -
74 - return !fstatfs(fd, &sf) && sf.f_type == DEBUGFS_MAGIC;
75 - }
76 -
77 - FIXTURE(layer) {
78 - char base[DIR_LEN];
79 - int fan;
80 - int evfd; /* on the layer clone of the lower debugfs */
81 - };
82 -
83 - FIXTURE_SETUP(layer)
84 - {
85 - char lower[PATH_LEN], other[PATH_LEN], ovl[PATH_LEN], opts[2 * PATH_LEN + 16];
86 - struct fanotify_event_metadata *ev;
87 - struct pollfd pfd;
88 - char buf[4096];
89 - int lfd, lower_id;
90 - ssize_t n;
91 - DIR *d;
92 -
93 - self->fan = -1;
94 - self->evfd = -1;
95 - if (geteuid())
96 - SKIP(return, "test requires root");
97 - if (!have_fs("debugfs") || !have_fs("tracefs"))
98 - SKIP(return, "test requires debugfs with the tracefs automount");
99 - if (!have_fs("overlay"))
100 - SKIP(return, "test requires overlayfs");
101 -
102 - snprintf(self->base, sizeof(self->base), "/tmp/layer.XXXXXX");
103 - ASSERT_NE(mkdtemp(self->base), NULL);
104 - ASSERT_EQ(unshare(CLONE_NEWNS), 0);
105 - ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
106 - ASSERT_EQ(mount("tmpfs", self->base, "tmpfs", 0, "mode=0755"), 0);
107 - snprintf(lower, sizeof(lower), "%s/lower", self->base);
108 - snprintf(other, sizeof(other), "%s/other", self->base);
109 - snprintf(ovl, sizeof(ovl), "%s/ovl", self->base);
110 - ASSERT_EQ(mkdir(lower, 0755), 0);
111 - ASSERT_EQ(mkdir(other, 0755), 0);
112 - ASSERT_EQ(mkdir(ovl, 0755), 0);
113 - ASSERT_EQ(mount("debugfs", lower, "debugfs", 0, NULL), 0);
114 - snprintf(opts, sizeof(opts), "lowerdir=%s:%s", lower, other);
115 - ASSERT_EQ(mount("overlay", ovl, "overlay", MS_RDONLY, opts), 0);
116 -
117 - self->fan = fanotify_init(FAN_CLASS_NOTIF | FAN_NONBLOCK | FAN_CLOEXEC,
118 - O_RDONLY | O_CLOEXEC);
119 - ASSERT_GE(self->fan, 0);
120 - ASSERT_EQ(fanotify_mark(self->fan, FAN_MARK_ADD | FAN_MARK_FILESYSTEM,
121 - FAN_OPEN | FAN_ONDIR, AT_FDCWD, lower), 0);
122 - lfd = open(lower, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
123 - ASSERT_GE(lfd, 0);
124 - lower_id = mnt_id_of(lfd);
125 - close(lfd);
126 -
127 - /* the overlay opens its lower directory through the layer clone */
128 - d = opendir(ovl);
129 - ASSERT_NE(d, NULL);
130 - closedir(d);
131 - pfd.fd = self->fan;
132 - pfd.events = POLLIN;
133 - ASSERT_EQ(poll(&pfd, 1, 5000), 1);
134 - n = read(self->fan, buf, sizeof(buf));
135 - ASSERT_GT(n, 0);
136 - for (ev = (void *)buf; FAN_EVENT_OK(ev, n); ev = FAN_EVENT_NEXT(ev, n)) {
137 - if (ev->fd < 0)
138 - continue;
139 - if (self->evfd < 0 && on_debugfs(ev->fd) &&
140 - mnt_id_of(ev->fd) != lower_id)
141 - self->evfd = ev->fd;
142 - else
143 - close(ev->fd);
144 - }
145 - ASSERT_GE(self->evfd, 0)
146 - TH_LOG("no event on the layer clone");
147 - }
148 -
149 - FIXTURE_TEARDOWN(layer)
150 - {
151 - if (self->evfd >= 0)
152 - close(self->evfd);
153 - if (self->fan >= 0)
154 - close(self->fan);
155 - umount2(self->base, MNT_DETACH);
156 - rmdir(self->base);
157 - }
158 -
159 - TEST_F(layer, automount_below_the_clone_is_refused)
160 - {
161 - struct stat st;
162 - int fd;
163 -
164 - /* the automount point is there */
165 - ASSERT_EQ(fstatat(self->evfd, "tracing", &st, AT_NO_AUTOMOUNT), 0);
166 - /* the clone is in no namespace, so the automount has nowhere to go */
167 - fd = openat(self->evfd, "tracing", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
168 - EXPECT_LT(fd, 0);
169 - EXPECT_EQ(errno, EINVAL);
170 - if (fd >= 0)
171 - close(fd);
172 - }
173 -
174 - TEST_HARNESS_MAIN
deleted tools/testing/selftests/filesystems/readdir_hold.h mode 100644
@@ -1,224 +0,0 @@
1 - /* SPDX-License-Identifier: GPL-2.0 */
2 - /*
3 - * Hold a readdir of a directory in the page fault of its buffer and see
4 - * whether a create and a lookup in that directory wait for it. For a
5 - * directory that is permanently empty they must not.
6 - */
7 - #ifndef __SELFTESTS_READDIR_HOLD_H
8 - #define __SELFTESTS_READDIR_HOLD_H
9 -
10 - #include <errno.h>
11 - #include <fcntl.h>
12 - #include <poll.h>
13 - #include <pthread.h>
14 - #include <stdbool.h>
15 - #include <stdio.h>
16 - #include <stdlib.h>
17 - #include <string.h>
18 - #include <unistd.h>
19 - #include <linux/userfaultfd.h>
20 - #include <sys/ioctl.h>
21 - #include <sys/mman.h>
22 - #include <sys/stat.h>
23 - #include <sys/syscall.h>
24 -
25 - #define HOLD_FAULT_MS 5000 /* for the reader to reach the fault */
26 - #define HOLD_QUEUE_MS 2000 /* for the create to queue up behind it */
27 - #define HOLD_LOOKUP_MS 5000 /* for the lookup to come back */
28 -
29 - struct readdir_hold {
30 - int uffd;
31 - int taskdir; /* /proc/self/task, from before any namespace change */
32 - long page_size;
33 - char *page; /* faults until released */
34 - int dfd;
35 - pid_t creator_tid;
36 - int created;
37 - int done[2]; /* the finder writes a byte when it is back */
38 - };
39 -
40 - /*
41 - * The fault happens in the kernel, so the userfaultfd needs CAP_SYS_PTRACE
42 - * in the initial user namespace or vm.unprivileged_userfaultfd. Call this
43 - * before entering a user namespace.
44 - */
45 - static inline int readdir_hold_init(struct readdir_hold *h)
46 - {
47 - struct uffdio_api api = { .api = UFFD_API };
48 -
49 - h->page = MAP_FAILED;
50 - h->page_size = sysconf(_SC_PAGESIZE);
51 - h->taskdir = open("/proc/self/task", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
52 - h->uffd = syscall(__NR_userfaultfd, O_CLOEXEC | O_NONBLOCK);
53 - if (h->uffd < 0 || h->taskdir < 0 || ioctl(h->uffd, UFFDIO_API, &api)) {
54 - if (h->uffd >= 0)
55 - close(h->uffd);
56 - if (h->taskdir >= 0)
57 - close(h->taskdir);
58 - h->uffd = h->taskdir = -1;
59 - return -1;
60 - }
61 - return 0;
62 - }
63 -
64 - static inline void readdir_hold_destroy(struct readdir_hold *h)
65 - {
66 - if (h->uffd >= 0)
67 - close(h->uffd);
68 - if (h->taskdir >= 0)
69 - close(h->taskdir);
70 - h->uffd = h->taskdir = -1;
71 - }
72 -
73 - static inline void *readdir_hold_reader(void *arg)
74 - {
75 - struct readdir_hold *h = arg;
76 -
77 - /* the first byte written to the buffer faults until released */
78 - syscall(__NR_getdents64, h->dfd, h->page, h->page_size);
79 - return NULL;
80 - }
81 -
82 - static inline void *readdir_hold_creator(void *arg)
83 - {
84 - struct readdir_hold *h = arg;
85 -
86 - h->creator_tid = syscall(__NR_gettid);
87 - /* takes the directory lock exclusive before it fails */
88 - mkdirat(h->dfd, "x", 0755);
89 - __atomic_store_n(&h->created, 1, __ATOMIC_RELEASE);
90 - return NULL;
91 - }
92 -
93 - static inline void *readdir_hold_finder(void *arg)
94 - {
95 - struct readdir_hold *h = arg;
96 - int fd;
97 -
98 - /* a lookup that misses the dcache takes the lock shared */
99 - fd = openat(h->dfd, "no_such_name", O_RDONLY | O_CLOEXEC);
100 - if (fd >= 0)
101 - close(fd);
102 - if (write(h->done[1], "x", 1) != 1)
103 - perror("readdir_hold: finder");
104 - return NULL;
105 - }
106 -
107 - /* the creator is back, or waits in the kernel for the lock */
108 - static inline bool readdir_hold_creator_settled(struct readdir_hold *h)
109 - {
110 - char path[32], buf[256], *p;
111 - ssize_t n;
112 - int fd;
113 -
114 - if (__atomic_load_n(&h->created, __ATOMIC_ACQUIRE))
115 - return true;
116 - if (!h->creator_tid)
117 - return false;
118 - snprintf(path, sizeof(path), "%d/stat", h->creator_tid);
119 - fd = openat(h->taskdir, path, O_RDONLY | O_CLOEXEC);
120 - if (fd < 0)
121 - return false;
122 - n = read(fd, buf, sizeof(buf) - 1);
123 - close(fd);
124 - if (n <= 0)
125 - return false;
126 - buf[n] = 0;
127 - /* "pid (comm) state ..." */
128 - p = strrchr(buf, ')');
129 - return p && p[1] == ' ' && p[2] == 'D';
130 - }
131 -
132 - static inline bool readdir_hold_faulted(struct readdir_hold *h)
133 - {
134 - struct pollfd pfd = { .fd = h->uffd, .events = POLLIN };
135 - struct uffd_msg msg;
136 -
137 - if (poll(&pfd, 1, HOLD_FAULT_MS) != 1)
138 - return false;
139 - if (read(h->uffd, &msg, sizeof(msg)) != sizeof(msg))
140 - return false;
141 - return msg.event == UFFD_EVENT_PAGEFAULT;
142 - }
143 -
144 - /* let the reader go on */
145 - static inline void readdir_hold_release(struct readdir_hold *h)
146 - {
147 - struct uffdio_copy cp = {
148 - .dst = (unsigned long)h->page,
149 - .len = h->page_size,
150 - };
151 - void *zero;
152 -
153 - zero = calloc(1, h->page_size);
154 - if (!zero)
155 - return;
156 - cp.src = (unsigned long)zero;
157 - if (ioctl(h->uffd, UFFDIO_COPY, &cp) && errno != EEXIST)
158 - perror("readdir_hold: UFFDIO_COPY");
159 - free(zero);
160 - }
161 -
162 - /*
163 - * A readdir of @dfd that sticks in the fault of its buffer, then a create
164 - * and a lookup in @dfd. Whether the lookup came back while the readdir was
165 - * still stuck goes to @stalled. Returns -1 when that could not be found
166 - * out.
167 - */
168 - static inline int readdir_hold_check(struct readdir_hold *h, int dfd,
169 - bool *stalled)
170 - {
171 - pthread_t reader, creator, finder;
172 - struct uffdio_register reg = {};
173 - struct pollfd pfd;
174 - int ret = -1, i;
175 -
176 - h->dfd = dfd;
177 - h->created = 0;
178 - h->creator_tid = 0;
179 - h->page = mmap(NULL, h->page_size, PROT_READ | PROT_WRITE,
180 - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
181 - if (h->page == MAP_FAILED)
182 - return -1;
183 - reg.range.start = (unsigned long)h->page;
184 - reg.range.len = h->page_size;
185 - reg.mode = UFFDIO_REGISTER_MODE_MISSING;
186 - if (ioctl(h->uffd, UFFDIO_REGISTER, &reg) || pipe2(h->done, O_CLOEXEC))
187 - goto out_page;
188 -
189 - if (pthread_create(&reader, NULL, readdir_hold_reader, h))
190 - goto out_pipe;
191 - if (!readdir_hold_faulted(h))
192 - goto out_reader;
193 - if (pthread_create(&creator, NULL, readdir_hold_creator, h))
194 - goto out_reader;
195 - for (i = 0; i < HOLD_QUEUE_MS / 10 && !readdir_hold_creator_settled(h); i++)
196 - usleep(10000);
197 - if (pthread_create(&finder, NULL, readdir_hold_finder, h))
198 - goto out_creator;
199 -
200 - pfd.fd = h->done[0];
201 - pfd.events = POLLIN;
202 - *stalled = poll(&pfd, 1, HOLD_LOOKUP_MS) != 1;
203 - ret = 0;
204 -
205 - readdir_hold_release(h);
206 - pthread_join(finder, NULL);
207 - out_creator:
208 - if (ret)
209 - readdir_hold_release(h);
210 - pthread_join(creator, NULL);
211 - out_reader:
212 - if (ret)
213 - readdir_hold_release(h);
214 - pthread_join(reader, NULL);
215 - out_pipe:
216 - close(h->done[0]);
217 - close(h->done[1]);
218 - out_page:
219 - munmap(h->page, h->page_size);
220 - h->page = MAP_FAILED;
221 - return ret;
222 - }
223 -
224 - #endif /* __SELFTESTS_READDIR_HOLD_H */
deleted tools/testing/selftests/filesystems/rw_hint_test.c mode 100644
@@ -1,129 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * F_SET_RW_HINT is refused on an immutable inode. Nothing is ever written
4 - * to it and it may be shared with everybody, like a namespace file or the
5 - * root of an empty mount namespace.
6 - */
7 - #define _GNU_SOURCE
8 - #include <errno.h>
9 - #include <fcntl.h>
10 - #include <sched.h>
11 - #include <stdint.h>
12 - #include <stdio.h>
13 - #include <stdlib.h>
14 - #include <string.h>
15 - #include <unistd.h>
16 - #include <sys/ioctl.h>
17 - #include <sys/stat.h>
18 - #include <sys/wait.h>
19 -
20 - #include "../kselftest_harness.h"
21 -
22 - /* <linux/fs.h> and <linux/fcntl.h> don't mix with the libc headers */
23 - #ifndef FS_IOC_GETFLAGS
24 - #define FS_IOC_GETFLAGS _IOR('f', 1, long)
25 - #define FS_IOC_SETFLAGS _IOW('f', 2, long)
26 - #endif
27 - #ifndef FS_IMMUTABLE_FL
28 - #define FS_IMMUTABLE_FL 0x00000010
29 - #endif
30 - #ifndef F_LINUX_SPECIFIC_BASE
31 - #define F_LINUX_SPECIFIC_BASE 1024
32 - #endif
33 - #ifndef F_GET_RW_HINT
34 - #define F_GET_RW_HINT (F_LINUX_SPECIFIC_BASE + 11)
35 - #define F_SET_RW_HINT (F_LINUX_SPECIFIC_BASE + 12)
36 - #endif
37 - #ifndef RWH_WRITE_LIFE_SHORT
38 - #define RWH_WRITE_LIFE_SHORT 2
39 - #endif
40 - #ifndef UNSHARE_EMPTY_MNTNS
41 - #define UNSHARE_EMPTY_MNTNS 0x00100000
42 - #endif
43 -
44 - static int set_hint(int fd, uint64_t hint)
45 - {
46 - return fcntl(fd, F_SET_RW_HINT, &hint);
47 - }
48 -
49 - static long get_hint(int fd)
50 - {
51 - uint64_t hint;
52 -
53 - if (fcntl(fd, F_GET_RW_HINT, &hint))
54 - return -1;
55 - return hint;
56 - }
57 -
58 - TEST(immutable_file)
59 - {
60 - char path[] = "/tmp/rw_hint.XXXXXX";
61 - int fd, flags;
62 -
63 - if (geteuid())
64 - SKIP(return, "test requires root");
65 -
66 - fd = mkstemp(path);
67 - ASSERT_GE(fd, 0);
68 - unlink(path);
69 - ASSERT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), 0);
70 - EXPECT_EQ(get_hint(fd), RWH_WRITE_LIFE_SHORT);
71 -
72 - if (ioctl(fd, FS_IOC_GETFLAGS, &flags)) {
73 - close(fd);
74 - SKIP(return, "no file attributes on this filesystem");
75 - }
76 - flags |= FS_IMMUTABLE_FL;
77 - ASSERT_EQ(ioctl(fd, FS_IOC_SETFLAGS, &flags), 0);
78 - EXPECT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), -1);
79 - EXPECT_EQ(errno, EPERM);
80 - flags &= ~FS_IMMUTABLE_FL;
81 - ASSERT_EQ(ioctl(fd, FS_IOC_SETFLAGS, &flags), 0);
82 - EXPECT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), 0);
83 - close(fd);
84 - }
85 -
86 - TEST(namespace_file)
87 - {
88 - int fd;
89 -
90 - if (geteuid())
91 - SKIP(return, "test requires root");
92 -
93 - fd = open("/proc/self/ns/mnt", O_RDONLY | O_CLOEXEC);
94 - ASSERT_GE(fd, 0);
95 - EXPECT_EQ(set_hint(fd, RWH_WRITE_LIFE_SHORT), -1);
96 - EXPECT_EQ(errno, EPERM);
97 - close(fd);
98 - }
99 -
100 - TEST(empty_mntns_root)
101 - {
102 - int status;
103 - pid_t pid;
104 -
105 - if (geteuid())
106 - SKIP(return, "test requires root");
107 -
108 - pid = fork();
109 - ASSERT_GE(pid, 0);
110 - if (pid == 0) {
111 - int fd;
112 -
113 - if (unshare(UNSHARE_EMPTY_MNTNS))
114 - _exit(errno == EINVAL ? 100 : 1);
115 - fd = open("/", O_RDONLY | O_DIRECTORY | O_CLOEXEC);
116 - if (fd < 0)
117 - _exit(2);
118 - if (set_hint(fd, RWH_WRITE_LIFE_SHORT) == 0)
119 - _exit(3);
120 - _exit(errno == EPERM ? 0 : 4);
121 - }
122 - ASSERT_EQ(waitpid(pid, &status, 0), pid);
123 - ASSERT_TRUE(WIFEXITED(status));
124 - if (WEXITSTATUS(status) == 100)
125 - SKIP(return, "UNSHARE_EMPTY_MNTNS not supported");
126 - EXPECT_EQ(WEXITSTATUS(status), 0);
127 - }
128 -
129 - TEST_HARNESS_MAIN
deleted tools/testing/selftests/filesystems/umount_propagation/Makefile mode 100644
@@ -1,6 +0,0 @@
1 - # SPDX-License-Identifier: GPL-2.0
2 - TEST_GEN_PROGS := umount_propagation_test shrink_submounts_test locked_mount_test
3 -
4 - CFLAGS += -Wall -O2 -g $(KHDR_INCLUDES)
5 -
6 - include ../../lib.mk
deleted tools/testing/selftests/filesystems/umount_propagation/locked_mount_test.c mode 100644
@@ -1,432 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * MNT_LOCKED keeps the owner of a user namespace from revealing what a
4 - * mount covers. The lock has to be set on the copy in that namespace and
5 - * only there, it has to survive the expiry of a mount placed beneath the
6 - * locked one, and it has to survive the propagated umount of such a copy.
7 - */
8 - #define _GNU_SOURCE
9 - #include <errno.h>
10 - #include <fcntl.h>
11 - #include <sched.h>
12 - #include <stdio.h>
13 - #include <stdlib.h>
14 - #include <string.h>
15 - #include <unistd.h>
16 - #include <sys/mount.h>
17 - #include <sys/prctl.h>
18 - #include <sys/stat.h>
19 - #include <sys/syscall.h>
20 - #include <sys/wait.h>
21 -
22 - #include "../../kselftest_harness.h"
23 -
24 - #ifndef MOVE_MOUNT_F_EMPTY_PATH
25 - #define MOVE_MOUNT_F_EMPTY_PATH 0x00000004
26 - #endif
27 - #ifndef MOVE_MOUNT_BENEATH
28 - #define MOVE_MOUNT_BENEATH 0x00000200
29 - #endif
30 -
31 - #define DIR_LEN 64
32 - #define PATH_LEN 192
33 - #define FLAGS (MS_NOSUID | MS_NODEV | MS_NOEXEC)
34 -
35 - /* exit codes of the children, each test says what they mean */
36 - enum {
37 - CHILD_OK,
38 - CHILD_SETUP,
39 - CHILD_STEP1,
40 - CHILD_STEP2,
41 - CHILD_STEP3,
42 - CHILD_STEP4,
43 - };
44 -
45 - static int write_file(const char *path, const char *s)
46 - {
47 - ssize_t n = -1;
48 - int fd;
49 -
50 - fd = open(path, O_WRONLY | O_CLOEXEC);
51 - if (fd >= 0) {
52 - n = write(fd, s, strlen(s));
53 - close(fd);
54 - }
55 - return n == (ssize_t)strlen(s) ? 0 : -1;
56 - }
57 -
58 - static int create_file(const char *path, const char *s)
59 - {
60 - ssize_t n = -1;
61 - int fd;
62 -
63 - fd = open(path, O_WRONLY | O_CREAT | O_EXCL | O_CLOEXEC, 0644);
64 - if (fd >= 0) {
65 - n = write(fd, s, strlen(s));
66 - close(fd);
67 - }
68 - return n == (ssize_t)strlen(s) ? 0 : -1;
69 - }
70 -
71 - /* Root in a new user namespace with a copy of the mount namespace. */
72 - static int enter_userns(void)
73 - {
74 - uid_t uid = getuid();
75 - gid_t gid = getgid();
76 - char map[32];
77 -
78 - prctl(PR_SET_DUMPABLE, 1);
79 - if (unshare(CLONE_NEWUSER | CLONE_NEWNS))
80 - return -1;
81 - if (write_file("/proc/self/setgroups", "deny") && errno != ENOENT)
82 - return -1;
83 - snprintf(map, sizeof(map), "0 %d 1", uid);
84 - if (write_file("/proc/self/uid_map", map))
85 - return -1;
86 - snprintf(map, sizeof(map), "0 %d 1", gid);
87 - if (write_file("/proc/self/gid_map", map))
88 - return -1;
89 - return setgid(0) || setuid(0) ? -1 : 0;
90 - }
91 -
92 - static int wait_child(pid_t pid)
93 - {
94 - int status;
95 -
96 - if (waitpid(pid, &status, 0) != pid || !WIFEXITED(status))
97 - return -1;
98 - return WEXITSTATUS(status);
99 - }
100 -
101 - static int wait_byte(int fd)
102 - {
103 - char c;
104 -
105 - return read(fd, &c, 1) == 1 ? 0 : -1;
106 - }
107 -
108 - static int send_byte(int fd)
109 - {
110 - return write(fd, "x", 1) == 1 ? 0 : -1;
111 - }
112 -
113 - /* A read of @path fails: the file is covered. */
114 - static bool covered(const char *path)
115 - {
116 - int fd = open(path, O_RDONLY | O_CLOEXEC);
117 -
118 - if (fd >= 0)
119 - close(fd);
120 - return fd < 0;
121 - }
122 -
123 - FIXTURE(locked_mount) {
124 - char base[DIR_LEN];
125 - bool tracing; /* debugfs with the tracefs automount is there */
126 - };
127 -
128 - FIXTURE_SETUP(locked_mount)
129 - {
130 - char p[PATH_LEN];
131 - struct stat st;
132 -
133 - if (geteuid())
134 - SKIP(return, "test requires root");
135 -
136 - snprintf(self->base, sizeof(self->base), "/tmp/locked_mount.XXXXXX");
137 - ASSERT_NE(mkdtemp(self->base), NULL);
138 - ASSERT_EQ(unshare(CLONE_NEWNS), 0);
139 - ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
140 - ASSERT_EQ(mount("tmpfs", self->base, "tmpfs", 0, "mode=0755"), 0);
141 -
142 - /* an automount that a user can name: the tracefs below debugfs */
143 - snprintf(p, sizeof(p), "%s/dbg", self->base);
144 - ASSERT_EQ(mkdir(p, 0755), 0);
145 - self->tracing = !mount("debugfs", p, "debugfs", FLAGS, NULL);
146 - if (self->tracing) {
147 - /* the cases trigger it themselves */
148 - snprintf(p, sizeof(p), "%s/dbg/tracing", self->base);
149 - self->tracing = !fstatat(AT_FDCWD, p, &st, AT_NO_AUTOMOUNT) &&
150 - S_ISDIR(st.st_mode);
151 - }
152 - }
153 -
154 - FIXTURE_TEARDOWN(locked_mount)
155 - {
156 - umount2(self->base, MNT_DETACH);
157 - rmdir(self->base);
158 - }
159 -
160 - /*
161 - * The child keeps a directory descriptor on the host's debugfs mount, moves
162 - * to a user namespace of its own and triggers the automount through the
163 - * descriptor. The mount goes below the host's mount and propagates into the
164 - * child's copy. The child's copy has to be locked, the host's not.
165 - */
166 - static int automount_child(const char *base, int dfd, int to_host, int from_host)
167 - {
168 - char p[PATH_LEN];
169 - struct stat st;
170 -
171 - if (enter_userns())
172 - return CHILD_SETUP;
173 - if (fstatat(dfd, "tracing/.", &st, 0))
174 - return CHILD_STEP1;
175 - if (send_byte(to_host) || wait_byte(from_host))
176 - return CHILD_SETUP;
177 - /* the flags of the copy are locked: EPERM */
178 - snprintf(p, sizeof(p), "%s/dbg/tracing", base);
179 - if (!mount(NULL, p, NULL, MS_REMOUNT | MS_BIND, NULL) || errno != EPERM)
180 - return CHILD_STEP2;
181 - return CHILD_OK;
182 - }
183 -
184 - TEST_F(locked_mount, automount_locked_in_the_triggering_namespace)
185 - {
186 - int to_host[2], from_host[2], dfd, ret;
187 - char p[PATH_LEN];
188 - pid_t pid;
189 -
190 - if (!self->tracing)
191 - SKIP(return, "test requires debugfs with the tracefs automount");
192 -
193 - snprintf(p, sizeof(p), "%s/dbg", self->base);
194 - ASSERT_EQ(mount(NULL, p, NULL, MS_SHARED, NULL), 0);
195 - dfd = open(p, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
196 - ASSERT_GE(dfd, 0);
197 - ASSERT_EQ(pipe(to_host), 0);
198 - ASSERT_EQ(pipe(from_host), 0);
199 -
200 - pid = fork();
201 - ASSERT_GE(pid, 0);
202 - if (pid == 0)
203 - _exit(automount_child(self->base, dfd, to_host[1], from_host[0]));
204 - close(dfd);
205 - ASSERT_EQ(wait_byte(to_host[0]), 0);
206 -
207 - /* the host's own mount isn't locked: the flags can go */
208 - snprintf(p, sizeof(p), "%s/dbg/tracing", self->base);
209 - EXPECT_EQ(mount(NULL, p, NULL, MS_REMOUNT | MS_BIND, NULL), 0);
210 -
211 - ASSERT_EQ(send_byte(from_host[1]), 0);
212 - ret = wait_child(pid);
213 - TH_LOG("child exit code %d", ret);
214 - EXPECT_EQ(ret, CHILD_OK);
215 - }
216 -
217 - /*
218 - * A copy of a tree with a locked cover. The child puts a shrinkable mount
219 - * beneath the cover, which hands the lock down, unmounts the cover and then
220 - * asks for the umount of an unlocked ancestor. That expires the shrinkable
221 - * mount on a kernel that doesn't look at the lock, and the covered
222 - * directory is bare.
223 - */
224 - static int expiry_child(const char *base)
225 - {
226 - char srv[PATH_LEN], shr[PATH_LEN], x[PATH_LEN], c[PATH_LEN];
227 - char hidden[PATH_LEN], secret[PATH_LEN];
228 -
229 - snprintf(srv, sizeof(srv), "%s/srv", base);
230 - snprintf(shr, sizeof(shr), "%s/shr", base);
231 - snprintf(x, sizeof(x), "%s/x", base);
232 - snprintf(c, sizeof(c), "%s/c", base);
233 - snprintf(hidden, sizeof(hidden), "%s/x/hidden", base);
234 - snprintf(secret, sizeof(secret), "%s/x/hidden/secret", base);
235 -
236 - if (enter_userns())
237 - return CHILD_SETUP;
238 - if (mount(srv, x, NULL, MS_BIND | MS_REC, NULL) ||
239 - mount(shr, c, NULL, MS_BIND, NULL))
240 - return CHILD_SETUP;
241 - /* the cover is locked */
242 - if (!umount2(hidden, 0) || errno != EINVAL)
243 - return CHILD_STEP1;
244 - if (syscall(__NR_move_mount, AT_FDCWD, c, AT_FDCWD, hidden, MOVE_MOUNT_BENEATH))
245 - return CHILD_STEP2;
246 - /* the lock moved down, the cover may go */
247 - if (umount2(hidden, 0))
248 - return CHILD_STEP3;
249 - /* the holder of the lock may not, in any way */
250 - if (!umount2(hidden, 0) || errno != EINVAL)
251 - return CHILD_STEP4;
252 - if (chdir(x))
253 - return CHILD_SETUP;
254 - umount2(x, 0);
255 - return covered(secret) ? CHILD_OK : CHILD_STEP4;
256 - }
257 -
258 - TEST_F(locked_mount, expiry_leaves_a_locked_mount_alone)
259 - {
260 - char p[PATH_LEN], q[PATH_LEN];
261 - pid_t pid;
262 - int ret;
263 -
264 - if (!self->tracing)
265 - SKIP(return, "test requires debugfs with the tracefs automount");
266 -
267 - snprintf(p, sizeof(p), "%s/dbg/tracing", self->base);
268 - snprintf(q, sizeof(q), "%s/shr", self->base);
269 - ASSERT_EQ(mkdir(q, 0755), 0);
270 - /* a bind of an automount is shrinkable as well */
271 - ASSERT_EQ(mount(p, q, NULL, MS_BIND, NULL), 0);
272 - snprintf(p, sizeof(p), "%s/srv", self->base);
273 - ASSERT_EQ(mkdir(p, 0755), 0);
274 - ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, "mode=0755"), 0);
275 - snprintf(p, sizeof(p), "%s/srv/hidden", self->base);
276 - ASSERT_EQ(mkdir(p, 0755), 0);
277 - snprintf(p, sizeof(p), "%s/srv/hidden/secret", self->base);
278 - ASSERT_EQ(create_file(p, "covered-by-root\n"), 0);
279 - snprintf(p, sizeof(p), "%s/srv/hidden", self->base);
280 - ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, "mode=0755"), 0);
281 - snprintf(p, sizeof(p), "%s/x", self->base);
282 - ASSERT_EQ(mkdir(p, 0755), 0);
283 - snprintf(p, sizeof(p), "%s/c", self->base);
284 - ASSERT_EQ(mkdir(p, 0755), 0);
285 -
286 - pid = fork();
287 - ASSERT_GE(pid, 0);
288 - if (pid == 0)
289 - _exit(expiry_child(self->base));
290 - ret = wait_child(pid);
291 - TH_LOG("child exit code %d", ret);
292 - EXPECT_EQ(ret, CHILD_OK);
293 - }
294 -
295 - /*
296 - * The copy of the mount tree that a user namespace gets at its creation has
297 - * the automounts in it locked unless they are on an expiry list. A bind of
298 - * such a tree inside the namespace copies the lock to the automount but not
299 - * to the root of the bind, so the child may ask for the umount of that root.
300 - * That must not expire the locked automount below it: the root is busy, the
301 - * umount fails and the automount has to be there afterwards.
302 - */
303 - static int copied_tree_child(const char *base)
304 - {
305 - char dbg[PATH_LEN], x[PATH_LEN], tracing[PATH_LEN];
306 - struct stat root, st;
307 -
308 - snprintf(dbg, sizeof(dbg), "%s/dbg", base);
309 - snprintf(x, sizeof(x), "%s/x", base);
310 - snprintf(tracing, sizeof(tracing), "%s/x/tracing", base);
311 -
312 - if (enter_userns())
313 - return CHILD_SETUP;
314 - if (mount(dbg, x, NULL, MS_BIND | MS_REC, NULL))
315 - return CHILD_SETUP;
316 - /* the copy of the automount carries the lock */
317 - if (!umount2(tracing, 0) || errno != EINVAL)
318 - return CHILD_STEP1;
319 - /* the root of the bind doesn't; keep it busy */
320 - if (chdir(x))
321 - return CHILD_SETUP;
322 - if (!umount2(x, 0) || errno != EBUSY)
323 - return CHILD_STEP2;
324 - /* the automount below it must not have gone */
325 - if (stat(x, &root) || fstatat(AT_FDCWD, tracing, &st, AT_NO_AUTOMOUNT))
326 - return CHILD_SETUP;
327 - return st.st_dev != root.st_dev ? CHILD_OK : CHILD_STEP3;
328 - }
329 -
330 - TEST_F(locked_mount, umount_of_a_bind_leaves_a_locked_automount_alone)
331 - {
332 - char p[PATH_LEN];
333 - struct stat st;
334 - pid_t pid;
335 - int ret;
336 -
337 - if (!self->tracing)
338 - SKIP(return, "test requires debugfs with the tracefs automount");
339 -
340 - /* the copy the child gets has to contain the automount */
341 - snprintf(p, sizeof(p), "%s/dbg/tracing/.", self->base);
342 - ASSERT_EQ(stat(p, &st), 0);
343 - snprintf(p, sizeof(p), "%s/x", self->base);
344 - ASSERT_EQ(mkdir(p, 0755), 0);
345 -
346 - pid = fork();
347 - ASSERT_GE(pid, 0);
348 - if (pid == 0)
349 - _exit(copied_tree_child(self->base));
350 - ret = wait_child(pid);
351 - TH_LOG("child exit code %d", ret);
352 - EXPECT_EQ(ret, CHILD_OK);
353 - }
354 -
355 - /*
356 - * Z is a user namespace with a copy of a tree in which P/d is covered by a
357 - * locked mount. The host mounts X on P/d, which propagates beneath Z's
358 - * cover, and unmounts it again. Z's cover has to be locked afterwards as
359 - * it was before.
360 - */
361 - static int propagation_child(const char *base, int to_host, int from_host)
362 - {
363 - char d[PATH_LEN], secret[PATH_LEN];
364 -
365 - snprintf(d, sizeof(d), "%s/P/d", base);
366 - snprintf(secret, sizeof(secret), "%s/P/d/secret", base);
367 -
368 - if (enter_userns())
369 - return CHILD_SETUP;
370 - /* the cover is locked */
371 - if (!umount2(d, 0) || errno != EINVAL)
372 - return CHILD_STEP1;
373 - if (send_byte(to_host) || wait_byte(from_host))
374 - return CHILD_SETUP;
375 - /* X came and went beneath it: still locked */
376 - if (!umount2(d, 0) || errno != EINVAL)
377 - return CHILD_STEP2;
378 - return covered(secret) ? CHILD_OK : CHILD_STEP3;
379 - }
380 -
381 - TEST_F(locked_mount, propagated_copy_keeps_the_cover_locked)
382 - {
383 - int to_host[2], from_host[2], ret;
384 - char p[PATH_LEN];
385 - pid_t pid;
386 -
387 - snprintf(p, sizeof(p), "%s/P", self->base);
388 - ASSERT_EQ(mkdir(p, 0755), 0);
389 - ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, "mode=0755"), 0);
390 - ASSERT_EQ(mount(NULL, p, NULL, MS_SHARED, NULL), 0);
391 - snprintf(p, sizeof(p), "%s/P/d", self->base);
392 - ASSERT_EQ(mkdir(p, 0755), 0);
393 - snprintf(p, sizeof(p), "%s/P/d/secret", self->base);
394 - ASSERT_EQ(create_file(p, "covered-by-root\n"), 0);
395 - ASSERT_EQ(pipe(to_host), 0);
396 - ASSERT_EQ(pipe(from_host), 0);
397 -
398 - pid = fork();
399 - ASSERT_GE(pid, 0);
400 - if (pid == 0) {
401 - /* M: a manager's namespace that covers P/d for Z */
402 - pid_t z;
403 -
404 - if (unshare(CLONE_NEWNS))
405 - _exit(CHILD_SETUP);
406 - snprintf(p, sizeof(p), "%s/P", self->base);
407 - if (mount(NULL, p, NULL, MS_SLAVE, NULL))
408 - _exit(CHILD_SETUP);
409 - snprintf(p, sizeof(p), "%s/P/d", self->base);
410 - if (mount("tmpfs", p, "tmpfs", 0, "mode=0755"))
411 - _exit(CHILD_SETUP);
412 - z = fork();
413 - if (z < 0)
414 - _exit(CHILD_SETUP);
415 - if (z == 0)
416 - _exit(propagation_child(self->base, to_host[1], from_host[0]));
417 - _exit(wait_child(z));
418 - }
419 - ASSERT_EQ(wait_byte(to_host[0]), 0);
420 -
421 - /* the host mounts on P/d and unmounts again; both propagate */
422 - snprintf(p, sizeof(p), "%s/P/d", self->base);
423 - ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, "mode=0755"), 0);
424 - ASSERT_EQ(umount2(p, 0), 0);
425 -
426 - ASSERT_EQ(send_byte(from_host[1]), 0);
427 - ret = wait_child(pid);
428 - TH_LOG("child exit code %d", ret);
429 - EXPECT_EQ(ret, CHILD_OK);
430 - }
431 -
432 - TEST_HARNESS_MAIN
deleted tools/testing/selftests/filesystems/umount_propagation/shrink_submounts_test.c mode 100644
@@ -1,211 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * A synchronous umount first unmounts the shrinkable submounts of the
4 - * victim that aren't busy. Every one of them has to be checked right
5 - * before it is unmounted: unmounting one can slide a busy mount to where
6 - * the propagated copy of the next one is looked up.
7 - */
8 - #define _GNU_SOURCE
9 - #include <errno.h>
10 - #include <fcntl.h>
11 - #include <sched.h>
12 - #include <stdio.h>
13 - #include <stdlib.h>
14 - #include <string.h>
15 - #include <unistd.h>
16 - #include <sys/fanotify.h>
17 - #include <sys/mount.h>
18 - #include <sys/stat.h>
19 - #include <sys/statfs.h>
20 - #include <sys/vfs.h>
21 - #include <linux/magic.h>
22 -
23 - #include "../../kselftest_harness.h"
24 -
25 - #ifndef FAN_REPORT_MNT
26 - #define FAN_REPORT_MNT 0x00004000
27 - #endif
28 - #ifndef FAN_MARK_MNTNS
29 - #define FAN_MARK_MNTNS 0x00000110
30 - #endif
31 - #ifndef FAN_MNT_ATTACH
32 - #define FAN_MNT_ATTACH 0x01000000
33 - #endif
34 - #ifndef FAN_MNT_DETACH
35 - #define FAN_MNT_DETACH 0x02000000
36 - #endif
37 -
38 - #define DIR_LEN 64
39 - #define PATH_LEN 128
40 -
41 - FIXTURE(shrink_submounts) {
42 - char base[DIR_LEN];
43 - char automount[PATH_LEN];
44 - bool mounted;
45 - int fan;
46 - };
47 -
48 - /*
49 - * Shrinkable mounts come from an automount. The tracefs mount below debugfs
50 - * is one and bind mounts inherit the flag.
51 - */
52 - FIXTURE_SETUP(shrink_submounts)
53 - {
54 - struct stat st;
55 - char p[PATH_LEN];
56 -
57 - self->mounted = false;
58 - self->fan = -1;
59 -
60 - if (geteuid() != 0)
61 - SKIP(return, "test requires CAP_SYS_ADMIN");
62 -
63 - ASSERT_EQ(unshare(CLONE_NEWNS), 0);
64 - ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
65 -
66 - snprintf(self->base, sizeof(self->base), "/tmp/shrink_submounts.XXXXXX");
67 - ASSERT_NE(mkdtemp(self->base), NULL);
68 - ASSERT_EQ(mount("tmpfs", self->base, "tmpfs", 0, NULL), 0);
69 - self->mounted = true;
70 - ASSERT_EQ(mount(NULL, self->base, NULL, MS_PRIVATE, NULL), 0);
71 -
72 - snprintf(p, sizeof(p), "%s/dbg", self->base);
73 - ASSERT_EQ(mkdir(p, 0755), 0);
74 - if (mount("debugfs", p, "debugfs", 0, NULL)) {
75 - umount2(self->base, MNT_DETACH);
76 - rmdir(self->base);
77 - SKIP(return, "test requires debugfs");
78 - }
79 - snprintf(self->automount, sizeof(self->automount), "%s/dbg/tracing",
80 - self->base);
81 - snprintf(p, sizeof(p), "%s/dbg/tracing/.", self->base);
82 - if (stat(p, &st)) {
83 - umount2(self->base, MNT_DETACH);
84 - rmdir(self->base);
85 - SKIP(return, "test requires the tracefs automount");
86 - }
87 - }
88 -
89 - FIXTURE_TEARDOWN(shrink_submounts)
90 - {
91 - if (self->fan >= 0)
92 - close(self->fan);
93 - chdir("/");
94 - if (self->mounted)
95 - umount2(self->base, MNT_DETACH);
96 - rmdir(self->base);
97 - }
98 -
99 - static bool mounted_tmpfs(const char *path)
100 - {
101 - struct statfs st;
102 -
103 - return !statfs(path, &st) && st.f_type == TMPFS_MAGIC;
104 - }
105 -
106 - /*
107 - * P is a shared bind mount of the automount, P1 a slave of P that is shared
108 - * in turn and P2 its peer. B, another bind mount of the automount, goes on
109 - * P/options and propagates copies Bc1 and Bc2 onto P1/options and
110 - * P2/options. R, a tmpfs and our working directory, sits on top of Bc2 which
111 - * is made private first. P, with B on it, is moved to P1/instances.
112 - *
113 - * A synchronous umount of P1 unmounts the shrinkable submounts Bc1 and B
114 - * first. Unmounting Bc1 takes Bc2 along and slides R to P2/options where
115 - * the propagated copy of B is looked up next. R is busy, so B has to stay
116 - * and the umount fails with EBUSY.
117 - */
118 - TEST_F(shrink_submounts, busy_mount_moved_into_reach)
119 - {
120 - char p[PATH_LEN], p1[PATH_LEN], p2[PATH_LEN], r[PATH_LEN], cwd[PATH_LEN];
121 - int nsfd;
122 -
123 - snprintf(p, sizeof(p), "%s/p", self->base);
124 - snprintf(p1, sizeof(p1), "%s/p1", self->base);
125 - snprintf(p2, sizeof(p2), "%s/p2", self->base);
126 - ASSERT_EQ(mkdir(p, 0755), 0);
127 - ASSERT_EQ(mkdir(p1, 0755), 0);
128 - ASSERT_EQ(mkdir(p2, 0755), 0);
129 -
130 - /* watch the mount namespace so that the detached mounts get queued */
131 - self->fan = fanotify_init(FAN_REPORT_MNT, O_RDONLY);
132 - if (self->fan >= 0) {
133 - nsfd = open("/proc/self/ns/mnt", O_RDONLY | O_CLOEXEC);
134 - ASSERT_GE(nsfd, 0);
135 - EXPECT_EQ(fanotify_mark(self->fan, FAN_MARK_ADD | FAN_MARK_MNTNS,
136 - FAN_MNT_ATTACH | FAN_MNT_DETACH, nsfd, NULL), 0);
137 - close(nsfd);
138 - }
139 -
140 - ASSERT_EQ(mount(self->automount, p, NULL, MS_BIND, NULL), 0);
141 - ASSERT_EQ(mount(NULL, p, NULL, MS_SHARED, NULL), 0);
142 - ASSERT_EQ(mount(p, p1, NULL, MS_BIND, NULL), 0);
143 - ASSERT_EQ(mount(NULL, p1, NULL, MS_SLAVE, NULL), 0);
144 - ASSERT_EQ(mount(NULL, p1, NULL, MS_SHARED, NULL), 0);
145 - ASSERT_EQ(mount(p1, p2, NULL, MS_BIND, NULL), 0);
146 -
147 - /* B on P/options, copies on P1/options and P2/options */
148 - snprintf(r, sizeof(r), "%s/p/options", self->base);
149 - ASSERT_EQ(mount(self->automount, r, NULL, MS_BIND, NULL), 0);
150 -
151 - /* R on top of Bc2 */
152 - snprintf(r, sizeof(r), "%s/p2/options", self->base);
153 - ASSERT_EQ(mount(NULL, r, NULL, MS_PRIVATE, NULL), 0);
154 - ASSERT_EQ(mount("R", r, "tmpfs", 0, NULL), 0);
155 - ASSERT_EQ(chdir(r), 0);
156 -
157 - /* P, with B on it, below the victim */
158 - snprintf(cwd, sizeof(cwd), "%s/p1/instances", self->base);
159 - ASSERT_EQ(mount(p, cwd, NULL, MS_MOVE, NULL), 0);
160 -
161 - ASSERT_TRUE(mounted_tmpfs(r));
162 - ASSERT_EQ(umount2(p1, 0), -1);
163 - EXPECT_EQ(errno, EBUSY);
164 -
165 - /* R is still mounted and still our working directory */
166 - EXPECT_TRUE(mounted_tmpfs(r));
167 - ASSERT_NE(getcwd(cwd, sizeof(cwd)), NULL);
168 - EXPECT_STREQ(cwd, r);
169 - }
170 -
171 - /*
172 - * T is shared and Q, a slave of T, has T moved into it, so Q receives
173 - * propagation from its own child. M, another bind mount of the automount, is
174 - * on T/options and that is the dentry T sits on in Q. Unmounting M makes T
175 - * the propagated victim at that dentry in Q and takes T along. The shrink
176 - * walk of V has just unmounted M and continues in the children of T.
177 - */
178 - TEST_F(shrink_submounts, parent_goes_with_child)
179 - {
180 - char v[PATH_LEN], t[PATH_LEN], q[PATH_LEN], p[PATH_LEN];
181 - struct stat before, after;
182 -
183 - snprintf(v, sizeof(v), "%s/v", self->base);
184 - snprintf(t, sizeof(t), "%s/v/t", self->base);
185 - snprintf(q, sizeof(q), "%s/v/q", self->base);
186 - ASSERT_EQ(mkdir(v, 0755), 0);
187 - ASSERT_EQ(mount("V", v, "tmpfs", 0, NULL), 0);
188 - ASSERT_EQ(mount(NULL, v, NULL, MS_PRIVATE, NULL), 0);
189 - ASSERT_EQ(stat(v, &before), 0);
190 - ASSERT_EQ(mkdir(t, 0755), 0);
191 - ASSERT_EQ(mkdir(q, 0755), 0);
192 -
193 - /* T shared, M on T/options before anything receives from T */
194 - ASSERT_EQ(mount(self->automount, t, NULL, MS_BIND, NULL), 0);
195 - ASSERT_EQ(mount(NULL, t, NULL, MS_SHARED, NULL), 0);
196 - snprintf(p, sizeof(p), "%s/v/t/options", self->base);
197 - ASSERT_EQ(mount(self->automount, p, NULL, MS_BIND, NULL), 0);
198 -
199 - /* Q, a slave of T, and T moved into Q at the dentry M sits on */
200 - ASSERT_EQ(mount(t, q, NULL, MS_BIND, NULL), 0);
201 - ASSERT_EQ(mount(NULL, q, NULL, MS_SLAVE, NULL), 0);
202 - snprintf(p, sizeof(p), "%s/v/q/options", self->base);
203 - ASSERT_EQ(mount(t, p, NULL, MS_MOVE, NULL), 0);
204 -
205 - /* M, T and then Q go, V is empty and can be unmounted */
206 - ASSERT_EQ(umount2(v, 0), 0);
207 - ASSERT_EQ(stat(v, &after), 0);
208 - EXPECT_NE(before.st_dev, after.st_dev);
209 - }
210 -
211 - TEST_HARNESS_MAIN
deleted tools/testing/selftests/filesystems/umount_propagation/umount_propagation_test.c mode 100644
@@ -1,226 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * A synchronous umount fails with EBUSY when a mount it would pull out by
4 - * propagation is still in use.
5 - */
6 - #define _GNU_SOURCE
7 - #include <errno.h>
8 - #include <fcntl.h>
9 - #include <sched.h>
10 - #include <stdio.h>
11 - #include <stdlib.h>
12 - #include <string.h>
13 - #include <sys/mount.h>
14 - #include <sys/stat.h>
15 - #include <sys/syscall.h>
16 - #include <sys/wait.h>
17 - #include <unistd.h>
18 - #include <linux/mount.h>
19 - #include <linux/stat.h>
20 -
21 - #include "../../kselftest_harness.h"
22 -
23 - #ifndef OPEN_TREE_CLONE
24 - #define OPEN_TREE_CLONE 1
25 - #endif
26 - #ifndef OPEN_TREE_CLOEXEC
27 - #define OPEN_TREE_CLOEXEC O_CLOEXEC
28 - #endif
29 - #ifndef AT_RECURSIVE
30 - #define AT_RECURSIVE 0x8000
31 - #endif
32 - #ifndef MOVE_MOUNT_F_EMPTY_PATH
33 - #define MOVE_MOUNT_F_EMPTY_PATH 0x00000004
34 - #endif
35 - #ifndef MOVE_MOUNT_BENEATH
36 - #define MOVE_MOUNT_BENEATH 0x00000200
37 - #endif
38 - #ifndef STATX_MNT_ID
39 - #define STATX_MNT_ID 0x00001000U
40 - #endif
41 -
42 - static int sys_open_tree(int dfd, const char *filename, unsigned int flags)
43 - {
44 - return syscall(__NR_open_tree, dfd, filename, flags);
45 - }
46 -
47 - static int sys_move_mount(int from_dfd, const char *from_pathname,
48 - int to_dfd, const char *to_pathname,
49 - unsigned int flags)
50 - {
51 - return syscall(__NR_move_mount, from_dfd, from_pathname, to_dfd,
52 - to_pathname, flags);
53 - }
54 -
55 - /* Child exit codes. */
56 - enum {
57 - CHILD_OK,
58 - CHILD_UNSHARE, /* could not set up the slave namespace */
59 - CHILD_OPEN_TREE, /* open_tree() failed */
60 - CHILD_MOVE_MOUNT, /* move_mount() failed */
61 - CHILD_STATX, /* statx() failed */
62 - CHILD_PIPE, /* the parent went away */
63 - };
64 -
65 - /* Messages between parent and child. */
66 - enum {
67 - MSG_READY = 'r', /* child: the copy is mounted and referenced */
68 - MSG_CHECK = 'c', /* parent: check that the copy is still attached */
69 - MSG_ATTACHED = 'a', /* child: it is */
70 - MSG_DETACHED = 'd', /* child: it is not */
71 - MSG_CLOSE = 'x', /* parent: drop the reference */
72 - MSG_CLOSED = 'y', /* child: dropped */
73 - MSG_EXIT = 'e', /* parent: done */
74 - };
75 -
76 - FIXTURE(umount_propagation)
77 - {
78 - char base[64];
79 - char victim[80];
80 - bool mounted;
81 - };
82 -
83 - FIXTURE_SETUP(umount_propagation)
84 - {
85 - self->mounted = false;
86 -
87 - if (geteuid() != 0)
88 - SKIP(return, "test requires CAP_SYS_ADMIN");
89 -
90 - ASSERT_EQ(unshare(CLONE_NEWNS), 0);
91 - ASSERT_EQ(mount("", "/", NULL, MS_REC | MS_PRIVATE, NULL), 0);
92 -
93 - snprintf(self->base, sizeof(self->base), "/tmp/umount_propagation.XXXXXX");
94 - ASSERT_NE(mkdtemp(self->base), NULL);
95 - ASSERT_EQ(mount("tmpfs", self->base, "tmpfs", 0, NULL), 0);
96 - self->mounted = true;
97 - ASSERT_EQ(mount(NULL, self->base, NULL, MS_SHARED, NULL), 0);
98 -
99 - snprintf(self->victim, sizeof(self->victim), "%s/victim", self->base);
100 - ASSERT_EQ(mkdir(self->victim, 0755), 0);
101 - ASSERT_EQ(mount("tmpfs", self->victim, "tmpfs", 0, NULL), 0);
102 - }
103 -
104 - FIXTURE_TEARDOWN(umount_propagation)
105 - {
106 - if (self->mounted)
107 - umount2(self->base, MNT_DETACH);
108 - rmdir(self->base);
109 - }
110 -
111 - static int send_msg(int fd, char msg)
112 - {
113 - return write(fd, &msg, 1) == 1 ? 0 : -1;
114 - }
115 -
116 - static char recv_msg(int fd)
117 - {
118 - char msg;
119 -
120 - if (read(fd, &msg, 1) != 1)
121 - return 0;
122 - return msg;
123 - }
124 -
125 - /* Is the mount with id @mnt_id attached in this mount namespace? */
126 - static bool mount_attached(__u64 mnt_id)
127 - {
128 - char line[4096];
129 - bool found = false;
130 - FILE *f;
131 -
132 - f = fopen("/proc/self/mountinfo", "re");
133 - if (!f)
134 - return false;
135 -
136 - while (fgets(line, sizeof(line), f)) {
137 - if (strtoull(line, NULL, 10) == mnt_id) {
138 - found = true;
139 - break;
140 - }
141 - }
142 - fclose(f);
143 - return found;
144 - }
145 -
146 - /*
147 - * The slave namespace: take a detached copy of the shared tree and move it
148 - * beneath the propagated copy of the victim, keeping the open_tree()
149 - * descriptor as a reference on it.
150 - */
151 - static int slave_child(const char *base, const char *victim, int to_parent,
152 - int from_parent)
153 - {
154 - struct statx stx;
155 - int fd;
156 -
157 - if (unshare(CLONE_NEWNS))
158 - return CHILD_UNSHARE;
159 - if (mount("", "/", NULL, MS_REC | MS_SLAVE, NULL))
160 - return CHILD_UNSHARE;
161 -
162 - fd = sys_open_tree(AT_FDCWD, base,
163 - OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC | AT_RECURSIVE);
164 - if (fd < 0)
165 - return CHILD_OPEN_TREE;
166 - if (sys_move_mount(fd, "", AT_FDCWD, victim,
167 - MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_BENEATH))
168 - return CHILD_MOVE_MOUNT;
169 - if (statx(fd, "", AT_EMPTY_PATH, STATX_MNT_ID, &stx))
170 - return CHILD_STATX;
171 -
172 - if (send_msg(to_parent, MSG_READY) || recv_msg(from_parent) != MSG_CHECK)
173 - return CHILD_PIPE;
174 - if (send_msg(to_parent, mount_attached(stx.stx_mnt_id) ?
175 - MSG_ATTACHED : MSG_DETACHED))
176 - return CHILD_PIPE;
177 -
178 - if (recv_msg(from_parent) != MSG_CLOSE)
179 - return CHILD_PIPE;
180 - close(fd);
181 - if (send_msg(to_parent, MSG_CLOSED) || recv_msg(from_parent) != MSG_EXIT)
182 - return CHILD_PIPE;
183 - return CHILD_OK;
184 - }
185 -
186 - TEST_F(umount_propagation, busy_copy_pulled_out)
187 - {
188 - int to_child[2], to_parent[2];
189 - int status;
190 - pid_t pid;
191 -
192 - ASSERT_EQ(pipe(to_child), 0);
193 - ASSERT_EQ(pipe(to_parent), 0);
194 -
195 - pid = fork();
196 - ASSERT_GE(pid, 0);
197 - if (pid == 0) {
198 - close(to_child[1]);
199 - close(to_parent[0]);
200 - _exit(slave_child(self->base, self->victim, to_parent[1],
201 - to_child[0]));
202 - }
203 - close(to_child[0]);
204 - close(to_parent[1]);
205 -
206 - ASSERT_EQ(recv_msg(to_parent[0]), MSG_READY);
207 -
208 - /* the copy in the slave namespace is in use */
209 - ASSERT_EQ(umount2(self->victim, 0), -1);
210 - ASSERT_EQ(errno, EBUSY);
211 -
212 - ASSERT_EQ(send_msg(to_child[1], MSG_CHECK), 0);
213 - ASSERT_EQ(recv_msg(to_parent[0]), MSG_ATTACHED);
214 -
215 - /* and once it is not, the umount goes through */
216 - ASSERT_EQ(send_msg(to_child[1], MSG_CLOSE), 0);
217 - ASSERT_EQ(recv_msg(to_parent[0]), MSG_CLOSED);
218 - ASSERT_EQ(umount2(self->victim, 0), 0);
219 -
220 - ASSERT_EQ(send_msg(to_child[1], MSG_EXIT), 0);
221 - ASSERT_EQ(waitpid(pid, &status, 0), pid);
222 - ASSERT_TRUE(WIFEXITED(status));
223 - ASSERT_EQ(WEXITSTATUS(status), CHILD_OK);
224 - }
225 -
226 - TEST_HARNESS_MAIN
modified tools/testing/selftests/mm/hugetlb-mmap.c
@@ -122,7 +122,7 @@ int main(int argc, char **argv)
122 122 hugepage_size = default_huge_page_size();
123 123 if (!hugepage_size)
124 124 ksft_exit_skip("Could not detect default hugetlb page size.");
125 - ksft_print_msg("Default size hugepages (%zu kB)\n", hugepage_size >> 10);
125 + ksft_print_msg("Default size hugepages (%lu kB)\n", hugepage_size >> 10);
126 126 }
127 127
128 128 /* munmap will fail if the length is not page aligned */
@@ -131,7 +131,7 @@ int main(int argc, char **argv)
131 131
132 132 hugetlb_set_nr_pages(hugepage_size, nr);
133 133 if (hugetlb_free_pages(hugepage_size) < nr)
134 - ksft_exit_skip("Not enough %zu Kb pages\n", hugepage_size >> 10);
134 + ksft_exit_skip("Not enough %lu Kb pages\n", hugepage_size >> 10);
135 135
136 136 ksft_set_plan(2);
137 137 ksft_print_msg("Mapping %lu Mbytes\n", (unsigned long)length >> 20);
modified tools/testing/selftests/move_mount_set_group/move_mount_set_group_test.c
@@ -146,19 +146,17 @@ static void null_endofword(char *word)
146 146 *word = '\0';
147 147 }
148 148
149 - /* Does the mount on @path carry the optional field @field in mountinfo? */
150 - static bool mount_has_field(const char *path, const char *field)
149 + static bool is_shared_mount(const char *path)
151 150 {
152 151 size_t len = 0;
153 152 char *line = NULL;
154 153 FILE *f = NULL;
155 - bool found = false;
156 154
157 155 f = fopen("/proc/self/mountinfo", "re");
158 156 if (!f)
159 157 return false;
160 158
161 - while (!found && getline(&line, &len, f) != -1) {
159 + while (getline(&line, &len, f) != -1) {
162 160 char *opts, *target;
163 161
164 162 target = get_field(line, 4);
@@ -174,29 +172,15 @@ static bool mount_has_field(const char *path, const char *field)
174 172 if (strcmp(target, path) != 0)
175 173 continue;
176 174
177 - /* the optional fields end at the "-" separator */
178 - while (opts && *opts != '-') {
179 - char *next = strchr(opts, ' ');
180 -
181 - if (next)
182 - *next++ = '\0';
183 - if (!strncmp(opts, field, strlen(field))) {
184 - found = true;
185 - break;
186 - }
187 - opts = next;
188 - }
175 + null_endofword(opts);
176 + if (strstr(opts, "shared:"))
177 + return true;
189 178 }
190 179
191 180 free(line);
192 181 fclose(f);
193 182
194 - return found;
195 - }
196 -
197 - static bool is_shared_mount(const char *path)
198 - {
199 - return mount_has_field(path, "shared:");
183 + return false;
200 184 }
201 185
202 186 /* Attempt to de-conflict with the selftests tree. */
@@ -388,50 +372,4 @@ TEST_F(move_mount_set_group, complex_sharing_copying)
388 372 ASSERT_EQ(is_shared_mount(SET_GROUP_A), 1);
389 373 }
390 374
391 - #define SET_GROUP_B "/tmp/B"
392 - #define SET_GROUP_C "/tmp/C"
393 -
394 - /*
395 - * An unbindable mount is neither shared nor a slave, so it must not be
396 - * accepted as the target: with a slave source it would end up unbindable
397 - * and a slave at the same time.
398 - */
399 - TEST_F(move_mount_set_group, unbindable_target)
400 - {
401 - bool ret;
402 -
403 - ret = move_mount_set_group_supported();
404 - ASSERT_GE(ret, 0);
405 - if (!ret)
406 - SKIP(return, "move_mount(MOVE_MOUNT_SET_GROUP) is not supported");
407 -
408 - ASSERT_EQ(mount(NULL, SET_GROUP_A, NULL, MS_SHARED, 0), 0);
409 -
410 - /* B: a slave of A's peer group */
411 - ASSERT_EQ(mkdir(SET_GROUP_B, 0777), 0);
412 - ASSERT_EQ(mount(SET_GROUP_A, SET_GROUP_B, NULL, MS_BIND, NULL), 0);
413 - ASSERT_EQ(mount(NULL, SET_GROUP_B, NULL, MS_SLAVE, 0), 0);
414 - ASSERT_TRUE(mount_has_field(SET_GROUP_B, "master:"));
415 -
416 - /* C: unbindable */
417 - ASSERT_EQ(mkdir(SET_GROUP_C, 0777), 0);
418 - ASSERT_EQ(mount(SET_GROUP_A, SET_GROUP_C, NULL, MS_BIND, NULL), 0);
419 - ASSERT_EQ(mount(NULL, SET_GROUP_C, NULL, MS_UNBINDABLE, 0), 0);
420 - ASSERT_TRUE(mount_has_field(SET_GROUP_C, "unbindable"));
421 -
422 - /* from a slave */
423 - ASSERT_EQ(syscall(__NR_move_mount, AT_FDCWD, SET_GROUP_B,
424 - AT_FDCWD, SET_GROUP_C, MOVE_MOUNT_SET_GROUP), -1);
425 - ASSERT_EQ(errno, EINVAL);
426 - ASSERT_FALSE(mount_has_field(SET_GROUP_C, "master:"));
427 - ASSERT_TRUE(mount_has_field(SET_GROUP_C, "unbindable"));
428 -
429 - /* from a shared mount */
430 - ASSERT_EQ(syscall(__NR_move_mount, AT_FDCWD, SET_GROUP_A,
431 - AT_FDCWD, SET_GROUP_C, MOVE_MOUNT_SET_GROUP), -1);
432 - ASSERT_EQ(errno, EINVAL);
433 - ASSERT_FALSE(mount_has_field(SET_GROUP_C, "shared:"));
434 - ASSERT_TRUE(mount_has_field(SET_GROUP_C, "unbindable"));
435 - }
436 -
437 375 TEST_HARNESS_MAIN
modified tools/testing/selftests/net/amt.sh
@@ -150,13 +150,6 @@ setup_interface()
150 150 ip netns exec "${RELAY}" ip a a 10.0.0.2/24 dev relay_gw
151 151 ip netns exec "${RELAY}" ip link add amtr type amt mode relay \
152 152 local 10.0.0.2 dev relay_gw relay_port 2268 max_tunnels 4
153 - # Count the IGMP and MLD queries that leave the relay through its own
154 - # amt device; test_query_egress expects none.
155 - ip netns exec "${RELAY}" tc qdisc add dev amtr clsact
156 - ip netns exec "${RELAY}" tc filter add dev amtr egress pref 1 \
157 - protocol ip flower ip_proto 0x2 action pass
158 - ip netns exec "${RELAY}" tc filter add dev amtr egress pref 2 \
159 - protocol ipv6 flower ip_proto icmpv6 type 130 action pass
160 153 ip netns exec "${RELAY}" ip a a 172.17.0.1/24 dev relay_src
161 154 ip netns exec "${RELAY}" ip a a 2001:db8:3::1/64 dev relay_src
162 155 ip netns exec "${SOURCE}" ip a a 172.17.0.2/24 dev src_relay
@@ -253,27 +246,6 @@ test_ipv6_forward()
253 246 fi
254 247 }
255 248
256 - # The relay sends its General Queries straight from the receive path, in
257 - # the same context that found the tunnel. A query queued on the amt device
258 - # instead could outlive the tunnel it was built for. The forwarding tests
259 - # above show that the gateway got its queries.
260 - test_query_egress()
261 - {
262 - local n4 n6
263 -
264 - n4=$(ip netns exec "${RELAY}" tc -s -j filter show dev amtr egress \
265 - pref 1 | jq '[.[].options.actions[0].stats.packets // empty] | add // 0')
266 - n6=$(ip netns exec "${RELAY}" tc -s -j filter show dev amtr egress \
267 - pref 2 | jq '[.[].options.actions[0].stats.packets // empty] | add // 0')
268 - if [ "$n4" -eq 0 ] && [ "$n6" -eq 0 ]; then
269 - printf "TEST: %-60s [ OK ]\n" "amt relay queries bypass the amt device"
270 - else
271 - printf "TEST: %-60s [FAIL]\n" "amt relay queries bypass the amt device"
272 - echo "IGMP queries on amtr egress: $n4, MLD queries: $n6" >&2
273 - ERR=1
274 - fi
275 - }
276 -
277 249 send_mcast4()
278 250 {
279 251 sleep 5
@@ -315,7 +287,6 @@ wait $pid || err=$?
315 287 if [ $err -eq 1 ]; then
316 288 ERR=1
317 289 fi
318 - test_query_egress
319 290 printf "TEST: %-50s" "IPv4 amt traffic forwarding torture"
320 291 send_mcast_torture4
321 292 printf " [ OK ]\n"
modified tools/testing/selftests/net/tun.c
@@ -9,7 +9,6 @@
9 9 #include <string.h>
10 10 #include <unistd.h>
11 11 #include <linux/if_tun.h>
12 - #include <netinet/tcp.h>
13 12 #include <sys/ioctl.h>
14 13 #include <sys/socket.h>
15 14
@@ -543,141 +542,6 @@ TEST_F(tun, reattach_close_delete)
543 542 EXPECT_EQ(tun_delete(self->ifname), 0);
544 543 }
545 544
546 - FIXTURE(tun_vnet_gso)
547 - {
548 - char ifname[IFNAMSIZ];
549 - int fd;
550 - };
551 -
552 - FIXTURE_SETUP(tun_vnet_gso)
553 - {
554 - int flags = IFF_TAP | IFF_NO_PI | IFF_VNET_HDR;
555 -
556 - memset(self->ifname, 0, sizeof(self->ifname));
557 - self->fd = tun_open(self->ifname, flags, 0, 0, NULL);
558 - ASSERT_GE(self->fd, 0);
559 - }
560 -
561 - FIXTURE_TEARDOWN(tun_vnet_gso)
562 - {
563 - if (self->fd >= 0)
564 - close(self->fd);
565 - }
566 -
567 - static int build_vlan_tcpv4_gso_packet(uint8_t *buf, int payload_len)
568 - {
569 - uint16_t vlan_tag[2] = { htons(100), htons(ETH_P_IP) };
570 - uint8_t *cur = buf + sizeof(struct virtio_net_hdr);
571 - struct virtio_net_hdr vh = { 0 };
572 - struct tcphdr tcph = { 0 };
573 - uint32_t sum;
574 -
575 - cur += build_eth(cur, ETH_P_8021Q, param_hwaddr_outer_src,
576 - param_hwaddr_outer_dst);
577 -
578 - /* 802.1Q tag: VID=100, inner protocol=ETH_P_IP */
579 - memcpy(cur, vlan_tag, sizeof(vlan_tag));
580 - cur += sizeof(vlan_tag);
581 -
582 - cur += build_ipv4_header(cur, IPPROTO_TCP,
583 - sizeof(tcph) + payload_len,
584 - &param_ipaddr4_outer_src,
585 - &param_ipaddr4_outer_dst);
586 -
587 - tcph.source = htons(12345);
588 - tcph.dest = htons(80);
589 - tcph.seq = htonl(1);
590 - tcph.doff = sizeof(tcph) / 4;
591 - tcph.ack = 1;
592 - tcph.window = htons(65535);
593 - memcpy(cur, &tcph, sizeof(tcph));
594 - memset(cur + sizeof(tcph), PKT_DATA, payload_len);
595 -
596 - sum = add_csum((const uint8_t *)&param_ipaddr4_outer_src,
597 - sizeof(param_ipaddr4_outer_src));
598 - sum += add_csum((const uint8_t *)&param_ipaddr4_outer_dst,
599 - sizeof(param_ipaddr4_outer_dst));
600 - sum += htons(IPPROTO_TCP) + htons(sizeof(tcph) + payload_len);
601 - sum += add_csum(cur, sizeof(tcph) + payload_len);
602 - tcph.check = finish_ip_csum(sum);
603 - memcpy(cur, &tcph, sizeof(tcph));
604 - cur += sizeof(tcph) + payload_len;
605 -
606 - vh.gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
607 - vh.gso_size = 1400;
608 - vh.hdr_len = (cur - buf) - sizeof(vh) - payload_len;
609 - memcpy(buf, &vh, sizeof(vh));
610 -
611 - return cur - buf;
612 - }
613 -
614 - TEST_F(tun_vnet_gso, vlan_tcpv4_gso_no_csum)
615 - {
616 - struct virtio_net_hdr vh;
617 - uint8_t pkt[4096] = { 0 };
618 - int len, ret;
619 -
620 - len = build_vlan_tcpv4_gso_packet(pkt, 2800);
621 - memcpy(&vh, pkt, sizeof(vh));
622 -
623 - /* Valid VLAN-tagged TCPv4 GSO with flags = 0 (no NEEDS_CSUM) */
624 - vh.flags = 0;
625 - memcpy(pkt, &vh, sizeof(vh));
626 - ret = write(self->fd, pkt, len);
627 - ASSERT_EQ(ret, len);
628 -
629 - /* Valid VLAN-tagged TCPv4 GSO with flags = DATA_VALID */
630 - vh.flags = VIRTIO_NET_HDR_F_DATA_VALID;
631 - memcpy(pkt, &vh, sizeof(vh));
632 - ret = write(self->fd, pkt, len);
633 - ASSERT_EQ(ret, len);
634 -
635 - /* Mismatched GSO type (TCPV6 on VLAN-tagged IPv4 packet) */
636 - vh.flags = 0;
637 - vh.gso_type = VIRTIO_NET_HDR_GSO_TCPV6;
638 - memcpy(pkt, &vh, sizeof(vh));
639 - ret = write(self->fd, pkt, len);
640 - ASSERT_EQ(ret, -1);
641 - ASSERT_EQ(errno, EINVAL);
642 -
643 - /* TCP header truncated after 10 bytes, without NEEDS_CSUM.
644 - * Requires the transport header offset found by flow dissection:
645 - * pulling only sizeof(struct iphdr) + sizeof(struct tcphdr) bytes
646 - * from the mac header would accept this frame.
647 - */
648 - vh.gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
649 - vh.hdr_len = ETH_HLEN + 4 + sizeof(struct iphdr) + 10;
650 - memcpy(pkt, &vh, sizeof(vh));
651 - ret = write(self->fd, pkt, sizeof(vh) + vh.hdr_len);
652 - ASSERT_EQ(ret, -1);
653 - ASSERT_EQ(errno, EINVAL);
654 - }
655 -
656 - TEST_F(tun_vnet_gso, vlan_tcpv4_gso_no_csum_64k)
657 - {
658 - /* Ethernet frame of 65540 bytes: skb->len is above U16_MAX when the
659 - * frame is flow-dissected, before eth_type_trans() pulls ETH_HLEN.
660 - */
661 - const int payload_len = 65540 - ETH_HLEN - 4 -
662 - sizeof(struct iphdr) - sizeof(struct tcphdr);
663 - struct virtio_net_hdr vh;
664 - uint8_t *pkt;
665 - int len, ret;
666 -
667 - pkt = calloc(1, sizeof(vh) + 65540);
668 - ASSERT_NE(pkt, NULL);
669 -
670 - len = build_vlan_tcpv4_gso_packet(pkt, payload_len);
671 - ASSERT_EQ(len, sizeof(vh) + 65540);
672 - memcpy(&vh, pkt, sizeof(vh));
673 -
674 - vh.flags = 0;
675 - memcpy(pkt, &vh, sizeof(vh));
676 - ret = write(self->fd, pkt, len);
677 - free(pkt);
678 - ASSERT_EQ(ret, len);
679 - }
680 -
681 545 FIXTURE(tun_vnet_udptnl)
682 546 {
683 547 char ifname[IFNAMSIZ];
modified tools/testing/selftests/net/veth.sh
@@ -9,8 +9,6 @@ readonly DST=1
9 9 readonly DST_NAT=100
10 10 readonly NS_SRC=$BASE$SRC
11 11 readonly NS_DST=$BASE$DST
12 - # shellcheck disable=SC2155 # prefer RO variable over return value from cmd
13 - readonly YNL="$(dirname "$(readlink -f "$0")")/../../../net/ynl/pyynl/cli.py"
14 12
15 13 # "baremetal" network used for raw UDP traffic
16 14 readonly BM_NET_V4=192.168.1.
@@ -76,37 +74,6 @@ chk_tso_flag() {
76 74 __chk_flag "$1" $2 $3 tcp-segmentation-offload
77 75 }
78 76
79 - chk_xdp_feature() {
80 - local msg="$1"
81 - local target=$2
82 - local expected=$3
83 - local feature=$4
84 - local ifindex
85 - local out
86 - local st
87 - local flag
88 -
89 - ifindex=`ip netns exec $BASE$target cat /sys/class/net/veth$target/ifindex`
90 - out=`ip netns exec $BASE$target "$YNL" --family netdev --do dev-get \
91 - --output-json --json "{\"ifindex\": $ifindex}" 2>&1`
92 - st=$?
93 -
94 - printf "%-60s" "$msg"
95 - if [ $st -ne 0 ]; then
96 - echo " fail - ynl cli error: $out"
97 - ret=1
98 - return
99 - fi
100 -
101 - flag=`echo "$out" | grep -c "\"$feature\""`
102 - if [ "$flag" = "$expected" ]; then
103 - echo " ok "
104 - else
105 - echo " fail - expected $expected found $flag"
106 - ret=1
107 - fi
108 - }
109 -
110 77 chk_channels() {
111 78 local msg="$1"
112 79 local target=$2
@@ -255,7 +222,6 @@ fi
255 222
256 223 [ $CPUS -lt 2 ] && echo "Only one CPU available, some tests will be skipped"
257 224 [ $STRESS -gt 0 -a $CPUS -lt 3 ] && echo " stress test will be skipped, too"
258 - [ ! -f "$YNL" ] && echo "ynl cli not found, ndo-xmit tests will be skipped"
259 225
260 226 create_ns
261 227 chk_gro_flag "default - gro flag" $SRC off
@@ -317,18 +283,6 @@ chk_gro_flag " - peer gro flag" $SRC off
317 283 chk_tso_flag " - tso flag" $SRC on
318 284 chk_tso_flag " - peer tso flag" $DST on
319 285 ip -n $NS_DST link set dev veth$DST up
320 - if [ -f "$YNL" ]; then
321 - chk_xdp_feature " - peer ndo-xmit" $SRC 1 ndo-xmit
322 - # make sure the peer flag is set before disabling gro while down
323 - ip netns exec $NS_DST ethtool -K veth$DST gro off
324 - ip netns exec $NS_DST ethtool -K veth$DST gro on
325 - chk_xdp_feature " - peer ndo-xmit re-armed" $SRC 1 ndo-xmit
326 - ip -n $NS_DST link set dev veth$DST down
327 - ip netns exec $NS_DST ethtool -K veth$DST gro off
328 - ip -n $NS_DST link set dev veth$DST up
329 - chk_xdp_feature " - peer ndo-xmit cleared" $SRC 0 ndo-xmit
330 - ip netns exec $NS_DST ethtool -K veth$DST gro on
331 - fi
332 286 ip netns exec $NS_SRC ethtool -K veth$SRC tx-udp-segmentation off
333 287 ip netns exec $NS_DST ethtool -K veth$DST rx-udp-gro-forwarding on
334 288 chk_gro " - aggregation with TSO off" 1
modified tools/testing/selftests/sched_ext/Makefile
@@ -165,7 +165,6 @@ auto-test-targets := \
165 165 create_dsq \
166 166 dequeue \
167 167 dequeue_iter \
168 - dequeue_remote \
169 168 enq_last_no_enq_fails \
170 169 ddsp_bogus_dsq_fail \
171 170 ddsp_vtimelocal_fail \
deleted tools/testing/selftests/sched_ext/dequeue_remote.bpf.c mode 100644
@@ -1,270 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * Verify that ops.dequeue() is called when a task leaves the BPF scheduler's
4 - * custody by being moved to the local DSQ of a CPU other than the one whose
5 - * rq it's on (move_remote_task_to_local_dsq()).
6 - *
7 - * ops.enqueue() puts every task into custody and ops.dispatch() moves it to
8 - * the dispatching CPU's local DSQ, so most moves cross CPUs. With
9 - * @test_use_move_to_local, tasks are queued on a user DSQ and consumed with
10 - * scx_bpf_dsq_move_to_local(). Otherwise, they are queued in a BPF queue and
11 - * dispatched with SCX_DSQ_LOCAL_ON.
12 - *
13 - * Copyright (c) 2026 Google LLC.
14 - */
15 -
16 - #include <scx/common.bpf.h>
17 -
18 - #define SHARED_DSQ 0
19 - #define MAX_DISPATCH_POPS 8
20 -
21 - char _license[] SEC("license") = "GPL";
22 -
23 - UEI_DEFINE(uei);
24 -
25 - struct {
26 - __uint(type, BPF_MAP_TYPE_QUEUE);
27 - __uint(max_entries, 32768);
28 - __type(value, s32);
29 - } global_queue SEC(".maps");
30 -
31 - enum task_state {
32 - TASK_NONE = 0,
33 - TASK_ENQUEUED, /* in BPF custody, waiting for ops.dequeue() */
34 - TASK_DISPATCHED, /* left custody */
35 - };
36 -
37 - struct task_ctx {
38 - enum task_state state;
39 - s32 enq_cpu; /* scx_bpf_task_cpu() at ops.enqueue() */
40 - u64 enqueue_seq;
41 - };
42 -
43 - struct {
44 - __uint(type, BPF_MAP_TYPE_TASK_STORAGE);
45 - __uint(map_flags, BPF_F_NO_PREALLOC);
46 - __type(key, int);
47 - __type(value, struct task_ctx);
48 - } task_ctx_stor SEC(".maps");
49 -
50 - /* core_cookie only exists with CONFIG_SCHED_CORE */
51 - struct task_struct___core_sched {
52 - unsigned long core_cookie;
53 - } __attribute__((preserve_access_index));
54 -
55 - bool test_use_move_to_local;
56 -
57 - u64 enqueue_cnt, dequeue_cnt, dispatch_dequeue_cnt, change_dequeue_cnt;
58 - u64 remote_dispatch_cnt, remote_running_cnt, missed_dequeue_cnt;
59 - u64 core_sched_exec_dequeue_cnt;
60 -
61 - static struct task_ctx *lookup_task_ctx(struct task_struct *p)
62 - {
63 - return bpf_task_storage_get(&task_ctx_stor, p, 0, 0);
64 - }
65 -
66 - static bool task_has_core_cookie(struct task_struct *p)
67 - {
68 - struct task_struct___core_sched *t = (void *)p;
69 -
70 - if (!bpf_core_field_exists(t->core_cookie))
71 - return false;
72 - return BPF_CORE_READ(t, core_cookie);
73 - }
74 -
75 - s32 BPF_STRUCT_OPS(dequeue_remote_select_cpu, struct task_struct *p,
76 - s32 prev_cpu, u64 wake_flags)
77 - {
78 - /* no direct dispatch, always go through ops.enqueue() */
79 - return prev_cpu;
80 - }
81 -
82 - void BPF_STRUCT_OPS(dequeue_remote_enqueue, struct task_struct *p, u64 enq_flags)
83 - {
84 - struct task_ctx *tctx;
85 - s32 pid = p->pid;
86 -
87 - tctx = lookup_task_ctx(p);
88 - if (!tctx) {
89 - scx_bpf_dsq_insert(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, enq_flags);
90 - return;
91 - }
92 -
93 - /* the previous custody period must have ended with ops.dequeue() */
94 - if (tctx->state == TASK_ENQUEUED)
95 - scx_bpf_error("%d (%s): enqueue while in ENQUEUED state seq=%llu",
96 - p->pid, p->comm, tctx->enqueue_seq);
97 -
98 - /*
99 - * Mark @p as enqueued before making it visible to ops.dispatch() on
100 - * other CPUs, which skips queue entries of tasks not in ENQUEUED
101 - * state as stale.
102 - */
103 - tctx->state = TASK_ENQUEUED;
104 - tctx->enq_cpu = scx_bpf_task_cpu(p);
105 - tctx->enqueue_seq++;
106 -
107 - if (test_use_move_to_local) {
108 - scx_bpf_dsq_insert(p, SHARED_DSQ, SCX_SLICE_DFL, enq_flags);
109 - } else if (bpf_map_push_elem(&global_queue, &pid, 0)) {
110 - scx_bpf_dsq_insert(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, enq_flags);
111 - tctx->state = TASK_DISPATCHED;
112 - tctx->enq_cpu = -1;
113 - goto out;
114 - }
115 -
116 - __sync_fetch_and_add(&enqueue_cnt, 1);
117 - out:
118 - scx_bpf_kick_cpu(scx_bpf_task_cpu(p), SCX_KICK_IDLE);
119 - }
120 -
121 - void BPF_STRUCT_OPS(dequeue_remote_dequeue, struct task_struct *p, u64 deq_flags)
122 - {
123 - struct task_ctx *tctx;
124 -
125 - __sync_fetch_and_add(&dequeue_cnt, 1);
126 -
127 - tctx = lookup_task_ctx(p);
128 - if (!tctx)
129 - return;
130 -
131 - /*
132 - * Only core scheduling can pick a task straight out of custody, and
133 - * only if the task has a core cookie. Otherwise, the custody exit was
134 - * missed when @p was inserted into a local DSQ and got deferred until
135 - * @p was picked.
136 - */
137 - if ((deq_flags & SCX_DEQ_CORE_SCHED_EXEC) && !task_has_core_cookie(p)) {
138 - __sync_fetch_and_add(&core_sched_exec_dequeue_cnt, 1);
139 - scx_bpf_error("%d (%s): late ops.dequeue() with SCX_DEQ_CORE_SCHED_EXEC (enq_cpu=%d cpu=%d seq=%llu)",
140 - p->pid, p->comm, tctx->enq_cpu,
141 - scx_bpf_task_cpu(p), tctx->enqueue_seq);
142 - }
143 -
144 - /* ops.dequeue() ends the custody period started by ops.enqueue() */
145 - if (tctx->state != TASK_ENQUEUED)
146 - scx_bpf_error("%d (%s): dequeue outside custody deq_flags=0x%llx state=%d seq=%llu",
147 - p->pid, p->comm, deq_flags, tctx->state,
148 - tctx->enqueue_seq);
149 -
150 - if (deq_flags & SCX_DEQ_SCHED_CHANGE) {
151 - __sync_fetch_and_add(&change_dequeue_cnt, 1);
152 - tctx->state = TASK_NONE;
153 - } else {
154 - __sync_fetch_and_add(&dispatch_dequeue_cnt, 1);
155 - tctx->state = TASK_DISPATCHED;
156 - }
157 - }
158 -
159 - void BPF_STRUCT_OPS(dequeue_remote_dispatch, s32 cpu, struct task_struct *prev)
160 - {
161 - struct task_ctx *tctx;
162 - struct task_struct *p;
163 - s32 pid;
164 - int i;
165 -
166 - if (test_use_move_to_local) {
167 - scx_bpf_dsq_move_to_local(SHARED_DSQ, 0);
168 - return;
169 - }
170 -
171 - /* pop past stale entries so that they don't leave this CPU idle */
172 - bpf_for(i, 0, MAX_DISPATCH_POPS) {
173 - if (bpf_map_pop_elem(&global_queue, &pid))
174 - return;
175 -
176 - p = bpf_task_from_pid(pid);
177 - if (!p)
178 - continue;
179 -
180 - /*
181 - * Entries are stale if @p left custody through a property
182 - * change dequeue or was dispatched from a duplicate entry.
183 - */
184 - tctx = lookup_task_ctx(p);
185 - if (!tctx || tctx->state != TASK_ENQUEUED) {
186 - bpf_task_release(p);
187 - continue;
188 - }
189 -
190 - if (bpf_cpumask_test_cpu(cpu, p->cpus_ptr)) {
191 - if (scx_bpf_task_cpu(p) != cpu)
192 - __sync_fetch_and_add(&remote_dispatch_cnt, 1);
193 - scx_bpf_dsq_insert(p, SCX_DSQ_LOCAL_ON | cpu,
194 - SCX_SLICE_DFL, 0);
195 - } else {
196 - scx_bpf_dsq_insert(p, SCX_DSQ_GLOBAL, SCX_SLICE_DFL, 0);
197 - }
198 -
199 - bpf_task_release(p);
200 - return;
201 - }
202 -
203 - /* out of pops with entries left, retry instead of idling this CPU */
204 - if (!bpf_map_peek_elem(&global_queue, &pid))
205 - scx_bpf_kick_cpu(cpu, SCX_KICK_IDLE);
206 - }
207 -
208 - void BPF_STRUCT_OPS(dequeue_remote_running, struct task_struct *p)
209 - {
210 - struct task_ctx *tctx;
211 -
212 - tctx = lookup_task_ctx(p);
213 - if (!tctx)
214 - return;
215 -
216 - /* tasks can only run from a local DSQ, i.e. after leaving custody */
217 - if (tctx->state == TASK_ENQUEUED) {
218 - __sync_fetch_and_add(&missed_dequeue_cnt, 1);
219 - scx_bpf_error("%d (%s): running without ops.dequeue() (enq_cpu=%d cpu=%d seq=%llu)",
220 - p->pid, p->comm, tctx->enq_cpu,
221 - scx_bpf_task_cpu(p), tctx->enqueue_seq);
222 - return;
223 - }
224 -
225 - if (tctx->enq_cpu >= 0 && tctx->enq_cpu != scx_bpf_task_cpu(p))
226 - __sync_fetch_and_add(&remote_running_cnt, 1);
227 - tctx->enq_cpu = -1;
228 - }
229 -
230 - s32 BPF_STRUCT_OPS(dequeue_remote_init_task, struct task_struct *p,
231 - struct scx_init_task_args *args)
232 - {
233 - struct task_ctx *tctx;
234 -
235 - tctx = bpf_task_storage_get(&task_ctx_stor, p, 0,
236 - BPF_LOCAL_STORAGE_GET_F_CREATE);
237 - if (!tctx)
238 - return -ENOMEM;
239 -
240 - /* task storage persists across attachments, start from scratch */
241 - tctx->state = TASK_NONE;
242 - tctx->enq_cpu = -1;
243 - tctx->enqueue_seq = 0;
244 -
245 - return 0;
246 - }
247 -
248 - s32 BPF_STRUCT_OPS_SLEEPABLE(dequeue_remote_init)
249 - {
250 - return scx_bpf_create_dsq(SHARED_DSQ, -1);
251 - }
252 -
253 - void BPF_STRUCT_OPS(dequeue_remote_exit, struct scx_exit_info *ei)
254 - {
255 - UEI_RECORD(uei, ei);
256 - }
257 -
258 - SEC(".struct_ops.link")
259 - struct sched_ext_ops dequeue_remote_ops = {
260 - .select_cpu = (void *)dequeue_remote_select_cpu,
261 - .enqueue = (void *)dequeue_remote_enqueue,
262 - .dequeue = (void *)dequeue_remote_dequeue,
263 - .dispatch = (void *)dequeue_remote_dispatch,
264 - .running = (void *)dequeue_remote_running,
265 - .init_task = (void *)dequeue_remote_init_task,
266 - .init = (void *)dequeue_remote_init,
267 - .exit = (void *)dequeue_remote_exit,
268 - .flags = SCX_OPS_ENQ_LAST,
269 - .name = "dequeue_remote",
270 - };
deleted tools/testing/selftests/sched_ext/dequeue_remote.c mode 100644
@@ -1,204 +0,0 @@
1 - // SPDX-License-Identifier: GPL-2.0
2 - /*
3 - * Verify that ops.dequeue() is called for tasks leaving BPF custody through
4 - * an SCX-internal cross-CPU migration (move_remote_task_to_local_dsq()).
5 - *
6 - * Copyright (c) 2026 Google LLC.
7 - */
8 - #define _GNU_SOURCE
9 - #include <stdio.h>
10 - #include <stdlib.h>
11 - #include <string.h>
12 - #include <unistd.h>
13 - #include <signal.h>
14 - #include <time.h>
15 - #include <sched.h>
16 - #include <bpf/bpf.h>
17 - #include <scx/common.h>
18 - #include <sys/wait.h>
19 - #include "scx_test.h"
20 - #include "dequeue_remote.bpf.skel.h"
21 -
22 - #define MAX_WORKERS 64
23 - #define RUN_MS 2000
24 -
25 - static int nr_cpus;
26 -
27 - static long long now_ms(void)
28 - {
29 - struct timespec ts;
30 -
31 - clock_gettime(CLOCK_MONOTONIC, &ts);
32 - return ts.tv_sec * 1000LL + ts.tv_nsec / 1000000;
33 - }
34 -
35 - /* mix of short bursts and sleeps to generate lots of enqueues and wakeups */
36 - static void worker_fn(int id)
37 - {
38 - long long end = now_ms() + RUN_MS;
39 - volatile unsigned long sum = 0;
40 -
41 - while (now_ms() < end) {
42 - unsigned long j;
43 -
44 - for (j = 0; j < 20000 + id * 1000; j++)
45 - sum += j;
46 - if (id & 1)
47 - usleep(100);
48 - else
49 - sched_yield();
50 - }
51 -
52 - exit(0);
53 - }
54 -
55 - static enum scx_test_status run_scenario(struct dequeue_remote *skel,
56 - bool use_move_to_local,
57 - const char *name)
58 - {
59 - enum scx_test_status ret = SCX_TEST_PASS;
60 - struct bpf_link *link;
61 - pid_t pids[MAX_WORKERS];
62 - int nr_workers, nr_forked, i;
63 -
64 - nr_workers = 2 * nr_cpus;
65 - if (nr_workers < 4)
66 - nr_workers = 4;
67 - if (nr_workers > MAX_WORKERS)
68 - nr_workers = MAX_WORKERS;
69 -
70 - skel->bss->test_use_move_to_local = use_move_to_local;
71 - skel->bss->enqueue_cnt = 0;
72 - skel->bss->dequeue_cnt = 0;
73 - skel->bss->dispatch_dequeue_cnt = 0;
74 - skel->bss->change_dequeue_cnt = 0;
75 - skel->bss->remote_dispatch_cnt = 0;
76 - skel->bss->remote_running_cnt = 0;
77 - skel->bss->missed_dequeue_cnt = 0;
78 - skel->bss->core_sched_exec_dequeue_cnt = 0;
79 - memset(&skel->data->uei, 0, sizeof(skel->data->uei));
80 -
81 - link = bpf_map__attach_struct_ops(skel->maps.dequeue_remote_ops);
82 - SCX_FAIL_IF(!link, "Failed to attach struct_ops for %s", name);
83 -
84 - fflush(stdout);
85 - fflush(stderr);
86 -
87 - for (nr_forked = 0; nr_forked < nr_workers; nr_forked++) {
88 - pid_t pid = fork();
89 -
90 - if (pid < 0) {
91 - SCX_ERR("Failed to fork worker %d", nr_forked);
92 - ret = SCX_TEST_FAIL;
93 - break;
94 - }
95 - if (pid == 0)
96 - worker_fn(nr_forked);
97 - pids[nr_forked] = pid;
98 - }
99 -
100 - /* on failure, kill the remaining workers but still reap them */
101 - for (i = 0; i < nr_forked; i++) {
102 - int status;
103 -
104 - if (ret != SCX_TEST_PASS)
105 - kill(pids[i], SIGKILL);
106 -
107 - if (waitpid(pids[i], &status, 0) != pids[i]) {
108 - SCX_ERR("Failed to wait for worker %d", i);
109 - ret = SCX_TEST_FAIL;
110 - } else if (ret == SCX_TEST_PASS && status != 0) {
111 - SCX_ERR("Worker %d exited with status %d", i, status);
112 - ret = SCX_TEST_FAIL;
113 - }
114 - }
115 -
116 - bpf_link__destroy(link);
117 -
118 - if (ret != SCX_TEST_PASS)
119 - return ret;
120 -
121 - printf("%s:\n", name);
122 - printf(" workers: %d\n", nr_workers);
123 - printf(" enqueues: %lu\n", (unsigned long)skel->bss->enqueue_cnt);
124 - printf(" dequeues: %lu (dispatch: %lu, property_change: %lu)\n",
125 - (unsigned long)skel->bss->dequeue_cnt,
126 - (unsigned long)skel->bss->dispatch_dequeue_cnt,
127 - (unsigned long)skel->bss->change_dequeue_cnt);
128 - if (!use_move_to_local)
129 - printf(" remote SCX_DSQ_LOCAL_ON dispatches: %lu\n",
130 - (unsigned long)skel->bss->remote_dispatch_cnt);
131 - printf(" ran on a CPU other than the enqueue CPU: %lu\n",
132 - (unsigned long)skel->bss->remote_running_cnt);
133 - printf(" ran without ops.dequeue(): %lu\n",
134 - (unsigned long)skel->bss->missed_dequeue_cnt);
135 - printf(" late SCX_DEQ_CORE_SCHED_EXEC dequeues: %lu\n",
136 - (unsigned long)skel->bss->core_sched_exec_dequeue_cnt);
137 -
138 - if (skel->data->uei.kind != EXIT_KIND(SCX_EXIT_UNREG))
139 - SCX_ERR("Scheduler exited with kind=%lld: %s",
140 - (long long)skel->data->uei.kind, skel->data->uei.msg);
141 - SCX_EQ(skel->data->uei.kind, EXIT_KIND(SCX_EXIT_UNREG));
142 -
143 - /* the test is meaningless if no task was moved across CPUs */
144 - SCX_GT(skel->bss->remote_running_cnt, 0);
145 - SCX_EQ(skel->bss->enqueue_cnt, skel->bss->dequeue_cnt);
146 -
147 - return SCX_TEST_PASS;
148 - }
149 -
150 - static enum scx_test_status setup(void **ctx)
151 - {
152 - struct dequeue_remote *skel;
153 - cpu_set_t cpus;
154 -
155 - SCX_FAIL_IF(sched_getaffinity(0, sizeof(cpus), &cpus),
156 - "Failed to get CPU affinity");
157 - nr_cpus = CPU_COUNT(&cpus);
158 - if (nr_cpus < 2) {
159 - fprintf(stderr, "Skipping: requires at least 2 usable CPUs\n");
160 - return SCX_TEST_SKIP;
161 - }
162 -
163 - skel = SCX_OPS_OPEN(dequeue_remote_ops, dequeue_remote);
164 - SCX_OPS_LOAD(skel, dequeue_remote_ops, dequeue_remote, uei);
165 -
166 - *ctx = skel;
167 -
168 - return SCX_TEST_PASS;
169 - }
170 -
171 - static enum scx_test_status run(void *ctx)
172 - {
173 - struct dequeue_remote *skel = ctx;
174 - enum scx_test_status status;
175 -
176 - status = run_scenario(skel, false,
177 - "BPF queue -> SCX_DSQ_LOCAL_ON | cpu");
178 - if (status != SCX_TEST_PASS)
179 - return status;
180 -
181 - status = run_scenario(skel, true,
182 - "user DSQ -> scx_bpf_dsq_move_to_local()");
183 - if (status != SCX_TEST_PASS)
184 - return status;
185 -
186 - return SCX_TEST_PASS;
187 - }
188 -
189 - static void cleanup(void *ctx)
190 - {
191 - struct dequeue_remote *skel = ctx;
192 -
193 - dequeue_remote__destroy(skel);
194 - }
195 -
196 - struct scx_test dequeue_remote_test = {
197 - .name = "dequeue_remote",
198 - .description = "Verify ops.dequeue() on SCX-internal cross-CPU migrations",
199 - .setup = setup,
200 - .run = run,
201 - .cleanup = cleanup,
202 - };
203 -
204 - REGISTER_SCX_TEST(&dequeue_remote_test)
modified tools/testing/selftests/tc-testing/tc-tests/filters/route.json
@@ -412,51 +412,5 @@
412 412 "teardown": [
413 413 "$TC qdisc del dev $DEV1 ingress"
414 414 ]
415 - },
416 - {
417 - "id": "4000",
418 - "name": "Change a wildcard route filter classid only (no routing attribute)",
419 - "category": [
420 - "filter",
421 - "route"
422 - ],
423 - "plugins": {
424 - "requires": "nsPlugin"
425 - },
426 - "setup": [
427 - "$TC qdisc add dev $DEV1 ingress",
428 - "$TC filter add dev $DEV1 parent ffff: protocol ip prio 100 route classid 1:1"
429 - ],
430 - "cmdUnderTest": "$TC filter change dev $DEV1 parent ffff: protocol ip prio 100 route classid 1:9",
431 - "expExitCode": "0",
432 - "verifyCmd": "$TC filter ls dev $DEV1 parent ffff:",
433 - "matchPattern": "fh 0xffff8000 flowid 1:9",
434 - "matchCount": "1",
435 - "teardown": [
436 - "$TC qdisc del dev $DEV1 ingress"
437 - ]
438 - },
439 - {
440 - "id": "907a",
441 - "name": "Try to change a route filter with no routing attribute and a non-wildcard handle",
442 - "category": [
443 - "filter",
444 - "route"
445 - ],
446 - "plugins": {
447 - "requires": "nsPlugin"
448 - },
449 - "setup": [
450 - "$TC qdisc add dev $DEV1 ingress",
451 - "$TC filter add dev $DEV1 parent ffff: protocol ip prio 100 route from 1 to 1 classid 1:1"
452 - ],
453 - "cmdUnderTest": "$TC filter change dev $DEV1 parent ffff: protocol ip prio 100 handle 0x10001 route classid 1:2",
454 - "expExitCode": "2",
455 - "verifyCmd": "$TC filter ls dev $DEV1 parent ffff:",
456 - "matchPattern": "fh 0x00010001 flowid 1:1 to 1 from 1",
457 - "matchCount": "1",
458 - "teardown": [
459 - "$TC qdisc del dev $DEV1 ingress"
460 - ]
461 415 }
462 416 ]
modified tools/testing/vma/tests/vma.c
@@ -40,7 +40,7 @@ static bool test_copy_vma(void)
40 40 vma = alloc_and_link_vma(&mm, 0x1000, 0x2000, 1, vma_flags);
41 41 vma_set_anonymous(vma);
42 42 vma_orig = vma;
43 - vma_new = copy_vma(&vma, 0x2000, 0x1000, 1, 1, &need_locks, false);
43 + vma_new = copy_vma(&vma, 0x2000, 0x1000, 1, 1, &need_locks);
44 44 ASSERT_EQ(vma_new, vma_orig);
45 45 ASSERT_EQ(vma, vma_orig);
46 46 ASSERT_EQ(vma_new->vm_start, 0x1000);
@@ -53,7 +53,7 @@ static bool test_copy_vma(void)
53 53 vma = alloc_and_link_vma(&mm, 0x2000, 0x3000, 2, vma_flags);
54 54 vma_set_anonymous(vma);
55 55 vma_orig = vma;
56 - vma_new = copy_vma(&vma, 0x1000, 0x1000, 2, 2, &need_locks, false);
56 + vma_new = copy_vma(&vma, 0x1000, 0x1000, 2, 2, &need_locks);
57 57 ASSERT_EQ(vma_new, vma_orig);
58 58 ASSERT_EQ(vma, vma_orig);
59 59 ASSERT_EQ(vma_new->vm_start, 0x1000);
@@ -71,7 +71,7 @@ static bool test_copy_vma(void)
71 71 vma = alloc_and_link_vma(&mm, 0x3000, 0x4000, 3, vma_flags);
72 72 vma_set_anonymous(vma);
73 73 vma_orig = vma;
74 - vma_new = copy_vma(&vma, 0x2000, 0x1000, 3, 3, &need_locks, false);
74 + vma_new = copy_vma(&vma, 0x2000, 0x1000, 3, 3, &need_locks);
75 75 ASSERT_NE(vma_new, vma_orig);
76 76 ASSERT_EQ(vma_new, vma);
77 77 ASSERT_EQ(vma_new->vm_start, 0x1000);
@@ -82,7 +82,7 @@ static bool test_copy_vma(void)
82 82 /* Move backwards and do not merge. */
83 83
84 84 vma = alloc_and_link_vma(&mm, 0x3000, 0x5000, 3, vma_flags);
85 - vma_new = copy_vma(&vma, 0, 0x2000, 0, 3, &need_locks, false);
85 + vma_new = copy_vma(&vma, 0, 0x2000, 0, 3, &need_locks);
86 86 ASSERT_NE(vma_new, vma);
87 87 ASSERT_EQ(vma_new->vm_start, 0);
88 88 ASSERT_EQ(vma_new->vm_end, 0x2000);
@@ -95,7 +95,7 @@ static bool test_copy_vma(void)
95 95
96 96 vma = alloc_and_link_vma(&mm, 0, 0x2000, 0, vma_flags);
97 97 vma_next = alloc_and_link_vma(&mm, 0x6000, 0x8000, 6, vma_flags);
98 - vma_new = copy_vma(&vma, 0x4000, 0x2000, 4, 4, &need_locks, false);
98 + vma_new = copy_vma(&vma, 0x4000, 0x2000, 4, 4, &need_locks);
99 99 vma_assert_attached(vma_new);
100 100
101 101 ASSERT_EQ(vma_new, vma_next);