Skip to contentSkip to conversation

x86/hyperv: Add Write/Read MSR registers via ghcb page

bug report Dan Carpenter 2 participants 4 messages Jan 16, 2023 – Jan 17, 2023

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

Hello Tianyu Lan,

The patch faff44069ff5: "x86/hyperv: Add Write/Read MSR registers via ghcb page" from Oct 25, 2021, leads to the following Smatch static checker warning:

	arch/x86/kernel/cpu/mshyperv.c:73 hv_get_non_nested_register()
	error: uninitialized symbol 'value'.

arch/x86/kernel/cpu/mshyperv.c

    63 
    64 #if IS_ENABLED(CONFIG_HYPERV)
    65 u64 hv_get_non_nested_register(unsigned int reg)
    66 {
    67         u64 value;
    68 
    69         if (hv_is_synic_reg(reg) && hv_isolation_type_snp())
    70                 hv_ghcb_msr_read(reg, &value);
                                             ^^^^^^

There are three places in hv_ghcb_msr_read() which don't initialize value.

    71         else
    72                 rdmsrl(reg, value);
--> 73         return value;
    74 }

regards,
dan carpenter

#1 lore raw

Does making 0 as the default value makes sense?

Regards,

Jinank

Quoted 29 lines · Dan Carpenter

Hello Tianyu Lan,

The patch faff44069ff5: "x86/hyperv: Add Write/Read MSR registers via ghcb page" from Oct 25, 2021, leads to the following Smatch static checker warning:

	arch/x86/kernel/cpu/mshyperv.c:73 hv_get_non_nested_register()
	error: uninitialized symbol 'value'.

arch/x86/kernel/cpu/mshyperv.c

     63
     64 #if IS_ENABLED(CONFIG_HYPERV)
     65 u64 hv_get_non_nested_register(unsigned int reg)
     66 {
     67         u64 value;
     68
     69         if (hv_is_synic_reg(reg) && hv_isolation_type_snp())
     70                 hv_ghcb_msr_read(reg, &value);
                                              ^^^^^^

There are three places in hv_ghcb_msr_read() which don't initialize value.

     71         else
     72                 rdmsrl(reg, value);
--> 73         return value;
     74 }

regards,
dan carpenter

#2 lore raw
Quoted 2 lines · Jinank Jain

Does making 0 as the default value makes sense?

That would silence the warning, and most distros are going to enable the config to zero it out anyway so it has no impact on runtime.

regards,
dan carpenter

#3 lore raw
Quoted 6 lines · Dan Carpenter
Quoted 2 lines · Jinank Jain

Does making 0 as the default value makes sense?

That would silence the warning, and most distros are going to enable the config to zero it out anyway so it has no impact on runtime.

The config to zero out stack variables. CONFIG_INIT_STACK_ALL_ZERO.

regards,
dan carpenter