mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sang-Hoon Choi <csh0052@gmail.com>
To: James Morse <james.morse@arm.com>, Ben Horgan <ben.horgan@arm.com>
Cc: Reinette Chatre <reinette.chatre@intel.com>,
	Fenghua Yu <fenghuay@nvidia.com>,
	linux-kernel@vger.kernel.org, Changyul Lee <lcy8047@gmail.com>
Subject: [PATCH] arm_mpam: return allocation errors as error pointers
Date: Wed, 30 Sep 2026 16:08:58 +0900	[thread overview]
Message-ID: <179075213853.3.16001626385793291460.idr-bug-33@gmail.com> (raw)

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

             reply	other threads:[~2026-09-30  7:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-30  7:08 Sang-Hoon Choi [this message]
2026-10-09 17:18 ` Ben Horgan
2026-10-26 14:41 ` Ben Horgan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=179075213853.3.16001626385793291460.idr-bug-33@gmail.com \
    --to=csh0052@gmail.com \
    --cc=ben.horgan@arm.com \
    --cc=fenghuay@nvidia.com \
    --cc=james.morse@arm.com \
    --cc=lcy8047@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=reinette.chatre@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®