All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Wei Liu" <wl@xen.org>, "Roger Pau Monné" <roger.pau@citrix.com>,
	"Tim Deegan" <tim@xen.org>,
	"George Dunlap" <george.dunlap@citrix.com>
Subject: [PATCH 09/11] x86/shadow: simplify conditionals in sh_{get,put}_ref()
Date: Thu, 5 Jan 2023 17:06:36 +0100	[thread overview]
Message-ID: <0998689a-91b1-e381-ac63-a485ab2cb65d@suse.com> (raw)
In-Reply-To: <074dc3bb-6057-4f61-d516-d0fe3551165c@suse.com>

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@suse.com>
---
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;



  parent reply	other threads:[~2023-01-05 16:06 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-05 15:57 [PATCH 00/11] x86/shadow: misc tidying Jan Beulich
2023-01-05 15:59 ` [PATCH 01/11] x86/shadow: replace sh_reset_l3_up_pointers() Jan Beulich
2023-01-06  0:55   ` Andrew Cooper
2023-01-09  8:35     ` Jan Beulich
2023-01-05 15:59 ` [PATCH 02/11] x86/shadow: convert sh_audit_flags()'es 1st parameter to domain Jan Beulich
2023-01-05 15:59 ` [PATCH 03/11] x86/shadow: drop hash_vcpu_foreach() Jan Beulich
2023-01-05 16:00 ` [PATCH 04/11] x86/shadow: rename hash_domain_foreach() Jan Beulich
2023-01-05 16:04 ` [PATCH 05/11] x86/shadow: move bogus HVM checks in sh_pagetable_dying() Jan Beulich
2023-01-06  1:00   ` Andrew Cooper
2023-01-09  8:39     ` Jan Beulich
2023-01-05 16:04 ` [PATCH 06/11] x86/shadow: drop a few uses of mfn_valid() Jan Beulich
2023-01-06  1:02   ` Andrew Cooper
2023-01-09  8:42     ` Jan Beulich
2023-01-05 16:05 ` [PATCH 07/11] x86/shadow: L2H shadow type is PV32-only Jan Beulich
2023-01-06  1:31   ` Andrew Cooper
2023-01-09  9:12     ` Jan Beulich
2023-01-05 16:05 ` [PATCH 08/11] x86/shadow: reduce effort of hash calculation Jan Beulich
2023-01-06  2:03   ` Andrew Cooper
2023-01-09  9:48     ` Jan Beulich
2023-01-05 16:06 ` Jan Beulich [this message]
2023-01-05 16:07 ` [PATCH 10/11] x86/shadow: correct shadow type bounds checks Jan Beulich
2023-01-05 16:07 ` [PATCH 11/11] x86/shadow: sh_remove_all_mappings() is HVM-only Jan Beulich
2023-01-06  2:03 ` [PATCH 00/11] x86/shadow: misc tidying Andrew Cooper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0998689a-91b1-e381-ac63-a485ab2cb65d@suse.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=roger.pau@citrix.com \
    --cc=tim@xen.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.