Commit 3cca6b2
drm/i915/gvt: Protect gfn hash table with vgpu_lock
Use vgpu_lock instead of KVM's mmu_lock to protect accesses to the hash
table used to track which gfns are write-protected when shadowing the
guest's GTT, and hoist the acquisition of vgpu_lock from
intel_vgpu_page_track_handler() out to its sole caller,
kvmgt_page_track_write().
This fixes a bug where kvmgt_page_track_write(), which doesn't hold
kvm->mmu_lock, could race with intel_gvt_page_track_remove() and trigger
a use-after-free.
Fixing kvmgt_page_track_write() by taking kvm->mmu_lock is not an option
as mmu_lock is a r/w spinlock, and intel_vgpu_page_track_handler() might
sleep when acquiring vgpu->cache_lock deep down the callstack:
intel_vgpu_page_track_handler()
|
|-> page_track->handler / ppgtt_write_protection_handler()
|
|-> ppgtt_handle_guest_write_page_table_bytes()
|
|-> ppgtt_handle_guest_write_page_table()
|
|-> ppgtt_handle_guest_entry_removal()
|
|-> ppgtt_invalidate_pte()
|
|-> intel_gvt_dma_unmap_guest_page()
|
|-> mutex_lock(&vgpu->cache_lock);
Reviewed-by: Yan Zhao <yan.y.zhao@intel.com>
Tested-by: Yongwei Ma <yongwei.ma@intel.com>
Reviewed-by: Zhi Wang <zhi.a.wang@intel.com>
Link: https://lore.kernel.org/r/20230729013535.1070024-12-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>1 parent a90c367 commit 3cca6b2
2 files changed
Lines changed: 25 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
352 | 352 | | |
353 | 353 | | |
354 | 354 | | |
| 355 | + | |
| 356 | + | |
355 | 357 | | |
356 | 358 | | |
357 | 359 | | |
| |||
1553 | 1555 | | |
1554 | 1556 | | |
1555 | 1557 | | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
1556 | 1561 | | |
1557 | 1562 | | |
1558 | 1563 | | |
| |||
1561 | 1566 | | |
1562 | 1567 | | |
1563 | 1568 | | |
1564 | | - | |
1565 | | - | |
1566 | | - | |
1567 | | - | |
1568 | 1569 | | |
1569 | | - | |
1570 | | - | |
1571 | | - | |
1572 | 1570 | | |
| 1571 | + | |
1573 | 1572 | | |
| 1573 | + | |
| 1574 | + | |
1574 | 1575 | | |
1575 | 1576 | | |
1576 | 1577 | | |
| |||
1583 | 1584 | | |
1584 | 1585 | | |
1585 | 1586 | | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
1586 | 1590 | | |
1587 | 1591 | | |
1588 | 1592 | | |
| |||
1591 | 1595 | | |
1592 | 1596 | | |
1593 | 1597 | | |
1594 | | - | |
1595 | | - | |
1596 | | - | |
1597 | | - | |
1598 | 1598 | | |
1599 | | - | |
1600 | | - | |
1601 | | - | |
1602 | 1599 | | |
1603 | 1600 | | |
| 1601 | + | |
| 1602 | + | |
1604 | 1603 | | |
1605 | 1604 | | |
1606 | 1605 | | |
| |||
1611 | 1610 | | |
1612 | 1611 | | |
1613 | 1612 | | |
| 1613 | + | |
| 1614 | + | |
1614 | 1615 | | |
1615 | 1616 | | |
1616 | 1617 | | |
| 1618 | + | |
| 1619 | + | |
1617 | 1620 | | |
1618 | 1621 | | |
1619 | 1622 | | |
| |||
1625 | 1628 | | |
1626 | 1629 | | |
1627 | 1630 | | |
1628 | | - | |
| 1631 | + | |
| 1632 | + | |
1629 | 1633 | | |
1630 | 1634 | | |
1631 | 1635 | | |
| 1636 | + | |
1632 | 1637 | | |
1633 | 1638 | | |
| 1639 | + | |
| 1640 | + | |
1634 | 1641 | | |
1635 | 1642 | | |
1636 | 1643 | | |
1637 | | - | |
| 1644 | + | |
1638 | 1645 | | |
1639 | 1646 | | |
1640 | 1647 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
165 | | - | |
166 | | - | |
167 | 165 | | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
| 166 | + | |
| 167 | + | |
172 | 168 | | |
173 | 169 | | |
174 | 170 | | |
| |||
179 | 175 | | |
180 | 176 | | |
181 | 177 | | |
182 | | - | |
183 | | - | |
184 | 178 | | |
185 | 179 | | |
0 commit comments