From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C917303A31 for ; Wed, 3 Dec 2025 23:01:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764802902; cv=none; b=AE4KytP/H4SRO85frpAPP1Qan0NpY+/RbYc+NtgbZCpD1vr+McnpmMz8gsFx/aLEUwFNl0Mj8K/1+eYYVxneLliLm0JV853qDTjPqdFx0IQkarGCgc2xJQCD59nVfmrPZzE0dSTJAAclBW/RXHW4k8vY5ltexgM6gzxeoP2lRWk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764802902; c=relaxed/simple; bh=cfj2zjNsaRfQ7e5BxzcOQVqsyl/ePA5gwrbyUaakR/I=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=EZ+T/aP037znjJt3OEnQeBaL2SSItJierXZaxBdr2/YZ36hgyywRk/soHQqKk3YQ36vNdGRoNbsmRMWIl9p6DIIu6XIlsBvnXH7YYhZQwz5mRJFQEx0lxJf8WN82G7OhM5n5Q3MwNd99ypSdIDEsFUPuzP9/RpwelwSrQoampPo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EzjGPCu8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EzjGPCu8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5548AC116B1 for ; Wed, 3 Dec 2025 23:01:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764802901; bh=cfj2zjNsaRfQ7e5BxzcOQVqsyl/ePA5gwrbyUaakR/I=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=EzjGPCu89DqsQSU2wKQ3g3NJ2JAxX2A4cDCb/yntid8zorUdpf7LuhezQLGvnYYH5 FxxpJhfvjpvsZQ/o62Jp6x7oqJlamvVv00wY70ZucU9byCZ3w/OZaLQm/pOxnLSLfs ajjlFuxgr6Mig+V+jWZgSIYRIqD0YJJvBzyIFPAZf13ixu7YWzxdnmSNdbhyqOnXTn sn5j4Hz8Kk8/j6r1SSRLqPUCctEyWEZcytmlLD/W0fhAdkCTNb3fy8oMF4clDFOQ0L kwR4MabAiYlRM2zbIM/cakz9xvfhXCq6nYG6ViJrds1GTDXPXG3mVhDYBSXCcA6qQ5 VifMkM/alvEOw== Received: by mail-lf1-f48.google.com with SMTP id 2adb3069b0e04-5942bac322dso275307e87.0 for ; Wed, 03 Dec 2025 15:01:41 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUFKOEAca56ksphn3NSSn7ess9epoa2H0SBRbA/OPSrecHVjkhOmAxU7D6bYq7Ry4JZOlVUINYw2gqNBUU=@vger.kernel.org X-Gm-Message-State: AOJu0YznEg+Hq/bOD7bt6bnn2nDmQMk0HHjB6rN19h5tTXDdDkS0N4b6 9qP7+n7OMTj+mjKOT/uqeQ9X/WjJKTddX43bo42ZKEJzTLC1eg6VwSj/iRH8on6gMUUyvoQy/MG SLBFEfJXmDM9qMY3w7N6wJTzHYWYazwk= X-Google-Smtp-Source: AGHT+IE39Ns68o2kZx+NKTfGww1Lg2nUJYqn7GdpUvAL7xI6DI6tHKKGbwrDa4yglhCU9i5ekgbZna7a/42dyfZ6rJE= X-Received: by 2002:a05:6512:3ba2:b0:594:35b7:aa7 with SMTP id 2adb3069b0e04-597d3feeeccmr1431043e87.48.1764802899678; Wed, 03 Dec 2025 15:01:39 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20251126173209.374755-2-chewi@gentoo.org> In-Reply-To: From: Ard Biesheuvel Date: Thu, 4 Dec 2025 00:01:28 +0100 X-Gmail-Original-Message-ID: X-Gm-Features: AWmQ_bls7Tg68h4Gy0l1vs4yOzV5-rElxWpT7QU_0V1GMUEJ6C08kDMnH_1xbLc Message-ID: Subject: Re: [PATCH] x86: fix oops caused by old EFI info on kexec boot To: Ingo Molnar Cc: James Le Cuirot , x86@kernel.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H . Peter Anvin" Content-Type: text/plain; charset="UTF-8" On Wed, 3 Dec 2025 at 23:57, Ard Biesheuvel wrote: > > On Wed, 3 Dec 2025 at 19:13, Ingo Molnar wrote: > > > > * James Le Cuirot wrote: > > > > > kexec on x86 passes initrd details via the boot_params. If no initrd is > > > supplied, then ramdisk_size is 0. When determining whether to reserve > > > memory for the initrd on the subsequent boot, ramdisk_size being 0 > > > causes the logic to fall back to phys_initrd_start and phys_initrd_size > > > set from the EFI tables in efi.c. This is stale information from the > > > initial boot. The system continues to boot and has even been seen to > > > function under heavy load for days, but allocating very large amounts of > > > memory reliably triggers an oops rather than the OOM killer. > > > > > > BUG: kernel NULL pointer dereference, address: 0000000000000008 > > > #PF: supervisor write access in kernel mode > > > #PF: error_code(0x0002) - not-present page > > > PGD 0 P4D 0 > > > Oops: Oops: 0002 [#1] SMP NOPTI > > > > > > This issue was introduced in f4dc7fffa9873db50ec25624572f8217a6225de8 > > > when the EFI stub initrd loading was unified between architectures. > > > > > > Avoid the issue by checking whether the bootloader is not kexec before > > > falling back to the EFI table values. > > > > > > I strongly suspect this also affects other architectures. A different > > > fix would be required there, and I do have a fix in mind, but I was > > > unable to reproduce the issue under QEMU's aarch64 virt machine. I think > > > this is at least partly because it relies on ACPI while kexec passes the > > > initd details via the device tree. > > > > > > Signed-off-by: James Le Cuirot > > > --- > > > arch/x86/kernel/setup.c | 6 ++++-- > > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > > > diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c > > > index 1b2edd07a3e1..8aa65daf121f 100644 > > > --- a/arch/x86/kernel/setup.c > > > +++ b/arch/x86/kernel/setup.c > > > @@ -300,7 +300,8 @@ static u64 __init get_ramdisk_image(void) > > > > > > ramdisk_image |= (u64)boot_params.ext_ramdisk_image << 32; > > > > > > - if (ramdisk_image == 0) > > > + /* Don't fall back for kexec as phys_initrd_start will be stale */ > > > + if (ramdisk_image == 0 && (boot_params.hdr.type_of_loader >> 4) != 0xD) > > > ramdisk_image = phys_initrd_start; > > > > > > return ramdisk_image; > > > @@ -311,7 +312,8 @@ static u64 __init get_ramdisk_size(void) > > > > > > ramdisk_size |= (u64)boot_params.ext_ramdisk_size << 32; > > > > > > - if (ramdisk_size == 0) > > > + /* Don't fall back for kexec as phys_initrd_start will be stale */ > > > + if (ramdisk_size == 0 && (boot_params.hdr.type_of_loader >> 4) != 0xD) > > > ramdisk_size = phys_initrd_size; > > > > Yeah, so this looks like a good fix - but please let's > > introduce some sort of enum for the bootloader IDs > > in arch/x86/include/uapi/asm/bootparam.h, I had to search > > way too long to figure out what 0xD is and where it > > was defined :-) > > > > Also, please introduce a "x86_bootloader_is_kexec()" kind > > of helper inline function as well. > > > > It might be better to fix this in the generic EFI code, and simply > wipe the EFI config table that the EFI stub created to pass the initrd > info. That way, it works for all architectures, and there is no need > for special x86 hacks. I.e., --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -818,6 +818,7 @@ if (tbl) { phys_initrd_start = tbl->base; phys_initrd_size = tbl->size; + tbl->base = tbl->size = 0; early_memunmap(tbl, sizeof(*tbl)); } }