Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4066935pxb; Tue, 17 Nov 2020 10:20:51 -0800 (PST) X-Google-Smtp-Source: ABdhPJy4YA0oF05MVU+NHOpkuj+nd4NnFFne0oy7Jxn93G7i+06ZKHhd3K/GOGl2Mw0dcJ62qQ0n X-Received: by 2002:a17:906:aacb:: with SMTP id kt11mr21963678ejb.12.1605637251029; Tue, 17 Nov 2020 10:20:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605637251; cv=none; d=google.com; s=arc-20160816; b=Fg6VHTLglqb2WDoFOsi89OlnvIvgPirpfR9LVja+Q6b4KpFLvIAvqWGc7dPk2b/LgF j7dMuHUQCRX+iuABQ6735msjqWfaMdb329wHtgOp5co+0vI+b7cXrA+mJyTu6N1R7fAD MaY3Dko6DMRlS/i5faTn5DFxKw8zkuUQrsCq9V+v7pabe28Oz/7w6Nwdj743dQAu8QRo wXeqp2D3KgN3k3zRec3n6d2jEhoqo4rk/kobR02337KdOiUP1O9EgI6ZPEPt+ISr8tqq yl0H7mE2trn9oVaLdv6EMt1l9miqWi+jcGJthl5SKcpVB42JicJJoZ2yL2RC/0JWzTSj FNYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=nDg4Q5UW5VyG5A48tL8468KlneKnyHjdeOZ0CSmRGUk=; b=UZ6aCnd19JFOFrnVPaf4g2XnKZaefqhjx6G8w8a5s2XXSttp/K3NF316laa0KKnyAw y0eeKvh1DSbh6ujmKrgnT9HRcb9SLGpv8JRiOrHqEszAsytaQrY85uDRdbglPHLz5iUy i4c6n5CtrZ8y6f7hAYuxtGwqhvHuj7mhug9jOAUcXmULvYgqZmuEyyMRCz9xq6Q+bXe9 nOjzJKcvTYfxpXmIvFytj3vON19Sgj9xPim3Lkm4DSjK/v5FbfFpiQo1lDeq9mICUlfo drZuexTG9c189vzgxvtKgy6sRzGJMWfmCpTghngno5Zg6lCpn27JxnZ0NvkNGsY/EeOq fSEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=N1TibN9j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y14si14239375eds.56.2020.11.17.10.20.28; Tue, 17 Nov 2020 10:20:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=N1TibN9j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731041AbgKQSRL (ORCPT + 99 others); Tue, 17 Nov 2020 13:17:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731020AbgKQSRG (ORCPT ); Tue, 17 Nov 2020 13:17:06 -0500 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB2A4C0613CF for ; Tue, 17 Nov 2020 10:17:04 -0800 (PST) Received: by mail-wr1-x44a.google.com with SMTP id x16so8648502wrn.9 for ; Tue, 17 Nov 2020 10:17:04 -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=nDg4Q5UW5VyG5A48tL8468KlneKnyHjdeOZ0CSmRGUk=; b=N1TibN9j6rqyDAz7w2MvN4SO5GZxQitBMjo5jrhjQsL+CqRT6cSgzwpG8/qIi2cqKl QupXDJkW94uUSAHQ/Avd20xRPPX5Qshr8JcXWEIpweKRZChjRI+YU7261YvmSIgucGbb YGbidLKp2mBFY77m2LsC5eN7onLPhV6anYgipS2Wbz8yGdVJ5EkVuUBY24a4Oo3WPnkf WvgYp/NvweM/l3FStseFKS26JKS9j8Idghu6U/AclJSNJVmYb5G6lNg8AiDGCVrU6TVx AGBetFJ2Kvmc3d57+t1arZwyoK4CzoIJCeQ7BEGcY2Uf29V1bO3LFUb4jjqch68AkY8Y GtOg== 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=nDg4Q5UW5VyG5A48tL8468KlneKnyHjdeOZ0CSmRGUk=; b=mDZfpNTXAWGqv6zR3dkCCjnwOrvrgT5kL6YshxZDDXxiK35nwrDp1WghgFc8wLBkbu HtTB+BYTTVYCRxz1SbSh7X3tieeWESe1FqCZt+70366u38++srBPhzrjPWrDykJ1BwgC fjgE1OY2m28sYHkFhspw6PU2WS2QFW1if3L3K6qaj8WPLcd33KGeobrAKUgv2NYrJ0Ad SXlOlQGNHu0vRMvlSZiDNaAqM0/xxjQzaOIkKwjldHKOpKGmvZGaMTTYsqvwvR1TcJh/ yCAqW5e+AmwJN+3Sw3t+CvOZYcLCriml23WmY+HT1u+JCVS65MhXsr9be+kwA9ilXYK1 akFQ== X-Gm-Message-State: AOAM531X4H4u0r/2Z5zl6MutDaOwVm20AyQAmGhNm0ec91BkaRBtO+jf FSL/lDGdY+3QhaM8SerwZ2OMmpBVbeM3 Sender: "qperret via sendgmr" X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:f693:9fff:fef4:a7ef]) (user=qperret job=sendgmr) by 2002:a1c:e442:: with SMTP id b63mr418225wmh.10.1605637023474; Tue, 17 Nov 2020 10:17:03 -0800 (PST) Date: Tue, 17 Nov 2020 18:15:59 +0000 In-Reply-To: <20201117181607.1761516-1-qperret@google.com> Message-Id: <20201117181607.1761516-20-qperret@google.com> Mime-Version: 1.0 References: <20201117181607.1761516-1-qperret@google.com> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog Subject: [RFC PATCH 19/27] KVM: arm64: Use kvm_arch in kvm_s2_mmu From: Quentin Perret To: Catalin Marinas , Will Deacon , Marc Zyngier , James Morse , Julien Thierry , Suzuki K Poulose , Rob Herring , Frank Rowand Cc: "moderated list:ARM64 PORT (AARCH64 ARCHITECTURE)" , open list , "open list:KERNEL VIRTUAL MACHINE FOR ARM64 (KVM/arm64)" , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE" , kernel-team@android.com, android-kvm@google.com, Quentin Perret Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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. Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_host.h | 2 +- arch/arm64/include/asm/kvm_mmu.h | 7 ++++++- arch/arm64/kvm/mmu.c | 8 ++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index ee8bb8021637..53b01d25e7d9 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -86,7 +86,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 { diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h index bb756757b51c..714357ebd278 100644 --- a/arch/arm64/include/asm/kvm_mmu.h +++ b/arch/arm64/include/asm/kvm_mmu.h @@ -275,7 +275,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); /* @@ -285,5 +285,10 @@ 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 384f2acc0115..3b1c53e754ee 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -169,7 +169,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); @@ -474,7 +474,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; @@ -556,7 +556,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); @@ -625,7 +625,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); } -- 2.29.2.299.gdc1121823c-goog