From patchwork Fri Mar 10 23:43:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13170461 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 9FEB9C6FD19 for ; Fri, 10 Mar 2023 23:43:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1382D6B0081; Fri, 10 Mar 2023 18:43:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B6116B0080; Fri, 10 Mar 2023 18:43:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E987F6B007E; Fri, 10 Mar 2023 18:43:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id D6ABD6B007B for ; Fri, 10 Mar 2023 18:43:40 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 940C91405B6 for ; Fri, 10 Mar 2023 23:43:40 +0000 (UTC) X-FDA: 80554618200.15.D27BAB6 Received: from out-14.mta1.migadu.com (out-14.mta1.migadu.com [95.215.58.14]) by imf14.hostedemail.com (Postfix) with ESMTP id DB9DA10000D for ; Fri, 10 Mar 2023 23:43:38 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=UcgdJ+DJ; spf=pass (imf14.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.14 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678491819; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=z4DPZvfjlbyZR04Gs5VqWFFoeLvvcar/vhfVx7MEdnM=; b=q8rpT0qy7t6Lncn6IVBB8WRsQ/WeGSkgJ3FY0UrahkOayYwLO1v4hy/HRLg+Vhac/1VvvU DOAkOdHBXlgf58JWY7m7AwN6mikZmN4HWBi1Dt2LXnVVdg2Do3gNHo9Do4zkcSlL5dOqPj cXRQ2jjKopIa2xGtyEArhGDTvBYorsA= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=UcgdJ+DJ; spf=pass (imf14.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.14 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678491819; a=rsa-sha256; cv=none; b=A5+wY8qOKd3t7RVXwRJ5X6IU602PiF+nsu+2/qXx55usRoMbRZiuVERnfWEi7BlDN2S+uI 8XIovtPvDVlO+rsSVtOuGTET9PsyGgf1Nnb0BeRpEDkdAavRD9c0fDo+3+kaTYK3RZChWI UnJOrtgFYDtPWrXQhHW7ggiZh5x7D9I= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1678491816; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=z4DPZvfjlbyZR04Gs5VqWFFoeLvvcar/vhfVx7MEdnM=; b=UcgdJ+DJVo9GF+Ix3wnxINMhtX483ckxS9anY1bHh8fL0eGkNMCuKJlKj1RTT3X1QfHe15 dJeb+N+1TAdv+RZ72TIMdS+If3df0G/LVbGfso6arBItfon0IiusknaIiSUQ4M11FCoxJ8 yjSINLfD2aKPSvaVR6zUm3NXPTT/r9E= From: andrey.konovalov@linux.dev To: Marco Elver , Catalin Marinas Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Vincenzo Frascino , Will Deacon , linux-arm-kernel@lists.infradead.org, Peter Collingbourne , Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, Weizhao Ouyang , linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 1/5] kasan: drop empty tagging-related defines Date: Sat, 11 Mar 2023 00:43:29 +0100 Message-Id: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: DB9DA10000D X-Stat-Signature: 5op333qso8ezg9coh5qdrpxq9yu4nosw X-HE-Tag: 1678491818-175391 X-HE-Meta: U2FsdGVkX1/JJ6Bs1rPtLpfQpld0J1NlLBxWFTpUAyQW8hqQ+nJ3IWobEcAKmNHUr59G38N0PP5PSh7wRFxh+/Uc4nE2bcue9AAPRFHp9y4AaVMKOfZpZUhusRnTb/uWk8uKtBh7Khf1Q4/OgqAAaFVKwwaFIjAT2eLravdKINa1Z2nlzVtdxs788Q+ejQmGA7CK3s0clEFJn2oKPsFUnHjm+/3UkTyWIDvGhN+JbbW42NaM9A7qdNSnhPVjWmQu8+kKcL4/gaQ0dqOuckBSyRH1YODYISBhItGivzjiySyEBK/LCcoiglTFPBEqmO9SdaocV222sr1it7ZCxcYVQhdzBTJQqFIW7Ogl9pmSQ8MzcBz3bTyEA5UEqkqHU1ZsAkMCCUwnTlCCym4XoNvxjfDSC2LALLG4fvGVX2KOwszhjXPL0YjXANNoaMtyGDIoHQRH1UAdr9rsODPsbxObFEOU32OAoIsrA6nB/14I9XuofUXBbWax5W/304HUP7qtVgKlAhJVA+SvgATP4WApgaPKeSWQ0FNDN0R12MHQSPbFKY1IMBJwHJ9D70QJluT6aLx1LNaa7c/3E7CRt8cB53waKzgEKzqcCfBWTChefpTb3odlw5aN9cchx429D6TptPhirZ4BuMEyt4vy6vTuoxCJ6cY8cpwsL5ZJ/c1VPsOv3PWRlFVrFL8UsUZkWYYQfJ7nxepPf8TnMyinHZRx83N4bR9VA1HNv4B2yZ0OrXsLXbK2sFLA2eQCOcb1wEYDMASBXXzG5LdvIdJWK7XMLbMYBoSklJZtLeksRHuLyjILyIw6lLVCdYDpbq/TBkVv1MAgJPHnVIzXwiwEMDNNJFq4rPGtqGk6DTZuN5BkkiBWm5bmVB1Bfp3G1+j83G7M1lwhh/tjFC0Mh9cBPMjTWqdGfeUSfkdab+GkoYoR4BeDbqWuaZXbA/auRR2gOY54np8oJ/MvU9KzMUBhIVn hi1oSx5K NuvhMYrHRsn9hYHZIMiMwkeAVcxPth2bU47jr0ElSl4yYlhy9SuT7erIM9RM234Hh8MZz6KxIiT1O83QDSv4MQaY8GiWbiTk6T2gnngRa397obDeI2OOfFt7twSpdadjiYBDVoQxMthUCpQkKb46sSAVn5dNmXON6p24fywsH/p4exvIwVYW9tcx8vg3RTiAIRoMd 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: From: Andrey Konovalov mm/kasan/kasan.h provides a number of empty defines for a few arch-specific tagging-related routines, in case the architecture code didn't define them. The original idea was to simplify integration in case another architecture starts supporting memory tagging. However, right now, if any of those routines are not provided by an architecture, Hardware Tag-Based KASAN won't work. Drop the empty defines, as it would be better to get compiler errors rather than runtime crashes when adding support for a new architecture. Also drop empty hw_enable_tagging_sync/async/asymm defines for !CONFIG_KASAN_HW_TAGS case, as those are only used in mm/kasan/hw_tags.c. Signed-off-by: Andrey Konovalov --- mm/kasan/kasan.h | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index a61eeee3095a..b1895526d02f 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -395,28 +395,6 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag) #ifdef CONFIG_KASAN_HW_TAGS -#ifndef arch_enable_tagging_sync -#define arch_enable_tagging_sync() -#endif -#ifndef arch_enable_tagging_async -#define arch_enable_tagging_async() -#endif -#ifndef arch_enable_tagging_asymm -#define arch_enable_tagging_asymm() -#endif -#ifndef arch_force_async_tag_fault -#define arch_force_async_tag_fault() -#endif -#ifndef arch_get_random_tag -#define arch_get_random_tag() (0xFF) -#endif -#ifndef arch_get_mem_tag -#define arch_get_mem_tag(addr) (0xFF) -#endif -#ifndef arch_set_mem_tag_range -#define arch_set_mem_tag_range(addr, size, tag, init) ((void *)(addr)) -#endif - #define hw_enable_tagging_sync() arch_enable_tagging_sync() #define hw_enable_tagging_async() arch_enable_tagging_async() #define hw_enable_tagging_asymm() arch_enable_tagging_asymm() @@ -430,10 +408,6 @@ void kasan_enable_tagging(void); #else /* CONFIG_KASAN_HW_TAGS */ -#define hw_enable_tagging_sync() -#define hw_enable_tagging_async() -#define hw_enable_tagging_asymm() - static inline void kasan_enable_tagging(void) { } #endif /* CONFIG_KASAN_HW_TAGS */ From patchwork Fri Mar 10 23:43:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13170460 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 1D3DAC6FA99 for ; Fri, 10 Mar 2023 23:43:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 412716B007B; Fri, 10 Mar 2023 18:43:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3CB508E0001; Fri, 10 Mar 2023 18:43:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 129C06B007D; Fri, 10 Mar 2023 18:43:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id F32716B007B for ; Fri, 10 Mar 2023 18:43:40 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D1BCC140609 for ; Fri, 10 Mar 2023 23:43:40 +0000 (UTC) X-FDA: 80554618200.14.BA18799 Received: from out-4.mta1.migadu.com (out-4.mta1.migadu.com [95.215.58.4]) by imf15.hostedemail.com (Postfix) with ESMTP id 1A2DBA0004 for ; Fri, 10 Mar 2023 23:43:38 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=irItE+Jg; spf=pass (imf15.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.4 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678491819; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=FR0GMMMnNdReMCefH2++iHzkAdqxWWuGhtNaRaBked8=; b=qkf26NIsLmv+yitdCS9a59iQJM7M6r30yvwXGhdyJ7MsEuoitPHwts9YXxQft3NmB+rT4H dZ3KU0d6/AfJlSibj5KrRgH6XgR5ZrUkaDB80GxTbMvRYpHDjwBCxHc0rjiJDq+cLnnyRc +RaWQyz6VBkyDG9X+mFgd5kBtIsviTs= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=irItE+Jg; spf=pass (imf15.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.4 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678491819; a=rsa-sha256; cv=none; b=mTtg6ES/e0ObhXF54V89Rfa1selWmNoWne/n0fbS+4jNNJJ2Wzm64FTR00nT6QDwErn5iF n6kNMrJPQ5mFTvOCTuTUlkewEA4xStWEN90s+XQyMoyRuX2IFAwkvrojylBkEHjZG80RYH gnF0SDbXpXlkoa+WBBwA09f/iC/IUps= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1678491817; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FR0GMMMnNdReMCefH2++iHzkAdqxWWuGhtNaRaBked8=; b=irItE+Jgfq84/wI+LBBhF478xDum91DlaJ3tXbxceNY1XuIeNE7SUeo192nrF/ADVo32Nv Mj/JU3ixWvLjBranQUiClYjvymP9MlGX94edM0Nqg2NpmEY1d0xzpdJW3KDOTg+t03LIw+ xlYUVAF+y/E5u7z5X5p0iduduPtLIuY= From: andrey.konovalov@linux.dev To: Marco Elver , Catalin Marinas Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Vincenzo Frascino , Will Deacon , linux-arm-kernel@lists.infradead.org, Peter Collingbourne , Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, Weizhao Ouyang , linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 2/5] kasan, arm64: rename tagging-related routines Date: Sat, 11 Mar 2023 00:43:30 +0100 Message-Id: <069ef5b77715c1ac8d69b186725576c32b149491.1678491668.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 1A2DBA0004 X-Stat-Signature: jahbi5xfn3864os5ikrg4cgcsk3eqqyd X-Rspam-User: X-HE-Tag: 1678491818-199870 X-HE-Meta: U2FsdGVkX18lsh6GqfVNKUMMev71RMDsazA4BIl+gZhFUES9ZL1awYyD5vsGfTfqDiqhEpgRZi67qU6cHymh38cW0lKC8df2ifDsTHpn1MA2z4vzJxXgtlHlV2aUbUwud+EPaNCyd8Xc9ZwVrW0IbMr4xfGT7iGkrkgHYb+aJgdp+wNTMYOr0bgxI/TEs61PvEaEh63Q/CBuvs6HaPvVf/UqnoyEaOzVuVCLf4+FkC8CLxJnfqma43vbpW6GxZAyj81n9xM3M6jd6LxbtIsLeBpyNCF/CLPSfLtJ1KnuA2NARy9kw7kAMvAl03m1CRjRxTaYn2OfkbC9qM50m7hvPkZyr0K/udOIWXbeyRTvPPVhzhVTvkTvfpbj49S9PXwfROV+NsZ064oDlB8paHJavqae0dN13OLLVypvHb9hPIH0ccjlRueSS4KSyWpILHV7APwyHMf7WWKwzl6Tq/DU5iKFmx2TWQCKDKmHRiH+3qUJ0QTpEd+9H0npku16p7k+VWm+ENFciiAL/xSx2FYWPFthmV8uhDRZ0+Q7wWXBr6Ud1+JwZ748iaAq85GJBefEHf0EqtWCD3zkevgdhNsVNc6m6Du2P7BpiOnOBPxhRq+wNYgiFJDI5ecolFTvVk6p96yy17UNXxWIplEC6pR43LgEoL5tYTxYE0bECJCoJMIBQaMUEUXHJVlnRE2m3dkcjlr4kVbe6w76DAlb9WbKJ11IKZz2Nirb+guX4rxodA1P0AsXF8Z/3BsAefpjj28g1vwScsQm8Pv+IWzvDLZUtebsJjsRJGCqjaLy1AeVc1HGk30qeGqc+IFH7EX8RKz03qjW0SVUXSa39GdukBS2EHWubTGSRJNiA2ksRey6EuLgg5ukmnMKfJKo3heYwv5Soj0TdUofR19g6A/ZSDHiqAGVAEY/fuwAVpv0Royy6t0KlC1QABOAVwzJCUNI2b7jzB3/kxmIFJzpMFe/3zr pQUnMkyG IpYyjWOxKaApw9J3LCFpLg0/rgaUYXK8RRjTO7f+E2VSXtqxS5fQcj46uYZxgF4ea31q7kX3m8MyKT25rPa/VLFc2LlK4PdQWUi5tU37AyxRXlZdGZ7tzu3Iu9dvZ8eUK3Elq8n4Rt90u8NWeYc9k13a2F60SFMNV9WQlJ45lvlgVlID9j2W2r3K2O53v7bYRDOCA 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: From: Andrey Konovalov Rename arch_enable_tagging_sync/async/asymm to arch_enable_tag_checks_sync/async/asymm, as the new name better reflects their function. Also rename kasan_enable_tagging to kasan_enable_hw_tags for the same reason. Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/memory.h | 6 +++--- mm/kasan/hw_tags.c | 12 ++++++------ mm/kasan/kasan.h | 10 +++++----- mm/kasan/kasan_test.c | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index 78e5163836a0..faf42bff9a60 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -261,9 +261,9 @@ static inline const void *__tag_set(const void *addr, u8 tag) } #ifdef CONFIG_KASAN_HW_TAGS -#define arch_enable_tagging_sync() mte_enable_kernel_sync() -#define arch_enable_tagging_async() mte_enable_kernel_async() -#define arch_enable_tagging_asymm() mte_enable_kernel_asymm() +#define arch_enable_tag_checks_sync() mte_enable_kernel_sync() +#define arch_enable_tag_checks_async() mte_enable_kernel_async() +#define arch_enable_tag_checks_asymm() mte_enable_kernel_asymm() #define arch_force_async_tag_fault() mte_check_tfsr_exit() #define arch_get_random_tag() mte_get_random_tag() #define arch_get_mem_tag(addr) mte_get_mem_tag(addr) diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index d1bcb0205327..b092e37b69a7 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -205,7 +205,7 @@ void kasan_init_hw_tags_cpu(void) * Enable async or asymm modes only when explicitly requested * through the command line. */ - kasan_enable_tagging(); + kasan_enable_hw_tags(); } /* kasan_init_hw_tags() is called once on boot CPU. */ @@ -373,19 +373,19 @@ void __kasan_poison_vmalloc(const void *start, unsigned long size) #endif -void kasan_enable_tagging(void) +void kasan_enable_hw_tags(void) { if (kasan_arg_mode == KASAN_ARG_MODE_ASYNC) - hw_enable_tagging_async(); + hw_enable_tag_checks_async(); else if (kasan_arg_mode == KASAN_ARG_MODE_ASYMM) - hw_enable_tagging_asymm(); + hw_enable_tag_checks_asymm(); else - hw_enable_tagging_sync(); + hw_enable_tag_checks_sync(); } #if IS_ENABLED(CONFIG_KASAN_KUNIT_TEST) -EXPORT_SYMBOL_GPL(kasan_enable_tagging); +EXPORT_SYMBOL_GPL(kasan_enable_hw_tags); void kasan_force_async_fault(void) { diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index b1895526d02f..a1613f5d7608 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -395,20 +395,20 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag) #ifdef CONFIG_KASAN_HW_TAGS -#define hw_enable_tagging_sync() arch_enable_tagging_sync() -#define hw_enable_tagging_async() arch_enable_tagging_async() -#define hw_enable_tagging_asymm() arch_enable_tagging_asymm() +#define hw_enable_tag_checks_sync() arch_enable_tag_checks_sync() +#define hw_enable_tag_checks_async() arch_enable_tag_checks_async() +#define hw_enable_tag_checks_asymm() arch_enable_tag_checks_asymm() #define hw_force_async_tag_fault() arch_force_async_tag_fault() #define hw_get_random_tag() arch_get_random_tag() #define hw_get_mem_tag(addr) arch_get_mem_tag(addr) #define hw_set_mem_tag_range(addr, size, tag, init) \ arch_set_mem_tag_range((addr), (size), (tag), (init)) -void kasan_enable_tagging(void); +void kasan_enable_hw_tags(void); #else /* CONFIG_KASAN_HW_TAGS */ -static inline void kasan_enable_tagging(void) { } +static inline void kasan_enable_hw_tags(void) { } #endif /* CONFIG_KASAN_HW_TAGS */ diff --git a/mm/kasan/kasan_test.c b/mm/kasan/kasan_test.c index 627eaf1ee1db..a375776f9896 100644 --- a/mm/kasan/kasan_test.c +++ b/mm/kasan/kasan_test.c @@ -148,7 +148,7 @@ static void kasan_test_exit(struct kunit *test) kasan_sync_fault_possible()) { \ if (READ_ONCE(test_status.report_found) && \ !READ_ONCE(test_status.async_fault)) \ - kasan_enable_tagging(); \ + kasan_enable_hw_tags(); \ migrate_enable(); \ } \ WRITE_ONCE(test_status.report_found, false); \ From patchwork Fri Mar 10 23:43:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13170462 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 BA68CC6FD1E for ; Fri, 10 Mar 2023 23:43:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6ADF36B007D; Fri, 10 Mar 2023 18:43:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 60DF96B007E; Fri, 10 Mar 2023 18:43:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 375FA8E0001; Fri, 10 Mar 2023 18:43:42 -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 1B76A6B007D for ; Fri, 10 Mar 2023 18:43:42 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E56C416058E for ; Fri, 10 Mar 2023 23:43:41 +0000 (UTC) X-FDA: 80554618242.07.E602368 Received: from out-55.mta1.migadu.com (out-55.mta1.migadu.com [95.215.58.55]) by imf07.hostedemail.com (Postfix) with ESMTP id 26B1540007 for ; Fri, 10 Mar 2023 23:43:39 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=URqlLtgK; spf=pass (imf07.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.55 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678491820; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5f47haFm6GLuf5I4IFtda8n0nMYkg8PQuTGiJh6Xcxk=; b=CyX//2rDOdKnn2q9r6dVdpSvWbDz+uR3sffzwv0lWI5wABaAeu7ZPRarnhXkYYeq34dfCF 5KKjp3tZ5b5IQNnoS47qIDjOh+hJ+oHBw6BS7MPB5oUkVOAD/wbdvyJ1Zfo7KLHomwRYf5 bSZqC59DKfM3Q6JHnL76jGBjlEipyDE= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=URqlLtgK; spf=pass (imf07.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.55 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678491820; a=rsa-sha256; cv=none; b=qwTnkGrF95ADbrsAx/2bHVTaXM72c+WakDn+sN0LFnOq7NChzp003mcTR9wJnVqFWWzwJ8 SRYiOIxEn+IgD9t6bXhVsslPXEajOJKIH3rDQ0l8x86wU0v8MmyYD4f8iQxKnbNGw6NJxA Qry6Sjsaim46nLJigaDe/sP33+KhcHI= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1678491818; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5f47haFm6GLuf5I4IFtda8n0nMYkg8PQuTGiJh6Xcxk=; b=URqlLtgKtU7wqK7xBS5bHeBjr5WwiRhdfPc1Ni8WyBWgvDmqcg2ttmYkrD3GdrN9sXpN2J wM71OGgI8pZ6UzoDkj/XU+xHSacBCAsfPqITXW0T8DyVBxBffrAP2wy4F8A3BrNOaU3Agl rurVoXkIzHjjg9W+nDSjPgFMWC161L8= From: andrey.konovalov@linux.dev To: Marco Elver , Catalin Marinas Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Vincenzo Frascino , Will Deacon , linux-arm-kernel@lists.infradead.org, Peter Collingbourne , Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, Weizhao Ouyang , linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 3/5] arm64: mte: Rename TCO routines Date: Sat, 11 Mar 2023 00:43:31 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 26B1540007 X-Rspam-User: X-Stat-Signature: jbanuiy1xm6e5gx4a7tsir51trgu873x X-HE-Tag: 1678491819-335426 X-HE-Meta: U2FsdGVkX19N1n0/1Ag0EvEKYB7DGUt1jLn+I+4FdiI+F+CqVlPfSqFInPKbU7pU0jtwwqIC+eJXAjEh7nNhEu8XH/Ie97Ex3o5LToB4tfMDmz0x0p+kfFMlVzGRNYO0M2sq4CrzTSjdNfNNVZcchujBZ+nCjPpRbH6qBsbZGL9XRyjBf+4WJTnaeKeVDC+nWHXIwQW6YmxPgmonkLWsVzlGX6RYoYJIcXYFhjuUEVR6zxLObHUtwHCTUED/aw0etg0MdYrZBlmvDfcOSIjRr7ALI//z+lKsjK4IVemBdtomo1fmo0l5ajdWmJqXidcqbqaTMiV+KXEhtihZucMuExU7SBtmcGFIg2uEpnICym2+IYPnkpmZcoyQ9x2G7qsRfi6oP660tLHAq96dTHlSGQew0Y+7VKB2Dq53JIICmLOux9sQNN6S6OppQhRwhBzDw4b/UDEn5nEbNnwb+l4bGQizdBk/HxdzjZ6EvoLEzj/sqRQUs5SHYjCK9GEVsEGtNRaC+zoVNGmutFIqeoYKjlXa4eROh20CvStP+PvaNrAHRXi+PJUOynw6NDgcLx5//T/KNoHU5x9lhNZYT8MN+sVWsIvKiP+XioXcfsAGv8LBqACHQYvTLa+lDaiKTEIPRJIBXjCqFxErV3Vn6ubjfauaA7/PPn8Yiptou2LJwOPE8i99De5cB+yFmPpNXxvwQrmDW/O1RfWeRsoLeV9ZfyDxLcZvctL6FWJDNJh/o5tOe4yX2j2HfKyk5qxcjH5AkvWRInOkSnQYda5w+DVLd+q32yv4UJT+VacMlc2d2b1hRkGPIhuze0Y2fNSovlrmuC3SjovQoIxvllSI3TT26Hn3Hm5i2tD0UJpVGvb0FZz9h6R4+itKizaiXIjAr62BccRk1d6ka+t20fg38JWwLXWlrIloKV+wXl9UpeXMJa6LBVt3lSPY79CxQN+c2Q/0OSlphdJCFAAWLP7lLoy 9KaMQKHt 524pW+J4hc12ocvhIG0ED1QDWZda810MfFYo//pm7VKZQjnyH2Br3uvBjAj1qPXVQc+oslI6SnNci18TcKEuDbGiZ/BoNrD3vuJPfzCs4eWM0Waki6LUTWrBRXJnsHDmpTIQ/aX1pd0V2KZYoToXc9qWOoUCGH9oKUlP4GlvDG1DWTd9Oa/6nqpfSWC75esOSiVyiUV/gSHWUrHnWEJCshSnujrCAlu1BctzU2my63yOVqeHwdStVAw6xW7PIVwnIaK+6/CkxtWyHrWdHFLJ+Ps6/ZXWj3kPNADNFZoqVwh0N0P6+QXSYu9cPPg== 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: From: Vincenzo Frascino The TCO related routines are used in uaccess methods and load_unaligned_zeropad() but are unrelated to both even if the naming suggest otherwise. Improve the readability of the code moving the away from uaccess.h and pre-pending them with "mte". Cc: Will Deacon Signed-off-by: Vincenzo Frascino Signed-off-by: Catalin Marinas Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/mte-kasan.h | 81 +++++++++++++++++++++++++ arch/arm64/include/asm/mte.h | 12 ---- arch/arm64/include/asm/uaccess.h | 66 +++----------------- arch/arm64/include/asm/word-at-a-time.h | 4 +- 4 files changed, 93 insertions(+), 70 deletions(-) diff --git a/arch/arm64/include/asm/mte-kasan.h b/arch/arm64/include/asm/mte-kasan.h index 9f79425fc65a..cc9e74876e9a 100644 --- a/arch/arm64/include/asm/mte-kasan.h +++ b/arch/arm64/include/asm/mte-kasan.h @@ -13,8 +13,73 @@ #include +#ifdef CONFIG_KASAN_HW_TAGS + +/* Whether the MTE asynchronous mode is enabled. */ +DECLARE_STATIC_KEY_FALSE(mte_async_or_asymm_mode); + +static inline bool system_uses_mte_async_or_asymm_mode(void) +{ + return static_branch_unlikely(&mte_async_or_asymm_mode); +} + +#else /* CONFIG_KASAN_HW_TAGS */ + +static inline bool system_uses_mte_async_or_asymm_mode(void) +{ + return false; +} + +#endif /* CONFIG_KASAN_HW_TAGS */ + #ifdef CONFIG_ARM64_MTE +/* + * The Tag Check Flag (TCF) mode for MTE is per EL, hence TCF0 + * affects EL0 and TCF affects EL1 irrespective of which TTBR is + * used. + * The kernel accesses TTBR0 usually with LDTR/STTR instructions + * when UAO is available, so these would act as EL0 accesses using + * TCF0. + * However futex.h code uses exclusives which would be executed as + * EL1, this can potentially cause a tag check fault even if the + * user disables TCF0. + * + * To address the problem we set the PSTATE.TCO bit in uaccess_enable() + * and reset it in uaccess_disable(). + * + * The Tag check override (TCO) bit disables temporarily the tag checking + * preventing the issue. + */ +static inline void __mte_disable_tco(void) +{ + asm volatile(ALTERNATIVE("nop", SET_PSTATE_TCO(0), + ARM64_MTE, CONFIG_KASAN_HW_TAGS)); +} + +static inline void __mte_enable_tco(void) +{ + asm volatile(ALTERNATIVE("nop", SET_PSTATE_TCO(1), + ARM64_MTE, CONFIG_KASAN_HW_TAGS)); +} + +/* + * These functions disable tag checking only if in MTE async mode + * since the sync mode generates exceptions synchronously and the + * nofault or load_unaligned_zeropad can handle them. + */ +static inline void __mte_disable_tco_async(void) +{ + if (system_uses_mte_async_or_asymm_mode()) + __mte_disable_tco(); +} + +static inline void __mte_enable_tco_async(void) +{ + if (system_uses_mte_async_or_asymm_mode()) + __mte_enable_tco(); +} + /* * These functions are meant to be only used from KASAN runtime through * the arch_*() interface defined in asm/memory.h. @@ -138,6 +203,22 @@ void mte_enable_kernel_asymm(void); #else /* CONFIG_ARM64_MTE */ +static inline void __mte_disable_tco(void) +{ +} + +static inline void __mte_enable_tco(void) +{ +} + +static inline void __mte_disable_tco_async(void) +{ +} + +static inline void __mte_enable_tco_async(void) +{ +} + static inline u8 mte_get_ptr_tag(void *ptr) { return 0xFF; diff --git a/arch/arm64/include/asm/mte.h b/arch/arm64/include/asm/mte.h index 20dd06d70af5..c028afb1cd0b 100644 --- a/arch/arm64/include/asm/mte.h +++ b/arch/arm64/include/asm/mte.h @@ -178,14 +178,6 @@ static inline void mte_disable_tco_entry(struct task_struct *task) } #ifdef CONFIG_KASAN_HW_TAGS -/* Whether the MTE asynchronous mode is enabled. */ -DECLARE_STATIC_KEY_FALSE(mte_async_or_asymm_mode); - -static inline bool system_uses_mte_async_or_asymm_mode(void) -{ - return static_branch_unlikely(&mte_async_or_asymm_mode); -} - void mte_check_tfsr_el1(void); static inline void mte_check_tfsr_entry(void) @@ -212,10 +204,6 @@ static inline void mte_check_tfsr_exit(void) mte_check_tfsr_el1(); } #else -static inline bool system_uses_mte_async_or_asymm_mode(void) -{ - return false; -} static inline void mte_check_tfsr_el1(void) { } diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 5c7b2f9d5913..057ec1882326 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -136,55 +136,9 @@ static inline void __uaccess_enable_hw_pan(void) CONFIG_ARM64_PAN)); } -/* - * The Tag Check Flag (TCF) mode for MTE is per EL, hence TCF0 - * affects EL0 and TCF affects EL1 irrespective of which TTBR is - * used. - * The kernel accesses TTBR0 usually with LDTR/STTR instructions - * when UAO is available, so these would act as EL0 accesses using - * TCF0. - * However futex.h code uses exclusives which would be executed as - * EL1, this can potentially cause a tag check fault even if the - * user disables TCF0. - * - * To address the problem we set the PSTATE.TCO bit in uaccess_enable() - * and reset it in uaccess_disable(). - * - * The Tag check override (TCO) bit disables temporarily the tag checking - * preventing the issue. - */ -static inline void __uaccess_disable_tco(void) -{ - asm volatile(ALTERNATIVE("nop", SET_PSTATE_TCO(0), - ARM64_MTE, CONFIG_KASAN_HW_TAGS)); -} - -static inline void __uaccess_enable_tco(void) -{ - asm volatile(ALTERNATIVE("nop", SET_PSTATE_TCO(1), - ARM64_MTE, CONFIG_KASAN_HW_TAGS)); -} - -/* - * These functions disable tag checking only if in MTE async mode - * since the sync mode generates exceptions synchronously and the - * nofault or load_unaligned_zeropad can handle them. - */ -static inline void __uaccess_disable_tco_async(void) -{ - if (system_uses_mte_async_or_asymm_mode()) - __uaccess_disable_tco(); -} - -static inline void __uaccess_enable_tco_async(void) -{ - if (system_uses_mte_async_or_asymm_mode()) - __uaccess_enable_tco(); -} - static inline void uaccess_disable_privileged(void) { - __uaccess_disable_tco(); + __mte_disable_tco(); if (uaccess_ttbr0_disable()) return; @@ -194,7 +148,7 @@ static inline void uaccess_disable_privileged(void) static inline void uaccess_enable_privileged(void) { - __uaccess_enable_tco(); + __mte_enable_tco(); if (uaccess_ttbr0_enable()) return; @@ -302,8 +256,8 @@ do { \ #define get_user __get_user /* - * We must not call into the scheduler between __uaccess_enable_tco_async() and - * __uaccess_disable_tco_async(). As `dst` and `src` may contain blocking + * We must not call into the scheduler between __mte_enable_tco_async() and + * __mte_disable_tco_async(). As `dst` and `src` may contain blocking * functions, we must evaluate these outside of the critical section. */ #define __get_kernel_nofault(dst, src, type, err_label) \ @@ -312,10 +266,10 @@ do { \ __typeof__(src) __gkn_src = (src); \ int __gkn_err = 0; \ \ - __uaccess_enable_tco_async(); \ + __mte_enable_tco_async(); \ __raw_get_mem("ldr", *((type *)(__gkn_dst)), \ (__force type *)(__gkn_src), __gkn_err, K); \ - __uaccess_disable_tco_async(); \ + __mte_disable_tco_async(); \ \ if (unlikely(__gkn_err)) \ goto err_label; \ @@ -388,8 +342,8 @@ do { \ #define put_user __put_user /* - * We must not call into the scheduler between __uaccess_enable_tco_async() and - * __uaccess_disable_tco_async(). As `dst` and `src` may contain blocking + * We must not call into the scheduler between __mte_enable_tco_async() and + * __mte_disable_tco_async(). As `dst` and `src` may contain blocking * functions, we must evaluate these outside of the critical section. */ #define __put_kernel_nofault(dst, src, type, err_label) \ @@ -398,10 +352,10 @@ do { \ __typeof__(src) __pkn_src = (src); \ int __pkn_err = 0; \ \ - __uaccess_enable_tco_async(); \ + __mte_enable_tco_async(); \ __raw_put_mem("str", *((type *)(__pkn_src)), \ (__force type *)(__pkn_dst), __pkn_err, K); \ - __uaccess_disable_tco_async(); \ + __mte_disable_tco_async(); \ \ if (unlikely(__pkn_err)) \ goto err_label; \ diff --git a/arch/arm64/include/asm/word-at-a-time.h b/arch/arm64/include/asm/word-at-a-time.h index 1c8e4f2490bf..f3b151ed0d7a 100644 --- a/arch/arm64/include/asm/word-at-a-time.h +++ b/arch/arm64/include/asm/word-at-a-time.h @@ -55,7 +55,7 @@ static inline unsigned long load_unaligned_zeropad(const void *addr) { unsigned long ret; - __uaccess_enable_tco_async(); + __mte_enable_tco_async(); /* Load word from unaligned pointer addr */ asm( @@ -65,7 +65,7 @@ static inline unsigned long load_unaligned_zeropad(const void *addr) : "=&r" (ret) : "r" (addr), "Q" (*(unsigned long *)addr)); - __uaccess_disable_tco_async(); + __mte_disable_tco_async(); return ret; } From patchwork Fri Mar 10 23:43:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13170463 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 54F78C74A4B for ; Fri, 10 Mar 2023 23:43:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 218816B007E; Fri, 10 Mar 2023 18:43:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 19FBB8E0001; Fri, 10 Mar 2023 18:43:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EBF686B0082; Fri, 10 Mar 2023 18:43:42 -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 CF11C6B007E for ; Fri, 10 Mar 2023 18:43:42 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A3222AAF0F for ; Fri, 10 Mar 2023 23:43:42 +0000 (UTC) X-FDA: 80554618284.04.94D4E90 Received: from out-48.mta1.migadu.com (out-48.mta1.migadu.com [95.215.58.48]) by imf02.hostedemail.com (Postfix) with ESMTP id 032ED80005 for ; Fri, 10 Mar 2023 23:43:40 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=KexIs4rR; spf=pass (imf02.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.48 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678491821; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oDcuLSEdW7dG92xT5iE2ytpvV+VW7Ad9krPNXrfRPwk=; b=4GKqnM/cpKeDYWwS8u0K+HLLYaSaVE55WZ72EezQmggSlrMzFdzYvlmM9x/Ab0G/juvQCl UyAzoQrHlLIWeSZes86iT0U5c4d2IbSpGtwI9AqdMIur1r/Rk6kBpQtsRtOBUVrT51aL/g v13X7Yha9MBwnDUoMq9/oBY/Wep9e5g= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=KexIs4rR; spf=pass (imf02.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.48 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678491821; a=rsa-sha256; cv=none; b=f9Wik6krqxTnYpI/vnuEgjOt0/mCpoq0Nf8GJ/KUAQM5pv9ux0tfjRwnOJXhtDd8LzI761 0MicNKfnLrcfSKAc7cm3tg+NSC61mPw9WjYQ4B9ewgF/HM5fDdTFjpAnXY1Z8VWP34Ylkz 1AMlQxwAWs0l2vD/jrscfFvlaFaZ8XM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1678491819; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oDcuLSEdW7dG92xT5iE2ytpvV+VW7Ad9krPNXrfRPwk=; b=KexIs4rR+UsVNXfzaoUthnE4Zbw7zg7FNPT1gxekp2AoL8vszqK4xiGhWr5TmHD2jr8GWb BcXN/UzGm+jLdtXRx5SulvVCeqYlSYgPb2IMtufbXS+i6OtCgvmlZON6FPzRzs7b1SLvyI KHBEnNEQalESu+M+IiALcpwFpnj1LG4= From: andrey.konovalov@linux.dev To: Marco Elver , Catalin Marinas Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Vincenzo Frascino , Will Deacon , linux-arm-kernel@lists.infradead.org, Peter Collingbourne , Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, Weizhao Ouyang , linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 4/5] kasan, arm64: add arch_suppress_tag_checks_start/stop Date: Sat, 11 Mar 2023 00:43:32 +0100 Message-Id: <75a362551c3c54b70ae59a3492cabb51c105fa6b.1678491668.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 032ED80005 X-Stat-Signature: 4ejunxrajoejdfpy9cxb5q684t8m5ddm X-HE-Tag: 1678491820-287188 X-HE-Meta: U2FsdGVkX18qX2uku28r10dkFF2Zner6rTgSr7xo3YyzZMA1y5hkb9WIimh6ad4NbV18ngh+yUpvMAZUAsVw1OObrLX6xO9uNwTEN6C901N9cc3y1rGAo8F6+DRq7VospZZuGCuDm5jvKl4u9+DcGYYp5IJKGU8exJ6MATBwowa1Fjdr8Bb6TtJ4BRqThJ3GLzs+CVgKgih+rx0hdrk932x7HIiDoprdF+5cc/lcP3TH0UuDJgNqFGW26agZczicxgPmuv49DRGjHVGuQ4WOhjCQnUMye57y8YLdmoR89DupddWmJSeAtRKmbqf7mnsw45Uye4IzTddfPv7g/EwRPQygbiXchsGSDKG56pX3hcPOujpJYOkHNdlB0/PSyzPeDdgTgSqyZ/hb0QVvCxQffgAbuuWPy4d5t4xmIWj0e7JHlNgikMFB69Ezrk93sVt8iP8sBNUUR0g2YrCBO+5NKgp8B07Byvozzh56elCaNeErG49uvKEp2LmWi5G4kFLe/StSrpMPO/w3PJ8UvcSzQzZp7rZ3sDzfW6f/m6mZXLundL3HYlJf2sKfK8M6VDiNIlhUkUEZi1/kF/VOoS1qwP/g0Cm/ZUnisLwaproOT+74xlNpSqVNLYjo80/Y545/DoKF0i2olC8MIKGxEJyzWKy6nHZE10stYJC9rKpgjuWGpVo8Y4ZQROT9W152EGkZjSNhVyWEDCq/qH2XAlI3r4c/0hD7qPClfx3mbcMmBHl0xpzp4Q4RGlnWkpJtJswkZEWAtVgfdCZpB+mt9hGoyT8VVOJg3MlDbOLF3zozUUExMC4+h2y08i8nyEfBnDTUhH3ZutGLFEkXAmMX3vPT5XPQwRIVdbN7p9F7q8ee7P+c2rtvmOZ0r7P2s7Qg4vArDsFQyVytwNGzmy+5/Fnp3WMwFq+wVV+Ir0ZmRWyTDd6VdNCFBGAi3QYsVLo5HPBE2LRfjLHDUNmrOvSymEL gTHG4m0a ycel0DGhz9NxwdOBPq5TE0huAKmYn1F12j6vq8DIPH4stFQiMC+pZlEZeG6/2OpxoLGCiG/Gsfm37V5QK2IHhgwuWUlpXYf59AlhCzdaz/t1FvZe9Er+PtE3S83Su38/7FdxrqLQYu77La/bqY5ejBZVjfsNeNdxiiWLL0YcbVzRM0qqFAiTFXu/8nAwuj4RGthkTgjwnxOH+3bJULARi1lZcgwmhPNMySqJz1cmP7CAAZyg= 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: From: Andrey Konovalov Add two new tagging-related routines arch_suppress_tag_checks_start/stop that suppress MTE tag checking via the TCO register. These rouines are used in the next patch. Signed-off-by: Andrey Konovalov --- arch/arm64/include/asm/memory.h | 2 ++ mm/kasan/kasan.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index faf42bff9a60..26bd4d9aa401 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -264,6 +264,8 @@ static inline const void *__tag_set(const void *addr, u8 tag) #define arch_enable_tag_checks_sync() mte_enable_kernel_sync() #define arch_enable_tag_checks_async() mte_enable_kernel_async() #define arch_enable_tag_checks_asymm() mte_enable_kernel_asymm() +#define arch_suppress_tag_checks_start() __mte_enable_tco() +#define arch_suppress_tag_checks_stop() __mte_disable_tco() #define arch_force_async_tag_fault() mte_check_tfsr_exit() #define arch_get_random_tag() mte_get_random_tag() #define arch_get_mem_tag(addr) mte_get_mem_tag(addr) diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index a1613f5d7608..f5e4f5f2ba20 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -398,6 +398,8 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag) #define hw_enable_tag_checks_sync() arch_enable_tag_checks_sync() #define hw_enable_tag_checks_async() arch_enable_tag_checks_async() #define hw_enable_tag_checks_asymm() arch_enable_tag_checks_asymm() +#define hw_suppress_tag_checks_start() arch_suppress_tag_checks_start() +#define hw_suppress_tag_checks_stop() arch_suppress_tag_checks_stop() #define hw_force_async_tag_fault() arch_force_async_tag_fault() #define hw_get_random_tag() arch_get_random_tag() #define hw_get_mem_tag(addr) arch_get_mem_tag(addr) From patchwork Fri Mar 10 23:43:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13170464 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 B3825C74A5B for ; Fri, 10 Mar 2023 23:43:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4D79D6B0080; Fri, 10 Mar 2023 18:43:44 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 41CD76B0082; Fri, 10 Mar 2023 18:43:44 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CA8D6B0083; Fri, 10 Mar 2023 18:43:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E40BA6B0080 for ; Fri, 10 Mar 2023 18:43:43 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id BC3221204DF for ; Fri, 10 Mar 2023 23:43:43 +0000 (UTC) X-FDA: 80554618326.30.CFB916E Received: from out-41.mta1.migadu.com (out-41.mta1.migadu.com [95.215.58.41]) by imf03.hostedemail.com (Postfix) with ESMTP id 1188820004 for ; Fri, 10 Mar 2023 23:43:41 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=qTe147Js; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf03.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.41 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1678491822; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SSBGLO0ZKcc5jSLq3xLNP5yCcA0qlKOn3pEju7Cd7ZE=; b=Pf7+rApRHEO2V7PzgDxF6Nfi6vIyrZhmH0F/X1rPTD1PHSNZnMjGOwLCMskb90V5l9NbiV vdNKV9aAAG8+yHq5dUumn20I5mHEWscUaVXgulbVIWVWuFmTnL33I6sCen1tXE0/I4b9AB rUWeB4c85mZIT3M1fTeNFQ7TFNbP7pA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=qTe147Js; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf03.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.41 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1678491822; a=rsa-sha256; cv=none; b=PgJesF1QS7wVOrSiHEgr4+WuoA3T0gmJT63dcODvHqfpxC7J/Ev/6uaQv6zsCqIHMsE3pE WyXjrcWbTeBrTTKfLIq8TYsa5k+Rzt9+dXO+hL6hJYP7T33fhPMValReDGnRZam+m8vRtV fDu4fEpqYayJ69fJZzm3RDDpB/NUrLQ= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1678491820; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SSBGLO0ZKcc5jSLq3xLNP5yCcA0qlKOn3pEju7Cd7ZE=; b=qTe147JsgTpvXQaz1MuzU6p4Le749GRL4+l6KHdDbxbjugDg757OBizgyv1xrZAf+akgys RT3+ihmsWdEcXCAxS5P4ef6oW0T5jdXhD7ui2fhRdioeaK9Oq8mjlqZo1/ClrUvMp+81Ke O1zfZHyyRBdAWHtNAfEhKB9LtxT8WoM= From: andrey.konovalov@linux.dev To: Marco Elver , Catalin Marinas Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Vincenzo Frascino , Will Deacon , linux-arm-kernel@lists.infradead.org, Peter Collingbourne , Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, Weizhao Ouyang , linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH 5/5] kasan: suppress recursive reports for HW_TAGS Date: Sat, 11 Mar 2023 00:43:33 +0100 Message-Id: <59f433e00f7fa985e8bf9f7caf78574db16b67ab.1678491668.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 1188820004 X-Stat-Signature: jaxiojsx19hxez145mbsyfrifc45uqhc X-HE-Tag: 1678491821-197805 X-HE-Meta: U2FsdGVkX18a+Z/0uuBBlynyz/LqTTLdaUxFTdesELihOQdrppjY8uoslhc45Lb0P+pdr2MqbSmWW1au/nyL7r9O5gD4MRhfoY9bmfB8fKFUbyNHi45L6L2pHrqNLhKAEyaKdsgc87RbAx0oAS2AwZ3IBb2gIVYPbXi4ExKUmw/BYkleJZrEt9UuTVo/uAnVYKzjQF8DVzr5oHhCEQ3T4nIu/pSAK1qE0J8WHKXKKMX8FL04E9mxZCsbZwCuApMru4NYW/olhERUAOcaCvG5LGDNr9iLXC4mh/Sl//jx0W6SLE5l0Igm2Q+0rB/5cDkECpldZY8Ctro+Xs98D5OHlqNvjHWtSOWiBsYd402pQpVBvT9CIE6KWQ29LxLqhj/uWF5gcKwPhO77Fr/Gf3IrSSlNrbpZqWhgqmGPwHaGatQphZwulgaptmf+863Uup6zzTvZKat7hKcXL/JYVgAy8PEhgcYInuEqIIf3rK1XSyUFi+XvalBr65Bcw84akfAWrp0xPPyc4rkRY/tGn8r9y/1STXaqAVY0SukBa4YSHtOJYC3e0ojsztJAQ75evWILYv5yW6ogOnHY9hBe6U4CEeWXivlDKMYboDKH/BnH3Dy7sgdFSyW/e+MOzMMYUCsJP3quJprGjfyAgCu90NnwrSGKZTA2u0qG0uQH0Neo6CiS5W3NilhaedG1dbv9/+heFjRFvLcl8dFvyFYwT1U7HmLxNOfffljQh3QWSUu/clRfK7uwXo+flcF35gKYr2dqr4qgD5CuyPAULOAb4OON1eNvGC8ZKv5OpaBt87nLpjSQbd1QHLQkVkESJOTqMGPoFDM89MVaM1mA0MZTzbiJV/8l7EaD3HBlRH9HqzBYOkMapbScyxpdThwc7M4pSCPHGfbfNJtkVKyF6B3HCkDWP5xvWPq1jhKpSMeolXAdWFhRdITT6BMevAsnTYKUKpE4lyKscfqp7GRFh1cCqsx SjMbTBsv d/vwjuIPWViqmmzPxGYWtozbLHfRdUbl9w1zxVFWjr7GTaAmHD5/3zoq5C46fqW+f9+KhPckwUWLCFF6CaQAKqYdqCgJlKPHipDCXiT65sJ6NrvhnnzZ2BbAUtfzK/QjU1Q/6NnMGmKmGAmrHPxG4IPVYP9moOfnOWUHEoZRjahPATfiIgNszYh+I2UUDwuE1mRIO8Jtl3IFSZnQhTVRGHojpwjEj0iSkUMQEOC8E/mx8n/O6+7Q6WjB/34/gP9EwuawktqGMYfG70m3Pdj9iApUaaAA7veS4OZKwPeLEAPjIgok= 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: From: Andrey Konovalov KASAN suppresses reports for bad accesses done by the KASAN reporting code. The reporting code might access poisoned memory for reporting purposes. Software KASAN modes do this by suppressing reports during reporting via current->kasan_depth, the same way they suppress reports during accesses to poisoned slab metadata. Hardware Tag-Based KASAN does not use current->kasan_depth, and instead resets pointer tags for accesses to poisoned memory done by the reporting code. Despite that, a recursive report can still happen: 1. On hardware with faulty MTE support. This was observed by Weizhao Ouyang on a faulty hardware that caused memory tags to randomly change from time to time. 2. Theoretically, due to a previous MTE-undetected memory corruption. A recursive report can happen via: 1. Accessing a pointer with a non-reset tag in the reporting code, e.g. slab->slab_cache, which is what Weizhao Ouyang observed. 2. Theoretically, via external non-annotated routines, e.g. stackdepot. To resolve this issue, resetting tags for all of the pointers in the reporting code and all the used external routines would be impractical. Instead, disable tag checking done by the CPU for the duration of KASAN reporting for Hardware Tag-Based KASAN. Without this fix, Hardware Tag-Based KASAN reporting code might deadlock. Fixes: 2e903b914797 ("kasan, arm64: implement HW_TAGS runtime") Reported-by: Weizhao Ouyang Signed-off-by: Andrey Konovalov --- Considering that 1. the bug this patch fixes was only observed on faulty MTE hardware, and 2. the patch depends on the other patches in this series, I don't think it's worth backporting it into stable. --- mm/kasan/report.c | 59 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 11 deletions(-) diff --git a/mm/kasan/report.c b/mm/kasan/report.c index 89078f912827..77a88d85c0a7 100644 --- a/mm/kasan/report.c +++ b/mm/kasan/report.c @@ -72,10 +72,18 @@ static int __init kasan_set_multi_shot(char *str) __setup("kasan_multi_shot", kasan_set_multi_shot); /* - * Used to suppress reports within kasan_disable/enable_current() critical - * sections, which are used for marking accesses to slab metadata. + * This function is used to check whether KASAN reports are suppressed for + * software KASAN modes via kasan_disable/enable_current() critical sections. + * + * This is done to avoid: + * 1. False-positive reports when accessing slab metadata, + * 2. Deadlocking when poisoned memory is accessed by the reporting code. + * + * Hardware Tag-Based KASAN instead relies on: + * For #1: Resetting tags via kasan_reset_tag(). + * For #2: Supression of tag checks via CPU, see report_suppress_start/end(). */ -static bool report_suppressed(void) +static bool report_suppressed_sw(void) { #if defined(CONFIG_KASAN_GENERIC) || defined(CONFIG_KASAN_SW_TAGS) if (current->kasan_depth) @@ -84,6 +92,30 @@ static bool report_suppressed(void) return false; } +static void report_suppress_start(void) +{ +#ifdef CONFIG_KASAN_HW_TAGS + /* + * Disable migration for the duration of printing a KASAN report, as + * hw_suppress_tag_checks_start() disables checks on the current CPU. + */ + migrate_disable(); + hw_suppress_tag_checks_start(); +#else + kasan_disable_current(); +#endif +} + +static void report_suppress_stop(void) +{ +#ifdef CONFIG_KASAN_HW_TAGS + hw_suppress_tag_checks_stop(); + migrate_enable(); +#else + kasan_enable_current(); +#endif +} + /* * Used to avoid reporting more than one KASAN bug unless kasan_multi_shot * is enabled. Note that KASAN tests effectively enable kasan_multi_shot @@ -174,7 +206,7 @@ static void start_report(unsigned long *flags, bool sync) /* Do not allow LOCKDEP mangling KASAN reports. */ lockdep_off(); /* Make sure we don't end up in loop. */ - kasan_disable_current(); + report_suppress_start(); spin_lock_irqsave(&report_lock, *flags); pr_err("==================================================================\n"); } @@ -192,7 +224,7 @@ static void end_report(unsigned long *flags, void *addr) panic("kasan.fault=panic set ...\n"); add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE); lockdep_on(); - kasan_enable_current(); + report_suppress_stop(); } static void print_error_description(struct kasan_report_info *info) @@ -480,9 +512,13 @@ void kasan_report_invalid_free(void *ptr, unsigned long ip, enum kasan_report_ty struct kasan_report_info info; /* - * Do not check report_suppressed(), as an invalid-free cannot be - * caused by accessing slab metadata and thus should not be - * suppressed by kasan_disable/enable_current() critical sections. + * Do not check report_suppressed_sw(), as an invalid-free cannot be + * caused by accessing poisoned memory and thus should not be suppressed + * by kasan_disable/enable_current() critical sections. + * + * Note that for Hardware Tag-Based KASAN, kasan_report_invalid_free() + * is triggered by explicit tag checks and not by the ones performed by + * the CPU. Thus, reporting invalid-free is not suppressed as well. */ if (unlikely(!report_enabled())) return; @@ -517,7 +553,7 @@ bool kasan_report(unsigned long addr, size_t size, bool is_write, unsigned long irq_flags; struct kasan_report_info info; - if (unlikely(report_suppressed()) || unlikely(!report_enabled())) { + if (unlikely(report_suppressed_sw()) || unlikely(!report_enabled())) { ret = false; goto out; } @@ -549,8 +585,9 @@ void kasan_report_async(void) unsigned long flags; /* - * Do not check report_suppressed(), as kasan_disable/enable_current() - * critical sections do not affect Hardware Tag-Based KASAN. + * Do not check report_suppressed_sw(), as + * kasan_disable/enable_current() critical sections do not affect + * Hardware Tag-Based KASAN. */ if (unlikely(!report_enabled())) return;