From patchwork Wed Aug 17 01:11:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 9285073 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 4545C600CB for ; Wed, 17 Aug 2016 01:11:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36D5A287C7 for ; Wed, 17 Aug 2016 01:11:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BCF8287CC; Wed, 17 Aug 2016 01:11: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=-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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D6BF4287C7 for ; Wed, 17 Aug 2016 01:11:55 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bZpOd-0003CO-DJ; Wed, 17 Aug 2016 01:11:55 +0000 Received: from mail-pa0-x231.google.com ([2607:f8b0:400e:c03::231]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bZpOX-00038Y-Aq for linux-rockchip@lists.infradead.org; Wed, 17 Aug 2016 01:11:50 +0000 Received: by mail-pa0-x231.google.com with SMTP id pp5so31233032pac.3 for ; Tue, 16 Aug 2016 18:11:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NDfwdGpDwyvljNjeL5cHERcAgTSFKWibrIg+GhFpg5o=; b=ePJgr0ArqP5ipKqkHBA1s+WNeNpmy+grhEZv0WDkriWmZaTpchFK3yWPeEBeIq/MyO PN3SPOeF5nIbmev3SOH4BOteaTXXvcy77uLjZzvl2PKN/9pzvSgjb6PSUN4aWkrLBwBN Vd2vCZn5MpouSJZBN8V86sJ8MkV7i5dwESHfM= 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=NDfwdGpDwyvljNjeL5cHERcAgTSFKWibrIg+GhFpg5o=; b=gd+tndzTu9H6SPfYrxHVtq3aXWtmGlg/ADSUU2Oi+M0oRv5T1RO0Jjf0XkMDotuqYu HlMdC5ePTveQ8VcIDb2OwU36PAb7ygURye3jxIJX7KAYmP3MiSJP9OfeQYZJly1gfgJc X5a/HLnxRLkXObvGn5px6056afJJVJL6P1a97n5/5oNAoqd6xOa+/D+dwqLdsBwMYTF8 p6Fo6I2DO6higfS5KW8PHuRkNHtIMLqychG0MepyfxH06YkRXrhFOc8xldIiY454eNLC 5WRsbtE4RmEFBVV+F3rSDOUIjVOXgT5umz5kmlb7Q24LkCURhSYjAiPgFk3xlXxR0mI8 +lEA== X-Gm-Message-State: AEkooutU8J5Qi2RHZzbBLkWPgAI0WJwU6kzaQD2G1BGIdWb2yJWkNSD7p9T/ctiqB5ztHyGO X-Received: by 10.66.236.201 with SMTP id uw9mr64387510pac.111.1471396287450; Tue, 16 Aug 2016 18:11:27 -0700 (PDT) Received: from seanpaul0.corp.google.com ([172.22.162.59]) by smtp.gmail.com with ESMTPSA id f6sm42170827pfa.17.2016.08.16.18.11.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Aug 2016 18:11:26 -0700 (PDT) From: Sean Paul To: mark.yao@rock-chips.com, dri-devel@lists.freedesktop.org, ykk@rock-chips.com Subject: [PATCH v2 3/6] drm/rockchip: Use a spinlock to protect psr state Date: Tue, 16 Aug 2016 18:11:13 -0700 Message-Id: <1471396276-8222-4-git-send-email-seanpaul@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1471396276-8222-1-git-send-email-seanpaul@chromium.org> References: <1471396276-8222-1-git-send-email-seanpaul@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160816_181149_463664_10DBD4DF X-CRM114-Status: GOOD ( 12.08 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcheu@chromium.org, Sean Paul , dianders@chromium.org, linux-rockchip@lists.infradead.org MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The handling of psr state is racey, shore that up with a per-psr driver lock. Signed-off-by: Sean Paul Reviewed-by: Yakir Yang --- Changes in v2: - Rebased on https://cgit.freedesktop.org/~seanpaul/dogwood/log/?h=for-next drivers/gpu/drm/rockchip/rockchip_drm_psr.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_psr.c b/drivers/gpu/drm/rockchip/rockchip_drm_psr.c index 4c645d7..5bd54f2 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_psr.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_psr.c @@ -30,6 +30,7 @@ struct psr_drv { struct list_head list; struct drm_encoder *encoder; + spinlock_t lock; enum psr_state state; struct timer_list flush_timer; @@ -55,7 +56,7 @@ out: return psr; } -static void psr_set_state(struct psr_drv *psr, enum psr_state state) +static void psr_set_state_locked(struct psr_drv *psr, enum psr_state state) { /* * Allowed finite state machine: @@ -75,7 +76,6 @@ static void psr_set_state(struct psr_drv *psr, enum psr_state state) if (state == PSR_FLUSH && psr->state == PSR_DISABLE) return; - /* Only wrote in this work, no need lock protection */ psr->state = state; /* Allow but no need hardware change, just need assign the state */ @@ -95,18 +95,28 @@ static void psr_set_state(struct psr_drv *psr, enum psr_state state) } } +static void psr_set_state(struct psr_drv *psr, enum psr_state state) +{ + unsigned long flags; + + spin_lock_irqsave(&psr->lock, flags); + psr_set_state_locked(psr, state); + spin_unlock_irqrestore(&psr->lock, flags); +} + static void psr_flush_handler(unsigned long data) { struct psr_drv *psr = (struct psr_drv *)data; + unsigned long flags; if (!psr) return; /* State changed between flush time, then keep it */ - if (psr->state != PSR_FLUSH) - return; - - psr_set_state(psr, PSR_ENABLE); + spin_lock_irqsave(&psr->lock, flags); + if (psr->state == PSR_FLUSH) + psr_set_state_locked(psr, PSR_ENABLE); + spin_unlock_irqrestore(&psr->lock, flags); } /** @@ -167,9 +177,6 @@ void rockchip_drm_psr_flush(struct drm_device *dev) spin_lock_irqsave(&drm_drv->psr_list_lock, flags); list_for_each_entry(psr, &drm_drv->psr_list, list) { - if (psr->state == PSR_DISABLE) - continue; - mod_timer(&psr->flush_timer, round_jiffies_up(jiffies + PSR_FLUSH_TIMEOUT)); @@ -202,6 +209,7 @@ int rockchip_drm_psr_register(struct drm_encoder *encoder, return -ENOMEM; setup_timer(&psr->flush_timer, psr_flush_handler, (unsigned long)psr); + spin_lock_init(&psr->lock); psr->state = PSR_DISABLE; psr->encoder = encoder;