From patchwork Fri Mar 17 20:20:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9631543 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 3945160245 for ; Fri, 17 Mar 2017 20:20:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2C18D285A1 for ; Fri, 17 Mar 2017 20:20:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 207E2285D4; Fri, 17 Mar 2017 20:20:38 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 81C26285A1 for ; Fri, 17 Mar 2017 20:20:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7619A6EDA8; Fri, 17 Mar 2017 20:20:36 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id D8DB86EDA8; Fri, 17 Mar 2017 20:20:34 +0000 (UTC) Received: by mail-wm0-x243.google.com with SMTP id x124so4967117wmf.3; Fri, 17 Mar 2017 13:20:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=0bfs4fW5ADOpapbxwmUI48/EDPaipnyaw4+ZKk4XnGs=; b=JRfWUf9oFFX/nBPH5/D6Ke3FPE69ZDtR83nh9vqM9FCIREvZ4q+vdF7xRiCQh+HrQy QqePKxuNz3na0ud7P8EQyRci+mmLgGsQKpt2/XFFl1zgz4D+yqbBzD+ne5ceP+MdPmLi EUioDlyTB7JB9Wn28HMDXe5ZAabGx40zlttog8ozj2zXQFgx+CeTdzisHwg/OxjkdJ/m aZjabN8WJrjzmZuZQpGCHuX084hE0GgBUSXbz3YT6QuikGYpLl90Bs71BPWI9QTiJfXe 3s8d85CxKZq1iMY1Gdv2cBcJC1ABg5komOLYsorQjMR38tuGqXwGxF7voh4zurgOKlk2 onMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=0bfs4fW5ADOpapbxwmUI48/EDPaipnyaw4+ZKk4XnGs=; b=qx8+OhUqEVOzCW/C3UySP9IEgsBsROC6gTYk2op+00P7bDlRthM/WXFv3QENnhyXPq l85m6ObbO8YswLlTqXGGtv92PWmfD0dsxwKmbSBZa6kTPItGgDGdWvKwDBxITal/0X7s 58ETP0GQHuq9WzcI6MyeQHEhBWWD99GV7YWp5b2sqDWiNJoJVQ+mNfA9gVhY2hegCG+n 0LQDLlE50NuYAfT6Q6qKqgU+ER1eIfOoNmxWZADDurRJJyAxaqU9Eqh7r8jtRGdNWqvn zwsrabCjKl/RTU42cgAzMXHqUuK0GmI3cDls8BlXCdMZSMaVAfjsu1c3Ext7sj7ZVqB+ H2Cw== X-Gm-Message-State: AFeK/H27NivKE6fRW8viEUAHafhLmifFygJKIrxlKbyEuWT/g39dktHCG5Z8dr/f0yq2aQ== X-Received: by 10.28.28.69 with SMTP id c66mr97483wmc.28.1489782033212; Fri, 17 Mar 2017 13:20:33 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id k139sm3829222wmg.11.2017.03.17.13.20.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 17 Mar 2017 13:20:32 -0700 (PDT) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 1/4] drm: Mark up accesses of vblank->enabled outside of its spinlock Date: Fri, 17 Mar 2017 20:20:27 +0000 Message-Id: <20170317202030.24410-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 Cc: Daniel Vetter , intel-gfx@lists.freedesktop.org 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: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Order the update to vblank->enabled after the timestamp is primed so that a concurrent unlocked reader will only see the vblank->enabled with the current timestamp. v2: vblank->enable is guarded by dev->vbl_lock not dev->vblank_time_lock, update the READ_ONCE accordingly. Do not add a READ_ONCE(vblank->enabled) inside the interrupt handler to avoid missing an interrupt whilst racing with enable_vblank() Signed-off-by: Chris Wilson Cc: Ville Syrjälä Cc: Daniel Vetter Reviewed-by: Ville Syrjälä --- drivers/gpu/drm/drm_irq.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c index 53a526c7b24d..c47e07c89136 100644 --- a/drivers/gpu/drm/drm_irq.c +++ b/drivers/gpu/drm/drm_irq.c @@ -325,6 +325,8 @@ static void vblank_disable_and_save(struct drm_device *dev, unsigned int pipe) struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; unsigned long irqflags; + assert_spin_locked(&dev->vbl_lock); + /* Prevent vblank irq processing while disabling vblank irqs, * so no updates of timestamps or count can happen after we've * disabled. Needed to prevent races in case of delayed irq's. @@ -336,10 +338,8 @@ static void vblank_disable_and_save(struct drm_device *dev, unsigned int pipe) * calling the ->disable_vblank() operation in atomic context with the * hardware potentially runtime suspended. */ - if (vblank->enabled) { + if (cmpxchg_relaxed(&vblank->enabled, true, false)) __disable_vblank(dev, pipe); - vblank->enabled = false; - } /* * Always update the count and timestamp to maintain the @@ -384,7 +384,7 @@ void drm_vblank_cleanup(struct drm_device *dev) for (pipe = 0; pipe < dev->num_crtcs; pipe++) { struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; - WARN_ON(vblank->enabled && + WARN_ON(READ_ONCE(vblank->enabled) && drm_core_check_feature(dev, DRIVER_MODESET)); del_timer_sync(&vblank->disable_timer); @@ -1105,11 +1105,16 @@ static int drm_vblank_enable(struct drm_device *dev, unsigned int pipe) */ ret = __enable_vblank(dev, pipe); DRM_DEBUG("enabling vblank on crtc %u, ret: %d\n", pipe, ret); - if (ret) + if (ret) { atomic_dec(&vblank->refcount); - else { - vblank->enabled = true; + } else { drm_update_vblank_count(dev, pipe, 0); + /* drm_update_vblank_count() includes a wmb so we just + * need to ensure that the compiler emits the write + * to mark the vblank as enabled after the call + * to drm_update_vblank_count(). + */ + WRITE_ONCE(vblank->enabled, true); } } @@ -1517,7 +1522,7 @@ static int drm_queue_vblank_event(struct drm_device *dev, unsigned int pipe, * vblank disable, so no need for further locking. The reference from * drm_vblank_get() protects against vblank disable from another source. */ - if (!vblank->enabled) { + if (!READ_ONCE(vblank->enabled)) { ret = -EINVAL; goto err_unlock; } @@ -1644,7 +1649,7 @@ int drm_wait_vblank(struct drm_device *dev, void *data, DRM_WAIT_ON(ret, vblank->queue, 3 * HZ, (((drm_vblank_count(dev, pipe) - vblwait->request.sequence) <= (1 << 23)) || - !vblank->enabled || + !READ_ONCE(vblank->enabled) || !dev->irq_enabled)); }