[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250521225307.743726-2-yuzhuo@google.com>
Date: Wed, 21 May 2025 15:53:04 -0700
From: Yuzhuo Jing <yuzhuo@...gle.com>
To: Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>, Namhyung Kim <namhyung@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>, Jiri Olsa <jolsa@...nel.org>,
Ian Rogers <irogers@...gle.com>, Adrian Hunter <adrian.hunter@...el.com>,
Liang Kan <kan.liang@...ux.intel.com>, Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <nick.desaulniers+lkml@...il.com>, Bill Wendling <morbo@...gle.com>,
Justin Stitt <justinstitt@...gle.com>, "Steven Rostedt (Google)" <rostedt@...dmis.org>,
James Clark <james.clark@...aro.org>, Tomas Glozar <tglozar@...hat.com>, Leo Yan <leo.yan@....com>,
Guilherme Amadio <amadio@...too.org>, Yuzhuo Jing <yuzhuo@...gle.com>,
Yang Jihong <yangjihong@...edance.com>,
"Masami Hiramatsu (Google)" <mhiramat@...nel.org>, Adhemerval Zanella <adhemerval.zanella@...aro.org>,
Wei Yang <richard.weiyang@...il.com>, Ard Biesheuvel <ardb@...nel.org>,
"Mike Rapoport (Microsoft)" <rppt@...nel.org>, Athira Rajeev <atrajeev@...ux.vnet.ibm.com>,
Kajol Jain <kjain@...ux.ibm.com>, Aditya Gupta <adityag@...ux.ibm.com>,
Charlie Jenkins <charlie@...osinc.com>, "Steinar H. Gunderson" <sesse@...gle.com>,
"Dr. David Alan Gilbert" <linux@...blig.org>, Herbert Xu <herbert@...dor.apana.org.au>,
Jeff Johnson <jeff.johnson@....qualcomm.com>, Al Viro <viro@...iv.linux.org.uk>,
linux-kernel@...r.kernel.org, linux-perf-users@...r.kernel.org,
llvm@...ts.linux.dev
Subject: [PATCH v1 1/4] perf utils: Add support functions for sha1 utils
Add missing functions to the shrunk down version tools headers from the
kernel headers to support sha1 utils.
Signed-off-by: Yuzhuo Jing <yuzhuo@...gle.com>
---
tools/include/linux/bitops.h | 10 ++++++++++
tools/include/linux/compiler.h | 17 +++++++++++++++++
tools/include/linux/string.h | 22 ++++++++++++++++++++++
3 files changed, 49 insertions(+)
diff --git a/tools/include/linux/bitops.h b/tools/include/linux/bitops.h
index b4e4cd071f8c..6a027031225c 100644
--- a/tools/include/linux/bitops.h
+++ b/tools/include/linux/bitops.h
@@ -89,6 +89,16 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
return (word << shift) | (word >> ((-shift) & 31));
}
+/**
+ * ror32 - rotate a 32-bit value right
+ * @word: value to rotate
+ * @shift: bits to roll
+ */
+static inline __u32 ror32(__u32 word, unsigned int shift)
+{
+ return (word >> (shift & 31)) | (word << ((-shift) & 31));
+}
+
/**
* sign_extend64 - sign extend a 64-bit value using specified bit as sign-bit
* @value: value to sign extend
diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
index 9c05a59f0184..72e92b202976 100644
--- a/tools/include/linux/compiler.h
+++ b/tools/include/linux/compiler.h
@@ -40,6 +40,23 @@
/* The "volatile" is due to gcc bugs */
#define barrier() __asm__ __volatile__("": : :"memory")
+#ifndef barrier_data
+/*
+ * This version is i.e. to prevent dead stores elimination on @ptr
+ * where gcc and llvm may behave differently when otherwise using
+ * normal barrier(): while gcc behavior gets along with a normal
+ * barrier(), llvm needs an explicit input variable to be assumed
+ * clobbered. The issue is as follows: while the inline asm might
+ * access any memory it wants, the compiler could have fit all of
+ * @ptr into memory registers instead, and since @ptr never escaped
+ * from that, it proved that the inline asm wasn't touching any of
+ * it. This version works well with both compilers, i.e. we're telling
+ * the compiler that the inline asm absolutely may see the contents
+ * of @ptr. See also: https://llvm.org/bugs/show_bug.cgi?id=15495
+ */
+# define barrier_data(ptr) __asm__ __volatile__("": :"r"(ptr) :"memory")
+#endif
+
#ifndef __always_inline
# define __always_inline inline __attribute__((always_inline))
#endif
diff --git a/tools/include/linux/string.h b/tools/include/linux/string.h
index 8499f509f03e..df3c95792a51 100644
--- a/tools/include/linux/string.h
+++ b/tools/include/linux/string.h
@@ -3,6 +3,7 @@
#define _TOOLS_LINUX_STRING_H_
#include <linux/types.h> /* for size_t */
+#include <linux/compiler.h> /* for barrier_data */
#include <string.h>
void *memdup(const void *src, size_t len);
@@ -52,4 +53,25 @@ extern void remove_spaces(char *s);
extern void *memchr_inv(const void *start, int c, size_t bytes);
extern unsigned long long memparse(const char *ptr, char **retptr);
+
+/**
+ * memzero_explicit - Fill a region of memory (e.g. sensitive
+ * keying data) with 0s.
+ * @s: Pointer to the start of the area.
+ * @count: The size of the area.
+ *
+ * Note: usually using memset() is just fine (!), but in cases
+ * where clearing out _local_ data at the end of a scope is
+ * necessary, memzero_explicit() should be used instead in
+ * order to prevent the compiler from optimising away zeroing.
+ *
+ * memzero_explicit() doesn't need an arch-specific version as
+ * it just invokes the one of memset() implicitly.
+ */
+static inline void memzero_explicit(void *s, size_t count)
+{
+ memset(s, 0, count);
+ barrier_data(s);
+}
+
#endif /* _TOOLS_LINUX_STRING_H_ */
--
2.49.0.1164.gab81da1b16-goog
Powered by blists - more mailing lists