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: [2/2] ras: close the race condition with timer
Date: Mon, 15 Apr 2019 18:20:01 -0700 [thread overview]
Message-ID: <20190416012001.5338-2-xiyou.wangcong@gmail.com> (raw)
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 mutex to a spinlock and holding it
inside the timer.
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 | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/ras/cec.c b/drivers/ras/cec.c
index 61332c9aab5a..a82c9d08d47a 100644
--- a/drivers/ras/cec.c
+++ b/drivers/ras/cec.c
@@ -117,7 +117,7 @@ static struct ce_array {
};
} ce_arr;
-static DEFINE_MUTEX(ce_mutex);
+static DEFINE_SPINLOCK(ce_lock);
static u64 dfs_pfn;
/* Amount of errors after which we offline */
@@ -171,7 +171,9 @@ static void cec_mod_timer(struct timer_list *t, unsigned long interval)
static void cec_timer_fn(struct timer_list *unused)
{
+ spin_lock(&ce_lock);
do_spring_cleaning(&ce_arr);
+ spin_unlock(&ce_lock);
cec_mod_timer(&cec_timer, timer_interval);
}
@@ -265,9 +267,9 @@ static u64 __maybe_unused del_lru_elem(void)
if (!ca->n)
return 0;
- mutex_lock(&ce_mutex);
+ spin_lock_bh(&ce_lock);
pfn = del_lru_elem_unlocked(ca);
- mutex_unlock(&ce_mutex);
+ spin_unlock_bh(&ce_lock);
return pfn;
}
@@ -288,7 +290,7 @@ int cec_add_elem(u64 pfn)
ca->ces_entered++;
- mutex_lock(&ce_mutex);
+ spin_lock_bh(&ce_lock);
if (ca->n == MAX_ELEMS)
WARN_ON(!del_lru_elem_unlocked(ca));
@@ -349,7 +351,7 @@ int cec_add_elem(u64 pfn)
do_spring_cleaning(ca);
unlock:
- mutex_unlock(&ce_mutex);
+ spin_unlock_bh(&ce_lock);
return ret;
}
@@ -406,7 +408,7 @@ static int array_dump(struct seq_file *m, void *v)
u64 prev = 0;
int i;
- mutex_lock(&ce_mutex);
+ spin_lock_bh(&ce_lock);
seq_printf(m, "{ n: %d\n", ca->n);
for (i = 0; i < ca->n; i++) {
@@ -431,7 +433,7 @@ static int array_dump(struct seq_file *m, void *v)
seq_printf(m, "Action threshold: %d\n", count_threshold);
- mutex_unlock(&ce_mutex);
+ spin_unlock_bh(&ce_lock);
return 0;
}
WARNING: multiple messages have this Message-ID (diff)
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 2/2] ras: close the race condition with timer
Date: Mon, 15 Apr 2019 18:20:01 -0700 [thread overview]
Message-ID: <20190416012001.5338-2-xiyou.wangcong@gmail.com> (raw)
Message-ID: <20190416012001.qyGGFYe4Uui8XgyeLXWV1quKyk9R9JV-L-h30gkjAfY@z> (raw)
In-Reply-To: <20190416012001.5338-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 mutex to a spinlock and holding it
inside the timer.
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 | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/ras/cec.c b/drivers/ras/cec.c
index 61332c9aab5a..a82c9d08d47a 100644
--- a/drivers/ras/cec.c
+++ b/drivers/ras/cec.c
@@ -117,7 +117,7 @@ static struct ce_array {
};
} ce_arr;
-static DEFINE_MUTEX(ce_mutex);
+static DEFINE_SPINLOCK(ce_lock);
static u64 dfs_pfn;
/* Amount of errors after which we offline */
@@ -171,7 +171,9 @@ static void cec_mod_timer(struct timer_list *t, unsigned long interval)
static void cec_timer_fn(struct timer_list *unused)
{
+ spin_lock(&ce_lock);
do_spring_cleaning(&ce_arr);
+ spin_unlock(&ce_lock);
cec_mod_timer(&cec_timer, timer_interval);
}
@@ -265,9 +267,9 @@ static u64 __maybe_unused del_lru_elem(void)
if (!ca->n)
return 0;
- mutex_lock(&ce_mutex);
+ spin_lock_bh(&ce_lock);
pfn = del_lru_elem_unlocked(ca);
- mutex_unlock(&ce_mutex);
+ spin_unlock_bh(&ce_lock);
return pfn;
}
@@ -288,7 +290,7 @@ int cec_add_elem(u64 pfn)
ca->ces_entered++;
- mutex_lock(&ce_mutex);
+ spin_lock_bh(&ce_lock);
if (ca->n == MAX_ELEMS)
WARN_ON(!del_lru_elem_unlocked(ca));
@@ -349,7 +351,7 @@ int cec_add_elem(u64 pfn)
do_spring_cleaning(ca);
unlock:
- mutex_unlock(&ce_mutex);
+ spin_unlock_bh(&ce_lock);
return ret;
}
@@ -406,7 +408,7 @@ static int array_dump(struct seq_file *m, void *v)
u64 prev = 0;
int i;
- mutex_lock(&ce_mutex);
+ spin_lock_bh(&ce_lock);
seq_printf(m, "{ n: %d\n", ca->n);
for (i = 0; i < ca->n; i++) {
@@ -431,7 +433,7 @@ static int array_dump(struct seq_file *m, void *v)
seq_printf(m, "Action threshold: %d\n", count_threshold);
- mutex_unlock(&ce_mutex);
+ spin_unlock_bh(&ce_lock);
return 0;
}
--
2.20.1
next reply other threads:[~2019-04-16 1:20 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-16 1:20 Cong Wang [this message]
2019-04-16 1:20 ` [PATCH 2/2] ras: close the race condition with timer Cong Wang
-- strict thread matches above, loose matches on Subject: below --
2019-04-18 22:54 [1/2] ras: fix an off-by-one error in __find_elem() Cong Wang
2019-04-18 22:54 ` [PATCH 1/2] " Cong Wang
2019-04-17 21:15 [1/2] " Luck, Tony
2019-04-17 21:15 ` [PATCH 1/2] " Luck, Tony
2019-04-17 2:37 [1/2] " Cong Wang
2019-04-17 2:37 ` [PATCH 1/2] " Cong Wang
2019-04-17 2:31 [1/2] " Cong Wang
2019-04-17 2:31 ` [PATCH 1/2] " Cong Wang
2019-04-17 1:53 [1/2] " Luck, Tony
2019-04-17 1:53 ` [PATCH 1/2] " Luck, Tony
2019-04-16 23:47 [1/2] " Cong Wang
2019-04-16 23:47 ` [PATCH 1/2] " Cong Wang
2019-04-16 23:28 [1/2] " Luck, Tony
2019-04-16 23:28 ` [PATCH 1/2] " Luck, Tony
2019-04-16 23:18 [1/2] " Cong Wang
2019-04-16 23:18 ` [PATCH 1/2] " Cong Wang
2019-04-16 22:18 [1/2] " Luck, Tony
2019-04-16 22:18 ` [PATCH 1/2] " Luck, Tony
2019-04-16 18:06 [2/2] ras: close the race condition with timer Cong Wang
2019-04-16 18:06 ` [PATCH 2/2] " Cong Wang
2019-04-16 18:00 [2/2] " Cong Wang
2019-04-16 18:00 ` [PATCH 2/2] " Cong Wang
2019-04-16 17:42 [2/2] " Borislav Petkov
2019-04-16 17:42 ` [PATCH 2/2] " Borislav Petkov
2019-04-16 17:09 [2/2] " Cong Wang
2019-04-16 17:09 ` [PATCH 2/2] " Cong Wang
2019-04-16 17:01 [1/2] ras: fix an off-by-one error in __find_elem() Cong Wang
2019-04-16 17:01 ` [PATCH 1/2] " Cong Wang
2019-04-16 9:58 [2/2] ras: close the race condition with timer Borislav Petkov
2019-04-16 9:58 ` [PATCH 2/2] " Borislav Petkov
2019-04-16 9:07 [1/2] ras: fix an off-by-one error in __find_elem() Borislav Petkov
2019-04-16 9:07 ` [PATCH 1/2] " Borislav Petkov
2019-04-16 1:20 [1/2] " Cong Wang
2019-04-16 1:20 ` [PATCH 1/2] " Cong Wang
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=20190416012001.5338-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.