@@ -1376,7 +1376,7 @@ static bool kvm_vma_mte_allowed(struct vm_area_struct *vma)
13761376
13771377static int user_mem_abort (struct kvm_vcpu * vcpu , phys_addr_t fault_ipa ,
13781378 struct kvm_memory_slot * memslot , unsigned long hva ,
1379- unsigned long fault_status )
1379+ bool fault_is_perm )
13801380{
13811381 int ret = 0 ;
13821382 bool write_fault , writable , force_pte = false;
@@ -1390,17 +1390,17 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
13901390 gfn_t gfn ;
13911391 kvm_pfn_t pfn ;
13921392 bool logging_active = memslot_is_logging (memslot );
1393- s8 fault_level = kvm_vcpu_trap_get_fault_level (vcpu );
13941393 long vma_pagesize , fault_granule ;
13951394 enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_R ;
13961395 struct kvm_pgtable * pgt ;
13971396
1398- fault_granule = 1UL << ARM64_HW_PGTABLE_LEVEL_SHIFT (fault_level );
1397+ if (fault_is_perm )
1398+ fault_granule = kvm_vcpu_trap_get_perm_fault_granule (vcpu );
13991399 write_fault = kvm_is_write_fault (vcpu );
14001400 exec_fault = kvm_vcpu_trap_is_exec_fault (vcpu );
14011401 VM_BUG_ON (write_fault && exec_fault );
14021402
1403- if (fault_status == ESR_ELx_FSC_PERM && !write_fault && !exec_fault ) {
1403+ if (fault_is_perm && !write_fault && !exec_fault ) {
14041404 kvm_err ("Unexpected L2 read permission error\n" );
14051405 return - EFAULT ;
14061406 }
@@ -1411,8 +1411,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
14111411 * only exception to this is when dirty logging is enabled at runtime
14121412 * and a write fault needs to collapse a block entry into a table.
14131413 */
1414- if (fault_status != ESR_ELx_FSC_PERM ||
1415- (logging_active && write_fault )) {
1414+ if (!fault_is_perm || (logging_active && write_fault )) {
14161415 ret = kvm_mmu_topup_memory_cache (memcache ,
14171416 kvm_mmu_cache_min_pages (vcpu -> arch .hw_mmu ));
14181417 if (ret )
@@ -1529,8 +1528,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
15291528 * backed by a THP and thus use block mapping if possible.
15301529 */
15311530 if (vma_pagesize == PAGE_SIZE && !(force_pte || device )) {
1532- if (fault_status == ESR_ELx_FSC_PERM &&
1533- fault_granule > PAGE_SIZE )
1531+ if (fault_is_perm && fault_granule > PAGE_SIZE )
15341532 vma_pagesize = fault_granule ;
15351533 else
15361534 vma_pagesize = transparent_hugepage_adjust (kvm , memslot ,
@@ -1543,7 +1541,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
15431541 }
15441542 }
15451543
1546- if (fault_status != ESR_ELx_FSC_PERM && !device && kvm_has_mte (kvm )) {
1544+ if (! fault_is_perm && !device && kvm_has_mte (kvm )) {
15471545 /* Check the VMM hasn't introduced a new disallowed VMA */
15481546 if (mte_allowed ) {
15491547 sanitise_mte_tags (kvm , pfn , vma_pagesize );
@@ -1569,7 +1567,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
15691567 * permissions only if vma_pagesize equals fault_granule. Otherwise,
15701568 * kvm_pgtable_stage2_map() should be called to change block size.
15711569 */
1572- if (fault_status == ESR_ELx_FSC_PERM && vma_pagesize == fault_granule )
1570+ if (fault_is_perm && vma_pagesize == fault_granule )
15731571 ret = kvm_pgtable_stage2_relax_perms (pgt , fault_ipa , prot );
15741572 else
15751573 ret = kvm_pgtable_stage2_map (pgt , fault_ipa , vma_pagesize ,
@@ -1620,20 +1618,20 @@ static void handle_access_fault(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa)
16201618 */
16211619int kvm_handle_guest_abort (struct kvm_vcpu * vcpu )
16221620{
1623- unsigned long fault_status ;
1621+ unsigned long esr ;
16241622 phys_addr_t fault_ipa ;
16251623 struct kvm_memory_slot * memslot ;
16261624 unsigned long hva ;
16271625 bool is_iabt , write_fault , writable ;
16281626 gfn_t gfn ;
16291627 int ret , idx ;
16301628
1631- fault_status = kvm_vcpu_trap_get_fault_type (vcpu );
1629+ esr = kvm_vcpu_get_esr (vcpu );
16321630
16331631 fault_ipa = kvm_vcpu_get_fault_ipa (vcpu );
16341632 is_iabt = kvm_vcpu_trap_is_iabt (vcpu );
16351633
1636- if (fault_status == ESR_ELx_FSC_FAULT ) {
1634+ if (esr_fsc_is_permission_fault ( esr ) ) {
16371635 /* Beyond sanitised PARange (which is the IPA limit) */
16381636 if (fault_ipa >= BIT_ULL (get_kvm_ipa_limit ())) {
16391637 kvm_inject_size_fault (vcpu );
@@ -1668,9 +1666,9 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)
16681666 kvm_vcpu_get_hfar (vcpu ), fault_ipa );
16691667
16701668 /* Check the stage-2 fault is trans. fault or write fault */
1671- if (fault_status != ESR_ELx_FSC_FAULT &&
1672- fault_status != ESR_ELx_FSC_PERM &&
1673- fault_status != ESR_ELx_FSC_ACCESS ) {
1669+ if (! esr_fsc_is_translation_fault ( esr ) &&
1670+ ! esr_fsc_is_permission_fault ( esr ) &&
1671+ ! esr_fsc_is_access_flag_fault ( esr ) ) {
16741672 kvm_err ("Unsupported FSC: EC=%#x xFSC=%#lx ESR_EL2=%#lx\n" ,
16751673 kvm_vcpu_trap_get_class (vcpu ),
16761674 (unsigned long )kvm_vcpu_trap_get_fault (vcpu ),
@@ -1732,13 +1730,14 @@ int kvm_handle_guest_abort(struct kvm_vcpu *vcpu)
17321730 /* Userspace should not be able to register out-of-bounds IPAs */
17331731 VM_BUG_ON (fault_ipa >= kvm_phys_size (vcpu -> arch .hw_mmu ));
17341732
1735- if (fault_status == ESR_ELx_FSC_ACCESS ) {
1733+ if (esr_fsc_is_access_flag_fault ( esr ) ) {
17361734 handle_access_fault (vcpu , fault_ipa );
17371735 ret = 1 ;
17381736 goto out_unlock ;
17391737 }
17401738
1741- ret = user_mem_abort (vcpu , fault_ipa , memslot , hva , fault_status );
1739+ ret = user_mem_abort (vcpu , fault_ipa , memslot , hva ,
1740+ esr_fsc_is_permission_fault (esr ));
17421741 if (ret == 0 )
17431742 ret = 1 ;
17441743out :
0 commit comments