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;