From: Yuzhuo Jing <yuzhuo@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Liang Kan <kan.liang@linux.intel.com>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
"Steven Rostedt (Google)" <rostedt@goodmis.org>,
James Clark <james.clark@linaro.org>,
Tomas Glozar <tglozar@redhat.com>, Leo Yan <leo.yan@arm.com>,
Guilherme Amadio <amadio@gentoo.org>,
Yuzhuo Jing <yuzhuo@google.com>,
Yang Jihong <yangjihong@bytedance.com>,
"Masami Hiramatsu (Google)" <mhiramat@kernel.org>,
Adhemerval Zanella <adhemerval.zanella@linaro.org>,
Wei Yang <richard.weiyang@gmail.com>,
Ard Biesheuvel <ardb@kernel.org>,
"Mike Rapoport (Microsoft)" <rppt@kernel.org>,
Athira Rajeev <atrajeev@linux.vnet.ibm.com>,
Kajol Jain <kjain@linux.ibm.com>,
Aditya Gupta <adityag@linux.ibm.com>,
Charlie Jenkins <charlie@rivosinc.com>,
"Steinar H. Gunderson" <sesse@google.com>,
"Dr. David Alan Gilbert" <linux@treblig.org>,
Herbert Xu <herbert@gondor.apana.org.au>,
Jeff Johnson <jeff.johnson@oss.qualcomm.com>,
Al Viro <viro@zeniv.linux.org.uk>,
linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
llvm@lists.linux.dev
Subject: [PATCH v1 1/4] perf utils: Add support functions for sha1 utils
Date: Wed, 21 May 2025 15:53:04 -0700 [thread overview]
Message-ID: <20250521225307.743726-2-yuzhuo@google.com> (raw)
In-Reply-To: <20250521225307.743726-1-yuzhuo@google.com>
Add missing functions to the shrunk down version tools headers from the
kernel headers to support sha1 utils.
Signed-off-by: Yuzhuo Jing <yuzhuo@google.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
next prev parent reply other threads:[~2025-05-21 22:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-21 22:53 [PATCH v1 0/4] perf: Remove libcrypto dependency Yuzhuo Jing
2025-05-21 22:53 ` Yuzhuo Jing [this message]
2025-05-21 22:53 ` [PATCH v1 2/4] perf tools: Add sha1 utils Yuzhuo Jing
2025-05-22 17:03 ` Arnaldo Carvalho de Melo
2025-05-22 17:56 ` Arnaldo Carvalho de Melo
2025-06-04 18:17 ` Yuzhuo Jing
2025-06-06 18:27 ` Ian Rogers
2025-06-06 20:17 ` Arnaldo Carvalho de Melo
2025-05-21 22:53 ` [PATCH v1 3/4] perf genelf: Remove libcrypto dependency and use " Yuzhuo Jing
2025-05-22 17:05 ` Arnaldo Carvalho de Melo
2025-05-22 17:23 ` Arnaldo Carvalho de Melo
2025-05-21 22:53 ` [PATCH v1 4/4] tools: Remove libcrypto dependency Yuzhuo Jing
2025-05-22 17:30 ` Arnaldo Carvalho de Melo
2025-05-29 19:31 ` [PATCH v1 0/4] perf: " Ian Rogers
2025-05-29 20:24 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250521225307.743726-2-yuzhuo@google.com \
--to=yuzhuo@google.com \
--cc=acme@kernel.org \
--cc=adhemerval.zanella@linaro.org \
--cc=adityag@linux.ibm.com \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=amadio@gentoo.org \
--cc=ardb@kernel.org \
--cc=atrajeev@linux.vnet.ibm.com \
--cc=charlie@rivosinc.com \
--cc=herbert@gondor.apana.org.au \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jeff.johnson@oss.qualcomm.com \
--cc=jolsa@kernel.org \
--cc=justinstitt@google.com \
--cc=kan.liang@linux.intel.com \
--cc=kjain@linux.ibm.com \
--cc=leo.yan@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=linux@treblig.org \
--cc=llvm@lists.linux.dev \
--cc=mark.rutland@arm.com \
--cc=mhiramat@kernel.org \
--cc=mingo@redhat.com \
--cc=morbo@google.com \
--cc=namhyung@kernel.org \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=peterz@infradead.org \
--cc=richard.weiyang@gmail.com \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=sesse@google.com \
--cc=tglozar@redhat.com \
--cc=viro@zeniv.linux.org.uk \
--cc=yangjihong@bytedance.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox