Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752281AbdDJTjE (ORCPT ); Mon, 10 Apr 2017 15:39:04 -0400 Received: from mail-qt0-f170.google.com ([209.85.216.170]:36126 "EHLO mail-qt0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752052AbdDJTjC (ORCPT ); Mon, 10 Apr 2017 15:39:02 -0400 Date: Mon, 10 Apr 2017 15:38:44 -0400 From: Sean Paul To: Jeffy Chen Cc: linux-kernel@vger.kernel.org, briannorris@chromium.org, dianders@chromium.org, tfiga@chromium.org, seanpaul@chromium.org, zyw@rock-chips.com, marcheu@chromium.org, mark.yao@rock-chips.com, hshi@chromium.org, Daniel Vetter , Jani Nikula , dri-devel@lists.freedesktop.org, Chris Wilson , David Airlie , Tom Gundersen , Patrik Jakobsson , Dave Airlie Subject: Re: [PATCH v6 1/2] drm: Unplug drm device when unregistering it Message-ID: <20170410193844.td6gdajtuzgztryn@art_vandelay> References: <1491818445-11409-1-git-send-email-jeffy.chen@rock-chips.com> <1491818445-11409-2-git-send-email-jeffy.chen@rock-chips.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1491818445-11409-2-git-send-email-jeffy.chen@rock-chips.com> User-Agent: NeoMutt/20170306-66-6ddb52-dirty (1.8.0) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2907 Lines: 101 On Mon, Apr 10, 2017 at 06:00:44PM +0800, Jeffy Chen wrote: > After unbinding drm, the user space may still owns the drm dev fd, > and may still be able to call drm ioctl. > > We're using an unplugged state to prevent something like that, so > let's reuse it here. > > Signed-off-by: Jeffy Chen > --- > > Changes in v6: > Address Daniel Vetter 's comments. > > Changes in v5: > Fix wrong git account. > > Changes in v2: > Fix some commit messages. > > drivers/gpu/drm/drm_drv.c | 6 +++--- > drivers/gpu/drm/udl/udl_drv.c | 2 +- > include/drm/drmP.h | 6 ++++++ > 3 files changed, 10 insertions(+), 4 deletions(-) > > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c > index b5c6bb4..f38de26 100644 > --- a/drivers/gpu/drm/drm_drv.c > +++ b/drivers/gpu/drm/drm_drv.c > @@ -357,9 +357,6 @@ EXPORT_SYMBOL(drm_put_dev); > > void drm_unplug_dev(struct drm_device *dev) > { > - /* for a USB device */ > - drm_dev_unregister(dev); > - > mutex_lock(&drm_global_mutex); > > drm_device_set_unplugged(dev); > @@ -787,6 +784,8 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) > if (drm_core_check_feature(dev, DRIVER_MODESET)) > drm_modeset_register_all(dev); > > + drm_device_set_plugged(dev); > + > ret = 0; > > DRM_INFO("Initialized %s %d.%d.%d %s for %s on minor %d\n", > @@ -826,6 +825,7 @@ void drm_dev_unregister(struct drm_device *dev) > drm_lastclose(dev); > > dev->registered = false; > + drm_unplug_dev(dev); > > if (drm_core_check_feature(dev, DRIVER_MODESET)) > drm_modeset_unregister_all(dev); > diff --git a/drivers/gpu/drm/udl/udl_drv.c b/drivers/gpu/drm/udl/udl_drv.c > index cd8b017..5dbd916 100644 > --- a/drivers/gpu/drm/udl/udl_drv.c > +++ b/drivers/gpu/drm/udl/udl_drv.c > @@ -108,7 +108,7 @@ static void udl_usb_disconnect(struct usb_interface *interface) > drm_kms_helper_poll_disable(dev); > udl_fbdev_unplug(dev); > udl_drop_usb(dev); > - drm_unplug_dev(dev); > + drm_dev_unregister(dev); > } > > /* > diff --git a/include/drm/drmP.h b/include/drm/drmP.h > index 3bfafcd..c930a77 100644 > --- a/include/drm/drmP.h > +++ b/include/drm/drmP.h > @@ -488,6 +488,12 @@ static __inline__ int drm_core_check_feature(struct drm_device *dev, > return ((dev->driver->driver_features & feature) ? 1 : 0); > } > > +static inline void drm_device_set_plugged(struct drm_device *dev) > +{ > + smp_wmb(); > + atomic_set(&dev->unplugged, 0); > +} > + > static inline void drm_device_set_unplugged(struct drm_device *dev) Instead of introducing a new function, just rename this to drm_device_set_plug_state(struct drm_device *dev, bool plugged) and call it from both plug and unplug With that nit, this is Reviewed-by: Sean Paul > { > smp_wmb(); > -- > 2.1.4 > -- Sean Paul, Software Engineer, Google / Chromium OS