mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
KVM: arm64: Use kvm_s2_fault_vma_info in pkvm_mem_abort()
To paraphrase Marc in commit08f97454b7("KVM: arm64: Fix protected mode handling of pages larger than 4kB"), pkvm_pgtable_stage2_map() assumes the address passed as a parameter is aligned to the size of the intended mapping, while HPFAR_EL2 gives the IPA minus the bottom 12 bits, regardless of the system page size configuration. To fix this alignment, bring support for kvm_s2_fault_vma_info in pkvm_mem_abort() and use its members where possible. They do contain the page-alignment we need to fix the fault on system with pages larger than 4K. Also, add a check at the start of pkvm_pgtable_stage2_map(), it does not support !PAGE_ALIGNED arguments. Fixes:ea03466e80("KVM: arm64: Handle aborts from protected VMs") Cc: stable@vger.kernel.org Signed-off-by: Vincent Donnefort <vdonnefort@google.com> Reviewed-by: Fuad Tabba <fuad.tabba@linux.dev> Tested-by: Fuad Tabba <fuad.tabba@linux.dev> Link: https://patch.msgid.link/20260928095454.3255918-5-vdonnefort@google.com Signed-off-by: Marc Zyngier <maz@kernel.org>
This commit is contained in:
parent
80b0b86dc5
commit
0cdcc10392
|
|
@ -1374,9 +1374,11 @@ static bool fault_supports_stage2_huge_mapping(const struct kvm_s2_fault_desc *s
|
|||
if (map_size == PAGE_SIZE)
|
||||
return true;
|
||||
|
||||
/* pKVM only supports PMD_SIZE huge-mappings */
|
||||
if (is_protected_kvm_enabled() && map_size != PMD_SIZE)
|
||||
return false;
|
||||
/* pKVM only supports PMD_SIZE huge-mappings for non-protected VMs */
|
||||
if (is_protected_kvm_enabled()) {
|
||||
if (vcpu_is_protected(s2fd->vcpu) || map_size != PMD_SIZE)
|
||||
return false;
|
||||
}
|
||||
|
||||
size = memslot->npages * PAGE_SIZE;
|
||||
|
||||
|
|
@ -1621,6 +1623,9 @@ struct kvm_s2_fault_vma_info {
|
|||
bool map_non_cacheable;
|
||||
};
|
||||
|
||||
static int kvm_s2_fault_get_vma_info(const struct kvm_s2_fault_desc *s2fd,
|
||||
struct kvm_s2_fault_vma_info *s2vi);
|
||||
|
||||
static gfn_t get_canonical_gfn(const struct kvm_s2_fault_desc *s2fd,
|
||||
const struct kvm_s2_fault_vma_info *s2vi);
|
||||
|
||||
|
|
@ -1710,12 +1715,12 @@ static int gmem_abort(const struct kvm_s2_fault_desc *s2fd)
|
|||
static int pkvm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
|
||||
{
|
||||
unsigned int flags = FOLL_HWPOISON | FOLL_LONGTERM | FOLL_WRITE;
|
||||
struct kvm_s2_fault_vma_info s2vi = {};
|
||||
struct kvm_vcpu *vcpu = s2fd->vcpu;
|
||||
struct kvm_pgtable *pgt = vcpu->arch.hw_mmu->pgt;
|
||||
struct mm_struct *mm = current->mm;
|
||||
struct kvm *kvm = vcpu->kvm;
|
||||
void *hyp_memcache;
|
||||
struct page *page;
|
||||
int ret;
|
||||
|
||||
hyp_memcache = get_mmu_memcache(vcpu);
|
||||
|
|
@ -1723,12 +1728,16 @@ static int pkvm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
|
|||
if (ret)
|
||||
return -ENOMEM;
|
||||
|
||||
ret = kvm_s2_fault_get_vma_info(s2fd, &s2vi);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = account_locked_vm(mm, 1, true);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
mmap_read_lock(mm);
|
||||
ret = pin_user_pages(s2fd->hva, 1, flags, &page);
|
||||
ret = pin_user_pages(s2fd->hva, 1, flags, &s2vi.page);
|
||||
mmap_read_unlock(mm);
|
||||
|
||||
if (ret == -EHWPOISON) {
|
||||
|
|
@ -1738,7 +1747,7 @@ static int pkvm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
|
|||
} else if (ret != 1) {
|
||||
ret = -EFAULT;
|
||||
goto dec_account;
|
||||
} else if (!folio_test_swapbacked(page_folio(page))) {
|
||||
} else if (!folio_test_swapbacked(page_folio(s2vi.page))) {
|
||||
/*
|
||||
* We really can't deal with page-cache pages returned by GUP
|
||||
* because (a) we may trigger writeback of a page for which we
|
||||
|
|
@ -1758,8 +1767,8 @@ static int pkvm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
|
|||
}
|
||||
|
||||
write_lock(&kvm->mmu_lock);
|
||||
ret = pkvm_pgtable_stage2_map(pgt, s2fd->fault_ipa, PAGE_SIZE,
|
||||
page_to_phys(page), KVM_PGTABLE_PROT_RWX,
|
||||
ret = pkvm_pgtable_stage2_map(pgt, gfn_to_gpa(s2vi.gfn), PAGE_SIZE,
|
||||
page_to_phys(s2vi.page), KVM_PGTABLE_PROT_RWX,
|
||||
hyp_memcache, 0);
|
||||
write_unlock(&kvm->mmu_lock);
|
||||
if (ret) {
|
||||
|
|
@ -1770,7 +1779,7 @@ static int pkvm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
|
|||
|
||||
return 0;
|
||||
unpin:
|
||||
unpin_user_pages(&page, 1);
|
||||
unpin_user_page(s2vi.page);
|
||||
dec_account:
|
||||
account_locked_vm(mm, 1, false);
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -414,6 +414,9 @@ int pkvm_pgtable_stage2_map(struct kvm_pgtable *pgt, u64 addr, u64 size,
|
|||
u64 end = addr + size;
|
||||
int ret;
|
||||
|
||||
if (WARN_ON_ONCE(!PAGE_ALIGNED(addr | size)))
|
||||
return -EINVAL;
|
||||
|
||||
lockdep_assert_held_write(&kvm->mmu_lock);
|
||||
mapping = pkvm_mapping_iter_first(&pgt->pkvm_mappings, addr, end - 1);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user