Received: by 2002:a05:7412:518d:b0:e2:908c:2ebd with SMTP id fn13csp340686rdb; Thu, 5 Oct 2023 07:31:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH8e3mMdanQCsDRYec4QZKgB+ps5oJHveMU4T7yfh8ZB9W3qlzF0IYozBjZ10vvCoF9dKg4 X-Received: by 2002:a17:90b:4f4d:b0:276:dc2f:be9d with SMTP id pj13-20020a17090b4f4d00b00276dc2fbe9dmr4993725pjb.33.1696516289215; Thu, 05 Oct 2023 07:31:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696516289; cv=none; d=google.com; s=arc-20160816; b=ughfgz7OZPOoONV/Os6svEN0XX7lPPYFmMojlvaPwLdu3Den1hnGrWe0I3zMSp6wP5 EFPtWzHaiyNoRNMRMLwg996QoQ57J+ZwOPCHBP/X6EH649ZLMsdx1WQV8sHk0Hl2uXea gGKFVlTTf1HOgXniLMc+HXfWxDYAu02ucFLjCWRfPHWm1i1Nd0KCVBgCGFKBVq5po2PL JRNANLzLmb0B1nVoqpSBx0t5NHt1vtr9Tyrn9scjahCEO/ZFmbOZ9gWFc3cdOsmLQqnO 2m8WLHUSWmLjftHTu3DQ5CETs7T9P1TS623TVwHU9wTxaBQt8gmjFIyQd9vNkemcxRms znIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=+vdqveFoqTC4kTMjULrJM/pFuxAH0pZ83O2NiJo6o6s=; fh=MobgfiYWbXofQWLtQj3pGPfgVhBxPXHXhPQf5TJMXd0=; b=RNfbjhhT/pHrmspUAvEPcO9V+2+Hs78nQt62AhP4qe5p0NEWIhN0A0ze8JcgV+rKNH XA4IMS5cYI2Vx+9TUJbpblVAEIKZ91M4D+9To/WW/h0X0m5xzd1XKGAqR8UxBVTlVBqb iRmq5coaihwGZ7roLj1HGkzB0kSIONK9cON0xAEp9LGz/mXTK4ZxWL3HnfngFSpjgXJJ YjGLACMRtc7QImQRY9wRVr/Ilz1E4ntn0RBpisktcfA55P0NXivyMleBjm8/XY/NQ8KD +iuAS96IYE0+pQuCuVnX8kuik4cxSI7VnMbBWFTHRV+E9vYoZEKsiJeuWxr3EzXYpqwR +SZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="u36YCd/s"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id h5-20020a17090ac38500b00279866aa14csi1707774pjt.16.2023.10.05.07.31.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 07:31:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="u36YCd/s"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id CBB41826FB57; Thu, 5 Oct 2023 07:31:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234126AbjJEO3u (ORCPT + 99 others); Thu, 5 Oct 2023 10:29:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233558AbjJEO2K (ORCPT ); Thu, 5 Oct 2023 10:28:10 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA8476EAB for ; Wed, 4 Oct 2023 23:41:41 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-40572aeb73cso5181905e9.3 for ; Wed, 04 Oct 2023 23:41:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696488100; x=1697092900; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=+vdqveFoqTC4kTMjULrJM/pFuxAH0pZ83O2NiJo6o6s=; b=u36YCd/sGIJoSFSh+280Jj7t+31EiOJylJmuP9BM2OQURFLvRGDj8inwgmZzHidOYk iBo2/l/eki3uSq2O3HeOVE1/frG9LB+i3Gq6pc8CfNg87AVASXn9XK1OT2znqVtI3mgK WTQ8fG1u0AOY6Zh9f1yhhj9o8cK/QEwWP+l2+mOOyJ1dgJWcXmXp/eDfbIJWpz+LxIo8 H2R0kBFS2SOUEuvvnfU2DWPM4JmuM2LAbWaW2YaZ9ZOK0MPqgJZuH0CBVg9+6Y548gaj Pwq0RgtpmMNVq8GtCLrD/Rq/EDunT+Xms9FWSfpt6TM8nH7Jwk6/apaf0PehJyuxZXfg o7FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696488100; x=1697092900; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=+vdqveFoqTC4kTMjULrJM/pFuxAH0pZ83O2NiJo6o6s=; b=uleU1MR6I/6om3Enxmudwg9L1iW9soFICuKQXIvqL41Ys7Eald02XIsMEc2hxhZa67 2fNF/iRXezbtmw4fY/lGxOp7/jK2JYvrWnNPKORGkL6vyRsMLAEzdexQ/2nlvGhbwIv8 A9WqL6pLC7UV20WjtyK7x6+0dsJkjYQwdTQQInJJw0DuiTlglssjNpB08+Kxo2jbRo5W VfEe7w9+ja//Lmgqgy4bRahzsXiH85HMV10AXg1+sJelClse0nCJsOWe12tBkgIReBKo /SnLJuuTMMm6LWkZXhr+eM8QllGZyRkDI1SB5I1FnZIpiO5W0E3+pinjHBSvW4oM9e3a c5mg== X-Gm-Message-State: AOJu0YzZWRcz7GFiI2uPEixIgH8o8YjL/xDsKB+8CvaNdi3C7aC/QV4D PZaR+6yIuJ/UyR2W/xXla91LkQ== X-Received: by 2002:a7b:c851:0:b0:405:3252:fe2 with SMTP id c17-20020a7bc851000000b0040532520fe2mr4050578wml.14.1696488100310; Wed, 04 Oct 2023 23:41:40 -0700 (PDT) Received: from [192.168.69.115] (tbo33-h01-176-171-211-120.dsl.sta.abo.bbox.fr. [176.171.211.120]) by smtp.gmail.com with ESMTPSA id w21-20020a05600c015500b0040652e8ca13sm3011556wmm.43.2023.10.04.23.41.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 04 Oct 2023 23:41:39 -0700 (PDT) Message-ID: <631a4966-982b-8d7c-1ad5-e9358f98fcf4@linaro.org> Date: Thu, 5 Oct 2023 08:41:38 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH] KVM: selftests: Zero-initialize entire test_result in memslot perf test Content-Language: en-US To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Maciej S . Szmigiero" References: <20231005002954.2887098-1-seanjc@google.com> From: =?UTF-8?Q?Philippe_Mathieu-Daud=c3=a9?= In-Reply-To: <20231005002954.2887098-1-seanjc@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email 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 (groat.vger.email [0.0.0.0]); Thu, 05 Oct 2023 07:31:15 -0700 (PDT) On 5/10/23 02:29, Sean Christopherson wrote: > 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 ‘main’: > include/test_util.h:31:22: error: ‘rbestslottime.slot_runtime.tv_nsec’ may be used uninitialized [-Werror=maybe-uninitialized] > 31 | #define pr_info(...) printf(__VA_ARGS__) > | ^~~~~~~~~~~~~~~~~~~ > memslot_perf_test.c:1127:17: note: in expansion of macro ‘pr_info’ > 1127 | pr_info("Best slot setup time for the whole test area was %ld.%.9lds\n", > | ^~~~~~~ > memslot_perf_test.c:1092:28: note: ‘rbestslottime.slot_runtime.tv_nsec’ was declared here > 1092 | struct test_result rbestslottime; > | ^~~~~~~~~~~~~ > include/test_util.h:31:22: error: ‘rbestslottime.slot_runtime.tv_sec’ may be used uninitialized [-Werror=maybe-uninitialized] > 31 | #define pr_info(...) printf(__VA_ARGS__) > | ^~~~~~~~~~~~~~~~~~~ > memslot_perf_test.c:1127:17: note: in expansion of macro ‘pr_info’ > 1127 | pr_info("Best slot setup time for the whole test area was %ld.%.9lds\n", > | ^~~~~~~ > memslot_perf_test.c:1092:28: note: ‘rbestslottime.slot_runtime.tv_sec’ 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 = 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 bit of > pain, and IMO the long-term downsides are quite minimal. And I already spent > way too much time trying to figure out if there is some bizarre edge case that > gcc is detecting :-/ > > tools/testing/selftests/kvm/memslot_perf_test.c | 9 +++------ > 1 file changed, 3 insertions(+), 6 deletions(-) Reviewed-by: Philippe Mathieu-Daudé