From: Naman Jain <namjain@linux.microsoft.com>
To: Michael Kelley <mhklinux@outlook.com>,
Peter Zijlstra <peterz@infradead.org>,
Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>
Cc: "linux-hyperv@vger.kernel.org" <linux-hyperv@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"x86@kernel.org" <x86@kernel.org>,
Mukesh Rathor <mrathor@linux.microsoft.com>,
Stanislav Kinsburskii <skinsburskii@linux.microsoft.com>,
Nuno Das Neves <nunodasneves@linux.microsoft.com>,
Christoph Hellwig <hch@infradead.org>,
Saurabh Sengar <ssengar@linux.microsoft.com>,
ALOK TIWARI <alok.a.tiwari@oracle.com>,
"K . Y . Srinivasan" <kys@microsoft.com>,
Haiyang Zhang <haiyangz@microsoft.com>,
Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
"H . Peter Anvin" <hpa@zytor.com>
Subject: Re: [PATCH v9 0/2] Drivers: hv: Introduce new driver - mshv_vtl
Date: Thu, 23 Oct 2025 20:51:35 +0530 [thread overview]
Message-ID: <0f9f9d71-d12a-4b52-8477-46a66a534eda@linux.microsoft.com> (raw)
In-Reply-To: <SN6PR02MB4157AE454F412993BC1D4BFDD4F6A@SN6PR02MB4157.namprd02.prod.outlook.com>
On 10/18/2025 12:02 AM, Michael Kelley wrote:
> From: Naman Jain <namjain@linux.microsoft.com> Sent: Friday, October 17, 2025 12:45 AM
>>
>> Introduce a new mshv_vtl driver to provide an interface for Virtual
>> Machine Monitor like OpenVMM and its use as OpenHCL paravisor to
>> control VTL0 (Virtual trust Level).
>> Expose devices and support IOCTLs for features like VTL creation,
>> VTL0 memory management, context switch, making hypercalls,
>> mapping VTL0 address space to VTL2 userspace, getting new VMBus
>> messages and channel events in VTL2 etc.
>>
>> OpenVMM : https://openvmm.dev/guide/
>>
>> Changes since v8:
>> https://lore.kernel.org/all/20251013060353.67326-1-namjain@linux.microsoft.com/
>> Addressed Sean's comments:
>> * Removed forcing SIGPENDING, and other minor changes, in
>> mshv_vtl_ioctl_return_to_lower_vtl after referring
>> to Sean's earlier changes for xfer_to_guest_mode_handle_work.
>>
>> * Rebased and resolved merge conflicts, compilation errors on latest
>> linux-next kernel tip, after Roman's Confidential VM changes,
>> which merged recently. No functional changes.
>
> Did your testing against the latest linux-next included testing with
> CONFIG_X86_KERNEL_IBT=y? This is Indirect Branch Tracking, which would
> have generated a fault with your v7 series and earlier because of the indirect
> call instruction when doing VTL Return through the hypercall page (which
> doesn't have the needed ENDBR64 instruction). But now that VTL Return is
> doing a static call, that should be direct, which won't trigger an IBT fault.
>
> To confirm that you really are running with IBT enabled, you should see
>
> [ 0.047008] CET detected: Indirect Branch Tracking enabled
>
> in the VTL2 dmesg output. And "ibt" should appear in the
> "flags" output line of 'cat /proc/cpuinfo' (or the 'lscpu' command).
>
> Michael
Hi Michael,
I have now tested with and without IBT, and in case of IBT enabled, I do
see the log you pasted for IBT in VTL2 logs and there are no failures.
However, this additional testing uncovered another issue here where
there is a crash in VTL0, some time after boot, due to rbp clobbering in
mshv_vtl_return_hypercall() wrapper function.
Thanks a lot Michael for helping me offline on this, to understand and
identify the issue.
Hi Peter, Paolo, Sean,
Here is the summary of the problem and the fix:
Assembly code make a call to mshv_vtl_return_hypercall() after handling
rbp properly. However, current wrapper function in C updates rbp to rsp
before making the static call. This creates problems.
<-snippet->
arch/x86/hyperv/mshv_vtl_asm.S:
/* make a hypercall to switch VTL */
call mshv_vtl_return_hypercall
arch/x86/hyperv/hv_vtl.c:
noinstr void mshv_vtl_return_hypercall(void)
{
asm volatile ("call " STATIC_CALL_TRAMP_STR(__mshv_vtl_return_hypercall) :
ASM_CALL_CONSTRAINT);
}
(gdb) disassemble mshv_vtl_return_hypercall
Dump of assembler code for function mshv_vtl_return_hypercall:
0xffffffff886981a0 <+0>: push %rbp
0xffffffff886981a1 <+1>: mov %rsp,%rbp
0xffffffff886981a4 <+4>: call 0xffffffff886a77a8
<__SCT____mshv_vtl_return_hypercall>
0xffffffff886981a9 <+9>: pop %rbp
0xffffffff886981aa <+10>: jmp 0xffffffff886a7670
<__x86_return_thunk>
<-end->
This is fixed after removing ASM_CALL_CONSTRAINT from above function
which makes sure it does not add save/restore rbp logic before the
assembly call instructions.
<-snippet->
(gdb) disassemble mshv_vtl_return_hypercall
Dump of assembler code for function mshv_vtl_return_hypercall:
0xffffffff886981a0 <+0>: call 0xffffffff886a77a8
<__SCT____mshv_vtl_return_hypercall>
0xffffffff886981a5 <+5>: jmp 0xffffffff886a7670
<__x86_return_thunk>
End of assembler dump.
<-end->
But then we see a warning reported by objtool for frame pointer, but
since this is expected, I will need to add STACK_FRAME_NON_STANDARD_FP
to suppress it.
vmlinux.o: warning: objtool: mshv_vtl_return_hypercall+0x4: call without
frame pointer save/setup
During code review, I found CR2 handling was missing after making
mshv_vtl_return_hypercall call in assembly, which I will *additionally*
fix in next version.
Pasting the diff at the end, on top of this patch, which should fix
these issues.
Please let me know if I should be doing it differently or if you foresee
any issues with this approach.
Regards,
Naman
------------------------
diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c
index 636e9253b81e..c61d2dce4d68 100644
--- a/arch/x86/hyperv/hv_vtl.c
+++ b/arch/x86/hyperv/hv_vtl.c
@@ -258,9 +258,9 @@ DEFINE_STATIC_CALL_NULL(__mshv_vtl_return_hypercall,
void (*)(void));
noinstr void mshv_vtl_return_hypercall(void)
{
- asm volatile ("call "
STATIC_CALL_TRAMP_STR(__mshv_vtl_return_hypercall) :
- ASM_CALL_CONSTRAINT);
+ asm volatile ("call "
STATIC_CALL_TRAMP_STR(__mshv_vtl_return_hypercall));
}
+STACK_FRAME_NON_STANDARD_FP(mshv_vtl_return_hypercall);
extern void __mshv_vtl_return_call(struct mshv_vtl_cpu_context *vtl0);
diff --git a/arch/x86/hyperv/mshv_vtl_asm.S b/arch/x86/hyperv/mshv_vtl_asm.S
index 4085073a5876..5f4b511749f8 100644
--- a/arch/x86/hyperv/mshv_vtl_asm.S
+++ b/arch/x86/hyperv/mshv_vtl_asm.S
@@ -65,6 +65,9 @@ SYM_FUNC_START(__mshv_vtl_return_call)
mov 16(%rsp), %rcx
mov 24(%rsp), %rax
+ mov %rdx, MSHV_VTL_CPU_CONTEXT_rdx(%rax)
+ mov %cr2, %rdx
+ mov %rdx, MSHV_VTL_CPU_CONTEXT_cr2(%rax)
pop MSHV_VTL_CPU_CONTEXT_rcx(%rax)
pop MSHV_VTL_CPU_CONTEXT_rax(%rax)
add $16, %rsp
next prev parent reply other threads:[~2025-10-23 15:21 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-17 7:45 [PATCH v9 0/2] Drivers: hv: Introduce new driver - mshv_vtl Naman Jain
2025-10-17 7:45 ` [PATCH v9 1/2] Drivers: hv: Export some symbols for mshv_vtl Naman Jain
2025-10-17 7:45 ` [PATCH v9 2/2] Drivers: hv: Introduce mshv_vtl driver Naman Jain
2025-10-17 18:32 ` [PATCH v9 0/2] Drivers: hv: Introduce new driver - mshv_vtl Michael Kelley
2025-10-23 15:21 ` Naman Jain [this message]
2025-10-28 5:09 ` Naman 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=0f9f9d71-d12a-4b52-8477-46a66a534eda@linux.microsoft.com \
--to=namjain@linux.microsoft.com \
--cc=alok.a.tiwari@oracle.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=decui@microsoft.com \
--cc=haiyangz@microsoft.com \
--cc=hch@infradead.org \
--cc=hpa@zytor.com \
--cc=kys@microsoft.com \
--cc=linux-hyperv@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhklinux@outlook.com \
--cc=mingo@redhat.com \
--cc=mrathor@linux.microsoft.com \
--cc=nunodasneves@linux.microsoft.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=seanjc@google.com \
--cc=skinsburskii@linux.microsoft.com \
--cc=ssengar@linux.microsoft.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