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) {