Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2647666imu; Thu, 29 Nov 2018 08:09:09 -0800 (PST) X-Google-Smtp-Source: AFSGD/U0kjMJ/cp6witnL6ms2mEgYr0Pd2gJ3tlwlDvn7C8A+X+44KloxxPXmhLN2RVvsTkKvN9L X-Received: by 2002:a62:5bc7:: with SMTP id p190-v6mr1929969pfb.175.1543507749300; Thu, 29 Nov 2018 08:09:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543507749; cv=none; d=google.com; s=arc-20160816; b=OhzsEa7WeNt5gim9xrRaJh5+zTFK98VGQYrOfVNvOB3oGQLZUypi2PYACpBQnjtUuB yY1rig1VGtdWdRisIzlo9az65hTkxBbiusjWkqlP/A8iJm/YBaF7PcO5aaERAm/18HUg uQPEZSvZanA5g/mky++Aui1jq+cZCV8mYNBU9Xeb4uwqU9vyHlbJx88E334hhw4L0Ti+ WCPNYPljkRlEDPvzqYPK7WVLsBGVptUHBsFC716DwpTbKk9JGpSfd1+ef2cHHr5CG0iH xsayxjgj4F4A5PLn/h/xTiaOvwNUWuMbJWiaTbIf5CiAMfmr5pevPiNhKhOmvfu5rBdd V0yA== 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:dkim-signature; bh=CX5oAC3wZPuif0c1h+buzxsrGVj6+VxDHVSytBvEyII=; b=rEBhFU/CFKYYVr4plByVdw2CCSX43P7Ig98lpYe551KsJsKU9/+VvN8Gexf/6KeWYM vhEOL97K2AjN81DzOLn+LbjHXLNQnzKyys88z7R4OY/D/eSHZUctYMg1doyZ+osD+AzT cOSBhU8t0Pcx3HVhApLuS3cAXx8JDI1SgeVg1KHY+akbbm9QgJ6Q57PUMwEx+cLZOhoS yqo9mZl77vdtrZ7l11BPzeu0OG2aNCQlpQYXriS/oM3A2d5HdKBu0sOjy+Zv16jZOYkk 2Hr76Bvb5IX8QVpT2I0s6fNN66K/ipDqRnA45/s1fO8X89DzwnoIHpZAuCMUFMxQPTC0 rlgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=nau6UIs3; 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 m8si2300998pgd.555.2018.11.29.08.08.35; Thu, 29 Nov 2018 08:09:09 -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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=nau6UIs3; 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 S1729196AbeK3DM2 (ORCPT + 99 others); Thu, 29 Nov 2018 22:12:28 -0500 Received: from bombadil.infradead.org ([198.137.202.133]:46638 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728635AbeK3DM1 (ORCPT ); Thu, 29 Nov 2018 22:12:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding: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=CX5oAC3wZPuif0c1h+buzxsrGVj6+VxDHVSytBvEyII=; b=nau6UIs362HXzB5SHMi96qkqO qpKMHtTtiG6Uq4ecnwC1KpBIdMHx+/DFzM3PK4TNR1fb+CHrUmoPMbm6CNpEWArULdgh1GfpdORRN BcV/3PjybtqVOuy2Mop/m05ngGPgSnUSO9niittBWOTY5PoqXG2MCknMKwHn/59SDWTRrSVUdmzbq dee8YUuDXDyqytzCykX/Bwkxy5JK5VhoFoGS63gAw5Kpmagco09pnuawQOKRTc6a5TPiFCFsBxa6f HXI2nk5MBXMCnBM3Osv4xf2PHQwBSnDwdvDYQiC8HuzK8jT/4T6igtv/OHmwATvsjlpu087IOifQM HOh384edA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gSOph-0003ru-1v; Thu, 29 Nov 2018 16:06:29 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5CF772029FD58; Thu, 29 Nov 2018 17:06:27 +0100 (CET) Date: Thu, 29 Nov 2018 17:06:27 +0100 From: Peter Zijlstra To: Waiman Long 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, Davidlohr Bueso Subject: Re: [RFC] locking/rwsem: Avoid issuing wakeup before setting the reader waiter to nil Message-ID: <20181129160627.GU2131@hirez.programming.kicks-ass.net> References: <1543495830-2644-1-git-send-email-xieyongji@baidu.com> <20181129131232.GN2131@hirez.programming.kicks-ass.net> <5598cd71-c3c8-d6ef-eb30-777cf901a2ef@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5598cd71-c3c8-d6ef-eb30-777cf901a2ef@redhat.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, Nov 29, 2018 at 10:21:58AM -0500, Waiman Long wrote: > >> diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c > >> index 09b1800..50d9af6 100644 > >> --- a/kernel/locking/rwsem-xadd.c > >> +++ b/kernel/locking/rwsem-xadd.c > >> @@ -198,15 +198,22 @@ static void __rwsem_mark_wake(struct rw_semaphore *sem, > >> woken++; > >> tsk = waiter->task; > >> > >> - wake_q_add(wake_q, tsk); > >> + get_task_struct(tsk); > >> list_del(&waiter->list); > >> /* > >> - * Ensure that the last operation is setting the reader > >> + * Ensure calling get_task_struct() before setting the reader > >> * waiter to nil such that rwsem_down_read_failed() cannot > >> * race with do_exit() by always holding a reference count > >> * to the task to wakeup. > >> */ > >> smp_store_release(&waiter->task, NULL); > >> + /* > >> + * Ensure issuing the wakeup (either by us or someone else) > >> + * after setting the reader waiter to nil. > >> + */ > >> + wake_q_add(wake_q, tsk); > >> + /* wake_q_add() already take the task ref */ > >> + put_task_struct(tsk); > >> } > >> > >> adjustment = woken * RWSEM_ACTIVE_READ_BIAS - adjustment; > > I doubt putting wake_q_add() after clearing waiter->task can really fix Why; at that point we know the wakeup will happen after, which is all we require.