[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201113152152.omo6pljscvlrzpsc@liuwe-devbox-debian-v2>
Date: Fri, 13 Nov 2020 15:21:52 +0000
From: Wei Liu <wei.liu@...nel.org>
To: Vitaly Kuznetsov <vkuznets@...hat.com>
Cc: Wei Liu <wei.liu@...nel.org>,
Linux on Hyper-V List <linux-hyperv@...r.kernel.org>,
virtualization@...ts.linux-foundation.org,
Linux Kernel List <linux-kernel@...r.kernel.org>,
Michael Kelley <mikelley@...rosoft.com>,
Vineeth Pillai <viremana@...ux.microsoft.com>,
Sunil Muthuswamy <sunilmut@...rosoft.com>,
Nuno Das Neves <nunodasneves@...ux.microsoft.com>,
Lillian Grassin-Drake <ligrassi@...rosoft.com>,
"K. Y. Srinivasan" <kys@...rosoft.com>,
Haiyang Zhang <haiyangz@...rosoft.com>,
Stephen Hemminger <sthemmin@...rosoft.com>,
Thomas Gleixner <tglx@...utronix.de>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" <x86@...nel.org>,
"H. Peter Anvin" <hpa@...or.com>, Arnd Bergmann <arnd@...db.de>,
"open list:GENERIC INCLUDE/ASM HEADER FILES"
<linux-arch@...r.kernel.org>
Subject: Re: [PATCH v2 07/17] x86/hyperv: extract partition ID from Microsoft
Hypervisor if necessary
On Thu, Nov 12, 2020 at 04:44:39PM +0100, Vitaly Kuznetsov wrote:
[...]
> > +void __init hv_get_partition_id(void)
> > +{
> > + struct hv_get_partition_id *output_page;
> > + u16 status;
> > + unsigned long flags;
> > +
> > + local_irq_save(flags);
> > + output_page = *this_cpu_ptr(hyperv_pcpu_output_arg);
> > + status = hv_do_hypercall(HVCALL_GET_PARTITION_ID, NULL, output_page) &
> > + HV_HYPERCALL_RESULT_MASK;
> > + if (status != HV_STATUS_SUCCESS)
> > + pr_err("Failed to get partition ID: %d\n", status);
> > + else
> > + hv_current_partition_id = output_page->partition_id;
>
> Nit: I'd suggest we simplify this to:
>
> if (status != HV_STATUS_SUCCESS) {
> pr_err("Failed to get partition ID: %d\n", status);
> BUG();
> }
> hv_current_partition_id = output_page->partition_id;
>
> and drop BUG_ON() below;
>
> > + local_irq_restore(flags);
> > +
> > + /* No point in proceeding if this failed */
> > + BUG_ON(status != HV_STATUS_SUCCESS);
> > +}
> > +
> > /*
> > * This function is to be invoked early in the boot sequence after the
> > * hypervisor has been detected.
> > @@ -430,6 +453,9 @@ void __init hyperv_init(void)
> >
> > register_syscore_ops(&hv_syscore_ops);
> >
> > + if (hv_root_partition)
> > + hv_get_partition_id();
> > +
>
>
> We don't seem to check that the partition has AccessPartitionId
> privilege. While I guess that root partitions always have it, I'd
> suggest we write this as:
>
Yes. Root should always have that permission. That's my understanding.
> if (cpuid_ebx(HYPERV_CPUID_FEATURES) & HV_ACCESS_PARTITION_ID)
> hv_get_partition_id();
>
> BUG_ON(hv_root_partition && !hv_current_partition_id);
>
> for correctness. Also, we need to make sure '0' is not a valid partition
> id and use e.g. -1 otherwise.
>
I've changed both places.
Wei.
Powered by blists - more mailing lists