From patchwork Tue Jan 29 18:48:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786885 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 CE32191E for ; Tue, 29 Jan 2019 18:49:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BEE682D1B1 for ; Tue, 29 Jan 2019 18:49:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B2E852D1CD; Tue, 29 Jan 2019 18:49:46 +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 ACD852D1B1 for ; Tue, 29 Jan 2019 18:49:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D47F68E0006; Tue, 29 Jan 2019 13:49:44 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CF91A8E0001; Tue, 29 Jan 2019 13:49:44 -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 BC1928E0006; Tue, 29 Jan 2019 13:49:44 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id 650C38E0001 for ; Tue, 29 Jan 2019 13:49:44 -0500 (EST) Received: by mail-ed1-f71.google.com with SMTP id y35so8312687edb.5 for ; Tue, 29 Jan 2019 10:49:44 -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=yrq+fajuZYlMQD6pqhm35zNniWCBZ92c1vlrhOua6h8=; b=AXw6/xtLSRyQub65b3D1GdfneArKON+zj+c1FpRJvDHBdK6wLVAYWYbyspAOhafiWz NYZjOJGVVs0+3Ykjbsp/8EWgYGhBilhPcCxwHH64k8NjWqkcyW9TY/kdjhWC9V6kUGms 7qAf6q/UfY71mqZV8D0QVNFg34M6EnKtz5IbzpStG6TpvCnSXQ5L6MZ427krzZieqCmi FxaJWYWA9cbD5XRWAFud8UcuduvHLfO8PZb2onQDkK9NzonirrkxjlqKVJ9s89vYpLEK RL5XuQ8cePVc873sOahvImgs21SYBeXSM46URDbUOt3S5QmxGMv3RhqZsGD37pq4esHa Mmjg== 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: AJcUukeJnaueXkZZ+jbC0QGZa5YEvS36Se1EU79NLnDJ+yfeNKfPNnod 9+ouot5OepVUS0RzwIqUbOfS72hLkYqmus1UI2zzZlc9WdR5cLVegKHBa35Hqq5yy1E4reGZbfu oTb7+ErWQ1Jxk+H3gh4tV9dUD0l7KMkqhcB+gPjwdg3MaEoZlY5RZJrLC0UHereS9Bg== X-Received: by 2002:a05:6402:14cd:: with SMTP id f13mr26783899edx.224.1548787783904; Tue, 29 Jan 2019 10:49:43 -0800 (PST) X-Google-Smtp-Source: ALg8bN7skBc3PEYe2A3LRSiwLYqh7Dr41XmZVctFALIIGlkA5PSuwJgT888/D5TwE/RHTxTGxNEb X-Received: by 2002:a05:6402:14cd:: with SMTP id f13mr26783835edx.224.1548787782726; Tue, 29 Jan 2019 10:49:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787782; cv=none; d=google.com; s=arc-20160816; b=WNqi9Fj5UQh4abqJmxkz5MT+CcVjzjbgf4d+OdaVO0R8Mn25hu3Vdl7okszLC30910 PIY5zNRcM/KupD3ZiLfIftLcHU7b+g9/fd9zyZPGz2lqtdVOaWx3kjRU4DFktobi0LHe rB1nMp6PrxYa+OPwtLRpQM6VZfE0M0CY7aAR64vm+u/9Aad6kbyveRAS9SgnwWrwpCFH G6xsZG4XMHHsPCPOO5/jHOzBg2yJ9cjxs+2+XwnGynEQ7tDIQBCDGhOcQQ/llJhzL6m2 xj4Ypf33WliO4lJaQb7BeCJZUEHcugoz30rcJEGA6DNm37ycWjXFpOLkm9VfjwL6s7tI /z6g== 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=yrq+fajuZYlMQD6pqhm35zNniWCBZ92c1vlrhOua6h8=; b=p8WFIcNL7N7LWqb2UcahQIjAlUALnx/Kmp0RpEM8BWmChuQYssNihoJkGnu/jptf34 FlPHJPKktYrFqRmYTnBTsdaHLdmDHqf9qjgOdXXqCuiiORpJ+HWOoIBjMMmazO4lcpWa GSfKOb4GNubTL2eb7zva6n1pjsm9lCSGfktakPVmIbPgkwk6gSyJ8KQeKEmp+/s9HD79 qtM7WkLb9l0PmMgDF0SXPA+b7hXb8hTXRa+QTqwu2mc2c1lxrQ+VUG4i7cgtJk8CQnDJ diSdS9ya03cI6cNLQddToRqvWYp7kzrw1/gQPGveLXiFojfAmXFFNPkdhglNa+OvPTNd RLCw== 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 k25si3149949edk.323.2019.01.29.10.49.42 for ; Tue, 29 Jan 2019 10:49:42 -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 960CEA78; Tue, 29 Jan 2019 10:49:41 -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 E99963F557; Tue, 29 Jan 2019 10:49:38 -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 , james.morse@arm.com Subject: [PATCH v8 01/26] ACPI / APEI: Don't wait to serialise with oops messages when panic()ing Date: Tue, 29 Jan 2019 18:48:37 +0000 Message-Id: <20190129184902.102850-2-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 oops_begin() exists to group printk() messages with the oops message printed by die(). To reach this caller we know that platform firmware took this error first, then notified the OS via NMI with a 'panic' severity. Don't wait for another CPU to release the die-lock before panic()ing, our only goal is to print this fatal error and panic(). This code is always called in_nmi(), and since commit 42a0bb3f7138 ("printk/nmi: generic solution for safe printk in NMI"), it has been safe to call printk() from this context. Messages are batched in a per-cpu buffer and printed via irq-work, or a call back from panic(). Link: https://patchwork.kernel.org/patch/10313555/ Acked-by: Borislav Petkov Signed-off-by: James Morse --- Changes since v6: * Capitals in patch subject * Tinkered with the commit message. --- drivers/acpi/apei/ghes.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index f008ba7c9ced..0c46b79e31b1 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -949,7 +948,6 @@ static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) sev = ghes_severity(ghes->estatus->error_severity); if (sev >= GHES_SEV_PANIC) { - oops_begin(); ghes_print_queued_estatus(); __ghes_panic(ghes); } From patchwork Tue Jan 29 18:48:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786887 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 E5B1991E for ; Tue, 29 Jan 2019 18:49:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D69582D1B9 for ; Tue, 29 Jan 2019 18:49:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAAE82D1D0; Tue, 29 Jan 2019 18:49:48 +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 688A72D1B9 for ; Tue, 29 Jan 2019 18:49:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4985C8E0007; Tue, 29 Jan 2019 13:49:47 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 447A38E0001; Tue, 29 Jan 2019 13:49:47 -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 3108D8E0007; Tue, 29 Jan 2019 13:49:47 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id CCAA88E0001 for ; Tue, 29 Jan 2019 13:49:46 -0500 (EST) Received: by mail-ed1-f69.google.com with SMTP id t7so8287773edr.21 for ; Tue, 29 Jan 2019 10:49:46 -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=zWuERV+0zMTrfeg4mludKeQEAgk+5eFdnl31qbVuu4Y=; b=jcYvrUPDMjdoBqwHGPQHb1/KDVbbSHzfJAQzusBT4VbbDnwSL11yxJ8tz6i/oGap3A BZv69kbZho4UzsfLtqHWQgXZ/8hK7ncogBTJkp6FwgLOGeThqdz7Eh0HYlqod7MiqFrg +BovabmOmyv7U+WtfeLBG4XNY34CgYrqEnUb/SL4GhUGhuoDeOAYmsgDC9ts0caqPe+O F77PtvF3HpYEI+m9wPM0u71AGeD0R//en7FTrOFa8CKW+HJdXvVZ6sdIGDBGf3a0JnBW IVfUT2ymf+2g5phYCuzmoRJ3yqGZgJ2ys8kn8TNniK0ONEhDVqx25qGLUxUU9BquvgjB 3MaQ== 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: AJcUukevfzG1OwR1vWZrwLjm68VUwXl57jV1scUzxkkteT7npeEf7pc9 l2uVsZ1c7X30qPxW8Nzb0eOfOAHY4fJbltSaABwz5q2TF2fJXPvp5X7vHwB0hToS6Pyf7p8EygN 25qk7Leb0jftKiR4ewX+iBUOEll6h7zyScrxhZhO2xrUSJa7vhTJcAt9PW2uWT4RpuQ== X-Received: by 2002:a05:6402:511:: with SMTP id m17mr27009032edv.33.1548787786333; Tue, 29 Jan 2019 10:49:46 -0800 (PST) X-Google-Smtp-Source: ALg8bN5A9VoIQr1Gc/Fpus35/OAfC9hMg5qR/o2nQ6GGr8d0yHs0L+pfaZGgUri/wz8f5KzaIgg0 X-Received: by 2002:a05:6402:511:: with SMTP id m17mr27008976edv.33.1548787785438; Tue, 29 Jan 2019 10:49:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787785; cv=none; d=google.com; s=arc-20160816; b=IIWYWIMqDu3HDSDJ8+JlmS0t6h8pE/BNl2cG+WtazznoShsYZGl7Vl5Fu4QTOUYmzc DcYYmBib9eSVWXNZnOCPE2/THUOw683rT1RjuNmucBjbH7To5Lgx9RGdQPCW7r7PufOt u6WRVWVQGWt2QkGFQRVmy4Xfdpxrn/6mzn4lIH9+7M59SslslE0zSJCsBVHfYA/szpa4 RMfJ5rWKYTxYkHROfXb2hUvrhPR5k4AZwSeDznMWLDFO/c99Rf2NXPI6xZZb0kyaVLsB 6OCue+1tUurfBhK0MPsiuDDP+Eco/bfzOhbsGBmGSOEfSMqLXfBcIH5K+O8EJlSfGIa0 Wizw== 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=zWuERV+0zMTrfeg4mludKeQEAgk+5eFdnl31qbVuu4Y=; b=n6VRLXIVl+s+mncUCeafbGccZx3gcMyrmiykA4mVqX4YfjhkQgVfLaFq1R2hiVY651 cMQTSi+J0nXRtt6tGRdhVY8gqJXUaGAx+RtlZ8EtutycSuNGVeWIVDiaf6F6TD+xqWaN 4PVsibFDFBH4RBL2DwW7FG0JBhvsOJ83VywxhxKECsQj/gt42uZbFQsWDx7dk/ZskevA 1MDOUEGoTSauVGE1DOXicuFi/IK2EesDtsa6X+kenU1tGgo0KUecFdcIk2ssE1isDuch h12AspZ+yX/M1AxCe+oKhjANNq6U7aYem6u30wxKAgI1pE2rWoyz4jd3xVyXrrjaZzI4 OP7g== 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 r16si2095416edo.219.2019.01.29.10.49.45 for ; Tue, 29 Jan 2019 10:49:45 -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 815AAA78; Tue, 29 Jan 2019 10:49:44 -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 D4AC23F557; Tue, 29 Jan 2019 10:49:41 -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 , james.morse@arm.com Subject: [PATCH v8 02/26] ACPI / APEI: Remove silent flag from ghes_read_estatus() Date: Tue, 29 Jan 2019 18:48:38 +0000 Message-Id: <20190129184902.102850-3-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 Subsequent patches will split up ghes_read_estatus(), at which point passing around the 'silent' flag gets annoying. This is to suppress prink() messages, which prior to commit 42a0bb3f7138 ("printk/nmi: generic solution for safe printk in NMI"), were unsafe in NMI context. This is no longer necessary, remove the flag. printk() messages are batched in a per-cpu buffer and printed via irq-work, or a call back from panic(). Signed-off-by: James Morse Reviewed-by: Borislav Petkov --- Changes since v6: * Moved earlier in the series, * Tinkered with the commit message. * switched to pr_warn_ratelimited() to shut checkpatch up --- drivers/acpi/apei/ghes.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 0c46b79e31b1..f0a704aed040 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -324,7 +324,7 @@ static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len, } } -static int ghes_read_estatus(struct ghes *ghes, int silent) +static int ghes_read_estatus(struct ghes *ghes) { struct acpi_hest_generic *g = ghes->generic; u64 buf_paddr; @@ -333,8 +333,7 @@ static int ghes_read_estatus(struct ghes *ghes, int silent) rc = apei_read(&buf_paddr, &g->error_status_address); if (rc) { - if (!silent && printk_ratelimit()) - pr_warning(FW_WARN GHES_PFX + pr_warn_ratelimited(FW_WARN GHES_PFX "Failed to read error status block address for hardware error source: %d.\n", g->header.source_id); return -EIO; @@ -366,9 +365,9 @@ static int ghes_read_estatus(struct ghes *ghes, int silent) rc = 0; err_read_block: - if (rc && !silent && printk_ratelimit()) - pr_warning(FW_WARN GHES_PFX - "Failed to read error status block!\n"); + if (rc) + pr_warn_ratelimited(FW_WARN GHES_PFX + "Failed to read error status block!\n"); return rc; } @@ -702,7 +701,7 @@ static int ghes_proc(struct ghes *ghes) { int rc; - rc = ghes_read_estatus(ghes, 0); + rc = ghes_read_estatus(ghes); if (rc) goto out; @@ -939,7 +938,7 @@ static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) return ret; list_for_each_entry_rcu(ghes, &ghes_nmi, list) { - if (ghes_read_estatus(ghes, 1)) { + if (ghes_read_estatus(ghes)) { ghes_clear_estatus(ghes); continue; } else { From patchwork Tue Jan 29 18:48:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786891 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 4076B1874 for ; Tue, 29 Jan 2019 18:49:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 309942D1B8 for ; Tue, 29 Jan 2019 18:49:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 249B72D1CD; Tue, 29 Jan 2019 18:49:52 +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 A5EEC2D1B8 for ; Tue, 29 Jan 2019 18:49:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 840638E0001; Tue, 29 Jan 2019 13:49:50 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7EFFA8E0008; Tue, 29 Jan 2019 13:49:50 -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 6E9E18E0001; Tue, 29 Jan 2019 13:49:50 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id 153A68E0001 for ; Tue, 29 Jan 2019 13:49:50 -0500 (EST) Received: by mail-ed1-f72.google.com with SMTP id m19so8310303edc.6 for ; Tue, 29 Jan 2019 10:49:50 -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=fD8p7np7UeGkTdvd8XbtAHGwPZeSf1NvRF2y9gcTwlQ=; b=oSksLgkBnH54t10fkVzOGMP6B9YPMdIFR7ZripN/yGXIfzoLLDZEaBlNZujjP3iAmu p7Gitx3HK6ogH/daedavyHB1kctUZtN4rEwWSRYbuhHEJ9m+kTiQKc51TBBAF4K3/3Un Ln3whpAhx5+gfuAdM73uMMoDgdO7ivxUzlrrEvHuhJg67CiYRf2+Os2Prbg/vQ8XqnAy GGT663vJxC/VYLzmKYezvGevUeCTdyZQ9eLXqDEpsisIwSmyFHg14FLEn4iy1WuXJ+ND CinIF9yVEakRMVc4coiWDWnbg8YX6Y0w4oHDJpc5BKZ3wqQ8jeEj9uuPccFc0xRqTh+2 Lh8Q== 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: AJcUukeFVIRWNn3TxrXN0EtMyfrzwN56zTMcExWfbqn/hl7y5CW7Tr0y 1AOcSNC0dSgSEOz1qVl5hnjwG0rygXZDqS1YVO1jjbq/FfjuYLxFELAUfFe4G5hCLOYC3TrGwDn xsn7PhvPFgGVBe19T5bOY+54toLWKPwuNt7uawOv8qYkdrcsCrTtoJQECPyx3IxP7gw== X-Received: by 2002:a17:906:b3c9:: with SMTP id cg9mr7408465ejb.159.1548787789551; Tue, 29 Jan 2019 10:49:49 -0800 (PST) X-Google-Smtp-Source: AHgI3IYfvfpsz50fR0C9IgJ+pBS6eEotVZcTIphqOajNg/jMXizM9dvemnJyEIklgpzWaLONqEb8 X-Received: by 2002:a17:906:b3c9:: with SMTP id cg9mr7408415ejb.159.1548787788477; Tue, 29 Jan 2019 10:49:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787788; cv=none; d=google.com; s=arc-20160816; b=E07nXcNIIRDWPi0GujyBRnraGJCacMh+g68shJAvAZQ5PAYYvFDZAZMFRaVraVOn33 Fyiqv/dqfmt6NHarBnOou2PfXASscq123BKQo0+1IoZUCqHbfiWINAbvOTrq7vdNuB8X OEIWFvPKTrpLMOXLexW4k8ZecYxwlqjNzcN+DtBp9hAu+PHmQGdp4vdeJ46BESOEz3O4 CzoLIAX9nhISPx8y5hS/Lsdl0ziXwxhRycnDKN/2mVxKcIKGzQqx+n6BUwl5SMwjfHeW 3mzzuTAoTQ/eD43Z7xbIQsjBhR3T4OEZK78V4zaUw5wDy2X0bQKBSpimAo0jTWvzEH8Z x2gA== 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=fD8p7np7UeGkTdvd8XbtAHGwPZeSf1NvRF2y9gcTwlQ=; b=gL1OyyeN3ZppSHXhf+KrbAiLGjgLLzhfV79jN/AWZRf3qkABl5KIMoRkRniUhxKD/3 UX9giKPYAiCiJa6FRUraZhAKhpxtFPyVvftaWz7OBkRxycdr2AbMN6uP/X0MR9vJAat2 B8qfqsKsHz8jemMvNrwCSQ5eK825IBCEAADrcshnGsEVLjmItATaSrSvXQlaG28pg3w0 m0XFtixPq3YaTzPowi0g8fnJRdeX+CXHZo3lpAc7DM5QvJYDnBl8DsCShl8mESJMVTfO ThKEYtuWEWDMEWwHw+YUMCJvZSFKrKG1qFdYPeMzTN4M6FIhuPWFoXc1M8Odkac/utFr 7zcg== 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 f10si632871eda.112.2019.01.29.10.49.48 for ; Tue, 29 Jan 2019 10:49:48 -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 6C49B1596; Tue, 29 Jan 2019 10:49:47 -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 BFDA93F557; Tue, 29 Jan 2019 10:49:44 -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 , james.morse@arm.com Subject: [PATCH v8 03/26] ACPI / APEI: Switch estatus pool to use vmalloc memory Date: Tue, 29 Jan 2019 18:48:39 +0000 Message-Id: <20190129184902.102850-4-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 The ghes code is careful to parse and round firmware's advertised memory requirements for CPER records, up to a maximum of 64K. However when ghes_estatus_pool_expand() does its work, it splits the requested size into PAGE_SIZE granules. This means if firmware generates 5K of CPER records, and correctly describes this in the table, __process_error() will silently fail as it is unable to allocate more than PAGE_SIZE. Switch the estatus pool to vmalloc() memory. On x86 vmalloc() memory may fault and be fixed up by vmalloc_fault(). To prevent this call vmalloc_sync_all() before an NMI handler could discover the memory. Signed-off-by: James Morse Reviewed-by: Borislav Petkov --- drivers/acpi/apei/ghes.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index f0a704aed040..ee9206d5e119 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -170,40 +170,40 @@ static int ghes_estatus_pool_init(void) return 0; } -static void ghes_estatus_pool_free_chunk_page(struct gen_pool *pool, +static void ghes_estatus_pool_free_chunk(struct gen_pool *pool, struct gen_pool_chunk *chunk, void *data) { - free_page(chunk->start_addr); + vfree((void *)chunk->start_addr); } static void ghes_estatus_pool_exit(void) { gen_pool_for_each_chunk(ghes_estatus_pool, - ghes_estatus_pool_free_chunk_page, NULL); + ghes_estatus_pool_free_chunk, NULL); gen_pool_destroy(ghes_estatus_pool); } static int ghes_estatus_pool_expand(unsigned long len) { - unsigned long i, pages, size, addr; - int ret; + unsigned long size, addr; ghes_estatus_pool_size_request += PAGE_ALIGN(len); size = gen_pool_size(ghes_estatus_pool); if (size >= ghes_estatus_pool_size_request) return 0; - pages = (ghes_estatus_pool_size_request - size) / PAGE_SIZE; - for (i = 0; i < pages; i++) { - addr = __get_free_page(GFP_KERNEL); - if (!addr) - return -ENOMEM; - ret = gen_pool_add(ghes_estatus_pool, addr, PAGE_SIZE, -1); - if (ret) - return ret; - } - return 0; + addr = (unsigned long)vmalloc(PAGE_ALIGN(len)); + if (!addr) + return -ENOMEM; + + /* + * New allocation must be visible in all pgd before it can be found by + * an NMI allocating from the pool. + */ + vmalloc_sync_all(); + + return gen_pool_add(ghes_estatus_pool, addr, PAGE_ALIGN(len), -1); } static int map_gen_v2(struct ghes *ghes) From patchwork Tue Jan 29 18:48:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786897 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 9AF7491E for ; Tue, 29 Jan 2019 18:49:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87FCB2D1A7 for ; Tue, 29 Jan 2019 18:49:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7AA7B2D1B9; Tue, 29 Jan 2019 18:49:55 +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 F134F2D1A7 for ; Tue, 29 Jan 2019 18:49:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 979188E0009; Tue, 29 Jan 2019 13:49:53 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 92CBD8E0008; Tue, 29 Jan 2019 13:49:53 -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 7CC448E0009; Tue, 29 Jan 2019 13:49:53 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id 24FA58E0008 for ; Tue, 29 Jan 2019 13:49:53 -0500 (EST) Received: by mail-ed1-f71.google.com with SMTP id b3so8351803edi.0 for ; Tue, 29 Jan 2019 10:49:53 -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=ZWJF8bIGxtJvec8yE+OonkJxAD3YvXGOUAi1MFmnEfk=; b=KEF+RXjQAet2fibFflkdpqZWru3mP4chgPVruszJW/tVSU2UMkG/RbRsQtYDeOaCEi CWqui28Vnvu+6LQ2aG0Qy6F8Rsf9DkDorI39c2CTeITSztvS7aoHCgyyc79kq4gjUptD ZbV4jFE07dnJrG9kCzG2cL4GXgDvbR3MClnfEvAmfEK03a55ZbvfO5tzOZKeGor6g971 PcxKH6e3oGIvDbGhia9IpxCBkVKhLcqvxABk6UdkK52ltdXp4bThYgu4rOraK7P3xdh6 SXvCICHHvEJSjxRjF1xdMt7W7zQeHLMBdGaHfiMMCR3I3PLW/JsJ5dgFKhMrTWaA4QKT GXOg== 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: AJcUukdShHdoHY5ulVEadClSUwlVfSMW8djD5SouIvIJvW1tUYOOeK3n IJ5WdW7CKX7O+ILOFXmo1rA2tOqn0R0ZAOT1/2/EVC8d7FtTtYYqDNL3Mq4hrt86AHOoamWypeM HcMBtahL3wxxO8s/NVZhwxcWMgNeGeseOykPjfqBCxn0tCqD2syviaixudX5FCxlK4g== X-Received: by 2002:a17:906:32c6:: with SMTP id k6-v6mr23489192ejk.48.1548787792607; Tue, 29 Jan 2019 10:49:52 -0800 (PST) X-Google-Smtp-Source: ALg8bN78vs8FDN0GsM8BtbOb0UJyR1MapD97rIUMfVtALWA+CKgitja/IwzWUGw8jTPLRHDDBfql X-Received: by 2002:a17:906:32c6:: with SMTP id k6-v6mr23489136ejk.48.1548787791586; Tue, 29 Jan 2019 10:49:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787791; cv=none; d=google.com; s=arc-20160816; b=sk3FbrxBf78lt+NphGAQV+Kef7DAayQr2vqPZ2G9eUbTiWLx4sD3gHEE1iPiXKMbj+ gEiyw+kxjkn5h8peOO2ctpdbQy27Z3I4TRJJhELjYMH7f6Gj/TxZ/O7eosmwvivhlQXj y80w8Nf8Ypt9OnHzi+NTZuj7RexptOBtP4g97ynE5vG2P1dSmvk0GaBPvdLSWQuwDTlJ 6II1C5D0y1R4HKQ3c3XejrffMraygezF737iExS22RD8/rIhGTG7Ygbv/3ivisgWMMiB IxcJJo048mVoC8zZJm5xOwiXuXV+PQxQYT/WuVPLMjst9e6uFAWQAnx4N8ZJGnxwMRfY w26Q== 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=ZWJF8bIGxtJvec8yE+OonkJxAD3YvXGOUAi1MFmnEfk=; b=De/ECf8MikobceSyxgy5Rb5uXrR2EBUYPlWUz9uDUmj3/MMIeL44rGjtuhER4SvYQg v0FMX/BnNsQmFzlGRoI/aA+AE8doAUWilP9bOBFExI13dfzoBgsW+t5EtCPMGoCDI7G4 Wio9iPA4DUFa7MyEbBhZuwzS4eEsBtJPG7ViZ4ihzK5QTocsy+hQzSc2PJwDX1fJpHKB EQA/RFeRLTJr3zY4XhBKS2oAa+B5JJSZCDA8ERCC90xUphL3aO1YUhXRTO02QxvVUSx2 1e30EOh4p0bMn5KNKvSyVKtEtTb7Ax7E7/G675BMxcI+Li1/BVDWvjXYfjHT36/xhzxN X7kQ== 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 (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id t16si2100473ejd.131.2019.01.29.10.49.51 for ; Tue, 29 Jan 2019 10:49:51 -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 58D2DA78; Tue, 29 Jan 2019 10:49:50 -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 AB2903F557; Tue, 29 Jan 2019 10:49:47 -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 , james.morse@arm.com Subject: [PATCH v8 04/26] ACPI / APEI: Make hest.c manage the estatus memory pool Date: Tue, 29 Jan 2019 18:48:40 +0000 Message-Id: <20190129184902.102850-5-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 ghes.c has a memory pool it uses for the estatus cache and the estatus queue. The cache is initialised when registering the platform driver. For the queue, an NMI-like notification has to grow/shrink the pool as it is registered and unregistered. This is all pretty noisy when adding new NMI-like notifications, it would be better to replace this with a static pool size based on the number of users. As a precursor, move the call that creates the pool from ghes_init(), into hest.c. Later this will take the number of ghes entries and consolidate the queue allocations. Remove ghes_estatus_pool_exit() as hest.c doesn't have anywhere to put this. The pool is now initialised as part of ACPI's subsys_initcall(): (acpi_init(), acpi_scan_init(), acpi_pci_root_init(), acpi_hest_init()) Before this patch it happened later as a GHES specific device_initcall(). Signed-off-by: James Morse Reviewed-by: Borislav Petkov --- Changes since v7: * Moved the pool init later, the driver isn't probed until device_init. --- drivers/acpi/apei/ghes.c | 33 ++++++--------------------------- drivers/acpi/apei/hest.c | 10 +++++++++- include/acpi/ghes.h | 2 ++ 3 files changed, 17 insertions(+), 28 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index ee9206d5e119..4150c72c78cb 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -162,26 +162,16 @@ static void ghes_iounmap_irq(void) clear_fixmap(FIX_APEI_GHES_IRQ); } -static int ghes_estatus_pool_init(void) +static int ghes_estatus_pool_expand(unsigned long len); //temporary + +int ghes_estatus_pool_init(void) { ghes_estatus_pool = gen_pool_create(GHES_ESTATUS_POOL_MIN_ALLOC_ORDER, -1); if (!ghes_estatus_pool) return -ENOMEM; - return 0; -} -static void ghes_estatus_pool_free_chunk(struct gen_pool *pool, - struct gen_pool_chunk *chunk, - void *data) -{ - vfree((void *)chunk->start_addr); -} - -static void ghes_estatus_pool_exit(void) -{ - gen_pool_for_each_chunk(ghes_estatus_pool, - ghes_estatus_pool_free_chunk, NULL); - gen_pool_destroy(ghes_estatus_pool); + return ghes_estatus_pool_expand(GHES_ESTATUS_CACHE_AVG_SIZE * + GHES_ESTATUS_CACHE_ALLOCED_MAX); } static int ghes_estatus_pool_expand(unsigned long len) @@ -1227,18 +1217,9 @@ static int __init ghes_init(void) ghes_nmi_init_cxt(); - rc = ghes_estatus_pool_init(); - if (rc) - goto err; - - rc = ghes_estatus_pool_expand(GHES_ESTATUS_CACHE_AVG_SIZE * - GHES_ESTATUS_CACHE_ALLOCED_MAX); - if (rc) - goto err_pool_exit; - rc = platform_driver_register(&ghes_platform_driver); if (rc) - goto err_pool_exit; + goto err; rc = apei_osc_setup(); if (rc == 0 && osc_sb_apei_support_acked) @@ -1251,8 +1232,6 @@ static int __init ghes_init(void) pr_info(GHES_PFX "Failed to enable APEI firmware first mode.\n"); return 0; -err_pool_exit: - ghes_estatus_pool_exit(); err: return rc; } diff --git a/drivers/acpi/apei/hest.c b/drivers/acpi/apei/hest.c index b1e9f81ebeea..097ba07a657b 100644 --- a/drivers/acpi/apei/hest.c +++ b/drivers/acpi/apei/hest.c @@ -32,6 +32,7 @@ #include #include #include +#include #include "apei-internal.h" @@ -203,6 +204,11 @@ static int __init hest_ghes_dev_register(unsigned int ghes_count) rc = apei_hest_parse(hest_parse_ghes, &ghes_arr); if (rc) goto err; + + rc = ghes_estatus_pool_init(); + if (rc) + goto err; + out: kfree(ghes_arr.ghes_devs); return rc; @@ -251,7 +257,9 @@ void __init acpi_hest_init(void) rc = apei_hest_parse(hest_parse_ghes_count, &ghes_count); if (rc) goto err; - rc = hest_ghes_dev_register(ghes_count); + + if (ghes_count) + rc = hest_ghes_dev_register(ghes_count); if (rc) goto err; } diff --git a/include/acpi/ghes.h b/include/acpi/ghes.h index 82cb4eb225a4..46ef5566e052 100644 --- a/include/acpi/ghes.h +++ b/include/acpi/ghes.h @@ -52,6 +52,8 @@ enum { GHES_SEV_PANIC = 0x3, }; +int ghes_estatus_pool_init(void); + /* From drivers/edac/ghes_edac.c */ #ifdef CONFIG_EDAC_GHES From patchwork Tue Jan 29 18:48:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786901 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 5892E1874 for ; Tue, 29 Jan 2019 18:49:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49BBF2D1A7 for ; Tue, 29 Jan 2019 18:49:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E1F92D1B9; Tue, 29 Jan 2019 18:49:58 +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 BDC8E2D1B8 for ; Tue, 29 Jan 2019 18:49:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5FADB8E000A; Tue, 29 Jan 2019 13:49:56 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5A93E8E0008; Tue, 29 Jan 2019 13:49:56 -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 470B08E000A; Tue, 29 Jan 2019 13:49:56 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id DD0B28E0008 for ; Tue, 29 Jan 2019 13:49:55 -0500 (EST) Received: by mail-ed1-f70.google.com with SMTP id b3so8351848edi.0 for ; Tue, 29 Jan 2019 10:49:55 -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=ITscJhVBj/odootafLFz/vckhUTU5gGBqQS3E9P7ckE=; b=Cgw6W3a5ZF56uppvdLdfYd57IDsRHgg2TLO/ZfcTDqOFnpgEGMAYKROEGqd2Tu9DwY YHpcABnHt//viQBNZCkcEQ5qro3CcuutKw+fbb2Y3wxwaWukrPRXoByQBcSWSLIpQ7Jy Xrob9wY2YEM9ZgnBys0L3K18MMMc4yYSmBdt5yXd+lzh3h2PcxDHWL+wLINDskRYIh8m 9dH3RAiBk5URc77tjIz7Pz6c+G5ARwV3WiQuZolMuDzfCeSmjP/Vic2gK3ZRc2KfPF7a TslLW9hWYTwYuQGEZdWmk0F3uZLqcfAdWPDwZIdLm/EXIJ/AKxydmQr9GA6SgIJt/qhg 9b0w== 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: AJcUukf7gAC1q2f+gQZM+8zkyjoKJj6C2CCsSamkTT0TKpVDHCzbBfZZ ZrymLe0q7pC/0BXhyFkFDU2d99uQdYZfep2RgADcGqpBWtTVp7IHdk6a/bX7evN43FN88SzHLpl j5RpRO8oAUAKukhaWV/hu/NXRfFXSYWB+wHZnKKBTwy0JKVGBFTU5PQdiYIi8By0jNQ== X-Received: by 2002:a17:906:1c0c:: with SMTP id k12mr8271824ejg.39.1548787795305; Tue, 29 Jan 2019 10:49:55 -0800 (PST) X-Google-Smtp-Source: ALg8bN7E1HV2LoVzVYYxvOBmPk/IwxxPnzc6bTxviZ2yFalo6ZEL3x80EQVAgE9+UBxZ3h+mPlKH X-Received: by 2002:a17:906:1c0c:: with SMTP id k12mr8271779ejg.39.1548787794260; Tue, 29 Jan 2019 10:49:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787794; cv=none; d=google.com; s=arc-20160816; b=G/kH4Y1ISYcMr0FmxxlNuwghgbAzIrEpiibe04TBqoABoRo2lsi3lZVlmeRXSH3dyo 2HOJ/lvAal55ZoVVSQS1XmnY+cUZru7010w2M4PXnq4GOtbXaGArkKe0b0FIWf4QF8Mn V9jkuWNahw7lt2v0DoP1+2OOtuzvFmNr6xwNxyY31zakY51FmKRpQopWIQq/0Lt4gZyQ E5v39VTNhFjFi+2NNzMMF94jP1E80bfe17gotMGlDgeB1wWObZJMPlfsl+d8Jesau+e3 HhnJe/ai7OdxCrNaGyXbW32djsxc1bX9wV7BN5bsjs76zyDLE/Nd9PFCCevO1x8Ubrcs +QJQ== 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=ITscJhVBj/odootafLFz/vckhUTU5gGBqQS3E9P7ckE=; b=J8OvFNAncob0ktsrwzkGB0VHXxjwrRlPWd3VMILG/9/mHDo00r/U9M0Nq36FwPrVrl pq++UBNIh+2ZcILlW+fDGpb9QBIWXuudWxCMTJ9SGQvWIpWkOcfunVm/c7INV75wSeU2 fHYolEjsqGjhzD3FaXqORLfOohlfYIFsqdYhimHapLiJmKRz5sXYDaQuqcWg9IqGl10E CyBQpz4F03OrKRNAlSzgS8YruQhqHnWBa9k7ErBgyVrGdwEPG+hBnJK5a3OeQOKo092I 27O2aM2MNlx6Ogro1ot3QFb05Kazfi0BqvADiUFsXrFgLCnfo5DQtQS80pwYdnrJGyve MuMA== 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 (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id q15-v6si2728934ejj.286.2019.01.29.10.49.53 for ; Tue, 29 Jan 2019 10:49:54 -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 45797A78; Tue, 29 Jan 2019 10:49:53 -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 97B233F557; Tue, 29 Jan 2019 10:49:50 -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 , james.morse@arm.com Subject: [PATCH v8 05/26] ACPI / APEI: Make estatus pool allocation a static size Date: Tue, 29 Jan 2019 18:48:41 +0000 Message-Id: <20190129184902.102850-6-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 Adding new NMI-like notifications duplicates the calls that grow and shrink the estatus pool. This is all pretty pointless, as the size is capped to 64K. Allocate this for each ghes and drop the code that grows and shrinks the pool. Suggested-by: Borislav Petkov Signed-off-by: James Morse Reviewed-by: Borislav Petkov --- drivers/acpi/apei/ghes.c | 49 +++++----------------------------------- drivers/acpi/apei/hest.c | 2 +- include/acpi/ghes.h | 2 +- 3 files changed, 8 insertions(+), 45 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 4150c72c78cb..33144ab0661a 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -162,27 +162,18 @@ static void ghes_iounmap_irq(void) clear_fixmap(FIX_APEI_GHES_IRQ); } -static int ghes_estatus_pool_expand(unsigned long len); //temporary - -int ghes_estatus_pool_init(void) +int ghes_estatus_pool_init(int num_ghes) { + unsigned long addr, len; + ghes_estatus_pool = gen_pool_create(GHES_ESTATUS_POOL_MIN_ALLOC_ORDER, -1); if (!ghes_estatus_pool) return -ENOMEM; - return ghes_estatus_pool_expand(GHES_ESTATUS_CACHE_AVG_SIZE * - GHES_ESTATUS_CACHE_ALLOCED_MAX); -} - -static int ghes_estatus_pool_expand(unsigned long len) -{ - unsigned long size, addr; - - ghes_estatus_pool_size_request += PAGE_ALIGN(len); - size = gen_pool_size(ghes_estatus_pool); - if (size >= ghes_estatus_pool_size_request) - return 0; + len = GHES_ESTATUS_CACHE_AVG_SIZE * GHES_ESTATUS_CACHE_ALLOCED_MAX; + len += (num_ghes * GHES_ESOURCE_PREALLOC_MAX_SIZE); + ghes_estatus_pool_size_request = PAGE_ALIGN(len); addr = (unsigned long)vmalloc(PAGE_ALIGN(len)); if (!addr) return -ENOMEM; @@ -956,32 +947,8 @@ static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) return ret; } -static unsigned long ghes_esource_prealloc_size( - const struct acpi_hest_generic *generic) -{ - unsigned long block_length, prealloc_records, prealloc_size; - - block_length = min_t(unsigned long, generic->error_block_length, - GHES_ESTATUS_MAX_SIZE); - prealloc_records = max_t(unsigned long, - generic->records_to_preallocate, 1); - prealloc_size = min_t(unsigned long, block_length * prealloc_records, - GHES_ESOURCE_PREALLOC_MAX_SIZE); - - return prealloc_size; -} - -static void ghes_estatus_pool_shrink(unsigned long len) -{ - ghes_estatus_pool_size_request -= PAGE_ALIGN(len); -} - static void ghes_nmi_add(struct ghes *ghes) { - unsigned long len; - - len = ghes_esource_prealloc_size(ghes->generic); - ghes_estatus_pool_expand(len); mutex_lock(&ghes_list_mutex); if (list_empty(&ghes_nmi)) register_nmi_handler(NMI_LOCAL, ghes_notify_nmi, 0, "ghes"); @@ -991,8 +958,6 @@ static void ghes_nmi_add(struct ghes *ghes) static void ghes_nmi_remove(struct ghes *ghes) { - unsigned long len; - mutex_lock(&ghes_list_mutex); list_del_rcu(&ghes->list); if (list_empty(&ghes_nmi)) @@ -1003,8 +968,6 @@ static void ghes_nmi_remove(struct ghes *ghes) * freed after NMI handler finishes. */ synchronize_rcu(); - len = ghes_esource_prealloc_size(ghes->generic); - ghes_estatus_pool_shrink(len); } static void ghes_nmi_init_cxt(void) diff --git a/drivers/acpi/apei/hest.c b/drivers/acpi/apei/hest.c index 097ba07a657b..fcc8cc1e4f3d 100644 --- a/drivers/acpi/apei/hest.c +++ b/drivers/acpi/apei/hest.c @@ -205,7 +205,7 @@ static int __init hest_ghes_dev_register(unsigned int ghes_count) if (rc) goto err; - rc = ghes_estatus_pool_init(); + rc = ghes_estatus_pool_init(ghes_count); if (rc) goto err; diff --git a/include/acpi/ghes.h b/include/acpi/ghes.h index 46ef5566e052..cd9ee507d860 100644 --- a/include/acpi/ghes.h +++ b/include/acpi/ghes.h @@ -52,7 +52,7 @@ enum { GHES_SEV_PANIC = 0x3, }; -int ghes_estatus_pool_init(void); +int ghes_estatus_pool_init(int num_ghes); /* From drivers/edac/ghes_edac.c */ From patchwork Tue Jan 29 18:48:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786905 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 AC2F191E for ; Tue, 29 Jan 2019 18:50:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CDDD2D1A7 for ; Tue, 29 Jan 2019 18:50:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E9352D1B9; Tue, 29 Jan 2019 18:50:01 +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 EDA2F2D1A7 for ; Tue, 29 Jan 2019 18:50:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 55A7C8E000B; Tue, 29 Jan 2019 13:49:59 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 50D608E0008; Tue, 29 Jan 2019 13:49:59 -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 3861F8E000B; Tue, 29 Jan 2019 13:49:59 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id D4EE78E0008 for ; Tue, 29 Jan 2019 13:49:58 -0500 (EST) Received: by mail-ed1-f71.google.com with SMTP id y35so8312908edb.5 for ; Tue, 29 Jan 2019 10:49:58 -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=wnz8yl/7ZDxGsxncPzV542oeZz/bggs58LBo1ZJN2WI=; b=a0cWV25lbeRhK0AqMnhCCpqHo3HDWyGITUeDjq0xvUcaDta6VtwmBKo+EWcYLcmnJK QvqEdFRYi9VlBFtqA+O3yn8xFkO3L3KQ59IXL2hoGIQOjMi1WSuTQtQY3RiapFosluXs 4YIyVeiGdcwBLNQzF0kKxhFuXgH6FHz+uVASIBju8ZgEJJyBLHLCry4/oe8cEdpDFgjY pBIK8/ZnWsRuNUiuEf3j/64auyMC51f0x5jshHEVGmEb0iR5WYwwamyppDM6IotR+sFL wvJWNMHmdYzNsM58FyulDsA69icynuVNtwHj/UpkO7/dMOm5NQxpdadDqV6VHFZ0tcKt wpYA== 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: AJcUuke9NC27rEVAVOoXrZEGhulByGXhgcfKrxb5RLIoLraPkLxX6rsQ K30QxDTYDPZlEAL4/QynpOkt/GLMtBSMdn/a8JfXaIYci35PjcODE9fxaHCc7Wsq8wNxR4eVr76 Xh/VYg+QGu1wxTM39cX/QsAEpyzK6V+tsuWhyhCEWW0DJJt7R6/USU04xEJQZGDFp4g== X-Received: by 2002:aa7:db0e:: with SMTP id t14mr26815850eds.292.1548787798318; Tue, 29 Jan 2019 10:49:58 -0800 (PST) X-Google-Smtp-Source: ALg8bN68+by8OSl0TUAYMRV91V3kDOpfnZmfpyiiaABjTe9pgf1c7BcbLsq+sweIRop4qW2E3lIo X-Received: by 2002:aa7:db0e:: with SMTP id t14mr26815786eds.292.1548787797302; Tue, 29 Jan 2019 10:49:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787797; cv=none; d=google.com; s=arc-20160816; b=zeGvYqAMtWNDuFzWgch5lWp7aS1CKREIC0fl83TTmXWWy6rGh8ICZXSLSFRBPJXznq 3vwfAjzEbEaMuCADDoxaTqNArNgwnqHJE2e6/RbQTAEFm7VOWC9Hg1TFxvj0CCk1TcbN egE9JV3uZTahs2FyRxbaKsSGVrs5KljRhKhTYflXPfWnsu5oGDBW+mK04NMavuaiqBXC Xym5Tj3+7ML7AbbW0uP6iTjuWJcLUYM2K0kpjs1LlFJpMbxx23PxQZtbl5BKdbXf9g3a A9LKRkYyLVzVNo8K+cvs+ryd4rp8lgIe5krNoMcJs1/AiKusJF4ettdkQO+PM2mcBMmK IqYw== 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=wnz8yl/7ZDxGsxncPzV542oeZz/bggs58LBo1ZJN2WI=; b=zpKmof5eZWSlOszrtzTeUaCIiQx6CU2DKb6mEsbf9+RmuRT/AuErA6u12TtoroO86x 5hbMVLofW4CKzVCTdcgZnz39cqyxST69jx8ODnb8dPJ00S8wpw7EnRalDfTelpyTFUkT 7PZNC8qnzw3RNwYOINsqBvsREt/0Lm+VlPy7RsfNIvznv4XrCGo0Q3NB0Gy67ekrgL3W FRe7jVIGYRtYIW+lxXN/3EpYJLxW0RLUsKj8VGhhsSEfprmrHxluFfcQrziXCVR3HTiK /ZWCC6iKWzvtOJvaX5XeTq0qNqVXs5ItyR7Ckyqca0vnwMWJfrRDQpz9okyaY3NYDuL3 AU0Q== 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 (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id v3-v6si1218521eji.60.2019.01.29.10.49.56 for ; Tue, 29 Jan 2019 10:49:57 -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 324F5A78; Tue, 29 Jan 2019 10:49:56 -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 847653F557; Tue, 29 Jan 2019 10:49:53 -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 , james.morse@arm.com Subject: [PATCH v8 06/26] ACPI / APEI: Don't store CPER records physical address in struct ghes Date: Tue, 29 Jan 2019 18:48:42 +0000 Message-Id: <20190129184902.102850-7-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 When CPER records are found the address of the records is stashed in the struct ghes. Once the records have been processed, this address is overwritten with zero so that it won't be processed again without being re-populated by firmware. This goes wrong if a struct ghes can be processed concurrently, as can happen at probe time when an NMI occurs. If the NMI arrives on another CPU, the probing CPU may call ghes_clear_estatus() on the records before the handler had finished with them. Even on the same CPU, once the interrupted handler is resumed, it will call ghes_clear_estatus() on the NMIs records, this memory may have already been re-used by firmware. Avoid this stashing by letting the caller hold the address. A later patch will do away with the use of ghes->flags in the read/clear code too. Signed-off-by: James Morse Reviewed-by: Borislav Petkov --- Changes since v7: * Added buf_paddr to ghes_panic, as it wants to print the estatus Changes since v6: * Moved earlier in the series * Added buf_adder = 0 on all the error paths, and test for it in ghes_estatus_clear() for extra sanity. --- drivers/acpi/apei/ghes.c | 46 +++++++++++++++++++++++----------------- include/acpi/ghes.h | 1 - 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 33144ab0661a..a34f79153b1a 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -305,29 +305,30 @@ static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len, } } -static int ghes_read_estatus(struct ghes *ghes) +static int ghes_read_estatus(struct ghes *ghes, u64 *buf_paddr) { struct acpi_hest_generic *g = ghes->generic; - u64 buf_paddr; u32 len; int rc; - rc = apei_read(&buf_paddr, &g->error_status_address); + rc = apei_read(buf_paddr, &g->error_status_address); if (rc) { + *buf_paddr = 0; pr_warn_ratelimited(FW_WARN GHES_PFX "Failed to read error status block address for hardware error source: %d.\n", g->header.source_id); return -EIO; } - if (!buf_paddr) + if (!*buf_paddr) return -ENOENT; - ghes_copy_tofrom_phys(ghes->estatus, buf_paddr, + ghes_copy_tofrom_phys(ghes->estatus, *buf_paddr, sizeof(*ghes->estatus), 1); - if (!ghes->estatus->block_status) + if (!ghes->estatus->block_status) { + *buf_paddr = 0; return -ENOENT; + } - ghes->buffer_paddr = buf_paddr; ghes->flags |= GHES_TO_CLEAR; rc = -EIO; @@ -339,7 +340,7 @@ static int ghes_read_estatus(struct ghes *ghes) if (cper_estatus_check_header(ghes->estatus)) goto err_read_block; ghes_copy_tofrom_phys(ghes->estatus + 1, - buf_paddr + sizeof(*ghes->estatus), + *buf_paddr + sizeof(*ghes->estatus), len - sizeof(*ghes->estatus), 1); if (cper_estatus_check(ghes->estatus)) goto err_read_block; @@ -349,15 +350,20 @@ static int ghes_read_estatus(struct ghes *ghes) if (rc) pr_warn_ratelimited(FW_WARN GHES_PFX "Failed to read error status block!\n"); + return rc; } -static void ghes_clear_estatus(struct ghes *ghes) +static void ghes_clear_estatus(struct ghes *ghes, u64 buf_paddr) { ghes->estatus->block_status = 0; if (!(ghes->flags & GHES_TO_CLEAR)) return; - ghes_copy_tofrom_phys(ghes->estatus, ghes->buffer_paddr, + + if (!buf_paddr) + return; + + ghes_copy_tofrom_phys(ghes->estatus, buf_paddr, sizeof(ghes->estatus->block_status), 0); ghes->flags &= ~GHES_TO_CLEAR; } @@ -666,11 +672,11 @@ static int ghes_ack_error(struct acpi_hest_generic_v2 *gv2) return apei_write(val, &gv2->read_ack_register); } -static void __ghes_panic(struct ghes *ghes) +static void __ghes_panic(struct ghes *ghes, u64 buf_paddr) { __ghes_print_estatus(KERN_EMERG, ghes->generic, ghes->estatus); - ghes_clear_estatus(ghes); + ghes_clear_estatus(ghes, buf_paddr); /* reboot to log the error! */ if (!panic_timeout) @@ -680,14 +686,15 @@ static void __ghes_panic(struct ghes *ghes) static int ghes_proc(struct ghes *ghes) { + u64 buf_paddr; int rc; - rc = ghes_read_estatus(ghes); + rc = ghes_read_estatus(ghes, &buf_paddr); if (rc) goto out; if (ghes_severity(ghes->estatus->error_severity) >= GHES_SEV_PANIC) { - __ghes_panic(ghes); + __ghes_panic(ghes, buf_paddr); } if (!ghes_estatus_cached(ghes->estatus)) { @@ -697,7 +704,7 @@ static int ghes_proc(struct ghes *ghes) ghes_do_proc(ghes, ghes->estatus); out: - ghes_clear_estatus(ghes); + ghes_clear_estatus(ghes, buf_paddr); if (rc == -ENOENT) return rc; @@ -912,6 +919,7 @@ static void __process_error(struct ghes *ghes) static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) { + u64 buf_paddr; struct ghes *ghes; int sev, ret = NMI_DONE; @@ -919,8 +927,8 @@ static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) return ret; list_for_each_entry_rcu(ghes, &ghes_nmi, list) { - if (ghes_read_estatus(ghes)) { - ghes_clear_estatus(ghes); + if (ghes_read_estatus(ghes, &buf_paddr)) { + ghes_clear_estatus(ghes, buf_paddr); continue; } else { ret = NMI_HANDLED; @@ -929,14 +937,14 @@ static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) sev = ghes_severity(ghes->estatus->error_severity); if (sev >= GHES_SEV_PANIC) { ghes_print_queued_estatus(); - __ghes_panic(ghes); + __ghes_panic(ghes, buf_paddr); } if (!(ghes->flags & GHES_TO_CLEAR)) continue; __process_error(ghes); - ghes_clear_estatus(ghes); + ghes_clear_estatus(ghes, buf_paddr); } #ifdef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG diff --git a/include/acpi/ghes.h b/include/acpi/ghes.h index cd9ee507d860..f82f4a7ddd90 100644 --- a/include/acpi/ghes.h +++ b/include/acpi/ghes.h @@ -22,7 +22,6 @@ struct ghes { struct acpi_hest_generic_v2 *generic_v2; }; struct acpi_hest_generic_status *estatus; - u64 buffer_paddr; unsigned long flags; union { struct list_head list; From patchwork Tue Jan 29 18:48:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786909 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 67CFC91E for ; Tue, 29 Jan 2019 18:50:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 581B62D1D2 for ; Tue, 29 Jan 2019 18:50:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4C0DA2D1A7; Tue, 29 Jan 2019 18:50:04 +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 EE73B2D1A7 for ; Tue, 29 Jan 2019 18:50:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B9D3D8E0008; Tue, 29 Jan 2019 13:50:01 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B4BA58E0003; Tue, 29 Jan 2019 13:50:01 -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 A11D18E0008; Tue, 29 Jan 2019 13:50:01 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id 5CDC78E0003 for ; Tue, 29 Jan 2019 13:50:01 -0500 (EST) Received: by mail-ed1-f72.google.com with SMTP id y35so8312950edb.5 for ; Tue, 29 Jan 2019 10:50:01 -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=k7wnSh0/AWdeE9IE2N0pFqQz9uaZdVz3WI19ff9zm4Y=; b=FJuJhWZoUUSO09RJr7MPslNi45iVntgw2H9GvtYi/CU7i8wORXIhvbi+UwZQ5F98Yq vMx7ktK6CLPqDEAuKlQGn0vmck38ddcowuRTuHAAwAFyc1nv2HxPe3hT9YWBwwKD2xmq CkdKoToVmcPAt+QhPS6Y4gB4fB0jPj5GT91/jDZev0exbCx4Vr37wqM1kFFhESDkSpZM CyvgaEW54X5VcAoBuITyAHOaSVPq+7FQCMsV59f3THSNBlGUAvNo+ATaPAuskN+A63MF uricGFaPzzsn5n+rEgxulKAEkSq5g286xW2/vaY9RtjRotc1uPDu6Iyfh7fmieq4dxhT lt3w== 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: AJcUukeEKq4T1mTSAM27zkGYSbdz+pF5KaeSSZySmoDfA8wmAvGrAaCK rxxb0pKrBu5LkxjDhvvmpt1STxEco1h12b+ObxyjyW+VCaRnveDc111ifIY5bvyqT8tVicX8j48 MLFnbRbmjlOCM5LnrQdpr14marJi5exvhT+OhQpvxcb+EQH6N5c1VGi7I7elESDZ81A== X-Received: by 2002:aa7:dd0f:: with SMTP id i15mr25423213edv.29.1548787800875; Tue, 29 Jan 2019 10:50:00 -0800 (PST) X-Google-Smtp-Source: ALg8bN5D/cc8Pvfobcng/yVBMiKgAPkUgKyyyYppoPx1g0GomMPjvQGYUJFwK2V5777bi8duKdXr X-Received: by 2002:aa7:dd0f:: with SMTP id i15mr25423178edv.29.1548787800094; Tue, 29 Jan 2019 10:50:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787800; cv=none; d=google.com; s=arc-20160816; b=GjGlk4f426yTjjEvibDoiHD0/D7QqZr656Wf4Nxs6PmLQ35yJ9q553rFHYLZ8VL9q4 HCpjisgnNSNvVeXVFx5kctCguAKYEtiZmLk0SF+Ds5Qv6S+aAVt3dqsb9z32gvNOg7dG 8HUlVbva8c4q9rh1lB3M0Yyd3Btk9LKX97SOqXVyC9lLGdxE18CHR8eMByTa+K7wa+xL VFvp3JbIO/hfhJTXW6DDjA8z37tPi2/wpwKGc4+0fv+8aecN2GylaXK4+poxG8SVcQT6 qpeqBnacYPwaWaKH84mY1qBaqdL3BzKrDixtWVfuV0vAYLOvMzv3N9dHVMqb+9StpQXD h+5w== 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=k7wnSh0/AWdeE9IE2N0pFqQz9uaZdVz3WI19ff9zm4Y=; b=EHfQlshV/aIZQrTZIuoQk0vEqc/YATmIqIr9HGFLxGlQvb95WzP4TMRMQhlpuwQkUa 5CNm5Rcmbq14Qf3AlgBBW4S+igJ5XseBmMPKPDsStB0mknEWmaZBdV+EHUxEYqjf8tNj DAYnT5UjLNVGn8fm3fopO33M3i1xvl40dR12jgl87X1b9EDqbaDiDYP2JucNzXE8I7eN 9enCYWqpGg20T79XIf2FHYEJ+bj0WqyUfMZT1Uih/BcXADQ1bBkjRT5BWc9wd6PO/QYc Wf4riXEOPCLBtINRIlJaztI3VXiJ3aa31Njt40fQAmZflvMHbKXnL5DfjbMpzXPkP/u+ COmA== 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 m22si3009302edj.434.2019.01.29.10.49.59 for ; Tue, 29 Jan 2019 10:50:00 -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 1E30E1596; Tue, 29 Jan 2019 10:49:59 -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 711903F557; Tue, 29 Jan 2019 10:49:56 -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 , james.morse@arm.com Subject: [PATCH v8 07/26] ACPI / APEI: Remove spurious GHES_TO_CLEAR check Date: Tue, 29 Jan 2019 18:48:43 +0000 Message-Id: <20190129184902.102850-8-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 ghes_notify_nmi() checks ghes->flags for GHES_TO_CLEAR before going on to __process_error(). This is pointless as ghes_read_estatus() will always set this flag if it returns success, which was checked earlier in the loop. Remove it. Signed-off-by: James Morse Reviewed-by: Borislav Petkov --- drivers/acpi/apei/ghes.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index a34f79153b1a..c20e1d0947b1 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -940,9 +940,6 @@ static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) __ghes_panic(ghes, buf_paddr); } - if (!(ghes->flags & GHES_TO_CLEAR)) - continue; - __process_error(ghes); ghes_clear_estatus(ghes, buf_paddr); } From patchwork Tue Jan 29 18:48:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786913 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 64EAD1874 for ; Tue, 29 Jan 2019 18:50:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 559872D1E3 for ; Tue, 29 Jan 2019 18:50:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 533892D200; Tue, 29 Jan 2019 18:50:07 +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 DFF772D1E3 for ; Tue, 29 Jan 2019 18:50:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EABCB8E0004; Tue, 29 Jan 2019 13:50:04 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E322C8E0003; Tue, 29 Jan 2019 13:50:04 -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 D22778E0004; Tue, 29 Jan 2019 13:50:04 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id 6FD878E0003 for ; Tue, 29 Jan 2019 13:50:04 -0500 (EST) Received: by mail-ed1-f72.google.com with SMTP id b7so8302790eda.10 for ; Tue, 29 Jan 2019 10:50:04 -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=IaVEJgJnSKvnLaX5eMVFN2DgBpxjFPyX7OIO8GDCklo=; b=aCjIYYuE4tjR6RQJY2tNM7oUj+jR7yVo45xdK3qtKFdMGvC9AgFerawgF9Q2ign2iU BjATs7I7GRMYj7ruwsCqHHv4+ody5qcXn789A4sBgHKRNuO+jWDGLU9p9BRVCJfX6vOV TH/W/C5FM+TdZOFot1jxWgGnpX8fkTfXehSkz/eaiY03UJwDxolIAEplhXcNsO7LvH0J zpF37/7cWNStT/N0eMl45555t6Bw6fVmmvK1LKZAZb67FLvWG2hV6xdUrY/tmKq6PHp/ EFO6SKF/kjI56FzEamQFrAfelqiqIpmrRZ8wM8aR2FJmcyfoMKi4U3Jh0wMve0sBpMJw x4XQ== 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: AJcUukdTMW6NPAIVCEAQb4gzQeE6kvWXuX49ppe1LXcvofjMsKz419AT AiSI56hWSgqTxtlSJJbWo3AZLi2EEMbFuewTVslI3pYwRP2cCfO7Adjib3K7LOf0B/v93v5/onT Ph/sQd9ByZDw6suAUBOm/0aHCOoeBZRc9HIt1DNKJQFr/m/wljs7Shp17fGCLklyy/g== X-Received: by 2002:a17:906:394e:: with SMTP id g14-v6mr4997240eje.0.1548787803931; Tue, 29 Jan 2019 10:50:03 -0800 (PST) X-Google-Smtp-Source: ALg8bN5JZM5u8M3GM6PYeIx0sDK+7e14r3f2qMZtZtNk3Jd1Ze9WFWEiBfL5CKlEJSSKOfbvRPmk X-Received: by 2002:a17:906:394e:: with SMTP id g14-v6mr4997192eje.0.1548787802910; Tue, 29 Jan 2019 10:50:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787802; cv=none; d=google.com; s=arc-20160816; b=Bgx/8ZwNpmIMsj1gLbbHS2e5LPSy0B+hqbp/gyDlkKCU8ZF+lI5MyMHtfl/PuGpbsi 2/Mn0NdNcVsYU4D9L6LQsAnKZj8SDGB2QCeURnPXwDQDyJmsEvakWxi/7VO0+7c04Sk1 hcFzTn/Ldk45em64i0yTwb5DqCZhfBmUoQuMHFpa/kOagrdH+TU0ti5RmA9lOtp+QaYb qhchxtOD9s6xR+qqKMuPVX8vDaoh0M7iSMal454Q8mOVUIJsvQi6pFYor0WmNTCrCjO+ BOEvTTtkiNlpnuQu9GNNZvxqstxZ+Jdos9o4yV5M87jmUvD03ooIgJUOpcTQcUQsbDO7 BbOw== 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=IaVEJgJnSKvnLaX5eMVFN2DgBpxjFPyX7OIO8GDCklo=; b=ebWs6Ftggf6kVcyBZWbftYRqIVcc6tvfBQ2HJPT1jfUEBlVUaHvYkITEnjhGwbLTOa 9p18j0ij78jdcFdVQiIIKGQWi04Qf7sadkbwCznlEmVkQdRq24TFYTLHJYO2kcvO/gae r9nUpaJTg3hx7ICKqhQWvJSftaVbuPgA518bdytlAQQkqu80ovO0ku//alb50iRo/F6r quCTQyLxNgylnkJfNZRTZJ0nyhZWlBUIU3Vr11MWron9m1Usxk4g8DF80PojZ3uvZb0h YfO+ul2OtXMFdJEqmWwC/FyVpyHeB3W9nwFMjecnWOb7gZc77o7IKbM/60tCtWXnIhiB kASQ== 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 (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id d29si333189ejn.154.2019.01.29.10.50.02 for ; Tue, 29 Jan 2019 10:50:02 -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 0A08DA78; Tue, 29 Jan 2019 10:50:02 -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 5CF633F557; Tue, 29 Jan 2019 10:49:59 -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 , james.morse@arm.com Subject: [PATCH v8 08/26] ACPI / APEI: Don't update struct ghes' flags in read/clear estatus Date: Tue, 29 Jan 2019 18:48:44 +0000 Message-Id: <20190129184902.102850-9-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 ghes_read_estatus() sets a flag in struct ghes if the buffer of CPER records needs to be cleared once the records have been processed. This flag value is a problem if a struct ghes can be processed concurrently, as happens at probe time if an NMI arrives for the same error source. The NMI clears the flag, meaning the interrupted handler may never do the ghes_estatus_clear() work. The GHES_TO_CLEAR flags is only set at the same time as buffer_paddr, which is now owned by the caller and passed to ghes_clear_estatus(). Use this value as the flag. A non-zero buf_paddr returned by ghes_read_estatus() means ghes_clear_estatus() should clear this address. ghes_read_estatus() already checks for a read of error_status_address being zero, so CPER records cannot be written here. Signed-off-by: James Morse Reviewed-by: Borislav Petkov --- Changes since v6: * Added Boris' RB, then: * Moved earlier in the series, * Tinkered with the commit message, * Always cleared buf_paddr on errors in the previous patch, which was previously in here. --- drivers/acpi/apei/ghes.c | 5 ----- include/acpi/ghes.h | 1 - 2 files changed, 6 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index c20e1d0947b1..af3c10f47f20 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -329,8 +329,6 @@ static int ghes_read_estatus(struct ghes *ghes, u64 *buf_paddr) return -ENOENT; } - ghes->flags |= GHES_TO_CLEAR; - rc = -EIO; len = cper_estatus_len(ghes->estatus); if (len < sizeof(*ghes->estatus)) @@ -357,15 +355,12 @@ static int ghes_read_estatus(struct ghes *ghes, u64 *buf_paddr) static void ghes_clear_estatus(struct ghes *ghes, u64 buf_paddr) { ghes->estatus->block_status = 0; - if (!(ghes->flags & GHES_TO_CLEAR)) - return; if (!buf_paddr) return; ghes_copy_tofrom_phys(ghes->estatus, buf_paddr, sizeof(ghes->estatus->block_status), 0); - ghes->flags &= ~GHES_TO_CLEAR; } static void ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata, int sev) diff --git a/include/acpi/ghes.h b/include/acpi/ghes.h index f82f4a7ddd90..e3f1cddb4ac8 100644 --- a/include/acpi/ghes.h +++ b/include/acpi/ghes.h @@ -13,7 +13,6 @@ * estatus: memory buffer for error status block, allocated during * HEST parsing. */ -#define GHES_TO_CLEAR 0x0001 #define GHES_EXITING 0x0002 struct ghes { From patchwork Tue Jan 29 18:48:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786917 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 9C8B891E for ; Tue, 29 Jan 2019 18:50:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D4232D21E for ; Tue, 29 Jan 2019 18:50:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B3D62D256; Tue, 29 Jan 2019 18:50:10 +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 182C72D286 for ; Tue, 29 Jan 2019 18:50:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 61D8A8E000C; Tue, 29 Jan 2019 13:50:08 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5F5FD8E0003; Tue, 29 Jan 2019 13:50:08 -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 3FB658E000C; Tue, 29 Jan 2019 13:50:08 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id D84708E0003 for ; Tue, 29 Jan 2019 13:50:07 -0500 (EST) Received: by mail-ed1-f72.google.com with SMTP id c53so8419867edc.9 for ; Tue, 29 Jan 2019 10:50:07 -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=zuDCjHKH0Pheb2PX+fbOrjU+7Fi6QYf32iCk7O3WPu8=; b=oSFdOgJtkUooDUuiJG21eV0LeeryjwQ2VuaZTVMRkMtUPS3gFB00yK20O6wQSZkfmH 55yS+7lJ0eDWqW0Bq2AAdIjCAAsLjznW34geLGorMUM27AteY+Gj+zQjidJrWxt/shtp 2twmWgFkLy9y5YccEg1gooQ0TwTA5VAD8TC6QsgeiYhjnIDB+YMEJwLsl36XRWAzdTG1 R3JA3RHvCtXAZez/OfuBVmykRUXLlp3LKhocB4xweeOJuhPctTutn+d4idrK26Uxm8XB zpQYI+G3USZbpHD9mZQwusL7NXrVS0acXTJRaSxwWKj4QoHZC25z96suxPanC1KRrmlt wrEg== 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: AJcUukcyvvNPjXle/fCX8ceOF5Hg963wTCKVk7voi0McvZ0KO1Tay1DJ xScZHJp453b8brEmqeKKO2uGbuC2Ca7ww5xg5VEW4wMPJAmyNdqaJClkLRRSUnjunJRnx4032pj PSaaIcPMe4nvHnrnsOh76UV74RXia064TOJDiEyAXTszq13P5oohQrOay+mHug1WMJQ== X-Received: by 2002:a17:906:e96:: with SMTP id p22mr11108151ejf.109.1548787807370; Tue, 29 Jan 2019 10:50:07 -0800 (PST) X-Google-Smtp-Source: ALg8bN4muYygbx9yyGT1hXyeqsZj60gUylFwGAlO00lkD88JXDODd+LTpaMpbvUfUCtRvq1kpySP X-Received: by 2002:a17:906:e96:: with SMTP id p22mr11108088ejf.109.1548787806163; Tue, 29 Jan 2019 10:50:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787806; cv=none; d=google.com; s=arc-20160816; b=tHT1nW6ySUySTQXQ09pnFZG9aWhrxVB+qUAePgzgneagBNfxoifu0rYhc9EH/S61sO X5yK1URPtLHZgtZ3a2Us7HUIHK4zBuJbpFLZ+BBFhqeECklqOgoJAgfQn1ZCkqsnYw7i y3WhnOfQ9MgXs4iqUEWyfWctZdtBQnM2xv7Ic9e8Jm9nGr/jtdU7FT59h0eVfbFFZR6A sXGN/OdOSip3EspbNBPdUQvJnRVdu3JkywZnZ0Lm9E1ijYl4Znc6VQtUsHjfnmuA5bVw tdNgyh+F5B2t5HFpFQK+HErmeaYV4NuUXyDAZnBf6OAhSB5Zs6JIXJS66uzwoFZgt3Ns CqBQ== 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=zuDCjHKH0Pheb2PX+fbOrjU+7Fi6QYf32iCk7O3WPu8=; b=WDe1DrRjBR93SklSSgr9N3dsY0+lH2gpQEccunZfw3dL19J0/8QGjmqvM1kkFraSKS GfzWlisxDD7vHyG7Ri70e0gFdfrUOwruXo3IaVQcrauJzc0Cms4qVyC3QlznNChkutvd yJZD2r866QQa+f/pH2TROd6Ha76uAimKOuLu0uI3KFIoWxNLHMq266yK1T4WAjSgxy86 TYzHdME3oPh+HL8mUtOhEGTZulETWUPW0Gqq0jdnq2SYbyPzV4sF0ukZWKAfAMZGwNtQ 9ZssgApkxgts3EXFTKy8IKRWL5h+UukT380l2RYKH4cjg2a/mcuII2W4A4QISOLy7+5g wpMQ== 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 z31si2458721ede.13.2019.01.29.10.50.05 for ; Tue, 29 Jan 2019 10:50:06 -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 EA8C41596; Tue, 29 Jan 2019 10:50:04 -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 48CA03F557; Tue, 29 Jan 2019 10:50:02 -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 , james.morse@arm.com Subject: [PATCH v8 09/26] ACPI / APEI: Generalise the estatus queue's notify code Date: Tue, 29 Jan 2019 18:48:45 +0000 Message-Id: <20190129184902.102850-10-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 Refactor the estatus queue's pool notification routine from NOTIFY_NMI's handlers. This will allow another notification method to use the estatus queue without duplicating this code. Add rcu_read_lock()/rcu_read_unlock() around the list list_for_each_entry_rcu() walker. These aren't strictly necessary as the whole nmi_enter/nmi_exit() window is a spooky RCU read-side critical section. in_nmi_queue_one_entry() is separate from the rcu-list walker for a later caller that doesn't need to walk a list. Signed-off-by: James Morse Reviewed-by: Punit Agrawal Tested-by: Tyler Baicar --- Changes since v7: * Moved err= onto a separate line to make this more readable * Dropped ghes_ prefix on new static functions * Renamed stuff, 'notify' has an overloaded meaning, Changes since v6: * Removed pool grow/remove code as this is no longer necessary. Changes since v3: * Removed duplicate or redundant paragraphs in commit message. * Fixed the style of a zero check. Changes since v1: * Tidied up _in_nmi_notify_one(). --- drivers/acpi/apei/ghes.c | 65 ++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index af3c10f47f20..cb3d88de711f 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -912,37 +912,58 @@ static void __process_error(struct ghes *ghes) #endif } -static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) +static int ghes_in_nmi_queue_one_entry(struct ghes *ghes) { u64 buf_paddr; - struct ghes *ghes; - int sev, ret = NMI_DONE; + int sev; - if (!atomic_add_unless(&ghes_in_nmi, 1, 1)) - return ret; + if (ghes_read_estatus(ghes, &buf_paddr)) { + ghes_clear_estatus(ghes, buf_paddr); + return -ENOENT; + } - list_for_each_entry_rcu(ghes, &ghes_nmi, list) { - if (ghes_read_estatus(ghes, &buf_paddr)) { - ghes_clear_estatus(ghes, buf_paddr); - continue; - } else { - ret = NMI_HANDLED; - } + sev = ghes_severity(ghes->estatus->error_severity); + if (sev >= GHES_SEV_PANIC) { + ghes_print_queued_estatus(); + __ghes_panic(ghes, buf_paddr); + } - sev = ghes_severity(ghes->estatus->error_severity); - if (sev >= GHES_SEV_PANIC) { - ghes_print_queued_estatus(); - __ghes_panic(ghes, buf_paddr); - } + __process_error(ghes); + ghes_clear_estatus(ghes, buf_paddr); - __process_error(ghes); - ghes_clear_estatus(ghes, buf_paddr); + return 0; +} + +static int ghes_in_nmi_spool_from_list(struct list_head *rcu_list) +{ + int err, ret = -ENOENT; + struct ghes *ghes; + + rcu_read_lock(); + list_for_each_entry_rcu(ghes, rcu_list, list) { + err = ghes_in_nmi_queue_one_entry(ghes); + if (!err) + ret = 0; } + rcu_read_unlock(); -#ifdef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG - if (ret == NMI_HANDLED) + if (IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG) && !ret) irq_work_queue(&ghes_proc_irq_work); -#endif + + return ret; +} + +static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) +{ + int err, ret = NMI_DONE; + + if (!atomic_add_unless(&ghes_in_nmi, 1, 1)) + return ret; + + err = ghes_in_nmi_spool_from_list(&ghes_nmi); + if (!err) + ret = NMI_HANDLED; + atomic_dec(&ghes_in_nmi); return ret; } From patchwork Tue Jan 29 18:48:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786923 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 9EAA713BF for ; Tue, 29 Jan 2019 18:50:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F7392D1F7 for ; Tue, 29 Jan 2019 18:50:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8DB562D2B6; Tue, 29 Jan 2019 18:50:13 +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 209A72D1F7 for ; Tue, 29 Jan 2019 18:50:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13E4A8E000D; Tue, 29 Jan 2019 13:50:11 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0C6008E0003; Tue, 29 Jan 2019 13:50:11 -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 EFCDA8E000D; Tue, 29 Jan 2019 13:50:10 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id 891F28E0003 for ; Tue, 29 Jan 2019 13:50:10 -0500 (EST) Received: by mail-ed1-f70.google.com with SMTP id l45so8325511edb.1 for ; Tue, 29 Jan 2019 10:50:10 -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=pgJKx3vOVAyg9MpHE0lPbrKAyNToi+4kEJf4caHQ36A=; b=NJcZy4H7rNVhBpZfp8L4izjK5Hyg1r2wdb15ed/6t0U+bRCqqLz5NyHbUQWNyhx2xh iZuvho3fzbLiIVhG33euHRKTSgRS4LPqS1P9+tqvRlC4eG+REuwwdX18TPZy4bXOYRIS Xr+ji+6sge2yW9EI/hntoEIIXmyTNKteZZM1/YVNmibWWSAuAMOEvy9sboYES15jsrge sRbiWiWuZ+XZl2N3gz4ewGh+C73McX5ZLpqkI+hf9vSQT7TbRKG2Mv8iX9gvq7ozGu7Z 7egVgz0vDGGVnhLJJuKd9KMO9PQZdn5mpyKeHEiahN9bwj2snKYgaoLc7cDeVs9owfzl gngg== 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: AJcUukcn0FvqR9H0zWAxjZSefGFkbMbBypQaBDFsBRwOgOu51Cixh46H 81Q24aQQZ8AQXBabQhZHen6D5gRd0xGBwhasQ8eygoaKRl27kMkGUfPBJItO1SdUR7rdA02QlDJ lQjGWjvfp0/KK5VzNpwS8i5Qi44PIxIMn5Xr+gYo3MdFsM+MZ39TYjpolnQZmDOMv6A== X-Received: by 2002:a50:a347:: with SMTP id 65mr27107336edn.40.1548787810016; Tue, 29 Jan 2019 10:50:10 -0800 (PST) X-Google-Smtp-Source: ALg8bN4+k8NANEsK32kNzrCoY71Kof5lSiC5m6K3iw3aIY9lPsqkTQHED/OQOAWEqzdp0uTbqHOQ X-Received: by 2002:a50:a347:: with SMTP id 65mr27107273edn.40.1548787808984; Tue, 29 Jan 2019 10:50:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787808; cv=none; d=google.com; s=arc-20160816; b=F6d8NUCkvuTlFMkMr7xd4zT/HrRy9b93hSRxan2ikAzbvXJj3Kxp9uVnOgbmWG8+Z5 5PQSazDuwvCCPAfSIMaEX+QSCWJMGDvss3smxT5ZaQakTgT+EM7IPem3kAj6TGlfUKCh LRlvDQJGtKzpt2Vm1bPztPn5jdryLSe6drQjX6HgZSc7gNMPnJ/nR+SV8CLvkKRTNBCN yzBkQF2X+Zm7uZDm4HCUBurB9Z2UzJFC/S3ykzmM3c6vNrZHihpeqxkNVGK04dMPVzN0 8rogjpZ6yn6DPyHmFvDm9Yqadkx6yXFvbebsznOUqlAdkK9Vwmi31OJY5Wt0rrDu5Ytn kvzA== 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=pgJKx3vOVAyg9MpHE0lPbrKAyNToi+4kEJf4caHQ36A=; b=nFvQrDF5gx1KwUjp8/ZY/kVo8Ej99HUpYOaYiukaAQDpKaOkLrOW2JL2bIUxBG45v0 rfIL8KrnCE0PLPcU+xP5h5plsVbDHvULkek3qks+D9u4Rz+ZN+xjJonKHw3QxvzJn314 +jSRQEnHmQPkRHVAy428TzERrLtDb9jzEydYGnGwVOP8yQFkt9ZLfmCJJYM4OFfZ2Qll sCktZMSN94R0lDSeOtOhcsWlatJKip59ijGeWEyVwdoKy+1cYJe3GiBb0UI+vCe4came qAiEjNSH6pE425FTY3P2KDfCutV2LVOEqn++J9r5K7hkh8H/+6J8bKLWQf+dHDs/krjj n/ug== 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 (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id l3-v6si2441594ejs.120.2019.01.29.10.50.08 for ; Tue, 29 Jan 2019 10:50:08 -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 D6620A78; Tue, 29 Jan 2019 10:50:07 -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 3533B3F557; Tue, 29 Jan 2019 10:50:05 -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 , james.morse@arm.com Subject: [PATCH v8 10/26] ACPI / APEI: Don't allow ghes_ack_error() to mask earlier errors Date: Tue, 29 Jan 2019 18:48:46 +0000 Message-Id: <20190129184902.102850-11-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 During ghes_proc() we use ghes_ack_error() to tell an external agent we are done with these records and it can re-use the memory. rc may hold an error returned by ghes_read_estatus(), ENOENT causes us to skip ghes_ack_error() (as there is nothing to ack), but rc may also by EIO, which gets supressed. ghes_clear_estatus() is where we mark the records as processed for non GHESv2 error sources, and already spots the ENOENT case as buf_paddr is set to 0 by ghes_read_estatus(). Move the ghes_ack_error() call in here to avoid extra logic with the return code in ghes_proc(). This enables GHESv2 acking for NMI-like error sources. This is safe as the buffer is pre-mapped by map_gen_v2() before the GHES is added to any NMI handler lists. This same pre-mapping step means we can't receive an error from apei_read()/write() here as apei_check_gar() succeeded when it was mapped, and the mapping was cached, so the address can't be rejected at runtime. Remove the error-returns as this is now called from a function with no return. Signed-off-by: James Morse --- drivers/acpi/apei/ghes.c | 47 +++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index cb3d88de711f..bd58749d31bb 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -197,6 +197,21 @@ static void unmap_gen_v2(struct ghes *ghes) apei_unmap_generic_address(&ghes->generic_v2->read_ack_register); } +static void ghes_ack_error(struct acpi_hest_generic_v2 *gv2) +{ + int rc; + u64 val = 0; + + rc = apei_read(&val, &gv2->read_ack_register); + if (rc) + return; + + val &= gv2->read_ack_preserve << gv2->read_ack_register.bit_offset; + val |= gv2->read_ack_write << gv2->read_ack_register.bit_offset; + + apei_write(val, &gv2->read_ack_register); +} + static struct ghes *ghes_new(struct acpi_hest_generic *generic) { struct ghes *ghes; @@ -361,6 +376,13 @@ static void ghes_clear_estatus(struct ghes *ghes, u64 buf_paddr) ghes_copy_tofrom_phys(ghes->estatus, buf_paddr, sizeof(ghes->estatus->block_status), 0); + + /* + * GHESv2 type HEST entries introduce support for error acknowledgment, + * so only acknowledge the error if this support is present. + */ + if (is_hest_type_generic_v2(ghes)) + ghes_ack_error(ghes->generic_v2); } static void ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata, int sev) @@ -652,21 +674,6 @@ static void ghes_estatus_cache_add( rcu_read_unlock(); } -static int ghes_ack_error(struct acpi_hest_generic_v2 *gv2) -{ - int rc; - u64 val = 0; - - rc = apei_read(&val, &gv2->read_ack_register); - if (rc) - return rc; - - val &= gv2->read_ack_preserve << gv2->read_ack_register.bit_offset; - val |= gv2->read_ack_write << gv2->read_ack_register.bit_offset; - - return apei_write(val, &gv2->read_ack_register); -} - static void __ghes_panic(struct ghes *ghes, u64 buf_paddr) { __ghes_print_estatus(KERN_EMERG, ghes->generic, ghes->estatus); @@ -701,16 +708,6 @@ static int ghes_proc(struct ghes *ghes) out: ghes_clear_estatus(ghes, buf_paddr); - if (rc == -ENOENT) - return rc; - - /* - * GHESv2 type HEST entries introduce support for error acknowledgment, - * so only acknowledge the error if this support is present. - */ - if (is_hest_type_generic_v2(ghes)) - return ghes_ack_error(ghes->generic_v2); - return rc; } From patchwork Tue Jan 29 18:48:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786927 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 DB8F491E for ; Tue, 29 Jan 2019 18:50:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CCDE12D1D4 for ; Tue, 29 Jan 2019 18:50:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CACB12D2B7; Tue, 29 Jan 2019 18:50:16 +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 403D52D256 for ; Tue, 29 Jan 2019 18:50:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E9228E000E; Tue, 29 Jan 2019 13:50:14 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 29A438E0003; Tue, 29 Jan 2019 13:50:14 -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 18EFC8E000E; Tue, 29 Jan 2019 13:50:14 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id A39A58E0003 for ; Tue, 29 Jan 2019 13:50:13 -0500 (EST) Received: by mail-ed1-f72.google.com with SMTP id t2so8195701edb.22 for ; Tue, 29 Jan 2019 10:50:13 -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=ialR/FtHnTwHJvUu65JX50y7bWNIj6R4mAr1PLkRFOs=; b=lV299Cl8RSv8Zyies9VXxw/1Hkw58P5Wxj9ueJC7bveIYTAlUvSEdzrQcdfxFJIkAZ muI080zj4IvQiGsA7jfgq8gELW0Qe+CQh9/azJuvd+ZYWJYdBl2Fgq01H9mnIQqdbAXX Ey95tlnfrFsJb72L4Lvf0Umer1kkxnnHcSaonlhX2ZLDwdCrbG1yUeyCpTwqNwYOGvCw WBQ6Ja8bBMxw4g6kKHW9I7cOjdYzJra6RTV/HzDnnrd49ivn+K//0muKjxoQiqJwxlUX DKfIAX4DH/xOsMMg7DnGU2jTSJ3oPba1EW2L5RIwcD6GWeFjslTtAXtvFp8OTpU5oGzE CQQw== 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: AJcUukdNxmSPqeSSCypmq9k/GLl0RP3nsXk8GapkQm/5bw7OBAgekiVu kDGEyrcNahWGLBw7QgAZiNV9R0QF8ZC8XJZ1cl++Mc195WFt9YygTBN4oHVGKiug5uptibq+wJG 8PqrntWZx7op8w/Icbkmuk2cFk+yn8yNND4vbLKXPaxJD0ywR6vM40wzm+6Dh8bwkYA== X-Received: by 2002:a17:906:9493:: with SMTP id t19mr23804578ejx.63.1548787813142; Tue, 29 Jan 2019 10:50:13 -0800 (PST) X-Google-Smtp-Source: ALg8bN6mmFOGka4I2wTRb+D2EEUL2Ncs/Z4hx4joSCbSVlGm+RKl2AncTd//90V21LSMsRTSo/lO X-Received: by 2002:a17:906:9493:: with SMTP id t19mr23804508ejx.63.1548787811902; Tue, 29 Jan 2019 10:50:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787811; cv=none; d=google.com; s=arc-20160816; b=zRIoWEmZd1Yc0upeLUGIoFWBjmGZidl7yvwQxTCHcee2H7LqLQBf+5QK2PZiS9P91C tL/qPn2C6qTd9x62yJMNVcZDEINUAHPzXlPIMrPZELpGCCPMNGif4iTdbNj0VOC2JOQD 4R7APWcjxAamnzzMfpAAXn0hUMMmcocNE8GgM+RwGJKWeyqrsToASt4vLcDyBmAlRvp4 6WLe5fUQ93/hjhwRTHgg4qWpnxV/0PftJhJS0NZQJulwneR3LHTTxB+apFjGrvwKopi8 KTQ/DMq689Ersgn62OTPsEmZvIZYWnSzgmDR+69fUm+Skm0LgfgejFH/Xg9ssnVJTS03 ROLw== 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=ialR/FtHnTwHJvUu65JX50y7bWNIj6R4mAr1PLkRFOs=; b=wOh/nLd60+LrMIb05p0tRLplmXoBlZjpVm+qRP32PIRMujLPbVVSGkeX2Jh6izBHuF HQ3HR+gPzWlMVveZcU8GgOApdq3xe+m3E9HYskpDwYGQdFO70q4FHKK3KAMCKnRUz1uR uHhtArpvvf2X9yq5Axj4Egq/V9m3Uv7NISlRHz2BfmFVZn3bev/qmZAJ81X3O2rYhwOZ rv4FTXc2dqIHK+aW4uoCyLWhCl220qvFyC3/vhsu2UtQ9aC1s6yjS9IJeOjv2RH//tTU ditgR4yOMXWh7SG7zi5yv9m40CyQuq8mS3ydbucs67Jk+PZHDvOqomdPhyeNHC4R69nr Dhsg== 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 (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id x22si315741ejs.223.2019.01.29.10.50.11 for ; Tue, 29 Jan 2019 10:50:11 -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 C2C4715AB; Tue, 29 Jan 2019 10:50:10 -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 210DF3F557; Tue, 29 Jan 2019 10:50:07 -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 , james.morse@arm.com Subject: [PATCH v8 11/26] ACPI / APEI: Move NOTIFY_SEA between the estatus-queue and NOTIFY_NMI Date: Tue, 29 Jan 2019 18:48:47 +0000 Message-Id: <20190129184902.102850-12-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 The estatus-queue code is currently hidden by the NOTIFY_NMI #ifdefs. Once NOTIFY_SEA starts using the estatus-queue we can stop hiding it as each architecture has a user that can't be turned off. Split the existing CONFIG_HAVE_ACPI_APEI_NMI block in two, and move the SEA code into the gap. Move the code around ... and changes the stale comment describing why the status queue is necessary: printk() is no longer the issue, its the helpers like memory_failure_queue() that aren't nmi safe. Signed-off-by: James Morse --- drivers/acpi/apei/ghes.c | 113 ++++++++++++++++++++------------------- 1 file changed, 59 insertions(+), 54 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index bd58749d31bb..576dce29159d 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -767,66 +767,21 @@ static struct notifier_block ghes_notifier_hed = { .notifier_call = ghes_notify_hed, }; -#ifdef CONFIG_ACPI_APEI_SEA -static LIST_HEAD(ghes_sea); - -/* - * Return 0 only if one of the SEA error sources successfully reported an error - * record sent from the firmware. - */ -int ghes_notify_sea(void) -{ - struct ghes *ghes; - int ret = -ENOENT; - - rcu_read_lock(); - list_for_each_entry_rcu(ghes, &ghes_sea, list) { - if (!ghes_proc(ghes)) - ret = 0; - } - rcu_read_unlock(); - return ret; -} - -static void ghes_sea_add(struct ghes *ghes) -{ - mutex_lock(&ghes_list_mutex); - list_add_rcu(&ghes->list, &ghes_sea); - mutex_unlock(&ghes_list_mutex); -} - -static void ghes_sea_remove(struct ghes *ghes) -{ - mutex_lock(&ghes_list_mutex); - list_del_rcu(&ghes->list); - mutex_unlock(&ghes_list_mutex); - synchronize_rcu(); -} -#else /* CONFIG_ACPI_APEI_SEA */ -static inline void ghes_sea_add(struct ghes *ghes) { } -static inline void ghes_sea_remove(struct ghes *ghes) { } -#endif /* CONFIG_ACPI_APEI_SEA */ - #ifdef CONFIG_HAVE_ACPI_APEI_NMI /* - * printk is not safe in NMI context. So in NMI handler, we allocate - * required memory from lock-less memory allocator - * (ghes_estatus_pool), save estatus into it, put them into lock-less - * list (ghes_estatus_llist), then delay printk into IRQ context via - * irq_work (ghes_proc_irq_work). ghes_estatus_size_request record - * required pool size by all NMI error source. + * Handlers for CPER records may not be NMI safe. For example, + * memory_failure_queue() takes spinlocks and calls schedule_work_on(). + * In any NMI-like handler, memory from ghes_estatus_pool is used to save + * estatus, and added to the ghes_estatus_llist. irq_work_queue() causes + * ghes_proc_in_irq() to run in IRQ context where each estatus in + * ghes_estatus_llist is processed. + * + * Memory from the ghes_estatus_pool is also used with the ghes_estatus_cache + * to suppress frequent messages. */ static struct llist_head ghes_estatus_llist; static struct irq_work ghes_proc_irq_work; -/* - * NMI may be triggered on any CPU, so ghes_in_nmi is used for - * having only one concurrent reader. - */ -static atomic_t ghes_in_nmi = ATOMIC_INIT(0); - -static LIST_HEAD(ghes_nmi); - static void ghes_proc_in_irq(struct irq_work *irq_work) { struct llist_node *llnode, *next; @@ -949,6 +904,56 @@ static int ghes_in_nmi_spool_from_list(struct list_head *rcu_list) return ret; } +#endif /* CONFIG_HAVE_ACPI_APEI_NMI */ + +#ifdef CONFIG_ACPI_APEI_SEA +static LIST_HEAD(ghes_sea); + +/* + * Return 0 only if one of the SEA error sources successfully reported an error + * record sent from the firmware. + */ +int ghes_notify_sea(void) +{ + struct ghes *ghes; + int ret = -ENOENT; + + rcu_read_lock(); + list_for_each_entry_rcu(ghes, &ghes_sea, list) { + if (!ghes_proc(ghes)) + ret = 0; + } + rcu_read_unlock(); + return ret; +} + +static void ghes_sea_add(struct ghes *ghes) +{ + mutex_lock(&ghes_list_mutex); + list_add_rcu(&ghes->list, &ghes_sea); + mutex_unlock(&ghes_list_mutex); +} + +static void ghes_sea_remove(struct ghes *ghes) +{ + mutex_lock(&ghes_list_mutex); + list_del_rcu(&ghes->list); + mutex_unlock(&ghes_list_mutex); + synchronize_rcu(); +} +#else /* CONFIG_ACPI_APEI_SEA */ +static inline void ghes_sea_add(struct ghes *ghes) { } +static inline void ghes_sea_remove(struct ghes *ghes) { } +#endif /* CONFIG_ACPI_APEI_SEA */ + +#ifdef CONFIG_HAVE_ACPI_APEI_NMI +/* + * NMI may be triggered on any CPU, so ghes_in_nmi is used for + * having only one concurrent reader. + */ +static atomic_t ghes_in_nmi = ATOMIC_INIT(0); + +static LIST_HEAD(ghes_nmi); static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) { From patchwork Tue Jan 29 18:48:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786929 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 E0EFB13BF for ; Tue, 29 Jan 2019 18:50:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D19EE2D2B9 for ; Tue, 29 Jan 2019 18:50:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF5002D4C3; Tue, 29 Jan 2019 18:50:19 +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 5FA092D4FB for ; Tue, 29 Jan 2019 18:50:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F27F78E000F; Tue, 29 Jan 2019 13:50:16 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E84048E0003; Tue, 29 Jan 2019 13:50:16 -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 D22CC8E000F; Tue, 29 Jan 2019 13:50:16 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id 6F3578E0003 for ; Tue, 29 Jan 2019 13:50:16 -0500 (EST) Received: by mail-ed1-f70.google.com with SMTP id x15so8358387edd.2 for ; Tue, 29 Jan 2019 10:50:16 -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=KywK7H6KOuId8dTgb/lIe0I83ZQq1HND6cxdnv9EtDY=; b=sXDHIOPHSfhZcUx8YI2GSUDi6RrutBn0f73x+6BIZmmhIjewBHz8QIdqB20B0k4CyU +nZ75q64nsFmSYqNgRed3k9loPTVtcGspOXSqsmKaWa8ZXdA6MAM14mPFtn7a9gQNgqp ZU/+FJmI5iOn92DDg8d2HCx4BcGmPCE7OEyGhTiwfwegnmTkV2Pq5NzyeVwkYfCJr/nv M9VzC1KuWQppOSQodKuo4jwqzVq2xa47JiZebgisNUrLDfAUxsdOZt3kLftUSRiuhPB9 VWeNhP52g2hLt30J/X2ESqHuflJ0s02yDvBzNLfJs2WwZTq0DAH6WRaxtYW1zK7dsKon vyQA== 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: AJcUukf/QxW3LhLRrCeIumFG4hyj3o7/z46y1HTbLKzc/6zViUhzZV+y OglLrISRRQ8P0A1aS1gkFTi9Bqx366vN8EBJkqukt4iQFEOY/woFfXuVIUCyyeLLeWDPs7YmhgS F3mqcRZnpa+7DV2fQ6SSJL1cPrpVqI7VxXnHqZmAJlcsZbUMJb8ble1gzU1DKKcG/Sg== X-Received: by 2002:a50:81e3:: with SMTP id 90mr26172860ede.67.1548787815940; Tue, 29 Jan 2019 10:50:15 -0800 (PST) X-Google-Smtp-Source: ALg8bN63wlJqojbXbXrS4B/5x7OtDlsgjh6cms79O7e5H1bhoE8FGlxrBQJ2zA4GXCC8g1p0+TiP X-Received: by 2002:a50:81e3:: with SMTP id 90mr26172788ede.67.1548787814771; Tue, 29 Jan 2019 10:50:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787814; cv=none; d=google.com; s=arc-20160816; b=YJb4R6ZQVU7m7r8knpELQyh2dMF9UUxW+wMkQ22XLEBWumPoKCCsOeI8tMCsV5qw5x myoqKAgKF3bWmUjofAmLu4BjvEx2jla2/gL6jzHBPWju8xceVlMsybvx/BK76VdpaLCS eNXu9y7rzsxroPaA3aeV9phzN/E8g8i9nOtV5traD5dxBrkrIDZikcaYt9XyCyVpRAAB 6mNYrnqWYSm+xVi6VRrh8DAc9Eap6MQ58ljM2CXdzKjphLALOaT66a3NHy/o0U+u+eIh Ek4qkahFL5RoGK1RNBymYCljj+ctGoKu4DIh0K9ozK6gtR6MEeBwfp/Qglrj6n2NYkIG uuRQ== 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=KywK7H6KOuId8dTgb/lIe0I83ZQq1HND6cxdnv9EtDY=; b=dfQ3gpb+3j0GesCgGVuIGQvo3+HDfjzAPFIUH26+zbviGh1r8bpHxPScAUg+ghw+Y/ CJJdf96P8cOqLvXma4vnju4KO5EmFiD/7p77y+ZJnl+fNf06BQbsH7c5goMZrom7pbCG 7LfRbWLq1MBThbmHFuk5hGdJLB1mVDFd4ub8zqn05oSAcKXbrVJ2l1ZrRdP9KqrOh8cL 15afKPtSOU5DIhDZ94WuvNIR6V1LtCVPdLbNfXNujag8axShSp1bbf4Zj8Or9Zy7vFI9 RgcJXKBcnmCKv6PGpgBmrOquusBN8T20w+BBuGvg+adgIK0LSpq11Xyyi35GGuxF7Kfw i5EQ== 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 n14si1690378edy.344.2019.01.29.10.50.14 for ; Tue, 29 Jan 2019 10:50:14 -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 ADFF21596; Tue, 29 Jan 2019 10:50:13 -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 0D7D83F557; Tue, 29 Jan 2019 10:50:10 -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 , james.morse@arm.com Subject: [PATCH v8 12/26] ACPI / APEI: Switch NOTIFY_SEA to use the estatus queue Date: Tue, 29 Jan 2019 18:48:48 +0000 Message-Id: <20190129184902.102850-13-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 Now that the estatus queue can be used by more than one notification method, we can move notifications that have NMI-like behaviour over. Switch NOTIFY_SEA over to use the estatus queue. This makes it behave in the same way as x86's NOTIFY_NMI. Remove Kconfig's ability to turn ACPI_APEI_SEA off if ACPI_APEI_GHES is selected. This roughly matches the x86 NOTIFY_NMI behaviour, and means each architecture has at least one user of the estatus-queue, meaning it doesn't need guarding with ifdef. Signed-off-by: James Morse --- Changes since v6: * Lost all the pool grow/shrink stuff, * Changed Kconfig so this can't be turned off to avoid kconfig complexity: * Dropped Tyler's tested-by. * For now we need #ifdef around the SEA code as the arch code assumes its there. * Removed Punit's reviewed-by due to the swirling #ifdeffery --- drivers/acpi/apei/Kconfig | 12 +----------- drivers/acpi/apei/ghes.c | 22 +++++----------------- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/drivers/acpi/apei/Kconfig b/drivers/acpi/apei/Kconfig index 52ae5438edeb..6b18f8bc7be3 100644 --- a/drivers/acpi/apei/Kconfig +++ b/drivers/acpi/apei/Kconfig @@ -41,19 +41,9 @@ config ACPI_APEI_PCIEAER Turn on this option to enable the corresponding support. config ACPI_APEI_SEA - bool "APEI Synchronous External Abort logging/recovering support" + bool depends on ARM64 && ACPI_APEI_GHES default y - help - This option should be enabled if the system supports - firmware first handling of SEA (Synchronous External Abort). - SEA happens with certain faults of data abort or instruction - abort synchronous exceptions on ARMv8 systems. If a system - supports firmware first handling of SEA, the platform analyzes - and handles hardware error notifications from SEA, and it may then - form a HW error record for the OS to parse and handle. This - option allows the OS to look for such hardware error record, and - take appropriate action. config ACPI_APEI_MEMORY_FAILURE bool "APEI memory error recovering support" diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 576dce29159d..ab794ab29554 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -767,7 +767,6 @@ static struct notifier_block ghes_notifier_hed = { .notifier_call = ghes_notify_hed, }; -#ifdef CONFIG_HAVE_ACPI_APEI_NMI /* * Handlers for CPER records may not be NMI safe. For example, * memory_failure_queue() takes spinlocks and calls schedule_work_on(). @@ -904,7 +903,6 @@ static int ghes_in_nmi_spool_from_list(struct list_head *rcu_list) return ret; } -#endif /* CONFIG_HAVE_ACPI_APEI_NMI */ #ifdef CONFIG_ACPI_APEI_SEA static LIST_HEAD(ghes_sea); @@ -915,16 +913,7 @@ static LIST_HEAD(ghes_sea); */ int ghes_notify_sea(void) { - struct ghes *ghes; - int ret = -ENOENT; - - rcu_read_lock(); - list_for_each_entry_rcu(ghes, &ghes_sea, list) { - if (!ghes_proc(ghes)) - ret = 0; - } - rcu_read_unlock(); - return ret; + return ghes_in_nmi_spool_from_list(&ghes_sea); } static void ghes_sea_add(struct ghes *ghes) @@ -992,16 +981,15 @@ static void ghes_nmi_remove(struct ghes *ghes) */ synchronize_rcu(); } +#else /* CONFIG_HAVE_ACPI_APEI_NMI */ +static inline void ghes_nmi_add(struct ghes *ghes) { } +static inline void ghes_nmi_remove(struct ghes *ghes) { } +#endif /* CONFIG_HAVE_ACPI_APEI_NMI */ static void ghes_nmi_init_cxt(void) { init_irq_work(&ghes_proc_irq_work, ghes_proc_in_irq); } -#else /* CONFIG_HAVE_ACPI_APEI_NMI */ -static inline void ghes_nmi_add(struct ghes *ghes) { } -static inline void ghes_nmi_remove(struct ghes *ghes) { } -static inline void ghes_nmi_init_cxt(void) { } -#endif /* CONFIG_HAVE_ACPI_APEI_NMI */ static int ghes_probe(struct platform_device *ghes_dev) { From patchwork Tue Jan 29 18:48:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786933 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 6E39791E for ; Tue, 29 Jan 2019 18:50:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D86D2D286 for ; Tue, 29 Jan 2019 18:50:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B4F22D50C; Tue, 29 Jan 2019 18:50:23 +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=ham 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 AE8FB2D286 for ; Tue, 29 Jan 2019 18:50:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D48688E0010; Tue, 29 Jan 2019 13:50:19 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CFC6B8E0003; Tue, 29 Jan 2019 13:50:19 -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 BEA538E0010; Tue, 29 Jan 2019 13:50:19 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id 5F1448E0003 for ; Tue, 29 Jan 2019 13:50:19 -0500 (EST) Received: by mail-ed1-f70.google.com with SMTP id x15so8358439edd.2 for ; Tue, 29 Jan 2019 10:50:19 -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=eKJBvj1T0IZPPUl7daGGreUupnxLX0+68N6RW9VrUHc=; b=E4y2itbuoKV7mVub++EOC71bXRLa0/D9SXBxwbO+GhJTKHyfBU7BRH+mtvDc84Xy0d lrFgBPKi/nHPqafhHLaTuizZbxck67+0CS1Tzw2+r1cQmd3CB6g938z4W7dsTiRmn8EE 814mfycyR294DhFjEy62FF9/pFl1LWHuFxuk1CI77Mg2jR1EZnDppQxPlduBAW1rOJam Ea0b0MYzoxfT9Qdbh/wgnY9WsfVgkZaa0hcsEGq8xw/qf7BPGJ2tWe9G10T0lbhaGxH7 bS7rQ7P5spZMTM6Yc0OhuuV/0/qBdrZQCBRZ27fOAuXLhy3zCc/rW4oxzTV6I4wQD7Rt aSrg== 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: AJcUukc3LvMdYTD0aEfJnJcZ9wwwzO4150jzjb4kWjyXYxphkx95hX42 rRghfR92m23mdjX5DGQecYdTHBMCHj5mt/LOJDR1WVCDpQVCP+ruA/BrNP12mlqpvCQeTuZHF4F qOHmHlB9PrCH/6tUvWptRmA4kKIn+1eklRcoVbyYferZ8EohHjutqp7QyxFbJ5lVeWw== X-Received: by 2002:a17:906:66c2:: with SMTP id k2-v6mr23751891ejp.152.1548787818849; Tue, 29 Jan 2019 10:50:18 -0800 (PST) X-Google-Smtp-Source: ALg8bN5zOeyM/8Hff6IqS+KRfZlCGnzX9WJAp8D6VvdysD6HAyaBYlUVOTfaGNcyhYSr+1SVaRzU X-Received: by 2002:a17:906:66c2:: with SMTP id k2-v6mr23751839ejp.152.1548787817657; Tue, 29 Jan 2019 10:50:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787817; cv=none; d=google.com; s=arc-20160816; b=uFzT+Q9nk1ierPGz2r6aY5kbq+D5gksABDAYuCYy+lzBQHGgSmPCr2IPfTvrDvc40N TTCiR5q3tOh48d5H83I9qgUge+XoDvjyD+IzpgDhetc2wchNotiTFEfWz3On+H8UyQlG 4NXdYcK2QDroPAvQk4IzTrn9PnIlLfw3dfKAm9jko5awb0f7MYeorMV7np5o/oGK1xFH abKwFXImwasZZUrtcL6xes2EA/3vKnkwZD679X8XIp8/MgcspxMC12abuMZXrUz7oena obqdqkjzBxniQpsworYa8YyxWv4FwNCreVrey5RUOooROJAGKc3r4ZFyRY90ONaeHzja dbPg== 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=eKJBvj1T0IZPPUl7daGGreUupnxLX0+68N6RW9VrUHc=; b=MEczMeChOU/Vyz5zZPBYoPB81LbPbGySyiKwl66RhW4PFhXzsfhIrvepURWARZ0Nct nYlf0Ric8EHYBxCiLJ5ZpHtX0EDtppcVZe9+rcHRfEc7LMQxUbcrn9VHUmX9XhDlYHk/ ZH72oH1Q/rVPPW2bYgvn3qGPYC2KO54mJmbkbhjQDxaEahypeH3vawDMft9FDLgQKE9B 7RNiQ5n1P1Oy67zMjZygEyZtUbNSnFkMWvFWdUe6/XLVS3sO08yD1KLiU4lO1OUUAa/S jFnjh34kzNr74xc3jkkt9xni3Qskt6UWUosb7SSoL6fVDxx/IJsj/ex2pVguQU/6780k ubMQ== 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 (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id t5si581924ejq.44.2019.01.29.10.50.17 for ; Tue, 29 Jan 2019 10:50:17 -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 9B54EA78; Tue, 29 Jan 2019 10:50:16 -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 ECE583F557; Tue, 29 Jan 2019 10:50:13 -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 , james.morse@arm.com Subject: [PATCH v8 13/26] KVM: arm/arm64: Add kvm_ras.h to collect kvm specific RAS plumbing Date: Tue, 29 Jan 2019 18:48:49 +0000 Message-Id: <20190129184902.102850-14-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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(). KVM shouldn't have to know about this, pull the RAS plumbing out into a header file. Currently guest synchronous external aborts are claimed as RAS notifications by handle_guest_sea(), which is hidden in the arch codes mm/fault.c. 32bit gets a dummy declaration in system_misc.h. There is going to be more of this in the future if/when the kernel supports the SError-based firmware-first notification mechanism and/or kernel-first notifications for both synchronous external abort and SError. Each of these will come with some Kconfig symbols and a handful of header files. Create a header file for all this. This patch gives handle_guest_sea() a 'kvm_' prefix, and moves the declarations to kvm_ras.h as preparation for a future patch that moves the ACPI-specific RAS code out of mm/fault.c. Signed-off-by: James Morse Reviewed-by: Punit Agrawal Acked-by: Marc Zyngier Tested-by: Tyler Baicar Acked-by: Catalin Marinas --- Changes since v6: * Tinkered with the commit message --- arch/arm/include/asm/kvm_ras.h | 14 ++++++++++++++ arch/arm/include/asm/system_misc.h | 5 ----- arch/arm64/include/asm/kvm_ras.h | 11 +++++++++++ arch/arm64/include/asm/system_misc.h | 2 -- arch/arm64/mm/fault.c | 2 +- virt/kvm/arm/mmu.c | 4 ++-- 6 files changed, 28 insertions(+), 10 deletions(-) create mode 100644 arch/arm/include/asm/kvm_ras.h create mode 100644 arch/arm64/include/asm/kvm_ras.h diff --git a/arch/arm/include/asm/kvm_ras.h b/arch/arm/include/asm/kvm_ras.h new file mode 100644 index 000000000000..e9577292dfe4 --- /dev/null +++ b/arch/arm/include/asm/kvm_ras.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2018 - Arm Ltd */ + +#ifndef __ARM_KVM_RAS_H__ +#define __ARM_KVM_RAS_H__ + +#include + +static inline int kvm_handle_guest_sea(phys_addr_t addr, unsigned int esr) +{ + return -1; +} + +#endif /* __ARM_KVM_RAS_H__ */ diff --git a/arch/arm/include/asm/system_misc.h b/arch/arm/include/asm/system_misc.h index 8e76db83c498..66f6a3ae68d2 100644 --- a/arch/arm/include/asm/system_misc.h +++ b/arch/arm/include/asm/system_misc.h @@ -38,11 +38,6 @@ static inline void harden_branch_predictor(void) extern unsigned int user_debug; -static inline int handle_guest_sea(phys_addr_t addr, unsigned int esr) -{ - return -1; -} - #endif /* !__ASSEMBLY__ */ #endif /* __ASM_ARM_SYSTEM_MISC_H */ diff --git a/arch/arm64/include/asm/kvm_ras.h b/arch/arm64/include/asm/kvm_ras.h new file mode 100644 index 000000000000..6096f0251812 --- /dev/null +++ b/arch/arm64/include/asm/kvm_ras.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2018 - Arm Ltd */ + +#ifndef __ARM64_KVM_RAS_H__ +#define __ARM64_KVM_RAS_H__ + +#include + +int kvm_handle_guest_sea(phys_addr_t addr, unsigned int esr); + +#endif /* __ARM64_KVM_RAS_H__ */ diff --git a/arch/arm64/include/asm/system_misc.h b/arch/arm64/include/asm/system_misc.h index 0e2a0ecaf484..32693f34f431 100644 --- a/arch/arm64/include/asm/system_misc.h +++ b/arch/arm64/include/asm/system_misc.h @@ -46,8 +46,6 @@ extern void __show_regs(struct pt_regs *); extern void (*arm_pm_restart)(enum reboot_mode reboot_mode, const char *cmd); -int handle_guest_sea(phys_addr_t addr, unsigned int esr); - #endif /* __ASSEMBLY__ */ #endif /* __ASM_SYSTEM_MISC_H */ diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index efb7b2cbead5..c76dc981e3fc 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -733,7 +733,7 @@ static const struct fault_info fault_info[] = { { do_bad, SIGKILL, SI_KERNEL, "unknown 63" }, }; -int handle_guest_sea(phys_addr_t addr, unsigned int esr) +int kvm_handle_guest_sea(phys_addr_t addr, unsigned int esr) { return ghes_notify_sea(); } diff --git a/virt/kvm/arm/mmu.c b/virt/kvm/arm/mmu.c index fbdf3ac2f001..600e0cc74ea4 100644 --- a/virt/kvm/arm/mmu.c +++ b/virt/kvm/arm/mmu.c @@ -27,10 +27,10 @@ #include #include #include +#include #include #include #include -#include #include "trace.h" @@ -1903,7 +1903,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) * For RAS the host kernel may handle this abort. * There is no need to pass the error into the guest. */ - if (!handle_guest_sea(fault_ipa, kvm_vcpu_get_hsr(vcpu))) + if (!kvm_handle_guest_sea(fault_ipa, kvm_vcpu_get_hsr(vcpu))) return 1; if (unlikely(!is_iabt)) { From patchwork Tue Jan 29 18:48:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786939 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 9DA4F91E for ; Tue, 29 Jan 2019 18:50:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8EC632D4C9 for ; Tue, 29 Jan 2019 18:50:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C9762D54E; Tue, 29 Jan 2019 18:50:26 +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 DA3272D4C9 for ; Tue, 29 Jan 2019 18:50:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C39AE8E0011; Tue, 29 Jan 2019 13:50:22 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C0E948E0003; Tue, 29 Jan 2019 13:50:22 -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 AD9EF8E0011; Tue, 29 Jan 2019 13:50:22 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id 4FCE28E0003 for ; Tue, 29 Jan 2019 13:50:22 -0500 (EST) Received: by mail-ed1-f69.google.com with SMTP id b3so8352425edi.0 for ; Tue, 29 Jan 2019 10:50:22 -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=J3ZEvjd6iSwqW9/Lj+HAFuc9FVXfG+8GlKLDC1orXuM=; b=jkh9rqq8m6xZJEWCzneIRF7IMwrumF+WFN9opTcpkr2fk9rJwQtEDz2r2spV/jsuAZ WTKeWjSU8cCTLzgcRsiVQa2O2NB9pjqErZ/gFgEX9Dvak9cZY+W34Ed93b3Bj1BsrMZl FQdWmrpg+vLOMkIs6Hofmq+A+QXvRiKqqM4x0EfY88+8jqhu5VY4l0xtVMAwTAXbx32B j/C3ZpxC7ge7gjzgOo3rPJa4sD9+hZW09Zcdu8ujweylS9l86H44tB5DYOQaFthyI8OO wtwoQGG3KKKlxXc3HQNOGs1coQUtoUWzxF0h/YAgh53H61DriakSg4tqmsgizQyx6lZe uJbA== 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: AJcUukdaGoxFDqcoqs8uejo4zU+DJ2C9Q3MnRtTix85bE2NzdC4nRECm mr+JzQLa2djmbl82tYwVUsh0KIgF4tNIcWFCcnD2lCsFSeyqfwCAac0KFs7iWZH6Fwdqm/b8oKU v8jBdRRTlkjuXFPXMjkV8kIhdfidoluatE/vTpPJOAIEuKw3GbWCrMrtEvOoWP1QDMQ== X-Received: by 2002:a50:903c:: with SMTP id b57mr27265680eda.161.1548787821761; Tue, 29 Jan 2019 10:50:21 -0800 (PST) X-Google-Smtp-Source: ALg8bN4wLWVcS/8llm8P31KleUEd2+exS14mXQMuvzazJB8tv1hbAlFr10UvVZyEQe7oLRQln6pO X-Received: by 2002:a50:903c:: with SMTP id b57mr27265611eda.161.1548787820554; Tue, 29 Jan 2019 10:50:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787820; cv=none; d=google.com; s=arc-20160816; b=RZd+YBSeZP5wGl/Y6c6akBXy9StCr4WXaij9LafSysmhblcDiRmPuBD94BXteM6BuQ 8ENvjZGbxhqZypPG4N5nQg6BZnOrNIllXFqUE6OBWWjOlM3Vvsl3PnKpNcs307b9qX3S UJZCVnJBOeU8T0z/kEjfjRbuBuaCoW5Kl9PBgP4oHCKk9w7Z+jusjZ0PfQYNp67e/DEz oGqz7soB8D2So0psvguBRKvhPE4xr5RxbUaGDO2Qz+rEsWJ5+iSDsxADJrL2C8UuidNI /e1W5ljfTEbbPvWV+4Lsyo+n6k3pGMAg6jQNSs4OW6dyMTGSwXe3d+FCot6qDrff1rJl qhxw== 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=J3ZEvjd6iSwqW9/Lj+HAFuc9FVXfG+8GlKLDC1orXuM=; b=qQ0fGkh37SgiHPeNCMAhn7pcm0EknXH7aycuOSjZEXtGxDepCZ2OyOKHqRVVYu8Feu OycCvwzhY7dxP/WoXPdNC8iL3Cz8ATaP/DMUPf/vx5BPUt0A5smrKGeb2RMP0QMEGmzo 8cmvvfsSN96NNjGB2sfnqhp7IruWfuW+/FSzACxXhhKt33nnR1LyfZlwt8Wlj+5gbtQW WKm02Az+LZWjYC4zIQFTBdfRLtYjJL1dPdTZBznlrQAcPhOt1tMI7N01Qr4ueRyUNs7a JaNEJurJPs8UvhLF8GVBF7xxIIhTxiO/ExN4YtO+o+yQTOmZbRxzB0qEqVEzcQYIU8zr MKxg== 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 (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id k1si854053ejv.2.2019.01.29.10.50.20 for ; Tue, 29 Jan 2019 10:50:20 -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 8646515BF; Tue, 29 Jan 2019 10:50:19 -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 D8A3F3F557; Tue, 29 Jan 2019 10:50:16 -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 , james.morse@arm.com Subject: [PATCH v8 14/26] arm64: KVM/mm: Move SEA handling behind a single 'claim' interface Date: Tue, 29 Jan 2019 18:48:50 +0000 Message-Id: <20190129184902.102850-15-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 2def77ec14be..7628efbe6c12 100644 --- a/arch/arm64/include/asm/acpi.h +++ b/arch/arm64/include/asm/acpi.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -110,9 +111,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 c76dc981e3fc..e1c84c2e1cab 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 @@ -47,8 +49,6 @@ #include #include -#include - struct fault_info { int (*fn)(unsigned long addr, unsigned int esr, struct pt_regs *regs); @@ -643,19 +643,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; @@ -733,11 +724,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) { From patchwork Tue Jan 29 18:48:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786945 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 155051874 for ; Tue, 29 Jan 2019 18:50:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0552B2D50C for ; Tue, 29 Jan 2019 18:50:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 032B52D526; Tue, 29 Jan 2019 18:50:30 +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 57F0E2D650 for ; Tue, 29 Jan 2019 18:50:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B260B8E0005; Tue, 29 Jan 2019 13:50:25 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AFFFF8E0003; Tue, 29 Jan 2019 13:50:25 -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 979118E0005; Tue, 29 Jan 2019 13:50:25 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id 36CF78E0003 for ; Tue, 29 Jan 2019 13:50:25 -0500 (EST) Received: by mail-ed1-f70.google.com with SMTP id l45so8325822edb.1 for ; Tue, 29 Jan 2019 10:50:25 -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=XZL3kiVvEBTmTsFpHsmD8zXMGbIAxkgsYweoSP+KAII=; b=jXo/vHtpf/EunBjDN1ZCwJ8oznL6dGURfOQXPXo4024JnyhiLyALEwfirYYd4XLlrY 7bucrzuaryxdTYH+3Fji4TrDIAQuhdBLx+hzEPBw/sqILd4s+l7m4VjfXoh74/Q+v9wc rAPAE3Blz7FS24kWutsgo89evuWv9GeLSHzy6qAsf8UvFKyliDvGjsYt5Ia/obN3A+YC N5kVZLcTNnVp2aSNPPWTcDcSP+GyK+zCkobljxmrktftX4wpznQMdog6RG84R1yFzgjf zeBbKaAeIuvw3mDY4FtNcm3rw6mtUsS1pEL4JuqJQKnYv4uxKPQfu8TQN/HCqKzoqwJ7 R3xg== 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: AJcUukf9kVXHKQikxvvWs4sHHtUjbIEW2QmYjdahon2A91xE4wHZp/MJ x76OpD9E9fehdKBDDRS1eU2Aa/YyRYmPJmzao+L5MgOGMQkf/L2Qjlxl4RTm0UP8QDOc9WxcLZK Q5LF2d/83IpWpUWi377eNA5QME6vvn+6fcnoM+klQrk4V31HdYSrjJ99db8P6Ol4IRw== X-Received: by 2002:a17:906:b749:: with SMTP id fx9mr6292147ejb.38.1548787824686; Tue, 29 Jan 2019 10:50:24 -0800 (PST) X-Google-Smtp-Source: ALg8bN6vmNWWDRHaGcaUHZETjUywlAhL4dF8nuFQEzzKaqncD2x6uhLU1EFom2hj2g1EH7mC/OoP X-Received: by 2002:a17:906:b749:: with SMTP id fx9mr6292080ejb.38.1548787823458; Tue, 29 Jan 2019 10:50:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787823; cv=none; d=google.com; s=arc-20160816; b=zcfTQkBCejQMKVAc3w8Eng2HxbyHWHE38TUOXBpE/aWkRaRX0WiFXruLzAxyv/lhNG KeK5vz4IcDL0Qh0PnL+8ROhD8dXlywyAnTt8J1wqO64pjPhmMbDpNT6N3do9NUlsfc50 I63fwONQ7M/q82B0gH6BX9bCQGMR21GNdq6fhxGikTxaEp2Oz3jUb3CXGLdRejq1eoX0 9EZ0XuMbZD2+eRGvVBjb5/043yb0QVzfemqKnCLs4Pu+hRvxYOUJ8FfVJN5ijydW96yz Z4FKjflfaUVajyt2PBJPbE2xsS2w5nkqSGhoaO5Ktq8ZsBei0MPivCCctYHm1iWB3zOv vDQg== 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=XZL3kiVvEBTmTsFpHsmD8zXMGbIAxkgsYweoSP+KAII=; b=05L35U9Wi/rVSafXQadxOltt3DS3BMZ+rRGZJ9VtKclgr8Z2wlmCP2BaXO2sArm6Nz xJPa1H+6Br3ZYtXkit+zaxBDhGVdokaNOkfMoPo4tPPr8iW/S+bT70+OvxBhAS4K982B KyrL7XbS5H1D0fJdXcT2ORZ7lTSNCoX8DMgnMTz3utatLuZAigIBy8fNgAtlJYI0S4pa eeMlRcm+DzyQJX09/wi+bvFB0ABg0EqqwlycPrEGWiClx0odwM3kxECIBvsr3ACVpYYd MLnOXp9IbPTrrUEC5RESaWTQbbvYXpKHZ777J2e2xcKHcBxtdFShCHg8/mEKo23rZSzk 0Lmw== 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 u37si2009610edm.419.2019.01.29.10.50.23 for ; Tue, 29 Jan 2019 10:50:23 -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 722A61650; Tue, 29 Jan 2019 10:50:22 -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 C530E3F557; Tue, 29 Jan 2019 10:50:19 -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 , james.morse@arm.com Subject: [PATCH v8 15/26] ACPI / APEI: Move locking to the notification helper Date: Tue, 29 Jan 2019 18:48:51 +0000 Message-Id: <20190129184902.102850-16-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 ghes_copy_tofrom_phys() takes different locks depending on in_nmi(). This doesn't work if there are multiple NMI-like notifications, that can interrupt each other. Now that NOTIFY_SEA is always called in the same context, move the lock-taking to the notification helper. The helper will always know which lock to take. This avoids ghes_copy_tofrom_phys() taking a guess based on in_nmi(). This splits NOTIFY_NMI and NOTIFY_SEA to use different locks. All the other notifications use ghes_proc(), and are called in process or IRQ context. Move the spin_lock_irqsave() around their ghes_proc() calls. Signed-off-by: James Morse Reviewed-by: Borislav Petkov --- Changes since v7: * Moved the locks into the function that uses them to make it clearer this is only use in_nmi(). Changes since v6: * Tinkered with the commit message * Lock definitions have moved due to the #ifdefs --- drivers/acpi/apei/ghes.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index ab794ab29554..c6bc73281d6a 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -114,11 +114,10 @@ static DEFINE_MUTEX(ghes_list_mutex); * handler, but general ioremap can not be used in atomic context, so * the fixmap is used instead. * - * These 2 spinlocks are used to prevent the fixmap entries from being used + * This spinlock is used to prevent the fixmap entry from being used * simultaneously. */ -static DEFINE_RAW_SPINLOCK(ghes_ioremap_lock_nmi); -static DEFINE_SPINLOCK(ghes_ioremap_lock_irq); +static DEFINE_SPINLOCK(ghes_notify_lock_irq); static struct gen_pool *ghes_estatus_pool; static unsigned long ghes_estatus_pool_size_request; @@ -287,7 +286,6 @@ static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len, int from_phys) { void __iomem *vaddr; - unsigned long flags = 0; int in_nmi = in_nmi(); u64 offset; u32 trunk; @@ -295,10 +293,8 @@ static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len, while (len > 0) { offset = paddr - (paddr & PAGE_MASK); if (in_nmi) { - raw_spin_lock(&ghes_ioremap_lock_nmi); vaddr = ghes_ioremap_pfn_nmi(paddr >> PAGE_SHIFT); } else { - spin_lock_irqsave(&ghes_ioremap_lock_irq, flags); vaddr = ghes_ioremap_pfn_irq(paddr >> PAGE_SHIFT); } trunk = PAGE_SIZE - offset; @@ -312,10 +308,8 @@ static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len, buffer += trunk; if (in_nmi) { ghes_iounmap_nmi(); - raw_spin_unlock(&ghes_ioremap_lock_nmi); } else { ghes_iounmap_irq(); - spin_unlock_irqrestore(&ghes_ioremap_lock_irq, flags); } } } @@ -729,8 +723,11 @@ static void ghes_add_timer(struct ghes *ghes) static void ghes_poll_func(struct timer_list *t) { struct ghes *ghes = from_timer(ghes, t, timer); + unsigned long flags; + spin_lock_irqsave(&ghes_notify_lock_irq, flags); ghes_proc(ghes); + spin_unlock_irqrestore(&ghes_notify_lock_irq, flags); if (!(ghes->flags & GHES_EXITING)) ghes_add_timer(ghes); } @@ -738,9 +735,12 @@ static void ghes_poll_func(struct timer_list *t) static irqreturn_t ghes_irq_func(int irq, void *data) { struct ghes *ghes = data; + unsigned long flags; int rc; + spin_lock_irqsave(&ghes_notify_lock_irq, flags); rc = ghes_proc(ghes); + spin_unlock_irqrestore(&ghes_notify_lock_irq, flags); if (rc) return IRQ_NONE; @@ -751,14 +751,17 @@ static int ghes_notify_hed(struct notifier_block *this, unsigned long event, void *data) { struct ghes *ghes; + unsigned long flags; int ret = NOTIFY_DONE; + spin_lock_irqsave(&ghes_notify_lock_irq, flags); rcu_read_lock(); list_for_each_entry_rcu(ghes, &ghes_hed, list) { if (!ghes_proc(ghes)) ret = NOTIFY_OK; } rcu_read_unlock(); + spin_unlock_irqrestore(&ghes_notify_lock_irq, flags); return ret; } @@ -913,7 +916,14 @@ static LIST_HEAD(ghes_sea); */ int ghes_notify_sea(void) { - return ghes_in_nmi_spool_from_list(&ghes_sea); + static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sea); + int rv; + + raw_spin_lock(&ghes_notify_lock_sea); + rv = ghes_in_nmi_spool_from_list(&ghes_sea); + raw_spin_unlock(&ghes_notify_lock_sea); + + return rv; } static void ghes_sea_add(struct ghes *ghes) @@ -946,14 +956,17 @@ static LIST_HEAD(ghes_nmi); static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) { + static DEFINE_RAW_SPINLOCK(ghes_notify_lock_nmi); int err, ret = NMI_DONE; if (!atomic_add_unless(&ghes_in_nmi, 1, 1)) return ret; + raw_spin_lock(&ghes_notify_lock_nmi); err = ghes_in_nmi_spool_from_list(&ghes_nmi); if (!err) ret = NMI_HANDLED; + raw_spin_unlock(&ghes_notify_lock_nmi); atomic_dec(&ghes_in_nmi); return ret; @@ -995,6 +1008,7 @@ static int ghes_probe(struct platform_device *ghes_dev) { struct acpi_hest_generic *generic; struct ghes *ghes = NULL; + unsigned long flags; int rc = -EINVAL; @@ -1097,7 +1111,9 @@ static int ghes_probe(struct platform_device *ghes_dev) ghes_edac_register(ghes, &ghes_dev->dev); /* Handle any pending errors right away */ + spin_lock_irqsave(&ghes_notify_lock_irq, flags); ghes_proc(ghes); + spin_unlock_irqrestore(&ghes_notify_lock_irq, flags); return 0; From patchwork Tue Jan 29 18:48:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786951 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 6269E1874 for ; Tue, 29 Jan 2019 18:50:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 533362D552 for ; Tue, 29 Jan 2019 18:50:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 516212D6CA; Tue, 29 Jan 2019 18:50:33 +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 A2A302D552 for ; Tue, 29 Jan 2019 18:50:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C85FB8E0012; Tue, 29 Jan 2019 13:50:28 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C16898E0003; Tue, 29 Jan 2019 13:50:28 -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 A13188E0012; Tue, 29 Jan 2019 13:50:28 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id 35C138E0003 for ; Tue, 29 Jan 2019 13:50:28 -0500 (EST) Received: by mail-ed1-f71.google.com with SMTP id d41so8139751eda.12 for ; Tue, 29 Jan 2019 10:50:28 -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=+/VkkUETllQIA07Icbpa2r7ErALoSIv6fRodU1kN9Fs=; b=SkIO++l8N8LJTe2DI7FFBWPLfVvHvzi7Huth+JL8IFMnIxA9sMnZz8PQoGNHD5cTNM cRTgSsgZYka0LVrIWjHLRpl87zLNSROmC1Fmkjb1Lvg7wpTguLj+nfsOL9SomK0fWHiJ iTpR4YXcBNJJz52l92sDHvzk8HXBm/8ikBR3CPrb558SHRBWA7cPW9y5dt42CWEXdwWm u7qQ6tQ3J6KAtMhzV0tJMC3ZP7kDeWkZqUa4frhrehz/AJHYJSoVF/ZzGLrqX5pg+xwc N8r2SsUQt+s5R6WwBQDLlzyxRPDXWUFYL/hbzG3iyzfseSF5ew90NzABQ0B81PDqtR52 yyQw== 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: AJcUukcMknXg1PTQMyXu7nxveEWLxQausaagpi3tnoui9G8P0nhBdToL Z1Rkg0VQPRiVSc2fmMEu9K0wl7VSsrkI7axpQVwrcweGS7M38WUIUEcrvHHdgWF9D+YtkY3K9mm 1DG+28njrGa87ab3iLe8xdKs2XovHdmgBYIW0wAe2kfryOReaR9HcUGvsPkjzsrPxYg== X-Received: by 2002:a50:8bc9:: with SMTP id n9mr26805189edn.41.1548787827681; Tue, 29 Jan 2019 10:50:27 -0800 (PST) X-Google-Smtp-Source: ALg8bN6WZd1QvS2HSl0JR48aBN/S5MkzuN4LLc3/R+O8eg4j5u3z4Rh5iQfeSAFAryu2vkrvERRG X-Received: by 2002:a50:8bc9:: with SMTP id n9mr26805123edn.41.1548787826561; Tue, 29 Jan 2019 10:50:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787826; cv=none; d=google.com; s=arc-20160816; b=lf+9TlL4ygzuI4nSpqjKuyWqkTmD4TIkCG0BQXv0XsG9/sXuWDV6awb0Pyuci+867D fY/ZL/T1YH1GMqqUSX8ly59kErJPdzYtG2udXNCz5S6YHwBj5zJ7uZmqA9UBscL05/sw QGdyHxwNkVvkA5Gp1kY0cSklCQVNwrV9mW31fncOUGWWC/+WS5iItC66Pq2dBYbqQ+Em b3vHdetIoxr7sH1CwZ6d7C9GWcejsrVPquTQaMp4hbxBHwNMTU+52Ey/KiaN7ZWmv5hd INFn156ommAtYGqpbl6x/oQXxmwOJVdrul1AvYYQCK4Igob0FaAWl4kLPLMFJKUZYgwZ b8wg== 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=+/VkkUETllQIA07Icbpa2r7ErALoSIv6fRodU1kN9Fs=; b=Mdq6Ggsug2gBIJ2w0zUhIw0dT70cbi70KOB8bMVfhR69IhmJv2dApUCsO/v24WuegA FYfNWb/GBM2Af2V8PuI4HjkkkKBxhCfwrvYR6aaNPqTg+MV3ZxcCh57znYMYtytEOdVR x5d+ArOP8uqfR0WASNwR4+BjPY32WVDCS/3D382SEN3iW0nsA71CeGtNE0/VgR8vPaCI VDik0aC9AWyFBe1k0vg1ncaEP6TgRT7jNowA3oNxvh8APm+N9KScta8xiNVxicktMb2V ocLFl+RXP4dp1lo1F9SGCG5GdOZcJuf9cj9Dq+c8fWeXsNGEDkwVzF20H3pK1DyCXW4u z35w== 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 (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id f22si1914677ejw.196.2019.01.29.10.50.26 for ; Tue, 29 Jan 2019 10:50:26 -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 815EB15AB; Tue, 29 Jan 2019 10:50:25 -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 B11E93F557; Tue, 29 Jan 2019 10:50:22 -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 , james.morse@arm.com Subject: [PATCH v8 16/26] ACPI / APEI: Let the notification helper specify the fixmap slot Date: Tue, 29 Jan 2019 18:48:52 +0000 Message-Id: <20190129184902.102850-17-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 ghes_copy_tofrom_phys() uses a different fixmap slot depending on in_nmi(). This doesn't work when there are multiple NMI-like notifications, that could interrupt each other. As with the locking, move the chosen fixmap_idx to the notification helper. This only matters for NMI-like notifications, anything calling ghes_proc() can use the IRQ fixmap slot as its already holding an irqsave spinlock. This lets us collapse the ghes_ioremap_pfn_*() helpers. Signed-off-by: James Morse Reviewed-by: Borislav Petkov --- The fixmap-idx and vaddr are passed back to ghes_unmap() to allow ioremap() to be used in process context in the future. This will let us send tlbi-ipi for notifications that don't mask irqs. Changes since v7: * Wwitched unmap arg order for concistency, p/v addr is always first * use the enum name for the fixmap_idx, in the hope the compiler validates it. --- drivers/acpi/apei/ghes.c | 92 +++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 53 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index c6bc73281d6a..ccad57468ab7 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -127,38 +128,24 @@ static atomic_t ghes_estatus_cache_alloced; static int ghes_panic_timeout __read_mostly = 30; -static void __iomem *ghes_ioremap_pfn_nmi(u64 pfn) +static void __iomem *ghes_map(u64 pfn, enum fixed_addresses fixmap_idx) { phys_addr_t paddr; pgprot_t prot; - paddr = pfn << PAGE_SHIFT; + paddr = PFN_PHYS(pfn); prot = arch_apei_get_mem_attribute(paddr); - __set_fixmap(FIX_APEI_GHES_NMI, paddr, prot); + __set_fixmap(fixmap_idx, paddr, prot); - return (void __iomem *) fix_to_virt(FIX_APEI_GHES_NMI); + return (void __iomem *) __fix_to_virt(fixmap_idx); } -static void __iomem *ghes_ioremap_pfn_irq(u64 pfn) +static void ghes_unmap(void __iomem *vaddr, enum fixed_addresses fixmap_idx) { - phys_addr_t paddr; - pgprot_t prot; - - paddr = pfn << PAGE_SHIFT; - prot = arch_apei_get_mem_attribute(paddr); - __set_fixmap(FIX_APEI_GHES_IRQ, paddr, prot); + int _idx = virt_to_fix((unsigned long)vaddr); - return (void __iomem *) fix_to_virt(FIX_APEI_GHES_IRQ); -} - -static void ghes_iounmap_nmi(void) -{ - clear_fixmap(FIX_APEI_GHES_NMI); -} - -static void ghes_iounmap_irq(void) -{ - clear_fixmap(FIX_APEI_GHES_IRQ); + WARN_ON_ONCE(fixmap_idx != _idx); + clear_fixmap(fixmap_idx); } int ghes_estatus_pool_init(int num_ghes) @@ -283,20 +270,16 @@ static inline int ghes_severity(int severity) } static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len, - int from_phys) + int from_phys, + enum fixed_addresses fixmap_idx) { void __iomem *vaddr; - int in_nmi = in_nmi(); u64 offset; u32 trunk; while (len > 0) { offset = paddr - (paddr & PAGE_MASK); - if (in_nmi) { - vaddr = ghes_ioremap_pfn_nmi(paddr >> PAGE_SHIFT); - } else { - vaddr = ghes_ioremap_pfn_irq(paddr >> PAGE_SHIFT); - } + vaddr = ghes_map(PHYS_PFN(paddr), fixmap_idx); trunk = PAGE_SIZE - offset; trunk = min(trunk, len); if (from_phys) @@ -306,15 +289,13 @@ static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len, len -= trunk; paddr += trunk; buffer += trunk; - if (in_nmi) { - ghes_iounmap_nmi(); - } else { - ghes_iounmap_irq(); - } + ghes_unmap(vaddr, fixmap_idx); } } -static int ghes_read_estatus(struct ghes *ghes, u64 *buf_paddr) +static int ghes_read_estatus(struct ghes *ghes, u64 *buf_paddr, + enum fixed_addresses fixmap_idx) + { struct acpi_hest_generic *g = ghes->generic; u32 len; @@ -332,7 +313,7 @@ static int ghes_read_estatus(struct ghes *ghes, u64 *buf_paddr) return -ENOENT; ghes_copy_tofrom_phys(ghes->estatus, *buf_paddr, - sizeof(*ghes->estatus), 1); + sizeof(*ghes->estatus), 1, fixmap_idx); if (!ghes->estatus->block_status) { *buf_paddr = 0; return -ENOENT; @@ -348,7 +329,7 @@ static int ghes_read_estatus(struct ghes *ghes, u64 *buf_paddr) goto err_read_block; ghes_copy_tofrom_phys(ghes->estatus + 1, *buf_paddr + sizeof(*ghes->estatus), - len - sizeof(*ghes->estatus), 1); + len - sizeof(*ghes->estatus), 1, fixmap_idx); if (cper_estatus_check(ghes->estatus)) goto err_read_block; rc = 0; @@ -361,7 +342,8 @@ static int ghes_read_estatus(struct ghes *ghes, u64 *buf_paddr) return rc; } -static void ghes_clear_estatus(struct ghes *ghes, u64 buf_paddr) +static void ghes_clear_estatus(struct ghes *ghes, u64 buf_paddr, + enum fixed_addresses fixmap_idx) { ghes->estatus->block_status = 0; @@ -369,7 +351,8 @@ static void ghes_clear_estatus(struct ghes *ghes, u64 buf_paddr) return; ghes_copy_tofrom_phys(ghes->estatus, buf_paddr, - sizeof(ghes->estatus->block_status), 0); + sizeof(ghes->estatus->block_status), 0, + fixmap_idx); /* * GHESv2 type HEST entries introduce support for error acknowledgment, @@ -668,11 +651,12 @@ static void ghes_estatus_cache_add( rcu_read_unlock(); } -static void __ghes_panic(struct ghes *ghes, u64 buf_paddr) +static void __ghes_panic(struct ghes *ghes, u64 buf_paddr, + enum fixed_addresses fixmap_idx) { __ghes_print_estatus(KERN_EMERG, ghes->generic, ghes->estatus); - ghes_clear_estatus(ghes, buf_paddr); + ghes_clear_estatus(ghes, buf_paddr, fixmap_idx); /* reboot to log the error! */ if (!panic_timeout) @@ -685,12 +669,12 @@ static int ghes_proc(struct ghes *ghes) u64 buf_paddr; int rc; - rc = ghes_read_estatus(ghes, &buf_paddr); + rc = ghes_read_estatus(ghes, &buf_paddr, FIX_APEI_GHES_IRQ); if (rc) goto out; if (ghes_severity(ghes->estatus->error_severity) >= GHES_SEV_PANIC) { - __ghes_panic(ghes, buf_paddr); + __ghes_panic(ghes, buf_paddr, FIX_APEI_GHES_IRQ); } if (!ghes_estatus_cached(ghes->estatus)) { @@ -700,7 +684,7 @@ static int ghes_proc(struct ghes *ghes) ghes_do_proc(ghes, ghes->estatus); out: - ghes_clear_estatus(ghes, buf_paddr); + ghes_clear_estatus(ghes, buf_paddr, FIX_APEI_GHES_IRQ); return rc; } @@ -866,36 +850,38 @@ static void __process_error(struct ghes *ghes) #endif } -static int ghes_in_nmi_queue_one_entry(struct ghes *ghes) +static int ghes_in_nmi_queue_one_entry(struct ghes *ghes, + enum fixed_addresses fixmap_idx) { u64 buf_paddr; int sev; - if (ghes_read_estatus(ghes, &buf_paddr)) { - ghes_clear_estatus(ghes, buf_paddr); + if (ghes_read_estatus(ghes, &buf_paddr, fixmap_idx)) { + ghes_clear_estatus(ghes, buf_paddr, fixmap_idx); return -ENOENT; } sev = ghes_severity(ghes->estatus->error_severity); if (sev >= GHES_SEV_PANIC) { ghes_print_queued_estatus(); - __ghes_panic(ghes, buf_paddr); + __ghes_panic(ghes, buf_paddr, fixmap_idx); } __process_error(ghes); - ghes_clear_estatus(ghes, buf_paddr); + ghes_clear_estatus(ghes, buf_paddr, fixmap_idx); return 0; } -static int ghes_in_nmi_spool_from_list(struct list_head *rcu_list) +static int ghes_in_nmi_spool_from_list(struct list_head *rcu_list, + enum fixed_addresses fixmap_idx) { int err, ret = -ENOENT; struct ghes *ghes; rcu_read_lock(); list_for_each_entry_rcu(ghes, rcu_list, list) { - err = ghes_in_nmi_queue_one_entry(ghes); + err = ghes_in_nmi_queue_one_entry(ghes, fixmap_idx); if (!err) ret = 0; } @@ -920,7 +906,7 @@ int ghes_notify_sea(void) int rv; raw_spin_lock(&ghes_notify_lock_sea); - rv = ghes_in_nmi_spool_from_list(&ghes_sea); + rv = ghes_in_nmi_spool_from_list(&ghes_sea, FIX_APEI_GHES_NMI); raw_spin_unlock(&ghes_notify_lock_sea); return rv; @@ -963,7 +949,7 @@ static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) return ret; raw_spin_lock(&ghes_notify_lock_nmi); - err = ghes_in_nmi_spool_from_list(&ghes_nmi); + err = ghes_in_nmi_spool_from_list(&ghes_nmi, FIX_APEI_GHES_NMI); if (!err) ret = NMI_HANDLED; raw_spin_unlock(&ghes_notify_lock_nmi); From patchwork Tue Jan 29 18:48:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786955 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 C73CF1874 for ; Tue, 29 Jan 2019 18:50:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B76A92D697 for ; Tue, 29 Jan 2019 18:50:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B51072D6CF; Tue, 29 Jan 2019 18:50:36 +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 0571F2D697 for ; Tue, 29 Jan 2019 18:50:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6DF228E0013; Tue, 29 Jan 2019 13:50:31 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6B6CE8E0003; Tue, 29 Jan 2019 13:50:31 -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 5A9318E0013; Tue, 29 Jan 2019 13:50:31 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id EE4268E0003 for ; Tue, 29 Jan 2019 13:50:30 -0500 (EST) Received: by mail-ed1-f71.google.com with SMTP id l45so8325919edb.1 for ; Tue, 29 Jan 2019 10:50:30 -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=GqLHpU/e3+KCvIM2ul3N2tkCkCGFhOd/kfF+9qLa44o=; b=qO03sy66dPo4zaOgx2cdkCtyJv2UBbNT2jtDXL9bG18saxmUCnGkQ+j3ieRg/ccyPD s0Yb8VbWwzovJ/IQhViKuxViEVzkbb2K1zOZ674jigODJ6kOEeG8Dskdv905TNyrIwSn OlBMKDOVRXw6dwiUrYP7VwTE7tUeJaI5CkHpofzRclTBP3tezm3hRnzxQ4Flx258AOLW 9ChLSM/3y3chnczwt9KJZEhCT0Q+XT0seVJrDaRDJZP2KxJtRNejgM1j0Mk/iVlPdB6d hVNtC+8h2TvemEECZ3u5b8rxUzxRkDQKLTHSQyrBqzq/TyO8GppXwJXmkPCoargdb/51 NzkA== 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: AJcUukfzF8djYpNVUoSZ8ijB930UABw8lPqr6EJpgm70yt5JvWOMHkz4 HdmNSAHjGtOpcNugSiGiT4uaUjYgobba8CUfCzhoSQD1TokFtm8rPYBYjteKzNrDTdVnK5Qttjl zF7xVBRIh2tyWoRird7HMSb7CnI5UlAYAg/NmnRCaRvXOeV4vSsIW7MCkk+rytseCwQ== X-Received: by 2002:a17:906:ee2:: with SMTP id x2mr5448156eji.202.1548787830442; Tue, 29 Jan 2019 10:50:30 -0800 (PST) X-Google-Smtp-Source: ALg8bN5sicFCOZGQx8dkvN3ecJW7rpzbVztUQc7KY9oelFOe/XfUkp9uoQ8OxfPHx5/kH5ZYt0s6 X-Received: by 2002:a17:906:ee2:: with SMTP id x2mr5448102eji.202.1548787829461; Tue, 29 Jan 2019 10:50:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787829; cv=none; d=google.com; s=arc-20160816; b=my5zCf1DrDpc/gzKW3z0rZfmAahW6JsF1l0HxOjjfJaBcuCF/hzK0Uf4lAOnq62JsD x0zdpg5Ckt1O7/Ngbm2ljz40V0dKcRZP6zvEoo22WDTCaY0x//aMThl4rMhgOOirOc9s 5XUTPw+57LqJhKvc9hSeDxnv/tmKhYt0X8CVPILthzTU+Of07I3HF3hzS7imBOR+crOK vfJpWVvVP5ReS1yZV9KhOtQqTmOVtCyhfC6bFJ4qqONXg5ARxFAO1jwc9VtSymtNxdia 5Jkvzj3TCadz5eo7ui36k+CYK6GYNmFXBNePwRVU45DYIltC+W11lGYdk+kBaz9mPHpl cjYA== 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=GqLHpU/e3+KCvIM2ul3N2tkCkCGFhOd/kfF+9qLa44o=; b=rGgp99gQwHpJ/a77diVy3EMUg7O3zUr0NcdwLiJqslQ2U7f8VsGGDJPv6DoMuaXIwl XElkVB75zN6mboMeKPc0E92m7j6Qa4Z+ulm0LIzKLQUZa4bTJDprIM0wTZ7riy4tUYoJ l5Hj/Q+6y90vdkEqBTxGNm+5kZSwMPAXA6CSHLlgudvNtvOUA9khsD7yaRkng9TCbMHM xVQdgP/UPNb4JvCA3CtkIowyEdxIYasasmCxw3/uQWsn94KafWMTykkaVEeEPcZ7jHRL y2OgjOP+c+LkDeaArXrQnXXfBnKJe7E99Hx3IqD9V9/qcjdp3vr4xWQDKsK99ySAvwf0 W1Ow== 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 (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id ge18si756742ejb.59.2019.01.29.10.50.29 for ; Tue, 29 Jan 2019 10:50:29 -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 6CC841596; Tue, 29 Jan 2019 10:50:28 -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 C01DC3F557; Tue, 29 Jan 2019 10:50:25 -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 , james.morse@arm.com Subject: [PATCH v8 17/26] ACPI / APEI: Pass ghes and estatus separately to avoid a later copy Date: Tue, 29 Jan 2019 18:48:53 +0000 Message-Id: <20190129184902.102850-18-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 The NMI-like notifications scribble over ghes->estatus, before copying it somewhere else. If this interrupts the ghes_probe() code calling ghes_proc() on each struct ghes, the data is corrupted. All the NMI-like notifications should use a queued estatus entry from the beginning, instead of the ghes version, then copying it. To do this, break up any use of "ghes->estatus" so that all functions take the estatus as an argument. This patch just moves these ghes->estatus dereferences into separate arguments, no change in behaviour. struct ghes becomes unused in ghes_clear_estatus() as it only wanted ghes->estatus, which we now pass directly. This is removed. Signed-off-by: James Morse --- Changes since v6: * Changed subject * Renamed ghes_estatus to src_estatus, which is a little clearer * Removed struct ghes from ghes_clear_estatus() now that this becomes unused in this patch. * Mangled the commit message to be different --- drivers/acpi/apei/ghes.c | 92 +++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 43 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index ccad57468ab7..f95db2398dd5 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -293,9 +293,9 @@ static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len, } } -static int ghes_read_estatus(struct ghes *ghes, u64 *buf_paddr, - enum fixed_addresses fixmap_idx) - +static int ghes_read_estatus(struct ghes *ghes, + struct acpi_hest_generic_status *estatus, + u64 *buf_paddr, enum fixed_addresses fixmap_idx) { struct acpi_hest_generic *g = ghes->generic; u32 len; @@ -312,25 +312,25 @@ static int ghes_read_estatus(struct ghes *ghes, u64 *buf_paddr, if (!*buf_paddr) return -ENOENT; - ghes_copy_tofrom_phys(ghes->estatus, *buf_paddr, - sizeof(*ghes->estatus), 1, fixmap_idx); - if (!ghes->estatus->block_status) { + ghes_copy_tofrom_phys(estatus, *buf_paddr, sizeof(*estatus), 1, + fixmap_idx); + if (!estatus->block_status) { *buf_paddr = 0; return -ENOENT; } rc = -EIO; - len = cper_estatus_len(ghes->estatus); - if (len < sizeof(*ghes->estatus)) + len = cper_estatus_len(estatus); + if (len < sizeof(*estatus)) goto err_read_block; if (len > ghes->generic->error_block_length) goto err_read_block; - if (cper_estatus_check_header(ghes->estatus)) + if (cper_estatus_check_header(estatus)) goto err_read_block; - ghes_copy_tofrom_phys(ghes->estatus + 1, - *buf_paddr + sizeof(*ghes->estatus), - len - sizeof(*ghes->estatus), 1, fixmap_idx); - if (cper_estatus_check(ghes->estatus)) + ghes_copy_tofrom_phys(estatus + 1, + *buf_paddr + sizeof(*estatus), + len - sizeof(*estatus), 1, fixmap_idx); + if (cper_estatus_check(estatus)) goto err_read_block; rc = 0; @@ -342,16 +342,17 @@ static int ghes_read_estatus(struct ghes *ghes, u64 *buf_paddr, return rc; } -static void ghes_clear_estatus(struct ghes *ghes, u64 buf_paddr, - enum fixed_addresses fixmap_idx) +static void ghes_clear_estatus(struct ghes *ghes, + struct acpi_hest_generic_status *estatus, + u64 buf_paddr, enum fixed_addresses fixmap_idx) { - ghes->estatus->block_status = 0; + estatus->block_status = 0; if (!buf_paddr) return; - ghes_copy_tofrom_phys(ghes->estatus, buf_paddr, - sizeof(ghes->estatus->block_status), 0, + ghes_copy_tofrom_phys(estatus, buf_paddr, + sizeof(estatus->block_status), 0, fixmap_idx); /* @@ -651,12 +652,13 @@ static void ghes_estatus_cache_add( rcu_read_unlock(); } -static void __ghes_panic(struct ghes *ghes, u64 buf_paddr, - enum fixed_addresses fixmap_idx) +static void __ghes_panic(struct ghes *ghes, + struct acpi_hest_generic_status *estatus, + u64 buf_paddr, enum fixed_addresses fixmap_idx) { - __ghes_print_estatus(KERN_EMERG, ghes->generic, ghes->estatus); + __ghes_print_estatus(KERN_EMERG, ghes->generic, estatus); - ghes_clear_estatus(ghes, buf_paddr, fixmap_idx); + ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx); /* reboot to log the error! */ if (!panic_timeout) @@ -666,25 +668,25 @@ static void __ghes_panic(struct ghes *ghes, u64 buf_paddr, static int ghes_proc(struct ghes *ghes) { + struct acpi_hest_generic_status *estatus = ghes->estatus; u64 buf_paddr; int rc; - rc = ghes_read_estatus(ghes, &buf_paddr, FIX_APEI_GHES_IRQ); + rc = ghes_read_estatus(ghes, estatus, &buf_paddr, FIX_APEI_GHES_IRQ); if (rc) goto out; - if (ghes_severity(ghes->estatus->error_severity) >= GHES_SEV_PANIC) { - __ghes_panic(ghes, buf_paddr, FIX_APEI_GHES_IRQ); - } + if (ghes_severity(estatus->error_severity) >= GHES_SEV_PANIC) + __ghes_panic(ghes, estatus, buf_paddr, FIX_APEI_GHES_IRQ); - if (!ghes_estatus_cached(ghes->estatus)) { - if (ghes_print_estatus(NULL, ghes->generic, ghes->estatus)) - ghes_estatus_cache_add(ghes->generic, ghes->estatus); + if (!ghes_estatus_cached(estatus)) { + if (ghes_print_estatus(NULL, ghes->generic, estatus)) + ghes_estatus_cache_add(ghes->generic, estatus); } - ghes_do_proc(ghes, ghes->estatus); + ghes_do_proc(ghes, estatus); out: - ghes_clear_estatus(ghes, buf_paddr, FIX_APEI_GHES_IRQ); + ghes_clear_estatus(ghes, estatus, buf_paddr, FIX_APEI_GHES_IRQ); return rc; } @@ -825,17 +827,20 @@ static void ghes_print_queued_estatus(void) } /* Save estatus for further processing in IRQ context */ -static void __process_error(struct ghes *ghes) +static void __process_error(struct ghes *ghes, + struct acpi_hest_generic_status *src_estatus) { -#ifdef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG u32 len, node_len; struct ghes_estatus_node *estatus_node; struct acpi_hest_generic_status *estatus; - if (ghes_estatus_cached(ghes->estatus)) + if (!IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG)) return; - len = cper_estatus_len(ghes->estatus); + if (ghes_estatus_cached(src_estatus)) + return; + + len = cper_estatus_len(src_estatus); node_len = GHES_ESTATUS_NODE_LEN(len); estatus_node = (void *)gen_pool_alloc(ghes_estatus_pool, node_len); @@ -845,30 +850,31 @@ static void __process_error(struct ghes *ghes) estatus_node->ghes = ghes; estatus_node->generic = ghes->generic; estatus = GHES_ESTATUS_FROM_NODE(estatus_node); - memcpy(estatus, ghes->estatus, len); + memcpy(estatus, src_estatus, len); llist_add(&estatus_node->llnode, &ghes_estatus_llist); -#endif } static int ghes_in_nmi_queue_one_entry(struct ghes *ghes, enum fixed_addresses fixmap_idx) { + struct acpi_hest_generic_status *estatus = ghes->estatus; u64 buf_paddr; int sev; - if (ghes_read_estatus(ghes, &buf_paddr, fixmap_idx)) { - ghes_clear_estatus(ghes, buf_paddr, fixmap_idx); + if (ghes_read_estatus(ghes, estatus, &buf_paddr, fixmap_idx)) { + ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx); return -ENOENT; } - sev = ghes_severity(ghes->estatus->error_severity); + sev = ghes_severity(estatus->error_severity); if (sev >= GHES_SEV_PANIC) { ghes_print_queued_estatus(); - __ghes_panic(ghes, buf_paddr, fixmap_idx); + __ghes_panic(ghes, estatus, buf_paddr, fixmap_idx); + } - __process_error(ghes); - ghes_clear_estatus(ghes, buf_paddr, fixmap_idx); + __process_error(ghes, estatus); + ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx); return 0; } From patchwork Tue Jan 29 18:48:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786957 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 8EBB413BF for ; Tue, 29 Jan 2019 18:50:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FD392D6AD for ; Tue, 29 Jan 2019 18:50:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DE982D650; Tue, 29 Jan 2019 18:50: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 0FC972D6AD for ; Tue, 29 Jan 2019 18:50:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4E83A8E0014; Tue, 29 Jan 2019 13:50:34 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 494D78E0003; Tue, 29 Jan 2019 13:50:34 -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 362FB8E0014; Tue, 29 Jan 2019 13:50:34 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by kanga.kvack.org (Postfix) with ESMTP id CE81D8E0003 for ; Tue, 29 Jan 2019 13:50:33 -0500 (EST) Received: by mail-ed1-f72.google.com with SMTP id c34so8136849edb.8 for ; Tue, 29 Jan 2019 10:50:33 -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=81UVWBzuiiLWxlt5Zhyss5LIIbWmTL+dhjejw8e0YyU=; b=b0uX+mMOM/OaUwooOQgxTVvrcBPpFVfK2OXYYlKkrZyr/6rmEf3aMHftDG49gGOnm0 kj1iRZWeOWzGkxP60njq0vrfS2FnvFjWafxMeJura1XxpgkkluRIcjEIrFsb5f07xDA+ NULj3wRk+Bk0JILoQtsTqi1xp3XmscvcaCIkkyoxNnokSugWFQRoFEAbE+c20RrfbzUB 8JBn+R8mw6UkEeysFwiczyBWBJzlbLVQymk0wYb6hAq8nTsGi6kJ/deOA6z51+dgZQwO 7dTCCEtrwX0xOh5HsmLn0KnKg0bwsvEWpsWP2MeoDvnHgb5ETyFGQoEZBS7gNiLi5uRu hVNw== 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: AJcUukc096SzJoODO6DHUjxEB3YzJUVqcdJz8igPVFhXyDO4exuLIB11 AqsVCbCcuAH1y8qPsux0yMBqdC4OPml6DpYa4NkHxq9TgNS4QRQ4WkohmrOY9kQAnEBM90K/FH1 6mmho9FpAc5YFXHrnA2lz23n6uxP7YtXIfr3lERpn9nTv8WSV1PcXAaBCNfJXBKJXGQ== X-Received: by 2002:a05:6402:8d2:: with SMTP id d18mr27058927edz.119.1548787833349; Tue, 29 Jan 2019 10:50:33 -0800 (PST) X-Google-Smtp-Source: ALg8bN5Ue/JKRduXMJ0TgtL2FAfHvCY5OPa2F0ZayK2pc7JEfY/6lEGZekwMl161EwcdJULQKXU7 X-Received: by 2002:a05:6402:8d2:: with SMTP id d18mr27058864edz.119.1548787832296; Tue, 29 Jan 2019 10:50:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787832; cv=none; d=google.com; s=arc-20160816; b=v7+Vi8YI79gVKRk5mQe7rkVcCEYwAhbecR4mKIBdstGme1iizH80yqq/76n8dtq+Mi hsUenK4oHaCOv9nvc9qDy6fSTGiIf0vPUMSunfRCjsnUjeP4IN0XAIg6DtE+jz1OMlsa q9vkELXH3V2sFCr87Xwjr5xIMbIgEnGN3x42uEdmNbSsSTNlDau0J+v0yqF0EVRMu/sD MwkGU7rOAkAdxum+6PR6bAbpWXvA+uCRgIxliw7swijl/yT5icFf0vAx0i343s5kGPoZ 8TR56f9Xv61IZbTBfIKC1So/8oldroZjhzN/kLUWjiUBK9X8hXRHmJqrZ0lp3z4KE5+T T46w== 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=81UVWBzuiiLWxlt5Zhyss5LIIbWmTL+dhjejw8e0YyU=; b=0oNuboi1A5uKsh0RtKN8M5/knbU5I7tT2gJjoWN/BdRPR5q9l36qvYUee6vatn4jjJ 0UXh4TgFP/1MGYD1oGDLc09XRb14AmBdqrDcw/SMnib94Kz+aSjpDFY5fFogH+4PBWx7 psTURinZmwOV9xAc8xfxfr3TPbKgOu5hgboX3Xfe5Pqq+PEwtpXD09eNyCnTSgdhJP04 e+DW8e2kWy47CnoOtoliwFP1JesMLv30KqZcmmWMmL7QGhUZRTEBqOyuk3oAndypFZgL e+i84BSRxxOJZufioK6OM+jc5+TopEVZMHCjwq6+lVO/8GPXPv8wS9xVTB4zn3IczdtJ wyjg== 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 d15si1130618eds.170.2019.01.29.10.50.32 for ; Tue, 29 Jan 2019 10:50:32 -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 5894715AB; Tue, 29 Jan 2019 10:50:31 -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 AB9013F557; Tue, 29 Jan 2019 10:50:28 -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 , james.morse@arm.com Subject: [PATCH v8 18/26] ACPI / APEI: Make GHES estatus header validation more user friendly Date: Tue, 29 Jan 2019 18:48:54 +0000 Message-Id: <20190129184902.102850-19-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 ghes_read_estatus() checks various lengths in the top-level header to ensure the CPER records to be read aren't obviously corrupt. Take the opportunity to make this more user-friendly, printing a (ratelimited) message about the nature of the header format error. Suggested-by: Borislav Petkov Signed-off-by: James Morse --- drivers/acpi/apei/ghes.c | 46 ++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index f95db2398dd5..9391fff71344 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -293,6 +293,30 @@ static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len, } } +/* Check the top-level record header has an appropriate size. */ +int __ghes_check_estatus(struct ghes *ghes, + struct acpi_hest_generic_status *estatus) +{ + u32 len = cper_estatus_len(estatus); + + if (len < sizeof(*estatus)) { + pr_warn_ratelimited(FW_WARN GHES_PFX "Truncated error status block!\n"); + return -EIO; + } + + if (len > ghes->generic->error_block_length) { + pr_warn_ratelimited(FW_WARN GHES_PFX "Invalid error status block length!\n"); + return -EIO; + } + + if (cper_estatus_check_header(estatus)) { + pr_warn_ratelimited(FW_WARN GHES_PFX "Invalid CPER header!\n"); + return -EIO; + } + + return 0; +} + static int ghes_read_estatus(struct ghes *ghes, struct acpi_hest_generic_status *estatus, u64 *buf_paddr, enum fixed_addresses fixmap_idx) @@ -319,27 +343,21 @@ static int ghes_read_estatus(struct ghes *ghes, return -ENOENT; } - rc = -EIO; + rc = __ghes_check_estatus(ghes, estatus); + if (rc) + return rc; + len = cper_estatus_len(estatus); - if (len < sizeof(*estatus)) - goto err_read_block; - if (len > ghes->generic->error_block_length) - goto err_read_block; - if (cper_estatus_check_header(estatus)) - goto err_read_block; ghes_copy_tofrom_phys(estatus + 1, *buf_paddr + sizeof(*estatus), len - sizeof(*estatus), 1, fixmap_idx); - if (cper_estatus_check(estatus)) - goto err_read_block; - rc = 0; - -err_read_block: - if (rc) + if (cper_estatus_check(estatus)) { pr_warn_ratelimited(FW_WARN GHES_PFX "Failed to read error status block!\n"); + return -EIO; + } - return rc; + return 0; } static void ghes_clear_estatus(struct ghes *ghes, From patchwork Tue Jan 29 18:48:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786967 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 054CE159A for ; Tue, 29 Jan 2019 18:50:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB5B02D6C4 for ; Tue, 29 Jan 2019 18:50:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E97F02D697; Tue, 29 Jan 2019 18:50:44 +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 89A682D73D for ; Tue, 29 Jan 2019 18:50:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 77BB38E0003; Tue, 29 Jan 2019 13:50:37 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 711D48E0017; Tue, 29 Jan 2019 13:50:37 -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 386238E0015; Tue, 29 Jan 2019 13:50:37 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id D019E8E0003 for ; Tue, 29 Jan 2019 13:50:36 -0500 (EST) Received: by mail-ed1-f69.google.com with SMTP id e12so8296076edd.16 for ; Tue, 29 Jan 2019 10:50:36 -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=cB5Vc/XqlFzwaz7GNJcyfHSezxcsXClhbOckn8nvs0Q=; b=cT+5hzeu33B0scNrnddjTFH1Ri3+SXyC3TlB7xwIH/cZTxshnAoMh7evlWwPlxUFJh wO4tj1MOsQ/X2L32e6+3Wit7PDmnihcCYTIFKOeQIGr5RJYHQ65+TJtlheZ7nJEvmxk8 OWxNC5pdm4V+eGtHxE7bbyychV2jsw661ENCF4XhtJhLHGtwD20BqatHOGbH9v0Bc31/ kUNjDa/ANwnTmxRy9RqeIyvR5ssWttcJm/YQpGKxzl7tKJtINIjibhR/NeOhUObvCQE7 RIA8umTP41rVlgYR6v4EL+ZyNnRgmFAG5t3wLOs+KO3mlndFA5URZOFI5bCKFGthSoS/ aZJw== 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: AJcUukdh+5uIOF8gicDI3bgGEWkdW0dqBefXwJ/UpBtZbmtGCHxR8CWg pzRbzO/JzMiD5jj70ZXCnO2rZ4M/SopK0rQD8ilT0Bpt4jUjESFTVdrmRyp5g2Z1DgO7/PMzVVO yrAHY4feJ3hDkSAWaTlfULEP2wgXLxACjF7ZjG0ohfsy909Z9HjEUC192ylSGA3kxuQ== X-Received: by 2002:a50:983a:: with SMTP id g55mr26742169edb.143.1548787836318; Tue, 29 Jan 2019 10:50:36 -0800 (PST) X-Google-Smtp-Source: ALg8bN4q5RE98aTwJ2FeRTRciETQUYshlNcj/dJQ1YfyvqEozoC6ghDqDoXejaxoYhhKAzfV5UBR X-Received: by 2002:a50:983a:: with SMTP id g55mr26742111edb.143.1548787835331; Tue, 29 Jan 2019 10:50:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787835; cv=none; d=google.com; s=arc-20160816; b=cHnlfuuykly8IouW7kbbR/oqxa49BO32WTc+1w3apP+jJoTXWqUgzB1h5/bnKjFmtV 5a3CkShl7zFc1FdpjUBpZTe7AbxpTII+DHnkRzXAvHsinasVcJmwOPk7vpw8UcuqJvbb xKSEtcCk66xq1tQYxVg853gwNK9J7MJmp/+o9xuANWLFcy3IflVN0mrXc8ip+FqWfHUF M81cVzC3tHgSALDsCjogk0r+O6qKygJzEAmAWdF+gpBLpssG62/QGMQCqeo6TSSVGxAV sOeq3Y0XpDYlabT8LRLna16IVYaa+T5XNTcSZtGd5RJptspPyk/dRG/O+yEtx9ShVrgD Y87w== 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=cB5Vc/XqlFzwaz7GNJcyfHSezxcsXClhbOckn8nvs0Q=; b=zUBNlDXPrBfEvyakGox6Jwsx4Jc/7pyrM5GdMFrclwbkKQnNCoboYMuoVL5NSQl7Sr HozACsaidNCLKOQMgl0+oa9ubIohk/ujbtOwepJ5k6OMS+8PvPzcsiTfL6MZLFWJGiEX Bh+HWQnLnz0zIJmkO2BpuLgmvUOde9RSYYzFvbeOz93VTrv/54Yjs3/hL2f+uGD4Kio9 MavnH9RvZQ3v/cSGeR4KwKy/qwGNiEx4g4SIZppYMb4O+Yszt72UWWqX3DjsZnXz9w5E UGTNfGE1cPEyE09X5Lj7FSlV1J66JoPGgy9sf1dLsqN+ahDaOvSnfLdtdZKSDerI/u+e DH4Q== 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 o11si1360504edv.168.2019.01.29.10.50.34 for ; Tue, 29 Jan 2019 10:50:35 -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 43C9115AB; Tue, 29 Jan 2019 10:50:34 -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 9741E3F557; Tue, 29 Jan 2019 10:50:31 -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 , james.morse@arm.com Subject: [PATCH v8 19/26] ACPI / APEI: Split ghes_read_estatus() to allow a peek at the CPER length Date: Tue, 29 Jan 2019 18:48:55 +0000 Message-Id: <20190129184902.102850-20-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 ghes_read_estatus() reads the record address, then the record's header, then performs some sanity checks before reading the records into the provided estatus buffer. To provide this estatus buffer the caller must know the size of the records in advance, or always provide a worst-case sized buffer as happens today for the non-NMI notifications. Add a function to peek at the record's header to find the size. This will let the NMI path allocate the right amount of memory before reading the records, instead of using the worst-case size, and having to copy the records. Split ghes_read_estatus() to create __ghes_peek_estatus() which returns the address and size of the CPER records. Signed-off-by: James Morse Changes since v7: * Grammar * concistent argument ordering Changes since v6: * Additional buf_addr = 0 error handling * Moved checking out of peek-estatus * Reworded an error message so we can tell them apart --- drivers/acpi/apei/ghes.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 9391fff71344..12375a82fa03 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -317,12 +317,12 @@ int __ghes_check_estatus(struct ghes *ghes, return 0; } -static int ghes_read_estatus(struct ghes *ghes, - struct acpi_hest_generic_status *estatus, - u64 *buf_paddr, enum fixed_addresses fixmap_idx) +/* Read the CPER block, returning its address, and header in estatus. */ +static int __ghes_peek_estatus(struct ghes *ghes, + struct acpi_hest_generic_status *estatus, + u64 *buf_paddr, enum fixed_addresses fixmap_idx) { struct acpi_hest_generic *g = ghes->generic; - u32 len; int rc; rc = apei_read(buf_paddr, &g->error_status_address); @@ -343,14 +343,14 @@ static int ghes_read_estatus(struct ghes *ghes, return -ENOENT; } - rc = __ghes_check_estatus(ghes, estatus); - if (rc) - return rc; + return __ghes_check_estatus(ghes, estatus); +} - len = cper_estatus_len(estatus); - ghes_copy_tofrom_phys(estatus + 1, - *buf_paddr + sizeof(*estatus), - len - sizeof(*estatus), 1, fixmap_idx); +static int __ghes_read_estatus(struct acpi_hest_generic_status *estatus, + u64 buf_paddr, enum fixed_addresses fixmap_idx, + size_t buf_len) +{ + ghes_copy_tofrom_phys(estatus, buf_paddr, buf_len, 1, fixmap_idx); if (cper_estatus_check(estatus)) { pr_warn_ratelimited(FW_WARN GHES_PFX "Failed to read error status block!\n"); @@ -360,6 +360,24 @@ static int ghes_read_estatus(struct ghes *ghes, return 0; } +static int ghes_read_estatus(struct ghes *ghes, + struct acpi_hest_generic_status *estatus, + u64 *buf_paddr, enum fixed_addresses fixmap_idx) +{ + int rc; + + rc = __ghes_peek_estatus(ghes, estatus, buf_paddr, fixmap_idx); + if (rc) + return rc; + + rc = __ghes_check_estatus(ghes, estatus); + if (rc) + return rc; + + return __ghes_read_estatus(estatus, *buf_paddr, fixmap_idx, + cper_estatus_len(estatus)); +} + static void ghes_clear_estatus(struct ghes *ghes, struct acpi_hest_generic_status *estatus, u64 buf_paddr, enum fixed_addresses fixmap_idx) From patchwork Tue Jan 29 18:48:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786969 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 A6AE513B4 for ; Tue, 29 Jan 2019 18:50:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 955852D738 for ; Tue, 29 Jan 2019 18:50:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 933772D76D; Tue, 29 Jan 2019 18:50:47 +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 13AE92D73D for ; Tue, 29 Jan 2019 18:50:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 38BFC8E0017; Tue, 29 Jan 2019 13:50:40 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 337C18E0015; Tue, 29 Jan 2019 13:50:40 -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 227038E0017; Tue, 29 Jan 2019 13:50:40 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id B35FA8E0015 for ; Tue, 29 Jan 2019 13:50:39 -0500 (EST) Received: by mail-ed1-f69.google.com with SMTP id z10so8314133edz.15 for ; Tue, 29 Jan 2019 10:50:39 -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=QOY/2hNJALFKKfjWnlCJcXzlT4qedTCy7caAQiFnm7o=; b=Ns6punK9vjU1uk3XUOPTB6MJkZ7dpbhj9DG0NSVUU7shbY1luzMRlOtoAqJWAPQeIm U7WCThHSDoDoFWKK7YycG6DsBQlyqDoFchIjxAS4az9LriZ3r0lBviuj5Bi+my2mzwcQ KHfryjytKsrGczE5Ba5fxyD+ZxztzgBtZDovWPRQXEG9U/p/reRD1G61eT+nDxjwSRH5 3TEQaKwNbBqb4U1QBujlqKo3cyp3d7747QQqpnISYd4OG/ttTawM3adTD5Z/KfZPYmvJ SJrHzJODGPU4nzNleyRtuQ/QqOP6DgWSzERpMu1DIrMmxXcO8csheMdMkUCcgCCif/x8 skBg== 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: AJcUukfbdxeFpUVxVMEcvQr+Us35v0u6TtkvRNOyt9HcM3MLMD7TOmEa aRz2/FQ0CCvk5wQAsto66x061K3U/viWgBdmurU9vNuD6YfSmGyhlpmNDo4CXYgAX2lDE4kDr0b 8HxBV0sB01sr2ZDFoNA252/mPrINtm/RyivdibSBRC81fFY1uLhrdGUuxOi+OYjzaMA== X-Received: by 2002:a50:9315:: with SMTP id m21mr26049245eda.58.1548787839239; Tue, 29 Jan 2019 10:50:39 -0800 (PST) X-Google-Smtp-Source: ALg8bN5ZxEbhRj1h2YKyVYmo8FdERc4hWsLzhD1/cO6YnBT8gYhOXo0c3jachEJBRUhHjcnKfozq X-Received: by 2002:a50:9315:: with SMTP id m21mr26049194eda.58.1548787838296; Tue, 29 Jan 2019 10:50:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787838; cv=none; d=google.com; s=arc-20160816; b=mHbhY/ACnWpIoUJXDNfQ+M2Aqi174oKXhXVEW3bWpT4BpGwuMEjmPcJyaPCGPCk+1H LWrsLc6umV05bNy2HQugtDjb1h8/ysuCrdejt+V+l0DkbQVgi2X1PiBWZdQbTx0wQ9IP BjIVwwIp8LQgWrxX00z++XQFqX+oMf6z3FJDXLFqfw3mwWT60JyPCBQzgqQXwAkFnUS4 ibUafSLG7f1MPr3ilSg98adm7SBPFWv+M4ZGgyEgQ3oFPSZLpuxMIz9TytpZYPt6aNsK uTlA5yZ2k/3KCVFYKMaWDIafNKcuxNH6J94mxucJWZxnWnMosT/6d+TsmH56Q4gkf5bz RPdA== 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=QOY/2hNJALFKKfjWnlCJcXzlT4qedTCy7caAQiFnm7o=; b=t9QtGIe2nYNPHnj7M/XO3vNQ3fuZ0D23dD0YabV8/327pMi3T28YhGsEuhAKEeBJut DFCgwt5xQFbjen2dQAqRaaqZm3CVaBkxal/jlEl0tVWHd2io2IZLhuzlRM1bUZ4F7lD6 0Rr4yBOavas94c3AtBR47koOOIwZhPamowu8K+wZm1RrfUKNAk+WYnjbcPWs5ofjJLvN W5XNZfY5T+ZaebzaMJiSr07QhnvL5uHf53gtQ/92fw8HBpod+q505xTg6J4S+HT5BCqQ TU4j3vT5ogWWb2xLw1RozVt1/nlXF6xkGsLxHTEEXEpWfBfeciNaiVveIzAy1WqVG/zr O0aA== 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 f7si3189875eda.363.2019.01.29.10.50.37 for ; Tue, 29 Jan 2019 10:50:38 -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 2FA8F15AB; Tue, 29 Jan 2019 10:50:37 -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 827933F557; Tue, 29 Jan 2019 10:50:34 -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 , james.morse@arm.com Subject: [PATCH v8 20/26] ACPI / APEI: Only use queued estatus entry during in_nmi_queue_one_entry() Date: Tue, 29 Jan 2019 18:48:56 +0000 Message-Id: <20190129184902.102850-21-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 Each struct ghes has an worst-case sized buffer for storing the estatus. If an error is being processed by ghes_proc() in process context this buffer will be in use. If the error source then triggers an NMI-like notification, the same buffer will be used by in_nmi_queue_one_entry() to stage the estatus data, before __process_error() copys it into a queued estatus entry. Merge __process_error()s work into in_nmi_queue_one_entry() so that the queued estatus entry is used from the beginning. Use the new ghes_peek_estatus() to know how much memory to allocate from the ghes_estatus_pool before reading the records. Reported-by: Borislav Petkov Signed-off-by: James Morse Reviewed-by: Borislav Petkov Change since v6: * Added a comment explaining the 'ack-error, then goto no_work'. * Added missing esatus-clearing, which is necessary after reading the GAS, --- drivers/acpi/apei/ghes.c | 64 +++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 12375a82fa03..957c1559ebf5 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -862,57 +862,67 @@ static void ghes_print_queued_estatus(void) } } -/* Save estatus for further processing in IRQ context */ -static void __process_error(struct ghes *ghes, - struct acpi_hest_generic_status *src_estatus) +static int ghes_in_nmi_queue_one_entry(struct ghes *ghes, + enum fixed_addresses fixmap_idx) { - u32 len, node_len; + struct acpi_hest_generic_status *estatus, tmp_header; struct ghes_estatus_node *estatus_node; - struct acpi_hest_generic_status *estatus; + u32 len, node_len; + u64 buf_paddr; + int sev, rc; if (!IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG)) - return; + return -EOPNOTSUPP; - if (ghes_estatus_cached(src_estatus)) - return; + rc = __ghes_peek_estatus(ghes, &tmp_header, &buf_paddr, fixmap_idx); + if (rc) { + ghes_clear_estatus(ghes, &tmp_header, buf_paddr, fixmap_idx); + return rc; + } - len = cper_estatus_len(src_estatus); - node_len = GHES_ESTATUS_NODE_LEN(len); + rc = __ghes_check_estatus(ghes, &tmp_header); + if (rc) { + ghes_clear_estatus(ghes, &tmp_header, buf_paddr, fixmap_idx); + return rc; + } + len = cper_estatus_len(&tmp_header); + node_len = GHES_ESTATUS_NODE_LEN(len); estatus_node = (void *)gen_pool_alloc(ghes_estatus_pool, node_len); if (!estatus_node) - return; + return -ENOMEM; estatus_node->ghes = ghes; estatus_node->generic = ghes->generic; estatus = GHES_ESTATUS_FROM_NODE(estatus_node); - memcpy(estatus, src_estatus, len); - llist_add(&estatus_node->llnode, &ghes_estatus_llist); -} -static int ghes_in_nmi_queue_one_entry(struct ghes *ghes, - enum fixed_addresses fixmap_idx) -{ - struct acpi_hest_generic_status *estatus = ghes->estatus; - u64 buf_paddr; - int sev; - - if (ghes_read_estatus(ghes, estatus, &buf_paddr, fixmap_idx)) { + if (__ghes_read_estatus(estatus, buf_paddr, fixmap_idx, len)) { ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx); - return -ENOENT; + rc = -ENOENT; + goto no_work; } sev = ghes_severity(estatus->error_severity); if (sev >= GHES_SEV_PANIC) { ghes_print_queued_estatus(); __ghes_panic(ghes, estatus, buf_paddr, fixmap_idx); - } - __process_error(ghes, estatus); - ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx); + ghes_clear_estatus(ghes, &tmp_header, buf_paddr, fixmap_idx); - return 0; + /* This error has been reported before, don't process it again. */ + if (ghes_estatus_cached(estatus)) + goto no_work; + + llist_add(&estatus_node->llnode, &ghes_estatus_llist); + + return rc; + +no_work: + gen_pool_free(ghes_estatus_pool, (unsigned long)estatus_node, + node_len); + + return rc; } static int ghes_in_nmi_spool_from_list(struct list_head *rcu_list, From patchwork Tue Jan 29 18:48:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786973 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 3DC8213B4 for ; Tue, 29 Jan 2019 18:50:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D6502D742 for ; Tue, 29 Jan 2019 18:50:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B3E62D7FF; Tue, 29 Jan 2019 18:50:50 +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 C5D7F2D697 for ; Tue, 29 Jan 2019 18:50:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA9F18E0018; Tue, 29 Jan 2019 13:50:42 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E5E7D8E0015; Tue, 29 Jan 2019 13:50:42 -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 CD3D48E0018; Tue, 29 Jan 2019 13:50:42 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id 682CA8E0015 for ; Tue, 29 Jan 2019 13:50:42 -0500 (EST) Received: by mail-ed1-f71.google.com with SMTP id z10so8314183edz.15 for ; Tue, 29 Jan 2019 10:50:42 -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=WYxvlKVfAa6t/tNZfSF0UteJyG2GjojemqgH68lA8Pg=; b=SHqvSRV7pePnHY/ESayS6lbzy59eds5OrGCaVkDNtqnT8f7GM6Zcze/VGDGAZ7NHK7 xeGZHaNrj3roX6f95JIwwK6OEMJdwBDYddlV0v4sDCjke96xLDMMf5YgE1t/Z/bmrbRt jypKhvdfSUCiugr2Vu9j3KnVmpiV03+eq3GDyubIf2XgqF4LmFRqq877uDrHBDXvfNNE 3TuNhklvme8uMakY7+no0e+uqz80oHBHOyQOb/ROKcv+ziqUL5lmKBPFNvx7TEequC6S IyuitJ2dQXAPX2hu1Y5wLv8wpTcoiAttP3E8JQS3CVz3MRFjxNxUOIMmT8YL1I7yXZqV Di8g== 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: AJcUukffIE7vPINPyvbqVTL2hWvDPcVG0IuN3yTiTCeqRvDTLNMrl0SY c8UPi5yKQvkOrV8hzSKM2oRivRmbBPuT71PqxhMrWFESgSw9PAl5iglnSBYylmy1K58ZbF2Jnrj 5AoyZbuMRiQ3J61vT/1EY+y7+YyIWGqAkqL5Bdd8BsWV5gMxhD18am0/C6qzC1mnxKw== X-Received: by 2002:a50:8bb5:: with SMTP id m50mr26055827edm.211.1548787841916; Tue, 29 Jan 2019 10:50:41 -0800 (PST) X-Google-Smtp-Source: ALg8bN78iubkW52z6ZRzrhkUlJe+7fGrtPeVkemVmbIUf57+53oBsEfRBu83wDl8BZi+1KH1kpXc X-Received: by 2002:a50:8bb5:: with SMTP id m50mr26055777edm.211.1548787840950; Tue, 29 Jan 2019 10:50:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787840; cv=none; d=google.com; s=arc-20160816; b=u5V59hJBWUsGjdzwTMY7ZEuWrWYpj/Gdnf6/7RFml/vKRQuhJb9kVo0ZRLncU1BKF9 Xd131XWb/iNe+qMWmBJdFhhOGQWoVOg0hmdRwGKuvnoZFPxyJkhNEe/Z4xSwe9Z+KQjj IzEX/qBDFzKrh4D/71xaGISe1GR1BlzZqNNinoaWl+V/IP83KHvX5UBl4FKyEj6EoU0F YMFttkfNtRF1Y9t+ps8/lBgMa1RxqqB9MBK9U/HniQxbeeDJcnTxvv+Wv+DQiFdg2XsD b2X1GBLvPuPz5bK/iWiSnVAszdNTwdEE1DOi3zi1bp9RWlEmNftyNu5s3jH1EEi/ri7e Zz7Q== 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=WYxvlKVfAa6t/tNZfSF0UteJyG2GjojemqgH68lA8Pg=; b=oiHGgNNWGYvh7cSj90lgrMRZhj+oKKEHzXzsSyPNQvGK1BR840qUYI9gw8x8tT1eQR kExLHXYnMJUVN77LtKDx/XztEUYEc7CYZ542/G6HCrj/4iQ3Q28Dgolgb4/TE97u+6Cs ONHZsRx9IixjPgttj2XQZdUFHvdAwHQdeH0crLaTKqn+y/qP5fYVYgXwioaAAktHSdtR UbZkbdHh7lU3sqyUbp1ZsnPfem6PnuKALOBWS4PxrquluxfpCO89VVRLUOF62utvTl2q 9ejEvqK8Zdzq4zUgtxPItPtosux9iAMff0fun6seUG5D6CAjPuxdnBHN3fNu/0lwj8iw NGMw== 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 v4si3967773edy.314.2019.01.29.10.50.40 for ; Tue, 29 Jan 2019 10:50:40 -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 1B90315AB; Tue, 29 Jan 2019 10:50:40 -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 6E72A3F557; Tue, 29 Jan 2019 10:50:37 -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 , james.morse@arm.com Subject: [PATCH v8 21/26] ACPI / APEI: Use separate fixmap pages for arm64 NMI-like notifications Date: Tue, 29 Jan 2019 18:48:57 +0000 Message-Id: <20190129184902.102850-22-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 Now that ghes notification helpers provide the fixmap slots and take the lock themselves, multiple NMI-like notifications can be used on arm64. These should be named after their notification method as they can't all be called 'NMI'. x86's NOTIFY_NMI already is, change the SEA fixmap entry to be called FIX_APEI_GHES_SEA. Future patches can add support for FIX_APEI_GHES_SEI and FIX_APEI_GHES_SDEI_{NORMAL,CRITICAL}. Because all of ghes.c builds on both architectures, provide a constant for each fixmap entry that the architecture will never use. Signed-off-by: James Morse --- Changes since v7: * Removed v6's #ifdefs, these aren't needed now that SEA/NMI can't be turned off on their respective architectures. Changes since v6: * Added #ifdef definitions of each missing fixmap entry. Changes since v3: * idx/lock are now in a separate struct. * Add to the comment above ghes_fixmap_lock_irq so that it makes more sense in isolation. --- arch/arm64/include/asm/fixmap.h | 2 +- drivers/acpi/apei/ghes.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/fixmap.h b/arch/arm64/include/asm/fixmap.h index ec1e6d6fa14c..966dd4bb23f2 100644 --- a/arch/arm64/include/asm/fixmap.h +++ b/arch/arm64/include/asm/fixmap.h @@ -55,7 +55,7 @@ enum fixed_addresses { #ifdef CONFIG_ACPI_APEI_GHES /* Used for GHES mapping from assorted contexts */ FIX_APEI_GHES_IRQ, - FIX_APEI_GHES_NMI, + FIX_APEI_GHES_SEA, #endif /* CONFIG_ACPI_APEI_GHES */ #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 957c1559ebf5..e6f0d176b245 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -958,7 +958,7 @@ int ghes_notify_sea(void) int rv; raw_spin_lock(&ghes_notify_lock_sea); - rv = ghes_in_nmi_spool_from_list(&ghes_sea, FIX_APEI_GHES_NMI); + rv = ghes_in_nmi_spool_from_list(&ghes_sea, FIX_APEI_GHES_SEA); raw_spin_unlock(&ghes_notify_lock_sea); return rv; From patchwork Tue Jan 29 18:48:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786977 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 DCFC81399 for ; Tue, 29 Jan 2019 18:50:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE75B2D620 for ; Tue, 29 Jan 2019 18:50:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC9322D757; Tue, 29 Jan 2019 18:50:52 +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 67EE62D620 for ; Tue, 29 Jan 2019 18:50:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D21A68E0019; Tue, 29 Jan 2019 13:50:45 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CD3A28E0015; Tue, 29 Jan 2019 13:50:45 -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 B72E78E0019; Tue, 29 Jan 2019 13:50:45 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) by kanga.kvack.org (Postfix) with ESMTP id 5AC4A8E0015 for ; Tue, 29 Jan 2019 13:50:45 -0500 (EST) Received: by mail-ed1-f71.google.com with SMTP id e29so8407931ede.19 for ; Tue, 29 Jan 2019 10:50:45 -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=6iae2T6BHQ6iX37iUpuGhQgLV/NJrmVS4ISG/YiCITg=; b=hsf5bfuBvUqfDHudQavnAEnAkg+tOOij+NcG+0wXUQLniB30Cx54MytJRQpBgJiFls 7DoDOZFMNjbjb9mObv+LBEPVpQcQEnHHBBpHN9pu18oRxcLujQ7C6yoNzWFrb9+pFr0z wrQmq29KuV7b87kKBoRQE1rJjVKwxgCzpet7bryffSrF37ms9vh3RO+joKvcg2JGAvRt +PInc6q5dWc6Z2VFhfiJt8nRXvLlFRnvoHBoiCSrRg6zgfoxF58kXHcJKwDh9nxyYF5T TsOjJwBG3YM4Mxtl8Qq81DUd99XkipuszvZ4lmu/4RXc03UkmCYgZTr7YnKJX696/YCv mhGw== 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: AJcUukdj5JsRJ0qaf7UxinjcoNRL6frLZR51IQePOIsPYL0mSSVe/EH7 Xicecujfnag2frl/Jjara0v+OE8Drm6P2LkGxP7g1X8ZUQr+odTMNwMq5yQyywj4V84zNPTJDZq rhKhQgoOhNP2VRSde13u3Yxhxdlm7PDH70mSgf/A4/JC42OKEL94wQgbeZq5Zj2QP0g== X-Received: by 2002:a17:906:7f01:: with SMTP id d1mr23564131ejr.244.1548787844845; Tue, 29 Jan 2019 10:50:44 -0800 (PST) X-Google-Smtp-Source: ALg8bN6J4uY2/pLp3HOYLpLuRNkCA1Qm/btC4gSyBnCQx+vgTH+WG/w/KECmDPk7ywoYcf8EBrdF X-Received: by 2002:a17:906:7f01:: with SMTP id d1mr23564078ejr.244.1548787843858; Tue, 29 Jan 2019 10:50:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787843; cv=none; d=google.com; s=arc-20160816; b=Sh35786+oTomw82op0Bo6fx9QZ/EJm97jZYDu8l32k/5ucMI+kutLBW7ROwc5EmL1S qHqWRh+kdSCtoX/7rs91CdebEUa/liEKkJKqfQ60sJnoD6Kqb828Fcpf17vie5cVQ4MJ eFxFPpdJDVvh/v7knmJiUn7GFSkH6AC6bPGmch2g/YJAw/OoKQFMsGXFKWMOPTUNma0T XXsB8S8VFDr6PAIUCH1K52PwEjtu5AxdAOevlobmmlvSD/0q0kBWgRFACfiz43EyDzKs RSfcf5sEZwe08OmeablUyKvitemnCWRxCwu8R8+wqlXPmn6R0NvkKEhOBAlk55mNk6v/ zJ5A== 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=6iae2T6BHQ6iX37iUpuGhQgLV/NJrmVS4ISG/YiCITg=; b=YHk3UYhav3MdARLfkDtt/+CG8vFi9WFBJS8hCMRS7vtg58HnsA6zmxvMPBif7yQgc6 /kxe5swEGQFVhDb+eyF9zuoqUxIy7gcb9OSWotR279Bb6JZAER+LRv08pmr4zg3dGOqq nNRzI/U3Kfscs03vBylByZz/qCR5nKFm4zcKsmSDFVRtMHbmOIK3fWod+ydaQjeL2Snc 5spmd8DbZqg88Y4h6j7z4LmjsA9Yo3UAatSwnPhoAr39+zEYA3oEa1nUlIYJlS+0K9DX pW4fka2WF+vq87kKFnZhuKUfdfu8V+Iyv2Bgu0Spoef+bTTFkP8n+YBx/BOru1pxPiVp PBqQ== 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 l22si2236282edj.93.2019.01.29.10.50.43 for ; Tue, 29 Jan 2019 10:50:43 -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 078BAA78; Tue, 29 Jan 2019 10:50:43 -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 5A5903F557; Tue, 29 Jan 2019 10:50:40 -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 , james.morse@arm.com Subject: [PATCH v8 22/26] mm/memory-failure: Add memory_failure_queue_kick() Date: Tue, 29 Jan 2019 18:48:58 +0000 Message-Id: <20190129184902.102850-23-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 The GHES code calls memory_failure_queue() from IRQ context to schedule work on the current CPU so that memory_failure() can sleep. For synchronous memory errors the arch code needs to know any signals that memory_failure() will trigger are pending before it returns to user-space, possibly when exiting from the IRQ. Add a helper to kick the memory failure queue, to ensure the scheduled work has happened. This has to be called from process context, so may have been migrated from the original cpu. Pass the cpu the work was queued on. Change memory_failure_work_func() to permit being called on the 'wrong' cpu. Signed-off-by: James Morse --- include/linux/mm.h | 1 + mm/memory-failure.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 80bb6408fe73..b33bededc69d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2743,6 +2743,7 @@ enum mf_flags { }; extern int memory_failure(unsigned long pfn, int flags); extern void memory_failure_queue(unsigned long pfn, int flags); +extern void memory_failure_queue_kick(int cpu); extern int unpoison_memory(unsigned long pfn); extern int get_hwpoison_page(struct page *page); #define put_hwpoison_page(page) put_page(page) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 6379fff1a5ff..9b4705a53fed 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1494,7 +1494,7 @@ static void memory_failure_work_func(struct work_struct *work) unsigned long proc_flags; int gotten; - mf_cpu = this_cpu_ptr(&memory_failure_cpu); + mf_cpu = container_of(work, struct memory_failure_cpu, work); for (;;) { spin_lock_irqsave(&mf_cpu->lock, proc_flags); gotten = kfifo_get(&mf_cpu->fifo, &entry); @@ -1508,6 +1508,19 @@ static void memory_failure_work_func(struct work_struct *work) } } +/* + * Process memory_failure work queued on the specified CPU. + * Used to avoid return-to-userspace racing with the memory_failure workqueue. + */ +void memory_failure_queue_kick(int cpu) +{ + struct memory_failure_cpu *mf_cpu; + + mf_cpu = &per_cpu(memory_failure_cpu, cpu); + cancel_work_sync(&mf_cpu->work); + memory_failure_work_func(&mf_cpu->work); +} + static int __init memory_failure_init(void) { struct memory_failure_cpu *mf_cpu; From patchwork Tue Jan 29 18:48:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786981 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 3F44D13B4 for ; Tue, 29 Jan 2019 18:50:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 306542D70B for ; Tue, 29 Jan 2019 18:50:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E4A32D7E4; Tue, 29 Jan 2019 18:50:56 +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 819192D70B for ; Tue, 29 Jan 2019 18:50:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8405B8E0006; Tue, 29 Jan 2019 13:50:49 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7C8A48E0015; Tue, 29 Jan 2019 13:50:49 -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 6DEC88E0006; Tue, 29 Jan 2019 13:50:49 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id 1017C8E0015 for ; Tue, 29 Jan 2019 13:50:49 -0500 (EST) Received: by mail-ed1-f69.google.com with SMTP id b3so8352877edi.0 for ; Tue, 29 Jan 2019 10:50:49 -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=cGyWsH8E5iMe5/JM/wndPOtcKX97fv1WfR21Y9tGLcE=; b=D/E2m/BmxoK90R+YHBqIEI9y50zBb1XykUVbANQrwvOdkeU1PQykmQhXHzoztW9bfk DuXCfI9PGtpzBLqVQL7/vFJRDJOWlIiCSA7tzVISWHzoOiGklX4g2Q9Ggny3uCBPx05r 8LggyhFKOpH2Wrq5li1fn/6u+xxvTzqqeW++hFWY6pTp/vqwGz7qhCxg/vVQfCOssF3B 1rmL/wr24ziw55b9QsweRVDc1hjLfJsGtUnpZogBGh/g4Sxg0rOFmjS7Nzns0qmzSTOF 3m9nyO0llGdnUnUuHKxyeC7UY3moKhqJ0YdZM1G6LZexgtHXEls14CcXrrJJiWcGokUL ruBg== 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: AJcUukcIAYsdGM6C2a88GywGWuNvcdq3b4t9XC+Aa26meTAtURYiMngl GcQeNyTowi/N8vLxHQmkMMpia3p2H2vo/z7/bEdCTzY2WVSfKbgJvXIn7FUhM6AccTdhTIcdWw2 adnpXMzCT1iC1+gO0lFoI/VKDTl3hen96Gczr2DwoAHVFkVYv+DwqRF5YSqB2rYOSDg== X-Received: by 2002:a50:d797:: with SMTP id w23mr27424729edi.19.1548787848526; Tue, 29 Jan 2019 10:50:48 -0800 (PST) X-Google-Smtp-Source: ALg8bN4rrLs8vdEs+VUvreeQeYqoFsD73eA6iERsY68nzHu0bA4fA3tb0fpOiIsR/FY927pDTNZ9 X-Received: by 2002:a50:d797:: with SMTP id w23mr27424644edi.19.1548787846920; Tue, 29 Jan 2019 10:50:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787846; cv=none; d=google.com; s=arc-20160816; b=DawYX0yIBME5nopyY0S+EZ1JEYgHGhE1qPhm1vs6n8oyVItacqoM0uREc24mFS27FU T2oaGpCqoTTwzSWOuABixCZMjXAjzpzz+CjoNSDRjDHt5aI1gEDOWVWZFr82wrLmyOms 7pDIxtY0SQdYxSrPsJPjTtkdlWNg6c1HK8BhyuL8TWTHj3oGghDQppZr3f7IbojL1qCk cAcP2Ysd9QcEOBN4fGntrpMAHkFbBDK2m/D19DdJ/lJen0/w5kGxsc8CH/FtuCCkXW26 N7JbAb5PmLn//ZyV5ABi+W13/G+eucr5Me5SUXCK1yBliQ9sBhFENiL+gQcjFTYFOa8r d5vA== 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=cGyWsH8E5iMe5/JM/wndPOtcKX97fv1WfR21Y9tGLcE=; b=d59fO3+N7M3Bgw0BLGJ6/4j0ke3TlupMUVeJ8GAeRrfCDQ8XYNFJxM6h4UbNuw5nxE cEjMeBEk87XwKcZ20KnKnaSfZb6eHFCRLK8Gl++o/SNJhQ2nI6VClJ32nPE/ZWQ9Ti6B DICUABfynCNcrfPD5xOiAAJFfRlSK29PSqFfm63OVUjHLKsrMCEk3dDzVdHR9arkZ1S6 bNClMNke2TxQs5+f5RbrMc36J8oF2Ita1ETdeKiTTvc+kseWgHhIjJbxNrOr1c78wR8f 0AnkBb7QnKib36HyzeCiLsohKK+fmgTv2tGw7rcG/F2b9iWVvCYewTVAa7sSJDmx7Vj/ x+BQ== 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 g41si7684527eda.198.2019.01.29.10.50.46 for ; Tue, 29 Jan 2019 10:50:46 -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 E7D8B15AB; Tue, 29 Jan 2019 10:50:45 -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 46AB93F557; Tue, 29 Jan 2019 10:50:43 -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 , james.morse@arm.com Subject: [PATCH v8 23/26] ACPI / APEI: Kick the memory_failure() queue for synchronous errors Date: Tue, 29 Jan 2019 18:48:59 +0000 Message-Id: <20190129184902.102850-24-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 memory_failure() offlines or repairs pages of memory that have been discovered to be corrupt. These may be detected by an external component, (e.g. the memory controller), and notified via an IRQ. In this case the work is queued as not all of memory_failure()s work can happen in IRQ context. If the error was detected as a result of user-space accessing a corrupt memory location the CPU may take an abort instead. On arm64 this is a 'synchronous external abort', and on a firmware first system it is replayed using NOTIFY_SEA. This notification has NMI like properties, (it can interrupt IRQ-masked code), so the memory_failure() work is queued. If we return to user-space before the queued memory_failure() work is processed, we will take the fault again. This loop may cause platform firmware to exceed some threshold and reboot when Linux could have recovered from this error. For NMIlike notifications keep track of whether memory_failure() work was queued, and make task_work pending to flush out the queue. To save memory allocations, the task_work is allocated as part of the ghes_estatus_node, and free()ing it back to the pool is deferred. Signed-off-by: James Morse --- current->mm == &init_mm ? I couldn't find a helper for this. The intent is not to set TIF flags on kernel threads. What happens if a kernel-thread takes on of these? Its just one of the many not-handled-very-well cases we have already, as memory_failure() puts it: "try to be lucky". I assume that if NOTIFY_NMI is coming from SMM it must suffer from this problem too. Changes since v7: * Don't allocate memory, stuff it in estatus_node. This means passing back a 'queued' flag to ghes_proc_in_irq() which holds the estatus_node. --- drivers/acpi/apei/ghes.c | 68 +++++++++++++++++++++++++++++++++------- include/acpi/ghes.h | 3 ++ 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index e6f0d176b245..dfa8f155f964 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -399,23 +400,46 @@ static void ghes_clear_estatus(struct ghes *ghes, ghes_ack_error(ghes->generic_v2); } -static void ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata, int sev) +/* + * Called as task_work before returning to user-space. + * Ensure any queued work has been done before we return to the context that + * triggered the notification. + */ +static void ghes_kick_task_work(struct callback_head *head) +{ + struct acpi_hest_generic_status *estatus; + struct ghes_estatus_node *estatus_node; + u32 node_len; + + estatus_node = container_of(head, struct ghes_estatus_node, task_work); + memory_failure_queue_kick(estatus_node->task_work_cpu); + + estatus = GHES_ESTATUS_FROM_NODE(estatus_node); + node_len = GHES_ESTATUS_NODE_LEN(cper_estatus_len(estatus)); + gen_pool_free(ghes_estatus_pool, (unsigned long)estatus_node, node_len); +} + +static bool ghes_handle_memory_failure(struct ghes *ghes, + struct acpi_hest_generic_data *gdata, + int sev) { -#ifdef CONFIG_ACPI_APEI_MEMORY_FAILURE unsigned long pfn; int flags = -1; int sec_sev = ghes_severity(gdata->error_severity); struct cper_sec_mem_err *mem_err = acpi_hest_get_payload(gdata); + if (!IS_ENABLED(CONFIG_ACPI_APEI_MEMORY_FAILURE)) + return false; + if (!(mem_err->validation_bits & CPER_MEM_VALID_PA)) - return; + return false; pfn = mem_err->physical_addr >> PAGE_SHIFT; if (!pfn_valid(pfn)) { pr_warn_ratelimited(FW_WARN GHES_PFX "Invalid address in generic error data: %#llx\n", mem_err->physical_addr); - return; + return false; } /* iff following two events can be handled properly by now */ @@ -425,9 +449,12 @@ static void ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata, int if (sev == GHES_SEV_RECOVERABLE && sec_sev == GHES_SEV_RECOVERABLE) flags = 0; - if (flags != -1) + if (flags != -1) { memory_failure_queue(pfn, flags); -#endif + return true; + } + + return false; } /* @@ -475,11 +502,12 @@ static void ghes_handle_aer(struct acpi_hest_generic_data *gdata) #endif } -static void ghes_do_proc(struct ghes *ghes, +static bool ghes_do_proc(struct ghes *ghes, const struct acpi_hest_generic_status *estatus) { int sev, sec_sev; struct acpi_hest_generic_data *gdata; + bool work_queued = false; guid_t *sec_type; guid_t *fru_id = &NULL_UUID_LE; char *fru_text = ""; @@ -500,7 +528,8 @@ static void ghes_do_proc(struct ghes *ghes, ghes_edac_report_mem_error(sev, mem_err); arch_apei_report_mem_error(sev, mem_err); - ghes_handle_memory_failure(gdata, sev); + if (ghes_handle_memory_failure(ghes, gdata, sev)) + work_queued = true; } else if (guid_equal(sec_type, &CPER_SEC_PCIE)) { ghes_handle_aer(gdata); @@ -517,6 +546,8 @@ static void ghes_do_proc(struct ghes *ghes, gdata->error_data_length); } } + + return work_queued; } static void __ghes_print_estatus(const char *pfx, @@ -812,7 +843,9 @@ static void ghes_proc_in_irq(struct irq_work *irq_work) struct ghes_estatus_node *estatus_node; struct acpi_hest_generic *generic; struct acpi_hest_generic_status *estatus; + bool task_work_pending; u32 len, node_len; + int ret; llnode = llist_del_all(&ghes_estatus_llist); /* @@ -827,14 +860,26 @@ static void ghes_proc_in_irq(struct irq_work *irq_work) estatus = GHES_ESTATUS_FROM_NODE(estatus_node); len = cper_estatus_len(estatus); node_len = GHES_ESTATUS_NODE_LEN(len); - ghes_do_proc(estatus_node->ghes, estatus); + task_work_pending = ghes_do_proc(estatus_node->ghes, estatus); if (!ghes_estatus_cached(estatus)) { generic = estatus_node->generic; if (ghes_print_estatus(NULL, generic, estatus)) ghes_estatus_cache_add(generic, estatus); } - gen_pool_free(ghes_estatus_pool, (unsigned long)estatus_node, - node_len); + + if (task_work_pending && current->mm != &init_mm) { + estatus_node->task_work.func = ghes_kick_task_work; + estatus_node->task_work_cpu = smp_processor_id(); + ret = task_work_add(current, &estatus_node->task_work, + true); + if (ret) + estatus_node->task_work.func = NULL; + } + + if (!estatus_node->task_work.func) + gen_pool_free(ghes_estatus_pool, + (unsigned long)estatus_node, node_len); + llnode = next; } } @@ -894,6 +939,7 @@ static int ghes_in_nmi_queue_one_entry(struct ghes *ghes, estatus_node->ghes = ghes; estatus_node->generic = ghes->generic; + estatus_node->task_work.func = NULL; estatus = GHES_ESTATUS_FROM_NODE(estatus_node); if (__ghes_read_estatus(estatus, buf_paddr, fixmap_idx, len)) { diff --git a/include/acpi/ghes.h b/include/acpi/ghes.h index e3f1cddb4ac8..517a5231cc1b 100644 --- a/include/acpi/ghes.h +++ b/include/acpi/ghes.h @@ -33,6 +33,9 @@ struct ghes_estatus_node { struct llist_node llnode; struct acpi_hest_generic *generic; struct ghes *ghes; + + int task_work_cpu; + struct callback_head task_work; }; struct ghes_estatus_cache { From patchwork Tue Jan 29 18:49:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786985 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 04D5913B4 for ; Tue, 29 Jan 2019 18:50:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA5272D694 for ; Tue, 29 Jan 2019 18:50:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E894C2D7EC; Tue, 29 Jan 2019 18:50:58 +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 756E42D7FF for ; Tue, 29 Jan 2019 18:50:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EF7ED8E0007; Tue, 29 Jan 2019 13:50:51 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id DE1E48E0015; Tue, 29 Jan 2019 13:50:51 -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 CF86F8E0007; Tue, 29 Jan 2019 13:50:51 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id 7620A8E0015 for ; Tue, 29 Jan 2019 13:50:51 -0500 (EST) Received: by mail-ed1-f70.google.com with SMTP id x15so8358993edd.2 for ; Tue, 29 Jan 2019 10:50:51 -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=WyX6PHLBF1pqpUWRcbcBKvnw8cl/d1twUs4/cn2oYq0=; b=Q0cJ68zVFZc5FIEdSvC/eFOzO1gCdRyFyq/sqLa3BY6NQlZ+EW9vObpSlNmVtJ6x0L 0IohyGmy8f81IC08nf7QsD0eVksAmZmo57Pwvfciihr2ASNXYnht4W2LsEkEozKPeUbF xicPLWKQeIIoDWgyErsL8mYmiANZHAUiXZKU14z7F/JjPbEYNbSfa9Qsx20gCRm/R5br mrDpNdw7Wvk7/G/eQkLy2BtXhXUSti+yBs/iwXnZfcz6L06jTSHI0Z6/lcde41lS6MXT o7mG4WNtAu7G0GelN+XmqAoN+OIBFv1JeZvY1qDrJNS/zpPxqqbNLHWB/RH8wPK9r62K rVvQ== 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: AJcUukfhYCQ6G6qvnDINMFsSdEvXHKypYFteespaSGyDATTJKNq24v3L tIzRFdlkuOBj9a4LyE0tWU6ejgvWLei3CGy3KDH7bV2IURSAThmtG2q9ijE0Ma2TcD1vtLj1yvg me5xurqKQxW3ghiv8J1vX3PK6KW0g9ES8Wa9KdxBT+yHUDBuRPdrIUV1nDDNt3eTdWg== X-Received: by 2002:a50:b1af:: with SMTP id m44mr26266492edd.47.1548787850949; Tue, 29 Jan 2019 10:50:50 -0800 (PST) X-Google-Smtp-Source: ALg8bN46GU/dcpHLMCmO+QPwYLfcJUv7gDmnQuxZmito0SsRQ6M5NR1PdsX8x2r3mf4+77bz0Ib2 X-Received: by 2002:a50:b1af:: with SMTP id m44mr26266435edd.47.1548787849916; Tue, 29 Jan 2019 10:50:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787849; cv=none; d=google.com; s=arc-20160816; b=RZ9O9Ogt8S7HPs6yFShkyKu9jMROiJrWqjM7IYpafq+/aD/+7SZZgYTwSqc8FgcOFR I5weUreNn8zf29HF+pkBipikJpOAIQPRTht/toG1ZjDDeCA1VjljlE/VrsjpqqbU2aTs ruLBBNMozE03IVOIxyixA+SS+vjgiFaLKrfeRkxPLdm06KHCp5VX2+fCIeZ7lKQqWfVd YmoLP7AyQ13L+N+j2fHZxg4QtyOY4j0E24WCBV0xy8SNPdgabbnARNwBNXKJwKE88N6I 6QK7Z9Hb/WlyaMsx7PW/2xUhBr+oq/RTaeiJjFP5aXHqYPQssj/Uqt+mAI2SGIRxL85E 2c9g== 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=WyX6PHLBF1pqpUWRcbcBKvnw8cl/d1twUs4/cn2oYq0=; b=r+zkVu/7rQYMNqMJsVZNQXwFtb+gADBSu2Nf001+37pqJKej4qhAOT7SNWl8ajGJYd HGcHY/9Jn5qjRj8hGttyLN8cGsocyY88WMyR457Kl/36hhM9n8HerhLxqhjZcaHMZ9W4 MW1C0c35GdFWzNQjhgbFdBgKItXDzMoWNI4DgPMPzWPYXbrJykVUzQeTmocliTudYm1E TR6+B8Ekkr3HFFWKd58zWyIEQZL+VfCLX+u56lfcxI8m0O71oDUWleBunhHIfpxDqgQn f9UPu3n+TpoxxL7XUuBxRm251ivDsRXa6ozaUT9/949XR6Jw/r9ndBZgGLZfep67qhvU 3ERg== 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 j30si2157551edc.365.2019.01.29.10.50.49 for ; Tue, 29 Jan 2019 10:50:49 -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 D427E1650; Tue, 29 Jan 2019 10:50:48 -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 327F33F557; Tue, 29 Jan 2019 10:50:46 -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 , james.morse@arm.com Subject: [PATCH v8 24/26] arm64: acpi: Make apei_claim_sea() synchronise with APEI's irq work Date: Tue, 29 Jan 2019 18:49:00 +0000 Message-Id: <20190129184902.102850-25-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 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 Reviewed-by: Punit Agrawal Tested-by: Tyler Baicar Acked-by: Catalin Marinas CC: Xie XiuQi CC: gengdongjiu Reviewed-by: Julien Thierry --- Changes since v7: * Added Catalin's ack, then: * Added __irq_enter()/exit() calls so if we interrupted preemptible code, the preempt count matches what other irq-work expects. * Changed the 'if (!arch_irqs_disabled_flags(interrupted_flags))' test to be safe before/after Julien's PMR series. Changes since v6: * Added pr_warn() for the EINPROGRESS case so panic-tracebacks show 'APEI was here'. * Tinkered with the commit message Changes since v2: * Removed IS_ENABLED() check, done by the caller unless we have a dummy definition. --- arch/arm64/kernel/acpi.c | 23 +++++++++++++++++++++++ arch/arm64/mm/fault.c | 9 ++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c index 803f0494dd3e..8288ae0c8f3b 100644 --- a/arch/arm64/kernel/acpi.c +++ b/arch/arm64/kernel/acpi.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -268,12 +269,17 @@ 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)) return err; current_flags = arch_local_save_flags(); + return_to_irqs_enabled = !irqs_disabled_flags(current_flags); + + if (regs) + return_to_irqs_enabled = interrupts_enabled(regs); /* * SEA can interrupt SError, mask it and describe this as an NMI so @@ -283,6 +289,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("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 e1c84c2e1cab..1611714f8333 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -642,11 +642,10 @@ 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 (apei_claim_sea(regs) == 0) { + /* APEI claimed this as a firmware-first notification */ + return 0; + } if (esr & ESR_ELx_FnV) siaddr = NULL; From patchwork Tue Jan 29 18:49:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786989 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 E35D21399 for ; Tue, 29 Jan 2019 18:51:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4E932D694 for ; Tue, 29 Jan 2019 18:51:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D2D862D76D; Tue, 29 Jan 2019 18:51:01 +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 45D752D694 for ; Tue, 29 Jan 2019 18:51:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE7D28E001A; Tue, 29 Jan 2019 13:50:54 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B9A348E0015; Tue, 29 Jan 2019 13:50:54 -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 A88A18E001A; Tue, 29 Jan 2019 13:50:54 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by kanga.kvack.org (Postfix) with ESMTP id 4B7928E0015 for ; Tue, 29 Jan 2019 13:50:54 -0500 (EST) Received: by mail-ed1-f70.google.com with SMTP id y35so8313977edb.5 for ; Tue, 29 Jan 2019 10:50:54 -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=j7b/Tpctf8lj076ai58Sj9p0zuBf66lnA97pNz2XZng=; b=Nb9RwbL2DBblkC6Z/UOkohft66oh/TKxyH0EzbFWvj+faLKVZVX228fVg1vuapzjx3 Nw1fQWEFpjXIalEVyf4FVqS4fywAj6ULifwxXLEJlKepm2I1Rnn64lPPPegDZimW/KBz tVto/MjA+vH0JOGZ/liOWne+Vn/6agHPcUnisNA4yB2rpH9oDbHrP/S3O0UQTxX7EwYd kf7ZlZtJaqooyTwBQOt15PYk/v/Zpx9XJDk49+Mc6Sre1dKLXbs2RYVSsgFMt8F0zTwg QkOHkHcqiY07p0BEn2aRXhOc8vZJ1gPr9iL96kSNLPsM1LmPST8Rj8fsTSSmkLuIeBjA hQOA== 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: AJcUukdB1NYY2DXe6gz+JggkU9B+AuB1mhUr9rfvblebxPu3+OQSHxld Swt3aWv/QdXW8H96filhAn35HNrx9pFu6GXRsIf3pmBcJHrcpCGaqr5sUppR/z/jU/N3rF8A+dc 0HURkuK7xAt5TYLeKuebkkMAo5spHNTFygxK1SH0QG+VvjIYdK9M4poe6OZBCcAPuwg== X-Received: by 2002:a50:ad0b:: with SMTP id y11mr25790478edc.113.1548787853769; Tue, 29 Jan 2019 10:50:53 -0800 (PST) X-Google-Smtp-Source: ALg8bN7g3BYKVNH+JVXDooe0lu2HcJwucTDG8MbXZuIX+a+07aHRG0R3gWnA4lMTEz3M5vvrnX9h X-Received: by 2002:a50:ad0b:: with SMTP id y11mr25790430edc.113.1548787852773; Tue, 29 Jan 2019 10:50:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787852; cv=none; d=google.com; s=arc-20160816; b=nHtI68q4AOxd68YK2EkomkmCr5sY1xra25xIzDctrv++GcJqJNJWZohmUKm2AMHeXM jVox3iaUEWpOVrNmk02SEWuoP0PDCQoKAd8m7vR6Nj5ZhTI2U3mWPA5B0/5NUAec+YTw l2WIcspcdDrlphszG8Qjk3rjnJUxsu6jmugvlyDnaQw2FpCJKzzjfi3CXdyDmzeK7CHo 8aDPn086NJrq4WmyW5Gh4EHZ36YUisZYD4pBGaRsGi+5zFgXD/mPWpvFr572Z4ZSx4Bu NWO28ez1k2zdXkDq6jG5A1duJxCQeveBU2pcxqcq8NoM9wHnIHpe131fjxX1zbZuu7Fk 1cIg== 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=j7b/Tpctf8lj076ai58Sj9p0zuBf66lnA97pNz2XZng=; b=HFdjsnNY6KImGvTrUOL9ZC9lur+2EzXHvMYliWAr/1OmrPgkrX2jMDRICo3YOy+FAA rmrWrmASEYL3VCNL+IsNKtNDNzPT4h67+4zjOwFsYFoOn2CBd6GvOc1vy4q/VN7hTfYY igF9Wp/EegTy7jdLLtjKUmVeR5FBXFqLn7NQVgB6IkVcQgTDiZKBQBD1F6wIJxRu5Wc3 X8QdRjcGQeM0sDTYFBfnx8ZE6KsvdYYTM75qIru+mTTmcbJCu82Z5g3LBkFYS8orP4DA fyFE9fkx6Xy/Fqf49CqV5l267phN8fdgd6Cf+qFS8Vjycal22o/Ml53nMwZD+2norS15 Cx/A== 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 (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id mj22si71886ejb.56.2019.01.29.10.50.52 for ; Tue, 29 Jan 2019 10:50:52 -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 BFB9815AB; Tue, 29 Jan 2019 10:50:51 -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 1EBD83F557; Tue, 29 Jan 2019 10:50:48 -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 , james.morse@arm.com Subject: [PATCH v8 25/26] firmware: arm_sdei: Add ACPI GHES registration helper Date: Tue, 29 Jan 2019 18:49:01 +0000 Message-Id: <20190129184902.102850-26-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 APEI's Generic Hardware Error Source structures do not describe whether the SDEI event is shared or private, as this information is discoverable via the API. GHES needs to know whether an event is normal or critical to avoid sharing locks or fixmap entries, but GHES shouldn't have to know about the SDEI API. Add a helper to register the GHES using the appropriate normal or critical callback. Signed-off-by: James Morse Acked-by: Catalin Marinas --- Changes since v4: * Moved normal/critical callbacks into the helper, as APEI needs to know. * Tinkered with the commit message. * Dropped Punit's Reviewed-by. Changes since v3: * Removed acpi_disabled() checks that aren't necessary after v2s #ifdef change. Changes since v2: * Added header file, thanks kbuild-robot! * changed ifdef to the GHES version to match the fixmap definition Changes since v1: * ghes->fixmap_idx variable rename --- arch/arm64/include/asm/fixmap.h | 4 ++ drivers/firmware/arm_sdei.c | 68 +++++++++++++++++++++++++++++++++ include/linux/arm_sdei.h | 6 +++ 3 files changed, 78 insertions(+) diff --git a/arch/arm64/include/asm/fixmap.h b/arch/arm64/include/asm/fixmap.h index 966dd4bb23f2..f987b8a8f325 100644 --- a/arch/arm64/include/asm/fixmap.h +++ b/arch/arm64/include/asm/fixmap.h @@ -56,6 +56,10 @@ enum fixed_addresses { /* Used for GHES mapping from assorted contexts */ FIX_APEI_GHES_IRQ, FIX_APEI_GHES_SEA, +#ifdef CONFIG_ARM_SDE_INTERFACE + FIX_APEI_GHES_SDEI_NORMAL, + FIX_APEI_GHES_SDEI_CRITICAL, +#endif #endif /* CONFIG_ACPI_APEI_GHES */ #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 diff --git a/drivers/firmware/arm_sdei.c b/drivers/firmware/arm_sdei.c index c64c7da73829..e6376f985ef7 100644 --- a/drivers/firmware/arm_sdei.c +++ b/drivers/firmware/arm_sdei.c @@ -2,6 +2,7 @@ // Copyright (C) 2017 Arm Ltd. #define pr_fmt(fmt) "sdei: " fmt +#include #include #include #include @@ -887,6 +888,73 @@ static void sdei_smccc_hvc(unsigned long function_id, arm_smccc_hvc(function_id, arg0, arg1, arg2, arg3, arg4, 0, 0, res); } +int sdei_register_ghes(struct ghes *ghes, sdei_event_callback *normal_cb, + sdei_event_callback *critical_cb) +{ + int err; + u64 result; + u32 event_num; + sdei_event_callback *cb; + + if (!IS_ENABLED(CONFIG_ACPI_APEI_GHES)) + return -EOPNOTSUPP; + + event_num = ghes->generic->notify.vector; + if (event_num == 0) { + /* + * Event 0 is reserved by the specification for + * SDEI_EVENT_SIGNAL. + */ + return -EINVAL; + } + + err = sdei_api_event_get_info(event_num, SDEI_EVENT_INFO_EV_PRIORITY, + &result); + if (err) + return err; + + if (result == SDEI_EVENT_PRIORITY_CRITICAL) + cb = critical_cb; + else + cb = normal_cb; + + err = sdei_event_register(event_num, cb, ghes); + if (!err) + err = sdei_event_enable(event_num); + + return err; +} + +int sdei_unregister_ghes(struct ghes *ghes) +{ + int i; + int err; + u32 event_num = ghes->generic->notify.vector; + + might_sleep(); + + if (!IS_ENABLED(CONFIG_ACPI_APEI_GHES)) + return -EOPNOTSUPP; + + /* + * The event may be running on another CPU. Disable it + * to stop new events, then try to unregister a few times. + */ + err = sdei_event_disable(event_num); + if (err) + return err; + + for (i = 0; i < 3; i++) { + err = sdei_event_unregister(event_num); + if (err != -EINPROGRESS) + break; + + schedule(); + } + + return err; +} + static int sdei_get_conduit(struct platform_device *pdev) { const char *method; diff --git a/include/linux/arm_sdei.h b/include/linux/arm_sdei.h index 942afbd544b7..393899192906 100644 --- a/include/linux/arm_sdei.h +++ b/include/linux/arm_sdei.h @@ -11,6 +11,7 @@ enum sdei_conduit_types { CONDUIT_HVC, }; +#include #include /* Arch code should override this to set the entry point from firmware... */ @@ -39,6 +40,11 @@ int sdei_event_unregister(u32 event_num); int sdei_event_enable(u32 event_num); int sdei_event_disable(u32 event_num); +/* GHES register/unregister helpers */ +int sdei_register_ghes(struct ghes *ghes, sdei_event_callback *normal_cb, + sdei_event_callback *critical_cb); +int sdei_unregister_ghes(struct ghes *ghes); + #ifdef CONFIG_ARM_SDE_INTERFACE /* For use by arch code when CPU hotplug notifiers are not appropriate. */ int sdei_mask_local_cpu(void); From patchwork Tue Jan 29 18:49:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10786991 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 B7A1B13B4 for ; Tue, 29 Jan 2019 18:51:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8B822D801 for ; Tue, 29 Jan 2019 18:51:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A676028742; Tue, 29 Jan 2019 18:51:04 +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 1BEB42D801 for ; Tue, 29 Jan 2019 18:51:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AFE6B8E001B; Tue, 29 Jan 2019 13:50:57 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AAE0A8E0015; Tue, 29 Jan 2019 13:50:57 -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 9A11B8E001B; Tue, 29 Jan 2019 13:50:57 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) by kanga.kvack.org (Postfix) with ESMTP id 3C3618E0015 for ; Tue, 29 Jan 2019 13:50:57 -0500 (EST) Received: by mail-ed1-f69.google.com with SMTP id e29so8408095ede.19 for ; Tue, 29 Jan 2019 10:50:57 -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=Z0mOO2ifhiBIvsjdnVsmHqOe6F85CHxFTHq9HFgxSC0=; b=BFIXn3JyJOB4BbhgJAZp1ZWhQrs5f3j7S5tD7CRBkvMm16rYzaNYjS93iKB5loerel XWH2qoIDw94RWDd2Sh0oag3XM7F7W3d2KMSjBskAWlLnFZfsQdrU0etq7XWrR5NKXbna uxWPpvtuHA+lZIni2dx8EaRjsfn72hsg1cGMf+WpNG+x3+qTZMjCH8I6J1+yx1B1maq7 WmjAXeC8W6VlNhenm1XHK7W+QAg55MmCue7OxJjqZkT8D/VxsF1PRfU93qfLJ6hZcUSB oge3Puv9YesdM19L/pb8NgfVExIPevi/3lxXePnmZul2czHlHrlVPzxOEuE8Y2tkB5VO puhA== 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: AJcUukdGtKd5es2rNNRSE2VOaMcPFDPrKYRzFae9XFkJxV/FrpeELIMn LaVuytPlzDdDTZT8hbZXQ+GNPhkNAXnAMKv5vDIZuxTdUqXVkI/yMHLsaOVNmWElg00kK6Armpz NKgZzEkFVuY0cBRGVnorNJ9dnYZMgle8S7LxLRbulDOK8MK1FxeUKvEoTgCaNzd81BQ== X-Received: by 2002:aa7:d1d7:: with SMTP id g23mr22395413edp.217.1548787856699; Tue, 29 Jan 2019 10:50:56 -0800 (PST) X-Google-Smtp-Source: ALg8bN4+SCxCv+v0ciJllZZSt1gizu2FLtH1GhZH9Pqg/UZOJ3D4wAV8BCsNApSveI/K/4xhxZMY X-Received: by 2002:aa7:d1d7:: with SMTP id g23mr22395352edp.217.1548787855673; Tue, 29 Jan 2019 10:50:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548787855; cv=none; d=google.com; s=arc-20160816; b=KbI4qeS5MfyIsnAZ7UW6IhWgeYt4NBRTx7SRDHwdNa9LXqp4+fAZEg+OpY6vq0ycbE Ag+JQFjvJ3oe3FBbNzX6QRYF0MjgT0/+Z7TwH12WhrjT5aEfVTwdMAml4scnWtRBhOVM +GzAGI/wyIZr1DvaJYWAaImtkOJRDRII79oVh+X+Z1WMlTEtz7JTrulAMARFaWVundjN 9S8e4BOp1SEJfdx/ssXrIxfl2HylFgieqx6u9+WSc6n4oFe37l4t/uC8cE7KiM22uAlZ OaOa9bkw2Mo4zILJNrzvIDkLvqvPzoXA61k9k1sTbECAy2vMlxDyQ4BGG7bLJtRWtrG6 MaLA== 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=Z0mOO2ifhiBIvsjdnVsmHqOe6F85CHxFTHq9HFgxSC0=; b=escheT5ppDZ9OlI/HxKePa5okWf2j8fwQmJCwHWeIZC+JXFyn1wEdCNauwbQjgnBwd b4MoCVHikcEvRRif4V0U9L0fS2wauBrNL2H1OqJBMuaBlxMunIvHdL6PigQfY4tAmj3g 3vSOZCx+lIubeiq66DKY9Vra1AdqFeHWcSWNiPHTZAGNMcqxxAHMmlJkmdZHJM3qyIeq OTbpPOC/bwnokNZBqQ0BPvtCA19NNqa1qu3PxlMs5VZlBy0nANYejyPKrjFAVN3WP7yM n8R6Loc7XUDOaLKBR/fsnBjaXhBKYTTLP/K7OnQTFuHe0gWV1+VPf/Opr+7pgR88lRSb CcqQ== 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 (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id b17si2746782eja.195.2019.01.29.10.50.55 for ; Tue, 29 Jan 2019 10:50:55 -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 AB4FA15BF; Tue, 29 Jan 2019 10:50:54 -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 0A4D13F557; Tue, 29 Jan 2019 10:50:51 -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 , james.morse@arm.com Subject: [PATCH v8 26/26] ACPI / APEI: Add support for the SDEI GHES Notification type Date: Tue, 29 Jan 2019 18:49:02 +0000 Message-Id: <20190129184902.102850-27-james.morse@arm.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129184902.102850-1-james.morse@arm.com> References: <20190129184902.102850-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 If the GHES notification type is SDEI, register the provided event using the SDEI-GHES helper. SDEI may be one of two types of event, normal and critical. Critical events can interrupt normal events, so these must have separate fixmap slots and locks in case both event types are in use. Signed-off-by: James Morse --- Changes since v7: * Use __end_of_fixed_addresses as an arch-agnostic invalid fixmap entry * Move the locks definition into the function that uses them to make it clear these are NMI only. Changes since v6: * Tinkering due to the absence of #ifdef * Added SDEI to the new ghes_is_synchronous() helper. --- drivers/acpi/apei/ghes.c | 85 ++++++++++++++++++++++++++++++++++++++++ include/linux/arm_sdei.h | 3 ++ 2 files changed, 88 insertions(+) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index dfa8f155f964..d0f0a219bf8f 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -25,6 +25,7 @@ * GNU General Public License for more details. */ +#include #include #include #include @@ -86,6 +87,15 @@ ((struct acpi_hest_generic_status *) \ ((struct ghes_estatus_node *)(estatus_node) + 1)) +/* + * NMI-like notifications vary by architecture, before the compiler can prune + * unused static functions it needs a value for these enums. + */ +#ifndef CONFIG_ARM_SDE_INTERFACE +#define FIX_APEI_GHES_SDEI_NORMAL __end_of_fixed_addresses +#define FIX_APEI_GHES_SDEI_CRITICAL __end_of_fixed_addresses +#endif + static inline bool is_hest_type_generic_v2(struct ghes *ghes) { return ghes->generic->header.type == ACPI_HEST_TYPE_GENERIC_ERROR_V2; @@ -1088,6 +1098,63 @@ static void ghes_nmi_init_cxt(void) init_irq_work(&ghes_proc_irq_work, ghes_proc_in_irq); } +static int __ghes_sdei_callback(struct ghes *ghes, + enum fixed_addresses fixmap_idx) +{ + if (!ghes_in_nmi_queue_one_entry(ghes, fixmap_idx)) { + irq_work_queue(&ghes_proc_irq_work); + + return 0; + } + + return -ENOENT; +} + +static int ghes_sdei_normal_callback(u32 event_num, struct pt_regs *regs, + void *arg) +{ + static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sdei_normal); + struct ghes *ghes = arg; + int err; + + raw_spin_lock(&ghes_notify_lock_sdei_normal); + err = __ghes_sdei_callback(ghes, FIX_APEI_GHES_SDEI_NORMAL); + raw_spin_unlock(&ghes_notify_lock_sdei_normal); + + return err; +} + +static int ghes_sdei_critical_callback(u32 event_num, struct pt_regs *regs, + void *arg) +{ + static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sdei_critical); + struct ghes *ghes = arg; + int err; + + raw_spin_lock(&ghes_notify_lock_sdei_critical); + err = __ghes_sdei_callback(ghes, FIX_APEI_GHES_SDEI_CRITICAL); + raw_spin_unlock(&ghes_notify_lock_sdei_critical); + + return err; +} + +static int apei_sdei_register_ghes(struct ghes *ghes) +{ + if (!IS_ENABLED(CONFIG_ARM_SDE_INTERFACE)) + return -EOPNOTSUPP; + + return sdei_register_ghes(ghes, ghes_sdei_normal_callback, + ghes_sdei_critical_callback); +} + +static int apei_sdei_unregister_ghes(struct ghes *ghes) +{ + if (!IS_ENABLED(CONFIG_ARM_SDE_INTERFACE)) + return -EOPNOTSUPP; + + return sdei_unregister_ghes(ghes); +} + static int ghes_probe(struct platform_device *ghes_dev) { struct acpi_hest_generic *generic; @@ -1123,6 +1190,13 @@ static int ghes_probe(struct platform_device *ghes_dev) goto err; } break; + case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED: + if (!IS_ENABLED(CONFIG_ARM_SDE_INTERFACE)) { + pr_warn(GHES_PFX "Generic hardware error source: %d notified via SDE Interface is not supported!\n", + generic->header.source_id); + goto err; + } + break; case ACPI_HEST_NOTIFY_LOCAL: pr_warning(GHES_PFX "Generic hardware error source: %d notified via local interrupt is not supported!\n", generic->header.source_id); @@ -1186,6 +1260,11 @@ static int ghes_probe(struct platform_device *ghes_dev) case ACPI_HEST_NOTIFY_NMI: ghes_nmi_add(ghes); break; + case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED: + rc = apei_sdei_register_ghes(ghes); + if (rc) + goto err; + break; default: BUG(); } @@ -1211,6 +1290,7 @@ static int ghes_probe(struct platform_device *ghes_dev) static int ghes_remove(struct platform_device *ghes_dev) { + int rc; struct ghes *ghes; struct acpi_hest_generic *generic; @@ -1243,6 +1323,11 @@ static int ghes_remove(struct platform_device *ghes_dev) case ACPI_HEST_NOTIFY_NMI: ghes_nmi_remove(ghes); break; + case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED: + rc = apei_sdei_unregister_ghes(ghes); + if (rc) + return rc; + break; default: BUG(); break; diff --git a/include/linux/arm_sdei.h b/include/linux/arm_sdei.h index 393899192906..3305ea7f9dc7 100644 --- a/include/linux/arm_sdei.h +++ b/include/linux/arm_sdei.h @@ -12,7 +12,10 @@ enum sdei_conduit_types { }; #include + +#ifdef CONFIG_ARM_SDE_INTERFACE #include +#endif /* Arch code should override this to set the entry point from firmware... */ #ifndef sdei_arch_get_entry_point