Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967085AbdDZTnp (ORCPT ); Wed, 26 Apr 2017 15:43:45 -0400 Received: from mga07.intel.com ([134.134.136.100]:14418 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753986AbdDZTnh (ORCPT ); Wed, 26 Apr 2017 15:43:37 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.37,255,1488873600"; d="scan'208";a="79288057" Date: Wed, 26 Apr 2017 22:43:31 +0300 From: Ville =?iso-8859-1?Q?Syrj=E4l=E4?= To: Jeffy Chen Cc: linux-kernel@vger.kernel.org, Dave Airlie , briannorris@chromium.org, dianders@chromium.org, tfiga@chromium.org, dri-devel@lists.freedesktop.org, Daniel Vetter , zyw@rock-chips.com, marcheu@chromium.org, hshi@chromium.org Subject: Re: [PATCH v8 1/2] drm: Unplug drm device when unregistering it Message-ID: <20170426194331.GJ30290@intel.com> References: <1491965730-31393-1-git-send-email-jeffy.chen@rock-chips.com> <1491965730-31393-2-git-send-email-jeffy.chen@rock-chips.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1491965730-31393-2-git-send-email-jeffy.chen@rock-chips.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4354 Lines: 142 On Wed, Apr 12, 2017 at 10:55:29AM +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. > > Also drop drm_unplug_dev, because it would be unused after other changes. > > Signed-off-by: Jeffy Chen > Reviewed-by: Sean Paul > > --- > > Changes in v8: > Fix hang when unregistering drm dev with open_count 0 > > Changes in v7: > Address Sean Paul 's comments. > > 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 | 19 +++---------------- > drivers/gpu/drm/udl/udl_drv.c | 2 +- > include/drm/drmP.h | 5 +++-- > include/drm/drm_drv.h | 1 - > 4 files changed, 7 insertions(+), 20 deletions(-) > > diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c > index b5c6bb4..cc2d018 100644 > --- a/drivers/gpu/drm/drm_drv.c > +++ b/drivers/gpu/drm/drm_drv.c > @@ -355,22 +355,6 @@ void drm_put_dev(struct drm_device *dev) > } > 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); > - > - if (dev->open_count == 0) { > - drm_put_dev(dev); > - } > - mutex_unlock(&drm_global_mutex); > -} > -EXPORT_SYMBOL(drm_unplug_dev); > - > /* > * DRM internal mount > * We want to be able to allocate our own "struct address_space" to control > @@ -787,6 +771,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_plug_state(dev, true); This makes me think this has something to do with actual plugs, be they the bath tub kind or some *ahem* other kind. /methinks this should at least be called set_plugged_state or something like that. Or maybe there's an even better name that could be used? > + > ret = 0; > > DRM_INFO("Initialized %s %d.%d.%d %s for %s on minor %d\n", > @@ -826,6 +812,7 @@ void drm_dev_unregister(struct drm_device *dev) > drm_lastclose(dev); > > dev->registered = false; > + drm_device_set_plug_state(dev, false); > > 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..a9a5a64 100644 > --- a/include/drm/drmP.h > +++ b/include/drm/drmP.h > @@ -488,10 +488,11 @@ 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_unplugged(struct drm_device *dev) > +static inline void drm_device_set_plug_state(struct drm_device *dev, > + bool plugged) > { > smp_wmb(); > - atomic_set(&dev->unplugged, 1); > + atomic_set(&dev->unplugged, !plugged); > } > > static inline int drm_device_is_unplugged(struct drm_device *dev) > diff --git a/include/drm/drm_drv.h b/include/drm/drm_drv.h > index 0fefc3f..eb63078 100644 > --- a/include/drm/drm_drv.h > +++ b/include/drm/drm_drv.h > @@ -544,7 +544,6 @@ void drm_dev_unregister(struct drm_device *dev); > void drm_dev_ref(struct drm_device *dev); > void drm_dev_unref(struct drm_device *dev); > void drm_put_dev(struct drm_device *dev); > -void drm_unplug_dev(struct drm_device *dev); > > int drm_dev_set_unique(struct drm_device *dev, const char *name); > > -- > 2.1.4 > > > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel -- Ville Syrj?l? Intel OTC