^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef __ASM_ALTERNATIVE_MACROS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define __ASM_ALTERNATIVE_MACROS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <asm/cpucaps.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define ARM64_CB_PATCH ARM64_NCAPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) /* A64 instructions are always 32 bits. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #define AARCH64_INSN_SIZE 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #ifndef BUILD_FIPS140_KO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #ifndef __ASSEMBLY__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/stringify.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define ALTINSTR_ENTRY(feature) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) " .word 661b - .\n" /* label */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) " .word 663f - .\n" /* new instruction */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) " .hword " __stringify(feature) "\n" /* feature bit */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) " .byte 662b-661b\n" /* source len */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) " .byte 664f-663f\n" /* replacement len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define ALTINSTR_ENTRY_CB(feature, cb) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) " .word 661b - .\n" /* label */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) " .word " __stringify(cb) "- .\n" /* callback */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) " .hword " __stringify(feature) "\n" /* feature bit */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) " .byte 662b-661b\n" /* source len */ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) " .byte 664f-663f\n" /* replacement len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * alternative assembly primitive:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * If any of these .org directive fail, it means that insn1 and insn2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * don't have the same length. This used to be written as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * .if ((664b-663b) != (662b-661b))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * .error "Alternatives instruction length mismatch"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * but most assemblers die if insn1 or insn2 have a .inst. This should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * be fixed in a binutils release posterior to 2.25.51.0.2 (anything
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * containing commit 4e4d08cf7399b606 or c1baaddf8861).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * Alternatives with callbacks do not generate replacement instructions.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define __ALTERNATIVE_CFG(oldinstr, newinstr, feature, cfg_enabled) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) ".if "__stringify(cfg_enabled)" == 1\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) "661:\n\t" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) oldinstr "\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) "662:\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) ".pushsection .altinstructions,\"a\"\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) ALTINSTR_ENTRY(feature) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) ".popsection\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) ".subsection 1\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) "663:\n\t" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) newinstr "\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) "664:\n\t" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) ".org . - (664b-663b) + (662b-661b)\n\t" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) ".org . - (662b-661b) + (664b-663b)\n\t" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) ".previous\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ".endif\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define __ALTERNATIVE_CFG_CB(oldinstr, feature, cfg_enabled, cb) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ".if "__stringify(cfg_enabled)" == 1\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) "661:\n\t" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) oldinstr "\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) "662:\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) ".pushsection .altinstructions,\"a\"\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) ALTINSTR_ENTRY_CB(feature, cb) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) ".popsection\n" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) "663:\n\t" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) "664:\n\t" \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ".endif\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) #define _ALTERNATIVE_CFG(oldinstr, newinstr, feature, cfg, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) __ALTERNATIVE_CFG(oldinstr, newinstr, feature, IS_ENABLED(cfg))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define ALTERNATIVE_CB(oldinstr, cb) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) __ALTERNATIVE_CFG_CB(oldinstr, ARM64_CB_PATCH, 1, cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) #include <asm/assembler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) .macro altinstruction_entry orig_offset alt_offset feature orig_len alt_len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .word \orig_offset - .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) .word \alt_offset - .
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) .hword \feature
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) .byte \orig_len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) .byte \alt_len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) .macro alternative_insn insn1, insn2, cap, enable = 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) .if \enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) 661: \insn1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) 662: .pushsection .altinstructions, "a"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) altinstruction_entry 661b, 663f, \cap, 662b-661b, 664f-663f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .popsection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .subsection 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 663: \insn2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 664: .org . - (664b-663b) + (662b-661b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .org . - (662b-661b) + (664b-663b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .previous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * Alternative sequences
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * The code for the case where the capability is not present will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * assembled and linked as normal. There are no restrictions on this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * The code for the case where the capability is present will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * assembled into a special section to be used for dynamic patching.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * Code for that case must:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * 1. Be exactly the same length (in bytes) as the default code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * 2. Not contain a branch target that is used outside of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * alternative sequence it is defined in (branches into an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * alternative sequence are not fixed up).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * Begin an alternative code sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) .macro alternative_if_not cap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) .set .Lasm_alt_mode, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) .pushsection .altinstructions, "a"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) altinstruction_entry 661f, 663f, \cap, 662f-661f, 664f-663f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .popsection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 661:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) .macro alternative_if cap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) .set .Lasm_alt_mode, 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .pushsection .altinstructions, "a"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) altinstruction_entry 663f, 661f, \cap, 664f-663f, 662f-661f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .popsection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .subsection 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) .align 2 /* So GAS knows label 661 is suitably aligned */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 661:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) .macro alternative_cb cb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) .set .Lasm_alt_mode, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) .pushsection .altinstructions, "a"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) altinstruction_entry 661f, \cb, ARM64_CB_PATCH, 662f-661f, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) .popsection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 661:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * Provide the other half of the alternative code sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) .macro alternative_else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 662:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) .if .Lasm_alt_mode==0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) .subsection 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) .else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) .previous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 663:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) * Complete an alternative code sequence.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) .macro alternative_endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 664:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) .org . - (664b-663b) + (662b-661b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) .org . - (662b-661b) + (664b-663b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) .if .Lasm_alt_mode==0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) .previous
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) .endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * Callback-based alternative epilogue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) .macro alternative_cb_end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 662:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * Provides a trivial alternative or default sequence consisting solely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * of NOPs. The number of NOPs is chosen automatically to match the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * previous case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) .macro alternative_else_nop_endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) alternative_else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) nops (662b-661b) / AARCH64_INSN_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) alternative_endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) #define _ALTERNATIVE_CFG(insn1, insn2, cap, cfg, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) alternative_insn insn1, insn2, cap, IS_ENABLED(cfg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) .macro user_alt, label, oldinstr, newinstr, cond
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 9999: alternative_insn "\oldinstr", "\newinstr", \cond
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) _asm_extable 9999b, \label
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) #endif /* __ASSEMBLY__ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * Usage: asm(ALTERNATIVE(oldinstr, newinstr, feature));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) * Usage: asm(ALTERNATIVE(oldinstr, newinstr, feature, CONFIG_FOO));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) * N.B. If CONFIG_FOO is specified, but not selected, the whole block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * will be omitted, including oldinstr.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) #define ALTERNATIVE(oldinstr, newinstr, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) _ALTERNATIVE_CFG(oldinstr, newinstr, __VA_ARGS__, 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * The FIPS140 module does not support alternatives patching, as this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * invalidates the HMAC digest of the .text section. However, some alternatives
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * are known to be irrelevant so we can tolerate them in the FIPS140 module, as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * they will never be applied in the first place in the use cases that the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * FIPS140 module targets (Android running on a production phone). Any other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * uses of alternatives should be avoided, as it is not safe in the general
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * case to simply use the default sequence in one place (the fips module) and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) * the alternative sequence everywhere else.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) * Below is an allowlist of features that we can ignore, by simply taking the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) * safe default instruction sequence. Note that this implies that the FIPS140
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * module is not compatible with VHE, or with pseudo-NMI support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) #define __ALT_ARM64_HAS_LDAPR 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) #define __ALT_ARM64_HAS_VIRT_HOST_EXTN 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) #define __ALT_ARM64_HAS_IRQ_PRIO_MASKING 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) #define ALTERNATIVE(oldinstr, newinstr, feature, ...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) _ALTERNATIVE(oldinstr, __ALT_ ## feature, #feature)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #define _ALTERNATIVE(oldinstr, feature, feature_str) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) __take_second_arg(feature oldinstr, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) ".err Feature " feature_str " not supported in fips140 module")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #endif /* BUILD_FIPS140_KO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #endif /* __ASM_ALTERNATIVE_MACROS_H */