From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751181AbdAaPkk (ORCPT ); Tue, 31 Jan 2017 10:40:40 -0500 Received: from mail01-md.ns.itscom.net ([175.177.155.111]:38172 "EHLO mail01-md.ns.itscom.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750840AbdAaPkc (ORCPT ); Tue, 31 Jan 2017 10:40:32 -0500 From: "J. R. Okajima" Subject: Re: Q: lockdep_assert_held_read() after downgrade_write() To: Jens Axboe Cc: peterz@infradead.org, linux-kernel@vger.kernel.org, darrick.wong@oracle.com, david@fromorbit.com In-Reply-To: <86195df9-2a43-2a0f-38ac-68792edc41c0@fb.com> References: <18295.1485811542@jrobl> <86195df9-2a43-2a0f-38ac-68792edc41c0@fb.com> Date: Wed, 01 Feb 2017 00:40:03 +0900 Message-ID: <5873.1485877203@jrobl> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jens Axboe: > 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: > > down_write(&rw); > downgrade_write(&rw); > lockdep_assert_held_read(&rw) > up_read(&rw); > > or just not drop up_write() from the last section. Arg... It is my bonehead mistake that I inserted up_write() before downgrade_write(). Sorry about that. Fortunately Peter Zijlstra reviewed downgrade_write() and sent a patch. Thank you, it passed my first test. Now allow me going on the second test (based upon Peter's patch) - two rwsem, rwA and rwB. - the locking order is rwA first, and then rwB. - good case down_read(rwA) down_read(rwB) up_read(rwB) up_read(rwA) down_write(rwA) down_write(rwB) up_write(rwB) up_write(rwA) - questionable case down_write(rwA) down_write(rwB) downgrade_write(rwA) downgrade_write(rwB) up_read(rwB) up_read(rwA) These two downgrade_write() have their strict order? If so, what is that? Do the added two lines + rwsem_release(&sem->dep_map, 1, _RET_IP_); + rwsem_acquire_read(&sem->dep_map, 0, 0, _RET_IP_); produce a traditional AB-BA deadlock warning, don't they? J. R. Okajima