From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A5ACEC87FCB for ; Wed, 30 Jul 2025 07:33:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=tg3kHXf/VEPySXPdaIeZnW9fOV15ESdV9yA7hGdIv+A=; b=I2HlIhVMWPwi5hUfI4Bcqzn9rg DJUk8kXKh9gFZhkljgATeTmauAoQK6HJNux8TobsdHjj88XYIxXudin5VQg84B7k1b7XwPiJb2E9n f51WlYFEhkKwO3p7nXRx6KHYVY71Y/q7uUwk8R6vxxblZOqjeqqX3LGSSpqO5GReZafzHzjNstHzg EH1zu0732STP98RgrzI67RDzvRl/MicHCi6p6i0cA5JoS9aAY5TLbHoLYBR7RzTjcbBCU81a+q61c TmQ6R6jrcGplWryNSAHFzNd+cdeJ3WrlW1AzWFAxTZwT+aDorh1wf4OvoqycKLyFqZhDa5gtbviFd ULZpcUZg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uh1JF-00000000tDc-1he9; Wed, 30 Jul 2025 07:33:09 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uh1JD-00000000tCy-0Jze for kexec@lists.infradead.org; Wed, 30 Jul 2025 07:33:08 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1753860785; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=tg3kHXf/VEPySXPdaIeZnW9fOV15ESdV9yA7hGdIv+A=; b=GXJi4pGBTzEoH0SQq/fH0ac5WGurle0344XgUN/k1fuZIIDiOYqqlhxGeekJJb9IDDtNtf zCkHRySiFClr576EAXojJ7SqtwNl/gxGsFzE1+V/sEb47noQm2MbQv93Ku/Qt6kQs+kw+Q p7Vlw09K4Yl8xKqrzkp1721TWFCJApo= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-626-Dp1SzmyFOle5TuJFQO5dSQ-1; Wed, 30 Jul 2025 03:31:24 -0400 X-MC-Unique: Dp1SzmyFOle5TuJFQO5dSQ-1 X-Mimecast-MFC-AGG-ID: Dp1SzmyFOle5TuJFQO5dSQ_1753860683 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1116119560AA; Wed, 30 Jul 2025 07:31:22 +0000 (UTC) Received: from darkstar.users.ipa.redhat.com (unknown [10.72.116.59]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 438C21800B71; Wed, 30 Jul 2025 07:31:12 +0000 (UTC) Date: Wed, 30 Jul 2025 15:31:59 +0800 From: Dave Young To: Brian Mak Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Andrew Morton , Baoquan He , Rob Herring , Saravana Kannan , x86@kernel.org, kexec@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH RESEND] x86/kexec: Carry forward the boot DTB on kexec Message-ID: References: <20250729182142.4875-1-makb@juniper.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250729182142.4875-1-makb@juniper.net> X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250730_003307_232368_B2D2B212 X-CRM114-Status: GOOD ( 28.12 ) X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" Errors-To: kexec-bounces+kexec=archiver.kernel.org@lists.infradead.org On Tue, Jul 29, 2025 at 11:21:42AM -0700, Brian Mak wrote: > The kexec_file_load syscall on x86 currently does not support passing > a device tree blob to the new kernel. > > To add support for this, we copy the behavior of ARM64 and PowerPC and > copy the current boot's device tree blob for use in the new kernel. We > do this on x86 by passing the device tree blob as a setup_data entry in > accordance with the x86 boot protocol. > > Signed-off-by: Brian Mak > --- > arch/x86/kernel/kexec-bzimage64.c | 46 +++++++++++++++++++++++++++++-- > 1 file changed, 43 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c > index 24a41f0e0cf1..c24536c25f98 100644 > --- a/arch/x86/kernel/kexec-bzimage64.c > +++ b/arch/x86/kernel/kexec-bzimage64.c > @@ -16,6 +16,8 @@ > #include > #include > #include > +#include > +#include > #include > #include > > @@ -212,6 +214,28 @@ setup_efi_state(struct boot_params *params, unsigned long params_load_addr, > } > #endif /* CONFIG_EFI */ > > +#ifdef CONFIG_OF_FLATTREE > +static void setup_dtb(struct boot_params *params, > + unsigned long params_load_addr, > + unsigned int dtb_setup_data_offset) > +{ > + struct setup_data *sd = (void *)params + dtb_setup_data_offset; > + unsigned long setup_data_phys, dtb_len; > + > + dtb_len = fdt_totalsize(initial_boot_params); > + sd->type = SETUP_DTB; > + sd->len = dtb_len; > + > + /* Carry over current boot DTB with setup_data */ > + memcpy(sd->data, initial_boot_params, dtb_len); > + > + /* Add setup data */ > + setup_data_phys = params_load_addr + dtb_setup_data_offset; > + sd->next = params->hdr.setup_data; > + params->hdr.setup_data = setup_data_phys; > +} > +#endif /* CONFIG_OF_FLATTREE */ > + > static void > setup_ima_state(const struct kimage *image, struct boot_params *params, > unsigned long params_load_addr, > @@ -336,6 +360,16 @@ setup_boot_parameters(struct kimage *image, struct boot_params *params, > sizeof(struct efi_setup_data); > #endif > > +#ifdef CONFIG_OF_FLATTREE > + if (initial_boot_params) { > + setup_dtb(params, params_load_addr, setup_data_offset); > + setup_data_offset += sizeof(struct setup_data) + > + fdt_totalsize(initial_boot_params); I suppose current boot dtb should be valid for the current runnning kernel, if you use kexec to load another kernel the next kexec reboot could fail due to unmatching dtb. Make this unconditionally could break the previous working kexec? > + } else { > + pr_info("No DTB\n"); pr_debug sounds better. > + } > +#endif > + > if (IS_ENABLED(CONFIG_IMA_KEXEC)) { > /* Setup IMA log buffer state */ > setup_ima_state(image, params, params_load_addr, > @@ -529,6 +563,12 @@ static void *bzImage64_load(struct kimage *image, char *kernel, > sizeof(struct setup_data) + > RNG_SEED_LENGTH; > > +#ifdef CONFIG_OF_FLATTREE > + if (initial_boot_params) > + kbuf.bufsz += sizeof(struct setup_data) + > + fdt_totalsize(initial_boot_params); > +#endif > + > if (IS_ENABLED(CONFIG_IMA_KEXEC)) > kbuf.bufsz += sizeof(struct setup_data) + > sizeof(struct ima_setup_data); > @@ -537,7 +577,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel, > kbuf.bufsz += sizeof(struct setup_data) + > sizeof(struct kho_data); > > - params = kzalloc(kbuf.bufsz, GFP_KERNEL); > + params = kvzalloc(kbuf.bufsz, GFP_KERNEL); > if (!params) > return ERR_PTR(-ENOMEM); > efi_map_offset = params_cmdline_sz; > @@ -647,7 +687,7 @@ static void *bzImage64_load(struct kimage *image, char *kernel, > return ldata; > > out_free_params: > - kfree(params); > + kvfree(params); > return ERR_PTR(ret); > } > > @@ -659,7 +699,7 @@ static int bzImage64_cleanup(void *loader_data) > if (!ldata) > return 0; > > - kfree(ldata->bootparams_buf); > + kvfree(ldata->bootparams_buf); > ldata->bootparams_buf = NULL; > > return 0; > > base-commit: d7b8f8e20813f0179d8ef519541a3527e7661d3a > -- > 2.25.1 > Thanks Dave