Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp882069pxf; Wed, 7 Apr 2021 14:03:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyE6qXCCTrb+S1Wm2exytKfNsyTYkwBv5mHcO3AfBhbi0jUviGOT1jrKkZUc9HQZIRFHgTZ X-Received: by 2002:a02:9718:: with SMTP id x24mr5611154jai.75.1617829432705; Wed, 07 Apr 2021 14:03:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617829432; cv=none; d=google.com; s=arc-20160816; b=NO/PVCOhk/rPaYHKpMa4unZTV3FJbbJAjvjXLEFtEDIScfEDs/0qdw5APV1clA2uvM jcFq5j64T3y82qZxYrvHdFgcpn4YgScsmNl36ZVwIVw30sr7GhUMm2S9Bu6yXbIdzLp4 CVT0R2zvt1ol8EKJ1NebrrqhmTjvI6U6aP8HFslVcyYezrT4LW5ih/a8HH8QnltHgu4J yBrTfNqvkyY0m7UugE7VbIhcj3l0mBp/28TdjghTLetaQBZZIAsw/cslnm6BjfctohhD 8uXsMAOTt0XFW55r0FUriau/BQhE290oB32+UOha2vSKEJC4C/PPj+YFQRPR+W2H0CKC uc8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=EtLqygi71vRkX7XbKNPu8aGXp0sRHC0Nw5lT5tmPTew=; b=BfT+G3lfoNOhnRNFenCcQ4HBg74TAUDWEHki97zA06hkar4bHsOFiMqdS3S/YOBjws eiIr/w3CL3dsNX6V1+FvwPgACGKahPrS6VFwRfOBvufkID0dLeyMIjLalFPLAPm3ONKh H9GfF1eXADnZStiFIEImmSvwD6FB/jTUC+d3xczj9QAkC8nRBuJ27X7M16+wlKkvBKNy ooV705EGx6UcApw+qHWfvSDLNBBfkhPyJBy7XgYvGMGsS8dc6F0Yut8DqKp21hEyC4I5 ydryCf6pCwiimVtyCeE6hLkPKytToJiDLRko8C1Mw9pguj7u9qFGTWSOF3lyddF7SPRG jStA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TarqHDJu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h30si16563366ila.131.2021.04.07.14.03.40; Wed, 07 Apr 2021 14:03:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TarqHDJu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352727AbhDGODu (ORCPT + 99 others); Wed, 7 Apr 2021 10:03:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:23149 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343988AbhDGODu (ORCPT ); Wed, 7 Apr 2021 10:03:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617804220; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=EtLqygi71vRkX7XbKNPu8aGXp0sRHC0Nw5lT5tmPTew=; b=TarqHDJuhJMXWnF3CUPuXx2MOI7QWeaterSh10VdbENogw3u/L+yzVwhnxy8J8j0ByG4/7 vSoT5bt4ZWjZe8dHj8OohffP9p5dPk+OUglxhgWjcikeleYKWi9Dh85qD8PTNDuQkHLJBx 12yVJyjPWyYLLPKGCzYXf0I3idJBbug= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-549-DdNpCKS7OUOPHLmVWQJPeg-1; Wed, 07 Apr 2021 10:03:36 -0400 X-MC-Unique: DdNpCKS7OUOPHLmVWQJPeg-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 97CB5801F98; Wed, 7 Apr 2021 14:03:34 +0000 (UTC) Received: from unused.redhat.com (ovpn-12-179.pek2.redhat.com [10.72.12.179]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABE99501DD; Wed, 7 Apr 2021 14:03:18 +0000 (UTC) From: Lianbo Jiang To: linux-kernel@vger.kernel.org Cc: linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, x86@kernel.org, ardb@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dvhart@infradead.org, andy@infradead.org, hpa@zytor.com, kexec@lists.infradead.org, bhe@redhat.com, dyoung@redhat.com Subject: [PATCH] x86/efi: Do not release sub-1MB memory regions when the crashkernel option is specified Date: Wed, 7 Apr 2021 22:03:16 +0800 Message-Id: <20210407140316.30210-1-lijiang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some sub-1MB memory regions may be reserved by EFI boot services, and the memory regions will be released later in the efi_free_boot_services(). Currently, always reserve all sub-1MB memory regions when the crashkernel option is specified, but unfortunately EFI boot services may have already reserved some sub-1MB memory regions before the crash_reserve_low_1M() is called, which makes that the crash_reserve_low_1M() only own the remaining sub-1MB memory regions, not all sub-1MB memory regions, because, subsequently EFI boot services will free its own sub-1MB memory regions. Eventually, DMA will be able to allocate memory from the sub-1MB area and cause the following error: crash> kmem -s |grep invalid kmem: dma-kmalloc-512: slab: ffffd52c40001900 invalid freepointer: ffff9403c0067300 kmem: dma-kmalloc-512: slab: ffffd52c40001900 invalid freepointer: ffff9403c0067300 crash> vtop ffff9403c0067300 VIRTUAL PHYSICAL ffff9403c0067300 67300 --->The physical address falls into this range [0x0000000000063000-0x000000000008efff] kernel debugging log: ... [ 0.008927] memblock_reserve: [0x0000000000010000-0x0000000000013fff] efi_reserve_boot_services+0x85/0xd0 [ 0.008930] memblock_reserve: [0x0000000000063000-0x000000000008efff] efi_reserve_boot_services+0x85/0xd0 ... [ 0.009425] memblock_reserve: [0x0000000000000000-0x00000000000fffff] crash_reserve_low_1M+0x2c/0x49 ... [ 0.010586] Zone ranges: [ 0.010587] DMA [mem 0x0000000000001000-0x0000000000ffffff] [ 0.010589] DMA32 [mem 0x0000000001000000-0x00000000ffffffff] [ 0.010591] Normal [mem 0x0000000100000000-0x0000000c7fffffff] [ 0.010593] Device empty ... [ 8.814894] __memblock_free_late: [0x0000000000063000-0x000000000008efff] efi_free_boot_services+0x14b/0x23b [ 8.815793] __memblock_free_late: [0x0000000000010000-0x0000000000013fff] efi_free_boot_services+0x14b/0x23b Do not release sub-1MB memory regions even though they are reserved by EFI boot services, so that always reserve all sub-1MB memory regions when the crashkernel option is specified. Signed-off-by: Lianbo Jiang --- arch/x86/platform/efi/quirks.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/x86/platform/efi/quirks.c b/arch/x86/platform/efi/quirks.c index 67d93a243c35..637f932c4fd4 100644 --- a/arch/x86/platform/efi/quirks.c +++ b/arch/x86/platform/efi/quirks.c @@ -18,6 +18,7 @@ #include #include #include +#include #define EFI_MIN_RESERVE 5120 @@ -303,6 +304,19 @@ void __init efi_arch_mem_reserve(phys_addr_t addr, u64 size) */ static __init bool can_free_region(u64 start, u64 size) { + /* + * Some sub-1MB memory regions may be reserved by EFI boot + * services, and these memory regions will be released later + * in the efi_free_boot_services(). + * + * Do not release sub-1MB memory regions even though they are + * reserved by EFI boot services, because, always reserve all + * sub-1MB memory when the crashkernel option is specified. + */ + if (cmdline_find_option(boot_command_line, "crashkernel", NULL, 0) > 0 + && (start + size < (1<<20))) + return false; + if (start + size > __pa_symbol(_text) && start <= __pa_symbol(_end)) return false; -- 2.17.1