Skip to content

Commit e3d8ed5

Browse files
kvaneeshmpe
authored andcommitted
powerpc/kvm/book3s: Use find_kvm_host_pte in h_enter
Since kvmppc_do_h_enter can get called in realmode use low level arch_spin_lock which is safe to be called in realmode. 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 9781e75 commit e3d8ed5

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

arch/powerpc/kvm/book3s_64_mmu_hv.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,10 @@ static long kvmppc_virtmode_do_h_enter(struct kvm *kvm, unsigned long flags,
281281
{
282282
long ret;
283283

284-
/* Protect linux PTE lookup from page table destruction */
285-
rcu_read_lock_sched(); /* this disables preemption too */
284+
preempt_disable();
286285
ret = kvmppc_do_h_enter(kvm, flags, pte_index, pteh, ptel,
287286
kvm->mm->pgd, false, pte_idx_ret);
288-
rcu_read_unlock_sched();
287+
preempt_enable();
289288
if (ret == H_TOO_HARD) {
290289
/* this can't happen */
291290
pr_err("KVM: Oops, kvmppc_h_enter returned too hard!\n");

arch/powerpc/kvm/book3s_hv_rm_mmu.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ long kvmppc_do_h_enter(struct kvm *kvm, unsigned long flags,
210210
pte_t *ptep;
211211
unsigned int writing;
212212
unsigned long mmu_seq;
213-
unsigned long rcbits, irq_flags = 0;
213+
unsigned long rcbits;
214214

215215
if (kvm_is_radix(kvm))
216216
return H_FUNCTION;
@@ -248,17 +248,9 @@ long kvmppc_do_h_enter(struct kvm *kvm, unsigned long flags,
248248

249249
/* Translate to host virtual address */
250250
hva = __gfn_to_hva_memslot(memslot, gfn);
251-
/*
252-
* If we had a page table table change after lookup, we would
253-
* retry via mmu_notifier_retry.
254-
*/
255-
if (!realmode)
256-
local_irq_save(irq_flags);
257-
/*
258-
* If called in real mode we have MSR_EE = 0. Otherwise
259-
* we disable irq above.
260-
*/
261-
ptep = __find_linux_pte(pgdir, hva, NULL, &hpage_shift);
251+
252+
arch_spin_lock(&kvm->mmu_lock.rlock.raw_lock);
253+
ptep = find_kvm_host_pte(kvm, mmu_seq, hva, &hpage_shift);
262254
if (ptep) {
263255
pte_t pte;
264256
unsigned int host_pte_size;
@@ -272,8 +264,7 @@ long kvmppc_do_h_enter(struct kvm *kvm, unsigned long flags,
272264
* to <= host page size, if host is using hugepage
273265
*/
274266
if (host_pte_size < psize) {
275-
if (!realmode)
276-
local_irq_restore(flags);
267+
arch_spin_unlock(&kvm->mmu_lock.rlock.raw_lock);
277268
return H_PARAMETER;
278269
}
279270
pte = kvmppc_read_update_linux_pte(ptep, writing);
@@ -287,8 +278,7 @@ long kvmppc_do_h_enter(struct kvm *kvm, unsigned long flags,
287278
pa |= gpa & ~PAGE_MASK;
288279
}
289280
}
290-
if (!realmode)
291-
local_irq_restore(irq_flags);
281+
arch_spin_unlock(&kvm->mmu_lock.rlock.raw_lock);
292282

293283
ptel &= HPTE_R_KEY | HPTE_R_PP0 | (psize-1);
294284
ptel |= pa;

0 commit comments

Comments
 (0)