On Wed, Feb 26, 2020 at 03:57:11PM +0000, Mark Brown wrote: > From: Dave Martin <Dave.Martin@xxxxxxx> > > Hoist the IT state handling code earlier in traps.c, to avoid > accumulating forward declarations. > > No functional change. > > Signed-off-by: Dave Martin <Dave.Martin@xxxxxxx> Reviewed-by: Kees Cook <keescook@xxxxxxxxxxxx> -Kees > Signed-off-by: Mark Brown <broonie@xxxxxxxxxx> > --- > arch/arm64/kernel/traps.c | 103 ++++++++++++++++++-------------------- > 1 file changed, 50 insertions(+), 53 deletions(-) > > diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c > index bc9f4292bfc3..3c07a7074145 100644 > --- a/arch/arm64/kernel/traps.c > +++ b/arch/arm64/kernel/traps.c > @@ -272,7 +272,55 @@ void arm64_notify_die(const char *str, struct pt_regs *regs, > } > } > > -static void advance_itstate(struct pt_regs *regs); > +#ifdef CONFIG_COMPAT > +#define PSTATE_IT_1_0_SHIFT 25 > +#define PSTATE_IT_1_0_MASK (0x3 << PSTATE_IT_1_0_SHIFT) > +#define PSTATE_IT_7_2_SHIFT 10 > +#define PSTATE_IT_7_2_MASK (0x3f << PSTATE_IT_7_2_SHIFT) > + > +static u32 compat_get_it_state(struct pt_regs *regs) > +{ > + u32 it, pstate = regs->pstate; > + > + it = (pstate & PSTATE_IT_1_0_MASK) >> PSTATE_IT_1_0_SHIFT; > + it |= ((pstate & PSTATE_IT_7_2_MASK) >> PSTATE_IT_7_2_SHIFT) << 2; > + > + return it; > +} > + > +static void compat_set_it_state(struct pt_regs *regs, u32 it) > +{ > + u32 pstate_it; > + > + pstate_it = (it << PSTATE_IT_1_0_SHIFT) & PSTATE_IT_1_0_MASK; > + pstate_it |= ((it >> 2) << PSTATE_IT_7_2_SHIFT) & PSTATE_IT_7_2_MASK; > + > + regs->pstate &= ~PSR_AA32_IT_MASK; > + regs->pstate |= pstate_it; > +} > + > +static void advance_itstate(struct pt_regs *regs) > +{ > + u32 it; > + > + /* ARM mode */ > + if (!(regs->pstate & PSR_AA32_T_BIT) || > + !(regs->pstate & PSR_AA32_IT_MASK)) > + return; > + > + it = compat_get_it_state(regs); > + > + /* > + * If this is the last instruction of the block, wipe the IT > + * state. Otherwise advance it. > + */ > + if (!(it & 7)) > + it = 0; > + else > + it = (it & 0xe0) | ((it << 1) & 0x1f); > + > + compat_set_it_state(regs, it); > +} > > void arm64_skip_faulting_instruction(struct pt_regs *regs, unsigned long size) > { > @@ -285,7 +333,7 @@ void arm64_skip_faulting_instruction(struct pt_regs *regs, unsigned long size) > if (user_mode(regs)) > user_fastforward_single_step(current); > > - if (regs->pstate & PSR_MODE32_BIT) > + if (compat_user_mode(regs)) > advance_itstate(regs); > } > > @@ -578,34 +626,6 @@ static const struct sys64_hook sys64_hooks[] = { > {}, > }; > > - > -#ifdef CONFIG_COMPAT > -#define PSTATE_IT_1_0_SHIFT 25 > -#define PSTATE_IT_1_0_MASK (0x3 << PSTATE_IT_1_0_SHIFT) > -#define PSTATE_IT_7_2_SHIFT 10 > -#define PSTATE_IT_7_2_MASK (0x3f << PSTATE_IT_7_2_SHIFT) > - > -static u32 compat_get_it_state(struct pt_regs *regs) > -{ > - u32 it, pstate = regs->pstate; > - > - it = (pstate & PSTATE_IT_1_0_MASK) >> PSTATE_IT_1_0_SHIFT; > - it |= ((pstate & PSTATE_IT_7_2_MASK) >> PSTATE_IT_7_2_SHIFT) << 2; > - > - return it; > -} > - > -static void compat_set_it_state(struct pt_regs *regs, u32 it) > -{ > - u32 pstate_it; > - > - pstate_it = (it << PSTATE_IT_1_0_SHIFT) & PSTATE_IT_1_0_MASK; > - pstate_it |= ((it >> 2) << PSTATE_IT_7_2_SHIFT) & PSTATE_IT_7_2_MASK; > - > - regs->pstate &= ~PSR_AA32_IT_MASK; > - regs->pstate |= pstate_it; > -} > - > static bool cp15_cond_valid(unsigned int esr, struct pt_regs *regs) > { > int cond; > @@ -626,29 +646,6 @@ static bool cp15_cond_valid(unsigned int esr, struct pt_regs *regs) > return aarch32_opcode_cond_checks[cond](regs->pstate); > } > > -static void advance_itstate(struct pt_regs *regs) > -{ > - u32 it; > - > - /* ARM mode */ > - if (!(regs->pstate & PSR_AA32_T_BIT) || > - !(regs->pstate & PSR_AA32_IT_MASK)) > - return; > - > - it = compat_get_it_state(regs); > - > - /* > - * If this is the last instruction of the block, wipe the IT > - * state. Otherwise advance it. > - */ > - if (!(it & 7)) > - it = 0; > - else > - it = (it & 0xe0) | ((it << 1) & 0x1f); > - > - compat_set_it_state(regs, it); > -} > - > static void compat_cntfrq_read_handler(unsigned int esr, struct pt_regs *regs) > { > int reg = (esr & ESR_ELx_CP15_32_ISS_RT_MASK) >> ESR_ELx_CP15_32_ISS_RT_SHIFT; > -- > 2.20.1 > -- Kees Cook