Re: [RFC PATCH V4 03/17] x86/hyperv: Set Virtual Trust Level in VMBus init message

From: Tianyu Lan
Date: Wed Apr 12 2023 - 23:29:56 EST


On 4/12/2023 10:24 PM, Michael Kelley (LINUX) wrote:
+static u8 __init get_vtl(void)
+{
+ u64 control = HV_HYPERCALL_REP_COMP_1 | HVCALL_GET_VP_REGISTERS;
+ struct hv_get_vp_registers_input *input;
+ struct hv_get_vp_registers_output *output;
+ u64 vtl = 0;
+ u64 ret;
+ unsigned long flags;
+
+ local_irq_save(flags);
+ input = *(struct hv_get_vp_registers_input **)this_cpu_ptr(hyperv_pcpu_input_arg);
The cast to struct hv_get_vp_registers_input isn't needed here. Just do:

input = *this_cpu_ptr(hyperv_pcpu_input_arg);

I know we have other code that references hyperv_pcpu_input_arg with a more
complicated code sequence, but it's really not necessary. At some point, we
should go back and clean those up, but let's not add any new cases. 😄


Hi Michael:
Thanks for your review. Yes, agree. I just follow the old coding style and will update.



+ output = (struct hv_get_vp_registers_output *)input;
+ if (!input) {
+ local_irq_restore(flags);
+ goto done;
+ }
+
+ memset(input, 0, sizeof(*input) + sizeof(input->element[0]));
Use struct_size() to calculate the size of a structure plus a trailing
variable size array.

+ input->header.partitionid = HV_PARTITION_ID_SELF;
+ input->header.vpindex = HV_VP_INDEX_SELF;
+ input->header.inputvtl = 0;
+ input->element[0].name0 = HV_X64_REGISTER_VSM_VP_STATUS;
+
+ ret = hv_do_hypercall(control, input, output);
+ if (hv_result_success(ret))
+ vtl = output->as64.low & HV_X64_VTL_MASK;
+ else
+ pr_err("Hyper-V: failed to get VTL!");
Let's include the hypercall status in the failure message. If a failure ever
happens, we will really want to know what that status is. 😄


Agree. Will update.

rv;
extern bool hv_nested;
@@ -58,6 +59,7 @@ extern void * __percpu *hyperv_pcpu_output_arg;
extern u64 hv_do_hypercall(u64 control, void *inputaddr, void *outputaddr);
extern u64 hv_do_fast_hypercall8(u16 control, u64 input8);
extern bool hv_isolation_type_snp(void);
+extern bool hv_isolation_type_en_snp(void);