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: 10948017 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 B68106C5 for ; Fri, 17 May 2019 14:06:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A467A20182 for ; Fri, 17 May 2019 14:06:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 96FED2023F; Fri, 17 May 2019 14:06:52 +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=unavailable 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 593EC20182 for ; Fri, 17 May 2019 14:06:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 718AC898ED; Fri, 17 May 2019 14:06:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@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 Subject: [RFC PATCH] drm/i915: Tolerate file owned GEM contexts on hot unbind 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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - 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, Rodrigo Vivi , Michal Wajdeczko Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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)