2020-11-05 17:04:09

by Wei Liu

[permalink] [raw]
Subject: [PATCH v2 02/17] x86/hyperv: detect if Linux is the root partition

For now we can use the privilege flag to check. Stash the value to be
used later.

Put in a bunch of defines for future use when we want to have more
fine-grained detection.

Signed-off-by: Wei Liu <[email protected]>
---
arch/x86/hyperv/hv_init.c | 4 ++++
arch/x86/include/asm/hyperv-tlfs.h | 10 ++++++++++
arch/x86/include/asm/mshyperv.h | 2 ++
arch/x86/kernel/cpu/mshyperv.c | 16 ++++++++++++++++
4 files changed, 32 insertions(+)

diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
index e04d90af4c27..533fe9e887f2 100644
--- a/arch/x86/hyperv/hv_init.c
+++ b/arch/x86/hyperv/hv_init.c
@@ -26,6 +26,10 @@
#include <linux/syscore_ops.h>
#include <clocksource/hyperv_timer.h>

+/* Is Linux running as the root partition? */
+bool hv_root_partition;
+EXPORT_SYMBOL_GPL(hv_root_partition);
+
void *hv_hypercall_pg;
EXPORT_SYMBOL_GPL(hv_hypercall_pg);

diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h
index 0ed20e8bba9e..41b628b9fb15 100644
--- a/arch/x86/include/asm/hyperv-tlfs.h
+++ b/arch/x86/include/asm/hyperv-tlfs.h
@@ -21,6 +21,7 @@
#define HYPERV_CPUID_FEATURES 0x40000003
#define HYPERV_CPUID_ENLIGHTMENT_INFO 0x40000004
#define HYPERV_CPUID_IMPLEMENT_LIMITS 0x40000005
+#define HYPERV_CPUID_CPU_MANAGEMENT_FEATURES 0x40000007
#define HYPERV_CPUID_NESTED_FEATURES 0x4000000A

#define HYPERV_HYPERVISOR_PRESENT_BIT 0x80000000
@@ -103,6 +104,15 @@
/* Recommend using enlightened VMCS */
#define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED BIT(14)

+/*
+ * CPU management features identification.
+ * These are HYPERV_CPUID_CPU_MANAGEMENT_FEATURES.EAX bits.
+ */
+#define HV_X64_START_LOGICAL_PROCESSOR BIT(0)
+#define HV_X64_CREATE_ROOT_VIRTUAL_PROCESSOR BIT(1)
+#define HV_X64_PERFORMANCE_COUNTER_SYNC BIT(2)
+#define HV_X64_RESERVED_IDENTITY_BIT BIT(31)
+
/*
* Virtual processor will never share a physical core with another virtual
* processor, except for virtual processors that are reported as sibling SMT
diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
index ffc289992d1b..ac2b0d110f03 100644
--- a/arch/x86/include/asm/mshyperv.h
+++ b/arch/x86/include/asm/mshyperv.h
@@ -237,6 +237,8 @@ int hyperv_fill_flush_guest_mapping_list(
struct hv_guest_mapping_flush_list *flush,
u64 start_gfn, u64 end_gfn);

+extern bool hv_root_partition;
+
#ifdef CONFIG_X86_64
void hv_apic_init(void);
void __init hv_init_spinlocks(void);
diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
index 05ef1f4550cb..f7633e1e4c82 100644
--- a/arch/x86/kernel/cpu/mshyperv.c
+++ b/arch/x86/kernel/cpu/mshyperv.c
@@ -237,6 +237,22 @@ static void __init ms_hyperv_init_platform(void)
pr_debug("Hyper-V: max %u virtual processors, %u logical processors\n",
ms_hyperv.max_vp_index, ms_hyperv.max_lp_index);

+ /*
+ * Check CPU management privilege.
+ *
+ * To mirror what Windows does we should extract CPU management
+ * features and use the ReservedIdentityBit to detect if Linux is the
+ * root partition. But that requires negotiating CPU management
+ * interface (a process to be finalized).
+ *
+ * For now, use the privilege flag as the indicator for running as
+ * root.
+ */
+ if (cpuid_ebx(HYPERV_CPUID_FEATURES) & HV_CPU_MANAGEMENT) {
+ hv_root_partition = true;
+ pr_info("Hyper-V: running as root partition\n");
+ }
+
/*
* Extract host information.
*/
--
2.20.1


