Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp59299pxf; Tue, 16 Mar 2021 22:20:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymGRhLDQh+7Nj2I1HGgFCCwKITvIA5O/tjOjzOF1/DsEGKJbw4DGWQGXDe7IKV0z9AW6VB X-Received: by 2002:a05:6402:270e:: with SMTP id y14mr39986253edd.283.1615958409955; Tue, 16 Mar 2021 22:20:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615958409; cv=none; d=google.com; s=arc-20160816; b=w5LPa7bP8ThjXJl/3sWdJAOwQkQIuLf1IWA/vBzF5QOvoi6vwsxUMKat6pY8xcag2N lfksgYovoFQNb+9QlRt233qcP8vAS+y5P17nO+S8lvPrzxEP2GS41W4d2MG/NrBr+Zdk XIhsIk2AYLEP9LraJOENjLoLK9D7UfBG1FLq9yXJXhZ7MqpXq3X6I8HutgqkEmE2Jqp4 1sGGgDzwnjzBDud2k8I1itkcuf5NePpWX0h4henKw9TCF/KmIcpNiPTTqcKtZ/tHGTNt g5Wy0t9bQLJZpQcDdXJy3pw3HWGrDrbrUqHV4tHPuLw2kTYCAa3BKDsGZlJEFxjSN136 UmVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=wX+cCTIisltbqjdWkAs9oi3B835cx8ccLc0G758csSY=; b=0cNV64NM88fYzNiVfoYzOM+EIFPWAVysn3a2A+lwYJQCpHbY3XZO/IuH1tDYc3YXyF zZuFODy+rrf+dP0ubuh3K4NWuMj8ylfdKXpoSkFtDVDLDHwSpsYqB3penAPa/rypntaS MMB8j3gBY850PfCCOj38XaCe1bHvMUM5SHt1B2zK7w8zY5c2BASCmxCqbZ65u0N62gau p4vufaKBwJIQBc/sDQ40ryCHImPPvjptkybYrvDlvihsaj9H+oU29+HzpK20D0py6FjK xqbsS962n0VZveTRe5dXgHv5EFx8z8guvvK60X9ij0BZyD67zGUUPQTD5EWgcK0DjZ6/ +Z4Q== ARC-Authentication-Results: i=1; mx.google.com; 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 lv19si6868012ejb.553.2021.03.16.22.19.47; Tue, 16 Mar 2021 22:20:09 -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; 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 S229472AbhCQFQq (ORCPT + 99 others); Wed, 17 Mar 2021 01:16:46 -0400 Received: from mx2.suse.de ([195.135.220.15]:43638 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229831AbhCQFQU (ORCPT ); Wed, 17 Mar 2021 01:16:20 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id ED00EAC17; Wed, 17 Mar 2021 05:16:13 +0000 (UTC) Date: Tue, 16 Mar 2021 22:16:05 -0700 From: Davidlohr Bueso To: Waiman Long Cc: Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , "Paul E. McKenney" , linux-kernel@vger.kernel.org, Juri Lelli Subject: Re: [PATCH 4/4] locking/locktorture: Fix incorrect use of ww_acquire_ctx in ww_mutex test Message-ID: <20210317051605.popetodgwbr47ha2@offworld> References: <20210316153119.13802-1-longman@redhat.com> <20210316153119.13802-5-longman@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20210316153119.13802-5-longman@redhat.com> User-Agent: NeoMutt/20201120 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 16 Mar 2021, Waiman Long wrote: >The ww_acquire_ctx structure for ww_mutex needs to persist for a complete >lock/unlock cycle. In the ww_mutex test in locktorture, however, both >ww_acquire_init() and ww_acquire_fini() are called within the lock >function only. This causes a lockdep splat of "WARNING: Nested lock >was not taken" when lockdep is enabled in the kernel. > >To fix this problem, we need to move the ww_acquire_fini() after the >ww_mutex_unlock() in torture_ww_mutex_unlock(). In other word, we need >to pass state information from the lock function to the unlock function. Right, and afaict this _is_ the way ww_acquire_fini() should be called: * Releases a w/w acquire context. This must be called _after_ all acquired w/w * mutexes have been released with ww_mutex_unlock. >Change the writelock and writeunlock function prototypes to allow that >and change the torture_ww_mutex_lock() and torture_ww_mutex_unlock() >accordingly. But wouldn't just making ctx a global variable be enough instead? That way we don't deal with memory allocation for every lock/unlock operation (yuck). Plus the ENOMEM would need to be handled/propagated accordingly - the code really doesn't expect any failure from ->writelock(). diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index 0ab94e1f1276..606c0f6c1657 100644 --- a/kernel/locking/locktorture.c +++ b/kernel/locking/locktorture.c @@ -362,6 +362,8 @@ 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 struct ww_acquire_ctx ctx; + static int torture_ww_mutex_lock(void) __acquires(torture_ww_mutex_0) __acquires(torture_ww_mutex_1) @@ -372,7 +374,6 @@ __acquires(torture_ww_mutex_2) struct list_head link; struct ww_mutex *lock; } locks[3], *ll, *ln; - struct ww_acquire_ctx ctx; locks[0].lock = &torture_ww_mutex_0; list_add(&locks[0].link, &list); @@ -403,7 +404,6 @@ __acquires(torture_ww_mutex_2) list_move(&ll->link, &list); } - ww_acquire_fini(&ctx); return 0; } @@ -415,6 +415,8 @@ __releases(torture_ww_mutex_2) ww_mutex_unlock(&torture_ww_mutex_0); ww_mutex_unlock(&torture_ww_mutex_1); ww_mutex_unlock(&torture_ww_mutex_2); + + ww_acquire_fini(&ctx); } static struct lock_torture_ops ww_mutex_lock_ops = {