lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250401182347.3422199-32-irogers@google.com>
Date: Tue,  1 Apr 2025 11:23:29 -0700
From: Ian Rogers <irogers@...gle.com>
To: Yury Norov <yury.norov@...il.com>, Rasmus Villemoes <linux@...musvillemoes.dk>, 
	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>, 
	Kan Liang <kan.liang@...ux.intel.com>, Thomas Gleixner <tglx@...utronix.de>, 
	Darren Hart <dvhart@...radead.org>, Davidlohr Bueso <dave@...olabs.net>, 
	"André Almeida" <andrealmeid@...lia.com>, John Garry <john.g.garry@...cle.com>, 
	Will Deacon <will@...nel.org>, James Clark <james.clark@...aro.org>, 
	Mike Leach <mike.leach@...aro.org>, Leo Yan <leo.yan@...ux.dev>, 
	Yicong Yang <yangyicong@...ilicon.com>, Jonathan Cameron <jonathan.cameron@...wei.com>, 
	Nathan Chancellor <nathan@...nel.org>, Bill Wendling <morbo@...gle.com>, 
	Justin Stitt <justinstitt@...gle.com>, Josh Poimboeuf <jpoimboe@...nel.org>, 
	Al Viro <viro@...iv.linux.org.uk>, Kyle Meyer <kyle.meyer@....com>, 
	Ben Gainey <ben.gainey@....com>, Athira Rajeev <atrajeev@...ux.vnet.ibm.com>, 
	Kajol Jain <kjain@...ux.ibm.com>, Aditya Gupta <adityag@...ux.ibm.com>, 
	Eder Zulian <ezulian@...hat.com>, Dapeng Mi <dapeng1.mi@...ux.intel.com>, 
	Kuan-Wei Chiu <visitorckw@...il.com>, He Zhe <zhe.he@...driver.com>, 
	Dirk Gouders <dirk@...ders.net>, Brian Geffon <bgeffon@...gle.com>, 
	Ravi Bangoria <ravi.bangoria@....com>, Howard Chu <howardchu95@...il.com>, 
	Charlie Jenkins <charlie@...osinc.com>, Colin Ian King <colin.i.king@...il.com>, 
	Dominique Martinet <asmadeus@...ewreck.org>, Jann Horn <jannh@...gle.com>, 
	Masahiro Yamada <masahiroy@...nel.org>, Arnd Bergmann <arnd@...db.de>, 
	Yang Jihong <yangjihong@...edance.com>, Dmitry Vyukov <dvyukov@...gle.com>, 
	Andi Kleen <ak@...ux.intel.com>, Graham Woodward <graham.woodward@....com>, 
	Ilkka Koskinen <ilkka@...amperecomputing.com>, 
	Anshuman Khandual <anshuman.khandual@....com>, Zhongqiu Han <quic_zhonhan@...cinc.com>, 
	Hao Ge <gehao@...inos.cn>, Tengda Wu <wutengda@...weicloud.com>, 
	Gabriele Monaco <gmonaco@...hat.com>, Chun-Tse Shao <ctshao@...gle.com>, 
	Casey Chen <cachen@...estorage.com>, "Dr. David Alan Gilbert" <linux@...blig.org>, 
	Li Huafei <lihuafei1@...wei.com>, "Steinar H. Gunderson" <sesse@...gle.com>, Levi Yun <yeoreum.yun@....com>, 
	Weilin Wang <weilin.wang@...el.com>, Thomas Falcon <thomas.falcon@...el.com>, 
	Thomas Richter <tmricht@...ux.ibm.com>, Andrew Kreimer <algonell@...il.com>, 
	"Krzysztof Łopatowski" <krzysztof.m.lopatowski@...il.com>, 
	Christophe Leroy <christophe.leroy@...roup.eu>, 
	Jean-Philippe Romain <jean-philippe.romain@...s.st.com>, Junhao He <hejunhao3@...wei.com>, 
	"Masami Hiramatsu (Google)" <mhiramat@...nel.org>, Xu Yang <xu.yang_2@....com>, 
	Steve Clevenger <scclevenger@...amperecomputing.com>, Zixian Cai <fzczx123@...il.com>, 
	Stephen Brennan <stephen.s.brennan@...cle.com>, Yujie Liu <yujie.liu@...el.com>, 
	linux-kernel@...r.kernel.org, linux-perf-users@...r.kernel.org, 
	linux-arm-kernel@...ts.infradead.org, llvm@...ts.linux.dev
