From patchwork Mon Jan 9 06:24:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9503803 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 1FCA960757 for ; Mon, 9 Jan 2017 06:26:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0EAA1280D0 for ; Mon, 9 Jan 2017 06:26:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 01D872815E; Mon, 9 Jan 2017 06:26:36 +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=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81F4F280D0 for ; Mon, 9 Jan 2017 06:26:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S939805AbdAIG02 (ORCPT ); Mon, 9 Jan 2017 01:26:28 -0500 Received: from outprodmail01.cc.columbia.edu ([128.59.72.39]:38100 "EHLO outprodmail01.cc.columbia.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S939471AbdAIGZw (ORCPT ); Mon, 9 Jan 2017 01:25:52 -0500 Received: from hazelnut (hazelnut.cc.columbia.edu [128.59.213.250]) by outprodmail01.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096PWXt017300 for ; Mon, 9 Jan 2017 01:25:50 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id A36FA7E for ; Mon, 9 Jan 2017 01:25:50 -0500 (EST) Received: from sendprodmail01.cc.columbia.edu (sendprodmail01.cc.columbia.edu [128.59.72.13]) by hazelnut (Postfix) with ESMTP id 8B6DC7E for ; Mon, 9 Jan 2017 01:25:50 -0500 (EST) Received: from mail-qk0-f199.google.com (mail-qk0-f199.google.com [209.85.220.199]) by sendprodmail01.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096PoIX040757 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 9 Jan 2017 01:25:50 -0500 Received: by mail-qk0-f199.google.com with SMTP id a16so37631589qkc.6 for ; Sun, 08 Jan 2017 22:25:50 -0800 (PST) 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=iKrB02l1+upsSyM7gOCrVgKe6rhXPD5nuEBA9ApHGzo=; b=XBZtk288UPTpKhtKx8U3EAH/rAfIIgJGeaxc/gqW0vY1FttOdyfAd0nG20b58sh3gt wS0mlN36O1wRL/93ltCfvZqWdsEYdQuRsVw2xW1XQ+KD1b+sH40YXfvvMSrfdY+QYncf VTyrJsbmFmRKa9PulVRwXn7rvbnhAdvBSKdN2WodefocaM6ieiMIOyBOqpw9fDRSmWcP B4xZceoUQNWPcfwpEwjn3hwHR1h9qI4ruZ8fjGEbJ1ZHjxAr0JzH4BIy0QfVGcQpISn/ GR0z5uBFlbeuOvYAYhGKrWXwvI7qgLcahoglY9HdtIQqqX47fhooP0BSzJzEaXNXdF9a +eRw== X-Gm-Message-State: AIkVDXJwkSUGKNKNVdNeUmgTnOLNt1p/w9S1bSbvuTiTGg4p0OXMe11ti+mnG5ybe4KYUUNacp1kEUNpBHec+uHoQSMkgjmheMUggqdI6gZXw2m/4QMyZwqR9xbpmjET3lLp1tVvysd2vvs= X-Received: by 10.55.76.82 with SMTP id z79mr6563564qka.20.1483943149777; Sun, 08 Jan 2017 22:25:49 -0800 (PST) X-Received: by 10.55.76.82 with SMTP id z79mr6563539qka.20.1483943149629; Sun, 08 Jan 2017 22:25:49 -0800 (PST) Received: from jintack.cs.columbia.edu ([2001:18d8:ffff:16:21a:4aff:feaa:f900]) by smtp.gmail.com with ESMTPSA id h3sm8623257qtc.6.2017.01.08.22.25.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Jan 2017 22:25:48 -0800 (PST) From: Jintack Lim To: christoffer.dall@linaro.org, marc.zyngier@arm.com, pbonzini@redhat.com, rkrcmar@redhat.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, vladimir.murzin@arm.com, suzuki.poulose@arm.com, mark.rutland@arm.com, james.morse@arm.com, lorenzo.pieralisi@arm.com, kevin.brodsky@arm.com, wcohen@redhat.com, shankerd@codeaurora.org, geoff@infradead.org, andre.przywara@arm.com, eric.auger@redhat.com, anna-maria@linutronix.de, shihwei@cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: jintack@cs.columbia.edu Subject: [RFC 13/55] KVM: arm64: Handle eret instruction traps Date: Mon, 9 Jan 2017 01:24:09 -0500 Message-Id: <1483943091-1364-14-git-send-email-jintack@cs.columbia.edu> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1483943091-1364-1-git-send-email-jintack@cs.columbia.edu> References: <1483943091-1364-1-git-send-email-jintack@cs.columbia.edu> X-No-Spam-Score: Local X-Scanned-By: MIMEDefang 2.78 on 128.59.72.13 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When HCR.NV bit is set, eret instruction execution in the guest hypervisor will trap with EC code 0x1A. Let ELR_EL2 and SPSR_EL2 state from the guest's perspective be restored to the hardware on the next guest entry. Signed-off-by: Jintack Lim --- arch/arm64/include/asm/esr.h | 1 + arch/arm64/kvm/handle_exit.c | 12 ++++++++++++ arch/arm64/kvm/trace.h | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/arch/arm64/include/asm/esr.h b/arch/arm64/include/asm/esr.h index d14c478..f32e3a7 100644 --- a/arch/arm64/include/asm/esr.h +++ b/arch/arm64/include/asm/esr.h @@ -42,6 +42,7 @@ #define ESR_ELx_EC_HVC64 (0x16) #define ESR_ELx_EC_SMC64 (0x17) #define ESR_ELx_EC_SYS64 (0x18) +#define ESR_ELx_EC_ERET (0x1A) /* Unallocated EC: 0x19 - 0x1E */ #define ESR_ELx_EC_IMP_DEF (0x1f) #define ESR_ELx_EC_IABT_LOW (0x20) diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index a204adf..4e4a915 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -125,6 +125,17 @@ static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu, struct kvm_run *run) return ret; } +static int kvm_handle_eret(struct kvm_vcpu *vcpu, struct kvm_run *run) +{ + trace_kvm_nested_eret(vcpu, vcpu_el2_reg(vcpu, ELR_EL2), + vcpu_el2_reg(vcpu, SPSR_EL2)); + + *vcpu_pc(vcpu) = vcpu_el2_reg(vcpu, ELR_EL2); + *vcpu_cpsr(vcpu) = vcpu_el2_reg(vcpu, SPSR_EL2); + + return 1; +} + static exit_handle_fn arm_exit_handlers[] = { [ESR_ELx_EC_WFx] = kvm_handle_wfx, [ESR_ELx_EC_CP15_32] = kvm_handle_cp15_32, @@ -137,6 +148,7 @@ static int kvm_handle_guest_debug(struct kvm_vcpu *vcpu, struct kvm_run *run) [ESR_ELx_EC_HVC64] = handle_hvc, [ESR_ELx_EC_SMC64] = handle_smc, [ESR_ELx_EC_SYS64] = kvm_handle_sys_reg, + [ESR_ELx_EC_ERET] = kvm_handle_eret, [ESR_ELx_EC_IABT_LOW] = kvm_handle_guest_abort, [ESR_ELx_EC_DABT_LOW] = kvm_handle_guest_abort, [ESR_ELx_EC_SOFTSTP_LOW]= kvm_handle_guest_debug, diff --git a/arch/arm64/kvm/trace.h b/arch/arm64/kvm/trace.h index 7c86cfb..5f40987 100644 --- a/arch/arm64/kvm/trace.h +++ b/arch/arm64/kvm/trace.h @@ -187,6 +187,27 @@ TP_printk("vcpu: %p, inject exception to vEL2: ESR_EL2 0x%lx, vector: 0x%016lx", __entry->vcpu, __entry->esr_el2, __entry->pc) ); + +TRACE_EVENT(kvm_nested_eret, + TP_PROTO(struct kvm_vcpu *vcpu, unsigned long elr_el2, + unsigned long spsr_el2), + TP_ARGS(vcpu, elr_el2, spsr_el2), + + TP_STRUCT__entry( + __field(struct kvm_vcpu *, vcpu) + __field(unsigned long, elr_el2) + __field(unsigned long, spsr_el2) + ), + + TP_fast_assign( + __entry->vcpu = vcpu; + __entry->elr_el2 = elr_el2; + __entry->spsr_el2 = spsr_el2; + ), + + TP_printk("vcpu: %p, eret to elr_el2: 0x%016lx, with spsr_el2: 0x%08lx", + __entry->vcpu, __entry->elr_el2, __entry->spsr_el2) +); #endif /* _TRACE_ARM64_KVM_H */ #undef TRACE_INCLUDE_PATH