Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2934405imm; Sun, 16 Sep 2018 06:17:26 -0700 (PDT) X-Google-Smtp-Source: ANB0VdapgAaln1ImxErOu7L2QYafBihGLW/sC+dKjXGDA7CPLuliwQauCBE+1Db/1h3frdL1PS5S X-Received: by 2002:a63:3281:: with SMTP id y123-v6mr19781531pgy.310.1537103846248; Sun, 16 Sep 2018 06:17:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537103846; cv=none; d=google.com; s=arc-20160816; b=rPLqRhVixKsXUHg5r0YU/yulsXecb7hqHQ6OqkuZ8P5thPE0Da0cLpdlaUtdEp8pBl OfEvtRqEOPKNo+YVFTDAIP5GXYrJSWutjl34jvEIWRkkt7ewcEsVaWmfqwyAfXfeh34e wJDuy1aobbJ6gE/0K+phKeXXx0Endl+R0PxzZoDVmrc8OPTVtXfPEesSsD7g8iONWUsP 7ucTsmEKoEfG3i66h6PJgSkUmG+SYVCl/4+SL2FXxRL1tWoJxpqpq+um4iZFh0UR9uMo 13mX4EU8MBOqkcaJ+KmsTwrd8XaOXjK8jaPITnH7aYe5RSBGNWqpkubiCpA3Sm4qgZGP R84A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=cncXiltl8WJOPbSth10sBFR8nV7oRWUxRW/TXpCSo1c=; b=nzGGBQPlD+XWQXs1KIOAoXoVXLgD0IWLHeG+hK2RoCjMa48klcM+SbzF9Zxst0keB+ Bte9ULbiOM9OBZiZU5diGvbTLFfasnyWTkfUCAAa4Sois3QQ8lyED7hzmiDg/hc9WVlY Z8TYLH6qdeQqIE27l1k7RYMZryWwVOp/e/ns6A9R7yZ6OSGCpwB8h4aRYz3kp9wlSEK3 eGAKwdoF6gXql51gNWv1RC/A06o4F7v97qw7AivxRYO2Qq/ojIzcu8rfe30VY9BYdfSw +fAfGFkcC64QfJ+6KIx4Ktnbu0snFCUQAp7i6FIawQXPkZw3sQlfzC8D1SuVNp/t9ck9 2U/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j67-v6si13028348pfg.34.2018.09.16.06.16.51; Sun, 16 Sep 2018 06:17:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728363AbeIPSjn (ORCPT + 99 others); Sun, 16 Sep 2018 14:39:43 -0400 Received: from 216-12-86-13.cv.mvl.ntelos.net ([216.12.86.13]:57068 "EHLO brightrain.aerifal.cx" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727071AbeIPSjn (ORCPT ); Sun, 16 Sep 2018 14:39:43 -0400 Received: from dalias by brightrain.aerifal.cx with local (Exim 3.15 #2) id 1g1Wuj-0006jn-00; Sun, 16 Sep 2018 13:16:37 +0000 Date: Sun, 16 Sep 2018 09:16:37 -0400 From: Rich Felker To: Florian Weimer Cc: Thomas Gleixner , linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , linux-man@vger.kernel.org, "Michael Kerrisk (man-pages)" Subject: Re: futex_cmpxchg_enabled breakage Message-ID: <20180916131637.GA17995@brightrain.aerifal.cx> References: <20180829222221.GA22017@brightrain.aerifal.cx> <87fty9hc2u.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <87fty9hc2u.fsf@mid.deneb.enyo.de> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Sep 16, 2018 at 02:16:25PM +0200, Florian Weimer wrote: > * Rich Felker: > > > I just spent a number of hours helping someone track down a bug that > > looks like it's some kind of futex_cmpxchg_enabled detection error on > > powerpc64 (still not sure of the root cause; set_robust_list producing > > -ENOSYS), and a while back I hit the same problem on sh2 due to lack > > of EFAULT on nommu, leading to commit 72cc564f16ca. I think the test > > (introduced way back in commit a0c1e9073ef7) is fundamentally buggy; > > if anything, it should be checking for !=-ENOSYS, not ==-EFAULT. > > Presumably it could also fail to produce -EFAULT if mmap_min_addr is 0 > > and page 0 is mapped (a bad idea, but maybe someone does it...). And > > of course other nommu archs are possibly still broken. > > Maybe it was related to this (“Kernel 4.15 lost set_robust_list > support on POWER 9”): > > Thanks! This is really helpful; I'll pass it along. > The Kconfig change you suggest was explicitly rejected as the fix. Even if it was rejected as a fix for this specific bug, I think it would be a good change for other reasons. If nothing else it reduces kernel code size and eliminates a few instructions in some (albeit long) hot paths. > I believe the expected userspace interface is that you probe support > with set_robust_list first, and then start using the relevant futex > interfaces only if that call succeeded. In order for it to work, set_robust_list needs to succeed for all threads, present and future, so there's an implicit contract needed here that, if it succeeds once, it needs to always succeed. This is satisfied by the kernel implementation. FWIW I adopted a fix using get_robust_list to probe just to avoid coupling the internals of setting up the list with the bland function pthread_mutexattr_setrobust which is unaware of any implementation details except the location of the attribute bit. Presumably a similar probing should happen in pthread_mutexattr_setprotocol for PI mutex support. Does glibc do this? musl still lacks PI mutex support so I'll save this as a note for when it's added. > If you do that, most parts of > a typical system will work as expected even if the kernel support is > not there, which is a bit surprising. It definitely makes the root > cause harder to spot. I don't follow here. "most parts of a typical system will work as expected" seems to be the case whether you do or don't correctly probe. The only difference is whether a program that carefully checks for errors will see and report that pthread_mutexattr_setrobust failed. Rich