Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp28135rdb; Wed, 29 Nov 2023 18:40:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IHB3yg0/XXnr/VqXOav2Vor2DxRTvawQvvzSNNz35cK3TxY/wqNSLWA+2FdMTeUx9R4MQLO X-Received: by 2002:a05:6a21:62f:b0:18b:b97:cdf4 with SMTP id ll47-20020a056a21062f00b0018b0b97cdf4mr17853414pzb.3.1701312039892; Wed, 29 Nov 2023 18:40:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701312039; cv=none; d=google.com; s=arc-20160816; b=bavm5eck6ryBRfbFyOde/+rFF6JuX84hbE8GJzpZCfMurzjRcZ3e2vnXoaaCuALzeo 60ZKBH3uGDLoZOkAuTdMyroRXO8ifNWF2fVxrbDNmKlMFIpZ540jX6wNxdmsc48orD5n SitzRWrUnUbQlHh1Pj4BfnHymPJtY42DH+dUXZOFrRXxdLft0VPD2l+xXZdN4LQMiQz/ JtIXidbXCCCxtBTeEOcPnlzTYXEP9J+WRfmYmBccIM1457T+EJzIHc5GxWJsW0Uapv6n V9BfkY3xWXn30wgBZtJROOT5sohftlbR73NbLamCb7H2N5dQ1TWPI329iqkL1WSq0CMs vRSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mO1KBSR/aHS3/goavwyErIvJSA5uOL+z59IlmO49PfM=; fh=5UuzwTQm02ADEtrX0cYUVH8jtF0RwJiWGme68kV/Ltg=; b=kazdn3JNw0LFSUC4reP3Z+8ibkaklhm3GcALH9v5tlGsiMCnkF1mu6rCIX5ApPu7Rd iPiHFEwa+RaagobUsBAw5qlMNgJtbfUsFNWbQEv4zzEkgAH8LzDpFpQk9JlKPKMjdAir VQ8n73rxzFRnc0IpdoHE1dBlJi/a9KhNvSGcC6/CpJMq7v/OFpFlTZ3eASIyD/0h7uPB jwiFYSdxGIyM5kZvqrukGYNW4X2yQjLuJZDYFZEZbwM+XYaFhPAweY6RhGwjQyryRZZJ lBX4sOhcb5H7UOa6GOgikpwV7fv4XEy3ikomInURR84QkS+VdiCtVvvFvF9ElHiEqJfd kKeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S2pYnClS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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. [23.128.96.32]) by mx.google.com with ESMTPS id bj11-20020a056a02018b00b00577f4d85fdbsi289219pgb.548.2023.11.29.18.40.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 18:40:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=S2pYnClS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 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 804FA803A6E5; Wed, 29 Nov 2023 18:40:33 -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 S234943AbjK3CkN (ORCPT + 99 others); Wed, 29 Nov 2023 21:40:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231621AbjK3CkJ (ORCPT ); Wed, 29 Nov 2023 21:40:09 -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 3FF6ED6C for ; Wed, 29 Nov 2023 18:40:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1701312014; 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=mO1KBSR/aHS3/goavwyErIvJSA5uOL+z59IlmO49PfM=; b=S2pYnClSO+SAQCD/4aDOuKYpLjrWj/aHDhBt3nbUA9IyLLDRGKHVultTDPJaS0IYUWlwWL TevNszAxris0RnDhHlFKRpnzWuiWRrPlF4FX37jB+rP5xvc6SHi1G5AJu0UrAWzVGSEyHc ZxDoI4p2NYUjN1C6lZW6/dsGSibLasI= 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-680-1ydL33qHOmWMKqvsAfQbfA-1; Wed, 29 Nov 2023 21:40:07 -0500 X-MC-Unique: 1ydL33qHOmWMKqvsAfQbfA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 9933D3C11A05; Thu, 30 Nov 2023 02:40:06 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.113.121]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9023C2026D4C; Thu, 30 Nov 2023 02:40:02 +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, akpm@linux-foundation.org, joe@perches.com, nathan@kernel.org, Baoquan He Subject: [PATCH v3 1/7] kexec_file: add kexec_file flag to control debug printing Date: Thu, 30 Nov 2023 10:39:49 +0800 Message-ID: <20231130023955.5257-2-bhe@redhat.com> In-Reply-To: <20231130023955.5257-1-bhe@redhat.com> References: <20231130023955.5257-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Spam-Status: No, score=-0.9 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, 29 Nov 2023 18:40:33 -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. If '-d' is not specified, it regresses to pr_debug(). Signed-off-by: Baoquan He --- include/linux/kexec.h | 9 ++++++++- include/uapi/linux/kexec.h | 1 + kernel/kexec_core.c | 2 ++ kernel/kexec_file.c | 3 +++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/include/linux/kexec.h b/include/linux/kexec.h index 8227455192b7..400cb6c02176 100644 --- a/include/linux/kexec.h +++ b/include/linux/kexec.h @@ -403,7 +403,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; @@ -500,6 +500,13 @@ static inline int crash_hotplug_memory_support(void) { return 0; } static inline unsigned int crash_get_elfcorehdr_size(void) { return 0; } #endif +extern bool kexec_file_dbg_print; + +#define kexec_dprintk(fmt, ...) \ + printk("%s" fmt, \ + kexec_file_dbg_print ? KERN_INFO : KERN_DEBUG, \ + ##__VA_ARGS__) + #else /* !CONFIG_KEXEC_CORE */ struct pt_regs; struct task_struct; 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_core.c b/kernel/kexec_core.c index be5642a4ec49..f70bf3a7885c 100644 --- a/kernel/kexec_core.c +++ b/kernel/kexec_core.c @@ -52,6 +52,8 @@ atomic_t __kexec_lock = ATOMIC_INIT(0); /* Flag to indicate we are going to kexec a new kernel */ bool kexec_in_progress = false; +bool kexec_file_dbg_print; + int kexec_should_crash(struct task_struct *p) { /* diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index f9a419cd22d4..aca5dac74044 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -123,6 +123,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 +280,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