[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC PATCH v2 09/13] wip: fastabi: Introduce memory_op



Signed-off-by: Teddy Astie <teddy.astie@xxxxxxxxxx>
---
Cc: Baptiste Le Duc <baptiste.le-duc@xxxxxxxxxx>
Cc: Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>

The idea here is to provide for the guest a way to get original E820
(with shared_info/grant_table locations) even if OVMF/firmware altered
it.

 docs/guest-guide/fastabi/abi/memory.yml      | 16 ++++++++
 xen/common/memory.c                          | 40 ++++++++++++++++++++
 xen/include/public/arch-x86/hvm/start_info.h |  9 +++++
 xen/include/public/memory.h                  | 12 ++++++
 xen/include/xen/fastabi.h                    |  2 +
 5 files changed, 79 insertions(+)
 create mode 100644 docs/guest-guide/fastabi/abi/memory.yml

diff --git a/docs/guest-guide/fastabi/abi/memory.yml 
b/docs/guest-guide/fastabi/abi/memory.yml
new file mode 100644
index 0000000000..a327702de8
--- /dev/null
+++ b/docs/guest-guide/fastabi/abi/memory.yml
@@ -0,0 +1,16 @@
+name: memory
+hypercall_index: 12
+
+subops:
+  memory_map_entry:
+    index: 9
+    input:
+      entry_index: 2
+    output:
+      addr: 3
+      size: 4
+      type: 5
+    c_lang:
+      param:
+        entry_index: uint64_t
+      struct: xen_memory_map_entry
diff --git a/xen/common/memory.c b/xen/common/memory.c
index 4afa2271b7..e240b2fb54 100644
--- a/xen/common/memory.c
+++ b/xen/common/memory.c
@@ -38,6 +38,7 @@
 #include <xsm/xsm.h>
 
 #ifdef CONFIG_X86
+#include <asm/fastabi.h>
 #include <asm/guest.h>
 #endif
 
@@ -2014,6 +2015,45 @@ long do_memory_op(unsigned long cmd, 
XEN_GUEST_HANDLE_PARAM(void) arg)
     return rc;
 }
 
+#ifdef CONFIG_FASTABI
+long do_memory_fast_op(struct cpu_user_regs *regs)
+{
+    long cmd = fastabi_value_n(regs, 1);
+    long rc = 0;
+
+    switch ( cmd )
+    {
+#ifdef CONFIG_X86
+    case XENMEM_memory_map_entry:
+    {
+        struct domain *d = current->domain;
+        unsigned long entry_index = fastabi_value_n(regs, 2);
+
+        spin_lock(&d->arch.e820_lock);
+        if ( d->arch.e820 && entry_index < d->arch.nr_e820 )
+        {
+            const struct e820entry entry = d->arch.e820[entry_index];
+            
+            fastabi_value_n(regs, 3) = entry.addr;
+            fastabi_value_n(regs, 4) = entry.size;
+            fastabi_value_n(regs, 5) = entry.type;
+        }
+        else
+            rc = -ENOENT;
+        spin_unlock(&d->arch.e820_lock);
+        break;
+    }
+#endif
+
+    default:
+        rc = -ENOSYS;
+        break;
+    }
+
+    return rc;
+}
+#endif
+
 void clear_domain_page(mfn_t mfn)
 {
     void *ptr = map_domain_page(mfn);
diff --git a/xen/include/public/arch-x86/hvm/start_info.h 
b/xen/include/public/arch-x86/hvm/start_info.h
index e33557c0b4..909feb381e 100644
--- a/xen/include/public/arch-x86/hvm/start_info.h
+++ b/xen/include/public/arch-x86/hvm/start_info.h
@@ -99,6 +99,15 @@
 #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 */
+/* For the future :) */
+#define XEN_HVM_MEMMAP_TYPE_HOTPLUG_ZONE  0xF0000005 /* Memory hotpluggable 
zone */
+
 /*
  * C representation of the x86/HVM start info layout.
  *
diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h
index bd9fc37b52..2ab23ad2f5 100644
--- a/xen/include/public/memory.h
+++ b/xen/include/public/memory.h
@@ -328,6 +328,18 @@ struct xen_memory_map {
 typedef struct xen_memory_map xen_memory_map_t;
 DEFINE_XEN_GUEST_HANDLE(xen_memory_map_t);
 
+/*
+ * Read a specific memory map entry.
+ * FastABI only.
+ */
+#define XENMEM_memory_map_entry     9
+struct xen_memory_map_entry {
+    uint64_t addr;
+    uint64_t size;
+    uint32_t type;
+};
+typedef struct xen_memory_map_entry xen_memory_map_entry_t;
+
 /*
  * Returns the real physical memory map. Passes the same structure as
  * XENMEM_memory_map.
diff --git a/xen/include/xen/fastabi.h b/xen/include/xen/fastabi.h
index de5a349787..7fa7590199 100644
--- a/xen/include/xen/fastabi.h
+++ b/xen/include/xen/fastabi.h
@@ -15,4 +15,6 @@ void do_vcpu_fast_op(struct cpu_user_regs *regs);
 void do_hvm_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);
+long do_memory_fast_op(struct cpu_user_regs *regs);
+
 #endif /* XEN_FASTABI_H */
-- 
2.56.1



--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.