summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Nelissen <marcone@google.com>2022-04-14 11:11:44 -0700
committerTreeHugger Robot <treehugger-gerrit@google.com>2023-03-06 22:48:05 +0000
commitd541cbcb14004e51c3c6f0ff416e9f5b117e48ee (patch)
treedd65c82fb6570ad5080fe533464b1ea1b234c712
parent7e2ad88707ddc86263cab75ba89d21108a5b554b (diff)
downloadtrusty-d541cbcb14004e51c3c6f0ff416e9f5b117e48ee.tar.gz
Revert "ANDROID: trusty-log: Don't copy Trusty logs to linux kernel log"
This reverts commit 94a36a1374e7, thus restoring the copying of Trusty logs to the linux kernel log. A followup change will make this configurable. Bug: 221867580 Signed-off-by: Marco Nelissen <marcone@google.com> Change-Id: I6453c6cd3a30d424f8d0e695d02d6b8df54b1adc
-rw-r--r--drivers/trusty/trusty-log.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/drivers/trusty/trusty-log.c b/drivers/trusty/trusty-log.c
index fde7190..ea8b822 100644
--- a/drivers/trusty/trusty-log.c
+++ b/drivers/trusty/trusty-log.c
@@ -92,6 +92,8 @@ struct trusty_log_sfile {
* struct trusty_log_sink_state - trusty log sink state
*
* @get: current read unwrapped index
+ * @last_successful_next:
+ * index for the next line after the last successful get
* @trusty_panicked: trusty panic status at the start of the sink interation
* (only used for kernel log sink)
* @sfile: seq_file used for sinking to a virtual file (misc device);
@@ -108,6 +110,7 @@ struct trusty_log_sfile {
*/
struct trusty_log_sink_state {
u32 get;
+ u32 last_successful_next;
bool trusty_panicked;
/* virtual file sink specific attributes */
@@ -120,6 +123,11 @@ struct trusty_log_state {
struct device *trusty_dev;
struct trusty_log_sfile log_sfile;
+ /*
+ * This lock is here to ensure only one consumer will read
+ * from the log ring buffer at a time.
+ */
+ spinlock_t lock;
struct log_rb *log;
struct trusty_log_sink_state klog_sink;
@@ -288,10 +296,13 @@ static void trusty_log_show(struct trusty_log_state *s,
sink->ignore_overflow = false;
if (sink->sfile) {
seq_printf(sink->sfile, "%s", s->line_buffer);
+ sink->last_successful_next = sink->get;
} else {
if (sink->trusty_panicked ||
__ratelimit(&trusty_log_rate_limit)) {
dev_info(s->dev, "%s", s->line_buffer);
+ /* next line after last successful get */
+ sink->last_successful_next = sink->get;
}
}
}
@@ -435,13 +446,18 @@ static int trusty_log_seq_show(struct seq_file *sfile, void *v)
static void trusty_dump_logs(struct trusty_log_state *s)
{
+ u32 start;
int rc;
/*
- * note: klog_sink.get initialized to zero by kzalloc
+ * note: klopg_sink.get and last_successful_next
+ * initialized to zero by kzalloc
*/
s->klog_sink.trusty_panicked = trusty_get_panic_status(s->trusty_dev);
- rc = trusty_log_start(s, &s->klog_sink, s->klog_sink.get);
+ start = s->klog_sink.trusty_panicked ?
+ s->klog_sink.last_successful_next :
+ s->klog_sink.get;
+ rc = trusty_log_start(s, &s->klog_sink, start);
if (rc < 0)
return;
@@ -467,6 +483,9 @@ static int trusty_log_call_notify(struct notifier_block *nb,
wake_up_all(&s->poll_waiters);
}
spin_unlock_irqrestore(&s->wake_up_lock, flags);
+ spin_lock_irqsave(&s->lock, flags);
+ trusty_dump_logs(s);
+ spin_unlock_irqrestore(&s->lock, flags);
return NOTIFY_OK;
}
@@ -543,14 +562,6 @@ static unsigned int trusty_log_sfile_dev_poll(struct file *filp,
s = container_of(lb, struct trusty_log_state, log_sfile);
poll_wait(filp, &s->poll_waiters, wait);
log = s->log;
-
- /*
- * Userspace has read up to filp->f_pos so far. Update klog_sink
- * to indicate that, so that we don't end up dumping the entire
- * Trusty log in case of panic.
- */
- s->klog_sink.get = (u32)filp->f_pos;
-
if (log->put != (u32)filp->f_pos) {
/* data ready to read */
return EPOLLIN | EPOLLRDNORM;
@@ -644,6 +655,7 @@ static int trusty_log_init(struct platform_device *pdev)
goto error_alloc_state;
}
+ spin_lock_init(&s->lock);
s->dev = &pdev->dev;
s->trusty_dev = s->dev->parent;