1 /* SPDX-License-Identifier: (GPL-2.0-only)
5 * Copyright (C) 2024 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 #ifndef _LTTNG_WRAPPER_IBT_H
9 #define _LTTNG_WRAPPER_IBT_H
11 struct irq_ibt_state
{
17 * Save (disable) and restore interrupts around MSR bit change and indirect
18 * function call to make sure this thread is not migrated to another CPU which
19 * would not have the MSR bit cleared.
22 #ifdef CONFIG_X86_KERNEL_IBT
23 # include <asm/cpufeature.h>
25 static inline __attribute__((always_inline
))
26 struct irq_ibt_state
wrapper_irq_ibt_save(void)
28 struct irq_ibt_state state
= { 0, 0 };
31 if (!cpu_feature_enabled(X86_FEATURE_IBT
))
33 local_irq_save(state
.flags
);
34 rdmsrl(MSR_IA32_S_CET
, msr
);
35 wrmsrl(MSR_IA32_S_CET
, msr
& ~CET_ENDBR_EN
);
41 static inline __attribute__((always_inline
))
42 void wrapper_irq_ibt_restore(struct irq_ibt_state state
)
46 if (!cpu_feature_enabled(X86_FEATURE_IBT
))
48 rdmsrl(MSR_IA32_S_CET
, msr
);
50 msr
|= (state
.msr
& CET_ENDBR_EN
);
51 wrmsrl(MSR_IA32_S_CET
, msr
);
52 local_irq_restore(state
.flags
);
55 static inline struct irq_ibt_state
wrapper_irq_ibt_save(void) { struct irq_ibt_state state
= { 0, 0 }; return state
; }
56 static inline void wrapper_irq_ibt_restore(struct irq_ibt_state state
) { }
59 #endif /* _LTTNG_WRAPPER_IBT_H */
This page took 0.043452 seconds and 4 git commands to generate.