All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/hyperv: Fix hv_get/set_register for nested bringup
@ 2023-02-09 22:02 Nuno Das Neves
  2023-02-13 14:28 ` Wei Liu
  0 siblings, 1 reply; 7+ messages in thread
From: Nuno Das Neves @ 2023-02-09 22:02 UTC (permalink / raw)
  To: linux-hyperv, linux-kernel, x86, wei.liu, jinankjain
  Cc: mikelley, kys, Tianyu.Lan, haiyangz, decui, tglx, mingo, bp,
	dave.hansen, hpa

hv_get_nested_reg only translates SINT0, resulting in the wrong sint
being registered by nested vmbus.
Fix the issue with new utility function hv_is_sint_reg.
While at it, improve clarity of hv_set_non_nested_register and hv_is_synic_reg.

Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
---
 arch/x86/include/asm/mshyperv.h | 11 +++++++----
 arch/x86/kernel/cpu/mshyperv.c  |  8 ++++----
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index 9ae1a344536b..684c547c1cca 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -225,10 +225,13 @@ extern bool hv_isolation_type_snp(void);
 
 static inline bool hv_is_synic_reg(unsigned int reg)
 {
-	if ((reg >= HV_REGISTER_SCONTROL) &&
-	    (reg <= HV_REGISTER_SINT15))
-		return true;
-	return false;
+	return (reg >= HV_REGISTER_SCONTROL) &&
+	       (reg <= HV_REGISTER_SINT15);
+}
+static inline bool hv_is_sint_reg(unsigned int reg)
+{
+	return (reg >= HV_REGISTER_SINT0) &&
+	       (reg <= HV_REGISTER_SINT15);
 }
 
 u64 hv_get_register(unsigned int reg);
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 0ceb6d1f9c3c..6bd344e1200f 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -44,6 +44,9 @@ struct ms_hyperv_info ms_hyperv;
 #if IS_ENABLED(CONFIG_HYPERV)
 static inline unsigned int hv_get_nested_reg(unsigned int reg)
 {
+	if (hv_is_sint_reg(reg))
+		return reg - HV_REGISTER_SINT0 + HV_REGISTER_NESTED_SINT0;
+
 	switch (reg) {
 	case HV_REGISTER_SIMP:
 		return HV_REGISTER_NESTED_SIMP;
@@ -53,8 +56,6 @@ static inline unsigned int hv_get_nested_reg(unsigned int reg)
 		return HV_REGISTER_NESTED_SVERSION;
 	case HV_REGISTER_SCONTROL:
 		return HV_REGISTER_NESTED_SCONTROL;
-	case HV_REGISTER_SINT0:
-		return HV_REGISTER_NESTED_SINT0;
 	case HV_REGISTER_EOM:
 		return HV_REGISTER_NESTED_EOM;
 	default:
@@ -80,8 +81,7 @@ void hv_set_non_nested_register(unsigned int reg, u64 value)
 		hv_ghcb_msr_write(reg, value);
 
 		/* Write proxy bit via wrmsl instruction */
-		if (reg >= HV_REGISTER_SINT0 &&
-		    reg <= HV_REGISTER_SINT15)
+		if (hv_is_sint_reg(reg))
 			wrmsrl(reg, value | 1 << 20);
 	} else {
 		wrmsrl(reg, value);
-- 
2.25.1


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

* Re: [PATCH] x86/hyperv: Fix hv_get/set_register for nested bringup
  2023-02-09 22:02 [PATCH] x86/hyperv: Fix hv_get/set_register for nested bringup Nuno Das Neves
@ 2023-02-13 14:28 ` Wei Liu
  2023-02-14 22:17   ` Nuno Das Neves
  2023-02-15 16:35   ` Jinank Jain
  0 siblings, 2 replies; 7+ messages in thread
From: Wei Liu @ 2023-02-13 14:28 UTC (permalink / raw)
  To: Nuno Das Neves
  Cc: linux-hyperv, linux-kernel, x86, wei.liu, jinankjain, mikelley,
	kys, Tianyu.Lan, haiyangz, decui, tglx, mingo, bp, dave.hansen,
	hpa

A few comments on style.

