From: Juergen Gross <jgross@suse.com>
To: minios-devel@lists.xenproject.org, xen-devel@lists.xenproject.org
Cc: Juergen Gross <jgross@suse.com>,
samuel.thibault@ens-lyon.org, wei.liu2@citrix.com
Subject: [PATCH v2 09/22] mini-os: support HVMlite traps
Date: Wed, 24 Aug 2016 12:11:31 +0200 [thread overview]
Message-ID: <1472033504-23180-10-git-send-email-jgross@suse.com> (raw)
In-Reply-To: <1472033504-23180-1-git-send-email-jgross@suse.com>
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 db1389a..8ccff21 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
next prev parent reply other threads:[~2016-08-24 10:11 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-24 10:11 [PATCH v2 00/22] mini-os: support HVMlite mode Juergen Gross
2016-08-24 10:11 ` [PATCH v2 01/22] mini-os: resync xen headers Juergen Gross
2016-08-24 10:11 ` [PATCH v2 02/22] mini-os: make dump_regs() work in early boot Juergen Gross
2016-08-24 10:11 ` [PATCH v2 03/22] mini-os: add CONFIG_PARAVIRT Juergen Gross
2016-08-24 10:11 ` [PATCH v2 04/22] mini-os: make some memory management related macros usable from assembler Juergen Gross
2016-08-24 10:11 ` [PATCH v2 05/22] mini-os: add boot code for HVMlite support Juergen Gross
2016-08-24 10:21 ` Samuel Thibault
2016-08-24 10:11 ` [PATCH v2 06/22] mini-os: setup hypercall page for HVMlite Juergen Gross
2016-08-24 10:11 ` [PATCH v2 07/22] mini-os: support hvm_op hypercall Juergen Gross
2016-08-24 10:11 ` [PATCH v2 08/22] mini-os: initialize trap handling for HVMlite Juergen Gross
2016-08-24 10:11 ` Juergen Gross [this message]
2016-08-24 10:11 ` [PATCH v2 10/22] mini-os: make p2m related code depend on CONFIG_PARAVIRT Juergen Gross
2016-08-24 10:11 ` [PATCH v2 11/22] mini-os: add static page tables for virtual kernel area for HVMlite Juergen Gross
2016-08-24 10:11 ` [PATCH v2 12/22] mini-os: add x86 native page table handling Juergen Gross
2016-08-24 10:11 ` [PATCH v2 13/22] mini-os: correct wrong calculation of alloc bitmap size Juergen Gross
2016-08-24 10:11 ` [PATCH v2 14/22] mini-os: add map_frame_virt() function Juergen Gross
2016-08-24 10:11 ` [PATCH v2 15/22] mini-os: setup console interface parameters Juergen Gross
2016-08-24 10:11 ` [PATCH v2 16/22] mini-os: setup xenbus " Juergen Gross
2016-08-24 10:11 ` [PATCH v2 17/22] mini-os: add get_cmdline() function Juergen Gross
2016-08-24 10:11 ` [PATCH v2 18/22] mini-os: map shared info page for HVMlite Juergen Gross
2016-08-24 10:11 ` [PATCH v2 19/22] mini-os: remove using start_info in architecture independent code Juergen Gross
2016-08-24 10:11 ` [PATCH v2 20/22] mini-os: print start of day messages depending on domain type Juergen Gross
2016-08-24 10:11 ` [PATCH v2 21/22] mini-os: get physical memory map Juergen Gross
2016-08-24 10:11 ` [PATCH v2 22/22] mini-os: support idle for HVMlite Juergen Gross
2016-08-24 10:38 ` [PATCH v2 00/22] mini-os: support HVMlite mode Wei Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1472033504-23180-10-git-send-email-jgross@suse.com \
--to=jgross@suse.com \
--cc=minios-devel@lists.xenproject.org \
--cc=samuel.thibault@ens-lyon.org \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).