Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2825954imu; Thu, 29 Nov 2018 10:50:22 -0800 (PST) X-Google-Smtp-Source: AFSGD/X9qYMTHTYa07J3LnN+5lnbPOVBBSr5TMV9g5OCFNpJwXQMb2WByyEmXUqqZ5H5eRGRTC16 X-Received: by 2002:a63:5e43:: with SMTP id s64mr1023087pgb.101.1543517422378; Thu, 29 Nov 2018 10:50:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543517422; cv=none; d=google.com; s=arc-20160816; b=a3tLr646iXOUZ2lHwzAwix/ad4uPhormEiCswlOgEoycd1Zda+smq8hYrfhvWe5RD0 XRFjVmlkgsRLDQ7SwLfe0yGbtutD+g8YxpoHnu/WD8V8RaDPBxviL3aJoPgqJCyvjarT EeVTayn/HvbifEQPreJ5CkjxRANt7j0SdIEg0nd1gfypdlKu/cGkxQdnPTd/vQAMhH1m lnQOruXbPubCUgsShVqYq3NZLS28PLfM/dk1igPpuQSc85LWsIBUDuzcwZvCwAg+fr0j 9UbXdpSylYohFC8B+48ZTIOfn56lGvGMgG9aBtIR8XZhzOgNK8/1ErTLI9p/b4GxkW5f RsLQ== 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=SNT7shgoaVk1Z1PzQZ5Mj4e+VjF0v/MjE1e/VrzuxYM=; b=lAR4AB7vC5z2NvMGydbra48ewaywPwHCcnCmq27KFghG5+Hh23zhiTP7xpA77dyVMD qal4zC3xLW0M+b0BcDDQt4E0ygVCLZis58MwYYkFV1mdnyb8x7sH7mcc656J4Ng0uFL/ 0f54tm5f8q+a3aWifVIbZWZm1a1c5eJ60SPxDK/ZWCbbKbRLXwR3Z3Zi1XnBlCkrYO5U 0lFFsC6xpsFB1JCUCWjj7TZOcnzVn6Mmh6cZ73yXs8UzCqzIBsuliQ10PHNIeHfOUokY y9Y7JIFrD9xrP8hm3VMs7moorxcjLv9T0iwZfLNQipR9DUmW3cIPNFPfy8BDGLvnc4H3 0rrQ== 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 y84si2402174pfc.68.2018.11.29.10.50.07; Thu, 29 Nov 2018 10:50:22 -0800 (PST) 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 S1726428AbeK3Ft5 (ORCPT + 99 others); Fri, 30 Nov 2018 00:49:57 -0500 Received: from mx2.suse.de ([195.135.220.15]:56698 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725873AbeK3Ft5 (ORCPT ); Fri, 30 Nov 2018 00:49:57 -0500 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 7C315AD5C; Thu, 29 Nov 2018 18:43:36 +0000 (UTC) Date: Thu, 29 Nov 2018 10:43:29 -0800 From: Davidlohr Bueso To: Peter Zijlstra Cc: Yongji Xie , mingo@redhat.com, will.deacon@arm.com, linux-kernel@vger.kernel.org, xieyongji@baidu.com, zhangyu31@baidu.com, liuqi16@baidu.com, yuanlinsi01@baidu.com, nixun@baidu.com, lilin24@baidu.com, Waiman Long , Thomas Gleixner Subject: Re: [RFC] locking/rwsem: Avoid issuing wakeup before setting the reader waiter to nil Message-ID: <20181129184329.ftxhtpgx4rwzoh6y@linux-r8p5> References: <1543495830-2644-1-git-send-email-xieyongji@baidu.com> <20181129131232.GN2131@hirez.programming.kicks-ass.net> <20181129134449.GH2149@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20181129134449.GH2149@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20180323 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 29 Nov 2018, Peter Zijlstra wrote: >On Thu, Nov 29, 2018 at 02:12:32PM +0100, Peter Zijlstra wrote: >> Yes, I think this is real, and worse, I think we need to go audit all >> wake_q_add() users and document this behaviour. >> >> In the ideal case we'd delay the actual wakeup to the last wake_up_q(), >> but I don't think we can easily fix that. > >See commit: 1d0dcb3ad9d3 ("futex: Implement lockless wakeups"), I think >that introduces the exact same bug. > >Something like the below perhaps, altough this pattern seems to want a >wake_a_add() variant that already assumes get_task_struct(). So I was looking at ways to avoid the redundant reference counting, but given how wake_q_add() and wake_up_q() are so loose I can't see how to avoid it -- we hold reference across the calls to maintain valid mem. For example, wake_q will grab reference iff the cmpxchg succeeds, likewise it will enter the wakeup loop in wake_up_q(), and there is no awareness of which caller had the failed cmpxchg because another wakup was in progress. And yes, afaict all wake_q users suffer from the same issue, so we have to move the wake_q_add() after the condition, while explicitly doing the task ref counting. Thanks, Davidlohr