Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp18181517rwd; Tue, 27 Jun 2023 12:56:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5soGaC2RmbCAGksgwUeGq+R1n87nDnNw5NygPljPouo3YhkMd4VBd6tWRhYn2LoWttQqiy X-Received: by 2002:a05:6808:485:b0:3a1:dd4d:54e0 with SMTP id z5-20020a056808048500b003a1dd4d54e0mr6139200oid.30.1687895795659; Tue, 27 Jun 2023 12:56:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687895795; cv=none; d=google.com; s=arc-20160816; b=DX++cWzo6PTIZF1xxjJwkG5ii370JGnoU1VDNS7LeEMO2fSbGog+i+CIBEJ6HRbuCS WlSYADOaoFfXftI8E/NM46ZwHJhOtOo+CMxFgvbVgvLFV0MIgCSNvonlswuzv3Dnq9zw dxexJSpiAaHUk4dkmCuFw1OWI7nKJcvt9+Q5p1c6UDwsTJ72ROBMJP11f07ODEEjd8bC XpCAniiY60OVg4xdnWlmfW64SB7/ZwGHN9sQvmmUgCRfVQOddV3LKfkst4tGYLxbuvJx EN+UY+FbgRN6pVmqj+o9vgV5bItAwgqM3iMU+aEZvbllDJpVqun6/pHo4c3JJY2bW+Km hZ5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=A0PL848p/iGK/mu873XkFV+KJXanwRDuGN+LI+se7LU=; fh=yltoE/RPmRBUMig+P+Tq9LFmW3208p9vSU3NZDSH4hE=; b=Ku1u19czlUZfqg21l4QacQlDUzC9wvKiFDp6ddr1Yij849qhVJTptwk9NfLm+7VeMq kedynwlCKdGLOoNPpCNCFuQB/2uHv86R1bqIR+3TIz0W0yh3sbJ4J9FRNeESMKzz0rWp pjXYMTJSZHE4BmdwGHJuk/iXDpsTfMh1lJyLpqlhf1F9asVBy+R8oaGqPE710o9Z/Hh8 /GzAeHVUBy75NCzWQpx7dNQ9ynQaz+WKEp18Z57mxW/GlI4Uyf6eAic5PBsU5cxB+Ss/ HauMB1PnU+rmbsaX0VOw98Ny0Sm8tuN/fjbKGryW85V9CL+3VZnqtNYuy7twGrnu2ZpX o8tA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x64-20020a638643000000b00553c6af75d5si7667496pgd.315.2023.06.27.12.56.22; Tue, 27 Jun 2023 12:56:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229568AbjF0Tmk (ORCPT + 99 others); Tue, 27 Jun 2023 15:42:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjF0Tmj (ORCPT ); Tue, 27 Jun 2023 15:42:39 -0400 X-Greylist: delayed 917 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Tue, 27 Jun 2023 12:42:37 PDT Received: from brightrain.aerifal.cx (brightrain.aerifal.cx [216.12.86.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 998501BD5 for ; Tue, 27 Jun 2023 12:42:37 -0700 (PDT) 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-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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