Move assignment close to use and combine all conditionals into one. Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx> --- x86/access.c | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/x86/access.c b/x86/access.c index 5a6d31c..7c8525d 100644 --- a/x86/access.c +++ b/x86/access.c @@ -338,17 +338,9 @@ void ac_test_reset_pt_pool(ac_pool_t *pool) void ac_emulate_access(ac_test_t *at, unsigned flags) { - int pde_valid, pte_valid; + bool pde_valid, pte_valid; bool user, writable, kwritable, executable; - pde_valid = F(AC_PDE_PRESENT) - && !F(AC_PDE_BIT51) && !F(AC_PDE_BIT13) - && !(F(AC_PDE_NX) && !F(AC_CPU_EFER_NX)); - pte_valid = pde_valid - && F(AC_PTE_PRESENT) - && !F(AC_PTE_BIT51) - && !(F(AC_PTE_NX) && !F(AC_CPU_EFER_NX)); - if (F(AC_ACCESS_USER)) at->expected_error |= PFERR_USER_MASK; @@ -358,19 +350,22 @@ void ac_emulate_access(ac_test_t *at, unsigned flags) if (F(AC_ACCESS_FETCH)) at->expected_error |= PFERR_FETCH_MASK; - if (!F(AC_PDE_PRESENT)) { - at->expected_fault = 1; - at->expected_error &= ~PFERR_PRESENT_MASK; - } else if (!pde_valid) { - at->expected_fault = 1; - at->expected_error |= PFERR_RESERVED_MASK; - } - if (!F(AC_PDE_ACCESSED)) at->ignore_pde = PT_ACCESSED_MASK; - if (!pde_valid) + pde_valid = F(AC_PDE_PRESENT) + && !F(AC_PDE_BIT51) && !F(AC_PDE_BIT13) + && !(F(AC_PDE_NX) && !F(AC_CPU_EFER_NX)); + + if (!pde_valid) { + at->expected_fault = 1; + if (F(AC_PDE_PRESENT)) { + at->expected_error |= PFERR_RESERVED_MASK; + } else { + at->expected_error &= ~PFERR_PRESENT_MASK; + } goto fault; + } kwritable = !F(AC_CPU_CR0_WP) && !F(AC_ACCESS_USER); writable = F(AC_PDE_WRITABLE); @@ -410,17 +405,20 @@ void ac_emulate_access(ac_test_t *at, unsigned flags) goto no_pte; } - if (!F(AC_PTE_PRESENT)) { - at->expected_fault = 1; - at->expected_error &= ~PFERR_PRESENT_MASK; - } else if (!pte_valid) { + pte_valid = F(AC_PTE_PRESENT) + && !F(AC_PTE_BIT51) + && !(F(AC_PTE_NX) && !F(AC_CPU_EFER_NX)); + + if (!pte_valid) { at->expected_fault = 1; - at->expected_error |= PFERR_RESERVED_MASK; + if (F(AC_PTE_PRESENT)) { + at->expected_error |= PFERR_RESERVED_MASK; + } else { + at->expected_error &= ~PFERR_PRESENT_MASK; + } + goto fault; } - if (!pte_valid) - goto fault; - writable &= F(AC_PTE_WRITABLE); user &= F(AC_PTE_USER); executable &= !F(AC_PTE_NX); -- 2.5.0 -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html