diff --git a/sys/arm64/arm64/genassym.c b/sys/arm64/arm64/genassym.c --- a/sys/arm64/arm64/genassym.c +++ b/sys/arm64/arm64/genassym.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -38,6 +39,8 @@ #include #include +#include + /* Sizeof arm64_bootparams, rounded to keep stack alignment */ ASSYM(BOOTPARAMS_SIZE, roundup2(sizeof(struct arm64_bootparams), STACKALIGNBYTES + 1)); @@ -88,3 +91,8 @@ ASSYM(INTR_ROOT_IRQ, INTR_ROOT_IRQ); ASSYM(INTR_ROOT_FIQ, INTR_ROOT_FIQ); + +ASSYM(ARM_SMCCC_RES_SIZE, sizeof(struct arm_smccc_res)); +ASSYM(ARM_SMCCC_1_2_REGS_SIZE, sizeof(struct arm_smccc_1_2_regs)); + +ASSYM(KMSAN_STATE_INITED, KMSAN_STATE_INITED); diff --git a/sys/dev/psci/smccc_arm64.S b/sys/dev/psci/smccc_arm64.S --- a/sys/dev/psci/smccc_arm64.S +++ b/sys/dev/psci/smccc_arm64.S @@ -34,6 +34,8 @@ #include +#include "assym.inc" + .macro arm_smccc_1_0 insn ENTRY(arm_smccc_\insn) \insn #0 @@ -41,6 +43,17 @@ cbz x4, 1f stp x0, x1, [x4, #16 * 0] stp x2, x3, [x4, #16 * 1] +#ifdef KMSAN + stp x29, x30, [sp, #-32]! + str x0, [sp, #16] + mov x29, sp + mov x0, x4 + mov x1, #(ARM_SMCCC_RES_SIZE) + mov x2, #(KMSAN_STATE_INITED) + bl kmsan_mark + ldr x0, [sp, #16] + ldp x29, x30, [sp], #32 +#endif 1: ret END(arm_smccc_\insn) .endm @@ -55,8 +68,15 @@ .macro arm_smccc_1_2 insn ENTRY(arm_smccc_1_2_\insn) - stp x1, x19, [sp, #-16]! + stp x29, x30, [sp, #-32]! + stp x1, x19, [sp, #16] + mov x29, sp mov x19, x0 +#ifdef KMSAN + mov x1, #(ARM_SMCCC_1_2_REGS_SIZE) + adr x2, .Lfunc_name_\insn + bl kmsan_check +#endif ldp x0, x1, [x19, #16 * 0] ldp x2, x3, [x19, #16 * 1] ldp x4, x5, [x19, #16 * 2] @@ -67,7 +87,7 @@ ldp x14, x15, [x19, #16 * 7] ldp x16, x17, [x19, #16 * 8] \insn #0 - ldr x19, [sp] + ldr x19, [sp, #16] cbz x19, 1f stp x0, x1, [x19, #16 * 0] stp x2, x3, [x19, #16 * 1] @@ -78,8 +98,22 @@ stp x12, x13, [x19, #16 * 6] stp x14, x15, [x19, #16 * 7] stp x16, x17, [x19, #16 * 8] -1: ldp xzr, x19, [sp], #16 +#ifdef KMSAN + mov x0, x19 + mov x1, #(ARM_SMCCC_1_2_REGS_SIZE) + mov x2, #(KMSAN_STATE_INITED) + bl kmsan_mark + /* Restore x0 as the return value */ + ldr x0, [x19] +#endif +1: + ldr x19, [sp, #24] + ldp x29, x30, [sp], #32 ret +#ifdef KMSAN +.Lfunc_name_\insn: + .asciz "arm_smccc_1_2_\insn" +#endif END(arm_smccc_1_2_\insn) .endm /* int arm_smccc_1_2_*(const struct arm_smccc_1_2_regs *args,