From patchwork Mon Jan 9 06:24:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jintack Lim X-Patchwork-Id: 9504083 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 7A9BE60710 for ; Mon, 9 Jan 2017 06:43:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 679C82811C for ; Mon, 9 Jan 2017 06:43:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 585EB280DE; Mon, 9 Jan 2017 06:43:50 +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=-3.7 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D538F280DE for ; Mon, 9 Jan 2017 06:43:49 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cQTgJ-0006hH-8o; Mon, 09 Jan 2017 06:43:47 +0000 Received: from casper.infradead.org ([85.118.1.10]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cQTgG-0006HC-20 for linux-arm-kernel@bombadil.infradead.org; Mon, 09 Jan 2017 06:43:44 +0000 Received: from outprodmail01.cc.columbia.edu ([128.59.72.39]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cQTQ1-00033i-OU for linux-arm-kernel@lists.infradead.org; Mon, 09 Jan 2017 06:26:59 +0000 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 v096PWZb017300 for ; Mon, 9 Jan 2017 01:26:37 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id CA4C183 for ; Mon, 9 Jan 2017 01:26:37 -0500 (EST) Received: from sendprodmail03.cc.columbia.edu (sendprodmail03.cc.columbia.edu [128.59.72.15]) by hazelnut (Postfix) with ESMTP id 8F0F48D for ; Mon, 9 Jan 2017 01:26:37 -0500 (EST) Received: from mail-qt0-f200.google.com (mail-qt0-f200.google.com [209.85.216.200]) by sendprodmail03.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096QbBc057991 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 9 Jan 2017 01:26:37 -0500 Received: by mail-qt0-f200.google.com with SMTP id x49so82681546qtc.7 for ; Sun, 08 Jan 2017 22:26:37 -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=U2YE8NBef5BiGS07jyDZ37X+JqAOdVZl1coK9YhHYxA=; b=cKi8BbhTIWJk/QvN0Avq7U4gJzZ9UThVbxdnUJzOC9ouJMuD0ZeByBWIp1+akRI1D0 92TI5iuPwLklwWlXxkRl87G0UTC39H/6u+7DruQ+Vw2KKPQmQVINKy2MC16b7ymRM2VA tqAnsdY3Zpb2i+YAZtg1pXc7YaCMTuOY+7j/gk8wrndi8YnRdL99PEYSsf7JK9qzSp1I FtIGnVJvcgbXjGecitXGMuFyuhYbxX7CdHk4vk06XyDxIPw2fRM31KiV8tGs6vg82Vxx z53JQqGCSrA3fvs7gIf+s3RcnzR86OiMzNv5wjMCbzI7d84L9VDo+rkW45Abhu1pPkES zFVQ== X-Gm-Message-State: AIkVDXLED1cA6amXl66QkQL4FCYEu5fovk4uqhX/rmyntKb8a3mr+k1OHQPqHq3kk08FyaWqfEK4uayJYC+8sTIJlcYikodKr93lj18EdC9xQ4JujvkQH9lh9OiIBHik1ulYoqT5KFZI+Ez3LZk29/NZy2D0mw7NyBDm3A== X-Received: by 10.237.34.167 with SMTP id p36mr79091987qtc.286.1483943196955; Sun, 08 Jan 2017 22:26:36 -0800 (PST) X-Received: by 10.237.34.167 with SMTP id p36mr79091965qtc.286.1483943196783; Sun, 08 Jan 2017 22:26:36 -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.26.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Jan 2017 22:26:36 -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 Subject: [RFC 52/55] KVM: arm/arm64: Create a vcpu mapping for the nested VM Date: Mon, 9 Jan 2017 01:24:48 -0500 Message-Id: <1483943091-1364-53-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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170109_062657_969991_3C5DF56D X-CRM114-Status: GOOD ( 18.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jintack@cs.columbia.edu MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Create a mapping from the nested VM's cpu interface to the hardware virtual cpu interface. This is to allow the nested VM to access virtual cpu interface directly. Signed-off-by: Jintack Lim --- arch/arm/include/asm/kvm_mmu.h | 3 +++ arch/arm/kvm/mmu.c | 5 +++++ arch/arm64/include/asm/kvm_mmu.h | 5 +++++ arch/arm64/kvm/mmu-nested.c | 26 ++++++++++++++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/arch/arm/include/asm/kvm_mmu.h b/arch/arm/include/asm/kvm_mmu.h index 0d106ae..048a021 100644 --- a/arch/arm/include/asm/kvm_mmu.h +++ b/arch/arm/include/asm/kvm_mmu.h @@ -254,6 +254,9 @@ static inline void kvm_nested_s2_teardown(struct kvm_vcpu *vcpu) { } static inline void kvm_nested_s2_all_vcpus_wp(struct kvm *kvm) { } static inline void kvm_nested_s2_all_vcpus_unmap(struct kvm *kvm) { } static inline void kvm_nested_s2_all_vcpus_flush(struct kvm *kvm) { } +static inline int kvm_nested_mmio_ondemand(struct kvm_vcpu *vcpu, + phys_addr_t fault_ipa, + phys_addr_t ipa) { return 0; } static inline u64 kvm_get_vttbr(struct kvm_s2_vmid *vmid, struct kvm_s2_mmu *mmu) diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c index 2cd6a19..f7c2911 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -1615,6 +1615,11 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu, struct kvm_run *run) goto out_unlock; } + if (kvm_nested_mmio_ondemand(vcpu, fault_ipa, ipa)) { + ret = 1; + goto out_unlock; + } + /* * The IPA is reported as [MAX:12], so we need to * complement it with the bottom 12 bits from the diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index ec9e5e9..ee80a58 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -354,6 +354,8 @@ int kvm_s2_handle_perm_fault(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, void kvm_nested_s2_all_vcpus_wp(struct kvm *kvm); void kvm_nested_s2_all_vcpus_unmap(struct kvm *kvm); void kvm_nested_s2_all_vcpus_flush(struct kvm *kvm); +int kvm_nested_mmio_ondemand(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, + phys_addr_t ipa); #else static inline struct kvm_nested_s2_mmu *get_nested_mmu(struct kvm_vcpu *vcpu, u64 vttbr) @@ -389,6 +391,9 @@ static inline void kvm_nested_s2_teardown(struct kvm_vcpu *vcpu) { } static inline void kvm_nested_s2_all_vcpus_wp(struct kvm *kvm) { } static inline void kvm_nested_s2_all_vcpus_unmap(struct kvm *kvm) { } static inline void kvm_nested_s2_all_vcpus_flush(struct kvm *kvm) { } +static inline int kvm_nested_mmio_ondemand(struct kvm_vcpu *vcpu, + phys_addr_t fault_ipa, + phys_addr_t ipa) { return 0; } #endif static inline u64 kvm_get_vttbr(struct kvm_s2_vmid *vmid, diff --git a/arch/arm64/kvm/mmu-nested.c b/arch/arm64/kvm/mmu-nested.c index 65ad0da..bce0042 100644 --- a/arch/arm64/kvm/mmu-nested.c +++ b/arch/arm64/kvm/mmu-nested.c @@ -473,3 +473,29 @@ bool handle_vttbr_update(struct kvm_vcpu *vcpu, u64 vttbr) return true; } + +/* + * vcpu interface address. This address is supposed to come from the guest's + * device tree via QEMU. Here we just hardcoded it, but should be fixed. + */ +#define NESTED_VCPU_IF_ADDR 0x08010000 +int kvm_nested_mmio_ondemand(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, + phys_addr_t ipa) +{ + int ret = 0; + phys_addr_t vcpu_base = vgic_vcpu_base(); + + /* Return if this fault is not from a nested VM */ + if (vcpu->arch.hw_mmu == &vcpu->kvm->arch.mmu) + return ret; + + if (ipa == NESTED_VCPU_IF_ADDR) { + ret = __kvm_phys_addr_ioremap(vcpu->kvm, vcpu->arch.hw_mmu, + fault_ipa, vcpu_base, + KVM_VGIC_V2_CPU_SIZE, true); + if (!ret) + ret = 1; + } + + return ret; +}