diff --git a/sys/conf/files.arm64 b/sys/conf/files.arm64 --- a/sys/conf/files.arm64 +++ b/sys/conf/files.arm64 @@ -419,6 +419,8 @@ dev/psci/psci.c standard dev/psci/smccc_arm64.S standard +dev/psci/smccc_kmsan.c optional kmsan \ + compile-with "${NOSAN_C}" dev/psci/smccc_trng.c standard dev/psci/smccc.c standard diff --git a/sys/dev/psci/smccc.h b/sys/dev/psci/smccc.h --- a/sys/dev/psci/smccc.h +++ b/sys/dev/psci/smccc.h @@ -87,10 +87,21 @@ int smccc_arch_workaround_1(void); int smccc_arch_workaround_2(int); +#if defined(SAN_NEEDS_INTERCEPTORS) && !defined(SMCCC_SAN_RUNTIME) +int SAN_INTERCEPTOR(arm_smccc_smc)(register_t, register_t, register_t, + register_t, register_t, register_t, register_t, register_t, + struct arm_smccc_res *res); +int SAN_INTERCEPTOR(arm_smccc_hvc)(register_t, register_t, register_t, + register_t, register_t, register_t, register_t, register_t, + struct arm_smccc_res *res); +#define arm_smccc_smc SAN_INTERCEPTOR(arm_smccc_smc) +#define arm_smccc_hvc SAN_INTERCEPTOR(arm_smccc_hvc) +#else int arm_smccc_smc(register_t, register_t, register_t, register_t, register_t, register_t, register_t, register_t, struct arm_smccc_res *res); int arm_smccc_hvc(register_t, register_t, register_t, register_t, register_t, register_t, register_t, register_t, struct arm_smccc_res *res); +#endif #define arm_smccc_invoke_1(func, a0, res) \ func(a0, 0, 0, 0, 0, 0, 0, 0, res) diff --git a/sys/dev/psci/smccc_kmsan.c b/sys/dev/psci/smccc_kmsan.c new file mode 100644 --- /dev/null +++ b/sys/dev/psci/smccc_kmsan.c @@ -0,0 +1,60 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2024 Arm Ltd + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#define SMCCC_SAN_RUNTIME + +#include +#include +#include + +#include +#include + +int kmsan_arm_smccc_smc(register_t, register_t, register_t, register_t, + register_t, register_t, register_t, register_t, struct arm_smccc_res *); +int kmsan_arm_smccc_hvc(register_t, register_t, register_t, register_t, + register_t, register_t, register_t, register_t, struct arm_smccc_res *); + +int +kmsan_arm_smccc_smc(register_t a0, register_t a1, register_t a2, + register_t a3, register_t a4, register_t a5, register_t a6, register_t a7, + struct arm_smccc_res *res) +{ + if (res != NULL) + kmsan_mark(res, sizeof(*res), KMSAN_STATE_INITED); + return (arm_smccc_smc(a0, a1, a2, a3, a4, a5, a6, a7, res)); +} + +int +kmsan_arm_smccc_hvc(register_t a0, register_t a1, register_t a2, + register_t a3, register_t a4, register_t a5, register_t a6, register_t a7, + struct arm_smccc_res *res) +{ + if (res != NULL) + kmsan_mark(res, sizeof(*res), KMSAN_STATE_INITED); + return (arm_smccc_hvc(a0, a1, a2, a3, a4, a5, a6, a7, res)); +}