hulk inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9206 ---------------------------------------- In the vstream_hbm_alloc() path, the previous implementation would attempt to automatically allocate a new context if one was not found for the current task. However, HBM (High Bandwidth Memory) allocation should only be permitted for existing AI tasks that already have a valid context. This patch simplifies the control flow by removing the automatic context creation logic. Now, if a valid context is not found for the current task, the function will directly return -ENOENT, effectively preventing invalid HBM region allocations. Fixes: dd2bb45851e5 ("xSched/dmem: introduce xsched_dmem_alloc()") Signed-off-by: Liu Kai <liukai284@huawei.com> --- kernel/xsched/vstream.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/kernel/xsched/vstream.c b/kernel/xsched/vstream.c index 6ece03d3ff22..1a30c205b366 100644 --- a/kernel/xsched/vstream.c +++ b/kernel/xsched/vstream.c @@ -633,7 +633,6 @@ int vstream_kick(struct vstream_args *arg) #ifdef CONFIG_CGROUP_DMEM static int vstream_hbm_alloc(struct vstream_args *arg) { - vstream_info_t vstream_info; struct xsched_cu *xcu_found; struct xsched_context *ctx; int ret = 0; @@ -648,22 +647,13 @@ static int vstream_hbm_alloc(struct vstream_args *arg) /* it will either allocate or find a context */ mutex_lock(&xcu_found->ctx_list_lock); ctx = ctx_find_by_tgid_and_xcu(current->tgid, xcu_found); - if (ctx) { + if (ctx) kref_get(&ctx->kref); - } else { - vstream_info.tgid = current->tgid; - vstream_info.xcu = xcu_found; - vstream_info.dev_id = arg->dev_id; - vstream_info.channel_id = arg->channel_id; - vstream_info.fd = arg->fd; - - ret = alloc_ctx_from_vstream(&vstream_info, &ctx); - } mutex_unlock(&xcu_found->ctx_list_lock); - if (ret != 0) { + if (!ctx) { XSCHED_ERR("Failed to find a context for HBM alloc"); - return ret; + return -ENOENT; } ret = xsched_dmem_alloc(ctx, arg); -- 2.34.1