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

[PATCH v2 1/3] x86/PoD: simplify / improve p2m_pod_cache_add()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 4 Jan 2022 10:48:19 +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=Is8eyqS5UXxKKaxllWqlmG+svyS0Sr+AMv6UtD6Pldg=; b=I1CsEA1zr7vU+Zeys3Xe0SSLoGLH5s9TsHjpPSs2HMmulf93CgF7FTrIPU5EDo4Wc9011twjxfLobvLrvHK/J4ViGDir2v8AJdAQc7ep6whzFurgANLDeIUX9ry7HSvURmVHetTwPeV6VBZDFvyMNV3jNY8MMVZNIYWyufsiA2vJ1ux8Vh9s5W1VKjCzetUryriPKqYWpNvfmyToFlThD1vvcIkmuzoQ4J3Zkx56dxTVsfY0r20iTUKhguQcijtP+ZR1l5/HsPHGCwww1GkNSmFHBw8yWCHl34UKAdvxHz36wAJcZJXanAdUBiD/k5kUkCF3r3vbR/jV1O1ma1ro+Q==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lEPut8a+paEEfOYuA9cYcDBhViwxvnuXSlq/BlwdO/tb9hMAaouLu1eRGMjx6HnYQO5v+ciJQjPGK7iFHJ2MRIhHmPDw+BeuupeXswwvTUdYvwZcLKq9dDcvAiUlYLLSnWSoNZX8xrVIg5Uajhkk7XDhTVk5iQCd4b7dOslAWn52qSy6xCaSpuAgQx3ZSG3A6obLJLAGUoTXxsplQ1J4FSUVtiOaP/7nP04az4ryzaFabbQwpuZmyA692eeS/JomGNlpzNn2Aruu1VZ5OJ/e3KBVqf0m9I/kSCBHAEbbvx1h9rQi0Aren8i+bHLl3sHHZZqTZFG1KT4+tH622U/44w==
  • 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>, George Dunlap <george.dunlap@xxxxxxxxxx>
  • Delivery-date: Tue, 04 Jan 2022 09:48:18 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Avoid recurring MFN -> page or page -> MFN translations. Drop the pretty
pointless local variable "p". Make sure the MFN logged in a debugging
error message is actually the offending one. Return negative errno
values rather than -1 (presently no caller really cares, but imo this
should change). Adjust style.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
v2: Return -errno. Drop exclamation mark from log message.

--- a/xen/arch/x86/mm/p2m-pod.c
+++ b/xen/arch/x86/mm/p2m-pod.c
@@ -58,34 +58,27 @@ p2m_pod_cache_add(struct p2m_domain *p2m
                   unsigned int order)
 {
     unsigned long i;
-    struct page_info *p;
     struct domain *d = p2m->domain;
+    mfn_t mfn = page_to_mfn(page);
 
 #ifndef NDEBUG
-    mfn_t mfn;
-
-    mfn = page_to_mfn(page);
-
     /* Check to make sure this is a contiguous region */
     if ( mfn_x(mfn) & ((1UL << order) - 1) )
     {
         printk("%s: mfn %lx not aligned order %u! (mask %lx)\n",
                __func__, mfn_x(mfn), order, ((1UL << order) - 1));
-        return -1;
+        return -EINVAL;
     }
 
-    for ( i = 0; i < 1UL << order ; i++)
+    for ( i = 0; i < (1UL << order); i++)
     {
-        struct domain * od;
+        const struct domain *od = page_get_owner(page + i);
 
-        p = mfn_to_page(mfn_add(mfn, i));
-        od = page_get_owner(p);
         if ( od != d )
         {
-            printk("%s: mfn %lx expected owner d%d, got owner d%d!\n",
-                   __func__, mfn_x(mfn), d->domain_id,
-                   od ? od->domain_id : -1);
-            return -1;
+            printk("%s: mfn %lx owner: expected %pd, got %pd\n",
+                   __func__, mfn_x(mfn) + i, d, od);
+            return -EACCES;
         }
     }
 #endif
@@ -98,16 +91,12 @@ p2m_pod_cache_add(struct p2m_domain *p2m
      * promise to provide zero pages. So we scrub pages before using.
      */
     for ( i = 0; i < (1UL << order); i++ )
-        clear_domain_page(mfn_add(page_to_mfn(page), i));
+        clear_domain_page(mfn_add(mfn, i));
 
     /* First, take all pages off the domain list */
     lock_page_alloc(p2m);
-    for ( i = 0; i < 1UL << order ; i++ )
-    {
-        p = page + i;
-        page_list_del(p, &d->page_list);
-    }
-
+    for ( i = 0; i < (1UL << order); i++ )
+        page_list_del(page + i, &d->page_list);
     unlock_page_alloc(p2m);
 
     /* Then add to the appropriate populate-on-demand list. */




 


Rackspace

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