From patchwork Mon Mar 15 14:35:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12139695 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=-17.0 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, 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 4EC64C4361A for ; Mon, 15 Mar 2021 14:43:05 +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 76FBA64F47 for ; Mon, 15 Mar 2021 14:43:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 76FBA64F47 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=KEUgAyeULN+gNl/NQQRHgymHPGxBD58G9UgZx5S6Dzc=; b=eWEbexmxFe3u4b nvzAN3mtm+Pap9vYyjhsgg3+QtIaW+Va10t3G2KTuMMvMyAclsjTKMTOK7plK6LCJDISXIjXa9mAa /wKzVLui607C/eCWe4zB6Mmtd0v0wckfpvNSSMPxuWvFuPV+dkwDLnl1firTOQOz2MyCwEUoM5k+S e08/UNccH5zQnB6KwDuLL1cl7a2vKmhGVVy8wD/Tf7mC1HUr0oM8Zg9teoHM3zns6EI3jVviJfNES Kh/j5Ryo9DC4ev+sNR6iEXJlUW9Xhv9jvGzmkEadxbPYZSBMZYBe38Bol7aReFc2/5JNvRmMmcgzl XCh4HxpDoikFnck4nPAg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lLoP3-00G7v3-O3; Mon, 15 Mar 2021 14:41:06 +0000 Received: from mail-qv1-xf49.google.com ([2607:f8b0:4864:20::f49]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lLoKV-00G5rR-UO for linux-arm-kernel@lists.infradead.org; Mon, 15 Mar 2021 14:36:27 +0000 Received: by mail-qv1-xf49.google.com with SMTP id s16so23178622qvw.3 for ; Mon, 15 Mar 2021 07:36:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=HRAFWrKIzylHbXfgNm/Fu2Q8xoVgUT5PJ9wf7XKiM18=; b=DCcz3x1/kW/GD99FmKaXddapQt41XZ32XNsYp7QWBDLlVO24xW5DpiW59uYWRTX1DJ KwMvZL7qz9CseKSBVwI41fMrKiTvUUJcGyZDt9OUAYImbWTblGSBvA4nUu4IX+ZlHBo8 hL20TRKTR4Qc88S21vfhSOuuUZ5OQntet777ua+efKJ4/93MkK1gH91l9s87ZdZCAiYT CYP9rP7uKnd843PIJBZXtROVc8w7J0I1k4Q7Ldv/Fk1Ye5f9DKst+rK6Pgyy81K8xTWs JejWtJ1SIW/fOH7WNLx+hrjx+vQAQdgSUqS2y1sJ/NPZd1xCpdDB6ognRrHWdoLl5xjd Xc7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=HRAFWrKIzylHbXfgNm/Fu2Q8xoVgUT5PJ9wf7XKiM18=; b=a14oeO1GznwSiX1VzIX4m2cYbNnEuVkpJ/BBIXMGlviVG9Uiiwdt3DR8vK4ovA7SQ2 aZogfOTA6Lsuky372mLtApjJ7k6TQKB191bVATtuVHVwFtVw3gFj3dCxAUwM8BuU6e7O CFmSfq/pH04xB8a7AYMgRbi+SM+8Ig7tGRI+nhEhB/JaH0ydjkMg5XTcfxoS4dIkM76t veaxqWDCMhbRMVgJt/V0Xark6EQWCGu3qAmefKyvNIIFx96ZqFqr8PsYAw0rk7HBgoAI 7i//9BwbTiMBpaiw8khabu7kX8LuTsvEn4IHfA/CXLpmfpSHjyhl0+6hhj4uyn8MtIIn FMsA== X-Gm-Message-State: AOAM531Ey7rL7gc15aWqRs78T21po5vqmBT1wKN9WMJfK+e9a+z9FAgi XlPdygOsVPIVWv1vTh7HTi3mEglr+aCU X-Google-Smtp-Source: ABdhPJyzqo0wyW19psT2TxHKUfltEf1yo5fncKMm24FmM3kFIm49/9SjdrDd5UArPWMDFW3pIsdD5UK2gyVu X-Received: from r2d2-qp.c.googlers.com ([fda3:e722:ac3:10:28:9cb1:c0a8:1652]) (user=qperret job=sendgmr) by 2002:ad4:4904:: with SMTP id bh4mr24441509qvb.53.1615818981861; Mon, 15 Mar 2021 07:36:21 -0700 (PDT) Date: Mon, 15 Mar 2021 14:35:20 +0000 In-Reply-To: <20210315143536.214621-1-qperret@google.com> Message-Id: <20210315143536.214621-21-qperret@google.com> Mime-Version: 1.0 References: <20210315143536.214621-1-qperret@google.com> X-Mailer: git-send-email 2.31.0.rc2.261.g7f71774620-goog Subject: [PATCH v5 20/36] 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, seanjc@google.com, mate.toth-pal@arm.com, linux-kernel@vger.kernel.org, robh+dt@kernel.org, linux-arm-kernel@lists.infradead.org, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, tabba@google.com, ardb@kernel.org, mark.rutland@arm.com, dbrazdil@google.com, qperret@google.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210315_143624_205098_0CEB0106 X-CRM114-Status: GOOD ( 14.91 ) 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); }