From patchwork Fri Nov 13 22:16:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11905043 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 D46E7C4742C for ; Fri, 13 Nov 2020 22:32:15 +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 824C721D7F for ; Fri, 13 Nov 2020 22:32:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="sk8tHZiW"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Irv9DM0U" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 824C721D7F 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=EFtPGP2MLjKGUYIKBaAFro4M5aBiW3r75UNtlbnxbzs=; b=sk8tHZiWdVngdXqnCAaV7kb7c sVQdnOfiENxV+0zJ57DFn6ycRfSDbhd0CJ5DhnBF1TYg2faFUYNIsT2t1EvWl5K3Q9N2xSSr0GsuZ D5UuZhPHWsOZfUBO1OCEuHh4M/8QQLpq3acvVCVWaDCgL4d2oajFgk2tUlTIIWWtOxSEZZzptS13G oDNjCFjK8mx6EexB0An3+utqSf36OPWTxQcUaMkXJWiQtI9b0hcLN2zjxF345XC6erRvonnmPjSuf VRuGp3MCeYZ46d4nv7gFWY2KD8gRUZErCgkvM0rSqh7soQJZYz7WHzm4ohZn+vJ4igw+mvyFzUfGv WDO0Rr0Dg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdhbL-0006bW-1l; Fri, 13 Nov 2020 22:31:27 +0000 Received: from mail-qt1-x849.google.com ([2607:f8b0:4864:20::849]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kdhNy-0000MZ-S5 for linux-arm-kernel@lists.infradead.org; Fri, 13 Nov 2020 22:17:52 +0000 Received: by mail-qt1-x849.google.com with SMTP id r29so4537959qtu.21 for ; Fri, 13 Nov 2020 14:17:36 -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=03ZVTANVMndAKxBTmMPKTeOd5fHJJQ7JXgAuJEAynpY=; b=Irv9DM0UsFmGy7ycpfksKZPxPunSrUwyrgROaAlP4JHh1CM806pobQwjXPDjkjMLYu Tq/jrkTfcZROzhXczIWaV8Elw+J8z3dnSxYlgf7ODC6FqBVoKUU1EJufDopynxdzUMXX oEG9EQkz35isWhsi7GBMbioHHVtQhZYN/ML9dSwXuFOI+0OyXJYQb7rnYHnAV/vLtcZo crDYrcmb69AOdmR0kt0n0AYZsNVctwb/jrkqOfxQ2ZzmXKTMSK2ckFl7Cpfd1Ml9ZdDV 130EiUyc0IZt1GuTRPtIFMomwkDMm1fpFt6wCA1ZZscVlA4SrxOzpEklei1UrZLTYuFT Mg0A== 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=03ZVTANVMndAKxBTmMPKTeOd5fHJJQ7JXgAuJEAynpY=; b=XKrF97DV5cb22aBFI5JqpLomjGvmDY5XcZLt4gHGuubLUC0kOGeKFmPgD8ZYdpcBCI N4y6ViCzhUnnCOM89d6tzFNnDB06/5bkzDtW6UU07LZc17HD3B20KWF5XPlt5tvEftYx en8j6bSnaHoEb+QzyH84/u1SHUN8LvdL/TH66ZWzdkuGdVJLTBFXA9YcU/o4Rrk9paXE +oM+KSGezUvwLPaG4une4FxB8H21kQ7UGCrq67WbTX0r1N3AZphHRmwROcrpEtuWogij gBN2AFoOGVMr2XyzbCcS82LsClnySJMgqZrraqWJqWr1BBqT7FD6AjhIszYN8HxeCx8H VuAw== X-Gm-Message-State: AOAM533sEFXamb31VfdLJpCr20yzy3mit/YxFhCj7mQdbDIuWC71KvNq jhQfYNSFgum6E6Y3/osC1qZIDlnn8T1fyFnB X-Google-Smtp-Source: ABdhPJxPrdklPOIoefBKRwfkTEjY5SIiFeAp3x6m0FK3ZXk20c36zYo+UiCHZufgZlMbZaHRuOFGyD9W4i9Te5n/ X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:56ee:: with SMTP id cr14mr4795372qvb.15.1605305854497; Fri, 13 Nov 2020 14:17:34 -0800 (PST) Date: Fri, 13 Nov 2020 23:16:01 +0100 In-Reply-To: Message-Id: <69ccb75b7fc7ec766e05ac62335e14e5bf0c50e2.1605305705.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [PATCH mm v10 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-20201113_171739_051060_827EFA78 X-CRM114-Status: GOOD ( 16.47 ) 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.