|
12 | 12 | #include <asm/kvm_hyp.h> |
13 | 13 | #include <asm/kvm_mmu.h> |
14 | 14 |
|
| 15 | +static inline bool __fault_safe_to_translate(u64 esr) |
| 16 | +{ |
| 17 | + u64 fsc = esr & ESR_ELx_FSC; |
| 18 | + |
| 19 | + if (esr_fsc_is_sea_ttw(esr) || esr_fsc_is_secc_ttw(esr)) |
| 20 | + return false; |
| 21 | + |
| 22 | + return !(fsc == ESR_ELx_FSC_EXTABT && (esr & ESR_ELx_FnV)); |
| 23 | +} |
| 24 | + |
15 | 25 | static inline bool __translate_far_to_hpfar(u64 far, u64 *hpfar) |
16 | 26 | { |
17 | 27 | int ret; |
@@ -44,34 +54,50 @@ static inline bool __translate_far_to_hpfar(u64 far, u64 *hpfar) |
44 | 54 | return true; |
45 | 55 | } |
46 | 56 |
|
47 | | -static inline bool __get_fault_info(u64 esr, struct kvm_vcpu_fault_info *fault) |
| 57 | +/* |
| 58 | + * Checks for the conditions when HPFAR_EL2 is written, per ARM ARM R_FKLWR. |
| 59 | + */ |
| 60 | +static inline bool __hpfar_valid(u64 esr) |
48 | 61 | { |
49 | | - u64 hpfar, far; |
50 | | - |
51 | | - far = read_sysreg_el2(SYS_FAR); |
52 | | - |
53 | 62 | /* |
54 | | - * The HPFAR can be invalid if the stage 2 fault did not |
55 | | - * happen during a stage 1 page table walk (the ESR_EL2.S1PTW |
56 | | - * bit is clear) and one of the two following cases are true: |
57 | | - * 1. The fault was due to a permission fault |
58 | | - * 2. The processor carries errata 834220 |
| 63 | + * CPUs affected by ARM erratum #834220 may incorrectly report a |
| 64 | + * stage-2 translation fault when a stage-1 permission fault occurs. |
59 | 65 | * |
60 | | - * Therefore, for all non S1PTW faults where we either have a |
61 | | - * permission fault or the errata workaround is enabled, we |
62 | | - * resolve the IPA using the AT instruction. |
| 66 | + * Re-walk the page tables to determine if a stage-1 fault actually |
| 67 | + * occurred. |
63 | 68 | */ |
64 | | - if (!(esr & ESR_ELx_S1PTW) && |
65 | | - (cpus_have_final_cap(ARM64_WORKAROUND_834220) || |
66 | | - esr_fsc_is_permission_fault(esr))) { |
67 | | - if (!__translate_far_to_hpfar(far, &hpfar)) |
68 | | - return false; |
69 | | - } else { |
| 69 | + if (cpus_have_final_cap(ARM64_WORKAROUND_834220) && |
| 70 | + esr_fsc_is_translation_fault(esr)) |
| 71 | + return false; |
| 72 | + |
| 73 | + if (esr_fsc_is_translation_fault(esr) || esr_fsc_is_access_flag_fault(esr)) |
| 74 | + return true; |
| 75 | + |
| 76 | + if ((esr & ESR_ELx_S1PTW) && esr_fsc_is_permission_fault(esr)) |
| 77 | + return true; |
| 78 | + |
| 79 | + return esr_fsc_is_addr_sz_fault(esr); |
| 80 | +} |
| 81 | + |
| 82 | +static inline bool __get_fault_info(u64 esr, struct kvm_vcpu_fault_info *fault) |
| 83 | +{ |
| 84 | + u64 hpfar; |
| 85 | + |
| 86 | + fault->far_el2 = read_sysreg_el2(SYS_FAR); |
| 87 | + fault->hpfar_el2 = 0; |
| 88 | + |
| 89 | + if (__hpfar_valid(esr)) |
70 | 90 | hpfar = read_sysreg(hpfar_el2); |
71 | | - } |
| 91 | + else if (unlikely(!__fault_safe_to_translate(esr))) |
| 92 | + return true; |
| 93 | + else if (!__translate_far_to_hpfar(fault->far_el2, &hpfar)) |
| 94 | + return false; |
72 | 95 |
|
73 | | - fault->far_el2 = far; |
74 | | - fault->hpfar_el2 = hpfar; |
| 96 | + /* |
| 97 | + * Hijack HPFAR_EL2.NS (RES0 in Non-secure) to indicate a valid |
| 98 | + * HPFAR value. |
| 99 | + */ |
| 100 | + fault->hpfar_el2 = hpfar | HPFAR_EL2_NS; |
75 | 101 | return true; |
76 | 102 | } |
77 | 103 |
|
|
0 commit comments