From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S971577AbeEXVOR (ORCPT ); Thu, 24 May 2018 17:14:17 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:51202 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967358AbeEXVOO (ORCPT ); Thu, 24 May 2018 17:14:14 -0400 X-Google-Smtp-Source: AB8JxZomeNky/loeRugOxyutaAzJTNgOw2hrJzcXA8CfKW8kTe112ZUO8UjY+4Fn81C5mwuUt3Rmng== Date: Thu, 24 May 2018 23:14:05 +0200 From: Andrea Parri To: Boqun Feng Cc: Will Deacon , Linus Torvalds , psodagud@codeaurora.org, Kees Cook , Andy Lutomirski , Will Drewry , Andrew Morton , Rik van Riel , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Eric Biggers , Frederic Weisbecker , sherryy@android.com, Vegard Nossum , Christoph Lameter , Andrea Arcangeli , Sasha Levin , Linux Kernel Mailing List , paulmck@linux.vnet.ibm.com, stern@rowland.harvard.edu Subject: Re: write_lock_irq(&tasklist_lock) Message-ID: <20180524211405.GA7206@andrea> References: <0879f797135033e05e8e9166a3c85628@codeaurora.org> <20180523130547.GF26965@arm.com> <20180523153607.GD2983@arm.com> <20180524124928.GH8689@arm.com> <20180524135158.GA19987@tardis> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180524135158.GA19987@tardis> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > Yeah, lemme put some details here: > > So we have three cases: > > Case #1 (from Will) > > P0: P1: P2: > > spin_lock(&slock) read_lock(&rwlock) > write_lock(&rwlock) > read_lock(&rwlock) spin_lock(&slock) > > , which is a deadlock, and couldn't not be detected by lockdep yet. And > lockdep could detect this with the patch I attach at the end of the > mail. > > Case #2 > > P0: P1: P2: > > > spin_lock(&slock) read_lock(&rwlock) > write_lock(&rwlock) > read_lock(&rwlock) spin_lock_irq(&slock) > > , which is not a deadlock, as the read_lock() on P0 can use the unfair > fastpass. > > Case #3 > > P0: P1: P2: > > > spin_lock_irq(&slock) read_lock(&rwlock) > write_lock_irq(&rwlock) > read_lock(&rwlock) spin_lock(&slock) > > , which is a deadlock, as the read_lock() on P0 cannot use the fastpass. Mmh, I'm starting to think that, maybe, we need a model (a tool) to distinguish these and other(?) cases (sorry, I could not resist ;-) [...] > ------------------->8 > Subject: [PATCH] locking: More accurate annotations for read_lock() > > On the archs using QUEUED_RWLOCKS, read_lock() is not always a recursive > read lock, actually it's only recursive if in_interrupt() is true. So Mmh, taking the "common denominator" over archs/Kconfig options and CPU states, this would suggest that read_lock() is non-recursive; it looks like I can say "good-bye" to my idea to define (formalize) consistent executions/the memory ordering of RW-LOCKS "by following" the following _emulation_: void read_lock(rwlock_t *s) { r0 = atomic_fetch_inc_acquire(&s->val); } void read_unlock(rwlock_t *s) { r0 = atomic_fetch_sub_release(&s->val); } void write_lock(rwlock_t *s) { r0 = atomic_cmpxchg_acquire(&s->val, 0, -1); } void write_unlock(rwlock_t *s) { atomic_set_release(&s->val, 0); } filter (~read_lock:r0=-1 /\ write_lock:r0=0) [...] > The code is done, I'm just working on the rework for documention stuff, > so if anyone is interested, could try it out ;-) Any idea on how to "educate" the LKMM about this code/documentation? Andrea