From patchwork Mon Jan 9 06:24: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: 9503881 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 E430C60757 for ; Mon, 9 Jan 2017 06:29:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D32FD280D0 for ; Mon, 9 Jan 2017 06:29:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5EDA2815E; Mon, 9 Jan 2017 06:29: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.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 3FF84280D0 for ; Mon, 9 Jan 2017 06:29:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S942259AbdAIG22 (ORCPT ); Mon, 9 Jan 2017 01:28:28 -0500 Received: from outprodmail02.cc.columbia.edu ([128.59.72.51]:52470 "EHLO outprodmail02.cc.columbia.edu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S939883AbdAIG0m (ORCPT ); Mon, 9 Jan 2017 01:26:42 -0500 Received: from hazelnut (hazelnut.cc.columbia.edu [128.59.213.250]) by outprodmail02.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096P41A005194 for ; Mon, 9 Jan 2017 01:26:35 -0500 Received: from hazelnut (localhost.localdomain [127.0.0.1]) by hazelnut (Postfix) with ESMTP id 3EC7A86 for ; Mon, 9 Jan 2017 01:26:35 -0500 (EST) Received: from sendprodmail04.cc.columbia.edu (sendprodmail04.cc.columbia.edu [128.59.72.16]) by hazelnut (Postfix) with ESMTP id 131DD83 for ; Mon, 9 Jan 2017 01:26:35 -0500 (EST) Received: from mail-qk0-f199.google.com (mail-qk0-f199.google.com [209.85.220.199]) by sendprodmail04.cc.columbia.edu (8.14.4/8.14.4) with ESMTP id v096QYhI005858 (version=TLSv1/SSLv3 cipher=AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 9 Jan 2017 01:26:34 -0500 Received: by mail-qk0-f199.google.com with SMTP id d75so52983810qkc.0 for ; Sun, 08 Jan 2017 22:26:34 -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=yh9+0XsyyJDt41zvFMLKivAUaZ9NeMgWzXexXrkOIxY=; b=J6AdKD5kEaFGY3vzkcH6LdmGeqaLRtA+j2KjEgwCQpEXcDwKFUcFLbikgJZ5Gu2gLE W48HzpAE8rlV/Uf5LQ6b1Ws+BnS2IA7+mBcTJe5hMW4+KjHS4HqMlyGl4F8ZQ7pjTJVH IWheCFkYDNu/GOi/u+ZgGT1FjBv9i6TaFPpSD9BtVH7h/hCV+Crb6EAwrqTgLjPWa7Bq r8Wl8RlBj2Ss6wGDaGXf8oLbFRR6/bcEkGtGooeHwEGr2ZFOiuzsiaZnKGP8NelaAkVa IXvXkDwaoNeIjMhd+76xdrmvH7svYuK1EwsREyzMDMfEyq9nathBA9A0kUCpMJQcVDnc w0mA== X-Gm-Message-State: AIkVDXIwsxIvU+G17vS6oA97jrIqky/Ug/G+17/3ZZ9Ko+y+cKFuLvp+LOp810vIn0tTYk+tms0+sC9tiweThlT1uNF9UczZcNAWvRc6j3Z+NqEoMwWtcCAdBhh8on4Ar/l/nDIN+NYAlKI= X-Received: by 10.200.47.84 with SMTP id k20mr68633205qta.119.1483943194692; Sun, 08 Jan 2017 22:26:34 -0800 (PST) X-Received: by 10.200.47.84 with SMTP id k20mr68633175qta.119.1483943194510; Sun, 08 Jan 2017 22:26: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.26.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 08 Jan 2017 22:26: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 50/55] KVM: arm/arm64: Abstract kvm_phys_addr_ioremap() function Date: Mon, 9 Jan 2017 01:24:46 -0500 Message-Id: <1483943091-1364-51-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.16 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The original kvm_phys_addr_ioremap function only uses mmu pointing to the VM's mmu context. However, it would be very useful to reuse this function for the nested mmu context. Therefore, create a function named __kvm_phys_addr_ioremapp which takes mmu as an argument, and let kvm_phys_addr_ioremap calls this function with the VM's mmu context. Signed-off-by: Jintack Lim --- arch/arm/kvm/mmu.c | 18 +++++++++++++----- arch/arm64/include/asm/kvm_mmu.h | 3 +++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/arch/arm/kvm/mmu.c b/arch/arm/kvm/mmu.c index 344bc01..2cd6a19 100644 --- a/arch/arm/kvm/mmu.c +++ b/arch/arm/kvm/mmu.c @@ -1058,15 +1058,16 @@ static int stage2_pmdp_test_and_clear_young(pmd_t *pmd) } /** - * kvm_phys_addr_ioremap - map a device range to guest IPA + * __kvm_phys_addr_ioremap - map a device range to guest IPA * * @kvm: The KVM pointer * @guest_ipa: The IPA at which to insert the mapping * @pa: The physical address of the device * @size: The size of the mapping */ -int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa, - phys_addr_t pa, unsigned long size, bool writable) +int __kvm_phys_addr_ioremap(struct kvm *kvm, struct kvm_s2_mmu *mmu, + phys_addr_t guest_ipa, phys_addr_t pa, + unsigned long size, bool writable) { phys_addr_t addr, end; int ret = 0; @@ -1087,8 +1088,8 @@ int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa, if (ret) goto out; spin_lock(&kvm->mmu_lock); - ret = stage2_set_pte(&kvm->arch.mmu, &cache, addr, &pte, - KVM_S2PTE_FLAG_IS_IOMAP); + ret = stage2_set_pte(mmu, &cache, addr, &pte, + KVM_S2PTE_FLAG_IS_IOMAP); spin_unlock(&kvm->mmu_lock); if (ret) goto out; @@ -1101,6 +1102,13 @@ int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa, return ret; } +int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa, + phys_addr_t pa, unsigned long size, bool writable) +{ + return __kvm_phys_addr_ioremap(kvm, &kvm->arch.mmu, guest_ipa, pa, + size, writable); +} + static bool transparent_hugepage_adjust(kvm_pfn_t *pfnp, gfn_t gfn, phys_addr_t *ipap) { diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index 7754f3e..ec9e5e9 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -149,6 +149,9 @@ static inline unsigned long __kern_hyp_va(unsigned long v) int __kvm_alloc_stage2_pgd(struct kvm_s2_mmu *mmu); void kvm_free_stage2_pgd(struct kvm *kvm); void __kvm_free_stage2_pgd(struct kvm_s2_mmu *mmu); +int __kvm_phys_addr_ioremap(struct kvm *kvm, struct kvm_s2_mmu *mmu, + phys_addr_t guest_ipa, phys_addr_t pa, + unsigned long size, bool writable); int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa, phys_addr_t pa, unsigned long size, bool writable); void kvm_unmap_stage2_range(struct kvm_s2_mmu *mmu, phys_addr_t start,