mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-26 09:15:03 +07:00
d5f744f9a2
- Convert the 32bit syscalls to be pt_regs based which removes the requirement to push all 6 potential arguments onto the stack and consolidates the interface with the 64bit variant - The first small portion of the exception and syscall related entry code consolidation which aims to address the recently discovered issues vs. RCU, int3, NMI and some other exceptions which can interrupt any context. The bulk of the changes is still work in progress and aimed for 5.8. - A few lockdep namespace cleanups which have been applied into this branch to keep the prerequisites for the ongoing work confined. -----BEGIN PGP SIGNATURE----- iQJHBAABCgAxFiEEQp8+kY+LLUocC4bMphj1TA10mKEFAl6B/TMTHHRnbHhAbGlu dXRyb25peC5kZQAKCRCmGPVMDXSYoYA6EAC7r/bCMxBelljT3b7LkBbiJcocJ+zK OSzWU9miJGTAvYqn4/ciLKg4dA424b/1rBFlF1hBTCQ0HL5Cv4lajxdKEZCO5WCC WWTCz+MC60aWFaH3VNoywiLGb39H2IbqWbS9yNPd/wBkLHiMAD6NPQntOvcPaD4j 1lyrMtLzfrWlrHxvxdI3kt5ZpFLYNXr2xk61xQjTz0ROFQBhf2sDsuhHhiYVLPj7 JwYktpbBiPeaw2+I18NPymNPY+VfY8LCTgLl5M+rbKyCqebKaedZQJ7QXFhAEqKC Y2f+gJsKWtTDzGP2mk/5kF0uP7cd0vJK35ZCXtLZ9BbcNtFZU6w+ADqRo4pJBHRY QRzo/AWrdkuTJF0CrP6mcneNC7NwWLSdKrE1z77RQCHUPVvhHhRDZsgdLcZ/KKwx y1ji22trwNB+7LmI2fUOU5RRHZBIuNvQT+mPt24febJuHpZKul62dd3cqTGeSTC+ MYVknYDSg/+jk+83DhuZnTyb9lWTbq/0Q1HRDu6l2LrMIH7YMPpY5Ea64ZFYzWXy s0+iHEM4mUzltwNauHIntjbwXi3C0l2k1WQyG0gun2eS6SXfu0lb93V4msFj/N1+ oHavH2n2A4XrRr+Ob87fsl7nfXJibWP7R9xPblrWP2sNdqfjSyGd49rnsvpWqWMK Fj0d7tQ78+/SwA== =tWXS -----END PGP SIGNATURE----- Merge tag 'x86-entry-2020-03-30' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip Pull x86 entry code updates from Thomas Gleixner: - Convert the 32bit syscalls to be pt_regs based which removes the requirement to push all 6 potential arguments onto the stack and consolidates the interface with the 64bit variant - The first small portion of the exception and syscall related entry code consolidation which aims to address the recently discovered issues vs. RCU, int3, NMI and some other exceptions which can interrupt any context. The bulk of the changes is still work in progress and aimed for 5.8. - A few lockdep namespace cleanups which have been applied into this branch to keep the prerequisites for the ongoing work confined. * tag 'x86-entry-2020-03-30' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (35 commits) x86/entry: Fix build error x86 with !CONFIG_POSIX_TIMERS lockdep: Rename trace_{hard,soft}{irq_context,irqs_enabled}() lockdep: Rename trace_softirqs_{on,off}() lockdep: Rename trace_hardirq_{enter,exit}() x86/entry: Rename ___preempt_schedule x86: Remove unneeded includes x86/entry: Drop asmlinkage from syscalls x86/entry/32: Enable pt_regs based syscalls x86/entry/32: Use IA32-specific wrappers for syscalls taking 64-bit arguments x86/entry/32: Rename 32-bit specific syscalls x86/entry/32: Clean up syscall_32.tbl x86/entry: Remove ABI prefixes from functions in syscall tables x86/entry/64: Add __SYSCALL_COMMON() x86/entry: Remove syscall qualifier support x86/entry/64: Remove ptregs qualifier from syscall table x86/entry: Move max syscall number calculation to syscallhdr.sh x86/entry/64: Split X32 syscall table into its own file x86/entry/64: Move sys_ni_syscall stub to common.c x86/entry/64: Use syscall wrappers for x32_rt_sigreturn x86/entry: Refactor SYS_NI macros ...
230 lines
5.8 KiB
C
230 lines
5.8 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
|
|
* Copyright (C) 2005-2006, Thomas Gleixner, Russell King
|
|
*
|
|
* This file contains the core interrupt handling code. Detailed
|
|
* information is available in Documentation/core-api/genericirq.rst
|
|
*
|
|
*/
|
|
|
|
#include <linux/irq.h>
|
|
#include <linux/random.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/kernel_stat.h>
|
|
|
|
#include <trace/events/irq.h>
|
|
|
|
#include "internals.h"
|
|
|
|
#ifdef CONFIG_GENERIC_IRQ_MULTI_HANDLER
|
|
void (*handle_arch_irq)(struct pt_regs *) __ro_after_init;
|
|
#endif
|
|
|
|
/**
|
|
* handle_bad_irq - handle spurious and unhandled irqs
|
|
* @desc: description of the interrupt
|
|
*
|
|
* Handles spurious and unhandled IRQ's. It also prints a debugmessage.
|
|
*/
|
|
void handle_bad_irq(struct irq_desc *desc)
|
|
{
|
|
unsigned int irq = irq_desc_get_irq(desc);
|
|
|
|
print_irq_desc(irq, desc);
|
|
kstat_incr_irqs_this_cpu(desc);
|
|
ack_bad_irq(irq);
|
|
}
|
|
EXPORT_SYMBOL_GPL(handle_bad_irq);
|
|
|
|
/*
|
|
* Special, empty irq handler:
|
|
*/
|
|
irqreturn_t no_action(int cpl, void *dev_id)
|
|
{
|
|
return IRQ_NONE;
|
|
}
|
|
EXPORT_SYMBOL_GPL(no_action);
|
|
|
|
static void warn_no_thread(unsigned int irq, struct irqaction *action)
|
|
{
|
|
if (test_and_set_bit(IRQTF_WARNED, &action->thread_flags))
|
|
return;
|
|
|
|
printk(KERN_WARNING "IRQ %d device %s returned IRQ_WAKE_THREAD "
|
|
"but no thread function available.", irq, action->name);
|
|
}
|
|
|
|
void __irq_wake_thread(struct irq_desc *desc, struct irqaction *action)
|
|
{
|
|
/*
|
|
* In case the thread crashed and was killed we just pretend that
|
|
* we handled the interrupt. The hardirq handler has disabled the
|
|
* device interrupt, so no irq storm is lurking.
|
|
*/
|
|
if (action->thread->flags & PF_EXITING)
|
|
return;
|
|
|
|
/*
|
|
* Wake up the handler thread for this action. If the
|
|
* RUNTHREAD bit is already set, nothing to do.
|
|
*/
|
|
if (test_and_set_bit(IRQTF_RUNTHREAD, &action->thread_flags))
|
|
return;
|
|
|
|
/*
|
|
* It's safe to OR the mask lockless here. We have only two
|
|
* places which write to threads_oneshot: This code and the
|
|
* irq thread.
|
|
*
|
|
* This code is the hard irq context and can never run on two
|
|
* cpus in parallel. If it ever does we have more serious
|
|
* problems than this bitmask.
|
|
*
|
|
* The irq threads of this irq which clear their "running" bit
|
|
* in threads_oneshot are serialized via desc->lock against
|
|
* each other and they are serialized against this code by
|
|
* IRQS_INPROGRESS.
|
|
*
|
|
* Hard irq handler:
|
|
*
|
|
* spin_lock(desc->lock);
|
|
* desc->state |= IRQS_INPROGRESS;
|
|
* spin_unlock(desc->lock);
|
|
* set_bit(IRQTF_RUNTHREAD, &action->thread_flags);
|
|
* desc->threads_oneshot |= mask;
|
|
* spin_lock(desc->lock);
|
|
* desc->state &= ~IRQS_INPROGRESS;
|
|
* spin_unlock(desc->lock);
|
|
*
|
|
* irq thread:
|
|
*
|
|
* again:
|
|
* spin_lock(desc->lock);
|
|
* if (desc->state & IRQS_INPROGRESS) {
|
|
* spin_unlock(desc->lock);
|
|
* while(desc->state & IRQS_INPROGRESS)
|
|
* cpu_relax();
|
|
* goto again;
|
|
* }
|
|
* if (!test_bit(IRQTF_RUNTHREAD, &action->thread_flags))
|
|
* desc->threads_oneshot &= ~mask;
|
|
* spin_unlock(desc->lock);
|
|
*
|
|
* So either the thread waits for us to clear IRQS_INPROGRESS
|
|
* or we are waiting in the flow handler for desc->lock to be
|
|
* released before we reach this point. The thread also checks
|
|
* IRQTF_RUNTHREAD under desc->lock. If set it leaves
|
|
* threads_oneshot untouched and runs the thread another time.
|
|
*/
|
|
desc->threads_oneshot |= action->thread_mask;
|
|
|
|
/*
|
|
* We increment the threads_active counter in case we wake up
|
|
* the irq thread. The irq thread decrements the counter when
|
|
* it returns from the handler or in the exit path and wakes
|
|
* up waiters which are stuck in synchronize_irq() when the
|
|
* active count becomes zero. synchronize_irq() is serialized
|
|
* against this code (hard irq handler) via IRQS_INPROGRESS
|
|
* like the finalize_oneshot() code. See comment above.
|
|
*/
|
|
atomic_inc(&desc->threads_active);
|
|
|
|
wake_up_process(action->thread);
|
|
}
|
|
|
|
irqreturn_t __handle_irq_event_percpu(struct irq_desc *desc, unsigned int *flags)
|
|
{
|
|
irqreturn_t retval = IRQ_NONE;
|
|
unsigned int irq = desc->irq_data.irq;
|
|
struct irqaction *action;
|
|
|
|
record_irq_time(desc);
|
|
|
|
for_each_action_of_desc(desc, action) {
|
|
irqreturn_t res;
|
|
|
|
/*
|
|
* If this IRQ would be threaded under force_irqthreads, mark it so.
|
|
*/
|
|
if (irq_settings_can_thread(desc) &&
|
|
!(action->flags & (IRQF_NO_THREAD | IRQF_PERCPU | IRQF_ONESHOT)))
|
|
lockdep_hardirq_threaded();
|
|
|
|
trace_irq_handler_entry(irq, action);
|
|
res = action->handler(irq, action->dev_id);
|
|
trace_irq_handler_exit(irq, action, res);
|
|
|
|
if (WARN_ONCE(!irqs_disabled(),"irq %u handler %pS enabled interrupts\n",
|
|
irq, action->handler))
|
|
local_irq_disable();
|
|
|
|
switch (res) {
|
|
case IRQ_WAKE_THREAD:
|
|
/*
|
|
* Catch drivers which return WAKE_THREAD but
|
|
* did not set up a thread function
|
|
*/
|
|
if (unlikely(!action->thread_fn)) {
|
|
warn_no_thread(irq, action);
|
|
break;
|
|
}
|
|
|
|
__irq_wake_thread(desc, action);
|
|
|
|
/* Fall through - to add to randomness */
|
|
case IRQ_HANDLED:
|
|
*flags |= action->flags;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
retval |= res;
|
|
}
|
|
|
|
return retval;
|
|
}
|
|
|
|
irqreturn_t handle_irq_event_percpu(struct irq_desc *desc)
|
|
{
|
|
irqreturn_t retval;
|
|
unsigned int flags = 0;
|
|
|
|
retval = __handle_irq_event_percpu(desc, &flags);
|
|
|
|
add_interrupt_randomness(desc->irq_data.irq, flags);
|
|
|
|
if (!noirqdebug)
|
|
note_interrupt(desc, retval);
|
|
return retval;
|
|
}
|
|
|
|
irqreturn_t handle_irq_event(struct irq_desc *desc)
|
|
{
|
|
irqreturn_t ret;
|
|
|
|
desc->istate &= ~IRQS_PENDING;
|
|
irqd_set(&desc->irq_data, IRQD_IRQ_INPROGRESS);
|
|
raw_spin_unlock(&desc->lock);
|
|
|
|
ret = handle_irq_event_percpu(desc);
|
|
|
|
raw_spin_lock(&desc->lock);
|
|
irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS);
|
|
return ret;
|
|
}
|
|
|
|
#ifdef CONFIG_GENERIC_IRQ_MULTI_HANDLER
|
|
int __init set_handle_irq(void (*handle_irq)(struct pt_regs *))
|
|
{
|
|
if (handle_arch_irq)
|
|
return -EBUSY;
|
|
|
|
handle_arch_irq = handle_irq;
|
|
return 0;
|
|
}
|
|
#endif
|