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: 13844965 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 C0307D17158 for ; Tue, 22 Oct 2024 01:59:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13A4E6B009D; Mon, 21 Oct 2024 21:59:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 076E86B009E; Mon, 21 Oct 2024 21:59:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E31866B009F; Mon, 21 Oct 2024 21:59:26 -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 BC2CB6B009D for ; Mon, 21 Oct 2024 21:59:26 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 87A25161C7C for ; Tue, 22 Oct 2024 01:59:08 +0000 (UTC) X-FDA: 82699580838.04.E8F6A2C Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) by imf16.hostedemail.com (Postfix) with ESMTP id 6F73B18000A for ; Tue, 22 Oct 2024 01:59:09 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=bE4I61WG; spf=pass (imf16.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.210.182 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com; dmarc=pass (policy=reject) header.from=sifive.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729562288; a=rsa-sha256; cv=none; b=SzkjGgHvBUEz2iOdBhWD6AbamkqDFz5L5eA9SunIU+G0BO6HzU32CRMqHNqGoNa3Hwqsu8 yT/mdE4MisoXzdJoyYu3AT4l0q18xUvhwppaBor8vbdSTwnZBk/Pm7wDQWpv+IaIB6M2xE N9CQpV3JideAqyUoAnJ2YKxRSLu169c= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=sifive.com header.s=google header.b=bE4I61WG; spf=pass (imf16.hostedemail.com: domain of samuel.holland@sifive.com designates 209.85.210.182 as permitted sender) smtp.mailfrom=samuel.holland@sifive.com; dmarc=pass (policy=reject) header.from=sifive.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729562288; 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=Y/iY9Y4RpcnWjc25xyItwxMbRygrVUaVLlWUhwxh2UQ=; b=qVJYsa46IJrlrPp3YRtiHfDssV+UIj7i7yqPos3GvALbQouHHc2NVoLeqa3Q1sOUiMKODX zUGMc6lW87E6Jxw29hqGmhImkogss6DECii2Q2vqympJ5Matt/azyRzn3FHUNcskwoUxqI N8Qb+3Ei6NZogW0dtDa4R/aLcG+uB0E= Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-71e52582cf8so3545717b3a.2 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=kvack.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=bE4I61WGLjMtUtwIdyrKV1E+so0BlEsZdW9F5rGjtZ3UU8plPS9jbqaPdU8R9LqFLs pRi6VpMNjaROsTvj0CUfQpkz1BHyub30ayj8vrMgwTri63NEG4Xi3qhGSUfxNZFG+RhZ HzjD3IxO/Hs0c7aEZb/6UM7tX1llc8ezQSQp2EDAx3QLw61X7s0FAJOSp83LR1rEGaWP 6wYNkR/aJXq7lMqHGNG/XuXA79BPj7k1mmKo4j0I7wGXfXENwd1WEELhItlEIGskFXRv STtwy37faxkLnYhQsM9G97vHhlE3tXngVQ0mbCUHC3aI4saHeJwCNFhY8G8ROBzDmeqJ LHPA== 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=hDl/Db38I/8hjhyJQ82MPlHsuDrZZmxTNKHPP+GKS3kXvp0/SosOwUP4BT9Nu89Oa0 0WModlSy1EkmzGwU2xFYmmlnzw+UgvvQR4VtsPRH21XAeAZYHA++8SDOs5oCooJ7U8o/ iwc6zA9+AHeX9b7WkvXbJb0MlJKD3n5RcSqEzvCznn5G7oDhbvE57zqL8vQLJYVQcoka NfREXZvORwMCx8y1FnguUammUwUMMzKXRZElgH10zwg66Gv1Tf/xvk4Ynp436lMbSMQ0 gMJoRGY+Qtr1muRNMVlwBRUbdA3sbn7sirWvrUWKj/ze9K/ytpUyHhVlaBnw1LbKNjKU T0Gg== X-Forwarded-Encrypted: i=1; AJvYcCUKeymKlT0APIY1jjmfNi3nvUgRtLHGpy/yrcCwHEhhC7P39/lLYbX9ip0eXzBcUir75eBtKgScRQ==@kvack.org X-Gm-Message-State: AOJu0YzM95p59gUb+EMiDN0xuD92z9ckpVqeQpHFFMfpPjBfzyuM2KVl P/rqED4TJmvzF+xcoQKaIbjdYJbWvlG+GrLgILL0DxOMXyhNkIYCitTDLPKCcY4= 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-Stat-Signature: ih7qew4audukixdyu934m6kefwpkdsio X-Rspamd-Queue-Id: 6F73B18000A X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1729562349-789250 X-HE-Meta: U2FsdGVkX18QdFejfcdeDqc/PGGa34stIZhZIO5GZcz5nIVeda5sBA/CQgaFk4HYtjmuCPVvgntQFYa+waD36p052Rd/O0bbF82ytWlj9RfmtxytS+tgdp4cZwZm9JJQbyqevK61U3yBLw6y7THblLjSIepyI7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mbh5brwLfiqCAdZ13cBeA5s0bxmWRcymhjHZsNpLtUmOpfHvIUboDLQlZivv3NQ/xz7rV1or9ZEIYZeANay1r3A77neP7MI+KOBX3SrdXvkpyd7mf7U9f5wHbc0vYrUb1LUNinMRRyoc/G0Ymr6BJWjqCmH/eG7PG9rvDlef1VGv9ldfjVipXFzEqn9jSxtN8QlLWg1EaxN0BOkLJ5ZTdq0/rLPu+KtYFoSRQ== 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: List-Subscribe: List-Unsubscribe: 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