On Thu, Feb 09, 2023 at 02:02:52PM -0800, Nuno Das Neves wrote:
> hv_get_nested_reg only translates SINT0, resulting in the wrong sint
> being registered by nested vmbus.

Please put a blank line between paragraphs.

> Fix the issue with new utility function hv_is_sint_reg.
> While at it, improve clarity of hv_set_non_nested_register and hv_is_synic_reg.
> 
> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
> ---
>  arch/x86/include/asm/mshyperv.h | 11 +++++++----
>  arch/x86/kernel/cpu/mshyperv.c  |  8 ++++----
>  2 files changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
> index 9ae1a344536b..684c547c1cca 100644
> --- a/arch/x86/include/asm/mshyperv.h
> +++ b/arch/x86/include/asm/mshyperv.h
> @@ -225,10 +225,13 @@ extern bool hv_isolation_type_snp(void);
>  
>  static inline bool hv_is_synic_reg(unsigned int reg)
>  {
> -	if ((reg >= HV_REGISTER_SCONTROL) &&
> -	    (reg <= HV_REGISTER_SINT15))
> -		return true;
> -	return false;
> +	return (reg >= HV_REGISTER_SCONTROL) &&
> +	       (reg <= HV_REGISTER_SINT15);
> +}

Please put a new line here.

I can fix these issues too if you don't end up sending a new version due
to other issues.

Jinank, please take a look. The code looks sensible to me, but I would
like you to have a look too.

Thanks,
Wei.

