From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796309454; b=o+OZIVDagabwYFPQDgZXUBY/42zm6K92uYHwYNB0AWVkVopfOkJswP0rUKwof8Yz9MZA dPobgyx4mo0kLXgtsxWsXFFdypHvJo5jzKDAoyvCkxFkPeRsL4s6v00mVkCGFt6U17WZN 4KLf37eDVDkNQj/IjVziUK5qmYO9KWZezXUaYQs9drYfkAj9bYy8RicP0OrQuptnReTGh utb2d8GnA/t/0lzqlEhEZW5E2LsT6dF7UpSvO9+54NuzAVoeP/EQMAHZgriiB3hz7ixQW IiJ+BejhiZuC7oOT4MINVh0mpgs1aqKpjX21Ku+eHQwzASYoMyeK1jbgnRMCZYgQnSg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796309454; h=DMARC-Filter:Received:Received:DKIM-Signature:Message-ID:Date: MIME-Version:User-Agent:Subject:To:Cc:References:From: Content-Language:In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=FIkq1Bvg9NC3kWtDxY+rVv/7khAqJIcwU4Oszt+nNFw=; b=JoLRCmqBq4Ti7XkObcCv552U2ymzoI/eVoAAXVMtCxEHEfpW10KxxVflE7TOnue1Ql+h htkKjz0wGVlcUz8+idER4Td5F+P0+0ff81sRku8OOkViAXBhJLsJ/jX/Jxfh177rUAMYS OJCjubaaZdAT6jTVUuLHi4ca+fctJXpOnlKPMkZVFmNbUmYE8QHVTXkTPcgZI9ws60MAW vYC4RjOtBhESOIcA7PywZYX+5CYD45wqamgPSzdvbw+L6iBGUzguqNelui7eu4IWMo5FV DZ4fEoUzhBpZvxCdac6ltbT+PU1ki3T6qkJLQE3hG4HW9HK6tdnA7y6nXpbddBG/HBQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=dlWbKvTy; arc=none smtp.remote-ip=217.140.110.172 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 10845606A33D for ; Thu, 3 Dec 2026 14:50:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 10845606A33D 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.a=rsa-sha256 header.s=foss header.b=dlWbKvTy 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 43BEE497; Thu, 3 Dec 2026 06:50:50 -0800 (PST) Received: from [10.0.128.193] (e122027.cambridge.arm.com [10.0.128.193]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1AED33F86F; Thu, 3 Dec 2026 06:50:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796309453; bh=HqkJUhn/RV0npPaILKr20onEv8TPKKFCZHM3Qqng5CI=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=dlWbKvTykoay5yiP8BYApYHXJyNN/KpafjkecOxJvyOl7spMHGXDfGZnUfAb41zG2 OOkVME1HsSDPeJj48r8y7lkGEb2YQz7KLWV9qjzGrQWQWUObX0F6R5yAdAHBE3/OmI UjIfNHAbEEwwRGCEYMIrpDFSgbeocuDIVX7gGbS0= Message-ID: Date: Thu, 3 Dec 2026 14:50:48 +0000 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 2/5] drm/panthor: Fix iova_mapped_as_huge_page() for imported BOs To: Boris Brezillon Cc: Liviu Dudau , =?UTF-8?Q?Adri=C3=A1n_Larumbe?= , Akash Goel , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org 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> <20261203104640.4db9c2ae@fedora1.home> From: Steven Price Content-Language: en-GB In-Reply-To: <20261203104640.4db9c2ae@fedora1.home> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 03/12/2026 09:46, Boris Brezillon wrote: > 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. No that's fine - it was very much only if you were going to respin anyway. Thanks, Steve