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

[PATCH 09/11] x86/shadow: simplify conditionals in sh_{get,put}_ref()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 5 Jan 2023 17:06:36 +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=iBgM5VtWVqIkPoDCOPK8xEPFq96mp+OUcLEBtT+07eA=; b=ZlHpO0xn9nPfqrWGjoomxwjgSXtoEQvCZAtYBuqneles+J7jyoz3PlESkWmfdEhpcr78533t5xqRSPwQIL5VA3MOGUVoexYKzIw5wvhP8hwX+oSUv5U+0jCcXnpViZVaQeTaSIf3tonW5XLKp6SgjpoWnnMBFDplXIkUKybfRJEEG1XwpBME47OLP8NyYexaNHdbVojtKNljyp7RVnuELpO6I7wP2lW29QB05peTl/Qwve25GNtEZ/uDPw+2PIwJdQFmFOyDbe4g+eHfCyRJ6m2VulvlssUI+OMeEEwl2nlhbH/qxnjVRhuqgp5N5LmaGg5NsIS6FIANbjwC12M0Iw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l4YhXWejcZbws13WDR0aSs6oVQoxmssMvS6YypsZTBokNSZJ9iiDVsXHqYHgXkdAsoHjvCFIlfg7kr7p/fCVUxfHLrUSQkICw6Ia+Fc7LirDbF/np3/oebizf+9HFM8Aa6CLSUE2kytICE0Ung6Z3fnGylwiwiOlaPkZAs6dpMWGkeM9ODMRASQh+paGb5CFWgR0Kv/5kz5+GtxeTPabRc4SfKhoUJx3LHmXbZ7EPwE+QcwXyAueXy/Dxbhi4asxcjtP3L3SptiRsNmTCoWBHaRV2vHFuELT4Wwx27l4KucBIlNNOY7RTEIPiR8o8uvBGZ7AMXTqNPYfJS1VKqqzgw==
  • 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>, Tim Deegan <tim@xxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>
  • Delivery-date: Thu, 05 Jan 2023 16:06:41 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

In both cases the "entry_pa != 0" check is redundant; storing 0 when the
field already is 0 is quite fine. Move the cheaper remaining part first
in sh_get_ref(). In sh_put_ref() convert the has-up-pointer check into
an assertion (requiring the zero check to be retained there).

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
---
RFC: Strictly speaking accessing ->up ahead of checking that the type
     actually has an "up" pointer is UB, as only the last written field
     of a union may be read. But we have violations of this rule in many
     other places, so I guess we can assume to be okay-ish here as well.

--- a/xen/arch/x86/mm/shadow/private.h
+++ b/xen/arch/x86/mm/shadow/private.h
@@ -586,9 +586,7 @@ static inline int sh_get_ref(struct doma
     sp->u.sh.count = nx;
 
     /* We remember the first shadow entry that points to each shadow. */
-    if ( entry_pa != 0
-         && sh_type_has_up_pointer(d, sp->u.sh.type)
-         && sp->up == 0 )
+    if ( !sp->up && sh_type_has_up_pointer(d, sp->u.sh.type) )
         sp->up = entry_pa;
 
     return 1;
@@ -607,10 +605,11 @@ static inline void sh_put_ref(struct dom
     ASSERT(!(sp->count_info & PGC_count_mask));
 
     /* If this is the entry in the up-pointer, remove it */
-    if ( entry_pa != 0
-         && sh_type_has_up_pointer(d, sp->u.sh.type)
-         && sp->up == entry_pa )
+    if ( sp->up == entry_pa )
+    {
+        ASSERT(!entry_pa || sh_type_has_up_pointer(d, sp->u.sh.type));
         sp->up = 0;
+    }
 
     x = sp->u.sh.count;
     nx = x - 1;




 


Rackspace

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