Commit 32b09c23 authored by H. Peter Anvin (Intel)'s avatar H. Peter Anvin (Intel) Committed by Borislav Petkov (AMD)
Browse files

x86/fred: Add a new header file for FRED definitions



Add a header file for FRED prototypes and definitions.

Signed-off-by: default avatarH. Peter Anvin (Intel) <hpa@zytor.com>
Signed-off-by: default avatarXin Li <xin3.li@intel.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
Tested-by: default avatarShan Kang <shan.kang@intel.com>
Link: https://lore.kernel.org/r/20231205105030.8698-16-xin3.li@intel.com
parent 3c77bf02
Loading
Loading
Loading
Loading
+68 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Macros for Flexible Return and Event Delivery (FRED)
 */

#ifndef ASM_X86_FRED_H
#define ASM_X86_FRED_H

#include <linux/const.h>

#include <asm/asm.h>

/*
 * FRED event return instruction opcodes for ERET{S,U}; supported in
 * binutils >= 2.41.
 */
#define ERETS			_ASM_BYTES(0xf2,0x0f,0x01,0xca)
#define ERETU			_ASM_BYTES(0xf3,0x0f,0x01,0xca)

/*
 * RSP is aligned to a 64-byte boundary before used to push a new stack frame
 */
#define FRED_STACK_FRAME_RSP_MASK	_AT(unsigned long, (~0x3f))

/*
 * Used for the return address for call emulation during code patching,
 * and measured in 64-byte cache lines.
 */
#define FRED_CONFIG_REDZONE_AMOUNT	1
#define FRED_CONFIG_REDZONE		(_AT(unsigned long, FRED_CONFIG_REDZONE_AMOUNT) << 6)
#define FRED_CONFIG_INT_STKLVL(l)	(_AT(unsigned long, l) << 9)
#define FRED_CONFIG_ENTRYPOINT(p)	_AT(unsigned long, (p))

#ifndef __ASSEMBLY__

#ifdef CONFIG_X86_FRED
#include <linux/kernel.h>

#include <asm/ptrace.h>

struct fred_info {
	/* Event data: CR2, DR6, ... */
	unsigned long edata;
	unsigned long resv;
};

/* Full format of the FRED stack frame */
struct fred_frame {
	struct pt_regs   regs;
	struct fred_info info;
};

static __always_inline struct fred_info *fred_info(struct pt_regs *regs)
{
	return &container_of(regs, struct fred_frame, regs)->info;
}

static __always_inline unsigned long fred_event_data(struct pt_regs *regs)
{
	return fred_info(regs)->edata;
}

#else /* CONFIG_X86_FRED */
static __always_inline unsigned long fred_event_data(struct pt_regs *regs) { return 0; }
#endif /* CONFIG_X86_FRED */
#endif /* !__ASSEMBLY__ */

#endif /* ASM_X86_FRED_H */