From patchwork Wed Oct 16 20:31:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13838897 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2089.outbound.protection.outlook.com [40.107.104.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B9712217325; Wed, 16 Oct 2024 20:31:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.104.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729110709; cv=fail; b=E+v7pksyDOtKinh4HN6DGWF7jsQVN6XZlZ0lhc9IZtJ938s65C/NxKC7K6QqtQZfzPWQwmO31SUA5Br+LgC6ky0o+TWRMDLvueziiXagZTKci5x9ldooeNjgoQ2xaaA2sNjgNuNV/ZrA9nWQyfILZr5xlp9auGWrKMLkSSSkc9I= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729110709; c=relaxed/simple; bh=kkq2oTJ4X6AP95d7t+PEWHZQVH1ktTm8zm0a5adwArE=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=Z7au/KN4WDVzgAl4qniZMGNCRRZ8JjW8o3CVEtznTCMtdXS9czfNUPha2WGze3xD72Bs44rAVNZPcoJtiu6/OEmwTSc7eoJjShKJrriILi+sg7fk8lVrxuh36M910xiwQ8QP9U+FvE6Vcup8+TMrBEhXMVYf49D27xdB5rcs4bI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=Lh9j951I; arc=fail smtp.client-ip=40.107.104.89 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="Lh9j951I" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=oPBJxX3eE+340cZ8GhbqwHR6GgLySNmyJkyuIh9jT5S7G7zXa3CmVLPzEDeWvQsCV3azrmE4Yt2uzo42pd1U85Uw4y5Df10iVDHXXeBwgql5vbomUcyOVNugVuGgjdMQG1PQwLauEAr/u6N/4cldBIMWGVIt/UW42ntL1k+fFkRrYhho1vf+V9iE+ey91djfNjArsFpoMHoY+oDxN/jYXunI/mojrdFYbqoDTGWuuv2u7Nk8h+fGP3r8/DcyHVXor5v2OLCyykfJR/AJvAXubpGJ1VpJhpenBsI412qG0RCNtqAkCMcS7rF7bdG4LX/D0Byrmo0g0FSgB1JXVpQ6/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9d8c0sNGYq4vfHYI6mkZB5AG2AIJXl/qLfLBHwapHrk=; b=MiB40jc6P/oGvueMDUPzG/mzJYxlpqCga0Q6i26ejlOSkf78REE8VZsWFmD+I4XcuXsNU2yQcAis+dVTlh4a7fscXYrm6vqqo5qCkb8QJED+ICAoK/BnMUxiGPHY0up0TzqGPPcWv4+awG17LpEGieBdv/tk9gb8zSkTlPsT93VzTF3E279HFGdxtFzcjLXEl8IY/b4PEJvr1qfSZamSUy6wS9cG/Hz3LzpcdTuSiEySJM/BtDe6WX4kkjaQsZHHQuB8UaU5rNJJqBUTgpUwdI4HcJ+F6VMI+iw18Tx4ErHXD5yBoUwbKjYEOHhRixScT+SCINo9L9jYeoS3Q+Cxdw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9d8c0sNGYq4vfHYI6mkZB5AG2AIJXl/qLfLBHwapHrk=; b=Lh9j951I+4qvPA8k6NwA8eNbnzDlhXWaRn6HNK+XWifJy0Y6XJ0e4n7dVhCTgvjXKrrXfUlAsfwAznIE0vpdUOwQKNMqATogLPP/IukOuXkB48QfdiqrAXYvwCdK3UStj8Up/VzUVNlmlwSCwwaGde0ryIHe0XGFVxF0o1rIXRWR3kT+l460bCXUftE3dhnAK2nBypQIItjrgGIBwTLIckFk65PvfPk7JAgUVvRzY+KvBIrgkBnZY0rIFxIIzVtlFUDSRBBrxolrSjyt4VrpRg2jtuiZc2usG5u+2SltNFsJIJEf0SRRf6syiIKjF80cv1zp/9tzHJbML83taYOBbw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by DUZPR04MB9845.eurprd04.prod.outlook.com (2603:10a6:10:4d8::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18; Wed, 16 Oct 2024 20:31:45 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%4]) with mapi id 15.20.8069.016; Wed, 16 Oct 2024 20:31:45 +0000 From: Frank Li Date: Wed, 16 Oct 2024 16:31:11 -0400 Subject: [PATCH v3 3/6] EDAC/fsl_ddr: Fix bad bit shift operations Message-Id: <20241016-imx95_edac-v3-3-86ae6fc2756a@nxp.com> References: <20241016-imx95_edac-v3-0-86ae6fc2756a@nxp.com> In-Reply-To: <20241016-imx95_edac-v3-0-86ae6fc2756a@nxp.com> To: York Sun , Borislav Petkov , Tony Luck , James Morse , Mauro Carvalho Chehab , Robert Richter , Krzysztof Kozlowski , Rob Herring , Conor Dooley , Krzysztof Kozlowski , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam Cc: linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org, Borislav Petkov , devicetree@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Frank Li , Priyanka Singh , Sherry Sun , Li Yang X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1729110683; l=1889; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=ZoeCNuBkYPhKpS/FeSuF2iwPzcC8UiQC1YFwpngjXhw=; b=D/ksnGAhxZQg7Qb7/AI21/XsrLMkiVMpm8GXiNGcFFbOwL6pE/1hRfED2f6Bk1ehUfuQTPzIz OWQHHVTB3AMCvG146S1knpt5XN0LpICKwrKUbOGPeuAQu35rzRyc3dz X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR07CA0042.namprd07.prod.outlook.com (2603:10b6:a03:60::19) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-edac@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|DUZPR04MB9845:EE_ X-MS-Office365-Filtering-Correlation-Id: 0c23579a-3d80-4d0b-b343-08dcee218d35 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|52116014|7416014|366016|1800799024|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?rN4lP10Mmmcp7lQipXoY5zZ9FI+IKzR?= =?utf-8?q?wfyaPR3kD62Y4Y/NIRYtX0PggWt5jQVKVcoWu/sP1wAtivdomkdhvd5FZnK1JhksG?= =?utf-8?q?WzWBp3zd0f1zLDRCYJ7esKLb9w77jUdoBhHrpEbNRVeqsTNMGL6Cm9gcwEXfIzWIe?= =?utf-8?q?tg/1irr4sVqljU72UWn0x8wCarMnNTTjXpNs++9cH9dfejgNkFQ1+zV2fPNhKhNEN?= =?utf-8?q?97YTyrXdyNH4iITOIZk4JcfkuutybyzsIkQT971CHY7oG27QcrrRYs8HByp/OVFk1?= =?utf-8?q?veKEBGcyQQ5P7c8Tiv4avHzoYU4BoiIVKrRtPAFAsgzoS0U6lGokQKnZw0D0KSPD3?= =?utf-8?q?L3V7V7JQxsBtgw6rpHz9CkfX2BrhXrqCuY4QtWAQfQsa5sr6irckfRXwx+QFqoTUR?= =?utf-8?q?VS/RcTEahOAsnzG0lc3bG7F9xwzWvsFh9x893NvXOEy8D75cIOqyETtBLeZhPc20t?= =?utf-8?q?nkp2AeiL9zwaFEm5tc1c1sPFRfIPB1BajA8l73FDpOwC//9TyabRVHhM8+3MXPPQK?= =?utf-8?q?QMK6OGmYi3+ufb1fZaxhRRmTxjHBoIXUptSwoeitIYezgGEYslLs3TF+7wVoScIao?= =?utf-8?q?MH4wE36uQoOnLmrRZAuZOwNDE8Gmj5SCrhvbhgMlyxMqQpDGRUZA3FsA5sWQSyfk3?= =?utf-8?q?FCL+wwT+qej8HB3Dmgi+aPa7xW51124r1s+f8EUCL+XLADxaoCt/G5sFLtueuM7sf?= =?utf-8?q?/E53cRZ/i88BqqCZ5bH0m5DAvMI9qgK+NxyGvGLWCFJNl3l8zPMOyo+jqUNiORc2v?= =?utf-8?q?LWyqQxL1dLgsD7C9RkGRKdnRda+n2DO8IP+tLyl1oNjfa3GRJgengrhGauoFgz6eL?= =?utf-8?q?rckU2ruR3liJyjSk4aoiZaUdfqYPI1OnYUBYZzCO2MjtGApgICeHI83NV/Rkl/Btw?= =?utf-8?q?17nyrSefR9+C73eDgiV1dFyXdZt0QncL8xgQFY7iutHtBYyS0BifutYTQyZDkl2K8?= =?utf-8?q?5s3sVq65k5h+VZKx+MMUV3mmlzObrmuuWQAhq/lg56xr1DIOtNuPu0yZ6tSCRnGFm?= =?utf-8?q?UktlbC8WZHp6vFzBuYoGIyt11HsG24A2/xZZl992Vjuqv/YLbPY7OPeCNx1u7EcEy?= =?utf-8?q?Cm0cmfaj+2yRYORn9F1T0w84eZ086B5nvleXOw9bzwL+FkboAlo6Fiod4V7XN2+7v?= =?utf-8?q?/jw7L/mANU8ZpmDU5RJ5kyLLc3t0p0EoMbVFqpN83iPk5OE7biJ885mck7a1r/TCn?= =?utf-8?q?VGeYSak4Ed4hiNYOtCEX+4E/laW5FaL4NKacaU7oshLGbbWnnegU/56e3U5fiSyJc?= =?utf-8?q?Ob4coou9z/FZpyH3/qEvgZ9ttawvXQ67/2C/wVmn3kZ6iqKyIpAXwe3np8B//NfFr?= =?utf-8?q?rdW7b/Gu1dxv?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(52116014)(7416014)(366016)(1800799024)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?oLWpBURrRgbu8uJz6XNwyQr6AXar?= =?utf-8?q?4BHYBbjkjRMBy5SO3h9tZ1dMo+rsuauGIANOfQm9IRUXuHnEMrDqEvu1EQ95kbHH8?= =?utf-8?q?JvT9hkwfOgTGAMb4CpxcU9tEE6pXJWqoUoxktbQiZWcPL0tO/YzhIAT6XTukGL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+d3UNNIzEz?= =?utf-8?q?o2LqLSl711OBpcebeGxS9e8AXMqMcjMSNNN3uGhSGc7v9y5WFQ+dFN3LNDRTQYBns?= =?utf-8?q?MnJND0u4WJ9Bzmawe81ml5NwlHSFWEpxBQ80EI9viHWt8ePZUQTAvI9m0PSA/wtKm?= =?utf-8?q?E+hsw11zwYWyjcrQHalRhuFcH06tHHJGJrOwgNSEqpIW0yRQ4CIezrJVwjN2d6RgH?= =?utf-8?q?meh/cjQncx4RRz9GjEdVsrj2TgTFPqRT4gKKRqzCSoiR3hFAVvg1ZhXGEQ5dGFD9w?= =?utf-8?q?GzU8P8KBGdw+8OIupVNVVE3cMo0o//caCETc3lG3WplWPprMkahiu1eo3ycxOh3Nd?= =?utf-8?q?eM1iZDBrS7xicMgtr/GJIegXjbBcdOYi+YtNA1WM634+oWHFgNXlm1IGGEopC3XFr?= =?utf-8?q?ZgZaUHo9YrFkilbJAXXoZMzqH648RQJZwH5aGw5PWawMSwhsuoFXmx6nMUkflZgBV?= =?utf-8?q?WfiXDurhusMWxW8agDklSuiIt3JzcX8kvqabHtrqtpTtel/+54th1w9dCgiqaSrb6?= =?utf-8?q?sIaje2K0+UyT?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c23579a-3d80-4d0b-b343-08dcee218d35 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2024 20:31:45.1031 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vO39xYqeBQbkF95ABuU5xHt2IMORg+s+q6Uz+pN6/OR4CyZtgJYQYV8M61LOtODJEGcJ1y4BbCUdXO8ItPPvAw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB9845 From: Priyanka Singh Fix undefined behavior caused by left-shifting a negative value in the expression: cap_high ^ (1 << (bad_data_bit - 32)) The variable 'bad_data_bit' ranges from 0 to 63. When 'bad_data_bit' is less than 32, 'bad_data_bit - 32' becomes negative, and left-shifting by a negative value in C is undefined behavior. Fix this by combining 'cap_high' and 'cap_low' into a 64-bit variable. Fixes: ea2eb9a8b620 ("EDAC, fsl-ddr: Separate FSL DDR driver from MPC85xx") Signed-off-by: Priyanka Singh Reviewed-by: Sherry Sun Signed-off-by: Li Yang Signed-off-by: Frank Li --- drivers/edac/fsl_ddr_edac.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/drivers/edac/fsl_ddr_edac.c b/drivers/edac/fsl_ddr_edac.c index 7a9fb1202f1a0..846a4ba25342a 100644 --- a/drivers/edac/fsl_ddr_edac.c +++ b/drivers/edac/fsl_ddr_edac.c @@ -328,6 +328,9 @@ static void fsl_mc_check(struct mem_ctl_info *mci) * TODO: Add support for 32-bit wide buses */ if ((err_detect & DDR_EDE_SBE) && (bus_width == 64)) { + u64 cap = (u64)cap_high << 32 | (u64)cap_low; + u32 s = syndrome; + sbe_ecc_decode(cap_high, cap_low, syndrome, &bad_data_bit, &bad_ecc_bit); @@ -338,11 +341,15 @@ static void fsl_mc_check(struct mem_ctl_info *mci) fsl_mc_printk(mci, KERN_ERR, "Faulty ECC bit: %d\n", bad_ecc_bit); + if (bad_data_bit >= 0) + cap ^= 1ULL << bad_data_bit; + + if (bad_ecc_bit >= 0) + s ^= 1 << bad_ecc_bit; + fsl_mc_printk(mci, KERN_ERR, "Expected Data / ECC:\t%#8.8x_%08x / %#2.2x\n", - cap_high ^ (1 << (bad_data_bit - 32)), - cap_low ^ (1 << bad_data_bit), - syndrome ^ (1 << bad_ecc_bit)); + upper_32_bits(cap), lower_32_bits(cap), s); } fsl_mc_printk(mci, KERN_ERR,