Subject: [PATCH v1 31/48] perf mem: Silence -Wshorten-64-to-32 warnings

The clang warning -Wshorten-64-to-32 can be useful to catch
inadvertent truncation. In some instances this truncation can lead to
changing the sign of a result, for example, truncation to return an
int to fit a sort routine. Silence the warning by making the implicit
truncation explicit.

Signed-off-by: Ian Rogers <irogers@...gle.com>
---
 tools/perf/builtin-c2c.c     | 21 ++++++++++---------
 tools/perf/builtin-kmem.c    | 39 ++++++++++++++++++------------------
 tools/perf/builtin-mem.c     |  2 +-
 tools/perf/util/mem-events.c | 12 +++++------
 tools/perf/util/mem2node.c   |  2 +-
 5 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 5d5bb0f32334..ac456ddb2f3d 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -1206,7 +1206,7 @@ node_entry(struct perf_hpp_fmt *fmt __maybe_unused, struct perf_hpp *hpp,
 			break;
 		case 1:
 		{
-			int num = bitmap_weight(set, c2c.cpus_cnt);
+			int num = (int)bitmap_weight(set, c2c.cpus_cnt);
 			struct c2c_stats *stats = &c2c_he->node_stats[node];
 
 			ret = scnprintf(hpp->buf, hpp->size, "%2d{%2d ", node, num);
@@ -1249,7 +1249,7 @@ node_entry(struct perf_hpp_fmt *fmt __maybe_unused, struct perf_hpp *hpp,
 			ret = scnprintf(hpp->buf, hpp->size, "%2d{", node);
 			advance_hpp(hpp, ret);
 
-			ret = bitmap_scnprintf(set, c2c.cpus_cnt, hpp->buf, hpp->size);
+			ret = (int)bitmap_scnprintf(set, c2c.cpus_cnt, hpp->buf, hpp->size);
 			advance_hpp(hpp, ret);
 
 			ret = scnprintf(hpp->buf, hpp->size, "}");
@@ -1911,7 +1911,7 @@ static int c2c_se_entry(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,
 			len = symbol_width(he->hists, dim->se);
 	}
 
-	return dim->se->se_snprintf(he, hpp->buf, hpp->size, len);
+	return dim->se->se_snprintf(he, hpp->buf, hpp->size, (unsigned int)len);
 }
 
 static int64_t c2c_se_cmp(struct perf_hpp_fmt *fmt,
@@ -2163,7 +2163,7 @@ static void set_node_width(struct c2c_hist_entry *c2c_he, int len)
 static int set_nodestr(struct c2c_hist_entry *c2c_he)
 {
 	char buf[30];
-	int len;
+	size_t len;
 
 	if (c2c_he->nodestr)
 		return 0;
@@ -2175,7 +2175,7 @@ static int set_nodestr(struct c2c_hist_entry *c2c_he)
 		len = scnprintf(buf, sizeof(buf), "N/A");
 	}
 
-	set_node_width(c2c_he, len);
+	set_node_width(c2c_he, (int)len);
 	c2c_he->nodestr = strdup(buf);
 	return c2c_he->nodestr ? 0 : -ENOMEM;
 }
@@ -2352,7 +2352,7 @@ static int hists__iterate_cb(struct hists *hists, hists__resort_cb_t cb)
 
 static void print_c2c__display_stats(FILE *out)
 {
-	int llc_misses;
+	uint64_t llc_misses;
 	struct c2c_stats *stats = &c2c.hists.stats;
 
 	llc_misses = get_load_llc_misses(stats);
@@ -2378,7 +2378,7 @@ static void print_c2c__display_stats(FILE *out)
 	fprintf(out, "  Load Remote DRAM                  : %10d\n", stats->rmt_dram);
 	fprintf(out, "  Load MESI State Exclusive         : %10d\n", stats->ld_excl);
 	fprintf(out, "  Load MESI State Shared            : %10d\n", stats->ld_shared);
-	fprintf(out, "  Load LLC Misses                   : %10d\n", llc_misses);
+	fprintf(out, "  Load LLC Misses                   : %10"PRIu64"\n", llc_misses);
 	fprintf(out, "  Load access blocked by data       : %10d\n", stats->blk_data);
 	fprintf(out, "  Load access blocked by address    : %10d\n", stats->blk_addr);
 	fprintf(out, "  Load HIT Local Peer               : %10d\n", stats->lcl_peer);
@@ -2737,9 +2737,10 @@ static void perf_c2c_display(struct perf_session *session)
 }
 #endif /* HAVE_SLANG_SUPPORT */
 
-static char *fill_line(const char *orig, int len)
+static char *fill_line(const char *orig, size_t len)
 {
-	int i, j, olen = strlen(orig);
+	size_t i, j;
+	size_t olen = strlen(orig);
 	char *buf;
 
 	buf = zalloc(len + 1);
@@ -3067,7 +3068,7 @@ static int perf_c2c__report(int argc, const char **argv)
 	c2c.tool.ordering_requires_timestamps = true;
 	session = perf_session__new(&data, &c2c.tool);
 	if (IS_ERR(session)) {
-		err = PTR_ERR(session);
+		err = (int)PTR_ERR(session);
 		pr_debug("Error creating perf session\n");
 		goto out;
 	}
diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index 67fb1946ef13..6a905161f21b 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -173,10 +173,10 @@ static int insert_caller_stat(unsigned long call_site,
 
 static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *sample)
 {
-	unsigned long ptr = evsel__intval(evsel, sample, "ptr"),
-		      call_site = evsel__intval(evsel, sample, "call_site");
-	int bytes_req = evsel__intval(evsel, sample, "bytes_req"),
-	    bytes_alloc = evsel__intval(evsel, sample, "bytes_alloc");
+	unsigned long ptr = evsel__intval(evsel, sample, "ptr");
+	unsigned long call_site = evsel__intval(evsel, sample, "call_site");
+	int bytes_req = (int)evsel__intval(evsel, sample, "bytes_req");
+	int bytes_alloc = (int)evsel__intval(evsel, sample, "bytes_alloc");
 
 	if (insert_alloc_stat(call_site, ptr, bytes_req, bytes_alloc, sample->cpu) ||
 	    insert_caller_stat(call_site, bytes_req, bytes_alloc))
@@ -202,7 +202,7 @@ static int evsel__process_alloc_event(struct evsel *evsel, struct perf_sample *s
 		int node1, node2;
 
 		node1 = cpu__get_node((struct perf_cpu){.cpu = sample->cpu});
-		node2 = evsel__intval(evsel, sample, "node");
+		node2 = (int)evsel__intval(evsel, sample, "node");
 
 		/*
 		 * If the field "node" is NUMA_NO_NODE (-1), we don't take it
@@ -737,7 +737,7 @@ static char *compact_gfp_flags(char *gfp_flags)
 	return new_flags;
 }
 
-static char *compact_gfp_string(unsigned long gfp_flags)
+static char *compact_gfp_string(unsigned int gfp_flags)
 {
 	struct gfp_flag key = {
 		.flags = gfp_flags,
@@ -808,10 +808,9 @@ static int parse_gfp_flags(struct evsel *evsel, struct perf_sample *sample,
 static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_sample *sample)
 {
 	u64 page;
-	unsigned int order = evsel__intval(evsel, sample, "order");
-	unsigned int gfp_flags = evsel__intval(evsel, sample, "gfp_flags");
-	unsigned int migrate_type = evsel__intval(evsel, sample,
-						       "migratetype");
+	unsigned int order = (unsigned int)evsel__intval(evsel, sample, "order");
+	unsigned int gfp_flags = (unsigned int)evsel__intval(evsel, sample, "gfp_flags");
+	unsigned int migrate_type = (unsigned int)evsel__intval(evsel, sample, "migratetype");
 	u64 bytes = kmem_page_size << order;
 	u64 callsite;
 	struct page_stat *pstat;
@@ -880,7 +879,7 @@ static int evsel__process_page_alloc_event(struct evsel *evsel, struct perf_samp
 static int evsel__process_page_free_event(struct evsel *evsel, struct perf_sample *sample)
 {
 	u64 page;
-	unsigned int order = evsel__intval(evsel, sample, "order");
+	unsigned int order = (unsigned int)evsel__intval(evsel, sample, "order");
 	u64 bytes = kmem_page_size << order;
 	struct page_stat *pstat;
 	struct page_stat this = {
@@ -1064,12 +1063,12 @@ static void __print_page_alloc_result(struct perf_session *session, int n_lines)
 	struct rb_node *next = rb_first(&page_alloc_sorted);
 	struct machine *machine = &session->machines.host;
 	const char *format;
-	int gfp_len = max(strlen("GFP flags"), max_gfp_len);
+	size_t gfp_len = max(strlen("GFP flags"), max_gfp_len);
 
 	printf("\n%.105s\n", graph_dotted_line);
 	printf(" %-16s | %5s alloc (KB) | Hits      | Order | Mig.type | %-*s | Callsite\n",
 	       use_pfn ? "PFN" : "Page", live_page ? "Live" : "Total",
-	       gfp_len, "GFP flags");
+		(int)gfp_len, "GFP flags");
 	printf("%.105s\n", graph_dotted_line);
 
 	if (use_pfn)
@@ -1102,7 +1101,7 @@ static void __print_page_alloc_result(struct perf_session *session, int n_lines)
 
 	if (n_lines == -1) {
 		printf(" ...              | ...              | ...       | ...   | ...      | %-*s | ...\n",
-		       gfp_len, "...");
+		       (int)gfp_len, "...");
 	}
 
 	printf("%.105s\n", graph_dotted_line);
@@ -1112,11 +1111,11 @@ static void __print_page_caller_result(struct perf_session *session, int n_lines
 {
 	struct rb_node *next = rb_first(&page_caller_sorted);
 	struct machine *machine = &session->machines.host;
-	int gfp_len = max(strlen("GFP flags"), max_gfp_len);
+	size_t gfp_len = max(strlen("GFP flags"), max_gfp_len);
 
 	printf("\n%.105s\n", graph_dotted_line);
 	printf(" %5s alloc (KB) | Hits      | Order | Mig.type | %-*s | Callsite\n",
-	       live_page ? "Live" : "Total", gfp_len, "GFP flags");
+	       live_page ? "Live" : "Total", (int)gfp_len, "GFP flags");
 	printf("%.105s\n", graph_dotted_line);
 
 	while (next && n_lines--) {
@@ -1137,14 +1136,14 @@ static void __print_page_caller_result(struct perf_session *session, int n_lines
 		       (unsigned long long)data->alloc_bytes / 1024,
 		       data->nr_alloc, data->order,
 		       migrate_type_str[data->migrate_type],
-		       gfp_len, compact_gfp_string(data->gfp_flags), caller);
+		       (int)gfp_len, compact_gfp_string(data->gfp_flags), caller);
 
 		next = rb_next(next);
 	}
 
 	if (n_lines == -1) {
 		printf(" ...              | ...       | ...   | ...      | %-*s | ...\n",
-		       gfp_len, "...");
+		       (int)gfp_len, "...");
 	}
 
 	printf("%.105s\n", graph_dotted_line);
@@ -1828,7 +1827,7 @@ static int parse_line_opt(const struct option *opt __maybe_unused,
 	if (!arg)
 		return -1;
 
-	lines = strtoul(arg, NULL, 10);
+	lines = (int)strtoul(arg, NULL, 10);
 
 	if (caller_flag > alloc_flag)
 		caller_lines = lines;
@@ -2001,7 +2000,7 @@ int cmd_kmem(int argc, const char **argv)
 
 	kmem_session = session = perf_session__new(&data, &perf_kmem);
 	if (IS_ERR(session))
-		return PTR_ERR(session);
+		return (int)PTR_ERR(session);
 
 	ret = -1;
 
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index 5ec83cd85650..988b3877cde8 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -293,7 +293,7 @@ static int report_raw_events(struct perf_mem *mem)
 	session = perf_session__new(&data, &mem->tool);
 
 	if (IS_ERR(session))
-		return PTR_ERR(session);
+		return (int)PTR_ERR(session);
 
 	session->itrace_synth_opts = &itrace_synth_opts;
 
diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c
index 884d9aebce91..6ad99ace56e3 100644
--- a/tools/perf/util/mem-events.c
+++ b/tools/perf/util/mem-events.c
@@ -364,7 +364,7 @@ int perf_mem__tlb_scnprintf(char *out, size_t sz, const struct mem_info *mem_inf
 	if (miss)
 		l += scnprintf(out + l, sz - l, " miss");
 
-	return l;
+	return (int)l;
 }
 
 static const char * const mem_lvl[] = {
@@ -476,7 +476,7 @@ int perf_mem__lvl_scnprintf(char *out, size_t sz, const struct mem_info *mem_inf
 			l += scnprintf(out + l, sz - l, "Unknown level %d", lvl);
 
 		l += scnprintf(out + l, sz - l, " %s", hit_miss);
-		return l;
+		return (int)l;
 	}
 
 	lvl = data_src.mem_lvl;
@@ -499,7 +499,7 @@ int perf_mem__lvl_scnprintf(char *out, size_t sz, const struct mem_info *mem_inf
 
 	if (printed) {
 		l += scnprintf(out + l, sz - l, " %s", hit_miss);
-		return l;
+		return (int)l;
 	}
 
 na:
@@ -559,7 +559,7 @@ int perf_mem__snp_scnprintf(char *out, size_t sz, const struct mem_info *mem_inf
 	if (*out == '\0')
 		l += scnprintf(out, sz - l, "N/A");
 
-	return l;
+	return (int)l;
 }
 
 int perf_mem__lck_scnprintf(char *out, size_t sz, const struct mem_info *mem_info)
@@ -593,14 +593,14 @@ int perf_mem__blk_scnprintf(char *out, size_t sz, const struct mem_info *mem_inf
 
 	if (!mask || (mask & PERF_MEM_BLK_NA)) {
 		l += scnprintf(out + l, sz - l, " N/A");
-		return l;
+		return (int)l;
 	}
 	if (mask & PERF_MEM_BLK_DATA)
 		l += scnprintf(out + l, sz - l, " Data");
 	if (mask & PERF_MEM_BLK_ADDR)
 		l += scnprintf(out + l, sz - l, " Addr");
 
-	return l;
+	return (int)l;
 }
 
 int perf_script__meminfo_scnprintf(char *out, size_t sz, const struct mem_info *mem_info)
diff --git a/tools/perf/util/mem2node.c b/tools/perf/util/mem2node.c
index 03a7d7b27737..2d76626dec01 100644
--- a/tools/perf/util/mem2node.c
+++ b/tools/perf/util/mem2node.c
@@ -56,7 +56,7 @@ int mem2node__init(struct mem2node *map, struct perf_env *env)
 
 	for (i = 0; i < env->nr_memory_nodes; i++) {
 		n = &nodes[i];
-		max += bitmap_weight(n->set, n->size);
+		max += bitmap_weight(n->set, (unsigned int)n->size);
 	}
 
 	entries = zalloc(sizeof(*entries) * max);
-- 
2.49.0.504.g3bcea36a83-goog


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