littlekernel / lk

LK embedded kernel
MIT License
3.11k stars 613 forks source link

[arch][x86] Unset x86 inner page table entry G bit #298

Closed eastmoutain closed 3 years ago

eastmoutain commented 3 years ago

The issue was initially found on AMD machine when run lk with qemu kvm, it can't boot if kvm hardware is enable in qemu.

According to Intel system programming guild Chapter 4 "Paging", if the page table entry is non-leaf entry, then the G bit will be ignored.

However, According to AMD programmer mannul Volume 2, Chapter 5.3 "Long-Mode Page Translation", the non-leaf page table entry G bit must be zero.

The patch clears inner page table entry G bit to zero so that it works on both Intel and AMD CPU

travisg commented 3 years ago

Oh thanks! I even knew about this one and forgot to apply it. Shows you how often I test x86, given that i'm largely AMD based.

eastmoutain commented 3 years ago

@travisg I found the issue nearly three years ago, and forgot to push the patch. these days am doing test on x86 virtualization, noticed the bug is flying there.

travisg commented 3 years ago

Yeah, I discovered it in the Fuchsia fork of this and fixed it there. Thought I had rolled it back but guess I had forgotten.