From patchwork Tue Jul 18 16:58:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9849149 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 74714600CC for ; Tue, 18 Jul 2017 17:13:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 57096285BA for ; Tue, 18 Jul 2017 17:13:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4BE62285D1; Tue, 18 Jul 2017 17:13:01 +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 CAA60285D8 for ; Tue, 18 Jul 2017 17:13:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751436AbdGRRMq (ORCPT ); Tue, 18 Jul 2017 13:12:46 -0400 Received: from mail-io0-f172.google.com ([209.85.223.172]:33370 "EHLO mail-io0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751620AbdGRQ7l (ORCPT ); Tue, 18 Jul 2017 12:59:41 -0400 Received: by mail-io0-f172.google.com with SMTP id 5so16497130iow.0 for ; Tue, 18 Jul 2017 09:59:41 -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=xzZF34TOJYqmhTjpA6ipdsQmbyVV8Q6Nja1JgJcypaI=; b=UgKXjw5FU2KWb9V74cKvtcY7hsUkIBZpvc+3ITx4C6/wTy6XVEsMR0cgCd+ZRgGFRR qUtl/m4JPJ4vjwTvlhtOzA3NTeWPZcD6zVUKsiAMd+nUmhvO1s8/NmI1tKC1fQB+ERDw SSJacCNSsbHxUeFHh/WFatIMa9Z50CC6ECey0= 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=xzZF34TOJYqmhTjpA6ipdsQmbyVV8Q6Nja1JgJcypaI=; b=rm5RH7brEa8uIfNKKJGXAw2ee4QS/80km6CkensClLAzciZl5uMQ/W3265NKCTdb86 XMuC3CQGTVORIItAzDrWJ97Ev8CunxDUHsrhnNB/d7ZdTXG0JhVcAkDPq8jXIlWCWfvo +481XtSJKUbikvHrURFIK1ewqd0y3aQLmI0A14pbCc775qZDabPKrNyU4QHL32joNrGO M++xRREZRhVOyxZWFgrpblE4fOTGWmAIJfHQUmCjTVSmAtPnGFY9DJTDFWi2L4/pp+Hq 8E6PkeVjGAjc2xiCQEgcboO6T4/V45bilsSQBQ0uuZDAVDUeL69iYZoYwhDI38c21Xts QNUw== X-Gm-Message-State: AIVw111j+H5LzRxotYUcPzYQ8+zz6HsvMELobPTHIUBk/KPNBUcv3+2t VfZaVtpBhazO3Vhk X-Received: by 10.107.7.33 with SMTP id 33mr1921566ioh.5.1500397181108; Tue, 18 Jul 2017 09:59:41 -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.09.59.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 09:59:40 -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 04/38] KVM: arm/arm64: Check if nested virtualization is in use Date: Tue, 18 Jul 2017 11:58:30 -0500 Message-Id: <1500397144-16232-5-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 Nested virtualizaion is in use only if all three conditions are met: - The architecture supports nested virtualization. - The kernel parameter is set. - The userspace uses nested virtualiztion feature. Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_host.h | 11 +++++++++++ arch/arm64/include/asm/kvm_host.h | 2 ++ arch/arm64/kvm/nested.c | 17 +++++++++++++++++ virt/kvm/arm/arm.c | 4 ++++ 4 files changed, 34 insertions(+) diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index 00b0f97..7e9e6c8 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -303,4 +303,15 @@ static inline int __init kvmarm_nested_cfg(char *buf) { return 0; } + +static inline int init_nested_virt(void) +{ + return 0; +} + +static inline bool nested_virt_in_use(struct kvm_vcpu *vcpu) +{ + return false; +} + #endif /* __ARM_KVM_HOST_H__ */ diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 6df0c7c..86d4b6c 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -387,5 +387,7 @@ static inline void __cpu_init_stage2(void) } int __init kvmarm_nested_cfg(char *buf); +int init_nested_virt(void); +bool nested_virt_in_use(struct kvm_vcpu *vcpu); #endif /* __ARM64_KVM_HOST_H__ */ diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c index 79f38da..9a05c76 100644 --- a/arch/arm64/kvm/nested.c +++ b/arch/arm64/kvm/nested.c @@ -24,3 +24,20 @@ int __init kvmarm_nested_cfg(char *buf) { return strtobool(buf, &nested_param); } + +int init_nested_virt(void) +{ + if (nested_param && cpus_have_const_cap(ARM64_HAS_NESTED_VIRT)) + kvm_info("Nested virtualization is supported\n"); + + return 0; +} + +bool nested_virt_in_use(struct kvm_vcpu *vcpu) +{ + if (nested_param && cpus_have_const_cap(ARM64_HAS_NESTED_VIRT) + && test_bit(KVM_ARM_VCPU_NESTED_VIRT, vcpu->arch.features)) + return true; + + return false; +} diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c index 1c1c772..36aae3a 100644 --- a/virt/kvm/arm/arm.c +++ b/virt/kvm/arm/arm.c @@ -1478,6 +1478,10 @@ int kvm_arch_init(void *opaque) if (err) goto out_err; + err = init_nested_virt(); + if (err) + return err; + err = init_subsystems(); if (err) goto out_hyp;