Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
dd3c9ee
ACPI: PRM: Annotate struct prm_module_info with __counted_by
kees Mar 11, 2025
d97d1f0
ACPI: PRM: Add PRM handler direct call support
jallen-amd Mar 11, 2025
055fc82
x86/cpu: Add model number for Intel Clearwater Forest processor
aegl Jan 17, 2024
19da7f8
x86: KVM: Advertise CPUIDs for new instructions in Clearwater Forest
taosu-linux Nov 5, 2024
f5fe988
dmaengine: idxd: Add a new DSA device ID for Granite Rapids-D platform
Aug 28, 2024
856841d
KVM: x86: Advertise max mappable GPA in CPUID.0x80000008.GuestPhysBits
kraxel Mar 13, 2024
44df0f1
KVM: selftests: x86: Prioritize getting max_gfn from GuestPhysBits
taosu-linux May 13, 2024
8dc2e17
EDAC/{skx_common,skx,i10nm}: Move the common debug code to skx_common
qzhuo2 Aug 29, 2024
1703456
KVM: VMX: Also clear SGX EDECCSSA in KVM CPU caps when SGX is disabled
kaihuang Sep 5, 2024
43371c4
platform/x86/intel-uncore-freq: Do not present separate package-die d…
spandruvada Aug 20, 2024
ddddaea
platform/x86/intel-uncore-freq: Add support for efficiency latency co…
Aug 28, 2024
c81f650
platform/x86/intel-uncore-freq: Add efficiency latency control to sys…
Aug 28, 2024
8ab34a4
intel_idle: add Granite Rapids Xeon D support
dedekind Nov 7, 2024
03d257a
intel_idle: add Clearwater Forest SoC support
dedekind Dec 3, 2024
f867c11
KVM: x86: Advertise AVX10.1 CPUID to userspace
taosu-linux Aug 19, 2024
e1554b4
x86/cpu: Add model number for Intel Clearwater Forest processor
aegl Jan 17, 2024
efa680e
i2c: i801: Hide Intel Birch Stream SoC TCO WDT
Sep 1, 2025
bfcc99d
tools headers UAPI: Sync include/uapi/linux/perf_event.h header with …
Oct 25, 2023
71879ae
powercap: intel_rapl: Sort header files
zhang-rui Apr 8, 2024
7398baa
powercap: intel_rapl: Introduce APIs for PMU support
zhang-rui Apr 28, 2024
ca18a3a
powercap: intel_rapl_tpmi: Enable PMU support
zhang-rui Apr 28, 2024
5df7536
perf/x86/uncore: Save the unit control address of all units
Jun 14, 2024
da11017
perf/x86/uncore: Support per PMU cpumask
Jun 14, 2024
0cf336d
perf/x86/uncore: Retrieve the unit ID from the unit control RB tree
Jun 14, 2024
6b5fe8a
perf/x86/uncore: Apply the unit control RB tree to MMIO uncore units
Jun 14, 2024
1c246a3
perf/x86/uncore: Apply the unit control RB tree to MSR uncore units
Jun 14, 2024
5265106
perf/x86/uncore: Apply the unit control RB tree to PCI uncore units
Jun 14, 2024
5745b30
perf/x86/uncore: Cleanup unused unit structure
Jun 14, 2024
464c564
perf/x86/intel/uncore: Support HBM and CXL PMON counters
Jun 14, 2024
431ff83
perf/x86/intel: Use the common uarch name for the shared functions
Aug 29, 2023
7c03566
perf/x86/intel: Factor out the initialization code for SPR
Aug 29, 2023
a8e3aa1
perf/x86/intel: Factor out the initialization code for ADL e-core
Aug 29, 2023
79f4513
perf/x86/intel: Apply the common initialization code for ADL
Aug 29, 2023
6c69664
perf/x86/intel: Clean up the hybrid CPU type handling code
Aug 29, 2023
4e92565
perf/x86/intel: Add common intel_pmu_init_hybrid()
Aug 29, 2023
4456e2e
perf/x86/intel: Add a distinct name for Granite Rapids
Jul 8, 2024
0cc31b6
perf/x86/intel: Fix broken fixed event constraints extension
Sep 11, 2023
6761941
perf/x86/intel: Correct incorrect 'or' operation for PMU capabilities
Nov 21, 2023
924f9ad
perf/x86/intel/uncore: Clean up func_id
Jan 8, 2025
ed1dbbc
perf/x86/intel/uncore: Support more units on Granite Rapids
Jan 8, 2025
09c10d1
perf/uapi: Clean up <uapi/linux/perf_event.h> a bit
ingomolnar May 22, 2025
bc4a025
perf/x86/intel: Support the PEBS event mask
Jun 26, 2024
72027d3
perf/x86: Support counter mask
Jun 26, 2024
8bfb1d4
perf/x86: Add Lunar Lake and Arrow Lake support
Jun 26, 2024
ae89990
perf/x86/intel: Rename model-specific pebs_latency_data functions
Jun 26, 2024
ef9bc1d
perf/x86/intel: Support new data source for Lunar Lake
Jun 26, 2024
4c320b6
perf/x86: Add config_mask to represent EVENTSEL bitmask
Jun 26, 2024
8824791
perf/x86/intel: Support PERFEVTSEL extension
Jun 26, 2024
f4d825b
perf/x86/intel: Support Perfmon MSRs aliasing
Jun 26, 2024
6aca9f5
perf/x86/intel/ds: Clarify adaptive PEBS processing
Nov 19, 2024
8dfc915
perf/x86/intel/ds: Factor out functions for PEBS records processing
Nov 19, 2024
45386b8
perf/x86/intel/ds: Simplify the PEBS records processing for adaptive …
Nov 19, 2024
209af1c
perf/x86/intel/ds: Add PEBS format 6
Dec 16, 2024
07143c2
perf/x86/intel: Support RDPMC metrics clear mode
Dec 11, 2024
d255658
perf/x86/intel: Fix crash in icl_update_topdown_event()
Jul 24, 2025
2fb3064
perf/x86/intel: Support PEBS counters snapshotting
Jan 21, 2025
63cdd8c
perf/x86: Add dynamic constraint
Mar 27, 2025
ffeffab
perf/x86/intel: Track the num of events needs late setup
Mar 27, 2025
a55cf45
perf: Extend the bit width of the arch-specific flag
Mar 27, 2025
8ee2b93
perf/x86/intel: Add CPUID enumeration for the auto counter reload
Mar 27, 2025
f160a28
perf/x86/intel: Support auto counter reload
Mar 27, 2025
5d0473d
perf/x86/intel: Don't clear perf metrics overflow bit unconditionally
Apr 15, 2025
a2302d1
perf/x86/intel: Add PMU support for Clearwater Forest
Apr 15, 2025
e6b640f
perf/x86/intel: Parse CPUID archPerfmonExt leaves for non-hybrid CPUs
Apr 15, 2025
101b3ef
perf/x86/intel: Only check the group flag for X86 leader
Apr 24, 2025
902fe01
perf/x86/intel: Check the X86 leader for pebs_counter_event_group
Apr 24, 2025
4bd67c8
perf/x86/intel: Check the X86 leader for ACR group
Apr 24, 2025
178054b
perf/x86: Optimize the is_x86_event
Apr 24, 2025
3644c77
perf/x86/intel/uncore: Add Clearwater Forest support
Dec 11, 2024
a1fbc6b
perf/x86/intel/uncore: Support MSR portal for discovery tables
Jul 7, 2025
9370484
perf/x86/intel/uncore: Support customized MMIO map size
Jul 7, 2025
e59b06d
perf vendor events: Add Clearwaterforest events
captain5050 Feb 11, 2025
121796d
cpufreq: intel_pstate: Support Emerald Rapids OOB mode
spandruvada May 30, 2024
de68868
cpufreq: intel_pstate: Support Granite Rapids and Sierra Forest OOB mode
spandruvada Aug 2, 2024
010e273
cpufreq: intel_pstate: Support Clearwater Forest OOB mode
spandruvada Aug 8, 2025
ff6cddf
cpufreq: intel_pstate: Add Granite Rapids support in no-HWP mode
lrq-max Jun 23, 2025
97b7823
platform/x86/intel/ifs: Add Clearwater Forest to CPU support list
jithu83 Dec 10, 2024
1ff3dc5
EDAC/i10nm: Add Intel Grand Ridge micro-server support
qzhuo2 Jan 29, 2024
8a9134e
EDAC/{skx_common,i10nm}: Remove the AMAP register for determing DDR5
qzhuo2 Aug 29, 2024
1ed6c5e
EDAC/i10nm: Add Intel Clearwater Forest server support
qzhuo2 Dec 3, 2024
8b7cb4f
EDAC/{i10nm,skx,skx_common}: Support UV systems
Dec 13, 2024
56bce82
EDAC/i10nm: Explicitly set the modes of the RRL register sets
qzhuo2 Apr 17, 2025
318dc19
EDAC/{skx_common,i10nm}: Structure the per-channel RRL registers
qzhuo2 Apr 17, 2025
7c8d9bc
EDAC/{skx_common,i10nm}: Refactor enable_retry_rd_err_log()
qzhuo2 Apr 17, 2025
8f29458
EDAC/{skx_common,i10nm}: Refactor show_retry_rd_err_log()
qzhuo2 Apr 17, 2025
0e1571e
EDAC/{skx_common,i10nm}: Add RRL support for Intel Granite Rapids server
qzhuo2 Apr 17, 2025
8cbb4be
EDAC/i10nm: Fix the bitwise operation between variables of different …
qzhuo2 Apr 24, 2025
acf971e
EDAC/i10nm: Add Intel Granite Rapids-D support
qzhuo2 Jul 4, 2025
795462a
EDAC/{skx_common,i10nm}: Use scnprintf() for safer buffer handling
Jul 15, 2025
b99264c
platform/x86: ISST: Add Clearwater Forest to support list
spandruvada Jan 3, 2025
904e4ff
cpufreq: intel_pstate: Update Balance-performance EPP for Granite Rapids
spandruvada Nov 12, 2024
a311c13
x86/cpufeatures,opcode,msr: Add the WRMSRNS instruction support
xinli-intel Dec 5, 2023
8b870b4
x86/entry: Remove idtentry_sysvec from entry_{32,64}.S
xinli-intel Dec 5, 2023
c47883d
x86/trapnr: Add event type macros to <asm/trapnr.h>
xinli-intel Dec 5, 2023
49d5662
Documentation/x86/64: Add documentation for FRED
xinli-intel Dec 5, 2023
cec8f77
x86/fred: Add Kconfig option for FRED (CONFIG_X86_FRED)
Dec 5, 2023
c4e03e2
x86/cpufeatures: Add the CPU feature bit for FRED
Dec 5, 2023
471b24d
x86/fred: Disable FRED support if CONFIG_X86_FRED is disabled
Dec 5, 2023
3a28ec2
x86/fred: Add a fred= cmdline param
xinli-intel Dec 5, 2023
e0981f2
x86/opcode: Add ERET[US] instructions to the x86 opcode map
Dec 5, 2023
689d8c6
x86/objtool: Teach objtool about ERET[US]
Dec 5, 2023
8cf9317
x86/cpu: Add X86_CR4_FRED macro
Dec 5, 2023
d4b40f0
x86/cpu: Add MSR numbers for FRED configuration
Dec 5, 2023
649c955
x86/fred: Add a new header file for FRED definitions
Dec 5, 2023
bff5893
x86/fred: Reserve space for the FRED stack frame
Dec 5, 2023
f8e8e2e
x86/fred: Update MSR_IA32_FRED_RSP0 during task switch
Dec 5, 2023
fde214b
x86/fred: Disallow the swapgs instruction when FRED is enabled
Dec 5, 2023
20299ed
x86/fred: No ESPFIX needed when FRED is enabled
Dec 5, 2023
8f13178
x86/fred: Allow single-step trap and NMI when starting a new task
Dec 5, 2023
40e5b29
x86/fred: Make exc_page_fault() work for FRED
Dec 5, 2023
fda677e
x86/fred: Add a debug fault entry stub for FRED
Dec 5, 2023
703eb56
x86/fred: Add a NMI entry stub for FRED
Dec 16, 2023
04d18a4
x86/fred: Add a machine check entry stub for FRED
xinli-intel Dec 5, 2023
796ee45
x86/entry: Compile entry_SYSCALL32_ignore() unconditionally
Jun 23, 2023
7b3d52e
x86/entry: Make IA32 syscalls' availability depend on ia32_enabled()
Jun 23, 2023
a7e4ccb
x86/fred: FRED entry/exit and dispatch code
Dec 9, 2023
66794c9
x86/traps: Add sysvec_install() to install a system interrupt handler
xinli-intel Dec 5, 2023
bbfd530
x86/fred: Let ret_from_fork_asm() jmp to asm_fred_exit_user when FRED…
Dec 5, 2023
24f9fbb
x86/fred: Fixup fault on ERETU by jumping to fred_entrypoint_user
xinli-intel Dec 5, 2023
3e49477
x86/entry/calling: Allow PUSH_AND_CLEAR_REGS being used beyond actual…
Dec 5, 2023
dd958cf
x86/entry: Add fred_entry_from_kvm() for VMX to handle IRQ/NMI
xinli-intel Dec 5, 2023
55c20be
KVM: VMX: Call fred_entry_from_kvm() for IRQ/NMI handling
xinli-intel Dec 5, 2023
71aab89
x86/syscall: Split IDT syscall setup code into idt_syscall_init()
xinli-intel Dec 5, 2023
1417a57
x86/fred: Add FRED initialization functions
Dec 5, 2023
6d58011
x86/fred: Invoke FRED initialization code to enable FRED
Dec 5, 2023
f1fd816
x86/fred: Fix a build warning with allmodconfig due to 'inline' faili…
xinli-intel Feb 2, 2024
a5aa3b1
MAINTAINERS: Add a maintainer entry for FRED
xinli-intel Jan 31, 2024
610e221
x86/fred: Fix init_task thread stack pointer initialization
xinli-intel Mar 4, 2024
df1d636
x86/fred: Parse cmdline param "fred=" in cpu_parse_early_param()
xinli-intel Jul 9, 2024
876858a
x86/fred: Move FRED RSP initialization into a separate function
xinli-intel Jul 9, 2024
e903390
x86/fred: Enable FRED right after init_mem_mapping()
xinli-intel Jul 9, 2024
e27cf34
x86/fred: Set SS to __KERNEL_DS when enabling FRED
xinli-intel Aug 16, 2024
f282099
x86/entry: Test ti_work for zero before processing individual bits
xinli-intel Aug 22, 2024
cdd2449
x86/msr: Switch between WRMSRNS and WRMSR with the alternatives mecha…
andyhhp Aug 22, 2024
517ae66
x86/entry: Set FRED RSP0 on return to userspace instead of context sw…
xinli-intel Aug 22, 2024
10c54fa
x86/fred: Fix the FRED RSP0 MSR out of sync with its per-CPU cache
xinli-intel Jan 10, 2025
d6ba2cc
x86/fred: Fix system hang during S4 resume with FRED enabled
xinli-intel Apr 1, 2025
a5696e4
x86/fred/signal: Prevent immediate repeat of single step trap on retu…
xinli-intel Jun 9, 2025
71aacb9
dmaengine: idxd: Remove improper idxd_free
ysun Jul 29, 2025
28d3110
dmaengine: idxd: Fix refcount underflow on module unload
ysun Jul 29, 2025
f6f9db5
dmaengine: idxd: Fix double free in idxd_setup_wqs()
Aug 11, 2025
2237527
perf/x86/intel/cstate: Add Clearwater Forrest support
zhenyw May 30, 2024
d9d1f57
perf/x86: Print PMU counters bitmap in x86_pmu_show_pmu_cap()
Aug 20, 2025
5e79b66
x86,fs/resctrl: Remove inappropriate references to cacheinfo in the r…
beckwen Oct 9, 2025
e363230
temp patch for upstream commit
beckwen Oct 13, 2025
aa743a1
add the unified config.velinux for test
bhe4 Oct 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Documentation/admin-guide/kernel-parameters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,12 @@
Warning: use of this parameter will taint the kernel
and may cause unknown problems.

