gpu: nvgpu: Correctly plumb -EAGAIN from vidmem allocations

Userspace can and should retry vidmem allocations if there are pending
clears still to be executed by the GPU. But this requires the -EAGAIN
to properly propagate back to userspace.

Bug 200378648

Change-Id: Ib930711270439843e043d65c2e87b60612a76239
Signed-off-by: Alex Waterman <alexw@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/1669099
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Konsta Holtta <kholtta@nvidia.com>
Reviewed-by: Vijayakumar Subbu <vsubbu@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Alex Waterman
2018-03-05 19:03:32 -08:00
committed by mobile promotions
parent 4320877eb4
commit da9b549cd1
2 changed files with 11 additions and 7 deletions

View File

@@ -173,6 +173,8 @@ int nvgpu_vidmem_export_linux(struct gk20a *g, size_t bytes)
if (!gk20a_get(g))
return -ENODEV;
vidmem_dbg(g, "Allocating vidmem buf: %zu bytes", bytes);
priv = nvgpu_kzalloc(g, sizeof(*priv));
if (!priv) {
err = -ENOMEM;
@@ -180,8 +182,8 @@ int nvgpu_vidmem_export_linux(struct gk20a *g, size_t bytes)
}
buf = nvgpu_vidmem_user_alloc(g, bytes);
if (!buf) {
err = -ENOMEM;
if (IS_ERR(buf)) {
err = PTR_ERR(buf);
goto fail;
}

View File

@@ -503,16 +503,18 @@ struct nvgpu_vidmem_buf *nvgpu_vidmem_user_alloc(struct gk20a *g, size_t bytes)
err = nvgpu_vidmem_clear_all(g);
if (err)
return NULL;
return ERR_PTR(-ENOMEM);
buf = nvgpu_kzalloc(g, sizeof(*buf));
if (!buf)
return NULL;
return ERR_PTR(-ENOMEM);
buf->g = g;
buf->mem = nvgpu_kzalloc(g, sizeof(*buf->mem));
if (!buf->mem)
if (!buf->mem) {
err = -ENOMEM;
goto fail;
}
err = nvgpu_dma_alloc_vid(g, bytes, buf->mem);
if (err)
@@ -530,7 +532,7 @@ fail:
/* buf will never be NULL here. */
nvgpu_kfree(g, buf->mem);
nvgpu_kfree(g, buf);
return NULL;
return ERR_PTR(err);
}
void nvgpu_vidmem_buf_free(struct gk20a *g, struct nvgpu_vidmem_buf *buf)
@@ -538,7 +540,7 @@ void nvgpu_vidmem_buf_free(struct gk20a *g, struct nvgpu_vidmem_buf *buf)
/*
* In some error paths it's convenient to be able to "free" a NULL buf.
*/
if (!buf)
if (IS_ERR_OR_NULL(buf))
return;
nvgpu_dma_free(g, buf->mem);