From patchwork Tue Jun 26 17:01:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Morse X-Patchwork-Id: 10489621 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 BF62860553 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 A8D8328236 for ; Tue, 26 Jun 2018 17:04:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B511286DF; 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 8E2EB28847 for ; Tue, 26 Jun 2018 17:02:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71DD56B0284; Tue, 26 Jun 2018 13:02:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 6A8596B0285; Tue, 26 Jun 2018 13:02:50 -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 595ED6B0286; Tue, 26 Jun 2018 13:02:50 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-ot0-f198.google.com (mail-ot0-f198.google.com [74.125.82.198]) by kanga.kvack.org (Postfix) with ESMTP id 30C736B0284 for ; Tue, 26 Jun 2018 13:02:50 -0400 (EDT) Received: by mail-ot0-f198.google.com with SMTP id r58-v6so12421316otr.0 for ; Tue, 26 Jun 2018 10:02:50 -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=5oEyi1psR52+AKJ96dGQ3WwbRFw+8tTAR3q7/aWhsf4=; b=AIRZkm8FV9kEnPx/P1Jz6A1VRKAprQrrtZzmWDaYt98w7Mr++F55jgzKW6Q4XToXD+ 3A7ZOnK0s4fC+zEEhMT0gL7OKCgi2n5yIwNFmw4rr0E2zlTaxC9Y9b51v/i5hiNicWq2 uczuqe/STdF7ZWOS9qdUslqwm4fFHZayPK+mc/dT9j5jUfYa3p53a9KlajdtTBBxgHoq FKLOIqfsdJpO9A3y2uddF5Ncim2pEnl2GpEIUbMB8fV+PgpJnJ5qg6uzPSi9dNdYu+gI fmQh2h390D+lMtzS40yHe+QUT0notZOGc09j7zw72RcK30G+wsJi9ymC3x99QbW0oOCK phrw== 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: APt69E2WxKtJ5LtYEGraN+CaByBmaTah1lnMBOHKfykxcyFtLnyc6Fou VRbso9ORkZ3WcUilLxPTZS2+5GmSkZACqZMzrqpS+u/oPLynfv5cOIEAAyYg2eC7DtoTm0vajJ9 2VAM/ci6HE+H6BdFV8xJGYZti1S/eEhjh4MM2FKEktEg6mk12tg1yBMwzHLzuMyC6zQ== X-Received: by 2002:aca:c70a:: with SMTP id x10-v6mr1251831oif.43.1530032569984; Tue, 26 Jun 2018 10:02:49 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdm5xa40WolICnkhCV/HswAwZGR0wCk78y2zWBm242Dizn/wUvC4TA5LmUYVNAwt53KifFT X-Received: by 2002:aca:c70a:: with SMTP id x10-v6mr1251752oif.43.1530032568178; Tue, 26 Jun 2018 10:02:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530032568; cv=none; d=google.com; s=arc-20160816; b=rbV+owtoE9vuTeIvnAIfSzjVkE2269XiRhANiNABaqi7wbhC2BCwlFnv+jbWdfOydE 54akI5qbtcxMwmIfJrk7FthsI1cV4oz7wmvcCL9p4M/LuaL/PP4RO5TVVsOK/GAjMSZF QYPDx1PZcVJx+QDZodUclXoKnhrXP7vaSZ4x6Bd55tRM6IQLwZels1VVBRpcYxw7Srp0 Yxkt7bPazSk+f+RXFYW9intzdEQTm90kU5K/PeEhrrhweFKmrIBHlTz87WAIOT5qOnl7 19UCpc1fIB/MMZukGN6z0XfNisvA6XmnDWpKLBz688YQK55VG1pHm2/1EXFJGmcCdr6J wESw== 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=5oEyi1psR52+AKJ96dGQ3WwbRFw+8tTAR3q7/aWhsf4=; b=PP+0q8wcRuLSThu/QIA/yo8N+DAQTOYVAGzdVIzEegiTmA0pwhNHi9YzjHkRqi+gqo K/gibj/HbNFm7BLPN9JeQAVpdwyC7MBxGzweIpZ0z82YvWBBXcc2R0CB5o3lfXUqBYvj zp7MI9IRA5VfjWNKIt3wGe/vo3naWv0fym5kcw7XMptkHqUR0suxWagTZ3eEnIZZQ3y9 HHhOGb/VY3dzhfNNM5XHIAwrr150OvvVxjfPIDPShPk1ax9vrL1GpA8bH4PjAKOsrYti c3AMnIC65tf3dTCmy5fqxSti5AdFoLsxBfqK8ezfljM6zLE9xJxj+Py4D3Y/rkElwGSO kWSQ== 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 t2-v6si669291oig.82.2018.06.26.10.02.47 for ; Tue, 26 Jun 2018 10:02:48 -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 AECD61713; Tue, 26 Jun 2018 10:02:47 -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 50E253F318; Tue, 26 Jun 2018 10:02:44 -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 14/20] ACPI / APEI: Split ghes_read_estatus() to read CPER length Date: Tue, 26 Jun 2018 18:01:10 +0100 Message-Id: <20180626170116.25825-15-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 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 75360525935d..1d59d85b38d2 100644 --- a/drivers/acpi/apei/ghes.c +++ b/drivers/acpi/apei/ghes.c @@ -289,11 +289,12 @@ static void ghes_copy_tofrom_phys(void *buffer, phys_addr_t paddr, u32 len, } } -static int ghes_read_estatus(struct ghes *ghes, - struct acpi_hest_generic_status *estatus, - phys_addr_t *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, + phys_addr_t *buf_paddr, u32 *buf_len) { struct acpi_hest_generic *g = ghes->generic; + struct acpi_hest_generic_status estatus; u32 len; int rc; @@ -308,26 +309,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: @@ -337,6 +335,35 @@ static int ghes_read_estatus(struct ghes *ghes, return rc; } +static int __ghes_read_estatus(struct acpi_hest_generic_status *estatus, + phys_addr_t 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, + phys_addr_t *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, phys_addr_t buf_paddr, int fixmap_idx) {