From patchwork Thu Oct 3 15:51:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 175184 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp627168ill; Thu, 3 Oct 2019 10:26:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqx0ha3SsA3ThvUpUsBdoc7S3mHqLyml5oy+2cbYRykXM6WABoU7OgohZOsCJWXzOkbIYl0v X-Received: by 2002:a17:906:d926:: with SMTP id rn6mr8520559ejb.175.1570123575720; Thu, 03 Oct 2019 10:26:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570123575; cv=none; d=google.com; s=arc-20160816; b=bYmsV8z1LpriX2E51xNS+NMOYZwyQjDRZmSxFqvbhLwnPUUjxYAPenIQUn8df60G+t 9LnNUx20XoRQvhSjwED2R8xcQ00xC8wNIXC1RuJ5mx11XvfnnPdOg/37GjaQJvnJO+En w1AO3rTa+Mutx+CQNLSaewQcfbqIsc+5Uo6YVta2uP/CzP3M2m2IyUMMIFatvRizqtxY DD7l64GMR6QiBJZzhipy5rDjTER8u9VJYuOdefDXOHdNY60SeVxw3v1JFyeijRcH2vaU JyorgRW3AAEl0vYMfBlKlBYgiLNtaV1kgyVDV/jGq1hwVH3fW0YLn4N7syOQz/aVy4bM ylyw== 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=skfHzbnpMoMCzJP77C7m+dDMcBWSLaYi9HOKhfcMK5k=; b=gSNribW3XaQgfnQvtK9B25Ok8VA7iPF3CJf7HZGIb0Xt5iwHdBxNcVDHHR9d2XhWW/ vExx6NF4q56uHpO85oZrA2CwvCEIieTU3jeNa8rl6HexGzSAIFvlVuBfz/8pJjw9gr6l HnXUYgC1i0YqDKgwXCbjUc8P3YyTfjX/r5HUzLJ6N6bPykGa7jvwRuhqJsgcCUDle6/K 1TKv7wkzc8X2OrpnJ3wYepvTUFUYDzZ2W5DFtPdLHcZJPXqAFHzxFO8ZbO7+TnGXFuv8 2G+gy2Be22V+5hlYUqp99XOaGAr8UifEEIa4Mkbft4Ihfik7bws8fkgIHT9fFNSq3EvR 2/eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Tgkw+Mjl; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-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 s17si1565483ejz.148.2019.10.03.10.26.15; Thu, 03 Oct 2019 10:26:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of stable-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=Tgkw+Mjl; spf=pass (google.com: best guess record for domain of stable-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730592AbfJCR0K (ORCPT + 14 others); Thu, 3 Oct 2019 13:26:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:41352 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388969AbfJCQQZ (ORCPT ); Thu, 3 Oct 2019 12:16:25 -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 E423D20700; Thu, 3 Oct 2019 16:16:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570119384; bh=REPlmJ3AG9u8ggMbAE/uWkhiDbswCFmGAr0G8TJ0BKE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Tgkw+Mjl2Z/PxXOCD1b2BUHiP//FQf+0EaS1C0SUQPXg+GvOtP4c2CwVMv5T4iusU DkRi00GC/P8gMNSX+sQsQe+S4R83YuG6SiIiS9Ormkq2FMhf7M0n+dpLi1ksG6IC1j S0hWnZKHZ00+i5AKbqG5PsPzpkwJWUO5ceKxzgMM= 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.19 046/211] EDAC/mc: Fix grain_bits calculation Date: Thu, 3 Oct 2019 17:51:52 +0200 Message-Id: <20191003154458.628881944@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191003154447.010950442@linuxfoundation.org> References: <20191003154447.010950442@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 7d3edd7139328..f59511bd99261 100644 --- a/drivers/edac/edac_mc.c +++ b/drivers/edac/edac_mc.c @@ -1246,9 +1246,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,