Received: by 2002:ac0:a591:0:0:0:0:0 with SMTP id m17-v6csp1127123imm; Thu, 5 Jul 2018 15:29:06 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfgng+kOPxLdUd1LBDz59Ii4nhsuFJ54YKWL9N4dz+xF/atBK5i7piWbGHHWHnEJRhtO4ly X-Received: by 2002:a63:8e41:: with SMTP id k62-v6mr2483196pge.187.1530829746182; Thu, 05 Jul 2018 15:29:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530829746; cv=none; d=google.com; s=arc-20160816; b=zcTJviCx2CLWwmoMwtwmRrrjdBoo0Yz+D5cIMAS83+6xABDSdS5YZqtjiGZjLIJ5N5 9fSQ4vP8DWl8aJvWMH11KauVpeljuBEdhDVFUEZg0WU9/f2Jw9ff5HnieYPkIaCVOwUi R09UTTYqqbuue3G1CIvuzbAgOKNlNpZwr5rGmClvFhqfHficQYwBiYOWi6NyIhDBVSc1 LB3ybdFMWNBJbI6kIK7+E2KFOLE8YtMxLWTv29VSvlDCPDMPZiym6OLgNkmA+tNSzaL8 7v+TboS8i0xMP2JwPoWK2PiWHb2VvPP1XOlDzQO3+ZNTCfz4P53XipyqiyUKGUdfzFuk 2KAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=UxRcbdE1oNw3BSXTwV9MezTNBrFXXmq8PRoRdtcey9Y=; b=m27mWeE3f1qLwjLL945ZjRteZIgKo2VyGPIxj1xEDYGvPEV/VEiXwbbsGnuvuJ8Bgf Aj0TmOJd/7sDepcKRL228pkNMz8QowFpyJevD6R4WSE1j4eU0U9tUYrc9hZdia9gSVMG a7q48qSSLHIb099Oh1mkDuc9UHbAxVaDI8Olqaf1f8MP/TgPaktg6CyZdxFNRFuTamxG jZIQavSZ7znnre0yWOfc1SjRbD0MLAgVODN3r/BjP8658b1N4v/Xayw1Jq0TMqi7iHQw Ir7XT0Dsx+dvDCMruN5xOXpza+nyhAofnBF+RBIyyc0/m8j5ys9VapDL19+jusU59YhM ZpTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UNHUYyC/"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h23-v6si6550514pgl.373.2018.07.05.15.28.51; Thu, 05 Jul 2018 15:29:06 -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; dkim=pass header.i=@linaro.org header.s=google header.b="UNHUYyC/"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753661AbeGEW1x (ORCPT + 99 others); Thu, 5 Jul 2018 18:27:53 -0400 Received: from mail-io0-f193.google.com ([209.85.223.193]:40379 "EHLO mail-io0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753471AbeGEW1w (ORCPT ); Thu, 5 Jul 2018 18:27:52 -0400 Received: by mail-io0-f193.google.com with SMTP id t135-v6so9174917iof.7 for ; Thu, 05 Jul 2018 15:27:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=UxRcbdE1oNw3BSXTwV9MezTNBrFXXmq8PRoRdtcey9Y=; b=UNHUYyC/GZ7B9mGYVO3SrpaonGRrTQ7hzelGJaCxV5ngUiY+ulIpoZX6ShsaGLUxCH o1h3BZ7/bCYVpd07CHCijjgZRFDwJQtpLRUYfMJah5Gu6MZB02KlrSc21VA5yM4xLmSg 9nU5DXTpipvl7sv7wnoQMJJeC5hCZLda+LEQ0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=UxRcbdE1oNw3BSXTwV9MezTNBrFXXmq8PRoRdtcey9Y=; b=DabEuQw8N6aHSmlGJCSlMAROGmAIHfQ9E2DTnKqwJg3JsHPoS8vjTGFo0MVCPi8bnj IXDBjQ+iVz6pd8ygP5r3dwEvgvVn7w2k6RIXBH231G4BB1lF5DIiPSAlVCrcH2IgH/l4 KlOlnN1F31x1n667eSFsf+josLrUwumcHbFjGBRxWzUJaYlWL8hwvWYfqTpHFAtjSEj0 dJs3MpDABGPyPmjXQHTRoOCvW2osfPBUdmrlAfX5a2n8zUnyop17sJ7hPbilku0DyywY U92mJmd4btbOFBhhlZbGFgBPvt/5pz0IADFcqSKTbXtuYUaNlIZuE/AVdxU3F4Vpxla0 tZRw== X-Gm-Message-State: AOUpUlFKb1h1NATkdmVrFzKV9kZ/kZv8WYXmQVk77ZH7w/Vg4HoorMe8 rI9yvPqjK64rlDe4ENEFeSoG4EeavSk3g+5dpK/+GQ== X-Received: by 2002:a6b:be83:: with SMTP id o125-v6mr6463073iof.173.1530829671458; Thu, 05 Jul 2018 15:27:51 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:bbc7:0:0:0:0:0 with HTTP; Thu, 5 Jul 2018 15:27:51 -0700 (PDT) In-Reply-To: <20180619064424.6642-5-takahiro.akashi@linaro.org> References: <20180619064424.6642-1-takahiro.akashi@linaro.org> <20180619064424.6642-5-takahiro.akashi@linaro.org> From: Ard Biesheuvel Date: Fri, 6 Jul 2018 00:27:51 +0200 Message-ID: Subject: Re: [PATCH v2 4/4] arm64: acpi: fix alignment fault in accessing ACPI To: AKASHI Takahiro Cc: Catalin Marinas , Will Deacon , Andrew Morton , "Baicar, Tyler" , Bhupesh Sharma , Dave Young , James Morse , Mark Rutland , Al Stone , Graeme Gregory , Hanjun Guo , Lorenzo Pieralisi , Sudeep Holla , linux-arm-kernel , Linux Kernel Mailing List , Kexec Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19 June 2018 at 08:44, AKASHI Takahiro wrote: > This is a fix against the issue that crash dump kernel may hang up > during booting, which can happen on any ACPI-based system with "ACPI > Reclaim Memory." > > (kernel messages after panic kicked off kdump) > (snip...) > Bye! > (snip...) > ACPI: Core revision 20170728 > pud=000000002e7d0003, *pmd=000000002e7c0003, *pte=00e8000039710707 > Internal error: Oops: 96000021 [#1] SMP > Modules linked in: > CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.14.0-rc6 #1 > task: ffff000008d05180 task.stack: ffff000008cc0000 > PC is at acpi_ns_lookup+0x25c/0x3c0 > LR is at acpi_ds_load1_begin_op+0xa4/0x294 > (snip...) > Process swapper/0 (pid: 0, stack limit = 0xffff000008cc0000) > Call trace: > (snip...) > [] acpi_ns_lookup+0x25c/0x3c0 > [] acpi_ds_load1_begin_op+0xa4/0x294 > [] acpi_ps_build_named_op+0xc4/0x198 > [] acpi_ps_create_op+0x14c/0x270 > [] acpi_ps_parse_loop+0x188/0x5c8 > [] acpi_ps_parse_aml+0xb0/0x2b8 > [] acpi_ns_one_complete_parse+0x144/0x184 > [] acpi_ns_parse_table+0x48/0x68 > [] acpi_ns_load_table+0x4c/0xdc > [] acpi_tb_load_namespace+0xe4/0x264 > [] acpi_load_tables+0x48/0xc0 > [] acpi_early_init+0x9c/0xd0 > [] start_kernel+0x3b4/0x43c > Code: b9008fb9 2a000318 36380054 32190318 (b94002c0) > ---[ end trace c46ed37f9651c58e ]--- > Kernel panic - not syncing: Fatal exception > Rebooting in 10 seconds.. > > (diagnosis) > * This fault is a data abort, alignment fault (ESR=0x96000021) > during reading out ACPI table. > * Initial ACPI tables are normally stored in system ram and marked as > "ACPI Reclaim memory" by the firmware. > * After the commit f56ab9a5b73c ("efi/arm: Don't mark ACPI reclaim > memory as MEMBLOCK_NOMAP"), those regions are differently handled > as they are "memblock-reserved", without NOMAP bit. > * So they are now excluded from device tree's "usable-memory-range" > which kexec-tools determines based on a current view of /proc/iomem. > * When crash dump kernel boots up, it tries to accesses ACPI tables by > mapping them with ioremap(), not ioremap_cache(), in acpi_os_ioremap() > since they are no longer part of mapped system ram. > * Given that ACPI accessor/helper functions are compiled in without > unaligned access support (ACPI_MISALIGNMENT_NOT_SUPPORTED), > any unaligned access to ACPI tables can cause a fatal panic. > > With this patch, acpi_os_ioremap() always honors memory attribute > information provided by the firmware (EFI) and retaining cacheability > allows the kernel safe access to ACPI tables. > > Signed-off-by: AKASHI Takahiro > Suggested-by: James Morse > Suggested-by: Ard Biesheuvel > Reported-by and Tested-by: Bhupesh Sharma Reviewed-by: Ard Biesheuvel > --- > arch/arm64/include/asm/acpi.h | 23 ++++++++++++++++------- > arch/arm64/kernel/acpi.c | 11 +++-------- > 2 files changed, 19 insertions(+), 15 deletions(-) > > diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h > index 0db62a4cbce2..68bc18cb2b85 100644 > --- a/arch/arm64/include/asm/acpi.h > +++ b/arch/arm64/include/asm/acpi.h > @@ -12,10 +12,12 @@ > #ifndef _ASM_ACPI_H > #define _ASM_ACPI_H > > +#include > #include > #include > > #include > +#include > #include > #include > > @@ -29,18 +31,22 @@ > > /* Basic configuration for ACPI */ > #ifdef CONFIG_ACPI > +pgprot_t __acpi_get_mem_attribute(phys_addr_t addr); > + > /* ACPI table mapping after acpi_permanent_mmap is set */ > static inline void __iomem *acpi_os_ioremap(acpi_physical_address phys, > acpi_size size) > { > + /* For normal memory we already have a cacheable mapping. */ > + if (memblock_is_map_memory(phys)) > + return (void __iomem *)__phys_to_virt(phys); > + > /* > - * EFI's reserve_regions() call adds memory with the WB attribute > - * to memblock via early_init_dt_add_memory_arch(). > + * We should still honor the memory's attribute here because > + * crash dump kernel possibly excludes some ACPI (reclaim) > + * regions from memblock list. > */ > - if (!memblock_is_memory(phys)) > - return ioremap(phys, size); > - > - return ioremap_cache(phys, size); > + return __ioremap(phys, size, __acpi_get_mem_attribute(phys)); > } > #define acpi_os_ioremap acpi_os_ioremap > > @@ -129,7 +135,10 @@ static inline const char *acpi_get_enable_method(int cpu) > * for compatibility. > */ > #define acpi_disable_cmcff 1 > -pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr); > +static inline pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr) > +{ > + return __acpi_get_mem_attribute(addr); > +} > #endif /* CONFIG_ACPI_APEI */ > > #ifdef CONFIG_ACPI_NUMA > diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c > index 7b09487ff8fb..ed46dc188b22 100644 > --- a/arch/arm64/kernel/acpi.c > +++ b/arch/arm64/kernel/acpi.c > @@ -18,6 +18,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -29,13 +30,9 @@ > > #include > #include > +#include > #include > > -#ifdef CONFIG_ACPI_APEI > -# include > -# include > -#endif > - > int acpi_noirq = 1; /* skip ACPI IRQ initialization */ > int acpi_disabled = 1; > EXPORT_SYMBOL(acpi_disabled); > @@ -239,8 +236,7 @@ void __init acpi_boot_table_init(void) > } > } > > -#ifdef CONFIG_ACPI_APEI > -pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr) > +pgprot_t __acpi_get_mem_attribute(phys_addr_t addr) > { > /* > * According to "Table 8 Map: EFI memory types to AArch64 memory > @@ -261,4 +257,3 @@ pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr) > return __pgprot(PROT_NORMAL_NC); > return __pgprot(PROT_DEVICE_nGnRnE); > } > -#endif > -- > 2.17.0 >