Xen Test Framework
main.c
Go to the documentation of this file.
1
35#include <xtf.h>
36
37const char test_title[] = "LBR/TSX VMentry failure test";
38
39static void int3_stub(void)
40{
41 /* Force a LBR record to be generated. */
42 asm volatile ("jmp 1f; 1:");
43
44 /*
45 * After latching an LBR record, we need to force a subsequent vmentry.
46 * Using printk() is the easiest way.
47 */
48 printk("Latched a Last Branch Record in the upper canonical half\n");
49}
50
51void test_main(void)
52{
53 uint64_t dbgctl;
54
55 /* Alias everything in the upper canonical half. */
56 pae_l4_identmap[256] = pae_l4_identmap[0];
57 barrier();
58
59 /* Probe for, and enable Last Branch Record. */
60 if ( rdmsr_safe(MSR_DEBUGCTL, &dbgctl) )
61 return xtf_skip("Skip: MSR_DEBUGCTL not available\n");
62 else if ( wrmsr_safe(MSR_DEBUGCTL, dbgctl | DEBUGCTL_LBR) )
63 return xtf_skip("Skip: MSR_DEBUGCTL.LBR not available\n");
64
65 /* Construct a function pointer to int3_stub() via its upper alias. */
66 void (*int3_stub_alias)(void) = _p(_u(int3_stub) | 0xffff800000000000);
67
68 int3_stub_alias();
69
70 /*
71 * If XTF is alive at this point, the vmentry succeeded. This will either
72 * be unaffected hardware, or Xen has all applicable workarounds.
73 */
74 xtf_success("Success: No LBR/TSX VMentry failure in this configuration\n");
75}
76
77/*
78 * Local variables:
79 * mode: C
80 * c-file-style: "BSD"
81 * c-basic-offset: 4
82 * tab-width: 4
83 * indent-tabs-mode: nil
84 * End:
85 */
#define barrier()
Definition: compiler.h:30
void printk(const char *fmt,...)
Definition: console.c:134
void test_main(void)
To be implemented by each test, as its entry point.
Definition: main.c:110
const char test_title[]
The title of the test.
Definition: main.c:24
static void int3_stub(void)
Definition: main.c:39
#define MSR_DEBUGCTL
Definition: msr-index.h:30
#define DEBUGCTL_LBR
Definition: msr-index.h:31
static bool wrmsr_safe(uint32_t idx, uint64_t val)
Wrapper around wrmsr which safely catches #GP[0].
Definition: msr.h:69
static bool rdmsr_safe(uint32_t idx, uint64_t *val)
Wrapper around rdmsr which safely catches #GP[0].
Definition: msr.h:35
#define _p(v)
Express an abitrary integer v as void *.
Definition: numbers.h:48
#define _u(v)
Express an arbitrary value v as unsigned long.
Definition: numbers.h:53
void xtf_skip(const char *fmt,...)
Report a test skip.
Definition: report.c:66
void xtf_success(const char *fmt,...)
Report test success.
Definition: report.c:38
__UINT64_TYPE__ uint64_t
Definition: stdint.h:17