]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
x86/mtrr: use memory_type_changed() in hvm_set_mem_pinned_cacheattr()
authorRoger Pau Monne <roger.pau@citrix.com>
Wed, 30 Apr 2025 14:33:50 +0000 (16:33 +0200)
committerRoger Pau Monne <roger.pau@citrix.com>
Tue, 6 May 2025 08:02:36 +0000 (10:02 +0200)
The current logic partially open-codes memory_type_changed(), but doesn't
check whether the type change or the cache flush is actually needed.
Instead switch to using memory_type_changed(), at possibly a higher expense
cost of not exclusively issuing cache flushes when limiting cacheability.

However using memory_type_changed() has the benefit of limiting
recalculations and cache flushes to strictly only when it's meaningful due
to the guest configuration, like having devices or IO regions assigned.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
xen/arch/x86/hvm/mtrr.c

index 797f2ae7fd3a4ac73e3ed86748cbf1572a07e414..b88e81eb44b1dd1c415fb5bcf10caff283deb149 100644 (file)
@@ -605,22 +605,8 @@ int hvm_set_mem_pinned_cacheattr(struct domain *d, uint64_t gfn_start,
 
                 type = range->type;
                 call_rcu(&range->rcu, free_pinned_cacheattr_entry);
-                p2m_memory_type_changed(d);
-                switch ( type )
-                {
-                case X86_MT_UCM:
-                    /*
-                     * For EPT we can also avoid the flush in this case;
-                     * see epte_get_entry_emt().
-                     */
-                    if ( hap_enabled(d) && cpu_has_vmx )
-                case X86_MT_UC:
-                        break;
-                    /* fall through */
-                default:
-                    flush_all(FLUSH_CACHE);
-                    break;
-                }
+                memory_type_changed(d);
+
                 return 0;
             }
         domain_unlock(d);
@@ -682,9 +668,7 @@ int hvm_set_mem_pinned_cacheattr(struct domain *d, uint64_t gfn_start,
 
     xfree(newr);
 
-    p2m_memory_type_changed(d);
-    if ( type != X86_MT_WB )
-        flush_all(FLUSH_CACHE);
+    memory_type_changed(d);
 
     return rc;
 }