Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp264973img; Mon, 18 Mar 2019 02:36:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqz661TIjzO9PB9zLQZnHXgVDZwrEjDioB3SKcOxuDNyYkLTgLzSKakbmeeUVajg7y94sFt9 X-Received: by 2002:a65:4981:: with SMTP id r1mr16949814pgs.62.1552901787917; Mon, 18 Mar 2019 02:36:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552901787; cv=none; d=google.com; s=arc-20160816; b=vc8uSxYj+9zo0IoX1DdfFtB4f28g31a22wT3XaaTTSFA3h9Rfv3uj71HSEBWP3ZX8D uqJ0ZN2KuA1mK4Zs1qbleAGQvT+fiNIXfvhEDXsWw43NzGY1Ar4wMrIpwg1Syd2bHXtO KNRm2zsHE24c6pVahHEw+xWGRki4JSMNyzUx0vjJJz2nCs1Z97KdiMTSJ71oSlK+VPjk yWbh/nATrWmE1c4lyq496LpVD8yiKzMQkOh85/YfLnZkiF3+gZaVUr4MLh9VhTilDM4J ZzQvy9vrB+cMDxQyYfQfi1h+UPdb5DtNCxPJzdCCAVNyEB4LH6BRonJrOHprjxHKk3AU qDLg== 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=gT14xiYahxJaMUcAbnh3NFmCUOh++iyNbgYx8PZ+HPE=; b=w1RrKCLiS9oMhMJjPvCZ+S10QWUzC1jz7Tbl0+ayU6Ig0bGUN/8T0pg2Zk9zljoZ60 DX61GBoQRVQ7e28lZ0PHftPIVBxhywVJi7Eb//TOS97NqqRb2zYIIHTjspXcBgVJQjJL 8dcd65eZxP3SYhZj6VOtWfbuGCdjA50I0hJmQ5pYnrEQnwIVNpqOv5LqSOym5Log18tq 5vfMxL/d2S9OQERSrWV6FThk0lYdY+VsBUzIlz0zb9hNXzMATtswQYGZKnC7jXA3Vg+E UTLGO6CvnbIqAhI8fwoMaX2lPHmk7dhHbFPzOXNhogNAGAubzDIiPatvYhY9lD5NH4br gFZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SFLRQtu4; 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 a4si9077527plp.431.2019.03.18.02.36.13; Mon, 18 Mar 2019 02:36:27 -0700 (PDT) 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=SFLRQtu4; 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 S1728572AbfCRJdh (ORCPT + 99 others); Mon, 18 Mar 2019 05:33:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:41888 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727964AbfCRJdf (ORCPT ); Mon, 18 Mar 2019 05:33:35 -0400 Received: from localhost (5356596B.cm-6-7b.dynamic.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 6DBCE21741; Mon, 18 Mar 2019 09:33:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552901613; bh=UTX18t6LRQbGxS8+WD4AwZ7m5iAsIev0DuYibkuINCA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SFLRQtu4Jywt4hfAPTm8w9AjFZZPCa8l16dRU11+yr3Pt5Ss1A0NGisTbbXFktW65 S49gAmOQicHLxKv8LhMFiGipeiNRJ+3Qs8GzeALjUbbkJGTQ95g7ta5GB0ZTdobgdV e/tNrLK0et3njKaNz36jAa3/yLM/Q7JF45RW0trU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Vetter , Harry Wentland , Andrey Grodzovsky , Nicholas Kazlauskas , Daniel Vetter Subject: [PATCH 4.19 49/52] drm: Block fb changes for async plane updates Date: Mon, 18 Mar 2019 10:25:46 +0100 Message-Id: <20190318084019.320907989@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190318084013.532280682@linuxfoundation.org> References: <20190318084013.532280682@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Nicholas Kazlauskas commit 25dc194b34dd5919dd07b8873ee338182e15df9d upstream. The prepare_fb call always happens on new_plane_state. The drm_atomic_helper_cleanup_planes checks to see if plane state pointer has changed when deciding to call cleanup_fb on either the new_plane_state or the old_plane_state. For a non-async atomic commit the state pointer is swapped, so this helper calls prepare_fb on the new_plane_state and cleanup_fb on the old_plane_state. This makes sense, since we want to prepare the framebuffer we are going to use and cleanup the the framebuffer we are no longer using. For the async atomic update helpers this differs. The async atomic update helpers perform in-place updates on the existing state. They call drm_atomic_helper_cleanup_planes but the state pointer is not swapped. This means that prepare_fb is called on the new_plane_state and cleanup_fb is called on the new_plane_state (not the old). In the case where old_plane_state->fb == new_plane_state->fb then there should be no behavioral difference between an async update and a non-async commit. But there are issues that arise when old_plane_state->fb != new_plane_state->fb. The first is that the new_plane_state->fb is immediately cleaned up after it has been prepared, so we're using a fb that we shouldn't be. The second occurs during a sequence of async atomic updates and non-async regular atomic commits. Suppose there are two framebuffers being interleaved in a double-buffering scenario, fb1 and fb2: - Async update, oldfb = NULL, newfb = fb1, prepare fb1, cleanup fb1 - Async update, oldfb = fb1, newfb = fb2, prepare fb2, cleanup fb2 - Non-async commit, oldfb = fb2, newfb = fb1, prepare fb1, cleanup fb2 We call cleanup_fb on fb2 twice in this example scenario, and any further use will result in use-after-free. The simple fix to this problem is to block framebuffer changes in the drm_atomic_helper_async_check function for now. v2: Move check by itself, add a FIXME (Daniel) Cc: Daniel Vetter Cc: Harry Wentland Cc: Andrey Grodzovsky Cc: # v4.14+ Fixes: fef9df8b5945 ("drm/atomic: initial support for asynchronous plane update") Signed-off-by: Nicholas Kazlauskas Acked-by: Andrey Grodzovsky Acked-by: Harry Wentland Reviewed-by: Daniel Vetter Signed-off-by: Harry Wentland Link: https://patchwork.freedesktop.org/patch/275364/ Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/drm_atomic_helper.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -1573,6 +1573,15 @@ int drm_atomic_helper_async_check(struct if (old_plane_state->fb != new_plane_state->fb) return -EINVAL; + /* + * FIXME: Since prepare_fb and cleanup_fb are always called on + * the new_plane_state for async updates we need to block framebuffer + * changes. This prevents use of a fb that's been cleaned up and + * double cleanups from occuring. + */ + if (old_plane_state->fb != new_plane_state->fb) + return -EINVAL; + funcs = plane->helper_private; if (!funcs->atomic_async_update) return -EINVAL;