linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -next] x86: Fix unused variable 'msr_val' warning
@ 2021-03-22  3:17 Xu Yihang
  2021-03-22 11:04 ` Wei Liu
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Xu Yihang @ 2021-03-22  3:17 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, tglx, mingo, bp, x86
  Cc: linux-hyperv, linux-kernel, xuyihang, johnny.chenyi, heying24

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 <hulkci@huawei.com>
Signed-off-by: Xu Yihang <xuyihang@huawei.com>
---
 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;
 
 	if (in_nmi())
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH -next] x86: Fix unused variable 'msr_val' warning
  2021-03-22  3:17 [PATCH -next] x86: Fix unused variable 'msr_val' warning Xu Yihang
@ 2021-03-22 11:04 ` Wei Liu
  2021-03-22 21:08 ` Ingo Molnar
  2021-03-23  2:43 ` Xu Yihang
  2 siblings, 0 replies; 10+ messages in thread
From: Wei Liu @ 2021-03-22 11:04 UTC (permalink / raw)
  To: Xu Yihang
  Cc: kys, haiyangz, sthemmin, tglx, mingo, bp, x86, linux-hyperv,
	linux-kernel, johnny.chenyi, heying24, Wei Liu

On Mon, Mar 22, 2021 at 11:17:13AM +0800, 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 <hulkci@huawei.com>
> Signed-off-by: Xu Yihang <xuyihang@huawei.com>

I modified the commit message a bit and queued this up for hyperv-next.
Thanks.

Wei.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH -next] x86: Fix unused variable 'msr_val' warning
  2021-03-22  3:17 [PATCH -next] x86: Fix unused variable 'msr_val' warning Xu Yihang
  2021-03-22 11:04 ` Wei Liu
@ 2021-03-22 21:08 ` Ingo Molnar
  2021-03-22 23:32   ` Michael Kelley
  2021-03-23  2:43 ` Xu Yihang
  2 siblings, 1 reply; 10+ messages in thread
From: Ingo Molnar @ 2021-03-22 21:08 UTC (permalink / raw)
  To: Xu Yihang
  Cc: kys, haiyangz, sthemmin, tglx, mingo, bp, x86, linux-hyperv,
	linux-kernel, johnny.chenyi, heying24


* Xu Yihang <xuyihang@huawei.com> 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 <hulkci@huawei.com>
> Signed-off-by: Xu Yihang <xuyihang@huawei.com>
> ---
>  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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH -next] x86: Fix unused variable 'msr_val' warning
  2021-03-22 21:08 ` Ingo Molnar
@ 2021-03-22 23:32   ` Michael Kelley
  2021-03-23  0:13     ` Ingo Molnar
  0 siblings, 1 reply; 10+ messages in thread
From: Michael Kelley @ 2021-03-22 23:32 UTC (permalink / raw)
  To: Ingo Molnar, Xu Yihang
  Cc: KY Srinivasan, Haiyang Zhang, Stephen Hemminger, tglx, mingo, bp,
	x86, linux-hyperv, linux-kernel, johnny.chenyi, heying24

From: Ingo Molnar <mingo.kernel.org@gmail.com> Sent: Monday, March 22, 2021 2:08 PM
> 
> * Xu Yihang <xuyihang@huawei.com> 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 <hulkci@huawei.com>
> > Signed-off-by: Xu Yihang <xuyihang@huawei.com>
> > ---
> >  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.

Michael



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH -next] x86: Fix unused variable 'msr_val' warning
  2021-03-22 23:32   ` Michael Kelley
@ 2021-03-23  0:13     ` Ingo Molnar
  2021-03-23 11:34       ` Wei Liu
  0 siblings, 1 reply; 10+ messages in thread
From: Ingo Molnar @ 2021-03-23  0:13 UTC (permalink / raw)
  To: Michael Kelley
  Cc: Xu Yihang, KY Srinivasan, Haiyang Zhang, Stephen Hemminger, tglx,
	mingo, bp, x86, linux-hyperv, linux-kernel, johnny.chenyi,
	heying24


* Michael Kelley <mikelley@microsoft.com> wrote:

> From: Ingo Molnar <mingo.kernel.org@gmail.com> Sent: Monday, March 22, 2021 2:08 PM
> > 
> > * Xu Yihang <xuyihang@huawei.com> 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 <hulkci@huawei.com>
> > > Signed-off-by: Xu Yihang <xuyihang@huawei.com>
> > > ---
> > >  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);
 }
 

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH -next] x86: Fix unused variable 'msr_val' warning
  2021-03-22  3:17 [PATCH -next] x86: Fix unused variable 'msr_val' warning Xu Yihang
  2021-03-22 11:04 ` Wei Liu
  2021-03-22 21:08 ` Ingo Molnar
@ 2021-03-23  2:43 ` Xu Yihang
  2021-03-24 11:28   ` Wei Liu
  2 siblings, 1 reply; 10+ messages in thread
