Received: by 2002:a17:90a:9103:0:0:0:0 with SMTP id k3csp11813378pjo; Thu, 2 Jan 2020 14:43:57 -0800 (PST) X-Google-Smtp-Source: APXvYqyPjz3NGKj6PebDYcQ2cmb3Zox+F4JieGq9Mi1sQW3Gww7BCfb8RQCqUO/cYJEJd/lOVrNL X-Received: by 2002:a05:6830:12da:: with SMTP id a26mr71498016otq.223.1578005037152; Thu, 02 Jan 2020 14:43:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578005037; cv=none; d=google.com; s=arc-20160816; b=QlmjefN9qyWJnu7uXTbLuZh7LwqfNIwEsInMQevQhIoHXlhdsnQD/KdRJR4R5DnTX3 kj2ZGHDJ94dIt+vHGIRUg2PGn/awN+2aJ5zvgldgeM3JKJtJyo7qEak8GgI5TyaZySos x2YzwkQzUzlpnheyXOs93yzkGA7FUpU3LhEo9g43TpXtMmzQ8ZtXiex8xlSnWdvFZkLx 5MtW8YHgkO+rdSsHW1IqyE5VS4IYWg7voClqLsUyrer9SEcEk3rk8zsxbswb1aclGCq3 ADbW4s3FqSUNmnfIO23vKMsureVbV83TduHmKBWI6+wZHIDhrZbfY1XafqEn7tYdTm+r qMAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0nl9gZaVKMojX/yQOeitihJIGmu0VE8UKtR2Y7V6pFg=; b=q+DpR8CqUiZeL/eWfMYXX6yGQ5akAP+9W3EIPlcigWNFAugBh/Yg8wle08BOhneJQx 44lHN1C/ACcP07XICrc1uNDFycXkVyKi7cYLBJUKaND7YbeZ36E9yY9MBwaraPG5lrBp bZNM2pHCJltCj8DCVROup2r93IN51Jk6D5HtiO+WB1Dmk8xIbpOKDZwfgqHJS267gHrD OYrbUxJpUmznpYhIDQDTRm8zWG+M/te6smy8JyFyCvLXXwq4BcN2jjbAT9gu91CY/JG4 VNdQgqQb4oBFvN52dxPC48TEpywyVWj328kDLZtLNF+z5gcWIPO5IZYwTAEkWF96snio od7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=s+N0ym+x; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u12si21121597oiv.13.2020.01.02.14.43.45; Thu, 02 Jan 2020 14:43:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=s+N0ym+x; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731309AbgABWmV (ORCPT + 99 others); Thu, 2 Jan 2020 17:42:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:46558 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730472AbgABWgF (ORCPT ); Thu, 2 Jan 2020 17:36:05 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DA7E121835; Thu, 2 Jan 2020 22:36:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578004564; bh=Cx/xZ2CdBultJ1QQYrebdLtgIDl5PklKrm8PpPvqR0s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s+N0ym+xhbEvBu3sz9EYWSDe4RK/CiSSrnVIKWphbjCEfItnglWaGyfO1NoWl1Z/j Yyhhuq79PZDhznsU2gJEiXOh2Axp4wSAygRW2H79OrTZkJDS3Elmxxna69FR4CKmG5 EwZyE9b+6QyWnOJe8bSQmYJJmo+dvKBIlE8i5lfI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, James Morse , Robert Richter , Borislav Petkov , Mauro Carvalho Chehab , "linux-edac@vger.kernel.org" , Tony Luck , Sasha Levin Subject: [PATCH 4.4 052/137] EDAC/ghes: Fix grain calculation Date: Thu, 2 Jan 2020 23:07:05 +0100 Message-Id: <20200102220553.544836208@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102220546.618583146@linuxfoundation.org> References: <20200102220546.618583146@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Robert Richter [ Upstream commit 7088e29e0423d3195e09079b4f849ec4837e5a75 ] The current code to convert a physical address mask to a grain (defined as granularity in bytes) is: e->grain = ~(mem_err->physical_addr_mask & ~PAGE_MASK); This is broken in several ways: 1) It calculates to wrong grain values. E.g., a physical address mask of ~0xfff should give a grain of 0x1000. Without considering PAGE_MASK, there is an off-by-one. Things are worse when also filtering it with ~PAGE_MASK. This will calculate to a grain with the upper bits set. In the example it even calculates to ~0. 2) The grain does not depend on and is unrelated to the kernel's page-size. The page-size only matters when unmapping memory in memory_failure(). Smaller grains are wrongly rounded up to the page-size, on architectures with a configurable page-size (e.g. arm64) this could round up to the even bigger page-size of the hypervisor. Fix this with: e->grain = ~mem_err->physical_addr_mask + 1; The grain_bits are defined as: grain = 1 << grain_bits; Change also the grain_bits calculation accordingly, it is the same formula as in edac_mc.c now and the code can be unified. The value in ->physical_addr_mask coming from firmware is assumed to be contiguous, but this is not sanity-checked. However, in case the mask is non-contiguous, a conversion to grain_bits effectively converts the grain bit mask to a power of 2 by rounding it up. Suggested-by: James Morse Signed-off-by: Robert Richter Signed-off-by: Borislav Petkov Reviewed-by: Mauro Carvalho Chehab Cc: "linux-edac@vger.kernel.org" Cc: Tony Luck Link: https://lkml.kernel.org/r/20191106093239.25517-11-rrichter@marvell.com Signed-off-by: Sasha Levin --- drivers/edac/ghes_edac.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/edac/ghes_edac.c b/drivers/edac/ghes_edac.c index e3fa4390f846..4ddbf6604e2a 100644 --- a/drivers/edac/ghes_edac.c +++ b/drivers/edac/ghes_edac.c @@ -189,6 +189,7 @@ void ghes_edac_report_mem_error(struct ghes *ghes, int sev, /* Cleans the error report buffer */ memset(e, 0, sizeof (*e)); e->error_count = 1; + e->grain = 1; strcpy(e->label, "unknown label"); e->msg = pvt->msg; e->other_detail = pvt->other_detail; @@ -284,7 +285,7 @@ void ghes_edac_report_mem_error(struct ghes *ghes, int sev, /* Error grain */ if (mem_err->validation_bits & CPER_MEM_VALID_PA_MASK) - e->grain = ~(mem_err->physical_addr_mask & ~PAGE_MASK); + e->grain = ~mem_err->physical_addr_mask + 1; /* Memory error location, mapped on e->location */ p = e->location; @@ -391,8 +392,13 @@ void ghes_edac_report_mem_error(struct ghes *ghes, int sev, if (p > pvt->other_detail) *(p - 1) = '\0'; + /* Sanity-check driver-supplied grain value. */ + if (WARN_ON_ONCE(!e->grain)) + e->grain = 1; + + grain_bits = fls_long(e->grain - 1); + /* Generate the trace event */ - grain_bits = fls_long(e->grain); snprintf(pvt->detail_location, sizeof(pvt->detail_location), "APEI location: %s %s", e->location, e->other_detail); trace_mc_event(type, e->msg, e->label, e->error_count, -- 2.20.1