Message ID | 20231002082535.1516405-1-stanislaw.gruszka@linux.intel.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1298238vqb; Mon, 2 Oct 2023 02:20:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHkhegZa8DpPyt+31C2BeCvUxzPCHbQ/eAKgR7VIyu5TddwgLT8lUSy78Qv/+OWHjqGdPez X-Received: by 2002:a05:6a20:9783:b0:159:fe1d:2f32 with SMTP id hx3-20020a056a20978300b00159fe1d2f32mr8253525pzc.42.1696238403534; Mon, 02 Oct 2023 02:20:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696238403; cv=none; d=google.com; s=arc-20160816; b=nYKNUfuH2ZFMJ2FpYzg5u6fzlKbwgjbYVhMZjNoFaM/pEysJkWofoh5/BvU418zn05 DVe91pTDJlEzaYzsY/SbULuzmTCL4qdCoTARIk+yXVYzdc6MqhDyeNRl/vj3swmoJN5L CY+yA/jUuNKYU77fwGDVasqF2c9u1h3w71RPdY//QEeNeGsiAX2Hn8MmsBMg42cLGu9W X3ooag70P0mVXd2Gm+tZdecWGSIn1OFfDgOyqnccWGRE2SdiJOvp9fHSgFAFt5Pgw4Mm TRdTfEXHhnRzxvqj9UfkXlkaiz5TBeyozfNvVhxnO1B4HRHK46DgvQ0Rrj/q2inMyIKt nQFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=7dWVXhnsg0E2Ini/bvxD4ogaMlTtqZlTWFRPwq7O0cA=; fh=6k1Qa9w0i0JNXyMeqoaLUcYR7kmAzoyFwtyOEBswuMo=; b=dQQu0GjwZXyMgOi2Vv1ahJGxkF8m4WrH3BGsrnH7l6R66EfQktMoz3PCTLv5qKmr4/ HyTIu2aIJ4Tu7ZfI/Z+p/FX3yYz08SC5DViSJVrq6qycGgGoC0jwLAAoGngojOLRsztc yI7k+dP8NzbLxYU3OaCCrBEDbtP/eOIo4sr9zVsdKKRvqLMh0OAM8WZ5K3j7mFLLeH3V g4D1ix3jdATN1X5nbCujDvpGQXZtX3wR3oNeZoUSX7uzFVA+ud+jO6BcxGMsPrntjehi t8BVoo/9sM6fmkG7MK+tJMjKyhNMsa66l33SSdSPa4JRhni/jShCtNV4wUrk4RH4SOD6 qy9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=n2cUg4hc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id ei16-20020a056a0080d000b00690c1e51cdfsi24839164pfb.188.2023.10.02.02.20.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 02:20:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=n2cUg4hc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 481CD80775B4; Mon, 2 Oct 2023 01:25:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235841AbjJBIZo (ORCPT <rfc822;pwkd43@gmail.com> + 17 others); Mon, 2 Oct 2023 04:25:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229981AbjJBIZn (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 2 Oct 2023 04:25:43 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B9308C6; Mon, 2 Oct 2023 01:25:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1696235140; x=1727771140; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=LjUA0WnZOwfBZbOsPWOE8rX33xk0uzpE44wPBaNDwPc=; b=n2cUg4hc3KB3pgqa/MSXJL/Bc6rC5qwHF7mRWyK/6w+HgEc+pwd0dIU9 /VZFQjBuGgf2OSrWjLzyY4duz4s2+dM6GMbLeoNR9skiXOvfSRRXOtQLR DLQhX4gTEz/S67Ltp60HJKeP5DTMfQDqBoYuMl+c5S04wAfULGlwzhCcT /WLK8KGOjRxkJXJtSxOFXn5aufagqVJRe+EhtVbphxZIbR5rgeXcxOryb DjiJfgQZniC7+GGuBo4hhO4NaqDbbxaVYh1GvKkl7qW93NiugQjnydWdW LIjM+FGvIICMPIgJUKZ8CMHVRDdyHgG85ASElkoIFJi+QlrsZ/O4Kz+oL g==; X-IronPort-AV: E=McAfee;i="6600,9927,10850"; a="468881032" X-IronPort-AV: E=Sophos;i="6.03,193,1694761200"; d="scan'208";a="468881032" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Oct 2023 01:25:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10850"; a="874286167" X-IronPort-AV: E=Sophos;i="6.03,193,1694761200"; d="scan'208";a="874286167" Received: from joe-255.igk.intel.com (HELO localhost) ([10.91.220.57]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Oct 2023 01:25:37 -0700 From: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com> To: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Matthew Wilcox <willy@infradead.org>, Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>, Waiman Long <longman@redhat.com>, Boqun Feng <boqun.feng@gmail.com>, Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com> Subject: [PATCH] XArray: Make xa_lock_init macro Date: Mon, 2 Oct 2023 10:25:35 +0200 Message-Id: <20231002082535.1516405-1-stanislaw.gruszka@linux.intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 02 Oct 2023 01:25:48 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778634879836981387 X-GMAIL-MSGID: 1778634879836981387 |
Series |
XArray: Make xa_lock_init macro
|
|
Commit Message
Stanislaw Gruszka
Oct. 2, 2023, 8:25 a.m. UTC
Make xa_init_flags() macro to avoid false positive lockdep splats.
When spin_lock_init() is used inside initialization function (like
in xa_init_flags()) which can be called many times, lockdep assign
the same key to different locks.
For example this splat is seen with intel_vpu driver which uses
two xarrays and has two separate xa_init_flags() calls:
[ 1139.148679] WARNING: inconsistent lock state
[ 1139.152941] 6.6.0-hardening.1+ #2 Tainted: G OE
[ 1139.158758] --------------------------------
[ 1139.163024] inconsistent {HARDIRQ-ON-W} -> {IN-HARDIRQ-W} usage.
[ 1139.169018] kworker/10:1/109 [HC1[1]:SC0[0]:HE0:SE1] takes:
[ 1139.174576] ffff888137237150 (&xa->xa_lock#18){?.+.}-{2:2}, at: ivpu_mmu_user_context_mark_invalid+0x1c/0x80 [intel_vpu]
[ 1139.185438] {HARDIRQ-ON-W} state was registered at:
[ 1139.190305] lock_acquire+0x1a3/0x4a0
[ 1139.194055] _raw_spin_lock+0x2c/0x40
[ 1139.197800] ivpu_submit_ioctl+0xf0b/0x3520 [intel_vpu]
[ 1139.203114] drm_ioctl_kernel+0x201/0x3f0 [drm]
[ 1139.207791] drm_ioctl+0x47d/0xa20 [drm]
[ 1139.211846] __x64_sys_ioctl+0x12e/0x1a0
[ 1139.215849] do_syscall_64+0x59/0x90
[ 1139.219509] entry_SYSCALL_64_after_hwframe+0x6e/0xd8
[ 1139.224636] irq event stamp: 45500
[ 1139.228037] hardirqs last enabled at (45499): [<ffffffff92ef0314>] _raw_spin_unlock_irq+0x24/0x50
[ 1139.236961] hardirqs last disabled at (45500): [<ffffffff92eadf8f>] common_interrupt+0xf/0x90
[ 1139.245457] softirqs last enabled at (44956): [<ffffffff92ef3430>] __do_softirq+0x4c0/0x712
[ 1139.253862] softirqs last disabled at (44461): [<ffffffff907df310>] irq_exit_rcu+0xa0/0xd0
[ 1139.262098]
other info that might help us debug this:
[ 1139.268604] Possible unsafe locking scenario:
[ 1139.274505] CPU0
[ 1139.276955] ----
[ 1139.279403] lock(&xa->xa_lock#18);
[ 1139.282978] <Interrupt>
[ 1139.285601] lock(&xa->xa_lock#18);
[ 1139.289345]
*** DEADLOCK ***
Lockdep falsely identified xa_lock from two different xarrays as the same
lock and report deadlock. More detailed description of the problem
is provided in commit c21f11d182c2 ("drm: fix drmm_mutex_init()")
Signed-off-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com>
---
include/linux/xarray.h | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
Comments
On Mon, Oct 02, 2023 at 10:25:35AM +0200, Stanislaw Gruszka wrote: > Make xa_init_flags() macro to avoid false positive lockdep splats. Friendly ping. The subject should be changed to mention xa_init_flags(), but anything else should be done here to get it apply ? Regards Stanislaw > When spin_lock_init() is used inside initialization function (like > in xa_init_flags()) which can be called many times, lockdep assign > the same key to different locks. > > For example this splat is seen with intel_vpu driver which uses > two xarrays and has two separate xa_init_flags() calls: > > [ 1139.148679] WARNING: inconsistent lock state > [ 1139.152941] 6.6.0-hardening.1+ #2 Tainted: G OE > [ 1139.158758] -------------------------------- > [ 1139.163024] inconsistent {HARDIRQ-ON-W} -> {IN-HARDIRQ-W} usage. > [ 1139.169018] kworker/10:1/109 [HC1[1]:SC0[0]:HE0:SE1] takes: > [ 1139.174576] ffff888137237150 (&xa->xa_lock#18){?.+.}-{2:2}, at: ivpu_mmu_user_context_mark_invalid+0x1c/0x80 [intel_vpu] > [ 1139.185438] {HARDIRQ-ON-W} state was registered at: > [ 1139.190305] lock_acquire+0x1a3/0x4a0 > [ 1139.194055] _raw_spin_lock+0x2c/0x40 > [ 1139.197800] ivpu_submit_ioctl+0xf0b/0x3520 [intel_vpu] > [ 1139.203114] drm_ioctl_kernel+0x201/0x3f0 [drm] > [ 1139.207791] drm_ioctl+0x47d/0xa20 [drm] > [ 1139.211846] __x64_sys_ioctl+0x12e/0x1a0 > [ 1139.215849] do_syscall_64+0x59/0x90 > [ 1139.219509] entry_SYSCALL_64_after_hwframe+0x6e/0xd8 > [ 1139.224636] irq event stamp: 45500 > [ 1139.228037] hardirqs last enabled at (45499): [<ffffffff92ef0314>] _raw_spin_unlock_irq+0x24/0x50 > [ 1139.236961] hardirqs last disabled at (45500): [<ffffffff92eadf8f>] common_interrupt+0xf/0x90 > [ 1139.245457] softirqs last enabled at (44956): [<ffffffff92ef3430>] __do_softirq+0x4c0/0x712 > [ 1139.253862] softirqs last disabled at (44461): [<ffffffff907df310>] irq_exit_rcu+0xa0/0xd0 > [ 1139.262098] > other info that might help us debug this: > [ 1139.268604] Possible unsafe locking scenario: > > [ 1139.274505] CPU0 > [ 1139.276955] ---- > [ 1139.279403] lock(&xa->xa_lock#18); > [ 1139.282978] <Interrupt> > [ 1139.285601] lock(&xa->xa_lock#18); > [ 1139.289345] > *** DEADLOCK *** > > Lockdep falsely identified xa_lock from two different xarrays as the same > lock and report deadlock. More detailed description of the problem > is provided in commit c21f11d182c2 ("drm: fix drmm_mutex_init()") > > Signed-off-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com> > --- > include/linux/xarray.h | 17 +++++++---------- > 1 file changed, 7 insertions(+), 10 deletions(-) > > diff --git a/include/linux/xarray.h b/include/linux/xarray.h > index cb571dfcf4b1..409d9d739ee9 100644 > --- a/include/linux/xarray.h > +++ b/include/linux/xarray.h > @@ -375,12 +375,12 @@ void xa_destroy(struct xarray *); > * > * Context: Any context. > */ > -static inline void xa_init_flags(struct xarray *xa, gfp_t flags) > -{ > - spin_lock_init(&xa->xa_lock); > - xa->xa_flags = flags; > - xa->xa_head = NULL; > -} > +#define xa_init_flags(_xa, _flags) \ > +do { \ > + spin_lock_init(&(_xa)->xa_lock);\ > + (_xa)->xa_flags = (_flags); \ > + (_xa)->xa_head = NULL; \ > +} while (0) > > /** > * xa_init() - Initialise an empty XArray. > @@ -390,10 +390,7 @@ static inline void xa_init_flags(struct xarray *xa, gfp_t flags) > * > * Context: Any context. > */ > -static inline void xa_init(struct xarray *xa) > -{ > - xa_init_flags(xa, 0); > -} > +#define xa_init(xa) xa_init_flags(xa, 0) > > /** > * xa_empty() - Determine if an array has any present entries. > -- > 2.25.1 >
On 10/23/23 04:49, Stanislaw Gruszka wrote: > On Mon, Oct 02, 2023 at 10:25:35AM +0200, Stanislaw Gruszka wrote: >> Make xa_init_flags() macro to avoid false positive lockdep splats. > > Friendly ping. The subject should be changed to mention xa_init_flags(), > but anything else should be done here to get it apply ? > > Regards > Stanislaw > > >> When spin_lock_init() is used inside initialization function (like >> in xa_init_flags()) which can be called many times, lockdep assign >> the same key to different locks. >> >> For example this splat is seen with intel_vpu driver which uses >> two xarrays and has two separate xa_init_flags() calls: >> >> [ 1139.148679] WARNING: inconsistent lock state >> [ 1139.152941] 6.6.0-hardening.1+ #2 Tainted: G OE >> [ 1139.158758] -------------------------------- >> [ 1139.163024] inconsistent {HARDIRQ-ON-W} -> {IN-HARDIRQ-W} usage. >> [ 1139.169018] kworker/10:1/109 [HC1[1]:SC0[0]:HE0:SE1] takes: >> [ 1139.174576] ffff888137237150 (&xa->xa_lock#18){?.+.}-{2:2}, at: ivpu_mmu_user_context_mark_invalid+0x1c/0x80 [intel_vpu] >> [ 1139.185438] {HARDIRQ-ON-W} state was registered at: >> [ 1139.190305] lock_acquire+0x1a3/0x4a0 >> [ 1139.194055] _raw_spin_lock+0x2c/0x40 >> [ 1139.197800] ivpu_submit_ioctl+0xf0b/0x3520 [intel_vpu] >> [ 1139.203114] drm_ioctl_kernel+0x201/0x3f0 [drm] >> [ 1139.207791] drm_ioctl+0x47d/0xa20 [drm] >> [ 1139.211846] __x64_sys_ioctl+0x12e/0x1a0 >> [ 1139.215849] do_syscall_64+0x59/0x90 >> [ 1139.219509] entry_SYSCALL_64_after_hwframe+0x6e/0xd8 >> [ 1139.224636] irq event stamp: 45500 >> [ 1139.228037] hardirqs last enabled at (45499): [<ffffffff92ef0314>] _raw_spin_unlock_irq+0x24/0x50 >> [ 1139.236961] hardirqs last disabled at (45500): [<ffffffff92eadf8f>] common_interrupt+0xf/0x90 >> [ 1139.245457] softirqs last enabled at (44956): [<ffffffff92ef3430>] __do_softirq+0x4c0/0x712 >> [ 1139.253862] softirqs last disabled at (44461): [<ffffffff907df310>] irq_exit_rcu+0xa0/0xd0 >> [ 1139.262098] >> other info that might help us debug this: >> [ 1139.268604] Possible unsafe locking scenario: >> >> [ 1139.274505] CPU0 >> [ 1139.276955] ---- >> [ 1139.279403] lock(&xa->xa_lock#18); >> [ 1139.282978] <Interrupt> >> [ 1139.285601] lock(&xa->xa_lock#18); >> [ 1139.289345] >> *** DEADLOCK *** >> >> Lockdep falsely identified xa_lock from two different xarrays as the same >> lock and report deadlock. More detailed description of the problem >> is provided in commit c21f11d182c2 ("drm: fix drmm_mutex_init()") >> >> Signed-off-by: Stanislaw Gruszka <stanislaw.gruszka@linux.intel.com> >> --- >> include/linux/xarray.h | 17 +++++++---------- >> 1 file changed, 7 insertions(+), 10 deletions(-) >> >> diff --git a/include/linux/xarray.h b/include/linux/xarray.h >> index cb571dfcf4b1..409d9d739ee9 100644 >> --- a/include/linux/xarray.h >> +++ b/include/linux/xarray.h >> @@ -375,12 +375,12 @@ void xa_destroy(struct xarray *); >> * >> * Context: Any context. >> */ >> -static inline void xa_init_flags(struct xarray *xa, gfp_t flags) >> -{ >> - spin_lock_init(&xa->xa_lock); >> - xa->xa_flags = flags; >> - xa->xa_head = NULL; >> -} >> +#define xa_init_flags(_xa, _flags) \ >> +do { \ >> + spin_lock_init(&(_xa)->xa_lock);\ >> + (_xa)->xa_flags = (_flags); \ >> + (_xa)->xa_head = NULL; \ >> +} while (0) >> >> /** >> * xa_init() - Initialise an empty XArray. >> @@ -390,10 +390,7 @@ static inline void xa_init_flags(struct xarray *xa, gfp_t flags) >> * >> * Context: Any context. >> */ >> -static inline void xa_init(struct xarray *xa) >> -{ >> - xa_init_flags(xa, 0); >> -} >> +#define xa_init(xa) xa_init_flags(xa, 0) >> >> /** >> * xa_empty() - Determine if an array has any present entries. >> -- >> 2.25.1 >> LGTM. However, it is up to Matthew to take it or not as he is the XArray maintainer. Acked-by: Waiman Long <longman@redhat.com>
diff --git a/include/linux/xarray.h b/include/linux/xarray.h index cb571dfcf4b1..409d9d739ee9 100644 --- a/include/linux/xarray.h +++ b/include/linux/xarray.h @@ -375,12 +375,12 @@ void xa_destroy(struct xarray *); * * Context: Any context. */ -static inline void xa_init_flags(struct xarray *xa, gfp_t flags) -{ - spin_lock_init(&xa->xa_lock); - xa->xa_flags = flags; - xa->xa_head = NULL; -} +#define xa_init_flags(_xa, _flags) \ +do { \ + spin_lock_init(&(_xa)->xa_lock);\ + (_xa)->xa_flags = (_flags); \ + (_xa)->xa_head = NULL; \ +} while (0) /** * xa_init() - Initialise an empty XArray. @@ -390,10 +390,7 @@ static inline void xa_init_flags(struct xarray *xa, gfp_t flags) * * Context: Any context. */ -static inline void xa_init(struct xarray *xa) -{ - xa_init_flags(xa, 0); -} +#define xa_init(xa) xa_init_flags(xa, 0) /** * xa_empty() - Determine if an array has any present entries.