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) {