From patchwork Mon Jun 24 15:08:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Richter X-Patchwork-Id: 167603 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp4347141ilk; Mon, 24 Jun 2019 08:09:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxrSFLMwwcgWCDuV6cIxL+y3M9DX9NlIu5IeXWDrI8mjuIvYJyTvdd87vepBW3PEXfkgdR X-Received: by 2002:a17:90a:8c0c:: with SMTP id a12mr25480756pjo.67.1561388950476; Mon, 24 Jun 2019 08:09:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561388950; cv=none; d=google.com; s=arc-20160816; b=v7n1Aemg6jc7aZ133nBRVtYRpdi0r5NXzTGxxsR6DpmQtl+qPuI7jNm9KMFXSH3CDD Kn2k2cswAkw/MN3gNP1sgQej6FqdfrJNSTZOiNDg4ZJPZ3EQsyVVZSdkZhDuESFpQxDv OhTRIOSoEJXlRXy0mDWWWbOHWXqjA4n2ogq/QvOgC0D7Q2QExARjwRiZXjFhZW5vIfu8 0jTof9Ke2BvoXMZEIxgs3bAON3ys4vbTmyIgBUhDdxJlDpagUKoLMpCoKzLrPpdqEAGK r0ALolJZWKUt9eP+jk8OEP6m3OAuVx6dLcfaSwpURq2tJ549xvgbtOzRHKVAIX/LdaPx at6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature :dkim-signature; bh=pIs8IdJVaFhb/v9+wntLcWsZ3Y3pUgrJps923RgfgQU=; b=cJqeTiCJS9WRyKiWVopgBj0X3mTZ4bpIcBcoCvzC05Inpa3ogOQwwihRkUZt6Rz9QG 4e8M3UHrVFijiVt//knVDeIt/OnER5nA0bc3MpylLOwfVpC68X3Czd6MO/UOcWRadHEI B2OXrTRvQrdyntmpAlnqqboOiUlCUBj96SdrIYO34fd8AZDmrP/6cOXz0nrSfMqxbHG1 nBvYCG9V3YsjMeYtfmh0X1RB5o2HlEHKHMmCRSmeh+c+ArXw6IfaJnGSJn0BRNh5BQh3 GPbNo2w/WkgWcYOHNpMezMA6EGcXEBwewHQrGKyzr+0Zjcy8LJlYTa483ZhoHu7Q+IE6 o4+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@marvell.com header.s=pfpt0818 header.b=woPDsTcN; dkim=pass header.i=@marvell.onmicrosoft.com header.s=selector2-marvell-onmicrosoft-com header.b=VIsf4jGX; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=marvell.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y19si10295333pgi.587.2019.06.24.08.09.10; Mon, 24 Jun 2019 08:09:10 -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=@marvell.com header.s=pfpt0818 header.b=woPDsTcN; dkim=pass header.i=@marvell.onmicrosoft.com header.s=selector2-marvell-onmicrosoft-com header.b=VIsf4jGX; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=marvell.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730373AbfFXPJI (ORCPT + 30 others); Mon, 24 Jun 2019 11:09:08 -0400 Received: from mx0b-0016f401.pphosted.com ([67.231.156.173]:39286 "EHLO mx0b-0016f401.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727454AbfFXPJH (ORCPT ); Mon, 24 Jun 2019 11:09:07 -0400 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x5OF8CZ4025866; Mon, 24 Jun 2019 08:08:58 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=pfpt0818; bh=pIs8IdJVaFhb/v9+wntLcWsZ3Y3pUgrJps923RgfgQU=; b=woPDsTcN6ObFwzvJf/EKY0u2JN8GDdvHU+tbP76RsUYTk9VdOoR5q5rnRRCKlAq/fsBY YYRUErvAP9mRfavlP+Kx4gEPZubRla9y39/XbTiVjNhZnkzr2y1fEAFj0bZf1Q50PHTE tCFlx0rGYb+czOe/heuRM7Lkrx48zubJF6BkxpO2zOUILV5ib9R9yh4zAcgVfbK5Q2Mr L5lq7wBsLZAbdcR3tgqcQ9RSRcBWVBPOEVhuOtK9Jn1+iRh6QIzoLD38gCppPsImRyOb CtMRmHUWPybUPqNVnlYI94FmnhSjKZCpxEsAJmgy3H6vJh/FnTtO19ahXvmWGy6MLquZ ZQ== Received: from sc-exch01.marvell.com ([199.233.58.181]) by mx0b-0016f401.pphosted.com with ESMTP id 2t9kujf7qx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Mon, 24 Jun 2019 08:08:58 -0700 Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Mon, 24 Jun 2019 08:08:56 -0700 Received: from NAM03-BY2-obe.outbound.protection.outlook.com (104.47.42.52) by SC-EXCH03.marvell.com (10.93.176.83) with Microsoft SMTP Server (TLS) id 15.0.1367.3 via Frontend Transport; Mon, 24 Jun 2019 08:08:56 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.onmicrosoft.com; s=selector2-marvell-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pIs8IdJVaFhb/v9+wntLcWsZ3Y3pUgrJps923RgfgQU=; b=VIsf4jGXt8OXzzyVvIco5NHrVpU/HaNIqIZuWqegbLdZhhw4Q7cCsHcIBjkORuhgjj4JCOUnq6g4Dn4lrexduJGDLf3o4B9OArw61epaZWLXaXgTCGavidwF8bS9oO2kO8rYpIdqd+VUWwoNcCOGcrIA9EFDP08Ym1uEjhpYTzw= Received: from MN2PR18MB3408.namprd18.prod.outlook.com (10.255.238.217) by MN2PR18MB2589.namprd18.prod.outlook.com (20.179.82.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2008.16; Mon, 24 Jun 2019 15:08:55 +0000 Received: from MN2PR18MB3408.namprd18.prod.outlook.com ([fe80::d3:794c:1b94:cf3]) by MN2PR18MB3408.namprd18.prod.outlook.com ([fe80::d3:794c:1b94:cf3%4]) with mapi id 15.20.2008.014; Mon, 24 Jun 2019 15:08:55 +0000 From: Robert Richter To: Borislav Petkov , James Morse , "Mauro Carvalho Chehab" CC: "linux-edac@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Robert Richter Subject: [PATCH v2 01/24] EDAC, mc: Fix grain_bits calculation Thread-Topic: [PATCH v2 01/24] EDAC, mc: Fix grain_bits calculation Thread-Index: AQHVKp69wZOPr3Ki20aR3to5WmH54Q== Date: Mon, 24 Jun 2019 15:08:55 +0000 Message-ID: <20190624150758.6695-2-rrichter@marvell.com> References: <20190624150758.6695-1-rrichter@marvell.com> In-Reply-To: <20190624150758.6695-1-rrichter@marvell.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: HE1P190CA0035.EURP190.PROD.OUTLOOK.COM (2603:10a6:7:52::24) To MN2PR18MB3408.namprd18.prod.outlook.com (2603:10b6:208:16c::25) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.20.1 x-originating-ip: [92.254.182.202] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 38f39192-31f6-4dbb-9b1b-08d6f8b5df77 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:MN2PR18MB2589; x-ms-traffictypediagnostic: MN2PR18MB2589: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:5797; x-forefront-prvs: 007814487B x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(39860400002)(346002)(376002)(366004)(136003)(189003)(199004)(2906002)(2616005)(486006)(476003)(52116002)(256004)(5660300002)(66446008)(73956011)(66946007)(1076003)(14454004)(6116002)(86362001)(3846002)(99286004)(6486002)(68736007)(81166006)(81156014)(6436002)(4326008)(305945005)(50226002)(53936002)(7736002)(8676002)(8936002)(478600001)(64756008)(66556008)(66476007)(6512007)(107886003)(71190400001)(71200400001)(36756003)(26005)(102836004)(386003)(186003)(11346002)(76176011)(6506007)(110136005)(316002)(54906003)(446003)(25786009)(66066001); DIR:OUT; SFP:1101; SCL:1; SRVR:MN2PR18MB2589; H:MN2PR18MB3408.namprd18.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: marvell.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: tW3YM7F+FiRKwKjYcKvsD9X3KboF+u1aLwnJPRb96hrRPK6KtisRajTzUSMK5N0ug62mcxuJOBPx0RM0i6C85FoG7OgMALrzqbzu9N6IJADIx3dUp3Gf5Twteboz4TAy5kQmWIAQBWx2QfdZIyXwHmzDHBeR+0TYAGuYlkFyAGqwMPtdx4P2imCku5HIeo62dMcOGdsSYEsLSEvCDdF0vHVPU/z5xReRA293XEZvzWFAjThfmKnRy+ErEyvx5ErPv/qsoWUqSWCe1I9NtDEB5RYijdeZ+aO0WKtCrrOA0E9hoeB2u4yQZREpnAHO1GgODLqjLse39Wu27nPn5QjyfSFfTJKioI9ylLcb+WT+JHnPsHFMJ+plsXl/iQTh4tGZVqnSR78RvhKNQ/fgbNLKMc3pu804xKWWM4HQkAMNd8w= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: 38f39192-31f6-4dbb-9b1b-08d6f8b5df77 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Jun 2019 15:08:55.3183 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 70e1fb47-1155-421d-87fc-2e58f638b6e0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: rrichter@marvell.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR18MB2589 X-OriginatorOrg: marvell.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2019-06-24_10:, , signatures=0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Replacing 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(8 - 1) grain_bits = 3 grain = 1 << 3 = 8 Note: We need to check if the hardware reports a reasonable grain != 0 and fallback with a warn_once and 1 byte granularity otherwise. Signed-off-by: Robert Richter --- drivers/edac/edac_mc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) -- 2.20.1 diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c index 64922c8fa7e3..45cac74ab833 100644 --- a/drivers/edac/edac_mc.c +++ b/drivers/edac/edac_mc.c @@ -1235,9 +1235,15 @@ 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; + /* + * We expect the hw to report a reasonable grain, fallback to + * 1 byte granularity otherwise. + */ + 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,