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

[PATCH 1/5] x86: support cache-writeback in flush_area_local() et al


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 19 Apr 2023 12:44:31 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XejQV07T8V2gYiQel4lhjkXlJAuuZk41L4stliIWs7I=; b=Hk/G0cOXWuIFoXbBkcN+W/iNWM3OXPMjIpOxtcV3WtkN+wxQkOnV7hXsPcdUEIAAZSrnekgEWYuy9CGkAj8GKgYS+xAAs/2ye8SQaQ5tuwNwuhDEydlRHP+jdD0C/BBdP0QVxOizuEV7VKcGo+nbrndyD1GLOqkJEEdx2HvN0CpowfGfsbSk69hnrovWWDhaHnvDzROFS1Q0IU7QhtaYNyXiKldRbgdaoRgvx5gUIl7N0NO5gQhvdggUUIC+Akfm2McqzxF0yrh2RfrC/AYewtjzY2n1aRsTmHeq1MXkZhGBuZ/8MurSonYsLU+8jOYXoGjVwtKgizXi88HjEyvX2g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SF3nigEobWvO4lZQvPg+fseXc0vqkXnOzT7Y66cbs3o4KzggUqnRa4N3ul0pGawJ/WYCByJSMDe1o8iVXV2yLUYJ29hFAQjE089vYsVQyHZ3VO8ZNQfdcd+Q/F+CjzHVPIZsvjnd5Y+U1Hf7/A1rFOcYiuRdv/L8o3ULnG/r9VnwJVntYWC9t740XAT+oMZFWT9gEMxNUiO2W1yUys1xvgIHpo8ahF38cbInlrCtlLGCdcpIKPGT9NplwxzwOrKcglxGoZpH8Ow+LDGpK4YKeY0IUlNvr9qRP3QuVV/N33mdmcXPjfvr82F3O3aPqhmnWXFTDsjR0Py22k2+yAolNw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Wed, 19 Apr 2023 10:44:39 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The majority of the present callers really aren't after invalidating
cache contents, but only after writeback. Make this available by simply
extending the FLUSH_CACHE handling accordingly. No feature checks are
required here: cache_writeback() falls back to cache_flush() as
necessary, while WBNOINVD degenerates to WBINVD on older hardware.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/xen/arch/x86/flushtlb.c
+++ b/xen/arch/x86/flushtlb.c
@@ -232,7 +232,7 @@ unsigned int flush_area_local(const void
     if ( flags & FLUSH_HVM_ASID_CORE )
         hvm_flush_guest_tlbs();
 
-    if ( flags & FLUSH_CACHE )
+    if ( flags & (FLUSH_CACHE | FLUSH_WRITEBACK) )
     {
         const struct cpuinfo_x86 *c = &current_cpu_data;
         unsigned long sz = 0;
@@ -245,13 +245,16 @@ unsigned int flush_area_local(const void
              c->x86_clflush_size && c->x86_cache_size && sz &&
              ((sz >> 10) < c->x86_cache_size) )
         {
-            cache_flush(va, sz);
-            flags &= ~FLUSH_CACHE;
+            if ( flags & FLUSH_CACHE )
+                cache_flush(va, sz);
+            else
+                cache_writeback(va, sz);
+            flags &= ~(FLUSH_CACHE | FLUSH_WRITEBACK);
         }
-        else
-        {
+        else if ( flags & FLUSH_CACHE )
             wbinvd();
-        }
+        else
+            wbnoinvd();
     }
 
     if ( flags & FLUSH_ROOT_PGTBL )
--- a/xen/arch/x86/include/asm/flushtlb.h
+++ b/xen/arch/x86/include/asm/flushtlb.h
@@ -135,6 +135,8 @@ void switch_cr3_cr4(unsigned long cr3, u
 #else
 # define FLUSH_NO_ASSIST 0
 #endif
+ /* Write back data cache contents */
+#define FLUSH_WRITEBACK  0x10000
 
 /* Flush local TLBs/caches. */
 unsigned int flush_area_local(const void *va, unsigned int flags);
@@ -194,7 +196,11 @@ static inline int clean_and_invalidate_d
 }
 static inline int clean_dcache_va_range(const void *p, unsigned long size)
 {
-    return clean_and_invalidate_dcache_va_range(p, size);
+    unsigned int order = get_order_from_bytes(size);
+
+    /* sub-page granularity support needs to be added if necessary */
+    flush_area_local(p, FLUSH_WRITEBACK | FLUSH_ORDER(order));
+    return 0;
 }
 
 unsigned int guest_flush_tlb_flags(const struct domain *d);




 


Rackspace

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