From 6b4f98d9380169fa5e6295407412c2ef357da8ae Mon Sep 17 00:00:00 2001 From: Chaoyi Chen Date: Mon, 25 Nov 2024 16:38:31 +0800 Subject: [PATCH] drm/rockchip: gem: Fix alloc size setting for IOMMU device For IOMMU devices, the mapped size may be larger than the requested alloc size, which may result in inconsistent sizes being used for unmap. [ 12.286016] iova: 0x0000000000000000 already mapped to 0x000000000c201000 cannot remap to phys: 0x000000001369f000 prot: 0x3 [ 12.287163] [drm:rockchip_gem_iommu_map] *ERROR* failed to map buffer: size=-98 request_size=4096 [ 12.299439] iova: 0x0000000000000000 already mapped to 0x000000000c201000 cannot remap to phys: 0x000000000c2b8000 prot: 0x3 [ 12.300541] [drm:rockchip_gem_iommu_map] *ERROR* failed to map buffer: size=-98 request_size=2785280 Fixes: 2ba5e1d68173 ("drm/rockchip: gem: Set size of the allocated object when create gem") Change-Id: I3496544e5a4eb65dde657f8ed3890f4db933258f Signed-off-by: Chaoyi Chen --- drivers/gpu/drm/rockchip/rockchip_drm_gem.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c index 862c50d94c97..e8574fe0c1f4 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_gem.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_gem.c @@ -67,6 +67,8 @@ static int rockchip_gem_iommu_map(struct rockchip_gem_object *rk_obj) iommu_flush_iotlb_all(private->domain); + rk_obj->size = ret; + return 0; err_remove_node: @@ -649,6 +651,15 @@ rockchip_gem_create_object(struct drm_device *drm, unsigned int size, if (ret) goto err_free_rk_obj; + /** + * For iommu device, this size will be set in rockchip_gem_iommu_map(). + * The actual mapped size may be larger than the request size. + * + * For non-iommu device, set to the requested fb size. + */ + if (rk_obj->size == 0) + rk_obj->size = size; + return rk_obj; err_free_rk_obj: @@ -729,7 +740,6 @@ rockchip_gem_create_with_handle(struct drm_file *file_priv, return ERR_CAST(rk_obj); obj = &rk_obj->base; - rk_obj->size = size; /* * allocate a id of idr table where the obj is registered