Message ID | 20241216175803.2716565-3-qperret@google.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | KVM: arm64: Non-protected guest stage-2 support for pKVM | expand |
On Mon, 16 Dec 2024 at 17:58, Quentin Perret <qperret@google.com> wrote: > > In order to prepare the way for storing page-tracking information in > pKVM's vmemmap, move the enum pkvm_page_state definition to > nvhe/memory.h. > > No functional changes intended. > > Signed-off-by: Quentin Perret <qperret@google.com> Reviewed-by: Fuad Tabba <tabba@google.com> Cheers, /fuad > --- > arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 34 +------------------ > arch/arm64/kvm/hyp/include/nvhe/memory.h | 33 ++++++++++++++++++ > 2 files changed, 34 insertions(+), 33 deletions(-) > > diff --git a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h > index 8c30362af2b9..25038ac705d8 100644 > --- a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h > +++ b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h > @@ -11,42 +11,10 @@ > #include <asm/kvm_mmu.h> > #include <asm/kvm_pgtable.h> > #include <asm/virt.h> > +#include <nvhe/memory.h> > #include <nvhe/pkvm.h> > #include <nvhe/spinlock.h> > > -/* > - * SW bits 0-1 are reserved to track the memory ownership state of each page: > - * 00: The page is owned exclusively by the page-table owner. > - * 01: The page is owned by the page-table owner, but is shared > - * with another entity. > - * 10: The page is shared with, but not owned by the page-table owner. > - * 11: Reserved for future use (lending). > - */ > -enum pkvm_page_state { > - PKVM_PAGE_OWNED = 0ULL, > - 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 = BIT(2), > -}; > -#define PKVM_PAGE_META_STATES_MASK (~(BIT(0) | BIT(1))) > - > -#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) > -{ > - 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 FIELD_GET(PKVM_PAGE_STATE_PROT_MASK, prot); > -} > - > struct host_mmu { > struct kvm_arch arch; > struct kvm_pgtable pgt; > diff --git a/arch/arm64/kvm/hyp/include/nvhe/memory.h b/arch/arm64/kvm/hyp/include/nvhe/memory.h > index ab205c4d6774..c84b24234ac7 100644 > --- a/arch/arm64/kvm/hyp/include/nvhe/memory.h > +++ b/arch/arm64/kvm/hyp/include/nvhe/memory.h > @@ -7,6 +7,39 @@ > > #include <linux/types.h> > > +/* > + * SW bits 0-1 are reserved to track the memory ownership state of each page: > + * 00: The page is owned exclusively by the page-table owner. > + * 01: The page is owned by the page-table owner, but is shared > + * with another entity. > + * 10: The page is shared with, but not owned by the page-table owner. > + * 11: Reserved for future use (lending). > + */ > +enum pkvm_page_state { > + PKVM_PAGE_OWNED = 0ULL, > + 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 = BIT(2), > +}; > +#define PKVM_PAGE_META_STATES_MASK (~(BIT(0) | BIT(1))) > + > +#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) > +{ > + 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 FIELD_GET(PKVM_PAGE_STATE_PROT_MASK, prot); > +} > + > struct hyp_page { > unsigned short refcount; > unsigned short order; > -- > 2.47.1.613.gc27f4b7a9f-goog >
diff --git a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h index 8c30362af2b9..25038ac705d8 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h +++ b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h @@ -11,42 +11,10 @@ #include <asm/kvm_mmu.h> #include <asm/kvm_pgtable.h> #include <asm/virt.h> +#include <nvhe/memory.h> #include <nvhe/pkvm.h> #include <nvhe/spinlock.h> -/* - * SW bits 0-1 are reserved to track the memory ownership state of each page: - * 00: The page is owned exclusively by the page-table owner. - * 01: The page is owned by the page-table owner, but is shared - * with another entity. - * 10: The page is shared with, but not owned by the page-table owner. - * 11: Reserved for future use (lending). - */ -enum pkvm_page_state { - PKVM_PAGE_OWNED = 0ULL, - 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 = BIT(2), -}; -#define PKVM_PAGE_META_STATES_MASK (~(BIT(0) | BIT(1))) - -#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) -{ - 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 FIELD_GET(PKVM_PAGE_STATE_PROT_MASK, prot); -} - struct host_mmu { struct kvm_arch arch; struct kvm_pgtable pgt; diff --git a/arch/arm64/kvm/hyp/include/nvhe/memory.h b/arch/arm64/kvm/hyp/include/nvhe/memory.h index ab205c4d6774..c84b24234ac7 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/memory.h +++ b/arch/arm64/kvm/hyp/include/nvhe/memory.h @@ -7,6 +7,39 @@ #include <linux/types.h> +/* + * SW bits 0-1 are reserved to track the memory ownership state of each page: + * 00: The page is owned exclusively by the page-table owner. + * 01: The page is owned by the page-table owner, but is shared + * with another entity. + * 10: The page is shared with, but not owned by the page-table owner. + * 11: Reserved for future use (lending). + */ +enum pkvm_page_state { + PKVM_PAGE_OWNED = 0ULL, + 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 = BIT(2), +}; +#define PKVM_PAGE_META_STATES_MASK (~(BIT(0) | BIT(1))) + +#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) +{ + 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 FIELD_GET(PKVM_PAGE_STATE_PROT_MASK, prot); +} + struct hyp_page { unsigned short refcount; unsigned short order;
In order to prepare the way for storing page-tracking information in pKVM's vmemmap, move the enum pkvm_page_state definition to nvhe/memory.h. No functional changes intended. Signed-off-by: Quentin Perret <qperret@google.com> --- arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 34 +------------------ arch/arm64/kvm/hyp/include/nvhe/memory.h | 33 ++++++++++++++++++ 2 files changed, 34 insertions(+), 33 deletions(-)