Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp771636ybl; Wed, 11 Dec 2019 07:17:15 -0800 (PST) X-Google-Smtp-Source: APXvYqwyfOk2MrfHVkDDEaFgCLEKAnq7ww1Qj+m6u8YiTft1qiVx40w44zWowG2JWV5VNR7hGpB5 X-Received: by 2002:a05:6830:1141:: with SMTP id x1mr2729619otq.120.1576077435173; Wed, 11 Dec 2019 07:17:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576077435; cv=none; d=google.com; s=arc-20160816; b=An0CzwzOdHV034n2UUw40+ngQ0wlsIbfcZmY2b71tORMPTS27WSxDZTra1j3YKCrEz qMnKsbO81QgiQBK/EwNE18H/kzRHFE4uggGBao/Zne7YIQcat5Nm9OI1V/fEq+t3NlSg tqmKxPKJwBeSe8v2enoV0uXddnsGylJkHm/ypisVQA8W1ljt5eR0OBdpWfiAB7JFGqHN d60Qd4hBYai7pLUjcoEV/nnzW1HRXO51+DRAphbZwEO3WAIgk4t+BB7/BaP/M7bd7S/t sHcFGdUo/DyRdljv3DY8mQrZ+1HpeJcPLIjGjexLLj89vHwZN8WQPN8rBH6MgMvwWQ1Q Psww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vTiA2RqJOhZy3Zl7C9rgeUlqqV5m7EKPYbreN6crcP0=; b=00vwYP4tBUo7Lh0XOhrk3o+pzrhhRNnro2ENRXNn6x4yZSxfYQC4/OWdWtbBuJz4j/ AepPJdl01ysKS4ISzVR5yDfu3x2Z370NeZEN36BnzTsxlZ1aU6WZjmBzhxYTOdrf2fa5 okhp3UARQCbAzzhFlZnINdHhjJQLoGeuyJup4kc/4d3OiPXyXqRG7dWFBCr0d+is5YHQ AnoMXmSbL+zMQBV+PwMvUqMgzQFFNnQ7RokC2SUsWzGg/EeyfRvF286FhDZmWAPs46D1 kLNshQaQLNYhR7qdnOd6hnEs9ITu48LKM5x2WbRc5C+iy1DKzWb64XKYU1fbMGCB/8FK k7sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rD6kgdcr; 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 w131si1355619oif.240.2019.12.11.07.17.03; Wed, 11 Dec 2019 07:17:15 -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=@kernel.org header.s=default header.b=rD6kgdcr; 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 S1731739AbfLKPPR (ORCPT + 99 others); Wed, 11 Dec 2019 10:15:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:38998 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731589AbfLKPOK (ORCPT ); Wed, 11 Dec 2019 10:14:10 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6605320663; Wed, 11 Dec 2019 15:14:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077249; bh=vkqTVeoP7Gmqtk/Duna3R/OH1Tk748TwIhp/xbYauV8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rD6kgdcr9+zaA1vtS7VS+3o/efZdD+d1oPj53uGKkUgBBOE2PEzDJFK6CAqoeBG0O YAevbIdJ7OkeWpP9lw1P4CWSIlFMVVJOPFqh4Pl54p8Op20y1zT3TGOjn6TzRBxf65 Fejw9VMsXyZqA90watdFTg4wP3qrl1gC2Yd1BoSQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rob Clark , Deepak Rawat , Daniel Vetter , Thomas Hellstrom , Maarten Lankhorst , Maxime Ripard , Sean Paul , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, Sean Paul Subject: [PATCH 5.3 073/105] drm: damage_helper: Fix race checking plane->state->fb Date: Wed, 11 Dec 2019 16:06:02 +0100 Message-Id: <20191211150252.259403546@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Paul commit 354c2d310082d1c384213ba76c3757dd3cd8755d upstream. 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 Reviewed-by: Daniel Vetter Signed-off-by: Sean Paul Link: https://patchwork.freedesktop.org/patch/msgid/20190904202938.110207-1-sean@poorly.run Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/drm_damage_helper.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) --- a/drivers/gpu/drm/drm_damage_helper.c +++ b/drivers/gpu/drm/drm_damage_helper.c @@ -212,8 +212,14 @@ retry: 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)) {