|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [RFC PATCH v2 03/13] hvm: Introduce FastABI infrastructure
FastABI is a new hypercall ABI intended to be used for confidential
guests, but also address some of the shortcomings of the current
virtual address based one.
Some of the key aspects :
- *everything* is passed through registers that can be either
input, output, both or unused. There is no clobbering of unused
registers (unused registers are untouched).
- On x86, available registers are :
rax, rdi, rsi, r8, r9, r10, r11, r12
Only long mode is supported, hypercall made outside of long mode are
sign-extended and may not behave as expected.
- Only a subset of existing hypercalls is covered.
- physmap manipulation by the guest is not provided grant table and
shared info are mapped in advance and its location is reported to
the guest through E820
Support for this ABI is reported to guest through CPUID
(XEN_HVM_CPUID_FASTABI). Support for this ABI is gated
behind CONFIG_FASTABI.
Signed-off-by: Teddy Astie <teddy.astie@xxxxxxxxxx>
---
Cc: Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>
Cc: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>
For now, it's HVM-only, but perhaps we may want to support it to PV64 ?
---
docs/guest-guide/fastabi/index.rst | 26 +++++++++++++
docs/guest-guide/x86/fastabi.rst | 58 +++++++++++++++++++++++++++++
docs/guest-guide/x86/index.rst | 1 +
xen/arch/x86/hvm/hypercall.c | 20 ++++++++++
xen/arch/x86/include/asm/fastabi.h | 18 +++++++++
xen/common/Kconfig | 7 ++++
xen/common/Makefile | 1 +
xen/common/fastabi.c | 22 +++++++++++
xen/include/public/arch-x86/cpuid.h | 4 ++
xen/include/public/fastabi.h | 11 ++++++
xen/include/xen/fastabi.h | 11 ++++++
11 files changed, 179 insertions(+)
create mode 100644 docs/guest-guide/fastabi/index.rst
create mode 100644 docs/guest-guide/x86/fastabi.rst
create mode 100644 xen/arch/x86/include/asm/fastabi.h
create mode 100644 xen/common/fastabi.c
create mode 100644 xen/include/public/fastabi.h
create mode 100644 xen/include/xen/fastabi.h
diff --git a/docs/guest-guide/fastabi/index.rst
b/docs/guest-guide/fastabi/index.rst
new file mode 100644
index 0000000000..1127ae8451
--- /dev/null
+++ b/docs/guest-guide/fastabi/index.rst
@@ -0,0 +1,26 @@
+.. SPDX-License-Identifier: CC-BY-4.0
+
+FastABI Hypercall ABI
+=====================
+
+A alternative hypercall may be available for guest, which
+is based on passing parameters and outputs through registers
+instead of virtual addresses.
+
+This is meant to be more efficient and compatible with confidential
+computing technologies (such as AMD SEV).
+
+Each architecture defines 8 registers which, if used in the
+operation, may be a input, a output or both. Unused registers are not
+considered nor modified by the hypervisor.
+
+Only a subset of hypercalls are exposed through this interface.
+
+As a convention, hypercall index is register 0, hypercall sub-operation
+(if any) is register 1. Error code is returned in register 0.
+
+Preemption
+----------
+
+FastABI hypercalls are allowed to report -ERESTART, in such case,
+the platform should redo the hypercall without altering parameters.
\ No newline at end of file
diff --git a/docs/guest-guide/x86/fastabi.rst b/docs/guest-guide/x86/fastabi.rst
new file mode 100644
index 0000000000..899e45d097
--- /dev/null
+++ b/docs/guest-guide/x86/fastabi.rst
@@ -0,0 +1,58 @@
+.. SPDX-License-Identifier: CC-BY-4.0
+
+x86 FastABI Hypercall ABI
+=========================
+
+Registers
+---------
+
+The FastABI registers used for x86 are defined as follow.
+
+.. list-table::
+ :header-rows: 1
+
+ * - Index
+ - Register
+
+ * - 0
+ - rax
+
+ * - 1
+ - rdi
+
+ * - 2
+ - rsi
+
+ * - 3
+ - r8
+
+ * - 4
+ - r9
+
+ * - 5
+ - r10
+
+ * - 6
+ - r11
+
+ * - 7
+ - r12
+
+Hypercall method
+----------------
+
+.. list-table::
+ :header-rows: 1
+
+ * - Hardware/Execution mode
+ - Transfer method
+
+ * - AMD SVM
+ - VMMCALL
+
+ * - Intel VMX
+ - VMCALL
+
+ * - AMD SEV-ES/SNP
+ - VMGEXIT with GHCB Page
+
diff --git a/docs/guest-guide/x86/index.rst b/docs/guest-guide/x86/index.rst
index 5b38ae397a..73d281047f 100644
--- a/docs/guest-guide/x86/index.rst
+++ b/docs/guest-guide/x86/index.rst
@@ -8,3 +8,4 @@ x86
hypercall-abi
pv-traps
+ fastabi
diff --git a/xen/arch/x86/hvm/hypercall.c b/xen/arch/x86/hvm/hypercall.c
index b254b3e2f7..e38a81a27e 100644
--- a/xen/arch/x86/hvm/hypercall.c
+++ b/xen/arch/x86/hvm/hypercall.c
@@ -10,6 +10,7 @@
#include <xen/hypercall.h>
#include <xen/ioreq.h>
#include <xen/nospec.h>
+#include <xen/fastabi.h>
#include <asm/hvm/emulate.h>
#include <asm/hvm/support.h>
@@ -155,6 +156,25 @@ int hvm_hypercall(struct cpu_user_regs *regs)
curr->hcall_preempted = false;
+ #ifdef CONFIG_FASTABI
+ if ( eax & __HYPERVISOR_FASTABI_MASK && is_hvm_domain(currd) &&
+ mode == X86_MODE_64BIT )
+ {
+ unsigned long index = eax & ~__HYPERVISOR_FASTABI_MASK;
+ HVM_DBG_LOG(DBG_LEVEL_HCALL,
+ "fasthcall%lu(%lx, %lx, %lx, %lx, %lx, %lx, %lx)",
+ index, fastabi_value_n(regs, 1),
+ fastabi_value_n(regs, 2), fastabi_value_n(regs, 3),
+ fastabi_value_n(regs, 4), fastabi_value_n(regs, 5),
+ fastabi_value_n(regs, 6), fastabi_value_n(regs, 7));
+
+ fastabi_dispatch(index, regs);
+
+ hvmemul_cache_restore(curr, token);
+ return curr->hcall_preempted ? HVM_HCALL_preempted :
HVM_HCALL_completed;
+ }
+ #endif
+
if ( mode == X86_MODE_64BIT )
{
HVM_DBG_LOG(DBG_LEVEL_HCALL, "hcall%lu(%lx, %lx, %lx, %lx, %lx)",
diff --git a/xen/arch/x86/include/asm/fastabi.h
b/xen/arch/x86/include/asm/fastabi.h
new file mode 100644
index 0000000000..3a6fd0c31f
--- /dev/null
+++ b/xen/arch/x86/include/asm/fastabi.h
@@ -0,0 +1,18 @@
+#ifndef XEN_ASM_FASTABI_H
+#define XEN_ASM_FASTABI_H
+
+#include <asm/current.h>
+#include <public/fastabi.h>
+
+#define fastabi_param_reg0 rax
+#define fastabi_param_reg1 rdi
+#define fastabi_param_reg2 rsi
+#define fastabi_param_reg3 r8
+#define fastabi_param_reg4 r9
+#define fastabi_param_reg5 r10
+#define fastabi_param_reg6 r11
+#define fastabi_param_reg7 r12
+
+#define fastabi_value_n(regs, n) (regs)->fastabi_param_reg##n
+
+#endif /* XEN_ASM_FASTABI_H */
\ No newline at end of file
diff --git a/xen/common/Kconfig b/xen/common/Kconfig
index 5b289e444f..e9be973fd4 100644
--- a/xen/common/Kconfig
+++ b/xen/common/Kconfig
@@ -675,4 +675,11 @@ config PM_STATS
Enable collection of performance management statistics to aid in
analyzing and tuning power/performance characteristics of the system
+config FASTABI
+ bool "Fast HVM ABI (UNSUPPORTED)" if UNSUPPORTED
+ depends on X86 && HVM
+ default n
+ help
+ Add support for a alternative fast HVM ABI.
+
endmenu
diff --git a/xen/common/Makefile b/xen/common/Makefile
index f69d47d189..c9ec72e5df 100644
--- a/xen/common/Makefile
+++ b/xen/common/Makefile
@@ -63,6 +63,7 @@ obj-y += vsprintf.o
obj-$(CONFIG_VM_EVENT) += wait.o
obj-bin-y += warning.init.o
obj-y += xmalloc_tlsf.o
+obj-$(CONFIG_FASTABI) += fastabi.o
obj-bin-$(CONFIG_X86) += $(foreach n,decompress bunzip2 unxz unlzma lzo unlzo
unlz4 unzstd,$(n).init.o)
diff --git a/xen/common/fastabi.c b/xen/common/fastabi.c
new file mode 100644
index 0000000000..90228206de
--- /dev/null
+++ b/xen/common/fastabi.c
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <xen/errno.h>
+#include <xen/fastabi.h>
+#include <xen/sched.h>
+
+#include <public/xen.h>
+
+void fastabi_make_continuation(void)
+{
+ current->hcall_preempted = true;
+}
+
+void fastabi_dispatch(unsigned long index, struct cpu_user_regs *regs)
+{
+ switch (index) {
+ /* Wrappers over traditional hypercalls */
+ default:
+ fastabi_value_n(regs, 0) = -ENOSYS;
+ break;
+ }
+}
diff --git a/xen/include/public/arch-x86/cpuid.h
b/xen/include/public/arch-x86/cpuid.h
index 3bb0dd249f..ff44ce0e7b 100644
--- a/xen/include/public/arch-x86/cpuid.h
+++ b/xen/include/public/arch-x86/cpuid.h
@@ -106,6 +106,10 @@
* bound to event channels.
*/
#define XEN_HVM_CPUID_UPCALL_VECTOR (1u << 6)
+/*
+ * Support for fast HVM ABI.
+ */
+#define XEN_HVM_CPUID_FASTABI (1u << 7)
/*
* Leaf 6 (0x40000x05)
diff --git a/xen/include/public/fastabi.h b/xen/include/public/fastabi.h
new file mode 100644
index 0000000000..b710fc72b8
--- /dev/null
+++ b/xen/include/public/fastabi.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: MIT */
+#ifndef __XEN_PUBLIC_FASTABI_H__
+#define __XEN_PUBLIC_FASTABI_H__
+
+#if defined(__x86_64__)
+#define __HYPERVISOR_FASTABI_MASK 0x40000000U
+#else
+#define __HYPERVISOR_FASTABI_MASK 0
+#endif
+
+#endif
diff --git a/xen/include/xen/fastabi.h b/xen/include/xen/fastabi.h
new file mode 100644
index 0000000000..9d0ca5264a
--- /dev/null
+++ b/xen/include/xen/fastabi.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef XEN_FASTABI_H
+#define XEN_FASTABI_H
+
+#include <asm/fastabi.h>
+
+void fastabi_dispatch(unsigned long index, struct cpu_user_regs *regs);
+void fastabi_make_continuation(void);
+
+#endif /* XEN_FASTABI_H */
--
2.56.1
--
Teddy Astie | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |