[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v10 28/38] x86/fred: FRED entry/exit and dispatch code





On 14.09.23 г. 7:47 ч., Xin Li wrote:
From: "H. Peter Anvin (Intel)" <hpa@xxxxxxxxx>

The code to actually handle kernel and event entry/exit using
FRED. It is split up into two files thus:

- entry_64_fred.S contains the actual entrypoints and exit code, and
   saves and restores registers.
- entry_fred.c contains the two-level event dispatch code for FRED.
   The first-level dispatch is on the event type, and the second-level
   is on the event vector.

Originally-by: Megha Dey <megha.dey@xxxxxxxxx>
Signed-off-by: H. Peter Anvin (Intel) <hpa@xxxxxxxxx>
Co-developed-by: Xin Li <xin3.li@xxxxxxxxx>
Tested-by: Shan Kang <shan.kang@xxxxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Signed-off-by: Xin Li <xin3.li@xxxxxxxxx>
---

Changes since v9:
* Don't use jump tables, indirect jumps are expensive (Thomas Gleixner).
* Except NMI/#DB/#MCE, FRED really can share the exception handlers
   with IDT (Thomas Gleixner).
* Avoid the sysvec_* idt_entry muck, do it at a central place, reuse code
   instead of blindly copying it, which breaks the performance optimized
   sysvec entries like reschedule_ipi (Thomas Gleixner).
* Add asm_ prefix to FRED asm entry points (Thomas Gleixner).

Changes since v8:
* Don't do syscall early out in fred_entry_from_user() before there are
   proper performance numbers and justifications (Thomas Gleixner).
* Add the control exception handler to the FRED exception handler table
   (Thomas Gleixner).
* Add ENDBR to the FRED_ENTER asm macro.
* Reflect the FRED spec 5.0 change that ERETS and ERETU add 8 to %rsp
   before popping the return context from the stack.

Changes since v1:
* Initialize a FRED exception handler to fred_bad_event() instead of NULL
   if no FRED handler defined for an exception vector (Peter Zijlstra).
* Push calling irqentry_{enter,exit}() and instrumentation_{begin,end}()
   down into individual FRED exception handlers, instead of in the dispatch
   framework (Peter Zijlstra).
---
  arch/x86/entry/Makefile               |   5 +-
  arch/x86/entry/entry_64_fred.S        |  52 ++++++
  arch/x86/entry/entry_fred.c           | 230 ++++++++++++++++++++++++++
  arch/x86/include/asm/asm-prototypes.h |   1 +
  arch/x86/include/asm/fred.h           |   6 +
  5 files changed, 293 insertions(+), 1 deletion(-)
  create mode 100644 arch/x86/entry/entry_64_fred.S
  create mode 100644 arch/x86/entry/entry_fred.c



<snip>

+
+static noinstr void fred_intx(struct pt_regs *regs)
+{
+       switch (regs->fred_ss.vector) {
+       /* INT0 */
+       case X86_TRAP_OF:
+               exc_overflow(regs);
+               return;
+
+       /* INT3 */
+       case X86_TRAP_BP:
+               exc_int3(regs);
+               return;
+
+       /* INT80 */
+       case IA32_SYSCALL_VECTOR:
+               if (likely(IS_ENABLED(CONFIG_IA32_EMULATION))) {

Since future kernels will support boottime toggling of whether 32bit syscall interface should be enabled or not as per:
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?h=x86/entry&id=1da5c9bc119d3a749b519596b93f9b2667e93c4a

It will make more sense to replace this with ia32_enabled() invocation. I guess this could be done as a follow-up patch based on when this is merged as the ia32_enbaled changes are going to be merged in 6.7.


+                       /* Save the syscall number */
+                       regs->orig_ax = regs->ax;
+                       regs->ax = -ENOSYS;
+                       do_int80_syscall_32(regs);
+                       return;
+               }
+               fallthrough;
+
+       default:
+               exc_general_protection(regs, 0);
+               return;
+       }
+}
+
+static __always_inline void fred_other(struct pt_regs *regs)
+{
+       /* The compiler can fold these conditions into a single test */
+       if (likely(regs->fred_ss.vector == FRED_SYSCALL && regs->fred_ss.lm)) {
+               regs->orig_ax = regs->ax;
+               regs->ax = -ENOSYS;
+               do_syscall_64(regs, regs->orig_ax);
+               return;
+       } else if (likely(IS_ENABLED(CONFIG_IA32_EMULATION) &&

Ditto

+                         regs->fred_ss.vector == FRED_SYSENTER &&
+                         !regs->fred_ss.lm)) {
+               regs->orig_ax = regs->ax;
+               regs->ax = -ENOSYS;
+               do_fast_syscall_32(regs);
+               return;
+       } else {
+               exc_invalid_op(regs);
+               return;
+       }
+}
+

<snip>



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.