Skip to contentSkip to conversation

x86/hvm: New Xen HVM ABI proposal ("HVMv2" part 1)

RFC PATCH In review Teddy Astie 3 participants 26 messages Aug 21, 2025 – Oct 20, 2025

lore
Share & tools
lore
#4 lore raw

RFC PATCH 2/9 common: Isolate XENVER_get_features into a separate function

In reply to Teddy Astie

Make do_xen_version more readable by moving the main XENVER_get_features into a separate function.

No functional changes intended.

---
 xen/common/kernel.c | 84 +++++++++++++++++++++++++--------------------
 1 file changed, 46 insertions(+), 38 deletions(-)
xen/common/kernel.c +46 -38
index 5be668ba85..eff6db6c8f 100644
@@ -569,6 +569,50 @@ static long xenver_varbuf_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
     return sz;
 }
 
+static long xenver_get_features(struct domain *d, uint32_t submap_idx, uint32_t *submap)
+{
+    switch ( submap_idx )
+    {
+    case 0:
+        *submap = (1U << XENFEAT_memory_op_vnode_supported) |
+#ifdef CONFIG_X86
+                  (1U << XENFEAT_vcpu_time_phys_area) |
+#endif
+                  (1U << XENFEAT_runstate_phys_area);
+        if ( VM_ASSIST(d, pae_extended_cr3) )
+            *submap |= (1U << XENFEAT_pae_pgdir_above_4gb);
+        if ( paging_mode_translate(d) )
+            *submap |=
+                (1U << XENFEAT_writable_page_tables) |
+                (1U << XENFEAT_auto_translated_physmap);
+        if ( is_hardware_domain(d) )
+            *submap |= 1U << XENFEAT_dom0;
+#ifdef CONFIG_ARM
+        *submap |= (1U << XENFEAT_ARM_SMCCC_supported);
+#endif
+#ifdef CONFIG_X86
+        if ( is_pv_domain(d) )
+            *submap |= (1U << XENFEAT_mmu_pt_update_preserve_ad) |
+                      (1U << XENFEAT_highmem_assist) |
+                      (1U << XENFEAT_gnttab_map_avail_bits);
+        else
+            *submap |= (1U << XENFEAT_hvm_safe_pvclock) |
+                       (1U << XENFEAT_hvm_callback_vector) |
+                       (has_pirq(d) ? (1U << XENFEAT_hvm_pirqs) : 0);
+        *submap |= (1U << XENFEAT_dm_msix_all_writes);
+#endif
+        if ( !paging_mode_translate(d) || is_domain_direct_mapped(d) )
+            *submap |= (1U << XENFEAT_direct_mapped);
+        else
+            *submap |= (1U << XENFEAT_not_direct_mapped);
+        break;
+    default:
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
 long do_xen_version(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     bool deny = xsm_xen_version(XSM_OTHER, cmd);
@@ -675,45 +719,9 @@ long do_xen_version(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         if ( copy_from_guest(&fi, arg, 1) )
             return -EFAULT;
 
-        switch ( fi.submap_idx )
-        {
-        case 0:
-            fi.submap = (1U << XENFEAT_memory_op_vnode_supported) |
-#ifdef CONFIG_X86
-                        (1U << XENFEAT_vcpu_time_phys_area) |
-#endif
-                        (1U << XENFEAT_runstate_phys_area);
-            if ( VM_ASSIST(d, pae_extended_cr3) )
-                fi.submap |= (1U << XENFEAT_pae_pgdir_above_4gb);
-            if ( paging_mode_translate(d) )
-                fi.submap |=
-                    (1U << XENFEAT_writable_page_tables) |
-                    (1U << XENFEAT_auto_translated_physmap);
-            if ( is_hardware_domain(d) )
-                fi.submap |= 1U << XENFEAT_dom0;
-#ifdef CONFIG_ARM
-            fi.submap |= (1U << XENFEAT_ARM_SMCCC_supported);
-#endif
-#ifdef CONFIG_X86
-            if ( is_pv_domain(d) )
-                fi.submap |= (1U << XENFEAT_mmu_pt_update_preserve_ad) |
-                             (1U << XENFEAT_highmem_assist) |
-                             (1U << XENFEAT_gnttab_map_avail_bits);
-            else
-                fi.submap |= (1U << XENFEAT_hvm_safe_pvclock) |
-                             (1U << XENFEAT_hvm_callback_vector) |
-                             (has_pirq(d) ? (1U << XENFEAT_hvm_pirqs) : 0);
-            fi.submap |= (1U << XENFEAT_dm_msix_all_writes);
-#endif
-            if ( !paging_mode_translate(d) || is_domain_direct_mapped(d) )
-                fi.submap |= (1U << XENFEAT_direct_mapped);
-            else
-                fi.submap |= (1U << XENFEAT_not_direct_mapped);
-            break;
-        default:
+        if ( xenver_get_features(d, fi.submap_idx, &fi.submap) )
             return -EINVAL;
-        }
-
+            
         if ( __copy_to_guest(arg, &fi, 1) )
             return -EFAULT;
         return 0;
Signature · 9 lines
2.50.1



Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#6 lore raw

RFC PATCH 3/9 common/grant_table: Use direct structures instead of guest handles

In reply to Teddy Astie

Make these functions work with hypervisor-owned pointer rather than guest handles, so the function parameters don't have to live in guest memory.

No functional changes.

---
 xen/common/grant_table.c | 68 +++++++++++++++++++++++-----------------
 1 file changed, 39 insertions(+), 29 deletions(-)
xen/common/grant_table.c +39 -29
index cf131c43a1..3c3bbca2fc 100644
@@ -3164,29 +3164,24 @@ static long gnttab_copy(
     return rc;
 }
 
-static long
-gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t) uop)
+static long gnttab_set_version(gnttab_set_version_t *op)
 {
-    gnttab_set_version_t op;
     struct domain *currd = current->domain;
     struct grant_table *gt = currd->grant_table;
     grant_entry_v1_t reserved_entries[GNTTAB_NR_RESERVED_ENTRIES];
     int res;
     unsigned int i, nr_ents;
 
-    if ( copy_from_guest(&op, uop, 1) )
-        return -EFAULT;
-
     res = -EINVAL;
-    if ( op.version != 1 && op.version != 2 )
+    if ( op->version != 1 && op->version != 2 )
         goto out;
 
     res = -ENOSYS;
-    if ( op.version == 2 && gt->max_version == 1 )
+    if ( op->version == 2 && gt->max_version == 1 )
         goto out; /* Behave as before set_version was introduced. */
 
     res = 0;
-    if ( gt->gt_version == op.version )
+    if ( gt->gt_version == op->version )
         goto out;
 
     grant_write_lock(gt);
@@ -3203,7 +3198,7 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t) uop)
         {
             gdprintk(XENLOG_WARNING,
                      "tried to change grant table version from %u to %u, but some grant entries still in use\n",
-                     gt->gt_version, op.version);
+                     gt->gt_version, op->version);
             res = -EBUSY;
             goto out_unlock;
         }
@@ -3268,7 +3263,7 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t) uop)
         break;
     }
 
-    if ( op.version < 2 && gt->gt_version == 2 &&
+    if ( op->version < 2 && gt->gt_version == 2 &&
          (res = gnttab_unpopulate_status_frames(currd, gt)) != 0 )
         goto out_unlock;
 
@@ -3279,7 +3274,7 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t) uop)
     /* Restore the first 8 entries (toolstack reserved grants). */
     if ( gt->gt_version )
     {
-        switch ( op.version )
+        switch ( op->version )
         {
         case 1:
             memcpy(&shared_entry_v1(gt, 0), reserved_entries, sizeof(reserved_entries));
@@ -3300,16 +3295,14 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t) uop)
         }
     }
 
-    gt->gt_version = op.version;
+    gt->gt_version = op->version;
 
  out_unlock:
     grant_write_unlock(gt);
 
  out:
-    op.version = gt->gt_version;
+    op->version = gt->gt_version;
 
-    if ( __copy_to_guest(uop, &op, 1) )
-        res = -EFAULT;
 
     return res;
 }
@@ -3387,17 +3380,12 @@ gnttab_get_status_frames(XEN_GUEST_HANDLE_PARAM(gnttab_get_status_frames_t) uop,
     return 0;
 }
 
-static long
-gnttab_get_version(XEN_GUEST_HANDLE_PARAM(gnttab_get_version_t) uop)
+static long gnttab_get_version(gnttab_get_version_t *op)
 {
-    gnttab_get_version_t op;
     struct domain *d;
     int rc;
 
-    if ( copy_from_guest(&op, uop, 1) )
-        return -EFAULT;
-
-    d = rcu_lock_domain_by_any_id(op.dom);
+    d = rcu_lock_domain_by_any_id(op->dom);
     if ( d == NULL )
         return -ESRCH;
 
@@ -3408,13 +3396,10 @@ gnttab_get_version(XEN_GUEST_HANDLE_PARAM(gnttab_get_version_t) uop)
         return rc;
     }
 
-    op.version = d->grant_table->gt_version;
+    op->version = d->grant_table->gt_version;
 
     rcu_unlock_domain(d);
 
-    if ( __copy_field_to_guest(uop, &op, version) )
-        return -EFAULT;
-
     return 0;
 }
 
