From patchwork Wed Sep 4 20:29:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 11131577 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A6AF91395 for ; Wed, 4 Sep 2019 20:29:44 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8E8B221726 for ; Wed, 4 Sep 2019 20:29:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E8B221726 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=poorly.run Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6BE568982C; Wed, 4 Sep 2019 20:29:42 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yw1-xc42.google.com (mail-yw1-xc42.google.com [IPv6:2607:f8b0:4864:20::c42]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9E7CA89623 for ; Wed, 4 Sep 2019 20:29:40 +0000 (UTC) Received: by mail-yw1-xc42.google.com with SMTP id n126so7855200ywf.1 for ; Wed, 04 Sep 2019 13:29:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8GtbizlkMPrZXUURKhwXVzGIR9K6zwzCUzTAta15LT4=; b=BThvg6hI+baASqPCcC3qvhmcf4VKxw2VjTUF7oGBYpdqKyMvbMIEdB1dmYbey30V/R pWaotOuEeMsIGdeVnvDOFfgoXdQTAq3daDwttvkPjjq//QtbFqYIjf4nTnP8bVs7sFPZ s64D6D7gx9V7KrCdV76mzf7+yMp5z/Ut51yZ/Pn9Aic5CiQFQQfv9FkoaeuGHkf4kC9H KSkcA4hixlKPXv0/Qh+El48g/NLnyiuEfjWeryVpqEzyRQ1K7BmrzPu7QD3r5hqXPsk/ nXVpeX98t5ivrpmOdWRLOfI7Aki1OmaRd37+dp8Y2DWkz+i7UjTQ2hnQ+QNbJO9xaEyF f6Lw== X-Gm-Message-State: APjAAAWRCdjfLUw5ko1+NkeB2fflGAQuqxaWzUFbBL0xIGJcCFJIT8O8 vzmV65n92BNvqsFWKzSnBeOW8a1xsL8fig== X-Google-Smtp-Source: APXvYqzVzAqe0E9A0gTrZGdq7KqWNEa/VHDLOQmWN98uN10FARcUPQTpZMY9ST8qYTYl/d2DXXAApw== X-Received: by 2002:a81:7046:: with SMTP id l67mr7393356ywc.253.1567628979608; Wed, 04 Sep 2019 13:29:39 -0700 (PDT) Received: from rosewood.cam.corp.google.com ([2620:0:1013:11:89c6:2139:5435:371d]) by smtp.gmail.com with ESMTPSA id z137sm1944393ywd.18.2019.09.04.13.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2019 13:29:39 -0700 (PDT) From: Sean Paul To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm: damage_helper: Fix race checking plane->state->fb Date: Wed, 4 Sep 2019 16:29:13 -0400 Message-Id: <20190904202938.110207-1-sean@poorly.run> X-Mailer: git-send-email 2.23.0.187.g17f5b7556c-goog MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=poorly.run; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8GtbizlkMPrZXUURKhwXVzGIR9K6zwzCUzTAta15LT4=; b=LV1epChq+XeeoVIIhc5b8513dZ1Zaf5mhdGuMY6vqmzkhclsDa1eGolRtdkXM05Aor w27i24ss9e34HGiNmSXw9xlXVWFa7L7bS55caQXhF5SNwIW4bigdsPmUmi5ZszvwtQhp 2DclMTptrrcpuzJPkjqnWOLwZmyQ80dlQYlImQFvFGdAol6unqCvrwteSpvTrjOS84k9 HpVoUr+OnIUpIkpUvmMYDBTkxWCaxOirHuVTISnl26naDe9SPyYJDD7Rv1DhrdzErEQG pQc6wBcNy+/NokXcc6+ftNYqeoI1IKfdq6/V0nR5/l+IQHzvLx/dIPIc2rQfLl0kkppk 6HmQ== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Hellstrom , Maxime Ripard , Daniel Vetter , stable@vger.kernel.org, David Airlie , Sean Paul , Deepak Rawat , Sean Paul Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Sean Paul Since the dirtyfb ioctl doesn't give us any hints as to which plane is scanning out the fb it's marking as damaged, we need to loop through planes to find it. Currently we just reach into plane state and check, but that can race with another commit changing the fb out from under us. This patch locks the plane before checking the fb and will release the lock if the plane is not displaying the dirty fb. Fixes: b9fc5e01d1ce ("drm: Add helper to implement legacy dirtyfb") Cc: Rob Clark Cc: Deepak Rawat Cc: Daniel Vetter Cc: Thomas Hellstrom Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Sean Paul Cc: David Airlie Cc: Daniel Vetter Cc: dri-devel@lists.freedesktop.org Cc: # v5.0+ Reported-by: Daniel Vetter Signed-off-by: Sean Paul --- drivers/gpu/drm/drm_damage_helper.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_damage_helper.c b/drivers/gpu/drm/drm_damage_helper.c index 8230dac01a89..3a4126dc2520 100644 --- a/drivers/gpu/drm/drm_damage_helper.c +++ b/drivers/gpu/drm/drm_damage_helper.c @@ -212,8 +212,14 @@ int drm_atomic_helper_dirtyfb(struct drm_framebuffer *fb, drm_for_each_plane(plane, fb->dev) { struct drm_plane_state *plane_state; - if (plane->state->fb != fb) + ret = drm_modeset_lock(&plane->mutex, state->acquire_ctx); + if (ret) + goto out; + + if (plane->state->fb != fb) { + drm_modeset_unlock(&plane->mutex); continue; + } plane_state = drm_atomic_get_plane_state(state, plane); if (IS_ERR(plane_state)) {