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

[PATCH] x86: idle domains don't have a domain-page mapcache


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 5 Jan 2023 12:09:37 +0100
  • 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=xtJ2tMl3hWQX0ZOOqnHW05T+xWUWp8nD3ypTcC84mxA=; b=Z8bPzqLT7Tpl9Hu3kX2IH5Nf7UxqJpTlDW4MOPMurW7x7HyBW1NtQAZ17z771Dd5jDophr63DpdseZ6Cf083tF5+irVRi9FPo39x0TlyQTyoBQvAsP7yUQnkYaXDTX34HeG1gBZbIEKHKa+XZvzGeq1o4bcsVN5BoSpvGBx140Ru1nv/7xsvjBUMkhHybPhYf8MFI/cThQYFHBoRNowRy6/NRVFevKaUP8XIrW0FTsJ3alQwR4qo1UBZOeKNG6nimpd0htNr13FKjL7FXDc+s74emyMchScSpoEc25nfzVuKeCT823slpNRq1M/3TFW8CwJHRZZKx6zCq+jNhzpWCw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kPrUxtfFQq/gUda+YtL0dXlEP1j6oELrH4y/nr07aqQInol4goKcFbqRc4MxsOuYSzAFQT6g/dczZBll9U1Y8+QxoKRC6Y7YHHMkdfkIlrpDNVGk3vHuIQbqJ7Rggd8D1NkkNFmdSDRx2pjrM06+AoTjuIqoOm6nTkMrGU4hH/RpjrSVs6pMa41pJ9nXUm+yNnn5tZsXi/3ugSYATzAhDHr5vflkOrQZLBbRiz8buJ2E6/59OPVzbsG6sGphj2Z0KZJHEzSxVyDhCGbwCFfLv2EXUKb8yPyJO1b7X1Y7OepDIp8AqG1zQz3ZRFdYVxnA/qfXt1TCB5CaNDEul3ORew==
  • 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>, Julien Grall <julien@xxxxxxx>
  • Delivery-date: Thu, 05 Jan 2023 11:09:50 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

First and foremost correct a comment implying the opposite. Then, to
make things more clear PV-vs-HVM-wise, move the PV check earlier in the
function, making it unnecessary for both callers to perform the check
individually. Finally return NULL from the function when using the idle
domain's page tables, allowing a dcache->inuse check to also become an
assertion.

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

--- a/xen/arch/x86/domain_page.c
+++ b/xen/arch/x86/domain_page.c
@@ -28,8 +28,11 @@ static inline struct vcpu *mapcache_curr
     /*
      * When current isn't properly set up yet, this is equivalent to
      * running in an idle vCPU (callers must check for NULL).
+     *
+     * Non-PV domains don't have any mapcache.  For idle domains (which
+     * appear to be PV but also have no mapcache) see below.
      */
-    if ( !v )
+    if ( !v || !is_pv_vcpu(v) )
         return NULL;
 
     /*
@@ -41,19 +44,22 @@ static inline struct vcpu *mapcache_curr
         return NULL;
 
     /*
-     * If guest_table is NULL, and we are running a paravirtualised guest,
-     * then it means we are running on the idle domain's page table and must
-     * therefore use its mapcache.
+     * If guest_table is NULL for a PV domain (which includes IDLE), then it
+     * means we are running on the idle domain's page tables and therefore
+     * must not use any mapcache.
      */
-    if ( unlikely(pagetable_is_null(v->arch.guest_table)) && is_pv_vcpu(v) )
+    if ( unlikely(pagetable_is_null(v->arch.guest_table)) )
     {
         /* If we really are idling, perform lazy context switch now. */
-        if ( (v = idle_vcpu[smp_processor_id()]) == current )
+        if ( idle_vcpu[smp_processor_id()] == current )
             sync_local_execstate();
         /* We must now be running on the idle page table. */
         ASSERT(cr3_pa(read_cr3()) == __pa(idle_pg_table));
+        return NULL;
     }
 
+    ASSERT(!is_idle_vcpu(v));
+
     return v;
 }
 
@@ -82,13 +88,12 @@ void *map_domain_page(mfn_t mfn)
 #endif
 
     v = mapcache_current_vcpu();
-    if ( !v || !is_pv_vcpu(v) )
+    if ( !v )
         return mfn_to_virt(mfn_x(mfn));
 
     dcache = &v->domain->arch.pv.mapcache;
     vcache = &v->arch.pv.mapcache;
-    if ( !dcache->inuse )
-        return mfn_to_virt(mfn_x(mfn));
+    ASSERT(dcache->inuse);
 
     perfc_incr(map_domain_page_count);
 
@@ -187,7 +192,7 @@ void unmap_domain_page(const void *ptr)
     ASSERT(va >= MAPCACHE_VIRT_START && va < MAPCACHE_VIRT_END);
 
     v = mapcache_current_vcpu();
-    ASSERT(v && is_pv_vcpu(v));
+    ASSERT(v);
 
     dcache = &v->domain->arch.pv.mapcache;
     ASSERT(dcache->inuse);



 


Rackspace

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