Skip to contentSkip to conversation

x86/hap: Defer P2M TLB flushes

PATCH Superseded Ross Lagerwall 2 participants 2 messages Mar 18 – Mar 19

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/hap: Defer P2M TLB flushes

Like the EPT code, defer TLB flushes to reduce the number of flushes and avoid holding the P2M lock while flushing. This can substantially improve performance in some scenarios.

The cases where the TLB needs to be flushed without deferring are already handled by the call to p2m_tlb_flush_sync() in p2m_free_ptp().

---
 xen/arch/x86/mm/hap/hap.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
xen/arch/x86/mm/hap/hap.c +12 -2
index a337752bf488..1eba995c7b39 100644
@@ -813,16 +813,26 @@ static void cf_check hap_update_paging_modes(struct vcpu *v)
 
 static void cf_check
 hap_write_p2m_entry_post(struct p2m_domain *p2m, unsigned int oflags)
+{
+    if ( oflags & _PAGE_PRESENT )
+    {
+        ASSERT(p2m->defer_flush);
+        p2m->need_flush = true;
+    }
+}
+
+static void cf_check
+hap_p2m_tlb_flush(struct p2m_domain *p2m)
 {
     struct domain *d = p2m->domain;
 
-    if ( oflags & _PAGE_PRESENT )
-        guest_flush_tlb_mask(d, d->dirty_cpumask);
+    guest_flush_tlb_mask(d, d->dirty_cpumask);
 }
 
 void hap_p2m_init(struct p2m_domain *p2m)
 {
     p2m->write_p2m_entry_post = hap_write_p2m_entry_post;
+    p2m->tlb_flush = hap_p2m_tlb_flush;
 }
 
 static unsigned long cf_check hap_gva_to_gfn_real_mode(
Signature · 1 line
2.53.0
#1 lore raw

The subject should possibly mention NPT, as reading HAP one would assume it applies to both EPT and NPT (and the EPT side is already done here):

x86/hap: Defer NPT P2M TLB flushes

Quoted 18 lines · Ross Lagerwall

Like the EPT code, defer TLB flushes to reduce the number of flushes and avoid holding the P2M lock while flushing. This can substantially improve performance in some scenarios.

The cases where the TLB needs to be flushed without deferring are already handled by the call to p2m_tlb_flush_sync() in p2m_free_ptp().

---
 xen/arch/x86/mm/hap/hap.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
xen/arch/x86/mm/hap/hap.c +0 -0
index a337752bf488..1eba995c7b39 100644

xen/arch/x86/mm/hap/hap.c static void cf_check hap_update_paging_modes(struct vcpu *v) · line 819

Quoted 7 lines
xen/arch/x86/mm/hap/hap.c +4 -0
@@ -813,16 +813,26 @@ static void cf_check hap_update_paging_modes(struct vcpu *v)
 
 static void cf_check
 hap_write_p2m_entry_post(struct p2m_domain *p2m, unsigned int oflags)
+{
+    if ( oflags & _PAGE_PRESENT )
+    {
+        ASSERT(p2m->defer_flush);

Here I'm unsure whether we might want to do:

if ( !p2m->defer_flush )

{
    ASSERT_UNREACHABLE();
    guest_flush_tlb_mask(d, d->dirty_cpumask);
}

Instead of just asserting that the defer_flush field is set, to be on the safe(r) side.

Thanks, Roger.