From patchwork Fri Sep 21 22:16:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10611033 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E20D14BD for ; Fri, 21 Sep 2018 22:18:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 203462D238 for ; Fri, 21 Sep 2018 22:18:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1454C2D2DB; Fri, 21 Sep 2018 22:18:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6873F2D238 for ; Fri, 21 Sep 2018 22:18:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 422928E0018; Fri, 21 Sep 2018 18:18:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3CF158E0001; Fri, 21 Sep 2018 18:18:16 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 296CF8E0018; Fri, 21 Sep 2018 18:18:16 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by kanga.kvack.org (Postfix) with ESMTP id F3E818E0001 for ; Fri, 21 Sep 2018 18:18:15 -0400 (EDT) Received: by mail-ot1-f69.google.com with SMTP id q3-v6so13807674otl.14 for ; Fri, 21 Sep 2018 15:18:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=icR6tn2J9gdMnwoNflR020W7wn+Aa33OrG5orolU8LM=; b=J9QTHMAroFRI/8CyBYqpLXeWglEAbUQM0GWhPk870iB23od84GvzXncruq6HAKaPKA 19D2wI1eHR4PVLqxnK1MmWobN8Au2nhri91JYr8MKx4ZX1eHLHnF/LUBrDaa2RfpHlcF Az3jPQrEP9ZDDvOGTSQfhXrbm5AaIWIa7l89ZJfdXErrpA8jo06FmEGmoBZ5EQ8QffBI aCiev2NWrxnT3LvkrwXOnFwpcHtuToTLO/3EVZbmxYg0iGra1nI/PUtLC/lBZXRzCS0D Bn/Xk52VRWEa6QQH6lL89IQMfkrUlJ/EwkDhR4h+rVnw8c1/Q8d7D4kIlhAuAb9q33wG Jwjw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: APzg51BqDmG54qP9sEwJMIimEp3TvWK36jDib5W6JZXHyKFL4GnlqzUh 0Kk+e2raXXFZs63dTNI2tezkI6Ze0Cy/1ZS8Wv7UWeNiI94QbpUvDyrFGtbnZ47OzAG9dp++Tzt 7JTn7tOIuDvIFzpa/4DRrIT8N+W+hO0xxHTE4gPmD5u+hbHKwApYCZz6bG2wUHKbgfA== X-Received: by 2002:a9d:a6:: with SMTP id w35-v6mr25336632oti.109.1537568295727; Fri, 21 Sep 2018 15:18:15 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY3kIgUREmFKaWnkmO21f2urOPWfGApmVov04+tMubE3rviSyY7vsmsgOZHPl4iv5C7JAEk X-Received: by 2002:a9d:a6:: with SMTP id w35-v6mr25336589oti.109.1537568294500; Fri, 21 Sep 2018 15:18:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568294; cv=none; d=google.com; s=arc-20160816; b=DdHSwjgAEm8/TUPBwOCTFlZbN+HN8r9cbhhx2gCG0MaIIGU2sLWFK/NVUooNNMTaTz E9vSJQXFjGAl2muNQTDQGVmqpWECvgjTagWCFKe5ExMTfCpGvp1sZwydtpyuqkJV5C/m raXOn9XwbqhKLUKu5nAcXCT9UavD1iAl6Q5DF0oRJJry4DT4gzCwZYMrKNE5zULh0Dsd AyJYd23TwV/jYBF4/TV/5wkAGxVu0ZthvHj+0wsjxfNJgu/Z/J/euCWXdK0FVXHfR/fX 0N/NbEZuM+XZ+proMf7bT5yA30RXKmNCk96f7GQwdkc7H+mdyHf5sQYOk2/95jzVuiU1 L0fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=icR6tn2J9gdMnwoNflR020W7wn+Aa33OrG5orolU8LM=; b=D8xjwQkFG4Rf9Q2VYnvtRDh6RHWPIFxryrL3MG6Y0l/UNBAYVYGK4yezEDw00tf+vh Z4g7CO/glWvUDujyDe7Ka22r1eelI1EAlJ3H69Rpfm5XxT2dhYQdplL3erPFmLd5EkdE z2bXc8TwAtXylI2cXV+sWsZ30SRT24QgsQWTdu9oBmq25OS8ZAoUUB8l2CTjAqikg3cd MvwjwlVuELC2kHLnWVXT0AF7B/ta3zRuzt0+9Rs0BnpvMcGmPblbPOz9215PNdvFc1/4 B6Wvwh3Lyb1ji1z+zGezPZFgkBhjtYULMncYOwFeIU1K0KVVQDzEKYeBQdI9+FGs82JU OMIQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com Received: from foss.arm.com (usa-sjc-mx-foss1.foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id g49-v6si258130otg.66.2018.09.21.15.18.14 for ; Fri, 21 Sep 2018 15:18:14 -0700 (PDT) Received-SPF: pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0012A15AD; Fri, 21 Sep 2018 15:18:13 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DEE6E3F557; Fri, 21 Sep 2018 15:18:10 -0700 (PDT) From: James Morse To: linux-acpi@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Borislav Petkov , Marc Zyngier , Christoffer Dall , Will Deacon , Catalin Marinas , Naoya Horiguchi , Rafael Wysocki , Len Brown , Tony Luck , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 07/18] arm64: KVM/mm: Move SEA handling behind a single 'claim' interface Date: Fri, 21 Sep 2018 23:16:54 +0100 Message-Id: <20180921221705.6478-8-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP To split up APEIs in_nmi() path, we need the nmi-like callers to always be in_nmi(). Add a helper to do the work and claim the notification. When KVM or the arch code takes an exception that might be a RAS notification, it asks the APEI firmware-first code whether it wants to claim the exception. We can then go on to see if (a future) kernel-first mechanism wants to claim the notification, before falling through to the existing default behaviour. The NOTIFY_SEA code was merged before we had multiple, possibly interacting, NMI-like notifications and the need to consider kernel first in the future. Make the 'claiming' behaviour explicit. As we're restructuring the APEI code to allow multiple NMI-like notifications, any notification that might interrupt interrupts-masked code must always be wrapped in nmi_enter()/nmi_exit(). This allows APEI to use in_nmi() to use the right fixmap entries. We mask SError over this window to prevent an asynchronous RAS error arriving and tripping 'nmi_enter()'s BUG_ON(in_nmi()). Signed-off-by: James Morse Acked-by: Marc Zyngier Tested-by: Tyler Baicar --- Why does apei_claim_sea() take a pt_regs? This gets used later to take APEI by the hand through NMI->IRQ context, depending on what we interrupted. Changes since v4: * Made irqs-unmasked comment a lockdep assert. Changes since v3: * Removed spurious whitespace change * Updated comment in acpi.c to cover SError masking Changes since v2: * Added dummy definition for !ACPI and culled IS_ENABLED() checks. squash: make 'call with irqs unmaksed' a lockdep assert, much better --- arch/arm64/include/asm/acpi.h | 4 ++++ arch/arm64/include/asm/daifflags.h | 1 + arch/arm64/include/asm/kvm_ras.h | 16 +++++++++++++++- arch/arm64/kernel/acpi.c | 29 +++++++++++++++++++++++++++++ arch/arm64/mm/fault.c | 24 +++++------------------- 5 files changed, 54 insertions(+), 20 deletions(-) diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h index 709208dfdc8b..f722d2d6bf2b 100644 --- a/arch/arm64/include/asm/acpi.h +++ b/arch/arm64/include/asm/acpi.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -139,6 +140,9 @@ static inline pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr) { return __acpi_get_mem_attribute(addr); } +int apei_claim_sea(struct pt_regs *regs); +#else +static inline int apei_claim_sea(struct pt_regs *regs) { return -ENOENT; } #endif /* CONFIG_ACPI_APEI */ #ifdef CONFIG_ACPI_NUMA diff --git a/arch/arm64/include/asm/daifflags.h b/arch/arm64/include/asm/daifflags.h index 22e4c83de5a5..cbd753855bf3 100644 --- a/arch/arm64/include/asm/daifflags.h +++ b/arch/arm64/include/asm/daifflags.h @@ -20,6 +20,7 @@ #define DAIF_PROCCTX 0 #define DAIF_PROCCTX_NOIRQ PSR_I_BIT +#define DAIF_ERRCTX (PSR_I_BIT | PSR_A_BIT) /* mask/save/unmask/restore all exceptions, including interrupts. */ static inline void local_daif_mask(void) diff --git a/arch/arm64/include/asm/kvm_ras.h b/arch/arm64/include/asm/kvm_ras.h index 5f72b07b7912..5b56e7e297b1 100644 --- a/arch/arm64/include/asm/kvm_ras.h +++ b/arch/arm64/include/asm/kvm_ras.h @@ -4,8 +4,22 @@ #ifndef __ARM64_KVM_RAS_H__ #define __ARM64_KVM_RAS_H__ +#include +#include #include -int kvm_handle_guest_sea(phys_addr_t addr, unsigned int esr); +#include + +/* + * Was this synchronous external abort a RAS notification? + * Returns '0' for errors handled by some RAS subsystem, or -ENOENT. + */ +static inline int kvm_handle_guest_sea(phys_addr_t addr, unsigned int esr) +{ + /* apei_claim_sea(NULL) expects to mask interrupts itself */ + lockdep_assert_irqs_enabled(); + + return apei_claim_sea(NULL); +} #endif /* __ARM64_KVM_RAS_H__ */ diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c index ed46dc188b22..a9b8bba014b5 100644 --- a/arch/arm64/kernel/acpi.c +++ b/arch/arm64/kernel/acpi.c @@ -28,8 +28,10 @@ #include #include +#include #include #include +#include #include #include @@ -257,3 +259,30 @@ pgprot_t __acpi_get_mem_attribute(phys_addr_t addr) return __pgprot(PROT_NORMAL_NC); return __pgprot(PROT_DEVICE_nGnRnE); } + +/* + * Claim Synchronous External Aborts as a firmware first notification. + * + * Used by KVM and the arch do_sea handler. + * @regs may be NULL when called from process context. + */ +int apei_claim_sea(struct pt_regs *regs) +{ + int err = -ENOENT; + unsigned long current_flags = arch_local_save_flags(); + + if (!IS_ENABLED(CONFIG_ACPI_APEI_SEA)) + return err; + + /* + * SEA can interrupt SError, mask it and describe this as an NMI so + * that APEI defers the handling. + */ + local_daif_restore(DAIF_ERRCTX); + nmi_enter(); + err = ghes_notify_sea(); + nmi_exit(); + local_daif_restore(current_flags); + + return err; +} diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 1a30d7a8c9bf..2c38776bb71f 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -18,6 +18,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -33,6 +34,7 @@ #include #include +#include #include #include #include @@ -45,8 +47,6 @@ #include #include -#include - struct fault_info { int (*fn)(unsigned long addr, unsigned int esr, struct pt_regs *regs); @@ -631,19 +631,10 @@ static int do_sea(unsigned long addr, unsigned int esr, struct pt_regs *regs) inf = esr_to_fault_info(esr); /* - * Synchronous aborts may interrupt code which had interrupts masked. - * Before calling out into the wider kernel tell the interested - * subsystems. + * Return value ignored as we rely on signal merging. + * Future patches will make this more robust. */ - if (IS_ENABLED(CONFIG_ACPI_APEI_SEA)) { - if (interrupts_enabled(regs)) - nmi_enter(); - - ghes_notify_sea(); - - if (interrupts_enabled(regs)) - nmi_exit(); - } + apei_claim_sea(regs); clear_siginfo(&info); info.si_signo = inf->sig; @@ -725,11 +716,6 @@ static const struct fault_info fault_info[] = { { do_bad, SIGKILL, SI_KERNEL, "unknown 63" }, }; -int kvm_handle_guest_sea(phys_addr_t addr, unsigned int esr) -{ - return ghes_notify_sea(); -} - asmlinkage void __exception do_mem_abort(unsigned long addr, unsigned int esr, struct pt_regs *regs) {