From patchwork Tue Oct 22 01:57:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13845003 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 111F7D17159 for ; Tue, 22 Oct 2024 02:14:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Y/iY9Y4RpcnWjc25xyItwxMbRygrVUaVLlWUhwxh2UQ=; b=eZ1BROmK4VHxGCCfdTZckI5yf9 oNVcmLxqiUvmfYxrIRHv5mSG8PGjM487nUtC5LE1gpI/W0JRMEeYbL4omZufnmCXh320DD/P4blbQ EfkuBayLnIXQFo62QjGegPHBff/xh4zmrTiFdoNvvB166tBpRoch41wb/C9jiNoUXiENa4V6i4s45 7vE4jeFerxYbo5yl7mXv1SEBh9AHTsEdA2HBJhz9ezjQ5r8oMa2EMwH5yZpwLF+bENikZhZ1edlT7 w8U4gh0nhqaxuEpBPbnG5S39uMgWqnX/s4mkZUFoIkfxsAthsPHLI8J1sgfXcI8Yy7kTasgKPQb/d rL6x7qHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t34PH-00000009ImF-1wnC; Tue, 22 Oct 2024 02:13:59 +0000 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t34BA-00000009Fnv-1ypO for linux-arm-kernel@lists.infradead.org; Tue, 22 Oct 2024 01:59:26 +0000 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-71e592d7f6eso3282619b3a.3 for ; Mon, 21 Oct 2024 18:59:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1729562363; x=1730167163; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y/iY9Y4RpcnWjc25xyItwxMbRygrVUaVLlWUhwxh2UQ=; b=MC0lpBtVc/H1rPTiBpCclnBzMwb69GoX0JsjIJjBqRm6djKgawCf2w21i7BBbMN6Rd jjdt97OPhVAPadhplc9SqQQu5kxTjqV2WQX66+KV4Niy8Y7RyLMl6p13uWVmpNNys/Jd +pBsQAv+W2VMPnOquk9ovVy1NIe6zfs6JRD9qDlJyWaf74eGIkRv9f8vIJNoaMcDtqKC txDhoKGQ1TvOJXjCwI81ZFl/Wo9va2BvHlfTxXy9eJ/CCAutWQyWm8jMaX5dfbOyCler JjPGbLAb654oEI1lHfDBh5t5j97nJ5XhMRqggeEoHUUdIR4E897LxZf28SKvkMbWEsup XJRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729562363; x=1730167163; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y/iY9Y4RpcnWjc25xyItwxMbRygrVUaVLlWUhwxh2UQ=; b=eNDlhJiqkbsuB1B4xQdG8+DGPeMuMdUKfgRk/5z5uYPiYemZNRScBPNzkWIAeNQ+G6 OGvQz2XEAdC5wuBGvhW11gh2p8NGUHV4VC1dQPqQ3FQ0eA9krNbImoURzdHGk6rSnbvS VFE+kpL5srOWnWx4v8OPrx3dmDFj4S6/ItJvuLKnDFX1l9N6HT90AYgZuvawddwMLYAX 0jL5oAA1kSuRytjLRHkfK7LeH/J4k/Y3qcpTVg7ZdO850d/lyvTKFv1iOCl0TXyFMy27 Uyj97q9qRnLHyYDaAjPudJeUsGfBLjKx3hf67pSEE6F2TzTMhBQo+1jPNqmyV9uchqNH wHAA== X-Forwarded-Encrypted: i=1; AJvYcCXTcFvcuI+yIbfWhzNcD/Nelp9EIvu6AB/A4BJ3cjOic+kKf+GdLDHpIa+HXhz6oMlGDBb+UplTgUcBOofg2I1k@lists.infradead.org X-Gm-Message-State: AOJu0Yx0alUF5pCAa1x74RyQGavr39fiu6lpNHb2j2yBjAs8xrXNbXwZ 5iFDdU1guBhDEH4VnsDZGPampstStLqV9T3edgX2XAwspjl8OU65MJOwUIWncJU= X-Google-Smtp-Source: AGHT+IFB0AudxwQCUfX+B+Q1Nd/kKdWsIXk3CQ+Qmrq1W4iGhp3wWHffFzDvMvs7eDfgOIFmgokQfg== X-Received: by 2002:a05:6a00:9298:b0:71e:5de:ad6d with SMTP id d2e1a72fcca58-71ea323b91dmr19028480b3a.24.1729562363415; Mon, 21 Oct 2024 18:59:23 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71ec132ffdcsm3600710b3a.46.2024.10.21.18.59.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2024 18:59:23 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt , linux-riscv@lists.infradead.org, Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , kasan-dev@googlegroups.com Cc: llvm@lists.linux.dev, Catalin Marinas , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexandre Ghiti , Will Deacon , Evgenii Stepanov , Andrew Morton , linux-arm-kernel@lists.infradead.org, Samuel Holland Subject: [PATCH v2 4/9] kasan: sw_tags: Support tag widths less than 8 bits Date: Mon, 21 Oct 2024 18:57:12 -0700 Message-ID: <20241022015913.3524425-5-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20241022015913.3524425-1-samuel.holland@sifive.com> References: <20241022015913.3524425-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241021_185924_635455_9D84C16C X-CRM114-Status: GOOD ( 12.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Allow architectures to override KASAN_TAG_KERNEL in asm/kasan.h. This is needed on RISC-V, which supports 57-bit virtual addresses and 7-bit pointer tags. For consistency, move the arm64 MTE definition of KASAN_TAG_MIN to asm/kasan.h, since it is also architecture-dependent; RISC-V's equivalent extension is expected to support 7-bit hardware memory tags. Reviewed-by: Andrey Konovalov Signed-off-by: Samuel Holland --- (no changes since v1) arch/arm64/include/asm/kasan.h | 6 ++++-- arch/arm64/include/asm/uaccess.h | 1 + include/linux/kasan-tags.h | 13 ++++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/kasan.h b/arch/arm64/include/asm/kasan.h index e1b57c13f8a4..4ab419df8b93 100644 --- a/arch/arm64/include/asm/kasan.h +++ b/arch/arm64/include/asm/kasan.h @@ -6,8 +6,10 @@ #include #include -#include -#include + +#ifdef CONFIG_KASAN_HW_TAGS +#define KASAN_TAG_MIN 0xF0 /* minimum value for random tags */ +#endif #define arch_kasan_set_tag(addr, tag) __tag_set(addr, tag) #define arch_kasan_reset_tag(addr) __tag_reset(addr) diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h index 1aa4ecb73429..8f700a7dd2cd 100644 --- a/arch/arm64/include/asm/uaccess.h +++ b/arch/arm64/include/asm/uaccess.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/include/linux/kasan-tags.h b/include/linux/kasan-tags.h index 4f85f562512c..e07c896f95d3 100644 --- a/include/linux/kasan-tags.h +++ b/include/linux/kasan-tags.h @@ -2,13 +2,16 @@ #ifndef _LINUX_KASAN_TAGS_H #define _LINUX_KASAN_TAGS_H +#include + +#ifndef KASAN_TAG_KERNEL #define KASAN_TAG_KERNEL 0xFF /* native kernel pointers tag */ -#define KASAN_TAG_INVALID 0xFE /* inaccessible memory tag */ -#define KASAN_TAG_MAX 0xFD /* maximum value for random tags */ +#endif + +#define KASAN_TAG_INVALID (KASAN_TAG_KERNEL - 1) /* inaccessible memory tag */ +#define KASAN_TAG_MAX (KASAN_TAG_KERNEL - 2) /* maximum value for random tags */ -#ifdef CONFIG_KASAN_HW_TAGS -#define KASAN_TAG_MIN 0xF0 /* minimum value for random tags */ -#else +#ifndef KASAN_TAG_MIN #define KASAN_TAG_MIN 0x00 /* minimum value for random tags */ #endif