From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 18D24C83F10 for ; Thu, 31 Aug 2023 14:00:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3776A10E680; Thu, 31 Aug 2023 14:00:12 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 46E3010E67D; Thu, 31 Aug 2023 14:00:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1693490409; x=1725026409; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=l/N6qgGvc2QkylKf6Jd7o1STK1wQt1v0FMLV2M6zGzA=; b=FTos3LbUcy54NY82JTDqBwHzOsjKDQkSnh/0qpEuKEBW3kCfGxoHUFJx iiTuGMDfXpL6CpPgrTQDu0UKK81Y3M+QYB8Q5R61kf3SqBGybwhg+0WyU NSOqgwkov3kYSNAtrJ1crRxzA/oRqS7HAm9mhiJRNkzn/y9oZknK6PcTL 5IdcjUVcBE5OJPPCQJNffaeZYh/qO3hXEo/LyQcsQmUTt08s/aG/SCoKi caZy/qofeJF51e+XoEXkJJaHjZRRYf+CEh4lrK7jNyZrfdOX8QHsiWsIY pkUy86aAxgQOt9PhSxoID6nPApRdUlglFjb1K4lPgX7C7ur3rDfsNKZ3C g==; X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="355451315" X-IronPort-AV: E=Sophos;i="6.02,216,1688454000"; d="scan'208";a="355451315" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Aug 2023 07:00:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="689366445" X-IronPort-AV: E=Sophos;i="6.02,216,1688454000"; d="scan'208";a="689366445" Received: from dineshba-mobl.ger.corp.intel.com (HELO intel.com) ([10.251.214.161]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Aug 2023 07:00:04 -0700 Date: Thu, 31 Aug 2023 16:00:00 +0200 From: Andi Shyti To: John Harrison Message-ID: References: <20230811182011.546026-1-zhanjun.dong@intel.com> <3a745c83-e7cf-6a24-5556-8c0c019adfec@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Intel-gfx] [PATCH v5] drm/i915: Avoid circular locking dependency when flush delayed work on gt reset X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Daniel Vetter Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" Hi, > > > > diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c > > > > index a0e3ef1c65d2..600388c849f7 100644 > > > > --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c > > > > +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c > > > > @@ -1359,7 +1359,16 @@ static void guc_enable_busyness_worker(struct intel_guc *guc) > > > > static void guc_cancel_busyness_worker(struct intel_guc *guc) > > > > { > > > > - cancel_delayed_work_sync(&guc->timestamp.work); > > > > + /* > > > > + * When intel_gt_reset was called, task will hold a lock. > > > > + * To cacel delayed work here, the _sync version will also acquire a lock, which might > > > > + * trigger the possible cirular locking dependency warning. > > > > + * Check the reset_in_progress flag, call async verion if reset is in progress. > > > > + */ > > > This needs to explain in much more detail what is going on and why it is not > > > a problem. E.g.: > > > > > > The busyness worker needs to be cancelled. In general that means > > > using the synchronous cancel version to ensure that an in-progress > > > worker will not keep executing beyond whatever is happening that > > > needs the cancel. E.g. suspend, driver unload, etc. However, in the > > > case of a reset, the synchronous version is not required and can > > > trigger a false deadlock detection warning. > > > > > > The business worker takes the reset mutex to protect against resets > > > interfering with it. However, it does a trylock and bails out if the > > > reset lock is already acquired. Thus there is no actual deadlock or > > > other concern with the worker running concurrently with a reset. So > > > an asynchronous cancel is safe in the case of a reset rather than a > > > driver unload or suspend type operation. On the other hand, if the > > > cancel_sync version is used when a reset is in progress then the > > > mutex deadlock detection sees the mutex being acquired through > > > multiple paths and complains. > > > > > > So just don't bother. That keeps the detection code happy and is > > > safe because of the trylock code described above. > > So why do we even need to cancel anything if it doesn't do anything while > > the reset is in progress? > It still needs to be cancelled. The worker only aborts if it is actively > executing concurrently with the reset. It might not start to execute until > after the reset has completed. And there is presumably a reason why the > cancel is being called, a reason not necessarily related to resets at all. > Leaving the worker to run arbitrarily after the driver is expecting it to be > stopped will lead to much worse things than a fake lockdep splat, e.g. a use > after free pointer deref. I was actually thinking why not leave things as they are and just disable lockdep from CI. This doesn't look like a relevant report to me. Andi From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5D1B2C83F01 for ; Thu, 31 Aug 2023 14:00:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AAF0310E67D; Thu, 31 Aug 2023 14:00:11 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.136]) by gabe.freedesktop.org (Postfix) with ESMTPS id 46E3010E67D; Thu, 31 Aug 2023 14:00:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1693490409; x=1725026409; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=l/N6qgGvc2QkylKf6Jd7o1STK1wQt1v0FMLV2M6zGzA=; b=FTos3LbUcy54NY82JTDqBwHzOsjKDQkSnh/0qpEuKEBW3kCfGxoHUFJx iiTuGMDfXpL6CpPgrTQDu0UKK81Y3M+QYB8Q5R61kf3SqBGybwhg+0WyU NSOqgwkov3kYSNAtrJ1crRxzA/oRqS7HAm9mhiJRNkzn/y9oZknK6PcTL 5IdcjUVcBE5OJPPCQJNffaeZYh/qO3hXEo/LyQcsQmUTt08s/aG/SCoKi caZy/qofeJF51e+XoEXkJJaHjZRRYf+CEh4lrK7jNyZrfdOX8QHsiWsIY pkUy86aAxgQOt9PhSxoID6nPApRdUlglFjb1K4lPgX7C7ur3rDfsNKZ3C g==; X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="355451315" X-IronPort-AV: E=Sophos;i="6.02,216,1688454000"; d="scan'208";a="355451315" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Aug 2023 07:00:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10818"; a="689366445" X-IronPort-AV: E=Sophos;i="6.02,216,1688454000"; d="scan'208";a="689366445" Received: from dineshba-mobl.ger.corp.intel.com (HELO intel.com) ([10.251.214.161]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Aug 2023 07:00:04 -0700 Date: Thu, 31 Aug 2023 16:00:00 +0200 From: Andi Shyti To: John Harrison Subject: Re: [PATCH v5] drm/i915: Avoid circular locking dependency when flush delayed work on gt reset Message-ID: References: <20230811182011.546026-1-zhanjun.dong@intel.com> <3a745c83-e7cf-6a24-5556-8c0c019adfec@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhanjun Dong , intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, Andi Shyti Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Hi, > > > > diff --git a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c > > > > index a0e3ef1c65d2..600388c849f7 100644 > > > > --- a/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c > > > > +++ b/drivers/gpu/drm/i915/gt/uc/intel_guc_submission.c > > > > @@ -1359,7 +1359,16 @@ static void guc_enable_busyness_worker(struct intel_guc *guc) > > > > static void guc_cancel_busyness_worker(struct intel_guc *guc) > > > > { > > > > - cancel_delayed_work_sync(&guc->timestamp.work); > > > > + /* > > > > + * When intel_gt_reset was called, task will hold a lock. > > > > + * To cacel delayed work here, the _sync version will also acquire a lock, which might > > > > + * trigger the possible cirular locking dependency warning. > > > > + * Check the reset_in_progress flag, call async verion if reset is in progress. > > > > + */ > > > This needs to explain in much more detail what is going on and why it is not > > > a problem. E.g.: > > > > > > The busyness worker needs to be cancelled. In general that means > > > using the synchronous cancel version to ensure that an in-progress > > > worker will not keep executing beyond whatever is happening that > > > needs the cancel. E.g. suspend, driver unload, etc. However, in the > > > case of a reset, the synchronous version is not required and can > > > trigger a false deadlock detection warning. > > > > > > The business worker takes the reset mutex to protect against resets > > > interfering with it. However, it does a trylock and bails out if the > > > reset lock is already acquired. Thus there is no actual deadlock or > > > other concern with the worker running concurrently with a reset. So > > > an asynchronous cancel is safe in the case of a reset rather than a > > > driver unload or suspend type operation. On the other hand, if the > > > cancel_sync version is used when a reset is in progress then the > > > mutex deadlock detection sees the mutex being acquired through > > > multiple paths and complains. > > > > > > So just don't bother. That keeps the detection code happy and is > > > safe because of the trylock code described above. > > So why do we even need to cancel anything if it doesn't do anything while > > the reset is in progress? > It still needs to be cancelled. The worker only aborts if it is actively > executing concurrently with the reset. It might not start to execute until > after the reset has completed. And there is presumably a reason why the > cancel is being called, a reason not necessarily related to resets at all. > Leaving the worker to run arbitrarily after the driver is expecting it to be > stopped will lead to much worse things than a fake lockdep splat, e.g. a use > after free pointer deref. I was actually thinking why not leave things as they are and just disable lockdep from CI. This doesn't look like a relevant report to me. Andi