From patchwork Thu Jan 13 10:06:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eliav Farber X-Patchwork-Id: 12712531 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3595EC433EF for ; Thu, 13 Jan 2022 10:06:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229539AbiAMKGg (ORCPT ); Thu, 13 Jan 2022 05:06:36 -0500 Received: from smtp-fw-6001.amazon.com ([52.95.48.154]:25523 "EHLO smtp-fw-6001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229483AbiAMKGe (ORCPT ); Thu, 13 Jan 2022 05:06:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1642068394; x=1673604394; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OEe8UJVrva6O5WnViJeZduwrLI034dWRHuRnXhh70zI=; b=VLXN78iYjS6+di/rVojm/NsegUF+/Z+XChSH2hEa0uKTAfNKfwx/rSYd R+jPyt74FQiWo7ihvYI97eXioVizUYkop8UV61mHvxpqj8ZwHGTmwtuAl mzHxd39qmf55s3UyHec3z44zFbzcIuNE28N0SORAVzIoDwA4Omwjao3T8 c=; X-IronPort-AV: E=Sophos;i="5.88,284,1635206400"; d="scan'208";a="170130791" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-pdx-2a-2dbf0206.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-6001.iad6.amazon.com with ESMTP; 13 Jan 2022 10:06:25 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-pdx-2a-2dbf0206.us-west-2.amazon.com (Postfix) with ESMTPS id 5ED61A253F; Thu, 13 Jan 2022 10:06:25 +0000 (UTC) Received: from EX13D13UWB003.ant.amazon.com (10.43.161.233) by EX13MTAUWB001.ant.amazon.com (10.43.161.207) with Microsoft SMTP Server (TLS) id 15.0.1497.28; Thu, 13 Jan 2022 10:06:23 +0000 Received: from EX13MTAUEA001.ant.amazon.com (10.43.61.82) by EX13D13UWB003.ant.amazon.com (10.43.161.233) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Thu, 13 Jan 2022 10:06:23 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.61.243) with Microsoft SMTP Server id 15.0.1497.28 via Frontend Transport; Thu, 13 Jan 2022 10:06:22 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 912FA2D7B; Thu, 13 Jan 2022 10:06:22 +0000 (UTC) From: Eliav Farber To: CC: , , , , , , , , Subject: [PATCH 1/4] EDAC: Fix calculation of returned address and next offset in edac_align_ptr() Date: Thu, 13 Jan 2022 10:06:19 +0000 Message-ID: <20220113100622.12783-2-farbere@amazon.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220113100622.12783-1-farbere@amazon.com> References: <20220113100622.12783-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org Do alignment logic properly and use 'ptr' for calculating the remainder of the alignment. This became an issue because 'struct edac_mc_layer' has a size that is not zero modulo eight, and the next offset that was prepared for the private-data was unaligned, causing an alignment exception. Signed-off-by: Eliav Farber --- drivers/edac/edac_mc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c index fd440b35d76e..61d72bd96754 100644 --- a/drivers/edac/edac_mc.c +++ b/drivers/edac/edac_mc.c @@ -265,7 +265,7 @@ void *edac_align_ptr(void **p, unsigned size, int n_elems) else return (char *)ptr; - r = (unsigned long)p % align; + r = (unsigned long)ptr % align; if (r == 0) return (char *)ptr; From patchwork Thu Jan 13 10:06:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eliav Farber X-Patchwork-Id: 12712532 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 916FEC433F5 for ; Thu, 13 Jan 2022 10:06:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229554AbiAMKGi (ORCPT ); Thu, 13 Jan 2022 05:06:38 -0500 Received: from smtp-fw-6001.amazon.com ([52.95.48.154]:25523 "EHLO smtp-fw-6001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229597AbiAMKGg (ORCPT ); Thu, 13 Jan 2022 05:06:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1642068396; x=1673604396; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9iBuEMkjnN/BTukgwf9Qul/VAIKXqO12+ruyZw7dlfQ=; b=QqCrnLCl/HzryU9zdi+lMTp+NrmNEXlfuqE/K91xU4WfDyRVADgUtFV3 H3wgw93MTBibXWmRFtHtSQiTWtMUkjrnEHsClMMWQhUVFOZ4siU8Q4hiC JhUPji4sEPn9Gx8GH9swFB+prGmpdPFyiZZ8RFE5EyOAKjv7wyNNo/lF/ E=; X-IronPort-AV: E=Sophos;i="5.88,284,1635206400"; d="scan'208";a="170130780" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-pdx-2b-0085f2c8.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-6001.iad6.amazon.com with ESMTP; 13 Jan 2022 10:06:24 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-pdx-2b-0085f2c8.us-west-2.amazon.com (Postfix) with ESMTPS id D2AD441532; Thu, 13 Jan 2022 10:06:23 +0000 (UTC) Received: from EX13D13UWB002.ant.amazon.com (10.43.161.21) by EX13MTAUWB001.ant.amazon.com (10.43.161.207) with Microsoft SMTP Server (TLS) id 15.0.1497.28; Thu, 13 Jan 2022 10:06:23 +0000 Received: from EX13MTAUWC001.ant.amazon.com (10.43.162.135) by EX13D13UWB002.ant.amazon.com (10.43.161.21) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Thu, 13 Jan 2022 10:06:23 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.162.232) with Microsoft SMTP Server id 15.0.1497.28 via Frontend Transport; Thu, 13 Jan 2022 10:06:23 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 9419E2D9C; Thu, 13 Jan 2022 10:06:22 +0000 (UTC) From: Eliav Farber To: CC: , , , , , , , , Subject: [PATCH 2/4] EDAC: Remove unnecessary cast to char* in edac_align_ptr() function Date: Thu, 13 Jan 2022 10:06:20 +0000 Message-ID: <20220113100622.12783-3-farbere@amazon.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220113100622.12783-1-farbere@amazon.com> References: <20220113100622.12783-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org Amend commit 7391c6dcab30 ("drivers/edac: mod edac_align_ptr function") and change all return path to use void* instead of char* according to the new signature. Signed-off-by: Eliav Farber --- drivers/edac/edac_mc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c index 61d72bd96754..8b9b86a7720a 100644 --- a/drivers/edac/edac_mc.c +++ b/drivers/edac/edac_mc.c @@ -263,12 +263,12 @@ void *edac_align_ptr(void **p, unsigned size, int n_elems) else if (size > sizeof(char)) align = sizeof(short); else - return (char *)ptr; + return ptr; r = (unsigned long)ptr % align; if (r == 0) - return (char *)ptr; + return ptr; *p += align - r; From patchwork Thu Jan 13 10:06:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eliav Farber X-Patchwork-Id: 12712535 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4697C4332F for ; Thu, 13 Jan 2022 10:06:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229969AbiAMKGm (ORCPT ); Thu, 13 Jan 2022 05:06:42 -0500 Received: from smtp-fw-9103.amazon.com ([207.171.188.200]:43763 "EHLO smtp-fw-9103.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229875AbiAMKGl (ORCPT ); Thu, 13 Jan 2022 05:06:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1642068400; x=1673604400; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yTT6Ven38nkWxOvaFHPHO4EqO2d8TTTnnFgagM+oe/w=; b=pIpjRNcjy10u2RHLjQWOZ0lQgqJTLFbR2LymhJPEgJunlOmfLOB1+2ZO 2a1wSflmX+jThMjCNdv7c/CrAQaoCxUr/wenMB9W08up/zjP8wTxV3NTg 8lNFNS0T/68bx5RCo8TnTxy5fWRqYxwyJRoFj8+t24qlxI9iWXg+bxW2k Y=; X-IronPort-AV: E=Sophos;i="5.88,284,1635206400"; d="scan'208";a="984504477" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-pdx-2a-2dbf0206.us-west-2.amazon.com) ([10.25.36.210]) by smtp-border-fw-9103.sea19.amazon.com with ESMTP; 13 Jan 2022 10:06:24 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-pdx-2a-2dbf0206.us-west-2.amazon.com (Postfix) with ESMTPS id 79B48A2540; Thu, 13 Jan 2022 10:06:25 +0000 (UTC) Received: from EX13D13UWB004.ant.amazon.com (10.43.161.218) by EX13MTAUWB001.ant.amazon.com (10.43.161.249) with Microsoft SMTP Server (TLS) id 15.0.1497.28; Thu, 13 Jan 2022 10:06:23 +0000 Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX13D13UWB004.ant.amazon.com (10.43.161.218) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Thu, 13 Jan 2022 10:06:23 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1497.26 via Frontend Transport; Thu, 13 Jan 2022 10:06:22 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 971002E6D; Thu, 13 Jan 2022 10:06:22 +0000 (UTC) From: Eliav Farber To: CC: , , , , , , , , Subject: [PATCH 3/4] EDAC: Refactor edac_align_ptr() to use u8/u16/u32/u64 data types Date: Thu, 13 Jan 2022 10:06:21 +0000 Message-ID: <20220113100622.12783-4-farbere@amazon.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220113100622.12783-1-farbere@amazon.com> References: <20220113100622.12783-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org Prefer well defined size variables, that are same in size across all systems. Signed-off-by: Eliav Farber --- drivers/edac/edac_mc.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c index 8b9b86a7720a..3367bf997b73 100644 --- a/drivers/edac/edac_mc.c +++ b/drivers/edac/edac_mc.c @@ -250,18 +250,13 @@ void *edac_align_ptr(void **p, unsigned size, int n_elems) * 'size'. Adjust 'p' so that its alignment is at least as * stringent as what the compiler would provide for X and return * the aligned result. - * Here we assume that the alignment of a "long long" is the most - * stringent alignment that the compiler will ever provide by default. - * As far as I know, this is a reasonable assumption. */ - if (size > sizeof(long)) - align = sizeof(long long); - else if (size > sizeof(int)) - align = sizeof(long); - else if (size > sizeof(short)) - align = sizeof(int); - else if (size > sizeof(char)) - align = sizeof(short); + if (size > sizeof(u32)) + align = sizeof(u64); + else if (size > sizeof(u16)) + align = sizeof(u32); + else if (size > sizeof(u8)) + align = sizeof(u16); else return ptr; From patchwork Thu Jan 13 10:06:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eliav Farber X-Patchwork-Id: 12712534 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7638BC433F5 for ; Thu, 13 Jan 2022 10:06:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229947AbiAMKGl (ORCPT ); Thu, 13 Jan 2022 05:06:41 -0500 Received: from smtp-fw-80007.amazon.com ([99.78.197.218]:42547 "EHLO smtp-fw-80007.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229762AbiAMKGk (ORCPT ); Thu, 13 Jan 2022 05:06:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1642068401; x=1673604401; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Iz+I4bzIGgmHfCHsYZ6rNTtN23uutTDTQTkg7YnpZtM=; b=ZOckOUPVGTvVgg5b4+U24LL0NctugflI7wY7QwH4ObW0dP0QxKKeaBlB OU+nldW/udtFTcTknq15kezP6FfwoeMGREw49ClJ/UqbR4n9eMq9IJunF rxsGxRxbsOlLWYZwbwuK/uSmmA2apj4nqZ0JnQBqcswP2uf2j9rbPQEgD 4=; X-IronPort-AV: E=Sophos;i="5.88,284,1635206400"; d="scan'208";a="55067096" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-pdx-2b-0085f2c8.us-west-2.amazon.com) ([10.25.36.210]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP; 13 Jan 2022 10:06:24 +0000 Received: from EX13MTAUWB001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan2.pdx.amazon.com [10.236.137.194]) by email-inbound-relay-pdx-2b-0085f2c8.us-west-2.amazon.com (Postfix) with ESMTPS id F3F5041557; Thu, 13 Jan 2022 10:06:23 +0000 (UTC) Received: from EX13D13UWB004.ant.amazon.com (10.43.161.218) by EX13MTAUWB001.ant.amazon.com (10.43.161.249) with Microsoft SMTP Server (TLS) id 15.0.1497.28; Thu, 13 Jan 2022 10:06:23 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX13D13UWB004.ant.amazon.com (10.43.161.218) with Microsoft SMTP Server (TLS) id 15.0.1497.26; Thu, 13 Jan 2022 10:06:23 +0000 Received: from dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (172.19.116.181) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1497.28 via Frontend Transport; Thu, 13 Jan 2022 10:06:23 +0000 Received: by dev-dsk-farbere-1a-46ecabed.eu-west-1.amazon.com (Postfix, from userid 14301484) id 9A16C3096; Thu, 13 Jan 2022 10:06:22 +0000 (UTC) From: Eliav Farber To: CC: , , , , , , , , Subject: [PATCH 4/4] EDAC: Refactor edac_align_ptr() flow Date: Thu, 13 Jan 2022 10:06:22 +0000 Message-ID: <20220113100622.12783-5-farbere@amazon.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220113100622.12783-1-farbere@amazon.com> References: <20220113100622.12783-1-farbere@amazon.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-edac@vger.kernel.org Modify flow to be more clear: - Calculate required alignment based on size. - Check if *p is aligned and fix if not. - Set return ptr to to be *p. - Increase *p by new size for the next call. Signed-off-by: Eliav Farber --- drivers/edac/edac_mc.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c index 3367bf997b73..a3ff5a019fc7 100644 --- a/drivers/edac/edac_mc.c +++ b/drivers/edac/edac_mc.c @@ -241,9 +241,7 @@ EXPORT_SYMBOL_GPL(edac_mem_types); void *edac_align_ptr(void **p, unsigned size, int n_elems) { unsigned align, r; - void *ptr = *p; - - *p += size * n_elems; + void *ptr; /* * 'p' can possibly be an unaligned item X such that sizeof(X) is @@ -258,16 +256,22 @@ void *edac_align_ptr(void **p, unsigned size, int n_elems) else if (size > sizeof(u8)) align = sizeof(u16); else - return ptr; - - r = (unsigned long)ptr % align; + goto out; - if (r == 0) - return ptr; + /* Calculate alignment, and fix *p if not aligned. */ + r = (unsigned long)*p % align; + if (r) + *p += align - r; - *p += align - r; +out: + /* + * Set return ptr to to be *p (after alignment if it was needed), + * and increase *p by new size for the next call. + */ + ptr = *p; + *p += size * n_elems; - return (void *)(((unsigned long)ptr) + align - r); + return ptr; } static void _edac_mc_free(struct mem_ctl_info *mci)