Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp746074pxf; Thu, 18 Mar 2021 10:32:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzUvXIZ+wZcxIRU3nR9N7xGvO/XkcoY+7Ka6o9miwNrcv8oR4D0pVPvqxjtNlDxe3tT37hv X-Received: by 2002:a05:6402:1649:: with SMTP id s9mr5033522edx.177.1616088746461; Thu, 18 Mar 2021 10:32:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616088746; cv=none; d=google.com; s=arc-20160816; b=tf0pPNNbQsbSzo3JQplzsIjt+BZZnmg9F/MJlPmvIw9z6zRXfOQil2GJd//N/eXPt0 S9FvonorGF0FYuYRblccwYT5w+my3TbeUXo3oi8nfoNvPuqnqoJEgfdJUsJil+3j7MRd 3aPKlOoJF041xleL9ZlHFDBNQc3Od1mp38xJU0+LhPPEuy9BUxVVCPhFq/Vnzhl1hSR1 OkC00DaQ/l+cqsy9vuZ7pzvMDowZFj5JEc9uqZAqGPPu4mW1XZpdX1ZWylVnP3xvbtHG rXKJfTRqQhjtkY1dZ6Ms/w11XLz0rYnqRiwXY17PixmjvHAJK29uQct5kasdAk8hntBn Ob8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=ZusXoMZDaE3Bt2kUKTCnzrcY35m3DzalMZ8qsnjHCWA=; b=AxW8ugTvAqOeRhgcjLMB5k2lcizKXTqQKaSMsDsnB0epkUJ7sekYyG11Xws3M2pkRa gguwoii2uBuNtpmPJ3QNIqbffbKD8LL7j6jXd2wF7VZ5fKWzAH0If4Y7syp+apkeJwc+ 1J4DKQsUm6EMhi5UX9snpVz7MKpzueWNzxSCFpOsdGpsNBI1kEdn6fIFekX195Wq+gwn stTBOdNbnhRWULAKqVexZa8vxOGs26XFSsUH2YLMr8PiQzyCGsKBzYUcXMJiLC3URQxV N1cWOxzw1t37hHRpJMKNW+ByU2Xe/61TpJ1uBWOJEGzpmxFTpt43zDrJjleFlBKmRSCw 09Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KE8RlwVE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a7si2032629edy.54.2021.03.18.10.32.02; Thu, 18 Mar 2021 10:32:26 -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=@redhat.com header.s=mimecast20190719 header.b=KE8RlwVE; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232294AbhCRR2p (ORCPT + 99 others); Thu, 18 Mar 2021 13:28:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:58392 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232282AbhCRR2n (ORCPT ); Thu, 18 Mar 2021 13:28:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616088522; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:in-reply-to:in-reply-to:references:references; bh=ZusXoMZDaE3Bt2kUKTCnzrcY35m3DzalMZ8qsnjHCWA=; b=KE8RlwVEpotFlMss8XftGbNagPgDgSxbGRvGdSLi1hJYaKR20H1vjIEPhxoX560Z9FebnJ xxKWlTVfvjt6Xtw2ES4MbVGQHFNnP6E7DEvbifQ5xAyGLzLaGlduwOQAD5SLPKpOinTjXf ra43PYBQtEsR5vVTl44oB3WlfdGg7/w= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-560-Czyxrn28O7OUwcB1ID7M3A-1; Thu, 18 Mar 2021 13:28:39 -0400 X-MC-Unique: Czyxrn28O7OUwcB1ID7M3A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AF2A910168C7; Thu, 18 Mar 2021 17:28:37 +0000 (UTC) Received: from llong.com (ovpn-119-86.rdu2.redhat.com [10.10.119.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id 98DC25D6A8; Thu, 18 Mar 2021 17:28:36 +0000 (UTC) From: Waiman Long To: Peter Zijlstra , Ingo Molnar , Will Deacon , Boqun Feng , "Paul E. McKenney" , Davidlohr Bueso Cc: linux-kernel@vger.kernel.org, Juri Lelli , Waiman Long Subject: [PATCH-tip 2/5] locking/locktorture: Fix false positive circular locking splat in ww_mutex test Date: Thu, 18 Mar 2021 13:28:11 -0400 Message-Id: <20210318172814.4400-3-longman@redhat.com> In-Reply-To: <20210318172814.4400-1-longman@redhat.com> References: <20210318172814.4400-1-longman@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to avoid false positive circular locking lockdep splat when runnng the ww_mutex torture test, we need to make sure that the ww_mutexes have the same lock class as the acquire_ctx. This means the ww_mutexes must have the same lockdep key as the acquire_ctx. Unfortunately the current DEFINE_WW_MUTEX() macro fails to do that. As a result, we add an init method for the ww_mutex test to do explicit ww_mutex_init()'s of the ww_mutexes to avoid the false positive warning. Suggested-by: Peter Zijlstra Signed-off-by: Waiman Long --- kernel/locking/locktorture.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/kernel/locking/locktorture.c b/kernel/locking/locktorture.c index 0ab94e1f1276..3c27f43ab3e8 100644 --- a/kernel/locking/locktorture.c +++ b/kernel/locking/locktorture.c @@ -357,10 +357,20 @@ static struct lock_torture_ops mutex_lock_ops = { }; #include +/* + * The torture ww_mutexes should belong to the same lock class as + * torture_ww_class to avoid lockdep problem. The ww_mutex_init() + * function is called for initialization to ensure that. + */ 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 struct ww_mutex torture_ww_mutex_0, torture_ww_mutex_1, torture_ww_mutex_2; + +static void torture_ww_mutex_init(void) +{ + ww_mutex_init(&torture_ww_mutex_0, &torture_ww_class); + ww_mutex_init(&torture_ww_mutex_1, &torture_ww_class); + ww_mutex_init(&torture_ww_mutex_2, &torture_ww_class); +} static int torture_ww_mutex_lock(void) __acquires(torture_ww_mutex_0) @@ -418,6 +428,7 @@ __releases(torture_ww_mutex_2) } static struct lock_torture_ops ww_mutex_lock_ops = { + .init = torture_ww_mutex_init, .writelock = torture_ww_mutex_lock, .write_delay = torture_mutex_delay, .task_boost = torture_boost_dummy, -- 2.18.1