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

[PATCH 1/9] gnttab: defer allocation of maptrack frames table


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 26 Aug 2021 12:09:17 +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-SenderADCheck; bh=1sa8Fe77gt8qRj28nz+tzjOoJt1XN6A7BIFTYCnT5LA=; b=UBEsFXrWkjO/lE5i0GPFTSM4Md6lrKJT9sfwVCCzwSiGIQhh8AIKFXzo/sKDKpz3atKRGnxAu4Ui45dtleUBo0yKucMav9m2X5rYlfc7aiJTH4/68BtPGgTRjA063W/ZhxHYd9spPNIzyYwHTb49dIAkAkAFfrQIVfFdNr6/Qy01n4Bcst854a9Gg/zov0pVYEtmDDivB3OlgFKM4qu07Vvywux2+5E/o8fA8tfhmREvOJ4JWjqRWedp12D/k+aaexVKyGBn2kZnmLMj/86+gkRav0WN2wLdn3682tWsPaL4X0Wfv//+XvxJj7TBkfOjN+ah0PUFcsdDOnJsrckaVA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ilwdX3hHicpbD62xvWuXm0Vhs6gUuEe+e6jcRPGS9Txdv0L/NJVazWO/lK8dDINJXltn+CNFFnWcF3mykNzSZjmEtj4fwirrXWehslEBo55WanQ3Ew/Y/Nt+p76AHv6L/CkLX8qCfAclterHbTVTp5Iq+rR5mqn+eEtn3WxS5/Qf5H1qq6XcziXhFXD4xbM0BREL4P7jq1Au5PHIikBFGHlZAIT7rtWM2Db41Xzv8P+6decMPNJSKX3f0IjydWV+EYfC8wpKBDQFisMg1L0tG+8qN127K/OtrSJXjtzmpJWxB6vLExj2p4aoMd1nrUjfxai2gbkskqXC5gA0/l8Wrw==
  • Authentication-results: xen.org; dkim=none (message not signed) header.d=none;xen.org; dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Ian Jackson <iwj@xxxxxxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Thu, 26 Aug 2021 10:09:28 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

By default all guests are permitted to have up to 1024 maptrack frames,
which on 64-bit means an 8k frame table. Yet except for driver domains
guests normally don't make use of grant mappings. Defer allocating the
table until a map track handle is first requested.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
I continue to be unconvinced that it is a good idea to allow all DomU-s
1024 maptrack frames by default. While I'm still of the opinion that a
hypervisor enforced upper bound is okay, I question this upper bound
also getting used as the default value - this is perhaps okay for Dom0,
but not elsewhere.

--- a/xen/common/grant_table.c
+++ b/xen/common/grant_table.c
@@ -633,6 +633,34 @@ get_maptrack_handle(
     if ( likely(handle != INVALID_MAPTRACK_HANDLE) )
         return handle;
 
+    if ( unlikely(!read_atomic(&lgt->maptrack)) )
+    {
+        struct grant_mapping **maptrack = NULL;
+
+        if ( lgt->max_maptrack_frames )
+            maptrack = vzalloc(lgt->max_maptrack_frames * sizeof(*maptrack));
+
+        spin_lock(&lgt->maptrack_lock);
+
+        if ( !lgt->maptrack )
+        {
+            if ( !maptrack )
+            {
+                spin_unlock(&lgt->maptrack_lock);
+                return INVALID_MAPTRACK_HANDLE;
+            }
+
+            write_atomic(&lgt->maptrack, maptrack);
+            maptrack = NULL;
+
+            radix_tree_init(&lgt->maptrack_tree);
+        }
+
+        spin_unlock(&lgt->maptrack_lock);
+
+        vfree(maptrack);
+    }
+
     spin_lock(&lgt->maptrack_lock);
 
     /*
@@ -1955,16 +1983,6 @@ int grant_table_init(struct domain *d, i
     if ( gt->active == NULL )
         goto out;
 
-    /* Tracking of mapped foreign frames table */
-    if ( gt->max_maptrack_frames )
-    {
-        gt->maptrack = vzalloc(gt->max_maptrack_frames * 
sizeof(*gt->maptrack));
-        if ( gt->maptrack == NULL )
-            goto out;
-
-        radix_tree_init(&gt->maptrack_tree);
-    }
-
     /* Shared grant table. */
     gt->shared_raw = xzalloc_array(void *, gt->max_grant_frames);
     if ( gt->shared_raw == NULL )




 


Rackspace

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