Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp575372pxf; Wed, 17 Mar 2021 10:48:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxf+UYethVZTTkZ3O+Yk/+qkWKXegcuuySy8yzMhi/upj/rbyGUXY9ToK7wjqwHQl/1DbC7 X-Received: by 2002:a17:906:90d8:: with SMTP id v24mr36125712ejw.547.1616003310555; Wed, 17 Mar 2021 10:48:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616003310; cv=none; d=google.com; s=arc-20160816; b=Hsq9H/TfSK8mYDdsPhcHGA4Ju3YF1MX+BLps0AI679IxZHhBo3mFDMEWR8BqA5xbHG lTanf0F/ezF3enNGtI0o/dkwNLAEIGDl2u2J7QK+/cyCv0tLXbPFr6nGfb+gVQx8lJpi K5Pe2cy6DVK0l6d4ZocItHmxMUax7cgl2IIB2slZBNn3XR8dgdqOgSe+aMa05Gymmpwy AMdmkZWUFPozoRYuOwzcjJyIrtbI1p7jDXg0qa1ew5LM8WdXll4kI8TVnZW+7+8AQLGj 60lPLChjehIIHUCjrAOSIrZSRCs+OU/Al6TDNKW5n8duN/ahOOuycXaQTfqnRf8DoD85 6Zxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=A2FtYHm1/WgaQlEuzToT6dfW4PtI9zS/+POuKxKvN7w=; b=IN7zaqXkwLvQCJmxvBXgwROB6LNqVgb6UOuN293B1JH1k3pp+78v1ZgM0sxM2qFl3n Hzj0TUDHP+1ypV50otSohdAaJbnbHWN4DivDIJGn2VgFlNDCwu9ETNLhTOqOthpLsQ/y 8DfkIlQkEOl6G3Lt/6PMokwDvL/W7exItBt+PY8DE6YtNgOyQ19wukMSacU+15S5kVst ZAYWXPk12pMNGezAseg01HK65EvmXkkCgIxgkEWhEhbCi24jtO8TPAfOhGdJQ7QqLwi4 x81w5z90Owsy88fFtitUt62Q/yEGDVOhp7JhJdNdZQJFiv9beJ71pMbKoBjtXUVORaWr HmDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b="bTeil9/C"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p15si15538170ejr.236.2021.03.17.10.48.07; Wed, 17 Mar 2021 10:48:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b="bTeil9/C"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232785AbhCQRqJ (ORCPT + 99 others); Wed, 17 Mar 2021 13:46:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232730AbhCQRpl (ORCPT ); Wed, 17 Mar 2021 13:45:41 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0774AC06174A; Wed, 17 Mar 2021 10:45:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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; bh=A2FtYHm1/WgaQlEuzToT6dfW4PtI9zS/+POuKxKvN7w=; b=bTeil9/Cl6vMIs4vkOmuiKUIzi iXyRwv2x3/mGFMgYjfMwBnFaHy+fpx6fESiRDmvTeN/g7Pf+HgVbeB1TUmjviwdYHwDbuqFs4VWMn UkbczNfJsvPr8BaUnoWKt19y1qQULzdWmQd5AZlcsTtjTwSIZEE+qRr4s54dJ0y06GAu0qPlOpO30 AWG/SCs+DNXErLJlX1FksIhC8RihyxQnPDmGLC7SV5qr0r2QPoxFLJlCvNERm+qLH97nIq77bT7Vi wTQcyUYOJqfGNyCUkmK5hhvyT/iezoQqIdxrtSmUV0P+8TiuKcEkbyMF6zX/uZD9odoD4gpnAYl+P VZCvo7hA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1lMaEi-003gwd-4H; Wed, 17 Mar 2021 17:45:36 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id B9B79305C22; Wed, 17 Mar 2021 18:45:35 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id AC581203D90CA; Wed, 17 Mar 2021 18:45:35 +0100 (CET) Date: Wed, 17 Mar 2021 18:45:35 +0100 From: Peter Zijlstra To: Waiman Long Cc: linux-kernel@vger.kernel.org, linux-tip-commits@vger.kernel.org, Ingo Molnar , x86@kernel.org Subject: Re: [tip: locking/urgent] locking/ww_mutex: Treat ww_mutex_lock() like a trylock Message-ID: References: <20210316153119.13802-4-longman@redhat.com> <161598470197.398.8903908266426306140.tip-bot2@tip-bot2> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 17, 2021 at 06:40:27PM +0100, Peter Zijlstra wrote: > On Wed, Mar 17, 2021 at 05:48:48PM +0100, Peter Zijlstra wrote: > > > I think you'll find that if you use ww_mutex_init() it'll all work. Let > > me go and zap this patch, and then I'll try and figure out why > > DEFINE_WW_MUTEX() is buggered. > > Moo, I can't get the compiler to do as I want :/ > > The below is so close but doesn't actually compile.. Maybe we should > just give up on DEFINE_WW_MUTEX and simply remove it. > > --- > diff --git a/include/linux/mutex.h b/include/linux/mutex.h > index 0cd631a19727..85f50538f26a 100644 > --- a/include/linux/mutex.h > +++ b/include/linux/mutex.h > @@ -129,12 +129,15 @@ do { \ > # define __DEP_MAP_MUTEX_INITIALIZER(lockname) > #endif > > -#define __MUTEX_INITIALIZER(lockname) \ > +#define ___MUTEX_INITIALIZER(lockname, depmap) \ > { .owner = ATOMIC_LONG_INIT(0) \ > , .wait_lock = __SPIN_LOCK_UNLOCKED(lockname.wait_lock) \ > , .wait_list = LIST_HEAD_INIT(lockname.wait_list) \ > __DEBUG_MUTEX_INITIALIZER(lockname) \ > - __DEP_MAP_MUTEX_INITIALIZER(lockname) } > + depmap } > + > +#define __MUTEX_INITIALIZER(lockname) \ > + ___MUTEX_INITIALIZER(lockname, __DEP_MAP_MUTEX_INITIALIZER(lockname)) > > #define DEFINE_MUTEX(mutexname) \ > struct mutex mutexname = __MUTEX_INITIALIZER(mutexname) > diff --git a/include/linux/ww_mutex.h b/include/linux/ww_mutex.h > index 6ecf2a0220db..c62a030652b4 100644 > --- a/include/linux/ww_mutex.h > +++ b/include/linux/ww_mutex.h > @@ -50,9 +50,17 @@ struct ww_acquire_ctx { > > #ifdef CONFIG_DEBUG_LOCK_ALLOC > # define __WW_CLASS_MUTEX_INITIALIZER(lockname, class) \ > - , .ww_class = class > + , .ww_class = &(class) > + > +# define __DEP_MAP_WW_MUTEX_INITIALIZER(lockname, class) \ > + , .dep_map = { \ > + .key = &(class).mutex_key, \ > + .name = (class).mutex_name, \ ,name = #class "_mutex", \ and it 'works', but shees! > + .wait_type_inner = LD_WAIT_SLEEP, \ > + } > #else > # define __WW_CLASS_MUTEX_INITIALIZER(lockname, class) > +# define __DEP_MAP_WW_MUTEX_INITIALIZER(lockname, class) > #endif > > #define __WW_CLASS_INITIALIZER(ww_class, _is_wait_die) \ > @@ -62,7 +70,8 @@ struct ww_acquire_ctx { > , .is_wait_die = _is_wait_die } > > #define __WW_MUTEX_INITIALIZER(lockname, class) \ > - { .base = __MUTEX_INITIALIZER(lockname.base) \ > + { .base = ___MUTEX_INITIALIZER(lockname.base, \ > + __DEP_MAP_WW_MUTEX_INITIALIZER(lockname.base, class)) \ > __WW_CLASS_MUTEX_INITIALIZER(lockname, class) } > > #define DEFINE_WD_CLASS(classname) \ > diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c > index 0ab94e1f1276..e8305233eb0b 100644 > --- a/kernel/locking/locktorture.c > +++ b/kernel/locking/locktorture.c > @@ -358,9 +358,9 @@ static struct lock_torture_ops mutex_lock_ops = { > > #include > static DEFINE_WD_CLASS(torture_ww_class); > -static DEFINE_WW_MUTEX(torture_ww_mutex_0, &torture_ww_class); > -static DEFINE_WW_MUTEX(torture_ww_mutex_1, &torture_ww_class); > -static DEFINE_WW_MUTEX(torture_ww_mutex_2, &torture_ww_class); > +static DEFINE_WW_MUTEX(torture_ww_mutex_0, torture_ww_class); > +static DEFINE_WW_MUTEX(torture_ww_mutex_1, torture_ww_class); > +static DEFINE_WW_MUTEX(torture_ww_mutex_2, torture_ww_class); > > static int torture_ww_mutex_lock(void) > __acquires(torture_ww_mutex_0)