Skip to content

Commit a1a1f1f

Browse files
Quentin PerretMarc Zyngier
authored andcommitted
KVM: arm64: Change the layout of enum pkvm_page_state
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 <[email protected]> Reviewed-by: Fuad Tabba <[email protected]> Signed-off-by: Quentin Perret <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent 78d4f34 commit a1a1f1f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

arch/arm64/kvm/hyp/include/nvhe/mem_protect.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,27 @@
2424
*/
2525
enum pkvm_page_state {
2626
PKVM_PAGE_OWNED = 0ULL,
27-
PKVM_PAGE_SHARED_OWNED = KVM_PGTABLE_PROT_SW0,
28-
PKVM_PAGE_SHARED_BORROWED = KVM_PGTABLE_PROT_SW1,
29-
__PKVM_PAGE_RESERVED = KVM_PGTABLE_PROT_SW0 |
30-
KVM_PGTABLE_PROT_SW1,
27+
PKVM_PAGE_SHARED_OWNED = BIT(0),
28+
PKVM_PAGE_SHARED_BORROWED = BIT(1),
29+
__PKVM_PAGE_RESERVED = BIT(0) | BIT(1),
3130

3231
/* Meta-states which aren't encoded directly in the PTE's SW bits */
33-
PKVM_NOPAGE,
32+
PKVM_NOPAGE = BIT(2),
3433
};
34+
#define PKVM_PAGE_META_STATES_MASK (~__PKVM_PAGE_RESERVED)
3535

3636
#define PKVM_PAGE_STATE_PROT_MASK (KVM_PGTABLE_PROT_SW0 | KVM_PGTABLE_PROT_SW1)
3737
static inline enum kvm_pgtable_prot pkvm_mkstate(enum kvm_pgtable_prot prot,
3838
enum pkvm_page_state state)
3939
{
40-
return (prot & ~PKVM_PAGE_STATE_PROT_MASK) | state;
40+
prot &= ~PKVM_PAGE_STATE_PROT_MASK;
41+
prot |= FIELD_PREP(PKVM_PAGE_STATE_PROT_MASK, state);
42+
return prot;
4143
}
4244

4345
static inline enum pkvm_page_state pkvm_getstate(enum kvm_pgtable_prot prot)
4446
{
45-
return prot & PKVM_PAGE_STATE_PROT_MASK;
47+
return FIELD_GET(PKVM_PAGE_STATE_PROT_MASK, prot);
4648
}
4749

4850
struct host_mmu {

0 commit comments

Comments
 (0)