From patchwork Tue Sep 15 21:16:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777761 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 D7D366CA for ; Tue, 15 Sep 2020 21:17:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8F3412078E for ; Tue, 15 Sep 2020 21:17:22 +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="BMgCiDxI" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8F3412078E 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 039EE90008B; Tue, 15 Sep 2020 17:17:21 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id F2FB990008A; Tue, 15 Sep 2020 17:17:20 -0400 (EDT) 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 E43DE90008B; Tue, 15 Sep 2020 17:17:20 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0086.hostedemail.com [216.40.44.86]) by kanga.kvack.org (Postfix) with ESMTP id CF96190008A for ; Tue, 15 Sep 2020 17:17:20 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 9DF488249980 for ; Tue, 15 Sep 2020 21:17:20 +0000 (UTC) X-FDA: 77266556640.09.music58_5a0408427114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id 6B3AC180AD81F for ; Tue, 15 Sep 2020 21:17:20 +0000 (UTC) X-Spam-Summary: 1,0,0,47ec04d40f82adaf,d41d8cd98f00b204,3xi9hxwokcemfsiwj3ps0qlttlqj.htrqnsz2-rrp0fhp.twl@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:1542: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:12048:12297:12438:12555:12895:12986:13149:13161:13229:13230:14181:14394:14659:14721:21080:21365:21433:21444:21451:21627:21990:30003:30012:30054,0,RBL:209.85.208.74:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.84.100 66.100.201.100;04y8dta39xjs3zppf7fw78urundahycxs8cioen1m9gpbjrg81jfkboyqzbng6c.ebeb97qjk69q1ogzqy58trtnriffp8st59rnm196yd4mfwbb6kybf9xekqjtpx9.y-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:neutr al,Custo X-HE-Tag: music58_5a0408427114 X-Filterd-Recvd-Size: 6155 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf03.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:19 +0000 (UTC) Received: by mail-ed1-f74.google.com with SMTP id d13so1776609edz.18 for ; Tue, 15 Sep 2020 14:17:19 -0700 (PDT) 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=uQBUcw70N5/pZNHz2QWMX765YU53M7496uPmAAbH/iU=; b=BMgCiDxI+ewSN9duc+vPhe1zL2wKt3c6rQlKYz9QH0ToEvMf9sfoL11ylpKV3yAh4t oALaiLPmKJtO5+cn5UwTLE5xrflMtIwwKQQj+kzXXG8bipIoxcKPpay1Pm37fb4lRf0+ W6NOp5qYE/ik0nutl3QC6yPy5/M4NVt8dzp09IBcnMvPV3OrigakDyyt1sI8LJi+kdKu vrK/smCBgTxnx2bBlpJKODNo5p5lX2c20XklJ5LKqv+YYdcyFPtVo+PBEuEQBdesT8l1 u+qj0kr40IC0Ark3xu2y4Ic/2Y+pTpby0p0pJqKia3b7oH5zmigy+cSlmRQ8HvgTACO5 ZBfw== 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=uQBUcw70N5/pZNHz2QWMX765YU53M7496uPmAAbH/iU=; b=QwJ/4FQ6dsxEPdiXzWrX01ndB20tCUHpPc6U2v2uamve7QmnaW9o+NaIueUB4tnuuM fZ1NIEKBj8zHb1xTNZjBLgkVyyy+psA3wmF2WqrD/RiZWBCYmcHYvoAy35xx+kOkKQac GkhYlX7dzHejpF2WPAEXc8O2fAEIiZ1llLFLwfd/zRGd9IzvtVc6L0cUEf6rP4HY6XeE eJRUfgjWtsjzQzIBYvLShqVfIwWQe+NX7Ye9DJCzE8+Q5mAY5sqSxUkvFMudJ5cGFISF yUO9NKE/u9tu7Y1np4y1VppX6rD+BHn2Po2eIogUoEWxABHDUp4qRfgQTA7aqbdyKLDj 0eow== X-Gm-Message-State: AOAM533F+vRwnpbj2Gm78e5ZAeyU8uIqOQh7BXJiCJOzMyyTiTODDpVL G+4kO2CEjeO5Xn1SGn3ykJr10Ot/L8/d1wSX X-Google-Smtp-Source: ABdhPJwWctjYlK1i0RQ9U5rwbx1MXyXTqF8P/2W35vyRuLyCkaQtqJgTmv97oJ7dLulE5XOcJgCU96m1Yrxfbnde X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:a05:6402:18d:: with SMTP id r13mr23596971edv.267.1600204638418; Tue, 15 Sep 2020 14:17:18 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:05 +0200 In-Reply-To: Message-Id: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 23/37] arm64: kasan: Add arch layer for memory tagging helpers From: Andrey Konovalov To: Dmitry Vyukov , Vincenzo Frascino , Catalin Marinas , kasan-dev@googlegroups.com Cc: Andrey Ryabinin , Alexander Potapenko , Marco Elver , Evgenii Stepanov , Elena Petrova , Branislav Rankov , Kevin Brodsky , Will Deacon , Andrew Morton , linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov X-Rspamd-Queue-Id: 6B3AC180AD81F X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam03 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 | 8 ++++++++ mm/kasan/kasan.h | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/arch/arm64/include/asm/memory.h b/arch/arm64/include/asm/memory.h index e424fc3a68cb..268a3b6cebd2 100644 --- a/arch/arm64/include/asm/memory.h +++ b/arch/arm64/include/asm/memory.h @@ -231,6 +231,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 1d3c7c6ce771..8b43fc163ed1 100644 --- a/mm/kasan/kasan.h +++ b/mm/kasan/kasan.h @@ -240,6 +240,25 @@ 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) +#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 init_tags(max_tag) arch_init_tags(max_tag) +#define get_random_tag() arch_get_random_tag() +#define get_mem_tag(addr) arch_get_mem_tag(addr) +#define set_mem_tag_range(addr, size, tag) \ + arch_set_mem_tag_range((addr), (size), (tag)) + /* * Exported functions for interfaces called from assembly or from generated * code. Declarations here to avoid warning about missing declarations.