Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp262879img; Mon, 18 Mar 2019 02:33:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqzmF6Pwvbh0jZ2ZXOZ66I2oZ2jGAxtzgggV2M4icE/WzmWHMHA2iKanPg/+ifU9O4bQiL3X X-Received: by 2002:a17:902:8a84:: with SMTP id p4mr18675171plo.2.1552901589184; Mon, 18 Mar 2019 02:33:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552901589; cv=none; d=google.com; s=arc-20160816; b=Fdm3JJRG1OZiypXMRca5ei2iPUf2XHxUlNd++QG7S7WxhOQDs2iF/pB0aFRwEP0D0m 01dgjM7VxFbMeuPDcRA9gNzcGkWZZgKvQleLvQ1dJ0Lxt89FwfQ0pTLgHhXQuUceBxBN 9/HFzLimdgmuU9QAr5hwpp+9lfZ8Lblmm9SVJMc4hzqQWgamsMtwF3oALgQwHQP1ZAqP yZyqFIQbs6eDME8PfB+1+PvroADKtjKlTzDau/zeEtL5dUfKs4Ev+xltbu3OSKX19kr+ peewbquP+CLD2koZmVra9TnuGEVHIdrb7oyebOGnjFBgbMBhPauOxZtxDZ6NukmtmtxU rafQ== 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=jc684B+2bugeuJKzcApOyrSiMRruHdjbwVdXMPBemec=; b=NI6TOiT7ABCetjYugqtQBm9EYLVteAFMITewSdJcQoPZSH4hCNNoKjgDFkWupUi7T7 DNk3TFOCJbW/0zsgwLeIumanKE9zmzU9Z64fT23nGpHXzicJcK5Pe+7u6z+dRZ2mFTlk ULcCZoZ5Rn3bfQMFmP5Zdts6prT9kejiB32m1frLUGgNpbdc4xNhQRfgF/qrtwyXd7RN 8XV6xXQnXUxDYxY8naJoDlvexrJPgNCqevQmwdj/3Qt44fyqoH9GDy5H1XpeDqR+Bc4O EkWASLyXWp0Yge6+6JIFfvN7wTlAKVtGYoQgQ9A2bK/+/SP1ZsJkyjZ1PIaGAo2tSULY YrRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="fLxl5x+/"; 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 w10si8836241plp.329.2019.03.18.02.32.54; Mon, 18 Mar 2019 02:33:09 -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="fLxl5x+/"; 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 S1728574AbfCRJb3 (ORCPT + 99 others); Mon, 18 Mar 2019 05:31:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:39060 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728561AbfCRJb1 (ORCPT ); Mon, 18 Mar 2019 05:31:27 -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 73911214D8; Mon, 18 Mar 2019 09:31:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552901486; bh=4swZMurOngnFHGK1i+NdGOhHlG+VSonNOrfx2qukzQk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fLxl5x+/tLh1oPwzyC4Ath8k5qjkjR3eCcOFNlOWMtmWj8aOYKsAktmQRoVU1rvqE RCQDbRTnQVBh7Vb/bS8dT6nMi59YioyAqzBQpl29SRW2ruO+c/EDVOmN+uj3nciAtD lgUHq7H/Mu1mznweF/Oc8xarA7igsR5aM75nmYgc= 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.20 51/52] drm: Block fb changes for async plane updates Date: Mon, 18 Mar 2019 10:25:38 +0100 Message-Id: <20190318083849.888924293@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190318083843.398913295@linuxfoundation.org> References: <20190318083843.398913295@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.20-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 @@ -1593,6 +1593,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;