Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1077830yba; Thu, 4 Apr 2019 03:55:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqzDf6hwF/b8Ug5DmOTunZAz0xfUgck3M9uM/+lQ+3AIpdCGfs/P3uDkSIyjlcKQdoERRfLw X-Received: by 2002:a65:5304:: with SMTP id m4mr5054820pgq.281.1554375307199; Thu, 04 Apr 2019 03:55:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554375307; cv=none; d=google.com; s=arc-20160816; b=MPnwFfG5bXZISNOUeS52HOcTUdEXlEJougBgo6KGa504a6Hk+BAYHnWUGbyfxPg3Gg spI31s1otN+uP8ad7W7VjjQ69Ed6ZeAGq1tUn//cQINGytGmMnFUC+LHh/SdPHzQn00R sHQjW/Zos/DrFJoaVwMNdvX1uazDboZj/kx2CoInLEcZVD8tpcgXpEuI1bVHwrTXqmDi fRdUkgScFcA3nJK/ZJlrCwpdNRmd3ax7l6dGfoIgjpQF+wjHlZGjtvUiZ36bszjqWvNN 9qbTxoUTz/8A59oPkoKa8pvdwKhS8g+DG2n0X/Pn3Iapu+33E6rYbIND+X5cNlEOcqFx h1jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:subject:user-agent:message-id :references:cc:in-reply-to:from:to:content-transfer-encoding :mime-version; bh=3Z+QKQb1KriTyIFz8e/80IoS8xZRi0bVY9BJ0aB/cb0=; b=LptLgoVvwcaL9ye32v8irXxswpm6+KLGlOVyhglaYt1O/md4yEazzAVO0KMMcZU2M4 RkSauv/GBHx/ejxwlwK/3p95T23gvz4ydYPW06o5n5sVC6POire1uxprrNZNJG+oAfJH RRi+ziZ3IzFo22Wjyx/cGCp4JEvoyah6b3SBIyauVe19ahEmdVRLTcklmwPXf8Z5bAiE g1gyM+pRrO2yPt9N2NQr8HjS17AZyLKw1ywoYid3qPc5Vg4D3cdWQxwjbiLKOkAFiBFN gQtTxzqNgYw38wkxzmRAazOtKxCglxxif3Mv2t86HT3yCBz3zlv5I+AYewsdwwfDd9zF Z0jw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 16si15828989pfh.244.2019.04.04.03.54.51; Thu, 04 Apr 2019 03:55:07 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729263AbfDDKyB convert rfc822-to-8bit (ORCPT + 99 others); Thu, 4 Apr 2019 06:54:01 -0400 Received: from mail.fireflyinternet.com ([109.228.58.192]:51313 "EHLO fireflyinternet.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727071AbfDDKyA (ORCPT ); Thu, 4 Apr 2019 06:54:00 -0400 X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from localhost (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP (TLS) id 16128902-1500050 for multiple; Thu, 04 Apr 2019 11:53:47 +0100 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT To: Janusz Krzysztofik From: Chris Wilson In-Reply-To: <1bda752c136f3a75817fe257027edd8be4e7472e.camel@linux.intel.com> Cc: David Airlie , intel-gfx@lists.freedesktop.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Rodrigo Vivi References: <20190404102445.12303-1-janusz.krzysztofik@linux.intel.com> <155437373474.7532.10868620123516507965@skylake-alporthouse-com> <155437462649.7532.18347010454266779928@skylake-alporthouse-com> <1bda752c136f3a75817fe257027edd8be4e7472e.camel@linux.intel.com> Message-ID: <155437522546.7532.6754257066058816161@skylake-alporthouse-com> User-Agent: alot/0.6 Subject: Re: [Intel-gfx] [PATCH] drm/i915: Fix context IDs not released on driver hot unbind Date: Thu, 04 Apr 2019 11:53:45 +0100 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Janusz Krzysztofik (2019-04-04 11:50:14) > On Thu, 2019-04-04 at 11:43 +0100, Chris Wilson wrote: > > Quoting Janusz Krzysztofik (2019-04-04 11:40:24) > > > On Thu, 2019-04-04 at 11:28 +0100, Chris Wilson wrote: > > > > Quoting Janusz Krzysztofik (2019-04-04 11:24:45) > > > > > From: Janusz Krzysztofik > > > > > > > > > > In case the driver gets unbound while a device is open, kernel > > > > > panic > > > > > may be forced if a list of allocated context IDs is not empty. > > > > > > > > > > When a device is open, the list may happen to be not empty > > > > > because > > > > > a > > > > > context ID, once allocated by a context ID allocator to a > > > > > context > > > > > assosiated with that open file descriptor, is released as late > > > > > as > > > > > on device close. > > > > > > > > > > On the other hand, there is a need to release all allocated > > > > > context > > > > > IDs > > > > > and destroy the context ID allocator on driver unbind, even if > > > > > a > > > > > device > > > > > is open, in order to free memory resources consumed and prevent > > > > > from > > > > > memory leaks. The purpose of the forced kernel panic was to > > > > > protect > > > > > the context ID allocator from being silently destroyed if not > > > > > all > > > > > allocated IDs had been released. > > > > > > > > Those open fd are still pointing into kernel memory where the > > > > driver > > > > used to be. The panic is entirely correct, we should not be > > > > unloading > > > > the module before those dangling pointers have been made safe. > > > > > > > > This is papering over the symptom. How is the module being > > > > unloaded > > > > with > > > > open fd? > > > > > > A user can play with the driver unbind or device remove sysfs > > > interface. > > > > Sure, but we must still follow all the steps before _unloading_ the > > module or else the user is left pointing into reused kernel memory. > > I'm not talking about unloading the module, that is prevented by open > fds. The driver still exists after being unbound from a device and may > just respond with -ENODEV. i915_gem_contexts_fini() *is* module unload. -Chris