@@ -3749,8 +3734,20 @@ long do_grant_table_op(
         break;
 
     case GNTTABOP_set_version:
-        rc = gnttab_set_version(guest_handle_cast(uop, gnttab_set_version_t));
+    {
+        gnttab_set_version_t op;
+        if ( copy_from_guest(&op, uop, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }
+
+        rc = gnttab_set_version(&op);
+
+        if ( copy_to_guest(uop, &op, 1) )
+            rc = -EFAULT;
         break;
+    }
 
     case GNTTABOP_get_status_frames:
         rc = gnttab_get_status_frames(
@@ -3758,8 +3755,21 @@ long do_grant_table_op(
         break;
 
     case GNTTABOP_get_version:
-        rc = gnttab_get_version(guest_handle_cast(uop, gnttab_get_version_t));
+    {
+        gnttab_get_version_t op;
+
+        if ( copy_from_guest(&op, uop, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }
+
+        rc = gnttab_get_version(&op);
+
+        if ( copy_to_guest(uop, &op, 1) )
+            rc = -EFAULT;
         break;
+    }
 
     case GNTTABOP_swap_grant_ref:
     {
Signature · 9 lines
2.50.1



Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#8 lore raw

RFC PATCH 4/9 hvm: Introduce "fixed memory layout" feature

In reply to Teddy Astie

Currently, guests needs to explicitely map their shared info and grant table through hypercalls. It has proved to be complicated and had been traditionally placed in the Xen PCI Platform device BAR, but has caused confusions regarding MTRR [1].

Introduce a optional feature to let the toolstack map these pages in advance, and exposing their location through the memory map (i.e E820).

When this feature is active, guests are expected to not invalidate such mappings (e.g by calling xen_remove_from_physmap); as they may be used by the operating system or firmware (i.e OVMF).

Moreover, this feature is useful to allow having a working guest without having to expose to it physmap manipulation.

[1] https://lore.kernel.org/xen-devel/[email protected]/

---
 .../x86/fixed-memory-layout.pandoc            | 24 ++++++
 docs/guest-guide/x86/index.rst                |  1 +
 tools/include/xen-tools/common-macros.h       |  4 +
 tools/libs/guest/xg_dom_x86.c                 | 84 +++++++++++++++++++
 tools/libs/light/libxl_create.c               |  1 +
 tools/libs/light/libxl_types.idl              |  1 +
 tools/libs/light/libxl_x86.c                  | 71 ++++++++++++++++
 tools/xl/xl_parse.c                           |  1 +
 xen/include/public/arch-x86/hvm/start_info.h  |  7 ++
 9 files changed, 194 insertions(+)
 create mode 100644 docs/guest-guide/x86/fixed-memory-layout.pandoc
docs/guest-guide/x86/fixed-memory-layout.pandoc new file +24 -0
new file mode 100644
index 0000000000..b394dc1cff
@@ -0,0 +1,24 @@
+# Fixed memory layout
+
+When creating a guest with "fixed_mem_layout", the guest has additional special
+pages mapped in advance. These mappings may be required in some cases due to FastABI
+not providing the ability for the guest to modify its physical memory layout (which is
+usually used to map the shared info page or the grant table).
+
+The guest is informed of such mappings and their location through the memory map using
+Xen specific memory map types (in the OEM range of ACPI specification).
+
+It's expected that these mappings stay stable, therefore, the guest shouldn't try to
+modify such mappings as it may be actively used by guest firmware or operating system.
+
+    /* Xen-specific types (OEM-specific range of the ACPI spec) */
+    #define XEN_HVM_MEMMAP_TYPE_SHARED_INFO   0xF0000001 /* Shared info page */
+    #define XEN_HVM_MEMMAP_TYPE_GRANT_TABLE   0xF0000002 /* Grant table pages */
+    #define XEN_HVM_MEMMAP_TYPE_GNTTAB_STATUS 0xF0000003 /* Grant table status page (v2) */
+    #define XEN_HVM_MEMMAP_TYPE_FOREIGN_REG   0xF0000004 /* Suitable region for grant mappings */
+                                                         /* and foreign mappings */
+
+These mappings are likely to be placed outside the 4G range.
+
+XEN_HVM_MEMMAP_TYPE_FOREIGN_REG is a special region which doesn't contain any mapping,
+but is safe to use for placing grant and foreign mappings.
docs/guest-guide/x86/index.rst +1 -0
index 502968490d..6927271e53 100644
@@ -7,3 +7,4 @@ x86
    :maxdepth: 2
 
    hypercall-abi
+   fixed-memory-layout
tools/include/xen-tools/common-macros.h +4 -0
index 0088208c2e..8b286b3da5 100644
@@ -72,6 +72,10 @@
 #define ROUNDUP(_x,_w) (((unsigned long)(_x)+(1UL<<(_w))-1) & ~((1UL<<(_w))-1))
 #endif
 
+#ifndef DIV_ROUNDUP
+#define DIV_ROUNDUP(n, d) (((n) + (d) - 1) / (d))
+#endif
+
 #define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m)))
 #define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m))
 
tools/libs/guest/xg_dom_x86.c +84 -0

96 lines not on this page · raw message

tools/libs/light/libxl_create.c +1 -0
index 8a85fba1cf..5e23e122fc 100644
@@ -2363,6 +2363,7 @@ int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config,
      * configuration.
      */
     libxl_defbool_setdefault(&d_config->b_info.arch_x86.msr_relaxed, true);
+    libxl_defbool_setdefault(&d_config->b_info.arch_x86.fixed_mem_layout, false);
     libxl_defbool_setdefault(&d_config->b_info.u.hvm.pirq, true);
 
     return do_domain_create(ctx, d_config, domid, restore_fd, send_back_fd,
tools/libs/light/libxl_types.idl +1 -0
index a3a79d12b2..74edfdebc1 100644
@@ -727,6 +727,7 @@ libxl_domain_build_info = Struct("domain_build_info",[
                                ("nr_spis", uint32, {'init_val': 'LIBXL_NR_SPIS_DEFAULT'}),
                               ])),
     ("arch_x86", Struct(None, [("msr_relaxed", libxl_defbool),
+                               ("fixed_mem_layout", libxl_defbool),
                               ])),
     # Alternate p2m is not bound to any architecture or guest type, as it is
     # supported by x86 HVM and ARM support is planned.
tools/libs/light/libxl_x86.c +71 -0

111 lines not on this page · raw message

tools/xl/xl_parse.c +1 -0
index 7e11c62ba0..a74cc577e9 100644
@@ -2992,6 +2992,7 @@ skip_usbdev:
                     "WARNING: msr_relaxed will be removed in future versions.\n"
                     "If it fixes an issue you are having please report to "
                     "[email protected].\n");
+    xlu_cfg_get_defbool(config, "fixed_mem_layout", &b_info->arch_x86.fixed_mem_layout, 0);
 
     xlu_cfg_get_defbool(config, "vpmu", &b_info->vpmu, 0);
 
xen/include/public/arch-x86/hvm/start_info.h +7 -0
index e33557c0b4..0b3dfe91af 100644
@@ -99,6 +99,13 @@
 #define XEN_HVM_MEMMAP_TYPE_DISABLED  6
 #define XEN_HVM_MEMMAP_TYPE_PMEM      7
 
+/* Xen-specific types (OEM-specific range of the ACPI spec) */
+#define XEN_HVM_MEMMAP_TYPE_SHARED_INFO   0xF0000001 /* Shared info page */
+#define XEN_HVM_MEMMAP_TYPE_GRANT_TABLE   0xF0000002 /* Grant table pages */
+#define XEN_HVM_MEMMAP_TYPE_GNTTAB_STATUS 0xF0000003 /* Grant table status page (v2) */
+#define XEN_HVM_MEMMAP_TYPE_FOREIGN_REG   0xF0000004 /* Suitable region for grant mappings */
+                                                     /* and foreign mappings */
+
 /*
  * C representation of the x86/HVM start info layout.
  *
Signature · 9 lines
2.50.1



Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#14 lore raw

RFC PATCH 5/9 docs/x86: Introduce FastABI

In reply to Teddy Astie

FastABI is a alternative ABI designed with performance and coco-enabled guest in mind. It is register-oriented instead of refering to C structures in the guest memory (through a virtual memory pointer).

It only focuses on kernel-side hypercalls, it doesn't aim to provide toolstack operations.

---
 docs/guest-guide/x86/fastabi.pandoc |  50 ++++++++++
 docs/guest-guide/x86/index.rst      |   1 +
 xen/abi/event_channel.yml           | 130 ++++++++++++++++++++++++++
 xen/abi/grant_table.yml             |  46 +++++++++
 xen/abi/hvm.yml                     |  50 ++++++++++
 xen/abi/memory.yml                  |  11 +++
 xen/abi/sched.yml                   |  48 ++++++++++
 xen/abi/vcpu.yml                    | 139 ++++++++++++++++++++++++++++
 xen/abi/version.yml                 |  15 +++
 xen/include/public/arch-x86/cpuid.h |   4 +
 10 files changed, 494 insertions(+)
 create mode 100644 docs/guest-guide/x86/fastabi.pandoc
 create mode 100644 xen/abi/event_channel.yml
 create mode 100644 xen/abi/grant_table.yml
 create mode 100644 xen/abi/hvm.yml
 create mode 100644 xen/abi/memory.yml
 create mode 100644 xen/abi/sched.yml
 create mode 100644 xen/abi/vcpu.yml
 create mode 100644 xen/abi/version.yml
docs/guest-guide/x86/fastabi.pandoc new file +50 -0
new file mode 100644
index 0000000000..8ff8609f37
@@ -0,0 +1,50 @@
+# x86 FastABI
+
+## Introduction
+
+FastABI is a alternative hypercall ABI designed with performance and confidential
+computing enabled guests (AMD SEV, Intel TDX, ...) in mind. It provides a minimal
+subset of the traditional ABI that is sufficient for having a working guest.
+
+This hypercall interface is designed around using registers for passing hypercall
+parameters and outputs rather than using pointer to C structures, thus it avoids
+potentially complicated or expensive memory copies from/to the guest.
+
+This ABI currently only supports HVM/PVH and x86 long mode.
+
+Each hypercall operation interface is described in a parsable yaml file, which
+defines each hypercall suboperation inputs and outputs and eventual metadata for
+code generation (e.g C stubs).
+
+## Support
+
+This interface is only supported if XEN_HVM_CPUID_FASTABI is set.
+
+## Semantics
+
+8 registers can be used as either input or output.
+
+Each hypercall operation (or sub-operation) defines its own set of used input and
+output registers. There is no implicit clobbering of unused registers, i.e input
+registers are not allowed to be modified by the hypervisor unless it is explicitely
+also marked as a output (or cloberred register).
+
+- reg0: `rax`: IN: hypercall operation index, OUT: error code
+- reg1: `rdi`: (if operation has sub-operations) IN: hypercall sub-operation index
+- reg2: `rsi`
+- reg3: `r8`
+- reg4: `r9`
+- reg5: `r10`
+- reg6: `r11`
+- reg7: `r12`
+
+`reg0` input is reserved for hypercall index.
+In order to distinguish FastABI with traditional hypercalls or viridian hypercalls,
+reg0 input needs to be OR-ed with 0x40000000 (__HYPERVISOR_FASTABI_MASK).
+
+`reg0` output is reserved for standard hypercall return code (errno) or returned value.
+
+`reg1` input can be used for identifying a sub-operation. output is available for use.
+
+The hypercall uses the native hypercall instruction, which is `vmcall` on Intel platforms
+and `vmmcall` on AMD platforms.
\ No newline at end of file
docs/guest-guide/x86/index.rst +1 -0
index 6927271e53..aaae42da5a 100644
@@ -7,4 +7,5 @@ x86
    :maxdepth: 2
 
    hypercall-abi
+   fastabi
    fixed-memory-layout
xen/abi/event_channel.yml new file +130 -0

130 lines not on this page · raw message

xen/abi/grant_table.yml new file +46 -0

46 lines not on this page · raw message

xen/abi/hvm.yml new file +50 -0

50 lines not on this page · raw message

xen/abi/memory.yml new file +11 -0
new file mode 100644
index 0000000000..8b51490f8a
@@ -0,0 +1,11 @@
+name: memory
+hypercall_index: 12
+
+subops:
+  memory_map:
+    index: 9
+    input:
+      nr_entries: 2
+      buffer: 3
+    c_lang:
+      struct: xen_memory_map
xen/abi/sched.yml new file +48 -0

48 lines not on this page · raw message

xen/abi/vcpu.yml new file +139 -0

139 lines not on this page · raw message

xen/abi/version.yml new file +15 -0
new file mode 100644
index 0000000000..bce64a4d69
@@ -0,0 +1,15 @@
+name: version
+hypercall_index: 17
+
+subops:
+  version:
+    index: 0
+
+  get_features:
+    index: 6
+    input:
+      submap_idx: 2
+    output:
+      submap: 3
+    c_lang:
+      struct: xen_feature_info
xen/include/public/arch-x86/cpuid.h +4 -0
index 3bb0dd249f..ff44ce0e7b 100644
@@ -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)
Signature · 9 lines
2.50.1



Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#24 lore raw

RFC PATCH 9/9 tools: Introduce abi-tool

In reply to Teddy Astie

abi-tool is a small Rust tool that is able to parse ABI yaml files and generate C stubs for performing hypercalls.

---
Usage :
./abi-tool < abi.yaml > abi.h

---
 xen/tools/abi-tool/.gitignore    |   1 +
 xen/tools/abi-tool/Cargo.lock    | 145 ++++++++++++++++++++++++++
 xen/tools/abi-tool/Cargo.toml    |  11 ++
 xen/tools/abi-tool/src/abi.rs    |  23 ++++
 xen/tools/abi-tool/src/c_lang.rs | 173 +++++++++++++++++++++++++++++++
 xen/tools/abi-tool/src/main.rs   |  17 +++
 xen/tools/abi-tool/src/spec.rs   |  61 +++++++++++
 7 files changed, 431 insertions(+)
 create mode 100644 xen/tools/abi-tool/.gitignore
 create mode 100644 xen/tools/abi-tool/Cargo.lock
 create mode 100644 xen/tools/abi-tool/Cargo.toml
 create mode 100644 xen/tools/abi-tool/src/abi.rs
 create mode 100644 xen/tools/abi-tool/src/c_lang.rs
 create mode 100644 xen/tools/abi-tool/src/main.rs
 create mode 100644 xen/tools/abi-tool/src/spec.rs
xen/tools/abi-tool/.gitignore new file +1 -0
new file mode 100644
index 0000000000..1de565933b
@@ -0,0 +1 @@
+target
\ No newline at end of file
xen/tools/abi-tool/Cargo.lock new file +145 -0

145 lines not on this page · raw message

xen/tools/abi-tool/Cargo.toml new file +11 -0
new file mode 100644
index 0000000000..eee8ad18a9
@@ -0,0 +1,11 @@
+[package]
+name = "abi-tool"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
+anyhow = "1.0.98"
+bimap = { version = "0.6.3", features = ["serde"] }
+indexmap = { version = "2.10.0", features = ["arbitrary", "serde"] }
+serde = { version = "1.0.219", features = ["derive"] }
+serde_yaml = "0.9.34"
xen/tools/abi-tool/src/abi.rs new file +23 -0
new file mode 100644
index 0000000000..9ca427e821
@@ -0,0 +1,23 @@
+pub trait XenABI {
+    fn get_register_name(id: u8) -> &'static str;
+}
+
+pub struct Amd64ABI;
+
+impl XenABI for Amd64ABI {
+    fn get_register_name(id: u8) -> &'static str {
+        match id {
+            0 => "rax",
+            1 => "rdi",
+            2 => "rsi",
+            3 => "r8",
+            4 => "r9",
+            5 => "r10",
+            6 => "r11",
+            7 => "r12",
+            8 => "r13",
+
+            _ => panic!("Unexpected register id: {id}"),
+        }
+    }
+}
xen/tools/abi-tool/src/c_lang.rs new file +173 -0

173 lines not on this page · raw message

xen/tools/abi-tool/src/main.rs new file +17 -0
new file mode 100644
index 0000000000..dda85c24d5
@@ -0,0 +1,17 @@
+use std::io::{Read, stdin};
+
+pub mod abi;
+pub mod c_lang;
+pub mod spec;
+
+fn main() {
+    let mut buffer = String::new();
+    stdin().read_to_string(&mut buffer).unwrap();
+
+    let abi_spec: spec::AbiSpec = serde_yaml::from_str(&buffer).unwrap();
+
+    let mut buffer = String::new();
+
+    c_lang::generate_code(&mut buffer, abi_spec).unwrap();
+    print!("{buffer}");
+}
xen/tools/abi-tool/src/spec.rs new file +61 -0

61 lines not on this page · raw message

Signature · 9 lines
2.50.1



Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#0 lore raw

cover x86/hvm: New Xen HVM ABI proposal ("HVMv2" part 1)

Hello, this series introduce a new hypercall ABI proposal (x86 only for now).

The current Xen ABI has some shortcommings :

First, the hypercall parameters are usually pointers that point to a structure in guest memory, this pointer is usually a virtual address.
It causes various issues as :
- you need to define a format for these structures which is currently C structures, but it complicates support with non LP64 platforms (e.g Windows) or other programming languages (e.g Rust, where solutions are hard to come with)
- the translation from virtual address to machine physical address is very expensive as you need to translate the GVA to GPA, and then GPA to HPA each time you want to access a virtual address
- such virtual addresses are not readable under confidential computing guests which makes such new ABI required.

Another issue is that all possible Xen hypercalls are exposed through this single interface, it makes hardening the hypervisor more complicated as you need to permission check on a per-hypercall basis (e.g through XSM) instead of having a minimal strict safe-for-guest-use set of operations.

The current ABI allows the guest to modify its physmap; this is notably used for mapping the shared info, grant table and ballooning. While we could make that work for confidential guests. It comes with its own set of problems, and in order to simplify the memory management, this series come with a proposal for mapping these specific pages in advance and telling the guest the location. That helps reducing the scope of this new ABI. Ballooning implementation hasn't been fully considered yet.

This series propose a new hypercall interface designed for use by guests kernels with high performance (low hypercall overhead) and confidential computing environments (notably AMD SEV) compatibility in mind. It currently only supports x86 long mode (64-bits) due to specific register requirements.

It doesn't aim to entirely replace the current ABI, but to propose a alternative one that could be used by guests as a fast-path ABI or for confidential computing guests.

This new ABI maps into current many operations (with some limitations), a tool is provided to generate C stubs using the yaml specification.
These C stubs reuse the existing hypercall structures to ease adding support for this ABI in guests.

You can find some example generated headers in Linux SEV WIP branch [1].

[1] https://github.com/xcp-ng/linux/tree/xen-sev-6.14/include/xen/interface/fastabi

Teddy Astie (9):
x86/hvm: Use direct structures instead of guest handles
common: Isolate XENVER_get_features into a separate function common/grant_table: Use direct structures instead of guest handles
hvm: Introduce "fixed memory layout" feature
docs/x86: Introduce FastABI
sched: Extract do_poll main logic into vcpu_poll x86/hvm: Introduce FastABI implementation
hvm: Introduce XEN_HVM_MEMMAP_TYPE_HOTPLUG_ZONE
tools: Introduce abi-tool

 docs/guest-guide/x86/fastabi.pandoc           |  50 +++++
 .../x86/fixed-memory-layout.pandoc            |  24 ++
 docs/guest-guide/x86/index.rst                |   2 +
 tools/include/xen-tools/common-macros.h       |   4 +
 tools/libs/guest/xg_dom_x86.c                 |  84 +++++++
 tools/libs/light/libxl_create.c               |   1 +
 tools/libs/light/libxl_types.idl              |   1 +
 tools/libs/light/libxl_x86.c                  |  71 ++++++
 tools/xl/xl_parse.c                           |   1 +
 xen/abi/event_channel.yml                     | 130 +++++++++++
 xen/abi/grant_table.yml                       |  46 ++++
 xen/abi/hvm.yml                               |  50 +++++
 xen/abi/memory.yml                            |  11 +
 xen/abi/sched.yml                             |  48 ++++
 xen/abi/vcpu.yml                              | 139 ++++++++++++
 xen/abi/version.yml                           |  15 ++
 xen/arch/x86/cpuid.c                          |   3 +
 xen/arch/x86/domain.c                         |  71 ++++++
 xen/arch/x86/hvm/hvm.c                        | 205 +++++++++++++-----
 xen/arch/x86/hvm/hypercall.c                  |  22 ++
 xen/arch/x86/include/asm/fastabi.h            |  17 ++
 xen/common/Kconfig                            |   6 +
 xen/common/Makefile                           |   1 +
 xen/common/domain.c                           | 179 +++++++++++++++
 xen/common/event_channel.c                    | 199 +++++++++++++++++
 xen/common/fastabi.c                          |  49 +++++
 xen/common/grant_table.c                      | 112 +++++++---
 xen/common/kernel.c                           | 117 ++++++----
 xen/common/memory.c                           | 110 ++++++++++
 xen/common/sched/core.c                       | 149 +++++++++++--
 xen/include/public/arch-x86/cpuid.h           |   4 +
 xen/include/public/arch-x86/hvm/start_info.h  |   8 +
 xen/include/public/event_channel.h            |   7 +
 xen/include/public/fastabi.h                  |  20 ++
 xen/include/xen/fastabi.h                     |  21 ++
 xen/tools/abi-tool/.gitignore                 |   1 +
 xen/tools/abi-tool/Cargo.lock                 | 145 +++++++++++++
 xen/tools/abi-tool/Cargo.toml                 |  11 +
 xen/tools/abi-tool/src/abi.rs                 |  23 ++
 xen/tools/abi-tool/src/c_lang.rs              | 173 +++++++++++++++
 xen/tools/abi-tool/src/main.rs                |  17 ++
 xen/tools/abi-tool/src/spec.rs                |  61 ++++++
 42 files changed, 2265 insertions(+), 143 deletions(-)
 create mode 100644 docs/guest-guide/x86/fastabi.pandoc
 create mode 100644 docs/guest-guide/x86/fixed-memory-layout.pandoc
 create mode 100644 xen/abi/event_channel.yml
 create mode 100644 xen/abi/grant_table.yml
 create mode 100644 xen/abi/hvm.yml
 create mode 100644 xen/abi/memory.yml
 create mode 100644 xen/abi/sched.yml
 create mode 100644 xen/abi/vcpu.yml
 create mode 100644 xen/abi/version.yml
 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
 create mode 100644 xen/tools/abi-tool/.gitignore
 create mode 100644 xen/tools/abi-tool/Cargo.lock
 create mode 100644 xen/tools/abi-tool/Cargo.toml
 create mode 100644 xen/tools/abi-tool/src/abi.rs
 create mode 100644 xen/tools/abi-tool/src/c_lang.rs
 create mode 100644 xen/tools/abi-tool/src/main.rs
 create mode 100644 xen/tools/abi-tool/src/spec.rs
Signature · 9 lines
2.50.1



Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#18 lore raw

RFC PATCH 6/9 sched: Extract do_poll main logic into vcpu_poll

do_poll takes sched_poll* as parameter, but that's actually in guest memory (so it's more a guest handle). Split its copy from/to guest logic from the main logic, so that we have a separate vcpu_poll which takes the sched_poll parameters directly.

---
 xen/common/sched/core.c | 40 +++++++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 19 deletions(-)
xen/common/sched/core.c +21 -19
index 13fdf57e57..b2c784c60e 100644
@@ -1437,21 +1437,13 @@ static void vcpu_block_enable_events(void)
     vcpu_block();
 }
 
-static long do_poll(const struct sched_poll *sched_poll)
+static long vcpu_poll(unsigned int nr_ports, uint64_t timeout, evtchn_port_t *ports)
 {
     struct vcpu   *v = current;
     struct domain *d = v->domain;
-    evtchn_port_t  port = 0;
     long           rc;
     unsigned int   i;
 
-    /* Fairly arbitrary limit. */
-    if ( sched_poll->nr_ports > 128 )
-        return -EINVAL;
-
-    if ( !guest_handle_okay(sched_poll->ports, sched_poll->nr_ports) )
-        return -EFAULT;
-
     set_bit(_VPF_blocked, &v->pause_flags);
     v->poll_evtchn = -1;
     set_bit(v->vcpu_id, d->poll_mask);
@@ -1478,13 +1470,9 @@ static long do_poll(const struct sched_poll *sched_poll)
     if ( local_events_need_delivery() )
         goto out;
 
-    for ( i = 0; i < sched_poll->nr_ports; i++ )
+    for ( i = 0; i < nr_ports; i++ )
     {
-        rc = -EFAULT;
-        if ( __copy_from_guest_offset(&port, sched_poll->ports, i, 1) )
-            goto out;
-
-        rc = evtchn_port_poll(d, port);
+        rc = evtchn_port_poll(d, ports[i]);
         if ( rc )
         {
             if ( rc > 0 )
@@ -1493,11 +1481,11 @@ static long do_poll(const struct sched_poll *sched_poll)
         }
     }
 
-    if ( sched_poll->nr_ports == 1 )
-        v->poll_evtchn = port;
+    if ( nr_ports == 1 )
+        v->poll_evtchn = ports[0];
 
-    if ( sched_poll->timeout != 0 )
-        set_timer(&v->poll_timer, sched_poll->timeout);
+    if ( timeout != 0 )
+        set_timer(&v->poll_timer, timeout);
 
     TRACE_TIME(TRC_SCHED_BLOCK, d->domain_id, v->vcpu_id);
     raise_softirq(SCHEDULE_SOFTIRQ);
@@ -1511,6 +1499,20 @@ static long do_poll(const struct sched_poll *sched_poll)
     return rc;
 }
 
+static long do_poll(struct sched_poll *sched_poll)
+{
+    evtchn_port_t ports[128];
+
+    /* Fairly arbitrary limit */
+    if ( sched_poll->nr_ports > 128 )
+        return -EINVAL;
+
+    if ( copy_from_guest(ports, sched_poll->ports, sched_poll->nr_ports) )
+        return -EFAULT;
+
+    return vcpu_poll(sched_poll->nr_ports, sched_poll->timeout, ports);
+}
+
 /* Voluntarily yield the processor for this allocation. */
 long vcpu_yield(void)
 {
Signature · 9 lines
2.50.1



Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#1 lore raw

RFC PATCH 1/9 x86/hvm: Use direct structures instead of guest handles

In reply to Teddy Astie

Make these functions work with hypervisor-owned pointer rather than guest handles, so the function parameters don't have to live in guest memory.

No functional changes intended.

---
 xen/arch/x86/hvm/hvm.c | 126 +++++++++++++++++++++++------------------
 1 file changed, 70 insertions(+), 56 deletions(-)
xen/arch/x86/hvm/hvm.c +70 -56
index 56c7de3977..8bf59c63fe 100644
@@ -4142,19 +4142,14 @@ static int hvmop_flush_tlb_all(void)
     return paging_flush_tlb(NULL) ? 0 : -ERESTART;
 }
 
-static int hvmop_set_evtchn_upcall_vector(
-    XEN_GUEST_HANDLE_PARAM(xen_hvm_evtchn_upcall_vector_t) uop)
+static int hvmop_set_evtchn_upcall_vector(xen_hvm_evtchn_upcall_vector_t op)
 {
-    xen_hvm_evtchn_upcall_vector_t op;
     struct domain *d = current->domain;
     struct vcpu *v;
 
     if ( !is_hvm_domain(d) )
         return -EINVAL;
 
-    if ( copy_from_guest(&op, uop, 1) )
-        return -EFAULT;
-
     if ( op.vector < 0x10 )
         return -EINVAL;
 
@@ -4434,26 +4429,21 @@ static int hvm_set_param(struct domain *d, uint32_t index, uint64_t value)
     return rc;
 }
 
-static int hvmop_set_param(
-    XEN_GUEST_HANDLE_PARAM(xen_hvm_param_t) arg)
+static int hvmop_set_param(struct xen_hvm_param op)
 {
-    struct xen_hvm_param a;
     struct domain *d;
     int rc;
 
-    if ( copy_from_guest(&a, arg, 1) )
-        return -EFAULT;
-
-    if ( a.index >= HVM_NR_PARAMS )
+    if ( op.index >= HVM_NR_PARAMS )
         return -EINVAL;
 
-    d = rcu_lock_domain_by_any_id(a.domid);
+    d = rcu_lock_domain_by_any_id(op.domid);
     if ( d == NULL )
         return -ESRCH;
 
     rc = -EINVAL;
     if ( is_hvm_domain(d) )
-        rc = hvm_set_param(d, a.index, a.value);
+        rc = hvm_set_param(d, op.index, op.value);
 
     rcu_unlock_domain(d);
     return rc;
@@ -4544,31 +4534,21 @@ int hvm_get_param(struct domain *d, uint32_t index, uint64_t *value)
     return 0;
 };
 
-static int hvmop_get_param(
-    XEN_GUEST_HANDLE_PARAM(xen_hvm_param_t) arg)
+static int hvmop_get_param(struct xen_hvm_param *op)
 {
-    struct xen_hvm_param a;
     struct domain *d;
     int rc;
 
-    if ( copy_from_guest(&a, arg, 1) )
-        return -EFAULT;
-
-    if ( a.index >= HVM_NR_PARAMS )
+    if ( op->index >= HVM_NR_PARAMS )
         return -EINVAL;
 
-    d = rcu_lock_domain_by_any_id(a.domid);
+    d = rcu_lock_domain_by_any_id(op->domid);
     if ( d == NULL )
         return -ESRCH;
 
     rc = -EINVAL;
-    if ( is_hvm_domain(d) && !(rc = hvm_get_param(d, a.index, &a.value)) )
-    {
-        rc = __copy_to_guest(arg, &a, 1) ? -EFAULT : 0;
-
-        HVM_DBG_LOG(DBG_LEVEL_HCALL, "get param %u = %"PRIx64,
-                    a.index, a.value);
-    }
+    if ( is_hvm_domain(d) && !(rc = hvm_get_param(d, op->index, &op->value)) )
+        HVM_DBG_LOG(DBG_LEVEL_HCALL, "get param %u = %"PRIx64, a.index, a.value);
 
     rcu_unlock_domain(d);
     return rc;
@@ -5046,18 +5026,13 @@ static int compat_altp2m_op(
     return rc;
 }
 
-static int hvmop_get_mem_type(
-    XEN_GUEST_HANDLE_PARAM(xen_hvm_get_mem_type_t) arg)
+static int hvmop_get_mem_type(struct xen_hvm_get_mem_type *op)
 {
-    struct xen_hvm_get_mem_type a;
     struct domain *d;
     p2m_type_t t;
     int rc;
 
-    if ( copy_from_guest(&a, arg, 1) )
-        return -EFAULT;
-
-    d = rcu_lock_domain_by_any_id(a.domid);
+    d = rcu_lock_domain_by_any_id(op->domid);
     if ( d == NULL )
         return -ESRCH;
 
@@ -5074,25 +5049,22 @@ static int hvmop_get_mem_type(
      * type, not in allocating or unsharing. That'll happen
      * on access.
      */
-    get_gfn_query_unlocked(d, a.pfn, &t);
+    get_gfn_query_unlocked(d, op->pfn, &t);
     if ( p2m_is_mmio(t) )
-        a.mem_type =  HVMMEM_mmio_dm;
+        op->mem_type =  HVMMEM_mmio_dm;
     else if ( t == p2m_ioreq_server )
-        a.mem_type = HVMMEM_ioreq_server;
+        op->mem_type = HVMMEM_ioreq_server;
     else if ( p2m_is_readonly(t) )
-        a.mem_type =  HVMMEM_ram_ro;
+        op->mem_type =  HVMMEM_ram_ro;
     else if ( p2m_is_ram(t) )
-        a.mem_type =  HVMMEM_ram_rw;
+        op->mem_type =  HVMMEM_ram_rw;
     else if ( p2m_is_pod(t) )
-        a.mem_type =  HVMMEM_ram_rw;
+        op->mem_type =  HVMMEM_ram_rw;
     else if ( p2m_is_grant(t) )
-        a.mem_type =  HVMMEM_ram_rw;
+        op->mem_type =  HVMMEM_ram_rw;
     else
-        a.mem_type =  HVMMEM_mmio_dm;
+        op->mem_type =  HVMMEM_mmio_dm;
 
-    rc = -EFAULT;
-    if ( __copy_to_guest(arg, &a, 1) )
-        goto out;
     rc = 0;
 
  out:
@@ -5115,28 +5087,70 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
     switch ( op )
     {
     case HVMOP_set_evtchn_upcall_vector:
-        rc = hvmop_set_evtchn_upcall_vector(
-            guest_handle_cast(arg, xen_hvm_evtchn_upcall_vector_t));
+    {
+        struct xen_hvm_evtchn_upcall_vector op;
+
+        if ( copy_from_guest(&op, arg, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }
+
+        rc = hvmop_set_evtchn_upcall_vector(op);
         break;
+    }
     
     case HVMOP_set_param:
-        rc = hvmop_set_param(
-            guest_handle_cast(arg, xen_hvm_param_t));
+    {
+        struct xen_hvm_param op;
+        
+        if ( copy_from_guest(&op, arg, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }
+
+        rc = hvmop_set_param(op);
         break;
+    }
 
     case HVMOP_get_param:
-        rc = hvmop_get_param(
-            guest_handle_cast(arg, xen_hvm_param_t));
+    {
+        struct xen_hvm_param op;
+        
+        if ( copy_from_guest(&op, arg, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }
+
+        rc = hvmop_get_param(&op);
+
+        if ( !rc && copy_to_guest(arg, &op, 1) )
+            rc = -EFAULT;
         break;
+    }
 
     case HVMOP_flush_tlbs:
         rc = guest_handle_is_null(arg) ? hvmop_flush_tlb_all() : -EINVAL;
         break;
 
     case HVMOP_get_mem_type:
-        rc = hvmop_get_mem_type(
-            guest_handle_cast(arg, xen_hvm_get_mem_type_t));
+    {
+        struct xen_hvm_get_mem_type op;
+
+        if ( copy_from_guest(&op, arg, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }
+        
+        rc = hvmop_get_mem_type(&op);
+
+        if ( !rc && copy_to_guest(arg, &op, 1) )
+            rc = -EFAULT;
         break;
+    }
 
     case HVMOP_pagetable_dying:
     {
Signature · 9 lines
2.50.1



Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#21 lore raw

RFC PATCH 8/9 hvm: Introduce XEN_HVM_MEMMAP_TYPE_HOTPLUG_ZONE

In reply to Teddy Astie

Allow specifying in memory map a region which can be hotplugged.

This will be used by a future memory hotplug feature.

---
 xen/include/public/arch-x86/hvm/start_info.h | 1 +
 1 file changed, 1 insertion(+)
xen/include/public/arch-x86/hvm/start_info.h +1 -0
index 0b3dfe91af..bdae8371d6 100644
@@ -105,6 +105,7 @@
 #define XEN_HVM_MEMMAP_TYPE_GNTTAB_STATUS 0xF0000003 /* Grant table status page (v2) */
 #define XEN_HVM_MEMMAP_TYPE_FOREIGN_REG   0xF0000004 /* Suitable region for grant mappings */
                                                      /* and foreign mappings */
+#define XEN_HVM_MEMMAP_TYPE_HOTPLUG_ZONE  0xF0000005 /* Memory hotpluggable zone */
 
 /*
  * C representation of the x86/HVM start info layout.
Signature · 9 lines
2.50.1



Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#20 lore raw

RFC PATCH 7/9 x86/hvm: Introduce FastABI implementation

In reply to Teddy Astie

Implement FastABI basing on docs/guest-guide/x86/fastabi.pandoc and defined ABI.

---
 xen/arch/x86/cpuid.c               |   3 +
 xen/arch/x86/domain.c              |  71 ++++++++++
 xen/arch/x86/hvm/hvm.c             |  81 +++++++++++-
 xen/arch/x86/hvm/hypercall.c       |  22 ++++
 xen/arch/x86/include/asm/fastabi.h |  17 +++
 xen/common/Kconfig                 |   6 +
 xen/common/Makefile                |   1 +
 xen/common/domain.c                | 179 ++++++++++++++++++++++++++
 xen/common/event_channel.c         | 199 +++++++++++++++++++++++++++++
 xen/common/fastabi.c               |  49 +++++++
 xen/common/grant_table.c           |  44 +++++++
 xen/common/kernel.c                |  33 +++++
 xen/common/memory.c                | 110 ++++++++++++++++
 xen/common/sched/core.c            | 109 +++++++++++++++-
 xen/include/public/event_channel.h |   7 +
 xen/include/public/fastabi.h       |  20 +++
 xen/include/xen/fastabi.h          |  21 +++
 17 files changed, 970 insertions(+), 2 deletions(-)
 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
xen/arch/x86/cpuid.c +3 -0
index 8dc68945f7..b1f90c1d91 100644
@@ -153,6 +153,9 @@ static void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf,
          */
         res->a |= XEN_HVM_CPUID_UPCALL_VECTOR;
 
+        if ( IS_ENABLED(CONFIG_FASTABI) && is_hvm_vcpu(v) )
+            res->a |= XEN_HVM_CPUID_FASTABI;
+
         break;
 
     case 5: /* PV-specific parameters */
xen/arch/x86/domain.c +71 -0

83 lines not on this page · raw message

xen/arch/x86/hvm/hvm.c +80 -1

99 lines not on this page · raw message

xen/arch/x86/hvm/hypercall.c +22 -0
index 6f8dfdff4a..3759a1aa58 100644
@@ -19,6 +19,10 @@
 #include <public/hvm/hvm_op.h>
 #include <public/hvm/params.h>
 
+#ifdef CONFIG_FASTABI
+#include <xen/fastabi.h>
+#endif
+
 long hvm_memory_op(unsigned long cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
 {
     long rc;
@@ -155,6 +159,24 @@ int hvm_hypercall(struct cpu_user_regs *regs)
 
     curr->hcall_preempted = false;
 
+    #ifdef CONFIG_FASTABI
+    if ( eax & 0x40000000U && is_hvm_domain(currd) && mode == X86_MODE_64BIT )
+    {
+        unsigned long index = eax & ~0x40000000U;
+        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 HVM_HCALL_completed;
+    }
+    #endif
+
     if ( mode == 8 )
     {
         HVM_DBG_LOG(DBG_LEVEL_HCALL, "hcall%lu(%lx, %lx, %lx, %lx, %lx)",
xen/arch/x86/include/asm/fastabi.h new file +17 -0
new file mode 100644
index 0000000000..914504c63d
@@ -0,0 +1,17 @@
+#ifndef XEN_ASM_FASTABI_H
+#define XEN_ASM_FASTABI_H
+
+#include <asm/current.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
xen/common/Kconfig +6 -0
index 65f07289dd..71bb4e4f2d 100644
@@ -636,4 +636,10 @@ config PM_STATS
 	  Enable collection of performance management statistics to aid in
 	  analyzing and tuning power/performance characteristics of the system
 
+config FASTABI
+	depends on X86 && HVM
+	bool "Fast HVM ABI (unsupported)"
+	help
+		Add support for a alternative fast HVM ABI.
+
 endmenu
xen/common/Makefile +1 -0
index 98f0873056..362e8f61d7 100644
@@ -62,6 +62,7 @@ obj-y += wait.o
 obj-bin-y += warning.init.o
 obj-$(CONFIG_XENOPROF) += xenoprof.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 earlycpio,$(n).init.o)
 
xen/common/domain.c +179 -0

191 lines not on this page · raw message

xen/common/event_channel.c +199 -0

211 lines not on this page · raw message

xen/common/fastabi.c new file +49 -0

50 lines not on this page · raw message

xen/common/grant_table.c +44 -0

56 lines not on this page · raw message

xen/common/kernel.c +33 -0
index eff6db6c8f..2230ccdcaf 100644
@@ -18,6 +18,10 @@
 #include <asm/current.h>
 #include <public/version.h>
 
+#ifdef CONFIG_FASTABI
+#include <xen/fastabi.h>
+#endif
+
 #ifdef CONFIG_COMPAT
 #include <compat/version.h>
 
@@ -772,6 +776,35 @@ long do_xen_version(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
     return -ENOSYS;
 }
 
+#ifdef CONFIG_FASTABI
+void do_xen_version_fast_op(struct cpu_user_regs *regs)
+{
+    long cmd = fastabi_value_n(regs, 1);
+    long rc = 0;
+
+    switch ( cmd ) {
+    case XENVER_version:
+        rc = (xen_major_version() << 16) | xen_minor_version();
+        break;
+    case XENVER_get_features:
+    {
+        uint32_t submap = 0, submap_idx = fastabi_value_n(regs, 2);
+
+        rc = xenver_get_features(current->domain, submap_idx, &submap);
+
+        if ( !rc )
+            fastabi_value_n(regs, 3) = submap;
+        break;
+    }
+    default:
+        rc = -ENOSYS;
+        break;
+    }
+
+    fastabi_value_n(regs, 0) = rc;
+}
+#endif
+
 /*
  * Local variables:
  * mode: C
xen/common/memory.c +110 -0

122 lines not on this page · raw message

xen/common/sched/core.c +108 -1

127 lines not on this page · raw message

xen/include/public/event_channel.h +7 -0
index c5548d206c..969c9ec264 100644
@@ -208,10 +208,17 @@ struct evtchn_status {
         } unbound;                 /* EVTCHNSTAT_unbound */
         struct {
             domid_t dom;
+            uint16_t _pad;
             evtchn_port_t port;
         } interdomain;             /* EVTCHNSTAT_interdomain */
         uint32_t pirq;             /* EVTCHNSTAT_pirq        */
         uint32_t virq;             /* EVTCHNSTAT_virq        */
+#ifndef __XEN__
+        struct {
+            uint32_t _output1;
+            uint32_t _output2;
+        };
+#endif
     } u;
 };
 typedef struct evtchn_status evtchn_status_t;
xen/include/public/fastabi.h new file +20 -0
new file mode 100644
index 0000000000..51f5085ce6
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: MIT */
+#ifndef __XEN_PUBLIC_FASTABI_H__
+#define __XEN_PUBLIC_FASTABI_H__
+
+#if defined(__x86_64__)
+#define __HYPERVISOR_FASTABI_MASK 0x40000000U
+
+enum xen_hypercall_vendor {
+    Intel,
+    Amd
+};
+#else
+#define __HYPERVISOR_FASTABI_MASK 0
+
+enum xen_hypercall_vendor {
+    Native
+};
+#endif
+
+#endif
xen/include/xen/fastabi.h new file +21 -0
new file mode 100644
index 0000000000..83ede943e0
@@ -0,0 +1,21 @@
+/* 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);
+
+void do_event_channel_fast_op(struct cpu_user_regs *regs);
+
+long common_vcpu_fast_op(struct cpu_user_regs *regs, int cmd, struct vcpu *v);
+void do_vcpu_fast_op(struct cpu_user_regs *regs);
+void do_hvm_fast_op(struct cpu_user_regs *regs);
+void do_memory_fast_op(struct cpu_user_regs *regs);
+void do_grant_table_fast_op(struct cpu_user_regs *regs);
+void do_sched_fast_op(struct cpu_user_regs *regs);
+void do_xen_version_fast_op(struct cpu_user_regs *regs);
+
+#endif /* XEN_FASTABI_H */
\ No newline at end of file
Signature · 9 lines
2.50.1



Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#25 lore raw

Re: [RFC PATCH 9/9] tools: Introduce abi-tool

In reply to Teddy Astie
Quoted 4 lines · Teddy Astie

abi-tool is a small Rust tool that is able to parse ABI yaml files and generate C stubs for performing hypercalls.

Would it make sense to generate the hypervisor side of the interface in this way as well?

Signature · 2 lines
Sincerely,
Demi Marie Obenour (she/her/hers)
#2 lore raw

Re: [RFC PATCH 1/9] x86/hvm: Use direct structures instead of guest handles

In reply to Teddy Astie
Quoted 2 lines · Teddy Astie

Make these functions work with hypervisor-owned pointer rather than guest handles, so the function parameters don't have to live in guest memory.

This is odd to read - the function parameters (arguments) didn't live in guest memory before either.

Quoted 12 lines

No functional changes intended.

---
 xen/arch/x86/hvm/hvm.c | 126 +++++++++++++++++++++++------------------
 1 file changed, 70 insertions(+), 56 deletions(-)
xen/arch/x86/hvm/hvm.c +0 -0
index 56c7de3977..8bf59c63fe 100644

xen/arch/x86/hvm/hvm.c static int hvmop_flush_tlb_all(void) · line 4145

Quoted 6 lines
xen/arch/x86/hvm/hvm.c +1 -2
@@ -4142,19 +4142,14 @@ static int hvmop_flush_tlb_all(void)
     return paging_flush_tlb(NULL) ? 0 : -ERESTART;
 }
 
-static int hvmop_set_evtchn_upcall_vector(
-    XEN_GUEST_HANDLE_PARAM(xen_hvm_evtchn_upcall_vector_t) uop)
+static int hvmop_set_evtchn_upcall_vector(xen_hvm_evtchn_upcall_vector_t op)

Please can we avoid passing structures by value?

More generally: This one-by-one adjustment is what I'd really like to avoid with any new interface. It would be far better if ...

xen/arch/x86/hvm/hvm.c static int hvmop_flush_tlb_all(void) · line 4156

Quoted 10 lines
xen/arch/x86/hvm/hvm.c +0 -3
 {
-    xen_hvm_evtchn_upcall_vector_t op;
     struct domain *d = current->domain;
     struct vcpu *v;
 
     if ( !is_hvm_domain(d) )
         return -EINVAL;
 
-    if ( copy_from_guest(&op, uop, 1) )
-        return -EFAULT;

... copy_from_guest() could transparantly handle both cases (virtual and physical addresses being used). And yes, this would exclude an "everying in registers" approach.

Quoted 40 lines
xen/arch/x86/hvm/hvm.c +24 -6
@@ -5115,28 +5087,70 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
     switch ( op )
     {
     case HVMOP_set_evtchn_upcall_vector:
-        rc = hvmop_set_evtchn_upcall_vector(
-            guest_handle_cast(arg, xen_hvm_evtchn_upcall_vector_t));
+    {
+        struct xen_hvm_evtchn_upcall_vector op;
+
+        if ( copy_from_guest(&op, arg, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }
+
+        rc = hvmop_set_evtchn_upcall_vector(op);
         break;
+    }
 
     case HVMOP_set_param:
-        rc = hvmop_set_param(
-            guest_handle_cast(arg, xen_hvm_param_t));
+    {
+        struct xen_hvm_param op;
+        
+        if ( copy_from_guest(&op, arg, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }
+
+        rc = hvmop_set_param(op);
         break;
+    }
 
     case HVMOP_get_param:
-        rc = hvmop_get_param(
-            guest_handle_cast(arg, xen_hvm_param_t));
+    {
+        struct xen_hvm_param op;

xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5129

Quoted 10 lines
xen/arch/x86/hvm/hvm.c +10 -0
+        
+        if ( copy_from_guest(&op, arg, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }
+
+        rc = hvmop_get_param(&op);
+
+        if ( !rc && copy_to_guest(arg, &op, 1) )

Why would the original __copy_to_guest() need to change to copy_to_guest()?

Jan

#5 lore raw

Re: [RFC PATCH 2/9] common: Isolate XENVER_get_features into a separate function

In reply to Teddy Astie
Quoted 2 lines · Teddy Astie

Make do_xen_version more readable by moving the main XENVER_get_features into a separate function.

I can't spot much of a readability gain, to be honest.

xen/common/kernel.c static long xenver_varbuf_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) · line 572

Quoted 7 lines
xen/common/kernel.c +1 -0
@@ -569,6 +569,50 @@ static long xenver_varbuf_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
     return sz;
 }
 
+static long xenver_get_features(struct domain *d, uint32_t submap_idx, uint32_t *submap)

Why "long", when you only return "int" -errno values?

Speaking of "long", why such long a line?

Jan

#7 lore raw

Re: [RFC PATCH 3/9] common/grant_table: Use direct structures instead of guest handles

In reply to Teddy Astie
Quoted 6 lines · Teddy Astie

Make these functions work with hypervisor-owned pointer rather than guest handles, so the function parameters don't have to live in guest memory.

No functional changes.

Unlike title/description suggest, this only touched two out of many sub-ops. As others don't lend themselves to your goal, that makes things overall inconsistent, for a questionable gain.

Jan

#9 lore raw

Re: [RFC PATCH 4/9] hvm: Introduce "fixed memory layout" feature

In reply to Teddy Astie

tools/libs/light/libxl_x86.c static int domain_construct_memmap(libxl__gc *gc, · line 701

Quoted 12 lines · Teddy Astie
tools/libs/light/libxl_x86.c +4 -0
@@ -686,10 +691,31 @@ static int domain_construct_memmap(libxl__gc *gc,
     /* We always own at least one lowmem entry. */
     unsigned int e820_entries = 1;
     struct e820entry *e820 = NULL;
+    uint64_t highmem_start = ((uint64_t)1 << 32);
     uint64_t highmem_size =
                     dom->highmem_end ? dom->highmem_end - (1ull << 32) : 0;
     uint32_t lowmem_start = dom->device_model ? GUEST_LOW_MEM_START_DEFAULT : 0;
     unsigned page_size = XC_DOM_PAGE_SIZE(dom);
+    /* Special region starts at the first 1G boundary after the highmem */
+    uint64_t special_region_start =
+        (highmem_start + highmem_size + GB(1) - 1) & ~(GB(1) - 1);

That is, inaccessible before entering PAE mode?

The open-coding of ROUNDUP() also isn't nice, but sadly unavoidable as long the the macro works in terms of unsigned long.

Quoted 24 lines
tools/libs/light/libxl_x86.c +20 -0
@@ -769,6 +805,40 @@ static int domain_construct_memmap(libxl__gc *gc,
         e820[nr].type = E820_RAM;
     }
 
+    /* Special regions */
+    if (libxl_defbool_val(d_config->b_info.arch_x86.fixed_mem_layout))
+    {
+        e820[nr].type = XEN_HVM_MEMMAP_TYPE_SHARED_INFO;
+        e820[nr].addr = special_region_offset;
+        e820[nr].size = page_size;
+        special_region_offset += e820[nr].size;
+        nr++;
+
+        if ( gnttab_frame_count )
+        {
+            e820[nr].type = XEN_HVM_MEMMAP_TYPE_GRANT_TABLE;
+            e820[nr].addr = special_region_offset;
+            e820[nr].size = gnttab_frame_count * page_size;
+            special_region_offset += e820[nr].size;
+            nr++;
+        }
+
+        if (d_config->b_info.max_grant_version >= 2 && gnttab_status_frame_count)
+        {

tools/libs/light/libxl_x86.c static int domain_construct_memmap(libxl__gc *gc, · line 837

Quoted 10 lines
tools/libs/light/libxl_x86.c +10 -0
+            e820[nr].type = XEN_HVM_MEMMAP_TYPE_GNTTAB_STATUS;
+            e820[nr].addr = special_region_offset;
+            e820[nr].size = gnttab_status_frame_count * page_size;
+            special_region_offset += e820[nr].size;
+            nr++;
+        }
+
+        e820[nr].type = XEN_HVM_MEMMAP_TYPE_FOREIGN_REG;
+        e820[nr].addr = special_region_offset;
+        e820[nr].size = MB(512);

Can we really know this is going to be enough for all use cases?

xen/include/public/arch-x86/hvm/start_info.h line 107

Quoted 12 lines
xen/include/public/arch-x86/hvm/start_info.h +6 -0
@@ -99,6 +99,13 @@
 #define XEN_HVM_MEMMAP_TYPE_DISABLED  6
 #define XEN_HVM_MEMMAP_TYPE_PMEM      7
 
+/* Xen-specific types (OEM-specific range of the ACPI spec) */
+#define XEN_HVM_MEMMAP_TYPE_SHARED_INFO   0xF0000001 /* Shared info page */
+#define XEN_HVM_MEMMAP_TYPE_GRANT_TABLE   0xF0000002 /* Grant table pages */
+#define XEN_HVM_MEMMAP_TYPE_GNTTAB_STATUS 0xF0000003 /* Grant table status page (v2) */
+#define XEN_HVM_MEMMAP_TYPE_FOREIGN_REG   0xF0000004 /* Suitable region for grant mappings */
+                                                     /* and foreign mappings */

I question it being legitimate for us to introduce new E820 types.

Jan

#15 lore raw

Re: [RFC PATCH 5/9] docs/x86: Introduce FastABI

In reply to Teddy Astie
Quoted 6 lines · Teddy Astie

FastABI is a alternative ABI designed with performance and coco-enabled guest in mind. It is register-oriented instead of refering to C structures in the guest memory (through a virtual memory pointer).

It only focuses on kernel-side hypercalls, it doesn't aim to provide toolstack operations.

And even there it excludes certain pretty relevant ones, like many of the gnttabop sub-ops. As alluded to by a reply to an earlier patch, I don't think having an ABI for just a subset of the hypercalls is going to help.

Jan

#19 lore raw

Re: [RFC PATCH 6/9] sched: Extract do_poll main logic into vcpu_poll

In reply to Teddy Astie
Quoted 2 lines · Teddy Astie

do_poll takes sched_poll* as parameter, but that's actually in guest memory (so it's more a guest handle).

No, it's not, or else ...

Quoted 7 lines
xen/common/sched/core.c +0 -1
@@ -1437,21 +1437,13 @@ static void vcpu_block_enable_events(void)
     vcpu_block();
 }
 
-static long do_poll(const struct sched_poll *sched_poll)

xen/common/sched/core.c static void vcpu_block_enable_events(void) · line 1449

Quoted 10 lines
xen/common/sched/core.c +1 -3
+static long vcpu_poll(unsigned int nr_ports, uint64_t timeout, evtchn_port_t *ports)
 {
     struct vcpu   *v = current;
     struct domain *d = v->domain;
-    evtchn_port_t  port = 0;
     long           rc;
     unsigned int   i;
 
-    /* Fairly arbitrary limit. */
-    if ( sched_poll->nr_ports > 128 )

... this access would be a security issue. The handle is ...

xen/common/sched/core.c static void vcpu_block_enable_events(void) · line 1452

Quoted 3 lines
xen/common/sched/core.c +0 -3
-        return -EINVAL;
-
-    if ( !guest_handle_okay(sched_poll->ports, sched_poll->nr_ports) )

... seen here, the ->ports member.

Here as well as for patch 1 and 3 what is entirely lacking from the description is the mentioning of why the change is actually going to be useful.

Jan

#22 lore raw

Re: [RFC PATCH 8/9] hvm: Introduce XEN_HVM_MEMMAP_TYPE_HOTPLUG_ZONE

In reply to Teddy Astie
Quoted 3 lines · Teddy Astie

Allow specifying in memory map a region which can be hotplugged.

This will be used by a future memory hotplug feature.

Why could this not be done the ACPI way, with the regions properly specified in SRAT?

Jan

#3 lore raw

Re: [RFC PATCH 1/9] x86/hvm: Use direct structures instead of guest handles

In reply to Jan Beulich

Le 28/08/2025 à 14:16, Jan Beulich a écrit :

Quoted 7 lines · Teddy Astie
Quoted 2 lines

Make these functions work with hypervisor-owned pointer rather than guest handles, so the function parameters don't have to live in guest memory.

This is odd to read - the function parameters (arguments) didn't live in guest memory before either.

I agree, I should reword that so that it's less confusing.

Quoted 15 lines
Quoted 15 lines

No functional changes intended.

---
  xen/arch/x86/hvm/hvm.c | 126 +++++++++++++++++++++++------------------
  1 file changed, 70 insertions(+), 56 deletions(-)
xen/arch/x86/hvm/hvm.c +0 -0
index 56c7de3977..8bf59c63fe 100644
@@ -4142,19 +4142,14 @@ static int hvmop_flush_tlb_all(void)
      return paging_flush_tlb(NULL) ? 0 : -ERESTART;
  }
 
Quoted 6 lines

xen/arch/x86/hvm/hvm.c static int hvmop_flush_tlb_all(void) · line 4145

Quoted 3 lines
xen/arch/x86/hvm/hvm.c +1 -2
-static int hvmop_set_evtchn_upcall_vector(
-    XEN_GUEST_HANDLE_PARAM(xen_hvm_evtchn_upcall_vector_t) uop)
+static int hvmop_set_evtchn_upcall_vector(xen_hvm_evtchn_upcall_vector_t op)

Please can we avoid passing structures by value?

We could, but we would end up having to modify more code to go there i.e replacing all op.* with op->* which I tried to avoid here.

Quoted 11 lines

More generally: This one-by-one adjustment is what I'd really like to avoid with any new interface. It would be far better if ...

Quoted 8 lines
xen/arch/x86/hvm/hvm.c +0 -1
  {
-    xen_hvm_evtchn_upcall_vector_t op;
      struct domain *d = current->domain;
      struct vcpu *v;
 
      if ( !is_hvm_domain(d) )
          return -EINVAL;
 
Quoted 7 lines

xen/arch/x86/hvm/hvm.c static int hvmop_flush_tlb_all(void) · line 4156

Quoted 2 lines
xen/arch/x86/hvm/hvm.c +0 -2
-    if ( copy_from_guest(&op, uop, 1) )
-        return -EFAULT;

... copy_from_guest() could transparantly handle both cases (virtual and physical addresses being used). And yes, this would exclude an "everying in registers" approach.

A part of the goal here is to split the ABI part from the hypercall logic; such as it gets possible to have ABI that don't need to refer to guest addresses (either virtual or physical); and could help dealing with current 32-bits vs 64-bits ABIs. All without duplicating the main hypercall logic.

Quoted 44 lines
Quoted 44 lines
xen/arch/x86/hvm/hvm.c +28 -6
@@ -5115,28 +5087,70 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
      switch ( op )
      {
      case HVMOP_set_evtchn_upcall_vector:
-        rc = hvmop_set_evtchn_upcall_vector(
-            guest_handle_cast(arg, xen_hvm_evtchn_upcall_vector_t));
+    {
+        struct xen_hvm_evtchn_upcall_vector op;
+
+        if ( copy_from_guest(&op, arg, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }
+
+        rc = hvmop_set_evtchn_upcall_vector(op);
          break;
+    }
 
      case HVMOP_set_param:
-        rc = hvmop_set_param(
-            guest_handle_cast(arg, xen_hvm_param_t));
+    {
+        struct xen_hvm_param op;
+
+        if ( copy_from_guest(&op, arg, 1) )
+        {
+            rc = -EFAULT;
+            break;
+        }
+
+        rc = hvmop_set_param(op);
          break;
+    }
 
      case HVMOP_get_param:
-        rc = hvmop_get_param(
-            guest_handle_cast(arg, xen_hvm_param_t));
+    {
+        struct xen_hvm_param op;
+
+        if ( copy_from_guest(&op, arg, 1) )
+        {
+            rc = -EFAULT;
Quoted 9 lines

xen/arch/x86/hvm/hvm.c long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg) · line 5129

Quoted 6 lines
xen/arch/x86/hvm/hvm.c +6 -0
+            break;
+        }
+
+        rc = hvmop_get_param(&op);
+
+        if ( !rc && copy_to_guest(arg, &op, 1) )

Why would the original __copy_to_guest() need to change to copy_to_guest()?

That doesn't need to.

Quoted 1 line

Jan

Teddy

Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#10 lore raw

Re: [RFC PATCH 4/9] hvm: Introduce "fixed memory layout" feature

In reply to Jan Beulich

Le 28/08/2025 à 14:30, Jan Beulich a écrit :

Quoted 7 lines · Teddy Astie
Quoted 6 lines
tools/libs/light/libxl_x86.c +1 -0
@@ -686,10 +691,31 @@ static int domain_construct_memmap(libxl__gc *gc,
      /* We always own at least one lowmem entry. */
      unsigned int e820_entries = 1;
      struct e820entry *e820 = NULL;
+    uint64_t highmem_start = ((uint64_t)1 << 32);
      uint64_t highmem_size =
Quoted 9 lines

tools/libs/light/libxl_x86.c static int domain_construct_memmap(libxl__gc *gc, · line 701

Quoted 6 lines
tools/libs/light/libxl_x86.c +3 -0
                      dom->highmem_end ? dom->highmem_end - (1ull << 32) : 0;
      uint32_t lowmem_start = dom->device_model ? GUEST_LOW_MEM_START_DEFAULT : 0;
      unsigned page_size = XC_DOM_PAGE_SIZE(dom);
+    /* Special region starts at the first 1G boundary after the highmem */
+    uint64_t special_region_start =
+        (highmem_start + highmem_size + GB(1) - 1) & ~(GB(1) - 1);

That is, inaccessible before entering PAE mode?

Yes, I expect this to be only used by newer guests which hopefully aren't limited to 4G range (i.e supports PAE or long mode). The issue of trying to put that below 4G is that much of the space is already taken for the MMIO hole, so that area would quite complicated with more special regions.

Quoted 31 lines

The open-coding of ROUNDUP() also isn't nice, but sadly unavoidable as long the the macro works in terms of unsigned long.

Quoted 28 lines
tools/libs/light/libxl_x86.c +24 -0
@@ -769,6 +805,40 @@ static int domain_construct_memmap(libxl__gc *gc,
          e820[nr].type = E820_RAM;
      }
 
+    /* Special regions */
+    if (libxl_defbool_val(d_config->b_info.arch_x86.fixed_mem_layout))
+    {
+        e820[nr].type = XEN_HVM_MEMMAP_TYPE_SHARED_INFO;
+        e820[nr].addr = special_region_offset;
+        e820[nr].size = page_size;
+        special_region_offset += e820[nr].size;
+        nr++;
+
+        if ( gnttab_frame_count )
+        {
+            e820[nr].type = XEN_HVM_MEMMAP_TYPE_GRANT_TABLE;
+            e820[nr].addr = special_region_offset;
+            e820[nr].size = gnttab_frame_count * page_size;
+            special_region_offset += e820[nr].size;
+            nr++;
+        }
+
+        if (d_config->b_info.max_grant_version >= 2 && gnttab_status_frame_count)
+        {
+            e820[nr].type = XEN_HVM_MEMMAP_TYPE_GNTTAB_STATUS;
+            e820[nr].addr = special_region_offset;
+            e820[nr].size = gnttab_status_frame_count * page_size;
+            special_region_offset += e820[nr].size;
Quoted 9 lines

tools/libs/light/libxl_x86.c static int domain_construct_memmap(libxl__gc *gc, · line 837

Quoted 6 lines
tools/libs/light/libxl_x86.c +6 -0
+            nr++;
+        }
+
+        e820[nr].type = XEN_HVM_MEMMAP_TYPE_FOREIGN_REG;
+        e820[nr].addr = special_region_offset;
+        e820[nr].size = MB(512);

Can we really know this is going to be enough for all use cases?

Probably not, but we could make this area larger in the future without changing this ABI.

Quoted 6 lines
Quoted 6 lines
xen/include/public/arch-x86/hvm/start_info.h +0 -0
@@ -99,6 +99,13 @@
  #define XEN_HVM_MEMMAP_TYPE_DISABLED  6
  #define XEN_HVM_MEMMAP_TYPE_PMEM      7
 
Quoted 9 lines

xen/include/public/arch-x86/hvm/start_info.h line 107

Quoted 6 lines
xen/include/public/arch-x86/hvm/start_info.h +6 -0
+/* Xen-specific types (OEM-specific range of the ACPI spec) */
+#define XEN_HVM_MEMMAP_TYPE_SHARED_INFO   0xF0000001 /* Shared info page */
+#define XEN_HVM_MEMMAP_TYPE_GRANT_TABLE   0xF0000002 /* Grant table pages */
+#define XEN_HVM_MEMMAP_TYPE_GNTTAB_STATUS 0xF0000003 /* Grant table status page (v2) */
+#define XEN_HVM_MEMMAP_TYPE_FOREIGN_REG   0xF0000004 /* Suitable region for grant mappings */
+                                                     /* and foreign mappings */

I question it being legitimate for us to introduce new E820 types.

These E820 types are (at least in ACPI specification) in the OEM-defined range which seems appropriate for me to use for Xen-specific mappings.

We could use reserved, but we still need a way to tell the OS what each of these "reserved" regions actually means (or it is gonna be ignored).

Quoted 1 line

Jan

Teddy

Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#23 lore raw

Re: [RFC PATCH 8/9] hvm: Introduce XEN_HVM_MEMMAP_TYPE_HOTPLUG_ZONE

In reply to Jan Beulich

Le 28/08/2025 à 14:40, Jan Beulich a écrit :

Quoted 8 lines · Teddy Astie
Quoted 3 lines

Allow specifying in memory map a region which can be hotplugged.

This will be used by a future memory hotplug feature.

Why could this not be done the ACPI way, with the regions properly specified in SRAT?

I am not sure whether or not ACPI mandates a specific way of doing memory hotplug when SRAT is advertised. But if doesn't, SRAT sounds like a better alternative.

Quoted 2 lines

Jan

Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#16 lore raw

Re: [RFC PATCH 5/9] docs/x86: Introduce FastABI

In reply to Jan Beulich

Le 28/08/2025 à 14:35, Jan Beulich a écrit :

Quoted 5 lines · Teddy Astie
Quoted 4 lines

FastABI is a alternative ABI designed with performance and coco-enabled guest in mind. It is register-oriented instead of refering to C structures in the guest memory (through a virtual memory pointer).

Quoted 7 lines
Quoted 2 lines

It only focuses on kernel-side hypercalls, it doesn't aim to provide toolstack operations.

And even there it excludes certain pretty relevant ones, like many of the gnttabop sub-ops. As alluded to by a reply to an earlier patch, I don't think having an ABI for just a subset of the hypercalls is going to help.

Many hypercalls are missing in current RFC, including the grant map/unmap ones. But a part of the idea is to still having some hypercalls out of scope (mainly legacy and toolstack-specific ones) to reduce the complexity.

Quoted 2 lines

Jan

Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#11 lore raw

Re: [RFC PATCH 4/9] hvm: Introduce "fixed memory layout" feature

In reply to Teddy Astie
Quoted 17 lines · Teddy Astie

Le 28/08/2025 à 14:30, Jan Beulich a écrit :

Quoted 7 lines · Teddy Astie
Quoted 6 lines
tools/libs/light/libxl_x86.c +1 -0
@@ -686,10 +691,31 @@ static int domain_construct_memmap(libxl__gc *gc,
      /* We always own at least one lowmem entry. */
      unsigned int e820_entries = 1;
      struct e820entry *e820 = NULL;
+    uint64_t highmem_start = ((uint64_t)1 << 32);
      uint64_t highmem_size =
Quoted 8 lines

tools/libs/light/libxl_x86.c static int domain_construct_memmap(libxl__gc *gc, · line 701

Quoted 6 lines
tools/libs/light/libxl_x86.c +3 -0
                      dom->highmem_end ? dom->highmem_end - (1ull << 32) : 0;
      uint32_t lowmem_start = dom->device_model ? GUEST_LOW_MEM_START_DEFAULT : 0;
      unsigned page_size = XC_DOM_PAGE_SIZE(dom);
+    /* Special region starts at the first 1G boundary after the highmem */
+    uint64_t special_region_start =
+        (highmem_start + highmem_size + GB(1) - 1) & ~(GB(1) - 1);

That is, inaccessible before entering PAE mode?

Quoted 5 lines

Yes, I expect this to be only used by newer guests which hopefully aren't limited to 4G range (i.e supports PAE or long mode). The issue of trying to put that below 4G is that much of the space is already taken for the MMIO hole, so that area would quite complicated with more special regions.

Which excludes any boot loaders simple enough to not even require entering paging mode.

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
xen/include/public/arch-x86/hvm/start_info.h +0 -0
@@ -99,6 +99,13 @@
  #define XEN_HVM_MEMMAP_TYPE_DISABLED  6
  #define XEN_HVM_MEMMAP_TYPE_PMEM      7
 
Quoted 8 lines

xen/include/public/arch-x86/hvm/start_info.h line 107

Quoted 6 lines
xen/include/public/arch-x86/hvm/start_info.h +6 -0
+/* Xen-specific types (OEM-specific range of the ACPI spec) */
+#define XEN_HVM_MEMMAP_TYPE_SHARED_INFO   0xF0000001 /* Shared info page */
+#define XEN_HVM_MEMMAP_TYPE_GRANT_TABLE   0xF0000002 /* Grant table pages */
+#define XEN_HVM_MEMMAP_TYPE_GNTTAB_STATUS 0xF0000003 /* Grant table status page (v2) */
+#define XEN_HVM_MEMMAP_TYPE_FOREIGN_REG   0xF0000004 /* Suitable region for grant mappings */
+                                                     /* and foreign mappings */

I question it being legitimate for us to introduce new E820 types.

Quoted 2 lines

These E820 types are (at least in ACPI specification) in the OEM-defined range which seems appropriate for me to use for Xen-specific mappings.

Just that we're not an OEM.

Jan

#17 lore raw

Re: [RFC PATCH 5/9] docs/x86: Introduce FastABI

In reply to Teddy Astie
Quoted 9 lines · Teddy Astie

Le 28/08/2025 à 14:35, Jan Beulich a écrit :

Quoted 8 lines · Teddy Astie
Quoted 6 lines

FastABI is a alternative ABI designed with performance and coco-enabled guest in mind. It is register-oriented instead of refering to C structures in the guest memory (through a virtual memory pointer).

It only focuses on kernel-side hypercalls, it doesn't aim to provide toolstack operations.

Quoted 7 lines
Quoted 4 lines

And even there it excludes certain pretty relevant ones, like many of the gnttabop sub-ops. As alluded to by a reply to an earlier patch, I don't think having an ABI for just a subset of the hypercalls is going to help.

Many hypercalls are missing in current RFC, including the grant map/unmap ones.

Yet the built-in batching that these come with would make it particularly interesting to see how you envision to support them without needing to access guest memory. (I simply can't see how that could work.)

Jan

Quoted 11 lines

But a part of the idea is to still having some
hypercalls out of scope (mainly legacy and toolstack-specific ones) to reduce the complexity.

Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#12 lore raw

Re: [RFC PATCH 4/9] hvm: Introduce "fixed memory layout" feature

In reply to Jan Beulich

Le 01/09/2025 à 17:50, Jan Beulich a écrit :

Quoted 18 lines · Teddy Astie
Quoted 17 lines

Le 28/08/2025 à 14:30, Jan Beulich a écrit :

Quoted 15 lines · Teddy Astie

xen/include/public/arch-x86/hvm/start_info.h line 107

Quoted 12 lines
xen/include/public/arch-x86/hvm/start_info.h +6 -0
@@ -99,6 +99,13 @@
   #define XEN_HVM_MEMMAP_TYPE_DISABLED  6
   #define XEN_HVM_MEMMAP_TYPE_PMEM      7
 
+/* Xen-specific types (OEM-specific range of the ACPI spec) */
+#define XEN_HVM_MEMMAP_TYPE_SHARED_INFO   0xF0000001 /* Shared info page */
+#define XEN_HVM_MEMMAP_TYPE_GRANT_TABLE   0xF0000002 /* Grant table pages */
+#define XEN_HVM_MEMMAP_TYPE_GNTTAB_STATUS 0xF0000003 /* Grant table status page (v2) */
+#define XEN_HVM_MEMMAP_TYPE_FOREIGN_REG   0xF0000004 /* Suitable region for grant mappings */
+                                                     /* and foreign mappings */

I question it being legitimate for us to introduce new E820 types.

Quoted 4 lines
Quoted 2 lines

These E820 types are (at least in ACPI specification) in the OEM-defined range which seems appropriate for me to use for Xen-specific mappings.

Just that we're not an OEM.

How should such information be provided alternatively ?

Currently, premapped pages (xenstore, PV console, ...) locations are provided through hvm parameters, but I don't think introducing new hvm parameters is very wise.

One way of another, we would need to provide to the guest a xen-specific memory map for implementing this.

Quoted 3 lines

Jan

--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#13 lore raw

Re: [RFC PATCH 4/9] hvm: Introduce "fixed memory layout" feature

Quoted 24 lines · Teddy Astie

Le 01/09/2025 à 17:50, Jan Beulich a écrit :

Quoted 18 lines · Teddy Astie
Quoted 17 lines

Le 28/08/2025 à 14:30, Jan Beulich a écrit :

Quoted 15 lines · Teddy Astie

xen/include/public/arch-x86/hvm/start_info.h line 107

Quoted 12 lines
xen/include/public/arch-x86/hvm/start_info.h +6 -0
@@ -99,6 +99,13 @@
   #define XEN_HVM_MEMMAP_TYPE_DISABLED  6
   #define XEN_HVM_MEMMAP_TYPE_PMEM      7
 
+/* Xen-specific types (OEM-specific range of the ACPI spec) */
+#define XEN_HVM_MEMMAP_TYPE_SHARED_INFO   0xF0000001 /* Shared info page */
+#define XEN_HVM_MEMMAP_TYPE_GRANT_TABLE   0xF0000002 /* Grant table pages */
+#define XEN_HVM_MEMMAP_TYPE_GNTTAB_STATUS 0xF0000003 /* Grant table status page (v2) */
+#define XEN_HVM_MEMMAP_TYPE_FOREIGN_REG   0xF0000004 /* Suitable region for grant mappings */
+                                                     /* and foreign mappings */

I question it being legitimate for us to introduce new E820 types.

Quoted 4 lines
Quoted 2 lines

These E820 types are (at least in ACPI specification) in the OEM-defined range which seems appropriate for me to use for Xen-specific mappings.

Just that we're not an OEM.

Quoted 8 lines

How should such information be provided alternatively ?

Currently, premapped pages (xenstore, PV console, ...) locations are provided through hvm parameters, but I don't think introducing new hvm parameters is very wise.

One way of another, we would need to provide to the guest a xen-specific memory map for implementing this.

Yes, I don't think there's a way around something custom. (I am, btw, also not overly happy about seeing "fixed memory layout" appear in the first place.)

Jan