Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752521AbdLAMhn (ORCPT ); Fri, 1 Dec 2017 07:37:43 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:60911 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752308AbdLAMhm (ORCPT ); Fri, 1 Dec 2017 07:37:42 -0500 Subject: Re: [PATCH] ubsan: don't handle misaligned address when support unaligned access To: David Laight , "akpm@linux-foundation.org" , "aryabinin@virtuozzo.co" , "linux-kernel@vger.kernel.org" , LinuxArm References: <9cdc75c4-326f-5adb-b32c-c95e1f3211ce@huawei.com> <4b788fc92eee4c509c37fba83365dd72@AcuMS.aculab.com> From: Ding Tianhong Message-ID: <957bb3ca-94a3-d083-7896-6bc8a5cac8a9@huawei.com> Date: Fri, 1 Dec 2017 20:37:09 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <4b788fc92eee4c509c37fba83365dd72@AcuMS.aculab.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.177.23.32] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1797 Lines: 66 On 2017/12/1 19:47, David Laight wrote: >> of noise in the log and cause confusion. >> >> This patch will close the detection of unaligned access when >> the system support unaligned access. >> >> Signed-off-by: Ding Tianhong >> --- >> lib/ubsan.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/lib/ubsan.c b/lib/ubsan.c >> index fb0409d..278b4c3 100644 >> --- a/lib/ubsan.c >> +++ b/lib/ubsan.c >> @@ -321,7 +321,8 @@ void __ubsan_handle_type_mismatch(struct type_mismatch_data *data, >> >> if (!ptr) >> handle_null_ptr_deref(data); >> - else if (data->alignment && !IS_ALIGNED(ptr, data->alignment)) >> + else if (data->alignment && !IS_ALIGNED(ptr, data->alignment) && >> + !IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) >> handle_missaligned_access(data, ptr); >> else >> handle_object_size_mismatch(data, ptr); > > Won't that report an object size error instead of actually > doing the required access? > Yes,I miss it. > Surely it shouldn't get into this function at all? > > I guess 'alignment' is set to 4 or 8. > If it were set to 3 or 7 (or 0) then the tests on the pointer > would be much simpler - maybe at a slight extra cost in setup. > Looks like we need to fix it in the handle_missaligned_access: diff --git a/lib/ubsan.c b/lib/ubsan.c index 278b4c3..040f8b2 100644 --- a/lib/ubsan.c +++ b/lib/ubsan.c @@ -289,6 +289,9 @@ static void handle_missaligned_access(struct type_mismatch_data *data, if (suppress_report(&data->location)) return; + if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) + return; + ubsan_prologue(&data->location, &flags); pr_err("%s misaligned address %p for type %s\n", Thanks Ding > David >