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 F423ED216A3 for ; Tue, 15 Oct 2024 13:40:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8BAB86B0096; Tue, 15 Oct 2024 09:40:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8916A6B0098; Tue, 15 Oct 2024 09:40:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7A69E6B0099; Tue, 15 Oct 2024 09:40:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 5C3E36B0096 for ; Tue, 15 Oct 2024 09:40:02 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 76F018171A for ; Tue, 15 Oct 2024 13:39:54 +0000 (UTC) X-FDA: 82675944960.28.4719976 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf01.hostedemail.com (Postfix) with ESMTP id C407340011 for ; Tue, 15 Oct 2024 13:39:53 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf01.hostedemail.com: domain of Dave.Martin@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=Dave.Martin@arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728999553; a=rsa-sha256; cv=none; b=1kIu86ybam5ZfnfgovRrmg9e9LqLCEjvMsORtBr/zdy2oJ1EMYKsJpX799kI2ZDsx7lmGD vMCONQHkTt0fVMgOdDC4mtVrr/0vh1PiWqmVz9SkVlphKYiXbkDJCmnSXsGR0564/Bw0yP 2J4AWDM6rZmuCuRvmC4Y7FGQsbAjrIk= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=arm.com; spf=pass (imf01.hostedemail.com: domain of Dave.Martin@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=Dave.Martin@arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728999553; 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; bh=hwhgeRMk4jyYgedHBOUOc/6CODzmYlrjcK+trw2k++w=; b=NyK/qekw7G3wGqpTHb4y5tYu7bxpO4MAjrAYgi0XE3dM3jUE7WP8EUCz8buyGFD+ddQSCd VMiYix4/OVhfaRrOPSHB/jXZ7LuwvAyy9uX0kjVLzk2Lr5yTGHjaHgK5+ivTenznBUp4j9 YrM6px4lnPItagdci2szYU6LAtX3lCE= 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 911ABFEC; Tue, 15 Oct 2024 06:40:28 -0700 (PDT) Received: from e133380.arm.com (e133380.arm.com [10.1.197.51]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C40753F51B; Tue, 15 Oct 2024 06:39:54 -0700 (PDT) Date: Tue, 15 Oct 2024 14:39:49 +0100 From: Dave Martin To: Will Deacon Cc: Joey Gouly , 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: 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> <20241015114116.GA19334@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241015114116.GA19334@willie-the-truck> X-Rspam-User: X-Rspamd-Queue-Id: C407340011 X-Rspamd-Server: rspam01 X-Stat-Signature: xixsn9ojyxuunatw8goe5f5ggig8b83w X-HE-Tag: 1728999593-217573 X-HE-Meta: U2FsdGVkX1/zE5C6+MZ64Q0iwqeUUT9VlZM7vQhMq9u4hbu6jU96ERr3YpwXByPvYWJgqqxqdlm58TbOc0aduKdX/p2MmQrI85yuXGsBpYBzb4YDWnuKgy8pBvpcBbOKu81o3nUgpk7wY0X/WIgpeO9EDfCWdF7h5YoP41xGh5ZEb9ZO6r2kGqGc+bjmh7Kz+shka2ndyLPQdZiRt7sw7E087Ox5CO1bpWgV9EX8tXJ1YuaZ8To3rksyeakVKGnAgi+ZXvaTe60gqxqiJUNH9091JdMxMNrOMf4g6RgCaVQa0VyDx3EydVeritMDgooZ9uFRX579KMvFd1Ii7bhnUcpxn67w5DAALgCckXpcAzJ0ClPiUVSd9Fc/erf4ojJQ0OY2ayX1UBdAwJTvxcokDD1pEH3s6MgY6zoGEVWH9O3WeSbukfmcF32AEphbx0Qtwwnlb7d4QPZjYIQ5It7a/K0E77xbfLYAqnGTo8+wNIS9SXRnEy6850wlEf2DSkmlnLf7SXUa21H0Xwq/Z7Eez2M25dG7oLiEZYnK08UQZkoliIeow3K+KCmeXIIm02siWui3GH+u+agpDwca+U686z3CkIS7JZ4rmBEDv7Jj06NkSyvfpxtPKhGCXnpP+W29nR53AF8aXQJDpGqWe0SgPds0bBpyl5unmwt0z6kH8mb/UBoe4q2jcIrofCrkMqI8/qOBIw2p4SCh93ccOyPKb0t3W7Y7MJPNEFWhxQSXh1UO15qE71bOng9nvPkcQj9ls8nSms+brf6wPMclyJutRMVLA4FGno/lY6ZCqYJFlGx+wtV1jHHbojW1heBwMOnxa9Db5fRQDsPnXGusnfUXrIovOylPG/OVEAelP9yG3+FqdtTfdf8AxS8LIunotik/9OhnjKvwlkjSXBoIp8NCTdIpdPZVpURoifyj9ZopS7S1+z1LQzcjXHwvcHRtA65uxM/zKTJGOAe2PChLDwQ NuWDd9tz esaPH8yarW7pmO31iH+FOAtWtSDrDM5h43DhDkQI2qJBZKhQnElbwnB0Mdb+iCD3OjQXj9GtjxtW2w8Z7BpRtE/1ceISpCfXpT+1oCFO5R5M0GpZUOUiFXA3YxB88rJQsBq7UlMPffLv+N9kKWlbfzG1I+w== 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 12:41:16PM +0100, Will Deacon wrote: > 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. >From memory and a quick glance at the code: For other "conditionally unconditional" things, we don't have a corresponding check on user->foo. For conditional stuff, non-NULLness of user->foo is used to track whether we decided to dump the corresponding record; for consistency here, if we have system_supports_poe() && err == 0, then that's sufficient (though in prior versions of this code, POR_EL0 dumping was conditional and so the extra check did do something...) In any case, if some allocation fails then we splat out with a SIGSEGV before modifying the user task state to deliver the signal (in setup_return() etc.) If The user's POR_EL0 value is being clobbered before we get here, we would save the wrong value -- so the code would be broken anyway. So, as Joey says, this is probably fine, but the user->poe_offset check looks superfluous. The kernel will splat on us here and kill the thread if it's NULL anyway. [...] Cheers ---Dave