Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp363870rdh; Thu, 23 Nov 2023 06:07:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IHJChTPnDvVc1PTmWmMpUbdbGynDWdW+NRmUW7OZx2IXcgU0TvuRZDYCOBZElrGDpOGKtgO X-Received: by 2002:a05:6871:e70d:b0:1e9:d158:7e85 with SMTP id qa13-20020a056871e70d00b001e9d1587e85mr7709398oac.30.1700748461465; Thu, 23 Nov 2023 06:07:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700748461; cv=none; d=google.com; s=arc-20160816; b=waxlqtOdy6lKUWZzuW98ynKmWswiJmocPeYf1Mw6QpvJqlL8LLbMNXUF9uTQ50/J3P 2JPMSiteDkO5XAKZzolmnBhLSmrcmmgOv33+xT2SWiFcwWR/WSjQsxGUN714mLlS5utJ C/Gqo+LPJfQKvop5bkxeaHzH4Z5Bd2CmyCOQS2j8YMefYs8TY06TJu4enqsnglM8qR2u URhIOE6GunYp81WsINHefx+Lsf6Tn/z2gGEoI3gOzodrITMcaLZrav2W9DKILK+D5BSo 05+k9cchneQjA1Fcd4n08+9pF0raJWOU6TlmO0bARuee6kxCSUTNJp6gCy/zMORwLI7Q tDGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=1vMmWboDI5QefdzlrHmYNry4lflRg/JUU/kI3pd0qQ4=; fh=IMTs9+7ONabIprSV2QVtAVg9he0mfUDprxRC5rmabdQ=; b=D/evH8PfMmq7w3Q1YUDIS3eLhxFOl84u4WavMvKkJXh6BBNUCLFgeuWIDrTTV9SABm yichyCWHqZwWTP49zr4psNbfF2c/Yq9SeZvSTW93qf8WfMiDSj0MrxVNLVjalMJqeyya 9H0asz7AFU2edJAsbBPczd1u7+3ZQ5xYAtRiSSKzzX2pYNjZSdn/G71ty6PiUdY+7qRM irkdjNWb9tk53W0hRydJODGL2hiyevvurPekMG0Xh11QddwwZXFXV6tdO5iQXB4uqwVt L8eQ8b2mjAdXYqiXetBe2q7GgrfA4VEnUp+qh5QUPjNp+AkPyMvwb2UOOn3ew0l29agT TTnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Ev1tzTd9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id r21-20020a056870179500b001dd87baa505si518658oae.254.2023.11.23.06.07.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 06:07:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Ev1tzTd9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 0C56080789C2; Thu, 23 Nov 2023 06:07:38 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345686AbjKWOHW (ORCPT + 99 others); Thu, 23 Nov 2023 09:07:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345666AbjKWOHU (ORCPT ); Thu, 23 Nov 2023 09:07:20 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C24671B2 for ; Thu, 23 Nov 2023 06:07:25 -0800 (PST) Received: from localhost (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bbrezillon) by madras.collabora.co.uk (Postfix) with ESMTPSA id 83DB666073BF; Thu, 23 Nov 2023 14:07:23 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1700748444; bh=Xh7ItolyIMoAQKYgzvPHx2FNhsLQj3Hwraf4dBbfyHg=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Ev1tzTd9M9Lz6R73YAzrEp8gE0HfO3AypSmzBPqhHhLY5MMmxTaYs8IQVqL28oubd 64tr4x3cfGNRHOJQYWJsjzWc1DhDexbu18ce0GvyUtLNXP5M6HJp686QUf3F3ufdmu 8q+AhHngIj14oV+/cxFOrQi3066FUnQtcmDG+nwidkM7yTr3UTSVpFmWD0aqjlH7Os o1vVj3KoqLlg6Qk74qI4Up8rAxEulyGneapoqu11a/Zwe6fq8Qco08vqKZXqkO02Xw 2fXwwA9U0OkQ9s2C4LdiDqVQ7vdY8N9KS9qoQqxXKgMXvu7SRiTRVi4HadGWBNQ2JL 6iRPOA+2ph4UQ== Date: Thu, 23 Nov 2023 15:07:20 +0100 From: Boris Brezillon To: AngeloGioacchino Del Regno Cc: steven.price@arm.com, robh@kernel.org, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@gmail.com, daniel@ffwll.ch, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, krzysztof.kozlowski@linaro.org Subject: Re: [PATCH v3] drm/panfrost: Ignore core_mask for poweroff and sync interrupts Message-ID: <20231123150720.07f33ada@collabora.com> In-Reply-To: References: <20231123120521.147695-1-angelogioacchino.delregno@collabora.com> <20231123141308.3ba50409@collabora.com> Organization: Collabora X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 23 Nov 2023 06:07:38 -0800 (PST) On Thu, 23 Nov 2023 14:30:08 +0100 AngeloGioacchino Del Regno wrote: > Il 23/11/23 14:13, Boris Brezillon ha scritto: > > On Thu, 23 Nov 2023 13:05:21 +0100 > > AngeloGioacchino Del Regno > > wrote: > > > >> Some SoCs may be equipped with a GPU containing two core groups > >> and this is exactly the case of Samsung's Exynos 5422 featuring > >> an ARM Mali-T628 MP6 GPU: the support for this GPU in Panfrost > >> is partial, as this driver currently supports using only one > >> core group and that's reflected on all parts of it, including > >> the power on (and power off, previously to this patch) function. > >> > >> The issue with this is that even though executing the soft reset > >> operation should power off all cores unconditionally, on at least > >> one platform we're seeing a crash that seems to be happening due > >> to an interrupt firing which may be because we are calling power > >> transition only on the first core group, leaving the second one > >> unchanged, or because ISR execution was pending before entering > >> the panfrost_gpu_power_off() function and executed after powering > >> off the GPU cores, or all of the above. > >> > >> Finally, solve this by introducing a new panfrost_gpu_suspend_irq() > >> helper function and changing the panfrost_device_suspend() flow to > >> 1. Mask and clear all interrupts: we don't need nor want any, as > >> for power_off() we are polling PWRTRANS, but we anyway don't > >> want GPU IRQs to fire while it is suspended/powered off; > >> 2. Call synchronize_irq() after that to make sure that any pending > >> ISR is executed before powering off the GPU Shaders/Tilers/L2 > >> hence avoiding unpowered registers R/W; and > >> 3. Ignore the core_mask and ask the GPU to poweroff both core groups > >> > >> Of course it was also necessary to add a `irq` variable to `struct > >> panfrost_device` as we need to get that in panfrost_gpu_power_off() > >> for calling synchronize_irq() on it. > >> > >> Fixes: 22aa1a209018 ("drm/panfrost: Really power off GPU cores in panfrost_gpu_power_off()") > >> [Regression detected on Odroid HC1, Exynos5422, Mali-T628 MP6] > >> Reported-by: Krzysztof Kozlowski > >> Signed-off-by: AngeloGioacchino Del Regno > >> --- > >> > >> Changes in v3: > >> - Fix compile issue > >> > >> Changes in v2: > >> - Fixed the commit hash of "Really power off [...]" > >> - Actually based on a clean next-20231121 > >> - Renamed "irq" to "gpu_irq" as per Boris' suggestion > >> - Moved the IRQ mask/clear/sync to a helper function and added > >> a call to that in panfrost_device.c instead of doing that in > >> panfrost_gpu_power_off(). > >> > >> NOTE: I didn't split 1+2 from 3 as suggested by Boris, and I'm sending > >> this one without waiting for feedback on my reasons for that which I > >> explained as a reply to v1 because the former couldn't be applied to > >> linux-next, and I want to unblock Krzysztof ASAP to get this tested. > >> > >> drivers/gpu/drm/panfrost/panfrost_device.c | 1 + > >> drivers/gpu/drm/panfrost/panfrost_device.h | 1 + > >> drivers/gpu/drm/panfrost/panfrost_gpu.c | 28 +++++++++++++++------- > >> drivers/gpu/drm/panfrost/panfrost_gpu.h | 1 + > >> 4 files changed, 23 insertions(+), 8 deletions(-) > >> > >> diff --git a/drivers/gpu/drm/panfrost/panfrost_device.c b/drivers/gpu/drm/panfrost/panfrost_device.c > >> index c90ad5ee34e7..b0a4f3e513f4 100644 > >> --- a/drivers/gpu/drm/panfrost/panfrost_device.c > >> +++ b/drivers/gpu/drm/panfrost/panfrost_device.c > >> @@ -421,6 +421,7 @@ static int panfrost_device_runtime_suspend(struct device *dev) > >> return -EBUSY; > >> > >> panfrost_devfreq_suspend(pfdev); > >> + panfrost_gpu_suspend_irq(pfdev); > >> panfrost_gpu_power_off(pfdev); > >> > >> return 0; > >> diff --git a/drivers/gpu/drm/panfrost/panfrost_device.h b/drivers/gpu/drm/panfrost/panfrost_device.h > >> index 0fc558db6bfd..f2b1d4afb9e9 100644 > >> --- a/drivers/gpu/drm/panfrost/panfrost_device.h > >> +++ b/drivers/gpu/drm/panfrost/panfrost_device.h > >> @@ -94,6 +94,7 @@ struct panfrost_device { > >> struct device *dev; > >> struct drm_device *ddev; > >> struct platform_device *pdev; > >> + int gpu_irq; > >> > >> void __iomem *iomem; > >> struct clk *clock; > >> diff --git a/drivers/gpu/drm/panfrost/panfrost_gpu.c b/drivers/gpu/drm/panfrost/panfrost_gpu.c > >> index 09f5e1563ebd..2c09aede0945 100644 > >> --- a/drivers/gpu/drm/panfrost/panfrost_gpu.c > >> +++ b/drivers/gpu/drm/panfrost/panfrost_gpu.c > >> @@ -425,11 +425,10 @@ void panfrost_gpu_power_on(struct panfrost_device *pfdev) > >> > >> void panfrost_gpu_power_off(struct panfrost_device *pfdev) > >> { > >> - u64 core_mask = panfrost_get_core_mask(pfdev); > >> int ret; > >> u32 val; > >> > >> - gpu_write(pfdev, SHADER_PWROFF_LO, pfdev->features.shader_present & core_mask); > >> + gpu_write(pfdev, SHADER_PWROFF_LO, pfdev->features.shader_present); > >> ret = readl_relaxed_poll_timeout(pfdev->iomem + SHADER_PWRTRANS_LO, > >> val, !val, 1, 1000); > >> if (ret) > >> @@ -441,16 +440,29 @@ void panfrost_gpu_power_off(struct panfrost_device *pfdev) > >> if (ret) > >> dev_err(pfdev->dev, "tiler power transition timeout"); > >> > >> - gpu_write(pfdev, L2_PWROFF_LO, pfdev->features.l2_present & core_mask); > >> + gpu_write(pfdev, L2_PWROFF_LO, pfdev->features.l2_present); > >> ret = readl_poll_timeout(pfdev->iomem + L2_PWRTRANS_LO, > >> val, !val, 0, 1000); > >> if (ret) > >> dev_err(pfdev->dev, "l2 power transition timeout"); > >> } > >> > >> +void panfrost_gpu_suspend_irq(struct panfrost_device *pfdev) > >> +{ > >> + /* Disable all interrupts before suspending the GPU */ > >> + gpu_write(pfdev, GPU_INT_MASK, 0); > >> + gpu_write(pfdev, GPU_INT_CLEAR, GPU_IRQ_MASK_ALL); > >> + > >> + /* > >> + * Make sure that we don't have pending ISRs, otherwise we'll be > >> + * reading and/or writing registers while the GPU is powered off > > > > I see this comment, plus the fact you call panfrost_gpu_suspend_irq() > > before panfrost_gpu_power_off() and I realize there might still be a > > misunderstanding. It's not the l2,shader,tiler-poweroff that causes the > > invalid reg access, it's what happens in the PM core after we've > > returned from panfrost_device_runtime_suspend() (power domain turned > > off). The register bank is still accessible when the sub-blocks are off, > > otherwise we wouldn't be able to power them on after a reset (which > > automatically powers off all the blocks, IIRC). > > > > Uhm, should I reword that? Suggestions about how? > > There wasn't any misunderstanding, I did get that the issue can be about unclocked > access or unpowered access (unpowered = vregs off or power domains off), but it is > correct to mask and sync IRQs *before* calling shader/tiler/l2 poweroff (at least > for how I see it), because if there's anything that we want to do in the ISR, we > still have the GPU fully powered up and we're sure that, for example, if we want > to read a debug register to get the reason of an error irq, we're sure that it did > not get cleared. Which is also true after the l2,tiler,core poweroff happened AFAICT (at least for registers that are in the GPU_xxx range). My point is, just because some internal blocks are powered off, doesn't mean the registers exposed to the CPU are invalid, some are just unlikely to change after that point. And if you're worried about some registers having invalid content after a poweroff, it's also true for MMU and JOB registers, but you don't mask+synchronize those in this patch. That's what I'm talking about when I say it's a partial fix to a potentially wider issue, and the very reason I suggested going for simpler fix here, and then fix the irq-sync-on-suspend issue in another patch series.