From: Sasha Levin Date: Thu, 19 Dec 2024 19:23:47 +0000 (-0500) Subject: Fixes for 6.6 X-Git-Tag: v6.1.122~55 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3b0716267b5c4192af9d168ef3e11b8f215cb83e;p=thirdparty%2Fkernel%2Fstable-queue.git Fixes for 6.6 Signed-off-by: Sasha Levin --- diff --git a/queue-6.6/asoc-intel-sof_sdw-add-quirk-for-dell-sku-0b8c.patch b/queue-6.6/asoc-intel-sof_sdw-add-quirk-for-dell-sku-0b8c.patch new file mode 100644 index 00000000000..0089b0670b4 --- /dev/null +++ b/queue-6.6/asoc-intel-sof_sdw-add-quirk-for-dell-sku-0b8c.patch @@ -0,0 +1,49 @@ +From 4927d514ccf8d8bfe91aa600ac6a2d47767e4a66 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sun, 28 Jul 2024 12:06:47 -0400 +Subject: ASoC: Intel: sof_sdw: add quirk for Dell SKU 0B8C +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Pierre-Louis Bossart + +[ Upstream commit 92d5b5930e7d55ca07b483490d6298eee828bbe4 ] + +Jack detection needs to rely on JD2, as most other Dell +AlderLake-based devices. + +Closes: https://github.com/thesofproject/linux/issues/5021 +Signed-off-by: Pierre-Louis Bossart +Reviewed-by: Péter Ujfalusi +Reviewed-by: Bard Liao +Link: https://patch.msgid.link/20240624121119.91552-4-pierre-louis.bossart@linux.intel.com +Signed-off-by: Mark Brown +Signed-off-by: Sasha Levin +--- + sound/soc/intel/boards/sof_sdw.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/sound/soc/intel/boards/sof_sdw.c b/sound/soc/intel/boards/sof_sdw.c +index dc144cd7e0e3..db1dcb9d7046 100644 +--- a/sound/soc/intel/boards/sof_sdw.c ++++ b/sound/soc/intel/boards/sof_sdw.c +@@ -425,6 +425,15 @@ static const struct dmi_system_id sof_sdw_quirk_table[] = { + /* No Jack */ + .driver_data = (void *)SOF_SDW_TGL_HDMI, + }, ++ { ++ .callback = sof_sdw_quirk_cb, ++ .matches = { ++ DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc"), ++ DMI_EXACT_MATCH(DMI_PRODUCT_SKU, "0B8C"), ++ }, ++ .driver_data = (void *)(SOF_SDW_TGL_HDMI | ++ RT711_JD2), ++ }, + { + .callback = sof_sdw_quirk_cb, + .matches = { +-- +2.39.5 + diff --git a/queue-6.6/asoc-intel-sof_sdw-fix-jack-detection-on-adl-n-varia.patch b/queue-6.6/asoc-intel-sof_sdw-fix-jack-detection-on-adl-n-varia.patch new file mode 100644 index 00000000000..eed15f82213 --- /dev/null +++ b/queue-6.6/asoc-intel-sof_sdw-fix-jack-detection-on-adl-n-varia.patch @@ -0,0 +1,45 @@ +From f378567750592a70c4282c42511d1ff7f5ef702e Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sun, 28 Jul 2024 12:06:46 -0400 +Subject: ASoC: Intel: sof_sdw: fix jack detection on ADL-N variant RVP + +From: Pierre-Louis Bossart + +[ Upstream commit 65c90df918205bc84f5448550cde76a54dae5f52 ] + +Experimental tests show that JD2_100K is required, otherwise the jack +is detected always even with nothing plugged-in. + +To avoid matching with other known quirks the SKU information is used. + +Signed-off-by: Pierre-Louis Bossart +Link: https://patch.msgid.link/20240624121119.91552-2-pierre-louis.bossart@linux.intel.com +Signed-off-by: Mark Brown +Signed-off-by: Sasha Levin +--- + sound/soc/intel/boards/sof_sdw.c | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/sound/soc/intel/boards/sof_sdw.c b/sound/soc/intel/boards/sof_sdw.c +index 5980fce81797..dc144cd7e0e3 100644 +--- a/sound/soc/intel/boards/sof_sdw.c ++++ b/sound/soc/intel/boards/sof_sdw.c +@@ -286,6 +286,15 @@ static const struct dmi_system_id sof_sdw_quirk_table[] = { + SOF_BT_OFFLOAD_SSP(2) | + SOF_SSP_BT_OFFLOAD_PRESENT), + }, ++ { ++ .callback = sof_sdw_quirk_cb, ++ .matches = { ++ DMI_MATCH(DMI_BOARD_VENDOR, "Intel Corporation"), ++ DMI_MATCH(DMI_PRODUCT_SKU, "0000000000070000"), ++ }, ++ .driver_data = (void *)(SOF_SDW_TGL_HDMI | ++ RT711_JD2_100K), ++ }, + { + .callback = sof_sdw_quirk_cb, + .matches = { +-- +2.39.5 + diff --git a/queue-6.6/i2c-pnx-fix-timeout-in-wait-functions.patch b/queue-6.6/i2c-pnx-fix-timeout-in-wait-functions.patch new file mode 100644 index 00000000000..5118c034a8a --- /dev/null +++ b/queue-6.6/i2c-pnx-fix-timeout-in-wait-functions.patch @@ -0,0 +1,48 @@ +From a96c70cca3a1a1d2a254ad065fce4bec4f84c63c Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sat, 7 Dec 2024 00:19:34 +0100 +Subject: i2c: pnx: Fix timeout in wait functions + +From: Vladimir Riabchun + +[ Upstream commit 7363f2d4c18557c99c536b70489187bb4e05c412 ] + +Since commit f63b94be6942 ("i2c: pnx: Fix potential deadlock warning +from del_timer_sync() call in isr") jiffies are stored in +i2c_pnx_algo_data.timeout, but wait_timeout and wait_reset are still +using it as milliseconds. Convert jiffies back to milliseconds to wait +for the expected amount of time. + +Fixes: f63b94be6942 ("i2c: pnx: Fix potential deadlock warning from del_timer_sync() call in isr") +Signed-off-by: Vladimir Riabchun +Signed-off-by: Andi Shyti +Signed-off-by: Sasha Levin +--- + drivers/i2c/busses/i2c-pnx.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c +index f448505d5468..2b9cc86fb3ab 100644 +--- a/drivers/i2c/busses/i2c-pnx.c ++++ b/drivers/i2c/busses/i2c-pnx.c +@@ -95,7 +95,7 @@ enum { + + static inline int wait_timeout(struct i2c_pnx_algo_data *data) + { +- long timeout = data->timeout; ++ long timeout = jiffies_to_msecs(data->timeout); + while (timeout > 0 && + (ioread32(I2C_REG_STS(data)) & mstatus_active)) { + mdelay(1); +@@ -106,7 +106,7 @@ static inline int wait_timeout(struct i2c_pnx_algo_data *data) + + static inline int wait_reset(struct i2c_pnx_algo_data *data) + { +- long timeout = data->timeout; ++ long timeout = jiffies_to_msecs(data->timeout); + while (timeout > 0 && + (ioread32(I2C_REG_CTL(data)) & mcntrl_reset)) { + mdelay(1); +-- +2.39.5 + diff --git a/queue-6.6/mips-loongson64-dts-fix-msi-node-for-ls7a.patch b/queue-6.6/mips-loongson64-dts-fix-msi-node-for-ls7a.patch new file mode 100644 index 00000000000..be4c31d36ad --- /dev/null +++ b/queue-6.6/mips-loongson64-dts-fix-msi-node-for-ls7a.patch @@ -0,0 +1,36 @@ +From 273b8263d5e14da6326d404e51cf3619b46e02dd Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sun, 28 Jul 2024 12:06:43 -0400 +Subject: MIPS: Loongson64: DTS: Fix msi node for ls7a + +From: Jiaxun Yang + +[ Upstream commit 98a9e2ac3755a353eefea8c52e23d5b0c50f3899 ] + +Add it to silent warning: +arch/mips/boot/dts/loongson/ls7a-pch.dtsi:68.16-416.5: Warning (interrupt_provider): /bus@10000000/pci@1a000000: '#interrupt-cells' found, but node is not an interrupt provider +arch/mips/boot/dts/loongson/loongson64g_4core_ls7a.dts:32.31-40.4: Warning (interrupt_provider): /bus@10000000/msi-controller@2ff00000: Missing '#interrupt-cells' in interrupt provider +arch/mips/boot/dts/loongson/loongson64g_4core_ls7a.dtb: Warning (interrupt_map): Failed prerequisite 'interrupt_provider' + +Signed-off-by: Jiaxun Yang +Signed-off-by: Thomas Bogendoerfer +Signed-off-by: Sasha Levin +--- + arch/mips/boot/dts/loongson/loongson64g_4core_ls7a.dts | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/arch/mips/boot/dts/loongson/loongson64g_4core_ls7a.dts b/arch/mips/boot/dts/loongson/loongson64g_4core_ls7a.dts +index c945f8565d54..fb180cb2b8e2 100644 +--- a/arch/mips/boot/dts/loongson/loongson64g_4core_ls7a.dts ++++ b/arch/mips/boot/dts/loongson/loongson64g_4core_ls7a.dts +@@ -33,6 +33,7 @@ + compatible = "loongson,pch-msi-1.0"; + reg = <0 0x2ff00000 0 0x8>; + interrupt-controller; ++ #interrupt-cells = <1>; + msi-controller; + loongson,msi-base-vec = <64>; + loongson,msi-num-vecs = <192>; +-- +2.39.5 + diff --git a/queue-6.6/net-stmmac-fix-tso-dma-api-usage-causing-oops.patch b/queue-6.6/net-stmmac-fix-tso-dma-api-usage-causing-oops.patch new file mode 100644 index 00000000000..e105824fca4 --- /dev/null +++ b/queue-6.6/net-stmmac-fix-tso-dma-api-usage-causing-oops.patch @@ -0,0 +1,84 @@ +From d3377fcb51de0e790f63c761cc4ae53dea31393e Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Fri, 6 Dec 2024 12:40:11 +0000 +Subject: net: stmmac: fix TSO DMA API usage causing oops + +From: Russell King (Oracle) + +[ Upstream commit 4c49f38e20a57f8abaebdf95b369295b153d1f8e ] + +Commit 66600fac7a98 ("net: stmmac: TSO: Fix unbalanced DMA map/unmap +for non-paged SKB data") moved the assignment of tx_skbuff_dma[]'s +members to be later in stmmac_tso_xmit(). + +The buf (dma cookie) and len stored in this structure are passed to +dma_unmap_single() by stmmac_tx_clean(). The DMA API requires that +the dma cookie passed to dma_unmap_single() is the same as the value +returned from dma_map_single(). However, by moving the assignment +later, this is not the case when priv->dma_cap.addr64 > 32 as "des" +is offset by proto_hdr_len. + +This causes problems such as: + + dwc-eth-dwmac 2490000.ethernet eth0: Tx DMA map failed + +and with DMA_API_DEBUG enabled: + + DMA-API: dwc-eth-dwmac 2490000.ethernet: device driver tries to +free DMA memory it has not allocated [device address=0x000000ffffcf65c0] [size=66 bytes] + +Fix this by maintaining "des" as the original DMA cookie, and use +tso_des to pass the offset DMA cookie to stmmac_tso_allocator(). + +Full details of the crashes can be found at: +https://lore.kernel.org/all/d8112193-0386-4e14-b516-37c2d838171a@nvidia.com/ +https://lore.kernel.org/all/klkzp5yn5kq5efgtrow6wbvnc46bcqfxs65nz3qy77ujr5turc@bwwhelz2l4dw/ + +Reported-by: Jon Hunter +Reported-by: Thierry Reding +Fixes: 66600fac7a98 ("net: stmmac: TSO: Fix unbalanced DMA map/unmap for non-paged SKB data") +Tested-by: Jon Hunter +Signed-off-by: Russell King (Oracle) +Reviewed-by: Furong Xu <0x1207@gmail.com> +Link: https://patch.msgid.link/E1tJXcx-006N4Z-PC@rmk-PC.armlinux.org.uk +Signed-off-by: Jakub Kicinski +Signed-off-by: Sasha Levin +--- + drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 7 ++++--- + 1 file changed, 4 insertions(+), 3 deletions(-) + +diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +index 853851d5f362..d6ee90fef2ec 100644 +--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c ++++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +@@ -4119,9 +4119,9 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) + int tmp_pay_len = 0, first_tx; + struct stmmac_tx_queue *tx_q; + bool has_vlan, set_ic; ++ dma_addr_t tso_des, des; + u8 proto_hdr_len, hdr; + u32 pay_len, mss; +- dma_addr_t des; + int i; + + tx_q = &priv->dma_conf.tx_queue[queue]; +@@ -4206,14 +4206,15 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev) + + /* If needed take extra descriptors to fill the remaining payload */ + tmp_pay_len = pay_len - TSO_MAX_BUFF_SIZE; ++ tso_des = des; + } else { + stmmac_set_desc_addr(priv, first, des); + tmp_pay_len = pay_len; +- des += proto_hdr_len; ++ tso_des = des + proto_hdr_len; + pay_len = 0; + } + +- stmmac_tso_allocator(priv, des, tmp_pay_len, (nfrags == 0), queue); ++ stmmac_tso_allocator(priv, tso_des, tmp_pay_len, (nfrags == 0), queue); + + /* In case two or more DMA transmit descriptors are allocated for this + * non-paged SKB data, the DMA buffer address should be saved to +-- +2.39.5 + diff --git a/queue-6.6/p2sb-do-not-scan-and-remove-the-p2sb-device-when-it-.patch b/queue-6.6/p2sb-do-not-scan-and-remove-the-p2sb-device-when-it-.patch new file mode 100644 index 00000000000..c69552e108c --- /dev/null +++ b/queue-6.6/p2sb-do-not-scan-and-remove-the-p2sb-device-when-it-.patch @@ -0,0 +1,136 @@ +From 90263e61ca486e78fd6f0963af47376c1c00f698 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Thu, 28 Nov 2024 09:28:36 +0900 +Subject: p2sb: Do not scan and remove the P2SB device when it is unhidden +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Shin'ichiro Kawasaki + +[ Upstream commit 360c400d0f568636c1b98d1d5f9f49aa3d420c70 ] + +When drivers access P2SB device resources, it calls p2sb_bar(). Before +the commit 5913320eb0b3 ("platform/x86: p2sb: Allow p2sb_bar() calls +during PCI device probe"), p2sb_bar() obtained the resources and then +called pci_stop_and_remove_bus_device() for clean up. Then the P2SB +device disappeared. The commit 5913320eb0b3 introduced the P2SB device +resource cache feature in the boot process. During the resource cache, +pci_stop_and_remove_bus_device() is called for the P2SB device, then the +P2SB device disappears regardless of whether p2sb_bar() is called or +not. Such P2SB device disappearance caused a confusion [1]. To avoid the +confusion, avoid the pci_stop_and_remove_bus_device() call when the BIOS +does not hide the P2SB device. + +For that purpose, cache the P2SB device resources only if the BIOS hides +the P2SB device. Call p2sb_scan_and_cache() only if p2sb_hidden_by_bios +is true. This allows removing two branches from p2sb_scan_and_cache(). +When p2sb_bar() is called, get the resources from the cache if the P2SB +device is hidden. Otherwise, read the resources from the unhidden P2SB +device. + +Reported-by: Daniel Walker (danielwa) +Closes: https://lore.kernel.org/lkml/ZzTI+biIUTvFT6NC@goliath/ [1] +Fixes: 5913320eb0b3 ("platform/x86: p2sb: Allow p2sb_bar() calls during PCI device probe") +Signed-off-by: Shin'ichiro Kawasaki +Reviewed-by: Hans de Goede +Link: https://lore.kernel.org/r/20241128002836.373745-5-shinichiro.kawasaki@wdc.com +Reviewed-by: Ilpo Järvinen +Signed-off-by: Ilpo Järvinen +Signed-off-by: Sasha Levin +--- + drivers/platform/x86/p2sb.c | 42 +++++++++++++++++++++++++++++-------- + 1 file changed, 33 insertions(+), 9 deletions(-) + +diff --git a/drivers/platform/x86/p2sb.c b/drivers/platform/x86/p2sb.c +index 6fb76b82ecce..eff920de31c2 100644 +--- a/drivers/platform/x86/p2sb.c ++++ b/drivers/platform/x86/p2sb.c +@@ -100,10 +100,8 @@ static int p2sb_scan_and_cache(struct pci_bus *bus, unsigned int devfn) + /* + * The BIOS prevents the P2SB device from being enumerated by the PCI + * subsystem, so we need to unhide and hide it back to lookup the BAR. +- * Unhide the P2SB device here, if needed. + */ +- if (p2sb_hidden_by_bios) +- pci_bus_write_config_dword(bus, devfn, P2SBC, 0); ++ pci_bus_write_config_dword(bus, devfn, P2SBC, 0); + + /* Scan the P2SB device and cache its BAR0 */ + p2sb_scan_and_cache_devfn(bus, devfn); +@@ -112,9 +110,7 @@ static int p2sb_scan_and_cache(struct pci_bus *bus, unsigned int devfn) + if (devfn == P2SB_DEVFN_GOLDMONT) + p2sb_scan_and_cache_devfn(bus, SPI_DEVFN_GOLDMONT); + +- /* Hide the P2SB device, if it was hidden */ +- if (p2sb_hidden_by_bios) +- pci_bus_write_config_dword(bus, devfn, P2SBC, P2SBC_HIDE); ++ pci_bus_write_config_dword(bus, devfn, P2SBC, P2SBC_HIDE); + + if (!p2sb_valid_resource(&p2sb_resources[PCI_FUNC(devfn)].res)) + return -ENOENT; +@@ -141,7 +137,7 @@ static int p2sb_cache_resources(void) + u32 value = P2SBC_HIDE; + struct pci_bus *bus; + u16 class; +- int ret; ++ int ret = 0; + + /* Get devfn for P2SB device itself */ + p2sb_get_devfn(&devfn_p2sb); +@@ -167,7 +163,12 @@ static int p2sb_cache_resources(void) + pci_bus_read_config_dword(bus, devfn_p2sb, P2SBC, &value); + p2sb_hidden_by_bios = value & P2SBC_HIDE; + +- ret = p2sb_scan_and_cache(bus, devfn_p2sb); ++ /* ++ * If the BIOS does not hide the P2SB device then its resources ++ * are accesilble. Cache them only if the P2SB device is hidden. ++ */ ++ if (p2sb_hidden_by_bios) ++ ret = p2sb_scan_and_cache(bus, devfn_p2sb); + + pci_unlock_rescan_remove(); + +@@ -190,6 +191,26 @@ static int p2sb_read_from_cache(struct pci_bus *bus, unsigned int devfn, + return 0; + } + ++static int p2sb_read_from_dev(struct pci_bus *bus, unsigned int devfn, ++ struct resource *mem) ++{ ++ struct pci_dev *pdev; ++ int ret = 0; ++ ++ pdev = pci_get_slot(bus, devfn); ++ if (!pdev) ++ return -ENODEV; ++ ++ if (p2sb_valid_resource(pci_resource_n(pdev, 0))) ++ p2sb_read_bar0(pdev, mem); ++ else ++ ret = -ENOENT; ++ ++ pci_dev_put(pdev); ++ ++ return ret; ++} ++ + /** + * p2sb_bar - Get Primary to Sideband (P2SB) bridge device BAR + * @bus: PCI bus to communicate with +@@ -213,7 +234,10 @@ int p2sb_bar(struct pci_bus *bus, unsigned int devfn, struct resource *mem) + if (!devfn) + p2sb_get_devfn(&devfn); + +- return p2sb_read_from_cache(bus, devfn, mem); ++ if (p2sb_hidden_by_bios) ++ return p2sb_read_from_cache(bus, devfn, mem); ++ ++ return p2sb_read_from_dev(bus, devfn, mem); + } + EXPORT_SYMBOL_GPL(p2sb_bar); + +-- +2.39.5 + diff --git a/queue-6.6/p2sb-factor-out-p2sb_read_from_cache.patch b/queue-6.6/p2sb-factor-out-p2sb_read_from_cache.patch new file mode 100644 index 00000000000..3749a03899c --- /dev/null +++ b/queue-6.6/p2sb-factor-out-p2sb_read_from_cache.patch @@ -0,0 +1,82 @@ +From 7e76d171735583619cd26f8f8d29741538ba67b6 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Thu, 28 Nov 2024 09:28:33 +0900 +Subject: p2sb: Factor out p2sb_read_from_cache() +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Shin'ichiro Kawasaki + +[ Upstream commit 9244524d60ddea55f4df54c51200e8fef2032447 ] + +To prepare for the following fix, factor out the code to read the P2SB +resource from the cache to the new function p2sb_read_from_cache(). + +Signed-off-by: Shin'ichiro Kawasaki +Reviewed-by: Hans de Goede +Link: https://lore.kernel.org/r/20241128002836.373745-2-shinichiro.kawasaki@wdc.com +Reviewed-by: Ilpo Järvinen +Signed-off-by: Ilpo Järvinen +Stable-dep-of: 360c400d0f56 ("p2sb: Do not scan and remove the P2SB device when it is unhidden") +Signed-off-by: Sasha Levin +--- + drivers/platform/x86/p2sb.c | 28 +++++++++++++++++----------- + 1 file changed, 17 insertions(+), 11 deletions(-) + +diff --git a/drivers/platform/x86/p2sb.c b/drivers/platform/x86/p2sb.c +index 687e341e3206..d6ee4b34f911 100644 +--- a/drivers/platform/x86/p2sb.c ++++ b/drivers/platform/x86/p2sb.c +@@ -171,6 +171,22 @@ static int p2sb_cache_resources(void) + return ret; + } + ++static int p2sb_read_from_cache(struct pci_bus *bus, unsigned int devfn, ++ struct resource *mem) ++{ ++ struct p2sb_res_cache *cache = &p2sb_resources[PCI_FUNC(devfn)]; ++ ++ if (cache->bus_dev_id != bus->dev.id) ++ return -ENODEV; ++ ++ if (!p2sb_valid_resource(&cache->res)) ++ return -ENOENT; ++ ++ memcpy(mem, &cache->res, sizeof(*mem)); ++ ++ return 0; ++} ++ + /** + * p2sb_bar - Get Primary to Sideband (P2SB) bridge device BAR + * @bus: PCI bus to communicate with +@@ -187,8 +203,6 @@ static int p2sb_cache_resources(void) + */ + int p2sb_bar(struct pci_bus *bus, unsigned int devfn, struct resource *mem) + { +- struct p2sb_res_cache *cache; +- + bus = p2sb_get_bus(bus); + if (!bus) + return -ENODEV; +@@ -196,15 +210,7 @@ int p2sb_bar(struct pci_bus *bus, unsigned int devfn, struct resource *mem) + if (!devfn) + p2sb_get_devfn(&devfn); + +- cache = &p2sb_resources[PCI_FUNC(devfn)]; +- if (cache->bus_dev_id != bus->dev.id) +- return -ENODEV; +- +- if (!p2sb_valid_resource(&cache->res)) +- return -ENOENT; +- +- memcpy(mem, &cache->res, sizeof(*mem)); +- return 0; ++ return p2sb_read_from_cache(bus, devfn, mem); + } + EXPORT_SYMBOL_GPL(p2sb_bar); + +-- +2.39.5 + diff --git a/queue-6.6/p2sb-introduce-the-global-flag-p2sb_hidden_by_bios.patch b/queue-6.6/p2sb-introduce-the-global-flag-p2sb_hidden_by_bios.patch new file mode 100644 index 00000000000..3a1a11c7032 --- /dev/null +++ b/queue-6.6/p2sb-introduce-the-global-flag-p2sb_hidden_by_bios.patch @@ -0,0 +1,60 @@ +From a4bcb620221f3aeefda4b924ba13bcb8fae02615 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Thu, 28 Nov 2024 09:28:34 +0900 +Subject: p2sb: Introduce the global flag p2sb_hidden_by_bios +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Shin'ichiro Kawasaki + +[ Upstream commit ae3e6ebc5ab046d434c05c58a3e3f7e94441fec2 ] + +To prepare for the following fix, introduce the global flag +p2sb_hidden_by_bios. Check if the BIOS hides the P2SB device and store +the result in the flag. This allows to refer to the check result across +functions. + +Signed-off-by: Shin'ichiro Kawasaki +Reviewed-by: Hans de Goede +Link: https://lore.kernel.org/r/20241128002836.373745-3-shinichiro.kawasaki@wdc.com +Reviewed-by: Ilpo Järvinen +Signed-off-by: Ilpo Järvinen +Stable-dep-of: 360c400d0f56 ("p2sb: Do not scan and remove the P2SB device when it is unhidden") +Signed-off-by: Sasha Levin +--- + drivers/platform/x86/p2sb.c | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/drivers/platform/x86/p2sb.c b/drivers/platform/x86/p2sb.c +index d6ee4b34f911..d015ddc9f30e 100644 +--- a/drivers/platform/x86/p2sb.c ++++ b/drivers/platform/x86/p2sb.c +@@ -42,6 +42,7 @@ struct p2sb_res_cache { + }; + + static struct p2sb_res_cache p2sb_resources[NR_P2SB_RES_CACHE]; ++static bool p2sb_hidden_by_bios; + + static void p2sb_get_devfn(unsigned int *devfn) + { +@@ -157,13 +158,14 @@ static int p2sb_cache_resources(void) + * Unhide the P2SB device here, if needed. + */ + pci_bus_read_config_dword(bus, devfn_p2sb, P2SBC, &value); +- if (value & P2SBC_HIDE) ++ p2sb_hidden_by_bios = value & P2SBC_HIDE; ++ if (p2sb_hidden_by_bios) + pci_bus_write_config_dword(bus, devfn_p2sb, P2SBC, 0); + + ret = p2sb_scan_and_cache(bus, devfn_p2sb); + + /* Hide the P2SB device, if it was hidden */ +- if (value & P2SBC_HIDE) ++ if (p2sb_hidden_by_bios) + pci_bus_write_config_dword(bus, devfn_p2sb, P2SBC, P2SBC_HIDE); + + pci_unlock_rescan_remove(); +-- +2.39.5 + diff --git a/queue-6.6/p2sb-move-p2sb-hide-and-unhide-code-to-p2sb_scan_and.patch b/queue-6.6/p2sb-move-p2sb-hide-and-unhide-code-to-p2sb_scan_and.patch new file mode 100644 index 00000000000..daf4ef0806f --- /dev/null +++ b/queue-6.6/p2sb-move-p2sb-hide-and-unhide-code-to-p2sb_scan_and.patch @@ -0,0 +1,82 @@ +From 984dd70e1a4d6695e274e361a6be38cf32d44a5a Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Thu, 28 Nov 2024 09:28:35 +0900 +Subject: p2sb: Move P2SB hide and unhide code to p2sb_scan_and_cache() +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Shin'ichiro Kawasaki + +[ Upstream commit 0286070c74ee48391fc07f7f617460479472d221 ] + +To prepare for the following fix, move the code to hide and unhide the +P2SB device from p2sb_cache_resources() to p2sb_scan_and_cache(). + +Signed-off-by: Shin'ichiro Kawasaki +Reviewed-by: Hans de Goede +Link: https://lore.kernel.org/r/20241128002836.373745-4-shinichiro.kawasaki@wdc.com +Reviewed-by: Ilpo Järvinen +Signed-off-by: Ilpo Järvinen +Stable-dep-of: 360c400d0f56 ("p2sb: Do not scan and remove the P2SB device when it is unhidden") +Signed-off-by: Sasha Levin +--- + drivers/platform/x86/p2sb.c | 23 ++++++++++++----------- + 1 file changed, 12 insertions(+), 11 deletions(-) + +diff --git a/drivers/platform/x86/p2sb.c b/drivers/platform/x86/p2sb.c +index d015ddc9f30e..6fb76b82ecce 100644 +--- a/drivers/platform/x86/p2sb.c ++++ b/drivers/platform/x86/p2sb.c +@@ -97,6 +97,14 @@ static void p2sb_scan_and_cache_devfn(struct pci_bus *bus, unsigned int devfn) + + static int p2sb_scan_and_cache(struct pci_bus *bus, unsigned int devfn) + { ++ /* ++ * The BIOS prevents the P2SB device from being enumerated by the PCI ++ * subsystem, so we need to unhide and hide it back to lookup the BAR. ++ * Unhide the P2SB device here, if needed. ++ */ ++ if (p2sb_hidden_by_bios) ++ pci_bus_write_config_dword(bus, devfn, P2SBC, 0); ++ + /* Scan the P2SB device and cache its BAR0 */ + p2sb_scan_and_cache_devfn(bus, devfn); + +@@ -104,6 +112,10 @@ static int p2sb_scan_and_cache(struct pci_bus *bus, unsigned int devfn) + if (devfn == P2SB_DEVFN_GOLDMONT) + p2sb_scan_and_cache_devfn(bus, SPI_DEVFN_GOLDMONT); + ++ /* Hide the P2SB device, if it was hidden */ ++ if (p2sb_hidden_by_bios) ++ pci_bus_write_config_dword(bus, devfn, P2SBC, P2SBC_HIDE); ++ + if (!p2sb_valid_resource(&p2sb_resources[PCI_FUNC(devfn)].res)) + return -ENOENT; + +@@ -152,22 +164,11 @@ static int p2sb_cache_resources(void) + */ + pci_lock_rescan_remove(); + +- /* +- * The BIOS prevents the P2SB device from being enumerated by the PCI +- * subsystem, so we need to unhide and hide it back to lookup the BAR. +- * Unhide the P2SB device here, if needed. +- */ + pci_bus_read_config_dword(bus, devfn_p2sb, P2SBC, &value); + p2sb_hidden_by_bios = value & P2SBC_HIDE; +- if (p2sb_hidden_by_bios) +- pci_bus_write_config_dword(bus, devfn_p2sb, P2SBC, 0); + + ret = p2sb_scan_and_cache(bus, devfn_p2sb); + +- /* Hide the P2SB device, if it was hidden */ +- if (p2sb_hidden_by_bios) +- pci_bus_write_config_dword(bus, devfn_p2sb, P2SBC, P2SBC_HIDE); +- + pci_unlock_rescan_remove(); + + return ret; +-- +2.39.5 + diff --git a/queue-6.6/pci-add-acs-quirk-for-broadcom-bcm5760x-nic.patch b/queue-6.6/pci-add-acs-quirk-for-broadcom-bcm5760x-nic.patch new file mode 100644 index 00000000000..e10cde7dc55 --- /dev/null +++ b/queue-6.6/pci-add-acs-quirk-for-broadcom-bcm5760x-nic.patch @@ -0,0 +1,51 @@ +From d8f6b0803e6e1c262678d2098dbfd5747aff2812 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sun, 28 Jul 2024 12:06:37 -0400 +Subject: PCI: Add ACS quirk for Broadcom BCM5760X NIC +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Ajit Khaparde + +[ Upstream commit 524e057b2d66b61f9b63b6db30467ab7b0bb4796 ] + +The Broadcom BCM5760X NIC may be a multi-function device. + +While it does not advertise an ACS capability, peer-to-peer transactions +are not possible between the individual functions. So it is ok to treat +them as fully isolated. + +Add an ACS quirk for this device so the functions can be in independent +IOMMU groups and attached individually to userspace applications using +VFIO. + +[kwilczynski: commit log] +Link: https://lore.kernel.org/linux-pci/20240510204228.73435-1-ajit.khaparde@broadcom.com +Signed-off-by: Ajit Khaparde +Signed-off-by: Krzysztof Wilczyński +Signed-off-by: Bjorn Helgaas +Reviewed-by: Andy Gospodarek +Signed-off-by: Sasha Levin +--- + drivers/pci/quirks.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c +index c5115ad59766..fd35ad0648a0 100644 +--- a/drivers/pci/quirks.c ++++ b/drivers/pci/quirks.c +@@ -5116,6 +5116,10 @@ static const struct pci_dev_acs_enabled { + { PCI_VENDOR_ID_BROADCOM, 0x1750, pci_quirk_mf_endpoint_acs }, + { PCI_VENDOR_ID_BROADCOM, 0x1751, pci_quirk_mf_endpoint_acs }, + { PCI_VENDOR_ID_BROADCOM, 0x1752, pci_quirk_mf_endpoint_acs }, ++ { PCI_VENDOR_ID_BROADCOM, 0x1760, pci_quirk_mf_endpoint_acs }, ++ { PCI_VENDOR_ID_BROADCOM, 0x1761, pci_quirk_mf_endpoint_acs }, ++ { PCI_VENDOR_ID_BROADCOM, 0x1762, pci_quirk_mf_endpoint_acs }, ++ { PCI_VENDOR_ID_BROADCOM, 0x1763, pci_quirk_mf_endpoint_acs }, + { PCI_VENDOR_ID_BROADCOM, 0xD714, pci_quirk_brcm_acs }, + /* Amazon Annapurna Labs */ + { PCI_VENDOR_ID_AMAZON_ANNAPURNA_LABS, 0x0031, pci_quirk_al_acs }, +-- +2.39.5 + diff --git a/queue-6.6/pci-aer-disable-aer-service-on-suspend.patch b/queue-6.6/pci-aer-disable-aer-service-on-suspend.patch new file mode 100644 index 00000000000..84c4435dd31 --- /dev/null +++ b/queue-6.6/pci-aer-disable-aer-service-on-suspend.patch @@ -0,0 +1,68 @@ +From b209d3acede320ce3a17a550d46a66f58ca12881 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sun, 28 Jul 2024 12:06:45 -0400 +Subject: PCI/AER: Disable AER service on suspend + +From: Kai-Heng Feng + +[ Upstream commit 5afc2f763edc5daae4722ee46fea4e627d01fa90 ] + +If the link is powered off during suspend, electrical noise may cause +errors that are logged via AER. If the AER interrupt is enabled and shares +an IRQ with PME, that causes a spurious wakeup during suspend. + +Disable the AER interrupt during suspend to prevent this. Clear error +status before re-enabling IRQ interrupts during resume so we don't get an +interrupt for errors that occurred during the suspend/resume process. + +Link: https://bugzilla.kernel.org/show_bug.cgi?id=209149 +Link: https://bugzilla.kernel.org/show_bug.cgi?id=216295 +Link: https://bugzilla.kernel.org/show_bug.cgi?id=218090 +Link: https://lore.kernel.org/r/20240416043225.1462548-2-kai.heng.feng@canonical.com +Signed-off-by: Kai-Heng Feng +[bhelgaas: drop pci_ancestor_pr3_present() etc, commit log] +Signed-off-by: Bjorn Helgaas +Signed-off-by: Sasha Levin +--- + drivers/pci/pcie/aer.c | 18 ++++++++++++++++++ + 1 file changed, 18 insertions(+) + +diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c +index c9afe4362835..eeb9ea9044b4 100644 +--- a/drivers/pci/pcie/aer.c ++++ b/drivers/pci/pcie/aer.c +@@ -1342,6 +1342,22 @@ static int aer_probe(struct pcie_device *dev) + return 0; + } + ++static int aer_suspend(struct pcie_device *dev) ++{ ++ struct aer_rpc *rpc = get_service_data(dev); ++ ++ aer_disable_rootport(rpc); ++ return 0; ++} ++ ++static int aer_resume(struct pcie_device *dev) ++{ ++ struct aer_rpc *rpc = get_service_data(dev); ++ ++ aer_enable_rootport(rpc); ++ return 0; ++} ++ + /** + * aer_root_reset - reset Root Port hierarchy, RCEC, or RCiEP + * @dev: pointer to Root Port, RCEC, or RCiEP +@@ -1413,6 +1429,8 @@ static struct pcie_port_service_driver aerdriver = { + .service = PCIE_PORT_SERVICE_AER, + + .probe = aer_probe, ++ .suspend = aer_suspend, ++ .resume = aer_resume, + .remove = aer_remove, + }; + +-- +2.39.5 + diff --git a/queue-6.6/pci-use-preserve_config-in-place-of-pci_flags.patch b/queue-6.6/pci-use-preserve_config-in-place-of-pci_flags.patch new file mode 100644 index 00000000000..23e80d6506c --- /dev/null +++ b/queue-6.6/pci-use-preserve_config-in-place-of-pci_flags.patch @@ -0,0 +1,77 @@ +From 8d83cfa8fc65aecd13bd079e6365f8de68456fb9 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sun, 28 Jul 2024 12:06:38 -0400 +Subject: PCI: Use preserve_config in place of pci_flags + +From: Vidya Sagar + +[ Upstream commit 7246a4520b4bf1494d7d030166a11b5226f6d508 ] + +Use preserve_config in place of checking for PCI_PROBE_ONLY flag to enable +support for "linux,pci-probe-only" on a per host bridge basis. + +This also obviates the use of adding PCI_REASSIGN_ALL_BUS flag if +!PCI_PROBE_ONLY, as pci_assign_unassigned_root_bus_resources() takes care +of reassigning the resources that are not already claimed. + +Link: https://lore.kernel.org/r/20240508174138.3630283-5-vidyas@nvidia.com +Signed-off-by: Vidya Sagar +Signed-off-by: Bjorn Helgaas +Signed-off-by: Sasha Levin +--- + drivers/pci/controller/pci-host-common.c | 4 ---- + drivers/pci/probe.c | 20 +++++++++----------- + 2 files changed, 9 insertions(+), 15 deletions(-) + +diff --git a/drivers/pci/controller/pci-host-common.c b/drivers/pci/controller/pci-host-common.c +index 6be3266cd7b5..e2602e38ae45 100644 +--- a/drivers/pci/controller/pci-host-common.c ++++ b/drivers/pci/controller/pci-host-common.c +@@ -73,10 +73,6 @@ int pci_host_common_probe(struct platform_device *pdev) + if (IS_ERR(cfg)) + return PTR_ERR(cfg); + +- /* Do not reassign resources if probe only */ +- if (!pci_has_flag(PCI_PROBE_ONLY)) +- pci_add_flags(PCI_REASSIGN_ALL_BUS); +- + bridge->sysdata = cfg; + bridge->ops = (struct pci_ops *)&ops->pci_ops; + bridge->msi_domain = true; +diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c +index 03b519a22840..7e84e472b338 100644 +--- a/drivers/pci/probe.c ++++ b/drivers/pci/probe.c +@@ -3096,20 +3096,18 @@ int pci_host_probe(struct pci_host_bridge *bridge) + + bus = bridge->bus; + ++ /* If we must preserve the resource configuration, claim now */ ++ if (bridge->preserve_config) ++ pci_bus_claim_resources(bus); ++ + /* +- * We insert PCI resources into the iomem_resource and +- * ioport_resource trees in either pci_bus_claim_resources() +- * or pci_bus_assign_resources(). ++ * Assign whatever was left unassigned. If we didn't claim above, ++ * this will reassign everything. + */ +- if (pci_has_flag(PCI_PROBE_ONLY)) { +- pci_bus_claim_resources(bus); +- } else { +- pci_bus_size_bridges(bus); +- pci_bus_assign_resources(bus); ++ pci_assign_unassigned_root_bus_resources(bus); + +- list_for_each_entry(child, &bus->children, node) +- pcie_bus_configure_settings(child); +- } ++ list_for_each_entry(child, &bus->children, node) ++ pcie_bus_configure_settings(child); + + pci_bus_add_devices(bus); + return 0; +-- +2.39.5 + diff --git a/queue-6.6/pci-vmd-create-domain-symlink-before-pci_bus_add_dev.patch b/queue-6.6/pci-vmd-create-domain-symlink-before-pci_bus_add_dev.patch new file mode 100644 index 00000000000..cf64d724506 --- /dev/null +++ b/queue-6.6/pci-vmd-create-domain-symlink-before-pci_bus_add_dev.patch @@ -0,0 +1,116 @@ +From 5ad890118a608d48701b5cf9f721db444106018b Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sun, 28 Jul 2024 12:06:51 -0400 +Subject: PCI: vmd: Create domain symlink before pci_bus_add_devices() +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Jiwei Sun + +[ Upstream commit f24c9bfcd423e2b2bb0d198456412f614ec2030a ] + +The vmd driver creates a "domain" symlink in sysfs for each VMD bridge. +Previously this symlink was created after pci_bus_add_devices() added +devices below the VMD bridge and emitted udev events to announce them to +userspace. + +This led to a race between userspace consumers of the udev events and the +kernel creation of the symlink. One such consumer is mdadm, which +assembles block devices into a RAID array, and for devices below a VMD +bridge, mdadm depends on the "domain" symlink. + +If mdadm loses the race, it may be unable to assemble a RAID array, which +may cause a boot failure or other issues, with complaints like this: + + (udev-worker)[2149]: nvme1n1: '/sbin/mdadm -I /dev/nvme1n1'(err) 'mdadm: Unable to get real path for '/sys/bus/pci/drivers/vmd/0000:c7:00.5/domain/device'' + (udev-worker)[2149]: nvme1n1: '/sbin/mdadm -I /dev/nvme1n1'(err) 'mdadm: /dev/nvme1n1 is not attached to Intel(R) RAID controller.' + (udev-worker)[2149]: nvme1n1: '/sbin/mdadm -I /dev/nvme1n1'(err) 'mdadm: No OROM/EFI properties for /dev/nvme1n1' + (udev-worker)[2149]: nvme1n1: '/sbin/mdadm -I /dev/nvme1n1'(err) 'mdadm: no RAID superblock on /dev/nvme1n1.' + (udev-worker)[2149]: nvme1n1: Process '/sbin/mdadm -I /dev/nvme1n1' failed with exit code 1. + +This symptom prevents the OS from booting successfully. + +After a NVMe disk is probed/added by the nvme driver, udevd invokes mdadm +to detect if there is a mdraid associated with this NVMe disk, and mdadm +determines if a NVMe device is connected to a particular VMD domain by +checking the "domain" symlink. For example: + + Thread A Thread B Thread mdadm + vmd_enable_domain + pci_bus_add_devices + __driver_probe_device + ... + work_on_cpu + schedule_work_on + : wakeup Thread B + nvme_probe + : wakeup scan_work + to scan nvme disk + and add nvme disk + then wakeup udevd + : udevd executes + mdadm command + flush_work main + : wait for nvme_probe done ... + __driver_probe_device find_driver_devices + : probe next nvme device : 1) Detect domain symlink + ... 2) Find domain symlink + ... from vmd sysfs + ... 3) Domain symlink not + ... created yet; failed + sysfs_create_link + : create domain symlink + +Create the VMD "domain" symlink before invoking pci_bus_add_devices() to +avoid this race. + +Suggested-by: Adrian Huang +Link: https://lore.kernel.org/linux-pci/20240605124844.24293-1-sjiwei@163.com +Signed-off-by: Jiwei Sun +Signed-off-by: Krzysztof Wilczyński +[bhelgaas: commit log] +Signed-off-by: Bjorn Helgaas +Reviewed-by: Nirmal Patel +Signed-off-by: Sasha Levin +--- + drivers/pci/controller/vmd.c | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/drivers/pci/controller/vmd.c b/drivers/pci/controller/vmd.c +index 992fea22fd9f..5ff2066aa516 100644 +--- a/drivers/pci/controller/vmd.c ++++ b/drivers/pci/controller/vmd.c +@@ -930,6 +930,9 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) + dev_set_msi_domain(&vmd->bus->dev, + dev_get_msi_domain(&vmd->dev->dev)); + ++ WARN(sysfs_create_link(&vmd->dev->dev.kobj, &vmd->bus->dev.kobj, ++ "domain"), "Can't create symlink to domain\n"); ++ + vmd_acpi_begin(); + + pci_scan_child_bus(vmd->bus); +@@ -969,9 +972,6 @@ static int vmd_enable_domain(struct vmd_dev *vmd, unsigned long features) + pci_bus_add_devices(vmd->bus); + + vmd_acpi_end(); +- +- WARN(sysfs_create_link(&vmd->dev->dev.kobj, &vmd->bus->dev.kobj, +- "domain"), "Can't create symlink to domain\n"); + return 0; + } + +@@ -1047,8 +1047,8 @@ static void vmd_remove(struct pci_dev *dev) + { + struct vmd_dev *vmd = pci_get_drvdata(dev); + +- sysfs_remove_link(&vmd->dev->dev.kobj, "domain"); + pci_stop_root_bus(vmd->bus); ++ sysfs_remove_link(&vmd->dev->dev.kobj, "domain"); + pci_remove_root_bus(vmd->bus); + vmd_cleanup_srcu(vmd); + vmd_detach_resources(vmd); +-- +2.39.5 + diff --git a/queue-6.6/platform-x86-p2sb-make-p2sb_get_devfn-return-void.patch b/queue-6.6/platform-x86-p2sb-make-p2sb_get_devfn-return-void.patch new file mode 100644 index 00000000000..4c1bcc0caed --- /dev/null +++ b/queue-6.6/platform-x86-p2sb-make-p2sb_get_devfn-return-void.patch @@ -0,0 +1,76 @@ +From 2cc8c23bb48219c69d64685854121844c4cbf919 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Tue, 5 Mar 2024 10:45:00 +0100 +Subject: platform/x86: p2sb: Make p2sb_get_devfn() return void + +From: Hans de Goede + +[ Upstream commit 3ff5873602a874035ba28826852bd45393002a08 ] + +p2sb_get_devfn() always succeeds, make it return void and +remove error checking from its callers. + +Reviewed-by: Shin'ichiro Kawasaki +Signed-off-by: Hans de Goede +Link: https://lore.kernel.org/r/20240305094500.23778-1-hdegoede@redhat.com +Stable-dep-of: 360c400d0f56 ("p2sb: Do not scan and remove the P2SB device when it is unhidden") +Signed-off-by: Sasha Levin +--- + drivers/platform/x86/p2sb.c | 15 ++++----------- + 1 file changed, 4 insertions(+), 11 deletions(-) + +diff --git a/drivers/platform/x86/p2sb.c b/drivers/platform/x86/p2sb.c +index 053be5c5e0ca..687e341e3206 100644 +--- a/drivers/platform/x86/p2sb.c ++++ b/drivers/platform/x86/p2sb.c +@@ -43,7 +43,7 @@ struct p2sb_res_cache { + + static struct p2sb_res_cache p2sb_resources[NR_P2SB_RES_CACHE]; + +-static int p2sb_get_devfn(unsigned int *devfn) ++static void p2sb_get_devfn(unsigned int *devfn) + { + unsigned int fn = P2SB_DEVFN_DEFAULT; + const struct x86_cpu_id *id; +@@ -53,7 +53,6 @@ static int p2sb_get_devfn(unsigned int *devfn) + fn = (unsigned int)id->driver_data; + + *devfn = fn; +- return 0; + } + + static bool p2sb_valid_resource(const struct resource *res) +@@ -132,9 +131,7 @@ static int p2sb_cache_resources(void) + int ret; + + /* Get devfn for P2SB device itself */ +- ret = p2sb_get_devfn(&devfn_p2sb); +- if (ret) +- return ret; ++ p2sb_get_devfn(&devfn_p2sb); + + bus = p2sb_get_bus(NULL); + if (!bus) +@@ -191,17 +188,13 @@ static int p2sb_cache_resources(void) + int p2sb_bar(struct pci_bus *bus, unsigned int devfn, struct resource *mem) + { + struct p2sb_res_cache *cache; +- int ret; + + bus = p2sb_get_bus(bus); + if (!bus) + return -ENODEV; + +- if (!devfn) { +- ret = p2sb_get_devfn(&devfn); +- if (ret) +- return ret; +- } ++ if (!devfn) ++ p2sb_get_devfn(&devfn); + + cache = &p2sb_resources[PCI_FUNC(devfn)]; + if (cache->bus_dev_id != bus->dev.id) +-- +2.39.5 + diff --git a/queue-6.6/series b/queue-6.6/series index 19e6f6cda0b..06752a16da3 100644 --- a/queue-6.6/series +++ b/queue-6.6/series @@ -1 +1,35 @@ net-sched-fix-ordering-of-qlen-adjustment.patch +usb-dwc2-gadget-don-t-write-invalid-mapped-sg-entrie.patch +pci-vmd-create-domain-symlink-before-pci_bus_add_dev.patch +pci-add-acs-quirk-for-broadcom-bcm5760x-nic.patch +usb-cdns3-ti-add-workaround-for-errata-i2409.patch +mips-loongson64-dts-fix-msi-node-for-ls7a.patch +asoc-intel-sof_sdw-fix-jack-detection-on-adl-n-varia.patch +asoc-intel-sof_sdw-add-quirk-for-dell-sku-0b8c.patch +pci-use-preserve_config-in-place-of-pci_flags.patch +pci-aer-disable-aer-service-on-suspend.patch +usb-cdns3-add-quirk-flag-to-enable-suspend-residency.patch +net-stmmac-fix-tso-dma-api-usage-causing-oops.patch +platform-x86-p2sb-make-p2sb_get_devfn-return-void.patch +p2sb-factor-out-p2sb_read_from_cache.patch +p2sb-introduce-the-global-flag-p2sb_hidden_by_bios.patch +p2sb-move-p2sb-hide-and-unhide-code-to-p2sb_scan_and.patch +p2sb-do-not-scan-and-remove-the-p2sb-device-when-it-.patch +i2c-pnx-fix-timeout-in-wait-functions.patch +xfs-fix-the-contact-address-for-the-sysfs-abi-docume.patch +xfs-verify-buffer-inode-and-dquot-items-every-tx-com.patch +xfs-use-consistent-uid-gid-when-grabbing-dquots-for-.patch +xfs-declare-xfs_file.c-symbols-in-xfs_file.h.patch +xfs-create-a-new-helper-to-return-a-file-s-allocatio.patch +xfs-fix-xfs_flush_unmap_range-range-for-rt.patch +xfs-fix-xfs_prepare_shift-range-for-rt.patch +xfs-don-t-walk-off-the-end-of-a-directory-data-block.patch +xfs-convert-comma-to-semicolon.patch +xfs-fix-file_path-handling-in-tracepoints.patch +xfs-remove-unused-parameter-in-macro-xfs_dquot_logre.patch +xfs-attr-forks-require-attr-not-attr2.patch +xfs-conditionally-allow-fs_xflag_realtime-changes-if.patch +xfs-fix-the-owner-setting-issue-for-rmap-query-in-xf.patch +xfs-use-xfs_buf_daddr_null-for-daddrs-in-getfsmap-co.patch +xfs-take-m_growlock-when-running-growfsrt.patch +xfs-reset-rootdir-extent-size-hint-after-growfsrt.patch diff --git a/queue-6.6/usb-cdns3-add-quirk-flag-to-enable-suspend-residency.patch b/queue-6.6/usb-cdns3-add-quirk-flag-to-enable-suspend-residency.patch new file mode 100644 index 00000000000..95c78df3b57 --- /dev/null +++ b/queue-6.6/usb-cdns3-add-quirk-flag-to-enable-suspend-residency.patch @@ -0,0 +1,86 @@ +From dac179bced3da26676360d1f4c7ec923a01d2158 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sun, 28 Jul 2024 12:06:39 -0400 +Subject: usb: cdns3: Add quirk flag to enable suspend residency + +From: Roger Quadros + +[ Upstream commit 0aca19e4037a4143273e90f1b44666b78b4dde9b ] + +Some platforms (e.g. ti,j721e-usb, ti,am64-usb) require +this bit to be set to workaround a lockup issue with PHY +short suspend intervals [1]. Add a platform quirk flag +to indicate if Suspend Residency should be enabled. + +[1] - https://www.ti.com/lit/er/sprz457h/sprz457h.pdf +i2409 - USB: USB2 PHY locks up due to short suspend + +Signed-off-by: Roger Quadros +Signed-off-by: Ravi Gunasekaran +Acked-by: Peter Chen +Link: https://lore.kernel.org/r/20240516044537.16801-2-r-gunasekaran@ti.com +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/usb/cdns3/core.h | 1 + + drivers/usb/cdns3/drd.c | 10 +++++++++- + drivers/usb/cdns3/drd.h | 3 +++ + 3 files changed, 13 insertions(+), 1 deletion(-) + +diff --git a/drivers/usb/cdns3/core.h b/drivers/usb/cdns3/core.h +index 81a9c9d6be08..57d47348dc19 100644 +--- a/drivers/usb/cdns3/core.h ++++ b/drivers/usb/cdns3/core.h +@@ -44,6 +44,7 @@ struct cdns3_platform_data { + bool suspend, bool wakeup); + unsigned long quirks; + #define CDNS3_DEFAULT_PM_RUNTIME_ALLOW BIT(0) ++#define CDNS3_DRD_SUSPEND_RESIDENCY_ENABLE BIT(1) + }; + + /** +diff --git a/drivers/usb/cdns3/drd.c b/drivers/usb/cdns3/drd.c +index ee917f1b091c..1b4ce2da1e4b 100644 +--- a/drivers/usb/cdns3/drd.c ++++ b/drivers/usb/cdns3/drd.c +@@ -389,7 +389,7 @@ static irqreturn_t cdns_drd_irq(int irq, void *data) + int cdns_drd_init(struct cdns *cdns) + { + void __iomem *regs; +- u32 state; ++ u32 state, reg; + int ret; + + regs = devm_ioremap_resource(cdns->dev, &cdns->otg_res); +@@ -433,6 +433,14 @@ int cdns_drd_init(struct cdns *cdns) + cdns->otg_irq_regs = (struct cdns_otg_irq_regs __iomem *) + &cdns->otg_v1_regs->ien; + writel(1, &cdns->otg_v1_regs->simulate); ++ ++ if (cdns->pdata && ++ (cdns->pdata->quirks & CDNS3_DRD_SUSPEND_RESIDENCY_ENABLE)) { ++ reg = readl(&cdns->otg_v1_regs->susp_ctrl); ++ reg |= SUSP_CTRL_SUSPEND_RESIDENCY_ENABLE; ++ writel(reg, &cdns->otg_v1_regs->susp_ctrl); ++ } ++ + cdns->version = CDNS3_CONTROLLER_V1; + } else { + dev_err(cdns->dev, "not supporte DID=0x%08x\n", state); +diff --git a/drivers/usb/cdns3/drd.h b/drivers/usb/cdns3/drd.h +index d72370c321d3..1e2aee14d629 100644 +--- a/drivers/usb/cdns3/drd.h ++++ b/drivers/usb/cdns3/drd.h +@@ -193,6 +193,9 @@ struct cdns_otg_irq_regs { + /* OTGREFCLK - bitmasks */ + #define OTGREFCLK_STB_CLK_SWITCH_EN BIT(31) + ++/* SUPS_CTRL - bitmasks */ ++#define SUSP_CTRL_SUSPEND_RESIDENCY_ENABLE BIT(17) ++ + /* OVERRIDE - bitmasks */ + #define OVERRIDE_IDPULLUP BIT(0) + /* Only for CDNS3_CONTROLLER_V0 version */ +-- +2.39.5 + diff --git a/queue-6.6/usb-cdns3-ti-add-workaround-for-errata-i2409.patch b/queue-6.6/usb-cdns3-ti-add-workaround-for-errata-i2409.patch new file mode 100644 index 00000000000..dde9069df4c --- /dev/null +++ b/queue-6.6/usb-cdns3-ti-add-workaround-for-errata-i2409.patch @@ -0,0 +1,68 @@ +From a96162733b435b84e52cca4849a6a449b1ee1748 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sun, 28 Jul 2024 12:06:40 -0400 +Subject: usb: cdns3-ti: Add workaround for Errata i2409 + +From: Roger Quadros + +[ Upstream commit b50a2da03bd95784541b3f9058e452cc38f9ba05 ] + +TI USB2 PHY is known to have a lockup issue on very short +suspend intervals. Enable the Suspend Residency quirk flag to +workaround this as described in Errata i2409 [1]. + +[1] - https://www.ti.com/lit/er/sprz457h/sprz457h.pdf + +Signed-off-by: Roger Quadros +Signed-off-by: Ravi Gunasekaran +Acked-by: Peter Chen +Link: https://lore.kernel.org/r/20240516044537.16801-3-r-gunasekaran@ti.com +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/usb/cdns3/cdns3-ti.c | 15 ++++++++++++++- + 1 file changed, 14 insertions(+), 1 deletion(-) + +diff --git a/drivers/usb/cdns3/cdns3-ti.c b/drivers/usb/cdns3/cdns3-ti.c +index 5945c4b1e11f..cfabc12ee0e3 100644 +--- a/drivers/usb/cdns3/cdns3-ti.c ++++ b/drivers/usb/cdns3/cdns3-ti.c +@@ -16,6 +16,7 @@ + #include + #include + #include ++#include "core.h" + + /* USB Wrapper register offsets */ + #define USBSS_PID 0x0 +@@ -85,6 +86,18 @@ static inline void cdns_ti_writel(struct cdns_ti *data, u32 offset, u32 value) + writel(value, data->usbss + offset); + } + ++static struct cdns3_platform_data cdns_ti_pdata = { ++ .quirks = CDNS3_DRD_SUSPEND_RESIDENCY_ENABLE, /* Errata i2409 */ ++}; ++ ++static const struct of_dev_auxdata cdns_ti_auxdata[] = { ++ { ++ .compatible = "cdns,usb3", ++ .platform_data = &cdns_ti_pdata, ++ }, ++ {}, ++}; ++ + static int cdns_ti_probe(struct platform_device *pdev) + { + struct device *dev = &pdev->dev; +@@ -176,7 +189,7 @@ static int cdns_ti_probe(struct platform_device *pdev) + reg |= USBSS_W1_PWRUP_RST; + cdns_ti_writel(data, USBSS_W1, reg); + +- error = of_platform_populate(node, NULL, NULL, dev); ++ error = of_platform_populate(node, NULL, cdns_ti_auxdata, dev); + if (error) { + dev_err(dev, "failed to create children: %d\n", error); + goto err; +-- +2.39.5 + diff --git a/queue-6.6/usb-dwc2-gadget-don-t-write-invalid-mapped-sg-entrie.patch b/queue-6.6/usb-dwc2-gadget-don-t-write-invalid-mapped-sg-entrie.patch new file mode 100644 index 00000000000..6eb8284da9c --- /dev/null +++ b/queue-6.6/usb-dwc2-gadget-don-t-write-invalid-mapped-sg-entrie.patch @@ -0,0 +1,56 @@ +From f66c297612868cb9c2e37450676f74eb4bd6d7ab Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Sun, 28 Jul 2024 12:06:41 -0400 +Subject: usb: dwc2: gadget: Don't write invalid mapped sg entries into + dma_desc with iommu enabled + +From: Peng Hongchi + +[ Upstream commit 1134289b6b93d73721340b66c310fd985385e8fa ] + +When using dma_map_sg() to map the scatterlist with iommu enabled, +the entries in the scatterlist can be mergerd into less but longer +entries in the function __finalise_sg(). So that the number of +valid mapped entries is actually smaller than ureq->num_reqs,and +there are still some invalid entries in the scatterlist with +dma_addr=0xffffffff and len=0. Writing these invalid sg entries +into the dma_desc can cause a data transmission error. + +The function dma_map_sg() returns the number of valid map entries +and the return value is assigned to usb_request::num_mapped_sgs in +function usb_gadget_map_request_by_dev(). So that just write valid +mapped entries into dma_desc according to the usb_request::num_mapped_sgs, +and set the IOC bit if it's the last valid mapped entry. + +This patch poses no risk to no-iommu situation, cause +ureq->num_mapped_sgs equals ureq->num_sgs while using dma_direct_map_sg() +to map the scatterlist whith iommu disabled. + +Signed-off-by: Peng Hongchi +Link: https://lore.kernel.org/r/20240523100315.7226-1-hongchi.peng@siengine.com +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/usb/dwc2/gadget.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c +index b2f6da5b65cc..b26de09f6b6d 100644 +--- a/drivers/usb/dwc2/gadget.c ++++ b/drivers/usb/dwc2/gadget.c +@@ -885,10 +885,10 @@ static void dwc2_gadget_config_nonisoc_xfer_ddma(struct dwc2_hsotg_ep *hs_ep, + } + + /* DMA sg buffer */ +- for_each_sg(ureq->sg, sg, ureq->num_sgs, i) { ++ for_each_sg(ureq->sg, sg, ureq->num_mapped_sgs, i) { + dwc2_gadget_fill_nonisoc_xfer_ddma_one(hs_ep, &desc, + sg_dma_address(sg) + sg->offset, sg_dma_len(sg), +- sg_is_last(sg)); ++ (i == (ureq->num_mapped_sgs - 1))); + desc_count += hs_ep->desc_count; + } + +-- +2.39.5 + diff --git a/queue-6.6/xfs-attr-forks-require-attr-not-attr2.patch b/queue-6.6/xfs-attr-forks-require-attr-not-attr2.patch new file mode 100644 index 00000000000..b41147f5042 --- /dev/null +++ b/queue-6.6/xfs-attr-forks-require-attr-not-attr2.patch @@ -0,0 +1,50 @@ +From ffde56f454becc67a2b481926f6284a1bc8b4a9b Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 18 Dec 2024 11:17:20 -0800 +Subject: xfs: attr forks require attr, not attr2 + +From: Darrick J. Wong + +commit 73c34b0b85d46bf9c2c0b367aeaffa1e2481b136 upstream. + +It turns out that I misunderstood the difference between the attr and +attr2 feature bits. "attr" means that at some point an attr fork was +created somewhere in the filesystem. "attr2" means that inodes have +variable-sized forks, but says nothing about whether or not there +actually /are/ attr forks in the system. + +If we have an attr fork, we only need to check that attr is set. + +Fixes: 99d9d8d05da26 ("xfs: scrub inode block mappings") +Signed-off-by: Darrick J. Wong +Reviewed-by: Christoph Hellwig +Signed-off-by: Chandan Babu R +Signed-off-by: Catherine Hoang +Acked-by: Darrick J. Wong +Signed-off-by: Sasha Levin +--- + fs/xfs/scrub/bmap.c | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/fs/xfs/scrub/bmap.c b/fs/xfs/scrub/bmap.c +index 75588915572e..9dfa310df311 100644 +--- a/fs/xfs/scrub/bmap.c ++++ b/fs/xfs/scrub/bmap.c +@@ -857,7 +857,13 @@ xchk_bmap( + } + break; + case XFS_ATTR_FORK: +- if (!xfs_has_attr(mp) && !xfs_has_attr2(mp)) ++ /* ++ * "attr" means that an attr fork was created at some point in ++ * the life of this filesystem. "attr2" means that inodes have ++ * variable-sized data/attr fork areas. Hence we only check ++ * attr here. ++ */ ++ if (!xfs_has_attr(mp)) + xchk_ino_set_corrupt(sc, sc->ip->i_ino); + break; + default: +-- +2.39.5 + diff --git a/queue-6.6/xfs-conditionally-allow-fs_xflag_realtime-changes-if.patch b/queue-6.6/xfs-conditionally-allow-fs_xflag_realtime-changes-if.patch new file mode 100644 index 00000000000..0b8fee0c589 --- /dev/null +++ b/queue-6.6/xfs-conditionally-allow-fs_xflag_realtime-changes-if.patch @@ -0,0 +1,51 @@ +From 6e35ee75134d50774464613eb3d40046774fda13 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 18 Dec 2024 11:17:21 -0800 +Subject: xfs: conditionally allow FS_XFLAG_REALTIME changes if S_DAX is set + +From: Darrick J. Wong + +commit 8d16762047c627073955b7ed171a36addaf7b1ff upstream. + +If a file has the S_DAX flag (aka fsdax access mode) set, we cannot +allow users to change the realtime flag unless the datadev and rtdev +both support fsdax access modes. Even if there are no extents allocated +to the file, the setattr thread could be racing with another thread +that has already started down the write code paths. + +Fixes: ba23cba9b3bdc ("fs: allow per-device dax status checking for filesystems") +Signed-off-by: Darrick J. Wong +Reviewed-by: Christoph Hellwig +Signed-off-by: Chandan Babu R +Signed-off-by: Catherine Hoang +Acked-by: Darrick J. Wong +Signed-off-by: Sasha Levin +--- + fs/xfs/xfs_ioctl.c | 11 +++++++++++ + 1 file changed, 11 insertions(+) + +diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c +index df4bf0d56aad..32e718043e0e 100644 +--- a/fs/xfs/xfs_ioctl.c ++++ b/fs/xfs/xfs_ioctl.c +@@ -1128,6 +1128,17 @@ xfs_ioctl_setattr_xflags( + /* Can't change realtime flag if any extents are allocated. */ + if (ip->i_df.if_nextents || ip->i_delayed_blks) + return -EINVAL; ++ ++ /* ++ * If S_DAX is enabled on this file, we can only switch the ++ * device if both support fsdax. We can't update S_DAX because ++ * there might be other threads walking down the access paths. ++ */ ++ if (IS_DAX(VFS_I(ip)) && ++ (mp->m_ddev_targp->bt_daxdev == NULL || ++ (mp->m_rtdev_targp && ++ mp->m_rtdev_targp->bt_daxdev == NULL))) ++ return -EINVAL; + } + + if (rtflag) { +-- +2.39.5 + diff --git a/queue-6.6/xfs-convert-comma-to-semicolon.patch b/queue-6.6/xfs-convert-comma-to-semicolon.patch new file mode 100644 index 00000000000..257d2e9bad1 --- /dev/null +++ b/queue-6.6/xfs-convert-comma-to-semicolon.patch @@ -0,0 +1,38 @@ +From f98d8b12c9826224cf34f9a4b16babe4b2e0882c Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 18 Dec 2024 11:17:17 -0800 +Subject: xfs: convert comma to semicolon + +From: Chen Ni + +commit 7bf888fa26e8f22bed4bc3965ab2a2953104ff96 upstream. + +Replace a comma between expression statements by a semicolon. + +Fixes: 178b48d588ea ("xfs: remove the for_each_xbitmap_ helpers") +Signed-off-by: Chen Ni +Reviewed-by: Darrick J. Wong +Signed-off-by: Chandan Babu R +Signed-off-by: Catherine Hoang +Acked-by: Darrick J. Wong +Signed-off-by: Sasha Levin +--- + fs/xfs/scrub/agheader_repair.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/fs/xfs/scrub/agheader_repair.c b/fs/xfs/scrub/agheader_repair.c +index 876a2f41b063..058b6c305224 100644 +--- a/fs/xfs/scrub/agheader_repair.c ++++ b/fs/xfs/scrub/agheader_repair.c +@@ -705,7 +705,7 @@ xrep_agfl_init_header( + * step. + */ + xagb_bitmap_init(&af.used_extents); +- af.agfl_bno = xfs_buf_to_agfl_bno(agfl_bp), ++ af.agfl_bno = xfs_buf_to_agfl_bno(agfl_bp); + xagb_bitmap_walk(agfl_extents, xrep_agfl_fill, &af); + error = xagb_bitmap_disunion(agfl_extents, &af.used_extents); + if (error) +-- +2.39.5 + diff --git a/queue-6.6/xfs-create-a-new-helper-to-return-a-file-s-allocatio.patch b/queue-6.6/xfs-create-a-new-helper-to-return-a-file-s-allocatio.patch new file mode 100644 index 00000000000..5e2c58c7864 --- /dev/null +++ b/queue-6.6/xfs-create-a-new-helper-to-return-a-file-s-allocatio.patch @@ -0,0 +1,128 @@ +From 6c6221ad1c3fcb4d6040d5a54bb8d2ce1aed2b5f Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 18 Dec 2024 11:17:13 -0800 +Subject: xfs: create a new helper to return a file's allocation unit + +From: Darrick J. Wong + +commit ee20808d848c87a51e176706d81b95a21747d6cf upstream. + +[backport: dependency of d3b689d and f23660f] + +Create a new helper function to calculate the fundamental allocation +unit (i.e. the smallest unit of space we can allocate) of a file. +Things are going to get hairy with range-exchange on the realtime +device, so prepare for this now. + +Remove the static attribute from xfs_is_falloc_aligned since the next +patch will need it. + +Signed-off-by: Darrick J. Wong +Reviewed-by: Christoph Hellwig +Signed-off-by: Catherine Hoang +Acked-by: Darrick J. Wong +Signed-off-by: Sasha Levin +--- + fs/xfs/xfs_file.c | 32 ++++++++++++-------------------- + fs/xfs/xfs_file.h | 3 +++ + fs/xfs/xfs_inode.c | 13 +++++++++++++ + fs/xfs/xfs_inode.h | 2 ++ + 4 files changed, 30 insertions(+), 20 deletions(-) + +diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c +index 8dcbcf965b2c..3b9d43d5c746 100644 +--- a/fs/xfs/xfs_file.c ++++ b/fs/xfs/xfs_file.c +@@ -39,33 +39,25 @@ static const struct vm_operations_struct xfs_file_vm_ops; + * Decide if the given file range is aligned to the size of the fundamental + * allocation unit for the file. + */ +-static bool ++bool + xfs_is_falloc_aligned( + struct xfs_inode *ip, + loff_t pos, + long long int len) + { +- struct xfs_mount *mp = ip->i_mount; +- uint64_t mask; +- +- if (XFS_IS_REALTIME_INODE(ip)) { +- if (!is_power_of_2(mp->m_sb.sb_rextsize)) { +- u64 rextbytes; +- u32 mod; +- +- rextbytes = XFS_FSB_TO_B(mp, mp->m_sb.sb_rextsize); +- div_u64_rem(pos, rextbytes, &mod); +- if (mod) +- return false; +- div_u64_rem(len, rextbytes, &mod); +- return mod == 0; +- } +- mask = XFS_FSB_TO_B(mp, mp->m_sb.sb_rextsize) - 1; +- } else { +- mask = mp->m_sb.sb_blocksize - 1; ++ unsigned int alloc_unit = xfs_inode_alloc_unitsize(ip); ++ ++ if (!is_power_of_2(alloc_unit)) { ++ u32 mod; ++ ++ div_u64_rem(pos, alloc_unit, &mod); ++ if (mod) ++ return false; ++ div_u64_rem(len, alloc_unit, &mod); ++ return mod == 0; + } + +- return !((pos | len) & mask); ++ return !((pos | len) & (alloc_unit - 1)); + } + + /* +diff --git a/fs/xfs/xfs_file.h b/fs/xfs/xfs_file.h +index 7d39e3eca56d..2ad91f755caf 100644 +--- a/fs/xfs/xfs_file.h ++++ b/fs/xfs/xfs_file.h +@@ -9,4 +9,7 @@ + extern const struct file_operations xfs_file_operations; + extern const struct file_operations xfs_dir_file_operations; + ++bool xfs_is_falloc_aligned(struct xfs_inode *ip, loff_t pos, ++ long long int len); ++ + #endif /* __XFS_FILE_H__ */ +diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c +index 1e50cc9a29db..6f7dca1c14c7 100644 +--- a/fs/xfs/xfs_inode.c ++++ b/fs/xfs/xfs_inode.c +@@ -3782,3 +3782,16 @@ xfs_inode_reload_unlinked( + + return error; + } ++ ++/* Returns the size of fundamental allocation unit for a file, in bytes. */ ++unsigned int ++xfs_inode_alloc_unitsize( ++ struct xfs_inode *ip) ++{ ++ unsigned int blocks = 1; ++ ++ if (XFS_IS_REALTIME_INODE(ip)) ++ blocks = ip->i_mount->m_sb.sb_rextsize; ++ ++ return XFS_FSB_TO_B(ip->i_mount, blocks); ++} +diff --git a/fs/xfs/xfs_inode.h b/fs/xfs/xfs_inode.h +index 3beb470f1892..0f2999b84e7d 100644 +--- a/fs/xfs/xfs_inode.h ++++ b/fs/xfs/xfs_inode.h +@@ -622,4 +622,6 @@ xfs_inode_unlinked_incomplete( + int xfs_inode_reload_unlinked_bucket(struct xfs_trans *tp, struct xfs_inode *ip); + int xfs_inode_reload_unlinked(struct xfs_inode *ip); + ++unsigned int xfs_inode_alloc_unitsize(struct xfs_inode *ip); ++ + #endif /* __XFS_INODE_H__ */ +-- +2.39.5 + diff --git a/queue-6.6/xfs-declare-xfs_file.c-symbols-in-xfs_file.h.patch b/queue-6.6/xfs-declare-xfs_file.c-symbols-in-xfs_file.h.patch new file mode 100644 index 00000000000..ec48e8d6cf0 --- /dev/null +++ b/queue-6.6/xfs-declare-xfs_file.c-symbols-in-xfs_file.h.patch @@ -0,0 +1,100 @@ +From 9079b3fd5caaa6ebbe25eeb48e34d8e70addbaf7 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 18 Dec 2024 11:17:12 -0800 +Subject: xfs: declare xfs_file.c symbols in xfs_file.h + +From: Darrick J. Wong + +commit 00acb28d96746f78389f23a7b5309a917b45c12f upstream. + +[backport: dependency of d3b689d and f23660f] + +Move the two public symbols in xfs_file.c to xfs_file.h. We're about to +add more public symbols in that source file, so let's finally create the +header file. + +Signed-off-by: Darrick J. Wong +Reviewed-by: Christoph Hellwig +Signed-off-by: Catherine Hoang +Acked-by: Darrick J. Wong +Signed-off-by: Sasha Levin +--- + fs/xfs/xfs_file.c | 1 + + fs/xfs/xfs_file.h | 12 ++++++++++++ + fs/xfs/xfs_ioctl.c | 1 + + fs/xfs/xfs_iops.c | 1 + + fs/xfs/xfs_iops.h | 3 --- + 5 files changed, 15 insertions(+), 3 deletions(-) + create mode 100644 fs/xfs/xfs_file.h + +diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c +index 16769c22c070..8dcbcf965b2c 100644 +--- a/fs/xfs/xfs_file.c ++++ b/fs/xfs/xfs_file.c +@@ -24,6 +24,7 @@ + #include "xfs_pnfs.h" + #include "xfs_iomap.h" + #include "xfs_reflink.h" ++#include "xfs_file.h" + + #include + #include +diff --git a/fs/xfs/xfs_file.h b/fs/xfs/xfs_file.h +new file mode 100644 +index 000000000000..7d39e3eca56d +--- /dev/null ++++ b/fs/xfs/xfs_file.h +@@ -0,0 +1,12 @@ ++// SPDX-License-Identifier: GPL-2.0 ++/* ++ * Copyright (c) 2000-2005 Silicon Graphics, Inc. ++ * All Rights Reserved. ++ */ ++#ifndef __XFS_FILE_H__ ++#define __XFS_FILE_H__ ++ ++extern const struct file_operations xfs_file_operations; ++extern const struct file_operations xfs_dir_file_operations; ++ ++#endif /* __XFS_FILE_H__ */ +diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c +index 535f6d38cdb5..df4bf0d56aad 100644 +--- a/fs/xfs/xfs_ioctl.c ++++ b/fs/xfs/xfs_ioctl.c +@@ -38,6 +38,7 @@ + #include "xfs_reflink.h" + #include "xfs_ioctl.h" + #include "xfs_xattr.h" ++#include "xfs_file.h" + + #include + #include +diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c +index b8ec045708c3..f9466311dfea 100644 +--- a/fs/xfs/xfs_iops.c ++++ b/fs/xfs/xfs_iops.c +@@ -25,6 +25,7 @@ + #include "xfs_error.h" + #include "xfs_ioctl.h" + #include "xfs_xattr.h" ++#include "xfs_file.h" + + #include + #include +diff --git a/fs/xfs/xfs_iops.h b/fs/xfs/xfs_iops.h +index 7f84a0843b24..52d6d510a21d 100644 +--- a/fs/xfs/xfs_iops.h ++++ b/fs/xfs/xfs_iops.h +@@ -8,9 +8,6 @@ + + struct xfs_inode; + +-extern const struct file_operations xfs_file_operations; +-extern const struct file_operations xfs_dir_file_operations; +- + extern ssize_t xfs_vn_listxattr(struct dentry *, char *data, size_t size); + + int xfs_vn_setattr_size(struct mnt_idmap *idmap, +-- +2.39.5 + diff --git a/queue-6.6/xfs-don-t-walk-off-the-end-of-a-directory-data-block.patch b/queue-6.6/xfs-don-t-walk-off-the-end-of-a-directory-data-block.patch new file mode 100644 index 00000000000..9aa6fd4d0b7 --- /dev/null +++ b/queue-6.6/xfs-don-t-walk-off-the-end-of-a-directory-data-block.patch @@ -0,0 +1,131 @@ +From 71907816c7f02d09d3eaad2bbcaa09c43a804791 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 18 Dec 2024 11:17:16 -0800 +Subject: xfs: don't walk off the end of a directory data block + +From: lei lu + +commit 0c7fcdb6d06cdf8b19b57c17605215b06afa864a upstream. + +This adds sanity checks for xfs_dir2_data_unused and xfs_dir2_data_entry +to make sure don't stray beyond valid memory region. Before patching, the +loop simply checks that the start offset of the dup and dep is within the +range. So in a crafted image, if last entry is xfs_dir2_data_unused, we +can change dup->length to dup->length-1 and leave 1 byte of space. In the +next traversal, this space will be considered as dup or dep. We may +encounter an out of bound read when accessing the fixed members. + +In the patch, we make sure that the remaining bytes large enough to hold +an unused entry before accessing xfs_dir2_data_unused and +xfs_dir2_data_unused is XFS_DIR2_DATA_ALIGN byte aligned. We also make +sure that the remaining bytes large enough to hold a dirent with a +single-byte name before accessing xfs_dir2_data_entry. + +Signed-off-by: lei lu +Reviewed-by: Darrick J. Wong +Signed-off-by: Chandan Babu R +Signed-off-by: Catherine Hoang +Acked-by: Darrick J. Wong +Signed-off-by: Sasha Levin +--- + fs/xfs/libxfs/xfs_dir2_data.c | 31 ++++++++++++++++++++++++++----- + fs/xfs/libxfs/xfs_dir2_priv.h | 7 +++++++ + 2 files changed, 33 insertions(+), 5 deletions(-) + +diff --git a/fs/xfs/libxfs/xfs_dir2_data.c b/fs/xfs/libxfs/xfs_dir2_data.c +index dbcf58979a59..e1d5da6d8d4a 100644 +--- a/fs/xfs/libxfs/xfs_dir2_data.c ++++ b/fs/xfs/libxfs/xfs_dir2_data.c +@@ -177,6 +177,14 @@ __xfs_dir3_data_check( + while (offset < end) { + struct xfs_dir2_data_unused *dup = bp->b_addr + offset; + struct xfs_dir2_data_entry *dep = bp->b_addr + offset; ++ unsigned int reclen; ++ ++ /* ++ * Are the remaining bytes large enough to hold an ++ * unused entry? ++ */ ++ if (offset > end - xfs_dir2_data_unusedsize(1)) ++ return __this_address; + + /* + * If it's unused, look for the space in the bestfree table. +@@ -186,9 +194,13 @@ __xfs_dir3_data_check( + if (be16_to_cpu(dup->freetag) == XFS_DIR2_DATA_FREE_TAG) { + xfs_failaddr_t fa; + ++ reclen = xfs_dir2_data_unusedsize( ++ be16_to_cpu(dup->length)); + if (lastfree != 0) + return __this_address; +- if (offset + be16_to_cpu(dup->length) > end) ++ if (be16_to_cpu(dup->length) != reclen) ++ return __this_address; ++ if (offset + reclen > end) + return __this_address; + if (be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup)) != + offset) +@@ -206,10 +218,18 @@ __xfs_dir3_data_check( + be16_to_cpu(bf[2].length)) + return __this_address; + } +- offset += be16_to_cpu(dup->length); ++ offset += reclen; + lastfree = 1; + continue; + } ++ ++ /* ++ * This is not an unused entry. Are the remaining bytes ++ * large enough for a dirent with a single-byte name? ++ */ ++ if (offset > end - xfs_dir2_data_entsize(mp, 1)) ++ return __this_address; ++ + /* + * It's a real entry. Validate the fields. + * If this is a block directory then make sure it's +@@ -218,9 +238,10 @@ __xfs_dir3_data_check( + */ + if (dep->namelen == 0) + return __this_address; +- if (!xfs_verify_dir_ino(mp, be64_to_cpu(dep->inumber))) ++ reclen = xfs_dir2_data_entsize(mp, dep->namelen); ++ if (offset + reclen > end) + return __this_address; +- if (offset + xfs_dir2_data_entsize(mp, dep->namelen) > end) ++ if (!xfs_verify_dir_ino(mp, be64_to_cpu(dep->inumber))) + return __this_address; + if (be16_to_cpu(*xfs_dir2_data_entry_tag_p(mp, dep)) != offset) + return __this_address; +@@ -244,7 +265,7 @@ __xfs_dir3_data_check( + if (i >= be32_to_cpu(btp->count)) + return __this_address; + } +- offset += xfs_dir2_data_entsize(mp, dep->namelen); ++ offset += reclen; + } + /* + * Need to have seen all the entries and all the bestfree slots. +diff --git a/fs/xfs/libxfs/xfs_dir2_priv.h b/fs/xfs/libxfs/xfs_dir2_priv.h +index 7404a9ff1a92..9046d08554e9 100644 +--- a/fs/xfs/libxfs/xfs_dir2_priv.h ++++ b/fs/xfs/libxfs/xfs_dir2_priv.h +@@ -187,6 +187,13 @@ void xfs_dir2_sf_put_ftype(struct xfs_mount *mp, + extern int xfs_readdir(struct xfs_trans *tp, struct xfs_inode *dp, + struct dir_context *ctx, size_t bufsize); + ++static inline unsigned int ++xfs_dir2_data_unusedsize( ++ unsigned int len) ++{ ++ return round_up(len, XFS_DIR2_DATA_ALIGN); ++} ++ + static inline unsigned int + xfs_dir2_data_entsize( + struct xfs_mount *mp, +-- +2.39.5 + diff --git a/queue-6.6/xfs-fix-file_path-handling-in-tracepoints.patch b/queue-6.6/xfs-fix-file_path-handling-in-tracepoints.patch new file mode 100644 index 00000000000..c7ad32b326e --- /dev/null +++ b/queue-6.6/xfs-fix-file_path-handling-in-tracepoints.patch @@ -0,0 +1,59 @@ +From 2d00be0d48066770722b8232f1b07472a53c482c Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 18 Dec 2024 11:17:18 -0800 +Subject: xfs: fix file_path handling in tracepoints + +From: Darrick J. Wong + +commit 19ebc8f84ea12e18dd6c8d3ecaf87bcf4666eee1 upstream. + +[backport: only apply fix for 3934e8ebb7cc6] + +Since file_path() takes the output buffer as one of its arguments, we +might as well have it format directly into the tracepoint's char array +instead of wasting stack space. + +Fixes: 3934e8ebb7cc6 ("xfs: create a big array data structure") +Fixes: 5076a6040ca16 ("xfs: support in-memory buffer cache targets") +Reported-by: kernel test robot +Closes: https://lore.kernel.org/oe-kbuild-all/202403290419.HPcyvqZu-lkp@intel.com/ +Signed-off-by: Darrick J. Wong +Reviewed-by: Christoph Hellwig +Signed-off-by: Chandan Babu R +Signed-off-by: Catherine Hoang +Acked-by: Darrick J. Wong +Signed-off-by: Sasha Levin +--- + fs/xfs/scrub/trace.h | 10 ++++------ + 1 file changed, 4 insertions(+), 6 deletions(-) + +diff --git a/fs/xfs/scrub/trace.h b/fs/xfs/scrub/trace.h +index 6d86f4d56353..b1e6879a0731 100644 +--- a/fs/xfs/scrub/trace.h ++++ b/fs/xfs/scrub/trace.h +@@ -784,18 +784,16 @@ TRACE_EVENT(xfile_create, + TP_STRUCT__entry( + __field(dev_t, dev) + __field(unsigned long, ino) +- __array(char, pathname, 256) ++ __array(char, pathname, MAXNAMELEN) + ), + TP_fast_assign( +- char pathname[257]; + char *path; + + __entry->ino = file_inode(xf->file)->i_ino; +- memset(pathname, 0, sizeof(pathname)); +- path = file_path(xf->file, pathname, sizeof(pathname) - 1); ++ path = file_path(xf->file, __entry->pathname, MAXNAMELEN); + if (IS_ERR(path)) +- path = "(unknown)"; +- strncpy(__entry->pathname, path, sizeof(__entry->pathname)); ++ strncpy(__entry->pathname, "(unknown)", ++ sizeof(__entry->pathname)); + ), + TP_printk("xfino 0x%lx path '%s'", + __entry->ino, +-- +2.39.5 + diff --git a/queue-6.6/xfs-fix-the-contact-address-for-the-sysfs-abi-docume.patch b/queue-6.6/xfs-fix-the-contact-address-for-the-sysfs-abi-docume.patch new file mode 100644 index 00000000000..61dc233ee01 --- /dev/null +++ b/queue-6.6/xfs-fix-the-contact-address-for-the-sysfs-abi-docume.patch @@ -0,0 +1,64 @@ +From 46e9bc193407c11626472e691edd4d351ea20add Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 18 Dec 2024 11:17:09 -0800 +Subject: xfs: fix the contact address for the sysfs ABI documentation + +From: Christoph Hellwig + +commit 9ff4490e2ab364ec433f15668ef3f5edfb53feca upstream. + +oss.sgi.com is long dead, refer to the current linux-xfs list instead. + +Signed-off-by: Christoph Hellwig +Reviewed-by: Darrick J. Wong +Signed-off-by: Chandan Babu R +Signed-off-by: Catherine Hoang +Acked-by: Darrick J. Wong +Signed-off-by: Sasha Levin +--- + Documentation/ABI/testing/sysfs-fs-xfs | 8 ++++---- + 1 file changed, 4 insertions(+), 4 deletions(-) + +diff --git a/Documentation/ABI/testing/sysfs-fs-xfs b/Documentation/ABI/testing/sysfs-fs-xfs +index f704925f6fe9..82d8e2f79834 100644 +--- a/Documentation/ABI/testing/sysfs-fs-xfs ++++ b/Documentation/ABI/testing/sysfs-fs-xfs +@@ -1,7 +1,7 @@ + What: /sys/fs/xfs//log/log_head_lsn + Date: July 2014 + KernelVersion: 3.17 +-Contact: xfs@oss.sgi.com ++Contact: linux-xfs@vger.kernel.org + Description: + The log sequence number (LSN) of the current head of the + log. The LSN is exported in "cycle:basic block" format. +@@ -10,7 +10,7 @@ Users: xfstests + What: /sys/fs/xfs//log/log_tail_lsn + Date: July 2014 + KernelVersion: 3.17 +-Contact: xfs@oss.sgi.com ++Contact: linux-xfs@vger.kernel.org + Description: + The log sequence number (LSN) of the current tail of the + log. The LSN is exported in "cycle:basic block" format. +@@ -18,7 +18,7 @@ Description: + What: /sys/fs/xfs//log/reserve_grant_head + Date: July 2014 + KernelVersion: 3.17 +-Contact: xfs@oss.sgi.com ++Contact: linux-xfs@vger.kernel.org + Description: + The current state of the log reserve grant head. It + represents the total log reservation of all currently +@@ -29,7 +29,7 @@ Users: xfstests + What: /sys/fs/xfs//log/write_grant_head + Date: July 2014 + KernelVersion: 3.17 +-Contact: xfs@oss.sgi.com ++Contact: linux-xfs@vger.kernel.org + Description: + The current state of the log write grant head. It + represents the total log reservation of all currently +-- +2.39.5 + diff --git a/queue-6.6/xfs-fix-the-owner-setting-issue-for-rmap-query-in-xf.patch b/queue-6.6/xfs-fix-the-owner-setting-issue-for-rmap-query-in-xf.patch new file mode 100644 index 00000000000..b31857860c5 --- /dev/null +++ b/queue-6.6/xfs-fix-the-owner-setting-issue-for-rmap-query-in-xf.patch @@ -0,0 +1,86 @@ +From a528c8c4f587c396cfff6678f90dbf8efbbbbca1 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 18 Dec 2024 11:17:22 -0800 +Subject: xfs: Fix the owner setting issue for rmap query in xfs fsmap + +From: Zizhi Wo + +commit 68415b349f3f16904f006275757f4fcb34b8ee43 upstream. + +I notice a rmap query bug in xfs_io fsmap: +[root@fedora ~]# xfs_io -c 'fsmap -vvvv' /mnt + EXT: DEV BLOCK-RANGE OWNER FILE-OFFSET AG AG-OFFSET TOTAL + 0: 253:16 [0..7]: static fs metadata 0 (0..7) 8 + 1: 253:16 [8..23]: per-AG metadata 0 (8..23) 16 + 2: 253:16 [24..39]: inode btree 0 (24..39) 16 + 3: 253:16 [40..47]: per-AG metadata 0 (40..47) 8 + 4: 253:16 [48..55]: refcount btree 0 (48..55) 8 + 5: 253:16 [56..103]: per-AG metadata 0 (56..103) 48 + 6: 253:16 [104..127]: free space 0 (104..127) 24 + ...... + +Bug: +[root@fedora ~]# xfs_io -c 'fsmap -vvvv -d 0 3' /mnt +[root@fedora ~]# +Normally, we should be able to get one record, but we got nothing. + +The root cause of this problem lies in the incorrect setting of rm_owner in +the rmap query. In the case of the initial query where the owner is not +set, __xfs_getfsmap_datadev() first sets info->high.rm_owner to ULLONG_MAX. +This is done to prevent any omissions when comparing rmap items. However, +if the current ag is detected to be the last one, the function sets info's +high_irec based on the provided key. If high->rm_owner is not specified, it +should continue to be set to ULLONG_MAX; otherwise, there will be issues +with interval omissions. For example, consider "start" and "end" within the +same block. If high->rm_owner == 0, it will be smaller than the founded +record in rmapbt, resulting in a query with no records. The main call stack +is as follows: + +xfs_ioc_getfsmap + xfs_getfsmap + xfs_getfsmap_datadev_rmapbt + __xfs_getfsmap_datadev + info->high.rm_owner = ULLONG_MAX + if (pag->pag_agno == end_ag) + xfs_fsmap_owner_to_rmap + // set info->high.rm_owner = 0 because fmr_owner == -1ULL + dest->rm_owner = 0 + // get nothing + xfs_getfsmap_datadev_rmapbt_query + +The problem can be resolved by simply modify the xfs_fsmap_owner_to_rmap +function internal logic to achieve. + +After applying this patch, the above problem have been solved: +[root@fedora ~]# xfs_io -c 'fsmap -vvvv -d 0 3' /mnt + EXT: DEV BLOCK-RANGE OWNER FILE-OFFSET AG AG-OFFSET TOTAL + 0: 253:16 [0..7]: static fs metadata 0 (0..7) 8 + +Fixes: e89c041338ed ("xfs: implement the GETFSMAP ioctl") +Signed-off-by: Zizhi Wo +Reviewed-by: Darrick J. Wong +Signed-off-by: Darrick J. Wong +Signed-off-by: Chandan Babu R +Signed-off-by: Catherine Hoang +Acked-by: Darrick J. Wong +Signed-off-by: Sasha Levin +--- + fs/xfs/xfs_fsmap.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c +index 8982c5d6cbd0..85953dbd4283 100644 +--- a/fs/xfs/xfs_fsmap.c ++++ b/fs/xfs/xfs_fsmap.c +@@ -71,7 +71,7 @@ xfs_fsmap_owner_to_rmap( + switch (src->fmr_owner) { + case 0: /* "lowest owner id possible" */ + case -1ULL: /* "highest owner id possible" */ +- dest->rm_owner = 0; ++ dest->rm_owner = src->fmr_owner; + break; + case XFS_FMR_OWN_FREE: + dest->rm_owner = XFS_RMAP_OWN_NULL; +-- +2.39.5 + diff --git a/queue-6.6/xfs-fix-xfs_flush_unmap_range-range-for-rt.patch b/queue-6.6/xfs-fix-xfs_flush_unmap_range-range-for-rt.patch new file mode 100644 index 00000000000..05bc721e4b2 --- /dev/null +++ b/queue-6.6/xfs-fix-xfs_flush_unmap_range-range-for-rt.patch @@ -0,0 +1,55 @@ +From 007c81c43a0efe8ca7bda064cee4a565602b6e65 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 18 Dec 2024 11:17:14 -0800 +Subject: xfs: Fix xfs_flush_unmap_range() range for RT + +From: John Garry + +commit d3b689d7c711a9f36d3e48db9eaa75784a892f4c upstream. + +Currently xfs_flush_unmap_range() does unmap for a full RT extent range, +which we also want to ensure is clean and idle. + +This code change is originally from Dave Chinner. + +Reviewed-by: Christoph Hellwig 4 +Reviewed-by: Darrick J. Wong +Signed-off-by: John Garry +Signed-off-by: Chandan Babu R +Signed-off-by: Catherine Hoang +Acked-by: Darrick J. Wong +Signed-off-by: Sasha Levin +--- + fs/xfs/xfs_bmap_util.c | 12 ++++++++---- + 1 file changed, 8 insertions(+), 4 deletions(-) + +diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c +index f9d72d8e3c35..7336402f1efa 100644 +--- a/fs/xfs/xfs_bmap_util.c ++++ b/fs/xfs/xfs_bmap_util.c +@@ -963,14 +963,18 @@ xfs_flush_unmap_range( + xfs_off_t offset, + xfs_off_t len) + { +- struct xfs_mount *mp = ip->i_mount; + struct inode *inode = VFS_I(ip); + xfs_off_t rounding, start, end; + int error; + +- rounding = max_t(xfs_off_t, mp->m_sb.sb_blocksize, PAGE_SIZE); +- start = round_down(offset, rounding); +- end = round_up(offset + len, rounding) - 1; ++ /* ++ * Make sure we extend the flush out to extent alignment ++ * boundaries so any extent range overlapping the start/end ++ * of the modification we are about to do is clean and idle. ++ */ ++ rounding = max_t(xfs_off_t, xfs_inode_alloc_unitsize(ip), PAGE_SIZE); ++ start = rounddown_64(offset, rounding); ++ end = roundup_64(offset + len, rounding) - 1; + + error = filemap_write_and_wait_range(inode->i_mapping, start, end); + if (error) +-- +2.39.5 + diff --git a/queue-6.6/xfs-fix-xfs_prepare_shift-range-for-rt.patch b/queue-6.6/xfs-fix-xfs_prepare_shift-range-for-rt.patch new file mode 100644 index 00000000000..379e5d7ec88 --- /dev/null +++ b/queue-6.6/xfs-fix-xfs_prepare_shift-range-for-rt.patch @@ -0,0 +1,58 @@ +From 3bdfbdf5d1a9f504413093fb8bfbadaf8db472f7 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 18 Dec 2024 11:17:15 -0800 +Subject: xfs: Fix xfs_prepare_shift() range for RT + +From: John Garry + +commit f23660f059470ec7043748da7641e84183c23bc8 upstream. + +The RT extent range must be considered in the xfs_flush_unmap_range() call +to stabilize the boundary. + +This code change is originally from Dave Chinner. + +Reviewed-by: Christoph Hellwig +Reviewed-by: Darrick J. Wong +Signed-off-by: John Garry +Signed-off-by: Chandan Babu R +Signed-off-by: Catherine Hoang +Acked-by: Darrick J. Wong +Signed-off-by: Sasha Levin +--- + fs/xfs/xfs_bmap_util.c | 10 ++++++---- + 1 file changed, 6 insertions(+), 4 deletions(-) + +diff --git a/fs/xfs/xfs_bmap_util.c b/fs/xfs/xfs_bmap_util.c +index 7336402f1efa..1fa10a83da0b 100644 +--- a/fs/xfs/xfs_bmap_util.c ++++ b/fs/xfs/xfs_bmap_util.c +@@ -1059,7 +1059,7 @@ xfs_prepare_shift( + struct xfs_inode *ip, + loff_t offset) + { +- struct xfs_mount *mp = ip->i_mount; ++ unsigned int rounding; + int error; + + /* +@@ -1077,11 +1077,13 @@ xfs_prepare_shift( + * with the full range of the operation. If we don't, a COW writeback + * completion could race with an insert, front merge with the start + * extent (after split) during the shift and corrupt the file. Start +- * with the block just prior to the start to stabilize the boundary. ++ * with the allocation unit just prior to the start to stabilize the ++ * boundary. + */ +- offset = round_down(offset, mp->m_sb.sb_blocksize); ++ rounding = xfs_inode_alloc_unitsize(ip); ++ offset = rounddown_64(offset, rounding); + if (offset) +- offset -= mp->m_sb.sb_blocksize; ++ offset -= rounding; + + /* + * Writeback and invalidate cache for the remainder of the file as we're +-- +2.39.5 + diff --git a/queue-6.6/xfs-remove-unused-parameter-in-macro-xfs_dquot_logre.patch b/queue-6.6/xfs-remove-unused-parameter-in-macro-xfs_dquot_logre.patch new file mode 100644 index 00000000000..192e71c490e --- /dev/null +++ b/queue-6.6/xfs-remove-unused-parameter-in-macro-xfs_dquot_logre.patch @@ -0,0 +1,163 @@ +From 9deae30c094f9825a3c039c075c0928653b1c5b1 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 18 Dec 2024 11:17:19 -0800 +Subject: xfs: remove unused parameter in macro XFS_DQUOT_LOGRES + +From: Julian Sun + +commit af5d92f2fad818663da2ce073b6fe15b9d56ffdc upstream. + +In the macro definition of XFS_DQUOT_LOGRES, a parameter is accepted, +but it is not used. Hence, it should be removed. + +This patch has only passed compilation test, but it should be fine. + +Signed-off-by: Julian Sun +Reviewed-by: Darrick J. Wong +Signed-off-by: Chandan Babu R +Signed-off-by: Catherine Hoang +Acked-by: Darrick J. Wong +Signed-off-by: Sasha Levin +--- + fs/xfs/libxfs/xfs_quota_defs.h | 2 +- + fs/xfs/libxfs/xfs_trans_resv.c | 28 ++++++++++++++-------------- + 2 files changed, 15 insertions(+), 15 deletions(-) + +diff --git a/fs/xfs/libxfs/xfs_quota_defs.h b/fs/xfs/libxfs/xfs_quota_defs.h +index cb035da3f990..fb05f44f6c75 100644 +--- a/fs/xfs/libxfs/xfs_quota_defs.h ++++ b/fs/xfs/libxfs/xfs_quota_defs.h +@@ -56,7 +56,7 @@ typedef uint8_t xfs_dqtype_t; + * And, of course, we also need to take into account the dquot log format item + * used to describe each dquot. + */ +-#define XFS_DQUOT_LOGRES(mp) \ ++#define XFS_DQUOT_LOGRES \ + ((sizeof(struct xfs_dq_logformat) + sizeof(struct xfs_disk_dquot)) * 6) + + #define XFS_IS_QUOTA_ON(mp) ((mp)->m_qflags & XFS_ALL_QUOTA_ACCT) +diff --git a/fs/xfs/libxfs/xfs_trans_resv.c b/fs/xfs/libxfs/xfs_trans_resv.c +index 5b2f27cbdb80..1bb2891b26ff 100644 +--- a/fs/xfs/libxfs/xfs_trans_resv.c ++++ b/fs/xfs/libxfs/xfs_trans_resv.c +@@ -334,11 +334,11 @@ xfs_calc_write_reservation( + blksz); + t1 += adj; + t3 += adj; +- return XFS_DQUOT_LOGRES(mp) + max3(t1, t2, t3); ++ return XFS_DQUOT_LOGRES + max3(t1, t2, t3); + } + + t4 = xfs_calc_refcountbt_reservation(mp, 1); +- return XFS_DQUOT_LOGRES(mp) + max(t4, max3(t1, t2, t3)); ++ return XFS_DQUOT_LOGRES + max(t4, max3(t1, t2, t3)); + } + + unsigned int +@@ -406,11 +406,11 @@ xfs_calc_itruncate_reservation( + xfs_refcountbt_block_count(mp, 4), + blksz); + +- return XFS_DQUOT_LOGRES(mp) + max3(t1, t2, t3); ++ return XFS_DQUOT_LOGRES + max3(t1, t2, t3); + } + + t4 = xfs_calc_refcountbt_reservation(mp, 2); +- return XFS_DQUOT_LOGRES(mp) + max(t4, max3(t1, t2, t3)); ++ return XFS_DQUOT_LOGRES + max(t4, max3(t1, t2, t3)); + } + + unsigned int +@@ -436,7 +436,7 @@ STATIC uint + xfs_calc_rename_reservation( + struct xfs_mount *mp) + { +- return XFS_DQUOT_LOGRES(mp) + ++ return XFS_DQUOT_LOGRES + + max((xfs_calc_inode_res(mp, 5) + + xfs_calc_buf_res(2 * XFS_DIROP_LOG_COUNT(mp), + XFS_FSB_TO_B(mp, 1))), +@@ -475,7 +475,7 @@ STATIC uint + xfs_calc_link_reservation( + struct xfs_mount *mp) + { +- return XFS_DQUOT_LOGRES(mp) + ++ return XFS_DQUOT_LOGRES + + xfs_calc_iunlink_remove_reservation(mp) + + max((xfs_calc_inode_res(mp, 2) + + xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), +@@ -513,7 +513,7 @@ STATIC uint + xfs_calc_remove_reservation( + struct xfs_mount *mp) + { +- return XFS_DQUOT_LOGRES(mp) + ++ return XFS_DQUOT_LOGRES + + xfs_calc_iunlink_add_reservation(mp) + + max((xfs_calc_inode_res(mp, 2) + + xfs_calc_buf_res(XFS_DIROP_LOG_COUNT(mp), +@@ -572,7 +572,7 @@ xfs_calc_icreate_resv_alloc( + STATIC uint + xfs_calc_icreate_reservation(xfs_mount_t *mp) + { +- return XFS_DQUOT_LOGRES(mp) + ++ return XFS_DQUOT_LOGRES + + max(xfs_calc_icreate_resv_alloc(mp), + xfs_calc_create_resv_modify(mp)); + } +@@ -581,7 +581,7 @@ STATIC uint + xfs_calc_create_tmpfile_reservation( + struct xfs_mount *mp) + { +- uint res = XFS_DQUOT_LOGRES(mp); ++ uint res = XFS_DQUOT_LOGRES; + + res += xfs_calc_icreate_resv_alloc(mp); + return res + xfs_calc_iunlink_add_reservation(mp); +@@ -630,7 +630,7 @@ STATIC uint + xfs_calc_ifree_reservation( + struct xfs_mount *mp) + { +- return XFS_DQUOT_LOGRES(mp) + ++ return XFS_DQUOT_LOGRES + + xfs_calc_inode_res(mp, 1) + + xfs_calc_buf_res(3, mp->m_sb.sb_sectsize) + + xfs_calc_iunlink_remove_reservation(mp) + +@@ -647,7 +647,7 @@ STATIC uint + xfs_calc_ichange_reservation( + struct xfs_mount *mp) + { +- return XFS_DQUOT_LOGRES(mp) + ++ return XFS_DQUOT_LOGRES + + xfs_calc_inode_res(mp, 1) + + xfs_calc_buf_res(1, mp->m_sb.sb_sectsize); + +@@ -756,7 +756,7 @@ STATIC uint + xfs_calc_addafork_reservation( + struct xfs_mount *mp) + { +- return XFS_DQUOT_LOGRES(mp) + ++ return XFS_DQUOT_LOGRES + + xfs_calc_inode_res(mp, 1) + + xfs_calc_buf_res(2, mp->m_sb.sb_sectsize) + + xfs_calc_buf_res(1, mp->m_dir_geo->blksize) + +@@ -804,7 +804,7 @@ STATIC uint + xfs_calc_attrsetm_reservation( + struct xfs_mount *mp) + { +- return XFS_DQUOT_LOGRES(mp) + ++ return XFS_DQUOT_LOGRES + + xfs_calc_inode_res(mp, 1) + + xfs_calc_buf_res(1, mp->m_sb.sb_sectsize) + + xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH, XFS_FSB_TO_B(mp, 1)); +@@ -844,7 +844,7 @@ STATIC uint + xfs_calc_attrrm_reservation( + struct xfs_mount *mp) + { +- return XFS_DQUOT_LOGRES(mp) + ++ return XFS_DQUOT_LOGRES + + max((xfs_calc_inode_res(mp, 1) + + xfs_calc_buf_res(XFS_DA_NODE_MAXDEPTH, + XFS_FSB_TO_B(mp, 1)) + +-- +2.39.5 + diff --git a/queue-6.6/xfs-reset-rootdir-extent-size-hint-after-growfsrt.patch b/queue-6.6/xfs-reset-rootdir-extent-size-hint-after-growfsrt.patch new file mode 100644 index 00000000000..4bcdd330584 --- /dev/null +++ b/queue-6.6/xfs-reset-rootdir-extent-size-hint-after-growfsrt.patch @@ -0,0 +1,95 @@ +From ef5cc24203d66661303c0dbd7315c2667d52886b Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 18 Dec 2024 11:17:25 -0800 +Subject: xfs: reset rootdir extent size hint after growfsrt + +From: Darrick J. Wong + +commit a24cae8fc1f13f6f6929351309f248fd2e9351ce upstream. + +If growfsrt is run on a filesystem that doesn't have a rt volume, it's +possible to change the rt extent size. If the root directory was +previously set up with an inherited extent size hint and rtinherit, it's +possible that the hint is no longer a multiple of the rt extent size. +Although the verifiers don't complain about this, xfs_repair will, so if +we detect this situation, log the root directory to clean it up. This +is still racy, but it's better than nothing. + +Reviewed-by: Christoph Hellwig +Signed-off-by: Darrick J. Wong +Signed-off-by: Chandan Babu R +Signed-off-by: Catherine Hoang +Acked-by: Darrick J. Wong +Signed-off-by: Sasha Levin +--- + fs/xfs/xfs_rtalloc.c | 40 ++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 40 insertions(+) + +diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c +index 9268961d887c..ad828fbd5ce4 100644 +--- a/fs/xfs/xfs_rtalloc.c ++++ b/fs/xfs/xfs_rtalloc.c +@@ -915,6 +915,39 @@ xfs_alloc_rsum_cache( + xfs_warn(mp, "could not allocate realtime summary cache"); + } + ++/* ++ * If we changed the rt extent size (meaning there was no rt volume previously) ++ * and the root directory had EXTSZINHERIT and RTINHERIT set, it's possible ++ * that the extent size hint on the root directory is no longer congruent with ++ * the new rt extent size. Log the rootdir inode to fix this. ++ */ ++static int ++xfs_growfs_rt_fixup_extsize( ++ struct xfs_mount *mp) ++{ ++ struct xfs_inode *ip = mp->m_rootip; ++ struct xfs_trans *tp; ++ int error = 0; ++ ++ xfs_ilock(ip, XFS_IOLOCK_EXCL); ++ if (!(ip->i_diflags & XFS_DIFLAG_RTINHERIT) || ++ !(ip->i_diflags & XFS_DIFLAG_EXTSZINHERIT)) ++ goto out_iolock; ++ ++ error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_ichange, 0, 0, false, ++ &tp); ++ if (error) ++ goto out_iolock; ++ ++ xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); ++ error = xfs_trans_commit(tp); ++ xfs_iunlock(ip, XFS_ILOCK_EXCL); ++ ++out_iolock: ++ xfs_iunlock(ip, XFS_IOLOCK_EXCL); ++ return error; ++} ++ + /* + * Visible (exported) functions. + */ +@@ -944,6 +977,7 @@ xfs_growfs_rt( + xfs_sb_t *sbp; /* old superblock */ + xfs_fsblock_t sumbno; /* summary block number */ + uint8_t *rsum_cache; /* old summary cache */ ++ xfs_agblock_t old_rextsize = mp->m_sb.sb_rextsize; + + sbp = &mp->m_sb; + +@@ -1177,6 +1211,12 @@ xfs_growfs_rt( + if (error) + goto out_free; + ++ if (old_rextsize != in->extsize) { ++ error = xfs_growfs_rt_fixup_extsize(mp); ++ if (error) ++ goto out_free; ++ } ++ + /* Update secondary superblocks now the physical grow has completed */ + error = xfs_update_secondary_sbs(mp); + +-- +2.39.5 + diff --git a/queue-6.6/xfs-take-m_growlock-when-running-growfsrt.patch b/queue-6.6/xfs-take-m_growlock-when-running-growfsrt.patch new file mode 100644 index 00000000000..7bf174dd42d --- /dev/null +++ b/queue-6.6/xfs-take-m_growlock-when-running-growfsrt.patch @@ -0,0 +1,133 @@ +From ea904fc4abcaed18ed8e942f8269d012cf3a148d Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 18 Dec 2024 11:17:24 -0800 +Subject: xfs: take m_growlock when running growfsrt + +From: Darrick J. Wong + +commit 16e1fbdce9c8d084863fd63cdaff8fb2a54e2f88 upstream. + +Take the grow lock when we're expanding the realtime volume, like we do +for the other growfs calls. + +Reviewed-by: Christoph Hellwig +Signed-off-by: Darrick J. Wong +Signed-off-by: Chandan Babu R +Signed-off-by: Catherine Hoang +Acked-by: Darrick J. Wong +Signed-off-by: Sasha Levin +--- + fs/xfs/xfs_rtalloc.c | 38 +++++++++++++++++++++++++------------- + 1 file changed, 25 insertions(+), 13 deletions(-) + +diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c +index 608db1ab88a4..9268961d887c 100644 +--- a/fs/xfs/xfs_rtalloc.c ++++ b/fs/xfs/xfs_rtalloc.c +@@ -953,34 +953,39 @@ xfs_growfs_rt( + /* Needs to have been mounted with an rt device. */ + if (!XFS_IS_REALTIME_MOUNT(mp)) + return -EINVAL; ++ ++ if (!mutex_trylock(&mp->m_growlock)) ++ return -EWOULDBLOCK; + /* + * Mount should fail if the rt bitmap/summary files don't load, but + * we'll check anyway. + */ ++ error = -EINVAL; + if (!mp->m_rbmip || !mp->m_rsumip) +- return -EINVAL; ++ goto out_unlock; + + /* Shrink not supported. */ + if (in->newblocks <= sbp->sb_rblocks) +- return -EINVAL; ++ goto out_unlock; + + /* Can only change rt extent size when adding rt volume. */ + if (sbp->sb_rblocks > 0 && in->extsize != sbp->sb_rextsize) +- return -EINVAL; ++ goto out_unlock; + + /* Range check the extent size. */ + if (XFS_FSB_TO_B(mp, in->extsize) > XFS_MAX_RTEXTSIZE || + XFS_FSB_TO_B(mp, in->extsize) < XFS_MIN_RTEXTSIZE) +- return -EINVAL; ++ goto out_unlock; + + /* Unsupported realtime features. */ ++ error = -EOPNOTSUPP; + if (xfs_has_rmapbt(mp) || xfs_has_reflink(mp) || xfs_has_quota(mp)) +- return -EOPNOTSUPP; ++ goto out_unlock; + + nrblocks = in->newblocks; + error = xfs_sb_validate_fsb_count(sbp, nrblocks); + if (error) +- return error; ++ goto out_unlock; + /* + * Read in the last block of the device, make sure it exists. + */ +@@ -988,7 +993,7 @@ xfs_growfs_rt( + XFS_FSB_TO_BB(mp, nrblocks - 1), + XFS_FSB_TO_BB(mp, 1), 0, &bp, NULL); + if (error) +- return error; ++ goto out_unlock; + xfs_buf_relse(bp); + + /* +@@ -996,8 +1001,10 @@ xfs_growfs_rt( + */ + nrextents = nrblocks; + do_div(nrextents, in->extsize); +- if (!xfs_validate_rtextents(nrextents)) +- return -EINVAL; ++ if (!xfs_validate_rtextents(nrextents)) { ++ error = -EINVAL; ++ goto out_unlock; ++ } + nrbmblocks = howmany_64(nrextents, NBBY * sbp->sb_blocksize); + nrextslog = xfs_compute_rextslog(nrextents); + nrsumlevels = nrextslog + 1; +@@ -1009,8 +1016,11 @@ xfs_growfs_rt( + * the log. This prevents us from getting a log overflow, + * since we'll log basically the whole summary file at once. + */ +- if (nrsumblocks > (mp->m_sb.sb_logblocks >> 1)) +- return -EINVAL; ++ if (nrsumblocks > (mp->m_sb.sb_logblocks >> 1)) { ++ error = -EINVAL; ++ goto out_unlock; ++ } ++ + /* + * Get the old block counts for bitmap and summary inodes. + * These can't change since other growfs callers are locked out. +@@ -1022,10 +1032,10 @@ xfs_growfs_rt( + */ + error = xfs_growfs_rt_alloc(mp, rbmblocks, nrbmblocks, mp->m_rbmip); + if (error) +- return error; ++ goto out_unlock; + error = xfs_growfs_rt_alloc(mp, rsumblocks, nrsumblocks, mp->m_rsumip); + if (error) +- return error; ++ goto out_unlock; + + rsum_cache = mp->m_rsum_cache; + if (nrbmblocks != sbp->sb_rbmblocks) +@@ -1190,6 +1200,8 @@ xfs_growfs_rt( + } + } + ++out_unlock: ++ mutex_unlock(&mp->m_growlock); + return error; + } + +-- +2.39.5 + diff --git a/queue-6.6/xfs-use-consistent-uid-gid-when-grabbing-dquots-for-.patch b/queue-6.6/xfs-use-consistent-uid-gid-when-grabbing-dquots-for-.patch new file mode 100644 index 00000000000..d8cb5f469c7 --- /dev/null +++ b/queue-6.6/xfs-use-consistent-uid-gid-when-grabbing-dquots-for-.patch @@ -0,0 +1,99 @@ +From 581161cea38d19639b81dfb44450d1de90cbe809 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 18 Dec 2024 11:17:11 -0800 +Subject: xfs: use consistent uid/gid when grabbing dquots for inodes + +From: Darrick J. Wong + +commit 24a4e1cb322e2bf0f3a1afd1978b610a23aa8f36 upstream. + +I noticed that callers of xfs_qm_vop_dqalloc use the following code to +compute the anticipated uid of the new file: + + mapped_fsuid(idmap, &init_user_ns); + +whereas the VFS uses a slightly different computation for actually +assigning i_uid: + + mapped_fsuid(idmap, i_user_ns(inode)); + +Technically, these are not the same things. According to Christian +Brauner, the only time that inode->i_sb->s_user_ns != &init_user_ns is +when the filesystem was mounted in a new mount namespace by an +unpriviledged user. XFS does not allow this, which is why we've never +seen bug reports about quotas being incorrect or the uid checks in +xfs_qm_vop_create_dqattach tripping debug assertions. + +However, this /is/ a logic bomb, so let's make the code consistent. + +Link: https://lore.kernel.org/linux-fsdevel/20240617-weitblick-gefertigt-4a41f37119fa@brauner/ +Fixes: c14329d39f2d ("fs: port fs{g,u}id helpers to mnt_idmap") +Signed-off-by: Darrick J. Wong +Reviewed-by: Christoph Hellwig +Signed-off-by: Catherine Hoang +Acked-by: Darrick J. Wong +Signed-off-by: Sasha Levin +--- + fs/xfs/xfs_inode.c | 16 ++++++++++------ + fs/xfs/xfs_symlink.c | 8 +++++--- + 2 files changed, 15 insertions(+), 9 deletions(-) + +diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c +index 7aa73855fab6..1e50cc9a29db 100644 +--- a/fs/xfs/xfs_inode.c ++++ b/fs/xfs/xfs_inode.c +@@ -982,10 +982,12 @@ xfs_create( + prid = xfs_get_initial_prid(dp); + + /* +- * Make sure that we have allocated dquot(s) on disk. ++ * Make sure that we have allocated dquot(s) on disk. The uid/gid ++ * computation code must match what the VFS uses to assign i_[ug]id. ++ * INHERIT adjusts the gid computation for setgid/grpid systems. + */ +- error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, &init_user_ns), +- mapped_fsgid(idmap, &init_user_ns), prid, ++ error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, i_user_ns(VFS_I(dp))), ++ mapped_fsgid(idmap, i_user_ns(VFS_I(dp))), prid, + XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, + &udqp, &gdqp, &pdqp); + if (error) +@@ -1131,10 +1133,12 @@ xfs_create_tmpfile( + prid = xfs_get_initial_prid(dp); + + /* +- * Make sure that we have allocated dquot(s) on disk. ++ * Make sure that we have allocated dquot(s) on disk. The uid/gid ++ * computation code must match what the VFS uses to assign i_[ug]id. ++ * INHERIT adjusts the gid computation for setgid/grpid systems. + */ +- error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, &init_user_ns), +- mapped_fsgid(idmap, &init_user_ns), prid, ++ error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, i_user_ns(VFS_I(dp))), ++ mapped_fsgid(idmap, i_user_ns(VFS_I(dp))), prid, + XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, + &udqp, &gdqp, &pdqp); + if (error) +diff --git a/fs/xfs/xfs_symlink.c b/fs/xfs/xfs_symlink.c +index 85e433df6a3f..b08be64dd10b 100644 +--- a/fs/xfs/xfs_symlink.c ++++ b/fs/xfs/xfs_symlink.c +@@ -191,10 +191,12 @@ xfs_symlink( + prid = xfs_get_initial_prid(dp); + + /* +- * Make sure that we have allocated dquot(s) on disk. ++ * Make sure that we have allocated dquot(s) on disk. The uid/gid ++ * computation code must match what the VFS uses to assign i_[ug]id. ++ * INHERIT adjusts the gid computation for setgid/grpid systems. + */ +- error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, &init_user_ns), +- mapped_fsgid(idmap, &init_user_ns), prid, ++ error = xfs_qm_vop_dqalloc(dp, mapped_fsuid(idmap, i_user_ns(VFS_I(dp))), ++ mapped_fsgid(idmap, i_user_ns(VFS_I(dp))), prid, + XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, + &udqp, &gdqp, &pdqp); + if (error) +-- +2.39.5 + diff --git a/queue-6.6/xfs-use-xfs_buf_daddr_null-for-daddrs-in-getfsmap-co.patch b/queue-6.6/xfs-use-xfs_buf_daddr_null-for-daddrs-in-getfsmap-co.patch new file mode 100644 index 00000000000..6debba68dfd --- /dev/null +++ b/queue-6.6/xfs-use-xfs_buf_daddr_null-for-daddrs-in-getfsmap-co.patch @@ -0,0 +1,49 @@ +From 666b02201ba47e84caef64d2e2396e96846c9c2f Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 18 Dec 2024 11:17:23 -0800 +Subject: xfs: use XFS_BUF_DADDR_NULL for daddrs in getfsmap code + +From: Darrick J. Wong + +commit 6b35cc8d9239569700cc7cc737c8ed40b8b9cfdb upstream. + +Use XFS_BUF_DADDR_NULL (instead of a magic sentinel value) to mean "this +field is null" like the rest of xfs. + +Cc: wozizhi@huawei.com +Fixes: e89c041338ed6 ("xfs: implement the GETFSMAP ioctl") +Reviewed-by: Christoph Hellwig +Signed-off-by: Darrick J. Wong +Signed-off-by: Chandan Babu R +Signed-off-by: Catherine Hoang +Acked-by: Darrick J. Wong +Signed-off-by: Sasha Levin +--- + fs/xfs/xfs_fsmap.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/fs/xfs/xfs_fsmap.c b/fs/xfs/xfs_fsmap.c +index 85953dbd4283..7754d51e1c27 100644 +--- a/fs/xfs/xfs_fsmap.c ++++ b/fs/xfs/xfs_fsmap.c +@@ -252,7 +252,7 @@ xfs_getfsmap_rec_before_start( + const struct xfs_rmap_irec *rec, + xfs_daddr_t rec_daddr) + { +- if (info->low_daddr != -1ULL) ++ if (info->low_daddr != XFS_BUF_DADDR_NULL) + return rec_daddr < info->low_daddr; + if (info->low.rm_blockcount) + return xfs_rmap_compare(rec, &info->low) < 0; +@@ -986,7 +986,7 @@ xfs_getfsmap( + info.dev = handlers[i].dev; + info.last = false; + info.pag = NULL; +- info.low_daddr = -1ULL; ++ info.low_daddr = XFS_BUF_DADDR_NULL; + info.low.rm_blockcount = 0; + error = handlers[i].fn(tp, dkeys, &info); + if (error) +-- +2.39.5 + diff --git a/queue-6.6/xfs-verify-buffer-inode-and-dquot-items-every-tx-com.patch b/queue-6.6/xfs-verify-buffer-inode-and-dquot-items-every-tx-com.patch new file mode 100644 index 00000000000..1e3b89fbd5a --- /dev/null +++ b/queue-6.6/xfs-verify-buffer-inode-and-dquot-items-every-tx-com.patch @@ -0,0 +1,285 @@ +From 2149cc04ec84f7876c98ebfe43ec36ed8bb217c1 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 18 Dec 2024 11:17:10 -0800 +Subject: xfs: verify buffer, inode, and dquot items every tx commit + +From: Darrick J. Wong + +commit 150bb10a28b9c8709ae227fc898d9cf6136faa1e upstream. + +generic/388 has an annoying tendency to fail like this during log +recovery: + +XFS (sda4): Unmounting Filesystem 435fe39b-82b6-46ef-be56-819499585130 +XFS (sda4): Mounting V5 Filesystem 435fe39b-82b6-46ef-be56-819499585130 +XFS (sda4): Starting recovery (logdev: internal) +00000000: 49 4e 81 b6 03 02 00 00 00 00 00 07 00 00 00 07 IN.............. +00000010: 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 10 ................ +00000020: 35 9a 8b c1 3e 6e 81 00 35 9a 8b c1 3f dc b7 00 5...>n..5...?... +00000030: 35 9a 8b c1 3f dc b7 00 00 00 00 00 00 3c 86 4f 5...?........<.O +00000040: 00 00 00 00 00 00 02 f3 00 00 00 00 00 00 00 00 ................ +00000050: 00 00 1f 01 00 00 00 00 00 00 00 02 b2 74 c9 0b .............t.. +00000060: ff ff ff ff d7 45 73 10 00 00 00 00 00 00 00 2d .....Es........- +00000070: 00 00 07 92 00 01 fe 30 00 00 00 00 00 00 00 1a .......0........ +00000080: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ +00000090: 35 9a 8b c1 3b 55 0c 00 00 00 00 00 04 27 b2 d1 5...;U.......'.. +000000a0: 43 5f e3 9b 82 b6 46 ef be 56 81 94 99 58 51 30 C_....F..V...XQ0 +XFS (sda4): Internal error Bad dinode after recovery at line 539 of file fs/xfs/xfs_inode_item_recover.c. Caller xlog_recover_items_pass2+0x4e/0xc0 [xfs] +CPU: 0 PID: 2189311 Comm: mount Not tainted 6.9.0-rc4-djwx #rc4 +Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ?-20171121_152543-x86-ol7-builder-01.us.oracle.com-4.el7.1 04/01/2014 +Call Trace: + + dump_stack_lvl+0x4f/0x60 + xfs_corruption_error+0x90/0xa0 + xlog_recover_inode_commit_pass2+0x5f1/0xb00 + xlog_recover_items_pass2+0x4e/0xc0 + xlog_recover_commit_trans+0x2db/0x350 + xlog_recovery_process_trans+0xab/0xe0 + xlog_recover_process_data+0xa7/0x130 + xlog_do_recovery_pass+0x398/0x840 + xlog_do_log_recovery+0x62/0xc0 + xlog_do_recover+0x34/0x1d0 + xlog_recover+0xe9/0x1a0 + xfs_log_mount+0xff/0x260 + xfs_mountfs+0x5d9/0xb60 + xfs_fs_fill_super+0x76b/0xa30 + get_tree_bdev+0x124/0x1d0 + vfs_get_tree+0x17/0xa0 + path_mount+0x72b/0xa90 + __x64_sys_mount+0x112/0x150 + do_syscall_64+0x49/0x100 + entry_SYSCALL_64_after_hwframe+0x4b/0x53 + +XFS (sda4): Corruption detected. Unmount and run xfs_repair +XFS (sda4): Metadata corruption detected at xfs_dinode_verify.part.0+0x739/0x920 [xfs], inode 0x427b2d1 +XFS (sda4): Filesystem has been shut down due to log error (0x2). +XFS (sda4): Please unmount the filesystem and rectify the problem(s). +XFS (sda4): log mount/recovery failed: error -117 +XFS (sda4): log mount failed + +This inode log item recovery failing the dinode verifier after +replaying the contents of the inode log item into the ondisk inode. +Looking back into what the kernel was doing at the time of the fs +shutdown, a thread was in the middle of running a series of +transactions, each of which committed changes to the inode. + +At some point in the middle of that chain, an invalid (at least +according to the verifier) change was committed. Had the filesystem not +shut down in the middle of the chain, a subsequent transaction would +have corrected the invalid state and nobody would have noticed. But +that's not what happened here. Instead, the invalid inode state was +committed to the ondisk log, so log recovery tripped over it. + +The actual defect here was an overzealous inode verifier, which was +fixed in a separate patch. This patch adds some transaction precommit +functions for CONFIG_XFS_DEBUG=y mode so that we can detect these kinds +of transient errors at transaction commit time, where it's much easier +to find the root cause. + +Signed-off-by: Darrick J. Wong +Reviewed-by: Christoph Hellwig +Signed-off-by: Catherine Hoang +Acked-by: Darrick J. Wong +Signed-off-by: Sasha Levin +--- + fs/xfs/Kconfig | 12 ++++++++++++ + fs/xfs/xfs.h | 4 ++++ + fs/xfs/xfs_buf_item.c | 32 ++++++++++++++++++++++++++++++++ + fs/xfs/xfs_dquot_item.c | 31 +++++++++++++++++++++++++++++++ + fs/xfs/xfs_inode_item.c | 32 ++++++++++++++++++++++++++++++++ + 5 files changed, 111 insertions(+) + +diff --git a/fs/xfs/Kconfig b/fs/xfs/Kconfig +index 567fb37274d3..ced0e6272aef 100644 +--- a/fs/xfs/Kconfig ++++ b/fs/xfs/Kconfig +@@ -204,6 +204,18 @@ config XFS_DEBUG + + Say N unless you are an XFS developer, or you play one on TV. + ++config XFS_DEBUG_EXPENSIVE ++ bool "XFS expensive debugging checks" ++ depends on XFS_FS && XFS_DEBUG ++ help ++ Say Y here to get an XFS build with expensive debugging checks ++ enabled. These checks may affect performance significantly. ++ ++ Note that the resulting code will be HUGER and SLOWER, and probably ++ not useful unless you are debugging a particular problem. ++ ++ Say N unless you are an XFS developer, or you play one on TV. ++ + config XFS_ASSERT_FATAL + bool "XFS fatal asserts" + default y +diff --git a/fs/xfs/xfs.h b/fs/xfs/xfs.h +index f6ffb4f248f7..9355ccad9503 100644 +--- a/fs/xfs/xfs.h ++++ b/fs/xfs/xfs.h +@@ -10,6 +10,10 @@ + #define DEBUG 1 + #endif + ++#ifdef CONFIG_XFS_DEBUG_EXPENSIVE ++#define DEBUG_EXPENSIVE 1 ++#endif ++ + #ifdef CONFIG_XFS_ASSERT_FATAL + #define XFS_ASSERT_FATAL 1 + #endif +diff --git a/fs/xfs/xfs_buf_item.c b/fs/xfs/xfs_buf_item.c +index 023d4e0385dd..b02ce568de0c 100644 +--- a/fs/xfs/xfs_buf_item.c ++++ b/fs/xfs/xfs_buf_item.c +@@ -22,6 +22,7 @@ + #include "xfs_trace.h" + #include "xfs_log.h" + #include "xfs_log_priv.h" ++#include "xfs_error.h" + + + struct kmem_cache *xfs_buf_item_cache; +@@ -781,8 +782,39 @@ xfs_buf_item_committed( + return lsn; + } + ++#ifdef DEBUG_EXPENSIVE ++static int ++xfs_buf_item_precommit( ++ struct xfs_trans *tp, ++ struct xfs_log_item *lip) ++{ ++ struct xfs_buf_log_item *bip = BUF_ITEM(lip); ++ struct xfs_buf *bp = bip->bli_buf; ++ struct xfs_mount *mp = bp->b_mount; ++ xfs_failaddr_t fa; ++ ++ if (!bp->b_ops || !bp->b_ops->verify_struct) ++ return 0; ++ if (bip->bli_flags & XFS_BLI_STALE) ++ return 0; ++ ++ fa = bp->b_ops->verify_struct(bp); ++ if (fa) { ++ xfs_buf_verifier_error(bp, -EFSCORRUPTED, bp->b_ops->name, ++ bp->b_addr, BBTOB(bp->b_length), fa); ++ xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); ++ ASSERT(fa == NULL); ++ } ++ ++ return 0; ++} ++#else ++# define xfs_buf_item_precommit NULL ++#endif ++ + static const struct xfs_item_ops xfs_buf_item_ops = { + .iop_size = xfs_buf_item_size, ++ .iop_precommit = xfs_buf_item_precommit, + .iop_format = xfs_buf_item_format, + .iop_pin = xfs_buf_item_pin, + .iop_unpin = xfs_buf_item_unpin, +diff --git a/fs/xfs/xfs_dquot_item.c b/fs/xfs/xfs_dquot_item.c +index 6a1aae799cf1..7d19091215b0 100644 +--- a/fs/xfs/xfs_dquot_item.c ++++ b/fs/xfs/xfs_dquot_item.c +@@ -17,6 +17,7 @@ + #include "xfs_trans_priv.h" + #include "xfs_qm.h" + #include "xfs_log.h" ++#include "xfs_error.h" + + static inline struct xfs_dq_logitem *DQUOT_ITEM(struct xfs_log_item *lip) + { +@@ -193,8 +194,38 @@ xfs_qm_dquot_logitem_committing( + return xfs_qm_dquot_logitem_release(lip); + } + ++#ifdef DEBUG_EXPENSIVE ++static int ++xfs_qm_dquot_logitem_precommit( ++ struct xfs_trans *tp, ++ struct xfs_log_item *lip) ++{ ++ struct xfs_dquot *dqp = DQUOT_ITEM(lip)->qli_dquot; ++ struct xfs_mount *mp = dqp->q_mount; ++ struct xfs_disk_dquot ddq = { }; ++ xfs_failaddr_t fa; ++ ++ xfs_dquot_to_disk(&ddq, dqp); ++ fa = xfs_dquot_verify(mp, &ddq, dqp->q_id); ++ if (fa) { ++ XFS_CORRUPTION_ERROR("Bad dquot during logging", ++ XFS_ERRLEVEL_LOW, mp, &ddq, sizeof(ddq)); ++ xfs_alert(mp, ++ "Metadata corruption detected at %pS, dquot 0x%x", ++ fa, dqp->q_id); ++ xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); ++ ASSERT(fa == NULL); ++ } ++ ++ return 0; ++} ++#else ++# define xfs_qm_dquot_logitem_precommit NULL ++#endif ++ + static const struct xfs_item_ops xfs_dquot_item_ops = { + .iop_size = xfs_qm_dquot_logitem_size, ++ .iop_precommit = xfs_qm_dquot_logitem_precommit, + .iop_format = xfs_qm_dquot_logitem_format, + .iop_pin = xfs_qm_dquot_logitem_pin, + .iop_unpin = xfs_qm_dquot_logitem_unpin, +diff --git a/fs/xfs/xfs_inode_item.c b/fs/xfs/xfs_inode_item.c +index 155a8b312875..b55ad3b7b113 100644 +--- a/fs/xfs/xfs_inode_item.c ++++ b/fs/xfs/xfs_inode_item.c +@@ -36,6 +36,36 @@ xfs_inode_item_sort( + return INODE_ITEM(lip)->ili_inode->i_ino; + } + ++#ifdef DEBUG_EXPENSIVE ++static void ++xfs_inode_item_precommit_check( ++ struct xfs_inode *ip) ++{ ++ struct xfs_mount *mp = ip->i_mount; ++ struct xfs_dinode *dip; ++ xfs_failaddr_t fa; ++ ++ dip = kzalloc(mp->m_sb.sb_inodesize, GFP_KERNEL | GFP_NOFS); ++ if (!dip) { ++ ASSERT(dip != NULL); ++ return; ++ } ++ ++ xfs_inode_to_disk(ip, dip, 0); ++ xfs_dinode_calc_crc(mp, dip); ++ fa = xfs_dinode_verify(mp, ip->i_ino, dip); ++ if (fa) { ++ xfs_inode_verifier_error(ip, -EFSCORRUPTED, __func__, dip, ++ sizeof(*dip), fa); ++ xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE); ++ ASSERT(fa == NULL); ++ } ++ kfree(dip); ++} ++#else ++# define xfs_inode_item_precommit_check(ip) ((void)0) ++#endif ++ + /* + * Prior to finally logging the inode, we have to ensure that all the + * per-modification inode state changes are applied. This includes VFS inode +@@ -168,6 +198,8 @@ xfs_inode_item_precommit( + iip->ili_fields |= (flags | iip->ili_last_fields); + spin_unlock(&iip->ili_lock); + ++ xfs_inode_item_precommit_check(ip); ++ + /* + * We are done with the log item transaction dirty state, so clear it so + * that it doesn't pollute future transactions. +-- +2.39.5 +