confused about linux 64 bit LDT

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
blound
Member
Member
Posts: 70
Joined: Sat Dec 01, 2007 1:36 pm

confused about linux 64 bit LDT

Post by blound »

http://git.kernel.org/?p=linux/kernel/g ... 504c2d81fe

I saw this patch in the linux kernel and got confused.

Code: Select all

-               set_tssldt_descriptor(&ldt, (unsigned long)addr,
-                                     DESC_LDT, entries * sizeof(ldt) - 1);
+               set_tssldt_descriptor(&ldt, (unsigned long)addr, DESC_LDT,
+                                     entries * LDT_ENTRY_SIZE - 1);
the set_tssldt_descriptor function is here:
http://lxr.linux.no/linux+v2.6.25.1/inc ... esc.h#L147
LDT_ENTRY_SIZE is hardcoded to 8 not matter which arch is used
sizeof(ldt) returns 16 bytes on 64 bit and 8 bytes on 32 bit

the size of an ldt entry on 64 bit is 16 bytes while the size of ldt entry is 8 bytes on 32 bits... so doesn't it seem like the patch broke what was previously working ? its setting the size field of the LDT entry in the GDT based on ldt entries of 8 bytes no matter what the arch is. this patch has me pretty confused and I am hoping someone knows/can figure out why they would change this. It seems like this patch broke what was working and cut the 64 bit LDT table in half.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: confused about linux 64 bit LDT

Post by Brendan »

Hi,
blound wrote:the size of an ldt entry on 64 bit is 16 bytes while the size of ldt entry is 8 bytes on 32 bits... so doesn't it seem like the patch broke what was previously working ?
For long mode, 16-bit and 32-bit code descriptors, and 16-bit and 32-bit data descriptors are still 8 bytes. 64-bit code descriptors are still 8 bytes (and most of those 8 bytes are ignored because "base = 0, no limit" is assumed for 64-bit code). There are no 64-bit data descriptors (to use a 64-bit base address for FS and/or GS you need to use MSRs).

The only descriptors that are 16 bytes are gates (call gates, interrupt gates and trap gates - task gates aren't supported), and "system descriptors" (LDT descriptors and TSS descriptors). Out of these, interrupt gates and trap gates must be in the IDT, and LDT and TSS descriptors must be in the GDT.

AFAIK this leaves call gates as the only 16-byte descriptor that is allowed in the LDT. I'm guessing Linux doesn't use the LDT for call gates...

To be honest, I'm actually wondering why Linux uses any LDT for anything, ever - I can't see any reason to use an LDT if the OS doesn't support segmentation.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply