From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A6B2A1C9EA5 for ; Tue, 6 Aug 2024 13:33:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722951236; cv=none; b=X/hWZpUjG5wHL7o8gZdkgBsNWHarVRegc5BJX9n2W4RRlfqYP1o5eV/KLJZefzgQQnJ9ghDe7PmZRLowLr5ieie6nFd1xJvfpZ4jFjvu0lPcc049TRiFjWiloVczpuwR4abxSR5aYaEd4/nSGlhg68Z8btCkT5hmCKaFn1RTlOc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722951236; c=relaxed/simple; bh=YdUDJoZXiC2IxpC7H5Bj19M4R1HDptmgeXEq2KSWL7I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=po00m9KORJGvAyUHtRCXbzLvOpGZ5eLw1XlhYEe4C6wSA7pD4Zs3OCfmpJrSbP/Y6qwQq7JEwxOw03NvCIM0pb18Sz5mquQ297yOi9WA0g1qT47UEqtLWK+7dyRwfjjn+K8kIyypFjM5aTsmBE6NpaemxSzeAa1lH4FlaOppJSQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 C287DFEC; Tue, 6 Aug 2024 06:34:18 -0700 (PDT) Received: from e133380.arm.com (e133380.arm.com [10.1.197.55]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1780C3F766; Tue, 6 Aug 2024 06:33:49 -0700 (PDT) Date: Tue, 6 Aug 2024 14:33:37 +0100 From: Dave Martin To: Joey Gouly Cc: linux-arm-kernel@lists.infradead.org, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, christophe.leroy@csgroup.eu, dave.hansen@linux.intel.com, hpa@zytor.com, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, maz@kernel.org, mingo@redhat.com, mpe@ellerman.id.au, naveen.n.rao@linux.ibm.com, npiggin@gmail.com, oliver.upton@linux.dev, shuah@kernel.org, szabolcs.nagy@arm.com, tglx@linutronix.de, will@kernel.org, x86@kernel.org, kvmarm@lists.linux.dev Subject: Re: [PATCH v4 15/29] arm64: handle PKEY/POE faults Message-ID: References: <20240503130147.1154804-1-joey.gouly@arm.com> <20240503130147.1154804-16-joey.gouly@arm.com> <20240801160110.GC841837@e124191.cambridge.arm.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240801160110.GC841837@e124191.cambridge.arm.com> Hi, On Thu, Aug 01, 2024 at 05:01:10PM +0100, Joey Gouly wrote: > On Thu, Jul 25, 2024 at 04:57:09PM +0100, Dave Martin wrote: > > On Fri, May 03, 2024 at 02:01:33PM +0100, Joey Gouly wrote: > > > If a memory fault occurs that is due to an overlay/pkey fault, report that to > > > userspace with a SEGV_PKUERR. > > > > > > Signed-off-by: Joey Gouly > > > Cc: Catalin Marinas > > > Cc: Will Deacon > > > --- > > > arch/arm64/include/asm/traps.h | 1 + > > > arch/arm64/kernel/traps.c | 12 ++++++-- > > > arch/arm64/mm/fault.c | 56 ++++++++++++++++++++++++++++++++-- > > > 3 files changed, 64 insertions(+), 5 deletions(-) > > > > > > diff --git a/arch/arm64/include/asm/traps.h b/arch/arm64/include/asm/traps.h > > > index eefe766d6161..f6f6f2cb7f10 100644 > > > --- a/arch/arm64/include/asm/traps.h > > > +++ b/arch/arm64/include/asm/traps.h > > > @@ -25,6 +25,7 @@ try_emulate_armv8_deprecated(struct pt_regs *regs, u32 insn) > > > void force_signal_inject(int signal, int code, unsigned long address, unsigned long err); > > > void arm64_notify_segfault(unsigned long addr); > > > void arm64_force_sig_fault(int signo, int code, unsigned long far, const char *str); > > > +void arm64_force_sig_fault_pkey(int signo, int code, unsigned long far, const char *str, int pkey); > > > void arm64_force_sig_mceerr(int code, unsigned long far, short lsb, const char *str); > > > void arm64_force_sig_ptrace_errno_trap(int errno, unsigned long far, const char *str); > > > > > > diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c > > > index 215e6d7f2df8..1bac6c84d3f5 100644 > > > --- a/arch/arm64/kernel/traps.c > > > +++ b/arch/arm64/kernel/traps.c > > > @@ -263,16 +263,24 @@ static void arm64_show_signal(int signo, const char *str) > > > __show_regs(regs); > > > } > > > > > > -void arm64_force_sig_fault(int signo, int code, unsigned long far, > > > - const char *str) > > > +void arm64_force_sig_fault_pkey(int signo, int code, unsigned long far, > > > + const char *str, int pkey) > > > { > > > arm64_show_signal(signo, str); > > > if (signo == SIGKILL) > > > force_sig(SIGKILL); > > > + else if (code == SEGV_PKUERR) > > > + force_sig_pkuerr((void __user *)far, pkey); > > > > Is signo definitely SIGSEGV here? It looks to me like we can get in > > here for SIGBUS, SIGTRAP etc. > > > > si_codes are not unique between different signo here, so I'm wondering > > whether this should this be: > > > > else if (signo == SIGSEGV && code == SEGV_PKUERR) > > > > ...? > > > > > > > else > > > force_sig_fault(signo, code, (void __user *)far); > > > } > > > > > > +void arm64_force_sig_fault(int signo, int code, unsigned long far, > > > + const char *str) > > > +{ > > > + arm64_force_sig_fault_pkey(signo, code, far, str, 0); > > > > Is there a reason not to follow the same convention as elsewhere, where > > -1 is passed for "no pkey"? > > > > If we think this should never be called with signo == SIGSEGV && > > code == SEGV_PKUERR and no valid pkey but if it's messy to prove, then > > maybe a WARN_ON_ONCE() would be worth it here? > > > > Anshuman suggested to separate them out, which I did like below, I think that > addresses your comments too? > > diff --git arch/arm64/kernel/traps.c arch/arm64/kernel/traps.c > index 215e6d7f2df8..49bac9ae04c0 100644 > --- arch/arm64/kernel/traps.c > +++ arch/arm64/kernel/traps.c > @@ -273,6 +273,13 @@ void arm64_force_sig_fault(int signo, int code, unsigned long far, > force_sig_fault(signo, code, (void __user *)far); > } > > +void arm64_force_sig_fault_pkey(int signo, int code, unsigned long far, > + const char *str, int pkey) > +{ > + arm64_show_signal(signo, str); > + force_sig_pkuerr((void __user *)far, pkey); > +} > + > void arm64_force_sig_mceerr(int code, unsigned long far, short lsb, > const char *str) > { > > diff --git arch/arm64/mm/fault.c arch/arm64/mm/fault.c > index 451ba7cbd5ad..1ddd46b97f88 100644 > --- arch/arm64/mm/fault.c > +++ arch/arm64/mm/fault.c (Guessing where this is means to apply, since there is no hunk header or context...) > > - arm64_force_sig_fault(SIGSEGV, si_code, far, inf->name); > + if (si_code == SEGV_PKUERR) > + arm64_force_sig_fault_pkey(SIGSEGV, si_code, far, inf->name, pkey); Maybe drop the the signo and si_code argument? This would mean that arm64_force_sig_fault_pkey() can't be called with a signo/si_code combination that makes no sense. I think pkey faults are always going to be SIGSEGV/SEGV_PKUERR, right? Or are there other combinations that can apply for these faults? > + else > + arm64_force_sig_fault(SIGSEGV, si_code, far, inf->name); Otherwise yes, I think splitting things this way makes sense. Cheers ---Dave