From: Greg Kroah-Hartman Date: Tue, 10 Dec 2024 09:35:08 +0000 (+0100) Subject: 5.4-stable patches X-Git-Tag: v6.6.65~26 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6d026f53b26b48efa89b9bc449e0b03c6a6825f9;p=thirdparty%2Fkernel%2Fstable-queue.git 5.4-stable patches added patches: dma-buf-fix-dma_fence_array_signaled-v4.patch mmc-core-further-prevent-card-detect-during-shutdown.patch regmap-detach-regmap-from-dev-on-regmap_exit.patch x86-kexec-restore-gdt-on-return-from-preserve_context-kexec.patch --- diff --git a/queue-5.4/dma-buf-fix-dma_fence_array_signaled-v4.patch b/queue-5.4/dma-buf-fix-dma_fence_array_signaled-v4.patch new file mode 100644 index 00000000000..c84e446fb2f --- /dev/null +++ b/queue-5.4/dma-buf-fix-dma_fence_array_signaled-v4.patch @@ -0,0 +1,75 @@ +From 78ac1c3558810486d90aa533b0039aa70487a3da Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Christian=20K=C3=B6nig?= +Date: Fri, 8 Nov 2024 09:29:48 +0100 +Subject: dma-buf: fix dma_fence_array_signaled v4 +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Christian König + +commit 78ac1c3558810486d90aa533b0039aa70487a3da upstream. + +The function silently assumed that signaling was already enabled for the +dma_fence_array. This meant that without enabling signaling first we would +never see forward progress. + +Fix that by falling back to testing each individual fence when signaling +isn't enabled yet. + +v2: add the comment suggested by Boris why this is done this way +v3: fix the underflow pointed out by Tvrtko +v4: atomic_read_acquire() as suggested by Tvrtko + +Signed-off-by: Christian König +Reviewed-by: Boris Brezillon +Tested-by: Chia-I Wu +Reviewed-by: Tvrtko Ursulin +Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/12094 +Cc: +Link: https://patchwork.freedesktop.org/patch/msgid/20241112121925.18464-1-christian.koenig@amd.com +Signed-off-by: Greg Kroah-Hartman +--- + drivers/dma-buf/dma-fence-array.c | 28 +++++++++++++++++++++++++++- + 1 file changed, 27 insertions(+), 1 deletion(-) + +--- a/drivers/dma-buf/dma-fence-array.c ++++ b/drivers/dma-buf/dma-fence-array.c +@@ -103,10 +103,36 @@ static bool dma_fence_array_enable_signa + static bool dma_fence_array_signaled(struct dma_fence *fence) + { + struct dma_fence_array *array = to_dma_fence_array(fence); ++ int num_pending; ++ unsigned int i; + +- if (atomic_read(&array->num_pending) > 0) ++ /* ++ * We need to read num_pending before checking the enable_signal bit ++ * to avoid racing with the enable_signaling() implementation, which ++ * might decrement the counter, and cause a partial check. ++ * atomic_read_acquire() pairs with atomic_dec_and_test() in ++ * dma_fence_array_enable_signaling() ++ * ++ * The !--num_pending check is here to account for the any_signaled case ++ * if we race with enable_signaling(), that means the !num_pending check ++ * in the is_signalling_enabled branch might be outdated (num_pending ++ * might have been decremented), but that's fine. The user will get the ++ * right value when testing again later. ++ */ ++ num_pending = atomic_read_acquire(&array->num_pending); ++ if (test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT, &array->base.flags)) { ++ if (num_pending <= 0) ++ goto signal; + return false; ++ } + ++ for (i = 0; i < array->num_fences; ++i) { ++ if (dma_fence_is_signaled(array->fences[i]) && !--num_pending) ++ goto signal; ++ } ++ return false; ++ ++signal: + dma_fence_array_clear_pending_error(array); + return true; + } diff --git a/queue-5.4/mmc-core-further-prevent-card-detect-during-shutdown.patch b/queue-5.4/mmc-core-further-prevent-card-detect-during-shutdown.patch new file mode 100644 index 00000000000..22f055ece9a --- /dev/null +++ b/queue-5.4/mmc-core-further-prevent-card-detect-during-shutdown.patch @@ -0,0 +1,56 @@ +From 87a0d90fcd31c0f36da0332428c9e1a1e0f97432 Mon Sep 17 00:00:00 2001 +From: Ulf Hansson +Date: Mon, 25 Nov 2024 13:24:46 +0100 +Subject: mmc: core: Further prevent card detect during shutdown + +From: Ulf Hansson + +commit 87a0d90fcd31c0f36da0332428c9e1a1e0f97432 upstream. + +Disabling card detect from the host's ->shutdown_pre() callback turned out +to not be the complete solution. More precisely, beyond the point when the +mmc_bus->shutdown() has been called, to gracefully power off the card, we +need to prevent card detect. Otherwise the mmc_rescan work may poll for the +card with a CMD13, to see if it's still alive, which then will fail and +hang as the card has already been powered off. + +To fix this problem, let's disable mmc_rescan prior to power off the card +during shutdown. + +Reported-by: Anthony Pighin +Fixes: 66c915d09b94 ("mmc: core: Disable card detect during shutdown") +Cc: stable@vger.kernel.org +Signed-off-by: Ulf Hansson +Reviewed-by: Adrian Hunter +Closes: https://lore.kernel.org/all/BN0PR08MB695133000AF116F04C3A9FFE83212@BN0PR08MB6951.namprd08.prod.outlook.com/ +Tested-by: Anthony Pighin +Message-ID: <20241125122446.18684-1-ulf.hansson@linaro.org> +Signed-off-by: Greg Kroah-Hartman +--- + drivers/mmc/core/bus.c | 2 ++ + drivers/mmc/core/core.c | 3 +++ + 2 files changed, 5 insertions(+) + +--- a/drivers/mmc/core/bus.c ++++ b/drivers/mmc/core/bus.c +@@ -134,6 +134,8 @@ static void mmc_bus_shutdown(struct devi + if (dev->driver && drv->shutdown) + drv->shutdown(card); + ++ __mmc_stop_host(host); ++ + if (host->bus_ops->shutdown) { + ret = host->bus_ops->shutdown(host); + if (ret) +--- a/drivers/mmc/core/core.c ++++ b/drivers/mmc/core/core.c +@@ -2382,6 +2382,9 @@ void mmc_start_host(struct mmc_host *hos + + void __mmc_stop_host(struct mmc_host *host) + { ++ if (host->rescan_disable) ++ return; ++ + if (host->slot.cd_irq >= 0) { + mmc_gpio_set_cd_wake(host, false); + disable_irq(host->slot.cd_irq); diff --git a/queue-5.4/regmap-detach-regmap-from-dev-on-regmap_exit.patch b/queue-5.4/regmap-detach-regmap-from-dev-on-regmap_exit.patch new file mode 100644 index 00000000000..6ce3ba1ad42 --- /dev/null +++ b/queue-5.4/regmap-detach-regmap-from-dev-on-regmap_exit.patch @@ -0,0 +1,59 @@ +From 3061e170381af96d1e66799d34264e6414d428a7 Mon Sep 17 00:00:00 2001 +From: Cosmin Tanislav +Date: Thu, 28 Nov 2024 15:16:23 +0200 +Subject: regmap: detach regmap from dev on regmap_exit + +From: Cosmin Tanislav + +commit 3061e170381af96d1e66799d34264e6414d428a7 upstream. + +At the end of __regmap_init(), if dev is not NULL, regmap_attach_dev() +is called, which adds a devres reference to the regmap, to be able to +retrieve a dev's regmap by name using dev_get_regmap(). + +When calling regmap_exit, the opposite does not happen, and the +reference is kept until the dev is detached. + +Add a regmap_detach_dev() function and call it in regmap_exit() to make +sure that the devres reference is not kept. + +Cc: stable@vger.kernel.org +Fixes: 72b39f6f2b5a ("regmap: Implement dev_get_regmap()") +Signed-off-by: Cosmin Tanislav +Rule: add +Link: https://lore.kernel.org/stable/20241128130554.362486-1-demonsingur%40gmail.com +Link: https://patch.msgid.link/20241128131625.363835-1-demonsingur@gmail.com +Signed-off-by: Mark Brown +Signed-off-by: Greg Kroah-Hartman +--- + drivers/base/regmap/regmap.c | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +--- a/drivers/base/regmap/regmap.c ++++ b/drivers/base/regmap/regmap.c +@@ -603,6 +603,17 @@ int regmap_attach_dev(struct device *dev + } + EXPORT_SYMBOL_GPL(regmap_attach_dev); + ++static int dev_get_regmap_match(struct device *dev, void *res, void *data); ++ ++static int regmap_detach_dev(struct device *dev, struct regmap *map) ++{ ++ if (!dev) ++ return 0; ++ ++ return devres_release(dev, dev_get_regmap_release, ++ dev_get_regmap_match, (void *)map->name); ++} ++ + static enum regmap_endian regmap_get_reg_endian(const struct regmap_bus *bus, + const struct regmap_config *config) + { +@@ -1347,6 +1358,7 @@ void regmap_exit(struct regmap *map) + { + struct regmap_async *async; + ++ regmap_detach_dev(map->dev, map); + regcache_exit(map); + regmap_debugfs_exit(map); + regmap_range_exit(map); diff --git a/queue-5.4/series b/queue-5.4/series index 9360796cc6e..49e47c3fba2 100644 --- a/queue-5.4/series +++ b/queue-5.4/series @@ -260,3 +260,7 @@ scsi-qla2xxx-supported-speed-displayed-incorrectly-for-vports.patch scsi-qla2xxx-remove-check-req_sg_cnt-should-be-equal-to-rsp_sg_cnt.patch nilfs2-fix-potential-out-of-bounds-memory-access-in-nilfs_find_entry.patch bcache-revert-replacing-is_err_or_null-with-is_err-again.patch +x86-kexec-restore-gdt-on-return-from-preserve_context-kexec.patch +dma-buf-fix-dma_fence_array_signaled-v4.patch +regmap-detach-regmap-from-dev-on-regmap_exit.patch +mmc-core-further-prevent-card-detect-during-shutdown.patch diff --git a/queue-5.4/x86-kexec-restore-gdt-on-return-from-preserve_context-kexec.patch b/queue-5.4/x86-kexec-restore-gdt-on-return-from-preserve_context-kexec.patch new file mode 100644 index 00000000000..ea55ef62d4a --- /dev/null +++ b/queue-5.4/x86-kexec-restore-gdt-on-return-from-preserve_context-kexec.patch @@ -0,0 +1,82 @@ +From 07fa619f2a40c221ea27747a3323cabc59ab25eb Mon Sep 17 00:00:00 2001 +From: David Woodhouse +Date: Thu, 5 Dec 2024 15:05:07 +0000 +Subject: x86/kexec: Restore GDT on return from ::preserve_context kexec + +From: David Woodhouse + +commit 07fa619f2a40c221ea27747a3323cabc59ab25eb upstream. + +The restore_processor_state() function explicitly states that "the asm code +that gets us here will have restored a usable GDT". That wasn't true in the +case of returning from a ::preserve_context kexec. Make it so. + +Without this, the kernel was depending on the called function to reload a +GDT which is appropriate for the kernel before returning. + +Test program: + + #include + #include + #include + #include + #include + #include + #include + #include + + int main (void) + { + struct kexec_segment segment = {}; + unsigned char purgatory[] = { + 0x66, 0xba, 0xf8, 0x03, // mov $0x3f8, %dx + 0xb0, 0x42, // mov $0x42, %al + 0xee, // outb %al, (%dx) + 0xc3, // ret + }; + int ret; + + segment.buf = &purgatory; + segment.bufsz = sizeof(purgatory); + segment.mem = (void *)0x400000; + segment.memsz = 0x1000; + ret = syscall(__NR_kexec_load, 0x400000, 1, &segment, KEXEC_PRESERVE_CONTEXT); + if (ret) { + perror("kexec_load"); + exit(1); + } + + ret = syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_KEXEC); + if (ret) { + perror("kexec reboot"); + exit(1); + } + printf("Success\n"); + return 0; + } + +Signed-off-by: David Woodhouse +Signed-off-by: Ingo Molnar +Cc: stable@vger.kernel.org +Link: https://lore.kernel.org/r/20241205153343.3275139-2-dwmw2@infradead.org +Signed-off-by: Greg Kroah-Hartman +--- + arch/x86/kernel/relocate_kernel_64.S | 7 +++++++ + 1 file changed, 7 insertions(+) + +--- a/arch/x86/kernel/relocate_kernel_64.S ++++ b/arch/x86/kernel/relocate_kernel_64.S +@@ -218,6 +218,13 @@ virtual_mapped: + movq CR0(%r8), %r8 + movq %rax, %cr3 + movq %r8, %cr0 ++ ++#ifdef CONFIG_KEXEC_JUMP ++ /* Saved in save_processor_state. */ ++ movq $saved_context, %rax ++ lgdt saved_context_gdt_desc(%rax) ++#endif ++ + movq %rbp, %rax + + popf