Re: [PATCH v2 3/3] rseq: optimise rseq_get_rseq_cs() and clear_rseq_cs()

From: Arjun Roy
Date: Tue Apr 13 2021 - 14:35:54 EST


On Tue, Apr 13, 2021 at 11:22 AM Eric Dumazet <edumazet@xxxxxxxxxx> wrote:
>
> On Tue, Apr 13, 2021 at 8:00 PM Mathieu Desnoyers
> <mathieu.desnoyers@xxxxxxxxxxxx> wrote:
> >
>
> > As long as the ifdefs are localized within clearly identified wrappers in the
> > rseq code I don't mind doing the special-casing there.
> >
> > The point which remains is that I don't think we want to optimize for speed
> > on 32-bit architectures when it adds special-casing and complexity to the 32-bit
> > build. I suspect there is less and less testing performed on 32-bit architectures
> > nowadays, and it's good that as much code as possible is shared between 32-bit and
> > 64-bit builds to share the test coverage.
> >
>
> Quite frankly V1 was fine, I can't really make it looking better.
>
> > Thanks,
> >
> > Mathieu
> >
> > >
> > >
> > >>
> > >> Thanks,
> > >>
> > >> Mathieu
> > >>

If we're special-casing 64-bit architectures anyways - unrolling the
32B copy_from_user() for struct rseq_cs appears to be roughly 5-10%
savings on x86-64 when I measured it (well, in a microbenchmark, not
in rseq_get_rseq_cs() directly). Perhaps that could be an additional
avenue for improvement here.

-Arjun

> > >> >
> > >> > diff --git a/kernel/rseq.c b/kernel/rseq.c
> > >> > index
> > >> > f2eee3f7f5d330688c81cb2e57d47ca6b843873e..537b1f684efa11069990018ffa3642c209993011
> > >> > 100644
> > >> > --- a/kernel/rseq.c
> > >> > +++ b/kernel/rseq.c
> > >> > @@ -136,6 +136,10 @@ static int rseq_get_cs_ptr(struct rseq_cs __user **uptrp,
> > >> > {
> > >> > u32 ptr;
> > >> >
> > >> > + if (get_user(ptr, &rseq->rseq_cs.ptr.padding))
> > >> > + return -EFAULT;
> > >> > + if (ptr)
> > >> > + return -EINVAL;
> > >> > if (get_user(ptr, &rseq->rseq_cs.ptr.ptr32))
> > >> > return -EFAULT;
> > >> > *uptrp = (struct rseq_cs __user *)ptr;
> > >> > @@ -150,8 +154,9 @@ static int rseq_get_rseq_cs(struct task_struct *t,
> > >> > struct rseq_cs *rseq_cs)
> > >> > u32 sig;
> > >> > int ret;
> > >> >
> > >> > - if (rseq_get_cs_ptr(&urseq_cs, t->rseq))
> > >> > - return -EFAULT;
> > >> > + ret = rseq_get_cs_ptr(&urseq_cs, t->rseq);
> > >> > + if (ret)
> > >> > + return ret;
> > >> > if (!urseq_cs) {
> > >> > memset(rseq_cs, 0, sizeof(*rseq_cs));
> > >> > return 0;
> > >> > @@ -237,7 +242,8 @@ static int clear_rseq_cs(struct task_struct *t)
> > >> > #ifdef CONFIG_64BIT
> > >> > return put_user(0UL, &t->rseq->rseq_cs.ptr64);
> > >> > #else
> > >> > - return put_user(0UL, &t->rseq->rseq_cs.ptr.ptr32);
> > >> > + return put_user(0UL, &t->rseq->rseq_cs.ptr.ptr32) |
> > >> > + put_user(0UL, &t->rseq->rseq_cs.ptr.padding);
> > >> > #endif
> > >> > }
> > >>
> > >> --
> > >> Mathieu Desnoyers
> > >> EfficiOS Inc.
> > > > http://www.efficios.com
> >
> > --
> > Mathieu Desnoyers
> > EfficiOS Inc.
> > http://www.efficios.com