Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp658972yba; Thu, 18 Apr 2019 07:33:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqzbsRKI3+Eae6kUEqu+sIUwsvzQTpuyTzaNw6H6MqMu37UzdGsIlXvNDJ5BQXpxKwvszSat X-Received: by 2002:aa7:91d5:: with SMTP id z21mr14610309pfa.222.1555597980432; Thu, 18 Apr 2019 07:33:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555597980; cv=none; d=google.com; s=arc-20160816; b=tiNB9MN6tzK/2hDuhPaldkAoTJ0JcwEhWkEMs9OTBkS1N2LXii7VZ/BcgVjijaOI8A jNWaekkuTj+9wpVPKwousRthplwrQuWtEhXLN7P38QOALDIyQDO3WXbuac92VX88/Haj vQu3QiNQ9HLIi3+tXkFZ7PYw+y0f0Y4UFlgwYLSdn5p1V6VxIcOlG/fwUd2HeN4EtCJY IHcma2equCVxPLTlYcSOGIqmm/r2b3WZFwPgi7DHKRpj9aWKYl8SpP0OW2KbhpxOhwsx B3oMLag8R4oaXbs4GK5Am4c/oybkinnyva4CZJXCTYrTJ65c4NN4tl7pcwu64MUHgGy0 3xkQ== 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=J1Rd8CJHOriTctJ+pY5mSELh59zsKZpvgRGWgzuNSlc=; b=nSb9oZX8/8WWX9SAwwehm1F/hs7U1xkNSAFQJ+gTPO/7XuahHR5uWdnCKLy0SV7d3f UHNG1krjQ/TuodhPf81NNh1Sx2Ubg7yzcjzvdvKF4DnqeVUe2CLP3o2TsQ8m3HH48iMG 86XOOjOGPGLw2S+0HzVyp17FdZJhmR+1kXI0d/EBSotaodJgDp43Zg+/rNqxFaGI48rT p3C7PVkiczkGcIULmksfcYuHUYX0HxAb0z346dUP2ZmGOxIHBjWHDjV6EFqjaL3n3rJB GCW1griIbwkvNyblN/1LlkolwGR0xnhGmt9wIU52d2oaALkYzW8oYgz98z7td+nGD189 ohqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=mlghnc4z; 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 i64si1893129pge.179.2019.04.18.07.32.43; Thu, 18 Apr 2019 07:33:00 -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=mlghnc4z; 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 S2389284AbfDRObK (ORCPT + 99 others); Thu, 18 Apr 2019 10:31:10 -0400 Received: from merlin.infradead.org ([205.233.59.134]:40740 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388097AbfDRObJ (ORCPT ); Thu, 18 Apr 2019 10:31:09 -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=J1Rd8CJHOriTctJ+pY5mSELh59zsKZpvgRGWgzuNSlc=; b=mlghnc4zMJtXMOVGws2LWViNE wpdDlSyMTckeE2JlRdzDcVhbgK4WjXsiT939yYUV6IG4CQSwMnYR2kpXodB7O5Uf194cF1j52CQuD m2FDKU3xnIXfET0uc8ZzzMOSSacWioU22sqNSmehshicFLe0+IrAD2QVAn4unoByKR5eHhzsnwoA1 6TIlDw9I1eE/9mz4LXaHevGymwsJGpf4B7VEwPXQoGN7pebxq8mfIuCVP3h5xGj7HhNpBEY/XZGyC pGMu5mZwUxmOYilXz8MBnPL2vMJmLRKkubUQycocx/vlR74eZBdVn9MeSor7T9XxpeGH4LfAhPH47 tQZXmgQ0w==; 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 1hH843-0002wY-TL; Thu, 18 Apr 2019 14:31:00 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 9FF5329B9B7B7; Thu, 18 Apr 2019 16:30:58 +0200 (CEST) Date: Thu, 18 Apr 2019 16:30:58 +0200 From: Peter Zijlstra To: Waiman Long Cc: Ingo Molnar , Will Deacon , Thomas Gleixner , linux-kernel@vger.kernel.org, x86@kernel.org, Davidlohr Bueso , Linus Torvalds , Tim Chen , huang ying Subject: Re: [PATCH v4 14/16] locking/rwsem: Guard against making count negative Message-ID: <20190418143058.GD12232@hirez.programming.kicks-ass.net> References: <20190413172259.2740-1-longman@redhat.com> <20190413172259.2740-15-longman@redhat.com> <20190418135151.GB12232@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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, Apr 18, 2019 at 10:08:28AM -0400, Waiman Long wrote: > On 04/18/2019 09:51 AM, Peter Zijlstra wrote: > > On Sat, Apr 13, 2019 at 01:22:57PM -0400, Waiman Long wrote: > >> inline void __down_read(struct rw_semaphore *sem) > >> { > >> + long count = atomic_long_fetch_add_acquire(RWSEM_READER_BIAS, > >> + &sem->count); > >> + > >> + if (unlikely(count & RWSEM_READ_FAILED_MASK)) { > >> + rwsem_down_read_failed(sem, count); > >> DEBUG_RWSEMS_WARN_ON(!is_rwsem_reader_owned(sem), sem); > >> } else { > >> rwsem_set_reader_owned(sem); > > *groan*, that is not provably correct. It is entirely possible to get > > enough fetch_add()s piled on top of one another to overflow regardless. > > > > Unlikely, yes, impossible, no. > > > > This makes me nervious as heck, I really don't want to ever have to > > debug something like that :-( > > The number of fetch_add() that can pile up is limited by the number of > CPUs available in the system. Uhhn, no. There is no preempt_disable() anywhere here. So even UP can overflow if it has enough tasks.