From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794064579; b=jgbJJgR+inzFFCQOOmeTrPDSEiN+AvdZdipd3B0kTpz6WB/UWhiWKfIDCPAYaxNjw2Vq HdHQt0c/nfRC4OQCOoUS9jr2gRttcWP0J68EFaYMN1C8R2bSB0FYJOD7HlNkyRrljtZQj OkZkBokpFRocVMowWVSu0/pvLcOVFVPAY24I3RTgl0DyLlVtgii3ItRLYwtITEn0rNG2s ALbLZhYxZkJrT4dhyG7VpRCq3v6Fw15kjtzsaJTitZ0pwuVyobJMBcqAWsIg50ClEkuNe JGWb1rWQ36j2meZxxbEPg96SM9fI+Y7bq8orrdwuQrE9sPONXDJC8T7Wmq569zGli3Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794064579; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=wOZYDAFp68GzO37nSFUlmuLuVcDfMf5QeKt19u1XcPg=; b=keK/OvCLcQMfK9DEgyGv0bYY2/isKYbLXV1vgxymi/jTfLvO7eWw9liKA66X5Aq8nbup +AbgLZ0M1rkPa8J5jCkrpKHLx2iB9R3DdSTQrVBQRGhtlx+5bb/4jcNsK49ge6fV6NpQX 5YLwcYNqAJOhBWFmCbaI3X8kWANPrkb/yGBmQ+91S1horGB9kHni/hF5dfGp2XrNqO/7/ RxoxfNyujrcTkEWOfiqpdtUNZBCwnU+wAOJSJFn2wQEOEwEa+7IzXGtEHl9MJI8I7UfOU 38oXkeEUySU1RYiLbZ9iiNphw01/zistNXvEmWhvxPWizQ0Zp3Iml0x5EKP/p+taboA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ErSNMczQ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (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 ED11A606D809; Sat, 7 Nov 2026 15:16:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=ErSNMczQ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9AE521F0089F; Sat, 7 Nov 2026 15:16:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794064578; bh=wOZYDAFp68GzO37nSFUlmuLuVcDfMf5QeKt19u1XcPg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=ErSNMczQglRSy0D5GbIQBuzt7Rh9PhkU5+aCdn+DNk4m0UqKO3fwPVEQgeAmWkUck NCUQn3PA6iAZphPRUz9bU1xPjMz+Nd1krxorZneWhyS9ZLoXIJSjma9cOHHyy/UinJ sN5qXhE8eX8rd3s9+f1dy5qtW6qlJtyULu0nG0ac= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Christian=20K=C3=B6nig?= , Jesse Zhang , Arunpravin Paneer Selvam , Sasha Levin Subject: [PATCH 7.3 0598/1257] drm/ttm: return an error when kmapping a BO without pages Date: Sat, 7 Nov 2026 08:48:14 -0500 Message-ID: <20261107134955.840071165@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261107134939.434104957@linuxfoundation.org> References: <20261107134939.434104957@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@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=UTF-8 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jesse Zhang [ Upstream commit fd485d47437ba1700dd47205a63b9f389a00aa36 ] ttm_tt objects for imported sg tables (ttm_bo_type_sg, set up by ttm_sg_tt_init() with TTM_TT_FLAG_EXTERNAL) only have DMA addresses and no pages array. ttm_bo_kmap() and ttm_bo_vmap() still dereference ttm->pages for them, so a driver that tries to CPU map such a BO oopses instead of getting an error: BUG: kernel NULL pointer dereference, address: 0000000000000000 RIP: 0010:ttm_bo_kmap+0x26c/0x300 [ttm] Call Trace: amdgpu_bo_kmap+0x89/0xb0 [amdgpu] amdgpu_userq_fence_read_wptr+0x116/0x170 [amdgpu] amdgpu_userq_signal_ioctl+0x3fe/0xbb0 [amdgpu] Return -EINVAL in that case, like ttm_bo_kmap_try_from_panic() already checks for a missing pages array. Fixes: 75a57669cbc8 ("drm/ttm: add ttm_sg_tt_init") Cc: stable@vger.kernel.org Suggested-by: Christian König Reviewed-by: Christian König Signed-off-by: Jesse Zhang Signed-off-by: Arunpravin Paneer Selvam Link: https://patch.msgid.link/20261009103419.4122940-1-Jesse.Zhang@amd.com Signed-off-by: Sasha Levin --- drivers/gpu/drm/ttm/ttm_bo_util.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c index bd0b23ac2cc4b..f9458a4d5a09d 100644 --- a/drivers/gpu/drm/ttm/ttm_bo_util.c +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c @@ -356,6 +356,10 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo, if (ret) return ret; + /* Imported sg tables only come with DMA addresses, no pages to map. */ + if (!ttm->pages) + return -EINVAL; + if (num_pages == 1 && ttm->caching == ttm_cached && !(man->use_tt && (ttm->page_flags & TTM_TT_FLAG_DECRYPTED))) { /* @@ -419,7 +423,7 @@ EXPORT_SYMBOL(ttm_bo_kmap_try_from_panic); * * Returns * -ENOMEM: Out of memory. - * -EINVAL: Invalid range. + * -EINVAL: Invalid range or the BO has no pages to map. */ int ttm_bo_kmap(struct ttm_buffer_object *bo, unsigned long start_page, unsigned long num_pages, @@ -493,7 +497,7 @@ EXPORT_SYMBOL(ttm_bo_kunmap); * * Returns * -ENOMEM: Out of memory. - * -EINVAL: Invalid range. + * -EINVAL: Invalid range or the BO has no pages to map. */ int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map) { @@ -537,6 +541,9 @@ int ttm_bo_vmap(struct ttm_buffer_object *bo, struct iosys_map *map) if (ret) return ret; + if (!ttm->pages) + return -EINVAL; + /* * We need to use vmap to get the desired page protection * or to make the buffer object look contiguous. -- 2.53.0