the syscall assembly instruction save the X64 flag
register rflag into r11 so the sysret instruction
can restore it.

Since OSv syscall hander does not use sysret since
it switch to privilege level 3 we must restore rflag
before doing the final jump.

Does it by pushing r11 on the stack and using
popfq to restore rflags.

Fixes #798

Signed-off-by: Benoît Canet <ben...@scylladb.com>
---
 arch/x64/entry.S | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/arch/x64/entry.S b/arch/x64/entry.S
index cd23cec..04d809d 100644
--- a/arch/x64/entry.S
+++ b/arch/x64/entry.S
@@ -276,7 +276,15 @@ syscall_entry:
     popq_cfi %rcx
 
     movq 8(%rsp), %rsp # undo alignment (as explained above)
-    addq $128, %rsp    # undo red-zone skip
+
+    # restore rflags
+    # push the rflag state syscall saved in r11 to the stack
+    pushq %r11
+    # pop the stack value in flag register
+    popfq
+
+    #undo red-zone skip without altering restored flags
+    lea 128(%rsp), %rsp
 
     # jump to rcx where the syscall instruction put rip
     # (sysret would leave rxc cloberred so we have nothing to do to restore it)
-- 
2.7.4

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to