From patchwork Mon Nov 23 20:07:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11926619 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=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,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 1D7F5C63697 for ; Mon, 23 Nov 2020 20:23:40 +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 93F0120717 for ; Mon, 23 Nov 2020 20:23:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="JeB3FmQp"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="uWayMXuK" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 93F0120717 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=cvNWkj64t6zB7J5V+aOM6Hd+Vv/p/jwUzyOeKzSOODE=; b=JeB3FmQpm+X8kme0Nej7eBsEN 4y/PlGnxIiXkqGFam61DozG8CGePueV2BPfAtTenPjVO5vwhMB7le3/9hub3mVdqpTjRImI7x5Jsj VL9x9NTNNUm0pDN1jssLmN+kTdgb8GZYf0QKS9eOxA1WP9V3GBv8KqCOR5IamIpjj8fQB56wv4M3A XpiA95sJN6obFWnFsUHuaf0FkgdefLA8JB6SAC7umXMYLsHcHN1f1tKus2Nr4nOSc+p0Irw68WuZx VP+yZCF7Jp6OsD3y8fFh8ui6SjsNkmrecY43Kal/lvB7IQ5NP0Ame9d8ax1B2tEOsxeYK12mI8B9D CeDlBIaIw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1khIMV-0005f2-Qs; Mon, 23 Nov 2020 20:22:59 +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 1khI9p-0008PH-5G for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2020 20:10:03 +0000 Received: by mail-qk1-x74a.google.com with SMTP id 198so15489716qkj.7 for ; Mon, 23 Nov 2020 12:09:47 -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=xwstu1pRxVcUMTNe9jDo3bBYpkf7yAJWDfxoqoLQsg4=; b=uWayMXuKdZWCV1higrGQv2NpqktTtho9GZJFFe0mcghk2JofBBlwlzxFNNAuyBzcnb MnSPmOQMzN+Qkemk7HFCiZNXc6G47pikO3FonIsdFF2kYE+L6KGsi31oInZPAPfvtip4 RzXFmNksxrR6+VTWmHVkR4hON69ypwY4FsbxCbReJ2EjHq+ubye0Meykm6zzeTKy6sRt iFCK088RdDgX5Uxti57MUD3MbacQ39860rUPvwy5MGkReRtqCdLzRMJP0OjveVU3sHyn fe5RteZeEGu/2stD0UtDYfr8h/fD9c+E1+HBE88f13iohLTiaR0b8aoYISnSbwFAF3OP H0rA== 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=xwstu1pRxVcUMTNe9jDo3bBYpkf7yAJWDfxoqoLQsg4=; b=OTcznYZip8uJt3ue0APLxPIi/y/L2ebdC2AGY75Nc/YRbo2Vyg9o7tuObK5sUNfm8N fsK2jRhqwIo3+TGeXGlmV7pYvmTfX8TNKnf/hdgzUYOSf9ZkgbpAC6Qy5bPeWI2oY2ik 2I7L98dyz2CaXfgvVcQnBXmC4Ult2/b454N3kDjtC5U13jtslcGRMeh91i36VxjO9Vpy JJMrEohJbkj+vK/5ZbwfboBUNGefuq4OfMmMRs3vEp1ybM2SwOTQm8/XLNPdQ8YO+Cpq fo7LBITfqhp8/cOzk89WTmDelv1aK/77MvWa7QawoYupReQOeVsIx5dRM8KGioCaI3S4 Lghw== X-Gm-Message-State: AOAM533xHx56JXx+LxC3qgUEu3pdNPPJqTOVdjCcoILh63wTJ0ko9dJe xCrmFSFWvbW7zz2mipSgCv4TmKssZE5pFvUg X-Google-Smtp-Source: ABdhPJyVCH3aV9RtNeLidfSxwK+YqFC9NJxqna13EKgsEqqpHDv7bbr5p0NI6j2KmS4DiR8SqCIix/ia52phMGBM X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:5621:: with SMTP id cb1mr1321441qvb.12.1606162185203; Mon, 23 Nov 2020 12:09:45 -0800 (PST) Date: Mon, 23 Nov 2020 21:07:57 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH mm v11 33/42] arm64: kasan: Add arch layer for memory tagging helpers From: Andrey Konovalov To: Andrew Morton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201123_150953_603999_CD044C78 X-CRM114-Status: GOOD ( 16.84 ) 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 , Catalin Marinas , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Konovalov , Andrey Ryabinin , 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 556cb2d62b5b..3bc08e6cf82e 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_kernel() +#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 3b349a6e799d..bc4f28156157 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -243,6 +243,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.