2020-11-05 19:18:44

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v2 02/17] x86/hyperv: detect if Linux is the root partition

Hi Wei,

I love your patch! Yet something to improve:

[auto build test ERROR on tip/x86/core]
[also build test ERROR on asm-generic/master iommu/next tip/timers/core pci/next linus/master v5.10-rc2 next-20201105]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/Wei-Liu/Introducing-Linux-root-partition-support-for-Microsoft-Hypervisor/20201106-010058
base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 238c91115cd05c71447ea071624a4c9fe661f970
config: x86_64-randconfig-m001-20201104 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/3984ce0be67e74b8945288f1751a91615459f75e
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Wei-Liu/Introducing-Linux-root-partition-support-for-Microsoft-Hypervisor/20201106-010058
git checkout 3984ce0be67e74b8945288f1751a91615459f75e
# save the attached .config to linux build tree
make W=1 ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

arch/x86/kernel/cpu/mshyperv.c: In function 'ms_hyperv_init_platform':
>> arch/x86/kernel/cpu/mshyperv.c:247:3: error: 'hv_root_partition' undeclared (first use in this function); did you mean 'blk_drop_partitions'?
247 | hv_root_partition = true;
| ^~~~~~~~~~~~~~~~~
| blk_drop_partitions
arch/x86/kernel/cpu/mshyperv.c:247:3: note: each undeclared identifier is reported only once for each function it appears in

vim +247 arch/x86/kernel/cpu/mshyperv.c

218
219 /*
220 * Extract the features and hints
221 */
222 ms_hyperv.features = cpuid_eax(HYPERV_CPUID_FEATURES);
223 ms_hyperv.misc_features = cpuid_edx(HYPERV_CPUID_FEATURES);
224 ms_hyperv.hints = cpuid_eax(HYPERV_CPUID_ENLIGHTMENT_INFO);
225
226 pr_info("Hyper-V: features 0x%x, hints 0x%x, misc 0x%x\n",
227 ms_hyperv.features, ms_hyperv.hints, ms_hyperv.misc_features);
228
229 ms_hyperv.max_vp_index = cpuid_eax(HYPERV_CPUID_IMPLEMENT_LIMITS);
230 ms_hyperv.max_lp_index = cpuid_ebx(HYPERV_CPUID_IMPLEMENT_LIMITS);
231
232 pr_debug("Hyper-V: max %u virtual processors, %u logical processors\n",
233 ms_hyperv.max_vp_index, ms_hyperv.max_lp_index);
234
235 /*
236 * Check CPU management privilege.
237 *
238 * To mirror what Windows does we should extract CPU management
239 * features and use the ReservedIdentityBit to detect if Linux is the
240 * root partition. But that requires negotiating CPU management
241 * interface (a process to be finalized).
242 *
243 * For now, use the privilege flag as the indicator for running as
244 * root.
245 */
246 if (cpuid_ebx(HYPERV_CPUID_FEATURES) & HV_CPU_MANAGEMENT) {
> 247 hv_root_partition = true;
248 pr_info("Hyper-V: running as root partition\n");
249 }
250
251 /*
252 * Extract host information.
253 */
254 if (cpuid_eax(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS) >=
255 HYPERV_CPUID_VERSION) {
256 hv_host_info_eax = cpuid_eax(HYPERV_CPUID_VERSION);
257 hv_host_info_ebx = cpuid_ebx(HYPERV_CPUID_VERSION);
258 hv_host_info_ecx = cpuid_ecx(HYPERV_CPUID_VERSION);
259 hv_host_info_edx = cpuid_edx(HYPERV_CPUID_VERSION);
260
261 pr_info("Hyper-V Host Build:%d-%d.%d-%d-%d.%d\n",
262 hv_host_info_eax, hv_host_info_ebx >> 16,
263 hv_host_info_ebx & 0xFFFF, hv_host_info_ecx,
264 hv_host_info_edx >> 24, hv_host_info_edx & 0xFFFFFF);
265 }
266
267 if (ms_hyperv.features & HV_X64_ACCESS_FREQUENCY_MSRS &&
268 ms_hyperv.misc_features & HV_FEATURE_FREQUENCY_MSRS_AVAILABLE) {
269 x86_platform.calibrate_tsc = hv_get_tsc_khz;
270 x86_platform.calibrate_cpu = hv_get_tsc_khz;
271 }
272
273 if (ms_hyperv.hints & HV_X64_ENLIGHTENED_VMCS_RECOMMENDED) {
274 ms_hyperv.nested_features =
275 cpuid_eax(HYPERV_CPUID_NESTED_FEATURES);
276 }
277
278 /*
279 * Hyper-V expects to get crash register data or kmsg when
280 * crash enlightment is available and system crashes. Set
281 * crash_kexec_post_notifiers to be true to make sure that
282 * calling crash enlightment interface before running kdump
283 * kernel.
284 */
285 if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE)
286 crash_kexec_post_notifiers = true;
287

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (4.88 kB)
.config.gz (29.75 kB)
Download all attachments