fred= [X86-64]
Enable/disable Flexible Return and Event Delivery.
Format: { on | off }
on: enable FRED when it's present.
off: disable FRED, the default setting.

ftrace=[tracer]
[FTRACE] will set and start the specified tracer
as early as possible in order to facilitate early
Expand Down
96 changes: 96 additions & 0 deletions Documentation/arch/x86/x86_64/fred.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
.. SPDX-License-Identifier: GPL-2.0

=========================================
Flexible Return and Event Delivery (FRED)
=========================================

Overview
========

The FRED architecture defines simple new transitions that change
privilege level (ring transitions). The FRED architecture was
designed with the following goals:

1) Improve overall performance and response time by replacing event
delivery through the interrupt descriptor table (IDT event
delivery) and event return by the IRET instruction with lower
latency transitions.

2) Improve software robustness by ensuring that event delivery
establishes the full supervisor context and that event return
establishes the full user context.

The new transitions defined by the FRED architecture are FRED event
delivery and, for returning from events, two FRED return instructions.
FRED event delivery can effect a transition from ring 3 to ring 0, but
it is used also to deliver events incident to ring 0. One FRED
instruction (ERETU) effects a return from ring 0 to ring 3, while the
other (ERETS) returns while remaining in ring 0. Collectively, FRED
event delivery and the FRED return instructions are FRED transitions.

