Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4155238ybp; Sun, 13 Oct 2019 23:31:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxDrYcbGMEow0eZAmo62P25p0B9yEPsBe6r/CTDoD99aCCyw+BJ3EKLVais5Bw5aTjdiz09 X-Received: by 2002:a17:906:4c97:: with SMTP id q23mr26162336eju.78.1571034698940; Sun, 13 Oct 2019 23:31:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571034698; cv=none; d=google.com; s=arc-20160816; b=SEHy101NWV2w3P5hDsIxtv4zzHg3s9NP2wdPjax9cHjgMkMfhzW8JhFMDaN71ETDNI aeLNYejE677T/MOJ4bSMl4n5PaOEPU808gGNElNvcAr4XGqF3mStAVZGjcjW7WEhaRgq mzEV/v+MGwhXI/e3jGu6J5XmynlkpmncuwHskQDsnle44GUBCwy+e/uhwWC/7eKyfRhc tRnbYR5HXWA9yyvtEMMPjsTJZnl6QUz7qzrhKg4UvN29SVEPHBpywI4dcwqHDzy21AXT fsBy1taLdBHKyLtXN7BS7/uZJD309NA90dRmgANzWwjNpTGsuF5lppkR6mBPSekjnpxs IqEA== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=oYYDY24osyKtWfT7VbZ4jlW9wYPpMdd673FccLDFnW8=; b=JO2V/fO8etYp3ks8sALdogHhseGwq3pZWr1hK+QR+FEergyzyPB3QU/mlyRoNRwZaU c5iIVS9jgfhtBZeO3DJQy0485HcS5rEcwpei5tXtHAaG04BdzUEW6pfoYAMqXLfkRch+ +1zOVK3uCG0NvKKNv0wxAPwC1jeGNgSbnc7aaDcXvSCNTrNWieSah9zZeXJRBlYpMj2q Ql7EQyY5PDTzvcttviVk01BMGvIG+B41lyyhaLoBepnUOJ8YczvvsCJ209w3dwb/36hz ZgLItsBoZKCu5rIByL7QgaYtF7hqF8+oahhYfViRUYgCqJf9kABy9JUewVVLCsJRfaQ5 XNjQ== 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 g21si10591392edg.339.2019.10.13.23.31.15; Sun, 13 Oct 2019 23:31:38 -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 S1729992AbfJNGag (ORCPT + 99 others); Mon, 14 Oct 2019 02:30:36 -0400 Received: from mx2.suse.de ([195.135.220.15]:45488 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729903AbfJNGag (ORCPT ); Mon, 14 Oct 2019 02:30:36 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D9F34B310; Mon, 14 Oct 2019 06:30:34 +0000 (UTC) Date: Sun, 13 Oct 2019 23:29:19 -0700 From: Davidlohr Bueso To: Manfred Spraul Cc: LKML , Waiman Long , 1vier1@web.de, Andrew Morton , Peter Zijlstra , Jonathan Corbet Subject: Re: [PATCH 2/5] ipc/mqueue.c: Update/document memory barriers Message-ID: <20191014062919.rr56mj5uzyb7sj6r@linux-p48b> References: <20191011112009.2365-1-manfred@colorfullife.com> <20191011112009.2365-3-manfred@colorfullife.com> <20191011165527.bsdiw6gu2sk7yrnl@linux-p48b> <5e08cb89-563c-4763-dd88-94edaf9d883b@colorfullife.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <5e08cb89-563c-4763-dd88-94edaf9d883b@colorfullife.com> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 11 Oct 2019, Manfred Spraul wrote: >But you are right, there are two different scenarios: > >1) thread already in another wake_q, wakeup happens immediately after >the cmpxchg_relaxed(). > >This scenario is safe, due to the smp_mb__before_atomic() in wake_q_add() > >2) thread woken up but e.g. a timeout, see ->state=STATE_READY, >returns to user space, calls sys_exit. > >This must not happen before get_task_struct acquired a reference. > >And this appears to be unsafe: get_task_struct() is refcount_inc(), >which is refcount_inc_checked(), which is according to lib/refcount.c >fully unordered. > >Thus: ->state=STATE_READY can execute before the refcount increase. > >Thus: ->state=STATE_READY needs a smp_store_release(), correct? What if we did the reference count explicitly, and then just use wake_q_add_safe()? That would avoid the extra barrier, __pipelined_op() would become: list_del(); get_task_struct(); wake_q_add_safe(); WRITE_ONCE(->state, STATE_READY); Thanks, Davidlohr