Received: by 2002:a05:6a10:6006:0:0:0:0 with SMTP id w6csp332746pxa; Thu, 27 Aug 2020 03:45:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYwrIgRSPEkaXuWgIy3LoBGjX/Fwel1+zo0C5X7ef4T/jCRRADy/Y5MFAzsD1/kDkjTyN1 X-Received: by 2002:a17:906:6853:: with SMTP id a19mr15465700ejs.506.1598525121368; Thu, 27 Aug 2020 03:45:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598525121; cv=none; d=google.com; s=arc-20160816; b=u+jhKz+U7xoMqP53rEtYivR856tOeYv89ncTOXZwLVbyjBcO6vughwtX1IzuGSVHax p7NrQ/G8IhC9CGMWxzrN63Q17welHyfrIrwDJA01O2DrfCWOC/oAABVUbysiAFdy96S+ ETJIV0+TAjkiB9QsG1pwW0B8zhK725xe1PpKJ9C7VZO6sVNdyng6XbkQABDkZa6o6Jhk YZrPDePbF0reW8OxXUCSP5iK/PKzPGKl/GqeTV6WrxssKRapWch/Tes6axyPUVh5NUwT a2aUq1S0AFir4VBSLuEE7rsuPtOSSVgr14IT5dUoHUXPV2RCO3q6k4kjdOX8zwZLLdvK nbZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=65nW4OgXjg/gayn4pYv5jGrcIrH3Et8tOSI0rX3E+sk=; b=iFvzetBdp+cLIEAdoJhQlrAsUJhwPy8Sn9gFqJfrp4dsrzOEWwVKMcbSpKN4SKDS0h hjsJD2TLNrWVmflPbQEX8YdbSp/yj/IbrFGw097jWBjiW3tCdqFMvHtszYARUiYrwiWR XKPwQQqFea1em4pVk0hTrTjcac4Xwz1hnL418QH9jFzkECOi2i5324zsKZnwG69n3Bus 6WUlDbZlDpgY22vnCAkDmg95zJOyPT2g8CMKQv/rxRm2M96a7wXYbHfFwnrm0W+IAawp kFGdLPf6rnxg/f8hBJ3wgbaL/MnJ6wYVWHlMjLYO9TSVcDmrS4JGhwKh8AGg8VzAcBNe 5G4g== 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 cz6si1506351edb.188.2020.08.27.03.44.57; Thu, 27 Aug 2020 03:45:21 -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 S1728063AbgH0Kmv (ORCPT + 99 others); Thu, 27 Aug 2020 06:42:51 -0400 Received: from foss.arm.com ([217.140.110.172]:56546 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726851AbgH0Kmu (ORCPT ); Thu, 27 Aug 2020 06:42:50 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 611E8101E; Thu, 27 Aug 2020 03:42:49 -0700 (PDT) Received: from [192.168.1.190] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 0285D3F66B; Thu, 27 Aug 2020 03:42:45 -0700 (PDT) Subject: Re: [PATCH 21/35] arm64: mte: Add in-kernel tag fault handler To: Catalin Marinas , Andrey Konovalov Cc: Dmitry Vyukov , 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 References: <20200827095429.GC29264@gaia> From: Vincenzo Frascino Message-ID: Date: Thu, 27 Aug 2020 11:44:58 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200827095429.GC29264@gaia> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/27/20 10:54 AM, Catalin Marinas wrote: > 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(). > That's correct. This was useful with "panic_on_mte_fault" kernel command line parameter. Since it has now been replaced by a similar kasan feature, this code can be safely removed. >> } else if (addr < PAGE_SIZE) { >> msg = "NULL pointer dereference"; >> } else { >> msg = "paging request"; >> } >> >> + > > Unnecessary empty line. > Agree. >> 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. > I tried to dig it out but I am not sure why we need this as well. >> + >> + 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? > That's correct. This had a meaning with "panic_on_mte_fault" but since the feature has been replaced is_el1_mte_sync_tag_check_fault() is not useful anymore. -- Regards, Vincenzo