At the moment, all the places where the LDT are set in the kernel are of the form: set_ldt_desc(cpu, segments, count); load_LDT_desc(); (two instances in asm-i386/desc.h). set_ldt_desc() sets an LDT descriptor in the GDT, and load_LDT_desc() is basically just lldt. These map to the write_gdt_entry and load_ldt_desc paravirt ops. This doesn't work well for Xen, because you set the ldt directly by passing the base+size into the hypervisor. In fact, it doesn't allow you to set an LDT-type descriptor into the GDT, so this current interface requires the Xen backend to decode the descriptor passed to write_gdt_entry, look to see if its an LDT; if so, store the base+size somewhere, and then when load_ldt_desc() is called, do the appropriate Xen hypercall. A better interface for us would be simply: set_ldt(const struct desc_struct *ldt, int num_entries); since this maps directly to the appropriate Xen hypercall. If you still want to implement it by plugging the LDT descriptor into the GDT and then lldt, then there's no reason you can't implement it that way. Thoughts? J
Jeremy Fitzhardinge wrote:> A better interface for us would be simply: > > set_ldt(const struct desc_struct *ldt, int num_entries); > > since this maps directly to the appropriate Xen hypercall. If you > still want to implement it by plugging the LDT descriptor into the GDT > and then lldt, then there's no reason you can't implement it that way. > > Thoughts?This interface doesn't work for anything other than Xen. It is impossible to implement it without specific knowledge of kernel internals, since it doesn't provide the GDT selector for the LDT. Now everything that looks like real hardware needs to move the knowledge of the LDT structure into paravirt-ops, and it has no clear calling convention, so you've now got to reason about SMP preemption correctness inside the paravirt-op, instead of at the higher level where it should be done. This is an example of one place where Xen has broken the x86 architecture in favor of a simpler implementation of the hypervisor, but a radical change to the kernel. It is one of the reasons why XenoLinux as implemented is unable to boot on native hardware. I would strongly prefer if we didn't introduce this ugliness into paravirt-ops. Zach