Skip to contentSkip to conversation

ipipe: Avoid recursive faults on root work overflow

PATCH In review Jan Kiszka 2 participants 3 messages Jul 1, 2021

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 ipipe: Avoid recursive faults on root work overflow

From: Jan Kiszka <[email protected]>

On some archs, WARN* is implemented by triggering a fault. This can cause troubles if we are already in a fault and try to submit too much root work. Convert to open-coded warning and stack dump.

---

Doesn't solve the overflow you've seen, Mauro, but should give a better hint.

 kernel/ipipe/core.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
kernel/ipipe/core.c +9 -2
index 99a88e4d620e..485db973b81b 100644
@@ -2027,9 +2027,16 @@ void __ipipe_post_work_root(struct ipipe_work_header *work)
 	cpu = ipipe_processor_id();
 	tail = per_cpu(work_tail, cpu);
 
-	if (WARN_ON_ONCE((unsigned char *)tail + work->size >=
-			 per_cpu(work_buf, cpu) + WORKBUF_SIZE))
+	if (unlikely((unsigned char *)tail + work->size >=
+		     per_cpu(work_buf, cpu) + WORKBUF_SIZE)) {
+		static volatile unsigned long once;
+		if (!test_and_set_bit(0, &once)) {
+			ipipe_prepare_panic();
+			pr_err("I-pipe root work queue overflow! System may be unstable now.\n");
+			dump_stack();
+		}
 		goto out;
+	}
 
 	/* Work handling is deferred, so data has to be copied. */
 	memcpy(tail, work, work->size);
Signature · 1 line
2.26.2
author
#1 lore raw
Quoted 29 lines · Jan Kiszka via Xenomai

From: Jan Kiszka <[email protected]>

On some archs, WARN* is implemented by triggering a fault. This can cause troubles if we are already in a fault and try to submit too much root work. Convert to open-coded warning and stack dump.

---

Doesn't solve the overflow you've seen, Mauro, but should give a better hint.

 kernel/ipipe/core.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
kernel/ipipe/core.c +3 -2
index 99a88e4d620e..485db973b81b 100644
@@ -2027,9 +2027,16 @@ void __ipipe_post_work_root(struct ipipe_work_header *work)
 	cpu = ipipe_processor_id();
 	tail = per_cpu(work_tail, cpu);
 
-	if (WARN_ON_ONCE((unsigned char *)tail + work->size >=
-			 per_cpu(work_buf, cpu) + WORKBUF_SIZE))
+	if (unlikely((unsigned char *)tail + work->size >=
+		     per_cpu(work_buf, cpu) + WORKBUF_SIZE)) {
+		static volatile unsigned long once;

kernel/ipipe/core.c void __ipipe_post_work_root(struct ipipe_work_header *work) · line 2042

Quoted 10 lines
kernel/ipipe/core.c +6 -0
+		if (!test_and_set_bit(0, &once)) {
+			ipipe_prepare_panic();
+			pr_err("I-pipe root work queue overflow! System may be unstable now.\n");
+			dump_stack();
+		}
 		goto out;
+	}
 
 	/* Work handling is deferred, so data has to be copied. */
 	memcpy(tail, work, work->size);

Possibly relevant for ARM/64 as well. Patch is in 4.19 and head noarch trees now.

Jan

Signature · 2 lines
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
#2 lore raw
Quoted 43 lines · Jan Kiszka

kernel/ipipe/core.c void __ipipe_post_work_root(struct

Quoted 20 lines · Jan Kiszka via Xenomai

From: Jan Kiszka <[email protected]>

On some archs, WARN* is implemented by triggering a fault. This can cause troubles if we are already in a fault and try to submit too much root work. Convert to open-coded warning and stack dump.

---

Doesn't solve the overflow you've seen, Mauro, but should give a better hint.

 kernel/ipipe/core.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
kernel/ipipe/core.c +0 -0
index 99a88e4d620e..485db973b81b 100644
@@ -2027,9 +2027,16 @@ void __ipipe_post_work_root(struct

ipipe_work_header *work)

kernel/ipipe/core.c void __ipipe_post_work_root(struct ipipe_work_header *work)

Quoted 11 lines
kernel/ipipe/core.c +6 -2
      cpu = ipipe_processor_id();
      tail = per_cpu(work_tail, cpu);
 
-     if (WARN_ON_ONCE((unsigned char *)tail + work->size >=
-                      per_cpu(work_buf, cpu) + WORKBUF_SIZE))
+     if (unlikely((unsigned char *)tail + work->size >=
+                  per_cpu(work_buf, cpu) + WORKBUF_SIZE)) {
+             static volatile unsigned long once;
+             if (!test_and_set_bit(0, &once)) {
+                     ipipe_prepare_panic();
+                     pr_err("I-pipe root work queue overflow! System

may be unstable now.\n");

kernel/ipipe/core.c void __ipipe_post_work_root(struct ipipe_work_header *work) · line 2042

Quoted 8 lines
kernel/ipipe/core.c +3 -0
+                     dump_stack();
+             }
              goto out;
+     }
 
      /* Work handling is deferred, so data has to be copied. */
      memcpy(tail, work, work->size);
Quoted 8 lines

Possibly relevant for ARM/64 as well. Patch is in 4.19 and head noarch trees now.

Jan

--
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux

Thanks, I’ll pull these in and do a new release shortly.

Greg

Quoted 2 lines