From patchwork Tue Jun 26 17:00: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: 10489619 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B038460386 for ; Tue, 26 Jun 2018 17:04:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 97C8D284BD for ; Tue, 26 Jun 2018 17:04:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 95CCD28680; Tue, 26 Jun 2018 17:04:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11C8128B09 for ; Tue, 26 Jun 2018 17:01:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BB3A56B0266; Tue, 26 Jun 2018 13:01:52 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B637C6B0269; Tue, 26 Jun 2018 13:01: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 9DF7F6B026A; Tue, 26 Jun 2018 13:01:52 -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 707376B0266 for ; Tue, 26 Jun 2018 13:01:52 -0400 (EDT) Received: by mail-oi0-f70.google.com with SMTP id 9-v6so11744104oin.12 for ; Tue, 26 Jun 2018 10:01:52 -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; bh=kSBrtkrN01BMVsRvxxFTM9P9aSIeVPAEzudQcJn3MSk=; b=t8jBa3DG4UHPV3jeHRs130k0owCbgddLfxOhh5BaMdtDa3cep3AK496GW/azVDqC26 cYnXTDe0uDU4J3S8BopS0kvnpx9Cf1EycwghA2HGTJt165N5ObFDcE6GQeeeyERto3/P CSYyYmn368BlP8afvbc0FAAdlFvd5/9Tf9RoD4dXQx+HYQvqzCPoLajUF9ZhOAn+XHAf zeVEyzRG3xoumYCNYeLGUVgt3AO6uZCOB84/E2Ep7I1Oy+Rc6nyYkyC77LiTwwBBjRSK iT5EhaUUH8RBwPFWQh5EG0KQPGrtXCLzxSOTkkkAIBguL9kiMH/63pPq+iSC3IF6SWep EoIA== 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: APt69E2KB2zyOPRy2mDqeKssrMQB1C7270FjS8cD0U4+/WK/Krjm5iEM b3F5+/QGiOkc8sYtZZnpYGeTpPhql3Ub/imUhtt6IZGo3ziQqAc39ILbhbKb0ufQIJrzovn9mB9 ckAgjUMcNMfqd7tmPCZ56SZfThqOJxqfD1ynlUOi8E91VyEn/xVzaxdzC2IGkI4FgUA== X-Received: by 2002:a9d:3421:: with SMTP id v30-v6mr1245755otb.245.1530032512144; Tue, 26 Jun 2018 10:01:52 -0700 (PDT) X-Google-Smtp-Source: AAOMgpe9PMVe1MN2scxVRBHCHJ6TtMdIUOl/Su9FmblYD1/WnXZZWzmWdbqtSTm9Y5AQlDarYVvT X-Received: by 2002:a9d:3421:: with SMTP id v30-v6mr1245681otb.245.1530032510827; Tue, 26 Jun 2018 10:01:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530032510; cv=none; d=google.com; s=arc-20160816; b=oSIiACKfCuOr3N3arFpc6SeCRGM8w+C5QWM6K66w3sW0xuRjv5W60KlSMUMKsvldEz qe+Y2WoaZ4SJaVip1Y4Nz7R5XpnJTED8fZOqAfJ0HWBkWsDKvLnvdO3Xnyytr4W3lVwo xvA1AhLaUglNAUyWULY9uGpS0D9qg4+68rFE/UofiTho6oXg2W2UGNkbbgrovPGH9VuA dN8W+cN2XaN9xWmmIOFzCJ4BAsiXnSHZ/9F2yd2VQf6EEEKshscPNx/y6GegWsEyufTT 9bjqiejFvpex2lj3S+TTyng+IPryiojQLwB9iHhHBmNg+2hLpEXy+t/wUEzGtNhw+y6J Og8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=kSBrtkrN01BMVsRvxxFTM9P9aSIeVPAEzudQcJn3MSk=; b=tlavJB2AA+Rj15Udx7JphhXbaWRApNJNPSrA9oNjWE/9WexVlaAW3FKrPabnGT0EO3 SO92zLiTICYO4JmPk2wfFfX/Rof3w8TrO25Xrrw+OiecPx4SJjd9ryvh4wkY7W2qCd3w d5VIjteqz/Ubucl20A5wUF/qfLGFUj0Q6N3w7XkHB6OoJASme07V3WC36qR1amu5ZN2l dyqP7Q68y5xZGwecdjEhduh2rXNlO675zJAPARG/QV16zX6Z3R3N4MTom0UzgS2GptVu r9ewsPkkSlaNPJG6HJUMK12XlfrWcG1l+8Ker6CHTG3kFrtaed/B0cjByh2YuVh4J7Hw XFPw== 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 (foss.arm.com. [217.140.101.70]) by mx.google.com with ESMTP id t192-v6si590752oif.142.2018.06.26.10.01.50 for ; Tue, 26 Jun 2018 10:01: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 6E16AED1; Tue, 26 Jun 2018 10:01:50 -0700 (PDT) Received: from melchizedek.cambridge.arm.com (melchizedek.cambridge.arm.com [10.1.206.34]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id DD70E3F318; Tue, 26 Jun 2018 10:01: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 v5 01/20] ACPI / APEI: Move the estatus queue code up, and under its own ifdef Date: Tue, 26 Jun 2018 18:00:57 +0100 Message-Id: <20180626170116.25825-2-james.morse@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180626170116.25825-1-james.morse@arm.com> References: <20180626170116.25825-1-james.morse@arm.com> 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)