Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5117628rdb; Tue, 12 Dec 2023 21:58:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJalYAVSfoaGCq8el3Qb94Tom8L8U6hSk2bmULU5YBZf/nsW1WSRLAQc6/6+z7tXhPR1Yz X-Received: by 2002:a05:6870:c98a:b0:1fa:f63a:13db with SMTP id hi10-20020a056870c98a00b001faf63a13dbmr9734985oab.51.1702447122308; Tue, 12 Dec 2023 21:58:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702447122; cv=none; d=google.com; s=arc-20160816; b=LSMVW5RqOIvRKun5Q9xkzgPCTLNCtJ5UK0sV6qWbD6M1em5gbuniO/I2Eruh/2liia IS/E2h0foabNRLPm6YYSEsKuOlidkQjSOYf04rhImuBjiF0xnqBQfIHMUWMw3RDdaEm6 E/bSNlOzyF9pdH7RM+SwGbcLHqjx/XuUhiJNTMkRN2gDaMeqX9HqsJ9XPHHtWkaPeQ6T VT6QfjyUWmPcn2sfS1KN9b2WyAoHb+KOGfRiIfeUJkkpOPl80Zxs1SBgL6WEo3OwMvQ/ nUFGyQK/do5c6LFMtJQCz05ALq/2FyDLOHemF6iroZXJnaBJQbno1ghzk1OV2wpC4V7Q QO3g== 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=nPOqcDOuxoODL3+Npm5GEBG1XQ606eHvq/icyslsljY=; fh=Hp23/yTs1prFnRvQlck2+XsDI7iq9YE2GFKxDKXVk2c=; b=rqJEni09OrHDQ4De8NlStzUruIpKcM4oi+2Yam8HgDWfe2eIfmzsds/bTcp5OPDRSB LWHNBYnTNLu4u0W/wjsWml8GmY73n1MHvj59sGvE8/Ys45PvZwKOUvcaIZWaryDSBWTk OG6C6Mi65UxMy5v8jSYID5NF2U8kBu3EPFhlfETxw7YnKHPAj/r1QpP7DQMhMVzIXgkP 1NcIrlUn0wx3F7EPltEnjRtDvaGCWP7T9ozYllTtjq4odzVb44eeSV4kG6CAaQ3EOUSQ xgoKKM+r6fo6iI2EtVBMphxdH1ZLrp2pTRSD2P0bUqxl3RfNitPo8pswFXXrYlTbclqc z4NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="KPDzaq/J"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id x37-20020a631725000000b005855f67e491si9156739pgl.696.2023.12.12.21.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 21:58:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="KPDzaq/J"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 9C7C8812E357; Tue, 12 Dec 2023 21:58:39 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235253AbjLMF6K (ORCPT + 99 others); Wed, 13 Dec 2023 00:58:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229476AbjLMF6H (ORCPT ); Wed, 13 Dec 2023 00:58:07 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A62BDB for ; Tue, 12 Dec 2023 21:58:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702447092; 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=nPOqcDOuxoODL3+Npm5GEBG1XQ606eHvq/icyslsljY=; b=KPDzaq/JPfGkxG4tJdmgoTQsmi+gnNgAW2aNXd97QqYtZaG0TDdVfDtPvjVWpv9Xe7Tx/F 9f8Q6JfJOHGkXwdwVLP8G2FK4LabuvTDcO4/6yMUBibl16R+u20ixMXC67NtoevH0/AtPq CqFp6aqPBnSxjAnHT0clr0ucrtkE1nU= 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-619-EpFdCEBxPSqFGEgPWPjEqQ-1; Wed, 13 Dec 2023 00:58:08 -0500 X-MC-Unique: EpFdCEBxPSqFGEgPWPjEqQ-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 CD5203C40B50; Wed, 13 Dec 2023 05:58:07 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (unknown [10.72.116.83]) by smtp.corp.redhat.com (Postfix) with ESMTP id 27E9B1C060AF; Wed, 13 Dec 2023 05:58:01 +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, conor@kernel.org, Baoquan He Subject: [PATCH v4 2/7] kexec_file: print out debugging message if required Date: Wed, 13 Dec 2023 13:57:42 +0800 Message-ID: <20231213055747.61826-3-bhe@redhat.com> In-Reply-To: <20231213055747.61826-1-bhe@redhat.com> References: <20231213055747.61826-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.7 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 pete.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 (pete.vger.email [0.0.0.0]); Tue, 12 Dec 2023 21:58:39 -0800 (PST) Then when specifying '-d' for kexec_file_load interface, loaded locations of kernel/initrd/cmdline etc can be printed out to help debug. Here replace pr_debug() with the newly added kexec_dprintk() in kexec_file loading related codes. And also print out type/start/head of kimage and flags to help debug. Signed-off-by: Baoquan He --- kernel/crash_core.c | 8 +++++--- kernel/kexec_file.c | 11 ++++++++--- security/integrity/ima/ima_kexec.c | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/kernel/crash_core.c b/kernel/crash_core.c index efe87d501c8c..380d0d3acc7b 100644 --- a/kernel/crash_core.c +++ b/kernel/crash_core.c @@ -551,9 +551,11 @@ int crash_prepare_elf64_headers(struct crash_mem *mem, int need_kernel_map, phdr->p_filesz = phdr->p_memsz = mend - mstart + 1; phdr->p_align = 0; ehdr->e_phnum++; - pr_debug("Crash PT_LOAD ELF header. phdr=%p vaddr=0x%llx, paddr=0x%llx, sz=0x%llx e_phnum=%d p_offset=0x%llx\n", - phdr, phdr->p_vaddr, phdr->p_paddr, phdr->p_filesz, - ehdr->e_phnum, phdr->p_offset); +#ifdef CONFIG_KEXEC_FILE + kexec_dprintk("Crash PT_LOAD ELF header. phdr=%p vaddr=0x%llx, paddr=0x%llx, sz=0x%llx e_phnum=%d p_offset=0x%llx\n", + phdr, phdr->p_vaddr, phdr->p_paddr, phdr->p_filesz, + ehdr->e_phnum, phdr->p_offset); +#endif phdr++; } diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index aca5dac74044..76de1ac7c424 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -204,6 +204,8 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, if (ret < 0) return ret; image->kernel_buf_len = ret; + kexec_dprintk("kernel: %p kernel_size: %#lx\n", + image->kernel_buf, image->kernel_buf_len); /* Call arch image probe handlers */ ret = arch_kexec_kernel_image_probe(image, image->kernel_buf, @@ -387,13 +389,14 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd, if (ret) goto out; + kexec_dprintk("nr_segments = %lu\n", image->nr_segments); for (i = 0; i < image->nr_segments; i++) { struct kexec_segment *ksegment; ksegment = &image->segment[i]; - pr_debug("Loading segment %d: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n", - i, ksegment->buf, ksegment->bufsz, ksegment->mem, - ksegment->memsz); + kexec_dprintk("segment[%d]: buf=0x%p bufsz=0x%zx mem=0x%lx memsz=0x%zx\n", + i, ksegment->buf, ksegment->bufsz, ksegment->mem, + ksegment->memsz); ret = kimage_load_segment(image, &image->segment[i]); if (ret) @@ -406,6 +409,8 @@ SYSCALL_DEFINE5(kexec_file_load, int, kernel_fd, int, initrd_fd, if (ret) goto out; + kexec_dprintk("kexec_file_load: type:%u, start:0x%lx head:0x%lx flags:0x%lx\n", + image->type, image->start, image->head, flags); /* * Free up any temporary buffers allocated which are not needed * after image has been loaded diff --git a/security/integrity/ima/ima_kexec.c b/security/integrity/ima/ima_kexec.c index ad133fe120db..dadc1d138118 100644 --- a/security/integrity/ima/ima_kexec.c +++ b/security/integrity/ima/ima_kexec.c @@ -129,8 +129,8 @@ void ima_add_kexec_buffer(struct kimage *image) image->ima_buffer_size = kexec_segment_size; image->ima_buffer = kexec_buffer; - pr_debug("kexec measurement buffer for the loaded kernel at 0x%lx.\n", - kbuf.mem); + kexec_dprintk("kexec measurement buffer for the loaded kernel at 0x%lx.\n", + kbuf.mem); } #endif /* IMA_KEXEC */ -- 2.41.0