From d8c503e06808c3fe78c5238d55c786b245f96bd8 Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Sun, 10 Dec 2023 14:38:55 -0500 Subject: [PATCH] Fixes for 5.10 Signed-off-by: Sasha Levin --- ...c-fix-problem-of-return-eoverflow-in.patch | 38 ++++++++++ ...c-return-negative-error-code-in-mei_.patch | 37 ++++++++++ ...e-absolute-timestamp-on-discard-of-e.patch | 71 ++++++++++++++++++ queue-5.10/series | 5 ++ ...actual-size-after-ring-buffer-resize.patch | 70 ++++++++++++++++++ ...-current-tracer-when-resizing-buffer.patch | 73 +++++++++++++++++++ 6 files changed, 294 insertions(+) create mode 100644 queue-5.10/misc-mei-client.c-fix-problem-of-return-eoverflow-in.patch create mode 100644 queue-5.10/misc-mei-client.c-return-negative-error-code-in-mei_.patch create mode 100644 queue-5.10/ring-buffer-force-absolute-timestamp-on-discard-of-e.patch create mode 100644 queue-5.10/tracing-set-actual-size-after-ring-buffer-resize.patch create mode 100644 queue-5.10/tracing-stop-current-tracer-when-resizing-buffer.patch diff --git a/queue-5.10/misc-mei-client.c-fix-problem-of-return-eoverflow-in.patch b/queue-5.10/misc-mei-client.c-fix-problem-of-return-eoverflow-in.patch new file mode 100644 index 00000000000..95ae8b39caf --- /dev/null +++ b/queue-5.10/misc-mei-client.c-fix-problem-of-return-eoverflow-in.patch @@ -0,0 +1,38 @@ +From 4b402e87b5a7400101531aae5ffff940a41a9a2d Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Mon, 20 Nov 2023 17:55:26 +0800 +Subject: misc: mei: client.c: fix problem of return '-EOVERFLOW' in + mei_cl_write + +From: Su Hui + +[ Upstream commit ee6236027218f8531916f1c5caa5dc330379f287 ] + +Clang static analyzer complains that value stored to 'rets' is never +read.Let 'buf_len = -EOVERFLOW' to make sure we can return '-EOVERFLOW'. + +Fixes: 8c8d964ce90f ("mei: move hbuf_depth from the mei device to the hw modules") +Signed-off-by: Su Hui +Link: https://lore.kernel.org/r/20231120095523.178385-2-suhui@nfschina.com +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/misc/mei/client.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c +index 1c9ced7383b63..aa87542f116c2 100644 +--- a/drivers/misc/mei/client.c ++++ b/drivers/misc/mei/client.c +@@ -1993,7 +1993,7 @@ ssize_t mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb) + + hbuf_slots = mei_hbuf_empty_slots(dev); + if (hbuf_slots < 0) { +- rets = -EOVERFLOW; ++ buf_len = -EOVERFLOW; + goto out; + } + +-- +2.42.0 + diff --git a/queue-5.10/misc-mei-client.c-return-negative-error-code-in-mei_.patch b/queue-5.10/misc-mei-client.c-return-negative-error-code-in-mei_.patch new file mode 100644 index 00000000000..ba9d01303a4 --- /dev/null +++ b/queue-5.10/misc-mei-client.c-return-negative-error-code-in-mei_.patch @@ -0,0 +1,37 @@ +From d73676bc639d1b5651f4e0bff155f55943b6b770 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Mon, 20 Nov 2023 17:55:23 +0800 +Subject: misc: mei: client.c: return negative error code in mei_cl_write + +From: Su Hui + +[ Upstream commit 8f06aee8089cf42fd99a20184501bd1347ce61b9 ] + +mei_msg_hdr_init() return negative error code, rets should be +'PTR_ERR(mei_hdr)' rather than '-PTR_ERR(mei_hdr)'. + +Fixes: 0cd7c01a60f8 ("mei: add support for mei extended header.") +Signed-off-by: Su Hui +Link: https://lore.kernel.org/r/20231120095523.178385-1-suhui@nfschina.com +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Sasha Levin +--- + drivers/misc/mei/client.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/drivers/misc/mei/client.c b/drivers/misc/mei/client.c +index d5c3f7d54634c..1c9ced7383b63 100644 +--- a/drivers/misc/mei/client.c ++++ b/drivers/misc/mei/client.c +@@ -1969,7 +1969,7 @@ ssize_t mei_cl_write(struct mei_cl *cl, struct mei_cl_cb *cb) + + mei_hdr = mei_msg_hdr_init(cb); + if (IS_ERR(mei_hdr)) { +- rets = -PTR_ERR(mei_hdr); ++ rets = PTR_ERR(mei_hdr); + mei_hdr = NULL; + goto err; + } +-- +2.42.0 + diff --git a/queue-5.10/ring-buffer-force-absolute-timestamp-on-discard-of-e.patch b/queue-5.10/ring-buffer-force-absolute-timestamp-on-discard-of-e.patch new file mode 100644 index 00000000000..296d69e8f96 --- /dev/null +++ b/queue-5.10/ring-buffer-force-absolute-timestamp-on-discard-of-e.patch @@ -0,0 +1,71 @@ +From 8056578f239179d991786ce2dc960ecc6dcd270a Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 6 Dec 2023 10:02:44 -0500 +Subject: ring-buffer: Force absolute timestamp on discard of event + +From: Steven Rostedt (Google) + +[ Upstream commit b2dd797543cfa6580eac8408dd67fa02164d9e56 ] + +There's a race where if an event is discarded from the ring buffer and an +interrupt were to happen at that time and insert an event, the time stamp +is still used from the discarded event as an offset. This can screw up the +timings. + +If the event is going to be discarded, set the "before_stamp" to zero. +When a new event comes in, it compares the "before_stamp" with the +"write_stamp" and if they are not equal, it will insert an absolute +timestamp. This will prevent the timings from getting out of sync due to +the discarded event. + +Link: https://lore.kernel.org/linux-trace-kernel/20231206100244.5130f9b3@gandalf.local.home + +Cc: stable@vger.kernel.org +Cc: Masami Hiramatsu +Cc: Mark Rutland +Cc: Mathieu Desnoyers +Fixes: 6f6be606e763f ("ring-buffer: Force before_stamp and write_stamp to be different on discard") +Signed-off-by: Steven Rostedt (Google) +Signed-off-by: Sasha Levin +--- + kernel/trace/ring_buffer.c | 19 ++++++++----------- + 1 file changed, 8 insertions(+), 11 deletions(-) + +diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c +index 0938222b45988..7e1148aafd284 100644 +--- a/kernel/trace/ring_buffer.c ++++ b/kernel/trace/ring_buffer.c +@@ -2903,22 +2903,19 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer, + local_read(&bpage->write) & ~RB_WRITE_MASK; + unsigned long event_length = rb_event_length(event); + ++ /* ++ * For the before_stamp to be different than the write_stamp ++ * to make sure that the next event adds an absolute ++ * value and does not rely on the saved write stamp, which ++ * is now going to be bogus. ++ */ ++ rb_time_set(&cpu_buffer->before_stamp, 0); ++ + /* Something came in, can't discard */ + if (!rb_time_cmpxchg(&cpu_buffer->write_stamp, + write_stamp, write_stamp - delta)) + return 0; + +- /* +- * It's possible that the event time delta is zero +- * (has the same time stamp as the previous event) +- * in which case write_stamp and before_stamp could +- * be the same. In such a case, force before_stamp +- * to be different than write_stamp. It doesn't +- * matter what it is, as long as its different. +- */ +- if (!delta) +- rb_time_set(&cpu_buffer->before_stamp, 0); +- + /* + * If an event were to come in now, it would see that the + * write_stamp and the before_stamp are different, and assume +-- +2.42.0 + diff --git a/queue-5.10/series b/queue-5.10/series index 4ff25d8d048..2eacc379523 100644 --- a/queue-5.10/series +++ b/queue-5.10/series @@ -57,3 +57,8 @@ packet-move-reference-count-in-packet_sock-to-atomic_long_t.patch arm64-dts-mediatek-mt7622-fix-memory-node-warning-check.patch arm64-dts-mediatek-mt8173-evb-fix-regulator-fixed-node-names.patch arm64-dts-mediatek-mt8183-fix-unit-address-for-scp-reserved-memory.patch +misc-mei-client.c-return-negative-error-code-in-mei_.patch +misc-mei-client.c-fix-problem-of-return-eoverflow-in.patch +ring-buffer-force-absolute-timestamp-on-discard-of-e.patch +tracing-set-actual-size-after-ring-buffer-resize.patch +tracing-stop-current-tracer-when-resizing-buffer.patch diff --git a/queue-5.10/tracing-set-actual-size-after-ring-buffer-resize.patch b/queue-5.10/tracing-set-actual-size-after-ring-buffer-resize.patch new file mode 100644 index 00000000000..0da17790acd --- /dev/null +++ b/queue-5.10/tracing-set-actual-size-after-ring-buffer-resize.patch @@ -0,0 +1,70 @@ +From 6f3474d3a0ead0df0da59ecacee771cf6e685b07 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Wed, 5 Jul 2023 08:27:05 +0800 +Subject: tracing: Set actual size after ring buffer resize + +From: Zheng Yejian + +[ Upstream commit 6d98a0f2ac3c021d21be66fa34e992137cd25bcb ] + +Currently we can resize trace ringbuffer by writing a value into file +'buffer_size_kb', then by reading the file, we get the value that is +usually what we wrote. However, this value may be not actual size of +trace ring buffer because of the round up when doing resize in kernel, +and the actual size would be more useful. + +Link: https://lore.kernel.org/linux-trace-kernel/20230705002705.576633-1-zhengyejian1@huawei.com + +Cc: +Signed-off-by: Zheng Yejian +Signed-off-by: Steven Rostedt (Google) +Stable-dep-of: d78ab792705c ("tracing: Stop current tracer when resizing buffer") +Signed-off-by: Sasha Levin +--- + kernel/trace/trace.c | 19 +++++++++++-------- + 1 file changed, 11 insertions(+), 8 deletions(-) + +diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c +index adabf4f0b081f..2c9769e1f7652 100644 +--- a/kernel/trace/trace.c ++++ b/kernel/trace/trace.c +@@ -5852,6 +5852,15 @@ static void set_buffer_entries(struct array_buffer *buf, unsigned long val) + per_cpu_ptr(buf->data, cpu)->entries = val; + } + ++static void update_buffer_entries(struct array_buffer *buf, int cpu) ++{ ++ if (cpu == RING_BUFFER_ALL_CPUS) { ++ set_buffer_entries(buf, ring_buffer_size(buf->buffer, 0)); ++ } else { ++ per_cpu_ptr(buf->data, cpu)->entries = ring_buffer_size(buf->buffer, cpu); ++ } ++} ++ + #ifdef CONFIG_TRACER_MAX_TRACE + /* resize @tr's buffer to the size of @size_tr's entries */ + static int resize_buffer_duplicate_size(struct array_buffer *trace_buf, +@@ -5929,18 +5938,12 @@ static int __tracing_resize_ring_buffer(struct trace_array *tr, + return ret; + } + +- if (cpu == RING_BUFFER_ALL_CPUS) +- set_buffer_entries(&tr->max_buffer, size); +- else +- per_cpu_ptr(tr->max_buffer.data, cpu)->entries = size; ++ update_buffer_entries(&tr->max_buffer, cpu); + + out: + #endif /* CONFIG_TRACER_MAX_TRACE */ + +- if (cpu == RING_BUFFER_ALL_CPUS) +- set_buffer_entries(&tr->array_buffer, size); +- else +- per_cpu_ptr(tr->array_buffer.data, cpu)->entries = size; ++ update_buffer_entries(&tr->array_buffer, cpu); + + return ret; + } +-- +2.42.0 + diff --git a/queue-5.10/tracing-stop-current-tracer-when-resizing-buffer.patch b/queue-5.10/tracing-stop-current-tracer-when-resizing-buffer.patch new file mode 100644 index 00000000000..41176505edb --- /dev/null +++ b/queue-5.10/tracing-stop-current-tracer-when-resizing-buffer.patch @@ -0,0 +1,73 @@ +From 564144698c1b6f65c47603cb91dc3feeaa69e0a0 Mon Sep 17 00:00:00 2001 +From: Sasha Levin +Date: Tue, 5 Dec 2023 16:52:10 -0500 +Subject: tracing: Stop current tracer when resizing buffer + +From: Steven Rostedt (Google) + +[ Upstream commit d78ab792705c7be1b91243b2544d1a79406a2ad7 ] + +When the ring buffer is being resized, it can cause side effects to the +running tracer. For instance, there's a race with irqsoff tracer that +swaps individual per cpu buffers between the main buffer and the snapshot +buffer. The resize operation modifies the main buffer and then the +snapshot buffer. If a swap happens in between those two operations it will +break the tracer. + +Simply stop the running tracer before resizing the buffers and enable it +again when finished. + +Link: https://lkml.kernel.org/r/20231205220010.748996423@goodmis.org + +Cc: stable@vger.kernel.org +Cc: Masami Hiramatsu +Cc: Mark Rutland +Cc: Mathieu Desnoyers +Cc: Andrew Morton +Fixes: 3928a8a2d9808 ("ftrace: make work with new ring buffer") +Signed-off-by: Steven Rostedt (Google) +Signed-off-by: Sasha Levin +--- + kernel/trace/trace.c | 10 +++++++--- + 1 file changed, 7 insertions(+), 3 deletions(-) + +diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c +index 2c9769e1f7652..4e0411b19ef96 100644 +--- a/kernel/trace/trace.c ++++ b/kernel/trace/trace.c +@@ -5905,9 +5905,12 @@ static int __tracing_resize_ring_buffer(struct trace_array *tr, + if (!tr->array_buffer.buffer) + return 0; + ++ /* Do not allow tracing while resizng ring buffer */ ++ tracing_stop_tr(tr); ++ + ret = ring_buffer_resize(tr->array_buffer.buffer, size, cpu); + if (ret < 0) +- return ret; ++ goto out_start; + + #ifdef CONFIG_TRACER_MAX_TRACE + if (!tr->current_trace->use_max_tr) +@@ -5935,7 +5938,7 @@ static int __tracing_resize_ring_buffer(struct trace_array *tr, + WARN_ON(1); + tracing_disabled = 1; + } +- return ret; ++ goto out_start; + } + + update_buffer_entries(&tr->max_buffer, cpu); +@@ -5944,7 +5947,8 @@ static int __tracing_resize_ring_buffer(struct trace_array *tr, + #endif /* CONFIG_TRACER_MAX_TRACE */ + + update_buffer_entries(&tr->array_buffer, cpu); +- ++ out_start: ++ tracing_start_tr(tr); + return ret; + } + +-- +2.42.0 + -- 2.47.3