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 B6501EB64D9 for ; Tue, 27 Jun 2023 19:27:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4A7558D0002; Tue, 27 Jun 2023 15:27:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 430588D0001; Tue, 27 Jun 2023 15:27:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D2B08D0002; Tue, 27 Jun 2023 15:27:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 176D28D0001 for ; Tue, 27 Jun 2023 15:27:22 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id C35751A0220 for ; Tue, 27 Jun 2023 19:27:21 +0000 (UTC) X-FDA: 80949511482.02.0339814 Received: from brightrain.aerifal.cx (brightrain.aerifal.cx [216.12.86.13]) by imf07.hostedemail.com (Postfix) with ESMTP id E34534001A for ; Tue, 27 Jun 2023 19:27:19 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf07.hostedemail.com: domain of dalias@libc.org designates 216.12.86.13 as permitted sender) smtp.mailfrom=dalias@libc.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687894040; 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=A0PL848p/iGK/mu873XkFV+KJXanwRDuGN+LI+se7LU=; b=sYKS4XMefG8d/AaGOAWuWrMfo/PGKD9kqFUEc69x05zAuUvbhG9ZoWn02uMVk3zq8RD+UF yJgeH9bAKL0H6l7Qj+ms+NwnJCXA20Ipys/ScjUf5BKXdXFU5QHuUlvdheFPYVHE57tgqf azGrOM6QZI2KMJYk+qq+xn3nyKmYtk0= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf07.hostedemail.com: domain of dalias@libc.org designates 216.12.86.13 as permitted sender) smtp.mailfrom=dalias@libc.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687894040; a=rsa-sha256; cv=none; b=SaaHsC/QslUuQd2BjArgzNc6NAW2p+WXrkQrfzxA24Wbqx9AanMjkcor4C6JjlOeYX7z3v uqZUbH3jm24cGoTssXvfRp/9ei8OhB56XEwnJL3/yrK1s8CQrOiqZirk9yCmpqKHv8+haq eqyp18XVyC1LTrQx4pca+GiNzWhxhsY= Date: Tue, 27 Jun 2023 15:27:19 -0400 From: Rich Felker To: Szabolcs Nagy Cc: Stafford Horne , LKML , Linux OpenRISC , Jonas Bonn , Stefan Kristiansson , Eric Biederman , Kees Cook , "Jason A. Donenfeld" , Dominik Brodowski , linux-mm@kvack.org Subject: Re: [PATCH 3/4] openrisc: Support floating point user api Message-ID: <20230627192719.GR20050@brightrain.aerifal.cx> References: <20230418165813.1900991-1-shorne@gmail.com> <20230418165813.1900991-4-shorne@gmail.com> <20230626213840.GA1236108@port70.net> <20230627175638.GD3630668@port70.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230627175638.GD3630668@port70.net> User-Agent: Mutt/1.5.21 (2010-09-15) X-Rspamd-Queue-Id: E34534001A X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: r9quixdbpw1n4dyskssejg1aj5okxf4x X-HE-Tag: 1687894039-118266 X-HE-Meta: U2FsdGVkX1/Wqm8pTOKO0yV4Sf42UGEJZV2Vz2N9I6syH8IEbrENv86hkGw7BfoH1ETcidmmGuTRI1+laISnqmRPPuoZMLgojSFY7QZTN9nIT8QvsOVLKxdHxLQSSmq38lrqWjS+/mKnTqvu5lfjAX76hQOnvdVfQDycBFrgQ6cbVfOMU76Rq4k5lidK0NawxmjNqWW1haxAh7QOKmralDGGVrL7wRRtBqIPvsbG/JDtNaviZY+ukWBLcpTUzlY5oCQXKWLXNnLMkr/XjtFl9dePHHIFCQMckDuU4J57VtYOmcI/Hy6GmC6AuUbR1KRLTxSYaTkGmem6AEspxuefz8y88mLN2VISKhNz6xUx3y+zuaMp9iySnwt/6AjFo4TPdIfejAVCMoKn3R4hSL9shGaq96fpBX2vybINLAAxxQydvm31k02sVUoX9ZwAQWbH0driQVCn/RKJYMZGCHVwfe6y6XYAjPFyVrqTHsim8/EqeKUZeONy+Cph+ckvoYZK2KtIrcb09yXiDsBiR3iXoj4KJOAEmWp/6DcVkmBnnEIs4nk8U8PqLiMfqPEcnoCKAv8FeJ52HpDQrmCkw4RP3XPgyiyqybQWLLiqcJGgRpAtA3hBodq3lQE8BMIXQe/MxeAHedoN+oGU7AShOfWDssoo8PopPPRylLaFHCXGx980p54X3VtYf8WyKn5QWc16gZre0Et9SSfyE+VT5oZXgZMlm3lXPi9fQD0X+EH2Fbq/UfS+PLpo5JG87vyHnjWZCuaegHtvejfb+MC6uF/XF/l+/9MbAHATORgKCKeNIeGS4aAo4cbWcqcO5HetX+jTii0UdjHNSTfOgh26t0bcP8qz+utqhFhR7+Z+Sps1iNNSGv1GKvh5ZBBQkSDveQIzjTWt8yia9LB+Z0AdAg9jXFwf/qdPzwHXm7LjctwQ1L8= 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: On Tue, Jun 27, 2023 at 07:56:38PM +0200, Szabolcs Nagy wrote: > * Stafford Horne [2023-06-27 17:41:03 +0100]: > > On Mon, Jun 26, 2023 at 11:38:40PM +0200, Szabolcs Nagy wrote: > > > * Stafford Horne [2023-04-18 17:58:12 +0100]: > > > > Add support for handling floating point exceptions and forwarding the > > > > SIGFPE signal to processes. Also, add fpu state to sigcontext. > > > > > > > > Signed-off-by: Stafford Horne > > > > --- > > > ... > > > > --- a/arch/openrisc/include/uapi/asm/sigcontext.h > > > > +++ b/arch/openrisc/include/uapi/asm/sigcontext.h > > > > @@ -28,6 +28,7 @@ > > > > > > > > struct sigcontext { > > > > struct user_regs_struct regs; /* needs to be first */ > > > > + struct __or1k_fpu_state fpu; > > > > unsigned long oldmask; > > > > }; > > > > > > this seems to break userspace abi. > > > glibc and musl have or1k abi without this field. > > > > > > either this is a new abi where binaries opt-in with some marking > > > and then the base sigcontext should be unmodified, > > > > > > or the fp state needs to be added to the signal frame in a way that > > > does not break existing abi (e.g. end of the struct ?) and also > > > advertise the new thing via a hwcap, otherwise userspace cannot > > > make use of it. > > > > > > unless i'm missing something. > > > > I think you are right, I meant to look into this but it must have slipped > > though. Is this something causing you issues or did you just notice it? > > i noticed it while trying to update musl headers to linux 6.4 uapi. > > > I didn't run into issues when running the glibc test suite, but I may have > > missed it. > > i would only expect issues when accessing ucontext entries > after uc_mcontext.regs in a signal handler registered with > SA_SIGINFO. > > in particular uc_sigmask is after uc_mcontext on or1k and e.g. > musl thread cancellation uses this entry to affect the mask on > signal return which will not work on a 6.4 kernel (not tested). > > i don't think glibc has tests for the ucontext signal abi. > > > Just moving this to the end of the sigcontext may be all that is needed. > > that won't help since uc_sigmask comes after sigcontext in ucontext. > it has to go to the end of ucontext or outside of ucontext then. > > one way to have fpu in sigcontext is > > struct sigcontext { > struct user_regs_struct regs; > unsigned long oldmask; > char padding[sizeof(__userspace_sigset_t)]; > struct __or1k_fpu_state fpu; > }; > > but the kernel still has to interpret the padding in a bwcompat > way. (and if libc wants to expose fpu in its ucontext then it > needs a flag day abi break as the ucontext size is abi.) > > (part of the userspace uc_sigmask is unused because sigset_t is > larger than necessary so may be that can be reused but this is > a hack as that's libc owned.) > > not sure how important this fpu field is, arm does not seem to > have fpu state in ucontext and armhf works. > > there may be other ways, i'm adding Rich (musl maintainer) on cc > in case he has an opinion. Indeed, mcontext_t cannot be modified because uc_sigmask follows it in ucontext_t. The only clean solution here is probably to store the additional data at offsets past sizeof(struct sigcontext) + sizeof(sigset_t) and not expose this at all in the uapi types. Some hwcap flag can inform userspace that this additional space is present and accessible if that's needed. Optionally you could consider exposing this in the uapi headers' ucontext_t structure; whether it's an API breakage depends on whether userspace is relying on being able to allocate its own ucontext_t etc. This would leave the actual userspace headers (provided by libc) free to decide whether to modify their type or not according to an assessment of whether it's a breaking change to application linkage. What's not workable though is the ABI break that shipped in 6.4. It's a serious violation of "don't break userspace" and makes existing application binaries just *not work* (cancellation breaks and possibly corrupts program state). This needs to be reverted. Rich