2020-11-05 20:26:11

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH v2 02/17] x86/hyperv: detect if Linux is the root partition

Hi Wei,

I love your patch! Yet something to improve:

[auto build test ERROR on tip/x86/core]
[also build test ERROR on asm-generic/master iommu/next tip/timers/core pci/next linus/master v5.10-rc2 next-20201105]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url: https://github.com/0day-ci/linux/commits/Wei-Liu/Introducing-Linux-root-partition-support-for-Microsoft-Hypervisor/20201106-010058
base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 238c91115cd05c71447ea071624a4c9fe661f970
config: x86_64-randconfig-a004-20201104 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 09ec07827b1128504457a93dee80b2ceee1af600)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/3984ce0be67e74b8945288f1751a91615459f75e
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Wei-Liu/Introducing-Linux-root-partition-support-for-Microsoft-Hypervisor/20201106-010058
git checkout 3984ce0be67e74b8945288f1751a91615459f75e
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

>> arch/x86/kernel/cpu/mshyperv.c:247:3: error: use of undeclared identifier 'hv_root_partition'
hv_root_partition = true;
^
1 error generated.

vim +/hv_root_partition +247 arch/x86/kernel/cpu/mshyperv.c

218
219 /*
220 * Extract the features and hints
221 */
222 ms_hyperv.features = cpuid_eax(HYPERV_CPUID_FEATURES);
223 ms_hyperv.misc_features = cpuid_edx(HYPERV_CPUID_FEATURES);
224 ms_hyperv.hints = cpuid_eax(HYPERV_CPUID_ENLIGHTMENT_INFO);
225
226 pr_info("Hyper-V: features 0x%x, hints 0x%x, misc 0x%x\n",
227 ms_hyperv.features, ms_hyperv.hints, ms_hyperv.misc_features);
228
229 ms_hyperv.max_vp_index = cpuid_eax(HYPERV_CPUID_IMPLEMENT_LIMITS);
230 ms_hyperv.max_lp_index = cpuid_ebx(HYPERV_CPUID_IMPLEMENT_LIMITS);
231
232 pr_debug("Hyper-V: max %u virtual processors, %u logical processors\n",
233 ms_hyperv.max_vp_index, ms_hyperv.max_lp_index);
234
235 /*
236 * Check CPU management privilege.
237 *
238 * To mirror what Windows does we should extract CPU management
239 * features and use the ReservedIdentityBit to detect if Linux is the
240 * root partition. But that requires negotiating CPU management
241 * interface (a process to be finalized).
242 *
243 * For now, use the privilege flag as the indicator for running as
244 * root.
245 */
246 if (cpuid_ebx(HYPERV_CPUID_FEATURES) & HV_CPU_MANAGEMENT) {
> 247 hv_root_partition = true;
248 pr_info("Hyper-V: running as root partition\n");
249 }
250
251 /*
252 * Extract host information.
253 */
254 if (cpuid_eax(HYPERV_CPUID_VENDOR_AND_MAX_FUNCTIONS) >=
255 HYPERV_CPUID_VERSION) {
256 hv_host_info_eax = cpuid_eax(HYPERV_CPUID_VERSION);
257 hv_host_info_ebx = cpuid_ebx(HYPERV_CPUID_VERSION);
258 hv_host_info_ecx = cpuid_ecx(HYPERV_CPUID_VERSION);
259 hv_host_info_edx = cpuid_edx(HYPERV_CPUID_VERSION);
260
261 pr_info("Hyper-V Host Build:%d-%d.%d-%d-%d.%d\n",
262 hv_host_info_eax, hv_host_info_ebx >> 16,
263 hv_host_info_ebx & 0xFFFF, hv_host_info_ecx,
264 hv_host_info_edx >> 24, hv_host_info_edx & 0xFFFFFF);
265 }
266
267 if (ms_hyperv.features & HV_X64_ACCESS_FREQUENCY_MSRS &&
268 ms_hyperv.misc_features & HV_FEATURE_FREQUENCY_MSRS_AVAILABLE) {
269 x86_platform.calibrate_tsc = hv_get_tsc_khz;
270 x86_platform.calibrate_cpu = hv_get_tsc_khz;
271 }
272
273 if (ms_hyperv.hints & HV_X64_ENLIGHTENED_VMCS_RECOMMENDED) {
274 ms_hyperv.nested_features =
275 cpuid_eax(HYPERV_CPUID_NESTED_FEATURES);
276 }
277
278 /*
279 * Hyper-V expects to get crash register data or kmsg when
280 * crash enlightment is available and system crashes. Set
281 * crash_kexec_post_notifiers to be true to make sure that
282 * calling crash enlightment interface before running kdump
283 * kernel.
284 */
285 if (ms_hyperv.misc_features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE)
286 crash_kexec_post_notifiers = true;
287

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (5.01 kB)
.config.gz (36.07 kB)
Download all attachments

