From patchwork Mon Feb 27 09:47:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 13153141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7C70C7EE30 for ; Mon, 27 Feb 2023 09:51:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3F8376B0072; Mon, 27 Feb 2023 04:51:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A7A96B0073; Mon, 27 Feb 2023 04:51:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 26F296B0074; Mon, 27 Feb 2023 04:51:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 16CBF6B0072 for ; Mon, 27 Feb 2023 04:51:46 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id DEC76409D0 for ; Mon, 27 Feb 2023 09:51:45 +0000 (UTC) X-FDA: 80512604970.17.BE5A79F Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf15.hostedemail.com (Postfix) with ESMTP id 24BA6A000B for ; Mon, 27 Feb 2023 09:51:43 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=kMaj71Vf; spf=pass (imf15.hostedemail.com: domain of 3Ln38YwUKCEEhoyhujrrjoh.frpolqx0-ppnydfn.ruj@flex--elver.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3Ln38YwUKCEEhoyhujrrjoh.frpolqx0-ppnydfn.ruj@flex--elver.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677491504; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=vLAZSY9lX30lbRvxmgqsLOf9PyjLVjvwhzsapOvRcDY=; b=ROF/w4pgfUcTKBDT6xgsYz0519PJgBNbXxh3MuCa+G5C4qLVTwGxwIZQb93nBPqfwoFaAc n/USKtBaAFSIpUi6figTNf29iQadImf4qhLiHNVEWLe71M5AqOcyStF/yPJpLHo5Ur/gtQ kSLuC+6KzDiEPvww8QsX3XLohljJEFA= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=kMaj71Vf; spf=pass (imf15.hostedemail.com: domain of 3Ln38YwUKCEEhoyhujrrjoh.frpolqx0-ppnydfn.ruj@flex--elver.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3Ln38YwUKCEEhoyhujrrjoh.frpolqx0-ppnydfn.ruj@flex--elver.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677491504; a=rsa-sha256; cv=none; b=AROJLP6BUCC16xzDQ7obELazab4E6KbotV3MAVJDpJDvyKCZ0mJHZ5QPCVffBSDJoHNGzD lb6B77ErRrtoxilTEAbPdYjbdkzfMpcsyAvw9AfzALKPglHoyuqAb/RXKqH+KcetSZzrjm GgGzusbhfxlbv3uSGCMa1LpOiBZf4Z0= Received: by mail-ed1-f74.google.com with SMTP id fi8-20020a056402550800b004a26cc7f6cbso7748658edb.4 for ; Mon, 27 Feb 2023 01:51:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=vLAZSY9lX30lbRvxmgqsLOf9PyjLVjvwhzsapOvRcDY=; b=kMaj71Vfi/lRJwpu2c6Y30c4GChofTS/1NAM6BSsppmd+79MVgshdAkbfwYcY+bpGs CiRnRoFJalGQy06Qf6ofr6IPOrEnPsJbQXg6+U1jdMGXFVGJ1AsOf4i7MQFcQA+l8ULe Mo2b8h0asHjntecxkZTvGug03tleK52dxXa25hMzrG4SNMTyU/JAHj9MR/l79zKdXHLQ buM5KSHUBERdH016UmpVUqFya9R7u6amo2onMgq6s4r74lW7NUSfh3ur9xrEK7PEmm+k 3xZcAhDWMRii49gLrjaLUjNtFD2IuQu4WrV5DAjjdfOzUNXSCtDX0oHDPSI05CE4qHzb EqWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=vLAZSY9lX30lbRvxmgqsLOf9PyjLVjvwhzsapOvRcDY=; b=DQFTyiKr12xd5Yw4oud7VdPjMWUhgMucuSYRMKtRY4dO2FZOCXozxt9EewnANz0EiV i258VOTBdETl+d/tudykwTHqvctukD4EyuPoIPWNqUHqe0juzXvkO27rRVcTv9iGVuxQ uH14at8JX1Ow74mDJVw/5BL3DpvO7U7c6wlgx5gfnZTL9V2a3l7lahk1s0j2dIYOF0Ds F2Eg2Wq9/EWM9AKFPaJUYP6PrMk/j3pjD0Ey4Sxboj0xdt7uMZP75h0OZZDEEKbvGZrE sLRVBzOKWctkrpMYJ1UrabeIV1SkTUr0MxKZhIIjjf+VBBnaxrexqu9rTfO8F/yE8X2Y D6ww== X-Gm-Message-State: AO0yUKXJ23ja7G+oTFerMOZNwO700rBLFvpcD2u5rUHwXgFemM+2uIDn w/OF42ohFcNcPS33kbjkXKWKozysZA== X-Google-Smtp-Source: AK7set8hge3bNWvK5Bx6TAmYJQ6x6+ySzteQpQn1kKAYlB8+s6f2a5QBRfTeJyAYOF013isoIX53pzIcXw== X-Received: from elver.muc.corp.google.com ([2a00:79e0:9c:201:1a89:611d:c416:e1ee]) (user=elver job=sendgmr) by 2002:a17:907:60cd:b0:8b1:3540:7632 with SMTP id hv13-20020a17090760cd00b008b135407632mr5583442ejc.2.1677491502399; Mon, 27 Feb 2023 01:51:42 -0800 (PST) Date: Mon, 27 Feb 2023 10:47:27 +0100 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230227094726.3833247-1-elver@google.com> Subject: [PATCH mm] kasan, powerpc: Don't rename memintrinsics if compiler adds prefixes From: Marco Elver To: elver@google.com, Andrew Morton Cc: Alexander Potapenko , Andrey Ryabinin , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Liam Howlett , kasan-dev@googlegroups.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Daniel Axtens , kernel test robot X-Rspamd-Queue-Id: 24BA6A000B X-Stat-Signature: w8qqt6363bkbhb8kpy4t61cwyd8compw X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1677491503-815289 X-HE-Meta: U2FsdGVkX19kPXOYLeK0gRqktxCM1gd6bzAixdRtzc49hH8OKXWQfHbiSNUVTo3bni2qnKlRnffvwhgcrrrFUnmMuuz3IQ2FIAeugITrhVIH1THFKYxjVyjuY/BIpeRHVKg9NZGdCzeZ9fUlGsVAyLBaf2+7phxGqsSO1cTkjHAap6ttsZdkdhD4y2Qz7zFlzjzhjyXs830zMWNCaan+daOCIPqAzQayiKkGRZ3nB9Ru8jrgP2lopZLk2o7jnHrEhSuYd0egngenSrXdsqWHJygbe2G7B/ZjYCRtGO8J1IkkKsF7kO7MNLzeP6pwzVprwG5BjL1czyY+xdGC5Q8pTFNk++v7FGYHagvuG1DoFeAD08cz0OVvoi26wRicZ5QBKYSR0aeQuArcoqNUt7eetJtMWeihO3ATTjj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Cwgxja/a1Je+Rji2g1EsLz+RFvh3p7iOGeyATM65cTpy/Ffzl6OUwNr4X7Psu1rK0WiqqhbGW5bLTibx+tFYqkQUsm//ZE41V+a8lFAgLdMR+sg6dROIbQHFDaoIIj54RHb6Tg0p4JT9Nik1GgnHJlwr8Z2Rrn7Xpp2njRH7/DSIJRpkF4P7+mKtWrFLS9lg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: With appropriate compiler support [1], KASAN builds use __asan prefixed meminstrinsics, and KASAN no longer overrides memcpy/memset/memmove. If compiler support is detected (CC_HAS_KASAN_MEMINTRINSIC_PREFIX), define memintrinsics normally (do not prefix '__'). On powerpc, KASAN is the only user of __mem functions, which are used to define instrumented memintrinsics. Alias the normal versions for KASAN to use in its implementation. Link: https://lore.kernel.org/all/20230224085942.1791837-1-elver@google.com/ [1] Link: https://lore.kernel.org/oe-kbuild-all/202302271348.U5lvmo0S-lkp@intel.com/ Reported-by: kernel test robot Signed-off-by: Marco Elver Acked-by: Michael Ellerman (powerpc) --- arch/powerpc/include/asm/kasan.h | 2 +- arch/powerpc/include/asm/string.h | 15 +++++++++++---- arch/powerpc/kernel/prom_init_check.sh | 9 +++++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/include/asm/kasan.h b/arch/powerpc/include/asm/kasan.h index 92a968202ba7..365d2720097c 100644 --- a/arch/powerpc/include/asm/kasan.h +++ b/arch/powerpc/include/asm/kasan.h @@ -2,7 +2,7 @@ #ifndef __ASM_KASAN_H #define __ASM_KASAN_H -#ifdef CONFIG_KASAN +#if defined(CONFIG_KASAN) && !defined(CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX) #define _GLOBAL_KASAN(fn) _GLOBAL(__##fn) #define _GLOBAL_TOC_KASAN(fn) _GLOBAL_TOC(__##fn) #define EXPORT_SYMBOL_KASAN(fn) EXPORT_SYMBOL(__##fn) diff --git a/arch/powerpc/include/asm/string.h b/arch/powerpc/include/asm/string.h index 2aa0e31e6884..60ba22770f51 100644 --- a/arch/powerpc/include/asm/string.h +++ b/arch/powerpc/include/asm/string.h @@ -30,11 +30,17 @@ extern int memcmp(const void *,const void *,__kernel_size_t); extern void * memchr(const void *,int,__kernel_size_t); void memcpy_flushcache(void *dest, const void *src, size_t size); +#ifdef CONFIG_KASAN +/* __mem variants are used by KASAN to implement instrumented meminstrinsics. */ +#ifdef CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX +#define __memset memset +#define __memcpy memcpy +#define __memmove memmove +#else /* CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX */ void *__memset(void *s, int c, __kernel_size_t count); void *__memcpy(void *to, const void *from, __kernel_size_t n); void *__memmove(void *to, const void *from, __kernel_size_t n); - -#if defined(CONFIG_KASAN) && !defined(__SANITIZE_ADDRESS__) +#ifndef __SANITIZE_ADDRESS__ /* * For files that are not instrumented (e.g. mm/slub.c) we * should use not instrumented version of mem* functions. @@ -46,8 +52,9 @@ void *__memmove(void *to, const void *from, __kernel_size_t n); #ifndef __NO_FORTIFY #define __NO_FORTIFY /* FORTIFY_SOURCE uses __builtin_memcpy, etc. */ #endif - -#endif +#endif /* !__SANITIZE_ADDRESS__ */ +#endif /* CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX */ +#endif /* CONFIG_KASAN */ #ifdef CONFIG_PPC64 #ifndef CONFIG_KASAN diff --git a/arch/powerpc/kernel/prom_init_check.sh b/arch/powerpc/kernel/prom_init_check.sh index 311890d71c4c..f3f43a8f48cf 100644 --- a/arch/powerpc/kernel/prom_init_check.sh +++ b/arch/powerpc/kernel/prom_init_check.sh @@ -13,8 +13,13 @@ # If you really need to reference something from prom_init.o add # it to the list below: -grep "^CONFIG_KASAN=y$" ${KCONFIG_CONFIG} >/dev/null -if [ $? -eq 0 ] +has_renamed_memintrinsics() +{ + grep -q "^CONFIG_KASAN=y$" ${KCONFIG_CONFIG} && \ + ! grep -q "^CONFIG_CC_HAS_KASAN_MEMINTRINSIC_PREFIX=y" ${KCONFIG_CONFIG} +} + +if has_renamed_memintrinsics then MEM_FUNCS="__memcpy __memset" else