Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp5066955yba; Tue, 30 Apr 2019 08:37:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqxYG5/0oDz4Y2+Xg4eOnG3ipEboh4MF4jBcY/vYdnyvpcNd5Ki9vudVZ6u+evzG6VMduibP X-Received: by 2002:a17:902:7205:: with SMTP id ba5mr49388205plb.285.1556638638053; Tue, 30 Apr 2019 08:37:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556638638; cv=none; d=google.com; s=arc-20160816; b=O1EcG9HM09uaVp9rJa5bXL6nDmKjbxrZNwRYYtcJI9W37yLho9DdYhOfNNGjhYSXFe /tQfCAVZQ/eG4GltfP4b0R4k5Pro+2UKgswreEJ/3IuvMJp/gg7e/WDYCXEFT4C12MKV 9x99Zb+eKJicIt77UlZZwpgzT7oStV/OSaBnBj72j0pabYZf3UXVbOOkKoenkSAu/wlD 1ojNdxTUvo3OD9OtD0gh/XkzPuxBQjvW+sVYgEx25ATe+DoFdKrRRbtyX25zhW4r3nsY oQPArVH81itcx7CzCKcq97OI9pweLUPH+9wji9F12UdWkoz2P5P8PlNxS+lOfepD2J2r tGJA== 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; bh=xkHmQ5VtLPFk5RCj2nSWg30TnIw2SSbj0nkad1c7W7E=; b=MB75dJBfhK2d8VrIsnRJ04eGqHekXjSDO52Mn1ekd3k09DDjk3GnlgCE+A42MUb7bF N5VV4WWO45OyhqbqB73FxNG7xJNuIX71totB4fMQSE31z9hziMMkqRiSTZh6RyQiN/d5 0p+JROW181lfnHAdfiJb6KaWDWjbLdylrTSW7hhky9BWV5VHeUml3fpeM3M+mOfqPAdP Y8446bo5F6ONKxj0WxNfqtksN4dR8wjvItU25tiYFrh+bYjJ7HCo9FLWO/XHOc7rw/Bu 0FM8bOAjdleUf1NMqthvwQ/cB5xHhRjgNLjXf2UkvgklL1U6yON+f4ALaMAygbeL2xrN FamQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=bOQnutm+; 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 a2si18201593plm.162.2019.04.30.08.37.01; Tue, 30 Apr 2019 08:37:18 -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=fail header.i=@infradead.org header.s=merlin.20170209 header.b=bOQnutm+; 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 S1726373AbfD3Pfi (ORCPT + 99 others); Tue, 30 Apr 2019 11:35:38 -0400 Received: from merlin.infradead.org ([205.233.59.134]:38748 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725906AbfD3Pfi (ORCPT ); Tue, 30 Apr 2019 11:35:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=xkHmQ5VtLPFk5RCj2nSWg30TnIw2SSbj0nkad1c7W7E=; b=bOQnutm+bB+XMxG3zduAv4jW7 znSbbl+5BGbPorr8/ibz5INOWoVxj3R8KryAVGOpi+MvZjoflt9dvB3sz2LtLacGEKb7VtLESUYeG xpJ5vyaOz8NWx3yGMQMdOABuahAZPhGd5TJMOVEBKO4soCdERdpqkwty7T7uxHDcLtbBMWTk3QeeJ QvQ4dUboMm24ewnqZjK93nB95uy6P8M8rllYuaqBYVq5CnZcPUNnt2FPsVgfFQnNLE+26Xk+pTTtM Zc4hm+xLMyGpzZ8gG3yzVNNXYwS2ntqc0mWbUdUvaoxJzwWyfa0MOAXUfmr8rxaipa3GCioOpDJR5 8Y+W9uNHw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hLUn3-0001zI-Lf; Tue, 30 Apr 2019 15:35:30 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 22100236F9E80; Tue, 30 Apr 2019 17:35:28 +0200 (CEST) Date: Tue, 30 Apr 2019 17:35:28 +0200 From: Peter Zijlstra To: Yuyang Du Cc: will.deacon@arm.com, mingo@kernel.org, bvanassche@acm.org, ming.lei@redhat.com, frederic@kernel.org, tglx@linutronix.de, linux-kernel@vger.kernel.org, Boqun Feng Subject: Re: [PATCH 24/28] locking/lockdep: Remove !dir in lock irq usage check Message-ID: <20190430153528.GA2650@hirez.programming.kicks-ass.net> References: <20190424101934.51535-1-duyuyang@gmail.com> <20190424101934.51535-25-duyuyang@gmail.com> <20190425200336.GY12232@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190425200336.GY12232@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 25, 2019 at 10:03:36PM +0200, Peter Zijlstra wrote: > On Wed, Apr 24, 2019 at 06:19:30PM +0800, Yuyang Du wrote: > > In mark_lock_irq(), the following checks are performed: > > > > ---------------------------------- > > | -> | unsafe | read unsafe | > > |----------------------------------| > > | safe | F B | F* B* | > > |----------------------------------| > > | read safe | F? B* | - | > > ---------------------------------- > > > > Where: > > F: check_usage_forwards > > B: check_usage_backwards > > *: check enabled by STRICT_READ_CHECKS > > ?: check enabled by the !dir condition > > > > From checking point of view, the special F? case does not make sense, > > whereas it perhaps is made for peroformance concern. As later patch will > > address this issue, remove this exception, which makes the checks > > consistent later. > > > > With STRICT_READ_CHECKS = 1 which is default, there is no functional > > change. > > Oh man.. thinking required and it is way late.. anyway this whole read > stuff made me remember we had a patch set on readlocks last year. > > https://lkml.kernel.org/r/20180411135110.9217-1-boqun.feng@gmail.com > > I remember reviewing that a few times and then it dropped on the floor, > probably because Spectre crap or something sucked up all my time again :/ So if we look at Boqun's patches (as posted, I haven't looked at his github, but I'm assuming this hasn't changed with the 'Shared' state), we'll find he'll only does either 1 backward or 1 foward search (which is already an improvement over the current state). His mark_lock_irq() looks like: static int mark_lock_irq(struct task_struct *curr, struct *held_lock *this, enum lock_usage_bit new_bit) { int excl_bit = exclusive_bit(new_bit); + if (new_bit & 2) { + /* + * mark ENABLED has to look backwards -- to ensure no dependee + * has USED_IN state, which, again, would allow recursion + * deadlocks. + */ + if (!check_usage_backwards(curr, this, new_bit, excl_bit)) return 0; + } else { + /* + * mark USED_IN has to look forwards -- to ensure no dependency + * has ENABLED state, which would allow recursion deadlocks. + */ + if (!check_usage_forwards(curr, this, new_bit, excl_bit)) return 0; } return 1; } Where '& 2' would read '& LOCK_USAGE_DIR_MASK' in the current code. Now, I'm thinking you're proposing to replace the backward search for USED_IN/safe with your reachable-safe state, which, if done on his 'strong' links, should still work. That is; I _think_ the two patch-sets are not in conceptual conflict. Of course; I could have missed something; I've just read both patchsets again, and it's a bit much :-)