From patchwork Mon Sep 18 10:52:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Whitchurch X-Patchwork-Id: 141433 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2711939vqi; Mon, 18 Sep 2023 07:43:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEdyAnWPW1YESBYl/E8OWLILup5x8sdIG8Cfb299NwtGmBTZbLBmqve2nPn8N2gPtf1G00 X-Received: by 2002:a05:6a20:3d06:b0:156:6bdd:2305 with SMTP id y6-20020a056a203d0600b001566bdd2305mr9539901pzi.45.1695048202509; Mon, 18 Sep 2023 07:43:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695048202; cv=none; d=google.com; s=arc-20160816; b=UefCWGfNlNwv6JFf5wEkiICGhLImkdnlYZw2kZ4240VF1gY8yMwzZOl5jWVRo/KUsx yJVv5FkgTApcbMXkXbpPXEv3Up9vGfkri01RbP38TTob5GK8A26POxk5Hacwnbv9W6Tv 3CBXGdCaj/lxslUInDlYmONKAFa3LtCprLt1bVwW3hxgow1YKz12uU+Kn9gv+HV5Zx9X fF+WbbVvadgiLxcE/werrcKtpB4/xFmrQkefEkLBmPIhfxMZfLaOrpohKn5k2tWQMu8N BOdFjk6LoHR9DHq66xGxdS8mUE5rZ3B8iXT+3gvqsudUShxLL/W8B1TW3R0xs3P4vK76 W4tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:message-id:content-transfer-encoding :mime-version:subject:date:from:dkim-signature; bh=bOsEzjVQKBPn7rGdrNw3l2iC/L1VtxB+euAZfU+U4zs=; fh=/BsWuqvqe3eo0r5JRt58YrKg2sVLpkLk+6gUJtF4R30=; b=HGKne6toh9mPS9CaTJVuRFTNLVCxEKBiYDsso2QAvmClZz9KSF7yTh62fPduT5+LuA O8vhFP6BwCqHU+IbgCpTb6xx3uDut9+BubGb+QKcvlp5N/yehVe2YucKAY/WWA7y9tYN JGR8Hi33nB0sm72bQlnw9R8AcRtOrazwNpwYfeRGFH2JiOJ29u2FNTEU6ayeYCpq/Y4k 4tr2NTUlDZBgteqylvQ5LwIeHnK+qupr7ofMXWZqBPxG8AmGAJiBGLg0/7ySVx6lOjYt Edcv/wrlBEVToJdIXnvTmSPbbpDQrmfhgy4Zul+Hn3Oho6lV/VanAPbWh9erYts+p0sD ByPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=K4y04qXC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id f16-20020a056a001ad000b0068ff741579fsi8116173pfv.318.2023.09.18.07.43.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 07:43:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@axis.com header.s=axis-central1 header.b=K4y04qXC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=axis.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 0A02680A7CE2; Mon, 18 Sep 2023 03:53:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237673AbjIRKxA (ORCPT + 27 others); Mon, 18 Sep 2023 06:53:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236692AbjIRKwq (ORCPT ); Mon, 18 Sep 2023 06:52:46 -0400 Received: from smtp2.axis.com (smtp2.axis.com [195.60.68.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF258A1 for ; Mon, 18 Sep 2023 03:52:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axis.com; q=dns/txt; s=axis-central1; t=1695034360; x=1726570360; h=from:date:subject:mime-version:content-transfer-encoding: message-id:to:cc; bh=bOsEzjVQKBPn7rGdrNw3l2iC/L1VtxB+euAZfU+U4zs=; b=K4y04qXC/1oq7GFlhMJEo/u48oSIj0wG0qXIrBm4gnU9Uxs/l3OQBbII Bk5+N8iLufUmt0Fuh4d8EAX32u4DS3JQW02kYoI3w8XTNEpXIUQGXboS3 qt5AiVNH3b69NFdYvi6mWv4sJOhOWmyHAFrvzLXFCYn4EOGwMHcjEonFe 8GhRe1C91Mq2Rwv9WgHARidsC8TomLdfPxjZ2YmsG9V3OPmlHzhm26uXW rQlaXP9UnRgEUaIbRuo/P61kgZjp/06DZNOI83pZp9nWpj2MgHl8Dk7TT dKjiiZkp4n6H/WQZglxfq6HHG2+2Wj34Xt8Yl0yOoTu1r5bHbhURkGANo w==; From: Vincent Whitchurch Date: Mon, 18 Sep 2023 12:52:34 +0200 Subject: [PATCH v3] x86: Fix build of UML with KASAN MIME-Version: 1.0 Message-ID: <20230918-uml-kasan-v3-1-7ad6db477df6@axis.com> X-B4-Tracking: v=1; b=H4sIAPErCGUC/22Nyw7CIBBFf6VhLYZXTXHlfxgXFAZLtNCAkpqm/ y50YxdmVudmzr0LShAdJHRuFhQhu+SCL8APDdKD8nfAzhRGjDBOTkTi9/jED5WUx4xLZozQvGs 7VP57lQD3UXk9VMOGwGo8RbBu3iaut8KDS68QP9tipjX9V54ppri1SndGEGmEvajZpaMOI6olm f1ESdu9yIoIlpezwlIhduK6rl9voZLC8QAAAA== To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , , "H. Peter Anvin" , Frederic Weisbecker , "Rafael J. Wysocki" , Peter Zijlstra CC: Richard Weinberger , Anton Ivanov , Johannes Berg , , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , , , , Vincent Whitchurch X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Mon, 18 Sep 2023 03:53:35 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777386864089369530 X-GMAIL-MSGID: 1777386864089369530 Building UML with KASAN fails since commit 69d4c0d32186 ("entry, kasan, x86: Disallow overriding mem*() functions") with the following errors: $ tools/testing/kunit/kunit.py run --kconfig_add CONFIG_KASAN=y ... ld: mm/kasan/shadow.o: in function `memset': shadow.c:(.text+0x40): multiple definition of `memset'; arch/x86/lib/memset_64.o:(.noinstr.text+0x0): first defined here ld: mm/kasan/shadow.o: in function `memmove': shadow.c:(.text+0x90): multiple definition of `memmove'; arch/x86/lib/memmove_64.o:(.noinstr.text+0x0): first defined here ld: mm/kasan/shadow.o: in function `memcpy': shadow.c:(.text+0x110): multiple definition of `memcpy'; arch/x86/lib/memcpy_64.o:(.noinstr.text+0x0): first defined here UML does not use GENERIC_ENTRY and is still supposed to be allowed to override the mem*() functions, so use weak aliases in that case. Fixes: 69d4c0d32186 ("entry, kasan, x86: Disallow overriding mem*() functions") Signed-off-by: Vincent Whitchurch --- Changes in v3: - Add SYM_FUNC_ALIAS_MEMFUNC() macro to avoid ifdefs in multiple places. - Link to v2: https://lore.kernel.org/r/20230915-uml-kasan-v2-1-ef3f3ff4f144@axis.com Changes in v2: - Use CONFIG_UML instead of CONFIG_GENERIC_ENTRY. - Link to v1: https://lore.kernel.org/r/20230609-uml-kasan-v1-1-5fac8d409d4f@axis.com --- arch/x86/include/asm/linkage.h | 7 +++++++ arch/x86/lib/memcpy_64.S | 2 +- arch/x86/lib/memmove_64.S | 2 +- arch/x86/lib/memset_64.S | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) --- base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d change-id: 20230609-uml-kasan-2392dd4c3858 Best regards, diff --git a/arch/x86/include/asm/linkage.h b/arch/x86/include/asm/linkage.h index 97a3de7892d3..32cdf1e92cfb 100644 --- a/arch/x86/include/asm/linkage.h +++ b/arch/x86/include/asm/linkage.h @@ -97,6 +97,13 @@ CFI_POST_PADDING \ SYM_FUNC_END(__cfi_##name) +/* UML needs to be able to override memcpy() and friends for KASAN. */ +#ifdef CONFIG_UML +#define SYM_FUNC_ALIAS_MEMFUNC SYM_FUNC_ALIAS_WEAK +#else +#define SYM_FUNC_ALIAS_MEMFUNC SYM_FUNC_ALIAS +#endif + /* SYM_TYPED_FUNC_START -- use for indirectly called globals, w/ CFI type */ #define SYM_TYPED_FUNC_START(name) \ SYM_TYPED_START(name, SYM_L_GLOBAL, SYM_F_ALIGN) \ diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S index 8f95fb267caa..76697df8dfd5 100644 --- a/arch/x86/lib/memcpy_64.S +++ b/arch/x86/lib/memcpy_64.S @@ -40,7 +40,7 @@ SYM_TYPED_FUNC_START(__memcpy) SYM_FUNC_END(__memcpy) EXPORT_SYMBOL(__memcpy) -SYM_FUNC_ALIAS(memcpy, __memcpy) +SYM_FUNC_ALIAS_MEMFUNC(memcpy, __memcpy) EXPORT_SYMBOL(memcpy) SYM_FUNC_START_LOCAL(memcpy_orig) diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S index 0559b206fb11..ccdf3a597045 100644 --- a/arch/x86/lib/memmove_64.S +++ b/arch/x86/lib/memmove_64.S @@ -212,5 +212,5 @@ SYM_FUNC_START(__memmove) SYM_FUNC_END(__memmove) EXPORT_SYMBOL(__memmove) -SYM_FUNC_ALIAS(memmove, __memmove) +SYM_FUNC_ALIAS_MEMFUNC(memmove, __memmove) EXPORT_SYMBOL(memmove) diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S index 7c59a704c458..3d818b849ec6 100644 --- a/arch/x86/lib/memset_64.S +++ b/arch/x86/lib/memset_64.S @@ -40,7 +40,7 @@ SYM_FUNC_START(__memset) SYM_FUNC_END(__memset) EXPORT_SYMBOL(__memset) -SYM_FUNC_ALIAS(memset, __memset) +SYM_FUNC_ALIAS_MEMFUNC(memset, __memset) EXPORT_SYMBOL(memset) SYM_FUNC_START_LOCAL(memset_orig)