Commit f763cf8e authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'ras-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull RAS fixes from Thomas Gleixner:
 "Two small fixes for RAS:

   - Use a proper search algorithm to find the correct element in the
     CEC array. The replacement was a better choice than fixing the
     crash causes by the original search function with horrible duct
     tape.

   - Move the timer based decay function into thread context so it can
     actually acquire the mutex which protects the CEC array to prevent
     corruption"

* 'ras-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  RAS/CEC: Convert the timer callback to a workqueue
  RAS/CEC: Fix binary search function
parents e01e060f 0ade0b62
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/gfp.h> #include <linux/gfp.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/workqueue.h>
#include <asm/mce.h> #include <asm/mce.h>
...@@ -123,16 +124,12 @@ static u64 dfs_pfn; ...@@ -123,16 +124,12 @@ static u64 dfs_pfn;
/* Amount of errors after which we offline */ /* Amount of errors after which we offline */
static unsigned int count_threshold = COUNT_MASK; static unsigned int count_threshold = COUNT_MASK;
/* /* Each element "decays" each decay_interval which is 24hrs by default. */
* The timer "decays" element count each timer_interval which is 24hrs by #define CEC_DECAY_DEFAULT_INTERVAL 24 * 60 * 60 /* 24 hrs */
* default. #define CEC_DECAY_MIN_INTERVAL 1 * 60 * 60 /* 1h */
*/ #define CEC_DECAY_MAX_INTERVAL 30 * 24 * 60 * 60 /* one month */
static struct delayed_work cec_work;
#define CEC_TIMER_DEFAULT_INTERVAL 24 * 60 * 60 /* 24 hrs */ static u64 decay_interval = CEC_DECAY_DEFAULT_INTERVAL;
#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 u64 timer_interval = CEC_TIMER_DEFAULT_INTERVAL;
/* /*
* Decrement decay value. We're using DECAY_BITS bits to denote decay of an * Decrement decay value. We're using DECAY_BITS bits to denote decay of an
...@@ -160,20 +157,21 @@ static void do_spring_cleaning(struct ce_array *ca) ...@@ -160,20 +157,21 @@ static void do_spring_cleaning(struct ce_array *ca)
/* /*
* @interval in seconds * @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; unsigned long iv;
iv = interval * HZ + jiffies; iv = interval * HZ;
mod_delayed_work(system_wq, &cec_work, round_jiffies(iv));
mod_timer(t, 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); do_spring_cleaning(&ce_arr);
mutex_unlock(&ce_mutex);
cec_mod_timer(&cec_timer, timer_interval); cec_mod_work(decay_interval);
} }
/* /*
...@@ -183,32 +181,38 @@ static void cec_timer_fn(struct timer_list *unused) ...@@ -183,32 +181,38 @@ static void cec_timer_fn(struct timer_list *unused)
*/ */
static int __find_elem(struct ce_array *ca, u64 pfn, unsigned int *to) static int __find_elem(struct ce_array *ca, u64 pfn, unsigned int *to)
{ {
int min = 0, max = ca->n - 1;
u64 this_pfn; u64 this_pfn;
int min = 0, max = ca->n;
while (min < max) { while (min <= max) {
int tmp = (max + min) >> 1; int i = (min + max) >> 1;
this_pfn = PFN(ca->array[tmp]); this_pfn = PFN(ca->array[i]);
if (this_pfn < pfn) if (this_pfn < pfn)
min = tmp + 1; min = i + 1;
else if (this_pfn > pfn) else if (this_pfn > pfn)
max = tmp; max = i - 1;
else { else if (this_pfn == pfn) {
min = tmp; if (to)
break; *to = i;
return i;
} }
} }
/*
* When the loop terminates without finding @pfn, min has the index of
* the element slot where the new @pfn should be inserted. The loop
* terminates when min > max, which means the min index points to the
* bigger element while the max index to the smaller element, in-between
* which the new @pfn belongs to.
*
* For more details, see exercise 1, Section 6.2.1 in TAOCP, vol. 3.
*/
if (to) if (to)
*to = min; *to = min;
this_pfn = PFN(ca->array[min]);
if (this_pfn == pfn)
return min;
return -ENOKEY; return -ENOKEY;
} }
...@@ -374,15 +378,15 @@ static int decay_interval_set(void *data, u64 val) ...@@ -374,15 +378,15 @@ static int decay_interval_set(void *data, u64 val)
{ {
*(u64 *)data = val; *(u64 *)data = val;
if (val < CEC_TIMER_MIN_INTERVAL) if (val < CEC_DECAY_MIN_INTERVAL)
return -EINVAL; return -EINVAL;
if (val > CEC_TIMER_MAX_INTERVAL) if (val > CEC_DECAY_MAX_INTERVAL)
return -EINVAL; return -EINVAL;
timer_interval = val; decay_interval = val;
cec_mod_timer(&cec_timer, timer_interval); cec_mod_work(decay_interval);
return 0; return 0;
} }
DEFINE_DEBUGFS_ATTRIBUTE(decay_interval_ops, u64_get, decay_interval_set, "%lld\n"); DEFINE_DEBUGFS_ATTRIBUTE(decay_interval_ops, u64_get, decay_interval_set, "%lld\n");
...@@ -426,7 +430,7 @@ static int array_dump(struct seq_file *m, void *v) ...@@ -426,7 +430,7 @@ static int array_dump(struct seq_file *m, void *v)
seq_printf(m, "Flags: 0x%x\n", ca->flags); seq_printf(m, "Flags: 0x%x\n", ca->flags);
seq_printf(m, "Timer interval: %lld seconds\n", timer_interval); seq_printf(m, "Decay interval: %lld seconds\n", decay_interval);
seq_printf(m, "Decays: %lld\n", ca->decays_done); seq_printf(m, "Decays: %lld\n", ca->decays_done);
seq_printf(m, "Action threshold: %d\n", count_threshold); seq_printf(m, "Action threshold: %d\n", count_threshold);
...@@ -472,7 +476,7 @@ static int __init create_debugfs_nodes(void) ...@@ -472,7 +476,7 @@ static int __init create_debugfs_nodes(void)
} }
decay = debugfs_create_file("decay_interval", S_IRUSR | S_IWUSR, d, decay = debugfs_create_file("decay_interval", S_IRUSR | S_IWUSR, d,
&timer_interval, &decay_interval_ops); &decay_interval, &decay_interval_ops);
if (!decay) { if (!decay) {
pr_warn("Error creating decay_interval debugfs node!\n"); pr_warn("Error creating decay_interval debugfs node!\n");
goto err; goto err;
...@@ -508,8 +512,8 @@ void __init cec_init(void) ...@@ -508,8 +512,8 @@ void __init cec_init(void)
if (create_debugfs_nodes()) if (create_debugfs_nodes())
return; return;
timer_setup(&cec_timer, cec_timer_fn, 0); INIT_DELAYED_WORK(&cec_work, cec_work_fn);
cec_mod_timer(&cec_timer, CEC_TIMER_DEFAULT_INTERVAL); schedule_delayed_work(&cec_work, CEC_DECAY_DEFAULT_INTERVAL);
pr_info("Correctable Errors collector initialized.\n"); pr_info("Correctable Errors collector initialized.\n");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment