Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp1495940pxb; Fri, 10 Sep 2021 07:14:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw86hr6uNgUZKb7bjrui+boXKH7yQwUSd17uv/lZ6QUbwPMpnXL0N+mA+ltl/giD+bMzNCl X-Received: by 2002:a17:906:6148:: with SMTP id p8mr9591165ejl.17.1631283284493; Fri, 10 Sep 2021 07:14:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631283284; cv=none; d=google.com; s=arc-20160816; b=M17heo6g2EwJfeYSeRerfz5+yNJS12TyKADEP/KZnBVxcRvCPl6AKZg+d572tAABm0 Gc0Vhn0nkmnF0++GSo9YTbO3MLAUNsao5alhdeeJJCIglZrFyA8Xv+gQXfGLoKDPDZNc HFVDqpJPOLglZsh3jC722NtPSTqdndQSIJAPtAPE4kuIg39kN5+unDNwLJKzwzpk/H7n D/il4r4hjPeMvIVK2JQahs/X6DcFIX3fG2AbodTgwOhfCj1n4sNYfHwsyhl/+UD8Q2Dp nlKQ49loXihZlIRllRKG/yOLezNvXRf9E5dhJMFUt3ECAvBYfXHC+jU6zgyDc464HhHu Jijw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=aVXF8d14zIFpF+uJtyZqjNLKEOlcbb/EECJsjrpqwAM=; b=xG6gSwHSaHSA+mBKTNevcpK1jxvjE+q0xu9ku7O9iHRB+wLpgwJOgW0rlusHQExXuF XWLOtMCPx0ZAXOOhofUaEZP1mdgpKMnGz7WnMBfDDvjZWinQfNbThILnjNb7BP6OMDjv IgN9/TTSK+tvnbPPLC8G+Jly37VgNfwoQq0sxgpVm/2j4kiLW089NpIAtREWR1voBDeg hTJbbzuJqOyAR2QdZi7n25yvvOCe82+ILRJ1sNFojuaMLK+45rQhseJO1911pU0EcK/i GYcVOpqUjkzxZULNOIxwgPXHnM5YHB+hzL2qtPiYlp1HLhTpOJ97gZKWVuCYFDJWIr8i TrcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=C+HZ4bH9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n6si5758600edi.48.2021.09.10.07.14.19; Fri, 10 Sep 2021 07:14:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=C+HZ4bH9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233920AbhIJOND (ORCPT + 99 others); Fri, 10 Sep 2021 10:13:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:60424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233928AbhIJOND (ORCPT ); Fri, 10 Sep 2021 10:13:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CBAFA611BF; Fri, 10 Sep 2021 14:11:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631283112; bh=ejUip3itZwLtheb3TXxocHtkN/0auCx2Nyksa+ii378=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=C+HZ4bH9qWVLiTV8Fh+ic8F170bofDkPzKdAi+/lR+PkiYjXf6/Z45UjJSMNDrB92 kYTFgaeU88+xie+OtpBFt7q7+KgSf8msQU1LwSBty1l285Lh/26UvUsxxTAt3JP0LH 4xXxqW3iFB1MaI+MSwRwnQUTS1o+ukcVPEg+PjKaUCOdXKtagxEI8KXb1z6UZCpyFn x6zeFBD2Z2/nUDYMD7YKkALCSY1T3p+MKJPV49Qwag4ZzLWEU3mDfZzfgTKlybMRzx V7UkKaXrqxysbmGMZHkC5VgnItAEYFLHyQAkm8kQ54HSLlUbJuGHvksZqYP46npPm6 l2faXe7RWYM3A== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id E28E84038F; Fri, 10 Sep 2021 11:11:48 -0300 (-03) Date: Fri, 10 Sep 2021 11:11:48 -0300 From: Arnaldo Carvalho de Melo To: Kim Phillips Cc: Arnaldo Carvalho de Melo , Alexander Shishkin , Boris Ostrovsky , Ian Rogers , Ingo Molnar , Jiri Olsa , Joao Martins , Konrad Rzeszutek Wilk , Mark Rutland , Michael Petlan , Namhyung Kim , Peter Zijlstra , Robert Richter , Stephane Eranian , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Subject: Re: [PATCH 0/3] perf report: Add support to print a textual representation of IBS raw sample data Message-ID: References: <20210817221509.88391-1-kim.phillips@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Fri, Sep 10, 2021 at 11:08:02AM -0300, Arnaldo Carvalho de Melo escreveu: > Em Fri, Sep 10, 2021 at 10:47:16AM -0300, Arnaldo Carvalho de Melo escreveu: > > Em Thu, Sep 09, 2021 at 04:58:12PM -0500, Kim Phillips escreveu: > > > Hi Arnaldo, > > > > > > Can you please take a look at applying this series? Its kernel-side > > > dependent series has already been applied and is in Linus' master. > > > > Sure, I'm now trying to fix this: > > > > CC /tmp/build/perf/util/amd-sample-raw.o > > util/amd-sample-raw.c: In function ‘evlist__amd_sample_raw’: > > util/amd-sample-raw.c:125:42: error: ‘ bytes’ directive output may be truncated writing 6 bytes into a region of size between 4 and 7 [-Werror=format-truncation=] > > 125 | " OpMemWidth %2d bytes", 1 << (reg.op_mem_width - 1)); > > | ^~~~~~ > > In file included from /usr/include/stdio.h:866, > > from util/amd-sample-raw.c:7: > > /usr/include/bits/stdio2.h:71:10: note: ‘__builtin___snprintf_chk’ output between 21 and 24 bytes into a destination of size 21 > > 71 | return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1, > > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > 72 | __glibc_objsize (__s), __fmt, > > | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > > 73 | __va_arg_pack ()); > > | ~~~~~~~~~~~~~~~~~ > > cc1: all warnings being treated as errors > > make[4]: *** [/var/home/acme/git/perf/tools/build/Makefile.build:96: /tmp/build/perf/util/amd-sample-raw.o] Error 1 > > So, that trick with using sizeof and that string 3 times is cumbersome > and prone to truncation, at least the compiler can't say that the number > you're passing to %2d will have just 2 digits: > > [acme@quaco c]$ cat printf.c > #include > #include > > int main(int argc, char *argv[]) > { > char bf[64]; > int len = snprintf(bf, sizeof(bf), "%2d", atoi(argv[1])); > > printf("strlen(%s): %u\n", bf, len); > > return 0; > } > [acme@quaco c]$ ./printf 1234567 > strlen(1234567): 7 > [acme@quaco c]$ > > I'm trying to rework this. So below is the minimal fix, the other cases the compiler somehow thinks its ok, so I'll keep as is, will just remove the sizeof(string) to sizeof(var), as I did below for the offending case. - Arnaldo diff --git a/tools/perf/util/amd-sample-raw.c b/tools/perf/util/amd-sample-raw.c index fc1f670e88562b2e..e24025022735acdc 100644 --- a/tools/perf/util/amd-sample-raw.c +++ b/tools/perf/util/amd-sample-raw.c @@ -106,7 +106,7 @@ static void pr_ibs_op_data2(union ibs_op_data2 reg) static void pr_ibs_op_data3(union ibs_op_data3 reg) { char l2_miss_str[sizeof(" L2Miss _")] = ""; - char op_mem_width_str[sizeof(" OpMemWidth __ bytes")] = ""; + char op_mem_width_str[sizeof(" OpMemWidth _____ bytes")] = ""; char op_dc_miss_open_mem_reqs_str[sizeof(" OpDcMissOpenMemReqs __")] = ""; /* @@ -121,7 +121,7 @@ static void pr_ibs_op_data3(union ibs_op_data3 reg) } if (reg.op_mem_width) - snprintf(op_mem_width_str, sizeof(" OpMemWidth __ bytes"), + snprintf(op_mem_width_str, sizeof(op_mem_width_str), " OpMemWidth %2d bytes", 1 << (reg.op_mem_width - 1)); printf("ibs_op_data3:\t%016llx LdOp %d StOp %d DcL1TlbMiss %d DcL2TlbMiss %d "