From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADD96C433E3 for ; Thu, 27 Aug 2020 10:42:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9716C22BF5 for ; Thu, 27 Aug 2020 10:42:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728358AbgH0Kmv (ORCPT ); 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 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5866FC433DF for ; Thu, 27 Aug 2020 10:44:24 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 226BF22B40 for ; Thu, 27 Aug 2020 10:44:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="GuhTl8Dy" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 226BF22B40 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=HIv79OfYFzT+9kDMY2IFvK4Kh0vRUZ1RBq3TS9Xr2Cs=; b=GuhTl8DyDbkX0Pb1ohFIZLh5s 7CIg5G9ER1uQLjGxM/J2W4iXA4aXapp7oB4GvzQIzHJ3p8MAkXIcoYBNtXrxKYEsHcbvDj6vRcKul OeYcS8qI4nmPWj87R3vz9NaWhqdgA+FD2uHmm3tP9WPeOviBdSzvHw5dzcGfBu1UL0wVjwKV0ZO33 7cNOXRaV4Gn/lHnokQg5GFCfnZfks67PJm2FG4QHqjQJOFcBbl+QUiB3dKQ+hkylPzoDrYqsAuYBL S1jyP6vqsqAOzX9EpAm+eGmeVZQuGImmbxakk1EF4jFHGm2d0PYFTjhKsXtH++RYlBgBAIiUlDK3B IbDQy+nFw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBFMv-000068-Dl; Thu, 27 Aug 2020 10:42:57 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBFMs-00004z-A9 for linux-arm-kernel@lists.infradead.org; Thu, 27 Aug 2020 10:42:55 +0000 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 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-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200827_064254_452081_B1D7AF49 X-CRM114-Status: GOOD ( 25.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Elena Petrova , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , Andrew Morton , Evgenii Stepanov Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel