KVM: arm64: Unify identifiers used to distinguish host and hypervisor
authorWill Deacon <will@kernel.org>
Thu, 10 Nov 2022 19:02:38 +0000 (19:02 +0000)
committerMarc Zyngier <maz@kernel.org>
Fri, 11 Nov 2022 16:40:54 +0000 (16:40 +0000)
The 'pkvm_component_id' enum type provides constants to refer to the
host and the hypervisor, yet this information is duplicated by the
'pkvm_hyp_id' constant.

Remove the definition of 'pkvm_hyp_id' and move the 'pkvm_component_id'
type definition to 'mem_protect.h' so that it can be used outside of
the memory protection code, for example when initialising the owner for
hypervisor-owned pages.

Reviewed-by: Oliver Upton <oliver.upton@linux.dev>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Vincent Donnefort <vdonnefort@google.com>
Signed-off-by: Will Deacon <will@kernel.org>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20221110190259.26861-6-will@kernel.org
arch/arm64/kvm/hyp/include/nvhe/mem_protect.h
arch/arm64/kvm/hyp/nvhe/mem_protect.c
arch/arm64/kvm/hyp/nvhe/setup.c

index 80e99836eac792427fd62e1c2a5be1b762ab5b26..f5705a1e972fffb3a315923b9f496dc104923398 100644 (file)
@@ -51,7 +51,11 @@ struct host_kvm {
 };
 extern struct host_kvm host_kvm;
 
-extern const u8 pkvm_hyp_id;
+/* This corresponds to page-table locking order */
+enum pkvm_component_id {
+       PKVM_ID_HOST,
+       PKVM_ID_HYP,
+};
 
 int __pkvm_prot_finalize(void);
 int __pkvm_host_share_hyp(u64 pfn);
index 1e78acf9662eb17490f2973ccd5a8831c876ee9b..ff86f5bd230f81d6c6029ed68e734d6ff5023335 100644 (file)
@@ -26,8 +26,6 @@ struct host_kvm host_kvm;
 
 static struct hyp_pool host_s2_pool;
 
-const u8 pkvm_hyp_id = 1;
-
 static void host_lock_component(void)
 {
        hyp_spin_lock(&host_kvm.lock);
@@ -380,12 +378,6 @@ void handle_host_mem_abort(struct kvm_cpu_context *host_ctxt)
        BUG_ON(ret && ret != -EAGAIN);
 }
 
-/* This corresponds to locking order */
-enum pkvm_component_id {
-       PKVM_ID_HOST,
-       PKVM_ID_HYP,
-};
-
 struct pkvm_mem_transition {
        u64                             nr_pages;
 
index 8f2726d7e20102b62d9811e261270371e7788814..0312c9c74a5a4c5478b5fdf57b2d38f049a791d2 100644 (file)
@@ -212,7 +212,7 @@ static int fix_host_ownership_walker(u64 addr, u64 end, u32 level,
        state = pkvm_getstate(kvm_pgtable_hyp_pte_prot(pte));
        switch (state) {
        case PKVM_PAGE_OWNED:
-               return host_stage2_set_owner_locked(phys, PAGE_SIZE, pkvm_hyp_id);
+               return host_stage2_set_owner_locked(phys, PAGE_SIZE, PKVM_ID_HYP);
        case PKVM_PAGE_SHARED_OWNED:
                prot = pkvm_mkstate(PKVM_HOST_MEM_PROT, PKVM_PAGE_SHARED_BORROWED);
                break;