From patchwork Wed Mar 29 18:37:44 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: 13193123 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 3B305C77B61 for ; Wed, 29 Mar 2023 18:38:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D30D06B0074; Wed, 29 Mar 2023 14:38:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE13B6B0075; Wed, 29 Mar 2023 14:38:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BCF466B0078; Wed, 29 Mar 2023 14:38:01 -0400 (EDT) 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 AF4886B0074 for ; Wed, 29 Mar 2023 14:38:01 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7F57E1C637B for ; Wed, 29 Mar 2023 18:38:01 +0000 (UTC) X-FDA: 80622795162.07.F3270C1 Received: from out-46.mta1.migadu.com (out-46.mta1.migadu.com [95.215.58.46]) by imf25.hostedemail.com (Postfix) with ESMTP id AB2F3A0002 for ; Wed, 29 Mar 2023 18:37:58 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=tIO3PhiO; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf25.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.46 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=1680115079; 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=IN3ZR72QwqhSmXvMtx1Sd2iYNmum0L5asYYBiJ8s6eCRBJytqZKCDWp5R3I3dKJCobnAvD IXcgXRQpBcXEWJlpE1s/NjXBoBuebWzWreoIY0x4UTwYOTpBWuogFPCOm0hF1CCd8WmYgT VEIUKEyBzZtEImIAS/hWovp/Ab1nEXY= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=tIO3PhiO; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf25.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.46 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680115079; a=rsa-sha256; cv=none; b=nAiRP80QYr8gTGdGKpGxayo+L9Ckpkn+ecThQIAiCbjQOl8FF7AH/mUoQn5onjJ1jHL/GF 7L9yx3O2Z2RgbAX7fz6lIZnngh3grWTTDuEBHoihYlSgth5mX+HNvJZWTM/dXvdc1GwYmt 0EhZu6FBGdjNAXISJDtoE5JKP53hYlM= 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=1680115076; 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=tIO3PhiOR2emercQwp44M6baOhhxEcQzHduTG2CPuKla6sVHmxWnHM9YWmEeKX28DgvZCV 9A+wF0Dv2nb8xskHclLbAXuQUuMRdY7xvjnkSyquQNWXMA6uaxWiNQqgVyLwJFW+XmE4Iy wvEeIkQDa8WA5AxpvHMez3p9xsgBnf0= 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 v2 1/5] kasan: drop empty tagging-related defines Date: Wed, 29 Mar 2023 20:37:44 +0200 Message-Id: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: AB2F3A0002 X-Stat-Signature: p6e1tod3brpgpdab1p79krfd8j9capdo X-HE-Tag: 1680115078-138720 X-HE-Meta: U2FsdGVkX1+fXcj3RB/k0HuzgsvhLD5zZ5fYrTiJe/W6Wge/+YW3loYyVEdeOP4od9lqSrJkJ5WhRqRn+NFOJNfBxHoIqp/aEagVx2PVONxgIRrGgYS14xZvbVc79BPD1nhtLWU5fVUA2Y3qWetSuZCbDcsnh16iaZZ6STxdq7DrsxmcgpXn4ebI6zLz2s+uyC7ZaQHxfJl/3z1pZXy6QPCuxoMeCMC+e7CUTpDN7ajnfDhIJJtniTHMhuYsnLXr7EWt5QpPQb6yjzNaVTbNv4/7xs4BvZhSgyhDH/+E+P3WSm0rUJXx0Kr4FtoyXvVPK7pAeObyJJ0GvRKXt/g9cm2MzKE7ZdoQDR1ffAKQlCqj8oNzWB1+941a4hz7v9QhKwpUyDGJhR6nK3pIbkU46U/+2hXGbpCcCaKNQ7kfHkiMysvz+yOsQ05aNUyx0b66OaFFBX9KxKT4nREaOVxn/VGOnoi+v6M9vkH/Re+2t0oyBnHS4TtB8XewocG9gVshXUFRma/v9gksSFwAoy+lsbbkDRa1w88wreSW2N0ZfB9XDcslrBmf3+bKBKYZeTPUSSrqkev0QJSfLnBH9xi0m2RnW1EoFrNKDW7gZhuJBuoN5pMGwJdOWeFBUzZZFIczQiWuyWQU+GTkrtn3nudIcPnYp4uJ1zGOxe5CoczaGbjC61BBmx32Z0ItE0clykazoBelMom0jDPlF7rJiFIcKGdRW/sgWLrJQLEfkEnzZwpCGPL71+Bwb7++1Ge/D130ITwVr8ejaOq9LhThmYHzV4a2K4lWts8J44pBEi01dUerbs7+an9eUk2nxs0kdFyb2oz6hDE+IBjJZ4nefq8JqEskjuVU2p7+/8NirVY82k6iQF+Izc5RSDqOIILm30HdAhYEkH7/kIKsYzVqyB7L55cIPlPmvnwvUO+dIjAbMYlGF0Gu//2CkrpMm56txI0o+1Fv8FSV4+037BxvwPp tJVaG8rJ uvMEYaAyygZHUhawyWthi51fiXOsYja9VsKhqVbwqTU356QaOdWTsQ7BiX0fo+fa3QE082/GI6/CqpE9dHUnNdvANLdXaJpqy5gCVQdu2/9iDNGKfHh0LRiepQSkv8otJgJg2L48ZT0YAVuRZyozVPKYs6IgDWbP0OdpYx81F4rrxUOXDu2otRxw8hQgpk+aP/XqO 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 Wed Mar 29 18:37:45 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: 13193122 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 47553C74A5B for ; Wed, 29 Mar 2023 18:38:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D9AF6B0072; Wed, 29 Mar 2023 14:38:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 789356B0074; Wed, 29 Mar 2023 14:38:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6509F6B0075; Wed, 29 Mar 2023 14:38:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5565D6B0072 for ; Wed, 29 Mar 2023 14:38:01 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 299F01A066B for ; Wed, 29 Mar 2023 18:38:01 +0000 (UTC) X-FDA: 80622795162.12.885AEFC Received: from out-22.mta1.migadu.com (out-22.mta1.migadu.com [95.215.58.22]) by imf17.hostedemail.com (Postfix) with ESMTP id 41E6F4000F for ; Wed, 29 Mar 2023 18:37:58 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=DbXVQvkG; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf17.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.22 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=1680115079; 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=qlgSyoorrFESfyoWduU9p7WJBbwKZa0+vTBkynXBEP8iMZOTMArOrCjE5FBi/uQGyo01Xo dlby9MuZrnn1cQ5jsRn+/sAEV1vOWX0uRYQKFishffSdqTV8sOnMMHCGLTWAtoUFpgPIfk tbxcqFWr6tUd0cbxTi524TJlnRkMlqw= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=DbXVQvkG; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf17.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.22 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680115079; a=rsa-sha256; cv=none; b=l5nyCNcFCKLLfdZtf50UkfQv5PGwjYe3Fxb2p03LlXHD4OEm1LVkPxJgRz1Fd96Heelax9 ds+ZeMS9kpX7RZVetg/AGlpnKG71+d25cYZ0vxvfJM87V1swquCkhefVJ1uYoQNXzHTyKG GzjP1oN8nAIyAK80XGhsCWh5tX0FHQY= 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=1680115077; 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=DbXVQvkGTlCs/4ox1E5HOmnOas+o8dhrEXZjhbQ6W8WQVmI5zYiq4ygRCi6EHxe9W/CCRl SYi0JaVw5IP0cy6wxqsztEnf8kDC6a250hmtkSn2HqVpd/QOP3J/6rbmYShIcirFB1djxa c4RW3q5ScoCHI8t9U4gig00pOB+z2mU= 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 v2 2/5] kasan, arm64: rename tagging-related routines Date: Wed, 29 Mar 2023 20:37:45 +0200 Message-Id: <75c4000c862996060a20f1f66d6c9adcf9f23aca.1680114854.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 41E6F4000F X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: gbjxtkxxzdawpfcf6fi55p18xx66opb1 X-HE-Tag: 1680115078-653894 X-HE-Meta: U2FsdGVkX19ZFd2j8Pg0wQ3LAeUahW/6dNlqZ4KgacQq+wMsZ7wN0a63Rpr4hacyUn9yU0n0a2oU9/VsS7oG5O5hyFHHj/8+5JLQjDI1cgw+wRdhd7EeCaE7nAPE+7T2Nnmj+Y+XMG1v4Vji/I1DnjRWAyzCm8/EdLUg58qYRifeQoQqHbNr04djUsN/VpPozF2BxQKEm9nscpya78gGOq9fY2nln6DZMkYgj5z33Z/O2WfLG0Z2nFSDn60XE33d3OHGXqqwsKvzOOwb2ABFqBscenXFt0Uc1S8xDPPLM5/jT/ezUFXO/feqczsDEufkeHpM2ZWQxa1kQCA4Bobo2LWaawV2yzzByyNZyEZkcU4zfR9L4QQARAvdyxB46Q2IidsdMulg1G6uY/QDzT65gYW/OJJWvhBrpBiWfEVz3EcEDMOhVt46MDUIvedj1Es6/E3q8uhD+tRHLUC80vrULEjSCA17n9Wl/GSizMbQclbis+N/nNb8xTAG8c0phz1yofQ7d73psXNGiXBbZCWnmUtwh7ZCcgczN/ogd2LwTzqDbvJa/MmZzwQSAW1y5KN8+drsoevNOmDy5H9MaoyeS761CD//JybHBunizsm0TQ8O4jdujp/GI6V9Po8QIrvCLuHjfFeShOjNpw+eEtZO1sbygAIvcQZCiQA0GPf85CUwxYYp2ddlzE1/8HJxVQm4daBBQj5+3z4Tfmm5JFzxUtVsjc3iikjAe9H5m9kq3hjrwMmDmmkQYxyc/QlfUgpxlBHKx5nvjpiRa1oLcuxIcpa8mpQX+c8XwqZbMDkAOyt8Lo1bYa+JH9BalDsJfhBaQdcMKQDhJWox3Pov1QMexKBimyUaVvLd01uUsd847cU/vp1fPoCcANq/1CafsqaG3H7ZI5DpwBzzdCZyXw4+y0h2eLILA+gIBoJlADwET+WoESPLi+oiyNcCHxV29RXZiWuqUGLTfPcoSL7Tdrx D8b0WxtY eXa2LCAs5NWpo3oK0Cq8BcchSKp+KxVgmh0BkdJ92Wyx1kxuYJockMgKq2QbAmD2OM/t04UJmvj+PlfkiuMkIzTyAYwaOwEtVzFPM76RIZLKHvd+tw1o+gMI1lOfj4Ch5S1GC58E8PbJZHzCYhzcZxgR+Qqtb+bOXsLVtPeGWhQ5S1OuNlKu5wt7m5nE5TnESqKV9 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 Wed Mar 29 18:37:46 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: 13193124 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 11D1AC6FD18 for ; Wed, 29 Mar 2023 18:38:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F2F46B0075; Wed, 29 Mar 2023 14:38:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8259C900004; Wed, 29 Mar 2023 14:38:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 652CD900002; Wed, 29 Mar 2023 14:38:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 501FB6B0075 for ; Wed, 29 Mar 2023 14:38:03 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 0BA661A066B for ; Wed, 29 Mar 2023 18:38:03 +0000 (UTC) X-FDA: 80622795246.26.03D61C2 Received: from out-47.mta1.migadu.com (out-47.mta1.migadu.com [95.215.58.47]) by imf01.hostedemail.com (Postfix) with ESMTP id 5771140009 for ; Wed, 29 Mar 2023 18:38:00 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=oP2VA3+D; spf=pass (imf01.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.47 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=1680115080; 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=R0ZTLDK0+ErC3gsprSGJ+tiVFRHa88yHqEYRk0ERiZ0=; b=FOPBTfoWf3QuRqY2IW89ACTCisxi4KgCJ0fMy3wGPbjBy/T7SKco+YapcCQn1FTUcQTRfO tK63VMi9ysnsDjORLSBRXsurN6yRChoMRb0MzCT6sLP4kKs/7S7ktW9Hbn+YSUvVXm3lEA s85rJAQ4B+Pd5jnq9YNICKL7lyKNgg4= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=oP2VA3+D; spf=pass (imf01.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.47 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=1680115080; a=rsa-sha256; cv=none; b=6RFyCU9HL0JtiwjH8a+j47VqVQhhgV37lqcdkAmc9ydfAnouzpN1ByzOMiyUhltxvkNCn6 /bGHe+q7A8nmeWoYo68TfU7ncwrq6EWRTpPrLFDkisEUe3Xs3piY8VjmfEtypk4UrwROhO EMn5RT93fNYlPeGs/NuMTe6y1lYEIAY= 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=1680115078; 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=R0ZTLDK0+ErC3gsprSGJ+tiVFRHa88yHqEYRk0ERiZ0=; b=oP2VA3+D9Qr8dKR4UOrrmrc1+nxlHZsTDv96qHpFlLIIE0qAxFcHxNtGpjSuXYDtYGe7g0 R9YJpt11ce2lsJJGHndi0vAWGx+Lrt1/J0xo2kovQdSX5r6myxaV5UGnajysVl3a/fkg9M 5PYt++7HFPVvKJdr1l9qX0EEByPuMKk= 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 v2 3/5] arm64: mte: Rename TCO routines Date: Wed, 29 Mar 2023 20:37:46 +0200 Message-Id: <74d26337b2360733956114069e96ff11c296a944.1680114854.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Stat-Signature: 5x5fo37obxhdbdyz5fknmxzz35mqjem5 X-Rspam-User: X-Rspamd-Queue-Id: 5771140009 X-Rspamd-Server: rspam06 X-HE-Tag: 1680115080-284705 X-HE-Meta: U2FsdGVkX18eGlJs9J/nw1ER5qb9JQPEpIxrZxVRGruYJuJOAkuz4Fp8Q3mkKZGQhvYOhBwceSLL9yEVpgp1YxHpFWhlkPZ2bLB/MPfJl5fGdU1NPF96dADaqR5ZLQgou5J0oFyUj2H30JAjHpUnkUHx9mrEraeR+FLIFqxq0LIYfGpEZN9Qcv+3vs90wHwMl4H8zz/i0sr/MZq+uDVBSjbNvPWAumN9+cSQBfO62OYLxnzUjLkHcR5EJnIzFr0MggktHx1On4GfKOymgq35/fMMizCf++LzLNwHi1zAmubiGCusWgym3MP1a0gOrfLvmEe1jbcLhI995jIZeD7I61QRC0UlaBpj1ITpZEgyfHdOYoX0Zp02Q1bRsXiLJDS3zBUqqWjFQHhG8R27ecGfhxuXOwGgwJjPr2knv/V36S5HcuFPnVLzsWCruxCTG/vA4/R3MwA0tj7zXnCY6RSorM9s/rT8fbfD+c4Y6JoWCzZgRUhNNbPQkKZoBUSgI6EjFYKpl357KXnTsW5/OEmO4tTs0Bhecg8pn9jX5tGN3kaf0rPp8MYx6qVORCzh7Mhth1be/bGFvTh+5Wh2xvFsHLPqV5K/uRdJ3EyOv9Phpmi8rpOESmo7LtorPULXKEfp6pdWihX3hW+gbxsEoGdztkmX0+HDMCrRNImjntWliLpd544KZd49aK8VgGED9GLGO4V+nXyKSIQyL9ciSUhbtCoh8oV37JaBqruWJV4mIkXE9XXSBrtAZFWQgRWqXVWlNMktlLBZgA7l7RnQPyjMGBLkHDt1hINk/SLzz+2PqfLoo26Tk2zTUAU40wwKHbBjwdAZR7fNMGZyLtdu5MXR5izJOgGJkAZ2T9R+NOqDlybRk1+O1eeieGfM+PaQXgddE5hqZ+QsKoF6JVjC99nVJRfRcEME3lPeAjr4vFtA8rI327G0hbiwpfv05FAX/zYOGjJWx/gEViPi3GhsiNK WEpUapBW Yue2vKWMRM1pm+387N3F6bI5aCoNEdLpJeMv+1PoOsGH+XQI29znutcwmS7hyKm2Y3WUaut+ZdEw5PkIqXXToIR95yhaqBZWC2/ixWLNscFk733OLyKbGsMaeZmsKjf9BL4cmsKORX23ZQFNKBzkefWURFjnQK/3CmU8EB8XF+634eTSnqc9UcBKyy3OeaLtsGKZkVxREJEopSKDtWQxao37+zu6XkgdBD452KKUA7grMVCbPfRNYM0+vJsPcpRS76zJkKfHuBfBft334U1Om6meHrPt+pHAHgMhl2oy+FIdEG4Bq/Uq6T+nYyw== 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 --- Chages v1->v2: - Drop __ from mte_disable/enable_tco names, as those functions are to be exported to KASAN code. --- 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..2e98028c1965 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..30ea7b5c3ccb 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 Wed Mar 29 18:37:47 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: 13193125 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 CD78DC761AF for ; Wed, 29 Mar 2023 18:38:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B75396B0078; Wed, 29 Mar 2023 14:38:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 986BE6B007B; Wed, 29 Mar 2023 14:38:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6EFBA900003; Wed, 29 Mar 2023 14:38:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 56C256B0078 for ; Wed, 29 Mar 2023 14:38:03 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 32FBE160E14 for ; Wed, 29 Mar 2023 18:38:03 +0000 (UTC) X-FDA: 80622795246.24.7F4BFF3 Received: from out-18.mta1.migadu.com (out-18.mta1.migadu.com [95.215.58.18]) by imf11.hostedemail.com (Postfix) with ESMTP id 6B31C4000A for ; Wed, 29 Mar 2023 18:38:01 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=QgAd4ttX; spf=pass (imf11.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.18 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=1680115081; 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=4IBB0t30IQWFgjzMoDMwNtgr4khYAd9V6YJirYANKJw=; b=MClE0Ok1XuJDpQhbH/yVyCoGhmYUH+TzzSvk2tvqSI5892w7+PzvikrTJNyphJdbSPegg5 fGZcpfNii6HhZjBth4adV9vE41INlarEIQqyWpglmCea+aqlDEpTUeaPpj6mcIsckE6qpt h0T1uycNqSsVYC4uW8SzkTr5Ckm5V/E= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=QgAd4ttX; spf=pass (imf11.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.18 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=1680115081; a=rsa-sha256; cv=none; b=NTtG7ra2DaUgr9KOuwnrbHYyuniaIYP5bYGyA5Qw3o3tRC7cIxhya+DRXXGOcvBrbMdsZj Dgd1RYOU8KeHjigksxOMyy8xgk0N6or7JPDLpcnIb3mPJ9Eqnq961UyC0GpxOMukSLjKt8 cxxkIHyU+dGDgnM039z7EkSJ6YMzJYQ= 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=1680115080; 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=4IBB0t30IQWFgjzMoDMwNtgr4khYAd9V6YJirYANKJw=; b=QgAd4ttXeu2KtUbjd+eYGisjZq9ioQEf7KHQO41mUQEncgqcvFT0kMtVWTnVhTvqO39dCs qnfT8VmxT5x2t4jFNaIYtC86D2toghjLwz4S6LnFhsQ33dWNChtMewppVDGTmO1JwwMcY9 /ZquEfYJhPqccz/gfQ0PZ1hFiaHWscc= 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 v2 4/5] kasan, arm64: add arch_suppress_tag_checks_start/stop Date: Wed, 29 Mar 2023 20:37:47 +0200 Message-Id: <7ad5e5a9db79e3aba08d8f43aca24350b04080f6.1680114854.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: 6B31C4000A X-Stat-Signature: gd7nmwjjabaayi5sdqr5nb4sga1eg11x X-Rspam-User: X-HE-Tag: 1680115081-501746 X-HE-Meta: U2FsdGVkX1+KO1w7T+CGcEoD/ldcb1gJsnuVRXiXYVoECpnts0JlUNtgZp1OFDeWVqtju66i5Eovd8BzIXwuUAxkBhAGNWYOibu3z0Zga2BFprbDsv0DlhTKX8Tve6ruSp8Vi2l3Vh7/vJqAD6LCdgiksd8lPiZHyQLwcwBgKPm/yqiwfQoMIuNpCLoiQpEXR6EyDAS6RDWIVkkY0KnEwwm9WdQInwU1QEfgPkVUzpg99dzxZRFzxMPefRvqCi0+a2SS25O3nIIEiVIx2lBp8QoXAw7h3s0jKKDSJufm/o9Cr/pS+//cMGCXj8KEXbsaA+uzOoU96wuFGUG4XiQPVjW9KSmk1l6LrsQ2FjrXj4Hmrffbl6vn+FyiO4p24m7QEQpPFeTKBNPWKep+1mCIMouxg840Rh/69AX24e9J+g8CtUmVlhBAjzY8+zepq1XqZYNwc9uxuZarVSErvzZJ4hJXX1m5EJa3NrSTQZgY8ws0aFss3V4GwS+uXnzA3T+qz9hA+Edoxv6LQFvIbp3anbmrdCJa9RN4vgAdd4T3IWC5DpOhs4W0Gq7o7EHUOYaRmkapEaTxzJRtLgsBJ7AVrm7y2K08M0Gy/s+PMAZvny7uqtm5tKk51K4/1wHXMDGnLC+rU0MK0fLwsBU4PZAF7kF7dyUgzs8/TMQaBZrV4p8TB7JbanROK0sDiksE0pt36I2S5EokyWTZamKmL3AXCiG0MwBRRWyWH9p+Zzx0QwYBJa8FcS5N4rG2I/Lxw4+qC3Te/kyqftuc0D+byCtppzKuSjJuRXhGsx+My8dgjDTtnWRsre19YLhIsuXpf9zw10g9EkAvbYKdK/opH3h8FGf7e9+FHCzJkqvKY2h6EvEuJVEIfpkyDbXB2y3LsxNdTmOVDnTWjhnxOmPnrQjeu8yHP0WVnKvNyBNIIlmM+eSRorWdsBCXeOnRGrCKNCVeyXuhv9j7V2j0yP4zd+W rRfWzZBe S9VRi6o+M6qFnwNpBXDUKMQ4v4oqQxs8TjP+H/41aj3mmVE+cSoJEgNxbW5sY7y8CIwuwzdd3wAEbqN0HaFPkPiYpUJKnmNSGH+EI52xg05M0nn5xatUzhipYrl1ABcjAT+nT+IIjyJtkQaivOMsz20r9OCfpzBmT8iwgYSxVpjDmT6o5bie5Qpuysu+AIvhXvPyofQAyP+1qRHKXTQeWGmQWS+CIcIePAhsf+97xYInMTY4= 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..05e42bd3555f 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 Wed Mar 29 18:37:48 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: 13193126 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 88B6CC6FD18 for ; Wed, 29 Mar 2023 18:38:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89FD66B007B; Wed, 29 Mar 2023 14:38:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 830CD900002; Wed, 29 Mar 2023 14:38:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6517E900002; Wed, 29 Mar 2023 14:38:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 55EF26B007B for ; Wed, 29 Mar 2023 14:38:05 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 313E3160E0F for ; Wed, 29 Mar 2023 18:38:05 +0000 (UTC) X-FDA: 80622795330.08.1F1C0E3 Received: from out-31.mta1.migadu.com (out-31.mta1.migadu.com [95.215.58.31]) by imf21.hostedemail.com (Postfix) with ESMTP id 77F961C001F for ; Wed, 29 Mar 2023 18:38:02 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=agGDWJ9x; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf21.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.31 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=1680115082; 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=KXwl8tO7n70VCzS+2Z99ZqyN4ebAwCoCQirv2FwloPQ=; b=TF4IIAZBoXajPX1gCwKo2a+EX0OqoultT9/rzSEriDE3YOw4rnYQs3ca85Wq8xUSBSOdXs xbVGgO9QPkz1kRca29OGdq2W2KBGbYeyaur9ZfvlU7z+WveMVpQyBG02pGWAnEmQo81BW+ I/pp0JdxY7tTkFgGvRvt8nzHOWGJ1Zw= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=agGDWJ9x; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf21.hostedemail.com: domain of andrey.konovalov@linux.dev designates 95.215.58.31 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1680115082; a=rsa-sha256; cv=none; b=5mMLbh77fJvk80Wwj08gaDBM7rDbER7Fw2N/noNiJJv6BttuqmvJgDWrIFEowmchUAwvqX BwyuejCoUo6o7RNEay7QdADVfWImOHkRIt6e/okm9yzc5+wnPoZw78Jia+xAl+h+sko6A8 xTPerk5xDmHlXGTJe53XKh520JRjf9k= 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=1680115080; 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=KXwl8tO7n70VCzS+2Z99ZqyN4ebAwCoCQirv2FwloPQ=; b=agGDWJ9xzHKORm0clngE5cybrY2NbiNiuT8Au3+SurJwSKOhd7350jBTyPn/yXpT9rTRV9 BE7EEFNPLvmCxOGUcnuqPyNdnpttIko/We2eAOk+kYoVbjy2qrGk3zUJLFwLcwFmSyampp LtPeZOW+QWpuEawW1ooy7OC5yXZRZpE= 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 v2 5/5] kasan: suppress recursive reports for HW_TAGS Date: Wed, 29 Mar 2023 20:37:48 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 77F961C001F X-Stat-Signature: 4o9juzs8qdog7e3o8kgxi1884o9iuew1 X-HE-Tag: 1680115082-406737 X-HE-Meta: U2FsdGVkX1+6hYLeHHC8zV1bIn60T8rQbDaAwQjWN8YuqJGQjlHYtm6Q/1Ve770i4V8nKCUSfJmi9c7ZrMProfw9tUn4VSTPOOQkMpnaQnX0jHTuXCvj6w7iMaBe6d8DsfLL7prMF4PoK3XuSsqw1TVeeCO+TcYVSuhAVRHhja9Wv92xSjcp28wUjSUQfmSKrTLqevP9U0ohsnDySIsMrLNVYjBLcg4TtnAeA/IdwI5erS5+VVgVwRfS6dKfRh6ag00p0xth7YnWgT6kxnVbmOjJ+6010ZKzRKh0ST+ddsuXoZ2uWci2i3UzWAvkT3tKdbUxBH3Atv67Hm8ktNV3OeJi5oonUwF5ipY0vfVc2x7z3xIaHyDa+sCuq3UjCH4FQHjhRbtoxrjTlmVPSI2ldsOlEKP8+++2C8LNbZJUH6O4iQtotw7PtccMYO46Ne5ud6qEJECdQDZU0B56Cq/i93d+ZXVCLCmcSGccHYYrZVzcdOefWzhNDXZd5O9dvzF8he66w9CvkKiKZ9gbJegSF8TQCA+JeoqEO478rYrBoZIvnLaXFcFL1JnKatQ//mmMxcU3v2/wkDSRxd/vcZA3IBS0wgXIIpL4I1dey9slpfKzI5lH7L+2M0T0rok/BIz1XIYWe6zpvVYaVwwi5vKjyVFn2qCwDQpp8Dtok2I6pl3jnmVV6El67y8UZS6W95theB/aZXlRgwwRSLEZm2hiJusvmdPg2Fs54n9T+0RPkDCrJieYeb2HoeZwFpnFYv9j2u+a5srG637RL2RpVmKM8GGkNiWnfmUfcZmxKUDbsStLXDhnVoeul0GIYf7viU4hgpgHZ3q57o8XbVKzVNP9YmDLSC4q3chw6LtaOiJCFjuL5TgUKhi3Z1iRRINDOjNqowJYEEB1fGF2nVy4gQj3uhxY8o10rJ2YgGTIhzfYbEbRXAtKXSYSn8MvloYG6qYo6FI5LNyDRO9Tf8EnmOz ZtkzhHId qBlW6Adz9gCp0TxWLQoBsNP5RFR3yfpjq1n/aLhfK1lpCSphy9Xlg+iTOAz6fgpAHh0E81z6Xz7QaHNXsT3hPPsjnEhmAYeBhCZ1LjJUmfUSplSHJzV/0P7ethhc3E8Pz+FEWLgVBYpLutGAUbPVoWDxdYFmMAJilrvlnrokqgB9kvTK24rLU9gXBCzEc684KEhikIKHOa7rKhDPSlkM7h/EBFLr+oc9LyJ/iHTDOb6fKeXzzBE31tYnJ1FkYOLnOcppyWKLJqjUugthgQtvqH0pJdG70Lyz0829vOaRrJDR+Aqs= 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 Reviewed-by: Marco Elver --- 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. Changes v1->v2: - Disable preemption instead of migration. - Fix comment typo. --- 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..892a9dc9d4d3 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: Suppression 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 preemption for the duration of printing a KASAN report, as + * hw_suppress_tag_checks_start() disables checks on the current CPU. + */ + preempt_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(); + preempt_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;