Received: by 10.213.65.68 with SMTP id h4csp79074imn; Tue, 27 Mar 2018 22:26:58 -0700 (PDT) X-Google-Smtp-Source: AIpwx48CFj7mJyrBey2RCQPpqlehueT9tHiM9FevK6ugtn0bba8zLXRXuR1hFlUZe5EvWx+aXBNm X-Received: by 10.98.182.26 with SMTP id j26mr1761859pff.223.1522214818629; Tue, 27 Mar 2018 22:26:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522214818; cv=none; d=google.com; s=arc-20160816; b=j7QaqRZZ33WLe+wjFsHJeZ2TRAHulgG4iJ/EeP1U1RHjVdIzynwpH98ujdaVcr+KSB LJbfLiS56E09i91CojefLoIN1EdR/0DUHSxKgSrT7tTL/vlLO9jKUgGjEvmn2RtplOv0 XuVw0xWJjlQBM7s3y73wCAD4PErjWZsUEcid7RduVCCRHfoqrAn6joBQqnoP9pW10Yzz LSglVF+HvmM3niWt9H7j6NgKLBdqNBxPngZZqDPny20WvmUsVYnucaHOxMT9FROXP0rk +9XFo/qgWj6aynz2ft7f0kulhdrjKPo2lPxSwMtiqsnRZ036H+f3cyd50B1/mdh/W/oV zIOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:arc-authentication-results; bh=7JJ0Wzq9yUeSvW3o7QHNJ0aOwO+pwcOXNxBvvH6A25s=; b=h5WI1Wtb3fwq/H8x9TK0F4WT8NwpZyK6ijwGiSZ0/hdPJYp09n1/8Ax5jETDLCTMre WBLZb9We8TuV5Wqd7EGdsgi7qk2a5GjhYdvqUaX8SgcndiL+6/eetinmvG0sUKkwO7Ac w1Td7Paxp1gb3rEYqAW/ycOoPN7GBJcbPHg0IZtE3xMhUYUn50E1KKwM1FNkS9lKETjv 7SmoQnMGWYvlAL3ZGYrVdfumopDrLE8811/QeJKeQqRpLcB+r+ugWRa9VHbV+qjLYlNu 1nwBAjZMTW7WV3UiipBba5U2MgfpnWjlOG95z7WFjucxsf4hYwZmBrQIwVc4CmW5hFxu 4LLA== 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 3-v6si2723926plc.700.2018.03.27.22.26.43; Tue, 27 Mar 2018 22:26:58 -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 S1751209AbeC1FZl (ORCPT + 99 others); Wed, 28 Mar 2018 01:25:41 -0400 Received: from ozlabs.org ([103.22.144.67]:44029 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750733AbeC1FZk (ORCPT ); Wed, 28 Mar 2018 01:25:40 -0400 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 409xDL0mT3z9s0x; Wed, 28 Mar 2018 16:25:37 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au From: Michael Ellerman To: Andrea Parri , Benjamin Herrenschmidt Cc: Paul Mackerras , Peter Zijlstra , Ingo Molnar , linux-kernel@vger.kernel.org, Linus Torvalds Subject: Re: [PATCH for-4.17 2/2] powerpc: Remove smp_mb() from arch_spin_is_locked() In-Reply-To: <20180327102521.GA7347@andrea> References: <1522060667-7034-1-git-send-email-andrea.parri@amarulasolutions.com> <1522109216.7364.30.camel@kernel.crashing.org> <20180327102521.GA7347@andrea> Date: Wed, 28 Mar 2018 16:25:37 +1100 Message-ID: <87a7us3h66.fsf@concordia.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Andrea Parri writes: > On Tue, Mar 27, 2018 at 11:06:56AM +1100, Benjamin Herrenschmidt wrote: >> On Mon, 2018-03-26 at 12:37 +0200, Andrea Parri wrote: >> > Commit 51d7d5205d338 ("powerpc: Add smp_mb() to arch_spin_is_locked()") >> > added an smp_mb() to arch_spin_is_locked(), in order to ensure that >> > >> > Thread 0 Thread 1 >> > >> > spin_lock(A); spin_lock(B); >> > r0 = spin_is_locked(B) r1 = spin_is_locked(A); >> > >> > never ends up with r0 = r1 = 0, and reported one example (in ipc/sem.c) >> > relying on such guarantee. >> > >> > It's however understood (and undocumented) that spin_is_locked() is not >> > required to ensure such ordering guarantee, >> >> Shouldn't we start by documenting it ? > > I do sympathize with your concern about the documentation! ;) The patch in > [1] was my (re)action to this concern; the sort of the patch is unclear to > me by this time (and I'm not aware of other proposals in this respect). >> >> > guarantee that is currently >> > _not_ provided by all implementations/arch, and that callers relying on >> > such ordering should instead use suitable memory barriers before acting >> > on the result of spin_is_locked(). >> > >> > Following a recent auditing[1] of the callers of {,raw_}spin_is_locked() >> > revealing that none of them are relying on this guarantee anymore, this >> > commit removes the leading smp_mb() from the primitive thus effectively >> > reverting 51d7d5205d338. >> >> I would rather wait until it is properly documented. Debugging that IPC >> problem took a *LOT* of time and energy, I wouldn't want these issues >> to come and bite us again. > > I understand. And I'm grateful for this debugging as well as for the (IMO) > excellent account of it you provided in 51d7d5205d338. Thanks, you're welcome :) > Said this ;) I cannot except myself from saying that I would probably have > resisted that solution (adding an smp_mb() in my arch_spin_is_locked), and > instead "blamed"/suggested that caller to fix his memory ordering... That was tempting, but it leaves unfixed all the other potential callers, both in in-tree and out-of-tree and in code that's yet to be written. Looking today nearly all the callers are debug code, where we probably don't need the barrier but we also don't care about the overhead of the barrier. Documenting it would definitely be good, but even then I'd be inclined to leave the barrier in our implementation. Matching the documented behaviour is one thing, but the actual real-world behaviour on well tested platforms (ie. x86) is more important. cheers