All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: kvm@vger.kernel.org
Cc: babu.moger@amd.com
Subject: [PATCH kvm-unit-tests 1/2] access: optimize check for multiple reserved bits
Date: Fri, 13 Aug 2021 07:12:24 -0400	[thread overview]
Message-ID: <20210813111225.3603660-2-pbonzini@redhat.com> (raw)
In-Reply-To: <20210813111225.3603660-1-pbonzini@redhat.com>

Instead of using multiple ANDs statements, build a mask and check
it for more than one set bit.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 x86/access.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/x86/access.c b/x86/access.c
index c71f39d..6285c8c 100644
--- a/x86/access.c
+++ b/x86/access.c
@@ -288,6 +288,7 @@ static int ac_test_bump_one(ac_test_t *at)
 static _Bool ac_test_legal(ac_test_t *at)
 {
     int flags = at->flags;
+    unsigned reserved;
 
     if (F(AC_ACCESS_FETCH) && F(AC_ACCESS_WRITE))
 	return false;
@@ -321,8 +322,12 @@ static _Bool ac_test_legal(ac_test_t *at)
      * error code; the odds of a KVM bug are super low, and the odds of actually
      * being able to detect a bug are even lower.
      */
-    if ((F(AC_PDE_BIT51) + F(AC_PDE_BIT36) + F(AC_PDE_BIT13) +
-        F(AC_PTE_BIT51) + F(AC_PTE_BIT36)) > 1)
+    reserved = (AC_PDE_BIT51_MASK | AC_PDE_BIT36_MASK | AC_PDE_BIT13_MASK |
+	        AC_PTE_BIT51_MASK | AC_PTE_BIT36_MASK);
+
+    /* Only test one reserved bit at a time.  */
+    reserved &= flags;
+    if (reserved & (reserved - 1))
         return false;
 
     return true;
-- 
2.27.0



  reply	other threads:[~2021-08-13 11:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-13 11:12 [PATCH kvm-unit-tests 0/2] access: cut more execution time on reserved bit tests Paolo Bonzini
2021-08-13 11:12 ` Paolo Bonzini [this message]
2021-08-13 11:12 ` [PATCH kvm-unit-tests 2/2] access: treat NX as reserved if EFER.NXE=0 Paolo Bonzini
2021-08-13 15:32 ` [PATCH kvm-unit-tests 0/2] access: cut more execution time on reserved bit tests Babu Moger

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=20210813111225.3603660-2-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=babu.moger@amd.com \
    --cc=kvm@vger.kernel.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.