From patchwork Wed Jan 10 07:15:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Coiby Xu X-Patchwork-Id: 186697 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp627356dyi; Tue, 9 Jan 2024 23:16:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IHTdSWAKwxyiptMlgRcOQAxxCk9QdmD8ZLyP1JHNnBYmjm0eRrHxfKGfGpd5p6jnlt2XEfN X-Received: by 2002:a0d:e28e:0:b0:5d7:1940:7d7a with SMTP id l136-20020a0de28e000000b005d719407d7amr519683ywe.81.1704870988405; Tue, 09 Jan 2024 23:16:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704870988; cv=none; d=google.com; s=arc-20160816; b=uTHsMWxETmLfxnQpNg1bW9os0OvmqU9i+OV53Zzf9HH2DJVE9C3L+uJGw1MO+4KbG7 u4lN6oqEBiTVVORSaKqjPCoEbSr0mM5fh29Ft9YQdDvxZz3+f+TP0fYnIhoBW8PAF+Bm A3M3+TsdiVVYbhojNTKYIu9TqlceFCwpXQmVoOo8T2G1MXBfSxJLp6PPmzdP43O05jb/ Bmw8sbEKXzxy9OSFJJGiowOGLuYXITLlIot9r3kkdnFkXmPYYpPPkJ75QGPqz7qandxk R3UozlUs5XY4oudltmwM811pIi6mc5auxZ9882WEurDJ+pjz7EHbnLcV0dC8NM1TRTrs WN3w== 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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21776-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id m7-20020a0cdb87000000b00680f6edff79si3852110qvk.335.2024.01.09.23.16.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 23:16:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21776-ouuuleilei=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-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21776-ouuuleilei=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 368BF1C2569F for ; Wed, 10 Jan 2024 07:16:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3763D3EA73; Wed, 10 Jan 2024 07:15:48 +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_P_=2E_Berrang=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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787686801832651011 X-GMAIL-MSGID: 1787686801832651011 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"); } /*