Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp874764pxk; Thu, 17 Sep 2020 19:59:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxDLVb3Tw4YUlMjoB9qiXIU8WyDcxC+aRWefWNGqZge1Oi2UBw6CctrZfZeOdhZtWuDnIeT X-Received: by 2002:a17:906:4154:: with SMTP id l20mr36116087ejk.68.1600397991660; Thu, 17 Sep 2020 19:59:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600397991; cv=none; d=google.com; s=arc-20160816; b=pvhkse/cVx8CJASJ+WqSr5Cde8jFJS1UINmLmTFAssl6jpYEyi899sZjZtQf8OsBcq /uocFqaylTeQMAS2AdYFqAjAyTAc0HEiXHvw+2wBwGMP3ISEmPAqmW+FdE5E0zgQ/ELd YjWX9KUj0ex6OW28m8Wyvw0+BMiQAxAg2v4K2qS4nnkFQFED7fGgy9xUnbJ1ZrPQiah4 61Znxwzoda4avxKyucri6DkTCmXVFBLcNhHXUU6sWbeT0YupXVv71BQeewtmrH7p7m3+ NrYpqUauaoAjHYU9h16q3J9i1n5BS9jCNBEgLpANr/LPD5fKOrsJf3l/mI9aV9YJfWxm JRNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=V4YwmMgHFJQWoiBTElNaxv8MIcnAmqyjQQhTiR4VcCQ=; b=F2lSH2eJvlRbC9PC0X6UI10g5XMSbQtzMSrpyfMTZBvFmBrg6Bg8bdcALD1EzbaDQ6 qxAJxbv0E0pW9e+cw/Jo5cP7Eq4quHEAdOJJ28hRwsBOiOdZuf1rSkFRVf1WlY1ZEVJ2 yvdIcLLbgxZ6etLs/KSmtDVwabeYw/7I9ncQA5iGjl4WCPWcKT2WxPrO+w7pgE4wRl6j zNHGDqVxAq2gnXbaEpRG7MlYNHpwzfChqhbPdjgapE6i3WBgLir/Y+aLc7bsms+zN6UO 4b7PTqeC7b8VUVW4GcbrprERyOTGbvOEzgAV7DqXNLh1OgpWC5nptxGBQTT5laH/j3v6 +iyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=11Q5Uxy0; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qx8si1308418ejb.175.2020.09.17.19.59.26; Thu, 17 Sep 2020 19:59:51 -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=@kernel.org header.s=default header.b=11Q5Uxy0; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730367AbgIRC4c (ORCPT + 99 others); Thu, 17 Sep 2020 22:56:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:57126 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727830AbgIRCHF (ORCPT ); Thu, 17 Sep 2020 22:07:05 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 72BF82395B; Fri, 18 Sep 2020 02:06:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394808; bh=tLj9bbCmKARSDrqm3XIwE29GbyTs9y0er/D6N+vkrMM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=11Q5Uxy0Qk6I1Az3NlA8Q/uvHwKLjDRLzAT4briOPPtWRqi/mC8xUh5e45X9W6CsY wmuJJoOY1Sf7WfOBrjsGLBLv0oc3qZwMpt95ARdxh+WksVxuz7AB/C4SjVdY8bMEWz XADMSRkeRjyzG2yq+gvMQ1dBa4xc+oZRfK74q8uk= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: James Morse , Tyler Baicar , Catalin Marinas , "Rafael J . Wysocki" , Sasha Levin , linux-arm-kernel@lists.infradead.org Subject: [PATCH AUTOSEL 5.4 276/330] arm64: acpi: Make apei_claim_sea() synchronise with APEI's irq work Date: Thu, 17 Sep 2020 22:00:16 -0400 Message-Id: <20200918020110.2063155-276-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: James Morse [ Upstream commit 8fcc4ae6faf8b455eeef00bc9ae70744e3b0f462 ] APEI is unable to do all of its error handling work in nmi-context, so it defers non-fatal work onto the irq_work queue. arch_irq_work_raise() sends an IPI to the calling cpu, but this is not guaranteed to be taken before returning to user-space. Unless the exception interrupted a context with irqs-masked, irq_work_run() can run immediately. Otherwise return -EINPROGRESS to indicate ghes_notify_sea() found some work to do, but it hasn't finished yet. With this apei_claim_sea() returning '0' means this external-abort was also notification of a firmware-first RAS error, and that APEI has processed the CPER records. Signed-off-by: James Morse Tested-by: Tyler Baicar Acked-by: Catalin Marinas Signed-off-by: Rafael J. Wysocki Signed-off-by: Sasha Levin --- arch/arm64/kernel/acpi.c | 25 +++++++++++++++++++++++++ arch/arm64/mm/fault.c | 12 +++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c index a100483b47c42..46ec402e97edc 100644 --- a/arch/arm64/kernel/acpi.c +++ b/arch/arm64/kernel/acpi.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -269,6 +270,7 @@ pgprot_t __acpi_get_mem_attribute(phys_addr_t addr) int apei_claim_sea(struct pt_regs *regs) { int err = -ENOENT; + bool return_to_irqs_enabled; unsigned long current_flags; if (!IS_ENABLED(CONFIG_ACPI_APEI_GHES)) @@ -276,6 +278,12 @@ int apei_claim_sea(struct pt_regs *regs) current_flags = local_daif_save_flags(); + /* current_flags isn't useful here as daif doesn't tell us about pNMI */ + return_to_irqs_enabled = !irqs_disabled_flags(arch_local_save_flags()); + + if (regs) + return_to_irqs_enabled = interrupts_enabled(regs); + /* * SEA can interrupt SError, mask it and describe this as an NMI so * that APEI defers the handling. @@ -284,6 +292,23 @@ int apei_claim_sea(struct pt_regs *regs) nmi_enter(); err = ghes_notify_sea(); nmi_exit(); + + /* + * APEI NMI-like notifications are deferred to irq_work. Unless + * we interrupted irqs-masked code, we can do that now. + */ + if (!err) { + if (return_to_irqs_enabled) { + local_daif_restore(DAIF_PROCCTX_NOIRQ); + __irq_enter(); + irq_work_run(); + __irq_exit(); + } else { + pr_warn_ratelimited("APEI work queued but not completed"); + err = -EINPROGRESS; + } + } + local_daif_restore(current_flags); return err; diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index d26e6cd289539..2a7339aeb1ad4 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -654,11 +654,13 @@ static int do_sea(unsigned long addr, unsigned int esr, struct pt_regs *regs) inf = esr_to_fault_info(esr); - /* - * Return value ignored as we rely on signal merging. - * Future patches will make this more robust. - */ - apei_claim_sea(regs); + if (user_mode(regs) && apei_claim_sea(regs) == 0) { + /* + * APEI claimed this as a firmware-first notification. + * Some processing deferred to task_work before ret_to_user(). + */ + return 0; + } if (esr & ESR_ELx_FnV) siaddr = NULL; -- 2.25.1