KVM: x86/mmu: Add optimized helper to retrieve an SPTE's index
authorSean Christopherson <seanjc@google.com>
Tue, 12 Jul 2022 02:07:22 +0000 (02:07 +0000)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 14 Jul 2022 15:31:23 +0000 (11:31 -0400)
commit79e48cec6cba4eee0bd3a13f31320e33a1729931
tree6fbaf53d21b12bde36b5a011c3403c0a181e47b2
parentb184b35d06b2a3de65ff2ef4303f83535572266c
KVM: x86/mmu: Add optimized helper to retrieve an SPTE's index

Add spte_index() to dedup all the code that calculates a SPTE's index
into its parent's page table and/or spt array.  Opportunistically tweak
the calculation to avoid pointer arithmetic, which is subtle (subtract in
8-byte chunks) and less performant (requires the compiler to generate the
subtraction).

Suggested-by: David Matlack <dmatlack@google.com>
Reviewed-by: David Matlack <dmatlack@google.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20220712020724.1262121-2-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/mmu/mmu.c
arch/x86/kvm/mmu/paging_tmpl.h
arch/x86/kvm/mmu/spte.h