In addition to these transitions, the FRED architecture defines a new
instruction (LKGS) for managing the state of the GS segment register.
The LKGS instruction can be used by 64-bit operating systems that do
not use the new FRED transitions.

Furthermore, the FRED architecture is easy to extend for future CPU
architectures.

Software based event dispatching
================================

FRED operates differently from IDT in terms of event handling. Instead
of directly dispatching an event to its handler based on the event
vector, FRED requires the software to dispatch an event to its handler
based on both the event's type and vector. Therefore, an event dispatch
framework must be implemented to facilitate the event-to-handler
dispatch process. The FRED event dispatch framework takes control
once an event is delivered, and employs a two-level dispatch.

The first level dispatching is event type based, and the second level
dispatching is event vector based.

Full supervisor/user context
============================

FRED event delivery atomically save and restore full supervisor/user
context upon event delivery and return. Thus it avoids the problem of
transient states due to %cr2 and/or %dr6, and it is no longer needed
to handle all the ugly corner cases caused by half baked entry states.

FRED allows explicit unblock of NMI with new event return instructions
ERETS/ERETU, avoiding the mess caused by IRET which unconditionally
unblocks NMI, e.g., when an exception happens during NMI handling.

FRED always restores the full value of %rsp, thus ESPFIX is no longer
needed when FRED is enabled.

