From mboxrd@z Thu Jan 1 00:00:00 1970 From: Catalin Marinas Subject: Re: [PATCH 13/22] arm64: mte: Handle synchronous and asynchronous tag check faults Date: Tue, 17 Dec 2019 18:01:52 +0000 Message-ID: <20191217180152.GO5624@arrakis.emea.arm.com> References: <20191211184027.20130-1-catalin.marinas@arm.com> <20191211184027.20130-14-catalin.marinas@arm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=m.gmane.org@lists.infradead.org To: Peter Collingbourne Cc: linux-arch@vger.kernel.org, Richard Earnshaw , linux-mm@kvack.org, Szabolcs Nagy , Marc Zyngier , Kevin Brodsky , Kostya Serebryany , Evgenii Stepanov , Andrey Konovalov , Vincenzo Frascino , Will Deacon , Linux ARM List-Id: linux-arch.vger.kernel.org On Fri, Dec 13, 2019 at 05:43:15PM -0800, Peter Collingbourne wrote: > On Wed, Dec 11, 2019 at 10:44 AM Catalin Marinas > wrote: > > diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c > > index dd2cdc0d5be2..41fae64af82a 100644 > > --- a/arch/arm64/kernel/signal.c > > +++ b/arch/arm64/kernel/signal.c > > @@ -730,6 +730,9 @@ static void setup_return(struct pt_regs *regs, struct k_sigaction *ka, > > regs->regs[29] = (unsigned long)&user->next_frame->fp; > > regs->pc = (unsigned long)ka->sa.sa_handler; > > > > + /* TCO (Tag Check Override) always cleared for signal handlers */ > > + regs->pstate &= ~PSR_TCO_BIT; > > + > > if (ka->sa.sa_flags & SA_RESTORER) > > sigtramp = ka->sa.sa_restorer; > > else > > @@ -921,6 +924,11 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, > > if (thread_flags & _TIF_UPROBE) > > uprobe_notify_resume(regs); > > > > + if (thread_flags & _TIF_MTE_ASYNC_FAULT) { > > + clear_thread_flag(TIF_MTE_ASYNC_FAULT); > > + force_signal_inject(SIGSEGV, SEGV_MTEAERR, 0); > > In the case where the kernel is entered due to a syscall, this will > inject a signal, but only after servicing the syscall. This means > that, for example, if the syscall is exit(), the async tag check > failure will be silently ignored. I can reproduce the problem with the > program below: [...] > This patch fixes the problem for me: > > diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c > index 9a9d98a443fc..d0c8918dee00 100644 > --- a/arch/arm64/kernel/syscall.c > +++ b/arch/arm64/kernel/syscall.c > @@ -94,6 +94,8 @@ static void el0_svc_common(struct pt_regs *regs, int > scno, int sc_nr, > const syscall_fn_t syscall_table[]) > { > unsigned long flags = current_thread_info()->flags; > + if (flags & _TIF_MTE_ASYNC_FAULT) > + return; It needs a bit of thinking. This one wouldn't work if you want to handle the signal and resume since it would skip the SVC instruction. We'd need at least to do a regs->pc -= 4 and probably move it further down in this function. -- Catalin From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com ([217.140.110.172]:44004 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727754AbfLQSB4 (ORCPT ); Tue, 17 Dec 2019 13:01:56 -0500 Date: Tue, 17 Dec 2019 18:01:52 +0000 From: Catalin Marinas Subject: Re: [PATCH 13/22] arm64: mte: Handle synchronous and asynchronous tag check faults Message-ID: <20191217180152.GO5624@arrakis.emea.arm.com> References: <20191211184027.20130-1-catalin.marinas@arm.com> <20191211184027.20130-14-catalin.marinas@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-arch-owner@vger.kernel.org List-ID: To: Peter Collingbourne Cc: Evgenii Stepanov , Kostya Serebryany , Linux ARM , linux-arch@vger.kernel.org, Richard Earnshaw , Szabolcs Nagy , Marc Zyngier , Kevin Brodsky , linux-mm@kvack.org, Andrey Konovalov , Vincenzo Frascino , Will Deacon Message-ID: <20191217180152.MeK-9z69FDaZO3GsMTpS4b4a_KH-aOsrFLUFgC_qcWc@z> On Fri, Dec 13, 2019 at 05:43:15PM -0800, Peter Collingbourne wrote: > On Wed, Dec 11, 2019 at 10:44 AM Catalin Marinas > wrote: > > diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c > > index dd2cdc0d5be2..41fae64af82a 100644 > > --- a/arch/arm64/kernel/signal.c > > +++ b/arch/arm64/kernel/signal.c > > @@ -730,6 +730,9 @@ static void setup_return(struct pt_regs *regs, struct k_sigaction *ka, > > regs->regs[29] = (unsigned long)&user->next_frame->fp; > > regs->pc = (unsigned long)ka->sa.sa_handler; > > > > + /* TCO (Tag Check Override) always cleared for signal handlers */ > > + regs->pstate &= ~PSR_TCO_BIT; > > + > > if (ka->sa.sa_flags & SA_RESTORER) > > sigtramp = ka->sa.sa_restorer; > > else > > @@ -921,6 +924,11 @@ asmlinkage void do_notify_resume(struct pt_regs *regs, > > if (thread_flags & _TIF_UPROBE) > > uprobe_notify_resume(regs); > > > > + if (thread_flags & _TIF_MTE_ASYNC_FAULT) { > > + clear_thread_flag(TIF_MTE_ASYNC_FAULT); > > + force_signal_inject(SIGSEGV, SEGV_MTEAERR, 0); > > In the case where the kernel is entered due to a syscall, this will > inject a signal, but only after servicing the syscall. This means > that, for example, if the syscall is exit(), the async tag check > failure will be silently ignored. I can reproduce the problem with the > program below: [...] > This patch fixes the problem for me: > > diff --git a/arch/arm64/kernel/syscall.c b/arch/arm64/kernel/syscall.c > index 9a9d98a443fc..d0c8918dee00 100644 > --- a/arch/arm64/kernel/syscall.c > +++ b/arch/arm64/kernel/syscall.c > @@ -94,6 +94,8 @@ static void el0_svc_common(struct pt_regs *regs, int > scno, int sc_nr, > const syscall_fn_t syscall_table[]) > { > unsigned long flags = current_thread_info()->flags; > + if (flags & _TIF_MTE_ASYNC_FAULT) > + return; It needs a bit of thinking. This one wouldn't work if you want to handle the signal and resume since it would skip the SVC instruction. We'd need at least to do a regs->pc -= 4 and probably move it further down in this function. -- Catalin