Skip to content

Commit 340430c

Browse files
ppaalanenIngo Molnar
authored andcommitted
x86 mmiotrace: fix race with release_kmmio_fault_page()
There was a theoretical possibility to a race between arming a page in post_kmmio_handler() and disarming the page in release_kmmio_fault_page(): cpu0 cpu1 ------------------------------------------------------------------ mmiotrace shutdown enter release_kmmio_fault_page fault on the page disarm the page disarm the page handle the MMIO access re-arm the page put the page on release list remove_kmmio_fault_pages() fault on the page page not known to mmiotrace fall back to do_page_fault() *KABOOM* (This scenario also shows the double disarm case which is allowed.) Fixed by acquiring kmmio_lock in post_kmmio_handler() and checking if the page is being released from mmiotrace. Signed-off-by: Pekka Paalanen <[email protected]> Cc: Stuart Bennett <[email protected]> Cc: Steven Rostedt <[email protected]> Signed-off-by: Ingo Molnar <[email protected]>
1 parent 3e39aa1 commit 340430c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

arch/x86/mm/kmmio.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ struct kmmio_fault_page {
3838
/*
3939
* Number of times this page has been registered as a part
4040
* of a probe. If zero, page is disarmed and this may be freed.
41-
* Used only by writers (RCU).
41+
* Used only by writers (RCU) and post_kmmio_handler().
42+
* Protected by kmmio_lock, when linked into kmmio_page_table.
4243
*/
4344
int count;
4445
};
@@ -317,7 +318,11 @@ static int post_kmmio_handler(unsigned long condition, struct pt_regs *regs)
317318
if (ctx->probe && ctx->probe->post_handler)
318319
ctx->probe->post_handler(ctx->probe, condition, regs);
319320

320-
arm_kmmio_fault_page(ctx->fpage);
321+
/* Prevent racing against release_kmmio_fault_page(). */
322+
spin_lock(&kmmio_lock);
323+
if (ctx->fpage->count)
324+
arm_kmmio_fault_page(ctx->fpage);
325+
spin_unlock(&kmmio_lock);
321326

322327
regs->flags &= ~X86_EFLAGS_TF;
323328
regs->flags |= ctx->saved_flags;

0 commit comments

Comments
 (0)