From: Hyeonggon Yoo <42.hyeyoo@gmail.com>
To: peterz@infradead.org, mingo@redhat.com, will@kernel.org
Cc: linux-kernel@vger.kernel.org, Hyeonggon Yoo <42.hyeyoo@gmail.com>
Subject: [PATCH] kernel/locking: make __down_common use flags previously saved
Date: Sat, 24 Apr 2021 23:28:23 +0900 [thread overview]
Message-ID: <20210424142823.3896-1-42.hyeyoo@gmail.com> (raw)
down, down_interruptible, down_killable, and down_timeout
call raw_spin_lock_irqsave that saves current status to flags.
but in __down_common, that is called by functions above, calls
raw_spin_lock_irq and raw_spin_unlock_irq regardless of flags previously saved.
this mismatch can potentially cause problem.
so made __down_common use raw_spin_lock_irqsave and raw_spin_unlock_irqrestore.
Signed-off-by: Hyeonggon Yoo <42.hyeyoo@gmail.com>
---
kernel/locking/semaphore.c | 42 +++++++++++++++++++++-----------------
1 file changed, 23 insertions(+), 19 deletions(-)
diff --git a/kernel/locking/semaphore.c b/kernel/locking/semaphore.c
index 9aa855a96c4a..0ea174223441 100644
--- a/kernel/locking/semaphore.c
+++ b/kernel/locking/semaphore.c
@@ -33,10 +33,10 @@
#include <linux/spinlock.h>
#include <linux/ftrace.h>
-static noinline void __down(struct semaphore *sem);
-static noinline int __down_interruptible(struct semaphore *sem);
-static noinline int __down_killable(struct semaphore *sem);
-static noinline int __down_timeout(struct semaphore *sem, long timeout);
+static noinline void __down(struct semaphore *sem, unsigned long flags);
+static noinline int __down_interruptible(struct semaphore *sem, unsigned long flags);
+static noinline int __down_killable(struct semaphore *sem, unsigned long flags);
+static noinline int __down_timeout(struct semaphore *sem, long timeout, unsigned long flags);
static noinline void __up(struct semaphore *sem);
/**
@@ -58,7 +58,7 @@ void down(struct semaphore *sem)
if (likely(sem->count > 0))
sem->count--;
else
- __down(sem);
+ __down(sem, flags);
raw_spin_unlock_irqrestore(&sem->lock, flags);
}
EXPORT_SYMBOL(down);
@@ -81,7 +81,7 @@ int down_interruptible(struct semaphore *sem)
if (likely(sem->count > 0))
sem->count--;
else
- result = __down_interruptible(sem);
+ result = __down_interruptible(sem, flags);
raw_spin_unlock_irqrestore(&sem->lock, flags);
return result;
@@ -107,7 +107,7 @@ int down_killable(struct semaphore *sem)
if (likely(sem->count > 0))
sem->count--;
else
- result = __down_killable(sem);
+ result = __down_killable(sem, flags);
raw_spin_unlock_irqrestore(&sem->lock, flags);
return result;
@@ -161,7 +161,7 @@ int down_timeout(struct semaphore *sem, long timeout)
if (likely(sem->count > 0))
sem->count--;
else
- result = __down_timeout(sem, timeout);
+ result = __down_timeout(sem, timeout, flags);
raw_spin_unlock_irqrestore(&sem->lock, flags);
return result;
@@ -202,7 +202,7 @@ struct semaphore_waiter {
* 'timeout' parameter for the cases without timeouts.
*/
static inline int __sched __down_common(struct semaphore *sem, long state,
- long timeout)
+ long timeout, unsigned long flags)
{
struct semaphore_waiter waiter;
@@ -216,9 +216,9 @@ static inline int __sched __down_common(struct semaphore *sem, long state,
if (unlikely(timeout <= 0))
goto timed_out;
__set_current_state(state);
- raw_spin_unlock_irq(&sem->lock);
+ raw_spin_unlock_irqrestore(&sem->lock, flags);
timeout = schedule_timeout(timeout);
- raw_spin_lock_irq(&sem->lock);
+ raw_spin_lock_irqsave(&sem->lock, flags);
if (waiter.up)
return 0;
}
@@ -232,24 +232,28 @@ static inline int __sched __down_common(struct semaphore *sem, long state,
return -EINTR;
}
-static noinline void __sched __down(struct semaphore *sem)
+static noinline void __sched __down(struct semaphore *sem, unsigned long flags)
{
- __down_common(sem, TASK_UNINTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
+ __down_common(sem, TASK_UNINTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT, flags);
}
-static noinline int __sched __down_interruptible(struct semaphore *sem)
+static noinline int __sched __down_interruptible(struct semaphore *sem,
+ unsigned long flags)
{
- return __down_common(sem, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT);
+ return __down_common(sem, TASK_INTERRUPTIBLE, MAX_SCHEDULE_TIMEOUT,
+ flags);
}
-static noinline int __sched __down_killable(struct semaphore *sem)
+static noinline int __sched __down_killable(struct semaphore *sem,
+ unsigned long flags)
{
- return __down_common(sem, TASK_KILLABLE, MAX_SCHEDULE_TIMEOUT);
+ return __down_common(sem, TASK_KILLABLE, MAX_SCHEDULE_TIMEOUT, flags);
}
-static noinline int __sched __down_timeout(struct semaphore *sem, long timeout)
+static noinline int __sched __down_timeout(struct semaphore *sem,
+ long timeout, unsigned long flags)
{
- return __down_common(sem, TASK_UNINTERRUPTIBLE, timeout);
+ return __down_common(sem, TASK_UNINTERRUPTIBLE, timeout, flags);
}
static noinline void __sched __up(struct semaphore *sem)
--
2.25.1
next reply other threads:[~2021-04-24 14:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-24 14:28 Hyeonggon Yoo [this message]
2021-05-11 2:23 ` [PATCH] kernel/locking: make __down_common use flags previously saved Hyeonggon Yoo
2021-05-12 19:09 ` Ingo Molnar
2021-05-17 14:36 ` Hyeonggon Yoo
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=20210424142823.3896-1-42.hyeyoo@gmail.com \
--to=42.hyeyoo@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=will@kernel.org \
/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).