2020-11-12 11:46:08

by Wei Liu

[permalink] [raw]
Subject: Re: [PATCH v2 02/17] x86/hyperv: detect if Linux is the root partition

On Fri, Nov 06, 2020 at 03:16:07AM +0800, kernel test robot wrote:
> Hi Wei,
>
> I love your patch! Yet something to improve:
>
> [auto build test ERROR on tip/x86/core]
> [also build test ERROR on asm-generic/master iommu/next tip/timers/core pci/next linus/master v5.10-rc2 next-20201105]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch]
>

This report is incorrect.

The bot seems to have only picked up this one patch but not the whole
series. While the patch can apply cleanly to all those trees, it has a
dependency on an earlier patch in this series.

Wei.

2020-11-12 11:49:14

by Wei Liu

[permalink] [raw]
Subject: Re: [PATCH v2 02/17] x86/hyperv: detect if Linux is the root partition

On Thu, Nov 12, 2020 at 11:42:15AM +0000, Wei Liu wrote:
> On Fri, Nov 06, 2020 at 03:16:07AM +0800, kernel test robot wrote:
> > Hi Wei,
> >
> > I love your patch! Yet something to improve:
> >
> > [auto build test ERROR on tip/x86/core]
> > [also build test ERROR on asm-generic/master iommu/next tip/timers/core pci/next linus/master v5.10-rc2 next-20201105]
> > [If your patch is applied to the wrong git tree, kindly drop us a note.
> > And when submitting patch, we suggest to use '--base' as documented in
> > https://git-scm.com/docs/git-format-patch]
> >
>
> This report is incorrect.
>
> The bot seems to have only picked up this one patch but not the whole
> series. While the patch can apply cleanly to all those trees, it has a
> dependency on an earlier patch in this series.

I misread this report and I'm confused now. Let me fetch the config and
try locally first.

Wei.

2020-11-12 12:27:29

by Wei Liu

[permalink] [raw]
Subject: Re: [PATCH v2 02/17] x86/hyperv: detect if Linux is the root partition

On Thu, Nov 12, 2020 at 11:46:41AM +0000, Wei Liu wrote:
> On Thu, Nov 12, 2020 at 11:42:15AM +0000, Wei Liu wrote:
> > On Fri, Nov 06, 2020 at 03:16:07AM +0800, kernel test robot wrote:
> > > Hi Wei,
> > >
> > > I love your patch! Yet something to improve:
> > >
> > > [auto build test ERROR on tip/x86/core]
> > > [also build test ERROR on asm-generic/master iommu/next tip/timers/core pci/next linus/master v5.10-rc2 next-20201105]
> > > [If your patch is applied to the wrong git tree, kindly drop us a note.
> > > And when submitting patch, we suggest to use '--base' as documented in
> > > https://git-scm.com/docs/git-format-patch]
> > >
> >
> > This report is incorrect.
> >
> > The bot seems to have only picked up this one patch but not the whole
> > series. While the patch can apply cleanly to all those trees, it has a
> > dependency on an earlier patch in this series.
>
> I misread this report and I'm confused now. Let me fetch the config and
> try locally first.

The attached config file has

# CONFIG_HYPERV is not set
.

The reported issue has been fixed by moving hv_root_partition to
mshyperv.c.

Wei.

2020-11-12 15:18:35

by Vitaly Kuznetsov

[permalink] [raw]
Subject: Re: [PATCH v2 02/17] x86/hyperv: detect if Linux is the root partition

Wei Liu <[email protected]> writes:

> For now we can use the privilege flag to check. Stash the value to be
> used later.
>
> Put in a bunch of defines for future use when we want to have more
> fine-grained detection.
>
> Signed-off-by: Wei Liu <[email protected]>
> ---
> arch/x86/hyperv/hv_init.c | 4 ++++
> arch/x86/include/asm/hyperv-tlfs.h | 10 ++++++++++
> arch/x86/include/asm/mshyperv.h | 2 ++
> arch/x86/kernel/cpu/mshyperv.c | 16 ++++++++++++++++
> 4 files changed, 32 insertions(+)
>
> diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c
> index e04d90af4c27..533fe9e887f2 100644
> --- a/arch/x86/hyperv/hv_init.c
> +++ b/arch/x86/hyperv/hv_init.c
> @@ -26,6 +26,10 @@
> #include <linux/syscore_ops.h>
> #include <clocksource/hyperv_timer.h>
>
> +/* Is Linux running as the root partition? */
> +bool hv_root_partition;
> +EXPORT_SYMBOL_GPL(hv_root_partition);

(Nitpick and rather a personal preference): I'd prefer
'hv_partition_is_root' for a boolean.

> +
> void *hv_hypercall_pg;
> EXPORT_SYMBOL_GPL(hv_hypercall_pg);
>
> diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h
> index 0ed20e8bba9e..41b628b9fb15 100644
> --- a/arch/x86/include/asm/hyperv-tlfs.h
> +++ b/arch/x86/include/asm/hyperv-tlfs.h
> @@ -21,6 +21,7 @@
> #define HYPERV_CPUID_FEATURES 0x40000003
> #define HYPERV_CPUID_ENLIGHTMENT_INFO 0x40000004
> #define HYPERV_CPUID_IMPLEMENT_LIMITS 0x40000005
> +#define HYPERV_CPUID_CPU_MANAGEMENT_FEATURES 0x40000007
> #define HYPERV_CPUID_NESTED_FEATURES 0x4000000A
>
> #define HYPERV_HYPERVISOR_PRESENT_BIT 0x80000000
> @@ -103,6 +104,15 @@
> /* Recommend using enlightened VMCS */
> #define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED BIT(14)
>
> +/*
> + * CPU management features identification.
> + * These are HYPERV_CPUID_CPU_MANAGEMENT_FEATURES.EAX bits.
> + */
> +#define HV_X64_START_LOGICAL_PROCESSOR BIT(0)
> +#define HV_X64_CREATE_ROOT_VIRTUAL_PROCESSOR BIT(1)
> +#define HV_X64_PERFORMANCE_COUNTER_SYNC BIT(2)
> +#define HV_X64_RESERVED_IDENTITY_BIT BIT(31)
> +
> /*
> * Virtual processor will never share a physical core with another virtual
> * processor, except for virtual processors that are reported as sibling SMT
> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
> index ffc289992d1b..ac2b0d110f03 100644
> --- a/arch/x86/include/asm/mshyperv.h
> +++ b/arch/x86/include/asm/mshyperv.h
> @@ -237,6 +237,8 @@ int hyperv_fill_flush_guest_mapping_list(
> struct hv_guest_mapping_flush_list *flush,
> u64 start_gfn, u64 end_gfn);
>
> +extern bool hv_root_partition;

Eventually this is not going to be an x86 only thing I believe?

> +
> #ifdef CONFIG_X86_64
> void hv_apic_init(void);
> void __init hv_init_spinlocks(void);
> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
> index 05ef1f4550cb..f7633e1e4c82 100644
> --- a/arch/x86/kernel/cpu/mshyperv.c
> +++ b/arch/x86/kernel/cpu/mshyperv.c
> @@ -237,6 +237,22 @@ static void __init ms_hyperv_init_platform(void)
> pr_debug("Hyper-V: max %u virtual processors, %u logical processors\n",
> ms_hyperv.max_vp_index, ms_hyperv.max_lp_index);
>
> + /*
> + * Check CPU management privilege.
> + *
> + * To mirror what Windows does we should extract CPU management
> + * features and use the ReservedIdentityBit to detect if Linux is the
> + * root partition. But that requires negotiating CPU management
> + * interface (a process to be finalized).
> + *
> + * For now, use the privilege flag as the indicator for running as
> + * root.
> + */
> + if (cpuid_ebx(HYPERV_CPUID_FEATURES) & HV_CPU_MANAGEMENT) {

We may want to cache cpuid_ebx(HYPERV_CPUID_FEATURES) somewhere but we
already had a discussion regading naming for these caches and decided to
wait until TLFS for ARM is out so we don't need to rename again.

> + hv_root_partition = true;
> + pr_info("Hyper-V: running as root partition\n");
> + }
> +
> /*
> * Extract host information.
> */

Reviewed-by: Vitaly Kuznetsov <[email protected]>

--
Vitaly

2020-11-12 15:55:18

by Wei Liu

[permalink] [raw]
Subject: Re: [PATCH v2 02/17] x86/hyperv: detect if Linux is the root partition

On Thu, Nov 12, 2020 at 04:16:30PM +0100, Vitaly Kuznetsov wrote:
[...]
> > /*
> > * Virtual processor will never share a physical core with another virtual
> > * processor, except for virtual processors that are reported as sibling SMT
> > diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
> > index ffc289992d1b..ac2b0d110f03 100644
> > --- a/arch/x86/include/asm/mshyperv.h
> > +++ b/arch/x86/include/asm/mshyperv.h
> > @@ -237,6 +237,8 @@ int hyperv_fill_flush_guest_mapping_list(
> > struct hv_guest_mapping_flush_list *flush,
> > u64 start_gfn, u64 end_gfn);
> >
> > +extern bool hv_root_partition;
>
> Eventually this is not going to be an x86 only thing I believe?

I hope so. :-)

>
> > +
> > #ifdef CONFIG_X86_64
> > void hv_apic_init(void);
> > void __init hv_init_spinlocks(void);
> > diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
> > index 05ef1f4550cb..f7633e1e4c82 100644
> > --- a/arch/x86/kernel/cpu/mshyperv.c
> > +++ b/arch/x86/kernel/cpu/mshyperv.c
> > @@ -237,6 +237,22 @@ static void __init ms_hyperv_init_platform(void)
> > pr_debug("Hyper-V: max %u virtual processors, %u logical processors\n",
> > ms_hyperv.max_vp_index, ms_hyperv.max_lp_index);
> >
> > + /*
> > + * Check CPU management privilege.
> > + *
> > + * To mirror what Windows does we should extract CPU management
> > + * features and use the ReservedIdentityBit to detect if Linux is the
> > + * root partition. But that requires negotiating CPU management
> > + * interface (a process to be finalized).
> > + *
> > + * For now, use the privilege flag as the indicator for running as
> > + * root.
> > + */
> > + if (cpuid_ebx(HYPERV_CPUID_FEATURES) & HV_CPU_MANAGEMENT) {
>
> We may want to cache cpuid_ebx(HYPERV_CPUID_FEATURES) somewhere but we
> already had a discussion regading naming for these caches and decided to
> wait until TLFS for ARM is out so we don't need to rename again.

Exactly.

Wei.