From patchwork Fri May 17 14:06:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz Krzysztofik X-Patchwork-Id: 10948015 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 18DC976 for ; Fri, 17 May 2019 14:06:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07CD920182 for ; Fri, 17 May 2019 14:06:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F08D52023F; Fri, 17 May 2019 14:06:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A234520182 for ; Fri, 17 May 2019 14:06:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 25D47898EA; Fri, 17 May 2019 14:06:50 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id 27CD4898EA; Fri, 17 May 2019 14:06:47 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 May 2019 07:06:45 -0700 Received: from jkrzyszt-desk.igk.intel.com ([172.22.244.18]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 May 2019 07:06:42 -0700 From: Janusz Krzysztofik To: intel-gfx@lists.freedesktop.org Date: Fri, 17 May 2019 16:06:17 +0200 Message-Id: <20190517140617.31187-1-janusz.krzysztofik@linux.intel.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Subject: [Intel-gfx] [RFC PATCH] drm/i915: Tolerate file owned GEM contexts on hot unbind X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Janusz Krzysztofik , David Airlie , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Janusz Krzysztofik During i915_driver_unload(), GEM contexts are verified restrictively inside i915_gem_fini() if they don't consume shared resources which should be cleaned up before the driver is released. If those checks don't result in kernel panic, one more check is performed at the end of i915_gem_fini() which issues a WARN_ON() if GEM contexts still exist. Some GEM contexts are allocated unconditionally on device file open, one per each file descriptor, and are kept open until those file descriptors are closed. Since open file descriptors prevent the driver module from being unloaded, that protects the driver from being released while contexts are still open. However, that's not the case on driver unbind or device unplug sysfs operations which are executed regardless of open file descriptors. To protect kernel resources from being accessed by those open file decriptors while driver unbind or device unplug operation is in progress, the driver now calls drm_device_unplug() at the beginning of that process and relies on the DRM layer to provide such protection. Taking all above information into account, as soon as shared resources not associated with specific file descriptors are cleaned up, it should be safe to postpone completion of driver release until users of those open file decriptors give up on errors and close them. When device has been marked unplugged, use WARN_ON() conditionally so the warning is displayed only if a GEM context not associated with a file descriptor is still allocated. Signed-off-by: Janusz Krzysztofik --- drivers/gpu/drm/i915/i915_gem.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 54f27cabae2a..c00b6dbaf4f5 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -4670,7 +4670,17 @@ void i915_gem_fini(struct drm_i915_private *dev_priv) i915_gem_drain_freed_objects(dev_priv); - WARN_ON(!list_empty(&dev_priv->contexts.list)); + if (drm_dev_is_unplugged(&dev_priv->drm)) { + struct i915_gem_context *ctx, *cn; + + list_for_each_entry_safe(ctx, cn, &dev_priv->contexts.list, + link) { + WARN_ON(IS_ERR_OR_NULL(ctx->file_priv)); + break; + } + } else { + WARN_ON(!list_empty(&dev_priv->contexts.list)); + } } void i915_gem_init_mmio(struct drm_i915_private *i915)