From patchwork Thu Dec 7 01:21:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ding Tianhong X-Patchwork-Id: 120915 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp7764483qgn; Wed, 6 Dec 2017 17:22:53 -0800 (PST) X-Google-Smtp-Source: AGs4zMa+yjkbmaydpKgZsmHLaesHrLXJy2yo3sBnYJZklzPL/ZLa+BCPVtUBuMHAgFYwvywI0L5y X-Received: by 10.99.165.25 with SMTP id n25mr22691281pgf.3.1512609773842; Wed, 06 Dec 2017 17:22:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512609773; cv=none; d=google.com; s=arc-20160816; b=KsNV3EILs6CRDzU6X0fuuIxv3cEeXhKG/5IGrrYPL3iWSW7M7O20KCso7fMLIR95UW TLl7fthkB8KmAH4HsB9tUbJPrEjRgdjuN2aETcl4ul55Jh/iUXuuuvxWpgoCgT1i0Wp3 z4Bs7tNFvqkVSGyF4t3UNrL3VxXobOqKAMScGa0+u+7HUn3NUEg1OJqBT+vna4QNQAax C9tgS98VYVz/QxIMWnBzbAVPfbr01KcoD+y6js5XSdRX6u7sMqfklTwt+8LOdXRxcRFI wX48ZjHZ481Me4EVzTJBB243hamZEjfLAl1S3aCJMPgo6NAypvVYEsw97HZkOjuxF5uM yTOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:date:message-id:to:subject:from :arc-authentication-results; bh=d4d4zR6TqNK/vtldIsoCsVfcLAwvqyOH0fMPdpEezuM=; b=JpI6eR9qejpXi3qCiiON1NYoc9xzKErc/ZwlTOaQ60EwHvaY3A1UikKkmlrXPQh9K3 BvclvyPODGPwg+mTdB0W5m1mmsCnDlsqiKeo4PZGgcBvjj8NF3epudI7g8RXoeikryL0 Pmer/d1Bog0o6x3VZpK98ZcUjq4dzwQVnvMEuS1vOtrARCfDcZGO50mA6v90/4zCCi0k FWxe0XpvP81uakBJGHty45s9vYguWeKsEcikN4LLG1bq0BKCw+CQYlyYa+1wv/hZ6VGY nF0VmsHdVM2T9+KBMQL/jrI4D2DOyh4A20TYQjhBXve+hY6HoS7ufHJ2yblhoOAFnwlP oMrg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i16si2778757pgv.496.2017.12.06.17.22.53; Wed, 06 Dec 2017 17:22:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752344AbdLGBWv (ORCPT + 21 others); Wed, 6 Dec 2017 20:22:51 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:11520 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752160AbdLGBWu (ORCPT ); Wed, 6 Dec 2017 20:22:50 -0500 Received: from 172.30.72.59 (EHLO DGGEMS411-HUB.china.huawei.com) ([172.30.72.59]) by dggrg05-dlp.huawei.com (MOS 4.4.6-GA FastPath queued) with ESMTP id DLX65748; Thu, 07 Dec 2017 09:22:26 +0800 (CST) Received: from [127.0.0.1] (10.177.23.32) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.361.1; Thu, 7 Dec 2017 09:22:18 +0800 From: Ding Tianhong Subject: [PATCH v3] ubsan: don't handle misaligned address when support unaligned access To: , Andrey Ryabinin , "linux-kernel@vger.kernel.org" , LinuxArm , David Laight Message-ID: <63dca1ee-bfd4-a5a0-050d-f0e3c94c6ae7@huawei.com> Date: Thu, 7 Dec 2017 09:21:10 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 X-Originating-IP: [10.177.23.32] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020205.5A2897D3.017B, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2014-11-16 11:51:01, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 74999e7c34bd1b538e16069f1884dfb9 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) -- 1.8.3.1 diff --git a/lib/ubsan.c b/lib/ubsan.c index fb0409d..0799678 100644 --- a/lib/ubsan.c +++ b/lib/ubsan.c @@ -321,9 +321,10 @@ 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)) - handle_missaligned_access(data, ptr); - else + else if (data->alignment && !IS_ALIGNED(ptr, data->alignment)) { + if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) + handle_missaligned_access(data, ptr); + } else handle_object_size_mismatch(data, ptr); } EXPORT_SYMBOL(__ubsan_handle_type_mismatch);