Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4459891ybi; Tue, 11 Jun 2019 07:03:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqwxMiwhrDgpixtXRouwrTVCofPdevh+NMOLlixQ8nTqP6Cuk3bnBRU2Mhln/aRFw/RhpgmP X-Received: by 2002:a17:902:42d:: with SMTP id 42mr72992902ple.228.1560261825131; Tue, 11 Jun 2019 07:03:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560261825; cv=none; d=google.com; s=arc-20160816; b=d/OGDOKml5utmftLw8BbDABBb/aSTB018VWniqmdbm7DgDIbFZk1H3NBB+GMtBF8UY 9AKay5/TqpdEV/8M5po4OUSqec2y9zx7imC7UGkG4lezhZighDjjI43noKCj+7mAkdol H1J8gkoaa2HMxjHlB0aj2OKmRgDVMMOAa44N/UObyCZQvemFBkDItzVfzLVRuyfnqBHi yQC2njtaM0+Zf23zRUldeyjZIgS3jnYqLaYyxif91vOHCvBaIG7cn+LKXIFwlqJf/YzN fyYq7fqPqUzKXeBOV1N3VrON5UaSqYcDnanSRUqNVqLekbrB/0kTW2sJh3+LKLPz21w0 b3mQ== 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=jTRI0sUYzBjbqkRPqRB0al8MVf/JfGUcO0S+nPEvatk=; b=AJQvh1o3pMpDPaeLcvmDimouegVBfgWIsVHudj/HyyKJujWhtk4Iq4UjMO2Mvysg32 AtREpaYnHA9c5xDtaNy7POHqdROs46Qe1eZXOWeKLnNl5MDWEl+edD5DChXE86B3i88U LRFgRTod1NADCACfbBxHENGeL6cxXpHK59aIaRfqq0jr4b8Am5awEk0a/+5y67TFuXKE cmie0frGriD1btOfQrSJoUyUWE27r36mbzYbGtXn3ILldFj/FAblxoczOqqg9bg43Owg XmyZwaItQ7vxZJe/2jXH1erjq7yOIWzcsAWjcOeE2RoxrUguAq33jowPYgofCZk7ulzn bOeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=fjO0Aztz; 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 bj12si6076295plb.378.2019.06.11.07.03.22; Tue, 11 Jun 2019 07:03:45 -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=bombadil.20170209 header.b=fjO0Aztz; 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 S2403771AbfFKNOG (ORCPT + 99 others); Tue, 11 Jun 2019 09:14:06 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:55296 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389077AbfFKNOG (ORCPT ); Tue, 11 Jun 2019 09:14:06 -0400 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=jTRI0sUYzBjbqkRPqRB0al8MVf/JfGUcO0S+nPEvatk=; b=fjO0Aztzc+pyUxCYwqc+vs43g 9rPrhQ89XcSL3p7dXSABlmjWx7puSS4lkAmMVaplO0j2zgrha07weiRGAOnNiH4sluZMkFByC89cT LVHVO5l5L+nBxAAoniGrGKXUg0RI4nqSYvhzyAoAxKhnqrRColkp+6H3Vxg0PofvzPGrVC63WfHwB zEB/Tap8Zqbj83rqp0AsFFhxvS1ktdmWqnJVgjXJwW7f0NMi4wNIEdL78HQoVh7JMay8mWT9g1F4c IxMwx6CjmDCi145Ibou4gy/hnkENzBj1sO++rdlsCPrzgi8yMOVET0efIptnELmP6tB1nqHDbFJ7U /ekJrFNtQ==; 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.92 #3 (Red Hat Linux)) id 1hagbA-0004VQ-K7; Tue, 11 Jun 2019 13:14:00 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 23DE520234FA4; Tue, 11 Jun 2019 15:13:59 +0200 (CEST) Date: Tue, 11 Jun 2019 15:13:59 +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 16/19] locking/rwsem: Guard against making count negative Message-ID: <20190611131359.GH3402@hirez.programming.kicks-ass.net> References: <20190520205918.22251-1-longman@redhat.com> <20190520205918.22251-17-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190520205918.22251-17-longman@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 Mon, May 20, 2019 at 04:59:15PM -0400, Waiman Long wrote: > static struct rw_semaphore __sched * > +rwsem_down_read_slowpath(struct rw_semaphore *sem, int state, long adjustment) > { > + long count; > bool wake = false; > struct rwsem_waiter waiter; > DEFINE_WAKE_Q(wake_q); > > + if (unlikely(!adjustment)) { > + /* > + * This shouldn't happen. If it does, there is probably > + * something wrong in the system. > + */ > + WARN_ON_ONCE(1); if (WARN_ON_ONCE(!adjustment)) { > + > + /* > + * An adjustment of 0 means that there are too many readers > + * holding or trying to acquire the lock. So disable > + * optimistic spinning and go directly into the wait list. > + */ > + if (rwsem_test_oflags(sem, RWSEM_RD_NONSPINNABLE)) > + rwsem_set_nonspinnable(sem); ISTR rwsem_set_nonspinnable() already does that test, so no need to do it again, right? > + goto queue; > + } > + > /* > * Save the current read-owner of rwsem, if available, and the > * reader nonspinnable bit.