]> xenbits.xensource.com Git - people/dariof/xen.git/commitdiff
x86/entry: Correct comparisons against boolean variables
authorAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 21 Feb 2018 13:00:23 +0000 (13:00 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 5 Mar 2018 17:36:31 +0000 (17:36 +0000)
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>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
xen/arch/x86/x86_64/compat/entry.S
xen/arch/x86/x86_64/entry.S

index 458d8108d45957f54eff230376b5f5315de78fc8..3e8b6c104cbabc4df65e321544dffef10e7a4892 100644 (file)
@@ -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
index 941f06feed73d3daefeee5c192b0c913f98ad3e0..6249efefe0674f57887545c138352ae72489fb15 100644 (file)
@@ -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: