public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Naman Jain <namjain@linux.microsoft.com>
Cc: "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>,
	linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org,
	x86@kernel.org, Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Michael Kelley <mhklinux@outlook.com>,
	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>
Subject: Re: [PATCH v11 2/2] Drivers: hv: Introduce mshv_vtl driver
Date: Mon, 10 Nov 2025 15:38:34 +0100	[thread overview]
Message-ID: <20251110143834.GA3245006@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <20251110050835.1603847-3-namjain@linux.microsoft.com>

On Mon, Nov 10, 2025 at 05:08:35AM +0000, Naman Jain wrote:
> 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.

> diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c
> index 042e8712d8de..dba27e1bcc10 100644
> --- a/arch/x86/hyperv/hv_vtl.c
> +++ b/arch/x86/hyperv/hv_vtl.c
> @@ -249,3 +253,42 @@ int __init hv_vtl_early_init(void)
>  
>  	return 0;
>  }
> +
> +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 is intentionally not used in above asm block before making a call to
> + * __mshv_vtl_return_hypercall, to avoid rbp clobbering before actual VTL return happens.
> + * This however leads to objtool complain about "call without frame pointer save/setup".
> + * To ignore that warning, and inform objtool about this non-standard function,
> + * STACK_FRAME_NON_STANDARD_FP is used.
> + */
> +STACK_FRAME_NON_STANDARD_FP(mshv_vtl_return_hypercall);

> --- /dev/null
> +++ b/arch/x86/hyperv/mshv_vtl_asm.S
> @@ -0,0 +1,98 @@
> +/* SPDX-License-Identifier: GPL-2.0
> + *
> + * Assembly level code for mshv_vtl VTL transition
> + *
> + * Copyright (c) 2025, Microsoft Corporation.
> + *
> + * Author:
> + *   Naman Jain <namjain@microsoft.com>
> + */
> +
> +#include <linux/linkage.h>
> +#include <asm/asm.h>
> +#include <asm/asm-offsets.h>
> +#include <asm/frame.h>
> +#include "mshv-asm-offsets.h"
> +
> +	.text
> +	.section .noinstr.text, "ax"
> +/*
> + * void __mshv_vtl_return_call(struct mshv_vtl_cpu_context *vtl0)

Can we please get a few words on the magical context here? Like no NMIs
and #DB traps and the like. Because if any of them were possible this
code would be horribly broken.

> + */
> +SYM_FUNC_START(__mshv_vtl_return_call)
> +	/* Push callee save registers */
> +	pushq %rbp
> +	mov %rsp, %rbp
> +	pushq %r12
> +	pushq %r13
> +	pushq %r14
> +	pushq %r15
> +	pushq %rbx
> +
> +	/* register switch to VTL0 clobbers all registers except rax/rcx */
> +	mov %_ASM_ARG1, %rax
> +
> +	/* grab rbx/rbp/rsi/rdi/r8-r15 */
> +	mov MSHV_VTL_CPU_CONTEXT_rbx(%rax), %rbx
> +	mov MSHV_VTL_CPU_CONTEXT_rbp(%rax), %rbp
> +	mov MSHV_VTL_CPU_CONTEXT_rsi(%rax), %rsi
> +	mov MSHV_VTL_CPU_CONTEXT_rdi(%rax), %rdi
> +	mov MSHV_VTL_CPU_CONTEXT_r8(%rax), %r8
> +	mov MSHV_VTL_CPU_CONTEXT_r9(%rax), %r9
> +	mov MSHV_VTL_CPU_CONTEXT_r10(%rax), %r10
> +	mov MSHV_VTL_CPU_CONTEXT_r11(%rax), %r11
> +	mov MSHV_VTL_CPU_CONTEXT_r12(%rax), %r12
> +	mov MSHV_VTL_CPU_CONTEXT_r13(%rax), %r13
> +	mov MSHV_VTL_CPU_CONTEXT_r14(%rax), %r14
> +	mov MSHV_VTL_CPU_CONTEXT_r15(%rax), %r15
> +
> +	mov MSHV_VTL_CPU_CONTEXT_cr2(%rax), %rdx
> +	mov %rdx, %cr2
> +	mov MSHV_VTL_CPU_CONTEXT_rdx(%rax), %rdx
> +
> +	/* stash host registers on stack */
> +	pushq %rax
> +	pushq %rcx
> +
> +	xor %ecx, %ecx
> +
> +	/* make a hypercall to switch VTL */
> +	call mshv_vtl_return_hypercall

