Skip to contentSkip to conversation

x86/hyperv: Fix hv_get/set_register for nested bringup

PATCH In review Nuno Das Neves 3 participants 7 messages Feb 9, 2023 – Feb 16, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hyperv: Fix hv_get/set_register for nested bringup

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.

---
 arch/x86/include/asm/mshyperv.h | 11 +++++++----
 arch/x86/kernel/cpu/mshyperv.c  |  8 ++++----
 2 files changed, 11 insertions(+), 8 deletions(-)
arch/x86/include/asm/mshyperv.h +7 -4
index 9ae1a344536b..684c547c1cca 100644
@@ -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);
arch/x86/kernel/cpu/mshyperv.c +4 -4
index 0ceb6d1f9c3c..6bd344e1200f 100644
@@ -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);
Signature · 1 line
2.25.1
maintainer
#1 lore raw

A few comments on style.

Quoted 2 lines · Nuno Das Neves

hv_get_nested_reg only translates SINT0, resulting in the wrong sint being registered by nested vmbus.

Please put a blank line between paragraphs.

Quoted 14 lines

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.

---
 arch/x86/include/asm/mshyperv.h | 11 +++++++----
 arch/x86/kernel/cpu/mshyperv.c  |  8 ++++----
 2 files changed, 11 insertions(+), 8 deletions(-)
arch/x86/include/asm/mshyperv.h +0 -0
index 9ae1a344536b..684c547c1cca 100644

arch/x86/include/asm/mshyperv.h extern bool hv_isolation_type_snp(void); · line 230

Quoted 10 lines
arch/x86/include/asm/mshyperv.h +3 -4
@@ -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.

Quoted 43 lines
arch/x86/include/asm/mshyperv.h +4 -0
+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);
arch/x86/kernel/cpu/mshyperv.c +4 -4
index 0ceb6d1f9c3c..6bd344e1200f 100644
@@ -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);
Signature · 1 line
2.25.1
#2 lore raw
Quoted 8 lines · Wei Liu

A few comments on style.

Quoted 2 lines · Nuno Das Neves

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

Quoted 15 lines
Quoted 15 lines

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.

---
 arch/x86/include/asm/mshyperv.h | 11 +++++++----
 arch/x86/kernel/cpu/mshyperv.c  |  8 ++++----
 2 files changed, 11 insertions(+), 8 deletions(-)
arch/x86/include/asm/mshyperv.h +0 -0
index 9ae1a344536b..684c547c1cca 100644
@@ -225,10 +225,13 @@ extern bool hv_isolation_type_snp(void);
 
Quoted 12 lines

arch/x86/include/asm/mshyperv.h extern bool hv_isolation_type_snp(void); · line 230

Quoted 9 lines
arch/x86/include/asm/mshyperv.h +3 -4
 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

Quoted 6 lines

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...

maintainer
#3 lore raw
Quoted 42 lines · Nuno Das Neves
Quoted 8 lines · Wei Liu

A few comments on style.

Quoted 2 lines · Nuno Das Neves

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

Quoted 15 lines
Quoted 15 lines

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.

---
 arch/x86/include/asm/mshyperv.h | 11 +++++++----
 arch/x86/kernel/cpu/mshyperv.c  |  8 ++++----
 2 files changed, 11 insertions(+), 8 deletions(-)
arch/x86/include/asm/mshyperv.h +0 -0
index 9ae1a344536b..684c547c1cca 100644
@@ -225,10 +225,13 @@ extern bool hv_isolation_type_snp(void);
 
Quoted 12 lines

arch/x86/include/asm/mshyperv.h extern bool hv_isolation_type_snp(void); · line 230

Quoted 9 lines
arch/x86/include/asm/mshyperv.h +3 -4
 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

Quoted 9 lines
Quoted 6 lines

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.

Reviewed-by
#4 lore raw
In reply to Wei Liu

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

Quoted 75 lines · Wei Liu

A few comments on style.

Quoted 2 lines · Nuno Das Neves

hv_get_nested_reg only translates SINT0, resulting in the wrong sint being registered by nested vmbus.

Please put a blank line between paragraphs.

Quoted 14 lines

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.

---
  arch/x86/include/asm/mshyperv.h | 11 +++++++----
  arch/x86/kernel/cpu/mshyperv.c  |  8 ++++----
  2 files changed, 11 insertions(+), 8 deletions(-)
arch/x86/include/asm/mshyperv.h +0 -0
index 9ae1a344536b..684c547c1cca 100644

arch/x86/include/asm/mshyperv.h extern bool hv_isolation_type_snp(void); · line 230

Quoted 10 lines
arch/x86/include/asm/mshyperv.h +3 -4
@@ -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.

Quoted 33 lines
arch/x86/include/asm/mshyperv.h +4 -0
+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);
arch/x86/kernel/cpu/mshyperv.c +3 -2
index 0ceb6d1f9c3c..6bd344e1200f 100644
@@ -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);
 
Quoted 9 lines
Quoted 9 lines
arch/x86/kernel/cpu/mshyperv.c +1 -2
  		/* 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);
Signature · 1 line
2.25.1
#5 lore raw
Quoted 2 lines · Jinank Jain

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

[..]

Quoted 5 lines · Wei Liu
Quoted 4 lines

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

maintainer
#6 lore raw
Quoted 12 lines · Nuno Das Neves
Quoted 2 lines · Jinank Jain

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

[..]

Quoted 5 lines · Wei Liu
Quoted 4 lines

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.