Re: [RFC][PATCH v2 5/5] sched: User Mode Concurency Groups

Mark Rutland
2022-01-24T10:27:45Z

On Mon, Jan 24, 2022 at 11:07:04AM +0100, Peter Zijlstra wrote:
> On Mon, Jan 24, 2022 at 11:03:06AM +0100, Peter Zijlstra wrote:
>
> > > Either way, it looks like we'd need helpers along the lines of:
> > >
> > > | static __always_inline void umcg_enter_from_user(struct pt_regs *regs)
> > > | {
> > > | if (current->flags & PF_UMCG_WORKER)
> > > | umcg_sys_enter(regs, -1);
> > > | }
> > > |
> > > | static __always_inline void umcg_exit_to_user(struct pt_regs *regs)
> > > | {
> > > | if (current->flags & PF_UMCG_WORKER)
> > > | umcg_sys_exit(regs);
> > > | }
> >
> > Would something like:
> >
> > #ifndef arch_irqentry_irq_enter
> > static __always_inline bool arch_irqentry_irq_enter(struct pt_regs *regs)
> > {
> > if (!regs_irqs_disabled(regs)) {
> > local_irq_enable();
> > return true;
> > }
> > return false;
> > }
> > #endif
> >
> > static __always_inline void irqentry_irq_enter(struct pt_regs *regs)
> > {
> > if (arch_irqentry_irq_inherit(regs)) {
> > if (user_mode(regs) && (current->flags & PF_UMCG_WORKER))
> > umcg_sys_enter(regs, -1);
> > }
> > }
> >
> > Work? Then arm64 can do:
> >
> > static __always_inline bool arch_irqentry_irq_enter(struct pt_regs *regs)
> > {
> > local_daif_inherit();
> > return interrupts_enabled(regs);
> > }
> >
> > or somesuch...
>
> Ah,.. just read your other email, so your concern is about the
> user_mode() thing due to ARM64 taking a different exception path for
> from-user vs from-kernel ?

Yup; it's two-fold:

1) We have separate vectors for entry from-user and from-kernel, and I'd like
to avoid the conditionality (e.g. the user_mode(regs) checks) where possible.
Having that unconditional and explicit in the from-user code avoids
redundant work and is much easier to see that it's correct and balanced.

We have separate irqentry_from_user() and irqentry_from_kernel() helpers
today for this.

2) Due to the way we nest classes of exception, on the entry path we manipulate
the flags differently depending on which specific exception we've taken. On
the return path we always mask everything (necessary due to the way
exception return works architecturally).

Luckily exceptions from-user don't nest, so those cases are simpler than
exceptions from-kernel.

> I don't mind too much if arm64 decides to open-code the umcg hooks, but
> please do it such that's hard to forget a spot.

I'll see what I can do. :)

Thanks,
Mark.