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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2591ACFC294 for ; Tue, 15 Oct 2024 11:41:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AA1C86B0093; Tue, 15 Oct 2024 07:41:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A51556B0095; Tue, 15 Oct 2024 07:41:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93FEE6B0096; Tue, 15 Oct 2024 07:41:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 76DEF6B0093 for ; Tue, 15 Oct 2024 07:41:28 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 9EE9C8039D for ; Tue, 15 Oct 2024 11:41:20 +0000 (UTC) X-FDA: 82675646046.05.7BFBF6B Received: from nyc.source.kernel.org (nyc.source.kernel.org [147.75.193.91]) by imf12.hostedemail.com (Postfix) with ESMTP id CADE840007 for ; Tue, 15 Oct 2024 11:41:22 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BKWuWFQq; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of will@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=will@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728992370; a=rsa-sha256; cv=none; b=kHg6huhMLi1AcNaPbZaobXY4vRSxCa72ZJG0OqBalQjUZHhIQXffQjGxooUak3aKg01rh4 etQE1hxs4OwqqXSf+OOmUPA+iXSRBJ4ZhVQupoC6nzQvRRSF04Nyoy1HwdxOQxd/lfhf2m uTa6BbFRTz3ePY1uBMlt8s2V/gFXF1c= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=BKWuWFQq; dmarc=pass (policy=quarantine) header.from=kernel.org; spf=pass (imf12.hostedemail.com: domain of will@kernel.org designates 147.75.193.91 as permitted sender) smtp.mailfrom=will@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728992370; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=MrJHQArAiuDbpB+jYLmra0DhH1iSL+p/MwXOTL9XyvA=; b=tOkShFR7GfPhhmh9ooyLb6QAvr6+f7ioxp9xn1k2jR4V6oVE4bpMa5RRqSrjbbx7az40ID 8CxF0Q6lRpRW55JgFpKsxooAUm5sJ2KQEIpgEEhKoNbqTXRjucPFF/07WNEAhhgA8BGL5p XO6ATTghww0lEEe7FME2tBLbMSx4ORg= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by nyc.source.kernel.org (Postfix) with ESMTP id 84EB5A42603; Tue, 15 Oct 2024 11:41:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 21911C4CECF; Tue, 15 Oct 2024 11:41:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1728992485; bh=MMLGYJ3ppH3zesWUxVBPsvLY3G0bLj+ulqZ3MXv+H+0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BKWuWFQqTVTJynGPE8DqW8n/xI73kLFPuoP5rh/c5kK1CSzjaiF8IYtd8kopRff3K XzdLUQpCs229QH3XbN6uW7uDFcld9GU4lQqyeSLikLmD2AArAbPqViBkORonVwi/F1 meo0nTDrGhQM/7o0bBVbjaX75lXFKFGpwWTYxfaZ1Q51KRZgYksDHYD54yqRhojHGr lKXOeOPfylHxDC0UYfMvK4LV2v0EDh5S3knmX5cyQ9SV2mj0M5ieWdUUod7sj74EvF xwI17jNouAEf7oIY/BXMWY8jbY8LGd8gPfdfvjZD8Bwi29mydpctt42T4rNrYJkSng 80ZuatKj9mzjg== Date: Tue, 15 Oct 2024 12:41:16 +0100 From: Will Deacon To: Joey Gouly Cc: Kevin Brodsky , linux-arm-kernel@lists.infradead.org, nd@arm.com, akpm@linux-foundation.org, aneesh.kumar@kernel.org, aneesh.kumar@linux.ibm.com, anshuman.khandual@arm.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, skhan@linuxfoundation.org, szabolcs.nagy@arm.com, tglx@linutronix.de, x86@kernel.org, kvmarm@lists.linux.dev, linux-kselftest@vger.kernel.org Subject: Re: [PATCH v5 19/30] arm64: add POE signal support Message-ID: <20241015114116.GA19334@willie-the-truck> References: <20240822151113.1479789-1-joey.gouly@arm.com> <20240822151113.1479789-20-joey.gouly@arm.com> <47e1537f-5b60-4541-aed1-a20e804c137d@arm.com> <20241009144301.GA12453@willie-the-truck> <20241014171023.GA18295@willie-the-truck> <20241015095911.GA3777204@e124191.cambridge.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241015095911.GA3777204@e124191.cambridge.arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: CADE840007 X-Stat-Signature: 1h6jwf3pebo6bgb3t49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Uyklf8OsseT2Haxc1d5PpWYZCoewLRLD3XBW9wAr5/QWfCLgJWGLlYqyMCOlEarzaHFgdlO7Dha3yfFJcJjo4oLs4Uq+zQhib8oe2KpubcxC01YhyH1kTeyJDd6dh8ZzzT4PK2CNqeUxLBLVZwexHL8WutIqukJTpiJAZk3Hx0lE+0sE7wh/w58pwUlq1In5ee X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Tue, Oct 15, 2024 at 10:59:11AM +0100, Joey Gouly wrote: > On Mon, Oct 14, 2024 at 06:10:23PM +0100, Will Deacon wrote: > > Kevin, Joey, > > > > On Wed, Oct 09, 2024 at 03:43:01PM +0100, Will Deacon wrote: > > > On Tue, Sep 24, 2024 at 01:27:58PM +0200, Kevin Brodsky wrote: > > > > On 22/08/2024 17:11, Joey Gouly wrote: > > > > > @@ -1178,6 +1237,9 @@ static void setup_return(struct pt_regs *regs, struct k_sigaction *ka, > > > > > sme_smstop(); > > > > > } > > > > > > > > > > + if (system_supports_poe()) > > > > > + write_sysreg_s(POR_EL0_INIT, SYS_POR_EL0); > > > > > > > > At the point where setup_return() is called, the signal frame has > > > > already been written to the user stack. In other words, we write to the > > > > user stack first, and then reset POR_EL0. This may be problematic, > > > > especially if we are using the alternate signal stack, which the > > > > interrupted POR_EL0 may not grant access to. In that situation uaccess > > > > will fail and we'll end up with a SIGSEGV. > > > > > > > > This issue has already been discussed on the x86 side, and as it happens > > > > patches to reset PKRU early [1] have just landed. I don't think this is > > > > a blocker for getting this series landed, but we should try and align > > > > with x86. If there's no objection, I'm planning to work on a counterpart > > > > to the x86 series (resetting POR_EL0 early during signal delivery). > > > > > > Did you get a chance to work on that? It would be great to land the > > > fixes for 6.12, if possible, so that the first kernel release with POE > > > support doesn't land with known issues. > > > > Looking a little more at this, I think we have quite a weird behaviour > > on arm64 as it stands. It looks like we rely on the signal frame to hold > > the original POR_EL0 so, if for some reason we fail to allocate space > > for the POR context, I think we'll return back from the signal with > > POR_EL0_INIT. That seems bad? > > If we don't allocate space for POR_EL0, I think the program recieves SIGSGEV? > > setup_sigframe_layout() > if (system_supports_poe()) { > err = sigframe_alloc(user, &user->poe_offset, > sizeof(struct poe_context)); > if (err) > return err; > } > > Through get_sigframe() and setup_rt_frame(), that eventually hets here: > > handle_signal() > ret = setup_rt_frame(usig, ksig, oldset, regs); > > [..] > > signal_setup_done(ret, ksig, test_thread_flag(TIF_SINGLESTEP)); > > void signal_setup_done(int failed, struct ksignal *ksig, int stepping) > { > if (failed) > force_sigsegv(ksig->sig); > else > signal_delivered(ksig, stepping); > } > > So I think it's "fine"? Ah, yes, sorry about that. I got confused by the conditional push in setup_sigframe(): if (system_supports_poe() && err == 0 && user->poe_offset) { ... which gives the wrong impression that the POR is somehow optional, even if the CPU supports POE. So we should drop that check of 'user->poe_offset' as it cannot be NULL here. We also still need to resolve Kevin's concern, which probably means keeping the thread's original POR around someplace. Will