Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3841878pxf; Mon, 22 Mar 2021 17:16:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7NsLlEnDtyjhZRQG30PHo/vMge3wU8bBMMDmwLvKfwq0moZpdAhDkRcdD2PckQ6vHAyKr X-Received: by 2002:aa7:d1cd:: with SMTP id g13mr2005951edp.369.1616458578950; Mon, 22 Mar 2021 17:16:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616458578; cv=none; d=google.com; s=arc-20160816; b=hLDy3/4NJffiJfFhjuaYpARKSzp9Sbei2bs8aRz6YyAUGKxLxWSAEPoxYjD1IA0P5V LTsod6qMT6AvYA4jJ85tsZgHmp/iZN7nSxVmBryUh925jjXJM06HeJLDmdBQVD6RkeMA wXrQBqngx3MjT2Fg70fndAMUJXofY4eAjaJJctXOqRQK2OPJbnOvjR18Cd0TFG6OJxPF GkY/0mw/aOLZCxSo+MZnu6fI8H1UyYhQ5297ZktGHlkf+h10icSXp++mzuifb1TxD+Wk PFv8FHs6pM1mBhfohKCXXnz26Jnndy5ouESh07FVAf+QzEw9cLWn9YTGV3qGyR3VAMAj VFRQ== 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-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=ZLe4jHn51FP9H526Os3ku5j3JqFdmzNB4MqtKFDpbIo=; b=yIj8X2lYlAO9tIfezcpq8Mgz6M9M8k2WQ5GWOUfTKGuTv5nSASb2VEITpKFg24RPT7 eyLQEohEG9lxKgGWihonl/U4IFMEMO5ZxH72aMZsmLJ8sXY9OFL5Ev7n3TJEEGs80T33 RH0xmZssJfhZsTvVn9aCv26NkIgbenm+xLyzNJPmrK4buh9fPlS9qYA+RAyinbSz7rJA AKVYZ8wy2qLdFRndDKyY1BvDdT8FwDEdabf8VcUp8dVo/H4OoX1ku3jH9DaLzdM2zh9m VAfRrQX1mawOFDt2XWL/aXoJ71TN+HlCmELCgtpwAdpYfWJI3zTpdgb5pHgJ8jDm9qQ2 aljw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=XkX373mm; 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 b9si12632452edq.492.2021.03.22.17.15.56; Mon, 22 Mar 2021 17:16:18 -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=@gmail.com header.s=20161025 header.b=XkX373mm; 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 S231195AbhCWANk (ORCPT + 99 others); Mon, 22 Mar 2021 20:13:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230476AbhCWANI (ORCPT ); Mon, 22 Mar 2021 20:13:08 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F082BC061574; Mon, 22 Mar 2021 17:13:07 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id p19so10109676wmq.1; Mon, 22 Mar 2021 17:13:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=ZLe4jHn51FP9H526Os3ku5j3JqFdmzNB4MqtKFDpbIo=; b=XkX373mmw4Dh8HNW12L7baOLdDWuLmPv1oNSV6ScxDctk7lmRGYaod7yEB90gcMX/K UBOw2C8snMjVAxSiJ5uQRc+5rqB3BIHzyy0xTv+3Gz5p1fS4S/qgFqo+kUO73GXhZWNl m5MvQXvT5sptN81SnUM72vURmrqo5KVQD7tSqLh1mXA8V4AbQY9FYRYPq1kQubPMCmS+ rsmSSPmacJwcgQLRQJGe/eILAxr4AIr2bu8koYFEG65yJGjqlUaP7VG8MKrKdm0+vhNA sKJHeXVPA+ko1BBiQGgbB79xCn6q4b7v1RLDgcbbb2gGe5eadZDJehvPJVW9W02Ojw8C 0qcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=ZLe4jHn51FP9H526Os3ku5j3JqFdmzNB4MqtKFDpbIo=; b=bcWsOByx3Spl2UeimkMx0ADZDNaVHyemN/7YfOijR63Ddiy+HhJznV9VRI2MgKF3dI 2DnauW/qurn/TRx05ZGszv1TCPDyXHDWyW+PW8vW5EJ7fJYT6bnNmsEB8QlJLJ4WsE1/ VAMCCDaZEZPd68ieJTusbYLI+pblLseb24aM8uLun+WmmIMETTIv3kKBz8u62B4kjFwx 72o0KBkSpbICCrN2rfZPxJ9nd0UQtadx1rGCSq+r/x+E5PuGI+DgIOe44sVYoB3K0S6X RV39F/KWVlDz9UqYaOfWyXc3+AT41UKEbdPh9iK49QR0lP9L0OCcB8pMhKtaenqgzFv/ Ld4Q== X-Gm-Message-State: AOAM531G0fwoF19mGR6Dw2rcwN5uQ6dBAQAEoS8qymp9DZCP9grsm8wn 254F77TFtPuFWNnhgEu7Z5Q= X-Received: by 2002:a1c:b48a:: with SMTP id d132mr751143wmf.108.1616458386647; Mon, 22 Mar 2021 17:13:06 -0700 (PDT) Received: from gmail.com (54033286.catv.pool.telekom.hu. [84.3.50.134]) by smtp.gmail.com with ESMTPSA id a4sm6686525wrx.86.2021.03.22.17.13.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 17:13:05 -0700 (PDT) Sender: Ingo Molnar Date: Tue, 23 Mar 2021 01:13:03 +0100 From: Ingo Molnar To: Michael Kelley Cc: Xu Yihang , KY Srinivasan , Haiyang Zhang , Stephen Hemminger , "tglx@linutronix.de" , "mingo@redhat.com" , "bp@alien8.de" , "x86@kernel.org" , "linux-hyperv@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "johnny.chenyi@huawei.com" , "heying24@huawei.com" Subject: Re: [PATCH -next] x86: Fix unused variable 'msr_val' warning Message-ID: <20210323001303.GA3092649@gmail.com> References: <20210322031713.23853-1-xuyihang@huawei.com> <20210322210828.GA1961861@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Michael Kelley wrote: > From: Ingo Molnar Sent: Monday, March 22, 2021 2:08 PM > > > > * Xu Yihang wrote: > > > > > Fixes the following W=1 kernel build warning(s): > > > arch/x86/hyperv/hv_spinlock.c:28:16: warning: variable 'msr_val' set but not used [- > > Wunused-but-set-variable] > > > unsigned long msr_val; > > > > > > As Hypervisor Top-Level Functional Specification states in chapter 7.5 Virtual Processor > > Idle Sleep State, "A partition which possesses the AccessGuestIdleMsr privilege (refer to > > section 4.2.2) may trigger entry into the virtual processor idle sleep state through a read to > > the hypervisor-defined MSR HV_X64_MSR_GUEST_IDLE". That means only a read is > > necessary, msr_val is not uesed, so __maybe_unused should be added. > > > > > > Reference: > > > > > > https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/tlfs > > > > > > Reported-by: Hulk Robot > > > Signed-off-by: Xu Yihang > > > --- > > > arch/x86/hyperv/hv_spinlock.c | 2 +- > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > diff --git a/arch/x86/hyperv/hv_spinlock.c b/arch/x86/hyperv/hv_spinlock.c > > > index f3270c1fc48c..67bc15c7752a 100644 > > > --- a/arch/x86/hyperv/hv_spinlock.c > > > +++ b/arch/x86/hyperv/hv_spinlock.c > > > @@ -25,7 +25,7 @@ static void hv_qlock_kick(int cpu) > > > > > > static void hv_qlock_wait(u8 *byte, u8 val) > > > { > > > - unsigned long msr_val; > > > + unsigned long msr_val __maybe_unused; > > > unsigned long flags; > > > > Please don't add new __maybe_unused annotations to the x86 tree - > > improve the flow instead to help GCC recognize the initialization > > sequence better. > > > > Thanks, > > > > Ingo > > Could you elaborate on the thinking here, or point to some written > discussion? I'm just curious. In this particular case, it's not a problem > with the flow or gcc detection. This code really does read an MSR and > ignore that value that is read, so it's not clear how gcc would ever > figure out that's OK. Yeah, so the canonical way to signal that the msr_val isn't used would be to rewrite this as: if (READ_ONCE(*byte) == val) { unsigned long msr_val; rdmsrl(HV_X64_MSR_GUEST_IDLE, msr_val); (void)msr_val; } (Also see the patch below - untested.) This makes it abundantly clear that the rdmsr() msr_val return value is not 'maybe' unused, but totally intentionally skipped. Thanks, Ingo arch/x86/hyperv/hv_spinlock.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/hyperv/hv_spinlock.c b/arch/x86/hyperv/hv_spinlock.c index f3270c1fc48c..7d948513ed42 100644 --- a/arch/x86/hyperv/hv_spinlock.c +++ b/arch/x86/hyperv/hv_spinlock.c @@ -25,7 +25,6 @@ static void hv_qlock_kick(int cpu) static void hv_qlock_wait(u8 *byte, u8 val) { - unsigned long msr_val; unsigned long flags; if (in_nmi()) @@ -48,8 +47,14 @@ static void hv_qlock_wait(u8 *byte, u8 val) /* * Only issue the rdmsrl() when the lock state has not changed. */ - if (READ_ONCE(*byte) == val) + if (READ_ONCE(*byte) == val) { + unsigned long msr_val; + rdmsrl(HV_X64_MSR_GUEST_IDLE, msr_val); + + (void)msr_val; + } + local_irq_restore(flags); }