From: Cong Wang <xiyou.wangcong@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: linux-edac@vger.kernel.org, Cong Wang <xiyou.wangcong@gmail.com>,
Tony Luck <tony.luck@intel.com>, Borislav Petkov <bp@alien8.de>,
Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH v2 2/2] ras: close the race condition with timer
Date: Tue, 16 Apr 2019 14:33:51 -0700 [thread overview]
Message-ID: <20190416213351.28999-2-xiyou.wangcong@gmail.com> (raw)
Message-ID: <20190416213351.LZcRXRL1pq6_4KGfi9OUKpGRkx4JY9q2DDwikRSIve8@z> (raw)
In-Reply-To: <20190416213351.28999-1-xiyou.wangcong@gmail.com>
cec_timer_fn() is a timer callback which reads ce_arr.array[]
and updates its decay values. Elements could be added to or
removed from this global array in parallel, although the array
itself will not grow or shrink. del_lru_elem_unlocked() uses
FULL_COUNT() as a key to find a right element to remove,
which could be affected by the parallel timer.
Fix this by converting the timer to a delayed work as suggested
by Borislav, to avoid using spinlock.
Fixes: 011d82611172 ("RAS: Add a Corrected Errors Collector")
Cc: Tony Luck <tony.luck@intel.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
drivers/ras/cec.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/drivers/ras/cec.c b/drivers/ras/cec.c
index a4ff54e50673..5c2040a7389d 100644
--- a/drivers/ras/cec.c
+++ b/drivers/ras/cec.c
@@ -2,6 +2,7 @@
#include <linux/mm.h>
#include <linux/gfp.h>
#include <linux/kernel.h>
+#include <linux/workqueue.h>
#include <asm/mce.h>
@@ -131,7 +132,7 @@ static unsigned int count_threshold = COUNT_MASK;
#define CEC_TIMER_DEFAULT_INTERVAL 24 * 60 * 60 /* 24 hrs */
#define CEC_TIMER_MIN_INTERVAL 1 * 60 * 60 /* 1h */
#define CEC_TIMER_MAX_INTERVAL 30 * 24 * 60 * 60 /* one month */
-static struct timer_list cec_timer;
+static struct delayed_work cec_work;
static u64 timer_interval = CEC_TIMER_DEFAULT_INTERVAL;
/*
@@ -160,20 +161,21 @@ static void do_spring_cleaning(struct ce_array *ca)
/*
* @interval in seconds
*/
-static void cec_mod_timer(struct timer_list *t, unsigned long interval)
+static void cec_mod_work(unsigned long interval)
{
unsigned long iv;
- iv = interval * HZ + jiffies;
-
- mod_timer(t, round_jiffies(iv));
+ iv = interval * HZ;
+ mod_delayed_work(system_wq, &cec_work, round_jiffies(iv));
}
-static void cec_timer_fn(struct timer_list *unused)
+static void cec_work_fn(struct work_struct *work)
{
+ mutex_lock(&ce_mutex);
do_spring_cleaning(&ce_arr);
+ mutex_unlock(&ce_mutex);
- cec_mod_timer(&cec_timer, timer_interval);
+ cec_mod_work(timer_interval);
}
/*
@@ -383,7 +385,7 @@ static int decay_interval_set(void *data, u64 val)
timer_interval = val;
- cec_mod_timer(&cec_timer, timer_interval);
+ cec_mod_work(timer_interval);
return 0;
}
DEFINE_DEBUGFS_ATTRIBUTE(decay_interval_ops, u64_get, decay_interval_set, "%lld\n");
@@ -509,8 +511,8 @@ void __init cec_init(void)
if (create_debugfs_nodes())
return;
- timer_setup(&cec_timer, cec_timer_fn, 0);
- cec_mod_timer(&cec_timer, CEC_TIMER_DEFAULT_INTERVAL);
+ INIT_DELAYED_WORK(&cec_work, cec_work_fn);
+ schedule_delayed_work(&cec_work, CEC_TIMER_DEFAULT_INTERVAL);
pr_info("Correctable Errors collector initialized.\n");
}
--
2.20.1
next prev parent reply other threads:[~2019-04-16 21:34 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-16 21:33 [v2,1/2] ras: fix an off-by-one error in __find_elem() Cong Wang
2019-04-16 21:33 ` [PATCH v2 1/2] " Cong Wang
2019-04-16 21:33 ` Cong Wang [this message]
2019-04-16 21:33 ` [PATCH v2 2/2] ras: close the race condition with timer Cong Wang
2019-06-08 15:28 ` [tip:ras/urgent] RAS/CEC: Convert the timer callback to a workqueue tip-bot for Cong Wang
2019-04-16 21:46 ` [v2,1/2] ras: fix an off-by-one error in __find_elem() Borislav Petkov
2019-04-16 21:46 ` [PATCH v2 1/2] " Borislav Petkov
2019-04-16 23:16 ` [v2,1/2] " Cong Wang
2019-04-16 23:16 ` [PATCH v2 1/2] " Cong Wang
2019-04-20 11:34 ` [v2,1/2] " Borislav Petkov
2019-04-20 11:34 ` [PATCH v2 1/2] " Borislav Petkov
2019-04-20 18:25 ` [v2,1/2] " Cong Wang
2019-04-20 18:25 ` [PATCH v2 1/2] " Cong Wang
2019-04-20 19:04 ` [v2,1/2] " Borislav Petkov
2019-04-20 19:04 ` [PATCH v2 1/2] " Borislav Petkov
2019-04-20 19:15 ` [v2,1/2] " Cong Wang
2019-04-20 19:15 ` [PATCH v2 1/2] " Cong Wang
2019-04-21 8:27 ` [v2,1/2] " Borislav Petkov
2019-04-21 8:27 ` [PATCH v2 1/2] " Borislav Petkov
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=20190416213351.28999-2-xiyou.wangcong@gmail.com \
--to=xiyou.wangcong@gmail.com \
--cc=bp@alien8.de \
--cc=linux-edac@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tglx@linutronix.de \
--cc=tony.luck@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).