From patchwork Sat Jan 9 13:28:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Vetter X-Patchwork-Id: 7992361 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BB9399F3F6 for ; Sat, 9 Jan 2016 13:28:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BFB4320265 for ; Sat, 9 Jan 2016 13:28:55 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 64AE320279 for ; Sat, 9 Jan 2016 13:28:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2DE606E095; Sat, 9 Jan 2016 05:28:52 -0800 (PST) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-f44.google.com (mail-wm0-f44.google.com [74.125.82.44]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5CF9B6E095 for ; Sat, 9 Jan 2016 05:28:50 -0800 (PST) Received: by mail-wm0-f44.google.com with SMTP id u188so166345593wmu.1 for ; Sat, 09 Jan 2016 05:28:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wgQU7E5ivb2rynbN96gbxnvY4WXDHLEbOnH9QPZSBzM=; b=QWuQ3GOO2w+TWaRgQCIEuCPkWZCikRQqjWepyujnSnSfMCeArQiLsn2Fa3X7n+Wxpd 1IRRJu2c1HZibzWtKAwREkGbQqTP9FFFNku5CqgpHFkYH3lTSIGX2aif1D175otjdb/m TewTzfPCIzYQOzrGwp9yfYcZhGBH2+Vzz2DSY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wgQU7E5ivb2rynbN96gbxnvY4WXDHLEbOnH9QPZSBzM=; b=U+h10YT6kiJOZRvHQXFTtxmtK8V1e+pFzC0UpbnVzWLgoRWxmlpDrPim4Z/lEkd1dE 1ZxOXbLQrkze2MrdF64ilJU2n5WJNECtvzkW9KV8lY3OoLsFq6Xaz3L5JROBBosuSoty LAW8fNJtEv4uwJI12aalczf8JFDXcZT6e9OoSEdAWv5AVa97f8/7FOeJ77J3kG3B/6yU TQO9zGIIyaQ+NYawD6nlwJga+IBHouo8qKCdVHUC2/BHucKkfssTf5uwKS6hRgFXumhj Yf5nR14G6Og9cngILvWckEFWUCl0gWrm+JVoFVF8mGMFtyWFJ1b1J8aVawpN7WMV8n+m 6wOg== X-Gm-Message-State: ALoCoQm+GbkA7R462XkLebi+YM+u9KlTEfz/eTUyWSoQClSWs8FMIp6C38FeErLExbYlSZc0XI4/oz4iTKCVRcvbsQxiVKwUFg== X-Received: by 10.194.87.1 with SMTP id t1mr87778117wjz.170.1452346129004; Sat, 09 Jan 2016 05:28:49 -0800 (PST) Received: from phenom.ffwll.local (212-51-149-109.fiber7.init7.net. [212.51.149.109]) by smtp.gmail.com with ESMTPSA id w8sm66617648wjx.21.2016.01.09.05.28.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 09 Jan 2016 05:28:48 -0800 (PST) From: Daniel Vetter To: DRI Development Subject: [PATCH] drm: Clean up pending events in the core Date: Sat, 9 Jan 2016 14:28:46 +0100 Message-Id: <1452346126-20091-1-git-send-email-daniel.vetter@ffwll.ch> X-Mailer: git-send-email 2.6.4 In-Reply-To: <1452285413-28459-10-git-send-email-daniel.vetter@ffwll.ch> References: <1452285413-28459-10-git-send-email-daniel.vetter@ffwll.ch> Cc: Alex Deucher , Daniel Vetter , Intel Graphics Development X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There's really no reason to not do so, instead of replicating this for every use-case and every driver. Now we can't just nuke the events, since that would still mean that all drm_event users would need to know when that has happened, since calling e.g. drm_send_event isn't allowed any more. Instead just unlink them from the file, and detect this case and handle it appropriately in all functions. v2: Adjust existing kerneldoc too. Cc: Alex Deucher Signed-off-by: Daniel Vetter Acked-by: Daniel Stone --- drivers/gpu/drm/drm_fops.c | 35 ++++++++++++++++++++++++++--------- include/drm/drmP.h | 2 ++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c index d85af1b2a238..d32b24c74e08 100644 --- a/drivers/gpu/drm/drm_fops.c +++ b/drivers/gpu/drm/drm_fops.c @@ -264,6 +264,7 @@ static int drm_open_helper(struct file *filp, struct drm_minor *minor) INIT_LIST_HEAD(&priv->fbs); mutex_init(&priv->fbs_lock); INIT_LIST_HEAD(&priv->blobs); + INIT_LIST_HEAD(&priv->pending_event_list); INIT_LIST_HEAD(&priv->event_list); init_waitqueue_head(&priv->event_wait); priv->event_space = 4096; /* set aside 4k for event buffer */ @@ -353,18 +354,16 @@ static void drm_events_release(struct drm_file *file_priv) { struct drm_device *dev = file_priv->minor->dev; struct drm_pending_event *e, *et; - struct drm_pending_vblank_event *v, *vt; unsigned long flags; spin_lock_irqsave(&dev->event_lock, flags); - /* Remove pending flips */ - list_for_each_entry_safe(v, vt, &dev->vblank_event_list, base.link) - if (v->base.file_priv == file_priv) { - list_del(&v->base.link); - drm_vblank_put(dev, v->pipe); - v->base.destroy(&v->base); - } + /* Unlink pending events */ + list_for_each_entry_safe(e, et, &file_priv->pending_event_list, + pending_link) { + list_del(&e->pending_link); + e->file_priv = NULL; + } /* Remove unconsumed events */ list_for_each_entry_safe(e, et, &file_priv->event_list, link) { @@ -712,6 +711,7 @@ int drm_event_reserve_init(struct drm_device *dev, file_priv->event_space -= e->length; p->event = e; + list_add(&p->pending_link, &file_priv->pending_event_list); p->file_priv = file_priv; /* we *could* pass this in as arg, but everyone uses kfree: */ @@ -736,7 +736,10 @@ void drm_event_cancel_free(struct drm_device *dev, { unsigned long flags; spin_lock_irqsave(&dev->event_lock, flags); - p->file_priv->event_space += p->event->length; + if (p->file_priv) { + p->file_priv->event_space += p->event->length; + list_del(&p->pending_link); + } spin_unlock_irqrestore(&dev->event_lock, flags); p->destroy(p); } @@ -750,11 +753,21 @@ EXPORT_SYMBOL(drm_event_cancel_free); * This function sends the event @e, initialized with drm_event_reserve_init(), * to its associated userspace DRM file. Callers must already hold * dev->event_lock, see drm_send_event() for the unlocked version. + * + * Note that the core will take care of unlinking and disarming events when the + * corresponding DRM file is closed. Drivers need to worry about that and can + * call this function upon completion of the asynchrnous work unconditionally. */ void drm_send_event_locked(struct drm_device *dev, struct drm_pending_event *e) { assert_spin_locked(&dev->event_lock); + if (!e->file_priv) { + e->destroy(e); + return; + } + + list_del(&e->pending_link); list_add_tail(&e->link, &e->file_priv->event_list); wake_up_interruptible(&e->file_priv->event_wait); @@ -769,6 +782,10 @@ EXPORT_SYMBOL(drm_send_event_locked); * This function sends the event @e, initialized with drm_event_reserve_init(), * to its associated userspace DRM file. This function acquires dev->event_lock, * see drm_send_event_locked() for callers which already hold this lock. + * + * Note that the core will take care of unlinking and disarming events when the + * corresponding DRM file is closed. Drivers need to worry about that and can + * call this function upon completion of the asynchrnous work unconditionally. */ void drm_send_event(struct drm_device *dev, struct drm_pending_event *e) { diff --git a/include/drm/drmP.h b/include/drm/drmP.h index ae73abf5c2cf..3d78a7406d54 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -283,6 +283,7 @@ struct drm_ioctl_desc { struct drm_pending_event { struct drm_event *event; struct list_head link; + struct list_head pending_link; struct drm_file *file_priv; pid_t pid; /* pid of requester, no guarantee it's valid by the time we deliver the event, for tracing only */ @@ -346,6 +347,7 @@ struct drm_file { struct list_head blobs; wait_queue_head_t event_wait; + struct list_head pending_event_list; struct list_head event_list; int event_space;