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

[PATCH] x86/p2m: don't calculate page owner twice in p2m_add_page()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Tue, 29 Nov 2022 15:47:53 +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=KXqcNSjY1JBioDkQ9SEAT1phAWhY/M3WTiUf0zQqqQ8=; b=XenCGMvoxrUu9mgF2USc0TfNQuutCnIcCg9w5EHt4q0HLlSRLXVkZLE9vsPwHWoLrItjtDCyNqgLUZqnYsRMIrITE23DNv+WigJVfVVT9DqyKKO5e2JhWQreZ07zxcnNYG+EMdBspYJlFG1AZu/mlKKQbF1XrWbQk7soc24EflSXaFngj7RruBfQ6cvQL/3I93Kf6+5shFjemLRhmex9hYq3wr4RNCidq6t3zBbaBpdob4qCciiYDirx5WoH5rtEye/uKla99a9AEjZ/MfQa6Sdr5TQgQIf0q9oULqbxobpcTeZ18Jacx3Ag+2YlWxKcSEJrCz8LqVgSNz7pGGY1nw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fIqrW4ZHeuIWC0JSmzcIFJRTCyzMpG0aOjQ6FnGmCx0PHAEurUqwO4DZPhNyDk+SNz9uRiitoMPbTLqd+t28xQ4Zq4V94vlgKX5r6AGfXurQQbuYXj2D+CvcOfTlPGPIJItStmPv0ZUZgHZkFKg3dsnoNO9M+hxQyhc3wqgFIgzvI6Reye5LJsplIyI1WRlT/WuR2+UGMIsap7PVvUStuT4tR9+HBgclZN/4jldp3K/th6jn4QXIFpaSAnUldz0Qh45bqBZVKjOdU/TMEi86f7xXsE50WMNONfV9usEExJptMC+SRTQZJ8bSkKCeLau2uVQvQY/UQqw/b8kPn63Gew==
  • 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, 29 Nov 2022 14:48:00 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Neither page_get_owner() nor mfn_to_page() are entirely trivial
operations - don't do the same thing twice in close succession. Instead
help CSE (when MEM_SHARING=y) by introducing a local variable holding
the page owner.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
According to my observations gcc12 manages to CSE mfn_to_page() but not
(all of) page_get_owner(). The overall savings there are, partly due to
knock-on effects, 64 bytes of code.

While looking there, "mfn_eq(omfn, mfn_add(mfn, i))" near the end of the
same loop caught my eye: Is that really correct? Shouldn't we fail the
operation if the MFN which "ogfn" was derived from doesn't match the MFN
"ogfn" maps to? Excluding grant mappings here is of course okay, but
that's already taken care of by the enclosing p2m_is_ram().

--- a/xen/arch/x86/mm/p2m.c
+++ b/xen/arch/x86/mm/p2m.c
@@ -691,8 +691,10 @@ p2m_add_page(struct domain *d, gfn_t gfn
     /* Then, look for m->p mappings for this range and deal with them */
     for ( i = 0; i < (1UL << page_order); i++ )
     {
-        if ( dom_cow &&
-             page_get_owner(mfn_to_page(mfn_add(mfn, i))) == dom_cow )
+        const struct domain *owner =
+            page_get_owner(mfn_to_page(mfn_add(mfn, i)));
+
+        if ( dom_cow && owner == dom_cow )
         {
             /* This is no way to add a shared page to your physmap! */
             gdprintk(XENLOG_ERR, "Adding shared mfn %lx directly to dom%d 
physmap not allowed.\n",
@@ -700,7 +702,7 @@ p2m_add_page(struct domain *d, gfn_t gfn
             p2m_unlock(p2m);
             return -EINVAL;
         }
-        if ( page_get_owner(mfn_to_page(mfn_add(mfn, i))) != d )
+        if ( owner != d )
             continue;
         ogfn = mfn_to_gfn(d, mfn_add(mfn, i));
         if ( !gfn_eq(ogfn, _gfn(INVALID_M2P_ENTRY)) &&



 


Rackspace

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