Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp807841rdd; Tue, 9 Jan 2024 23:16:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IH11gww2raRoTeuFF7mpaO3vM6Y1A+PXuOn2wv4WlI5GJt+Ut+3hT9KG+4d5aHFG7Vjszfw X-Received: by 2002:a05:620a:b0f:b0:783:1497:156 with SMTP id t15-20020a05620a0b0f00b0078314970156mr590324qkg.79.1704870971500; Tue, 09 Jan 2024 23:16:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704870971; cv=none; d=google.com; s=arc-20160816; b=0CP6JDdhLxehhztypfhbaxZ1A/uh7MRqUggORwJgM/P11kBMPyl2tN+frtR8UNpk4C xp4TnMFNR9yR3vCweKm4xxdaVYaauoS4A6TXtPJnogYBiXJSAQRh3if93ZPcNBI66IXK G0udhkBJf9CrBF8TvLXThZOrIvGZmRdDw9WL607AOxULRx2kwmo2G2Qpp6RfxKBeXRsY pMq5DYYkbH+lC2EYwaMNRfN0Y8+My5JOiyn2rr2nvVRsHHIQ54pcFsxi2dpHBkamxmhJ 6A9EYXmP8dimo5XA6r6OG7uHL88+OTlUAzA8hy7KSIrfZpZBXOVIF/hoM8mL4HyX8isG +Fdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=tIMuati7cTP1ekV5ZbT9f3EKmgfJPaZbTXabrZEOoZs=; fh=0CnQcBBpPPCzbO2LVNr7a4xtuL8tReXWok6+u5weL08=; b=MIp6Mkwz6iLqsfKbRDP0wz/2hjRKWldHddNJmN8T5kpN3/YgP5Mmf5cdF2NPq4EGKx l2KfsjpoheSYQe45s9v0I781dFwSHkYSz1JV/yiPj50RxuOMWhBn/hwefQ7EZsGBVOQP rwKY9i5kFXQ0u7mjR+fbxQI3i0KsfB6hWvU7WJlqhD2znSfTTyl0p7K8e2C4UCZaQr2U HQHrqeRpFBZCXWYZuzP6ykxQQp9rR0uBVZJt88RcDLWAGwV1QX5kOA3hiPePSGqaNw5E oyYoIFe/vtEj6UhlsKEDzuSq1MYFMxbQAV4MQqR9UB1dfeltJjo1SNtTWU0Ew3/MFZCa pLYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Dg+Yxi/0"; spf=pass (google.com: domain of linux-kernel+bounces-21776-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21776-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id bk26-20020a05620a1a1a00b007831b72d6c1si3754628qkb.247.2024.01.09.23.16.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 23:16:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21776-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="Dg+Yxi/0"; spf=pass (google.com: domain of linux-kernel+bounces-21776-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21776-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 452211C25686 for ; Wed, 10 Jan 2024 07:16:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3DB8C3DBB7; Wed, 10 Jan 2024 07:15:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Dg+Yxi/0" 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 B92B43C46A for ; Wed, 10 Jan 2024 07:15:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704870942; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tIMuati7cTP1ekV5ZbT9f3EKmgfJPaZbTXabrZEOoZs=; b=Dg+Yxi/06TuSt2mOWoR+U+FuLjCwmJcKyuk+p7yCBRJlzP+gYO8B8fjfGGVOuOKrIw2U7W 0ut7b2KPu1/ETwzv9JvzgCvhSb0lZpvnVy8NKct0GXpgkh2/5+I4q4T7vGPIElGTU/zf/J 5YHIWHYaW9vssqVkPRSm32W4ttZwQoU= Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-Vj_YWPS1NXGPaUOF6IRDww-1; Wed, 10 Jan 2024 02:15:41 -0500 X-MC-Unique: Vj_YWPS1NXGPaUOF6IRDww-1 Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3bbf47262ccso4677241b6e.1 for ; Tue, 09 Jan 2024 23:15:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704870941; x=1705475741; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tIMuati7cTP1ekV5ZbT9f3EKmgfJPaZbTXabrZEOoZs=; b=wkpwOtjhU5n9U2nuPKWc3nhUdEQl93FeqDSRGPrD1BdrsiDnea7UrJ8Nk4uZDV/Jql aMDY7e8Ms4s6EE93Ike67St+T8kbynUjs50PZtFXq4ofeB9YK4E+X+eSTAzuOQuC9FI5 s+7gLRzMuU8nOcNEdHod3d/KqPe3VUTnCg1u7C0ziuUg34hsVPhpw2Gsh6G1ss4ZnXgg lr5jVJegl/BvYZ9ZPsulh3HUXBwRkuUyeKAVRWtjdHbewOMZiGAwbooalXYf/nPjbt29 5/k3G3KgnOzMWO5cNRpyHWdoNOlK05g0EyaAaE/dr4E/cCWkx7cqCGUqFekvuO50oGwo +sXw== X-Gm-Message-State: AOJu0YwSiDSJjxSfwVnp3sj8gSM6JuWHaQUKmYwrem5wb79b0aJLmQHy yl5v/iLsQduZeBliDNTUNW56VmaOQ0Mr/UxZoiApHzw6USIN0K1EnblP48Xt13Rz+p1QwNUPasA CURajqakj+7Xufh9f0ejOQ9U837Tm87jW X-Received: by 2002:a05:6358:1aaf:b0:170:efd3:2d03 with SMTP id gm47-20020a0563581aaf00b00170efd32d03mr362969rwb.24.1704870940766; Tue, 09 Jan 2024 23:15:40 -0800 (PST) X-Received: by 2002:a05:6358:1aaf:b0:170:efd3:2d03 with SMTP id gm47-20020a0563581aaf00b00170efd32d03mr362951rwb.24.1704870940380; Tue, 09 Jan 2024 23:15:40 -0800 (PST) Received: from localhost ([43.228.180.230]) by smtp.gmail.com with ESMTPSA id q14-20020a17090ac10e00b0028d0c8c9d37sm751199pjt.22.2024.01.09.23.15.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 23:15:40 -0800 (PST) From: Coiby Xu To: kexec@lists.infradead.org Cc: Ondrej Kozina , Milan Broz , Thomas Staudt , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Kairui Song , dm-devel@redhat.com, Jan Pazdziora , Pingfan Liu , Baoquan He , Dave Young , linux-kernel@vger.kernel.org, x86@kernel.org, Dave Hansen , Vitaly Kuznetsov , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH v2 4/5] x86/crash: pass the dm crypt key to kdump kernel Date: Wed, 10 Jan 2024 15:15:19 +0800 Message-ID: <20240110071522.1308935-5-coxu@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240110071522.1308935-1-coxu@redhat.com> References: <20240110071522.1308935-1-coxu@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 1st kernel will build up the kernel command parameter dmcryptkey as similar to elfcorehdr to pass the memory address of the stored info of dm crypt key to kdump kernel. Signed-off-by: Coiby Xu --- arch/x86/kernel/crash.c | 15 ++++++++++++++- arch/x86/kernel/kexec-bzimage64.c | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c index c92d88680dbf..69e1090f01bc 100644 --- a/arch/x86/kernel/crash.c +++ b/arch/x86/kernel/crash.c @@ -262,6 +262,7 @@ static int memmap_exclude_ranges(struct kimage *image, struct crash_mem *cmem, unsigned long long mend) { unsigned long start, end; + int r; cmem->ranges[0].start = mstart; cmem->ranges[0].end = mend; @@ -270,7 +271,19 @@ static int memmap_exclude_ranges(struct kimage *image, struct crash_mem *cmem, /* Exclude elf header region */ start = image->elf_load_addr; end = start + image->elf_headers_sz - 1; - return crash_exclude_mem_range(cmem, start, end); + r = crash_exclude_mem_range(cmem, start, end); + + if (r) + return r; + + /* Exclude dm crypt key region */ + if (image->dm_crypt_key_addr) { + start = image->dm_crypt_key_addr; + end = start + image->dm_crypt_key_sz - 1; + return crash_exclude_mem_range(cmem, start, end); + } + + return r; } /* Prepare memory map for crash dump kernel */ diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c index a61c12c01270..6e8adfe0b417 100644 --- a/arch/x86/kernel/kexec-bzimage64.c +++ b/arch/x86/kernel/kexec-bzimage64.c @@ -76,6 +76,10 @@ static int setup_cmdline(struct kimage *image, struct boot_params *params, if (image->type == KEXEC_TYPE_CRASH) { len = sprintf(cmdline_ptr, "elfcorehdr=0x%lx ", image->elf_load_addr); + + if (image->dm_crypt_key_addr != 0) + len += sprintf(cmdline_ptr + len, + "dmcryptkey=0x%lx ", image->dm_crypt_key_addr); } memcpy(cmdline_ptr + len, cmdline, cmdline_len); cmdline_len += len; @@ -433,6 +437,9 @@ static void *bzImage64_load(struct kimage *image, char *kernel, ret = crash_load_segments(image); if (ret) return ERR_PTR(ret); + ret = crash_load_dm_crypt_key(image); + if (ret) + pr_debug("Either no dm crypt key or error to retrieve the dm crypt key\n"); } /* -- 2.43.0