Skip to content

Commit ee0fa69

Browse files
sean-jcbonzini
authored andcommitted
KVM: PPC: Use kvm_vcpu_map() to map guest memory to patch dcbz instructions
Use kvm_vcpu_map() when patching dcbz in guest memory, as a regular GUP isn't technically sufficient when writing to data in the target pages. As per Documentation/core-api/pin_user_pages.rst: Correct (uses FOLL_PIN calls): pin_user_pages() write to the data within the pages unpin_user_pages() INCORRECT (uses FOLL_GET calls): get_user_pages() write to the data within the pages put_page() As a happy bonus, using kvm_vcpu_{,un}map() takes care of creating a mapping and marking the page dirty. Signed-off-by: Sean Christopherson <[email protected]> Tested-by: Dmitry Osipenko <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]> Message-ID: <[email protected]>
1 parent 17b7dba commit ee0fa69

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

arch/powerpc/kvm/book3s_pr.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -639,28 +639,27 @@ static void kvmppc_set_pvr_pr(struct kvm_vcpu *vcpu, u32 pvr)
639639
*/
640640
static void kvmppc_patch_dcbz(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte)
641641
{
642-
struct page *hpage;
642+
struct kvm_host_map map;
643643
u64 hpage_offset;
644644
u32 *page;
645-
int i;
645+
int i, r;
646646

647-
hpage = gfn_to_page(vcpu->kvm, pte->raddr >> PAGE_SHIFT);
648-
if (!hpage)
647+
r = kvm_vcpu_map(vcpu, pte->raddr >> PAGE_SHIFT, &map);
648+
if (r)
649649
return;
650650

651651
hpage_offset = pte->raddr & ~PAGE_MASK;
652652
hpage_offset &= ~0xFFFULL;
653653
hpage_offset /= 4;
654654

655-
page = kmap_atomic(hpage);
655+
page = map.hva;
656656

657657
/* patch dcbz into reserved instruction, so we trap */
658658
for (i=hpage_offset; i < hpage_offset + (HW_PAGE_SIZE / 4); i++)
659659
if ((be32_to_cpu(page[i]) & 0xff0007ff) == INS_DCBZ)
660660
page[i] &= cpu_to_be32(0xfffffff7);
661661

662-
kunmap_atomic(page);
663-
put_page(hpage);
662+
kvm_vcpu_unmap(vcpu, &map);
664663
}
665664

666665
static bool kvmppc_visible_gpa(struct kvm_vcpu *vcpu, gpa_t gpa)

0 commit comments

Comments
 (0)