From patchwork Thu Oct 3 15:52:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 175102 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp528325ill; Thu, 3 Oct 2019 09:09:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqwE0LKJGXbKst09op2NWq6imL0/g5bIBAXJ4HqsTGW4fVzcDLHPE6qEMxQ0nEzPEu0gxclY X-Received: by 2002:a05:6402:32f:: with SMTP id q15mr10285617edw.143.1570118954673; Thu, 03 Oct 2019 09:09:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570118954; cv=none; d=google.com; s=arc-20160816; b=L27vYu4jNs2FD+7FG6f79L6Mism1G2F1Y+BUfSUUn0a3Y19uWI0kYS11PgTqISGiZ5 JPSeY68MJd6NH+yCx3V8YC6vEVmbn242ZFd0gweIBdSodjBHXFgPZhlVvHTmbKmekgcH FbhhDAKvNswNSgxtaiwfWjaKLPGgukLvA1X5tVBnODILywuudGAdOfnNkSyxn4bt+ZYE i7AXRi+DUE/P75b74ei8lH0mVGdhC6tKmqLaz2udPfbMfXyNMgXeAXX4/J6IrFSOni7H ZRzF/0rPegdlM0nytZIDEkEfPWGoTpoa3aImH9GRelMWqLD3LBcTFRA0RC29uKgqgXxq Qgbw== 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=h6cY9aMAMEeatSETVtKVMIkHdX7aqZnGVr7gIza3IE0=; b=ALWnVQsghsiBfhFMmUTnwWqk185r5uUqKxELN5i2bbFcIEblb4k9Eb0JUdY7PxPPvp KlLYVeWhgWrZQw4+W6v+EV3Tvo1sXW0UVhkKTdn+ijNVbVGlNzw541+n3wlfyd4jm5Tc aBbbuyU6op7A1zxwxbvUChhphR6wCnNltZ180MMk8jdrA/amv9ODl5gJYzVjWoyVIlc5 AwIPoVylGd6KRWMlbIPjORJuLkLs2W0NB8Tr9udG1sXHrwhG2T1cWEhzdWbZOvAJWMZp 38VHig8Mh4lOs1Z9jQdku98LWViMw20eLE7Z0yY1fWohqzzQqLy8sc1WdJQjOU6r1p4S NNIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eogvt0xL; 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 t9si1512665ejr.29.2019.10.03.09.09.14; Thu, 03 Oct 2019 09:09:14 -0700 (PDT) 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=eogvt0xL; 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 S1732733AbfJCQJN (ORCPT + 27 others); Thu, 3 Oct 2019 12:09:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:57844 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733078AbfJCQJM (ORCPT ); Thu, 3 Oct 2019 12:09:12 -0400 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 BA052207FF; Thu, 3 Oct 2019 16:09:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570118951; bh=q7MH5xjL57lYshgLlsRFQ3lgZeENdcd5LR0JjZVkFok=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eogvt0xLu2N0RzVWDBH3iISmxmo1Oy3cYBIRHQqYRJPBTOgzXZ4ZmEaPI3k/g2dTv RfX4ofd9OODlKbr3Y4X/RVMgvDAgXPhJUSkwsVS87M9z7PL/YE3yVhxM6Voyqon9U/ 2fSpgoqyis0AF+syOScmyHntv34OjvgzxB2pbig0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robert Richter , Borislav Petkov , "linux-edac@vger.kernel.org" , James Morse , Mauro Carvalho Chehab , Tony Luck , Sasha Levin Subject: [PATCH 4.14 069/185] EDAC/mc: Fix grain_bits calculation Date: Thu, 3 Oct 2019 17:52:27 +0200 Message-Id: <20191003154453.150860539@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154437.541662648@linuxfoundation.org> References: <20191003154437.541662648@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 3724ace582d9f675134985727fd5e9811f23c059 ] The grain in EDAC is defined as "minimum granularity for an error report, in bytes". The following calculation of the grain_bits in edac_mc is wrong: grain_bits = fls_long(e->grain) + 1; Where grain_bits is defined as: grain = 1 << grain_bits Example: grain = 8 # 64 bit (8 bytes) grain_bits = fls_long(8) + 1 grain_bits = 4 + 1 = 5 grain = 1 << grain_bits grain = 1 << 5 = 32 Replace it with the correct calculation: grain_bits = fls_long(e->grain - 1); The example gives now: grain_bits = fls_long(8 - 1) grain_bits = fls_long(7) grain_bits = 3 grain = 1 << 3 = 8 Also, check if the hardware reports a reasonable grain != 0 and fallback with a warning to 1 byte granularity otherwise. [ bp: massage a bit. ] Signed-off-by: Robert Richter Signed-off-by: Borislav Petkov Cc: "linux-edac@vger.kernel.org" Cc: James Morse Cc: Mauro Carvalho Chehab Cc: Tony Luck Link: https://lkml.kernel.org/r/20190624150758.6695-2-rrichter@marvell.com Signed-off-by: Sasha Levin --- drivers/edac/edac_mc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) -- 2.20.1 diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c index 80801c616395e..f7fa05fee45a1 100644 --- a/drivers/edac/edac_mc.c +++ b/drivers/edac/edac_mc.c @@ -1240,9 +1240,13 @@ void edac_mc_handle_error(const enum hw_event_mc_err_type type, if (p > e->location) *(p - 1) = '\0'; - /* Report the error via the trace interface */ - grain_bits = fls_long(e->grain) + 1; + /* Sanity-check driver-supplied grain value. */ + if (WARN_ON_ONCE(!e->grain)) + e->grain = 1; + + grain_bits = fls_long(e->grain - 1); + /* Report the error via the trace interface */ if (IS_ENABLED(CONFIG_RAS)) trace_mc_event(type, e->msg, e->label, e->error_count, mci->mc_idx, e->top_layer, e->mid_layer,