From patchwork Tue Mar 2 14:59:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12114003 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A35DC433E0 for ; Wed, 3 Mar 2021 18:09:51 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B7F8B64EE4 for ; Wed, 3 Mar 2021 18:09:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B7F8B64EE4 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Cc:To:From:Subject:References:Mime-Version: Message-Id:In-Reply-To:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=eOli8+ez0tBg8X4Ik3hJXecbQQgvaoFvL9EGRteHWoQ=; b=X0nt4Wbd/6QYIX 7zI9nGkvgz2map331SOVCxeb68QDOWjxcJacOQ7wSR2v9EZvcTZlQ4mcQPxp0xl+S+rsg1w+GSWVK f8ulAmw687P/6nKPc4PgN2vjGfclkCxDI6QvOni/q3gDYtIwdozGfeDDTemRQ/JBOboQJFEnhZ75j QRWt4dRkkiZSoK3hhYmzMZ7M7x5yu53I2YfftVV+5DbuutqFYtpGbaTNyzFIUAlF4HNC/n3V8isV2 gOt0OSKzis2Hgl61FpeJ3NX0nNpi9n2iDjMcA1AgN7Hr57GndYzDzAZwX5ZYqo2iUV9Hk4QuVa8A3 56N+xQRPuIloAePMwTpQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHVu6-005wqd-Ux; Wed, 03 Mar 2021 18:07:26 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHSyb-005GRV-NA for linux-arm-kernel@desiato.infradead.org; Wed, 03 Mar 2021 14:59:50 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:Cc:To:From:Subject: References:Mime-Version:Message-Id:In-Reply-To:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=bwje5/mTjAPXp3ucjvZl1d3xYnpG4DOJqI6qSewZTKg=; b=rLCArenzA89LGAJ46BTkQzROrk wwKoOuFjYtN7Lk4IPTVcCSd1g3AMKEfndlaXODfLLgYp21czsC6URJ3oaC8E2x/o0Kwou58bUZeIu ptukeqtv5vj33HynXL/g38L7oXuBS/RtkS4xr0GXRDmePvKVf4FZnLvJJdbsvYAwzhUBWj9+cWpWh pYkbq2AYoEWbM/gakmVIjInWm82IUBw1yg11oGexgaafSpE7Q8zg/gD5mZNSfhBV9j1EI9yi5sGB0 sT8e5qT9sNu80trTY21OZISEgQT13N9kjFH3iYv5FWNgdM5l93NmiFaHWB9sGwqOPwcPAwEKvIZJn E8Cx5VKA==; Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lH6XG-00HJKQ-5D for linux-arm-kernel@lists.infradead.org; Tue, 02 Mar 2021 15:02:09 +0000 Received: by mail-wm1-x34a.google.com with SMTP id c9so697356wme.5 for ; Tue, 02 Mar 2021 07:01:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=bwje5/mTjAPXp3ucjvZl1d3xYnpG4DOJqI6qSewZTKg=; b=tSH114d1S+uNQoX1kRD+PT///jcNFZH5jQl4y1I39FKxDMU/3Sk/nzK2nY32s3DZf9 mL7k3exN2AHB4ZPq66MGZyG7q1FEaXJALsmwnbUFPXQI/YMQ/GmienaMnA3fR32YF/0i XTK0G6ii03eAGLnaGVfNIse2zOnd+Zg7Xl7jhIdY9I8AE1QjfhEfugAQDu99o4kpmYVD 26I0Hhq2R71cD5A2582Cf2YgETUOfD4hGCDIviMAgjW9yes0SiyksL6bpH2ex5Iljrzf W8T6pvOEg+SLKYRCoHtIR/ruVvjA92TJcf94f9E66xMC2DC/9t07gQ3jGjztpQdJQR9e XK0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=bwje5/mTjAPXp3ucjvZl1d3xYnpG4DOJqI6qSewZTKg=; b=nCYXmcd5GDqxnbS6P2mmDuVh9IPO5ELgq7t+zaP4DDHk6GFap3H3zAplRNUFMgXvR/ FoU8CcxozJwnWA8VAzIxJ4VtRe3vVFa6iVT+g6wpvycuboqIlNFDXQ+iWX2H6BEeWNYR gM+6KU81S1uWDH3C+AZ9WBPiz3Vu2pLHMG91IN6jypUpZ2yoouXK6FqCz02+1BhjcGd5 ZscwO7wR1Ja1Fw3UvtffS/TF5ZPsdoXU9RzD/CuiEpB6fNgrP8nlAcQPiG//DlgWFu2H aya+9PAJarY25WKW6lC3joALOkmiafaCrCLVqDsfnZk3sQL69s5yoCWEYa5/DjInwWE2 1Zvw== X-Gm-Message-State: AOAM530ar9JNBNYdGxWJbaNF+bp4jVQz9lc527XIQp44PhBWMtM8e3dL ejNp79mxxg4Nel44oJQ7eHCYGWqKt0+a X-Google-Smtp-Source: ABdhPJxElOYIMAIdgYSrQfXOebmZeuQAKDUTFyUl0M9C/M5W0sRKgrJje34shxxo7rpQfJ8MEv13l1k/xiXX X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:10:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:a05:6000:24b:: with SMTP id m11mr14742698wrz.393.1614697247009; Tue, 02 Mar 2021 07:00:47 -0800 (PST) Date: Tue, 2 Mar 2021 14:59:48 +0000 In-Reply-To: <20210302150002.3685113-1-qperret@google.com> Message-Id: <20210302150002.3685113-19-qperret@google.com> Mime-Version: 1.0 References: <20210302150002.3685113-1-qperret@google.com> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH v3 18/32] KVM: arm64: Use kvm_arch in kvm_s2_mmu From: Quentin Perret To: catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com Cc: android-kvm@google.com, linux-kernel@vger.kernel.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, tabba@google.com, mark.rutland@arm.com, dbrazdil@google.com, mate.toth-pal@arm.com, seanjc@google.com, qperret@google.com, robh+dt@kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210302_150209_497190_C03032E3 X-CRM114-Status: GOOD ( 14.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In order to make use of the stage 2 pgtable code for the host stage 2, change kvm_s2_mmu to use a kvm_arch pointer in lieu of the kvm pointer, as the host will have the former but not the latter. Acked-by: Will Deacon Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_host.h | 2 +- arch/arm64/include/asm/kvm_mmu.h | 6 +++++- arch/arm64/kvm/mmu.c | 8 ++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index b9d45a1f8538..90565782ce3e 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -94,7 +94,7 @@ struct kvm_s2_mmu { /* The last vcpu id that ran on each physical CPU */ int __percpu *last_vcpu_ran; - struct kvm *kvm; + struct kvm_arch *arch; }; struct kvm_arch_memory_slot { diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index ce02a4052dcf..6f743e20cb06 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -272,7 +272,7 @@ static __always_inline u64 kvm_get_vttbr(struct kvm_s2_mmu *mmu) */ static __always_inline void __load_guest_stage2(struct kvm_s2_mmu *mmu) { - write_sysreg(kern_hyp_va(mmu->kvm)->arch.vtcr, vtcr_el2); + write_sysreg(kern_hyp_va(mmu->arch)->vtcr, vtcr_el2); write_sysreg(kvm_get_vttbr(mmu), vttbr_el2); /* @@ -283,5 +283,9 @@ static __always_inline void __load_guest_stage2(struct kvm_s2_mmu *mmu) asm(ALTERNATIVE("nop", "isb", ARM64_WORKAROUND_SPECULATIVE_AT)); } +static inline struct kvm *kvm_s2_mmu_to_kvm(struct kvm_s2_mmu *mmu) +{ + return container_of(mmu->arch, struct kvm, arch); +} #endif /* __ASSEMBLY__ */ #endif /* __ARM64_KVM_MMU_H__ */ diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index 41f9c03cbcc3..3257cadfab24 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -165,7 +165,7 @@ static void *kvm_host_va(phys_addr_t phys) static void __unmap_stage2_range(struct kvm_s2_mmu *mmu, phys_addr_t start, u64 size, bool may_block) { - struct kvm *kvm = mmu->kvm; + struct kvm *kvm = kvm_s2_mmu_to_kvm(mmu); phys_addr_t end = start + size; assert_spin_locked(&kvm->mmu_lock); @@ -470,7 +470,7 @@ int kvm_init_stage2_mmu(struct kvm *kvm, struct kvm_s2_mmu *mmu) for_each_possible_cpu(cpu) *per_cpu_ptr(mmu->last_vcpu_ran, cpu) = -1; - mmu->kvm = kvm; + mmu->arch = &kvm->arch; mmu->pgt = pgt; mmu->pgd_phys = __pa(pgt->pgd); mmu->vmid.vmid_gen = 0; @@ -552,7 +552,7 @@ void stage2_unmap_vm(struct kvm *kvm) void kvm_free_stage2_pgd(struct kvm_s2_mmu *mmu) { - struct kvm *kvm = mmu->kvm; + struct kvm *kvm = kvm_s2_mmu_to_kvm(mmu); struct kvm_pgtable *pgt = NULL; spin_lock(&kvm->mmu_lock); @@ -621,7 +621,7 @@ int kvm_phys_addr_ioremap(struct kvm *kvm, phys_addr_t guest_ipa, */ static void stage2_wp_range(struct kvm_s2_mmu *mmu, phys_addr_t addr, phys_addr_t end) { - struct kvm *kvm = mmu->kvm; + struct kvm *kvm = kvm_s2_mmu_to_kvm(mmu); stage2_apply_range_resched(kvm, addr, end, kvm_pgtable_stage2_wrprotect); }