Skip to content

Commit bdf370d

Browse files
Andi KleenKuppuswamy Sathyanarayanan
authored andcommitted
x86/tdx: Add trace point for tdx fuzzer
This will allow generating coverage using the ftrace hist triggers, and also in general is useful for understanding what happened on a failure. Signed-off-by: Andi Kleen <[email protected]>
1 parent a9b2b00 commit bdf370d

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

arch/x86/include/asm/trace/tdx.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,51 @@ TRACE_EVENT(tdx_hypercall_exit,
148148

149149
#endif // CONFIG_INTEL_TDX_GUEST
150150

151+
#ifdef CONFIG_TDX_FUZZ
152+
153+
TRACE_EVENT(tdx_fuzz,
154+
155+
TP_PROTO(u64 rip, unsigned bits, u64 oldval, u64 newval, int loc),
156+
157+
TP_ARGS(rip, bits, oldval, newval, loc),
158+
159+
TP_STRUCT__entry(
160+
__field(u64, rip)
161+
__field(unsigned, bits)
162+
__field(u64, oldval)
163+
__field(u64, newval)
164+
__field(int, loc)
165+
),
166+
167+
TP_fast_assign(
168+
__entry->rip = rip;
169+
__entry->bits = bits;
170+
__entry->oldval = oldval;
171+
__entry->newval = newval;
172+
__entry->loc = loc;
173+
),
174+
175+
TP_printk("rip %pF bits %u oldval %llx newval %llx loc %s",
176+
(void *)__entry->rip,
177+
__entry->bits,
178+
__entry->oldval,
179+
__entry->newval,
180+
__print_symbolic(__entry->loc,
181+
{ TDX_FUZZ_MSR_READ, "msr_read" },
182+
{ TDX_FUZZ_MMIO_READ, "mmio_read" },
183+
{ TDX_FUZZ_MSR_READ_ERR, "msr_read_err" },
184+
{ TDX_FUZZ_MSR_WRITE_ERR, "msr_write_err" },
185+
{ TDX_FUZZ_PORT_IN, "port_in" },
186+
{ TDX_FUZZ_PORT_IN_ERR, "port_in_err" },
187+
{ TDX_FUZZ_CPUID1, "cpuid1" },
188+
{ TDX_FUZZ_CPUID2, "cpuid2" },
189+
{ TDX_FUZZ_CPUID3, "cpuid3" },
190+
{ TDX_FUZZ_CPUID4, "cpuid4" })
191+
)
192+
);
193+
194+
#endif
195+
151196
#undef TRACE_INCLUDE_PATH
152197
#define TRACE_INCLUDE_PATH asm/trace/
153198
#undef TRACE_INCLUDE_FILE

arch/x86/kernel/tdx-fuzz.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/percpu.h>
1414
#include <linux/smp.h>
1515
#include <asm/tdx.h>
16+
#include <asm/trace/tdx.h>
1617

1718
static DEFINE_PER_CPU(struct rnd_state, fuzz_rndstate);
1819
static DECLARE_FAULT_ATTR(tdx_fault);
@@ -39,6 +40,7 @@ static u64 __tdx_fuzz(u64 var, int bits, enum tdx_fuzz_loc loc)
3940
for (i = 0; i < num_bits; i++)
4041
var ^= 1ULL << (rnd[i] & (bits-1));
4142
}
43+
trace_tdx_fuzz((u64)__builtin_return_address(0), bits, oldvar, var, loc);
4244
put_cpu();
4345
return var;
4446
}
@@ -56,6 +58,7 @@ bool tdx_fuzz_err(enum tdx_fuzz_loc loc)
5658
if (!fuzz_errors || !should_fail(&tdx_fault, 1))
5759
return false;
5860

61+
trace_tdx_fuzz((u64)__builtin_return_address(0), 1, 0, 1, loc);
5962
return true;
6063
}
6164

0 commit comments

Comments
 (0)