]> sourceware.org Git - systemtap.git/commitdiff
PR23860: reduce stack pressure from format strings
authorSerhei Makarov <smakarov@redhat.com>
Fri, 9 Nov 2018 21:24:09 +0000 (16:24 -0500)
committerSerhei Makarov <smakarov@redhat.com>
Fri, 9 Nov 2018 21:45:47 +0000 (16:45 -0500)
Reduce stack pressure created by the earlier commits by allocating
format strings in a predictable location in the top half of the stack
[-BPF_MAXSTRINGLEN*2..0) as long as they fit in there. This works
since only one format string is active at a time and no ordinary
strings are being allocated in that region of the stack now.

* bpf-opt.cxx (alloc_literal_str): Store format_str in top half.

bpf-opt.cxx

index f3aa5c46285dcaf852bcca1c7b79f45d5a6ac9c5..5c7acb6b983f524ca425ab9e56316161d5026b34 100644 (file)
@@ -27,6 +27,16 @@ alloc_literal_str(program &p, insn_inserter &ins, value *s)
   str_bytes += 4 - str_bytes % 4; // write aligned words to avoid garbage data
 
   int ofs; size_t tmp_space;
+  if (s->is_format() && str_bytes <= BPF_MAXSTRINGLEN * 2)
+    {
+      // PR23068 workaround mitigation to reduce stack pressure:
+      //
+      // Store format strings in the top of the stack, since at most
+      // one printf() operation is prepared at a time and other string
+      // values will not be stored in that area now.
+      ofs = -str_bytes;
+      goto write_string;
+    }
 
   // Append the string to existing temporary data.
   //
@@ -65,6 +75,7 @@ alloc_literal_str(program &p, insn_inserter &ins, value *s)
   p.use_tmp_space(tmp_space);
   ofs = -tmp_space;
 
+ write_string:
   value *frame = p.lookup_reg(BPF_REG_10);
   value *out = emit_simple_literal_str(p, ins, frame, ofs, str, false /* don't zero pad */);
   return out;
This page took 0.028418 seconds and 5 git commands to generate.