From patchwork Fri May 6 08:03:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 9029911 Return-Path: X-Original-To: patchwork-linux-samsung-soc@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 90FFC9F39D for ; Fri, 6 May 2016 08:03:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 93EDF20382 for ; Fri, 6 May 2016 08:03:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7DCDA2037F for ; Fri, 6 May 2016 08:03:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757968AbcEFID2 (ORCPT ); Fri, 6 May 2016 04:03:28 -0400 Received: from mailout1.w1.samsung.com ([210.118.77.11]:60333 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757870AbcEFIDY (ORCPT ); Fri, 6 May 2016 04:03:24 -0400 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O6Q00H8SX1L3790@mailout1.w1.samsung.com> for linux-samsung-soc@vger.kernel.org; Fri, 06 May 2016 09:03:21 +0100 (BST) X-AuditID: cbfec7f4-f796c6d000001486-bc-572c4fc929ec Received: from eusync3.samsung.com ( [203.254.199.213]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id FE.57.05254.9CF4C275; Fri, 6 May 2016 09:03:21 +0100 (BST) Received: from amdc1061.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 <0O6Q00J4PX1KL340@eusync3.samsung.com>; Fri, 06 May 2016 09:03:21 +0100 (BST) From: Andrzej Hajda To: tjakobi@math.uni-bielefeld.de Cc: Andrzej Hajda , Bartlomiej Zolnierkiewicz , Marek Szyprowski , dri-devel@lists.freedesktop.org, linux-samsung-soc@vger.kernel.org, inki.dae@samsung.com Subject: [RFC PATCH] drm/exynos: fix pending update handling Date: Fri, 06 May 2016 10:03:03 +0200 Message-id: <1462521783-4723-1-git-send-email-a.hajda@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <572C4C65.4070501@math.uni-bielefeld.de> References: <572C4C65.4070501@math.uni-bielefeld.de> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplluLIzCtJLcpLzFFi42I5/e/4Vd2T/jrhBtO3c1vcWneO1WLjjPWs Fle+vmezmHR/AovFjPP7mCzWHrnLbtG2+gOrA7vH/e7jTB7/jrF79G1ZxejxeZNcAEsUl01K ak5mWWqRvl0CV8aLvn9sBau1KibefcfYwPhKuYuRk0NCwERizuRf7BC2mMSFe+vZuhi5OIQE ljJKtOy/zgLhNDFJ9ExawwJSxSagKfF38002EFtEQFHi2M0OJhCbWeAVo0TjDSUQW1jARmLN xr2MIDaLgKrEi6d9YBt4BZwkJs04zgaxTU7i5LHJrCA2p4CpxJkzD4DmcwAtM5FY3eI8gZF3 ASPDKkbR1NLkguKk9FxDveLE3OLSvHS95PzcTYyQQPqyg3HxMatDjAIcjEo8vBkntcOFWBPL iitzDzFKcDArifDu8tUJF+JNSaysSi3Kjy8qzUktPsQozcGiJM47d9f7ECGB9MSS1OzU1ILU IpgsEwenVAOjYLtzocKDqsfnWkRn75yzhG3utoO3i7zPzrmy8qhax6TXVlcspM6/qNkldeb9 FPfFvAniyq3b7gd+2D0ncn91X4hVjLFxxKfvTrlPOORONL2/6V98/Q1vqrPjqeLWuhtr8j/L nVZ/cu6UZdKmwyv3Ho/X2ubD9rHu3TLDhWs190p/1n77sXOrohJLcUaioRZzUXEiAJgCrt0g AgAA Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Spam-Status: No, score=-9.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 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 --- Hi Tobias, This is a quick/dirty patch just for checking if it solves your issue. Successfully tested on decon5433/dsi/i80 path. Please verify if it helps in your case. The patch is based on exynos-drm-next and "drm/exynos: fix cancel page flip code" [1]. [1]: http://permalink.gmane.org/gmane.linux.kernel.samsung-soc/53801 Regards Andrzej --- 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 0281b30..cc96e85 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 561925f..0bb3766 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_drv.h +++ b/drivers/gpu/drm/exynos/exynos_drm_drv.h @@ -174,8 +174,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;