From nobody Sun Dec 14 19:20:26 2025 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E52DD23A9B8 for ; Wed, 21 May 2025 22:54:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747868054; cv=none; b=CL7oi1B0HBNqXU1opaDXiS1Iin2deN1tfiedzB56StfcN099FuZYX5x7NAOIRqexctg1DZwlhRPrHMxmREpp+eWKaOu9pIpmEULwVK7afGrBAUSzWtN38XpUGRmWTaEM/sn5QfiytRalYR18J5NcsTiNARDbMXjcrtjsTP8qvz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747868054; c=relaxed/simple; bh=i4qJcHC4AXmCz4+v5m4Aw3Tqwh0i/7XUMvLhkU4ocZg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=Pu29aOETUODLeLT0ltf1sOB/1RBMomPOcoeEjXEHH5ZK9fAEqnrEB2cqgIu2f/QjSDjtvjkLleHBLq2IGtenWS2KvcDIZIDw+eC+bnphEbLA45QNdQ3cYP4E4eoMW8CL+yQT3rtavVPp84wNLvUZWfub8yNotkxKsQ/tlIKJFKI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yuzhuo.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=mTzeFZxc; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yuzhuo.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="mTzeFZxc" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-30e9e81d4b0so6665392a91.3 for ; Wed, 21 May 2025 15:54:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1747868052; x=1748472852; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=MTjLK1VK7KWwntnP1zRVvSaeiNRGhMUiu9M8vIKuSKI=; b=mTzeFZxcoYmGHDiOTWbMhb/A88Ce85Wa4fxnVOJmIbCIsnaMRHLMk9hLQqe5CcZ6aE bKaajKTz9rp7/Kn6TEiPF7dr1f7uoY0ojA65h7pz5m60woaw8/qH0v2PYYtXHR6S24ee fJURDcVsXYT4KFhaSYOhltdM3RCtJ+m2bzits018fjBbzlL3nNGRmWJgIIiq0cuRbLrB gx8aWvMJuHxFsp48jP5WXzghB8kI5pwBt9E9GTYxjvDFjf6tfm+1TtfaGkQQwwfqrZeG QB4rBN3NIZ2dqm6PIJ3CTFag+ZJj+DL1E+uZOY9khoQq/DrKa+BpfWv/8KUAoIT9wE6O jfWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747868052; x=1748472852; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=MTjLK1VK7KWwntnP1zRVvSaeiNRGhMUiu9M8vIKuSKI=; b=IF33mBh+iiJ/Zo2ymoS43wZudHszprWS4CJ7ZZLYFrNS7oq0wwlsUqRCX0gwS4465x Jg1ZBx2Np4UlJCXRKErKztXfsQpXjo/Qqo7MutqO69LHf/4o45Qvyx6dcxKwAGwAUHWB 9n8/0Zqoma8HZnN2KaHIXh1v5iUk8M84GxOUigTBA+8iCc+vkxZ6pp+P7fW+JJPXVOho ZXQtneb+xGHQOl63NMP/C+IMKS+7Hmg/0LNj2rNel3gOCiQShpZlaNgYIlmfLJDATDgL N98+dj92DFsvW08j4QHsN4uHgs/ednRpkjf/1tOlkvBocvjmVBdljOu8/WiM1pjiWTN0 P0Lg== X-Forwarded-Encrypted: i=1; AJvYcCXNQvt+CMzhbqIn/kbMORjgyYo2kPl6Qyw3sB5PODSL7p6PUgvhjbGJThhzOcRx8MQbRCD6D3i08vO3U3Y=@vger.kernel.org X-Gm-Message-State: AOJu0YxdWbec2GscnjKMEGJ6kTRJUaEzs3XjW1MKYwe9YUqWmPOsVRQs QUEIBlCnZCk3uVzRk+0UUQjPjmch+Lgg5wrsY0OjmvSjzR8kB2ZWreWrpmIDrBxCsJuprXe3lLG af+w62w== X-Google-Smtp-Source: AGHT+IFmnmxwO0MLdVfjk/jYioN8tCVaKs4uDbmfl+l9zYOM4srNZri9GV62ypwvXHSucke23gOipFD43Yk= X-Received: from plkg8.prod.google.com ([2002:a17:903:19c8:b0:223:242b:480a]) (user=yuzhuo job=prod-delivery.src-stubby-dispatcher) by 2002:a17:902:d543:b0:22f:af3f:bf22 with SMTP id d9443c01a7336-231de3ba64fmr296480105ad.42.1747868052157; Wed, 21 May 2025 15:54:12 -0700 (PDT) Date: Wed, 21 May 2025 15:53:04 -0700 In-Reply-To: <20250521225307.743726-1-yuzhuo@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250521225307.743726-1-yuzhuo@google.com> X-Mailer: git-send-email 2.49.0.1164.gab81da1b16-goog Message-ID: <20250521225307.743726-2-yuzhuo@google.com> Subject: [PATCH v1 1/4] perf utils: Add support functions for sha1 utils From: Yuzhuo Jing To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Liang Kan , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , "Steven Rostedt (Google)" , James Clark , Tomas Glozar , Leo Yan , Guilherme Amadio , Yuzhuo Jing , Yang Jihong , "Masami Hiramatsu (Google)" , Adhemerval Zanella , Wei Yang , Ard Biesheuvel , "Mike Rapoport (Microsoft)" , Athira Rajeev , Kajol Jain , Aditya Gupta , Charlie Jenkins , "Steinar H. Gunderson" , "Dr. David Alan Gilbert" , Herbert Xu , Jeff Johnson , Al Viro , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add missing functions to the shrunk down version tools headers from the kernel headers to support sha1 utils. Signed-off-by: Yuzhuo Jing Tested-by: Ian Rogers --- 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)); } =20 +/** + * 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") =20 +#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=3D15495 + */ +# 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_ =20 #include /* for size_t */ +#include /* for barrier_data */ #include =20 void *memdup(const void *src, size_t len); @@ -52,4 +53,25 @@ extern void remove_spaces(char *s); =20 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_ */ --=20 2.49.0.1164.gab81da1b16-goog From nobody Sun Dec 14 19:20:26 2025 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 975F323BF8F for ; Wed, 21 May 2025 22:54:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747868057; cv=none; b=FslHjRS+SL3BavEkBIy0tCcrfKsPJuexSJnKUhg4HP/4e/m64yBSm3EDThFTcAOE7Yt2YM0uYp3A/jWcbshYAZqAtFOKz6Gv+9OEG8iK49vjOI1pt6RT2ZsSEJPia7TCfkhpJI043AXUYFUwxWGEoZkwE7haYOWSFs+BmTHydII= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747868057; c=relaxed/simple; bh=d2rJA7G+jwUoRMjm3TQ8lzd6ZwA1L33yy/0oEX1JfxE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=rpXVqFaJI0SMKTHtmyYe30BlVCN/I0MHkKRak3WEB1zix9lphPod26lF/WpyGF+Ts0ukpsh/9I6yfAeQYBuE1bRxsGs2mSyiZQYU/MsBNqdB7x1FvM7bWew2vCarcaUUJpiGS/3AZLEirVoB8mKQ23bknx1OmXCZA3egexSpv3E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yuzhuo.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=c6saEHfE; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yuzhuo.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="c6saEHfE" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-30e9659a391so4569597a91.0 for ; Wed, 21 May 2025 15:54:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1747868054; x=1748472854; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=//ERDOnJgsKO7BhUhvUMeqTIqu4t02IBQ8dRbwwSono=; b=c6saEHfETcGUCj7QBMP6CIyOnkw/TRduq2VOdU+OvoxiGFfM7txzGOdDM4Ke1pfzrJ lMrfF1wmrtXgpqB3bcES4xzuUj7PbMW95jfT/6IP7s3neg8Xz1vcpOXYVx7ZnOmaWN2D jFp1MmLs+hCnM9CBqKsJnrbP65x3IdiZuwpy2/z2JyB+rOf+f8qkpy+HgysQ9xet4t6w 4aX2b+nsnLDsCZxG0Bm0oxx9n0oFNGvNHNQ0RSAinwl4GzwhGsAL7RxgRDnVgZCPXcQI 2YZQmMidsgX/REuZyoVlv6E7UiWze/57xbgi4CM/jSWj7F1bcEGIcm2KX/UW5Q3HUHuT 9CVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747868054; x=1748472854; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=//ERDOnJgsKO7BhUhvUMeqTIqu4t02IBQ8dRbwwSono=; b=ZMRlwUGhoNgrEXz26vO0bm6Yn1helg0yC9iKsRlf12nuVrDsVVD2MLZ2T4H2rLHM+b KaxuzXkgdufvj7Dk5Kj+gulsAg2vhfbniZv7P0ymRyP3qjxtzNH8ZtE2R7WtjkEjO1h/ pPhVyzjTseK8nqhIx69Kj2KjVGGkWGllc0SHHForZ2uNy3+XRq6ZDx6tyAbzplgANG6V +BGUBiO4YqKHZap+2qiwtReCDJodyBPjv55mFN8FFGPgZ7ftd3BHEkj6sJWN3QZMAYkE E288mjIA2uNIdKw6kRRTF2FqBIIITHEQGNXqNqkwItI5O+9JI+wYhYMQfXVxo9uEUSJp t5lA== X-Forwarded-Encrypted: i=1; AJvYcCW6QaQWCqvfyfkA0Qztke2PqJ1gg9e4yb+aRDBTHt8X9f14l8hvhpS2+fMt+ss2zPx9VomnKD2BCS6WwtQ=@vger.kernel.org X-Gm-Message-State: AOJu0Yz69A52H8pfC7zNuTFiS/glmkTmdoz+MBTHFyjbmZoizwKbKmH4 YtvCcnHNFs6fHPvZHUNs4on4fC2sM0ab8mv2rYKVyS3cKNEtRDc0uUvjwTQvNZzp0gXYd1oDWCg VElpgcA== X-Google-Smtp-Source: AGHT+IHkKbwEjL2MD72gwxTrxDKE8LBZSKj9LKUcEYr9R6Vukr4nHcCEGBKYkRqfgFqDJbthREUj1MrZ6EA= X-Received: from pjb7.prod.google.com ([2002:a17:90b:2f07:b0:2fe:800f:23a]) (user=yuzhuo job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:4f4c:b0:301:a0e9:66f with SMTP id 98e67ed59e1d1-30e830ebf11mr36896809a91.14.1747868053829; Wed, 21 May 2025 15:54:13 -0700 (PDT) Date: Wed, 21 May 2025 15:53:05 -0700 In-Reply-To: <20250521225307.743726-1-yuzhuo@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250521225307.743726-1-yuzhuo@google.com> X-Mailer: git-send-email 2.49.0.1164.gab81da1b16-goog Message-ID: <20250521225307.743726-3-yuzhuo@google.com> Subject: [PATCH v1 2/4] perf tools: Add sha1 utils From: Yuzhuo Jing To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Liang Kan , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , "Steven Rostedt (Google)" , James Clark , Tomas Glozar , Leo Yan , Guilherme Amadio , Yuzhuo Jing , Yang Jihong , "Masami Hiramatsu (Google)" , Adhemerval Zanella , Wei Yang , Ard Biesheuvel , "Mike Rapoport (Microsoft)" , Athira Rajeev , Kajol Jain , Aditya Gupta , Charlie Jenkins , "Steinar H. Gunderson" , "Dr. David Alan Gilbert" , Herbert Xu , Jeff Johnson , Al Viro , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Those new files are derived from the kernel tree, namely: tools/perf/util/sha1.c from lib/crypto/sha1.c tools/perf/util/sha1.h from include/crypto/sha1.h tools/perf/util/sha1_base.h from include/crypto/sha1_base.h tools/perf/util/sha1_generic.c from crypto/sha1_generic.c The reason that we are not syncing them with the kernel tree like other tools header files is because of the deep dependency in include/crypto/hash.h. It's painful to import the whole kernel crypto driver infrastructure into tools. The derived files get rid of struct shash_desc definition, and directly operates on the struct sha1_state. Signed-off-by: Yuzhuo Jing Tested-by: Ian Rogers --- tools/perf/util/Build | 2 + tools/perf/util/sha1.c | 122 +++++++++++++++++++++++++++++++++ tools/perf/util/sha1.h | 41 +++++++++++ tools/perf/util/sha1_base.h | 103 ++++++++++++++++++++++++++++ tools/perf/util/sha1_generic.c | 49 +++++++++++++ 5 files changed, 317 insertions(+) create mode 100644 tools/perf/util/sha1.c create mode 100644 tools/perf/util/sha1.h create mode 100644 tools/perf/util/sha1_base.h create mode 100644 tools/perf/util/sha1_generic.c diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 7910d908c814..ecee96b3f3fa 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -41,6 +41,8 @@ perf-util-y +=3D rbtree.o perf-util-y +=3D libstring.o perf-util-y +=3D bitmap.o perf-util-y +=3D hweight.o +perf-util-y +=3D sha1.o +perf-util-y +=3D sha1_generic.o perf-util-y +=3D smt.o perf-util-y +=3D strbuf.o perf-util-y +=3D string.o diff --git a/tools/perf/util/sha1.c b/tools/perf/util/sha1.c new file mode 100644 index 000000000000..5ae658afb56b --- /dev/null +++ b/tools/perf/util/sha1.c @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * SHA1 routine optimized to do word accesses rather than byte accesses, + * and to avoid unnecessary copies into the context array. + * + * This was based on the git SHA1 implementation. + */ + +#include +#include +#include +#include + +#include "sha1.h" + +/* + * If you have 32 registers or more, the compiler can (and should) + * try to change the array[] accesses into registers. However, on + * machines with less than ~25 registers, that won't really work, + * and at least gcc will make an unholy mess of it. + * + * So to avoid that mess which just slows things down, we force + * the stores to memory to actually happen (we might be better off + * with a 'W(t)=3D(val);asm("":"+m" (W(t))' there instead, as + * suggested by Artur Skawina - that will also make gcc unable to + * try to do the silly "optimize away loads" part because it won't + * see what the value will be). + * + * Ben Herrenschmidt reports that on PPC, the C version comes close + * to the optimized asm with this (ie on PPC you don't want that + * 'volatile', since there are lots of registers). + * + * On ARM we get the best code generation by forcing a full memory barrier + * between each SHA_ROUND, otherwise gcc happily get wild with spilling and + * the stack frame size simply explode and performance goes down the drain. + */ + +#ifdef CONFIG_X86 + #define setW(x, val) (*(volatile __u32 *)&W(x) =3D (val)) +#elif defined(CONFIG_ARM) + #define setW(x, val) do { W(x) =3D (val); __asm__("":::"memory"); } whil= e (0) +#else + #define setW(x, val) (W(x) =3D (val)) +#endif + +/* This "rolls" over the 512-bit array */ +#define W(x) (array[(x)&15]) + +/* + * Where do we get the source from? The first 16 iterations get it from + * the input data, the next mix it from the 512-bit array. + */ +#define SHA_SRC(t) get_unaligned_be32((__u32 *)data + t) +#define SHA_MIX(t) rol32(W(t+13) ^ W(t+8) ^ W(t+2) ^ W(t), 1) + +#define SHA_ROUND(t, input, fn, constant, A, B, C, D, E) do { \ + __u32 TEMP =3D input(t); setW(t, TEMP); \ + E +=3D TEMP + rol32(A,5) + (fn) + (constant); \ + B =3D ror32(B, 2); \ + TEMP =3D E; E =3D D; D =3D C; C =3D B; B =3D A; A =3D TEMP; } while (0) + +#define T_0_15(t, A, B, C, D, E) SHA_ROUND(t, SHA_SRC, (((C^D)&B)^D) , 0x= 5a827999, A, B, C, D, E ) +#define T_16_19(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (((C^D)&B)^D) , 0x= 5a827999, A, B, C, D, E ) +#define T_20_39(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (B^C^D) , 0x6ed9eb= a1, A, B, C, D, E ) +#define T_40_59(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, ((B&C)+(D&(B^C))) = , 0x8f1bbcdc, A, B, C, D, E ) +#define T_60_79(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (B^C^D) , 0xca62c= 1d6, A, B, C, D, E ) + +/** + * sha1_transform - single block SHA1 transform (deprecated) + * + * @digest: 160 bit digest to update + * @data: 512 bits of data to hash + * @array: 16 words of workspace (see note) + * + * This function executes SHA-1's internal compression function. It updat= es the + * 160-bit internal state (@digest) with a single 512-bit data block (@dat= a). + * + * Don't use this function. SHA-1 is no longer considered secure. And ev= en if + * you do have to use SHA-1, this isn't the correct way to hash something = with + * SHA-1 as this doesn't handle padding and finalization. + * + * Note: If the hash is security sensitive, the caller should be sure + * to clear the workspace. This is left to the caller to avoid + * unnecessary clears between chained hashing operations. + */ +void sha1_transform(__u32 *digest, const char *data, __u32 *array) +{ + __u32 A, B, C, D, E; + unsigned int i =3D 0; + + A =3D digest[0]; + B =3D digest[1]; + C =3D digest[2]; + D =3D digest[3]; + E =3D digest[4]; + + /* Round 1 - iterations 0-16 take their input from 'data' */ + for (; i < 16; ++i) + T_0_15(i, A, B, C, D, E); + + /* Round 1 - tail. Input from 512-bit mixing array */ + for (; i < 20; ++i) + T_16_19(i, A, B, C, D, E); + + /* Round 2 */ + for (; i < 40; ++i) + T_20_39(i, A, B, C, D, E); + + /* Round 3 */ + for (; i < 60; ++i) + T_40_59(i, A, B, C, D, E); + + /* Round 4 */ + for (; i < 80; ++i) + T_60_79(i, A, B, C, D, E); + + digest[0] +=3D A; + digest[1] +=3D B; + digest[2] +=3D C; + digest[3] +=3D D; + digest[4] +=3D E; +} diff --git a/tools/perf/util/sha1.h b/tools/perf/util/sha1.h new file mode 100644 index 000000000000..9da4ece49bc6 --- /dev/null +++ b/tools/perf/util/sha1.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Common values for SHA-1 algorithms + */ + +#ifndef _CRYPTO_SHA1_H +#define _CRYPTO_SHA1_H + +#include + +#define SHA1_DIGEST_SIZE 20 +#define SHA1_BLOCK_SIZE 64 + +#define SHA1_H0 0x67452301UL +#define SHA1_H1 0xefcdab89UL +#define SHA1_H2 0x98badcfeUL +#define SHA1_H3 0x10325476UL +#define SHA1_H4 0xc3d2e1f0UL + +struct sha1_state { + u32 state[SHA1_DIGEST_SIZE / 4]; + u64 count; + u8 buffer[SHA1_BLOCK_SIZE]; +}; + +extern int crypto_sha1_update(struct sha1_state *desc, const u8 *data, + unsigned int len); + +extern int crypto_sha1_finup(struct sha1_state *desc, const u8 *data, + unsigned int len, u8 *hash); + +/* + * An implementation of SHA-1's compression function. Don't use in new co= de! + * You shouldn't be using SHA-1, and even if you *have* to use SHA-1, this= isn't + * the correct way to hash something with SHA-1 (use crypto_shash instead). + */ +#define SHA1_DIGEST_WORDS (SHA1_DIGEST_SIZE / 4) +#define SHA1_WORKSPACE_WORDS 16 +void sha1_transform(__u32 *digest, const char *data, __u32 *W); + +#endif /* _CRYPTO_SHA1_H */ diff --git a/tools/perf/util/sha1_base.h b/tools/perf/util/sha1_base.h new file mode 100644 index 000000000000..cea22c5a4952 --- /dev/null +++ b/tools/perf/util/sha1_base.h @@ -0,0 +1,103 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * sha1_base.h - core logic for SHA-1 implementations + * + * Copyright (C) 2015 Linaro Ltd + */ + +#ifndef _CRYPTO_SHA1_BASE_H +#define _CRYPTO_SHA1_BASE_H + +#include + +#include +#include + +#include "sha1.h" + +typedef void (sha1_block_fn)(struct sha1_state *sst, u8 const *src, int bl= ocks); + +static inline int sha1_base_init(struct sha1_state *sctx) +{ + sctx->state[0] =3D SHA1_H0; + sctx->state[1] =3D SHA1_H1; + sctx->state[2] =3D SHA1_H2; + sctx->state[3] =3D SHA1_H3; + sctx->state[4] =3D SHA1_H4; + sctx->count =3D 0; + + return 0; +} + +static inline int sha1_base_do_update(struct sha1_state *sctx, + const u8 *data, + unsigned int len, + sha1_block_fn *block_fn) +{ + unsigned int partial =3D sctx->count % SHA1_BLOCK_SIZE; + + sctx->count +=3D len; + + if (unlikely((partial + len) >=3D SHA1_BLOCK_SIZE)) { + int blocks; + + if (partial) { + int p =3D SHA1_BLOCK_SIZE - partial; + + memcpy(sctx->buffer + partial, data, p); + data +=3D p; + len -=3D p; + + block_fn(sctx, sctx->buffer, 1); + } + + blocks =3D len / SHA1_BLOCK_SIZE; + len %=3D SHA1_BLOCK_SIZE; + + if (blocks) { + block_fn(sctx, data, blocks); + data +=3D blocks * SHA1_BLOCK_SIZE; + } + partial =3D 0; + } + if (len) + memcpy(sctx->buffer + partial, data, len); + + return 0; +} + +static inline int sha1_base_do_finalize(struct sha1_state *sctx, + sha1_block_fn *block_fn) +{ + const int bit_offset =3D SHA1_BLOCK_SIZE - sizeof(__be64); + __be64 *bits =3D (__be64 *)(sctx->buffer + bit_offset); + unsigned int partial =3D sctx->count % SHA1_BLOCK_SIZE; + + sctx->buffer[partial++] =3D 0x80; + if (partial > bit_offset) { + memset(sctx->buffer + partial, 0x0, SHA1_BLOCK_SIZE - partial); + partial =3D 0; + + block_fn(sctx, sctx->buffer, 1); + } + + memset(sctx->buffer + partial, 0x0, bit_offset - partial); + *bits =3D cpu_to_be64(sctx->count << 3); + block_fn(sctx, sctx->buffer, 1); + + return 0; +} + +static inline int sha1_base_finish(struct sha1_state *sctx, u8 *out) +{ + __be32 *digest =3D (__be32 *)out; + int i; + + for (i =3D 0; i < SHA1_DIGEST_SIZE / (int)sizeof(__be32); i++) + put_unaligned_be32(sctx->state[i], digest++); + + memzero_explicit(sctx, sizeof(*sctx)); + return 0; +} + +#endif /* _CRYPTO_SHA1_BASE_H */ diff --git a/tools/perf/util/sha1_generic.c b/tools/perf/util/sha1_generic.c new file mode 100644 index 000000000000..b0a7af370d59 --- /dev/null +++ b/tools/perf/util/sha1_generic.c @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Cryptographic API. + * + * SHA1 Secure Hash Algorithm. + * + * Derived from cryptoapi implementation, adapted for in-place + * scatterlist interface. + * + * Copyright (c) Alan Smithee. + * Copyright (c) Andrew McDonald + * Copyright (c) Jean-Francois Dive + */ +#include +#include +#include + +#include "sha1_base.h" + +static void sha1_generic_block_fn(struct sha1_state *sst, u8 const *src, + int blocks) +{ + u32 temp[SHA1_WORKSPACE_WORDS]; + + while (blocks--) { + sha1_transform(sst->state, (const char *)src, temp); + src +=3D SHA1_BLOCK_SIZE; + } + memzero_explicit(temp, sizeof(temp)); +} + +int crypto_sha1_update(struct sha1_state *desc, const u8 *data, + unsigned int len) +{ + return sha1_base_do_update(desc, data, len, sha1_generic_block_fn); +} + +static int sha1_final(struct sha1_state *desc, u8 *out) +{ + sha1_base_do_finalize(desc, sha1_generic_block_fn); + return sha1_base_finish(desc, out); +} + +int crypto_sha1_finup(struct sha1_state *desc, const u8 *data, + unsigned int len, u8 *out) +{ + sha1_base_do_update(desc, data, len, sha1_generic_block_fn); + return sha1_final(desc, out); +} --=20 2.49.0.1164.gab81da1b16-goog From nobody Sun Dec 14 19:20:26 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7883C23C8CD for ; Wed, 21 May 2025 22:54:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747868058; cv=none; b=Fx9f8AdyylruugzaOYJxoUZKHzsCBUca9/mcHiegeJU+Mcn6ASUzE+00SCoMIKqndbYJUEiPwn8S0B/a30JLai3AO8Utclx6CAHBVfDYGE6EpYhWLmMxHiF/C8dSzTbctynWTW2C7hmBqcl9dX9K1bOQ/HJr1BJLk15JEBQ+DS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747868058; c=relaxed/simple; bh=+AUYSNahAWGf9W1tBYRZu9JyCsHrw3J+A7EkvETxE5o=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=L0/zHCqvin6RU4WZ4s1/+utTz3vlfRKeRsee2pbf98isS9xi/8o7qb4SznPhaV+rdZJuwDWmDvCl+43Ge9orJExjmehRUi3EbXiD8nmVXa/dws5jHP1646ziroYP1SyBmya1znHUdLM7P+KyPfTUaEWvaL6FucS8dTBuWGHqTJk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yuzhuo.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=1dPv3eh6; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yuzhuo.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="1dPv3eh6" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-74299055c3dso10043518b3a.0 for ; Wed, 21 May 2025 15:54:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1747868055; x=1748472855; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=y5iEOEtDGQjkBBG8+IR+GBcP08I1z1xCE1eB2Wanmvw=; b=1dPv3eh6DxGR7kFDDGZT45Z1Kvt/N0uinbb+If1cuSxfnLdvcn+yV9d5cGiIUTz3c+ OUOVWXLgjPvgw3GqU407+IIsOkR1MkUxM37HJW2ElRNrzY9lbOL3Y3/Mfm2j3UbklwKk cfl8MsUFrTWHG1wCDejE1le19f9dGYQ/HD6L4fY3fFH9l5mfEk14XxkFqd311SHwBTzl 38WAzWYN8lYDzdN0Mxg3i1aDxOqCHyE8pn6OVVFooMQvGoJobEO2sBcaSAusuwNj8VVW 2O45rfmSpsmLjj3XvdGThTapWNC+t9eZDSEkbg8KGgtEaUBEpo2SPT8kKyoKM19LiNN1 ZacA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747868055; x=1748472855; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=y5iEOEtDGQjkBBG8+IR+GBcP08I1z1xCE1eB2Wanmvw=; b=cyu5wFmDdPuK/y+9EpNPig2t86haiiyAr631/hvwY652eiol7qS6BepP4YFfjEtdAW 5BXUIe21P3p5z981uPMiX5pYjBtjcadhOhnTQw09Az+G05jVoZY5ollqbJnMkoTqtoPO mGYzX3ut4+b3SnnibR3A3D1X46fBHkOj3wcqHeVda11aVSXfVfSaKECQzADLmi5KO+np R7+t+S4Vtg6dCx8vLELwa/j+mjZ5wR8uNz+0jGqcPQRYDex9vhbuAcgq1euwQRZi3DxM L3AxwT1MpNBpng/MHH3B6f1OrjaKy2LVTArO837RftH1lJMXlFq7EKtQhskucj5984Rg imqA== X-Forwarded-Encrypted: i=1; AJvYcCXdH/yKT0YkOY1RxwlrOaMAa7aN+5oc+PW3zLjLBex06/YV1R1ABMdFnqzBk4rvUUYaT+AT3T47yn9TALw=@vger.kernel.org X-Gm-Message-State: AOJu0Yxx/iCLGg7vMNaHf4Zpk6fT8VxgoFWDt8Ks9rKsnWOudAlsHY/W 7MaHsYjZGikb4qy1DPfhGeuqeVoX2bMDTS5L7CkujQV3ryuAWA3rAOFcfJe4TVCyTkmEGrUE+zo Uva4toA== X-Google-Smtp-Source: AGHT+IEK2MKOxh7O7TqCVhedlN7LWirgEvC2NFjssFnsIa6UXUWSiPhGiHliRMQVf82CzHliIwdjxuvaB50= X-Received: from pfbjw12.prod.google.com ([2002:a05:6a00:928c:b0:736:b2a2:5bfe]) (user=yuzhuo job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:3d12:b0:1f5:59e5:8ada with SMTP id adf61e73a8af0-2162187a945mr31068430637.4.1747868055561; Wed, 21 May 2025 15:54:15 -0700 (PDT) Date: Wed, 21 May 2025 15:53:06 -0700 In-Reply-To: <20250521225307.743726-1-yuzhuo@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250521225307.743726-1-yuzhuo@google.com> X-Mailer: git-send-email 2.49.0.1164.gab81da1b16-goog Message-ID: <20250521225307.743726-4-yuzhuo@google.com> Subject: [PATCH v1 3/4] perf genelf: Remove libcrypto dependency and use sha1 utils From: Yuzhuo Jing To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Liang Kan , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , "Steven Rostedt (Google)" , James Clark , Tomas Glozar , Leo Yan , Guilherme Amadio , Yuzhuo Jing , Yang Jihong , "Masami Hiramatsu (Google)" , Adhemerval Zanella , Wei Yang , Ard Biesheuvel , "Mike Rapoport (Microsoft)" , Athira Rajeev , Kajol Jain , Aditya Gupta , Charlie Jenkins , "Steinar H. Gunderson" , "Dr. David Alan Gilbert" , Herbert Xu , Jeff Johnson , Al Viro , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" genelf is the only file in perf that depends on libcrypto (or openssl) which only calculates a Build ID (SHA1, MD5, or URANDOM). SHA1 was expected to be the default option, but MD5 was used by default due to previous issues when linking against Java. This commit switches genelf to use in-house SHA1 utils, and also removes MD5 and URANDOM options since we have a reliable SHA1 implementation to rely on. It passes the tools/perf/tests/shell/test_java_symbol.sh test. Signed-off-by: Yuzhuo Jing Tested-by: Ian Rogers --- tools/perf/util/genelf.c | 72 ++++------------------------------------ 1 file changed, 6 insertions(+), 66 deletions(-) diff --git a/tools/perf/util/genelf.c b/tools/perf/util/genelf.c index cdce7f173d00..cfedb29260ef 100644 --- a/tools/perf/util/genelf.c +++ b/tools/perf/util/genelf.c @@ -28,24 +28,7 @@ #define NT_GNU_BUILD_ID 3 #endif =20 -#define BUILD_ID_URANDOM /* different uuid for each run */ - -#ifdef HAVE_LIBCRYPTO_SUPPORT - -#define BUILD_ID_MD5 -#undef BUILD_ID_SHA /* does not seem to work well when linked with Java */ -#undef BUILD_ID_URANDOM /* different uuid for each run */ - -#ifdef BUILD_ID_SHA -#include -#endif - -#ifdef BUILD_ID_MD5 -#include -#include -#endif -#endif - +#include "sha1_base.h" =20 typedef struct { unsigned int namesz; /* Size of entry's owner string */ @@ -92,64 +75,21 @@ static Elf_Sym symtab[]=3D{ } }; =20 -#ifdef BUILD_ID_URANDOM -static void -gen_build_id(struct buildid_note *note, - unsigned long load_addr __maybe_unused, - const void *code __maybe_unused, - size_t csize __maybe_unused) -{ - int fd; - size_t sz =3D sizeof(note->build_id); - ssize_t sret; - - fd =3D open("/dev/urandom", O_RDONLY); - if (fd =3D=3D -1) - err(1, "cannot access /dev/urandom for buildid"); - - sret =3D read(fd, note->build_id, sz); - - close(fd); - - if (sret !=3D (ssize_t)sz) - memset(note->build_id, 0, sz); -} -#endif - -#ifdef BUILD_ID_SHA static void gen_build_id(struct buildid_note *note, unsigned long load_addr __maybe_unused, const void *code, size_t csize) { - if (sizeof(note->build_id) < SHA_DIGEST_LENGTH) - errx(1, "build_id too small for SHA1"); - - SHA1(code, csize, (unsigned char *)note->build_id); -} -#endif - -#ifdef BUILD_ID_MD5 -static void -gen_build_id(struct buildid_note *note, unsigned long load_addr, const voi= d *code, size_t csize) -{ - EVP_MD_CTX *mdctx; + struct sha1_state sctx; =20 - if (sizeof(note->build_id) < 16) - errx(1, "build_id too small for MD5"); + if (sizeof(note->build_id) < SHA1_DIGEST_SIZE) + errx(1, "build_id too small for SHA1"); =20 - mdctx =3D EVP_MD_CTX_new(); - if (!mdctx) - errx(2, "failed to create EVP_MD_CTX"); + sha1_base_init(&sctx); =20 - EVP_DigestInit_ex(mdctx, EVP_md5(), NULL); - EVP_DigestUpdate(mdctx, &load_addr, sizeof(load_addr)); - EVP_DigestUpdate(mdctx, code, csize); - EVP_DigestFinal_ex(mdctx, (unsigned char *)note->build_id, NULL); - EVP_MD_CTX_free(mdctx); + crypto_sha1_finup(&sctx, code, csize, (unsigned char *)note->build_id); } -#endif =20 static int jit_add_eh_frame_info(Elf *e, void* unwinding, uint64_t unwinding_header_s= ize, --=20 2.49.0.1164.gab81da1b16-goog From nobody Sun Dec 14 19:20:26 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2201323D2AD for ; Wed, 21 May 2025 22:54:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747868060; cv=none; b=kaA9vgoTLhZsI/DamKD5DDkqr4SsY+i4FGLlJJfP2JDgcMxKtlrJq6gjCrv+JEmpQBCs0DTsMyH/mE3j1EaaWVHu4i42FlS21gGVqylXIbjEQiMmQPaCMrJsdfmUIvBbezXA+yQfWLGXIvsaSK3rqcUQz7FFS3DGMI+ObPik8eM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747868060; c=relaxed/simple; bh=/IZuOYb6jOm8wv3pZnvemwOfZFQ2a3K5E2hJWe/msQk=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=T94P4jKlvinvJw/uXpY/w6t5IEx/a4U/qRarXTxq6M33IWDzTzI2DKIjQDNIonVJchhY7vUoTwyfcWe4RPah3PvAsKusoa6kB01ZENSazgBMxWhlo3PFf6ZFNpy1TxRD2eyQDv16amrE+wxDofqQv9j1S0C86wzryvGc3Ury5bI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yuzhuo.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=tI2qyITC; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yuzhuo.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="tI2qyITC" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-7377139d8b1so6290281b3a.0 for ; Wed, 21 May 2025 15:54:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1747868057; x=1748472857; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=0ihLi7PZYZBdDuLpPbH4KRd+Os7j6d6WLAwKlSBj2Ys=; b=tI2qyITC95EBNOVTBYH1sqPs40H7U+DB7SkxuVQ9Nlb4p2MfH9zDu175S9L82AKMrR uxHt69BOr1rXKXMjrsYg2/vLq0NC6TYjZ/NvMDkjgATQUkahYM8vCHogRH44DnD1FGeB lMCZJrFTJZ+ceDCGBz1yigJYsgoC4ceWlgs4OnRp0DA1H7Wk/8L3jTd8gvgi6uVwpkzI KLGh04LojMmejKIXVs9cNpB8lRHP63PuS32MiyJzIHFfD0rpwCq+RIGR3fJoyRo12VKS ILNT2M9UQ5hMYOSXonbb2/F1055HCfE6WDHyk8rRScfQgqkWlbTYRyP6eSlnZoszheaZ x9yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747868057; x=1748472857; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0ihLi7PZYZBdDuLpPbH4KRd+Os7j6d6WLAwKlSBj2Ys=; b=i1IfyQXXh21yYdSJnehZsU0OiFnhw8qz23tXrt08/Ud+tYAh72zO6ZUHyCOTKED2SX xsR2QI5epy5xHRI2Xm0hiRL+2c1dgXIqstgOox9HwyBKE1eXaekJWQA/Y9MkkvoA79Vv hL5YFPMxdWydGwk028pOAM6YhTvia8RXKCH2+r/9GmLx4pyaFTNKVZiih2rM1sNjwc99 UA/pYBDMqPyYFEFH4kiC3aX+uri4hlnZ4hAt7K9DrlLlNRviB60duM/QbtqVWbx/+R+b +4+VS/oHZHRpTrE4thbE4TnnPpp5unXVPlvBcg6og0cyEF4MnlSSJ10Zpo/x5hBdZZXW WQKw== X-Forwarded-Encrypted: i=1; AJvYcCXoGzZGuAQL4cSwraEw0pqK+9LZa5Oq7TaSckHBHPQmLr1AlVHkm6OncLnVJ3+VCCaRknIhGr0HA2R445U=@vger.kernel.org X-Gm-Message-State: AOJu0YxdObFpMy4FuBELHar7aDE2cGbsWvKGtCJ//E0Fc+rwk/jxtRw2 KtH7oDQCVuTA2zN5TcOHVCjPR0VAorB07mTxH0RLwNWD2Ti4h0q+LDT2WTROIi3eDCdM73eeEnm MdSoaqQ== X-Google-Smtp-Source: AGHT+IFlqvDhagDgmm0am0QLyt1D9KzRRnWhzPMiMPi+OaIJxmlzZsP5oeZWd2bbp+CX0XipedfHv+KHA/o= X-Received: from pfqz29.prod.google.com ([2002:aa7:9e5d:0:b0:740:6f6:7346]) (user=yuzhuo job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:c8d:b0:740:aa31:fe66 with SMTP id d2e1a72fcca58-742a97768f0mr32694402b3a.4.1747868057262; Wed, 21 May 2025 15:54:17 -0700 (PDT) Date: Wed, 21 May 2025 15:53:07 -0700 In-Reply-To: <20250521225307.743726-1-yuzhuo@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250521225307.743726-1-yuzhuo@google.com> X-Mailer: git-send-email 2.49.0.1164.gab81da1b16-goog Message-ID: <20250521225307.743726-5-yuzhuo@google.com> Subject: [PATCH v1 4/4] tools: Remove libcrypto dependency From: Yuzhuo Jing To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Liang Kan , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , "Steven Rostedt (Google)" , James Clark , Tomas Glozar , Leo Yan , Guilherme Amadio , Yuzhuo Jing , Yang Jihong , "Masami Hiramatsu (Google)" , Adhemerval Zanella , Wei Yang , Ard Biesheuvel , "Mike Rapoport (Microsoft)" , Athira Rajeev , Kajol Jain , Aditya Gupta , Charlie Jenkins , "Steinar H. Gunderson" , "Dr. David Alan Gilbert" , Herbert Xu , Jeff Johnson , Al Viro , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, llvm@lists.linux.dev Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove all occurrence of libcrypto in the build system. Signed-off-by: Yuzhuo Jing Tested-by: Ian Rogers --- tools/build/Makefile.feature | 2 -- tools/build/feature/Makefile | 4 ---- tools/build/feature/test-all.c | 5 ----- tools/build/feature/test-libcrypto.c | 25 ------------------------- tools/perf/Documentation/perf-check.txt | 1 - tools/perf/Makefile.config | 13 ------------- tools/perf/Makefile.perf | 3 --- tools/perf/builtin-check.c | 1 - tools/perf/tests/make | 4 +--- 9 files changed, 1 insertion(+), 57 deletions(-) delete mode 100644 tools/build/feature/test-libcrypto.c diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature index 57bd995ce6af..bbadfb5568eb 100644 --- a/tools/build/Makefile.feature +++ b/tools/build/Makefile.feature @@ -86,7 +86,6 @@ FEATURE_TESTS_BASIC :=3D \ libtraceevent \ libtracefs \ libcpupower \ - libcrypto \ pthread-attr-setaffinity-np \ pthread-barrier \ reallocarray \ @@ -152,7 +151,6 @@ FEATURE_DISPLAY ?=3D \ numa_num_possible_cpus \ libperl \ libpython \ - libcrypto \ libcapstone \ llvm-perf \ zlib \ diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index b8b5fb183dd4..04a4aa0341aa 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -38,7 +38,6 @@ FILES=3D \ test-libtraceevent.bin \ test-libcpupower.bin \ test-libtracefs.bin \ - test-libcrypto.bin \ test-libunwind.bin \ test-libunwind-debug-frame.bin \ test-libunwind-x86.bin \ @@ -246,9 +245,6 @@ $(OUTPUT)test-libcpupower.bin: $(OUTPUT)test-libtracefs.bin: $(BUILD) $(shell $(PKG_CONFIG) --cflags libtracefs 2>/dev/null) -ltracefs =20 -$(OUTPUT)test-libcrypto.bin: - $(BUILD) -lcrypto - $(OUTPUT)test-gtk2.bin: $(BUILD) $(shell $(PKG_CONFIG) --libs --cflags gtk+-2.0 2>/dev/null) -Wno= -deprecated-declarations =20 diff --git a/tools/build/feature/test-all.c b/tools/build/feature/test-all.c index 03ddaac6f4c4..ce72e2061ac0 100644 --- a/tools/build/feature/test-all.c +++ b/tools/build/feature/test-all.c @@ -138,10 +138,6 @@ # include "test-bpf.c" #undef main =20 -#define main main_test_libcrypto -# include "test-libcrypto.c" -#undef main - #define main main_test_sdt # include "test-sdt.c" #undef main @@ -206,7 +202,6 @@ int main(int argc, char *argv[]) main_test_lzma(); main_test_get_cpuid(); main_test_bpf(); - main_test_libcrypto(); main_test_scandirat(); main_test_sched_getcpu(); main_test_sdt(); diff --git a/tools/build/feature/test-libcrypto.c b/tools/build/feature/tes= t-libcrypto.c deleted file mode 100644 index bc34a5bbb504..000000000000 --- a/tools/build/feature/test-libcrypto.c +++ /dev/null @@ -1,25 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#include -#include -#include - -int main(void) -{ - EVP_MD_CTX *mdctx; - unsigned char md[MD5_DIGEST_LENGTH + SHA_DIGEST_LENGTH]; - unsigned char dat[] =3D "12345"; - unsigned int digest_len; - - mdctx =3D EVP_MD_CTX_new(); - if (!mdctx) - return 0; - - EVP_DigestInit_ex(mdctx, EVP_md5(), NULL); - EVP_DigestUpdate(mdctx, &dat[0], sizeof(dat)); - EVP_DigestFinal_ex(mdctx, &md[0], &digest_len); - EVP_MD_CTX_free(mdctx); - - SHA1(&dat[0], sizeof(dat), &md[0]); - - return 0; -} diff --git a/tools/perf/Documentation/perf-check.txt b/tools/perf/Documenta= tion/perf-check.txt index a764a4629220..2b96cb578658 100644 --- a/tools/perf/Documentation/perf-check.txt +++ b/tools/perf/Documentation/perf-check.txt @@ -53,7 +53,6 @@ feature:: auxtrace / HAVE_AUXTRACE_SUPPORT libbfd / HAVE_LIBBFD_SUPPORT libcapstone / HAVE_LIBCAPSTONE_SUPPORT - libcrypto / HAVE_LIBCRYPTO_SUPPORT libdw-dwarf-unwind / HAVE_LIBDW_SUPPORT libelf / HAVE_LIBELF_SUPPORT libnuma / HAVE_LIBNUMA_SUPPORT diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index d1ea7bf44964..d19d1f132726 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -130,8 +130,6 @@ ifndef NO_LIBUNWIND FEATURE_CHECK_LDFLAGS-libunwind-x86_64 +=3D -lunwind -llzma -lunwind-x86= _64 endif =20 -FEATURE_CHECK_LDFLAGS-libcrypto =3D -lcrypto - ifdef CSINCLUDES LIBOPENCSD_CFLAGS :=3D -I$(CSINCLUDES) endif @@ -772,17 +770,6 @@ ifneq ($(NO_LIBTRACEEVENT),1) $(call detected,CONFIG_TRACE) endif =20 -ifndef NO_LIBCRYPTO - ifneq ($(feature-libcrypto), 1) - $(warning No libcrypto.h found, disables jitted code injection, please= install openssl-devel or libssl-dev) - NO_LIBCRYPTO :=3D 1 - else - CFLAGS +=3D -DHAVE_LIBCRYPTO_SUPPORT - EXTLIBS +=3D -lcrypto - $(call detected,CONFIG_CRYPTO) - endif -endif - ifndef NO_SLANG ifneq ($(feature-libslang), 1) ifneq ($(feature-libslang-include-subdir), 1) diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index d4c7031b01a7..9246c94656e0 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -61,9 +61,6 @@ include ../scripts/utilities.mak # # Define NO_LIBBIONIC if you do not want bionic support # -# Define NO_LIBCRYPTO if you do not want libcrypto (openssl) support -# used for generating build-ids for ELFs generated by jitdump. -# # Define NO_LIBDW_DWARF_UNWIND if you do not want libdw support # for dwarf backtrace post unwind. # diff --git a/tools/perf/builtin-check.c b/tools/perf/builtin-check.c index 9a509cb3bb9a..ad49f2564aae 100644 --- a/tools/perf/builtin-check.c +++ b/tools/perf/builtin-check.c @@ -44,7 +44,6 @@ struct feature_status supported_features[] =3D { FEATURE_STATUS("auxtrace", HAVE_AUXTRACE_SUPPORT), FEATURE_STATUS_TIP("libbfd", HAVE_LIBBFD_SUPPORT, "Deprecated, license in= compatibility, use BUILD_NONDISTRO=3D1 and install binutils-dev[el]"), FEATURE_STATUS("libcapstone", HAVE_LIBCAPSTONE_SUPPORT), - FEATURE_STATUS("libcrypto", HAVE_LIBCRYPTO_SUPPORT), FEATURE_STATUS("libdw-dwarf-unwind", HAVE_LIBDW_SUPPORT), FEATURE_STATUS("libelf", HAVE_LIBELF_SUPPORT), FEATURE_STATUS("libnuma", HAVE_LIBNUMA_SUPPORT), diff --git a/tools/perf/tests/make b/tools/perf/tests/make index 0ee94caf9ec1..e3651e5b195a 100644 --- a/tools/perf/tests/make +++ b/tools/perf/tests/make @@ -91,7 +91,6 @@ make_no_auxtrace :=3D NO_AUXTRACE=3D1 make_no_libbpf :=3D NO_LIBBPF=3D1 make_libbpf_dynamic :=3D LIBBPF_DYNAMIC=3D1 make_no_libbpf_DEBUG :=3D NO_LIBBPF=3D1 DEBUG=3D1 -make_no_libcrypto :=3D NO_LIBCRYPTO=3D1 make_no_libllvm :=3D NO_LIBLLVM=3D1 make_with_babeltrace:=3D LIBBABELTRACE=3D1 make_with_coresight :=3D CORESIGHT=3D1 @@ -122,7 +121,7 @@ make_minimal :=3D NO_LIBPERL=3D1 NO_LIBPYTHON=3D= 1 NO_GTK2=3D1 make_minimal +=3D NO_DEMANGLE=3D1 NO_LIBELF=3D1 NO_BACKTRACE=3D1 make_minimal +=3D NO_LIBNUMA=3D1 NO_LIBBIONIC=3D1 make_minimal +=3D NO_LIBDW_DWARF_UNWIND=3D1 NO_AUXTRACE=3D1 NO_LIBB= PF=3D1 -make_minimal +=3D NO_LIBCRYPTO=3D1 NO_SDT=3D1 NO_JVMTI=3D1 NO_LIBZS= TD=3D1 +make_minimal +=3D NO_SDT=3D1 NO_JVMTI=3D1 NO_LIBZSTD=3D1 make_minimal +=3D NO_LIBCAP=3D1 NO_CAPSTONE=3D1 =20 # $(run) contains all available tests @@ -160,7 +159,6 @@ run +=3D make_no_libbionic run +=3D make_no_auxtrace run +=3D make_no_libbpf run +=3D make_no_libbpf_DEBUG -run +=3D make_no_libcrypto run +=3D make_no_libllvm run +=3D make_no_sdt run +=3D make_no_syscall_tbl --=20 2.49.0.1164.gab81da1b16-goog