Re: [PATCH 20/22] x86,word-at-a-time: Remove .fixup usage

From: Peter Zijlstra
Date: Fri Nov 05 2021 - 14:11:41 EST


On Fri, Nov 05, 2021 at 11:01:52AM -0700, Josh Poimboeuf wrote:
> On Fri, Nov 05, 2021 at 06:10:43PM +0100, Peter Zijlstra wrote:
> > +#ifdef CONFIG_CC_HAS_ASM_GOTO_OUTPUT
> > +
> > +static inline unsigned long load_unaligned_zeropad(const void *addr)
> > +{
> > + unsigned long offset, data;
> > + unsigned long ret;
> > +
> > + asm_volatile_goto(
> > + "1: mov %[mem], %[ret]\n"
> > +
> > + _ASM_EXTABLE(1b, %l[do_exception])
> > +
> > + : [ret] "=&r" (ret)
> > + : [mem] "m" (*(unsigned long *)addr)
> > + : : do_exception);
> > +
> > +out:
> > + return ret;
> > +
> > +do_exception: __cold;
> > +
> > + offset = (unsigned long)addr & (sizeof(long) - 1);
> > + addr = (void *)((unsigned long)addr & ~(sizeof(long) - 1));
> > + data = *(unsigned long *)addr;
> > + ret = data >> offset * 8;
> > + goto out;
>
> Superfluous goto, can just return here?

Can do I suppose.

> > static inline unsigned long load_unaligned_zeropad(const void *addr)
> > {
> > - unsigned long ret, dummy;
> > + unsigned long offset, data;
> > + unsigned long ret, err = 0;
> >
> > - asm(
> > - "1:\tmov %2,%0\n"
> > + asm( "1: mov %[mem], %[ret]\n"
> > "2:\n"
> > - ".section .fixup,\"ax\"\n"
> > - "3:\t"
> > - "lea %2,%1\n\t"
> > - "and %3,%1\n\t"
> > - "mov (%1),%0\n\t"
> > - "leal %2,%%ecx\n\t"
> > - "andl %4,%%ecx\n\t"
> > - "shll $3,%%ecx\n\t"
> > - "shr %%cl,%0\n\t"
> > - "jmp 2b\n"
> > - ".previous\n"
> > - _ASM_EXTABLE(1b, 3b)
> > - :"=&r" (ret),"=&c" (dummy)
> > - :"m" (*(unsigned long *)addr),
> > - "i" (-sizeof(unsigned long)),
> > - "i" (sizeof(unsigned long)-1));
> > +
> > + _ASM_EXTABLE_FAULT(1b, 2b)
> > +
> > + : [ret] "=&r" (ret), "+a" (err)
> > + : [mem] "m" (*(unsigned long *)addr));
> > +
> > + if (unlikely(err)) {
> > + offset = (unsigned long)addr & (sizeof(long) - 1);
> > + addr = (void *)((unsigned long)addr & ~(sizeof(long) - 1));
> > + data = *(unsigned long *)addr;
> > + ret = data >> offset * 8;
> > + }
> > +
> > return ret;
>
> This adds a (normally not taken) conditional jump, would a straight jmp
> over the fixup not be better?
>
> i.e.
>
> 1: mov %[mem], %[ret]
> jmp 2
> ... fixup code ...
> 2:

I really don't know, this way we can get the bulk of the text
out-of-line.