Re: [PATCH 2/3] x86/boot: Allow to hook up alternative port I/O helpers

From: Borislav Petkov
Date: Thu Jan 20 2022 - 17:19:29 EST


On Thu, Jan 20, 2022 at 01:13:47PM -0800, Josh Poimboeuf wrote:
> This one:
>
> pio_ops = (struct port_io_ops){
> .inb = inb,
> .inw = inw,
> .inl = inl,
> .outb = outb,
> .outw = outw,
> .outl = outl,
> };
>
> .. actually allocates an anonymous struct in the .data section, which is
> memcpy'ed at runtime when the assignment occurs. That anonymous struct
> has .data -> .text relocations which have to be resolved at runtime
> because the distance between .data and .text isn't constant.

Yap, and this is the key point - decompressor kernel is a -pie
executable so it needs to resolve .data section relocations at *runtime*
but we don't have a dynamic linker during early boot.

We could patch at early boot by going through the .data runtime
relocations and patch in the target locations but that would be probably
too much just so that we can do those struct initializers.

And, I'm being told, global .data section things should be avoided, if
possible.

> The working version:
>
> pio_ops.inb = inb;
> pio_ops.inw = inw;
> pio_ops.inl = inl;
> pio_ops.outb = outb;
> pio_ops.outw = outw;
> pio_ops.outl = outl;
>
> ... only needs .text -> .text relocations which can be resolved at link
> time.

So yeah, we can simply do this and forget about it.

If someone is bored and wants to fixup such runtime relocations at,
well, runtime, sure. But until then...

Thx.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette