locking, printk: Annotate logbuf_lock as raw
The logbuf_lock lock can be taken in atomic context and therefore cannot be preempted on -rt - annotate it. In mainline this change documents the low level nature of the lock - otherwise there's no functional difference. Lockdep and Sparse checking will work as usual. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> [ merged and fixed it ] Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
parent
5389f6fad2
commit
07354eb1a7
@ -8,7 +8,7 @@
|
|||||||
#define DEFAULT_RATELIMIT_BURST 10
|
#define DEFAULT_RATELIMIT_BURST 10
|
||||||
|
|
||||||
struct ratelimit_state {
|
struct ratelimit_state {
|
||||||
spinlock_t lock; /* protect the state */
|
raw_spinlock_t lock; /* protect the state */
|
||||||
|
|
||||||
int interval;
|
int interval;
|
||||||
int burst;
|
int burst;
|
||||||
@ -20,7 +20,7 @@ struct ratelimit_state {
|
|||||||
#define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init) \
|
#define DEFINE_RATELIMIT_STATE(name, interval_init, burst_init) \
|
||||||
\
|
\
|
||||||
struct ratelimit_state name = { \
|
struct ratelimit_state name = { \
|
||||||
.lock = __SPIN_LOCK_UNLOCKED(name.lock), \
|
.lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \
|
||||||
.interval = interval_init, \
|
.interval = interval_init, \
|
||||||
.burst = burst_init, \
|
.burst = burst_init, \
|
||||||
}
|
}
|
||||||
@ -28,7 +28,7 @@ struct ratelimit_state {
|
|||||||
static inline void ratelimit_state_init(struct ratelimit_state *rs,
|
static inline void ratelimit_state_init(struct ratelimit_state *rs,
|
||||||
int interval, int burst)
|
int interval, int burst)
|
||||||
{
|
{
|
||||||
spin_lock_init(&rs->lock);
|
raw_spin_lock_init(&rs->lock);
|
||||||
rs->interval = interval;
|
rs->interval = interval;
|
||||||
rs->burst = burst;
|
rs->burst = burst;
|
||||||
rs->printed = 0;
|
rs->printed = 0;
|
||||||
|
@ -100,7 +100,7 @@ static int console_locked, console_suspended;
|
|||||||
* It is also used in interesting ways to provide interlocking in
|
* It is also used in interesting ways to provide interlocking in
|
||||||
* console_unlock();.
|
* console_unlock();.
|
||||||
*/
|
*/
|
||||||
static DEFINE_SPINLOCK(logbuf_lock);
|
static DEFINE_RAW_SPINLOCK(logbuf_lock);
|
||||||
|
|
||||||
#define LOG_BUF_MASK (log_buf_len-1)
|
#define LOG_BUF_MASK (log_buf_len-1)
|
||||||
#define LOG_BUF(idx) (log_buf[(idx) & LOG_BUF_MASK])
|
#define LOG_BUF(idx) (log_buf[(idx) & LOG_BUF_MASK])
|
||||||
@ -212,7 +212,7 @@ void __init setup_log_buf(int early)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock_irqsave(&logbuf_lock, flags);
|
raw_spin_lock_irqsave(&logbuf_lock, flags);
|
||||||
log_buf_len = new_log_buf_len;
|
log_buf_len = new_log_buf_len;
|
||||||
log_buf = new_log_buf;
|
log_buf = new_log_buf;
|
||||||
new_log_buf_len = 0;
|
new_log_buf_len = 0;
|
||||||
@ -230,7 +230,7 @@ void __init setup_log_buf(int early)
|
|||||||
log_start -= offset;
|
log_start -= offset;
|
||||||
con_start -= offset;
|
con_start -= offset;
|
||||||
log_end -= offset;
|
log_end -= offset;
|
||||||
spin_unlock_irqrestore(&logbuf_lock, flags);
|
raw_spin_unlock_irqrestore(&logbuf_lock, flags);
|
||||||
|
|
||||||
pr_info("log_buf_len: %d\n", log_buf_len);
|
pr_info("log_buf_len: %d\n", log_buf_len);
|
||||||
pr_info("early log buf free: %d(%d%%)\n",
|
pr_info("early log buf free: %d(%d%%)\n",
|
||||||
@ -365,18 +365,18 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
|
|||||||
if (error)
|
if (error)
|
||||||
goto out;
|
goto out;
|
||||||
i = 0;
|
i = 0;
|
||||||
spin_lock_irq(&logbuf_lock);
|
raw_spin_lock_irq(&logbuf_lock);
|
||||||
while (!error && (log_start != log_end) && i < len) {
|
while (!error && (log_start != log_end) && i < len) {
|
||||||
c = LOG_BUF(log_start);
|
c = LOG_BUF(log_start);
|
||||||
log_start++;
|
log_start++;
|
||||||
spin_unlock_irq(&logbuf_lock);
|
raw_spin_unlock_irq(&logbuf_lock);
|
||||||
error = __put_user(c,buf);
|
error = __put_user(c,buf);
|
||||||
buf++;
|
buf++;
|
||||||
i++;
|
i++;
|
||||||
cond_resched();
|
cond_resched();
|
||||||
spin_lock_irq(&logbuf_lock);
|
raw_spin_lock_irq(&logbuf_lock);
|
||||||
}
|
}
|
||||||
spin_unlock_irq(&logbuf_lock);
|
raw_spin_unlock_irq(&logbuf_lock);
|
||||||
if (!error)
|
if (!error)
|
||||||
error = i;
|
error = i;
|
||||||
break;
|
break;
|
||||||
@ -399,7 +399,7 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
|
|||||||
count = len;
|
count = len;
|
||||||
if (count > log_buf_len)
|
if (count > log_buf_len)
|
||||||
count = log_buf_len;
|
count = log_buf_len;
|
||||||
spin_lock_irq(&logbuf_lock);
|
raw_spin_lock_irq(&logbuf_lock);
|
||||||
if (count > logged_chars)
|
if (count > logged_chars)
|
||||||
count = logged_chars;
|
count = logged_chars;
|
||||||
if (do_clear)
|
if (do_clear)
|
||||||
@ -416,12 +416,12 @@ int do_syslog(int type, char __user *buf, int len, bool from_file)
|
|||||||
if (j + log_buf_len < log_end)
|
if (j + log_buf_len < log_end)
|
||||||
break;
|
break;
|
||||||
c = LOG_BUF(j);
|
c = LOG_BUF(j);
|
||||||
spin_unlock_irq(&logbuf_lock);
|
raw_spin_unlock_irq(&logbuf_lock);
|
||||||
error = __put_user(c,&buf[count-1-i]);
|
error = __put_user(c,&buf[count-1-i]);
|
||||||
cond_resched();
|
cond_resched();
|
||||||
spin_lock_irq(&logbuf_lock);
|
raw_spin_lock_irq(&logbuf_lock);
|
||||||
}
|
}
|
||||||
spin_unlock_irq(&logbuf_lock);
|
raw_spin_unlock_irq(&logbuf_lock);
|
||||||
if (error)
|
if (error)
|
||||||
break;
|
break;
|
||||||
error = i;
|
error = i;
|
||||||
@ -689,7 +689,7 @@ static void zap_locks(void)
|
|||||||
oops_timestamp = jiffies;
|
oops_timestamp = jiffies;
|
||||||
|
|
||||||
/* If a crash is occurring, make sure we can't deadlock */
|
/* If a crash is occurring, make sure we can't deadlock */
|
||||||
spin_lock_init(&logbuf_lock);
|
raw_spin_lock_init(&logbuf_lock);
|
||||||
/* And make sure that we print immediately */
|
/* And make sure that we print immediately */
|
||||||
sema_init(&console_sem, 1);
|
sema_init(&console_sem, 1);
|
||||||
}
|
}
|
||||||
@ -802,9 +802,9 @@ static int console_trylock_for_printk(unsigned int cpu)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
printk_cpu = UINT_MAX;
|
printk_cpu = UINT_MAX;
|
||||||
spin_unlock(&logbuf_lock);
|
|
||||||
if (wake)
|
if (wake)
|
||||||
up(&console_sem);
|
up(&console_sem);
|
||||||
|
raw_spin_unlock(&logbuf_lock);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
static const char recursion_bug_msg [] =
|
static const char recursion_bug_msg [] =
|
||||||
@ -864,7 +864,7 @@ asmlinkage int vprintk(const char *fmt, va_list args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
lockdep_off();
|
lockdep_off();
|
||||||
spin_lock(&logbuf_lock);
|
raw_spin_lock(&logbuf_lock);
|
||||||
printk_cpu = this_cpu;
|
printk_cpu = this_cpu;
|
||||||
|
|
||||||
if (recursion_bug) {
|
if (recursion_bug) {
|
||||||
@ -1257,14 +1257,14 @@ void console_unlock(void)
|
|||||||
|
|
||||||
again:
|
again:
|
||||||
for ( ; ; ) {
|
for ( ; ; ) {
|
||||||
spin_lock_irqsave(&logbuf_lock, flags);
|
raw_spin_lock_irqsave(&logbuf_lock, flags);
|
||||||
wake_klogd |= log_start - log_end;
|
wake_klogd |= log_start - log_end;
|
||||||
if (con_start == log_end)
|
if (con_start == log_end)
|
||||||
break; /* Nothing to print */
|
break; /* Nothing to print */
|
||||||
_con_start = con_start;
|
_con_start = con_start;
|
||||||
_log_end = log_end;
|
_log_end = log_end;
|
||||||
con_start = log_end; /* Flush */
|
con_start = log_end; /* Flush */
|
||||||
spin_unlock(&logbuf_lock);
|
raw_spin_unlock(&logbuf_lock);
|
||||||
stop_critical_timings(); /* don't trace print latency */
|
stop_critical_timings(); /* don't trace print latency */
|
||||||
call_console_drivers(_con_start, _log_end);
|
call_console_drivers(_con_start, _log_end);
|
||||||
start_critical_timings();
|
start_critical_timings();
|
||||||
@ -1276,7 +1276,7 @@ again:
|
|||||||
if (unlikely(exclusive_console))
|
if (unlikely(exclusive_console))
|
||||||
exclusive_console = NULL;
|
exclusive_console = NULL;
|
||||||
|
|
||||||
spin_unlock(&logbuf_lock);
|
raw_spin_unlock(&logbuf_lock);
|
||||||
|
|
||||||
up(&console_sem);
|
up(&console_sem);
|
||||||
|
|
||||||
@ -1286,13 +1286,13 @@ again:
|
|||||||
* there's a new owner and the console_unlock() from them will do the
|
* there's a new owner and the console_unlock() from them will do the
|
||||||
* flush, no worries.
|
* flush, no worries.
|
||||||
*/
|
*/
|
||||||
spin_lock(&logbuf_lock);
|
raw_spin_lock(&logbuf_lock);
|
||||||
if (con_start != log_end)
|
if (con_start != log_end)
|
||||||
retry = 1;
|
retry = 1;
|
||||||
spin_unlock_irqrestore(&logbuf_lock, flags);
|
|
||||||
if (retry && console_trylock())
|
if (retry && console_trylock())
|
||||||
goto again;
|
goto again;
|
||||||
|
|
||||||
|
raw_spin_unlock_irqrestore(&logbuf_lock, flags);
|
||||||
if (wake_klogd)
|
if (wake_klogd)
|
||||||
wake_up_klogd();
|
wake_up_klogd();
|
||||||
}
|
}
|
||||||
@ -1522,9 +1522,9 @@ void register_console(struct console *newcon)
|
|||||||
* console_unlock(); will print out the buffered messages
|
* console_unlock(); will print out the buffered messages
|
||||||
* for us.
|
* for us.
|
||||||
*/
|
*/
|
||||||
spin_lock_irqsave(&logbuf_lock, flags);
|
raw_spin_lock_irqsave(&logbuf_lock, flags);
|
||||||
con_start = log_start;
|
con_start = log_start;
|
||||||
spin_unlock_irqrestore(&logbuf_lock, flags);
|
raw_spin_unlock_irqrestore(&logbuf_lock, flags);
|
||||||
/*
|
/*
|
||||||
* We're about to replay the log buffer. Only do this to the
|
* We're about to replay the log buffer. Only do this to the
|
||||||
* just-registered console to avoid excessive message spam to
|
* just-registered console to avoid excessive message spam to
|
||||||
@ -1731,10 +1731,10 @@ void kmsg_dump(enum kmsg_dump_reason reason)
|
|||||||
/* Theoretically, the log could move on after we do this, but
|
/* Theoretically, the log could move on after we do this, but
|
||||||
there's not a lot we can do about that. The new messages
|
there's not a lot we can do about that. The new messages
|
||||||
will overwrite the start of what we dump. */
|
will overwrite the start of what we dump. */
|
||||||
spin_lock_irqsave(&logbuf_lock, flags);
|
raw_spin_lock_irqsave(&logbuf_lock, flags);
|
||||||
end = log_end & LOG_BUF_MASK;
|
end = log_end & LOG_BUF_MASK;
|
||||||
chars = logged_chars;
|
chars = logged_chars;
|
||||||
spin_unlock_irqrestore(&logbuf_lock, flags);
|
raw_spin_unlock_irqrestore(&logbuf_lock, flags);
|
||||||
|
|
||||||
if (chars > end) {
|
if (chars > end) {
|
||||||
s1 = log_buf + log_buf_len - chars + end;
|
s1 = log_buf + log_buf_len - chars + end;
|
||||||
|
@ -39,7 +39,7 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
|
|||||||
* in addition to the one that will be printed by
|
* in addition to the one that will be printed by
|
||||||
* the entity that is holding the lock already:
|
* the entity that is holding the lock already:
|
||||||
*/
|
*/
|
||||||
if (!spin_trylock_irqsave(&rs->lock, flags))
|
if (!raw_spin_trylock_irqsave(&rs->lock, flags))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!rs->begin)
|
if (!rs->begin)
|
||||||
@ -60,7 +60,7 @@ int ___ratelimit(struct ratelimit_state *rs, const char *func)
|
|||||||
rs->missed++;
|
rs->missed++;
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
spin_unlock_irqrestore(&rs->lock, flags);
|
raw_spin_unlock_irqrestore(&rs->lock, flags);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user