From patchwork Mon Jan 9 06:23:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9504063 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 EEB1160762 for ; Mon, 9 Jan 2017 06:40:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF2FF28112 for ; Mon, 9 Jan 2017 06:40:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D44D428285; Mon, 9 Jan 2017 06:40:34 +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=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 560EB2811C for ; Mon, 9 Jan 2017 06:40:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755954AbdAIGkZ (ORCPT ); Mon, 9 Jan 2017 01:40:25 -0500 Received: from outprodmail01.cc.columbia.edu ([128.59.72.39]:37949 "EHLO outprodmail01.cc.columbia.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760509AbdAIGZh (ORCPT ); Mon, 9 Jan 2017 01:25:37 -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 v096PX6H017321 for ; Mon, 9 Jan 2017 01:25:36 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id 8CB4F80 for ; Mon, 9 Jan 2017 01:25:36 -0500 (EST) Received: from sendprodmail03.cc.columbia.edu (sendprodmail03.cc.columbia.edu [128.59.72.15]) by hazelnut (Postfix) with ESMTP id 6AAA680 for ; Mon, 9 Jan 2017 01:25:36 -0500 (EST) Received: from mail-qt0-f197.google.com (mail-qt0-f197.google.com [209.85.216.197]) by sendprodmail03.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096PaLq056477 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 9 Jan 2017 01:25:36 -0500 Received: by mail-qt0-f197.google.com with SMTP id t56so77861962qte.3 for ; Sun, 08 Jan 2017 22:25:36 -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=VKoEFY8lxpBwPPJlc/VOZC5oy3J+ZJcV62T1l0fXcIs=; b=O/cEDVlsvAJV8BZ+1vfZZCaYWRjcW62dHKleuluQee3I9hscI6gJjJkVViMkS+Oawi rqD6I0+OTBRFU7bN9cCLeEHQ6bUBDjLv4+BSFEmM2p7ICfg5hdFylN7uPgWSiSMaLJbJ LSKPSz5pUmU0ktfJIURgNDBuqJTVgJLVICuZ9hGRZBMeIhIyhi4Eh/gfCyIIWuGReu7t SMIXZnGFO4kvUZMm9L1g+CpWcC72rXd5LBqYhMoN51fiFhfO0yme/Sk5A+cSWyZjGMaQ TrG4B+/dU53E+0yiKssOQwfbETP/huxnWypl9cKkrSlCFEPD7XT3ewFnwX+v9em7wXx7 oTeA== X-Gm-Message-State: AIkVDXKIMQSAZafU6N+06qRAngQ4jgOcxy8XY+TFrmtvO9LLGQiwEorW/mHmZsMXXw0/qsd2dpJXzK3RtATfRy1Dilm6V1z7EVALyhj+uTpK+ZWc5VGObkyVsDlEXvGrOBKWGkCn3VPXpBI= X-Received: by 10.200.37.241 with SMTP id f46mr80567845qtf.164.1483943136071; Sun, 08 Jan 2017 22:25:36 -0800 (PST) X-Received: by 10.200.37.241 with SMTP id f46mr80567781qtf.164.1483943134865; Sun, 08 Jan 2017 22:25:34 -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.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Jan 2017 22:25:33 -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 03/55] KVM: arm64: Add KVM nesting feature Date: Mon, 9 Jan 2017 01:23:59 -0500 Message-Id: <1483943091-1364-4-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.15 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Christoffer Dall Set the initial exception level of the guest to EL2 if nested virtualization feature is enabled. Signed-off-by: Christoffer Dall Signed-off-by: Jintack Lim --- arch/arm64/include/asm/kvm_host.h | 2 +- arch/arm64/include/uapi/asm/kvm.h | 1 + arch/arm64/kvm/reset.c | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index e505038..c0c8b02 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -41,7 +41,7 @@ #define KVM_MAX_VCPUS VGIC_V3_MAX_CPUS -#define KVM_VCPU_MAX_FEATURES 4 +#define KVM_VCPU_MAX_FEATURES 5 #define KVM_REQ_VCPU_EXIT 8 diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h index 3051f86..78117bf 100644 --- a/arch/arm64/include/uapi/asm/kvm.h +++ b/arch/arm64/include/uapi/asm/kvm.h @@ -97,6 +97,7 @@ struct kvm_regs { #define KVM_ARM_VCPU_EL1_32BIT 1 /* CPU running a 32bit VM */ #define KVM_ARM_VCPU_PSCI_0_2 2 /* CPU uses PSCI v0.2 */ #define KVM_ARM_VCPU_PMU_V3 3 /* Support guest PMUv3 */ +#define KVM_ARM_VCPU_NESTED_VIRT 4 /* Support nested virtual EL2 */ struct kvm_vcpu_init { __u32 target; diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c index 74322c2..e6b0b20 100644 --- a/arch/arm64/kvm/reset.c +++ b/arch/arm64/kvm/reset.c @@ -41,6 +41,11 @@ PSR_F_BIT | PSR_D_BIT), }; +static const struct kvm_regs default_regs_reset_el2 = { + .regs.pstate = (PSR_MODE_EL2h | PSR_A_BIT | PSR_I_BIT | + PSR_F_BIT | PSR_D_BIT), +}; + static const struct kvm_regs default_regs_reset32 = { .regs.pstate = (COMPAT_PSR_MODE_SVC | COMPAT_PSR_A_BIT | COMPAT_PSR_I_BIT | COMPAT_PSR_F_BIT), @@ -124,6 +129,9 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu) if (!cpu_has_32bit_el1()) return -EINVAL; cpu_reset = &default_regs_reset32; + } else if (test_bit(KVM_ARM_VCPU_NESTED_VIRT, + vcpu->arch.features)) { + cpu_reset = &default_regs_reset_el2; } else { cpu_reset = &default_regs_reset; }