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

[UNIKRAFT PATCH RFCv3 32/32] plat/kvm/arm: Fix x19 corruption by interrupt handler



There is a crashing when testing nginx on arm64:
        [0x401015bc] trap_el1_sync+0x50/0x58
        [0x4010209c] el1_sync+0x9c/0x100
        [0x401169c0] _vprint+0x158/0x318
        [0x40116ce0] _uk_vprintk+0x64/0x74
        [0x40116d74] _uk_printk+0x84/0x90
        [0x4017f2e8] netif_alloc_rxpkts+0xd0/0x1f8
        [0x4010e5d0] virtio_netdev_rx_fillup+0x78/0x2a4
        [0x4010f298] virtio_netdev_recv+0x20c/0x400
        [0x4017eddc] uk_netdev_rx_one+0x2c8/0x2d0
        [0x4017f8a4] uknetdev_input+0x158/0x348
        [0x4013e5fc] _dispatcher+0x110/0x114
        [0x4011d478] uk_sched_thread_exit+0/0xbc
        [0x40218f44] uk_free+0x1c/0x28
        [0x40219030] free+0x18/0x20
        [0x4012a300] sys_write+0x17c/0x188
        [0x4012dcfc] pwritev+0x6c/0xd0
        [...]

Previously, x18,x19 are incorrectly restored by old _sp_. x18 can be
used/restore freely, but x19 is callee save register which can't be
corrupted.

Besides, this adds ENTRY() for el1_irq/el1_sync, which can prevent
gcc messed up registers in interrupt handler.

Signed-off-by: Jia He <justin.he@xxxxxxx>
---
 plat/kvm/arm/exceptions.S | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/plat/kvm/arm/exceptions.S b/plat/kvm/arm/exceptions.S
index 929d900..e0f4cb2 100644
--- a/plat/kvm/arm/exceptions.S
+++ b/plat/kvm/arm/exceptions.S
@@ -111,6 +111,7 @@
 .macro LEAVE_TRAP, el
        /* Mask IRQ to make sure restore would not be interrupted by IRQ */
        msr daifset, #2
+
        /* Restore pstate and exception status register */
        ldp x22, x23, [sp, #16 * 16]
        msr spsr_el1, x22
@@ -126,6 +127,7 @@
        ldp x24, x25, [sp, #16 * 12]
        ldp x22, x23, [sp, #16 * 11]
        ldp x20, x21, [sp, #16 * 10]
+       ldp x18, x19, [sp, #16 * 9]
        ldp x16, x17, [sp, #16 * 8]
        ldp x14, x15, [sp, #16 * 7]
        ldp x12, x13, [sp, #16 * 6]
@@ -136,6 +138,7 @@
        ldp x2, x3, [sp, #16 * 1]
        ldp x0, x1, [sp, #16 * 0]
 
+       /* x18 can be used freely */
 .if \el == 0
        /* Restore stack pointer for exception from EL0 */
        ldr x18, [sp, #__SP_EL0_OFFSET]
@@ -147,9 +150,6 @@
 .endif
        add sp, sp, #__TRAP_STACK_SIZE
 
-       /* Restore x18,x19 */
-       ldp x18, x19, [sp, #16 * 9]
-
        eret
 .endm
 
-- 
2.17.1




 


Rackspace

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