From patchwork Tue Jul 18 16:58:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9849069 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 63FFF600CC for ; Tue, 18 Jul 2017 17:07:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47AB323B34 for ; Tue, 18 Jul 2017 17:07:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39431285C2; Tue, 18 Jul 2017 17:07:58 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM autolearn=unavailable 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 B486323B34 for ; Tue, 18 Jul 2017 17:07:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752673AbdGRRH2 (ORCPT ); Tue, 18 Jul 2017 13:07:28 -0400 Received: from mail-it0-f53.google.com ([209.85.214.53]:37664 "EHLO mail-it0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752251AbdGRRAJ (ORCPT ); Tue, 18 Jul 2017 13:00:09 -0400 Received: by mail-it0-f53.google.com with SMTP id v127so6945665itd.0 for ; Tue, 18 Jul 2017 10:00:09 -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=VpYnMlglPnVCmfktOSAHTQch804MdYvz/n57z6rGkQE=; b=dAY2OlDt2ekF5A7miJ0jp0864HBumtlLuJi5q/RjdH3ZuH7FDj4WIVs40M0pD6g7tH 4Ezpb187gcscILFrMtm421mb72xl2Docr9yXZkb6yI/+/Q3AVwY8LJ90wOFktyR+c4H4 QJDmLFSOW3f8Q2Sc8h3QT2ImrLJ6Cwyr3nCI8= 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=VpYnMlglPnVCmfktOSAHTQch804MdYvz/n57z6rGkQE=; b=ql9NNa7/fJHSKuzWpYqlU5aaaMKvJe9JWc6KOGKVnYrqgwKld1iVBtqifRP/n4iCQE 1gSW5LIaqfNCFB2eJ/pJEhAIijQZ/d2VoYaF/0JKuGmXigNJzfNKfm/AgGUubPlfC+a2 6TuLHfAIoKYUjdgWir6rsi8B3+V0LbSXq9Ml+a1trZVLa68bAYMw8LBnUev+gwsjMNSK WB3FZuLRXvK70jqUFaOpBn4tjb/QD5BL8LQE7McZm+SUa/vgeqezHarGvyyxNiu8RKx5 yD8fuka4dZToJM1sz2884Gg9p0R5houSrazRmxWVqCGczCsMFHIkMgtM0Z1j/GvCPSdc cNFQ== X-Gm-Message-State: AIVw113MPz0rWhLKVQdsRaEVSKdR6saaZCgR465MTCyTtmwKvMR6/4Oo Qq30Ty1kCI5l4kCA X-Received: by 10.36.124.67 with SMTP id a64mr3085347itd.25.1500397209271; Tue, 18 Jul 2017 10:00:09 -0700 (PDT) Received: from node.jintackl-qv26972.kvmarm-pg0.wisc.cloudlab.us (c220g1-030822.wisc.cloudlab.us. [128.104.222.82]) by smtp.gmail.com with ESMTPSA id j96sm1413075ioo.49.2017.07.18.10.00.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 10:00:08 -0700 (PDT) From: Jintack Lim To: kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com Cc: corbet@lwn.net, pbonzini@redhat.com, rkrcmar@redhat.com, linux@armlinux.org.uk, catalin.marinas@arm.com, will.deacon@arm.com, akpm@linux-foundation.org, mchehab@kernel.org, cov@codeaurora.org, daniel.lezcano@linaro.org, david.daney@cavium.com, mark.rutland@arm.com, suzuki.poulose@arm.com, stefan@hello-penguin.com, andy.gross@linaro.org, wcohen@redhat.com, ard.biesheuvel@linaro.org, shankerd@codeaurora.org, vladimir.murzin@arm.com, james.morse@arm.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Jintack Lim Subject: [RFC PATCH v2 20/38] KVM: arm64: Handle eret instruction traps Date: Tue, 18 Jul 2017 11:58:46 -0500 Message-Id: <1500397144-16232-21-git-send-email-jintack.lim@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1500397144-16232-1-git-send-email-jintack.lim@linaro.org> References: <1500397144-16232-1-git-send-email-jintack.lim@linaro.org> 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 instructions trap to EL2 with EC code 0x1A. Emulate eret instructions by setting pc and pstate. Note that the current exception level is always the virtual EL2, since we set HCR_EL2.NV bit only when entering the virtual EL2. So, we take spsr and elr states from the virtual _EL2 registers. Signed-off-by: Jintack Lim --- arch/arm64/include/asm/esr.h | 1 + arch/arm64/kvm/handle_exit.c | 16 ++++++++++++++++ arch/arm64/kvm/trace.h | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/arch/arm64/include/asm/esr.h b/arch/arm64/include/asm/esr.h index e7d8e28..210fde6 100644 --- a/arch/arm64/include/asm/esr.h +++ b/arch/arm64/include/asm/esr.h @@ -43,6 +43,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 17d8a16..9259881 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -147,6 +147,21 @@ static int kvm_handle_unknown_ec(struct kvm_vcpu *vcpu, struct kvm_run *run) return 1; } +static int kvm_handle_eret(struct kvm_vcpu *vcpu, struct kvm_run *run) +{ + trace_kvm_nested_eret(vcpu, vcpu_el2_sreg(vcpu, ELR_EL2), + vcpu_el2_sreg(vcpu, SPSR_EL2)); + + /* + * Note that the current exception level is always the virtual EL2, + * since we set HCR_EL2.NV bit only when entering the virtual EL2. + */ + *vcpu_pc(vcpu) = vcpu_el2_sreg(vcpu, ELR_EL2); + *vcpu_cpsr(vcpu) = vcpu_el2_sreg(vcpu, SPSR_EL2); + + return 1; +} + static exit_handle_fn arm_exit_handlers[] = { [0 ... ESR_ELx_EC_MAX] = kvm_handle_unknown_ec, [ESR_ELx_EC_WFx] = kvm_handle_wfx, @@ -160,6 +175,7 @@ static int kvm_handle_unknown_ec(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