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; }