Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5683057ybi; Tue, 4 Jun 2019 10:21:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqwJ2hM4NKU1NExyFtLZB/jeI2pQ/2rytacr8zJmGANyW/BKdDotgGtua0GCGV5bERyTeEti X-Received: by 2002:a63:18e:: with SMTP id 136mr36529391pgb.277.1559668900614; Tue, 04 Jun 2019 10:21:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559668900; cv=none; d=google.com; s=arc-20160816; b=FSQGq4HZ+H19OSeDBDZTMxBp7f6ILXSS0WXFsz8fH5rvJphcxbdrtibw/ShVoqiIws 8f+/7WbCyt2WVWc0MQxw5FMktEZ7py+GzmM47XWmS+KlEAj76Mub6NaExChk+dYajaKJ 3Xao3x5RxJHET3UrVyoV9bJjQB58Vn6cg/jV1W0WK1huXz3lKdoZ/DQ+PT8OZZCaLbVs BiTPXzYxpJdqfQ2FPycnlKNYOoDHPgdv3AIKJ5oLTOXDTxh17810vewXStnmv5mYdWmB Vo8E9J3nETN5XBzka6HML+mlkP0qhtFfbR//zhlhQn93UJMvqWVMi5zwvML6BrYodZyD 2onw== 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=gWGjWzmCxsyuXIXCpCZydRWI4/aqXORiJ7KdqIf6h8A=; b=BuDabQqRNdscO276J4n2MnSwMy7fbh9bNjGxxd0CNkAOU6rRgDy+h9VCybyaCTGw4p bTVtkcSTiBjW3nNI//hRyMMlcID1WFBsdrUkAoMagESyJdcGw7asmPowdTWD/MEJC0d/ QwJST+NSR4GupdKsbmAtvV0oF0ZZHxTctblYtqDWx46pNpXj/O1OuG7V46R5kJ4NKNOc TSU63UR8CDwEaleyAG0Jeovomzv6YtG/LZPAmlvNGM95nyA+qmlcTjKuWgNgErDCHkdG llK+n4IF8wplFuq25KbHJK9Kj7LVUHGRAfpG5JpsqHL2LVQSI/uvPEzSyR7+BXpg6OSH 6mUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=pnah5gSI; 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 t1si22010928pjv.82.2019.06.04.10.21.23; Tue, 04 Jun 2019 10:21:40 -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=pnah5gSI; 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 S1726295AbfFDRTR (ORCPT + 99 others); Tue, 4 Jun 2019 13:19:17 -0400 Received: from merlin.infradead.org ([205.233.59.134]:41312 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726092AbfFDRTR (ORCPT ); Tue, 4 Jun 2019 13:19:17 -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-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=gWGjWzmCxsyuXIXCpCZydRWI4/aqXORiJ7KdqIf6h8A=; b=pnah5gSItygt61ykCf1GYTq/j uUzMYF9hlIKA/l8FEHyURRElzRnkJ3zAL8SYH+lB2itn68gHmROydqhB3TsGGgNmXEPiCM3FRdZnK Mo1CYz+qCywwBDt24sgh7vU9aTS1N1dUGOAWxUY52r7iRl+hthks2u3ExihCj3H+2JzCgY6vqEwi5 5jLS6HaSLouyyumMm8KqkeDgkMDf0gWWebCelraH/QANcLXMTq+1A4fXAfk52wSZHcgNJshvqccCb HuYI8iiOsa/8HPh6pfjJo+pAmOjDksq46njBnXFh23fqWsySS66krfqiPRK9/MuBh/vJeMMcnrg4T Ln7EAfnjA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hYD5B-0007jT-Mr; Tue, 04 Jun 2019 17:18:46 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 4A82B2008D9D7; Tue, 4 Jun 2019 19:18:44 +0200 (CEST) Date: Tue, 4 Jun 2019 19:18:44 +0200 From: Peter Zijlstra To: Waiman Long Cc: Ingo Molnar , Will Deacon , Thomas Gleixner , Borislav Petkov , "H. Peter Anvin" , linux-kernel@vger.kernel.org, x86@kernel.org, Davidlohr Bueso , Linus Torvalds , Tim Chen , huang ying Subject: Re: [PATCH v8 17/19] locking/rwsem: Merge owner into count on x86-64 Message-ID: <20190604171844.GF3419@hirez.programming.kicks-ass.net> References: <20190520205918.22251-1-longman@redhat.com> <20190520205918.22251-18-longman@redhat.com> <20190604094537.GK3402@hirez.programming.kicks-ass.net> <20190604170218.GE3419@hirez.programming.kicks-ass.net> <28a6c7b5-c40e-1c89-03e2-688c1135f3b5@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <28a6c7b5-c40e-1c89-03e2-688c1135f3b5@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 Tue, Jun 04, 2019 at 01:06:11PM -0400, Waiman Long wrote: > On 6/4/19 1:02 PM, Peter Zijlstra wrote: > > On Tue, Jun 04, 2019 at 11:47:21AM -0400, Waiman Long wrote: > >> On 6/4/19 5:45 AM, Peter Zijlstra wrote: > >>> On Mon, May 20, 2019 at 04:59:16PM -0400, Waiman Long wrote: > >>>> With separate count and owner, there are timing windows where the two > >>>> values are inconsistent. That can cause problem when trying to figure > >>>> out the exact state of the rwsem. For instance, a RT task will stop > >>>> optimistic spinning if the lock is acquired by a writer but the owner > >>>> field isn't set yet. That can be solved by combining the count and > >>>> owner together in a single atomic value. > >>> I just realized we can use cmpxchg_double() here (where available of > >>> course). > >> Does the 2 doubles need to be 128-bit aligned to use cmpxchg_double()? I > >> don't think we can guarantee that unless we explicitly set this alignment. > > It does :/ and yes, we'd need to play games with __align(2*sizeof(long)) > > and such. > > So do you want this as an option now as it will be x86 specific? Or we > can do that as a follow-up if we want to. x86, s390 and arm64 have cmpxchg_double(). I was going to have a look (but like I wrote, I'm pretty useless today so i didn't actually get anywhere) at the exact race that's a problem here and see if there's not another solution too.