Message ID | 20230208164011.2287122-4-arnd@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3560194wrn; Wed, 8 Feb 2023 08:42:40 -0800 (PST) X-Google-Smtp-Source: AK7set8OHKC/pUArsGlIvbzCL1Q5UZccH3JCw376yd8pOxpJZXp6llHQQ9vHDSA6kUIuFvMHU0VI X-Received: by 2002:a17:902:d48a:b0:196:6308:c9d3 with SMTP id c10-20020a170902d48a00b001966308c9d3mr8666487plg.0.1675874559998; Wed, 08 Feb 2023 08:42:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675874559; cv=none; d=google.com; s=arc-20160816; b=d+IesmFi5Q3bGrzYdRkkG70cHZt9zCdvr30ZqVX7j3hp7ziLz2HKDWI3QLKSvBlKm3 LT9eNJ+jj9dfuuTR/K/mHDp4g24wsbtueasZWzhQVRVESOhvKeZ5NimHnWhcttsPAm/G OMwJ1uzI+kmR5O+kTQ5GeM8aj8OpM4YOWMFJ0Z8F3DiPtneqQ3o3BT0xY1yZ0VSmljYG rwkdJPe61R4GQHwFZIHBS+ZZH/SbZKnMirc0tuEZ4zn3hPj1tmRRQMgS2+ozdrEueqAS 00ewAVjxMWSr1NXL5xLKj5UKh8Z9iaTIybfyAfctazLGfICEOMdIUxNJQsyX7QPZSADb C4mQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=643+SwLgNy1RbLG04tqRWPpetLAovg4NxWaY4lJrCag=; b=Zcla0R3yVkxuInIUEVV/S6BGp/EEMw9q4IYy3Z1B4ILS9zioFrCmNAEnvP2/HIRhGs ffdnVlV+z6Uu/BOWBMs3Hrg0MaaECSd7wwCRjkNptTAVdm+lPS4ivwk42nrD6QZZkWbu pRsTsVL+JFpLxI9EiBi3OHHrIkCZtgtpJmFz9iqAT3M1KWfvP0nbvRrkVJgFgCDDlFu+ qqR2/N3F7tdJDnPvfO8N1GuhI9Ok0433WnPGWcJYjdMiEgCL1GJwZTJcBtQFzhDcqB6Q qwy4D/rmyIoRpO9ot1ncqBz/hgRcbmsvR8hkHUP96KxSPSO3CUOwtXvijVY57R4MQcnb cRvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LFdiQq6g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g4-20020a1709026b4400b001965acaade8si18062308plt.24.2023.02.08.08.42.27; Wed, 08 Feb 2023 08:42:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LFdiQq6g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231728AbjBHQlk (ORCPT <rfc822;ivan.orlov0322@gmail.com> + 99 others); Wed, 8 Feb 2023 11:41:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231582AbjBHQlD (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 8 Feb 2023 11:41:03 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D61ED4E513 for <linux-kernel@vger.kernel.org>; Wed, 8 Feb 2023 08:40:42 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C544161735 for <linux-kernel@vger.kernel.org>; Wed, 8 Feb 2023 16:40:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFC6DC433EF; Wed, 8 Feb 2023 16:40:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675874441; bh=KSTAGgDnOoF+Y8ilpIa2/cv9j+0fPW1oC9ZZcQLM2eE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LFdiQq6ga8XowSHjWP/gHx+MTRZ5gzHOeEQItB6u0vWi/qAM+7TSG3jKpbFM7ST7b HknJHLkLkxSrNsweBODYdwxdhCcwh0ZP6KDRwCyJU1yO6mOkKy8qYEKcaXvB64lfpn 5t0WDjHlkUTIUMzXJ9hPLJ4nKK1YA9uoSz8OxTLGZY/oGJ5o+BeDqc55kJL2VQ4B87 YxoQM4JHEJPWnH2N5G1XeloDTsyVU817GwYyN0sti+KNMVklvT04KqIeKt4+6xi5cW a1l5Zgc6knppsb6GttEz3n6W3/c7nvKpJaBEYvNlwc3B5kdBXl7a+j62nm6XTMgCh2 QXKjMqDmBb5uA== From: Arnd Bergmann <arnd@kernel.org> To: Josh Poimboeuf <jpoimboe@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Borislav Petkov <bp@suse.de>, Marco Elver <elver@google.com>, Will Deacon <will@kernel.org>, Thomas Gleixner <tglx@linutronix.de> Cc: kasan-dev@googlegroups.com, Dmitry Vyukov <dvyukov@google.com>, Alexander Potapenko <glider@google.com>, Andrey Ryabinin <ryabinin.a.a@gmail.com>, Vincenzo Frascino <vincenzo.frascino@arm.com>, Andrey Konovalov <andreyknvl@gmail.com>, Arnd Bergmann <arnd@arndb.de>, Miroslav Benes <mbenes@suse.cz>, "Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>, Sathvika Vasireddy <sv@linux.ibm.com>, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] objtool: add UACCESS exceptions for __tsan_volatile_read/write Date: Wed, 8 Feb 2023 17:39:58 +0100 Message-Id: <20230208164011.2287122-4-arnd@kernel.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208164011.2287122-1-arnd@kernel.org> References: <20230208164011.2287122-1-arnd@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757281842105729444?= X-GMAIL-MSGID: =?utf-8?q?1757281842105729444?= |
Series |
[1/4] kasan: mark addr_has_metadata __always_inline
|
|
Commit Message
Arnd Bergmann
Feb. 8, 2023, 4:39 p.m. UTC
From: Arnd Bergmann <arnd@arndb.de> A lot of the tsan helpers are already excempt from the UACCESS warnings, but some more functions were added that need the same thing: kernel/kcsan/core.o: warning: objtool: __tsan_volatile_read16+0x0: call to __tsan_unaligned_read16() with UACCESS enabled kernel/kcsan/core.o: warning: objtool: __tsan_volatile_write16+0x0: call to __tsan_unaligned_write16() with UACCESS enabled vmlinux.o: warning: objtool: __tsan_unaligned_volatile_read16+0x4: call to __tsan_unaligned_read16() with UACCESS enabled vmlinux.o: warning: objtool: __tsan_unaligned_volatile_write16+0x4: call to __tsan_unaligned_write16() with UACCESS enabled Fixes: 75d75b7a4d54 ("kcsan: Support distinguishing volatile accesses") Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- tools/objtool/check.c | 2 ++ 1 file changed, 2 insertions(+)
Comments
On Wed, 8 Feb 2023 at 17:40, Arnd Bergmann <arnd@kernel.org> wrote: > > From: Arnd Bergmann <arnd@arndb.de> > > A lot of the tsan helpers are already excempt from the UACCESS warnings, > but some more functions were added that need the same thing: > > kernel/kcsan/core.o: warning: objtool: __tsan_volatile_read16+0x0: call to __tsan_unaligned_read16() with UACCESS enabled > kernel/kcsan/core.o: warning: objtool: __tsan_volatile_write16+0x0: call to __tsan_unaligned_write16() with UACCESS enabled > vmlinux.o: warning: objtool: __tsan_unaligned_volatile_read16+0x4: call to __tsan_unaligned_read16() with UACCESS enabled > vmlinux.o: warning: objtool: __tsan_unaligned_volatile_write16+0x4: call to __tsan_unaligned_write16() with UACCESS enabled That's odd - this has never been needed, because all __tsan_unaligned are aliases for the non-unaligned functions. And all those are in the uaccess_safe_builtin list already. So if suddenly the alias name becomes the symbol that objtool sees, we might need to add all the other functions as well. Is this a special build with a new compiler? > Fixes: 75d75b7a4d54 ("kcsan: Support distinguishing volatile accesses") > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > tools/objtool/check.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/tools/objtool/check.c b/tools/objtool/check.c > index e8fb3bf7a2e3..d89ef6957021 100644 > --- a/tools/objtool/check.c > +++ b/tools/objtool/check.c > @@ -1200,6 +1200,8 @@ static const char *uaccess_safe_builtin[] = { > "__tsan_atomic64_compare_exchange_val", > "__tsan_atomic_thread_fence", > "__tsan_atomic_signal_fence", > + "__tsan_unaligned_read16", > + "__tsan_unaligned_write16", > /* KCOV */ > "write_comp_data", > "check_kcov_mode", > -- > 2.39.1 > > -- > You received this message because you are subscribed to the Google Groups "kasan-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20230208164011.2287122-4-arnd%40kernel.org.
On Wed, Feb 8, 2023, at 17:59, Marco Elver wrote: > On Wed, 8 Feb 2023 at 17:40, Arnd Bergmann <arnd@kernel.org> wrote: >> >> From: Arnd Bergmann <arnd@arndb.de> >> >> A lot of the tsan helpers are already excempt from the UACCESS warnings, >> but some more functions were added that need the same thing: >> >> kernel/kcsan/core.o: warning: objtool: __tsan_volatile_read16+0x0: call to __tsan_unaligned_read16() with UACCESS enabled >> kernel/kcsan/core.o: warning: objtool: __tsan_volatile_write16+0x0: call to __tsan_unaligned_write16() with UACCESS enabled >> vmlinux.o: warning: objtool: __tsan_unaligned_volatile_read16+0x4: call to __tsan_unaligned_read16() with UACCESS enabled >> vmlinux.o: warning: objtool: __tsan_unaligned_volatile_write16+0x4: call to __tsan_unaligned_write16() with UACCESS enabled > > That's odd - this has never been needed, because all __tsan_unaligned > are aliases for the non-unaligned functions. And all those are in the > uaccess_safe_builtin list already. > > So if suddenly the alias name becomes the symbol that objtool sees, we > might need to add all the other functions as well. > > Is this a special build with a new compiler? I see this with gcc-12 and gcc-13 but not with clang-{14,15,16}, have not tried any older versions recently. What I see in the .s file for one of the affected configs is .globl __tsan_unaligned_read16 .set __tsan_unaligned_read16,__tsan_read16 .p2align 6 .globl __tsan_volatile_read16 .type __tsan_volatile_read16, @function __tsan_volatile_read16: endbr64 jmp __tsan_read16 # .size __tsan_volatile_read16, .-__tsan_volatile_read16 .globl __tsan_unaligned_volatile_read16 .set __tsan_unaligned_volatile_read16,__tsan_volatile_read16 ... .set __tsan_unaligned_write16,__tsan_write16 .p2align 6 .globl __tsan_volatile_write16 .type __tsan_volatile_write16, @function __tsan_volatile_write16: endbr64 jmp __tsan_write16 # .size __tsan_volatile_write16, .-__tsan_volatile_write16 .globl __tsan_unaligned_volatile_write16 .set __tsan_unaligned_volatile_write16,__tsan_volatile_write16 In the object file that turns into: 0000000000004e80 <__tsan_unaligned_volatile_read16>: 4e80: f3 0f 1e fa endbr64 4e84: e9 b7 fe ff ff jmp 4d40 <__tsan_read16> ... 0000000000005000 <__tsan_unaligned_volatile_write16>: 5000: f3 0f 1e fa endbr64 5004: e9 b7 fe ff ff jmp 4ec0 <__tsan_unaligned_write16> It appears like it picks randomly between the original name and the alias here, no idea why. Using the clang integrated assembler to build the .o file from the gcc generated .s file shows the same code as 0000000000004e80 <__tsan_unaligned_volatile_read16>: 4e80: f3 0f 1e fa endbr64 4e84: e9 00 00 00 00 jmp 4e89 <__tsan_unaligned_volatile_read16+0x9> 4e85: R_X86_64_PLT32 __tsan_read16-0x4 ... 0000000000005000 <__tsan_unaligned_volatile_write16>: 5000: f3 0f 1e fa endbr64 5004: e9 00 00 00 00 jmp 5009 <__tsan_unaligned_volatile_write16+0x9> 5005: R_X86_64_PLT32 __tsan_write16-0x4 Attaching the object file for reference. Arnd
On Wed, 8 Feb 2023 at 20:53, Arnd Bergmann <arnd@arndb.de> wrote: > > On Wed, Feb 8, 2023, at 17:59, Marco Elver wrote: > > On Wed, 8 Feb 2023 at 17:40, Arnd Bergmann <arnd@kernel.org> wrote: > >> > >> From: Arnd Bergmann <arnd@arndb.de> > >> > >> A lot of the tsan helpers are already excempt from the UACCESS warnings, > >> but some more functions were added that need the same thing: > >> > >> kernel/kcsan/core.o: warning: objtool: __tsan_volatile_read16+0x0: call to __tsan_unaligned_read16() with UACCESS enabled > >> kernel/kcsan/core.o: warning: objtool: __tsan_volatile_write16+0x0: call to __tsan_unaligned_write16() with UACCESS enabled > >> vmlinux.o: warning: objtool: __tsan_unaligned_volatile_read16+0x4: call to __tsan_unaligned_read16() with UACCESS enabled > >> vmlinux.o: warning: objtool: __tsan_unaligned_volatile_write16+0x4: call to __tsan_unaligned_write16() with UACCESS enabled > > > > That's odd - this has never been needed, because all __tsan_unaligned > > are aliases for the non-unaligned functions. And all those are in the > > uaccess_safe_builtin list already. > > > > So if suddenly the alias name becomes the symbol that objtool sees, we > > might need to add all the other functions as well. > > > > Is this a special build with a new compiler? > > I see this with gcc-12 and gcc-13 but not with clang-{14,15,16}, have > not tried any older versions recently. > > What I see in the .s file for one of the affected configs is > > .globl __tsan_unaligned_read16 > .set __tsan_unaligned_read16,__tsan_read16 > .p2align 6 > .globl __tsan_volatile_read16 > .type __tsan_volatile_read16, @function > __tsan_volatile_read16: > endbr64 > jmp __tsan_read16 # > .size __tsan_volatile_read16, .-__tsan_volatile_read16 > .globl __tsan_unaligned_volatile_read16 > .set __tsan_unaligned_volatile_read16,__tsan_volatile_read16 > ... > .set __tsan_unaligned_write16,__tsan_write16 > .p2align 6 > .globl __tsan_volatile_write16 > .type __tsan_volatile_write16, @function > __tsan_volatile_write16: > endbr64 > jmp __tsan_write16 # > .size __tsan_volatile_write16, .-__tsan_volatile_write16 > .globl __tsan_unaligned_volatile_write16 > .set __tsan_unaligned_volatile_write16,__tsan_volatile_write16 > > > In the object file that turns into: > > 0000000000004e80 <__tsan_unaligned_volatile_read16>: > 4e80: f3 0f 1e fa endbr64 > 4e84: e9 b7 fe ff ff jmp 4d40 <__tsan_read16> > ... > 0000000000005000 <__tsan_unaligned_volatile_write16>: > 5000: f3 0f 1e fa endbr64 > 5004: e9 b7 fe ff ff jmp 4ec0 <__tsan_unaligned_write16> > > > It appears like it picks randomly between the original name > and the alias here, no idea why. Using the clang integrated assembler > to build the .o file from the gcc generated .s file shows the same > code as > > 0000000000004e80 <__tsan_unaligned_volatile_read16>: > 4e80: f3 0f 1e fa endbr64 > 4e84: e9 00 00 00 00 jmp 4e89 <__tsan_unaligned_volatile_read16+0x9> > 4e85: R_X86_64_PLT32 __tsan_read16-0x4 > ... > 0000000000005000 <__tsan_unaligned_volatile_write16>: > 5000: f3 0f 1e fa endbr64 > 5004: e9 00 00 00 00 jmp 5009 <__tsan_unaligned_volatile_write16+0x9> > 5005: R_X86_64_PLT32 __tsan_write16-0x4 Interesting - also note that in kernel/kcsan/core.c, these functions don't even call each other explicitly. Although because sizeof(long) < 16 everywhere, the code for the volatile and non-volatile 16-byte variants ends up the same. So the optimizer seems to think it's ok to just "call" the other equivalent function, even though we didn't tell it to do so - check_access() is __always_inline. Whatever happens here isn't completely wrong, so if you just want to silence the warning: Acked-by: Marco Elver <elver@google.com> But I have a feeling the compiler is being a bit too clever here.
diff --git a/tools/objtool/check.c b/tools/objtool/check.c index e8fb3bf7a2e3..d89ef6957021 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -1200,6 +1200,8 @@ static const char *uaccess_safe_builtin[] = { "__tsan_atomic64_compare_exchange_val", "__tsan_atomic_thread_fence", "__tsan_atomic_signal_fence", + "__tsan_unaligned_read16", + "__tsan_unaligned_write16", /* KCOV */ "write_comp_data", "check_kcov_mode",