From patchwork Tue Nov 10 22:10:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11895691 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD765C388F7 for ; Tue, 10 Nov 2020 22:26:08 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 37AB1206B2 for ; Tue, 10 Nov 2020 22:26:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ZmS/O0Ud"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="XwoM493D" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 37AB1206B2 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version:Message-Id: In-Reply-To:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=88o7Qs0ujI0ve14P4lzUgXkpp96DT/bQCIKnWBVi9BQ=; b=ZmS/O0UdlI0uqRlreuBswN5j8 9yhQYw7SF8FGNXWdml5IVy2wGIR/y41uNO3Oi17rJ5e2LLftSm0AvqEzAKOvQwgghskH5kUK5s8CL QtvSLbOR0n2hm0ajWwNpF1G1yiUbWR96MCGGm1bhJoZznDxNKDW43ChzzGu/eS42LRYuiWqRxmuTx PNMWfKUzgisfWyQkTNB2CpYo4QtxtbtBmzJVFHrD25r/yGt8OxMcmLYtP1P5YWz8X6jwUusiKU8CK p4TIFRHAvQrQdnegYqpt9HYCufQRyJTIXl7uvHPpilandERzo6MbEVcxZQRmF5k2X5zs9aYiKOHIj T3ZgRGKAA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcc50-0002VJ-3A; Tue, 10 Nov 2020 22:25:34 +0000 Received: from mail-qk1-x74a.google.com ([2607:f8b0:4864:20::74a]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcbsQ-000508-Ft for linux-arm-kernel@lists.infradead.org; Tue, 10 Nov 2020 22:12:52 +0000 Received: by mail-qk1-x74a.google.com with SMTP id v134so174054qka.19 for ; Tue, 10 Nov 2020 14:12:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=S5GVREd9VqHHCaX+FFNS+NOU5hd6lun6S29ewqSBNuk=; b=XwoM493DRsmqkt6xilLOyWrlTKG+10CwtsIBXxiDYuysKqe8W1Z8yNzJpaiGtL0MlU OWJrAqOrqNYMQ+lv2x31StrZZXWduCh74/scNJxfqh8vvZtc6/VPdbpCXECbSXH6pC2B 86vNnKsKhkGGffR3jZMvjiN8v8HswomR/jNftid5/d1foLR4W2rGS0l5FHwMA9V9vvND BX/vS7NtcWtbRw0G6eVGWCWGaltAtv6BcT8+uKK5P5VQRswRCaGUu+JcIb2sgmNFcqR/ EtQMxGqZTbB40bLtokcITZ7Vd6BDyJCCaLZuUeXyCwNKdayj2S3NQ/veNLGxus+qAW4s ZUAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=S5GVREd9VqHHCaX+FFNS+NOU5hd6lun6S29ewqSBNuk=; b=moFc4zlE+CkFZQHD5C4FIpkEwW/mJdGeTj/poD4BcaZ2ayxLcGyrkKxAq11rKqkHrP 7fAVnqJtZYUuz/ScmYs3mEusX8vMsDKm7D1CykyWR6jlyQWnSid3MRBIo8sCc04vtdSt 09jPl3aDy/rlz8R4c3hQG804YdcshllrXzus2b9e7ppGsls6YGEm7vns7EjhoiGJLLW5 tn4qaRBKQA2IwrRgTtKE11qmETZY9aGZ/LhXOVk0oJwb2Pmv3rPrTxJe5AtXZAOXp3rs uTsuhrj/ev/ShkL01aZz/24afpDs8fP+OqBC6S+6X4/YuwlzZSP/N8g6jADgrOTCpOa8 qgMA== X-Gm-Message-State: AOAM533VrwnV90bHmZYhX21tPECuZKMd9AOrLVQJEQdeJRFTox+TWLyT RwK5DQA4UTEpDQ/d02ALrGVLz1D9aByWLRAS X-Google-Smtp-Source: ABdhPJzC2wAi5b1T1w3VlZYh7/z1S2yPnXtdLFrf+n0SJcixeF++pJ8B/DF1WTwAjZwEDicG+91irs4hKnWppdtB X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:4142:: with SMTP id z2mr8829724qvp.48.1605046350079; Tue, 10 Nov 2020 14:12:30 -0800 (PST) Date: Tue, 10 Nov 2020 23:10:32 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v9 35/44] arm64: kasan: Add arch layer for memory tagging helpers From: Andrey Konovalov To: Catalin Marinas X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201110_171234_615992_DFA66C2A X-CRM114-Status: GOOD ( 16.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Vincenzo Frascino , Dmitry Vyukov Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This patch add a set of arch_*() memory tagging helpers currently only defined for arm64 when hardware tag-based KASAN is enabled. These helpers will be used by KASAN runtime to implement the hardware tag-based mode. The arch-level indirection level is introduced to simplify adding hardware tag-based KASAN support for other architectures in the future by defining the appropriate arch_*() macros. Signed-off-by: Andrey Konovalov Co-developed-by: Vincenzo Frascino Signed-off-by: Vincenzo Frascino Reviewed-by: Catalin Marinas --- Change-Id: I42b0795a28067872f8308e00c6f0195bca435c2a --- arch/arm64/include/asm/memory.h | 9 +++++++++ mm/kasan/kasan.h | 26 ++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index cd61239bae8c..419bbace29d5 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -230,6 +230,15 @@ static inline const void *__tag_set(const void *addr, u8 tag) return (const void *)(__addr | __tag_shifted(tag)); } +#ifdef CONFIG_KASAN_HW_TAGS +#define arch_enable_tagging() mte_enable() +#define arch_init_tags(max_tag) mte_init_tags(max_tag) +#define arch_get_random_tag() mte_get_random_tag() +#define arch_get_mem_tag(addr) mte_get_mem_tag(addr) +#define arch_set_mem_tag_range(addr, size, tag) \ + mte_set_mem_tag_range((addr), (size), (tag)) +#endif /* CONFIG_KASAN_HW_TAGS */ + /* * Physical vs virtual RAM address space conversion. These are * private definitions which should NOT be used outside memory.h diff --git a/mm/kasan/kasan.h b/mm/kasan/kasan.h index b5b00bff358f..ae7def3b725b 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -241,6 +241,32 @@ static inline const void *arch_kasan_set_tag(const void *addr, u8 tag) #define reset_tag(addr) ((void *)arch_kasan_reset_tag(addr)) #define get_tag(addr) arch_kasan_get_tag(addr) +#ifdef CONFIG_KASAN_HW_TAGS + +#ifndef arch_enable_tagging +#define arch_enable_tagging() +#endif +#ifndef arch_init_tags +#define arch_init_tags(max_tag) +#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) ((void *)(addr)) +#endif + +#define hw_enable_tagging() arch_enable_tagging() +#define hw_init_tags(max_tag) arch_init_tags(max_tag) +#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) arch_set_mem_tag_range((addr), (size), (tag)) + +#endif /* CONFIG_KASAN_HW_TAGS */ + /* * Exported functions for interfaces called from assembly or from generated * code. Declarations here to avoid warning about missing declarations.