Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp700630yba; Fri, 3 May 2019 09:05:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4bkBRq09luc07+IzS/gV4w/EjH2aOx0S+c6iu+ywesP4eDK9JgDwtK6LAYIE457qKfwzt X-Received: by 2002:a65:4489:: with SMTP id l9mr11043373pgq.1.1556899520936; Fri, 03 May 2019 09:05:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556899520; cv=none; d=google.com; s=arc-20160816; b=oiX2AmAgHXlEdcMf5O1m/Ky3/zlJeV51UXgU+ujmBb+uK3jbZ7hGUmAXLWhoY3fMS2 eSGhFGeeM5HhSOj8J/4GmJIWvv3ArONLba3+m4A2kitf++QnjUbW4lyGHWAWf3h8jVwB mVXUKGxtIg4ANSf93/JtWNdwwnrCkGlx1yLn+R1Fl8tmTrRmWxfddIBbiY/GJAI376OT fgNNATaofPWc5Iu1bSA0Y5EcAwoEZJvumk7sVwTsss4WiMVQDLsZhGabZvSKWQ/+Prnp 1f8rKfxto/JWsn9ddIhgHMCZ0J/RY2tULoEWpGdyoUSiTzMj9hYchO7aXbYIG0TUfNtV EiEA== 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=lWg0JPj9e/gRwSlFXsEmcb/CzVkvs80ThDEUvZmJx1Q=; b=dTuOegM3LX55cwYcui6B36N31GUf7mRN7S0lixMThR1AnQ3w1NNnp7uSL1TLnU61qC cfVhmail8SzTh/j8/c4elJnTWsX3+jCoAyaU31CB+zLOXhHP/PPMjfVcS7tPB2Fdt1Kd pTtXCdkz8O1yPILMkuTZwZ4BfrZAivJEeU27hNTVdtB3N2wMvEmYKeh4AlLe1Yc5qIBW kU4E8XQcFrru+9fASolK9v2N2gK0sKK8gQewqsBhPjVbHVAi1iiWuGSlvVsONpRgijNT tfbbUX/e0Pagu9wL9VdKjuHyskvVVWl5mSLOYFoyzI8XfouQJ6OHNBqVEU5AJJ3kaLbY Qljg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z22si1622626plo.171.2019.05.03.09.05.04; Fri, 03 May 2019 09:05:20 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728361AbfECPhy (ORCPT + 99 others); Fri, 3 May 2019 11:37:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41532 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726476AbfECPhy (ORCPT ); Fri, 3 May 2019 11:37:54 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 521BC307EA9C; Fri, 3 May 2019 15:37:54 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.43.17.159]) by smtp.corp.redhat.com (Postfix) with SMTP id 0903819C4F; Fri, 3 May 2019 15:37:48 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Fri, 3 May 2019 17:37:54 +0200 (CEST) Date: Fri, 3 May 2019 17:37:48 +0200 From: Oleg Nesterov To: Peter Zijlstra Cc: Sebastian Andrzej Siewior , linux-rt-users , LKML , Thomas Gleixner , Daniel Bristot de Oliveira , Clark Williams , Juri Lelli , jack@suse.com, Waiman Long , Davidlohr Bueso Subject: Re: [RT WARNING] DEBUG_LOCKS_WARN_ON(rt_mutex_owner(lock) != current) with fsfreeze (4.19.25-rt16) Message-ID: <20190503153747.GC20802@redhat.com> References: <20190326093421.GA29508@localhost.localdomain> <20190419085627.GI4742@localhost.localdomain> <20190430125130.uw7mhdnsoqr2v3gf@linutronix.de> <20190430132811.GB2589@hirez.programming.kicks-ass.net> <20190501170953.GB2650@hirez.programming.kicks-ass.net> <20190502100932.GA7323@redhat.com> <20190503141633.GB2606@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190503141633.GB2606@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 03 May 2019 15:37:54 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/03, Peter Zijlstra wrote: > > On Thu, May 02, 2019 at 12:09:32PM +0200, Oleg Nesterov wrote: > > > > +static void readers_block(struct percpu_rw_semaphore *sem) > > > +{ > > > + wait_event_cmd(sem->writer, !sem->readers_block, > > > + __up_read(&sem->rw_sem), __down_read(&sem->rw_sem)); > > > +} > > > + > > > +static void block_readers(struct percpu_rw_semaphore *sem) > > > +{ > > > + wait_event_exclusive_cmd(sem->writer, !sem->readers_block, > > > + __up_write(&sem->rw_sem), > > > + __down_write(&sem->rw_sem)); > > > + /* > > > + * Notify new readers to block; up until now, and thus throughout the > > > + * longish rcu_sync_enter() above, new readers could still come in. > > > + */ > > > + WRITE_ONCE(sem->readers_block, 1); > > > +} > > > > So iiuc, despite it name block_readers() also serializes the writers, ->rw_sem > > can be dropped by down_write_non_owner() so the new writer can take this lock. > > I don't think block_readers() is sufficient to serialize writers; > suppose two concurrent callers when !->readers_block. Without ->rwsem > that case would not serialize. Of course. I meant that the next writer can enter block_readers() if up_non_owner() drops ->rw_sem, but it will block in wait_event(!readers_block). (And if we change this code to use wait_event(xchg(readers_block) == 0) we can remove rw_sem altogether). The main problem is that this is sub-optimal. We can have a lot of readers sleeping in __down_read() when percpu_down_write() succeeds, then after percpu_down_write_non_owner() does up_write() they all will be woken just to hang in readers_block(). Plus the new readers will need to pass the lock-check-unlock-schedule path. Peter, just in case... I see another patch from you but I need to run away till Monday. Oleg.