From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.251.105.195 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796291210; b=1xBn8gbdGh2jhNTPPMoL4klwuF3dIZFbDxqweQm29jOFDGMeoq6/tkWCG/L1fRx/MJx7 +z9m5QjE1CGdv2KvBbkskS/aHU6DqR4DfnI+f5E1n4M6xQnOI3XJGM9A6jpw31wAUU+K7 0XRMDynyLVrUtwS6iWSpirmtK7ZSdD2PREDyxUniECDWgMbN/jvEuLk3zxnw0xzGWhkb8 LzhfXsgYcJCmc4JYN1YS1IIon6HwNuxfcPsu+Spe+yf40FF6Ljunh0pidOgABf+zUPO6W qSo6MIgcb9Xt7SCE4YN9zYexzaFNHwFoUSvuMvYQKr7sq5aQjc04i1RJIQai5O0HB/A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796291210; h=DMARC-Filter:DKIM-Signature:Received:Date:From:To:Cc:Subject: Message-ID:In-Reply-To:References:Organization:X-Mailer:MIME-Version: Content-Type:Content-Transfer-Encoding; bh=NMe9Es38apoqd0mKnmpWv2g3iExlhDAYol8CIya8Jl0=; b=NVRlj6zXw0FVimrBx2kVkQ9tSzs5qk6/Xm4RC4MurLm7n/LodPZTe0iy2JTpqwshRbfa tWwaY31R/mBBUg9/qov8FfTsWnRJyZixR4cInojgbE30T+fiJot5lx0VTkupLEwE6GSwD yq4N9gxqrVNUXY+diQXIbwbnPsdNN7g6FInBodDmPnDXQxf5/mrQBd83MqdrH/vKSGnMs f4z0bTQUhiBrZlOVeRbOf6nyLmHBpNjovTz3IjpDjW4WeEH6Iyksjl3w6UaOzYozAgeEF Fu2Ce2zeQVyLpv70rE+ZyjTBU9UdmlKaQ3KhDvWZ/zeE20eXwxXiwka8gggLygfeJYw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=DfADLbXC; arc=none smtp.remote-ip=148.251.105.195 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE2CB606A330 for ; Thu, 3 Dec 2026 09:46:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EE2CB606A330 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=collabora.com header.i=@collabora.com header.a=rsa-sha256 header.s=mail header.b=DfADLbXC DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1796291208; bh=8l0b/+NlKcz+Pxux0oxTpexnN3oXVq4AElVG20UiEPU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=DfADLbXCjXUfKIPot/JDzUaTRw9s/5cSgD/zMzYqs7JR/UxllvLKlPFi/PgTlo83n YJzpWbiynFf9Xqf+qbEGAQmKZ3xi3HhPMIGKQXrL1Ow7tnKPrXNWvWZXB5StjmbKi7 XgNiD6HlM7Ke/PGne+i0vMfH+hFA4rxCsWDI0slygJBSC10/VMbrw+H5q7qpGKg5b+ tOjEZz8jylUa1TPc5RUt3S9xTGfRsGyGrE0iUfb7n3coXytpHPiMIeMgfqkG26NlDX bXpFiOiuXSwfEPRZhi6/MSH1TPhkbkyA2u0A6/mIdq+1psTvfTqkykNJSYatQBqgvo Ogq0G9EqM6nMA== Received: from fedora1.home (unknown [100.64.0.11]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange secp256r1 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: bbrezillon) by bali.collaboradmins.com (Postfix) with ESMTPSA id AB74617E0967; Thu, 03 Dec 2026 10:46:47 +0100 (CET) Date: Thu, 3 Dec 2026 10:46:40 +0100 From: Boris Brezillon To: Steven Price Cc: Liviu Dudau , =?UTF-8?B?QWRyacOhbg==?= Larumbe , Akash Goel , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 2/5] drm/panthor: Fix iova_mapped_as_huge_page() for imported BOs Message-ID: <20261203104640.4db9c2ae@fedora1.home> In-Reply-To: <043e60c3-bf24-479b-9b87-1a6682a7f576@arm.com> References: <20260924-panthor-fix-partial-unmap-v2-0-59a68a1f9e14@collabora.com> <20260924-panthor-fix-partial-unmap-v2-2-59a68a1f9e14@collabora.com> <043e60c3-bf24-479b-9b87-1a6682a7f576@arm.com> Organization: Collabora X-Mailer: Claws Mail 4.4.0 (GTK 3.24.52; x86_64-redhat-linux-gnu) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Mon, 5 Oct 2026 11:28:43 +0100 Steven Price wrote: > On 24/09/2026 12:04, Boris Brezillon wrote: > > Imported BOs have no backing.pages array allocated, leading to a NULL > > deref when iova_mapped_as_huge_page() gets called on them. > > > > Implement this check through and sgt walk to reach the position of the > NIT: ^^^ > s/and/an/ > > > sgt targeted by a VA, and check that the DMA address is properly aligned > > and the size remaining in the SG entry is bigger than a huge page. > > This is basically matching the logic in vm_map_pages(), with get_pgsize() > > being replaced by a simpler test, because we don't care about the pgcount > > info. > > > > Reported-by: Akash Goel > > Fixes: 8e7460eac786 ("drm/panthor: Support partial unmaps of huge pages") > > Reviewed-by: Liviu Dudau > > Reviewed-by: Akash Goel > > Signed-off-by: Boris Brezillon > > Reviewed-by: Steven Price > > Although there's a minor style issue below if you do respin (see below). > > > --- > > drivers/gpu/drm/panthor/panthor_mmu.c | 44 ++++++++++++++++++++++++++++------- > > 1 file changed, 36 insertions(+), 8 deletions(-) > > > > diff --git a/drivers/gpu/drm/panthor/panthor_mmu.c b/drivers/gpu/drm/panthor/panthor_mmu.c > > index b0a7033480e6..6cef954e2cba 100644 > > --- a/drivers/gpu/drm/panthor/panthor_mmu.c > > +++ b/drivers/gpu/drm/panthor/panthor_mmu.c > > @@ -2299,7 +2299,6 @@ iova_mapped_as_huge_page(struct drm_gpuva *mapping, u64 va) > > { > > struct panthor_gem_object *bo = to_panthor_bo(mapping->gem.obj); > > u64 aligned_va = ALIGN_DOWN(va, SZ_2M); > > - const struct page *pg; > > pgoff_t bo_offset; > > > > /* If the 2M-aligned VA is outside the mapping being tested, we know > > @@ -2309,16 +2308,45 @@ iova_mapped_as_huge_page(struct drm_gpuva *mapping, u64 va) > > return false; > > > > bo_offset = aligned_va - mapping->va.addr + mapping->gem.offset; > > - pg = bo->backing.pages[bo_offset >> PAGE_SHIFT]; > > > > - /* In case of shmem backing, we know we can only have a huge mapping > > - * if the bo_offset is 2M aligned, meaning we can skip the folio size > > - * check if it's not the case. > > - */ > > - if (!IS_ALIGNED(bo_offset, SZ_2M)) > > + if (drm_gem_is_imported(&bo->base)) { > > + struct sg_table *sgt = bo->dmap.sgt; > > + struct scatterlist *sgl; > > + unsigned int count; > > + > > + /* If this is an imported BO, we have to walk the SGT and > > + * check the dma address/size alignment to determine if it's > > + * a huge map or not. > > + */ > > + for_each_sgtable_dma_sg(sgt, sgl, count) { > > + size_t len = sg_dma_len(sgl); > > + dma_addr_t daddr; > > + > > + if (len <= bo_offset) { > > + bo_offset -= len; > > + continue; > > + } > > + > > + len -= bo_offset; > > + daddr = sg_dma_address(sgl) + bo_offset; > > + > > + return IS_ALIGNED(daddr, SZ_2M) && > > + len >= SZ_2M; > > + } > > + > > return false; > > + } else { > > This 'else' branch isn't needed - since the above branch returns early. > Dropping the below back out of the braces would make the diff easier to > read - effectively the drm_gem_is_imported() branch is just added and > the rest of the code is left as is. I ended up not going for this approach, so the pg variable is scoped to this branch instead of being declared at the top, with the risk of dereferencing it when it's uninitialized in other places. We can always change that in a follow-up patch if you think it's still preferable over the extra indentation level the else branch adds.