Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2303154ybp; Thu, 10 Oct 2019 05:33:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqzP/3i87/3uWyB9DS/Flomg5aIaNy7VIlA/T9z8lwJ+d1SweENI/MguFislQSVw9qxOctMd X-Received: by 2002:aa7:c38d:: with SMTP id k13mr7963393edq.34.1570710810064; Thu, 10 Oct 2019 05:33:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570710810; cv=none; d=google.com; s=arc-20160816; b=uVD6HmzFjoIzG0b1qmMB9J3AqYZWefxR+gbfmWufAh5/zEc8PsbGkjTT5YIPKCfy0a y8b8n/AU8i6FygrGLbP5PVikxQtkRVv8wA+LY0tQOZj1qXWzPJc+B5hLLZTCDrRLGj72 RqqH0skN0His/7gtupwmWBjA2IsYa8cs7vFigpe+IiLc7g/FobUUQoUpTp1y2H41XMxg eQuJa1EmmtK52lfcQqFvFJU5phHhjKVg/tr9k0fphQXnsL7BODDN8svdS76lWIYBDMMC 9b1aAvNSoZNzoyaqpcPxrywTIG0G1kHxVJk0t7UItXtH7/dwOhkHDklpJkLePwPJLVYs PhPw== 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:dkim-signature; bh=JHl9GmYtentxJL+7m1E2SgJVgP8t2x02tS9jT0BZXPY=; b=gp14CwzguUiYZC9SCpFB1I3NXkP7N7FG5Z3kqZCoz9npxz6G68ZDqIsdrJF+1kDjs5 g3/F+JAy0Y0g2FZiSa9ktvx6wsR+xy6mtR+bKIABHZWZ6O7Vt2qeAWs0c5B8CJ2nXPET GZaCtU0K/fG1zDwKrcnfrFaFY5cr9YOkcIkC5HwGmjGQYIe+1d5YQRHpK3X7gfHB2e71 arARGlyyUkovn2KKCgtChvO1nIOdSfwGhvLUcOs5TgWlJR529Oqk6+t4rnvh09VMWCuW bYkn0GuIfRwqN+L+/YA4LrwGsHtDdchd7bf/vFUlEIYJ/amLscm4iT2hDY1UwglU4frz HEoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=kc7eo7i+; 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 t18si3003661ejr.440.2019.10.10.05.33.06; Thu, 10 Oct 2019 05:33:30 -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; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=kc7eo7i+; 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 S1733231AbfJJMci (ORCPT + 99 others); Thu, 10 Oct 2019 08:32:38 -0400 Received: from merlin.infradead.org ([205.233.59.134]:59476 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726923AbfJJMci (ORCPT ); Thu, 10 Oct 2019 08:32:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=JHl9GmYtentxJL+7m1E2SgJVgP8t2x02tS9jT0BZXPY=; b=kc7eo7i+iGPnb8iSo9NczDvt8Y rHiGsvmqx6erZt14GL+1e78YvnlkwOKyVo5iRHX3aNc6HNbp075D50M0f/3cwgl3k/RKzpL/fn5wM HwmRmVLSPU73hu0+yOml9+pkJbkPL/YWeQLnxcbi+dqHiHAflRV9XbPnwVPP1pQVlh4Wuojy77Zd/ +DnGmEl9KT+vM1hdNOW5t7WCXnAqVKqFtFJN8sg3m4cOAF7mqkciZ9RpFPf7r0nm+GjldiZh9Hfok o/4vYmvXXwWQykt36mUK24VRQjx3gApcCdF/ZFsML1vLZHT4ZKAn7tMExucfcapZwXhbBM2KLLz1x 3b7Rv0yw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1iIXcD-0007JG-Cc; Thu, 10 Oct 2019 12:32:21 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 51A1B301224; Thu, 10 Oct 2019 14:31:27 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 88009205A4300; Thu, 10 Oct 2019 14:32:19 +0200 (CEST) Date: Thu, 10 Oct 2019 14:32:19 +0200 From: Peter Zijlstra To: Manfred Spraul Cc: Waiman Long , Davidlohr Bueso , Linux Kernel Mailing List , 1vier1@web.de, "Paul E. McKenney" Subject: Re: wake_q memory ordering Message-ID: <20191010123219.GO2328@hirez.programming.kicks-ass.net> References: <990690aa-8281-41da-4a46-99bb8f9fec31@colorfullife.com> <20191010114244.GS2311@hirez.programming.kicks-ass.net> <7af22b09-2ab9-78c9-3027-8281f020e2e8@colorfullife.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7af22b09-2ab9-78c9-3027-8281f020e2e8@colorfullife.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 10, 2019 at 02:13:47PM +0200, Manfred Spraul wrote: > Hi Peter, > > On 10/10/19 1:42 PM, Peter Zijlstra wrote: > > On Thu, Oct 10, 2019 at 12:41:11PM +0200, Manfred Spraul wrote: > > > Hi, > > > > > > Waiman Long noticed that the memory barriers in sem_lock() are not really > > > documented, and while adding documentation, I ended up with one case where > > > I'm not certain about the wake_q code: > > > > > > Questions: > > > - Does smp_mb__before_atomic() + a (failed) cmpxchg_relaxed provide an > > > ? ordering guarantee? > > Yep. Either the atomic instruction implies ordering (eg. x86 LOCK > > prefix) or it doesn't (most RISC LL/SC), if it does, > > smp_mb__{before,after}_atomic() are a NO-OP and the ordering is > > unconditinoal, if it does not, then smp_mb__{before,after}_atomic() are > > unconditional barriers. > > And _relaxed() differs from "normal" cmpxchg only for LL/SC architectures, > correct? Indeed. > Therefore smp_mb__{before,after}_atomic() may be combined with > cmpxchg_relaxed, to form a full memory barrier, on all archs. Just so. > > > - Is it ok that wake_up_q just writes wake_q->next, shouldn't > > > ? smp_store_acquire() be used? I.e.: guarantee that wake_up_process() > > > ? happens after cmpxchg_relaxed(), assuming that a failed cmpxchg_relaxed > > > ? provides any ordering. > > There is no such thing as store_acquire, it is either load_acquire or > > store_release. But just like how we can write load-aquire like > > load+smp_mb(), so too I suppose we could write store-acquire like > > store+smp_mb(), and that is exactly what is there (through the implied > > barrier of wake_up_process()). > > Thanks for confirming my assumption: > The code is correct, due to the implied barrier inside wake_up_process(). It has a comment there, trying to state this. task->wake_q.next = NULL; /* * wake_up_process() executes a full barrier, which pairs with * the queueing in wake_q_add() so as not to miss wakeups. */ wake_up_process(task);