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

[PATCH v1 13/13] xen/arm: unmap foreign memory mapping when destroyed domain is owner domain


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Penny Zheng <Penny.Zheng@xxxxxxx>
  • Date: Fri, 11 Mar 2022 14:11:23 +0800
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 40.67.248.234) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=none (message not signed); 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=a4JLEIb5PBTxY4a54x6twnAqTQYE+B3WX7UNftnFy/Y=; b=CnDeoL7KRuf3AES+KHlb8NEtpPl4OykRncA5pUO+Dql6iWpYiuH1Hr+n+va+wIjo65guJvg0b9NdDg4966XYss+OyCeKop7rIVZqmW2ulSsXiz8lcWHvrDEEW67hNyNIMfVI/yvpFYHwHxT9wGEPELjraE9fnRNYBo6uBCUHcf2CF2BUXbwnEpcfH7XASJq1sEqjy/ImZr115DcBcc2muhe20u53fAeWaefXAvFcZOnwhQrGMDusFAviDpt0YYbkzICzJE8z6HJlOzF+ZAvySsYm+0fJuUplXiy2Npzi8oZTR76NUjsgeA69AQLF5t2OXFgNxhWltkoEFEz+7LsKxA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AiKndQNN58ZHsVaj3z8ySMKYedS5Vl9IFXeO8xgYkdV5gsnODpGJpvIn+CcdefVsmByU6tWfS9j6Htghq7vLSPh5A2YB1ZD7wRwnoGBkAP8bhLyRIqhAmEhYuSQeCGgfWMweWRr25/DFh/BmQUuaxcZl6X5A8lXYKXur+HbSiwzG4OI72BgF+AOODq3+VfrdRY+d7fM90HsArq+vysOTUqiTRsFUiz6HjSMIEPl9n/CnM6iYgwmy3PAlF3txB+CsImJvN41jyDSseB6e8OIZdH/pBeydy1FpNnUY5juo8LCarDKtOxXALpnxJ6MgTQIoiwnU5QC5r9/Z7ok8iKVUZQ==
  • Cc: <nd@xxxxxxx>, Penny Zheng <penny.zheng@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Fri, 11 Mar 2022 06:16:26 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true

From: Penny Zheng <penny.zheng@xxxxxxx>

When destroyed domain is an owner domain of a static shared memory
region, then we need to ensure that all according borrower domains
shall not have the access to this static shared memory region too.

This commit covers above scenario through unmapping all borrowers'
according foreign memory mapping when destroyed domain is a owner
domain of a static shared memory region.

NOTE: It will best for users to destroy all borrowers before the owner
domain in case encountering data abort when accidentally accessing
the static shared memory region.

Signed-off-by: Penny Zheng <penny.zheng@xxxxxxx>
---
 xen/arch/arm/domain.c | 88 ++++++++++++++++++++++++++++++++++---------
 1 file changed, 71 insertions(+), 17 deletions(-)

diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index 73ffbfb918..8f4a8dcbfc 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -998,10 +998,39 @@ static int relinquish_memory(struct domain *d, struct 
page_list_head *list)
 }
 
 #ifdef CONFIG_STATIC_SHM
+static int destroy_shm(struct domain *d, gfn_t gfn, unsigned long nr_gfns)
+{
+    unsigned long i = 0;
+    int ret = 0;
+
+    for ( ; i < nr_gfns; i++ )
+    {
+        mfn_t mfn;
+
+        mfn = gfn_to_mfn(d, gfn_add(gfn, i));
+        if ( !mfn_valid(mfn) )
+        {
+            dprintk(XENLOG_ERR,
+                    "Domain %pd page number %lx invalid.\n",
+                    d, gfn_x(gfn) + i);
+            return -EINVAL;
+        }
+
+        ret = guest_physmap_remove_page(d, gfn_add(gfn, i), mfn, 0);
+        if ( ret )
+            return ret;
+
+        /* Drop the reference. */
+        put_page(mfn_to_page(mfn));
+    }
+
+    return ret;
+}
+
 static int domain_destroy_shm(struct domain *d)
 {
     int ret = 0;
-    unsigned long i = 0UL, j;
+    unsigned long i = 0UL;
 
     if ( d->arch.shm_mem == NULL )
         return ret;
@@ -1009,29 +1038,54 @@ static int domain_destroy_shm(struct domain *d)
     {
         for ( ; i < d->arch.shm_mem->nr_banks; i++ )
         {
+            u32 shm_id = d->arch.shm_mem->bank[i].shm_id;
             unsigned long nr_gfns = PFN_DOWN(d->arch.shm_mem->bank[i].size);
             gfn_t gfn = gaddr_to_gfn(d->arch.shm_mem->bank[i].start);
 
-            for ( j = 0; j < nr_gfns; j++ )
+            if ( test_bit(shm_id, shm_list_mask) )
             {
-                mfn_t mfn;
-
-                mfn = gfn_to_mfn(d, gfn_add(gfn, j));
-                if ( !mfn_valid(mfn) )
+                domid_t od = shm_list[shm_id].owner_dom;
+                unsigned long j;
+                /*
+                 * If it is a owner domain, then after it gets destroyed,
+                 * static shared memory region shall be unaccessible to all
+                 * borrower domains too.
+                 */
+                if ( d->domain_id == od )
                 {
-                    dprintk(XENLOG_ERR,
-                            "Domain %pd page number %lx invalid.\n",
-                            d, gfn_x(gfn) + i);
-                    return -EINVAL;
+                    struct domain *bd;
+
+                    for ( j = 0; j < shm_list[shm_id].nr_borrower; j++ )
+                    {
+                        bd = 
get_domain_by_id(shm_list[shm_id].borrower_dom[j]);
+                        /*
+                         * borrower domain could be dead already, in such case
+                         * no need to do the unmapping.
+                         */
+                        if ( bd != NULL )
+                        {
+                            gfn_t b_gfn = gaddr_to_gfn(
+                                          shm_list[shm_id].borrower_gbase[j]);
+                            ret = destroy_shm(bd, b_gfn, nr_gfns);
+                            if ( ret )
+                                dprintk(XENLOG_ERR,
+                                        "Domain %pd: failed to destroy static 
shared memory.\n",
+                                        bd);
+                        }
+                    }
+
+                    continue;
                 }
-
-                ret = guest_physmap_remove_page(d, gfn_add(gfn, j), mfn, 0);
-                if ( ret )
-                    return ret;
-
-                /* Drop the reference. */
-                put_page(mfn_to_page(mfn));
             }
+            /*
+             * As borrower domain, remove foreign memory mapping and drop the
+             * reference count.
+             */
+            ret = destroy_shm(d, gfn, nr_gfns);
+            if ( ret )
+                dprintk(XENLOG_ERR,
+                        "Domain %pd: failed to destroy static shared 
memory.\n",
+                        d);
         }
     }
 
-- 
2.25.1




 


Rackspace

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