[PATCH 1/5] cgroup/dmem: Return error when setting max below current usage

Thomas Hellström
2026-03-27T12:41:50Z

Return -EBUSY to userspace when writing dmem.max below the cgroup's
current device memory usage, rather than silently leaving the limit
unchanged.

Assisted-by: GitHub Copilot:claude-sonnet-4.6
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
kernel/cgroup/dmem.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/kernel/cgroup/dmem.c b/kernel/cgroup/dmem.c
index 9d95824dc6fa..3e6d4c0b26a1 100644
--- a/kernel/cgroup/dmem.c
+++ b/kernel/cgroup/dmem.c
@@ -144,22 +144,24 @@ static void free_cg_pool(struct dmem_cgroup_pool_state *pool)
dmemcg_pool_put(pool);
}

-static void
+static int
set_resource_min(struct dmem_cgroup_pool_state *pool, u64 val)
{
page_counter_set_min(&pool->cnt, val);
+ return 0;
}

-static void
+static int
set_resource_low(struct dmem_cgroup_pool_state *pool, u64 val)
{
page_counter_set_low(&pool->cnt, val);
+ return 0;
}

-static void
+static int
set_resource_max(struct dmem_cgroup_pool_state *pool, u64 val)
{
- page_counter_set_max(&pool->cnt, val);
+ return page_counter_set_max(&pool->cnt, val);
}

static u64 get_resource_low(struct dmem_cgroup_pool_state *pool)
@@ -726,7 +728,7 @@ static int dmemcg_parse_limit(char *options, struct dmem_cgroup_region *region,

static ssize_t dmemcg_limit_write(struct kernfs_open_file *of,
char *buf, size_t nbytes, loff_t off,
- void (*apply)(struct dmem_cgroup_pool_state *, u64))
+ int (*apply)(struct dmem_cgroup_pool_state *, u64))
{
struct dmemcg_state *dmemcs = css_to_dmemcs(of_css(of));
int err = 0;
@@ -773,7 +775,7 @@ static ssize_t dmemcg_limit_write(struct kernfs_open_file *of,
}

/* And commit */
- apply(pool, new_limit);
+ err = apply(pool, new_limit);
dmemcg_pool_put(pool);

out_put:
--
2.53.0