From: Anirudh Rayabharam <anrayabh@linux.microsoft.com>
To: Jinank Jain <jinankjain@linux.microsoft.com>
Cc: jinankjain@microsoft.com, kys@microsoft.com,
haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com,
tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com,
arnd@arndb.de, peterz@infradead.org, jpoimboe@kernel.org,
seanjc@google.com, kirill.shutemov@linux.intel.com,
ak@linux.intel.com, sathyanarayanan.kuppuswamy@linux.intel.com,
linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arch@vger.kernel.org, mikelley@microsoft.com
Subject: Re: [PATCH v3 1/5] x86/hyperv: Add support for detecting nested hypervisor
Date: Fri, 4 Nov 2022 15:54:44 +0530 [thread overview]
Message-ID: <Y2TobFUO2dM1yVmq@anrayabh-desk> (raw)
In-Reply-To: <285b15b90ac6f29ef8ab6b6ececeeef7d7c6f380.1667480257.git.jinankjain@linux.microsoft.com>
On Thu, Nov 03, 2022 at 01:04:03PM +0000, Jinank Jain wrote:
> When Linux runs as a root partition for Microsoft Hypervisor. It is
> possible to detect if it is running as nested hypervisor using
> hints exposed by mshv. While at it expose a new variable called
> hv_nested which can be used later for making decisions specific to
> nested use case.
>
> Signed-off-by: Jinank Jain <jinankjain@linux.microsoft.com>
> ---
> arch/x86/include/asm/hyperv-tlfs.h | 3 +++
> arch/x86/include/asm/mshyperv.h | 2 ++
> arch/x86/kernel/cpu/mshyperv.c | 7 +++++++
> drivers/hv/hv_common.c | 7 +++++--
> 4 files changed, 17 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hyperv-tlfs.h
> index 3089ec352743..d9a611565859 100644
> --- a/arch/x86/include/asm/hyperv-tlfs.h
> +++ b/arch/x86/include/asm/hyperv-tlfs.h
> @@ -114,6 +114,9 @@
> /* Recommend using the newer ExProcessorMasks interface */
> #define HV_X64_EX_PROCESSOR_MASKS_RECOMMENDED BIT(11)
>
> +/* Indicates that the hypervisor is nested within a Hyper-V partition. */
> +#define HV_X64_HYPERV_NESTED BIT(12)
> +
> /* Recommend using enlightened VMCS */
> #define HV_X64_ENLIGHTENED_VMCS_RECOMMENDED BIT(14)
>
> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h
> index 61f0c206bff0..3c39923e5969 100644
> --- a/arch/x86/include/asm/mshyperv.h
> +++ b/arch/x86/include/asm/mshyperv.h
> @@ -26,6 +26,8 @@ void hyperv_vector_handler(struct pt_regs *regs);
> #if IS_ENABLED(CONFIG_HYPERV)
> extern int hyperv_init_cpuhp;
>
> +extern bool hv_nested;
> +
> extern void *hv_hypercall_pg;
>
> extern u64 hv_current_partition_id;
> diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c
> index 831613959a92..9a4204139490 100644
> --- a/arch/x86/kernel/cpu/mshyperv.c
> +++ b/arch/x86/kernel/cpu/mshyperv.c
> @@ -37,6 +37,8 @@
>
> /* Is Linux running as the root partition? */
> bool hv_root_partition;
> +/* Is Linux running on nested Microsoft Hypervisor */
> +bool hv_nested;
> struct ms_hyperv_info ms_hyperv;
>
> #if IS_ENABLED(CONFIG_HYPERV)
> @@ -301,6 +303,11 @@ static void __init ms_hyperv_init_platform(void)
> pr_info("Hyper-V: running as root partition\n");
> }
>
> + if (ms_hyperv.hints & HV_X64_HYPERV_NESTED) {
> + hv_nested = true;
> + pr_info("Hyper-V: running on a nested hypervisor\n");
> + }
> +
> /*
> * Extract host information.
> */
> diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
> index ae68298c0dca..dcb336ce374f 100644
> --- a/drivers/hv/hv_common.c
> +++ b/drivers/hv/hv_common.c
> @@ -25,8 +25,8 @@
> #include <asm/mshyperv.h>
>
> /*
> - * hv_root_partition and ms_hyperv are defined here with other Hyper-V
> - * specific globals so they are shared across all architectures and are
> + * hv_root_partition, ms_hyperv and hv_nested are defined here with other
> + * Hyper-V specific globals so they are shared across all architectures and are
> * built only when CONFIG_HYPERV is defined. But on x86,
> * ms_hyperv_init_platform() is built even when CONFIG_HYPERV is not
> * defined, and it uses these two variables. So mark them as __weak
> @@ -36,6 +36,9 @@
> bool __weak hv_root_partition;
> EXPORT_SYMBOL_GPL(hv_root_partition);
>
> +bool __weak hv_nested;
> +EXPORT_SYMBOL_GPL(hv_nested);
> +
> struct ms_hyperv_info __weak ms_hyperv;
> EXPORT_SYMBOL_GPL(ms_hyperv);
>
> --
> 2.25.1
Reviewed-by: <anrayabh@linux.microsoft.com>
next prev parent reply other threads:[~2022-11-04 10:25 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <https://lore.kernel.org/linux-hyperv/cover.1667406350.git.jinankjain@linux.microsoft.com/T/#t>
2022-11-03 13:04 ` [PATCH v3 0/5] Add support running nested Microsoft Hypervisor Jinank Jain
2022-11-03 13:04 ` [PATCH v3 1/5] x86/hyperv: Add support for detecting nested hypervisor Jinank Jain
2022-11-04 10:24 ` Anirudh Rayabharam [this message]
2022-11-03 13:04 ` [PATCH v3 2/5] Drivers: hv: Setup synic registers in case of nested root partition Jinank Jain
2022-11-04 10:41 ` Anirudh Rayabharam
2022-11-15 5:27 ` Jinank Jain
2022-11-03 13:04 ` [PATCH v3 3/5] x86/hyperv: Add an interface to do nested hypercalls Jinank Jain
2022-11-04 10:49 ` Anirudh Rayabharam
2022-11-03 13:04 ` [PATCH v3 4/5] Drivers: hv: Enable vmbus driver for nested root partition Jinank Jain
2022-11-03 13:04 ` [PATCH v3 5/5] x86/hyperv: Change interrupt vector " Jinank Jain
2022-11-03 14:00 ` [PATCH v3 0/5] Add support running nested Microsoft Hypervisor Borislav Petkov
2022-11-03 15:42 ` Anirudh Rayabharam
2022-11-16 12:12 ` Wei Liu
2022-11-17 4:04 ` Jinank Jain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y2TobFUO2dM1yVmq@anrayabh-desk \
--to=anrayabh@linux.microsoft.com \
--cc=ak@linux.intel.com \
--cc=arnd@arndb.de \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=decui@microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=hpa@zytor.com \
--cc=jinankjain@linux.microsoft.com \
--cc=jinankjain@microsoft.com \
--cc=jpoimboe@kernel.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=kys@microsoft.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mikelley@microsoft.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=sathyanarayanan.kuppuswamy@linux.intel.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=wei.liu@kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox