Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2568882rdb; Wed, 15 Nov 2023 04:51:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IGP2vvG0PPMynu8UX/MhtZk0KVt1FW/vTIPpoM+AlirHwHF9uYjTCTyd/j7MVV4JVT98OCr X-Received: by 2002:a92:ca4e:0:b0:359:506f:c0e4 with SMTP id q14-20020a92ca4e000000b00359506fc0e4mr20673516ilo.17.1700052703873; Wed, 15 Nov 2023 04:51:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700052703; cv=none; d=google.com; s=arc-20160816; b=Um6McoHGZi9vojZ/2KOjWuaH85T9AtZHOKHc9OE0C7sNPkIMs36koN7LzYwFRLUrty ly4CJurWODX1ozeQ0SLshume2urEiyeNb3OvKhgazaI9SkmMkrEZ/kINy2JODzEpYW+a YZDCbWeNH2jTG+T/wclV6T66iZd0hIoSVYQlhvNLeebt3zaHG0+UFkT5B6enEocAKoQq UxSOcu5yodm6WmcuM1Iiv7pWb4EnmZjSaLAXvz840u1WPSX9+CSHMaqJLoEdGQRbzsk8 D6OnDm892ItvXoPqrhy7Mneo45becmC3MCUXP0HeRzT1dhf6YNKcUtfE3mTZEmCmhmTU +uIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ehFjwhsPPcv7nimSjR09jzg4Dqe1DEZTTTAxghtYd8o=; fh=qVUpd03q1exVH5msKuDam0wUqGacbWDGme4jnKJ1eWE=; b=Z4G4pmMoiFZGoFqaKTRF2lUOyCiqtY09vMTFDcOC4GgdFq7k/u0tSm1UhLf9rdHGJs 2O49Z4UhnJcWv4zXIBEXGXdNvml0u3z38AHzx5yCuFCYKN5CbrHYqKPdsyJx081wpd/5 7YfH6hCgS86IHL25Zx7b5Jyw74K8XXx+i7Ss95Gl4qKnobjX/oZ5gxRYQZMeQkA9Ot3s 1dmUApolfdcgN4od90w7/rqfyXi2K95TCinyu3qOlvtgsf+383lhPT2JmzE7Q9/GBmcr IL7ArvvjX/rRXy5iopUXFUkwa6bBD9b3JgHlK7gfBE1Ww87s3fOue4MNmAHhKhLuXhXv sM3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Bbx7OUie; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id q1-20020a056a00150100b006be322191desi10296459pfu.112.2023.11.15.04.51.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 04:51:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Bbx7OUie; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 872A08029E2E; Wed, 15 Nov 2023 04:51:34 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343686AbjKOMvV (ORCPT + 99 others); Wed, 15 Nov 2023 07:51:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234924AbjKOMvT (ORCPT ); Wed, 15 Nov 2023 07:51:19 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B84B11C for ; Wed, 15 Nov 2023 04:51:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700052675; 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=ehFjwhsPPcv7nimSjR09jzg4Dqe1DEZTTTAxghtYd8o=; b=Bbx7OUieKyLhEbhg8f/de496HWsERiEdaT/xSroutd79BNgLmrtUdInZAZwKopz82ZGCH+ T7aIvJV8lnSKPeJwshbok2E6AT9oaPJNbCrQ0VCxtNheaq78YvLZnHy3RNTjURQg4yYQoC xLRzSkVvzkBTK9RJK6g7llQD89VSqa8= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-378-LR_rUWiCNDKtUhiOdXXDbA-1; Wed, 15 Nov 2023 07:51:13 -0500 X-MC-Unique: LR_rUWiCNDKtUhiOdXXDbA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9AB1C1C068CA; Wed, 15 Nov 2023 12:51:10 +0000 (UTC) Received: from localhost (unknown [10.72.112.9]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E5CD41121307; Wed, 15 Nov 2023 12:51:09 +0000 (UTC) Date: Wed, 15 Nov 2023 20:51:06 +0800 From: Baoquan He To: linux-kernel@vger.kernel.org Cc: kexec@lists.infradead.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-parisc@vger.kernel.org Subject: Re: [PATCH v2 1/7] kexec_file: add kexec_file flag to control debug printing Message-ID: References: <20231114153253.241262-1-bhe@redhat.com> <20231114153253.241262-2-bhe@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231114153253.241262-2-bhe@redhat.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 15 Nov 2023 04:51:34 -0800 (PST) When specifying 'kexec -c -d', kexec_load interface will print loading information, e.g the regions where kernel/initrd/purgatory/cmdline are put, the memmap passed to 2nd kernel taken as system RAM ranges, and printing all contents of struct kexec_segment, etc. These are very helpful for analyzing or positioning what's happening when kexec/kdump itself failed. The debugging printing for kexec_load interface is made in user space utility kexec-tools. Whereas, with kexec_file_load interface, 'kexec -s -d' print nothing. Because kexec_file code is mostly implemented in kernel space, and the debugging printing functionality is missed. It's not convenient when debugging kexec/kdump loading and jumping with kexec_file_load interface. Now add KEXEC_FILE_DEBUG to kexec_file flag to control the debugging message printing. And add global variable kexec_file_dbg_print and macro kexec_dprintk() to facilitate the printing. This is a preparation, later kexec_dprintk() will be used to replace the existing pr_debug(). Once 'kexec -s -d' is specified, it will print out kexec/kdump loading information at KERN_INFO level. If '-d' is not specified, it regresses to print message at KERN_DEBUG level. Signed-off-by: Baoquan He --- v1->v2: - Rewrite the kexec_dprintk() macro as Joe suggested to reduce kernel text size. include/linux/kexec.h | 10 +++++++++- include/uapi/linux/kexec.h | 1 + kernel/kexec_file.c | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 8227455192b7..66997efe36f1 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -264,6 +264,14 @@ arch_kexec_apply_relocations(struct purgatory_info *pi, Elf_Shdr *section, return -ENOEXEC; } #endif + +extern bool kexec_file_dbg_print; + +#define kexec_dprintk(fmt, ...) \ + printk("%s" fmt, \ + kexec_file_dbg_print ? KERN_INFO : KERN_DEBUG, \ + ##__VA_ARGS__) + #endif /* CONFIG_KEXEC_FILE */ #ifdef CONFIG_KEXEC_ELF @@ -403,7 +411,7 @@ bool kexec_load_permitted(int kexec_image_type); /* List of defined/legal kexec file flags */ #define KEXEC_FILE_FLAGS (KEXEC_FILE_UNLOAD | KEXEC_FILE_ON_CRASH | \ - KEXEC_FILE_NO_INITRAMFS) + KEXEC_FILE_NO_INITRAMFS | KEXEC_FILE_DEBUG) /* flag to track if kexec reboot is in progress */ extern bool kexec_in_progress; diff --git a/include/uapi/linux/kexec.h b/include/uapi/linux/kexec.h index 01766dd839b0..c17bb096ea68 100644 --- a/include/uapi/linux/kexec.h +++ b/include/uapi/linux/kexec.h @@ -25,6 +25,7 @@ #define KEXEC_FILE_UNLOAD 0x00000001 #define KEXEC_FILE_ON_CRASH 0x00000002 #define KEXEC_FILE_NO_INITRAMFS 0x00000004 +#define KEXEC_FILE_DEBUG 0x00000008 /* These values match the ELF architecture values. * Unless there is a good reason that should continue to be the case. diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index f9a419cd22d4..4c35500ae40a 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -38,6 +38,8 @@ void set_kexec_sig_enforced(void) } #endif +bool kexec_file_dbg_print; + static int kexec_calculate_store_digests(struct kimage *image); /* Maximum size in bytes for kernel/initrd files. */ @@ -123,6 +125,8 @@ void kimage_file_post_load_cleanup(struct kimage *image) */ kfree(image->image_loader_data); image->image_loader_data = NULL; + + kexec_file_dbg_print = false; } #ifdef CONFIG_KEXEC_SIG @@ -278,6 +282,7 @@ kimage_file_alloc_init(struct kimage **rimage, int kernel_fd, if (!image) return -ENOMEM; + kexec_file_dbg_print = !!(flags & KEXEC_FILE_DEBUG); image->file_mode = 1; if (kexec_on_panic) { -- 2.41.0