Compare

fcbc48dc650d2f58bfe19c4486830de0e9cad62e..32c52ec87d6245ee2d12ed5dd509e40062939b50

x86/insn-eval: Fix shadowed segment index in get_seg_reg_override_idx()

Commit 45e1dccc0653 ("x86/insn: Simplify for_each_insn_prefix()") made
for_each_insn_prefix() declare its own loop counter named idx.
get_seg_reg_override_idx() keeps its result in a local of the same name,
so the assignments in the loop body now write the loop counter:

 - the function always returns INAT_SEG_REG_DEFAULT, so FS and GS
   overrides are ignored;

 - a CS override sets the counter to INAT_SEG_REG_CS (2), the increment
   makes it 3, and prefixes.bytes[3] holds the last prefix, 0x2e again,
   so the loop never terminates.

The UMIP emulation reaches this from the #GP handler for user space: an
SGDT, SIDT or SMSW with a memory operand and a CS prefix leaves the task
spinning in the kernel, never returning to user space, with a SIGKILL
that is never delivered.  Any user can thus tie up CPUs until reboot.
With an FS or GS prefix, the emulated result is written to the wrong
address.

Rename the internal macro iterator variable.

[ Lukas' original patch renamed the use site, I changed it to rename the
  iterator in the macro instead, but left Lukas' commit message and
  authorship   - Linus ]

Fixes: 45e1dccc0653 ("x86/insn: Simplify for_each_insn_prefix()")
Signed-off-by: Lukas Zobernig <lukas.zobernig@gmail.com>
Acked-by: Peter Zijlstra <peterz@infradead.org>
Acked-by: Borislav Petkov <bp@alien8.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

Lukas Zobernig <lukas.zobernig@gmail.com> · 2026-10-17 01:04 UTC · committed by Linus Torvalds

