From patchwork Mon Dec 3 18:05:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710187 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 858A215A6 for ; Mon, 3 Dec 2018 18:06:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BBF32B068 for ; Mon, 3 Dec 2018 18:06:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 702842B47E; Mon, 3 Dec 2018 18:06:42 +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 17C3D2B068 for ; Mon, 3 Dec 2018 18:06:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B69C6B6A77; Mon, 3 Dec 2018 13:06:41 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 269886B6A78; Mon, 3 Dec 2018 13:06:41 -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 12FE36B6A79; Mon, 3 Dec 2018 13:06:41 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) by kanga.kvack.org (Postfix) with ESMTP id DC65B6B6A77 for ; Mon, 3 Dec 2018 13:06:40 -0500 (EST) Received: by mail-oi1-f199.google.com with SMTP id t83so8729032oie.16 for ; Mon, 03 Dec 2018 10:06:40 -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=aVEv9rbeYxezghts4bbhYTuuYiG4k1B5LfzjOaaIC4E=; b=of/hBhE5jHQWYokrs+1ZmrH+jhHJDpp4XeLU494TLOqfRvbyGGs34zOnXPigMbizLW 5bQmSiwOMeG/UC2RrUXI703hexVxLzYPZOJud1gz+pEzFb46aYWgUT29g9KIELvrhAnJ QNUoj6plg19M/yORgZpf19SY4PmRd+0DPzwcgU/KEKQ/JYKw5HzyFbz1qzJ2QlUoLVQS LJ2b0eEUZMVFhmICI0rkPRD9FrlPiaQt7VYaukXyzp30DnFfbDGcg7CIKTMlhqH9M7PK eseioiYQO0Pw/Bj+3pD+0MrR7bU+HDHUBTbYIBMAcGtlEw0yyjkpKGhDqk0ICMQwNkts 9YQQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWbcr2bVGVS3hd/FKIi9FDRXuTSWcsXwOHoS84plm5UYMqJPvnyZ uGvgvj1aqjwOarhPvm3BCZICzjOEB/cO70qwUVMNbIalCjJVEDl9l+OceiM+l8NyWDMQhS9nKYu XhrHX4NxwiypTKp3hnMVrHf0lv/r7NX+ii55ebJPCwi7YwMM++vgqqIjnk0xnddxcCw== X-Received: by 2002:aca:c46:: with SMTP id i6mr10007911oiy.208.1543860400613; Mon, 03 Dec 2018 10:06:40 -0800 (PST) X-Google-Smtp-Source: AFSGD/XJejJTutRj1iaCmYIqfgEWwXeLfBRFKrH/01OFcwHLMaMf5ooaVt9RNAgNGANHQxN0fYUw X-Received: by 2002:aca:c46:: with SMTP id i6mr10007879oiy.208.1543860399938; Mon, 03 Dec 2018 10:06:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860399; cv=none; d=google.com; s=arc-20160816; b=D4boZKmX8M/lxgJlOWMdUMJRPNCTKoHZef4bFTRR/UU21SeNt1hp5hui7nE7S9MT5s f9X8nNuSlbRkFVumUAHpf98UPRaFUCzrIq/TaaJVCInblWc1RpeXgpWSDkVEzn/gqzed i0dLOePglG5/6ZA+JW9V665gKbgJZIKmbgMTQBjXulDWi+KzVkSpoVI7IKi7SSkvACrJ flqJK42CayQ1Ek7HIDqXPGWe7YtZJ5sSK6chWVY3yf/mfRuxQ+ZV1aqB+Ba4GvbCh03u yIEYXCYkp+Vso89u/rf0XCR1hhfLPQZ2Uj4+EXPNhqqIdiwGMh7WFdaxxLdbkcokrpU5 Xv9w== 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=aVEv9rbeYxezghts4bbhYTuuYiG4k1B5LfzjOaaIC4E=; b=DhKly/n4TFICBNP2qXXG7AXIHG0YAJwVBdIWw966VOW1HjeHJmjx0mjNWlCoiCxh95 6DPGtwwos7/mJ5h3CAsLPSjgL4nz2dApijRS6/5MNmUgM6omMqQXr0DxRuRoG9UdAe6K cx+mLE5VcmbxeTyFPJXz6Qv/s54r5fV8eg7MqM66nJmwgx3qrLlECRxWGNDL22DX8/am U3uT+5aiZPfSxn0YCfgY9uxvXHaME+KbsyQn6Ac5+QfM9Nl35eDhKxUung9Tv/ZtPNeU l6wSnMmHbAB42+ViLnUMVT4fZHDYawJA96Si2NwfqinuOfMf6qv2XC2ZCExXRA3Pz9pP OSmg== 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 w81si6866609oie.88.2018.12.03.10.06.39 for ; Mon, 03 Dec 2018 10:06:39 -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 483B21682; Mon, 3 Dec 2018 10:06:39 -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 78B303F59C; Mon, 3 Dec 2018 10:06:36 -0800 (PST) From: James Morse To: linux-acpi@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Borislav Petkov , Marc Zyngier , Christoffer Dall , Will Deacon , Catalin Marinas , Naoya Horiguchi , Rafael Wysocki , Len Brown , Tony Luck , Dongjiu Geng , Xie XiuQi , Fan Wu , James Morse Subject: [PATCH v7 01/25] ACPI / APEI: Don't wait to serialise with oops messages when panic()ing Date: Mon, 3 Dec 2018 18:05:49 +0000 Message-Id: <20181203180613.228133-2-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 02c6fd9caff7..ab2dae6fc7e4 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -947,7 +946,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 Mon Dec 3 18:05:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710191 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 749B21057 for ; Mon, 3 Dec 2018 18:06:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 671282B47E for ; Mon, 3 Dec 2018 18:06:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 589312B10A; Mon, 3 Dec 2018 18:06: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 E8B2E2B10A for ; Mon, 3 Dec 2018 18:06:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B69956B69A4; Mon, 3 Dec 2018 13:06:44 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B19F66B69DD; Mon, 3 Dec 2018 13:06: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 9E3F76B6A31; Mon, 3 Dec 2018 13:06:44 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by kanga.kvack.org (Postfix) with ESMTP id 722C66B69A4 for ; Mon, 3 Dec 2018 13:06:44 -0500 (EST) Received: by mail-ot1-f69.google.com with SMTP id r24so3731836otk.7 for ; Mon, 03 Dec 2018 10:06: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=oKQiBv4c8SCObAeH6gAm7qQfsLUE0f47p7oCQKPtu88=; b=mErsXF5Vv4XjtbLqu6ymoKoFFcr+Bzka7iwyn0bSJiJO31yICw/H21Fc2fQ0xxco/n 8FLxSV4CPquQsCiAZjlHPOVhZA0vESrsSKcnNDv0VWWyE6BN5cPv5k6KqEwzujlTf5VI xTFxHsKeOUWOGuIeYeYIpQyfQ+olfMzTEzVImKZaaYgXcZsImcYaEUaWRowXUvB8uj6F adpkniXS3VAdkJgoq96tzli+/IZuKVFfmzNSO3v6ath0Rsmyl8S4VeG+D/z7eVR4TN9Y SN+MXLgpH3HnLDV5DE4v6PTuADYgqAaaaOdZ3gU1k3Qj6j03SCN9xUUtyd+loZIVPCgb tGVw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWZO1Wy4XZcf7NqhQMF1AkTCfSJ9lV6V9qkOG5Wkqah+A82RrD1O 9aZdQ4izzwYqg59mPmcK2piVwp1FFfhWItM6LlRvzUtqDLeOKH9NIVk+FTvCeuC7i7zqh9Xog0N VBQgavptEohmdDV3iAnRNsLI2EKN+PV9C4OQHjjP50QQqea+5fwV6jiuxOhsVgAgpkw== X-Received: by 2002:aca:b4c5:: with SMTP id d188mr10692048oif.309.1543860404190; Mon, 03 Dec 2018 10:06:44 -0800 (PST) X-Google-Smtp-Source: AFSGD/UqyQZ3ajxPF3eMv7M2kcMtCjJbmWxMOCZiyFe8lEmZFdqWQ+619sCMVbBnF8pTgzSRH1hK X-Received: by 2002:aca:b4c5:: with SMTP id d188mr10692019oif.309.1543860403471; Mon, 03 Dec 2018 10:06:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860403; cv=none; d=google.com; s=arc-20160816; b=pYHFw67g29jXt7MuYNvC5ciKPBSShdII7+G+e6rItbK9If959Uyhgozvd7ujBlZUp1 pa5409dBvfq8xwdPZUNKFQHknZHm3GvUBQiKWIDZO8IjbVDpCkpYR9QpspxZu4Q9rLVq NhKcjx+X5Xs1BIp/aocqlLzTJe57I5l85Lu5hfJGX+LL7NGlAyN4xuPkc7almnnmzlht XGX2eZ3RCsnbb+HSdfTPqUYkOm3bql8xggXsDI9J1s9+tAfw7tgjzY96U5WMYU36+ilQ dD6a18tV/APbfnYDDfT9BBzpyCJvp9LkkECO4SAsJhUN2kFuDNtv6NAjgZ3GhqDSqKik ChwA== 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=oKQiBv4c8SCObAeH6gAm7qQfsLUE0f47p7oCQKPtu88=; b=Tl0tcnmYfe0tCfPaKHn+HLbi/abyi1YWRUIUnjTCseDGXkW5jP5n2KEzWimTSXVIVU 55DPIitKz309N8ygvJMUAlOd9fDnY70Um2Gwki365c+3+mAjXX6gc1Xkccd2Pbbi4vOd 2Jbab6bdAdL3RC8HuYC19++5mqCeG50iV98VAgYXU6N7ZCFvk6dcwxuywmL2rHxAAwyO vMVQJctPOAu66UbHaHOh8nz6Zegx96l2hv0AbUgDVNVpEFwtm23Tutwy9HvYWHN8sXvb qsIZkXBW0mZd+RGXdZFBUAaQBlIg9x8RyJx8DvOvHFosUJgb0d5VYySQU2Ui3eFw+Y0+ 2EPw== 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 r137si6131581oie.147.2018.12.03.10.06.43 for ; Mon, 03 Dec 2018 10:06: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 E6CA7168F; Mon, 3 Dec 2018 10:06:42 -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 22BD73F59C; Mon, 3 Dec 2018 10:06:39 -0800 (PST) From: James Morse To: linux-acpi@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Borislav Petkov , Marc Zyngier , Christoffer Dall , Will Deacon , Catalin Marinas , Naoya Horiguchi , Rafael Wysocki , Len Brown , Tony Luck , Dongjiu Geng , Xie XiuQi , Fan Wu , James Morse Subject: [PATCH v7 02/25] ACPI / APEI: Remove silent flag from ghes_read_estatus() Date: Mon, 3 Dec 2018 18:05:50 +0000 Message-Id: <20181203180613.228133-3-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 shutup checkpatch --- 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 ab2dae6fc7e4..e8503c7d721f 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; } @@ -700,7 +699,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; @@ -937,7 +936,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 Mon Dec 3 18:05:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710197 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 6A62E15A6 for ; Mon, 3 Dec 2018 18:06:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F7BA2B47E for ; Mon, 3 Dec 2018 18:06:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5332F2B48F; Mon, 3 Dec 2018 18:06: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 DCAB42B47E for ; Mon, 3 Dec 2018 18:06:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B4396B69DD; Mon, 3 Dec 2018 13:06:48 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 65F486B6A31; Mon, 3 Dec 2018 13:06:48 -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 529EB6B6A32; Mon, 3 Dec 2018 13:06:48 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) by kanga.kvack.org (Postfix) with ESMTP id 26E756B69DD for ; Mon, 3 Dec 2018 13:06:48 -0500 (EST) Received: by mail-oi1-f199.google.com with SMTP id w80so8787296oiw.19 for ; Mon, 03 Dec 2018 10:06:48 -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=0O0wJfuc0UzHpAlq92San4mKfKpE+8UwtpVszOGCwwk=; b=kWoqbkONazG7cAek4Afu+nQtSAEIVPV5Ly7Sharp55CQlzKdpXkc/Mk+A3JqF/sw9u WUd+85+SNEuFGBTTMy+IYy1febn39tf8gKz5iuGLscUs2DXRKiE99ra2D8BvahG/yqbm 6/MeAWyVW0cbIgNtTvaXLEZ440GCSdcm3+FFydf5snfZ8PIMW8PyxhX9fHi9EyP9M5EE 6SiB4b3XLvJrViPjgP2MAPksC5eD9yrGp+RM/f+lGufYs8Ob0mqy/Kw20W+3fGi07vYo 9Qv/+NbO/WuL99hcdAv8EGjBvW/nfPS4zngx7gCXTXQHD6gaIKMMsSrjtRtt6OpMAHZf kXvg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWaGh3JusRz4pn73tbJOTYpeibZRuScO98f/m0mUUzqGTCR3WhQk VmBjOSVgkvbQ7DQsjDboZZFwuHfVEJ+nrMEupGSkeXkfMdA4hTpL9KY6hwsNC89FVz1KI1HGLuJ zt6SwdfCCtf5ndWPGX5+PjnEVPjWi4mPgAxP93d9GDPYfTyQRveNVm36cunY9qtIhZw== X-Received: by 2002:aca:db41:: with SMTP id s62mr9987205oig.349.1543860407899; Mon, 03 Dec 2018 10:06:47 -0800 (PST) X-Google-Smtp-Source: AFSGD/UaxyqidY04adsIYt20IcvUrvtkvj4s2ZQU+05Xnm8VhFgLnwwxm0byE9HAU/2STMJGDVXW X-Received: by 2002:aca:db41:: with SMTP id s62mr9987167oig.349.1543860407165; Mon, 03 Dec 2018 10:06:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860407; cv=none; d=google.com; s=arc-20160816; b=qSVuyVOJSxGa/Bm+9zsm/DB78mSNlTozoIA5FTgW2+mILIiOXqswEBMMIJV++BJCMx arbQKcHJ0mL3P7EM5I6289P+yRo8K1XwgD95qJIwCnaVYlDAefzArNE/XW9t3+CuV/XC 7l0R1qvW7EAmNTK8TycknWFXRrwevsiO+KO0wcvhNvUyQyEYQbTInDPDFYaan0qJRhR+ 6PhDvEDSdXblU35OhOY5s52u5wAhAnT+dIVCwUnN7YfjTc1/QF0phdO1Ht1JlWOZ11NZ meQm4k0DwHb1PhgjQ1u0DODH+bwQZK7hw9SfxGZlcXA0xxMjwQ/LP/554SImmEFBPDhB 06vQ== 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=0O0wJfuc0UzHpAlq92San4mKfKpE+8UwtpVszOGCwwk=; b=ao/65vBw4q3fx6t5mWwGQoQpyeqOEjATxaoZdc+qUfPKJ5cfwo1uS7CiIMz9Y4ssoM Wmhfp/iXJkVUM2FHvJOdeRXNFzz3RnYfvhl/SLe/9fDK4tMYYJ+INWFrFsf5c08W9ouk WEMcCElfmTAEbNZtkJf4aZDEO8pB0s4l340guLU9nzayJrbysTWlR/zV7djvX0ycEDf1 fh5R3HgEHOodFdB2JaMV8y1cHL9y77n3YKxlRUHyQmUUpDKpOaj+cKqTTyXxGgWARUpD lNgUDMTvkkVVJcqhmKMCJRuX9kyN7X2mLdD+tVx/aLvijRnfWHm9bsb1GXpL7df+BRv4 PPYw== 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 n1si6879652otn.272.2018.12.03.10.06.46 for ; Mon, 03 Dec 2018 10:06: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 7DB36169E; Mon, 3 Dec 2018 10:06:46 -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 AD9163F59C; Mon, 3 Dec 2018 10:06: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 , Fan Wu , James Morse Subject: [PATCH v7 03/25] ACPI / APEI: Switch estatus pool to use vmalloc memory Date: Mon, 3 Dec 2018 18:05:51 +0000 Message-Id: <20181203180613.228133-4-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 e8503c7d721f..c15264f2dc4b 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 Mon Dec 3 18:05:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710201 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 AE8681057 for ; Mon, 3 Dec 2018 18:06:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A35A12B47E for ; Mon, 3 Dec 2018 18:06:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 971132B48F; Mon, 3 Dec 2018 18:06:54 +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 2B53F2B47E for ; Mon, 3 Dec 2018 18:06:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 52ADD6B6A31; Mon, 3 Dec 2018 13:06:52 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4B0B46B6A32; Mon, 3 Dec 2018 13:06:52 -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 387796B6A78; Mon, 3 Dec 2018 13:06:52 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) by kanga.kvack.org (Postfix) with ESMTP id 0FFC26B6A31 for ; Mon, 3 Dec 2018 13:06:52 -0500 (EST) Received: by mail-oi1-f199.google.com with SMTP id n196so8714791oig.15 for ; Mon, 03 Dec 2018 10:06:52 -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=Jb/HfFcVRIO+ukolQMwK2cGv9REut3HKPUb8Vf9DTOg=; b=IZPp2WO6g8NIC+Q6TcdN8wDPY+FnTlJvhRoC5goIqj0+87LTGHlj8v+e+4QP1QoAJl 8gFflXmBIVVq23LO+myKOFckF1QRy82qyXLNiaNCJ8Nm9gPB/P3PXAyBEUfLYrLz6Zi4 IFLoh8L3kS8+kCRq3gXQ+8F/aia7vhSmi2GZDhEKxLEnSTlFt4smjdX5pDbzTH+rOMn7 QkPfltUzd1JIjgL1KruzrimRuJrdcDk6Js+5qY/GDYRz8VepBdeQfbC0u5JzueAJ+B4I B2I+TuROevsqLN3ZAXdevE0jJD1SAvs/8Fe4nNfeXL66xMcq1MrW5GMCN8r8MJEIhtfQ NNYw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWYEJYkZWbiib/t4JK/otu78NAvJk1Cy/zPnr/KIBArQLRcbPE/P 5mymXSHPUkIqlesbF5xlDAloSUJTX2ZaapKRyRwo7Jv/XMtXXOKF9BEgAps9Tlr7+jqPNcDbATA +kLdqx8RaftA8DsXEQcMWCJ3bdeA8bGp06cqEkU6+7+88wvt1XzRR158sCu5mhP+TPw== X-Received: by 2002:a9d:1b2c:: with SMTP id l41mr10213248otl.1.1543860411799; Mon, 03 Dec 2018 10:06:51 -0800 (PST) X-Google-Smtp-Source: AFSGD/U+wDfwrOoDXnmCBZLoLOQF3VTQo7DRV2TAGXcmlIPR0oMBY98924jE72HcsrxT0QTC2rRi X-Received: by 2002:a9d:1b2c:: with SMTP id l41mr10213183otl.1.1543860410759; Mon, 03 Dec 2018 10:06:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860410; cv=none; d=google.com; s=arc-20160816; b=hst0bV1u74Jg95zEWi1CInbYue+zKILkdsMa12v+ByikQq6orG4k0i3Xrz0USCVc/g +z3g2XweMGtoOzVPk2sNttuXamVIDo64z/xZf8JdjBSo9CPc0twKuWpGIIQ4Xpmnbu5t /a6t2/E7Is40Ee12WHFj2Iqc4dk1Bx0OivJyVGdxjAYVqlHW8xlR1XNWYbP/+MQFPInk m+Jzwg/hqHGw+v5gX+qtFbm+1bp1gU56RLdmscmi+aoWcZ+H0GuTmofezLwmiPrVmINn fK7lxrSwDr1NCTEymyqbCR0dOui+1QeQ1AiSD6T1I5Edas48y7MzxU0yPXfYxIMU9KyD Ucxw== 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=Jb/HfFcVRIO+ukolQMwK2cGv9REut3HKPUb8Vf9DTOg=; b=PWqyePIUOU7oopaHqd5oW9BCOtR6JwBAxGbCx5r9TzHDGQ/WLKmOmSptI1bSEjvRG8 Iy6LpW84mmuRvcYxvBmjy2Eo772/KI3HwF2CUEINv+1lKU1oA5tizMl/bg57mPgyGWN6 PfbKODhrdVvbiSJa8CMRaWwl8WufZHbe1PIKKMUWDGd7cF/rAYWnnmoIMy8Buo4Uqeu/ U1XRJDtVO1mpGFe7j3dvwAL0CpFY5/HNr2l11cDNZZcF3BEldWTmz+60byMzII4q7ioJ ttdST6PeztlIRxhdgrPt4q2BA6FYADNV+8IsYLD6TlH8thzQduM7llFeoPFPgGv4WluC cvxg== 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 k186si5994816oih.238.2018.12.03.10.06.50 for ; Mon, 03 Dec 2018 10:06:50 -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 108D11713; Mon, 3 Dec 2018 10:06: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 404C33F59C; Mon, 3 Dec 2018 10:06: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 , Fan Wu , James Morse Subject: [PATCH v7 04/25] ACPI / APEI: Make hest.c manage the estatus memory pool Date: Mon, 3 Dec 2018 18:05:52 +0000 Message-Id: <20181203180613.228133-5-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/acpi/apei/ghes.c | 33 ++++++--------------------------- drivers/acpi/apei/hest.c | 5 +++++ include/acpi/ghes.h | 2 ++ 3 files changed, 13 insertions(+), 27 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index c15264f2dc4b..78058adb2574 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) @@ -1225,18 +1215,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) @@ -1249,8 +1230,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..da5fabaeb48f 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" @@ -200,6 +201,10 @@ static int __init hest_ghes_dev_register(unsigned int ghes_count) if (!ghes_arr.ghes_devs) return -ENOMEM; + rc = ghes_estatus_pool_init(); + if (rc) + goto out; + rc = apei_hest_parse(hest_parse_ghes, &ghes_arr); 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 Mon Dec 3 18:05:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710207 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 029DB18BC for ; Mon, 3 Dec 2018 18:06:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ECE512B495 for ; Mon, 3 Dec 2018 18:06:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E022C2B48F; Mon, 3 Dec 2018 18:06: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 6CCD02B487 for ; Mon, 3 Dec 2018 18:06:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E1946B6A32; Mon, 3 Dec 2018 13:06:56 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 06D1D6B6A78; Mon, 3 Dec 2018 13:06: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 E4EBE6B6A79; Mon, 3 Dec 2018 13:06:55 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) by kanga.kvack.org (Postfix) with ESMTP id B86C56B6A32 for ; Mon, 3 Dec 2018 13:06:55 -0500 (EST) Received: by mail-ot1-f72.google.com with SMTP id w24so5834964otk.22 for ; Mon, 03 Dec 2018 10:06: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=32pQbp1azz8lOuYjiMIPoqSkEvXqXwtpekjbJaSIwMk=; b=FFkrjHchsoGQs1R0RECCws3yvURYFSpNI8nPtWJSJR5ffhrU6ai6AIA1KwefrRaoQ3 MCnQLL6kWlOxkQSS3Erpt4o9OJAOXPQKi0dwRmv6NNKxjYWpreyPaaB0S3RwSl/+LnN+ jTYvE38f3B3euNV39P/0rHugFDJmjFQeF85tfxrWO2f51q7YtzuYoU5nFspVkUVtRv1G JOttfnCLjQZfgxdn6fW8OldK+p9VZVGy3Xr95JWD9RhWS8s3iYsP8uZvbq14LkKdqR+r neC3mOzR8riZFoXTpnpHOc1akd7vwAiQMPvFxFY0oFyLlj1OljxEtQu/IbnymhjP/un+ EKuw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWY3+rjxQlNMRoA0pAKpdGeGyEWyxuagK42E7KYLxhhyhqqfaCHH JlsabpHJrgs0b1uDoBe9XKPIHWZxidLMU8QeZE9cs2JUBqXEgnS15org6LxUrFD+yfIdCSF97Kf GpzeK5ETwXMEIzTVEZFbbALM5SWE99oY1n9TyzLAfhX3KhaaiqDqT9p/oibuWzG443A== X-Received: by 2002:a9d:177:: with SMTP id 110mr11104702otu.26.1543860415442; Mon, 03 Dec 2018 10:06:55 -0800 (PST) X-Google-Smtp-Source: AFSGD/VnhIOzEC61CmMLsSZn/nsT2V0VRsOOfLh1HNIm+4ULEeIdJ/qTPByZLnUZMatNRZFEvMBR X-Received: by 2002:a9d:177:: with SMTP id 110mr11104644otu.26.1543860414247; Mon, 03 Dec 2018 10:06:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860414; cv=none; d=google.com; s=arc-20160816; b=mLs1EZ6+/PUv0kXTYhUzsyMRLtj5RIAwRjO4Lvhe3e92STKRBa+/5MCp89jh9hi054 zBla0va3yG9osVCheOUu6Zrs0osH44+yHPjyr3kW37Eyzmp8dg5hlshlKcmJRZsp0mmW 7VaL8oNUY+820eI9CBPmN2yAIeXMafKAR08WGcC73WF9ZaY1jg+fVohFKH/S9A+b0NHy MOHDdhNWHB+Xd9PwQK8mDNbViseaUxzgIw6ieNwzsp9lg/k++ufcgpEUd3t9y4+432N/ 794Sd/XGlErD+P0Kq44VUJ6HBTKzsT5/gleNhz/+C3vVfWrgUvQekA2RDFMuSCCQfe+/ UoIA== 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=32pQbp1azz8lOuYjiMIPoqSkEvXqXwtpekjbJaSIwMk=; b=Woy4iBXUhsWVMyYq/s/M0kpNQNjpHBQrKqskpw2nKquB3ytdfVayfeG5DaGcWg9s7/ 8Rnw+sLbesbVIbGnemrC1pDV7fyMc0gwPE9jxicR5aGVU4cEeuegvx8BhYkUI6ZRIKzo lCu9R95nLXYRsaMEdLTn5Uhd+0zETzCUFeYs+ZOp0xvxZqKTyD4QW4eSIOxF0CRhsqif 0Mh1YQEgLPXcUKh8QisbJfcocq8QP3+jcxigl8S5A/P71yZUAXqz2Hv57jrFfjMPOOIv U/CjWNJnXSEJoWwOx/2smcbRGTbbjz+YkLeoD10g7Tf7woHeAWLRB4SBtjstyj/24bxF wlfA== 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 y23si7282604otj.129.2018.12.03.10.06.53 for ; Mon, 03 Dec 2018 10:06: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 8BDD21682; Mon, 3 Dec 2018 10:06: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 BB7543F59C; Mon, 3 Dec 2018 10:06: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 , Fan Wu , James Morse Subject: [PATCH v7 05/25] ACPI / APEI: Make estatus pool allocation a static size Date: Mon, 3 Dec 2018 18:05:53 +0000 Message-Id: <20181203180613.228133-6-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 78058adb2574..7c2e9ac140d4 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; @@ -954,32 +945,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"); @@ -989,8 +956,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)) @@ -1001,8 +966,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 da5fabaeb48f..66e1e2fd7bc4 100644 --- a/drivers/acpi/apei/hest.c +++ b/drivers/acpi/apei/hest.c @@ -201,7 +201,7 @@ static int __init hest_ghes_dev_register(unsigned int ghes_count) if (!ghes_arr.ghes_devs) return -ENOMEM; - rc = ghes_estatus_pool_init(); + rc = ghes_estatus_pool_init(ghes_count); if (rc) goto out; 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 Mon Dec 3 18:05:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710211 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 5BD961057 for ; Mon, 3 Dec 2018 18:07:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 501252B47E for ; Mon, 3 Dec 2018 18:07:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 437B32B48F; Mon, 3 Dec 2018 18:07:03 +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 B42412B47E for ; Mon, 3 Dec 2018 18:07:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3C9896B6A78; Mon, 3 Dec 2018 13:06:59 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 39E656B6A79; Mon, 3 Dec 2018 13:06: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 1F6136B6A7A; Mon, 3 Dec 2018 13:06:59 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by kanga.kvack.org (Postfix) with ESMTP id E303E6B6A78 for ; Mon, 3 Dec 2018 13:06:58 -0500 (EST) Received: by mail-ot1-f70.google.com with SMTP id c33so5860535otb.18 for ; Mon, 03 Dec 2018 10:06: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=WSsL+KMNR04L5v6Hpw8zYrY0eTmIAOjGpHIkNrUglQ8=; b=La0DgpwRQOE45wE7LmjZXoRPjstnwKl/QSfB6XsRy8sl1mlqkMGVdHz+MEwe+6iyXa yWPi65K3+vqdHF788zTzWmQwCYsVdQ1AH6hIGKTTHgYcOiONOywoldJuZkhj1nRrD7aJ 5nqLWxPYXBs1PTYFUh6AplnoAl8NNHZzPomS2z2KEep1M0b3ec3nPGEiB/De0ILw8y+I RXOOP+UGC/QZ0LnP9tUrhOFPqCSCsXAlqwsyUV94riL2sdTd+TDzg1Q90vbJ65WWt4f6 EK5A90del44xUyJ5gdZgsP8673nUEMKBlBPhVlUL9Do41c0ieYhJM6v6TjBQqoZ8vdjO mARA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWbpubkw6qObWqOZC98UvPsxAZxX9NSic+80v9GXhZxEMZxAJN0A NE+tPnauYs84gd016ExTDlL3pjL7zESLGL7sdT33KfgE0i+TYplSO1Df1OJRjpY7yQMWL1+7H2R BBYJIvg98Abbtii1yMpjDpu0FrmUzveGszdZT4/8uRf6lsBqVxhEY/h8Fb98oK5Mz6A== X-Received: by 2002:a9d:2666:: with SMTP id a93mr7656905otb.235.1543860418648; Mon, 03 Dec 2018 10:06:58 -0800 (PST) X-Google-Smtp-Source: AFSGD/UIWLQp2ZEx/ln/T3Ou7wV4R73JmlsQlfkPlxHFW2CTZuhNDCTKbZnJlZ7a1+p2dkjaZqYh X-Received: by 2002:a9d:2666:: with SMTP id a93mr7656872otb.235.1543860417792; Mon, 03 Dec 2018 10:06:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860417; cv=none; d=google.com; s=arc-20160816; b=D4/dRS5gdDfIh2haYWxHRQNz65TVNQuBlCLxGPSjN8r8bk1fCnV0kCFR+aGaFZoXX6 nbNO6tGGg8YcYl8xB9Z1JvJ9U2oAeqYvmKq3UA733lIgmbkJ6vmchOo7do997fR17fkw 57dDA9C9dW6Zc23ulRYcVyLRC+4GSJIZAoliKDufLlEb+L+IXd5nUHMmBs+sI0vhiMWK LrlSJArVnxkk2QvP0/0cYSv1EecDXOWbp2WrXJTHrC7IGlhcRkmMUfzQ6JHxjZQIUZGC d0xDsQEDVwwxuVy3zwhMkM17/9caSvCUl6Genrj29Msrk6Uq48IP1nsQH/jvGBXgsluu sGeQ== 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=WSsL+KMNR04L5v6Hpw8zYrY0eTmIAOjGpHIkNrUglQ8=; b=og5KGVLZOwQmRG/ToboF2keBk43FwyY48met9Hoh7TynJlT1dJuyaEY15AffcMnv/2 HtaqLQf58L5LYr6qmRk34CyDiwoTYuRhtdDR1nGXd+M2ML4pUyrZOzpBGqUZJT8Ao5du Hx8/dCqXjF3DSQ62I83zWfC1FboupN1d+ToC1MQfvh3fIhRrL23kDCM5oU76wHYi98e/ C3Bl76jr+wF9lxUEwjhJ4t0oRQEusoa33dXfAJWw4hewCBpK3x+J227J4QAn/ktYAKFo nfMXbtZ4xdz4NLh1j38/h/xIBy8gcdcN+xxc4QiJBlOgVrViweMeTCosi4BBom7XmzNf FNeA== 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 79si6700677oth.11.2018.12.03.10.06.57 for ; Mon, 03 Dec 2018 10:06: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 1EACD169E; Mon, 3 Dec 2018 10:06:57 -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 4E39C3F59C; Mon, 3 Dec 2018 10:06:54 -0800 (PST) From: James Morse To: linux-acpi@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Borislav Petkov , Marc Zyngier , Christoffer Dall , Will Deacon , Catalin Marinas , Naoya Horiguchi , Rafael Wysocki , Len Brown , Tony Luck , Dongjiu Geng , Xie XiuQi , Fan Wu , James Morse Subject: [PATCH v7 06/25] ACPI / APEI: Don't store CPER records physical address in struct ghes Date: Mon, 3 Dec 2018 18:05:54 +0000 Message-Id: <20181203180613.228133-7-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 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 | 40 +++++++++++++++++++++++----------------- include/acpi/ghes.h | 1 - 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 7c2e9ac140d4..acf0c37e9af9 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,17 +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, - sizeof(ghes->estatus->block_status), 0); - ghes->flags &= ~GHES_TO_CLEAR; + if (buf_paddr) { + 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) @@ -678,9 +682,10 @@ 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; @@ -695,7 +700,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; @@ -910,6 +915,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; @@ -917,8 +923,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; @@ -934,7 +940,7 @@ static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) 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 Mon Dec 3 18:05:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710217 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 13FB71057 for ; Mon, 3 Dec 2018 18:07:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 098D62B47E for ; Mon, 3 Dec 2018 18:07:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0FB12B48F; Mon, 3 Dec 2018 18:07: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 E25B72B47E for ; Mon, 3 Dec 2018 18:07:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 773C96B6A7A; Mon, 3 Dec 2018 13:07:02 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 723BE6B6A7B; Mon, 3 Dec 2018 13:07:02 -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 5EB0D6B6A7C; Mon, 3 Dec 2018 13:07:02 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by kanga.kvack.org (Postfix) with ESMTP id 3471E6B6A7A for ; Mon, 3 Dec 2018 13:07:02 -0500 (EST) Received: by mail-ot1-f70.google.com with SMTP id t13so5992578otk.4 for ; Mon, 03 Dec 2018 10:07:02 -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=SPE3tkVs7kyyAhNfXdmKVgnugPqRoGsxuJaKhfBQBrk=; b=MokHYOnwerpc42A9yr5jct1nBxz96JRV1j9fyxY2J/zT0ZYgnXjh4DhTD9hZ/A0u8F +9XQKoj8J163EyC3aR3ZIrrNRNoLOIsA0RynVC+m9nGR2/CmuP+hosscyQ/5X3S3FjoD cc6FfOiNYbGghhdtpEq5h/VTVJd/aSrAEtjDRozKdK2t81aPbdd+NdKwoai0meHz1b76 Z0RqvxDn4lB6tK5KYa3F7vCzp8zKsFzHaV0yFsVUytIFlyshUZEGmBiE2Srv6X4oupSq iKDcuK9pLUyLO1Fif3VS/rp2N3tmxtje/eovZ/E51lE3gJ7JRXZq0kvlcwttV0kMSGhh a2Sw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWaAxzuwVTlXFywLTCqC8omHSiNm6vW5DyioX0SzX2uZjAz9G88t uoE6/4x+rtjswY16FLgxLFwn7hC1ZBmDzT9foBU2JRkjaSJegzNMpKXEp+jXoMePNhP7SbYIRLz McsAESkeLuHDXkqjEA1S3ZbHwmki+yZIOA/MjHhQK0hWaeyD7Zlzc1Aj+1SHMIWTabw== X-Received: by 2002:a9d:6c3:: with SMTP id 61mr11504591otx.314.1543860421962; Mon, 03 Dec 2018 10:07:01 -0800 (PST) X-Google-Smtp-Source: AFSGD/VLG3c3oVQRfx2IeIXBYZfJ9E14Axi6HqQE37S1wvYPF/hxGTre1UKzA3gb2x+dlPEcBRWc X-Received: by 2002:a9d:6c3:: with SMTP id 61mr11504556otx.314.1543860421148; Mon, 03 Dec 2018 10:07:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860421; cv=none; d=google.com; s=arc-20160816; b=gbHT3EaGU+nLouBKF2VlEA//reI1ENtUsMC5pKrWaIZ4XSOaTt8lA/WHUcH4dclQwL jg2pnyZu1s2iFXhpvpiJvTjc9YwncQ/lvkW4aPfQrFg3ho3548R884yexbuDAn2Of2LZ LEGtQYyx2/nRTjh9BR6vTTkY6Fv52j2rAKW6Deb4VppfoNnWGLtnygo/jK87+1sapsFN 62pvmXZ2NxccA2IuEbP56rR+frxp9T+4rMVFsQPp6a2ClkqcXk/a5Jww76hGInOkMD92 yvCA0TsgX5gWk1X6vFdEydcD09QdokAdMXPXxNS5B3rFdGOvOPu+mFdzkrv0qRqJMGgR nmpg== 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=SPE3tkVs7kyyAhNfXdmKVgnugPqRoGsxuJaKhfBQBrk=; b=KWdZj/VL/1TOkY4+bEoM+h7hYAcSdVVSsvAKCIEZjkgTVcMNqfXfye++DVZQR2zlk9 LqTHj8z6yqNeiXTMB9rFwt40XGTZrQB8i2oGdsM5sO51WYvrOvCvD1q0eVhYQ8cFCEY1 WQMmx8UYcKNCiGUqnnATeTXQ/TvfnjLzXEb5KsoFh1hT74oJwwDEKcaSoqhRUTeZQGQ7 GAPpI3fl2A3xKV912A2QAIB8A3UQuGwjAODbMatMgaqafiaAN3no8KGWDex9EheWlgtH ANu1D511v+F0eXh0da/PP0+DiXTW6VkRAukIXl8fxwuw3xj7w2q6KWTK73Nt3ikXRD08 8zNA== 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 e17si6869937oib.145.2018.12.03.10.07.00 for ; Mon, 03 Dec 2018 10:07:01 -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 893ED168F; Mon, 3 Dec 2018 10:07:00 -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 B9C2C3F59C; Mon, 3 Dec 2018 10:06:57 -0800 (PST) From: James Morse To: linux-acpi@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Borislav Petkov , Marc Zyngier , Christoffer Dall , Will Deacon , Catalin Marinas , Naoya Horiguchi , Rafael Wysocki , Len Brown , Tony Luck , Dongjiu Geng , Xie XiuQi , Fan Wu , James Morse Subject: [PATCH v7 07/25] ACPI / APEI: Remove spurious GHES_TO_CLEAR check Date: Mon, 3 Dec 2018 18:05:55 +0000 Message-Id: <20181203180613.228133-8-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 acf0c37e9af9..f7a0ff1c785a 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -936,9 +936,6 @@ static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) __ghes_panic(ghes); } - if (!(ghes->flags & GHES_TO_CLEAR)) - continue; - __process_error(ghes); ghes_clear_estatus(ghes, buf_paddr); } From patchwork Mon Dec 3 18:05:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710223 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 442661057 for ; Mon, 3 Dec 2018 18:07:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 386FD2B47E for ; Mon, 3 Dec 2018 18:07:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2B55F2B48F; Mon, 3 Dec 2018 18:07:11 +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 BE82C2B47E for ; Mon, 3 Dec 2018 18:07:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B42AE6B6A7B; Mon, 3 Dec 2018 13:07:05 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AF3196B6A7C; Mon, 3 Dec 2018 13:07:05 -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 A0CFD6B6A7D; Mon, 3 Dec 2018 13:07:05 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) by kanga.kvack.org (Postfix) with ESMTP id 74F756B6A7B for ; Mon, 3 Dec 2018 13:07:05 -0500 (EST) Received: by mail-oi1-f197.google.com with SMTP id p131so1297616oig.10 for ; Mon, 03 Dec 2018 10:07:05 -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=1h3n0IWtDadO1PFfu0yti7m1Cb4M4Vp3Bsov6nNlZVc=; b=c3GTzFWQgl4/oo4zO0i4HznqMFkGgbrtCZ3VgBnrYFtRh8w1ls4RRkisp4gzBLf/Bk 4ZY2Wb+Re4Z0xls5fodBgngpFtjPn2rIdW4wWtDqssYZ58bmytE7kvETYejSse7qPyE0 PeDMV4+W/JZNS1xQIbd0d1SPsUclXHxJKLWYVCRrqPxo8e8XRFt8vXaWMr+XgiDTKBC7 ZHnezOjLaQ0HMeJdUD88YVabGiCLVDjzZ9iLRK3pNRCuHIbBlD6UoqSGl/vffZ8W7vBU opR30FiLT7BLQm1ZpN0I7RHvNyS17JzTc2gHJMT2gfPpOyv/MYSUZtNZDfZSOejIupWe F5CQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWZTJb5U316ok3GIEUz+Ct4gCpGnnrTqAguZHa6jBT1A2glk5Ept GhlMsiIR9OMI98js9stjV+2aaYTMyge+YMmowGzKHRp5De06tAXdckogjpr1pf17nzl3CaoYWRz ber+5/jg6OPlO0/bKuPp+w6C/FZQeSbEaKFdJ1MKayp7+DmgGyyu8E3oitY6nR5wQLQ== X-Received: by 2002:a9d:620a:: with SMTP id g10mr10238376otj.249.1543860425179; Mon, 03 Dec 2018 10:07:05 -0800 (PST) X-Google-Smtp-Source: AFSGD/X2XiImt5VBvn5o1gSpVNaNiN7KgykOpU6ZYZA+LFHUN55LXo2zAZGHAt6a7ReELqrQfDy3 X-Received: by 2002:a9d:620a:: with SMTP id g10mr10238345otj.249.1543860424489; Mon, 03 Dec 2018 10:07:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860424; cv=none; d=google.com; s=arc-20160816; b=zjywdJ2jkDLJHiw8iX2bP3mDH9yAS8X4ylsHFPzKFNR4BfboKa1RmPXXfykHO75y61 1KYKdyMMNnDDANmAX+SesQpIEoGPdB0JcwTvTQyHGWT4aSbpgLzFPTCzyvCytnLJO9h1 /cBLqIwUSxeacGP7tBPu3T5MumlUnryDzYhxN1F181+lV7wQh/DiiincZR6P02ktQSJ0 Ey5QHlGHcMU6QOxzVUphlihCTxbMqzcbBNxMBPBAfaA0+rAihpQh0vzOVTB2+DpukarW yhkn+RRXr+HHIiJh+Bvr6kur+IKL9Qz6hCcraMKhaPF2nqaprlchsj6HoMNao5ANDZaN kcXw== 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=1h3n0IWtDadO1PFfu0yti7m1Cb4M4Vp3Bsov6nNlZVc=; b=EqMsfklduhZroK/qC8RiIc8nSIlMoW+V/JoWFAO4s2pm39EnpKIzqfPUqiSRTaRUYs SD7+TMjISgVt7t4gUDCd6LNVQKseElOHIZOwVjQ+pccpmWGdYsgSs03vWuSRf3Hwcqu6 luLq0j9gvxDdSr67qUBUACWpmxEoTDx4A/JgTXGfDIvbsK8/ConmyS0QanudGDmNsJMP 01dWyesSMAmvd3wG/z5WM5OnUIeg3EgTFak2Q0Ud3r4rnQQpFR9UwSIcPrmCBIiEa+W/ I9FTUq6rDJn+erH9XSbrEVGYeUyv/WafXacSbcfht3gEXxeJWOCQQkQYy2kAC8KmHsaz LArA== 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 v7si5802576otk.268.2018.12.03.10.07.04 for ; Mon, 03 Dec 2018 10:07:04 -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 14E741713; Mon, 3 Dec 2018 10:07: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 44BA93F719; Mon, 3 Dec 2018 10:07:01 -0800 (PST) From: James Morse To: linux-acpi@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Borislav Petkov , Marc Zyngier , Christoffer Dall , Will Deacon , Catalin Marinas , Naoya Horiguchi , Rafael Wysocki , Len Brown , Tony Luck , Dongjiu Geng , Xie XiuQi , Fan Wu , James Morse Subject: [PATCH v7 08/25] ACPI / APEI: Don't update struct ghes' flags in read/clear estatus Date: Mon, 3 Dec 2018 18:05:56 +0000 Message-Id: <20181203180613.228133-9-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 | 8 +------- include/acpi/ghes.h | 1 - 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index f7a0ff1c785a..d06456e60318 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,13 +355,9 @@ 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) { + if (buf_paddr) 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 Mon Dec 3 18:05:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710227 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 396D41057 for ; Mon, 3 Dec 2018 18:07:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E7312B47E for ; Mon, 3 Dec 2018 18:07:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2204F2B495; Mon, 3 Dec 2018 18:07: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 C27CB2B47E for ; Mon, 3 Dec 2018 18:07:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 095CB6B6A7C; Mon, 3 Dec 2018 13:07:10 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F18236B6A7D; Mon, 3 Dec 2018 13:07:09 -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 DB4A96B6A7E; Mon, 3 Dec 2018 13:07:09 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by kanga.kvack.org (Postfix) with ESMTP id AE1EF6B6A7C for ; Mon, 3 Dec 2018 13:07:09 -0500 (EST) Received: by mail-ot1-f70.google.com with SMTP id 62so5950180otr.14 for ; Mon, 03 Dec 2018 10:07:09 -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=HjBwv54S7WHFfQkiw9qR098cj5jgmE/yJtTlhtiGgvc=; b=RuHn6bGMK+3OXS3ijYEh1D7o1zfFvuEeM7CXUPqjbzrc64+pYNLjQ+M/KzUvHhXuD8 62zeF5Jrs1vDjzMqAJbBKUhtzpdCjuhPgST2fjFaZFAobcUpl6tUOYjeMCAOvNqGE5Oi CGpZyJO5zkPX6+G6Q5aShPforPgz2RDhUE05NVJ44hGad48OnUUwcwr+dUbL2YyGSwMo pQqwu73Oesyd5SFlVTWwUZuuaf6TsUhbYkDYm7arkJ/VpgPWS1PkCbESPLhyWmRz6Xtc Ulq4eVg1k0C9IldaFyFQIEzaeQFtBvC1hmZlne78vp0tNOjToLIrdqwOtyFZiCIgA2wc 1BYQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWY++ehsw1lJscDIg70vjFt3wQYOpJIPVEHlaTCljncCxV5Ed4kT vaaAL+7kFBSgPwlHpDCsjlWi6CPcxjqZfMaNBaX2uF2O5zDTbNTkf5dCqyFlugGm1RLpmSgrinx 9bOtTBTKDgPZnWH/9E1AyYJ7l2ytRg5+mGPTnbpfkANGIdwDRC0iSKiYqLJL9vVQHFA== X-Received: by 2002:a9d:694a:: with SMTP id p10mr11548293oto.44.1543860429463; Mon, 03 Dec 2018 10:07:09 -0800 (PST) X-Google-Smtp-Source: AFSGD/UKkK5kj695MleFCet4ZUmXqeOWCYAk7ZNfrtyjjnBiA6pFBCU+CY6Bj2q7V+/wPL1fSfpR X-Received: by 2002:a9d:694a:: with SMTP id p10mr11548224oto.44.1543860428155; Mon, 03 Dec 2018 10:07:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860428; cv=none; d=google.com; s=arc-20160816; b=UxecwShjxftMerBb5VPWKCzNYsu7LI/LSRXIk4qvribmOnlqBo9nxz1L9rFj8gXo1r K+2xcDEfR5tQdHBBQnAIn8nHXPUgLVBmCXxnxuzBd0UzjtpEqLN7h4O0X1lLVZu61BXG OzfSpITSCjVAGx3pIujvhW7iX71s8IG0IKZeF4OIgfrZI5mkukbpaPFn94rBPr0C5P8G FoOfKsIbT3R1JbWqS/9K7X6kGl2RhnsP9QGd9SIsLprXMoaFBpoIQwjoWQWZD8b5GRoc M6niYw/8aJSwjngbCR/7/FM2rtRa3SYwBkj6zPSmzNebaRw1nCOt08SxOBIrBUbUUMWP skMw== 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=HjBwv54S7WHFfQkiw9qR098cj5jgmE/yJtTlhtiGgvc=; b=rpCRaI5zk2y1/7JA3h3iJiKJHlTipXFSkLpDDc6GLdH53nTjIWgWyXu0uCftRPJpqe IofYG30/KTiO1lmb+h2E0MSYIqaxVpmMEwabYczZ0wgi2XGgMccrpuKFIP9GuZOmL6l2 WOweFCQiTG4y+dvUN4iPC/P22w/CnvvY8b/C67w4AvUH0pgRsioEZVuEjBaTVOs0ru8i AV5L5UI0Zvqidhu5A3sooqThq8HhjEEFojTJ1pt/pAbIAhgS3dPBqcqVpvfbClBQEJxh 31T+SRQj1vcSxVdjpQubpD7ZF4jx7UZVR0TmpkFkuzjRjN9fv5QxT+DJ5KmnArwRe+ZV 2Igw== 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 s205si6182708oig.116.2018.12.03.10.07.07 for ; Mon, 03 Dec 2018 10:07: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 93DF21715; Mon, 3 Dec 2018 10:07: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 C3C443F59C; Mon, 3 Dec 2018 10:07:04 -0800 (PST) From: James Morse To: linux-acpi@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Borislav Petkov , Marc Zyngier , Christoffer Dall , Will Deacon , Catalin Marinas , Naoya Horiguchi , Rafael Wysocki , Len Brown , Tony Luck , Dongjiu Geng , Xie XiuQi , Fan Wu , James Morse Subject: [PATCH v7 09/25] ACPI / APEI: Generalise the estatus queue's notify code Date: Mon, 3 Dec 2018 18:05:57 +0000 Message-Id: <20181203180613.228133-10-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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. This patch adds 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_notify_one() 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 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 | 63 ++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index d06456e60318..366dbdd41ef3 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -907,37 +907,56 @@ static void __process_error(struct ghes *ghes) #endif } -static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) +static int _in_nmi_notify_one(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); + } - sev = ghes_severity(ghes->estatus->error_severity); - if (sev >= GHES_SEV_PANIC) { - ghes_print_queued_estatus(); - __ghes_panic(ghes); - } + __process_error(ghes); + ghes_clear_estatus(ghes, buf_paddr); - __process_error(ghes); - ghes_clear_estatus(ghes, buf_paddr); + return 0; +} + +static int ghes_estatus_queue_notified(struct list_head *rcu_list) +{ + int ret = -ENOENT; + struct ghes *ghes; + + rcu_read_lock(); + list_for_each_entry_rcu(ghes, rcu_list, list) { + if (!_in_nmi_notify_one(ghes)) + 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 ret = NMI_DONE; + + if (!atomic_add_unless(&ghes_in_nmi, 1, 1)) + return ret; + + if (!ghes_estatus_queue_notified(&ghes_nmi)) + ret = NMI_HANDLED; + atomic_dec(&ghes_in_nmi); return ret; } From patchwork Mon Dec 3 18:05:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710231 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 D0FCC1057 for ; Mon, 3 Dec 2018 18:07:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5FFA2B487 for ; Mon, 3 Dec 2018 18:07:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9E852B49D; Mon, 3 Dec 2018 18:07: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 6321C2B487 for ; Mon, 3 Dec 2018 18:07:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 01F6D6B6A7D; Mon, 3 Dec 2018 13:07:14 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F12FE6B6A7E; Mon, 3 Dec 2018 13:07:13 -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 D8EC26B6A7F; Mon, 3 Dec 2018 13:07:13 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) by kanga.kvack.org (Postfix) with ESMTP id A91BF6B6A7D for ; Mon, 3 Dec 2018 13:07:13 -0500 (EST) Received: by mail-ot1-f71.google.com with SMTP id 32so5926014ots.15 for ; Mon, 03 Dec 2018 10:07: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=gXCbx7FLYJYLoHWmTibUsDbopZnSEkoIoNBLX6Xu06g=; b=Jv98kB/9OaTOT2gmVVo83yU30HyOQAytW9szWLsjprbzijH070SUkAi6MxRmjlI6g5 IWM4+M+2/+6MWfGc5jJzsb0wqfZC7Fz+q9tg8AxwO3m3cec2RVVbIATfk5RLv9EZEJRp layd7rmjEHXrShBBEHiaK2UHIhwF8inqBHROFFhxuwnxiHlC0yhpgKKGfg0PsTsEoPAI Wu1EYv893UTdEnLdUD0RD/U15Q8LfKvrsaOjZWpqCXbPRprVkbbjYiYPhe0coAUTdO0u j5D8sebuJUgUoSx1KqEg1L0a+fpj7Idf8/+VUlc12BjA3Ogba2dXZ1Cpkmaq/rb0V/p+ dQUw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWZWNQ0XdD/GF6y1HVOTrDszp06Jzh3dmfVQHqaqAGb7BycDVVc+ Uj9znKzvmUQTlSkjvsAUyf++J3FGr/Q0xF0dHHHU5mqR9RfbWmEd2JItkzaWvgqdMWWiEVCd8xe NSvTbfXuhaqOwq2nii3hJ32jSrCc5Yvg5+GPw+3/qSdYEvd9o8U94h//gDA9t5v8+8w== X-Received: by 2002:a9d:18f:: with SMTP id e15mr11373458ote.84.1543860433373; Mon, 03 Dec 2018 10:07:13 -0800 (PST) X-Google-Smtp-Source: AFSGD/XZQ3rJcpBLeMeNSAB6kYDJprPEWKaunuUeD/6AjnQy+Jt61rlYGVk2xKBvn74hlCyLCyd2 X-Received: by 2002:a9d:18f:: with SMTP id e15mr11373429ote.84.1543860432733; Mon, 03 Dec 2018 10:07:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860432; cv=none; d=google.com; s=arc-20160816; b=E88xv6ukPAU6TIX0ZGnjKF9JPqYq0l4LDH8ix9gGdcfzUY7IKtHPXpVz2ICK6W93iE ngIIyI1Blw2iMq9JN41vlb8scCnIk4MvqfJTrnu4l/w0/8QURwkwrAZ5gX7jiqL1XuSU I2neaGjv7//1MpmjHn2aNTAfHHi0CYMRHYEkKy6oB/BY5Pz379dfY2FKeCxfvWCXvBo9 HyN4WWFX38RJYZ0BImyLjY+x/avm3u2LDSKdBEc4jWCesDNwda55VGj0SI99mIPfNvsx 0qy6caLMrGwmB55OHCQMRHu5uRuL1Xhg+kD4oXI1EJ8XrQl9KjLWql5hjTnzQnDPywr2 nhxQ== 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=gXCbx7FLYJYLoHWmTibUsDbopZnSEkoIoNBLX6Xu06g=; b=Q/YD7hHdegguP44u0NwrTHwnW2dlQCWJxuLbV8Y1tO1bRz7s8KUBxhPc+IJT85OHhE qoKrYiZVoRzX9imMQ09+r/F3NYziZYv2UZLL2YHpy+VK97+wRDZLeU80/l7DQywUowy3 Fi2uSLA/DffDOD5LwF+ewCuMdsJNIZ5wB5Qa4wgALdNefVhfkfM04tCB3QbpjUzJTJPf 4j2jiy6i5UVcVnNmF7dL478rgwvQH2UrFFkSJjWMlDBLLCl1ko/x8+uCxlBtmbb2hUDR hCbhrzB8tHZuEg2RYq0yxviZjrdDvRVm/pznmye2wDYlwtJrkt7IVvmWTW+qxoMsyfgd FzQg== 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 c127si6302024oib.58.2018.12.03.10.07.12 for ; Mon, 03 Dec 2018 10:07:12 -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 F15271713; Mon, 3 Dec 2018 10:07:11 -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 2D90F3F59C; Mon, 3 Dec 2018 10:07:09 -0800 (PST) From: James Morse To: linux-acpi@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Borislav Petkov , Marc Zyngier , Christoffer Dall , Will Deacon , Catalin Marinas , Naoya Horiguchi , Rafael Wysocki , Len Brown , Tony Luck , Dongjiu Geng , Xie XiuQi , Fan Wu , James Morse Subject: [PATCH v7 10/25] ACPI / APEI: Tell firmware the estatus queue consumed the records Date: Mon, 3 Dec 2018 18:05:58 +0000 Message-Id: <20181203180613.228133-11-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP ACPI has a GHESv2 which is used on hardware reduced platforms to explicitly acknowledge that the memory for CPER records has been consumed. This lets an external agent know it can re-use this memory for something else. Previously notify_nmi and the estatus queue didn't do this as they were never used on hardware reduced platforms. Once we move notify_sea over to use the estatus queue, it may become necessary. Add the call. This is safe for use in NMI context as the read_ack_register is pre-mapped by ghes_new() before the ghes can be added to an RCU list, and then found by the notification handler. Signed-off-by: James Morse --- drivers/acpi/apei/ghes.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 366dbdd41ef3..15d94373ba72 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -926,6 +926,10 @@ static int _in_nmi_notify_one(struct ghes *ghes) __process_error(ghes); ghes_clear_estatus(ghes, buf_paddr); + if (is_hest_type_generic_v2(ghes) && ghes_ack_error(ghes->generic_v2)) + pr_warn_ratelimited(FW_WARN GHES_PFX + "Failed to ack error status block!\n"); + return 0; } From patchwork Mon Dec 3 18:05:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710235 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 8AF6A15A6 for ; Mon, 3 Dec 2018 18:07:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F7182B47E for ; Mon, 3 Dec 2018 18:07:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 738272B495; Mon, 3 Dec 2018 18:07:24 +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 EAD172B47E for ; Mon, 3 Dec 2018 18:07:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 12F066B6A7E; Mon, 3 Dec 2018 13:07:18 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0E4C36B6A7F; Mon, 3 Dec 2018 13:07:18 -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 E9FB16B6A80; Mon, 3 Dec 2018 13:07:17 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) by kanga.kvack.org (Postfix) with ESMTP id BD86B6B6A7E for ; Mon, 3 Dec 2018 13:07:17 -0500 (EST) Received: by mail-ot1-f71.google.com with SMTP id s3so5996330otb.0 for ; Mon, 03 Dec 2018 10:07:17 -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=NWOuoqyRcXiWkH3ZxuyBKiaiIfIqRiXKOIQVdYczQfA=; b=QXhUbMCoI9Hr3IiGg5EscEDQyMh3tuOkGgWXijX06vGwr/Aw56m0xpcxYmkucomLsW XHCJLZNIoQ4xpq7nFGqScnrJxWNFetf9pAwhYPYDZ8BwwjYiWJsqXjxGLeQWTDOxpBzt w7PhZ2mFp1x47kshN3+MMq5xtYstirL9mGFHOTVx+m+D+p6/qRoQjV/eLzKmjxH32Krq x+IsAYRj/b+9EsO2Hi4GfeAW0s0l2IV456iU4ekPD8YaJRryH71CyJmIaxXNiFs+my2K lGZvvXMUwMEH3vtPcPSCYVA7IcTtk6/1EUH1V0Ge8zhxronJT2OG71BU5rEspC9bH1L/ txVg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWa6zbCigYWCXly3hDOipoCnMnCsJIRX5yKACckEL2EzrIpgEWqw OO6xz1orA6fHXHe9dyowdgE8J9nlzFACLWL5Dkk6kq5xVU5+O8PPsuVJ8HUZC/aa4TeGWUFNBkw iWpOi4qyxmywhjuJA+JI99FrZiSJRXjpWXBolDjLT6Ky8WupnWJRNoV42LN0rz19BtQ== X-Received: by 2002:a05:6830:134a:: with SMTP id r10mr10478807otq.195.1543860437535; Mon, 03 Dec 2018 10:07:17 -0800 (PST) X-Google-Smtp-Source: AFSGD/V+TkeLzX641L9B3POc+gYSAx7FgoY+eSqa1yBrBi1Bm9eSD+YR4rcmWcttQcNq5YYzZ2N2 X-Received: by 2002:a05:6830:134a:: with SMTP id r10mr10478757otq.195.1543860436596; Mon, 03 Dec 2018 10:07:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860436; cv=none; d=google.com; s=arc-20160816; b=VL8f/kxKMPExSs8o6CVA8gx/C1YxGsqb/1eJ56gd7Ux2vreZMkRO2KILX9y9Mhi8y5 9v7z7Z6CE+zT+la3RfxwQa8zXfxiHWLt5FjXlP0UM+adEHlLIkrbKowU1tVy/PNYbm3f R1ycGhKPGhFVera2S8yaae7kvRc9Grx7j9Ib3pf74kF4IatqZ1TW0DNL13alzyYjRh4D ATBCf4N3Yhb9qwSmtRm9OmmmTDHei1xug073qz7aMw/eqDhLxIXtdCRsF4nqlKQP2aom dqsEZ/w+6JT/O3mTTlQo4XGkY/FK1yH9X09PJv9TuyJ5MAbO5ys+nJsVpNP+IIA4BvJc WZzQ== 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=NWOuoqyRcXiWkH3ZxuyBKiaiIfIqRiXKOIQVdYczQfA=; b=km1ELV1WL3Efv6gKgOKz6CsVFPXD7K67JYRFAsVwAcio0P8tVzZmJQJbI8ecgnzTMb AuDDLrhdWfUTkLfK+3EjooiSJZ0BC2ybbxf5cr+5DqRg9z1F97fSBRX6XjK7TAZQ/kP+ SxKkJuDWVtTwxwphm19MHBGfXjLAHdPMJXk2qSrlB+A5lCZ8K4kcruR21s9D0fuTkYrE BzKsZh+1Ykc2mCkSambkGt6QCniKhyFa0ZuTG22DC04ULqkBY5DXMvh7nCtIjGslAfDi nUPuOzr7uCYcZhIu1Zo+QFO4djK0/NkChpxtE0NNIKJTP5koVktajFWwpLu6sJHfRbTe anoA== 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 q82si6483304oic.178.2018.12.03.10.07.16 for ; Mon, 03 Dec 2018 10:07:16 -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 09ED2174E; Mon, 3 Dec 2018 10:07: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 396EB3F719; Mon, 3 Dec 2018 10:07: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 , Fan Wu , James Morse Subject: [PATCH v7 11/25] ACPI / APEI: Move NOTIFY_SEA between the estatus-queue and NOTIFY_NMI Date: Mon, 3 Dec 2018 18:05:59 +0000 Message-Id: <20181203180613.228133-12-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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. This patch moves 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 15d94373ba72..00fe4785e469 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -765,66 +765,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; @@ -950,6 +905,56 @@ static int ghes_estatus_queue_notified(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 Mon Dec 3 18:06:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710243 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 231F11057 for ; Mon, 3 Dec 2018 18:07:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1830B2B47E for ; Mon, 3 Dec 2018 18:07:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C0052B495; Mon, 3 Dec 2018 18:07:29 +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 8C0632B487 for ; Mon, 3 Dec 2018 18:07:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9E2646B6A7F; Mon, 3 Dec 2018 13:07:21 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 999456B6A80; Mon, 3 Dec 2018 13:07:21 -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 85D9D6B6A81; Mon, 3 Dec 2018 13:07:21 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f72.google.com (mail-ot1-f72.google.com [209.85.210.72]) by kanga.kvack.org (Postfix) with ESMTP id 556546B6A7F for ; Mon, 3 Dec 2018 13:07:21 -0500 (EST) Received: by mail-ot1-f72.google.com with SMTP id c26so5971829otl.19 for ; Mon, 03 Dec 2018 10:07:21 -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=og/HhddhQV4kd5weptQo3NtZBBhCvSV4v/gbtQSKrLY=; b=kTFWdZpD+z+xPyw/ln0zZz57Ax4/w0vE9VA9JuELg/qhtBYhAx59sqQXynCrm7fpT3 tk4mURjB3K6Xtk3So2YTN5JVYx13xFS+e9DgmKd72pNsc7J8hHbAxZGv2xqZQ98ASMEA eoZi2g01PTSgA6kZiz9LLdxC65rWgnzeBJINt5ClOkR4g5EUBoEsKNm6pHdwCQNtyJU+ yNkg77ztyuiglbXMXduk0PES30Yqjqu2aoeVKsfVmMOSsJL5wpVQdL4P5Gro3LLeUAyo jCIk9bHOXI61Du6YgCpbrDiiTjjrhscEM/mM2xLzlDtwpuNDzO48NR6Hr3C7zl70WwI8 x5FA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWbJJJH0dCmuLOaIvwezbJ7Bq/hcyRj04BzAQ5RWDjy5sfIdklHr 0L1Ne3UXs4rAi0sHVkZY786rItHG1lwTWP3BrgQPyanltRbpH0mXyk4+MuYZVFljtkHzyNBkEeO S82vdZCvkKOQgFId0cUytGKNtP2/Mn3qeSAdStKgszMTSNg5S/YtM9Yn52/HsfgHgqA== X-Received: by 2002:a9d:5f4:: with SMTP id 107mr11492521otd.102.1543860441094; Mon, 03 Dec 2018 10:07:21 -0800 (PST) X-Google-Smtp-Source: AFSGD/VKws/BFIGMoNsoEA+zOfzgm7WX5qMVRTZcX9arDzT2i2SCzPgcVJHkf+Ky6nF2i82d+1s8 X-Received: by 2002:a9d:5f4:: with SMTP id 107mr11492476otd.102.1543860440211; Mon, 03 Dec 2018 10:07:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860440; cv=none; d=google.com; s=arc-20160816; b=GECYcpo37UO9j1Fj4TldinDj+eSE0k2cHz+mKh3qiAuVlbOJqXQSoDjC+ulBCdW/AR i/PL1l2SsaFH1ebMNJ9pSs/o6B5CVcFdAMCvgDjnCxQT8Pkr5JHigMbiEbMBySB4JYtf ENN5saDvv4/AXhDZivfKuWUrSe3ptHw9tkv7hKg2HtZT8QyqUucYOlvGL7lH7CHt32K/ d1emmiErxPtZddtJ0JjBpbHeot8JL/zv5qjaK/Nlze5cGEbKIb68cQzoT6Ubddukd6xn njPqs41h0dVWmo2EsBg1X/DB48xL2l74U5/2v3mlqGp4RGug856CTyAtK/979Ox7nhqD rTxQ== 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=og/HhddhQV4kd5weptQo3NtZBBhCvSV4v/gbtQSKrLY=; b=pNL/ZqwdtRVIRcIzLjuNs2Y9hH5UdfqImTcSSgWz/C6fVk+M+aOfLyBw/D22nW2eqv ZX7kQu1L9dBYaygr9HKQdtpZScPG9DGiTqry/C3ZI6Uh/+fzAygTpvaYO7Dzqri3LmRa lBcHQScMdbHDzMKgPzVSDJj4MYVO4B4gqxKXCcjtQ7WZpmMrxPAzksb4TgVrvv60Dk2r aBDaNcUULZ3L0E9BYhv0AX9sKnFd+W8dn9+KAkSM2wwx6Kc5Yg5GnZtG4xdIAUDfvOc2 pPMdg5mohrcyUUW7zAXxx3hX22WFZIoS2DlqaSV++jxA+0YFefPs7S4Hi2+1zY5i3AYF vzng== 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 4si6455839otq.38.2018.12.03.10.07.19 for ; Mon, 03 Dec 2018 10:07: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 A28C61682; Mon, 3 Dec 2018 10:07: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 CFF173F59C; Mon, 3 Dec 2018 10:07: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 , Fan Wu , James Morse Subject: [PATCH v7 12/25] ACPI / APEI: Switch NOTIFY_SEA to use the estatus queue Date: Mon, 3 Dec 2018 18:06:00 +0000 Message-Id: <20181203180613.228133-13-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 00fe4785e469..4b33fa562e32 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -765,7 +765,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(). @@ -905,7 +904,6 @@ static int ghes_estatus_queue_notified(struct list_head *rcu_list) return ret; } -#endif /* CONFIG_HAVE_ACPI_APEI_NMI */ #ifdef CONFIG_ACPI_APEI_SEA static LIST_HEAD(ghes_sea); @@ -916,16 +914,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_estatus_queue_notified(&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 Mon Dec 3 18:06:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710247 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 6B7191057 for ; Mon, 3 Dec 2018 18:07:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60EA92B47E for ; Mon, 3 Dec 2018 18:07:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 553B22B49D; Mon, 3 Dec 2018 18:07:35 +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 093F22B47E for ; Mon, 3 Dec 2018 18:07:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6D4246B6A81; Mon, 3 Dec 2018 13:07:25 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 684766B6A82; Mon, 3 Dec 2018 13:07: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 5261A6B6A83; Mon, 3 Dec 2018 13:07:25 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by kanga.kvack.org (Postfix) with ESMTP id 1DFC56B6A81 for ; Mon, 3 Dec 2018 13:07:25 -0500 (EST) Received: by mail-oi1-f200.google.com with SMTP id u63so6800129oie.17 for ; Mon, 03 Dec 2018 10:07: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=xBPdcCdKy7IgM0fyCHO8+ryv1fkn+Icc11ZQeY9VFPY=; b=RXbpre2htrUqujmvzxw2CYXVcEmkrmxvQJp7RL0MGTcKGrAAjKvaQqRb1ygmjyykQY cQFMJazbB2WlUQdO0rilJLfpRKJPl3xgTN2+6EHeNMAl05RbZkefZkn+ieutpYtcxSNm 3ugBewGk99MFHiRttR+HiNN+h+2uUnt9YT/91spMsnuGsi/A0Hp2zj7z/YX31Ig3MEuf Y6+b5TEXUSGkwSOmeh2Bae5no5i33Q4U+jSvrrJ6Vsk0AJP+I91Hqw00Hj12nxPBe4G2 s8B3QiIfQAL9eOMJmmNor81r5th/NyRoCODMmdxVaX1saQwt6nmKbWMgR9SoNn6e5tdO FdOg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWagEf7h2ijmjLS6btvZQWfvMhXjTfdOBD+QnUy6flWV0wsnH9Sa ClPuepEWdurowEH9t/aD+A1jfflIvOe0oyWWOI7+DHFZ+1MGPBj8rduTW5BtdcriPN5lcwrMI42 L0HBN+fGgN4AcbSN0RWOoFTxFgTsFk2e8N82dhQakOHXEyoJtNZTD+TUYGhR7x6Siww== X-Received: by 2002:a9d:1eea:: with SMTP id n97mr10061615otn.248.1543860444847; Mon, 03 Dec 2018 10:07:24 -0800 (PST) X-Google-Smtp-Source: AFSGD/VECdGtfKMfJglsxp5iVZlYLcuBN/HLOcwOrw0bwj4fWpoIon1S2JBMcNGXeDNSnI6ff30H X-Received: by 2002:a9d:1eea:: with SMTP id n97mr10061569otn.248.1543860443955; Mon, 03 Dec 2018 10:07:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860443; cv=none; d=google.com; s=arc-20160816; b=Lh9xik3SUks3RtGvrqmkVhRYmsaIqB0wCblY8cQifyL2PaGdinxyPoBxcdoasXfoYi 8fkb9vvxBZJROTqndedFUsOwOAP1CRJDZKgC69aOxBckMlzwh97RwZM5CsGGWHDjviyH LNN6RMuhIfAijNpFHCdsAcIRhds6VIUOee/4no0domVgG3s8ORFTnpL3ts628xpD6fEv EtQ+YsRx9zA9fq+OYc+5L/nBYkYoFyZ7dBygFKYB4chIimmDcGQ5zvqFPhoJDj7DwtRV wH455iGAMh3VraovB2RvygRJZ6cIyKbCz/rd+rxAVmsrqIrx1cVy6pCGbqm31X9owJ22 36/w== 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=xBPdcCdKy7IgM0fyCHO8+ryv1fkn+Icc11ZQeY9VFPY=; b=qFrG1XXL8nbZuyUvUVE5lXrS8OYcChJK6KsC7FU1VFq5FuYyu4LnFhHhU1Q6LjiMY7 WPX7n8ENLa2+Wp1oQiNJn3Wm2DOadMdAlxsj2g1+qDw+xjpY+FkRyuWn34iyMhCm0LEX PRH1hBV2DbxuOV4L0LaK6VTf8tBPYcb78ZQCvZPL3so8pAw2zopqCg8EQU7yODNmLkVi ucwVplXohRtHdr0SDprfpti+uUf9jzTMd77qIXrzIjwktQDwuIXpDkEsFLCXMPuDXD1l ZsXjR1Hl3tetkKDdZj4YXtA83Odi/AGJxOuJvqE4ANxdX5F2JnMN2dhxdKzCWTuHK5TD oh0A== 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 w16si6194093otl.261.2018.12.03.10.07.23 for ; Mon, 03 Dec 2018 10:07: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 81A67168F; Mon, 3 Dec 2018 10:07:23 -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 B0DCC3F59C; Mon, 3 Dec 2018 10:07:20 -0800 (PST) From: James Morse To: linux-acpi@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Borislav Petkov , Marc Zyngier , Christoffer Dall , Will Deacon , Catalin Marinas , Naoya Horiguchi , Rafael Wysocki , Len Brown , Tony Luck , Dongjiu Geng , Xie XiuQi , Fan Wu , James Morse Subject: [PATCH v7 13/25] KVM: arm/arm64: Add kvm_ras.h to collect kvm specific RAS plumbing Date: Mon, 3 Dec 2018 18:06:01 +0000 Message-Id: <20181203180613.228133-14-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP To split up APEIs in_nmi() path, the caller needs to always be in_nmi(). 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 7d9571f4ae3d..eeeb576b33d7 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -720,7 +720,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 5eca48bdb1a6..f322b66ef975 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" @@ -1703,7 +1703,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 Mon Dec 3 18:06:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710251 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7CF7A15A6 for ; Mon, 3 Dec 2018 18:07:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 72AE32B47E for ; Mon, 3 Dec 2018 18:07:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 670F12B49D; Mon, 3 Dec 2018 18:07:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B83242B47E for ; Mon, 3 Dec 2018 18:07:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 63C216B6A82; Mon, 3 Dec 2018 13:07:29 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 60FF66B6A83; Mon, 3 Dec 2018 13:07:29 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4FF1B6B6A84; Mon, 3 Dec 2018 13:07:29 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) by kanga.kvack.org (Postfix) with ESMTP id 24E826B6A82 for ; Mon, 3 Dec 2018 13:07:29 -0500 (EST) Received: by mail-oi1-f199.google.com with SMTP id p131so4557899oia.21 for ; Mon, 03 Dec 2018 10:07:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=cvoduY6NMUcDYyIXKzYuFn0uayj+J0WpGRWrEtFaJ/A=; b=dQz1ofCkceDOlXUVKdVr0hswI5FR7DqN6sGd5DPwl04QWEcHQB0mMSj8d49NdTdHxt pbD3+hyuM4vuZCRAkYNvADWOHUDaXu4CIuJF0ceGlyBuAT3AcxBCtXpaN0A8o+wIlVWp IZPfP0DhN7OYESfT7aNQMTPQvVJqOwhdD/HCwdPWwwmY96+oKjYMQycph/AxK4ocVfCm Ao0RKWLtDToGBtZ9QO3eKdE2XwmHfne5ETGjs9vIq9Rncc7t783pv3SLWCjhtXPNLCDe 4Fnmi7kVJr2MRX4q7zbEL2miLNo363usYoocFeTvNWnVeewsz5rG9yyuFRi74AyxNYeu MzkQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWa0Sz9u7cymswVtaRvq7TQ14aWu0podhfHA2QLtZGIXraNrlXtI 2m/1iMNDG5MwJP8OtoINlv3xz5tRxiTYvCUbOtKTNnBDN+I3uPL8sKuc9heOcsppdg7oK+9kp5r FxoAR1i2OFO5NrMUQD+QvYEiXAlSa50TKnDTZBaKTvWvRHtq+sG01kQYDZHxbYxsrig== X-Received: by 2002:a9d:3f34:: with SMTP id m49mr10229609otc.23.1543860448859; Mon, 03 Dec 2018 10:07:28 -0800 (PST) X-Google-Smtp-Source: AFSGD/XNuJKpObUVJu4gZ/UyOEkbkTl9JmF8+oReQ7EhFfisbxTKsInVfyIIkZU2SPKEk3ikjawy X-Received: by 2002:a9d:3f34:: with SMTP id m49mr10229570otc.23.1543860447829; Mon, 03 Dec 2018 10:07:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860447; cv=none; d=google.com; s=arc-20160816; b=qFhS9GcSeju1xpWNeAt8OgsGU248mID7LTHh3YFN6npr4cqdmQMPuxEb1jEND1eytu 9vvKQLHOaT716v7M53v+XTnYy++gzJRXvGBD9O4gDNDuUgxtoSKbiT0FrZpcm9xgn/WR qgfMdWVoAf/BKQsCCgYOp9QtYRPvJsUCOE5Dgp765nhYfaZ1N2X7NEMrJzRASoZiX2Qw MatznJ1RXDc56c8GFAXTX3QmGfPvp+ju5uUmBBm29w2EPooRQpfQMpB/OdS9VJJluF+1 TIrbJovZNLF7CsHfvnXh2eu2YKivNpRqjy2HPyTSpvOtxuzXRcz2qO/k/OSHTBJLCkZg HmvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=cvoduY6NMUcDYyIXKzYuFn0uayj+J0WpGRWrEtFaJ/A=; b=AxVdXMokQ4f7vywKiPRDYb8u5gJG0EltuIkTJjxCaH2kLGjSzkyrF4NUvcPnMLzbVW LAqfcsQLhZ8usbwTsR1POzP3VioAMJZCShTD1RsP7lk5HlLvlWOx+CCz1o1t+unblsgI Bhx6nmWsMQXcYT6Z5zMVk7TIeWaO9cLG5L6WFDMM+AuZWJea79GzREwjojSQNeRDoo/C O/OoY3MydZpbaaCo/pChPenL+4lq6iNJXhJuJIHQIqONk/0j3svRwpQJLrpndX1fUM4Q 83Evt2f6CbPh+F0TgePMAiCo7eQyItPe0MyRETWajMKQ2c5ZYF4kjaNEwKZT41SNOuzx LMiQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com Received: from foss.arm.com (usa-sjc-mx-foss1.foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id e126si6629442oig.75.2018.12.03.10.07.27 for ; Mon, 03 Dec 2018 10:07:27 -0800 (PST) Received-SPF: pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) client-ip=217.140.101.70; Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 3ECF0169E; Mon, 3 Dec 2018 10:07:27 -0800 (PST) Received: from eglon.cambridge.arm.com (eglon.cambridge.arm.com [10.1.196.105]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6E9973F59C; Mon, 3 Dec 2018 10:07:24 -0800 (PST) From: James Morse To: linux-acpi@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Borislav Petkov , Marc Zyngier , Christoffer Dall , Will Deacon , Catalin Marinas , Naoya Horiguchi , Rafael Wysocki , Len Brown , Tony Luck , Dongjiu Geng , Xie XiuQi , Fan Wu , James Morse Subject: [PATCH v7 14/25] arm64: KVM/mm: Move SEA handling behind a single 'claim' interface Date: Mon, 3 Dec 2018 18:06:02 +0000 Message-Id: <20181203180613.228133-15-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP To split up APEIs in_nmi() path, the caller needs to always be in_nmi(). Add a helper to do the work and claim the notification. When KVM or the arch code takes an exception that might be a RAS notification, it asks the APEI firmware-first code whether it wants to claim the exception. A future kernel-first mechanism may be queried afterwards, and claim the notification, otherwise we fall through to the existing default behaviour. The NOTIFY_SEA code was merged before considering multiple, possibly interacting, NMI-like notifications and the need to consider kernel first in the future. Make the 'claiming' behaviour explicit. Restructuring the APEI code to allow multiple NMI-like notifications means any notification that might interrupt interrupts-masked code must always be wrapped in nmi_enter()/nmi_exit(). This will allow APEI to use in_nmi() to use the right fixmap entries. Mask SError over this window to prevent an asynchronous RAS error arriving and tripping 'nmi_enter()'s BUG_ON(in_nmi()). Signed-off-by: James Morse Acked-by: Marc Zyngier Tested-by: Tyler Baicar Acked-by: Catalin Marinas --- Why does apei_claim_sea() take a pt_regs? This gets used later to take APEI by the hand through NMI->IRQ context, depending on what we interrupted. Changes since v6: * Moved the voice of the commit message. * moved arch_local_save_flags() below the !IS_ENABLED drop-out * Moved the dummy declaration into the if-ACPI part of the header instead of if-APEI. Changes since v4: * Made irqs-unmasked comment a lockdep assert. Changes since v3: * Removed spurious whitespace change * Updated comment in acpi.c to cover SError masking Changes since v2: * Added dummy definition for !ACPI and culled IS_ENABLED() checks. --- arch/arm64/include/asm/acpi.h | 4 +++- arch/arm64/include/asm/daifflags.h | 1 + arch/arm64/include/asm/kvm_ras.h | 16 ++++++++++++++- arch/arm64/kernel/acpi.c | 31 ++++++++++++++++++++++++++++++ arch/arm64/mm/fault.c | 24 +++++------------------ 5 files changed, 55 insertions(+), 21 deletions(-) diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h index 709208dfdc8b..4ed19b26ec1a 100644 --- a/arch/arm64/include/asm/acpi.h +++ b/arch/arm64/include/asm/acpi.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -99,9 +100,10 @@ static inline u32 get_acpi_id_for_cpu(unsigned int cpu) static inline void arch_fix_phys_package_id(int num, u32 slot) { } void __init acpi_init_cpus(void); - +int apei_claim_sea(struct pt_regs *regs); #else static inline void acpi_init_cpus(void) { } +static inline int apei_claim_sea(struct pt_regs *regs) { return -ENOENT; } #endif /* CONFIG_ACPI */ #ifdef CONFIG_ARM64_ACPI_PARKING_PROTOCOL diff --git a/arch/arm64/include/asm/daifflags.h b/arch/arm64/include/asm/daifflags.h index 8d91f2233135..fa90779fc752 100644 --- a/arch/arm64/include/asm/daifflags.h +++ b/arch/arm64/include/asm/daifflags.h @@ -20,6 +20,7 @@ #define DAIF_PROCCTX 0 #define DAIF_PROCCTX_NOIRQ PSR_I_BIT +#define DAIF_ERRCTX (PSR_I_BIT | PSR_A_BIT) /* mask/save/unmask/restore all exceptions, including interrupts. */ static inline void local_daif_mask(void) diff --git a/arch/arm64/include/asm/kvm_ras.h b/arch/arm64/include/asm/kvm_ras.h index 6096f0251812..8ac6ee77437c 100644 --- a/arch/arm64/include/asm/kvm_ras.h +++ b/arch/arm64/include/asm/kvm_ras.h @@ -4,8 +4,22 @@ #ifndef __ARM64_KVM_RAS_H__ #define __ARM64_KVM_RAS_H__ +#include +#include #include -int kvm_handle_guest_sea(phys_addr_t addr, unsigned int esr); +#include + +/* + * Was this synchronous external abort a RAS notification? + * Returns '0' for errors handled by some RAS subsystem, or -ENOENT. + */ +static inline int kvm_handle_guest_sea(phys_addr_t addr, unsigned int esr) +{ + /* apei_claim_sea(NULL) expects to mask interrupts itself */ + lockdep_assert_irqs_enabled(); + + return apei_claim_sea(NULL); +} #endif /* __ARM64_KVM_RAS_H__ */ diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c index 44e3c351e1ea..803f0494dd3e 100644 --- a/arch/arm64/kernel/acpi.c +++ b/arch/arm64/kernel/acpi.c @@ -27,8 +27,10 @@ #include #include +#include #include #include +#include #include #include @@ -256,3 +258,32 @@ pgprot_t __acpi_get_mem_attribute(phys_addr_t addr) return __pgprot(PROT_NORMAL_NC); return __pgprot(PROT_DEVICE_nGnRnE); } + +/* + * Claim Synchronous External Aborts as a firmware first notification. + * + * Used by KVM and the arch do_sea handler. + * @regs may be NULL when called from process context. + */ +int apei_claim_sea(struct pt_regs *regs) +{ + int err = -ENOENT; + unsigned long current_flags; + + if (!IS_ENABLED(CONFIG_ACPI_APEI_GHES)) + return err; + + current_flags = arch_local_save_flags(); + + /* + * SEA can interrupt SError, mask it and describe this as an NMI so + * that APEI defers the handling. + */ + local_daif_restore(DAIF_ERRCTX); + nmi_enter(); + err = ghes_notify_sea(); + nmi_exit(); + local_daif_restore(current_flags); + + return err; +} diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index eeeb576b33d7..956afc7d932a 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -18,6 +18,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -33,6 +34,7 @@ #include #include +#include #include #include #include @@ -46,8 +48,6 @@ #include #include -#include - struct fault_info { int (*fn)(unsigned long addr, unsigned int esr, struct pt_regs *regs); @@ -630,19 +630,10 @@ static int do_sea(unsigned long addr, unsigned int esr, struct pt_regs *regs) inf = esr_to_fault_info(esr); /* - * Synchronous aborts may interrupt code which had interrupts masked. - * Before calling out into the wider kernel tell the interested - * subsystems. + * Return value ignored as we rely on signal merging. + * Future patches will make this more robust. */ - if (IS_ENABLED(CONFIG_ACPI_APEI_SEA)) { - if (interrupts_enabled(regs)) - nmi_enter(); - - ghes_notify_sea(); - - if (interrupts_enabled(regs)) - nmi_exit(); - } + apei_claim_sea(regs); if (esr & ESR_ELx_FnV) siaddr = NULL; @@ -720,11 +711,6 @@ static const struct fault_info fault_info[] = { { do_bad, SIGKILL, SI_KERNEL, "unknown 63" }, }; -int kvm_handle_guest_sea(phys_addr_t addr, unsigned int esr) -{ - return ghes_notify_sea(); -} - asmlinkage void __exception do_mem_abort(unsigned long addr, unsigned int esr, struct pt_regs *regs) { From patchwork Mon Dec 3 18:06:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710257 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 3FF7C1057 for ; Mon, 3 Dec 2018 18:07:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34FF52B47E for ; Mon, 3 Dec 2018 18:07:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 288A22B495; Mon, 3 Dec 2018 18:07: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 8F0B02B47E for ; Mon, 3 Dec 2018 18:07:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43CD26B6A84; Mon, 3 Dec 2018 13:07:33 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3EE9C6B6A85; Mon, 3 Dec 2018 13:07:33 -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 2B5FA6B6A86; Mon, 3 Dec 2018 13:07:33 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by kanga.kvack.org (Postfix) with ESMTP id EF7E26B6A84 for ; Mon, 3 Dec 2018 13:07:32 -0500 (EST) Received: by mail-oi1-f200.google.com with SMTP id j13so8564488oii.8 for ; Mon, 03 Dec 2018 10:07:32 -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=Lk7Z0u07RFB1AXUDsGSy0KFoRuRRaLA70m1JekiZSS4=; b=qkJRQN6Is0+SIQO7qrf0NVdUVj+YPi3FM5HGICyO6E1H3k96MGbS3lM+aVLlq0xKv2 MGACh3p5gCHTGaeUOaSr/4ttnwNUBCEjkC6xpdCO5A4NBYmZUj+bc8PzjYz6riH1gGbh PduR+FKQRy1K+0QbvhRCcOUsdmGwEsy0lsx0jaccMiZp7M3FVXOgRfZnbPM+y3YLynki jSFtGa9ajBDnGqGBiJiaCWAP0whOnBUKLf/4Wby04SIKkL/6xWYie2zu3U43qsbsoWHr z8n1zSH4Cz3m5D38S9fb8NrC15VCGp53y23rcH4fDez0/bKQ11+AtuhPwgivUqdtILol MLgg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWbQ7C9groSuQiHwwW4nbW66rlYW7EzJyBQfShhVNL3gnsNzXLJN B/wNcW3pkV8toBGsCneTLWZkmE3pyZqLYYZ/e5hMVgro55OU+xao3T0Rqb+FZEv9z6xttgi+ulF hiCTgm9EoK+XDPoBPaeV5gDzZE15tnzDSEmUD3/J/+lf0HYbbFk2UNr5VcOOzJpHmPA== X-Received: by 2002:aca:e495:: with SMTP id b143mr9806440oih.286.1543860452669; Mon, 03 Dec 2018 10:07:32 -0800 (PST) X-Google-Smtp-Source: AFSGD/VB1cQJlGHJclmr3jd9lSI9ZWhexE/d3eR7QivkucK7u+EZRhL3qT0ca0aKnUK9FpWlD6mO X-Received: by 2002:aca:e495:: with SMTP id b143mr9806388oih.286.1543860451361; Mon, 03 Dec 2018 10:07:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860451; cv=none; d=google.com; s=arc-20160816; b=uk6C9kpJN1V81ATcUyuUQrvMasbrvGBfu8JECMxRM00x/GWun1qGBaABCYChaUgrGD DOMqb55eIfymQJMss3on1oV3rO6oEelnoMVEgx9rDBusvphHyDcfSzLdH7LtQCLVSphN VP717gqCFCeLsPdS90lwqxi8MtzPjVBhbGfPbwelIPLmmuonbjahU33+EAC1qDWtPd2F kcl7QLPGr3sUeVaWIvKbGesowRjtbSXIUUsZyQBj+GydoWIYbO8uYegEicFCGq6w30OR QDanHdzFHwIeWHJJ7B0MwA2HydI55OmKpUNm3sqIvn0BDlJBPch0gBXc5fYRi4aoz9H9 IldQ== 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=Lk7Z0u07RFB1AXUDsGSy0KFoRuRRaLA70m1JekiZSS4=; b=QRRHaggFkneWiev9PqI702CtZiWtveyhlFhuCIS4tDOjBr1Vzngya3p/EKRb2T7oMp HwvyAiWv7KxeaPlEbZI+Axwz4GbSDjUoR5P8c9R+PMfbCuLeTRAQruIa5GyLJNuMv0jA 1l4kWgGRh53AeNRW0TA7MplT30eNpdlNVxmMWoYU8K7+ghILfSdenioy4LXUGVHblWqs dmWVd54OkOu2QDTdSc/g//FeG/ivUxIXkBJGOMHSyVYQb5f+vixRJaYDD19taYywIGha eStrU0RaPZtwkD2wKHSFmWm/T2qgGorpTCSUyYNLXX8v5/kTAxZAwxsC4BDBBf5jHPlk i/aQ== 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 17si6644804oty.291.2018.12.03.10.07.31 for ; Mon, 03 Dec 2018 10:07:31 -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 D503C1713; Mon, 3 Dec 2018 10:07:30 -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 10F073F59C; Mon, 3 Dec 2018 10:07:27 -0800 (PST) From: James Morse To: linux-acpi@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Borislav Petkov , Marc Zyngier , Christoffer Dall , Will Deacon , Catalin Marinas , Naoya Horiguchi , Rafael Wysocki , Len Brown , Tony Luck , Dongjiu Geng , Xie XiuQi , Fan Wu , James Morse Subject: [PATCH v7 15/25] ACPI / APEI: Move locking to the notification helper Date: Mon, 3 Dec 2018 18:06:03 +0000 Message-Id: <20181203180613.228133-16-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 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 4b33fa562e32..30490eff7704 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; @@ -272,7 +271,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; @@ -280,10 +278,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; @@ -297,10 +293,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); } } } @@ -727,8 +721,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); } @@ -736,9 +733,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; @@ -749,14 +749,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; } @@ -906,6 +909,7 @@ static int ghes_estatus_queue_notified(struct list_head *rcu_list) } #ifdef CONFIG_ACPI_APEI_SEA +static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sea); static LIST_HEAD(ghes_sea); /* @@ -914,7 +918,13 @@ static LIST_HEAD(ghes_sea); */ int ghes_notify_sea(void) { - return ghes_estatus_queue_notified(&ghes_sea); + int rv; + + raw_spin_lock(&ghes_notify_lock_sea); + rv = ghes_estatus_queue_notified(&ghes_sea); + raw_spin_unlock(&ghes_notify_lock_sea); + + return rv; } static void ghes_sea_add(struct ghes *ghes) @@ -943,6 +953,7 @@ static inline void ghes_sea_remove(struct ghes *ghes) { } */ static atomic_t ghes_in_nmi = ATOMIC_INIT(0); +static DEFINE_RAW_SPINLOCK(ghes_notify_lock_nmi); static LIST_HEAD(ghes_nmi); static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) @@ -952,8 +963,10 @@ static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) if (!atomic_add_unless(&ghes_in_nmi, 1, 1)) return ret; + raw_spin_lock(&ghes_notify_lock_nmi); if (!ghes_estatus_queue_notified(&ghes_nmi)) 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 Mon Dec 3 18:06:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710263 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 F0F031057 for ; Mon, 3 Dec 2018 18:07:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5FB92B47E for ; Mon, 3 Dec 2018 18:07:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D99FF2B495; Mon, 3 Dec 2018 18:07: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 3F16F2B47E for ; Mon, 3 Dec 2018 18:07:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5C5A06B6A86; Mon, 3 Dec 2018 13:07:36 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 526606B6A87; Mon, 3 Dec 2018 13:07:36 -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 3ED5D6B6A88; Mon, 3 Dec 2018 13:07:36 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) by kanga.kvack.org (Postfix) with ESMTP id 0A75E6B6A86 for ; Mon, 3 Dec 2018 13:07:36 -0500 (EST) Received: by mail-ot1-f71.google.com with SMTP id j18so5866443oth.11 for ; Mon, 03 Dec 2018 10:07: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=bBlvTiFpt5mSFqNPhoI7cPO8rL4wf6nBDu/9DNR5+ow=; b=c8Kw8tKgT+9tWiDNwX5F0nEVEHVsERBDhpf6I5thXDxTPTp/IOKtz2GtuRjZB4MuZW N29o2e1teZ+04Ask3b2SnZ94esdOa6fyih2wlUfgB4maTr1y6ZSoSEj1AIcPJ8AMCbKx O8OJCbWNheTzngQE7DqvSfEjYSCnyC8ICgDmNZBcsXKZ+ajA9a9qoUCOBSvkR4psC9bP EvykYEaqeNHp78LKLznJixW9/WJuvu+Et2V0/2+yTme9aVctqJnW6uhVgiSknv1mUWvf 2zzVCCfbjRH+x6iAGhUX0fjOt+oR14tI7SIpB1aVTknKVkPXVrJ71jIJ98tLRoHocYU7 XxVg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWZOcDkwpNuZ4vpQqdNhAMvaNpWefSh5n51dz2Lc0TnBlD3UFr+J DyK2syT08pHOYSEVgJYbxV06kJfJDV9w16D6C59TbHHxJLEXkNw8AZt7V5GDm34Yg992ljimQHl I5/TkFr1ZbwMkz/2cmzt0kNWTKQnI5AFYmhqsvDoPPo0pWI1qUvoFaXSq+HXDolGJNA== X-Received: by 2002:aca:5e0b:: with SMTP id s11mr11087861oib.62.1543860455786; Mon, 03 Dec 2018 10:07:35 -0800 (PST) X-Google-Smtp-Source: AFSGD/WcxAcqMkrAhyQD3m/km359Fsy9ueknIIFRxUROcd5lK0754FM4MnT8B1e2Jn1yLxe2B2fh X-Received: by 2002:aca:5e0b:: with SMTP id s11mr11087829oib.62.1543860454829; Mon, 03 Dec 2018 10:07:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860454; cv=none; d=google.com; s=arc-20160816; b=IgPq5MY+8Y25N8Y+pWexP1kP4owBb0vWSxOdj3FFYvgkIqGX3Ampuajg/Y2krE619C 8HhZOwu0OENg0OUIRARCLSka1sH7KabFNdQyEZ2QMsXGBAzJf7E0cJQREFtZVKgBUmsQ N4AoGDgBJFPGqGAN6UElza1pgTkymitM3bBo4+pCmrWBYLGg6kxxBz0o3sptr4b6Fe+b R9Jx5sgbrK9Nf7L11e616r3V6j/cA9sIHLAdP85S9R6M/+09F7lIKeSd/4WP0/lCmeie RIdYkRqVw4cc5KEEUfOSCDFUg0+DR1dLTyo5x9CZVVDPKN7RXJc5sveKpmKlkiNVZDtc RIRw== 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=bBlvTiFpt5mSFqNPhoI7cPO8rL4wf6nBDu/9DNR5+ow=; b=pa+wDwMckS+kdVqVVFtyToxJLwNX9uUAKHd6jMovsChwD47ciMcaHqcE5WJYK162wW zf0bg2oNNsBlNWrYNZ0Y2SvxxWNYgBqqRPrhGnn11CE/xq4WUhTiFb5Mz129tfGbfuM2 8/UgL7BbUFfxZtjjHi5/SY0j2CiKH20B+3sOKVZnexCg5IgHOGEMFDuT5L/YwM7BwUjv 8t/QiKXxdqW+Kue3kJy24T/KPWYO2MRO48dx1Uo8uhXnO4Q0zGgjDxLnRGLWscecseQ2 EoAXhx8DgHGH+MuJ3S8XXDTfl9R6hfUVqkILM2o7sNzdDAemQ+XgiqYgHY5/OEfzDfUv FbZg== 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 4si5898124oiz.163.2018.12.03.10.07.34 for ; Mon, 03 Dec 2018 10:07:34 -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 583751682; Mon, 3 Dec 2018 10:07: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 8834F3F59C; Mon, 3 Dec 2018 10:07: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 , Fan Wu , James Morse Subject: [PATCH v7 16/25] ACPI / APEI: Let the notification helper specify the fixmap slot Date: Mon, 3 Dec 2018 18:06:04 +0000 Message-Id: <20181203180613.228133-17-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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. --- drivers/acpi/apei/ghes.c | 79 +++++++++++++++------------------------- 1 file changed, 30 insertions(+), 49 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 30490eff7704..b5c31f65a1c0 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, int 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(int fixmap_idx, void __iomem *vaddr) { - 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) @@ -268,20 +255,15 @@ 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, int 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) @@ -291,15 +273,12 @@ 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(fixmap_idx, vaddr); } } -static int ghes_read_estatus(struct ghes *ghes, u64 *buf_paddr) +static int ghes_read_estatus(struct ghes *ghes, u64 *buf_paddr, int fixmap_idx) + { struct acpi_hest_generic *g = ghes->generic; u32 len; @@ -317,7 +296,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; @@ -333,7 +312,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; @@ -346,12 +325,13 @@ 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, int fixmap_idx) { ghes->estatus->block_status = 0; if (buf_paddr) ghes_copy_tofrom_phys(ghes->estatus, buf_paddr, - sizeof(ghes->estatus->block_status), 0); + sizeof(ghes->estatus->block_status), 0, + fixmap_idx); } static void ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata, int sev) @@ -673,7 +653,7 @@ 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; @@ -688,7 +668,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); if (rc == -ENOENT) return rc; @@ -864,13 +844,13 @@ static void __process_error(struct ghes *ghes) #endif } -static int _in_nmi_notify_one(struct ghes *ghes) +static int _in_nmi_notify_one(struct ghes *ghes, int 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; } @@ -881,7 +861,7 @@ static int _in_nmi_notify_one(struct ghes *ghes) } __process_error(ghes); - ghes_clear_estatus(ghes, buf_paddr); + ghes_clear_estatus(ghes, buf_paddr, fixmap_idx); if (is_hest_type_generic_v2(ghes) && ghes_ack_error(ghes->generic_v2)) pr_warn_ratelimited(FW_WARN GHES_PFX @@ -890,14 +870,15 @@ static int _in_nmi_notify_one(struct ghes *ghes) return 0; } -static int ghes_estatus_queue_notified(struct list_head *rcu_list) +static int ghes_estatus_queue_notified(struct list_head *rcu_list, + int fixmap_idx) { int ret = -ENOENT; struct ghes *ghes; rcu_read_lock(); list_for_each_entry_rcu(ghes, rcu_list, list) { - if (!_in_nmi_notify_one(ghes)) + if (!_in_nmi_notify_one(ghes, fixmap_idx)) ret = 0; } rcu_read_unlock(); @@ -921,7 +902,7 @@ int ghes_notify_sea(void) int rv; raw_spin_lock(&ghes_notify_lock_sea); - rv = ghes_estatus_queue_notified(&ghes_sea); + rv = ghes_estatus_queue_notified(&ghes_sea, FIX_APEI_GHES_NMI); raw_spin_unlock(&ghes_notify_lock_sea); return rv; @@ -964,7 +945,7 @@ static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) return ret; raw_spin_lock(&ghes_notify_lock_nmi); - if (!ghes_estatus_queue_notified(&ghes_nmi)) + if (!ghes_estatus_queue_notified(&ghes_nmi, FIX_APEI_GHES_NMI)) ret = NMI_HANDLED; raw_spin_unlock(&ghes_notify_lock_nmi); From patchwork Mon Dec 3 18:06:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710269 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 46B0818BC for ; Mon, 3 Dec 2018 18:07:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B3B32B47E for ; Mon, 3 Dec 2018 18:07:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FA162B495; Mon, 3 Dec 2018 18:07:53 +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 904C52B487 for ; Mon, 3 Dec 2018 18:07:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B19D56B6A87; Mon, 3 Dec 2018 13:07:39 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id ACB556B6A88; Mon, 3 Dec 2018 13:07:39 -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 9B92D6B6A89; Mon, 3 Dec 2018 13:07:39 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by kanga.kvack.org (Postfix) with ESMTP id 6CF156B6A87 for ; Mon, 3 Dec 2018 13:07:39 -0500 (EST) Received: by mail-ot1-f69.google.com with SMTP id d5so3847689otl.21 for ; Mon, 03 Dec 2018 10:07: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=hg9/PBkd/JojkmEyrb+e6z1c3DIezwsNzyf9guMbWPs=; b=R+OJWCARQ6rl8+MSqmF9TLE484E9oIeJ5goBA3CcQor9JVZ+WrCXnjVNM7yg9vytT/ 2zzKklFqPkjX14sO+RlTM5Or+biCyai/577F8JqSDqHZi0gf3pQbNfGkbH/faKvGAdWu DXVdu9N5J09ZZjcjC7A8XW0f7LADQpRA+LBrgiY6WH2SOWFf7/qKuMVpU907Mu34Cict ai1jHJks2voX3kDQZQ+8cViBmdJRYcGksLewMnhaI6eQO8fEPZ5rBqDaMmWHTjSZ0yOv +xWgQw2tEZhjFadcvJ+YOBUVM9EbW4FvtHj344Xog1XSQgsP+OQKCwQdnrMAVPJULrw2 Z8uw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWZuMLr09lLMPvQ03LtBClg7oD+4wS4LsibO2RMA9kGHUmSXfuMB avog2GwxhslytIfwPduIoYkZUGC89LR8hbko1+wkAJG76ucR9pe+KOX6AUaO3usMBykV/2R4ucg K3YG/EY1JwO8Y8n0f9i6fqNQmknM8zv/r5qyZUwwzz7dXi5N0yyt2n7CfXAaXWOXWeA== X-Received: by 2002:a9d:5e8c:: with SMTP id f12mr11409398otl.343.1543860459160; Mon, 03 Dec 2018 10:07:39 -0800 (PST) X-Google-Smtp-Source: AFSGD/UjY8ZryI31W4m1R8a5Kfbwq4gOSH44bOg4ah9Y5VlIsdQimZ6T9hN+0lOX1r08KGGb97Bk X-Received: by 2002:a9d:5e8c:: with SMTP id f12mr11409354otl.343.1543860458360; Mon, 03 Dec 2018 10:07:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860458; cv=none; d=google.com; s=arc-20160816; b=NCkSe6ow5ZvmPLM3Dtm+Z2dXSkw0AsfO0Wu8pnnPzPLnpfzTMmhK5qLSoTMdUEGEoq nmJsnGG/LbnvvAEwPXMeZ9kwZqAukrOVktvJKDRXYmAFvd5KXrkKfkxyRQTEg3VDblFK AQH/klpubGCzo4JhBqDrx6lvyci5HCqKXvIeeN4LHwR+pvrQBjev2u83J5VUkDZ2sJvx Flc+6XyrSqNWswSwN0T72y7+4NbLeJzs/v4tDrC0Meow37xIK8d4oSYDu+2rH50LN0SF MKQ/uV0oDPR7XDoNwtuelEVjg6itacmelx3z6WLu6pSY1I4ClV8Nsnr1Je1C9VnQ+N4v yeTQ== 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=hg9/PBkd/JojkmEyrb+e6z1c3DIezwsNzyf9guMbWPs=; b=eMTekd4AM/eSJbmaG7teUfDNXuPkSGuT467hkD+YF/fmqHI5txI7M4pXfnROfxipkN 6+71vL4HSAl1lmLUNnGYSdUCUdQdUSxMvLAewwzT8GPwPt2clSJ/GyrRHK1S0HXfXtYR aslGiNjFPe9ji1B2wXMCN3ilwv6RWlHNL59H381APaVqFvrL+XPyuLmQTLocZIuSUdUO TV8aZc0cJ4qkumpbw0UembAGV9KUej+tL4fcVrSv3iNr2WpkplWMUE6S14/QUAX/Fpqx /r+/V/SM90o9pDHsorSCCex48KaQB/WaEgfIvFTbkjOzyvIhM8rdNcLWX640Ui0je4tR gmiQ== 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 y203si5763511oie.110.2018.12.03.10.07.38 for ; Mon, 03 Dec 2018 10:07: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 D35571993; Mon, 3 Dec 2018 10:07: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 0F40A3F59C; Mon, 3 Dec 2018 10:07: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 , Fan Wu , James Morse Subject: [PATCH v7 17/25] ACPI / APEI: Pass ghes and estatus separately to avoid a later copy Date: Mon, 3 Dec 2018 18:06:05 +0000 Message-Id: <20181203180613.228133-18-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 | 84 +++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index b5c31f65a1c0..b70f5fd962cc 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -277,8 +277,9 @@ static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len, } } -static int ghes_read_estatus(struct ghes *ghes, u64 *buf_paddr, int fixmap_idx) - +static int ghes_read_estatus(struct ghes *ghes, + struct acpi_hest_generic_status *estatus, + u64 *buf_paddr, int fixmap_idx) { struct acpi_hest_generic *g = ghes->generic; u32 len; @@ -295,25 +296,25 @@ static int ghes_read_estatus(struct ghes *ghes, u64 *buf_paddr, int fixmap_idx) 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; @@ -325,12 +326,13 @@ static int ghes_read_estatus(struct ghes *ghes, u64 *buf_paddr, int fixmap_idx) return rc; } -static void ghes_clear_estatus(struct ghes *ghes, u64 buf_paddr, int fixmap_idx) +static void ghes_clear_estatus(struct acpi_hest_generic_status *estatus, + u64 buf_paddr, int fixmap_idx) { - ghes->estatus->block_status = 0; + estatus->block_status = 0; if (buf_paddr) - 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); } @@ -638,9 +640,10 @@ 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, + struct acpi_hest_generic_status *estatus) { - __ghes_print_estatus(KERN_EMERG, ghes->generic, ghes->estatus); + __ghes_print_estatus(KERN_EMERG, ghes->generic, estatus); /* reboot to log the error! */ if (!panic_timeout) @@ -650,25 +653,25 @@ static void __ghes_panic(struct ghes *ghes) 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); - } + if (ghes_severity(estatus->error_severity) >= GHES_SEV_PANIC) + __ghes_panic(ghes, estatus); - 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(estatus, buf_paddr, FIX_APEI_GHES_IRQ); if (rc == -ENOENT) return rc; @@ -819,17 +822,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); @@ -839,29 +845,29 @@ 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 _in_nmi_notify_one(struct ghes *ghes, int 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(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); + __ghes_panic(ghes, estatus); } - __process_error(ghes); - ghes_clear_estatus(ghes, buf_paddr, fixmap_idx); + __process_error(ghes, estatus); + ghes_clear_estatus(estatus, buf_paddr, fixmap_idx); if (is_hest_type_generic_v2(ghes) && ghes_ack_error(ghes->generic_v2)) pr_warn_ratelimited(FW_WARN GHES_PFX From patchwork Mon Dec 3 18:06:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710273 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 849B718BC for ; Mon, 3 Dec 2018 18:07:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 795D92B47E for ; Mon, 3 Dec 2018 18:07:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6C8942B495; Mon, 3 Dec 2018 18:07:57 +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 F3EBA2B487 for ; Mon, 3 Dec 2018 18:07:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EC44F6B6A88; Mon, 3 Dec 2018 13:07:42 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E73C36B6A89; Mon, 3 Dec 2018 13:07: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 D69646B6A8A; Mon, 3 Dec 2018 13:07:42 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) by kanga.kvack.org (Postfix) with ESMTP id A96786B6A88 for ; Mon, 3 Dec 2018 13:07:42 -0500 (EST) Received: by mail-oi1-f197.google.com with SMTP id j13so8564864oii.8 for ; Mon, 03 Dec 2018 10:07: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=i8kqVEny1BxLFODzbCS4OoIldxl/VAf8AelIhGS7wlY=; b=Evb5EopcpoCj2AD7p7AzIPYBDUwOLX6ZuKaUo2LHtubdXaGjIMMQOG1xZ0C7mWB2md ld0r1h3dP4zoUsmLqXs6Crr9M1OVXX6QktW+37ECyv3rT/ayTOCnnZrjLL1Y5UIDX30K QRsWHXdWUPg5nUw1ny5E7O3h5DUGzKTkr4SmPupv5AwlDgy+IqbgXR9jOrlY5vdytnmf DBEAWV2rhvGasYH97VLLchrMgjH047+t16JsQflSfjbCpjyFX1GU9kHsocWjwbEqykho rqjM/dJvuZvdcQSiTx8H6xmNQu7dVi12Mb40YrIWl7Ghm+jkN0fZt9OIClNmUSxfrDxD M4Vw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWaL7MQlEum+c+2X6Ki5tPYGPdbwmGUL7dlY5S8NdTY9thdDMi+V RKrD3ZiKZxBusWsBWChwnPI0R4dKnQ/UgQKqfeECgyaM/Q0/qMtP3ob/NvLkbt7XscPn91H7i/u txs+dOUNV/gpZBfZVb+JwQsc5HfjRDBlXuoNlzyPPWyEa8MQTdKzx7IVlKC08Q8UsdA== X-Received: by 2002:a9d:2da2:: with SMTP id g31mr11323394otb.310.1543860462430; Mon, 03 Dec 2018 10:07:42 -0800 (PST) X-Google-Smtp-Source: AFSGD/XSKXDgHDyl0/fkq0mH3ToWvrnpoyGBCDol+g52eMIzg2s8J3Etib67V7MsYWSrVeZjaYgH X-Received: by 2002:a9d:2da2:: with SMTP id g31mr11323365otb.310.1543860461711; Mon, 03 Dec 2018 10:07:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860461; cv=none; d=google.com; s=arc-20160816; b=h7FuEPBwYE2hg7UYq+UCQns3/i1uV62sP1IJfaU0zdh52UZbuq4nfuw97kxj6ZLsY4 818CzBkdjynNi/IvIHXDJxqz+5nql2aioa4TsbKSsSUsXa4p7VunYq2dUajw6vaU5Epj 5HlI09Cf+p3UFG/GVZeRIpjeAa1a+0l6upa8QitXypwgMkomDM0FO30viqoRus0f5aYH bwmFho/GWd3DzH9ZtqMG9wxTnmeoFqOEguV0ngxNEwckc8dl3yzhWFFquMZvAktqbVLc JOJ/F2P5V7dUsS+PmB+G2KJZlJte26iMVdunh1eKw/qMkeXlntl7H31COKn3QbDEpAzp S3yA== 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=i8kqVEny1BxLFODzbCS4OoIldxl/VAf8AelIhGS7wlY=; b=Z5LX54Xtb8TV2ftbY5hbYbE0Awa3qixV/9ykiS4fdXreUXsa+SjSjyLqbDXqvqQFkh cJB6GQnRcLvaAO+cuxmq3F5UlsCYUtyQzwEpFC0u/s4hQ1A/G/A2L8f6oflzEIHGBXJI btTDKvTMGvb6yIoIpvw0xiiGw8JCHKxj0kAX8qjOiwCYUHG8JVtFSmHtDyb0bFumWnD2 p21Jw3dLpo/BE7mwsTtzOy76RKbdwE/zJonf2+6BtcrM+ZwKr5QlSVsDXHtpQ/SzwJJu LH1XFmRPJUQDqjjUOaJQPaYY5CJX3hYG6Yjzw684L/bLFO10Q6orqQwsQNYMOcfZjJQw x47A== 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 y23si7283647otj.129.2018.12.03.10.07.41 for ; Mon, 03 Dec 2018 10:07:41 -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 46A07169E; Mon, 3 Dec 2018 10:07: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 76E263F59C; Mon, 3 Dec 2018 10:07: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 , Fan Wu , James Morse Subject: [PATCH v7 18/25] ACPI / APEI: Split ghes_read_estatus() to allow a peek at the CPER length Date: Mon, 3 Dec 2018 18:06:06 +0000 Message-Id: <20181203180613.228133-19-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 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 | 59 ++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index b70f5fd962cc..07a12aac4c1a 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -277,12 +277,12 @@ static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len, } } -static int ghes_read_estatus(struct ghes *ghes, - struct acpi_hest_generic_status *estatus, - u64 *buf_paddr, int fixmap_idx) +/* Read the CPER block and returning its address, and header in estatus. */ +static int __ghes_peek_estatus(struct ghes *ghes, int fixmap_idx, + struct acpi_hest_generic_status *estatus, + u64 *buf_paddr) { struct acpi_hest_generic *g = ghes->generic; - u32 len; int rc; rc = apei_read(buf_paddr, &g->error_status_address); @@ -303,29 +303,64 @@ static int ghes_read_estatus(struct ghes *ghes, return -ENOENT; } - rc = -EIO; - len = cper_estatus_len(estatus); + return 0; +} + +/* 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); + int rc = -EIO; + 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) pr_warn_ratelimited(FW_WARN GHES_PFX - "Failed to read error status block!\n"); + "Invalid Error status block!\n"); return rc; } +static int __ghes_read_estatus(struct acpi_hest_generic_status *estatus, + u64 buf_paddr, size_t buf_len, + int fixmap_idx) +{ + 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"); + return -EIO; + } + + return 0; +} + +static int ghes_read_estatus(struct ghes *ghes, + struct acpi_hest_generic_status *estatus, + u64 *buf_paddr, int fixmap_idx) +{ + int rc; + + rc = __ghes_peek_estatus(ghes, fixmap_idx, estatus, buf_paddr); + if (rc) + return rc; + + rc = __ghes_check_estatus(ghes, estatus); + if (rc) + return rc; + + return __ghes_read_estatus(estatus, *buf_paddr, + cper_estatus_len(estatus), fixmap_idx); +} + static void ghes_clear_estatus(struct acpi_hest_generic_status *estatus, u64 buf_paddr, int fixmap_idx) { From patchwork Mon Dec 3 18:06:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710277 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 471EF1057 for ; Mon, 3 Dec 2018 18:08:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C9172B47E for ; Mon, 3 Dec 2018 18:08:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 30A102B49D; Mon, 3 Dec 2018 18:08:02 +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 AF0992B47E for ; Mon, 3 Dec 2018 18:08:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB3616B6A8A; Mon, 3 Dec 2018 13:07:46 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D8ED96B6A8B; Mon, 3 Dec 2018 13:07:46 -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 C553F6B6A8C; Mon, 3 Dec 2018 13:07:46 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by kanga.kvack.org (Postfix) with ESMTP id 92B036B6A8A for ; Mon, 3 Dec 2018 13:07:46 -0500 (EST) Received: by mail-ot1-f70.google.com with SMTP id w6so5968783otb.6 for ; Mon, 03 Dec 2018 10:07: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=h30DZ5QsoanOwOfyV3bhyCWkTrBNg0fy/1dD74I5bNY=; b=jBQROFopR33yR97qHJggnph1K/mKXojksm9tEWvre4CMMAgDN+utBeI4JQ9UKXNGvx udwG4HVemZbWCZm7te0rl7ZdYMOZ7h/55cLaeF78AU/HImYF3NDYhFqEl1sWYtH3hwIt rwwKxOBQJGm1MkgWG2XsZmhj8cxq6yp7ZcqD7UTs0AkgR5NPmQIGfA6SeNelgMs2aTaE Wc6mMgkaYEAN/Hgvy91npDGl7Jta9/DGBwVAH5PRjGVfBKa5dh/2InjJtHdLHv0KY3Cm ylCppNDymfxvVpoXj7UKd6W+dgQG0ALqZSNH2t3gxRp3VaI3B4psR8nUXomt1DmXKFFa docw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWYPwrIfftbgjJgmYSvEn26QjKNOG5Zp4DLNoGJydAEwo5egN5iZ UlNajYvQPWQoP64cxODT6RFuanOQohdQKKO8//vHOL6nyPlYsG2GeRPGNo6TdP7XBQdcW+Dha2q wUkxsUw3JJczXo1afJTE/gGsW/vGiObQUvgm/k2RogadLlXVBBZGkw7jqkeiHiBEuVw== X-Received: by 2002:aca:e84d:: with SMTP id f74mr11089357oih.34.1543860466369; Mon, 03 Dec 2018 10:07:46 -0800 (PST) X-Google-Smtp-Source: AFSGD/U/fMjqSQmZE3yd1rEdwxEwTUEuW9EREuQHO+IbiMGAJFrDfPkWUK9QYGeAxbXzZVD5glXz X-Received: by 2002:aca:e84d:: with SMTP id f74mr11089312oih.34.1543860465442; Mon, 03 Dec 2018 10:07:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860465; cv=none; d=google.com; s=arc-20160816; b=eAcYy26QQXwWQzbD6XElwm7PklyzqiMsyFPT2lJ5MjBfHhQM9MoKpbY7kcYreiQtxe yQELzjhVU21h8R0mASuQ3Ime+ay40rHzgSpBjn02o/pWaf519Z9Jeaje3mQxPJR1sV/y noq0+qQllpD/PrWMHbS0plobfM1vVgmuCMWflVucA5xcdk08MhKPwNPi2oNFP+8KS94c Ufj4SFm290JNsNCaFweO95L0JIoWSp5EwfeyA9dleep0ghzp+6CkfZ9NDgI7fRWec2NY R7Y8OWQj9gzhyrGHtHCZl5o5QMvp5RqRkcgrh0YcMdEALvynfLhu+1PE6DF44iXWussg f9PA== 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=h30DZ5QsoanOwOfyV3bhyCWkTrBNg0fy/1dD74I5bNY=; b=FYdOqptfI1C2EQcF/R0avvXBOz9cERPwVx2QXEkKrA6wiiWSbpp7o3gnObdIxB0Q68 d9IlGiMS7H4z5No0KWTYXTft5njXQUbGRvZHwpdQ39WpdmQvYqpEzC3/iVWrYe6KLmtN JgXg/3VS7VDtbv9AWULVh8OG0hqI7jYxuKVDZ/Bjrzg3zWsS4Db9WOFbjHUp11R73CES RdV6gpSdie069TdWQHAWsOpcLGLcvYgVJ7x2t5UkzSyamxEKW1v7HFEtmCJpGHIcSWXe itfR/kCj0b0Nf1CrPFmJJ1LrkyzrDLvyme71dgeEByf0XmlJqCFn2+agG8v2X5Vi3nH+ aHmg== 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 97si6695626otb.98.2018.12.03.10.07.45 for ; Mon, 03 Dec 2018 10:07: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 CE3DD1713; Mon, 3 Dec 2018 10:07: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 09A853F59C; Mon, 3 Dec 2018 10:07: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 , Fan Wu , James Morse Subject: [PATCH v7 19/25] ACPI / APEI: Only use queued estatus entry during _in_nmi_notify_one() Date: Mon, 3 Dec 2018 18:06:07 +0000 Message-Id: <20181203180613.228133-20-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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_notify_one() to stage the estatus data, before __process_error() copys it into a queued estatus entry. Merge __process_error()s work into _in_nmi_notify_one() 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 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, Reviewed-by: Borislav Petkov --- drivers/acpi/apei/ghes.c | 59 ++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 07a12aac4c1a..849da0d43a21 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -856,43 +856,43 @@ 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 _in_nmi_notify_one(struct ghes *ghes, int 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, fixmap_idx, &tmp_header, &buf_paddr); + if (rc) { + ghes_clear_estatus(&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(&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 _in_nmi_notify_one(struct ghes *ghes, int 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, len, fixmap_idx)) { ghes_clear_estatus(estatus, buf_paddr, fixmap_idx); - return -ENOENT; + rc = -ENOENT; + goto no_work; } sev = ghes_severity(estatus->error_severity); @@ -901,14 +901,25 @@ static int _in_nmi_notify_one(struct ghes *ghes, int fixmap_idx) __ghes_panic(ghes, estatus); } - __process_error(ghes, estatus); ghes_clear_estatus(estatus, buf_paddr, fixmap_idx); if (is_hest_type_generic_v2(ghes) && ghes_ack_error(ghes->generic_v2)) pr_warn_ratelimited(FW_WARN GHES_PFX "Failed to ack error status block!\n"); - 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_estatus_queue_notified(struct list_head *rcu_list, From patchwork Mon Dec 3 18:06:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710281 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 EB98C15A6 for ; Mon, 3 Dec 2018 18:08:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1BEF2B495 for ; Mon, 3 Dec 2018 18:08:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D66712B49D; Mon, 3 Dec 2018 18:08:06 +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 52C732B47E for ; Mon, 3 Dec 2018 18:08:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D8F4F6B6A8C; Mon, 3 Dec 2018 13:07:49 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CEE926B6A8D; Mon, 3 Dec 2018 13:07: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 BDD1D6B6A8E; Mon, 3 Dec 2018 13:07:49 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f69.google.com (mail-ot1-f69.google.com [209.85.210.69]) by kanga.kvack.org (Postfix) with ESMTP id 8E6C36B6A8C for ; Mon, 3 Dec 2018 13:07:49 -0500 (EST) Received: by mail-ot1-f69.google.com with SMTP id q23so5964608otn.3 for ; Mon, 03 Dec 2018 10:07: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=JjFMpXuQdPX46XYZAzvi+XQG8d/WswNsuRYargo7X0o=; b=NfwFhAOLHU3Pg7bQasICU9Y43WcafyZ8UsbYH7IQK2tmJSElfjx7goNKuQVo0JaD7u JxkppuMSQG+lccxizV4+0SO1ELvpwxZQWk+jXUumEVxYNqlrAbs4iL9OiWShfrL3s3+w E9LSRrtBP/LHvFiGTg+E3kRcPeqJj4PN41WxtPvIrW7xZmxqeMkE6hRBVRf0oo27tmUP k2qRB6X6i2eUy4Ef1b2Wlq0Cj37A2QPpTFpsS6rsgz4dYhdAOfUZgjHFvVAzdk7d6CbA 18HvnS2gMWri2NUZcP5CRt6wsUHBJOwDFbiB+Q1NkTUp7czu1Wo+b8/jlYXRizuUVBpK SOpg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWZGd2v3dGtzL9QLnV9aV8VvVvc/WrhyiROdHHq2CaNn5Px4+0zF 2GhMqOi92VW+Wl2BcRM2UDzTH4ys2LaT/MuJG838YOGSVVZxYFtc2VNYVTh/J0FoybrT0uDOoF6 4keHrUw34XdBtJmIsgiSzxqG+A05NM//a6uUxzYXdnAB9Hj/PIIU9KTkqlpGr1e2QHg== X-Received: by 2002:aca:2807:: with SMTP id 7mr10770282oix.7.1543860469343; Mon, 03 Dec 2018 10:07:49 -0800 (PST) X-Google-Smtp-Source: AFSGD/UWDTQjn7ffEQ66dWd0BAFIeXBivKDCPLs6DEjM7u7seU/fXdcdg6MdPCg7O6WqJnPjlOja X-Received: by 2002:aca:2807:: with SMTP id 7mr10770253oix.7.1543860468687; Mon, 03 Dec 2018 10:07:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860468; cv=none; d=google.com; s=arc-20160816; b=qhEaAgvenYDHJFadt1Mo0ORtnPLHFBSqrC2dmK2lYSHnJ+RPxjejugT0a3S418yS2w 1OEieoTegZsQkmu+gOLHiSWSwTGkgt513qfXBwxvUVrOkL827srWQeikyPxqG77pyzYu IDLSOMRtshz2AE+yXveufQcgwTsthOCgpIKuOaQXVevLXnlxehr65xqDTxZX9QFlCOvE iXw1k84eQCj90WIPB8EvvcCGxOsyYPRRJbzeGQAD2I5uohOyc5B81TvKM94b/vNmjClU GO27AxcG2a2ZrxWj7S8mTmBKx9YrultlFKQh4XR4+25I+qBc90GyElbHuGB+V8HPlICW /O2Q== 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=JjFMpXuQdPX46XYZAzvi+XQG8d/WswNsuRYargo7X0o=; b=sdllIGKtGjKfYrTN3vTxZjewE3w2PBzug55TzrnKENwgDZPh4KIytAQLJbX0yOfeg8 3tLi49dxMGi5ksulJ837BDeAvFaondXNqukGGzjNdXHmoGqZcIWmlhS2t3gq75rtjeUb jxs3EeWoeh9ZC3diIe6S9anjxpegzF9enXlWmhHeGTWI2KP7lAoWQ2KHoNojdqSrLcX9 ZDSrhNohznJk5fzMByjTMGuYZAoUPdKL6xIIF7wyrNKWVYSaxs7NPQASb0y4dZysh0s1 Qgz4TKyTYp4+xa0y5Z1sFPlrgJa/9VkwKbSRjxMZw3Jvkfb12FzB/bm3xlz4ZL0oIuc3 2wrQ== 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 t3si6495635otq.54.2018.12.03.10.07.48 for ; Mon, 03 Dec 2018 10:07: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 496F0169E; Mon, 3 Dec 2018 10:07: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 792003F59C; Mon, 3 Dec 2018 10:07:45 -0800 (PST) From: James Morse To: linux-acpi@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Borislav Petkov , Marc Zyngier , Christoffer Dall , Will Deacon , Catalin Marinas , Naoya Horiguchi , Rafael Wysocki , Len Brown , Tony Luck , Dongjiu Geng , Xie XiuQi , Fan Wu , James Morse Subject: [PATCH v7 20/25] ACPI / APEI: Use separate fixmap pages for arm64 NMI-like notifications Date: Mon, 3 Dec 2018 18:06:08 +0000 Message-Id: <20181203180613.228133-21-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 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. fixup for split fixmap --- arch/arm64/include/asm/fixmap.h | 2 +- drivers/acpi/apei/ghes.c | 10 +++++++++- 2 files changed, 10 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 849da0d43a21..6cbf9471b2a2 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -85,6 +85,14 @@ ((struct acpi_hest_generic_status *) \ ((struct ghes_estatus_node *)(estatus_node) + 1)) +/* NMI-like notifications vary by architecture. Fill in the fixmap gaps */ +#ifndef CONFIG_HAVE_ACPI_APEI_NMI +#define FIX_APEI_GHES_NMI -1 +#endif +#ifndef CONFIG_ACPI_APEI_SEA +#define FIX_APEI_GHES_SEA -1 +#endif + static inline bool is_hest_type_generic_v2(struct ghes *ghes) { return ghes->generic->header.type == ACPI_HEST_TYPE_GENERIC_ERROR_V2; @@ -954,7 +962,7 @@ int ghes_notify_sea(void) int rv; raw_spin_lock(&ghes_notify_lock_sea); - rv = ghes_estatus_queue_notified(&ghes_sea, FIX_APEI_GHES_NMI); + rv = ghes_estatus_queue_notified(&ghes_sea, FIX_APEI_GHES_SEA); raw_spin_unlock(&ghes_notify_lock_sea); return rv; From patchwork Mon Dec 3 18:06:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710287 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 075A815A6 for ; Mon, 3 Dec 2018 18:08:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F08092B47E for ; Mon, 3 Dec 2018 18:08:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E48EA2B495; Mon, 3 Dec 2018 18:08:11 +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 7A5862B47E for ; Mon, 3 Dec 2018 18:08:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D1636B6A8D; Mon, 3 Dec 2018 13:07:53 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 883D96B6A8E; Mon, 3 Dec 2018 13:07: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 721AA6B6A8F; Mon, 3 Dec 2018 13:07:53 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by kanga.kvack.org (Postfix) with ESMTP id 416F36B6A8D for ; Mon, 3 Dec 2018 13:07:53 -0500 (EST) Received: by mail-ot1-f70.google.com with SMTP id s12so5859767otc.12 for ; Mon, 03 Dec 2018 10:07: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=kerOtvmOxxD7FTzicp7qWBnU/Qscugchq6UMLvEsTfY=; b=R2L+QTy/Ahs4Tqegqya/x0hoUbSLMTSd97G9yXJBwjqb3MlwCjtBqy1O6T8FOp+OXn s7+j+hZXdE4KmNeSABTRNhzlbJEhl9uhmhbzGWNv3Jj/YbyD4KC3WXb0BfvXkbwJVnqQ Fj+rujPw2pz7MTmQF+1+Fhu+vN7JroGHFhU1jIwvD6b4+kmNEbgxqOwLxg7zUMhzN4pW uYAKMY0mr1GAlWYGP5z3SJYkVPIzGiitk7/petyInPie0m1TKEVEXl44pveU9DaT0H0X 5/UM6MIrUOEbMKsS7Bnq6aP6AXiU4xLmQBSC5NxBR97zPxBir1NCrxSej+7IHUhfA3rq LSHg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWa58L/luivUD5tZmaJ/Lj/vPLHnVoGp3DnstVGa3wR5bTz/p4Yp VVUrjFkgZ/pcWmYQsgBt/682+zwBU6cfc4gJmukg86xUIVoWztKeIQc9MUfUE6SUsJRYaTrJ3XK So3o/J/n7F8vfdTUvmdPteEHVqv1mFzfeJTp8SAarzEMd4aHo7GAiBDkJsLVhIz2xnA== X-Received: by 2002:aca:5a88:: with SMTP id o130mr11060655oib.275.1543860473027; Mon, 03 Dec 2018 10:07:53 -0800 (PST) X-Google-Smtp-Source: AFSGD/VDDlwXgeGgCaMdYv6K+aSxyirMJBtBNcL3upWvmHKvZbFUk5KovP0GtVQeBTBF9uli1cGW X-Received: by 2002:aca:5a88:: with SMTP id o130mr11060628oib.275.1543860472327; Mon, 03 Dec 2018 10:07:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860472; cv=none; d=google.com; s=arc-20160816; b=XJHx/vNcwMrWPUBmt7+UB9VHA20f81/C8AjiFd85PA8gR99ZOWaZQ1ed2OncAI+R5A RaJZM5RldjLMQ4z0C48pyp2/PRO0fW+FR1AbgiBni97TnuY+f6dkLmv5hmhLYA3K0q8T 6m823ZckyMHH7GtQVovrW5u5y1kpBm6Hsy7dLJ2yvBIyjmtKpQJE1QKqEHQO78ttegmi jsRf6b3qoUBQCmUcPstZncHQrD6QN9zGXjznseE74+KlxuK2a9prz08SUDVziqWq0mBj z6Ik3t+EV8KL5VC2jgUS7vKBGVgMbEJhDtuooyez+BNDersRZoipPRvIgSV9pt9flz2f cNtQ== 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=kerOtvmOxxD7FTzicp7qWBnU/Qscugchq6UMLvEsTfY=; b=DhIyWSxlEBbeJPPoEjD/tEJag1X2hpGxO3SXVzL43z8Vd6De0p0BJtk/50mF5BZUEq wabLQT4dCVyZ8RWCqmk7ruX6SfSstUbkFLHEC9qaxmqCaICY1o6QMkZo/dTWPOsZ5/4e BfX2aOXXs8kyRIuPq5SDLpvZkGLrb/cLpuCQ8Kb9cTw++FTTqnI0KADhQCdYs6XpTB35 mRCKKuZoxFuxKYB8sexA4dKlWdUTKX8AQdcrJ1Ac6Qe1D2Zn/mhpd4MN1U2M022As6rm VvUDdmPrcrU16vvx3U9xh/wsG231aHg/tqP3pqBpC5HNxNNjQ7jgqJ7kp2TMmK3Inf6L agPg== 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 108si7171623oti.277.2018.12.03.10.07.52 for ; Mon, 03 Dec 2018 10:07: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 B8DDC1715; Mon, 3 Dec 2018 10:07: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 E88C93F59C; Mon, 3 Dec 2018 10:07: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 , Fan Wu , James Morse Subject: [PATCH v7 21/25] mm/memory-failure: Add memory_failure_queue_kick() Date: Mon, 3 Dec 2018 18:06:09 +0000 Message-Id: <20181203180613.228133-22-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 5411de93a363..37b4884b2a1e 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2692,6 +2692,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 0cd3de3550f0..ec05e1dfce37 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -1480,7 +1480,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); @@ -1494,6 +1494,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 Mon Dec 3 18:06:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710289 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 703FD1057 for ; Mon, 3 Dec 2018 18:08:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65E612B47E for ; Mon, 3 Dec 2018 18:08:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 592F42B495; Mon, 3 Dec 2018 18:08:17 +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 C89962B47E for ; Mon, 3 Dec 2018 18:08:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A302E6B6A8E; Mon, 3 Dec 2018 13:07:57 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 995376B6A8F; Mon, 3 Dec 2018 13:07: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 87F3E6B6A90; Mon, 3 Dec 2018 13:07:57 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by kanga.kvack.org (Postfix) with ESMTP id 6078B6B6A8E for ; Mon, 3 Dec 2018 13:07:57 -0500 (EST) Received: by mail-oi1-f198.google.com with SMTP id p131so1299473oig.10 for ; Mon, 03 Dec 2018 10:07: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=EBSpijSkolzccED4lKghWiZT1vIhGy2WcfQBL5IIU28=; b=uE4aF6FLVQcOvUcbnbvUtPT6B2vYDU3D4fpXz0sEzcIzKv9jRwUTGV+0EmvnnBDiGf IXQ9pFejjpucP25TCSR3g246ogZP4V+lKI5cz9ZZaq0gBEp3VkPLRihRxnzA7Jg608bU Ks/bko+L1XfJ2pVNer/SX2ARrAZoR/NW5J+YyxC87tQ2W2W0ihDmbWBfSV+OZy9CWKjZ YRADNVksNRrDN7h07zf+p9MTQkQV2lLcBRRxNgwhofv4Y5os6aOWMo7io/TaibZVA6Jr q+r06xIDxdPCC/T5Dtmx6DGXGFe4iWlctQuYs/twFQOSjxfVuwecvSeVtEDWkVig/RUG sf3Q== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWZJccpZqkkwLOVva/H+fHcRvXAM8UxGBIxZ31A8d71Psc13S7D7 L7hJjXVV0TWNN9ui7dwL1853tsKmnCo27ti6A7wLnbpUyBfPxfxu4gXo8+oCHJ/7MDAw4LYjt1b B9BThFQaklXcGdhALQmFVhcS8HTFOeXs+q3/FHhdOFKuSPAqcS5I6T9uPMfJe6WsZ0A== X-Received: by 2002:aca:51c6:: with SMTP id f189mr9977993oib.281.1543860477141; Mon, 03 Dec 2018 10:07:57 -0800 (PST) X-Google-Smtp-Source: AFSGD/WGefkAm3VqXlIkscBpLNhYL9Sg2KcSOXoEeAciEtNaDwVqG29ksLwY0whQDvmdMTPVEZXu X-Received: by 2002:aca:51c6:: with SMTP id f189mr9977941oib.281.1543860475821; Mon, 03 Dec 2018 10:07:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860475; cv=none; d=google.com; s=arc-20160816; b=HI5+Ysw7B6Z2jtQzpVhucMrZDR59z9Qz0qCFoepJcpLknFj57zEEzr4DehP/PWFSjt /oXc+N00xKcfRcVbyZb9Km0w9yvnGUj1QY11OLga7GqULeQa+dDKWXGSv61+9HqVGjfu 1xN/CvMVSCzO6aN1t6g62u8BdsbcfnVNgT64/jNnkqiN/glCmecPup/pK5Cjtn1bK60n aiaKbo/CB8GGN5XIIPzlID4ILmCPCSUxgI0Sc/6afHfPGRsD3NTKhDdHyEmbrvePsAfx vNE7CIe7rryAWIQEDQAvIS9+s89FRzeSljIfp6WYIeQNjOi9uXOL5GmMboNTF6ABo+hK MCLg== 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=EBSpijSkolzccED4lKghWiZT1vIhGy2WcfQBL5IIU28=; b=wdeuAwqURm0RIsLCIjoCvU7Ig038lXduXkuMLheu+8rUq/LB5dVxcmem7LZ6FZmnR/ Jtbus6mEEUJr5sT8GZjgdP7RkcPRPRb+WX7ZFYYyuzpb6uEqKKuCxqxxwSxGHS7Z6H6o M+TB1kNCHR5AmcpEhCcF2xOUI96qbO0h8R+C+Mk17kmaaGpES7o2tepoNsc5pOFwPuG5 09WdLxv33kR+CUu4VSFWEX4L2gWHj9q+0cUJRALLCfffi0NIayfgLGnpqKBeRY+F/ymr voHekNt0QCtqYaRtw7nNZ4x1lD0CYTUyDHFpXHSp9qNYy1qcX3KTMq1DjZmGrF6Y+SsS uQvQ== 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 k18si6600879otj.208.2018.12.03.10.07.55 for ; Mon, 03 Dec 2018 10:07: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 48E11169E; Mon, 3 Dec 2018 10:07:55 -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 7788E3F59C; Mon, 3 Dec 2018 10:07:52 -0800 (PST) From: James Morse To: linux-acpi@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Borislav Petkov , Marc Zyngier , Christoffer Dall , Will Deacon , Catalin Marinas , Naoya Horiguchi , Rafael Wysocki , Len Brown , Tony Luck , Dongjiu Geng , Xie XiuQi , Fan Wu , James Morse Subject: [PATCH v7 22/25] ACPI / APEI: Kick the memory_failure() queue for synchronous errors Date: Mon, 3 Dec 2018 18:06:10 +0000 Message-Id: <20181203180613.228133-23-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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. If a ghes notification type indicates that it may be triggered again when we return to user-space, use the task-work and notify-resume hooks to kick the relevant memory_failure() queue before returning to user-space. 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. --- drivers/acpi/apei/ghes.c | 65 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 6cbf9471b2a2..3e7da9243153 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -136,6 +137,26 @@ static atomic_t ghes_estatus_cache_alloced; static int ghes_panic_timeout __read_mostly = 30; +static bool ghes_is_synchronous(struct ghes *ghes) +{ + switch (ghes->generic->notify.type) { + case ACPI_HEST_NOTIFY_NMI: /* fall through */ + case ACPI_HEST_NOTIFY_SEA: + /* + * These notifications could be repeated if the interrupted + * instruction is run again. e.g. a read of bad-memory causing + * a trap to platform firmware. + */ + return true; + default: + /* + * Other notifications are asynchronous, and not related to the + * interrupted instruction. e.g. an IRQ. + */ + return false; + } +} + static void __iomem *ghes_map(u64 pfn, int fixmap_idx) { phys_addr_t paddr; @@ -379,14 +400,33 @@ static void ghes_clear_estatus(struct acpi_hest_generic_status *estatus, fixmap_idx); } -static void ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata, int sev) +struct ghes_memory_failure_work { + int cpu; + struct callback_head work; +}; + +static void ghes_kick_memory_failure(struct callback_head *head) +{ + struct ghes_memory_failure_work *callback; + + callback = container_of(head, struct ghes_memory_failure_work, work); + memory_failure_queue_kick(callback->cpu); + kfree(callback); +} + +static void 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 flags = -1, ret; + struct ghes_memory_failure_work *callback; 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; + if (!(mem_err->validation_bits & CPER_MEM_VALID_PA)) return; @@ -407,7 +447,22 @@ static void ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata, int if (flags != -1) memory_failure_queue(pfn, flags); -#endif + + /* + * If the notification indicates that it was the interrupted + * instruction that caused the error, try to kick the + * memory_failure() queue before returning to user-space. + */ + if (ghes_is_synchronous(ghes) && current->mm != &init_mm) { + callback = kzalloc(sizeof(*callback), GFP_ATOMIC); + if (!callback) + return; + callback->work.func = ghes_kick_memory_failure; + callback->cpu = smp_processor_id(); + ret = task_work_add(current, &callback->work, true); + if (ret) + kfree(callback); + } } /* @@ -480,7 +535,7 @@ 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); + ghes_handle_memory_failure(ghes, gdata, sev); } else if (guid_equal(sec_type, &CPER_SEC_PCIE)) { ghes_handle_aer(gdata); From patchwork Mon Dec 3 18:06:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710291 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 8ECB1109C for ; Mon, 3 Dec 2018 18:08:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 835D12B47E for ; Mon, 3 Dec 2018 18:08:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 76DFF2B495; Mon, 3 Dec 2018 18:08:22 +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 072ED2B47E for ; Mon, 3 Dec 2018 18:08:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 80E126B6A9B; Mon, 3 Dec 2018 13:08:01 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7BEA06B6A9D; Mon, 3 Dec 2018 13:08: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 65CD16B6A9E; Mon, 3 Dec 2018 13:08:01 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot1-f70.google.com (mail-ot1-f70.google.com [209.85.210.70]) by kanga.kvack.org (Postfix) with ESMTP id 11DDC6B6A9B for ; Mon, 3 Dec 2018 13:08:01 -0500 (EST) Received: by mail-ot1-f70.google.com with SMTP id t13so5994522otk.4 for ; Mon, 03 Dec 2018 10:08: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=yYwIdTKWeRNtz5QSmMouRNEU9UwxT/m3QVZga4V1oPc=; b=nvc/28V+zZIoBsAps3y2MZ2H5v4lleva0qK/GQjmXRAwaVIV6xdhrvOtdWNYAJHhlG OSgnGb6BkjKum2UiE4CK1uBXvRvRbYuU0C6FFegARO6bOrojK63+cxAlUucbVLHkQuqJ nyHafLAWhtH+b1s0tahA9XXQiHguXogQP4PHKS4/inK1vVvdoVN50WuoZPbLF3vyGJJn cdw9+Z7H84nU8typkpy1HIo4A/HsvUf7x9ZQkoPmQU6nhUD8qxUjjwL28+HXveUvrZfR AFz3Q9sPDqjbvPb2Mg4K/TPdEXGcUHop2u0Vek40l0B6qpW/fPXBpyDvIPou1XnDf7w+ PXKg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWaGUE9CrauAtH1575rxMdIZROVxeelVgbpvEKHFOSak2tgG4dgj nxuKb3k6tM6ic2s+hN6TJyBy6lQFbUC1RgZDEgNk9EPboLVT1IWjFMCFdgOGRgjvpHObrjWsXip Oypwv9tsOyuwXZE/NNxqPKjRqi5pwsBV78R0byUGN3bqaScQN+S3My+w83gMsUJXpFA== X-Received: by 2002:aca:4506:: with SMTP id s6mr9836447oia.115.1543860480793; Mon, 03 Dec 2018 10:08:00 -0800 (PST) X-Google-Smtp-Source: AFSGD/VP1KvKpqhkH9Kyoi7YBNu1QUp4rOu5T2iSVAjQPruO5gMu5+fmc16A6M53HWgTWBRF2d09 X-Received: by 2002:aca:4506:: with SMTP id s6mr9836396oia.115.1543860479542; Mon, 03 Dec 2018 10:07:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860479; cv=none; d=google.com; s=arc-20160816; b=kxTfgKFGfOv61s4YrbdkTjoKkNdad3o2mug7s4AdtFoFgOQiq9aSIMg2oxO8rPk+9O wSWysYS/+WnPNjSEzMe3bdHLeD7esbgTTsAYJFP0UrARZ+UhnZZhT9McDGyYtr1cF4YV ZJWr+Mfn7y6aMz3px+DjoMkpbX+yBFfZDpZqyClOHGid6HKT1NuxZnxVLVnBePmaiVf/ 4q3b3WbVOQBgTLJP/CTagQTRXUoAWG7ORjw/2/X9mgOXHG5KfrMAA3MbfFWPYG+vzqMC HvH8eqNSVIm8xoTC3nb8fh/wGwkGGsIMUZ2hIxIwLISZhTA37oIKX7PU2EHugDDp595k 0PQg== 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=yYwIdTKWeRNtz5QSmMouRNEU9UwxT/m3QVZga4V1oPc=; b=sILInYiXiddVEWbzMNFi6XNHxjM0uBWp6Fz8dy7NOMO9ow0yh1souv1/aIxupzEGM7 EHXUspc8R3RhhF+gB8wC22OAm3NItCIbfMszW4Txllmp2Cl/mXDQ2/UYi8H4iURMyjl4 H5klzVn93eNttGSS8czFGvXPjY4d4+HVxyyj50Nm9FB71rYUFJO4LWPWveFEwS5RdTdQ Dm3lcD58ELLJ6O9VzyY3kBuAZraW/dFXdHYickKEhxP1bDl6unia8FLdq4tf9bPAI5o0 MYNDceO1Qz5NkaagVp1TsYocrM2GnKYKWCwGflUvBu6rttpk8di/08Pya4e10VCKKAAQ 34Vw== 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 l78si6508323oih.207.2018.12.03.10.07.59 for ; Mon, 03 Dec 2018 10:07:59 -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 CE757169E; Mon, 3 Dec 2018 10:07:58 -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 0A36C3F59C; Mon, 3 Dec 2018 10:07:55 -0800 (PST) From: James Morse To: linux-acpi@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Borislav Petkov , Marc Zyngier , Christoffer Dall , Will Deacon , Catalin Marinas , Naoya Horiguchi , Rafael Wysocki , Len Brown , Tony Luck , Dongjiu Geng , Xie XiuQi , Fan Wu , James Morse Subject: [PATCH v7 23/25] arm64: acpi: Make apei_claim_sea() synchronise with APEI's irq work Date: Mon, 3 Dec 2018 18:06:11 +0000 Message-Id: <20181203180613.228133-24-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 CC: Xie XiuQi CC: gengdongjiu Acked-by: Catalin Marinas --- 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 | 22 +++++++++++++++++++++- arch/arm64/mm/fault.c | 9 ++++----- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c index 803f0494dd3e..421331157e8f 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,13 +269,17 @@ pgprot_t __acpi_get_mem_attribute(phys_addr_t addr) int apei_claim_sea(struct pt_regs *regs) { int err = -ENOENT; - unsigned long current_flags; + unsigned long current_flags, interrupted_flags; if (!IS_ENABLED(CONFIG_ACPI_APEI_GHES)) return err; current_flags = arch_local_save_flags(); + interrupted_flags = current_flags; + if (regs) + interrupted_flags = regs->pstate; + /* * SEA can interrupt SError, mask it and describe this as an NMI so * that APEI defers the handling. @@ -283,6 +288,21 @@ 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 (!arch_irqs_disabled_flags(interrupted_flags)) { + local_daif_restore(DAIF_PROCCTX_NOIRQ); + irq_work_run(); + } 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 956afc7d932a..c26ee1f1cc36 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -629,11 +629,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 Mon Dec 3 18:06:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710295 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 DDF50109C for ; Mon, 3 Dec 2018 18:08:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFCC32B47E for ; Mon, 3 Dec 2018 18:08:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1D282B495; Mon, 3 Dec 2018 18:08:27 +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 3F6BC2B47E for ; Mon, 3 Dec 2018 18:08:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D3AC6B6A9D; Mon, 3 Dec 2018 13:08:04 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3A1D16B6A9F; Mon, 3 Dec 2018 13:08: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 2681B6B6AA0; Mon, 3 Dec 2018 13:08:04 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f197.google.com (mail-oi1-f197.google.com [209.85.167.197]) by kanga.kvack.org (Postfix) with ESMTP id E94C86B6A9D for ; Mon, 3 Dec 2018 13:08:03 -0500 (EST) Received: by mail-oi1-f197.google.com with SMTP id h85so8764435oib.9 for ; Mon, 03 Dec 2018 10:08:03 -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=gMemP6CVYESD7JPOg7f7tWzOngUpBjOLmcBn3e9J/LM=; b=mYB07iDKBlzmcHx/G4HE/bf85K0M2N6xoFuZ5ejhcaRfswwU80TTqnp+dfLAgluwyo v11kiMUiQOcuT80SJY/fDZFWAyeCyo6ikYSr44c53E5tzz5nlOYoOuQyZq+OZkxdxBZV b3JmeKsFYfscBoGt8jGFx8ZJWcgoXIg9D8+/9Diqq3jFXU/OTVGVLFcMx/n5enyvK5au D1YFul2obR9hrKQw/xKLCX3o1fLKSxsZXGNzbrvYZ+M2Ka+U7lORv1UG/3yTk+Qfx2bb 37q9LWxxzoCXMAiHyHzm1VxObHFREFqzMWkdvW+kumkJLCFHEOFQxkFhyUJIEzqcbLnZ wTbA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWZMsAWgTY7QygtI/XxvnYA4oY5NueMN3giJRWQtCPR0aMKqb7IN zBWk3zrcUY6LmR3KzKuhLThmjuFA/MxdD32jJK5i6eEKirdL8XCZ2I16m5qqeEa+5DD7fYjP8Su iHIJfNe2zCF8BD00ykpozsyiBZ9Mw9yIcZ3NXOHxHVAfCk/sSfcMpIQuLA6rrtnWOUA== X-Received: by 2002:aca:de03:: with SMTP id v3mr10749890oig.152.1543860483707; Mon, 03 Dec 2018 10:08:03 -0800 (PST) X-Google-Smtp-Source: AFSGD/Uan2bdZHCacknetf/oeV1pkP6c2nOV8emeYmWEeJR6TW/Ts49XdnI6uSrGzUXnkY2Vk6Ug X-Received: by 2002:aca:de03:: with SMTP id v3mr10749856oig.152.1543860482937; Mon, 03 Dec 2018 10:08:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860482; cv=none; d=google.com; s=arc-20160816; b=wC7eh45a8iGUr8t1SM5jtZ/F1iwRkxxdevokHvO/6DfYfEBjDzXtE30Egv1OaVxIlg 50J6KXBJ+L++GyW6zuoAGXpHtOMCL0gk9+au27bvuigw9+4fRvoA7ZlspfZUzhxcCMgL hVRyh6vdUC7LxiK2YeEuGOHLuOLq77xGxSJoVogBzIEjaNzPP1lPbFNU4noMNgSh2/hl PobonvAuTNpVI38VWe63ajiGVAogfhpTvZsnRRBvtPCnvNGW4nywEbzn7YiP6q2vpw9n brfmns9YPAduducrDcrUQ30AlFn+U1l12bwBctEyd/UJN6MWWeSVJ0sCuFPqXv88EtZM duAQ== 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=gMemP6CVYESD7JPOg7f7tWzOngUpBjOLmcBn3e9J/LM=; b=ueaUGBz040q8UzSkX1SYD81eg0epQxQzwz6lRx1N4isAFBbXkbReGP1hPmSlujjUTW MRDBE9ZHRfQ72f5FIMnjh4qzqwtXbxMhCHm27se4geWUZnLD9aoHPmdQJ02rKJOxeyku zwwGQKRp3XRHyITkzduGRU6p+SPyynWW8PLt6WdMVrLdOD2WBEeBejQQv3jXmijsH+Ln aiw/OVrqdppJqe3OPJheJjsxttzOp4qLX9LOFoWokv5trfr7YAZJQX9Un3Bg362tj+jZ ooL9lbH28685AazMNyloI5UZZApekdHdMl/n8281Zrjcand4OaXQ4ky9y+d3foiEh4eJ HAAA== 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 f36si6885153otf.163.2018.12.03.10.08.02 for ; Mon, 03 Dec 2018 10:08: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 660F71713; Mon, 3 Dec 2018 10:08: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 950123F59C; Mon, 3 Dec 2018 10:07: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 , Fan Wu , James Morse Subject: [PATCH v7 24/25] firmware: arm_sdei: Add ACPI GHES registration helper Date: Mon, 3 Dec 2018 18:06:12 +0000 Message-Id: <20181203180613.228133-25-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 | 70 +++++++++++++++++++++++++++++++++ include/linux/arm_sdei.h | 6 +++ 3 files changed, 80 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 1ea71640fdc2..4bcbe3a3f597 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 @@ -32,6 +33,8 @@ #include #include +#include + /* * The call to use to reach the firmware. */ @@ -887,6 +890,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 Mon Dec 3 18:06:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10710299 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 18A171057 for ; Mon, 3 Dec 2018 18:08:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DA952B47E for ; Mon, 3 Dec 2018 18:08:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00C802B495; Mon, 3 Dec 2018 18:08:32 +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 6E2322B487 for ; Mon, 3 Dec 2018 18:08:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BE2776B6A9F; Mon, 3 Dec 2018 13:08:07 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B68106B6AA1; Mon, 3 Dec 2018 13:08:07 -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 9E6156B6AA2; Mon, 3 Dec 2018 13:08:07 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) by kanga.kvack.org (Postfix) with ESMTP id 6D2D06B6A9F for ; Mon, 3 Dec 2018 13:08:07 -0500 (EST) Received: by mail-oi1-f200.google.com with SMTP id w128so8715539oie.20 for ; Mon, 03 Dec 2018 10:08: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=xaMNalE2guwsyW9EtXo5sNk34iVUQAWFwG8Myi8K5JA=; b=ab4K2fKUf95OAXQwdtczcVRZy1hw+SXjxlUwRK5ehy8Pvi1WEgG+xVSGftVWI5llH2 yqzUQK7zVCRUjgh+aXswATB7G4Wusy4rcGrHgrgbScghn1c5cW/VVn2ypZSCwgbaI7+i Gf+MXL4mVck6H65VxsuvQzM4hxesG+t9zsnQmDqG7z9ZGEenYvcx6OojIiC8o4mP/8JV RA/DhxOm6l7BRMM8RnW1XNb8vAXn31K9NtvFMi1w4/paiFQpCWJLTuJBXaPEJM4m05VV SwxlsiNw42wxhTwrkEaudMu23yt6+loPuaA1CPzUMjOGCOKudjCyn/P7BrfJPf5Bgb0v Hf+A== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of james.morse@arm.com designates 217.140.101.70 as permitted sender) smtp.mailfrom=james.morse@arm.com X-Gm-Message-State: AA+aEWbQ+G4Y1pYbSyzSYwKcVzKFnzHPsugPoQHYZ8vvWbzrldGtcDmG qaDQPIgZxujvc5oWcMdJglM/R+zFKRmUujZuXh0NzjFt97PvfWUHs9kr4uVW0zJ5zGYZjXGbeQq M9bPFrjtR79C2CUq2efL1yI2drCWDXPqlcGdPwwRX4cuD76Td1sFWOhrDs7g5SfAhXA== X-Received: by 2002:a54:4713:: with SMTP id k19mr9770703oik.241.1543860487200; Mon, 03 Dec 2018 10:08:07 -0800 (PST) X-Google-Smtp-Source: AFSGD/W8dusHikM9zyocIGVXgkTDPPl5bWv7MylttoXwHpragR+IAsrYZ4WfOYHUMti3+/ycHOnv X-Received: by 2002:a54:4713:: with SMTP id k19mr9770675oik.241.1543860486399; Mon, 03 Dec 2018 10:08:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543860486; cv=none; d=google.com; s=arc-20160816; b=oRW4atfiLgdBp8h8BFSQV2WPlG2UwmqqeWps+y5FGNOw+VQ5rbW8MSqMePzmanL2OI R3r0eb60Qb2Bt7kwE6CeiViSMC4nRDKQbjzWNdbOkjiYi50xUsWC8ss5KuROvhdfU0Su QUiCOh9x/M5lT8PSHVTVom82sdmlp0awI57XoC47ymUQ3Ws7INTfw0UI8CTu/OsFCOjW XslJg2q/8hmXXhBOj/95Iptcg/hPBGal2eABnnB/vXNdZs/H+Xdatfw9zxKkCW3y9U+W z98iANwukhcJ+s1t9COp47E40yW3DGuT2xxOZSf3IlxBt/GAAour2xagpaA7O0HnYOwe neUA== 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=xaMNalE2guwsyW9EtXo5sNk34iVUQAWFwG8Myi8K5JA=; b=ob+zSCM+1QE7GTb+sypAoxqDJcAMC9wKvHUVOdz5Zhj8ubAVa70vyMDJxjEOgUc0Vk K0DTb0qPQ287kRqaTjXYrHuo2JGLD04zR9O5YbgwKxENXNQuWLKvtlFugG3mnI2bPTv6 +bNBcL9YpexGRbROtRO7pBsoSPZforc3HkdeRhFZTkWvdoujjjPm9NxMB5HrvSZz7kH6 ILkZmIs5/MgeHnfx8lFVl91vRDYfup5Yr8SgTMdcx7k4/iK22yt0MUhm+K6RospGnZ5c FRKJUREajrLaMBJsWLyIT6S962FafRw11rOIoKE2iIHjqeO3XxDan3noYpYCYb/fbN7E XkZg== 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 j5si5986037oiw.131.2018.12.03.10.08.06 for ; Mon, 03 Dec 2018 10:08: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 EA071169E; Mon, 3 Dec 2018 10:08:05 -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 25A843F59C; Mon, 3 Dec 2018 10:08:03 -0800 (PST) From: James Morse To: linux-acpi@vger.kernel.org Cc: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, Borislav Petkov , Marc Zyngier , Christoffer Dall , Will Deacon , Catalin Marinas , Naoya Horiguchi , Rafael Wysocki , Len Brown , Tony Luck , Dongjiu Geng , Xie XiuQi , Fan Wu , James Morse Subject: [PATCH v7 25/25] ACPI / APEI: Add support for the SDEI GHES Notification type Date: Mon, 3 Dec 2018 18:06:13 +0000 Message-Id: <20181203180613.228133-26-james.morse@arm.com> X-Mailer: git-send-email 2.19.2 In-Reply-To: <20181203180613.228133-1-james.morse@arm.com> References: <20181203180613.228133-1-james.morse@arm.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 v6: * Tinkering due to the absence of #ifdef * Added SDEI to the new ghes_is_synchronous() helper. --- drivers/acpi/apei/ghes.c | 82 +++++++++++++++++++++++++++++++++++++++- include/linux/arm_sdei.h | 3 ++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 3e7da9243153..6325f1d6d9df 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 @@ -93,6 +94,10 @@ #ifndef CONFIG_ACPI_APEI_SEA #define FIX_APEI_GHES_SEA -1 #endif +#ifndef CONFIG_ARM_SDE_INTERFACE +#define FIX_APEI_GHES_SDEI_NORMAL -1 +#define FIX_APEI_GHES_SDEI_CRITICAL -1 +#endif static inline bool is_hest_type_generic_v2(struct ghes *ghes) { @@ -128,6 +133,8 @@ static DEFINE_MUTEX(ghes_list_mutex); * simultaneously. */ static DEFINE_SPINLOCK(ghes_notify_lock_irq); +static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sdei_normal); +static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sdei_critical); static struct gen_pool *ghes_estatus_pool; static unsigned long ghes_estatus_pool_size_request; @@ -141,7 +148,8 @@ static bool ghes_is_synchronous(struct ghes *ghes) { switch (ghes->generic->notify.type) { case ACPI_HEST_NOTIFY_NMI: /* fall through */ - case ACPI_HEST_NOTIFY_SEA: + case ACPI_HEST_NOTIFY_SEA: /* fall through */ + case ACPI_HEST_NOTIFY_SOFTWARE_DELEGATED: /* * These notifications could be repeated if the interrupted * instruction is run again. e.g. a read of bad-memory causing @@ -1100,6 +1108,60 @@ 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, int fixmap_idx) +{ + if (!_in_nmi_notify_one(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) +{ + int err; + struct ghes *ghes = arg; + + 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) +{ + int err; + struct ghes *ghes = arg; + + 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; @@ -1135,6 +1197,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); @@ -1198,6 +1267,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(); } @@ -1223,6 +1297,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; @@ -1255,6 +1330,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