From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 456 invoked from network); 1 Nov 2023 17:29:15 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 1 Nov 2023 17:29:15 -0000 Received: (qmail 21853 invoked by uid 550); 1 Nov 2023 17:29:12 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 21818 invoked from network); 1 Nov 2023 17:29:12 -0000 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.ispras.ru E5DC6407675D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ispras.ru; s=default; t=1698859739; bh=P0v5q+9qg/vGdcIZHz98ls6Y8lPlWEjn9vCkWcKz7gQ=; h=Date:From:To:Subject:Reply-To:In-Reply-To:References:From; b=tIG/Z6XQa1lkRrbQYTIrjUOQ/b6+X4Y+NkvBDMI87tsPdUzc9X4pV+Xygra/AiWQm GSg2tFTN0aQk13yLLNBAHshQLbK1Rw9U3V+SwiwlOFZZWlybnHcp2YW8sublAsSb9C sX5gs5NsbKWVDVmhCBlgyZq7T6XbqljUF3oTdhZo= MIME-Version: 1.0 Date: Thu, 02 Nov 2023 00:28:59 +0700 From: Alexey Izbyshev To: musl@lists.openwall.com Mail-Followup-To: musl@lists.openwall.com In-Reply-To: <20231101130033.GR4163@brightrain.aerifal.cx> References: <20231101130033.GR4163@brightrain.aerifal.cx> User-Agent: Roundcube Webmail/1.4.13 Message-ID: <2193f3bd74f006d5bd44ecf5af6187fa@ispras.ru> X-Sender: izbyshev@ispras.ru Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [musl] synccall patches On 2023-11-01 20:00, Rich Felker wrote: > On Tue, Oct 31, 2023 at 05:21:01PM +0100, Markus Wichmann wrote: >> Then I noticed that __synccall() has a logic bug explained in the >> commit >> message. It wouldn't be a bug if semaphores had any kind of preference >> for the thread that has waited longest or something, but musl does not >> implement something like this. And the kernel explicitly documents >> that >> FUTEX_WAKE will wake a random thread. >> >> At first I thought the best solution would be to forego the serialized >> execution of the callback; just release all threads in line 97 (and >> then >> fix the callbacks to cope with parallel execution). But BSD semaphores >> have no way to do that, and a mass-release loop like the one on line >> 110 >> would have the same issue as given here. It would only be less likely >> to >> happen, with the likelihood rising with the number of threads. So a >> new >> semaphore it is. > > I think your assessment of the problem is correct and I think your fix > works but I need to look at it in a little more detail. Review from > others familiar with this stuff would be very welcome too. > I looked at synccall code back when it was rewritten in commit e4235d70672d9751d7718ddc2b52d0b426430768, but I missed this bug. Markus' patch looks good to me. Alexey