Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp272808img; Mon, 18 Mar 2019 02:49:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqxoiQuyBUh0B5u2jpKYZK2skP/hFV0PgVPb/2yvIh7jbZcSZf1MHPNjZktDEJ4lp1PkubT8 X-Received: by 2002:a17:902:3f83:: with SMTP id a3mr18297195pld.6.1552902564125; Mon, 18 Mar 2019 02:49:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552902564; cv=none; d=google.com; s=arc-20160816; b=vuplZdm4oL0tdaXj/itbmnYJQLz+2eYUYg7+QvG9aap9bZrmRDYRhhetso1hGyCfN7 MDVvtwDbwJZ1liu/0xzt9rvUdCQFSPHTzCgT9q7IvJieFXJLHDZ35x+jTcLcBU0jZ42P LfMxuQR/1EWDuDt26vVahbH+7Z260eU3EWu0I1qVt2KPSnW4wZsDzHWZG6yCz2DV6xFg oKwjLODnhVjd5g7ljVOs/iwrddxGIm9uTPZVZkThJzn+2/BcrkjBKIUdQ9b51rU7hQHI 0qVDEFLsS1i0A9DMXJBLvO+khzBkf8aAjX9ggbIjDM92KyMcXceUzZyUVxfwLozlUDJo zhig== 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=8e3O+EyJqIRjlRcfMYOHvbXOSKi0XG01bEH9KVYGc8E=; b=ZWQHYKGyyTRBYyQj2xmH7XILGS/8iDQ3+Sn3JPoeWzXo5WiUks4160h2QPRAiDMx1X I2hhqrpUKqT7Hg0vNxle8SQKr7DY/Ct2aZ6ukaMUznm4cKyOlHnpHVbwirScoh7b+NDF /6eB8E4mQuSzVHeELUQNFmF31UTNoPy55bnHDpzzmXuU1WDBz1/vSvq7Vqo0u3Dziu/I eq+dtrW2hKL7NCMvF5CbBH2Zh0dDGCdg80zoj3IP41J39d5Wf7bb/SZY6Apdmau/0mUh LcYwsEDAYhs5gKaA6+a33XwkpxtYYbl4J3WEfRWjrx2ZC1ik3FFxkebtSlYNInAFgcl5 ELyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=k5DYRlHN; 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.49.09; Mon, 18 Mar 2019 02:49:24 -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=k5DYRlHN; 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 S1728042AbfCRJ2T (ORCPT + 99 others); Mon, 18 Mar 2019 05:28:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:34020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728002AbfCRJ2R (ORCPT ); Mon, 18 Mar 2019 05:28:17 -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 D09162087C; Mon, 18 Mar 2019 09:28:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552901296; bh=YKgmJYI+QrsVfbNJkweYMshig/sNWWhqFXoFItEOeH4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=k5DYRlHN73hGkXYeNwwAfuxHfBk6hGuP9bqNeTqlL3fGrMn2jpqfmgAFW6ExeaTA2 vFh1U1CkWBFdDZ1o25lyQB5MZnbyoogHs4nQIHigFNrGV5Bx0dcTbqNu297a6FBJ7c GeAHY8XAzGy1SswiV5Uy3iqef6AlRPJYszunpHns= 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 5.0 43/43] drm: Block fb changes for async plane updates Date: Mon, 18 Mar 2019 10:24:35 +0100 Message-Id: <20190318083717.135180711@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190318083715.877441740@linuxfoundation.org> References: <20190318083715.877441740@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 5.0-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 @@ -1611,6 +1611,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;