From f422aee39387a5aa337de69cc21a67f16697ae0e Mon Sep 17 00:00:00 2001 From: Thomas Fleury Date: Tue, 27 Aug 2019 10:09:51 -0400 Subject: [PATCH] gpu: nvgpu: use refcnt for ch mmu_debug_mode Replaced ch->mmu_debug_mode_enabled with ch->mmu_debug_mode_refcnt. If channel is enabled multiple times by userspace, then ref count is updated accordingly. There is an expectation that enable/disable calls are balanced for setting channel's mmu debug mode. When unbinding the channel, decrease refcnt for the channel until it reaches 0. Also, removed tsg parameter from nvgpu_tsg_set_mmu_debug_mode as it can be retrieved from ch. Bug 2515097 Change-Id: If334e374a55bd14ae219edbfd3b1fce5ff25c226 Signed-off-by: Thomas Fleury Reviewed-on: https://git-master.nvidia.com/r/2184702 Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/gpu/nvgpu/common/fifo/tsg.c | 22 +++++++++------------- drivers/gpu/nvgpu/include/nvgpu/channel.h | 4 ++-- drivers/gpu/nvgpu/include/nvgpu/tsg.h | 3 +-- drivers/gpu/nvgpu/os/linux/ioctl_dbg.c | 2 +- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/nvgpu/common/fifo/tsg.c b/drivers/gpu/nvgpu/common/fifo/tsg.c index 0f1dd206b..b49bef912 100644 --- a/drivers/gpu/nvgpu/common/fifo/tsg.c +++ b/drivers/gpu/nvgpu/common/fifo/tsg.c @@ -185,11 +185,12 @@ static int nvgpu_tsg_unbind_channel_common(struct nvgpu_tsg *tsg, nvgpu_rwsem_up_write(&tsg->ch_list_lock); #ifdef CONFIG_NVGPU_DEBUGGER - if (ch->mmu_debug_mode_enabled) { - err = nvgpu_tsg_set_mmu_debug_mode(tsg, ch, false); + while (ch->mmu_debug_mode_refcnt > 0U) { + err = nvgpu_tsg_set_mmu_debug_mode(ch, false); if (err != 0) { nvgpu_err(g, "disable mmu debug mode failed ch:%u", ch->chid); + break; } } #endif @@ -887,13 +888,14 @@ void nvgpu_tsg_reset_faulted_eng_pbdma(struct gk20a *g, struct nvgpu_tsg *tsg, } #ifdef CONFIG_NVGPU_DEBUGGER -int nvgpu_tsg_set_mmu_debug_mode(struct nvgpu_tsg *tsg, - struct nvgpu_channel *ch, bool enable) +int nvgpu_tsg_set_mmu_debug_mode(struct nvgpu_channel *ch, bool enable) { struct gk20a *g; int err = 0; + u32 ch_refcnt; u32 tsg_refcnt; u32 fb_refcnt; + struct nvgpu_tsg *tsg = nvgpu_tsg_from_ch(ch); if ((ch == NULL) || (tsg == NULL)) { return -EINVAL; @@ -906,17 +908,11 @@ int nvgpu_tsg_set_mmu_debug_mode(struct nvgpu_tsg *tsg, } if (enable) { - if (ch->mmu_debug_mode_enabled) { - /* already enabled for this channel */ - return 0; - } + ch_refcnt = ch->mmu_debug_mode_refcnt + 1U; tsg_refcnt = tsg->mmu_debug_mode_refcnt + 1U; fb_refcnt = g->mmu_debug_mode_refcnt + 1U; } else { - if (!ch->mmu_debug_mode_enabled) { - /* already disabled for this channel */ - return 0; - } + ch_refcnt = ch->mmu_debug_mode_refcnt - 1U; tsg_refcnt = tsg->mmu_debug_mode_refcnt - 1U; fb_refcnt = g->mmu_debug_mode_refcnt - 1U; } @@ -941,7 +937,7 @@ int nvgpu_tsg_set_mmu_debug_mode(struct nvgpu_tsg *tsg, g->ops.fb.set_mmu_debug_mode(g, fb_refcnt > 0U); } - ch->mmu_debug_mode_enabled = enable; + ch->mmu_debug_mode_refcnt = ch_refcnt; tsg->mmu_debug_mode_refcnt = tsg_refcnt; g->mmu_debug_mode_refcnt = fb_refcnt; diff --git a/drivers/gpu/nvgpu/include/nvgpu/channel.h b/drivers/gpu/nvgpu/include/nvgpu/channel.h index b53e5d1e9..1d13385bb 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/channel.h +++ b/drivers/gpu/nvgpu/include/nvgpu/channel.h @@ -597,9 +597,9 @@ struct nvgpu_channel { bool is_privileged_channel; #ifdef CONFIG_NVGPU_DEBUGGER /** - * MMU Debugger Mode is enabled for this channel. + * MMU Debugger Mode is enabled for this channel if refcnt > 0 */ - bool mmu_debug_mode_enabled; + u32 mmu_debug_mode_refcnt; #endif }; diff --git a/drivers/gpu/nvgpu/include/nvgpu/tsg.h b/drivers/gpu/nvgpu/include/nvgpu/tsg.h index 6cba6f20a..9f46201d3 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/tsg.h +++ b/drivers/gpu/nvgpu/include/nvgpu/tsg.h @@ -622,7 +622,6 @@ void nvgpu_tsg_abort(struct gk20a *g, struct nvgpu_tsg *tsg, bool preempt); void nvgpu_tsg_reset_faulted_eng_pbdma(struct gk20a *g, struct nvgpu_tsg *tsg, bool eng, bool pbdma); #ifdef CONFIG_NVGPU_DEBUGGER -int nvgpu_tsg_set_mmu_debug_mode(struct nvgpu_tsg *tsg, - struct nvgpu_channel *ch, bool enable); +int nvgpu_tsg_set_mmu_debug_mode(struct nvgpu_channel *ch, bool enable); #endif #endif /* NVGPU_TSG_H */ diff --git a/drivers/gpu/nvgpu/os/linux/ioctl_dbg.c b/drivers/gpu/nvgpu/os/linux/ioctl_dbg.c index 6030d4faa..a23dedbb9 100644 --- a/drivers/gpu/nvgpu/os/linux/ioctl_dbg.c +++ b/drivers/gpu/nvgpu/os/linux/ioctl_dbg.c @@ -1115,7 +1115,7 @@ static int nvgpu_dbg_gpu_ioctl_set_mmu_debug_mode( goto clean_up; } - err = nvgpu_tsg_set_mmu_debug_mode(nvgpu_tsg_from_ch(ch), ch, enable); + err = nvgpu_tsg_set_mmu_debug_mode(ch, enable); if (err) { nvgpu_err(g, "set mmu debug mode failed, err=%d", err); }