From: Marc Zyngier <marc.zyngier@arm.com>
To: Christoffer Dall <christoffer.dall@linaro.org>
Cc: linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org,
kvmarm@lists.cs.columbia.edu
Subject: Re: [PATCH v2 18/28] ARM: KVM: Add HYP mode entry code
Date: Wed, 10 Feb 2016 16:02:14 +0000 [thread overview]
Message-ID: <56BB5F06.9000606@arm.com> (raw)
In-Reply-To: <20160209170042.GA5171@cbox>
On 09/02/16 17:00, Christoffer Dall wrote:
> On Thu, Feb 04, 2016 at 11:00:35AM +0000, Marc Zyngier wrote:
>> This part is almost entierely borrowed from the existing code, just
>> slightly simplifying the HYP function call (as we now save SPSR_hyp
>> in the world switch).
>>
>> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
>> ---
>> arch/arm/kvm/hyp/Makefile | 1 +
>> arch/arm/kvm/hyp/hyp-entry.S | 157 +++++++++++++++++++++++++++++++++++++++++++
>> arch/arm/kvm/hyp/hyp.h | 2 +
>> 3 files changed, 160 insertions(+)
>> create mode 100644 arch/arm/kvm/hyp/hyp-entry.S
>>
>> diff --git a/arch/arm/kvm/hyp/Makefile b/arch/arm/kvm/hyp/Makefile
>> index cfab402..a7d3a7e 100644
>> --- a/arch/arm/kvm/hyp/Makefile
>> +++ b/arch/arm/kvm/hyp/Makefile
>> @@ -9,4 +9,5 @@ obj-$(CONFIG_KVM_ARM_HOST) += vgic-v2-sr.o
>> obj-$(CONFIG_KVM_ARM_HOST) += vfp.o
>> obj-$(CONFIG_KVM_ARM_HOST) += banked-sr.o
>> obj-$(CONFIG_KVM_ARM_HOST) += entry.o
>> +obj-$(CONFIG_KVM_ARM_HOST) += hyp-entry.o
>> obj-$(CONFIG_KVM_ARM_HOST) += switch.o
>> diff --git a/arch/arm/kvm/hyp/hyp-entry.S b/arch/arm/kvm/hyp/hyp-entry.S
>> new file mode 100644
>> index 0000000..44bc11f
>> --- /dev/null
>> +++ b/arch/arm/kvm/hyp/hyp-entry.S
>> @@ -0,0 +1,157 @@
>> +/*
>> + * Copyright (C) 2012 - Virtual Open Systems and Columbia University
>> + * Author: Christoffer Dall <c.dall@virtualopensystems.com>
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License, version 2, as
>> + * published by the Free Software Foundation.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>> + * GNU General Public License for more details.
>> + *
>> + * You should have received a copy of the GNU General Public License
>> + * along with this program; if not, write to the Free Software
>> + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
>> + */
>> +
>> +#include <linux/linkage.h>
>> +#include <asm/kvm_arm.h>
>> +#include <asm/kvm_asm.h>
>> +
>> + .arch_extension virt
>> +
>> + .text
>> + .pushsection .hyp.text, "ax"
>> +
>> +.macro load_vcpu reg
>> + mrc p15, 4, \reg, c13, c0, 2 @ HTPIDR
>> +.endm
>> +
>> +/********************************************************************
>> + * Hypervisor exception vector and handlers
>> + *
>> + *
>> + * The KVM/ARM Hypervisor ABI is defined as follows:
>> + *
>> + * Entry to Hyp mode from the host kernel will happen _only_ when an HVC
>> + * instruction is issued since all traps are disabled when running the host
>> + * kernel as per the Hyp-mode initialization at boot time.
>> + *
>> + * HVC instructions cause a trap to the vector page + offset 0x14 (see hyp_hvc
>> + * below) when the HVC instruction is called from SVC mode (i.e. a guest or the
>> + * host kernel) and they cause a trap to the vector page + offset 0x8 when HVC
>> + * instructions are called from within Hyp-mode.
>> + *
>> + * Hyp-ABI: Calling HYP-mode functions from host (in SVC mode):
>> + * Switching to Hyp mode is done through a simple HVC #0 instruction. The
>> + * exception vector code will check that the HVC comes from VMID==0.
>> + * - r0 contains a pointer to a HYP function
>> + * - r1, r2, and r3 contain arguments to the above function.
>> + * - The HYP function will be called with its arguments in r0, r1 and r2.
>> + * On HYP function return, we return directly to SVC.
>> + *
>> + * Note that the above is used to execute code in Hyp-mode from a host-kernel
>> + * point of view, and is a different concept from performing a world-switch and
>> + * executing guest code SVC mode (with a VMID != 0).
>> + */
>> +
>> + .align 5
>> +__hyp_vector:
>> + .global __hyp_vector
>> +__kvm_hyp_vector:
>> + .weak __kvm_hyp_vector
>> +
>> + @ Hyp-mode exception vector
>> + W(b) hyp_reset
>> + W(b) hyp_undef
>> + W(b) hyp_svc
>> + W(b) hyp_pabt
>> + W(b) hyp_dabt
>> + W(b) hyp_hvc
>> + W(b) hyp_irq
>> + W(b) hyp_fiq
>> +
>> +.macro invalid_vector label, cause
>> + .align
>> +\label: b .
>> +.endm
>> +
>> + invalid_vector hyp_reset
>> + invalid_vector hyp_undef
>> + invalid_vector hyp_svc
>> + invalid_vector hyp_pabt
>> + invalid_vector hyp_dabt
>> + invalid_vector hyp_fiq
>> +
>> +hyp_hvc:
>> + /*
>> + * Getting here is either because of a trap from a guest,
>> + * or from executing HVC from the host kernel, which means
>> + * "do something in Hyp mode".
>> + */
>> + push {r0, r1, r2}
>> +
>> + @ Check syndrome register
>> + mrc p15, 4, r1, c5, c2, 0 @ HSR
>> + lsr r0, r1, #HSR_EC_SHIFT
>> + cmp r0, #HSR_EC_HVC
>> + bne guest_trap @ Not HVC instr.
>> +
>> + /*
>> + * Let's check if the HVC came from VMID 0 and allow simple
>> + * switch to Hyp mode
>> + */
>> + mrrc p15, 6, r0, r2, c2
>> + lsr r2, r2, #16
>> + and r2, r2, #0xff
>> + cmp r2, #0
>> + bne guest_trap @ Guest called HVC
>> +
>> + /*
>> + * Getting here means host called HVC, we shift parameters and branch
>> + * to Hyp function.
>> + */
>> + pop {r0, r1, r2}
>> +
>> + /* Check for __hyp_get_vectors */
>> + cmp r0, #-1
>> + mrceq p15, 4, r0, c12, c0, 0 @ get HVBAR
>> + beq 1f
>> +
>> + push {lr}
>> +
>> + mov lr, r0
>> + mov r0, r1
>> + mov r1, r2
>> + mov r2, r3
>> +
>> +THUMB( orr lr, #1)
>> + blx lr @ Call the HYP function
>> +
>> + pop {lr}
>> +1: eret
>> +
>> +guest_trap:
>> + load_vcpu r0 @ Load VCPU pointer to r0
>> +
>> + @ Check if we need the fault information
>
> nit: this is not about faults at this point, so this comment should
> either go or be reworded to "let's check if we trapped on guest VFP
> access"
>
> and I think the lsr can be moved into the ifdef as well.
Yes, both good points.
Thanks,
M.
--
Jazz is not dead. It just smells funny...
next prev parent reply other threads:[~2016-02-10 16:02 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-04 11:00 [PATCH v2 00/28] ARM: KVM: Rewrite the world switch in C (mostly) Marc Zyngier
2016-02-04 11:00 ` [PATCH v2 01/28] ARM: KVM: Move the HYP code to its own section Marc Zyngier
2016-02-09 18:39 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 02/28] ARM: KVM: Remove __kvm_hyp_code_start/__kvm_hyp_code_end Marc Zyngier
2016-02-09 18:39 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 03/28] ARM: KVM: Move VFP registers to a CPU context structure Marc Zyngier
2016-02-09 18:42 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 04/28] ARM: KVM: Move CP15 array into the " Marc Zyngier
2016-02-09 18:42 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 05/28] ARM: KVM: Move GP registers " Marc Zyngier
2016-02-09 18:42 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 06/28] ARM: KVM: Add a HYP-specific header file Marc Zyngier
2016-02-09 18:42 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 07/28] ARM: KVM: Add system register accessor macros Marc Zyngier
2016-02-10 17:25 ` Christoffer Dall
2016-02-10 17:32 ` Marc Zyngier
2016-02-04 11:00 ` [PATCH v2 08/28] ARM: KVM: Add TLB invalidation code Marc Zyngier
2016-02-09 18:42 ` Christoffer Dall
2016-02-10 15:32 ` Marc Zyngier
2016-02-04 11:00 ` [PATCH v2 09/28] ARM: KVM: Add CP15 save/restore code Marc Zyngier
2016-02-09 18:42 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 10/28] ARM: KVM: Add timer save/restore Marc Zyngier
2016-02-09 18:42 ` Christoffer Dall
2016-02-10 15:36 ` Marc Zyngier
2016-02-04 11:00 ` [PATCH v2 11/28] ARM: KVM: Add vgic v2 save/restore Marc Zyngier
2016-02-09 18:42 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 12/28] ARM: KVM: Add VFP save/restore Marc Zyngier
2016-02-09 18:42 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 13/28] ARM: KVM: Add banked registers save/restore Marc Zyngier
2016-02-09 18:42 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 14/28] ARM: KVM: Add guest entry code Marc Zyngier
2016-02-09 18:44 ` Christoffer Dall
2016-02-10 15:48 ` Marc Zyngier
2016-02-04 11:00 ` [PATCH v2 15/28] ARM: KVM: Add VFP lazy save/restore handler Marc Zyngier
2016-02-09 18:44 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 16/28] ARM: KVM: Add the new world switch implementation Marc Zyngier
2016-02-09 18:44 ` Christoffer Dall
2016-02-10 16:00 ` Marc Zyngier
2016-02-04 11:00 ` [PATCH v2 17/28] ARM: KVM: Add populating of fault data structure Marc Zyngier
2016-02-09 18:44 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 18/28] ARM: KVM: Add HYP mode entry code Marc Zyngier
2016-02-09 17:00 ` Christoffer Dall
2016-02-10 16:02 ` Marc Zyngier [this message]
2016-02-10 17:23 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 19/28] ARM: KVM: Add panic handling code Marc Zyngier
2016-02-09 18:45 ` Christoffer Dall
2016-02-10 16:03 ` Marc Zyngier
2016-02-04 11:00 ` [PATCH v2 20/28] ARM: KVM: Change kvm_call_hyp return type to unsigned long Marc Zyngier
2016-02-09 18:28 ` Christoffer Dall
2016-02-10 16:07 ` Marc Zyngier
2016-02-04 11:00 ` [PATCH v2 21/28] ARM: KVM: Remove the old world switch Marc Zyngier
2016-02-09 18:45 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 22/28] ARM: KVM: Switch to C-based stage2 init Marc Zyngier
2016-02-09 18:45 ` Christoffer Dall
2016-02-10 7:42 ` Marc Zyngier
2016-02-10 8:04 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 23/28] ARM: KVM: Remove __weak attributes Marc Zyngier
2016-02-09 18:45 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 24/28] ARM: KVM: Turn CP15 defines to an enum Marc Zyngier
2016-02-09 18:45 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 25/28] ARM: KVM: Cleanup asm-offsets.c Marc Zyngier
2016-02-09 18:45 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 26/28] ARM: KVM: Remove unused hyp_pc field Marc Zyngier
2016-02-09 18:39 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 27/28] ARM: KVM: Remove handling of ARM_EXCEPTION_DATA/PREF_ABORT Marc Zyngier
2016-02-09 18:39 ` Christoffer Dall
2016-02-04 11:00 ` [PATCH v2 28/28] ARM: KVM: Remove __kvm_hyp_exit/__kvm_hyp_exit_end Marc Zyngier
2016-02-09 18:39 ` Christoffer Dall
2016-02-09 18:49 ` [PATCH v2 00/28] ARM: KVM: Rewrite the world switch in C (mostly) Christoffer Dall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56BB5F06.9000606@arm.com \
--to=marc.zyngier@arm.com \
--cc=christoffer.dall@linaro.org \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).