Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp5850562ybn; Sun, 29 Sep 2019 07:04:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqwTKP0n/+JjwUNSImlqcwOkGBdbQ7/UV3y72yCJX6rGizZExTLBjXTGe3FkccaBB2x/MwVz X-Received: by 2002:a17:906:b804:: with SMTP id dv4mr10459393ejb.243.1569765856783; Sun, 29 Sep 2019 07:04:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569765856; cv=none; d=google.com; s=arc-20160816; b=FwkLVaVQRgtNpmcthB2Ravt6M5qRLIpk4QHg3NpcOpec4cUbaw5B4NghNJgZ45DnXX Q5Whdc+r1FTVFJzjl5vW7yLp+FTs4/JBOa5r+jyjv0xoZUZZeo/FWFE0FYOnnX7C2nfg 2sQLXLFN8ZSBv82svf4f3jUN/oqTOWZ7Rfovetz8eEKVLVaWe5Mme8qAlSD4b6tzoTIO gFcjjEObQDCEwLjxa1f5cBxFyHtdU4O1jvqhuu+sIMMyBK3iRit5STNn2zhELZ3ufmHX 6v9jJF4SgrShsjrJrUaLD+YKRyAJLf0MzoeBVVTx8LkixrDk7YSteCLe2sm6say7D4La ZC5g== 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=fA3YmJTvW3kr0L71TnsYNbCKF4nOGpSqCD+1WsfmzqI=; b=VHO/ZQQ/w4dbZ7taK52Z56KWiIaqGZm2eSmG+sjr6eF0YGooFn85uPMHHRI3aSeOAP 8dHcq3B5pMdHFN4YAiOaskNsvzuWORpCE6K+CWkqEFX2uaTgq1QYEmgjyIHIHqx3kiT2 3jbd3CVGfI1+3Y0ubfTiKz6Jsdi0q+DZX8DMbOWGH1c/X49oY4rY8+mTcdg+vdpd+sqb LepsR0SIXPXTDx1DwkL0Rpluq1cjHppw6S7c5HF/SAzW4S5x50MW5TaKNuofytK0FVlf WNgjmKcg+Eel8ZHN9VCc+GKcpMpu4BpG6B/EmVhr4I7GhODEkwl6vCtcdGFKKn9atgnR 3HpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=u6zHBu9c; 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 l22si4960695edq.174.2019.09.29.07.03.48; Sun, 29 Sep 2019 07:04:16 -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=u6zHBu9c; 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 S1729964AbfI2OBD (ORCPT + 99 others); Sun, 29 Sep 2019 10:01:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:43078 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729954AbfI2OBB (ORCPT ); Sun, 29 Sep 2019 10:01:01 -0400 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 AD6F42082F; Sun, 29 Sep 2019 14:00:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569765660; bh=jZ1ynH8cHoy6h5UeSxVTkPfxVFRyTDW1B9UepsKgozc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u6zHBu9cdpWj6E57NWyOxDmxQ+oqaTrGJh5FvpeaJgBy1nUB/fktMFBJIhnEEQt6r EDpyJW90xb+3RO28igDvqpM3x6YQkYy4tZayeThS8j6OTiDhFNP0e8ZNPvIZcYqszi OHKOz92Xh/84vznIDwPNOkzz+B4r27bFIfN2R/NI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nicholas Kazlauskas , Alex Deucher , David Francis Subject: [PATCH 5.2 08/45] drm/amd/display: Dont replace the dc_state for fast updates Date: Sun, 29 Sep 2019 15:55:36 +0200 Message-Id: <20190929135027.241231535@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190929135024.387033930@linuxfoundation.org> References: <20190929135024.387033930@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: Nicholas Kazlauskas commit bd200d190f45b62c006d1ad0a63eeffd87db7a47 upstream. [Why] DRM private objects have no hw_done/flip_done fencing mechanism on their own and cannot be used to sequence commits accordingly. When issuing commits that don't touch the same set of hardware resources like page-flips on different CRTCs we can run into the issue below because of this: 1. Client requests non-blocking Commit #1, has a new dc_state #1, state is swapped, commit tail is deferred to work queue 2. Client requests non-blocking Commit #2, has a new dc_state #2, state is swapped, commit tail is deferred to work queue 3. Commit #2 work starts, commit tail finishes, atomic state is cleared, dc_state #1 is freed 4. Commit #1 work starts, commit tail encounters null pointer deref on dc_state #1 In order to change the DC state as in the private object we need to ensure that we wait for all outstanding commits to finish and that any other pending commits must wait for the current one to finish as well. We do this for MEDIUM and FULL updates. But not for FAST updates, nor would we want to since it would cause stuttering from the delays. FAST updates that go through dm_determine_update_type_for_commit always create a new dc_state and lock the DRM private object if there are any changed planes. We need the old state to validate, but we don't actually need the new state here. [How] If the commit isn't a full update then the use after free can be resolved by simply discarding the new state entirely and retaining the existing one instead. With this change the sequence above can be reexamined. Commit #2 will still free Commit #1's reference, but before this happens we actually added an additional reference as part of Commit #2. If an update comes in during this that needs to change the dc_state it will need to wait on Commit #1 and Commit #2 to finish. Then it'll swap the state, finish the work in commit tail and drop the last reference on Commit #2's dc_state. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204181 Fixes: 004b3938e637 ("drm/amd/display: Check scaling info when determing update type") Signed-off-by: Nicholas Kazlauskas Acked-by: Alex Deucher Reviewed-by: David Francis Signed-off-by: Alex Deucher Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -6860,6 +6860,29 @@ static int amdgpu_dm_atomic_check(struct ret = -EINVAL; goto fail; } + } else { + /* + * The commit is a fast update. Fast updates shouldn't change + * the DC context, affect global validation, and can have their + * commit work done in parallel with other commits not touching + * the same resource. If we have a new DC context as part of + * the DM atomic state from validation we need to free it and + * retain the existing one instead. + */ + struct dm_atomic_state *new_dm_state, *old_dm_state; + + new_dm_state = dm_atomic_get_new_state(state); + old_dm_state = dm_atomic_get_old_state(state); + + if (new_dm_state && old_dm_state) { + if (new_dm_state->context) + dc_release_state(new_dm_state->context); + + new_dm_state->context = old_dm_state->context; + + if (old_dm_state->context) + dc_retain_state(old_dm_state->context); + } } /* Must be success */