[PATCH v17 20/20] KVM: arm64: Abstract out memory abort handling
Suzuki K Poulose
suzuki.poulose at arm.com
Tue Sep 8 09:22:23 PDT 2026
Move the memory abort handling under VM specific s2 operation.
Signed-off-by: Suzuki K Poulose <suzuki.poulose at arm.com>
---
arch/arm64/include/asm/kvm_host.h | 2 ++
arch/arm64/kvm/mmu.c | 36 +++++++++++++++++++------------
2 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index e3c308b6e319f..fbfd85dc999ef 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -158,6 +158,7 @@ struct kvm_vcpu_ops {
};
struct kvm_gfn_range;
+struct kvm_s2_fault_desc;
struct kvm_vm_s2_ops {
bool (*vm_age_gfn)(struct kvm *kvm, struct kvm_gfn_range *range);
@@ -168,6 +169,7 @@ struct kvm_vm_s2_ops {
void (*vm_stage2_unmap_range)(struct kvm_s2_mmu *mmu,
phys_addr_t start, u64 size,
bool may_block);
+ int (*vm_mem_abort)(const struct kvm_s2_fault_desc *s2fd);
};
struct kvm_s2_mmu {
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index e78a56fb73696..5e7cdbe310fc8 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -1753,7 +1753,7 @@ struct kvm_s2_fault_vma_info {
bool map_non_cacheable;
};
-static int pkvm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
+static int protected_vm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
{
unsigned int flags = FOLL_HWPOISON | FOLL_LONGTERM | FOLL_WRITE;
struct kvm_vcpu *vcpu = s2fd->vcpu;
@@ -2191,6 +2191,22 @@ static int user_mem_abort(const struct kvm_s2_fault_desc *s2fd)
return kvm_s2_fault_map(s2fd, &s2vi, prot, memcache);
}
+static int kvm_vm_mem_abort(const struct kvm_s2_fault_desc *s2fd)
+{
+ int ret;
+ struct kvm_vcpu *vcpu = s2fd->vcpu;
+
+ VM_WARN_ON_ONCE(kvm_vcpu_trap_is_permission_fault(vcpu) &&
+ !kvm_is_write_fault(vcpu) &&
+ !kvm_vcpu_trap_is_exec_fault(vcpu));
+
+ if (kvm_slot_has_gmem(s2fd->memslot))
+ ret = gmem_abort(s2fd);
+ else
+ ret = user_mem_abort(s2fd);
+ return ret;
+}
+
/* Resolve the access fault by making the page young again. */
static void handle_access_fault(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa)
{
@@ -2298,6 +2314,7 @@ int kvm_handle_guest_sea(struct kvm_vcpu *vcpu)
int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)
{
struct kvm_s2_trans nested_trans, *nested = NULL;
+ struct kvm *kvm = vcpu->kvm;
unsigned long esr;
phys_addr_t fault_ipa; /* The address we faulted on */
phys_addr_t ipa; /* Always the IPA in the L1 guest phys space */
@@ -2459,19 +2476,7 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)
.hva = hva,
};
- if (kvm_vm_is_protected(vcpu->kvm)) {
- ret = pkvm_mem_abort(&s2fd);
- } else {
- VM_WARN_ON_ONCE(kvm_vcpu_trap_is_permission_fault(vcpu) &&
- !write_fault &&
- !kvm_vcpu_trap_is_exec_fault(vcpu));
-
- if (kvm_slot_has_gmem(memslot))
- ret = gmem_abort(&s2fd);
- else
- ret = user_mem_abort(&s2fd);
- }
-
+ ret = kvm->arch.vm_s2_ops->vm_mem_abort(&s2fd);
if (ret == 0)
ret = 1;
out:
@@ -2868,6 +2873,7 @@ static const struct kvm_vm_s2_ops protected_vm_s2_ops = {
* .vm_test_age_gfn
* .vm_stage2_unmap_range
*/
+ .vm_mem_abort = protected_vm_mem_abort,
};
static const struct kvm_vm_s2_ops pkvm_vm_s2_ops = {
@@ -2876,6 +2882,7 @@ static const struct kvm_vm_s2_ops pkvm_vm_s2_ops = {
.vm_age_gfn = kvm_vm_age_gfn,
.vm_test_age_gfn = kvm_vm_test_age_gfn,
.vm_stage2_unmap_range = kvm_vm_stage2_unmap_range,
+ .vm_mem_abort = kvm_vm_mem_abort,
};
static const struct kvm_vm_s2_ops kvm_default_vm_s2_ops = {
@@ -2884,4 +2891,5 @@ static const struct kvm_vm_s2_ops kvm_default_vm_s2_ops = {
.vm_age_gfn = kvm_vm_age_gfn,
.vm_test_age_gfn = kvm_vm_test_age_gfn,
.vm_stage2_unmap_range = kvm_vm_stage2_unmap_range,
+ .vm_mem_abort = kvm_vm_mem_abort,
};
--
2.43.0
More information about the linux-arm-kernel
mailing list