From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
"Wei Liu" <wei.liu2@citrix.com>,
"Jan Beulich" <JBeulich@suse.com>,
"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH v2 1/5] x86/entry: Correct comparisons against boolean variables
Date: Tue, 27 Feb 2018 14:50:32 +0000 [thread overview]
Message-ID: <1519743036-11600-2-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1519743036-11600-1-git-send-email-andrew.cooper3@citrix.com>
The correct way to check a boolean is `cmpb $0` or `testb $0xff`, whereas a
lot of our entry code uses `testb $1`. This will work in principle for values
which are really C _Bool types, but won't work for other integer types which
are intended to have boolean properties.
cmp is the more logical way of thinking about the operation, so adjust all
outstanding uses of `testb $1` against boolean values. Changing test to cmp
changes the logical mnemonic of the following condition from 'zero' to
'equal', but the actual encoding remains the same.
No functional change, as all uses are real C _Bool types, and confirmed by
diffing the disassembly.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
New in v2
---
xen/arch/x86/x86_64/compat/entry.S | 8 ++++----
xen/arch/x86/x86_64/entry.S | 28 ++++++++++++++--------------
2 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/xen/arch/x86/x86_64/compat/entry.S b/xen/arch/x86/x86_64/compat/entry.S
index 458d810..3e8b6c1 100644
--- a/xen/arch/x86/x86_64/compat/entry.S
+++ b/xen/arch/x86/x86_64/compat/entry.S
@@ -41,11 +41,11 @@ ENTRY(compat_test_all_events)
leaq irq_stat+IRQSTAT_softirq_pending(%rip),%rcx
cmpl $0,(%rcx,%rax,1)
jne compat_process_softirqs
- testb $1,VCPU_mce_pending(%rbx)
- jnz compat_process_mce
+ cmpb $0, VCPU_mce_pending(%rbx)
+ jne compat_process_mce
.Lcompat_test_guest_nmi:
- testb $1,VCPU_nmi_pending(%rbx)
- jnz compat_process_nmi
+ cmpb $0, VCPU_nmi_pending(%rbx)
+ jne compat_process_nmi
compat_test_guest_events:
movq VCPU_vcpu_info(%rbx),%rax
movzwl COMPAT_VCPUINFO_upcall_pending(%rax),%eax
diff --git a/xen/arch/x86/x86_64/entry.S b/xen/arch/x86/x86_64/entry.S
index 941f06f..6249efe 100644
--- a/xen/arch/x86/x86_64/entry.S
+++ b/xen/arch/x86/x86_64/entry.S
@@ -190,11 +190,11 @@ test_all_events:
leaq irq_stat+IRQSTAT_softirq_pending(%rip),%rcx
cmpl $0,(%rcx,%rax,1)
jne process_softirqs
- testb $1,VCPU_mce_pending(%rbx)
- jnz process_mce
+ cmpb $0, VCPU_mce_pending(%rbx)
+ jne process_mce
.Ltest_guest_nmi:
- testb $1,VCPU_nmi_pending(%rbx)
- jnz process_nmi
+ cmpb $0, VCPU_nmi_pending(%rbx)
+ jne process_nmi
test_guest_events:
movq VCPU_vcpu_info(%rbx),%rax
movzwl VCPUINFO_upcall_pending(%rax),%eax
@@ -305,8 +305,8 @@ UNLIKELY_END(sysenter_gpf)
movq VCPU_domain(%rbx),%rdi
movq %rax,TRAPBOUNCE_eip(%rdx)
movb %cl,TRAPBOUNCE_flags(%rdx)
- testb $1,DOMAIN_is_32bit_pv(%rdi)
- jnz compat_sysenter
+ cmpb $0, DOMAIN_is_32bit_pv(%rdi)
+ jne compat_sysenter
jmp .Lbounce_exception
ENTRY(int80_direct_trap)
@@ -342,8 +342,8 @@ UNLIKELY_END(msi_check)
jz int80_slow_path
movq VCPU_domain(%rbx),%rax
- testb $1,DOMAIN_is_32bit_pv(%rax)
- jnz compat_int80_direct_trap
+ cmpb $0, DOMAIN_is_32bit_pv(%rax)
+ jne compat_int80_direct_trap
call create_bounce_frame
jmp test_all_events
@@ -484,8 +484,8 @@ ENTRY(dom_crash_sync_extable)
# create_bounce_frame() temporarily clobbers CS.RPL. Fix up.
movq STACK_CPUINFO_FIELD(current_vcpu)(%rax), %rax
movq VCPU_domain(%rax),%rax
- testb $1,DOMAIN_is_32bit_pv(%rax)
- setz %al
+ cmpb $0, DOMAIN_is_32bit_pv(%rax)
+ sete %al
leal (%rax,%rax,2),%eax
orb %al,UREGS_cs(%rsp)
xorl %edi,%edi
@@ -529,8 +529,8 @@ ENTRY(ret_from_intr)
testb $3,UREGS_cs(%rsp)
jz restore_all_xen
movq VCPU_domain(%rbx),%rax
- testb $1,DOMAIN_is_32bit_pv(%rax)
- jz test_all_events
+ cmpb $0, DOMAIN_is_32bit_pv(%rax)
+ je test_all_events
jmp compat_test_all_events
ENTRY(page_fault)
@@ -629,8 +629,8 @@ handle_exception_saved:
jz restore_all_xen
leaq VCPU_trap_bounce(%rbx),%rdx
movq VCPU_domain(%rbx),%rax
- testb $1,DOMAIN_is_32bit_pv(%rax)
- jnz compat_post_handle_exception
+ cmpb $0, DOMAIN_is_32bit_pv(%rax)
+ jne compat_post_handle_exception
testb $TBF_EXCEPTION,TRAPBOUNCE_flags(%rdx)
jz test_all_events
.Lbounce_exception:
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-02-27 14:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-27 14:50 [PATCH v2 0/5] x86: Lift create_exception_frame() up out of C Andrew Cooper
2018-02-27 14:50 ` Andrew Cooper [this message]
2018-03-02 16:27 ` [PATCH v2 1/5] x86/entry: Correct comparisons against boolean variables Jan Beulich
2018-03-02 17:32 ` Wei Liu
2018-02-27 14:50 ` [PATCH v2 2/5] x86/pv: Drop int80_bounce from struct pv_vcpu Andrew Cooper
2018-02-27 14:50 ` [PATCH v2 3/5] x86/pv: Introduce pv_create_exception_frame() Andrew Cooper
2018-03-02 16:44 ` Jan Beulich
2018-02-27 14:50 ` [PATCH v2 4/5] x86/pv: Drop {compat_, }create_bounce_frame() and use the C version instead Andrew Cooper
2018-03-05 9:27 ` Jan Beulich
2018-09-07 14:17 ` Andrew Cooper
2018-09-07 15:49 ` Jan Beulich
2018-02-27 14:50 ` [PATCH v2 5/5] x86/pv: Implement the failsafe callback using the general path 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=1519743036-11600-2-git-send-email-andrew.cooper3@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=roger.pau@citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).