hulk inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/8697 ---------------------------------------- To properly release device memory (dmem) regions allocated from an xsched_dmem_pool, the pool must retain knowledge of the size of each allocated region. Currently, this information is not stored, making it impossible to safely free variable-sized dmem allocations. This commit adds a 'size' member to struct xsched_dmem_pool to record the total size of the underlying dmem region. This enables correct deallocation via the device memory management interface, which requires both the base address and the allocation size. The change is minimal and backward-compatible, as the new field is only used during pool teardown or explicit dmem release paths. Fixes: ff8b804d8161 ("xsched/dmem: introduce xsched_dmem_free()") Signed-off-by: Liu Kai <liukai284@huawei.com> --- kernel/xsched/dmem.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/kernel/xsched/dmem.c b/kernel/xsched/dmem.c index b202aac6a693..05e93d564808 100644 --- a/kernel/xsched/dmem.c +++ b/kernel/xsched/dmem.c @@ -27,6 +27,7 @@ static struct dmem_cgroup_region *hbm_regions[XSCHED_NR_CUS]; struct xsched_dmem_pool { uint64_t id; + uint64_t size; struct dmem_cgroup_pool_state *pool; struct list_head pool_node; }; @@ -89,6 +90,7 @@ int xsched_dmem_alloc(struct xsched_context *ctx, struct vstream_args *args) } new_pool->pool = ret_pool; + new_pool->size = args->vh_args.size; /* protect list using ctx_lock */ spin_lock(&ctx->ctx_lock); @@ -98,7 +100,7 @@ int xsched_dmem_alloc(struct xsched_context *ctx, struct vstream_args *args) args->vh_args.pool_id = new_pool->id; XSCHED_DEBUG("charged %llu bytes, new_alloc = %p with id %llu", - args->vh_args.size, new_pool, new_pool->id); + new_pool->size, new_pool, new_pool->id); return 0; @@ -112,10 +114,11 @@ int xsched_dmem_alloc(struct xsched_context *ctx, struct vstream_args *args) int xsched_dmem_free(struct xsched_context *ctx, struct vstream_args *args) { struct xsched_dmem_pool *pool, *target = NULL; + uint64_t pool_id = args->vh_args.pool_id; spin_lock(&ctx->ctx_lock); list_for_each_entry(pool, &ctx->pool_list, pool_node) { - if (pool->id == args->vh_args.pool_id) { + if (pool->id == pool_id) { list_del(&pool->pool_node); target = pool; break; @@ -124,13 +127,13 @@ int xsched_dmem_free(struct xsched_context *ctx, struct vstream_args *args) spin_unlock(&ctx->ctx_lock); if (!target) { - XSCHED_ERR("pool with id %llu is not found\n", args->vh_args.pool_id); + XSCHED_ERR("pool with id %llu is not found\n", pool_id); return -EINVAL; } XSCHED_DEBUG("uncharged %llu bytes for pool = %p with id %llu\n", - args->vh_args.size, target, target->id); - dmem_cgroup_uncharge(target->pool, args->vh_args.size); + target->size, target, target->id); + dmem_cgroup_uncharge(target->pool, target->size); kfree(target); return 0; -- 2.34.1