From patchwork Mon Nov 2 16:03:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11874327 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 56CBFC00A89 for ; Mon, 2 Nov 2020 16:05:56 +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 D52A02225E for ; Mon, 2 Nov 2020 16:05:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="zQWssKtN"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="eTcXtcdf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D52A02225E 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=UR1snEpS2sCjo4Mh0BmeCOCvb/orAMOn7+L0y3uLiGo=; b=zQWssKtNUkaG+2PtLMOKP91eK t74A01KXRs14O/lQWMDUcKJxRdQe7tBnBbq/1PfFy3Xx6m9f+CzoWT+7ljIHTX+bgKkqze1653Vyn LY7e337eDB49QElLavDvsVJr41tFZazRFz0BNL6YabSyJbGJHjBXNKleIFDcSWXdjwFZ5r5pcJAOq uggHl8NKhlSEqw3W7xfe/Qc1B0YdrrJfE3XUy+zbHBeRwRwYEuT19Cx3axWe1LR2pg+S7MvxE39+o 27hUdCIY2rYcZ2anaQYN0SNgKLLqN7vDoRjJsYEb6vljCGiBAktxUQOzW3sLn4/c3HzWb+9NnPfP0 iBgvS6pDQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kZcKY-0006fg-Nr; Mon, 02 Nov 2020 16:05:14 +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 1kZcJz-0006QF-82 for linux-arm-kernel@lists.infradead.org; Mon, 02 Nov 2020 16:04:44 +0000 Received: by mail-qk1-x74a.google.com with SMTP id f9so8982638qkg.13 for ; Mon, 02 Nov 2020 08:04:37 -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=1lgjgRBViJ2FbMeVeB4B/ij4auA2e+RgHcIDFXlMEDw=; b=eTcXtcdfMvy+WyRtuvyCepkwJ6ocKrkM/ieC4IXk8mo02+7bgRtXbnpPS1nnrK4MPu jYDSZZBx2ojnnb8RSUPjQttkhA0yMtUHxrV0JfStvjLzl/Ock8CHF6cOpqK46YMtJjwd +v7644SuBx4yl2tYa+1nFY1X0iesetVgFBiG3iPcxKcnTqEydGRQIvmnbdmav46A1qbh lgEW9LSIvtCsvgb7FQADBiZLxy7DG5MBupKCzPeL19NWko5Yk4XipowXC6PSQQ6WRH6P EXlg1OKIPJLhYh17zpZiovtKMzy+GiJMsYQvdRH/4dWCqVI6mem5vvDbt2gkTqoCuP0B RLAA== 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=1lgjgRBViJ2FbMeVeB4B/ij4auA2e+RgHcIDFXlMEDw=; b=tLXQumNoYtNeKuXjlciBYjRNLUq5vmIOA0Fr4ROAuEsSeL9y729ro5C2jbbYTvUnCN 9TDTSiMuT+w/W5vSahUorCRYEC6uhuQ1o3MKIns5/IDW+61EmrBTx1w878wiIdK+npPv 2VI1J4IrfFdFC1HNLQUlPrQXAWEzpRYm6lMJwtgFhCFyTbZnhh/SjBIbfi6xGKcmPK2q bTTIi+FNK516UAlFNh6SJ36yNknk0wOcjEDmCE2Ed/7wePcvG3Ub/IA8bYcK8mFis8uh Pm8USaU2XV82QZAevxqUghzFHyZE6/FgYFZN9LeUI79k7SYtIS+pJPH8E7Z+45wna7vM FWKQ== X-Gm-Message-State: AOAM532UpEsNzwV79rBR0tf4JNsjw57hlqzfhZGkXlj3QbBwisEoZfWO NAsN2p0cOrHlXfc/gAmCwTXa1kPPBv4zlbMX X-Google-Smtp-Source: ABdhPJyVr13ENFyTmUBYq3AfGMq6rXuKCfjybVY7GxJsx9eviaTcVoWJD27K8DdccUef3MIgT/vUdvhG7bdx1RZk X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6214:162f:: with SMTP id e15mr23073972qvw.32.1604333076511; Mon, 02 Nov 2020 08:04:36 -0800 (PST) Date: Mon, 2 Nov 2020 17:03:44 +0100 In-Reply-To: Message-Id: <0fa21264ea32a5820bc6ba2ea2049ccd513cd016.1604333009.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.1.341.ge80a0c044ae-goog Subject: [PATCH v7 04/41] arm64: kasan: Add arch layer for memory tagging helpers From: Andrey Konovalov To: Catalin Marinas , Will Deacon X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201102_110439_373873_65AA01BF X-CRM114-Status: GOOD ( 16.60 ) 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 , Elena Petrova , Andrey Konovalov , Kevin Brodsky , 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 ac499456740f..a4db457a9023 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -224,6 +224,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.