Re: [PATCH 08/62] x86/boot/compressed/64: Add IDT Infrastructure

From: Joerg Roedel
Date: Sat Feb 15 2020 - 07:33:03 EST


On Fri, Feb 14, 2020 at 11:40:36AM -0800, Andi Kleen wrote:
> Joerg Roedel <joro@xxxxxxxxxx> writes:
> > + addq $8, %rsp
> > +
> > + /*
> > + * Make sure we return to __KERNEL_CS - the CS selector on
> > + * the IRET frame might still be from an old BIOS GDT
> > + */
> > + movq $__KERNEL_CS, 8(%rsp)
>
> This doesn't make sense. Either it's running on the correct CS
> before the exception or not. Likely there's some other problem
> here that you patched over with this hack.

It is actually a well-known situation and not some other problem. The
boot-code loaded a new GDT and IDT, but did not reload CS with a far
jump/ret/call. The CS value loaded is undefined and comes from the UEFI
BIOS. When an exception is raised, this old CS value is stored in the
IRET frame, and when IRET is executed the processor loads an undefined
CS value, which causes a triple fault with the current IDT setup.

The hack in this patch just fixes the IRET frame up so that it will
return to the correct CS. The reason for this hack was actually to safe
some instructions in the boot-path, because the space is limited there
between the defined offsets of the various entry points.

I removed this hack meanwhile and added a separate function which
reloads CS, DS, SS and ES and which is called from the boot-path, so
that there is no problem with the offsets.

Regards,

Joerg