Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1702325ybp; Fri, 11 Oct 2019 19:23:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqyvO5TXD+oYlFm0AKSFDtNbphitoRgZh2aM+AAe2BKurijyILPhJXsZF+Crg6aJU1CfKBIb X-Received: by 2002:a17:906:264f:: with SMTP id i15mr17235285ejc.333.1570847037060; Fri, 11 Oct 2019 19:23:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570847037; cv=none; d=google.com; s=arc-20160816; b=qUbMpS/v9EyZQKVOuPO6QSJo/d84YcxUDut6HfUZHKNGH1ExyEjnASbokj5+HA0oWI FfPKNUkQ6FxGuP4Fr4VthmkwBmpkRmYInzrT+SHqSVjxg9yq4saQ1V1RyqeQvn2XlUet sGkmJre88wlNEH14hdaO977+6nqjQlakr3voX+uVXIw4LihSBit9Ir+IwXDdHJvjxj/B eKJpLOBLUSBZBCIZmfHA/Vm186I6cyPXNciL/+G3PWc8Tb6XBsAyOBudqjrKBEckozKA hfndI5L71h4ANhYq0eexkLWE2/RgV5lAA3C/MqBZSIuPcF43rm672qV69p6JJWE5SZ5I k+jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=ekPRWwC91Y031wq3NE0Xbws6PmXaz1WqNmGbYgxGRtE=; b=nWdEjETNkVgwSgQJ9EmWExhPsxCkiGnNlJGy5D0aFdR+Ty4KUmYly058qQfAoNvjYz aH5EpIbe0zfOiDuBf/8eqtn+NELpyYDAybsCMAHkT4fCe9Md85Pt8s0X0BRcsJgFGlYb ZsgUZb7w3WtlyG/3q1tGLRAHrEm9Z9ERjONWG8sK9EIhr6b5nEZNSc+qg45ndjE9d5/z 5PEI+8I4B1o1ecNZjMKPQy9gD8n61uedJj3m7I8ubx5UlOI+VCTC1w60fMcbGh+yD+Kw gQ9r+d3ctBmEZXSckYErK+AokbIc2pAmWPuqGCY8/6oeP4B+UqR8d9cxuma3HzDTZFuJ 1oZA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w2si7679444edc.386.2019.10.11.19.23.33; Fri, 11 Oct 2019 19:23:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728429AbfJLCWD (ORCPT + 99 others); Fri, 11 Oct 2019 22:22:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56474 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726757AbfJLCWD (ORCPT ); Fri, 11 Oct 2019 22:22:03 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D6AF8309DEF0; Sat, 12 Oct 2019 02:22:02 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-12-50.pek2.redhat.com [10.72.12.50]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA6E910013D9; Sat, 12 Oct 2019 02:21:56 +0000 (UTC) From: Lianbo Jiang To: linux-kernel@vger.kernel.org Cc: tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, hpa@zytor.com, x86@kernel.org, bhe@redhat.com, dyoung@redhat.com, jgross@suse.com, dhowells@redhat.com, Thomas.Lendacky@amd.com, ebiederm@xmission.com, vgoyal@redhat.com, kexec@lists.infradead.org Subject: [PATCH 1/3 v3] x86/kdump: Fix 'kmem -s' reported an invalid freepointer when SME was active Date: Sat, 12 Oct 2019 10:21:38 +0800 Message-Id: <20191012022140.19003-2-lijiang@redhat.com> In-Reply-To: <20191012022140.19003-1-lijiang@redhat.com> References: <20191012022140.19003-1-lijiang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Sat, 12 Oct 2019 02:22:03 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204793 Kdump kernel will reuse the first 640k region because of some reasons, for example: the trampline and conventional PC system BIOS region may require to allocate memory in this area. Obviously, kdump kernel will also overwrite the first 640k region, therefore, kernel has to copy the contents of the first 640k area to a backup area, which is done in purgatory(), because vmcore may need the old memory. When vmcore is dumped, kdump kernel will read the old memory from the backup area of the first 640k area. Basically, the main reason should be clear, kernel does not correctly handle the first 640k region when SME is active, which causes that kernel does not properly copy these old memory to the backup area in purgatory(). Therefore, kdump kernel reads out the incorrect contents from the backup area when dumping vmcore. Finally, the phenomenon is as follow: [root linux]$ crash vmlinux /var/crash/127.0.0.1-2019-09-19-08\:31\:27/vmcore WARNING: kernel relocated [240MB]: patching 97110 gdb minimal_symbol values KERNEL: /var/crash/127.0.0.1-2019-09-19-08:31:27/vmlinux DUMPFILE: /var/crash/127.0.0.1-2019-09-19-08:31:27/vmcore [PARTIAL DUMP] CPUS: 128 DATE: Thu Sep 19 08:31:18 2019 UPTIME: 00:01:21 LOAD AVERAGE: 0.16, 0.07, 0.02 TASKS: 1343 NODENAME: amd-ethanol RELEASE: 5.3.0-rc7+ VERSION: #4 SMP Thu Sep 19 08:14:00 EDT 2019 MACHINE: x86_64 (2195 Mhz) MEMORY: 127.9 GB PANIC: "Kernel panic - not syncing: sysrq triggered crash" PID: 9789 COMMAND: "bash" TASK: "ffff89711894ae80 [THREAD_INFO: ffff89711894ae80]" CPU: 83 STATE: TASK_RUNNING (PANIC) crash> kmem -s|grep -i invalid kmem: dma-kmalloc-512: slab:ffffd77680001c00 invalid freepointer:a6086ac099f0c5a4 kmem: dma-kmalloc-512: slab:ffffd77680001c00 invalid freepointer:a6086ac099f0c5a4 crash> BTW: I also tried to fix the above problem in purgatory(), but there are too many restricts in purgatory() context, for example: i can't allocate new memory to create the identity mapping page table for SME situation. Currently, there are two places where the first 640k area is needed, the first one is in the find_trampoline_placement(), another one is in the reserve_real_mode(), and their content doesn't matter. To avoid the above error, when the crashkernel kernel command line option is specified, lets reserve the remain low 1MiB memory(after reserving real mode memroy) so that the allocated memory does not fall into the low 1MiB area, which makes us not to copy the first 640k content to a backup region in purgatory(). In addition, also need to clean all the code related to the backup region later. Signed-off-by: Lianbo Jiang --- arch/x86/realmode/init.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c index 7dce39c8c034..bf4c8ffc5ed9 100644 --- a/arch/x86/realmode/init.c +++ b/arch/x86/realmode/init.c @@ -34,6 +34,17 @@ void __init reserve_real_mode(void) memblock_reserve(mem, size); set_real_mode_mem(mem); + +#ifdef CONFIG_KEXEC_CORE + /* + * When the crashkernel option is specified, only use the low + * 1MiB for the real mode trampoline. + */ + if (strstr(boot_command_line, "crashkernel=")) { + memblock_reserve(0, SZ_1M); + pr_info("Reserving low 1MiB of memory for crashkernel\n"); + } +#endif /* CONFIG_KEXEC_CORE */ } static void __init setup_real_mode(void) -- 2.17.1