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

[Minios-devel] [UNIKRAFT PATCH 08/23] plat/xen/x86/entry64.S: Add more comments for critical region fixup


  • To: minios-devel@xxxxxxxxxxxxx
  • From: Costin Lupu <costin.lupu@xxxxxxxxx>
  • Date: Mon, 8 Jul 2019 11:33:37 +0300
  • Cc: felipe.huici@xxxxxxxxx, simon.kuenzer@xxxxxxxxx
  • Delivery-date: Mon, 08 Jul 2019 08:50:18 +0000
  • Ironport-phdr: 9a23:yCpxxBGdJRGq9DWgcyra/Z1GYnF86YWxBRYc798ds5kLTJ7yps+wAkXT6L1XgUPTWs2DsrQY0rCQ7/irATBIyK3CmUhKSIZLWR4BhJdetC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TW94jEIBxrwKxd+KPjrFY7OlcS30P2594HObwlSizexfK1+IA+5oAnNucUanYRvIbstxxXUpXdFZ/5Yzn5yK1KJmBb86Maw/Jp9/ClVpvks6c1OX7jkcqohVbBXAygoPG4z5M3wqBnMVhCP6WcGUmUXiRVHHQ7I5wznU5jrsyv6su192DSGPcDzULs5Vyiu47ttRRT1jioMKjw3/3zNisFojKxVvg+vqRJ8zYDTYo6VOuFzcr/Bcd4AWWZMRNpdWzBHD4ihb4UPFe0BPeNAooTjoFsOtge+BQiqBOjyzDFIm2f23bAn2OkmDQ7G2xcgH84PsHTSttn1MLoSUfiozKTT0TrDdOla2S/g6IfTaBwhu/aMUKt2fMHMx0cvEAbFgU+RqYzjJz6ayOINs3SB7+tgVO+ihHQrqxpqrTWp28wiiZHJi5oIxl3L6Cl12oU4KN2iREJlf9KpEoFcui+CO4drTc4uXntktSU6x7Ecp5K2ciYHxI46yxPQdfCKdZWD7Aj5W+aLOzh4gWpoeLe4hxmv70et0vb8Vsyo0FZSqSpFj8XMumgN1xPN7siHTeNw/lmk2TmV1gDT7vtILlwvlabBM54h36U/moAJsUTEBiP2mUP2g7GKdkg85+Sl5Pnrbq/lq5KcLYN4lB/yP6Y0lsGxGeg4NxIBX2mf+eSyzr3j+kj5Ta1Wgf0xianZrJHaJcIBqq69Hg9Vypsj5g2jADe9ytgYhWQHI0lfdBKdiIjlI0vOL+zgDfejn1Ssly9mx/XHPr3nA5XNKWPDnK78crlj9U5T1g4zwMtb55JVEbEBPOnzVlX+tdPGCB81KQu0w/zoCN9lzIMRRXqPArOFMKPVqVKI6PwgI+2NZI8NpjnxMfgl5+PvjXAlmF8QZq+p0oULZ3C8BPtpOF+VbmTxgt0ZC2cFohI+TPD2iF2FSTNTfHeyX6c75jE9Eo6mDprDSZ6rgL2Awii7BIZbZmZYBV+QFXfnbZ6LV+0SZyKPcYddlWkBVL6gTJRk2RywuQvSz7t8MvGS6iAe85X524tb/erWwDo17iB1CYy5znmQBzV/mXgURjlw2L1nvGR20RGbzKI+mfsORo8b3O9ATgpvbc2U9Od9Ed2nAg8=
  • Ironport-sdr: 7IvZ/lNHOCMeaUtqXSZZdnuHbnfYqJpz2nHtMKDRrpWjdJt3exp3RU0UtHKeRPbe4Zz1DZCZgU z6C6UEaPiUfw==
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>

The implementation for handling event on Xen was ported from Mini-OS and has a
race condition after handling an event and before returning to user (more
details in entry64.S code). In order to support preemptive scheduling on Xen,
the fix for the race condition had to be properly understood and extended.
Therefore this patch adds the comments which helped me towards these goals.

Signed-off-by: Costin Lupu <costin.lupu@xxxxxxxxx>
---
 plat/xen/x86/entry64.S | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/plat/xen/x86/entry64.S b/plat/xen/x86/entry64.S
index d34181be..1aba52c1 100644
--- a/plat/xen/x86/entry64.S
+++ b/plat/xen/x86/entry64.S
@@ -274,21 +274,21 @@ hypervisor_callback2:
        cmpq $ecrit,%rax
        jb  critical_region_fixup
 
-11:    movq %gs:8,%rax
-       incl %gs:0
-       cmovzq %rax,%rsp
-       pushq %rdi
-       call do_hypervisor_callback
-       popq %rsp
-       decl %gs:0
+11:    movq %gs:8, %rax                # load IRQ stack
+       incl %gs:0                      # increment nested IRQ counter
+       cmovzq %rax, %rsp               # if not nested IRQ, then set IRQ sp
+       pushq %rdi                      # save last sp
+       call do_hypervisor_callback     # handle IRQ/event
+       popq %rsp                       # restore last sp
+       decl %gs:0                      # decrement nested IRQ counter
 
 error_exit:
        movl OFFSETOF_REGS_EFLAGS(%rsp), %eax
-       shr $9, %eax                    # EAX[0] == IRET_RFLAGS.IF
+       shr $9, %eax                    # EAX[0] == IRET_RFLAGS.IF
        XEN_GET_VCPU_INFO(%rsi)
-       andb evtchn_upcall_mask(%rsi),%al
-       andb $1,%al                     # EAX[0] == IRET_RFLAGS.IF & event_mask
-       jnz restore_all_enable_events   #        != 0 => enable event delivery
+       andb evtchn_upcall_mask(%rsi), %al
+       andb $1, %al                    # EAX[0] == IRET_RFLAGS.IF & event_mask
+       jnz restore_all_enable_events   #        != 0 => enable event delivery
 
        RESTORE_ALL
        HYPERVISOR_IRET
@@ -356,7 +356,7 @@ critical_region_fixup:
        andb $KERNEL_CS_MASK,OFFSETOF_REGS_CS(%rsp)      # CS might have changed
        jmp  11b
 
-#else
+#else /* !CONFIG_PARAVIRT */
 error_exit:
        RESTORE_ALL
        HYPERVISOR_IRET
@@ -365,7 +365,7 @@ error_exit:
  * Xen event (virtual interrupt) entry point.
  */
 TRAP_ENTRY hypervisor_callback, 0
-#endif
+#endif /* CONFIG_PARAVIRT */
 
 ENTRY(asm_failsafe_callback)
 #ifdef CONFIG_PARAVIRT
-- 
2.20.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

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