Blame SOURCES/rhbz1643997.0027-PR23860-reduce-stack-pressure-from-format-strings.patch

583230
From 59ec363d7236d92f896135ef8fe85433d6f1995e Mon Sep 17 00:00:00 2001
583230
From: Serhei Makarov <smakarov@redhat.com>
583230
Date: Fri, 9 Nov 2018 16:24:09 -0500
583230
Subject: [PATCH 27/32] PR23860: reduce stack pressure from format strings
583230
583230
Reduce stack pressure created by the earlier commits by allocating
583230
format strings in a predictable location in the top half of the stack
583230
[-BPF_MAXSTRINGLEN*2..0) as long as they fit in there. This works
583230
since only one format string is active at a time and no ordinary
583230
strings are being allocated in that region of the stack now.
583230
583230
* bpf-opt.cxx (alloc_literal_str): Store format_str in top half.
583230
---
583230
 bpf-opt.cxx | 11 +++++++++++
583230
 1 file changed, 11 insertions(+)
583230
583230
diff --git a/bpf-opt.cxx b/bpf-opt.cxx
583230
index f3aa5c462..5c7acb6b9 100644
583230
--- a/bpf-opt.cxx
583230
+++ b/bpf-opt.cxx
583230
@@ -27,6 +27,16 @@ alloc_literal_str(program &p, insn_inserter &ins, value *s)
583230
   str_bytes += 4 - str_bytes % 4; // write aligned words to avoid garbage data
583230
 
583230
   int ofs; size_t tmp_space;
583230
+  if (s->is_format() && str_bytes <= BPF_MAXSTRINGLEN * 2)
583230
+    {
583230
+      // PR23068 workaround mitigation to reduce stack pressure:
583230
+      //
583230
+      // Store format strings in the top of the stack, since at most
583230
+      // one printf() operation is prepared at a time and other string
583230
+      // values will not be stored in that area now.
583230
+      ofs = -str_bytes;
583230
+      goto write_string;
583230
+    }
583230
 
583230
   // Append the string to existing temporary data.
583230
   //
583230
@@ -65,6 +75,7 @@ alloc_literal_str(program &p, insn_inserter &ins, value *s)
583230
   p.use_tmp_space(tmp_space);
583230
   ofs = -tmp_space;
583230
 
583230
+ write_string:
583230
   value *frame = p.lookup_reg(BPF_REG_10);
583230
   value *out = emit_simple_literal_str(p, ins, frame, ofs, str, false /* don't zero pad */);
583230
   return out;
583230
-- 
583230
2.14.5
583230