From patchwork Tue Jul 18 16:59:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9848993 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 3BA1C600CC for ; Tue, 18 Jul 2017 17:02:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 257B7285BD for ; Tue, 18 Jul 2017 17:02:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 197C1285CB; Tue, 18 Jul 2017 17:02:19 +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 06E6C285CE for ; Tue, 18 Jul 2017 17:02:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752521AbdGRRCP (ORCPT ); Tue, 18 Jul 2017 13:02:15 -0400 Received: from mail-it0-f51.google.com ([209.85.214.51]:34105 "EHLO mail-it0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752496AbdGRRAg (ORCPT ); Tue, 18 Jul 2017 13:00:36 -0400 Received: by mail-it0-f51.google.com with SMTP id v205so2303743itf.1 for ; Tue, 18 Jul 2017 10:00:36 -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=G5Qtvk8sUMgkpfcgAgzvw9AkE1w5H7uqMAoeWmMPdMY=; b=VHEnrJLEM8CTjaGMr8suIDxb7fNm7v5DygQWq5iRnkhpNGd1wWKPbUnnmluqSNbpw3 /txLc5kVd4fsXzOEJfLDTi5sq7SlPKZfNTeSb7ogaog1rxcgiXahiM2woBbLGdo8Xk/E 13WRn3YLIS736hzDrb2N4OOcYmulxEny3pgGA= 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=G5Qtvk8sUMgkpfcgAgzvw9AkE1w5H7uqMAoeWmMPdMY=; b=Y5f0QJVSiaPAWCwU9JKfJB+JlPsM42NOs4ucmvUC2yUQjqfVtp62z6K1dtAdkmkEvr PfLfI+AK6agu3UBPrYgidBULzoBduq5oyfxmpeTS1jmk0JM7VvSIlVSGOj/MkXP2TmJQ gyF4CanfVTuAIrRNdHDooyD4BHjUWrX7Alb5GezmhvtSHr14vHf6Y1yqUW44+clfUw+/ LAGHYX5KM5OTmJSC3KWhIW4Fej4YoPw8byZJOZ4QwJcTSZbpu+t0zl3wIFMMyuCPqmou ia2KztnUb3rNUfH5tL/Q4LKPLCSLdyK76kN9MIHHxmp0GkcqQiGk1CDe5jPXXe63+6x9 5Hng== X-Gm-Message-State: AIVw111uY48rBa5AiBGQHSS3+Ny+4aNBiyqzmgHTmWW4pkUN+TopZDOU m35vk7Qmtt6yJOCK X-Received: by 10.36.198.6 with SMTP id j6mr3602095itg.100.1500397235829; Tue, 18 Jul 2017 10:00:35 -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.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 10:00:35 -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 34/38] KVM: arm64: Respect the virtual HCR_EL2.NV bit setting Date: Tue, 18 Jul 2017 11:59:00 -0500 Message-Id: <1500397144-16232-35-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 Forward traps due to HCR_EL2.NV bit to the virtual EL2 if they are not coming from the virtual EL2 and the virtual HCR_EL2.NV bit is set. This is for recursive nested virtualization. Signed-off-by: Jintack Lim --- arch/arm64/include/asm/kvm_arm.h | 1 + arch/arm64/include/asm/kvm_coproc.h | 1 + arch/arm64/kvm/handle_exit.c | 13 +++++++++++++ arch/arm64/kvm/sys_regs.c | 22 ++++++++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h index 6e99978..aeaac4e 100644 --- a/arch/arm64/include/asm/kvm_arm.h +++ b/arch/arm64/include/asm/kvm_arm.h @@ -23,6 +23,7 @@ #include /* Hyp Configuration Register (HCR) bits */ +#define HCR_NV (UL(1) << 42) #define HCR_E2H (UL(1) << 34) #define HCR_ID (UL(1) << 33) #define HCR_CD (UL(1) << 32) diff --git a/arch/arm64/include/asm/kvm_coproc.h b/arch/arm64/include/asm/kvm_coproc.h index 1b3d21b..6223df6 100644 --- a/arch/arm64/include/asm/kvm_coproc.h +++ b/arch/arm64/include/asm/kvm_coproc.h @@ -44,6 +44,7 @@ void kvm_register_target_sys_reg_table(unsigned int target, int kvm_handle_cp15_32(struct kvm_vcpu *vcpu, struct kvm_run *run); int kvm_handle_cp15_64(struct kvm_vcpu *vcpu, struct kvm_run *run); int kvm_handle_sys(struct kvm_vcpu *vcpu, struct kvm_run *run); +bool forward_nv_traps(struct kvm_vcpu *vcpu); #define kvm_coproc_table_init kvm_sys_reg_table_init void kvm_sys_reg_table_init(void); diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c index d4e7b2b..fccd9d6 100644 --- a/arch/arm64/kvm/handle_exit.c +++ b/arch/arm64/kvm/handle_exit.c @@ -61,6 +61,12 @@ static int handle_smc(struct kvm_vcpu *vcpu, struct kvm_run *run) { int ret; + /* + * Forward this trapped smc instruction to the virtual EL2. + */ + if (forward_nv_traps(vcpu) && (vcpu_sys_reg(vcpu, HCR_EL2) & HCR_TSC)) + return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_hsr(vcpu)); + /* If imm is non-zero, it's not defined */ if (kvm_vcpu_hvc_get_imm(vcpu)) { kvm_inject_undefined(vcpu); @@ -197,6 +203,13 @@ static int kvm_handle_eret(struct kvm_vcpu *vcpu, struct kvm_run *run) vcpu_el2_sreg(vcpu, SPSR_EL2)); /* + * Forward this trap to the virtual EL2 if the virtual HCR_EL2.NV + * bit is set. + */ + if (forward_nv_traps(vcpu)) + return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_hsr(vcpu)); + + /* * Note that the current exception level is always the virtual EL2, * since we set HCR_EL2.NV bit only when entering the virtual EL2. */ diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 910b50d..4fd7090 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -939,6 +939,14 @@ static bool access_cntp_cval(struct kvm_vcpu *vcpu, return true; } +/* This function is to support the recursive nested virtualization */ +bool forward_nv_traps(struct kvm_vcpu *vcpu) +{ + if (!vcpu_mode_el2(vcpu) && (vcpu_sys_reg(vcpu, HCR_EL2) & HCR_NV)) + return true; + return false; +} + static inline void access_rw(struct sys_reg_params *p, u64 *sysreg) { if (!p->is_write) @@ -977,6 +985,13 @@ static bool trap_el2_regs(struct kvm_vcpu *vcpu, { u64 *sys_reg; + /* + * Forward this trap to the virtual EL2 if the virtual HCR_EL2.NV + * bit is set. + */ + if (forward_nv_traps(vcpu)) + return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_hsr(vcpu)); + sys_reg = get_special_reg(vcpu, p); if (!sys_reg) sys_reg = &vcpu_sys_reg(vcpu, r->reg); @@ -1914,6 +1929,13 @@ static int emulate_sys_instr(struct kvm_vcpu *vcpu, { int ret = 0; + /* + * Forward this trap to the virtual EL2 if the virtual HCR_EL2.NV + * bit is set. + */ + if (forward_nv_traps(vcpu)) + return kvm_inject_nested_sync(vcpu, kvm_vcpu_get_hsr(vcpu)); + /* TLB maintenance instructions*/ if (params->CRn == 0b1000) ret = emulate_tlbi(vcpu, params);