[SLOF] [PATCH 5/5] Move the code for rfill into a separate function

Thomas Huth thuth at redhat.com
Thu Nov 26 06:58:19 AEDT 2015


The code from the FAST_RFILL macro uses a local array as a
temporary buffer - which gets allocated in the stack frame
of the engine() function. Since engine() can be called
recursively, this can cause stack overflows. So let's
move the rfill code into a separate function to avoid
these problems.

Signed-off-by: Thomas Huth <thuth at redhat.com>
---
 include/ppcp7/cache.h  | 13 ++-----------
 lib/libhvcall/Makefile |  2 +-
 lib/libhvcall/rfill.c  | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 41 insertions(+), 12 deletions(-)
 create mode 100644 lib/libhvcall/rfill.c

diff --git a/include/ppcp7/cache.h b/include/ppcp7/cache.h
index 27975f0..3c02bb1 100644
--- a/include/ppcp7/cache.h
+++ b/include/ppcp7/cache.h
@@ -124,17 +124,8 @@ static inline void ci_rmove(void *dst, void *src, unsigned long esize,
 
 #define FAST_MRMOVE(s, d, size) _FASTRMOVE(s, d, size)
 
-#define FAST_RFILL(dst, size, pat) do { \
-		type_u buf[64]; \
-		char *d = (char *)(dst); \
-		memset(buf, pat, size < sizeof(buf) ? size : sizeof(buf)); \
-		while (size > sizeof(buf)) { \
-			FAST_MRMOVE(buf, d, sizeof(buf)); \
-			d += sizeof(buf); \
-			size -= sizeof(buf); \
-		} \
-		FAST_MRMOVE(buf, d, size); \
-	} while(0)
+extern void fast_rfill(char *dst, long size, char pat);
+#define FAST_RFILL(dst, size, pat) fast_rfill(dst, size, pat)
 
 static inline uint16_t bswap16_load(uint64_t addr)
 {
diff --git a/lib/libhvcall/Makefile b/lib/libhvcall/Makefile
index 2a9b2d7..def5325 100644
--- a/lib/libhvcall/Makefile
+++ b/lib/libhvcall/Makefile
@@ -24,7 +24,7 @@ TARGET = ../libhvcall.a
 
 all: $(TARGET)
 
-SRCS = brokensc1.c
+SRCS = brokensc1.c rfill.c
 SRCSS = hvcall.S
 
 
diff --git a/lib/libhvcall/rfill.c b/lib/libhvcall/rfill.c
new file mode 100644
index 0000000..5407cd2
--- /dev/null
+++ b/lib/libhvcall/rfill.c
@@ -0,0 +1,38 @@
+/*****************************************************************************
+ * Fast function for filling cache-inhibited memory regions via h-call.
+ *
+ * Copyright 2015 Red Hat, Inc.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the BSD License
+ * which accompanies this distribution, and is available at
+ * http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ *     Thomas Huth, Red Hat Inc. - initial implementation
+ *****************************************************************************/
+
+#include <cache.h>
+#include <string.h>
+
+typedef unsigned long type_u;
+
+/**
+ * fast_rfill is the implementation of the FAST_RFILL macro with h-calls.
+ * This is defined here instead of cache.h since we need a temporary
+ * local buffer - and that caused stack size problems in engine() when
+ * we used it directly in the FAST_RFILL macro.
+ */
+void fast_rfill(char *dst, long size, char pat)
+{
+	type_u buf[64];
+
+	memset(buf, pat, size < sizeof(buf) ? size : sizeof(buf));
+
+	while (size > sizeof(buf)) {
+		FAST_MRMOVE(buf, dst, sizeof(buf));
+		dst += sizeof(buf);
+		size -= sizeof(buf);
+	}
+	FAST_MRMOVE(buf, dst, size);
+}
-- 
1.8.3.1



More information about the SLOF mailing list