From 189ab6bd9ac4d4473d15540271abdc8e00e1704e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konsta=20H=C3=B6ltt=C3=A4?= Date: Tue, 5 Oct 2021 13:37:27 +0300 Subject: [PATCH] gpu: nvgpu: fix nvgpu_locate_pte for unmapped entries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit nvgpu_locate_pte() can be attempted on an address that is not mapped yet. When the address is just right, it's possible that the pd entries haven't been allocated yet; return an error in such case before accessing the indexed entry. Bug 200778663 Change-Id: I4f062531d30aec746d6828c2d05c046bc912bd2a Signed-off-by: Konsta Hölttä Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2606175 Reviewed-by: Alex Waterman Reviewed-by: mobile promotions Tested-by: mobile promotions GVS: Gerrit_Virtual_Submit --- drivers/gpu/nvgpu/common/mm/gmmu/page_table.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/nvgpu/common/mm/gmmu/page_table.c b/drivers/gpu/nvgpu/common/mm/gmmu/page_table.c index aae204b4a..1f27c2600 100644 --- a/drivers/gpu/nvgpu/common/mm/gmmu/page_table.c +++ b/drivers/gpu/nvgpu/common/mm/gmmu/page_table.c @@ -1270,7 +1270,14 @@ static int nvgpu_locate_pte(struct gk20a *g, struct vm_gk20a *vm, * then find the next level PD and recurse. */ if (next_l->update_entry != NULL) { - struct nvgpu_gmmu_pd *pd_next = pd->entries + pd_idx; + struct nvgpu_gmmu_pd *pd_next; + + /* Not mapped yet, invalid entry */ + if (pd->entries == NULL) { + return -EINVAL; + } + + pd_next = pd->entries + pd_idx; /* Invalid entry! */ if (pd_next->mem == NULL) {