From nobody Wed Nov 27 10:32:58 2024 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8EFCE20ADFF for ; Thu, 10 Oct 2024 18:27:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728584830; cv=none; b=qpPqIrCg7IMOB99AH/EMw8cjOZ1vHNiuGAIMSy9nXaKbRj/yET424E6eOpIkyHl6XPnj+L8W5YT1sr3Q6e9d9YEXLtVe9jZ+srWydqPXQFMGe9YjaNZS0cFWHFrYcrtWZ4/QkGV3GrlwAP+AywBWL36ojVzf4q6Bx/r/vAJIRpY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728584830; c=relaxed/simple; bh=2hWIRT2fMV5KiR0O+VosZUqCujtj2BkFwotH6/Eh4cU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=sSyq6jZxmPCESjYWutrINhSsqx4Lq9ZDFCSLqIQfk0RUUMcTxOwjjBxcHpIvJIatVcqqD/FbB05fJlL/rEX0HK1vNJyfTzIBYwNnDClcle+kj+7ccZKBi86GCWdxl8OM/Z3E47I6ZOdCDm35F8RU39gaZ8SsB1JuViqHYcPrV/8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=G6z4vMP9; arc=none smtp.client-ip=209.85.219.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="G6z4vMP9" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e291426b528so900313276.3 for ; Thu, 10 Oct 2024 11:27:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728584827; x=1729189627; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=dJnHBDyCwUFZKgDYTVV2s9CsyA2Ll45yxWv/Qp8Ijpw=; b=G6z4vMP9tzYY14hXAhxfo/HfE8ULyiyaSY7AT4hs+6XX7YyXXgEe6O37wq9BBRAEHY JjYKYtqD1iWPnNOP0QUJOqkipQau8FTv+SOCs4bSJZ/+xsRiTlTk8hAtWgVqN39tY9wb 5wuQAD6Me87ITDD+d5kwWjudoFu47bo9mH4wNF57jSfLISkmDJFq+8MNbu+tNL3vkKn2 v2ApXZjUUxYtS4slwS0/LY1XeiQ/zBTeCGV9GgWF21giZfBEjJ4CFOW4/P1yJbjy43hn 4G0JRBGtzbJl4nPCqsics+FV23cU7ErCcRDF50f3YIrP8/H28BTAqVBAOIwwOx4dDcxN NaNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728584827; x=1729189627; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dJnHBDyCwUFZKgDYTVV2s9CsyA2Ll45yxWv/Qp8Ijpw=; b=S4mn5KuK1O0qKpBRZqa3ngz/hGF7DfhHSQftYVzSrI65FaToR9a2HvRRqgYFIs16MB tPkONo5IS+EutVdAMm/VaQp+nazm94F1+CVkQVJyBvaLONx8wzpGL0THvSDJcFH5d83B K9AGlkwPO6aETM+LebnNO9C/hgjG92dI9UhMV3nVyyvBGzoN1IDCEZzNdGmuLNG/290z Mk4QngWvYR6YyLTx9NXCyh0h68JG8BvZtiAl9bjYy/uvyMzxptt2WRSt+LnejHVhGMAp d8U9rAvlYMo95CcB9ICaXTQcIPhc5yjt70DrVzwNaymLU6HWHNAN40fcgPN/wvo0bIkK z/Dg== X-Forwarded-Encrypted: i=1; AJvYcCX7yT/6kTc3yyZJMD8hhLLuYWkf7QGILpYG1uSuDUjsJxwv1eg6TyEt/S8ZPsfkwEoRhNcTPxYoCtALw/k=@vger.kernel.org X-Gm-Message-State: AOJu0YybD16IQDTqRMVjVuELPfU+5y4brZ5FeLV9FX+1XG+z//CqHajL KHoE5sdQUxtJD2+OfPhAq3Yp7HsD/1IQuGHzDE1SQiM6hyO7yBlHSntQ20T13ldBhRIsnFjHIPX TLg== X-Google-Smtp-Source: AGHT+IE3wQG+AmAWHFVOEkWtTHcZkQX/AbMzk25RszCXWWBD0mfEZbS2aMxfU1imj+f8RQ2cZBD1mpHhlQw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a5b:a07:0:b0:e28:ef8f:7423 with SMTP id 3f1490d57ef6-e28fe355de0mr48920276.4.1728584827639; Thu, 10 Oct 2024 11:27:07 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 10 Oct 2024 11:24:06 -0700 In-Reply-To: <20241010182427.1434605-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241010182427.1434605-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241010182427.1434605-65-seanjc@google.com> Subject: [PATCH v13 64/85] KVM: PPC: Use kvm_faultin_pfn() to handle page faults on Book3s PR From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, "=?UTF-8?q?Alex=20Benn=C3=A9e?=" , Yan Zhao , David Matlack , David Stevens , Andrew Jones Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Convert Book3S PR to __kvm_faultin_pfn()+kvm_release_faultin_page(), which are new APIs to consolidate arch code and provide consistent behavior across all KVM architectures. Signed-off-by: Sean Christopherson --- arch/powerpc/include/asm/kvm_book3s.h | 2 +- arch/powerpc/kvm/book3s.c | 7 ++++--- arch/powerpc/kvm/book3s_32_mmu_host.c | 7 ++++--- arch/powerpc/kvm/book3s_64_mmu_host.c | 10 +++++----- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/arch/powerpc/include/asm/kvm_book3s.h b/arch/powerpc/include/a= sm/kvm_book3s.h index 3d289dbe3982..e1ff291ba891 100644 --- a/arch/powerpc/include/asm/kvm_book3s.h +++ b/arch/powerpc/include/asm/kvm_book3s.h @@ -235,7 +235,7 @@ extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struc= t kvmppc_bat *bat, extern void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr); extern int kvmppc_emulate_paired_single(struct kvm_vcpu *vcpu); extern kvm_pfn_t kvmppc_gpa_to_pfn(struct kvm_vcpu *vcpu, gpa_t gpa, - bool writing, bool *writable); + bool writing, bool *writable, struct page **page); extern void kvmppc_add_revmap_chain(struct kvm *kvm, struct revmap_entry *= rev, unsigned long *rmap, long pte_index, int realmode); extern void kvmppc_update_dirty_map(const struct kvm_memory_slot *memslot, diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c index ff6c38373957..d79c5d1098c0 100644 --- a/arch/powerpc/kvm/book3s.c +++ b/arch/powerpc/kvm/book3s.c @@ -422,7 +422,7 @@ int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu) EXPORT_SYMBOL_GPL(kvmppc_core_prepare_to_enter); =20 kvm_pfn_t kvmppc_gpa_to_pfn(struct kvm_vcpu *vcpu, gpa_t gpa, bool writing, - bool *writable) + bool *writable, struct page **page) { ulong mp_pa =3D vcpu->arch.magic_page_pa & KVM_PAM; gfn_t gfn =3D gpa >> PAGE_SHIFT; @@ -437,13 +437,14 @@ kvm_pfn_t kvmppc_gpa_to_pfn(struct kvm_vcpu *vcpu, gp= a_t gpa, bool writing, kvm_pfn_t pfn; =20 pfn =3D (kvm_pfn_t)virt_to_phys((void*)shared_page) >> PAGE_SHIFT; - get_page(pfn_to_page(pfn)); + *page =3D pfn_to_page(pfn); + get_page(*page); if (writable) *writable =3D true; return pfn; } =20 - return gfn_to_pfn_prot(vcpu->kvm, gfn, writing, writable); + return kvm_faultin_pfn(vcpu, gfn, writing, writable, page); } EXPORT_SYMBOL_GPL(kvmppc_gpa_to_pfn); =20 diff --git a/arch/powerpc/kvm/book3s_32_mmu_host.c b/arch/powerpc/kvm/book3= s_32_mmu_host.c index 4b3a8d80cfa3..5b7212edbb13 100644 --- a/arch/powerpc/kvm/book3s_32_mmu_host.c +++ b/arch/powerpc/kvm/book3s_32_mmu_host.c @@ -130,6 +130,7 @@ extern char etext[]; int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte, bool iswrite) { + struct page *page; kvm_pfn_t hpaddr; u64 vpn; u64 vsid; @@ -145,7 +146,7 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct k= vmppc_pte *orig_pte, bool writable; =20 /* Get host physical address for gpa */ - hpaddr =3D kvmppc_gpa_to_pfn(vcpu, orig_pte->raddr, iswrite, &writable); + hpaddr =3D kvmppc_gpa_to_pfn(vcpu, orig_pte->raddr, iswrite, &writable, &= page); if (is_error_noslot_pfn(hpaddr)) { printk(KERN_INFO "Couldn't get guest page for gpa %lx!\n", orig_pte->raddr); @@ -232,7 +233,7 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct k= vmppc_pte *orig_pte, =20 pte =3D kvmppc_mmu_hpte_cache_next(vcpu); if (!pte) { - kvm_release_pfn_clean(hpaddr >> PAGE_SHIFT); + kvm_release_page_unused(page); r =3D -EAGAIN; goto out; } @@ -250,7 +251,7 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct k= vmppc_pte *orig_pte, =20 kvmppc_mmu_hpte_cache_map(vcpu, pte); =20 - kvm_release_pfn_clean(hpaddr >> PAGE_SHIFT); + kvm_release_page_clean(page); out: return r; } diff --git a/arch/powerpc/kvm/book3s_64_mmu_host.c b/arch/powerpc/kvm/book3= s_64_mmu_host.c index d0e4f7bbdc3d..be20aee6fd7d 100644 --- a/arch/powerpc/kvm/book3s_64_mmu_host.c +++ b/arch/powerpc/kvm/book3s_64_mmu_host.c @@ -88,13 +88,14 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct k= vmppc_pte *orig_pte, struct hpte_cache *cpte; unsigned long gfn =3D orig_pte->raddr >> PAGE_SHIFT; unsigned long pfn; + struct page *page; =20 /* used to check for invalidations in progress */ mmu_seq =3D kvm->mmu_invalidate_seq; smp_rmb(); =20 /* Get host physical address for gpa */ - pfn =3D kvmppc_gpa_to_pfn(vcpu, orig_pte->raddr, iswrite, &writable); + pfn =3D kvmppc_gpa_to_pfn(vcpu, orig_pte->raddr, iswrite, &writable, &pag= e); if (is_error_noslot_pfn(pfn)) { printk(KERN_INFO "Couldn't get guest page for gpa %lx!\n", orig_pte->raddr); @@ -199,10 +200,9 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct = kvmppc_pte *orig_pte, } =20 out_unlock: - if (!orig_pte->may_write || !writable) - kvm_release_pfn_clean(pfn); - else - kvm_release_pfn_dirty(pfn); + /* FIXME: Don't unconditionally pass unused=3Dfalse. */ + kvm_release_faultin_page(kvm, page, false, + orig_pte->may_write && writable); spin_unlock(&kvm->mmu_lock); if (cpte) kvmppc_mmu_hpte_cache_free(cpte); --=20 2.47.0.rc1.288.g06298d1525-goog