Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp10887506imu; Thu, 6 Dec 2018 08:16:57 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vq5wDLjQpec3Zy/AkK2qQufi2Ca8Pqiy80P4FxpeBstMEshgNVC9vPPqbxoMt3bfp1BWun X-Received: by 2002:a62:7e93:: with SMTP id z141mr28569408pfc.239.1544113017661; Thu, 06 Dec 2018 08:16:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544113017; cv=none; d=google.com; s=arc-20160816; b=q07+HuiLlmfL8r5yEDyMnTBz7v42CqRWGlXXqym63LLALFpPN3RkY0AtSnkjDt7bH2 sHObD52bDF+CW9UKJ6uFehj4bhQurGfldC+dTY0GLqOem3meoYlpj38OJRu8ny+4DwPU TCvKrdYz8C3myvjZX5lEzNuL3CMp1OkRgn+h9wap0b73zQUMNgLps3bgihVPzMk4sSps 4ukcJbV67CIDgRtaEkA1LIP3YS3vcepFIuvDvnIi4KCVlg5Y4j8g8jhjEiF50CJU3YM4 gNa0g48aVRKaIu6DHvNwFDduIrADayWZmfZpY1ehcG4PxmFrUJdsOvWaQhFIEaVVupPx rVmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=t09BdzwjWvguY4YKHSIexRTDwMCnh+rppGbPm+alkWw=; b=li47tKs6UsleV6+qhejJBEivtkrsfpwj0ClywLpbdIlrQ7f2/XaiJjJv2Xu3n6LCZf hYKLCVg8j+FMe2nIthmQgSY5/jaFZmLpGhUUpFXr6JmQ8497Qge/cO9dKRhjimqALwXb plAehp6aGGTSq5ExUZMEZSHuEqe5ESKA3RKppBf91UE9cSztowVJQDS+TRLUh3yJ+X88 /pAY5au92EVgVAzG7czOFr6B7ENla1bIIkvSO1cJtHzgN8Ou5ZDRb0qczBnQYSLhXeJi 6bdKCvJI30qrduYy/onp6U4VLC14wB7+qvqylukxvuh+JsSGrS4mMXK3gocVuJ9bByzR bB8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@poorly.run header.s=google header.b=S0Z43LIk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s11si506345pgk.344.2018.12.06.08.16.11; Thu, 06 Dec 2018 08:16:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@poorly.run header.s=google header.b=S0Z43LIk; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726281AbeLFQOd (ORCPT + 99 others); Thu, 6 Dec 2018 11:14:33 -0500 Received: from mail-yb1-f195.google.com ([209.85.219.195]:33443 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725972AbeLFQOd (ORCPT ); Thu, 6 Dec 2018 11:14:33 -0500 Received: by mail-yb1-f195.google.com with SMTP id f125so843530ybc.0 for ; Thu, 06 Dec 2018 08:14:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=poorly.run; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=t09BdzwjWvguY4YKHSIexRTDwMCnh+rppGbPm+alkWw=; b=S0Z43LIk/cYa+e0A9HYsjtezzTaPCKUzgdQO4d8U/kMcaB/eF2hxD92sTzM6nQ9Bkj DYwE0czN0PutNK5bRq2SHC9ZxRRrno+NaY8UunN8T1BXqg4CGSYGLPb4trgu8KP1E6nM pv4/tiPUZbc6Cx8+Hlpl9Wt4067+RNEA3rV7jUHEn0ka6HHyLMWa4rxL4JHdU5wHAglO Sv1RnIsTVzo3E7MlyQRjlJvWj4eO1+dRfQd8xoPeSqFgxHWvgBVbtwzIohWKq7XcjGpb imms3xvbVZDsJ/S2TOTsGrvqK0Q/F8tLuodrMP/mg2kPOCwXsbgGgWTMx1u/0qdayoZT 8Rdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=t09BdzwjWvguY4YKHSIexRTDwMCnh+rppGbPm+alkWw=; b=gRshcrwt0T/BJubcEUW6B5O02H8sUnsSsMW1Rs+CRuG7b5qgsYICEgomNwJuezSWNt jeGHlwpXJ7xQmVgEibq0VP1mqPP1QzqcGUuv+V15WzPtO1zyjITzh2Qz8MNFDmP9dbon wes0B1NfldWa8nspI8CGUZcSgMkhyvQ821zObdMGBeaoaao+/AJnNn0PM9cMHVNa0A25 n6+fcTlVeh0KKLta22XUxhAQoXxwnZ34DK/HADIPk4JF4x9YaAy9LoYl8wglIAkpghDh 8FcSKQcPSah81DM4Mz/kn4POlwi0W1vtJoz0BwgTZlARngJ07V9N4aE/nCPEYuH2Gy+6 u0ig== X-Gm-Message-State: AA+aEWZAbRVk2GiQkgPePLAMxUgZj4yqYbM9M87ADS38AmrMZkzSdCYz YiOjHAvKeUwo62Df7JWYoXS95w== X-Received: by 2002:a5b:d07:: with SMTP id y7-v6mr5525982ybp.385.1544112872110; Thu, 06 Dec 2018 08:14:32 -0800 (PST) Received: from localhost ([2620:0:1013:11:ad55:b1db:adfe:3b9f]) by smtp.gmail.com with ESMTPSA id n16sm564259ywn.31.2018.12.06.08.14.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Dec 2018 08:14:31 -0800 (PST) Date: Thu, 6 Dec 2018 11:14:31 -0500 From: Sean Paul To: Jayant Shekhar Cc: dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, robdclark@gmail.com, seanpaul@chromium.org, hoegsberg@chromium.org, abhinavk@codeaurora.org, jsanka@codeaurora.org, chandanu@codeaurora.org, nganji@codeaurora.org Subject: Re: [DPU PATCH] drm/msm/dpu: Fix vblank refcount mismatch Message-ID: <20181206161431.GA154160@art_vandelay> References: <1544078813-10945-1-git-send-email-jshekhar@codeaurora.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1544078813-10945-1-git-send-email-jshekhar@codeaurora.org> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 06, 2018 at 12:16:53PM +0530, Jayant Shekhar wrote: > _dpu_crtc_vblank_enable_no_lock releases crtc_lock as > its needed for power handle operations. This opens up a > window where in a thread running dpu_crtc_disable and a thread > running dpu_crtc_vblank can race in using dpu_crtc->enabled. Looks like you're using an old kernel. Both power_handle and vblank_enable_no_lock were removed. If you want something more up-to-date for testing, grab the mtp-testing branch from my dpu-staging tree [1] Sean [1]- https://gitlab.freedesktop.org/seanpaul/dpu-staging.git > > dpu_crtc_disable will change the state, where as dpu_crtc_vblank > use the variable. The fix is to cache the crtc enabled state > while holding the lock and use it as a gate in calling > _dpu_crtc_vblank_enable_no_lock. > > This issue was introduced with the commit cf871c48 > (drm/msm/dpu: Remove suspend state tracking from crtc). > > Below are stack traces of thread 1 and thread 2 in good case > and bad case: > > Bad case: > ------------- > Thread 1 > dpu_encoder_phys_vid_control_vblank_irq+0xd0/0x170 > dpu_encoder_register_vblank_callback+0xb8/0x100 > _dpu_crtc_vblank_enable_no_lock+0x240/0x288 > dpu_crtc_disable+0xc4/0x288 > drm_atomic_helper_commit_modeset_disables+0x19c/0x350 > msm_atomic_commit_tail+0x48/0x144 > commit_tail+0x44/0x70 > drm_atomic_helper_commit+0xf0/0xf8 > drm_atomic_commit+0x40/0x4c > drm_mode_atomic_ioctl+0x374/0x90c > drm_ioctl_kernel+0xac/0xec > drm_ioctl+0x218/0x384 > drm_compat_ioctl+0xd8/0xe8 > > Thread 2: > dpu_encoder_phys_vid_control_vblank_irq+0x74/0x170 > dpu_encoder_register_vblank_callback+0xb8/0x100 > _dpu_crtc_vblank_enable_no_lock+0x240/0x288 > dpu_crtc_vblank+0xa8/0x118 > dpu_kms_disable_vblank+0x20/0x2c > vblank_ctrl_worker+0xa0/0xe0 > kthread_worker_fn+0xe4/0x1a4 > kthread+0x11c/0x12c > ret_from_fork+0x10/0x18 > > Good case: > -------------- > Thread 1: > dpu_encoder_phys_vid_control_vblank_irq+0xd0/0x170 > dpu_encoder_phys_vid_irq_control+0xc8/0x110 > _dpu_encoder_irq_control+0x48/0xa0 > _dpu_encoder_resource_control_helper+0xb4/0x10c > dpu_encoder_resource_control+0x4e0/0x664 > dpu_encoder_virt_enable+0xb8/0x120 > dpu_kms_encoder_enable+0x34/0xcc > drm_atomic_helper_commit_modeset_enables+0x120/0x1b8 > msm_atomic_commit_tail+0x5c/0x144 > commit_tail+0x44/0x70 > drm_atomic_helper_commit+0xf0/0xf8 > drm_atomic_commit+0x40/0x4c > drm_mode_atomic_ioctl+0x374/0x90c > > Thread 2: > dpu_crtc_vblank+0xc8/0x118 > dpu_kms_disable_vblank+0x20/0x2c > vblank_ctrl_worker+0xa0/0xe0 > kthread_worker_fn+0xe4/0x1a4 > kthread+0x11c/0x12c > > Signed-off-by: Jayant Shekhar > --- > drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c | 17 ++++++++++++++--- > 1 file changed, 14 insertions(+), 3 deletions(-) > > diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c > index 630cbaa..e81ad8c 100644 > --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c > +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_crtc.c > @@ -877,6 +877,7 @@ static void dpu_crtc_disable(struct drm_crtc *crtc) > struct drm_encoder *encoder; > struct msm_drm_private *priv; > unsigned long flags; > + bool crtc_en; > > if (!crtc || !crtc->dev || !crtc->dev->dev_private || !crtc->state) { > DPU_ERROR("invalid crtc\n"); > @@ -901,11 +902,21 @@ static void dpu_crtc_disable(struct drm_crtc *crtc) > atomic_read(&dpu_crtc->frame_pending)); > > trace_dpu_crtc_disable(DRMID(crtc), false, dpu_crtc); > - if (dpu_crtc->enabled && dpu_crtc->vblank_requested) { > - _dpu_crtc_vblank_enable_no_lock(dpu_crtc, false); > - } > + > + /* > + * Cache vblank enabled before calling _dpu_crtc_vblank_enable_no_lock, > + * because we release crtc_lock inside and acquire it back. While lock > + * is released, there are cases where dpu_crtc_vblank comes in between > + * while disable is going on. dpu_crtc_vblank further calls > + * _dpu_crtc_vblank_enable_no_lock which tries vblank disable again > + * resulting in refcount mismatch. > + */ > + crtc_en = dpu_crtc->enabled; > dpu_crtc->enabled = false; > > + if (crtc_en && dpu_crtc->vblank_requested) > + _dpu_crtc_vblank_enable_no_lock(dpu_crtc, false); > + > if (atomic_read(&dpu_crtc->frame_pending)) { > trace_dpu_crtc_disable_frame_pending(DRMID(crtc), > atomic_read(&dpu_crtc->frame_pending)); > -- > The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, > a Linux Foundation Collaborative Project > -- Sean Paul, Software Engineer, Google / Chromium OS