Skip to content

Commit

Permalink
selftests/powerpc: Fix wild_bctr test to work on ppc64
Browse files Browse the repository at this point in the history
The selftest I recently added to test branching to an out-of-bounds
NIP doesn't work on 64-bit big endian. It does fail but not in the
right way. That is it SEGVs trying to load from the opd at BAD_NIP,
but it never gets as far as branching to BAD_NIP.

To fix it we need to create an opd which is reachable but which holds
the bad address.

Fixes: b7683fc ("selftests/powerpc: Add a test of wild bctr")
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
  • Loading branch information
Michael Ellerman committed Nov 12, 2018
1 parent 43c6494 commit 2c7645b
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion tools/testing/selftests/powerpc/mm/wild_bctr.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ static void dump_regs(void)
}
}

#ifdef _CALL_AIXDESC
struct opd {
unsigned long ip;
unsigned long toc;
unsigned long env;
};
static struct opd bad_opd = {
.ip = BAD_NIP,
};
#define BAD_FUNC (&bad_opd)
#else
#define BAD_FUNC BAD_NIP
#endif

int test_wild_bctr(void)
{
int (*func_ptr)(void);
Expand Down Expand Up @@ -133,7 +147,7 @@ int test_wild_bctr(void)

poison_regs();

func_ptr = (int (*)(void))BAD_NIP;
func_ptr = (int (*)(void))BAD_FUNC;
func_ptr();

FAIL_IF(1); /* we didn't segv? */
Expand Down

0 comments on commit 2c7645b

Please sign in to comment.