Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp180233yba; Fri, 5 Apr 2019 04:40:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqwFnqZeLr2Wyov8kNSGn8Iu5UWUpNLjDsawSdL8dR8sxmpUIpisbvAqS3AFiV1glcLg+m5S X-Received: by 2002:a63:e14e:: with SMTP id h14mr11466759pgk.184.1554464406995; Fri, 05 Apr 2019 04:40:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554464406; cv=none; d=google.com; s=arc-20160816; b=p5cVkZcA69/46Tvs2TRtSqHK2uMLC7QYTcVagJf2HN10X4/smMnw68+rK3h/Riuy8M mfEEL9awO0seU0Ns5/69fmyTx2HmWXfvwtDq3mJ+YuutM07BJNQV4xSqVKewClA7iZxb FwFxZTx/3H3i8lDCPWTXm8Jg1XCawwpKusyYRBCYph1lpFCv0ze0pVHlg7FKuLeHEo5a jj7Pd3/r8AotVcJeA46TgJJASHBU+nNnOUEXmA5L0i7OXBKdVawBuK7HMDqMTcSvAQl3 UyKnuWNE5h1chQpLzdenDZRzBfB6R/hPYIHIU+nyDeQg7qEE7PdfC9H8CZr1vnqGYdE+ RfRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:organization:references:in-reply-to:date:cc:to:from :subject:message-id; bh=1DnHSzZt137eysH1urPjIOsCUsfGTd0pNPa1G8j2mhQ=; b=nmeQjsLDvRo0xOpwVbECMtqwvjHaWFMRRfZC6FvmoP+a//74RW1RnBTVc+xZjZ+NWA ili2xA2BnJ+nQalUirc+esCKu82k2ttCB6ZSmVuYRtugyyjoI4YabA426U8YeEw6iKTU 6sawiuedS9E6WOPSJFeWdLuRHheukCvMlu382GaxSEBWS2WWpcxnMC7DyscM7YA0P0lA dHHBHg49BzXWLvB4VlveSkIXVEtn9XmX7muRZMRwwNC6cy2XA4GtjzjxVQvW0wOUWamv 7GZas4ER5fDNaCXY1P+e4uD8wU71xfnjjJgErU4DZn74RI6tLtL9Vbf8Hqvmge8Tpgh6 UfIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o12si6363939plk.310.2019.04.05.04.39.51; Fri, 05 Apr 2019 04:40:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731139AbfDELis (ORCPT + 99 others); Fri, 5 Apr 2019 07:38:48 -0400 Received: from mga12.intel.com ([192.55.52.136]:50163 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730642AbfDELis (ORCPT ); Fri, 5 Apr 2019 07:38:48 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Apr 2019 04:38:47 -0700 X-IronPort-AV: E=Sophos;i="5.60,312,1549958400"; d="scan'208";a="131720024" Received: from jkrzyszt-desk.igk.intel.com ([172.22.244.18]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 05 Apr 2019 04:38:45 -0700 Message-ID: Subject: Re: [PATCH] drm/i915: Use drm_dev_unplug() From: Janusz Krzysztofik To: Chris Wilson Cc: David Airlie , intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Rodrigo Vivi , michal.wajdeczko@intel.com Date: Fri, 05 Apr 2019 13:38:43 +0200 In-Reply-To: <155445268803.8259.16095445514284244974@skylake-alporthouse-com> References: <20190405072657.9997-1-janusz.krzysztofik@linux.intel.com> <155445007634.8259.18397004914881394541@skylake-alporthouse-com> <51c51c4d1a2facbc1dfb240b94377027e263872e.camel@linux.intel.com> <155445268803.8259.16095445514284244974@skylake-alporthouse-com> Organization: Intel Technology Poland sp. z o.o. - ul. Slowackiego 173, 80-298 Gdansk - KRS 101882 - NIP 957-07-52-316 Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5 (3.30.5-1.fc29) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2019-04-05 at 09:24 +0100, Chris Wilson wrote: > Quoting Janusz Krzysztofik (2019-04-05 09:11:54) > > On Fri, 2019-04-05 at 08:41 +0100, Chris Wilson wrote: > > > Quoting Janusz Krzysztofik (2019-04-05 08:26:57) > > > > From: Janusz Krzysztofik > > > > > > > > The driver does not currently support unbinding from a device > > > > which > > > > is > > > > in use. Since open file descriptors may still be pointing into > > > > kernel > > > > memory where the device structures used to be, entirely correct > > > > kernel > > > > panics protect the driver from being unbound as we should not > > > > be > > > > unbinding it before those dangling pointers have been made > > > > safe. > > > > > > > > According to the documentation found inside > > > > drivers/gpu/drm/drm_drv.c, > > > > drm_dev_unplug() should be used instead of drm_dev_unregister() > > > > in > > > > order to make a device inaccessible to users as soon as it is > > > > unpluged. > > > > Follow that advice to make those possibly dangling pointers > > > > safe, > > > > protected by DRM layer from a user who is otherwise left > > > > pointing > > > > into > > > > possibly reused kernel memory after the driver has been unbound > > > > from > > > > the device. > > > > > > > > Signed-off-by: Janusz Krzysztofik > > > > > > > > --- > > > > drivers/gpu/drm/i915/i915_drv.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/drivers/gpu/drm/i915/i915_drv.c > > > > b/drivers/gpu/drm/i915/i915_drv.c > > > > index 9df65d386d11..66163378c481 100644 > > > > --- a/drivers/gpu/drm/i915/i915_drv.c > > > > +++ b/drivers/gpu/drm/i915/i915_drv.c > > > > @@ -1596,7 +1596,7 @@ static void i915_driver_unregister(struct > > > > drm_i915_private *dev_priv) > > > > i915_pmu_unregister(dev_priv); > > > > > > > > i915_teardown_sysfs(dev_priv); > > > > - drm_dev_unregister(&dev_priv->drm); > > > > + drm_dev_unplug(&dev_priv->drm); > > > > > > I think we may have our onion inverted here. We want to stop the > > > users > > > as the first step, then start removing the entries. (That will > > > also > > > nicely invert the order from register, which is what we typically > > > expect). > > > > > > After calling i915_driver_unregister(); call > > > i915_gem_set_wedged() to > > > immediately (give or take external fences) cancel inflight > > > operations. > > > > OK, thanks. Do you prefer them squashed or as serparate patches? > > Quite happy to do the s/unregister/unplug/ and move in one go. Have a > pre-emptive > Reviewed-by: Chris Wilson > on that as that seems to be the right thing to do. > > And there should be no issues in placing a i915_gem_set_wedged() > immediately after the call to i915_driver_unregister, so if you > include > a line of commentary about why, for example > > /* > * After unregistering the device to prevent any new users, cancel > * all in-flight requests so that we can quickly unbind the active > * resources. > */ > i915_gem_set_wedged(dev_priv); > > Reviewed-by: Chris Wilson I've given it some testing, no side effects with test workloads I've tried, and looks like it at least helps to prevent from making the device actually wedged. With these two patches, plus the one we discussed yesterday, and yet another one I'm going to submit soon, I'm now able to unbind the driver from a device while a workload is running on it, unload the module, reload it and successfully perform basic GEM health checks, all in a quick succession :-). Unfortunately, not 100% reproducible, as well as not the case with device unplug simulated by writing 1 to device/remove sysfs file. Surely that needs the work you describe below to be done first. Thanks for your cooperation, Janusz > > I think overall though, we need to go through i915_driver_unload() > and > push the module cleanup operations to i915_driver_release -- that > will > take a bit of surgery to separate the different phases that are > currently smashed together. > -Chris > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel