From patchwork Tue Nov 10 22:10:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11895575 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3E72D138B for ; Tue, 10 Nov 2020 22:12:34 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EE5D820637 for ; Tue, 10 Nov 2020 22:12:33 +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="XwoM493D" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EE5D820637 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 2956D6B00B7; Tue, 10 Nov 2020 17:12:32 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 24B9E6B00B8; Tue, 10 Nov 2020 17:12:32 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E6E36B00B9; Tue, 10 Nov 2020 17:12:32 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0194.hostedemail.com [216.40.44.194]) by kanga.kvack.org (Postfix) with ESMTP id D20876B00B7 for ; Tue, 10 Nov 2020 17:12:31 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 82CE98249980 for ; Tue, 10 Nov 2020 22:12:31 +0000 (UTC) X-FDA: 77469908502.25.north86_1a0a82f272f8 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin25.hostedemail.com (Postfix) with ESMTP id 5A8B91804E3A8 for ; Tue, 10 Nov 2020 22:12:31 +0000 (UTC) X-Spam-Summary: 1,0,0,635e93c1a1c736ae,d41d8cd98f00b204,3thcrxwokcb85i8m9tfiqgbjjbg9.7jhgdips-hhfq57f.jmb@flex--andreyknvl.bounces.google.com,,RULES_HIT:41:152:355:379:541:800:960:973:988:989:1260:1277:1313:1314:1345:1359:1431:1437:1516:1518:1535:1543:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2693:3138:3139:3140:3141:3142:3152:3353:3865:3866:3867:3870:3871:4117:4250:4321:4605:5007:6261:6653:6742:7903:8603:9969:10004:10400:11026:11232:11473:11657:11658:11914:12043:12291:12297:12438:12555:12895:12986:13149:13161:13229:13230:14096:14097:14181:14394:14659:14721:21080:21365:21433:21444:21451:21627:21990:30003:30012:30054,0,RBL:209.85.160.201:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-66.100.201.100 62.18.0.100;04yggcmxipdmi41w8omexfyucrgihycjb5xu8r5fs49nq4u4nykbajcsza3o7hc.xazcwx1t9sgnk3yknp3c1fkmkxwdafkswiq9q9zpzsjozzfehum3t7i9njcjff5.k-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0 ,DNSBL:n X-HE-Tag: north86_1a0a82f272f8 X-Filterd-Recvd-Size: 6428 Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Nov 2020 22:12:30 +0000 (UTC) Received: by mail-qt1-f201.google.com with SMTP id o1so2146190qtp.7 for ; Tue, 10 Nov 2020 14:12:30 -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=S5GVREd9VqHHCaX+FFNS+NOU5hd6lun6S29ewqSBNuk=; b=XwoM493DRsmqkt6xilLOyWrlTKG+10CwtsIBXxiDYuysKqe8W1Z8yNzJpaiGtL0MlU OWJrAqOrqNYMQ+lv2x31StrZZXWduCh74/scNJxfqh8vvZtc6/VPdbpCXECbSXH6pC2B 86vNnKsKhkGGffR3jZMvjiN8v8HswomR/jNftid5/d1foLR4W2rGS0l5FHwMA9V9vvND BX/vS7NtcWtbRw0G6eVGWCWGaltAtv6BcT8+uKK5P5VQRswRCaGUu+JcIb2sgmNFcqR/ EtQMxGqZTbB40bLtokcITZ7Vd6BDyJCCaLZuUeXyCwNKdayj2S3NQ/veNLGxus+qAW4s ZUAQ== 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=S5GVREd9VqHHCaX+FFNS+NOU5hd6lun6S29ewqSBNuk=; b=A2Y0/iCEiY92FaoAUiMUyI3btvSre/9Ku4Jzx3s/JVXmaNSEnYk+Zw/S/KCtWMLaxO x19LwMbaRB50Wlln9AQeSSAqqtSegVDvUtZFebRhpus92NjQgZzTXmriSBj0n3KqQjFo Nkpy6ocCvqCWJlE8tASpVBaoD3JGU5ElED0e5LwEu+/KdJf++eVQ+W84FGH5OUMxoa5o AxpaScWsIf6Fx1yMcert4iqrtAQDNIsOmXBSLswQncabjbwA8fGBNbr9sP3OJ0uloz09 l4tBUqhjC9ZTiTqs3LGhpvWZZ9Orf4vkvNFMR9wXe+PdRD0bcC8MoncPLv6yTouYnRtW KXhw== X-Gm-Message-State: AOAM53359nYLCDpXXU6vhDb/HMxHWIaPdVbpS9PjcJ9z+mJl6NIYvHlb QhAxwNmGub1A9sQe6DuNM4HqejfPyPZtLooj X-Google-Smtp-Source: ABdhPJzC2wAi5b1T1w3VlZYh7/z1S2yPnXtdLFrf+n0SJcixeF++pJ8B/DF1WTwAjZwEDicG+91irs4hKnWppdtB X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:4142:: with SMTP id z2mr8829724qvp.48.1605046350079; Tue, 10 Nov 2020 14:12:30 -0800 (PST) Date: Tue, 10 Nov 2020 23:10:32 +0100 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog Subject: [PATCH v9 35/44] arm64: kasan: Add arch layer for memory tagging helpers From: Andrey Konovalov To: Catalin Marinas Cc: Will Deacon , Vincenzo Frascino , Dmitry Vyukov , Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Branislav Rankov , Kevin Brodsky , Andrew Morton , 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 cd61239bae8c..419bbace29d5 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() +#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..ae7def3b725b 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -241,6 +241,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.