From patchwork Fri Sep 23 08:15:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 9347697 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ABCF8601C2 for ; Fri, 23 Sep 2016 08:15:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CE3129F34 for ; Fri, 23 Sep 2016 08:15:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9147329F56; Fri, 23 Sep 2016 08:15:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1039729F34 for ; Fri, 23 Sep 2016 08:15:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965414AbcIWIPz (ORCPT ); Fri, 23 Sep 2016 04:15:55 -0400 Received: from mailout3.w1.samsung.com ([210.118.77.13]:53098 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965416AbcIWIPs (ORCPT ); Fri, 23 Sep 2016 04:15:48 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0ODY00CKB6YAZ720@mailout3.w1.samsung.com> for linux-samsung-soc@vger.kernel.org; Fri, 23 Sep 2016 09:15:46 +0100 (BST) Received: from eusmges4.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20160923081545eucas1p1ba0c68fee3fcfd95386189dc93540e5b~25cEMAUi00692406924eucas1p1-; Fri, 23 Sep 2016 08:15:45 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges4.samsung.com (EUCPMTA) with SMTP id 12.DB.28332.1B4E4E75; Fri, 23 Sep 2016 09:15:45 +0100 (BST) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20160923081544eucas1p1a734de81448b36af65196f982bee5e27~25cDm91b80827808278eucas1p1U; Fri, 23 Sep 2016 08:15:44 +0000 (GMT) X-AuditID: cbfec7f4-f791c6d000006eac-d6-57e4e4b15327 Received: from eusync3.samsung.com ( [203.254.199.213]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 2A.D5.07726.A84E4E75; Fri, 23 Sep 2016 09:15:06 +0100 (BST) Received: from AMDC2768.digital.local ([106.116.147.88]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0ODY00KL06XWOSA0@eusync3.samsung.com>; Fri, 23 Sep 2016 09:15:44 +0100 (BST) From: Andrzej Hajda To: Inki Dae Cc: Andrzej Hajda , Bartlomiej Zolnierkiewicz , Marek Szyprowski , dri-devel@lists.freedesktop.org, linux-samsung-soc@vger.kernel.org, Daniel Vetter , Tobias Jakobi Subject: [PATCH 2/2] drm/exynos: fix pending update handling Date: Fri, 23 Sep 2016 10:15:24 +0200 Message-id: <1474618524-8916-3-git-send-email-a.hajda@samsung.com> X-Mailer: git-send-email 2.7.4 In-reply-to: <1474618524-8916-1-git-send-email-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrDIsWRmVeSWpSXmKPExsWy7djPc7obnzwJN7iyitni1rpzrBYbZ6xn tVj48C6zxZWv79ksJt2fwGIx4/w+Jou1R+6yW7St/sDqwOGx99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3MXICmWISF+6tZwOx hQSWMEq8+x3YxcgFZDcxSdxcMY0ZJMEmoCnxd/NNsCIRAWWJVfva2UGKmAXWMknMannBCDJU WMBGYskWB5AaFgFViaObehlBbF4BJ4lNl66yQyyTk7h5rhNsJqeAs8SWjk+MEIudJM5ee8w8 gZF3ASPDKkaR1NLi3PTcYkO94sTc4tK8dL3k/NxNjMCA3nbs5+YdjJc2Bh9iFOBgVOLh7Xj4 OFyINbGsuDL3EKMEB7OSCO+sh0/ChXhTEiurUovy44tKc1KLDzGaAh01kVlKNDkfGG15JfGG JobmloZGxhYW5kZGSuK8JR+uhAsJpCeWpGanphakFsH0MXFwSjUwMl8+Hqa1bNW3+dMbUvjm T5WwFoj69HbyYbWOncdPvNimpt3VPVs+6ce5uR6bqr831YjUddT+i3+llz3nd7zbN7sZa6XF b98Q0lJXv5cboeP8wP91xoMpATEhxVxRcW8Wn4tc75rVqaZiv6vthWJ1zpJrfIp3rfIyfE6w ZF1ysFycmuxW8cFfiaU4I9FQi7moOBEApgakyn4CAAA= X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20160923081544eucas1p1a734de81448b36af65196f982bee5e27 X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 X-Local-Sender: =?UTF-8?B?QW5kcnplaiBIYWpkYRtTUlBPTC1LZXJuZWwgKFRQKRvsgrw=?= =?UTF-8?B?7ISx7KCE7J6QG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Global-Sender: =?UTF-8?B?QW5kcnplaiBIYWpkYRtTUlBPTC1LZXJuZWwgKFRQKRtTYW1z?= =?UTF-8?B?dW5nIEVsZWN0cm9uaWNzG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTI=?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20160923081544eucas1p1a734de81448b36af65196f982bee5e27 X-RootMTR: 20160923081544eucas1p1a734de81448b36af65196f982bee5e27 References: <1474618524-8916-1-git-send-email-a.hajda@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Exynos DRM devices update their registers at vblank time. Exynos-DRM uses custom mechanism to wait for vblank. This mechanism is error prone - variables are not updated atomically. As a result in certain circumstances user space can try to free buffers which are still in use by hardware, in such cases IOMMU can throw OOPS. The patch instead of fixing the mechanism replaces it with drm core helper. Signed-off-by: Andrzej Hajda Reviewed-by: Gustavo Padovan --- drivers/gpu/drm/exynos/exynos_drm_crtc.c | 16 +----------- drivers/gpu/drm/exynos/exynos_drm_drv.c | 44 +------------------------------- drivers/gpu/drm/exynos/exynos_drm_drv.h | 2 -- 3 files changed, 2 insertions(+), 60 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_crtc.c b/drivers/gpu/drm/exynos/exynos_drm_crtc.c index 785ffa6..5b6845b 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_crtc.c +++ b/drivers/gpu/drm/exynos/exynos_drm_crtc.c @@ -134,8 +134,6 @@ struct exynos_drm_crtc *exynos_drm_crtc_create(struct drm_device *drm_dev, exynos_crtc->ops = ops; exynos_crtc->ctx = ctx; - init_waitqueue_head(&exynos_crtc->wait_update); - crtc = &exynos_crtc->base; private->crtc[pipe] = crtc; @@ -175,13 +173,6 @@ void exynos_drm_crtc_disable_vblank(struct drm_device *dev, unsigned int pipe) exynos_crtc->ops->disable_vblank(exynos_crtc); } -void exynos_drm_crtc_wait_pending_update(struct exynos_drm_crtc *exynos_crtc) -{ - wait_event_timeout(exynos_crtc->wait_update, - (atomic_read(&exynos_crtc->pending_update) == 0), - msecs_to_jiffies(50)); -} - void exynos_drm_crtc_finish_update(struct exynos_drm_crtc *exynos_crtc, struct exynos_drm_plane *exynos_plane) { @@ -190,9 +181,6 @@ void exynos_drm_crtc_finish_update(struct exynos_drm_crtc *exynos_crtc, exynos_plane->pending_fb = NULL; - if (atomic_dec_and_test(&exynos_crtc->pending_update)) - wake_up(&exynos_crtc->wait_update); - spin_lock_irqsave(&crtc->dev->event_lock, flags); if (exynos_crtc->event) drm_crtc_send_vblank_event(crtc, exynos_crtc->event); @@ -235,10 +223,8 @@ void exynos_drm_crtc_cancel_page_flip(struct drm_crtc *crtc, spin_lock_irqsave(&crtc->dev->event_lock, flags); e = exynos_crtc->event; - if (e && e->base.file_priv == file) { + if (e && e->base.file_priv == file) exynos_crtc->event = NULL; - atomic_dec(&exynos_crtc->pending_update); - } spin_unlock_irqrestore(&crtc->dev->event_lock, flags); diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.c b/drivers/gpu/drm/exynos/exynos_drm_drv.c index 877d2efa..a1bc13f 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_drv.c +++ b/drivers/gpu/drm/exynos/exynos_drm_drv.c @@ -45,37 +45,11 @@ struct exynos_atomic_commit { u32 crtcs; }; -static void exynos_atomic_wait_for_commit(struct drm_atomic_state *state) -{ - struct drm_crtc_state *crtc_state; - struct drm_crtc *crtc; - int i, ret; - - for_each_crtc_in_state(state, crtc, crtc_state, i) { - struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); - - if (!crtc->state->enable) - continue; - - ret = drm_crtc_vblank_get(crtc); - if (ret) - continue; - - exynos_drm_crtc_wait_pending_update(exynos_crtc); - drm_crtc_vblank_put(crtc); - } -} - static void exynos_atomic_commit_complete(struct exynos_atomic_commit *commit) { struct drm_device *dev = commit->dev; struct exynos_drm_private *priv = dev->dev_private; struct drm_atomic_state *state = commit->state; - struct drm_plane *plane; - struct drm_crtc *crtc; - struct drm_plane_state *plane_state; - struct drm_crtc_state *crtc_state; - int i; drm_atomic_helper_commit_modeset_disables(dev, state); @@ -89,25 +63,9 @@ static void exynos_atomic_commit_complete(struct exynos_atomic_commit *commit) * have the relevant clocks enabled to perform the update. */ - for_each_crtc_in_state(state, crtc, crtc_state, i) { - struct exynos_drm_crtc *exynos_crtc = to_exynos_crtc(crtc); - - atomic_set(&exynos_crtc->pending_update, 0); - } - - for_each_plane_in_state(state, plane, plane_state, i) { - struct exynos_drm_crtc *exynos_crtc = - to_exynos_crtc(plane->crtc); - - if (!plane->crtc) - continue; - - atomic_inc(&exynos_crtc->pending_update); - } - drm_atomic_helper_commit_planes(dev, state, false); - exynos_atomic_wait_for_commit(state); + drm_atomic_helper_wait_for_vblanks(dev, state); drm_atomic_helper_cleanup_planes(dev, state); diff --git a/drivers/gpu/drm/exynos/exynos_drm_drv.h b/drivers/gpu/drm/exynos/exynos_drm_drv.h index 7f1a49d..cee3a4c 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_drv.h +++ b/drivers/gpu/drm/exynos/exynos_drm_drv.h @@ -173,8 +173,6 @@ struct exynos_drm_crtc { enum exynos_drm_output_type type; unsigned int pipe; struct drm_pending_vblank_event *event; - wait_queue_head_t wait_update; - atomic_t pending_update; const struct exynos_drm_crtc_ops *ops; void *ctx; struct exynos_drm_clk *pipe_clk;