From: Dave Martin <Dave.Martin@arm.com>
To: Robin Murphy <robin.murphy@arm.com>
Cc: Marc Zyngier <marc.zyngier@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will.deacon@arm.com>,
linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] arm64: Trap WFI executed in userspace
Date: Tue, 7 Aug 2018 14:02:48 +0100 [thread overview]
Message-ID: <20180807130248.GH9097@e103592.cambridge.arm.com> (raw)
In-Reply-To: <da5d1650-fcd8-83ec-bd4c-02f236163776@arm.com>
On Tue, Aug 07, 2018 at 01:12:03PM +0100, Robin Murphy wrote:
> On 07/08/18 11:30, Dave Martin wrote:
> >On Tue, Aug 07, 2018 at 11:24:34AM +0100, Marc Zyngier wrote:
> >>On 07/08/18 11:05, Dave Martin wrote:
> >>>On Tue, Aug 07, 2018 at 10:33:26AM +0100, Marc Zyngier wrote:
> >>>>It recently came to light that userspace can execute WFI, and that
> >>>>the arm64 kernel doesn trap this event. This sounds rather benign,
> >>>>but the kernel should decide when it wants to wait for an interrupt,
> >>>>and not userspace.
> >>>>
> >>>>Let's trap WFI and treat it as a way to yield the CPU to another
> >>>>process.
> >>>
> >>>This doesn't amount to a justification.
> >>>
> >>>If the power controller is unexpectedly left in a bad state so that
> >>>WFI will do something nasty to a cpu that may enter userspace, then we
> >>>probably have bigger problems.
> >>>
> >>>So, maybe it really is pretty harmless to let userspace execute this.
> >>
> >>Or not. It is also a very good way for userspace to find out when an
> >>interrupt gets delivered and start doing all kind of probing on the
> >>kernel. The least the userspace knows about that, the better I feel.
> >
> >Possibly. I suspect there are other ways to guess pretty accurately
> >when an interrupt occurs, but WFI allows greater precision.
>
> ...unless you're running in a VM and it traps to KVM anyway ;)
>
> >>>I can't think of a legitimate reason for userspace to execute WFI
> >>>however. Userspace doesn't have interrupts under Linux, so it makes
> >>>no sense to wait for one.
> >>>
> >>>Have we seen anybody using WFI in userspace? It may be cleaner to
> >>>map this to SIGILL rather than be permissive and regret it later.
> >>
> >>I couldn't find any user, and I'm happy to just send userspace to hell
> >>in that case. But it could also been said that since it was never
> >>prevented, it is a de-facto ABI.
> >
> >Agreed. I wonder whether it's sufficient to have this mapping to SIGILL
> >in -next for a while and see whether anybody complains.
>
> I think we'd have to avoid that for compat, though, since v7 code would have
> the expectation that WFI can't be trapped by the kernel at all. Personally
> I'm in favour of this patch as-is, since the architectural intent of the
> instruction is essentially "I've got nothing better to do right now than
> wait for something to happen", so treating it as a poor man's sched_vield()
Congratulations for knowing what the architects intended ;)
That said, sched_yield() does seem a reasonable approximation if
we don't go for SIGILL.
Note, the patch currently maps WFI to schedule(), which is not quite
the same, though I don't understand the details.
I suspect that sched_yield() is more appropriate, since it tells the
scheduler that the task doesn't expect to run in the very near future,
whereas schedule() only tells the scheduler not to run the task right
now.
> stays close to that while mitigating the potential nefarious and/or minor
> DoS implications of letting it architecturally execute.
Agreed.
For cleanliness I still prefer SIGILL, since WFI just provides code
with a grubby, nonportable means of yielding that won't work the
same on all kernel versions anyway, whereas there is a perfectly good
standard API for yielding already.
This argument works for compat too (if a little more controversial,
due to the historial lack of a trap).
But sched_yield() is minimally invasive and highly unlikely to break
anything (even where deserved).
I wonder whether we can get the Debian folks to act as guinea-pigs
for the SIGILL approach. Their package builders are likely to be good
at finding compat regressions... May not be worth it for such a small
change though.
Cheers
---Dave
next prev parent reply other threads:[~2018-08-07 13:02 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-07 9:33 Marc Zyngier
2018-08-07 10:05 ` Dave Martin
2018-08-07 10:24 ` Marc Zyngier
2018-08-07 10:30 ` Dave Martin
2018-08-07 12:12 ` Robin Murphy
2018-08-07 13:02 ` Dave Martin [this message]
2018-08-08 12:34 ` Catalin Marinas
2018-08-09 12:34 ` Dave Martin
2018-08-09 12:38 ` Will Deacon
2018-08-09 12:47 ` Dave Martin
2018-08-09 13:25 ` Marc Zyngier
2018-09-20 22:04 ` Pavel Machek
2018-09-20 22:33 ` Marc Zyngier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180807130248.GH9097@e103592.cambridge.arm.com \
--to=dave.martin@arm.com \
--cc=catalin.marinas@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marc.zyngier@arm.com \
--cc=robin.murphy@arm.com \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®