From patchwork Sun Apr 23 17:09:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9695101 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5A19260245 for ; Sun, 23 Apr 2017 17:18:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 492D126530 for ; Sun, 23 Apr 2017 17:18:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DF97267EC; Sun, 23 Apr 2017 17:18:15 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 D16BC26530 for ; Sun, 23 Apr 2017 17:18:14 +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=yLEC7qO2/V2lsH16z2nITMAxpCkD2Xo76EyD2JOfqHI=; b=fYRvP7JM4cNC9u0aMzMTS3DN19 heIfYBrHKoXeSBAtzI+RmAvbE3OM31jWAH+B10SfZvVtsgwPwp3yARQ+jB7o3qrqHGizLxc6e9poW a7lnLNmspQqNfjvDmfyCuI5gJ+rmO+4yqqFJ0KSOZJV9TjyXJKewA+dgh/bco/4ofWgOuGfGnsg6O UQ3zB2b9BbzTkO/UPhQrfcgWCHQiAyZU//oA9Tvwp9arL3p6ZOtTv0AW/Fgit4VhbdO11m3Jt+r1p KhXGa0W3sJPhGW9tnDFzqih5zPg4/z3umcTObPfa1aP0rrGhiRQWHsJ0jX0x8BunQ+4X93p5/gCZg YFayJpNg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d2L9J-0007QY-Fl; Sun, 23 Apr 2017 17:18:13 +0000 Received: from mail-wr0-x235.google.com ([2a00:1450:400c:c0c::235]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d2L2B-0006Ry-QG for linux-arm-kernel@lists.infradead.org; Sun, 23 Apr 2017 17:11:05 +0000 Received: by mail-wr0-x235.google.com with SMTP id z109so79246060wrb.1 for ; Sun, 23 Apr 2017 10:10:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dD/gDXtpeXL3sbYU/9H+bXZsv7nIlJwX+qOrDL5YXng=; b=alJSlkiO7sgq21b8zmMM8dFXO6E15/s9eOmUnjp5d66CqfL2GyIvA6PDfEea33uaWY 7OPq1UGi+QYzK8GFHw2AUfZy5KVv0LXuJLkwwkoV2zx9FDmGXtjAJxLiSFOfWyTc600W 4ylVuFRm8qvVwZhqV8er7k22sckK/Ef61Qghk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dD/gDXtpeXL3sbYU/9H+bXZsv7nIlJwX+qOrDL5YXng=; b=GiDpmL+ce6fNwEG2dadtwF8SufIGzHOxj50jKeK2fUUcpa2Ge51ivMKyGbiPzqocED ywWNxGEWCLdB2MbGp1fThkU+i0ZcEuV7irYigDt8BRyZa6uQFqF9n4D0AStrcMkqmhFi 1lN+BPZXdWZ/9fLM9TuO9s0Xbpsy/VJrSI6ez58cFujG6kBuZxYVTNWVHjUHvC77m0Ns xO8WNLhHveREhrFLRR4dcgXd/ZQI4A5zlygW/BYC6v6RkD5YatAs+Z3/47uIyv2HKExy PP6n62MOauA+Zj9FfgRJ3Nih5nN6nyaAl2LuSyg17cceYCiq717cFqzw8HbaVVZ0CAqt HsXg== X-Gm-Message-State: AN3rC/6X28+dudlq0tGjPDgjU/ViPc+7394weRixYqNVZsKPxBU/enQJ QJRwc1pCo3ceAjdo X-Received: by 10.223.153.195 with SMTP id y61mr2674562wrb.96.1492967429903; Sun, 23 Apr 2017 10:10:29 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id 58sm2803521edz.2.2017.04.23.10.10.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 23 Apr 2017 10:10:29 -0700 (PDT) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PULL 55/79] ARM: KVM: Implement HVC_RESET_VECTORS stub hypercall in the init code Date: Sun, 23 Apr 2017 19:09:05 +0200 Message-Id: <20170423170929.27334-56-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170423170929.27334-1-cdall@linaro.org> References: <20170423170929.27334-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170423_101052_473367_F496B4D5 X-CRM114-Status: GOOD ( 13.80 ) 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: Marc Zyngier , Christoffer Dall , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org 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 From: Marc Zyngier In order to restore HYP mode to its original condition, KVM currently implements __kvm_hyp_reset(). As we're moving towards a hyp-stub defined API, it becomes necessary to implement HVC_RESET_VECTORS. This patch adds the HVC_RESET_VECTORS hypercall to the KVM init code, which so far lacked any form of hypercall support. Tested-by: Keerthy Acked-by: Russell King Acked-by: Catalin Marinas Signed-off-by: Marc Zyngier Signed-off-by: Christoffer Dall --- arch/arm/include/asm/virt.h | 1 + arch/arm/kernel/hyp-stub.S | 2 +- arch/arm/kvm/init.S | 33 +++++++++++++++++++++++++++------ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/arch/arm/include/asm/virt.h b/arch/arm/include/asm/virt.h index c5a2757..663adc0 100644 --- a/arch/arm/include/asm/virt.h +++ b/arch/arm/include/asm/virt.h @@ -54,6 +54,7 @@ static inline void sync_boot_mode(void) void __hyp_set_vectors(unsigned long phys_vector_base); unsigned long __hyp_get_vectors(void); +void __hyp_reset_vectors(void); #else #define __boot_cpu_mode (SVC_MODE) #define sync_boot_mode() diff --git a/arch/arm/kernel/hyp-stub.S b/arch/arm/kernel/hyp-stub.S index e637854..675c50f 100644 --- a/arch/arm/kernel/hyp-stub.S +++ b/arch/arm/kernel/hyp-stub.S @@ -280,7 +280,7 @@ ENDPROC(__hyp_reset_vectors) #endif .align 5 -__hyp_stub_vectors: +ENTRY(__hyp_stub_vectors) __hyp_stub_reset: W(b) . __hyp_stub_und: W(b) . __hyp_stub_svc: W(b) . diff --git a/arch/arm/kvm/init.S b/arch/arm/kvm/init.S index bf89c91..86a7008 100644 --- a/arch/arm/kvm/init.S +++ b/arch/arm/kvm/init.S @@ -23,6 +23,7 @@ #include #include #include +#include /******************************************************************** * Hypervisor initialization @@ -39,6 +40,10 @@ * - Setup the page tables * - Enable the MMU * - Profit! (or eret, if you only care about the code). + * + * Another possibility is to get a HYP stub hypercall. + * We discriminate between the two by checking if r0 contains a value + * that is less than HVC_STUB_HCALL_NR. */ .text @@ -58,6 +63,10 @@ __kvm_hyp_init: W(b) . __do_hyp_init: + @ Check for a stub hypercall + cmp r0, #HVC_STUB_HCALL_NR + blo __kvm_handle_stub_hvc + @ Set stack pointer mov sp, r0 @@ -112,19 +121,31 @@ __do_hyp_init: eret - @ r0 : stub vectors address +ENTRY(__kvm_handle_stub_hvc) + cmp r0, #HVC_RESET_VECTORS + bne 1f ENTRY(__kvm_hyp_reset) /* We're now in idmap, disable MMU */ mrc p15, 4, r1, c1, c0, 0 @ HSCTLR - ldr r2, =(HSCTLR_M | HSCTLR_A | HSCTLR_C | HSCTLR_I) - bic r1, r1, r2 + ldr r0, =(HSCTLR_M | HSCTLR_A | HSCTLR_C | HSCTLR_I) + bic r1, r1, r0 mcr p15, 4, r1, c1, c0, 0 @ HSCTLR - /* Install stub vectors */ - mcr p15, 4, r0, c12, c0, 0 @ HVBAR - isb + /* + * Install stub vectors, using ardb's VA->PA trick. + */ +0: adr r0, 0b @ PA(0) + movw r1, #:lower16:__hyp_stub_vectors - 0b @ VA(stub) - VA(0) + movt r1, #:upper16:__hyp_stub_vectors - 0b + add r1, r1, r0 @ PA(stub) + mcr p15, 4, r1, c12, c0, 0 @ HVBAR + b exit + +1: ldr r0, =HVC_STUB_ERR +exit: eret +ENDPROC(__kvm_handle_stub_hvc) ENDPROC(__kvm_hyp_reset) .ltorg