Message ID | ZULCd/TGJL9Dmncf@agluck-desk3 |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:abcd:0:b0:403:3b70:6f57 with SMTP id f13csp719327vqx; Wed, 1 Nov 2023 14:26:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCxOAg4ANpJK1ddeknUlRPAvbJE6UnEgHWydBmWKgIGmfprSDgU+9wkk618KIkFiu6Z1+C X-Received: by 2002:a17:90a:1b8e:b0:27f:fcdb:89c1 with SMTP id w14-20020a17090a1b8e00b0027ffcdb89c1mr13103157pjc.41.1698874011117; Wed, 01 Nov 2023 14:26:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698874011; cv=none; d=google.com; s=arc-20160816; b=lY5xmmXpBkFu7ubd6IzbPG0yX8dYSsy9IKYT0akY421RO4d+UDPzIQsBf4sRz7j7Gf fwmc/5UfWCpRl7DUAYKfoGvuDGqHEEy1gSfiubL+NYYYc2OuZpIuh91WCioE0vKYNnBn W66ROuPFnLvtDbg+7TC9kNbPS2t/GAV9ol3Z44MprQLzS5Z5p0IJ6+gYvADN9vNSLAPM HHZ/8o0rfQk3yd8IXi9hrsUGWx4suyEjXSCYsXrxBr8/WT26ME50G1r5WPzW3+GqkPio KjblvKW7tUTjSSOtLSsgUt8UpIJYc2FaI+494FMyrfDxbF8GAoe/+vqPsWnal++HwlmO 8p1A== 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=TYznC4Ba2w7P8whegdh9nfzaur0ZoCXIEwB2uF6027c=; fh=fPeCjUcfyw8i8skiX06N5dr0nnedBh1fpz0K59kWKqo=; b=HLNkfkF5WAAjjonotQtKWJInQHQPcrFn85NjAYUsHhi+IkvkFtpkmp1XiAyD43HG5y IyGJUwJlhEQbzf4tpCMcdoiE0wj+pfidD0K30Az0ZQFBxeantTA+hQCZ4fx0ERGUPJM7 u5Vd3o1voBT+9fbCUSowb8dLclurdsXcT4JrmerAA3ubxcxO+RidqcWRKJqosFFWczO9 hhvNLFp4nwSfEcTrKw8+fhkmGQGFSdtDuv2MQSoik2QWP9Pif99cz1S5dqHjgcWoZbe3 KJcE8TwijWqkZ4yCZ00HUvQwEMVA6ePA47We689ZW0wmRghZRp8GlTIQ0En+lHQxz4wC B8qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=griO7eMp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id i10-20020a17090a974a00b0028014e41ff7si1532686pjw.48.2023.11.01.14.26.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 14:26:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=griO7eMp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 14E8A8194765; Wed, 1 Nov 2023 14:26:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345581AbjKAV03 (ORCPT <rfc822;heyuhang3455@gmail.com> + 35 others); Wed, 1 Nov 2023 17:26:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345432AbjKAV0Z (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 1 Nov 2023 17:26:25 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45E5F122 for <linux-kernel@vger.kernel.org>; Wed, 1 Nov 2023 14:26:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1698873977; x=1730409977; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=W/tSw6Scof6Iowi5GgeffcVwE78iqgrLgeV/J7eZZQI=; b=griO7eMpF5cxCy9ltVStBpzPF2mB1vmoZv+Z/MVuusupU7zT53OCpWjS i6Y0sjK0LMpNojeOUIirzA/Y/6WPsW2dOrtdcsIGzwgF1td6hKjlhnurj yRqbsfPCQ6S04UT5iaGf91geIlE/dcb2LFshSw+V9Mge1jh2BZ7QCVINT Y+DxrZdKhJ9xxvhCpXcKgbqLrBx2fb9X2zCriqcCwjUn5yaKzook73ZTo 2TnTzIkvc+C2I876vF/hAmuTVSjnjXAB3yfgB6qpKpJAIKs+fSriY/Sf5 8Fs/ANZCWoULgrNcwthmoMyVG38sb2ds2OQHpjwOj8dCuHNICxxyCm6CD g==; X-IronPort-AV: E=McAfee;i="6600,9927,10881"; a="419699894" X-IronPort-AV: E=Sophos;i="6.03,269,1694761200"; d="scan'208";a="419699894" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2023 14:26:17 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10881"; a="764691693" X-IronPort-AV: E=Sophos;i="6.03,269,1694761200"; d="scan'208";a="764691693" Received: from agluck-desk3.sc.intel.com (HELO agluck-desk3) ([172.25.222.74]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Nov 2023 14:26:16 -0700 Date: Wed, 1 Nov 2023 14:26:15 -0700 From: Tony Luck <tony.luck@intel.com> To: "Moger, Babu" <babu.moger@amd.com> Cc: "Yu, Fenghua" <fenghua.yu@intel.com>, "Chatre, Reinette" <reinette.chatre@intel.com>, Peter Newman <peternewman@google.com>, "x86@kernel.org" <x86@kernel.org>, Shaopeng Tan <tan.shaopeng@fujitsu.com>, James Morse <james.morse@arm.com>, Jamie Iles <quic_jiles@quicinc.com>, Randy Dunlap <rdunlap@infradead.org>, "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>, "patches@lists.linux.dev" <patches@lists.linux.dev> Subject: [PATCH v2] x86/resctrl: Fix unused variable warning in cache_alloc_hsw_probe() Message-ID: <ZULCd/TGJL9Dmncf@agluck-desk3> References: <20231031220534.37730-1-tony.luck@intel.com> <d47235e0-7ecd-483e-82c3-78f13c77df67@amd.com> <SJ1PR11MB6083C14236AC0AFCB49DFB15FCA7A@SJ1PR11MB6083.namprd11.prod.outlook.com> <9e6a979a-48db-4b25-884f-ac8d4c2bb078@amd.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <9e6a979a-48db-4b25-884f-ac8d4c2bb078@amd.com> X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 01 Nov 2023 14:26:43 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781310405072899362 X-GMAIL-MSGID: 1781398514726921398 |
Series |
[v2] x86/resctrl: Fix unused variable warning in cache_alloc_hsw_probe()
|
|
Commit Message
Luck, Tony
Nov. 1, 2023, 9:26 p.m. UTC
In a "W=1" build gcc throws a warning:
arch/x86/kernel/cpu/resctrl/core.c: In function ‘cache_alloc_hsw_probe’:
arch/x86/kernel/cpu/resctrl/core.c:139:16: warning: variable ‘h’ set but not used
Fix by switching from wrmsr_safe() to wrmsrl_safe(), and from rdmsr()
to rdmsrl() using a single u64 argument for the MSR value instead of
the pair of u32 for the high and low halves.
Signed-off-by: Tony Luck <tony.luck@intel.com>
---
Changes since v1 (suggested by Babu)
Switch both the wrmsr() and rdmsr() to the 64-bit versions.
arch/x86/kernel/cpu/resctrl/core.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
Comments
Looks good. On 11/1/23 16:26, Tony Luck wrote: > In a "W=1" build gcc throws a warning: > > arch/x86/kernel/cpu/resctrl/core.c: In function ‘cache_alloc_hsw_probe’: > arch/x86/kernel/cpu/resctrl/core.c:139:16: warning: variable ‘h’ set but not used > > Fix by switching from wrmsr_safe() to wrmsrl_safe(), and from rdmsr() > to rdmsrl() using a single u64 argument for the MSR value instead of > the pair of u32 for the high and low halves. > > Signed-off-by: Tony Luck <tony.luck@intel.com> Reviewed-by: Babu Moger <babu.moger@amd.com> > --- > Changes since v1 (suggested by Babu) > > Switch both the wrmsr() and rdmsr() to the 64-bit versions. > > arch/x86/kernel/cpu/resctrl/core.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c > index 19e0681f0435..d29ebe345de6 100644 > --- a/arch/x86/kernel/cpu/resctrl/core.c > +++ b/arch/x86/kernel/cpu/resctrl/core.c > @@ -136,15 +136,15 @@ static inline void cache_alloc_hsw_probe(void) > { > struct rdt_hw_resource *hw_res = &rdt_resources_all[RDT_RESOURCE_L3]; > struct rdt_resource *r = &hw_res->r_resctrl; > - u32 l, h, max_cbm = BIT_MASK(20) - 1; > + u64 max_cbm = BIT_ULL_MASK(20) - 1, l3_cbm_0; > > - if (wrmsr_safe(MSR_IA32_L3_CBM_BASE, max_cbm, 0)) > + if (wrmsrl_safe(MSR_IA32_L3_CBM_BASE, max_cbm)) > return; > > - rdmsr(MSR_IA32_L3_CBM_BASE, l, h); > + rdmsrl(MSR_IA32_L3_CBM_BASE, l3_cbm_0); > > /* If all the bits were set in MSR, return success */ > - if (l != max_cbm) > + if (l3_cbm_0 != max_cbm) > return; > > hw_res->num_closid = 4;
Hi Tony, On 11/1/2023 2:26 PM, Tony Luck wrote: > In a "W=1" build gcc throws a warning: This is strange, I am not able to encounter this warning. Is my gcc perhaps too old? I know there were some specific versions needed to reproduce similar warnings with clang (see reference commit 793207bad71c ("x86/resctrl: Fix a silly -Wunused-but-set-variable warning")). > > arch/x86/kernel/cpu/resctrl/core.c: In function ‘cache_alloc_hsw_probe’: > arch/x86/kernel/cpu/resctrl/core.c:139:16: warning: variable ‘h’ set but not used > > Fix by switching from wrmsr_safe() to wrmsrl_safe(), and from rdmsr() > to rdmsrl() using a single u64 argument for the MSR value instead of > the pair of u32 for the high and low halves. > > Signed-off-by: Tony Luck <tony.luck@intel.com> I do not know if all the text from that reference commit applies here, but for what it is worth: Acked-by: Reinette Chatre <reinette.chatre@intel.com> Reinette
> This is strange, I am not able to encounter this warning. Is my gcc perhaps > too old? I know there were some specific versions needed to reproduce similar > warnings with clang (see reference commit 793207bad71c ("x86/resctrl: Fix a silly > -Wunused-but-set-variable warning")). I'm using the default install from Fedora 38: $ gcc --version gcc (GCC) 13.2.1 20230728 (Red Hat 13.2.1-1) Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -Tony
Hi Tony, On 11/2/2023 3:02 PM, Luck, Tony wrote: >> This is strange, I am not able to encounter this warning. Is my gcc perhaps >> too old? I know there were some specific versions needed to reproduce similar >> warnings with clang (see reference commit 793207bad71c ("x86/resctrl: Fix a silly >> -Wunused-but-set-variable warning")). > > I'm using the default install from Fedora 38: > > $ gcc --version > gcc (GCC) 13.2.1 20230728 (Red Hat 13.2.1-1) > Copyright (C) 2023 Free Software Foundation, Inc. > This is free software; see the source for copying conditions. There is NO > warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Thank you for confirming. I tested with the same version. Strange, I see other instances of this warning but not the resctrl one: $ grep "set but not used" ~/t/log | wc -l 20 $ grep resctrl ~/t/log CC arch/x86/kernel/cpu/resctrl/core.o CC arch/x86/kernel/cpu/resctrl/rdtgroup.o CC arch/x86/kernel/cpu/resctrl/monitor.o CC arch/x86/kernel/cpu/resctrl/ctrlmondata.o CC arch/x86/kernel/cpu/resctrl/pseudo_lock.o AR arch/x86/kernel/cpu/resctrl/built-in.a This does seem a valid issue and my Ack remains. I'm just puzzled why I do not encounter the same warning. Reinette
> This does seem a valid issue and my Ack remains. I'm just puzzled why I do not > encounter the same warning. Reinette, Some other CONFIG option changing CFLAGS? Here's what I have for a "make V=1 W=1" for core.o # CC arch/x86/kernel/cpu/resctrl/core.o gcc -Wp,-MMD,arch/x86/kernel/cpu/resctrl/.core.o.d -nostdinc -I./arch/x86/include -I./arch/x86/include/generated -I./include -I./arch/x86/include/uapi -I./arch/x86/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -fmacro-prefix-map=./= -Wundef -DKBUILD_EXTRA_WARN1 -std=gnu11 -fshort-wchar -funsigned-char -fno-common -fno-PIE -fno-strict-aliasing -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fcf-protection=none -m64 -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mpreferred-stack-boundary=3 -mskip-rax-setup -mtune=generic -mno-red-zone -mcmodel=kernel -Wno-sign-compare -fno-asynchronous-unwind-tables -mindirect-branch=thunk-extern -mindirect-branch-register -mindirect-branch-cs-prefix -mfunction-return=thunk-extern -fno-jump-tables -mharden-sls=all -fpatchable-function-entry=16,16 -fno-delete-null-pointer-checks -O2 -fno-allow-store-data-races -fstack-protector-strong -ftrivial-auto-var-init=zero -fno-stack-clash-protection -pg -mrecord-mcount -mfentry -DCC_USING_FENTRY -falign-functions=16 -fstrict-flex-arrays=3 -fno-strict-overflow -fno-stack-check -fconserve-stack -Wall -Wundef -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-packed-member -Wframe-larger-than=2048 -Wno-main -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-dangling-pointer -Wvla -Wno-pointer-sign -Wcast-function-type -Wno-array-bounds -Wno-alloc-size-larger-than -Wimplicit-fallthrough=5 -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wenum-conversion -Wextra -Wunused -Wno-unused-parameter -Wmissing-declarations -Wrestrict -Wmissing-format-attribute -Wmissing-prototypes -Wold-style-definition -Wmissing-include-dirs -Wunused-but-set-variable -Wunused-const-variable -Wpacked-not-aligned -Wformat-overflow -Wformat-truncation -Wstringop-overflow -Wstringop-truncation -Wno-missing-field-initializers -Wno-type-limits -Wno-shift-negative-value -Wno-maybe-uninitialized -Wno-sign-compare -g -DKBUILD_MODFILE='"arch/x86/kernel/cpu/resctrl/core"' -DKBUILD_BASENAME='"core"' -DKBUILD_MODNAME='"core"' -D__KBUILD_MODNAME=kmod_core -c -o arch/x86/kernel/cpu/resctrl/core.o arch/x86/kernel/cpu/resctrl/core.c ; ./tools/objtool/objtool --hacks=jump_label --hacks=noinstr --hacks=skylake --orc --retpoline --rethunk --sls --static-call --uaccess --prefix=16 arch/x86/kernel/cpu/resctrl/core.o arch/x86/kernel/cpu/resctrl/core.c: In function ‘cache_alloc_hsw_probe’: arch/x86/kernel/cpu/resctrl/core.c:139:16: warning: variable ‘h’ set but not used [-Wunused-but-set-variable] 139 | u32 l, h, max_cbm = BIT_MASK(20) - 1; | ^ Dropping just the "-Wunused-but-set-variable" from that big mess does make the warning disappear for me. But maybe some option can result in the argument list being built in a different order? I see there is an earlier " -Wno-unused-but-set-variable" -Tony
On 11/2/2023 3:50 PM, Luck, Tony wrote: >> This does seem a valid issue and my Ack remains. I'm just puzzled why I do not >> encounter the same warning. > > Reinette, > > Some other CONFIG option changing CFLAGS? > > Here's what I have for a "make V=1 W=1" for core.o > Tony and I went a bit more back-and-forth on this one and it appears that the relevant code is optimized out in my build while the same did not happen for him. I can now trigger the warning by enabling Xen support, with CONFIG_PARAVIRT_XXL causing rdmsr() to be replaced by paravirt_read_msr(). With the relevant code no longer optimized out, the warning is triggered. Thanks Tony! Reinette
diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c index 19e0681f0435..d29ebe345de6 100644 --- a/arch/x86/kernel/cpu/resctrl/core.c +++ b/arch/x86/kernel/cpu/resctrl/core.c @@ -136,15 +136,15 @@ static inline void cache_alloc_hsw_probe(void) { struct rdt_hw_resource *hw_res = &rdt_resources_all[RDT_RESOURCE_L3]; struct rdt_resource *r = &hw_res->r_resctrl; - u32 l, h, max_cbm = BIT_MASK(20) - 1; + u64 max_cbm = BIT_ULL_MASK(20) - 1, l3_cbm_0; - if (wrmsr_safe(MSR_IA32_L3_CBM_BASE, max_cbm, 0)) + if (wrmsrl_safe(MSR_IA32_L3_CBM_BASE, max_cbm)) return; - rdmsr(MSR_IA32_L3_CBM_BASE, l, h); + rdmsrl(MSR_IA32_L3_CBM_BASE, l3_cbm_0); /* If all the bits were set in MSR, return success */ - if (l != max_cbm) + if (l3_cbm_0 != max_cbm) return; hw_res->num_closid = 4;