From patchwork Wed Sep 26 13:56:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Thierry X-Patchwork-Id: 10616043 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7AAEE913 for ; Wed, 26 Sep 2018 14:04:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7402728B26 for ; Wed, 26 Sep 2018 14:04:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67A7A29BB2; Wed, 26 Sep 2018 14:04:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B3A3328B26 for ; Wed, 26 Sep 2018 14:03:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=9qElvygRK57PinZ8QhGfCJprkyd3XFS141yugK9jqG0=; b=dvgi7YbD4ytYtAI47jCm4sIyXO BW0kpAUgaVBqVMMqQd4XuS+wmttUBZDoYpAfi6bfZ0N3Yk3y5g4daQLpBFss0SZ/QsGtntt49DhPt oWiwxmgqPlm+vjs54qCLdpIF5s1gbgNLPOinK4iDKAmMQAeBD+g2VHSSoH8V8U6uwY86rTjfKoOeY vtuVX+JNfwWTTu4Co9f40nYyf2tl/IhrII8AKXfhOArJGr0L4q0dk+VpEgua3MelnmrGAl1YjyBJD jljFg7B5rbwt7Dm9H+8EUNn+4/6cG34e1sKODZyLUFUnnUPSM0DLy2xpED9Q1if5bw47W9uK2PqvJ oNDiHiQw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5APs-0002v1-FF; Wed, 26 Sep 2018 14:03:48 +0000 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70] helo=foss.arm.com) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5AKL-0007XX-2n for linux-arm-kernel@lists.infradead.org; Wed, 26 Sep 2018 13:58:24 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 5985216A3; Wed, 26 Sep 2018 06:56:43 -0700 (PDT) Received: from e112298-lin.Emea.Arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id A9B403F5B3; Wed, 26 Sep 2018 06:56:41 -0700 (PDT) From: Julien Thierry To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 7/7] arm64: kvm: Align stack for exception coming from EL2 Date: Wed, 26 Sep 2018 14:56:24 +0100 Message-Id: <1537970184-44348-8-git-send-email-julien.thierry@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1537970184-44348-1-git-send-email-julien.thierry@arm.com> References: <1537970184-44348-1-git-send-email-julien.thierry@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180926_065805_193571_B57F60A9 X-CRM114-Status: GOOD ( 12.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Julien Thierry , marc.zyngier@arm.com, catalin.marinas@arm.com, will.deacon@arm.com, christoffer.dall@arm.com, kvmarm@lists.cs.columbia.edu, james.morse@arm.com, Dave.Martin@arm.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP SP needs to be 16-bytes aligned before accessing memory through it. When handling exceptions from EL2, there is no guarantee that SP is already aligned. Ensure SP is aligned upon entries from EL2. Signed-off-by: Julien Thierry Cc: kvmarm@lists.cs.columbia.edu --- arch/arm64/kvm/hyp/hyp-entry.S | 63 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 11 deletions(-) -- 1.9.1 diff --git a/arch/arm64/kvm/hyp/hyp-entry.S b/arch/arm64/kvm/hyp/hyp-entry.S index da31386..f611072 100644 --- a/arch/arm64/kvm/hyp/hyp-entry.S +++ b/arch/arm64/kvm/hyp/hyp-entry.S @@ -184,6 +184,10 @@ el2_error: ccmp x0, x1, #4, ne b.ne __hyp_panic mov x0, #(1 << ARM_EXIT_WITH_SERROR_BIT) + + /* Restore the stack */ + ldr x1, [sp] + mov sp, x1 eret ENTRY(__hyp_do_panic) @@ -221,29 +225,66 @@ ENDPROC(\label) .align 11 -.macro valid_vect target +/* + * Aligns the stack and stores the old sp value. This is what the stack + * looks like after this code: + * + * +--------+ + * | | + * |--------|--> old_sp (upon entry) + * | x1 |--> (only used for local save/restore) + * |--------|--> old_sp - 8 + * | |--> padding + * |--------|--> aligned_sp + 8 + * | old_sp | + * |--------|--> sp = aligned_sp + * | | + * +--------+ + */ +.macro align_sp_el2 + xchg_sp x0 + str x1, [x0, #-8] // save x1 + mov x1, x0 // x1 = old_sp + sub x0, x0, #0x10 // save space for x1 + old_sp + bic x0, x0, #0xf // align down to 16-bytes + xchg_sp x0 + str x1, [sp] // save old_sp + ldr x1, [x1, #-8] +.endm + +.macro valid_vect target, el=1 .align 7 + .if \el == 2 + align_sp_el2 + .endif + stp x0, x1, [sp, #-16]! b \target .endm -.macro invalid_vect target +.macro invalid_vect target, el=1 .align 7 + .if \el == 2 + align_sp_el2 + .endif + b \target + .if \el == 1 ldp x0, x1, [sp], #16 b \target + .endif .endm ENTRY(__kvm_hyp_vector) - invalid_vect el2t_sync_invalid // Synchronous EL2t - invalid_vect el2t_irq_invalid // IRQ EL2t - invalid_vect el2t_fiq_invalid // FIQ EL2t - invalid_vect el2t_error_invalid // Error EL2t - - invalid_vect el2h_sync_invalid // Synchronous EL2h - invalid_vect el2h_irq_invalid // IRQ EL2h - invalid_vect el2h_fiq_invalid // FIQ EL2h - valid_vect el2_error // Error EL2h + invalid_vect el2t_sync_invalid, 2 // Synchronous EL2t + invalid_vect el2t_irq_invalid, 2 // IRQ EL2t + invalid_vect el2t_fiq_invalid, 2 // FIQ EL2t + invalid_vect el2t_error_invalid, 2 // Error EL2t + + invalid_vect el2h_sync_invalid, 2 // Synchronous EL2h + invalid_vect el2h_irq_invalid, 2 // IRQ EL2h + invalid_vect el2h_fiq_invalid, 2 // FIQ EL2h + valid_vect el2_error, 2 // Error EL2h valid_vect el1_sync // Synchronous 64-bit EL1 valid_vect el1_irq // IRQ 64-bit EL1