* [PATCH RESEND v2] blk-cgroup: improve policy registration error handling
@ 2025-03-17 2:29 Chen Linxuan
2025-03-17 18:39 ` Tejun Heo
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Chen Linxuan @ 2025-03-17 2:29 UTC (permalink / raw)
To: Tejun Heo, Josef Bacik, Jens Axboe
Cc: Chen Linxuan, Wen Tao, cgroups, linux-block, linux-kernel
This patch improve the returned error code of blkcg_policy_register().
1. Move the validation check for cpd/pd_alloc_fn and cpd/pd_free_fn
function pairs to the start of blkcg_policy_register(). This ensures
we immediately return -EINVAL if the function pairs are not correctly
provided, rather than returning -ENOSPC after locking and unlocking
mutexes unnecessarily.
Those locks should not contention any problems, as error of policy
registration is a super cold path.
2. Return -ENOMEM when cpd_alloc_fn() failed.
Co-authored-by: Wen Tao <wentao@uniontech.com>
Signed-off-by: Wen Tao <wentao@uniontech.com>
Signed-off-by: Chen Linxuan <chenlinxuan@uniontech.com>
---
block/blk-cgroup.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 9ed93d91d754..2609f7294427 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -1727,27 +1727,27 @@ int blkcg_policy_register(struct blkcg_policy *pol)
struct blkcg *blkcg;
int i, ret;
+ /*
+ * Make sure cpd/pd_alloc_fn and cpd/pd_free_fn in pairs, and policy
+ * without pd_alloc_fn/pd_free_fn can't be activated.
+ */
+ if ((!pol->cpd_alloc_fn ^ !pol->cpd_free_fn) ||
+ (!pol->pd_alloc_fn ^ !pol->pd_free_fn))
+ return -EINVAL;
+
mutex_lock(&blkcg_pol_register_mutex);
mutex_lock(&blkcg_pol_mutex);
/* find an empty slot */
- ret = -ENOSPC;
for (i = 0; i < BLKCG_MAX_POLS; i++)
if (!blkcg_policy[i])
break;
if (i >= BLKCG_MAX_POLS) {
pr_warn("blkcg_policy_register: BLKCG_MAX_POLS too small\n");
+ ret = -ENOSPC;
goto err_unlock;
}
- /*
- * Make sure cpd/pd_alloc_fn and cpd/pd_free_fn in pairs, and policy
- * without pd_alloc_fn/pd_free_fn can't be activated.
- */
- if ((!pol->cpd_alloc_fn ^ !pol->cpd_free_fn) ||
- (!pol->pd_alloc_fn ^ !pol->pd_free_fn))
- goto err_unlock;
-
/* register @pol */
pol->plid = i;
blkcg_policy[pol->plid] = pol;
@@ -1758,8 +1758,10 @@ int blkcg_policy_register(struct blkcg_policy *pol)
struct blkcg_policy_data *cpd;
cpd = pol->cpd_alloc_fn(GFP_KERNEL);
- if (!cpd)
+ if (!cpd) {
+ ret = -ENOMEM;
goto err_free_cpds;
+ }
blkcg->cpd[pol->plid] = cpd;
cpd->blkcg = blkcg;
--
2.48.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH RESEND v2] blk-cgroup: improve policy registration error handling
2025-03-17 2:29 [PATCH RESEND v2] blk-cgroup: improve policy registration error handling Chen Linxuan
@ 2025-03-17 18:39 ` Tejun Heo
2025-03-18 15:51 ` Michal Koutný
2025-03-18 18:32 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Tejun Heo @ 2025-03-17 18:39 UTC (permalink / raw)
To: Chen Linxuan
Cc: Josef Bacik, Jens Axboe, Wen Tao, cgroups, linux-block,
linux-kernel
On Mon, Mar 17, 2025 at 10:29:24AM +0800, Chen Linxuan wrote:
> This patch improve the returned error code of blkcg_policy_register().
>
> 1. Move the validation check for cpd/pd_alloc_fn and cpd/pd_free_fn
> function pairs to the start of blkcg_policy_register(). This ensures
> we immediately return -EINVAL if the function pairs are not correctly
> provided, rather than returning -ENOSPC after locking and unlocking
> mutexes unnecessarily.
>
> Those locks should not contention any problems, as error of policy
> registration is a super cold path.
>
> 2. Return -ENOMEM when cpd_alloc_fn() failed.
>
> Co-authored-by: Wen Tao <wentao@uniontech.com>
> Signed-off-by: Wen Tao <wentao@uniontech.com>
> Signed-off-by: Chen Linxuan <chenlinxuan@uniontech.com>
Acked-by: Tejun Heo <tj@kernel.org>
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH RESEND v2] blk-cgroup: improve policy registration error handling
2025-03-17 2:29 [PATCH RESEND v2] blk-cgroup: improve policy registration error handling Chen Linxuan
2025-03-17 18:39 ` Tejun Heo
@ 2025-03-18 15:51 ` Michal Koutný
2025-03-18 18:32 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Michal Koutný @ 2025-03-18 15:51 UTC (permalink / raw)
To: Chen Linxuan
Cc: Tejun Heo, Josef Bacik, Jens Axboe, Wen Tao, cgroups, linux-block,
linux-kernel
[-- Attachment #1: Type: text/plain, Size: 988 bytes --]
On Mon, Mar 17, 2025 at 10:29:24AM +0800, Chen Linxuan <chenlinxuan@uniontech.com> wrote:
> This patch improve the returned error code of blkcg_policy_register().
>
> 1. Move the validation check for cpd/pd_alloc_fn and cpd/pd_free_fn
> function pairs to the start of blkcg_policy_register(). This ensures
> we immediately return -EINVAL if the function pairs are not correctly
> provided, rather than returning -ENOSPC after locking and unlocking
> mutexes unnecessarily.
>
> Those locks should not contention any problems, as error of policy
> registration is a super cold path.
>
> 2. Return -ENOMEM when cpd_alloc_fn() failed.
>
> Co-authored-by: Wen Tao <wentao@uniontech.com>
> Signed-off-by: Wen Tao <wentao@uniontech.com>
> Signed-off-by: Chen Linxuan <chenlinxuan@uniontech.com>
> ---
> block/blk-cgroup.c | 22 ++++++++++++----------
> 1 file changed, 12 insertions(+), 10 deletions(-)
Reviewed-by: Michal Koutný <mkoutny@suse.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH RESEND v2] blk-cgroup: improve policy registration error handling
2025-03-17 2:29 [PATCH RESEND v2] blk-cgroup: improve policy registration error handling Chen Linxuan
2025-03-17 18:39 ` Tejun Heo
2025-03-18 15:51 ` Michal Koutný
@ 2025-03-18 18:32 ` Jens Axboe
2 siblings, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2025-03-18 18:32 UTC (permalink / raw)
To: Tejun Heo, Josef Bacik, Chen Linxuan
Cc: Wen Tao, cgroups, linux-block, linux-kernel
On Mon, 17 Mar 2025 10:29:24 +0800, Chen Linxuan wrote:
> This patch improve the returned error code of blkcg_policy_register().
>
> 1. Move the validation check for cpd/pd_alloc_fn and cpd/pd_free_fn
> function pairs to the start of blkcg_policy_register(). This ensures
> we immediately return -EINVAL if the function pairs are not correctly
> provided, rather than returning -ENOSPC after locking and unlocking
> mutexes unnecessarily.
>
> [...]
Applied, thanks!
[1/1] blk-cgroup: improve policy registration error handling
commit: e1a0202c6bfda24002a3ae2115154fa90104c649
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-18 18:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-17 2:29 [PATCH RESEND v2] blk-cgroup: improve policy registration error handling Chen Linxuan
2025-03-17 18:39 ` Tejun Heo
2025-03-18 15:51 ` Michal Koutný
2025-03-18 18:32 ` Jens Axboe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox