]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
KVM: arm64: Change the layout of enum pkvm_page_state
authorQuentin Perret <qperret@google.com>
Wed, 18 Dec 2024 19:40:42 +0000 (19:40 +0000)
committerMarc Zyngier <maz@kernel.org>
Fri, 20 Dec 2024 09:43:59 +0000 (09:43 +0000)
The 'concrete' (a.k.a non-meta) page states are currently encoded using
software bits in PTEs. For performance reasons, the abstract
pkvm_page_state enum uses the same bits to encode these states as that
makes conversions from and to PTEs easy.

In order to prepare the ground for moving the 'concrete' state storage
to the hyp vmemmap, re-arrange the enum to use bits 0 and 1 for this
purpose.

No functional changes intended.

Tested-by: Fuad Tabba <tabba@google.com>
Reviewed-by: Fuad Tabba <tabba@google.com>
Signed-off-by: Quentin Perret <qperret@google.com>
Link: https://lore.kernel.org/r/20241218194059.3670226-2-qperret@google.com
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/hyp/include/nvhe/mem_protect.h

index 0972faccc2af0764d00deff099662738c6e5a1e4..5462faf6bfeebb17e4ba0c53edb6755df0b96647 100644 (file)
  */
 enum pkvm_page_state {
        PKVM_PAGE_OWNED                 = 0ULL,
-       PKVM_PAGE_SHARED_OWNED          = KVM_PGTABLE_PROT_SW0,
-       PKVM_PAGE_SHARED_BORROWED       = KVM_PGTABLE_PROT_SW1,
-       __PKVM_PAGE_RESERVED            = KVM_PGTABLE_PROT_SW0 |
-                                         KVM_PGTABLE_PROT_SW1,
+       PKVM_PAGE_SHARED_OWNED          = BIT(0),
+       PKVM_PAGE_SHARED_BORROWED       = BIT(1),
+       __PKVM_PAGE_RESERVED            = BIT(0) | BIT(1),
 
        /* Meta-states which aren't encoded directly in the PTE's SW bits */
-       PKVM_NOPAGE,
+       PKVM_NOPAGE                     = BIT(2),
 };
+#define PKVM_PAGE_META_STATES_MASK     (~__PKVM_PAGE_RESERVED)
 
 #define PKVM_PAGE_STATE_PROT_MASK      (KVM_PGTABLE_PROT_SW0 | KVM_PGTABLE_PROT_SW1)
 static inline enum kvm_pgtable_prot pkvm_mkstate(enum kvm_pgtable_prot prot,
                                                 enum pkvm_page_state state)
 {
-       return (prot & ~PKVM_PAGE_STATE_PROT_MASK) | state;
+       prot &= ~PKVM_PAGE_STATE_PROT_MASK;
+       prot |= FIELD_PREP(PKVM_PAGE_STATE_PROT_MASK, state);
+       return prot;
 }
 
 static inline enum pkvm_page_state pkvm_getstate(enum kvm_pgtable_prot prot)
 {
-       return prot & PKVM_PAGE_STATE_PROT_MASK;
+       return FIELD_GET(PKVM_PAGE_STATE_PROT_MASK, prot);
 }
 
 struct host_mmu {