* [PATCH] arm_mpam: return allocation errors as error pointers
@ 2026-09-30 7:08 Sang-Hoon Choi
2026-10-09 17:18 ` Ben Horgan
2026-10-26 14:41 ` Ben Horgan
0 siblings, 2 replies; 3+ messages in thread
From: Sang-Hoon Choi @ 2026-09-30 7:08 UTC (permalink / raw)
To: James Morse, Ben Horgan
Cc: Reinette Chatre, Fenghua Yu, linux-kernel, Changyul Lee
resctrl_arch_mon_ctx_alloc() stores the result of monitor allocation in
an allocated int. If monitor allocation fails, it still returns that pointer.
Callers check IS_ERR(), so they treat the failed allocation as a valid
monitor context and pass the error value on as a monitor index.
For example, if the wait for a free monitor ends because a signal is
pending, the stored result is still -ENOSPC. Other allocation errors
also reach the same return path.
Free the temporary allocation and return ERR_PTR(err) for negative
results. Leave successful indices and USE_PRE_ALLOCATED unchanged.
Fixes: 2a3c79c61539 ("arm_mpam: resctrl: Allow resctrl to allocate monitors")
Reported-by: Changyul Lee <lcy8047@gmail.com>
Link: https://github.com/lcy8047/radix-tree-bug-temp/blob/main/bug_list/idr-ida-xarray/wrong-id-value/IDR-BUG-33-mpam-monitor-id.md
Assisted-by: Sang-Hoon Choi <csh0052@gmail.com>
Signed-off-by: Sang-Hoon Choi <csh0052@gmail.com>
---
Compile-tested on arm64 with allmodconfig and W=1 against mainline
6f8319e3e9a44dd537d17f41565a8453c560a581. No hardware runtime test was
performed.
drivers/resctrl/mpam_resctrl.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
index 9d223057953a..945be7465ad3 100644
--- a/drivers/resctrl/mpam_resctrl.c
+++ b/drivers/resctrl/mpam_resctrl.c
@@ -413,6 +413,13 @@ void *resctrl_arch_mon_ctx_alloc(struct rdt_resource *r,
} while (*ret == -ENOSPC && !signal_pending(current));
finish_wait(&resctrl_mon_ctx_waiters, &wait);
+ if (*ret < 0) {
+ int err = *ret;
+
+ kfree(ret);
+ return ERR_PTR(err);
+ }
+
return ret;
}
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] arm_mpam: return allocation errors as error pointers
2026-09-30 7:08 [PATCH] arm_mpam: return allocation errors as error pointers Sang-Hoon Choi
@ 2026-10-09 17:18 ` Ben Horgan
2026-10-26 14:41 ` Ben Horgan
1 sibling, 0 replies; 3+ messages in thread
From: Ben Horgan @ 2026-10-09 17:18 UTC (permalink / raw)
To: Sang-Hoon Choi, James Morse
Cc: Reinette Chatre, Fenghua Yu, linux-kernel, Changyul Lee
Hi Sang-Hoon,
On 9/30/26 08:08, Sang-Hoon Choi wrote:
> resctrl_arch_mon_ctx_alloc() stores the result of monitor allocation in
> an allocated int. If monitor allocation fails, it still returns that pointer.
> Callers check IS_ERR(), so they treat the failed allocation as a valid
> monitor context and pass the error value on as a monitor index.
>
> For example, if the wait for a free monitor ends because a signal is
> pending, the stored result is still -ENOSPC. Other allocation errors
> also reach the same return path.
Thanks for report and fix. Is this addressing a hypothetical problem or
have you seen resctrl_arch_mon_ctx_alloc() fail?
>
> Free the temporary allocation and return ERR_PTR(err) for negative
> results. Leave successful indices and USE_PRE_ALLOCATED unchanged.
>
> Fixes: 2a3c79c61539 ("arm_mpam: resctrl: Allow resctrl to allocate monitors")
> Reported-by: Changyul Lee <lcy8047@gmail.com>
> Link: https://github.com/lcy8047/radix-tree-bug-temp/blob/main/bug_list/idr-ida-xarray/wrong-id-value/IDR-BUG-33-mpam-monitor-id.md
I don't see anything at this link. This line can just go.
> Assisted-by: Sang-Hoon Choi <csh0052@gmail.com>
Should this be?
Assisted-by: LLM
Thanks,
Ben
> Signed-off-by: Sang-Hoon Choi <csh0052@gmail.com>
> ---
> Compile-tested on arm64 with allmodconfig and W=1 against mainline
> 6f8319e3e9a44dd537d17f41565a8453c560a581. No hardware runtime test was
> performed.
>
> drivers/resctrl/mpam_resctrl.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
> index 9d223057953a..945be7465ad3 100644
> --- a/drivers/resctrl/mpam_resctrl.c
> +++ b/drivers/resctrl/mpam_resctrl.c
> @@ -413,6 +413,13 @@ void *resctrl_arch_mon_ctx_alloc(struct rdt_resource *r,
> } while (*ret == -ENOSPC && !signal_pending(current));
> finish_wait(&resctrl_mon_ctx_waiters, &wait);
>
> + if (*ret < 0) {
> + int err = *ret;
> +
> + kfree(ret);
> + return ERR_PTR(err);
> + }
> +
> return ret;
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] arm_mpam: return allocation errors as error pointers
2026-09-30 7:08 [PATCH] arm_mpam: return allocation errors as error pointers Sang-Hoon Choi
2026-10-09 17:18 ` Ben Horgan
@ 2026-10-26 14:41 ` Ben Horgan
1 sibling, 0 replies; 3+ messages in thread
From: Ben Horgan @ 2026-10-26 14:41 UTC (permalink / raw)
To: Sang-Hoon Choi, James Morse
Cc: Reinette Chatre, Fenghua Yu, linux-kernel, Changyul Lee
Hi Sang-Hoon,
On 30/09/2026 08:08, Sang-Hoon Choi wrote:
> resctrl_arch_mon_ctx_alloc() stores the result of monitor allocation in
> an allocated int. If monitor allocation fails, it still returns that pointer.
> Callers check IS_ERR(), so they treat the failed allocation as a valid
> monitor context and pass the error value on as a monitor index.
>
> For example, if the wait for a free monitor ends because a signal is
> pending, the stored result is still -ENOSPC. Other allocation errors
> also reach the same return path.
>
> Free the temporary allocation and return ERR_PTR(err) for negative
> results. Leave successful indices and USE_PRE_ALLOCATED unchanged.
>
> Fixes: 2a3c79c61539 ("arm_mpam: resctrl: Allow resctrl to allocate monitors")
> Reported-by: Changyul Lee <lcy8047@gmail.com>
> Link: https://github.com/lcy8047/radix-tree-bug-temp/blob/main/bug_list/idr-ida-xarray/wrong-id-value/IDR-BUG-33-mpam-monitor-id.md
> Assisted-by: Sang-Hoon Choi <csh0052@gmail.com>
> Signed-off-by: Sang-Hoon Choi <csh0052@gmail.com>
> ---
> Compile-tested on arm64 with allmodconfig and W=1 against mainline
> 6f8319e3e9a44dd537d17f41565a8453c560a581. No hardware runtime test was
> performed.
>
> drivers/resctrl/mpam_resctrl.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/resctrl/mpam_resctrl.c b/drivers/resctrl/mpam_resctrl.c
> index 9d223057953a..945be7465ad3 100644
> --- a/drivers/resctrl/mpam_resctrl.c
> +++ b/drivers/resctrl/mpam_resctrl.c
> @@ -413,6 +413,13 @@ void *resctrl_arch_mon_ctx_alloc(struct rdt_resource *r,
> } while (*ret == -ENOSPC && !signal_pending(current));
> finish_wait(&resctrl_mon_ctx_waiters, &wait);
>
> + if (*ret < 0) {
> + int err = *ret;
> +
> + kfree(ret);
> + return ERR_PTR(err);
> + }
> +
> return ret;
This seems like a good place to use the cleanup.h helpers, __free(kfree) and then pass on the
pointer with return_ptr(ret).
Thanks,
Ben
> }
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-26 14:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-30 7:08 [PATCH] arm_mpam: return allocation errors as error pointers Sang-Hoon Choi
2026-10-09 17:18 ` Ben Horgan
2026-10-26 14:41 ` Ben Horgan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®