From 1e81983bed9d03b68ea97c6b59b1dd95d707f185 Mon Sep 17 00:00:00 2001 From: Yu Qiaowei Date: Thu, 22 Sep 2022 19:27:39 +0800 Subject: [PATCH] video: rockchip: rga3: Fixed the crash caused by RGA2 using dma_buf_fd When rga2 uses sgt to generate the page table, length should be used instead of dma_length, which will cause the length of the sgt after the default_mapping_core to be the length of the entire dma_buf. Update driver version to 1.2.20 Signed-off-by: Yu Qiaowei Change-Id: I07ad619b41554ededc0c5ade552a3bc176fef3f7 --- drivers/video/rockchip/rga3/include/rga_drv.h | 2 +- drivers/video/rockchip/rga3/rga_mm.c | 27 ++++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/video/rockchip/rga3/include/rga_drv.h b/drivers/video/rockchip/rga3/include/rga_drv.h index 6b8bac5fec2f..7f94456bc497 100644 --- a/drivers/video/rockchip/rga3/include/rga_drv.h +++ b/drivers/video/rockchip/rga3/include/rga_drv.h @@ -87,7 +87,7 @@ #define DRIVER_MAJOR_VERISON 1 #define DRIVER_MINOR_VERSION 2 -#define DRIVER_REVISION_VERSION 19 +#define DRIVER_REVISION_VERSION 20 #define DRIVER_PATCH_VERSION #define DRIVER_VERSION (STR(DRIVER_MAJOR_VERISON) "." STR(DRIVER_MINOR_VERSION) \ diff --git a/drivers/video/rockchip/rga3/rga_mm.c b/drivers/video/rockchip/rga3/rga_mm.c index 4c5a667311bb..7d59472d0888 100644 --- a/drivers/video/rockchip/rga3/rga_mm.c +++ b/drivers/video/rockchip/rga3/rga_mm.c @@ -1042,15 +1042,24 @@ static int rga_mm_sgt_to_page_table(struct sg_table *sg, uint32_t break_flag = 0; do { - len = sg_dma_len(sgl) >> PAGE_SHIFT; - if (len == 0) - len = sgl->length >> PAGE_SHIFT; + /* + * The length of each sgl is expected to be obtained here, not + * the length of the entire dma_buf, so sg_dma_len() is not used. + */ + len = sgl->length >> PAGE_SHIFT; if (use_dma_address) /* - * The fd passed by user space gets sg through - * dma_buf_map_attachment, - * so dma_address can be use here. + * The fd passed by user space gets sg through + * dma_buf_map_attachment, so dma_address can + * be use here. + * When the mapped device does not have iommu, it will + * return the first address of the real physical page + * when it meets the requirements of the current device, + * and will trigger swiotlb when it does not meet the + * requirements to obtain a software-mapped physical + * address that is mapped to meet the device address + * requirements. */ Address = sg_dma_address(sgl); else @@ -1061,15 +1070,13 @@ static int rga_mm_sgt_to_page_table(struct sg_table *sg, break_flag = 1; break; } - page_table[mapped_size + i] = - (uint32_t) (Address + (i << PAGE_SHIFT)); + page_table[mapped_size + i] = (uint32_t)(Address + (i << PAGE_SHIFT)); } if (break_flag) break; mapped_size += len; sg_num += 1; - } while ((sgl = sg_next(sgl)) && (mapped_size < pageCount) - && (sg_num < sg->nents)); + } while ((sgl = sg_next(sgl)) && (mapped_size < pageCount) && (sg_num < sg->orig_nents)); return 0; }