Skip to content

Commit bf51e2a

Browse files
houlz0507Sasha Levin
authored andcommitted
accel/amdxdna: Remove buffer size check when creating command BO
[ Upstream commit 08fe1b5 ] 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 Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 825f218 commit bf51e2a

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

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
@@ -746,12 +744,6 @@ amdxdna_drm_create_cmd_bo(struct drm_device *dev,
746744
{
747745
struct amdxdna_dev *xdna = to_xdna_dev(dev);
748746
struct amdxdna_gem_obj *abo;
749-
int ret;
750-
751-
if (args->size > XDNA_MAX_CMD_BO_SIZE) {
752-
XDNA_ERR(xdna, "Command bo size 0x%llx too large", args->size);
753-
return ERR_PTR(-EINVAL);
754-
}
755747

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

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

781763
int amdxdna_drm_create_bo_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
@@ -872,6 +854,7 @@ struct amdxdna_gem_obj *amdxdna_gem_get_obj(struct amdxdna_client *client,
872854
struct amdxdna_dev *xdna = client->xdna;
873855
struct amdxdna_gem_obj *abo;
874856
struct drm_gem_object *gobj;
857+
int ret;
875858

876859
gobj = drm_gem_object_lookup(client->filp, bo_hdl);
877860
if (!gobj) {
@@ -880,9 +863,26 @@ struct amdxdna_gem_obj *amdxdna_gem_get_obj(struct amdxdna_client *client,
880863
}
881864

882865
abo = to_xdna_obj(gobj);
883-
if (bo_type == AMDXDNA_BO_INVALID || abo->type == bo_type)
866+
if (bo_type != AMDXDNA_BO_INVALID && abo->type != bo_type)
867+
goto put_obj;
868+
869+
if (bo_type != AMDXDNA_BO_CMD || abo->mem.kva)
884870
return abo;
885871

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

0 commit comments

Comments
 (0)