Gentoo Archives: gentoo-commits

From: Mike Pagano <mpagano@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/linux-patches:5.4 commit in: /
Date: Wed, 28 Sep 2022 09:27:01
Message-Id: 1664357203.5d7cccc1dc9c15cd82804ef6615b4a6632d20205.mpagano@gentoo
1 commit: 5d7cccc1dc9c15cd82804ef6615b4a6632d20205
2 Author: Mike Pagano <mpagano <AT> gentoo <DOT> org>
3 AuthorDate: Wed Sep 28 09:26:43 2022 +0000
4 Commit: Mike Pagano <mpagano <AT> gentoo <DOT> org>
5 CommitDate: Wed Sep 28 09:26:43 2022 +0000
6 URL: https://gitweb.gentoo.org/proj/linux-patches.git/commit/?id=5d7cccc1
7
8 Linux patch 5.4.215
9
10 Signed-off-by: Mike Pagano <mpagano <AT> gentoo.org>
11
12 0000_README | 4 +
13 1214_linux-5.4.215.patch | 4028 ++++++++++++++++++++++++++++++++++++++++++++++
14 2 files changed, 4032 insertions(+)
15
16 diff --git a/0000_README b/0000_README
17 index 4de883be..a97a10dc 100644
18 --- a/0000_README
19 +++ b/0000_README
20 @@ -899,6 +899,10 @@ Patch: 1213_linux-5.4.214.patch
21 From: http://www.kernel.org
22 Desc: Linux 5.4.214
23
24 +Patch: 1214_linux-5.4.215.patch
25 +From: http://www.kernel.org
26 +Desc: Linux 5.4.215
27 +
28 Patch: 1500_XATTR_USER_PREFIX.patch
29 From: https://bugs.gentoo.org/show_bug.cgi?id=470644
30 Desc: Support for namespace user.pax.* on tmpfs.
31
32 diff --git a/1214_linux-5.4.215.patch b/1214_linux-5.4.215.patch
33 new file mode 100644
34 index 00000000..4036c8a4
35 --- /dev/null
36 +++ b/1214_linux-5.4.215.patch
37 @@ -0,0 +1,4028 @@
38 +diff --git a/MAINTAINERS b/MAINTAINERS
39 +index f45d6548a4aa8..973fcc9143d1e 100644
40 +--- a/MAINTAINERS
41 ++++ b/MAINTAINERS
42 +@@ -17864,7 +17864,8 @@ S: Supported
43 + F: sound/xen/*
44 +
45 + XFS FILESYSTEM
46 +-M: Darrick J. Wong <darrick.wong@××××××.com>
47 ++M: Chandan Babu R <chandan.babu@××××××.com>
48 ++M: Darrick J. Wong <djwong@××××××.org>
49 + M: linux-xfs@×××××××××××.org
50 + L: linux-xfs@×××××××××××.org
51 + W: http://xfs.org/
52 +diff --git a/Makefile b/Makefile
53 +index 59f34d7f6f3b2..0c501d2c6a3b0 100644
54 +--- a/Makefile
55 ++++ b/Makefile
56 +@@ -1,7 +1,7 @@
57 + # SPDX-License-Identifier: GPL-2.0
58 + VERSION = 5
59 + PATCHLEVEL = 4
60 +-SUBLEVEL = 214
61 ++SUBLEVEL = 215
62 + EXTRAVERSION =
63 + NAME = Kleptomaniac Octopus
64 +
65 +diff --git a/arch/arm64/boot/dts/rockchip/rk3399-gru-bob.dts b/arch/arm64/boot/dts/rockchip/rk3399-gru-bob.dts
66 +index a9f4d6d7d2b75..586351340da66 100644
67 +--- a/arch/arm64/boot/dts/rockchip/rk3399-gru-bob.dts
68 ++++ b/arch/arm64/boot/dts/rockchip/rk3399-gru-bob.dts
69 +@@ -77,3 +77,8 @@
70 + };
71 + };
72 + };
73 ++
74 ++&wlan_host_wake_l {
75 ++ /* Kevin has an external pull up, but Bob does not. */
76 ++ rockchip,pins = <0 RK_PB0 RK_FUNC_GPIO &pcfg_pull_up>;
77 ++};
78 +diff --git a/arch/arm64/boot/dts/rockchip/rk3399-gru-chromebook.dtsi b/arch/arm64/boot/dts/rockchip/rk3399-gru-chromebook.dtsi
79 +index 7cd6d470c1cbd..7416db3d27a77 100644
80 +--- a/arch/arm64/boot/dts/rockchip/rk3399-gru-chromebook.dtsi
81 ++++ b/arch/arm64/boot/dts/rockchip/rk3399-gru-chromebook.dtsi
82 +@@ -237,6 +237,14 @@
83 + &edp {
84 + status = "okay";
85 +
86 ++ /*
87 ++ * eDP PHY/clk don't sync reliably at anything other than 24 MHz. Only
88 ++ * set this here, because rk3399-gru.dtsi ensures we can generate this
89 ++ * off GPLL=600MHz, whereas some other RK3399 boards may not.
90 ++ */
91 ++ assigned-clocks = <&cru PCLK_EDP>;
92 ++ assigned-clock-rates = <24000000>;
93 ++
94 + ports {
95 + edp_out: port@1 {
96 + reg = <1>;
97 +@@ -397,6 +405,7 @@ ap_i2c_tp: &i2c5 {
98 + };
99 +
100 + wlan_host_wake_l: wlan-host-wake-l {
101 ++ /* Kevin has an external pull up, but Bob does not */
102 + rockchip,pins = <0 RK_PB0 RK_FUNC_GPIO &pcfg_pull_none>;
103 + };
104 + };
105 +diff --git a/arch/arm64/boot/dts/rockchip/rk3399-puma.dtsi b/arch/arm64/boot/dts/rockchip/rk3399-puma.dtsi
106 +index 390b86ec65389..365fa9a3c5bfb 100644
107 +--- a/arch/arm64/boot/dts/rockchip/rk3399-puma.dtsi
108 ++++ b/arch/arm64/boot/dts/rockchip/rk3399-puma.dtsi
109 +@@ -102,7 +102,6 @@
110 + vcc5v0_host: vcc5v0-host-regulator {
111 + compatible = "regulator-fixed";
112 + gpio = <&gpio4 RK_PA3 GPIO_ACTIVE_LOW>;
113 +- enable-active-low;
114 + pinctrl-names = "default";
115 + pinctrl-0 = <&vcc5v0_host_en>;
116 + regulator-name = "vcc5v0_host";
117 +diff --git a/arch/mips/cavium-octeon/octeon-irq.c b/arch/mips/cavium-octeon/octeon-irq.c
118 +index 3ad1f76c063a9..2d5e7b21d9600 100644
119 +--- a/arch/mips/cavium-octeon/octeon-irq.c
120 ++++ b/arch/mips/cavium-octeon/octeon-irq.c
121 +@@ -127,6 +127,16 @@ static void octeon_irq_free_cd(struct irq_domain *d, unsigned int irq)
122 + static int octeon_irq_force_ciu_mapping(struct irq_domain *domain,
123 + int irq, int line, int bit)
124 + {
125 ++ struct device_node *of_node;
126 ++ int ret;
127 ++
128 ++ of_node = irq_domain_get_of_node(domain);
129 ++ if (!of_node)
130 ++ return -EINVAL;
131 ++ ret = irq_alloc_desc_at(irq, of_node_to_nid(of_node));
132 ++ if (ret < 0)
133 ++ return ret;
134 ++
135 + return irq_domain_associate(domain, irq, line << 6 | bit);
136 + }
137 +
138 +diff --git a/arch/mips/lantiq/clk.c b/arch/mips/lantiq/clk.c
139 +index 7a623684d9b5e..2d5a0bcb0cec1 100644
140 +--- a/arch/mips/lantiq/clk.c
141 ++++ b/arch/mips/lantiq/clk.c
142 +@@ -50,6 +50,7 @@ struct clk *clk_get_io(void)
143 + {
144 + return &cpu_clk_generic[2];
145 + }
146 ++EXPORT_SYMBOL_GPL(clk_get_io);
147 +
148 + struct clk *clk_get_ppe(void)
149 + {
150 +diff --git a/arch/mips/loongson32/common/platform.c b/arch/mips/loongson32/common/platform.c
151 +index 794c96c2a4cdd..311dc1580bbde 100644
152 +--- a/arch/mips/loongson32/common/platform.c
153 ++++ b/arch/mips/loongson32/common/platform.c
154 +@@ -98,7 +98,7 @@ int ls1x_eth_mux_init(struct platform_device *pdev, void *priv)
155 + if (plat_dat->bus_id) {
156 + __raw_writel(__raw_readl(LS1X_MUX_CTRL0) | GMAC1_USE_UART1 |
157 + GMAC1_USE_UART0, LS1X_MUX_CTRL0);
158 +- switch (plat_dat->interface) {
159 ++ switch (plat_dat->phy_interface) {
160 + case PHY_INTERFACE_MODE_RGMII:
161 + val &= ~(GMAC1_USE_TXCLK | GMAC1_USE_PWM23);
162 + break;
163 +@@ -107,12 +107,12 @@ int ls1x_eth_mux_init(struct platform_device *pdev, void *priv)
164 + break;
165 + default:
166 + pr_err("unsupported mii mode %d\n",
167 +- plat_dat->interface);
168 ++ plat_dat->phy_interface);
169 + return -ENOTSUPP;
170 + }
171 + val &= ~GMAC1_SHUT;
172 + } else {
173 +- switch (plat_dat->interface) {
174 ++ switch (plat_dat->phy_interface) {
175 + case PHY_INTERFACE_MODE_RGMII:
176 + val &= ~(GMAC0_USE_TXCLK | GMAC0_USE_PWM01);
177 + break;
178 +@@ -121,7 +121,7 @@ int ls1x_eth_mux_init(struct platform_device *pdev, void *priv)
179 + break;
180 + default:
181 + pr_err("unsupported mii mode %d\n",
182 +- plat_dat->interface);
183 ++ plat_dat->phy_interface);
184 + return -ENOTSUPP;
185 + }
186 + val &= ~GMAC0_SHUT;
187 +@@ -131,7 +131,7 @@ int ls1x_eth_mux_init(struct platform_device *pdev, void *priv)
188 + plat_dat = dev_get_platdata(&pdev->dev);
189 +
190 + val &= ~PHY_INTF_SELI;
191 +- if (plat_dat->interface == PHY_INTERFACE_MODE_RMII)
192 ++ if (plat_dat->phy_interface == PHY_INTERFACE_MODE_RMII)
193 + val |= 0x4 << PHY_INTF_SELI_SHIFT;
194 + __raw_writel(val, LS1X_MUX_CTRL1);
195 +
196 +@@ -146,9 +146,9 @@ static struct plat_stmmacenet_data ls1x_eth0_pdata = {
197 + .bus_id = 0,
198 + .phy_addr = -1,
199 + #if defined(CONFIG_LOONGSON1_LS1B)
200 +- .interface = PHY_INTERFACE_MODE_MII,
201 ++ .phy_interface = PHY_INTERFACE_MODE_MII,
202 + #elif defined(CONFIG_LOONGSON1_LS1C)
203 +- .interface = PHY_INTERFACE_MODE_RMII,
204 ++ .phy_interface = PHY_INTERFACE_MODE_RMII,
205 + #endif
206 + .mdio_bus_data = &ls1x_mdio_bus_data,
207 + .dma_cfg = &ls1x_eth_dma_cfg,
208 +@@ -186,7 +186,7 @@ struct platform_device ls1x_eth0_pdev = {
209 + static struct plat_stmmacenet_data ls1x_eth1_pdata = {
210 + .bus_id = 1,
211 + .phy_addr = -1,
212 +- .interface = PHY_INTERFACE_MODE_MII,
213 ++ .phy_interface = PHY_INTERFACE_MODE_MII,
214 + .mdio_bus_data = &ls1x_mdio_bus_data,
215 + .dma_cfg = &ls1x_eth_dma_cfg,
216 + .has_gmac = 1,
217 +diff --git a/arch/x86/include/asm/cpu_entry_area.h b/arch/x86/include/asm/cpu_entry_area.h
218 +index ea866c7bf31d3..0d1d37d8b279f 100644
219 +--- a/arch/x86/include/asm/cpu_entry_area.h
220 ++++ b/arch/x86/include/asm/cpu_entry_area.h
221 +@@ -133,7 +133,7 @@ extern void cea_set_pte(void *cea_vaddr, phys_addr_t pa, pgprot_t flags);
222 +
223 + extern struct cpu_entry_area *get_cpu_entry_area(int cpu);
224 +
225 +-static inline struct entry_stack *cpu_entry_stack(int cpu)
226 ++static __always_inline struct entry_stack *cpu_entry_stack(int cpu)
227 + {
228 + return &get_cpu_entry_area(cpu)->entry_stack_page.stack;
229 + }
230 +diff --git a/drivers/firmware/efi/libstub/secureboot.c b/drivers/firmware/efi/libstub/secureboot.c
231 +index edba5e7a37437..c8a1ef872e0d9 100644
232 +--- a/drivers/firmware/efi/libstub/secureboot.c
233 ++++ b/drivers/firmware/efi/libstub/secureboot.c
234 +@@ -19,7 +19,7 @@ static const efi_char16_t efi_SetupMode_name[] = L"SetupMode";
235 +
236 + /* SHIM variables */
237 + static const efi_guid_t shim_guid = EFI_SHIM_LOCK_GUID;
238 +-static const efi_char16_t shim_MokSBState_name[] = L"MokSBState";
239 ++static const efi_char16_t shim_MokSBState_name[] = L"MokSBStateRT";
240 +
241 + #define get_efi_var(name, vendor, ...) \
242 + efi_call_runtime(get_variable, \
243 +@@ -58,8 +58,8 @@ enum efi_secureboot_mode efi_get_secureboot(efi_system_table_t *sys_table_arg)
244 +
245 + /*
246 + * See if a user has put the shim into insecure mode. If so, and if the
247 +- * variable doesn't have the runtime attribute set, we might as well
248 +- * honor that.
249 ++ * variable doesn't have the non-volatile attribute set, we might as
250 ++ * well honor that.
251 + */
252 + size = sizeof(moksbstate);
253 + status = get_efi_var(shim_MokSBState_name, &shim_guid,
254 +@@ -68,7 +68,7 @@ enum efi_secureboot_mode efi_get_secureboot(efi_system_table_t *sys_table_arg)
255 + /* If it fails, we don't care why. Default to secure */
256 + if (status != EFI_SUCCESS)
257 + goto secure_boot_enabled;
258 +- if (!(attr & EFI_VARIABLE_RUNTIME_ACCESS) && moksbstate == 1)
259 ++ if (!(attr & EFI_VARIABLE_NON_VOLATILE) && moksbstate == 1)
260 + return efi_secureboot_mode_disabled;
261 +
262 + secure_boot_enabled:
263 +diff --git a/drivers/gpio/gpio-mpc8xxx.c b/drivers/gpio/gpio-mpc8xxx.c
264 +index d72a3a5507b01..f3bf82efea8e3 100644
265 +--- a/drivers/gpio/gpio-mpc8xxx.c
266 ++++ b/drivers/gpio/gpio-mpc8xxx.c
267 +@@ -190,6 +190,7 @@ static int mpc8xxx_irq_set_type(struct irq_data *d, unsigned int flow_type)
268 +
269 + switch (flow_type) {
270 + case IRQ_TYPE_EDGE_FALLING:
271 ++ case IRQ_TYPE_LEVEL_LOW:
272 + raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
273 + gc->write_reg(mpc8xxx_gc->regs + GPIO_ICR,
274 + gc->read_reg(mpc8xxx_gc->regs + GPIO_ICR)
275 +diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
276 +index b588e0e409e72..d8687868407de 100644
277 +--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
278 ++++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_display.c
279 +@@ -35,6 +35,7 @@
280 + #include <linux/pci.h>
281 + #include <linux/pm_runtime.h>
282 + #include <drm/drm_crtc_helper.h>
283 ++#include <drm/drm_damage_helper.h>
284 + #include <drm/drm_edid.h>
285 + #include <drm/drm_gem_framebuffer_helper.h>
286 + #include <drm/drm_fb_helper.h>
287 +@@ -495,6 +496,7 @@ bool amdgpu_display_ddc_probe(struct amdgpu_connector *amdgpu_connector,
288 + static const struct drm_framebuffer_funcs amdgpu_fb_funcs = {
289 + .destroy = drm_gem_fb_destroy,
290 + .create_handle = drm_gem_fb_create_handle,
291 ++ .dirty = drm_atomic_helper_dirtyfb,
292 + };
293 +
294 + uint32_t amdgpu_display_supported_domains(struct amdgpu_device *adev,
295 +diff --git a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
296 +index e042d8ce05b4a..22d105635e338 100644
297 +--- a/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
298 ++++ b/drivers/gpu/drm/amd/display/modules/color/color_gamma.c
299 +@@ -1486,6 +1486,7 @@ static void interpolate_user_regamma(uint32_t hw_points_num,
300 + struct fixed31_32 lut2;
301 + struct fixed31_32 delta_lut;
302 + struct fixed31_32 delta_index;
303 ++ const struct fixed31_32 one = dc_fixpt_from_int(1);
304 +
305 + i = 0;
306 + /* fixed_pt library has problems handling too small values */
307 +@@ -1514,6 +1515,9 @@ static void interpolate_user_regamma(uint32_t hw_points_num,
308 + } else
309 + hw_x = coordinates_x[i].x;
310 +
311 ++ if (dc_fixpt_le(one, hw_x))
312 ++ hw_x = one;
313 ++
314 + norm_x = dc_fixpt_mul(norm_factor, hw_x);
315 + index = dc_fixpt_floor(norm_x);
316 + if (index < 0 || index > 255)
317 +diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
318 +index ed543227b00dd..53f5d0581c355 100644
319 +--- a/drivers/gpu/drm/meson/meson_plane.c
320 ++++ b/drivers/gpu/drm/meson/meson_plane.c
321 +@@ -128,7 +128,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
322 +
323 + /* Enable OSD and BLK0, set max global alpha */
324 + priv->viu.osd1_ctrl_stat = OSD_ENABLE |
325 +- (0xFF << OSD_GLOBAL_ALPHA_SHIFT) |
326 ++ (0x100 << OSD_GLOBAL_ALPHA_SHIFT) |
327 + OSD_BLK0_ENABLE;
328 +
329 + canvas_id_osd1 = priv->canvas_id_osd1;
330 +diff --git a/drivers/gpu/drm/meson/meson_viu.c b/drivers/gpu/drm/meson/meson_viu.c
331 +index 9991f0a43b1ab..8d09385259780 100644
332 +--- a/drivers/gpu/drm/meson/meson_viu.c
333 ++++ b/drivers/gpu/drm/meson/meson_viu.c
334 +@@ -91,7 +91,7 @@ static void meson_viu_set_g12a_osd1_matrix(struct meson_drm *priv,
335 + priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF11_12));
336 + writel(((m[9] & 0x1fff) << 16) | (m[10] & 0x1fff),
337 + priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF20_21));
338 +- writel((m[11] & 0x1fff) << 16,
339 ++ writel((m[11] & 0x1fff),
340 + priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF22));
341 +
342 + writel(((m[18] & 0xfff) << 16) | (m[19] & 0xfff),
343 +diff --git a/drivers/gpu/drm/rockchip/cdn-dp-core.c b/drivers/gpu/drm/rockchip/cdn-dp-core.c
344 +index 8f299d76b69b8..67dae1354aa65 100644
345 +--- a/drivers/gpu/drm/rockchip/cdn-dp-core.c
346 ++++ b/drivers/gpu/drm/rockchip/cdn-dp-core.c
347 +@@ -275,8 +275,9 @@ static int cdn_dp_connector_get_modes(struct drm_connector *connector)
348 + return ret;
349 + }
350 +
351 +-static int cdn_dp_connector_mode_valid(struct drm_connector *connector,
352 +- struct drm_display_mode *mode)
353 ++static enum drm_mode_status
354 ++cdn_dp_connector_mode_valid(struct drm_connector *connector,
355 ++ struct drm_display_mode *mode)
356 + {
357 + struct cdn_dp_device *dp = connector_to_dp(connector);
358 + struct drm_display_info *display_info = &dp->connector.display_info;
359 +diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
360 +index 56918274c48cf..d4c5efc6e157b 100644
361 +--- a/drivers/hv/vmbus_drv.c
362 ++++ b/drivers/hv/vmbus_drv.c
363 +@@ -2075,7 +2075,7 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
364 + bool fb_overlap_ok)
365 + {
366 + struct resource *iter, *shadow;
367 +- resource_size_t range_min, range_max, start;
368 ++ resource_size_t range_min, range_max, start, end;
369 + const char *dev_n = dev_name(&device_obj->device);
370 + int retval;
371 +
372 +@@ -2110,6 +2110,14 @@ int vmbus_allocate_mmio(struct resource **new, struct hv_device *device_obj,
373 + range_max = iter->end;
374 + start = (range_min + align - 1) & ~(align - 1);
375 + for (; start + size - 1 <= range_max; start += align) {
376 ++ end = start + size - 1;
377 ++
378 ++ /* Skip the whole fb_mmio region if not fb_overlap_ok */
379 ++ if (!fb_overlap_ok && fb_mmio &&
380 ++ (((start >= fb_mmio->start) && (start <= fb_mmio->end)) ||
381 ++ ((end >= fb_mmio->start) && (end <= fb_mmio->end))))
382 ++ continue;
383 ++
384 + shadow = __request_region(iter, start, size, NULL,
385 + IORESOURCE_BUSY);
386 + if (!shadow)
387 +diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
388 +index bf4ab30186aff..abd2a57b18cbb 100644
389 +--- a/drivers/net/can/usb/gs_usb.c
390 ++++ b/drivers/net/can/usb/gs_usb.c
391 +@@ -678,6 +678,7 @@ static int gs_can_open(struct net_device *netdev)
392 + flags |= GS_CAN_MODE_TRIPLE_SAMPLE;
393 +
394 + /* finally start device */
395 ++ dev->can.state = CAN_STATE_ERROR_ACTIVE;
396 + dm->mode = cpu_to_le32(GS_CAN_MODE_START);
397 + dm->flags = cpu_to_le32(flags);
398 + rc = usb_control_msg(interface_to_usbdev(dev->iface),
399 +@@ -694,13 +695,12 @@ static int gs_can_open(struct net_device *netdev)
400 + if (rc < 0) {
401 + netdev_err(netdev, "Couldn't start device (err=%d)\n", rc);
402 + kfree(dm);
403 ++ dev->can.state = CAN_STATE_STOPPED;
404 + return rc;
405 + }
406 +
407 + kfree(dm);
408 +
409 +- dev->can.state = CAN_STATE_ERROR_ACTIVE;
410 +-
411 + parent->active_channels++;
412 + if (!(dev->can.ctrlmode & CAN_CTRLMODE_LISTENONLY))
413 + netif_start_queue(netdev);
414 +diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
415 +index 2d01eaeb703af..15f177185d71d 100644
416 +--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
417 ++++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
418 +@@ -5638,6 +5638,26 @@ static int i40e_get_link_speed(struct i40e_vsi *vsi)
419 + }
420 + }
421 +
422 ++/**
423 ++ * i40e_bw_bytes_to_mbits - Convert max_tx_rate from bytes to mbits
424 ++ * @vsi: Pointer to vsi structure
425 ++ * @max_tx_rate: max TX rate in bytes to be converted into Mbits
426 ++ *
427 ++ * Helper function to convert units before send to set BW limit
428 ++ **/
429 ++static u64 i40e_bw_bytes_to_mbits(struct i40e_vsi *vsi, u64 max_tx_rate)
430 ++{
431 ++ if (max_tx_rate < I40E_BW_MBPS_DIVISOR) {
432 ++ dev_warn(&vsi->back->pdev->dev,
433 ++ "Setting max tx rate to minimum usable value of 50Mbps.\n");
434 ++ max_tx_rate = I40E_BW_CREDIT_DIVISOR;
435 ++ } else {
436 ++ do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
437 ++ }
438 ++
439 ++ return max_tx_rate;
440 ++}
441 ++
442 + /**
443 + * i40e_set_bw_limit - setup BW limit for Tx traffic based on max_tx_rate
444 + * @vsi: VSI to be configured
445 +@@ -5660,10 +5680,10 @@ int i40e_set_bw_limit(struct i40e_vsi *vsi, u16 seid, u64 max_tx_rate)
446 + max_tx_rate, seid);
447 + return -EINVAL;
448 + }
449 +- if (max_tx_rate && max_tx_rate < 50) {
450 ++ if (max_tx_rate && max_tx_rate < I40E_BW_CREDIT_DIVISOR) {
451 + dev_warn(&pf->pdev->dev,
452 + "Setting max tx rate to minimum usable value of 50Mbps.\n");
453 +- max_tx_rate = 50;
454 ++ max_tx_rate = I40E_BW_CREDIT_DIVISOR;
455 + }
456 +
457 + /* Tx rate credits are in values of 50Mbps, 0 is disabled */
458 +@@ -7591,9 +7611,9 @@ config_tc:
459 +
460 + if (pf->flags & I40E_FLAG_TC_MQPRIO) {
461 + if (vsi->mqprio_qopt.max_rate[0]) {
462 +- u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
463 ++ u64 max_tx_rate = i40e_bw_bytes_to_mbits(vsi,
464 ++ vsi->mqprio_qopt.max_rate[0]);
465 +
466 +- do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
467 + ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
468 + if (!ret) {
469 + u64 credits = max_tx_rate;
470 +@@ -10247,10 +10267,10 @@ static void i40e_rebuild(struct i40e_pf *pf, bool reinit, bool lock_acquired)
471 + }
472 +
473 + if (vsi->mqprio_qopt.max_rate[0]) {
474 +- u64 max_tx_rate = vsi->mqprio_qopt.max_rate[0];
475 ++ u64 max_tx_rate = i40e_bw_bytes_to_mbits(vsi,
476 ++ vsi->mqprio_qopt.max_rate[0]);
477 + u64 credits = 0;
478 +
479 +- do_div(max_tx_rate, I40E_BW_MBPS_DIVISOR);
480 + ret = i40e_set_bw_limit(vsi, vsi->seid, max_tx_rate);
481 + if (ret)
482 + goto end_unlock;
483 +diff --git a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
484 +index 4080fdacca4cc..16f5baafbbd52 100644
485 +--- a/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
486 ++++ b/drivers/net/ethernet/intel/i40e/i40e_virtchnl_pf.c
487 +@@ -1873,6 +1873,25 @@ static void i40e_del_qch(struct i40e_vf *vf)
488 + }
489 + }
490 +
491 ++/**
492 ++ * i40e_vc_get_max_frame_size
493 ++ * @vf: pointer to the VF
494 ++ *
495 ++ * Max frame size is determined based on the current port's max frame size and
496 ++ * whether a port VLAN is configured on this VF. The VF is not aware whether
497 ++ * it's in a port VLAN so the PF needs to account for this in max frame size
498 ++ * checks and sending the max frame size to the VF.
499 ++ **/
500 ++static u16 i40e_vc_get_max_frame_size(struct i40e_vf *vf)
501 ++{
502 ++ u16 max_frame_size = vf->pf->hw.phy.link_info.max_frame_size;
503 ++
504 ++ if (vf->port_vlan_id)
505 ++ max_frame_size -= VLAN_HLEN;
506 ++
507 ++ return max_frame_size;
508 ++}
509 ++
510 + /**
511 + * i40e_vc_get_vf_resources_msg
512 + * @vf: pointer to the VF info
513 +@@ -1973,6 +1992,7 @@ static int i40e_vc_get_vf_resources_msg(struct i40e_vf *vf, u8 *msg)
514 + vfres->max_vectors = pf->hw.func_caps.num_msix_vectors_vf;
515 + vfres->rss_key_size = I40E_HKEY_ARRAY_SIZE;
516 + vfres->rss_lut_size = I40E_VF_HLUT_ARRAY_SIZE;
517 ++ vfres->max_mtu = i40e_vc_get_max_frame_size(vf);
518 +
519 + if (vf->lan_vsi_idx) {
520 + vfres->vsi_res[0].vsi_id = vf->lan_vsi_id;
521 +diff --git a/drivers/net/ethernet/intel/iavf/iavf_txrx.c b/drivers/net/ethernet/intel/iavf/iavf_txrx.c
522 +index c6905d1b6182c..1f7b842c67638 100644
523 +--- a/drivers/net/ethernet/intel/iavf/iavf_txrx.c
524 ++++ b/drivers/net/ethernet/intel/iavf/iavf_txrx.c
525 +@@ -114,8 +114,11 @@ u32 iavf_get_tx_pending(struct iavf_ring *ring, bool in_sw)
526 + {
527 + u32 head, tail;
528 +
529 ++ /* underlying hardware might not allow access and/or always return
530 ++ * 0 for the head/tail registers so just use the cached values
531 ++ */
532 + head = ring->next_to_clean;
533 +- tail = readl(ring->tail);
534 ++ tail = ring->next_to_use;
535 +
536 + if (head != tail)
537 + return (head < tail) ?
538 +@@ -1371,7 +1374,7 @@ static struct sk_buff *iavf_build_skb(struct iavf_ring *rx_ring,
539 + #endif
540 + struct sk_buff *skb;
541 +
542 +- if (!rx_buffer)
543 ++ if (!rx_buffer || !size)
544 + return NULL;
545 + /* prefetch first cache line of first page */
546 + va = page_address(rx_buffer->page) + rx_buffer->page_offset;
547 +@@ -1531,7 +1534,7 @@ static int iavf_clean_rx_irq(struct iavf_ring *rx_ring, int budget)
548 + /* exit if we failed to retrieve a buffer */
549 + if (!skb) {
550 + rx_ring->rx_stats.alloc_buff_failed++;
551 +- if (rx_buffer)
552 ++ if (rx_buffer && size)
553 + rx_buffer->pagecnt_bias++;
554 + break;
555 + }
556 +diff --git a/drivers/net/ethernet/intel/iavf/iavf_virtchnl.c b/drivers/net/ethernet/intel/iavf/iavf_virtchnl.c
557 +index 4d471a6f2946f..7a17694b6a0b1 100644
558 +--- a/drivers/net/ethernet/intel/iavf/iavf_virtchnl.c
559 ++++ b/drivers/net/ethernet/intel/iavf/iavf_virtchnl.c
560 +@@ -241,11 +241,14 @@ out:
561 + void iavf_configure_queues(struct iavf_adapter *adapter)
562 + {
563 + struct virtchnl_vsi_queue_config_info *vqci;
564 +- struct virtchnl_queue_pair_info *vqpi;
565 ++ int i, max_frame = adapter->vf_res->max_mtu;
566 + int pairs = adapter->num_active_queues;
567 +- int i, max_frame = IAVF_MAX_RXBUFFER;
568 ++ struct virtchnl_queue_pair_info *vqpi;
569 + size_t len;
570 +
571 ++ if (max_frame > IAVF_MAX_RXBUFFER || !max_frame)
572 ++ max_frame = IAVF_MAX_RXBUFFER;
573 ++
574 + if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
575 + /* bail because we already have a command pending */
576 + dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
577 +diff --git a/drivers/net/ethernet/sun/sunhme.c b/drivers/net/ethernet/sun/sunhme.c
578 +index 3133f903279ce..dbbbb6ea9f2b6 100644
579 +--- a/drivers/net/ethernet/sun/sunhme.c
580 ++++ b/drivers/net/ethernet/sun/sunhme.c
581 +@@ -2064,9 +2064,9 @@ static void happy_meal_rx(struct happy_meal *hp, struct net_device *dev)
582 +
583 + skb_reserve(copy_skb, 2);
584 + skb_put(copy_skb, len);
585 +- dma_sync_single_for_cpu(hp->dma_dev, dma_addr, len, DMA_FROM_DEVICE);
586 ++ dma_sync_single_for_cpu(hp->dma_dev, dma_addr, len + 2, DMA_FROM_DEVICE);
587 + skb_copy_from_linear_data(skb, copy_skb->data, len);
588 +- dma_sync_single_for_device(hp->dma_dev, dma_addr, len, DMA_FROM_DEVICE);
589 ++ dma_sync_single_for_device(hp->dma_dev, dma_addr, len + 2, DMA_FROM_DEVICE);
590 + /* Reuse original ring buffer. */
591 + hme_write_rxd(hp, this,
592 + (RXFLAG_OWN|((RX_BUF_ALLOC_SIZE-RX_OFFSET)<<16)),
593 +diff --git a/drivers/net/ipvlan/ipvlan_core.c b/drivers/net/ipvlan/ipvlan_core.c
594 +index 8801d093135c3..a33149ee0ddcf 100644
595 +--- a/drivers/net/ipvlan/ipvlan_core.c
596 ++++ b/drivers/net/ipvlan/ipvlan_core.c
597 +@@ -496,7 +496,6 @@ static int ipvlan_process_v6_outbound(struct sk_buff *skb)
598 +
599 + static int ipvlan_process_outbound(struct sk_buff *skb)
600 + {
601 +- struct ethhdr *ethh = eth_hdr(skb);
602 + int ret = NET_XMIT_DROP;
603 +
604 + /* The ipvlan is a pseudo-L2 device, so the packets that we receive
605 +@@ -506,6 +505,8 @@ static int ipvlan_process_outbound(struct sk_buff *skb)
606 + if (skb_mac_header_was_set(skb)) {
607 + /* In this mode we dont care about
608 + * multicast and broadcast traffic */
609 ++ struct ethhdr *ethh = eth_hdr(skb);
610 ++
611 + if (is_multicast_ether_addr(ethh->h_dest)) {
612 + pr_debug_ratelimited(
613 + "Dropped {multi|broad}cast of type=[%x]\n",
614 +@@ -590,7 +591,7 @@ out:
615 + static int ipvlan_xmit_mode_l2(struct sk_buff *skb, struct net_device *dev)
616 + {
617 + const struct ipvl_dev *ipvlan = netdev_priv(dev);
618 +- struct ethhdr *eth = eth_hdr(skb);
619 ++ struct ethhdr *eth = skb_eth_hdr(skb);
620 + struct ipvl_addr *addr;
621 + void *lyr3h;
622 + int addr_type;
623 +@@ -620,6 +621,7 @@ static int ipvlan_xmit_mode_l2(struct sk_buff *skb, struct net_device *dev)
624 + return dev_forward_skb(ipvlan->phy_dev, skb);
625 +
626 + } else if (is_multicast_ether_addr(eth->h_dest)) {
627 ++ skb_reset_mac_header(skb);
628 + ipvlan_skb_crossing_ns(skb, NULL);
629 + ipvlan_multicast_enqueue(ipvlan->port, skb, true);
630 + return NET_XMIT_SUCCESS;
631 +diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
632 +index 0eb894b7c0bda..da74ec778b6e7 100644
633 +--- a/drivers/net/team/team.c
634 ++++ b/drivers/net/team/team.c
635 +@@ -1270,10 +1270,12 @@ static int team_port_add(struct team *team, struct net_device *port_dev,
636 + }
637 + }
638 +
639 +- netif_addr_lock_bh(dev);
640 +- dev_uc_sync_multiple(port_dev, dev);
641 +- dev_mc_sync_multiple(port_dev, dev);
642 +- netif_addr_unlock_bh(dev);
643 ++ if (dev->flags & IFF_UP) {
644 ++ netif_addr_lock_bh(dev);
645 ++ dev_uc_sync_multiple(port_dev, dev);
646 ++ dev_mc_sync_multiple(port_dev, dev);
647 ++ netif_addr_unlock_bh(dev);
648 ++ }
649 +
650 + port->index = -1;
651 + list_add_tail_rcu(&port->list, &team->port_list);
652 +@@ -1344,8 +1346,10 @@ static int team_port_del(struct team *team, struct net_device *port_dev)
653 + netdev_rx_handler_unregister(port_dev);
654 + team_port_disable_netpoll(port);
655 + vlan_vids_del_by_dev(port_dev, dev);
656 +- dev_uc_unsync(port_dev, dev);
657 +- dev_mc_unsync(port_dev, dev);
658 ++ if (dev->flags & IFF_UP) {
659 ++ dev_uc_unsync(port_dev, dev);
660 ++ dev_mc_unsync(port_dev, dev);
661 ++ }
662 + dev_close(port_dev);
663 + team_port_leave(team, port);
664 +
665 +@@ -1694,6 +1698,14 @@ static int team_open(struct net_device *dev)
666 +
667 + static int team_close(struct net_device *dev)
668 + {
669 ++ struct team *team = netdev_priv(dev);
670 ++ struct team_port *port;
671 ++
672 ++ list_for_each_entry(port, &team->port_list, list) {
673 ++ dev_uc_unsync(port->dev, dev);
674 ++ dev_mc_unsync(port->dev, dev);
675 ++ }
676 ++
677 + return 0;
678 + }
679 +
680 +diff --git a/drivers/net/usb/qmi_wwan.c b/drivers/net/usb/qmi_wwan.c
681 +index 8ef0a013874c5..cee90e505d175 100644
682 +--- a/drivers/net/usb/qmi_wwan.c
683 ++++ b/drivers/net/usb/qmi_wwan.c
684 +@@ -1046,6 +1046,7 @@ static const struct usb_device_id products[] = {
685 + {QMI_MATCH_FF_FF_FF(0x2c7c, 0x0512)}, /* Quectel EG12/EM12 */
686 + {QMI_MATCH_FF_FF_FF(0x2c7c, 0x0620)}, /* Quectel EM160R-GL */
687 + {QMI_MATCH_FF_FF_FF(0x2c7c, 0x0800)}, /* Quectel RM500Q-GL */
688 ++ {QMI_MATCH_FF_FF_FF(0x2c7c, 0x0801)}, /* Quectel RM520N */
689 +
690 + /* 3. Combined interface devices matching on interface number */
691 + {QMI_FIXED_INTF(0x0408, 0xea42, 4)}, /* Yota / Megafon M100-1 */
692 +diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
693 +index 943d2a60bfdf9..6d519ef3c5da4 100644
694 +--- a/drivers/of/fdt.c
695 ++++ b/drivers/of/fdt.c
696 +@@ -315,7 +315,7 @@ static int unflatten_dt_nodes(const void *blob,
697 + for (offset = 0;
698 + offset >= 0 && depth >= initial_depth;
699 + offset = fdt_next_node(blob, offset, &depth)) {
700 +- if (WARN_ON_ONCE(depth >= FDT_MAX_DEPTH))
701 ++ if (WARN_ON_ONCE(depth >= FDT_MAX_DEPTH - 1))
702 + continue;
703 +
704 + if (!IS_ENABLED(CONFIG_OF_KOBJ) &&
705 +diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c
706 +index 26ddb4cc675a9..7a3de2b5de0cd 100644
707 +--- a/drivers/of/of_mdio.c
708 ++++ b/drivers/of/of_mdio.c
709 +@@ -281,6 +281,7 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np)
710 + return 0;
711 +
712 + unregister:
713 ++ of_node_put(child);
714 + mdiobus_unregister(mdio);
715 + return rc;
716 + }
717 +diff --git a/drivers/parisc/ccio-dma.c b/drivers/parisc/ccio-dma.c
718 +index 6209d58e9492a..fdd302d0a1c90 100644
719 +--- a/drivers/parisc/ccio-dma.c
720 ++++ b/drivers/parisc/ccio-dma.c
721 +@@ -1544,6 +1544,7 @@ static int __init ccio_probe(struct parisc_device *dev)
722 + }
723 + ccio_ioc_init(ioc);
724 + if (ccio_init_resources(ioc)) {
725 ++ iounmap(ioc->ioc_regs);
726 + kfree(ioc);
727 + return -ENOMEM;
728 + }
729 +diff --git a/drivers/regulator/pfuze100-regulator.c b/drivers/regulator/pfuze100-regulator.c
730 +index f873d97100e28..13609942d45c0 100644
731 +--- a/drivers/regulator/pfuze100-regulator.c
732 ++++ b/drivers/regulator/pfuze100-regulator.c
733 +@@ -788,7 +788,7 @@ static int pfuze100_regulator_probe(struct i2c_client *client,
734 + ((pfuze_chip->chip_id == PFUZE3000) ? "3000" : "3001"))));
735 +
736 + memcpy(pfuze_chip->regulator_descs, pfuze_chip->pfuze_regulators,
737 +- sizeof(pfuze_chip->regulator_descs));
738 ++ regulator_num * sizeof(struct pfuze_regulator));
739 +
740 + ret = pfuze_parse_regulators_dt(pfuze_chip);
741 + if (ret)
742 +diff --git a/drivers/s390/block/dasd_alias.c b/drivers/s390/block/dasd_alias.c
743 +index dc78a523a69f2..b6b938aa66158 100644
744 +--- a/drivers/s390/block/dasd_alias.c
745 ++++ b/drivers/s390/block/dasd_alias.c
746 +@@ -675,12 +675,12 @@ int dasd_alias_remove_device(struct dasd_device *device)
747 + struct dasd_device *dasd_alias_get_start_dev(struct dasd_device *base_device)
748 + {
749 + struct dasd_eckd_private *alias_priv, *private = base_device->private;
750 +- struct alias_pav_group *group = private->pavgroup;
751 + struct alias_lcu *lcu = private->lcu;
752 + struct dasd_device *alias_device;
753 ++ struct alias_pav_group *group;
754 + unsigned long flags;
755 +
756 +- if (!group || !lcu)
757 ++ if (!lcu)
758 + return NULL;
759 + if (lcu->pav == NO_PAV ||
760 + lcu->flags & (NEED_UAC_UPDATE | UPDATE_PENDING))
761 +@@ -697,6 +697,11 @@ struct dasd_device *dasd_alias_get_start_dev(struct dasd_device *base_device)
762 + }
763 +
764 + spin_lock_irqsave(&lcu->lock, flags);
765 ++ group = private->pavgroup;
766 ++ if (!group) {
767 ++ spin_unlock_irqrestore(&lcu->lock, flags);
768 ++ return NULL;
769 ++ }
770 + alias_device = group->next;
771 + if (!alias_device) {
772 + if (list_empty(&group->aliaslist)) {
773 +diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
774 +index 3b2c25bd2e06b..3bd93558b4435 100644
775 +--- a/drivers/tty/serial/atmel_serial.c
776 ++++ b/drivers/tty/serial/atmel_serial.c
777 +@@ -306,16 +306,16 @@ static int atmel_config_rs485(struct uart_port *port,
778 +
779 + mode = atmel_uart_readl(port, ATMEL_US_MR);
780 +
781 +- /* Resetting serial mode to RS232 (0x0) */
782 +- mode &= ~ATMEL_US_USMODE;
783 +-
784 +- port->rs485 = *rs485conf;
785 +-
786 + if (rs485conf->flags & SER_RS485_ENABLED) {
787 + dev_dbg(port->dev, "Setting UART to RS485\n");
788 +- atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
789 ++ if (rs485conf->flags & SER_RS485_RX_DURING_TX)
790 ++ atmel_port->tx_done_mask = ATMEL_US_TXRDY;
791 ++ else
792 ++ atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
793 ++
794 + atmel_uart_writel(port, ATMEL_US_TTGR,
795 + rs485conf->delay_rts_after_send);
796 ++ mode &= ~ATMEL_US_USMODE;
797 + mode |= ATMEL_US_USMODE_RS485;
798 + } else {
799 + dev_dbg(port->dev, "Setting UART to RS232\n");
800 +@@ -832,7 +832,7 @@ static void atmel_tx_chars(struct uart_port *port)
801 + struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
802 +
803 + if (port->x_char &&
804 +- (atmel_uart_readl(port, ATMEL_US_CSR) & atmel_port->tx_done_mask)) {
805 ++ (atmel_uart_readl(port, ATMEL_US_CSR) & ATMEL_US_TXRDY)) {
806 + atmel_uart_write_char(port, port->x_char);
807 + port->icount.tx++;
808 + port->x_char = 0;
809 +@@ -840,8 +840,7 @@ static void atmel_tx_chars(struct uart_port *port)
810 + if (uart_circ_empty(xmit) || uart_tx_stopped(port))
811 + return;
812 +
813 +- while (atmel_uart_readl(port, ATMEL_US_CSR) &
814 +- atmel_port->tx_done_mask) {
815 ++ while (atmel_uart_readl(port, ATMEL_US_CSR) & ATMEL_US_TXRDY) {
816 + atmel_uart_write_char(port, xmit->buf[xmit->tail]);
817 + xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
818 + port->icount.tx++;
819 +@@ -852,10 +851,20 @@ static void atmel_tx_chars(struct uart_port *port)
820 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
821 + uart_write_wakeup(port);
822 +
823 +- if (!uart_circ_empty(xmit))
824 ++ if (!uart_circ_empty(xmit)) {
825 ++ /* we still have characters to transmit, so we should continue
826 ++ * transmitting them when TX is ready, regardless of
827 ++ * mode or duplexity
828 ++ */
829 ++ atmel_port->tx_done_mask |= ATMEL_US_TXRDY;
830 ++
831 + /* Enable interrupts */
832 + atmel_uart_writel(port, ATMEL_US_IER,
833 + atmel_port->tx_done_mask);
834 ++ } else {
835 ++ if (atmel_uart_is_half_duplex(port))
836 ++ atmel_port->tx_done_mask &= ~ATMEL_US_TXRDY;
837 ++ }
838 + }
839 +
840 + static void atmel_complete_tx_dma(void *arg)
841 +@@ -2541,8 +2550,7 @@ static int atmel_init_port(struct atmel_uart_port *atmel_port,
842 + * Use TXEMPTY for interrupt when rs485 or ISO7816 else TXRDY or
843 + * ENDTX|TXBUFE
844 + */
845 +- if (port->rs485.flags & SER_RS485_ENABLED ||
846 +- port->iso7816.flags & SER_ISO7816_ENABLED)
847 ++ if (atmel_uart_is_half_duplex(port))
848 + atmel_port->tx_done_mask = ATMEL_US_TXEMPTY;
849 + else if (atmel_use_pdc_tx(port)) {
850 + port->fifosize = PDC_BUFFER_SIZE;
851 +diff --git a/drivers/tty/serial/serial-tegra.c b/drivers/tty/serial/serial-tegra.c
852 +index 74c21152367ae..c5f43cd39664a 100644
853 +--- a/drivers/tty/serial/serial-tegra.c
854 ++++ b/drivers/tty/serial/serial-tegra.c
855 +@@ -519,7 +519,7 @@ static void tegra_uart_tx_dma_complete(void *args)
856 + count = tup->tx_bytes_requested - state.residue;
857 + async_tx_ack(tup->tx_dma_desc);
858 + spin_lock_irqsave(&tup->uport.lock, flags);
859 +- xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1);
860 ++ uart_xmit_advance(&tup->uport, count);
861 + tup->tx_in_progress = 0;
862 + if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
863 + uart_write_wakeup(&tup->uport);
864 +@@ -606,7 +606,6 @@ static unsigned int tegra_uart_tx_empty(struct uart_port *u)
865 + static void tegra_uart_stop_tx(struct uart_port *u)
866 + {
867 + struct tegra_uart_port *tup = to_tegra_uport(u);
868 +- struct circ_buf *xmit = &tup->uport.state->xmit;
869 + struct dma_tx_state state;
870 + unsigned int count;
871 +
872 +@@ -617,7 +616,7 @@ static void tegra_uart_stop_tx(struct uart_port *u)
873 + dmaengine_tx_status(tup->tx_dma_chan, tup->tx_cookie, &state);
874 + count = tup->tx_bytes_requested - state.residue;
875 + async_tx_ack(tup->tx_dma_desc);
876 +- xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1);
877 ++ uart_xmit_advance(&tup->uport, count);
878 + tup->tx_in_progress = 0;
879 + }
880 +
881 +diff --git a/drivers/tty/serial/tegra-tcu.c b/drivers/tty/serial/tegra-tcu.c
882 +index aaf8748a61479..31ae705aa38b7 100644
883 +--- a/drivers/tty/serial/tegra-tcu.c
884 ++++ b/drivers/tty/serial/tegra-tcu.c
885 +@@ -101,7 +101,7 @@ static void tegra_tcu_uart_start_tx(struct uart_port *port)
886 + break;
887 +
888 + tegra_tcu_write(tcu, &xmit->buf[xmit->tail], count);
889 +- xmit->tail = (xmit->tail + count) & (UART_XMIT_SIZE - 1);
890 ++ uart_xmit_advance(port, count);
891 + }
892 +
893 + uart_write_wakeup(port);
894 +diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c
895 +index 8bedf0504e92f..d111cf81cecef 100644
896 +--- a/drivers/usb/cdns3/gadget.c
897 ++++ b/drivers/usb/cdns3/gadget.c
898 +@@ -1259,6 +1259,7 @@ static int cdns3_check_ep_interrupt_proceed(struct cdns3_endpoint *priv_ep)
899 + ep_cfg &= ~EP_CFG_ENABLE;
900 + writel(ep_cfg, &priv_dev->regs->ep_cfg);
901 + priv_ep->flags &= ~EP_QUIRK_ISO_OUT_EN;
902 ++ priv_ep->flags |= EP_UPDATE_EP_TRBADDR;
903 + }
904 + cdns3_transfer_completed(priv_dev, priv_ep);
905 + } else if (!(priv_ep->flags & EP_STALLED) &&
906 +diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
907 +index 68d860a3fd617..50c7df59f7e87 100644
908 +--- a/drivers/usb/core/hub.c
909 ++++ b/drivers/usb/core/hub.c
910 +@@ -5924,7 +5924,7 @@ re_enumerate_no_bos:
911 + *
912 + * Return: The same as for usb_reset_and_verify_device().
913 + * However, if a reset is already in progress (for instance, if a
914 +- * driver doesn't have pre_ or post_reset() callbacks, and while
915 ++ * driver doesn't have pre_reset() or post_reset() callbacks, and while
916 + * being unbound or re-bound during the ongoing reset its disconnect()
917 + * or probe() routine tries to perform a second, nested reset), the
918 + * routine returns -EINPROGRESS.
919 +diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
920 +index f4655665a1b5c..a9c49b2ce511b 100644
921 +--- a/drivers/usb/dwc3/core.c
922 ++++ b/drivers/usb/dwc3/core.c
923 +@@ -227,7 +227,7 @@ u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type)
924 + * dwc3_core_soft_reset - Issues core soft reset and PHY reset
925 + * @dwc: pointer to our context structure
926 + */
927 +-static int dwc3_core_soft_reset(struct dwc3 *dwc)
928 ++int dwc3_core_soft_reset(struct dwc3 *dwc)
929 + {
930 + u32 reg;
931 + int retries = 1000;
932 +diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
933 +index da296f888f45d..f320b989abd21 100644
934 +--- a/drivers/usb/dwc3/core.h
935 ++++ b/drivers/usb/dwc3/core.h
936 +@@ -994,6 +994,7 @@ struct dwc3_scratchpad_array {
937 + * @tx_max_burst_prd: max periodic ESS transmit burst size
938 + * @hsphy_interface: "utmi" or "ulpi"
939 + * @connected: true when we're connected to a host, false otherwise
940 ++ * @softconnect: true when gadget connect is called, false when disconnect runs
941 + * @delayed_status: true when gadget driver asks for delayed status
942 + * @ep0_bounced: true when we used bounce buffer
943 + * @ep0_expect_in: true when we expect a DATA IN transfer
944 +@@ -1196,6 +1197,7 @@ struct dwc3 {
945 + const char *hsphy_interface;
946 +
947 + unsigned connected:1;
948 ++ unsigned softconnect:1;
949 + unsigned delayed_status:1;
950 + unsigned ep0_bounced:1;
951 + unsigned ep0_expect_in:1;
952 +@@ -1420,6 +1422,8 @@ bool dwc3_has_imod(struct dwc3 *dwc);
953 + int dwc3_event_buffers_setup(struct dwc3 *dwc);
954 + void dwc3_event_buffers_cleanup(struct dwc3 *dwc);
955 +
956 ++int dwc3_core_soft_reset(struct dwc3 *dwc);
957 ++
958 + #if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE)
959 + int dwc3_host_init(struct dwc3 *dwc);
960 + void dwc3_host_exit(struct dwc3 *dwc);
961 +diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
962 +index 80fee7ea83ca4..a40935f3592bc 100644
963 +--- a/drivers/usb/dwc3/gadget.c
964 ++++ b/drivers/usb/dwc3/gadget.c
965 +@@ -2008,14 +2008,42 @@ static void dwc3_gadget_disable_irq(struct dwc3 *dwc);
966 + static void __dwc3_gadget_stop(struct dwc3 *dwc);
967 + static int __dwc3_gadget_start(struct dwc3 *dwc);
968 +
969 ++static int dwc3_gadget_soft_disconnect(struct dwc3 *dwc)
970 ++{
971 ++ unsigned long flags;
972 ++
973 ++ spin_lock_irqsave(&dwc->lock, flags);
974 ++ dwc->connected = false;
975 ++
976 ++ /*
977 ++ * In the Synopsys DesignWare Cores USB3 Databook Rev. 3.30a
978 ++ * Section 4.1.8 Table 4-7, it states that for a device-initiated
979 ++ * disconnect, the SW needs to ensure that it sends "a DEPENDXFER
980 ++ * command for any active transfers" before clearing the RunStop
981 ++ * bit.
982 ++ */
983 ++ dwc3_stop_active_transfers(dwc);
984 ++ __dwc3_gadget_stop(dwc);
985 ++ spin_unlock_irqrestore(&dwc->lock, flags);
986 ++
987 ++ /*
988 ++ * Note: if the GEVNTCOUNT indicates events in the event buffer, the
989 ++ * driver needs to acknowledge them before the controller can halt.
990 ++ * Simply let the interrupt handler acknowledges and handle the
991 ++ * remaining event generated by the controller while polling for
992 ++ * DSTS.DEVCTLHLT.
993 ++ */
994 ++ return dwc3_gadget_run_stop(dwc, false, false);
995 ++}
996 ++
997 + static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
998 + {
999 + struct dwc3 *dwc = gadget_to_dwc(g);
1000 +- unsigned long flags;
1001 + int ret;
1002 +
1003 + is_on = !!is_on;
1004 +
1005 ++ dwc->softconnect = is_on;
1006 + /*
1007 + * Per databook, when we want to stop the gadget, if a control transfer
1008 + * is still in process, complete it and get the core into setup phase.
1009 +@@ -2051,50 +2079,27 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
1010 + return 0;
1011 + }
1012 +
1013 +- /*
1014 +- * Synchronize and disable any further event handling while controller
1015 +- * is being enabled/disabled.
1016 +- */
1017 +- disable_irq(dwc->irq_gadget);
1018 +-
1019 +- spin_lock_irqsave(&dwc->lock, flags);
1020 ++ if (dwc->pullups_connected == is_on) {
1021 ++ pm_runtime_put(dwc->dev);
1022 ++ return 0;
1023 ++ }
1024 +
1025 + if (!is_on) {
1026 +- u32 count;
1027 +-
1028 +- dwc->connected = false;
1029 ++ ret = dwc3_gadget_soft_disconnect(dwc);
1030 ++ } else {
1031 + /*
1032 +- * In the Synopsis DesignWare Cores USB3 Databook Rev. 3.30a
1033 +- * Section 4.1.8 Table 4-7, it states that for a device-initiated
1034 +- * disconnect, the SW needs to ensure that it sends "a DEPENDXFER
1035 +- * command for any active transfers" before clearing the RunStop
1036 +- * bit.
1037 ++ * In the Synopsys DWC_usb31 1.90a programming guide section
1038 ++ * 4.1.9, it specifies that for a reconnect after a
1039 ++ * device-initiated disconnect requires a core soft reset
1040 ++ * (DCTL.CSftRst) before enabling the run/stop bit.
1041 + */
1042 +- dwc3_stop_active_transfers(dwc);
1043 +- __dwc3_gadget_stop(dwc);
1044 ++ dwc3_core_soft_reset(dwc);
1045 +
1046 +- /*
1047 +- * In the Synopsis DesignWare Cores USB3 Databook Rev. 3.30a
1048 +- * Section 1.3.4, it mentions that for the DEVCTRLHLT bit, the
1049 +- * "software needs to acknowledge the events that are generated
1050 +- * (by writing to GEVNTCOUNTn) while it is waiting for this bit
1051 +- * to be set to '1'."
1052 +- */
1053 +- count = dwc3_readl(dwc->regs, DWC3_GEVNTCOUNT(0));
1054 +- count &= DWC3_GEVNTCOUNT_MASK;
1055 +- if (count > 0) {
1056 +- dwc3_writel(dwc->regs, DWC3_GEVNTCOUNT(0), count);
1057 +- dwc->ev_buf->lpos = (dwc->ev_buf->lpos + count) %
1058 +- dwc->ev_buf->length;
1059 +- }
1060 +- } else {
1061 ++ dwc3_event_buffers_setup(dwc);
1062 + __dwc3_gadget_start(dwc);
1063 ++ ret = dwc3_gadget_run_stop(dwc, true, false);
1064 + }
1065 +
1066 +- ret = dwc3_gadget_run_stop(dwc, is_on, false);
1067 +- spin_unlock_irqrestore(&dwc->lock, flags);
1068 +- enable_irq(dwc->irq_gadget);
1069 +-
1070 + pm_runtime_put(dwc->dev);
1071 +
1072 + return ret;
1073 +@@ -3791,7 +3796,7 @@ int dwc3_gadget_resume(struct dwc3 *dwc)
1074 + {
1075 + int ret;
1076 +
1077 +- if (!dwc->gadget_driver)
1078 ++ if (!dwc->gadget_driver || !dwc->softconnect)
1079 + return 0;
1080 +
1081 + ret = __dwc3_gadget_start(dwc);
1082 +diff --git a/drivers/usb/host/xhci-mtk-sch.c b/drivers/usb/host/xhci-mtk-sch.c
1083 +index 8950d1f10a7fb..86c4bc9df3b80 100644
1084 +--- a/drivers/usb/host/xhci-mtk-sch.c
1085 ++++ b/drivers/usb/host/xhci-mtk-sch.c
1086 +@@ -25,6 +25,13 @@
1087 + */
1088 + #define TT_MICROFRAMES_MAX 9
1089 +
1090 ++/* schedule error type */
1091 ++#define ESCH_SS_Y6 1001
1092 ++#define ESCH_SS_OVERLAP 1002
1093 ++#define ESCH_CS_OVERFLOW 1003
1094 ++#define ESCH_BW_OVERFLOW 1004
1095 ++#define ESCH_FIXME 1005
1096 ++
1097 + /* mtk scheduler bitmasks */
1098 + #define EP_BPKTS(p) ((p) & 0x7f)
1099 + #define EP_BCSCOUNT(p) (((p) & 0x7) << 8)
1100 +@@ -32,6 +39,24 @@
1101 + #define EP_BOFFSET(p) ((p) & 0x3fff)
1102 + #define EP_BREPEAT(p) (((p) & 0x7fff) << 16)
1103 +
1104 ++static char *sch_error_string(int err_num)
1105 ++{
1106 ++ switch (err_num) {
1107 ++ case ESCH_SS_Y6:
1108 ++ return "Can't schedule Start-Split in Y6";
1109 ++ case ESCH_SS_OVERLAP:
1110 ++ return "Can't find a suitable Start-Split location";
1111 ++ case ESCH_CS_OVERFLOW:
1112 ++ return "The last Complete-Split is greater than 7";
1113 ++ case ESCH_BW_OVERFLOW:
1114 ++ return "Bandwidth exceeds the maximum limit";
1115 ++ case ESCH_FIXME:
1116 ++ return "FIXME, to be resolved";
1117 ++ default:
1118 ++ return "Unknown";
1119 ++ }
1120 ++}
1121 ++
1122 + static int is_fs_or_ls(enum usb_device_speed speed)
1123 + {
1124 + return speed == USB_SPEED_FULL || speed == USB_SPEED_LOW;
1125 +@@ -375,7 +400,6 @@ static void update_bus_bw(struct mu3h_sch_bw_info *sch_bw,
1126 + sch_ep->bw_budget_table[j];
1127 + }
1128 + }
1129 +- sch_ep->allocated = used;
1130 + }
1131 +
1132 + static int check_fs_bus_bw(struct mu3h_sch_ep_info *sch_ep, int offset)
1133 +@@ -384,19 +408,20 @@ static int check_fs_bus_bw(struct mu3h_sch_ep_info *sch_ep, int offset)
1134 + u32 num_esit, tmp;
1135 + int base;
1136 + int i, j;
1137 ++ u8 uframes = DIV_ROUND_UP(sch_ep->maxpkt, FS_PAYLOAD_MAX);
1138 +
1139 + num_esit = XHCI_MTK_MAX_ESIT / sch_ep->esit;
1140 ++
1141 ++ if (sch_ep->ep_type == INT_IN_EP || sch_ep->ep_type == ISOC_IN_EP)
1142 ++ offset++;
1143 ++
1144 + for (i = 0; i < num_esit; i++) {
1145 + base = offset + i * sch_ep->esit;
1146 +
1147 +- /*
1148 +- * Compared with hs bus, no matter what ep type,
1149 +- * the hub will always delay one uframe to send data
1150 +- */
1151 +- for (j = 0; j < sch_ep->cs_count; j++) {
1152 ++ for (j = 0; j < uframes; j++) {
1153 + tmp = tt->fs_bus_bw[base + j] + sch_ep->bw_cost_per_microframe;
1154 + if (tmp > FS_PAYLOAD_MAX)
1155 +- return -ERANGE;
1156 ++ return -ESCH_BW_OVERFLOW;
1157 + }
1158 + }
1159 +
1160 +@@ -406,15 +431,11 @@ static int check_fs_bus_bw(struct mu3h_sch_ep_info *sch_ep, int offset)
1161 + static int check_sch_tt(struct usb_device *udev,
1162 + struct mu3h_sch_ep_info *sch_ep, u32 offset)
1163 + {
1164 +- struct mu3h_sch_tt *tt = sch_ep->sch_tt;
1165 + u32 extra_cs_count;
1166 +- u32 fs_budget_start;
1167 + u32 start_ss, last_ss;
1168 + u32 start_cs, last_cs;
1169 +- int i;
1170 +
1171 + start_ss = offset % 8;
1172 +- fs_budget_start = (start_ss + 1) % 8;
1173 +
1174 + if (sch_ep->ep_type == ISOC_OUT_EP) {
1175 + last_ss = start_ss + sch_ep->cs_count - 1;
1176 +@@ -424,11 +445,7 @@ static int check_sch_tt(struct usb_device *udev,
1177 + * must never schedule Start-Split in Y6
1178 + */
1179 + if (!(start_ss == 7 || last_ss < 6))
1180 +- return -ERANGE;
1181 +-
1182 +- for (i = 0; i < sch_ep->cs_count; i++)
1183 +- if (test_bit(offset + i, tt->ss_bit_map))
1184 +- return -ERANGE;
1185 ++ return -ESCH_SS_Y6;
1186 +
1187 + } else {
1188 + u32 cs_count = DIV_ROUND_UP(sch_ep->maxpkt, FS_PAYLOAD_MAX);
1189 +@@ -438,29 +455,24 @@ static int check_sch_tt(struct usb_device *udev,
1190 + * must never schedule Start-Split in Y6
1191 + */
1192 + if (start_ss == 6)
1193 +- return -ERANGE;
1194 ++ return -ESCH_SS_Y6;
1195 +
1196 + /* one uframe for ss + one uframe for idle */
1197 + start_cs = (start_ss + 2) % 8;
1198 + last_cs = start_cs + cs_count - 1;
1199 +
1200 + if (last_cs > 7)
1201 +- return -ERANGE;
1202 ++ return -ESCH_CS_OVERFLOW;
1203 +
1204 + if (sch_ep->ep_type == ISOC_IN_EP)
1205 + extra_cs_count = (last_cs == 7) ? 1 : 2;
1206 + else /* ep_type : INTR IN / INTR OUT */
1207 +- extra_cs_count = (fs_budget_start == 6) ? 1 : 2;
1208 ++ extra_cs_count = 1;
1209 +
1210 + cs_count += extra_cs_count;
1211 + if (cs_count > 7)
1212 + cs_count = 7; /* HW limit */
1213 +
1214 +- for (i = 0; i < cs_count + 2; i++) {
1215 +- if (test_bit(offset + i, tt->ss_bit_map))
1216 +- return -ERANGE;
1217 +- }
1218 +-
1219 + sch_ep->cs_count = cs_count;
1220 + /* one for ss, the other for idle */
1221 + sch_ep->num_budget_microframes = cs_count + 2;
1222 +@@ -482,28 +494,24 @@ static void update_sch_tt(struct usb_device *udev,
1223 + struct mu3h_sch_tt *tt = sch_ep->sch_tt;
1224 + u32 base, num_esit;
1225 + int bw_updated;
1226 +- int bits;
1227 + int i, j;
1228 ++ int offset = sch_ep->offset;
1229 ++ u8 uframes = DIV_ROUND_UP(sch_ep->maxpkt, FS_PAYLOAD_MAX);
1230 +
1231 + num_esit = XHCI_MTK_MAX_ESIT / sch_ep->esit;
1232 +- bits = (sch_ep->ep_type == ISOC_OUT_EP) ? sch_ep->cs_count : 1;
1233 +
1234 + if (used)
1235 + bw_updated = sch_ep->bw_cost_per_microframe;
1236 + else
1237 + bw_updated = -sch_ep->bw_cost_per_microframe;
1238 +
1239 +- for (i = 0; i < num_esit; i++) {
1240 +- base = sch_ep->offset + i * sch_ep->esit;
1241 ++ if (sch_ep->ep_type == INT_IN_EP || sch_ep->ep_type == ISOC_IN_EP)
1242 ++ offset++;
1243 +
1244 +- for (j = 0; j < bits; j++) {
1245 +- if (used)
1246 +- set_bit(base + j, tt->ss_bit_map);
1247 +- else
1248 +- clear_bit(base + j, tt->ss_bit_map);
1249 +- }
1250 ++ for (i = 0; i < num_esit; i++) {
1251 ++ base = offset + i * sch_ep->esit;
1252 +
1253 +- for (j = 0; j < sch_ep->cs_count; j++)
1254 ++ for (j = 0; j < uframes; j++)
1255 + tt->fs_bus_bw[base + j] += bw_updated;
1256 + }
1257 +
1258 +@@ -513,21 +521,48 @@ static void update_sch_tt(struct usb_device *udev,
1259 + list_del(&sch_ep->tt_endpoint);
1260 + }
1261 +
1262 ++static int load_ep_bw(struct usb_device *udev, struct mu3h_sch_bw_info *sch_bw,
1263 ++ struct mu3h_sch_ep_info *sch_ep, bool loaded)
1264 ++{
1265 ++ if (sch_ep->sch_tt)
1266 ++ update_sch_tt(udev, sch_ep, loaded);
1267 ++
1268 ++ /* update bus bandwidth info */
1269 ++ update_bus_bw(sch_bw, sch_ep, loaded);
1270 ++ sch_ep->allocated = loaded;
1271 ++
1272 ++ return 0;
1273 ++}
1274 ++
1275 ++static u32 get_esit_boundary(struct mu3h_sch_ep_info *sch_ep)
1276 ++{
1277 ++ u32 boundary = sch_ep->esit;
1278 ++
1279 ++ if (sch_ep->sch_tt) { /* LS/FS with TT */
1280 ++ /*
1281 ++ * tune for CS, normally esit >= 8 for FS/LS,
1282 ++ * not add one for other types to avoid access array
1283 ++ * out of boundary
1284 ++ */
1285 ++ if (sch_ep->ep_type == ISOC_OUT_EP && boundary > 1)
1286 ++ boundary--;
1287 ++ }
1288 ++
1289 ++ return boundary;
1290 ++}
1291 ++
1292 + static int check_sch_bw(struct usb_device *udev,
1293 + struct mu3h_sch_bw_info *sch_bw, struct mu3h_sch_ep_info *sch_ep)
1294 + {
1295 + u32 offset;
1296 +- u32 esit;
1297 + u32 min_bw;
1298 + u32 min_index;
1299 + u32 worst_bw;
1300 + u32 bw_boundary;
1301 ++ u32 esit_boundary;
1302 + u32 min_num_budget;
1303 + u32 min_cs_count;
1304 +- bool tt_offset_ok = false;
1305 +- int ret;
1306 +-
1307 +- esit = sch_ep->esit;
1308 ++ int ret = 0;
1309 +
1310 + /*
1311 + * Search through all possible schedule microframes.
1312 +@@ -537,16 +572,15 @@ static int check_sch_bw(struct usb_device *udev,
1313 + min_index = 0;
1314 + min_cs_count = sch_ep->cs_count;
1315 + min_num_budget = sch_ep->num_budget_microframes;
1316 +- for (offset = 0; offset < esit; offset++) {
1317 +- if (is_fs_or_ls(udev->speed)) {
1318 ++ esit_boundary = get_esit_boundary(sch_ep);
1319 ++ for (offset = 0; offset < sch_ep->esit; offset++) {
1320 ++ if (sch_ep->sch_tt) {
1321 + ret = check_sch_tt(udev, sch_ep, offset);
1322 + if (ret)
1323 + continue;
1324 +- else
1325 +- tt_offset_ok = true;
1326 + }
1327 +
1328 +- if ((offset + sch_ep->num_budget_microframes) > sch_ep->esit)
1329 ++ if ((offset + sch_ep->num_budget_microframes) > esit_boundary)
1330 + break;
1331 +
1332 + worst_bw = get_max_bw(sch_bw, sch_ep, offset);
1333 +@@ -569,35 +603,21 @@ static int check_sch_bw(struct usb_device *udev,
1334 +
1335 + /* check bandwidth */
1336 + if (min_bw > bw_boundary)
1337 +- return -ERANGE;
1338 ++ return ret ? ret : -ESCH_BW_OVERFLOW;
1339 +
1340 + sch_ep->offset = min_index;
1341 + sch_ep->cs_count = min_cs_count;
1342 + sch_ep->num_budget_microframes = min_num_budget;
1343 +
1344 +- if (is_fs_or_ls(udev->speed)) {
1345 +- /* all offset for tt is not ok*/
1346 +- if (!tt_offset_ok)
1347 +- return -ERANGE;
1348 +-
1349 +- update_sch_tt(udev, sch_ep, 1);
1350 +- }
1351 +-
1352 +- /* update bus bandwidth info */
1353 +- update_bus_bw(sch_bw, sch_ep, 1);
1354 +-
1355 +- return 0;
1356 ++ return load_ep_bw(udev, sch_bw, sch_ep, true);
1357 + }
1358 +
1359 + static void destroy_sch_ep(struct usb_device *udev,
1360 + struct mu3h_sch_bw_info *sch_bw, struct mu3h_sch_ep_info *sch_ep)
1361 + {
1362 + /* only release ep bw check passed by check_sch_bw() */
1363 +- if (sch_ep->allocated) {
1364 +- update_bus_bw(sch_bw, sch_ep, 0);
1365 +- if (sch_ep->sch_tt)
1366 +- update_sch_tt(udev, sch_ep, 0);
1367 +- }
1368 ++ if (sch_ep->allocated)
1369 ++ load_ep_bw(udev, sch_bw, sch_ep, false);
1370 +
1371 + if (sch_ep->sch_tt)
1372 + drop_tt(udev);
1373 +@@ -760,7 +780,8 @@ int xhci_mtk_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev)
1374 +
1375 + ret = check_sch_bw(udev, sch_bw, sch_ep);
1376 + if (ret) {
1377 +- xhci_err(xhci, "Not enough bandwidth!\n");
1378 ++ xhci_err(xhci, "Not enough bandwidth! (%s)\n",
1379 ++ sch_error_string(-ret));
1380 + return -ENOSPC;
1381 + }
1382 + }
1383 +diff --git a/drivers/usb/host/xhci-mtk.h b/drivers/usb/host/xhci-mtk.h
1384 +index 985e7a19f6f6c..2f702342de666 100644
1385 +--- a/drivers/usb/host/xhci-mtk.h
1386 ++++ b/drivers/usb/host/xhci-mtk.h
1387 +@@ -20,14 +20,12 @@
1388 + #define XHCI_MTK_MAX_ESIT 64
1389 +
1390 + /**
1391 +- * @ss_bit_map: used to avoid start split microframes overlay
1392 + * @fs_bus_bw: array to keep track of bandwidth already used for FS
1393 + * @ep_list: Endpoints using this TT
1394 + * @usb_tt: usb TT related
1395 + * @tt_port: TT port number
1396 + */
1397 + struct mu3h_sch_tt {
1398 +- DECLARE_BITMAP(ss_bit_map, XHCI_MTK_MAX_ESIT);
1399 + u32 fs_bus_bw[XHCI_MTK_MAX_ESIT];
1400 + struct list_head ep_list;
1401 + struct usb_tt *usb_tt;
1402 +diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
1403 +index cbe8ad3cd61fd..14aa8500221b8 100644
1404 +--- a/drivers/usb/serial/option.c
1405 ++++ b/drivers/usb/serial/option.c
1406 +@@ -256,6 +256,7 @@ static void option_instat_callback(struct urb *urb);
1407 + #define QUECTEL_PRODUCT_EM060K 0x030b
1408 + #define QUECTEL_PRODUCT_EM12 0x0512
1409 + #define QUECTEL_PRODUCT_RM500Q 0x0800
1410 ++#define QUECTEL_PRODUCT_RM520N 0x0801
1411 + #define QUECTEL_PRODUCT_EC200S_CN 0x6002
1412 + #define QUECTEL_PRODUCT_EC200T 0x6026
1413 + #define QUECTEL_PRODUCT_RM500K 0x7001
1414 +@@ -1138,6 +1139,8 @@ static const struct usb_device_id option_ids[] = {
1415 + { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EG95, 0xff, 0xff, 0xff),
1416 + .driver_info = NUMEP2 },
1417 + { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EG95, 0xff, 0, 0) },
1418 ++ { USB_DEVICE_INTERFACE_CLASS(QUECTEL_VENDOR_ID, 0x0203, 0xff), /* BG95-M3 */
1419 ++ .driver_info = ZLP },
1420 + { USB_DEVICE(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_BG96),
1421 + .driver_info = RSVD(4) },
1422 + { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EP06, 0xff, 0xff, 0xff),
1423 +@@ -1159,6 +1162,9 @@ static const struct usb_device_id option_ids[] = {
1424 + { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_RM500Q, 0xff, 0, 0) },
1425 + { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_RM500Q, 0xff, 0xff, 0x10),
1426 + .driver_info = ZLP },
1427 ++ { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_RM520N, 0xff, 0xff, 0x30) },
1428 ++ { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_RM520N, 0xff, 0, 0x40) },
1429 ++ { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_RM520N, 0xff, 0, 0) },
1430 + { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EC200S_CN, 0xff, 0, 0) },
1431 + { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_EC200T, 0xff, 0, 0) },
1432 + { USB_DEVICE_AND_INTERFACE_INFO(QUECTEL_VENDOR_ID, QUECTEL_PRODUCT_RM500K, 0xff, 0x00, 0x00) },
1433 +diff --git a/drivers/video/fbdev/pxa3xx-gcu.c b/drivers/video/fbdev/pxa3xx-gcu.c
1434 +index 7c4694d70dac1..15162b37f302f 100644
1435 +--- a/drivers/video/fbdev/pxa3xx-gcu.c
1436 ++++ b/drivers/video/fbdev/pxa3xx-gcu.c
1437 +@@ -382,7 +382,7 @@ pxa3xx_gcu_write(struct file *file, const char *buff,
1438 + struct pxa3xx_gcu_batch *buffer;
1439 + struct pxa3xx_gcu_priv *priv = to_pxa3xx_gcu_priv(file);
1440 +
1441 +- int words = count / 4;
1442 ++ size_t words = count / 4;
1443 +
1444 + /* Does not need to be atomic. There's a lock in user space,
1445 + * but anyhow, this is just for statistics. */
1446 +diff --git a/fs/afs/misc.c b/fs/afs/misc.c
1447 +index 5334f1bd2bca7..5171d6d990315 100644
1448 +--- a/fs/afs/misc.c
1449 ++++ b/fs/afs/misc.c
1450 +@@ -69,6 +69,7 @@ int afs_abort_to_error(u32 abort_code)
1451 + /* Unified AFS error table */
1452 + case UAEPERM: return -EPERM;
1453 + case UAENOENT: return -ENOENT;
1454 ++ case UAEAGAIN: return -EAGAIN;
1455 + case UAEACCES: return -EACCES;
1456 + case UAEBUSY: return -EBUSY;
1457 + case UAEEXIST: return -EEXIST;
1458 +diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
1459 +index 86bdebd2ece65..f8127edb89730 100644
1460 +--- a/fs/cifs/connect.c
1461 ++++ b/fs/cifs/connect.c
1462 +@@ -791,9 +791,6 @@ cifs_readv_from_socket(struct TCP_Server_Info *server, struct msghdr *smb_msg)
1463 + int length = 0;
1464 + int total_read;
1465 +
1466 +- smb_msg->msg_control = NULL;
1467 +- smb_msg->msg_controllen = 0;
1468 +-
1469 + for (total_read = 0; msg_data_left(smb_msg); total_read += length) {
1470 + try_to_freeze();
1471 +
1472 +@@ -844,7 +841,7 @@ int
1473 + cifs_read_from_socket(struct TCP_Server_Info *server, char *buf,
1474 + unsigned int to_read)
1475 + {
1476 +- struct msghdr smb_msg;
1477 ++ struct msghdr smb_msg = {};
1478 + struct kvec iov = {.iov_base = buf, .iov_len = to_read};
1479 + iov_iter_kvec(&smb_msg.msg_iter, READ, &iov, 1, to_read);
1480 +
1481 +@@ -855,7 +852,7 @@ int
1482 + cifs_read_page_from_socket(struct TCP_Server_Info *server, struct page *page,
1483 + unsigned int page_offset, unsigned int to_read)
1484 + {
1485 +- struct msghdr smb_msg;
1486 ++ struct msghdr smb_msg = {};
1487 + struct bio_vec bv = {
1488 + .bv_page = page, .bv_len = to_read, .bv_offset = page_offset};
1489 + iov_iter_bvec(&smb_msg.msg_iter, READ, &bv, 1, to_read);
1490 +diff --git a/fs/cifs/file.c b/fs/cifs/file.c
1491 +index 03c85beecec10..eb61cecf42d66 100644
1492 +--- a/fs/cifs/file.c
1493 ++++ b/fs/cifs/file.c
1494 +@@ -3194,6 +3194,9 @@ static ssize_t __cifs_writev(
1495 +
1496 + ssize_t cifs_direct_writev(struct kiocb *iocb, struct iov_iter *from)
1497 + {
1498 ++ struct file *file = iocb->ki_filp;
1499 ++
1500 ++ cifs_revalidate_mapping(file->f_inode);
1501 + return __cifs_writev(iocb, from, true);
1502 + }
1503 +
1504 +diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c
1505 +index 61e7df4d9cb11..b98ae69edb8fe 100644
1506 +--- a/fs/cifs/transport.c
1507 ++++ b/fs/cifs/transport.c
1508 +@@ -209,10 +209,6 @@ smb_send_kvec(struct TCP_Server_Info *server, struct msghdr *smb_msg,
1509 +
1510 + *sent = 0;
1511 +
1512 +- smb_msg->msg_name = (struct sockaddr *) &server->dstaddr;
1513 +- smb_msg->msg_namelen = sizeof(struct sockaddr);
1514 +- smb_msg->msg_control = NULL;
1515 +- smb_msg->msg_controllen = 0;
1516 + if (server->noblocksnd)
1517 + smb_msg->msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL;
1518 + else
1519 +@@ -324,7 +320,7 @@ __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst,
1520 + sigset_t mask, oldmask;
1521 + size_t total_len = 0, sent, size;
1522 + struct socket *ssocket = server->ssocket;
1523 +- struct msghdr smb_msg;
1524 ++ struct msghdr smb_msg = {};
1525 + int val = 1;
1526 + __be32 rfc1002_marker;
1527 +
1528 +diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
1529 +index d5e649e578cb1..ace8d6145253f 100644
1530 +--- a/fs/ext4/extents.c
1531 ++++ b/fs/ext4/extents.c
1532 +@@ -500,6 +500,10 @@ static int __ext4_ext_check(const char *function, unsigned int line,
1533 + error_msg = "invalid eh_entries";
1534 + goto corrupted;
1535 + }
1536 ++ if (unlikely((eh->eh_entries == 0) && (depth > 0))) {
1537 ++ error_msg = "eh_entries is 0 but eh_depth is > 0";
1538 ++ goto corrupted;
1539 ++ }
1540 + if (!ext4_valid_extent_entries(inode, eh, lblk, &pblk, depth)) {
1541 + error_msg = "invalid extent entries";
1542 + goto corrupted;
1543 +diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
1544 +index 83846cc814850..cbde5a096c7bf 100644
1545 +--- a/fs/ext4/ialloc.c
1546 ++++ b/fs/ext4/ialloc.c
1547 +@@ -500,7 +500,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,
1548 + goto fallback;
1549 + }
1550 +
1551 +- max_dirs = ndirs / ngroups + inodes_per_group / 16;
1552 ++ max_dirs = ndirs / ngroups + inodes_per_group*flex_size / 16;
1553 + min_inodes = avefreei - inodes_per_group*flex_size / 4;
1554 + if (min_inodes < 1)
1555 + min_inodes = 1;
1556 +diff --git a/fs/nfs/super.c b/fs/nfs/super.c
1557 +index a84df7d634032..ecc7277b3eda4 100644
1558 +--- a/fs/nfs/super.c
1559 ++++ b/fs/nfs/super.c
1560 +@@ -2375,22 +2375,31 @@ void nfs_fill_super(struct super_block *sb, struct nfs_mount_info *mount_info)
1561 + if (data && data->bsize)
1562 + sb->s_blocksize = nfs_block_size(data->bsize, &sb->s_blocksize_bits);
1563 +
1564 +- if (server->nfs_client->rpc_ops->version != 2) {
1565 +- /* The VFS shouldn't apply the umask to mode bits. We will do
1566 +- * so ourselves when necessary.
1567 ++ switch (server->nfs_client->rpc_ops->version) {
1568 ++ case 2:
1569 ++ sb->s_time_gran = 1000;
1570 ++ sb->s_time_min = 0;
1571 ++ sb->s_time_max = U32_MAX;
1572 ++ break;
1573 ++ case 3:
1574 ++ /*
1575 ++ * The VFS shouldn't apply the umask to mode bits.
1576 ++ * We will do so ourselves when necessary.
1577 + */
1578 + sb->s_flags |= SB_POSIXACL;
1579 + sb->s_time_gran = 1;
1580 +- sb->s_export_op = &nfs_export_ops;
1581 +- } else
1582 +- sb->s_time_gran = 1000;
1583 +-
1584 +- if (server->nfs_client->rpc_ops->version != 4) {
1585 + sb->s_time_min = 0;
1586 + sb->s_time_max = U32_MAX;
1587 +- } else {
1588 ++ sb->s_export_op = &nfs_export_ops;
1589 ++ break;
1590 ++ case 4:
1591 ++ sb->s_flags |= SB_POSIXACL;
1592 ++ sb->s_time_gran = 1;
1593 + sb->s_time_min = S64_MIN;
1594 + sb->s_time_max = S64_MAX;
1595 ++ if (server->caps & NFS_CAP_ATOMIC_OPEN_V1)
1596 ++ sb->s_export_op = &nfs_export_ops;
1597 ++ break;
1598 + }
1599 +
1600 + nfs_initialise_sb(sb);
1601 +diff --git a/fs/xfs/libxfs/xfs_alloc.c b/fs/xfs/libxfs/xfs_alloc.c
1602 +index 436f686a98918..084d39d8856bd 100644
1603 +--- a/fs/xfs/libxfs/xfs_alloc.c
1604 ++++ b/fs/xfs/libxfs/xfs_alloc.c
1605 +@@ -684,8 +684,10 @@ xfs_alloc_update_counters(
1606 +
1607 + xfs_trans_agblocks_delta(tp, len);
1608 + if (unlikely(be32_to_cpu(agf->agf_freeblks) >
1609 +- be32_to_cpu(agf->agf_length)))
1610 ++ be32_to_cpu(agf->agf_length))) {
1611 ++ xfs_buf_corruption_error(agbp);
1612 + return -EFSCORRUPTED;
1613 ++ }
1614 +
1615 + xfs_alloc_log_agf(tp, agbp, XFS_AGF_FREEBLKS);
1616 + return 0;
1617 +@@ -751,6 +753,7 @@ xfs_alloc_ag_vextent_small(
1618 +
1619 + bp = xfs_btree_get_bufs(args->mp, args->tp, args->agno, fbno);
1620 + if (!bp) {
1621 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, args->mp);
1622 + error = -EFSCORRUPTED;
1623 + goto error;
1624 + }
1625 +@@ -1995,24 +1998,32 @@ xfs_alloc_longest_free_extent(
1626 + return pag->pagf_flcount > 0 || pag->pagf_longest > 0;
1627 + }
1628 +
1629 ++/*
1630 ++ * Compute the minimum length of the AGFL in the given AG. If @pag is NULL,
1631 ++ * return the largest possible minimum length.
1632 ++ */
1633 + unsigned int
1634 + xfs_alloc_min_freelist(
1635 + struct xfs_mount *mp,
1636 + struct xfs_perag *pag)
1637 + {
1638 ++ /* AG btrees have at least 1 level. */
1639 ++ static const uint8_t fake_levels[XFS_BTNUM_AGF] = {1, 1, 1};
1640 ++ const uint8_t *levels = pag ? pag->pagf_levels : fake_levels;
1641 + unsigned int min_free;
1642 +
1643 ++ ASSERT(mp->m_ag_maxlevels > 0);
1644 ++
1645 + /* space needed by-bno freespace btree */
1646 +- min_free = min_t(unsigned int, pag->pagf_levels[XFS_BTNUM_BNOi] + 1,
1647 ++ min_free = min_t(unsigned int, levels[XFS_BTNUM_BNOi] + 1,
1648 + mp->m_ag_maxlevels);
1649 + /* space needed by-size freespace btree */
1650 +- min_free += min_t(unsigned int, pag->pagf_levels[XFS_BTNUM_CNTi] + 1,
1651 ++ min_free += min_t(unsigned int, levels[XFS_BTNUM_CNTi] + 1,
1652 + mp->m_ag_maxlevels);
1653 + /* space needed reverse mapping used space btree */
1654 + if (xfs_sb_version_hasrmapbt(&mp->m_sb))
1655 +- min_free += min_t(unsigned int,
1656 +- pag->pagf_levels[XFS_BTNUM_RMAPi] + 1,
1657 +- mp->m_rmap_maxlevels);
1658 ++ min_free += min_t(unsigned int, levels[XFS_BTNUM_RMAPi] + 1,
1659 ++ mp->m_rmap_maxlevels);
1660 +
1661 + return min_free;
1662 + }
1663 +@@ -2087,8 +2098,10 @@ xfs_free_agfl_block(
1664 + return error;
1665 +
1666 + bp = xfs_btree_get_bufs(tp->t_mountp, tp, agno, agbno);
1667 +- if (!bp)
1668 ++ if (!bp) {
1669 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, tp->t_mountp);
1670 + return -EFSCORRUPTED;
1671 ++ }
1672 + xfs_trans_binval(tp, bp);
1673 +
1674 + return 0;
1675 +diff --git a/fs/xfs/libxfs/xfs_attr_leaf.c b/fs/xfs/libxfs/xfs_attr_leaf.c
1676 +index de33efc9b4f94..0c23127347aca 100644
1677 +--- a/fs/xfs/libxfs/xfs_attr_leaf.c
1678 ++++ b/fs/xfs/libxfs/xfs_attr_leaf.c
1679 +@@ -2287,8 +2287,10 @@ xfs_attr3_leaf_lookup_int(
1680 + leaf = bp->b_addr;
1681 + xfs_attr3_leaf_hdr_from_disk(args->geo, &ichdr, leaf);
1682 + entries = xfs_attr3_leaf_entryp(leaf);
1683 +- if (ichdr.count >= args->geo->blksize / 8)
1684 ++ if (ichdr.count >= args->geo->blksize / 8) {
1685 ++ xfs_buf_corruption_error(bp);
1686 + return -EFSCORRUPTED;
1687 ++ }
1688 +
1689 + /*
1690 + * Binary search. (note: small blocks will skip this loop)
1691 +@@ -2304,10 +2306,14 @@ xfs_attr3_leaf_lookup_int(
1692 + else
1693 + break;
1694 + }
1695 +- if (!(probe >= 0 && (!ichdr.count || probe < ichdr.count)))
1696 ++ if (!(probe >= 0 && (!ichdr.count || probe < ichdr.count))) {
1697 ++ xfs_buf_corruption_error(bp);
1698 + return -EFSCORRUPTED;
1699 +- if (!(span <= 4 || be32_to_cpu(entry->hashval) == hashval))
1700 ++ }
1701 ++ if (!(span <= 4 || be32_to_cpu(entry->hashval) == hashval)) {
1702 ++ xfs_buf_corruption_error(bp);
1703 + return -EFSCORRUPTED;
1704 ++ }
1705 +
1706 + /*
1707 + * Since we may have duplicate hashval's, find the first matching
1708 +diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
1709 +index c114d24be6193..8d035842fe51d 100644
1710 +--- a/fs/xfs/libxfs/xfs_bmap.c
1711 ++++ b/fs/xfs/libxfs/xfs_bmap.c
1712 +@@ -729,6 +729,7 @@ xfs_bmap_extents_to_btree(
1713 + xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, 1L);
1714 + abp = xfs_btree_get_bufl(mp, tp, args.fsbno);
1715 + if (!abp) {
1716 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
1717 + error = -EFSCORRUPTED;
1718 + goto out_unreserve_dquot;
1719 + }
1720 +@@ -1084,6 +1085,7 @@ xfs_bmap_add_attrfork(
1721 + if (XFS_IFORK_Q(ip))
1722 + goto trans_cancel;
1723 + if (ip->i_d.di_anextents != 0) {
1724 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
1725 + error = -EFSCORRUPTED;
1726 + goto trans_cancel;
1727 + }
1728 +@@ -1374,7 +1376,8 @@ xfs_bmap_last_before(
1729 + case XFS_DINODE_FMT_EXTENTS:
1730 + break;
1731 + default:
1732 +- return -EIO;
1733 ++ ASSERT(0);
1734 ++ return -EFSCORRUPTED;
1735 + }
1736 +
1737 + if (!(ifp->if_flags & XFS_IFEXTENTS)) {
1738 +@@ -1474,8 +1477,10 @@ xfs_bmap_last_offset(
1739 + return 0;
1740 +
1741 + if (XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_BTREE &&
1742 +- XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_EXTENTS)
1743 +- return -EIO;
1744 ++ XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_EXTENTS) {
1745 ++ ASSERT(0);
1746 ++ return -EFSCORRUPTED;
1747 ++ }
1748 +
1749 + error = xfs_bmap_last_extent(NULL, ip, whichfork, &rec, &is_empty);
1750 + if (error || is_empty)
1751 +@@ -5871,8 +5876,9 @@ xfs_bmap_insert_extents(
1752 + XFS_WANT_CORRUPTED_GOTO(mp, !isnullstartblock(got.br_startblock),
1753 + del_cursor);
1754 +
1755 +- if (stop_fsb >= got.br_startoff + got.br_blockcount) {
1756 +- error = -EIO;
1757 ++ if (stop_fsb > got.br_startoff) {
1758 ++ ASSERT(0);
1759 ++ error = -EFSCORRUPTED;
1760 + goto del_cursor;
1761 + }
1762 +
1763 +diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c
1764 +index 71de937f9e64d..a13a25e922ec6 100644
1765 +--- a/fs/xfs/libxfs/xfs_btree.c
1766 ++++ b/fs/xfs/libxfs/xfs_btree.c
1767 +@@ -1820,6 +1820,7 @@ xfs_btree_lookup_get_block(
1768 +
1769 + out_bad:
1770 + *blkp = NULL;
1771 ++ xfs_buf_corruption_error(bp);
1772 + xfs_trans_brelse(cur->bc_tp, bp);
1773 + return -EFSCORRUPTED;
1774 + }
1775 +@@ -1867,8 +1868,10 @@ xfs_btree_lookup(
1776 + XFS_BTREE_STATS_INC(cur, lookup);
1777 +
1778 + /* No such thing as a zero-level tree. */
1779 +- if (cur->bc_nlevels == 0)
1780 ++ if (cur->bc_nlevels == 0) {
1781 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, cur->bc_mp);
1782 + return -EFSCORRUPTED;
1783 ++ }
1784 +
1785 + block = NULL;
1786 + keyno = 0;
1787 +diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c
1788 +index 4fd1223c1bd5d..1e2dc65adeb85 100644
1789 +--- a/fs/xfs/libxfs/xfs_da_btree.c
1790 ++++ b/fs/xfs/libxfs/xfs_da_btree.c
1791 +@@ -504,6 +504,7 @@ xfs_da3_split(
1792 + node = oldblk->bp->b_addr;
1793 + if (node->hdr.info.forw) {
1794 + if (be32_to_cpu(node->hdr.info.forw) != addblk->blkno) {
1795 ++ xfs_buf_corruption_error(oldblk->bp);
1796 + error = -EFSCORRUPTED;
1797 + goto out;
1798 + }
1799 +@@ -516,6 +517,7 @@ xfs_da3_split(
1800 + node = oldblk->bp->b_addr;
1801 + if (node->hdr.info.back) {
1802 + if (be32_to_cpu(node->hdr.info.back) != addblk->blkno) {
1803 ++ xfs_buf_corruption_error(oldblk->bp);
1804 + error = -EFSCORRUPTED;
1805 + goto out;
1806 + }
1807 +@@ -1541,8 +1543,10 @@ xfs_da3_node_lookup_int(
1808 + break;
1809 + }
1810 +
1811 +- if (magic != XFS_DA_NODE_MAGIC && magic != XFS_DA3_NODE_MAGIC)
1812 ++ if (magic != XFS_DA_NODE_MAGIC && magic != XFS_DA3_NODE_MAGIC) {
1813 ++ xfs_buf_corruption_error(blk->bp);
1814 + return -EFSCORRUPTED;
1815 ++ }
1816 +
1817 + blk->magic = XFS_DA_NODE_MAGIC;
1818 +
1819 +@@ -1554,15 +1558,18 @@ xfs_da3_node_lookup_int(
1820 + btree = dp->d_ops->node_tree_p(node);
1821 +
1822 + /* Tree taller than we can handle; bail out! */
1823 +- if (nodehdr.level >= XFS_DA_NODE_MAXDEPTH)
1824 ++ if (nodehdr.level >= XFS_DA_NODE_MAXDEPTH) {
1825 ++ xfs_buf_corruption_error(blk->bp);
1826 + return -EFSCORRUPTED;
1827 ++ }
1828 +
1829 + /* Check the level from the root. */
1830 + if (blkno == args->geo->leafblk)
1831 + expected_level = nodehdr.level - 1;
1832 +- else if (expected_level != nodehdr.level)
1833 ++ else if (expected_level != nodehdr.level) {
1834 ++ xfs_buf_corruption_error(blk->bp);
1835 + return -EFSCORRUPTED;
1836 +- else
1837 ++ } else
1838 + expected_level--;
1839 +
1840 + max = nodehdr.count;
1841 +@@ -1612,12 +1619,17 @@ xfs_da3_node_lookup_int(
1842 + }
1843 +
1844 + /* We can't point back to the root. */
1845 +- if (blkno == args->geo->leafblk)
1846 ++ if (blkno == args->geo->leafblk) {
1847 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW,
1848 ++ dp->i_mount);
1849 + return -EFSCORRUPTED;
1850 ++ }
1851 + }
1852 +
1853 +- if (expected_level != 0)
1854 ++ if (expected_level != 0) {
1855 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, dp->i_mount);
1856 + return -EFSCORRUPTED;
1857 ++ }
1858 +
1859 + /*
1860 + * A leaf block that ends in the hashval that we are interested in
1861 +diff --git a/fs/xfs/libxfs/xfs_dir2.c b/fs/xfs/libxfs/xfs_dir2.c
1862 +index 867c5dee07518..452d04ae10ceb 100644
1863 +--- a/fs/xfs/libxfs/xfs_dir2.c
1864 ++++ b/fs/xfs/libxfs/xfs_dir2.c
1865 +@@ -600,8 +600,10 @@ xfs_dir2_isblock(
1866 + if ((rval = xfs_bmap_last_offset(args->dp, &last, XFS_DATA_FORK)))
1867 + return rval;
1868 + rval = XFS_FSB_TO_B(args->dp->i_mount, last) == args->geo->blksize;
1869 +- if (rval != 0 && args->dp->i_d.di_size != args->geo->blksize)
1870 ++ if (rval != 0 && args->dp->i_d.di_size != args->geo->blksize) {
1871 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, args->dp->i_mount);
1872 + return -EFSCORRUPTED;
1873 ++ }
1874 + *vp = rval;
1875 + return 0;
1876 + }
1877 +diff --git a/fs/xfs/libxfs/xfs_dir2_leaf.c b/fs/xfs/libxfs/xfs_dir2_leaf.c
1878 +index a53e4585a2f3a..388b5da122287 100644
1879 +--- a/fs/xfs/libxfs/xfs_dir2_leaf.c
1880 ++++ b/fs/xfs/libxfs/xfs_dir2_leaf.c
1881 +@@ -1343,8 +1343,10 @@ xfs_dir2_leaf_removename(
1882 + oldbest = be16_to_cpu(bf[0].length);
1883 + ltp = xfs_dir2_leaf_tail_p(args->geo, leaf);
1884 + bestsp = xfs_dir2_leaf_bests_p(ltp);
1885 +- if (be16_to_cpu(bestsp[db]) != oldbest)
1886 ++ if (be16_to_cpu(bestsp[db]) != oldbest) {
1887 ++ xfs_buf_corruption_error(lbp);
1888 + return -EFSCORRUPTED;
1889 ++ }
1890 + /*
1891 + * Mark the former data entry unused.
1892 + */
1893 +diff --git a/fs/xfs/libxfs/xfs_dir2_node.c b/fs/xfs/libxfs/xfs_dir2_node.c
1894 +index 99d5b2ed67f2e..35e698fa85fd7 100644
1895 +--- a/fs/xfs/libxfs/xfs_dir2_node.c
1896 ++++ b/fs/xfs/libxfs/xfs_dir2_node.c
1897 +@@ -374,8 +374,10 @@ xfs_dir2_leaf_to_node(
1898 + leaf = lbp->b_addr;
1899 + ltp = xfs_dir2_leaf_tail_p(args->geo, leaf);
1900 + if (be32_to_cpu(ltp->bestcount) >
1901 +- (uint)dp->i_d.di_size / args->geo->blksize)
1902 ++ (uint)dp->i_d.di_size / args->geo->blksize) {
1903 ++ xfs_buf_corruption_error(lbp);
1904 + return -EFSCORRUPTED;
1905 ++ }
1906 +
1907 + /*
1908 + * Copy freespace entries from the leaf block to the new block.
1909 +@@ -446,8 +448,10 @@ xfs_dir2_leafn_add(
1910 + * Quick check just to make sure we are not going to index
1911 + * into other peoples memory
1912 + */
1913 +- if (index < 0)
1914 ++ if (index < 0) {
1915 ++ xfs_buf_corruption_error(bp);
1916 + return -EFSCORRUPTED;
1917 ++ }
1918 +
1919 + /*
1920 + * If there are already the maximum number of leaf entries in
1921 +@@ -740,8 +744,10 @@ xfs_dir2_leafn_lookup_for_entry(
1922 + ents = dp->d_ops->leaf_ents_p(leaf);
1923 +
1924 + xfs_dir3_leaf_check(dp, bp);
1925 +- if (leafhdr.count <= 0)
1926 ++ if (leafhdr.count <= 0) {
1927 ++ xfs_buf_corruption_error(bp);
1928 + return -EFSCORRUPTED;
1929 ++ }
1930 +
1931 + /*
1932 + * Look up the hash value in the leaf entries.
1933 +diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c
1934 +index ae16ca7c422a9..f980c3f3d2f66 100644
1935 +--- a/fs/xfs/libxfs/xfs_dir2_sf.c
1936 ++++ b/fs/xfs/libxfs/xfs_dir2_sf.c
1937 +@@ -944,6 +944,27 @@ xfs_dir2_sf_removename(
1938 + return 0;
1939 + }
1940 +
1941 ++/*
1942 ++ * Check whether the sf dir replace operation need more blocks.
1943 ++ */
1944 ++static bool
1945 ++xfs_dir2_sf_replace_needblock(
1946 ++ struct xfs_inode *dp,
1947 ++ xfs_ino_t inum)
1948 ++{
1949 ++ int newsize;
1950 ++ struct xfs_dir2_sf_hdr *sfp;
1951 ++
1952 ++ if (dp->i_d.di_format != XFS_DINODE_FMT_LOCAL)
1953 ++ return false;
1954 ++
1955 ++ sfp = (struct xfs_dir2_sf_hdr *)dp->i_df.if_u1.if_data;
1956 ++ newsize = dp->i_df.if_bytes + (sfp->count + 1) * XFS_INO64_DIFF;
1957 ++
1958 ++ return inum > XFS_DIR2_MAX_SHORT_INUM &&
1959 ++ sfp->i8count == 0 && newsize > XFS_IFORK_DSIZE(dp);
1960 ++}
1961 ++
1962 + /*
1963 + * Replace the inode number of an entry in a shortform directory.
1964 + */
1965 +@@ -980,17 +1001,14 @@ xfs_dir2_sf_replace(
1966 + */
1967 + if (args->inumber > XFS_DIR2_MAX_SHORT_INUM && sfp->i8count == 0) {
1968 + int error; /* error return value */
1969 +- int newsize; /* new inode size */
1970 +
1971 +- newsize = dp->i_df.if_bytes + (sfp->count + 1) * XFS_INO64_DIFF;
1972 + /*
1973 + * Won't fit as shortform, convert to block then do replace.
1974 + */
1975 +- if (newsize > XFS_IFORK_DSIZE(dp)) {
1976 ++ if (xfs_dir2_sf_replace_needblock(dp, args->inumber)) {
1977 + error = xfs_dir2_sf_to_block(args);
1978 +- if (error) {
1979 ++ if (error)
1980 + return error;
1981 +- }
1982 + return xfs_dir2_block_replace(args);
1983 + }
1984 + /*
1985 +diff --git a/fs/xfs/libxfs/xfs_ialloc.c b/fs/xfs/libxfs/xfs_ialloc.c
1986 +index 443cf33f66668..c3e0c2f61be4d 100644
1987 +--- a/fs/xfs/libxfs/xfs_ialloc.c
1988 ++++ b/fs/xfs/libxfs/xfs_ialloc.c
1989 +@@ -2854,3 +2854,67 @@ xfs_ialloc_setup_geometry(
1990 + else
1991 + igeo->ialloc_align = 0;
1992 + }
1993 ++
1994 ++/* Compute the location of the root directory inode that is laid out by mkfs. */
1995 ++xfs_ino_t
1996 ++xfs_ialloc_calc_rootino(
1997 ++ struct xfs_mount *mp,
1998 ++ int sunit)
1999 ++{
2000 ++ struct xfs_ino_geometry *igeo = M_IGEO(mp);
2001 ++ xfs_agblock_t first_bno;
2002 ++
2003 ++ /*
2004 ++ * Pre-calculate the geometry of AG 0. We know what it looks like
2005 ++ * because libxfs knows how to create allocation groups now.
2006 ++ *
2007 ++ * first_bno is the first block in which mkfs could possibly have
2008 ++ * allocated the root directory inode, once we factor in the metadata
2009 ++ * that mkfs formats before it. Namely, the four AG headers...
2010 ++ */
2011 ++ first_bno = howmany(4 * mp->m_sb.sb_sectsize, mp->m_sb.sb_blocksize);
2012 ++
2013 ++ /* ...the two free space btree roots... */
2014 ++ first_bno += 2;
2015 ++
2016 ++ /* ...the inode btree root... */
2017 ++ first_bno += 1;
2018 ++
2019 ++ /* ...the initial AGFL... */
2020 ++ first_bno += xfs_alloc_min_freelist(mp, NULL);
2021 ++
2022 ++ /* ...the free inode btree root... */
2023 ++ if (xfs_sb_version_hasfinobt(&mp->m_sb))
2024 ++ first_bno++;
2025 ++
2026 ++ /* ...the reverse mapping btree root... */
2027 ++ if (xfs_sb_version_hasrmapbt(&mp->m_sb))
2028 ++ first_bno++;
2029 ++
2030 ++ /* ...the reference count btree... */
2031 ++ if (xfs_sb_version_hasreflink(&mp->m_sb))
2032 ++ first_bno++;
2033 ++
2034 ++ /*
2035 ++ * ...and the log, if it is allocated in the first allocation group.
2036 ++ *
2037 ++ * This can happen with filesystems that only have a single
2038 ++ * allocation group, or very odd geometries created by old mkfs
2039 ++ * versions on very small filesystems.
2040 ++ */
2041 ++ if (mp->m_sb.sb_logstart &&
2042 ++ XFS_FSB_TO_AGNO(mp, mp->m_sb.sb_logstart) == 0)
2043 ++ first_bno += mp->m_sb.sb_logblocks;
2044 ++
2045 ++ /*
2046 ++ * Now round first_bno up to whatever allocation alignment is given
2047 ++ * by the filesystem or was passed in.
2048 ++ */
2049 ++ if (xfs_sb_version_hasdalign(&mp->m_sb) && igeo->ialloc_align > 0)
2050 ++ first_bno = roundup(first_bno, sunit);
2051 ++ else if (xfs_sb_version_hasalign(&mp->m_sb) &&
2052 ++ mp->m_sb.sb_inoalignmt > 1)
2053 ++ first_bno = roundup(first_bno, mp->m_sb.sb_inoalignmt);
2054 ++
2055 ++ return XFS_AGINO_TO_INO(mp, 0, XFS_AGB_TO_AGINO(mp, first_bno));
2056 ++}
2057 +diff --git a/fs/xfs/libxfs/xfs_ialloc.h b/fs/xfs/libxfs/xfs_ialloc.h
2058 +index 323592d563d52..72b3468b97b15 100644
2059 +--- a/fs/xfs/libxfs/xfs_ialloc.h
2060 ++++ b/fs/xfs/libxfs/xfs_ialloc.h
2061 +@@ -152,5 +152,6 @@ int xfs_inobt_insert_rec(struct xfs_btree_cur *cur, uint16_t holemask,
2062 +
2063 + int xfs_ialloc_cluster_alignment(struct xfs_mount *mp);
2064 + void xfs_ialloc_setup_geometry(struct xfs_mount *mp);
2065 ++xfs_ino_t xfs_ialloc_calc_rootino(struct xfs_mount *mp, int sunit);
2066 +
2067 + #endif /* __XFS_IALLOC_H__ */
2068 +diff --git a/fs/xfs/libxfs/xfs_inode_fork.c b/fs/xfs/libxfs/xfs_inode_fork.c
2069 +index 8fdd0424070e0..15d6f947620ff 100644
2070 +--- a/fs/xfs/libxfs/xfs_inode_fork.c
2071 ++++ b/fs/xfs/libxfs/xfs_inode_fork.c
2072 +@@ -75,11 +75,15 @@ xfs_iformat_fork(
2073 + error = xfs_iformat_btree(ip, dip, XFS_DATA_FORK);
2074 + break;
2075 + default:
2076 ++ xfs_inode_verifier_error(ip, -EFSCORRUPTED, __func__,
2077 ++ dip, sizeof(*dip), __this_address);
2078 + return -EFSCORRUPTED;
2079 + }
2080 + break;
2081 +
2082 + default:
2083 ++ xfs_inode_verifier_error(ip, -EFSCORRUPTED, __func__, dip,
2084 ++ sizeof(*dip), __this_address);
2085 + return -EFSCORRUPTED;
2086 + }
2087 + if (error)
2088 +@@ -110,6 +114,8 @@ xfs_iformat_fork(
2089 + error = xfs_iformat_btree(ip, dip, XFS_ATTR_FORK);
2090 + break;
2091 + default:
2092 ++ xfs_inode_verifier_error(ip, error, __func__, dip,
2093 ++ sizeof(*dip), __this_address);
2094 + error = -EFSCORRUPTED;
2095 + break;
2096 + }
2097 +diff --git a/fs/xfs/libxfs/xfs_refcount.c b/fs/xfs/libxfs/xfs_refcount.c
2098 +index 9a7fadb1361cb..78236bd6c64f0 100644
2099 +--- a/fs/xfs/libxfs/xfs_refcount.c
2100 ++++ b/fs/xfs/libxfs/xfs_refcount.c
2101 +@@ -1591,8 +1591,10 @@ xfs_refcount_recover_extent(
2102 + struct list_head *debris = priv;
2103 + struct xfs_refcount_recovery *rr;
2104 +
2105 +- if (be32_to_cpu(rec->refc.rc_refcount) != 1)
2106 ++ if (be32_to_cpu(rec->refc.rc_refcount) != 1) {
2107 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, cur->bc_mp);
2108 + return -EFSCORRUPTED;
2109 ++ }
2110 +
2111 + rr = kmem_alloc(sizeof(struct xfs_refcount_recovery), 0);
2112 + xfs_refcount_btrec_to_irec(rec, &rr->rr_rrec);
2113 +diff --git a/fs/xfs/libxfs/xfs_rtbitmap.c b/fs/xfs/libxfs/xfs_rtbitmap.c
2114 +index 42085e70c01ac..85f123b3dfcc1 100644
2115 +--- a/fs/xfs/libxfs/xfs_rtbitmap.c
2116 ++++ b/fs/xfs/libxfs/xfs_rtbitmap.c
2117 +@@ -15,7 +15,7 @@
2118 + #include "xfs_bmap.h"
2119 + #include "xfs_trans.h"
2120 + #include "xfs_rtalloc.h"
2121 +-
2122 ++#include "xfs_error.h"
2123 +
2124 + /*
2125 + * Realtime allocator bitmap functions shared with userspace.
2126 +@@ -70,8 +70,10 @@ xfs_rtbuf_get(
2127 + if (error)
2128 + return error;
2129 +
2130 +- if (nmap == 0 || !xfs_bmap_is_real_extent(&map))
2131 ++ if (nmap == 0 || !xfs_bmap_is_real_extent(&map)) {
2132 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
2133 + return -EFSCORRUPTED;
2134 ++ }
2135 +
2136 + ASSERT(map.br_startblock != NULLFSBLOCK);
2137 + error = xfs_trans_read_buf(mp, tp, mp->m_ddev_targp,
2138 +diff --git a/fs/xfs/xfs_acl.c b/fs/xfs/xfs_acl.c
2139 +index 96d7071cfa468..3f2292c7835ca 100644
2140 +--- a/fs/xfs/xfs_acl.c
2141 ++++ b/fs/xfs/xfs_acl.c
2142 +@@ -12,6 +12,7 @@
2143 + #include "xfs_inode.h"
2144 + #include "xfs_attr.h"
2145 + #include "xfs_trace.h"
2146 ++#include "xfs_error.h"
2147 + #include <linux/posix_acl_xattr.h>
2148 +
2149 +
2150 +@@ -23,6 +24,7 @@
2151 +
2152 + STATIC struct posix_acl *
2153 + xfs_acl_from_disk(
2154 ++ struct xfs_mount *mp,
2155 + const struct xfs_acl *aclp,
2156 + int len,
2157 + int max_entries)
2158 +@@ -32,11 +34,18 @@ xfs_acl_from_disk(
2159 + const struct xfs_acl_entry *ace;
2160 + unsigned int count, i;
2161 +
2162 +- if (len < sizeof(*aclp))
2163 ++ if (len < sizeof(*aclp)) {
2164 ++ XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, aclp,
2165 ++ len);
2166 + return ERR_PTR(-EFSCORRUPTED);
2167 ++ }
2168 ++
2169 + count = be32_to_cpu(aclp->acl_cnt);
2170 +- if (count > max_entries || XFS_ACL_SIZE(count) != len)
2171 ++ if (count > max_entries || XFS_ACL_SIZE(count) != len) {
2172 ++ XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, aclp,
2173 ++ len);
2174 + return ERR_PTR(-EFSCORRUPTED);
2175 ++ }
2176 +
2177 + acl = posix_acl_alloc(count, GFP_KERNEL);
2178 + if (!acl)
2179 +@@ -145,7 +154,7 @@ xfs_get_acl(struct inode *inode, int type)
2180 + if (error != -ENOATTR)
2181 + acl = ERR_PTR(error);
2182 + } else {
2183 +- acl = xfs_acl_from_disk(xfs_acl, len,
2184 ++ acl = xfs_acl_from_disk(ip->i_mount, xfs_acl, len,
2185 + XFS_ACL_MAX_ENTRIES(ip->i_mount));
2186 + kmem_free(xfs_acl);
2187 + }
2188 +diff --git a/fs/xfs/xfs_attr_inactive.c b/fs/xfs/xfs_attr_inactive.c
2189 +index a640a285cc521..766b1386402a0 100644
2190 +--- a/fs/xfs/xfs_attr_inactive.c
2191 ++++ b/fs/xfs/xfs_attr_inactive.c
2192 +@@ -22,6 +22,7 @@
2193 + #include "xfs_attr_leaf.h"
2194 + #include "xfs_quota.h"
2195 + #include "xfs_dir2.h"
2196 ++#include "xfs_error.h"
2197 +
2198 + /*
2199 + * Look at all the extents for this logical region,
2200 +@@ -208,8 +209,9 @@ xfs_attr3_node_inactive(
2201 + * Since this code is recursive (gasp!) we must protect ourselves.
2202 + */
2203 + if (level > XFS_DA_NODE_MAXDEPTH) {
2204 ++ xfs_buf_corruption_error(bp);
2205 + xfs_trans_brelse(*trans, bp); /* no locks for later trans */
2206 +- return -EIO;
2207 ++ return -EFSCORRUPTED;
2208 + }
2209 +
2210 + node = bp->b_addr;
2211 +@@ -258,8 +260,9 @@ xfs_attr3_node_inactive(
2212 + error = xfs_attr3_leaf_inactive(trans, dp, child_bp);
2213 + break;
2214 + default:
2215 +- error = -EIO;
2216 ++ xfs_buf_corruption_error(child_bp);
2217 + xfs_trans_brelse(*trans, child_bp);
2218 ++ error = -EFSCORRUPTED;
2219 + break;
2220 + }
2221 + if (error)
2222 +@@ -341,7 +344,8 @@ xfs_attr3_root_inactive(
2223 + error = xfs_attr3_leaf_inactive(trans, dp, bp);
2224 + break;
2225 + default:
2226 +- error = -EIO;
2227 ++ error = -EFSCORRUPTED;
2228 ++ xfs_buf_corruption_error(bp);
2229 + xfs_trans_brelse(*trans, bp);
2230 + break;
2231 + }
2232 +diff --git a/fs/xfs/xfs_attr_list.c b/fs/xfs/xfs_attr_list.c
2233 +index 00758fdc2fecf..8b9b500e75e81 100644
2234 +--- a/fs/xfs/xfs_attr_list.c
2235 ++++ b/fs/xfs/xfs_attr_list.c
2236 +@@ -258,8 +258,10 @@ xfs_attr_node_list_lookup(
2237 + return 0;
2238 +
2239 + /* We can't point back to the root. */
2240 +- if (cursor->blkno == 0)
2241 ++ if (cursor->blkno == 0) {
2242 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
2243 + return -EFSCORRUPTED;
2244 ++ }
2245 + }
2246 +
2247 + if (expected_level != 0)
2248 +@@ -269,6 +271,7 @@ xfs_attr_node_list_lookup(
2249 + return 0;
2250 +
2251 + out_corruptbuf:
2252 ++ xfs_buf_corruption_error(bp);
2253 + xfs_trans_brelse(tp, bp);
2254 + return -EFSCORRUPTED;
2255 + }
2256 +diff --git a/fs/xfs/xfs_bmap_item.c b/fs/xfs/xfs_bmap_item.c
2257 +index 83d24e983d4c2..243e5e0f82a30 100644
2258 +--- a/fs/xfs/xfs_bmap_item.c
2259 ++++ b/fs/xfs/xfs_bmap_item.c
2260 +@@ -21,7 +21,7 @@
2261 + #include "xfs_icache.h"
2262 + #include "xfs_bmap_btree.h"
2263 + #include "xfs_trans_space.h"
2264 +-
2265 ++#include "xfs_error.h"
2266 +
2267 + kmem_zone_t *xfs_bui_zone;
2268 + kmem_zone_t *xfs_bud_zone;
2269 +@@ -456,7 +456,7 @@ xfs_bui_recover(
2270 + if (buip->bui_format.bui_nextents != XFS_BUI_MAX_FAST_EXTENTS) {
2271 + set_bit(XFS_BUI_RECOVERED, &buip->bui_flags);
2272 + xfs_bui_release(buip);
2273 +- return -EIO;
2274 ++ return -EFSCORRUPTED;
2275 + }
2276 +
2277 + /*
2278 +@@ -490,7 +490,7 @@ xfs_bui_recover(
2279 + */
2280 + set_bit(XFS_BUI_RECOVERED, &buip->bui_flags);
2281 + xfs_bui_release(buip);
2282 +- return -EIO;
2283 ++ return -EFSCORRUPTED;
2284 + }
2285 +
2286 + error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate,
2287 +@@ -525,6 +525,7 @@ xfs_bui_recover(
2288 + type = bui_type;
2289 + break;
2290 + default:
2291 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
2292 + error = -EFSCORRUPTED;
2293 + goto err_inode;
2294 + }
2295 +diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c
2296 +index d6d78e1276254..113bed28bc310 100644
2297 +--- a/fs/xfs/xfs_bmap_util.c
2298 ++++ b/fs/xfs/xfs_bmap_util.c
2299 +@@ -1167,6 +1167,7 @@ xfs_prepare_shift(
2300 + struct xfs_inode *ip,
2301 + loff_t offset)
2302 + {
2303 ++ struct xfs_mount *mp = ip->i_mount;
2304 + int error;
2305 +
2306 + /*
2307 +@@ -1179,6 +1180,17 @@ xfs_prepare_shift(
2308 + return error;
2309 + }
2310 +
2311 ++ /*
2312 ++ * Shift operations must stabilize the start block offset boundary along
2313 ++ * with the full range of the operation. If we don't, a COW writeback
2314 ++ * completion could race with an insert, front merge with the start
2315 ++ * extent (after split) during the shift and corrupt the file. Start
2316 ++ * with the block just prior to the start to stabilize the boundary.
2317 ++ */
2318 ++ offset = round_down(offset, 1 << mp->m_sb.sb_blocklog);
2319 ++ if (offset)
2320 ++ offset -= (1 << mp->m_sb.sb_blocklog);
2321 ++
2322 + /*
2323 + * Writeback and invalidate cache for the remainder of the file as we're
2324 + * about to shift down every extent from offset to EOF.
2325 +diff --git a/fs/xfs/xfs_buf_item.c b/fs/xfs/xfs_buf_item.c
2326 +index d74fbd1e9d3ea..b1452117e4429 100644
2327 +--- a/fs/xfs/xfs_buf_item.c
2328 ++++ b/fs/xfs/xfs_buf_item.c
2329 +@@ -956,7 +956,7 @@ xfs_buf_item_relse(
2330 + struct xfs_buf_log_item *bip = bp->b_log_item;
2331 +
2332 + trace_xfs_buf_item_relse(bp, _RET_IP_);
2333 +- ASSERT(!(bip->bli_item.li_flags & XFS_LI_IN_AIL));
2334 ++ ASSERT(!test_bit(XFS_LI_IN_AIL, &bip->bli_item.li_flags));
2335 +
2336 + bp->b_log_item = NULL;
2337 + if (list_empty(&bp->b_li_list))
2338 +diff --git a/fs/xfs/xfs_dquot.c b/fs/xfs/xfs_dquot.c
2339 +index 3cbf248af51ff..aa50841802703 100644
2340 +--- a/fs/xfs/xfs_dquot.c
2341 ++++ b/fs/xfs/xfs_dquot.c
2342 +@@ -1125,7 +1125,7 @@ xfs_qm_dqflush(
2343 + xfs_buf_relse(bp);
2344 + xfs_dqfunlock(dqp);
2345 + xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
2346 +- return -EIO;
2347 ++ return -EFSCORRUPTED;
2348 + }
2349 +
2350 + /* This is the only portion of data that needs to persist */
2351 +diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c
2352 +index 849fd4476950a..d8cdb27fe6ed3 100644
2353 +--- a/fs/xfs/xfs_error.c
2354 ++++ b/fs/xfs/xfs_error.c
2355 +@@ -329,7 +329,7 @@ xfs_corruption_error(
2356 + const char *tag,
2357 + int level,
2358 + struct xfs_mount *mp,
2359 +- void *buf,
2360 ++ const void *buf,
2361 + size_t bufsize,
2362 + const char *filename,
2363 + int linenum,
2364 +@@ -341,6 +341,27 @@ xfs_corruption_error(
2365 + xfs_alert(mp, "Corruption detected. Unmount and run xfs_repair");
2366 + }
2367 +
2368 ++/*
2369 ++ * Complain about the kinds of metadata corruption that we can't detect from a
2370 ++ * verifier, such as incorrect inter-block relationship data. Does not set
2371 ++ * bp->b_error.
2372 ++ */
2373 ++void
2374 ++xfs_buf_corruption_error(
2375 ++ struct xfs_buf *bp)
2376 ++{
2377 ++ struct xfs_mount *mp = bp->b_mount;
2378 ++
2379 ++ xfs_alert_tag(mp, XFS_PTAG_VERIFIER_ERROR,
2380 ++ "Metadata corruption detected at %pS, %s block 0x%llx",
2381 ++ __return_address, bp->b_ops->name, bp->b_bn);
2382 ++
2383 ++ xfs_alert(mp, "Unmount and run xfs_repair");
2384 ++
2385 ++ if (xfs_error_level >= XFS_ERRLEVEL_HIGH)
2386 ++ xfs_stack_trace();
2387 ++}
2388 ++
2389 + /*
2390 + * Warnings specifically for verifier errors. Differentiate CRC vs. invalid
2391 + * values, and omit the stack trace unless the error level is tuned high.
2392 +@@ -350,7 +371,7 @@ xfs_buf_verifier_error(
2393 + struct xfs_buf *bp,
2394 + int error,
2395 + const char *name,
2396 +- void *buf,
2397 ++ const void *buf,
2398 + size_t bufsz,
2399 + xfs_failaddr_t failaddr)
2400 + {
2401 +@@ -402,7 +423,7 @@ xfs_inode_verifier_error(
2402 + struct xfs_inode *ip,
2403 + int error,
2404 + const char *name,
2405 +- void *buf,
2406 ++ const void *buf,
2407 + size_t bufsz,
2408 + xfs_failaddr_t failaddr)
2409 + {
2410 +diff --git a/fs/xfs/xfs_error.h b/fs/xfs/xfs_error.h
2411 +index 602aa7d62b66e..c319379f7d1a3 100644
2412 +--- a/fs/xfs/xfs_error.h
2413 ++++ b/fs/xfs/xfs_error.h
2414 +@@ -12,16 +12,17 @@ extern void xfs_error_report(const char *tag, int level, struct xfs_mount *mp,
2415 + const char *filename, int linenum,
2416 + xfs_failaddr_t failaddr);
2417 + extern void xfs_corruption_error(const char *tag, int level,
2418 +- struct xfs_mount *mp, void *buf, size_t bufsize,
2419 ++ struct xfs_mount *mp, const void *buf, size_t bufsize,
2420 + const char *filename, int linenum,
2421 + xfs_failaddr_t failaddr);
2422 ++void xfs_buf_corruption_error(struct xfs_buf *bp);
2423 + extern void xfs_buf_verifier_error(struct xfs_buf *bp, int error,
2424 +- const char *name, void *buf, size_t bufsz,
2425 ++ const char *name, const void *buf, size_t bufsz,
2426 + xfs_failaddr_t failaddr);
2427 + extern void xfs_verifier_error(struct xfs_buf *bp, int error,
2428 + xfs_failaddr_t failaddr);
2429 + extern void xfs_inode_verifier_error(struct xfs_inode *ip, int error,
2430 +- const char *name, void *buf, size_t bufsz,
2431 ++ const char *name, const void *buf, size_t bufsz,
2432 + xfs_failaddr_t failaddr);
2433 +
2434 + #define XFS_ERROR_REPORT(e, lvl, mp) \
2435 +diff --git a/fs/xfs/xfs_extfree_item.c b/fs/xfs/xfs_extfree_item.c
2436 +index e44efc41a0412..a05a1074e8f81 100644
2437 +--- a/fs/xfs/xfs_extfree_item.c
2438 ++++ b/fs/xfs/xfs_extfree_item.c
2439 +@@ -21,7 +21,7 @@
2440 + #include "xfs_alloc.h"
2441 + #include "xfs_bmap.h"
2442 + #include "xfs_trace.h"
2443 +-
2444 ++#include "xfs_error.h"
2445 +
2446 + kmem_zone_t *xfs_efi_zone;
2447 + kmem_zone_t *xfs_efd_zone;
2448 +@@ -228,6 +228,7 @@ xfs_efi_copy_format(xfs_log_iovec_t *buf, xfs_efi_log_format_t *dst_efi_fmt)
2449 + }
2450 + return 0;
2451 + }
2452 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL);
2453 + return -EFSCORRUPTED;
2454 + }
2455 +
2456 +@@ -624,7 +625,7 @@ xfs_efi_recover(
2457 + */
2458 + set_bit(XFS_EFI_RECOVERED, &efip->efi_flags);
2459 + xfs_efi_release(efip);
2460 +- return -EIO;
2461 ++ return -EFSCORRUPTED;
2462 + }
2463 + }
2464 +
2465 +diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c
2466 +index 01c0933a4d10d..79e8af8f4669c 100644
2467 +--- a/fs/xfs/xfs_fsmap.c
2468 ++++ b/fs/xfs/xfs_fsmap.c
2469 +@@ -146,6 +146,7 @@ xfs_fsmap_owner_from_rmap(
2470 + dest->fmr_owner = XFS_FMR_OWN_FREE;
2471 + break;
2472 + default:
2473 ++ ASSERT(0);
2474 + return -EFSCORRUPTED;
2475 + }
2476 + return 0;
2477 +diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c
2478 +index 7a9048c4c2f95..7b72c189cff0b 100644
2479 +--- a/fs/xfs/xfs_inode.c
2480 ++++ b/fs/xfs/xfs_inode.c
2481 +@@ -2149,8 +2149,10 @@ xfs_iunlink_update_bucket(
2482 + * passed in because either we're adding or removing ourselves from the
2483 + * head of the list.
2484 + */
2485 +- if (old_value == new_agino)
2486 ++ if (old_value == new_agino) {
2487 ++ xfs_buf_corruption_error(agibp);
2488 + return -EFSCORRUPTED;
2489 ++ }
2490 +
2491 + agi->agi_unlinked[bucket_index] = cpu_to_be32(new_agino);
2492 + offset = offsetof(struct xfs_agi, agi_unlinked) +
2493 +@@ -2213,6 +2215,8 @@ xfs_iunlink_update_inode(
2494 + /* Make sure the old pointer isn't garbage. */
2495 + old_value = be32_to_cpu(dip->di_next_unlinked);
2496 + if (!xfs_verify_agino_or_null(mp, agno, old_value)) {
2497 ++ xfs_inode_verifier_error(ip, -EFSCORRUPTED, __func__, dip,
2498 ++ sizeof(*dip), __this_address);
2499 + error = -EFSCORRUPTED;
2500 + goto out;
2501 + }
2502 +@@ -2224,8 +2228,11 @@ xfs_iunlink_update_inode(
2503 + */
2504 + *old_next_agino = old_value;
2505 + if (old_value == next_agino) {
2506 +- if (next_agino != NULLAGINO)
2507 ++ if (next_agino != NULLAGINO) {
2508 ++ xfs_inode_verifier_error(ip, -EFSCORRUPTED, __func__,
2509 ++ dip, sizeof(*dip), __this_address);
2510 + error = -EFSCORRUPTED;
2511 ++ }
2512 + goto out;
2513 + }
2514 +
2515 +@@ -2276,8 +2283,10 @@ xfs_iunlink(
2516 + */
2517 + next_agino = be32_to_cpu(agi->agi_unlinked[bucket_index]);
2518 + if (next_agino == agino ||
2519 +- !xfs_verify_agino_or_null(mp, agno, next_agino))
2520 ++ !xfs_verify_agino_or_null(mp, agno, next_agino)) {
2521 ++ xfs_buf_corruption_error(agibp);
2522 + return -EFSCORRUPTED;
2523 ++ }
2524 +
2525 + if (next_agino != NULLAGINO) {
2526 + struct xfs_perag *pag;
2527 +@@ -3215,6 +3224,7 @@ xfs_rename(
2528 + struct xfs_trans *tp;
2529 + struct xfs_inode *wip = NULL; /* whiteout inode */
2530 + struct xfs_inode *inodes[__XFS_SORT_INODES];
2531 ++ int i;
2532 + int num_inodes = __XFS_SORT_INODES;
2533 + bool new_parent = (src_dp != target_dp);
2534 + bool src_is_directory = S_ISDIR(VFS_I(src_ip)->i_mode);
2535 +@@ -3326,6 +3336,30 @@ xfs_rename(
2536 + }
2537 + }
2538 +
2539 ++ /*
2540 ++ * Lock the AGI buffers we need to handle bumping the nlink of the
2541 ++ * whiteout inode off the unlinked list and to handle dropping the
2542 ++ * nlink of the target inode. Per locking order rules, do this in
2543 ++ * increasing AG order and before directory block allocation tries to
2544 ++ * grab AGFs because we grab AGIs before AGFs.
2545 ++ *
2546 ++ * The (vfs) caller must ensure that if src is a directory then
2547 ++ * target_ip is either null or an empty directory.
2548 ++ */
2549 ++ for (i = 0; i < num_inodes && inodes[i] != NULL; i++) {
2550 ++ if (inodes[i] == wip ||
2551 ++ (inodes[i] == target_ip &&
2552 ++ (VFS_I(target_ip)->i_nlink == 1 || src_is_directory))) {
2553 ++ struct xfs_buf *bp;
2554 ++ xfs_agnumber_t agno;
2555 ++
2556 ++ agno = XFS_INO_TO_AGNO(mp, inodes[i]->i_ino);
2557 ++ error = xfs_read_agi(mp, tp, agno, &bp);
2558 ++ if (error)
2559 ++ goto out_trans_cancel;
2560 ++ }
2561 ++ }
2562 ++
2563 + /*
2564 + * Directory entry creation below may acquire the AGF. Remove
2565 + * the whiteout from the unlinked list first to preserve correct
2566 +diff --git a/fs/xfs/xfs_inode_item.c b/fs/xfs/xfs_inode_item.c
2567 +index bb8f076805b9e..726aa3bfd6e84 100644
2568 +--- a/fs/xfs/xfs_inode_item.c
2569 ++++ b/fs/xfs/xfs_inode_item.c
2570 +@@ -17,6 +17,7 @@
2571 + #include "xfs_trans_priv.h"
2572 + #include "xfs_buf_item.h"
2573 + #include "xfs_log.h"
2574 ++#include "xfs_error.h"
2575 +
2576 + #include <linux/iversion.h>
2577 +
2578 +@@ -828,8 +829,10 @@ xfs_inode_item_format_convert(
2579 + {
2580 + struct xfs_inode_log_format_32 *in_f32 = buf->i_addr;
2581 +
2582 +- if (buf->i_len != sizeof(*in_f32))
2583 ++ if (buf->i_len != sizeof(*in_f32)) {
2584 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL);
2585 + return -EFSCORRUPTED;
2586 ++ }
2587 +
2588 + in_f->ilf_type = in_f32->ilf_type;
2589 + in_f->ilf_size = in_f32->ilf_size;
2590 +diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
2591 +index 239c9548b1568..b6f85e488d5c1 100644
2592 +--- a/fs/xfs/xfs_iomap.c
2593 ++++ b/fs/xfs/xfs_iomap.c
2594 +@@ -765,6 +765,11 @@ xfs_iomap_write_unwritten(
2595 + */
2596 + resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1;
2597 +
2598 ++ /* Attach dquots so that bmbt splits are accounted correctly. */
2599 ++ error = xfs_qm_dqattach(ip);
2600 ++ if (error)
2601 ++ return error;
2602 ++
2603 + do {
2604 + /*
2605 + * Set up a transaction to convert the range of extents
2606 +@@ -783,6 +788,11 @@ xfs_iomap_write_unwritten(
2607 + xfs_ilock(ip, XFS_ILOCK_EXCL);
2608 + xfs_trans_ijoin(tp, ip, 0);
2609 +
2610 ++ error = xfs_trans_reserve_quota_nblks(tp, ip, resblks, 0,
2611 ++ XFS_QMOPT_RES_REGBLKS);
2612 ++ if (error)
2613 ++ goto error_on_bmapi_transaction;
2614 ++
2615 + /*
2616 + * Modify the unwritten extent state of the buffer.
2617 + */
2618 +@@ -1055,6 +1065,13 @@ xfs_file_iomap_begin(
2619 + trace_xfs_iomap_alloc(ip, offset, length, XFS_DATA_FORK, &imap);
2620 +
2621 + out_finish:
2622 ++ /*
2623 ++ * Writes that span EOF might trigger an IO size update on completion,
2624 ++ * so consider them to be dirty for the purposes of O_DSYNC even if
2625 ++ * there is no other metadata changes pending or have been made here.
2626 ++ */
2627 ++ if ((flags & IOMAP_WRITE) && offset + length > i_size_read(inode))
2628 ++ iomap->flags |= IOMAP_F_DIRTY;
2629 + return xfs_bmbt_to_iomap(ip, iomap, &imap, shared);
2630 +
2631 + out_found:
2632 +diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
2633 +index ca8c763902b96..80dd05f8f1afc 100644
2634 +--- a/fs/xfs/xfs_iops.c
2635 ++++ b/fs/xfs/xfs_iops.c
2636 +@@ -20,6 +20,7 @@
2637 + #include "xfs_symlink.h"
2638 + #include "xfs_dir2.h"
2639 + #include "xfs_iomap.h"
2640 ++#include "xfs_error.h"
2641 +
2642 + #include <linux/xattr.h>
2643 + #include <linux/posix_acl.h>
2644 +@@ -470,17 +471,20 @@ xfs_vn_get_link_inline(
2645 + struct inode *inode,
2646 + struct delayed_call *done)
2647 + {
2648 ++ struct xfs_inode *ip = XFS_I(inode);
2649 + char *link;
2650 +
2651 +- ASSERT(XFS_I(inode)->i_df.if_flags & XFS_IFINLINE);
2652 ++ ASSERT(ip->i_df.if_flags & XFS_IFINLINE);
2653 +
2654 + /*
2655 + * The VFS crashes on a NULL pointer, so return -EFSCORRUPTED if
2656 + * if_data is junk.
2657 + */
2658 +- link = XFS_I(inode)->i_df.if_u1.if_data;
2659 +- if (!link)
2660 ++ link = ip->i_df.if_u1.if_data;
2661 ++ if (!link) {
2662 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, ip->i_mount);
2663 + return ERR_PTR(-EFSCORRUPTED);
2664 ++ }
2665 + return link;
2666 + }
2667 +
2668 +diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c
2669 +index c1a514ffff555..248101876e1ec 100644
2670 +--- a/fs/xfs/xfs_log_recover.c
2671 ++++ b/fs/xfs/xfs_log_recover.c
2672 +@@ -471,7 +471,7 @@ xlog_find_verify_log_record(
2673 + xfs_warn(log->l_mp,
2674 + "Log inconsistent (didn't find previous header)");
2675 + ASSERT(0);
2676 +- error = -EIO;
2677 ++ error = -EFSCORRUPTED;
2678 + goto out;
2679 + }
2680 +
2681 +@@ -1347,10 +1347,11 @@ xlog_find_tail(
2682 + error = xlog_rseek_logrec_hdr(log, *head_blk, *head_blk, 1, buffer,
2683 + &rhead_blk, &rhead, &wrapped);
2684 + if (error < 0)
2685 +- return error;
2686 ++ goto done;
2687 + if (!error) {
2688 + xfs_warn(log->l_mp, "%s: couldn't find sync record", __func__);
2689 +- return -EIO;
2690 ++ error = -EFSCORRUPTED;
2691 ++ goto done;
2692 + }
2693 + *tail_blk = BLOCK_LSN(be64_to_cpu(rhead->h_tail_lsn));
2694 +
2695 +@@ -3166,7 +3167,7 @@ xlog_recover_inode_pass2(
2696 + default:
2697 + xfs_warn(log->l_mp, "%s: Invalid flag", __func__);
2698 + ASSERT(0);
2699 +- error = -EIO;
2700 ++ error = -EFSCORRUPTED;
2701 + goto out_release;
2702 + }
2703 + }
2704 +@@ -3247,12 +3248,12 @@ xlog_recover_dquot_pass2(
2705 + recddq = item->ri_buf[1].i_addr;
2706 + if (recddq == NULL) {
2707 + xfs_alert(log->l_mp, "NULL dquot in %s.", __func__);
2708 +- return -EIO;
2709 ++ return -EFSCORRUPTED;
2710 + }
2711 + if (item->ri_buf[1].i_len < sizeof(xfs_disk_dquot_t)) {
2712 + xfs_alert(log->l_mp, "dquot too small (%d) in %s.",
2713 + item->ri_buf[1].i_len, __func__);
2714 +- return -EIO;
2715 ++ return -EFSCORRUPTED;
2716 + }
2717 +
2718 + /*
2719 +@@ -3279,7 +3280,7 @@ xlog_recover_dquot_pass2(
2720 + if (fa) {
2721 + xfs_alert(mp, "corrupt dquot ID 0x%x in log at %pS",
2722 + dq_f->qlf_id, fa);
2723 +- return -EIO;
2724 ++ return -EFSCORRUPTED;
2725 + }
2726 + ASSERT(dq_f->qlf_len == 1);
2727 +
2728 +@@ -3537,6 +3538,7 @@ xfs_cui_copy_format(
2729 + memcpy(dst_cui_fmt, src_cui_fmt, len);
2730 + return 0;
2731 + }
2732 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL);
2733 + return -EFSCORRUPTED;
2734 + }
2735 +
2736 +@@ -3601,8 +3603,10 @@ xlog_recover_cud_pass2(
2737 + struct xfs_ail *ailp = log->l_ailp;
2738 +
2739 + cud_formatp = item->ri_buf[0].i_addr;
2740 +- if (item->ri_buf[0].i_len != sizeof(struct xfs_cud_log_format))
2741 ++ if (item->ri_buf[0].i_len != sizeof(struct xfs_cud_log_format)) {
2742 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, log->l_mp);
2743 + return -EFSCORRUPTED;
2744 ++ }
2745 + cui_id = cud_formatp->cud_cui_id;
2746 +
2747 + /*
2748 +@@ -3654,6 +3658,7 @@ xfs_bui_copy_format(
2749 + memcpy(dst_bui_fmt, src_bui_fmt, len);
2750 + return 0;
2751 + }
2752 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL);
2753 + return -EFSCORRUPTED;
2754 + }
2755 +
2756 +@@ -3677,8 +3682,10 @@ xlog_recover_bui_pass2(
2757 +
2758 + bui_formatp = item->ri_buf[0].i_addr;
2759 +
2760 +- if (bui_formatp->bui_nextents != XFS_BUI_MAX_FAST_EXTENTS)
2761 ++ if (bui_formatp->bui_nextents != XFS_BUI_MAX_FAST_EXTENTS) {
2762 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, log->l_mp);
2763 + return -EFSCORRUPTED;
2764 ++ }
2765 + buip = xfs_bui_init(mp);
2766 + error = xfs_bui_copy_format(&item->ri_buf[0], &buip->bui_format);
2767 + if (error) {
2768 +@@ -3720,8 +3727,10 @@ xlog_recover_bud_pass2(
2769 + struct xfs_ail *ailp = log->l_ailp;
2770 +
2771 + bud_formatp = item->ri_buf[0].i_addr;
2772 +- if (item->ri_buf[0].i_len != sizeof(struct xfs_bud_log_format))
2773 ++ if (item->ri_buf[0].i_len != sizeof(struct xfs_bud_log_format)) {
2774 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, log->l_mp);
2775 + return -EFSCORRUPTED;
2776 ++ }
2777 + bui_id = bud_formatp->bud_bui_id;
2778 +
2779 + /*
2780 +@@ -4018,7 +4027,7 @@ xlog_recover_commit_pass1(
2781 + xfs_warn(log->l_mp, "%s: invalid item type (%d)",
2782 + __func__, ITEM_TYPE(item));
2783 + ASSERT(0);
2784 +- return -EIO;
2785 ++ return -EFSCORRUPTED;
2786 + }
2787 + }
2788 +
2789 +@@ -4066,7 +4075,7 @@ xlog_recover_commit_pass2(
2790 + xfs_warn(log->l_mp, "%s: invalid item type (%d)",
2791 + __func__, ITEM_TYPE(item));
2792 + ASSERT(0);
2793 +- return -EIO;
2794 ++ return -EFSCORRUPTED;
2795 + }
2796 + }
2797 +
2798 +@@ -4187,7 +4196,7 @@ xlog_recover_add_to_cont_trans(
2799 + ASSERT(len <= sizeof(struct xfs_trans_header));
2800 + if (len > sizeof(struct xfs_trans_header)) {
2801 + xfs_warn(log->l_mp, "%s: bad header length", __func__);
2802 +- return -EIO;
2803 ++ return -EFSCORRUPTED;
2804 + }
2805 +
2806 + xlog_recover_add_item(&trans->r_itemq);
2807 +@@ -4243,13 +4252,13 @@ xlog_recover_add_to_trans(
2808 + xfs_warn(log->l_mp, "%s: bad header magic number",
2809 + __func__);
2810 + ASSERT(0);
2811 +- return -EIO;
2812 ++ return -EFSCORRUPTED;
2813 + }
2814 +
2815 + if (len > sizeof(struct xfs_trans_header)) {
2816 + xfs_warn(log->l_mp, "%s: bad header length", __func__);
2817 + ASSERT(0);
2818 +- return -EIO;
2819 ++ return -EFSCORRUPTED;
2820 + }
2821 +
2822 + /*
2823 +@@ -4285,7 +4294,7 @@ xlog_recover_add_to_trans(
2824 + in_f->ilf_size);
2825 + ASSERT(0);
2826 + kmem_free(ptr);
2827 +- return -EIO;
2828 ++ return -EFSCORRUPTED;
2829 + }
2830 +
2831 + item->ri_total = in_f->ilf_size;
2832 +@@ -4293,7 +4302,16 @@ xlog_recover_add_to_trans(
2833 + kmem_zalloc(item->ri_total * sizeof(xfs_log_iovec_t),
2834 + 0);
2835 + }
2836 +- ASSERT(item->ri_total > item->ri_cnt);
2837 ++
2838 ++ if (item->ri_total <= item->ri_cnt) {
2839 ++ xfs_warn(log->l_mp,
2840 ++ "log item region count (%d) overflowed size (%d)",
2841 ++ item->ri_cnt, item->ri_total);
2842 ++ ASSERT(0);
2843 ++ kmem_free(ptr);
2844 ++ return -EFSCORRUPTED;
2845 ++ }
2846 ++
2847 + /* Description region is ri_buf[0] */
2848 + item->ri_buf[item->ri_cnt].i_addr = ptr;
2849 + item->ri_buf[item->ri_cnt].i_len = len;
2850 +@@ -4380,7 +4398,7 @@ xlog_recovery_process_trans(
2851 + default:
2852 + xfs_warn(log->l_mp, "%s: bad flag 0x%x", __func__, flags);
2853 + ASSERT(0);
2854 +- error = -EIO;
2855 ++ error = -EFSCORRUPTED;
2856 + break;
2857 + }
2858 + if (error || freeit)
2859 +@@ -4460,7 +4478,7 @@ xlog_recover_process_ophdr(
2860 + xfs_warn(log->l_mp, "%s: bad clientid 0x%x",
2861 + __func__, ohead->oh_clientid);
2862 + ASSERT(0);
2863 +- return -EIO;
2864 ++ return -EFSCORRUPTED;
2865 + }
2866 +
2867 + /*
2868 +@@ -4470,7 +4488,7 @@ xlog_recover_process_ophdr(
2869 + if (dp + len > end) {
2870 + xfs_warn(log->l_mp, "%s: bad length 0x%x", __func__, len);
2871 + WARN_ON(1);
2872 +- return -EIO;
2873 ++ return -EFSCORRUPTED;
2874 + }
2875 +
2876 + trans = xlog_recover_ophdr_to_trans(rhash, rhead, ohead);
2877 +@@ -5172,8 +5190,10 @@ xlog_recover_process(
2878 + * If the filesystem is CRC enabled, this mismatch becomes a
2879 + * fatal log corruption failure.
2880 + */
2881 +- if (xfs_sb_version_hascrc(&log->l_mp->m_sb))
2882 ++ if (xfs_sb_version_hascrc(&log->l_mp->m_sb)) {
2883 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, log->l_mp);
2884 + return -EFSCORRUPTED;
2885 ++ }
2886 + }
2887 +
2888 + xlog_unpack_data(rhead, dp, log);
2889 +@@ -5200,7 +5220,7 @@ xlog_valid_rec_header(
2890 + (be32_to_cpu(rhead->h_version) & (~XLOG_VERSION_OKBITS))))) {
2891 + xfs_warn(log->l_mp, "%s: unrecognised log version (%d).",
2892 + __func__, be32_to_cpu(rhead->h_version));
2893 +- return -EIO;
2894 ++ return -EFSCORRUPTED;
2895 + }
2896 +
2897 + /* LR body must have data or it wouldn't have been written */
2898 +@@ -5296,8 +5316,12 @@ xlog_do_recovery_pass(
2899 + "invalid iclog size (%d bytes), using lsunit (%d bytes)",
2900 + h_size, log->l_mp->m_logbsize);
2901 + h_size = log->l_mp->m_logbsize;
2902 +- } else
2903 +- return -EFSCORRUPTED;
2904 ++ } else {
2905 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW,
2906 ++ log->l_mp);
2907 ++ error = -EFSCORRUPTED;
2908 ++ goto bread_err1;
2909 ++ }
2910 + }
2911 +
2912 + if ((be32_to_cpu(rhead->h_version) & XLOG_VERSION_2) &&
2913 +diff --git a/fs/xfs/xfs_message.c b/fs/xfs/xfs_message.c
2914 +index 9804efe525a93..c57e8ad397125 100644
2915 +--- a/fs/xfs/xfs_message.c
2916 ++++ b/fs/xfs/xfs_message.c
2917 +@@ -105,7 +105,7 @@ assfail(char *expr, char *file, int line)
2918 + }
2919 +
2920 + void
2921 +-xfs_hex_dump(void *p, int length)
2922 ++xfs_hex_dump(const void *p, int length)
2923 + {
2924 + print_hex_dump(KERN_ALERT, "", DUMP_PREFIX_OFFSET, 16, 1, p, length, 1);
2925 + }
2926 +diff --git a/fs/xfs/xfs_message.h b/fs/xfs/xfs_message.h
2927 +index 34447dca97d13..7f040b04b7393 100644
2928 +--- a/fs/xfs/xfs_message.h
2929 ++++ b/fs/xfs/xfs_message.h
2930 +@@ -60,6 +60,6 @@ do { \
2931 + extern void assfail(char *expr, char *f, int l);
2932 + extern void asswarn(char *expr, char *f, int l);
2933 +
2934 +-extern void xfs_hex_dump(void *p, int length);
2935 ++extern void xfs_hex_dump(const void *p, int length);
2936 +
2937 + #endif /* __XFS_MESSAGE_H */
2938 +diff --git a/fs/xfs/xfs_mount.c b/fs/xfs/xfs_mount.c
2939 +index 5a0ce0c2c4bbd..bbcf48a625b2a 100644
2940 +--- a/fs/xfs/xfs_mount.c
2941 ++++ b/fs/xfs/xfs_mount.c
2942 +@@ -31,7 +31,7 @@
2943 + #include "xfs_reflink.h"
2944 + #include "xfs_extent_busy.h"
2945 + #include "xfs_health.h"
2946 +-
2947 ++#include "xfs_trace.h"
2948 +
2949 + static DEFINE_MUTEX(xfs_uuid_table_mutex);
2950 + static int xfs_uuid_table_size;
2951 +@@ -365,66 +365,119 @@ release_buf:
2952 + }
2953 +
2954 + /*
2955 +- * Update alignment values based on mount options and sb values
2956 ++ * If the sunit/swidth change would move the precomputed root inode value, we
2957 ++ * must reject the ondisk change because repair will stumble over that.
2958 ++ * However, we allow the mount to proceed because we never rejected this
2959 ++ * combination before. Returns true to update the sb, false otherwise.
2960 ++ */
2961 ++static inline int
2962 ++xfs_check_new_dalign(
2963 ++ struct xfs_mount *mp,
2964 ++ int new_dalign,
2965 ++ bool *update_sb)
2966 ++{
2967 ++ struct xfs_sb *sbp = &mp->m_sb;
2968 ++ xfs_ino_t calc_ino;
2969 ++
2970 ++ calc_ino = xfs_ialloc_calc_rootino(mp, new_dalign);
2971 ++ trace_xfs_check_new_dalign(mp, new_dalign, calc_ino);
2972 ++
2973 ++ if (sbp->sb_rootino == calc_ino) {
2974 ++ *update_sb = true;
2975 ++ return 0;
2976 ++ }
2977 ++
2978 ++ xfs_warn(mp,
2979 ++"Cannot change stripe alignment; would require moving root inode.");
2980 ++
2981 ++ /*
2982 ++ * XXX: Next time we add a new incompat feature, this should start
2983 ++ * returning -EINVAL to fail the mount. Until then, spit out a warning
2984 ++ * that we're ignoring the administrator's instructions.
2985 ++ */
2986 ++ xfs_warn(mp, "Skipping superblock stripe alignment update.");
2987 ++ *update_sb = false;
2988 ++ return 0;
2989 ++}
2990 ++
2991 ++/*
2992 ++ * If we were provided with new sunit/swidth values as mount options, make sure
2993 ++ * that they pass basic alignment and superblock feature checks, and convert
2994 ++ * them into the same units (FSB) that everything else expects. This step
2995 ++ * /must/ be done before computing the inode geometry.
2996 + */
2997 + STATIC int
2998 +-xfs_update_alignment(xfs_mount_t *mp)
2999 ++xfs_validate_new_dalign(
3000 ++ struct xfs_mount *mp)
3001 + {
3002 +- xfs_sb_t *sbp = &(mp->m_sb);
3003 ++ if (mp->m_dalign == 0)
3004 ++ return 0;
3005 +
3006 +- if (mp->m_dalign) {
3007 ++ /*
3008 ++ * If stripe unit and stripe width are not multiples
3009 ++ * of the fs blocksize turn off alignment.
3010 ++ */
3011 ++ if ((BBTOB(mp->m_dalign) & mp->m_blockmask) ||
3012 ++ (BBTOB(mp->m_swidth) & mp->m_blockmask)) {
3013 ++ xfs_warn(mp,
3014 ++ "alignment check failed: sunit/swidth vs. blocksize(%d)",
3015 ++ mp->m_sb.sb_blocksize);
3016 ++ return -EINVAL;
3017 ++ } else {
3018 + /*
3019 +- * If stripe unit and stripe width are not multiples
3020 +- * of the fs blocksize turn off alignment.
3021 ++ * Convert the stripe unit and width to FSBs.
3022 + */
3023 +- if ((BBTOB(mp->m_dalign) & mp->m_blockmask) ||
3024 +- (BBTOB(mp->m_swidth) & mp->m_blockmask)) {
3025 ++ mp->m_dalign = XFS_BB_TO_FSBT(mp, mp->m_dalign);
3026 ++ if (mp->m_dalign && (mp->m_sb.sb_agblocks % mp->m_dalign)) {
3027 + xfs_warn(mp,
3028 +- "alignment check failed: sunit/swidth vs. blocksize(%d)",
3029 +- sbp->sb_blocksize);
3030 ++ "alignment check failed: sunit/swidth vs. agsize(%d)",
3031 ++ mp->m_sb.sb_agblocks);
3032 + return -EINVAL;
3033 +- } else {
3034 +- /*
3035 +- * Convert the stripe unit and width to FSBs.
3036 +- */
3037 +- mp->m_dalign = XFS_BB_TO_FSBT(mp, mp->m_dalign);
3038 +- if (mp->m_dalign && (sbp->sb_agblocks % mp->m_dalign)) {
3039 +- xfs_warn(mp,
3040 +- "alignment check failed: sunit/swidth vs. agsize(%d)",
3041 +- sbp->sb_agblocks);
3042 +- return -EINVAL;
3043 +- } else if (mp->m_dalign) {
3044 +- mp->m_swidth = XFS_BB_TO_FSBT(mp, mp->m_swidth);
3045 +- } else {
3046 +- xfs_warn(mp,
3047 +- "alignment check failed: sunit(%d) less than bsize(%d)",
3048 +- mp->m_dalign, sbp->sb_blocksize);
3049 +- return -EINVAL;
3050 +- }
3051 +- }
3052 +-
3053 +- /*
3054 +- * Update superblock with new values
3055 +- * and log changes
3056 +- */
3057 +- if (xfs_sb_version_hasdalign(sbp)) {
3058 +- if (sbp->sb_unit != mp->m_dalign) {
3059 +- sbp->sb_unit = mp->m_dalign;
3060 +- mp->m_update_sb = true;
3061 +- }
3062 +- if (sbp->sb_width != mp->m_swidth) {
3063 +- sbp->sb_width = mp->m_swidth;
3064 +- mp->m_update_sb = true;
3065 +- }
3066 ++ } else if (mp->m_dalign) {
3067 ++ mp->m_swidth = XFS_BB_TO_FSBT(mp, mp->m_swidth);
3068 + } else {
3069 + xfs_warn(mp,
3070 +- "cannot change alignment: superblock does not support data alignment");
3071 ++ "alignment check failed: sunit(%d) less than bsize(%d)",
3072 ++ mp->m_dalign, mp->m_sb.sb_blocksize);
3073 + return -EINVAL;
3074 + }
3075 ++ }
3076 ++
3077 ++ if (!xfs_sb_version_hasdalign(&mp->m_sb)) {
3078 ++ xfs_warn(mp,
3079 ++"cannot change alignment: superblock does not support data alignment");
3080 ++ return -EINVAL;
3081 ++ }
3082 ++
3083 ++ return 0;
3084 ++}
3085 ++
3086 ++/* Update alignment values based on mount options and sb values. */
3087 ++STATIC int
3088 ++xfs_update_alignment(
3089 ++ struct xfs_mount *mp)
3090 ++{
3091 ++ struct xfs_sb *sbp = &mp->m_sb;
3092 ++
3093 ++ if (mp->m_dalign) {
3094 ++ bool update_sb;
3095 ++ int error;
3096 ++
3097 ++ if (sbp->sb_unit == mp->m_dalign &&
3098 ++ sbp->sb_width == mp->m_swidth)
3099 ++ return 0;
3100 ++
3101 ++ error = xfs_check_new_dalign(mp, mp->m_dalign, &update_sb);
3102 ++ if (error || !update_sb)
3103 ++ return error;
3104 ++
3105 ++ sbp->sb_unit = mp->m_dalign;
3106 ++ sbp->sb_width = mp->m_swidth;
3107 ++ mp->m_update_sb = true;
3108 + } else if ((mp->m_flags & XFS_MOUNT_NOALIGN) != XFS_MOUNT_NOALIGN &&
3109 + xfs_sb_version_hasdalign(&mp->m_sb)) {
3110 +- mp->m_dalign = sbp->sb_unit;
3111 +- mp->m_swidth = sbp->sb_width;
3112 ++ mp->m_dalign = sbp->sb_unit;
3113 ++ mp->m_swidth = sbp->sb_width;
3114 + }
3115 +
3116 + return 0;
3117 +@@ -692,12 +745,12 @@ xfs_mountfs(
3118 + }
3119 +
3120 + /*
3121 +- * Check if sb_agblocks is aligned at stripe boundary
3122 +- * If sb_agblocks is NOT aligned turn off m_dalign since
3123 +- * allocator alignment is within an ag, therefore ag has
3124 +- * to be aligned at stripe boundary.
3125 ++ * If we were given new sunit/swidth options, do some basic validation
3126 ++ * checks and convert the incore dalign and swidth values to the
3127 ++ * same units (FSB) that everything else uses. This /must/ happen
3128 ++ * before computing the inode geometry.
3129 + */
3130 +- error = xfs_update_alignment(mp);
3131 ++ error = xfs_validate_new_dalign(mp);
3132 + if (error)
3133 + goto out;
3134 +
3135 +@@ -708,6 +761,17 @@ xfs_mountfs(
3136 + xfs_rmapbt_compute_maxlevels(mp);
3137 + xfs_refcountbt_compute_maxlevels(mp);
3138 +
3139 ++ /*
3140 ++ * Check if sb_agblocks is aligned at stripe boundary. If sb_agblocks
3141 ++ * is NOT aligned turn off m_dalign since allocator alignment is within
3142 ++ * an ag, therefore ag has to be aligned at stripe boundary. Note that
3143 ++ * we must compute the free space and rmap btree geometry before doing
3144 ++ * this.
3145 ++ */
3146 ++ error = xfs_update_alignment(mp);
3147 ++ if (error)
3148 ++ goto out;
3149 ++
3150 + /* enable fail_at_unmount as default */
3151 + mp->m_fail_unmount = true;
3152 +
3153 +diff --git a/fs/xfs/xfs_pnfs.c b/fs/xfs/xfs_pnfs.c
3154 +index f63fe8d924a36..058af699e046c 100644
3155 +--- a/fs/xfs/xfs_pnfs.c
3156 ++++ b/fs/xfs/xfs_pnfs.c
3157 +@@ -147,11 +147,11 @@ xfs_fs_map_blocks(
3158 + if (error)
3159 + goto out_unlock;
3160 +
3161 ++ ASSERT(!nimaps || imap.br_startblock != DELAYSTARTBLOCK);
3162 ++
3163 + if (write) {
3164 + enum xfs_prealloc_flags flags = 0;
3165 +
3166 +- ASSERT(imap.br_startblock != DELAYSTARTBLOCK);
3167 +-
3168 + if (!nimaps || imap.br_startblock == HOLESTARTBLOCK) {
3169 + /*
3170 + * xfs_iomap_write_direct() expects to take ownership of
3171 +diff --git a/fs/xfs/xfs_qm.c b/fs/xfs/xfs_qm.c
3172 +index ecd8ce152ab1f..66ea8e4fca86c 100644
3173 +--- a/fs/xfs/xfs_qm.c
3174 ++++ b/fs/xfs/xfs_qm.c
3175 +@@ -22,6 +22,7 @@
3176 + #include "xfs_qm.h"
3177 + #include "xfs_trace.h"
3178 + #include "xfs_icache.h"
3179 ++#include "xfs_error.h"
3180 +
3181 + /*
3182 + * The global quota manager. There is only one of these for the entire
3183 +@@ -754,11 +755,19 @@ xfs_qm_qino_alloc(
3184 + if ((flags & XFS_QMOPT_PQUOTA) &&
3185 + (mp->m_sb.sb_gquotino != NULLFSINO)) {
3186 + ino = mp->m_sb.sb_gquotino;
3187 +- ASSERT(mp->m_sb.sb_pquotino == NULLFSINO);
3188 ++ if (mp->m_sb.sb_pquotino != NULLFSINO) {
3189 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW,
3190 ++ mp);
3191 ++ return -EFSCORRUPTED;
3192 ++ }
3193 + } else if ((flags & XFS_QMOPT_GQUOTA) &&
3194 + (mp->m_sb.sb_pquotino != NULLFSINO)) {
3195 + ino = mp->m_sb.sb_pquotino;
3196 +- ASSERT(mp->m_sb.sb_gquotino == NULLFSINO);
3197 ++ if (mp->m_sb.sb_gquotino != NULLFSINO) {
3198 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW,
3199 ++ mp);
3200 ++ return -EFSCORRUPTED;
3201 ++ }
3202 + }
3203 + if (ino != NULLFSINO) {
3204 + error = xfs_iget(mp, NULL, ino, 0, 0, ip);
3205 +diff --git a/fs/xfs/xfs_refcount_item.c b/fs/xfs/xfs_refcount_item.c
3206 +index 2328268e62459..d5708d40ad877 100644
3207 +--- a/fs/xfs/xfs_refcount_item.c
3208 ++++ b/fs/xfs/xfs_refcount_item.c
3209 +@@ -17,7 +17,7 @@
3210 + #include "xfs_refcount_item.h"
3211 + #include "xfs_log.h"
3212 + #include "xfs_refcount.h"
3213 +-
3214 ++#include "xfs_error.h"
3215 +
3216 + kmem_zone_t *xfs_cui_zone;
3217 + kmem_zone_t *xfs_cud_zone;
3218 +@@ -497,7 +497,7 @@ xfs_cui_recover(
3219 + */
3220 + set_bit(XFS_CUI_RECOVERED, &cuip->cui_flags);
3221 + xfs_cui_release(cuip);
3222 +- return -EIO;
3223 ++ return -EFSCORRUPTED;
3224 + }
3225 + }
3226 +
3227 +@@ -536,6 +536,7 @@ xfs_cui_recover(
3228 + type = refc_type;
3229 + break;
3230 + default:
3231 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, mp);
3232 + error = -EFSCORRUPTED;
3233 + goto abort_error;
3234 + }
3235 +diff --git a/fs/xfs/xfs_rmap_item.c b/fs/xfs/xfs_rmap_item.c
3236 +index 8939e0ea09cd5..02f84d9a511c3 100644
3237 +--- a/fs/xfs/xfs_rmap_item.c
3238 ++++ b/fs/xfs/xfs_rmap_item.c
3239 +@@ -17,7 +17,7 @@
3240 + #include "xfs_rmap_item.h"
3241 + #include "xfs_log.h"
3242 + #include "xfs_rmap.h"
3243 +-
3244 ++#include "xfs_error.h"
3245 +
3246 + kmem_zone_t *xfs_rui_zone;
3247 + kmem_zone_t *xfs_rud_zone;
3248 +@@ -171,8 +171,10 @@ xfs_rui_copy_format(
3249 + src_rui_fmt = buf->i_addr;
3250 + len = xfs_rui_log_format_sizeof(src_rui_fmt->rui_nextents);
3251 +
3252 +- if (buf->i_len != len)
3253 ++ if (buf->i_len != len) {
3254 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL);
3255 + return -EFSCORRUPTED;
3256 ++ }
3257 +
3258 + memcpy(dst_rui_fmt, src_rui_fmt, len);
3259 + return 0;
3260 +@@ -539,7 +541,7 @@ xfs_rui_recover(
3261 + */
3262 + set_bit(XFS_RUI_RECOVERED, &ruip->rui_flags);
3263 + xfs_rui_release(ruip);
3264 +- return -EIO;
3265 ++ return -EFSCORRUPTED;
3266 + }
3267 + }
3268 +
3269 +@@ -581,6 +583,7 @@ xfs_rui_recover(
3270 + type = XFS_RMAP_FREE;
3271 + break;
3272 + default:
3273 ++ XFS_ERROR_REPORT(__func__, XFS_ERRLEVEL_LOW, NULL);
3274 + error = -EFSCORRUPTED;
3275 + goto abort_error;
3276 + }
3277 +diff --git a/fs/xfs/xfs_trace.h b/fs/xfs/xfs_trace.h
3278 +index eaae275ed4308..ffb398c1de698 100644
3279 +--- a/fs/xfs/xfs_trace.h
3280 ++++ b/fs/xfs/xfs_trace.h
3281 +@@ -3609,6 +3609,27 @@ DEFINE_KMEM_EVENT(kmem_alloc_large);
3282 + DEFINE_KMEM_EVENT(kmem_realloc);
3283 + DEFINE_KMEM_EVENT(kmem_zone_alloc);
3284 +
3285 ++TRACE_EVENT(xfs_check_new_dalign,
3286 ++ TP_PROTO(struct xfs_mount *mp, int new_dalign, xfs_ino_t calc_rootino),
3287 ++ TP_ARGS(mp, new_dalign, calc_rootino),
3288 ++ TP_STRUCT__entry(
3289 ++ __field(dev_t, dev)
3290 ++ __field(int, new_dalign)
3291 ++ __field(xfs_ino_t, sb_rootino)
3292 ++ __field(xfs_ino_t, calc_rootino)
3293 ++ ),
3294 ++ TP_fast_assign(
3295 ++ __entry->dev = mp->m_super->s_dev;
3296 ++ __entry->new_dalign = new_dalign;
3297 ++ __entry->sb_rootino = mp->m_sb.sb_rootino;
3298 ++ __entry->calc_rootino = calc_rootino;
3299 ++ ),
3300 ++ TP_printk("dev %d:%d new_dalign %d sb_rootino %llu calc_rootino %llu",
3301 ++ MAJOR(__entry->dev), MINOR(__entry->dev),
3302 ++ __entry->new_dalign, __entry->sb_rootino,
3303 ++ __entry->calc_rootino)
3304 ++)
3305 ++
3306 + #endif /* _TRACE_XFS_H */
3307 +
3308 + #undef TRACE_INCLUDE_PATH
3309 +diff --git a/include/linux/iomap.h b/include/linux/iomap.h
3310 +index 53b16f104081b..74e05e7b67f50 100644
3311 +--- a/include/linux/iomap.h
3312 ++++ b/include/linux/iomap.h
3313 +@@ -32,6 +32,8 @@ struct vm_fault;
3314 + *
3315 + * IOMAP_F_DIRTY indicates the inode has uncommitted metadata needed to access
3316 + * written data and requires fdatasync to commit them to persistent storage.
3317 ++ * This needs to take into account metadata changes that *may* be made at IO
3318 ++ * completion, such as file size updates from direct IO.
3319 + */
3320 + #define IOMAP_F_NEW 0x01 /* blocks have been newly allocated */
3321 + #define IOMAP_F_DIRTY 0x02 /* uncommitted metadata */
3322 +diff --git a/include/linux/sched/task_stack.h b/include/linux/sched/task_stack.h
3323 +index d10150587d819..1009b6b5ce403 100644
3324 +--- a/include/linux/sched/task_stack.h
3325 ++++ b/include/linux/sched/task_stack.h
3326 +@@ -16,7 +16,7 @@
3327 + * try_get_task_stack() instead. task_stack_page will return a pointer
3328 + * that could get freed out from under you.
3329 + */
3330 +-static inline void *task_stack_page(const struct task_struct *task)
3331 ++static __always_inline void *task_stack_page(const struct task_struct *task)
3332 + {
3333 + return task->stack;
3334 + }
3335 +diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
3336 +index 2b78cc734719a..10f209d54f18a 100644
3337 +--- a/include/linux/serial_core.h
3338 ++++ b/include/linux/serial_core.h
3339 +@@ -297,6 +297,23 @@ struct uart_state {
3340 + /* number of characters left in xmit buffer before we ask for more */
3341 + #define WAKEUP_CHARS 256
3342 +
3343 ++/**
3344 ++ * uart_xmit_advance - Advance xmit buffer and account Tx'ed chars
3345 ++ * @up: uart_port structure describing the port
3346 ++ * @chars: number of characters sent
3347 ++ *
3348 ++ * This function advances the tail of circular xmit buffer by the number of
3349 ++ * @chars transmitted and handles accounting of transmitted bytes (into
3350 ++ * @up's icount.tx).
3351 ++ */
3352 ++static inline void uart_xmit_advance(struct uart_port *up, unsigned int chars)
3353 ++{
3354 ++ struct circ_buf *xmit = &up->state->xmit;
3355 ++
3356 ++ xmit->tail = (xmit->tail + chars) & (UART_XMIT_SIZE - 1);
3357 ++ up->icount.tx += chars;
3358 ++}
3359 ++
3360 + struct module;
3361 + struct tty_driver;
3362 +
3363 +diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c
3364 +index aa7577b189e92..9e847e71ceddf 100644
3365 +--- a/kernel/cgroup/cgroup-v1.c
3366 ++++ b/kernel/cgroup/cgroup-v1.c
3367 +@@ -15,6 +15,7 @@
3368 + #include <linux/pid_namespace.h>
3369 + #include <linux/cgroupstats.h>
3370 + #include <linux/fs_parser.h>
3371 ++#include <linux/cpu.h>
3372 +
3373 + #include <trace/events/cgroup.h>
3374 +
3375 +@@ -62,6 +63,7 @@ int cgroup_attach_task_all(struct task_struct *from, struct task_struct *tsk)
3376 + int retval = 0;
3377 +
3378 + mutex_lock(&cgroup_mutex);
3379 ++ cpus_read_lock();
3380 + percpu_down_write(&cgroup_threadgroup_rwsem);
3381 + for_each_root(root) {
3382 + struct cgroup *from_cgrp;
3383 +@@ -78,6 +80,7 @@ int cgroup_attach_task_all(struct task_struct *from, struct task_struct *tsk)
3384 + break;
3385 + }
3386 + percpu_up_write(&cgroup_threadgroup_rwsem);
3387 ++ cpus_read_unlock();
3388 + mutex_unlock(&cgroup_mutex);
3389 +
3390 + return retval;
3391 +diff --git a/kernel/trace/trace_preemptirq.c b/kernel/trace/trace_preemptirq.c
3392 +index 26b06b09c9f68..e9645f829b94c 100644
3393 +--- a/kernel/trace/trace_preemptirq.c
3394 ++++ b/kernel/trace/trace_preemptirq.c
3395 +@@ -56,14 +56,14 @@ __visible void trace_hardirqs_on_caller(unsigned long caller_addr)
3396 + this_cpu_write(tracing_irq_cpu, 0);
3397 + }
3398 +
3399 +- lockdep_hardirqs_on(CALLER_ADDR0);
3400 ++ lockdep_hardirqs_on(caller_addr);
3401 + }
3402 + EXPORT_SYMBOL(trace_hardirqs_on_caller);
3403 + NOKPROBE_SYMBOL(trace_hardirqs_on_caller);
3404 +
3405 + __visible void trace_hardirqs_off_caller(unsigned long caller_addr)
3406 + {
3407 +- lockdep_hardirqs_off(CALLER_ADDR0);
3408 ++ lockdep_hardirqs_off(caller_addr);
3409 +
3410 + if (!this_cpu_read(tracing_irq_cpu)) {
3411 + this_cpu_write(tracing_irq_cpu, 1);
3412 +diff --git a/kernel/workqueue.c b/kernel/workqueue.c
3413 +index e90f37e22202a..dd96391b44de0 100644
3414 +--- a/kernel/workqueue.c
3415 ++++ b/kernel/workqueue.c
3416 +@@ -3049,10 +3049,8 @@ static bool __flush_work(struct work_struct *work, bool from_cancel)
3417 + if (WARN_ON(!work->func))
3418 + return false;
3419 +
3420 +- if (!from_cancel) {
3421 +- lock_map_acquire(&work->lockdep_map);
3422 +- lock_map_release(&work->lockdep_map);
3423 +- }
3424 ++ lock_map_acquire(&work->lockdep_map);
3425 ++ lock_map_release(&work->lockdep_map);
3426 +
3427 + if (start_flush_work(work, &barr, from_cancel)) {
3428 + wait_for_completion(&barr.done);
3429 +diff --git a/mm/slub.c b/mm/slub.c
3430 +index 5211496f6d24f..17e663cf38f69 100644
3431 +--- a/mm/slub.c
3432 ++++ b/mm/slub.c
3433 +@@ -5743,7 +5743,8 @@ static char *create_unique_id(struct kmem_cache *s)
3434 + char *name = kmalloc(ID_STR_LENGTH, GFP_KERNEL);
3435 + char *p = name;
3436 +
3437 +- BUG_ON(!name);
3438 ++ if (!name)
3439 ++ return ERR_PTR(-ENOMEM);
3440 +
3441 + *p++ = ':';
3442 + /*
3443 +@@ -5825,6 +5826,8 @@ static int sysfs_slab_add(struct kmem_cache *s)
3444 + * for the symlinks.
3445 + */
3446 + name = create_unique_id(s);
3447 ++ if (IS_ERR(name))
3448 ++ return PTR_ERR(name);
3449 + }
3450 +
3451 + s->kobj.kset = kset;
3452 +diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
3453 +index ddb988c339c17..f6853fc0fcc00 100644
3454 +--- a/net/bridge/netfilter/ebtables.c
3455 ++++ b/net/bridge/netfilter/ebtables.c
3456 +@@ -999,8 +999,10 @@ static int do_replace_finish(struct net *net, struct ebt_replace *repl,
3457 + goto free_iterate;
3458 + }
3459 +
3460 +- if (repl->valid_hooks != t->valid_hooks)
3461 ++ if (repl->valid_hooks != t->valid_hooks) {
3462 ++ ret = -EINVAL;
3463 + goto free_unlock;
3464 ++ }
3465 +
3466 + if (repl->num_counters && repl->num_counters != t->private->nentries) {
3467 + ret = -EINVAL;
3468 +diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
3469 +index 344b2c22e75b5..c353162e81aea 100644
3470 +--- a/net/mac80211/scan.c
3471 ++++ b/net/mac80211/scan.c
3472 +@@ -431,10 +431,6 @@ static void __ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
3473 + scan_req = rcu_dereference_protected(local->scan_req,
3474 + lockdep_is_held(&local->mtx));
3475 +
3476 +- if (scan_req != local->int_scan_req) {
3477 +- local->scan_info.aborted = aborted;
3478 +- cfg80211_scan_done(scan_req, &local->scan_info);
3479 +- }
3480 + RCU_INIT_POINTER(local->scan_req, NULL);
3481 +
3482 + scan_sdata = rcu_dereference_protected(local->scan_sdata,
3483 +@@ -444,6 +440,13 @@ static void __ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
3484 + local->scanning = 0;
3485 + local->scan_chandef.chan = NULL;
3486 +
3487 ++ synchronize_rcu();
3488 ++
3489 ++ if (scan_req != local->int_scan_req) {
3490 ++ local->scan_info.aborted = aborted;
3491 ++ cfg80211_scan_done(scan_req, &local->scan_info);
3492 ++ }
3493 ++
3494 + /* Set power back to normal operating levels. */
3495 + ieee80211_hw_config(local, 0);
3496 +
3497 +diff --git a/net/netfilter/nf_conntrack_irc.c b/net/netfilter/nf_conntrack_irc.c
3498 +index 26245419ef4a9..65b5b05fe38d3 100644
3499 +--- a/net/netfilter/nf_conntrack_irc.c
3500 ++++ b/net/netfilter/nf_conntrack_irc.c
3501 +@@ -148,15 +148,37 @@ static int help(struct sk_buff *skb, unsigned int protoff,
3502 + data = ib_ptr;
3503 + data_limit = ib_ptr + skb->len - dataoff;
3504 +
3505 +- /* strlen("\1DCC SENT t AAAAAAAA P\1\n")=24
3506 +- * 5+MINMATCHLEN+strlen("t AAAAAAAA P\1\n")=14 */
3507 +- while (data < data_limit - (19 + MINMATCHLEN)) {
3508 +- if (memcmp(data, "\1DCC ", 5)) {
3509 ++ /* Skip any whitespace */
3510 ++ while (data < data_limit - 10) {
3511 ++ if (*data == ' ' || *data == '\r' || *data == '\n')
3512 ++ data++;
3513 ++ else
3514 ++ break;
3515 ++ }
3516 ++
3517 ++ /* strlen("PRIVMSG x ")=10 */
3518 ++ if (data < data_limit - 10) {
3519 ++ if (strncasecmp("PRIVMSG ", data, 8))
3520 ++ goto out;
3521 ++ data += 8;
3522 ++ }
3523 ++
3524 ++ /* strlen(" :\1DCC SENT t AAAAAAAA P\1\n")=26
3525 ++ * 7+MINMATCHLEN+strlen("t AAAAAAAA P\1\n")=26
3526 ++ */
3527 ++ while (data < data_limit - (21 + MINMATCHLEN)) {
3528 ++ /* Find first " :", the start of message */
3529 ++ if (memcmp(data, " :", 2)) {
3530 + data++;
3531 + continue;
3532 + }
3533 ++ data += 2;
3534 ++
3535 ++ /* then check that place only for the DCC command */
3536 ++ if (memcmp(data, "\1DCC ", 5))
3537 ++ goto out;
3538 + data += 5;
3539 +- /* we have at least (19+MINMATCHLEN)-5 bytes valid data left */
3540 ++ /* we have at least (21+MINMATCHLEN)-(2+5) bytes valid data left */
3541 +
3542 + iph = ip_hdr(skb);
3543 + pr_debug("DCC found in master %pI4:%u %pI4:%u\n",
3544 +@@ -172,7 +194,7 @@ static int help(struct sk_buff *skb, unsigned int protoff,
3545 + pr_debug("DCC %s detected\n", dccprotos[i]);
3546 +
3547 + /* we have at least
3548 +- * (19+MINMATCHLEN)-5-dccprotos[i].matchlen bytes valid
3549 ++ * (21+MINMATCHLEN)-7-dccprotos[i].matchlen bytes valid
3550 + * data left (== 14/13 bytes) */
3551 + if (parse_dcc(data, data_limit, &dcc_ip,
3552 + &dcc_port, &addr_beg_p, &addr_end_p)) {
3553 +diff --git a/net/netfilter/nf_conntrack_sip.c b/net/netfilter/nf_conntrack_sip.c
3554 +index b83dc9bf0a5dd..78fd9122b70c7 100644
3555 +--- a/net/netfilter/nf_conntrack_sip.c
3556 ++++ b/net/netfilter/nf_conntrack_sip.c
3557 +@@ -477,7 +477,7 @@ static int ct_sip_walk_headers(const struct nf_conn *ct, const char *dptr,
3558 + return ret;
3559 + if (ret == 0)
3560 + break;
3561 +- dataoff += *matchoff;
3562 ++ dataoff = *matchoff;
3563 + }
3564 + *in_header = 0;
3565 + }
3566 +@@ -489,7 +489,7 @@ static int ct_sip_walk_headers(const struct nf_conn *ct, const char *dptr,
3567 + break;
3568 + if (ret == 0)
3569 + return ret;
3570 +- dataoff += *matchoff;
3571 ++ dataoff = *matchoff;
3572 + }
3573 +
3574 + if (in_header)
3575 +diff --git a/net/netfilter/nfnetlink_osf.c b/net/netfilter/nfnetlink_osf.c
3576 +index 79fbf37291f38..51e3953b414c0 100644
3577 +--- a/net/netfilter/nfnetlink_osf.c
3578 ++++ b/net/netfilter/nfnetlink_osf.c
3579 +@@ -269,6 +269,7 @@ bool nf_osf_find(const struct sk_buff *skb,
3580 + struct nf_osf_hdr_ctx ctx;
3581 + const struct tcphdr *tcp;
3582 + struct tcphdr _tcph;
3583 ++ bool found = false;
3584 +
3585 + memset(&ctx, 0, sizeof(ctx));
3586 +
3587 +@@ -283,10 +284,11 @@ bool nf_osf_find(const struct sk_buff *skb,
3588 +
3589 + data->genre = f->genre;
3590 + data->version = f->version;
3591 ++ found = true;
3592 + break;
3593 + }
3594 +
3595 +- return true;
3596 ++ return found;
3597 + }
3598 + EXPORT_SYMBOL_GPL(nf_osf_find);
3599 +
3600 +diff --git a/net/rxrpc/call_event.c b/net/rxrpc/call_event.c
3601 +index 8574e7066d94c..b5f173960725b 100644
3602 +--- a/net/rxrpc/call_event.c
3603 ++++ b/net/rxrpc/call_event.c
3604 +@@ -166,7 +166,7 @@ static void rxrpc_resend(struct rxrpc_call *call, unsigned long now_j)
3605 + _enter("{%d,%d}", call->tx_hard_ack, call->tx_top);
3606 +
3607 + now = ktime_get_real();
3608 +- max_age = ktime_sub(now, jiffies_to_usecs(call->peer->rto_j));
3609 ++ max_age = ktime_sub_us(now, jiffies_to_usecs(call->peer->rto_j));
3610 +
3611 + spin_lock_bh(&call->lock);
3612 +
3613 +diff --git a/net/rxrpc/local_object.c b/net/rxrpc/local_object.c
3614 +index 01135e54d95d2..fc784fcc3a947 100644
3615 +--- a/net/rxrpc/local_object.c
3616 ++++ b/net/rxrpc/local_object.c
3617 +@@ -448,6 +448,9 @@ static void rxrpc_local_processor(struct work_struct *work)
3618 + container_of(work, struct rxrpc_local, processor);
3619 + bool again;
3620 +
3621 ++ if (local->dead)
3622 ++ return;
3623 ++
3624 + trace_rxrpc_local(local->debug_id, rxrpc_local_processing,
3625 + atomic_read(&local->usage), NULL);
3626 +
3627 +diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
3628 +index 919c7fa5f02d6..48a8c7daa635e 100644
3629 +--- a/net/sched/cls_api.c
3630 ++++ b/net/sched/cls_api.c
3631 +@@ -2098,6 +2098,7 @@ replay:
3632 + }
3633 +
3634 + if (chain->tmplt_ops && chain->tmplt_ops != tp->ops) {
3635 ++ tfilter_put(tp, fh);
3636 + NL_SET_ERR_MSG(extack, "Chain template is set to a different filter kind");
3637 + err = -EINVAL;
3638 + goto errout;
3639 +diff --git a/net/sched/sch_taprio.c b/net/sched/sch_taprio.c
3640 +index 4c26f7fb32b34..506ebae1f72cf 100644
3641 +--- a/net/sched/sch_taprio.c
3642 ++++ b/net/sched/sch_taprio.c
3643 +@@ -65,6 +65,7 @@ struct taprio_sched {
3644 + u32 flags;
3645 + enum tk_offsets tk_offset;
3646 + int clockid;
3647 ++ bool offloaded;
3648 + atomic64_t picos_per_byte; /* Using picoseconds because for 10Gbps+
3649 + * speeds it's sub-nanoseconds per byte
3650 + */
3651 +@@ -1268,6 +1269,8 @@ static int taprio_enable_offload(struct net_device *dev,
3652 + goto done;
3653 + }
3654 +
3655 ++ q->offloaded = true;
3656 ++
3657 + done:
3658 + taprio_offload_free(offload);
3659 +
3660 +@@ -1282,12 +1285,9 @@ static int taprio_disable_offload(struct net_device *dev,
3661 + struct tc_taprio_qopt_offload *offload;
3662 + int err;
3663 +
3664 +- if (!FULL_OFFLOAD_IS_ENABLED(q->flags))
3665 ++ if (!q->offloaded)
3666 + return 0;
3667 +
3668 +- if (!ops->ndo_setup_tc)
3669 +- return -EOPNOTSUPP;
3670 +-
3671 + offload = taprio_offload_alloc(0);
3672 + if (!offload) {
3673 + NL_SET_ERR_MSG(extack,
3674 +@@ -1303,6 +1303,8 @@ static int taprio_disable_offload(struct net_device *dev,
3675 + goto out;
3676 + }
3677 +
3678 ++ q->offloaded = false;
3679 ++
3680 + out:
3681 + taprio_offload_free(offload);
3682 +
3683 +@@ -1904,12 +1906,14 @@ start_error:
3684 +
3685 + static struct Qdisc *taprio_leaf(struct Qdisc *sch, unsigned long cl)
3686 + {
3687 +- struct netdev_queue *dev_queue = taprio_queue_get(sch, cl);
3688 ++ struct taprio_sched *q = qdisc_priv(sch);
3689 ++ struct net_device *dev = qdisc_dev(sch);
3690 ++ unsigned int ntx = cl - 1;
3691 +
3692 +- if (!dev_queue)
3693 ++ if (ntx >= dev->num_tx_queues)
3694 + return NULL;
3695 +
3696 +- return dev_queue->qdisc_sleeping;
3697 ++ return q->qdiscs[ntx];
3698 + }
3699 +
3700 + static unsigned long taprio_find(struct Qdisc *sch, u32 classid)
3701 +diff --git a/scripts/mksysmap b/scripts/mksysmap
3702 +index 9aa23d15862a0..ad8bbc52267d0 100755
3703 +--- a/scripts/mksysmap
3704 ++++ b/scripts/mksysmap
3705 +@@ -41,4 +41,4 @@
3706 + # so we just ignore them to let readprofile continue to work.
3707 + # (At least sparc64 has __crc_ in the middle).
3708 +
3709 +-$NM -n $1 | grep -v '\( [aNUw] \)\|\(__crc_\)\|\( \$[adt]\)\|\( \.L\)' > $2
3710 ++$NM -n $1 | grep -v '\( [aNUw] \)\|\(__crc_\)\|\( \$[adt]\)\|\( \.L\)\|\( L0\)' > $2
3711 +diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
3712 +index ad4e0af2d0d03..51d2911366e93 100644
3713 +--- a/sound/core/oss/pcm_oss.c
3714 ++++ b/sound/core/oss/pcm_oss.c
3715 +@@ -1661,13 +1661,14 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
3716 + runtime = substream->runtime;
3717 + if (atomic_read(&substream->mmap_count))
3718 + goto __direct;
3719 +- if ((err = snd_pcm_oss_make_ready(substream)) < 0)
3720 +- return err;
3721 + atomic_inc(&runtime->oss.rw_ref);
3722 + if (mutex_lock_interruptible(&runtime->oss.params_lock)) {
3723 + atomic_dec(&runtime->oss.rw_ref);
3724 + return -ERESTARTSYS;
3725 + }
3726 ++ err = snd_pcm_oss_make_ready_locked(substream);
3727 ++ if (err < 0)
3728 ++ goto unlock;
3729 + format = snd_pcm_oss_format_from(runtime->oss.format);
3730 + width = snd_pcm_format_physical_width(format);
3731 + if (runtime->oss.buffer_used > 0) {
3732 +diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
3733 +index b8fe0ec5d6247..5b892e7090ddc 100644
3734 +--- a/sound/pci/hda/hda_intel.c
3735 ++++ b/sound/pci/hda/hda_intel.c
3736 +@@ -2528,6 +2528,8 @@ static const struct pci_device_id azx_ids[] = {
3737 + /* 5 Series/3400 */
3738 + { PCI_DEVICE(0x8086, 0x3b56),
3739 + .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
3740 ++ { PCI_DEVICE(0x8086, 0x3b57),
3741 ++ .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_NOPM },
3742 + /* Poulsbo */
3743 + { PCI_DEVICE(0x8086, 0x811b),
3744 + .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_INTEL_PCH_BASE },
3745 +diff --git a/sound/pci/hda/hda_tegra.c b/sound/pci/hda/hda_tegra.c
3746 +index 2971b34c87c1a..e235c3ec634db 100644
3747 +--- a/sound/pci/hda/hda_tegra.c
3748 ++++ b/sound/pci/hda/hda_tegra.c
3749 +@@ -428,7 +428,8 @@ MODULE_DEVICE_TABLE(of, hda_tegra_match);
3750 + static int hda_tegra_probe(struct platform_device *pdev)
3751 + {
3752 + const unsigned int driver_flags = AZX_DCAPS_CORBRP_SELF_CLEAR |
3753 +- AZX_DCAPS_PM_RUNTIME;
3754 ++ AZX_DCAPS_PM_RUNTIME |
3755 ++ AZX_DCAPS_4K_BDLE_BOUNDARY;
3756 + struct snd_card *card;
3757 + struct azx *chip;
3758 + struct hda_tegra *hda;
3759 +diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
3760 +index 5128a5df16fd3..169e742999873 100644
3761 +--- a/sound/pci/hda/patch_hdmi.c
3762 ++++ b/sound/pci/hda/patch_hdmi.c
3763 +@@ -3703,6 +3703,7 @@ static int patch_tegra_hdmi(struct hda_codec *codec)
3764 + if (err)
3765 + return err;
3766 +
3767 ++ codec->depop_delay = 10;
3768 + codec->patch_ops.build_pcms = tegra_hdmi_build_pcms;
3769 + spec = codec->spec;
3770 + spec->chmap.ops.chmap_cea_alloc_validate_get_type =
3771 +diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
3772 +index d925ae7f1b027..930bb040b403e 100644
3773 +--- a/sound/pci/hda/patch_realtek.c
3774 ++++ b/sound/pci/hda/patch_realtek.c
3775 +@@ -6484,6 +6484,8 @@ enum {
3776 + ALC294_FIXUP_ASUS_GU502_HP,
3777 + ALC294_FIXUP_ASUS_GU502_PINS,
3778 + ALC294_FIXUP_ASUS_GU502_VERBS,
3779 ++ ALC294_FIXUP_ASUS_G513_PINS,
3780 ++ ALC285_FIXUP_ASUS_G533Z_PINS,
3781 + ALC285_FIXUP_HP_GPIO_LED,
3782 + ALC285_FIXUP_HP_MUTE_LED,
3783 + ALC236_FIXUP_HP_GPIO_LED,
3784 +@@ -7760,6 +7762,24 @@ static const struct hda_fixup alc269_fixups[] = {
3785 + [ALC294_FIXUP_ASUS_GU502_HP] = {
3786 + .type = HDA_FIXUP_FUNC,
3787 + .v.func = alc294_fixup_gu502_hp,
3788 ++ },
3789 ++ [ALC294_FIXUP_ASUS_G513_PINS] = {
3790 ++ .type = HDA_FIXUP_PINS,
3791 ++ .v.pins = (const struct hda_pintbl[]) {
3792 ++ { 0x19, 0x03a11050 }, /* front HP mic */
3793 ++ { 0x1a, 0x03a11c30 }, /* rear external mic */
3794 ++ { 0x21, 0x03211420 }, /* front HP out */
3795 ++ { }
3796 ++ },
3797 ++ },
3798 ++ [ALC285_FIXUP_ASUS_G533Z_PINS] = {
3799 ++ .type = HDA_FIXUP_PINS,
3800 ++ .v.pins = (const struct hda_pintbl[]) {
3801 ++ { 0x14, 0x90170120 },
3802 ++ { }
3803 ++ },
3804 ++ .chained = true,
3805 ++ .chain_id = ALC294_FIXUP_ASUS_G513_PINS,
3806 + },
3807 + [ALC294_FIXUP_ASUS_COEF_1B] = {
3808 + .type = HDA_FIXUP_VERBS,
3809 +@@ -8118,6 +8138,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
3810 + SND_PCI_QUIRK(0x1028, 0x0871, "Dell Precision 3630", ALC255_FIXUP_DELL_HEADSET_MIC),
3811 + SND_PCI_QUIRK(0x1028, 0x0872, "Dell Precision 3630", ALC255_FIXUP_DELL_HEADSET_MIC),
3812 + SND_PCI_QUIRK(0x1028, 0x0873, "Dell Precision 3930", ALC255_FIXUP_DUMMY_LINEOUT_VERB),
3813 ++ SND_PCI_QUIRK(0x1028, 0x087d, "Dell Precision 5530", ALC289_FIXUP_DUAL_SPK),
3814 + SND_PCI_QUIRK(0x1028, 0x08ad, "Dell WYSE AIO", ALC225_FIXUP_DELL_WYSE_AIO_MIC_NO_PRESENCE),
3815 + SND_PCI_QUIRK(0x1028, 0x08ae, "Dell WYSE NB", ALC225_FIXUP_DELL1_MIC_NO_PRESENCE),
3816 + SND_PCI_QUIRK(0x1028, 0x0935, "Dell", ALC274_FIXUP_DELL_AIO_LINEOUT_VERB),
3817 +@@ -8229,10 +8250,11 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
3818 + SND_PCI_QUIRK(0x1043, 0x13b0, "ASUS Z550SA", ALC256_FIXUP_ASUS_MIC),
3819 + SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_ASUS_ZENBOOK),
3820 + SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_ASUS_ZENBOOK_UX31A),
3821 ++ SND_PCI_QUIRK(0x1043, 0x1662, "ASUS GV301QH", ALC294_FIXUP_ASUS_DUAL_SPK),
3822 ++ SND_PCI_QUIRK(0x1043, 0x16b2, "ASUS GU603", ALC289_FIXUP_ASUS_GA401),
3823 + SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
3824 + SND_PCI_QUIRK(0x1043, 0x1740, "ASUS UX430UA", ALC295_FIXUP_ASUS_DACS),
3825 + SND_PCI_QUIRK(0x1043, 0x17d1, "ASUS UX431FL", ALC294_FIXUP_ASUS_DUAL_SPK),
3826 +- SND_PCI_QUIRK(0x1043, 0x1662, "ASUS GV301QH", ALC294_FIXUP_ASUS_DUAL_SPK),
3827 + SND_PCI_QUIRK(0x1043, 0x1881, "ASUS Zephyrus S/M", ALC294_FIXUP_ASUS_GX502_PINS),
3828 + SND_PCI_QUIRK(0x1043, 0x18b1, "Asus MJ401TA", ALC256_FIXUP_ASUS_HEADSET_MIC),
3829 + SND_PCI_QUIRK(0x1043, 0x18f1, "Asus FX505DT", ALC256_FIXUP_ASUS_HEADSET_MIC),
3830 +@@ -8247,14 +8269,16 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
3831 + SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
3832 + SND_PCI_QUIRK(0x1043, 0x1bbd, "ASUS Z550MA", ALC255_FIXUP_ASUS_MIC_NO_PRESENCE),
3833 + SND_PCI_QUIRK(0x1043, 0x1c23, "Asus X55U", ALC269_FIXUP_LIMIT_INT_MIC_BOOST),
3834 ++ SND_PCI_QUIRK(0x1043, 0x1c92, "ASUS ROG Strix G15", ALC285_FIXUP_ASUS_G533Z_PINS),
3835 + SND_PCI_QUIRK(0x1043, 0x1ccd, "ASUS X555UB", ALC256_FIXUP_ASUS_MIC),
3836 ++ SND_PCI_QUIRK(0x1043, 0x1d42, "ASUS Zephyrus G14 2022", ALC289_FIXUP_ASUS_GA401),
3837 + SND_PCI_QUIRK(0x1043, 0x1d4e, "ASUS TM420", ALC256_FIXUP_ASUS_HPE),
3838 + SND_PCI_QUIRK(0x1043, 0x1e11, "ASUS Zephyrus G15", ALC289_FIXUP_ASUS_GA502),
3839 + SND_PCI_QUIRK(0x1043, 0x1e51, "ASUS Zephyrus M15", ALC294_FIXUP_ASUS_GU502_PINS),
3840 ++ SND_PCI_QUIRK(0x1043, 0x1e5e, "ASUS ROG Strix G513", ALC294_FIXUP_ASUS_G513_PINS),
3841 + SND_PCI_QUIRK(0x1043, 0x1e8e, "ASUS Zephyrus G15", ALC289_FIXUP_ASUS_GA401),
3842 ++ SND_PCI_QUIRK(0x1043, 0x1c52, "ASUS Zephyrus G15 2022", ALC289_FIXUP_ASUS_GA401),
3843 + SND_PCI_QUIRK(0x1043, 0x1f11, "ASUS Zephyrus G14", ALC289_FIXUP_ASUS_GA401),
3844 +- SND_PCI_QUIRK(0x1043, 0x1d42, "ASUS Zephyrus G14 2022", ALC289_FIXUP_ASUS_GA401),
3845 +- SND_PCI_QUIRK(0x1043, 0x16b2, "ASUS GU603", ALC289_FIXUP_ASUS_GA401),
3846 + SND_PCI_QUIRK(0x1043, 0x3030, "ASUS ZN270IE", ALC256_FIXUP_ASUS_AIO_GPIO2),
3847 + SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
3848 + SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
3849 +@@ -8425,6 +8449,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
3850 + SND_PCI_QUIRK(0x17aa, 0x511f, "Thinkpad", ALC298_FIXUP_TPT470_DOCK),
3851 + SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
3852 + SND_PCI_QUIRK(0x19e5, 0x3204, "Huawei MACH-WX9", ALC256_FIXUP_HUAWEI_MACH_WX9_PINS),
3853 ++ SND_PCI_QUIRK(0x19e5, 0x320f, "Huawei WRT-WX9 ", ALC256_FIXUP_ASUS_MIC_NO_PRESENCE),
3854 + SND_PCI_QUIRK(0x1b35, 0x1235, "CZC B20", ALC269_FIXUP_CZC_B20),
3855 + SND_PCI_QUIRK(0x1b35, 0x1236, "CZC TMI", ALC269_FIXUP_CZC_TMI),
3856 + SND_PCI_QUIRK(0x1b35, 0x1237, "CZC L101", ALC269_FIXUP_CZC_L101),
3857 +diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
3858 +index bfd3fe5eff31c..04a89171327dc 100644
3859 +--- a/sound/pci/hda/patch_sigmatel.c
3860 ++++ b/sound/pci/hda/patch_sigmatel.c
3861 +@@ -209,6 +209,7 @@ struct sigmatel_spec {
3862 +
3863 + /* beep widgets */
3864 + hda_nid_t anabeep_nid;
3865 ++ bool beep_power_on;
3866 +
3867 + /* SPDIF-out mux */
3868 + const char * const *spdif_labels;
3869 +@@ -4441,6 +4442,28 @@ static int stac_suspend(struct hda_codec *codec)
3870 + stac_shutup(codec);
3871 + return 0;
3872 + }
3873 ++
3874 ++static int stac_check_power_status(struct hda_codec *codec, hda_nid_t nid)
3875 ++{
3876 ++#ifdef CONFIG_SND_HDA_INPUT_BEEP
3877 ++ struct sigmatel_spec *spec = codec->spec;
3878 ++#endif
3879 ++ int ret = snd_hda_gen_check_power_status(codec, nid);
3880 ++
3881 ++#ifdef CONFIG_SND_HDA_INPUT_BEEP
3882 ++ if (nid == spec->gen.beep_nid && codec->beep) {
3883 ++ if (codec->beep->enabled != spec->beep_power_on) {
3884 ++ spec->beep_power_on = codec->beep->enabled;
3885 ++ if (spec->beep_power_on)
3886 ++ snd_hda_power_up_pm(codec);
3887 ++ else
3888 ++ snd_hda_power_down_pm(codec);
3889 ++ }
3890 ++ ret |= spec->beep_power_on;
3891 ++ }
3892 ++#endif
3893 ++ return ret;
3894 ++}
3895 + #else
3896 + #define stac_suspend NULL
3897 + #endif /* CONFIG_PM */
3898 +@@ -4453,6 +4476,7 @@ static const struct hda_codec_ops stac_patch_ops = {
3899 + .unsol_event = snd_hda_jack_unsol_event,
3900 + #ifdef CONFIG_PM
3901 + .suspend = stac_suspend,
3902 ++ .check_power_status = stac_check_power_status,
3903 + #endif
3904 + .reboot_notify = stac_shutup,
3905 + };
3906 +diff --git a/sound/soc/codecs/nau8824.c b/sound/soc/codecs/nau8824.c
3907 +index c8ccfa2fff848..a95fe3fff1db8 100644
3908 +--- a/sound/soc/codecs/nau8824.c
3909 ++++ b/sound/soc/codecs/nau8824.c
3910 +@@ -1072,6 +1072,7 @@ static int nau8824_hw_params(struct snd_pcm_substream *substream,
3911 + struct snd_soc_component *component = dai->component;
3912 + struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component);
3913 + unsigned int val_len = 0, osr, ctrl_val, bclk_fs, bclk_div;
3914 ++ int err = -EINVAL;
3915 +
3916 + nau8824_sema_acquire(nau8824, HZ);
3917 +
3918 +@@ -1088,7 +1089,7 @@ static int nau8824_hw_params(struct snd_pcm_substream *substream,
3919 + osr &= NAU8824_DAC_OVERSAMPLE_MASK;
3920 + if (nau8824_clock_check(nau8824, substream->stream,
3921 + nau8824->fs, osr))
3922 +- return -EINVAL;
3923 ++ goto error;
3924 + regmap_update_bits(nau8824->regmap, NAU8824_REG_CLK_DIVIDER,
3925 + NAU8824_CLK_DAC_SRC_MASK,
3926 + osr_dac_sel[osr].clk_src << NAU8824_CLK_DAC_SRC_SFT);
3927 +@@ -1098,7 +1099,7 @@ static int nau8824_hw_params(struct snd_pcm_substream *substream,
3928 + osr &= NAU8824_ADC_SYNC_DOWN_MASK;
3929 + if (nau8824_clock_check(nau8824, substream->stream,
3930 + nau8824->fs, osr))
3931 +- return -EINVAL;
3932 ++ goto error;
3933 + regmap_update_bits(nau8824->regmap, NAU8824_REG_CLK_DIVIDER,
3934 + NAU8824_CLK_ADC_SRC_MASK,
3935 + osr_adc_sel[osr].clk_src << NAU8824_CLK_ADC_SRC_SFT);
3936 +@@ -1119,7 +1120,7 @@ static int nau8824_hw_params(struct snd_pcm_substream *substream,
3937 + else if (bclk_fs <= 256)
3938 + bclk_div = 0;
3939 + else
3940 +- return -EINVAL;
3941 ++ goto error;
3942 + regmap_update_bits(nau8824->regmap,
3943 + NAU8824_REG_PORT0_I2S_PCM_CTRL_2,
3944 + NAU8824_I2S_LRC_DIV_MASK | NAU8824_I2S_BLK_DIV_MASK,
3945 +@@ -1140,15 +1141,17 @@ static int nau8824_hw_params(struct snd_pcm_substream *substream,
3946 + val_len |= NAU8824_I2S_DL_32;
3947 + break;
3948 + default:
3949 +- return -EINVAL;
3950 ++ goto error;
3951 + }
3952 +
3953 + regmap_update_bits(nau8824->regmap, NAU8824_REG_PORT0_I2S_PCM_CTRL_1,
3954 + NAU8824_I2S_DL_MASK, val_len);
3955 ++ err = 0;
3956 +
3957 ++ error:
3958 + nau8824_sema_release(nau8824);
3959 +
3960 +- return 0;
3961 ++ return err;
3962 + }
3963 +
3964 + static int nau8824_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
3965 +@@ -1157,8 +1160,6 @@ static int nau8824_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
3966 + struct nau8824 *nau8824 = snd_soc_component_get_drvdata(component);
3967 + unsigned int ctrl1_val = 0, ctrl2_val = 0;
3968 +
3969 +- nau8824_sema_acquire(nau8824, HZ);
3970 +-
3971 + switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
3972 + case SND_SOC_DAIFMT_CBM_CFM:
3973 + ctrl2_val |= NAU8824_I2S_MS_MASTER;
3974 +@@ -1200,6 +1201,8 @@ static int nau8824_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
3975 + return -EINVAL;
3976 + }
3977 +
3978 ++ nau8824_sema_acquire(nau8824, HZ);
3979 ++
3980 + regmap_update_bits(nau8824->regmap, NAU8824_REG_PORT0_I2S_PCM_CTRL_1,
3981 + NAU8824_I2S_DF_MASK | NAU8824_I2S_BP_MASK |
3982 + NAU8824_I2S_PCMB_EN, ctrl1_val);
3983 +diff --git a/tools/perf/util/genelf.c b/tools/perf/util/genelf.c
3984 +index 17b74aba8b9a2..69744fd5db395 100644
3985 +--- a/tools/perf/util/genelf.c
3986 ++++ b/tools/perf/util/genelf.c
3987 +@@ -256,6 +256,7 @@ jit_write_elf(int fd, uint64_t load_addr, const char *sym,
3988 + Elf_Data *d;
3989 + Elf_Scn *scn;
3990 + Elf_Ehdr *ehdr;
3991 ++ Elf_Phdr *phdr;
3992 + Elf_Shdr *shdr;
3993 + uint64_t eh_frame_base_offset;
3994 + char *strsym = NULL;
3995 +@@ -290,6 +291,19 @@ jit_write_elf(int fd, uint64_t load_addr, const char *sym,
3996 + ehdr->e_version = EV_CURRENT;
3997 + ehdr->e_shstrndx= unwinding ? 4 : 2; /* shdr index for section name */
3998 +
3999 ++ /*
4000 ++ * setup program header
4001 ++ */
4002 ++ phdr = elf_newphdr(e, 1);
4003 ++ phdr[0].p_type = PT_LOAD;
4004 ++ phdr[0].p_offset = 0;
4005 ++ phdr[0].p_vaddr = 0;
4006 ++ phdr[0].p_paddr = 0;
4007 ++ phdr[0].p_filesz = csize;
4008 ++ phdr[0].p_memsz = csize;
4009 ++ phdr[0].p_flags = PF_X | PF_R;
4010 ++ phdr[0].p_align = 8;
4011 ++
4012 + /*
4013 + * setup text section
4014 + */
4015 +diff --git a/tools/perf/util/genelf.h b/tools/perf/util/genelf.h
4016 +index d4137559be053..ac638945b4cb0 100644
4017 +--- a/tools/perf/util/genelf.h
4018 ++++ b/tools/perf/util/genelf.h
4019 +@@ -50,8 +50,10 @@ int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_ent
4020 +
4021 + #if GEN_ELF_CLASS == ELFCLASS64
4022 + #define elf_newehdr elf64_newehdr
4023 ++#define elf_newphdr elf64_newphdr
4024 + #define elf_getshdr elf64_getshdr
4025 + #define Elf_Ehdr Elf64_Ehdr
4026 ++#define Elf_Phdr Elf64_Phdr
4027 + #define Elf_Shdr Elf64_Shdr
4028 + #define Elf_Sym Elf64_Sym
4029 + #define ELF_ST_TYPE(a) ELF64_ST_TYPE(a)
4030 +@@ -59,8 +61,10 @@ int jit_add_debug_info(Elf *e, uint64_t code_addr, void *debug, int nr_debug_ent
4031 + #define ELF_ST_VIS(a) ELF64_ST_VISIBILITY(a)
4032 + #else
4033 + #define elf_newehdr elf32_newehdr
4034 ++#define elf_newphdr elf32_newphdr
4035 + #define elf_getshdr elf32_getshdr
4036 + #define Elf_Ehdr Elf32_Ehdr
4037 ++#define Elf_Phdr Elf32_Phdr
4038 + #define Elf_Shdr Elf32_Shdr
4039 + #define Elf_Sym Elf32_Sym
4040 + #define ELF_ST_TYPE(a) ELF32_ST_TYPE(a)
4041 +diff --git a/tools/perf/util/symbol-elf.c b/tools/perf/util/symbol-elf.c
4042 +index a04a7dfb8ec09..f15258fbe9dbf 100644
4043 +--- a/tools/perf/util/symbol-elf.c
4044 ++++ b/tools/perf/util/symbol-elf.c
4045 +@@ -1912,8 +1912,8 @@ static int kcore_copy__compare_file(const char *from_dir, const char *to_dir,
4046 + * unusual. One significant peculiarity is that the mapping (start -> pgoff)
4047 + * is not the same for the kernel map and the modules map. That happens because
4048 + * the data is copied adjacently whereas the original kcore has gaps. Finally,
4049 +- * kallsyms and modules files are compared with their copies to check that
4050 +- * modules have not been loaded or unloaded while the copies were taking place.
4051 ++ * kallsyms file is compared with its copy to check that modules have not been
4052 ++ * loaded or unloaded while the copies were taking place.
4053 + *
4054 + * Return: %0 on success, %-1 on failure.
4055 + */
4056 +@@ -1976,9 +1976,6 @@ int kcore_copy(const char *from_dir, const char *to_dir)
4057 + goto out_extract_close;
4058 + }
4059 +
4060 +- if (kcore_copy__compare_file(from_dir, to_dir, "modules"))
4061 +- goto out_extract_close;
4062 +-
4063 + if (kcore_copy__compare_file(from_dir, to_dir, "kallsyms"))
4064 + goto out_extract_close;
4065 +