[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging-4.20] x86/pv: fix MMUEXT_FLUSH_CACHE to flush all pCPU caches



commit ee150f56fca78f696e3fee4e8fa8a9adaa0fab4e
Author:     Roger Pau Monné <roger.pau@xxxxxxxxxx>
AuthorDate: Thu May 15 09:04:43 2025 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Thu May 15 09:04:43 2025 +0200

    x86/pv: fix MMUEXT_FLUSH_CACHE to flush all pCPU caches
    
    The implementation of MMUEXT_FLUSH_CACHE is bogus, as it doesn't account to
    flush the cache of any previous pCPU where the current vCPU might have run,
    and hence is likely to not work as expected.
    
    Fix this by resorting to use the same logic as MMUEXT_FLUSH_CACHE_GLOBAL,
    which will be correct in all cases.
    
    Adjust MMUEXT_FLUSH_CACHE_GLOBAL return code in case cache flush is not
    permitted for the domain to use -EACCES instead of -EINVAL, as that's more
    accurate and also matches the error code used by MMUEXT_FLUSH_CACHE.
    
    Fixes: 8e90e37e6db8 ("Fix WBINVD by adding a new hypercall.")
    Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
    Acked-by: Jan Beulich <jbeulich@xxxxxxxx>
    master commit: bbaea9878bf6d11f6f336710148dbbd26e927cfd
    master date: 2025-05-13 19:43:48 +0200
---
 xen/arch/x86/mm.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c
index 3f43cbabe1..3430b13dcd 100644
--- a/xen/arch/x86/mm.c
+++ b/xen/arch/x86/mm.c
@@ -3811,14 +3811,11 @@ long do_mmuext_op(
             break;
 
         case MMUEXT_FLUSH_CACHE:
-            if ( unlikely(currd != pg_owner) )
-                rc = -EPERM;
-            else if ( unlikely(!cache_flush_permitted(currd)) )
-                rc = -EACCES;
-            else
-                wbinvd();
-            break;
-
+            /*
+             * Dirty pCPU caches where the current vCPU has been scheduled are
+             * not tracked, and hence we need to resort to a global cache
+             * flush for correctness.
+             */
         case MMUEXT_FLUSH_CACHE_GLOBAL:
             if ( unlikely(currd != pg_owner) )
                 rc = -EPERM;
@@ -3835,7 +3832,7 @@ long do_mmuext_op(
                 flush_mask(mask, FLUSH_CACHE);
             }
             else
-                rc = -EINVAL;
+                rc = -EACCES;
             break;
 
         case MMUEXT_SET_LDT:
--
generated by git-patchbot for /home/xen/git/xen.git#staging-4.20



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.