From 350c8ebf1110c9e855d447b52ec48c86ee7b39a4 Mon Sep 17 00:00:00 2001 From: Nicolas Benech Date: Fri, 15 Feb 2019 16:56:01 -0500 Subject: [PATCH] gpu: nvgpu: unit: handle BUG() calls in pd_cache With the use of nvgpu_assert in pd_cache code, some tests trying to cause failures are now causing calls to BUG() which are now being handled with calls to EXPECT_BUG JIRA NVGPU-677 Change-Id: Idc3696ddef30165588fe9c9dcb6ab0b7241ab5fe Signed-off-by: Nicolas Benech Reviewed-on: https://git-master.nvidia.com/r/2020601 Reviewed-by: svc-misra-checker GVS: Gerrit_Virtual_Submit Reviewed-by: Adeel Raza Reviewed-by: mobile promotions Tested-by: mobile promotions --- userspace/units/mm/gmmu/pd_cache/pd_cache.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/userspace/units/mm/gmmu/pd_cache/pd_cache.c b/userspace/units/mm/gmmu/pd_cache/pd_cache.c index f85b1d0bd..e159745c1 100644 --- a/userspace/units/mm/gmmu/pd_cache/pd_cache.c +++ b/userspace/units/mm/gmmu/pd_cache/pd_cache.c @@ -32,6 +32,8 @@ #include #include +#include + /* * Direct allocs are allocs large enough to just pass straight on to the * DMA allocator. Basically that means the size of the PD is larger than a page. @@ -318,10 +320,17 @@ static int test_pd_free_empty_pd(struct unit_module *m, * So we will make sure we don't crash. */ nvgpu_pd_free(&vm, &pd); - nvgpu_pd_free(&vm, &pd); + if (!EXPECT_BUG(nvgpu_pd_free(&vm, &pd))) { + unit_return_fail(m, "nvgpu_pd_free did not BUG() as expected"); + } + /* When BUG() occurs the pd_cache lock is not released, so do it here */ + nvgpu_mutex_release(&g->mm.pd_cache->lock); pd.mem = NULL; - nvgpu_pd_free(&vm, &pd); + if (!EXPECT_BUG(nvgpu_pd_free(&vm, &pd))) { + unit_return_fail(m, "nvgpu_pd_free did not BUG() as expected"); + } + nvgpu_mutex_release(&g->mm.pd_cache->lock); /* And now direct frees. */ memset(&pd, 0U, sizeof(pd)); @@ -331,6 +340,11 @@ static int test_pd_free_empty_pd(struct unit_module *m, } nvgpu_pd_free(&vm, &pd); + + /* + * nvgpu_pd_free calls below will not cause BUG() because pd->cached is + * true. + */ nvgpu_pd_free(&vm, &pd); pd.mem = NULL; @@ -357,8 +371,7 @@ static int test_pd_alloc_invalid_input(struct unit_module *m, } /* Obviously shouldn't work pd_cache is not init'ed. */ - err = nvgpu_pd_alloc(&vm, &pd, 2048U); - if (err == 0) { + if (!EXPECT_BUG(nvgpu_pd_alloc(&vm, &pd, 2048U))) { unit_return_fail(m, "pd_alloc worked on NULL pd_cache\n"); }