LKGS
====

LKGS behaves like the MOV to GS instruction except that it loads the
base address into the IA32_KERNEL_GS_BASE MSR instead of the GS
segment’s descriptor cache. With LKGS, it ends up with avoiding
mucking with kernel GS, i.e., an operating system can always operate
with its own GS base address.

Because FRED event delivery from ring 3 and ERETU both swap the value
of the GS base address and that of the IA32_KERNEL_GS_BASE MSR, plus
the introduction of LKGS instruction, the SWAPGS instruction is no
longer needed when FRED is enabled, thus is disallowed (#UD).

Stack levels
============

4 stack levels 0~3 are introduced to replace the nonreentrant IST for
event handling, and each stack level should be configured to use a
dedicated stack.

The current stack level could be unchanged or go higher upon FRED
event delivery. If unchanged, the CPU keeps using the current event
stack. If higher, the CPU switches to a new event stack specified by
the MSR of the new stack level, i.e., MSR_IA32_FRED_RSP[123].

Only execution of a FRED return instruction ERET[US], could lower the
current stack level, causing the CPU to switch back to the stack it was
on before a previous event delivery that promoted the stack level.
1 change: 1 addition & 0 deletions Documentation/arch/x86/x86_64/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ x86_64 Support
cpu-hotplug-spec
machinecheck
fsgs
fred
10 changes: 10 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -10911,6 +10911,16 @@ L: netdev@vger.kernel.org
S: Maintained
F: drivers/net/wwan/iosm/

INTEL(R) FLEXIBLE RETURN AND EVENT DELIVERY
M: Xin Li <xin@zytor.com>
M: "H. Peter Anvin" <hpa@zytor.com>
S: Supported
F: Documentation/arch/x86/x86_64/fred.rst
F: arch/x86/entry/entry_64_fred.S
F: arch/x86/entry/entry_fred.c
F: arch/x86/include/asm/fred.h
F: arch/x86/kernel/fred.c

INTEL(R) TRACE HUB
M: Alexander Shishkin <alexander.shishkin@linux.intel.com>
S: Supported
Expand Down
9 changes: 9 additions & 0 deletions arch/x86/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,15 @@ config X86_CPU_RESCTRL

Say N if unsure.

config X86_FRED
bool "Flexible Return and Event Delivery"
depends on X86_64
help
When enabled, try to use Flexible Return and Event Delivery
instead of the legacy SYSCALL/SYSENTER/IDT architecture for
ring transitions and exception/interrupt handling if the
system supports.

if X86_32
config X86_BIGSMP
bool "Support for big SMP systems with more than 8 CPUs"
Expand Down
5 changes: 4 additions & 1 deletion arch/x86/entry/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ obj-y += vdso/
obj-y += vsyscall/

obj-$(CONFIG_PREEMPTION) += thunk_$(BITS).o
CFLAGS_entry_fred.o += -fno-stack-protector
CFLAGS_REMOVE_entry_fred.o += -pg $(CC_FLAGS_FTRACE)
obj-$(CONFIG_X86_FRED) += entry_64_fred.o entry_fred.o

obj-$(CONFIG_IA32_EMULATION) += entry_64_compat.o syscall_32.o
obj-$(CONFIG_X86_X32_ABI) += syscall_x32.o

15 changes: 10 additions & 5 deletions arch/x86/entry/calling.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ For 32-bit we have the following conventions - kernel is built with
* for assembly code:
*/

.macro PUSH_REGS rdx=%rdx rcx=%rcx rax=%rax save_ret=0
.macro PUSH_REGS rdx=%rdx rcx=%rcx rax=%rax save_ret=0 unwind_hint=1
.if \save_ret
pushq %rsi /* pt_regs->si */
movq 8(%rsp), %rsi /* temporarily store the return address in %rsi */
Expand All @@ -89,14 +89,17 @@ For 32-bit we have the following conventions - kernel is built with
pushq %r13 /* pt_regs->r13 */
pushq %r14 /* pt_regs->r14 */
pushq %r15 /* pt_regs->r15 */

.if \unwind_hint
UNWIND_HINT_REGS
.endif

.if \save_ret
pushq %rsi /* return address on top of stack */
.endif
.endm

.macro CLEAR_REGS
.macro CLEAR_REGS clear_bp=1
/*
* Sanitize registers of values that a speculation attack might
* otherwise want to exploit. The lower registers are likely clobbered
Expand All @@ -111,17 +114,19 @@ For 32-bit we have the following conventions - kernel is built with
xorl %r10d, %r10d /* nospec r10 */
xorl %r11d, %r11d /* nospec r11 */
xorl %ebx, %ebx /* nospec rbx */
.if \clear_bp
xorl %ebp, %ebp /* nospec rbp */
.endif
xorl %r12d, %r12d /* nospec r12 */
xorl %r13d, %r13d /* nospec r13 */
xorl %r14d, %r14d /* nospec r14 */
xorl %r15d, %r15d /* nospec r15 */

.endm

.macro PUSH_AND_CLEAR_REGS rdx=%rdx rcx=%rcx rax=%rax save_ret=0
PUSH_REGS rdx=\rdx, rcx=\rcx, rax=\rax, save_ret=\save_ret
CLEAR_REGS
.macro PUSH_AND_CLEAR_REGS rdx=%rdx rcx=%rcx rax=%rax save_ret=0 clear_bp=1 unwind_hint=1
PUSH_REGS rdx=\rdx, rcx=\rcx, rax=\rax, save_ret=\save_ret unwind_hint=\unwind_hint
CLEAR_REGS clear_bp=\clear_bp
.endm

.macro POP_REGS pop_rdi=1
Expand Down
4 changes: 0 additions & 4 deletions arch/x86/entry/entry_32.S
Original file line number Diff line number Diff line change
Expand Up @@ -649,10 +649,6 @@ SYM_CODE_START_LOCAL(asm_\cfunc)
SYM_CODE_END(asm_\cfunc)
.endm

.macro idtentry_sysvec vector cfunc
idtentry \vector asm_\cfunc \cfunc has_error_code=0
.endm

/*
* Include the defines which emit the idt entries which are shared
* shared between 32 and 64 bit and emit the __irqentry_text_* markers
Expand Down
16 changes: 6 additions & 10 deletions arch/x86/entry/entry_64.S
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,13 @@ SYM_CODE_START(ret_from_fork_asm)
* and unwind should work normally.
*/
UNWIND_HINT_REGS

#ifdef CONFIG_X86_FRED
ALTERNATIVE "jmp swapgs_restore_regs_and_return_to_usermode", \
"jmp asm_fred_exit_user", X86_FEATURE_FRED
#else
jmp swapgs_restore_regs_and_return_to_usermode
#endif
SYM_CODE_END(ret_from_fork_asm)
.popsection

Expand Down Expand Up @@ -421,14 +427,6 @@ SYM_CODE_END(\asmsym)
idtentry \vector asm_\cfunc \cfunc has_error_code=1
.endm

/*
* System vectors which invoke their handlers directly and are not
* going through the regular common device interrupt handling code.
*/
.macro idtentry_sysvec vector cfunc
idtentry \vector asm_\cfunc \cfunc has_error_code=0
.endm

/**
* idtentry_mce_db - Macro to generate entry stubs for #MC and #DB
* @vector: Vector number
Expand Down Expand Up @@ -1509,7 +1507,6 @@ nmi_restore:
iretq
SYM_CODE_END(asm_exc_nmi)

#ifndef CONFIG_IA32_EMULATION
/*
* This handles SYSCALL from 32-bit code. There is no way to program
* MSRs to fully disable 32-bit SYSCALL.
Expand All @@ -1521,7 +1518,6 @@ SYM_CODE_START(entry_SYSCALL32_ignore)
CLEAR_CPU_BUFFERS
sysretl
SYM_CODE_END(entry_SYSCALL32_ignore)
#endif

.pushsection .text, "ax"
__FUNC_ALIGN
Expand Down
131 changes: 131 additions & 0 deletions arch/x86/entry/entry_64_fred.S
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* The actual FRED entry points.
*/

#include <linux/export.h>

#include <asm/asm.h>
#include <asm/fred.h>
#include <asm/segment.h>

#include "calling.h"

.code64
.section .noinstr.text, "ax"

.macro FRED_ENTER
UNWIND_HINT_END_OF_STACK
ENDBR
PUSH_AND_CLEAR_REGS
movq %rsp, %rdi /* %rdi -> pt_regs */
.endm

.macro FRED_EXIT
UNWIND_HINT_REGS
POP_REGS
.endm

/*
* The new RIP value that FRED event delivery establishes is
* IA32_FRED_CONFIG & ~FFFH for events that occur in ring 3.
* Thus the FRED ring 3 entry point must be 4K page aligned.
*/
.align 4096

SYM_CODE_START_NOALIGN(asm_fred_entrypoint_user)
FRED_ENTER
call fred_entry_from_user
SYM_INNER_LABEL(asm_fred_exit_user, SYM_L_GLOBAL)
FRED_EXIT
1: ERETU

_ASM_EXTABLE_TYPE(1b, asm_fred_entrypoint_user, EX_TYPE_ERETU)
SYM_CODE_END(asm_fred_entrypoint_user)

/*
* The new RIP value that FRED event delivery establishes is
* (IA32_FRED_CONFIG & ~FFFH) + 256 for events that occur in
* ring 0, i.e., asm_fred_entrypoint_user + 256.
*/
.org asm_fred_entrypoint_user + 256, 0xcc
SYM_CODE_START_NOALIGN(asm_fred_entrypoint_kernel)
FRED_ENTER
call fred_entry_from_kernel
FRED_EXIT
ERETS
SYM_CODE_END(asm_fred_entrypoint_kernel)

#if IS_ENABLED(CONFIG_KVM_INTEL)
SYM_FUNC_START(asm_fred_entry_from_kvm)
push %rbp
mov %rsp, %rbp

UNWIND_HINT_SAVE

/*
* Both IRQ and NMI from VMX can be handled on current task stack
* because there is no need to protect from reentrancy and the call
* stack leading to this helper is effectively constant and shallow
* (relatively speaking). Do the same when FRED is active, i.e., no
* need to check current stack level for a stack switch.
*
* Emulate the FRED-defined redzone and stack alignment.
*/
sub $(FRED_CONFIG_REDZONE_AMOUNT << 6), %rsp
and $FRED_STACK_FRAME_RSP_MASK, %rsp

/*
* Start to push a FRED stack frame, which is always 64 bytes:
*
* +--------+-----------------+
* | Bytes | Usage |
* +--------+-----------------+
* | 63:56 | Reserved |
* | 55:48 | Event Data |
* | 47:40 | SS + Event Info |
* | 39:32 | RSP |
* | 31:24 | RFLAGS |
* | 23:16 | CS + Aux Info |
* | 15:8 | RIP |
* | 7:0 | Error Code |
* +--------+-----------------+
*/
push $0 /* Reserved, must be 0 */
push $0 /* Event data, 0 for IRQ/NMI */
push %rdi /* fred_ss handed in by the caller */
push %rbp
pushf
mov $__KERNEL_CS, %rax
push %rax

/*
* Unlike the IDT event delivery, FRED _always_ pushes an error code
* after pushing the return RIP, thus the CALL instruction CANNOT be
* used here to push the return RIP, otherwise there is no chance to
* push an error code before invoking the IRQ/NMI handler.
*
* Use LEA to get the return RIP and push it, then push an error code.
*/
lea 1f(%rip), %rax
push %rax /* Return RIP */
push $0 /* Error code, 0 for IRQ/NMI */

PUSH_AND_CLEAR_REGS clear_bp=0 unwind_hint=0
movq %rsp, %rdi /* %rdi -> pt_regs */
call __fred_entry_from_kvm /* Call the C entry point */
POP_REGS
ERETS
1:
/*
* Objtool doesn't understand what ERETS does, this hint tells it that
* yes, we'll reach here and with what stack state. A save/restore pair
* isn't strictly needed, but it's the simplest form.
*/
UNWIND_HINT_RESTORE
pop %rbp
RET

SYM_FUNC_END(asm_fred_entry_from_kvm)
EXPORT_SYMBOL_GPL(asm_fred_entry_from_kvm);
#endif
Loading