Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp306974pxa; Thu, 27 Aug 2020 02:55:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzr/pdLdqqEpIVB2Avc1Qkx6AfVdmfiIrEHcLJqyUuiTPRorp287f+2EzAftkT1Gg5DuDAN X-Received: by 2002:aa7:dbd9:: with SMTP id v25mr13915208edt.78.1598522135633; Thu, 27 Aug 2020 02:55:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598522135; cv=none; d=google.com; s=arc-20160816; b=zUjoHiSWhg822mtjzYbd9EPHSPdwiOi5X6zPBzhnPikFMVZyw3T6HJ3/GZWZwAofQx eOC1JYjjjx2GUTkBwDQO/ShSu3lTeKwTB9Dp1hgyeikRJw9+HO+3QYeLNrzyeyg0zVin MNfYoVXuwdNOObM2dziBZfOtQdPTx19QJMwpx2TPluKaIctDJPrhd0cHytJx4Nu6YIMK FIBatmy8SJYdMS8B95ZIzked72+vJ9DemMyZlgLJ9GxpOqAJ3FyzBJ5Jhifeh6vhB2zi n6sKIF2POMqt/DNR2DvOJzvizs3mmmTzHkm2dzxepP8jTCcD/RhcDDxMbdQnnIrSNgVT 0O7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=uFRzcGiihkwUfBGa9/IBa5BcYdbYHLW6QRQUaRAviRI=; b=D7wokwVkIzhU69wgaj/b4vVieZYmgTDAvnrJ6slbA2tX1+uyScyeqSs9qqrcKQdBUA vb+Ao+QivYKC3EGIwLYF6ewudFekj5Wl78i2biAYTLjC6Q1tz+yuu6iLlp7erMgZ9Dbd kcOe02me2osdczfsHWTARG/TEJ2fKBTYrqnghjubfUcs3T9fWd8TWHcXbjdc4S7nhEuT Ra0dvVs0NLjRjXPdpUCxiWaJ8H796RcNI6thCgrg5939BSOM49VHPMo3S4BRCgiaSf6v pWD2/f3dsBM93MatFayVVH3RVPGXiP4SJJp0DHdaUcL4H+qQrKmDDZREqifFfzpJGFeq s1Vg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e11si1016483ejk.250.2020.08.27.02.55.12; Thu, 27 Aug 2020 02:55:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728372AbgH0Jyh (ORCPT + 99 others); Thu, 27 Aug 2020 05:54:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:53056 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728303AbgH0Jye (ORCPT ); Thu, 27 Aug 2020 05:54:34 -0400 Received: from gaia (unknown [46.69.195.127]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BD3A0207CD; Thu, 27 Aug 2020 09:54:31 +0000 (UTC) Date: Thu, 27 Aug 2020 10:54:29 +0100 From: Catalin Marinas To: Andrey Konovalov Cc: Dmitry Vyukov , Vincenzo Frascino , kasan-dev@googlegroups.com, 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 Subject: Re: [PATCH 21/35] arm64: mte: Add in-kernel tag fault handler Message-ID: <20200827095429.GC29264@gaia> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 14, 2020 at 07:27:03PM +0200, Andrey Konovalov wrote: > diff --git a/arch/arm64/mm/fault.c b/arch/arm64/mm/fault.c > index 5e832b3387f1..c62c8ba85c0e 100644 > --- a/arch/arm64/mm/fault.c > +++ b/arch/arm64/mm/fault.c > @@ -33,6 +33,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -222,6 +223,20 @@ int ptep_set_access_flags(struct vm_area_struct *vma, > return 1; > } > > +static bool is_el1_mte_sync_tag_check_fault(unsigned int esr) > +{ > + unsigned int ec = ESR_ELx_EC(esr); > + unsigned int fsc = esr & ESR_ELx_FSC; > + > + if (ec != ESR_ELx_EC_DABT_CUR) > + return false; > + > + if (fsc == ESR_ELx_FSC_MTE) > + return true; > + > + return false; > +} > + > static bool is_el1_instruction_abort(unsigned int esr) > { > return ESR_ELx_EC(esr) == ESR_ELx_EC_IABT_CUR; > @@ -294,6 +309,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) > { > @@ -317,12 +344,16 @@ static void __do_kernel_fault(unsigned long addr, unsigned int esr, > msg = "execute from non-executable memory"; > else > msg = "read from unreadable memory"; > + } else if (is_el1_mte_sync_tag_check_fault(esr)) { > + report_tag_fault(addr, esr, regs); > + msg = "memory tagging extension fault"; IIUC, that's dead code. See my comment below on do_tag_check_fault(). > } else if (addr < PAGE_SIZE) { > msg = "NULL pointer dereference"; > } else { > msg = "paging request"; > } > > + Unnecessary empty line. > die_kernel_fault(msg, addr, esr, regs); > } > > @@ -658,10 +689,27 @@ static int do_sea(unsigned long addr, unsigned int esr, struct pt_regs *regs) > return 0; > } > > +static int do_tag_recovery(unsigned long addr, unsigned int esr, > + struct pt_regs *regs) > +{ > + report_tag_fault(addr, esr, regs); > + > + /* Skip over the faulting instruction and continue: */ > + arm64_skip_faulting_instruction(regs, AARCH64_INSN_SIZE); Ooooh, do we expect the kernel to still behave correctly after this? I thought the recovery means disabling tag checking altogether and restarting the instruction rather than skipping over it. We only skip if we emulated it. > + > + return 0; > +} > + > + > 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); So we never invoke __do_kernel_fault() for a synchronous tag check in the kernel. What's with all the is_el1_mte_sync_tag_check_fault() check above? -- Catalin