From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 5E2C928F520 for ; Wed, 30 Jul 2025 07:31:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753860693; cv=none; b=sGtvuHTVKdDRz7IE5nelNck7E2zLSiGhlMR6/DJohWIWH49dllSSSOv2mGW/6A1do1qZISoGp/CmweC2gSFh0Ln6gwl6R+VNVambRuz4j+Omw4UKdgv6B4m9A4dPyLdi8m96C5iJhTlzCMZGCabPF7P+jo8zaeiCH4HqA5q4LLI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753860693; c=relaxed/simple; bh=pGAOCVRw0BLj2G2xXBMzOn9p5X2PAw/oxgucy6qgMkQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=SGk3pQ9/mHb/NUJDQAWV/vNFr7CJHfbK3Ba5tmRQrEJygv9J1oWH6+gIxaQSYaaTcWrfCsd71cdATCIcAG+4+aIfsDJGZDbTOExuc8LAbSPc0w9bsV1DnoSdaIDNQN0275itjc8Z/icT/J/g1GSFwrt3jV5eBJPQWK8/7MAaGJw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ADW4/det; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ADW4/det" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1753860690; 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=ADW4/detI8pQGN9DQwpJsq8ehSnj+X/tdQI6gWuXiWYqjKuXS0cNEcqsWshkgwpkgQT4uz mtnUCK1fy4oE3l2WEymlNtDnicDuJW9aGhIF6lNbXdJK6OVl6YKFv4iGc57L5xDnVja/XF 0OCVfdBr5jYHP4OZO73cqr1R/Ojzbc4= 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> Precedence: bulk X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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