arm64: Make NOP handling a whitelist
cover arm64: Make NOP handling a whitelist
Currently we default to assuming any unrecognized instruction in the hint space can be safely handled as a NOP. This is not robust and any code that really wants a NOP should be using the explicitly defined NOP so let's instead invert this and whitelist those instructions which it is safe to handle as NOPs.
Mark Brown (3):
arm64: insn: Don't assume unrecognized HINTs are NOPs
arm64: insn: Add constants for PAC and BTI instruction decode
arm64: insn: Report PAC and BTI instructions as NOPs
arch/arm64/include/asm/insn.h | 22 ++++++++++++++++++++-- arch/arm64/kernel/insn.c | 32 ++++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 10 deletions(-)
base-commit: f8788d86ab28f61f7b46eb6be375f8a726783636
Signature · 7 lines
2.20.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 1/3 arm64: insn: Don't assume unrecognized HINTs are NOPs
Currently the kernel assumes that any HINT which it does not explicitly recognise is a NOP. This is not robust as new instructions may be added which need special handling, including recent extensions like PAC, and in any case software should only be using explicit NOP instructions for deliberate NOPs.
This has the effect of rendering PAC and BTI instructions unprobeable which means that probes can't be inserted on the first instruction of functions built with those features.
--- arch/arm64/kernel/insn.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
arch/arm64/kernel/insn.c +3 -7
@@ -58,14 +58,10 @@ bool __kprobes aarch64_insn_is_nop(u32 insn)return false;switch (insn &0xFE0 ) { -case AARCH64_INSN_HINT_YIELD : -case AARCH64_INSN_HINT_WFE : -case AARCH64_INSN_HINT_WFI : -case AARCH64_INSN_HINT_SEV : -case AARCH64_INSN_HINT_SEVL : -return false; -default : +case AARCH64_INSN_HINT_NOP :return true; +default : +return false; } }
Signature · 7 lines
2.20.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 2/3 arm64: insn: Add constants for PAC and BTI instruction decode
In reply to Mark BrownAdd constants for decoding the various PAC and BTI instructions defined in the HINT space. Since we are now decoding both the op2 and CRm fields rename the enum as well; this is compatible with what the existing users are doing.
--- arch/arm64/include/asm/insn.h | 22 ++++++++++++++++++++-- arch/arm64/kernel/insn.c | 2 +- 2 files changed, 21 insertions(+), 3 deletions(-)
arch/arm64/include/asm/insn.h +20 -2
@@ -39,13 +39,31 @@ enum aarch64_insn_encoding_class {* system instructions */ }; -enum aarch64_insn_hint_op { +enum aarch64_insn_hint_cr_op {AARCH64_INSN_HINT_NOP =0x0 <<5 ,AARCH64_INSN_HINT_YIELD =0x1 <<5 ,AARCH64_INSN_HINT_WFE =0x2 <<5 ,AARCH64_INSN_HINT_WFI =0x3 <<5 ,AARCH64_INSN_HINT_SEV =0x4 <<5 ,AARCH64_INSN_HINT_SEVL =0x5 <<5 , + +AARCH64_INSN_HINT_PACIA_1716 =0x08 <<5 , +AARCH64_INSN_HINT_PACIB_1716 =0x0A <<5 , +AARCH64_INSN_HINT_AUTIA_1716 =0x0B <<5 , +AARCH64_INSN_HINT_AUTIB_1716 =0x0C <<5 , +AARCH64_INSN_HINT_PACIAZ =0x18 <<5 , +AARCH64_INSN_HINT_PACIASP =0x19 <<5 , +AARCH64_INSN_HINT_PACIBZ =0x1A <<5 , +AARCH64_INSN_HINT_PACIBSP =0x1B <<5 , +AARCH64_INSN_HINT_AUTIAZ =0x1C <<5 , +AARCH64_INSN_HINT_AUTIASP =0x1D <<5 , +AARCH64_INSN_HINT_AUTIBZ =0x1E <<5 , +AARCH64_INSN_HINT_AUTIBSP =0x1F <<5 , + +AARCH64_INSN_HINT_BTI =0x40 <<5 , +AARCH64_INSN_HINT_BTIC =0x42 <<5 , +AARCH64_INSN_HINT_BTIJ =0x44 <<5 , +AARCH64_INSN_HINT_BTIJC =0x4C <<5 , };enum aarch64_insn_imm_type {
@@ -370,7 +388,7 @@ u32 aarch64_insn_gen_comp_branch_imm(unsigned long pc, unsigned long addr, enum aarch64_insn_branch_type type);u32 aarch64_insn_gen_cond_branch_imm (unsigned long pc,unsigned long addr,enum aarch64_insn_condition cond); -u32 aarch64_insn_gen_hint (enum aarch64_insn_hint_op op); +u32 aarch64_insn_gen_hint (enum aarch64_insn_hint_cr_op op);u32 aarch64_insn_gen_nop (void );u32 aarch64_insn_gen_branch_reg (enum aarch64_insn_register reg,enum aarch64_insn_branch_type type);
arch/arm64/kernel/insn.c +1 -1
@@ -570,7 +570,7 @@ u32 aarch64_insn_gen_cond_branch_imm(unsigned long pc, unsigned long addr, offset >> 2); } -u32 __kprobes aarch64_insn_gen_hint (enum aarch64_insn_hint_op op) +u32 __kprobes aarch64_insn_gen_hint (enum aarch64_insn_hint_cr_op op) {return aarch64_insn_get_hint_value () | op; }
Signature · 7 lines
2.20.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH 2/3] arm64: insn: Add constants for PAC and BTI instruction decode
arch/arm64/include/asm/insn.h enum aarch64_insn_encoding_class { · line 66
Quoted 4 lines · Mark Brown
arch/arm64/include/asm/insn.h +4
-0+AARCH64_INSN_HINT_BTI =0x40 <<5 , +AARCH64_INSN_HINT_BTIC =0x42 <<5 , +AARCH64_INSN_HINT_BTIJ =0x44 <<5 , + AARCH64_INSN_HINT_BTIJC = 0x4C << 5,
These constants are wrong (I checked the others, they're fine) - I'll send out a fixed version as part of the next version of the BTI kernel patches since they will depend on these.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Will Deacon
maintainerRe: [PATCH 2/3] arm64: insn: Add constants for PAC and BTI instruction decode
Quoted 10 lines · Mark Brown
arch/arm64/include/asm/insn.h enum aarch64_insn_encoding_class { · line 66
Quoted 4 lines · Mark Brown
arch/arm64/include/asm/insn.h +4
-0+AARCH64_INSN_HINT_BTI =0x40 <<5 , +AARCH64_INSN_HINT_BTIC =0x42 <<5 , +AARCH64_INSN_HINT_BTIJ =0x44 <<5 , + AARCH64_INSN_HINT_BTIJC = 0x4C << 5,These constants are wrong (I checked the others, they're fine) - I'll send out a fixed version as part of the next version of the BTI kernel patches since they will depend on these.
Ok, I'll ignore this series then.
Will
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH 3/3 arm64: insn: Report PAC and BTI instructions as NOPs
In reply to Mark BrownIn order to allow probing of PAC and BTI instructions without more specialized support recognize them as NOPs.
--- arch/arm64/kernel/insn.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
arch/arm64/kernel/insn.c +20 -0
@@ -57,7 +57,27 @@ bool __kprobes aarch64_insn_is_nop(u32 insn)if (!aarch64_insn_is_hint (insn))return false; +/* +* The PAC and BTI instructons are not strictly NOPs but until +* better support is added we can treat them as such. +*/ switch (insn &0xFE0 ) { +case AARCH64_INSN_HINT_PACIA_1716 : +case AARCH64_INSN_HINT_PACIB_1716 : +case AARCH64_INSN_HINT_AUTIA_1716 : +case AARCH64_INSN_HINT_AUTIB_1716 : +case AARCH64_INSN_HINT_PACIAZ : +case AARCH64_INSN_HINT_PACIASP : +case AARCH64_INSN_HINT_PACIBZ : +case AARCH64_INSN_HINT_PACIBSP : +case AARCH64_INSN_HINT_AUTIAZ : +case AARCH64_INSN_HINT_AUTIASP : +case AARCH64_INSN_HINT_AUTIBZ : +case AARCH64_INSN_HINT_AUTIBSP : +case AARCH64_INSN_HINT_BTI : +case AARCH64_INSN_HINT_BTIC : +case AARCH64_INSN_HINT_BTIJ : +case AARCH64_INSN_HINT_BTIJC :case AARCH64_INSN_HINT_NOP :return true;default :
Signature · 7 lines
2.20.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 6 lines · Mark Brown
Currently we default to assuming any unrecognized instruction in the hint space can be safely handled as a NOP. This is not robust and any code that really wants a NOP should be using the explicitly defined NOP so let's instead invert this and whitelist those instructions which it is safe to handle as NOPs.
Quoted 8 lines
Mark Brown (3):
arm64: insn: Don't assume unrecognized HINTs are NOPs
arm64: insn: Add constants for PAC and BTI instruction decode
arm64: insn: Report PAC and BTI instructions as NOPsarch/arm64/include/asm/insn.h | 22 ++++++++++++++++++++-- arch/arm64/kernel/insn.c | 32 ++++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 10 deletions(-)
IIRC, we concluded [1] there is no problem for PAC and BTI instruction in the NOP space. For this series:
[1] https://lore.kernel.org/linux-arm-kernel/[email protected]/
Signature · 6 lines
Catalin _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel