From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751815AbdAaLE7 (ORCPT ); Tue, 31 Jan 2017 06:04:59 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:39696 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751549AbdAaLEv (ORCPT ); Tue, 31 Jan 2017 06:04:51 -0500 Date: Tue, 31 Jan 2017 11:36:20 +0100 From: Peter Zijlstra To: Jens Axboe Cc: "J. R. Okajima" , linux-kernel@vger.kernel.org, darrick.wong@oracle.com, david@fromorbit.com Subject: Re: Q: lockdep_assert_held_read() after downgrade_write() Message-ID: <20170131103620.GM6515@twins.programming.kicks-ass.net> References: <18295.1485811542@jrobl> <86195df9-2a43-2a0f-38ac-68792edc41c0@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <86195df9-2a43-2a0f-38ac-68792edc41c0@fb.com> User-Agent: Mutt/1.5.23.1 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 30, 2017 at 02:30:45PM -0700, Jens Axboe wrote: > On 01/30/2017 02:25 PM, J. R. Okajima wrote: > > Peter Zijlstra, > > > > May I ask you a question? > > v4.10-rc1 got a commit > > f831948 2016-11-30 locking/lockdep: Provide a type check for lock_is_held > > I've tested a little and lockdep splat a stack trace. > > > > { > > DECLARE_RWSEM(rw); > > static struct lock_class_key key; > > lockdep_set_class(&rw, &key); > > > > down_read(&rw); > > lockdep_assert_held_read(&rw); > > up_read(&rw); > > > > down_write(&rw); > > lockdep_assert_held_exclusive(&rw); > > up_write(&rw); > > > > downgrade_write(&rw); > > lockdep_assert_held_read(&rw); <-- here > > up_read(&rw); > > } > > > > I was expecting that lockdep_assert_held_read() splat nothing after > > downgrade_write(). Is this warning an intentional behaviour? > > > > Also the final up_read() gives me a warning too. It is produced at > > lockdep.c:3514:lock_release(): DEBUG_LOCKS_WARN_ON(depth <= 0) > > I don't think you understand how it works. downgrade_write() turns a write > lock into read held. To make that last sequence valid, you'd need: Correct, and I'm surprised that didn't explode in different ways. > > down_write(&rw); > downgrade_write(&rw); > lockdep_assert_held_read(&rw) > up_read(&rw); > > or just not drop up_write() from the last section. Right, but also, there seems to be a missing lockdep annotation to make that work. That is, downgrade_write() doesn't have a lockdep annotation, so it (lockdep) will still think its a write lock. Let me try and fix both issues.