Skip to content

Commit 0620223

Browse files
James Morserafaeljw
authored andcommitted
mm/memory-failure: Add memory_failure_queue_kick()
The GHES code calls memory_failure_queue() from IRQ context to schedule work on the current CPU so that memory_failure() can sleep. For synchronous memory errors the arch code needs to know any signals that memory_failure() will trigger are pending before it returns to user-space, possibly when exiting from the IRQ. Add a helper to kick the memory failure queue, to ensure the scheduled work has happened. This has to be called from process context, so may have been migrated from the original cpu. Pass the cpu the work was queued on. Change memory_failure_work_func() to permit being called on the 'wrong' cpu. Signed-off-by: James Morse <james.morse@arm.com> Tested-by: Tyler Baicar <baicar@os.amperecomputing.com> Acked-by: Naoya Horiguchi <naoya.horiguchi@nec.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent b9bbe6e commit 0620223

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

include/linux/mm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3012,6 +3012,7 @@ enum mf_flags {
30123012
};
30133013
extern int memory_failure(unsigned long pfn, int flags);
30143014
extern void memory_failure_queue(unsigned long pfn, int flags);
3015+
extern void memory_failure_queue_kick(int cpu);
30153016
extern int unpoison_memory(unsigned long pfn);
30163017
extern int get_hwpoison_page(struct page *page);
30173018
#define put_hwpoison_page(page) put_page(page)

mm/memory-failure.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,7 @@ static void memory_failure_work_func(struct work_struct *work)
14931493
unsigned long proc_flags;
14941494
int gotten;
14951495

1496-
mf_cpu = this_cpu_ptr(&memory_failure_cpu);
1496+
mf_cpu = container_of(work, struct memory_failure_cpu, work);
14971497
for (;;) {
14981498
spin_lock_irqsave(&mf_cpu->lock, proc_flags);
14991499
gotten = kfifo_get(&mf_cpu->fifo, &entry);
@@ -1507,6 +1507,19 @@ static void memory_failure_work_func(struct work_struct *work)
15071507
}
15081508
}
15091509

1510+
/*
1511+
* Process memory_failure work queued on the specified CPU.
1512+
* Used to avoid return-to-userspace racing with the memory_failure workqueue.
1513+
*/
1514+
void memory_failure_queue_kick(int cpu)
1515+
{
1516+
struct memory_failure_cpu *mf_cpu;
1517+
1518+
mf_cpu = &per_cpu(memory_failure_cpu, cpu);
1519+
cancel_work_sync(&mf_cpu->work);
1520+
memory_failure_work_func(&mf_cpu->work);
1521+
}
1522+
15101523
static int __init memory_failure_init(void)
15111524
{
15121525
struct memory_failure_cpu *mf_cpu;

0 commit comments

Comments
 (0)