From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Yuzhuo Jing <yuzhuo@google.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
Eric Biggers <ebiggers@google.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>,
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>,
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>,
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: Re: [PATCH v1 2/4] perf tools: Add sha1 utils
Date: Fri, 6 Jun 2025 17:17:35 -0300 [thread overview]
Message-ID: <aENM39y1XBf6ajKi@x1> (raw)
In-Reply-To: <CAP-5=fV11L=5cBaYcd0ftVyk8=Tm4+NWCoTG+MBnAwjEogS5iA@mail.gmail.com>
On Fri, Jun 06, 2025 at 11:27:28AM -0700, Ian Rogers wrote:
> On Wed, Jun 4, 2025 at 11:17 AM Yuzhuo Jing <yuzhuo@google.com> wrote:
> > Thanks for testing the patches!
You're welcome!
> > > In file included from util/sha1_generic.c:18:
> > > util/sha1_base.h: In function ‘sha1_base_do_finalize’:
> > > util/sha1_base.h:77:21: error: comparison of integer expressions of different signedness: ‘unsigned int’ and ‘int’ [-Werror=sign-compare]
> > > 77 | if (partial > bit_offset) {
> > > | ^
> > > cc1: all warnings being treated as errors
> >
> > Oh, I didn't see that on my GCC 14.2. A quick fix would work:
> >
> > --- /dev/fd/63 2025-06-04 09:54:42.344516115 -0700
> > +++ tools/perf/util/sha1_base.h 2025-06-03 15:43:39.194036707 -0700
> > @@ -71,7 +69,7 @@
> > static inline int sha1_base_do_finalize(struct sha1_state *sctx,
> > sha1_block_fn *block_fn)
> > {
> > - const int bit_offset = SHA1_BLOCK_SIZE - sizeof(__be64);
> > + const unsigned int bit_offset = SHA1_BLOCK_SIZE - sizeof(__be64);
> > __be64 *bits = (__be64 *)(sctx->buffer + bit_offset);
> > unsigned int partial = sctx->count % SHA1_BLOCK_SIZE;
> >
> >
> > To test it, I added -Werror=sign-compare to my local Makefile.config to
> > force the error.
> >
> > diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
> > index d19d1f132726..9909611be301 100644
> > --- a/tools/perf/Makefile.config
> > +++ b/tools/perf/Makefile.config
> > @@ -225,9 +225,9 @@ endif
> >
> > # Treat warnings as errors unless directed not to
> > ifneq ($(WERROR),0)
> > - CORE_CFLAGS += -Werror
> > - CXXFLAGS += -Werror
> > - HOSTCFLAGS += -Werror
> > + CORE_CFLAGS += -Werror=sign-compare -Werror
> > + CXXFLAGS += -Werror=sign-compare -Werror
> > + HOSTCFLAGS += -Werror=sign-compare -Werror
> > endif
> > ifndef DEBUG
> > While testing with "make -C tools/perf -f tests/make make_debug", I saw
> > similar compile errors in libjvmti.c:
> > jvmti/libjvmti.c: In function ‘copy_class_filename’:
> > jvmti/libjvmti.c:148:39: error: comparison of integer expressions of
> > different signedness: ‘int’ and ‘long unsigned int’
> > [-Werror=sign-compare]
> > 148 | for (i = 0; i < (size_t)(p - class_sign); i++)
> > | ^
> > jvmti/libjvmti.c:155:31: error: comparison of integer expressions of
> > different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’}
> > [-Werror=sign-compare]
> > 155 | for (j = 0; i < (max_length - 1) && file_name
> > && j < strlen(file_name); j++, i++)
> > | ^
> > jvmti/libjvmti.c:155:68: error: comparison of integer expressions of
> > different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’}
> > [-Werror=sign-compare]
> > 155 | for (j = 0; i < (max_length - 1) && file_name
> > && j < strlen(file_name); j++, i++)
> > | ^
> >
> > I've just sent a separate patch to the mailing list:
> > https://lore.kernel.org/lkml/20250604173632.2362759-1-yuzhuo@google.com/T/
> Thanks Yuzhuo! I guess this happened because jvmti.h is missing in the
> test container. It seems to make sense to add -Wsign-compare to the
> standard CFLAGS to lower the chance of breaking this container again.
> > > Humm that part is the same as in the kernel...
> > >
> > > ⬢ [acme@toolbx perf-tools-next]$ line=$(ctags -x --c-kinds=f include/crypto/sha1_base.h | awk '$1 == "sha1_base_do_finalize" {print $3}')
> > > ⬢ [acme@toolbx perf-tools-next]$ sed -n $line,\$p include/crypto/sha1_base.h | awk '{print} /\{/ {c++} /\}/ {c--; if (c==0) exit}' > /tmp/original
> > > ⬢ [acme@toolbx perf-tools-next]$ line=$(ctags -x --c-kinds=f tools/perf/util/sha1_base.h | awk '$1 == "sha1_base_do_finalize" {print $3}')
> > > ⬢ [acme@toolbx perf-tools-next]$ sed -n $line,\$p include/crypto/sha1_base.h | awk '{print} /\{/ {c++} /\}/ {c--; if (c==0) exit}' > /tmp/copy
> > > ⬢ [acme@toolbx perf-tools-next]$ diff -u /tmp/original /tmp/copy
> > > --- /tmp/original 2025-05-22 14:48:31.338406860 -0300
> > > +++ /tmp/copy 2025-05-22 14:48:58.401603439 -0300
> > > @@ -1,3 +1,7 @@
> > > +
> > > + return 0;
> > > +}
> > > +
> > > static inline int sha1_base_do_finalize(struct shash_desc *desc,
> > > sha1_block_fn *block_fn)
> > > {
> > > @@ -13,10 +17,3 @@
> > >
> > > block_fn(sctx, sctx->buffer, 1);
> > > }
> > > -
> > > - memset(sctx->buffer + partial, 0x0, bit_offset - partial);
> > > - *bits = cpu_to_be64(sctx->count << 3);
> > > - block_fn(sctx, sctx->buffer, 1);
> > > -
> > > - return 0;
> > > -}
> > > ⬢ [acme@toolbx perf-tools-next]$
> >
> > There were some other fixes that I made only to the perf tree version,
> > while maintaining verbatim for other parts. Here's a script that
> > retains and compares only the copied parts.
> >
> > # Ignore everything after sha1_transform
> > diff -u -B -I "^#include " <(sed -n
> > '/EXPORT_SYMBOL(sha1_transform)/q;p' lib/crypto/sha1.c)
> > tools/perf/util/sha1.c
> > diff -u -B -I "^#include " -I "sha1_zero_message_hash" -I "^struct
> > sha1_state;$" -I "^void sha1_init(__u32 \*buf);$" \
> > <(sed 's/shash_desc/sha1_state/g;' include/crypto/sha1.h)
> > tools/perf/util/sha1.h
> > diff -u -B -I "^EXPORT_SYMBOL" -I "^#include " \
> > <(sed 's/shash_desc \*desc/sha1_state *sctx/g;
> > /shash_desc_ctx(desc)/d' include/crypto/sha1_base.h)
> > tools/perf/util/sha1_base.h
> > # Ignore everything after crypto_sha1_finup
> > diff -u -B -I "^EXPORT_SYMBOL" -I "^#include " \
> > <(sed -n -e '/const u8
> > sha1_zero_message_hash/,/EXPORT_SYMBOL_GPL(sha1_zero_message_hash)/d'
> > \
> > -e 's/shash_desc/sha1_state/g;
> > /EXPORT_SYMBOL(crypto_sha1_finup)/q;p' crypto/sha1_generic.c) \
> > tools/perf/util/sha1_generic.c
> >
> > And the changes are as below (including the quick fix above), with one
> > changing the sign and integer type and another fixing type mismatch from
> > const u8 * to const char *.
> >
> > Should we send another patch to the kernel tree version to fix the sign
> > error, or we add rules to allow perf tree only changes?
>
> I believe there will need to be a set of patches for the kernel sha1
> code (fixing -Wsign-compare, any other typing issues) and a set of
> patches for perf with the check-headers.sh updated as your scripts
> check above.
Right, we try to reuse bits from the kernel as there are more people
working there and its a more critical piece of software than tooling
like perf, so when we notice something in the copies we carry, we better
fix it first in the origin.
> The perf patches shouldn't assume kernel patches have
> landed. The perf check-headers.sh produces a warning but doesn't stop
> the perf build. When the kernel changes land we can update the perf
> check-headers.sh expectations.
Right,
Thanks,
- Arnaldo
> Thanks,
> Ian
>
> > --- /dev/fd/63 2025-06-04 09:54:42.344516115 -0700
> > +++ tools/perf/util/sha1_base.h 2025-06-03 15:43:39.194036707 -0700
> > @@ -71,7 +69,7 @@
> > static inline int sha1_base_do_finalize(struct sha1_state *sctx,
> > sha1_block_fn *block_fn)
> > {
> > - const int bit_offset = SHA1_BLOCK_SIZE - sizeof(__be64);
> > + const unsigned int bit_offset = SHA1_BLOCK_SIZE - sizeof(__be64);
> > __be64 *bits = (__be64 *)(sctx->buffer + bit_offset);
> > unsigned int partial = sctx->count % SHA1_BLOCK_SIZE;
> >
> > @@ -95,7 +93,7 @@
> > __be32 *digest = (__be32 *)out;
> > int i;
> >
> > - for (i = 0; i < SHA1_DIGEST_SIZE / sizeof(__be32); i++)
> > + for (i = 0; i < SHA1_DIGEST_SIZE / (int)sizeof(__be32); i++)
> > put_unaligned_be32(sctx->state[i], digest++);
> >
> > memzero_explicit(sctx, sizeof(*sctx));
> > --- /dev/fd/63 2025-06-04 09:54:42.344516115 -0700
> > +++ tools/perf/util/sha1_generic.c 2025-05-16 10:52:59.219531034 -0700
> > @@ -27,7 +23,7 @@
> > u32 temp[SHA1_WORKSPACE_WORDS];
> >
> > while (blocks--) {
> > - sha1_transform(sst->state, src, temp);
> > + sha1_transform(sst->state, (const char *)src, temp);
> > src += SHA1_BLOCK_SIZE;
> > }
> > memzero_explicit(temp, sizeof(temp));
> >
> > Thanks!
> >
> > Best regards,
> > Yuzhuo
next prev parent reply other threads:[~2025-06-06 20:17 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 ` [PATCH v1 1/4] perf utils: Add support functions for sha1 utils Yuzhuo Jing
2025-05-21 22:53 ` [PATCH v1 2/4] perf tools: Add " 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 [this message]
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=aENM39y1XBf6ajKi@x1 \
--to=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=ebiggers@google.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 \
--cc=yuzhuo@google.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;
as well as URLs for NNTP newsgroup(s).