Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4011381ybi; Mon, 27 May 2019 09:24:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2ynVLtWvdDepDZV2GHd3OfKKkSfCo0GzsYUW/TR2tgDQ6LCzI8LVXjKC3ZRdXdun83oSg X-Received: by 2002:a17:90a:36c5:: with SMTP id t63mr32631029pjb.2.1558974247061; Mon, 27 May 2019 09:24:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558974247; cv=none; d=google.com; s=arc-20160816; b=Z9HzHNXugnilNpBXbrPTyW/fsKmOeCtXIKF7ZrpsRH5vhsrWMqii+RTfbyBQj4whBx IKUPhYLxVjlMvIcqp0hCvL+m+4hW8svDHwSLm0JKuXGs7sJyxVK9eCwTsc8V92YEbk9K Wg9/VxQ6aWwfwxsZfRKoGkP/EHAUWLqEYhTg4lmD+q8zzWdA/m1TRrLuquh5db6CWU9F Oi6Bk8e6c7fMOLmBJ0Dhs9ihmDk3v+kkU/pAT1fAqb78trZx8dXiGweSADDRTBPtRWS2 91fxHXmuOdI/RU2uA9Xv77+8kYOuBj019z/bssXqCV4zMabrHFPpioieLNX+6AX5/46t nHXw== 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:reply-to:message-id :subject:cc:to:from:date; bh=CrUu7vi8DNQlFvBUXf+Kp18BQ4MGswBXngu69wmoQvg=; b=zFL4LZdTdKTaMyCEZgor8NiSLsM9hI9w3GEOAKi5kzNeBCpk3Ef+eM8w+1oM9NYo8l rcxn7IQIaZXz/oP9Qq3KXfc2SFYmuhH7hjJLeiRjsW8hI5wWp5W5b4JA55iko6ujjoPS jjK2/H+z0RRcGzDfqmJTZ1T+uOBxmwNMlht+BZqoNFVSxNPaLUPWMWVaQCQwCV7obC1m y2xGTUX9m7c/xT9aCTg+M85eWnUNjQNtLdoEutyBBC2Lt5ryPBvWC+LOrZrd86U5q9DA WHyjaXibCme/pv/GkkDN6wJCYtC0oOZay6+P4B//NDt2iQNSU1ZW/+5RCdGP7RAp3Cty Dt7w== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n14si22267756pfq.105.2019.05.27.09.23.52; Mon, 27 May 2019 09:24:07 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726663AbfE0QW1 (ORCPT + 99 others); Mon, 27 May 2019 12:22:27 -0400 Received: from mga07.intel.com ([134.134.136.100]:35375 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725991AbfE0QW1 (ORCPT ); Mon, 27 May 2019 12:22:27 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 May 2019 09:22:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,519,1549958400"; d="scan'208";a="178946686" Received: from ideak-desk.fi.intel.com ([10.237.72.204]) by fmsmga002.fm.intel.com with ESMTP; 27 May 2019 09:22:25 -0700 Date: Mon, 27 May 2019 19:21:49 +0300 From: Imre Deak To: Peter Zijlstra Cc: LKML , Ville =?iso-8859-1?Q?Syrj=E4l=E4?= , Ingo Molnar , Will Deacon Subject: Re: [PATCH v2 2/2] lockdep: Fix merging of hlocks with non-zero references Message-ID: <20190527162149.GA25731@ideak-desk.fi.intel.com> Reply-To: imre.deak@intel.com References: <20190524201509.9199-1-imre.deak@intel.com> <20190524201509.9199-2-imre.deak@intel.com> <20190527151438.GF2623@hirez.programming.kicks-ass.net> <20190527160618.GT2650@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190527160618.GT2650@hirez.programming.kicks-ass.net> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, May 27, 2019 at 06:06:18PM +0200, Peter Zijlstra wrote: > On Mon, May 27, 2019 at 05:14:38PM +0200, Peter Zijlstra wrote: > > On Fri, May 24, 2019 at 11:15:09PM +0300, Imre Deak wrote: > > > diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c > > > index 967352d32af1..9e2a4ab6c731 100644 > > > --- a/kernel/locking/lockdep.c > > > +++ b/kernel/locking/lockdep.c > > > @@ -3637,6 +3637,11 @@ print_lock_nested_lock_not_held(struct task_struct *curr, > > > > > > static int __lock_is_held(const struct lockdep_map *lock, int read); > > > > > > +static int hlock_reference(int reference) > > > +{ > > > + return reference ? : 1; > > > +} > > > + > > > /* > > > * This gets called for every mutex_lock*()/spin_lock*() operation. > > > * We maintain the dependency maps and validate the locking attempt: > > > @@ -3702,17 +3707,15 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, > > > if (depth) { > > > hlock = curr->held_locks + depth - 1; > > > if (hlock->class_idx == class_idx && nest_lock) { > > > - if (hlock->references) { > > > - /* > > > - * Check: unsigned int references overflow. > > > - */ > > > - if (DEBUG_LOCKS_WARN_ON(hlock->references == UINT_MAX)) > > > > What tree is this against? Afaict this is still 12 bits ?! > > > > > - return 0; > > > + /* > > > + * Check: unsigned int references overflow. > > > + */ > > > + if (DEBUG_LOCKS_WARN_ON(hlock_reference(hlock->references) > > > > + UINT_MAX - hlock_reference(references))) > > > > Idem. Also very weird overflow check.. > > > > > + return 0; > > > > > > - hlock->references++; > > > - } else { > > > - hlock->references = 2; > > > - } > > > + hlock->references = hlock_reference(hlock->references) + > > > + hlock_reference(references); > > > > > > return 2; > > > } > > I think you wanted something like this: ? > > --- a/kernel/locking/lockdep.c > +++ b/kernel/locking/lockdep.c > @@ -3731,6 +3731,11 @@ print_lock_nested_lock_not_held(struct t > > static int __lock_is_held(const struct lockdep_map *lock, int read); > > +static inline int hlock_references(struct held_lock *hlock) > +{ > + return hlock->references ? : 1; > +} > + > /* > * This gets called for every mutex_lock*()/spin_lock*() operation. > * We maintain the dependency maps and validate the locking attempt: > @@ -3796,17 +3801,14 @@ static int __lock_acquire(struct lockdep > if (depth) { > hlock = curr->held_locks + depth - 1; > if (hlock->class_idx == class_idx && nest_lock) { > - if (hlock->references) { > - /* > - * Check: unsigned int references:12, overflow. > - */ > - if (DEBUG_LOCKS_WARN_ON(hlock->references == (1 << 12)-1)) > - return 0; > - > - hlock->references++; > - } else { > - hlock->references = 2; > - } > + if (!references) > + references++; > + > + hlock->references = hlock_references(hlock) + references; > + > + /* Overflow */ > + if (DEBUG_LOCKS_WARN_ON(hlock->references < references)) > + return 0; Yes, it works. > > return 2; > }