Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2950719imm; Thu, 24 May 2018 19:44:39 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoiJq2NdiSK/1bEZSHGUkkzRzahaJIDxJLpRS03W3xkE+0KftqTL+u4/gzzfuwHFo8hHcAj X-Received: by 2002:a17:902:a60d:: with SMTP id u13-v6mr653376plq.40.1527216279307; Thu, 24 May 2018 19:44:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527216279; cv=none; d=google.com; s=arc-20160816; b=UBzxTQn1XtL6xrJQbPs8V05WYfjQAllx7fCUE0FKRNcIqnSXn5PM0Qj9dYCvcJsQSY xVioe4Lvoqiuj9Jq9h3+xxbMgOzSl6WxEAy9bt73m/eg3bORJiiCRFBYUZT5IQEMsFqp BJMnoQTLm+tFVn8wbwyLLvootz189Yw7wotAXXemDpQNmgSLDeDffxQYQzZJbknM6XrJ wkWjxv09A0CoIo2/O8jMwor/DR29/bAjYJLZKJ082rk98j+ZumywCLclTQ671+Q5Z4MP DPxj+keT+PmGsWx00LZJAwBHL3tsoi4BYKWWD3/Y/ndikmqg6ScVhZ7YhnRJHk7Sy7N5 x7Cg== 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:arc-authentication-results; bh=1WvDMVGr1uZ4AutVuu6pKsVUJ2AuG3cUh9UKLKDXUKM=; b=ciOVpuYA2SYhQivIHiUSBtc/XAr0p3NS2iRsM5dFUssrLx4XL/9Tt/TDE7MZn1yv7q jscdGT4oAXFVDDoOBNvBTER8tcjFMRgYPxUsTmfkAfDnMENciUJL8rUbNOyEaF5hHlXZ D3cbCOp8pMXqp+08+xjRmzv6Pgyqmxi3dDxSMaKSWpPDyCRSNwgiZ4sdBrUxqnNipBRw ts4q7zXpMp6hmisyStP9vSS4iOYkkrdXvQjbSubNQKT+cTzSkf8KwhrdGoSTqAs0OfCO t5sVNrr3KO4B/bI1RF555qzja+BjPFYI3VoGriDojKnCNEZpUJrvpcIdSCP+xUs9a5Z3 VWRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=UizDgxGd; 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 b10-v6si22858499pls.81.2018.05.24.19.44.24; Thu, 24 May 2018 19:44:39 -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=pass header.i=@amarulasolutions.com header.s=google header.b=UizDgxGd; 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 S971574AbeEXVOR (ORCPT + 99 others); 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 Received: by mail-wm0-f47.google.com with SMTP id j4-v6so8902221wme.1 for ; Thu, 24 May 2018 14:14:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=1WvDMVGr1uZ4AutVuu6pKsVUJ2AuG3cUh9UKLKDXUKM=; b=UizDgxGdfH58TmW76/rv0k338RgjlzQWfvP036X3DQj1GblMJh3LhvdAr+IUN+LybQ 2nZC6JqPPg3LwWBxiViZ04x9pjTk/vJ9N/03O+iieepIQAYkequthf079Ba2E/Pjr6ZU IXsgER9VirUGEuU90c19ySlCHuOzIGClcVqco= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=1WvDMVGr1uZ4AutVuu6pKsVUJ2AuG3cUh9UKLKDXUKM=; b=srolAreN4vRl8mt2UpPa9gFeZlwK5rf7J+bijIFDobTYcLC6PR/tHUPqsZLoZ0b6GD aAE9fINEtp1uIUVQedd+6nEtzxlc+Sk71GmycGphZkIPt1ZTrSOq/bu7gMiqJ8EOz/M7 /GyKfy1a9/KYCoNpzyqZ8iewjKB39Vn8pOtbG8gM42PGnjaQC0os8rmJJQ8o16pp54ew btKy6aJ1aUb77fG/1Scicr2l3Q9jKzw6S+PcjoX7TaDWJSTTMw7xtL8PztQ6i/Q30svz y00bzROPaDMC7JAHyI056gxWH8sBgNGiiKXtoAMXnPmbCH2QBFBGwGq/TbuLdmy7yNwd 3AKg== X-Gm-Message-State: ALKqPweFD3Q6VygOFo5kUXbrcgORjnv5Mrb8ycLXBl/fIisYVURhFMot rq6SqsSmOXbC+QjQsng1UZNX0g== X-Received: by 2002:a1c:7609:: with SMTP id r9-v6mr10050927wmc.111.1527196452858; Thu, 24 May 2018 14:14:12 -0700 (PDT) Received: from andrea ([94.230.152.15]) by smtp.gmail.com with ESMTPSA id f10-v6sm4410793wmc.0.2018.05.24.14.14.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 May 2018 14:14:12 -0700 (PDT) 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 Precedence: bulk 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