From patchwork Tue Sep 15 21:16:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Konovalov X-Patchwork-Id: 11777763 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 DE13B59D for ; Tue, 15 Sep 2020 21:17:24 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9917820770 for ; Tue, 15 Sep 2020 21:17:24 +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="vmOgCDX4" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9917820770 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 A506190008C; Tue, 15 Sep 2020 17:17:22 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id A341990008A; Tue, 15 Sep 2020 17:17:22 -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 8ECE390008C; Tue, 15 Sep 2020 17:17:22 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0005.hostedemail.com [216.40.44.5]) by kanga.kvack.org (Postfix) with ESMTP id 760EF90008A for ; Tue, 15 Sep 2020 17:17:22 -0400 (EDT) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 2FF328249980 for ; Tue, 15 Sep 2020 21:17:22 +0000 (UTC) X-FDA: 77266556724.11.toys18_2a0bbfb27114 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id 0236F180F8B80 for ; Tue, 15 Sep 2020 21:17:21 +0000 (UTC) X-Spam-Summary: 1,0,0,6b27c6fd7daf8446,d41d8cd98f00b204,3yc9hxwokceuhukyl5ru2snvvnsl.jvtspu14-ttr2hjr.vyn@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:3354:3865:3866:3868:3870:3871:3872:4117:4321:4605:5007:6117:6261:6653:6742:7576:9036:9165:9969:10004:10400:11026:11232:11473:11658:11914:12043:12048:12291:12296:12297:12438:12555:12679:12683:12895:12986:14096:14097:14181:14394:14659:14721:21080:21365:21444:21451:21627:21795:21939:21966:21990:30003:30051:30054:30070,0,RBL:209.85.222.201:@flex--andreyknvl.bounces.google.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yrbrr4fwnm1jrddhdu8np8tkbs9ophfa19wk8b5fdte456pgsef9peu3yiwjd.sgjh1d598kwakwnaci3wxz5xdtye4xt6kwqtb6gt37ymwgiwiqfj9i6okcap9pu.s-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF: not bulk X-HE-Tag: toys18_2a0bbfb27114 X-Filterd-Recvd-Size: 6037 Received: from mail-qk1-f201.google.com (mail-qk1-f201.google.com [209.85.222.201]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Tue, 15 Sep 2020 21:17:21 +0000 (UTC) Received: by mail-qk1-f201.google.com with SMTP id 205so4115192qkd.2 for ; Tue, 15 Sep 2020 14:17:21 -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=8gCy5LzCrZ4Ippif5C2Kr6pI1Q8A3vPTLrXylwHP5Is=; b=vmOgCDX4Ovlo+g3q/YjlH2gzNXCBg6oYk1uHca7WFAJy0wEyxCaO7diA4/HQFhbfTm vZCxg8qtkEXtSmNVkwvmd3y9aPHfb1O3HzVcCMYG5GkvRSxpNmSqOEo731jm0j0k1tVu OEKw5b06tRh6HL9jAeFZXqBsP1qLSDni5lS66o6K10BKTIu2Gh3yDizNmuHcNyx++XHH tHYzDWRe+6TQkK1QpWT99yOl6ce7cDGFlAIEDlSgVkns9356jlEzO60Y5PwCulcoS0Vx tVwDbjoZHJktHkYmPTJ4GRQBmCpdAnlxFId4luoMymcP63yZ58/CEn/wg3c6xs89g66t gxGA== 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=8gCy5LzCrZ4Ippif5C2Kr6pI1Q8A3vPTLrXylwHP5Is=; b=D4vzuee78GCAbPgUtIpzpWPxSShi3Dlyz7wkf3dbWbt6rL+cdGaloYvf8nlP0yD/mW 1vWUoXVxH5QZ1+pR9RI71xaumeK/jIcFkeuBHpXsBIA1iYaCrg9iAknnCQ7uI9Rqfmu8 XMEdwHN0n+STnp4+iwoGYryFBonuILSf7HQFGGsl71ga89oK9g9/X7ZLYQtDOlecRfYt 7dPN57Xkd60EZVaeVheJoTEJxsOtZYzQyc/Qlu6DbtG1QhgjLHfCz6rSidEPN7cTdCjW lxe3dxlQ1ZiduQ7Dc+WILK6EYY9p+rToIvixLaO0fZyjrO+3W/zwXufHvWzHefPeo9cc 9Qtw== X-Gm-Message-State: AOAM532Ycq7pYL4Dngousd7c/iuOOFr89z8mCS0t6ryZOh8be4xNRP3o Y/b2QBxOwWcXz8GMJ1eZAbd/qO+LDyh6C4vN X-Google-Smtp-Source: ABdhPJx1hOhDWmjDE0HlzEorlVjxg9QmeE8fIeKQfK3gTvzMzRC6zTbmaUqg7dVWWCVncgIssdu5E4KU6Pu81Z6R X-Received: from andreyknvl3.muc.corp.google.com ([2a00:79e0:15:13:7220:84ff:fe09:7e9d]) (user=andreyknvl job=sendgmr) by 2002:ad4:5745:: with SMTP id q5mr19950252qvx.29.1600204640737; Tue, 15 Sep 2020 14:17:20 -0700 (PDT) Date: Tue, 15 Sep 2020 23:16:06 +0200 In-Reply-To: Message-Id: <7866d9e6f11f12f1bad42c895bf4947addba71c2.1600204505.git.andreyknvl@google.com> Mime-Version: 1.0 References: X-Mailer: git-send-email 2.28.0.618.gf4bc123cb7-goog Subject: [PATCH v2 24/37] arm64: mte: Add in-kernel tag fault handler 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: 0236F180F8B80 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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: From: Vincenzo Frascino Add the implementation of the in-kernel fault handler. When a tag fault happens on a kernel address: * a warning is logged, * MTE is disabled on the current CPU, * the execution continues. When a tag fault happens on a user address: * the kernel executes do_bad_area() and panics. Signed-off-by: Vincenzo Frascino Co-developed-by: Andrey Konovalov Signed-off-by: Andrey Konovalov --- Change-Id: I9b8aa79567f7c45f4d6a1290efcf34567e620717 --- arch/arm64/mm/fault.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c index a3bd189602df..cdc23662691c 100644 --- a/arch/arm64/mm/fault.c +++ b/arch/arm64/mm/fault.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -294,6 +295,18 @@ static void die_kernel_fault(const char *msg, unsigned long addr, do_exit(SIGKILL); } +static void report_tag_fault(unsigned long addr, unsigned int esr, + struct pt_regs *regs) +{ + bool is_write = ((esr & ESR_ELx_WNR) >> ESR_ELx_WNR_SHIFT) != 0; + + pr_alert("Memory Tagging Extension Fault in %pS\n", (void *)regs->pc); + pr_alert(" %s at address %lx\n", is_write ? "Write" : "Read", addr); + pr_alert(" Pointer tag: [%02x], memory tag: [%02x]\n", + mte_get_ptr_tag(addr), + mte_get_mem_tag((void *)addr)); +} + static void __do_kernel_fault(unsigned long addr, unsigned int esr, struct pt_regs *regs) { @@ -641,10 +654,31 @@ static int do_sea(unsigned long addr, unsigned int esr, struct pt_regs *regs) return 0; } +static void do_tag_recovery(unsigned long addr, unsigned int esr, + struct pt_regs *regs) +{ + report_tag_fault(addr, esr, regs); + + /* + * Disable Memory Tagging Extension Tag Checking on the local CPU + * for the current EL. + * It will be done lazily on the other CPUs when they will hit a + * tag fault. + */ + sysreg_clear_set(sctlr_el1, SCTLR_ELx_TCF_MASK, SCTLR_ELx_TCF_NONE); + isb(); +} + + static int do_tag_check_fault(unsigned long addr, unsigned int esr, struct pt_regs *regs) { - do_bad_area(addr, esr, regs); + /* The tag check fault (TCF) is per TTBR */ + if (is_ttbr0_addr(addr)) + do_bad_area(addr, esr, regs); + else + do_tag_recovery(addr, esr, regs); + return 0; }