From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08A5540626C for ; Thu, 13 Aug 2026 15:29:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786634977; cv=none; b=Yd1Lj6tuxiOpOtlamY6A5078L5ZtcUWA+/uWuth+aQ0BQWPwsrjORorjnblh0G8/BRHpFQQNjhxggqXY5UStTCsSeAHuE6v497nUvh7kX0W744FxMc0Lvoqr3GOn+n5VGZHsc/sYPRRBkmX51wY99Mo1OOW46d9JmtTo1bdHaeE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786634977; c=relaxed/simple; bh=HX5lmoJ8U40GOQvbc7bCue8HQIqzzve9G5mKtq7Eh0Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Mrm5Z3IA2B6ugOpv3Gj4YyCjI9zmFIw1z+XcIXCUfQxfTYVHgKYB7m/j1TjED0mMsfQtaZcnDeB0x5claDPrM2bxLmkWU8Wrt4r+KAKD6+dIad74bvDUfEv0jobAI4F9RWG/KMnHCc146Cx+dF8QAQCXzwwP+w1paklPfRkvzxI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=p5iH8TYR; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b="p5iH8TYR" Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 48E3F1756 for ; Thu, 13 Aug 2026 08:29:30 -0700 (PDT) Received: from [192.168.0.1] (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 09FEB3F632 for ; Thu, 13 Aug 2026 08:29:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1786634974; bh=HX5lmoJ8U40GOQvbc7bCue8HQIqzzve9G5mKtq7Eh0Y=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=p5iH8TYRxq+xQEo4Lq2o62z6XjxxqnLTGB2kQRj7zwhEwkQm3pEPfHJW1XHvi+sgQ XoZX4mz0TTP2nq77sh9ebXgQg3XeylJ2avoXyUbT1Z7QczNucIdbH70CfOB4JkuJLB ZhHbyYWOR6+6OHUc/Azc1MnSEpQ07Qgubttyal10= Date: Thu, 13 Aug 2026 16:29:22 +0100 From: Liviu Dudau To: Nicolas Frattaroli Cc: Boris Brezillon , Steven Price , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Grant Likely , Heiko Stuebner , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, kernel@collabora.com Subject: Re: [PATCH v3 2/3] drm/panthor: Revisit reqs_lock handling in flush/reset paths Message-ID: References: <20260811-panthor-cache-flush-fix-v3-0-47d2c1bb1dab@collabora.com> <20260811-panthor-cache-flush-fix-v3-2-47d2c1bb1dab@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260811-panthor-cache-flush-fix-v3-2-47d2c1bb1dab@collabora.com> On Tue, Aug 11, 2026 at 04:08:32PM +0200, Nicolas Frattaroli wrote: > panthor_gpu_flush_caches() and panthor_gpu_soft_reset() acquire their > reqs_lock spinlock with the IRQ-disabling variants of the spinlocking > functions. This isn't necessary, as the lock is never taken from an > atomic context, as Panthor uses threaded interrupt handlers. The result > of this overly strict locking is that IRQs may be disabled more > frequently and for longer than they should be, resulting in increased > system latency. > > Switch the locking to use non-IRQ-disabling scoped_guard statements for > locking. The wait_event_timeout read of pending_reqs outside of the > spinlock is fine as wait_event_timeout is a memory barrier according to > the Linux Memory Model. > > Fixes: 5cd894e258c4 ("drm/panthor: Add the GPU logical block") > Signed-off-by: Nicolas Frattaroli Reviewed-by: Liviu Dudau Best regards, Liviu > --- > drivers/gpu/drm/panthor/panthor_gpu.c | 66 ++++++++++++++++------------------- > 1 file changed, 30 insertions(+), 36 deletions(-) > > diff --git a/drivers/gpu/drm/panthor/panthor_gpu.c b/drivers/gpu/drm/panthor/panthor_gpu.c > index 68e2dd2527df..cb5319d1c5de 100644 > --- a/drivers/gpu/drm/panthor/panthor_gpu.c > +++ b/drivers/gpu/drm/panthor/panthor_gpu.c > @@ -330,37 +330,32 @@ int panthor_gpu_flush_caches(struct panthor_device *ptdev, > u32 l2, u32 lsc, u32 other) > { > struct panthor_gpu *gpu = ptdev->gpu; > - unsigned long flags; > int ret = 0; > > /* Serialize cache flush operations. */ > guard(mutex)(&ptdev->gpu->cache_flush_lock); > > - spin_lock_irqsave(&ptdev->gpu->reqs_lock, flags); > - trace_gpu_cache_flush_start(ptdev->base.dev, l2, lsc, other); > - if (!(ptdev->gpu->pending_reqs & GPU_IRQ_CLEAN_CACHES_COMPLETED)) { > - ptdev->gpu->pending_reqs |= GPU_IRQ_CLEAN_CACHES_COMPLETED; > - gpu_write(gpu->iomem, GPU_CMD, GPU_FLUSH_CACHES(l2, lsc, other)); > - } else { > - ret = -EIO; > - } > - spin_unlock_irqrestore(&ptdev->gpu->reqs_lock, flags); > - > - if (ret) { > - trace_gpu_cache_flush_end(ptdev->base.dev, l2, lsc, other); > - return ret; > + scoped_guard(spinlock, &ptdev->gpu->reqs_lock) { > + trace_gpu_cache_flush_start(ptdev->base.dev, l2, lsc, other); > + if (!(ptdev->gpu->pending_reqs & GPU_IRQ_CLEAN_CACHES_COMPLETED)) { > + ptdev->gpu->pending_reqs |= GPU_IRQ_CLEAN_CACHES_COMPLETED; > + gpu_write(gpu->iomem, GPU_CMD, GPU_FLUSH_CACHES(l2, lsc, other)); > + } else { > + trace_gpu_cache_flush_end(ptdev->base.dev, l2, lsc, other); > + return -EIO; > + } > } > > if (!wait_event_timeout(ptdev->gpu->reqs_acked, > !(ptdev->gpu->pending_reqs & GPU_IRQ_CLEAN_CACHES_COMPLETED), > msecs_to_jiffies(100))) { > - spin_lock_irqsave(&ptdev->gpu->reqs_lock, flags); > - if ((ptdev->gpu->pending_reqs & GPU_IRQ_CLEAN_CACHES_COMPLETED) != 0 && > - !(gpu_read(gpu->irq.iomem, INT_RAWSTAT) & GPU_IRQ_CLEAN_CACHES_COMPLETED)) > - ret = -ETIMEDOUT; > - else > - ptdev->gpu->pending_reqs &= ~GPU_IRQ_CLEAN_CACHES_COMPLETED; > - spin_unlock_irqrestore(&ptdev->gpu->reqs_lock, flags); > + scoped_guard(spinlock, &ptdev->gpu->reqs_lock) { > + if ((ptdev->gpu->pending_reqs & GPU_IRQ_CLEAN_CACHES_COMPLETED) != 0 && > + !(gpu_read(gpu->irq.iomem, INT_RAWSTAT) & GPU_IRQ_CLEAN_CACHES_COMPLETED)) > + ret = -ETIMEDOUT; > + else > + ptdev->gpu->pending_reqs &= ~GPU_IRQ_CLEAN_CACHES_COMPLETED; > + } > } > > trace_gpu_cache_flush_end(ptdev->base.dev, l2, lsc, other); > @@ -383,27 +378,26 @@ int panthor_gpu_soft_reset(struct panthor_device *ptdev) > { > struct panthor_gpu *gpu = ptdev->gpu; > bool timedout = false; > - unsigned long flags; > > - spin_lock_irqsave(&ptdev->gpu->reqs_lock, flags); > - if (!drm_WARN_ON(&ptdev->base, > - ptdev->gpu->pending_reqs & GPU_IRQ_RESET_COMPLETED)) { > - ptdev->gpu->pending_reqs |= GPU_IRQ_RESET_COMPLETED; > - gpu_write(gpu->irq.iomem, INT_CLEAR, GPU_IRQ_RESET_COMPLETED); > - gpu_write(gpu->iomem, GPU_CMD, GPU_SOFT_RESET); > + scoped_guard(spinlock, &ptdev->gpu->reqs_lock) { > + if (!drm_WARN_ON(&ptdev->base, > + ptdev->gpu->pending_reqs & GPU_IRQ_RESET_COMPLETED)) { > + ptdev->gpu->pending_reqs |= GPU_IRQ_RESET_COMPLETED; > + gpu_write(gpu->irq.iomem, INT_CLEAR, GPU_IRQ_RESET_COMPLETED); > + gpu_write(gpu->iomem, GPU_CMD, GPU_SOFT_RESET); > + } > } > - spin_unlock_irqrestore(&ptdev->gpu->reqs_lock, flags); > > if (!wait_event_timeout(ptdev->gpu->reqs_acked, > !(ptdev->gpu->pending_reqs & GPU_IRQ_RESET_COMPLETED), > msecs_to_jiffies(100))) { > - spin_lock_irqsave(&ptdev->gpu->reqs_lock, flags); > - if ((ptdev->gpu->pending_reqs & GPU_IRQ_RESET_COMPLETED) != 0 && > - !(gpu_read(gpu->irq.iomem, INT_RAWSTAT) & GPU_IRQ_RESET_COMPLETED)) > - timedout = true; > - else > - ptdev->gpu->pending_reqs &= ~GPU_IRQ_RESET_COMPLETED; > - spin_unlock_irqrestore(&ptdev->gpu->reqs_lock, flags); > + scoped_guard(spinlock, &ptdev->gpu->reqs_lock) { > + if ((ptdev->gpu->pending_reqs & GPU_IRQ_RESET_COMPLETED) != 0 && > + !(gpu_read(gpu->irq.iomem, INT_RAWSTAT) & GPU_IRQ_RESET_COMPLETED)) > + timedout = true; > + else > + ptdev->gpu->pending_reqs &= ~GPU_IRQ_RESET_COMPLETED; > + } > } > > if (timedout) { > > -- > 2.55.0 > -- ==================== | I would like to | | fix the world, | | but they're not | | giving me the | \ source code! / --------------- ¯\_(ツ)_/¯