Re: [PATCH 4/6] arm64: pmu: Add hook to handle pmu-related undefined instructions

From: Peter Zijlstra
Date: Fri May 17 2019 - 03:12:33 EST


On Thu, May 16, 2019 at 02:21:46PM +0100, Raphael Gault wrote:
> In order to prevent the userspace processes which are trying to access
> the registers from the pmu registers on a big.LITTLE environment we
> introduce a hook to handle undefined instructions.
>
> The goal here is to prevent the process to be interrupted by a signal
> when the error is caused by the task being scheduled while accessing
> a counter, causing the counter access to be invalid. As we are not able
> to know efficiently the number of counters available physically on both
> pmu in that context we consider that any faulting access to a counter
> which is architecturally correct should not cause a SIGILL signal if
> the permissions are set accordingly.

The other approach is using rseq for this; with that you can guarantee
it will never issue the instruction on a wrong CPU.

That said; emulating the thing isn't horrible either.

> + /*
> + * We put 0 in the target register if we
> + * are reading from pmu register. If we are
> + * writing, we do nothing.
> + */

Wait _what_ ?!? userspace can _WRITE_ to these registers?