2019-05-28 16:57:18 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
2013-08-06 07:42:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013, Michael Ellerman, IBM Corp.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SELFTESTS_POWERPC_UTILS_H
|
|
|
|
#define _SELFTESTS_POWERPC_UTILS_H
|
|
|
|
|
2016-05-02 03:51:38 +00:00
|
|
|
#define __cacheline_aligned __attribute__((aligned(128)))
|
|
|
|
|
2013-08-06 07:42:36 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2015-11-24 02:05:39 +00:00
|
|
|
#include <linux/auxvec.h>
|
2018-05-21 15:13:57 +00:00
|
|
|
#include <linux/perf_event.h>
|
2015-12-23 05:49:50 +00:00
|
|
|
#include "reg.h"
|
2013-08-06 07:42:36 +00:00
|
|
|
|
|
|
|
/* Avoid headaches with PRI?64 - just use %ll? always */
|
|
|
|
typedef unsigned long long u64;
|
|
|
|
typedef signed long long s64;
|
|
|
|
|
|
|
|
/* Just for familiarity */
|
|
|
|
typedef uint32_t u32;
|
2015-02-23 15:14:44 +00:00
|
|
|
typedef uint16_t u16;
|
2013-08-06 07:42:36 +00:00
|
|
|
typedef uint8_t u8;
|
|
|
|
|
2016-09-23 06:18:17 +00:00
|
|
|
void test_harness_set_timeout(uint64_t time);
|
2013-08-06 07:42:36 +00:00
|
|
|
int test_harness(int (test_function)(void), char *name);
|
2017-02-06 10:13:27 +00:00
|
|
|
|
|
|
|
int read_auxv(char *buf, ssize_t buf_size);
|
|
|
|
void *find_auxv_entry(int type, char *auxv);
|
|
|
|
void *get_auxv_entry(int type);
|
|
|
|
|
2015-12-16 07:59:31 +00:00
|
|
|
int pick_online_cpu(void);
|
2013-08-06 07:42:36 +00:00
|
|
|
|
2018-05-21 15:13:57 +00:00
|
|
|
int read_debugfs_file(char *debugfs_file, int *result);
|
|
|
|
int write_debugfs_file(char *debugfs_file, int result);
|
|
|
|
void set_dscr(unsigned long val);
|
|
|
|
int perf_event_open_counter(unsigned int type,
|
|
|
|
unsigned long config, int group_fd);
|
|
|
|
int perf_event_enable(int fd);
|
|
|
|
int perf_event_disable(int fd);
|
|
|
|
int perf_event_reset(int fd);
|
|
|
|
|
2016-07-11 05:25:18 +00:00
|
|
|
static inline bool have_hwcap(unsigned long ftr)
|
|
|
|
{
|
|
|
|
return ((unsigned long)get_auxv_entry(AT_HWCAP) & ftr) == ftr;
|
|
|
|
}
|
|
|
|
|
2016-09-23 06:18:07 +00:00
|
|
|
#ifdef AT_HWCAP2
|
2015-11-24 02:05:39 +00:00
|
|
|
static inline bool have_hwcap2(unsigned long ftr2)
|
|
|
|
{
|
|
|
|
return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2;
|
|
|
|
}
|
2016-09-23 06:18:07 +00:00
|
|
|
#else
|
|
|
|
static inline bool have_hwcap2(unsigned long ftr2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
2015-11-24 02:05:39 +00:00
|
|
|
|
2018-07-26 12:24:57 +00:00
|
|
|
bool is_ppc64le(void);
|
|
|
|
|
2013-08-06 07:42:36 +00:00
|
|
|
/* Yes, this is evil */
|
|
|
|
#define FAIL_IF(x) \
|
|
|
|
do { \
|
|
|
|
if ((x)) { \
|
|
|
|
fprintf(stderr, \
|
|
|
|
"[FAIL] Test FAILED on line %d\n", __LINE__); \
|
|
|
|
return 1; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2014-06-10 12:23:09 +00:00
|
|
|
/* The test harness uses this, yes it's gross */
|
|
|
|
#define MAGIC_SKIP_RETURN_VALUE 99
|
|
|
|
|
|
|
|
#define SKIP_IF(x) \
|
|
|
|
do { \
|
|
|
|
if ((x)) { \
|
|
|
|
fprintf(stderr, \
|
|
|
|
"[SKIP] Test skipped on line %d\n", __LINE__); \
|
|
|
|
return MAGIC_SKIP_RETURN_VALUE; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2018-10-31 14:38:21 +00:00
|
|
|
#define SKIP_IF_MSG(x, msg) \
|
|
|
|
do { \
|
|
|
|
if ((x)) { \
|
|
|
|
fprintf(stderr, \
|
|
|
|
"[SKIP] Test skipped on line %d: %s\n", \
|
|
|
|
__LINE__, msg); \
|
|
|
|
return MAGIC_SKIP_RETURN_VALUE; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2014-01-21 04:22:17 +00:00
|
|
|
#define _str(s) #s
|
|
|
|
#define str(s) _str(s)
|
|
|
|
|
2016-05-02 03:51:38 +00:00
|
|
|
/* POWER9 feature */
|
|
|
|
#ifndef PPC_FEATURE2_ARCH_3_00
|
|
|
|
#define PPC_FEATURE2_ARCH_3_00 0x00800000
|
|
|
|
#endif
|
|
|
|
|
2018-05-21 15:13:56 +00:00
|
|
|
#if defined(__powerpc64__)
|
|
|
|
#define UCONTEXT_NIA(UC) (UC)->uc_mcontext.gp_regs[PT_NIP]
|
selftests/powerpc: New TM signal self test
A new self test that forces MSR[TS] to be set without calling any TM
instruction. This test also tries to cause a page fault at a signal
handler, exactly between MSR[TS] set and tm_recheckpoint(), forcing
thread->texasr to be rewritten with TEXASR[FS] = 0, which will cause a BUG
when tm_recheckpoint() is called.
This test is not deterministic, since it is hard to guarantee that the page
access will cause a page fault. In order to force more page faults at
signal context, the signal handler and the ucontext are being mapped into a
MADV_DONTNEED memory chunks.
Tests have shown that the bug could be exposed with few interactions in a
buggy kernel. This test is configured to loop 5000x, having a good chance
to hit the kernel issue in just one run. This self test takes less than
two seconds to run.
This test uses set/getcontext because the kernel will recheckpoint
zeroed structures, causing the test to segfault, which is undesired because
the test needs to rerun, so, there is a signal handler for SIGSEGV which
will restart the test.
v2: Uses the MADV_DONTNEED memory advice
v3: Fix memcpy and 32-bits compilation
v4: Does not define unused macros
Signed-off-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-01-08 11:31:21 +00:00
|
|
|
#define UCONTEXT_MSR(UC) (UC)->uc_mcontext.gp_regs[PT_MSR]
|
2018-05-21 15:13:56 +00:00
|
|
|
#elif defined(__powerpc__)
|
|
|
|
#define UCONTEXT_NIA(UC) (UC)->uc_mcontext.uc_regs->gregs[PT_NIP]
|
selftests/powerpc: New TM signal self test
A new self test that forces MSR[TS] to be set without calling any TM
instruction. This test also tries to cause a page fault at a signal
handler, exactly between MSR[TS] set and tm_recheckpoint(), forcing
thread->texasr to be rewritten with TEXASR[FS] = 0, which will cause a BUG
when tm_recheckpoint() is called.
This test is not deterministic, since it is hard to guarantee that the page
access will cause a page fault. In order to force more page faults at
signal context, the signal handler and the ucontext are being mapped into a
MADV_DONTNEED memory chunks.
Tests have shown that the bug could be exposed with few interactions in a
buggy kernel. This test is configured to loop 5000x, having a good chance
to hit the kernel issue in just one run. This self test takes less than
two seconds to run.
This test uses set/getcontext because the kernel will recheckpoint
zeroed structures, causing the test to segfault, which is undesired because
the test needs to rerun, so, there is a signal handler for SIGSEGV which
will restart the test.
v2: Uses the MADV_DONTNEED memory advice
v3: Fix memcpy and 32-bits compilation
v4: Does not define unused macros
Signed-off-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
2019-01-08 11:31:21 +00:00
|
|
|
#define UCONTEXT_MSR(UC) (UC)->uc_mcontext.uc_regs->gregs[PT_MSR]
|
2018-05-21 15:13:56 +00:00
|
|
|
#else
|
|
|
|
#error implement UCONTEXT_NIA
|
|
|
|
#endif
|
|
|
|
|
2013-08-06 07:42:36 +00:00
|
|
|
#endif /* _SELFTESTS_POWERPC_UTILS_H */
|