Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752270AbdLALrU (ORCPT ); Fri, 1 Dec 2017 06:47:20 -0500 Received: from smtp-out6.electric.net ([192.162.217.184]:59311 "EHLO smtp-out6.electric.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752124AbdLALrS (ORCPT ); Fri, 1 Dec 2017 06:47:18 -0500 From: David Laight To: "'Ding Tianhong'" , "akpm@linux-foundation.org" , "aryabinin@virtuozzo.co" , "linux-kernel@vger.kernel.org" , LinuxArm Subject: RE: [PATCH] ubsan: don't handle misaligned address when support unaligned access Thread-Topic: [PATCH] ubsan: don't handle misaligned address when support unaligned access Thread-Index: AQHTapg/Xry74PW6KUaDG8eK14ciy6MuXkSA Date: Fri, 1 Dec 2017 11:47:35 +0000 Message-ID: <4b788fc92eee4c509c37fba83365dd72@AcuMS.aculab.com> References: <9cdc75c4-326f-5adb-b32c-c95e1f3211ce@huawei.com> In-Reply-To: <9cdc75c4-326f-5adb-b32c-c95e1f3211ce@huawei.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [fd9f:af1c:a25b:0:43c:695e:880f:8750] Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 X-Outbound-IP: 156.67.243.126 X-Env-From: David.Laight@ACULAB.COM X-Proto: esmtps X-Revdns: X-HELO: AcuMS.aculab.com X-TLS: TLSv1.2:ECDHE-RSA-AES256-SHA384:256 X-Authenticated_ID: X-PolicySMART: 3396946, 3397078 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by nfs id vB1BlQvY000870 Content-Length: 2327 Lines: 61 From: Ding Tianhong > Sent: 01 December 2017 11:32 > To: akpm@linux-foundation.org; aryabinin@virtuozzo.co; linux-kernel@vger.kernel.org; LinuxArm > Subject: [PATCH] ubsan: don't handle misaligned address when support unaligned access > > The ubsan always report Warning just like: > > UBSAN: Undefined behaviour in ../include/linux/etherdevice.h:386:9 > load of misaligned address ffffffc069ba0482 for type 'long unsigned int' > which requires 8 byte alignment > CPU: 0 PID: 901 Comm: sshd Not tainted 4.xx+ #1 > Hardware name: linux,dummy-virt (DT) > Call trace: > [] dump_backtrace+0x0/0x348 > [] show_stack+0x20/0x30 > [] dump_stack+0x144/0x1b4 > [] ubsan_epilogue+0x18/0x74 > [] __ubsan_handle_type_mismatch+0x1a0/0x25c > [] dev_gro_receive+0x17d8/0x1830 > [] napi_gro_receive+0x30/0x158 > [] virtnet_receive+0xad4/0x1fa8 > > The reason is that when enable the CONFIG_UBSAN_ALIGNMENT, the ubsan > will report the unaligned access even if the system support it > (CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS=y), it will produce a lot > 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? 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. David