提交 1681616f 编写于 作者: P Peter Zijlstra 提交者: Caspar Zhang

x86/mce: Send #MC singal from task work

fix #29415191

commit 5567d11c21a1d508a91a8cb64a819783a0835d9f upstream

Convert #MC over to using task_work_add(); it will run the same code
slightly later, on the return to user path of the same exception.
Signed-off-by: NPeter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
Reviewed-by: NFrederic Weisbecker <frederic@kernel.org>
Reviewed-by: NAlexandre Chartre <alexandre.chartre@oracle.com>
Link: https://lkml.kernel.org/r/20200505134100.957390899@linutronix.deSigned-off-by: NYouquan Song <youquan.song@intel.com>
Signed-off-by: NWetp Zhang <wetp.zy@linux.alibaba.com>
Reviewed-by: NArtie Ding <artie.ding@linux.alibaba.com>
上级 432c4786
...@@ -43,6 +43,7 @@ ...@@ -43,6 +43,7 @@
#include <linux/export.h> #include <linux/export.h>
#include <linux/jump_label.h> #include <linux/jump_label.h>
#include <linux/set_memory.h> #include <linux/set_memory.h>
#include <linux/task_work.h>
#include <asm/intel-family.h> #include <asm/intel-family.h>
#include <asm/processor.h> #include <asm/processor.h>
...@@ -1099,23 +1100,6 @@ static void mce_clear_state(unsigned long *toclear) ...@@ -1099,23 +1100,6 @@ static void mce_clear_state(unsigned long *toclear)
} }
} }
static int do_memory_failure(struct mce *m)
{
int flags = MF_ACTION_REQUIRED;
int ret;
pr_err("Uncorrected hardware memory error in user-access at %llx", m->addr);
if (!(m->mcgstatus & MCG_STATUS_RIPV))
flags |= MF_MUST_KILL;
ret = memory_failure(m->addr >> PAGE_SHIFT, flags);
if (ret)
pr_err("Memory error not recovered");
else
set_mce_nospec(m->addr >> PAGE_SHIFT, whole_page(m));
return ret;
}
/* /*
* Cases where we avoid rendezvous handler timeout: * Cases where we avoid rendezvous handler timeout:
* 1) If this CPU is offline. * 1) If this CPU is offline.
...@@ -1210,6 +1194,29 @@ static void __mc_scan_banks(struct mce *m, struct mce *final, ...@@ -1210,6 +1194,29 @@ static void __mc_scan_banks(struct mce *m, struct mce *final,
*m = *final; *m = *final;
} }
static void kill_me_now(struct callback_head *ch)
{
force_sig(SIGBUS, current);
}
static void kill_me_maybe(struct callback_head *cb)
{
struct task_struct *p = container_of(cb, struct task_struct, mce_kill_me);
int flags = MF_ACTION_REQUIRED;
pr_err("Uncorrected hardware memory error in user-access at %llx", p->mce_addr);
if (!p->mce_ripv)
flags |= MF_MUST_KILL;
if (!memory_failure(p->mce_addr >> PAGE_SHIFT, flags)) {
set_mce_nospec(p->mce_addr >> PAGE_SHIFT, p->mce_whole_page);
return;
}
pr_err("Memory error not recovered");
kill_me_now(cb);
}
/* /*
* The actual machine check handler. This only handles real * The actual machine check handler. This only handles real
* exceptions when something got corrupted coming in through int 18. * exceptions when something got corrupted coming in through int 18.
...@@ -1352,13 +1359,13 @@ void do_machine_check(struct pt_regs *regs, long error_code) ...@@ -1352,13 +1359,13 @@ void do_machine_check(struct pt_regs *regs, long error_code)
if ((m.cs & 3) == 3) { if ((m.cs & 3) == 3) {
/* If this triggers there is no way to recover. Die hard. */ /* If this triggers there is no way to recover. Die hard. */
BUG_ON(!on_thread_stack() || !user_mode(regs)); BUG_ON(!on_thread_stack() || !user_mode(regs));
local_irq_enable(); current->mce_addr = m.addr;
preempt_enable(); current->mce_ripv = !!(m.mcgstatus & MCG_STATUS_RIPV);
current->mce_whole_page = whole_page(&m);
if (kill_it || do_memory_failure(&m)) current->mce_kill_me.func = kill_me_maybe;
force_sig(SIGBUS, current); if (kill_it)
preempt_disable(); current->mce_kill_me.func = kill_me_now;
local_irq_disable(); task_work_add(current, &current->mce_kill_me, true);
} else { } else {
if (!fixup_exception(regs, X86_TRAP_MC)) if (!fixup_exception(regs, X86_TRAP_MC))
mce_panic("Failed kernel mode recovery", &m, NULL); mce_panic("Failed kernel mode recovery", &m, NULL);
......
...@@ -1246,7 +1246,14 @@ struct task_struct { ...@@ -1246,7 +1246,14 @@ struct task_struct {
struct bio *wait_bio; struct bio *wait_bio;
}; };
unsigned long wait_moment; unsigned long wait_moment;
#ifdef CONFIG_X86_MCE
u64 mce_addr;
__u64 mce_ripv : 1,
mce_whole_page : 1,
__mce_reserved : 62;
struct callback_head mce_kill_me;
#endif
ALI_HOTFIX_RESERVE(1) ALI_HOTFIX_RESERVE(1)
ALI_HOTFIX_RESERVE(2) ALI_HOTFIX_RESERVE(2)
ALI_HOTFIX_RESERVE(3) ALI_HOTFIX_RESERVE(3)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册