From patchwork Tue Nov 14 15:32:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13455543 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 5D171C4167D for ; Tue, 14 Nov 2023 15:33:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ai+2JYWJC2lRZohn7yZdxmudBnIHJu/JGfbrF/igmps=; b=WzAAneF/BjuXuA Dysw/61KZy9mcmUsVrKf/5gnkY5ntp8+I6pH39qCs+RNtBKWF/VwZ6FTmUsH9ay4x42MTAQv/GyOn TMSRGaLv7kvzIt4nLLndbiGe5taQ4IyoXaX4Sy1BHCBeeCbNZA7MESlKCoC6+TGyyZEt/bjgvcYSY E71GUj5dNxBdYGSwiW/fI27Yvux0ChyNqZpo0TLp1RM1N0nwz49A6IgypEwkJ10o9m8mXjD9QL36n COOETFicwi/oyL/pijXqlmIlC7s5FzM5bDy3/7TcXj61YMtFxKyvd6q4DdGa1mQEqYSrrPyjSUZK8 RkTKBZBpGVTrdBr1g35A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r2vQ9-00GJwM-0g; Tue, 14 Nov 2023 15:33:45 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r2vPx-00GJhw-1R for linux-riscv@lists.infradead.org; Tue, 14 Nov 2023 15:33:37 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699976012; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uyeWVmLOn2JLlMGOiKTLkdbq3lsSPR6w1wGNV6RcYZE=; b=CbB85c5dfziyVrIJftQ5mf7vtw1jPt0FFFjka0aYQ8nB5bO9t60xVIrR0MKKB4A/pOYxr4 qvm0nX2nnQD/e2+6CRIFNyF1U9fyEkg7UwowESEKLuaBGI392rLmW6PDd4CrOomkU60ddq WIYSGQE6FJFuzXIQhr8eOtZB5Et2src= 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-329-vpv-XXKAOiq83ZmBq6vDFQ-1; Tue, 14 Nov 2023 10:33:30 -0500 X-MC-Unique: vpv-XXKAOiq83ZmBq6vDFQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 8B4BE3C02B55; Tue, 14 Nov 2023 15:33:03 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.112.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C7AE1C060AE; Tue, 14 Nov 2023 15:33:00 +0000 (UTC) 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, Baoquan He Subject: [PATCH 1/7] kexec_file: add kexec_file flag to control debug printing Date: Tue, 14 Nov 2023 23:32:47 +0800 Message-ID: <20231114153253.241262-2-bhe@redhat.com> In-Reply-To: <20231114153253.241262-1-bhe@redhat.com> References: <20231114153253.241262-1-bhe@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231114_073333_582902_16B8392D X-CRM114-Status: GOOD ( 16.05 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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. If '-d' is not specified, it regresses to pr_debug(). Signed-off-by: Baoquan He Signed-off-by: Baoquan He --- include/linux/kexec.h | 14 +++++++++++++- include/uapi/linux/kexec.h | 1 + kernel/kexec_file.c | 5 +++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 8227455192b7..189a6c5bec84 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -264,6 +264,18 @@ arch_kexec_apply_relocations(struct purgatory_info *pi, Elf_Shdr *section, return -ENOEXEC; } #endif + +extern bool kexec_file_dbg_print; + +#define kexec_dprintk(fmt, args...) \ + do { \ + if (kexec_file_dbg_print) \ + printk(KERN_INFO fmt, ##args); \ + else \ + printk(KERN_DEBUG fmt, ##args); \ + } while (0) + + #endif /* CONFIG_KEXEC_FILE */ #ifdef CONFIG_KEXEC_ELF @@ -403,7 +415,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) {