Skip to content

Commit 16ec54a

Browse files
committed
Merge branch 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf fixes from Ingo Molnar: - an s2ram related fix on AMD systems - a perf fault handling bug that is relatively old but which has become much easier to trigger in v3.13 after commit e00b12e ("perf/x86: Further optimize copy_from_user_nmi()") * 'perf-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: perf/x86/amd/ibs: Fix waking up from S3 for AMD family 10h x86, mm, perf: Allow recursive faults from interrupts
2 parents 7d0d46d + bee09ed commit 16ec54a

File tree

2 files changed

+63
-8
lines changed

2 files changed

+63
-8
lines changed

arch/x86/kernel/cpu/perf_event_amd_ibs.c

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/module.h>
1111
#include <linux/pci.h>
1212
#include <linux/ptrace.h>
13+
#include <linux/syscore_ops.h>
1314

1415
#include <asm/apic.h>
1516

@@ -816,6 +817,18 @@ static int force_ibs_eilvt_setup(void)
816817
return ret;
817818
}
818819

820+
static void ibs_eilvt_setup(void)
821+
{
822+
/*
823+
* Force LVT offset assignment for family 10h: The offsets are
824+
* not assigned by the BIOS for this family, so the OS is
825+
* responsible for doing it. If the OS assignment fails, fall
826+
* back to BIOS settings and try to setup this.
827+
*/
828+
if (boot_cpu_data.x86 == 0x10)
829+
force_ibs_eilvt_setup();
830+
}
831+
819832
static inline int get_ibs_lvt_offset(void)
820833
{
821834
u64 val;
@@ -851,6 +864,36 @@ static void clear_APIC_ibs(void *dummy)
851864
setup_APIC_eilvt(offset, 0, APIC_EILVT_MSG_FIX, 1);
852865
}
853866

867+
#ifdef CONFIG_PM
868+
869+
static int perf_ibs_suspend(void)
870+
{
871+
clear_APIC_ibs(NULL);
872+
return 0;
873+
}
874+
875+
static void perf_ibs_resume(void)
876+
{
877+
ibs_eilvt_setup();
878+
setup_APIC_ibs(NULL);
879+
}
880+
881+
static struct syscore_ops perf_ibs_syscore_ops = {
882+
.resume = perf_ibs_resume,
883+
.suspend = perf_ibs_suspend,
884+
};
885+
886+
static void perf_ibs_pm_init(void)
887+
{
888+
register_syscore_ops(&perf_ibs_syscore_ops);
889+
}
890+
891+
#else
892+
893+
static inline void perf_ibs_pm_init(void) { }
894+
895+
#endif
896+
854897
static int
855898
perf_ibs_cpu_notifier(struct notifier_block *self, unsigned long action, void *hcpu)
856899
{
@@ -877,18 +920,12 @@ static __init int amd_ibs_init(void)
877920
if (!caps)
878921
return -ENODEV; /* ibs not supported by the cpu */
879922

880-
/*
881-
* Force LVT offset assignment for family 10h: The offsets are
882-
* not assigned by the BIOS for this family, so the OS is
883-
* responsible for doing it. If the OS assignment fails, fall
884-
* back to BIOS settings and try to setup this.
885-
*/
886-
if (boot_cpu_data.x86 == 0x10)
887-
force_ibs_eilvt_setup();
923+
ibs_eilvt_setup();
888924

889925
if (!ibs_eilvt_valid())
890926
goto out;
891927

928+
perf_ibs_pm_init();
892929
get_online_cpus();
893930
ibs_caps = caps;
894931
/* make ibs_caps visible to other cpus: */

arch/x86/mm/fault.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,20 @@ no_context(struct pt_regs *regs, unsigned long error_code,
641641

642642
/* Are we prepared to handle this kernel fault? */
643643
if (fixup_exception(regs)) {
644+
/*
645+
* Any interrupt that takes a fault gets the fixup. This makes
646+
* the below recursive fault logic only apply to a faults from
647+
* task context.
648+
*/
649+
if (in_interrupt())
650+
return;
651+
652+
/*
653+
* Per the above we're !in_interrupt(), aka. task context.
654+
*
655+
* In this case we need to make sure we're not recursively
656+
* faulting through the emulate_vsyscall() logic.
657+
*/
644658
if (current_thread_info()->sig_on_uaccess_error && signal) {
645659
tsk->thread.trap_nr = X86_TRAP_PF;
646660
tsk->thread.error_code = error_code | PF_USER;
@@ -649,6 +663,10 @@ no_context(struct pt_regs *regs, unsigned long error_code,
649663
/* XXX: hwpoison faults will set the wrong code. */
650664
force_sig_info_fault(signal, si_code, address, tsk, 0);
651665
}
666+
667+
/*
668+
* Barring that, we can do the fixup and be happy.
669+
*/
652670
return;
653671
}
654672

0 commit comments

Comments
 (0)