From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 1D80D3858C42 for ; Tue, 19 Dec 2023 14:57:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1D80D3858C42 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1D80D3858C42 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702997867; cv=none; b=GO5OW1UKhh8UmK1YeGa1GC3xh3I5VvkFaXTqT/sXDuJbmL5FJmGGHTZ8zZiA5xK47JgzASM80qgR/VMv3fDX8Dv/k4r1EZWKG838IYuj0sx49LtToAtDXHFj/PKQmLQG/99iY1xtIf/WXF2ml0unerkjoftNWImuNQCXCx3QLJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702997867; c=relaxed/simple; bh=hLPIWU0/U00EAQDN/FNr3tlsTFWPUTp8UfSUiHJWI6I=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=HQMm7OECl08hj1Jmy6St5G/aVvKaSsWuJEw6+NCQeNFaT8WDgIJqo5+rJZ/Vu5yXW+7azWkWpQCizyFBR+a5WaaHhMYcjlXYai5Y8Ri4GLNlwOjzRcSOFlw4jUxhjE9X/pViFr8uAPHAnWE4x+5cqe3PJ9EmeQFWcPfgCqzDql8= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702997864; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OSnjqrAOi0aJauvIBA05jTkDq7hWua8wDE2XTRGWNwE=; b=G14Nwynpa/oO+UWJpKgON0zjAhJcFXq45/fdW17vl6GeIusiI4zkf9u3Lb/7Lr8j9rl7lo snDHPGOKkUzMlaz2RhOuLC8Ga+cHNQ8Qx4B0DteCzzHqPSs/4i4Yr7CAqgOaSga0GFUGCT yeHzjEb9/idPv/hr68oJZ4kkzANyXj4= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-Ap3HAaLGOtW21PzbQazRDg-1; Tue, 19 Dec 2023 09:57:40 -0500 X-MC-Unique: Ap3HAaLGOtW21PzbQazRDg-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-4258d33d5f4so52473071cf.3 for ; Tue, 19 Dec 2023 06:57:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702997859; x=1703602659; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=OSnjqrAOi0aJauvIBA05jTkDq7hWua8wDE2XTRGWNwE=; b=oT5jRkGIkpR1eA4MQJ4aCBIHwiVnDxHPvzK2V0cbbJtYivBFYSgwqPhOOSVkayu85+ f24Tm8CHjXSqeEECYJNFXMB8MpgjU4ore1eyWARchwEnNj6lSYCAhgneoy9FzXQcYies U1C3D7o64PlJEG+mEmh0GAt8Xy2FMbyihHuDlmnXlM4tYja7tnZneQrm26BTt1blLYFZ FSUyMN5BXSM8JVu1xfDmsHSTxaBwJZ8mM+jtcYHUJctJbyxPXPCT8S2eCRPzKCx7B5Iu lbkmYoeafu2p1aeLJGK1zBj79mLcJocY5N+riXt2qOhCzaAHYPPuGBA7wb0MZm+K3BmK 85EQ== X-Gm-Message-State: AOJu0YzS3zkG/whsyYWLDqxl6kiDIEeqRbpwoTEw7ll7iJGxi2QVQYc9 vugUtHwttCpeOqnSNMgGQmnz1mgr9xoiW2W53IPdbSQsh5DLacnIUtYk0P9KqGyvI7Ilfbzxfrl iy6l7HegLcaVgfMCUmijKacodzsIo X-Received: by 2002:a05:6214:29ee:b0:67f:2d9b:2753 with SMTP id jv14-20020a05621429ee00b0067f2d9b2753mr5545658qvb.22.1702997859603; Tue, 19 Dec 2023 06:57:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IEuEsdmhDnTfV/sKFEnXgabYUjcFpfNaQMrFrPP5BV+Bg9IWLIaPKj0o6oLkEEQxZcKKvM+TA== X-Received: by 2002:a05:6214:29ee:b0:67f:2d9b:2753 with SMTP id jv14-20020a05621429ee00b0067f2d9b2753mr5545651qvb.22.1702997859294; Tue, 19 Dec 2023 06:57:39 -0800 (PST) Received: from [192.168.0.241] ([198.48.244.52]) by smtp.gmail.com with ESMTPSA id i17-20020a0cfcd1000000b0067f2dc0f888sm3038588qvq.71.2023.12.19.06.57.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 19 Dec 2023 06:57:38 -0800 (PST) Message-ID: <990d5b9b-b966-fa7e-5fd8-44e1b5902a89@redhat.com> Date: Tue, 19 Dec 2023 09:57:37 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v2 1/7] powerpc: Do not raise exception traps for fesetexcept/fesetexceptflag (BZ 30988) To: Adhemerval Zanella Netto , libc-alpha@sourceware.org, Bruno Haible References: <20231106132713.953501-1-adhemerval.zanella@linaro.org> <20231106132713.953501-2-adhemerval.zanella@linaro.org> <6130f4c9-dab2-6f8e-5bc5-902b5a48e2dc@redhat.com> <5e031d35-5d3e-49a7-b354-809bb4a1dc8f@linaro.org> <6e4ff3c5-8504-79a4-8865-0239b0cd7185@redhat.com> <8aaf2565-5310-44aa-a331-6d12b26d2274@linaro.org> <3052e518-dac2-4b23-a070-787db5e13bf2@linaro.org> <6e52fa2f-9198-4a0a-9c77-80a1eccbd347@linaro.org> <0f892926-e336-f08d-c96e-0ad38d4ce75a@redhat.com> <0490564f-e7b0-9a62-7940-90dd32665143@redhat.com> <600c6e8e-1283-47fd-af00-db1204629fa4@linaro.org> <578ae9cd-a47a-47a6-b17d-646ed3d97e46@linaro.org> From: Carlos O'Donell Organization: Red Hat In-Reply-To: <578ae9cd-a47a-47a6-b17d-646ed3d97e46@linaro.org> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,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 server2.sourceware.org List-Id: On 11/27/23 08:46, Adhemerval Zanella Netto wrote: > Hi Carlos, > > Updated patch below: LGTM, but because this is submitted under the existing thread patchwork doesn't consider this a submission. Reviewed-by: Carlos O'Donell > -- > > From c10d1d59321d3fce0c532304b428dcef3c8cbb3a Mon Sep 17 00:00:00 2001 > From: Adhemerval Zanella > Date: Tue, 24 Oct 2023 08:37:14 -0300 > Subject: [PATCH 1/7] powerpc: Do not raise exception traps for > fesetexcept/fesetexceptflag (BZ 30988) > > According to ISO C23 (7.6.4.4), fesetexcept is supposed to set > floating-point exception flags without raising a trap (unlike > feraiseexcept, which is supposed to raise a trap if feenableexcept was > called with the appropriate argument). > > This is a side-effect of how we implement the GNU extension > feenableexcept, where feenableexcept/fesetenv/fesetmode/feupdateenv > might issue prctl (PR_SET_FPEXC, PR_FP_EXC_PRECISE) depending of the > argument. And on PR_FP_EXC_PRECISE, setting a floating-point exception > flag triggers a trap. > > To make the both functions follow the C23, fesetexcept and > fesetexceptflag now fail if the argument may trigger a trap. > > The math tests now check for an value different than 0, instead > of bail out as unsupported for EXCEPTION_SET_FORCES_TRAP. > > Checked on powerpc64le-linux-gnu. > --- > math/test-fesetexcept-traps.c | 24 ++++++++++++++++-------- > math/test-fexcept-traps.c | 16 +++++++++------- > sysdeps/powerpc/fpu/fesetexcept.c | 5 +++++ > sysdeps/powerpc/fpu/fsetexcptflg.c | 9 ++++++++- > 4 files changed, 38 insertions(+), 16 deletions(-) > > diff --git a/math/test-fesetexcept-traps.c b/math/test-fesetexcept-traps.c > index 71b6e45b33..7efcd0343a 100644 > --- a/math/test-fesetexcept-traps.c > +++ b/math/test-fesetexcept-traps.c > @@ -39,16 +39,24 @@ do_test (void) > return result; > } > > - if (EXCEPTION_SET_FORCES_TRAP) > - { > - puts ("setting exceptions traps, cannot test on this architecture"); > - return 77; > - } > - /* Verify fesetexcept does not cause exception traps. */ > + /* Verify fesetexcept does not cause exception traps. For architectures > + where setting the exception might result in traps the function should > + return a nonzero value. */ OK. > ret = fesetexcept (FE_ALL_EXCEPT); > + > + _Static_assert (!(EXCEPTION_SET_FORCES_TRAP && !EXCEPTION_TESTS(float)), > + "EXCEPTION_SET_FORCES_TRAP only makes sense if the " > + "architecture suports exceptions"); OK. Good _Static_assert to avoid machine misconfiguration. > + > if (ret == 0) > - puts ("fesetexcept (FE_ALL_EXCEPT) succeeded"); > - else > + { > + if (EXCEPTION_SET_FORCES_TRAP) > + { > + puts ("unexpected fesetexcept success"); > + result = 1; > + } > + } > + else if (!EXCEPTION_SET_FORCES_TRAP) OK. Tests both sides pass/fail. I like this version. > { > puts ("fesetexcept (FE_ALL_EXCEPT) failed"); > if (EXCEPTION_TESTS (float)) > diff --git a/math/test-fexcept-traps.c b/math/test-fexcept-traps.c > index 9701c3c320..998c241058 100644 > --- a/math/test-fexcept-traps.c > +++ b/math/test-fexcept-traps.c > @@ -63,14 +63,16 @@ do_test (void) > result = 1; > } > > - if (EXCEPTION_SET_FORCES_TRAP) > - { > - puts ("setting exceptions traps, cannot test on this architecture"); > - return 77; > - } > - /* The test is that this does not cause exception traps. */ > + /* The test is that this does not cause exception traps. For architectures > + where setting the exception might result in traps the function should > + return a nonzero value. */ OK. > ret = fesetexceptflag (&saved, FE_ALL_EXCEPT); > - if (ret != 0) > + > + _Static_assert (!(EXCEPTION_SET_FORCES_TRAP && !EXCEPTION_TESTS(float)), > + "EXCEPTION_SET_FORCES_TRAP only makes sense if the " > + "architecture suports exceptions"); OK. > + > + if (ret != 0 && !EXCEPTION_SET_FORCES_TRAP) > { > puts ("fesetexceptflag failed"); > result = 1; OK. > diff --git a/sysdeps/powerpc/fpu/fesetexcept.c b/sysdeps/powerpc/fpu/fesetexcept.c > index 609a148a95..2850156d3a 100644 > --- a/sysdeps/powerpc/fpu/fesetexcept.c > +++ b/sysdeps/powerpc/fpu/fesetexcept.c > @@ -31,6 +31,11 @@ fesetexcept (int excepts) > & FE_INVALID_SOFTWARE)); > if (n.l != u.l) > { > + if (n.l & fenv_exceptions_to_reg (excepts)) > + /* Setting the exception flags may trigger a trap. ISO C 23 § 7.6.4.4 > + does not allow it. */ > + return -1; > + > fesetenv_register (n.fenv); > > /* Deal with FE_INVALID_SOFTWARE not being implemented on some chips. */ > diff --git a/sysdeps/powerpc/fpu/fsetexcptflg.c b/sysdeps/powerpc/fpu/fsetexcptflg.c > index 2b22f913c0..6517e8ea03 100644 > --- a/sysdeps/powerpc/fpu/fsetexcptflg.c > +++ b/sysdeps/powerpc/fpu/fsetexcptflg.c > @@ -44,7 +44,14 @@ __fesetexceptflag (const fexcept_t *flagp, int excepts) > This may cause floating-point exceptions if the restored state > requests it. */ > if (n.l != u.l) > - fesetenv_register (n.fenv); > + { > + if (n.l & fenv_exceptions_to_reg (excepts)) > + /* Setting the exception flags may trigger a trap. ISO C 23 § 7.6.4.4 > + does not allow it. */ > + return -1; > + > + fesetenv_register (n.fenv); > + } > > /* Deal with FE_INVALID_SOFTWARE not being implemented on some chips. */ > if (flag & FE_INVALID) -- Cheers, Carlos.