Skip to content

Commit 08fe1b5

Browse files
committed
accel/amdxdna: Remove buffer size check when creating command BO
Large command buffers may be used, and they do not always need to be mapped or accessed by the driver. Performing a size check at command BO creation time unnecessarily rejects valid use cases. Remove the buffer size check from command BO creation, and defer vmap and size validation to the paths where the driver actually needs to map and access the command buffer. Fixes: ac49797 ("accel/amdxdna: Add GEM buffer object management") Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com> Link: https://patch.msgid.link/20260206060237.4050492-1-lizhi.hou@amd.com
1 parent c17ee63 commit 08fe1b5

1 file changed

Lines changed: 19 additions & 19 deletions

File tree

drivers/accel/amdxdna/amdxdna_gem.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include "amdxdna_pci_drv.h"
2222
#include "amdxdna_ubuf.h"
2323

24-
#define XDNA_MAX_CMD_BO_SIZE SZ_32K
25-
2624
MODULE_IMPORT_NS("DMA_BUF");
2725

2826
static int
@@ -745,12 +743,6 @@ amdxdna_drm_create_cmd_bo(struct drm_device *dev,
745743
{
746744
struct amdxdna_dev *xdna = to_xdna_dev(dev);
747745
struct amdxdna_gem_obj *abo;
748-
int ret;
749-
750-
if (args->size > XDNA_MAX_CMD_BO_SIZE) {
751-
XDNA_ERR(xdna, "Command bo size 0x%llx too large", args->size);
752-
return ERR_PTR(-EINVAL);
753-
}
754746

755747
if (args->size < sizeof(struct amdxdna_cmd)) {
756748
XDNA_DBG(xdna, "Command BO size 0x%llx too small", args->size);
@@ -764,17 +756,7 @@ amdxdna_drm_create_cmd_bo(struct drm_device *dev,
764756
abo->type = AMDXDNA_BO_CMD;
765757
abo->client = filp->driver_priv;
766758

767-
ret = amdxdna_gem_obj_vmap(abo, &abo->mem.kva);
768-
if (ret) {
769-
XDNA_ERR(xdna, "Vmap cmd bo failed, ret %d", ret);
770-
goto release_obj;
771-
}
772-
773759
return abo;
774-
775-
release_obj:
776-
drm_gem_object_put(to_gobj(abo));
777-
return ERR_PTR(ret);
778760
}
779761

780762
int amdxdna_drm_create_bo_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
@@ -871,6 +853,7 @@ struct amdxdna_gem_obj *amdxdna_gem_get_obj(struct amdxdna_client *client,
871853
struct amdxdna_dev *xdna = client->xdna;
872854
struct amdxdna_gem_obj *abo;
873855
struct drm_gem_object *gobj;
856+
int ret;
874857

875858
gobj = drm_gem_object_lookup(client->filp, bo_hdl);
876859
if (!gobj) {
@@ -879,9 +862,26 @@ struct amdxdna_gem_obj *amdxdna_gem_get_obj(struct amdxdna_client *client,
879862
}
880863

881864
abo = to_xdna_obj(gobj);
882-
if (bo_type == AMDXDNA_BO_INVALID || abo->type == bo_type)
865+
if (bo_type != AMDXDNA_BO_INVALID && abo->type != bo_type)
866+
goto put_obj;
867+
868+
if (bo_type != AMDXDNA_BO_CMD || abo->mem.kva)
883869
return abo;
884870

871+
if (abo->mem.size > SZ_32K) {
872+
XDNA_ERR(xdna, "Cmd bo is too big %ld", abo->mem.size);
873+
goto put_obj;
874+
}
875+
876+
ret = amdxdna_gem_obj_vmap(abo, &abo->mem.kva);
877+
if (ret) {
878+
XDNA_ERR(xdna, "Vmap cmd bo failed, ret %d", ret);
879+
goto put_obj;
880+
}
881+
882+
return abo;
883+
884+
put_obj:
885885
drm_gem_object_put(gobj);
886886
return NULL;
887887
}

0 commit comments

Comments
 (0)