From: Xu Yihang @ 2021-03-23  2:43 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, tglx, mingo, bp, x86
  Cc: linux-hyperv, linux-kernel, xuyihang, johnny.chenyi, heying24

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 potentially cast to void in order to silent this warning.

Reference:
https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/tlfs

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Xu Yihang <xuyihang@huawei.com>
---
 arch/x86/hyperv/hv_spinlock.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/x86/hyperv/hv_spinlock.c b/arch/x86/hyperv/hv_spinlock.c
index f3270c1fc48c..91cfe698bde0 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,13 @@ 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);
 }
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH -next] x86: Fix unused variable 'msr_val' warning
  2021-03-23  0:13     ` Ingo Molnar
@ 2021-03-23 11:34       ` Wei Liu
  0 siblings, 0 replies; 10+ messages in thread
From: Wei Liu @ 2021-03-23 11:34 UTC (permalink / raw)
  To: Ingo Molnar
  Cc: Michael Kelley, Xu Yihang, KY Srinivasan, Haiyang Zhang,
	Stephen Hemminger, tglx, mingo, bp, x86, linux-hyperv,
	linux-kernel, johnny.chenyi, heying24, Wei Liu

On Tue, Mar 23, 2021 at 01:13:03AM +0100, Ingo Molnar wrote:
> 
> * Michael Kelley <mikelley@microsoft.com> wrote:
> 
> > From: Ingo Molnar <mingo.kernel.org@gmail.com> Sent: Monday, March 22, 2021 2:08 PM
> > > 
> > > * Xu Yihang <xuyihang@huawei.com> 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 <hulkci@huawei.com>
> > > > Signed-off-by: Xu Yihang <xuyihang@huawei.com>
> > > > ---
> > > >  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
> 

Thank you for the advice, Ingo.

Wei.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH -next] x86: Fix unused variable 'msr_val' warning
  2021-03-23  2:43 ` Xu Yihang
@ 2021-03-24 11:28   ` Wei Liu
  0 siblings, 0 replies; 10+ messages in thread
From: Wei Liu @ 2021-03-24 11:28 UTC (permalink / raw)
  To: Xu Yihang
  Cc: kys, haiyangz, sthemmin, tglx, mingo, bp, x86, linux-hyperv,
	linux-kernel, johnny.chenyi, heying24, Wei Liu

On Tue, Mar 23, 2021 at 10:43:02AM +0800, 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 potentially cast to void in order to silent this warning.
> 
> Reference:
> https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/tlfs
> 
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Xu Yihang <xuyihang@huawei.com>

Applied to hyperv-next. Thanks.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: [PATCH -next] x86: Fix unused variable 'msr_val' warning
  2021-03-18  8:03 Xu Yihang
@ 2021-03-19 18:48 ` Michael Kelley
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Kelley @ 2021-03-19 18:48 UTC (permalink / raw)
  To: Xu Yihang, KY Srinivasan, Haiyang Zhang, Stephen Hemminger, tglx,
	mingo, bp, x86
  Cc: linux-hyperv, linux-kernel

From: Xu Yihang <xuyihang@huawei.com> Sent: Thursday, March 18, 2021 1:04 AM
> 
> 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;
> 
> Reported-by: Hulk Robot <hulkci@huawei.com>
> Signed-off-by: Xu Yihang <xuyihang@huawei.com>
> ---
>  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;
> 
>  	if (in_nmi())
> --
> 2.17.1

This is one of those slightly weird cases where the side 
effect of reading the synthetic MSR provided by Hyper-V
is what we want.  The returned value is irrelevant and
never used, so the __maybe_unused annotation is correct.

Let me suggest updating the commit message, and adding
a brief comment to the code to explain this.  The side
effect behavior is described in the Hyper-V TLFS, though
perhaps not as clearly as it should be.

Michael

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH -next] x86: Fix unused variable 'msr_val' warning
@ 2021-03-18  8:03 Xu Yihang
  2021-03-19 18:48 ` Michael Kelley
  0 siblings, 1 reply; 10+ messages in thread
From: Xu Yihang @ 2021-03-18  8:03 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, tglx, mingo, bp, x86
  Cc: linux-hyperv, linux-kernel, xuyihang

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;

Reported-by: Hulk Robot <hulkci@huawei.com>
Signed-off-by: Xu Yihang <xuyihang@huawei.com>
---
 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;
 
 	if (in_nmi())
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-03-24 11:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-22  3:17 [PATCH -next] x86: Fix unused variable 'msr_val' warning Xu Yihang
2021-03-22 11:04 ` Wei Liu
2021-03-22 21:08 ` Ingo Molnar
2021-03-22 23:32   ` Michael Kelley
2021-03-23  0:13     ` Ingo Molnar
2021-03-23 11:34       ` Wei Liu
2021-03-23  2:43 ` Xu Yihang
2021-03-24 11:28   ` Wei Liu
  -- strict thread matches above, loose matches on Subject: below --
2021-03-18  8:03 Xu Yihang
2021-03-19 18:48 ` Michael Kelley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).