From patchwork Thu Mar 16 23:47:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9629447 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 3AE1460132 for ; Thu, 16 Mar 2017 23:47:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28C0628665 for ; Thu, 16 Mar 2017 23:47:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A1D72867F; Thu, 16 Mar 2017 23:47:57 +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 843F228665 for ; Thu, 16 Mar 2017 23:47:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C61F36EC39; Thu, 16 Mar 2017 23:47:54 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr0-x244.google.com (mail-wr0-x244.google.com [IPv6:2a00:1450:400c:c0c::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id B4CEE6EC38; Thu, 16 Mar 2017 23:47:53 +0000 (UTC) Received: by mail-wr0-x244.google.com with SMTP id u108so7713148wrb.2; Thu, 16 Mar 2017 16:47:53 -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=UNX8aorLAcoef6gP95P0ZGseLkSj9DR12wm5F8IpmF0=; b=KAafVBeRtiZSH5hxU4ckR1uzDArMmPFBB6rWsL5Cxifn7G4YS38lvOVCYeVyFRZ13I GLzSNYpwYx2SNOTVEla6Us5zw7eFSDoR40aQeRM/VBebJYINs3kwWTlAVpAWNxAWrcuY DaCd3YBTLdP8nNriitr1en9jKON+ITveex/OA+44qOBR+RaBMXnWl576IkLQG03apva9 bap8FwweIAQVLipsGIblYus++ROL6rh7E7pM/RoS5+9alrr29CSMbdGlFY/E/tYERosq IZfDYcDT1+QdZMswQP4NevSAGhPQGBPixkSluadxRA1w0H64kv3yfE1T5G5ebdw/eZCF 7K8Q== 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=UNX8aorLAcoef6gP95P0ZGseLkSj9DR12wm5F8IpmF0=; b=GITBXM0xKU30bWtcRBMMTy64bedrUmuCI2fX/PY/A3lGqJiqB4cBZu29jCrWBInJGf 1p7quyKKgflh4AQLKxpwNVsR50gDxzDZfjzMj+ZDnI/JYfu3YY9w5/KFpZEnqk1boTuV PPfzaCxTIj13mHeo+eweBg5ZnvRagoRMEYQvJSHAf4lhG6+LOeGaseYUd7x4np69Dwzm 8z/TuSbxSRn4M16qOUMwc1vfdw0TofzYoe8qPWE6TAYnfwQtEoaRvd1znAV4del22HDl uXGgtusqE5uvfk0UFvpdhmqcE8X5HjwazrSZHOavn2MVU2etmM7B+zB2aA9+6vjcsUuR KZ6Q== X-Gm-Message-State: AFeK/H3sRlCoTLQ4RiAkMzuWxlwpxIvpwSM+QCesakq1kjwD582d77WGKw+2Com4hu2C8g== X-Received: by 10.223.177.148 with SMTP id q20mr10582525wra.154.1489708072209; Thu, 16 Mar 2017 16:47:52 -0700 (PDT) Received: from haswell.alporthouse.com ([78.156.65.138]) by smtp.gmail.com with ESMTPSA id r2sm616684wmb.26.2017.03.16.16.47.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 Mar 2017 16:47:51 -0700 (PDT) From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] drm: Mark up accesses of vblank->enabled outside of its spinlock Date: Thu, 16 Mar 2017 23:47:48 +0000 Message-Id: <20170316234749.1297-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. Signed-off-by: Chris Wilson Cc: Ville Syrjälä Cc: Daniel Vetter --- drivers/gpu/drm/drm_irq.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c index 53a526c7b24d..4cc9352ab6a8 100644 --- a/drivers/gpu/drm/drm_irq.c +++ b/drivers/gpu/drm/drm_irq.c @@ -336,10 +336,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 @@ -360,7 +358,7 @@ static void vblank_disable_fn(unsigned long arg) unsigned long irqflags; spin_lock_irqsave(&dev->vbl_lock, irqflags); - if (atomic_read(&vblank->refcount) == 0 && vblank->enabled) { + if (atomic_read(&vblank->refcount) == 0 && READ_ONCE(vblank->enabled)) { DRM_DEBUG("disabling vblank on crtc %u\n", pipe); vblank_disable_and_save(dev, pipe); } @@ -384,7 +382,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); @@ -564,7 +562,7 @@ int drm_irq_uninstall(struct drm_device *dev) for (i = 0; i < dev->num_crtcs; i++) { struct drm_vblank_crtc *vblank = &dev->vblank[i]; - if (!vblank->enabled) + if (!READ_ONCE(vblank->enabled)) continue; WARN_ON(drm_core_check_feature(dev, DRIVER_MODESET)); @@ -1105,11 +1103,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); } } @@ -1148,7 +1151,7 @@ static int drm_vblank_get(struct drm_device *dev, unsigned int pipe) if (atomic_add_return(1, &vblank->refcount) == 1) { ret = drm_vblank_enable(dev, pipe); } else { - if (!vblank->enabled) { + if (!READ_ONCE(vblank->enabled)) { atomic_dec(&vblank->refcount); ret = -EINVAL; } @@ -1517,7 +1520,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 +1647,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)); } @@ -1714,6 +1717,9 @@ bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe) if (WARN_ON(pipe >= dev->num_crtcs)) return false; + if (!READ_ONCE(vblank->enabled)) + return false; + spin_lock_irqsave(&dev->event_lock, irqflags); /* Need timestamp lock to prevent concurrent execution with