From patchwork Wed Nov 4 23:18:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11883089 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 8AA94C388F9 for ; Thu, 5 Nov 2020 04:09:18 +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 E6C0A20786 for ; Thu, 5 Nov 2020 04:09:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="E0NCdsDN"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="eXeljIC2"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="MDmPTXJQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E6C0A20786 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=CpsfVXkUE3O+vAiz+B/wgJfsABriPgCspWLUvgQkJuk=; b=E0NCdsDNLHuAMI9tm1IVQPNA+ 28BikVc9m2I2ffSUcDDIfPLRis4sDhBJTg7immCMuxBZftiVh6gtxwHB4dZPY7el02DD1vstfqjkq 51zDQm+2YDewGr9oQX6E+lg1BxopOALTcli7dPzMId6NfV7b4Hk4RIZBsC5YAfS6XSCfyGN/ZUQnC 0wTbZsAgEfSV4SSrbtHBSOqh1FejCz1GTToT3plGsuu4derqcxtSfsbtlWUXxrf9vOYUx33D0/ZnH UQ586xfCxqh9Ih9dFS/o/jaJ1mwAj4h6XzM2zZfKWN1aQxfZPrC0aoVbIhCFEHarvYC9FKi+lEETu jriHNy4kw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaWZ1-0003Y9-8N; Thu, 05 Nov 2020 04:07:55 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaW56-000145-MU for linux-arm-kernel@merlin.infradead.org; Thu, 05 Nov 2020 03:37:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=VwB+r0G+nQxE1tuBjegw7DUOaY0AiMb9tMmTZBhg6+8=; b=eXeljIC2raKiOdUVPq1Ycgk806 TQNjTywLkuvo3ic0cQ24niHjSS85S015g9IW8it58LNqTrKo/kNwsRHvbghII+yygszzKq/SQgQTa Yj5t/47hNiVZSB8LzY/YEpDKfP7o+FW7F/L0jcDefaVfMrcst2l2kvPOLp8vZIBamu+YeLyMFKKW0 XNIakO/6TbG4+AlNYfckYcT/gQPvkuOssv0P9ipPU7JTgmMVYg/W5FoMYq69C/gG0Jg0JvxejAkmJ angzbsXsZtXfl35xxHg+9NpDoQEXYrwcFysKPg1ob1jxS91ARxkBXc+ETFqvbKEnhw4XucSnMewHV I9cPqrqg==; Received: from mail-wm1-x349.google.com ([2a00:1450:4864:20::349]) by casper.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kaS5s-00048s-6b for linux-arm-kernel@lists.infradead.org; Wed, 04 Nov 2020 23:21:34 +0000 Received: by mail-wm1-x349.google.com with SMTP id o19so28271wme.2 for ; Wed, 04 Nov 2020 15:21: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=VwB+r0G+nQxE1tuBjegw7DUOaY0AiMb9tMmTZBhg6+8=; b=MDmPTXJQevl3NQ6pPgEvXpSSQtSuvY2cTzhAh3FiI69d33h3RwvxrJF8DhF4f9ozzW 38bGuVV/PLZ/cPT/AlhSH3FfbpQN9mZJ58knWztbqd6E7JMGFYQ7XWAqQyJfnNNNGDFw d5rl22jSmqJvbLqs0mPj/8hYcvCcQFMBIfiWQyKhKZRnxiW4bT/I5A56UDSnrNFCF/vA P6FRc3aJRnfbADBibKj/h59pLcE+PT8sseLnPTzIatx6eW/X7jX8BiGJ6FrffbHcc4/Z 58x0qGiCyUk2TeU4RU2RgD61GpjPYNjkeeQTO/N9ew2p8fegRjyWCv//Rs5tIMfLiwRu GxJA== 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=VwB+r0G+nQxE1tuBjegw7DUOaY0AiMb9tMmTZBhg6+8=; b=HTxdEZWGXsf9660mTThJeXSGC6oOKAIXH6TqDZabXqgl16hsKiw9VSY7lRy+LsbXqu HigSRAvTrsEB9fcEBr/HL92q3sPxluz16SINPrq14CuyjOgtRAOysmJek7xHdOxzn0aD v0t9I/zghDN5XHb+p64D9JoJdD5CEtzQMobPebNCLm+xd2CMSSeVMo3QQu5CK5j4SOiG jHdnlUGpIYQzjYBoSPBZsGa30RsAZN0lgwTJbSCLKaOjJJmljmFr3Z5gjCqeTa7uNsU8 uodfzC6yZDtaeBxq+pw1Mu32OqvGgdk5FjnNZOLKyGXimnEmjHBVG96E+Mxhj0Nncab5 tgrw== X-Gm-Message-State: AOAM533MjJimgr1P/wIbofqNQsekFlwZz+e4Y2YpRawR9VtHyZ08yjlG irRZQktXWX4NY9coAqqLiWTrOq9xcAJVuvXe X-Google-Smtp-Source: ABdhPJxroHsqJ2INmWm39MqryU/d9TuUcrDwnrdfUwfCHfE74IyGC4tjThzYCtzqtdPk9orQeLHnvF6nrHhjcgxf X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a7b:c101:: with SMTP id w1mr80924wmi.170.1604532028927; Wed, 04 Nov 2020 15:20:28 -0800 (PST) Date: Thu, 5 Nov 2020 00:18:49 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v8 34/43] 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-20201104_232132_398800_4F27D9EF X-CRM114-Status: GOOD ( 13.41 ) 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 | 8 ++++++++ mm/kasan/kasan.h | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index cd61239bae8c..580d6ef17079 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -230,6 +230,14 @@ 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_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..e3cd6a3d2b23 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -241,6 +241,28 @@ 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_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_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.