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: 11926423 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.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 AC478C63777 for ; Mon, 23 Nov 2020 20:09:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3AC3E20717 for ; Mon, 23 Nov 2020 20:09:49 +0000 (UTC) Authentication-Results: mail.kernel.org; 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 3AC3E20717 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 7E81C6B00B9; Mon, 23 Nov 2020 15:09:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7727C6B00BA; Mon, 23 Nov 2020 15:09:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 526286B00BB; Mon, 23 Nov 2020 15:09:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0220.hostedemail.com [216.40.44.220]) by kanga.kvack.org (Postfix) with ESMTP id 1A68C6B00B9 for ; Mon, 23 Nov 2020 15:09:47 -0500 (EST) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id BE55C1EE6 for ; Mon, 23 Nov 2020 20:09:46 +0000 (UTC) X-FDA: 77516773572.20.bone30_0c0a92b27368 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin20.hostedemail.com (Postfix) with ESMTP id 7B1BA180C07AF for ; Mon, 23 Nov 2020 20:09:46 +0000 (UTC) X-HE-Tag: bone30_0c0a92b27368 X-Filterd-Recvd-Size: 6441 Received: from mail-qk1-f202.google.com (mail-qk1-f202.google.com [209.85.222.202]) by imf48.hostedemail.com (Postfix) with ESMTP for ; Mon, 23 Nov 2020 20:09:45 +0000 (UTC) Received: by mail-qk1-f202.google.com with SMTP id q25so15476827qkm.17 for ; Mon, 23 Nov 2020 12:09:45 -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=gblDE61fAcel08fbzV+CDaqv2FDxaisuCOOHY5/Ml6Mau27D/BRfD/K+RUazoWbyuY 9fk3jH+o/1Xkmunn6YdS1PjPZmwnIciRD0yyW4/wUIndY81EwSTV6tioONDPaOJOHJXX 8is/zeWAV0jzx2ow46Pj8LKEtkIYLhAv1urO2OF2eV1eOd7WDDo/akb6neaJoziAQCGh Eoj3aV55Idm7a5jX5pgPWRj3IIB78JVGlg4195ogVKh66/gGvEEf+5S8GiBRaEHkgnEc luqS2TlZ9zbdtNLXfe5Oey/By5vP/kMSQ8CV82l+fSdx00Um1OS9dJ+4fgOg8iv1kWR0 0TWw== X-Gm-Message-State: AOAM5315yPSFQwH81tti+fP2Al/iWqU6Z5uKJAEhn5JQewL5QhPEJWcM vkF64+qBqZfNLJjFCPyGbK/lJ/8Z8wBYi0j9 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 Cc: Catalin Marinas , Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , kasan-dev@googlegroups.com, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov 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: 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.