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 144BDD2F7FA for ; Thu, 17 Oct 2024 07:44:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 89AF76B007B; Thu, 17 Oct 2024 03:44:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 84B7E6B0082; Thu, 17 Oct 2024 03:44:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 739966B0083; Thu, 17 Oct 2024 03:44:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 541126B007B for ; Thu, 17 Oct 2024 03:44:26 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0172E121091 for ; Thu, 17 Oct 2024 07:44:15 +0000 (UTC) X-FDA: 82682306112.19.324C960 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf03.hostedemail.com (Postfix) with ESMTP id 400F520005 for ; Thu, 17 Oct 2024 07:44:19 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; spf=pass (imf03.hostedemail.com: domain of kevin.brodsky@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=kevin.brodsky@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729150989; a=rsa-sha256; cv=none; b=f43zsNH3SU1twlXPo5c/YEg4iJDWYl4yY4aQQW4L6D6EwsRLovryN6Ce/jRErGypWEwTch UX8LsNat3FhxuXlVL3a9CG4sXW/pzr9EtQpJosvIR2eEhsOw3ZPUwv0JBFY4z7z6Ko7BSR EKuS/ImTRs4oCV2OqPWI8OTysTQUSkQ= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; spf=pass (imf03.hostedemail.com: domain of kevin.brodsky@arm.com designates 217.140.110.172 as permitted sender) smtp.mailfrom=kevin.brodsky@arm.com; dmarc=pass (policy=none) header.from=arm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729150989; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/UhWQm9eLeR8YNtGPI8a1RnIKQeZCQmW5PVmQJ1rnJg=; b=bpkyCn0ohe8UOBlLQZ2EBO/7fGPi2SzU3ARxapSOHPaRQkCHP5nUVbDjRNqUZJ6ZMQKWiA v7fkRUTkB75lsRXK5/EoSE4DC9818pFpZLESTkmSQWbRQYsGf90ld9MbU5lW7seQuaV01J UM5sKUozNl2vmBeUhXF2nBdtN8ZouSk= 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 6602DFEC; Thu, 17 Oct 2024 00:44:52 -0700 (PDT) Received: from [10.57.66.61] (unknown [10.57.66.61]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id EACE83F528; Thu, 17 Oct 2024 00:44:15 -0700 (PDT) Message-ID: Date: Thu, 17 Oct 2024 09:44:13 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5 19/30] arm64: add POE signal support To: Joey Gouly , Will Deacon Cc: 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 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> <20241015122529.GA3820764@e124191.cambridge.arm.com> Content-Language: en-GB From: Kevin Brodsky In-Reply-To: <20241015122529.GA3820764@e124191.cambridge.arm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Stat-Signature: 5hjchs6pdxj6k93io7z3d8yrtw5nmp3g X-Rspamd-Queue-Id: 400F520005 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1729151059-258736 X-HE-Meta: U2FsdGVkX1/GtolH73sKG2GX0SmkpIpb9s+8RhOS4HMifdsk2ddbxyHpWcV3BT80AvTXB8UKqxQ/2jwsYe/qWd8T8E0+WXgQAYSOsMKexUvoTxI+P7an2xXTGozEaZZd0gb4xmomY42wMGN4ILdVyOAzDmPP60DcYIHoEOhERSWwl3hBk1O0iZ0kt8dQna4zk3c0d59JTLB4ZACXov6T54u3JiLCfxsT8HUjNmgGRbYAsaOpomgldhIuTVD6PTPyN1BbN2BNNapo3i+Rm4cY4rlt7ffDx7NhtaYPIpLQQb+rgmFt6A3AtYpPmMcVb9eY6vSh4qgK2KCqE/x1zsNWiDuOpNRMc6aFdEJP2cBwhpqcY3En3b+YyHhq/KNDB7igV7uXvanxkwuGc0brPerJMTe64G3PmZsPdotLIAFsg/OofSTRqB+SA25FAMXuwhpwJOzNVkK6R1QFRFzpTvUgJphq4d6fDZOzGCHltCt2lVukqohXaDXwEDNrll152GNcT47j1WQoh55MlHSC4q8NjnEMGlI+p7IRCJl+k1iM2c7Ddak0tCW/o1wFZfdgpSc9h3+YoXKAibRtwmxfu5ezxfWHgD79T5vxuc/dj3Rj9lZDi/BZ3JWVDFyLUWr1htVkbyxjhoOY4PkOQkhA//Pa15Zlo5HhYdfifacbIwR2NwZ1AZSusspGPg3jjqsyjbVRZNiNOfQoP28Z+MJBQd7S+RRzCRcVh9iq5dtMyHBozg8GeeMGSlv9eyaOTugm3BwfAbzJ631PB437dcki7XLN6XaHlq4zDgLvg+uqb+zZoTFETYb06AnrQ5mAMK3f3Aw132Kx6DIO2rEb/A6TBct9U95PDkga0McQctURAyUZhTxfz0VBvda9V2a3pIaFajyCE1pMjbsHO+hlp4QS8swUOGKD/iuFike+oyZ0euEtYKc6Etn9ZDwvtdizKbfUs0mHOYFXITTLtjfyfSFUrkT 0EEtGdZl jAf2pjpZ3Ls8rOLx6LLYzp93a+vrw3c+FczGtHbbs5Dilus2TgLSN2juFkgmHXF4XkKctBv6veQtlZcYGzbeUCKcCNC67CJkOEH6ZYrfOSEjC/5ncsG22hTvFY3+RXJ4AkTgtknBKTukwqN9U1bFalnip7Q== 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 15/10/2024 14:25, Joey Gouly wrote: > 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. >> >> We also still need to resolve Kevin's concern, which probably means >> keeping the thread's original POR around someplace. > That was cargo culted (by me) from the rest of the function (apart from TPIDR2 > and FPMR). I think Kevin is planning on sending his signal changes still, but > is on holiday, maybe he can remove the last part of the condition as part of > his series. Indeed just got back from holiday. I've got the series ready, about to send it. I will add a clean-up patch removing this check on poe_offset. Kevin