From patchwork Fri Sep 21 22:16:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10611009 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 97A8D5A4 for ; Fri, 21 Sep 2018 22:17:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88E022E6DC for ; Fri, 21 Sep 2018 22:17:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A39A2E6E3; Fri, 21 Sep 2018 22:17:51 +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 A30A62E6DC for ; Fri, 21 Sep 2018 22:17:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD32E8E0012; Fri, 21 Sep 2018 18:17:49 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CAAA28E0001; Fri, 21 Sep 2018 18:17:49 -0400 (EDT) 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 B98DE8E0012; Fri, 21 Sep 2018 18:17:49 -0400 (EDT) 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 8AA198E0001 for ; Fri, 21 Sep 2018 18:17:49 -0400 (EDT) Received: by mail-ot1-f72.google.com with SMTP id q3-v6so13806507otl.14 for ; Fri, 21 Sep 2018 15:17:49 -0700 (PDT) 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=YLQ6O2SJwR9dm8ku/ehxRPu10kwLELGq6raJODfSVTQ=; b=ANzfH9xk7OwspZXENaODJTGnRHKYdMCQ3NtkGIfIMKG0SxYKkKsT7+AQESwvpUj4nY r1lQM/dTDl8ozPdQpaGIvFfU0m1BJrLzzHP5lKeZu+pqjd9Orz/suwbiuYyFskAoW/5p ObsZkNO1UMAqQ+wFI3EDFKNCdeM8wfI11tnboUQ7c9eRKUaHPWgd5c1UzLPU9Zyi4VKR Bmu4CI+LDgMMl5gkIYRtGikPjvGIqpPEVYX6DDKusEtY/3Dkkn3Gm5+EjSajQbvQ7edN gfhE5CMkL4dM1mIhZ3cieWLJLcARvilxiLJbk57FHUogQ9ANSLH5vfW4xcUKUD1DoIxb g6Sg== 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: APzg51CKVC03UU4yr4TLFlql9ckLmLCqnvLTVAANAqFLzEW+0o9mIgk6 dZRSwKXTkMjeKugD2pL4xBrlY1hDqYEkGNY9LfcTMjEihtQD55ip0Q2T2eK4y18qjGUFP1eFfTG qtUyPvVLAEEigw+fi8ZEjRz6Z9nvzfdZ6K+mVyB8z4gxgZBECBW8j8rIBQIjG23uEaA== X-Received: by 2002:a9d:4378:: with SMTP id y53-v6mr27875197oti.266.1537568268238; Fri, 21 Sep 2018 15:17:48 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda+07DdA1iyPz5DQdmlk9MEXPpWlhrJGqjZU49Mpew4+VakrdB+75wjOM0PoigQ21Oanh6M X-Received: by 2002:a9d:4378:: with SMTP id y53-v6mr27875162oti.266.1537568266997; Fri, 21 Sep 2018 15:17:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568266; cv=none; d=google.com; s=arc-20160816; b=HjTK7Y3puVlCp8aiYVKDO8XVFMCJ08WI/oGRdC/YwovqRGOwfy7Buu8KKmeCkkAicj Q3Yah5pn32TVcYnMUyDRNb8mPlVKQHG0oWjpK28dJr0zNSBgN56P0SWbCPWWSy9cU6Jh xhT5TbnGSzMkzOlGliOJ7xHB11nsn1QSNLGoGl5WNTCWL+PG5JIts7IzfjIm7eRzBLvn iq6tnsmrHIdoMbR+Gb0TGna1GkS8oQ4O6sKPw1DWpXXCvIBbjYjNXvVezayZX7ZV2lGI S7baig8rKG0zLyq3x7y7cWNUZP8fLZq1q6k/pKxpp25ixca5f9h50Dt6urG00zeTA92G TqVg== 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=YLQ6O2SJwR9dm8ku/ehxRPu10kwLELGq6raJODfSVTQ=; b=FJ4jtGTQwlECm0+SAXVqnNMxbY1iSxDO08vRsFbJ8g/usPiQmS+9hXQEkaWNcP93WU MwfXyUEaIbDglyReAFXyhhrzKxCnlOD5HvY39cef8daoG0azQgqM81rGqSxss/gGlGgc BvQgQC12l3wuDit5AnWx4BjfjetWTtrXwk40Rc8Ho+GvI2gh9t5qE4j3gcezaHIZFSuR YDq8UcuCDyBpOsOBU2PPDErP8M3Js4zkkxEK1cLCWZGj1ZqXCP3zRnh3N78uNwvvRx1K cWYBrTMENbfd66umNKr7wFlimYF08PbDZB14SyFkjEKKuxT+BBD9TEGEXulPdrphruk5 eIuw== 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 z3-v6si11425999otj.179.2018.09.21.15.17.46 for ; Fri, 21 Sep 2018 15:17:46 -0700 (PDT) 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 7A71018A; Fri, 21 Sep 2018 15:17:46 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 660AC3F557; Fri, 21 Sep 2018 15:17:43 -0700 (PDT) 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 , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 01/18] ACPI / APEI: Move the estatus queue code up, and under its own ifdef Date: Fri, 21 Sep 2018 23:16:48 +0100 Message-Id: <20180921221705.6478-2-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-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 support asynchronous NMI-like notifications on arm64 we need to use the estatus-queue. These patches refactor it to allow multiple APEI notification types to use it. First we move the estatus-queue code higher in the file so that any notify_foo() handler can make use of it. This patch moves code around ... and makes the following trivial change: Freshen the dated comment above ghes_estatus_llist. printk() is no longer the issue, its the helpers like memory_failure_queue() that still aren't nmi safe. Signed-off-by: James Morse Reviewed-by: Punit Agrawal Reviewed-by: Borislav Petkov Tested-by: Tyler Baicar --- drivers/acpi/apei/ghes.c | 265 ++++++++++++++++++++------------------- 1 file changed, 137 insertions(+), 128 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 02c6fd9caff7..f5732e6b5be8 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -545,6 +545,16 @@ static int ghes_print_estatus(const char *pfx, return 0; } +static void __ghes_panic(struct ghes *ghes) +{ + __ghes_print_estatus(KERN_EMERG, ghes->generic, ghes->estatus); + + /* reboot to log the error! */ + if (!panic_timeout) + panic_timeout = ghes_panic_timeout; + panic("Fatal hardware error!"); +} + /* * GHES error status reporting throttle, to report more kinds of * errors, instead of just most frequently occurred errors. @@ -672,6 +682,133 @@ static void ghes_estatus_cache_add( rcu_read_unlock(); } +#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(). + * 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. Each NMI-like error source must grow + * the ghes_estatus_pool to ensure memory is available. + * + * 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; + +static void ghes_print_queued_estatus(void) +{ + struct llist_node *llnode; + struct ghes_estatus_node *estatus_node; + struct acpi_hest_generic *generic; + struct acpi_hest_generic_status *estatus; + + llnode = llist_del_all(&ghes_estatus_llist); + /* + * Because the time order of estatus in list is reversed, + * revert it back to proper order. + */ + llnode = llist_reverse_order(llnode); + while (llnode) { + estatus_node = llist_entry(llnode, struct ghes_estatus_node, + llnode); + estatus = GHES_ESTATUS_FROM_NODE(estatus_node); + generic = estatus_node->generic; + ghes_print_estatus(NULL, generic, estatus); + llnode = llnode->next; + } +} + +/* Save estatus for further processing in IRQ context */ +static void __process_error(struct ghes *ghes) +{ +#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)) + return; + + len = cper_estatus_len(ghes->estatus); + node_len = GHES_ESTATUS_NODE_LEN(len); + + estatus_node = (void *)gen_pool_alloc(ghes_estatus_pool, node_len); + if (!estatus_node) + return; + + estatus_node->ghes = ghes; + estatus_node->generic = ghes->generic; + estatus = GHES_ESTATUS_FROM_NODE(estatus_node); + memcpy(estatus, ghes->estatus, len); + llist_add(&estatus_node->llnode, &ghes_estatus_llist); +#endif +} + +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_proc_in_irq(struct irq_work *irq_work) +{ + struct llist_node *llnode, *next; + struct ghes_estatus_node *estatus_node; + struct acpi_hest_generic *generic; + struct acpi_hest_generic_status *estatus; + u32 len, node_len; + + llnode = llist_del_all(&ghes_estatus_llist); + /* + * Because the time order of estatus in list is reversed, + * revert it back to proper order. + */ + llnode = llist_reverse_order(llnode); + while (llnode) { + next = llnode->next; + estatus_node = llist_entry(llnode, struct ghes_estatus_node, + llnode); + estatus = GHES_ESTATUS_FROM_NODE(estatus_node); + len = cper_estatus_len(estatus); + node_len = GHES_ESTATUS_NODE_LEN(len); + ghes_do_proc(estatus_node->ghes, estatus); + if (!ghes_estatus_cached(estatus)) { + generic = estatus_node->generic; + if (ghes_print_estatus(NULL, generic, estatus)) + ghes_estatus_cache_add(generic, estatus); + } + gen_pool_free(ghes_estatus_pool, (unsigned long)estatus_node, + node_len); + llnode = next; + } +} + +static void ghes_nmi_init_cxt(void) +{ + init_irq_work(&ghes_proc_irq_work, ghes_proc_in_irq); +} + +#else +static inline void ghes_nmi_init_cxt(void) { } +#endif /* CONFIG_HAVE_ACPI_APEI_NMI */ + static int ghes_ack_error(struct acpi_hest_generic_v2 *gv2) { int rc; @@ -687,16 +824,6 @@ 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) -{ - __ghes_print_estatus(KERN_EMERG, ghes->generic, ghes->estatus); - - /* reboot to log the error! */ - if (!panic_timeout) - panic_timeout = ghes_panic_timeout; - panic("Fatal hardware error!"); -} - static int ghes_proc(struct ghes *ghes) { int rc; @@ -828,17 +955,6 @@ 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. - */ -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. @@ -847,88 +963,6 @@ 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; - struct ghes_estatus_node *estatus_node; - struct acpi_hest_generic *generic; - struct acpi_hest_generic_status *estatus; - u32 len, node_len; - - llnode = llist_del_all(&ghes_estatus_llist); - /* - * Because the time order of estatus in list is reversed, - * revert it back to proper order. - */ - llnode = llist_reverse_order(llnode); - while (llnode) { - next = llnode->next; - estatus_node = llist_entry(llnode, struct ghes_estatus_node, - llnode); - estatus = GHES_ESTATUS_FROM_NODE(estatus_node); - len = cper_estatus_len(estatus); - node_len = GHES_ESTATUS_NODE_LEN(len); - ghes_do_proc(estatus_node->ghes, estatus); - if (!ghes_estatus_cached(estatus)) { - generic = estatus_node->generic; - if (ghes_print_estatus(NULL, generic, estatus)) - ghes_estatus_cache_add(generic, estatus); - } - gen_pool_free(ghes_estatus_pool, (unsigned long)estatus_node, - node_len); - llnode = next; - } -} - -static void ghes_print_queued_estatus(void) -{ - struct llist_node *llnode; - struct ghes_estatus_node *estatus_node; - struct acpi_hest_generic *generic; - struct acpi_hest_generic_status *estatus; - - llnode = llist_del_all(&ghes_estatus_llist); - /* - * Because the time order of estatus in list is reversed, - * revert it back to proper order. - */ - llnode = llist_reverse_order(llnode); - while (llnode) { - estatus_node = llist_entry(llnode, struct ghes_estatus_node, - llnode); - estatus = GHES_ESTATUS_FROM_NODE(estatus_node); - generic = estatus_node->generic; - ghes_print_estatus(NULL, generic, estatus); - llnode = llnode->next; - } -} - -/* Save estatus for further processing in IRQ context */ -static void __process_error(struct ghes *ghes) -{ -#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)) - return; - - len = cper_estatus_len(ghes->estatus); - node_len = GHES_ESTATUS_NODE_LEN(len); - - estatus_node = (void *)gen_pool_alloc(ghes_estatus_pool, node_len); - if (!estatus_node) - return; - - estatus_node->ghes = ghes; - estatus_node->generic = ghes->generic; - estatus = GHES_ESTATUS_FROM_NODE(estatus_node); - memcpy(estatus, ghes->estatus, len); - llist_add(&estatus_node->llnode, &ghes_estatus_llist); -#endif -} - static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) { struct ghes *ghes; @@ -967,26 +1001,6 @@ 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; @@ -1018,14 +1032,9 @@ static void ghes_nmi_remove(struct ghes *ghes) ghes_estatus_pool_shrink(len); } -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 Fri Sep 21 22:16: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: 10611013 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 6D60014BD for ; Fri, 21 Sep 2018 22:17:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FDDB2E6DC for ; Fri, 21 Sep 2018 22:17:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 546622E6E3; Fri, 21 Sep 2018 22:17:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C28922E6DC for ; Fri, 21 Sep 2018 22:17:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CAB838E0013; Fri, 21 Sep 2018 18:17:53 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C822F8E0001; Fri, 21 Sep 2018 18:17:53 -0400 (EDT) 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 B98178E0013; Fri, 21 Sep 2018 18:17:53 -0400 (EDT) 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 9017C8E0001 for ; Fri, 21 Sep 2018 18:17:53 -0400 (EDT) Received: by mail-ot1-f70.google.com with SMTP id e38-v6so13811352otj.15 for ; Fri, 21 Sep 2018 15:17:53 -0700 (PDT) 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=oDCGh+Hfyzp4ezaxevmAUyfg8LPskX1Kh8X66qfDuy8=; b=FVWbwfE6z+Lg2azkaB9YCDmR4qIJZ2jC+koluTNok0qbDBABd89Nq1ysssz52Y34kW TWyPCCU0ZaZMQFjV9mhPbmOW/+AX4Q5Qz0zAqGmpSDSUe+TBtW8astnFVUMdefwwFv+s Oo8l+fuPwr88fUOpv8D1l4AmLW8HuXu9Sn3+dfXi/LGs0N8gD1Q/L4briMmLNnmyS4Oo RvIGEYyaYXm8YYsG9dV/lgI5/hRUjK62op8h4ZBOjm2iCvTJVMO9LfSHlI4bo7aR6QFV NvOzRueR//Y7G70IiJha6l9y9IayikWlWDhUoySSP+Fohfn8rkT04hh0au2G3/dz892m g5zg== 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: APzg51BHT0jNJG+B+x/HysNuBfV75Xvk+DK+6x82kcLuvcfen7PNbcyf aoLBWP1h81YBUnQlA/ynEIbYPZlkO3J/XLlGy8ZSFLYhfdJY5u5azOg3bHpRgKxy/Yt5gkuGP9Z TMpscDsPivtrR/Y/WXgFHdKGt3i+HKONV/0DYF5WPgbxmadjkJwcrDjFwBx3PYLwLLA== X-Received: by 2002:a9d:2282:: with SMTP id y2-v6mr27749957ota.382.1537568273322; Fri, 21 Sep 2018 15:17:53 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbpUtvGoaYKyljxJKID2k29uiUkX3t0aFs21nrAo+HOMFvBqRsNaZo8ZSURnEzoqehW6lg4 X-Received: by 2002:a9d:2282:: with SMTP id y2-v6mr27749919ota.382.1537568272370; Fri, 21 Sep 2018 15:17:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568272; cv=none; d=google.com; s=arc-20160816; b=KvUO+Xa31YZ4e5FG1p3jPYHA0ofLpKaN5XDBTN6N1FbmBhUo9hjUvR9+QU8caRBGnr NcF/JriSSaYa95wlsopTtTaUqn2LjetgNuKqLAQSOCOkaHwLCeatpB+MMMdiGbhpGRHK qZGE6HKIrlzcCpKujbPh4MIoWQgNgv6CyDKZSN5q0QDJ+ri1C5eIg7DsCrYA3crB9PxV NvpBS+F9B129KHkcbDIjnWubTqgWctW+Dbeu5tFthJGOkNOVHhUGRG03svPOeY4rdwOT 4UjGrTX5KcJADh05XrGm2OTPwtoIwerplYpe5lmisC+fRdp0wo9TZMdARKFmrnN75B4v P2Ow== 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=oDCGh+Hfyzp4ezaxevmAUyfg8LPskX1Kh8X66qfDuy8=; b=wX4qa4DcbR4JVY3WP5QuX/4e7avquvfWp0a56ffCNk21oCZ4yN9Q8iS/0RD1joPDZn VAfRqY7Ah3q0aSrY10pCoJKj7GQvYoXmAS2+l1/XruJ7T/zi44YNMzUBSVOiC8maRBjy 5VSqQnmyOpu/RRPzkqqEQLRBd6ZMDTbiVTq2xavnE4DjaGvuNelfmUqtxOTS8hKSHmfK /zN5PVwEPW1AX4kgLOTWZmAGjCkM5DfWW0JjhKWrOuqx3g5pEHMoiDprBGvAGDe4u7SB X0wB/kBd44NfduyRQJkkSjhcKjSV27kmCATLOz0iXPoG3e6sRCkDi7xd/ofYoi8ppkYj NTjg== 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 s8-v6si10269727ote.403.2018.09.21.15.17.52 for ; Fri, 21 Sep 2018 15:17:52 -0700 (PDT) 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 D31AE15AD; Fri, 21 Sep 2018 15:17:51 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BC9763F557; Fri, 21 Sep 2018 15:17:48 -0700 (PDT) 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 , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 02/18] ACPI / APEI: Generalise the estatus queue's add/remove and notify code Date: Fri, 21 Sep 2018 23:16:49 +0100 Message-Id: <20180921221705.6478-3-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-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 grow/shrink code and 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. The existing ghes_estatus_pool_shrink() is folded into the new ghes_estatus_queue_shrink_pool() as only the queue uses it. _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 v3: * Removed dupicate 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 | 100 +++++++++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 35 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index f5732e6b5be8..29d863ff2f87 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -747,6 +747,51 @@ static void __process_error(struct ghes *ghes) #endif } +static int _in_nmi_notify_one(struct ghes *ghes) +{ + int sev; + + if (ghes_read_estatus(ghes, 1)) { + ghes_clear_estatus(ghes); + return -ENOENT; + } + + sev = ghes_severity(ghes->estatus->error_severity); + if (sev >= GHES_SEV_PANIC) { +#ifdef CONFIG_X86 + oops_begin(); +#endif + ghes_print_queued_estatus(); + __ghes_panic(ghes); + } + + if (!(ghes->flags & GHES_TO_CLEAR)) + return 0; + + __process_error(ghes); + ghes_clear_estatus(ghes); + + 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(); + + if (IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG) && !ret) + irq_work_queue(&ghes_proc_irq_work); + + return ret; +} + static unsigned long ghes_esource_prealloc_size( const struct acpi_hest_generic *generic) { @@ -762,11 +807,24 @@ static unsigned long ghes_esource_prealloc_size( return prealloc_size; } -static void ghes_estatus_pool_shrink(unsigned long len) +/* After removing a queue user, we can shrink the pool */ +static void ghes_estatus_queue_shrink_pool(struct ghes *ghes) { + unsigned long len; + + len = ghes_esource_prealloc_size(ghes->generic); ghes_estatus_pool_size_request -= PAGE_ALIGN(len); } +/* Before adding a queue user, grow the pool */ +static void ghes_estatus_queue_grow_pool(struct ghes *ghes) +{ + unsigned long len; + + len = ghes_esource_prealloc_size(ghes->generic); + ghes_estatus_pool_expand(len); +} + static void ghes_proc_in_irq(struct irq_work *irq_work) { struct llist_node *llnode, *next; @@ -965,48 +1023,22 @@ static LIST_HEAD(ghes_nmi); static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) { - struct ghes *ghes; - int sev, ret = NMI_DONE; + int ret = NMI_DONE; if (!atomic_add_unless(&ghes_in_nmi, 1, 1)) return ret; - list_for_each_entry_rcu(ghes, &ghes_nmi, list) { - if (ghes_read_estatus(ghes, 1)) { - ghes_clear_estatus(ghes); - continue; - } else { - ret = NMI_HANDLED; - } - - sev = ghes_severity(ghes->estatus->error_severity); - if (sev >= GHES_SEV_PANIC) { - oops_begin(); - ghes_print_queued_estatus(); - __ghes_panic(ghes); - } + if (!ghes_estatus_queue_notified(&ghes_nmi)) + ret = NMI_HANDLED; - if (!(ghes->flags & GHES_TO_CLEAR)) - continue; - - __process_error(ghes); - ghes_clear_estatus(ghes); - } - -#ifdef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG - if (ret == NMI_HANDLED) - irq_work_queue(&ghes_proc_irq_work); -#endif atomic_dec(&ghes_in_nmi); return ret; } static void ghes_nmi_add(struct ghes *ghes) { - unsigned long len; + ghes_estatus_queue_grow_pool(ghes); - 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"); @@ -1016,8 +1048,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)) @@ -1028,8 +1058,8 @@ 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); + + ghes_estatus_queue_shrink_pool(ghes); } #else /* CONFIG_HAVE_ACPI_APEI_NMI */ From patchwork Fri Sep 21 22:16: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: 10611017 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 B97AC14BD for ; Fri, 21 Sep 2018 22:17:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AC5E32E6DC for ; Fri, 21 Sep 2018 22:17:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0B2F2E6E3; Fri, 21 Sep 2018 22:17:59 +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 49AD22E6DC for ; Fri, 21 Sep 2018 22:17:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 50B468E0014; Fri, 21 Sep 2018 18:17:58 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4E1758E0001; Fri, 21 Sep 2018 18:17:58 -0400 (EDT) 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 3A8A58E0014; Fri, 21 Sep 2018 18:17:58 -0400 (EDT) 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 128688E0001 for ; Fri, 21 Sep 2018 18:17:58 -0400 (EDT) Received: by mail-ot1-f72.google.com with SMTP id q3-v6so13806908otl.14 for ; Fri, 21 Sep 2018 15:17:58 -0700 (PDT) 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=tLY63TKE4myS/mWyo9MZfSxBAOmWW4ke/duPxwghuiA=; b=bNaq6du1JNM4gC8Ol5nBl41+6WuhTdx3SbBYV9BQtX7zXFdp3uks+v+jkXkz/fi/wO heSt8cXT3Zhf+VJSMk+9Sx0K00E0odcFmFVj6IlP7X8ygsrL0GtlYhGDYf4yAWyp21fA ceOnqFrRT5Epk0q7EAWr4EgI9ZwnDOP7XcKleg/t0E4SlK+KnTq6N0QcVV0MeuiNXt+N I7v705LWNNoaVYMXiQOjgrU5Of+MJj4GliKyoOt3Tn8hwHiu39NqY6AW84FehPNri6Fx Pq0KCaK2K/4+q2AksbVynhILdTPQZRv/HpoSOG3jv4t38Z+C6m50ista2I2J53oZd3Di 4Bng== 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: APzg51CfBltBJWxw5tUqL/K+yfBnYmJuX+R6SXMy627OXzP+/BHevBsr l+bUHWGyTRG5ugv/kFfJx6XfZYONB32jPd1+Ob7Bjxtob1AWcAyM/eG9sXYNabWYyCQ3xU/pl0U EPjqg+d0ehbWJPovwY+ZgA3CW32zFRMggDfymO0CZnudvqr9TCNrjwqQf3rjqDYI3eg== X-Received: by 2002:a9d:9a1:: with SMTP id q30-v6mr25169223otd.351.1537568277830; Fri, 21 Sep 2018 15:17:57 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbw9hHwXOVfRLIPXCRPaXIz2e0DmaVBD1Tgs7CxEe1fccW1w5OTW5gA+e82L+mQ4Ua+GqZ0 X-Received: by 2002:a9d:9a1:: with SMTP id q30-v6mr25169195otd.351.1537568276945; Fri, 21 Sep 2018 15:17:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568276; cv=none; d=google.com; s=arc-20160816; b=Hxmb9M5MPSFsbOPxpst5RnuhPwFYGKf5qPUTqketre4bhD4hXu0J47Lc1QqJRFQMM+ 7A3YLgo3MOum3oxMGqbWOhNM27sI/H5Khuf3Ejtl3jLrXJLvLIV7vWVWER29vT+NeCBO M7uWAwcBxXbwdxwuccQvRFgZxBqBYt0qyrEgEfZu9OByrcTx2kldJSQ9bLkRZBjQYlWE 4uQlXWAATAWhEBQ3X+0yCTcpDkkOfTEOYV3q1mf6jHtz+FJhHjo0noHBmIPI+eNBbR+n wmSoNXrpdHQEVzxrhijQ/9x5mMwvpjb2pnF3YfTBgFlfKxireJR7Etkb+OCF0YoRJCtA MBUQ== 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=tLY63TKE4myS/mWyo9MZfSxBAOmWW4ke/duPxwghuiA=; b=ddfMoZltrIKeAOQK66cRVHP3jZNQq6PaRUXfoabo7+Ueh3db4U7k1yegdU1czD9B5W zYvNcFYmHF7GF+DQsaKIkkKfepZb0P4v0VKMwqmendK9A+w6YE4RjlbTLV8IveuUOSgk wlsMJIO+f4x8o52ScOSCPaxJlOll2xSPhqlAXzduqdiuIPYU21AKhxs1BUMQuAyXZ8rs r5zeK79n5Ye6bwCTm6reT2AV95dZpacqcdTWg0PrpMLX5iQyM9J+kvRGaXutkrMK5y4t jy5zwB0fRvj/e8KOAf8kQ4c3/+2luzkk+J+5j/HD+VIsSuphqCymE0fY+rKSrYxUEFbM P/nA== 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 x19-v6si11961739oix.68.2018.09.21.15.17.56 for ; Fri, 21 Sep 2018 15:17:56 -0700 (PDT) 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 525E31596; Fri, 21 Sep 2018 15:17:56 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3DFC83F557; Fri, 21 Sep 2018 15:17:53 -0700 (PDT) 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 , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 03/18] ACPI / APEI: don't wait to serialise with oops messages when panic()ing Date: Fri, 21 Sep 2018 23:16:50 +0100 Message-Id: <20180921221705.6478-4-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-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 we can panic(), our only goal is to print this fatal error and panic(). This code is always called in_nmi(), and since 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 --- drivers/acpi/apei/ghes.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 29d863ff2f87..d7c46236b353 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -758,9 +757,6 @@ static int _in_nmi_notify_one(struct ghes *ghes) sev = ghes_severity(ghes->estatus->error_severity); if (sev >= GHES_SEV_PANIC) { -#ifdef CONFIG_X86 - oops_begin(); -#endif ghes_print_queued_estatus(); __ghes_panic(ghes); } From patchwork Fri Sep 21 22:16: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: 10611019 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 AD4ED5A4 for ; Fri, 21 Sep 2018 22:18:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B5A02AD9C for ; Fri, 21 Sep 2018 22:18:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C1D52AAD0; Fri, 21 Sep 2018 22:18: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 1D45B29D97 for ; Fri, 21 Sep 2018 22:18:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C51B8E0015; Fri, 21 Sep 2018 18:18:02 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 09B4A8E0001; Fri, 21 Sep 2018 18:18:02 -0400 (EDT) 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 EF3D08E0015; Fri, 21 Sep 2018 18:18:01 -0400 (EDT) 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 C2F8C8E0001 for ; Fri, 21 Sep 2018 18:18:01 -0400 (EDT) Received: by mail-ot1-f72.google.com with SMTP id n23-v6so13825538otl.2 for ; Fri, 21 Sep 2018 15:18:01 -0700 (PDT) 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=uhuKrpMkALaclkRhTZlwBer2cfI37HrF+E5FN6AkaoY=; b=nV7c+wWgMlvos09scB7q/Jb4jIKiKLr2EzrqrQb0Fai3dgkJWzmuf2IE2t4ULjJSVI gCz7KaFQeFAKFo2KAftX2FXBpwjsMgj3MSZ3OCBicqjWHmKKtxaofvCnpI3wqcq0g2YI AmY8NXlfEVOqiGH78BVVq6eyIjhOj5SwChKMDGewE/garzxq+B1C4pGZGgjPGp/7NACG Ii/DlgTKy6hUpuisEYn9aFW1tQeDqPKPrFu/AjPjitJDg0QWDdsv/ttE2lRECBTmEV5Y N5Us7qm2LOrMli5Yop7RvpzSl247gO+zlwfnGSrAZgYUiQtIXC7CT2bFBfUMP+admN/3 Z2CQ== 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: APzg51DYTgg4BA/KsZIKFwM9UZcusM8CLx+W8HfEfGM8GgeOtys1Q9fY x5bmkKtE0QmuhTfIjnMsYPLx6i3+3rX9PbvGCQW6GC+/2yysY9BYUDEd/xPEpLn/HPjYOoPQjfJ Gb0mTMqORpbth0FrfmpomG8k7ApJ0KkGhoLAG0NU/0+TbhfeIbhBZmyuXbIjuLutClw== X-Received: by 2002:aca:e089:: with SMTP id x131-v6mr305253oig.221.1537568281582; Fri, 21 Sep 2018 15:18:01 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYq3WJTwL/WxKJpy2bKOKQ1czj28tGlbBoeeAYXI4Gc63zQurkoxQNixHjEooeMR7w7FlYW X-Received: by 2002:aca:e089:: with SMTP id x131-v6mr305220oig.221.1537568280745; Fri, 21 Sep 2018 15:18:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568280; cv=none; d=google.com; s=arc-20160816; b=Y6V2ngLU5Ktm37vI4wUGjY065vOrNCyqwpoxREPlkC60ziPg2YCHBmcIXXYwAbvzeg cL4RuFhKGU4pWtHc8mUGxBJfFLvMOOTRgiLCLEdSehZP6Djm5vKLa8EecFDkG1BEJCvM WSlPeU9BURikxd/4YCdVfBbHc/oe3wJL1/9Lfuh0TSm7uIqOYigxDQW5Ezxe71q+fEfT VH0sx7fW1tfkKY7Ik4cLAK3BHdpLrtrKb57JGyqUB3EwwQtlQYmxKKhFBp4j6B/mQi6f 6BURFMVP51WvXWVXaNTS0O8NHuxDV/zKKHnF0bytZU+c6seVpxIjpEmtrMzG7rALvgSQ NzFA== 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=uhuKrpMkALaclkRhTZlwBer2cfI37HrF+E5FN6AkaoY=; b=hTZ+WXqcJcM0zZbapEBA/jpaumtOD5im4JPDo66vhekEqO7SRvcAPOgZSApzKLeY1C ttY7gdgglJU0iT9232olf9iV/oTrrlKIpjCMbZ4E0kXhWVxvutMxgAcOdjy/b5FhlWr4 aJKyuWx5MK6qlrG6XYRrDHIvDjA0kGJREfx3kq1kNWzrlIaZJZnvwB2AsLbRNZPhbKHe naxja+DbASpVAkB1Udb0pAapnYk6Zdmuon5i4ZQsEKCsyyh9V0lZ7I1INB0YIHvFC651 2WuaU/Zx5xjEfubJmlWk2pXgNaAPIyrGFQ4CY1mAFQjIDpeIvt3Xtpb0c/pHo65ZiCVa HHHw== 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 a65-v6si10915340otc.361.2018.09.21.15.18.00 for ; Fri, 21 Sep 2018 15:18:00 -0700 (PDT) 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 5528C15BE; Fri, 21 Sep 2018 15:18:00 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 404DE3F557; Fri, 21 Sep 2018 15:17:57 -0700 (PDT) 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 , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 04/18] ACPI / APEI: Switch NOTIFY_SEA to use the estatus queue Date: Fri, 21 Sep 2018 23:16:51 +0100 Message-Id: <20180921221705.6478-5-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-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 to it, and start abstracting GHES's single in_nmi() path. Switch NOTIFY_SEA over to use the estatus queue. This makes it behave in the same way as x86's NOTIFY_NMI. Signed-off-by: James Morse Reviewed-by: Punit Agrawal Tested-by: Tyler Baicar --- drivers/acpi/apei/ghes.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index d7c46236b353..150fb184c7cb 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -58,6 +58,10 @@ #define GHES_PFX "GHES: " +#if defined(CONFIG_HAVE_ACPI_APEI_NMI) || defined(CONFIG_ACPI_APEI_SEA) +#define WANT_NMI_ESTATUS_QUEUE 1 +#endif + #define GHES_ESTATUS_MAX_SIZE 65536 #define GHES_ESOURCE_PREALLOC_MAX_SIZE 65536 @@ -681,7 +685,7 @@ static void ghes_estatus_cache_add( rcu_read_unlock(); } -#ifdef CONFIG_HAVE_ACPI_APEI_NMI +#ifdef WANT_NMI_ESTATUS_QUEUE /* * Handlers for CPER records may not be NMI safe. For example, * memory_failure_queue() takes spinlocks and calls schedule_work_on(). @@ -861,7 +865,7 @@ static void ghes_nmi_init_cxt(void) #else static inline void ghes_nmi_init_cxt(void) { } -#endif /* CONFIG_HAVE_ACPI_APEI_NMI */ +#endif /* WANT_NMI_ESTATUS_QUEUE */ static int ghes_ack_error(struct acpi_hest_generic_v2 *gv2) { @@ -977,20 +981,13 @@ 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) { + ghes_estatus_queue_grow_pool(ghes); + mutex_lock(&ghes_list_mutex); list_add_rcu(&ghes->list, &ghes_sea); mutex_unlock(&ghes_list_mutex); @@ -1002,6 +999,8 @@ static void ghes_sea_remove(struct ghes *ghes) list_del_rcu(&ghes->list); mutex_unlock(&ghes_list_mutex); synchronize_rcu(); + + ghes_estatus_queue_shrink_pool(ghes); } #else /* CONFIG_ACPI_APEI_SEA */ static inline void ghes_sea_add(struct ghes *ghes) { } From patchwork Fri Sep 21 22:16: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: 10611025 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 72A615A4 for ; Fri, 21 Sep 2018 22:18:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62E8D2CF2B for ; Fri, 21 Sep 2018 22:18:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 562272CF55; Fri, 21 Sep 2018 22:18:08 +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 E40C32CF2B for ; Fri, 21 Sep 2018 22:18:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C84878E0016; Fri, 21 Sep 2018 18:18:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id C59FC8E0001; Fri, 21 Sep 2018 18:18:06 -0400 (EDT) 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 B49D98E0016; Fri, 21 Sep 2018 18:18:06 -0400 (EDT) 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 8B06D8E0001 for ; Fri, 21 Sep 2018 18:18:06 -0400 (EDT) Received: by mail-ot1-f72.google.com with SMTP id j65-v6so13813357otc.5 for ; Fri, 21 Sep 2018 15:18:06 -0700 (PDT) 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=Cy2z5ioh7lrkiGogBYRabgSup7PludHtyjIyxhDrobI=; b=JMMfKbI4/IipKfDCZiXGYrpZaNwkNInkWprh49XxiZ2bjxAPO+j3BSx8Ykg1IeWsGR If5MS0Pqt+kgFuVv6EcXrnVNwUWnrNrMEBLM1yPDf8WvqiadZqNuOl58JqvQgsAbE3bL jQSHzrBPQQBccREdQGNsnmFAfaaw/JxXs0+1S8vYEtg5n0PfUVRcrcsTlZsxQHZnZog4 uPpGNNL7ywuJCEQfq/uym7rmFO7sXUwVygnAklnQqPXuMNMMePa+952KbU8DU2pkaB2L rOm1uul8RYac/6gQdJoj1xqvEMSyuM4yk6g+c3BDgPSzlIQ3QuwAeYxfGD0Kl0CYwjtO YMZA== 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: APzg51CAzoB4pcVukOyo7ASpCZr5c0cD3nBiFYI1t6vI/EeZcr1Z2ot0 oQZG497mfz2tIza1Q8n8p9f8zBHL2l0UXToUbAQ5WgbfY1mN36LN2dEvGRWfXsyLTpk1VdH7jIJ Xv8HTrGe0/l2zJ7qbgXg+e1B9DVuM2RpsDMD5/1Wb08RSINeuHDRuS6h22zAs9R2gAQ== X-Received: by 2002:aca:e748:: with SMTP id e69-v6mr303473oih.263.1537568286342; Fri, 21 Sep 2018 15:18:06 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdb+HSvihQ5lzIDbBk+LdV2go12PHok/MhECVui2VdgIUACYGNm5qSxlo2ms7Ej13LGrslEX X-Received: by 2002:aca:e748:: with SMTP id e69-v6mr303443oih.263.1537568285390; Fri, 21 Sep 2018 15:18:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568285; cv=none; d=google.com; s=arc-20160816; b=yuio02FvOi8JgnRgvU44d7T2TrQnFm3SomEKdHEtWxXQmJJG992zc5VP1Th6gGIbI3 a1tXPlF9yvv60Y9C5nQwpDjQ3OQ7DUj5TBE7f/xIFujbQMvhZnr+26SKM7NVRWCct1Cl jN4SDR3fSBV2w0zqA+R+ps7l4qp8EUXeGq0lmmGyyrXMVZFab8KMSbT13tkofEsqBhnV SJnuoIJNDKTaFhveOoVggMYaM7snfMF041r87IP4gad8ETSySIac+PGKaN+VMXcvj/+N yksb5GPCVxUWuHs5gWAL2LyzQ4vxbS7yk8v8fYvJk/diehybBJRE8Dly1onIFE5MwAAm z4Wg== 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=Cy2z5ioh7lrkiGogBYRabgSup7PludHtyjIyxhDrobI=; b=v/1gxbkZWMosfgp3Ke9dcFwl140PMAM2MAdbqXuX1+iENImxYXWwUY1+FprJDlFZQV J6hmayajlUm1pKHXDQcbE3b8K5fy4EZbJBWifI43J2TQzWoC2VDSePr4MjWRNJ2n6Mbn NrR4buwtYuFxtHN9DtkqrW1e7TSuf8NuohNqfXjzrQlPphTzA6Ww10PUBas4Im1MCjrm 5q3RF7w/drLyZ8U0koNl8sZK2L6FYBTf2Y6T+dHra/cFAUiN4QJwvGYpfWhen++r66mU Iv5dMRdmhUikYWhjvBtL8TpGYgwuXNwPbRwC3meWToHEZ27shNJIl7VfntlqDMIhA2RI 8gDA== 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 i11-v6si13063711oia.112.2018.09.21.15.18.05 for ; Fri, 21 Sep 2018 15:18:05 -0700 (PDT) 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 DD2FF15BF; Fri, 21 Sep 2018 15:18:04 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id C80763F557; Fri, 21 Sep 2018 15:18:01 -0700 (PDT) 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 , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 05/18] ACPI / APEI: Make estatus queue a Kconfig symbol Date: Fri, 21 Sep 2018 23:16:52 +0100 Message-Id: <20180921221705.6478-6-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-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 there are two users of the estatus queue, and likely to be more, make it a Kconfig symbol selected by the appropriate notification. We can move the ARCH_HAVE_NMI_SAFE_CMPXCHG checks in here too. Signed-off-by: James Morse --- drivers/acpi/apei/Kconfig | 6 ++++++ drivers/acpi/apei/ghes.c | 12 +++--------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/acpi/apei/Kconfig b/drivers/acpi/apei/Kconfig index 52ae5438edeb..2b191e09b647 100644 --- a/drivers/acpi/apei/Kconfig +++ b/drivers/acpi/apei/Kconfig @@ -4,6 +4,7 @@ config HAVE_ACPI_APEI config HAVE_ACPI_APEI_NMI bool + select ACPI_APEI_GHES_ESTATUS_QUEUE config ACPI_APEI bool "ACPI Platform Error Interface (APEI)" @@ -33,6 +34,10 @@ config ACPI_APEI_GHES by firmware to produce more valuable hardware error information for Linux. +config ACPI_APEI_GHES_ESTATUS_QUEUE + bool + depends on ACPI_APEI_GHES && ARCH_HAVE_NMI_SAFE_CMPXCHG + config ACPI_APEI_PCIEAER bool "APEI PCIe AER logging/recovering support" depends on ACPI_APEI && PCIEAER @@ -43,6 +48,7 @@ config ACPI_APEI_PCIEAER config ACPI_APEI_SEA bool "APEI Synchronous External Abort logging/recovering support" depends on ARM64 && ACPI_APEI_GHES + select ACPI_APEI_GHES_ESTATUS_QUEUE default y help This option should be enabled if the system supports diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 150fb184c7cb..2880547e13b8 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -58,10 +58,6 @@ #define GHES_PFX "GHES: " -#if defined(CONFIG_HAVE_ACPI_APEI_NMI) || defined(CONFIG_ACPI_APEI_SEA) -#define WANT_NMI_ESTATUS_QUEUE 1 -#endif - #define GHES_ESTATUS_MAX_SIZE 65536 #define GHES_ESOURCE_PREALLOC_MAX_SIZE 65536 @@ -685,7 +681,7 @@ static void ghes_estatus_cache_add( rcu_read_unlock(); } -#ifdef WANT_NMI_ESTATUS_QUEUE +#ifdef CONFIG_ACPI_APEI_GHES_ESTATUS_QUEUE /* * Handlers for CPER records may not be NMI safe. For example, * memory_failure_queue() takes spinlocks and calls schedule_work_on(). @@ -727,7 +723,6 @@ static void ghes_print_queued_estatus(void) /* Save estatus for further processing in IRQ context */ static void __process_error(struct ghes *ghes) { -#ifdef CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG u32 len, node_len; struct ghes_estatus_node *estatus_node; struct acpi_hest_generic_status *estatus; @@ -747,7 +742,6 @@ static void __process_error(struct ghes *ghes) estatus = GHES_ESTATUS_FROM_NODE(estatus_node); memcpy(estatus, ghes->estatus, len); llist_add(&estatus_node->llnode, &ghes_estatus_llist); -#endif } static int _in_nmi_notify_one(struct ghes *ghes) @@ -786,7 +780,7 @@ static int ghes_estatus_queue_notified(struct list_head *rcu_list) } rcu_read_unlock(); - if (IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG) && !ret) + if (!ret) irq_work_queue(&ghes_proc_irq_work); return ret; @@ -865,7 +859,7 @@ static void ghes_nmi_init_cxt(void) #else static inline void ghes_nmi_init_cxt(void) { } -#endif /* WANT_NMI_ESTATUS_QUEUE */ +#endif /* CONFIG_ACPI_APEI_GHES_ESTATUS_QUEUE */ static int ghes_ack_error(struct acpi_hest_generic_v2 *gv2) { From patchwork Fri Sep 21 22:16: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: 10611029 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 52C505A4 for ; Fri, 21 Sep 2018 22:18:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45D5A2D238 for ; Fri, 21 Sep 2018 22:18:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39F582D2DB; Fri, 21 Sep 2018 22:18:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7B412D238 for ; Fri, 21 Sep 2018 22:18:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9285F8E0017; Fri, 21 Sep 2018 18:18:11 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8D8058E0001; Fri, 21 Sep 2018 18:18:11 -0400 (EDT) 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 7EF338E0017; Fri, 21 Sep 2018 18:18:11 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi0-f69.google.com (mail-oi0-f69.google.com [209.85.218.69]) by kanga.kvack.org (Postfix) with ESMTP id 5023B8E0001 for ; Fri, 21 Sep 2018 18:18:11 -0400 (EDT) Received: by mail-oi0-f69.google.com with SMTP id b8-v6so13459691oib.4 for ; Fri, 21 Sep 2018 15:18:11 -0700 (PDT) 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=hFs2zpmTOS7tfV4GbEaJY2QzACMTsqtMSbp0U45C8jE=; b=SRSAt9vwnxFDtEJL8tLOBlZ/V4soBzQqmbXarJb5KRtg7Xeqk/1fxf0h05RJYlmLF8 FhN6qWLaBcWGIxNAxDvzFD3z8e0IeV8bEq+Flva2TFxYpy2X2hAFd+Vm/k5qmBt0hPN4 a2BpW/HdUNrZCunHjjPCPuMtJNql/TqQmjcg0ZWpc5vjaR6Sslb/bGGqJUc9uDdDGo7p msZKDIC0dFLx9Jbc+a5mGpFx7AFh8ZmpPk2Iq/IVsGuNK6fc5caR7umNbFW3BxcJ4Pl+ eNwolyTgq4Obmkhc1vdGrrsHDEov50NHES3fayxoSBdu3kL1CjgVjttK4wa2tcXsvF34 svgQ== 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: APzg51Bs17Eqw1/k+FAcJkrdElkwgoMGhQdvVo4UcQ8RW2CyNNtJEGhL Qroymtlobju8K74rOvvQRET4S5x98fZ2eWn5gOoZKmlpIPC9mZp0BbLxB/TqS6kQUgUmptXSB0D dYB82EIpN2UwZek7aGaPWv1oS1Qd2GJU5OlNpolJ/vv5a5VGFWwMZWn/RnjosyEhhgg== X-Received: by 2002:a9d:3bf5:: with SMTP id k108-v6mr27817219otc.349.1537568291007; Fri, 21 Sep 2018 15:18:11 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaM30SRQHmvtpIxnGtRFkimW1mAzxk9Br9YljEfjIJDoumA3lZ83bnSeNxr3qhoBO4OixOF X-Received: by 2002:a9d:3bf5:: with SMTP id k108-v6mr27817181otc.349.1537568289930; Fri, 21 Sep 2018 15:18:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568289; cv=none; d=google.com; s=arc-20160816; b=Rjfl07fi0IXEFSaxEJz9A3Oes6wGiUFqsRBHNainUDFKbwLvwqEWvlEy8dNUTIXWCk eDmm1nt7zsnkos8qXoRpxuzoR1b6koPVVKjqi+j9MiUjaBgoOI9B/YpfcBzQWM1kcbBh IBGRoC14qVXZBP82o5bKNtZi6u3rXQw+aJ4W/jL4GpU0DDAwk/zR9f5PF/lpwP6/3WBJ otETg858rkhAc8y9IiDDD9BZ+5FGSO9WgtffuVUlyr1SC/HD7orVBo0Z03QW4x4Bcr99 FDEQSzgvfPOuq70yWyzlCf6RFXVgeS6wO5xWUzt8/0l7QFrnoaxhK27JLIC3SwS6ahUJ NDDg== 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=hFs2zpmTOS7tfV4GbEaJY2QzACMTsqtMSbp0U45C8jE=; b=XTccCmfuTSKxBBUA4d3u3L0CmxUFQa0LRDdPPrgljHt2mTWEMYt2sQd7qASpXKXWjP cE6rVEzH39FXKTQQqWDk+wpsJSa3pKb36aiDrYFx62m77GXv91XT15h/oTRU6/w/mUaf QU2YUaBbYk5V9d2mjSp6RPBome9o4gwf27q8DIJEYdvbo70rPmQADC/pUBAWsYjq/GcW rICE4GuHSrzN83s2BFczLSyy5l4cBQQK2C4j9j1aygQIQMId+BYBsBamosIrN/VmQaPA cUoqOm0vrLk3yMCm+OYPietBshnYfIV/knoM2zcT6Qmr/+uvGxKXis04vTyT731cOCy6 Suqw== 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 r204-v6si12032213oih.29.2018.09.21.15.18.09 for ; Fri, 21 Sep 2018 15:18:09 -0700 (PDT) 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 662C718A; Fri, 21 Sep 2018 15:18:09 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5173B3F557; Fri, 21 Sep 2018 15:18:06 -0700 (PDT) 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 , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 06/18] KVM: arm/arm64: Add kvm_ras.h to collect kvm specific RAS plumbing Date: Fri, 21 Sep 2018 23:16:53 +0100 Message-Id: <20180921221705.6478-7-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-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, we need any nmi-like callers 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 we support 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 --- 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..aaff56bf338f --- /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..5f72b07b7912 --- /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 28893a0b141d..48ded3628a89 100644 --- a/arch/arm64/include/asm/system_misc.h +++ b/arch/arm64/include/asm/system_misc.h @@ -45,8 +45,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 50b30ff30de4..1a30d7a8c9bf 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -725,7 +725,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 ed162a6c57c5..100c8f2d67ac 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" @@ -1699,7 +1699,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 Fri Sep 21 22:16: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: 10611033 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 2E20D14BD for ; Fri, 21 Sep 2018 22:18:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 203462D238 for ; Fri, 21 Sep 2018 22:18:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1454C2D2DB; Fri, 21 Sep 2018 22:18:18 +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 6873F2D238 for ; Fri, 21 Sep 2018 22:18:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 422928E0018; Fri, 21 Sep 2018 18:18:16 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3CF158E0001; Fri, 21 Sep 2018 18:18:16 -0400 (EDT) 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 296CF8E0018; Fri, 21 Sep 2018 18:18:16 -0400 (EDT) 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 F3E818E0001 for ; Fri, 21 Sep 2018 18:18:15 -0400 (EDT) Received: by mail-ot1-f69.google.com with SMTP id q3-v6so13807674otl.14 for ; Fri, 21 Sep 2018 15:18:15 -0700 (PDT) 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=icR6tn2J9gdMnwoNflR020W7wn+Aa33OrG5orolU8LM=; b=J9QTHMAroFRI/8CyBYqpLXeWglEAbUQM0GWhPk870iB23od84GvzXncruq6HAKaPKA 19D2wI1eHR4PVLqxnK1MmWobN8Au2nhri91JYr8MKx4ZX1eHLHnF/LUBrDaa2RfpHlcF Az3jPQrEP9ZDDvOGTSQfhXrbm5AaIWIa7l89ZJfdXErrpA8jo06FmEGmoBZ5EQ8QffBI aCiev2NWrxnT3LvkrwXOnFwpcHtuToTLO/3EVZbmxYg0iGra1nI/PUtLC/lBZXRzCS0D Bn/Xk52VRWEa6QQH6lL89IQMfkrUlJ/EwkDhR4h+rVnw8c1/Q8d7D4kIlhAuAb9q33wG Jwjw== 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: APzg51BqDmG54qP9sEwJMIimEp3TvWK36jDib5W6JZXHyKFL4GnlqzUh 0Kk+e2raXXFZs63dTNI2tezkI6Ze0Cy/1ZS8Wv7UWeNiI94QbpUvDyrFGtbnZ47OzAG9dp++Tzt 7JTn7tOIuDvIFzpa/4DRrIT8N+W+hO0xxHTE4gPmD5u+hbHKwApYCZz6bG2wUHKbgfA== X-Received: by 2002:a9d:a6:: with SMTP id w35-v6mr25336632oti.109.1537568295727; Fri, 21 Sep 2018 15:18:15 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY3kIgUREmFKaWnkmO21f2urOPWfGApmVov04+tMubE3rviSyY7vsmsgOZHPl4iv5C7JAEk X-Received: by 2002:a9d:a6:: with SMTP id w35-v6mr25336589oti.109.1537568294500; Fri, 21 Sep 2018 15:18:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568294; cv=none; d=google.com; s=arc-20160816; b=DdHSwjgAEm8/TUPBwOCTFlZbN+HN8r9cbhhx2gCG0MaIIGU2sLWFK/NVUooNNMTaTz E9vSJQXFjGAl2muNQTDQGVmqpWECvgjTagWCFKe5ExMTfCpGvp1sZwydtpyuqkJV5C/m raXOn9XwbqhKLUKu5nAcXCT9UavD1iAl6Q5DF0oRJJry4DT4gzCwZYMrKNE5zULh0Dsd AyJYd23TwV/jYBF4/TV/5wkAGxVu0ZthvHj+0wsjxfNJgu/Z/J/euCWXdK0FVXHfR/fX 0N/NbEZuM+XZ+proMf7bT5yA30RXKmNCk96f7GQwdkc7H+mdyHf5sQYOk2/95jzVuiU1 L0fQ== 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=icR6tn2J9gdMnwoNflR020W7wn+Aa33OrG5orolU8LM=; b=D8xjwQkFG4Rf9Q2VYnvtRDh6RHWPIFxryrL3MG6Y0l/UNBAYVYGK4yezEDw00tf+vh Z4g7CO/glWvUDujyDe7Ka22r1eelI1EAlJ3H69Rpfm5XxT2dhYQdplL3erPFmLd5EkdE z2bXc8TwAtXylI2cXV+sWsZ30SRT24QgsQWTdu9oBmq25OS8ZAoUUB8l2CTjAqikg3cd MvwjwlVuELC2kHLnWVXT0AF7B/ta3zRuzt0+9Rs0BnpvMcGmPblbPOz9215PNdvFc1/4 B6Wvwh3Lyb1ji1z+zGezPZFgkBhjtYULMncYOwFeIU1K0KVVQDzEKYeBQdI9+FGs82JU OMIQ== 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 g49-v6si258130otg.66.2018.09.21.15.18.14 for ; Fri, 21 Sep 2018 15:18:14 -0700 (PDT) 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 0012A15AD; Fri, 21 Sep 2018 15:18:13 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DEE6E3F557; Fri, 21 Sep 2018 15:18:10 -0700 (PDT) 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 , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 07/18] arm64: KVM/mm: Move SEA handling behind a single 'claim' interface Date: Fri, 21 Sep 2018 23:16:54 +0100 Message-Id: <20180921221705.6478-8-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-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, we need the nmi-like callers 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. We can then go on to see if (a future) kernel-first mechanism wants to claim the notification, before falling through to the existing default behaviour. The NOTIFY_SEA code was merged before we had multiple, possibly interacting, NMI-like notifications and the need to consider kernel first in the future. Make the 'claiming' behaviour explicit. As we're restructuring the APEI code to allow multiple NMI-like notifications, any notification that might interrupt interrupts-masked code must always be wrapped in nmi_enter()/nmi_exit(). This allows APEI to use in_nmi() to use the right fixmap entries. We 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 --- 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 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. squash: make 'call with irqs unmaksed' a lockdep assert, much better --- 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 | 29 +++++++++++++++++++++++++++++ arch/arm64/mm/fault.c | 24 +++++------------------- 5 files changed, 54 insertions(+), 20 deletions(-) diff --git a/arch/arm64/include/asm/acpi.h b/arch/arm64/include/asm/acpi.h index 709208dfdc8b..f722d2d6bf2b 100644 --- a/arch/arm64/include/asm/acpi.h +++ b/arch/arm64/include/asm/acpi.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -139,6 +140,9 @@ static inline pgprot_t arch_apei_get_mem_attribute(phys_addr_t addr) { return __acpi_get_mem_attribute(addr); } +int apei_claim_sea(struct pt_regs *regs); +#else +static inline int apei_claim_sea(struct pt_regs *regs) { return -ENOENT; } #endif /* CONFIG_ACPI_APEI */ #ifdef CONFIG_ACPI_NUMA diff --git a/arch/arm64/include/asm/daifflags.h b/arch/arm64/include/asm/daifflags.h index 22e4c83de5a5..cbd753855bf3 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 5f72b07b7912..5b56e7e297b1 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 ed46dc188b22..a9b8bba014b5 100644 --- a/arch/arm64/kernel/acpi.c +++ b/arch/arm64/kernel/acpi.c @@ -28,8 +28,10 @@ #include #include +#include #include #include +#include #include #include @@ -257,3 +259,30 @@ 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 = arch_local_save_flags(); + + if (!IS_ENABLED(CONFIG_ACPI_APEI_SEA)) + return err; + + /* + * 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 1a30d7a8c9bf..2c38776bb71f 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 @@ -45,8 +47,6 @@ #include #include -#include - struct fault_info { int (*fn)(unsigned long addr, unsigned int esr, struct pt_regs *regs); @@ -631,19 +631,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); clear_siginfo(&info); info.si_signo = inf->sig; @@ -725,11 +716,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 Fri Sep 21 22:16: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: 10611037 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 6EDAD14BD for ; Fri, 21 Sep 2018 22:18:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61A9B2D238 for ; Fri, 21 Sep 2018 22:18:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55B872D2DB; Fri, 21 Sep 2018 22:18: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 BCD5B2D238 for ; Fri, 21 Sep 2018 22:18:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 904598E0019; Fri, 21 Sep 2018 18:18:20 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 8D7C38E0001; Fri, 21 Sep 2018 18:18:20 -0400 (EDT) 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 7A16B8E0019; Fri, 21 Sep 2018 18:18:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi0-f69.google.com (mail-oi0-f69.google.com [209.85.218.69]) by kanga.kvack.org (Postfix) with ESMTP id 4D2528E0001 for ; Fri, 21 Sep 2018 18:18:20 -0400 (EDT) Received: by mail-oi0-f69.google.com with SMTP id b8-v6so13460044oib.4 for ; Fri, 21 Sep 2018 15:18:20 -0700 (PDT) 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=x3Q4K7d1ZHm69LZFDvUW0P+oTOW3REEurmS8OsSR3lU=; b=JNAq6Iww6EvjJRa+XW8mogiGXNnoe0qnRMVnXmO0k4yQ1Jg2B002yqfywOB51pnXwU GGAiiArd05YXMJ+euvPzyj4KGbOoN/6IpMjM4xJMfxPL3mex/Pr82hHdRKC2s9kruLg3 +cxaIzaKzb38h6J3LN+EMPDnQvuVbKgwUZMZMqVjpA1SrUjXee/O8E6qtWASgkmIwI1J lC3IELrBrcBFt5q3ZxtGjQ7UI8guwmB6ni6Ic5rhy1u2hgVIfuUKf2ont80HkjyuFr+3 F/NT3i9cf5lNS6GIF0RUERdVO1o3Q/AY5BdT6Y2pmWcoO7mNGC9mQmlq54LXOoJc730e 4htA== 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: APzg51BV+Arsvkd28DYn7w26USywl8b3GOd4csh5ZQW6HbvuaDslds9R 9IDNRoFezTrDKs9oXVq6iRsFUcMr7pkLb/LC7YFg14HwR13eh/J7oWSbfJLahm62JUHxKM2v2G/ NopuAclfSuO4NtpVXzfd30UQYiGbOV+UkgqZKo9/Dk7GDnw1iqqmPmo62G5u2BzMYIA== X-Received: by 2002:aca:3e56:: with SMTP id l83-v6mr324959oia.170.1537568300040; Fri, 21 Sep 2018 15:18:20 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZBdwL9fyAPkB+sxxVaaNccktSw/il+FBKaJK71j7oxa85lXjZVO91+Q8bQ5cvm4tfqONyy X-Received: by 2002:aca:3e56:: with SMTP id l83-v6mr324919oia.170.1537568298807; Fri, 21 Sep 2018 15:18:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568298; cv=none; d=google.com; s=arc-20160816; b=SiAU2sRgkMGlE1qOzVk2UA4UAj5xAJqOZkRLaNjqSPBA6ebPXKJu6eocwhnT1ESX+Q DyDvrcVDMeSe0PKfOaY5bIkwF+617NEJDtFG12Y0Y6oxwavp8FyEPWPHiABdF4H80hXQ ZyHB0Z3oO5p4NV8Yg+iqKm9GilNzoUTXFHH1EgeJE9Czt/irmOKuQZXAFhtF6Pu1K4tn xkxnZozzbevYmxOGW7a6fz4LV+f1gD0u79pgeCXdS5h0lD11uWRbX3YEgu1L5zA2fooK wri62hGyNawu8MdilOe8ervgnOQNagVgyN1omNM80IwiBTAg2c+XU4Im7r34cwWgNtNX FY8A== 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=x3Q4K7d1ZHm69LZFDvUW0P+oTOW3REEurmS8OsSR3lU=; b=DCraQQ/fx6G89PPh7qlF7SJ8Fxe0AylmruOZ5tR16ouYxmFO1aX9aQCbq0vZLf7RPZ G1gRuAdjdjE0lCzSrTNUKnBvQjrNtp4DRD52CwNlpbUdQoLogT6SDx1MQ8Ky139VM5GL borvTSv7s96JUnGlnqEvJLMDwpFxNcY0OkzHvpqFnIOmNcB1HHixFnlQYxNPxG9rIKMg 4dKzD+gKDEV7Vk4a0aOQSN9+LSn2ZUi5GcnEzj1Pv5NlLHiu1IrUY5X+ekrE6sbQArHo T80GFwXBJ9wU1o+qtcl96a+JUqUgR+1luLbXUFPyfrIZxdYXZbDX/ByZ9or5jsaHKfQp AoWg== 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 s10-v6si9240045oth.173.2018.09.21.15.18.18 for ; Fri, 21 Sep 2018 15:18:18 -0700 (PDT) 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 3FDAF1596; Fri, 21 Sep 2018 15:18:18 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2AF6B3F557; Fri, 21 Sep 2018 15:18:15 -0700 (PDT) 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 , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 08/18] ACPI / APEI: Move locking to the notification helper Date: Fri, 21 Sep 2018 23:16:55 +0100 Message-Id: <20180921221705.6478-9-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-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 when we have multiple NMI-like notifications, that can interrupt each other. Now that NOTIFY_SEA is always called as an NMI, 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 v5: * Moved locking further out, to allow no-irq-masking in the future. drivers/acpi/apei/ghes.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 2880547e13b8..ed8669a6c100 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -113,12 +113,13 @@ static DEFINE_MUTEX(ghes_list_mutex); * from BIOS to Linux can be determined only in NMI, IRQ or timer * 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 - * simultaneously. */ -static DEFINE_RAW_SPINLOCK(ghes_ioremap_lock_nmi); -static DEFINE_SPINLOCK(ghes_ioremap_lock_irq); + +/* + * Used by ghes_proc() to prevent non-NMI notifications from interacting. + * This also protects the FIX_APEI_GHES_IRQ fixmap slot. + */ +static DEFINE_SPINLOCK(ghes_notify_lock_irq); static struct gen_pool *ghes_estatus_pool; static unsigned long ghes_estatus_pool_size_request; @@ -291,7 +292,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; @@ -299,10 +299,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; @@ -316,10 +314,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); } } } @@ -928,8 +924,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); } @@ -937,9 +936,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; @@ -950,14 +952,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; } @@ -968,6 +973,7 @@ static struct notifier_block ghes_notifier_hed = { #ifdef CONFIG_ACPI_APEI_SEA static LIST_HEAD(ghes_sea); +static DEFINE_RAW_SPINLOCK(ghes_notify_lock_sea); /* * Return 0 only if one of the SEA error sources successfully reported an error @@ -975,7 +981,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) @@ -1009,6 +1021,7 @@ static inline void ghes_sea_remove(struct ghes *ghes) { } static atomic_t ghes_in_nmi = ATOMIC_INIT(0); static LIST_HEAD(ghes_nmi); +static DEFINE_RAW_SPINLOCK(ghes_notify_lock_nmi); static int ghes_notify_nmi(unsigned int cmd, struct pt_regs *regs) { @@ -1017,8 +1030,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; @@ -1060,6 +1075,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; @@ -1162,7 +1178,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 Fri Sep 21 22:16: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: 10611041 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 D9D715A4 for ; Fri, 21 Sep 2018 22:18:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CBDFE2D238 for ; Fri, 21 Sep 2018 22:18:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C02AC2D2DB; Fri, 21 Sep 2018 22:18:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 305C92D238 for ; Fri, 21 Sep 2018 22:18:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EA7428E001A; Fri, 21 Sep 2018 18:18:24 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E7F868E0001; Fri, 21 Sep 2018 18:18:24 -0400 (EDT) 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 D47088E001A; Fri, 21 Sep 2018 18:18:24 -0400 (EDT) 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 A8DC78E0001 for ; Fri, 21 Sep 2018 18:18:24 -0400 (EDT) Received: by mail-ot1-f70.google.com with SMTP id k18-v6so13786890otl.16 for ; Fri, 21 Sep 2018 15:18:24 -0700 (PDT) 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=sAXZUylohXuZm+5P1yu+MS9VYyc1gfUewYxv0kdlr4I=; b=iujMND4IiGlWxJ7FSJ2BuTu0L+0Xzs6XGP1qEzMr5dXHn/fUMo4q0/ntUaJH6XxF+b Fwu8KR1IeVmTMn9v3q5yZeRzKHULNvqgbpmaX3csUKidsdoqae5IDRXzjoJjI+CuJaqX jJb2GJ8T8+5WBLJV7EtcwdqKpN0C01m6xqDkErVf0GLtUb6F1vPRQrunclSXUxXTfxSw 5Zc+HvFPr+/U+oeDz7OI9N/01vL/fkeOudAk4NE5FbwA5CrDf9/WPXUollEVJFXalobV DH2EKOMdXuS7vnW9nkYwLbu4k7I/Ai7yYvL+d5BbXAcQk5Vm+vDbqG77YzoiWepqRi91 nthw== 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: APzg51CPMgM7Lx6MQMzzBJnLesQtd2U0pcEacoplv4BD5m3iezaRmRbG xfrdoebqrEWjfALtyqXQS3Wts42RHes/xtp2OQra2kN3NZibLxSkjBSwWqhkns+QaCEPllvhLxq Ovo00/9CnxBzr4ZO01D+x26GQKY+htYIiOT9WK4EZxgFlb/OmYRxd4AnkoTsZpYNcfA== X-Received: by 2002:aca:3a57:: with SMTP id h84-v6mr343471oia.336.1537568304461; Fri, 21 Sep 2018 15:18:24 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY8+Sb1yJFlgdsWYFnmnXlSZ3A5YlCVndNGLhR5TgWMmGQWRNLXfUEol1IuqaAg66k0ByvP X-Received: by 2002:aca:3a57:: with SMTP id h84-v6mr343431oia.336.1537568303446; Fri, 21 Sep 2018 15:18:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568303; cv=none; d=google.com; s=arc-20160816; b=Lu0gIrZMW/ZKBHgsoV3LtAqrQVZ3kIYiED2Vajfwl8YxP+AU2aKAPS2FQc3OMTQoqt r5bDP4PFfWvhAS2mHfdmTVv0ZlVmz0GIfWaEjG3dPmkaIm0tvVwx2S+H23c1w0ZmuRhb Giwv/jJTvzrpiNeCb/VW4PTWJ+/xjYFtN3m8OUe952AUnppAORk5rWF0g66vGiLOviZb mXasHl7ctAz+ZOYceoA1bFazE+0WZ580nldgY+hplVGfFYtl62rOYaNwNCtazFl66Y4k EM/JbFtjvcfOU6uqKizm/1sbE3a9+NG8eNQxjvGIsDR6dvIhe7vkdtm1sfcaeX4V+zDZ YQIQ== 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=sAXZUylohXuZm+5P1yu+MS9VYyc1gfUewYxv0kdlr4I=; b=oPMFLwWDGaDXpa7ajmM5sD8H8qgBEL0Md4BnX7kMKCAfuAyGrI6ZPUcHY8qb+TYqhM wHaPolywJxRPsLijzi08dYTSN9vySWL69UpKInUGuYhLTeroUg4i6+wdGDw1S5H82oHt 14FBdIvN4BqDA6nUSM6C28zhtlNzSiDZFA3dR6RN8w298W/ZJXdSQIBoCsJEXM7kWRp/ dXD7KyCV2FeTTrgxaeGD6Iug+/mJsmpLzTbvoVNvGP/vaYpvSjkqcozLmPRoSbGtHxop 5grkg/Gfm8EntRuMVnnpxOass+FXbEqk3XYVcvUXJmgqq5vFaT47sylHLcRJecTBMkt7 jcWA== 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 u30-v6si10976626otb.374.2018.09.21.15.18.23 for ; Fri, 21 Sep 2018 15:18:23 -0700 (PDT) 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 E7A5015BF; Fri, 21 Sep 2018 15:18:22 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D2B323F557; Fri, 21 Sep 2018 15:18:19 -0700 (PDT) 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 , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 09/18] ACPI / APEI: Let the notification helper specify the fixmap slot Date: Fri, 21 Sep 2018 23:16:56 +0100 Message-Id: <20180921221705.6478-10-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-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 we have multiple NMI-like notifications, that can 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. --- drivers/acpi/apei/ghes.c | 76 ++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 49 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index ed8669a6c100..adf7fd402813 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -129,38 +130,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); - - return (void __iomem *) fix_to_virt(FIX_APEI_GHES_IRQ); -} - -static void ghes_iounmap_nmi(void) -{ - clear_fixmap(FIX_APEI_GHES_NMI); -} + int _idx = virt_to_fix((unsigned long)vaddr); -static void ghes_iounmap_irq(void) -{ - clear_fixmap(FIX_APEI_GHES_IRQ); + WARN_ON_ONCE(fixmap_idx != _idx); + clear_fixmap(fixmap_idx); } static int ghes_estatus_pool_init(void) @@ -289,20 +276,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) @@ -312,15 +294,11 @@ 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, int silent) +static int ghes_read_estatus(struct ghes *ghes, int silent, int fixmap_idx) { struct acpi_hest_generic *g = ghes->generic; u64 buf_paddr; @@ -339,7 +317,7 @@ static int ghes_read_estatus(struct ghes *ghes, int silent) 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) return -ENOENT; @@ -356,7 +334,7 @@ static int ghes_read_estatus(struct ghes *ghes, int silent) 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; @@ -368,13 +346,13 @@ static int ghes_read_estatus(struct ghes *ghes, int silent) return rc; } -static void ghes_clear_estatus(struct ghes *ghes) +static void ghes_clear_estatus(struct ghes *ghes, int fixmap_idx) { 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); + sizeof(ghes->estatus->block_status), 0, fixmap_idx); ghes->flags &= ~GHES_TO_CLEAR; } @@ -740,12 +718,12 @@ static void __process_error(struct ghes *ghes) llist_add(&estatus_node->llnode, &ghes_estatus_llist); } -static int _in_nmi_notify_one(struct ghes *ghes) +static int _in_nmi_notify_one(struct ghes *ghes, int fixmap_idx) { int sev; - if (ghes_read_estatus(ghes, 1)) { - ghes_clear_estatus(ghes); + if (ghes_read_estatus(ghes, 1, fixmap_idx)) { + ghes_clear_estatus(ghes, fixmap_idx); return -ENOENT; } @@ -759,19 +737,19 @@ static int _in_nmi_notify_one(struct ghes *ghes) return 0; __process_error(ghes); - ghes_clear_estatus(ghes); + ghes_clear_estatus(ghes, fixmap_idx); 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(); @@ -876,7 +854,7 @@ static int ghes_proc(struct ghes *ghes) { int rc; - rc = ghes_read_estatus(ghes, 0); + rc = ghes_read_estatus(ghes, 0, FIX_APEI_GHES_IRQ); if (rc) goto out; @@ -891,7 +869,7 @@ static int ghes_proc(struct ghes *ghes) ghes_do_proc(ghes, ghes->estatus); out: - ghes_clear_estatus(ghes); + ghes_clear_estatus(ghes, FIX_APEI_GHES_IRQ); if (rc == -ENOENT) return rc; @@ -984,7 +962,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; @@ -1031,7 +1009,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 Fri Sep 21 22:16: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: 10611045 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 9C8A35A4 for ; Fri, 21 Sep 2018 22:18:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E5C72D238 for ; Fri, 21 Sep 2018 22:18:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 824162DDC8; Fri, 21 Sep 2018 22:18:31 +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 616ED2D238 for ; Fri, 21 Sep 2018 22:18:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0790E8E001B; Fri, 21 Sep 2018 18:18:29 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 04D688E0001; Fri, 21 Sep 2018 18:18:28 -0400 (EDT) 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 E58DC8E001B; Fri, 21 Sep 2018 18:18:28 -0400 (EDT) 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 B9E108E0001 for ; Fri, 21 Sep 2018 18:18:28 -0400 (EDT) Received: by mail-ot1-f72.google.com with SMTP id f11-v6so13679615otf.7 for ; Fri, 21 Sep 2018 15:18:28 -0700 (PDT) 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=ZMaGmi8+i1xyXO2zgDdxrVcghcXZ3SFBxxQwybJs7mQ=; b=Q1AjcPGwu2fI+Oo4toPWRgUrXdM1DK6zDnEzqUrfx2lBOWKS+jrYkFGlttwkH9519x i68qTsX6qZ5ndqOycl4fld2UrPgcYA+a+/PIE+q1jfCDsCKUndCBUmNjDnjU7wK++fGK QJwzvgyUPgQ47zpgpFtYVvvR7uW5myYZE9FmJ9d6+jSapYEIBE4IF2tzIkdeIUqq2sYZ iRj8QHJojqdOj6LbHqU8XiipDPbdGpQpbZ4bEW5SXi0YaOldOfVS6U61HwHWn5DaMzAh 70tVG/ua1GSr8Qz8Qr381Yuz2mFtLd0Ka/GG8dPmLgA4GVAQKnKBEfR31U303eaIa4vz U1wQ== 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: APzg51AKyfF2Avp5jO37rQwgkbkXupScmfznsfiMirRvJLYc6yaO/b1y 3bfyEHoy2KpVZWfdI5VFO4n7T/Navy/OPOmrPrgFN6WtVXokESfsbBSwt+Tkfp9j3qzEXs7QYeJ go0nfviLpU2QKfBQL73FtDVUJo6wT8mJtFzKiPxyT2g6eW2+NZpTNBwz7AaIGYY2O9A== X-Received: by 2002:a9d:62d5:: with SMTP id z21-v6mr27162900otk.216.1537568308535; Fri, 21 Sep 2018 15:18:28 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaIKoYk1PkAPZGZ1b30MQk+vUYVYqMdVVXSRkQUtppOYe1I6AhooKbvPCDRfHjiD4Ve5aMH X-Received: by 2002:a9d:62d5:: with SMTP id z21-v6mr27162868otk.216.1537568307560; Fri, 21 Sep 2018 15:18:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568307; cv=none; d=google.com; s=arc-20160816; b=slK5XaWr+cYdzLSZ6yMRSUpp1s/5Xupca4JjgXrB4rS+GcB3BOFH6pctE32ZIV3y7t nTbUIDLHVi+63AKgM1YoWOj1kwIZQRN3hilHd6+13haf7Vglr2Lp9a2Zw5XIaCw67rgl J57rKyadYXMOUiX2mJjjBQ4hJNDrWkmTEX5Y1nAAnk11zLaM33s2/yE5eAQyNlttWsey dYcm0vr3eDkogBEZQ+KbDg3yom5Mx/VbXuzfOxHE2bpKf56FCx1dOE86wz/iDk6dXPDG 2v2RvelNqF3QJKg22gJq1yzO+UT/U5KDpzjqqPNdRFdh9WhllYHqAkKPdhIOWHEVFqR5 snQQ== 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=ZMaGmi8+i1xyXO2zgDdxrVcghcXZ3SFBxxQwybJs7mQ=; b=pwHA7SS48ww/fqWqffp7/mSq9COvM8mY84oZ2VF21bnYAkVqJuelhN6NUl44r6EumC ICOYrSEDOlH68OWZXO+mKT0g21CDWfGgdZYCsjavO9x4oMZWOUvDJ2U15pSc1xrDzrBt IhW7jJWR/J4jlcNWatoA8Ai7XN3SASPcioSfoV99hk9csB3ffh5nGbPiZtGvukWwWPiE XX3P77zbUMWL7gsQK3Mm9dlEWBZZ1Hab8+1/XwBYEWjaUl/S2ta++eXJodX0Vo8JHBbK 1Y9SykglJkGuh9D9BF3aqMcuLLm5Kyb7iZUuHSZi+Wz1pMtGHUV0N5fliZkns1gvvxyu HfMQ== 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 e18-v6si11564312oii.45.2018.09.21.15.18.27 for ; Fri, 21 Sep 2018 15:18:27 -0700 (PDT) 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 1C3E01684; Fri, 21 Sep 2018 15:18:27 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 071723F557; Fri, 21 Sep 2018 15:18:23 -0700 (PDT) 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 , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 10/18] ACPI / APEI: preparatory split of ghes->estatus Date: Fri, 21 Sep 2018 23:16:57 +0100 Message-Id: <20180921221705.6478-11-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-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. We want the NMI-like notifications to use a queued estatus entry from the beginning. To that end, break up any use of "ghes->estatus" so that all functions take the estatus as an argument. This patch is just moving code around, no change in behaviour. Signed-off-by: James Morse --- drivers/acpi/apei/ghes.c | 82 ++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 37 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index adf7fd402813..586689cbc0fd 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -298,7 +298,9 @@ static void ghes_copy_tofrom_phys(void *buffer, u64 paddr, u32 len, } } -static int ghes_read_estatus(struct ghes *ghes, int silent, int fixmap_idx) +static int ghes_read_estatus(struct ghes *ghes, + struct acpi_hest_generic_status *estatus, + int silent, int fixmap_idx) { struct acpi_hest_generic *g = ghes->generic; u64 buf_paddr; @@ -316,26 +318,26 @@ static int ghes_read_estatus(struct ghes *ghes, int silent, 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) return -ENOENT; ghes->buffer_paddr = buf_paddr; ghes->flags |= GHES_TO_CLEAR; 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; @@ -346,13 +348,15 @@ static int ghes_read_estatus(struct ghes *ghes, int silent, int fixmap_idx) return rc; } -static void ghes_clear_estatus(struct ghes *ghes, int fixmap_idx) +static void ghes_clear_estatus(struct ghes *ghes, + struct acpi_hest_generic_status *estatus, + int fixmap_idx) { - ghes->estatus->block_status = 0; + 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, fixmap_idx); + ghes_copy_tofrom_phys(estatus, ghes->buffer_paddr, + sizeof(estatus->block_status), 0, fixmap_idx); ghes->flags &= ~GHES_TO_CLEAR; } @@ -518,9 +522,10 @@ static int ghes_print_estatus(const char *pfx, return 0; } -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) @@ -695,16 +700,17 @@ 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 *ghes_estatus) { u32 len, node_len; struct ghes_estatus_node *estatus_node; struct acpi_hest_generic_status *estatus; - if (ghes_estatus_cached(ghes->estatus)) + if (ghes_estatus_cached(ghes_estatus)) return; - len = cper_estatus_len(ghes->estatus); + len = cper_estatus_len(ghes_estatus); node_len = GHES_ESTATUS_NODE_LEN(len); estatus_node = (void *)gen_pool_alloc(ghes_estatus_pool, node_len); @@ -714,35 +720,37 @@ 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, ghes_estatus, len); llist_add(&estatus_node->llnode, &ghes_estatus_llist); } static int _in_nmi_notify_one(struct ghes *ghes, int fixmap_idx) { int sev; + struct acpi_hest_generic_status *estatus = ghes->estatus; - if (ghes_read_estatus(ghes, 1, fixmap_idx)) { - ghes_clear_estatus(ghes, fixmap_idx); + if (ghes_read_estatus(ghes, estatus, 1, fixmap_idx)) { + ghes_clear_estatus(ghes, estatus, 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); } if (!(ghes->flags & GHES_TO_CLEAR)) return 0; - __process_error(ghes); - ghes_clear_estatus(ghes, fixmap_idx); + __process_error(ghes, estatus); + ghes_clear_estatus(ghes, estatus, fixmap_idx); return 0; } -static int ghes_estatus_queue_notified(struct list_head *rcu_list, int fixmap_idx) +static int ghes_estatus_queue_notified(struct list_head *rcu_list, + int fixmap_idx) { int ret = -ENOENT; struct ghes *ghes; @@ -853,23 +861,23 @@ static int ghes_ack_error(struct acpi_hest_generic_v2 *gv2) static int ghes_proc(struct ghes *ghes) { int rc; + struct acpi_hest_generic_status *estatus = ghes->estatus; - rc = ghes_read_estatus(ghes, 0, FIX_APEI_GHES_IRQ); + rc = ghes_read_estatus(ghes, estatus, 0, 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, FIX_APEI_GHES_IRQ); + ghes_clear_estatus(ghes, estatus, FIX_APEI_GHES_IRQ); if (rc == -ENOENT) return rc; From patchwork Fri Sep 21 22:16: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: 10611049 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 BAFF35A4 for ; Fri, 21 Sep 2018 22:18:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ACF642DDC8 for ; Fri, 21 Sep 2018 22:18:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 99C302DDD4; Fri, 21 Sep 2018 22:18:38 +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 3D44C2DDC8 for ; Fri, 21 Sep 2018 22:18:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C4F28E001C; Fri, 21 Sep 2018 18:18:37 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 09AB68E0001; Fri, 21 Sep 2018 18:18:37 -0400 (EDT) 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 ECBBD8E001C; Fri, 21 Sep 2018 18:18:36 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi0-f70.google.com (mail-oi0-f70.google.com [209.85.218.70]) by kanga.kvack.org (Postfix) with ESMTP id BFF2A8E0001 for ; Fri, 21 Sep 2018 18:18:36 -0400 (EDT) Received: by mail-oi0-f70.google.com with SMTP id b8-v6so13460722oib.4 for ; Fri, 21 Sep 2018 15:18:36 -0700 (PDT) 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=l5JGnkBBXH8lQz6scfVyIXH0qZPR0stWI9sdTV4O/R0=; b=g9oxKG1fCGVqPWPs8qAGtnbTHBmItLk9IVfqy4WRmauyuWU7BFu5UAexSWrYM/pSAh L7hUkv74Q4GBaTPrXB50Qv6kjuez+mmwWTjiwxLeL5Wlq/pTNahSUewQjx7C6AS9yvw4 MPAoXgf8qyNTFB0X3si9hyQWBo43JVMOTEkwclgyG0W93moStUcVeO+qZbWPyxXGzyrg 1SaLGGc7hwLJML34to0RdPVTcoRU4osQNMtKlyk3mBBfaGPSsLH57NhgHVnUtYucsjvh vAZYMMwZP+TxR2C9y9grJJOP36pQZ+263WA3CGiKw2fdWpNwOfASQV3+6oW8T2lM4Xyi RS9A== 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: APzg51BwZyrIsICMuYVnvdrrkOOxNSPP7+iUw8uRPt1pEEbb9OlaOKWl GEtun1gNnvJJ14a+mRBK6ThISaoMBRi8+bpvRToZ3l5G3+XaaZYLURd9ilZHaqZkrt4hZpxczDG fS6HpPJ1X0vtWo3iicTjTf0NHFmCdjZWm5BFGpOYy8JPPQrbBLSm6TMifSERtqx3kcw== X-Received: by 2002:aca:2214:: with SMTP id b20-v6mr324757oic.365.1537568316574; Fri, 21 Sep 2018 15:18:36 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYkM+vE+Y/QZmXcfwXSUXRyjdU3mFn5/3oiLpP2ZL8jTxkli3O8c+r9cFWiKGnCUqKsaIqX X-Received: by 2002:aca:2214:: with SMTP id b20-v6mr324718oic.365.1537568315755; Fri, 21 Sep 2018 15:18:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568315; cv=none; d=google.com; s=arc-20160816; b=DcLlUebWNZu6Xi39/AltV/FUYwUOaOK2haiSg9TehlTIWGQ7/LctSFYRPdL35lpyQq UKSgtSKxLu9BmmKH/mxYRglX8R8sllfxo0Z2KzMawwgilXzDj6t/uJnj8TkbLk+/VRh1 DOCdWkek58HbM9LuZZBEU1ibDZrv8wWOsHRPLphPNBN4+Jtu06IaVCIiA94fUZ+G8XD+ qu1oQxHDd45dm5xE6pBzasfHFUzd25umhqEDWqw1CHo9aZQ8PHvrWkZ9AZhfIhRYrnLZ x6E94RK3v2wgXk/4AFg5M04YQoD3fgGI6vivSBf8qxY8qcxfpZg/gUF4Fb+jdXqllK1Q +rVw== 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=l5JGnkBBXH8lQz6scfVyIXH0qZPR0stWI9sdTV4O/R0=; b=Dn0TNkkY8HA/ajn/DDyHMVXtpoR+4nGUevaWYAp4GaejpHKvBxZpeUAN9D0/1Tf4Pu hNu5clh7M+o7Krdxs0fMRLVSTAuzScvdJkJJxmv3y/f978zbcfop2EsWQjGITyVFHLkO tzwjmIW5BEOn5WVPkpbloPTli3jSUyO9GkCQ+wjR40e49msBD//zooliUzCkH18u3bxQ Apo9pTI6WTAQ5hx3r2tPCaoH8QXyAPvKcJc1au8Dx1Zno5N8GQX5vYCFvb/paaNUvv1d Jz22EQxIQriJyju1VeRSxZ9duaDL+jnY8CkxX8NCWAE3K5QAbW11KUNaPaB9DyAL9sVO iH4g== 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 t5-v6si10640577oti.271.2018.09.21.15.18.35 for ; Fri, 21 Sep 2018 15:18:35 -0700 (PDT) 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 4C0051596; Fri, 21 Sep 2018 15:18:35 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 3765B3F557; Fri, 21 Sep 2018 15:18:32 -0700 (PDT) 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 , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 11/18] ACPI / APEI: Remove silent flag from ghes_read_estatus() Date: Fri, 21 Sep 2018 23:16:58 +0100 Message-Id: <20180921221705.6478-12-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-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 42a0bb3f7138 ("printk/nmi: generic solution for safe printk in NMI"), were unsafe in NMI context. We don't need to do this anymore, 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 --- drivers/acpi/apei/ghes.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 586689cbc0fd..ba5344d26a39 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -300,7 +300,7 @@ 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, - int silent, int fixmap_idx) + int fixmap_idx) { struct acpi_hest_generic *g = ghes->generic; u64 buf_paddr; @@ -309,7 +309,7 @@ static int ghes_read_estatus(struct ghes *ghes, rc = apei_read(&buf_paddr, &g->error_status_address); if (rc) { - if (!silent && printk_ratelimit()) + if (printk_ratelimit()) pr_warning(FW_WARN GHES_PFX "Failed to read error status block address for hardware error source: %d.\n", g->header.source_id); @@ -342,7 +342,7 @@ static int ghes_read_estatus(struct ghes *ghes, rc = 0; err_read_block: - if (rc && !silent && printk_ratelimit()) + if (rc && printk_ratelimit()) pr_warning(FW_WARN GHES_PFX "Failed to read error status block!\n"); return rc; @@ -729,7 +729,7 @@ static int _in_nmi_notify_one(struct ghes *ghes, int fixmap_idx) int sev; struct acpi_hest_generic_status *estatus = ghes->estatus; - if (ghes_read_estatus(ghes, estatus, 1, fixmap_idx)) { + if (ghes_read_estatus(ghes, estatus, fixmap_idx)) { ghes_clear_estatus(ghes, estatus, fixmap_idx); return -ENOENT; } @@ -863,7 +863,7 @@ static int ghes_proc(struct ghes *ghes) int rc; struct acpi_hest_generic_status *estatus = ghes->estatus; - rc = ghes_read_estatus(ghes, estatus, 0, FIX_APEI_GHES_IRQ); + rc = ghes_read_estatus(ghes, estatus, FIX_APEI_GHES_IRQ); if (rc) goto out; From patchwork Fri Sep 21 22:16: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: 10611053 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 EA50A14BD for ; Fri, 21 Sep 2018 22:18:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCFD42DDC8 for ; Fri, 21 Sep 2018 22:18:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0A392DDD4; Fri, 21 Sep 2018 22:18:43 +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 57B1B2DDC8 for ; Fri, 21 Sep 2018 22:18:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 111EB8E001D; Fri, 21 Sep 2018 18:18:42 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0E8C18E0001; Fri, 21 Sep 2018 18:18:42 -0400 (EDT) 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 F19DA8E001D; Fri, 21 Sep 2018 18:18:41 -0400 (EDT) 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 C81128E0001 for ; Fri, 21 Sep 2018 18:18:41 -0400 (EDT) Received: by mail-ot1-f71.google.com with SMTP id j27-v6so13832705oth.3 for ; Fri, 21 Sep 2018 15:18:41 -0700 (PDT) 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=W8xhfjYK2/1TcXsdgpXmSCTO/ZH8hhDC4qYWAF8qWtY=; b=d3udc2x5Pe/ixgZJ7g397u8AxULQtB1/lw1g6tv1Uc3WkB0yFBeNmT7TS0IsUiS+eH bB5KeaKOSL4P/7TqlL+HsnkRKP4QBWdCnDGfo5LHJJ/KyxNe5hwGde2Te1Gwj8oc/EWW 9xwQlS24HUzb9+HbJiwFZKCKN/dwGF7ZYKRJ9yDUwI8nVMmYDmW2+QyPdn9DQWQaEsAa 1NyTe1HZgJYJQhQCrtgiHRdpSrFXMHhKx7LuhuS8c0Gez9PGhqhyv56L0JM/o+7d4VTo IlSJRTFMYkaVnlVtj+j1nF4mT/wjDjXcqn5RU+6VrJQe2PWBdATru4Ef4sHIlJxffLFi 0A0Q== 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: APzg51Dh4cQO22ITKVwrmlZgKf1kGbtGM6wlSE2EhOSmNEYXzKtEwl4i YESZQPkPPsYVMnhwgy8wMLZbC5B9qQLxLsDezX2y8kSGgpZry5l/GCt0JGYAr4oCQZRTftW6tvh EGcCMRMjNLhJZdXlbMuDI4WhaTTSxokPx3SPeeBKxUQ8j+E5l06X0uXhpSk9dh4K+RA== X-Received: by 2002:aca:e6cd:: with SMTP id d196-v6mr352086oih.94.1537568321586; Fri, 21 Sep 2018 15:18:41 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYkaaCHW+sh2UM5rMvXyjHuihc/f3f9pDx37gttdWpRl5iijQaXrmjEc1n/kawZoDJii1bw X-Received: by 2002:aca:e6cd:: with SMTP id d196-v6mr352052oih.94.1537568320636; Fri, 21 Sep 2018 15:18:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568320; cv=none; d=google.com; s=arc-20160816; b=fq9lrS6St/sZjhpsutBXVI6F08dDXjSrW+dfGd3Fnq03MFOCZvXA/oe0Jb6tKeOtsR wXs439sintU5X4ST8KCeLMt3M9+cigqp3ovbiR7qd2tYvBsjuKFG6I4hzBwbi3y7HpDp 9WI28bFuEhjOV1X4HuWMr53M7czvXKfQY+DAlCUJMgdqelCWOoqcLuV4HTDi3SEBOoNf xqU2UYsUM51Wx7wyQeJezwLUhTtqHW33Qc70FXokFMQ7ElfKIhYiJKDTdCV/5IogZCZ0 egiznZVfs8/21Pqsw19zqEbUoLcKyLPgAe8vbIJnm6IYgz31C7DZYlNfQKz76cPMGvRs SEtA== 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=W8xhfjYK2/1TcXsdgpXmSCTO/ZH8hhDC4qYWAF8qWtY=; b=huMyURBLVd1WKV+g3+BG0ow5ghHK/Na2XVEiBkm1ZygK43zsZ/IGD9nCmumJHYdmwY /BIY1HznJyibWjfxiSTpwusryTfM1KOfZ50TRcq1uXFaSjhmGzkAQxZv2zGEr9XJsoMg gywK1L6ycWO8NDMkims+AvKcPliGRsyc8o00L1yinjtP8yWaW0JRFdI19r0coICZF7p5 H4/HePnyQSeCsRqbE2VKmnzvmA8vYhJa6Hu2Hw+eCE883FWlY5bx5j1YeEzL6KNmYGX7 ZgLN5d8oE/n9W64og715yCYZWTgUKSeHSVfkdUham9eBN51ibi6z2oN7B39C9tStbyZH /G3A== 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 m24-v6si11448293oth.48.2018.09.21.15.18.40 for ; Fri, 21 Sep 2018 15:18:40 -0700 (PDT) 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 23AAE15BF; Fri, 21 Sep 2018 15:18:40 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0F1FF3F557; Fri, 21 Sep 2018 15:18:36 -0700 (PDT) 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 , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 12/18] ACPI / APEI: Don't store CPER records physical address in struct ghes Date: Fri, 21 Sep 2018 23:16:59 +0100 Message-Id: <20180921221705.6478-13-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-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. 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 --- drivers/acpi/apei/ghes.c | 28 ++++++++++++++-------------- include/acpi/ghes.h | 1 - 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index ba5344d26a39..c58f9b330ed3 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -300,14 +300,13 @@ 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, - int fixmap_idx) + u64 *buf_paddr, int fixmap_idx) { 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) { if (printk_ratelimit()) pr_warning(FW_WARN GHES_PFX @@ -315,15 +314,14 @@ static int ghes_read_estatus(struct ghes *ghes, g->header.source_id); return -EIO; } - if (!buf_paddr) + if (!*buf_paddr) return -ENOENT; - ghes_copy_tofrom_phys(estatus, buf_paddr, + ghes_copy_tofrom_phys(estatus, *buf_paddr, sizeof(*estatus), 1, fixmap_idx); if (!estatus->block_status) return -ENOENT; - ghes->buffer_paddr = buf_paddr; ghes->flags |= GHES_TO_CLEAR; rc = -EIO; @@ -335,7 +333,7 @@ static int ghes_read_estatus(struct ghes *ghes, if (cper_estatus_check_header(estatus)) goto err_read_block; ghes_copy_tofrom_phys(estatus + 1, - buf_paddr + sizeof(*estatus), + *buf_paddr + sizeof(*estatus), len - sizeof(*estatus), 1, fixmap_idx); if (cper_estatus_check(estatus)) goto err_read_block; @@ -350,12 +348,12 @@ static int ghes_read_estatus(struct ghes *ghes, static void ghes_clear_estatus(struct ghes *ghes, struct acpi_hest_generic_status *estatus, - int fixmap_idx) + u64 buf_paddr, int fixmap_idx) { estatus->block_status = 0; if (!(ghes->flags & GHES_TO_CLEAR)) return; - ghes_copy_tofrom_phys(estatus, ghes->buffer_paddr, + ghes_copy_tofrom_phys(estatus, buf_paddr, sizeof(estatus->block_status), 0, fixmap_idx); ghes->flags &= ~GHES_TO_CLEAR; } @@ -727,10 +725,11 @@ static void __process_error(struct ghes *ghes, static int _in_nmi_notify_one(struct ghes *ghes, int fixmap_idx) { int sev; + u64 buf_paddr; struct acpi_hest_generic_status *estatus = ghes->estatus; - if (ghes_read_estatus(ghes, estatus, fixmap_idx)) { - ghes_clear_estatus(ghes, estatus, fixmap_idx); + if (ghes_read_estatus(ghes, estatus, &buf_paddr, fixmap_idx)) { + ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx); return -ENOENT; } @@ -744,7 +743,7 @@ static int _in_nmi_notify_one(struct ghes *ghes, int fixmap_idx) return 0; __process_error(ghes, estatus); - ghes_clear_estatus(ghes, estatus, fixmap_idx); + ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx); return 0; } @@ -861,9 +860,10 @@ static int ghes_ack_error(struct acpi_hest_generic_v2 *gv2) static int ghes_proc(struct ghes *ghes) { int rc; + u64 buf_paddr; struct acpi_hest_generic_status *estatus = ghes->estatus; - rc = ghes_read_estatus(ghes, estatus, FIX_APEI_GHES_IRQ); + rc = ghes_read_estatus(ghes, estatus, &buf_paddr, FIX_APEI_GHES_IRQ); if (rc) goto out; @@ -877,7 +877,7 @@ static int ghes_proc(struct ghes *ghes) ghes_do_proc(ghes, estatus); out: - ghes_clear_estatus(ghes, estatus, FIX_APEI_GHES_IRQ); + ghes_clear_estatus(ghes, estatus, buf_paddr, FIX_APEI_GHES_IRQ); if (rc == -ENOENT) return rc; diff --git a/include/acpi/ghes.h b/include/acpi/ghes.h index 82cb4eb225a4..6dc021e9cdad 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 Fri Sep 21 22:17: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: 10611057 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 8A8F514BD for ; Fri, 21 Sep 2018 22:18:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D4792DDC8 for ; Fri, 21 Sep 2018 22:18:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71AB82DDD4; Fri, 21 Sep 2018 22:18: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 0B1772DDC8 for ; Fri, 21 Sep 2018 22:18:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D46078E001E; Fri, 21 Sep 2018 18:18:46 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id CF62C8E0001; Fri, 21 Sep 2018 18:18:46 -0400 (EDT) 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 C0C738E001E; Fri, 21 Sep 2018 18:18:46 -0400 (EDT) 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 973C08E0001 for ; Fri, 21 Sep 2018 18:18:46 -0400 (EDT) Received: by mail-ot1-f69.google.com with SMTP id b9-v6so13829623otl.4 for ; Fri, 21 Sep 2018 15:18:46 -0700 (PDT) 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=bboPjrhPBdZVtPAqzi8WofR0+B9wPN9MRHdT7ciiho8=; b=X+dshElLcITpGZWK5qZdL2zKgIz35fb0fCziOcTUl2YZ2zaFXDTLctz1yId8bAZHKy FES4YWZXXWHbqbABkyeBC6nrgCHx1TZVR8fsvffxLYi+HqlNcGzP9QdzQ9lyHX0uDAJW JgMHOFGuPzW/qGprvnLun9+SmjFPE7T9CWxAMqaJzXNT3eshy9Bd841uIIJrAKM4afyV 4I1tJZYD6ge8qWh9rF6niHEjOlAXWfo9mPzHlTPu1BNfuF3xmdU9AwuQXscyscdzEcZV o5xdMPGfP7VtLsR6NG6tZ6JPif65mObSMxjIuT7LGoY3WcyNPEKNcis6iGUsTcU+Sd/u jvmg== 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: APzg51DRVtVMwmSHCuy9ul9XR8Jwpl1xs/Q1hZ7hv4VDmmSUfkB8yIxA 8aAYyCxQciB5OoVJOCkNObeO76iEdZ+C8h6YaSwV6wJuQkx28bSiVdO/dK/78ffWMC/JHxpvN/F cCbKkcpzad+sVZI4Z7u+Ow17wJ8RBwtgFD9fSoZZL6TqBd2krF62H0CHzUlvCyvNiBQ== X-Received: by 2002:a9d:1ea5:: with SMTP id n34-v6mr25101828otn.313.1537568326353; Fri, 21 Sep 2018 15:18:46 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ6PiOdHoyt7sf8Lug2sRbWuSN/3vDwzuBRevV99ITTXJafd7p2yjItkkcUlGBTub82oS0r X-Received: by 2002:a9d:1ea5:: with SMTP id n34-v6mr25101803otn.313.1537568325495; Fri, 21 Sep 2018 15:18:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568325; cv=none; d=google.com; s=arc-20160816; b=BcQnZ+U/jgOXzSduA+FpklSZRDSsGzkmrlHqv2glQs6wDHTYRnm9Tdqtzzhv3qEtBr 8wdFvI5tTIkjOsXWrN4iMdyy1LmIaepu6zcs+VxQC4JQBZEVu8IkWIMEK7coaK1kNXyO EbzPm9MVWFMLwAZZTxZH6pj3zbDB5inLifkr0YTw3IsDGIFPPeGyxXaMgiwyeRWt5uLP 1OOi0QOw2gT9VlKUWj0HwHyqQba7dWGHgM+F4Dz/5dEcuARQ6qXoblN3AcnWg8ryQvH5 1FQ+7uyMR6X78n8anUbvnaCeaxW72VxJAZ2mKX6Wn1qjRAcJhMrYgicwsj6jPNvRZttM bZOw== 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=bboPjrhPBdZVtPAqzi8WofR0+B9wPN9MRHdT7ciiho8=; b=OfUCO6tH34YaKA3RSvy4LmuFzWczsS3lh1aSnFJHCdArBXqRtE8C49kSQNt/aJnKoT hnITQCnXSNiD180jaaOJvsdX5EkwPp+vHIKkX6nXdN2eqdDq+YspyULRL3bLtRcLlV07 W5cUAWwYfHiYkF7C4GBO29YvPEvGWn+YLRnG+xBECoHIh4q5Re5Ub/NpTYv2nkZeFiMg R5+rBDCSaPhxrDetHgPFfOZVn0nkXnSygAALNTLkXS9RfJAJk/CHRc6Bt6bFzo3hbrEr EZikVJ6pZ/7F/l655GIEuPGyOPKZs4HJUmuYHUC/dnlGBwEEcFYGN2f1+Jn//KF62gaT DYjw== 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 u142-v6si12775372oiu.234.2018.09.21.15.18.45 for ; Fri, 21 Sep 2018 15:18:45 -0700 (PDT) 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 EDAA61684; Fri, 21 Sep 2018 15:18:44 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D87523F557; Fri, 21 Sep 2018 15:18:41 -0700 (PDT) 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 , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 13/18] ACPI / APEI: Don't update struct ghes' flags in read/clear estatus Date: Fri, 21 Sep 2018 23:17:00 +0100 Message-Id: <20180921221705.6478-14-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-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 global flags 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 GHES_TO_CLEAR flags was only set at the same time as buffer_paddr, which is now owned by the caller and passed to ghes_clear_estatus(). Use this as the flag. A non-zero buf_paddr returned by ghes_read_estatus() means ghes_clear_estatus() will clear this address. ghes_read_estatus() already checks for a read of error_status_address being zero, so we can never get CPER records written at zero. After this ghes_clear_estatus() no longer needs the struct ghes. Signed-off-by: James Morse Reviewed-by: Borislav Petkov --- drivers/acpi/apei/ghes.c | 26 ++++++++++++-------------- include/acpi/ghes.h | 1 - 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index c58f9b330ed3..3028487d43a3 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -319,10 +319,10 @@ static int ghes_read_estatus(struct ghes *ghes, ghes_copy_tofrom_phys(estatus, *buf_paddr, sizeof(*estatus), 1, fixmap_idx); - if (!estatus->block_status) + if (!estatus->block_status) { + *buf_paddr = 0; return -ENOENT; - - ghes->flags |= GHES_TO_CLEAR; + } rc = -EIO; len = cper_estatus_len(estatus); @@ -346,16 +346,14 @@ static int ghes_read_estatus(struct ghes *ghes, return rc; } -static void ghes_clear_estatus(struct ghes *ghes, - struct acpi_hest_generic_status *estatus, +static void ghes_clear_estatus(struct acpi_hest_generic_status *estatus, u64 buf_paddr, int fixmap_idx) { estatus->block_status = 0; - if (!(ghes->flags & GHES_TO_CLEAR)) - return; - ghes_copy_tofrom_phys(estatus, buf_paddr, - sizeof(estatus->block_status), 0, fixmap_idx); - ghes->flags &= ~GHES_TO_CLEAR; + if (buf_paddr) + ghes_copy_tofrom_phys(estatus, buf_paddr, + sizeof(estatus->block_status), 0, + fixmap_idx); } static void ghes_handle_memory_failure(struct acpi_hest_generic_data *gdata, int sev) @@ -729,7 +727,7 @@ static int _in_nmi_notify_one(struct ghes *ghes, int fixmap_idx) struct acpi_hest_generic_status *estatus = ghes->estatus; if (ghes_read_estatus(ghes, estatus, &buf_paddr, fixmap_idx)) { - ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx); + ghes_clear_estatus(estatus, buf_paddr, fixmap_idx); return -ENOENT; } @@ -739,11 +737,11 @@ static int _in_nmi_notify_one(struct ghes *ghes, int fixmap_idx) __ghes_panic(ghes, estatus); } - if (!(ghes->flags & GHES_TO_CLEAR)) + if (!buf_paddr) return 0; __process_error(ghes, estatus); - ghes_clear_estatus(ghes, estatus, buf_paddr, fixmap_idx); + ghes_clear_estatus(estatus, buf_paddr, fixmap_idx); return 0; } @@ -877,7 +875,7 @@ static int ghes_proc(struct ghes *ghes) ghes_do_proc(ghes, estatus); out: - ghes_clear_estatus(ghes, estatus, buf_paddr, FIX_APEI_GHES_IRQ); + ghes_clear_estatus(estatus, buf_paddr, FIX_APEI_GHES_IRQ); if (rc == -ENOENT) return rc; diff --git a/include/acpi/ghes.h b/include/acpi/ghes.h index 6dc021e9cdad..536f90dd1e34 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 Fri Sep 21 22:17: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: 10611061 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 09C965A4 for ; Fri, 21 Sep 2018 22:18:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F03902DDC8 for ; Fri, 21 Sep 2018 22:18:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4A7A2DDD4; Fri, 21 Sep 2018 22:18: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 81DA72DDC8 for ; Fri, 21 Sep 2018 22:18:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C2868E001F; Fri, 21 Sep 2018 18:18:52 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 073368E0001; Fri, 21 Sep 2018 18:18:52 -0400 (EDT) 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 EA4A58E001F; Fri, 21 Sep 2018 18:18:51 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi0-f72.google.com (mail-oi0-f72.google.com [209.85.218.72]) by kanga.kvack.org (Postfix) with ESMTP id BC5318E0001 for ; Fri, 21 Sep 2018 18:18:51 -0400 (EDT) Received: by mail-oi0-f72.google.com with SMTP id m197-v6so13260612oig.18 for ; Fri, 21 Sep 2018 15:18:51 -0700 (PDT) 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=Y9S2NRqeqmzhZPhWg4xrBfVcu6WIctERs26ngNDlqyI=; b=SUHEePpto+llzw8nurbwbbEfEEyAid/h3q1BmAELKLEXWsvItSqNNMB2N7yOH6XO3m 7STqGZFwvdf4JShF9OmlaQHHXQyyoN7FYSFo4sPE80HIQY7FXpw9diaw3BXvAnvyiHRH Kr0Msn8XrvxrhNO8f7H4NhGkmcNM8M14dIiwUcvzDGO9gMuEwIpy5ZSovNLpSslT91Nm pZY6HsHADaxMeeSfUsQjOS3G0WczBQ9yOA/xcIn8OW+3s9kKwtClGL4vftX7PXE9dNjv yYODE5JWYrVHMibMqd4f+wzGSYov/qR3XANTVYM4xUgT1mTDVJPCpVyMdbclgHtEgH2Z Hs0Q== 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: APzg51Cxqsij8ljNEGWo4rARkgn7Mofhhbgs+F5MKZzZYe6t9eF4ybU9 ucxzGWfZIAm0NLKwitdjHwWYBR5Vx3n0MbjQDpvZyzRogmpj8n2ZqSVGi8nmesND0Xa4ZaQIKUQ mYjhs7KuI0qumQRyK5MmQ79z24BkqaLcrOXzaCMjZVunjAUt6c2JKgZyDmdQ1wdkxlw== X-Received: by 2002:aca:91a:: with SMTP id 26-v6mr317127oij.33.1537568331554; Fri, 21 Sep 2018 15:18:51 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbUU12dpIIotLDwK5973vV/zbFB9vFo/8CES8YTRb4nTCEGXowpaqrb8wfLw4veDdWulvhF X-Received: by 2002:aca:91a:: with SMTP id 26-v6mr317096oij.33.1537568330661; Fri, 21 Sep 2018 15:18:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568330; cv=none; d=google.com; s=arc-20160816; b=WuYFQ/M9A0Fb9LybywK8xMCwsFWtt2slKX13iDGdKpoNMqGueSut4al6LQhZcIy40T vm8W5gx5LQBcTeiNTd0onFAHNbudnp9f7JHMiJhJZrk+R4Bk1dHwhvvxHQOdqfzkMqKG 6o2ePc4VIfbOMW2A+cktIRVIdmVT6TxT3xD6gc3AYkxYI8G3eWQCLyN3e9cqiB+X5VAr qsqcO/X7nyUB3DZo4GBBfnTwvgtEpQvTp0VU97FBiuFrgKBd+BKDsmJd0YdJON+ELlpQ KXAP54QcPyiP6RZ2U7X28xQeWs2jIIhW3IOt8VSVzigOxRleKV3PDb+ERky8zRnATy81 6lWA== 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=Y9S2NRqeqmzhZPhWg4xrBfVcu6WIctERs26ngNDlqyI=; b=YAckBQI4Axb/pIrEpZlsHPZ5QgzVSkKj+hmmAfN5wAANotK5P6FU3L+drEZ5F8tNdT KFSDw6xfAVy0ywQQRDf0IAVq3/Z5c9VqB62E12FDFqCmqZpxxqOZofet4VBORzd9GlBT 1QhXTnunks5HjOv3fXhB4Ytg1faJvUkKenWG2e7T4ONT+1n0Yoy+iM61OPBHNjwC0vzo Qpc0Um2e2HCttd03+uUoqBL3GOEMUNcgA5RzsYsbMqXbUhaDy8OEFhbN4impdG5JbuDQ IvkjTIVfPL9DB/ZQpj7GWqj9FljotIFlxCHSezvBxkqAQuAA2fmNf6LN65zmQfiuXDyH nmBw== 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 n13-v6si11518798ota.180.2018.09.21.15.18.50 for ; Fri, 21 Sep 2018 15:18:50 -0700 (PDT) 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 21CA81596; Fri, 21 Sep 2018 15:18:50 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 0C7F43F557; Fri, 21 Sep 2018 15:18:46 -0700 (PDT) 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 , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 14/18] ACPI / APEI: Split ghes_read_estatus() to read CPER length Date: Fri, 21 Sep 2018 23:17:01 +0100 Message-Id: <20180921221705.6478-15-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-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. We either need to know the size of the records before we call ghes_read_estatus(), or always provide a worst-case sized buffer, as happens today. 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 --- drivers/acpi/apei/ghes.c | 55 ++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 3028487d43a3..055176ed68ac 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -298,11 +298,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 returning its address and size */ +static int ghes_peek_estatus(struct ghes *ghes, int fixmap_idx, + u64 *buf_paddr, u32 *buf_len) { struct acpi_hest_generic *g = ghes->generic; + struct acpi_hest_generic_status estatus; u32 len; int rc; @@ -317,26 +318,23 @@ static int ghes_read_estatus(struct ghes *ghes, if (!*buf_paddr) return -ENOENT; - ghes_copy_tofrom_phys(estatus, *buf_paddr, - sizeof(*estatus), 1, fixmap_idx); - if (!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(estatus); - if (len < sizeof(*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(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)) + if (cper_estatus_check_header(&estatus)) goto err_read_block; + *buf_len = len; + rc = 0; err_read_block: @@ -346,6 +344,35 @@ static int ghes_read_estatus(struct ghes *ghes, 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)) { + if (printk_ratelimit()) + pr_warning(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; + u32 buf_len; + + rc = ghes_peek_estatus(ghes, fixmap_idx, buf_paddr, &buf_len); + if (rc) + return rc; + + return __ghes_read_estatus(estatus, *buf_paddr, buf_len, fixmap_idx); +} + static void ghes_clear_estatus(struct acpi_hest_generic_status *estatus, u64 buf_paddr, int fixmap_idx) { From patchwork Fri Sep 21 22:17: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: 10611065 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 3A5AB14BD for ; Fri, 21 Sep 2018 22:18:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2DA672DDC8 for ; Fri, 21 Sep 2018 22:18:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 214E32DDD4; Fri, 21 Sep 2018 22:18:59 +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 A92A82DDC8 for ; Fri, 21 Sep 2018 22:18:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 57D988E0020; Fri, 21 Sep 2018 18:18:57 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 52D398E0001; Fri, 21 Sep 2018 18:18:57 -0400 (EDT) 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 41EDE8E0020; Fri, 21 Sep 2018 18:18:57 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-oi0-f69.google.com (mail-oi0-f69.google.com [209.85.218.69]) by kanga.kvack.org (Postfix) with ESMTP id 17EA88E0001 for ; Fri, 21 Sep 2018 18:18:57 -0400 (EDT) Received: by mail-oi0-f69.google.com with SMTP id x145-v6so13426687oia.10 for ; Fri, 21 Sep 2018 15:18:57 -0700 (PDT) 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=NlHipBD85WpKIhfoKQJofToLO84wEXj65vQgfTlE2IY=; b=nmPx//8+lCDyKjj4S4OZlD91IdlWh0YhFxkw6PghfbBYMZiC1RW1BI/v7teXHPT4YX 6+sBSxqK/tu96zhgUACBQl+FZHyBqSZqXjgZV30wFQ35xYr7XRLKc8xzFc82mi3i6vim l9Ds+H+biY9PxpN7yom17M5wWUQk7bC24+d/xMVy8Uj2w3bq6JJtxTEVB3mdiWzOUW9i dEVALEWuO4Bx17+mz2c9lsymriMzku9M6qKFuCOBKl/RoiLKmoNG0l7RbLhcx2ihAxhy dFUnMWL8HHuF9kCMm55rgNL2tycNbdhyXrwVmsExiJdpvaPG/4MppOAv3QIFd5zu8Rki iz2Q== 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: APzg51C7XcKvXFh84BEMpUmuygUfy8mMaxMFwPnNnpaoeDncvCLs0veB ZTqShM5e7K+IVe6nHCzp4GtxQnc1f41CLr5u9KPSzaucAKUPpAyR47GT7Ssuk7BSFuDcj3AixuE x3DViBQro5Ri2b7G8hzrZ9v+KR2fW4m7a2THgiFnWZtW8TO9c6g8txMfn+Kis+soUpA== X-Received: by 2002:a9d:2c85:: with SMTP id p5-v6mr24739220otb.354.1537568336816; Fri, 21 Sep 2018 15:18:56 -0700 (PDT) X-Google-Smtp-Source: ANB0VdazsQpgXmM6txbzK1OgLPN+C1wuiykU+V0ZtxK4kXiJC0cWIXDhdoXCMqQO4mcCWa/g97eN X-Received: by 2002:a9d:2c85:: with SMTP id p5-v6mr24739190otb.354.1537568335810; Fri, 21 Sep 2018 15:18:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568335; cv=none; d=google.com; s=arc-20160816; b=k7n78eW3mesfBo4zZXeXBr0pES/KTk3OkH4uwOKQs3ZAqvcZJ9eeXLj2lWlBToj+y1 D2vJJE6ePGt0n6A3lpIpy4nPKcTqT5Q1J+1D1XXPSRjCiCR744q2G9V2+pHv9HPXxzKB iD9cGYLuTOLGGwc5zdKMk5tmcMLYaElJw59ulNwFqLy9auaeeborYnZCeo1Qx1JzgYKk MaXCZ4BILyEdzvXpHg9/2cgTTEHy08rXpLlhI9PLlJ6kR4WXcAFmRw3IA3PD68BL/jZc fyog6VtsM4yI2FTuDuGcX+QlQjcE9Jz02PugeiCv5Q8Sd7S1EDkfm0eBndvT5p328HIQ KrBw== 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=NlHipBD85WpKIhfoKQJofToLO84wEXj65vQgfTlE2IY=; b=qw3Dk3imvvuXugMBA07T2EAMUyX+2GYmITqaD8FgNQJst9YESYogWzzraNPFZhr6ZP SVYWTqR5MPzI2IOjP6FJ2sn5p8KdJbtgrl1qdAAtno8Uh8udMxH5Ki//zm0Z841tS3/7 gpfzQHGwXRIrf/Epav7L+VLwKAdUwqJW9JbJ2jYFgbrnZhuUl3kI6V7m/xPNSXDfYqAt 6w9ecdgCgDbyE/PkLChQ1MacM4ZISYGRtvpXmbD7+eo2slIQYmL9GQt2Fbh2B60tJ+8m 8MeXo7De6Y8y7zFe9vIQAb+Pwkgd1Ktj/gsKMaWhp0WWFESMoZmKaJIKHOB9KA7v7cKr pUOA== 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 k70-v6si10681498otk.129.2018.09.21.15.18.55 for ; Fri, 21 Sep 2018 15:18:55 -0700 (PDT) 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 4347D15BE; Fri, 21 Sep 2018 15:18:55 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2DB4A3F557; Fri, 21 Sep 2018 15:18:52 -0700 (PDT) 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 , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 15/18] ACPI / APEI: Only use queued estatus entry during _in_nmi_notify_one() Date: Fri, 21 Sep 2018 23:17:02 +0100 Message-Id: <20180921221705.6478-16-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-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 ghes_peek_estatus() so we know how much memory to allocate from the ghes_estatus_pool before we read the records. Reported-by: Borislav Petkov Signed-off-by: James Morse --- drivers/acpi/apei/ghes.c | 45 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c index 055176ed68ac..a0c10b60ad44 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -722,40 +722,32 @@ 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 *ghes_estatus) +static int _in_nmi_notify_one(struct ghes *ghes, int fixmap_idx) { + u64 buf_paddr; + int sev, rc = 0; u32 len, node_len; struct ghes_estatus_node *estatus_node; struct acpi_hest_generic_status *estatus; - if (ghes_estatus_cached(ghes_estatus)) - return; + rc = ghes_peek_estatus(ghes, fixmap_idx, &buf_paddr, &len); + if (rc) + return rc; - len = cper_estatus_len(ghes_estatus); 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, ghes_estatus, len); - llist_add(&estatus_node->llnode, &ghes_estatus_llist); -} - -static int _in_nmi_notify_one(struct ghes *ghes, int fixmap_idx) -{ - int sev; - u64 buf_paddr; - struct acpi_hest_generic_status *estatus = ghes->estatus; - 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); @@ -764,13 +756,20 @@ static int _in_nmi_notify_one(struct ghes *ghes, int fixmap_idx) __ghes_panic(ghes, estatus); } - if (!buf_paddr) - return 0; - - __process_error(ghes, estatus); ghes_clear_estatus(estatus, buf_paddr, fixmap_idx); - return 0; + if (!buf_paddr || 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 Fri Sep 21 22:17: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: 10611069 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 6AAC714BD for ; Fri, 21 Sep 2018 22:19:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CCEF2DDC8 for ; Fri, 21 Sep 2018 22:19:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 501362DDD4; Fri, 21 Sep 2018 22:19: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 E8D332DDC8 for ; Fri, 21 Sep 2018 22:19:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9C6FC8E0021; Fri, 21 Sep 2018 18:19:01 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 9A6238E0001; Fri, 21 Sep 2018 18:19:01 -0400 (EDT) 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 88A888E0021; Fri, 21 Sep 2018 18:19:01 -0400 (EDT) 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 5D0DA8E0001 for ; Fri, 21 Sep 2018 18:19:01 -0400 (EDT) Received: by mail-ot1-f71.google.com with SMTP id p23-v6so13630607otl.23 for ; Fri, 21 Sep 2018 15:19:01 -0700 (PDT) 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=FxGw+iV01oGrcLCTyFbW5iMNYV3xDYX8+cWpbfzyJ0M=; b=sd8LTEf7B4Q7DYgLxMpabXG4JrQx94FBJDyhZOcOGet6OXfICbnhjGAE20UDVfeEnD xNMzfaeLgOSB4Xb2mQeZcVhtYqkl7f5jVq4Ppl30aZdMJzNa++zPiHrqyNr1kEj2Xcj/ 0TFedXhmD04lTPLGAi6cIyo3Ryw8V2k2E4ArShbvFrw/OJwlytM2WclRed/WD59xWb8w QL6NRgxLWPuaO3+ihSzB6omRzD6y8uyoSpYvok2YwFEpawYn9FLjXuAlfffO2zcVooSQ DSwELxaVrT7kRdJRFM0rZKsKh3NHnM2kCEGQ8gXwZ3Hd/qvJWJewoUlCkX6Acy9iOO02 bsgg== 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: APzg51AzzorvivSD1ERm6x/pKCQooed+Hgdox7ZfwLyYNNPjGNA1TxUj lAFtKbh+fEaA0BTjRvtOfjqzkh0j3yZFjk3Ql5Yj1y96EwdIVuhQyQH7CkPbeBpx14Rtps/UOhS OvktdRFfnvwNtbDGlG0DMDGU/ELwWu1GHgu7YLwWmA40QI5WCYyOv80+aoHQM8RN8hg== X-Received: by 2002:a9d:4887:: with SMTP id d7-v6mr26496005otf.94.1537568341167; Fri, 21 Sep 2018 15:19:01 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYZptVCnZ1hxt6TGgZcDT+tFtYINlLTypEHtQWHpj7apJ4XKOIf05B/8Ju4Yp+TssLxzv8i X-Received: by 2002:a9d:4887:: with SMTP id d7-v6mr26495978otf.94.1537568340363; Fri, 21 Sep 2018 15:19:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568340; cv=none; d=google.com; s=arc-20160816; b=DuHCOF9aFOmmP/5x9ECyNErkj9Ht0kFUaU3v8sfCVS7jXVBZSIvEToQaVmYGrxZPY1 Y8+yisew2cK8JUE+WJn3iNqS0A94BFeLV9kzrXzlrtsGeAJTZc+gs4EpViRtYYErBkJV cePegNVHMzLuVRyzRA9krtaSJm4aAdJ+oa1Xvtb6Fc23Z10fZdoje6GhNiG0iscuWD6v HjA7Qhxv0pALhyR8ckCOgNUpuV17r3DzsICDq8Ny//DyMwb/hXv422kIXIKX4WIlTzT3 tk6XB0NF1rU54LURnJT4vqm9KgvUfiRiuhvgl5tz7gWLuXV6N78iL72PWavPvMJXKHs3 HFRA== 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=FxGw+iV01oGrcLCTyFbW5iMNYV3xDYX8+cWpbfzyJ0M=; b=iwyE5gXafEAot/5xQVDv5tfTtxDRX42VhReuF2TU2Q2tMaYJAudeCmkgTI5qZRdKwf wmF/EJxZTEUqfNLhX9VqIgFsbjShl+wGGtPjX3ikSfEtILrB2NH32qngqc63d4BmVw0/ mp2Uo3NtZx6Ba8bA5XGbtdqAzAOYMPvZMF/QW0Iw+Ofi+VOBHH4BrjWJetSngeZJeHom DuIIkyTaCXJDEl1nx4jKCp9BkIo4wUI1YoUQKlVRnKr0gf2AhFwjSpZUSurSUuuEtQBV Ahw2jbIfbSLLs4NAKXcGaj+KTkO2EdcyedGmRBUwADsBswsWEeBsQSDO5oykIxQW0c+4 wBeg== 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 k5-v6si12626985oih.2.2018.09.21.15.19.00 for ; Fri, 21 Sep 2018 15:19:00 -0700 (PDT) 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 EBABF15BF; Fri, 21 Sep 2018 15:18:59 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D62BB3F557; Fri, 21 Sep 2018 15:18:56 -0700 (PDT) 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 , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 16/18] ACPI / APEI: Split fixmap pages for arm64 NMI-like notifications Date: Fri, 21 Sep 2018 23:17:03 +0100 Message-Id: <20180921221705.6478-17-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-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 we can support multiple NMI-like notifications on arm64. These should be named after their notification method. x86's NOTIFY_NMI already is, move it to live with the ghes_nmi list. 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}. Signed-off-by: James Morse --- Changes since v3: * idx/lock are now in a separate struct. * Add to the comment above ghes_fixmap_lock_irq so that it makes more sense in isolation. --- arch/arm64/include/asm/fixmap.h | 4 +++- drivers/acpi/apei/ghes.c | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/fixmap.h b/arch/arm64/include/asm/fixmap.h index ec1e6d6fa14c..c3974517c2cb 100644 --- a/arch/arm64/include/asm/fixmap.h +++ b/arch/arm64/include/asm/fixmap.h @@ -55,7 +55,9 @@ enum fixed_addresses { #ifdef CONFIG_ACPI_APEI_GHES /* Used for GHES mapping from assorted contexts */ FIX_APEI_GHES_IRQ, - FIX_APEI_GHES_NMI, +#ifdef CONFIG_ACPI_APEI_SEA + FIX_APEI_GHES_SEA, +#endif #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 a0c10b60ad44..463c8e6d1bb5 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -994,7 +994,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; @@ -1025,8 +1025,8 @@ static inline void ghes_sea_remove(struct ghes *ghes) { } #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. + * NOTIFY_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); From patchwork Fri Sep 21 22:17: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: 10611073 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 C06C614BD for ; Fri, 21 Sep 2018 22:19:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B2F6B2DDC8 for ; Fri, 21 Sep 2018 22:19:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A73E12DDD4; Fri, 21 Sep 2018 22:19:08 +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 469622DDC8 for ; Fri, 21 Sep 2018 22:19:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B22748E0022; Fri, 21 Sep 2018 18:19:06 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id AD2CE8E0001; Fri, 21 Sep 2018 18:19:06 -0400 (EDT) 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 9E89E8E0022; Fri, 21 Sep 2018 18:19:06 -0400 (EDT) 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 73E728E0001 for ; Fri, 21 Sep 2018 18:19:06 -0400 (EDT) Received: by mail-ot1-f71.google.com with SMTP id h9-v6so13793650otj.10 for ; Fri, 21 Sep 2018 15:19:06 -0700 (PDT) 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=MRWCM2674PLZLao8XX6YSk3/LTKlQlpF1gW9UIEfsUY=; b=bxdet9RgOSwPgNAJUrO/Z5PL36lSrD6oqHsVoCcGDI5xyamzEiroqed02787aJIokk 0pBl3j9FH1NPYtbn/FD01GYkwAa4gDzNunUCQNs/+iMQzccJPIErB7n3DIDQRQBR9zbf m7OR/aI1KdH5iKMFfXnxzuvrYhoX5nIdv0uxNcw4pXhEKl1PHjkUNm3RfPDN6tYcgl09 lHYf2ofl+kVaRM5iCj26boviDKJXOIB5FtJqpoUKMQ2Z59rOsJi2OOYvxeq5G/y3c7KB mtspRP8Z7Vk2hbWjaajUjGXmqpWGWeR2vWCMseDUurV1IG4m/TAXav5XO49oYsc0maYS sbLw== 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: ABuFfog+eI6y1ylCl+/PqzR7ifHlvGy4EtnVJhjuGwJYEcr2LMtz0Ipm i2l4iDnFyFZ3YMSMC/eAuIzmd6ouiYitCAzOKBNQ7sIHkOoca0WudlDdVkyjrttTH1s627rvCfe ZycDvvUJdOapHfe8IqHVYRaKt8eEu4yBhoNHuQiVVyq5OuwT0ou23bYSJhuKsSkM0mQ== X-Received: by 2002:a9d:6082:: with SMTP id m2-v6mr1063965otj.177.1537568346242; Fri, 21 Sep 2018 15:19:06 -0700 (PDT) X-Google-Smtp-Source: ACcGV606L+XG2E/bGKGv1Qdkf5uWLHls1V62Z031u/Zg3z91X5c2CWE99NaoVQAjas/RWLkjMOjk X-Received: by 2002:a9d:6082:: with SMTP id m2-v6mr1063932otj.177.1537568345004; Fri, 21 Sep 2018 15:19:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568344; cv=none; d=google.com; s=arc-20160816; b=IRSo9Tdg1QC0013qPKp1pom57CwrkcU+ty4JG44aIe/ttuzP/s7NSGjPd7wa+0m2ip cljr9uymKBEGckIMmk+k4jVGojbtCCMe31l9Eo2TmePY6F6YFNlqwX1XfFVe6LTR0cDO kxlVZ+G12H6Q4DBdxRrlGaGCfU/NXekGlDyLj6pLoFKatO2My/GhZnOeQgJmvRlo1Kn/ kPk4Iu58XJFtqVOyprksaJ0zC7ecQ0f1L1LpSYAxw6adWqA2+TiLAdxNbdpgve+WsyU4 9QCpfsWtPZNNhjJ/I8q+pG/Ec9xbFO9FREnqK6ToUUuN4l7U4wsNpH66wtk/yJb39yBA hTDw== 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=MRWCM2674PLZLao8XX6YSk3/LTKlQlpF1gW9UIEfsUY=; b=QM+uBFhJO0hqMWeCXjKpkQUSbc0YRzWioP19jtUmd6hojBklXWExN5wR9wACz3mhEW 0DO8iguWhbQ5kABHcImbPiqjVmHcUHKjIa/qN6EWcwRXR5HRxKgvrCM19Z9t+njAmtrH LJdVnDtQNkWgMxTUOOmpPyMssJPlksrHeQiABQd9Kgp93YZixMtZnkkyNw9bTudBaw9N 4WGuze0IGsdttXLsVw66eXMggOX6HqVLCu4qiGKdfvmA8t1824soBVzuK1qt2QCA6b5K PHshKUMe3/isxTEmML+HXjqYb5B+FC+2tmPaguQw5aB85vXhZGtYWJLmEllZGfsdlqp6 PM3A== 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 x64-v6si10328466otb.272.2018.09.21.15.19.04 for ; Fri, 21 Sep 2018 15:19:04 -0700 (PDT) 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 8754318A; Fri, 21 Sep 2018 15:19:04 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 727973F557; Fri, 21 Sep 2018 15:19:01 -0700 (PDT) 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 , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 17/18] mm/memory-failure: increase queued recovery work's priority Date: Fri, 21 Sep 2018 23:17:04 +0100 Message-Id: <20180921221705.6478-18-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-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 arm64 can take an NMI-like error notification when user-space steps in some corrupt memory. APEI's GHES code will call memory_failure_queue() to schedule the recovery work. We then return to user-space, possibly taking the fault again. Currently the arch code unconditionally signals user-space from this path, so we don't get stuck in this loop, but the affected process never benefits from memory_failure()s recovery work. To fix this we need to know the recovery work will run before we get back to user-space. Increase the priority of the recovery work by scheduling it on the system_highpri_wq, then try to bump the current task off this CPU so that the recovery work starts immediately. Reported-by: Xie XiuQi Signed-off-by: James Morse Reviewed-by: Punit Agrawal Tested-by: Tyler Baicar Tested-by: gengdongjiu CC: Xie XiuQi CC: gengdongjiu --- mm/memory-failure.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mm/memory-failure.c b/mm/memory-failure.c index 0cd3de3550f0..4e7b115cea5a 100644 --- a/mm/memory-failure.c +++ b/mm/memory-failure.c @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -1454,6 +1455,7 @@ static DEFINE_PER_CPU(struct memory_failure_cpu, memory_failure_cpu); */ void memory_failure_queue(unsigned long pfn, int flags) { + int cpu = smp_processor_id(); struct memory_failure_cpu *mf_cpu; unsigned long proc_flags; struct memory_failure_entry entry = { @@ -1463,11 +1465,14 @@ void memory_failure_queue(unsigned long pfn, int flags) mf_cpu = &get_cpu_var(memory_failure_cpu); spin_lock_irqsave(&mf_cpu->lock, proc_flags); - if (kfifo_put(&mf_cpu->fifo, entry)) - schedule_work_on(smp_processor_id(), &mf_cpu->work); - else + if (kfifo_put(&mf_cpu->fifo, entry)) { + queue_work_on(cpu, system_highpri_wq, &mf_cpu->work); + set_tsk_need_resched(current); + preempt_set_need_resched(); + } else { pr_err("Memory failure: buffer overflow when queuing memory failure at %#lx\n", pfn); + } spin_unlock_irqrestore(&mf_cpu->lock, proc_flags); put_cpu_var(memory_failure_cpu); } From patchwork Fri Sep 21 22:17: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: 10611077 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 DC0B25A4 for ; Fri, 21 Sep 2018 22:19:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF8B22DDD2 for ; Fri, 21 Sep 2018 22:19:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B94D82DDDF; Fri, 21 Sep 2018 22:19:12 +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 451D22DDD2 for ; Fri, 21 Sep 2018 22:19:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DBACA8E0023; Fri, 21 Sep 2018 18:19:10 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D6B198E0001; Fri, 21 Sep 2018 18:19:10 -0400 (EDT) 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 C5B598E0023; Fri, 21 Sep 2018 18:19:10 -0400 (EDT) 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 9A3418E0001 for ; Fri, 21 Sep 2018 18:19:10 -0400 (EDT) Received: by mail-ot1-f71.google.com with SMTP id n12-v6so1993313otk.22 for ; Fri, 21 Sep 2018 15:19:10 -0700 (PDT) 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=Jk9gZco1Cu30m5Tw/JSrvCazhgDfTTXWmpc9MnvC4ws=; b=CjZTJmtds3aGkNBy3KbnFRHFWc0ht5LCGYm+dce9Lsc/rdu+5ZIfE9yP6EHNPVDC4G 5mrdiSQkVYr1HT1l4x7GS/fGCBlBjyVcMV+g7hIEgkMMF+Ewi8GjZq42nRZaeShIeCFz xL26PcDdTCztAVQkyEwIYErXfEyM8pNoxskvwzkj5jaq17sBc6gZ10URAGY0+yJUBBvu KXyNG9jeICMTTPne3z9XQrzWvoIwznV4EkYYbBpo4BVszciE47RWmp+YobnZiX8oykVw rXJhS+Gao03cw7Y+r6+9/qJKLfqHP4IN9EARzJuNBNABk08HrBUeSrEimorzY3VyCIGx QxtQ== 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: APzg51BzArT2GVp9K57LU0cagQK0Qwcrp+iNk1TL2sUMgaNYeHymTq3+ k6g6d3bGRGgPujQlorGCe6mZzMXV+onyLQgVCq7OSObHZg6PHiFfU1rb05DP5DVJ91TelGtcOnT Xi6k2OrTwDhPa/GxUZ7roJOz6uVL2M3C8WbbncklEzc4lhhhEQtkydSHbeHk/lp1xqg== X-Received: by 2002:a9d:541c:: with SMTP id j28-v6mr27838747oth.134.1537568350372; Fri, 21 Sep 2018 15:19:10 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbq7LaN3f1I/Psz6RR6JXcymV3rcO8c+gjY4lDTH4RkjLgkRxW14/pHAqa2/U4Hxg1sAMx9 X-Received: by 2002:a9d:541c:: with SMTP id j28-v6mr27838714oth.134.1537568349443; Fri, 21 Sep 2018 15:19:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537568349; cv=none; d=google.com; s=arc-20160816; b=tt9VUf68mVEyvyQIyOhPunoEgskF1EX4ZqfwZiQJQjJHXZIbUNNTsA3a1/7t1aSb8J VXfizojfvPHWqJL8YIDxUsXHVX//zBCNrSNxfakqOwHrqW2Kc87lFnD1RQqkCAiXm5Y8 e9xwljZQVqvBksOedoF7mVrv8rbue9T0CA2Ey9m8IFhq2XhlfEgIDrTnPDxuLBmtUyfT /bTKeX1Mu6xa5sfVOh4ubDakbk1IDk01pe3l+8DZw+jokcyJdT03ns7YLkiaKEEKyvt4 vBbCxwvUaGsl5gv8NC5hnPwtl3fOUBhO9U2LzRAASjwlHezKbf9KScpxeq2eefRPqsq5 j0gw== 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=Jk9gZco1Cu30m5Tw/JSrvCazhgDfTTXWmpc9MnvC4ws=; b=aM1LaLtkpEsq6knVVKoakzQZ5Pu6ygx5t7J8UP9d4N10RBPHtQPCsqrNZDZ2Y0mtn9 sna7WXa7Zl2IFo5T9ieJaAqd0mL4AhkixjHJUNkQHgbpHug2WgfsYAlg4TZ6OVClaMgV 6T15A2HxbMxMNy51rQ01XdFm8o33CvEKljui6bphpSgMuH8ZHoxlWkRG2+tPleATL/jc lDz2GNQtB8wQqWOUUCtfT3+Enjj+CPts9xUoHfPE0bcJ8qThaXiw79XTT9HlmsWQFhe5 OwIKHbIXZwvwAgbl7VEIc4TrXBt7TZfMGBNdeCWShu9ylL3DOfJ7P11N/8ObWg+6sYFy I79A== 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 r17-v6si11765982oic.35.2018.09.21.15.19.09 for ; Fri, 21 Sep 2018 15:19:09 -0700 (PDT) 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 E085518A; Fri, 21 Sep 2018 15:19:08 -0700 (PDT) Received: from melchizedek.Emea.Arm.com (melchizedek.emea.arm.com [10.4.12.81]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id CB4903F557; Fri, 21 Sep 2018 15:19:05 -0700 (PDT) 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 , Tyler Baicar , Dongjiu Geng , Xie XiuQi , Punit Agrawal , jonathan.zhang@cavium.com, James Morse Subject: [PATCH v6 18/18] arm64: acpi: Make apei_claim_sea() synchronise with APEI's irq work Date: Fri, 21 Sep 2018 23:17:05 +0100 Message-Id: <20180921221705.6478-19-james.morse@arm.com> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180921221705.6478-1-james.morse@arm.com> References: <20180921221705.6478-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 we can't guarantee this will be taken before we return. Unless we interrupted a context with irqs-masked, we can call irq_work_run() to do the work now. Otherwise return -EINPROGRESS to indicate ghes_notify_sea() found some work to do, but it hasn't finished yet. With this we can take apei_claim_sea() returning '0' to mean 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 --- Changes since v2: * Removed IS_ENABLED() check, done by the caller unless we have a dummy definition. --- arch/arm64/kernel/acpi.c | 19 +++++++++++++++++++ arch/arm64/mm/fault.c | 9 ++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/arch/arm64/kernel/acpi.c b/arch/arm64/kernel/acpi.c index a9b8bba014b5..09744e2d15a0 100644 --- a/arch/arm64/kernel/acpi.c +++ b/arch/arm64/kernel/acpi.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -270,10 +271,14 @@ int apei_claim_sea(struct pt_regs *regs) { int err = -ENOENT; unsigned long current_flags = arch_local_save_flags(); + unsigned long interrupted_flags = current_flags; if (!IS_ENABLED(CONFIG_ACPI_APEI_SEA)) return err; + if (regs) + interrupted_flags = regs->pstate; + /* * SEA can interrupt SError, mask it and describe this as an NMI so * that APEI defers the handling. @@ -282,6 +287,20 @@ 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 { + err = -EINPROGRESS; + } + } + local_daif_restore(current_flags); return err; diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index 2c38776bb71f..97036e01522a 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -630,11 +630,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; + } clear_siginfo(&info); info.si_signo = inf->sig;