From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794815989; b=QrdSUlvi7ZQ/wl5mueyh7PcDhZvu1M0nHQGkzuZuX6r8NO4iaB/o5xbD96252n5BizqL 713CbioHP8Xh1lTLzYJVkGn642AbU6KzsJ/sIqshwPNv27sjiKzCwRp+5vim9u2RyoUtx VjW/2a+5w7PZwBXrvQ1rDEB4aUUqRZjZijDpwxnZoGgF2ayN2wbhsrif5J5f8vaXwjB9h L0/JD/S/AmIaiSqnJQ5B6v5wflWmFEIfB1JoOMLQTt5MSQC0qcpi50YrAbqQ+yWKyHGuy 4sS7SIk1q+dhhr0CivC3iamBdgTdnZrmZGiAN47FX1FZdGT7t+1KPx/auUdAGCjPLiQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794815989; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:Content-Transfer-Encoding:User-Agent:MIME-Version; bh=mcuJSSxZnzgSbNJLicY5YRDK+dG26RVtPhpOzcEjiSU=; b=f58O59pMz7GFhiBUuU6QhDrUeAZIdUCPOBGSGjRi6Lz12WbPH/fM6VUMViIbJlUBRukb lNqZX1fyDF4A6/VVKBJwAXOxXpgyD8mnzaNi7V0JK7tZtw3Jcx3JD78wrjjIIdTlY8mCc t77a54XGSouXuSoSDM24yw5VHTqFyK1uJESsZO/PN28v1bMNYK2cMyuxfaqJqiwo2jVKe bU7r/xV7LZJGwofuYwNG0QDcwAO6WQ1jmfy69Q42fsZ8VPzWxft5DEKT+gYUqJBJCYjh3 orkWVLIq60cFEtWRVk0jkgGUNmjeP2rNk/yRQKIisx7u5/MNvvjHPm+HlyKyTn2c0gA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=amutable.com; spf=pass smtp.mailfrom=amutable.com; dkim=pass header.d=amutable-com.20260707.gappssmtp.com header.i=@amutable-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=O1BXF7ki; arc=none smtp.remote-ip=209.85.221.51 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46395606A32A for ; Mon, 16 Nov 2026 07:59:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 46395606A32A Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=amutable.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amutable.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amutable-com.20260707.gappssmtp.com header.i=@amutable-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=O1BXF7ki Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-48dee593f18so3296513f8f.3 for ; Sun, 15 Nov 2026 23:59:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amutable-com.20260707.gappssmtp.com; s=20260707; t=1794815987; x=1795420787; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:from:to :cc:subject:date:message-id:reply-to:content-type; bh=mcuJSSxZnzgSbNJLicY5YRDK+dG26RVtPhpOzcEjiSU=; b=O1BXF7kitU2oRSc1LTo+wW4pDoWUGl2PNfV6Mrx6Mvp0/wij7mnUpERFldGZUqkIKs XZw/mtfFkj/UusVH9UrBTKcJVRdKx157srIuj7SKjCzseY8A/sgQ6OmnwahspQTTMdTb ByYOOEcfk1PuecIY/16A6lAoNoMzQHrf6zdncTXX7aDRK9LszvHpzh7ZPEH0Mx6sQJmq xrh7MXGpzyM4o4TzkERIrB1zJfr9k2i/s6K+UbTefEt1DHDqv/Xkm9Buwd9MUFTJidcV xXqa8U5JudzPl6G50YjbGyGAURqJrnYr87IThG271yWvR/pRqmIPWQef8YP9COtt8oSx doJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794815987; x=1795420787; h=mime-version:user-agent:content-transfer-encoding:content-type :references:in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=mcuJSSxZnzgSbNJLicY5YRDK+dG26RVtPhpOzcEjiSU=; b=yn7u+oQROv2ZbfNnmcwQdAfjDoVDLao/W9gNW/qR6S/NmXyui5Kj0oqeIsdNHGb+Na sI9KTQ6Ix5vJw/tqw5oYxCpq6mBe3bIgXiOOJvWpUUEBGju6jp0Ob3AOVxr3z4WqM5CF 2tFx9+aDSB7wSAktZNtFwZ77rGsf7TVIocSxPD+Hk+IKLQq1PxeNNSq2idqVvARMfE0O vN0mtcGsI/0hCZhzpge3pF9/KR12tQqL38XJ3xHJcjVAF1Kcsn8Slvl3nPCB2XQG2MOK NcmhhLA4V9Y4rKu3ku+ZSQimlGRi8UU494IZ3lrvOVjersokeWQdS3Q3T/f44AKJ2Aj0 2grA== X-Forwarded-Encrypted: i=1; AL+hErE1yyTDtyDK2QMhHgGUeu3s5eiY77g3aQ2swoysPBeB+XY3xCjnEsqlsqcywQXQDaWxs1+55pwh0r/F/xg=@vger.kernel.org X-Gm-Message-State: APuU4Z8VTRRnxpIhDG2BTDLCyDFV3+X6o7DrSzQTEhnjioBL7pba9ESD x8r6tHDubz8vgJeEzcrgEKfTtukbGslg3Gcw3C5iTzR5fRQxDhH0kfOvp9osBLSO4LPI X-Gm-Gg: AYBFou24P23fCLt74QoWFYrxOdraSDZSdoRjcNTSDFfORFCEnIzxXTEBZ0EnimyPp39 CGzA50L1kup6Vqgp2V4Do+QNTtDQdaghSkfbZuERqwQ0EpG3x6pJHA7/yzFdC2AjOv3AnWpBUQX LBGgcyKjOJIdqEbNbHefOBTvtAtxqxtpB1Z8kCnQ5vcTZO0ZJovU/YSV5XUaG29XM4XHbV3lh0m qioVf0+FGXJ7fbF6dgyiWf4h+yQmucFIju6XWehUrUfcjwxVhqQpENl7zUS+gz9TN3Pe1iSS7SG JrAO3STI3caOTeoOLsoOkQ99oG3nJk7JiBn3EdlVI/3/nasJHQjz8yhU2m07pPuxcoq9VOESryE Cqd/HRU4lJ/pKeoEWXkdQlOv9gJ5KBarEXIaDOyHI9a3ToHm16ChC/YtOufRuPyjiHFz6oYhaDj 3NdYE07MDX3JYecrBW8OqjH1/+h8KfezXaV+jXQ4hUFanMmN0EEropv3RDDQDoY8JnkrVHZRAoo ztEpSNznIZuTOo90KkGqJP4mNmO6NWfIXC8e76ofbw5BM3d+pQepcajT/PJBiLESfBpxSC0fS5x gmNbBEW9PrzzHZyxWhBDNtkDNscX/32f5lPhSQHg4PkZpTHFhPZ4+W8Pj41AGlC+z/GZgm6Qg9L spVN64s/+ X-Received: by 2002:a05:6000:993:b0:48f:bc59:ab9c with SMTP id ffacd0b85a97d-49c6fd932f0mr20349731f8f.12.1794815987554; Sun, 15 Nov 2026 23:59:47 -0800 (PST) Received: from [10.0.0.233] (tmo-086-54.customers.d1-online.com. [80.187.86.54]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-49d69c21a17sm15766858f8f.50.2026.11.15.23.59.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Nov 2026 23:59:47 -0800 (PST) Message-ID: <832e0f9ce4e81ee31a6bcde01591a56aac36e976.camel@amutable.com> Subject: Re: [PATCH RFC 3/4] crash_dump: recover from a machine check in copy_oldmem_page() From: Alexander Mikhalitsyn To: Christian Brauner , linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , Breno Leitao , Chris Mason , Thomas Gleixner , x86@kernel.org, kexec@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, David Hildenbrand , stable@vger.kernel.org Date: Mon, 16 Nov 2026 08:59:45 +0100 In-Reply-To: <20261112-work-procfs-oldmem-v1-3-ecdcafd99265@kernel.org> References: <20261112-work-procfs-oldmem-v1-0-ecdcafd99265@kernel.org> <20261112-work-procfs-oldmem-v1-3-ecdcafd99265@kernel.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.56.2-0+deb13u1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 On Thu, 2026-11-12 at 17:37 +0100, Christian Brauner wrote: > A capture kernel reads the memory of the crashed kernel, and that > memory > may well have uncorrectable errors. That is after all what the first > kernel often died of. Every architecture that maps a page of the old > kernel and copies it out does so with copy_to_iter(), and a machine > check in that copy takes the capture kernel down. >=20 > On x86 a machine check in the kernel is only recovered from if the > instruction that took it has a machine check safe exception table > entry > or copies from userspace (cf. error_context()). The copy of an old > page > is neither. Its source is kernel memory, whether it goes to the > buffer > of a read() or, since commit 4a22fd20379c ("vmcore: convert > __read_vmcore to use an iov_iter"), into a kernel page for splice(), > sendfile() and copy_file_range(). So a read of /proc/vmcore that runs > into a poisoned page panics the capture kernel, and so do vmcore's > own > reads of the ELF headers and notes. Breno sees the result on a fleet: > the first kernel dies of a machine check and the capture kernel > produces > no usable vmcore at all (cf. [1]). >=20 > On book3s64 a machine check in the kernel is recovered from if the > instruction that took it has an exception table entry (cf. > mce_common_process_ue()). The user copy has them, so a read() comes > up > short there and read_from_oldmem() returns -EFAULT. The copies into > kernel pages have none and panic the same way. Other powerpc > platforms > don't recover from a machine check in such a copy at all. >=20 > Copy with _copy_mc_to_iter() instead. x86_64 and PPC64 select > ARCH_HAS_COPY_MC, and on x86_64 and book3s64 the machine check safe > copy > turns the machine check into a short copy, which read_from_oldmem() > turns into -EFAULT like any other short copy. On x86 that holds for > the > fragile and the enhanced fast string variant, a CPU with neither gets > the plain copy it has today. Everywhere else _copy_mc_to_iter() is > _copy_to_iter(). Put the call into a helper, copy_oldmem_to_iter(), > so > that the copy of a page of the old kernel lives in one place and an > architecture that gains a machine check safe copy later gets this for > free. The helper does the same check_copy_size() as copy_to_iter(), > so > hardened usercopy keeps checking the copy. >=20 > With a v7.4-rc1 capture kernel reading /proc/vmcore and a machine > check > injected into the copy of an old page the capture kernel is gone. A > machine check panic prints no trace of its own, this one comes from > panic_sys_info=3Dall_bt: >=20 > [=C2=A0=C2=A0=C2=A0 0.580568] mce: [Hardware Error]: CPU 0: Machine Check= Exception: > 7 Bank 1: bd80000000000134 > [=C2=A0=C2=A0=C2=A0 0.580574] mce: [Hardware Error]: RIP 10: > {_copy_to_iter+0x81/0x850} > [=C2=A0=C2=A0=C2=A0 0.580584] mce: [Hardware Error]: TSC 202f2117f ADDR 1= 0000000 > MISC 8c > [=C2=A0=C2=A0=C2=A0 0.580587] mce: [Hardware Error]: PROCESSOR 2:aa0f02 T= IME > 1794493617 SOCKET 0 APIC 0 microcode aa0021c > [=C2=A0=C2=A0=C2=A0 0.580589] mce: [Hardware Error]: Machine check: Uncor= rected > unrecoverable error in kernel context > [=C2=A0=C2=A0=C2=A0 0.580591] Kernel panic - not syncing: Fatal local mac= hine check > [=C2=A0=C2=A0=C2=A0 0.582587] CPU: 0 UID: 0 PID: 1 Comm: init Not tainted= 7.4.0-rc1- > g6628e7d4c6b2 #1 PREEMPT(lazy) > [=C2=A0=C2=A0=C2=A0 0.583101] Call Trace: > [=C2=A0=C2=A0=C2=A0 0.583198]=C2=A0 <#MC> > [=C2=A0=C2=A0=C2=A0 0.583279]=C2=A0 dump_stack_lvl+0x4d/0x70 > [=C2=A0=C2=A0=C2=A0 0.583419]=C2=A0 nmi_cpu_backtrace.cold+0x18/0x6e > [=C2=A0=C2=A0=C2=A0 0.583584]=C2=A0 ? __pfx_nmi_raise_cpu_backtrace+0x10/= 0x10 > [=C2=A0=C2=A0=C2=A0 0.583772]=C2=A0 nmi_trigger_cpumask_backtrace+0xba/0x= f0 > [=C2=A0=C2=A0=C2=A0 0.583955]=C2=A0 sys_info+0x83/0xb0 > [=C2=A0=C2=A0=C2=A0 0.584075]=C2=A0 vpanic+0x1b4/0x303 > [=C2=A0=C2=A0=C2=A0 0.584197]=C2=A0 panic+0x66/0x70 > [=C2=A0=C2=A0=C2=A0 0.584488]=C2=A0 mce_panic+0x19e/0x290 > [=C2=A0=C2=A0=C2=A0 0.584799]=C2=A0 do_machine_check+0x627/0x9a0 > [=C2=A0=C2=A0=C2=A0 0.584953]=C2=A0 ? _copy_to_iter+0x81/0x850 > [=C2=A0=C2=A0=C2=A0 0.585099]=C2=A0 exc_machine_check+0x68/0xb0 > [=C2=A0=C2=A0=C2=A0 0.585246]=C2=A0 asm_exc_machine_check+0x1e/0x40 > [=C2=A0=C2=A0=C2=A0 0.587747]=C2=A0 > [=C2=A0=C2=A0=C2=A0 0.587831]=C2=A0 > [=C2=A0=C2=A0=C2=A0 0.588092]=C2=A0 ? iomem_map_sanity_check+0x98/0xb0 > [=C2=A0=C2=A0=C2=A0 0.588430]=C2=A0 ? __ioremap_caller.isra.0+0x1a9/0x300 > [=C2=A0=C2=A0=C2=A0 0.588604]=C2=A0 ? __copy_oldmem_page+0x3d/0xb0 > [=C2=A0=C2=A0=C2=A0 0.588928]=C2=A0 __copy_oldmem_page+0x5e/0xb0 > [=C2=A0=C2=A0=C2=A0 0.589079]=C2=A0 read_from_oldmem.part.0+0xe3/0x140 > [=C2=A0=C2=A0=C2=A0 0.589247]=C2=A0 read_vmcore+0x137/0x280 > [=C2=A0=C2=A0=C2=A0 0.589381]=C2=A0 proc_reg_read_iter+0x49/0x90 > [=C2=A0=C2=A0=C2=A0 0.589533]=C2=A0 vfs_read+0x348/0x490 > [=C2=A0=C2=A0=C2=A0 0.589666]=C2=A0 ksys_read+0x76/0x100 > [=C2=A0=C2=A0=C2=A0 0.589792]=C2=A0 do_syscall_64+0xde/0x4b0 > [=C2=A0=C2=A0=C2=A0 0.590103]=C2=A0 entry_SYSCALL_64_after_hwframe+0x77/0= x7f >=20 > With this patch the same injection ends the read() with -EFAULT, the > capture kernel logs the machine check and keeps running. >=20 > [1]: https://lore.kernel.org/all/avRXzzCSzT9Qj2FC@gmail.com/ >=20 > Reported-by: Chris Mason > Suggested-by: Breno Leitao > Fixes: 4ae362be5093 ("[PATCH] kdump: read previous kernel's memory") > Fixes: 54c32021eb6f ("[PATCH] powerpc: Add arch-dependent > copy_oldmem_page") > Fixes: 4a22fd20379c ("vmcore: convert __read_vmcore to use an > iov_iter") > Cc: stable@vger.kernel.org > Signed-off-by: Christian Brauner (Amutable) Reviewed-by: Alexander Mikhalitsyn > --- > =C2=A0arch/powerpc/kernel/crash_dump.c |=C2=A0 4 ++-- > =C2=A0arch/x86/kernel/crash_dump_64.c=C2=A0 |=C2=A0 2 +- > =C2=A0include/linux/crash_dump.h=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 | 22= ++++++++++++++++++++++ > =C2=A03 files changed, 25 insertions(+), 3 deletions(-) >=20 > diff --git a/arch/powerpc/kernel/crash_dump.c > b/arch/powerpc/kernel/crash_dump.c > index 1543917bd3e1d..f784fc5cb0030 100644 > --- a/arch/powerpc/kernel/crash_dump.c > +++ b/arch/powerpc/kernel/crash_dump.c > @@ -83,12 +83,12 @@ ssize_t copy_oldmem_page(struct iov_iter *iter, > unsigned long pfn, > =C2=A0 > =C2=A0 if (memblock_is_region_memory(paddr, csize)) { > =C2=A0 vaddr =3D __va(paddr); > - csize =3D copy_to_iter(vaddr + offset, csize, iter); > + csize =3D copy_oldmem_to_iter(vaddr + offset, csize, > iter); > =C2=A0 } else { > =C2=A0 vaddr =3D ioremap_cache(paddr, PAGE_SIZE); > =C2=A0 if (!vaddr) > =C2=A0 return -ENOMEM; > - csize =3D copy_to_iter(vaddr + offset, csize, iter); > + csize =3D copy_oldmem_to_iter(vaddr + offset, csize, > iter); > =C2=A0 iounmap(vaddr); > =C2=A0 } > =C2=A0 > diff --git a/arch/x86/kernel/crash_dump_64.c > b/arch/x86/kernel/crash_dump_64.c > index 32d710f7eb84c..e10dada855b70 100644 > --- a/arch/x86/kernel/crash_dump_64.c > +++ b/arch/x86/kernel/crash_dump_64.c > @@ -29,7 +29,7 @@ static ssize_t __copy_oldmem_page(struct iov_iter > *iter, unsigned long pfn, > =C2=A0 if (!vaddr) > =C2=A0 return -ENOMEM; > =C2=A0 > - csize =3D copy_to_iter(vaddr + offset, csize, iter); > + csize =3D copy_oldmem_to_iter(vaddr + offset, csize, iter); > =C2=A0 > =C2=A0 iounmap((void __iomem *)vaddr); > =C2=A0 return csize; > diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h > index 8315270e27b7a..12aeaa40c1c94 100644 > --- a/include/linux/crash_dump.h > +++ b/include/linux/crash_dump.h > @@ -6,6 +6,7 @@ > =C2=A0#include > =C2=A0#include > =C2=A0#include > +#include > =C2=A0#include > =C2=A0 > =C2=A0/* For IS_ENABLED(CONFIG_CRASH_DUMP) */ > @@ -33,6 +34,27 @@ ssize_t copy_oldmem_page(struct iov_iter *i, > unsigned long pfn, size_t csize, > =C2=A0ssize_t copy_oldmem_page_encrypted(struct iov_iter *iter, unsigned > long pfn, > =C2=A0 =C2=A0=C2=A0 size_t csize, unsigned long > offset); > =C2=A0 > +/** > + * copy_oldmem_to_iter - copy from the crashed kernel's memory > + * @src: where in the mapped page of the crashed kernel to copy from > + * @count: how many bytes to copy > + * @iter: where to copy them > + * > + * The memory of the crashed kernel may well have uncorrectable > errors. > + * Where the architecture has a machine check safe copy a machine > check > + * in the copy ends it short, like a fault would, instead of taking > the > + * capture kernel down. Everywhere else this is copy_to_iter(). > + * > + * Return: the number of bytes copied, like copy_to_iter(). > + */ > +static inline size_t copy_oldmem_to_iter(const void *src, size_t > count, > + struct iov_iter *iter) > +{ > + if (check_copy_size(src, count, true)) > + return _copy_mc_to_iter(src, count, iter); > + return 0; > +} > + > =C2=A0void vmcore_cleanup(void); > =C2=A0 > =C2=A0/* Architecture code defines this if there are other possible ELF