linux-edac.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: yaozhenguo <yaozhenguo1@gmail.com>
To: tony.luck@intel.com, youquan.song@intel.com
Cc: linux-edac@vger.kernel.org, linux-kernel@vger.kernel.org,
	yaozhenguo@jd.com, yaozhenguo <yaozhenguo1@gmail.com>
Subject: [PATCH] mm,hwpoison: Don't call task_work_add when there is same work in the queue
Date: Fri,  9 Jul 2021 17:28:18 +0800	[thread overview]
Message-ID: <20210709092818.7795-1-yaozhenguo1@gmail.com> (raw)

queue_task_work can be called more than once in one task before
this task work is running. it can lead to task->task_works becomes
an endless loop list and the task will never return to user mode.
Don't call task_work_add when there is same work in the queue.

Signed-off-by: yaozhenguo <yaozhenguo1@gmail.com>
---
 arch/x86/kernel/cpu/mce/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c
index 22791aa..62c67ad 100644
--- a/arch/x86/kernel/cpu/mce/core.c
+++ b/arch/x86/kernel/cpu/mce/core.c
@@ -1299,7 +1299,9 @@ static void queue_task_work(struct mce *m, int kill_current_task)
 	else
 		current->mce_kill_me.func = kill_me_maybe;
 
-	task_work_add(current, &current->mce_kill_me, TWA_RESUME);
+	/* Avoid endless loops in task_work_run */
+	if (READ_ONCE(current->task_works) != &current->mce_kill_me)
+		task_work_add(current, &current->mce_kill_me, TWA_RESUME);
 }
 
 /*
-- 
1.8.3.1


                 reply	other threads:[~2021-07-09  9:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210709092818.7795-1-yaozhenguo1@gmail.com \
    --to=yaozhenguo1@gmail.com \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tony.luck@intel.com \
    --cc=yaozhenguo@jd.com \
    --cc=youquan.song@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;
as well as URLs for NNTP newsgroup(s).