From patchwork Sun Dec 29 17:19:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 182544 Delivered-To: patch@linaro.org Received: by 2002:a92:815a:0:0:0:0:0 with SMTP id e87csp5450095ild; Sun, 29 Dec 2019 09:33:41 -0800 (PST) X-Google-Smtp-Source: APXvYqwqO51o14bWiYcvt9k/f91mzbzRythIAc+BK/TzAwR5BzAtqk6nuftnUcRTL1L59kg50sEF X-Received: by 2002:a9d:5c86:: with SMTP id a6mr70416962oti.68.1577640821489; Sun, 29 Dec 2019 09:33:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577640821; cv=none; d=google.com; s=arc-20160816; b=zmvSEZuxbyvb4dq5JW3xvmHk3dOMiG6G0vZR2XwaK8Th0HD06v/9NdYCwQwMY4b9zP duxr7GKOZFQfrZz8ytRAcE+0mP4uI8vZj2qpE82ROUyKzJIqb3Ae2+UfAUJAJxR401OZ eAs3U3CuRmjCkMiKZt0R4Q461nzPPWoLI8MeKPTr2ntskfWDmO8knbEnKSB3nxnIldWN wvSZh946OFcaIuiVohET9hpnIEr3o9SxpXLIlholbZpqzbDRbvi3evjkMgxIkFl9fL57 HNZ8T31lhSnVKeMP0lp/fq5GlsAOWeEzmIGZyHN77+jxgwx4thYrvqVGWUBB9jvRvgMv oSQQ== 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=DvZ3GhAVXzLylW1kj9Y66/Bz3NQdE3K4w/oFBzcQuMs=; b=ToN9XRHX3Cc4EEWk4eqA6kqOFTwaZ2znkFflCpAGz9xjPmOk8CQvwMRvHQeEXYiCCB /jNAGIGDwQGmvNB9w2/M8I/I0tbkk8UmcGlrZDbWEcOIwSD3fJ2kWHSb11Pzxmb+oLyz X4Fc/C+OLkaq8YEgxOz82RqWIO/O5ri5yosNMa0+ivZggKxNbF69KUtOB3+2EltZgQFw h2DUhw4FZiBaqIkI4YjUZLawtXQzbDfJFDjFLCIVt0s6wH1x3h18Xo3MBzj2xs12Jwli j5hGY1aLdQBWeOI/Z+DkNBPpgcWzKCA3p46YMcYNPoPdA/BYJDxJoDERaJ+pHoIyuLAa z82w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bURsVCl9; 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 h138si19581659oib.6.2019.12.29.09.33.41; Sun, 29 Dec 2019 09:33:41 -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=bURsVCl9; 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 S1729490AbfL2Rdk (ORCPT + 27 others); Sun, 29 Dec 2019 12:33:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:35474 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729459AbfL2Rde (ORCPT ); Sun, 29 Dec 2019 12:33:34 -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 9E555207FD; Sun, 29 Dec 2019 17:33:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577640813; bh=tuRipZte5EqskJXk8kD1/fPZoHKEC/8f/pLxDLZ6hIE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bURsVCl9+Rui7rCzX+5Ewe6WTDVExQC9FWnVI0+Jzxc1vgTFzi1c/1IZW8Y3mkOM3 crfZe2Ba8xqnTKTikc7KN3BIa3fZnPPUDC60ElI77XKjAS6vOi+R8UWa+cKMaIhTzy 7J+imMxIMEc9mRc5MQ0a02KhHeEHlE3IIThwZlJg= 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.19 149/219] EDAC/ghes: Fix grain calculation Date: Sun, 29 Dec 2019 18:19:11 +0100 Message-Id: <20191229162530.890383917@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229162508.458551679@linuxfoundation.org> References: <20191229162508.458551679@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 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(-) -- 2.20.1 diff --git a/drivers/edac/ghes_edac.c b/drivers/edac/ghes_edac.c index 574bce603337..78c339da19b5 100644 --- a/drivers/edac/ghes_edac.c +++ b/drivers/edac/ghes_edac.c @@ -210,6 +210,7 @@ void ghes_edac_report_mem_error(int sev, struct cper_sec_mem_err *mem_err) /* 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; @@ -305,7 +306,7 @@ void ghes_edac_report_mem_error(int sev, struct cper_sec_mem_err *mem_err) /* 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; @@ -412,8 +413,13 @@ void ghes_edac_report_mem_error(int sev, struct cper_sec_mem_err *mem_err) 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,