[PATCH OLK-6.6] ucounts: fix mq_perf test error.

hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/IC97W5 ---------------------------------------------------------------------- The mq_perf_tests reported an error in the rlimit test. This issue stems from commit d8043c5873a0 ("ucounts: reimplement rlimit with percpu_counter "), which introduced a limit parameter as an input. However, since the limit parameter is of type 'long', when RLIM_INFINITY is passed as input, the computed maximum value may become less than 0. This unexpected behavior leads to the test failure. Fixes: d8043c5873a0 ("ucounts: reinplement rlimit with percpu_counter") Signed-off-by: Chen Ridong <chenridong@huawei.com> --- include/linux/user_namespace.h | 5 +++-- kernel/ucount.c | 14 +++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h index 37517ed7489a4..aa8594e18ddc5 100644 --- a/include/linux/user_namespace.h +++ b/include/linux/user_namespace.h @@ -165,7 +165,8 @@ static inline long get_rlimit_value(struct ucounts *ucounts, enum rlimit_type ty #endif } -long inc_rlimit_ucounts_limit(struct ucounts *ucounts, enum rlimit_type type, long v, long limit); +long inc_rlimit_ucounts_limit(struct ucounts *ucounts, enum rlimit_type type, + long v, unsigned long limit); static inline long inc_rlimit_ucounts(struct ucounts *ucounts, enum rlimit_type type, long v) { return inc_rlimit_ucounts_limit(ucounts, type, v, LONG_MAX); @@ -173,7 +174,7 @@ static inline long inc_rlimit_ucounts(struct ucounts *ucounts, enum rlimit_type bool dec_rlimit_ucounts(struct ucounts *ucounts, enum rlimit_type type, long v); long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type, - bool override_rlimit, long limit); + bool override_rlimit, unsigned long limit); void dec_rlimit_put_ucounts(struct ucounts *ucounts, enum rlimit_type type); bool is_rlimit_overlimit(struct ucounts *ucounts, enum rlimit_type type, unsigned long max); diff --git a/kernel/ucount.c b/kernel/ucount.c index 20145f12ee3a8..e4fee03aa1782 100644 --- a/kernel/ucount.c +++ b/kernel/ucount.c @@ -323,14 +323,14 @@ void dec_ucount(struct ucounts *ucounts, enum ucount_type type) #ifdef CONFIG_UCOUNTS_PERCPU_COUNTER /* Return 1 if increments successful, otherwise return LONG_MAX. */ long inc_rlimit_ucounts_limit(struct ucounts *ucounts, enum rlimit_type type, - long v, long limit) + long v, unsigned long limit) { struct ucounts *iter; long max = LONG_MAX; bool over_limit = false; for (iter = ucounts; iter; iter = iter->ns->ucounts) { - max = min(limit, max); + max = limit < max ? limit : max; if (!percpu_counter_limited_add(&iter->rlimit[type], max, v)) over_limit = true; @@ -387,18 +387,18 @@ void dec_rlimit_put_ucounts(struct ucounts *ucounts, enum rlimit_type type) * Return 1 if increments successful, otherwise return 0. */ long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type, - bool override_rlimit, long limit) + bool override_rlimit, unsigned long limit) { struct ucounts *iter; long max = LONG_MAX; - long in_limit = limit; + unsigned long in_limit = limit; if (override_rlimit) in_limit = LONG_MAX; for (iter = ucounts; iter; iter = iter->ns->ucounts) { /* Can not exceed the limit(inputed) or the ns->rlimit_max */ - max = min(in_limit, max); + max = in_limit < max ? in_limit : max; if (!percpu_counter_limited_add(&iter->rlimit[type], max, 1)) goto dec_unwind; @@ -420,7 +420,7 @@ void __init ucounts_init(void) #else long inc_rlimit_ucounts_limit(struct ucounts *ucounts, enum rlimit_type type, - long v, long limit) + long v, unsigned long limit) { struct ucounts *iter; long max = LONG_MAX; @@ -469,7 +469,7 @@ void dec_rlimit_put_ucounts(struct ucounts *ucounts, enum rlimit_type type) } long inc_rlimit_get_ucounts(struct ucounts *ucounts, enum rlimit_type type, - bool override_rlimit, long limit) + bool override_rlimit, unsigned long limit) { /* Caller must hold a reference to ucounts */ struct ucounts *iter; -- 2.34.1

反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/17362 邮件列表地址:https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/SGY... FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/17362 Mailing list address: https://mailweb.openeuler.org/archives/list/kernel@openeuler.org/message/SGY...
participants (2)
-
Chen Ridong
-
patchwork bot