From patchwork Mon Dec 3 18:06:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710251 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 7CF7A15A6 for ; Mon, 3 Dec 2018 18:07:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 72AE32B47E for ; Mon, 3 Dec 2018 18:07:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 670F12B49D; Mon, 3 Dec 2018 18:07:39 +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 B83242B47E for ; Mon, 3 Dec 2018 18:07:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63C216B6A82; Mon, 3 Dec 2018 13:07:29 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 60FF66B6A83; Mon, 3 Dec 2018 13:07:29 -0500 (EST) 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 4FF1B6B6A84; Mon, 3 Dec 2018 13:07:29 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) by kanga.kvack.org (Postfix) with ESMTP id 24E826B6A82 for ; Mon, 3 Dec 2018 13:07:29 -0500 (EST) Received: by mail-oi1-f199.google.com with SMTP id p131so4557899oia.21 for ; Mon, 03 Dec 2018 10:07:29 -0800 (PST) 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=cvoduY6NMUcDYyIXKzYuFn0uayj+J0WpGRWrEtFaJ/A=; b=dQz1ofCkceDOlXUVKdVr0hswI5FR7DqN6sGd5DPwl04QWEcHQB0mMSj8d49NdTdHxt pbD3+hyuM4vuZCRAkYNvADWOHUDaXu4CIuJF0ceGlyBuAT3AcxBCtXpaN0A8o+wIlVWp IZPfP0DhN7OYESfT7aNQMTPQvVJqOwhdD/HCwdPWwwmY96+oKjYMQycph/AxK4ocVfCm Ao0RKWLtDToGBtZ9QO3eKdE2XwmHfne5ETGjs9vIq9Rncc7t783pv3SLWCjhtXPNLCDe 4Fnmi7kVJr2MRX4q7zbEL2miLNo363usYoocFeTvNWnVeewsz5rG9yyuFRi74AyxNYeu MzkQ== 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: AA+aEWa0Sz9u7cymswVtaRvq7TQ14aWu0podhfHA2QLtZGIXraNrlXtI 2m/1iMNDG5MwJP8OtoINlv3xz5tRxiTYvCUbOtKTNnBDN+I3uPL8sKuc9heOcsppdg7oK+9kp5r FxoAR1i2OFO5NrMUQD+QvYEiXAlSa50TKnDTZBaKTvWvRHtq+sG01kQYDZHxbYxsrig== X-Received: by 2002:a9d:3f34:: with SMTP id m49mr10229609otc.23.1543860448859; Mon, 03 Dec 2018 10:07:28 -0800 (PST) X-Google-Smtp-Source: AFSGD/XNuJKpObUVJu4gZ/UyOEkbkTl9JmF8+oReQ7EhFfisbxTKsInVfyIIkZU2SPKEk3ikjawy X-Received: by 2002:a9d:3f34:: with SMTP id m49mr10229570otc.23.1543860447829; Mon, 03 Dec 2018 10:07:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860447; cv=none; d=google.com; s=arc-20160816; b=qFhS9GcSeju1xpWNeAt8OgsGU248mID7LTHh3YFN6npr4cqdmQMPuxEb1jEND1eytu 9vvKQLHOaT716v7M53v+XTnYy++gzJRXvGBD9O4gDNDuUgxtoSKbiT0FrZpcm9xgn/WR qgfMdWVoAf/BKQsCCgYOp9QtYRPvJsUCOE5Dgp765nhYfaZ1N2X7NEMrJzRASoZiX2Qw MatznJ1RXDc56c8GFAXTX3QmGfPvp+ju5uUmBBm29w2EPooRQpfQMpB/OdS9VJJluF+1 TIrbJovZNLF7CsHfvnXh2eu2YKivNpRqjy2HPyTSpvOtxuzXRcz2qO/k/OSHTBJLCkZg HmvA== 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=cvoduY6NMUcDYyIXKzYuFn0uayj+J0WpGRWrEtFaJ/A=; b=AxVdXMokQ4f7vywKiPRDYb8u5gJG0EltuIkTJjxCaH2kLGjSzkyrF4NUvcPnMLzbVW LAqfcsQLhZ8usbwTsR1POzP3VioAMJZCShTD1RsP7lk5HlLvlWOx+CCz1o1t+unblsgI Bhx6nmWsMQXcYT6Z5zMVk7TIeWaO9cLG5L6WFDMM+AuZWJea79GzREwjojSQNeRDoo/C O/OoY3MydZpbaaCo/pChPenL+4lq6iNJXhJuJIHQIqONk/0j3svRwpQJLrpndX1fUM4Q 83Evt2f6CbPh+F0TgePMAiCo7eQyItPe0MyRETWajMKQ2c5ZYF4kjaNEwKZT41SNOuzx LMiQ== 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 e126si6629442oig.75.2018.12.03.10.07.27 for ; Mon, 03 Dec 2018 10:07:27 -0800 (PST) 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 3ECF0169E; Mon, 3 Dec 2018 10:07:27 -0800 (PST) Received: from eglon.cambridge.arm.com (eglon.cambridge.arm.com [10.1.196.105]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6E9973F59C; Mon, 3 Dec 2018 10:07:24 -0800 (PST) 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 , Dongjiu Geng , Xie XiuQi , Fan Wu , James Morse Subject: [PATCH v7 14/25] arm64: KVM/mm: Move SEA handling behind a single 'claim' interface Date: Mon, 3 Dec 2018 18:06:02 +0000 Message-Id: <20181203180613.228133-15-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-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, the caller needs 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. A future kernel-first mechanism may be queried afterwards, and claim the notification, otherwise we fall through to the existing default behaviour. The NOTIFY_SEA code was merged before considering multiple, possibly interacting, NMI-like notifications and the need to consider kernel first in the future. Make the 'claiming' behaviour explicit. Restructuring the APEI code to allow multiple NMI-like notifications means any notification that might interrupt interrupts-masked code must always be wrapped in nmi_enter()/nmi_exit(). This will allow APEI to use in_nmi() to use the right fixmap entries. 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 Acked-by: Catalin Marinas --- 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 v6: * Moved the voice of the commit message. * moved arch_local_save_flags() below the !IS_ENABLED drop-out * Moved the dummy declaration into the if-ACPI part of the header instead of if-APEI. 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. --- 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 | 31 ++++++++++++++++++++++++++++++ arch/arm64/mm/fault.c | 24 +++++------------------ 5 files changed, 55 insertions(+), 21 deletions(-) diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h index 709208dfdc8b..4ed19b26ec1a 100644 --- a/arch/arm64/include/asm/acpi.h +++ b/arch/arm64/include/asm/acpi.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -99,9 +100,10 @@ static inline u32 get_acpi_id_for_cpu(unsigned int cpu) static inline void arch_fix_phys_package_id(int num, u32 slot) { } void __init acpi_init_cpus(void); - +int apei_claim_sea(struct pt_regs *regs); #else static inline void acpi_init_cpus(void) { } +static inline int apei_claim_sea(struct pt_regs *regs) { return -ENOENT; } #endif /* CONFIG_ACPI */ #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL diff --git a/arch/arm64/include/asm/daifflags.h b/arch/arm64/include/asm/daifflags.h index 8d91f2233135..fa90779fc752 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 6096f0251812..8ac6ee77437c 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 44e3c351e1ea..803f0494dd3e 100644 --- a/arch/arm64/kernel/acpi.c +++ b/arch/arm64/kernel/acpi.c @@ -27,8 +27,10 @@ #include #include +#include #include #include +#include #include #include @@ -256,3 +258,32 @@ 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; + + if (!IS_ENABLED(CONFIG_ACPI_APEI_GHES)) + return err; + + current_flags = arch_local_save_flags(); + + /* + * 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 eeeb576b33d7..956afc7d932a 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 @@ -46,8 +48,6 @@ #include #include -#include - struct fault_info { int (*fn)(unsigned long addr, unsigned int esr, struct pt_regs *regs); @@ -630,19 +630,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); if (esr & ESR_ELx_FnV) siaddr = NULL; @@ -720,11 +711,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) {