From nobody Sun Feb 8 16:35:57 2026 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2071.outbound.protection.outlook.com [40.107.237.71]) (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 4A03E7FBB9; Tue, 19 Mar 2024 11:33:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.71 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710848022; cv=fail; b=qzA/A6K1Fo6X5rktEF7h3YG2AIfLVO8mt/Xmjf55i663NichsdNxCJ/Ba1QZZq6aeaFsqWbYR2p/B03VThR9fDzQkdsrXir9lPR2hkO1EWA651Xcd9bdRFNfjzuWGXFQiC4DwStZIZr92OMhk8ey2votiLKV1rdHVt4ahTKab44= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710848022; c=relaxed/simple; bh=KONc5UKShc4NqllYcxFGx6fEWh70f+iZ5fBkkyFMKXg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=vEyJH8CzVl0tfEGVlpM0YlIWB6JRGAg5n8ms2s/aJBOnl7NYZig234MPphcf5DjoCEa0ljncqW8JEbPqjJYvu6g7rfRjDEzP87pYHyoqEMrDgpdLpmUG42FvSkIcRvRVmqrNASHzZOq2Imt1eeMLYCNUCHP1w2K+PYD3M7vgZIM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Soe78rsx; arc=fail smtp.client-ip=40.107.237.71 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Soe78rsx" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ar53jN1Vhx5mlJey0PS++2xgq/rcXN9Y3TxfnGW/z5MgdFOQh17YBvC7ADMUPTK2ZW8VrmqtzkShULBXXzoG8bMS6SjWlBahGC9K2tZ9UrNejSggx73NFnjqPuPED8Ld8IsKdWvQShS7JiYEPKD1olkEx7LIgjcOMd1kR/dNoRgPsFzqldw7NXWFUci89YZfwczhzpECzuyuTkyvP7VJ1b+GFvE2Ph52cGr++aGIKkfikEjzLX9ssmc4DUJBD3oKmIDwbKRmewKVwOQUZp88QD9kBj9kUOFljGocFCMPo0coLOmWGdsY2TRAb0cZ7m58BxdFvjwc0HBsbsoHPmjhNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=QrThdxDYx+HelMReifKH/2yl+3W9qSQwuZ/6QxmbMqA=; b=PdP6MIWr8wKmi/0nS77YRqZp+nXKoza6vYn0OwHV6dug3UUViQ5OVGFVNzbGnfWnqtM8prILvyl+dvoG3Dez3n1KBJB44EA4d0Rt/ljQw5/lE5CRh9AmNjUglmY9znHuVKgqbm5k2mcqyN/QHHuNsKjF5EfKlAOA0Xs21HTphnifbcUlV33AEvMGaABOxGskLIM1gnEJBFnbensV9LusSEaioJ6srkFFwlOwnmcaywO+nGXoat5w8ElDIyCEohymkcrqZk29rIfrXnlnVLgS64B991UXrMwQJeIVzIBB7UvAOtfLr6FMjC5wR8YiSo30GF7pO/IMv5TOR257PUlJ/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=alien8.de smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=QrThdxDYx+HelMReifKH/2yl+3W9qSQwuZ/6QxmbMqA=; b=Soe78rsxKSNONz0luaqqLJAkfwvHlDmZAeMQ2qHKvfRUr9c7DsLL3kfQQOHT+HIVYZtK4aCSfJtiuWC+23At+E/b9EZzmqM4F4we3DHOjFUITLNNKJTJ5hjOB6226aQdxU+3MMz0e2J9YPM+VYJDfvVHX0BTc2TMNC5pm6ZnsIw= Received: from MW3PR05CA0016.namprd05.prod.outlook.com (2603:10b6:303:2b::21) by IA1PR12MB6284.namprd12.prod.outlook.com (2603:10b6:208:3e4::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.26; Tue, 19 Mar 2024 11:33:34 +0000 Received: from CO1PEPF000066E6.namprd05.prod.outlook.com (2603:10b6:303:2b::4) by MW3PR05CA0016.outlook.office365.com (2603:10b6:303:2b::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.12 via Frontend Transport; Tue, 19 Mar 2024 11:33:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000066E6.mail.protection.outlook.com (10.167.249.4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Tue, 19 Mar 2024 11:33:33 +0000 Received: from quartz-7b1chost.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 19 Mar 2024 06:33:32 -0500 From: Yazen Ghannam To: , , CC: , , , , , Yazen Ghannam Subject: [PATCH 1/2] RAS/AMD/FMPM: Avoid NULL ptr deref in get_saved_records() Date: Tue, 19 Mar 2024 06:33:21 -0500 Message-ID: <20240319113322.280096-2-yazen.ghannam@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240319113322.280096-1-yazen.ghannam@amd.com> References: <20240319113322.280096-1-yazen.ghannam@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000066E6:EE_|IA1PR12MB6284:EE_ X-MS-Office365-Filtering-Correlation-Id: fae5604a-1b9a-49da-b1fd-08dc4808692b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iLcX8DxUlgK3EgITdF9l56//QFyH/+KmLAQHgMyxVYyU5orusU2vj9grJ+Mc3R90ZH7z4YGAMq3L4Go4jm8uZAhG6ax+L7IoGPyDvbp5wB2oR01EKJX+oAv1YOG9JzuqSq1yVhqt1gSnR0hbkiz2HYA2u0z0DfvdVejPeaBKZAFnPMxS2EhZzdGx7dtnSEqILMF6bHsYtbhW2tbFTi60IIsdbyCQSg6vABMEzGo0edHOaCmo7IWUCrEt/1D+8yiWO8xjejEkVSSu16f3qo3HcnTy4R3uxNCHe5vL4yt7QB/YiBLv0Du5MPWbtzobcDp5o0oExfusPjjr62hhBmsotPKQGWH2ywQCjYDkYk40dQZIQEy3dW0dzrcgvR5SXlVJsJmYIV8HyYNWdPKvWJ9HT5iQBzWbataK3my6+AWvNny1KF4RrJeS0harqPzOMNbXsIovcyMNwMkyZXtIm5FMx5WJCyYHOjuKz+OwEutY89eIoDwlESxpeRMUDkFbvfsbDKwep00OMYzedazOUQ5212u8B+T+ohbl/t/06JGfZBvrLg3KasVUCbeR4qXakpWFC7B+BNcPwB7IQ1UStmXHRVlswY9QDOWyiT7bHxhzE6VlD8hv51LA3cY+e/GeX+t3oqt9gttzdcutlCJUn1cksT2KKycAKfDZITe6wuHVreqkO9QFR4EHpeYlRA9p9XTyWZQ6t1I1JuDvbpqB/KyRIXddIxWIbM4PHs7y4tFgXZ3OjDdWgp/bgVXTfecDZ7JZ X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(1800799015)(36860700004)(376005)(82310400014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Mar 2024 11:33:33.8208 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fae5604a-1b9a-49da-b1fd-08dc4808692b X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000066E6.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6284 Content-Type: text/plain; charset="utf-8" An old, invalid record should be cleared and skipped. Currently, the record is cleared in ERST, but it is not skipped. This leads to a NULL pointer dereference when attempting to copy the old record to the new record. Continue the loop after clearing an old, invalid record to skip it. Fixes: 6f15e617cc99 ("RAS: Introduce a FRU memory poison manager") Signed-off-by: Yazen Ghannam Tested-by: Muralidhara M K --- drivers/ras/amd/fmpm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/ras/amd/fmpm.c b/drivers/ras/amd/fmpm.c index 2f4ac9591c8f..9d25195b4538 100644 --- a/drivers/ras/amd/fmpm.c +++ b/drivers/ras/amd/fmpm.c @@ -676,8 +676,10 @@ static int get_saved_records(void) } =20 new =3D get_valid_record(old); - if (!new) + if (!new) { erst_clear(record_id); + continue; + } =20 /* Restore the record */ memcpy(new, old, len); --=20 2.34.1 From nobody Sun Feb 8 16:35:57 2026 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2049.outbound.protection.outlook.com [40.107.95.49]) (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 6C1837F7DF; Tue, 19 Mar 2024 11:33:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.49 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710848020; cv=fail; b=MQKPNGKtXDB9N9uar/IZKrvMu0LP/OtJaq6+98TQnlt7gztv2oxVAHXynWjXN0jlAS+kmXuKSjllwqAAben+tNUAzSBqWge0LqjC0dttBHV4xZGeG95hVZkmO2D7FFAvjNCo66vNHg8kUeMiHdIaSq+rv/M9NZAIhYZYlYCJ/Wk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710848020; c=relaxed/simple; bh=DeHO9SdCsbnavh0nfXCvqsLRFNY5Ay0bocBPYkIMBF4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=N3DQzw/Vq+5zagwAaIA3+gp+qS6Fv6yL/oofJ/0BkIeCB4iYLqitj4OvrxpO5LC+TuVY9Jbfmst0rQ9ombbCg40bLoYbGMJZb2zk2L4DN4qpbFk+W5NTYQ4K23zOUmQN8iHuWUdY9bvpUmKf+RzCfL3ttA8Ut1GvT9E72FkfOL8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=W6+nC5U+; arc=fail smtp.client-ip=40.107.95.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="W6+nC5U+" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lkAhnjk+ENjFdsc3TlhTBfjattda0Uw5cve1xm5X0Fm4OoYKLFTPr/nWiTxYiPJ30+CGYGXRhv/k5oc/lSZ2Dxeqa0DXYkKomdQaFQVpW3P+InmOBBDNdFL3DhSppROyi4UxMFzuCuLw/BN8x1DpnN3MgatcqY18CIgRdOnGGoBP8CUWpyAWDHkzvBrUZiuLHP24xzJq3AMzstYAeklseufOKCxvZrChxV1lPjBQWb1ptlrcn8BWZ9gS9nqx/GX3g6yTFq5pmoOBcZBwdBxbwOKxvAeoFHQl9XGd513MLLUfoCZpEvnVpY3zMyGsS1aEP7ceHJo9ET3W+l3GLl7RUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=XTF/HzIgr0bisGILVrbHQOh0UlydRgUyeafyM+P0L+4=; b=f7uAt6yEpE0PtpkTiJ9i45XKfaiI4V8VeBGYZhhg+I3aQklnnMxo/dzTxwy924dnzAigOl5vU86l9gpihg484mTM5P9y4yK5t2MWSq7MMc7wcJM1LfqpRXQUeUr6pvmYlnBfCwD22wlEK4yvB3NwqXiDW3XTLN16GXxQBziMFVvOXrg3/60gcBXGcX6ZU6HkkwFNj6IvdAEqbSTQqCXsn7wzg8wlD/ScJyLX93h4rjaUSkab06GOxa63WLyWaHyGj/bJF+7XKNzibIJb3mW7/TKBrmrSdVi1CgAs0wl5WXxDRR5YDB0o0Pkj3DKtmhSYQXBGC2a3Jxl+V0hU6acOKA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=alien8.de smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XTF/HzIgr0bisGILVrbHQOh0UlydRgUyeafyM+P0L+4=; b=W6+nC5U+qf06BaZnq91KKhil0Cr5nX31RLFFCTz7GvbMS2uU6zKYvS9jV0nTE2jBt1tvScx+mJ+F5sMQPz9JodtsyO1mRrfzQWz5HHIR0BbeU8ip7vPZSsTylQmTJVWhqkygv0xSWGm3tzwDYXGqdjYTtmtyCZrngcsAJXMMaic= Received: from MW4PR03CA0091.namprd03.prod.outlook.com (2603:10b6:303:b7::6) by PH7PR12MB9150.namprd12.prod.outlook.com (2603:10b6:510:2eb::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.26; Tue, 19 Mar 2024 11:33:34 +0000 Received: from CO1PEPF000066EC.namprd05.prod.outlook.com (2603:10b6:303:b7:cafe::f4) by MW4PR03CA0091.outlook.office365.com (2603:10b6:303:b7::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7386.28 via Frontend Transport; Tue, 19 Mar 2024 11:33:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1PEPF000066EC.mail.protection.outlook.com (10.167.249.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Tue, 19 Mar 2024 11:33:34 +0000 Received: from quartz-7b1chost.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Tue, 19 Mar 2024 06:33:33 -0500 From: Yazen Ghannam To: , , CC: , , , , , Yazen Ghannam Subject: [PATCH 2/2] RAS/AMD/FMPM: Safely handle saved records of various sizes Date: Tue, 19 Mar 2024 06:33:22 -0500 Message-ID: <20240319113322.280096-3-yazen.ghannam@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240319113322.280096-1-yazen.ghannam@amd.com> References: <20240319113322.280096-1-yazen.ghannam@amd.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PEPF000066EC:EE_|PH7PR12MB9150:EE_ X-MS-Office365-Filtering-Correlation-Id: 47a1490b-bb83-4217-eb82-08dc4808695c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3zXS6yooiyYKfOciHf4xq2d9CX21OtbvsZ3f0e9mcyFEba/56GFEgRY76WRDv9bbtsZy3SmYWN4sIqJKCIxGOo1V7U2KxCv9VWMtcA1DdlacLBouBeoAI/rWEXIcAaLn9Bre4TgkLFPTxPD9dR+DRxaWmau+102Yv+0nH78k1MVfrJZa0Izno7dZDLqJuGmCa5rVfxTPHUqc2fe0L97quj449u7quYjFNveq9rCcdyctGBaYqPXhE2hvO+sVZmgC5NR5JVHeE8qqLQu6t3nO/8+v3QwTudGynxQppuUAHVtpOxnXpXKluNUHnEcCYTBjYHA+P3Zci74Q2a6iZq1mJhaY8ijPLpruYaMR+ZLaXgip/524ghrtHCctvGCwRhBV6Cx1DmwQkQzkI9ZhWE7gDE9Ak8j+Cv5+fkAvJ8SUB4S66tE4zQt0xdQ1+ArveV1pDLfI1zzAY2hj6UC0NRQH+K7UXGyNC9eplLgMDREvnvgI00VlDD1KAbBxpQ7cXBqONZSUmCJX+XvwnTo0t56FQgo1P/xiCLx2B+8O420WwIbJgfFP5XQO2XtegLHCMvna1q08VJtoyvQ3ASHV7QT2NgrTtOnnsgXgsa1kHZYq1iVmv/c5lcw8bYWG73m+fsR0hkGs9kfbbQ9YgH/VkCZcTRvcixX0GTRBbu6QLRo/hZAP9mofrTt8xfW5cYx+vLdGlUss6LHtcl6MHF0zP/aqBKN4z6Dd2iff8DI4gv/JowgSmwuAWi088z4Hfp0WHDTQ X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(376005)(82310400014)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Mar 2024 11:33:34.1278 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 47a1490b-bb83-4217-eb82-08dc4808695c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1PEPF000066EC.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB9150 Content-Type: text/plain; charset="utf-8" Currently, the size of the locally cached FRU record structures is based on the module parameter "max_nr_entries". This creates issues when restoring records if a user changes the parameter. If the number of entries is reduced, then old, larger records will not be restored. The opportunity to take action on the saved data is missed. Also, new records will be created and written to storage, even as the old records remain in storage, resulting in wasted space. If the number of entries is increased, then the length of the old, smaller records will not be adjusted. This causes a checksum failure which leads to the old record being cleared from storage. Again this results in another missed opportunity for action on the saved data. Allocate the temporary record with the maximum possible size based on the current maximum number of supported entries (255). This allows the ERST read operation to succeed if max_nr_entries has been increased. Warn the user if a saved record exceeds the expected size and fail to load the module. This allows the user to adjust the module parameter without losing data or the opportunity to restore larger records. Increase the size of a saved record up to the current max_rec_len. The checksum will be recalculated, and the updated record will be written to storage. Fixes: 6f15e617cc99 ("RAS: Introduce a FRU memory poison manager") Signed-off-by: Yazen Ghannam Tested-by: Muralidhara M K --- drivers/ras/amd/fmpm.c | 55 ++++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/drivers/ras/amd/fmpm.c b/drivers/ras/amd/fmpm.c index 9d25195b4538..271dfad05d68 100644 --- a/drivers/ras/amd/fmpm.c +++ b/drivers/ras/amd/fmpm.c @@ -150,6 +150,8 @@ static unsigned int max_nr_fru; /* Total length of record including headers and list of descriptor entries= . */ static size_t max_rec_len; =20 +#define FMPM_MAX_REC_LEN (sizeof(struct fru_rec) + (sizeof(struct cper_fru= _poison_desc) * 255)) + /* Total number of SPA entries across all FRUs. */ static unsigned int spa_nr_entries; =20 @@ -475,6 +477,16 @@ static void set_rec_fields(struct fru_rec *rec) struct cper_section_descriptor *sec_desc =3D &rec->sec_desc; struct cper_record_header *hdr =3D &rec->hdr; =20 + /* + * This is a saved record created with fewer max_nr_entries. + * Update the record lengths and keep everything else as-is. + */ + if (hdr->record_length && hdr->record_length < max_rec_len) { + pr_debug("Growing record 0x%016llx from %u to %zu bytes\n", + hdr->record_id, hdr->record_length, max_rec_len); + goto update_lengths; + } + memcpy(hdr->signature, CPER_SIG_RECORD, CPER_SIG_SIZE); hdr->revision =3D CPER_RECORD_REV; hdr->signature_end =3D CPER_SIG_END; @@ -489,19 +501,21 @@ static void set_rec_fields(struct fru_rec *rec) hdr->error_severity =3D CPER_SEV_RECOVERABLE; =20 hdr->validation_bits =3D 0; - hdr->record_length =3D max_rec_len; hdr->creator_id =3D CPER_CREATOR_FMP; hdr->notification_type =3D CPER_NOTIFY_MCE; hdr->record_id =3D cper_next_record_id(); hdr->flags =3D CPER_HW_ERROR_FLAGS_PREVERR; =20 sec_desc->section_offset =3D sizeof(struct cper_record_header); - sec_desc->section_length =3D max_rec_len - sizeof(struct cper_record_head= er); sec_desc->revision =3D CPER_SEC_REV; sec_desc->validation_bits =3D 0; sec_desc->flags =3D CPER_SEC_PRIMARY; sec_desc->section_type =3D CPER_SECTION_TYPE_FMP; sec_desc->section_severity =3D CPER_SEV_RECOVERABLE; + +update_lengths: + hdr->record_length =3D max_rec_len; + sec_desc->section_length =3D max_rec_len - sizeof(struct cper_record_head= er); } =20 static int save_new_records(void) @@ -512,16 +526,18 @@ static int save_new_records(void) int ret =3D 0; =20 for_each_fru(i, rec) { - if (rec->hdr.record_length) + /* No need to update saved records that match the current record size. */ + if (rec->hdr.record_length =3D=3D max_rec_len) continue; =20 + if (!rec->hdr.record_length) + set_bit(i, new_records); + set_rec_fields(rec); =20 ret =3D update_record_on_storage(rec); if (ret) goto out_clear; - - set_bit(i, new_records); } =20 return ret; @@ -641,12 +657,7 @@ static int get_saved_records(void) int ret, pos; ssize_t len; =20 - /* - * Assume saved records match current max size. - * - * However, this may not be true depending on module parameters. - */ - old =3D kmalloc(max_rec_len, GFP_KERNEL); + old =3D kmalloc(FMPM_MAX_REC_LEN, GFP_KERNEL); if (!old) { ret =3D -ENOMEM; goto out; @@ -663,24 +674,32 @@ static int get_saved_records(void) * Make sure to clear temporary buffer between reads to avoid * leftover data from records of various sizes. */ - memset(old, 0, max_rec_len); + memset(old, 0, FMPM_MAX_REC_LEN); =20 - len =3D erst_read_record(record_id, &old->hdr, max_rec_len, + len =3D erst_read_record(record_id, &old->hdr, FMPM_MAX_REC_LEN, sizeof(struct fru_rec), &CPER_CREATOR_FMP); if (len < 0) continue; =20 - if (len > max_rec_len) { - pr_debug("Found record larger than max_rec_len\n"); - continue; - } - new =3D get_valid_record(old); if (!new) { erst_clear(record_id); continue; } =20 + if (len > max_rec_len) { + unsigned int saved_nr_entries; + + saved_nr_entries =3D len - sizeof(struct fru_rec); + saved_nr_entries /=3D sizeof(struct cper_fru_poison_desc); + + pr_warn("Saved record found with %u entries.\n", saved_nr_entries); + pr_warn("Please increase max_nr_entries to %u.\n", saved_nr_entries); + + ret =3D -EINVAL; + goto out_end; + } + /* Restore the record */ memcpy(new, old, len); } --=20 2.34.1