Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2948768rdb; Wed, 4 Oct 2023 17:31:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFenHtV5UYwZessTok4jRJU5xlj6/y48vNCk+vvjDKInyo70HTlJHjlxhsxDBrtlByKdWSh X-Received: by 2002:a05:6e02:1c46:b0:351:57d5:51c4 with SMTP id d6-20020a056e021c4600b0035157d551c4mr4540198ilg.1.1696465862390; Wed, 04 Oct 2023 17:31:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696465862; cv=none; d=google.com; s=arc-20160816; b=GqamknqpPnWKp3AqY2udywxchVMbJyJMp8oQfLyjVBsASH+1jz4P9qwbKTLKtBaiyc vM5ZanRwEYrVTH+8bP3HtByQF6BTo3IyijQ+4HUEG5NqBJtqLWQfOkR85BF4LRJe6zzB csPzw/LzYfH6NsSw1PjAlXEgAqOC0O+McOsIWqRnYyOdAhc+tTaXXEcXtHCGpBwTnukQ DL7jH2ktivL2mKeWHt8hq7XSHvphfzG2Og1sUNIz+lb3gHxf9o1p30/SKmuqDx3NuNeO pvoLJEbyuue25PjgBAXYtXX9Wp/ZnCfhgLMOs9FMiT71o2887EUZVehR4DrueaqBkl1C 0+jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:from:subject :message-id:mime-version:date:reply-to:dkim-signature; bh=HP82+f2LW6og6nQMkdcaVuem0dmBP2uW2zMzUlSKFRQ=; fh=JYzqeNcM24uPHvgkJsGIwps1D2P1MHRVSTJA6e2ZGSY=; b=UeCU0o9fcUG8qRA70CjhX7ol76mF7Vaz73bDRFOy7+ujxjv0Qjy6mnxulFQRjXY3p6 ypApWR1mfWNSkYumV4anJc/4E3uPM1Colm9mQSoS8zFqO3BKongiyRIqsxdn8x8ncDRM 5fIMJwEUX18JB9pmUXrA4dJD+wciJlO4D8lAEEvciz863LV65qqDJa4HOZ4ielJqFoNA ENMUPxH9o0YbbIl+EQZhxns4m/GtOIi2qsIQjmRV74/1J7CI1mx+CaBvRSGQA5zc4OII Hz7F+9huKatGgqwOnUSYPq89Wf1kPvS+goXGOVYYgz0uiOL4h54OWVt98QXuNtDIjrJn 3Naw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=imJGrfrS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id e5-20020a637445000000b00573faa3bb3csi281232pgn.307.2023.10.04.17.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 17:31:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=imJGrfrS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 563A980B9511; Wed, 4 Oct 2023 17:30:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244022AbjJEAaC (ORCPT + 99 others); Wed, 4 Oct 2023 20:30:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233742AbjJEAaB (ORCPT ); Wed, 4 Oct 2023 20:30:01 -0400 Received: from mail-pj1-x104a.google.com (mail-pj1-x104a.google.com [IPv6:2607:f8b0:4864:20::104a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 184E7AD for ; Wed, 4 Oct 2023 17:29:58 -0700 (PDT) Received: by mail-pj1-x104a.google.com with SMTP id 98e67ed59e1d1-27731a63481so329154a91.2 for ; Wed, 04 Oct 2023 17:29:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696465797; x=1697070597; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:reply-to:from:to:cc:subject:date:message-id :reply-to; bh=HP82+f2LW6og6nQMkdcaVuem0dmBP2uW2zMzUlSKFRQ=; b=imJGrfrSMe5fW+gOt1/z+NlKJkfFdy4a4Uv4N0mbip6T87AseqQvFkdczhffRQhpEE TovjWNNhqucSugBbWcy9AogsMuQU83AKeb/gjOx6B7e7Orf945vIFmbA57tg1PldAU4Q QDSK7LPE/03UWAoC7zrg1qJsc2ENn6Ic2XwFt+kdylVn/zav8WQ8xtSErlpqTXGeYYHN Ut43HbhWyVSj33O45g22UqiUrOKecoQ898kNC2Uu5+fRf1iGmx9VEJFSaUHZ6OvJuvDf 9ZxQfjPpB9P/1xayzE9072dJD+1oFktH2ApSLz9w1cD6SwKiK+iFVn8kA4YCIj8wajPN 5hCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696465797; x=1697070597; h=content-transfer-encoding:cc:to:from:subject:message-id :mime-version:date:reply-to:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=HP82+f2LW6og6nQMkdcaVuem0dmBP2uW2zMzUlSKFRQ=; b=eFqSdhvyktnlKNx2mP4UMHO0C0jJjuUQCAXvwjCpXzYZha6D3WT5T9s7VUN46YOr72 WiWr4Z6JV6CBj+M+gmcsqauJy691CCYvwLwfPoL5obcluOk50eWEm94YePPeY1z1OYzm nORiDuRS5vxD0on4DJRIof19T9V8jTGnlWJGpeDsrfdOK80qYzE4lXrUO397ushG9gHC CFysM1fXuIDCV5iPgoiSxD3EFXlnUgbny1r+0pSmTwowQWbpm/7Sev6BR9o6rfQepJVo gAvz92AHDIH5QCe8Vhx9lPhWAOE+wGwWwng+ldr7gk02vcO8AeBzfrPKI4KUVZEfHkpv tgeA== X-Gm-Message-State: AOJu0YzmUu909Sucx6dzkSUBXawBJjGimMR2EsKpYi7p46o6xejMrKsI S5loZiKvqmnmQi0lewq970uuUPyQZB4= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90a:a393:b0:274:90a4:f29 with SMTP id x19-20020a17090aa39300b0027490a40f29mr61931pjp.1.1696465797603; Wed, 04 Oct 2023 17:29:57 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 4 Oct 2023 17:29:54 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog Message-ID: <20231005002954.2887098-1-seanjc@google.com> Subject: [PATCH] KVM: selftests: Zero-initialize entire test_result in memslot perf test From: Sean Christopherson To: Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Maciej S . Szmigiero" , Sean Christopherson Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 04 Oct 2023 17:30:30 -0700 (PDT) Zero-initialize the entire test_result structure used by memslot_perf_test instead of zeroing only the fields used to guard the pr_info() calls. gcc 13.2.0 is a bit overzealous and incorrectly thinks that rbestslottim's slot_runtime may be used uninitialized. In file included from memslot_perf_test.c:25: memslot_perf_test.c: In function =E2=80=98main=E2=80=99: include/test_util.h:31:22: error: =E2=80=98rbestslottime.slot_runtime.tv_= nsec=E2=80=99 may be used uninitialized [-Werror=3Dmaybe-uninitialized] 31 | #define pr_info(...) printf(__VA_ARGS__) | ^~~~~~~~~~~~~~~~~~~ memslot_perf_test.c:1127:17: note: in expansion of macro =E2=80=98pr_info= =E2=80=99 1127 | pr_info("Best slot setup time for the whole test = area was %ld.%.9lds\n", | ^~~~~~~ memslot_perf_test.c:1092:28: note: =E2=80=98rbestslottime.slot_runtime.tv= _nsec=E2=80=99 was declared here 1092 | struct test_result rbestslottime; | ^~~~~~~~~~~~~ include/test_util.h:31:22: error: =E2=80=98rbestslottime.slot_runtime.tv_= sec=E2=80=99 may be used uninitialized [-Werror=3Dmaybe-uninitialized] 31 | #define pr_info(...) printf(__VA_ARGS__) | ^~~~~~~~~~~~~~~~~~~ memslot_perf_test.c:1127:17: note: in expansion of macro =E2=80=98pr_info= =E2=80=99 1127 | pr_info("Best slot setup time for the whole test = area was %ld.%.9lds\n", | ^~~~~~~ memslot_perf_test.c:1092:28: note: =E2=80=98rbestslottime.slot_runtime.tv= _sec=E2=80=99 was declared here 1092 | struct test_result rbestslottime; | ^~~~~~~~~~~~~ That can't actually happen, at least not without the "result" structure in test_loop() also being used uninitialized, which gcc doesn't complain about, as writes to rbestslottime are all-or-nothing, i.e. slottimens can't be non-zero without slot_runtime being written. if (!data->mem_size && (!rbestslottime->slottimens || result.slottimens < rbestslottime->slottimens)) *rbestslottime =3D result; Zero-initialize the structures to make gcc happy even though this is likely a compiler bug. The cost to do so is negligible, both in terms of code and runtime overhead. The only downside is that the compiler won't warn about legitimate usage of "uninitialized" data, e.g. the test could end up consuming zeros instead of useful data. However, given that the test is quite mature and unlikely to see substantial changes, the odds of introducing such bugs are relatively low, whereas being able to compile KVM selftests with -Werror detects issues on a regular basis. Cc: Maciej S. Szmigiero Signed-off-by: Sean Christopherson --- I don't like papering over compiler bugs, but this is causing me quite a bi= t of pain, and IMO the long-term downsides are quite minimal. And I already spe= nt way too much time trying to figure out if there is some bizarre edge case t= hat gcc is detecting :-/ tools/testing/selftests/kvm/memslot_perf_test.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/kvm/memslot_perf_test.c b/tools/testin= g/selftests/kvm/memslot_perf_test.c index 20eb2e730800..8698d1ab60d0 100644 --- a/tools/testing/selftests/kvm/memslot_perf_test.c +++ b/tools/testing/selftests/kvm/memslot_perf_test.c @@ -1033,9 +1033,8 @@ static bool test_loop(const struct test_data *data, struct test_result *rbestruntime) { uint64_t maxslots; - struct test_result result; + struct test_result result =3D {}; =20 - result.nloops =3D 0; if (!test_execute(targs->nslots, &maxslots, targs->seconds, data, &result.nloops, &result.slot_runtime, &result.guest_runtime)) { @@ -1089,7 +1088,7 @@ int main(int argc, char *argv[]) .seconds =3D 5, .runs =3D 1, }; - struct test_result rbestslottime; + struct test_result rbestslottime =3D {}; int tctr; =20 if (!check_memory_sizes()) @@ -1098,11 +1097,10 @@ int main(int argc, char *argv[]) if (!parse_args(argc, argv, &targs)) return -1; =20 - rbestslottime.slottimens =3D 0; for (tctr =3D targs.tfirst; tctr <=3D targs.tlast; tctr++) { const struct test_data *data =3D &tests[tctr]; unsigned int runctr; - struct test_result rbestruntime; + struct test_result rbestruntime =3D {}; =20 if (tctr > targs.tfirst) pr_info("\n"); @@ -1110,7 +1108,6 @@ int main(int argc, char *argv[]) pr_info("Testing %s performance with %i runs, %d seconds each\n", data->name, targs.runs, targs.seconds); =20 - rbestruntime.runtimens =3D 0; for (runctr =3D 0; runctr < targs.runs; runctr++) if (!test_loop(data, &targs, &rbestslottime, &rbestruntime)) base-commit: 013858c6fc2491c70640556385d5af123d1596c5 --=20 2.42.0.582.g8ccd20d70d-goog