ANDROID: KVM: arm64: Gather the stage-2 invalid-pte definitions

These definitions need to be non-overlapping, which is clearer to
see if they are all defined together in the same place and with
the same name prefix.

Bug: 357781595
Change-Id: I6be1becf00ae35772fa738e9d5ce4084804fd09d
Signed-off-by: Keir Fraser <keirf@google.com>
This commit is contained in:
Keir Fraser
2024-02-15 15:01:28 +00:00
parent c63f9890b4
commit ef53e1835d
2 changed files with 20 additions and 7 deletions
+17
View File
@@ -259,6 +259,23 @@ enum kvm_pgtable_prot {
KVM_PGTABLE_PROT_SW3 = BIT(58),
};
/*
* Stage-2 invalid-PTE annotations. These are non-overlapping bitfields which
* define mutually-exclusive PTE states.
*/
/* (Host S2) The owner of the corresponding physical page. */
#define KVM_INVALID_PTE_OWNER_MASK GENMASK(9, 2)
/*
* Used to indicate a pte for which a 'break-before-make' sequence is in
* progress.
*/
#define KVM_INVALID_PTE_LOCKED BIT(10)
/* Indicates a valid MMIO mapping registered via ioguard. */
#define KVM_INVALID_PTE_MMIO_NOTE BIT(11)
#define KVM_PGTABLE_PROT_RW (KVM_PGTABLE_PROT_R | KVM_PGTABLE_PROT_W)
#define KVM_PGTABLE_PROT_RWX (KVM_PGTABLE_PROT_RW | KVM_PGTABLE_PROT_X)
+3 -7
View File
@@ -512,7 +512,6 @@ int host_stage2_idmap_locked(phys_addr_t addr, u64 size,
return host_stage2_try(__host_stage2_idmap, addr, addr + size, prot);
}
#define KVM_INVALID_PTE_OWNER_MASK GENMASK(9, 2)
#define KVM_MAX_OWNER_ID FIELD_MAX(KVM_INVALID_PTE_OWNER_MASK)
static kvm_pte_t kvm_init_invalid_leaf_owner(u8 owner_id)
@@ -1870,9 +1869,6 @@ unlock:
return ret;
}
/* Replace this with something more structured once day */
#define MMIO_NOTE (('M' << 24 | 'M' << 16 | 'I' << 8 | 'O') << 1)
static bool __check_ioguard_page(struct pkvm_hyp_vcpu *hyp_vcpu, u64 ipa)
{
struct pkvm_hyp_vm *vm = pkvm_hyp_vcpu_to_hyp_vm(hyp_vcpu);
@@ -1886,7 +1882,7 @@ static bool __check_ioguard_page(struct pkvm_hyp_vcpu *hyp_vcpu, u64 ipa)
/* Must be a PAGE_SIZE mapping with our annotation */
return (BIT(ARM64_HW_PGTABLE_LEVEL_SHIFT(level)) == PAGE_SIZE &&
pte == MMIO_NOTE);
pte == KVM_INVALID_PTE_MMIO_NOTE);
}
int __pkvm_install_ioguard_page(struct pkvm_hyp_vcpu *hyp_vcpu, u64 ipa)
@@ -1913,7 +1909,7 @@ int __pkvm_install_ioguard_page(struct pkvm_hyp_vcpu *hyp_vcpu, u64 ipa)
* Already flagged as MMIO, let's accept it, and fail
* otherwise
*/
if (pte != MMIO_NOTE)
if (pte != KVM_INVALID_PTE_MMIO_NOTE)
ret = -EBUSY;
goto unlock;
@@ -1921,7 +1917,7 @@ int __pkvm_install_ioguard_page(struct pkvm_hyp_vcpu *hyp_vcpu, u64 ipa)
ret = kvm_pgtable_stage2_annotate(&vm->pgt, ipa, PAGE_SIZE,
&hyp_vcpu->vcpu.arch.pkvm_memcache,
MMIO_NOTE);
KVM_INVALID_PTE_MMIO_NOTE);
unlock:
guest_unlock_component(vm);