From: Mukesh R <mrathor@linux.microsoft.com>
To: linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com,
mhkelley58@gmail.com
Subject: [PATCH V0 1/2] Drivers: hv: Add new function hv_isolation_hw_cvm()
Date: Tue, 10 Nov 2026 18:20:35 -0800 [thread overview]
Message-ID: <20261111022036.351231-2-mrathor@linux.microsoft.com> (raw)
In-Reply-To: <20261111022036.351231-1-mrathor@linux.microsoft.com>
Add a new function hv_isolation_hw_cvm() for convenient check
if a VM is running in HW confidential mode, ie, TDX or SNP.
Signed-off-by: Mukesh R <mrathor@linux.microsoft.com>
---
arch/x86/hyperv/ivm.c | 5 +++++
drivers/hv/hv_common.c | 9 +++++++--
include/asm-generic/mshyperv.h | 7 +++++++
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c
index 2ce4dfe53472..b3340be0c43a 100644
--- a/arch/x86/hyperv/ivm.c
+++ b/arch/x86/hyperv/ivm.c
@@ -944,3 +944,8 @@ bool hv_isolation_type_tdx(void)
{
return static_branch_unlikely(&isolation_type_tdx);
}
+
+bool hv_isolation_hw_cvm(void)
+{
+ return hv_isolation_type_snp() || hv_isolation_type_tdx();
+}
diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c
index 27b9b79d4f4c..62b52855ae69 100644
--- a/drivers/hv/hv_common.c
+++ b/drivers/hv/hv_common.c
@@ -528,8 +528,7 @@ int hv_common_cpu_init(unsigned int cpu)
*outputarg = (char *)mem + HV_HYP_PAGE_SIZE;
}
- if (!ms_hyperv.paravisor_present &&
- (hv_isolation_type_snp() || hv_isolation_type_tdx())) {
+ if (!ms_hyperv.paravisor_present && hv_isolation_hw_cvm()) {
ret = set_memory_decrypted((unsigned long)mem, pgcount);
if (ret) {
/* It may be unsafe to free 'mem' */
@@ -696,6 +695,12 @@ bool __weak hv_isolation_type_tdx(void)
}
EXPORT_SYMBOL_GPL(hv_isolation_type_tdx);
+bool __weak hv_isolation_hw_cvm(void)
+{
+ return false;
+}
+EXPORT_SYMBOL_GPL(hv_isolation_hw_cvm);
+
void __weak hv_setup_vmbus_handler(void (*handler)(void))
{
}
diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h
index a3d497d99b0b..440c599784eb 100644
--- a/include/asm-generic/mshyperv.h
+++ b/include/asm-generic/mshyperv.h
@@ -87,6 +87,13 @@ u64 hv_do_fast_hypercall16(u16 control, u64 input1, u64 input2);
bool hv_isolation_type_snp(void);
bool hv_isolation_type_tdx(void);
+/* This needs to be before hv_do_rep_hypercall() below */
+#if IS_ENABLED(CONFIG_HYPERV)
+bool hv_isolation_hw_cvm(void);
+#else
+static inline bool hv_isolation_hw_cvm(void) { return false; }
+#endif
+
/*
* On architectures where Hyper-V doesn't support AEOI (e.g., ARM64),
* it doesn't provide a recommendation flag and AEOI must be disabled.
--
2.51.2.vfs.0.1
next prev parent reply other threads:[~2026-11-11 2:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 2:20 [PATCH V0 0/2] Hyper-V: Fix bugs and issues around repeat hypercall Mukesh R
2026-11-11 2:20 ` Mukesh R [this message]
2026-11-11 2:20 ` [PATCH V0 2/2] Drivers: hv: " Mukesh R
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=20261111022036.351231-2-mrathor@linux.microsoft.com \
--to=mrathor@linux.microsoft.com \
--cc=decui@microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhkelley58@gmail.com \
--cc=wei.liu@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
all inboxes | Powered by JetHome®