Skip to contentSkip to conversation

cxl: Fix struct pid leak when attaching a process through user API

PATCH In review Frederic Barrat 4 participants 5 messages Nov 3, 2015 – Jan 26, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cxl: Fix struct pid leak when attaching a process through user API

When the cxl driver creates a context, it stores the pid of the calling task, and mistakenly increments the reference count of the struct pid twice, once through get_task_pid(), once through get_pid(). The reference count is only decremented once on detach. As a result, a struct pid is leaked and it reduces the number of processes that can run simultaneously by one.
The fix is to simply remove the call to get_pid().

There is a separate patch for the kernel API, since it goes to different kernel versions.

---
 drivers/misc/cxl/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/misc/cxl/file.c +1 -1
index 7ccd299..97003ee 100644
@@ -199,7 +199,7 @@ static long afu_ioctl_start_work(struct cxl_context *ctx,
 	 * behalf of another process, so the AFU's mm gets bound to the process
 	 * that performs this ioctl and not the process that opened the file.
 	 */
-	ctx->pid = get_pid(get_task_pid(current, PIDTYPE_PID));
+	ctx->pid = get_task_pid(current, PIDTYPE_PID);
 
 	trace_cxl_attach(ctx, work.work_element_descriptor, work.num_interrupts, amr);
 
Signature · 1 line
1.9.1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Frederic Barrat
Quoted 8 lines · Frederic Barrat

When the cxl driver creates a context, it stores the pid of the calling task, and mistakenly increments the reference count of the struct pid twice, once through get_task_pid(), once through get_pid(). The reference count is only decremented once on detach. As a result, a struct pid is leaked and it reduces the number of processes that can run simultaneously by one.
The fix is to simply remove the call to get_pid().

Quoted 5 lines

There is a separate patch for the kernel API, since it goes to different kernel versions.

Signature · 3 lines
Andrew Donnellan              Software Engineer, OzLabs
[email protected]  Australia Development Lab, Canberra
+61 2 6201 8874 (work)        IBM Australia Limited
#3 lore raw
In reply to Frederic Barrat
Quoted 8 lines · Frederic Barrat

When the cxl driver creates a context, it stores the pid of the calling task, and mistakenly increments the reference count of the struct pid twice, once through get_task_pid(), once through get_pid(). The reference count is only decremented once on detach. As a result, a struct pid is leaked and it reduces the number of processes that can run simultaneously by one.
The fix is to simply remove the call to get_pid().

Quoted 7 lines

There is a separate patch for the kernel API, since it goes to different kernel versions.

This no longer applies, since we merged 7b8ad495d592 ("cxl: Fix DSI misses when the context owning task exits").

Please resend if it's still applicable.

cheers

#4 lore raw
Quoted 2 lines · Michael Ellerman

This no longer applies, since we merged 7b8ad495d592 ("cxl: Fix DSI misses when the context owning task exits").

Yes, on 4.5, it has been superseded by 7b8ad495d592. It may still be worth considering for stable releases though.

Fred