All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/22] mini-os: support HVMlite mode
@ 2016-08-23 15:15 Juergen Gross
  2016-08-23 15:15 ` [PATCH 01/22] mini-os: resync xen headers Juergen Gross
                   ` (21 more replies)
  0 siblings, 22 replies; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:15 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

This patch series adds HVMlite support for Mini-OS. Setting
CONFIG_PARAVIRT to "n" (default is "y") will build mini-os as a
HVMlite domain on x86. Both 32- and 64-bit builds are supported.

Tested with plain Mini-OS configuration to work in 32- and 64-bit
mode either paravirtualized or as HVM domain (device-model none).

Ballooning should basically work, too, but there is some support for
a sparse memory map missing in HVMlite mode.

Juergen Gross (22):
  mini-os: resync xen headers
  mini-os: make dump_regs() work in early boot
  mini-os: add CONFIG_PARAVIRT
  mini-os: make some memory management related macros usable from
    assembler
  mini-os: add boot code for HVMlite support
  mini-os: setup hypercall page for HVMlite
  mini-os: support hvm_op hypercall
  mini-os: initialize trap handling for HVMlite
  mini-os: support HVMlite traps
  mini-os: make p2m related code depend on CONFIG_PARAVIRT
  mini-os: add static page tables for virtual kernel area for HVMlite
  mini-os: add x86 native page table handling
  mini-os: correct wrong calculation of alloc bitmap size
  mini-os: add map_frame_virt() function
  mini-os: setup console interface parameters
  mini-os: setup xenbus interface parameters
  mini-os: add get_cmdline() function
  mini-os: map shared info page for HVMlite
  mini-os: remove using start_info in architecture independent code
  mini-os: print start of day messages depending on domain type
  mini-os: get physical memory map
  mini-os: support idle for HVMlite

 Config.mk                             |   6 +
 Makefile                              |   2 +-
 arch/arm/arm32.S                      |   4 +-
 arch/arm/balloon.c                    |   7 -
 arch/arm/mm.c                         |  17 +-
 arch/arm/setup.c                      |  66 +-----
 arch/x86/arch.mk                      |   4 +
 arch/x86/balloon.c                    |  26 ++-
 arch/x86/events.c                     |   4 +-
 arch/x86/mm.c                         | 347 +++++++++++++++++++++++++++-----
 arch/x86/setup.c                      | 155 ++++++++------
 arch/x86/time.c                       |  11 +-
 arch/x86/traps.c                      | 108 +++++++++-
 arch/x86/x86_32.S                     |  50 ++++-
 arch/x86/x86_64.S                     |  66 +++++-
 arch/x86/x86_hvm.S                    |  77 +++++++
 balloon.c                             |  12 +-
 console/xencons_ring.c                |  38 +++-
 daytime.c                             |   2 +-
 events.c                              |   3 +-
 hypervisor.c                          |  44 ++++
 include/arm/arch_mm.h                 |   3 -
 include/balloon.h                     |   4 -
 include/compiler.h                    |   1 +
 include/console.h                     |   3 +-
 include/e820.h                        |  48 +++++
 include/hypervisor.h                  |  17 +-
 include/kernel.h                      |   3 +
 include/mm.h                          |   3 +-
 include/paravirt.h                    |  81 ++++++++
 include/x86/arch_mm.h                 | 101 +++++-----
 include/x86/desc.h                    | 366 ++++++++++++++++++++++++++++++++++
 include/x86/os.h                      | 104 +++++++++-
 include/x86/x86_32/hypercall-x86_32.h |   6 +
 include/x86/x86_64/hypercall-x86_64.h |   6 +
 include/xen/arch-x86/hvm/start_info.h |  98 +++++++++
 include/xen/arch-x86/xen-x86_32.h     |   2 +
 include/xen/arch-x86/xen-x86_64.h     |   2 +
 include/xen/elfnote.h                 |  12 +-
 include/xenbus.h                      |   3 +
 kernel.c                              |   7 +-
 main.c                                |  11 +-
 minios.mk                             |   2 +-
 mm.c                                  |  80 +++++---
 test.c                                |  20 +-
 xenbus/xenbus.c                       |  40 +++-
 46 files changed, 1697 insertions(+), 375 deletions(-)
 create mode 100644 arch/x86/x86_hvm.S
 create mode 100644 include/e820.h
 create mode 100644 include/paravirt.h
 create mode 100644 include/x86/desc.h
 create mode 100644 include/xen/arch-x86/hvm/start_info.h

-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* [PATCH 01/22] mini-os: resync xen headers
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
@ 2016-08-23 15:15 ` Juergen Gross
  2016-08-23 19:44   ` Samuel Thibault
  2016-08-23 15:15 ` [PATCH 02/22] mini-os: make dump_regs() work in early boot Juergen Gross
                   ` (20 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:15 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

Use the latest Xen headers.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 include/xen/arch-x86/hvm/start_info.h | 98 +++++++++++++++++++++++++++++++++++
 include/xen/elfnote.h                 | 12 ++++-
 2 files changed, 109 insertions(+), 1 deletion(-)
 create mode 100644 include/xen/arch-x86/hvm/start_info.h

diff --git a/include/xen/arch-x86/hvm/start_info.h b/include/xen/arch-x86/hvm/start_info.h
new file mode 100644
index 0000000..6484159
--- /dev/null
+++ b/include/xen/arch-x86/hvm/start_info.h
@@ -0,0 +1,98 @@
+/*
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Copyright (c) 2016, Citrix Systems, Inc.
+ */
+
+#ifndef __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__
+#define __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__
+
+/*
+ * Start of day structure passed to PVH guests and to HVM guests in %ebx.
+ *
+ * NOTE: nothing will be loaded at physical address 0, so a 0 value in any
+ * of the address fields should be treated as not present.
+ *
+ *  0 +----------------+
+ *    | magic          | Contains the magic value XEN_HVM_START_MAGIC_VALUE
+ *    |                | ("xEn3" with the 0x80 bit of the "E" set).
+ *  4 +----------------+
+ *    | version        | Version of this structure. Current version is 0. New
+ *    |                | versions are guaranteed to be backwards-compatible.
+ *  8 +----------------+
+ *    | flags          | SIF_xxx flags.
+ * 12 +----------------+
+ *    | nr_modules     | Number of modules passed to the kernel.
+ * 16 +----------------+
+ *    | modlist_paddr  | Physical address of an array of modules
+ *    |                | (layout of the structure below).
+ * 24 +----------------+
+ *    | cmdline_paddr  | Physical address of the command line,
+ *    |                | a zero-terminated ASCII string.
+ * 32 +----------------+
+ *    | rsdp_paddr     | Physical address of the RSDP ACPI data structure.
+ * 40 +----------------+
+ *
+ * The layout of each entry in the module structure is the following:
+ *
+ *  0 +----------------+
+ *    | paddr          | Physical address of the module.
+ *  8 +----------------+
+ *    | size           | Size of the module in bytes.
+ * 16 +----------------+
+ *    | cmdline_paddr  | Physical address of the command line,
+ *    |                | a zero-terminated ASCII string.
+ * 24 +----------------+
+ *    | reserved       |
+ * 32 +----------------+
+ *
+ * The address and sizes are always a 64bit little endian unsigned integer.
+ *
+ * NB: Xen on x86 will always try to place all the data below the 4GiB
+ * boundary.
+ */
+#define XEN_HVM_START_MAGIC_VALUE 0x336ec578
+
+/*
+ * C representation of the x86/HVM start info layout.
+ *
+ * The canonical definition of this layout is above, this is just a way to
+ * represent the layout described there using C types.
+ */
+struct hvm_start_info {
+    uint32_t magic;             /* Contains the magic value 0x336ec578       */
+                                /* ("xEn3" with the 0x80 bit of the "E" set).*/
+    uint32_t version;           /* Version of this structure.                */
+    uint32_t flags;             /* SIF_xxx flags.                            */
+    uint32_t nr_modules;        /* Number of modules passed to the kernel.   */
+    uint64_t modlist_paddr;     /* Physical address of an array of           */
+                                /* hvm_modlist_entry.                        */
+    uint64_t cmdline_paddr;     /* Physical address of the command line.     */
+    uint64_t rsdp_paddr;        /* Physical address of the RSDP ACPI data    */
+                                /* structure.                                */
+};
+
+struct hvm_modlist_entry {
+    uint64_t paddr;             /* Physical address of the module.           */
+    uint64_t size;              /* Size of the module in bytes.              */
+    uint64_t cmdline_paddr;     /* Physical address of the command line.     */
+    uint64_t reserved;
+};
+
+#endif /* __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__ */
diff --git a/include/xen/elfnote.h b/include/xen/elfnote.h
index 3824a94..353985f 100644
--- a/include/xen/elfnote.h
+++ b/include/xen/elfnote.h
@@ -200,9 +200,19 @@
 #define XEN_ELFNOTE_SUPPORTED_FEATURES 17
 
 /*
+ * Physical entry point into the kernel.
+ *
+ * 32bit entry point into the kernel. When requested to launch the
+ * guest kernel in a HVM container, Xen will use this entry point to
+ * launch the guest in 32bit protected mode with paging disabled.
+ * Ignored otherwise.
+ */
+#define XEN_ELFNOTE_PHYS32_ENTRY 18
+
+/*
  * The number of the highest elfnote defined.
  */
-#define XEN_ELFNOTE_MAX XEN_ELFNOTE_SUPPORTED_FEATURES
+#define XEN_ELFNOTE_MAX XEN_ELFNOTE_PHYS32_ENTRY
 
 /*
  * System information exported through crash notes.
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 02/22] mini-os: make dump_regs() work in early boot
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
  2016-08-23 15:15 ` [PATCH 01/22] mini-os: resync xen headers Juergen Gross
@ 2016-08-23 15:15 ` Juergen Gross
  2016-08-23 19:44   ` Samuel Thibault
  2016-08-23 15:15 ` [PATCH 03/22] mini-os: add CONFIG_PARAVIRT Juergen Gross
                   ` (19 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:15 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

dump_regs() will result in page fault in early boot as there is no
current thread pointer. Handle this case.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/traps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/traps.c b/arch/x86/traps.c
index 6353718..307a14c 100644
--- a/arch/x86/traps.c
+++ b/arch/x86/traps.c
@@ -32,7 +32,7 @@ void machine_check(void);
 
 void dump_regs(struct pt_regs *regs)
 {
-    printk("Thread: %s\n", current->name);
+    printk("Thread: %s\n", current ? current->name : "*NONE*");
 #ifdef __i386__    
     printk("EIP: %lx, EFLAGS %lx.\n", regs->eip, regs->eflags);
     printk("EBX: %08lx ECX: %08lx EDX: %08lx\n",
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 03/22] mini-os: add CONFIG_PARAVIRT
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
  2016-08-23 15:15 ` [PATCH 01/22] mini-os: resync xen headers Juergen Gross
  2016-08-23 15:15 ` [PATCH 02/22] mini-os: make dump_regs() work in early boot Juergen Gross
@ 2016-08-23 15:15 ` Juergen Gross
  2016-08-23 19:54   ` Samuel Thibault
  2016-08-23 15:15 ` [PATCH 04/22] mini-os: make some memory management related macros usable from assembler Juergen Gross
                   ` (18 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:15 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

Add a new config macro CONFIG_PARAVIRT which defaults to be defined on
x86. This is the first step for supporting a HVMlite Mini-OS.

Doing this via CONFIG_PARAVIRT instead of something like CONFIG_HVMLITE
was chosen as the arm port can then drop some dummy routines needed for
para-virtualization only.

Add include/paravirt.h for furute support of paravirt specific
handling.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 Config.mk          |  6 ++++++
 include/paravirt.h | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)
 create mode 100644 include/paravirt.h

diff --git a/Config.mk b/Config.mk
index 8ab1a7e..aa36761 100644
--- a/Config.mk
+++ b/Config.mk
@@ -153,6 +153,11 @@ LDFLAGS-$(clang) += -plugin LLVMgold.so
 endif
 
 # Configuration defaults
+ifeq ($(TARGET_ARCH_FAM),x86)
+CONFIG_PARAVIRT ?= y
+else
+CONFIG_PARAVIRT ?= n
+endif
 CONFIG_START_NETWORK ?= y
 CONFIG_SPARSE_BSS ?= y
 CONFIG_QEMU_XS_ARGS ?= n
@@ -172,6 +177,7 @@ CONFIG_LWIP ?= $(lwip)
 CONFIG_BALLOON ?= n
 
 # Export config items as compiler directives
+DEFINES-$(CONFIG_PARAVIRT) += -DCONFIG_PARAVIRT
 DEFINES-$(CONFIG_START_NETWORK) += -DCONFIG_START_NETWORK
 DEFINES-$(CONFIG_SPARSE_BSS) += -DCONFIG_SPARSE_BSS
 DEFINES-$(CONFIG_QEMU_XS_ARGS) += -DCONFIG_QEMU_XS_ARGS
diff --git a/include/paravirt.h b/include/paravirt.h
new file mode 100644
index 0000000..7852e16
--- /dev/null
+++ b/include/paravirt.h
@@ -0,0 +1,33 @@
+/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
+ *
+ * (C) 2016 - Juergen Gross, SUSE Linux GmbH
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _PARAVIRT_H
+#define _PARAVIRT_H
+
+#if defined(CONFIG_PARAVIRT)
+
+#else
+
+#endif
+
+#endif /* _PARAVIRT_H */
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 04/22] mini-os: make some memory management related macros usable from assembler
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (2 preceding siblings ...)
  2016-08-23 15:15 ` [PATCH 03/22] mini-os: add CONFIG_PARAVIRT Juergen Gross
@ 2016-08-23 15:15 ` Juergen Gross
  2016-08-23 19:46   ` Samuel Thibault
  2016-08-23 15:15 ` [PATCH 05/22] mini-os: add boot code for HVMlite support Juergen Gross
                   ` (17 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:15 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

Especially page table entry definitions are currently not usable from
assembler sources on x86 as the constants are defined with ULL suffix.
Change this by adding the suffix only when the header is included from
a C source.

Hide some C prototypes when in assembler environment.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 include/x86/arch_mm.h | 56 +++++++++++++++++++++++++++++++--------------------
 1 file changed, 34 insertions(+), 22 deletions(-)

diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h
index 690a919..2b18b34 100644
--- a/include/x86/arch_mm.h
+++ b/include/x86/arch_mm.h
@@ -29,11 +29,16 @@
 #include <xen/xen.h>
 #if defined(__i386__)
 #include <xen/arch-x86_32.h>
+#define __CONST(x) x ## ULL
 #elif defined(__x86_64__)
 #include <xen/arch-x86_64.h>
+#define __CONST(x) x ## UL
 #else
 #error "Unsupported architecture"
 #endif
+#define CONST(x) __CONST(x)
+#else
+#define CONST(x) x
 #endif
 
 /*
@@ -81,14 +86,16 @@
 #define PRIpte "016llx"
 #ifndef __ASSEMBLY__
 typedef uint64_t pgentry_t;
+#else
+#define PTE(val) .long val; .long 0
 #endif
 
-#define MAX_MEM_SIZE            0x3f000000UL
-#define VIRT_KERNEL_AREA        0x3f000000UL
-#define VIRT_DEMAND_AREA        0x40000000UL
-#define VIRT_HEAP_AREA          0xb0000000UL
+#define MAX_MEM_SIZE            CONST(0x3f000000)
+#define VIRT_KERNEL_AREA        CONST(0x3f000000)
+#define VIRT_DEMAND_AREA        CONST(0x40000000)
+#define VIRT_HEAP_AREA          CONST(0xb0000000)
 
-#define DEMAND_MAP_PAGES        0x6ffffUL
+#define DEMAND_MAP_PAGES        CONST(0x6ffff)
 #define HEAP_PAGES_MAX          ((HYPERVISOR_VIRT_START - VIRT_HEAP_AREA) / \
                                  PAGE_SIZE - 1)
 
@@ -115,15 +122,17 @@ typedef uint64_t pgentry_t;
 #define PRIpte "016lx"
 #ifndef __ASSEMBLY__
 typedef unsigned long pgentry_t;
+#else
+#define PTE(val) .quad val
 #endif
 
-#define MAX_MEM_SIZE            (512ULL << 30)
-#define VIRT_KERNEL_AREA        0x0000008000000000UL
-#define VIRT_DEMAND_AREA        0x0000100000000000UL
-#define VIRT_HEAP_AREA          0x0000200000000000UL
+#define MAX_MEM_SIZE            (CONST(512) << 30)
+#define VIRT_KERNEL_AREA        CONST(0x0000008000000000)
+#define VIRT_DEMAND_AREA        CONST(0x0000100000000000)
+#define VIRT_HEAP_AREA          CONST(0x0000200000000000)
 
-#define DEMAND_MAP_PAGES        0x8000000UL
-#define HEAP_PAGES_MAX          0x8000000UL
+#define DEMAND_MAP_PAGES        CONST(0x8000000)
+#define HEAP_PAGES_MAX          CONST(0x8000000)
 
 #endif
 
@@ -147,16 +156,16 @@ typedef unsigned long pgentry_t;
   (((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1))
 #endif
 
-#define _PAGE_PRESENT  0x001ULL
-#define _PAGE_RW       0x002ULL
-#define _PAGE_USER     0x004ULL
-#define _PAGE_PWT      0x008ULL
-#define _PAGE_PCD      0x010ULL
-#define _PAGE_ACCESSED 0x020ULL
-#define _PAGE_DIRTY    0x040ULL
-#define _PAGE_PAT      0x080ULL
-#define _PAGE_PSE      0x080ULL
-#define _PAGE_GLOBAL   0x100ULL
+#define _PAGE_PRESENT  CONST(0x001)
+#define _PAGE_RW       CONST(0x002)
+#define _PAGE_USER     CONST(0x004)
+#define _PAGE_PWT      CONST(0x008)
+#define _PAGE_PCD      CONST(0x010)
+#define _PAGE_ACCESSED CONST(0x020)
+#define _PAGE_DIRTY    CONST(0x040)
+#define _PAGE_PAT      CONST(0x080)
+#define _PAGE_PSE      CONST(0x080)
+#define _PAGE_GLOBAL   CONST(0x100)
 
 #if defined(__i386__)
 #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
@@ -191,12 +200,14 @@ typedef unsigned long pgentry_t;
 #define L3_P2M_IDX(pfn) (((pfn) >> L2_P2M_SHIFT) & P2M_MASK)
 #define INVALID_P2M_ENTRY (~0UL)
 
+#ifndef __ASSEMBLY__
 void p2m_chk_pfn(unsigned long pfn);
 
 static inline unsigned long p2m_pages(unsigned long pages)
 {
     return (pages + P2M_ENTRIES - 1) >> L1_P2M_SHIFT;
 }
+#endif
 
 #include "arch_limits.h"
 #define PAGE_SIZE       __PAGE_SIZE
@@ -239,7 +250,6 @@ static __inline__ paddr_t machine_to_phys(maddr_t machine)
 	phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
 	return phys;
 }
-#endif
 
 #define VIRT_START                 ((unsigned long)&_text)
 
@@ -288,4 +298,6 @@ static __inline__ paddr_t machine_to_phys(maddr_t machine)
 
 pgentry_t *need_pgt(unsigned long addr);
 
+#endif
+
 #endif /* _ARCH_MM_H_ */
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 05/22] mini-os: add boot code for HVMlite support
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (3 preceding siblings ...)
  2016-08-23 15:15 ` [PATCH 04/22] mini-os: make some memory management related macros usable from assembler Juergen Gross
@ 2016-08-23 15:15 ` Juergen Gross
  2016-08-23 20:51   ` Samuel Thibault
  2016-08-23 15:15 ` [PATCH 06/22] mini-os: setup hypercall page for HVMlite Juergen Gross
                   ` (16 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:15 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

A HVMlite domain is always starting in 32 bit mode. Add the appropriate
boot code to arch/x86 for the non-paravirtualized case.

For this boot code to become active we need to suppress the pv related
elfnotes and add an appropriate elfnote for HVMlite.

As the HVMlite boot code is more or less the same for 32- and 64-bit
Mini-OS #include the new code from x86_[32|64].S in order to avoid
error prone code duplication. The specific parts of 32- or 64-bit code
are added to x86_[32|64].S

This enables Mini-OS to start the boot process in HVMlite mode until it
enters C code. This is working for 32- and for 64-bit mode.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 Makefile           |   2 +-
 arch/x86/arch.mk   |   4 +
 arch/x86/mm.c      |  31 +++++
 arch/x86/setup.c   |   4 +-
 arch/x86/x86_32.S  |  31 ++++-
 arch/x86/x86_64.S  |  35 ++++-
 arch/x86/x86_hvm.S |  77 +++++++++++
 include/compiler.h |   1 +
 include/x86/desc.h | 366 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/x86/os.h   |   5 +
 minios.mk          |   2 +-
 11 files changed, 544 insertions(+), 14 deletions(-)
 create mode 100644 arch/x86/x86_hvm.S
 create mode 100644 include/x86/desc.h

diff --git a/Makefile b/Makefile
index 779bc91..b783684 100644
--- a/Makefile
+++ b/Makefile
@@ -24,7 +24,7 @@ include minios.mk
 LDLIBS := 
 APP_LDLIBS := 
 LDARCHLIB := -L$(OBJ_DIR)/$(TARGET_ARCH_DIR) -l$(ARCH_LIB_NAME)
-LDFLAGS_FINAL := -T $(TARGET_ARCH_DIR)/minios-$(MINIOS_TARGET_ARCH).lds
+LDFLAGS_FINAL := -T $(TARGET_ARCH_DIR)/minios-$(MINIOS_TARGET_ARCH).lds $(ARCH_LDFLAGS_FINAL)
 
 # Prefix for global API names. All other symbols are localised before
 # linking with EXTRA_OBJS.
diff --git a/arch/x86/arch.mk b/arch/x86/arch.mk
index 81e8118..673a19d 100644
--- a/arch/x86/arch.mk
+++ b/arch/x86/arch.mk
@@ -20,3 +20,7 @@ EXTRA_INC += $(TARGET_ARCH_FAM)/$(MINIOS_TARGET_ARCH)
 EXTRA_SRC += arch/$(EXTRA_INC)
 endif
 
+ifeq ($(CONFIG_PARAVIRT),n)
+ARCH_LDFLAGS_FINAL := --oformat=elf32-i386
+ARCH_AS_DEPS += x86_hvm.S
+endif
diff --git a/arch/x86/mm.c b/arch/x86/mm.c
index 88a928d..fe18f53 100644
--- a/arch/x86/mm.c
+++ b/arch/x86/mm.c
@@ -56,6 +56,37 @@ unsigned long mfn_zero;
 extern char stack[];
 extern void page_walk(unsigned long va);
 
+#ifndef CONFIG_PARAVIRT
+#include <mini-os/desc.h>
+user_desc gdt[NR_GDT_ENTRIES] =
+{
+    [GDTE_CS64_DPL0] = INIT_GDTE_SYM(0, 0xfffff, COMMON, CODE, DPL0, R, L),
+    [GDTE_CS32_DPL0] = INIT_GDTE_SYM(0, 0xfffff, COMMON, CODE, DPL0, R, D),
+    [GDTE_DS32_DPL0] = INIT_GDTE_SYM(0, 0xfffff, COMMON, DATA, DPL0, B, W),
+
+    [GDTE_CS64_DPL3] = INIT_GDTE_SYM(0, 0xfffff, COMMON, CODE, DPL3, R, L),
+    [GDTE_CS32_DPL3] = INIT_GDTE_SYM(0, 0xfffff, COMMON, CODE, DPL3, R, D),
+    [GDTE_DS32_DPL3] = INIT_GDTE_SYM(0, 0xfffff, COMMON, DATA, DPL3, B, W),
+
+    /* [GDTE_TSS]     */
+    /* [GDTE_TSS + 1] */
+};
+
+desc_ptr gdt_ptr =
+{
+    .limit = sizeof(gdt) - 1,
+    .base = (unsigned long)&gdt,
+};
+
+gate_desc idt[256] = { };
+
+desc_ptr idt_ptr =
+{
+    .limit = sizeof(idt) - 1,
+    .base = (unsigned long)&idt,
+};
+#endif
+
 /*
  * Make pt_pfn a new 'level' page table frame and hook it into the page
  * table at offset in previous level MFN (pref_l_mfn). pt_pfn is a guest
diff --git a/arch/x86/setup.c b/arch/x86/setup.c
index 5e87dd1..30a9143 100644
--- a/arch/x86/setup.c
+++ b/arch/x86/setup.c
@@ -94,9 +94,10 @@ static inline void sse_init(void) {
  * INITIAL C ENTRY POINT.
  */
 void
-arch_init(start_info_t *si)
+arch_init(void *par)
 {
 	static char hello[] = "Bootstrapping...\n";
+	start_info_t *si;
 
 	(void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello);
 
@@ -111,6 +112,7 @@ arch_init(start_info_t *si)
 	/* Copy the start_info struct to a globally-accessible area. */
 	/* WARN: don't do printk before here, it uses information from
 	   shared_info. Use xprintk instead. */
+	si = par;
 	memcpy(&start_info, si, sizeof(*si));
 
 	/* print out some useful information  */
diff --git a/arch/x86/x86_32.S b/arch/x86/x86_32.S
index 6dc985a..6f38708 100644
--- a/arch/x86/x86_32.S
+++ b/arch/x86/x86_32.S
@@ -1,20 +1,31 @@
 #include <mini-os/os.h>
 #include <mini-os/x86/arch_limits.h>
 #include <mini-os/asm_macros.h>
+#include <mini-os/arch_mm.h>
+#include <mini-os/desc.h>
+#include <xen/arch-x86_32.h>
 #include <xen/elfnote.h>
 #include <xen/arch-x86_32.h>
 
+#ifdef CONFIG_PARAVIRT
 ELFNOTE(Xen, XEN_ELFNOTE_GUEST_OS, .asciz "Mini-OS")
 ELFNOTE(Xen, XEN_ELFNOTE_LOADER, .asciz "generic")
 ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, _WORD hypercall_page)
 ELFNOTE(Xen, XEN_ELFNOTE_XEN_VERSION, .asciz "xen-3.0")
 ELFNOTE(Xen, XEN_ELFNOTE_PAE_MODE, .asciz "yes")
+.text
 
-.globl _start, shared_info, hypercall_page
+.globl _start
                         
 _start:
-        cld
         lss stack_start,%esp
+#else
+
+#include "x86_hvm.S"
+        movl stack_start,%esp
+
+#endif
+        cld
         andl $(~(__STACK_SIZE-1)), %esp
         push %esi 
         call arch_init
@@ -22,14 +33,15 @@ _start:
 stack_start:
 	.long stack+(2*__STACK_SIZE), __KERNEL_SS
 
+.globl shared_info, hypercall_page
         /* Unpleasant -- the PTE that maps this page is actually overwritten */
         /* to map the real shared-info page! :-)                             */
-        .org 0x1000
+        .align __PAGE_SIZE
 shared_info:
-        .org 0x2000
+        .fill __PAGE_SIZE,1,0
 
 hypercall_page:
-        .org 0x3000
+        .fill __PAGE_SIZE,1,0
 
 ES		= 0x20
 ORIG_EAX	= 0x24
@@ -300,3 +312,12 @@ ENTRY(__arch_switch_threads)
     popl %ebx
     popl %ebp
     ret
+
+#ifndef CONFIG_PARAVIRT
+.data
+.globl page_table_base
+        .align __PAGE_SIZE
+page_table_base:
+        PTE(page_table_l2 + L3_PROT)
+        .align __PAGE_SIZE, 0
+#endif
diff --git a/arch/x86/x86_64.S b/arch/x86/x86_64.S
index 8ed452f..373f400 100644
--- a/arch/x86/x86_64.S
+++ b/arch/x86/x86_64.S
@@ -1,19 +1,29 @@
 #include <mini-os/os.h>
 #include <mini-os/x86/arch_limits.h>
 #include <mini-os/asm_macros.h>
+#include <mini-os/arch_mm.h>
+#include <mini-os/desc.h>
+#include <xen/features.h>
 #include <xen/elfnote.h>
 #include <xen/features.h>
 
+#define ENTRY(X) .globl X ; X :
+
+#ifdef CONFIG_PARAVIRT
 ELFNOTE(Xen, XEN_ELFNOTE_GUEST_OS, .asciz "Mini-OS")
 ELFNOTE(Xen, XEN_ELFNOTE_LOADER, .asciz "generic")
 ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, _WORD hypercall_page)
 ELFNOTE(Xen, XEN_ELFNOTE_XEN_VERSION, .asciz "xen-3.0")
+.text
 
-#define ENTRY(X) .globl X ; X :
-.globl _start, shared_info, hypercall_page
-
+.globl _start
 
 _start:
+#else
+
+#include "x86_hvm.S"
+
+#endif
         cld
         movq stack_start(%rip),%rsp
         andq $(~(__STACK_SIZE-1)), %rsp
@@ -23,14 +33,15 @@ _start:
 stack_start:
         .quad stack+(2*__STACK_SIZE)
 
+.globl shared_info, hypercall_page
         /* Unpleasant -- the PTE that maps this page is actually overwritten */
         /* to map the real shared-info page! :-)                             */
-        .org 0x1000
+        .align __PAGE_SIZE
 shared_info:
-        .org 0x2000
+        .fill __PAGE_SIZE,1,0
 
 hypercall_page:
-        .org 0x3000
+        .fill __PAGE_SIZE,1,0
 
 
 #define XEN_GET_VCPU_INFO(reg)	movq HYPERVISOR_shared_info,reg
@@ -378,3 +389,15 @@ ENTRY(__arch_switch_threads)
 	popq %rbx
 	popq %rbp
 	ret
+
+#ifndef CONFIG_PARAVIRT
+.data
+.globl page_table_base
+        .align __PAGE_SIZE
+page_table_l3:
+        PTE(page_table_l2 + L3_PROT)
+        .align __PAGE_SIZE, 0
+page_table_base:
+        PTE(page_table_l3 + L4_PROT)
+        .align __PAGE_SIZE, 0
+#endif
diff --git a/arch/x86/x86_hvm.S b/arch/x86/x86_hvm.S
new file mode 100644
index 0000000..1f30755
--- /dev/null
+++ b/arch/x86/x86_hvm.S
@@ -0,0 +1,77 @@
+/* Included by x86_[32|64].S */
+
+        ELFNOTE(Xen, XEN_ELFNOTE_PHYS32_ENTRY, .long _start)
+.text
+        .code32                 /* Always starts in 32bit flat mode. */
+
+.globl _start
+
+_start:
+        mov $(X86_CR4_PAE | X86_CR4_OSFXSR), %eax
+        mov %eax, %cr4
+        mov $page_table_base, %eax
+        mov %eax, %cr3
+
+#ifdef __x86_64__               /* EFER.LME = 1 */
+        mov $MSR_EFER, %ecx
+        rdmsr
+        bts $_EFER_LME, %eax
+        wrmsr
+#endif /* __x86_64__ */
+
+        mov %cr0, %eax
+        or $X86_CR0_PG, %eax
+        mov %eax, %cr0
+
+        lgdt gdt_ptr
+
+        /* Load code segment. */
+        ljmp $__KERN_CS, $1f
+#ifdef __x86_64__
+        .code64
+#endif
+
+        /* Load data segments. */
+1:
+        mov $__USER_DS, %eax
+        mov %eax, %ds
+        mov %eax, %es
+        mov %eax, %fs
+        mov %eax, %gs
+        mov $__KERN_DS, %eax
+        mov %eax, %ss
+
+        mov %ebx, %esi
+
+.data
+        .macro PTES prot, addr, incr, idx, end
+        .ifgt \end-\idx-32
+        PTES \prot, \addr, \incr, \idx, "(\idx+32)"
+        PTES \prot, "(\addr+32*\incr)", \incr, "(\idx+32)", \end
+        .else
+        PTE(\addr + \prot)
+        .if \end-\idx-1
+        PTES \prot, "(\addr+\incr)", \incr, "(\idx+1)", \end
+        .endif
+        .endif
+        .endm
+        .align __PAGE_SIZE
+page_table_virt_l1:
+        PTE(0)
+        .align __PAGE_SIZE, 0
+page_table_l1:
+        PTES L1_PROT, 0x00000000, 0x00001000, 0, L1_PAGETABLE_ENTRIES
+        .align __PAGE_SIZE, 0
+page_table_l2:
+        /* Map the first 1GB of memory (on 32 bit 16MB less). */
+        PTE(page_table_l1 + L2_PROT)
+#ifdef __x86_64__
+        PTES L2_PROT|_PAGE_PSE, 0x00200000, 0x00200000, 1, L2_PAGETABLE_ENTRIES
+#else
+        /* At 3f000000 virtual kernel area is starting. */
+        PTES L2_PROT|_PAGE_PSE, 0x00200000, 0x00200000, 1, l2_table_offset(VIRT_KERNEL_AREA)
+        PTE(page_table_virt_l1 + L2_PROT)
+#endif
+        .align __PAGE_SIZE, 0
+
+.text
diff --git a/include/compiler.h b/include/compiler.h
index 4188277..0cbad98 100644
--- a/include/compiler.h
+++ b/include/compiler.h
@@ -6,5 +6,6 @@
 #endif
 #define unlikely(x)  __builtin_expect(!!(x),0)
 #define likely(x)    __builtin_expect(!!(x),1)
+#define __packed     __attribute__((__packed__))
 
 #endif /* __MINIOS_COMPILER_H_ */
diff --git a/include/x86/desc.h b/include/x86/desc.h
new file mode 100644
index 0000000..d450557
--- /dev/null
+++ b/include/x86/desc.h
@@ -0,0 +1,366 @@
+/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
+ *
+ * (C) 2016 - Juergen Gross, SUSE Linux GmbH
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef _DESC_H_
+#define _DESC_H_
+
+/*
+ * Count the number of varadic arguments provided.
+ *
+ * <pre>
+ *   VA_NARGS()     => 0
+ *   VA_NARGS(x)    => 1
+ *   VA_NARGS(x, y) => 2
+ * </pre>
+ *
+ * Currently functions for 0 to 11 arguments.
+ */
+#define VA_NARGS_(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, N, ...) N
+#define VA_NARGS(...) \
+    VA_NARGS_(X,##__VA_ARGS__, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
+
+/*
+ * Call a macro variation, based on the number of varadic arguments.
+ *
+ * @param macro Partial token to call a variation of.
+ * @param c1    Constant parameter to pass through.
+ * @param ...   Varadic arguments to pass through.
+ *
+ * Tokenises 'macro' with the count of varadic arguments, passing 'c1' and the
+ * varadic arguments.
+ *
+ * <pre>
+ *   VAR_MACRO_C1(m, c)          => m0(c)
+ *   VAR_MACRO_C1(m, c, x)       => m1(c, x)
+ *   VAR_MACRO_C1(m, c, x, y)    => m2(c, x, y)
+ *   VAR_MACRO_C1(m, c, x, y, z) => m3(c, x, y, z)
+ * </pre>
+ */
+#define VAR_MACRO_C1__(macro, c1, count, ...) macro##count(c1, ##__VA_ARGS__)
+#define VAR_MACRO_C1_(macro, c1, count, ...)        \
+    VAR_MACRO_C1__(macro, c1, count, ##__VA_ARGS__)
+#define VAR_MACRO_C1(macro, c1, ...)                                \
+    VAR_MACRO_C1_(macro, c1, VA_NARGS(__VA_ARGS__), ##__VA_ARGS__)
+
+/*
+ * GDT layout:
+ *
+ *  0 - null
+ *  1 - 64bit supervisor code
+ *  2 - 32bit supervisor code
+ *  3 - 32bit supervisor data
+ *  4 - 64bit userspace code
+ *  5 - 32bit userspace code
+ *  6 - 32bit userspace data
+ *  7 - TSS (two slots in long mode)
+ *
+ *  9-12 - Available for test use
+ */
+
+#define GDTE_CS64_DPL0 1
+#define GDTE_CS32_DPL0 2
+#define GDTE_DS32_DPL0 3
+#define GDTE_CS64_DPL3 4
+#define GDTE_CS32_DPL3 5
+#define GDTE_DS32_DPL3 6
+
+#define GDTE_TSS 7
+
+#define GDTE_AVAIL0     9
+#define GDTE_AVAIL1    10
+#define GDTE_AVAIL2    11
+#define GDTE_AVAIL3    12
+
+#define NR_GDT_ENTRIES 13
+
+#ifdef __x86_64__
+
+#define __KERN_CS (GDTE_CS64_DPL0 * 8)
+#define __KERN_DS (0)
+#define __USER_CS (GDTE_CS64_DPL3 * 8 + 3)
+#define __USER_DS (GDTE_DS32_DPL3 * 8 + 3)
+
+#else /* __x86_64__ */
+
+#define __KERN_CS (GDTE_CS32_DPL0 * 8)
+#define __KERN_DS (GDTE_DS32_DPL0 * 8)
+#define __USER_CS (GDTE_CS32_DPL3 * 8 + 3)
+#define __USER_DS (GDTE_DS32_DPL3 * 8 + 3)
+
+#endif /* __x86_64__ */
+
+#ifndef __ASSEMBLY__
+/* 8 byte user segment descriptor (GDT/LDT entries with .s = 1) */
+struct __packed seg_desc32 {
+    union {
+        /* Raw backing integers. */
+        struct {
+            uint32_t lo, hi;
+        };
+        /* Common named fields. */
+        struct {
+            uint16_t limit0;
+            uint16_t base0;
+            uint8_t  base1;
+            unsigned type: 4;
+            unsigned s: 1, dpl: 2, p: 1;
+            unsigned limit: 4;
+            unsigned avl: 1, l: 1, d: 1, g: 1;
+            uint8_t base2;
+        };
+        /* Code segment specific field names. */
+        struct {
+            uint16_t limit0;
+            uint16_t base0;
+            uint8_t  base1;
+            unsigned a: 1, r: 1, c: 1, x: 1;
+            unsigned s: 1, dpl: 2, p: 1;
+            unsigned limit: 4;
+            unsigned avl: 1, l: 1, d: 1, g: 1;
+            uint8_t base2;
+        } code;
+        /* Data segment specific field names. */
+        struct {
+            uint16_t limit0;
+            uint16_t base0;
+            uint8_t  base1;
+            unsigned a: 1, w: 1, e: 1, x: 1;
+            unsigned s: 1, dpl: 2, p: 1;
+            unsigned limit: 4;
+            unsigned avl: 1, _r0: 1, b: 1, g: 1;
+            uint8_t base2;
+        } data;
+    };
+};
+
+/* 8-byte gate - Protected mode IDT entry, GDT task/call gate. */
+struct __packed seg_gate32 {
+    union {
+        struct {
+            uint32_t lo, hi;
+        };
+        struct {
+            uint16_t offset0;
+            uint16_t selector;
+            uint8_t  _r0;
+            unsigned type: 4, s: 1, dpl: 2, p: 1;
+            uint16_t offset1;
+        };
+    };
+};
+
+/* 16-byte gate - Long mode IDT entry. */
+struct __packed seg_gate64 {
+    union {
+        struct {
+            uint64_t lo, hi;
+        };
+        struct {
+            uint16_t offset0;
+            uint16_t selector;
+            unsigned ist: 3, _r0: 5, type: 4, s: 1, dpl: 2, p: 1;
+            uint16_t offset1;
+            uint32_t offset2;
+            uint32_t _r1;
+        };
+    };
+};
+
+/* GDT/LDT attribute flags for user segments */
+
+/* Common */
+#define SEG_ATTR_G      0x8000 /* Granularity of limit (0 = 1, 1 = 4K) */
+#define SEG_ATTR_AVL    0x1000 /* Available for software use */
+#define SEG_ATTR_P      0x0080 /* Present? */
+#define SEG_ATTR_S      0x0010 /* !System desc (0 = system, 1 = user) */
+#define SEG_ATTR_A      0x0001 /* Accessed? (set by hardware) */
+
+#define SEG_ATTR_COMMON 0x8091 /* Commonly set bits (G P S A) */
+
+#define SEG_ATTR_DPL0   0x0000 /* Descriptor privilege level 0 */
+#define SEG_ATTR_DPL1   0x0020 /* Descriptor privilege level 1 */
+#define SEG_ATTR_DPL2   0x0040 /* Descriptor privilege level 2 */
+#define SEG_ATTR_DPL3   0x0060 /* Descriptor privilege level 3 */
+#define SEG_ATTR_CODE   0x0008 /* Type (0 = data, 1 = code)    */
+#define SEG_ATTR_DATA   0x0000 /* Type (0 = data, 1 = code)    */
+
+/* Code segments */
+#define SEG_ATTR_D      0x4000 /* Default operand size (0 = 16bit, 1 = 32bit) */
+#define SEG_ATTR_L      0x2000 /* Long segment? (1 = 64bit) */
+#define SEG_ATTR_C      0x0004 /* Conforming? (0 = non, 1 = conforming) */
+#define SEG_ATTR_R      0x0002 /* Readable? (0 = XO seg, 1 = RX seg) */
+
+/* Data segments */
+#define SEG_ATTR_B      0x4000 /* 'Big' flag.
+                                *    - For %ss, default operand size.
+                                *    - For expand-down segment, sets upper bound. */
+#define SEG_ATTR_E      0x0004 /* Expand-down? (0 = normal, 1 = expand-down) */
+#define SEG_ATTR_W      0x0002 /* Writable? (0 = RO seg, 1 = RW seg) */
+
+/*
+ * Initialise an LDT/GDT entry using a raw attribute number.
+ *
+ * @param base  Segment base.
+ * @param limit Segment limit.
+ * @param attr  Segment attributes.
+ */
+#define INIT_GDTE(base, limit, attr) { { {                            \
+     .lo = (((base) & 0xffff) << 16) | ((limit) & 0xffff),            \
+     .hi = ((base) & 0xff000000) | ((limit) & 0xf0000) |              \
+           (((attr) & 0xf0ff) << 8) | (((base) & 0xff0000) >> 16)     \
+     } } }
+
+/*
+ * Tokenise and OR together.
+ *
+ * For each varadic parameter, tokenise with 't' and OR together.
+ *
+ * @param t   Common stem partial token.
+ * @param ... Partial tokens.
+ *
+ * Example:
+ * <pre>
+ *   TOK_OR(t, x, y)    => (t ## x | t ## y)
+ *   TOK_OR(t, x, y, z) => (t ## x | t ## y | t ## z)
+ * </pre>
+ */
+#define TOK_OR0(t)         (0)
+#define TOK_OR1(t, x)      (t ## x)
+#define TOK_OR2(t, x, ...) (t ## x | TOK_OR1(t, ##__VA_ARGS__))
+#define TOK_OR3(t, x, ...) (t ## x | TOK_OR2(t, ##__VA_ARGS__))
+#define TOK_OR4(t, x, ...) (t ## x | TOK_OR3(t, ##__VA_ARGS__))
+#define TOK_OR5(t, x, ...) (t ## x | TOK_OR4(t, ##__VA_ARGS__))
+#define TOK_OR6(t, x, ...) (t ## x | TOK_OR5(t, ##__VA_ARGS__))
+#define TOK_OR7(t, x, ...) (t ## x | TOK_OR6(t, ##__VA_ARGS__))
+#define TOK_OR8(t, x, ...) (t ## x | TOK_OR7(t, ##__VA_ARGS__))
+#define TOK_OR(t, ...)     VAR_MACRO_C1(TOK_OR, t, ##__VA_ARGS__)
+
+/*
+ * Initialise an LDT/GDT entry using SEG_ATTR_ mnemonics.
+ *
+ * @param base  Segment base.
+ * @param limit Segment limit.
+ * @param ...   Partial SEG_ATTR_ tokens for attributes.
+ *
+ * Example usage:
+ * - INIT_GDTE_SYM(0, 0xfffff, P)
+ *   - uses @ref SEG_ATTR_P
+ *
+ * - INIT_GDTE_SYM(0, 0xfffff, CODE, L)
+ *   - uses @ref SEG_ATTR_CODE and @ref SEG_ATTR_L
+ */
+#define INIT_GDTE_SYM(base, limit, ...) \
+    INIT_GDTE(base, limit, TOK_OR(SEG_ATTR_, ##__VA_ARGS__))
+
+/* Long mode lgdt/lidt table pointer. */
+struct __packed desc_ptr64 {
+    uint16_t limit;
+    uint64_t base;
+};
+
+/* Protected mode lgdt/lidt table pointer. */
+struct __packed desc_ptr32 {
+    uint16_t limit;
+    uint32_t base;
+};
+
+struct __packed hw_tss32 {
+    uint16_t link; uint16_t _r0;
+
+    uint32_t esp0;
+    uint16_t ss0; uint16_t _r1;
+
+    uint32_t esp1;
+    uint16_t ss1; uint16_t _r2;
+
+    uint32_t esp2;
+    uint16_t ss2; uint16_t _r3;
+
+    uint32_t cr3;
+    uint32_t eip;
+    uint32_t eflags;
+    uint32_t eax;
+    uint32_t ecx;
+    uint32_t edx;
+    uint32_t ebx;
+    uint32_t esp;
+    uint32_t ebp;
+    uint32_t esi;
+    uint32_t edi;
+
+    uint16_t es; uint16_t _r4;
+    uint16_t cs; uint16_t _r5;
+    uint16_t ss; uint16_t _r6;
+    uint16_t ds; uint16_t _r7;
+    uint16_t fs; uint16_t _r8;
+    uint16_t gs; uint16_t _r9;
+    uint16_t ldtr; uint16_t _r10;
+    uint16_t t; uint16_t iopb;
+};
+
+struct __packed hw_tss64 {
+    uint16_t link; uint16_t _r0;
+
+    uint64_t rsp0;
+    uint64_t rsp1;
+    uint64_t rsp2;
+
+    uint64_t _r1;
+
+    uint64_t ist[7]; /* 1-based structure */
+
+    uint64_t _r2;
+
+    uint16_t t;
+    uint16_t iopb;
+};
+
+#define X86_TSS_INVALID_IO_BITMAP 0x8000
+
+#if defined(__x86_64__)
+
+typedef struct desc_ptr64 desc_ptr;
+typedef struct seg_desc32 user_desc;
+typedef struct seg_gate64 gate_desc;
+typedef struct hw_tss64 hw_tss;
+
+#elif defined(__i386__)
+
+typedef struct desc_ptr32 desc_ptr;
+typedef struct seg_desc32 user_desc;
+typedef struct seg_gate32 gate_desc;
+typedef struct hw_tss32 hw_tss;
+
+#endif
+
+extern user_desc gdt[NR_GDT_ENTRIES];
+extern desc_ptr  gdt_ptr;
+
+extern gate_desc idt[256];
+extern desc_ptr  idt_ptr;
+
+extern hw_tss tss;
+
+#endif
+
+#endif /* _DESC_H_ */
diff --git a/include/x86/os.h b/include/x86/os.h
index ee9050b..eeefbe2 100644
--- a/include/x86/os.h
+++ b/include/x86/os.h
@@ -24,7 +24,12 @@
 #endif
 #include <xen/xen.h>
 
+#define MSR_EFER          0xc0000080
+#define _EFER_LME         8             /* Long mode enable */
 
+#define X86_CR0_PG        0x80000000    /* Paging */
+#define X86_CR4_PAE       0x00000020    /* enable physical address extensions */
+#define X86_CR4_OSFXSR    0x00000200    /* enable fast FPU save and restore */
 
 #define __KERNEL_CS  FLAT_KERNEL_CS
 #define __KERNEL_DS  FLAT_KERNEL_DS
diff --git a/minios.mk b/minios.mk
index 1d1cc99..9ff6bf7 100644
--- a/minios.mk
+++ b/minios.mk
@@ -68,7 +68,7 @@ HEAD_OBJ := $(OBJ_DIR)/$(TARGET_ARCH_DIR)/$(HEAD_ARCH_OBJ)
 $(OBJ_DIR)/%.o: %.c $(HDRS) Makefile $(EXTRA_DEPS)
 	$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
 
-$(OBJ_DIR)/%.o: %.S $(HDRS) Makefile $(EXTRA_DEPS)
+$(OBJ_DIR)/%.o: %.S $(HDRS) Makefile $(EXTRA_DEPS) $(ARCH_AS_DEPS)
 	$(CC) $(ASFLAGS) $(CPPFLAGS) -c $< -o $@
 
 
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 06/22] mini-os: setup hypercall page for HVMlite
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (4 preceding siblings ...)
  2016-08-23 15:15 ` [PATCH 05/22] mini-os: add boot code for HVMlite support Juergen Gross
@ 2016-08-23 15:15 ` Juergen Gross
  2016-08-23 21:03   ` Samuel Thibault
  2016-08-23 15:15 ` [PATCH 07/22] mini-os: support hvm_op hypercall Juergen Gross
                   ` (15 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:15 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

When running in HVMlite mode we need to setup the hypercall page by
ourself.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/events.c |  4 ++--
 arch/x86/setup.c  | 26 ++++++++++++++++++++++++++
 include/x86/os.h  | 22 +++++++++++++++++-----
 3 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/arch/x86/events.c b/arch/x86/events.c
index 5198cf3..342662d 100644
--- a/arch/x86/events.c
+++ b/arch/x86/events.c
@@ -16,7 +16,7 @@ void arch_init_events(void)
 {
 #if defined(__x86_64__)
     asm volatile("movl %0,%%fs ; movl %0,%%gs" :: "r" (0));
-    wrmsrl(0xc0000101, &cpu0_pda); /* 0xc0000101 is MSR_GS_BASE */
+    wrmsrl(0xc0000101, (uint64_t)&cpu0_pda); /* 0xc0000101 is MSR_GS_BASE */
     cpu0_pda.irqcount = -1;
     cpu0_pda.irqstackptr = (void*) (((unsigned long)irqstack + 2 * STACK_SIZE)
                                     & ~(STACK_SIZE - 1));
@@ -30,6 +30,6 @@ void arch_unbind_ports(void)
 void arch_fini_events(void)
 {
 #if defined(__x86_64__)
-    wrmsrl(0xc0000101, NULL); /* 0xc0000101 is MSR_GS_BASE */
+    wrmsrl(0xc0000101, 0); /* 0xc0000101 is MSR_GS_BASE */
 #endif
 }
diff --git a/arch/x86/setup.c b/arch/x86/setup.c
index 30a9143..edc4ca4 100644
--- a/arch/x86/setup.c
+++ b/arch/x86/setup.c
@@ -30,6 +30,7 @@
 #include <mini-os/lib.h> /* for printk, memcpy */
 #include <mini-os/kernel.h>
 #include <xen/xen.h>
+#include <xen/arch-x86/cpuid.h>
 
 /*
  * Shared page for communicating with the hypervisor.
@@ -89,6 +90,30 @@ static inline void sse_init(void) {
 #define sse_init()
 #endif
 
+#ifdef CONFIG_PARAVIRT
+#define hpc_init()
+#else
+static void hpc_init(void)
+{
+    uint32_t eax, ebx, ecx, edx, base;
+
+    for ( base = XEN_CPUID_FIRST_LEAF;
+          base < XEN_CPUID_FIRST_LEAF + 0x10000; base += 0x100 )
+    {
+        cpuid(base, &eax, &ebx, &ecx, &edx);
+
+        if ( (ebx == XEN_CPUID_SIGNATURE_EBX) &&
+             (ecx == XEN_CPUID_SIGNATURE_ECX) &&
+             (edx == XEN_CPUID_SIGNATURE_EDX) &&
+             ((eax - base) >= 2) )
+            break;
+    }
+
+    cpuid(base + 2, &eax, &ebx, &ecx, &edx);
+    wrmsrl(ebx, (unsigned long)&hypercall_page);
+    barrier();
+}
+#endif
 
 /*
  * INITIAL C ENTRY POINT.
@@ -99,6 +124,7 @@ arch_init(void *par)
 	static char hello[] = "Bootstrapping...\n";
 	start_info_t *si;
 
+	hpc_init();
 	(void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello);
 
 	trap_init();
diff --git a/include/x86/os.h b/include/x86/os.h
index eeefbe2..610d8e0 100644
--- a/include/x86/os.h
+++ b/include/x86/os.h
@@ -440,17 +440,20 @@ static __inline__ unsigned long __ffs(unsigned long word)
      (val) = ((unsigned long)__a) | (((unsigned long)__d)<<32); \
 } while(0)
 
+#else /* ifdef __x86_64__ */
+#error "Unsupported architecture"
+#endif
+
 #define wrmsr(msr,val1,val2) \
       __asm__ __volatile__("wrmsr" \
                            : /* no outputs */ \
                            : "c" (msr), "a" (val1), "d" (val2))
 
-#define wrmsrl(msr,val) wrmsr(msr,(uint32_t)((uint64_t)(val)),((uint64_t)(val))>>32)
+static inline void wrmsrl(unsigned msr, uint64_t val)
+{
+    wrmsr(msr, (uint32_t)(val & 0xffffffffULL), (uint32_t)(val >> 32));
+}
 
-
-#else /* ifdef __x86_64__ */
-#error "Unsupported architecture"
-#endif
 #endif /* ifdef __INSIDE_MINIOS */
 
 /********************* common i386 and x86_64  ****************************/
@@ -571,6 +574,15 @@ HYPERVISOR_xsm_op(
     return _hypercall1(int, xsm_op, op);
 }
 
+static inline void cpuid(uint32_t leaf,
+                         uint32_t *eax, uint32_t *ebx,
+                         uint32_t *ecx, uint32_t *edx)
+{
+    asm volatile ("cpuid"
+                  : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
+                  : "0" (leaf));
+}
+
 #undef ADDR
 
 #endif /* not assembly */
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 07/22] mini-os: support hvm_op hypercall
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (5 preceding siblings ...)
  2016-08-23 15:15 ` [PATCH 06/22] mini-os: setup hypercall page for HVMlite Juergen Gross
@ 2016-08-23 15:15 ` Juergen Gross
  2016-08-23 22:00   ` Samuel Thibault
  2016-08-23 15:15 ` [PATCH 08/22] mini-os: initialize trap handling for HVMlite Juergen Gross
                   ` (14 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:15 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

Support the HYPERVISOR_hvm_op() hypercall which is needed for HVMlite.
Add convenience functions hvm_get_parameter() and hvm_set_parameter().

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/arm/setup.c                      | 15 ---------------
 hypervisor.c                          | 27 +++++++++++++++++++++++++++
 include/hypervisor.h                  |  5 +++++
 include/x86/x86_32/hypercall-x86_32.h |  6 ++++++
 include/x86/x86_64/hypercall-x86_64.h |  6 ++++++
 5 files changed, 44 insertions(+), 15 deletions(-)

diff --git a/arch/arm/setup.c b/arch/arm/setup.c
index 06afe46..cbe67c6 100644
--- a/arch/arm/setup.c
+++ b/arch/arm/setup.c
@@ -25,21 +25,6 @@ extern char shared_info_page[PAGE_SIZE];
 
 void *device_tree;
 
-static int hvm_get_parameter(int idx, uint64_t *value)
-{
-    struct xen_hvm_param xhv;
-    int ret;
-
-    xhv.domid = DOMID_SELF;
-    xhv.index = idx;
-    ret = HYPERVISOR_hvm_op(HVMOP_get_param, &xhv);
-    if (ret < 0) {
-        BUG();
-    }
-    *value = xhv.value;
-    return ret;
-}
-
 static void get_console(void)
 {
     uint64_t v = -1;
diff --git a/hypervisor.c b/hypervisor.c
index 1b61d9b..715cfe8 100644
--- a/hypervisor.c
+++ b/hypervisor.c
@@ -36,6 +36,33 @@
 
 int in_callback;
 
+#ifndef CONFIG_PARAVIRT
+int hvm_get_parameter(int idx, uint64_t *value)
+{
+    struct xen_hvm_param xhv;
+    int ret;
+
+    xhv.domid = DOMID_SELF;
+    xhv.index = idx;
+    ret = HYPERVISOR_hvm_op(HVMOP_get_param, &xhv);
+    if ( ret < 0 )
+        BUG();
+
+    *value = xhv.value;
+    return ret;
+}
+
+int hvm_set_parameter(int idx, uint64_t value)
+{
+    struct xen_hvm_param xhv;
+
+    xhv.domid = DOMID_SELF;
+    xhv.index = idx;
+    xhv.value = value;
+    return HYPERVISOR_hvm_op(HVMOP_set_param, &xhv);
+}
+#endif
+
 void do_hypervisor_callback(struct pt_regs *regs)
 {
     unsigned long  l1, l2, l1i, l2i;
diff --git a/include/hypervisor.h b/include/hypervisor.h
index 21b3566..6e421b1 100644
--- a/include/hypervisor.h
+++ b/include/hypervisor.h
@@ -23,6 +23,7 @@
 #else
 #error "Unsupported architecture"
 #endif
+#include <xen/hvm/hvm_op.h>
 #include <mini-os/traps.h>
 
 /*
@@ -37,6 +38,10 @@ extern union start_info_union start_info_union;
 #define start_info (start_info_union.start_info)
 
 /* hypervisor.c */
+#ifndef CONFIG_PARAVIRT
+int hvm_get_parameter(int idx, uint64_t *value);
+int hvm_set_parameter(int idx, uint64_t value);
+#endif
 void force_evtchn_callback(void);
 void do_hypervisor_callback(struct pt_regs *regs);
 void mask_evtchn(uint32_t port);
diff --git a/include/x86/x86_32/hypercall-x86_32.h b/include/x86/x86_32/hypercall-x86_32.h
index 99a4ee3..5c93464 100644
--- a/include/x86/x86_32/hypercall-x86_32.h
+++ b/include/x86/x86_32/hypercall-x86_32.h
@@ -324,6 +324,12 @@ HYPERVISOR_domctl(
 	return _hypercall1(int, domctl, op);
 }
 
+static inline unsigned long
+HYPERVISOR_hvm_op(int op, void *arg)
+{
+	return _hypercall2(unsigned long, hvm_op, op, arg);
+}
+
 #endif /* __HYPERCALL_X86_32_H__ */
 
 /*
diff --git a/include/x86/x86_64/hypercall-x86_64.h b/include/x86/x86_64/hypercall-x86_64.h
index e00b3bd..6171812 100644
--- a/include/x86/x86_64/hypercall-x86_64.h
+++ b/include/x86/x86_64/hypercall-x86_64.h
@@ -331,6 +331,12 @@ HYPERVISOR_domctl(
 	return _hypercall1(int, domctl, op);
 }
 
+static inline unsigned long
+HYPERVISOR_hvm_op(int op, void *arg)
+{
+	return _hypercall2(unsigned long, hvm_op, op, arg);
+}
+
 #endif /* __HYPERCALL_X86_64_H__ */
 
 /*
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 08/22] mini-os: initialize trap handling for HVMlite
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (6 preceding siblings ...)
  2016-08-23 15:15 ` [PATCH 07/22] mini-os: support hvm_op hypercall Juergen Gross
@ 2016-08-23 15:15 ` Juergen Gross
  2016-08-23 22:05   ` Samuel Thibault
  2016-08-23 15:15 ` [PATCH 09/22] mini-os: support HVMlite traps Juergen Gross
                   ` (13 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:15 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

Trap handling for HVMlite domains requires an initialized IDT.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/setup.c  | 15 ----------
 arch/x86/traps.c  | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 arch/x86/x86_64.S |  4 +++
 include/x86/os.h  |  1 +
 4 files changed, 93 insertions(+), 15 deletions(-)

diff --git a/arch/x86/setup.c b/arch/x86/setup.c
index edc4ca4..efecefb 100644
--- a/arch/x86/setup.c
+++ b/arch/x86/setup.c
@@ -52,10 +52,6 @@ char stack[2*STACK_SIZE];
 
 extern char shared_info[PAGE_SIZE];
 
-/* Assembler interface fns in entry.S. */
-void hypervisor_callback(void);
-void failsafe_callback(void);
-
 #if defined(__x86_64__)
 #define __pte(x) ((pte_t) { (x) } )
 #else
@@ -162,17 +158,6 @@ arch_init(void *par)
 	/* Grab the shared_info pointer and put it in a safe place. */
 	HYPERVISOR_shared_info = map_shared_info(start_info.shared_info);
 
-	    /* Set up event and failsafe callback addresses. */
-#ifdef __i386__
-	HYPERVISOR_set_callbacks(
-		__KERNEL_CS, (unsigned long)hypervisor_callback,
-		__KERNEL_CS, (unsigned long)failsafe_callback);
-#else
-	HYPERVISOR_set_callbacks(
-		(unsigned long)hypervisor_callback,
-		(unsigned long)failsafe_callback, 0);
-#endif
-
 	start_kernel();
 }
 
diff --git a/arch/x86/traps.c b/arch/x86/traps.c
index 307a14c..3b1fffb 100644
--- a/arch/x86/traps.c
+++ b/arch/x86/traps.c
@@ -1,10 +1,12 @@
 
 #include <mini-os/os.h>
 #include <mini-os/traps.h>
+#include <mini-os/desc.h>
 #include <mini-os/hypervisor.h>
 #include <mini-os/mm.h>
 #include <mini-os/lib.h>
 #include <mini-os/sched.h>
+#include <xen/hvm/params.h>
 
 /*
  * These are assembler stubs in entry.S.
@@ -293,6 +295,11 @@ void do_spurious_interrupt_bug(struct pt_regs * regs)
 {
 }
 
+/* Assembler interface fns in entry.S. */
+void hypervisor_callback(void);
+void failsafe_callback(void);
+
+#ifdef CONFIG_PARAVIRT
 /*
  * Submit a virtual IDT to teh hypervisor. This consists of tuples
  * (interrupt vector, privilege ring, CS:EIP of handler).
@@ -325,9 +332,90 @@ static trap_info_t trap_table[] = {
 void trap_init(void)
 {
     HYPERVISOR_set_trap_table(trap_table);    
+
+#ifdef __i386__
+    HYPERVISOR_set_callbacks(
+        __KERNEL_CS, (unsigned long)hypervisor_callback,
+        __KERNEL_CS, (unsigned long)failsafe_callback);
+#else
+    HYPERVISOR_set_callbacks(
+        (unsigned long)hypervisor_callback,
+        (unsigned long)failsafe_callback, 0);
+#endif
 }
 
 void trap_fini(void)
 {
     HYPERVISOR_set_trap_table(NULL);
 }
+#else
+
+#define INTR_STACK_SIZE PAGE_SIZE
+static uint8_t intr_stack[INTR_STACK_SIZE] __attribute__((aligned(16)));
+
+hw_tss tss __attribute__((aligned(16))) =
+{
+#if defined(__i386__)
+    .esp0 = (unsigned long)&intr_stack[INTR_STACK_SIZE],
+    .ss0  = __KERN_DS,
+#elif defined(__x86_64__)
+    .rsp0 = (unsigned long)&intr_stack[INTR_STACK_SIZE],
+#endif
+    .iopb = X86_TSS_INVALID_IO_BITMAP,
+};
+
+static void setup_gate(unsigned int entry, void *addr, unsigned int dpl)
+{
+    idt[entry].offset0 = (unsigned long)addr & 0xffff;
+    idt[entry].selector = __KERN_CS;
+    idt[entry]._r0 = 0;
+    idt[entry].type = 14;
+    idt[entry].s = 0;
+    idt[entry].dpl = dpl;
+    idt[entry].p = 1;
+    idt[entry].offset1 = ((unsigned long)addr >> 16) & 0xffff;
+#if defined(__x86_64__)
+    idt[entry].ist = 0;
+    idt[entry].offset2 = ((unsigned long)addr >> 32) & 0xffffffffu;
+    idt[entry]._r1 = 0;
+#endif
+}
+
+void trap_init(void)
+{
+    setup_gate(TRAP_divide_error, &divide_error, 0);
+    setup_gate(TRAP_debug, &debug, 0);
+    setup_gate(TRAP_int3, &int3, 3);
+    setup_gate(TRAP_overflow, &overflow, 3);
+    setup_gate(TRAP_bounds, &bounds, 0);
+    setup_gate(TRAP_invalid_op, &invalid_op, 0);
+    setup_gate(TRAP_no_device, &device_not_available, 0);
+    setup_gate(TRAP_copro_seg, &coprocessor_segment_overrun, 0);
+    setup_gate(TRAP_invalid_tss, &invalid_TSS, 0);
+    setup_gate(TRAP_no_segment, &segment_not_present, 0);
+    setup_gate(TRAP_stack_error, &stack_segment, 0);
+    setup_gate(TRAP_gp_fault, &general_protection, 0);
+    setup_gate(TRAP_page_fault, &page_fault, 0);
+    setup_gate(TRAP_spurious_int, &spurious_interrupt_bug, 0);
+    setup_gate(TRAP_copro_error, &coprocessor_error, 0);
+    setup_gate(TRAP_alignment_check, &alignment_check, 0);
+    setup_gate(TRAP_simd_error, &simd_coprocessor_error, 0);
+    setup_gate(TRAP_xen_callback, hypervisor_callback, 0);
+
+    asm volatile ("lidt idt_ptr");
+
+    gdt[GDTE_TSS] = (typeof(*gdt))INIT_GDTE((unsigned long)&tss, 0x67, 0x89);
+    asm volatile ("ltr %w0" :: "rm" (GDTE_TSS * 8));
+
+    if ( hvm_set_parameter(HVM_PARAM_CALLBACK_IRQ,
+                           (2ULL << 56) | TRAP_xen_callback) )
+    {
+        xprintk("Request for Xen HVM callback vector failed\n");
+        do_exit();
+    }
+}
+
+void trap_fini(void)
+{
+}
+#endif
diff --git a/arch/x86/x86_64.S b/arch/x86/x86_64.S
index 373f400..e725c63 100644
--- a/arch/x86/x86_64.S
+++ b/arch/x86/x86_64.S
@@ -130,18 +130,22 @@ KERNEL_CS_MASK = 0xfc
 .endm
 
 .macro HYPERVISOR_IRET flag
+#ifdef CONFIG_PARAVIRT
 	testl $NMI_MASK,2*8(%rsp)
 	jnz   2f
+#endif
 
 	/* Direct iret to kernel space. Correct CS and SS. */
 	orb   $3,1*8(%rsp)
 	orb   $3,4*8(%rsp)
 	iretq
 
+#ifdef CONFIG_PARAVIRT
 2:	/* Slow iret via hypervisor. */
 	andl  $~NMI_MASK, 16(%rsp)
 	pushq $\flag
 	jmp  hypercall_page + (__HYPERVISOR_iret * 32)
+#endif
 .endm
 
 
diff --git a/include/x86/os.h b/include/x86/os.h
index 610d8e0..6826b9f 100644
--- a/include/x86/os.h
+++ b/include/x86/os.h
@@ -56,6 +56,7 @@
 #define TRAP_machine_check    18
 #define TRAP_simd_error       19
 #define TRAP_deferred_nmi     31
+#define TRAP_xen_callback     32
 
 /* Everything below this point is not included by assembler (.S) files. */
 #ifndef __ASSEMBLY__
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 09/22] mini-os: support HVMlite traps
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (7 preceding siblings ...)
  2016-08-23 15:15 ` [PATCH 08/22] mini-os: initialize trap handling for HVMlite Juergen Gross
@ 2016-08-23 15:15 ` Juergen Gross
  2016-08-23 22:10   ` Samuel Thibault
  2016-08-23 15:15 ` [PATCH 10/22] mini-os: make p2m related code depend on CONFIG_PARAVIRT Juergen Gross
                   ` (12 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:15 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

Trap handling in HVMlite domain is different from pv one.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/traps.c  |  2 --
 arch/x86/x86_32.S | 19 ++++++++++++++--
 arch/x86/x86_64.S | 22 +++++++++++++++++-
 include/x86/os.h  | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 4 files changed, 101 insertions(+), 9 deletions(-)

diff --git a/arch/x86/traps.c b/arch/x86/traps.c
index 3b1fffb..0b3d85b 100644
--- a/arch/x86/traps.c
+++ b/arch/x86/traps.c
@@ -191,8 +191,6 @@ static void dump_mem(unsigned long addr)
     }
     printk("\n");
 }
-#define read_cr2() \
-        (HYPERVISOR_shared_info->vcpu_info[smp_processor_id()].arch.cr2)
 
 static int handling_pg_fault = 0;
 
diff --git a/arch/x86/x86_32.S b/arch/x86/x86_32.S
index 6f38708..9241418 100644
--- a/arch/x86/x86_32.S
+++ b/arch/x86/x86_32.S
@@ -8,6 +8,9 @@
 #include <xen/arch-x86_32.h>
 
 #ifdef CONFIG_PARAVIRT
+
+#define KERNEL_DS __KERNEL_DS
+
 ELFNOTE(Xen, XEN_ELFNOTE_GUEST_OS, .asciz "Mini-OS")
 ELFNOTE(Xen, XEN_ELFNOTE_LOADER, .asciz "generic")
 ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, _WORD hypercall_page)
@@ -21,6 +24,8 @@ _start:
         lss stack_start,%esp
 #else
 
+#define KERNEL_DS __KERN_DS
+
 #include "x86_hvm.S"
         movl stack_start,%esp
 
@@ -61,7 +66,7 @@ CS		= 0x2C
 	pushl %edx; \
 	pushl %ecx; \
 	pushl %ebx; \
-	movl $(__KERNEL_DS),%edx; \
+	movl $(KERNEL_DS),%edx; \
 	movl %edx,%ds; \
 	movl %edx,%es;
 
@@ -98,7 +103,7 @@ do_exception:
 	movl ORIG_EAX(%esp), %edx	# get the error code
 	movl %eax, ORIG_EAX(%esp)
 	movl %ecx, ES(%esp)
-	movl $(__KERNEL_DS), %ecx
+	movl $(KERNEL_DS), %ecx
 	movl %ecx, %ds
 	movl %ecx, %es
 	movl %esp,%eax			# pt_regs pointer
@@ -112,6 +117,7 @@ ret_from_exception:
     addl $8,%esp
     RESTORE_ALL
 
+#ifdef CONFIG_PARAVIRT
 # A note on the "critical region" in our callback handler.
 # We want to avoid stacking callback handlers due to events occurring
 # during handling of the last event. To do this, we keep events disabled
@@ -189,6 +195,15 @@ critical_fixup_table:
         .byte 0x28                            # iret
         .byte 0x00,0x00,0x00,0x00             # movb $1,1(%esi)
         .byte 0x00,0x00                       # jmp  11b
+
+#else
+
+ENTRY(hypervisor_callback)
+	pushl $0
+	pushl $do_hypervisor_callback
+	jmp do_exception
+
+#endif
        
 # Hypervisor uses this for application faults while it executes.
 ENTRY(failsafe_callback)
diff --git a/arch/x86/x86_64.S b/arch/x86/x86_64.S
index e725c63..17a9ead 100644
--- a/arch/x86/x86_64.S
+++ b/arch/x86/x86_64.S
@@ -78,9 +78,11 @@ KERNEL_CS_MASK = 0xfc
 
 /* Macros */
 .macro zeroentry sym
+#ifdef CONFIG_PARAVIRT
 	movq (%rsp),%rcx
 	movq 8(%rsp),%r11
 	addq $0x10,%rsp /* skip rcx and r11 */
+#endif
 	pushq $0	/* push error code/oldrax */
 	pushq %rax	/* push real oldrax to the rdi slot */
 	leaq  \sym(%rip),%rax
@@ -88,9 +90,11 @@ KERNEL_CS_MASK = 0xfc
 .endm
 
 .macro errorentry sym
+#ifdef CONFIG_PARAVIRT
 	movq (%rsp),%rcx
 	movq 8(%rsp),%r11
 	addq $0x10,%rsp /* rsp points to the error code */
+#endif
 	pushq %rax
 	leaq  \sym(%rip),%rax
 	jmp error_entry
@@ -133,11 +137,11 @@ KERNEL_CS_MASK = 0xfc
 #ifdef CONFIG_PARAVIRT
 	testl $NMI_MASK,2*8(%rsp)
 	jnz   2f
-#endif
 
 	/* Direct iret to kernel space. Correct CS and SS. */
 	orb   $3,1*8(%rsp)
 	orb   $3,4*8(%rsp)
+#endif
 	iretq
 
 #ifdef CONFIG_PARAVIRT
@@ -182,6 +186,7 @@ error_call_handler:
 	jmp error_exit
 
 
+#ifdef CONFIG_PARAVIRT
 /*
  * Xen event (virtual interrupt) entry point.
  */
@@ -285,11 +290,26 @@ critical_region_fixup:
 	andb $KERNEL_CS_MASK,CS(%rsp)      # CS might have changed
 	jmp  11b
 
+#else
+error_exit:
+	RESTORE_REST
+	RESTORE_ALL
+	HYPERVISOR_IRET 0
 
+/*
+ * Xen event (virtual interrupt) entry point.
+ */
+ENTRY(hypervisor_callback)
+	zeroentry do_hypervisor_callback
+
+
+#endif
 
 ENTRY(failsafe_callback)
+#ifdef CONFIG_PARAVIRT
         popq  %rcx
         popq  %r11
+#endif
         iretq
 
 
diff --git a/include/x86/os.h b/include/x86/os.h
index 6826b9f..1083328 100644
--- a/include/x86/os.h
+++ b/include/x86/os.h
@@ -31,6 +31,8 @@
 #define X86_CR4_PAE       0x00000020    /* enable physical address extensions */
 #define X86_CR4_OSFXSR    0x00000200    /* enable fast FPU save and restore */
 
+#define X86_EFLAGS_IF     0x00000200
+
 #define __KERNEL_CS  FLAT_KERNEL_CS
 #define __KERNEL_DS  FLAT_KERNEL_DS
 #define __KERNEL_SS  FLAT_KERNEL_SS
@@ -70,7 +72,7 @@ void arch_fini(void);
 
 
 
-
+#ifdef CONFIG_PARAVIRT
 
 /* 
  * The use of 'barrier' in the following reflects their use as local-lock
@@ -129,15 +131,57 @@ do {									\
 	barrier();							\
 } while (0)
 
+#define irqs_disabled()			\
+    HYPERVISOR_shared_info->vcpu_info[smp_processor_id()].evtchn_upcall_mask
+
+#else
+
+#if defined(__i386__)
+#define __SZ "l"
+#define __REG "e"
+#else
+#define __SZ "q"
+#define __REG "r"
+#endif
+
+#define __cli() asm volatile ( "cli" : : : "memory" )
+#define __sti() asm volatile ( "sti" : : : "memory" )
+
+#define __save_flags(x)                                                 \
+do {                                                                    \
+    unsigned long __f;                                                  \
+    asm volatile ( "pushf" __SZ " ; pop" __SZ " %0" : "=g" (__f));      \
+    x = (__f & X86_EFLAGS_IF) ? 1 : 0;                                  \
+} while (0)
+
+#define __restore_flags(x)                                              \
+do {                                                                    \
+    if (x) __sti();                                                     \
+    else __cli();                                                       \
+} while (0)
+
+#define __save_and_cli(x)                                               \
+do {                                                                    \
+    __save_flags(x);                                                    \
+    __cli();                                                            \
+} while (0)
+
+static inline int irqs_disabled(void)
+{
+    int flag;
+
+    __save_flags(flag);
+    return !flag;
+}
+
+#endif
+
 #define local_irq_save(x)	__save_and_cli(x)
 #define local_irq_restore(x)	__restore_flags(x)
 #define local_save_flags(x)	__save_flags(x)
 #define local_irq_disable()	__cli()
 #define local_irq_enable()	__sti()
 
-#define irqs_disabled()			\
-    HYPERVISOR_shared_info->vcpu_info[smp_processor_id()].evtchn_upcall_mask
-
 /* This is a barrier for the compiler only, NOT the processor! */
 #define barrier() __asm__ __volatile__("": : :"memory")
 
@@ -586,5 +630,20 @@ static inline void cpuid(uint32_t leaf,
 
 #undef ADDR
 
+#ifdef CONFIG_PARAVIRT
+static inline unsigned long read_cr2(void)
+{
+    return HYPERVISOR_shared_info->vcpu_info[smp_processor_id()].arch.cr2;
+}
+#else
+static inline unsigned long read_cr2(void)
+{
+    unsigned long cr2;
+
+    asm volatile ( "mov %%cr2,%0\n\t" : "=r" (cr2) );
+    return cr2;
+}
+#endif
+
 #endif /* not assembly */
 #endif /* _OS_H_ */
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 10/22] mini-os: make p2m related code depend on CONFIG_PARAVIRT
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (8 preceding siblings ...)
  2016-08-23 15:15 ` [PATCH 09/22] mini-os: support HVMlite traps Juergen Gross
@ 2016-08-23 15:15 ` Juergen Gross
  2016-08-23 22:20   ` Samuel Thibault
  2016-08-23 15:15 ` [PATCH 11/22] mini-os: add static page tables for virtual kernel area for HVMlite Juergen Gross
                   ` (11 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:15 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

All handling related to p2m is needed for paravirtualized environment
only. So put all functions operating on p2m list in #ifdef
CONFIG_PARAVIRT sections. Add a paravirt.h header defining dummy
functions for non-paravirtualized environments. Instead of using
references to start_info use dedicated variables initialized from
start_info on boot.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/arm/balloon.c                |  5 ---
 arch/arm/mm.c                     |  4 ---
 arch/x86/balloon.c                | 13 ++++++++
 arch/x86/mm.c                     | 67 +++++++++++++++++++++++++++++----------
 arch/x86/setup.c                  |  6 ++--
 arch/x86/traps.c                  |  6 ++--
 balloon.c                         |  1 +
 include/arm/arch_mm.h             |  3 --
 include/balloon.h                 |  3 --
 include/mm.h                      |  2 +-
 include/paravirt.h                | 48 ++++++++++++++++++++++++++++
 include/x86/arch_mm.h             | 40 +++++------------------
 include/xen/arch-x86/xen-x86_32.h |  2 ++
 include/xen/arch-x86/xen-x86_64.h |  2 ++
 mm.c                              |  1 +
 15 files changed, 133 insertions(+), 70 deletions(-)

diff --git a/arch/arm/balloon.c b/arch/arm/balloon.c
index 7f35328..958ecba 100644
--- a/arch/arm/balloon.c
+++ b/arch/arm/balloon.c
@@ -27,11 +27,6 @@
 
 unsigned long virt_kernel_area_end;   /* TODO: find a virtual area */
 
-int arch_expand_p2m(unsigned long max_pfn)
-{
-    return 0;
-}
-
 void arch_pfn_add(unsigned long pfn, unsigned long mfn)
 {
 }
diff --git a/arch/arm/mm.c b/arch/arm/mm.c
index fc8d4bc..4f58fc7 100644
--- a/arch/arm/mm.c
+++ b/arch/arm/mm.c
@@ -72,10 +72,6 @@ void arch_init_mm(unsigned long *start_pfn_p, unsigned long *max_pfn_p)
     *max_pfn_p = to_phys(new_device_tree) >> PAGE_SHIFT;
 }
 
-void arch_init_p2m(unsigned long max_pfn)
-{
-}
-
 void arch_init_demand_mapping_area(void)
 {
 }
diff --git a/arch/x86/balloon.c b/arch/x86/balloon.c
index 42389e4..16aaae4 100644
--- a/arch/x86/balloon.c
+++ b/arch/x86/balloon.c
@@ -26,11 +26,13 @@
 #include <mini-os/errno.h>
 #include <mini-os/lib.h>
 #include <mini-os/mm.h>
+#include <mini-os/paravirt.h>
 
 #ifdef CONFIG_BALLOON
 
 unsigned long virt_kernel_area_end = VIRT_KERNEL_AREA;
 
+#ifdef CONFIG_PARAVIRT
 static void p2m_invalidate(unsigned long *list, unsigned long start_idx)
 {
     unsigned long idx;
@@ -143,5 +145,16 @@ void arch_pfn_add(unsigned long pfn, unsigned long mfn)
         do_exit();
     }
 }
+#else
+void arch_pfn_add(unsigned long pfn, unsigned long mfn)
+{
+    pgentry_t *pgt;
+
+    pgt = need_pgt((unsigned long)pfn_to_virt(pfn));
+    ASSERT(pgt);
+    if ( !(*pgt & _PAGE_PSE) )
+        *pgt = (pgentry_t)(mfn << PAGE_SHIFT) | _PAGE_PRESENT | _PAGE_RW;
+}
+#endif
 
 #endif
diff --git a/arch/x86/mm.c b/arch/x86/mm.c
index fe18f53..0543017 100644
--- a/arch/x86/mm.c
+++ b/arch/x86/mm.c
@@ -39,6 +39,7 @@
 #include <mini-os/hypervisor.h>
 #include <mini-os/balloon.h>
 #include <mini-os/mm.h>
+#include <mini-os/paravirt.h>
 #include <mini-os/types.h>
 #include <mini-os/lib.h>
 #include <mini-os/xmalloc.h>
@@ -53,10 +54,24 @@
 
 unsigned long *phys_to_machine_mapping;
 unsigned long mfn_zero;
+pgentry_t *pt_base;
+static unsigned long first_free_pfn;
+static unsigned long last_free_pfn;
+
 extern char stack[];
 extern void page_walk(unsigned long va);
 
-#ifndef CONFIG_PARAVIRT
+#ifdef CONFIG_PARAVIRT
+void arch_mm_preinit(void *p)
+{
+    start_info_t *si = p;
+
+    phys_to_machine_mapping = (unsigned long *)si->mfn_list;
+    pt_base = (pgentry_t *)si->pt_base;
+    first_free_pfn = PFN_UP(to_phys(pt_base)) + si->nr_pt_frames;
+    last_free_pfn = si->nr_pages;
+}
+#else
 #include <mini-os/desc.h>
 user_desc gdt[NR_GDT_ENTRIES] =
 {
@@ -85,6 +100,22 @@ desc_ptr idt_ptr =
     .limit = sizeof(idt) - 1,
     .base = (unsigned long)&idt,
 };
+
+void arch_mm_preinit(void *p)
+{
+    long ret;
+    domid_t domid = DOMID_SELF;
+
+    pt_base = page_table_base;
+    first_free_pfn = PFN_UP(to_phys(&_end));
+    ret = HYPERVISOR_memory_op(XENMEM_current_reservation, &domid);
+    if ( ret < 0 )
+    {
+        xprintk("could not get memory size\n");
+        do_exit();
+    }
+    last_free_pfn = ret;
+}
 #endif
 
 /*
@@ -95,7 +126,7 @@ desc_ptr idt_ptr =
 static void new_pt_frame(unsigned long *pt_pfn, unsigned long prev_l_mfn, 
                          unsigned long offset, unsigned long level)
 {   
-    pgentry_t *tab = (pgentry_t *)start_info.pt_base;
+    pgentry_t *tab = pt_base;
     unsigned long pt_page = (unsigned long)pfn_to_virt(*pt_pfn); 
     pgentry_t prot_e, prot_t;
     mmu_update_t mmu_updates[1];
@@ -172,8 +203,8 @@ static void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
     unsigned long start_address, end_address;
     unsigned long pfn_to_map, pt_pfn = *start_pfn;
     static mmu_update_t mmu_updates[L1_PAGETABLE_ENTRIES + 1];
-    pgentry_t *tab = (pgentry_t *)start_info.pt_base, page;
-    unsigned long pt_mfn = pfn_to_mfn(virt_to_pfn(start_info.pt_base));
+    pgentry_t *tab = pt_base, page;
+    unsigned long pt_mfn = pfn_to_mfn(virt_to_pfn(pt_base));
     unsigned long offset;
     int count = 0;
     int rc;
@@ -182,6 +213,7 @@ static void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
        mapped, start the loop at the very beginning. */
     pfn_to_map = *start_pfn;
 
+#ifdef CONFIG_PARAVIRT
     if ( *max_pfn >= virt_to_pfn(HYPERVISOR_VIRT_START) )
     {
         printk("WARNING: Mini-OS trying to use Xen virtual space. "
@@ -193,6 +225,7 @@ static void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
                ((unsigned long)pfn_to_virt(*max_pfn) - 
                 (unsigned long)&_text)>>20);
     }
+#endif
 
     start_address = (unsigned long)pfn_to_virt(pfn_to_map);
     end_address = (unsigned long)pfn_to_virt(*max_pfn);
@@ -202,8 +235,8 @@ static void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
 
     while ( start_address < end_address )
     {
-        tab = (pgentry_t *)start_info.pt_base;
-        pt_mfn = pfn_to_mfn(virt_to_pfn(start_info.pt_base));
+        tab = pt_base;
+        pt_mfn = pfn_to_mfn(virt_to_pfn(pt_base));
 
 #if defined(__x86_64__)
         offset = l4_table_offset(start_address);
@@ -270,8 +303,8 @@ static void set_readonly(void *text, void *etext)
         ((unsigned long) text + PAGE_SIZE - 1) & PAGE_MASK;
     unsigned long end_address = (unsigned long) etext;
     static mmu_update_t mmu_updates[L1_PAGETABLE_ENTRIES + 1];
-    pgentry_t *tab = (pgentry_t *)start_info.pt_base, page;
-    unsigned long mfn = pfn_to_mfn(virt_to_pfn(start_info.pt_base));
+    pgentry_t *tab = pt_base, page;
+    unsigned long mfn = pfn_to_mfn(virt_to_pfn(pt_base));
     unsigned long offset;
     int count = 0;
     int rc;
@@ -280,8 +313,8 @@ static void set_readonly(void *text, void *etext)
 
     while ( start_address + PAGE_SIZE <= end_address )
     {
-        tab = (pgentry_t *)start_info.pt_base;
-        mfn = pfn_to_mfn(virt_to_pfn(start_info.pt_base));
+        tab = pt_base;
+        mfn = pfn_to_mfn(virt_to_pfn(pt_base));
 
 #if defined(__x86_64__)
         offset = l4_table_offset(start_address);
@@ -343,8 +376,8 @@ static pgentry_t *get_pgt(unsigned long va)
     pgentry_t *tab;
     unsigned offset;
 
-    tab = (pgentry_t *)start_info.pt_base;
-    mfn = virt_to_mfn(start_info.pt_base);
+    tab = pt_base;
+    mfn = virt_to_mfn(pt_base);
 
 #if defined(__x86_64__)
     offset = l4_table_offset(va);
@@ -379,8 +412,8 @@ pgentry_t *need_pgt(unsigned long va)
     unsigned long pt_pfn;
     unsigned offset;
 
-    tab = (pgentry_t *)start_info.pt_base;
-    pt_mfn = virt_to_mfn(start_info.pt_base);
+    tab = pt_base;
+    pt_mfn = virt_to_mfn(pt_base);
 
 #if defined(__x86_64__)
     offset = l4_table_offset(va);
@@ -639,6 +672,7 @@ static void clear_bootstrap(void)
         printk("Unable to unmap NULL page. rc=%d\n", rc);
 }
 
+#ifdef CONFIG_PARAVIRT
 void p2m_chk_pfn(unsigned long pfn)
 {
     if ( (pfn >> L3_P2M_SHIFT) > 0 )
@@ -670,6 +704,7 @@ void arch_init_p2m(unsigned long max_pfn)
 
     arch_remap_p2m(max_pfn);
 }
+#endif
 
 void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p)
 {
@@ -683,8 +718,8 @@ void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p)
     printk("       _end: %p(VA)\n", &_end);
 
     /* First page follows page table pages. */
-    start_pfn = PFN_UP(to_phys(start_info.pt_base)) + start_info.nr_pt_frames;
-    max_pfn = start_info.nr_pages;
+    start_pfn = first_free_pfn;
+    max_pfn = last_free_pfn;
 
     if ( max_pfn >= MAX_MEM_SIZE / PAGE_SIZE )
         max_pfn = MAX_MEM_SIZE / PAGE_SIZE - 1;
diff --git a/arch/x86/setup.c b/arch/x86/setup.c
index efecefb..8b6bb6e 100644
--- a/arch/x86/setup.c
+++ b/arch/x86/setup.c
@@ -131,6 +131,9 @@ arch_init(void *par)
 	/* Initialize SSE */
 	sse_init();
 
+	/* Setup memory management info from start_info. */
+	arch_mm_preinit(par);
+
 	/* Copy the start_info struct to a globally-accessible area. */
 	/* WARN: don't do printk before here, it uses information from
 	   shared_info. Use xprintk instead. */
@@ -152,9 +155,6 @@ arch_init(void *par)
 			si->cmd_line ? (const char *)si->cmd_line : "NULL");
 	printk("       stack: %p-%p\n", stack, stack + sizeof(stack));
 
-	/* set up minimal memory infos */
-	phys_to_machine_mapping = (unsigned long *)start_info.mfn_list;
-
 	/* Grab the shared_info pointer and put it in a safe place. */
 	HYPERVISOR_shared_info = map_shared_info(start_info.shared_info);
 
diff --git a/arch/x86/traps.c b/arch/x86/traps.c
index 0b3d85b..2d3222d 100644
--- a/arch/x86/traps.c
+++ b/arch/x86/traps.c
@@ -97,9 +97,9 @@ DO_ERROR(18, "machine check", machine_check)
 
 void page_walk(unsigned long virt_address)
 {
-        pgentry_t *tab = (pgentry_t *)start_info.pt_base, page;
+        pgentry_t *tab = pt_base, page;
         unsigned long addr = virt_address;
-        printk("Pagetable walk from virt %lx, base %lx:\n", virt_address, start_info.pt_base);
+        printk("Pagetable walk from virt %lx, base %p:\n", virt_address, pt_base);
     
 #if defined(__x86_64__)
         page = tab[l4_table_offset(addr)];
@@ -119,7 +119,7 @@ void page_walk(unsigned long virt_address)
 }
 
 static int handle_cow(unsigned long addr) {
-        pgentry_t *tab = (pgentry_t *)start_info.pt_base, page;
+        pgentry_t *tab = pt_base, page;
 	unsigned long new_page;
 	int rc;
 
diff --git a/balloon.c b/balloon.c
index 608492a..8d2f151 100644
--- a/balloon.c
+++ b/balloon.c
@@ -25,6 +25,7 @@
 #include <mini-os/balloon.h>
 #include <mini-os/errno.h>
 #include <mini-os/lib.h>
+#include <mini-os/paravirt.h>
 #include <xen/xen.h>
 #include <xen/memory.h>
 
diff --git a/include/arm/arch_mm.h b/include/arm/arch_mm.h
index f4685d8..79d9e05 100644
--- a/include/arm/arch_mm.h
+++ b/include/arm/arch_mm.h
@@ -29,9 +29,6 @@ extern uint32_t physical_address_offset;	/* Add this to a virtual address to get
 #define mfn_to_virt(_mfn)          (to_virt(PFN_PHYS(_mfn)))
 #define pfn_to_virt(_pfn)          (to_virt(PFN_PHYS(_pfn)))
 
-#define mfn_to_pfn(x) (x)
-#define pfn_to_mfn(x) (x)
-
 #define virtual_to_mfn(_virt)	   virt_to_mfn(_virt)
 
 // FIXME
diff --git a/include/balloon.h b/include/balloon.h
index d8710ad..8cd41af 100644
--- a/include/balloon.h
+++ b/include/balloon.h
@@ -39,16 +39,13 @@ extern unsigned long nr_mem_pages;
 void get_max_pages(void);
 int balloon_up(unsigned long n_pages);
 
-void arch_remap_p2m(unsigned long max_pfn);
 void mm_alloc_bitmap_remap(void);
-int arch_expand_p2m(unsigned long max_pfn);
 void arch_pfn_add(unsigned long pfn, unsigned long mfn);
 int chk_free_pages(unsigned long needed);
 
 #else /* CONFIG_BALLOON */
 
 static inline void get_max_pages(void) { }
-static inline void arch_remap_p2m(unsigned long max_pfn) { }
 static inline void mm_alloc_bitmap_remap(void) { }
 static inline int chk_free_pages(unsigned long needed)
 {
diff --git a/include/mm.h b/include/mm.h
index fc3128b..953570c 100644
--- a/include/mm.h
+++ b/include/mm.h
@@ -36,6 +36,7 @@
 #endif
 #include <xen/xen.h>
 
+#include <mini-os/paravirt.h>
 #include <mini-os/arch_limits.h>
 #include <mini-os/arch_mm.h>
 
@@ -67,7 +68,6 @@ static __inline__ int get_order(unsigned long size)
 
 void arch_init_demand_mapping_area(void);
 void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p);
-void arch_init_p2m(unsigned long max_pfn_p);
 
 unsigned long allocate_ondemand(unsigned long n, unsigned long alignment);
 /* map f[i*stride]+i*increment for i in 0..n-1, aligned on alignment pages */
diff --git a/include/paravirt.h b/include/paravirt.h
index 7852e16..15076be 100644
--- a/include/paravirt.h
+++ b/include/paravirt.h
@@ -26,7 +26,55 @@
 
 #if defined(CONFIG_PARAVIRT)
 
+#define mfn_to_pfn(_mfn) (machine_to_phys_mapping[(_mfn)])
+#define pfn_to_mfn(_pfn) (phys_to_machine_mapping[(_pfn)])
+
+/* for P2M */
+#ifdef __x86_64__
+#define P2M_SHIFT       9
 #else
+#define P2M_SHIFT       10
+#endif
+#define P2M_ENTRIES     (1UL << P2M_SHIFT)
+#define P2M_MASK        (P2M_ENTRIES - 1)
+#define L1_P2M_SHIFT    P2M_SHIFT
+#define L2_P2M_SHIFT    (2 * P2M_SHIFT)
+#define L3_P2M_SHIFT    (3 * P2M_SHIFT)
+#define L1_P2M_IDX(pfn) ((pfn) & P2M_MASK)
+#define L2_P2M_IDX(pfn) (((pfn) >> L1_P2M_SHIFT) & P2M_MASK)
+#define L3_P2M_IDX(pfn) (((pfn) >> L2_P2M_SHIFT) & P2M_MASK)
+#define INVALID_P2M_ENTRY (~0UL)
+
+void p2m_chk_pfn(unsigned long pfn);
+
+static inline unsigned long p2m_pages(unsigned long pages)
+{
+    return (pages + P2M_ENTRIES - 1) >> L1_P2M_SHIFT;
+}
+
+void arch_init_p2m(unsigned long max_pfn_p);
+
+#else
+
+#define mfn_to_pfn(_mfn) ((unsigned long)(_mfn))
+#define pfn_to_mfn(_pfn) ((unsigned long)(_pfn))
+
+static inline void arch_init_p2m(unsigned long max_pfn_p) { }
+
+#endif
+
+#if defined(CONFIG_PARAVIRT) && defined(CONFIG_BALLOON)
+
+void arch_remap_p2m(unsigned long max_pfn);
+int arch_expand_p2m(unsigned long max_pfn);
+
+#else
+
+static inline void arch_remap_p2m(unsigned long max_pfn) { }
+static inline int arch_expand_p2m(unsigned long max_pfn)
+{
+    return 0;
+}
 
 #endif
 
diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h
index 2b18b34..28ab406 100644
--- a/include/x86/arch_mm.h
+++ b/include/x86/arch_mm.h
@@ -184,31 +184,6 @@ typedef unsigned long pgentry_t;
 #define IO_PROT (L1_PROT)
 #define IO_PROT_NOCACHE (L1_PROT | _PAGE_PCD)
 
-/* for P2M */
-#ifdef __x86_64__
-#define P2M_SHIFT       9
-#else
-#define P2M_SHIFT       10
-#endif
-#define P2M_ENTRIES     (1UL << P2M_SHIFT)
-#define P2M_MASK        (P2M_ENTRIES - 1)
-#define L1_P2M_SHIFT    P2M_SHIFT
-#define L2_P2M_SHIFT    (2 * P2M_SHIFT)
-#define L3_P2M_SHIFT    (3 * P2M_SHIFT)
-#define L1_P2M_IDX(pfn) ((pfn) & P2M_MASK)
-#define L2_P2M_IDX(pfn) (((pfn) >> L1_P2M_SHIFT) & P2M_MASK)
-#define L3_P2M_IDX(pfn) (((pfn) >> L2_P2M_SHIFT) & P2M_MASK)
-#define INVALID_P2M_ENTRY (~0UL)
-
-#ifndef __ASSEMBLY__
-void p2m_chk_pfn(unsigned long pfn);
-
-static inline unsigned long p2m_pages(unsigned long pages)
-{
-    return (pages + P2M_ENTRIES - 1) >> L1_P2M_SHIFT;
-}
-#endif
-
 #include "arch_limits.h"
 #define PAGE_SIZE       __PAGE_SIZE
 #define PAGE_SHIFT      __PAGE_SHIFT
@@ -232,10 +207,14 @@ typedef unsigned long paddr_t;
 typedef unsigned long maddr_t;
 #endif
 
+extern pgentry_t *pt_base;
+#ifdef CONFIG_PARAVIRT
 extern unsigned long *phys_to_machine_mapping;
+#else
+extern pgentry_t page_table_base[];
+#endif
 extern char _text, _etext, _erodata, _edata, _end;
 extern unsigned long mfn_zero;
-#define pfn_to_mfn(_pfn) (phys_to_machine_mapping[(_pfn)])
 static __inline__ maddr_t phys_to_machine(paddr_t phys)
 {
 	maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT);
@@ -243,7 +222,6 @@ static __inline__ maddr_t phys_to_machine(paddr_t phys)
 	return machine;
 }
 
-#define mfn_to_pfn(_mfn) (machine_to_phys_mapping[(_mfn)])
 static __inline__ paddr_t machine_to_phys(maddr_t machine)
 {
 	paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT);
@@ -267,13 +245,10 @@ static __inline__ paddr_t machine_to_phys(maddr_t machine)
 #define pte_to_mfn(_pte)           (((_pte) & (PADDR_MASK&PAGE_MASK)) >> L1_PAGETABLE_SHIFT)
 #define pte_to_virt(_pte)          to_virt(mfn_to_pfn(pte_to_mfn(_pte)) << PAGE_SHIFT)
 
-
-#define PT_BASE			   ((pgentry_t *)start_info.pt_base)
-
 #ifdef __x86_64__
-#define virtual_to_l3(_virt)	   ((pgentry_t *)pte_to_virt(PT_BASE[l4_table_offset(_virt)]))
+#define virtual_to_l3(_virt)	   ((pgentry_t *)pte_to_virt(pt_base[l4_table_offset(_virt)]))
 #else
-#define virtual_to_l3(_virt)	   PT_BASE
+#define virtual_to_l3(_virt)	   pt_base
 #endif
 
 #define virtual_to_l2(_virt)	   ({ \
@@ -297,6 +272,7 @@ static __inline__ paddr_t machine_to_phys(maddr_t machine)
 #define do_map_zero(start, n) do_map_frames(start, &mfn_zero, n, 0, 0, DOMID_SELF, NULL, L1_PROT_RO)
 
 pgentry_t *need_pgt(unsigned long addr);
+void arch_mm_preinit(void *p);
 
 #endif
 
diff --git a/include/xen/arch-x86/xen-x86_32.h b/include/xen/arch-x86/xen-x86_32.h
index 1504191..6339727 100644
--- a/include/xen/arch-x86/xen-x86_32.h
+++ b/include/xen/arch-x86/xen-x86_32.h
@@ -55,6 +55,7 @@
 #define FLAT_USER_DS    FLAT_RING3_DS
 #define FLAT_USER_SS    FLAT_RING3_SS
 
+#ifdef CONFIG_PARAVIRT
 #define __HYPERVISOR_VIRT_START_PAE    0xF5800000
 #define __MACH2PHYS_VIRT_START_PAE     0xF5800000
 #define __MACH2PHYS_VIRT_END_PAE       0xF6800000
@@ -90,6 +91,7 @@
 #ifndef machine_to_phys_mapping
 #define machine_to_phys_mapping ((unsigned long *)MACH2PHYS_VIRT_START)
 #endif
+#endif
 
 /* 32-/64-bit invariability for control interfaces (domctl/sysctl). */
 #if defined(__XEN__) || defined(__XEN_TOOLS__)
diff --git a/include/xen/arch-x86/xen-x86_64.h b/include/xen/arch-x86/xen-x86_64.h
index 1c4e159..2c00111 100644
--- a/include/xen/arch-x86/xen-x86_64.h
+++ b/include/xen/arch-x86/xen-x86_64.h
@@ -70,6 +70,7 @@
 #define FLAT_USER_SS32 FLAT_RING3_SS32
 #define FLAT_USER_SS   FLAT_USER_SS64
 
+#ifdef CONFIG_PARAVIRT
 #define __HYPERVISOR_VIRT_START 0xFFFF800000000000
 #define __HYPERVISOR_VIRT_END   0xFFFF880000000000
 #define __MACH2PHYS_VIRT_START  0xFFFF800000000000
@@ -86,6 +87,7 @@
 #ifndef machine_to_phys_mapping
 #define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START)
 #endif
+#endif
 
 /*
  * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base)
diff --git a/mm.c b/mm.c
index ca0b9be..c76be7f 100644
--- a/mm.c
+++ b/mm.c
@@ -39,6 +39,7 @@
 #include <xen/memory.h>
 #include <mini-os/mm.h>
 #include <mini-os/balloon.h>
+#include <mini-os/paravirt.h>
 #include <mini-os/types.h>
 #include <mini-os/lib.h>
 #include <mini-os/xmalloc.h>
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 11/22] mini-os: add static page tables for virtual kernel area for HVMlite
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (9 preceding siblings ...)
  2016-08-23 15:15 ` [PATCH 10/22] mini-os: make p2m related code depend on CONFIG_PARAVIRT Juergen Gross
@ 2016-08-23 15:15 ` Juergen Gross
  2016-08-23 22:27   ` Samuel Thibault
  2016-08-23 15:15 ` [PATCH 12/22] mini-os: add x86 native page table handling Juergen Gross
                   ` (10 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:15 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

In HVMlite mode we need the virtual kernel area for mapping of the
console and xenbus ring pages as especially on 32 bit architecture
their pfns might be above the supported maximum memory size.

Add the page tables needed for doing the mapping.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/mm.c     | 11 +++++++++++
 arch/x86/x86_64.S |  7 +++++++
 2 files changed, 18 insertions(+)

diff --git a/arch/x86/mm.c b/arch/x86/mm.c
index 0543017..cbb5617 100644
--- a/arch/x86/mm.c
+++ b/arch/x86/mm.c
@@ -733,6 +733,17 @@ void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p)
 
     *start_pfn_p = start_pfn;
     *max_pfn_p = max_pfn;
+
+#ifndef CONFIG_PARAVIRT
+#ifdef __x86_64__
+    BUILD_BUG_ON(l4_table_offset(VIRT_KERNEL_AREA) != 1 ||
+                 l3_table_offset(VIRT_KERNEL_AREA) != 0 ||
+                 l2_table_offset(VIRT_KERNEL_AREA) != 0);
+#else
+    BUILD_BUG_ON(l3_table_offset(VIRT_KERNEL_AREA) != 0 ||
+                 l2_table_offset(VIRT_KERNEL_AREA) == 0);
+#endif
+#endif
 }
 
 grant_entry_t *arch_init_gnttab(int nr_grant_frames)
diff --git a/arch/x86/x86_64.S b/arch/x86/x86_64.S
index 17a9ead..5932bfb 100644
--- a/arch/x86/x86_64.S
+++ b/arch/x86/x86_64.S
@@ -418,10 +418,17 @@ ENTRY(__arch_switch_threads)
 .data
 .globl page_table_base
         .align __PAGE_SIZE
+page_table_virt_l2:
+        PTE(page_table_virt_l1 + L2_PROT)
+        .align __PAGE_SIZE, 0
+page_table_virt_l3:
+        PTE(page_table_virt_l2 + L3_PROT)
+        .align __PAGE_SIZE, 0
 page_table_l3:
         PTE(page_table_l2 + L3_PROT)
         .align __PAGE_SIZE, 0
 page_table_base:
         PTE(page_table_l3 + L4_PROT)
+        PTE(page_table_virt_l3 + L4_PROT)
         .align __PAGE_SIZE, 0
 #endif
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 12/22] mini-os: add x86 native page table handling
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (10 preceding siblings ...)
  2016-08-23 15:15 ` [PATCH 11/22] mini-os: add static page tables for virtual kernel area for HVMlite Juergen Gross
@ 2016-08-23 15:15 ` Juergen Gross
  2016-08-23 22:40   ` Samuel Thibault
  2016-08-23 15:15 ` [PATCH 13/22] mini-os: correct wrong calculation of alloc bitmap size Juergen Gross
                   ` (9 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:15 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

For support of HVMlite don't use mmu_update hypercalls, but write the
page table entries directly.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/mm.c         | 147 +++++++++++++++++++++++++++++++++++++-------------
 arch/x86/traps.c      |  10 ++++
 include/x86/arch_mm.h |   4 ++
 include/x86/os.h      |   9 ++++
 4 files changed, 132 insertions(+), 38 deletions(-)

diff --git a/arch/x86/mm.c b/arch/x86/mm.c
index cbb5617..f5248a4 100644
--- a/arch/x86/mm.c
+++ b/arch/x86/mm.c
@@ -123,16 +123,25 @@ void arch_mm_preinit(void *p)
  * table at offset in previous level MFN (pref_l_mfn). pt_pfn is a guest
  * PFN.
  */
+static pgentry_t pt_prot[PAGETABLE_LEVELS] = {
+    L1_PROT,
+    L2_PROT,
+    L3_PROT,
+#if defined(__x86_64__)
+    L4_PROT,
+#endif
+};
+
 static void new_pt_frame(unsigned long *pt_pfn, unsigned long prev_l_mfn, 
                          unsigned long offset, unsigned long level)
 {   
-    pgentry_t *tab = pt_base;
+    pgentry_t *tab;
     unsigned long pt_page = (unsigned long)pfn_to_virt(*pt_pfn); 
-    pgentry_t prot_e, prot_t;
+#ifdef CONFIG_PARAVIRT
     mmu_update_t mmu_updates[1];
     int rc;
+#endif
     
-    prot_e = prot_t = 0;
     DEBUG("Allocating new L%d pt frame for pfn=%lx, "
           "prev_l_mfn=%lx, offset=%lx", 
           level, *pt_pfn, prev_l_mfn, offset);
@@ -140,30 +149,12 @@ static void new_pt_frame(unsigned long *pt_pfn, unsigned long prev_l_mfn,
     /* We need to clear the page, otherwise we might fail to map it
        as a page table page */
     memset((void*) pt_page, 0, PAGE_SIZE);  
- 
-    switch ( level )
-    {
-    case L1_FRAME:
-        prot_e = L1_PROT;
-        prot_t = L2_PROT;
-        break;
-    case L2_FRAME:
-        prot_e = L2_PROT;
-        prot_t = L3_PROT;
-        break;
-#if defined(__x86_64__)
-    case L3_FRAME:
-        prot_e = L3_PROT;
-        prot_t = L4_PROT;
-        break;
-#endif
-    default:
-        printk("new_pt_frame() called with invalid level number %lu\n", level);
-        do_exit();
-        break;
-    }
 
+    ASSERT(level >= 1 && level <= PAGETABLE_LEVELS);
+
+#ifdef CONFIG_PARAVIRT
     /* Make PFN a page table page */
+    tab = pt_base;
 #if defined(__x86_64__)
     tab = pte_to_virt(tab[l4_table_offset(pt_page)]);
 #endif
@@ -172,7 +163,7 @@ static void new_pt_frame(unsigned long *pt_pfn, unsigned long prev_l_mfn,
     mmu_updates[0].ptr = (tab[l2_table_offset(pt_page)] & PAGE_MASK) + 
         sizeof(pgentry_t) * l1_table_offset(pt_page);
     mmu_updates[0].val = (pgentry_t)pfn_to_mfn(*pt_pfn) << PAGE_SHIFT | 
-        (prot_e & ~_PAGE_RW);
+        (pt_prot[level - 1] & ~_PAGE_RW);
     
     if ( (rc = HYPERVISOR_mmu_update(mmu_updates, 1, NULL, DOMID_SELF)) < 0 )
     {
@@ -184,13 +175,18 @@ static void new_pt_frame(unsigned long *pt_pfn, unsigned long prev_l_mfn,
     /* Hook the new page table page into the hierarchy */
     mmu_updates[0].ptr =
         ((pgentry_t)prev_l_mfn << PAGE_SHIFT) + sizeof(pgentry_t) * offset;
-    mmu_updates[0].val = (pgentry_t)pfn_to_mfn(*pt_pfn) << PAGE_SHIFT | prot_t;
+    mmu_updates[0].val = (pgentry_t)pfn_to_mfn(*pt_pfn) << PAGE_SHIFT |
+        pt_prot[level];
 
     if ( (rc = HYPERVISOR_mmu_update(mmu_updates, 1, NULL, DOMID_SELF)) < 0 ) 
     {
         printk("ERROR: mmu_update failed with rc=%d\n", rc);
         do_exit();
     }
+#else
+    tab = mfn_to_virt(prev_l_mfn);
+    tab[offset] = (*pt_pfn << PAGE_SHIFT) | pt_prot[level];
+#endif
 
     *pt_pfn += 1;
 }
@@ -202,12 +198,14 @@ static void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
 {
     unsigned long start_address, end_address;
     unsigned long pfn_to_map, pt_pfn = *start_pfn;
-    static mmu_update_t mmu_updates[L1_PAGETABLE_ENTRIES + 1];
     pgentry_t *tab = pt_base, page;
     unsigned long pt_mfn = pfn_to_mfn(virt_to_pfn(pt_base));
     unsigned long offset;
+#ifdef CONFIG_PARAVIRT
+    static mmu_update_t mmu_updates[L1_PAGETABLE_ENTRIES + 1];
     int count = 0;
     int rc;
+#endif
 
     /* Be conservative: even if we know there will be more pages already
        mapped, start the loop at the very beginning. */
@@ -225,6 +223,10 @@ static void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
                ((unsigned long)pfn_to_virt(*max_pfn) - 
                 (unsigned long)&_text)>>20);
     }
+#else
+    /* Round up to next 2MB boundary as we are using 2MB pages on HVMlite. */
+    pfn_to_map = (pfn_to_map + L1_PAGETABLE_ENTRIES - 1) &
+                 ~(L1_PAGETABLE_ENTRIES - 1);
 #endif
 
     start_address = (unsigned long)pfn_to_virt(pfn_to_map);
@@ -257,6 +259,7 @@ static void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
         pt_mfn = pte_to_mfn(page);
         tab = to_virt(mfn_to_pfn(pt_mfn) << PAGE_SHIFT);
         offset = l2_table_offset(start_address);        
+#ifdef CONFIG_PARAVIRT
         /* Need new L1 pt frame */
         if ( !(tab[offset] & _PAGE_PRESENT) )
             new_pt_frame(&pt_pfn, pt_mfn, offset, L1_FRAME);
@@ -288,6 +291,12 @@ static void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
             count = 0;
         }
         start_address += PAGE_SIZE;
+#else
+        if ( !(tab[offset] & _PAGE_PRESENT) )
+            tab[offset] = (pgentry_t)pfn_to_map << PAGE_SHIFT |
+                          L2_PROT | _PAGE_PSE;
+        start_address += 1UL << L2_PAGETABLE_SHIFT;
+#endif
     }
 
     *start_pfn = pt_pfn;
@@ -302,16 +311,19 @@ static void set_readonly(void *text, void *etext)
     unsigned long start_address =
         ((unsigned long) text + PAGE_SIZE - 1) & PAGE_MASK;
     unsigned long end_address = (unsigned long) etext;
-    static mmu_update_t mmu_updates[L1_PAGETABLE_ENTRIES + 1];
     pgentry_t *tab = pt_base, page;
     unsigned long mfn = pfn_to_mfn(virt_to_pfn(pt_base));
     unsigned long offset;
+    unsigned long page_size = PAGE_SIZE;
+#ifdef CONFIG_PARAVIRT
+    static mmu_update_t mmu_updates[L1_PAGETABLE_ENTRIES + 1];
     int count = 0;
     int rc;
+#endif
 
     printk("setting %p-%p readonly\n", text, etext);
 
-    while ( start_address + PAGE_SIZE <= end_address )
+    while ( start_address + page_size <= end_address )
     {
         tab = pt_base;
         mfn = pfn_to_mfn(virt_to_pfn(pt_base));
@@ -327,26 +339,34 @@ static void set_readonly(void *text, void *etext)
         mfn = pte_to_mfn(page);
         tab = to_virt(mfn_to_pfn(mfn) << PAGE_SHIFT);
         offset = l2_table_offset(start_address);        
-        page = tab[offset];
-        mfn = pte_to_mfn(page);
-        tab = to_virt(mfn_to_pfn(mfn) << PAGE_SHIFT);
+        if ( !(tab[offset] & _PAGE_PSE) )
+        {
+            page = tab[offset];
+            mfn = pte_to_mfn(page);
+            tab = to_virt(mfn_to_pfn(mfn) << PAGE_SHIFT);
 
-        offset = l1_table_offset(start_address);
+            offset = l1_table_offset(start_address);
+        }
 
         if ( start_address != (unsigned long)&shared_info )
         {
+#ifdef CONFIG_PARAVIRT
             mmu_updates[count].ptr = 
                 ((pgentry_t)mfn << PAGE_SHIFT) + sizeof(pgentry_t) * offset;
             mmu_updates[count].val = tab[offset] & ~_PAGE_RW;
             count++;
+#else
+            tab[offset] &= ~_PAGE_RW;
+#endif
         }
         else
             printk("skipped %lx\n", start_address);
 
-        start_address += PAGE_SIZE;
+        start_address += page_size;
 
+#ifdef CONFIG_PARAVIRT
         if ( count == L1_PAGETABLE_ENTRIES || 
-             start_address + PAGE_SIZE > end_address )
+             start_address + page_size > end_address )
         {
             rc = HYPERVISOR_mmu_update(mmu_updates, count, NULL, DOMID_SELF);
             if ( rc < 0 )
@@ -356,8 +376,13 @@ static void set_readonly(void *text, void *etext)
             }
             count = 0;
         }
+#else
+        if ( start_address == (1UL << L2_PAGETABLE_SHIFT) )
+            page_size = 1UL << L2_PAGETABLE_SHIFT;
+#endif
     }
 
+#ifdef CONFIG_PARAVIRT
     {
         mmuext_op_t op = {
             .cmd = MMUEXT_TLB_FLUSH_ALL,
@@ -365,6 +390,9 @@ static void set_readonly(void *text, void *etext)
         int count;
         HYPERVISOR_mmuext_op(&op, 1, &count, DOMID_SELF);
     }
+#else
+    write_cr3((unsigned long)pt_base);
+#endif
 }
 
 /*
@@ -394,6 +422,8 @@ static pgentry_t *get_pgt(unsigned long va)
     offset = l2_table_offset(va);
     if ( !(tab[offset] & _PAGE_PRESENT) )
         return NULL;
+    if ( tab[offset] & _PAGE_PSE )
+        return &tab[offset];
     mfn = pte_to_mfn(tab[offset]);
     tab = mfn_to_virt(mfn);
     offset = l1_table_offset(va);
@@ -448,6 +478,9 @@ pgentry_t *need_pgt(unsigned long va)
         new_pt_frame(&pt_pfn, pt_mfn, offset, L1_FRAME);
     }
     ASSERT(tab[offset] & _PAGE_PRESENT);
+    if ( tab[offset] & _PAGE_PSE )
+        return &tab[offset];
+
     pt_mfn = pte_to_mfn(tab[offset]);
     tab = mfn_to_virt(pt_mfn);
 
@@ -524,8 +557,6 @@ int do_map_frames(unsigned long va,
 {
     pgentry_t *pgt = NULL;
     unsigned long done = 0;
-    unsigned long i;
-    int rc;
 
     if ( !mfns ) 
     {
@@ -539,6 +570,9 @@ int do_map_frames(unsigned long va,
         memset(err, 0x00, n * sizeof(int));
     while ( done < n )
     {
+#ifdef CONFIG_PARAVIRT
+        unsigned long i;
+        int rc;
         unsigned long todo;
 
         if ( err )
@@ -578,6 +612,17 @@ int do_map_frames(unsigned long va,
             }
         }
         done += todo;
+#else
+        if ( !pgt || !(va & L1_MASK) )
+            pgt = need_pgt(va & ~L1_MASK);
+        if ( !pgt )
+            return -ENOMEM;
+
+        ASSERT(!(*pgt & _PAGE_PSE));
+        pgt[l1_table_offset(va)] = (pgentry_t)
+            (((mfns[done * stride] + done * incr) << PAGE_SHIFT) | prot);
+        done++;
+#endif
     }
 
     return 0;
@@ -609,16 +654,21 @@ void *map_frames_ex(const unsigned long *mfns, unsigned long n,
 #define UNMAP_BATCH ((STACK_SIZE / 2) / sizeof(multicall_entry_t))
 int unmap_frames(unsigned long va, unsigned long num_frames)
 {
+#ifdef CONFIG_PARAVIRT
     int n = UNMAP_BATCH;
     multicall_entry_t call[n];
     int ret;
     int i;
+#else
+    pgentry_t *pgt;
+#endif
 
     ASSERT(!((unsigned long)va & ~PAGE_MASK));
 
     DEBUG("va=%p, num=0x%lx\n", va, num_frames);
 
     while ( num_frames ) {
+#ifdef CONFIG_PARAVIRT
         if ( n > num_frames )
             n = num_frames;
 
@@ -653,6 +703,17 @@ int unmap_frames(unsigned long va, unsigned long num_frames)
             }
         }
         num_frames -= n;
+#else
+        pgt = get_pgt(va);
+        if ( pgt )
+        {
+            ASSERT(!(*pgt & _PAGE_PSE));
+            *pgt = 0;
+            invlpg(va);
+        }
+        va += PAGE_SIZE;
+        num_frames--;
+#endif
     }
     return 0;
 }
@@ -662,14 +723,24 @@ int unmap_frames(unsigned long va, unsigned long num_frames)
  */
 static void clear_bootstrap(void)
 {
+#ifdef CONFIG_PARAVIRT
     pte_t nullpte = { };
     int rc;
+#else
+    pgentry_t *pgt;
+#endif
 
     /* Use first page as the CoW zero page */
     memset(&_text, 0, PAGE_SIZE);
     mfn_zero = virt_to_mfn((unsigned long) &_text);
+#ifdef CONFIG_PARAVIRT
     if ( (rc = HYPERVISOR_update_va_mapping(0, nullpte, UVMF_INVLPG)) )
         printk("Unable to unmap NULL page. rc=%d\n", rc);
+#else
+    pgt = get_pgt((unsigned long)&_text);
+    *pgt = 0;
+    invlpg((unsigned long)&_text);
+#endif
 }
 
 #ifdef CONFIG_PARAVIRT
diff --git a/arch/x86/traps.c b/arch/x86/traps.c
index 2d3222d..aa17da3 100644
--- a/arch/x86/traps.c
+++ b/arch/x86/traps.c
@@ -121,7 +121,9 @@ void page_walk(unsigned long virt_address)
 static int handle_cow(unsigned long addr) {
         pgentry_t *tab = pt_base, page;
 	unsigned long new_page;
+#ifdef CONFIG_PARAVIRT
 	int rc;
+#endif
 
 #if defined(__x86_64__)
         page = tab[l4_table_offset(addr)];
@@ -137,6 +139,8 @@ static int handle_cow(unsigned long addr) {
         page = tab[l2_table_offset(addr)];
 	if (!(page & _PAGE_PRESENT))
 	    return 0;
+	if ( page & _PAGE_PSE )
+	    return 0;
         tab = pte_to_virt(page);
         
         page = tab[l1_table_offset(addr)];
@@ -149,12 +153,18 @@ static int handle_cow(unsigned long addr) {
 	new_page = alloc_pages(0);
 	memset((void*) new_page, 0, PAGE_SIZE);
 
+#ifdef CONFIG_PARAVIRT
 	rc = HYPERVISOR_update_va_mapping(addr & PAGE_MASK, __pte(virt_to_mach(new_page) | L1_PROT), UVMF_INVLPG);
 	if (!rc)
 		return 1;
 
 	printk("Map zero page to %lx failed: %d.\n", addr, rc);
 	return 0;
+#else
+	tab[l1_table_offset(addr)] = virt_to_mach(new_page) | L1_PROT;
+	invlpg(addr);
+	return 1;
+#endif
 }
 
 static void do_stack_walk(unsigned long frame_base)
diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h
index 28ab406..e0ae552 100644
--- a/include/x86/arch_mm.h
+++ b/include/x86/arch_mm.h
@@ -78,6 +78,8 @@
 #define L2_PAGETABLE_ENTRIES    512
 #define L3_PAGETABLE_ENTRIES    4
 
+#define PAGETABLE_LEVELS        3
+
 #define PADDR_BITS              44
 #define PADDR_MASK              ((1ULL << PADDR_BITS)-1)
 
@@ -110,6 +112,8 @@ typedef uint64_t pgentry_t;
 #define L3_PAGETABLE_ENTRIES    512
 #define L4_PAGETABLE_ENTRIES    512
 
+#define PAGETABLE_LEVELS        4
+
 /* These are page-table limitations. Current CPUs support only 40-bit phys. */
 #define PADDR_BITS              52
 #define VADDR_BITS              48
diff --git a/include/x86/os.h b/include/x86/os.h
index 1083328..20cc27f 100644
--- a/include/x86/os.h
+++ b/include/x86/os.h
@@ -206,6 +206,15 @@ static inline int irqs_disabled(void)
  */
 typedef struct { volatile int counter; } atomic_t;
 
+static inline void write_cr3(unsigned long cr3)
+{
+    asm volatile( "mov %0, %%cr3" : : "r" (cr3) : "memory" );
+}
+
+static inline void invlpg(unsigned long va)
+{
+    asm volatile ( "invlpg %0": : "m" (*(const char *)(va)) : "memory" );
+}
 
 /************************** i386 *******************************/
 #ifdef __INSIDE_MINIOS__
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 13/22] mini-os: correct wrong calculation of alloc bitmap size
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (11 preceding siblings ...)
  2016-08-23 15:15 ` [PATCH 12/22] mini-os: add x86 native page table handling Juergen Gross
@ 2016-08-23 15:15 ` Juergen Gross
  2016-08-23 19:49   ` Samuel Thibault
  2016-08-23 15:16 ` [PATCH 14/22] mini-os: add map_frame_virt() function Juergen Gross
                   ` (8 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:15 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

When remapping the page allocator's bitmap for the ballooning support
the calculation of the needed size is wrong. This doesn't really
matter today as nothing is allocated after that bitmap, but it should
be corrected nevertheless.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 balloon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/balloon.c b/balloon.c
index 8d2f151..8669edb 100644
--- a/balloon.c
+++ b/balloon.c
@@ -52,7 +52,7 @@ void mm_alloc_bitmap_remap(void)
 {
     unsigned long i;
 
-    if ( mm_alloc_bitmap_size >= ((nr_max_pages + 1) >> (PAGE_SHIFT + 3)) )
+    if ( mm_alloc_bitmap_size >= ((nr_max_pages + 1) >> 3) )
         return;
 
     for ( i = 0; i < mm_alloc_bitmap_size; i += PAGE_SIZE )
@@ -62,7 +62,7 @@ void mm_alloc_bitmap_remap(void)
     }
 
     mm_alloc_bitmap = (unsigned long *)virt_kernel_area_end;
-    virt_kernel_area_end += round_pgup((nr_max_pages + 1) >> (PAGE_SHIFT + 3));
+    virt_kernel_area_end += round_pgup((nr_max_pages + 1) >> 3);
     ASSERT(virt_kernel_area_end <= VIRT_DEMAND_AREA);
 }
 
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 14/22] mini-os: add map_frame_virt() function
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (12 preceding siblings ...)
  2016-08-23 15:15 ` [PATCH 13/22] mini-os: correct wrong calculation of alloc bitmap size Juergen Gross
@ 2016-08-23 15:16 ` Juergen Gross
  2016-08-23 22:42   ` Samuel Thibault
  2016-08-23 15:16 ` [PATCH 15/22] mini-os: setup console interface parameters Juergen Gross
                   ` (7 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:16 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

Add a function map_frame_virt() to map a given frame and return its
virtual address.

On arm we just use the frame physical address, while on x86 we take a
page from the virtual kernel area. For this purpose make this area
available even in case of undefined CONFIG_BALLOON.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/arm/balloon.c    |  2 --
 arch/arm/mm.c         |  5 +++++
 arch/x86/balloon.c    | 13 ++++---------
 arch/x86/mm.c         | 23 +++++++++++++++++++++++
 balloon.c             |  9 ++++-----
 include/balloon.h     |  1 -
 include/mm.h          |  1 +
 include/x86/arch_mm.h |  1 +
 8 files changed, 38 insertions(+), 17 deletions(-)

diff --git a/arch/arm/balloon.c b/arch/arm/balloon.c
index 958ecba..1df7d1c 100644
--- a/arch/arm/balloon.c
+++ b/arch/arm/balloon.c
@@ -25,8 +25,6 @@
 
 #ifdef CONFIG_BALLOON
 
-unsigned long virt_kernel_area_end;   /* TODO: find a virtual area */
-
 void arch_pfn_add(unsigned long pfn, unsigned long mfn)
 {
 }
diff --git a/arch/arm/mm.c b/arch/arm/mm.c
index 4f58fc7..dbde162 100644
--- a/arch/arm/mm.c
+++ b/arch/arm/mm.c
@@ -141,3 +141,8 @@ grant_entry_t *arch_init_gnttab(int nr_grant_frames)
 
     return to_virt(gnttab_table);
 }
+
+unsigned long map_frame_virt(unsigned long mfn)
+{
+    return mfn_to_virt(mfn);
+}
diff --git a/arch/x86/balloon.c b/arch/x86/balloon.c
index 16aaae4..10b440c 100644
--- a/arch/x86/balloon.c
+++ b/arch/x86/balloon.c
@@ -29,9 +29,6 @@
 #include <mini-os/paravirt.h>
 
 #ifdef CONFIG_BALLOON
-
-unsigned long virt_kernel_area_end = VIRT_KERNEL_AREA;
-
 #ifdef CONFIG_PARAVIRT
 static void p2m_invalidate(unsigned long *list, unsigned long start_idx)
 {
@@ -53,7 +50,7 @@ static inline unsigned long *p2m_to_virt(unsigned long p2m)
 
 void arch_remap_p2m(unsigned long max_pfn)
 {
-    unsigned long pfn;
+    unsigned long pfn, new_p2m;
     unsigned long *l3_list, *l2_list, *l1_list;
 
     l3_list = p2m_l3list();
@@ -67,17 +64,15 @@ void arch_remap_p2m(unsigned long max_pfn)
     if ( p2m_pages(nr_max_pages) <= p2m_pages(max_pfn) )
         return;
 
+    new_p2m = alloc_virt_kernel(p2m_pages(nr_max_pages));
     for ( pfn = 0; pfn < max_pfn; pfn += P2M_ENTRIES )
     {
-        map_frame_rw(virt_kernel_area_end + PAGE_SIZE * (pfn / P2M_ENTRIES),
+        map_frame_rw(new_p2m + PAGE_SIZE * (pfn / P2M_ENTRIES),
                      virt_to_mfn(phys_to_machine_mapping + pfn));
     }
 
-    phys_to_machine_mapping = (unsigned long *)virt_kernel_area_end;
+    phys_to_machine_mapping = (unsigned long *)new_p2m;
     printk("remapped p2m list to %p\n", phys_to_machine_mapping);
-
-    virt_kernel_area_end += PAGE_SIZE * p2m_pages(nr_max_pages);
-    ASSERT(virt_kernel_area_end <= VIRT_DEMAND_AREA);
 }
 
 int arch_expand_p2m(unsigned long max_pfn)
diff --git a/arch/x86/mm.c b/arch/x86/mm.c
index f5248a4..762599d 100644
--- a/arch/x86/mm.c
+++ b/arch/x86/mm.c
@@ -57,6 +57,7 @@ unsigned long mfn_zero;
 pgentry_t *pt_base;
 static unsigned long first_free_pfn;
 static unsigned long last_free_pfn;
+static unsigned long virt_kernel_area_end = VIRT_KERNEL_AREA;
 
 extern char stack[];
 extern void page_walk(unsigned long va);
@@ -829,3 +830,25 @@ grant_entry_t *arch_init_gnttab(int nr_grant_frames)
     HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1);
     return map_frames(frames, nr_grant_frames);
 }
+
+unsigned long alloc_virt_kernel(unsigned n_pages)
+{
+    unsigned long addr;
+
+    addr = virt_kernel_area_end;
+    virt_kernel_area_end += PAGE_SIZE * n_pages;
+    ASSERT(virt_kernel_area_end <= VIRT_DEMAND_AREA);
+
+    return addr;
+}
+
+unsigned long map_frame_virt(unsigned long mfn)
+{
+    unsigned long addr;
+
+    addr = alloc_virt_kernel(1);
+    if ( map_frame_rw(addr, mfn) )
+        return 0;
+
+    return addr;
+}
diff --git a/balloon.c b/balloon.c
index 8669edb..b0d0230 100644
--- a/balloon.c
+++ b/balloon.c
@@ -50,20 +50,19 @@ void get_max_pages(void)
 
 void mm_alloc_bitmap_remap(void)
 {
-    unsigned long i;
+    unsigned long i, new_bitmap;
 
     if ( mm_alloc_bitmap_size >= ((nr_max_pages + 1) >> 3) )
         return;
 
+    new_bitmap = alloc_virt_kernel(PFN_UP((nr_max_pages + 1) >> 3));
     for ( i = 0; i < mm_alloc_bitmap_size; i += PAGE_SIZE )
     {
-        map_frame_rw(virt_kernel_area_end + i,
+        map_frame_rw(new_bitmap + i,
                      virt_to_mfn((unsigned long)(mm_alloc_bitmap) + i));
     }
 
-    mm_alloc_bitmap = (unsigned long *)virt_kernel_area_end;
-    virt_kernel_area_end += round_pgup((nr_max_pages + 1) >> 3);
-    ASSERT(virt_kernel_area_end <= VIRT_DEMAND_AREA);
+    mm_alloc_bitmap = (unsigned long *)new_bitmap;
 }
 
 #define N_BALLOON_FRAMES 64
diff --git a/include/balloon.h b/include/balloon.h
index 8cd41af..6cfec4f 100644
--- a/include/balloon.h
+++ b/include/balloon.h
@@ -33,7 +33,6 @@
 #define BALLOON_EMERGENCY_PAGES   64
 
 extern unsigned long nr_max_pages;
-extern unsigned long virt_kernel_area_end;
 extern unsigned long nr_mem_pages;
 
 void get_max_pages(void);
diff --git a/include/mm.h b/include/mm.h
index 953570c..4fc364f 100644
--- a/include/mm.h
+++ b/include/mm.h
@@ -79,6 +79,7 @@ int do_map_frames(unsigned long addr,
 	unsigned long increment, domid_t id, int *err, unsigned long prot);
 int unmap_frames(unsigned long va, unsigned long num_frames);
 int map_frame_rw(unsigned long addr, unsigned long mfn);
+unsigned long map_frame_virt(unsigned long mfn);
 #ifdef HAVE_LIBC
 extern unsigned long heap, brk, heap_mapped, heap_end;
 #endif
diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h
index e0ae552..9372f1e 100644
--- a/include/x86/arch_mm.h
+++ b/include/x86/arch_mm.h
@@ -277,6 +277,7 @@ static __inline__ paddr_t machine_to_phys(maddr_t machine)
 
 pgentry_t *need_pgt(unsigned long addr);
 void arch_mm_preinit(void *p);
+unsigned long alloc_virt_kernel(unsigned n_pages);
 
 #endif
 
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 15/22] mini-os: setup console interface parameters
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (13 preceding siblings ...)
  2016-08-23 15:16 ` [PATCH 14/22] mini-os: add map_frame_virt() function Juergen Gross
@ 2016-08-23 15:16 ` Juergen Gross
  2016-08-23 22:44   ` Samuel Thibault
  2016-08-23 15:16 ` [PATCH 16/22] mini-os: setup xenbus " Juergen Gross
                   ` (6 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:16 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

In order to support HVMlite we need to get the ring page and event
channel from the hypervisor via hypercalls. Move the already existing
get_console() function from arm specific coding to
console/xencons_ring.c and provide a similar paravirtualized function.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/arm/setup.c       | 16 +---------------
 arch/x86/setup.c       |  1 +
 console/xencons_ring.c | 38 ++++++++++++++++++++++++++++++--------
 events.c               |  2 +-
 include/console.h      |  3 ++-
 5 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/arch/arm/setup.c b/arch/arm/setup.c
index cbe67c6..a021616 100644
--- a/arch/arm/setup.c
+++ b/arch/arm/setup.c
@@ -25,20 +25,6 @@ extern char shared_info_page[PAGE_SIZE];
 
 void *device_tree;
 
-static void get_console(void)
-{
-    uint64_t v = -1;
-
-    hvm_get_parameter(HVM_PARAM_CONSOLE_EVTCHN, &v);
-    start_info.console.domU.evtchn = v;
-
-    hvm_get_parameter(HVM_PARAM_CONSOLE_PFN, &v);
-    start_info.console.domU.mfn = v;
-
-    printk("Console is on port %d\n", start_info.console.domU.evtchn);
-    printk("Console ring is at mfn %lx\n", (unsigned long) start_info.console.domU.mfn);
-}
-
 void get_xenbus(void)
 {
     uint64_t value;
@@ -85,7 +71,7 @@ void arch_init(void *dtb_pointer, uint32_t physical_offset)
     HYPERVISOR_shared_info = (struct shared_info *)shared_info_page;
 
     /* Fill in start_info */
-    get_console();
+    get_console(NULL);
     get_xenbus();
 
     gic_init();
diff --git a/arch/x86/setup.c b/arch/x86/setup.c
index 8b6bb6e..0c1f2ec 100644
--- a/arch/x86/setup.c
+++ b/arch/x86/setup.c
@@ -137,6 +137,7 @@ arch_init(void *par)
 	/* Copy the start_info struct to a globally-accessible area. */
 	/* WARN: don't do printk before here, it uses information from
 	   shared_info. Use xprintk instead. */
+	get_console(par);
 	si = par;
 	memcpy(&start_info, si, sizeof(*si));
 
diff --git a/console/xencons_ring.c b/console/xencons_ring.c
index 81c8e99..dd64a41 100644
--- a/console/xencons_ring.c
+++ b/console/xencons_ring.c
@@ -9,27 +9,49 @@
 #include <xen/io/console.h>
 #include <xen/io/protocols.h>
 #include <xen/io/ring.h>
+#include <xen/hvm/params.h>
 #include <mini-os/xmalloc.h>
 #include <mini-os/gnttab.h>
 #include "console.h"
 
 DECLARE_WAIT_QUEUE_HEAD(console_queue);
 
+static struct xencons_interface *console_ring;
+uint32_t console_evtchn;
+
+#ifdef CONFIG_PARAVIRT
+void get_console(void *p)
+{
+    start_info_t *si = p;
+
+    console_ring = mfn_to_virt(si->console.domU.mfn);
+    console_evtchn = si->console.domU.evtchn;
+}
+#else
+void get_console(void *p)
+{
+    uint64_t v = -1;
+
+    hvm_get_parameter(HVM_PARAM_CONSOLE_EVTCHN, &v);
+    console_evtchn = v;
+
+    hvm_get_parameter(HVM_PARAM_CONSOLE_PFN, &v);
+    console_ring = (struct xencons_interface *)map_frame_virt(v);
+}
+#endif
+
 static inline void notify_daemon(struct consfront_dev *dev)
 {
     /* Use evtchn: this is called early, before irq is set up. */
     if (!dev)
-        notify_remote_via_evtchn(start_info.console.domU.evtchn);
+        notify_remote_via_evtchn(console_evtchn);
     else
         notify_remote_via_evtchn(dev->evtchn);
 }
 
 static inline struct xencons_interface *xencons_interface(void)
 {
-    if (start_info.console.domU.evtchn)
-        return mfn_to_virt(start_info.console.domU.mfn);
-    else
-        return NULL;
+    return console_evtchn ? console_ring : NULL;
 } 
  
 int xencons_ring_send_no_notify(struct consfront_dev *dev, const char *data, unsigned len)
@@ -158,7 +180,7 @@ struct consfront_dev *xencons_ring_init(void)
 	int err;
 	struct consfront_dev *dev;
 
-	if (!start_info.console.domU.evtchn)
+	if (!console_evtchn)
 		return 0;
 
 	dev = malloc(sizeof(struct consfront_dev));
@@ -171,8 +193,8 @@ struct consfront_dev *xencons_ring_init(void)
 #ifdef HAVE_LIBC
 	dev->fd = -1;
 #endif
-	dev->evtchn = start_info.console.domU.evtchn;
-	dev->ring = (struct xencons_interface *) mfn_to_virt(start_info.console.domU.mfn);
+	dev->evtchn = console_evtchn;
+	dev->ring = xencons_interface();
 
 	err = bind_evtchn(dev->evtchn, console_handle_input, dev);
 	if (err <= 0) {
diff --git a/events.c b/events.c
index 2a23042..76ea617 100644
--- a/events.c
+++ b/events.c
@@ -46,7 +46,7 @@ void unbind_all_ports(void)
 
     for ( i = 0; i < NR_EVS; i++ )
     {
-        if ( i == start_info.console.domU.evtchn ||
+        if ( i == console_evtchn ||
              i == start_info.store_evtchn)
             continue;
 
diff --git a/include/console.h b/include/console.h
index a77f47f..eb327a8 100644
--- a/include/console.h
+++ b/include/console.h
@@ -61,7 +61,7 @@ struct consfront_dev {
 #endif
 };
 
-
+extern uint32_t console_evtchn;
 
 void print(int direct, const char *fmt, va_list args);
 void printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
@@ -72,6 +72,7 @@ void xprintk(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
 void xencons_rx(char *buf, unsigned len, struct pt_regs *regs);
 void xencons_tx(void);
 
+void get_console(void *p);
 void init_console(void);
 void console_print(struct consfront_dev *dev, char *data, int length);
 void fini_console(struct consfront_dev *dev);
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 16/22] mini-os: setup xenbus interface parameters
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (14 preceding siblings ...)
  2016-08-23 15:16 ` [PATCH 15/22] mini-os: setup console interface parameters Juergen Gross
@ 2016-08-23 15:16 ` Juergen Gross
  2016-08-23 22:45   ` Samuel Thibault
  2016-08-23 15:16 ` [PATCH 17/22] mini-os: add get_cmdline() function Juergen Gross
                   ` (5 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:16 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

In order to support HVMlite we need to get the ring page and event
channel from the hypervisor via hypercalls. Move the already existing
get_xenbus() function from arm specific coding to xenbus/xenbus.c and
provide a similar paravirtualized function.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/arm/setup.c | 16 +---------------
 arch/x86/setup.c |  1 +
 events.c         |  3 +--
 include/xenbus.h |  3 +++
 xenbus/xenbus.c  | 40 +++++++++++++++++++++++++++++++---------
 5 files changed, 37 insertions(+), 26 deletions(-)

diff --git a/arch/arm/setup.c b/arch/arm/setup.c
index a021616..72e025a 100644
--- a/arch/arm/setup.c
+++ b/arch/arm/setup.c
@@ -25,20 +25,6 @@ extern char shared_info_page[PAGE_SIZE];
 
 void *device_tree;
 
-void get_xenbus(void)
-{
-    uint64_t value;
-
-    if (hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &value))
-        BUG();
-
-    start_info.store_evtchn = (int)value;
-
-    if(hvm_get_parameter(HVM_PARAM_STORE_PFN, &value))
-        BUG();
-    start_info.store_mfn = (unsigned long)value;
-}
-
 /*
  * INITIAL C ENTRY POINT.
  */
@@ -72,7 +58,7 @@ void arch_init(void *dtb_pointer, uint32_t physical_offset)
 
     /* Fill in start_info */
     get_console(NULL);
-    get_xenbus();
+    get_xenbus(NULL);
 
     gic_init();
 
diff --git a/arch/x86/setup.c b/arch/x86/setup.c
index 0c1f2ec..6645784 100644
--- a/arch/x86/setup.c
+++ b/arch/x86/setup.c
@@ -138,6 +138,7 @@ arch_init(void *par)
 	/* WARN: don't do printk before here, it uses information from
 	   shared_info. Use xprintk instead. */
 	get_console(par);
+	get_xenbus(par);
 	si = par;
 	memcpy(&start_info, si, sizeof(*si));
 
diff --git a/events.c b/events.c
index 76ea617..e8ef8aa 100644
--- a/events.c
+++ b/events.c
@@ -46,8 +46,7 @@ void unbind_all_ports(void)
 
     for ( i = 0; i < NR_EVS; i++ )
     {
-        if ( i == console_evtchn ||
-             i == start_info.store_evtchn)
+        if ( i == console_evtchn || i == xenbus_evtchn )
             continue;
 
         if ( test_and_clear_bit(i, bound_ports) )
diff --git a/include/xenbus.h b/include/xenbus.h
index d3bb7af..5646a25 100644
--- a/include/xenbus.h
+++ b/include/xenbus.h
@@ -29,6 +29,9 @@ struct xenbus_event {
 };
 typedef struct xenbus_event *xenbus_event_queue;
 
+extern uint32_t xenbus_evtchn;
+
+void get_xenbus(void *p);
 char *xenbus_watch_path_token(xenbus_transaction_t xbt, const char *path, const char *token, xenbus_event_queue *events);
 char *xenbus_unwatch_path_token(xenbus_transaction_t xbt, const char *path, const char *token);
 extern struct wait_queue_head xenbus_watch_queue;
diff --git a/xenbus/xenbus.c b/xenbus/xenbus.c
index 0ab387a..636786c 100644
--- a/xenbus/xenbus.c
+++ b/xenbus/xenbus.c
@@ -26,6 +26,7 @@
 #include <mini-os/sched.h>
 #include <mini-os/wait.h>
 #include <xen/io/xs_wire.h>
+#include <xen/hvm/params.h>
 #include <mini-os/spinlock.h>
 #include <mini-os/xmalloc.h>
 
@@ -62,6 +63,31 @@ struct xenbus_req_info
 #define NR_REQS 32
 static struct xenbus_req_info req_info[NR_REQS];
 
+uint32_t xenbus_evtchn;
+
+#ifdef CONFIG_PARAVIRT
+void get_xenbus(void *p)
+{
+    start_info_t *si = p;
+
+    xenbus_evtchn = si->store_evtchn;
+    xenstore_buf = mfn_to_virt(si->store_mfn);
+}
+#else
+void get_xenbus(void *p)
+{
+    uint64_t v;
+
+    if ( hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v) )
+        BUG();
+    xenbus_evtchn = v;
+
+    if( hvm_get_parameter(HVM_PARAM_STORE_PFN, &v) )
+        BUG();
+    xenstore_buf = (struct xenstore_domain_interface *)map_frame_virt(v);
+}
+#endif
+
 static void memcpy_from_ring(const void *Ring,
         void *Dest,
         int off,
@@ -269,7 +295,7 @@ static void xenbus_thread_func(void *ign)
             }
 
             wmb();
-            notify_remote_via_evtchn(start_info.store_evtchn);
+            notify_remote_via_evtchn(xenbus_evtchn);
         }
     }
 }
@@ -335,15 +361,11 @@ void init_xenbus(void)
 {
     int err;
     DEBUG("init_xenbus called.\n");
-    xenstore_buf = mfn_to_virt(start_info.store_mfn);
     create_thread("xenstore", xenbus_thread_func, NULL);
     DEBUG("buf at %p.\n", xenstore_buf);
-    err = bind_evtchn(start_info.store_evtchn,
-		      xenbus_evtchn_handler,
-              NULL);
-    unmask_evtchn(start_info.store_evtchn);
-    printk("xenbus initialised on irq %d mfn %#llx\n",
-	   err, (unsigned long long) start_info.store_mfn);
+    err = bind_evtchn(xenbus_evtchn, xenbus_evtchn_handler, NULL);
+    unmask_evtchn(xenbus_evtchn);
+    printk("xenbus initialised on irq %d\n", err);
 }
 
 void fini_xenbus(void)
@@ -425,7 +447,7 @@ static void xb_write(int type, int req_id, xenbus_transaction_t trans_id,
     xenstore_buf->req_prod += len;
 
     /* Send evtchn to notify remote */
-    notify_remote_via_evtchn(start_info.store_evtchn);
+    notify_remote_via_evtchn(xenbus_evtchn);
 }
 
 /* Send a mesasge to xenbus, in the same fashion as xb_write, and
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 17/22] mini-os: add get_cmdline() function
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (15 preceding siblings ...)
  2016-08-23 15:16 ` [PATCH 16/22] mini-os: setup xenbus " Juergen Gross
@ 2016-08-23 15:16 ` Juergen Gross
  2016-08-23 23:03   ` [Minios-devel] " Samuel Thibault
  2016-08-23 15:16 ` [PATCH 18/22] mini-os: map shared info page for HVMlite Juergen Gross
                   ` (4 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:16 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

The command line parameters are passed in start_info structure for pv,
but via hvm_start_info for HVMlite. Add a generic function to fill a
local cmdline variable with the command line string.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/setup.c | 20 ++++++++++++++++++--
 include/kernel.h |  3 +++
 kernel.c         |  1 +
 main.c           |  5 +++--
 4 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/arch/x86/setup.c b/arch/x86/setup.c
index 6645784..13633f0 100644
--- a/arch/x86/setup.c
+++ b/arch/x86/setup.c
@@ -31,6 +31,7 @@
 #include <mini-os/kernel.h>
 #include <xen/xen.h>
 #include <xen/arch-x86/cpuid.h>
+#include <xen/arch-x86/hvm/start_info.h>
 
 /*
  * Shared page for communicating with the hypervisor.
@@ -88,6 +89,13 @@ static inline void sse_init(void) {
 
 #ifdef CONFIG_PARAVIRT
 #define hpc_init()
+
+static void get_cmdline(void *p)
+{
+    start_info_t *si = p;
+
+    strncpy(cmdline, (char *)si->cmd_line, MAX_CMDLINE_SIZE - 1);
+}
 #else
 static void hpc_init(void)
 {
@@ -109,6 +117,14 @@ static void hpc_init(void)
     wrmsrl(ebx, (unsigned long)&hypercall_page);
     barrier();
 }
+
+static void get_cmdline(void *p)
+{
+    struct hvm_start_info *si = p;
+
+    if ( si->cmdline_paddr )
+        strncpy(cmdline, to_virt(si->cmdline_paddr), MAX_CMDLINE_SIZE - 1);
+}
 #endif
 
 /*
@@ -139,6 +155,7 @@ arch_init(void *par)
 	   shared_info. Use xprintk instead. */
 	get_console(par);
 	get_xenbus(par);
+	get_cmdline(par);
 	si = par;
 	memcpy(&start_info, si, sizeof(*si));
 
@@ -153,8 +170,7 @@ arch_init(void *par)
 	printk("   mod_start: 0x%lx(VA)\n", si->mod_start);
 	printk("     mod_len: %lu\n", si->mod_len);
 	printk("       flags: 0x%x\n", (unsigned int)si->flags);
-	printk("    cmd_line: %s\n",
-			si->cmd_line ? (const char *)si->cmd_line : "NULL");
+	printk("    cmd_line: %s\n", cmdline);
 	printk("       stack: %p-%p\n", stack, stack + sizeof(stack));
 
 	/* Grab the shared_info pointer and put it in a safe place. */
diff --git a/include/kernel.h b/include/kernel.h
index 13e3274..d37ddda 100644
--- a/include/kernel.h
+++ b/include/kernel.h
@@ -1,6 +1,9 @@
 #ifndef _KERNEL_H_
 #define _KERNEL_H_
 
+#define MAX_CMDLINE_SIZE 1024
+extern char cmdline[MAX_CMDLINE_SIZE];
+
 void start_kernel(void);
 void do_exit(void) __attribute__((noreturn));
 void arch_do_exit(void);
diff --git a/kernel.c b/kernel.c
index 437e5b4..f22997e 100644
--- a/kernel.c
+++ b/kernel.c
@@ -48,6 +48,7 @@
 #include <xen/version.h>
 
 uint8_t xen_features[XENFEAT_NR_SUBMAPS * 32];
+char cmdline[MAX_CMDLINE_SIZE];
 
 void setup_xen_features(void)
 {
diff --git a/main.c b/main.c
index 4ec40b5..71e3be3 100644
--- a/main.c
+++ b/main.c
@@ -6,6 +6,7 @@
 
 #ifdef HAVE_LIBC
 #include <os.h>
+#include <kernel.h>
 #include <sched.h>
 #include <console.h>
 #include <netfront.h>
@@ -134,7 +135,7 @@ static void call_main(void *p)
 #define PARSE_ARGS_COUNT(ARGS) PARSE_ARGS(ARGS, argc++, c++, )
 #define PARSE_ARGS_STORE(ARGS) PARSE_ARGS(ARGS, argv[argc++] = c, memmove(c, c + 1, strlen(c + 1) + 1), *c++ = 0)
 
-    PARSE_ARGS_COUNT((char*)start_info.cmd_line);
+    PARSE_ARGS_COUNT(cmdline);
 #ifdef CONFIG_QEMU_XS_ARGS
     PARSE_ARGS_COUNT(domargs);
 #endif
@@ -143,7 +144,7 @@ static void call_main(void *p)
     argv[0] = "main";
     argc = 1;
 
-    PARSE_ARGS_STORE((char*)start_info.cmd_line)
+    PARSE_ARGS_STORE(cmdline)
 #ifdef CONFIG_QEMU_XS_ARGS
     PARSE_ARGS_STORE(domargs)
 #endif
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 18/22] mini-os: map shared info page for HVMlite
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (16 preceding siblings ...)
  2016-08-23 15:16 ` [PATCH 17/22] mini-os: add get_cmdline() function Juergen Gross
@ 2016-08-23 15:16 ` Juergen Gross
  2016-08-23 22:47   ` Samuel Thibault
  2016-08-23 15:16 ` [PATCH 19/22] mini-os: remove using start_info in architecture independent code Juergen Gross
                   ` (3 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:16 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

Add a service function to map the shared info page on a
non-paravirtualized system. The code is already existing on ARM side,
just move it to hypervisor.c.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/arm/arm32.S     |  4 ++--
 arch/arm/setup.c     | 11 +----------
 arch/x86/setup.c     | 38 ++++++++++++++++++++------------------
 hypervisor.c         | 17 +++++++++++++++++
 include/hypervisor.h |  1 +
 5 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/arch/arm/arm32.S b/arch/arm/arm32.S
index a08a170..bcaca17 100644
--- a/arch/arm/arm32.S
+++ b/arch/arm/arm32.S
@@ -151,8 +151,8 @@ stage2:
 .pushsection .bss
 @ Note: calling arch_init zeroes out this region.
 .align 12
-.globl shared_info_page
-shared_info_page:
+.globl shared_info
+shared_info:
 	.fill (1024), 4, 0x0
 
 .align 3
diff --git a/arch/arm/setup.c b/arch/arm/setup.c
index 72e025a..05b405b 100644
--- a/arch/arm/setup.c
+++ b/arch/arm/setup.c
@@ -21,8 +21,6 @@ union start_info_union start_info_union;
  */
 shared_info_t *HYPERVISOR_shared_info;
 
-extern char shared_info_page[PAGE_SIZE];
-
 void *device_tree;
 
 /*
@@ -30,7 +28,6 @@ void *device_tree;
  */
 void arch_init(void *dtb_pointer, uint32_t physical_offset)
 {
-    struct xen_add_to_physmap xatp;
     int r;
 
     memset(&__bss_start, 0, &_end - &__bss_start);
@@ -48,13 +45,7 @@ void arch_init(void *dtb_pointer, uint32_t physical_offset)
     device_tree = dtb_pointer;
 
     /* Map shared_info page */
-    xatp.domid = DOMID_SELF;
-    xatp.idx = 0;
-    xatp.space = XENMAPSPACE_shared_info;
-    xatp.gpfn = virt_to_pfn(shared_info_page);
-    if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp) != 0)
-        BUG();
-    HYPERVISOR_shared_info = (struct shared_info *)shared_info_page;
+    HYPERVISOR_shared_info = map_shared_info(NULL);
 
     /* Fill in start_info */
     get_console(NULL);
diff --git a/arch/x86/setup.c b/arch/x86/setup.c
index 13633f0..278e88f 100644
--- a/arch/x86/setup.c
+++ b/arch/x86/setup.c
@@ -60,20 +60,6 @@ extern char shared_info[PAGE_SIZE];
     ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); })
 #endif
 
-static
-shared_info_t *map_shared_info(unsigned long pa)
-{
-    int rc;
-
-	if ( (rc = HYPERVISOR_update_va_mapping(
-              (unsigned long)shared_info, __pte(pa | 7), UVMF_INVLPG)) )
-	{
-		printk("Failed to map shared_info!! rc=%d\n", rc);
-		do_exit();
-	}
-	return (shared_info_t *)shared_info;
-}
-
 static inline void fpu_init(void) {
 	asm volatile("fninit");
 }
@@ -90,6 +76,21 @@ static inline void sse_init(void) {
 #ifdef CONFIG_PARAVIRT
 #define hpc_init()
 
+shared_info_t *map_shared_info(void *p)
+{
+    int rc;
+    start_info_t *si = p;
+    unsigned long pa = si->shared_info;
+
+    if ( (rc = HYPERVISOR_update_va_mapping((unsigned long)shared_info,
+                                            __pte(pa | 7), UVMF_INVLPG)) )
+    {
+        printk("Failed to map shared_info!! rc=%d\n", rc);
+        do_exit();
+    }
+    return (shared_info_t *)shared_info;
+}
+
 static void get_cmdline(void *p)
 {
     start_info_t *si = p;
@@ -156,6 +157,10 @@ arch_init(void *par)
 	get_console(par);
 	get_xenbus(par);
 	get_cmdline(par);
+
+	/* Grab the shared_info pointer and put it in a safe place. */
+	HYPERVISOR_shared_info = map_shared_info(par);
+
 	si = par;
 	memcpy(&start_info, si, sizeof(*si));
 
@@ -163,7 +168,7 @@ arch_init(void *par)
 	printk("Xen Minimal OS!\n");
 	printk("  start_info: %p(VA)\n", si);
 	printk("    nr_pages: 0x%lx\n", si->nr_pages);
-	printk("  shared_inf: 0x%08lx(MA)\n", si->shared_info);
+	printk("  shared_inf: %p(VA)\n", HYPERVISOR_shared_info);
 	printk("     pt_base: %p(VA)\n", (void *)si->pt_base);
 	printk("nr_pt_frames: 0x%lx\n", si->nr_pt_frames);
 	printk("    mfn_list: %p(VA)\n", (void *)si->mfn_list);
@@ -173,9 +178,6 @@ arch_init(void *par)
 	printk("    cmd_line: %s\n", cmdline);
 	printk("       stack: %p-%p\n", stack, stack + sizeof(stack));
 
-	/* Grab the shared_info pointer and put it in a safe place. */
-	HYPERVISOR_shared_info = map_shared_info(start_info.shared_info);
-
 	start_kernel();
 }
 
diff --git a/hypervisor.c b/hypervisor.c
index 715cfe8..1647121 100644
--- a/hypervisor.c
+++ b/hypervisor.c
@@ -29,6 +29,7 @@
 #include <mini-os/lib.h>
 #include <mini-os/hypervisor.h>
 #include <mini-os/events.h>
+#include <xen/memory.h>
 
 #define active_evtchns(cpu,sh,idx)              \
     ((sh)->evtchn_pending[idx] &                \
@@ -37,6 +38,8 @@
 int in_callback;
 
 #ifndef CONFIG_PARAVIRT
+extern shared_info_t shared_info;
+
 int hvm_get_parameter(int idx, uint64_t *value)
 {
     struct xen_hvm_param xhv;
@@ -61,6 +64,20 @@ int hvm_set_parameter(int idx, uint64_t value)
     xhv.value = value;
     return HYPERVISOR_hvm_op(HVMOP_set_param, &xhv);
 }
+
+shared_info_t *map_shared_info(void *p)
+{
+    struct xen_add_to_physmap xatp;
+
+    xatp.domid = DOMID_SELF;
+    xatp.idx = 0;
+    xatp.space = XENMAPSPACE_shared_info;
+    xatp.gpfn = virt_to_pfn(&shared_info);
+    if ( HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp) != 0 )
+        BUG();
+
+    return &shared_info;
+}
 #endif
 
 void do_hypervisor_callback(struct pt_regs *regs)
diff --git a/include/hypervisor.h b/include/hypervisor.h
index 6e421b1..7c44702 100644
--- a/include/hypervisor.h
+++ b/include/hypervisor.h
@@ -42,6 +42,7 @@ extern union start_info_union start_info_union;
 int hvm_get_parameter(int idx, uint64_t *value);
 int hvm_set_parameter(int idx, uint64_t value);
 #endif
+shared_info_t *map_shared_info(void *p);
 void force_evtchn_callback(void);
 void do_hypervisor_callback(struct pt_regs *regs);
 void mask_evtchn(uint32_t port);
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 19/22] mini-os: remove using start_info in architecture independent code
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (17 preceding siblings ...)
  2016-08-23 15:16 ` [PATCH 18/22] mini-os: map shared info page for HVMlite Juergen Gross
@ 2016-08-23 15:16 ` Juergen Gross
  2016-08-23 22:48   ` Samuel Thibault
  2016-08-23 15:16 ` [PATCH 20/22] mini-os: print start of day messages depending on domain type Juergen Gross
                   ` (2 subsequent siblings)
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:16 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

The start_info structure should be used only in case of CONFIG_PARAVIRT
defined. Remove it from being used in other places. Especially the
usage as parameter for applications linked to the kernel is no good
idea.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/arm/setup.c     |  8 --------
 arch/x86/setup.c     |  8 --------
 daytime.c            |  2 +-
 include/hypervisor.h | 11 -----------
 kernel.c             |  6 +++---
 main.c               |  6 +++---
 test.c               | 20 ++++++++++----------
 7 files changed, 17 insertions(+), 44 deletions(-)

diff --git a/arch/arm/setup.c b/arch/arm/setup.c
index 05b405b..b65023c 100644
--- a/arch/arm/setup.c
+++ b/arch/arm/setup.c
@@ -9,13 +9,6 @@
 #include <libfdt.h>
 
 /*
- * This structure contains start-of-day info, such as pagetable base pointer,
- * address of the shared_info structure, and things like that.
- * On x86, the hypervisor passes it to us. On ARM, we fill it in ourselves.
- */
-union start_info_union start_info_union;
-
-/*
  * Shared page for communicating with the hypervisor.
  * Events flags go here, for example.
  */
@@ -47,7 +40,6 @@ void arch_init(void *dtb_pointer, uint32_t physical_offset)
     /* Map shared_info page */
     HYPERVISOR_shared_info = map_shared_info(NULL);
 
-    /* Fill in start_info */
     get_console(NULL);
     get_xenbus(NULL);
 
diff --git a/arch/x86/setup.c b/arch/x86/setup.c
index 278e88f..50aa504 100644
--- a/arch/x86/setup.c
+++ b/arch/x86/setup.c
@@ -40,12 +40,6 @@
 shared_info_t *HYPERVISOR_shared_info;
 
 /*
- * This structure contains start-of-day info, such as pagetable base pointer,
- * address of the shared_info structure, and things like that.
- */
-union start_info_union start_info_union;
-
-/*
  * Just allocate the kernel stack here. SS:ESP is set up to point here
  * in head.S.
  */
@@ -151,7 +145,6 @@ arch_init(void *par)
 	/* Setup memory management info from start_info. */
 	arch_mm_preinit(par);
 
-	/* Copy the start_info struct to a globally-accessible area. */
 	/* WARN: don't do printk before here, it uses information from
 	   shared_info. Use xprintk instead. */
 	get_console(par);
@@ -162,7 +155,6 @@ arch_init(void *par)
 	HYPERVISOR_shared_info = map_shared_info(par);
 
 	si = par;
-	memcpy(&start_info, si, sizeof(*si));
 
 	/* print out some useful information  */
 	printk("Xen Minimal OS!\n");
diff --git a/daytime.c b/daytime.c
index 7dc0de0..6049e78 100644
--- a/daytime.c
+++ b/daytime.c
@@ -60,7 +60,7 @@ void run_server(void *p)
 }
 
 
-int app_main(start_info_t *si)
+int app_main(void *p)
 {
     create_thread("server", run_server, NULL);
     return 0;
diff --git a/include/hypervisor.h b/include/hypervisor.h
index 7c44702..3073a8a 100644
--- a/include/hypervisor.h
+++ b/include/hypervisor.h
@@ -26,17 +26,6 @@
 #include <xen/hvm/hvm_op.h>
 #include <mini-os/traps.h>
 
-/*
- * a placeholder for the start of day information passed up from the hypervisor
- */
-union start_info_union
-{
-    start_info_t start_info;
-    char padding[512];
-};
-extern union start_info_union start_info_union;
-#define start_info (start_info_union.start_info)
-
 /* hypervisor.c */
 #ifndef CONFIG_PARAVIRT
 int hvm_get_parameter(int idx, uint64_t *value);
diff --git a/kernel.c b/kernel.c
index f22997e..0d84a9b 100644
--- a/kernel.c
+++ b/kernel.c
@@ -110,9 +110,9 @@ static void shutdown_thread(void *p)
 
 
 /* This should be overridden by the application we are linked against. */
-__attribute__((weak)) int app_main(start_info_t *si)
+__attribute__((weak)) int app_main(void *p)
 {
-    printk("kernel.c: dummy main: start_info=%p\n", si);
+    printk("kernel.c: dummy main: par=%p\n", p);
     return 0;
 }
 
@@ -149,7 +149,7 @@ void start_kernel(void)
 #endif
 
     /* Call (possibly overridden) app_main() */
-    app_main(&start_info);
+    app_main(NULL);
 
     /* Everything initialised, start idle thread */
     run_idle_thread();
diff --git a/main.c b/main.c
index 71e3be3..263364c 100644
--- a/main.c
+++ b/main.c
@@ -185,10 +185,10 @@ void _exit(int ret)
     do_exit();
 }
 
-int app_main(start_info_t *si)
+int app_main(void *p)
 {
-    printk("main.c: dummy main: start_info=%p\n", si);
-    main_thread = create_thread("main", call_main, si);
+    printk("main.c: dummy main: par=%p\n", p);
+    main_thread = create_thread("main", call_main, p);
     return 0;
 }
 #endif
diff --git a/test.c b/test.c
index 154af49..42a2666 100644
--- a/test.c
+++ b/test.c
@@ -552,28 +552,28 @@ static void shutdown_thread(void *p)
 }
 #endif
 
-int app_main(start_info_t *si)
+int app_main(void *p)
 {
-    printk("Test main: start_info=%p\n", si);
+    printk("Test main: par=%p\n", p);
 #ifdef CONFIG_XENBUS
-    create_thread("xenbus_tester", xenbus_tester, si);
+    create_thread("xenbus_tester", xenbus_tester, p);
 #endif
-    create_thread("periodic_thread", periodic_thread, si);
+    create_thread("periodic_thread", periodic_thread, p);
 #ifdef CONFIG_NETFRONT
-    create_thread("netfront", netfront_thread, si);
+    create_thread("netfront", netfront_thread, p);
 #endif
 #ifdef CONFIG_BLKFRONT
-    create_thread("blkfront", blkfront_thread, si);
+    create_thread("blkfront", blkfront_thread, p);
 #endif
 #if defined(CONFIG_FBFRONT) && defined(CONFIG_KBDFRONT)
-    create_thread("fbfront", fbfront_thread, si);
-    create_thread("kbdfront", kbdfront_thread, si);
+    create_thread("fbfront", fbfront_thread, p);
+    create_thread("kbdfront", kbdfront_thread, p);
 #endif
 #ifdef CONFIG_PCIFRONT
-    create_thread("pcifront", pcifront_thread, si);
+    create_thread("pcifront", pcifront_thread, p);
 #endif
 #ifdef CONFIG_XENBUS
-    create_thread("shutdown", shutdown_thread, si);
+    create_thread("shutdown", shutdown_thread, p);
 #endif
     return 0;
 }
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 20/22] mini-os: print start of day messages depending on domain type
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (18 preceding siblings ...)
  2016-08-23 15:16 ` [PATCH 19/22] mini-os: remove using start_info in architecture independent code Juergen Gross
@ 2016-08-23 15:16 ` Juergen Gross
  2016-08-23 22:51   ` Samuel Thibault
  2016-08-23 15:16 ` [PATCH 21/22] mini-os: get physical memory map Juergen Gross
  2016-08-23 15:16 ` [PATCH 22/22] mini-os: support idle for HVMlite Juergen Gross
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:16 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

Select what to print in arch_init() depending on the domain type.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/setup.c | 47 ++++++++++++++++++++++++++++++++---------------
 1 file changed, 32 insertions(+), 15 deletions(-)

diff --git a/arch/x86/setup.c b/arch/x86/setup.c
index 50aa504..948b08a 100644
--- a/arch/x86/setup.c
+++ b/arch/x86/setup.c
@@ -91,6 +91,24 @@ static void get_cmdline(void *p)
 
     strncpy(cmdline, (char *)si->cmd_line, MAX_CMDLINE_SIZE - 1);
 }
+
+static void print_start_of_day(void *p)
+{
+    start_info_t *si = p;
+
+    printk("Xen Minimal OS (pv)!\n");
+    printk("  start_info: %p(VA)\n", si);
+    printk("    nr_pages: 0x%lx\n", si->nr_pages);
+    printk("  shared_inf: 0x%08lx(MA)\n", si->shared_info);
+    printk("     pt_base: %p(VA)\n", (void *)si->pt_base);
+    printk("nr_pt_frames: 0x%lx\n", si->nr_pt_frames);
+    printk("    mfn_list: %p(VA)\n", (void *)si->mfn_list);
+    printk("   mod_start: 0x%lx(VA)\n", si->mod_start);
+    printk("     mod_len: %lu\n", si->mod_len);
+    printk("       flags: 0x%x\n", (unsigned int)si->flags);
+    printk("    cmd_line: %s\n", cmdline);
+    printk("       stack: %p-%p\n", stack, stack + sizeof(stack));
+}
 #else
 static void hpc_init(void)
 {
@@ -120,6 +138,19 @@ static void get_cmdline(void *p)
     if ( si->cmdline_paddr )
         strncpy(cmdline, to_virt(si->cmdline_paddr), MAX_CMDLINE_SIZE - 1);
 }
+
+static void print_start_of_day(void *p)
+{
+    struct hvm_start_info *si = p;
+
+    printk("Xen Minimal OS (hvm)!\n");
+    printk("  start_info: %p(VA)\n", si);
+    printk("  shared_inf: %p(VA)\n", HYPERVISOR_shared_info);
+    printk("     modlist: 0x%lx(PA)\n", (unsigned long)si->modlist_paddr);
+    printk("       flags: 0x%x\n", (unsigned int)si->flags);
+    printk("    cmd_line: %s\n", cmdline);
+    printk("       stack: %p-%p\n", stack, stack + sizeof(stack));
+}
 #endif
 
 /*
@@ -129,7 +160,6 @@ void
 arch_init(void *par)
 {
 	static char hello[] = "Bootstrapping...\n";
-	start_info_t *si;
 
 	hpc_init();
 	(void)HYPERVISOR_console_io(CONSOLEIO_write, strlen(hello), hello);
@@ -154,21 +184,8 @@ arch_init(void *par)
 	/* Grab the shared_info pointer and put it in a safe place. */
 	HYPERVISOR_shared_info = map_shared_info(par);
 
-	si = par;
-
 	/* print out some useful information  */
-	printk("Xen Minimal OS!\n");
-	printk("  start_info: %p(VA)\n", si);
-	printk("    nr_pages: 0x%lx\n", si->nr_pages);
-	printk("  shared_inf: %p(VA)\n", HYPERVISOR_shared_info);
-	printk("     pt_base: %p(VA)\n", (void *)si->pt_base);
-	printk("nr_pt_frames: 0x%lx\n", si->nr_pt_frames);
-	printk("    mfn_list: %p(VA)\n", (void *)si->mfn_list);
-	printk("   mod_start: 0x%lx(VA)\n", si->mod_start);
-	printk("     mod_len: %lu\n", si->mod_len);
-	printk("       flags: 0x%x\n", (unsigned int)si->flags);
-	printk("    cmd_line: %s\n", cmdline);
-	printk("       stack: %p-%p\n", stack, stack + sizeof(stack));
+	print_start_of_day(par);
 
 	start_kernel();
 }
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 21/22] mini-os: get physical memory map
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (19 preceding siblings ...)
  2016-08-23 15:16 ` [PATCH 20/22] mini-os: print start of day messages depending on domain type Juergen Gross
@ 2016-08-23 15:16 ` Juergen Gross
  2016-08-23 22:58   ` Samuel Thibault
  2016-08-23 15:16 ` [PATCH 22/22] mini-os: support idle for HVMlite Juergen Gross
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:16 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

On HVMlite we have to look at the physical memory map to know which
memory frames are usable.

In order to make life easier we define a dummy memory map for other
domain types (pv and arm) which has just one entry with a maximum
memory size.

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/arm/mm.c         |  8 ++++++
 arch/x86/mm.c         | 72 ++++++++++++++++++++++++++++++++++++++++++++++
 arch/x86/setup.c      |  1 +
 include/e820.h        | 48 +++++++++++++++++++++++++++++++
 include/x86/arch_mm.h |  4 +++
 mm.c                  | 79 ++++++++++++++++++++++++++++++++-------------------
 6 files changed, 183 insertions(+), 29 deletions(-)
 create mode 100644 include/e820.h

diff --git a/arch/arm/mm.c b/arch/arm/mm.c
index dbde162..8c156c4 100644
--- a/arch/arm/mm.c
+++ b/arch/arm/mm.c
@@ -7,6 +7,14 @@
 #include <lib.h>
 
 uint32_t physical_address_offset;
+struct e820entry e820_map[1] = {
+    {
+        .addr = 0,
+        .size = ULONG_MAX - 1,
+        .type = E820_RAM
+    }
+};
+unsigned e820_entries = 1;
 
 unsigned long allocate_ondemand(unsigned long n, unsigned long alignment)
 {
diff --git a/arch/x86/mm.c b/arch/x86/mm.c
index 762599d..8dd90b8 100644
--- a/arch/x86/mm.c
+++ b/arch/x86/mm.c
@@ -43,6 +43,7 @@
 #include <mini-os/types.h>
 #include <mini-os/lib.h>
 #include <mini-os/xmalloc.h>
+#include <mini-os/e820.h>
 #include <xen/memory.h>
 
 #ifdef MM_DEBUG
@@ -63,6 +64,15 @@ extern char stack[];
 extern void page_walk(unsigned long va);
 
 #ifdef CONFIG_PARAVIRT
+struct e820entry e820_map[1] = {
+    {
+        .addr = 0,
+        .size = ULONG_MAX - 1,
+        .type = E820_RAM
+    }
+};
+unsigned e820_entries = 1;
+
 void arch_mm_preinit(void *p)
 {
     start_info_t *si = p;
@@ -102,10 +112,25 @@ desc_ptr idt_ptr =
     .base = (unsigned long)&idt,
 };
 
+struct e820entry e820_map[E820_MAX];
+unsigned e820_entries;
+
+static char *e820_types[E820_TYPES] = {
+    [E820_RAM]      = "RAM",
+    [E820_RESERVED] = "Reserved",
+    [E820_ACPI]     = "ACPI",
+    [E820_NVS]      = "NVS",
+    [E820_UNUSABLE] = "Unusable",
+    [E820_PMEM]     = "PMEM"
+};
+
 void arch_mm_preinit(void *p)
 {
     long ret;
     domid_t domid = DOMID_SELF;
+    struct xen_memory_map memmap;
+    int i;
+    unsigned long pfn, max = 0;
 
     pt_base = page_table_base;
     first_free_pfn = PFN_UP(to_phys(&_end));
@@ -116,6 +141,53 @@ void arch_mm_preinit(void *p)
         do_exit();
     }
     last_free_pfn = ret;
+
+    memmap.nr_entries = E820_MAX;
+    set_xen_guest_handle(memmap.buffer, e820_map);
+    ret = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap);
+    if ( ret < 0 )
+    {
+        xprintk("could not get memory map\n");
+        do_exit();
+    }
+    e820_entries = memmap.nr_entries;
+
+    for ( i = 0; i < e820_entries; i++ )
+    {
+        if ( e820_map[i].type != E820_RAM )
+            continue;
+        pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT;
+        if ( pfn > max )
+            max = pfn;
+    }
+
+    if ( max < last_free_pfn )
+        last_free_pfn = max;
+}
+
+void arch_print_memmap(void)
+{
+    int i;
+    unsigned long from, to;
+    char *type;
+    char buf[12];
+
+    printk("Memory map:\n");
+    for ( i = 0; i < e820_entries; i++ )
+    {
+        if ( e820_map[i].type >= E820_TYPES || !e820_types[e820_map[i].type] )
+        {
+            snprintf(buf, sizeof(buf), "%8x", e820_map[i].type);
+            type = buf;
+        }
+        else
+        {
+            type = e820_types[e820_map[i].type];
+        }
+        from = e820_map[i].addr;
+        to = from + e820_map[i].size - 1;
+        printk("%012lx-%012lx: %s\n", from, to, type);
+    }
 }
 #endif
 
diff --git a/arch/x86/setup.c b/arch/x86/setup.c
index 948b08a..829b03c 100644
--- a/arch/x86/setup.c
+++ b/arch/x86/setup.c
@@ -150,6 +150,7 @@ static void print_start_of_day(void *p)
     printk("       flags: 0x%x\n", (unsigned int)si->flags);
     printk("    cmd_line: %s\n", cmdline);
     printk("       stack: %p-%p\n", stack, stack + sizeof(stack));
+    arch_print_memmap();
 }
 #endif
 
diff --git a/include/e820.h b/include/e820.h
new file mode 100644
index 0000000..920551c
--- /dev/null
+++ b/include/e820.h
@@ -0,0 +1,48 @@
+/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
+ *
+ * (C) 2016 - Juergen Gross, SUSE Linux GmbH
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef __E820_HEADER
+#define __E820_HEADER
+
+/* PC BIOS standard E820 types and structure. */
+#define E820_RAM          1
+#define E820_RESERVED     2
+#define E820_ACPI         3
+#define E820_NVS          4
+#define E820_UNUSABLE     5
+#define E820_PMEM         7
+#define E820_TYPES        8
+
+struct __packed e820entry {
+    uint64_t addr;
+    uint64_t size;
+    uint32_t type;
+};
+
+/* Maximum number of entries. */
+#define E820_MAX          128
+
+extern struct e820entry e820_map[];
+extern unsigned e820_entries;
+
+#endif /*__E820_HEADER*/
diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h
index 9372f1e..ab8a53e 100644
--- a/include/x86/arch_mm.h
+++ b/include/x86/arch_mm.h
@@ -279,6 +279,10 @@ pgentry_t *need_pgt(unsigned long addr);
 void arch_mm_preinit(void *p);
 unsigned long alloc_virt_kernel(unsigned n_pages);
 
+#ifndef CONFIG_PARAVIRT
+void arch_print_memmap(void);
+#endif
+
 #endif
 
 #endif /* _ARCH_MM_H_ */
diff --git a/mm.c b/mm.c
index c76be7f..932ceeb 100644
--- a/mm.c
+++ b/mm.c
@@ -43,6 +43,7 @@
 #include <mini-os/types.h>
 #include <mini-os/lib.h>
 #include <mini-os/xmalloc.h>
+#include <mini-os/e820.h>
 
 /*********************
  * ALLOCATION BITMAP
@@ -147,10 +148,14 @@ static chunk_head_t  free_tail[FREELIST_SIZE];
  */
 static void init_page_allocator(unsigned long min, unsigned long max)
 {
-    int i;
+    int i, m;
     unsigned long range;
+    unsigned long r_min, r_max;
     chunk_head_t *ch;
     chunk_tail_t *ct;
+
+    printk("MM: Initialise page allocator for %lx(%lx)-%lx(%lx)\n",
+           (u_long)to_virt(min), min, (u_long)to_virt(max), max);
     for ( i = 0; i < FREELIST_SIZE; i++ )
     {
         free_head[i]       = &free_tail[i];
@@ -166,38 +171,57 @@ static void init_page_allocator(unsigned long min, unsigned long max)
     mm_alloc_bitmap_size  = round_pgup(mm_alloc_bitmap_size);
     mm_alloc_bitmap = (unsigned long *)to_virt(min);
     min         += mm_alloc_bitmap_size;
-    range        = max - min;
 
     /* All allocated by default. */
     memset(mm_alloc_bitmap, ~0, mm_alloc_bitmap_size);
-    /* Free up the memory we've been given to play with. */
-    map_free(PHYS_PFN(min), range>>PAGE_SHIFT);
 
-    /* The buddy lists are addressed in high memory. */
-    min = (unsigned long) to_virt(min);
-    max = (unsigned long) to_virt(max);
-
-    while ( range != 0 )
+    for ( m = 0; m < e820_entries; m++ )
     {
-        /*
-         * Next chunk is limited by alignment of min, but also
-         * must not be bigger than remaining range.
-         */
-        for ( i = PAGE_SHIFT; (1UL<<(i+1)) <= range; i++ )
-            if ( min & (1UL<<i) ) break;
+        if ( e820_map[m].type != E820_RAM )
+            continue;
+        if ( e820_map[m].addr + e820_map[m].size >= ULONG_MAX )
+            BUG();
 
+        r_min = e820_map[m].addr;
+        r_max = r_min + e820_map[m].size;
+        if ( r_max <= min || r_min >= max )
+            continue;
+        if ( r_min < min )
+            r_min = min;
+        if ( r_max > max )
+            r_max = max;
 
-        ch = (chunk_head_t *)min;
-        min   += (1UL<<i);
-        range -= (1UL<<i);
-        ct = (chunk_tail_t *)min-1;
-        i -= PAGE_SHIFT;
-        ch->level       = i;
-        ch->next        = free_head[i];
-        ch->pprev       = &free_head[i];
-        ch->next->pprev = &ch->next;
-        free_head[i]    = ch;
-        ct->level       = i;
+        printk("    Adding memory range %lx-%lx\n", r_min, r_max);
+
+        /* The buddy lists are addressed in high memory. */
+        r_min = (unsigned long)to_virt(r_min);
+        r_max = (unsigned long)to_virt(r_max);
+        range = r_max - r_min;
+
+        /* Free up the memory we've been given to play with. */
+        map_free(PHYS_PFN(r_min), range >> PAGE_SHIFT);
+
+        while ( range != 0 )
+        {
+            /*
+             * Next chunk is limited by alignment of min, but also
+             * must not be bigger than remaining range.
+             */
+            for ( i = PAGE_SHIFT; (1UL << (i + 1)) <= range; i++ )
+                if ( r_min & (1UL << i) ) break;
+
+            ch = (chunk_head_t *)r_min;
+            r_min += 1UL << i;
+            range -= 1UL << i;
+            ct = (chunk_tail_t *)r_min - 1;
+            i -= PAGE_SHIFT;
+            ch->level       = i;
+            ch->next        = free_head[i];
+            ch->pprev       = &free_head[i];
+            ch->next->pprev = &ch->next;
+            free_head[i]    = ch;
+            ct->level       = i;
+        }
     }
 
     mm_alloc_bitmap_remap();
@@ -377,9 +401,6 @@ void init_mm(void)
     /*
      * now we can initialise the page allocator
      */
-    printk("MM: Initialise page allocator for %lx(%lx)-%lx(%lx)\n",
-           (u_long)to_virt(PFN_PHYS(start_pfn)), (u_long)PFN_PHYS(start_pfn),
-           (u_long)to_virt(PFN_PHYS(max_pfn)), (u_long)PFN_PHYS(max_pfn));
     init_page_allocator(PFN_PHYS(start_pfn), PFN_PHYS(max_pfn));
     printk("MM: done\n");
 
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* [PATCH 22/22] mini-os: support idle for HVMlite
  2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
                   ` (20 preceding siblings ...)
  2016-08-23 15:16 ` [PATCH 21/22] mini-os: get physical memory map Juergen Gross
@ 2016-08-23 15:16 ` Juergen Gross
  2016-08-23 23:01   ` Samuel Thibault
  21 siblings, 1 reply; 48+ messages in thread
From: Juergen Gross @ 2016-08-23 15:16 UTC (permalink / raw)
  To: minios-devel, xen-devel; +Cc: Juergen Gross, samuel.thibault, wei.liu2

Instead of calling HYPERVISOR_sched_op(SCHEDOP_block, 0) we need to use
the "hlt" instruction with interrupts enabled to switch to idle when
running as HVMlite domain.

This requires to setup a new timer in the timer handler as there is no
guarantee the original timer event we are waiting for won't fire
between enabling interrupts and calling "hlt".

Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/time.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/arch/x86/time.c b/arch/x86/time.c
index af45e56..3658142 100644
--- a/arch/x86/time.c
+++ b/arch/x86/time.c
@@ -212,17 +212,20 @@ void block_domain(s_time_t until)
     if(monotonic_clock() < until)
     {
         HYPERVISOR_set_timer_op(until);
+#ifdef CONFIG_PARAVIRT
         HYPERVISOR_sched_op(SCHEDOP_block, 0);
+#else
+        local_irq_enable();
+        asm volatile ( "hlt" : : : "memory" );
+#endif
         local_irq_disable();
+        HYPERVISOR_set_timer_op(0);
     }
 }
 
-
-/*
- * Just a dummy
- */
 static void timer_handler(evtchn_port_t ev, struct pt_regs *regs, void *ign)
 {
+    HYPERVISOR_set_timer_op(monotonic_clock() + MILLISECS(1));
 }
 
 
-- 
2.6.6


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 48+ messages in thread

* Re: [PATCH 01/22] mini-os: resync xen headers
  2016-08-23 15:15 ` [PATCH 01/22] mini-os: resync xen headers Juergen Gross
@ 2016-08-23 19:44   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 19:44 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:15:47 +0200, wrote:
> Use the latest Xen headers.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  include/xen/arch-x86/hvm/start_info.h | 98 +++++++++++++++++++++++++++++++++++
>  include/xen/elfnote.h                 | 12 ++++-
>  2 files changed, 109 insertions(+), 1 deletion(-)
>  create mode 100644 include/xen/arch-x86/hvm/start_info.h
> 
> diff --git a/include/xen/arch-x86/hvm/start_info.h b/include/xen/arch-x86/hvm/start_info.h
> new file mode 100644
> index 0000000..6484159
> --- /dev/null
> +++ b/include/xen/arch-x86/hvm/start_info.h
> @@ -0,0 +1,98 @@
> +/*
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to
> + * deal in the Software without restriction, including without limitation the
> + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
> + * sell copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> + * DEALINGS IN THE SOFTWARE.
> + *
> + * Copyright (c) 2016, Citrix Systems, Inc.
> + */
> +
> +#ifndef __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__
> +#define __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__
> +
> +/*
> + * Start of day structure passed to PVH guests and to HVM guests in %ebx.
> + *
> + * NOTE: nothing will be loaded at physical address 0, so a 0 value in any
> + * of the address fields should be treated as not present.
> + *
> + *  0 +----------------+
> + *    | magic          | Contains the magic value XEN_HVM_START_MAGIC_VALUE
> + *    |                | ("xEn3" with the 0x80 bit of the "E" set).
> + *  4 +----------------+
> + *    | version        | Version of this structure. Current version is 0. New
> + *    |                | versions are guaranteed to be backwards-compatible.
> + *  8 +----------------+
> + *    | flags          | SIF_xxx flags.
> + * 12 +----------------+
> + *    | nr_modules     | Number of modules passed to the kernel.
> + * 16 +----------------+
> + *    | modlist_paddr  | Physical address of an array of modules
> + *    |                | (layout of the structure below).
> + * 24 +----------------+
> + *    | cmdline_paddr  | Physical address of the command line,
> + *    |                | a zero-terminated ASCII string.
> + * 32 +----------------+
> + *    | rsdp_paddr     | Physical address of the RSDP ACPI data structure.
> + * 40 +----------------+
> + *
> + * The layout of each entry in the module structure is the following:
> + *
> + *  0 +----------------+
> + *    | paddr          | Physical address of the module.
> + *  8 +----------------+
> + *    | size           | Size of the module in bytes.
> + * 16 +----------------+
> + *    | cmdline_paddr  | Physical address of the command line,
> + *    |                | a zero-terminated ASCII string.
> + * 24 +----------------+
> + *    | reserved       |
> + * 32 +----------------+
> + *
> + * The address and sizes are always a 64bit little endian unsigned integer.
> + *
> + * NB: Xen on x86 will always try to place all the data below the 4GiB
> + * boundary.
> + */
> +#define XEN_HVM_START_MAGIC_VALUE 0x336ec578
> +
> +/*
> + * C representation of the x86/HVM start info layout.
> + *
> + * The canonical definition of this layout is above, this is just a way to
> + * represent the layout described there using C types.
> + */
> +struct hvm_start_info {
> +    uint32_t magic;             /* Contains the magic value 0x336ec578       */
> +                                /* ("xEn3" with the 0x80 bit of the "E" set).*/
> +    uint32_t version;           /* Version of this structure.                */
> +    uint32_t flags;             /* SIF_xxx flags.                            */
> +    uint32_t nr_modules;        /* Number of modules passed to the kernel.   */
> +    uint64_t modlist_paddr;     /* Physical address of an array of           */
> +                                /* hvm_modlist_entry.                        */
> +    uint64_t cmdline_paddr;     /* Physical address of the command line.     */
> +    uint64_t rsdp_paddr;        /* Physical address of the RSDP ACPI data    */
> +                                /* structure.                                */
> +};
> +
> +struct hvm_modlist_entry {
> +    uint64_t paddr;             /* Physical address of the module.           */
> +    uint64_t size;              /* Size of the module in bytes.              */
> +    uint64_t cmdline_paddr;     /* Physical address of the command line.     */
> +    uint64_t reserved;
> +};
> +
> +#endif /* __XEN_PUBLIC_ARCH_X86_HVM_START_INFO_H__ */
> diff --git a/include/xen/elfnote.h b/include/xen/elfnote.h
> index 3824a94..353985f 100644
> --- a/include/xen/elfnote.h
> +++ b/include/xen/elfnote.h
> @@ -200,9 +200,19 @@
>  #define XEN_ELFNOTE_SUPPORTED_FEATURES 17
>  
>  /*
> + * Physical entry point into the kernel.
> + *
> + * 32bit entry point into the kernel. When requested to launch the
> + * guest kernel in a HVM container, Xen will use this entry point to
> + * launch the guest in 32bit protected mode with paging disabled.
> + * Ignored otherwise.
> + */
> +#define XEN_ELFNOTE_PHYS32_ENTRY 18
> +
> +/*
>   * The number of the highest elfnote defined.
>   */
> -#define XEN_ELFNOTE_MAX XEN_ELFNOTE_SUPPORTED_FEATURES
> +#define XEN_ELFNOTE_MAX XEN_ELFNOTE_PHYS32_ENTRY
>  
>  /*
>   * System information exported through crash notes.
> -- 
> 2.6.6
> 

-- 
Samuel
> [Linux] c'est une philosophie un art de vivre, un état intérieur,
> une sorte de fluide qui nous entoure et nous pénètre.
Fais tourner stp !
-+- Guillaume in Guide du linuxien pervers - "Tous drogués j'vous dis !"

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 02/22] mini-os: make dump_regs() work in early boot
  2016-08-23 15:15 ` [PATCH 02/22] mini-os: make dump_regs() work in early boot Juergen Gross
@ 2016-08-23 19:44   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 19:44 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:15:48 +0200, wrote:
> dump_regs() will result in page fault in early boot as there is no
> current thread pointer. Handle this case.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/x86/traps.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/traps.c b/arch/x86/traps.c
> index 6353718..307a14c 100644
> --- a/arch/x86/traps.c
> +++ b/arch/x86/traps.c
> @@ -32,7 +32,7 @@ void machine_check(void);
>  
>  void dump_regs(struct pt_regs *regs)
>  {
> -    printk("Thread: %s\n", current->name);
> +    printk("Thread: %s\n", current ? current->name : "*NONE*");
>  #ifdef __i386__    
>      printk("EIP: %lx, EFLAGS %lx.\n", regs->eip, regs->eflags);
>      printk("EBX: %08lx ECX: %08lx EDX: %08lx\n",
> -- 
> 2.6.6
> 

-- 
Samuel
 > Subject: pb fvwm95-2 comment l'installer le compiler???
 > Merci d'avance
 je te conseille d'être un peu plus précis dans l'exposé de ton pb...
 -+- EJ in guide du linuxien pervers :"Les modéros sont sympas !" -+-

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 04/22] mini-os: make some memory management related macros usable from assembler
  2016-08-23 15:15 ` [PATCH 04/22] mini-os: make some memory management related macros usable from assembler Juergen Gross
@ 2016-08-23 19:46   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 19:46 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:15:50 +0200, wrote:
> Especially page table entry definitions are currently not usable from
> assembler sources on x86 as the constants are defined with ULL suffix.
> Change this by adding the suffix only when the header is included from
> a C source.
> 
> Hide some C prototypes when in assembler environment.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  include/x86/arch_mm.h | 56 +++++++++++++++++++++++++++++++--------------------
>  1 file changed, 34 insertions(+), 22 deletions(-)
> 
> diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h
> index 690a919..2b18b34 100644
> --- a/include/x86/arch_mm.h
> +++ b/include/x86/arch_mm.h
> @@ -29,11 +29,16 @@
>  #include <xen/xen.h>
>  #if defined(__i386__)
>  #include <xen/arch-x86_32.h>
> +#define __CONST(x) x ## ULL
>  #elif defined(__x86_64__)
>  #include <xen/arch-x86_64.h>
> +#define __CONST(x) x ## UL
>  #else
>  #error "Unsupported architecture"
>  #endif
> +#define CONST(x) __CONST(x)
> +#else
> +#define CONST(x) x
>  #endif
>  
>  /*
> @@ -81,14 +86,16 @@
>  #define PRIpte "016llx"
>  #ifndef __ASSEMBLY__
>  typedef uint64_t pgentry_t;
> +#else
> +#define PTE(val) .long val; .long 0
>  #endif
>  
> -#define MAX_MEM_SIZE            0x3f000000UL
> -#define VIRT_KERNEL_AREA        0x3f000000UL
> -#define VIRT_DEMAND_AREA        0x40000000UL
> -#define VIRT_HEAP_AREA          0xb0000000UL
> +#define MAX_MEM_SIZE            CONST(0x3f000000)
> +#define VIRT_KERNEL_AREA        CONST(0x3f000000)
> +#define VIRT_DEMAND_AREA        CONST(0x40000000)
> +#define VIRT_HEAP_AREA          CONST(0xb0000000)
>  
> -#define DEMAND_MAP_PAGES        0x6ffffUL
> +#define DEMAND_MAP_PAGES        CONST(0x6ffff)
>  #define HEAP_PAGES_MAX          ((HYPERVISOR_VIRT_START - VIRT_HEAP_AREA) / \
>                                   PAGE_SIZE - 1)
>  
> @@ -115,15 +122,17 @@ typedef uint64_t pgentry_t;
>  #define PRIpte "016lx"
>  #ifndef __ASSEMBLY__
>  typedef unsigned long pgentry_t;
> +#else
> +#define PTE(val) .quad val
>  #endif
>  
> -#define MAX_MEM_SIZE            (512ULL << 30)
> -#define VIRT_KERNEL_AREA        0x0000008000000000UL
> -#define VIRT_DEMAND_AREA        0x0000100000000000UL
> -#define VIRT_HEAP_AREA          0x0000200000000000UL
> +#define MAX_MEM_SIZE            (CONST(512) << 30)
> +#define VIRT_KERNEL_AREA        CONST(0x0000008000000000)
> +#define VIRT_DEMAND_AREA        CONST(0x0000100000000000)
> +#define VIRT_HEAP_AREA          CONST(0x0000200000000000)
>  
> -#define DEMAND_MAP_PAGES        0x8000000UL
> -#define HEAP_PAGES_MAX          0x8000000UL
> +#define DEMAND_MAP_PAGES        CONST(0x8000000)
> +#define HEAP_PAGES_MAX          CONST(0x8000000)
>  
>  #endif
>  
> @@ -147,16 +156,16 @@ typedef unsigned long pgentry_t;
>    (((_a) >> L4_PAGETABLE_SHIFT) & (L4_PAGETABLE_ENTRIES - 1))
>  #endif
>  
> -#define _PAGE_PRESENT  0x001ULL
> -#define _PAGE_RW       0x002ULL
> -#define _PAGE_USER     0x004ULL
> -#define _PAGE_PWT      0x008ULL
> -#define _PAGE_PCD      0x010ULL
> -#define _PAGE_ACCESSED 0x020ULL
> -#define _PAGE_DIRTY    0x040ULL
> -#define _PAGE_PAT      0x080ULL
> -#define _PAGE_PSE      0x080ULL
> -#define _PAGE_GLOBAL   0x100ULL
> +#define _PAGE_PRESENT  CONST(0x001)
> +#define _PAGE_RW       CONST(0x002)
> +#define _PAGE_USER     CONST(0x004)
> +#define _PAGE_PWT      CONST(0x008)
> +#define _PAGE_PCD      CONST(0x010)
> +#define _PAGE_ACCESSED CONST(0x020)
> +#define _PAGE_DIRTY    CONST(0x040)
> +#define _PAGE_PAT      CONST(0x080)
> +#define _PAGE_PSE      CONST(0x080)
> +#define _PAGE_GLOBAL   CONST(0x100)
>  
>  #if defined(__i386__)
>  #define L1_PROT (_PAGE_PRESENT|_PAGE_RW|_PAGE_ACCESSED)
> @@ -191,12 +200,14 @@ typedef unsigned long pgentry_t;
>  #define L3_P2M_IDX(pfn) (((pfn) >> L2_P2M_SHIFT) & P2M_MASK)
>  #define INVALID_P2M_ENTRY (~0UL)
>  
> +#ifndef __ASSEMBLY__
>  void p2m_chk_pfn(unsigned long pfn);
>  
>  static inline unsigned long p2m_pages(unsigned long pages)
>  {
>      return (pages + P2M_ENTRIES - 1) >> L1_P2M_SHIFT;
>  }
> +#endif
>  
>  #include "arch_limits.h"
>  #define PAGE_SIZE       __PAGE_SIZE
> @@ -239,7 +250,6 @@ static __inline__ paddr_t machine_to_phys(maddr_t machine)
>  	phys = (phys << PAGE_SHIFT) | (machine & ~PAGE_MASK);
>  	return phys;
>  }
> -#endif
>  
>  #define VIRT_START                 ((unsigned long)&_text)
>  
> @@ -288,4 +298,6 @@ static __inline__ paddr_t machine_to_phys(maddr_t machine)
>  
>  pgentry_t *need_pgt(unsigned long addr);
>  
> +#endif
> +
>  #endif /* _ARCH_MM_H_ */
> -- 
> 2.6.6
> 

-- 
Samuel
I am the "ILOVEGNU" signature virus. Just copy me to your signature.
This email was infected under the terms of the GNU General Public License.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 13/22] mini-os: correct wrong calculation of alloc bitmap size
  2016-08-23 15:15 ` [PATCH 13/22] mini-os: correct wrong calculation of alloc bitmap size Juergen Gross
@ 2016-08-23 19:49   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 19:49 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:15:59 +0200, wrote:
> When remapping the page allocator's bitmap for the ballooning support
> the calculation of the needed size is wrong. This doesn't really
> matter today as nothing is allocated after that bitmap, but it should
> be corrected nevertheless.

Oops, indeed!

> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  balloon.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/balloon.c b/balloon.c
> index 8d2f151..8669edb 100644
> --- a/balloon.c
> +++ b/balloon.c
> @@ -52,7 +52,7 @@ void mm_alloc_bitmap_remap(void)
>  {
>      unsigned long i;
>  
> -    if ( mm_alloc_bitmap_size >= ((nr_max_pages + 1) >> (PAGE_SHIFT + 3)) )
> +    if ( mm_alloc_bitmap_size >= ((nr_max_pages + 1) >> 3) )
>          return;
>  
>      for ( i = 0; i < mm_alloc_bitmap_size; i += PAGE_SIZE )
> @@ -62,7 +62,7 @@ void mm_alloc_bitmap_remap(void)
>      }
>  
>      mm_alloc_bitmap = (unsigned long *)virt_kernel_area_end;
> -    virt_kernel_area_end += round_pgup((nr_max_pages + 1) >> (PAGE_SHIFT + 3));
> +    virt_kernel_area_end += round_pgup((nr_max_pages + 1) >> 3);
>      ASSERT(virt_kernel_area_end <= VIRT_DEMAND_AREA);
>  }
>  
> -- 
> 2.6.6
> 

-- 
Samuel
/*
 * [...] Note that 120 sec is defined in the protocol as the maximum
 * possible RTT.  I guess we'll have to use something other than TCP
 * to talk to the University of Mars.
 * PAWS allows us longer timeouts and large windows, so once implemented
 * ftp to mars will work nicely.
 */
(from /usr/src/linux/net/inet/tcp.c, concerning RTT [retransmission timeout])

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 03/22] mini-os: add CONFIG_PARAVIRT
  2016-08-23 15:15 ` [PATCH 03/22] mini-os: add CONFIG_PARAVIRT Juergen Gross
@ 2016-08-23 19:54   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 19:54 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:15:49 +0200, wrote:
> Add a new config macro CONFIG_PARAVIRT which defaults to be defined on
> x86. This is the first step for supporting a HVMlite Mini-OS.
> 
> Doing this via CONFIG_PARAVIRT instead of something like CONFIG_HVMLITE
> was chosen as the arm port can then drop some dummy routines needed for
> para-virtualization only.
> 
> Add include/paravirt.h for furute support of paravirt specific
> handling.

future*

> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  Config.mk          |  6 ++++++
>  include/paravirt.h | 33 +++++++++++++++++++++++++++++++++
>  2 files changed, 39 insertions(+)
>  create mode 100644 include/paravirt.h
> 
> diff --git a/Config.mk b/Config.mk
> index 8ab1a7e..aa36761 100644
> --- a/Config.mk
> +++ b/Config.mk
> @@ -153,6 +153,11 @@ LDFLAGS-$(clang) += -plugin LLVMgold.so
>  endif
>  
>  # Configuration defaults
> +ifeq ($(TARGET_ARCH_FAM),x86)
> +CONFIG_PARAVIRT ?= y
> +else
> +CONFIG_PARAVIRT ?= n
> +endif
>  CONFIG_START_NETWORK ?= y
>  CONFIG_SPARSE_BSS ?= y
>  CONFIG_QEMU_XS_ARGS ?= n
> @@ -172,6 +177,7 @@ CONFIG_LWIP ?= $(lwip)
>  CONFIG_BALLOON ?= n
>  
>  # Export config items as compiler directives
> +DEFINES-$(CONFIG_PARAVIRT) += -DCONFIG_PARAVIRT
>  DEFINES-$(CONFIG_START_NETWORK) += -DCONFIG_START_NETWORK
>  DEFINES-$(CONFIG_SPARSE_BSS) += -DCONFIG_SPARSE_BSS
>  DEFINES-$(CONFIG_QEMU_XS_ARGS) += -DCONFIG_QEMU_XS_ARGS
> diff --git a/include/paravirt.h b/include/paravirt.h
> new file mode 100644
> index 0000000..7852e16
> --- /dev/null
> +++ b/include/paravirt.h
> @@ -0,0 +1,33 @@
> +/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
> + *
> + * (C) 2016 - Juergen Gross, SUSE Linux GmbH
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to
> + * deal in the Software without restriction, including without limitation the
> + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
> + * sell copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> + * DEALINGS IN THE SOFTWARE.
> + */
> +
> +#ifndef _PARAVIRT_H
> +#define _PARAVIRT_H
> +
> +#if defined(CONFIG_PARAVIRT)
> +
> +#else
> +
> +#endif
> +
> +#endif /* _PARAVIRT_H */
> -- 
> 2.6.6
> 

-- 
Samuel
Pour un père, autant mourir que de faire plein de calculs et pas s'occuper
de son fils
 -+- y sur #ens-mim - sombres histoires de zombies -+-

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 05/22] mini-os: add boot code for HVMlite support
  2016-08-23 15:15 ` [PATCH 05/22] mini-os: add boot code for HVMlite support Juergen Gross
@ 2016-08-23 20:51   ` Samuel Thibault
  2016-08-24  5:13     ` Juergen Gross
  0 siblings, 1 reply; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 20:51 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Hello,

It looks good, there is just:

Juergen Gross, on Tue 23 Aug 2016 17:15:51 +0200, wrote:
> +        .macro PTES prot, addr, incr, idx, end

Please document what prot, addr, incr, idx, end represent precisely.

> +        .ifgt \end-\idx-32
> +        PTES \prot, \addr, \incr, \idx, "(\idx+32)"
> +        PTES \prot, "(\addr+32*\incr)", \incr, "(\idx+32)", \end
> +        .else
> +        PTE(\addr + \prot)
> +        .if \end-\idx-1
> +        PTES \prot, "(\addr+\incr)", \incr, "(\idx+1)", \end
> +        .endif
> +        .endif
> +        .endm

> diff --git a/include/x86/desc.h b/include/x86/desc.h
> new file mode 100644
> index 0000000..d450557
> --- /dev/null
> +++ b/include/x86/desc.h
> @@ -0,0 +1,366 @@
> +/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
> + *
> + * (C) 2016 - Juergen Gross, SUSE Linux GmbH

Was this whole file imported from somewhere, or written from scratch?

Samuel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 06/22] mini-os: setup hypercall page for HVMlite
  2016-08-23 15:15 ` [PATCH 06/22] mini-os: setup hypercall page for HVMlite Juergen Gross
@ 2016-08-23 21:03   ` Samuel Thibault
  2016-08-24  5:10     ` Juergen Gross
  0 siblings, 1 reply; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 21:03 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

hello,

Juergen Gross, on Tue 23 Aug 2016 17:15:52 +0200, wrote:
> When running in HVMlite mode we need to setup the hypercall page by
> ourself.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
>  
> +#else /* ifdef __x86_64__ */
> +#error "Unsupported architecture"
> +#endif
> +
>  #define wrmsr(msr,val1,val2) \
>        __asm__ __volatile__("wrmsr" \
>                             : /* no outputs */ \
>                             : "c" (msr), "a" (val1), "d" (val2))
>  
> -#define wrmsrl(msr,val) wrmsr(msr,(uint32_t)((uint64_t)(val)),((uint64_t)(val))>>32)
> +static inline void wrmsrl(unsigned msr, uint64_t val)
> +{
> +    wrmsr(msr, (uint32_t)(val & 0xffffffffULL), (uint32_t)(val >> 32));
> +}
>  
> -
> -#else /* ifdef __x86_64__ */
> -#error "Unsupported architecture"
> -#endif
>  #endif /* ifdef __INSIDE_MINIOS */

Then please move it after

>  /********************* common i386 and x86_64  ****************************/

This line :)

Apart from that, 

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

Samuel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 07/22] mini-os: support hvm_op hypercall
  2016-08-23 15:15 ` [PATCH 07/22] mini-os: support hvm_op hypercall Juergen Gross
@ 2016-08-23 22:00   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 22:00 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:15:53 +0200, wrote:
> Support the HYPERVISOR_hvm_op() hypercall which is needed for HVMlite.
> Add convenience functions hvm_get_parameter() and hvm_set_parameter().
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/arm/setup.c                      | 15 ---------------
>  hypervisor.c                          | 27 +++++++++++++++++++++++++++
>  include/hypervisor.h                  |  5 +++++
>  include/x86/x86_32/hypercall-x86_32.h |  6 ++++++
>  include/x86/x86_64/hypercall-x86_64.h |  6 ++++++
>  5 files changed, 44 insertions(+), 15 deletions(-)
> 
> diff --git a/arch/arm/setup.c b/arch/arm/setup.c
> index 06afe46..cbe67c6 100644
> --- a/arch/arm/setup.c
> +++ b/arch/arm/setup.c
> @@ -25,21 +25,6 @@ extern char shared_info_page[PAGE_SIZE];
>  
>  void *device_tree;
>  
> -static int hvm_get_parameter(int idx, uint64_t *value)
> -{
> -    struct xen_hvm_param xhv;
> -    int ret;
> -
> -    xhv.domid = DOMID_SELF;
> -    xhv.index = idx;
> -    ret = HYPERVISOR_hvm_op(HVMOP_get_param, &xhv);
> -    if (ret < 0) {
> -        BUG();
> -    }
> -    *value = xhv.value;
> -    return ret;
> -}
> -
>  static void get_console(void)
>  {
>      uint64_t v = -1;
> diff --git a/hypervisor.c b/hypervisor.c
> index 1b61d9b..715cfe8 100644
> --- a/hypervisor.c
> +++ b/hypervisor.c
> @@ -36,6 +36,33 @@
>  
>  int in_callback;
>  
> +#ifndef CONFIG_PARAVIRT
> +int hvm_get_parameter(int idx, uint64_t *value)
> +{
> +    struct xen_hvm_param xhv;
> +    int ret;
> +
> +    xhv.domid = DOMID_SELF;
> +    xhv.index = idx;
> +    ret = HYPERVISOR_hvm_op(HVMOP_get_param, &xhv);
> +    if ( ret < 0 )
> +        BUG();
> +
> +    *value = xhv.value;
> +    return ret;
> +}
> +
> +int hvm_set_parameter(int idx, uint64_t value)
> +{
> +    struct xen_hvm_param xhv;
> +
> +    xhv.domid = DOMID_SELF;
> +    xhv.index = idx;
> +    xhv.value = value;
> +    return HYPERVISOR_hvm_op(HVMOP_set_param, &xhv);
> +}
> +#endif
> +
>  void do_hypervisor_callback(struct pt_regs *regs)
>  {
>      unsigned long  l1, l2, l1i, l2i;
> diff --git a/include/hypervisor.h b/include/hypervisor.h
> index 21b3566..6e421b1 100644
> --- a/include/hypervisor.h
> +++ b/include/hypervisor.h
> @@ -23,6 +23,7 @@
>  #else
>  #error "Unsupported architecture"
>  #endif
> +#include <xen/hvm/hvm_op.h>
>  #include <mini-os/traps.h>
>  
>  /*
> @@ -37,6 +38,10 @@ extern union start_info_union start_info_union;
>  #define start_info (start_info_union.start_info)
>  
>  /* hypervisor.c */
> +#ifndef CONFIG_PARAVIRT
> +int hvm_get_parameter(int idx, uint64_t *value);
> +int hvm_set_parameter(int idx, uint64_t value);
> +#endif
>  void force_evtchn_callback(void);
>  void do_hypervisor_callback(struct pt_regs *regs);
>  void mask_evtchn(uint32_t port);
> diff --git a/include/x86/x86_32/hypercall-x86_32.h b/include/x86/x86_32/hypercall-x86_32.h
> index 99a4ee3..5c93464 100644
> --- a/include/x86/x86_32/hypercall-x86_32.h
> +++ b/include/x86/x86_32/hypercall-x86_32.h
> @@ -324,6 +324,12 @@ HYPERVISOR_domctl(
>  	return _hypercall1(int, domctl, op);
>  }
>  
> +static inline unsigned long
> +HYPERVISOR_hvm_op(int op, void *arg)
> +{
> +	return _hypercall2(unsigned long, hvm_op, op, arg);
> +}
> +
>  #endif /* __HYPERCALL_X86_32_H__ */
>  
>  /*
> diff --git a/include/x86/x86_64/hypercall-x86_64.h b/include/x86/x86_64/hypercall-x86_64.h
> index e00b3bd..6171812 100644
> --- a/include/x86/x86_64/hypercall-x86_64.h
> +++ b/include/x86/x86_64/hypercall-x86_64.h
> @@ -331,6 +331,12 @@ HYPERVISOR_domctl(
>  	return _hypercall1(int, domctl, op);
>  }
>  
> +static inline unsigned long
> +HYPERVISOR_hvm_op(int op, void *arg)
> +{
> +	return _hypercall2(unsigned long, hvm_op, op, arg);
> +}
> +
>  #endif /* __HYPERCALL_X86_64_H__ */
>  
>  /*
> -- 
> 2.6.6
> 

-- 
Samuel
«Le monochrome, c'est pour ceux qui s'intéressent (encore) au contenu. 
 Usenet dans ces conditions, c'est comme le web avec lynx, on prend 
 trop conscience du vide, c'est déprimant.»
    -+- JLC in Guide du linuxien pervers : "Coup de cafard..." -+-

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 08/22] mini-os: initialize trap handling for HVMlite
  2016-08-23 15:15 ` [PATCH 08/22] mini-os: initialize trap handling for HVMlite Juergen Gross
@ 2016-08-23 22:05   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 22:05 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:15:54 +0200, wrote:
> Trap handling for HVMlite domains requires an initialized IDT.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/x86/setup.c  | 15 ----------
>  arch/x86/traps.c  | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  arch/x86/x86_64.S |  4 +++
>  include/x86/os.h  |  1 +
>  4 files changed, 93 insertions(+), 15 deletions(-)
> 
> diff --git a/arch/x86/setup.c b/arch/x86/setup.c
> index edc4ca4..efecefb 100644
> --- a/arch/x86/setup.c
> +++ b/arch/x86/setup.c
> @@ -52,10 +52,6 @@ char stack[2*STACK_SIZE];
>  
>  extern char shared_info[PAGE_SIZE];
>  
> -/* Assembler interface fns in entry.S. */
> -void hypervisor_callback(void);
> -void failsafe_callback(void);
> -
>  #if defined(__x86_64__)
>  #define __pte(x) ((pte_t) { (x) } )
>  #else
> @@ -162,17 +158,6 @@ arch_init(void *par)
>  	/* Grab the shared_info pointer and put it in a safe place. */
>  	HYPERVISOR_shared_info = map_shared_info(start_info.shared_info);
>  
> -	    /* Set up event and failsafe callback addresses. */
> -#ifdef __i386__
> -	HYPERVISOR_set_callbacks(
> -		__KERNEL_CS, (unsigned long)hypervisor_callback,
> -		__KERNEL_CS, (unsigned long)failsafe_callback);
> -#else
> -	HYPERVISOR_set_callbacks(
> -		(unsigned long)hypervisor_callback,
> -		(unsigned long)failsafe_callback, 0);
> -#endif
> -
>  	start_kernel();
>  }
>  
> diff --git a/arch/x86/traps.c b/arch/x86/traps.c
> index 307a14c..3b1fffb 100644
> --- a/arch/x86/traps.c
> +++ b/arch/x86/traps.c
> @@ -1,10 +1,12 @@
>  
>  #include <mini-os/os.h>
>  #include <mini-os/traps.h>
> +#include <mini-os/desc.h>
>  #include <mini-os/hypervisor.h>
>  #include <mini-os/mm.h>
>  #include <mini-os/lib.h>
>  #include <mini-os/sched.h>
> +#include <xen/hvm/params.h>
>  
>  /*
>   * These are assembler stubs in entry.S.
> @@ -293,6 +295,11 @@ void do_spurious_interrupt_bug(struct pt_regs * regs)
>  {
>  }
>  
> +/* Assembler interface fns in entry.S. */
> +void hypervisor_callback(void);
> +void failsafe_callback(void);
> +
> +#ifdef CONFIG_PARAVIRT
>  /*
>   * Submit a virtual IDT to teh hypervisor. This consists of tuples
>   * (interrupt vector, privilege ring, CS:EIP of handler).
> @@ -325,9 +332,90 @@ static trap_info_t trap_table[] = {
>  void trap_init(void)
>  {
>      HYPERVISOR_set_trap_table(trap_table);    
> +
> +#ifdef __i386__
> +    HYPERVISOR_set_callbacks(
> +        __KERNEL_CS, (unsigned long)hypervisor_callback,
> +        __KERNEL_CS, (unsigned long)failsafe_callback);
> +#else
> +    HYPERVISOR_set_callbacks(
> +        (unsigned long)hypervisor_callback,
> +        (unsigned long)failsafe_callback, 0);
> +#endif
>  }
>  
>  void trap_fini(void)
>  {
>      HYPERVISOR_set_trap_table(NULL);
>  }
> +#else
> +
> +#define INTR_STACK_SIZE PAGE_SIZE
> +static uint8_t intr_stack[INTR_STACK_SIZE] __attribute__((aligned(16)));
> +
> +hw_tss tss __attribute__((aligned(16))) =
> +{
> +#if defined(__i386__)
> +    .esp0 = (unsigned long)&intr_stack[INTR_STACK_SIZE],
> +    .ss0  = __KERN_DS,
> +#elif defined(__x86_64__)
> +    .rsp0 = (unsigned long)&intr_stack[INTR_STACK_SIZE],
> +#endif
> +    .iopb = X86_TSS_INVALID_IO_BITMAP,
> +};
> +
> +static void setup_gate(unsigned int entry, void *addr, unsigned int dpl)
> +{
> +    idt[entry].offset0 = (unsigned long)addr & 0xffff;
> +    idt[entry].selector = __KERN_CS;
> +    idt[entry]._r0 = 0;
> +    idt[entry].type = 14;
> +    idt[entry].s = 0;
> +    idt[entry].dpl = dpl;
> +    idt[entry].p = 1;
> +    idt[entry].offset1 = ((unsigned long)addr >> 16) & 0xffff;
> +#if defined(__x86_64__)
> +    idt[entry].ist = 0;
> +    idt[entry].offset2 = ((unsigned long)addr >> 32) & 0xffffffffu;
> +    idt[entry]._r1 = 0;
> +#endif
> +}
> +
> +void trap_init(void)
> +{
> +    setup_gate(TRAP_divide_error, &divide_error, 0);
> +    setup_gate(TRAP_debug, &debug, 0);
> +    setup_gate(TRAP_int3, &int3, 3);
> +    setup_gate(TRAP_overflow, &overflow, 3);
> +    setup_gate(TRAP_bounds, &bounds, 0);
> +    setup_gate(TRAP_invalid_op, &invalid_op, 0);
> +    setup_gate(TRAP_no_device, &device_not_available, 0);
> +    setup_gate(TRAP_copro_seg, &coprocessor_segment_overrun, 0);
> +    setup_gate(TRAP_invalid_tss, &invalid_TSS, 0);
> +    setup_gate(TRAP_no_segment, &segment_not_present, 0);
> +    setup_gate(TRAP_stack_error, &stack_segment, 0);
> +    setup_gate(TRAP_gp_fault, &general_protection, 0);
> +    setup_gate(TRAP_page_fault, &page_fault, 0);
> +    setup_gate(TRAP_spurious_int, &spurious_interrupt_bug, 0);
> +    setup_gate(TRAP_copro_error, &coprocessor_error, 0);
> +    setup_gate(TRAP_alignment_check, &alignment_check, 0);
> +    setup_gate(TRAP_simd_error, &simd_coprocessor_error, 0);
> +    setup_gate(TRAP_xen_callback, hypervisor_callback, 0);
> +
> +    asm volatile ("lidt idt_ptr");
> +
> +    gdt[GDTE_TSS] = (typeof(*gdt))INIT_GDTE((unsigned long)&tss, 0x67, 0x89);
> +    asm volatile ("ltr %w0" :: "rm" (GDTE_TSS * 8));
> +
> +    if ( hvm_set_parameter(HVM_PARAM_CALLBACK_IRQ,
> +                           (2ULL << 56) | TRAP_xen_callback) )
> +    {
> +        xprintk("Request for Xen HVM callback vector failed\n");
> +        do_exit();
> +    }
> +}
> +
> +void trap_fini(void)
> +{
> +}
> +#endif
> diff --git a/arch/x86/x86_64.S b/arch/x86/x86_64.S
> index 373f400..e725c63 100644
> --- a/arch/x86/x86_64.S
> +++ b/arch/x86/x86_64.S
> @@ -130,18 +130,22 @@ KERNEL_CS_MASK = 0xfc
>  .endm
>  
>  .macro HYPERVISOR_IRET flag
> +#ifdef CONFIG_PARAVIRT
>  	testl $NMI_MASK,2*8(%rsp)
>  	jnz   2f
> +#endif
>  
>  	/* Direct iret to kernel space. Correct CS and SS. */
>  	orb   $3,1*8(%rsp)
>  	orb   $3,4*8(%rsp)
>  	iretq
>  
> +#ifdef CONFIG_PARAVIRT
>  2:	/* Slow iret via hypervisor. */
>  	andl  $~NMI_MASK, 16(%rsp)
>  	pushq $\flag
>  	jmp  hypercall_page + (__HYPERVISOR_iret * 32)
> +#endif
>  .endm
>  
>  
> diff --git a/include/x86/os.h b/include/x86/os.h
> index 610d8e0..6826b9f 100644
> --- a/include/x86/os.h
> +++ b/include/x86/os.h
> @@ -56,6 +56,7 @@
>  #define TRAP_machine_check    18
>  #define TRAP_simd_error       19
>  #define TRAP_deferred_nmi     31
> +#define TRAP_xen_callback     32
>  
>  /* Everything below this point is not included by assembler (.S) files. */
>  #ifndef __ASSEMBLY__
> -- 
> 2.6.6
> 

-- 
Samuel
 RM> Mauvais OS, changer d'OS (c)(r)(tm)
 J'ai windows 98 et comment faire pour changer l'os de windows 98?
 Dans ajout et suppression du programme et il ne parle pas d'os.
 -+- DN in : GNU -+- L'O.S. est las, hélas, c'est là qu'est l'os -+-

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 09/22] mini-os: support HVMlite traps
  2016-08-23 15:15 ` [PATCH 09/22] mini-os: support HVMlite traps Juergen Gross
@ 2016-08-23 22:10   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 22:10 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:15:55 +0200, wrote:
> Trap handling in HVMlite domain is different from pv one.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/x86/traps.c  |  2 --
>  arch/x86/x86_32.S | 19 ++++++++++++++--
>  arch/x86/x86_64.S | 22 +++++++++++++++++-
>  include/x86/os.h  | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++----
>  4 files changed, 101 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/x86/traps.c b/arch/x86/traps.c
> index 3b1fffb..0b3d85b 100644
> --- a/arch/x86/traps.c
> +++ b/arch/x86/traps.c
> @@ -191,8 +191,6 @@ static void dump_mem(unsigned long addr)
>      }
>      printk("\n");
>  }
> -#define read_cr2() \
> -        (HYPERVISOR_shared_info->vcpu_info[smp_processor_id()].arch.cr2)
>  
>  static int handling_pg_fault = 0;
>  
> diff --git a/arch/x86/x86_32.S b/arch/x86/x86_32.S
> index 6f38708..9241418 100644
> --- a/arch/x86/x86_32.S
> +++ b/arch/x86/x86_32.S
> @@ -8,6 +8,9 @@
>  #include <xen/arch-x86_32.h>
>  
>  #ifdef CONFIG_PARAVIRT
> +
> +#define KERNEL_DS __KERNEL_DS
> +
>  ELFNOTE(Xen, XEN_ELFNOTE_GUEST_OS, .asciz "Mini-OS")
>  ELFNOTE(Xen, XEN_ELFNOTE_LOADER, .asciz "generic")
>  ELFNOTE(Xen, XEN_ELFNOTE_HYPERCALL_PAGE, _WORD hypercall_page)
> @@ -21,6 +24,8 @@ _start:
>          lss stack_start,%esp
>  #else
>  
> +#define KERNEL_DS __KERN_DS
> +
>  #include "x86_hvm.S"
>          movl stack_start,%esp
>  
> @@ -61,7 +66,7 @@ CS		= 0x2C
>  	pushl %edx; \
>  	pushl %ecx; \
>  	pushl %ebx; \
> -	movl $(__KERNEL_DS),%edx; \
> +	movl $(KERNEL_DS),%edx; \
>  	movl %edx,%ds; \
>  	movl %edx,%es;
>  
> @@ -98,7 +103,7 @@ do_exception:
>  	movl ORIG_EAX(%esp), %edx	# get the error code
>  	movl %eax, ORIG_EAX(%esp)
>  	movl %ecx, ES(%esp)
> -	movl $(__KERNEL_DS), %ecx
> +	movl $(KERNEL_DS), %ecx
>  	movl %ecx, %ds
>  	movl %ecx, %es
>  	movl %esp,%eax			# pt_regs pointer
> @@ -112,6 +117,7 @@ ret_from_exception:
>      addl $8,%esp
>      RESTORE_ALL
>  
> +#ifdef CONFIG_PARAVIRT
>  # A note on the "critical region" in our callback handler.
>  # We want to avoid stacking callback handlers due to events occurring
>  # during handling of the last event. To do this, we keep events disabled
> @@ -189,6 +195,15 @@ critical_fixup_table:
>          .byte 0x28                            # iret
>          .byte 0x00,0x00,0x00,0x00             # movb $1,1(%esi)
>          .byte 0x00,0x00                       # jmp  11b
> +
> +#else
> +
> +ENTRY(hypervisor_callback)
> +	pushl $0
> +	pushl $do_hypervisor_callback
> +	jmp do_exception
> +
> +#endif
>         
>  # Hypervisor uses this for application faults while it executes.
>  ENTRY(failsafe_callback)
> diff --git a/arch/x86/x86_64.S b/arch/x86/x86_64.S
> index e725c63..17a9ead 100644
> --- a/arch/x86/x86_64.S
> +++ b/arch/x86/x86_64.S
> @@ -78,9 +78,11 @@ KERNEL_CS_MASK = 0xfc
>  
>  /* Macros */
>  .macro zeroentry sym
> +#ifdef CONFIG_PARAVIRT
>  	movq (%rsp),%rcx
>  	movq 8(%rsp),%r11
>  	addq $0x10,%rsp /* skip rcx and r11 */
> +#endif
>  	pushq $0	/* push error code/oldrax */
>  	pushq %rax	/* push real oldrax to the rdi slot */
>  	leaq  \sym(%rip),%rax
> @@ -88,9 +90,11 @@ KERNEL_CS_MASK = 0xfc
>  .endm
>  
>  .macro errorentry sym
> +#ifdef CONFIG_PARAVIRT
>  	movq (%rsp),%rcx
>  	movq 8(%rsp),%r11
>  	addq $0x10,%rsp /* rsp points to the error code */
> +#endif
>  	pushq %rax
>  	leaq  \sym(%rip),%rax
>  	jmp error_entry
> @@ -133,11 +137,11 @@ KERNEL_CS_MASK = 0xfc
>  #ifdef CONFIG_PARAVIRT
>  	testl $NMI_MASK,2*8(%rsp)
>  	jnz   2f
> -#endif
>  
>  	/* Direct iret to kernel space. Correct CS and SS. */
>  	orb   $3,1*8(%rsp)
>  	orb   $3,4*8(%rsp)
> +#endif
>  	iretq
>  
>  #ifdef CONFIG_PARAVIRT
> @@ -182,6 +186,7 @@ error_call_handler:
>  	jmp error_exit
>  
>  
> +#ifdef CONFIG_PARAVIRT
>  /*
>   * Xen event (virtual interrupt) entry point.
>   */
> @@ -285,11 +290,26 @@ critical_region_fixup:
>  	andb $KERNEL_CS_MASK,CS(%rsp)      # CS might have changed
>  	jmp  11b
>  
> +#else
> +error_exit:
> +	RESTORE_REST
> +	RESTORE_ALL
> +	HYPERVISOR_IRET 0
>  
> +/*
> + * Xen event (virtual interrupt) entry point.
> + */
> +ENTRY(hypervisor_callback)
> +	zeroentry do_hypervisor_callback
> +
> +
> +#endif
>  
>  ENTRY(failsafe_callback)
> +#ifdef CONFIG_PARAVIRT
>          popq  %rcx
>          popq  %r11
> +#endif
>          iretq
>  
>  
> diff --git a/include/x86/os.h b/include/x86/os.h
> index 6826b9f..1083328 100644
> --- a/include/x86/os.h
> +++ b/include/x86/os.h
> @@ -31,6 +31,8 @@
>  #define X86_CR4_PAE       0x00000020    /* enable physical address extensions */
>  #define X86_CR4_OSFXSR    0x00000200    /* enable fast FPU save and restore */
>  
> +#define X86_EFLAGS_IF     0x00000200
> +
>  #define __KERNEL_CS  FLAT_KERNEL_CS
>  #define __KERNEL_DS  FLAT_KERNEL_DS
>  #define __KERNEL_SS  FLAT_KERNEL_SS
> @@ -70,7 +72,7 @@ void arch_fini(void);
>  
>  
>  
> -
> +#ifdef CONFIG_PARAVIRT
>  
>  /* 
>   * The use of 'barrier' in the following reflects their use as local-lock
> @@ -129,15 +131,57 @@ do {									\
>  	barrier();							\
>  } while (0)
>  
> +#define irqs_disabled()			\
> +    HYPERVISOR_shared_info->vcpu_info[smp_processor_id()].evtchn_upcall_mask
> +
> +#else
> +
> +#if defined(__i386__)
> +#define __SZ "l"
> +#define __REG "e"
> +#else
> +#define __SZ "q"
> +#define __REG "r"
> +#endif
> +
> +#define __cli() asm volatile ( "cli" : : : "memory" )
> +#define __sti() asm volatile ( "sti" : : : "memory" )
> +
> +#define __save_flags(x)                                                 \
> +do {                                                                    \
> +    unsigned long __f;                                                  \
> +    asm volatile ( "pushf" __SZ " ; pop" __SZ " %0" : "=g" (__f));      \
> +    x = (__f & X86_EFLAGS_IF) ? 1 : 0;                                  \
> +} while (0)
> +
> +#define __restore_flags(x)                                              \
> +do {                                                                    \
> +    if (x) __sti();                                                     \
> +    else __cli();                                                       \
> +} while (0)
> +
> +#define __save_and_cli(x)                                               \
> +do {                                                                    \
> +    __save_flags(x);                                                    \
> +    __cli();                                                            \
> +} while (0)
> +
> +static inline int irqs_disabled(void)
> +{
> +    int flag;
> +
> +    __save_flags(flag);
> +    return !flag;
> +}
> +
> +#endif
> +
>  #define local_irq_save(x)	__save_and_cli(x)
>  #define local_irq_restore(x)	__restore_flags(x)
>  #define local_save_flags(x)	__save_flags(x)
>  #define local_irq_disable()	__cli()
>  #define local_irq_enable()	__sti()
>  
> -#define irqs_disabled()			\
> -    HYPERVISOR_shared_info->vcpu_info[smp_processor_id()].evtchn_upcall_mask
> -
>  /* This is a barrier for the compiler only, NOT the processor! */
>  #define barrier() __asm__ __volatile__("": : :"memory")
>  
> @@ -586,5 +630,20 @@ static inline void cpuid(uint32_t leaf,
>  
>  #undef ADDR
>  
> +#ifdef CONFIG_PARAVIRT
> +static inline unsigned long read_cr2(void)
> +{
> +    return HYPERVISOR_shared_info->vcpu_info[smp_processor_id()].arch.cr2;
> +}
> +#else
> +static inline unsigned long read_cr2(void)
> +{
> +    unsigned long cr2;
> +
> +    asm volatile ( "mov %%cr2,%0\n\t" : "=r" (cr2) );
> +    return cr2;
> +}
> +#endif
> +
>  #endif /* not assembly */
>  #endif /* _OS_H_ */
> -- 
> 2.6.6
> 

-- 
Samuel
Tu as lu les docs. Tu es devenu un informaticien. Que tu le veuilles
ou non. Lire la doc, c'est le Premier et Unique Commandement de
l'informaticien.
-+- TP in: Guide du Linuxien pervers - "L'évangile selon St Thomas"

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 10/22] mini-os: make p2m related code depend on CONFIG_PARAVIRT
  2016-08-23 15:15 ` [PATCH 10/22] mini-os: make p2m related code depend on CONFIG_PARAVIRT Juergen Gross
@ 2016-08-23 22:20   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 22:20 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:15:56 +0200, wrote:
> All handling related to p2m is needed for paravirtualized environment
> only. So put all functions operating on p2m list in #ifdef
> CONFIG_PARAVIRT sections. Add a paravirt.h header defining dummy
> functions for non-paravirtualized environments. Instead of using
> references to start_info use dedicated variables initialized from
> start_info on boot.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/arm/balloon.c                |  5 ---
>  arch/arm/mm.c                     |  4 ---
>  arch/x86/balloon.c                | 13 ++++++++
>  arch/x86/mm.c                     | 67 +++++++++++++++++++++++++++++----------
>  arch/x86/setup.c                  |  6 ++--
>  arch/x86/traps.c                  |  6 ++--
>  balloon.c                         |  1 +
>  include/arm/arch_mm.h             |  3 --
>  include/balloon.h                 |  3 --
>  include/mm.h                      |  2 +-
>  include/paravirt.h                | 48 ++++++++++++++++++++++++++++
>  include/x86/arch_mm.h             | 40 +++++------------------
>  include/xen/arch-x86/xen-x86_32.h |  2 ++
>  include/xen/arch-x86/xen-x86_64.h |  2 ++
>  mm.c                              |  1 +
>  15 files changed, 133 insertions(+), 70 deletions(-)
> 
> diff --git a/arch/arm/balloon.c b/arch/arm/balloon.c
> index 7f35328..958ecba 100644
> --- a/arch/arm/balloon.c
> +++ b/arch/arm/balloon.c
> @@ -27,11 +27,6 @@
>  
>  unsigned long virt_kernel_area_end;   /* TODO: find a virtual area */
>  
> -int arch_expand_p2m(unsigned long max_pfn)
> -{
> -    return 0;
> -}
> -
>  void arch_pfn_add(unsigned long pfn, unsigned long mfn)
>  {
>  }
> diff --git a/arch/arm/mm.c b/arch/arm/mm.c
> index fc8d4bc..4f58fc7 100644
> --- a/arch/arm/mm.c
> +++ b/arch/arm/mm.c
> @@ -72,10 +72,6 @@ void arch_init_mm(unsigned long *start_pfn_p, unsigned long *max_pfn_p)
>      *max_pfn_p = to_phys(new_device_tree) >> PAGE_SHIFT;
>  }
>  
> -void arch_init_p2m(unsigned long max_pfn)
> -{
> -}
> -
>  void arch_init_demand_mapping_area(void)
>  {
>  }
> diff --git a/arch/x86/balloon.c b/arch/x86/balloon.c
> index 42389e4..16aaae4 100644
> --- a/arch/x86/balloon.c
> +++ b/arch/x86/balloon.c
> @@ -26,11 +26,13 @@
>  #include <mini-os/errno.h>
>  #include <mini-os/lib.h>
>  #include <mini-os/mm.h>
> +#include <mini-os/paravirt.h>
>  
>  #ifdef CONFIG_BALLOON
>  
>  unsigned long virt_kernel_area_end = VIRT_KERNEL_AREA;
>  
> +#ifdef CONFIG_PARAVIRT
>  static void p2m_invalidate(unsigned long *list, unsigned long start_idx)
>  {
>      unsigned long idx;
> @@ -143,5 +145,16 @@ void arch_pfn_add(unsigned long pfn, unsigned long mfn)
>          do_exit();
>      }
>  }
> +#else
> +void arch_pfn_add(unsigned long pfn, unsigned long mfn)
> +{
> +    pgentry_t *pgt;
> +
> +    pgt = need_pgt((unsigned long)pfn_to_virt(pfn));
> +    ASSERT(pgt);
> +    if ( !(*pgt & _PAGE_PSE) )
> +        *pgt = (pgentry_t)(mfn << PAGE_SHIFT) | _PAGE_PRESENT | _PAGE_RW;
> +}
> +#endif
>  
>  #endif
> diff --git a/arch/x86/mm.c b/arch/x86/mm.c
> index fe18f53..0543017 100644
> --- a/arch/x86/mm.c
> +++ b/arch/x86/mm.c
> @@ -39,6 +39,7 @@
>  #include <mini-os/hypervisor.h>
>  #include <mini-os/balloon.h>
>  #include <mini-os/mm.h>
> +#include <mini-os/paravirt.h>
>  #include <mini-os/types.h>
>  #include <mini-os/lib.h>
>  #include <mini-os/xmalloc.h>
> @@ -53,10 +54,24 @@
>  
>  unsigned long *phys_to_machine_mapping;
>  unsigned long mfn_zero;
> +pgentry_t *pt_base;
> +static unsigned long first_free_pfn;
> +static unsigned long last_free_pfn;
> +
>  extern char stack[];
>  extern void page_walk(unsigned long va);
>  
> -#ifndef CONFIG_PARAVIRT
> +#ifdef CONFIG_PARAVIRT
> +void arch_mm_preinit(void *p)
> +{
> +    start_info_t *si = p;
> +
> +    phys_to_machine_mapping = (unsigned long *)si->mfn_list;
> +    pt_base = (pgentry_t *)si->pt_base;
> +    first_free_pfn = PFN_UP(to_phys(pt_base)) + si->nr_pt_frames;
> +    last_free_pfn = si->nr_pages;
> +}
> +#else
>  #include <mini-os/desc.h>
>  user_desc gdt[NR_GDT_ENTRIES] =
>  {
> @@ -85,6 +100,22 @@ desc_ptr idt_ptr =
>      .limit = sizeof(idt) - 1,
>      .base = (unsigned long)&idt,
>  };
> +
> +void arch_mm_preinit(void *p)
> +{
> +    long ret;
> +    domid_t domid = DOMID_SELF;
> +
> +    pt_base = page_table_base;
> +    first_free_pfn = PFN_UP(to_phys(&_end));
> +    ret = HYPERVISOR_memory_op(XENMEM_current_reservation, &domid);
> +    if ( ret < 0 )
> +    {
> +        xprintk("could not get memory size\n");
> +        do_exit();
> +    }
> +    last_free_pfn = ret;
> +}
>  #endif
>  
>  /*
> @@ -95,7 +126,7 @@ desc_ptr idt_ptr =
>  static void new_pt_frame(unsigned long *pt_pfn, unsigned long prev_l_mfn, 
>                           unsigned long offset, unsigned long level)
>  {   
> -    pgentry_t *tab = (pgentry_t *)start_info.pt_base;
> +    pgentry_t *tab = pt_base;
>      unsigned long pt_page = (unsigned long)pfn_to_virt(*pt_pfn); 
>      pgentry_t prot_e, prot_t;
>      mmu_update_t mmu_updates[1];
> @@ -172,8 +203,8 @@ static void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
>      unsigned long start_address, end_address;
>      unsigned long pfn_to_map, pt_pfn = *start_pfn;
>      static mmu_update_t mmu_updates[L1_PAGETABLE_ENTRIES + 1];
> -    pgentry_t *tab = (pgentry_t *)start_info.pt_base, page;
> -    unsigned long pt_mfn = pfn_to_mfn(virt_to_pfn(start_info.pt_base));
> +    pgentry_t *tab = pt_base, page;
> +    unsigned long pt_mfn = pfn_to_mfn(virt_to_pfn(pt_base));
>      unsigned long offset;
>      int count = 0;
>      int rc;
> @@ -182,6 +213,7 @@ static void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
>         mapped, start the loop at the very beginning. */
>      pfn_to_map = *start_pfn;
>  
> +#ifdef CONFIG_PARAVIRT
>      if ( *max_pfn >= virt_to_pfn(HYPERVISOR_VIRT_START) )
>      {
>          printk("WARNING: Mini-OS trying to use Xen virtual space. "
> @@ -193,6 +225,7 @@ static void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
>                 ((unsigned long)pfn_to_virt(*max_pfn) - 
>                  (unsigned long)&_text)>>20);
>      }
> +#endif
>  
>      start_address = (unsigned long)pfn_to_virt(pfn_to_map);
>      end_address = (unsigned long)pfn_to_virt(*max_pfn);
> @@ -202,8 +235,8 @@ static void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
>  
>      while ( start_address < end_address )
>      {
> -        tab = (pgentry_t *)start_info.pt_base;
> -        pt_mfn = pfn_to_mfn(virt_to_pfn(start_info.pt_base));
> +        tab = pt_base;
> +        pt_mfn = pfn_to_mfn(virt_to_pfn(pt_base));
>  
>  #if defined(__x86_64__)
>          offset = l4_table_offset(start_address);
> @@ -270,8 +303,8 @@ static void set_readonly(void *text, void *etext)
>          ((unsigned long) text + PAGE_SIZE - 1) & PAGE_MASK;
>      unsigned long end_address = (unsigned long) etext;
>      static mmu_update_t mmu_updates[L1_PAGETABLE_ENTRIES + 1];
> -    pgentry_t *tab = (pgentry_t *)start_info.pt_base, page;
> -    unsigned long mfn = pfn_to_mfn(virt_to_pfn(start_info.pt_base));
> +    pgentry_t *tab = pt_base, page;
> +    unsigned long mfn = pfn_to_mfn(virt_to_pfn(pt_base));
>      unsigned long offset;
>      int count = 0;
>      int rc;
> @@ -280,8 +313,8 @@ static void set_readonly(void *text, void *etext)
>  
>      while ( start_address + PAGE_SIZE <= end_address )
>      {
> -        tab = (pgentry_t *)start_info.pt_base;
> -        mfn = pfn_to_mfn(virt_to_pfn(start_info.pt_base));
> +        tab = pt_base;
> +        mfn = pfn_to_mfn(virt_to_pfn(pt_base));
>  
>  #if defined(__x86_64__)
>          offset = l4_table_offset(start_address);
> @@ -343,8 +376,8 @@ static pgentry_t *get_pgt(unsigned long va)
>      pgentry_t *tab;
>      unsigned offset;
>  
> -    tab = (pgentry_t *)start_info.pt_base;
> -    mfn = virt_to_mfn(start_info.pt_base);
> +    tab = pt_base;
> +    mfn = virt_to_mfn(pt_base);
>  
>  #if defined(__x86_64__)
>      offset = l4_table_offset(va);
> @@ -379,8 +412,8 @@ pgentry_t *need_pgt(unsigned long va)
>      unsigned long pt_pfn;
>      unsigned offset;
>  
> -    tab = (pgentry_t *)start_info.pt_base;
> -    pt_mfn = virt_to_mfn(start_info.pt_base);
> +    tab = pt_base;
> +    pt_mfn = virt_to_mfn(pt_base);
>  
>  #if defined(__x86_64__)
>      offset = l4_table_offset(va);
> @@ -639,6 +672,7 @@ static void clear_bootstrap(void)
>          printk("Unable to unmap NULL page. rc=%d\n", rc);
>  }
>  
> +#ifdef CONFIG_PARAVIRT
>  void p2m_chk_pfn(unsigned long pfn)
>  {
>      if ( (pfn >> L3_P2M_SHIFT) > 0 )
> @@ -670,6 +704,7 @@ void arch_init_p2m(unsigned long max_pfn)
>  
>      arch_remap_p2m(max_pfn);
>  }
> +#endif
>  
>  void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p)
>  {
> @@ -683,8 +718,8 @@ void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p)
>      printk("       _end: %p(VA)\n", &_end);
>  
>      /* First page follows page table pages. */
> -    start_pfn = PFN_UP(to_phys(start_info.pt_base)) + start_info.nr_pt_frames;
> -    max_pfn = start_info.nr_pages;
> +    start_pfn = first_free_pfn;
> +    max_pfn = last_free_pfn;
>  
>      if ( max_pfn >= MAX_MEM_SIZE / PAGE_SIZE )
>          max_pfn = MAX_MEM_SIZE / PAGE_SIZE - 1;
> diff --git a/arch/x86/setup.c b/arch/x86/setup.c
> index efecefb..8b6bb6e 100644
> --- a/arch/x86/setup.c
> +++ b/arch/x86/setup.c
> @@ -131,6 +131,9 @@ arch_init(void *par)
>  	/* Initialize SSE */
>  	sse_init();
>  
> +	/* Setup memory management info from start_info. */
> +	arch_mm_preinit(par);
> +
>  	/* Copy the start_info struct to a globally-accessible area. */
>  	/* WARN: don't do printk before here, it uses information from
>  	   shared_info. Use xprintk instead. */
> @@ -152,9 +155,6 @@ arch_init(void *par)
>  			si->cmd_line ? (const char *)si->cmd_line : "NULL");
>  	printk("       stack: %p-%p\n", stack, stack + sizeof(stack));
>  
> -	/* set up minimal memory infos */
> -	phys_to_machine_mapping = (unsigned long *)start_info.mfn_list;
> -
>  	/* Grab the shared_info pointer and put it in a safe place. */
>  	HYPERVISOR_shared_info = map_shared_info(start_info.shared_info);
>  
> diff --git a/arch/x86/traps.c b/arch/x86/traps.c
> index 0b3d85b..2d3222d 100644
> --- a/arch/x86/traps.c
> +++ b/arch/x86/traps.c
> @@ -97,9 +97,9 @@ DO_ERROR(18, "machine check", machine_check)
>  
>  void page_walk(unsigned long virt_address)
>  {
> -        pgentry_t *tab = (pgentry_t *)start_info.pt_base, page;
> +        pgentry_t *tab = pt_base, page;
>          unsigned long addr = virt_address;
> -        printk("Pagetable walk from virt %lx, base %lx:\n", virt_address, start_info.pt_base);
> +        printk("Pagetable walk from virt %lx, base %p:\n", virt_address, pt_base);
>      
>  #if defined(__x86_64__)
>          page = tab[l4_table_offset(addr)];
> @@ -119,7 +119,7 @@ void page_walk(unsigned long virt_address)
>  }
>  
>  static int handle_cow(unsigned long addr) {
> -        pgentry_t *tab = (pgentry_t *)start_info.pt_base, page;
> +        pgentry_t *tab = pt_base, page;
>  	unsigned long new_page;
>  	int rc;
>  
> diff --git a/balloon.c b/balloon.c
> index 608492a..8d2f151 100644
> --- a/balloon.c
> +++ b/balloon.c
> @@ -25,6 +25,7 @@
>  #include <mini-os/balloon.h>
>  #include <mini-os/errno.h>
>  #include <mini-os/lib.h>
> +#include <mini-os/paravirt.h>
>  #include <xen/xen.h>
>  #include <xen/memory.h>
>  
> diff --git a/include/arm/arch_mm.h b/include/arm/arch_mm.h
> index f4685d8..79d9e05 100644
> --- a/include/arm/arch_mm.h
> +++ b/include/arm/arch_mm.h
> @@ -29,9 +29,6 @@ extern uint32_t physical_address_offset;	/* Add this to a virtual address to get
>  #define mfn_to_virt(_mfn)          (to_virt(PFN_PHYS(_mfn)))
>  #define pfn_to_virt(_pfn)          (to_virt(PFN_PHYS(_pfn)))
>  
> -#define mfn_to_pfn(x) (x)
> -#define pfn_to_mfn(x) (x)
> -
>  #define virtual_to_mfn(_virt)	   virt_to_mfn(_virt)
>  
>  // FIXME
> diff --git a/include/balloon.h b/include/balloon.h
> index d8710ad..8cd41af 100644
> --- a/include/balloon.h
> +++ b/include/balloon.h
> @@ -39,16 +39,13 @@ extern unsigned long nr_mem_pages;
>  void get_max_pages(void);
>  int balloon_up(unsigned long n_pages);
>  
> -void arch_remap_p2m(unsigned long max_pfn);
>  void mm_alloc_bitmap_remap(void);
> -int arch_expand_p2m(unsigned long max_pfn);
>  void arch_pfn_add(unsigned long pfn, unsigned long mfn);
>  int chk_free_pages(unsigned long needed);
>  
>  #else /* CONFIG_BALLOON */
>  
>  static inline void get_max_pages(void) { }
> -static inline void arch_remap_p2m(unsigned long max_pfn) { }
>  static inline void mm_alloc_bitmap_remap(void) { }
>  static inline int chk_free_pages(unsigned long needed)
>  {
> diff --git a/include/mm.h b/include/mm.h
> index fc3128b..953570c 100644
> --- a/include/mm.h
> +++ b/include/mm.h
> @@ -36,6 +36,7 @@
>  #endif
>  #include <xen/xen.h>
>  
> +#include <mini-os/paravirt.h>
>  #include <mini-os/arch_limits.h>
>  #include <mini-os/arch_mm.h>
>  
> @@ -67,7 +68,6 @@ static __inline__ int get_order(unsigned long size)
>  
>  void arch_init_demand_mapping_area(void);
>  void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p);
> -void arch_init_p2m(unsigned long max_pfn_p);
>  
>  unsigned long allocate_ondemand(unsigned long n, unsigned long alignment);
>  /* map f[i*stride]+i*increment for i in 0..n-1, aligned on alignment pages */
> diff --git a/include/paravirt.h b/include/paravirt.h
> index 7852e16..15076be 100644
> --- a/include/paravirt.h
> +++ b/include/paravirt.h
> @@ -26,7 +26,55 @@
>  
>  #if defined(CONFIG_PARAVIRT)
>  
> +#define mfn_to_pfn(_mfn) (machine_to_phys_mapping[(_mfn)])
> +#define pfn_to_mfn(_pfn) (phys_to_machine_mapping[(_pfn)])
> +
> +/* for P2M */
> +#ifdef __x86_64__
> +#define P2M_SHIFT       9
>  #else
> +#define P2M_SHIFT       10
> +#endif
> +#define P2M_ENTRIES     (1UL << P2M_SHIFT)
> +#define P2M_MASK        (P2M_ENTRIES - 1)
> +#define L1_P2M_SHIFT    P2M_SHIFT
> +#define L2_P2M_SHIFT    (2 * P2M_SHIFT)
> +#define L3_P2M_SHIFT    (3 * P2M_SHIFT)
> +#define L1_P2M_IDX(pfn) ((pfn) & P2M_MASK)
> +#define L2_P2M_IDX(pfn) (((pfn) >> L1_P2M_SHIFT) & P2M_MASK)
> +#define L3_P2M_IDX(pfn) (((pfn) >> L2_P2M_SHIFT) & P2M_MASK)
> +#define INVALID_P2M_ENTRY (~0UL)
> +
> +void p2m_chk_pfn(unsigned long pfn);
> +
> +static inline unsigned long p2m_pages(unsigned long pages)
> +{
> +    return (pages + P2M_ENTRIES - 1) >> L1_P2M_SHIFT;
> +}
> +
> +void arch_init_p2m(unsigned long max_pfn_p);
> +
> +#else
> +
> +#define mfn_to_pfn(_mfn) ((unsigned long)(_mfn))
> +#define pfn_to_mfn(_pfn) ((unsigned long)(_pfn))
> +
> +static inline void arch_init_p2m(unsigned long max_pfn_p) { }
> +
> +#endif
> +
> +#if defined(CONFIG_PARAVIRT) && defined(CONFIG_BALLOON)
> +
> +void arch_remap_p2m(unsigned long max_pfn);
> +int arch_expand_p2m(unsigned long max_pfn);
> +
> +#else
> +
> +static inline void arch_remap_p2m(unsigned long max_pfn) { }
> +static inline int arch_expand_p2m(unsigned long max_pfn)
> +{
> +    return 0;
> +}
>  
>  #endif
>  
> diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h
> index 2b18b34..28ab406 100644
> --- a/include/x86/arch_mm.h
> +++ b/include/x86/arch_mm.h
> @@ -184,31 +184,6 @@ typedef unsigned long pgentry_t;
>  #define IO_PROT (L1_PROT)
>  #define IO_PROT_NOCACHE (L1_PROT | _PAGE_PCD)
>  
> -/* for P2M */
> -#ifdef __x86_64__
> -#define P2M_SHIFT       9
> -#else
> -#define P2M_SHIFT       10
> -#endif
> -#define P2M_ENTRIES     (1UL << P2M_SHIFT)
> -#define P2M_MASK        (P2M_ENTRIES - 1)
> -#define L1_P2M_SHIFT    P2M_SHIFT
> -#define L2_P2M_SHIFT    (2 * P2M_SHIFT)
> -#define L3_P2M_SHIFT    (3 * P2M_SHIFT)
> -#define L1_P2M_IDX(pfn) ((pfn) & P2M_MASK)
> -#define L2_P2M_IDX(pfn) (((pfn) >> L1_P2M_SHIFT) & P2M_MASK)
> -#define L3_P2M_IDX(pfn) (((pfn) >> L2_P2M_SHIFT) & P2M_MASK)
> -#define INVALID_P2M_ENTRY (~0UL)
> -
> -#ifndef __ASSEMBLY__
> -void p2m_chk_pfn(unsigned long pfn);
> -
> -static inline unsigned long p2m_pages(unsigned long pages)
> -{
> -    return (pages + P2M_ENTRIES - 1) >> L1_P2M_SHIFT;
> -}
> -#endif
> -
>  #include "arch_limits.h"
>  #define PAGE_SIZE       __PAGE_SIZE
>  #define PAGE_SHIFT      __PAGE_SHIFT
> @@ -232,10 +207,14 @@ typedef unsigned long paddr_t;
>  typedef unsigned long maddr_t;
>  #endif
>  
> +extern pgentry_t *pt_base;
> +#ifdef CONFIG_PARAVIRT
>  extern unsigned long *phys_to_machine_mapping;
> +#else
> +extern pgentry_t page_table_base[];
> +#endif
>  extern char _text, _etext, _erodata, _edata, _end;
>  extern unsigned long mfn_zero;
> -#define pfn_to_mfn(_pfn) (phys_to_machine_mapping[(_pfn)])
>  static __inline__ maddr_t phys_to_machine(paddr_t phys)
>  {
>  	maddr_t machine = pfn_to_mfn(phys >> PAGE_SHIFT);
> @@ -243,7 +222,6 @@ static __inline__ maddr_t phys_to_machine(paddr_t phys)
>  	return machine;
>  }
>  
> -#define mfn_to_pfn(_mfn) (machine_to_phys_mapping[(_mfn)])
>  static __inline__ paddr_t machine_to_phys(maddr_t machine)
>  {
>  	paddr_t phys = mfn_to_pfn(machine >> PAGE_SHIFT);
> @@ -267,13 +245,10 @@ static __inline__ paddr_t machine_to_phys(maddr_t machine)
>  #define pte_to_mfn(_pte)           (((_pte) & (PADDR_MASK&PAGE_MASK)) >> L1_PAGETABLE_SHIFT)
>  #define pte_to_virt(_pte)          to_virt(mfn_to_pfn(pte_to_mfn(_pte)) << PAGE_SHIFT)
>  
> -
> -#define PT_BASE			   ((pgentry_t *)start_info.pt_base)
> -
>  #ifdef __x86_64__
> -#define virtual_to_l3(_virt)	   ((pgentry_t *)pte_to_virt(PT_BASE[l4_table_offset(_virt)]))
> +#define virtual_to_l3(_virt)	   ((pgentry_t *)pte_to_virt(pt_base[l4_table_offset(_virt)]))
>  #else
> -#define virtual_to_l3(_virt)	   PT_BASE
> +#define virtual_to_l3(_virt)	   pt_base
>  #endif
>  
>  #define virtual_to_l2(_virt)	   ({ \
> @@ -297,6 +272,7 @@ static __inline__ paddr_t machine_to_phys(maddr_t machine)
>  #define do_map_zero(start, n) do_map_frames(start, &mfn_zero, n, 0, 0, DOMID_SELF, NULL, L1_PROT_RO)
>  
>  pgentry_t *need_pgt(unsigned long addr);
> +void arch_mm_preinit(void *p);
>  
>  #endif
>  
> diff --git a/include/xen/arch-x86/xen-x86_32.h b/include/xen/arch-x86/xen-x86_32.h
> index 1504191..6339727 100644
> --- a/include/xen/arch-x86/xen-x86_32.h
> +++ b/include/xen/arch-x86/xen-x86_32.h
> @@ -55,6 +55,7 @@
>  #define FLAT_USER_DS    FLAT_RING3_DS
>  #define FLAT_USER_SS    FLAT_RING3_SS
>  
> +#ifdef CONFIG_PARAVIRT
>  #define __HYPERVISOR_VIRT_START_PAE    0xF5800000
>  #define __MACH2PHYS_VIRT_START_PAE     0xF5800000
>  #define __MACH2PHYS_VIRT_END_PAE       0xF6800000
> @@ -90,6 +91,7 @@
>  #ifndef machine_to_phys_mapping
>  #define machine_to_phys_mapping ((unsigned long *)MACH2PHYS_VIRT_START)
>  #endif
> +#endif
>  
>  /* 32-/64-bit invariability for control interfaces (domctl/sysctl). */
>  #if defined(__XEN__) || defined(__XEN_TOOLS__)
> diff --git a/include/xen/arch-x86/xen-x86_64.h b/include/xen/arch-x86/xen-x86_64.h
> index 1c4e159..2c00111 100644
> --- a/include/xen/arch-x86/xen-x86_64.h
> +++ b/include/xen/arch-x86/xen-x86_64.h
> @@ -70,6 +70,7 @@
>  #define FLAT_USER_SS32 FLAT_RING3_SS32
>  #define FLAT_USER_SS   FLAT_USER_SS64
>  
> +#ifdef CONFIG_PARAVIRT
>  #define __HYPERVISOR_VIRT_START 0xFFFF800000000000
>  #define __HYPERVISOR_VIRT_END   0xFFFF880000000000
>  #define __MACH2PHYS_VIRT_START  0xFFFF800000000000
> @@ -86,6 +87,7 @@
>  #ifndef machine_to_phys_mapping
>  #define machine_to_phys_mapping ((unsigned long *)HYPERVISOR_VIRT_START)
>  #endif
> +#endif
>  
>  /*
>   * int HYPERVISOR_set_segment_base(unsigned int which, unsigned long base)
> diff --git a/mm.c b/mm.c
> index ca0b9be..c76be7f 100644
> --- a/mm.c
> +++ b/mm.c
> @@ -39,6 +39,7 @@
>  #include <xen/memory.h>
>  #include <mini-os/mm.h>
>  #include <mini-os/balloon.h>
> +#include <mini-os/paravirt.h>
>  #include <mini-os/types.h>
>  #include <mini-os/lib.h>
>  #include <mini-os/xmalloc.h>
> -- 
> 2.6.6
> 

-- 
Samuel
<y> t1 faich
<y> les programmes ils segfaultent jamais quand on veut
 -+- #ens-mim en plein débogage -+-

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 11/22] mini-os: add static page tables for virtual kernel area for HVMlite
  2016-08-23 15:15 ` [PATCH 11/22] mini-os: add static page tables for virtual kernel area for HVMlite Juergen Gross
@ 2016-08-23 22:27   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 22:27 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:15:57 +0200, wrote:
> In HVMlite mode we need the virtual kernel area for mapping of the
> console and xenbus ring pages as especially on 32 bit architecture
> their pfns might be above the supported maximum memory size.
> 
> Add the page tables needed for doing the mapping.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/x86/mm.c     | 11 +++++++++++
>  arch/x86/x86_64.S |  7 +++++++
>  2 files changed, 18 insertions(+)
> 
> diff --git a/arch/x86/mm.c b/arch/x86/mm.c
> index 0543017..cbb5617 100644
> --- a/arch/x86/mm.c
> +++ b/arch/x86/mm.c
> @@ -733,6 +733,17 @@ void arch_init_mm(unsigned long* start_pfn_p, unsigned long* max_pfn_p)
>  
>      *start_pfn_p = start_pfn;
>      *max_pfn_p = max_pfn;
> +
> +#ifndef CONFIG_PARAVIRT
> +#ifdef __x86_64__
> +    BUILD_BUG_ON(l4_table_offset(VIRT_KERNEL_AREA) != 1 ||
> +                 l3_table_offset(VIRT_KERNEL_AREA) != 0 ||
> +                 l2_table_offset(VIRT_KERNEL_AREA) != 0);
> +#else
> +    BUILD_BUG_ON(l3_table_offset(VIRT_KERNEL_AREA) != 0 ||
> +                 l2_table_offset(VIRT_KERNEL_AREA) == 0);
> +#endif
> +#endif
>  }
>  
>  grant_entry_t *arch_init_gnttab(int nr_grant_frames)
> diff --git a/arch/x86/x86_64.S b/arch/x86/x86_64.S
> index 17a9ead..5932bfb 100644
> --- a/arch/x86/x86_64.S
> +++ b/arch/x86/x86_64.S
> @@ -418,10 +418,17 @@ ENTRY(__arch_switch_threads)
>  .data
>  .globl page_table_base
>          .align __PAGE_SIZE
> +page_table_virt_l2:
> +        PTE(page_table_virt_l1 + L2_PROT)
> +        .align __PAGE_SIZE, 0
> +page_table_virt_l3:
> +        PTE(page_table_virt_l2 + L3_PROT)
> +        .align __PAGE_SIZE, 0
>  page_table_l3:
>          PTE(page_table_l2 + L3_PROT)
>          .align __PAGE_SIZE, 0
>  page_table_base:
>          PTE(page_table_l3 + L4_PROT)
> +        PTE(page_table_virt_l3 + L4_PROT)
>          .align __PAGE_SIZE, 0
>  #endif
> -- 
> 2.6.6
> 

-- 
Samuel
<A> sauf que le firewall bloque tout sauf internet
 -+- ben ouais, il bloque ipx/spx ! -+-

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 12/22] mini-os: add x86 native page table handling
  2016-08-23 15:15 ` [PATCH 12/22] mini-os: add x86 native page table handling Juergen Gross
@ 2016-08-23 22:40   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 22:40 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:15:58 +0200, wrote:
> For support of HVMlite don't use mmu_update hypercalls, but write the
> page table entries directly.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/x86/mm.c         | 147 +++++++++++++++++++++++++++++++++++++-------------
>  arch/x86/traps.c      |  10 ++++
>  include/x86/arch_mm.h |   4 ++
>  include/x86/os.h      |   9 ++++
>  4 files changed, 132 insertions(+), 38 deletions(-)
> 
> diff --git a/arch/x86/mm.c b/arch/x86/mm.c
> index cbb5617..f5248a4 100644
> --- a/arch/x86/mm.c
> +++ b/arch/x86/mm.c
> @@ -123,16 +123,25 @@ void arch_mm_preinit(void *p)
>   * table at offset in previous level MFN (pref_l_mfn). pt_pfn is a guest
>   * PFN.
>   */
> +static pgentry_t pt_prot[PAGETABLE_LEVELS] = {
> +    L1_PROT,
> +    L2_PROT,
> +    L3_PROT,
> +#if defined(__x86_64__)
> +    L4_PROT,
> +#endif
> +};
> +
>  static void new_pt_frame(unsigned long *pt_pfn, unsigned long prev_l_mfn, 
>                           unsigned long offset, unsigned long level)
>  {   
> -    pgentry_t *tab = pt_base;
> +    pgentry_t *tab;
>      unsigned long pt_page = (unsigned long)pfn_to_virt(*pt_pfn); 
> -    pgentry_t prot_e, prot_t;
> +#ifdef CONFIG_PARAVIRT
>      mmu_update_t mmu_updates[1];
>      int rc;
> +#endif
>      
> -    prot_e = prot_t = 0;
>      DEBUG("Allocating new L%d pt frame for pfn=%lx, "
>            "prev_l_mfn=%lx, offset=%lx", 
>            level, *pt_pfn, prev_l_mfn, offset);
> @@ -140,30 +149,12 @@ static void new_pt_frame(unsigned long *pt_pfn, unsigned long prev_l_mfn,
>      /* We need to clear the page, otherwise we might fail to map it
>         as a page table page */
>      memset((void*) pt_page, 0, PAGE_SIZE);  
> - 
> -    switch ( level )
> -    {
> -    case L1_FRAME:
> -        prot_e = L1_PROT;
> -        prot_t = L2_PROT;
> -        break;
> -    case L2_FRAME:
> -        prot_e = L2_PROT;
> -        prot_t = L3_PROT;
> -        break;
> -#if defined(__x86_64__)
> -    case L3_FRAME:
> -        prot_e = L3_PROT;
> -        prot_t = L4_PROT;
> -        break;
> -#endif
> -    default:
> -        printk("new_pt_frame() called with invalid level number %lu\n", level);
> -        do_exit();
> -        break;
> -    }
>  
> +    ASSERT(level >= 1 && level <= PAGETABLE_LEVELS);
> +
> +#ifdef CONFIG_PARAVIRT
>      /* Make PFN a page table page */
> +    tab = pt_base;
>  #if defined(__x86_64__)
>      tab = pte_to_virt(tab[l4_table_offset(pt_page)]);
>  #endif
> @@ -172,7 +163,7 @@ static void new_pt_frame(unsigned long *pt_pfn, unsigned long prev_l_mfn,
>      mmu_updates[0].ptr = (tab[l2_table_offset(pt_page)] & PAGE_MASK) + 
>          sizeof(pgentry_t) * l1_table_offset(pt_page);
>      mmu_updates[0].val = (pgentry_t)pfn_to_mfn(*pt_pfn) << PAGE_SHIFT | 
> -        (prot_e & ~_PAGE_RW);
> +        (pt_prot[level - 1] & ~_PAGE_RW);
>      
>      if ( (rc = HYPERVISOR_mmu_update(mmu_updates, 1, NULL, DOMID_SELF)) < 0 )
>      {
> @@ -184,13 +175,18 @@ static void new_pt_frame(unsigned long *pt_pfn, unsigned long prev_l_mfn,
>      /* Hook the new page table page into the hierarchy */
>      mmu_updates[0].ptr =
>          ((pgentry_t)prev_l_mfn << PAGE_SHIFT) + sizeof(pgentry_t) * offset;
> -    mmu_updates[0].val = (pgentry_t)pfn_to_mfn(*pt_pfn) << PAGE_SHIFT | prot_t;
> +    mmu_updates[0].val = (pgentry_t)pfn_to_mfn(*pt_pfn) << PAGE_SHIFT |
> +        pt_prot[level];
>  
>      if ( (rc = HYPERVISOR_mmu_update(mmu_updates, 1, NULL, DOMID_SELF)) < 0 ) 
>      {
>          printk("ERROR: mmu_update failed with rc=%d\n", rc);
>          do_exit();
>      }
> +#else
> +    tab = mfn_to_virt(prev_l_mfn);
> +    tab[offset] = (*pt_pfn << PAGE_SHIFT) | pt_prot[level];
> +#endif
>  
>      *pt_pfn += 1;
>  }
> @@ -202,12 +198,14 @@ static void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
>  {
>      unsigned long start_address, end_address;
>      unsigned long pfn_to_map, pt_pfn = *start_pfn;
> -    static mmu_update_t mmu_updates[L1_PAGETABLE_ENTRIES + 1];
>      pgentry_t *tab = pt_base, page;
>      unsigned long pt_mfn = pfn_to_mfn(virt_to_pfn(pt_base));
>      unsigned long offset;
> +#ifdef CONFIG_PARAVIRT
> +    static mmu_update_t mmu_updates[L1_PAGETABLE_ENTRIES + 1];
>      int count = 0;
>      int rc;
> +#endif
>  
>      /* Be conservative: even if we know there will be more pages already
>         mapped, start the loop at the very beginning. */
> @@ -225,6 +223,10 @@ static void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
>                 ((unsigned long)pfn_to_virt(*max_pfn) - 
>                  (unsigned long)&_text)>>20);
>      }
> +#else
> +    /* Round up to next 2MB boundary as we are using 2MB pages on HVMlite. */
> +    pfn_to_map = (pfn_to_map + L1_PAGETABLE_ENTRIES - 1) &
> +                 ~(L1_PAGETABLE_ENTRIES - 1);
>  #endif
>  
>      start_address = (unsigned long)pfn_to_virt(pfn_to_map);
> @@ -257,6 +259,7 @@ static void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
>          pt_mfn = pte_to_mfn(page);
>          tab = to_virt(mfn_to_pfn(pt_mfn) << PAGE_SHIFT);
>          offset = l2_table_offset(start_address);        
> +#ifdef CONFIG_PARAVIRT
>          /* Need new L1 pt frame */
>          if ( !(tab[offset] & _PAGE_PRESENT) )
>              new_pt_frame(&pt_pfn, pt_mfn, offset, L1_FRAME);
> @@ -288,6 +291,12 @@ static void build_pagetable(unsigned long *start_pfn, unsigned long *max_pfn)
>              count = 0;
>          }
>          start_address += PAGE_SIZE;
> +#else
> +        if ( !(tab[offset] & _PAGE_PRESENT) )
> +            tab[offset] = (pgentry_t)pfn_to_map << PAGE_SHIFT |
> +                          L2_PROT | _PAGE_PSE;
> +        start_address += 1UL << L2_PAGETABLE_SHIFT;
> +#endif
>      }
>  
>      *start_pfn = pt_pfn;
> @@ -302,16 +311,19 @@ static void set_readonly(void *text, void *etext)
>      unsigned long start_address =
>          ((unsigned long) text + PAGE_SIZE - 1) & PAGE_MASK;
>      unsigned long end_address = (unsigned long) etext;
> -    static mmu_update_t mmu_updates[L1_PAGETABLE_ENTRIES + 1];
>      pgentry_t *tab = pt_base, page;
>      unsigned long mfn = pfn_to_mfn(virt_to_pfn(pt_base));
>      unsigned long offset;
> +    unsigned long page_size = PAGE_SIZE;
> +#ifdef CONFIG_PARAVIRT
> +    static mmu_update_t mmu_updates[L1_PAGETABLE_ENTRIES + 1];
>      int count = 0;
>      int rc;
> +#endif
>  
>      printk("setting %p-%p readonly\n", text, etext);
>  
> -    while ( start_address + PAGE_SIZE <= end_address )
> +    while ( start_address + page_size <= end_address )
>      {
>          tab = pt_base;
>          mfn = pfn_to_mfn(virt_to_pfn(pt_base));
> @@ -327,26 +339,34 @@ static void set_readonly(void *text, void *etext)
>          mfn = pte_to_mfn(page);
>          tab = to_virt(mfn_to_pfn(mfn) << PAGE_SHIFT);
>          offset = l2_table_offset(start_address);        
> -        page = tab[offset];
> -        mfn = pte_to_mfn(page);
> -        tab = to_virt(mfn_to_pfn(mfn) << PAGE_SHIFT);
> +        if ( !(tab[offset] & _PAGE_PSE) )
> +        {
> +            page = tab[offset];
> +            mfn = pte_to_mfn(page);
> +            tab = to_virt(mfn_to_pfn(mfn) << PAGE_SHIFT);
>  
> -        offset = l1_table_offset(start_address);
> +            offset = l1_table_offset(start_address);
> +        }
>  
>          if ( start_address != (unsigned long)&shared_info )
>          {
> +#ifdef CONFIG_PARAVIRT
>              mmu_updates[count].ptr = 
>                  ((pgentry_t)mfn << PAGE_SHIFT) + sizeof(pgentry_t) * offset;
>              mmu_updates[count].val = tab[offset] & ~_PAGE_RW;
>              count++;
> +#else
> +            tab[offset] &= ~_PAGE_RW;
> +#endif
>          }
>          else
>              printk("skipped %lx\n", start_address);
>  
> -        start_address += PAGE_SIZE;
> +        start_address += page_size;
>  
> +#ifdef CONFIG_PARAVIRT
>          if ( count == L1_PAGETABLE_ENTRIES || 
> -             start_address + PAGE_SIZE > end_address )
> +             start_address + page_size > end_address )
>          {
>              rc = HYPERVISOR_mmu_update(mmu_updates, count, NULL, DOMID_SELF);
>              if ( rc < 0 )
> @@ -356,8 +376,13 @@ static void set_readonly(void *text, void *etext)
>              }
>              count = 0;
>          }
> +#else
> +        if ( start_address == (1UL << L2_PAGETABLE_SHIFT) )
> +            page_size = 1UL << L2_PAGETABLE_SHIFT;
> +#endif
>      }
>  
> +#ifdef CONFIG_PARAVIRT
>      {
>          mmuext_op_t op = {
>              .cmd = MMUEXT_TLB_FLUSH_ALL,
> @@ -365,6 +390,9 @@ static void set_readonly(void *text, void *etext)
>          int count;
>          HYPERVISOR_mmuext_op(&op, 1, &count, DOMID_SELF);
>      }
> +#else
> +    write_cr3((unsigned long)pt_base);
> +#endif
>  }
>  
>  /*
> @@ -394,6 +422,8 @@ static pgentry_t *get_pgt(unsigned long va)
>      offset = l2_table_offset(va);
>      if ( !(tab[offset] & _PAGE_PRESENT) )
>          return NULL;
> +    if ( tab[offset] & _PAGE_PSE )
> +        return &tab[offset];
>      mfn = pte_to_mfn(tab[offset]);
>      tab = mfn_to_virt(mfn);
>      offset = l1_table_offset(va);
> @@ -448,6 +478,9 @@ pgentry_t *need_pgt(unsigned long va)
>          new_pt_frame(&pt_pfn, pt_mfn, offset, L1_FRAME);
>      }
>      ASSERT(tab[offset] & _PAGE_PRESENT);
> +    if ( tab[offset] & _PAGE_PSE )
> +        return &tab[offset];
> +
>      pt_mfn = pte_to_mfn(tab[offset]);
>      tab = mfn_to_virt(pt_mfn);
>  
> @@ -524,8 +557,6 @@ int do_map_frames(unsigned long va,
>  {
>      pgentry_t *pgt = NULL;
>      unsigned long done = 0;
> -    unsigned long i;
> -    int rc;
>  
>      if ( !mfns ) 
>      {
> @@ -539,6 +570,9 @@ int do_map_frames(unsigned long va,
>          memset(err, 0x00, n * sizeof(int));
>      while ( done < n )
>      {
> +#ifdef CONFIG_PARAVIRT
> +        unsigned long i;
> +        int rc;
>          unsigned long todo;
>  
>          if ( err )
> @@ -578,6 +612,17 @@ int do_map_frames(unsigned long va,
>              }
>          }
>          done += todo;
> +#else
> +        if ( !pgt || !(va & L1_MASK) )
> +            pgt = need_pgt(va & ~L1_MASK);
> +        if ( !pgt )
> +            return -ENOMEM;
> +
> +        ASSERT(!(*pgt & _PAGE_PSE));
> +        pgt[l1_table_offset(va)] = (pgentry_t)
> +            (((mfns[done * stride] + done * incr) << PAGE_SHIFT) | prot);
> +        done++;
> +#endif
>      }
>  
>      return 0;
> @@ -609,16 +654,21 @@ void *map_frames_ex(const unsigned long *mfns, unsigned long n,
>  #define UNMAP_BATCH ((STACK_SIZE / 2) / sizeof(multicall_entry_t))
>  int unmap_frames(unsigned long va, unsigned long num_frames)
>  {
> +#ifdef CONFIG_PARAVIRT
>      int n = UNMAP_BATCH;
>      multicall_entry_t call[n];
>      int ret;
>      int i;
> +#else
> +    pgentry_t *pgt;
> +#endif
>  
>      ASSERT(!((unsigned long)va & ~PAGE_MASK));
>  
>      DEBUG("va=%p, num=0x%lx\n", va, num_frames);
>  
>      while ( num_frames ) {
> +#ifdef CONFIG_PARAVIRT
>          if ( n > num_frames )
>              n = num_frames;
>  
> @@ -653,6 +703,17 @@ int unmap_frames(unsigned long va, unsigned long num_frames)
>              }
>          }
>          num_frames -= n;
> +#else
> +        pgt = get_pgt(va);
> +        if ( pgt )
> +        {
> +            ASSERT(!(*pgt & _PAGE_PSE));
> +            *pgt = 0;
> +            invlpg(va);
> +        }
> +        va += PAGE_SIZE;
> +        num_frames--;
> +#endif
>      }
>      return 0;
>  }
> @@ -662,14 +723,24 @@ int unmap_frames(unsigned long va, unsigned long num_frames)
>   */
>  static void clear_bootstrap(void)
>  {
> +#ifdef CONFIG_PARAVIRT
>      pte_t nullpte = { };
>      int rc;
> +#else
> +    pgentry_t *pgt;
> +#endif
>  
>      /* Use first page as the CoW zero page */
>      memset(&_text, 0, PAGE_SIZE);
>      mfn_zero = virt_to_mfn((unsigned long) &_text);
> +#ifdef CONFIG_PARAVIRT
>      if ( (rc = HYPERVISOR_update_va_mapping(0, nullpte, UVMF_INVLPG)) )
>          printk("Unable to unmap NULL page. rc=%d\n", rc);
> +#else
> +    pgt = get_pgt((unsigned long)&_text);
> +    *pgt = 0;
> +    invlpg((unsigned long)&_text);
> +#endif
>  }
>  
>  #ifdef CONFIG_PARAVIRT
> diff --git a/arch/x86/traps.c b/arch/x86/traps.c
> index 2d3222d..aa17da3 100644
> --- a/arch/x86/traps.c
> +++ b/arch/x86/traps.c
> @@ -121,7 +121,9 @@ void page_walk(unsigned long virt_address)
>  static int handle_cow(unsigned long addr) {
>          pgentry_t *tab = pt_base, page;
>  	unsigned long new_page;
> +#ifdef CONFIG_PARAVIRT
>  	int rc;
> +#endif
>  
>  #if defined(__x86_64__)
>          page = tab[l4_table_offset(addr)];
> @@ -137,6 +139,8 @@ static int handle_cow(unsigned long addr) {
>          page = tab[l2_table_offset(addr)];
>  	if (!(page & _PAGE_PRESENT))
>  	    return 0;
> +	if ( page & _PAGE_PSE )
> +	    return 0;
>          tab = pte_to_virt(page);
>          
>          page = tab[l1_table_offset(addr)];
> @@ -149,12 +153,18 @@ static int handle_cow(unsigned long addr) {
>  	new_page = alloc_pages(0);
>  	memset((void*) new_page, 0, PAGE_SIZE);
>  
> +#ifdef CONFIG_PARAVIRT
>  	rc = HYPERVISOR_update_va_mapping(addr & PAGE_MASK, __pte(virt_to_mach(new_page) | L1_PROT), UVMF_INVLPG);
>  	if (!rc)
>  		return 1;
>  
>  	printk("Map zero page to %lx failed: %d.\n", addr, rc);
>  	return 0;
> +#else
> +	tab[l1_table_offset(addr)] = virt_to_mach(new_page) | L1_PROT;
> +	invlpg(addr);
> +	return 1;
> +#endif
>  }
>  
>  static void do_stack_walk(unsigned long frame_base)
> diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h
> index 28ab406..e0ae552 100644
> --- a/include/x86/arch_mm.h
> +++ b/include/x86/arch_mm.h
> @@ -78,6 +78,8 @@
>  #define L2_PAGETABLE_ENTRIES    512
>  #define L3_PAGETABLE_ENTRIES    4
>  
> +#define PAGETABLE_LEVELS        3
> +
>  #define PADDR_BITS              44
>  #define PADDR_MASK              ((1ULL << PADDR_BITS)-1)
>  
> @@ -110,6 +112,8 @@ typedef uint64_t pgentry_t;
>  #define L3_PAGETABLE_ENTRIES    512
>  #define L4_PAGETABLE_ENTRIES    512
>  
> +#define PAGETABLE_LEVELS        4
> +
>  /* These are page-table limitations. Current CPUs support only 40-bit phys. */
>  #define PADDR_BITS              52
>  #define VADDR_BITS              48
> diff --git a/include/x86/os.h b/include/x86/os.h
> index 1083328..20cc27f 100644
> --- a/include/x86/os.h
> +++ b/include/x86/os.h
> @@ -206,6 +206,15 @@ static inline int irqs_disabled(void)
>   */
>  typedef struct { volatile int counter; } atomic_t;
>  
> +static inline void write_cr3(unsigned long cr3)
> +{
> +    asm volatile( "mov %0, %%cr3" : : "r" (cr3) : "memory" );
> +}
> +
> +static inline void invlpg(unsigned long va)
> +{
> +    asm volatile ( "invlpg %0": : "m" (*(const char *)(va)) : "memory" );
> +}
>  
>  /************************** i386 *******************************/
>  #ifdef __INSIDE_MINIOS__
> -- 
> 2.6.6
> 

-- 
Samuel
	/* Amuse the user. */
	printk(
"              \\|/ ____ \\|/\n"
"              \"@'/ ,. \\`@\"\n"
"              /_| \\__/ |_\\\n"
"                 \\__U_/\n");
(From linux/arch/sparc/kernel/traps.c:die_if_kernel())

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 14/22] mini-os: add map_frame_virt() function
  2016-08-23 15:16 ` [PATCH 14/22] mini-os: add map_frame_virt() function Juergen Gross
@ 2016-08-23 22:42   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 22:42 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:16:00 +0200, wrote:
> Add a function map_frame_virt() to map a given frame and return its
> virtual address.
> 
> On arm we just use the frame physical address, while on x86 we take a
> page from the virtual kernel area. For this purpose make this area
> available even in case of undefined CONFIG_BALLOON.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/arm/balloon.c    |  2 --
>  arch/arm/mm.c         |  5 +++++
>  arch/x86/balloon.c    | 13 ++++---------
>  arch/x86/mm.c         | 23 +++++++++++++++++++++++
>  balloon.c             |  9 ++++-----
>  include/balloon.h     |  1 -
>  include/mm.h          |  1 +
>  include/x86/arch_mm.h |  1 +
>  8 files changed, 38 insertions(+), 17 deletions(-)
> 
> diff --git a/arch/arm/balloon.c b/arch/arm/balloon.c
> index 958ecba..1df7d1c 100644
> --- a/arch/arm/balloon.c
> +++ b/arch/arm/balloon.c
> @@ -25,8 +25,6 @@
>  
>  #ifdef CONFIG_BALLOON
>  
> -unsigned long virt_kernel_area_end;   /* TODO: find a virtual area */
> -
>  void arch_pfn_add(unsigned long pfn, unsigned long mfn)
>  {
>  }
> diff --git a/arch/arm/mm.c b/arch/arm/mm.c
> index 4f58fc7..dbde162 100644
> --- a/arch/arm/mm.c
> +++ b/arch/arm/mm.c
> @@ -141,3 +141,8 @@ grant_entry_t *arch_init_gnttab(int nr_grant_frames)
>  
>      return to_virt(gnttab_table);
>  }
> +
> +unsigned long map_frame_virt(unsigned long mfn)
> +{
> +    return mfn_to_virt(mfn);
> +}
> diff --git a/arch/x86/balloon.c b/arch/x86/balloon.c
> index 16aaae4..10b440c 100644
> --- a/arch/x86/balloon.c
> +++ b/arch/x86/balloon.c
> @@ -29,9 +29,6 @@
>  #include <mini-os/paravirt.h>
>  
>  #ifdef CONFIG_BALLOON
> -
> -unsigned long virt_kernel_area_end = VIRT_KERNEL_AREA;
> -
>  #ifdef CONFIG_PARAVIRT
>  static void p2m_invalidate(unsigned long *list, unsigned long start_idx)
>  {
> @@ -53,7 +50,7 @@ static inline unsigned long *p2m_to_virt(unsigned long p2m)
>  
>  void arch_remap_p2m(unsigned long max_pfn)
>  {
> -    unsigned long pfn;
> +    unsigned long pfn, new_p2m;
>      unsigned long *l3_list, *l2_list, *l1_list;
>  
>      l3_list = p2m_l3list();
> @@ -67,17 +64,15 @@ void arch_remap_p2m(unsigned long max_pfn)
>      if ( p2m_pages(nr_max_pages) <= p2m_pages(max_pfn) )
>          return;
>  
> +    new_p2m = alloc_virt_kernel(p2m_pages(nr_max_pages));
>      for ( pfn = 0; pfn < max_pfn; pfn += P2M_ENTRIES )
>      {
> -        map_frame_rw(virt_kernel_area_end + PAGE_SIZE * (pfn / P2M_ENTRIES),
> +        map_frame_rw(new_p2m + PAGE_SIZE * (pfn / P2M_ENTRIES),
>                       virt_to_mfn(phys_to_machine_mapping + pfn));
>      }
>  
> -    phys_to_machine_mapping = (unsigned long *)virt_kernel_area_end;
> +    phys_to_machine_mapping = (unsigned long *)new_p2m;
>      printk("remapped p2m list to %p\n", phys_to_machine_mapping);
> -
> -    virt_kernel_area_end += PAGE_SIZE * p2m_pages(nr_max_pages);
> -    ASSERT(virt_kernel_area_end <= VIRT_DEMAND_AREA);
>  }
>  
>  int arch_expand_p2m(unsigned long max_pfn)
> diff --git a/arch/x86/mm.c b/arch/x86/mm.c
> index f5248a4..762599d 100644
> --- a/arch/x86/mm.c
> +++ b/arch/x86/mm.c
> @@ -57,6 +57,7 @@ unsigned long mfn_zero;
>  pgentry_t *pt_base;
>  static unsigned long first_free_pfn;
>  static unsigned long last_free_pfn;
> +static unsigned long virt_kernel_area_end = VIRT_KERNEL_AREA;
>  
>  extern char stack[];
>  extern void page_walk(unsigned long va);
> @@ -829,3 +830,25 @@ grant_entry_t *arch_init_gnttab(int nr_grant_frames)
>      HYPERVISOR_grant_table_op(GNTTABOP_setup_table, &setup, 1);
>      return map_frames(frames, nr_grant_frames);
>  }
> +
> +unsigned long alloc_virt_kernel(unsigned n_pages)
> +{
> +    unsigned long addr;
> +
> +    addr = virt_kernel_area_end;
> +    virt_kernel_area_end += PAGE_SIZE * n_pages;
> +    ASSERT(virt_kernel_area_end <= VIRT_DEMAND_AREA);
> +
> +    return addr;
> +}
> +
> +unsigned long map_frame_virt(unsigned long mfn)
> +{
> +    unsigned long addr;
> +
> +    addr = alloc_virt_kernel(1);
> +    if ( map_frame_rw(addr, mfn) )
> +        return 0;
> +
> +    return addr;
> +}
> diff --git a/balloon.c b/balloon.c
> index 8669edb..b0d0230 100644
> --- a/balloon.c
> +++ b/balloon.c
> @@ -50,20 +50,19 @@ void get_max_pages(void)
>  
>  void mm_alloc_bitmap_remap(void)
>  {
> -    unsigned long i;
> +    unsigned long i, new_bitmap;
>  
>      if ( mm_alloc_bitmap_size >= ((nr_max_pages + 1) >> 3) )
>          return;
>  
> +    new_bitmap = alloc_virt_kernel(PFN_UP((nr_max_pages + 1) >> 3));
>      for ( i = 0; i < mm_alloc_bitmap_size; i += PAGE_SIZE )
>      {
> -        map_frame_rw(virt_kernel_area_end + i,
> +        map_frame_rw(new_bitmap + i,
>                       virt_to_mfn((unsigned long)(mm_alloc_bitmap) + i));
>      }
>  
> -    mm_alloc_bitmap = (unsigned long *)virt_kernel_area_end;
> -    virt_kernel_area_end += round_pgup((nr_max_pages + 1) >> 3);
> -    ASSERT(virt_kernel_area_end <= VIRT_DEMAND_AREA);
> +    mm_alloc_bitmap = (unsigned long *)new_bitmap;
>  }
>  
>  #define N_BALLOON_FRAMES 64
> diff --git a/include/balloon.h b/include/balloon.h
> index 8cd41af..6cfec4f 100644
> --- a/include/balloon.h
> +++ b/include/balloon.h
> @@ -33,7 +33,6 @@
>  #define BALLOON_EMERGENCY_PAGES   64
>  
>  extern unsigned long nr_max_pages;
> -extern unsigned long virt_kernel_area_end;
>  extern unsigned long nr_mem_pages;
>  
>  void get_max_pages(void);
> diff --git a/include/mm.h b/include/mm.h
> index 953570c..4fc364f 100644
> --- a/include/mm.h
> +++ b/include/mm.h
> @@ -79,6 +79,7 @@ int do_map_frames(unsigned long addr,
>  	unsigned long increment, domid_t id, int *err, unsigned long prot);
>  int unmap_frames(unsigned long va, unsigned long num_frames);
>  int map_frame_rw(unsigned long addr, unsigned long mfn);
> +unsigned long map_frame_virt(unsigned long mfn);
>  #ifdef HAVE_LIBC
>  extern unsigned long heap, brk, heap_mapped, heap_end;
>  #endif
> diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h
> index e0ae552..9372f1e 100644
> --- a/include/x86/arch_mm.h
> +++ b/include/x86/arch_mm.h
> @@ -277,6 +277,7 @@ static __inline__ paddr_t machine_to_phys(maddr_t machine)
>  
>  pgentry_t *need_pgt(unsigned long addr);
>  void arch_mm_preinit(void *p);
> +unsigned long alloc_virt_kernel(unsigned n_pages);
>  
>  #endif
>  
> -- 
> 2.6.6
> 

-- 
Samuel
After watching my newly-retired dad spend two weeks learning how to make a new
folder, it became obvious that "intuitive" mostly means "what the writer or
speaker of intuitive likes".
(Bruce Ediger, bediger@teal.csn.org, in comp.os.linux.misc, on X the
intuitiveness of a Mac interface.)

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 15/22] mini-os: setup console interface parameters
  2016-08-23 15:16 ` [PATCH 15/22] mini-os: setup console interface parameters Juergen Gross
@ 2016-08-23 22:44   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 22:44 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:16:01 +0200, wrote:
> In order to support HVMlite we need to get the ring page and event
> channel from the hypervisor via hypercalls. Move the already existing
> get_console() function from arm specific coding to
> console/xencons_ring.c and provide a similar paravirtualized function.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/arm/setup.c       | 16 +---------------
>  arch/x86/setup.c       |  1 +
>  console/xencons_ring.c | 38 ++++++++++++++++++++++++++++++--------
>  events.c               |  2 +-
>  include/console.h      |  3 ++-
>  5 files changed, 35 insertions(+), 25 deletions(-)
> 
> diff --git a/arch/arm/setup.c b/arch/arm/setup.c
> index cbe67c6..a021616 100644
> --- a/arch/arm/setup.c
> +++ b/arch/arm/setup.c
> @@ -25,20 +25,6 @@ extern char shared_info_page[PAGE_SIZE];
>  
>  void *device_tree;
>  
> -static void get_console(void)
> -{
> -    uint64_t v = -1;
> -
> -    hvm_get_parameter(HVM_PARAM_CONSOLE_EVTCHN, &v);
> -    start_info.console.domU.evtchn = v;
> -
> -    hvm_get_parameter(HVM_PARAM_CONSOLE_PFN, &v);
> -    start_info.console.domU.mfn = v;
> -
> -    printk("Console is on port %d\n", start_info.console.domU.evtchn);
> -    printk("Console ring is at mfn %lx\n", (unsigned long) start_info.console.domU.mfn);
> -}
> -
>  void get_xenbus(void)
>  {
>      uint64_t value;
> @@ -85,7 +71,7 @@ void arch_init(void *dtb_pointer, uint32_t physical_offset)
>      HYPERVISOR_shared_info = (struct shared_info *)shared_info_page;
>  
>      /* Fill in start_info */
> -    get_console();
> +    get_console(NULL);
>      get_xenbus();
>  
>      gic_init();
> diff --git a/arch/x86/setup.c b/arch/x86/setup.c
> index 8b6bb6e..0c1f2ec 100644
> --- a/arch/x86/setup.c
> +++ b/arch/x86/setup.c
> @@ -137,6 +137,7 @@ arch_init(void *par)
>  	/* Copy the start_info struct to a globally-accessible area. */
>  	/* WARN: don't do printk before here, it uses information from
>  	   shared_info. Use xprintk instead. */
> +	get_console(par);
>  	si = par;
>  	memcpy(&start_info, si, sizeof(*si));
>  
> diff --git a/console/xencons_ring.c b/console/xencons_ring.c
> index 81c8e99..dd64a41 100644
> --- a/console/xencons_ring.c
> +++ b/console/xencons_ring.c
> @@ -9,27 +9,49 @@
>  #include <xen/io/console.h>
>  #include <xen/io/protocols.h>
>  #include <xen/io/ring.h>
> +#include <xen/hvm/params.h>
>  #include <mini-os/xmalloc.h>
>  #include <mini-os/gnttab.h>
>  #include "console.h"
>  
>  DECLARE_WAIT_QUEUE_HEAD(console_queue);
>  
> +static struct xencons_interface *console_ring;
> +uint32_t console_evtchn;
> +
> +#ifdef CONFIG_PARAVIRT
> +void get_console(void *p)
> +{
> +    start_info_t *si = p;
> +
> +    console_ring = mfn_to_virt(si->console.domU.mfn);
> +    console_evtchn = si->console.domU.evtchn;
> +}
> +#else
> +void get_console(void *p)
> +{
> +    uint64_t v = -1;
> +
> +    hvm_get_parameter(HVM_PARAM_CONSOLE_EVTCHN, &v);
> +    console_evtchn = v;
> +
> +    hvm_get_parameter(HVM_PARAM_CONSOLE_PFN, &v);
> +    console_ring = (struct xencons_interface *)map_frame_virt(v);
> +}
> +#endif
> +
>  static inline void notify_daemon(struct consfront_dev *dev)
>  {
>      /* Use evtchn: this is called early, before irq is set up. */
>      if (!dev)
> -        notify_remote_via_evtchn(start_info.console.domU.evtchn);
> +        notify_remote_via_evtchn(console_evtchn);
>      else
>          notify_remote_via_evtchn(dev->evtchn);
>  }
>  
>  static inline struct xencons_interface *xencons_interface(void)
>  {
> -    if (start_info.console.domU.evtchn)
> -        return mfn_to_virt(start_info.console.domU.mfn);
> -    else
> -        return NULL;
> +    return console_evtchn ? console_ring : NULL;
>  } 
>   
>  int xencons_ring_send_no_notify(struct consfront_dev *dev, const char *data, unsigned len)
> @@ -158,7 +180,7 @@ struct consfront_dev *xencons_ring_init(void)
>  	int err;
>  	struct consfront_dev *dev;
>  
> -	if (!start_info.console.domU.evtchn)
> +	if (!console_evtchn)
>  		return 0;
>  
>  	dev = malloc(sizeof(struct consfront_dev));
> @@ -171,8 +193,8 @@ struct consfront_dev *xencons_ring_init(void)
>  #ifdef HAVE_LIBC
>  	dev->fd = -1;
>  #endif
> -	dev->evtchn = start_info.console.domU.evtchn;
> -	dev->ring = (struct xencons_interface *) mfn_to_virt(start_info.console.domU.mfn);
> +	dev->evtchn = console_evtchn;
> +	dev->ring = xencons_interface();
>  
>  	err = bind_evtchn(dev->evtchn, console_handle_input, dev);
>  	if (err <= 0) {
> diff --git a/events.c b/events.c
> index 2a23042..76ea617 100644
> --- a/events.c
> +++ b/events.c
> @@ -46,7 +46,7 @@ void unbind_all_ports(void)
>  
>      for ( i = 0; i < NR_EVS; i++ )
>      {
> -        if ( i == start_info.console.domU.evtchn ||
> +        if ( i == console_evtchn ||
>               i == start_info.store_evtchn)
>              continue;
>  
> diff --git a/include/console.h b/include/console.h
> index a77f47f..eb327a8 100644
> --- a/include/console.h
> +++ b/include/console.h
> @@ -61,7 +61,7 @@ struct consfront_dev {
>  #endif
>  };
>  
> -
> +extern uint32_t console_evtchn;
>  
>  void print(int direct, const char *fmt, va_list args);
>  void printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
> @@ -72,6 +72,7 @@ void xprintk(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
>  void xencons_rx(char *buf, unsigned len, struct pt_regs *regs);
>  void xencons_tx(void);
>  
> +void get_console(void *p);
>  void init_console(void);
>  void console_print(struct consfront_dev *dev, char *data, int length);
>  void fini_console(struct consfront_dev *dev);
> -- 
> 2.6.6
> 

-- 
Samuel
	/* Amuse the user. */
	printk(
"              \\|/ ____ \\|/\n"
"              \"@'/ ,. \\`@\"\n"
"              /_| \\__/ |_\\\n"
"                 \\__U_/\n");
(From linux/arch/sparc/kernel/traps.c:die_if_kernel())

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 16/22] mini-os: setup xenbus interface parameters
  2016-08-23 15:16 ` [PATCH 16/22] mini-os: setup xenbus " Juergen Gross
@ 2016-08-23 22:45   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 22:45 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:16:02 +0200, wrote:
> In order to support HVMlite we need to get the ring page and event
> channel from the hypervisor via hypercalls. Move the already existing
> get_xenbus() function from arm specific coding to xenbus/xenbus.c and
> provide a similar paravirtualized function.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/arm/setup.c | 16 +---------------
>  arch/x86/setup.c |  1 +
>  events.c         |  3 +--
>  include/xenbus.h |  3 +++
>  xenbus/xenbus.c  | 40 +++++++++++++++++++++++++++++++---------
>  5 files changed, 37 insertions(+), 26 deletions(-)
> 
> diff --git a/arch/arm/setup.c b/arch/arm/setup.c
> index a021616..72e025a 100644
> --- a/arch/arm/setup.c
> +++ b/arch/arm/setup.c
> @@ -25,20 +25,6 @@ extern char shared_info_page[PAGE_SIZE];
>  
>  void *device_tree;
>  
> -void get_xenbus(void)
> -{
> -    uint64_t value;
> -
> -    if (hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &value))
> -        BUG();
> -
> -    start_info.store_evtchn = (int)value;
> -
> -    if(hvm_get_parameter(HVM_PARAM_STORE_PFN, &value))
> -        BUG();
> -    start_info.store_mfn = (unsigned long)value;
> -}
> -
>  /*
>   * INITIAL C ENTRY POINT.
>   */
> @@ -72,7 +58,7 @@ void arch_init(void *dtb_pointer, uint32_t physical_offset)
>  
>      /* Fill in start_info */
>      get_console(NULL);
> -    get_xenbus();
> +    get_xenbus(NULL);
>  
>      gic_init();
>  
> diff --git a/arch/x86/setup.c b/arch/x86/setup.c
> index 0c1f2ec..6645784 100644
> --- a/arch/x86/setup.c
> +++ b/arch/x86/setup.c
> @@ -138,6 +138,7 @@ arch_init(void *par)
>  	/* WARN: don't do printk before here, it uses information from
>  	   shared_info. Use xprintk instead. */
>  	get_console(par);
> +	get_xenbus(par);
>  	si = par;
>  	memcpy(&start_info, si, sizeof(*si));
>  
> diff --git a/events.c b/events.c
> index 76ea617..e8ef8aa 100644
> --- a/events.c
> +++ b/events.c
> @@ -46,8 +46,7 @@ void unbind_all_ports(void)
>  
>      for ( i = 0; i < NR_EVS; i++ )
>      {
> -        if ( i == console_evtchn ||
> -             i == start_info.store_evtchn)
> +        if ( i == console_evtchn || i == xenbus_evtchn )
>              continue;
>  
>          if ( test_and_clear_bit(i, bound_ports) )
> diff --git a/include/xenbus.h b/include/xenbus.h
> index d3bb7af..5646a25 100644
> --- a/include/xenbus.h
> +++ b/include/xenbus.h
> @@ -29,6 +29,9 @@ struct xenbus_event {
>  };
>  typedef struct xenbus_event *xenbus_event_queue;
>  
> +extern uint32_t xenbus_evtchn;
> +
> +void get_xenbus(void *p);
>  char *xenbus_watch_path_token(xenbus_transaction_t xbt, const char *path, const char *token, xenbus_event_queue *events);
>  char *xenbus_unwatch_path_token(xenbus_transaction_t xbt, const char *path, const char *token);
>  extern struct wait_queue_head xenbus_watch_queue;
> diff --git a/xenbus/xenbus.c b/xenbus/xenbus.c
> index 0ab387a..636786c 100644
> --- a/xenbus/xenbus.c
> +++ b/xenbus/xenbus.c
> @@ -26,6 +26,7 @@
>  #include <mini-os/sched.h>
>  #include <mini-os/wait.h>
>  #include <xen/io/xs_wire.h>
> +#include <xen/hvm/params.h>
>  #include <mini-os/spinlock.h>
>  #include <mini-os/xmalloc.h>
>  
> @@ -62,6 +63,31 @@ struct xenbus_req_info
>  #define NR_REQS 32
>  static struct xenbus_req_info req_info[NR_REQS];
>  
> +uint32_t xenbus_evtchn;
> +
> +#ifdef CONFIG_PARAVIRT
> +void get_xenbus(void *p)
> +{
> +    start_info_t *si = p;
> +
> +    xenbus_evtchn = si->store_evtchn;
> +    xenstore_buf = mfn_to_virt(si->store_mfn);
> +}
> +#else
> +void get_xenbus(void *p)
> +{
> +    uint64_t v;
> +
> +    if ( hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v) )
> +        BUG();
> +    xenbus_evtchn = v;
> +
> +    if( hvm_get_parameter(HVM_PARAM_STORE_PFN, &v) )
> +        BUG();
> +    xenstore_buf = (struct xenstore_domain_interface *)map_frame_virt(v);
> +}
> +#endif
> +
>  static void memcpy_from_ring(const void *Ring,
>          void *Dest,
>          int off,
> @@ -269,7 +295,7 @@ static void xenbus_thread_func(void *ign)
>              }
>  
>              wmb();
> -            notify_remote_via_evtchn(start_info.store_evtchn);
> +            notify_remote_via_evtchn(xenbus_evtchn);
>          }
>      }
>  }
> @@ -335,15 +361,11 @@ void init_xenbus(void)
>  {
>      int err;
>      DEBUG("init_xenbus called.\n");
> -    xenstore_buf = mfn_to_virt(start_info.store_mfn);
>      create_thread("xenstore", xenbus_thread_func, NULL);
>      DEBUG("buf at %p.\n", xenstore_buf);
> -    err = bind_evtchn(start_info.store_evtchn,
> -		      xenbus_evtchn_handler,
> -              NULL);
> -    unmask_evtchn(start_info.store_evtchn);
> -    printk("xenbus initialised on irq %d mfn %#llx\n",
> -	   err, (unsigned long long) start_info.store_mfn);
> +    err = bind_evtchn(xenbus_evtchn, xenbus_evtchn_handler, NULL);
> +    unmask_evtchn(xenbus_evtchn);
> +    printk("xenbus initialised on irq %d\n", err);
>  }
>  
>  void fini_xenbus(void)
> @@ -425,7 +447,7 @@ static void xb_write(int type, int req_id, xenbus_transaction_t trans_id,
>      xenstore_buf->req_prod += len;
>  
>      /* Send evtchn to notify remote */
> -    notify_remote_via_evtchn(start_info.store_evtchn);
> +    notify_remote_via_evtchn(xenbus_evtchn);
>  }
>  
>  /* Send a mesasge to xenbus, in the same fashion as xb_write, and
> -- 
> 2.6.6
> 

-- 
Samuel
"...[Linux's] capacity to talk via any medium except smoke signals."
(By Dr. Greg Wettstein, Roger Maris Cancer Center)

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 18/22] mini-os: map shared info page for HVMlite
  2016-08-23 15:16 ` [PATCH 18/22] mini-os: map shared info page for HVMlite Juergen Gross
@ 2016-08-23 22:47   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 22:47 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:16:04 +0200, wrote:
> Add a service function to map the shared info page on a
> non-paravirtualized system. The code is already existing on ARM side,
> just move it to hypervisor.c.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/arm/arm32.S     |  4 ++--
>  arch/arm/setup.c     | 11 +----------
>  arch/x86/setup.c     | 38 ++++++++++++++++++++------------------
>  hypervisor.c         | 17 +++++++++++++++++
>  include/hypervisor.h |  1 +
>  5 files changed, 41 insertions(+), 30 deletions(-)
> 
> diff --git a/arch/arm/arm32.S b/arch/arm/arm32.S
> index a08a170..bcaca17 100644
> --- a/arch/arm/arm32.S
> +++ b/arch/arm/arm32.S
> @@ -151,8 +151,8 @@ stage2:
>  .pushsection .bss
>  @ Note: calling arch_init zeroes out this region.
>  .align 12
> -.globl shared_info_page
> -shared_info_page:
> +.globl shared_info
> +shared_info:
>  	.fill (1024), 4, 0x0
>  
>  .align 3
> diff --git a/arch/arm/setup.c b/arch/arm/setup.c
> index 72e025a..05b405b 100644
> --- a/arch/arm/setup.c
> +++ b/arch/arm/setup.c
> @@ -21,8 +21,6 @@ union start_info_union start_info_union;
>   */
>  shared_info_t *HYPERVISOR_shared_info;
>  
> -extern char shared_info_page[PAGE_SIZE];
> -
>  void *device_tree;
>  
>  /*
> @@ -30,7 +28,6 @@ void *device_tree;
>   */
>  void arch_init(void *dtb_pointer, uint32_t physical_offset)
>  {
> -    struct xen_add_to_physmap xatp;
>      int r;
>  
>      memset(&__bss_start, 0, &_end - &__bss_start);
> @@ -48,13 +45,7 @@ void arch_init(void *dtb_pointer, uint32_t physical_offset)
>      device_tree = dtb_pointer;
>  
>      /* Map shared_info page */
> -    xatp.domid = DOMID_SELF;
> -    xatp.idx = 0;
> -    xatp.space = XENMAPSPACE_shared_info;
> -    xatp.gpfn = virt_to_pfn(shared_info_page);
> -    if (HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp) != 0)
> -        BUG();
> -    HYPERVISOR_shared_info = (struct shared_info *)shared_info_page;
> +    HYPERVISOR_shared_info = map_shared_info(NULL);
>  
>      /* Fill in start_info */
>      get_console(NULL);
> diff --git a/arch/x86/setup.c b/arch/x86/setup.c
> index 13633f0..278e88f 100644
> --- a/arch/x86/setup.c
> +++ b/arch/x86/setup.c
> @@ -60,20 +60,6 @@ extern char shared_info[PAGE_SIZE];
>      ((pte_t) {(unsigned long)(_x), (unsigned long)(_x>>32)}); })
>  #endif
>  
> -static
> -shared_info_t *map_shared_info(unsigned long pa)
> -{
> -    int rc;
> -
> -	if ( (rc = HYPERVISOR_update_va_mapping(
> -              (unsigned long)shared_info, __pte(pa | 7), UVMF_INVLPG)) )
> -	{
> -		printk("Failed to map shared_info!! rc=%d\n", rc);
> -		do_exit();
> -	}
> -	return (shared_info_t *)shared_info;
> -}
> -
>  static inline void fpu_init(void) {
>  	asm volatile("fninit");
>  }
> @@ -90,6 +76,21 @@ static inline void sse_init(void) {
>  #ifdef CONFIG_PARAVIRT
>  #define hpc_init()
>  
> +shared_info_t *map_shared_info(void *p)
> +{
> +    int rc;
> +    start_info_t *si = p;
> +    unsigned long pa = si->shared_info;
> +
> +    if ( (rc = HYPERVISOR_update_va_mapping((unsigned long)shared_info,
> +                                            __pte(pa | 7), UVMF_INVLPG)) )
> +    {
> +        printk("Failed to map shared_info!! rc=%d\n", rc);
> +        do_exit();
> +    }
> +    return (shared_info_t *)shared_info;
> +}
> +
>  static void get_cmdline(void *p)
>  {
>      start_info_t *si = p;
> @@ -156,6 +157,10 @@ arch_init(void *par)
>  	get_console(par);
>  	get_xenbus(par);
>  	get_cmdline(par);
> +
> +	/* Grab the shared_info pointer and put it in a safe place. */
> +	HYPERVISOR_shared_info = map_shared_info(par);
> +
>  	si = par;
>  	memcpy(&start_info, si, sizeof(*si));
>  
> @@ -163,7 +168,7 @@ arch_init(void *par)
>  	printk("Xen Minimal OS!\n");
>  	printk("  start_info: %p(VA)\n", si);
>  	printk("    nr_pages: 0x%lx\n", si->nr_pages);
> -	printk("  shared_inf: 0x%08lx(MA)\n", si->shared_info);
> +	printk("  shared_inf: %p(VA)\n", HYPERVISOR_shared_info);
>  	printk("     pt_base: %p(VA)\n", (void *)si->pt_base);
>  	printk("nr_pt_frames: 0x%lx\n", si->nr_pt_frames);
>  	printk("    mfn_list: %p(VA)\n", (void *)si->mfn_list);
> @@ -173,9 +178,6 @@ arch_init(void *par)
>  	printk("    cmd_line: %s\n", cmdline);
>  	printk("       stack: %p-%p\n", stack, stack + sizeof(stack));
>  
> -	/* Grab the shared_info pointer and put it in a safe place. */
> -	HYPERVISOR_shared_info = map_shared_info(start_info.shared_info);
> -
>  	start_kernel();
>  }
>  
> diff --git a/hypervisor.c b/hypervisor.c
> index 715cfe8..1647121 100644
> --- a/hypervisor.c
> +++ b/hypervisor.c
> @@ -29,6 +29,7 @@
>  #include <mini-os/lib.h>
>  #include <mini-os/hypervisor.h>
>  #include <mini-os/events.h>
> +#include <xen/memory.h>
>  
>  #define active_evtchns(cpu,sh,idx)              \
>      ((sh)->evtchn_pending[idx] &                \
> @@ -37,6 +38,8 @@
>  int in_callback;
>  
>  #ifndef CONFIG_PARAVIRT
> +extern shared_info_t shared_info;
> +
>  int hvm_get_parameter(int idx, uint64_t *value)
>  {
>      struct xen_hvm_param xhv;
> @@ -61,6 +64,20 @@ int hvm_set_parameter(int idx, uint64_t value)
>      xhv.value = value;
>      return HYPERVISOR_hvm_op(HVMOP_set_param, &xhv);
>  }
> +
> +shared_info_t *map_shared_info(void *p)
> +{
> +    struct xen_add_to_physmap xatp;
> +
> +    xatp.domid = DOMID_SELF;
> +    xatp.idx = 0;
> +    xatp.space = XENMAPSPACE_shared_info;
> +    xatp.gpfn = virt_to_pfn(&shared_info);
> +    if ( HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp) != 0 )
> +        BUG();
> +
> +    return &shared_info;
> +}
>  #endif
>  
>  void do_hypervisor_callback(struct pt_regs *regs)
> diff --git a/include/hypervisor.h b/include/hypervisor.h
> index 6e421b1..7c44702 100644
> --- a/include/hypervisor.h
> +++ b/include/hypervisor.h
> @@ -42,6 +42,7 @@ extern union start_info_union start_info_union;
>  int hvm_get_parameter(int idx, uint64_t *value);
>  int hvm_set_parameter(int idx, uint64_t value);
>  #endif
> +shared_info_t *map_shared_info(void *p);
>  void force_evtchn_callback(void);
>  void do_hypervisor_callback(struct pt_regs *regs);
>  void mask_evtchn(uint32_t port);
> -- 
> 2.6.6
> 

-- 
Samuel
<m> bouhouhouh, b il m'a abandonné. Tout ca parce que je regardais plus mon emacs que lui !
<m> s/lui/ses messages irc/
 -+- #ens-mim esseulé -+-

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 19/22] mini-os: remove using start_info in architecture independent code
  2016-08-23 15:16 ` [PATCH 19/22] mini-os: remove using start_info in architecture independent code Juergen Gross
@ 2016-08-23 22:48   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 22:48 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:16:05 +0200, wrote:
> The start_info structure should be used only in case of CONFIG_PARAVIRT
> defined. Remove it from being used in other places. Especially the
> usage as parameter for applications linked to the kernel is no good
> idea.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/arm/setup.c     |  8 --------
>  arch/x86/setup.c     |  8 --------
>  daytime.c            |  2 +-
>  include/hypervisor.h | 11 -----------
>  kernel.c             |  6 +++---
>  main.c               |  6 +++---
>  test.c               | 20 ++++++++++----------
>  7 files changed, 17 insertions(+), 44 deletions(-)
> 
> diff --git a/arch/arm/setup.c b/arch/arm/setup.c
> index 05b405b..b65023c 100644
> --- a/arch/arm/setup.c
> +++ b/arch/arm/setup.c
> @@ -9,13 +9,6 @@
>  #include <libfdt.h>
>  
>  /*
> - * This structure contains start-of-day info, such as pagetable base pointer,
> - * address of the shared_info structure, and things like that.
> - * On x86, the hypervisor passes it to us. On ARM, we fill it in ourselves.
> - */
> -union start_info_union start_info_union;
> -
> -/*
>   * Shared page for communicating with the hypervisor.
>   * Events flags go here, for example.
>   */
> @@ -47,7 +40,6 @@ void arch_init(void *dtb_pointer, uint32_t physical_offset)
>      /* Map shared_info page */
>      HYPERVISOR_shared_info = map_shared_info(NULL);
>  
> -    /* Fill in start_info */
>      get_console(NULL);
>      get_xenbus(NULL);
>  
> diff --git a/arch/x86/setup.c b/arch/x86/setup.c
> index 278e88f..50aa504 100644
> --- a/arch/x86/setup.c
> +++ b/arch/x86/setup.c
> @@ -40,12 +40,6 @@
>  shared_info_t *HYPERVISOR_shared_info;
>  
>  /*
> - * This structure contains start-of-day info, such as pagetable base pointer,
> - * address of the shared_info structure, and things like that.
> - */
> -union start_info_union start_info_union;
> -
> -/*
>   * Just allocate the kernel stack here. SS:ESP is set up to point here
>   * in head.S.
>   */
> @@ -151,7 +145,6 @@ arch_init(void *par)
>  	/* Setup memory management info from start_info. */
>  	arch_mm_preinit(par);
>  
> -	/* Copy the start_info struct to a globally-accessible area. */
>  	/* WARN: don't do printk before here, it uses information from
>  	   shared_info. Use xprintk instead. */
>  	get_console(par);
> @@ -162,7 +155,6 @@ arch_init(void *par)
>  	HYPERVISOR_shared_info = map_shared_info(par);
>  
>  	si = par;
> -	memcpy(&start_info, si, sizeof(*si));
>  
>  	/* print out some useful information  */
>  	printk("Xen Minimal OS!\n");
> diff --git a/daytime.c b/daytime.c
> index 7dc0de0..6049e78 100644
> --- a/daytime.c
> +++ b/daytime.c
> @@ -60,7 +60,7 @@ void run_server(void *p)
>  }
>  
>  
> -int app_main(start_info_t *si)
> +int app_main(void *p)
>  {
>      create_thread("server", run_server, NULL);
>      return 0;
> diff --git a/include/hypervisor.h b/include/hypervisor.h
> index 7c44702..3073a8a 100644
> --- a/include/hypervisor.h
> +++ b/include/hypervisor.h
> @@ -26,17 +26,6 @@
>  #include <xen/hvm/hvm_op.h>
>  #include <mini-os/traps.h>
>  
> -/*
> - * a placeholder for the start of day information passed up from the hypervisor
> - */
> -union start_info_union
> -{
> -    start_info_t start_info;
> -    char padding[512];
> -};
> -extern union start_info_union start_info_union;
> -#define start_info (start_info_union.start_info)
> -
>  /* hypervisor.c */
>  #ifndef CONFIG_PARAVIRT
>  int hvm_get_parameter(int idx, uint64_t *value);
> diff --git a/kernel.c b/kernel.c
> index f22997e..0d84a9b 100644
> --- a/kernel.c
> +++ b/kernel.c
> @@ -110,9 +110,9 @@ static void shutdown_thread(void *p)
>  
>  
>  /* This should be overridden by the application we are linked against. */
> -__attribute__((weak)) int app_main(start_info_t *si)
> +__attribute__((weak)) int app_main(void *p)
>  {
> -    printk("kernel.c: dummy main: start_info=%p\n", si);
> +    printk("kernel.c: dummy main: par=%p\n", p);
>      return 0;
>  }
>  
> @@ -149,7 +149,7 @@ void start_kernel(void)
>  #endif
>  
>      /* Call (possibly overridden) app_main() */
> -    app_main(&start_info);
> +    app_main(NULL);
>  
>      /* Everything initialised, start idle thread */
>      run_idle_thread();
> diff --git a/main.c b/main.c
> index 71e3be3..263364c 100644
> --- a/main.c
> +++ b/main.c
> @@ -185,10 +185,10 @@ void _exit(int ret)
>      do_exit();
>  }
>  
> -int app_main(start_info_t *si)
> +int app_main(void *p)
>  {
> -    printk("main.c: dummy main: start_info=%p\n", si);
> -    main_thread = create_thread("main", call_main, si);
> +    printk("main.c: dummy main: par=%p\n", p);
> +    main_thread = create_thread("main", call_main, p);
>      return 0;
>  }
>  #endif
> diff --git a/test.c b/test.c
> index 154af49..42a2666 100644
> --- a/test.c
> +++ b/test.c
> @@ -552,28 +552,28 @@ static void shutdown_thread(void *p)
>  }
>  #endif
>  
> -int app_main(start_info_t *si)
> +int app_main(void *p)
>  {
> -    printk("Test main: start_info=%p\n", si);
> +    printk("Test main: par=%p\n", p);
>  #ifdef CONFIG_XENBUS
> -    create_thread("xenbus_tester", xenbus_tester, si);
> +    create_thread("xenbus_tester", xenbus_tester, p);
>  #endif
> -    create_thread("periodic_thread", periodic_thread, si);
> +    create_thread("periodic_thread", periodic_thread, p);
>  #ifdef CONFIG_NETFRONT
> -    create_thread("netfront", netfront_thread, si);
> +    create_thread("netfront", netfront_thread, p);
>  #endif
>  #ifdef CONFIG_BLKFRONT
> -    create_thread("blkfront", blkfront_thread, si);
> +    create_thread("blkfront", blkfront_thread, p);
>  #endif
>  #if defined(CONFIG_FBFRONT) && defined(CONFIG_KBDFRONT)
> -    create_thread("fbfront", fbfront_thread, si);
> -    create_thread("kbdfront", kbdfront_thread, si);
> +    create_thread("fbfront", fbfront_thread, p);
> +    create_thread("kbdfront", kbdfront_thread, p);
>  #endif
>  #ifdef CONFIG_PCIFRONT
> -    create_thread("pcifront", pcifront_thread, si);
> +    create_thread("pcifront", pcifront_thread, p);
>  #endif
>  #ifdef CONFIG_XENBUS
> -    create_thread("shutdown", shutdown_thread, si);
> +    create_thread("shutdown", shutdown_thread, p);
>  #endif
>      return 0;
>  }
> -- 
> 2.6.6
> 

-- 
Samuel
Now, it we had this sort of thing:
  yield -a     for yield to all traffic
  yield -t     for yield to trucks
  yield -f     for yield to people walking (yield foot)
  yield -d t*  for yield on days starting with t
...you'd have a lot of dead people at intersections, and traffic jams you
wouldn't believe...
(Discussion in comp.os.linux.misc on the intuitiveness of commands.)

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 20/22] mini-os: print start of day messages depending on domain type
  2016-08-23 15:16 ` [PATCH 20/22] mini-os: print start of day messages depending on domain type Juergen Gross
@ 2016-08-23 22:51   ` Samuel Thibault
  2016-08-24  5:09     ` Juergen Gross
  0 siblings, 1 reply; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 22:51 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:16:06 +0200, wrote:
> +    printk("Xen Minimal OS (hvm)!\n");
> +    printk("  start_info: %p(VA)\n", si);
> +    printk("  shared_inf: %p(VA)\n", HYPERVISOR_shared_info);
> +    printk("     modlist: 0x%lx(PA)\n", (unsigned long)si->modlist_paddr);

It would be useful to also print nr_modules.

> +    printk("       flags: 0x%x\n", (unsigned int)si->flags);
> +    printk("    cmd_line: %s\n", cmdline);
> +    printk("       stack: %p-%p\n", stack, stack + sizeof(stack));

Apart from that,

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

Samuel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 21/22] mini-os: get physical memory map
  2016-08-23 15:16 ` [PATCH 21/22] mini-os: get physical memory map Juergen Gross
@ 2016-08-23 22:58   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 22:58 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:16:07 +0200, wrote:
> On HVMlite we have to look at the physical memory map to know which
> memory frames are usable.
> 
> In order to make life easier we define a dummy memory map for other
> domain types (pv and arm) which has just one entry with a maximum
> memory size.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/arm/mm.c         |  8 ++++++
>  arch/x86/mm.c         | 72 ++++++++++++++++++++++++++++++++++++++++++++++
>  arch/x86/setup.c      |  1 +
>  include/e820.h        | 48 +++++++++++++++++++++++++++++++
>  include/x86/arch_mm.h |  4 +++
>  mm.c                  | 79 ++++++++++++++++++++++++++++++++-------------------
>  6 files changed, 183 insertions(+), 29 deletions(-)
>  create mode 100644 include/e820.h
> 
> diff --git a/arch/arm/mm.c b/arch/arm/mm.c
> index dbde162..8c156c4 100644
> --- a/arch/arm/mm.c
> +++ b/arch/arm/mm.c
> @@ -7,6 +7,14 @@
>  #include <lib.h>
>  
>  uint32_t physical_address_offset;
> +struct e820entry e820_map[1] = {
> +    {
> +        .addr = 0,
> +        .size = ULONG_MAX - 1,
> +        .type = E820_RAM
> +    }
> +};
> +unsigned e820_entries = 1;
>  
>  unsigned long allocate_ondemand(unsigned long n, unsigned long alignment)
>  {
> diff --git a/arch/x86/mm.c b/arch/x86/mm.c
> index 762599d..8dd90b8 100644
> --- a/arch/x86/mm.c
> +++ b/arch/x86/mm.c
> @@ -43,6 +43,7 @@
>  #include <mini-os/types.h>
>  #include <mini-os/lib.h>
>  #include <mini-os/xmalloc.h>
> +#include <mini-os/e820.h>
>  #include <xen/memory.h>
>  
>  #ifdef MM_DEBUG
> @@ -63,6 +64,15 @@ extern char stack[];
>  extern void page_walk(unsigned long va);
>  
>  #ifdef CONFIG_PARAVIRT
> +struct e820entry e820_map[1] = {
> +    {
> +        .addr = 0,
> +        .size = ULONG_MAX - 1,
> +        .type = E820_RAM
> +    }
> +};
> +unsigned e820_entries = 1;
> +
>  void arch_mm_preinit(void *p)
>  {
>      start_info_t *si = p;
> @@ -102,10 +112,25 @@ desc_ptr idt_ptr =
>      .base = (unsigned long)&idt,
>  };
>  
> +struct e820entry e820_map[E820_MAX];
> +unsigned e820_entries;
> +
> +static char *e820_types[E820_TYPES] = {
> +    [E820_RAM]      = "RAM",
> +    [E820_RESERVED] = "Reserved",
> +    [E820_ACPI]     = "ACPI",
> +    [E820_NVS]      = "NVS",
> +    [E820_UNUSABLE] = "Unusable",
> +    [E820_PMEM]     = "PMEM"
> +};
> +
>  void arch_mm_preinit(void *p)
>  {
>      long ret;
>      domid_t domid = DOMID_SELF;
> +    struct xen_memory_map memmap;
> +    int i;
> +    unsigned long pfn, max = 0;
>  
>      pt_base = page_table_base;
>      first_free_pfn = PFN_UP(to_phys(&_end));
> @@ -116,6 +141,53 @@ void arch_mm_preinit(void *p)
>          do_exit();
>      }
>      last_free_pfn = ret;
> +
> +    memmap.nr_entries = E820_MAX;
> +    set_xen_guest_handle(memmap.buffer, e820_map);
> +    ret = HYPERVISOR_memory_op(XENMEM_memory_map, &memmap);
> +    if ( ret < 0 )
> +    {
> +        xprintk("could not get memory map\n");
> +        do_exit();
> +    }
> +    e820_entries = memmap.nr_entries;
> +
> +    for ( i = 0; i < e820_entries; i++ )
> +    {
> +        if ( e820_map[i].type != E820_RAM )
> +            continue;
> +        pfn = (e820_map[i].addr + e820_map[i].size) >> PAGE_SHIFT;
> +        if ( pfn > max )
> +            max = pfn;
> +    }
> +
> +    if ( max < last_free_pfn )
> +        last_free_pfn = max;
> +}
> +
> +void arch_print_memmap(void)
> +{
> +    int i;
> +    unsigned long from, to;
> +    char *type;
> +    char buf[12];
> +
> +    printk("Memory map:\n");
> +    for ( i = 0; i < e820_entries; i++ )
> +    {
> +        if ( e820_map[i].type >= E820_TYPES || !e820_types[e820_map[i].type] )
> +        {
> +            snprintf(buf, sizeof(buf), "%8x", e820_map[i].type);
> +            type = buf;
> +        }
> +        else
> +        {
> +            type = e820_types[e820_map[i].type];
> +        }
> +        from = e820_map[i].addr;
> +        to = from + e820_map[i].size - 1;
> +        printk("%012lx-%012lx: %s\n", from, to, type);
> +    }
>  }
>  #endif
>  
> diff --git a/arch/x86/setup.c b/arch/x86/setup.c
> index 948b08a..829b03c 100644
> --- a/arch/x86/setup.c
> +++ b/arch/x86/setup.c
> @@ -150,6 +150,7 @@ static void print_start_of_day(void *p)
>      printk("       flags: 0x%x\n", (unsigned int)si->flags);
>      printk("    cmd_line: %s\n", cmdline);
>      printk("       stack: %p-%p\n", stack, stack + sizeof(stack));
> +    arch_print_memmap();
>  }
>  #endif
>  
> diff --git a/include/e820.h b/include/e820.h
> new file mode 100644
> index 0000000..920551c
> --- /dev/null
> +++ b/include/e820.h
> @@ -0,0 +1,48 @@
> +/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
> + *
> + * (C) 2016 - Juergen Gross, SUSE Linux GmbH
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a copy
> + * of this software and associated documentation files (the "Software"), to
> + * deal in the Software without restriction, including without limitation the
> + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
> + * sell copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> + * DEALINGS IN THE SOFTWARE.
> + */
> +
> +#ifndef __E820_HEADER
> +#define __E820_HEADER
> +
> +/* PC BIOS standard E820 types and structure. */
> +#define E820_RAM          1
> +#define E820_RESERVED     2
> +#define E820_ACPI         3
> +#define E820_NVS          4
> +#define E820_UNUSABLE     5
> +#define E820_PMEM         7
> +#define E820_TYPES        8
> +
> +struct __packed e820entry {
> +    uint64_t addr;
> +    uint64_t size;
> +    uint32_t type;
> +};
> +
> +/* Maximum number of entries. */
> +#define E820_MAX          128
> +
> +extern struct e820entry e820_map[];
> +extern unsigned e820_entries;
> +
> +#endif /*__E820_HEADER*/
> diff --git a/include/x86/arch_mm.h b/include/x86/arch_mm.h
> index 9372f1e..ab8a53e 100644
> --- a/include/x86/arch_mm.h
> +++ b/include/x86/arch_mm.h
> @@ -279,6 +279,10 @@ pgentry_t *need_pgt(unsigned long addr);
>  void arch_mm_preinit(void *p);
>  unsigned long alloc_virt_kernel(unsigned n_pages);
>  
> +#ifndef CONFIG_PARAVIRT
> +void arch_print_memmap(void);
> +#endif
> +
>  #endif
>  
>  #endif /* _ARCH_MM_H_ */
> diff --git a/mm.c b/mm.c
> index c76be7f..932ceeb 100644
> --- a/mm.c
> +++ b/mm.c
> @@ -43,6 +43,7 @@
>  #include <mini-os/types.h>
>  #include <mini-os/lib.h>
>  #include <mini-os/xmalloc.h>
> +#include <mini-os/e820.h>
>  
>  /*********************
>   * ALLOCATION BITMAP
> @@ -147,10 +148,14 @@ static chunk_head_t  free_tail[FREELIST_SIZE];
>   */
>  static void init_page_allocator(unsigned long min, unsigned long max)
>  {
> -    int i;
> +    int i, m;
>      unsigned long range;
> +    unsigned long r_min, r_max;
>      chunk_head_t *ch;
>      chunk_tail_t *ct;
> +
> +    printk("MM: Initialise page allocator for %lx(%lx)-%lx(%lx)\n",
> +           (u_long)to_virt(min), min, (u_long)to_virt(max), max);
>      for ( i = 0; i < FREELIST_SIZE; i++ )
>      {
>          free_head[i]       = &free_tail[i];
> @@ -166,38 +171,57 @@ static void init_page_allocator(unsigned long min, unsigned long max)
>      mm_alloc_bitmap_size  = round_pgup(mm_alloc_bitmap_size);
>      mm_alloc_bitmap = (unsigned long *)to_virt(min);
>      min         += mm_alloc_bitmap_size;
> -    range        = max - min;
>  
>      /* All allocated by default. */
>      memset(mm_alloc_bitmap, ~0, mm_alloc_bitmap_size);
> -    /* Free up the memory we've been given to play with. */
> -    map_free(PHYS_PFN(min), range>>PAGE_SHIFT);
>  
> -    /* The buddy lists are addressed in high memory. */
> -    min = (unsigned long) to_virt(min);
> -    max = (unsigned long) to_virt(max);
> -
> -    while ( range != 0 )
> +    for ( m = 0; m < e820_entries; m++ )
>      {
> -        /*
> -         * Next chunk is limited by alignment of min, but also
> -         * must not be bigger than remaining range.
> -         */
> -        for ( i = PAGE_SHIFT; (1UL<<(i+1)) <= range; i++ )
> -            if ( min & (1UL<<i) ) break;
> +        if ( e820_map[m].type != E820_RAM )
> +            continue;
> +        if ( e820_map[m].addr + e820_map[m].size >= ULONG_MAX )
> +            BUG();
>  
> +        r_min = e820_map[m].addr;
> +        r_max = r_min + e820_map[m].size;
> +        if ( r_max <= min || r_min >= max )
> +            continue;
> +        if ( r_min < min )
> +            r_min = min;
> +        if ( r_max > max )
> +            r_max = max;
>  
> -        ch = (chunk_head_t *)min;
> -        min   += (1UL<<i);
> -        range -= (1UL<<i);
> -        ct = (chunk_tail_t *)min-1;
> -        i -= PAGE_SHIFT;
> -        ch->level       = i;
> -        ch->next        = free_head[i];
> -        ch->pprev       = &free_head[i];
> -        ch->next->pprev = &ch->next;
> -        free_head[i]    = ch;
> -        ct->level       = i;
> +        printk("    Adding memory range %lx-%lx\n", r_min, r_max);
> +
> +        /* The buddy lists are addressed in high memory. */
> +        r_min = (unsigned long)to_virt(r_min);
> +        r_max = (unsigned long)to_virt(r_max);
> +        range = r_max - r_min;
> +
> +        /* Free up the memory we've been given to play with. */
> +        map_free(PHYS_PFN(r_min), range >> PAGE_SHIFT);
> +
> +        while ( range != 0 )
> +        {
> +            /*
> +             * Next chunk is limited by alignment of min, but also
> +             * must not be bigger than remaining range.
> +             */
> +            for ( i = PAGE_SHIFT; (1UL << (i + 1)) <= range; i++ )
> +                if ( r_min & (1UL << i) ) break;
> +
> +            ch = (chunk_head_t *)r_min;
> +            r_min += 1UL << i;
> +            range -= 1UL << i;
> +            ct = (chunk_tail_t *)r_min - 1;
> +            i -= PAGE_SHIFT;
> +            ch->level       = i;
> +            ch->next        = free_head[i];
> +            ch->pprev       = &free_head[i];
> +            ch->next->pprev = &ch->next;
> +            free_head[i]    = ch;
> +            ct->level       = i;
> +        }
>      }
>  
>      mm_alloc_bitmap_remap();
> @@ -377,9 +401,6 @@ void init_mm(void)
>      /*
>       * now we can initialise the page allocator
>       */
> -    printk("MM: Initialise page allocator for %lx(%lx)-%lx(%lx)\n",
> -           (u_long)to_virt(PFN_PHYS(start_pfn)), (u_long)PFN_PHYS(start_pfn),
> -           (u_long)to_virt(PFN_PHYS(max_pfn)), (u_long)PFN_PHYS(max_pfn));
>      init_page_allocator(PFN_PHYS(start_pfn), PFN_PHYS(max_pfn));
>      printk("MM: done\n");
>  
> -- 
> 2.6.6
> 

-- 
Samuel
 Les roots ne sont plus ce qu'ils étaient...Maintenant il sont dioxinés,
 c'est de la m... ! Avant on les élevaient avec du bon unix mais ça été
 remplacé par des farines industrielles nouvelles technologies (NT).
 -+- JdK in NPC : Exigez un root élevé sous la mère ! -+-

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 22/22] mini-os: support idle for HVMlite
  2016-08-23 15:16 ` [PATCH 22/22] mini-os: support idle for HVMlite Juergen Gross
@ 2016-08-23 23:01   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 23:01 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:16:08 +0200, wrote:
> Instead of calling HYPERVISOR_sched_op(SCHEDOP_block, 0) we need to use
> the "hlt" instruction with interrupts enabled to switch to idle when
> running as HVMlite domain.
> 
> This requires to setup a new timer in the timer handler as there is no
> guarantee the original timer event we are waiting for won't fire
> between enabling interrupts and calling "hlt".
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/x86/time.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/time.c b/arch/x86/time.c
> index af45e56..3658142 100644
> --- a/arch/x86/time.c
> +++ b/arch/x86/time.c
> @@ -212,17 +212,20 @@ void block_domain(s_time_t until)
>      if(monotonic_clock() < until)
>      {
>          HYPERVISOR_set_timer_op(until);
> +#ifdef CONFIG_PARAVIRT
>          HYPERVISOR_sched_op(SCHEDOP_block, 0);
> +#else
> +        local_irq_enable();
> +        asm volatile ( "hlt" : : : "memory" );
> +#endif
>          local_irq_disable();
> +        HYPERVISOR_set_timer_op(0);
>      }
>  }
>  
> -
> -/*
> - * Just a dummy
> - */
>  static void timer_handler(evtchn_port_t ev, struct pt_regs *regs, void *ign)
>  {
> +    HYPERVISOR_set_timer_op(monotonic_clock() + MILLISECS(1));
>  }
>  
>  
> -- 
> 2.6.6
> 

-- 
Samuel
Linux, c'est simple : ça s'adresse à une machine qui est parfois un peu
maraboutée mais qui d'habitude n'a pas d'états d'âme. Sur Usenet y'a
plein d'humains et de primates, et ça devient vraiment gore par moment.
-+- TP in : Guide du linuxien pervers - "Le linuxien a-t-il une âme ?" -+-

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [Minios-devel] [PATCH 17/22] mini-os: add get_cmdline() function
  2016-08-23 15:16 ` [PATCH 17/22] mini-os: add get_cmdline() function Juergen Gross
@ 2016-08-23 23:03   ` Samuel Thibault
  0 siblings, 0 replies; 48+ messages in thread
From: Samuel Thibault @ 2016-08-23 23:03 UTC (permalink / raw)
  To: Juergen Gross; +Cc: minios-devel, xen-devel, wei.liu2

Juergen Gross, on Tue 23 Aug 2016 17:16:03 +0200, wrote:
> The command line parameters are passed in start_info structure for pv,
> but via hvm_start_info for HVMlite. Add a generic function to fill a
> local cmdline variable with the command line string.
> 
> Signed-off-by: Juergen Gross <jgross@suse.com>

Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

> ---
>  arch/x86/setup.c | 20 ++++++++++++++++++--
>  include/kernel.h |  3 +++
>  kernel.c         |  1 +
>  main.c           |  5 +++--
>  4 files changed, 25 insertions(+), 4 deletions(-)
> 
> diff --git a/arch/x86/setup.c b/arch/x86/setup.c
> index 6645784..13633f0 100644
> --- a/arch/x86/setup.c
> +++ b/arch/x86/setup.c
> @@ -31,6 +31,7 @@
>  #include <mini-os/kernel.h>
>  #include <xen/xen.h>
>  #include <xen/arch-x86/cpuid.h>
> +#include <xen/arch-x86/hvm/start_info.h>
>  
>  /*
>   * Shared page for communicating with the hypervisor.
> @@ -88,6 +89,13 @@ static inline void sse_init(void) {
>  
>  #ifdef CONFIG_PARAVIRT
>  #define hpc_init()
> +
> +static void get_cmdline(void *p)
> +{
> +    start_info_t *si = p;
> +
> +    strncpy(cmdline, (char *)si->cmd_line, MAX_CMDLINE_SIZE - 1);
> +}
>  #else
>  static void hpc_init(void)
>  {
> @@ -109,6 +117,14 @@ static void hpc_init(void)
>      wrmsrl(ebx, (unsigned long)&hypercall_page);
>      barrier();
>  }
> +
> +static void get_cmdline(void *p)
> +{
> +    struct hvm_start_info *si = p;
> +
> +    if ( si->cmdline_paddr )
> +        strncpy(cmdline, to_virt(si->cmdline_paddr), MAX_CMDLINE_SIZE - 1);
> +}
>  #endif
>  
>  /*
> @@ -139,6 +155,7 @@ arch_init(void *par)
>  	   shared_info. Use xprintk instead. */
>  	get_console(par);
>  	get_xenbus(par);
> +	get_cmdline(par);
>  	si = par;
>  	memcpy(&start_info, si, sizeof(*si));
>  
> @@ -153,8 +170,7 @@ arch_init(void *par)
>  	printk("   mod_start: 0x%lx(VA)\n", si->mod_start);
>  	printk("     mod_len: %lu\n", si->mod_len);
>  	printk("       flags: 0x%x\n", (unsigned int)si->flags);
> -	printk("    cmd_line: %s\n",
> -			si->cmd_line ? (const char *)si->cmd_line : "NULL");
> +	printk("    cmd_line: %s\n", cmdline);
>  	printk("       stack: %p-%p\n", stack, stack + sizeof(stack));
>  
>  	/* Grab the shared_info pointer and put it in a safe place. */
> diff --git a/include/kernel.h b/include/kernel.h
> index 13e3274..d37ddda 100644
> --- a/include/kernel.h
> +++ b/include/kernel.h
> @@ -1,6 +1,9 @@
>  #ifndef _KERNEL_H_
>  #define _KERNEL_H_
>  
> +#define MAX_CMDLINE_SIZE 1024
> +extern char cmdline[MAX_CMDLINE_SIZE];
> +
>  void start_kernel(void);
>  void do_exit(void) __attribute__((noreturn));
>  void arch_do_exit(void);
> diff --git a/kernel.c b/kernel.c
> index 437e5b4..f22997e 100644
> --- a/kernel.c
> +++ b/kernel.c
> @@ -48,6 +48,7 @@
>  #include <xen/version.h>
>  
>  uint8_t xen_features[XENFEAT_NR_SUBMAPS * 32];
> +char cmdline[MAX_CMDLINE_SIZE];
>  
>  void setup_xen_features(void)
>  {
> diff --git a/main.c b/main.c
> index 4ec40b5..71e3be3 100644
> --- a/main.c
> +++ b/main.c
> @@ -6,6 +6,7 @@
>  
>  #ifdef HAVE_LIBC
>  #include <os.h>
> +#include <kernel.h>
>  #include <sched.h>
>  #include <console.h>
>  #include <netfront.h>
> @@ -134,7 +135,7 @@ static void call_main(void *p)
>  #define PARSE_ARGS_COUNT(ARGS) PARSE_ARGS(ARGS, argc++, c++, )
>  #define PARSE_ARGS_STORE(ARGS) PARSE_ARGS(ARGS, argv[argc++] = c, memmove(c, c + 1, strlen(c + 1) + 1), *c++ = 0)
>  
> -    PARSE_ARGS_COUNT((char*)start_info.cmd_line);
> +    PARSE_ARGS_COUNT(cmdline);
>  #ifdef CONFIG_QEMU_XS_ARGS
>      PARSE_ARGS_COUNT(domargs);
>  #endif
> @@ -143,7 +144,7 @@ static void call_main(void *p)
>      argv[0] = "main";
>      argc = 1;
>  
> -    PARSE_ARGS_STORE((char*)start_info.cmd_line)
> +    PARSE_ARGS_STORE(cmdline)
>  #ifdef CONFIG_QEMU_XS_ARGS
>      PARSE_ARGS_STORE(domargs)
>  #endif
> -- 
> 2.6.6
> 
> 
> _______________________________________________
> Minios-devel mailing list
> Minios-devel@lists.xenproject.org
> https://lists.xenproject.org/cgi-bin/mailman/listinfo/minios-devel

-- 
Samuel
<T> csp.tar.gz:     ascii text
 -+- #ens-mim - vive les browsers qui prennent des initiatives à la con -+-

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 20/22] mini-os: print start of day messages depending on domain type
  2016-08-23 22:51   ` Samuel Thibault
@ 2016-08-24  5:09     ` Juergen Gross
  0 siblings, 0 replies; 48+ messages in thread
From: Juergen Gross @ 2016-08-24  5:09 UTC (permalink / raw)
  To: Samuel Thibault, minios-devel, xen-devel, wei.liu2

On 24/08/16 00:51, Samuel Thibault wrote:
> Juergen Gross, on Tue 23 Aug 2016 17:16:06 +0200, wrote:
>> +    printk("Xen Minimal OS (hvm)!\n");
>> +    printk("  start_info: %p(VA)\n", si);
>> +    printk("  shared_inf: %p(VA)\n", HYPERVISOR_shared_info);
>> +    printk("     modlist: 0x%lx(PA)\n", (unsigned long)si->modlist_paddr);
> 
> It would be useful to also print nr_modules.

Okay, I'll add it.

> 
>> +    printk("       flags: 0x%x\n", (unsigned int)si->flags);
>> +    printk("    cmd_line: %s\n", cmdline);
>> +    printk("       stack: %p-%p\n", stack, stack + sizeof(stack));
> 
> Apart from that,
> 
> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

Thanks,

Juergen


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 06/22] mini-os: setup hypercall page for HVMlite
  2016-08-23 21:03   ` Samuel Thibault
@ 2016-08-24  5:10     ` Juergen Gross
  0 siblings, 0 replies; 48+ messages in thread
From: Juergen Gross @ 2016-08-24  5:10 UTC (permalink / raw)
  To: Samuel Thibault, minios-devel, xen-devel, wei.liu2

On 23/08/16 23:03, Samuel Thibault wrote:
> hello,
> 
> Juergen Gross, on Tue 23 Aug 2016 17:15:52 +0200, wrote:
>> When running in HVMlite mode we need to setup the hypercall page by
>> ourself.
>>
>> Signed-off-by: Juergen Gross <jgross@suse.com>
>> ---
>>  
>> +#else /* ifdef __x86_64__ */
>> +#error "Unsupported architecture"
>> +#endif
>> +
>>  #define wrmsr(msr,val1,val2) \
>>        __asm__ __volatile__("wrmsr" \
>>                             : /* no outputs */ \
>>                             : "c" (msr), "a" (val1), "d" (val2))
>>  
>> -#define wrmsrl(msr,val) wrmsr(msr,(uint32_t)((uint64_t)(val)),((uint64_t)(val))>>32)
>> +static inline void wrmsrl(unsigned msr, uint64_t val)
>> +{
>> +    wrmsr(msr, (uint32_t)(val & 0xffffffffULL), (uint32_t)(val >> 32));
>> +}
>>  
>> -
>> -#else /* ifdef __x86_64__ */
>> -#error "Unsupported architecture"
>> -#endif
>>  #endif /* ifdef __INSIDE_MINIOS */
> 
> Then please move it after
> 
>>  /********************* common i386 and x86_64  ****************************/
> 
> This line :)

Okay.

> 
> Apart from that, 
> 
> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>

Thanks,

Juergen


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

* Re: [PATCH 05/22] mini-os: add boot code for HVMlite support
  2016-08-23 20:51   ` Samuel Thibault
@ 2016-08-24  5:13     ` Juergen Gross
  0 siblings, 0 replies; 48+ messages in thread
From: Juergen Gross @ 2016-08-24  5:13 UTC (permalink / raw)
  To: Samuel Thibault, minios-devel, xen-devel, wei.liu2

On 23/08/16 22:51, Samuel Thibault wrote:
> Hello,
> 
> It looks good, there is just:
> 
> Juergen Gross, on Tue 23 Aug 2016 17:15:51 +0200, wrote:
>> +        .macro PTES prot, addr, incr, idx, end
> 
> Please document what prot, addr, incr, idx, end represent precisely.

Okay.

> 
>> +        .ifgt \end-\idx-32
>> +        PTES \prot, \addr, \incr, \idx, "(\idx+32)"
>> +        PTES \prot, "(\addr+32*\incr)", \incr, "(\idx+32)", \end
>> +        .else
>> +        PTE(\addr + \prot)
>> +        .if \end-\idx-1
>> +        PTES \prot, "(\addr+\incr)", \incr, "(\idx+1)", \end
>> +        .endif
>> +        .endif
>> +        .endm
> 
>> diff --git a/include/x86/desc.h b/include/x86/desc.h
>> new file mode 100644
>> index 0000000..d450557
>> --- /dev/null
>> +++ b/include/x86/desc.h
>> @@ -0,0 +1,366 @@
>> +/* -*-  Mode:C; c-basic-offset:4; tab-width:4 -*-
>> + *
>> + * (C) 2016 - Juergen Gross, SUSE Linux GmbH
> 
> Was this whole file imported from somewhere, or written from scratch?

It is a modified variant of a similar file in:

http://xenbits.xen.org/gitweb/?p=people/andrewcoop/xen-test-framework.git

I'll add a comment telling so.


Juergen


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 48+ messages in thread

end of thread, other threads:[~2016-08-24  5:13 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-23 15:15 [PATCH 00/22] mini-os: support HVMlite mode Juergen Gross
2016-08-23 15:15 ` [PATCH 01/22] mini-os: resync xen headers Juergen Gross
2016-08-23 19:44   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 02/22] mini-os: make dump_regs() work in early boot Juergen Gross
2016-08-23 19:44   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 03/22] mini-os: add CONFIG_PARAVIRT Juergen Gross
2016-08-23 19:54   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 04/22] mini-os: make some memory management related macros usable from assembler Juergen Gross
2016-08-23 19:46   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 05/22] mini-os: add boot code for HVMlite support Juergen Gross
2016-08-23 20:51   ` Samuel Thibault
2016-08-24  5:13     ` Juergen Gross
2016-08-23 15:15 ` [PATCH 06/22] mini-os: setup hypercall page for HVMlite Juergen Gross
2016-08-23 21:03   ` Samuel Thibault
2016-08-24  5:10     ` Juergen Gross
2016-08-23 15:15 ` [PATCH 07/22] mini-os: support hvm_op hypercall Juergen Gross
2016-08-23 22:00   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 08/22] mini-os: initialize trap handling for HVMlite Juergen Gross
2016-08-23 22:05   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 09/22] mini-os: support HVMlite traps Juergen Gross
2016-08-23 22:10   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 10/22] mini-os: make p2m related code depend on CONFIG_PARAVIRT Juergen Gross
2016-08-23 22:20   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 11/22] mini-os: add static page tables for virtual kernel area for HVMlite Juergen Gross
2016-08-23 22:27   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 12/22] mini-os: add x86 native page table handling Juergen Gross
2016-08-23 22:40   ` Samuel Thibault
2016-08-23 15:15 ` [PATCH 13/22] mini-os: correct wrong calculation of alloc bitmap size Juergen Gross
2016-08-23 19:49   ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 14/22] mini-os: add map_frame_virt() function Juergen Gross
2016-08-23 22:42   ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 15/22] mini-os: setup console interface parameters Juergen Gross
2016-08-23 22:44   ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 16/22] mini-os: setup xenbus " Juergen Gross
2016-08-23 22:45   ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 17/22] mini-os: add get_cmdline() function Juergen Gross
2016-08-23 23:03   ` [Minios-devel] " Samuel Thibault
2016-08-23 15:16 ` [PATCH 18/22] mini-os: map shared info page for HVMlite Juergen Gross
2016-08-23 22:47   ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 19/22] mini-os: remove using start_info in architecture independent code Juergen Gross
2016-08-23 22:48   ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 20/22] mini-os: print start of day messages depending on domain type Juergen Gross
2016-08-23 22:51   ` Samuel Thibault
2016-08-24  5:09     ` Juergen Gross
2016-08-23 15:16 ` [PATCH 21/22] mini-os: get physical memory map Juergen Gross
2016-08-23 22:58   ` Samuel Thibault
2016-08-23 15:16 ` [PATCH 22/22] mini-os: support idle for HVMlite Juergen Gross
2016-08-23 23:01   ` Samuel Thibault

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.