Yuck!

This seems to build for me.

---
--- a/arch/x86/hyperv/hv_vtl.c
+++ b/arch/x86/hyperv/hv_vtl.c
@@ -256,20 +256,6 @@ int __init hv_vtl_early_init(void)
 
 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 is intentionally not used in above asm block before making a call to
- * __mshv_vtl_return_hypercall, to avoid rbp clobbering before actual VTL return happens.
- * This however leads to objtool complain about "call without frame pointer save/setup".
- * To ignore that warning, and inform objtool about this non-standard function,
- * STACK_FRAME_NON_STANDARD_FP is used.
- */
-STACK_FRAME_NON_STANDARD_FP(mshv_vtl_return_hypercall);
-
 void mshv_vtl_return_call_init(u64 vtl_return_offset)
 {
 	static_call_update(__mshv_vtl_return_hypercall,
--- a/arch/x86/hyperv/mshv_vtl_asm.S
+++ b/arch/x86/hyperv/mshv_vtl_asm.S
@@ -9,6 +9,7 @@
  */
 
 #include <linux/linkage.h>
+#include <linux/static_call_types.h>
 #include <asm/asm.h>
 #include <asm/asm-offsets.h>
 #include <asm/frame.h>
@@ -57,7 +58,7 @@ SYM_FUNC_START(__mshv_vtl_return_call)
 	xor %ecx, %ecx
 
 	/* make a hypercall to switch VTL */
-	call mshv_vtl_return_hypercall
+	call STATIC_CALL_TRAMP_STR(__mshv_vtl_return_hypercall)
 
 	/* stash guest registers on stack, restore saved host copies */
 	pushq %rax
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -11,6 +11,10 @@
 #define __has_builtin(x) (0)
 #endif
 
+/* Indirect macros required for expanded argument pasting, eg. __LINE__. */
+#define ___PASTE(a,b) a##b
+#define __PASTE(a,b) ___PASTE(a,b)
+
 #ifndef __ASSEMBLY__
 
 /*
@@ -79,10 +83,6 @@ static inline void __chk_io_ptr(const vo
 # define __builtin_warning(x, y...) (1)
 #endif /* __CHECKER__ */
 
-/* Indirect macros required for expanded argument pasting, eg. __LINE__. */
-#define ___PASTE(a,b) a##b
-#define __PASTE(a,b) ___PASTE(a,b)
-
 #ifdef __KERNEL__
 
 /* Attributes */
--- a/include/linux/static_call_types.h
+++ b/include/linux/static_call_types.h
@@ -25,6 +25,8 @@
 #define STATIC_CALL_SITE_INIT 2UL	/* init section */
 #define STATIC_CALL_SITE_FLAGS 3UL
 
+#ifndef __ASSEMBLY__
+
 /*
  * The static call site table needs to be created by external tooling (objtool
  * or a compiler plugin).
@@ -100,4 +102,6 @@ struct static_call_key {
 
 #endif /* CONFIG_HAVE_STATIC_CALL */
 
+#endif /* __ASSEMBLY__ */
+
 #endif /* _STATIC_CALL_TYPES_H */

  reply	other threads:[~2025-11-10 14:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-10  5:08 [PATCH v11 0/2] Drivers: hv: Introduce new driver - mshv_vtl Naman Jain
2025-11-10  5:08 ` [PATCH v11 1/2] Drivers: hv: Export some symbols for mshv_vtl Naman Jain
2025-11-10  5:08 ` [PATCH v11 2/2] Drivers: hv: Introduce mshv_vtl driver Naman Jain
2025-11-10 14:38   ` Peter Zijlstra [this message]
2025-11-11  6:55     ` Naman Jain
2025-11-11  8:13       ` Peter Zijlstra
2025-11-11 10:58         ` Naman Jain
2025-11-11 10:59           ` Peter Zijlstra
2025-11-12  4:12         ` Michael Kelley
2025-11-12  8:54           ` Paolo Bonzini
2025-11-12  9:37           ` Peter Zijlstra
2025-11-12  9:44             ` Michael Kelley
2025-11-12 10:10               ` Peter Zijlstra
2025-11-12 10:49                 ` 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=20251110143834.GA3245006@noisy.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --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=namjain@linux.microsoft.com \
    --cc=nunodasneves@linux.microsoft.com \
    --cc=pbonzini@redhat.com \
    --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