Skip to content

Commit b14033a

Browse files
NunoDasNevesliuw
authored andcommitted
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. Signed-off-by: Nuno Das Neves <[email protected]> Reviewed-by: Jinank Jain <[email protected]> Link: https://lore.kernel.org/r/1675980172-6851-1-git-send-email-nunodasneves@linux.microsoft.com Signed-off-by: Wei Liu <[email protected]>
1 parent 96ec293 commit b14033a

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

arch/x86/include/asm/mshyperv.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,14 @@ extern bool hv_isolation_type_snp(void);
224224

225225
static inline bool hv_is_synic_reg(unsigned int reg)
226226
{
227-
if ((reg >= HV_REGISTER_SCONTROL) &&
228-
(reg <= HV_REGISTER_SINT15))
229-
return true;
230-
return false;
227+
return (reg >= HV_REGISTER_SCONTROL) &&
228+
(reg <= HV_REGISTER_SINT15);
229+
}
230+
231+
static inline bool hv_is_sint_reg(unsigned int reg)
232+
{
233+
return (reg >= HV_REGISTER_SINT0) &&
234+
(reg <= HV_REGISTER_SINT15);
231235
}
232236

233237
u64 hv_get_register(unsigned int reg);

arch/x86/kernel/cpu/mshyperv.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ struct ms_hyperv_info ms_hyperv;
4444
#if IS_ENABLED(CONFIG_HYPERV)
4545
static inline unsigned int hv_get_nested_reg(unsigned int reg)
4646
{
47+
if (hv_is_sint_reg(reg))
48+
return reg - HV_REGISTER_SINT0 + HV_REGISTER_NESTED_SINT0;
49+
4750
switch (reg) {
4851
case HV_REGISTER_SIMP:
4952
return HV_REGISTER_NESTED_SIMP;
@@ -53,8 +56,6 @@ static inline unsigned int hv_get_nested_reg(unsigned int reg)
5356
return HV_REGISTER_NESTED_SVERSION;
5457
case HV_REGISTER_SCONTROL:
5558
return HV_REGISTER_NESTED_SCONTROL;
56-
case HV_REGISTER_SINT0:
57-
return HV_REGISTER_NESTED_SINT0;
5859
case HV_REGISTER_EOM:
5960
return HV_REGISTER_NESTED_EOM;
6061
default:
@@ -80,8 +81,7 @@ void hv_set_non_nested_register(unsigned int reg, u64 value)
8081
hv_ghcb_msr_write(reg, value);
8182

8283
/* Write proxy bit via wrmsl instruction */
83-
if (reg >= HV_REGISTER_SINT0 &&
84-
reg <= HV_REGISTER_SINT15)
84+
if (hv_is_sint_reg(reg))
8585
wrmsrl(reg, value | 1 << 20);
8686
} else {
8787
wrmsrl(reg, value);

0 commit comments

Comments
 (0)