From patchwork Wed Aug 17 01:11:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 9285069 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 6B192600CB for ; Wed, 17 Aug 2016 01:11:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5BAED287CA for ; Wed, 17 Aug 2016 01:11:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F4E4287CE; Wed, 17 Aug 2016 01:11:52 +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 EA219287CA for ; Wed, 17 Aug 2016 01:11:51 +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 1bZpOZ-0003B0-JE; Wed, 17 Aug 2016 01:11:51 +0000 Received: from mail-pf0-x235.google.com ([2607:f8b0:400e:c00::235]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bZpOU-00038A-8t for linux-rockchip@lists.infradead.org; Wed, 17 Aug 2016 01:11:47 +0000 Received: by mail-pf0-x235.google.com with SMTP id p64so32664590pfb.1 for ; Tue, 16 Aug 2016 18:11:25 -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=Tm7daSKZj+NXepW9Mov6BhJS/EnegM2WRwaeT6WOJTo=; b=M+CMOXPRQyo1f/jsXdsDec24/EpNkNUQvh7k7HIchqwagalyCQJw4zTmNriLUmBp28 vFnT8afacAVo4f2Hog/YSIMwHdtN5wFaOB/K+5pSwajgQ84n2bEpED4nLI+7eLUivh3o FAw9l/5p1+HWwtu8SF05KkTzZMHgNgzwpF/f8= 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=Tm7daSKZj+NXepW9Mov6BhJS/EnegM2WRwaeT6WOJTo=; b=QLk/8MloHfk1QlysQwCol6+dDad+6KvWI7tYXyEH0Y0GAxBhVt63BrP9bwEVb2TXxt 9F4WBpGb+FszyJ8fmWZhJafT4fkND5jwCXagGqmryqDQ1ErN6T3BxyVyf7KGbIzRA4dQ qFHCs71jBIwEjwn1rxth5hfPdGgscuOJCpUZPjqcc6qsFUR0h9CPBlEoDx8W0qY6ZOxw pXNlfCfi682//HntCFyXxR0C6NrNj86etVChQWWvv+trYZ4SoFgIBvCk35T5qKj8g7IP Ao36oZKe6u3eG0+Khj0HwvmykkTXfS7YysHQ42XJicDuPjvzNgfQksq4an88DODgmkvK MdtQ== X-Gm-Message-State: AEkoouuf7RZfDUdZrCMYLvbBO/O8Swc9IMBRCXsPwjcRznxnSQQKsxwOw+crqpwjlltSLGMe X-Received: by 10.98.35.7 with SMTP id j7mr13749779pfj.39.1471396285160; Tue, 16 Aug 2016 18:11:25 -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.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Aug 2016 18:11:24 -0700 (PDT) From: Sean Paul To: mark.yao@rock-chips.com, dri-devel@lists.freedesktop.org, ykk@rock-chips.com Subject: [PATCH v2 1/6] drm/rockchip: Convert psr_list_mutex to spinlock and use it Date: Tue, 16 Aug 2016 18:11:11 -0700 Message-Id: <1471396276-8222-2-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_181146_413014_84CA9C75 X-CRM114-Status: GOOD ( 13.50 ) 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 This patch converts the psr_list_mutex to a spinlock and locks all access to psr_list to avoid races (however unlikely they were). 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_drv.c | 2 +- drivers/gpu/drm/rockchip/rockchip_drm_drv.h | 2 +- drivers/gpu/drm/rockchip/rockchip_drm_psr.c | 25 ++++++++++++++++++------- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c index b43fe5d9..76eaf1d 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c @@ -157,7 +157,7 @@ static int rockchip_drm_bind(struct device *dev) drm_dev->dev_private = private; INIT_LIST_HEAD(&private->psr_list); - mutex_init(&private->psr_list_mutex); + spin_lock_init(&private->psr_list_lock); drm_mode_config_init(drm_dev); diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h index 9c34c9e..5c69845 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h @@ -63,7 +63,7 @@ struct rockchip_drm_private { struct drm_atomic_state *state; struct list_head psr_list; - struct mutex psr_list_mutex; + spinlock_t psr_list_lock; }; int rockchip_register_crtc_funcs(struct drm_crtc *crtc, diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_psr.c b/drivers/gpu/drm/rockchip/rockchip_drm_psr.c index a6d3bd25..bd25273 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_psr.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_psr.c @@ -45,12 +45,18 @@ static struct psr_drv *find_psr_by_crtc(struct drm_crtc *crtc) { struct rockchip_drm_private *drm_drv = crtc->dev->dev_private; struct psr_drv *psr; + unsigned long flags; - list_for_each_entry(psr, &drm_drv->psr_list, list) + spin_lock_irqsave(&drm_drv->psr_list_lock, flags); + list_for_each_entry(psr, &drm_drv->psr_list, list) { if (psr->encoder->crtc == crtc) - return psr; + goto out; + } + psr = ERR_PTR(-ENODEV); - return ERR_PTR(-ENODEV); +out: + spin_unlock_irqrestore(&drm_drv->psr_list_lock, flags); + return psr; } static void psr_state_work(struct work_struct *work) @@ -173,7 +179,9 @@ void rockchip_drm_psr_flush(struct drm_device *dev) { struct rockchip_drm_private *drm_drv = dev->dev_private; struct psr_drv *psr; + unsigned long flags; + spin_lock_irqsave(&drm_drv->psr_list_lock, flags); list_for_each_entry(psr, &drm_drv->psr_list, list) { if (psr->request_state == PSR_DISABLE) continue; @@ -183,6 +191,7 @@ void rockchip_drm_psr_flush(struct drm_device *dev) psr_set_state(psr, PSR_FLUSH); } + spin_unlock_irqrestore(&drm_drv->psr_list_lock, flags); } EXPORT_SYMBOL(rockchip_drm_psr_flush); @@ -199,6 +208,7 @@ int rockchip_drm_psr_register(struct drm_encoder *encoder, { struct rockchip_drm_private *drm_drv = encoder->dev->dev_private; struct psr_drv *psr; + unsigned long flags; if (!encoder || !psr_set) return -EINVAL; @@ -215,9 +225,9 @@ int rockchip_drm_psr_register(struct drm_encoder *encoder, psr->encoder = encoder; psr->set = psr_set; - mutex_lock(&drm_drv->psr_list_mutex); + spin_lock_irqsave(&drm_drv->psr_list_lock, flags); list_add_tail(&psr->list, &drm_drv->psr_list); - mutex_unlock(&drm_drv->psr_list_mutex); + spin_unlock_irqrestore(&drm_drv->psr_list_lock, flags); return 0; } @@ -235,8 +245,9 @@ void rockchip_drm_psr_unregister(struct drm_encoder *encoder) { struct rockchip_drm_private *drm_drv = encoder->dev->dev_private; struct psr_drv *psr, *n; + unsigned long flags; - mutex_lock(&drm_drv->psr_list_mutex); + spin_lock_irqsave(&drm_drv->psr_list_lock, flags); list_for_each_entry_safe(psr, n, &drm_drv->psr_list, list) { if (psr->encoder == encoder) { del_timer(&psr->flush_timer); @@ -244,6 +255,6 @@ void rockchip_drm_psr_unregister(struct drm_encoder *encoder) kfree(psr); } } - mutex_unlock(&drm_drv->psr_list_mutex); + spin_unlock_irqrestore(&drm_drv->psr_list_lock, flags); } EXPORT_SYMBOL(rockchip_drm_psr_unregister);