> +static inline bool hv_is_sint_reg(unsigned int reg)
> +{
> +	return (reg >= HV_REGISTER_SINT0) &&
> +	       (reg <= HV_REGISTER_SINT15);
>  }
>  
>  u64 hv_get_register(unsigned int reg);
> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
> index 0ceb6d1f9c3c..6bd344e1200f 100644
> --- a/arch/x86/kernel/cpu/mshyperv.c
> +++ b/arch/x86/kernel/cpu/mshyperv.c
> @@ -44,6 +44,9 @@ struct ms_hyperv_info ms_hyperv;
>  #if IS_ENABLED(CONFIG_HYPERV)
>  static inline unsigned int hv_get_nested_reg(unsigned int reg)
>  {
> +	if (hv_is_sint_reg(reg))
> +		return reg - HV_REGISTER_SINT0 + HV_REGISTER_NESTED_SINT0;
> +
>  	switch (reg) {
>  	case HV_REGISTER_SIMP:
>  		return HV_REGISTER_NESTED_SIMP;
> @@ -53,8 +56,6 @@ static inline unsigned int hv_get_nested_reg(unsigned int reg)
>  		return HV_REGISTER_NESTED_SVERSION;
>  	case HV_REGISTER_SCONTROL:
>  		return HV_REGISTER_NESTED_SCONTROL;
> -	case HV_REGISTER_SINT0:
> -		return HV_REGISTER_NESTED_SINT0;
>  	case HV_REGISTER_EOM:
>  		return HV_REGISTER_NESTED_EOM;
>  	default:
> @@ -80,8 +81,7 @@ void hv_set_non_nested_register(unsigned int reg, u64 value)
>  		hv_ghcb_msr_write(reg, value);
>  
>  		/* Write proxy bit via wrmsl instruction */
> -		if (reg >= HV_REGISTER_SINT0 &&
> -		    reg <= HV_REGISTER_SINT15)
> +		if (hv_is_sint_reg(reg))
>  			wrmsrl(reg, value | 1 << 20);
>  	} else {
>  		wrmsrl(reg, value);
> -- 
> 2.25.1
> 

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

* Re: [PATCH] x86/hyperv: Fix hv_get/set_register for nested bringup
  2023-02-13 14:28 ` Wei Liu
@ 2023-02-14 22:17   ` Nuno Das Neves
  2023-02-14 23:05     ` Wei Liu
  2023-02-15 16:35   ` Jinank Jain
  1 sibling, 1 reply; 7+ messages in thread
From: Nuno Das Neves @ 2023-02-14 22:17 UTC (permalink / raw)
  To: Wei Liu
  Cc: linux-hyperv, linux-kernel, x86, jinankjain, mikelley, kys,
	Tianyu.Lan, haiyangz, decui, tglx, mingo, bp, dave.hansen, hpa

On 2/13/2023 6:28 AM, Wei Liu wrote:
> A few comments on style.
> 
> On Thu, Feb 09, 2023 at 02:02:52PM -0800, Nuno Das Neves wrote:
>> hv_get_nested_reg only translates SINT0, resulting in the wrong sint
>> being registered by nested vmbus.
> 
> Please put a blank line between paragraphs.
> 

Ok

>> Fix the issue with new utility function hv_is_sint_reg.
>> While at it, improve clarity of hv_set_non_nested_register and hv_is_synic_reg.
>>
>> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
>> ---
>>  arch/x86/include/asm/mshyperv.h | 11 +++++++----
>>  arch/x86/kernel/cpu/mshyperv.c  |  8 ++++----
>>  2 files changed, 11 insertions(+), 8 deletions(-)
>>
>> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
>> index 9ae1a344536b..684c547c1cca 100644
>> --- a/arch/x86/include/asm/mshyperv.h
>> +++ b/arch/x86/include/asm/mshyperv.h
>> @@ -225,10 +225,13 @@ extern bool hv_isolation_type_snp(void);
>>  
>>  static inline bool hv_is_synic_reg(unsigned int reg)
>>  {
>> -	if ((reg >= HV_REGISTER_SCONTROL) &&
>> -	    (reg <= HV_REGISTER_SINT15))
>> -		return true;
>> -	return false;
>> +	return (reg >= HV_REGISTER_SCONTROL) &&
>> +	       (reg <= HV_REGISTER_SINT15);
>> +}
> 
> Please put a new line here.
> 

Ok

> I can fix these issues too if you don't end up sending a new version due
> to other issues.
> 
> Jinank, please take a look. The code looks sensible to me, but I would
> like you to have a look too.
> 

I'll wait for Jinank to take a look before posting another version...


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

* Re: [PATCH] x86/hyperv: Fix hv_get/set_register for nested bringup
  2023-02-14 22:17   ` Nuno Das Neves
@ 2023-02-14 23:05     ` Wei Liu
  0 siblings, 0 replies; 7+ messages in thread
From: Wei Liu @ 2023-02-14 23:05 UTC (permalink / raw)
  To: Nuno Das Neves
  Cc: Wei Liu, linux-hyperv, linux-kernel, x86, jinankjain, mikelley,
	kys, Tianyu.Lan, haiyangz, decui, tglx, mingo, bp, dave.hansen,
	hpa

On Tue, Feb 14, 2023 at 02:17:52PM -0800, Nuno Das Neves wrote:
> On 2/13/2023 6:28 AM, Wei Liu wrote:
> > A few comments on style.
> > 
> > On Thu, Feb 09, 2023 at 02:02:52PM -0800, Nuno Das Neves wrote:
> >> hv_get_nested_reg only translates SINT0, resulting in the wrong sint
> >> being registered by nested vmbus.
> > 
> > Please put a blank line between paragraphs.
> > 
> 
> Ok
> 
> >> Fix the issue with new utility function hv_is_sint_reg.
> >> While at it, improve clarity of hv_set_non_nested_register and hv_is_synic_reg.
> >>
> >> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
> >> ---
> >>  arch/x86/include/asm/mshyperv.h | 11 +++++++----
> >>  arch/x86/kernel/cpu/mshyperv.c  |  8 ++++----
> >>  2 files changed, 11 insertions(+), 8 deletions(-)
> >>
> >> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
> >> index 9ae1a344536b..684c547c1cca 100644
> >> --- a/arch/x86/include/asm/mshyperv.h
> >> +++ b/arch/x86/include/asm/mshyperv.h
> >> @@ -225,10 +225,13 @@ extern bool hv_isolation_type_snp(void);
> >>  
> >>  static inline bool hv_is_synic_reg(unsigned int reg)
> >>  {
> >> -	if ((reg >= HV_REGISTER_SCONTROL) &&
> >> -	    (reg <= HV_REGISTER_SINT15))
> >> -		return true;
> >> -	return false;
> >> +	return (reg >= HV_REGISTER_SCONTROL) &&
> >> +	       (reg <= HV_REGISTER_SINT15);
> >> +}
> > 
> > Please put a new line here.
> > 
> 
> Ok
> 
> > I can fix these issues too if you don't end up sending a new version due
> > to other issues.
> > 
> > Jinank, please take a look. The code looks sensible to me, but I would
> > like you to have a look too.
> > 
> 
> I'll wait for Jinank to take a look before posting another version...
> 

If Jinank is happy with the change, I can just fix things up for you
before I commit this patch.

Wei.

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

* Re: [PATCH] x86/hyperv: Fix hv_get/set_register for nested bringup
  2023-02-13 14:28 ` Wei Liu
  2023-02-14 22:17   ` Nuno Das Neves
@ 2023-02-15 16:35   ` Jinank Jain
  2023-02-15 22:07     ` Nuno Das Neves
  1 sibling, 1 reply; 7+ messages in thread
From: Jinank Jain @ 2023-02-15 16:35 UTC (permalink / raw)
  To: Wei Liu, Nuno Das Neves
  Cc: linux-hyperv, linux-kernel, x86, mikelley, kys, Tianyu.Lan,
	haiyangz, decui, tglx, mingo, bp, dave.hansen, hpa

The patch looks good to me, apart from the comments from Wei regarding 
styling.

On 2/13/2023 7:58 PM, Wei Liu wrote:
> A few comments on style.
>
> On Thu, Feb 09, 2023 at 02:02:52PM -0800, Nuno Das Neves wrote:
>> hv_get_nested_reg only translates SINT0, resulting in the wrong sint
>> being registered by nested vmbus.
> Please put a blank line between paragraphs.
>
>> Fix the issue with new utility function hv_is_sint_reg.
>> While at it, improve clarity of hv_set_non_nested_register and hv_is_synic_reg.
>>
>> Signed-off-by: Nuno Das Neves <nunodasneves@linux.microsoft.com>
>> ---
>>   arch/x86/include/asm/mshyperv.h | 11 +++++++----
>>   arch/x86/kernel/cpu/mshyperv.c  |  8 ++++----
>>   2 files changed, 11 insertions(+), 8 deletions(-)
>>
>> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
>> index 9ae1a344536b..684c547c1cca 100644
>> --- a/arch/x86/include/asm/mshyperv.h
>> +++ b/arch/x86/include/asm/mshyperv.h
>> @@ -225,10 +225,13 @@ extern bool hv_isolation_type_snp(void);
>>   
>>   static inline bool hv_is_synic_reg(unsigned int reg)
>>   {
>> -	if ((reg >= HV_REGISTER_SCONTROL) &&
>> -	    (reg <= HV_REGISTER_SINT15))
>> -		return true;
>> -	return false;
>> +	return (reg >= HV_REGISTER_SCONTROL) &&
>> +	       (reg <= HV_REGISTER_SINT15);
>> +}
> Please put a new line here.
>
> I can fix these issues too if you don't end up sending a new version due
> to other issues.
>
> Jinank, please take a look. The code looks sensible to me, but I would
> like you to have a look too.
>
> Thanks,
> Wei.
>
>> +static inline bool hv_is_sint_reg(unsigned int reg)
>> +{
>> +	return (reg >= HV_REGISTER_SINT0) &&
>> +	       (reg <= HV_REGISTER_SINT15);
>>   }
>>   
>>   u64 hv_get_register(unsigned int reg);
>> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
>> index 0ceb6d1f9c3c..6bd344e1200f 100644
>> --- a/arch/x86/kernel/cpu/mshyperv.c
>> +++ b/arch/x86/kernel/cpu/mshyperv.c
>> @@ -44,6 +44,9 @@ struct ms_hyperv_info ms_hyperv;
>>   #if IS_ENABLED(CONFIG_HYPERV)
>>   static inline unsigned int hv_get_nested_reg(unsigned int reg)
>>   {
>> +	if (hv_is_sint_reg(reg))
>> +		return reg - HV_REGISTER_SINT0 + HV_REGISTER_NESTED_SINT0;
>> +
>>   	switch (reg) {
>>   	case HV_REGISTER_SIMP:
>>   		return HV_REGISTER_NESTED_SIMP;
>> @@ -53,8 +56,6 @@ static inline unsigned int hv_get_nested_reg(unsigned int reg)
>>   		return HV_REGISTER_NESTED_SVERSION;
>>   	case HV_REGISTER_SCONTROL:
>>   		return HV_REGISTER_NESTED_SCONTROL;
>> -	case HV_REGISTER_SINT0:
>> -		return HV_REGISTER_NESTED_SINT0;
>>   	case HV_REGISTER_EOM:
>>   		return HV_REGISTER_NESTED_EOM;
>>   	default:
>> @@ -80,8 +81,7 @@ void hv_set_non_nested_register(unsigned int reg, u64 value)
>>   		hv_ghcb_msr_write(reg, value);
>>   
>>   		/* Write proxy bit via wrmsl instruction */
>> -		if (reg >= HV_REGISTER_SINT0 &&
>> -		    reg <= HV_REGISTER_SINT15)
>> +		if (hv_is_sint_reg(reg))
>>   			wrmsrl(reg, value | 1 << 20);
>>   	} else {
>>   		wrmsrl(reg, value);
>> -- 
>> 2.25.1

Reviewed-by: Jinank Jain <jinankjain@linux.microsoft.com>


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

* Re: [PATCH] x86/hyperv: Fix hv_get/set_register for nested bringup
  2023-02-15 16:35   ` Jinank Jain
@ 2023-02-15 22:07     ` Nuno Das Neves
  2023-02-16 14:33       ` Wei Liu
  0 siblings, 1 reply; 7+ messages in thread
From: Nuno Das Neves @ 2023-02-15 22:07 UTC (permalink / raw)
  To: Jinank Jain, Wei Liu
  Cc: linux-hyperv, linux-kernel, x86, mikelley, kys, Tianyu.Lan,
	haiyangz, decui, tglx, mingo, bp, dave.hansen, hpa

On 2/15/2023 8:35 AM, Jinank Jain wrote:
> The patch looks good to me, apart from the comments from Wei regarding styling.
> 
[..]
> On 2/13/2023 7:58 PM, Wei Liu wrote:
>>
>> I can fix these issues too if you don't end up sending a new version due
>> to other issues.
>>

Wei, feel free to fix the issues when you commit the patch.

Thanks
Nuno

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

* Re: [PATCH] x86/hyperv: Fix hv_get/set_register for nested bringup
  2023-02-15 22:07     ` Nuno Das Neves
@ 2023-02-16 14:33       ` Wei Liu
  0 siblings, 0 replies; 7+ messages in thread
From: Wei Liu @ 2023-02-16 14:33 UTC (permalink / raw)
  To: Nuno Das Neves
  Cc: Jinank Jain, Wei Liu, linux-hyperv, linux-kernel, x86, mikelley,
	kys, Tianyu.Lan, haiyangz, decui, tglx, mingo, bp, dave.hansen,
	hpa

On Wed, Feb 15, 2023 at 02:07:13PM -0800, Nuno Das Neves wrote:
> On 2/15/2023 8:35 AM, Jinank Jain wrote:
> > The patch looks good to me, apart from the comments from Wei regarding styling.
> > 
> [..]
> > On 2/13/2023 7:58 PM, Wei Liu wrote:
> >>
> >> I can fix these issues too if you don't end up sending a new version due
> >> to other issues.
> >>
> 
> Wei, feel free to fix the issues when you commit the patch.
> 

Fixed and applied.

Thanks,
Wei.

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

end of thread, other threads:[~2023-02-16 14:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-09 22:02 [PATCH] x86/hyperv: Fix hv_get/set_register for nested bringup Nuno Das Neves
2023-02-13 14:28 ` Wei Liu
2023-02-14 22:17   ` Nuno Das Neves
2023-02-14 23:05     ` Wei Liu
2023-02-15 16:35   ` Jinank Jain
2023-02-15 22:07     ` Nuno Das Neves
2023-02-16 14:33       ` Wei Liu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.