tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

x86: move the LAPIC va



On x86 there's a set of memory-mapped registers that are per-cpu and called the
LAPIC. They reside at a fixed one-page-sized physical address, and in order to
read or write to them the kernel has to allocate a virtual address and then
kenter it to the aforementioned physical one.

In the NetBSD kernel, however, we do something a little bizarre: instead of
following this model, the kernel has a blank page at the beginning of the data
segment, and it then directly kenters the va of this page into the LAPIC pa.

The issue with this design is that it implies the first page of .data does not
actually belong to .data, and therefore it is not possible to map the beginning
of .data with large pages. In addition to this, without going into useless
details, it creates an inconsistency in the low memory map, because the pa<->va
translation is not linear, even if it seemingly is harmless.

I have a patch that moves the LAPIC va out of the kernel data segment into
dynamically-allocated memory. This patch adds a necessary level of indirection,
because we go from using &local_apic to using *local_apic, and we thus need an
additional instruction in the asm parts.

It works like this: when the kernel boots, pmap_bootstrap allocates one virtual
page, and sets the lapic_xx variables accordingly. Later, at some point, mainbus
is attached, lapic_map is called and the virtual page that we allocated is
manually kentered into the LAPIC pa. Then, the secondary CPUs are launched, and
they use their respective LAPIC directly from memory, since the va is mapped in
pmap_kernel and already available.

The patch is available here [1]. Clearly, I'm not going to commit it now, but
if someone here has an opinion about it, or if you think there is something
obviously wrong that I missed, feel free to tell me about it.

[1] http://m00nbsd.net/garbage/lapic/


Home | Main Index | Thread Index | Old Index