From patchwork Fri Oct 28 09:52:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tretter X-Patchwork-Id: 13023307 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B145EFA3744 for ; Fri, 28 Oct 2022 09:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=LUNBwl5+cOp9/6BcxFTk/iRUVOIPkjmgKAIZybETEMA=; b=C+Ry/PiAXWvoCr 6URJmMp/UGy21wWfX91PlOcLP5mMwIz+PheN2Hctd1C0O5z81Qy1Tb+gIBGRBvpeFhq1kebJbhwcz 2YdXauqEisXs4939J3CBZkBxZBBiB4ISkGpz+kHhlxgD3aiPuRv0NkNm3dj6sEflpUXj5FjHslmka hXainfp5iz8yBYM7izCw6D4uf05krTXN6fwA/soW0phtlXA3kwLyDTtYkT29oHhfRwqcY8+eoz2+l 87zWVQnKdeyliDnSsvrIXaejYzJFg73o+ERudPFb/SYZzRVz7vNPfcA7A4wPnVnkyolcwyq+k9433 xAgO7tg7IiF7MRY+gIBA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ooM4z-00GSa8-S8; Fri, 28 Oct 2022 09:55:09 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ooM2Q-00GRRG-Ny for linux-rockchip@lists.infradead.org; Fri, 28 Oct 2022 09:52:32 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ooM27-0005YW-0C; Fri, 28 Oct 2022 11:52:11 +0200 Received: from [2a0a:edc0:0:1101:1d::54] (helo=dude05.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1ooM24-000s2M-Je; Fri, 28 Oct 2022 11:52:07 +0200 Received: from mtr by dude05.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1ooM22-008xq6-NC; Fri, 28 Oct 2022 11:52:06 +0200 From: Michael Tretter To: dri-devel@lists.freedesktop.org Cc: linux-rockchip@lists.infradead.org, Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , kernel@pengutronix.de, Michael Riesch , linux-arm-kernel@lists.infradead.org, Chris Morgan , Sascha Hauer Subject: [PATCH 1/2] drm/rockchip: vop2: fix null pointer in plane_atomic_disable Date: Fri, 28 Oct 2022 11:52:05 +0200 Message-Id: <20221028095206.2136601-2-m.tretter@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221028095206.2136601-1-m.tretter@pengutronix.de> References: <20221028095206.2136601-1-m.tretter@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: mtr@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-rockchip@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221028_025230_839118_52F4887C X-CRM114-Status: GOOD ( 12.76 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org If the vop2_plane_atomic_disable function is called with NULL as a state, accessing the old_pstate runs into a null pointer exception. However, the drm_atomic_helper_disable_planes_on_crtc function calls the atomic_disable callback with state NULL. Allow to disable a plane without passing a plane state by checking the old_pstate only if a state is passed. Signed-off-by: Michael Tretter --- drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c index aac20be5ac08..26f8a8489ded 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c @@ -996,13 +996,15 @@ static int vop2_plane_atomic_check(struct drm_plane *plane, static void vop2_plane_atomic_disable(struct drm_plane *plane, struct drm_atomic_state *state) { - struct drm_plane_state *old_pstate = drm_atomic_get_old_plane_state(state, plane); + struct drm_plane_state *old_pstate = NULL; struct vop2_win *win = to_vop2_win(plane); struct vop2 *vop2 = win->vop2; drm_dbg(vop2->drm, "%s disable\n", win->data->name); - if (!old_pstate->crtc) + if (state) + old_pstate = drm_atomic_get_old_plane_state(state, plane); + if (old_pstate && !old_pstate->crtc) return; vop2_win_disable(win); From patchwork Fri Oct 28 09:52:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tretter X-Patchwork-Id: 13023306 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 381BCECAAA1 for ; Fri, 28 Oct 2022 09:55:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=gF1MugNfJOQLMqswzLQ+YoxfeHyplRbPvYW/VWctGm0=; b=JE7tQEhJV+IJEZ glm39FljvoQr0mWu7i38F9tv3X4cfl+Wwj1eY+LIoCOaz6cjg2CDeOUM25kECw0IJoppj8J4scYDG 8V0puBR9/L2vibvYUdnNthU8Lz4/ph8SqMu84Gy5TwDZQUyi/1NPqYJjQd5ohaLQPCv+RevTnCr0c 2fQlCreFsAtw/I6XfX+gm2TnKVtAoAYL8mH3RqZBRUA4RYB0RUrvDa32/T3fdV3QmvA89W1SARuCy cIWq3ylNyrSggiVJ6OvS99vxxd63Aew1C/6IUzeNbERvwLQ7+HEjIYorH09/muwfI6IKVmmu2040y HwmVHjYThwNwpuAlSRHA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ooM4w-00GSXu-Po; Fri, 28 Oct 2022 09:55:06 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ooM2J-00GRMs-2K for linux-rockchip@lists.infradead.org; Fri, 28 Oct 2022 09:52:24 +0000 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ooM27-0005YU-0C; Fri, 28 Oct 2022 11:52:11 +0200 Received: from [2a0a:edc0:0:1101:1d::54] (helo=dude05.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1ooM24-000s2G-Al; Fri, 28 Oct 2022 11:52:07 +0200 Received: from mtr by dude05.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1ooM22-008xq9-NT; Fri, 28 Oct 2022 11:52:06 +0200 From: Michael Tretter To: dri-devel@lists.freedesktop.org Cc: linux-rockchip@lists.infradead.org, Sandy Huang , =?utf-8?q?Heiko_St=C3=BCbner?= , kernel@pengutronix.de, Michael Riesch , linux-arm-kernel@lists.infradead.org, Chris Morgan , Sascha Hauer Subject: [PATCH 2/2] drm/rockchip: vop2: disable planes when disabling the crtc Date: Fri, 28 Oct 2022 11:52:06 +0200 Message-Id: <20221028095206.2136601-3-m.tretter@pengutronix.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221028095206.2136601-1-m.tretter@pengutronix.de> References: <20221028095206.2136601-1-m.tretter@pengutronix.de> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: mtr@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-rockchip@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221028_025223_142994_4DB4075B X-CRM114-Status: GOOD ( 12.82 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org The vop2 driver needs to explicitly disable the planes if the crtc is disabled. Unless the planes are explicitly disabled, the address of the last framebuffer is kept in the registers of the VOP2. When re-enabling the encoder after it has been disabled by the driver, the VOP2 will start and read the framebuffer that has been freed but is still pointed to by the register. The iommu will catch these read accesses and print errors. Explicitly disable the planes when the crtc is disabled to reset the registers. Signed-off-by: Michael Tretter --- drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c index 26f8a8489ded..105a548d0abe 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c @@ -877,10 +877,14 @@ static void vop2_crtc_atomic_disable(struct drm_crtc *crtc, { struct vop2_video_port *vp = to_vop2_video_port(crtc); struct vop2 *vop2 = vp->vop2; + struct drm_crtc_state *old_crtc_state; int ret; vop2_lock(vop2); + old_crtc_state = drm_atomic_get_old_crtc_state(state, crtc); + drm_atomic_helper_disable_planes_on_crtc(old_crtc_state, false); + drm_crtc_vblank_off(crtc); /*