diff options
author | Konsta Holtta <kholtta@nvidia.com> | 2018-11-13 08:36:19 -0500 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2019-02-05 12:04:20 -0500 |
commit | 3794afbeb177ed0932d166d30bb2af9d9859dff9 (patch) | |
tree | ddec116ed6ebee65f14108aaa54b84e3869589d4 /drivers/gpu/nvgpu/vgpu | |
parent | ed6e3960903b9e2ba82ded06d1abfe3dec0ac865 (diff) |
gpu: nvgpu: add safe channel id lookup
Add gk20a_channel_from_id() to retrieve a channel, given a raw channel
ID, with a reference taken (or NULL if the channel was dead). This makes
it harder to mistakenly use a channel that's dead and thus uncovers bugs
sooner. Convert code to use the new lookup when applicable; work remains
to convert complex uses where a ref should have been taken but hasn't.
The channel ID is also validated against FIFO_INVAL_CHANNEL_ID; NULL is
returned for such IDs. This is often useful and does not hurt when
unnecessary.
However, this does not prevent the case where a channel would be closed
and reopened again when someone would hold a stale channel number. In
all such conditions the caller should hold a reference already.
The only conditions where a channel can be safely looked up by an id and
used without taking a ref are when initializing or deinitializing the
list of channels.
Jira NVGPU-1460
Change-Id: I0a30968d17c1e0784d315a676bbe69c03a73481c
Signed-off-by: Konsta Holtta <kholtta@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1955400
Signed-off-by: Debarshi Dutta <ddutta@nvidia.com>
(cherry picked from commit 7df3d587502c2de997dfbe8ea8ddc114d0a0481e
in dev-kernel)
Reviewed-on: https://git-master.nvidia.com/r/2008515
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/vgpu')
-rw-r--r-- | drivers/gpu/nvgpu/vgpu/fifo_vgpu.c | 3 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/vgpu/gr_vgpu.c | 4 | ||||
-rw-r--r-- | drivers/gpu/nvgpu/vgpu/vgpu.c | 2 |
3 files changed, 4 insertions, 5 deletions
diff --git a/drivers/gpu/nvgpu/vgpu/fifo_vgpu.c b/drivers/gpu/nvgpu/vgpu/fifo_vgpu.c index aa5abec9..8821e799 100644 --- a/drivers/gpu/nvgpu/vgpu/fifo_vgpu.c +++ b/drivers/gpu/nvgpu/vgpu/fifo_vgpu.c | |||
@@ -721,8 +721,7 @@ static void vgpu_fifo_set_ctx_mmu_error_ch_tsg(struct gk20a *g, | |||
721 | 721 | ||
722 | int vgpu_fifo_isr(struct gk20a *g, struct tegra_vgpu_fifo_intr_info *info) | 722 | int vgpu_fifo_isr(struct gk20a *g, struct tegra_vgpu_fifo_intr_info *info) |
723 | { | 723 | { |
724 | struct fifo_gk20a *f = &g->fifo; | 724 | struct channel_gk20a *ch = gk20a_channel_from_id(g, info->chid); |
725 | struct channel_gk20a *ch = gk20a_channel_get(&f->channel[info->chid]); | ||
726 | 725 | ||
727 | nvgpu_log_fn(g, " "); | 726 | nvgpu_log_fn(g, " "); |
728 | if (!ch) | 727 | if (!ch) |
diff --git a/drivers/gpu/nvgpu/vgpu/gr_vgpu.c b/drivers/gpu/nvgpu/vgpu/gr_vgpu.c index 9fafa52f..6a86c9a0 100644 --- a/drivers/gpu/nvgpu/vgpu/gr_vgpu.c +++ b/drivers/gpu/nvgpu/vgpu/gr_vgpu.c | |||
@@ -953,10 +953,10 @@ int vgpu_init_gr_support(struct gk20a *g) | |||
953 | 953 | ||
954 | int vgpu_gr_isr(struct gk20a *g, struct tegra_vgpu_gr_intr_info *info) | 954 | int vgpu_gr_isr(struct gk20a *g, struct tegra_vgpu_gr_intr_info *info) |
955 | { | 955 | { |
956 | struct fifo_gk20a *f = &g->fifo; | 956 | struct channel_gk20a *ch = gk20a_channel_from_id(g, info->chid); |
957 | struct channel_gk20a *ch = gk20a_channel_get(&f->channel[info->chid]); | ||
958 | 957 | ||
959 | nvgpu_log_fn(g, " "); | 958 | nvgpu_log_fn(g, " "); |
959 | |||
960 | if (!ch) | 960 | if (!ch) |
961 | return 0; | 961 | return 0; |
962 | 962 | ||
diff --git a/drivers/gpu/nvgpu/vgpu/vgpu.c b/drivers/gpu/nvgpu/vgpu/vgpu.c index 266b801e..07361afe 100644 --- a/drivers/gpu/nvgpu/vgpu/vgpu.c +++ b/drivers/gpu/nvgpu/vgpu/vgpu.c | |||
@@ -119,7 +119,7 @@ static void vgpu_handle_channel_event(struct gk20a *g, | |||
119 | 119 | ||
120 | static void vgpu_channel_abort_cleanup(struct gk20a *g, u32 chid) | 120 | static void vgpu_channel_abort_cleanup(struct gk20a *g, u32 chid) |
121 | { | 121 | { |
122 | struct channel_gk20a *ch = gk20a_channel_get(&g->fifo.channel[chid]); | 122 | struct channel_gk20a *ch = gk20a_channel_from_id(g, chid); |
123 | 123 | ||
124 | if (ch == NULL) { | 124 | if (ch == NULL) { |
125 | nvgpu_err(g, "invalid channel id %d", chid); | 125 | nvgpu_err(g, "invalid channel id %d", chid); |