Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3842204yba; Tue, 9 Apr 2019 06:04:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqzM1AvdCNQw89a/KPuQ3BRLRyPgEbO8RPF4MEK0J950thsHyLNcB/muMIytgoy3IVd9FflR X-Received: by 2002:a17:902:20c9:: with SMTP id v9mr18329570plg.239.1554815088197; Tue, 09 Apr 2019 06:04:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554815088; cv=none; d=google.com; s=arc-20160816; b=YSpX6kcd5QajFUQxOe5uabz0lNcUjJ6LV+KPIgB6WcTFrUnuPJWAXEOPc6OlLVIdNM bYQdoyVBRpDc460nWhxex6xIZKgtGPJ2E3zB/HbGPoj6xsZt6BwpC6CiO4QuSVoATLYD zFEhE0DSQ2kFpVj1gN9hEgD6SjqxVuKbUqVFhv7J5pV3KfdaG58SVSD9ndXqa7LWdGpg wcs5/H5rZ85bbLArcNgIH1EcAKZTHsKpBOrbqXsEzWDpFau4KzIOUrCZG9PakLM/yJXg NgLcAkjIsKPlKr2x0TKQDlrlYOh2K9r2SpkI9gmtkeB+3lmO9ZBNNU1pxaT2VQZ4ENcl LsjA== 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=Yz7y3uRjexTMwBlrpw3DdpRr3Ih3yhNfcZOnq/NFiQQ=; b=tGWs8RO704sj1CYvNpyOSBVyAyWWFHl++IfNTewRtV5y6xeHY5PmjdxDZTF5b1Kzwd AAzed1aq58eWwIp2LMuN0YduWvrppTXog8pdMsEAcWAOSkjzMsqFcxGWYAJ5FSXNlsjp 5HMuFfe1Hi8kEhqtbW+nTRwrM8HrjtvEaM+qliNHDYa6GghXGpogLs7pIukIWKI/eRhN tyrjI6cFHgh9lLoy+qzbd1ebXrvtdJ7qH0w2jCUCZKctA2SzPwTjG+mmDY2wT8JxqWPI IS6DdKtPltKMYnJygxQyOvvWe/OqPNEDlj5f+Bc4xSpkFAjckWQ8H/PbMWWcwZCwR5lk FRdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b="KZZJA3p/"; 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 k24si30036621pgf.294.2019.04.09.06.04.31; Tue, 09 Apr 2019 06:04:48 -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=bombadil.20170209 header.b="KZZJA3p/"; 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 S1727310AbfDINDz (ORCPT + 99 others); Tue, 9 Apr 2019 09:03:55 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:34834 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727030AbfDINDz (ORCPT ); Tue, 9 Apr 2019 09:03:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.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=Yz7y3uRjexTMwBlrpw3DdpRr3Ih3yhNfcZOnq/NFiQQ=; b=KZZJA3p/k62DBVI7YRc9TM7lF 5vtfkypO3/sgM3/NiMuTqYCKdrGxiEI47ONCr43u9u3x75wxVgKTRyqjSy0aNFXqkWBvjrXSxSy56 +3pWmQc+NAEvK3nLBftmLIR2q2MVgjzjEcIpSTe8c95/jaM2jUD8N2SRrQAVNCHmdAMgZ3HETVq9M SJPu7QK2p0/Aah0bVjPI50xgVLMjUGx++UcOqBOGJNIaCUdVnOMR3xVojnDTjgh7QnkmVBRMze9dG E+lWFBHpjP9NoDRU2JQTzAvchdtrlXnDzX8s1DOw1XTUZMSnf/oAxqHhLzwDp5VuuMVwVB5UZfcJt IX+Pz/k8w==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1hDqPq-0002rP-NV; Tue, 09 Apr 2019 13:03:54 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 623ED29B12221; Tue, 9 Apr 2019 15:03:52 +0200 (CEST) Date: Tue, 9 Apr 2019 15:03:52 +0200 From: Peter Zijlstra To: Frederic Weisbecker Cc: LKML , Ingo Molnar Subject: Re: [PATCH 4/4] locking/lockdep: Test all incompatible scenario at once in check_irq_usage() Message-ID: <20190409130352.GV4038@hirez.programming.kicks-ass.net> References: <20190402160244.32434-1-frederic@kernel.org> <20190402160244.32434-5-frederic@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190402160244.32434-5-frederic@kernel.org> 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 Tue, Apr 02, 2019 at 06:02:44PM +0200, Frederic Weisbecker wrote: > @@ -1988,45 +1961,151 @@ static int exclusive_bit(int new_bit) > return state | (dir ^ LOCK_USAGE_DIR_MASK); > } > > +static unsigned long exclusive_dir_mask(unsigned long mask) Would you mind terribly if I call that: invert_dir_mask() ? > +{ > + unsigned long excl; > + > + /* Invert dir */ > + excl = (mask & LOCKF_ENABLED_IRQ_ALL) >> LOCK_USAGE_DIR_MASK; > + excl |= (mask & LOCKF_USED_IN_IRQ_ALL) << LOCK_USAGE_DIR_MASK; > + > + return excl; > +} > + > +static unsigned long exclusive_mask(unsigned long mask) > +{ > + unsigned long excl = exclusive_dir_mask(mask); > + > + /* Strip read */ > + excl |= (excl & LOCKF_IRQ_READ) >> LOCK_USAGE_READ_MASK; > + excl &= ~LOCKF_IRQ_READ; > + > + return excl; > +} And I might write a comment to go with those functions; they're too clever by half. I'm sure I'll have forgotten how they work in a few months time. Very well done :-) > +/* > + * Find the first pair of bit match between an original > + * usage mask and an exclusive usage mask. > + */ > +static int find_exclusive_match(unsigned long mask, > + unsigned long excl_mask, > + enum lock_usage_bit *bit, > + enum lock_usage_bit *excl_bit) > +{ > + int fs, nr = 0; > + > + while ((fs = ffs(mask))) { > + int excl; > + > + nr += fs; > + excl = exclusive_bit(nr - 1); > + if (excl_mask & lock_flag(excl)) { > + *bit = nr - 1; > + *excl_bit = excl; > + return 0; > + } > + mask >>= fs - 1; > + /* > + * Prevent from shifts of sizeof(long) which can > + * give unpredictable results. > + */ > + mask >>= 1; > + } > + return -1; Should we write that like: for_each_set_bit(bit, &mask, LOCK_USED) { int excl = exclusive_bit(bit); if (excl_mask & lock_flag(excl)) { *bitp = bit; *excl_bitp = excl; return 0; } } return -1; Or something along those lines? > +} > +