Skip to content

Commit 6cdf303

Browse files
kvaneeshmpe
authored andcommitted
powerpc/kvm/book3s: Use kvm helpers to walk shadow or secondary table
update kvmppc_hv_handle_set_rc to use find_kvm_nested_guest_pte and find_kvm_secondary_pte Signed-off-by: Aneesh Kumar K.V <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent dc89184 commit 6cdf303

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

arch/powerpc/include/asm/kvm_book3s.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ extern void kvmppc_unmap_pte(struct kvm *kvm, pte_t *pte, unsigned long gpa,
198198
unsigned int shift,
199199
const struct kvm_memory_slot *memslot,
200200
unsigned int lpid);
201-
extern bool kvmppc_hv_handle_set_rc(struct kvm *kvm, pgd_t *pgtable,
201+
extern bool kvmppc_hv_handle_set_rc(struct kvm *kvm, bool nested,
202202
bool writing, unsigned long gpa,
203203
unsigned int lpid);
204204
extern int kvmppc_book3s_instantiate_page(struct kvm_vcpu *vcpu,

arch/powerpc/include/asm/kvm_book3s_64.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,9 @@ static inline pte_t *find_kvm_secondary_pte(struct kvm *kvm, unsigned long ea,
647647
return pte;
648648
}
649649

650+
extern pte_t *find_kvm_nested_guest_pte(struct kvm *kvm, unsigned long lpid,
651+
unsigned long ea, unsigned *hshift);
652+
650653
#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */
651654

652655
#endif /* __ASM_KVM_BOOK3S_64_H__ */

arch/powerpc/kvm/book3s_64_mmu_radix.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ int kvmppc_create_pte(struct kvm *kvm, pgd_t *pgtable, pte_t pte,
735735
return ret;
736736
}
737737

738-
bool kvmppc_hv_handle_set_rc(struct kvm *kvm, pgd_t *pgtable, bool writing,
738+
bool kvmppc_hv_handle_set_rc(struct kvm *kvm, bool nested, bool writing,
739739
unsigned long gpa, unsigned int lpid)
740740
{
741741
unsigned long pgflags;
@@ -750,12 +750,12 @@ bool kvmppc_hv_handle_set_rc(struct kvm *kvm, pgd_t *pgtable, bool writing,
750750
pgflags = _PAGE_ACCESSED;
751751
if (writing)
752752
pgflags |= _PAGE_DIRTY;
753-
/*
754-
* We are walking the secondary (partition-scoped) page table here.
755-
* We can do this without disabling irq because the Linux MM
756-
* subsystem doesn't do THP splits and collapses on this tree.
757-
*/
758-
ptep = __find_linux_pte(pgtable, gpa, NULL, &shift);
753+
754+
if (nested)
755+
ptep = find_kvm_nested_guest_pte(kvm, lpid, gpa, &shift);
756+
else
757+
ptep = find_kvm_secondary_pte(kvm, gpa, &shift);
758+
759759
if (ptep && pte_present(*ptep) && (!writing || pte_write(*ptep))) {
760760
kvmppc_radix_update_pte(kvm, ptep, 0, pgflags, gpa, shift);
761761
return true;
@@ -949,8 +949,8 @@ int kvmppc_book3s_radix_page_fault(struct kvm_run *run, struct kvm_vcpu *vcpu,
949949
/* Failed to set the reference/change bits */
950950
if (dsisr & DSISR_SET_RC) {
951951
spin_lock(&kvm->mmu_lock);
952-
if (kvmppc_hv_handle_set_rc(kvm, kvm->arch.pgtable,
953-
writing, gpa, kvm->arch.lpid))
952+
if (kvmppc_hv_handle_set_rc(kvm, false, writing,
953+
gpa, kvm->arch.lpid))
954954
dsisr &= ~DSISR_SET_RC;
955955
spin_unlock(&kvm->mmu_lock);
956956

arch/powerpc/kvm/book3s_hv_nested.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,8 @@ static struct kvm_nested_guest *kvmhv_find_nested(struct kvm *kvm, int lpid)
750750
return kvm->arch.nested_guests[lpid];
751751
}
752752

753-
static pte_t *find_kvm_nested_guest_pte(struct kvm *kvm, unsigned long lpid,
754-
unsigned long ea, unsigned *hshift)
753+
pte_t *find_kvm_nested_guest_pte(struct kvm *kvm, unsigned long lpid,
754+
unsigned long ea, unsigned *hshift)
755755
{
756756
struct kvm_nested_guest *gp;
757757
pte_t *pte;
@@ -767,7 +767,6 @@ static pte_t *find_kvm_nested_guest_pte(struct kvm *kvm, unsigned long lpid,
767767
return pte;
768768
}
769769

770-
771770
static inline bool kvmhv_n_rmap_is_equal(u64 rmap_1, u64 rmap_2)
772771
{
773772
return !((rmap_1 ^ rmap_2) & (RMAP_NESTED_LPID_MASK |
@@ -1226,16 +1225,16 @@ static long kvmhv_handle_nested_set_rc(struct kvm_vcpu *vcpu,
12261225

12271226
spin_lock(&kvm->mmu_lock);
12281227
/* Set the rc bit in the pte of our (L0) pgtable for the L1 guest */
1229-
ret = kvmppc_hv_handle_set_rc(kvm, kvm->arch.pgtable, writing,
1230-
gpte.raddr, kvm->arch.lpid);
1228+
ret = kvmppc_hv_handle_set_rc(kvm, false, writing,
1229+
gpte.raddr, kvm->arch.lpid);
12311230
if (!ret) {
12321231
ret = -EINVAL;
12331232
goto out_unlock;
12341233
}
12351234

12361235
/* Set the rc bit in the pte of the shadow_pgtable for the nest guest */
1237-
ret = kvmppc_hv_handle_set_rc(kvm, gp->shadow_pgtable, writing, n_gpa,
1238-
gp->shadow_lpid);
1236+
ret = kvmppc_hv_handle_set_rc(kvm, true, writing,
1237+
n_gpa, gp->shadow_lpid);
12391238
if (!ret)
12401239
ret = -EINVAL;
12411240
else

0 commit comments

Comments
 (0)