From patchwork Fri Feb 12 20:08:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 12086003 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A53FAC433E0 for ; Fri, 12 Feb 2021 20:10:35 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5690464DB2 for ; Fri, 12 Feb 2021 20:10:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5690464DB2 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:Mime-Version:Message-Id:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=HR1qPKxbMRTzDpTEf7kCi+akpJFVBvdWFHdvGMgWBSU=; b=dLTGItuhJnJmTA9mLbY4DXVVf5 pAo5LwvyShRRuhVSb3oTATaZgbouZCzMMBH0EG5i/fxn0VNS8PjNczpUxEXpQlZ17cTBlE6lv5y3X zj+rPjQnNQQXOV/1Lg5d+kc+yU42HD/4Um9oQJuqM6qQUkMhrPayJ36fqieL05CzhrZrUIX93eGiL JyVFGwpF3vvAHc/h/WNR8J4DXIeP7O8qMOAAniMn56Yr3ITP1nfV1IZrM3Nm6b4bXerMWTnh1RTPM bbYuH6AcmRN7VTg7bV8crdGroBh8nQjFcEM82diFCrv8CGDpfQnycBytSzP/HxmFG4H+fNWi0W68Z iPOBCMqg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1lAekR-0005gD-Q2; Fri, 12 Feb 2021 20:09:03 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1lAekP-0005fF-3j for linux-arm-kernel@lists.infradead.org; Fri, 12 Feb 2021 20:09:01 +0000 Received: by mail-wm1-x34a.google.com with SMTP id l21so503698wmj.1 for ; Fri, 12 Feb 2021 12:08:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:message-id:mime-version:subject:from:to:cc; bh=Yt8QroauzMxSaO8dfOJkOemr7RXc+gc/JDflCqQTAVk=; b=ri92KeJxTQmZDYwPc9CI1JAo1D1ryQFfgFIYBWpGFyAFqMNYOwh0bVZZOtPBYCHINt JXq4uovQhwEBqXp4m8r22GMI+KUzbMp8Y6em6kYTTic5PPM9dub7i9oEcNJg03qdaq1y rZkB1N85zdJ2cXshg3MTsu6LH141DL+75izXKKm5zhrJNEtD47qXcIkCkiwz/V5XYVHS WdVc/9cKFurKK/3wO6ckHf472nbQJbhXXDeOLDPSaXO9q96LV65Q0SFPY9aDjJWe7C8x jW3i6gT2DM5ik1XqbZEeq/gILY+Rx9FKfkd0yl26m1c18hXQoVvczc8tOxmxQhVzjntb U8ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:message-id:mime-version:subject:from :to:cc; bh=Yt8QroauzMxSaO8dfOJkOemr7RXc+gc/JDflCqQTAVk=; b=d8TrAePHwH+YzZjCCXXuEcggL5HRpBfvyoMIZPeynyxcUAJ0HMM3Gh+AAjCTM5oxl5 xq/E1K+WEH+/Ew9kjSyFVIoWTV6JYd/G57lT8Z75ImazfqdOsbF+m2HsDF07Zqo/JjJA n11qoA9qyoucLDADBHyUZ8TgKZ3vuyQBu6eyTNEcfcfb4/zXRWguFZLw62aSsLdnMQeO kzliv8+Gyn+7D0q0mu0M4R0aPkcwvSEUprhgJ5sPO8cj81oItQpXLKI2ew6FlSYsQXa4 +bKwEpRs21gI294pFWDtuVgl3awnMgfXlI5IxWMjE+5cmJ8CftzVcDte7qDcVtxS6Ru3 foPA== X-Gm-Message-State: AOAM533+d2Q3FiQFwu1WxUcuEom7V7GD5RDAdLgs2EQ3GQclXBRkiKAn m0RQ43ZwUCdSq5gAvS9W2f2of/okgAJf3rgx X-Google-Smtp-Source: ABdhPJzE2cAe228eOqgK3Bsnp2vYCX8C+miv+96QZ9bSkzK8DaWHuZTD+wNAnyJPdbflLU6JRbQ5zCku4iMbjMUW X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:19dd:6137:bedc:2fae]) (user=andreyknvl job=sendgmr) by 2002:a1c:3546:: with SMTP id c67mr2778wma.1.1613160536016; Fri, 12 Feb 2021 12:08:56 -0800 (PST) Date: Fri, 12 Feb 2021 21:08:52 +0100 Message-Id: Mime-Version: 1.0 X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog Subject: [PATCH mm] kasan: export HW_TAGS symbols for KUnit tests From: Andrey Konovalov To: Andrew Morton , Catalin Marinas , Vincenzo Frascino X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210212_150901_174161_65D37652 X-CRM114-Status: GOOD ( 16.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, Christoph Hellwig , linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Peter Collingbourne , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Currently, building KASAN-KUnit tests as a module fails with: ERROR: modpost: "mte_enable_kernel" [lib/test_kasan.ko] undefined! ERROR: modpost: "mte_set_report_once" [lib/test_kasan.ko] undefined! This change adds KASAN wrappers for mte_enable_kernel() and mte_set_report_once() and only defines and exports them when KASAN-KUnit tests are enabled. The wrappers aren't defined when tests aren't enabled to avoid misuse. The mte_() functions aren't exported directly to avoid having low-level KASAN ifdefs in the arch code. Signed-off-by: Andrey Konovalov --- Changes v1->v2: - Add wrappers instead of exporting MTE symbols directly. - Only define and export wrappers when KASAN-KUnit tests are enabled. --- lib/test_kasan.c | 6 +++--- mm/kasan/hw_tags.c | 16 ++++++++++++++++ mm/kasan/kasan.h | 12 ++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/test_kasan.c b/lib/test_kasan.c index 1328c468fdb5..e5647d147b35 100644 --- a/lib/test_kasan.c +++ b/lib/test_kasan.c @@ -53,13 +53,13 @@ static int kasan_test_init(struct kunit *test) } multishot = kasan_save_enable_multi_shot(); - hw_set_tagging_report_once(false); + kasan_set_tagging_report_once(false); return 0; } static void kasan_test_exit(struct kunit *test) { - hw_set_tagging_report_once(true); + kasan_set_tagging_report_once(true); kasan_restore_multi_shot(multishot); } @@ -97,7 +97,7 @@ static void kasan_test_exit(struct kunit *test) READ_ONCE(fail_data.report_found)); \ if (IS_ENABLED(CONFIG_KASAN_HW_TAGS)) { \ if (READ_ONCE(fail_data.report_found)) \ - hw_enable_tagging(); \ + kasan_enable_tagging(); \ migrate_enable(); \ } \ } while (0) diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index 1dfe4f62a89e..2aad21fda156 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -185,3 +185,19 @@ struct kasan_track *kasan_get_free_track(struct kmem_cache *cache, return &alloc_meta->free_track[0]; } + +#if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) + +void kasan_set_tagging_report_once(bool state) +{ + hw_set_tagging_report_once(state); +} +EXPORT_SYMBOL_GPL(kasan_set_tagging_report_once); + +void kasan_enable_tagging(void) +{ + hw_enable_tagging(); +} +EXPORT_SYMBOL_GPL(kasan_enable_tagging); + +#endif diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index cc787ba47e1b..3436c6bf7c0c 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -308,6 +308,18 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag) #endif /* CONFIG_KASAN_HW_TAGS */ +#if defined(CONFIG_KASAN_HW_TAGS) && IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) + +void kasan_set_tagging_report_once(bool state); +void kasan_enable_tagging(void); + +#else /* CONFIG_KASAN_HW_TAGS || CONFIG_KASAN_KUNIT_TEST */ + +static inline void kasan_set_tagging_report_once(bool state) { } +static inline void kasan_enable_tagging(void) { } + +#endif /* CONFIG_KASAN_HW_TAGS || CONFIG_KASAN_KUNIT_TEST */ + #ifdef CONFIG_KASAN_SW_TAGS u8 kasan_random_tag(void); #elif defined(CONFIG_KASAN_HW_TAGS)