Browse files
172 files changed, +1743 −645
modified MAINTAINERS
@@ -8013,6 +8013,7 @@ F: include/uapi/drm/ivpu_accel.h
8013 8013
8014 8014 DRM ACCEL DRIVER FOR ROCKCHIP NPU
8015 8015 M: Tomeu Vizoso <tomeu@tomeuvizoso.net>
8016 + R: Heiko Stuebner <heiko@sntech.de>
8016 8017 L: dri-devel@lists.freedesktop.org
8017 8018 S: Supported
8018 8019 T: git https://gitlab.freedesktop.org/drm/misc/kernel.git
@@ -8170,7 +8171,6 @@ F: drivers/gpu/drm/tiny/hx8357d.c
8170 8171
8171 8172 DRM DRIVER FOR HYPERV SYNTHETIC VIDEO DEVICE
8172 8173 M: Dexuan Cui <decui@microsoft.com>
8173 - M: Long Li <longli@microsoft.com>
8174 8174 M: Saurabh Sengar <ssengar@linux.microsoft.com>
8175 8175 L: linux-hyperv@vger.kernel.org
8176 8176 L: dri-devel@lists.freedesktop.org
@@ -8575,7 +8575,7 @@ F: Documentation/devicetree/bindings/display/panel/synaptics,r63353.yaml
8575 8575 F: drivers/gpu/drm/panel/panel-synaptics-r63353.c
8576 8576
8577 8577 DRM DRIVER FOR SYNOPSYS DESIGNWARE DISPLAYPORT BRIDGE
8578 - M: Andy Yan <andy.yan@rock-chips.com>
8578 + M: Andy Yan <andyshrk@163.com>
8579 8579 S: Maintained
8580 8580 T: git https://gitlab.freedesktop.org/drm/misc/kernel.git
8581 8581 F: Documentation/devicetree/bindings/display/rockchip/rockchip,dw-dp.yaml
@@ -8928,7 +8928,7 @@ F: include/linux/platform_data/shmob_drm.h
8928 8928 DRM DRIVERS FOR ROCKCHIP
8929 8929 M: Sandy Huang <hjc@rock-chips.com>
8930 8930 M: Heiko Stübner <heiko@sntech.de>
8931 - M: Andy Yan <andy.yan@rock-chips.com>
8931 + M: Andy Yan <andyshrk@163.com>
8932 8932 L: dri-devel@lists.freedesktop.org
8933 8933 L: linux-rockchip@lists.infradead.org
8934 8934 S: Maintained
@@ -10102,7 +10102,6 @@ F: tools/testing/selftests/mount_setattr/
10102 10102
10103 10103 FILESYSTEMS [IOMAP]
10104 10104 M: Christian Brauner <brauner@kernel.org>
10105 - R: Darrick J. Wong <djwong@kernel.org>
10106 10105 L: linux-xfs@vger.kernel.org
10107 10106 L: linux-fsdevel@vger.kernel.org
10108 10107 S: Supported
@@ -12161,11 +12160,9 @@ S: Maintained
12161 12160 F: drivers/media/i2c/hi847.c
12162 12161
12163 12162 Hyper-V/Azure CORE AND DRIVERS
12164 - M: "K. Y. Srinivasan" <kys@microsoft.com>
12165 12163 M: Haiyang Zhang <haiyangz@microsoft.com>
12166 12164 M: Wei Liu <wei.liu@kernel.org>
12167 12165 M: Dexuan Cui <decui@microsoft.com>
12168 - M: Long Li <longli@microsoft.com>
12169 12166 L: linux-hyperv@vger.kernel.org
12170 12167 S: Supported
12171 12168 T: git git://git.kernel.org/pub/scm/linux/kernel/git/hyperv/linux.git
@@ -12883,7 +12880,7 @@ S: Maintained
12883 12880 F: drivers/power/supply/ip5xxx_power.c
12884 12881
12885 12882 INNOSILICON HDMI BRIDGE DRIVER
12886 - M: Andy Yan <andy.yan@rock-chips.com>
12883 + M: Andy Yan <andyshrk@163.com>
12887 12884 L: dri-devel@lists.freedesktop.org
12888 12885 S: Maintained
12889 12886 T: git https://gitlab.freedesktop.org/drm/misc/kernel.git
@@ -18818,6 +18815,7 @@ F: drivers/hwmon/nct7363.c
18818 18815
18819 18816 NETCONSOLE
18820 18817 M: Breno Leitao <leitao@debian.org>
18818 + R: Gustavo Luiz Duarte <gustavold@gmail.com>
18821 18819 S: Maintained
18822 18820 F: Documentation/networking/netconsole.rst
18823 18821 F: drivers/net/netconsole.c
modified arch/arm/boot/dts/ti/omap/dra7xx-clocks.dtsi
@@ -1376,8 +1376,8 @@
1376 1376 clocks = <&apll_pcie_ck>;
1377 1377 #clock-cells = <0>;
1378 1378 reg = <0x021c>;
1379 + ti,dividers = <2>, <1>;
1379 1380 ti,bit-shift = <8>;
1380 - ti,max-div = <2>;
1381 1381 };
1382 1382
1383 1383 apll_pcie_clkvcoldo: clock-apll-pcie-clkvcoldo {
modified arch/arm/configs/sama5_defconfig
@@ -69,8 +69,8 @@ CONFIG_BLK_DEV_SD=y
69 69 # CONFIG_BLK_DEV_BSG is not set
70 70 # CONFIG_SCSI_LOWLEVEL is not set
71 71 CONFIG_NETDEVICES=y
72 - CONFIG_NET_DSA_MICROCHIP_KSZ9477=m
73 - CONFIG_NET_DSA_MICROCHIP_KSZ9477_SPI=m
72 + CONFIG_NET_DSA_MICROCHIP_KSZ_COMMON=m
73 + CONFIG_NET_DSA_MICROCHIP_KSZ_SPI=m
74 74 # CONFIG_NET_VENDOR_BROADCOM is not set
75 75 CONFIG_MACB=y
76 76 # CONFIG_NET_VENDOR_CIRRUS is not set
modified arch/arm64/boot/dts/nvidia/tegra264-p4071-0000+p3834.dtsi
@@ -9,4 +9,17 @@
9 9 chosen {
10 10 stdout-path = "serial0:115200n8";
11 11 };
12 +
13 + bus@0 {
14 + pwm@c6a0000 {
15 + status = "okay";
16 + };
17 + };
18 +
19 + fan: pwm-fan {
20 + compatible = "pwm-fan";
21 + cooling-levels = <77 102 140 192 255>;
22 + pwms = <&pwm4 0 40000>;
23 + #cooling-cells = <2>;
24 + };
12 25 };
modified arch/arm64/boot/dts/nvidia/tegra264.dtsi
@@ -3356,6 +3356,18 @@
3356 3356 status = "disabled";
3357 3357 };
3358 3358
3359 + pwm4: pwm@c6a0000 {
3360 + compatible = "nvidia,tegra264-pwm";
3361 + reg = <0x0 0xc6a0000 0x0 0x10000>;
3362 + status = "disabled";
3363 +
3364 + clocks = <&bpmp TEGRA264_CLK_PWM4>;
3365 + resets = <&bpmp TEGRA264_RESET_PWM4>;
3366 + reset-names = "pwm";
3367 +
3368 + #pwm-cells = <2>;
3369 + };
3370 +
3359 3371 pinmux_aon: pinmux@c7a2000 {
3360 3372 compatible = "nvidia,tegra264-pinmux-aon";
3361 3373 reg = <0x0 0x0c7a2000 0x0 0x2000>;
@@ -3537,11 +3549,11 @@
3537 3549
3538 3550 pci@c000000 {
3539 3551 compatible = "nvidia,tegra264-pcie";
3540 - reg = <0xd0 0xb0000000 0x0 0x10000000>,
3541 - <0x00 0x0c000000 0x0 0x00004000>,
3552 + reg = <0x00 0x0c000000 0x0 0x00004000>,
3542 3553 <0x00 0x0c004000 0x0 0x00001000>,
3543 - <0x00 0x0c005000 0x0 0x00001000>;
3544 - reg-names = "ecam", "xal", "xtl", "xtl-pri";
3554 + <0x00 0x0c005000 0x0 0x00001000>,
3555 + <0xd0 0xb0000000 0x0 0x10000000>;
3556 + reg-names = "xal", "xtl", "xtl-pri", "ecam";
3545 3557 #address-cells = <3>;
3546 3558 #size-cells = <2>;
3547 3559 device_type = "pci";
@@ -3565,6 +3577,16 @@
3565 3577
3566 3578 nvidia,bpmp = <&bpmp 0>;
3567 3579 status = "disabled";
3580 +
3581 + pcie@0 {
3582 + device_type = "pci";
3583 + compatible = "pciclass,0604";
3584 + reg = <0x0 0x0 0x0 0x0 0x0>;
3585 + bus-range = <0x01 0xff>;
3586 + #address-cells = <3>;
3587 + #size-cells = <2>;
3588 + ranges;
3589 + };
3568 3590 };
3569 3591
3570 3592 pinmux_main: pinmux@c281000 {
@@ -3661,6 +3683,66 @@
3661 3683 status = "disabled";
3662 3684 };
3663 3685
3686 + pwm2: pwm@c5e0000 {
3687 + compatible = "nvidia,tegra264-pwm";
3688 + reg = <0x0 0xc5e0000 0x0 0x10000>;
3689 + status = "disabled";
3690 +
3691 + clocks = <&bpmp TEGRA264_CLK_PWM2>;
3692 + resets = <&bpmp TEGRA264_RESET_PWM2>;
3693 + reset-names = "pwm";
3694 +
3695 + #pwm-cells = <2>;
3696 + };
3697 +
3698 + pwm3: pwm@c5f0000 {
3699 + compatible = "nvidia,tegra264-pwm";
3700 + reg = <0x0 0xc5f0000 0x0 0x10000>;
3701 + status = "disabled";
3702 +
3703 + clocks = <&bpmp TEGRA264_CLK_PWM3>;
3704 + resets = <&bpmp TEGRA264_RESET_PWM3>;
3705 + reset-names = "pwm";
3706 +
3707 + #pwm-cells = <2>;
3708 + };
3709 +
3710 + pwm5: pwm@c600000 {
3711 + compatible = "nvidia,tegra264-pwm";
3712 + reg = <0x0 0xc600000 0x0 0x10000>;
3713 + status = "disabled";
3714 +
3715 + clocks = <&bpmp TEGRA264_CLK_PWM5>;
3716 + resets = <&bpmp TEGRA264_RESET_PWM5>;
3717 + reset-names = "pwm";
3718 +
3719 + #pwm-cells = <2>;
3720 + };
3721 +
3722 + pwm9: pwm@c610000 {
3723 + compatible = "nvidia,tegra264-pwm";
3724 + reg = <0x0 0xc610000 0x0 0x10000>;
3725 + status = "disabled";
3726 +
3727 + clocks = <&bpmp TEGRA264_CLK_PWM9>;
3728 + resets = <&bpmp TEGRA264_RESET_PWM9>;
3729 + reset-names = "pwm";
3730 +
3731 + #pwm-cells = <2>;
3732 + };
3733 +
3734 + pwm10: pwm@c620000 {
3735 + compatible = "nvidia,tegra264-pwm";
3736 + reg = <0x0 0xc620000 0x0 0x10000>;
3737 + status = "disabled";
3738 +
3739 + clocks = <&bpmp TEGRA264_CLK_PWM10>;
3740 + resets = <&bpmp TEGRA264_RESET_PWM10>;
3741 + reset-names = "pwm";
3742 +
3743 + #pwm-cells = <2>;
3744 + };
3745 +
3664 3746 i2c0: i2c@c630000 {
3665 3747 compatible = "nvidia,tegra264-i2c";
3666 3748 reg = <0x00 0x0c630000 0x0 0x10000>;
@@ -3990,12 +4072,12 @@
3990 4072
3991 4073 pci@8400000 {
3992 4074 compatible = "nvidia,tegra264-pcie";
3993 - reg = <0xa8 0xb0000000 0x0 0x10000000>,
3994 - <0x00 0x08400000 0x0 0x00004000>,
4075 + reg = <0x00 0x08400000 0x0 0x00004000>,
3995 4076 <0x00 0x08404000 0x0 0x00001000>,
3996 4077 <0x00 0x08405000 0x0 0x00001000>,
3997 - <0x00 0x08410000 0x0 0x00010000>;
3998 - reg-names = "ecam", "xal", "xtl", "xtl-pri", "xpl";
4078 + <0x00 0x08410000 0x0 0x00010000>,
4079 + <0xa8 0xb0000000 0x0 0x10000000>;
4080 + reg-names = "xal", "xtl", "xtl-pri", "xpl", "ecam";
3999 4081 #address-cells = <3>;
4000 4082 #size-cells = <2>;
4001 4083 device_type = "pci";
@@ -4018,16 +4100,26 @@
4018 4100
4019 4101 nvidia,bpmp = <&bpmp 1>;
4020 4102 status = "disabled";
4103 +
4104 + pcie@0 {
4105 + device_type = "pci";
4106 + compatible = "pciclass,0604";
4107 + reg = <0x0 0x0 0x0 0x0 0x0>;
4108 + bus-range = <0x01 0xff>;
4109 + #address-cells = <3>;
4110 + #size-cells = <2>;
4111 + ranges;
4112 + };
4021 4113 };
4022 4114
4023 4115 pci@8420000 {
4024 4116 compatible = "nvidia,tegra264-pcie";
4025 - reg = <0xb0 0xb0000000 0x0 0x10000000>,
4026 - <0x00 0x08420000 0x0 0x00004000>,
4117 + reg = <0x00 0x08420000 0x0 0x00004000>,
4027 4118 <0x00 0x08424000 0x0 0x00001000>,
4028 4119 <0x00 0x08425000 0x0 0x00001000>,
4029 - <0x00 0x08430000 0x0 0x00010000>;
4030 - reg-names = "ecam", "xal", "xtl", "xtl-pri", "xpl";
4120 + <0x00 0x08430000 0x0 0x00010000>,
4121 + <0xb0 0xb0000000 0x0 0x10000000>;
4122 + reg-names = "xal", "xtl", "xtl-pri", "xpl", "ecam";
4031 4123 #address-cells = <3>;
4032 4124 #size-cells = <2>;
4033 4125 device_type = "pci";
@@ -4050,16 +4142,26 @@
4050 4142
4051 4143 nvidia,bpmp = <&bpmp 2>;
4052 4144 status = "disabled";
4145 +
4146 + pcie@0 {
4147 + device_type = "pci";
4148 + compatible = "pciclass,0604";
4149 + reg = <0x0 0x0 0x0 0x0 0x0>;
4150 + bus-range = <0x01 0xff>;
4151 + #address-cells = <3>;
4152 + #size-cells = <2>;
4153 + ranges;
4154 + };
4053 4155 };
4054 4156
4055 4157 pci@8440000 {
4056 4158 compatible = "nvidia,tegra264-pcie";
4057 - reg = <0xb8 0xb0000000 0x0 0x10000000>,
4058 - <0x00 0x08440000 0x0 0x00004000>,
4159 + reg = <0x00 0x08440000 0x0 0x00004000>,
4059 4160 <0x00 0x08444000 0x0 0x00001000>,
4060 4161 <0x00 0x08445000 0x0 0x00001000>,
4061 - <0x00 0x08450000 0x0 0x00010000>;
4062 - reg-names = "ecam", "xal", "xtl", "xtl-pri", "xpl";
4162 + <0x00 0x08450000 0x0 0x00010000>,
4163 + <0xb8 0xb0000000 0x0 0x10000000>;
4164 + reg-names = "xal", "xtl", "xtl-pri", "xpl", "ecam";
4063 4165 #address-cells = <3>;
4064 4166 #size-cells = <2>;
4065 4167 device_type = "pci";
@@ -4082,16 +4184,26 @@
4082 4184
4083 4185 nvidia,bpmp = <&bpmp 3>;
4084 4186 status = "disabled";
4187 +
4188 + pcie@0 {
4189 + device_type = "pci";
4190 + compatible = "pciclass,0604";
4191 + reg = <0x0 0x0 0x0 0x0 0x0>;
4192 + bus-range = <0x01 0xff>;
4193 + #address-cells = <3>;
4194 + #size-cells = <2>;
4195 + ranges;
4196 + };
4085 4197 };
4086 4198
4087 4199 pci@8460000 {
4088 4200 compatible = "nvidia,tegra264-pcie";
4089 - reg = <0xc0 0xb0000000 0x0 0x10000000>,
4090 - <0x00 0x08460000 0x0 0x00004000>,
4201 + reg = <0x00 0x08460000 0x0 0x00004000>,
4091 4202 <0x00 0x08464000 0x0 0x00001000>,
4092 4203 <0x00 0x08465000 0x0 0x00001000>,
4093 - <0x00 0x08470000 0x0 0x00010000>;
4094 - reg-names = "ecam", "xal", "xtl", "xtl-pri", "xpl";
4204 + <0x00 0x08470000 0x0 0x00010000>,
4205 + <0xc0 0xb0000000 0x0 0x10000000>;
4206 + reg-names = "xal", "xtl", "xtl-pri", "xpl", "ecam";
4095 4207 #address-cells = <3>;
4096 4208 #size-cells = <2>;
4097 4209 device_type = "pci";
@@ -4114,16 +4226,26 @@
4114 4226
4115 4227 nvidia,bpmp = <&bpmp 4>;
4116 4228 status = "disabled";
4229 +
4230 + pcie@0 {
4231 + device_type = "pci";
4232 + compatible = "pciclass,0604";
4233 + reg = <0x0 0x0 0x0 0x0 0x0>;
4234 + bus-range = <0x01 0xff>;
4235 + #address-cells = <3>;
4236 + #size-cells = <2>;
4237 + ranges;
4238 + };
4117 4239 };
4118 4240
4119 4241 pci@8480000 {
4120 4242 compatible = "nvidia,tegra264-pcie";
4121 - reg = <0xc8 0xb0000000 0x0 0x10000000>,
4122 - <0x00 0x08480000 0x0 0x00004000>,
4243 + reg = <0x00 0x08480000 0x0 0x00004000>,
4123 4244 <0x00 0x08484000 0x0 0x00001000>,
4124 4245 <0x00 0x08485000 0x0 0x00001000>,
4125 - <0x00 0x08490000 0x0 0x00010000>;
4126 - reg-names = "ecam", "xal", "xtl", "xtl-pri", "xpl";
4246 + <0x00 0x08490000 0x0 0x00010000>,
4247 + <0xc8 0xb0000000 0x0 0x10000000>;
4248 + reg-names = "xal", "xtl", "xtl-pri", "xpl", "ecam";
4127 4249 #address-cells = <3>;
4128 4250 #size-cells = <2>;
4129 4251 device_type = "pci";
@@ -4146,6 +4268,16 @@
4146 4268
4147 4269 nvidia,bpmp = <&bpmp 5>;
4148 4270 status = "disabled";
4271 +
4272 + pcie@0 {
4273 + device_type = "pci";
4274 + compatible = "pciclass,0604";
4275 + reg = <0x0 0x0 0x0 0x0 0x0>;
4276 + bus-range = <0x01 0xff>;
4277 + #address-cells = <3>;
4278 + #size-cells = <2>;
4279 + ranges;
4280 + };
4149 4281 };
4150 4282 };
4151 4283
modified arch/nios2/include/asm/checksum.h
@@ -27,7 +27,7 @@ static inline __sum16 csum_fold(__wsum sum)
27 27 "add %0, %0, r8\n"
28 28 "nor %0, %0, %0\n"
29 29 : "=r" (sum)
30 - : "r" (sum << 16), "0" (sum)
30 + : "r" ((__force u32)sum << 16), "0" (sum)
31 31 : "r8");
32 32 return (__force __sum16) sum;
33 33 }
modified arch/riscv/boot/dts/microchip/mpfs-beaglev-fire.dts
@@ -90,10 +90,6 @@
90 90 };
91 91
92 92 &gpio0 {
93 - interrupts = <13>, <14>, <15>, <16>,
94 - <17>, <18>, <19>, <20>,
95 - <21>, <22>, <23>, <24>,
96 - <25>, <26>;
97 93 ngpios = <14>;
98 94 gpio-line-names = "", "", "", "", "", "", "",
99 95 "", "", "", "", "", "SD_CARD_CS", "USER_BUTTON";
@@ -101,12 +97,6 @@
101 97 };
102 98
103 99 &gpio1 {
104 - interrupts = <27>, <28>, <29>, <30>,
105 - <31>, <32>, <33>, <34>,
106 - <35>, <36>, <37>, <38>,
107 - <39>, <40>, <41>, <42>,
108 - <43>, <44>, <45>, <46>,
109 - <47>, <48>, <49>, <50>;
110 100 ngpios = <24>;
111 101 gpio-line-names = "", "", "", "", "", "", "", "", "", "",
112 102 "", "", "", "", "", "", "", "", "", "",
@@ -115,14 +105,6 @@
115 105 };
116 106
117 107 &gpio2 {
118 - interrupts = <53>, <53>, <53>, <53>,
119 - <53>, <53>, <53>, <53>,
120 - <53>, <53>, <53>, <53>,
121 - <53>, <53>, <53>, <53>,
122 - <53>, <53>, <53>, <53>,
123 - <53>, <53>, <53>, <53>,
124 - <53>, <53>, <53>, <53>,
125 - <53>, <53>, <53>, <53>;
126 108 ngpios = <32>;
127 109 gpio-line-names = "P8_PIN3_USER_LED_0", "P8_PIN4_USER_LED_1", "P8_PIN5_USER_LED_2",
128 110 "P8_PIN6_USER_LED_3", "P8_PIN7_USER_LED_4", "P8_PIN8_USER_LED_5",
modified arch/x86/hyperv/hv_init.c
@@ -426,7 +426,7 @@ static void __init hv_stimer_setup_percpu_clockev(void)
426 426 int ret;
427 427
428 428 /*
429 - * Continue afters errors in setting up stimer clockevents
429 + * Continue after errors in setting up stimer clockevents
430 430 * as we can run with the LAPIC timer as a fallback.
431 431 */
432 432 ret = hv_stimer_alloc(false);
@@ -434,7 +434,7 @@ static void __init hv_stimer_setup_percpu_clockev(void)
434 434 pr_warn("stimer setup failed with error %d\n", ret);
435 435
436 436 /*
437 - * Still register the LAPIC timer to allows users
437 + * Still register the LAPIC timer to allow users
438 438 * to switch to LAPIC timer via /sys, if they want to.
439 439 */
440 440 if (old_setup_percpu_clockev)
@@ -727,7 +727,8 @@ int hv_apicid_to_vp_index(u32 apic_id)
727 727 input->partition_id = HV_PARTITION_ID_SELF;
728 728 input->apic_ids[0] = apic_id;
729 729
730 - output = *this_cpu_ptr(hyperv_pcpu_output_arg);
730 + /* Treat input as having 2 APIC IDs so output is 64-bit aligned */
731 + output = (void *)input + struct_size(input, apic_ids, 2);
731 732
732 733 control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_INDEX_FROM_APIC_ID;
733 734 status = hv_do_hypercall(control, input, output);
modified arch/x86/include/asm/insn.h
@@ -321,7 +321,7 @@ static inline int insn_offset_immediate(struct insn *insn)
321 321 * are repeated, it cannot be used for looping over the prefixes.
322 322 */
323 323 #define for_each_insn_prefix(insn, prefix) \
324 - for (int idx = 0; idx < ARRAY_SIZE(insn->prefixes.bytes) && (prefix = insn->prefixes.bytes[idx]) != 0; idx++)
324 + for (int __i = 0; __i < ARRAY_SIZE(insn->prefixes.bytes) && (prefix = insn->prefixes.bytes[__i]) != 0; __i++)
325 325
326 326 #define POP_SS_OPCODE 0x1f
327 327 #define MOV_SREG_OPCODE 0x8e
modified arch/x86/kernel/kvm.c
@@ -265,11 +265,39 @@ noinstr u32 kvm_read_and_reset_apf_flags(void)
265 265 }
266 266 EXPORT_SYMBOL_FOR_KVM(kvm_read_and_reset_apf_flags);
267 267
268 + static __always_inline bool kvm_apf_reason_pending(void)
269 + {
270 + return __this_cpu_read(async_pf_enabled) &&
271 + __this_cpu_read(apf_reason.flags);
272 + }
273 +
268 274 noinstr bool __kvm_handle_async_pf(struct pt_regs *regs, u32 token)
269 275 {
270 - u32 flags = kvm_read_and_reset_apf_flags();
271 276 irqentry_state_t state;
277 + u32 flags;
278 +
279 + if (!kvm_apf_reason_pending())
280 + return false;
281 +
282 + /*
283 + * The guest does not enable KVM_ASYNC_PF_SEND_ALWAYS, so the host
284 + * delivers async #PF only to user mode (or as a #PF VM-exit, which KVM
285 + * reads itself). A #PF from kernel mode can still arrive between that
286 + * delivery and the read of the reason flags, inside an NMI that
287 + * interrupted it, for instance perf reading user memory for a call
288 + * chain. Such a fault is not async, so leave the async PF flags
289 + * untouched for the outer handler. Outside NMI context, on the other
290 + * hand, async PF flags on a kernel-mode fault mean the host is broken.
291 + */
292 + if (!user_mode(regs)) {
293 + if (likely(in_nmi()))
294 + return false;
295 + state = irqentry_enter(regs);
296 + instrumentation_begin();
297 + panic("Host injected async #PF in kernel mode\n");
298 + }
272 299
300 + flags = kvm_read_and_reset_apf_flags();
273 301 if (!flags)
274 302 return false;
275 303
@@ -285,8 +313,6 @@ noinstr bool __kvm_handle_async_pf(struct pt_regs *regs, u32 token)
285 313 panic("Host injected async #PF in interrupt disabled region\n");
286 314
287 315 if (flags & KVM_PV_REASON_PAGE_NOT_PRESENT) {
288 - if (unlikely(!(user_mode(regs))))
289 - panic("Host injected async #PF in kernel mode\n");
290 316 /* Page is swapped out by the host. */
291 317 kvm_async_pf_task_wait_schedule(token);
292 318 } else {
modified arch/x86/kvm/mmu.h
@@ -275,8 +275,18 @@ static inline u8 permission_fault(struct kvm_vcpu *vcpu, struct kvm_pagewalk *w,
275 275 unsigned pte_access, unsigned pte_pkey,
276 276 u64 access)
277 277 {
278 - /* strip nested paging fault error codes */
279 - unsigned int pfec = access;
278 + /*
279 + * Of the error codes that do not contribute to the index in
280 + * fmt->permissions, PK and SS are not supported by shadow paging
281 + * and also not provided to EPT violations, but SS *is* included
282 + * in the NPT exit code. RSVD faults are handled elsewhere.
283 + */
284 + unsigned int pfec = access & ~PFERR_SS_MASK;
285 + if (WARN_ON_ONCE(pfec & ~(PFERR_PRESENT_MASK | PFERR_WRITE_MASK |
286 + PFERR_USER_MASK | PFERR_FETCH_MASK)))
287 + pfec &= (PFERR_PRESENT_MASK | PFERR_WRITE_MASK |
288 + PFERR_USER_MASK | PFERR_FETCH_MASK);
289 +
280 290 unsigned long rflags = kvm_x86_call(get_rflags)(vcpu);
281 291
282 292 /*
@@ -301,8 +311,6 @@ static inline u8 permission_fault(struct kvm_vcpu *vcpu, struct kvm_pagewalk *w,
301 311 kvm_mmu_refresh_passthrough_bits(vcpu, w);
302 312
303 313 fault = (fmt->permissions[index] >> pte_access) & 1;
304 -
305 - WARN_ON_ONCE(pfec & (PFERR_PK_MASK | PFERR_SS_MASK | PFERR_RSVD_MASK));
306 314 if (unlikely(fmt->pkru_mask)) {
307 315 u32 pkru_bits, offset;
308 316
modified arch/x86/kvm/mmu/paging_tmpl.h
@@ -328,7 +328,6 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
328 328 int offset;
329 329 u64 walk_nx_mask = 0;
330 330 const int write_fault = access & PFERR_WRITE_MASK;
331 - const int user_fault = access & PFERR_USER_MASK;
332 331 const int fetch_fault = access & PFERR_FETCH_MASK;
333 332 /*
334 333 * Note! Track the error_code that's common to legacy shadow paging
@@ -486,7 +485,7 @@ retry_walk:
486 485 return 1;
487 486
488 487 error:
489 - errcode |= write_fault | user_fault;
488 + errcode |= access & (PFERR_WRITE_MASK | PFERR_USER_MASK | PFERR_SS_MASK);
490 489 if (fetch_fault && has_pferr_fetch(w))
491 490 errcode |= PFERR_FETCH_MASK;
492 491
modified arch/x86/kvm/svm/avic.c
@@ -395,6 +395,11 @@ static phys_addr_t avic_get_backing_page_address(struct vcpu_svm *svm)
395 395 return __sme_set(__pa(svm->vcpu.arch.apic->regs));
396 396 }
397 397
398 + static bool avic_is_addressable_vcpu(struct kvm_vcpu *vcpu)
399 + {
400 + return vcpu->vcpu_id <= __avic_get_max_physical_id(vcpu->kvm, NULL);
401 + }
402 +
398 403 void avic_init_vmcb(struct vcpu_svm *svm, struct vmcb *vmcb)
399 404 {
400 405 struct kvm_svm *kvm_svm = to_kvm_svm(svm->vcpu.kvm);
@@ -412,7 +417,6 @@ void avic_init_vmcb(struct vcpu_svm *svm, struct vmcb *vmcb)
412 417
413 418 static int avic_init_backing_page(struct kvm_vcpu *vcpu)
414 419 {
415 - u32 max_id = x2avic_enabled ? x2avic_max_physical_id : AVIC_MAX_PHYSICAL_ID;
416 420 struct kvm_svm *kvm_svm = to_kvm_svm(vcpu->kvm);
417 421 struct vcpu_svm *svm = to_svm(vcpu);
418 422 u32 id = vcpu->vcpu_id;
@@ -425,7 +429,7 @@ static int avic_init_backing_page(struct kvm_vcpu *vcpu)
425 429 * avic_vcpu_load() expects to be called if and only if the vCPU has
426 430 * fully initialized AVIC.
427 431 */
428 - if (id > max_id) {
432 + if (!avic_is_addressable_vcpu(vcpu)) {
429 433 kvm_set_apicv_inhibit(vcpu->kvm, APICV_INHIBIT_REASON_PHYSICAL_ID_TOO_BIG);
430 434 vcpu->arch.apic->apicv_active = false;
431 435 return 0;
@@ -885,6 +889,14 @@ int avic_init_vcpu(struct vcpu_svm *svm)
885 889 return ret;
886 890 }
887 891
892 + void avic_vcpu_free(struct kvm_vcpu *vcpu)
893 + {
894 + struct kvm_svm *kvm_svm = to_kvm_svm(vcpu->kvm);
895 +
896 + if (kvm_svm->avic_physical_id_table && avic_is_addressable_vcpu(vcpu))
897 + WRITE_ONCE(kvm_svm->avic_physical_id_table[vcpu->vcpu_id], 0);
898 + }
899 +
888 900 void avic_apicv_post_state_restore(struct kvm_vcpu *vcpu)
889 901 {
890 902 avic_handle_dfr_update(vcpu);
@@ -1045,8 +1057,7 @@ static void __avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu,
1045 1057 if (WARN_ON(h_physical_id & ~AVIC_PHYSICAL_ID_ENTRY_HOST_PHYSICAL_ID_MASK))
1046 1058 return;
1047 1059
1048 - if (WARN_ON_ONCE(vcpu->vcpu_id * sizeof(entry) >=
1049 - PAGE_SIZE << avic_get_physical_id_table_order(vcpu->kvm)))
1060 + if (WARN_ON_ONCE(!avic_is_addressable_vcpu(vcpu)))
1050 1061 return;
1051 1062
1052 1063 /*
@@ -1108,8 +1119,7 @@ static void __avic_vcpu_put(struct kvm_vcpu *vcpu, enum avic_vcpu_action action)
1108 1119
1109 1120 lockdep_assert_preemption_disabled();
1110 1121
1111 - if (WARN_ON_ONCE(vcpu->vcpu_id * sizeof(entry) >=
1112 - PAGE_SIZE << avic_get_physical_id_table_order(vcpu->kvm)))
1122 + if (WARN_ON_ONCE(!avic_is_addressable_vcpu(vcpu)))
1113 1123 return;
1114 1124
1115 1125 /*
modified arch/x86/kvm/svm/sev.c
@@ -2421,7 +2421,7 @@ static int sev_gmem_post_populate(struct kvm *kvm, gfn_t gfn, kvm_pfn_t pfn,
2421 2421 void *dst_vaddr = kmap_local_pfn(pfn);
2422 2422
2423 2423 memcpy(src_vaddr, dst_vaddr, PAGE_SIZE);
2424 - set_page_dirty(src_page);
2424 + set_page_dirty_lock(src_page);
2425 2425
2426 2426 kunmap_local(dst_vaddr);
2427 2427 kunmap_local(src_vaddr);
modified arch/x86/kvm/svm/svm.c
@@ -1328,7 +1328,7 @@ static int svm_vcpu_create(struct kvm_vcpu *vcpu)
1328 1328 svm->msrpm = svm_vcpu_alloc_msrpm();
1329 1329 if (!svm->msrpm) {
1330 1330 err = -ENOMEM;
1331 - goto error_free_sev;
1331 + goto error_free_avic;
1332 1332 }
1333 1333
1334 1334 svm->x2avic_msrs_intercepted = true;
@@ -1342,6 +1342,8 @@ static int svm_vcpu_create(struct kvm_vcpu *vcpu)
1342 1342
1343 1343 return 0;
1344 1344
1345 + error_free_avic:
1346 + avic_vcpu_free(vcpu);
1345 1347 error_free_sev:
1346 1348 sev_free_vcpu(vcpu);
1347 1349 error_free_vmcb_page:
@@ -1356,6 +1358,8 @@ static void svm_vcpu_free(struct kvm_vcpu *vcpu)
1356 1358
1357 1359 WARN_ON_ONCE(!list_empty(&svm->ir_list));
1358 1360
1361 + avic_vcpu_free(vcpu);
1362 +
1359 1363 svm_leave_nested(vcpu);
1360 1364 svm_free_nested(svm);
1361 1365
modified arch/x86/kvm/svm/svm.h
@@ -955,6 +955,7 @@ void avic_init_vmcb(struct vcpu_svm *svm, struct vmcb *vmcb);
955 955 int avic_incomplete_ipi_interception(struct kvm_vcpu *vcpu);
956 956 int avic_unaccelerated_access_interception(struct kvm_vcpu *vcpu);
957 957 int avic_init_vcpu(struct vcpu_svm *svm);
958 + void avic_vcpu_free(struct kvm_vcpu *vcpu);
958 959 void avic_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
959 960 void avic_vcpu_put(struct kvm_vcpu *vcpu);
960 961 void avic_apicv_post_state_restore(struct kvm_vcpu *vcpu);
modified arch/x86/kvm/vmx/nested.c
@@ -3770,8 +3770,10 @@ vmentry_fail_vmexit_guest_mode:
3770 3770 vmentry_fail_vmexit:
3771 3771 vmx_switch_vmcs(vcpu, &vmx->vmcs01);
3772 3772
3773 - if (!from_vmentry)
3773 + if (!from_vmentry) {
3774 + nested_ept_uninit_mmu_context(vcpu);
3774 3775 return NVMX_VMENTRY_VMEXIT;
3776 + }
3775 3777
3776 3778 nested_put_vmcs12_pages(vcpu);
3777 3779
modified arch/x86/kvm/x86.h
@@ -250,7 +250,7 @@ static inline bool is_noncanonical_invlpg_address(u64 la, struct kvm_vcpu *vcpu)
250 250 static inline void vcpu_cache_mmio_info(struct kvm_vcpu *vcpu,
251 251 gva_t gva, gfn_t gfn, unsigned access)
252 252 {
253 - u64 gen = kvm_memslots(vcpu->kvm)->generation;
253 + u64 gen = kvm_vcpu_memslots(vcpu)->generation;
254 254
255 255 if (unlikely(gen & KVM_MEMSLOT_GEN_UPDATE_IN_PROGRESS))
256 256 return;
@@ -267,7 +267,7 @@ static inline void vcpu_cache_mmio_info(struct kvm_vcpu *vcpu,
267 267
268 268 static inline bool vcpu_match_mmio_gen(struct kvm_vcpu *vcpu)
269 269 {
270 - return vcpu->arch.mmio_gen == kvm_memslots(vcpu->kvm)->generation;
270 + return vcpu->arch.mmio_gen == kvm_vcpu_memslots(vcpu)->generation;
271 271 }
272 272
273 273 /*
modified drivers/accel/amdxdna/Kconfig
@@ -6,6 +6,7 @@ config DRM_ACCEL_AMDXDNA
6 6 depends on DRM_ACCEL
7 7 depends on PCI && HAS_IOMEM
8 8 depends on X86_64
9 + depends on AMD_PMF || !AMD_PMF
9 10 select DRM_SCHED
10 11 select DRM_GEM_SHMEM_HELPER
11 12 select FW_LOADER
modified drivers/accel/rocket/rocket_device.c
@@ -31,6 +31,8 @@ struct rocket_device *rocket_device_init(struct platform_device *pdev,
31 31 if (of_device_is_available(core_node))
32 32 num_cores++;
33 33
34 + rdev->max_cores = num_cores;
35 +
34 36 rdev->cores = devm_kcalloc(dev, num_cores, sizeof(*rdev->cores), GFP_KERNEL);
35 37 if (!rdev->cores)
36 38 return ERR_PTR(-ENOMEM);
modified drivers/accel/rocket/rocket_device.h
@@ -19,6 +19,7 @@ struct rocket_device {
19 19
20 20 struct rocket_core *cores;
21 21 unsigned int num_cores;
22 + unsigned int max_cores;
22 23 };
23 24
24 25 struct rocket_device *rocket_device_init(struct platform_device *pdev,
modified drivers/accel/rocket/rocket_drv.c
@@ -165,8 +165,11 @@ static int rocket_probe(struct platform_device *pdev)
165 165 /* First core probing, initialize DRM device. */
166 166 rdev = rocket_device_init(drm_dev, &rocket_drm_driver);
167 167 if (IS_ERR(rdev)) {
168 + int err = PTR_ERR(rdev);
169 +
168 170 dev_err(&pdev->dev, "failed to initialize rocket device\n");
169 - return PTR_ERR(rdev);
171 + rdev = NULL;
172 + return err;
170 173 }
171 174 }
172 175
@@ -223,7 +226,7 @@ static int find_core_for_dev(struct device *dev)
223 226 {
224 227 struct rocket_device *rdev = dev_get_drvdata(dev);
225 228
226 - for (unsigned int core = 0; core < rdev->num_cores; core++) {
229 + for (unsigned int core = 0; core < rdev->max_cores; core++) {
227 230 if (dev == rdev->cores[core].dev)
228 231 return core;
229 232 }
modified drivers/accel/rocket/rocket_job.c
@@ -283,7 +283,7 @@ static struct rocket_core *sched_to_core(struct rocket_device *rdev,
283 283 {
284 284 unsigned int core;
285 285
286 - for (core = 0; core < rdev->num_cores; core++) {
286 + for (core = 0; core < rdev->max_cores; core++) {
287 287 if (&rdev->cores[core].sched == sched)
288 288 return &rdev->cores[core];
289 289 }
modified drivers/dma-buf/Kconfig
@@ -43,7 +43,7 @@ config UDMABUF
43 43 config DMABUF_DEBUG
44 44 bool "DMA-BUF debug checks"
45 45 depends on DMA_SHARED_BUFFER
46 - default y if DEBUG_KERNEL
46 + default y if DEBUG
47 47 help
48 48 This option enables additional checks for DMA-BUF importers and
49 49 exporters. Specifically it validates that importers do not peek at the
modified drivers/gpio/gpio-mxc.c
@@ -7,6 +7,7 @@
7 7 // Authors: Daniel Mack, Juergen Beisert.
8 8 // Copyright (C) 2004-2010 Freescale Semiconductor, Inc. All Rights Reserved.
9 9
10 + #include <linux/bitops.h>
10 11 #include <linux/cleanup.h>
11 12 #include <linux/clk.h>
12 13 #include <linux/err.h>
@@ -68,11 +69,11 @@ struct mxc_gpio_port {
68 69 struct irq_domain *domain;
69 70 struct gpio_generic_chip gen_gc;
70 71 struct device *dev;
71 - u32 both_edges;
72 + unsigned long both_edges;
72 73 struct mxc_gpio_reg_saved gpio_saved_reg;
73 74 bool power_off;
74 - u32 wakeup_pads;
75 75 bool is_pad_wakeup;
76 + unsigned long wakeup_pads;
76 77 u32 pad_type[32];
77 78 const struct mxc_gpio_hwdata *hwdata;
78 79 };
@@ -168,7 +169,7 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type)
168 169 int edge;
169 170 void __iomem *reg = port->base;
170 171
171 - port->both_edges &= ~(1 << gpio_idx);
172 + clear_bit(gpio_idx, &port->both_edges);
172 173 switch (type) {
173 174 case IRQ_TYPE_EDGE_RISING:
174 175 edge = GPIO_INT_RISE_EDGE;
@@ -188,7 +189,7 @@ static int gpio_set_irq_type(struct irq_data *d, u32 type)
188 189 edge = GPIO_INT_HIGH_LEV;
189 190 pr_debug("mxc: set GPIO %d to high trigger\n", gpio_idx);
190 191 }
191 - port->both_edges |= 1 << gpio_idx;
192 + set_bit(gpio_idx, &port->both_edges);
192 193 }
193 194 break;
194 195 case IRQ_TYPE_LEVEL_LOW:
@@ -259,7 +260,7 @@ static void mxc_gpio_irq_handler(struct mxc_gpio_port *port, u32 irq_stat)
259 260 while (irq_stat != 0) {
260 261 int irqoffset = fls(irq_stat) - 1;
261 262
262 - if (port->both_edges & (1 << irqoffset))
263 + if (test_bit(irqoffset, &port->both_edges))
263 264 mxc_flip_edge(port, irqoffset);
264 265
265 266 generic_handle_domain_irq(port->domain, irqoffset);
@@ -330,16 +331,18 @@ static int gpio_set_wake_irq(struct irq_data *d, u32 enable)
330 331 ret = enable_irq_wake(port->irq_high);
331 332 else
332 333 ret = enable_irq_wake(port->irq);
333 - port->wakeup_pads |= BIT(gpio_idx);
334 334 } else {
335 335 if (port->irq_high && (gpio_idx >= 16))
336 336 ret = disable_irq_wake(port->irq_high);
337 337 else
338 338 ret = disable_irq_wake(port->irq);
339 - port->wakeup_pads &= ~BIT(gpio_idx);
340 339 }
340 + if (ret)
341 + return ret;
341 342
342 - return ret;
343 + assign_bit(gpio_idx, &port->wakeup_pads, enable);
344 +
345 + return 0;
343 346 }
344 347
345 348 static int mxc_gpio_init_gc(struct mxc_gpio_port *port, int irq_base)
@@ -474,8 +477,6 @@ static int mxc_gpio_probe(struct platform_device *pdev)
474 477 } else
475 478 port->mx_irq_handler = mx3_gpio_irq_handler;
476 479
477 - mxc_update_irq_chained_handler(port, true);
478 -
479 480 config.dev = &pdev->dev;
480 481 config.sz = 4;
481 482 config.dat = port->base + GPIO_PSR;
@@ -499,10 +500,6 @@ static int mxc_gpio_probe(struct platform_device *pdev)
499 500 else /* silence boot time warning */
500 501 port->gen_gc.gc.base = -1;
501 502
502 - err = devm_gpiochip_add_data(&pdev->dev, &port->gen_gc.gc, port);
503 - if (err)
504 - goto out_bgio;
505 -
506 503 irq_base = devm_irq_alloc_descs(&pdev->dev, -1, 0, 32, numa_node_id());
507 504 if (irq_base < 0) {
508 505 err = irq_base;
@@ -523,8 +520,19 @@ static int mxc_gpio_probe(struct platform_device *pdev)
523 520 if (err < 0)
524 521 goto out_irqdomain_remove;
525 522
523 + /*
524 + * Register the GPIO chip last: devm_gpiochip_add_data() makes the
525 + * chip visible to consumers immediately, so the IRQ domain and
526 + * generic irq chip must be ready before any to_irq() call.
527 + */
528 + err = devm_gpiochip_add_data(&pdev->dev, &port->gen_gc.gc, port);
529 + if (err)
530 + goto out_irqdomain_remove;
531 +
526 532 list_add_tail(&port->node, &mxc_gpio_ports);
527 533
534 + mxc_update_irq_chained_handler(port, true);
535 +
528 536 platform_set_drvdata(pdev, port);
529 537 pm_runtime_put_autosuspend(&pdev->dev);
530 538
modified drivers/gpio/gpiolib-kunit.c
@@ -28,6 +28,8 @@
28 28
29 29 #define GPIO_TEST_PROVIDER_NGPIO 4
30 30
31 + KUNIT_DEFINE_ACTION_WRAPPER(gpio_device_put_wrapper, gpio_device_put, struct gpio_device *);
32 +
31 33 /*
32 34 * The test provider tracks per-line direction and value so that lines can be
33 35 * driven as both inputs and outputs - this is needed to exercise input as well
@@ -770,6 +772,7 @@ static void gpio_hog_assert(struct kunit *test, unsigned int offset,
770 772 struct property_entry properties[2];
771 773 struct platform_device *pdev;
772 774 struct fwnode_handle *fwnode;
775 + struct gpio_device *gdev;
773 776 struct gpio_desc *desc;
774 777 bool bound = true;
775 778 int ret;
@@ -789,10 +792,12 @@ static void gpio_hog_assert(struct kunit *test, unsigned int offset,
789 792 wait_for_device_probe();
790 793
791 794 /* The hog must have configured the line with the expected direction. */
792 - struct gpio_device *gdev __free(gpio_device_put) =
793 - gpio_device_find_by_label(GPIO_CONSUMER_NAME);
795 + gdev = gpio_device_find_by_label(GPIO_CONSUMER_NAME);
794 796 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, gdev);
795 797
798 + ret = kunit_add_action_or_reset(test, gpio_device_put_wrapper, gdev);
799 + KUNIT_ASSERT_EQ(test, ret, 0);
800 +
796 801 desc = gpio_device_get_desc(gdev, offset);
797 802 KUNIT_ASSERT_NOT_ERR_OR_NULL(test, desc);
798 803
modified drivers/gpio/gpiolib-shared.c
@@ -449,10 +449,14 @@ static bool gpio_shared_dev_is_reset_gpio(struct device *consumer,
449 449 int gpio_shared_add_proxy_lookup(struct device *consumer, struct fwnode_handle *fwnode,
450 450 const char *con_id, unsigned long lflags)
451 451 {
452 - const char *dev_id = dev_name(consumer);
453 - struct gpiod_lookup_table *lookup;
454 452 struct gpio_shared_entry *entry;
455 453 struct gpio_shared_ref *ref;
454 + const char *dev_id;
455 +
456 + if (!consumer)
457 + return -EOPNOTSUPP;
458 +
459 + dev_id = dev_name(consumer);
456 460
457 461 list_for_each_entry(entry, &gpio_shared_list, list) {
458 462 list_for_each_entry(ref, &entry->refs, list) {
@@ -480,18 +484,22 @@ int gpio_shared_add_proxy_lookup(struct device *consumer, struct fwnode_handle *
480 484 if (!key)
481 485 return -ENOMEM;
482 486
483 - lookup = kzalloc_flex(*lookup, table, 2);
487 + struct gpiod_lookup_table *lookup __free(kfree) =
488 + kzalloc_flex(*lookup, table, 2);
484 489 if (!lookup)
485 490 return -ENOMEM;
486 491
487 492 pr_debug("Adding machine lookup entry for a shared GPIO for consumer %s, with key '%s' and con_id '%s'\n",
488 493 dev_id, key, ref->con_id ?: "none");
489 494
490 - lookup->dev_id = dev_id;
495 + lookup->dev_id = kstrdup(dev_id, GFP_KERNEL);
496 + if (!lookup->dev_id)
497 + return -ENOMEM;
498 +
491 499 lookup->table[0] = GPIO_LOOKUP(no_free_ptr(key), 0,
492 500 ref->con_id, lflags);
493 501
494 - ref->lookup = lookup;
502 + ref->lookup = no_free_ptr(lookup);
495 503 gpiod_add_lookup_table(ref->lookup);
496 504
497 505 return 0;
@@ -611,6 +619,7 @@ void gpio_device_teardown_shared(struct gpio_device *gdev)
611 619 if (ref->lookup) {
612 620 gpiod_remove_lookup_table(ref->lookup);
613 621 kfree(ref->lookup->table[0].key);
622 + kfree(ref->lookup->dev_id);
614 623 kfree(ref->lookup);
615 624 ref->lookup = NULL;
616 625 }
modified drivers/gpio/gpiolib.c
@@ -3954,16 +3954,17 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,
3954 3954 } while ((i < array_size) &&
3955 3955 gpio_device_chip_cmp(desc_array[i]->gdev, guard.gc));
3956 3956 /* push collected bits to outputs */
3957 - if (count != 0) {
3957 + ret = 0;
3958 + if (count != 0)
3958 3959 ret = gpiochip_set_multiple(guard.gc, mask, bits);
3959 - if (ret)
3960 - return ret;
3961 - }
3962 3960
3963 3961 if (mask != fastpath_mask)
3964 3962 bitmap_free(mask);
3965 3963 if (bits != fastpath_bits)
3966 3964 bitmap_free(bits);
3965 +
3966 + if (ret)
3967 + return ret;
3967 3968 }
3968 3969 return 0;
3969 3970 }
modified drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -1431,6 +1431,7 @@ static void amdgpu_cs_parser_fini(struct amdgpu_cs_parser *parser)
1431 1431 int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
1432 1432 {
1433 1433 struct amdgpu_device *adev = drm_to_adev(dev);
1434 + struct amdgpu_bo_list_entry *e;
1434 1435 struct amdgpu_cs_parser parser;
1435 1436 int r;
1436 1437
@@ -1465,25 +1466,31 @@ int amdgpu_cs_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
1465 1466
1466 1467 r = amdgpu_cs_patch_jobs(&parser);
1467 1468 if (r)
1468 - goto error_fini;
1469 + goto error_free_user_pages;
1469 1470
1470 1471 r = amdgpu_cs_vm_handling(&parser);
1471 1472 if (r)
1472 - goto error_fini;
1473 + goto error_free_user_pages;
1473 1474
1474 1475 r = amdgpu_cs_sync_rings(&parser);
1475 1476 if (r)
1476 - goto error_fini;
1477 + goto error_free_user_pages;
1477 1478
1478 1479 trace_amdgpu_cs_ibs(&parser);
1479 1480
1480 1481 r = amdgpu_cs_submit(&parser, data);
1481 1482 if (r)
1482 - goto error_fini;
1483 + goto error_free_user_pages;
1483 1484
1484 1485 amdgpu_cs_parser_fini(&parser);
1485 1486 return 0;
1486 1487
1488 + error_free_user_pages:
1489 + /* amdgpu_cs_submit() only drops the ranges once it got that far. */
1490 + amdgpu_bo_list_for_each_userptr_entry(e, parser.bo_list) {
1491 + amdgpu_hmm_range_free(e->range);
1492 + e->range = NULL;
1493 + }
1487 1494 error_fini:
1488 1495 amdgpu_cs_parser_fini(&parser);
1489 1496 return r;
modified drivers/gpu/drm/amd/amdgpu/amdgpu_debugfs.c
@@ -1266,7 +1266,6 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
1266 1266 {
1267 1267 struct amdgpu_device *adev = f->f_inode->i_private;
1268 1268 int r;
1269 - ssize_t result = 0;
1270 1269 uint32_t offset, se, sh, cu, wave, simd, thread, bank, *data;
1271 1270
1272 1271 if (size > 4096 || size & 3 || *pos & 3)
@@ -1310,25 +1309,11 @@ static ssize_t amdgpu_debugfs_gpr_read(struct file *f, char __user *buf,
1310 1309 mutex_unlock(&adev->grbm_idx_mutex);
1311 1310
1312 1311 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
1312 + amdgpu_virt_disable_access_debugfs(adev);
1313 1313
1314 - while (size) {
1315 - uint32_t value;
1316 -
1317 - value = data[result >> 2];
1318 - r = put_user(value, (uint32_t *)buf);
1319 - if (r) {
1320 - amdgpu_virt_disable_access_debugfs(adev);
1321 - goto err;
1322 - }
1323 -
1324 - result += 4;
1325 - buf += 4;
1326 - size -= 4;
1327 - }
1328 -
1314 + r = copy_to_user(buf, data, size) ? -EFAULT : size;
1329 1315 kfree(data);
1330 - amdgpu_virt_disable_access_debugfs(adev);
1331 - return result;
1316 + return r;
1332 1317
1333 1318 err:
1334 1319 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
modified drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -337,11 +337,14 @@ static void amdgpu_gem_object_close(struct drm_gem_object *obj,
337 337 goto out_unlock;
338 338 }
339 339
340 + bo_va = amdgpu_vm_bo_find(vm, bo);
341 + /* the fence is attached once per bo_va, so keep it for other handles */
342 + if (bo_va && --bo_va->ref_count)
343 + goto out_unlock;
344 +
340 345 if (!amdgpu_vm_is_bo_always_valid(vm, bo))
341 346 amdgpu_evf_mgr_detach_fence(&fpriv->evf_mgr, bo);
342 -
343 - bo_va = amdgpu_vm_bo_find(vm, bo);
344 - if (!bo_va || --bo_va->ref_count)
347 + if (!bo_va)
345 348 goto out_unlock;
346 349
347 350 amdgpu_vm_bo_del(adev, bo_va);
@@ -567,8 +570,10 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
567 570
568 571 if (args->flags & AMDGPU_GEM_USERPTR_VALIDATE) {
569 572 range = amdgpu_hmm_range_alloc(NULL);
570 - if (unlikely(!range))
571 - return -ENOMEM;
573 + if (unlikely(!range)) {
574 + r = -ENOMEM;
575 + goto release_object;
576 + }
572 577 r = amdgpu_ttm_tt_get_user_pages(bo, range);
573 578 if (r) {
574 579 amdgpu_hmm_range_free(range);
@@ -1236,7 +1241,7 @@ int amdgpu_gem_list_handles_ioctl(struct drm_device *dev, void *data,
1236 1241 bo_entry->alloc_flags = bo->flags & AMDGPU_GEM_CREATE_SETTABLE_MASK;
1237 1242 bo_entry->preferred_domains = bo->preferred_domains;
1238 1243 bo_entry->gem_handle = id;
1239 - bo_entry->alignment = bo->tbo.page_alignment;
1244 + bo_entry->alignment = (u64)bo->tbo.page_alignment << PAGE_SHIFT;
1240 1245
1241 1246 if (bo->tbo.base.import_attach)
1242 1247 bo_entry->flags |= AMDGPU_GEM_LIST_HANDLES_FLAG_IS_IMPORT;
modified drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -2065,14 +2065,15 @@ static int amdgpu_ttm_buffer_entity_init(struct amdgpu_gtt_mgr *mgr,
2065 2065 int i, r, num_pages;
2066 2066 const u64 GTT_MAX_PAGES = (AMDGPU_GTT_MAX_TRANSFER_SIZE >> PAGE_SHIFT);
2067 2067
2068 + if (ARRAY_SIZE(entity->gart_window_offs) < num_gart_windows)
2069 + return -EINVAL;
2070 +
2068 2071 r = drm_sched_entity_init(&entity->base, prio, scheds, num_schedulers, NULL);
2069 2072 if (r)
2070 2073 return r;
2071 2074
2072 2075 mutex_init(&entity->lock);
2073 2076
2074 - if (ARRAY_SIZE(entity->gart_window_offs) < num_gart_windows)
2075 - return -EINVAL;
2076 2077 if (num_gart_windows == 0)
2077 2078 return 0;
2078 2079
@@ -2080,6 +2081,7 @@ static int amdgpu_ttm_buffer_entity_init(struct amdgpu_gtt_mgr *mgr,
2080 2081 r = amdgpu_gtt_mgr_alloc_entries(mgr, &entity->gart_node, num_pages,
2081 2082 DRM_MM_INSERT_BEST);
2082 2083 if (r) {
2084 + mutex_destroy(&entity->lock);
2083 2085 drm_sched_entity_destroy(&entity->base);
2084 2086 return r;
2085 2087 }
@@ -2097,6 +2099,7 @@ static void amdgpu_ttm_buffer_entity_fini(struct amdgpu_gtt_mgr *mgr,
2097 2099 struct amdgpu_ttm_buffer_entity *entity)
2098 2100 {
2099 2101 amdgpu_gtt_mgr_free_entries(mgr, &entity->gart_node);
2102 + mutex_destroy(&entity->lock);
2100 2103 drm_sched_entity_destroy(&entity->base);
2101 2104 }
2102 2105
modified drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c
@@ -980,19 +980,21 @@ amdgpu_userq_bo_validate(struct amdgpu_device *adev, struct drm_exec *exec,
980 980 {
981 981 struct ttm_operation_ctx ctx = { false, false };
982 982 struct amdgpu_bo_va *bo_va;
983 - struct amdgpu_bo *bo;
983 + struct amdgpu_bo *bo, *tmp;
984 984 int ret;
985 985
986 986 spin_lock(&vm->individual_lock);
987 - while (!list_empty(&vm->always_valid.evicted)) {
988 - bo_va = list_first_entry(&vm->always_valid.evicted,
987 + while (!list_empty(&vm->individual.evicted)) {
988 + bo_va = list_first_entry(&vm->individual.evicted,
989 989 struct amdgpu_bo_va,
990 990 base.vm_status);
991 + bo = bo_va->base.bo;
992 + tmp = amdgpu_bo_ref(bo);
991 993 spin_unlock(&vm->individual_lock);
992 994
993 - bo = bo_va->base.bo;
994 995 ret = drm_exec_prepare_obj(exec, &bo->tbo.base,
995 996 TTM_NUM_MOVE_FENCES + 1);
997 + amdgpu_bo_unref(&tmp);
996 998 if (unlikely(ret))
997 999 return ret;
998 1000
modified drivers/gpu/drm/amd/amdgpu/sdma_v3_0.c
@@ -457,6 +457,9 @@ static void sdma_v3_0_ring_emit_hdp_flush(struct amdgpu_ring *ring)
457 457 else
458 458 ref_and_mask = REG_SET_FIELD(ref_and_mask, GPU_HDP_FLUSH_DONE, SDMA1, 1);
459 459
460 + /* Hang workaround */
461 + amdgpu_ring_write(ring, SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP));
462 +
460 463 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_POLL_REGMEM) |
461 464 SDMA_PKT_POLL_REGMEM_HEADER_HDP_FLUSH(1) |
462 465 SDMA_PKT_POLL_REGMEM_HEADER_FUNC(3)); /* == */
@@ -484,6 +487,10 @@ static void sdma_v3_0_ring_emit_fence(struct amdgpu_ring *ring, u64 addr, u64 se
484 487 unsigned flags)
485 488 {
486 489 bool write64bit = flags & AMDGPU_FENCE_FLAG_64BIT;
490 +
491 + /* Hang workaround */
492 + amdgpu_ring_write(ring, SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP));
493 +
487 494 /* write the fence */
488 495 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_FENCE));
489 496 amdgpu_ring_write(ring, lower_32_bits(addr));
@@ -492,7 +499,11 @@ static void sdma_v3_0_ring_emit_fence(struct amdgpu_ring *ring, u64 addr, u64 se
492 499
493 500 /* optionally write high bits as well */
494 501 if (write64bit) {
502 + /* Hang workaround */
503 + amdgpu_ring_write(ring, SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP));
504 +
495 505 addr += 4;
506 +
496 507 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_FENCE));
497 508 amdgpu_ring_write(ring, lower_32_bits(addr));
498 509 amdgpu_ring_write(ring, upper_32_bits(addr));
@@ -1033,6 +1044,9 @@ static void sdma_v3_0_ring_emit_pipeline_sync(struct amdgpu_ring *ring)
1033 1044 uint32_t seq = ring->fence_drv.sync_seq;
1034 1045 uint64_t addr = ring->fence_drv.gpu_addr;
1035 1046
1047 + /* Hang workaround */
1048 + amdgpu_ring_write(ring, SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP));
1049 +
1036 1050 /* wait for idle */
1037 1051 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_POLL_REGMEM) |
1038 1052 SDMA_PKT_POLL_REGMEM_HEADER_HDP_FLUSH(0) |
@@ -1061,6 +1075,9 @@ static void sdma_v3_0_ring_emit_vm_flush(struct amdgpu_ring *ring,
1061 1075 {
1062 1076 amdgpu_gmc_emit_flush_gpu_tlb(ring, vmid, pd_addr);
1063 1077
1078 + /* Hang workaround */
1079 + amdgpu_ring_write(ring, SDMA_PKT_NOP_HEADER_OP(SDMA_OP_NOP));
1080 +
1064 1081 /* wait for flush */
1065 1082 amdgpu_ring_write(ring, SDMA_PKT_HEADER_OP(SDMA_OP_POLL_REGMEM) |
1066 1083 SDMA_PKT_POLL_REGMEM_HEADER_HDP_FLUSH(0) |
@@ -1510,11 +1527,11 @@ static const struct amdgpu_ring_funcs sdma_v3_0_ring_funcs = {
1510 1527 .get_wptr = sdma_v3_0_ring_get_wptr,
1511 1528 .set_wptr = sdma_v3_0_ring_set_wptr,
1512 1529 .emit_frame_size =
1513 - 6 + /* sdma_v3_0_ring_emit_hdp_flush */
1530 + 6 + 1 + /* sdma_v3_0_ring_emit_hdp_flush */
1514 1531 3 + /* hdp invalidate */
1515 - 6 + /* sdma_v3_0_ring_emit_pipeline_sync */
1516 - VI_FLUSH_GPU_TLB_NUM_WREG * 3 + 6 + /* sdma_v3_0_ring_emit_vm_flush */
1517 - 10 + 10 + 10, /* sdma_v3_0_ring_emit_fence x3 for user fence, vm fence */
1532 + 6 + 1 + /* sdma_v3_0_ring_emit_pipeline_sync */
1533 + VI_FLUSH_GPU_TLB_NUM_WREG * 3 + 6 + 1 + /* sdma_v3_0_ring_emit_vm_flush */
1534 + (10 + 1) * 3, /* sdma_v3_0_ring_emit_fence x3 for user fence, vm fence */
1518 1535 .emit_ib_size = 7 + 6, /* sdma_v3_0_ring_emit_ib */
1519 1536 .emit_ib = sdma_v3_0_ring_emit_ib,
1520 1537 .emit_fence = sdma_v3_0_ring_emit_fence,
modified drivers/gpu/drm/amd/amdgpu/uvd_v3_1.c
@@ -288,7 +288,7 @@ static int uvd_v3_1_fw_validate(struct amdgpu_device *adev)
288 288 int i;
289 289 uint32_t keysel = adev->uvd.keyselect;
290 290
291 - if (RREG32(mmUVD_FW_START) & UVD_FW_STATUS__PASS_MASK) {
291 + if (RREG32(mmUVD_FW_START)) {
292 292 dev_dbg(adev->dev, "UVD keyselect already set: 0x%x (on CPU: 0x%x)\n",
293 293 RREG32(mmUVD_FW_START), adev->uvd.keyselect);
294 294 return 0;
modified drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c
@@ -89,6 +89,7 @@ static const struct smu_feature_bits smu_v14_0_2_dpm_features = {
89 89 #define PP_OD_FEATURE_FAN_TARGET_TEMPERATURE 9
90 90 #define PP_OD_FEATURE_FAN_MINIMUM_PWM 10
91 91 #define PP_OD_FEATURE_FAN_ZERO_RPM_ENABLE 11
92 + #define PP_OD_FEATURE_FAN_ZERO_RPM_STOP_TEMP 12
92 93
93 94 static struct cmn2asic_msg_mapping smu_v14_0_2_message_map[SMU_MSG_MAX_COUNT] = {
94 95 MSG_MAP(TestMessage, PPSMC_MSG_TestMessage, 1),
@@ -1020,6 +1021,10 @@ static void smu_v14_0_2_get_od_setting_limits(struct smu_context *smu,
1020 1021 od_min_setting = overdrive_lowerlimits->FanZeroRpmEnable;
1021 1022 od_max_setting = overdrive_upperlimits->FanZeroRpmEnable;
1022 1023 break;
1024 + case PP_OD_FEATURE_FAN_ZERO_RPM_STOP_TEMP:
1025 + od_min_setting = pptable->SkuTable.MsgLimits.FanStopTempMin;
1026 + od_max_setting = pptable->SkuTable.MsgLimits.FanStopTempMax;
1027 + break;
1023 1028 default:
1024 1029 od_min_setting = od_max_setting = INT_MAX;
1025 1030 break;
@@ -1244,6 +1249,24 @@ static int smu_v14_0_2_emit_clk_levels(struct smu_context *smu,
1244 1249 min_value, max_value);
1245 1250 break;
1246 1251
1252 + case SMU_OD_FAN_ZERO_RPM_STOP_TEMP:
1253 + if (!smu_v14_0_2_is_od_feature_supported(smu,
1254 + PP_OD_FEATURE_ZERO_FAN_BIT))
1255 + break;
1256 +
1257 + size += sysfs_emit_at(buf, size, "FAN_ZERO_RPM_STOP_TEMPERATURE:\n");
1258 + size += sysfs_emit_at(buf, size, "%d\n",
1259 + (int)od_table->OverDriveTable.FanZeroRpmStopTemp);
1260 +
1261 + size += sysfs_emit_at(buf, size, "%s:\n", "OD_RANGE");
1262 + smu_v14_0_2_get_od_setting_limits(smu,
1263 + PP_OD_FEATURE_FAN_ZERO_RPM_STOP_TEMP,
1264 + &min_value,
1265 + &max_value);
1266 + size += sysfs_emit_at(buf, size, "ZERO_RPM_STOP_TEMPERATURE: %u %u\n",
1267 + min_value, max_value);
1268 + break;
1269 +
1247 1270 case SMU_OD_RANGE:
1248 1271 if (!smu_v14_0_2_is_od_feature_supported(smu, PP_OD_FEATURE_GFXCLK_BIT) &&
1249 1272 !smu_v14_0_2_is_od_feature_supported(smu, PP_OD_FEATURE_UCLK_BIT) &&
@@ -2311,7 +2334,9 @@ static void smu_v14_0_2_set_supported_od_feature_mask(struct smu_context *smu)
2311 2334 OD_OPS_SUPPORT_FAN_MINIMUM_PWM_RETRIEVE |
2312 2335 OD_OPS_SUPPORT_FAN_MINIMUM_PWM_SET |
2313 2336 OD_OPS_SUPPORT_FAN_ZERO_RPM_ENABLE_RETRIEVE |
2314 - OD_OPS_SUPPORT_FAN_ZERO_RPM_ENABLE_SET;
2337 + OD_OPS_SUPPORT_FAN_ZERO_RPM_ENABLE_SET |
2338 + OD_OPS_SUPPORT_FAN_ZERO_RPM_STOP_TEMP_RETRIEVE |
2339 + OD_OPS_SUPPORT_FAN_ZERO_RPM_STOP_TEMP_SET;
2315 2340 }
2316 2341
2317 2342 static int smu_v14_0_2_get_overdrive_table(struct smu_context *smu,
@@ -2392,6 +2417,8 @@ static int smu_v14_0_2_set_default_od_settings(struct smu_context *smu)
2392 2417 user_od_table_bak.OverDriveTable.FanMinimumPwm;
2393 2418 user_od_table->OverDriveTable.FanZeroRpmEnable =
2394 2419 user_od_table_bak.OverDriveTable.FanZeroRpmEnable;
2420 + user_od_table->OverDriveTable.FanZeroRpmStopTemp =
2421 + user_od_table_bak.OverDriveTable.FanZeroRpmStopTemp;
2395 2422 }
2396 2423
2397 2424 smu_v14_0_2_set_supported_od_feature_mask(smu);
@@ -2446,6 +2473,11 @@ static int smu_v14_0_2_od_restore_table_single(struct smu_context *smu, long inp
2446 2473 boot_overdrive_table->OverDriveTable.FanZeroRpmEnable;
2447 2474 od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_ZERO_FAN_BIT);
2448 2475 break;
2476 + case PP_OD_EDIT_FAN_ZERO_RPM_STOP_TEMP:
2477 + od_table->OverDriveTable.FanZeroRpmStopTemp =
2478 + boot_overdrive_table->OverDriveTable.FanZeroRpmStopTemp;
2479 + od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_ZERO_FAN_BIT);
2480 + break;
2449 2481 case PP_OD_EDIT_ACOUSTIC_LIMIT:
2450 2482 od_table->OverDriveTable.AcousticLimitRpmThreshold =
2451 2483 boot_overdrive_table->OverDriveTable.AcousticLimitRpmThreshold;
@@ -2752,6 +2784,27 @@ static int smu_v14_0_2_od_edit_dpm_table(struct smu_context *smu,
2752 2784 od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_ZERO_FAN_BIT);
2753 2785 break;
2754 2786
2787 + case PP_OD_EDIT_FAN_ZERO_RPM_STOP_TEMP:
2788 + if (!smu_v14_0_2_is_od_feature_supported(smu, PP_OD_FEATURE_ZERO_FAN_BIT)) {
2789 + dev_warn(adev->dev, "Zero RPM setting not supported!\n");
2790 + return -ENOTSUPP;
2791 + }
2792 +
2793 + smu_v14_0_2_get_od_setting_limits(smu,
2794 + PP_OD_FEATURE_FAN_ZERO_RPM_STOP_TEMP,
2795 + &minimum,
2796 + &maximum);
2797 + if (input[0] < minimum ||
2798 + input[0] > maximum) {
2799 + dev_info(adev->dev, "zero RPM stop temperature setting(%ld) must be within [%d, %d]!\n",
2800 + input[0], minimum, maximum);
2801 + return -EINVAL;
2802 + }
2803 +
2804 + od_table->OverDriveTable.FanZeroRpmStopTemp = input[0];
2805 + od_table->OverDriveTable.FeatureCtrlMask |= BIT(PP_OD_FEATURE_ZERO_FAN_BIT);
2806 + break;
2807 +
2755 2808 case PP_OD_RESTORE_DEFAULT_TABLE:
2756 2809 if (size == 1) {
2757 2810 ret = smu_v14_0_2_od_restore_table_single(smu, input[0]);
modified drivers/gpu/drm/drm_exec.c
@@ -48,6 +48,16 @@
48 48 * See struct dma_exec for more details.
49 49 */
50 50
51 + /* Unlock and put the prelocked obj */
52 + static void drm_exec_drop_prelocked(struct drm_exec *exec)
53 + {
54 + if (exec->prelocked) {
55 + dma_resv_unlock(exec->prelocked->resv);
56 + drm_gem_object_put(exec->prelocked);
57 + exec->prelocked = NULL;
58 + }
59 + }
60 +
51 61 /* Unlock all objects and drop references */
52 62 static void drm_exec_unlock_all(struct drm_exec *exec)
53 63 {
@@ -58,8 +68,7 @@ static void drm_exec_unlock_all(struct drm_exec *exec)
58 68 drm_gem_object_put(obj);
59 69 }
60 70
61 - drm_gem_object_put(exec->prelocked);
62 - exec->prelocked = NULL;
71 + drm_exec_drop_prelocked(exec);
63 72 }
64 73
65 74 /**
@@ -118,6 +127,14 @@ EXPORT_SYMBOL(drm_exec_fini);
118 127 bool drm_exec_cleanup(struct drm_exec *exec)
119 128 {
120 129 if (likely(!exec->contended)) {
130 +
131 + /*
132 + * The contended and prelocked object might never be passed to
133 + * drm_exec_lock_obj() again. This can happen when the object
134 + * is about to be cleaned up and we now hold the last reference
135 + * to it. Make sure that we don't unnecessarily keep it around.
136 + */
137 + drm_exec_drop_prelocked(exec);
121 138 ww_acquire_done(&exec->ticket);
122 139 return false;
123 140 }
@@ -175,16 +192,16 @@ static int drm_exec_lock_contended(struct drm_exec *exec)
175 192 dma_resv_lock_slow(obj->resv, &exec->ticket);
176 193 }
177 194
178 - ret = drm_exec_obj_locked(exec, obj);
179 - if (unlikely(ret))
180 - goto error_unlock;
195 + /*
196 + * It is perfectly possible that we see another contention before the
197 + * first one is fully handled.
198 + */
199 + drm_exec_drop_prelocked(exec);
181 200
201 + /* We move the reference from contended to prelocked here */
182 202 exec->prelocked = obj;
183 203 return 0;
184 204
185 - error_unlock:
186 - dma_resv_unlock(obj->resv);
187 -
188 205 error_dropref:
189 206 drm_gem_object_put(obj);
190 207 return ret;
@@ -212,35 +229,31 @@ int drm_exec_lock_obj(struct drm_exec *exec, struct drm_gem_object *obj)
212 229 if (exec->prelocked == obj) {
213 230 drm_gem_object_put(exec->prelocked);
214 231 exec->prelocked = NULL;
215 - return 0;
216 - }
232 + } else {
233 + if (exec->flags & DRM_EXEC_INTERRUPTIBLE_WAIT)
234 + ret = dma_resv_lock_interruptible(obj->resv,
235 + &exec->ticket);
236 + else
237 + ret = dma_resv_lock(obj->resv, &exec->ticket);
238 +
239 + if (unlikely(ret == -EDEADLK)) {
240 + drm_gem_object_get(obj);
241 + exec->contended = obj;
242 + return -EDEADLK;
243 + }
217 244
218 - if (exec->flags & DRM_EXEC_INTERRUPTIBLE_WAIT)
219 - ret = dma_resv_lock_interruptible(obj->resv, &exec->ticket);
220 - else
221 - ret = dma_resv_lock(obj->resv, &exec->ticket);
245 + if (unlikely(ret == -EALREADY) &&
246 + exec->flags & DRM_EXEC_IGNORE_DUPLICATES)
247 + return 0;
222 248
223 - if (unlikely(ret == -EDEADLK)) {
224 - drm_gem_object_get(obj);
225 - exec->contended = obj;
226 - return -EDEADLK;
249 + if (unlikely(ret))
250 + return ret;
227 251 }
228 252
229 - if (unlikely(ret == -EALREADY) &&
230 - exec->flags & DRM_EXEC_IGNORE_DUPLICATES)
231 - return 0;
232 -
233 - if (unlikely(ret))
234 - return ret;
235 -
236 253 ret = drm_exec_obj_locked(exec, obj);
237 254 if (ret)
238 - goto error_unlock;
239 -
240 - return 0;
255 + dma_resv_unlock(obj->resv);
241 256
242 - error_unlock:
243 - dma_resv_unlock(obj->resv);
244 257 return ret;
245 258 }
246 259 EXPORT_SYMBOL(drm_exec_lock_obj);
modified drivers/gpu/drm/i915/display/intel_cx0_phy.c
@@ -2342,12 +2342,14 @@ static void intel_c10pll_dump_hw_state(struct drm_printer *p,
2342 2342 static bool is_arrowlake_s_by_host_bridge(void)
2343 2343 {
2344 2344 struct pci_dev *pdev = NULL;
2345 - u16 host_bridge_pci_dev_id;
2346 -
2347 - while ((pdev = pci_get_class(PCI_CLASS_BRIDGE_HOST << 8, pdev)))
2348 - host_bridge_pci_dev_id = pdev->device;
2345 + while ((pdev = pci_get_class(PCI_CLASS_BRIDGE_HOST << 8, pdev))) {
2346 + if (IS_ARROWLAKE_S_BY_HOST_BRIDGE_ID(pdev->device)) {
2347 + pci_dev_put(pdev);
2348 + return true;
2349 + }
2350 + }
2349 2351
2350 - return pdev && IS_ARROWLAKE_S_BY_HOST_BRIDGE_ID(host_bridge_pci_dev_id);
2352 + return false;
2351 2353 }
2352 2354
2353 2355 static u16 intel_c20_hdmi_tmds_tx_cgf_1(struct intel_display *display)
modified drivers/gpu/drm/i915/display/intel_dmc.c
@@ -1023,6 +1023,55 @@ static void dmc_set_fw_offset(struct intel_dmc *dmc,
1023 1023 }
1024 1024 }
1025 1025
1026 + /*
1027 + * Check if the load address is within the valid range for the given DMC ID.
1028 + */
1029 + static bool dmc_load_addr_sanity_check(struct intel_dmc *dmc,
1030 + u32 start_addr, u32 payload_size,
1031 + int header_ver, enum intel_dmc_id dmc_id)
1032 + {
1033 + u32 start_range, end_range, end_addr;
1034 +
1035 + if (header_ver != 3)
1036 + return true;
1037 +
1038 + switch (dmc_id) {
1039 + case DMC_FW_MAIN:
1040 + start_range = DMC_MAIN_PROGRAM_BASE_START;
1041 + end_range = DMC_MAIN_PROGRAM_BASE_END;
1042 + break;
1043 + case DMC_FW_PIPEA:
1044 + start_range = DMC_PIPEA_PROGRAM_BASE_START;
1045 + end_range = DMC_PIPEA_PROGRAM_BASE_END;
1046 + break;
1047 + case DMC_FW_PIPEB:
1048 + start_range = DMC_PIPEB_PROGRAM_BASE_START;
1049 + end_range = DMC_PIPEB_PROGRAM_BASE_END;
1050 + break;
1051 + case DMC_FW_PIPEC:
1052 + start_range = DMC_PIPEC_PROGRAM_BASE_START;
1053 + end_range = DMC_PIPEC_PROGRAM_BASE_END;
1054 + break;
1055 + case DMC_FW_PIPED:
1056 + start_range = DMC_PIPED_PROGRAM_BASE_START;
1057 + end_range = DMC_PIPED_PROGRAM_BASE_END;
1058 + break;
1059 + default:
1060 + MISSING_CASE(dmc_id);
1061 + return false;
1062 + }
1063 +
1064 + if (payload_size == 0)
1065 + end_addr = start_addr;
1066 + else if (check_add_overflow(start_addr, payload_size - 1, &end_addr))
1067 + return false;
1068 +
1069 + if (start_addr < start_range || end_addr > end_range)
1070 + return false;
1071 +
1072 + return true;
1073 + }
1074 +
1026 1075 static bool dmc_mmio_addr_sanity_check(struct intel_dmc *dmc,
1027 1076 const u32 *mmioaddr, u32 mmio_count,
1028 1077 int header_ver, enum intel_dmc_id dmc_id)
@@ -1120,7 +1169,7 @@ static u32 parse_dmc_fw_header(struct intel_dmc *dmc,
1120 1169 }
1121 1170
1122 1171 /* Cache the dmc header info. */
1123 - if (mmio_count > mmio_count_max) {
1172 + if (!mmio_count || mmio_count > mmio_count_max) {
1124 1173 drm_err(display->drm, "DMC firmware has wrong mmio count %u\n", mmio_count);
1125 1174 return 0;
1126 1175 }
@@ -1166,13 +1215,21 @@ static u32 parse_dmc_fw_header(struct intel_dmc *dmc,
1166 1215 disable_dmc_evt(display, dmc_id, dmc_info->mmioaddr[i],
1167 1216 dmc_info->mmiodata[i]) ? " (disabling)" : "");
1168 1217 }
1169 - dmc_info->mmio_count = mmio_count;
1170 - dmc_info->start_mmioaddr = start_mmioaddr;
1171 1218
1172 1219 rem_size -= header_len_bytes;
1173 1220
1174 1221 /* fw_size is in dwords, so multiplied by 4 to convert into bytes. */
1175 - payload_size = dmc_header->fw_size * 4;
1222 + if (check_mul_overflow(dmc_header->fw_size, 4u, &payload_size)) {
1223 + drm_err(display->drm, "DMC fw_size too large (%u dwords)\n",
1224 + dmc_header->fw_size);
1225 + return 0;
1226 + }
1227 +
1228 + if (!payload_size) {
1229 + drm_err(display->drm, "DMC firmware has empty payload\n");
1230 + return 0;
1231 + }
1232 +
1176 1233 if (rem_size < payload_size)
1177 1234 goto error_truncated;
1178 1235
@@ -1180,12 +1237,21 @@ static u32 parse_dmc_fw_header(struct intel_dmc *dmc,
1180 1237 drm_err(display->drm, "DMC FW too big (%u bytes)\n", payload_size);
1181 1238 return 0;
1182 1239 }
1183 - dmc_info->dmc_fw_size = dmc_header->fw_size;
1240 +
1241 + if (!dmc_load_addr_sanity_check(dmc, start_mmioaddr, payload_size,
1242 + dmc_header->header_ver, dmc_id)) {
1243 + drm_err(display->drm, "DMC %d: firmware has wrong load address\n", dmc_id);
1244 + return 0;
1245 + }
1184 1246
1185 1247 dmc_info->payload = kmalloc(payload_size, GFP_KERNEL);
1186 1248 if (!dmc_info->payload)
1187 1249 return 0;
1188 1250
1251 + dmc_info->mmio_count = mmio_count;
1252 + dmc_info->start_mmioaddr = start_mmioaddr;
1253 + dmc_info->dmc_fw_size = dmc_header->fw_size;
1254 +
1189 1255 payload = (u8 *)(dmc_header) + header_len_bytes;
1190 1256 memcpy(dmc_info->payload, payload, payload_size);
1191 1257
modified drivers/gpu/drm/i915/display/intel_dmc_regs.h
@@ -521,6 +521,18 @@ enum pipedmc_event_id {
521 521 #define TGL_PIPE_MMIO_END(dmc_id) _PICK_EVEN(((dmc_id) - 1), _TGL_PIPEA_MMIO_END,\
522 522 _TGL_PIPEB_MMIO_END)
523 523
524 + /* For DMC header version v3*/
525 + #define DMC_MAIN_PROGRAM_BASE_START 0x80000
526 + #define DMC_MAIN_PROGRAM_BASE_END 0x86fff
527 + #define DMC_PIPEA_PROGRAM_BASE_START 0x90000
528 + #define DMC_PIPEA_PROGRAM_BASE_END 0x96fff
529 + #define DMC_PIPEB_PROGRAM_BASE_START 0x98000
530 + #define DMC_PIPEB_PROGRAM_BASE_END 0x9efff
531 + #define DMC_PIPEC_PROGRAM_BASE_START 0x52000
532 + #define DMC_PIPEC_PROGRAM_BASE_END 0x53fff
533 + #define DMC_PIPED_PROGRAM_BASE_START 0x59000
534 + #define DMC_PIPED_PROGRAM_BASE_END 0x5afff
535 +
524 536 #define SKL_DMC_DC3_DC5_COUNT _MMIO(0x80030)
525 537 #define SKL_DMC_DC5_DC6_COUNT _MMIO(0x8002C)
526 538 #define BXT_DMC_DC3_DC5_COUNT _MMIO(0x80038)
modified drivers/gpu/drm/panthor/panthor_hw.c
@@ -136,7 +136,7 @@ static char *get_gpu_model_name(struct panthor_device *ptdev)
136 136 case GPU_PROD_ID_MAKE(10, 7):
137 137 return "Mali-G610";
138 138 case GPU_PROD_ID_MAKE(11, 2):
139 - if (shader_core_count > 10 && ray_intersection)
139 + if (shader_core_count >= 10 && ray_intersection)
140 140 return "Mali-G715-Immortalis";
141 141 else if (shader_core_count >= 7)
142 142 return "Mali-G715";
modified drivers/gpu/drm/vc4/vc4_hdmi.c
@@ -894,7 +894,7 @@ static void vc4_hdmi_encoder_post_crtc_disable(struct drm_encoder *encoder,
894 894
895 895 spin_lock_irqsave(&vc4_hdmi->hw_lock, flags);
896 896
897 - HDMI_WRITE(HDMI_RAM_PACKET_CONFIG, 0);
897 + HDMI_WRITE(HDMI_RAM_PACKET_CONFIG, VC4_HDMI_RAM_PACKET_ENABLE);
898 898
899 899 HDMI_WRITE(HDMI_VID_CTL, HDMI_READ(HDMI_VID_CTL) | VC4_HD_VID_CTL_CLRRGB);
900 900
@@ -1663,9 +1663,6 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder,
1663 1663 WARN_ONCE(ret, "Timeout waiting for "
1664 1664 "VC4_HDMI_SCHEDULER_CONTROL_HDMI_ACTIVE\n");
1665 1665 } else {
1666 - HDMI_WRITE(HDMI_RAM_PACKET_CONFIG,
1667 - HDMI_READ(HDMI_RAM_PACKET_CONFIG) &
1668 - ~(VC4_HDMI_RAM_PACKET_ENABLE));
1669 1666 HDMI_WRITE(HDMI_SCHEDULER_CONTROL,
1670 1667 HDMI_READ(HDMI_SCHEDULER_CONTROL) &
1671 1668 ~VC4_HDMI_SCHEDULER_CONTROL_MODE_HDMI);
@@ -1684,9 +1681,6 @@ static void vc4_hdmi_encoder_post_crtc_enable(struct drm_encoder *encoder,
1684 1681 WARN_ON(!(HDMI_READ(HDMI_SCHEDULER_CONTROL) &
1685 1682 VC4_HDMI_SCHEDULER_CONTROL_HDMI_ACTIVE));
1686 1683
1687 - HDMI_WRITE(HDMI_RAM_PACKET_CONFIG,
1688 - VC4_HDMI_RAM_PACKET_ENABLE);
1689 -
1690 1684 spin_unlock_irqrestore(&vc4_hdmi->hw_lock, flags);
1691 1685 vc4_hdmi->packet_ram_enabled = true;
1692 1686
@@ -3143,6 +3137,11 @@ static int vc5_hdmi_init_resources(struct drm_device *drm,
3143 3137 static int vc4_hdmi_runtime_suspend(struct device *dev)
3144 3138 {
3145 3139 struct vc4_hdmi *vc4_hdmi = dev_get_drvdata(dev);
3140 + unsigned long flags;
3141 +
3142 + spin_lock_irqsave(&vc4_hdmi->hw_lock, flags);
3143 + HDMI_WRITE(HDMI_RAM_PACKET_CONFIG, 0);
3144 + spin_unlock_irqrestore(&vc4_hdmi->hw_lock, flags);
3146 3145
3147 3146 clk_disable_unprepare(vc4_hdmi->audio_clock);
3148 3147 clk_disable_unprepare(vc4_hdmi->hsm_clock);
@@ -3153,9 +3152,8 @@ static int vc4_hdmi_runtime_suspend(struct device *dev)
3153 3152 static int vc4_hdmi_runtime_resume(struct device *dev)
3154 3153 {
3155 3154 struct vc4_hdmi *vc4_hdmi = dev_get_drvdata(dev);
3156 - unsigned long __maybe_unused flags;
3155 + unsigned long rate, flags;
3157 3156 u32 __maybe_unused value;
3158 - unsigned long rate;
3159 3157 int ret;
3160 3158
3161 3159 ret = clk_prepare_enable(vc4_hdmi->hsm_clock);
@@ -3201,6 +3199,10 @@ static int vc4_hdmi_runtime_resume(struct device *dev)
3201 3199 }
3202 3200 #endif
3203 3201
3202 + spin_lock_irqsave(&vc4_hdmi->hw_lock, flags);
3203 + HDMI_WRITE(HDMI_RAM_PACKET_CONFIG, VC4_HDMI_RAM_PACKET_ENABLE);
3204 + spin_unlock_irqrestore(&vc4_hdmi->hw_lock, flags);
3205 +
3204 3206 return 0;
3205 3207
3206 3208 err_disable_clk:
modified drivers/gpu/drm/virtio/virtgpu_drv.c
@@ -225,6 +225,7 @@ static int virtgpu_freeze(struct virtio_device *vdev)
225 225 goto err_resume;
226 226 }
227 227
228 + virtio_reset_device(vdev);
228 229 vdev->config->del_vqs(vdev);
229 230
230 231 return 0;
modified drivers/gpu/drm/virtio/virtgpu_plane.c
@@ -589,7 +589,6 @@ struct drm_plane *virtio_gpu_plane_init(struct virtio_gpu_device *vgdev,
589 589 struct drm_plane *plane;
590 590 const uint32_t *formats;
591 591 int nformats;
592 - int ret;
593 592
594 593 if (type == DRM_PLANE_TYPE_CURSOR) {
595 594 formats = virtio_gpu_cursor_formats;
@@ -615,17 +614,5 @@ struct drm_plane *virtio_gpu_plane_init(struct virtio_gpu_device *vgdev,
615 614 drm_plane_create_blend_mode_property(plane,
616 615 BIT(DRM_MODE_BLEND_PREMULTI));
617 616
618 - if (type == DRM_PLANE_TYPE_CURSOR) {
619 - /*
620 - * The cursor plane exposes a format with an alpha channel,
621 - * which requires a blend mode property. The host blends
622 - * premultiplied alpha, matching the property's default.
623 - */
624 - ret = drm_plane_create_blend_mode_property(plane,
625 - BIT(DRM_MODE_BLEND_PREMULTI));
626 - if (ret)
627 - return ERR_PTR(ret);
628 - }
629 -
630 617 return plane;
631 618 }
modified drivers/gpu/drm/xe/xe_bo.c
@@ -330,6 +330,12 @@ static void xe_evict_flags(struct ttm_buffer_object *tbo,
330 330 return;
331 331 }
332 332
333 + /* No resource: nothing is placed/mapped, so there is nothing to evict. */
334 + if (!tbo->resource) {
335 + placement->num_placement = 0;
336 + return;
337 + }
338 +
333 339 bo = ttm_to_xe_bo(tbo);
334 340 if (bo->flags & XE_BO_FLAG_CPU_ADDR_MIRROR) {
335 341 *placement = sys_placement;
@@ -944,6 +950,8 @@ static int xe_bo_move_notify(struct xe_bo *bo,
944 950 *
945 951 * Transfers pages between shrinkable and purgeable buckets when the BO
946 952 * purgeable state changes. Called automatically from xe_bo_set_purgeable_state().
953 + * For pinned BOs, whose pages are not accounted, only the purgeable flag is
954 + * updated, so that the correct bucket is used when the BO is unpinned.
947 955 */
948 956 static void xe_bo_set_purgeable_shrinker(struct xe_bo *bo,
949 957 enum xe_madv_purgeable_state new_state)
@@ -960,7 +968,8 @@ static void xe_bo_set_purgeable_shrinker(struct xe_bo *bo,
960 968 return;
961 969
962 970 xe_tt = container_of(tt, struct xe_ttm_tt, ttm);
963 - tt_pages = tt->num_pages;
971 + /* Pinned bos are not accounted. Only update the purgeable flag. */
972 + tt_pages = xe_bo_is_pinned(bo) ? 0 : tt->num_pages;
964 973
965 974 if (!xe_tt->purgeable && new_state == XE_MADV_PURGEABLE_DONTNEED) {
966 975 xe_tt->purgeable = true;
modified drivers/gpu/drm/xe/xe_exec.c
@@ -346,11 +346,8 @@ retry:
346 346 xe_sched_job_push(job);
347 347 xe_vm_reactivate_rebind(vm);
348 348
349 - if (!err && !xe_vm_in_lr_mode(vm)) {
350 - spin_lock(&xe->ttm.lru_lock);
351 - ttm_lru_bulk_move_tail(&vm->lru_bulk_move);
352 - spin_unlock(&xe->ttm.lru_lock);
353 - }
349 + if (!err && !xe_vm_in_lr_mode(vm))
350 + xe_vm_bump_lru(vm, exec);
354 351
355 352 if (mode == EXEC_MODE_LR)
356 353 xe_hw_engine_group_resume_faulting_lr_jobs(group);
modified drivers/gpu/drm/xe/xe_oa.c
@@ -914,6 +914,13 @@ static int xe_oa_alloc_oa_buffer(struct xe_oa_stream *stream, size_t size)
914 914 if (IS_ERR(bo))
915 915 return PTR_ERR(bo);
916 916
917 + /*
918 + * ttm_bo_type_kernel BOs are not zeroed on allocation, so the buffer can
919 + * hold stale data from previously freed pages. Since the OA buffer is
920 + * mmap'able by userspace, clear it here to avoid leaking kernel memory.
921 + */
922 + xe_map_memset(stream->oa->xe, &bo->vmap, 0, 0, xe_bo_size(bo));
923 +
917 924 stream->oa_buffer.bo = bo;
918 925
919 926 stream->oa_buffer.bounce = kmalloc(stream->oa_buffer.format->size, GFP_KERNEL);
modified drivers/gpu/drm/xe/xe_vm.c
@@ -410,6 +410,33 @@ int xe_vm_validate_rebind(struct xe_vm *vm, struct drm_exec *exec,
410 410 return 0;
411 411 }
412 412
413 + /**
414 + * xe_vm_bump_lru() - Bump the LRU position of BOs used by a submission
415 + * @vm: The vm for which we are bumping LRUs.
416 + * @exec: The struct drm_exec with the locked GEM objects.
417 + *
418 + * Move the VM's private BOs, and all external objects locked by @exec,
419 + * to the LRU tail. Private BOs are moved in bulk using @vm's
420 + * &xe_vm.lru_bulk_move. External objects, which may be shared with other
421 + * VMs, are not part of that bulk move and are bumped individually.
422 + */
423 + void xe_vm_bump_lru(struct xe_vm *vm, struct drm_exec *exec)
424 + {
425 + spinlock_t *lru_lock = &vm->xe->ttm.lru_lock;
426 + struct drm_gem_object *obj;
427 +
428 + spin_lock(lru_lock);
429 + ttm_lru_bulk_move_tail(&vm->lru_bulk_move);
430 + drm_exec_for_each_locked_object(exec, obj) {
431 + if (!drm_gpuvm_is_extobj(&vm->gpuvm, obj))
432 + continue;
433 +
434 + ttm_bo_move_to_lru_tail(&gem_to_xe_bo(obj)->ttm);
435 + cond_resched_lock(lru_lock);
436 + }
437 + spin_unlock(lru_lock);
438 + }
439 +
413 440 static int xe_preempt_work_begin(struct drm_exec *exec, struct xe_vm *vm,
414 441 bool *done)
415 442 {
@@ -560,9 +587,7 @@ retry:
560 587
561 588 #undef retry_required
562 589
563 - spin_lock(&vm->xe->ttm.lru_lock);
564 - ttm_lru_bulk_move_tail(&vm->lru_bulk_move);
565 - spin_unlock(&vm->xe->ttm.lru_lock);
590 + xe_vm_bump_lru(vm, &exec);
566 591
567 592 /* Point of no return. */
568 593 arm_preempt_fences(vm, &preempt_fences);
modified drivers/gpu/drm/xe/xe_vm.h
@@ -284,6 +284,8 @@ int xe_vm_lock_vma(struct drm_exec *exec, struct xe_vma *vma);
284 284 int xe_vm_validate_rebind(struct xe_vm *vm, struct drm_exec *exec,
285 285 unsigned int num_fences);
286 286
287 + void xe_vm_bump_lru(struct xe_vm *vm, struct drm_exec *exec);
288 +
287 289 struct dma_fence *xe_vm_bind_kernel_bo(struct xe_vm *vm, struct xe_bo *bo,
288 290 struct xe_exec_queue *q, u64 addr,
289 291 enum xe_cache_level cache_lvl);
modified drivers/hv/channel.c
@@ -79,7 +79,7 @@ static inline u32 hv_ring_gpadl_send_hvpgoffset(u32 offset)
79 79 * therefore leaving a (PAGE_SIZE - HV_HYP_PAGE_SIZE) gap.
80 80 *
81 81 * And to calculate the effective send offset in gpadl, we need to
82 - * substract this gap.
82 + * subtract this gap.
83 83 */
84 84 return (offset - (PAGE_SIZE - HV_HYP_PAGE_SIZE)) >> HV_HYP_PAGE_SHIFT;
85 85 }
modified drivers/hv/channel_mgmt.c
@@ -752,13 +752,14 @@ static void init_vp_index(struct vmbus_channel *channel)
752 752 u32 i, ncpu = num_online_cpus();
753 753 cpumask_var_t available_mask;
754 754 struct cpumask *allocated_mask;
755 + const struct cpumask *node_mask;
755 756 const struct cpumask *hk_mask = housekeeping_cpumask(HK_TYPE_MANAGED_IRQ);
756 757 u32 target_cpu;
757 758 int numa_node;
758 759
759 760 if (!perf_chn ||
760 761 !alloc_cpumask_var(&available_mask, GFP_KERNEL) ||
761 - cpumask_empty(hk_mask)) {
762 + !cpumask_intersects(hk_mask, cpu_online_mask)) {
762 763 /*
763 764 * If the channel is not a performance critical
764 765 * channel, bind it to VMBUS_CONNECT_CPU.
@@ -780,14 +781,19 @@ static void init_vp_index(struct vmbus_channel *channel)
780 781 next_numa_node_id = 0;
781 782 continue;
782 783 }
783 - if (cpumask_empty(cpumask_of_node(numa_node)))
784 + /*
785 + * Try next NUMA node if current NUMA node has no CPU
786 + * or doesn't contain any housekeeping CPU.
787 + */
788 + node_mask = cpumask_of_node(numa_node);
789 + if (!cpumask_intersects(node_mask, hk_mask))
784 790 continue;
785 791 break;
786 792 }
787 793 allocated_mask = &hv_context.hv_numa_map[numa_node];
788 794
789 795 retry:
790 - cpumask_xor(available_mask, allocated_mask, cpumask_of_node(numa_node));
796 + cpumask_xor(available_mask, allocated_mask, node_mask);
791 797 cpumask_and(available_mask, available_mask, hk_mask);
792 798
793 799 if (cpumask_empty(available_mask)) {
modified drivers/hv/connection.c
@@ -346,7 +346,6 @@ int vmbus_connect(void)
346 346 cleanup:
347 347 pr_err("Unable to connect to host\n");
348 348
349 - vmbus_connection.conn_state = DISCONNECTED;
350 349 vmbus_disconnect();
351 350
352 351 kfree(msginfo);
modified drivers/hv/mshv_vtl_main.c
@@ -819,6 +819,9 @@ static vm_fault_t mshv_vtl_fault(struct vm_fault *vmf)
819 819 return VM_FAULT_NOPAGE;
820 820 }
821 821
822 + if (!page)
823 + return VM_FAULT_SIGBUS;
824 +
822 825 get_page(page);
823 826 vmf->page = page;
824 827
modified drivers/hv/vmbus_drv.c
@@ -2923,23 +2923,19 @@ static void hv_crash_handler(struct pt_regs *regs)
2923 2923 static int hv_synic_suspend(void *data)
2924 2924 {
2925 2925 /*
2926 - * When we reach here, all the non-boot CPUs have been offlined.
2927 - * If we're in a legacy configuration where stimer Direct Mode is
2928 - * not enabled, the stimers on the non-boot CPUs have been unbound
2929 - * in hv_synic_cleanup() -> hv_stimer_legacy_cleanup() ->
2930 - * hv_stimer_cleanup() -> clockevents_unbind_device().
2926 + * When we reach here, all the non-boot CPUs have been offlined,
2927 + * and their stimers have been cleaned up by the cpuhp teardown
2928 + * callback hv_stimer_cleanup().
2931 2929 *
2932 2930 * hv_synic_suspend() only runs on CPU0 with interrupts disabled.
2933 - * Here we do not call hv_stimer_legacy_cleanup() on CPU0 because:
2934 - * 1) it's unnecessary as interrupts remain disabled between
2935 - * syscore_suspend() and syscore_resume(): see create_image() and
2931 + * The stimer on CPU0 is not explicitly cleaned up here because:
2932 + * 1) it's harmless as interrupts remain disabled between
2933 + * syscore_suspend() and syscore_resume(), so the stimer cannot
2934 + * fire during this window: see create_image() and
2936 2935 * resume_target_kernel()
2937 2936 * 2) the stimer on CPU0 is automatically disabled later by
2938 2937 * syscore_suspend() -> timekeeping_suspend() -> tick_suspend() -> ...
2939 2938 * -> clockevents_shutdown() -> ... -> hv_ce_shutdown()
2940 - * 3) a warning would be triggered if we call
2941 - * clockevents_unbind_device(), which may sleep, in an
2942 - * interrupts-disabled context.
2943 2939 */
2944 2940
2945 2941 hv_hyp_synic_disable_regs(0);
@@ -3043,7 +3039,6 @@ static void __exit vmbus_exit(void)
3043 3039
3044 3040 hv_remove_kexec_handler();
3045 3041 hv_remove_crash_handler();
3046 - vmbus_connection.conn_state = DISCONNECTED;
3047 3042 hv_stimer_global_cleanup();
3048 3043 vmbus_disconnect();
3049 3044 if (vmbus_irq == -1)
modified drivers/iommu/amd/amd_iommu_types.h
@@ -421,6 +421,9 @@ struct irq_remap_table {
421 421 u32 *table;
422 422 };
423 423
424 + /* Interrupt remapping feature used? */
425 + extern bool amd_iommu_irq_remap;
426 +
424 427 extern const struct iommu_ops amd_iommu_ops;
425 428
426 429 /* IVRS indicates that pre-boot remapping was enabled */
modified drivers/iommu/amd/init.c
@@ -152,7 +152,7 @@ struct ivmd_header {
152 152 } __attribute__((packed));
153 153
154 154 bool amd_iommu_dump;
155 - static bool amd_iommu_irq_remap __read_mostly;
155 + bool amd_iommu_irq_remap __read_mostly;
156 156
157 157 enum protection_domain_mode amd_iommu_pgtable = PD_MODE_V1;
158 158 /* Virtual address size */
modified drivers/iommu/amd/iommu.c
@@ -3973,6 +3973,9 @@ static int irq_remapping_select(struct irq_domain *d, struct irq_fwspec *fwspec,
3973 3973 struct amd_iommu *iommu;
3974 3974 int devid = -1;
3975 3975
3976 + if (!amd_iommu_irq_remap)
3977 + return 0;
3978 +
3976 3979 if (x86_fwspec_is_ioapic(fwspec))
3977 3980 devid = get_ioapic_devid(fwspec->param[0]);
3978 3981 else if (x86_fwspec_is_hpet(fwspec))
modified drivers/iommu/generic_pt/fmt/Makefile
@@ -25,6 +25,6 @@ $(eval $(foreach fmt,$(iommu_pt_fmt-m),$(call create_format,$(fmt),m)))
25 25 # with -DGENERIC_PT_KUNIT
26 26 $(obj)/kunit_iommu_%.o: $(src)/iommu_%.c FORCE
27 27 $(call rule_mkdir)
28 - $(call if_changed_dep,cc_o_c)
28 + $(call if_changed_rule,cc_o_c)
29 29
30 30 obj-$(CONFIG_IOMMU_PT_KUNIT_TEST) += $(IOMMU_PT_KUNIT_TEST)
modified drivers/net/ethernet/actions/owl-emac.c
@@ -1552,6 +1552,8 @@ static int owl_emac_probe(struct platform_device *pdev)
1552 1552 return ret;
1553 1553 }
1554 1554
1555 + netdev->netdev_ops = &owl_emac_netdev_ops;
1556 +
1555 1557 ret = owl_emac_phy_init(netdev);
1556 1558 if (ret) {
1557 1559 dev_err(dev, "failed to initialize PHY\n");
@@ -1563,7 +1565,6 @@ static int owl_emac_probe(struct platform_device *pdev)
1563 1565 netdev->min_mtu = OWL_EMAC_MTU_MIN;
1564 1566 netdev->max_mtu = OWL_EMAC_MTU_MAX;
1565 1567 netdev->watchdog_timeo = OWL_EMAC_TX_TIMEOUT;
1566 - netdev->netdev_ops = &owl_emac_netdev_ops;
1567 1568 netdev->ethtool_ops = &owl_emac_ethtool_ops;
1568 1569 netif_napi_add(netdev, &priv->napi, owl_emac_poll);
1569 1570
modified drivers/net/ethernet/adi/adin1140.c
@@ -733,6 +733,8 @@ static int adin1140_probe(struct spi_device *spi)
733 733 if (ret)
734 734 return ret;
735 735
736 + netdev->netdev_ops = &adin1140_netdev_ops;
737 +
736 738 ret = adin1140_phy_init(priv, spi);
737 739 if (ret)
738 740 return ret;
@@ -748,7 +750,6 @@ static int adin1140_probe(struct spi_device *spi)
748 750
749 751 netdev->if_port = IF_PORT_10BASET;
750 752 netdev->irq = spi->irq;
751 - netdev->netdev_ops = &adin1140_netdev_ops;
752 753 netdev->ethtool_ops = &adin1140_ethtool_ops;
753 754 netdev->netns_immutable = true;
754 755 netdev->priv_flags |= IFF_LIVE_ADDR_CHANGE |
modified drivers/net/ethernet/aeroflex/greth.c
@@ -1421,6 +1421,8 @@ static int greth_of_probe(struct platform_device *ofdev)
1421 1421 /* Check if MAC can handle MDIO interrupts */
1422 1422 greth->mdio_int_en = (tmp >> 26) & 1;
1423 1423
1424 + dev->netdev_ops = &greth_netdev_ops;
1425 +
1424 1426 err = greth_mdio_init(greth);
1425 1427 if (err) {
1426 1428 if (netif_msg_probe(greth))
@@ -1498,7 +1500,6 @@ static int greth_of_probe(struct platform_device *ofdev)
1498 1500 dev->flags &= ~IFF_MULTICAST;
1499 1501 }
1500 1502
1501 - dev->netdev_ops = &greth_netdev_ops;
1502 1503 dev->ethtool_ops = &greth_ethtool_ops;
1503 1504
1504 1505 err = register_netdev(dev);
modified drivers/net/ethernet/amd/au1000_eth.c
@@ -1225,6 +1225,8 @@ static int au1000_probe(struct platform_device *pdev)
1225 1225 goto err_mdiobus_reg;
1226 1226 }
1227 1227
1228 + dev->netdev_ops = &au1000_netdev_ops;
1229 +
1228 1230 err = au1000_mii_probe(dev);
1229 1231 if (err != 0)
1230 1232 goto err_out;
@@ -1263,7 +1265,6 @@ static int au1000_probe(struct platform_device *pdev)
1263 1265
1264 1266 dev->base_addr = base->start;
1265 1267 dev->irq = irq;
1266 - dev->netdev_ops = &au1000_netdev_ops;
1267 1268 dev->ethtool_ops = &au1000_ethtool_ops;
1268 1269 dev->watchdog_timeo = ETH_TX_TIMEOUT;
1269 1270
modified drivers/net/ethernet/broadcom/genet/bcmgenet.c
@@ -2153,6 +2153,16 @@ static netdev_tx_t bcmgenet_xmit(struct sk_buff *skb, struct net_device *dev)
2153 2153 goto out;
2154 2154 }
2155 2155
2156 + /* We store Tx state in the control block, so the skb must not be
2157 + * shared, but ether_setup() leaves IFF_TX_SKB_SHARING set.
2158 + */
2159 + skb = skb_share_check(skb, GFP_ATOMIC);
2160 + if (!skb) {
2161 + BCMGENET_STATS64_INC((&ring->stats64), dropped);
2162 + ret = NETDEV_TX_OK;
2163 + goto out;
2164 + }
2165 +
2156 2166 /* Retain how many bytes will be sent on the wire, without TSB inserted
2157 2167 * by transmit checksum offload
2158 2168 */
modified drivers/net/ethernet/ethoc.c
@@ -1211,6 +1211,8 @@ static int ethoc_probe(struct platform_device *pdev)
1211 1211 goto free3;
1212 1212 }
1213 1213
1214 + netdev->netdev_ops = &ethoc_netdev_ops;
1215 +
1214 1216 ret = ethoc_mdio_probe(netdev);
1215 1217 if (ret) {
1216 1218 dev_err(&netdev->dev, "failed to probe MDIO bus\n");
@@ -1218,7 +1220,6 @@ static int ethoc_probe(struct platform_device *pdev)
1218 1220 }
1219 1221
1220 1222 /* setup the net_device structure */
1221 - netdev->netdev_ops = &ethoc_netdev_ops;
1222 1223 netdev->watchdog_timeo = ETHOC_TIMEOUT;
1223 1224 netdev->features |= 0;
1224 1225 netdev->ethtool_ops = &ethoc_ethtool_ops;
modified drivers/net/ethernet/hisilicon/hip04_eth.c
@@ -976,6 +976,8 @@ static int hip04_mac_probe(struct platform_device *pdev)
976 976 goto init_fail;
977 977 }
978 978
979 + ndev->netdev_ops = &hip04_netdev_ops;
980 +
979 981 priv->phy_node = of_parse_phandle(node, "phy-handle", 0);
980 982 if (priv->phy_node) {
981 983 priv->phy = of_phy_connect(ndev, priv->phy_node,
@@ -989,7 +991,6 @@ static int hip04_mac_probe(struct platform_device *pdev)
989 991
990 992 INIT_WORK(&priv->tx_timeout_task, hip04_tx_timeout_task);
991 993
992 - ndev->netdev_ops = &hip04_netdev_ops;
993 994 ndev->ethtool_ops = &hip04_ethtool_ops;
994 995 ndev->watchdog_timeo = TX_TIMEOUT;
995 996 ndev->priv_flags |= IFF_UNICAST_FLT;
modified drivers/net/ethernet/hisilicon/hisi_femac.c
@@ -830,6 +830,8 @@ static int hisi_femac_drv_probe(struct platform_device *pdev)
830 830 hisi_femac_phy_reset(priv);
831 831 }
832 832
833 + ndev->netdev_ops = &hisi_femac_netdev_ops;
834 +
833 835 phy = of_phy_get_and_connect(ndev, node, hisi_femac_adjust_link);
834 836 if (!phy) {
835 837 dev_err(dev, "connect to PHY failed!\n");
@@ -850,7 +852,6 @@ static int hisi_femac_drv_probe(struct platform_device *pdev)
850 852
851 853 ndev->watchdog_timeo = 6 * HZ;
852 854 ndev->priv_flags |= IFF_UNICAST_FLT;
853 - ndev->netdev_ops = &hisi_femac_netdev_ops;
854 855 ndev->ethtool_ops = &hisi_femac_ethtools_ops;
855 856 netif_napi_add_weight(ndev, &priv->napi, hisi_femac_poll,
856 857 FEMAC_POLL_WEIGHT);
modified drivers/net/ethernet/marvell/mv643xx_eth.c
@@ -3171,6 +3171,8 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
3171 3171 netif_set_real_num_tx_queues(dev, mp->txq_count);
3172 3172 netif_set_real_num_rx_queues(dev, mp->rxq_count);
3173 3173
3174 + dev->netdev_ops = &mv643xx_eth_netdev_ops;
3175 +
3174 3176 err = 0;
3175 3177 if (pd->phy_node) {
3176 3178 phydev = of_phy_connect(mp->dev, pd->phy_node,
@@ -3221,8 +3223,6 @@ static int mv643xx_eth_probe(struct platform_device *pdev)
3221 3223 }
3222 3224 dev->irq = irq;
3223 3225
3224 - dev->netdev_ops = &mv643xx_eth_netdev_ops;
3225 -
3226 3226 dev->watchdog_timeo = 2 * HZ;
3227 3227 dev->base_addr = 0;
3228 3228
modified drivers/net/ethernet/mellanox/mlx5/core/steering/hws/fs_hws.c
@@ -928,6 +928,7 @@ static int mlx5_fs_fte_get_hws_actions(struct mlx5_flow_root_namespace *ns,
928 928 goto free_actions;
929 929 }
930 930 (*ractions)[num_actions].aso_meter.offset =
931 + (fte_action->exe_aso.object_id - fte_action->exe_aso.base_id) * 2 +
931 932 fte_action->exe_aso.flow_meter.meter_idx;
932 933 (*ractions)[num_actions].aso_meter.init_color =
933 934 fte_action->exe_aso.flow_meter.init_color;
@@ -1398,8 +1399,8 @@ static void mlx5_cmd_hws_packet_reformat_dealloc(struct mlx5_flow_root_namespace
1398 1399 pr_data->data_size);
1399 1400 break;
1400 1401 case MLX5_REFORMAT_TYPE_L2_TO_L3_TUNNEL:
1401 - pr_pool = mlx5_fs_get_pr_encap_pool(dev, &hws_pool->el2tol2tnl_pools,
1402 - MLX5HWS_ACTION_TYP_REFORMAT_L2_TO_TNL_L2,
1402 + pr_pool = mlx5_fs_get_pr_encap_pool(dev, &hws_pool->el2tol3tnl_pools,
1403 + MLX5HWS_ACTION_TYP_REFORMAT_L2_TO_TNL_L3,
1403 1404 pr_data->data_size);
1404 1405 break;
1405 1406 case MLX5_REFORMAT_TYPE_L3_TUNNEL_TO_L2:
modified drivers/net/ethernet/microchip/lan865x/lan865x.c
@@ -346,6 +346,8 @@ static int lan865x_probe(struct spi_device *spi)
346 346 spi_set_drvdata(spi, priv);
347 347 INIT_WORK(&priv->multicast_work, lan865x_multicast_work_handler);
348 348
349 + netdev->netdev_ops = &lan865x_netdev_ops;
350 +
349 351 priv->tc6 = oa_tc6_init(spi, netdev, NULL);
350 352 if (!priv->tc6) {
351 353 ret = -ENODEV;
@@ -397,7 +399,6 @@ static int lan865x_probe(struct spi_device *spi)
397 399
398 400 netdev->if_port = IF_PORT_10BASET;
399 401 netdev->irq = spi->irq;
400 - netdev->netdev_ops = &lan865x_netdev_ops;
401 402 netdev->ethtool_ops = &lan865x_ethtool_ops;
402 403
403 404 ret = register_netdev(netdev);
modified drivers/net/ethernet/stmicro/stmmac/dwmac1000_core.c
@@ -312,6 +312,12 @@ static int dwmac1000_irq_status(struct stmmac_priv *priv,
312 312 if (intr_status & (PCS_ANE_IRQ | PCS_LINK_IRQ))
313 313 stmmac_integrated_pcs_irq(priv, intr_status, x);
314 314
315 + /* Reading RGSMIIIS clears the interrupt the MAC reset unmasks. */
316 + if (intr_status & PCS_RGSMIIIS_IRQ) {
317 + readl(ioaddr + GMAC_RGSMIIIS);
318 + x->irq_rgmii_n++;
319 + }
320 +
315 321 return ret;
316 322 }
317 323
modified drivers/net/ethernet/ti/icssm/icssm_prueth.c
@@ -1563,6 +1563,8 @@ static int icssm_prueth_netdev_init(struct prueth *prueth,
1563 1563 }
1564 1564 ether_addr_copy(emac->mac_addr, ndev->dev_addr);
1565 1565
1566 + ndev->netdev_ops = &emac_netdev_ops;
1567 +
1566 1568 /* connect PHY */
1567 1569 emac->phydev = of_phy_get_and_connect(ndev, eth_node,
1568 1570 icssm_emac_adjust_link);
@@ -1590,7 +1592,6 @@ static int icssm_prueth_netdev_init(struct prueth *prueth,
1590 1592 }
1591 1593
1592 1594 ndev->dev.of_node = eth_node;
1593 - ndev->netdev_ops = &emac_netdev_ops;
1594 1595
1595 1596 netif_napi_add(ndev, &emac->napi, icssm_emac_napi_poll);
1596 1597
modified drivers/net/wireless/ath/ath9k/wmi.c
@@ -206,16 +206,9 @@ static void ath9k_wmi_rsp_callback(struct wmi *wmi, struct sk_buff *skb)
206 206 {
207 207 skb_pull(skb, sizeof(struct wmi_cmd_hdr));
208 208
209 - if (wmi->cmd_rsp_buf && wmi->cmd_rsp_len) {
210 - if (skb->len < wmi->cmd_rsp_len) {
211 - wmi->cmd_rsp_status = -EMSGSIZE;
212 - goto complete;
213 - }
209 + if (wmi->cmd_rsp_buf != NULL && wmi->cmd_rsp_len != 0)
214 210 memcpy(wmi->cmd_rsp_buf, skb->data, wmi->cmd_rsp_len);
215 - }
216 - wmi->cmd_rsp_status = 0;
217 211
218 - complete:
219 212 complete(&wmi->cmd_wait);
220 213 }
221 214
@@ -307,7 +300,6 @@ static int ath9k_wmi_cmd_issue(struct wmi *wmi,
307 300 /* record the rsp buffer and length */
308 301 wmi->cmd_rsp_buf = rsp_buf;
309 302 wmi->cmd_rsp_len = rsp_len;
310 - wmi->cmd_rsp_status = 0;
311 303
312 304 wmi->last_seq_id = wmi->tx_seq_id;
313 305 spin_unlock_irqrestore(&wmi->wmi_lock, flags);
@@ -364,13 +356,9 @@ int ath9k_wmi_cmd(struct wmi *wmi, enum wmi_cmd_id cmd_id,
364 356 return -ETIMEDOUT;
365 357 }
366 358
367 - spin_lock_irqsave(&wmi->wmi_lock, flags);
368 - ret = wmi->cmd_rsp_status;
369 - spin_unlock_irqrestore(&wmi->wmi_lock, flags);
370 -
371 359 mutex_unlock(&wmi->op_mutex);
372 360
373 - return ret;
361 + return 0;
374 362
375 363 out:
376 364 ath_dbg(common, WMI, "WMI failure for: %s\n", wmi_cmd_to_name(cmd_id));
modified drivers/net/wireless/ath/ath9k/wmi.h
@@ -157,7 +157,6 @@ struct wmi {
157 157 u16 tx_seq_id;
158 158 u8 *cmd_rsp_buf;
159 159 u32 cmd_rsp_len;
160 - int cmd_rsp_status;
161 160 bool stopped;
162 161
163 162 struct list_head pending_tx_events;
modified drivers/pci/controller/dwc/pcie-dw-rockchip.c
@@ -421,23 +421,9 @@ static void rockchip_pcie_stop_link(struct dw_pcie *pci)
421 421 static int rockchip_pcie_host_init(struct dw_pcie_rp *pp)
422 422 {
423 423 struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
424 - struct rockchip_pcie *rockchip = to_rockchip_pcie(pci);
425 - struct device *dev = rockchip->pci.dev;
426 - int irq, ret;
427 -
428 - irq = of_irq_get_byname(dev->of_node, "legacy");
429 - if (irq < 0)
430 - return irq;
431 424
432 425 pci->dbi_base2 = pci->dbi_base + PCIE_TYPE0_HDR_DBI2_OFFSET;
433 426
434 - ret = rockchip_pcie_init_irq_domain(rockchip);
435 - if (ret < 0)
436 - dev_err(dev, "failed to init irq domain\n");
437 -
438 - irq_set_chained_handler_and_data(irq, rockchip_pcie_intx_handler,
439 - rockchip);
440 -
441 427 rockchip_pcie_configure_l1ss(pci);
442 428 rockchip_pcie_enable_l0s(pci);
443 429 pp->bridge->reset_root_port = rockchip_pcie_rc_reset_root_port;
@@ -730,6 +716,19 @@ static int rockchip_pcie_configure_rc(struct platform_device *pdev,
730 716 PCIE_CLIENT_SET_MODE(PCIE_CLIENT_MODE_RC),
731 717 PCIE_CLIENT_GENERAL_CON);
732 718
719 + irq = of_irq_get_byname(dev->of_node, "legacy");
720 + if (irq < 0)
721 + return irq;
722 +
723 + ret = rockchip_pcie_init_irq_domain(rockchip);
724 + if (ret < 0) {
725 + dev_err(dev, "failed to init irq domain\n");
726 + return ret;
727 + }
728 +
729 + irq_set_chained_handler_and_data(irq, rockchip_pcie_intx_handler,
730 + rockchip);
731 +
733 732 pp = &rockchip->pci.pp;
734 733 pp->ops = &rockchip_pcie_host_ops;
735 734
modified drivers/pci/controller/pci-hyperv.c
@@ -1040,19 +1040,38 @@ static void put_pcichild(struct hv_pci_dev *hpdev)
1040 1040
1041 1041 /*
1042 1042 * There is no good way to get notified from vmbus_onoffer_rescind(),
1043 - * so let's use polling here, since this is not a hot path.
1043 + * so let's use polling here, since this is not a hot path. If
1044 + * wait_for_response() has been polling for 2 minutes
1045 + * without either a rescind or completion, add a warning.
1044 1046 */
1047 + #define PCI_RESPONSE_WARN_POLL_COUNT 1200
1048 +
1045 1049 static int wait_for_response(struct hv_device *hdev,
1046 - struct completion *comp)
1050 + struct completion *comp,
1051 + const char *msg_type)
1047 1052 {
1053 + u64 counter = 0;
1054 +
1048 1055 while (true) {
1049 1056 if (hdev->channel->rescind) {
1050 1057 dev_warn_once(&hdev->device, "The device is gone.\n");
1051 1058 return -ENODEV;
1052 1059 }
1053 1060
1054 - if (wait_for_completion_timeout(comp, HZ / 10))
1061 + counter++;
1062 +
1063 + if (wait_for_completion_timeout(comp, HZ / 10)) {
1064 + if (counter > PCI_RESPONSE_WARN_POLL_COUNT)
1065 + dev_warn(&hdev->device,
1066 + "Late %s completion arrived.\n", msg_type);
1055 1067 break;
1068 + }
1069 +
1070 + if (counter == PCI_RESPONSE_WARN_POLL_COUNT) {
1071 + dev_err(&hdev->device,
1072 + "%s stuck waiting for response, relid = %u\n",
1073 + msg_type, hdev->channel->offermsg.child_relid);
1074 + }
1056 1075 }
1057 1076
1058 1077 return 0;
@@ -1518,7 +1537,8 @@ static int hv_read_config_block(struct pci_dev *pdev, void *buf,
1518 1537 if (ret)
1519 1538 return ret;
1520 1539
1521 - ret = wait_for_response(hbus->hdev, &comp_pkt.comp_pkt.host_event);
1540 + ret = wait_for_response(hbus->hdev, &comp_pkt.comp_pkt.host_event,
1541 + "PCI_READ_BLOCK");
1522 1542 if (ret)
1523 1543 return ret;
1524 1544
@@ -1607,7 +1627,8 @@ static int hv_write_config_block(struct pci_dev *pdev, void *buf,
1607 1627 if (ret)
1608 1628 return ret;
1609 1629
1610 - ret = wait_for_response(hbus->hdev, &comp_pkt.host_event);
1630 + ret = wait_for_response(hbus->hdev, &comp_pkt.host_event,
1631 + "PCI_WRITE_BLOCK");
1611 1632 if (ret)
1612 1633 return ret;
1613 1634
@@ -2624,7 +2645,8 @@ static struct hv_pci_dev *new_pcichild_device(struct hv_pcibus_device *hbus,
2624 2645 if (ret)
2625 2646 goto error;
2626 2647
2627 - if (wait_for_response(hbus->hdev, &comp_pkt.host_event))
2648 + if (wait_for_response(hbus->hdev, &comp_pkt.host_event,
2649 + "PCI_QUERY_RESOURCE_REQUIREMENTS"))
2628 2650 goto error;
2629 2651
2630 2652 hpdev->desc = *desc;
@@ -3256,7 +3278,8 @@ static int hv_pci_protocol_negotiation(struct hv_device *hdev,
3256 3278 (unsigned long)pkt, VM_PKT_DATA_INBAND,
3257 3279 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
3258 3280 if (!ret)
3259 - ret = wait_for_response(hdev, &comp_pkt.host_event);
3281 + ret = wait_for_response(hdev, &comp_pkt.host_event,
3282 + "PCI_QUERY_PROTOCOL_VERSION");
3260 3283
3261 3284 if (ret) {
3262 3285 dev_err(&hdev->device,
@@ -3476,7 +3499,8 @@ enter_d0_retry:
3476 3499 (unsigned long)pkt, VM_PKT_DATA_INBAND,
3477 3500 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
3478 3501 if (!ret)
3479 - ret = wait_for_response(hdev, &comp_pkt.host_event);
3502 + ret = wait_for_response(hdev, &comp_pkt.host_event,
3503 + "PCI_BUS_D0ENTRY");
3480 3504
3481 3505 if (ret)
3482 3506 goto exit;
@@ -3553,7 +3577,8 @@ static int hv_pci_query_relations(struct hv_device *hdev)
3553 3577 ret = vmbus_sendpacket(hdev->channel, &message, sizeof(message),
3554 3578 0, VM_PKT_DATA_INBAND, 0);
3555 3579 if (!ret)
3556 - ret = wait_for_response(hdev, &comp);
3580 + ret = wait_for_response(hdev, &comp,
3581 + "PCI_QUERY_BUS_RELATIONS");
3557 3582
3558 3583 /*
3559 3584 * In the case of fast device addition/removal, it's possible that
@@ -3644,7 +3669,8 @@ static int hv_send_resources_allocated(struct hv_device *hdev)
3644 3669 VM_PKT_DATA_INBAND,
3645 3670 VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
3646 3671 if (!ret)
3647 - ret = wait_for_response(hdev, &comp_pkt.host_event);
3672 + ret = wait_for_response(hdev, &comp_pkt.host_event,
3673 + "PCI_RESOURCE_ASSIGNED");
3648 3674 if (ret)
3649 3675 break;
3650 3676
@@ -4155,6 +4181,9 @@ static struct hv_driver hv_pci_drv = {
4155 4181 .remove = hv_pci_remove,
4156 4182 .suspend = hv_pci_suspend,
4157 4183 .resume = hv_pci_resume,
4184 + .driver = {
4185 + .probe_type = PROBE_PREFER_ASYNCHRONOUS,
4186 + },
4158 4187 };
4159 4188
4160 4189 static void __exit exit_hv_pci_drv(void)
modified drivers/pci/pci.c
@@ -1246,9 +1246,11 @@ static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout)
1246 1246 * initialize.
1247 1247 *
1248 1248 * If the device is below a Root Port with Configuration RRS
1249 - * Software Visibility enabled, reading the Vendor ID returns a
1249 + * Software Visibility enabled, reading the Vendor ID may return a
1250 1250 * special data value if the device responded with RRS. Read the
1251 - * Vendor ID until we get non-RRS status.
1251 + * Vendor ID until we get non-RRS status and something other than
1252 + * ~0. The Vendor ID of VFs reads ~0, so check their Command
1253 + * register instead.
1252 1254 *
1253 1255 * If there's no Root Port or Configuration RRS Software Visibility
1254 1256 * is not enabled, the device may still respond with RRS, but
@@ -1268,8 +1270,13 @@ static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout)
1268 1270
1269 1271 if (root && root->config_rrs_sv) {
1270 1272 pci_read_config_dword(dev, PCI_VENDOR_ID, &id);
1271 - if (!pci_bus_rrs_vendor_id(id))
1272 - break;
1273 + if (!pci_bus_rrs_vendor_id(id)) {
1274 + if (PCI_POSSIBLE_ERROR(id) && dev->is_virtfn)
1275 + pci_read_config_dword(dev, PCI_COMMAND,
1276 + &id);
1277 + if (!PCI_POSSIBLE_ERROR(id))
1278 + break;
1279 + }
1273 1280 } else {
1274 1281 pci_read_config_dword(dev, PCI_COMMAND, &id);
1275 1282 if (!PCI_POSSIBLE_ERROR(id))
modified drivers/pci/pcie/aer.c
@@ -428,7 +428,8 @@ void pci_aer_init(struct pci_dev *dev)
428 428 * Advisory Non-Fatal Errors are masked by default (PCIe r7.0, sec
429 429 * 7.8.4.6).
430 430 */
431 - if (pcie_aer_is_native(dev) && dev->devcap & PCI_EXP_DEVCAP_RBER)
431 + if (pcie_aer_is_native(dev) && dev->devcap & PCI_EXP_DEVCAP_RBER &&
432 + !dev->no_aer_anfe)
432 433 pci_clear_and_set_config_dword(dev,
433 434 dev->aer_cap + PCI_ERR_COR_MASK,
434 435 PCI_ERR_COR_ADV_NFAT, 0);
modified drivers/pci/quirks.c
@@ -2574,6 +2574,17 @@ static void quirk_p64h2_1k_io(struct pci_dev *dev)
2574 2574 }
2575 2575 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x1460, quirk_p64h2_1k_io);
2576 2576
2577 + /*
2578 + * Unmasking Advisory Non-Fatal Errors on the Apple T2 Secure Enclave
2579 + * causes a MacBookPro16,1 to lose power. Set this before pci_aer_init()
2580 + * so that it leaves the ANFE mask bit unchanged.
2581 + */
2582 + static void quirk_no_aer_anfe(struct pci_dev *dev)
2583 + {
2584 + dev->no_aer_anfe = 1;
2585 + }
2586 + DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_APPLE, 0x1802, quirk_no_aer_anfe);
2587 +
2577 2588 /*
2578 2589 * Under some circumstances, AER is not linked with extended capabilities.
2579 2590 * Force it to be linked by setting the corresponding control bit in the
@@ -5623,6 +5634,18 @@ static void quirk_no_flr_snet(struct pci_dev *dev)
5623 5634 }
5624 5635 DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SOLIDRUN, 0x1000, quirk_no_flr_snet);
5625 5636
5637 + /* Some Samsung SSDs advertise Immediate Readiness but aren't ready after FLR */
5638 + static void quirk_no_imm_ready(struct pci_dev *dev)
5639 + {
5640 + if (!dev->imm_ready)
5641 + return;
5642 +
5643 + pci_info(dev, "Ignoring incorrectly advertised Immediate Readiness support\n");
5644 + dev->imm_ready = 0;
5645 + }
5646 + DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SAMSUNG, 0xa80c, quirk_no_imm_ready);
5647 + DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SAMSUNG, 0xa80d, quirk_no_imm_ready);
5648 +
5626 5649 static void quirk_no_ext_tags(struct pci_dev *pdev)
5627 5650 {
5628 5651 struct pci_host_bridge *bridge = pci_find_host_bridge(pdev->bus);
modified drivers/pinctrl/pinctrl-amd.c
@@ -886,6 +886,15 @@ static void amd_gpio_irq_init(struct amd_gpio *gpio_dev)
886 886
887 887 mask = BIT(WAKE_CNTRL_OFF_S0I3) | BIT(WAKE_CNTRL_OFF_S3);
888 888
889 + #ifdef CONFIG_ACPI
890 + /*
891 + * Platforms without _AEI leave GPIO wake sources to firmware, so
892 + * preserve their S4 wake bits.
893 + */
894 + if (acpi_has_method(ACPI_HANDLE(&gpio_dev->pdev->dev), "_AEI"))
895 + mask |= BIT(WAKE_CNTRL_OFF_S4);
896 + #endif
897 +
889 898 for (i = 0; i < desc->npins; i++) {
890 899 int pin = desc->pins[i].number;
891 900 const struct pin_desc *pd = pin_desc_get(gpio_dev->pctrl, pin);
modified drivers/pinctrl/qcom/pinctrl-hawi.c
@@ -47,6 +47,7 @@
47 47 .intr_wakeup_present_bit = 6, \
48 48 .intr_wakeup_enable_bit = 7, \
49 49 .intr_target_bit = 8, \
50 + .intr_target_width = 4, \
50 51 .intr_target_kpss_val = 3, \
51 52 .intr_raw_status_bit = 4, \
52 53 .intr_polarity_bit = 1, \
modified drivers/pinctrl/qcom/pinctrl-ipq5018.c
@@ -361,7 +361,7 @@ static const char * const blsp1_uart0_groups[] = {
361 361 };
362 362
363 363 static const char * const gcc_plltest_groups[] = {
364 - "gpio10", "gpio12",
364 + "gpio10",
365 365 };
366 366
367 367 static const char * const gcc_tlmm_groups[] = {
@@ -539,7 +539,7 @@ static const char * const qdss_tracectl_b_groups[] = {
539 539 };
540 540
541 541 static const char * const pwm0_groups[] = {
542 - "gpio42",
542 + "gpio42", "gpio46",
543 543 };
544 544
545 545 static const char * const qdss_cti_trig_out_b0_groups[] = {
@@ -547,7 +547,7 @@ static const char * const qdss_cti_trig_out_b0_groups[] = {
547 547 };
548 548
549 549 static const char * const pwm1_groups[] = {
550 - "gpio43",
550 + "gpio43", "gpio1",
551 551 };
552 552
553 553 static const char * const qdss_cti_trig_in_b0_groups[] = {
@@ -555,7 +555,7 @@ static const char * const qdss_cti_trig_in_b0_groups[] = {
555 555 };
556 556
557 557 static const char * const pwm2_groups[] = {
558 - "gpio44",
558 + "gpio12", "gpio44",
559 559 };
560 560
561 561 static const char * const qdss_cti_trig_out_b1_groups[] = {
@@ -563,7 +563,7 @@ static const char * const qdss_cti_trig_out_b1_groups[] = {
563 563 };
564 564
565 565 static const char * const pwm3_groups[] = {
566 - "gpio45",
566 + "gpio45", "gpio30", "gpio13",
567 567 };
568 568
569 569 static const char * const qdss_cti_trig_in_b1_groups[] = {
@@ -677,7 +677,7 @@ static const struct pinfunction ipq5018_functions[] = {
677 677
678 678 static const struct msm_pingroup ipq5018_groups[] = {
679 679 PINGROUP(0, atest_char, _, qdss_cti_trig_out_a0, wci_txd, wci_rxd, xfem, _, _, _),
680 - PINGROUP(1, atest_char, _, qdss_cti_trig_in_a0, wci_txd, wci_rxd, xfem, _, _, _),
680 + PINGROUP(1, atest_char, pwm1, qdss_cti_trig_in_a0, wci_txd, wci_rxd, xfem, _, _, _),
681 681 PINGROUP(2, atest_char, _, qdss_cti_trig_out_a1, wci_txd, wci_rxd, xfem, _, _, _),
682 682 PINGROUP(3, atest_char, _, qdss_cti_trig_in_a1, wci_txd, wci_rxd, xfem, _, _, _),
683 683 PINGROUP(4, sdc1_data, qspi_data, blsp1_spi1, btss, dbg_out, qdss_traceclk_a, _, burn0, _),
@@ -688,8 +688,8 @@ static const struct msm_pingroup ipq5018_groups[] = {
688 688 PINGROUP(9, sdc1_clk, qspi_clk, _, qdss_tracedata_a, _, _, _, _, _),
689 689 PINGROUP(10, blsp0_spi, blsp1_uart0, led0, gcc_plltest, qdss_tracedata_a, _, _, _, _),
690 690 PINGROUP(11, blsp0_spi, blsp1_uart0, _, gcc_tlmm, qdss_tracedata_a, _, _, _, _),
691 - PINGROUP(12, blsp0_spi, blsp0_i2c, blsp1_uart0, _, gcc_plltest, qdss_tracedata_a, _, _, _),
692 - PINGROUP(13, blsp0_spi, blsp0_i2c, blsp1_uart0, _, qdss_tracedata_a, _, _, _, _),
691 + PINGROUP(12, blsp0_spi, blsp0_i2c, blsp1_uart0, _, pwm2, qdss_tracedata_a, _, _, _),
692 + PINGROUP(13, blsp0_spi, blsp0_i2c, blsp1_uart0, pwm3, qdss_tracedata_a, _, _, _, _),
693 693 PINGROUP(14, pcie0_clk, _, _, cri_trng0, qdss_tracedata_a, _, _, _, _),
694 694 PINGROUP(15, _, _, cri_trng1, qdss_tracedata_a, _, _, _, _, _),
695 695 PINGROUP(16, pcie0_wake, _, _, cri_trng, qdss_tracedata_a, _, _, _, _),
@@ -706,7 +706,7 @@ static const struct msm_pingroup ipq5018_groups[] = {
706 706 PINGROUP(27, audio_txmclk, wsa_swrm, audio_txmclk, blsp2_spi, btss, _, qdss_tracedata_b, _, _),
707 707 PINGROUP(28, audio_txbclk, wsa_swrm, blsp0_uart1, btss, qdss_tracedata_b, _, _, _, _),
708 708 PINGROUP(29, audio_txfsync, _, blsp0_uart1, _, qdss_tracedata_b, _, _, _, _),
709 - PINGROUP(30, audio_txd, led2, led0, _, _, _, _, _, _),
709 + PINGROUP(30, audio_txd, led2, led0, pwm3, _, _, _, _, _),
710 710 PINGROUP(31, blsp2_spi0, blsp1_uart1, _, qdss_tracedata_b, eud_gpio, _, _, _, _),
711 711 PINGROUP(32, blsp2_spi0, blsp1_uart1, _, qdss_tracedata_b, eud_gpio, _, _, _, _),
712 712 PINGROUP(33, blsp2_i2c0, blsp2_spi0, blsp1_uart1, _, qdss_tracedata_b, eud_gpio, _, _, _),
@@ -722,7 +722,7 @@ static const struct msm_pingroup ipq5018_groups[] = {
722 722 PINGROUP(43, pwm1, qdss_cti_trig_in_b0, wci_txd, wci_rxd, xfem, _, _, _, _),
723 723 PINGROUP(44, pwm2, qdss_cti_trig_out_b1, wci_txd, wci_rxd, xfem, _, _, _, _),
724 724 PINGROUP(45, pwm3, qdss_cti_trig_in_b1, wci_txd, wci_rxd, xfem, _, _, _, _),
725 - PINGROUP(46, led0, _, _, _, _, _, _, _, _),
725 + PINGROUP(46, led0, pwm0, _, _, _, _, _, _, _),
726 726 };
727 727
728 728 static const struct msm_pinctrl_soc_data ipq5018_pinctrl = {
modified drivers/pinctrl/qcom/pinctrl-maili.c
@@ -47,6 +47,7 @@
47 47 .intr_wakeup_present_bit = 6, \
48 48 .intr_wakeup_enable_bit = 7, \
49 49 .intr_target_bit = 8, \
50 + .intr_target_width = 4, \
50 51 .intr_target_kpss_val = 3, \
51 52 .intr_raw_status_bit = 4, \
52 53 .intr_polarity_bit = 1, \
modified drivers/pinctrl/qcom/pinctrl-nord.c
@@ -32,6 +32,7 @@
32 32 .intr_wakeup_present_bit = 6, \
33 33 .intr_wakeup_enable_bit = 7, \
34 34 .intr_target_bit = 8, \
35 + .intr_target_width = 4, \
35 36 .intr_target_kpss_val = 3, \
36 37 .intr_raw_status_bit = 4, \
37 38 .intr_polarity_bit = 1, \
modified drivers/pinctrl/qcom/pinctrl-qcs8300.c
@@ -45,6 +45,7 @@
45 45 .intr_enable_bit = 0, \
46 46 .intr_status_bit = 0, \
47 47 .intr_target_bit = 5, \
48 + .intr_target_width = 4, \
48 49 .intr_target_kpss_val = 3, \
49 50 .intr_raw_status_bit = 4, \
50 51 .intr_polarity_bit = 1, \
modified drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
@@ -734,29 +734,50 @@ static int pmic_gpio_get_direction(struct gpio_chip *chip, unsigned pin)
734 734 (!pad->input_enabled && !pad->output_enabled))
735 735 return -EINVAL;
736 736
737 - /* Make sure the state is aligned on what pmic_gpio_get() returns */
738 - return pad->input_enabled ? GPIO_LINE_DIRECTION_IN : GPIO_LINE_DIRECTION_OUT;
737 + /*
738 + * An open-drain or open-source pad keeps its input buffer enabled while
739 + * driving, so the output buffer is what tells the direction.
740 + */
741 + return pad->output_enabled ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
739 742 }
740 743
741 744 static int pmic_gpio_direction_input(struct gpio_chip *chip, unsigned pin)
742 745 {
743 746 struct pmic_gpio_state *state = gpiochip_get_data(chip);
744 - unsigned long config;
747 + unsigned long configs[2];
745 748
746 - config = pinconf_to_config_packed(PIN_CONFIG_INPUT_ENABLE, 1);
749 + configs[0] = pinconf_to_config_packed(PIN_CONFIG_OUTPUT_ENABLE, 0);
750 + configs[1] = pinconf_to_config_packed(PIN_CONFIG_INPUT_ENABLE, 1);
747 751
748 - return pmic_gpio_config_set(state->ctrl, pin, &config, 1);
752 + return pmic_gpio_config_set(state->ctrl, pin, configs,
753 + ARRAY_SIZE(configs));
749 754 }
750 755
751 756 static int pmic_gpio_direction_output(struct gpio_chip *chip,
752 757 unsigned pin, int val)
753 758 {
754 759 struct pmic_gpio_state *state = gpiochip_get_data(chip);
755 - unsigned long config;
760 + struct pmic_gpio_pad *pad = state->ctrl->desc->pins[pin].drv_data;
761 + unsigned long configs[2];
756 762
757 - config = pinconf_to_config_packed(PIN_CONFIG_LEVEL, val);
763 + /*
764 + * An open-drain or open-source pad only ever drives one rail, so the
765 + * line can still be sampled while the pad is an output. Keep the input
766 + * buffer enabled for those, so that pmic_gpio_get() reports what is on
767 + * the wire rather than the value last written, and disable it for a
768 + * CMOS pad, so that the pad ends up in DIGITAL_OUTPUT rather than
769 + * DIGITAL_INPUT_OUTPUT. Program it either way, as the buffer may have
770 + * been left in the opposite state by the bootloader or by an earlier
771 + * direction change with a different buffer type. gpiolib applies
772 + * PIN_CONFIG_DRIVE_OPEN_DRAIN before calling this, so buffer_type is
773 + * already up to date here.
774 + */
775 + configs[0] = pinconf_to_config_packed(PIN_CONFIG_INPUT_ENABLE,
776 + pad->buffer_type != PMIC_GPIO_OUT_BUF_CMOS);
777 + configs[1] = pinconf_to_config_packed(PIN_CONFIG_LEVEL, val);
758 778
759 - return pmic_gpio_config_set(state->ctrl, pin, &config, 1);
779 + return pmic_gpio_config_set(state->ctrl, pin, configs,
780 + ARRAY_SIZE(configs));
760 781 }
761 782
762 783 static int pmic_gpio_get(struct gpio_chip *chip, unsigned pin)
modified drivers/pinctrl/sunxi/pinctrl-sunxi-dt.c
@@ -84,6 +84,7 @@ static struct sunxi_desc_pin *init_pins_table(struct device *dev,
84 84 * Find the total number of pins.
85 85 * Also work out how much memory we need to store all the pin names.
86 86 */
87 + desc->npins = 0;
87 88 for (i = 0; i < SUNXI_PINCTRL_MAX_BANKS; i++) {
88 89 desc->npins += pins_per_bank[i];
89 90 if (pins_per_bank[i] < 10) {
modified drivers/power/sequencing/pwrseq-qcom-wcn.c
@@ -496,15 +496,8 @@ static int pwrseq_qcom_wcn_probe(struct platform_device *pdev)
496 496 return dev_err_probe(dev, PTR_ERR(ctx->bt_gpio),
497 497 "Failed to get the Bluetooth enable GPIO\n");
498 498
499 - /*
500 - * FIXME: This should actually be GPIOD_OUT_LOW, but doing so would
501 - * cause the WLAN power to be toggled, resulting in PCIe link down.
502 - * Since the PCIe controller driver is not handling link down currently,
503 - * the device becomes unusable. So we need to keep this workaround until
504 - * the link down handling is implemented in the controller driver.
505 - */
506 499 ctx->wlan_gpio = devm_gpiod_get_optional(dev, "wlan-enable",
507 - GPIOD_ASIS);
500 + GPIOD_OUT_LOW);
508 501 if (IS_ERR(ctx->wlan_gpio))
509 502 return dev_err_probe(dev, PTR_ERR(ctx->wlan_gpio),
510 503 "Failed to get the WLAN enable GPIO\n");
@@ -515,13 +508,6 @@ static int pwrseq_qcom_wcn_probe(struct platform_device *pdev)
515 508 return dev_err_probe(dev, PTR_ERR(ctx->xo_clk_gpio),
516 509 "Failed to get the XO_CLK GPIO\n");
517 510
518 - /*
519 - * Set direction to output but keep the current value in order to not
520 - * disable the WLAN module accidentally if it's already powered on.
521 - */
522 - gpiod_direction_output(ctx->wlan_gpio,
523 - gpiod_get_value_cansleep(ctx->wlan_gpio));
524 -
525 511 ctx->clk = devm_clk_get_optional(dev, NULL);
526 512 if (IS_ERR(ctx->clk))
527 513 return dev_err_probe(dev, PTR_ERR(ctx->clk),
modified drivers/power/supply/ds2780_battery.c
@@ -304,7 +304,7 @@ static int ds2780_get_capacity(struct ds2780_device_info *dev_info,
304 304 return ret;
305 305
306 306 *capacity = raw;
307 - return raw;
307 + return 0;
308 308 }
309 309
310 310 static int ds2780_get_status(struct ds2780_device_info *dev_info, int *status)
modified drivers/power/supply/generic-adc-battery.c
@@ -90,12 +90,17 @@ static int gab_read_channel(struct gab *adc_bat, enum gab_chan_type channel,
90 90 int ret;
91 91
92 92 ret = iio_read_channel_processed(adc_bat->channel[channel], result);
93 - if (ret < 0)
93 + if (ret < 0) {
94 94 dev_err(&adc_bat->psy->dev, "read channel error: %d\n", ret);
95 + return ret;
96 + }
97 +
98 + if (channel == GAB_TEMP)
99 + *result /= 100; /* Convert from milli- to deci-degree */
95 100 else
96 101 *result *= 1000;
97 102
98 - return ret;
103 + return 0;
99 104 }
100 105
101 106 static int gab_get_property(struct power_supply *psy,
modified drivers/power/supply/max17042_battery.c
@@ -1233,7 +1233,7 @@ static int max17042_parse_dt(struct max17042_chip *chip)
1233 1233 if (of_property_read_u32(np, "maxim,over-volt", &prop))
1234 1234 chip->vmax = INT_MAX;
1235 1235 else
1236 - chip->vmin = prop;
1236 + chip->vmax = prop;
1237 1237
1238 1238 return 0;
1239 1239 }
modified drivers/power/supply/power_supply_core.c
@@ -1530,6 +1530,19 @@ void power_supply_external_power_changed(struct power_supply *psy)
1530 1530 !psy->desc->external_power_changed)
1531 1531 return;
1532 1532
1533 + /*
1534 + * Keep power_supply_unregister() from returning, and thus from letting
1535 + * the driver's data be freed, while the callback is running. The
1536 + * ->removing check has to happen under the lock: on its own, just like
1537 + * the use_cnt check above, it only tells us the supply was still there
1538 + * when we looked, not that it still is by the time the callback
1539 + * dereferences its driver data.
1540 + */
1541 + guard(rwsem_read)(&psy->epc_sem);
1542 +
1543 + if (psy->removing)
1544 + return;
1545 +
1533 1546 psy->desc->external_power_changed(psy);
1534 1547 }
1535 1548 EXPORT_SYMBOL_GPL(power_supply_external_power_changed);
@@ -1774,6 +1787,7 @@ __power_supply_register(struct device *parent,
1774 1787 }
1775 1788
1776 1789 spin_lock_init(&psy->changed_lock);
1790 + init_rwsem(&psy->epc_sem);
1777 1791 init_rwsem(&psy->extensions_sem);
1778 1792 INIT_LIST_HEAD(&psy->extensions);
1779 1793
@@ -1914,7 +1928,17 @@ EXPORT_SYMBOL_GPL(devm_power_supply_register);
1914 1928 void power_supply_unregister(struct power_supply *psy)
1915 1929 {
1916 1930 WARN_ON(atomic_dec_return(&psy->use_cnt));
1917 - psy->removing = true;
1931 +
1932 + /*
1933 + * Publish ->removing so that no new ->external_power_changed() call can
1934 + * start, and wait via semaphore for one that is already running: it may
1935 + * be a supplier's changed_work, which cancel_work_sync() below does not
1936 + * cover, and it may still dereference driver data that the caller is
1937 + * about to free.
1938 + */
1939 + scoped_guard(rwsem_write, &psy->epc_sem)
1940 + psy->removing = true;
1941 +
1918 1942 cancel_work_sync(&psy->changed_work);
1919 1943 cancel_delayed_work_sync(&psy->deferred_register_work);
1920 1944 sysfs_remove_link(&psy->dev.kobj, "powers");
modified drivers/soc/tegra/fuse/tegra-apbmisc.c
@@ -309,7 +309,7 @@ void tegra_acpi_init_apbmisc(void)
309 309
310 310 ret = acpi_dev_get_memory_resources(adev, &resource_list);
311 311 if (ret < 0) {
312 - pr_err("failed to get APBMISC memory resources");
312 + pr_err("failed to get APBMISC memory resources\n");
313 313 goto out_put_acpi_dev;
314 314 }
315 315
modified drivers/soc/tegra/pmc.c
@@ -3151,6 +3151,7 @@ static int tegra_pmc_probe(struct platform_device *pdev)
3151 3151
3152 3152 #if defined(CONFIG_ARM)
3153 3153 mutex_lock(&early_pmc->powergates_lock);
3154 + early_pmc->rate = pmc->rate;
3154 3155 iounmap(early_pmc->base);
3155 3156 early_pmc->base = pmc->base;
3156 3157 mutex_unlock(&early_pmc->powergates_lock);
modified fs/9p/v9fs.h
@@ -137,6 +137,7 @@ struct v9fs_session_info {
137 137 struct list_head slist; /* list of sessions registered with v9fs */
138 138 struct rw_semaphore rename_sem;
139 139 long session_lock_timeout; /* retry interval for blocking locks */
140 + struct rcu_head rcu; /* v9fs_vfs_get_link_dotl() reads ->cache in rcu pathwalk */
140 141 };
141 142
142 143 #define NDENTRY_TIMEOUT_NEVER (-1U)
modified fs/9p/vfs_super.c
@@ -173,8 +173,8 @@ static void v9fs_kill_super(struct super_block *s)
173 173
174 174 v9fs_session_cancel(v9ses);
175 175 v9fs_session_close(v9ses);
176 - kfree(v9ses);
177 - s->s_fs_info = NULL;
176 + /* v9fs_vfs_get_link_dotl() may still read ->cache in rcu pathwalk */
177 + kfree_rcu(v9ses, rcu);
178 178 p9_debug(P9_DEBUG_VFS, "exiting kill_super\n");
179 179 }
180 180
modified fs/afs/internal.h
@@ -251,6 +251,8 @@ struct afs_super_info {
251 251 struct afs_volume *volume; /* volume record */
252 252 enum afs_flock_mode flock_mode:8; /* File locking emulation mode */
253 253 bool dyn_root; /* True if dynamic root */
254 + /* afs_atcell_get_link() reads ->net_ns in rcu pathwalk */
255 + struct rcu_head rcu;
254 256 };
255 257
256 258 static inline struct afs_super_info *AFS_FS_S(struct super_block *sb)
modified fs/afs/super.c
@@ -523,7 +523,7 @@ static void afs_destroy_sbi(struct afs_super_info *as)
523 523 afs_put_volume(as->volume, afs_volume_trace_put_destroy_sbi);
524 524 afs_unuse_cell(as->cell, afs_cell_trace_unuse_sbi);
525 525 put_net(as->net_ns);
526 - kfree(as);
526 + kfree_rcu(as, rcu);
527 527 }
528 528 }
529 529
modified fs/autofs/waitq.c
@@ -12,15 +12,13 @@
12 12 */
13 13 static autofs_wqt_t autofs_next_wait_queue = 1;
14 14
15 - void autofs_catatonic_mode(struct autofs_sb_info *sbi)
15 + static void autofs_catatonic_mode_locked(struct autofs_sb_info *sbi)
16 16 {
17 17 struct autofs_wait_queue *wq, *nwq;
18 18
19 - mutex_lock(&sbi->wq_mutex);
20 - if (sbi->flags & AUTOFS_SBI_CATATONIC) {
21 - mutex_unlock(&sbi->wq_mutex);
19 + lockdep_assert_held(&sbi->wq_mutex);
20 + if (sbi->flags & AUTOFS_SBI_CATATONIC)
22 21 return;
23 - }
24 22
25 23 pr_debug("entering catatonic mode\n");
26 24
@@ -40,6 +38,21 @@ void autofs_catatonic_mode(struct autofs_sb_info *sbi)
40 38 fput(sbi->pipe); /* Close the pipe */
41 39 sbi->pipe = NULL;
42 40 sbi->pipefd = -1;
41 + }
42 +
43 + void autofs_catatonic_mode(struct autofs_sb_info *sbi)
44 + {
45 + mutex_lock(&sbi->wq_mutex);
46 + autofs_catatonic_mode_locked(sbi);
47 + mutex_unlock(&sbi->wq_mutex);
48 + }
49 +
50 + static void autofs_catatonic_mode_for_pipe(struct autofs_sb_info *sbi,
51 + struct file *pipe)
52 + {
53 + mutex_lock(&sbi->wq_mutex);
54 + if (sbi->pipe == pipe)
55 + autofs_catatonic_mode_locked(sbi);
43 56 mutex_unlock(&sbi->wq_mutex);
44 57 }
45 58
@@ -170,7 +183,7 @@ static void autofs_notify_daemon(struct autofs_sb_info *sbi,
170 183 autofs_wait_release(sbi, wq->wait_queue_token, ret);
171 184 break;
172 185 default:
173 - autofs_catatonic_mode(sbi);
186 + autofs_catatonic_mode_for_pipe(sbi, pipe);
174 187 break;
175 188 }
176 189 fput(pipe);
modified fs/ext4/ext4.h
@@ -1774,6 +1774,8 @@ struct ext4_sb_info {
1774 1774 struct list_head s_es_list; /* List of inodes with reclaimable extents */
1775 1775 long s_es_nr_inode;
1776 1776 struct ext4_es_stats s_es_stats;
1777 + /* ext4_get_link() reads the sbi in rcu pathwalk */
1778 + struct rcu_head s_rcu;
1777 1779 struct mb_cache *s_ea_block_cache;
1778 1780 struct mb_cache *s_ea_inode_cache;
1779 1781
modified fs/ext4/extents-test.c
@@ -151,6 +151,7 @@ static void extents_kunit_exit(struct kunit *test)
151 151
152 152 sbi = k_ctx.k_ei->vfs_inode.i_sb->s_fs_info;
153 153 ext4_es_unregister_shrinker(sbi);
154 + ext4_es_destroy_stats(sbi);
154 155 deactivate_super(sbi->s_sb);
155 156 kfree(sbi);
156 157 kfree(k_ctx.k_ei);
@@ -340,6 +341,7 @@ out:
340 341 k_ctx.k_data = NULL;
341 342
342 343 ext4_es_unregister_shrinker(sbi);
344 + ext4_es_destroy_stats(sbi);
343 345 out_deactivate:
344 346 deactivate_locked_super(sb);
345 347 kfree(sbi);
modified fs/ext4/extents.c
@@ -6409,6 +6409,7 @@ EXPORT_SYMBOL_FOR_EXT4_TEST(__ext4_ext_dirty);
6409 6409 EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_ext_zeroout);
6410 6410 EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_register_shrinker);
6411 6411 EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_unregister_shrinker);
6412 + EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_destroy_stats);
6412 6413 EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_map_create_blocks);
6413 6414 EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_init_tree);
6414 6415 EXPORT_SYMBOL_FOR_EXT4_TEST(ext4_es_lookup_extent);
modified fs/ext4/extents_status.c
@@ -1881,12 +1881,17 @@ err1:
1881 1881 }
1882 1882
1883 1883 void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi)
1884 + {
1885 + shrinker_free(sbi->s_es_shrinker);
1886 + }
1887 +
1888 + /* ext4_get_link() bumps the hit and miss counters in rcu pathwalk */
1889 + void ext4_es_destroy_stats(struct ext4_sb_info *sbi)
1884 1890 {
1885 1891 percpu_counter_destroy(&sbi->s_es_stats.es_stats_cache_hits);
1886 1892 percpu_counter_destroy(&sbi->s_es_stats.es_stats_cache_misses);
1887 1893 percpu_counter_destroy(&sbi->s_es_stats.es_stats_all_cnt);
1888 1894 percpu_counter_destroy(&sbi->s_es_stats.es_stats_shk_cnt);
1889 - shrinker_free(sbi->s_es_shrinker);
1890 1895 }
1891 1896
1892 1897 /*
modified fs/ext4/extents_status.h
@@ -238,6 +238,7 @@ static inline void ext4_es_store_pblock_status(struct extent_status *es,
238 238
239 239 extern int ext4_es_register_shrinker(struct ext4_sb_info *sbi);
240 240 extern void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi);
241 + extern void ext4_es_destroy_stats(struct ext4_sb_info *sbi);
241 242
242 243 extern int ext4_seq_es_shrinker_info_show(struct seq_file *seq, void *v);
243 244
modified fs/ext4/super.c
@@ -1279,6 +1279,14 @@ static void ext4_flex_groups_free(struct ext4_sb_info *sbi)
1279 1279 }
1280 1280 }
1281 1281
1282 + static void ext4_put_sbi_rcu(struct rcu_head *head)
1283 + {
1284 + struct ext4_sb_info *sbi = container_of(head, struct ext4_sb_info, s_rcu);
1285 +
1286 + ext4_es_destroy_stats(sbi);
1287 + kfree(sbi);
1288 + }
1289 +
1282 1290 static void ext4_put_super(struct super_block *sb)
1283 1291 {
1284 1292 struct ext4_sb_info *sbi = EXT4_SB(sb);
@@ -1374,7 +1382,6 @@ static void ext4_put_super(struct super_block *sb)
1374 1382 ext4_stop_mmpd(sbi);
1375 1383
1376 1384 brelse(sbi->s_sbh);
1377 - sb->s_fs_info = NULL;
1378 1385 /*
1379 1386 * Now that we are completely done shutting down the
1380 1387 * superblock, we need to actually destroy the kobject.
@@ -1387,7 +1394,8 @@ static void ext4_put_super(struct super_block *sb)
1387 1394 #if IS_ENABLED(CONFIG_UNICODE)
1388 1395 utf8_unload(sb->s_encoding);
1389 1396 #endif
1390 - kfree(sbi);
1397 + /* ext4_get_link() reads the sbi and the counters in rcu pathwalk */
1398 + call_rcu(&sbi->s_rcu, ext4_put_sbi_rcu);
1391 1399 }
1392 1400
1393 1401 static struct kmem_cache *ext4_inode_cachep;
@@ -5806,6 +5814,7 @@ failed_mount3a:
5806 5814 /* Drain deferred EA inode iputs from journal replay */
5807 5815 flush_delayed_work(&sbi->s_ea_inode_work);
5808 5816 ext4_es_unregister_shrinker(sbi);
5817 + ext4_es_destroy_stats(sbi);
5809 5818 failed_mount3:
5810 5819 /* flush s_sb_upd_work before sbi destroy */
5811 5820 flush_work(&sbi->s_sb_upd_work);
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);
@@ -4750,8 +4721,7 @@ static struct dentry *lookup_fast_for_open(struct nameidata *nd, int open_flag)
4750 4721 return dentry;
4751 4722
4752 4723 if (open_flag & O_CREAT) {
4753 - /* Discard negative dentries. Need inode_lock to do the create */
4754 - if (!dentry->d_inode) {
4724 + if (d_is_negative(dentry)) {
4755 4725 if (!(nd->flags & LOOKUP_RCU))
4756 4726 dput(dentry);
4757 4727 dentry = NULL;
modified fs/namespace.c
@@ -297,7 +297,11 @@ int mnt_get_count(struct mount *mnt)
297 297 /* puts first, so a put counted here has its get counted below */
298 298 for_each_possible_cpu(cpu)
299 299 puts += per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_puts;
300 - smp_mb(); /* pairs with the smp_wmb() in mntput_no_expire() */
300 + /*
301 + * Pairs with the smp_wmb() in mntput_no_expire() and with the
302 + * smp_mb() in __legitimize_mnt().
303 + */
304 + smp_mb();
301 305 for_each_possible_cpu(cpu)
302 306 gets += per_cpu_ptr(mnt->mnt_pcp, cpu)->mnt_gets;
303 307
@@ -782,7 +786,7 @@ int __legitimize_mnt(struct vfsmount *bastard, unsigned seq)
782 786 return 0;
783 787 mnt = real_mount(bastard);
784 788 mnt_inc_count(mnt);
785 - smp_mb(); /* see mntput_no_expire_slowpath() and do_umount() */
789 + smp_mb(); /* pairs with the smp_mb() in mnt_get_count() */
786 790 if (likely(!read_seqretry(&mount_lock, seq)))
787 791 return 0;
788 792 lock_mount_hash();
@@ -1419,11 +1423,6 @@ static void noinline mntput_no_expire_slowpath(struct mount *mnt)
1419 1423
1420 1424 VFS_BUG_ON(mnt->mnt_ns);
1421 1425 lock_mount_hash();
1422 - /*
1423 - * make sure that if __legitimize_mnt() has not seen us grab
1424 - * mount_lock, we'll see their refcount increment here.
1425 - */
1426 - smp_mb();
1427 1426 mnt_dec_count(mnt);
1428 1427 count = mnt_get_count(mnt);
1429 1428 if (count != 0) {
@@ -2006,7 +2005,6 @@ static int do_umount(struct mount *mnt, int flags)
2006 2005 umount_tree(mnt, UMOUNT_PROPAGATE);
2007 2006 retval = 0;
2008 2007 } else {
2009 - smp_mb(); // paired with __legitimize_mnt()
2010 2008 shrink_submounts(mnt);
2011 2009 retval = -EBUSY;
2012 2010 if (!propagate_mount_busy(mnt, 2)) {
@@ -2254,6 +2252,11 @@ struct mount *copy_tree(struct mount *src_root, struct dentry *dentry,
2254 2252 }
2255 2253 if (!(flag & CL_COPY_MNT_NS_FILE) &&
2256 2254 is_mnt_ns_file(src_mnt->mnt.mnt_root)) {
2255 + if (src_mnt->mnt.mnt_flags & MNT_LOCKED) {
2256 + /* Both a mount namespace file and locked. */
2257 + dst_mnt = ERR_PTR(-EPERM);
2258 + goto out;
2259 + }
2257 2260 src_mnt = skip_mnt_tree(src_mnt);
2258 2261 continue;
2259 2262 }
@@ -3649,8 +3652,9 @@ static bool mount_is_ancestor(const struct mount *p1, const struct mount *p2)
3649 3652 * @mnt_to: mount under which to mount
3650 3653 * @mp: mountpoint of @mnt_to
3651 3654 *
3652 - * - Make sure that the caller can unmount the topmost mount ensuring
3653 - * that the caller could reveal the underlying mountpoint.
3655 + * - Make sure that @mnt_from can take over the lock of @mnt_to. A
3656 + * mount of a mount namespace file is left out of a copy of the tree
3657 + * and can't.
3654 3658 * - Ensure that nothing has been mounted on top of @mnt_from before we
3655 3659 * grabbed @namespace_sem to avoid creating pointless shadow mounts.
3656 3660 * - Prevent mounting beneath a mount if the propagation relationship
@@ -3666,6 +3670,15 @@ static int can_move_mount_beneath(const struct mount *mnt_from,
3666 3670 {
3667 3671 struct mount *parent_mnt_to = mnt_to->mnt_parent;
3668 3672
3673 + /*
3674 + * @mnt_from takes over the lock of @mnt_to. copy_tree() leaves a
3675 + * mount of a mount namespace file out of every copy made without
3676 + * CL_COPY_MNT_NS_FILE, together with what is mounted on it, so it
3677 + * can't keep anything hidden.
3678 + */
3679 + if (IS_MNT_LOCKED(mnt_to) && is_mnt_ns_file(mnt_from->mnt.mnt_root))
3680 + return -EINVAL;
3681 +
3669 3682 /* Avoid creating shadow mounts during mount propagation. */
3670 3683 if (mnt_from->overmount)
3671 3684 return -EINVAL;
modified fs/notify/mark.c
@@ -929,6 +929,11 @@ restart:
929 929 goto restart;
930 930 }
931 931
932 + if (conn->flags & FSNOTIFY_CONN_FLAG_DESTROYING) {
933 + err = -ENOENT;
934 + goto out_err;
935 + }
936 +
932 937 /* is mark the first mark? */
933 938 if (hlist_empty(&conn->list)) {
934 939 hlist_add_head_rcu(&mark->obj_list, &conn->list);
@@ -1116,6 +1121,12 @@ void fsnotify_destroy_marks(fsnotify_connp_t *connp)
1116 1121 conn = fsnotify_grab_connector(connp);
1117 1122 if (!conn)
1118 1123 return;
1124 + /*
1125 + * New marks could be inserted before our cursor and survive the final
1126 + * detachment of the connector from the object. Prevent additions to
1127 + * this connector before dropping its lock.
1128 + */
1129 + conn->flags |= FSNOTIFY_CONN_FLAG_DESTROYING;
1119 1130 /*
1120 1131 * We have to be careful since we can race with e.g.
1121 1132 * fsnotify_clear_marks_by_group() and once we drop the conn->lock, the
modified fs/ntfs3/dir.c
@@ -186,11 +186,20 @@ int ntfs_nls_to_utf16(struct ntfs_sb_info *sbi, const u8 *name, u32 name_len,
186 186 {
187 187 int ret, slen, i;
188 188 const u8 *end;
189 - struct nls_table *nls = sbi->options->nls;
189 + struct ntfs_mount_options *opts;
190 + struct nls_table *nls;
191 + bool ads;
190 192 u16 *uname = uni->name;
191 193
192 194 static_assert(sizeof(wchar_t) == sizeof(u16));
193 195
196 + /* ntfs_fs_reconfigure() may replace the options, but not ->nls */
197 + rcu_read_lock();
198 + opts = READ_ONCE(sbi->options);
199 + nls = opts->nls;
200 + ads = opts->ads;
201 + rcu_read_unlock();
202 +
194 203 if (!nls) {
195 204 /* utf8 -> utf16 */
196 205 ret = _utf8s_to_utf16s(name, name_len, endian, uname, max_ulen);
@@ -230,7 +239,7 @@ int ntfs_nls_to_utf16(struct ntfs_sb_info *sbi, const u8 *name, u32 name_len,
230 239
231 240 uni->len = ret;
232 241 uni->ads_len = 0;
233 - if (ret > 0 && sbi->options->ads) {
242 + if (ret > 0 && ads) {
234 243 uname = uni->name;
235 244 /* Find delimiter in range [1 : ret-2). */
236 245 for (i = 1; i + 1 < ret; i++) {
modified fs/ntfs3/ntfs_fs.h
@@ -91,6 +91,8 @@ enum utf16_endian;
91 91 struct ntfs_mount_options {
92 92 char *nls_name;
93 93 struct nls_table *nls;
94 + /* ->d_hash() and ->d_compare() read the options in rcu pathwalk */
95 + struct rcu_head rcu;
94 96
95 97 kuid_t fs_uid;
96 98 kgid_t fs_gid;
@@ -211,6 +213,7 @@ struct ntfs_index {
211 213 /* Ntfs file system in-core superblock data. */
212 214 struct ntfs_sb_info {
213 215 struct super_block *sb;
216 + struct rcu_head rcu;
214 217
215 218 u32 discard_granularity;
216 219 u64 discard_granularity_mask_inv; // ~(discard_granularity_mask_inv-1)
modified fs/ntfs3/super.c
@@ -196,7 +196,7 @@ void *ntfs_set_shared(void *ptr, u32 bytes)
196 196 void *ret = NULL;
197 197 int i, j = -1;
198 198
199 - spin_lock(&s_shared_lock);
199 + spin_lock_bh(&s_shared_lock);
200 200 for (i = 0; i < ARRAY_SIZE(s_shared); i++) {
201 201 if (!s_shared[i].cnt) {
202 202 j = i;
@@ -214,7 +214,7 @@ void *ntfs_set_shared(void *ptr, u32 bytes)
214 214 s_shared[j].cnt = 1;
215 215 ret = ptr;
216 216 }
217 - spin_unlock(&s_shared_lock);
217 + spin_unlock_bh(&s_shared_lock);
218 218
219 219 return ret;
220 220 }
@@ -231,7 +231,7 @@ void *ntfs_put_shared(void *ptr)
231 231 void *ret = ptr;
232 232 int i;
233 233
234 - spin_lock(&s_shared_lock);
234 + spin_lock_bh(&s_shared_lock);
235 235 for (i = 0; i < ARRAY_SIZE(s_shared); i++) {
236 236 if (s_shared[i].cnt && s_shared[i].ptr == ptr) {
237 237 if (--s_shared[i].cnt)
@@ -239,7 +239,7 @@ void *ntfs_put_shared(void *ptr)
239 239 break;
240 240 }
241 241 }
242 - spin_unlock(&s_shared_lock);
242 + spin_unlock_bh(&s_shared_lock);
243 243
244 244 return ret;
245 245 }
@@ -251,6 +251,11 @@ static inline void put_mount_options(struct ntfs_mount_options *options)
251 251 kfree(options);
252 252 }
253 253
254 + static void put_mount_options_rcu(struct rcu_head *head)
255 + {
256 + put_mount_options(container_of(head, struct ntfs_mount_options, rcu));
257 + }
258 +
254 259 enum Opt {
255 260 Opt_uid,
256 261 Opt_gid,
@@ -444,6 +449,7 @@ static int ntfs_fs_reconfigure(struct fs_context *fc)
444 449 struct super_block *sb = fc->root->d_sb;
445 450 struct ntfs_sb_info *sbi = sb->s_fs_info;
446 451 struct ntfs_mount_options *new_opts = fc->fs_private;
452 + struct ntfs_mount_options *old_opts;
447 453 int ro_rw;
448 454
449 455 ro_rw = sb_rdonly(sb) && !(fc->sb_flags & SB_RDONLY);
@@ -473,7 +479,15 @@ static int ntfs_fs_reconfigure(struct fs_context *fc)
473 479 }
474 480
475 481 sync_filesystem(sb);
476 - swap(sbi->options, fc->fs_private);
482 + old_opts = sbi->options;
483 + /* pairs with the READ_ONCE() in ntfs_nls_to_utf16() */
484 + smp_store_release(&sbi->options, new_opts);
485 + fc->fs_private = NULL;
486 + /*
487 + * ntfs_d_hash() and ntfs_d_compare() of a pathwalk in rcu mode may
488 + * still read the old options through the sbi.
489 + */
490 + call_rcu(&old_opts->rcu, put_mount_options_rcu);
477 491
478 492 return 0;
479 493 }
@@ -708,6 +722,8 @@ static noinline void ntfs3_put_sbi(struct ntfs_sb_info *sbi)
708 722
709 723 static void ntfs3_free_sbi(struct ntfs_sb_info *sbi)
710 724 {
725 + if (sbi->options)
726 + put_mount_options(sbi->options);
711 727 kfree(sbi->new_rec);
712 728 kvfree(ntfs_put_shared(sbi->upcase));
713 729 kvfree(sbi->def_table);
@@ -719,6 +735,11 @@ static void ntfs3_free_sbi(struct ntfs_sb_info *sbi)
719 735 kfree(sbi);
720 736 }
721 737
738 + static void ntfs3_free_sbi_rcu(struct rcu_head *head)
739 + {
740 + ntfs3_free_sbi(container_of(head, struct ntfs_sb_info, rcu));
741 + }
742 +
722 743 static void ntfs_put_super(struct super_block *sb)
723 744 {
724 745 struct ntfs_sb_info *sbi = sb->s_fs_info;
@@ -728,11 +749,11 @@ static void ntfs_put_super(struct super_block *sb)
728 749 /* Mark rw ntfs as clear, if possible. */
729 750 ntfs_set_state(sbi, NTFS_DIRTY_CLEAR);
730 751
731 - if (sbi->options) {
732 - put_mount_options(sbi->options);
733 - sbi->options = NULL;
734 - }
735 -
752 + /*
753 + * The mount options stay until the sbi is freed: ->d_hash() and
754 + * ->d_compare() of a pathwalk in rcu mode read the nls table through
755 + * them.
756 + */
736 757 ntfs3_put_sbi(sbi);
737 758 }
738 759
@@ -1939,9 +1960,11 @@ static void ntfs3_kill_sb(struct super_block *sb)
1939 1960
1940 1961 kill_block_super(sb);
1941 1962
1942 - if (sbi->options)
1943 - put_mount_options(sbi->options);
1944 - ntfs3_free_sbi(sbi);
1963 + /*
1964 + * A pathwalk in rcu mode may still be in ->d_hash() or ->d_compare()
1965 + * and read the upcase table and the nls table through the sbi.
1966 + */
1967 + call_rcu(&sbi->rcu, ntfs3_free_sbi_rcu);
1945 1968 }
1946 1969
1947 1970 // clang-format off
modified fs/ocfs2/dlm/dlmcommon.h
@@ -435,6 +435,8 @@ enum {
435 435 DLM_DEREF_LOCKRES_DONE = 522,
436 436 };
437 437
438 + extern spinlock_t dlm_reco_state_lock;
439 +
438 440 struct dlm_reco_node_data
439 441 {
440 442 int state;
modified fs/ocfs2/dlm/dlmdebug.c
@@ -736,8 +736,11 @@ static int debug_state_print(struct dlm_ctxt *dlm, char *buf, int len)
736 736 buf + out, len - out);
737 737 out += scnprintf(buf + out, len - out, "\n");
738 738
739 + spin_unlock(&dlm->spinlock);
740 +
739 741 /* Recovery Node State: */
740 742 out += scnprintf(buf + out, len - out, "Recovery Node State:\n");
743 + spin_lock(&dlm_reco_state_lock);
741 744 list_for_each_entry(node, &dlm->reco.node_data, list) {
742 745 switch (node->state) {
743 746 case DLM_RECO_NODE_DATA_INIT:
@@ -769,7 +772,7 @@ static int debug_state_print(struct dlm_ctxt *dlm, char *buf, int len)
769 772 node->node_num, state);
770 773 }
771 774
772 - spin_unlock(&dlm->spinlock);
775 + spin_unlock(&dlm_reco_state_lock);
773 776
774 777 return out;
775 778 }
modified fs/ocfs2/dlm/dlmrecovery.c
@@ -80,7 +80,7 @@ static int dlm_lockres_master_requery(struct dlm_ctxt *dlm,
80 80
81 81 static u64 dlm_get_next_mig_cookie(void);
82 82
83 - static DEFINE_SPINLOCK(dlm_reco_state_lock);
83 + DEFINE_SPINLOCK(dlm_reco_state_lock);
84 84 static DEFINE_SPINLOCK(dlm_mig_cookie_lock);
85 85 static u64 dlm_mig_cookie = 1;
86 86
modified fs/overlayfs/params.c
@@ -216,6 +216,9 @@ static ssize_t ovl_parse_param_split_lowerdirs(char *str)
216 216 if (*s == '\\') {
217 217 /* keep esc chars in split lowerdir */
218 218 *d++ = *s++;
219 + /* A trailing backslash escapes nothing. */
220 + if (!*s)
221 + return -EINVAL;
219 222 } else if (*s == ':') {
220 223 bool next_colon = (*(s + 1) == ':');
221 224
modified fs/pipe.c
@@ -838,9 +838,11 @@ pipe_fasync(int fd, struct file *filp, int on)
838 838 if (filp->f_mode & FMODE_READ)
839 839 retval = fasync_helper(fd, filp, on, &pipe->fasync_readers);
840 840 if ((filp->f_mode & FMODE_WRITE) && retval >= 0) {
841 + int read_ret = retval;
842 +
841 843 retval = fasync_helper(fd, filp, on, &pipe->fasync_writers);
842 - if (retval < 0 && (filp->f_mode & FMODE_READ))
843 - /* this can happen only if on == T */
844 + /* Undo only a reader entry added by this call. */
845 + if (retval < 0 && read_ret > 0)
844 846 fasync_helper(-1, filp, 0, &pipe->fasync_readers);
845 847 }
846 848 mutex_unlock(&pipe->mutex);
modified fs/tracefs/event_inode.c
@@ -91,6 +91,14 @@ static void free_ei_rcu(struct rcu_head *rcu)
91 91 }
92 92 }
93 93
94 + /* read under eventfs_srcu and, by tracefs_d_revalidate(), in rcu pathwalk */
95 + static void free_ei_srcu(struct rcu_head *rcu)
96 + {
97 + struct eventfs_inode *ei = container_of(rcu, struct eventfs_inode, rcu);
98 +
99 + call_rcu(&ei->rcu, free_ei_rcu);
100 + }
101 +
94 102 /*
95 103 * eventfs_inode reference count management.
96 104 *
@@ -112,7 +120,7 @@ static void release_ei(struct kref *ref)
112 120 entry->release(entry->name, ei->data);
113 121 }
114 122
115 - call_srcu(&eventfs_srcu, &ei->rcu, free_ei_rcu);
123 + call_srcu(&eventfs_srcu, &ei->rcu, free_ei_srcu);
116 124 }
117 125
118 126 static inline void put_ei(struct eventfs_inode *ei)
modified fs/unicode/utf8-core.c
@@ -3,6 +3,7 @@
3 3 #include <linux/kernel.h>
4 4 #include <linux/string.h>
5 5 #include <linux/slab.h>
6 + #include <linux/rcupdate.h>
6 7 #include <linux/parser.h>
7 8 #include <linux/errno.h>
8 9 #include <linux/stringhash.h>
@@ -183,12 +184,24 @@ out_free_um:
183 184 }
184 185 EXPORT_SYMBOL(utf8_load);
185 186
187 + static void utf8_unload_rcu(struct rcu_head *head)
188 + {
189 + struct unicode_map *um = container_of(head, struct unicode_map, rcu);
190 +
191 + symbol_put(utf8_data_table);
192 + kfree(um);
193 + }
194 +
195 + /*
196 + * A pathwalk in rcu mode may still be in ->d_hash() or ->d_compare() of a
197 + * filesystem that is being torn down and read the map through its
198 + * superblock, so the map and the tables it points to have to outlive the
199 + * grace period.
200 + */
186 201 void utf8_unload(struct unicode_map *um)
187 202 {
188 - if (um) {
189 - symbol_put(utf8_data_table);
190 - kfree(um);
191 - }
203 + if (um)
204 + call_rcu(&um->rcu, utf8_unload_rcu);
192 205 }
193 206 EXPORT_SYMBOL(utf8_unload);
194 207
modified include/drm/drm_exec.h
@@ -73,13 +73,15 @@ drm_exec_obj(struct drm_exec *exec, unsigned long index)
73 73
74 74 /* Helper for drm_exec_for_each_locked_object(). Internal use only. */
75 75 #define __drm_exec_for_each_locked_object(exec, obj, __index) \
76 - for (unsigned long __index = 0; ((obj) = drm_exec_obj(exec, __index)); ++__index)
76 + for (unsigned long __index = 0; ((obj) = drm_exec_obj(exec, __index)); \
77 + ++__index)
77 78 /**
78 79 * drm_exec_for_each_locked_object - iterate over all the locked objects
79 80 * @exec: drm_exec object
80 81 * @obj: the current GEM object
81 82 *
82 - * Iterate over all the locked GEM objects inside the drm_exec object.
83 + * Iterate over all the explicitly locked GEM objects inside the drm_exec
84 + * container, except for the contended and implicit prelocked one.
83 85 */
84 86 #define drm_exec_for_each_locked_object(exec, obj) \
85 87 __drm_exec_for_each_locked_object(exec, obj, __UNIQUE_ID(drm_exec))
@@ -94,12 +96,13 @@ drm_exec_obj(struct drm_exec *exec, unsigned long index)
94 96 * @exec: drm_exec object
95 97 * @obj: the current GEM object
96 98 *
97 - * Iterate over all the locked GEM objects inside the drm_exec object in
98 - * reverse locking order. Note that the internal index may wrap around,
99 - * but that will be caught by drm_exec_obj(), returning a NULL object.
99 + * Iterate over all the explicitly locked GEM objects inside the drm_exec
100 + * container in reverse locking order. Note that the internal index may wrap
101 + * around, but that will be caught by drm_exec_obj(), returning a NULL object.
100 102 */
101 103 #define drm_exec_for_each_locked_object_reverse(exec, obj) \
102 - __drm_exec_for_each_locked_object_reverse(exec, obj, __UNIQUE_ID(drm_exec))
104 + __drm_exec_for_each_locked_object_reverse(exec, obj, \
105 + __UNIQUE_ID(drm_exec))
103 106
104 107 /**
105 108 * drm_exec_until_all_locked - loop until all GEM objects are locked
modified include/linux/fsnotify_backend.h
@@ -566,6 +566,7 @@ struct fsnotify_mark_connector {
566 566 unsigned char prio; /* Highest priority group */
567 567 #define FSNOTIFY_CONN_FLAG_IS_WATCHED 0x01
568 568 #define FSNOTIFY_CONN_FLAG_HAS_IREF 0x02
569 + #define FSNOTIFY_CONN_FLAG_DESTROYING 0x04
569 570 unsigned short flags; /* flags [lock] */
570 571 union {
571 572 /* Object pointer [lock] */
modified include/linux/pci.h
@@ -467,6 +467,7 @@ struct pci_dev {
467 467
468 468 unsigned int is_busmaster:1; /* Is busmaster */
469 469 unsigned int no_msi:1; /* May not use MSI */
470 + unsigned int no_aer_anfe:1; /* Do not unmask ANFE */
470 471 unsigned int block_cfg_access:1; /* Config space access blocked */
471 472 unsigned int broken_parity_status:1; /* Generates false positive parity */
472 473 unsigned int irq_reroute_variant:2; /* Needs IRQ rerouting variant */
modified include/linux/power_supply.h
@@ -351,6 +351,16 @@ struct power_supply {
351 351 bool removing;
352 352 atomic_t use_cnt;
353 353 struct power_supply_battery_info *battery_info;
354 + /*
355 + * Held for read while ->external_power_changed() runs, and for write by
356 + * power_supply_unregister() when it publishes @removing, so that it
357 + * waits for an in-flight callback to finish. Without this a driver's
358 + * data, typically devm-allocated on its own device, can be freed while
359 + * the callback is still using it.
360 + * Must not be shared with extensions_sem: callbacks may read their own
361 + * properties, which takes that one for read.
362 + */
363 + struct rw_semaphore epc_sem;
354 364 struct rw_semaphore extensions_sem; /* protects "extensions" */
355 365 struct list_head extensions;
356 366 #ifdef CONFIG_THERMAL
@@ -414,9 +424,9 @@ struct power_supply_vbat_ri_table {
414 424 * @charge_voltage_max_uv: maintenance charging voltage that is usually a bit
415 425 * lower than the constant_charge_voltage_max_uv. We can apply this settings
416 426 * charge_current_max_ua until we get back up to this voltage.
417 - * @safety_timer_minutes: maintenance charging safety timer, with an expiry
418 - * time in minutes. We will only use maintenance charging in this setting
419 - * for a certain amount of time, then we will first move to the next
427 + * @charge_safety_timer_minutes: maintenance charging safety timer, with an
428 + * expiry time in minutes. We will only use maintenance charging in this
429 + * setting for a certain amount of time, then we will first move to the next
420 430 * maintenance charge current and voltage pair in respective array and wait
421 431 * for the next safety timer timeout, or, if we reached the last maintencance
422 432 * charging setting, disable charging until we reach
modified include/linux/sched/signal.h
@@ -130,8 +130,8 @@ struct signal_struct {
130 130 * process will inherit a flag if they should look for a
131 131 * child_subreaper process at exit.
132 132 */
133 - unsigned int is_child_subreaper:1;
134 - unsigned int has_child_subreaper:1;
133 + bool is_child_subreaper;
134 + bool has_child_subreaper;
135 135 unsigned int autoreap:1;
136 136
137 137 #ifdef CONFIG_POSIX_TIMERS
modified include/linux/unicode.h
@@ -53,6 +53,7 @@ struct unicode_map {
53 53 unsigned int version;
54 54 const struct utf8data *ntab[UTF8_NMAX];
55 55 const struct utf8data_table *tables;
56 + struct rcu_head rcu;
56 57 };
57 58
58 59 int utf8_validate(const struct unicode_map *um, const struct qstr *str);
modified ipc/namespace.c
@@ -96,7 +96,7 @@ fail_ipc:
96 96 fail_mq_sysctls:
97 97 retire_mq_sysctls(ns);
98 98 fail_mq_mount:
99 - mntput(ns->mq_mnt);
99 + kern_unmount(ns->mq_mnt);
100 100 fail_put:
101 101 put_user_ns(ns->user_ns);
102 102 ns_common_free(ns);
modified kernel/exit.c
@@ -1729,7 +1729,7 @@ static long do_wait(struct wait_opts *wo)
1729 1729 add_wait_queue(&current->signal->wait_chldexit, &wo->child_wait);
1730 1730
1731 1731 do {
1732 - set_current_state(TASK_INTERRUPTIBLE);
1732 + set_current_state(TASK_INTERRUPTIBLE | TASK_FREEZABLE);
1733 1733 retval = __do_wait(wo);
1734 1734 if (retval != -ERESTARTSYS)
1735 1735 break;
modified kernel/fork.c
@@ -1619,7 +1619,13 @@ static int copy_exec_state(u64 clone_flags, struct task_struct *tsk)
1619 1619 return task_exec_state_copy(tsk);
1620 1620 }
1621 1621
1622 - static int copy_fs(u64 clone_flags, struct task_struct *tsk, bool umh)
1622 + enum copy_fs_flags_t {
1623 + COPY_FS_UMH = (1 << 0),
1624 + COPY_FS_IDLE = (1 << 1),
1625 + };
1626 +
1627 + static int copy_fs(u64 clone_flags, struct task_struct *tsk,
1628 + enum copy_fs_flags_t flags)
1623 1629 {
1624 1630 struct fs_struct *fs;
1625 1631
@@ -1629,19 +1635,20 @@ static int copy_fs(u64 clone_flags, struct task_struct *tsk, bool umh)
1629 1635 * filesystem state, or be started from a non-initial mount
1630 1636 * namespace.
1631 1637 */
1632 - if (umh) {
1638 + if (flags & COPY_FS_UMH) {
1633 1639 if (clone_flags & (CLONE_NEWNS | CLONE_FS))
1634 1640 return -EINVAL;
1635 1641 if (current->nsproxy->mnt_ns != &init_mnt_ns)
1636 1642 return -EINVAL;
1637 1643 fs = userspace_init_fs;
1644 + } else if (flags & COPY_FS_IDLE) {
1645 + fs = &init_fs;
1638 1646 } else {
1639 1647 fs = current->fs;
1640 1648 VFS_WARN_ON_ONCE(current->fs != current->real_fs);
1641 1649 }
1642 1650
1643 1651 if (clone_flags & CLONE_FS) {
1644 - /* tsk->fs is already what we want */
1645 1652 read_seqlock_excl(&fs->seq);
1646 1653 /* "users" and "in_exec" locked for check_unsafe_exec() */
1647 1654 if (fs->in_exec) {
@@ -1650,6 +1657,7 @@ static int copy_fs(u64 clone_flags, struct task_struct *tsk, bool umh)
1650 1657 }
1651 1658 fs->users++;
1652 1659 read_sequnlock_excl(&fs->seq);
1660 + tsk->real_fs = tsk->fs = fs;
1653 1661 return 0;
1654 1662 }
1655 1663 tsk->real_fs = tsk->fs = copy_fs_struct(fs);
@@ -2299,7 +2307,9 @@ __latent_entropy struct task_struct *copy_process(
2299 2307 retval = copy_files(clone_flags, p, args->no_files);
2300 2308 if (retval)
2301 2309 goto bad_fork_cleanup_semundo;
2302 - retval = copy_fs(clone_flags, p, args->umh);
2310 + retval = copy_fs(clone_flags, p,
2311 + (args->umh ? COPY_FS_UMH : 0) |
2312 + (args->idle ? COPY_FS_IDLE : 0));
2303 2313 if (retval)
2304 2314 goto bad_fork_cleanup_files;
2305 2315 retval = copy_sighand(clone_flags, p);
@@ -2671,7 +2681,7 @@ struct task_struct * __init fork_idle(int cpu)
2671 2681 {
2672 2682 struct task_struct *task;
2673 2683 struct kernel_clone_args args = {
2674 - .flags = CLONE_VM,
2684 + .flags = CLONE_VM | CLONE_FS,
2675 2685 .fn = &idle_dummy,
2676 2686 .fn_arg = NULL,
2677 2687 .kthread = 1,
modified kernel/pid_namespace.c
@@ -268,7 +268,7 @@ void zap_pid_ns_processes(struct pid_namespace *pid_ns)
268 268 * free_pid() will awaken this task.
269 269 */
270 270 for (;;) {
271 - set_current_state(TASK_INTERRUPTIBLE);
271 + set_current_state(TASK_IDLE | TASK_FREEZABLE);
272 272 if (pid_ns->pid_allocated == init_pids)
273 273 break;
274 274 schedule();
modified kernel/printk/nbcon.c
@@ -2005,7 +2005,8 @@ void nbcon_kdb_release(struct nbcon_write_context *wctxt)
2005 2005 }
2006 2006
2007 2007 /**
2008 - * nbcon_is_braille - Checks whether the nbcon write context is using Braille console
2008 + * nbcon_write_context_is_braille - Checks whether the nbcon write context
2009 + * is using Braille console
2009 2010 *
2010 2011 * @wctxt: checked nbcon write context
2011 2012 *
modified kernel/printk/printk.c
@@ -3862,7 +3862,7 @@ static int __init printk_set_kthreads_ready(void)
3862 3862
3863 3863 return 0;
3864 3864 }
3865 - early_initcall(printk_set_kthreads_ready);
3865 + subsys_initcall(printk_set_kthreads_ready);
3866 3866 #endif /* CONFIG_PRINTK */
3867 3867
3868 3868 static int __read_mostly keep_bootcon;
modified kernel/reboot.c
@@ -8,6 +8,7 @@
8 8 #define pr_fmt(fmt) "reboot: " fmt
9 9
10 10 #include <linux/atomic.h>
11 + #include <linux/console.h>
11 12 #include <linux/ctype.h>
12 13 #include <linux/export.h>
13 14 #include <linux/kexec.h>
@@ -94,6 +95,14 @@ void emergency_restart(void)
94 95 {
95 96 kmsg_dump(KMSG_DUMP_EMERG);
96 97 system_state = SYSTEM_RESTART;
98 +
99 + /*
100 + * NBCON kthreads won't be flushed and stopped properly in
101 + * the emergency restart. Move them to the atomic mode.
102 + */
103 + nbcon_cpu_emergency_enter();
104 + printk_trigger_flush();
105 +
97 106 machine_emergency_restart();
98 107 }
99 108 EXPORT_SYMBOL_GPL(emergency_restart);
modified kernel/sched/ext/ext.c
@@ -1149,6 +1149,10 @@ void schedule_dsq_reenq(struct scx_sched *sch, struct scx_dispatch_q *dsq,
1149 1149
1150 1150 guard(raw_spinlock_irqsave)(&rq->scx.deferred_reenq_lock);
1151 1151
1152 + /* @dsq is being destroyed, see free_dsq_irq_workfn() */
1153 + if (unlikely(READ_ONCE(dsq->id) == SCX_DSQ_INVALID))
1154 + return;
1155 +
1152 1156 if (list_empty(&dru->node))
1153 1157 list_move_tail(&dru->node, &rq->scx.deferred_reenq_users);
1154 1158 WRITE_ONCE(dru->flags, dru->flags | reenq_flags);
@@ -2403,11 +2407,14 @@ static void wakeup_preempt_scx(struct rq *rq, struct task_struct *p, int wake_fl
2403 2407 void scx_move_local_task_to_local_dsq(struct scx_sched *sch, struct task_struct *p,
2404 2408 u64 enq_flags, struct rq *dst_rq)
2405 2409 {
2406 - struct scx_dispatch_q *dst_dsq = scx_resolve_local_dsq(sch, dst_rq, p, &enq_flags);
2410 + struct scx_dispatch_q *dst_dsq;
2407 2411
2408 2412 lockdep_assert_rq_held(dst_rq);
2409 2413
2410 2414 WARN_ON_ONCE(p->scx.holding_cpu >= 0);
2415 + scx_wait_dispatching(p);
2416 +
2417 + dst_dsq = scx_resolve_local_dsq(sch, dst_rq, p, &enq_flags);
2411 2418
2412 2419 if (enq_flags & (SCX_ENQ_HEAD | SCX_ENQ_PREEMPT))
2413 2420 dsq_insert_head(dst_dsq, p);
@@ -2587,8 +2594,12 @@ static bool unlink_dsq_and_switch_rq_lock(struct task_struct *p,
2587 2594 switch_rq_lock(locked_rq, src_rq);
2588 2595
2589 2596 /* task_rq couldn't have changed if we're still the holding cpu */
2590 - return likely(p->scx.holding_cpu == cpu) &&
2591 - !WARN_ON_ONCE(src_rq != task_rq(p));
2597 + if (likely(p->scx.holding_cpu == cpu) && !WARN_ON_ONCE(src_rq != task_rq(p))) {
2598 + scx_wait_dispatching(p);
2599 + return true;
2600 + }
2601 +
2602 + return false;
2592 2603 }
2593 2604
2594 2605 static bool consume_remote_task(struct scx_sched *sch, struct rq *this_rq,
@@ -2631,6 +2642,8 @@ static struct rq *move_task_between_dsqs(struct scx_sched *sch,
2631 2642 lockdep_assert_held(&src_dsq->lock);
2632 2643 lockdep_assert_rq_held(src_rq);
2633 2644
2645 + scx_wait_dispatching(p);
2646 +
2634 2647 if (dst_dsq->id == SCX_DSQ_LOCAL) {
2635 2648 dst_rq = container_of(dst_dsq, struct rq, scx.local_dsq);
2636 2649 if (src_rq != dst_rq &&
@@ -3213,8 +3226,7 @@ static void put_prev_task_scx(struct rq *rq, struct task_struct *p,
3213 3226 /*
3214 3227 * If @p is runnable but we're about to enter a lower
3215 3228 * sched_class, %SCX_OPS_ENQ_LAST must be set. Tell
3216 - * ops.enqueue() that @p is the only one available for this cpu,
3217 - * which should trigger an explicit follow-up scheduling event.
3229 + * ops.enqueue() that @p is the only one available for this cpu.
3218 3230 * This doesn't apply if the baseline access on the CPU is lost.
3219 3231 *
3220 3232 * Under core scheduling, a pick dispatches only when nothing is
@@ -3226,6 +3238,16 @@ static void put_prev_task_scx(struct rq *rq, struct task_struct *p,
3226 3238 WARN_ON_ONCE(!sched_core_enabled(rq) &&
3227 3239 !(sch->ops.flags & SCX_OPS_ENQ_LAST));
3228 3240 scx_do_enqueue_task(rq, p, SCX_ENQ_LAST, -1);
3241 +
3242 + /*
3243 + * A task put on the local DSQ runs, as anywhere else.
3244 + * Here the insert can't reschedule on its own: the pick
3245 + * has settled on @next and @p is still curr, so
3246 + * resched_curr() would flag @p and __schedule() clears
3247 + * that right after the pick. Flag @next instead.
3248 + */
3249 + if (p->scx.dsq == &rq->scx.local_dsq)
3250 + set_tsk_need_resched(next);
3229 3251 } else {
3230 3252 scx_do_enqueue_task(rq, p, 0, -1);
3231 3253 }
@@ -4470,11 +4492,12 @@ static bool local_task_should_reenq(struct rq *rq, struct task_struct *p,
4470 4492 }
4471 4493
4472 4494 /*
4473 - * The dispatcher stores the final ops_state after dropping the DSQ lock, so @p
4474 - * can be found on a DSQ while still %SCX_OPSS_DISPATCHING. Reenqueueing @p
4475 - * before that store lands would have it clobber the new %SCX_OPSS_QUEUED.
4495 + * The dispatcher runs ops.dequeue() and stores the final ops_state after
4496 + * dropping the DSQ lock, so @p can be found on a DSQ while still
4497 + * %SCX_OPSS_DISPATCHING. Wait for the dispatch to finish before operating on
4498 + * @p.
4476 4499 */
4477 - void scx_reenq_wait_dispatching(struct task_struct *p)
4500 + void scx_wait_dispatching(struct task_struct *p)
4478 4501 {
4479 4502 if (unlikely(atomic_long_read_acquire(&p->scx.ops_state) == SCX_OPSS_DISPATCHING))
4480 4503 wait_ops_state(p, SCX_OPSS_DISPATCHING);
@@ -4523,7 +4546,7 @@ static u32 reenq_local(struct scx_sched *sch, struct rq *rq, u64 reenq_flags)
4523 4546 if (!local_task_should_reenq(rq, p, &reenq_flags, &reason))
4524 4547 continue;
4525 4548
4526 - scx_reenq_wait_dispatching(p);
4549 + scx_wait_dispatching(p);
4527 4550 scx_dispatch_dequeue(rq, p);
4528 4551
4529 4552 if (WARN_ON_ONCE(p->scx.flags & SCX_TASK_REENQ_REASON_MASK))
@@ -4647,7 +4670,7 @@ static void reenq_user(struct rq *rq, struct scx_dispatch_q *dsq, u64 reenq_flag
4647 4670 }
4648 4671
4649 4672 /* @p is on @dsq, its rq and @dsq are locked */
4650 - scx_reenq_wait_dispatching(p);
4673 + scx_wait_dispatching(p);
4651 4674 dispatch_dequeue_locked(p, dsq);
4652 4675 raw_spin_unlock(&dsq->lock);
4653 4676
@@ -5171,8 +5194,8 @@ static void exit_dsq(struct scx_dispatch_q *dsq)
5171 5194 struct rq *rq = cpu_rq(cpu);
5172 5195
5173 5196 /*
5174 - * There must have been a RCU grace period since the last
5175 - * insertion and @dsq should be off the deferred list by now.
5197 + * free_dsq_irq_workfn() cancelled the reenqs before the grace
5198 + * period and schedule_dsq_reenq() queues nothing after that.
5176 5199 */
5177 5200 if (WARN_ON_ONCE(!list_empty(&dru->node))) {
5178 5201 guard(raw_spinlock_irqsave)(&rq->scx.deferred_reenq_lock);
@@ -5196,8 +5219,26 @@ static void free_dsq_irq_workfn(struct irq_work *irq_work)
5196 5219 struct llist_node *to_free = llist_del_all(&dsqs_to_free);
5197 5220 struct scx_dispatch_q *dsq, *tmp_dsq;
5198 5221
5199 - llist_for_each_entry_safe(dsq, tmp_dsq, to_free, free_node)
5222 + llist_for_each_entry_safe(dsq, tmp_dsq, to_free, free_node) {
5223 + s32 cpu;
5224 +
5225 + /*
5226 + * Cancel pending reenqs. Only a run_deferred() that started
5227 + * before the grace period can hold one, and it keeps IRQs off,
5228 + * so the grace period waits for it. After this sweep,
5229 + * schedule_dsq_reenq() sees the invalid id under the same lock
5230 + * and queues nothing.
5231 + */
5232 + for_each_possible_cpu(cpu) {
5233 + struct scx_dsq_pcpu *pcpu = per_cpu_ptr(dsq->pcpu, cpu);
5234 + struct rq *rq = cpu_rq(cpu);
5235 +
5236 + guard(raw_spinlock_irqsave)(&rq->scx.deferred_reenq_lock);
5237 + list_del_init(&pcpu->deferred_reenq_user.node);
5238 + }
5239 +
5200 5240 call_rcu(&dsq->rcu, free_dsq_rcufn);
5241 + }
5201 5242 }
5202 5243
5203 5244 static DEFINE_IRQ_WORK(free_dsq_irq_work, free_dsq_irq_workfn);
@@ -6068,15 +6109,12 @@ static void enable_bypass_dsp(struct scx_sched *sch)
6068 6109
6069 6110 /*
6070 6111 * When a sub-sched bypasses, its tasks are queued on the bypass DSQs of
6071 - * the nearest non-bypassing ancestor or root. As enable_bypass_dsp() is
6072 - * called iff @sch is not already bypassed due to an ancestor bypassing,
6073 - * we can assume that the parent is not bypassing and thus will be the
6074 - * host of the bypass DSQs.
6075 - *
6076 - * While the situation may change in the future, the following
6077 - * guarantees that the nearest non-bypassing ancestor or root has bypass
6078 - * dispatch enabled while a descendant is bypassing, which is all that's
6079 - * required.
6112 + * the nearest non-bypassing ancestor or root. The parent hosts them
6113 + * unless it is bypassing too. Then they sit further up and the parent
6114 + * consumes only its own bypass DSQs, empty until it leaves bypass and
6115 + * becomes the host. Either way the nearest non-bypassing ancestor or
6116 + * root has bypass dispatch enabled while a descendant is bypassing,
6117 + * which is all that's required.
6080 6118 *
6081 6119 * scx_bypass_dsp_enabled() test is used to determine whether to enter
6082 6120 * the bypass dispatch handling path from both bypassing and hosting
@@ -6185,34 +6223,45 @@ void scx_bypass(struct scx_sched *sch, bool bypass)
6185 6223 struct scx_sched *pos;
6186 6224 unsigned long flags;
6187 6225 int cpu;
6226 + bool changed;
6188 6227
6189 6228 raw_spin_lock_irqsave(&scx_bypass_lock, flags);
6190 6229
6191 6230 if (bypass) {
6192 - if (!inc_bypass_depth(sch))
6193 - goto unlock;
6194 -
6195 - enable_bypass_dsp(sch);
6231 + changed = inc_bypass_depth(sch);
6232 + if (changed)
6233 + enable_bypass_dsp(sch);
6196 6234 } else {
6197 - if (!dec_bypass_depth(sch))
6198 - goto unlock;
6235 + changed = dec_bypass_depth(sch);
6199 6236 }
6200 6237
6201 6238 /*
6202 6239 * Bypass state is propagated to all descendants - an scx_sched bypasses
6203 - * if itself or any of its ancestors are in bypass mode.
6240 + * if itself or any of its ancestors are in bypass mode. A descendant's
6241 + * depth is the sum of its own bypasses and its ancestors', so every
6242 + * call propagates whether or not @sch changed state. The descendants'
6243 + * claims are released below with @sch's, after their tasks have moved.
6204 6244 */
6205 6245 raw_spin_lock(&scx_sched_lock);
6206 6246 scx_for_each_descendant_pre(pos, sch) {
6207 6247 if (pos == sch)
6208 6248 continue;
6209 - if (bypass)
6210 - inc_bypass_depth(pos);
6211 - else
6249 + if (bypass) {
6250 + if (inc_bypass_depth(pos))
6251 + enable_bypass_dsp(pos);
6252 + } else {
6212 6253 dec_bypass_depth(pos);
6254 + }
6213 6255 }
6214 6256 raw_spin_unlock(&scx_sched_lock);
6215 6257
6258 + /*
6259 + * A descendant's depth is at least @sch's, so no bypass state changed
6260 + * unless @sch's did.
6261 + */
6262 + if (!changed)
6263 + goto unlock;
6264 +
6216 6265 /*
6217 6266 * No task property is changing. We just need to make sure all currently
6218 6267 * queued tasks are re-queued according to the new scx_bypassing()
@@ -6291,8 +6340,12 @@ void scx_bypass(struct scx_sched *sch, bool bypass)
6291 6340 }
6292 6341
6293 6342 /* disarming must come after moving all tasks out of the bypass DSQs */
6294 - if (!bypass)
6295 - scx_disable_bypass_dsp(sch);
6343 + if (!bypass) {
6344 + guard(raw_spinlock)(&scx_sched_lock);
6345 + scx_for_each_descendant_pre(pos, sch)
6346 + if (!pos->bypass_depth)
6347 + scx_disable_bypass_dsp(pos);
6348 + }
6296 6349 unlock:
6297 6350 raw_spin_unlock_irqrestore(&scx_bypass_lock, flags);
6298 6351 }
modified kernel/sched/ext/idle.c
@@ -952,12 +952,43 @@ static bool is_bpf_migration_disabled(const struct task_struct *p)
952 952 return p->migration_disabled;
953 953 }
954 954
955 + static s32 select_cpu_restricted(struct task_struct *p, s32 prev_cpu,
956 + const struct cpumask *allowed, u64 flags,
957 + bool migration_disabled)
958 + {
959 + s32 cpu;
960 +
961 + if (migration_disabled)
962 + cpu = task_cpu(p);
963 + else
964 + cpu = cpumask_first(p->cpus_ptr);
965 +
966 + if (!cpumask_test_cpu(cpu, p->cpus_ptr))
967 + return -EBUSY;
968 +
969 + if (allowed && !cpumask_test_cpu(cpu, allowed))
970 + return -EBUSY;
971 +
972 + if (flags & SCX_PICK_IDLE_IN_NODE) {
973 + int node = scx_cpu_node_if_enabled(prev_cpu);
974 +
975 + if (scx_cpu_node_if_enabled(cpu) != node)
976 + return -EBUSY;
977 + }
978 +
979 + if (!scx_idle_test_and_clear_cpu(cpu))
980 + return -EBUSY;
981 +
982 + return cpu;
983 + }
984 +
955 985 static s32 select_cpu_from_kfunc(struct scx_sched *sch, struct task_struct *p,
956 986 s32 prev_cpu, u64 wake_flags,
957 987 const struct cpumask *allowed, u64 flags)
958 988 {
959 989 unsigned long irq_flags;
960 990 bool we_locked = false;
991 + bool migration_disabled;
961 992 s32 cpu;
962 993
963 994 if (!scx_cpu_valid(sch, prev_cpu, NULL))
@@ -994,20 +1025,17 @@ static s32 select_cpu_from_kfunc(struct scx_sched *sch, struct task_struct *p,
994 1025
995 1026 /*
996 1027 * This may also be called from ops.enqueue(), so we need to handle
997 - * per-CPU tasks as well. For these tasks, we can skip all idle CPU
998 - * selection optimizations and simply check whether the previously
999 - * used CPU is idle and within the allowed cpumask.
1028 + * per-CPU tasks as well. For these tasks, skip general idle CPU
1029 + * selection and validate the task's only usable CPU directly.
1000 1030 */
1001 - if (p->nr_cpus_allowed == 1 || is_bpf_migration_disabled(p)) {
1002 - if (cpumask_test_cpu(prev_cpu, allowed ?: p->cpus_ptr) &&
1003 - scx_idle_test_and_clear_cpu(prev_cpu))
1004 - cpu = prev_cpu;
1005 - else
1006 - cpu = -EBUSY;
1007 - } else {
1031 + migration_disabled = is_bpf_migration_disabled(p);
1032 +
1033 + if (p->nr_cpus_allowed == 1 || migration_disabled)
1034 + cpu = select_cpu_restricted(p, prev_cpu, allowed, flags,
1035 + migration_disabled);
1036 + else
1008 1037 cpu = scx_select_cpu_dfl(p, prev_cpu, wake_flags,
1009 1038 allowed ?: p->cpus_ptr, flags);
1010 - }
1011 1039
1012 1040 if (we_locked)
1013 1041 raw_spin_unlock_irqrestore(&p->pi_lock, irq_flags);
modified kernel/sched/ext/internal.h
@@ -1774,8 +1774,9 @@ enum scx_enq_flags {
1774 1774 * %SCX_OPS_ENQ_LAST is specified, they're ops.enqueue()'d with the
1775 1775 * %SCX_ENQ_LAST flag set.
1776 1776 *
1777 - * The BPF scheduler is responsible for triggering a follow-up
1778 - * scheduling event. Otherwise, Execution may stall.
1777 + * If the task is queued on the local DSQ of the CPU it was running on,
1778 + * it continues to run. Otherwise, the CPU goes idle. A scheduler that
1779 + * wants a full dispatch cycle on the CPU should kick it.
1779 1780 */
1780 1781 SCX_ENQ_LAST = 1LLU << 41,
1781 1782
@@ -2122,7 +2123,7 @@ void scx_kick_cpu(struct scx_sched *sch, s32 cpu, u64 flags);
2122 2123 u64 __scx_bpf_now(struct rq *rq);
2123 2124 void schedule_dsq_reenq(struct scx_sched *sch, struct scx_dispatch_q *dsq,
2124 2125 u64 reenq_flags, struct rq *locked_rq);
2125 - void scx_reenq_wait_dispatching(struct task_struct *p);
2126 + void scx_wait_dispatching(struct task_struct *p);
2126 2127 int __scx_init_task(struct scx_sched *sch, struct task_struct *p,
2127 2128 struct cgroup *cgrp, bool fork);
2128 2129 void scx_enable_task(struct scx_sched *sch, struct task_struct *p);
modified kernel/sched/ext/sub.c
@@ -797,7 +797,7 @@ void scx_reenq_reject(struct rq *rq)
797 797 if (WARN_ON_ONCE(p->migration_pending))
798 798 continue;
799 799
800 - scx_reenq_wait_dispatching(p);
800 + scx_wait_dispatching(p);
801 801 scx_dispatch_dequeue(rq, p);
802 802
803 803 if (WARN_ON_ONCE(p->scx.flags & SCX_TASK_REENQ_REASON_MASK))
modified kernel/trace/Makefile
@@ -146,11 +146,12 @@ 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 - $(shell $(NM) -u $(obj)/undefsyms_base.o 2>/dev/null | awk '{print $$2}')
149 + current_thread_info_reg \
150 + $(shell $(NM) -u $(obj)/undefsyms_base.o 2>/dev/null | awk '$$2 {print $$2}')
150 151
151 152 quiet_cmd_check_undefined = NM $<
152 153 cmd_check_undefined = \
153 - undefsyms=$$($(NM) -u $< | grep -v $(addprefix -e , $(UNDEFINED_ALLOWLIST)) || true); \
154 + undefsyms=$$($(NM) -u $< | awk '$$2 {print $$2}' | grep -v $(addprefix -e , $(UNDEFINED_ALLOWLIST)) || true); \
154 155 if [ -n "$$undefsyms" ]; then \
155 156 echo "Unexpected symbols in $<:" >&2; \
156 157 echo "$$undefsyms" >&2; \
modified kernel/trace/ring_buffer.c
@@ -2380,6 +2380,9 @@ 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 +
2383 2386 ret = seq_open(file, &rb_meta_seq_ops);
2384 2387 if (ret)
2385 2388 return ret;
@@ -2440,22 +2443,33 @@ static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,
2440 2443 unsigned long nr_pages, struct list_head *pages)
2441 2444 {
2442 2445 struct trace_buffer *buffer = cpu_buffer->buffer;
2446 + unsigned int subbuf_order = buffer->subbuf_order;
2443 2447 struct ring_buffer_cpu_meta *meta = NULL;
2444 2448 struct buffer_page *bpage, *tmp;
2445 - bool user_thread = current->mm != NULL;
2446 2449 struct ring_buffer_desc *desc = NULL;
2450 + bool user_thread = false;
2447 2451 long i;
2448 2452
2449 - /*
2450 - * Check if the available memory is there first.
2451 - * Note, si_mem_available() only gives us a rough estimate of available
2452 - * memory. It may not be accurate. But we don't care, we just want
2453 - * to prevent doing any allocation when it is obvious that it is
2454 - * not going to succeed.
2455 - */
2456 - i = si_mem_available();
2457 - if (i < nr_pages)
2458 - return -ENOMEM;
2453 + if (buffer->range_addr_start) {
2454 + meta = rb_range_meta(buffer, nr_pages, cpu_buffer->cpu);
2455 + } else if (buffer->remote) {
2456 + desc = ring_buffer_desc(buffer->remote->desc, cpu_buffer->cpu);
2457 + if (!desc || WARN_ON(desc->nr_page_va != (nr_pages + 1)))
2458 + return -EINVAL;
2459 + } else {
2460 + /*
2461 + * Check if the available memory is there first.
2462 + * Note, si_mem_available() only gives us a rough estimate of available
2463 + * memory. It may not be accurate. But we don't care, we just want
2464 + * to prevent doing any allocation when it is obvious that it is
2465 + * not going to succeed.
2466 + */
2467 + i = si_mem_available();
2468 + if (i < (nr_pages << subbuf_order))
2469 + return -ENOMEM;
2470 +
2471 + user_thread = current->mm != NULL;
2472 + }
2459 2473
2460 2474 /*
2461 2475 * If a user thread allocates too much, and si_mem_available()
@@ -2469,15 +2483,6 @@ static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,
2469 2483 if (user_thread)
2470 2484 set_current_oom_origin();
2471 2485
2472 - if (buffer->range_addr_start)
2473 - meta = rb_range_meta(buffer, nr_pages, cpu_buffer->cpu);
2474 -
2475 - if (buffer->remote) {
2476 - desc = ring_buffer_desc(buffer->remote->desc, cpu_buffer->cpu);
2477 - if (!desc || WARN_ON(desc->nr_page_va != (nr_pages + 1)))
2478 - return -EINVAL;
2479 - }
2480 -
2481 2486 for (i = 0; i < nr_pages; i++) {
2482 2487
2483 2488 bpage = alloc_cpu_page(cpu_buffer->cpu);
@@ -2513,12 +2518,11 @@ static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,
2513 2518 bpage->id = i + 1;
2514 2519 cpu_buffer->subbuf_ids[i + 1] = bpage;
2515 2520 } else {
2516 - bpage->page = alloc_cpu_data(cpu_buffer->cpu,
2517 - cpu_buffer->buffer->subbuf_order);
2521 + bpage->page = alloc_cpu_data(cpu_buffer->cpu, subbuf_order);
2518 2522 if (!bpage->page)
2519 2523 goto free_pages;
2520 2524 }
2521 - bpage->order = cpu_buffer->buffer->subbuf_order;
2525 + bpage->order = subbuf_order;
2522 2526
2523 2527 if (user_thread && fatal_signal_pending(current))
2524 2528 goto free_pages;
@@ -3627,10 +3631,8 @@ static void rb_inc_iter(struct ring_buffer_iter *iter)
3627 3631 /* Return the index into the sub-buffers for a given sub-buffer */
3628 3632 static int rb_meta_subbuf_idx(struct ring_buffer_cpu_meta *meta, void *subbuf)
3629 3633 {
3630 - void *subbuf_array;
3634 + void *subbuf_array = rb_subbufs_from_meta(meta);
3631 3635
3632 - subbuf_array = (void *)meta + sizeof(int) * meta->nr_subbufs;
3633 - subbuf_array = (void *)ALIGN((unsigned long)subbuf_array, meta->subbuf_size);
3634 3636 return (subbuf - subbuf_array) / meta->subbuf_size;
3635 3637 }
3636 3638
@@ -7997,12 +7999,8 @@ consume:
7997 7999 goto out;
7998 8000 }
7999 8001
8000 - /* Did the reader catch up with the writer? */
8001 - if (cpu_buffer->reader_page == cpu_buffer->commit_page)
8002 - goto out;
8003 -
8004 8002 reader = rb_get_reader_page(cpu_buffer);
8005 - if (WARN_ON(!reader))
8003 + if (!reader)
8006 8004 goto out;
8007 8005
8008 8006 /* Check if any events were dropped */
modified kernel/trace/trace.c
@@ -99,6 +99,12 @@ struct tracers {
99 99 struct tracer_flags *flags;
100 100 };
101 101
102 + /*
103 + * Tracers that do not define their own flags use these empty flags,
104 + * as tr->current_trace_flags must never be NULL.
105 + */
106 + static struct tracer_flags no_tracer_flags;
107 +
102 108 /*
103 109 * To prevent the comm cache from being overwritten when no
104 110 * tracing is active, only save the comm when a trace event
@@ -1318,7 +1324,12 @@ static int run_tracer_selftest(struct tracer *type)
1318 1324 tracing_reset_online_cpus(&tr->array_buffer);
1319 1325
1320 1326 tr->current_trace = type;
1321 - tr->current_trace_flags = type->flags ? : type->default_flags;
1327 + if (type->flags)
1328 + tr->current_trace_flags = type->flags;
1329 + else if (type->default_flags)
1330 + tr->current_trace_flags = type->default_flags;
1331 + else
1332 + tr->current_trace_flags = &no_tracer_flags;
1322 1333
1323 1334 #ifdef CONFIG_TRACER_MAX_TRACE
1324 1335 if (tracer_uses_snapshot(type)) {
@@ -5089,7 +5100,12 @@ int tracing_set_tracer(struct trace_array *tr, const char *buf)
5089 5100 return ret;
5090 5101 }
5091 5102
5092 - tr->current_trace_flags = t->flags ? : t->tracer->flags;
5103 + if (t->flags)
5104 + tr->current_trace_flags = t->flags;
5105 + else if (t->tracer->flags)
5106 + tr->current_trace_flags = t->tracer->flags;
5107 + else
5108 + tr->current_trace_flags = &no_tracer_flags;
5093 5109
5094 5110 if (trace->init) {
5095 5111 ret = tracer_init(trace, tr);
@@ -5881,7 +5897,7 @@ static int tracing_buffer_meta_open(struct inode *inode, struct file *filp)
5881 5897
5882 5898 ret = ring_buffer_meta_seq_init(filp, tr->array_buffer.buffer, cpu);
5883 5899 if (ret < 0)
5884 - __trace_array_put(tr);
5900 + trace_array_put(tr);
5885 5901 return ret;
5886 5902 }
5887 5903
@@ -9287,6 +9303,12 @@ static struct notifier_block trace_module_nb = {
9287 9303
9288 9304 static __init void tracer_init_tracefs_work_func(struct work_struct *work)
9289 9305 {
9306 + /*
9307 + * Do not attempt to initialize tracefs if tracing was disabled or
9308 + * failed to allocate
9309 + */
9310 + if (tracing_disabled)
9311 + return;
9290 9312
9291 9313 event_trace_init();
9292 9314
modified kernel/trace/trace_events_filter.c
@@ -482,18 +482,17 @@ predicate_parse(const char *str, int nr_parens, int nr_preds,
482 482 int len;
483 483 int N = 0;
484 484 int i;
485 -
486 - nr_preds += 2; /* For TRUE and FALSE */
485 + int nr_preds_alloc = nr_preds + 2; /* For TRUE and FALSE */
487 486
488 487 op_stack = kmalloc_objs(*op_stack, nr_parens);
489 488 if (!op_stack)
490 489 return ERR_PTR(-ENOMEM);
491 - prog_stack = kzalloc_objs(*prog_stack, nr_preds);
490 + prog_stack = kzalloc_objs(*prog_stack, nr_preds_alloc);
492 491 if (!prog_stack) {
493 492 parse_error(pe, -ENOMEM, 0);
494 493 goto out_free;
495 494 }
496 - inverts = kmalloc_array(nr_preds, sizeof(*inverts), GFP_KERNEL);
495 + inverts = kmalloc_array(nr_preds_alloc, sizeof(*inverts), GFP_KERNEL);
497 496 if (!inverts) {
498 497 parse_error(pe, -ENOMEM, 0);
499 498 goto out_free;
@@ -512,7 +511,7 @@ predicate_parse(const char *str, int nr_parens, int nr_preds,
512 511
513 512 switch (*next) {
514 513 case '(': /* #2 */
515 - if (top - op_stack > nr_parens) {
514 + if (top - op_stack >= nr_parens - 1) {
516 515 ret = -EINVAL;
517 516 goto out_free;
518 517 }
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 (u64) ilog2(roundup_pow_of_two(val));
292 + return order_base_2(val);
293 293 }
294 294
295 295 static u64 hist_field_bucket(struct hist_field *hist_field,
@@ -873,7 +873,7 @@ static u64 hist_field_timestamp(struct hist_field *hist_field,
873 873 struct hist_trigger_data *hist_data = hist_field->hist_data;
874 874 struct trace_array *tr = hist_data->event_file->tr;
875 875
876 - u64 ts = ring_buffer_event_time_stamp(buffer, rbe);
876 + u64 ts = tracing_event_time_stamp(buffer, rbe);
877 877
878 878 if (hist_data->attrs->ts_in_usecs && trace_clock_in_ns(tr))
879 879 ts = ns2usecs(ts);
@@ -2121,7 +2121,8 @@ static int init_var_ref(struct hist_field *ref_field,
2121 2121 ref_field->size = var_field->size;
2122 2122 ref_field->is_signed = var_field->is_signed;
2123 2123 ref_field->flags |= var_field->flags &
2124 - (HIST_FIELD_FL_TIMESTAMP | HIST_FIELD_FL_TIMESTAMP_USECS);
2124 + (HIST_FIELD_FL_TIMESTAMP | HIST_FIELD_FL_TIMESTAMP_USECS |
2125 + HIST_FIELD_FL_STACKTRACE);
2125 2126
2126 2127 if (system) {
2127 2128 ref_field->system = kstrdup(system, GFP_KERNEL);
@@ -3090,7 +3091,7 @@ create_field_var_hist(struct hist_trigger_data *target_hist_data,
3090 3091 key_field = hist_data->fields[i];
3091 3092 if (!first)
3092 3093 seq_buf_putc(&s, ',');
3093 - seq_buf_puts(&s, key_field->field->name);
3094 + expr_field_str(key_field, &s);
3094 3095 first = false;
3095 3096 }
3096 3097
@@ -3318,6 +3319,7 @@ static struct field_var *create_field_var(struct hist_trigger_data *hist_data,
3318 3319 ret = PTR_ERR(var);
3319 3320 goto err;
3320 3321 }
3322 + var->flags |= val->flags & HIST_FIELD_FL_STACKTRACE;
3321 3323
3322 3324 field_var = kzalloc_obj(struct field_var);
3323 3325 if (!field_var) {
@@ -3946,7 +3948,10 @@ static int check_synth_field(struct synth_event *event,
3946 3948 && field->is_dynamic)
3947 3949 return 0;
3948 3950
3949 - if (strstr(hist_field->type, "long[") && field->is_stack)
3951 + if (!!(hist_field->flags & HIST_FIELD_FL_STACKTRACE) != field->is_stack)
3952 + return -EINVAL;
3953 +
3954 + if (field->is_stack)
3950 3955 return 0;
3951 3956
3952 3957 if (strcmp(field->type, hist_field->type) != 0) {
@@ -4487,7 +4492,8 @@ static int create_var_field(struct hist_trigger_data *hist_data,
4487 4492 if (!ret && hist_data->fields[val_idx]->flags & HIST_FIELD_FL_EXECNAME)
4488 4493 update_var_execname(hist_data->fields[val_idx]);
4489 4494
4490 - if (!ret && hist_data->fields[val_idx]->flags &
4495 + if (!ret && !(hist_data->fields[val_idx]->flags & HIST_FIELD_FL_ALIAS) &&
4496 + hist_data->fields[val_idx]->flags &
4491 4497 (HIST_FIELD_FL_STRING | HIST_FIELD_FL_STACKTRACE))
4492 4498 hist_data->fields[val_idx]->var_str_idx = hist_data->n_var_str++;
4493 4499
@@ -5228,7 +5234,8 @@ static void hist_trigger_elt_update(struct hist_trigger_data *hist_data,
5228 5234 if (hist_field->flags & HIST_FIELD_FL_VAR) {
5229 5235 var_idx = hist_field->var.idx;
5230 5236
5231 - if (hist_field->flags &
5237 + if (!(hist_field->flags & HIST_FIELD_FL_ALIAS) &&
5238 + hist_field->flags &
5232 5239 (HIST_FIELD_FL_STRING | HIST_FIELD_FL_STACKTRACE)) {
5233 5240 unsigned int str_start, var_str_idx, idx;
5234 5241 char *str, *val_str;
modified kernel/trace/trace_probe.c
@@ -2287,7 +2287,6 @@ const char **traceprobe_expand_meta_args(int argc, const char *argv[],
2287 2287 int *new_argc, char *buf, int bufsize,
2288 2288 struct traceprobe_parse_context *ctx)
2289 2289 {
2290 - const struct btf_param *params = NULL;
2291 2290 int i, j, n, used, ret, args_idx = -1;
2292 2291 const char **new_argv __free(kfree) = NULL;
2293 2292
@@ -2305,7 +2304,7 @@ const char **traceprobe_expand_meta_args(int argc, const char *argv[],
2305 2304 if (args_idx != -1) {
2306 2305 /* $arg* requires BTF info */
2307 2306 trace_probe_log_err(0, NOSUP_BTFARG);
2308 - return (const char **)params;
2307 + return ERR_PTR(-EOPNOTSUPP);
2309 2308 }
2310 2309 *new_argc = argc;
2311 2310 return NULL;
modified kernel/trace/trace_snapshot.c
@@ -675,9 +675,12 @@ tracing_snapshot_write(struct file *filp, const char __user *ubuf, size_t cnt,
675 675 if (iter->cpu_file != RING_BUFFER_ALL_CPUS)
676 676 return -EINVAL;
677 677 #endif
678 - if (tr->allocated_snapshot)
678 + if (tr->allocated_snapshot) {
679 679 ret = resize_buffer_duplicate_size(&tr->snapshot_buffer,
680 680 &tr->array_buffer, iter->cpu_file);
681 + if (ret < 0)
682 + return ret;
683 + }
681 684
682 685 ret = tracing_arm_snapshot_locked(tr);
683 686 if (ret)
modified kernel/trace/undefsyms_base.c
@@ -9,6 +9,7 @@
9 9
10 10 #include <linux/atomic.h>
11 11 #include <linux/string.h>
12 + #include <asm/local.h>
12 13 #include <asm/page.h>
13 14
14 15 void undefsyms_base(void *p, int n);
@@ -18,11 +19,13 @@ static char page[PAGE_SIZE] __aligned(PAGE_SIZE);
18 19 void undefsyms_base(void *p, int n)
19 20 {
20 21 char buffer[256] = { 0 };
21 -
22 22 u32 u = 0;
23 +
23 24 memset((char * volatile)page, 8, PAGE_SIZE);
24 25 memset((char * volatile)buffer, 8, sizeof(buffer));
25 26 memcpy((void * volatile)p, buffer, sizeof(buffer));
26 27 cmpxchg((u32 * volatile)&u, 0, 8);
28 + cmpxchg((unsigned long *)p, 0, 8);
29 + local_set((local_t *)p, 8);
27 30 WARN_ON(n == 0xdeadbeef);
28 31 }
modified kernel/watch_queue.c
@@ -101,7 +101,7 @@ static bool post_one_notification(struct watch_queue *wqueue,
101 101 struct pipe_inode_info *pipe = wqueue->pipe;
102 102 struct pipe_buffer *buf;
103 103 struct page *page;
104 - unsigned int head, tail, note, offset, len;
104 + unsigned int head, tail, note, offset, len, nr_notes;
105 105 bool done = false;
106 106
107 107 spin_lock_irq(&pipe->rd_wait.lock);
@@ -111,8 +111,10 @@ static bool post_one_notification(struct watch_queue *wqueue,
111 111 if (pipe_full(head, tail, pipe->ring_size))
112 112 goto lost;
113 113
114 - note = find_first_bit(wqueue->notes_bitmap, wqueue->nr_notes);
115 - if (note >= wqueue->nr_notes)
114 + /* Pairs with the smp_store_release() in watch_queue_set_size(). */
115 + nr_notes = smp_load_acquire(&wqueue->nr_notes);
116 + note = find_first_bit(wqueue->notes_bitmap, nr_notes);
117 + if (note >= nr_notes)
116 118 goto lost;
117 119
118 120 page = wqueue->notes[note / WATCH_QUEUE_NOTES_PER_PAGE];
@@ -297,7 +299,8 @@ long watch_queue_set_size(struct pipe_inode_info *pipe, unsigned int nr_notes)
297 299 wqueue->notes = pages;
298 300 wqueue->notes_bitmap = bitmap;
299 301 wqueue->nr_pages = nr_pages;
300 - wqueue->nr_notes = nr_notes;
302 + /* Pairs with the smp_load_acquire() in post_one_notification(). */
303 + smp_store_release(&wqueue->nr_notes, nr_notes);
301 304 return 0;
302 305
303 306 error_p:
modified kernel/workqueue.c
@@ -6320,7 +6320,7 @@ bool current_is_workqueue_mem_reclaim(void)
6320 6320 {
6321 6321 struct worker *worker = current_wq_worker();
6322 6322
6323 - return worker &&
6323 + return worker && worker->current_pwq &&
6324 6324 ((worker->current_pwq->wq->flags &
6325 6325 (WQ_MEM_RECLAIM | __WQ_LEGACY)) == WQ_MEM_RECLAIM);
6326 6326 }
modified lib/crypto/arm64/poly1305-armv8.pl
@@ -375,7 +375,7 @@ poly1305_blocks_neon:
375 375 adc $h1,$h1,xzr
376 376 lsr $h2,x14,#24
377 377 adds $h1,$h1,x14,lsl#40
378 - adc $d2,$h2,xzr // can be partially reduced...
378 + adc $h2,$h2,xzr // preserve carry into top limb
379 379
380 380 ldp $d0,$d1,[$inp],#16 // load input
381 381 sub $len,$len,#16
modified lib/crypto/poly1305.c
@@ -78,7 +78,7 @@ void poly1305_final(struct poly1305_desc_ctx *desc, u8 *dst)
78 78 }
79 79
80 80 poly1305_emit(&desc->state.h, dst, desc->s);
81 - *desc = (struct poly1305_desc_ctx){};
81 + memzero_explicit(desc, sizeof(*desc));
82 82 }
83 83 EXPORT_SYMBOL(poly1305_final);
84 84
modified lib/crypto/tests/poly1305_kunit.c
@@ -55,16 +55,17 @@ static int poly1305_suite_init(struct kunit_suite *suite)
55 55 * - Using an all-one-bits r_key tests the key clamping.
56 56 * - Using an all-one-bits s_key tests carries in implementations of the
57 57 * addition mod 2**128 during finalization.
58 - * - Using all-one-bits message, and to a lesser extent r_key, tends to maximize
59 - * any intermediate accumulator values. This increases the chance of
60 - * detecting bugs that occur only in rare cases where the accumulator values
61 - * get very large, for example the bug fixed by commit 678cce4019d746da
62 - * ("crypto: x86/poly1305 - fix overflow during partial reduction").
58 + * - Using all-one-bits message and r_key results in large values for the
59 + * internal products of r_key by (accumulator + message block). This
60 + * increases the chance of detecting bugs that occur only in rare cases where
61 + * the sum of these internal products is very large, for example the bug fixed
62 + * by commit 678cce4019d7 ("crypto: x86/poly1305 - fix overflow during partial
63 + * reduction").
63 64 *
64 - * Accumulator overflow bugs may be specific to particular update lengths (in
65 - * blocks) and/or particular values of the previous acculumator. Note that the
66 - * accumulator starts at 0 which gives the lowest chance of an overflow. Thus,
67 - * a single all-one-bits test vector may be insufficient.
65 + * Bugs with the handling of large internal product sums may be specific to
66 + * particular update lengths (in blocks) and/or require that the accumulator
67 + * also have a large value. Note that the accumulator starts at 0. Thus, a
68 + * single all-one-bits test vector may be insufficient.
68 69 *
69 70 * Considering that, do the following test: continuously update a single
70 71 * Poly1305 context with all-one-bits data of varying lengths (0, 16, 32, ...,
@@ -141,10 +142,88 @@ static void test_poly1305_reduction_edge_cases(struct kunit *test)
141 142 }
142 143 }
143 144
145 + /*
146 + * Test that Poly1305 MACs are computed correctly when r_key=1, s_key=0, and the
147 + * message consists of all-ones blocks.
148 + *
149 + * With r_key=1 and s_key=0, Poly1305 degrades to the sum of the padded blocks
150 + * mod 2**130 - 5, then reduced mod 2**128. A padded all-ones block maps to
151 + * 2**128 + (2**128 - 1) = 2**129 - 1. Two such blocks sum to 2**130 - 2, which
152 + * is congruent to 3 mod 2**130 - 5. Thus, the expected MAC is just 3 *
153 + * floor(nblocks / 2), minus 1 if nblocks is odd, then reduced mod 2**128. If
154 + * nblocks == 1 this is 2**128 - 1, otherwise it's just a small integer.
155 + *
156 + * Inside the Poly1305 implementation in this case, the multiplication does
157 + * nothing and each block just adds 2**129 - 1 to the accumulator. Without the
158 + * multiplication to mix things up, this results in some interesting values
159 + * being reached where the limbs are at or near their maximum values, even after
160 + * (lazy) reduction. This can reproduce bugs that happen only in such cases.
161 + *
162 + * For example, this test case reproduces the bug fixed by commit 24f07e8c07a0
163 + * ("lib/crypto: arm64: Fix lost Poly1305 carry when resuming NEON state").
164 + *
165 + * However, reaching that bug required two consecutive updates: one with >= 8
166 + * blocks to cause NEON code to be used and leave the accumulator in base 2**26
167 + * with its limbs in a certain pattern, then one with an odd number of blocks >=
168 + * 9 to cause NEON to be used again, but first processing one block using scalar
169 + * code as a special case, triggering a conversion to base 2**64 where the carry
170 + * into the 2**128 bit was lost. To cover this and other similar edge cases
171 + * that may exist in other Poly1305 implementations, just test all possible
172 + * block-aligned splits between three poly1305_update() calls.
173 + */
174 + static void test_poly1305_split_update_carry(struct kunit *test)
175 + {
176 + static const u8 key[POLY1305_KEY_SIZE] = { 1 }; /* r_key=1, s_key=0 */
177 + /*
178 + * Use max_nblocks=66 so that it's a bit more than twice the AVX-512
179 + * threshold of 32 blocks.
180 + */
181 + const int max_nblocks = 66;
182 + u8 *data = alloc_buf(test, max_nblocks * POLY1305_BLOCK_SIZE);
183 + u8 expected_mac[POLY1305_DIGEST_SIZE];
184 + u8 actual_mac[POLY1305_DIGEST_SIZE];
185 + struct poly1305_desc_ctx ctx;
186 +
187 + KUNIT_ASSERT_LE(test, 3 * (max_nblocks / 2), U8_MAX);
188 +
189 + memset(data, 0xff, max_nblocks * POLY1305_BLOCK_SIZE);
190 +
191 + for (int nblocks = 0; nblocks <= max_nblocks; nblocks++) {
192 + size_t len = nblocks * POLY1305_BLOCK_SIZE;
193 +
194 + expected_mac[0] = 3 * (nblocks / 2) - (nblocks % 2);
195 + memset(&expected_mac[1], nblocks == 1 ? 0xff : 0,
196 + POLY1305_DIGEST_SIZE - 1);
197 + for (size_t part1_len = 0; part1_len <= len;
198 + part1_len += POLY1305_BLOCK_SIZE) {
199 + for (size_t part2_len = 0; part2_len <= len - part1_len;
200 + part2_len += POLY1305_BLOCK_SIZE) {
201 + size_t part3_len = len - part1_len - part2_len;
202 +
203 + poly1305_init(&ctx, key);
204 + poly1305_update(&ctx, data, part1_len);
205 + poly1305_update(&ctx, &data[part1_len],
206 + part2_len);
207 + poly1305_update(&ctx,
208 + &data[part1_len + part2_len],
209 + part3_len);
210 + poly1305_final(&ctx, actual_mac);
211 + KUNIT_ASSERT_MEMEQ_MSG(
212 + test, actual_mac, expected_mac,
213 + POLY1305_DIGEST_SIZE,
214 + "Failed with nblocks=%d, part1_len=%zu, part2_len=%zu, part3_len=%zu",
215 + nblocks, part1_len, part2_len,
216 + part3_len);
217 + }
218 + }
219 + }
220 + }
221 +
144 222 static struct kunit_case poly1305_test_cases[] = {
145 223 HASH_KUNIT_CASES,
146 224 KUNIT_CASE(test_poly1305_allones_keys_and_message),
147 225 KUNIT_CASE(test_poly1305_reduction_edge_cases),
226 + KUNIT_CASE(test_poly1305_split_update_carry),
148 227 KUNIT_CASE(benchmark_hash),
149 228 {},
150 229 };
modified net/ipv6/calipso.c
@@ -1318,7 +1318,7 @@ static int calipso_skbuff_setattr(struct sk_buff *skb,
1318 1318 struct ipv6hdr *ip6_hdr;
1319 1319 struct ipv6_opt_hdr *hop;
1320 1320 unsigned char buf[CALIPSO_MAX_BUFFER];
1321 - int len_delta, new_end, pad, payload;
1321 + int len_delta, new_end, pad;
1322 1322 unsigned int start, end;
1323 1323
1324 1324 ip6_hdr = ipv6_hdr(skb);
@@ -1357,8 +1357,8 @@ static int calipso_skbuff_setattr(struct sk_buff *skb,
1357 1357 sizeof(*ip6_hdr) + start);
1358 1358 skb_reset_network_header(skb);
1359 1359 ip6_hdr = ipv6_hdr(skb);
1360 - payload = ntohs(ip6_hdr->payload_len);
1361 - ip6_hdr->payload_len = htons(payload + len_delta);
1360 + /* 0 above IPV6_MAXPLEN (BIG TCP), the real length otherwise */
1361 + ipv6_set_payload_len(ip6_hdr, skb->len - sizeof(*ip6_hdr));
1362 1362 }
1363 1363
1364 1364 hop = (struct ipv6_opt_hdr *)(ip6_hdr + 1);
modified net/netlink/af_netlink.c
@@ -464,7 +464,7 @@ netlink_unlock_table(void)
464 464
465 465 struct netlink_compare_arg
466 466 {
467 - possible_net_t pnet;
467 + u64 net_cookie;
468 468 u32 portid;
469 469 };
470 470
@@ -479,14 +479,14 @@ static inline int netlink_compare(struct rhashtable_compare_arg *arg,
479 479 const struct netlink_sock *nlk = ptr;
480 480
481 481 return nlk->portid != x->portid ||
482 - !net_eq(sock_net(&nlk->sk), read_pnet(&x->pnet));
482 + sock_net(&nlk->sk)->net_cookie != x->net_cookie;
483 483 }
484 484
485 485 static void netlink_compare_arg_init(struct netlink_compare_arg *arg,
486 486 struct net *net, u32 portid)
487 487 {
488 488 memset(arg, 0, sizeof(*arg));
489 - write_pnet(&arg->pnet, net);
489 + arg->net_cookie = net->net_cookie;
490 490 arg->portid = portid;
491 491 }
492 492
@@ -1363,6 +1363,8 @@ retry:
1363 1363 if (netlink_is_kernel(sk))
1364 1364 return netlink_unicast_kernel(sk, skb, ssk);
1365 1365
1366 + skb_reset_network_header(skb);
1367 + skb_reset_mac_header(skb);
1366 1368 if (sk_filter(sk, skb)) {
1367 1369 err = skb->len;
1368 1370 kfree_skb(skb);
@@ -1497,6 +1499,8 @@ static void do_one_broadcast(struct sock *sk,
1497 1499 goto out;
1498 1500 }
1499 1501
1502 + skb_reset_network_header(p->skb2);
1503 + skb_reset_mac_header(p->skb2);
1500 1504 if (sk_filter(sk, p->skb2)) {
1501 1505 kfree_skb(p->skb2);
1502 1506 p->skb2 = NULL;
modified net/rds/rdma_transport.c
@@ -52,7 +52,7 @@ static int rds_rdma_cm_event_handler_cmn(struct rdma_cm_id *cm_id,
52 52 {
53 53 /* this can be null in the listening path */
54 54 struct rds_connection *conn = cm_id->context;
55 - struct rds_transport *trans;
55 + struct rds_transport *trans = &rds_ib_transport;
56 56 int ret = 0;
57 57 int *err;
58 58 u8 len;
@@ -60,9 +60,6 @@ static int rds_rdma_cm_event_handler_cmn(struct rdma_cm_id *cm_id,
60 60 rdsdebug("conn %p id %p handling event %u (%s)\n", conn, cm_id,
61 61 event->event, rdma_event_msg(event->event));
62 62
63 - if (cm_id->device->node_type == RDMA_NODE_IB_CA)
64 - trans = &rds_ib_transport;
65 -
66 63 /* Prevent shutdown from tearing down the connection
67 64 * while we're executing. */
68 65 if (conn) {
@@ -82,16 +79,47 @@ static int rds_rdma_cm_event_handler_cmn(struct rdma_cm_id *cm_id,
82 79
83 80 switch (event->event) {
84 81 case RDMA_CM_EVENT_CONNECT_REQUEST:
82 + /* Only the IB transport is supported, but RDS listens on
83 + * every RDMA device: reject a request that arrived on any
84 + * other kind. A non-zero return has rdma_cm destroy the
85 + * request's id, which is what we want here and only here.
86 + */
87 + if (cm_id->device->node_type != RDMA_NODE_IB_CA) {
88 + ret = 1;
89 + break;
90 + }
85 91 ret = trans->cm_handle_connect(cm_id, event, isv6);
86 92 break;
87 93
88 94 case RDMA_CM_EVENT_ADDR_RESOLVED:
89 95 if (conn) {
96 + /* The address resolved to a device RDS has no
97 + * transport for. Do not go on to resolve a route:
98 + * an iWARP route leaves cm_id->route.path_rec
99 + * unset, which the ROUTE_RESOLVED case below
100 + * dereferences. Drop the connection instead; the
101 + * id is still ic->i_cm_id, so return 0 and let the
102 + * shutdown destroy it.
103 + */
104 + if (cm_id->device->node_type != RDMA_NODE_IB_CA) {
105 + rds_conn_drop(conn);
106 + break;
107 + }
90 108 rdma_set_service_type(cm_id, conn->c_tos);
91 109 rdma_set_min_rnr_timer(cm_id, IB_RNR_TIMER_000_32);
92 - /* XXX do we need to clean up if this fails? */
93 110 ret = rdma_resolve_route(cm_id,
94 111 RDS_RDMA_RESOLVE_TIMEOUT_MS);
112 + if (ret) {
113 + /* A non-zero return has the rdma_cm destroy
114 + * the id, but it is still ic->i_cm_id, which
115 + * the connection's shutdown would then
116 + * disconnect and destroy again. Drop the
117 + * connection and keep the id for that
118 + * shutdown.
119 + */
120 + rds_conn_drop(conn);
121 + ret = 0;
122 + }
95 123 }
96 124 break;
97 125
modified net/sched/act_api.c
@@ -372,9 +372,10 @@ static int __tcf_action_put(struct tc_action *p, bool bind)
372 372 {
373 373 struct tcf_idrinfo *idrinfo = p->idrinfo;
374 374
375 - if (refcount_dec_and_mutex_lock(&p->tcfa_refcnt, &idrinfo->lock)) {
376 - if (bind)
377 - atomic_dec(&p->tcfa_bindcnt);
375 + mutex_lock(&idrinfo->lock);
376 + if (bind)
377 + atomic_dec(&p->tcfa_bindcnt);
378 + if (refcount_dec_and_test(&p->tcfa_refcnt)) {
378 379 idr_remove(&idrinfo->action_idr, p->tcfa_index);
379 380 mutex_unlock(&idrinfo->lock);
380 381
@@ -382,9 +383,7 @@ static int __tcf_action_put(struct tc_action *p, bool bind)
382 383 return 1;
383 384 }
384 385
385 - if (bind)
386 - atomic_dec(&p->tcfa_bindcnt);
387 -
386 + mutex_unlock(&idrinfo->lock);
388 387 return 0;
389 388 }
390 389
modified net/sctp/socket.c
@@ -1786,6 +1786,18 @@ static int sctp_sendmsg_check_sflags(struct sctp_association *asoc,
1786 1786 return 1;
1787 1787 }
1788 1788
1789 + static int sctp_sendmsg_check_stream(struct sctp_association *asoc,
1790 + struct sctp_sndrcvinfo *sinfo)
1791 + {
1792 + if (unlikely(sinfo->sinfo_stream >= asoc->stream.outcnt))
1793 + return -EINVAL;
1794 +
1795 + if (unlikely(!SCTP_SO(&asoc->stream, sinfo->sinfo_stream)->ext))
1796 + return sctp_stream_init_ext(&asoc->stream, sinfo->sinfo_stream);
1797 +
1798 + return 0;
1799 + }
1800 +
1789 1801 static int sctp_sendmsg_to_asoc(struct sctp_association *asoc,
1790 1802 struct msghdr *msg, size_t msg_len,
1791 1803 struct sctp_transport *transport,
@@ -1800,16 +1812,9 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc,
1800 1812 long timeo;
1801 1813 int err;
1802 1814
1803 - if (sinfo->sinfo_stream >= asoc->stream.outcnt) {
1804 - err = -EINVAL;
1815 + err = sctp_sendmsg_check_stream(asoc, sinfo);
1816 + if (err)
1805 1817 goto err;
1806 - }
1807 -
1808 - if (unlikely(!SCTP_SO(&asoc->stream, sinfo->sinfo_stream)->ext)) {
1809 - err = sctp_stream_init_ext(&asoc->stream, sinfo->sinfo_stream);
1810 - if (err)
1811 - goto err;
1812 - }
1813 1818
1814 1819 if (sp->disable_fragments && msg_len > asoc->frag_point) {
1815 1820 err = -EMSGSIZE;
@@ -1830,10 +1835,9 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc,
1830 1835 err = sctp_wait_for_sndbuf(asoc, transport, &timeo, msg_len);
1831 1836 if (err)
1832 1837 goto err;
1833 - if (unlikely(sinfo->sinfo_stream >= asoc->stream.outcnt)) {
1834 - err = -EINVAL;
1838 + err = sctp_sendmsg_check_stream(asoc, sinfo);
1839 + if (err)
1835 1840 goto err;
1836 - }
1837 1841 }
1838 1842
1839 1843 if (sctp_state(asoc, CLOSED)) {
@@ -1848,6 +1852,11 @@ static int sctp_sendmsg_to_asoc(struct sctp_association *asoc,
1848 1852 err = -ESRCH;
1849 1853 goto err;
1850 1854 }
1855 + err = sctp_sendmsg_check_stream(asoc, sinfo);
1856 + if (err) {
1857 + err = -ESRCH;
1858 + goto err;
1859 + }
1851 1860 } else {
1852 1861 wait_connect = true;
1853 1862 }
modified net/vmw_vsock/af_vsock.c
@@ -1836,23 +1836,22 @@ static int vsock_connect(struct socket *sock, struct sockaddr_unsized *addr,
1836 1836 timeout = schedule_timeout(timeout);
1837 1837 lock_sock(sk);
1838 1838
1839 - /* Connection established. Whatever happens to socket once we
1840 - * release it, that's not connect()'s concern. No need to go
1839 + /* Connection was established. Whatever happens to socket once
1840 + * we release it, that's not connect()'s concern. No need to go
1841 1841 * into signal and timeout handling. Call it a day.
1842 1842 *
1843 1843 * Note that allowing to "reset" an already established socket
1844 1844 * here is racy and insecure.
1845 1845 */
1846 - if (sk->sk_state == TCP_ESTABLISHED)
1847 - break;
1846 + if (sk->sk_state == TCP_ESTABLISHED ||
1847 + sk->sk_state == TCP_CLOSING) {
1848 + err = 0;
1849 + goto out_wait;
1850 + }
1848 1851
1849 1852 /* If connection was _not_ established and a signal/timeout came
1850 1853 * to be, we want the socket's state reset. User space may want
1851 - * to retry.
1852 - *
1853 - * sk_state != TCP_ESTABLISHED implies that socket is not on
1854 - * vsock_connected_table. We keep the binding and the transport
1855 - * assigned.
1854 + * to retry, so we keep the binding and the transport assigned.
1856 1855 */
1857 1856 if (signal_pending(current) || timeout == 0) {
1858 1857 err = timeout == 0 ? -ETIMEDOUT : sock_intr_errno(timeout);
modified samples/pidfd/Makefile
@@ -1,4 +1,4 @@
1 1 # SPDX-License-Identifier: GPL-2.0
2 - usertprogs-always-y += pidfd-metadata
2 + userprogs-always-y += pidfd-metadata
3 3
4 4 userccflags += -I usr/include
modified sound/soc/amd/yc/pci-acp6x.c
@@ -301,7 +301,7 @@ static int snd_acp6x_suspend(struct device *dev)
301 301 return ret;
302 302 }
303 303
304 - static int snd_acp6x_resume(struct device *dev)
304 + static int snd_acp6x_runtime_resume(struct device *dev)
305 305 {
306 306 struct acp6x_dev_data *adata;
307 307 int ret;
@@ -313,8 +313,42 @@ static int snd_acp6x_resume(struct device *dev)
313 313 return ret;
314 314 }
315 315
316 + static void acp6x_disable_msi_on_resume(struct pci_dev *pdev)
317 + {
318 + u16 control;
319 +
320 + if (!pdev->msi_cap)
321 + return;
322 +
323 + pci_read_config_word(pdev, pdev->msi_cap + PCI_MSI_FLAGS, &control);
324 + if (control & PCI_MSI_FLAGS_ENABLE) {
325 + dev_warn(&pdev->dev,
326 + "ACP: MSI unexpectedly enabled after resume (flags=0x%04x), disabling\n",
327 + control);
328 + control &= ~PCI_MSI_FLAGS_ENABLE;
329 + pci_write_config_word(pdev, pdev->msi_cap + PCI_MSI_FLAGS, control);
330 + }
331 + }
332 +
333 + static int snd_acp6x_resume(struct device *dev)
334 + {
335 + struct pci_dev *pdev = to_pci_dev(dev);
336 +
337 + /*
338 + * BIOS/firmware may re-enable MSI in PCI config space during
339 + * system resume even though this driver only uses legacy INTx
340 + * interrupts. If MSI is left enabled with stale address/data
341 + * registers, the device will write interrupts to a bogus address
342 + * causing IOMMU IO_PAGE_FAULT and interrupt delivery failure.
343 + * Explicitly clear the MSI Enable bit before reinitializing
344 + * the ACP hardware.
345 + */
346 + acp6x_disable_msi_on_resume(pdev);
347 + return snd_acp6x_runtime_resume(dev);
348 + }
349 +
316 350 static const struct dev_pm_ops acp6x_pm = {
317 - RUNTIME_PM_OPS(snd_acp6x_suspend, snd_acp6x_resume, NULL)
351 + RUNTIME_PM_OPS(snd_acp6x_suspend, snd_acp6x_runtime_resume, NULL)
318 352 SYSTEM_SLEEP_PM_OPS(snd_acp6x_suspend, snd_acp6x_resume)
319 353 };
320 354
modified sound/soc/codecs/cs42l52.c
@@ -290,7 +290,7 @@ static const char * const cs42l52_ng_type_text[] = {
290 290 };
291 291
292 292 static SOC_ENUM_SINGLE_DECL(ng_type_enum,
293 - CS42L52_NOISE_GATE_CTL, 6,
293 + CS42L52_NOISE_GATE_CTL, 7,
294 294 cs42l52_ng_type_text);
295 295
296 296 static const char * const left_swap_text[] = {
modified sound/soc/codecs/cs42l56.c
@@ -481,7 +481,7 @@ static const struct snd_kcontrol_new cs42l56_snd_controls[] = {
481 481 0, 0x3f, 0, 0),
482 482 SOC_SINGLE_TLV("Limiter MAX", CS42L56_LIM_THRESHOLD_CTL,
483 483 5, 0x07, 1, alc_tlv),
484 - SOC_SINGLE_TLV("Limiter Cushion", CS42L56_ALC_THRESHOLD,
484 + SOC_SINGLE_TLV("Limiter Cushion", CS42L56_LIM_THRESHOLD_CTL,
485 485 2, 0x07, 1, alc_tlv),
486 486
487 487 SOC_SINGLE("NG Switch", CS42L56_NOISE_GATE_CTL, 6, 1, 1),
modified sound/soc/codecs/max98371.c
@@ -166,7 +166,7 @@ static const struct snd_kcontrol_new max98371_snd_controls[] = {
166 166 0, (1<<MAX98371_DHT_MAX_WIDTH)-1, 0,
167 167 max98371_dht_max_gain),
168 168 SOC_SINGLE_TLV("Speaker DHT Min Volume", MAX98371_DHT_GAIN,
169 - 0, (1<<MAX98371_DHT_GAIN_WIDTH)-1, 0,
169 + 4, (1<<MAX98371_DHT_GAIN_WIDTH)-1, 0,
170 170 max98371_dht_min_gain),
171 171 SOC_SINGLE_TLV("Speaker DHT Rotation Volume", MAX98371_DHT_GAIN,
172 172 0, (1<<MAX98371_DHT_ROT_WIDTH)-1, 0,
modified sound/soc/codecs/nau8822.c
@@ -383,9 +383,9 @@ static const struct snd_kcontrol_new nau8822_snd_controls[] = {
383 383 NAU8822_REG_RIGHT_ADC_BOOST_CONTROL, 0, 7, 0, boost_tlv),
384 384
385 385 SOC_SINGLE("DAC 128x Oversampling Switch",
386 - NAU8822_REG_DAC_CONTROL, 5, 1, 0),
386 + NAU8822_REG_DAC_CONTROL, 3, 1, 0),
387 387 SOC_SINGLE("ADC 128x Oversampling Switch",
388 - NAU8822_REG_ADC_CONTROL, 5, 1, 0),
388 + NAU8822_REG_ADC_CONTROL, 3, 1, 0),
389 389 };
390 390
391 391 /* LMAIN and RMAIN Mixer */
modified sound/soc/codecs/pcm3168a.c
@@ -103,7 +103,7 @@ static SOC_ENUM_SINGLE_DECL(pcm3168a_dac_zf_func, PCM3168A_DAC_ATT_DEMP_ZF,
103 103 static const char *const pcm3168a_pol[] = { "Active High", "Active Low" };
104 104
105 105 static SOC_ENUM_SINGLE_DECL(pcm3168a_dac_zf_pol, PCM3168A_DAC_ATT_DEMP_ZF,
106 - PCM3168A_DAC_ATSPDA_SHIFT, pcm3168a_pol);
106 + PCM3168A_DAC_ZREV_SHIFT, pcm3168a_pol);
107 107
108 108 static const char *const pcm3168a_con[] = { "Differential", "Single-Ended" };
109 109
modified sound/soc/codecs/wm8978.c
@@ -255,9 +255,9 @@ static const struct snd_kcontrol_new wm8978_snd_controls[] = {
255 255
256 256 /* DAC / ADC oversampling */
257 257 SOC_SINGLE("DAC 128x Oversampling Switch", WM8978_DAC_CONTROL,
258 - 5, 1, 0),
258 + 3, 1, 0),
259 259 SOC_SINGLE("ADC 128x Oversampling Switch", WM8978_ADC_CONTROL,
260 - 5, 1, 0),
260 + 3, 1, 0),
261 261 };
262 262
263 263 /* Mixer #1: Output (OUT1, OUT2) Mixer: mix AUX, Input mixer output and DAC */
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 tools/arch/x86/include/asm/insn.h
@@ -321,7 +321,7 @@ static inline int insn_offset_immediate(struct insn *insn)
321 321 * are repeated, it cannot be used for looping over the prefixes.
322 322 */
323 323 #define for_each_insn_prefix(insn, prefix) \
324 - for (int idx = 0; idx < ARRAY_SIZE(insn->prefixes.bytes) && (prefix = insn->prefixes.bytes[idx]) != 0; idx++)
324 + for (int __i = 0; __i < ARRAY_SIZE(insn->prefixes.bytes) && (prefix = insn->prefixes.bytes[__i]) != 0; __i++)
325 325
326 326 #define POP_SS_OPCODE 0x1f
327 327 #define MOV_SREG_OPCODE 0x8e
modified tools/bootconfig/main.c
@@ -495,7 +495,8 @@ static int apply_xbc(const char *path, const char *xbc_path)
495 495 footer.size = htole32(size);
496 496 footer.csum = htole32(csum);
497 497 memcpy(footer.magic, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN);
498 - static_assert(sizeof(footer) == BOOTCONFIG_FOOTER_SIZE);
498 + static_assert(sizeof(footer) == BOOTCONFIG_FOOTER_SIZE,
499 + "bootconfig footer size mismatch");
499 500 memcpy(data + size, &footer, BOOTCONFIG_FOOTER_SIZE);
500 501
501 502 total_size = size + BOOTCONFIG_FOOTER_SIZE;
modified tools/gpio/Makefile
@@ -7,7 +7,13 @@ bindir ?= /usr/bin
7 7 # isn't set and when invoked from selftests build, where srctree
8 8 # is set to ".". building_out_of_srctree is undefined for in srctree
9 9 # builds
10 + ifeq ($(srctree),)
11 + update_srctree := 1
12 + endif
10 13 ifndef building_out_of_srctree
14 + update_srctree := 1
15 + endif
16 + ifeq ($(update_srctree),1)
11 17 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
12 18 srctree := $(patsubst %/,%,$(dir $(srctree)))
13 19 endif
modified tools/hv/hv_get_dns_info.sh
@@ -1,6 +1,6 @@
1 1 #!/bin/sh
2 2
3 - # This example script parses /etc/resolv.conf to retrive DNS information.
3 + # This example script parses /etc/resolv.conf to retrieve DNS information.
4 4 # In the interest of keeping the KVP daemon code free of distro specific
5 5 # information; the kvp daemon code invokes this external script to gather
6 6 # DNS information.
modified tools/power/x86/turbostat/turbostat.c
@@ -2034,8 +2034,11 @@ const struct dirent *pmt_diriter_begin(struct pmt_diriter_t *iter, const char *p
2034 2034 return NULL;
2035 2035
2036 2036 num_names = scandir(pmt_root_path, &iter->namelist, pmt_telemdir_filter, pmt_telemdir_sort);
2037 - if (num_names == -1)
2037 + if (num_names == -1) {
2038 + closedir(iter->dir);
2039 + iter->dir = NULL;
2038 2040 return NULL;
2041 + }
2039 2042 }
2040 2043
2041 2044 iter->current_name_idx = 0;
@@ -2063,8 +2066,10 @@ void pmt_diriter_remove(struct pmt_diriter_t *iter)
2063 2066 iter->num_names = 0;
2064 2067 iter->current_name_idx = 0;
2065 2068
2066 - closedir(iter->dir);
2067 - iter->dir = NULL;
2069 + if (iter->dir) {
2070 + closedir(iter->dir);
2071 + iter->dir = NULL;
2072 + }
2068 2073 }
2069 2074
2070 2075 unsigned int pmt_counter_get_width(const struct pmt_counter *p)
@@ -3636,7 +3641,7 @@ int format_counters(PER_THREAD_PARAMS)
3636 3641 if (p->gfx_rc6_ms == -1) { /* detect GFX counter reset */
3637 3642 outp += sprintf(outp, "%s**.**", (printed++ ? delim : ""));
3638 3643 } else {
3639 - outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), p->gfx_rc6_ms / 10.0 / interval_float);
3644 + outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), pct(p->gfx_rc6_ms / 10.0, interval_float));
3640 3645 }
3641 3646 }
3642 3647
@@ -3653,7 +3658,7 @@ int format_counters(PER_THREAD_PARAMS)
3653 3658 if (p->sam_mc6_ms == -1) { /* detect GFX counter reset */
3654 3659 outp += sprintf(outp, "%s**.**", (printed++ ? delim : ""));
3655 3660 } else {
3656 - outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), p->sam_mc6_ms / 10.0 / interval_float);
3661 + outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), pct(p->sam_mc6_ms / 10.0, interval_float));
3657 3662 }
3658 3663 }
3659 3664
@@ -5915,7 +5920,7 @@ void free_fd_msr(void)
5915 5920 if (!msr_counter_info)
5916 5921 return;
5917 5922
5918 - for (int cpu = 0; cpu < topo.max_cpu_num; ++cpu) {
5923 + for (int cpu = 0; cpu <= topo.max_cpu_num; ++cpu) {
5919 5924 if (msr_counter_info[cpu].fd_perf != -1)
5920 5925 close(msr_counter_info[cpu].fd_perf);
5921 5926 }
@@ -6311,33 +6316,35 @@ int for_all_proc_cpus(int (func) (int))
6311 6316
6312 6317 #define PATH_EFFECTIVE_CPUS "/sys/fs/cgroup/cpuset.cpus.effective"
6313 6318
6314 - static char cpu_effective_str[1024];
6319 + static char *cpu_effective_str;
6315 6320
6316 6321 static int update_effective_str(bool startup)
6317 6322 {
6318 6323 FILE *fp;
6319 - char *pos;
6320 - char buf[1024];
6324 + char *buf = NULL;
6325 + size_t size = 0;
6321 6326 int ret;
6322 6327
6323 - if (cpu_effective_str[0] == '\0' && !startup)
6328 + if (!cpu_effective_str && !startup)
6324 6329 return 0;
6325 6330
6326 6331 fp = fopen(PATH_EFFECTIVE_CPUS, "r");
6327 6332 if (!fp)
6328 6333 return 0;
6329 6334
6330 - pos = fgets(buf, 1024, fp);
6331 - if (!pos)
6335 + if (getline(&buf, &size, fp) < 0)
6332 6336 err(1, "%s: file read failed", PATH_EFFECTIVE_CPUS);
6333 6337
6334 6338 fclose(fp);
6335 6339
6336 - ret = strncmp(cpu_effective_str, buf, 1024);
6337 - if (!ret)
6340 + ret = cpu_effective_str ? strcmp(cpu_effective_str, buf) : 1;
6341 + if (!ret) {
6342 + free(buf);
6338 6343 return 0;
6344 + }
6339 6345
6340 - strncpy(cpu_effective_str, buf, 1024);
6346 + free(cpu_effective_str);
6347 + cpu_effective_str = buf;
6341 6348 return 1;
6342 6349 }
6343 6350
@@ -8529,13 +8536,16 @@ end:
8529 8536 return ret;
8530 8537 }
8531 8538
8532 - char cpuset_buf[1024];
8533 - int initialize_cpu_set_from_sysfs(cpu_set_t *cpu_set, char *sysfs_path, char *sysfs_file)
8539 + int initialize_cpu_set_from_sysfs(cpu_set_t *cpu_set, const char *sysfs_path,
8540 + const char *sysfs_file)
8534 8541 {
8535 8542 FILE *fp;
8543 + char *cpuset_buf = NULL;
8544 + size_t size = 0;
8536 8545 char path[128];
8546 + int ret = -1;
8537 8547
8538 - if (snprintf(path, 128, "%s/%s", sysfs_path, sysfs_file) > 128)
8548 + if (snprintf(path, sizeof(path), "%s/%s", sysfs_path, sysfs_file) >= (int)sizeof(path))
8539 8549 err(-1, "%s %s", sysfs_path, sysfs_file);
8540 8550
8541 8551 fp = fopen(path, "r");
@@ -8543,19 +8553,20 @@ int initialize_cpu_set_from_sysfs(cpu_set_t *cpu_set, char *sysfs_path, char *sy
8543 8553 warn("open %s", path);
8544 8554 return -1;
8545 8555 }
8546 - if (fread(cpuset_buf, sizeof(char), 1024, fp) == 0) {
8556 + if (getline(&cpuset_buf, &size, fp) < 0) {
8547 8557 warn("read %s", sysfs_path);
8548 - goto err;
8558 + goto out;
8549 8559 }
8550 8560 if (parse_cpu_str(cpuset_buf, cpu_set, cpu_possible_setsize)) {
8551 - warnx("%s: cpu str malformat %s\n", sysfs_path, cpu_effective_str);
8552 - goto err;
8561 + warnx("%s: cpu str malformat %s\n", sysfs_path, cpuset_buf);
8562 + goto out;
8553 8563 }
8554 - return 0;
8564 + ret = 0;
8555 8565
8556 - err:
8566 + out:
8557 8567 fclose(fp);
8558 - return -1;
8568 + free(cpuset_buf);
8569 + return ret;
8559 8570 }
8560 8571
8561 8572 void print_cpu_set(char *s, cpu_set_t *set)
@@ -8655,6 +8666,8 @@ void rapl_perf_init(void)
8655 8666 {
8656 8667 const unsigned int num_domains = get_rapl_num_domains();
8657 8668 bool *domain_visited = calloc(num_domains, sizeof(bool));
8669 + if (!domain_visited)
8670 + err(-1, "calloc domain_visited");
8658 8671
8659 8672 rapl_counter_info_perdomain = calloc(num_domains, sizeof(*rapl_counter_info_perdomain));
8660 8673 if (rapl_counter_info_perdomain == NULL)
@@ -9471,8 +9484,10 @@ void perf_l2_init(void)
9471 9484 free_fd_l2_percpu();
9472 9485 return;
9473 9486 }
9474 - } else
9475 - err(-1, "%s: cpu%d: type %d", __func__, cpu, cpus[cpu].type);
9487 + } else {
9488 + warn("%s: cpu%d: type %d: Update kernel perf support or use \"--hide L2MRPS,L2%%hit\" or \"--hide cache\" or \"--no-perf\"", __func__, cpu, cpus[cpu].type);
9489 + return;
9490 + }
9476 9491 }
9477 9492 BIC_PRESENT(BIC_L2_MRPS);
9478 9493 BIC_PRESENT(BIC_L2_HIT);
@@ -9999,6 +10014,8 @@ int added_perf_counters_init_(struct perf_counter_info *pinfo)
9999 10014 const size_t max_num_domains = MAX(topo.max_cpu_num + 1, MAX(topo.max_core_id + 1, topo.max_package_id + 1));
10000 10015
10001 10016 domain_visited = calloc(max_num_domains, sizeof(*domain_visited));
10017 + if (!domain_visited)
10018 + errx(1, "%s: alloc %s", __func__, "domain_visited");
10002 10019
10003 10020 while (pinfo) {
10004 10021 switch (pinfo->scope) {
@@ -10390,6 +10407,8 @@ int pmt_add_counter(unsigned int guid, unsigned int seq, const char *name, enum
10390 10407 pcounter = pmt_find_counter(*pmt_root, name);
10391 10408 if (!pcounter) {
10392 10409 pcounter = calloc(1, sizeof(*pcounter));
10410 + if (!pcounter)
10411 + return 1;
10393 10412 new_counter = true;
10394 10413 }
10395 10414
@@ -10439,7 +10458,7 @@ void pmt_init(void)
10439 10458 mod_num = 0; /* Relative module number for current PMT file. */
10440 10459
10441 10460 /* Open the counter for each CPU. */
10442 - for (cpu_num = 0; cpu_num < topo.max_cpu_num;) {
10461 + for (cpu_num = 0; cpu_num <= topo.max_cpu_num;) {
10443 10462
10444 10463 if (cpu_is_not_allowed(cpu_num))
10445 10464 goto next_loop_iter;
@@ -10608,7 +10627,7 @@ int get_and_dump_counters(void)
10608 10627
10609 10628 void print_version()
10610 10629 {
10611 - fprintf(outf, "turbostat version 2026.04.21 - Len Brown <lenb@kernel.org>\n");
10630 + fprintf(outf, "turbostat version 2026.09.28 - Len Brown <lenb@kernel.org>\n");
10612 10631 }
10613 10632
10614 10633 #define COMMAND_LINE_SIZE 2048
@@ -10668,10 +10687,11 @@ int add_counter(unsigned int msr_num, char *path, char *name,
10668 10687 fprintf(stderr, "%s: %s FOUND\n", __func__, name);
10669 10688 break;
10670 10689 }
10671 - if (sys.added_thread_counters++ >= MAX_ADDED_THREAD_COUNTERS) {
10690 + if (sys.added_thread_counters >= MAX_ADDED_THREAD_COUNTERS) {
10672 10691 warnx("ignoring thread counter %s", name);
10673 10692 return -1;
10674 10693 }
10694 + sys.added_thread_counters++;
10675 10695 break;
10676 10696 case SCOPE_CORE:
10677 10697 msrp = find_msrp_by_name(sys.cp, name);
@@ -10680,10 +10700,11 @@ int add_counter(unsigned int msr_num, char *path, char *name,
10680 10700 fprintf(stderr, "%s: %s FOUND\n", __func__, name);
10681 10701 break;
10682 10702 }
10683 - if (sys.added_core_counters++ >= MAX_ADDED_CORE_COUNTERS) {
10703 + if (sys.added_core_counters >= MAX_ADDED_CORE_COUNTERS) {
10684 10704 warnx("ignoring core counter %s", name);
10685 10705 return -1;
10686 10706 }
10707 + sys.added_core_counters++;
10687 10708 break;
10688 10709 case SCOPE_PACKAGE:
10689 10710 msrp = find_msrp_by_name(sys.pp, name);
@@ -10692,10 +10713,11 @@ int add_counter(unsigned int msr_num, char *path, char *name,
10692 10713 fprintf(stderr, "%s: %s FOUND\n", __func__, name);
10693 10714 break;
10694 10715 }
10695 - if (sys.added_package_counters++ >= MAX_ADDED_PACKAGE_COUNTERS) {
10716 + if (sys.added_package_counters >= MAX_ADDED_PACKAGE_COUNTERS) {
10696 10717 warnx("ignoring package counter %s", name);
10697 10718 return -1;
10698 10719 }
10720 + sys.added_package_counters++;
10699 10721 break;
10700 10722 default:
10701 10723 warnx("ignoring counter %s with unknown scope", name);
modified tools/testing/selftests/filesystems/umount_propagation/locked_mount_test.c
@@ -9,6 +9,8 @@
9 9 #include <errno.h>
10 10 #include <fcntl.h>
11 11 #include <sched.h>
12 + #include <stdbool.h>
13 + #include <signal.h>
12 14 #include <stdio.h>
13 15 #include <stdlib.h>
14 16 #include <string.h>
@@ -27,6 +29,12 @@
27 29 #ifndef MOVE_MOUNT_BENEATH
28 30 #define MOVE_MOUNT_BENEATH 0x00000200
29 31 #endif
32 + #ifndef OPEN_TREE_CLONE
33 + #define OPEN_TREE_CLONE 1
34 + #endif
35 + #ifndef OPEN_TREE_CLOEXEC
36 + #define OPEN_TREE_CLOEXEC O_CLOEXEC
37 + #endif
30 38
31 39 #define DIR_LEN 64
32 40 #define PATH_LEN 192
@@ -120,6 +128,35 @@ static bool covered(const char *path)
120 128 return fd < 0;
121 129 }
122 130
131 + /* What @path reads, "" if it can't be read. */
132 + static int read_word(const char *path, char *buf, size_t len)
133 + {
134 + ssize_t n = 0;
135 + int fd;
136 +
137 + fd = open(path, O_RDONLY | O_CLOEXEC);
138 + if (fd >= 0) {
139 + n = read(fd, buf, len - 1);
140 + close(fd);
141 + }
142 + buf[n > 0 ? n : 0] = 0;
143 + return fd < 0 ? -1 : 0;
144 + }
145 +
146 + /* Put a clone of the mount at @src beneath the top mount at @where. */
147 + static int move_beneath(const char *src, const char *where)
148 + {
149 + int fd, ret;
150 +
151 + fd = syscall(__NR_open_tree, AT_FDCWD, src, OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC);
152 + if (fd < 0)
153 + return -1;
154 + ret = syscall(__NR_move_mount, fd, "", AT_FDCWD, where,
155 + MOVE_MOUNT_F_EMPTY_PATH | MOVE_MOUNT_BENEATH);
156 + close(fd);
157 + return ret;
158 + }
159 +
123 160 FIXTURE(locked_mount) {
124 161 char base[DIR_LEN];
125 162 bool tracing; /* debugfs with the tracefs automount is there */
@@ -429,4 +466,89 @@ TEST_F(locked_mount, propagated_copy_keeps_the_cover_locked)
429 466 EXPECT_EQ(ret, CHILD_OK);
430 467 }
431 468
469 + /*
470 + * A mount of a mount namespace file is left out of the copy that
471 + * unshare(CLONE_NEWNS) makes, together with everything mounted on it, so
472 + * it can't take over the lock of a cover it is moved beneath. The child
473 + * tries just that with the namespace file of a grandchild and gets EINVAL.
474 + * A bind of an ordinary file takes the lock over, and the file is still
475 + * covered in the next copy of the mount namespace.
476 + */
477 + static int ns_file_child(const char *base)
478 + {
479 + char secret[PATH_LEN], mine[PATH_LEN], nsfile[PATH_LEN], buf[32];
480 + int ret = CHILD_OK, pfd[2];
481 + pid_t pid;
482 +
483 + snprintf(secret, sizeof(secret), "%s/P/secret", base);
484 + snprintf(mine, sizeof(mine), "%s/mine", base);
485 +
486 + if (enter_userns() || pipe(pfd))
487 + return CHILD_SETUP;
488 + /* the cover is locked */
489 + if (!umount2(secret, 0) || errno != EINVAL)
490 + return CHILD_STEP1;
491 +
492 + /* a mount namespace newer than our own, so that a bind of it is allowed */
493 + pid = fork();
494 + if (pid < 0)
495 + return CHILD_SETUP;
496 + if (pid == 0) {
497 + if (unshare(CLONE_NEWNS) || send_byte(pfd[1]))
498 + _exit(1);
499 + pause();
500 + _exit(0);
501 + }
502 + if (wait_byte(pfd[0]))
503 + return CHILD_SETUP;
504 + snprintf(nsfile, sizeof(nsfile), "/proc/%d/ns/mnt", pid);
505 + if (!move_beneath(nsfile, secret) || errno != EINVAL)
506 + ret = CHILD_STEP2;
507 + kill(pid, SIGKILL);
508 + waitpid(pid, NULL, 0);
509 + if (ret)
510 + return ret;
511 +
512 + /* an ordinary file beneath the cover takes the lock over */
513 + if (move_beneath(mine, secret))
514 + return CHILD_STEP3;
515 + if (umount2(secret, 0))
516 + return CHILD_STEP3;
517 + if (!umount2(secret, 0) || errno != EINVAL)
518 + return CHILD_STEP3;
519 + /* and it is in the next copy of the namespace */
520 + if (unshare(CLONE_NEWNS))
521 + return CHILD_SETUP;
522 + if (read_word(secret, buf, sizeof(buf)) || strcmp(buf, "mine"))
523 + return CHILD_STEP4;
524 + return CHILD_OK;
525 + }
526 +
527 + TEST_F(locked_mount, mount_namespace_file_cant_take_the_lock)
528 + {
529 + char p[PATH_LEN], q[PATH_LEN];
530 + pid_t pid;
531 + int ret;
532 +
533 + snprintf(p, sizeof(p), "%s/P", self->base);
534 + ASSERT_EQ(mkdir(p, 0755), 0);
535 + ASSERT_EQ(mount("tmpfs", p, "tmpfs", 0, "mode=0755"), 0);
536 + snprintf(p, sizeof(p), "%s/P/secret", self->base);
537 + ASSERT_EQ(create_file(p, "covered-by-root\n"), 0);
538 + snprintf(q, sizeof(q), "%s/P/empty", self->base);
539 + ASSERT_EQ(create_file(q, ""), 0);
540 + /* the cover: an empty file over the secret */
541 + ASSERT_EQ(mount(q, p, NULL, MS_BIND, NULL), 0);
542 + snprintf(q, sizeof(q), "%s/mine", self->base);
543 + ASSERT_EQ(create_file(q, "mine"), 0);
544 +
545 + pid = fork();
546 + ASSERT_GE(pid, 0);
547 + if (pid == 0)
548 + _exit(ns_file_child(self->base));
549 + ret = wait_child(pid);
550 + TH_LOG("child exit code %d", ret);
551 + EXPECT_EQ(ret, CHILD_OK);
552 + }
553 +
432 554 TEST_HARNESS_MAIN