Re: [tip:perfcounters/core] perf_counter: x86: Fix call-chainsupport to use NMI-safe methods

From: Mathieu Desnoyers
Date: Mon Jun 15 2009 - 23:05:38 EST


* H. Peter Anvin (hpa@xxxxxxxxx) wrote:
> Mathieu Desnoyers wrote:
> >
> > Where is the kernel page fault handler grabbing any lock to service
> > in-kernel page faults exactly ?
> >
> > Those are usually considered as utterly simple page table fixups,
> > nothing more.
> >
>
> It doesn't, *because it doesn't have to*. Your proposal requires that
> page faults can be handled inside the page fault handler, and that's a
> pretty tall order.
>
> -hpa
>

I am not asking for the pf handler to handle every possible kind of
fault recursively. Just to keep the in-kernel page fault related code
for vmalloc (and possibly for prefetch ?) paths NMI-reentrant :

void do_page_fault(struct pt_regs *regs, unsigned long error_code)

address = read_cr2();

if (unlikely(kmmio_fault(regs, address)))
return;

#ifdef CONFIG_X86_32
if (unlikely(address >= TASK_SIZE)) {
#else
if (unlikely(address >= TASK_SIZE64)) {
#endif
if (!(error_code & (PF_RSVD|PF_USER|PF_PROT)) &&
vmalloc_fault(address) >= 0)
return;

/* Can handle a stale RO->RW TLB */
if (spurious_fault(address, error_code))
return;

/* kprobes don't want to hook the spurious faults. */
if (notify_page_fault(regs))
return;
/*
* Don't take the mm semaphore here. If we fixup a prefetch
* fault we could otherwise deadlock.
*/
goto bad_area_nosemaphore;
}

This includes vmalloc_fault. Note that I already looked into
vmalloc_fault to ensure it could handle NMIs on x86_64 as well. See
commit bdd5ea31e79fed76eb57d0cd797355267f4f4a8c. It seems I missed the
cr2 register issue though. I assumed NMI handler to save it somehow,
which ends up not being the case.

Mathieu




--
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F BA06 3F25 A8FE 3BAE 9A68
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/