History

sparc64: Ensure perf can access user stacks

When an interrupt (such as a perf counter interrupt) is delivered while executing in user space, the trap entry code puts ASI_AIUS in %asi so that copy_from_user() and copy_to_user() will access the correct memory. But if a perf counter interrupt is delivered while the cpu is already executing in kernel space, then the trap entry code will put ASI_P in %asi, and this will prevent copy_from_user() from reading any useful stack data in either of the perf_callchain_user_X functions, and thus no user callgraph data will be collected for this sample period. An additional problem is that a fault is guaranteed to occur, and though it will be silently covered up, it wastes time and could perturb state. In perf_callchain_user(), we ensure that %asi contains ASI_AIUS because we know for a fact that the subsequent calls to copy_from_user() are intended to read the user's stack. [ Use get_fs()/set_fs() -DaveM ]

Rob Gardner committed 10 years ago

Commit 3f743061 parent 1ca04a41 file · +7 −0Browse files

Unified · Split

arch/sparc/kernel/perf_event.c+7−0
@@ -1828,11 +1828,16 @@ static void perf_callchain_user_32(struct perf_callchain_entry *entry, · 1827 unmodified lines
1828void1828void
1829perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)1829perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
1830{1830{
1831 mm_segment_t old_fs;
1832
1831 perf_callchain_store(entry, regs->tpc);1833 perf_callchain_store(entry, regs->tpc);
1832 1834
1833 if (!current->mm)1835 if (!current->mm)
1834 return;1836 return;
1835 1837
1838 old_fs = get_fs();
1839 set_fs(USER_DS);
1840
1836 flushw_user();1841 flushw_user();
1837 1842
1838 pagefault_disable();1843 pagefault_disable();
@@ -1843,4 +1848,6 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs) · 4 unmodified lines
1843 perf_callchain_user_64(entry, regs);1848 perf_callchain_user_64(entry, regs);
1844 1849
1845 pagefault_enable();1850 pagefault_enable();
1851
1852 set_fs(old_fs);
1846}1853}