Skip to contentSkip to conversation

Assignment of GDT entries

DISCUSSION Jeremy Fitzhardinge 8 participants 19 messages Sep 13, 2006 – Sep 14, 2006

lore
Share & tools
lore
#0 lore raw

What's the rationale for the current assignment of GDT entries? In particular, this section:

*   0 - null
*   1 - reserved
*   2 - reserved
*   3 - reserved

*
* 4 - unused <==== new cacheline
* 5 - unused
*
* ------- start of TLS (Thread-Local Storage) segments:
*

*   6 - TLS segment #1			[ glibc's TLS segment ]
*   7 - TLS segment #2			[ Wine's %fs Win32 segment ]
*   8 - TLS segment #3
*   9 - reserved

* 10 - reserved
* 11 - reserved

What are entries 1-3 and 9-11 reserved for? Must they be unused for some reason, or is there some proposed use that has not been impemented yet?

Also, is there a particular reason kernel GDT entries start at 12? Would there be a problem in using either 4 or 5 for a kernel GDT descriptor?

I'm asking because I'd like to use one of these entries for the PDA descriptor, so that it is on the same cache line as the TLS descriptors. That way, the entry/exit segment register reloads would still only need to touch two GDT cache lines. Would there be a real problem in doing this?

Thanks,
J

#1 lore raw
Quoted 17 lines · Jeremy Fitzhardinge

What's the rationale for the current assignment of GDT entries? In particular, this section:

 *   0 - null
 *   1 - reserved
 *   2 - reserved
 *   3 - reserved
 *
 *   4 - unused			<==== new cacheline
 *   5 - unused
 *
 *  ------- start of TLS (Thread-Local Storage) segments:
 *
 *   6 - TLS segment #1			[ glibc's TLS segment ]
 *   7 - TLS segment #2			[ Wine's %fs Win32 segment ]
 *   8 - TLS segment #3
 *   9 - reserved
Quoted 6 lines

* 10 - reserved
* 11 - reserved

What are entries 1-3 and 9-11 reserved for? Must they be unused for some reason, or is there some proposed use that has not been impemented yet?

I don't know the exact details on these; I do know that several GDT entries tend to be used by BIOSes in their APM implementations and thus are better of not being used. That might be the underlying reason here....

#2 lore raw

Ar Mer, 2006-09-13 am 21:16 +0200, ysgrifennodd Arjan van de Ven:

Quoted 3 lines

I don't know the exact details on these; I do know that several GDT entries tend to be used by BIOSes in their APM implementations and thus are better of not being used.

Thats 0x40 which tends to get used as if was a real mode base for BIOS accesses even via the protected mode interface.

Alan

#3 lore raw
Quoted 10 lines · Alan Cox

Ar Mer, 2006-09-13 am 21:16 +0200, ysgrifennodd Arjan van de Ven:

Quoted 4 lines

I don't know the exact details on these; I do know that several GDT entries tend to be used by BIOSes in their APM implementations and thus are better of not being used.

Thats 0x40 which tends to get used as if was a real mode base for BIOS accesses even via the protected mode interface.

Do you mean descriptor entry 8? Because that's TLS #3, not reserved...

J

#4 lore raw
In reply to Arjan van de Ven
Quoted 5 lines · Arjan van de Ven

I don't know the exact details on these; I do know that several GDT entries tend to be used by BIOSes in their APM implementations and thus are better of not being used. That might be the underlying reason here....

Hm, I see.

Also, thinking about this a bit more, it would be most helpful to move the PDA descriptor onto the same cache line as the other descriptors used in the kernel - ie, somewhere in the range of 8-15 (assuming 64 byte line size):

* 8 - TLS segment #3
* 9 - reserved
* 10 - reserved
* 11 - reserved
*
* ------- start of kernel segments:
*

*  12 - kernel code segment
*  13 - kernel data segment
*  14 - default user CS
*  15 - default user DS

This seems pretty wasteful of the GDT cache line, since the kernel+user cs/ds are shared a cache line with 3 reserved entries and the never-used TLS #3 descriptor. If it were OK to put the PDA in one of 9,10,11, then that would be good. Unfortunately the next cache line is clogged up with PNP and APM stuff, which I presume not movable.

In fact, if we assume that "reserved" means "unusable", it looks like none of the GDT's cache lines can be freed up to lay out the most commonly used descriptors into a single cache line:

line 0: NULL descriptor, 3 reserved, 2 unused, 2 TLS line 1: 1 TLS, 3 reserved, kernel+user code+data line 2: TSS, LDT, PNPBIOS, APMBIOS
line 3: APMBIOS, ESPFIX, 4 unused, doublefault TSS

Otherwise line 1 would be ideal for putting 3 TLS, kernel+user code+data and PDA into, thereby making 99.999% of GDT descriptor uses come from one cache line.

But anyway, what breaks if I put the PDA in 11?

J

#5 lore raw
Quoted 18 lines · Jeremy Fitzhardinge
Quoted 5 lines · Arjan van de Ven

I don't know the exact details on these; I do know that several GDT entries tend to be used by BIOSes in their APM implementations and thus are better of not being used. That might be the underlying reason here....

Hm, I see.

Also, thinking about this a bit more, it would be most helpful to move the PDA descriptor onto the same cache line as the other descriptors used in the kernel - ie, somewhere in the range of 8-15 (assuming 64 byte line size):

* 8 - TLS segment #3
* 9 - reserved
* 10 - reserved
* 11 - reserved
*
* ------- start of kernel segments:
*

Quoted 6 lines
*  12 - kernel code segment
*  13 - kernel data segment
*  14 - default user CS
*  15 - default user DS

This seems pretty wasteful of the GDT cache line, since the kernel+user cs/ds are shared a cache line with 3 reserved entries and the never-used TLS #3 descriptor. If it were OK to put the PDA in one of 9,10,11, then that would be

TLS #3 overlaps BIOS 0x40, but code which calls borken APM / PnP BIOS and sets up protected mode 0x40 GDT segment does so by swapping out the TLS segment with the identity simulation of physical 0x400 offset, swapping it back afterwards. Short of bugs in that code (which there are, btw), you shouldn't need to be concerned with it.

I believe 9,10,11 are reserved for future users like yourself or expanded TLS segments. I think a bank of 3 TLS segments in the GDT is working fine now (does NPTL even use more than one?).

Quoted 1 line

good. Unfortunately the next cache line is clogged up with PNP and APM stuff, which I presume not movable.

Totally movable, actually, just means breaking module dependencies.

Quoted 9 lines

In fact, if we assume that "reserved" means "unusable", it looks like none of the GDT's cache lines can be freed up to lay out the most commonly used descriptors into a single cache line:

line 0: NULL descriptor, 3 reserved, 2 unused, 2 TLS line 1: 1 TLS, 3 reserved, kernel+user code+data line 2: TSS, LDT, PNPBIOS, APMBIOS
line 3: APMBIOS, ESPFIX, 4 unused, doublefault TSS

Otherwise line 1 would be ideal for putting 3 TLS, kernel+user code+data and PDA into, thereby making 99.999% of GDT descriptor uses come from one cache line.

That change is visible to userspace, unfortunately.

Quoted 2 lines

But anyway, what breaks if I put the PDA in 11?

Nothing.

Zach

#6 lore raw

Ar Mer, 2006-09-13 am 13:59 -0700, ysgrifennodd Zachary Amsden:

Quoted 5 lines

TLS #3 overlaps BIOS 0x40, but code which calls borken APM / PnP BIOS and sets up protected mode 0x40 GDT segment does so by swapping out the TLS segment with the identity simulation of physical 0x400 offset, swapping it back afterwards. Short of bugs in that code (which there are, btw), you shouldn't need to be concerned with it.

Care to elucidate ?

#7 lore raw
Quoted 7 lines · Alan Cox

Ar Mer, 2006-09-13 am 13:59 -0700, ysgrifennodd Zachary Amsden:

Quoted 2 lines

TLS #3 overlaps BIOS 0x40, but code which calls borken APM / PnP BIOS and sets up protected mode 0x40 GDT segment does so by swapping out the TLS segment with the identity simulation of physical 0x400 offset, swapping it back afterwards. Short of bugs in that code (which there are, btw), you shouldn't need to be concerned with it.

Care to elucidate ?

I believe the current max use case for GDT descriptors is Wine. Wine compiled against TLS glibc uses entry zero for libc, and allocates another GDT entry for the first thread created by NTDLL (although I have no idea why, since there is fallback code to use LDT allocation instead, and all subsequent allocations happen via the LDT - perhaps some kernel mode DLL thing insists on having the first thread in the GDT?) DOSemu by the way, only uses the LDT.

But there is no reason userspace can't allocate 3 TLS descriptors in the GDT per thread. If it did, the overlap between 0x40 (descriptor #8, real mode BIOS simulation of physical address 0x400, BIOS data area) causes a problem. Fortunately, APM and PnP take care to fix this by swapping in and out the descriptors. Unfortunately, they don't get it quite right.

Selected code snippets (PnP):

       /*
        * PnP BIOSes are generally not terribly re-entrant.
        * Also, don't rely on them to save everything correctly.
        */
       if(pnp_bios_is_utter_crap)
               return PNP_FUNCTION_NOT_SUPPORTED;

       cpu = get_cpu();
       save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
       get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;   <---- set up 

fake BIOS descriptor for 0x400

       /* On some boxes IRQ's during PnP BIOS calls are deadly.  */
       spin_lock_irqsave(&pnp_bios_lock, flags);

... now inline assembler

               "pushl %%fs\n\t"
               "pushl %%gs\n\t"
               "pushfl\n\t"
               "movl %%esp, pnp_bios_fault_esp\n\t"
               "movl $1f, pnp_bios_fault_eip\n\t"
               "lcall %5,%6\n\t"
               "1:popfl\n\t"
               "popl %%gs\n\t"   <---- (**)
               "popl %%fs\n\t"    <---- (**)

... now restore original GDT descriptor back

       spin_unlock_irqrestore(&pnp_bios_lock, flags);

       get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
       put_cpu();

But it is too late - damage is already done (at **), since %fs or %gs could have had a reference to TLS descriptor #3, and they get reloaded _before_ the GDT is restored. Thus any userspace process that uses TLS descriptor #3 in FS or GS and makes a BIOS call to PnP may get corrupted data loaded into the hidden state of FS / GS selectors.

APM has a similar problem. Both are easily fixable, but there has been too much flux in this area recently to get a stable patch for these problems, and the problems are exceedingly unlikely, since I don't know of a single userspace program using TLS descriptor #3, much less one that makes use of APM or PnP facilities. There is the possibility however, that such a program could sleep, run the idle thread, which makes a call into some of these BIOS facilities, and then reschedules the same program thread - which means FS/GS never get reloaded, thus maintaining their corrupted values. It is worth fixing, just not a high priority. I had a patch that fixed both APM and PnP at one time, but it is covered with mold and now looks like a science experiment. Shall I apply disinfectant?

Zach

#8 lore raw
Quoted 5 lines · On Wed, 13 Sep 2006 17:25:53 -0700 Zachary Amsden <[email protected]> wrote:

It is worth fixing, just not a high
priority. I had a patch that fixed both APM and PnP at one time, but it is covered with mold and now looks like a science experiment. Shall I apply disinfectant?

Yes, please.

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
#9 lore raw
In reply to Zachary Amsden

Ar Mer, 2006-09-13 am 17:25 -0700, ysgrifennodd Zachary Amsden:

Quoted 8 lines

that makes use of APM or PnP facilities. There is the possibility however, that such a program could sleep, run the idle thread, which makes a call into some of these BIOS facilities, and then reschedules the same program thread - which means FS/GS never get reloaded, thus maintaining their corrupted values. It is worth fixing, just not a high priority. I had a patch that fixed both APM and PnP at one time, but it is covered with mold and now looks like a science experiment. Shall I apply disinfectant?

I think that would be useful, or just post up the mouldy one for someone else to rework. If someone is hitting that kind of bug its going to be pretty horrible to track down.

#10 lore raw
In reply to Zachary Amsden
Quoted 1 line · Zachary Amsden

I believe 9,10,11 are reserved for future users like yourself or expanded TLS segments. I think a bank of 3 TLS segments in the GDT is working fine now (does NPTL even use more than one?).

Nope. And there's a comment that wine uses one more. I think the third is completely unused.

Does this mean that "reserved" is actually synonymous with "unused" in asm/segment.h?

Quoted 3 lines
Quoted 1 line

Otherwise line 1 would be ideal for putting 3 TLS, kernel+user code+data and PDA into, thereby making 99.999% of GDT descriptor uses come from one cache line.

That change is visible to userspace, unfortunately.

Don't think it matters much. 32-bit processes on x86-64 seem perfectly happy with the TLS being in a different place. I think the ABI is defined in terms of "use the selector for the entry that set_thread_area/clone returns", and so is not a constant. But I agree it would be better not to.

Hm, moving user cs/ds would be pretty visible too... Hm, and it would have a greater chance of breaking stuff if they changed, compared to moving the TLS...

So is there any reason for "kernel entries start at 12"? If there's no reason for it, then we can pack everything useful into 1-5.

Quoted 3 lines
Quoted 1 line

But anyway, what breaks if I put the PDA in 11?

Nothing.

OK then.

J

#11 lore raw
In reply to Jeremy Fitzhardinge
Quoted 17 lines · Jeremy Fitzhardinge

What's the rationale for the current assignment of GDT entries? In particular, this section:

*   0 - null
*   1 - reserved
*   2 - reserved
*   3 - reserved

*
* 4 - unused <==== new cacheline
* 5 - unused
*
* ------- start of TLS (Thread-Local Storage) segments:
*

*   6 - TLS segment #1			[ glibc's TLS segment ]
*   7 - TLS segment #2			[ Wine's %fs Win32 segment ]
*   8 - TLS segment #3
*   9 - reserved
Quoted 7 lines

* 10 - reserved
* 11 - reserved

What are entries 1-3 and 9-11 reserved for? Must they be unused for some reason, or is there some proposed use that has not been impemented yet?

In the ix86, the first descriptor in the GDT is not used. The are TWO 32-bits words for each GDT entry. The GDT numbers are the offset from the first, so they are numbered as offsets, there are multiplied by 8, the size of a GDT, by the processor when they are used to set segment registers. This table is only accessed by the CPU when the LGDT instruction in executed. When a segment register is set, the invisible part of the segment, the top 16 bits, contains the information extracted from the GDT, so no further access is necessary. This means that it has nothing to do with cache-lines.

The entries 1 through 3 are used during the boot sequence, see setup.S, search for "gdt" around line 983.

Quoted 9 lines

Also, is there a particular reason kernel GDT entries start at 12? Would there be a problem in using either 4 or 5 for a kernel GDT descriptor?

I'm asking because I'd like to use one of these entries for the PDA descriptor, so that it is on the same cache line as the TLS descriptors. That way, the entry/exit segment register reloads would still only need to touch two GDT cache lines. Would there be a real problem in doing this?

You can add other GDT entries up to 8192 if you want. If you set the base, limit, type, etc., to something that's different than the kernel DS, SS, CS, etc., then you need to reload the segment registers and if the base is different, the code offset will be WRONG so you will need to tell the linker the new relocation information.

I can't imagine a reason why you'd want to do this.

Quoted 3 lines

Thanks,
J

Cheers,
Dick Johnson
Penguin : Linux version 2.6.16.24 on an i686 machine (5592.66 BogoMips). New book: http://www.AbominableFirebug.com/
_


****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.

#12 lore raw
Quoted 3 lines · linux-os (Dick Johnson)

The entries 1 through 3 are used during the boot sequence, see setup.S, search for "gdt" around line 983.

OK, but that's an early GDT used during boot, which shouldn't have any bearing on the GDT of the running kernel.

Quoted 2 lines

I can't imagine a reason why you'd want to do this.

I'm looking at packing all the descriptors together so they share a cache line, and therefore reduce the likelihood of a cache miss when loading a segment register.

J

#13 lore raw
Quoted 8 lines · Jeremy Fitzhardinge
Quoted 3 lines · linux-os (Dick Johnson)

The entries 1 through 3 are used during the boot sequence, see setup.S, search for "gdt" around line 983.

OK, but that's an early GDT used during boot, which shouldn't have any bearing on the GDT of the running kernel.

Quoted 8 lines
Quoted 2 lines

I can't imagine a reason why you'd want to do this.

I'm looking at packing all the descriptors together so they share a cache line, and therefore reduce the likelihood of a cache miss when loading a segment register.

J

You can certainly see if what you do works, but the last time I looked, you need the linear address-space mapped by these to load a new GDT, which needs to be untranslated in the TLB (unity mapped). You can also search the kernel to see if they are required to get into and get out of VM86 mode, for the dosemu users. Basically, you need to change to what you want, see if it boots, then test everything that might use these entries. It's scary and a lot of work, probably the reason why nobody's bothered to muck with the GDT. There is also a "specific" entry, used for pseudo-real mode to access the BIOS for some APM stuff. I don't remember the number, but that shouldn't be changed because the BIOS hard-codes it for setting segments.

Cheers,
Dick Johnson
Penguin : Linux version 2.6.16.24 on an i686 machine (5592.66 BogoMips). New book: http://www.AbominableFirebug.com/
_


****************************************************************
The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to [email protected] - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.

#14 lore raw
In reply to Jeremy Fitzhardinge
Quoted 3 lines · Jeremy Fitzhardinge

*
* 4 - unused <==== new cacheline
* 5 - unused

These _used_ to be the "user CS/DS" respectively, but that got changed around by me when did the "sysenter" support.

The sysenter logic (or, more properly, the sysexit one) requires that the user code segment number is the same as the kernel code segment +2 (ie "+16" in actual selector term). And the user data segment needs to be +3.

So with sysenter, we needed a block of four contiguous segments: kernel code, kernel data, user code, user data (in that order).

There are other possible things to do, but what we did was to move the user segments up to just above the kernel ones (which we left in place).

Quoted 6 lines
*   6 - TLS segment #1			[ glibc's TLS segment ]
*   7 - TLS segment #2			[ Wine's %fs Win32 segment ]
*   8 - TLS segment #3
*   9 - reserved

* 10 - reserved
* 11 - reserved

These are really reserved, I think we left them that way on purpose so that if we wanted to, we can allow more of the contiguous per-thread state. And segment #8 (ie 0x40) is special (TLS segment #3), of course. Anybody who wants to emulate windows or use the BIOS needs to use that for their "common BIOS area" thing, iirc.

I think it's generally a good idea to keep the low segment reserved (or at least free to use for whatever user code), since if there are any special magic segment descriptor numbers, they tend to be in that low range. The #8/0x40 thing is just an example.

Quoted 5 lines

What are entries 1-3 and 9-11 reserved for? Must they be unused for some reason, or is there some proposed use that has not been impemented yet?

Also, is there a particular reason kernel GDT entries start at 12? Would there be a problem in using either 4 or 5 for a kernel GDT descriptor?

See above. The kernel and user segments have to be moved as a block of four, and obviously we'd like to keep them in the same cacheline too. Also, the cacheline that contains segment #8/0x40 is not available, so that together with keeping low segments for user space explains why it's at segment numbers #12-15 (selectors 0x60/0x68/0x73/0x7b).

But I don't think anything but 0x40 is "set in stone".

Linus

#15 lore raw
Quoted 2 lines · Linus Torvalds

These _used_ to be the "user CS/DS" respectively, but that got changed around by me when did the "sysenter" support.

So does this mean that moving the user-visible cs/ds isn't likely to break stuff, if it has been done before?

Quoted 2 lines

The sysenter logic (or, more properly, the sysexit one) requires that the user code segment number is the same as the kernel code segment +2 (ie "+16" in actual selector term). And the user data segment needs to be +3.

Yep, I'm aware of that constraint.

Quoted 2 lines

And segment #8 (ie 0x40) is special (TLS segment #3), of course. Anybody who wants to emulate windows or use the BIOS needs to use that for their "common BIOS area" thing, iirc.

Do you mean that something like dosemu/Wine needs to be able to use GDT #8? Or is it only used in kernel code?

Quoted 1 line

See above. The kernel and user segments have to be moved as a block of four, and obviously we'd like to keep them in the same cacheline too. Also, the cacheline that contains segment #8/0x40 is not available,

Why's that? That cacheline (assuming 64 byte line size) already contains the user/kernel/cs/ds descriptors.

I'm thinking of putting together a patch to change the descriptor use to:

8 - TLS #1
9 - TLS #2
10 - TLS #3
11 - Kernel PDA
12 - Kernel CS
13 - Kernel DS
14 - User CS
15 - User DS

This has the advantage of leaving the user cs/ds unchanged. From what people had said so far, this should be OK, other than making the heavily used TLS #1 share the BIOS common area entry number. If this needs to be usable by userspace for something special, then making it TLS #1 won't fly...

Alternatively, maybe:

   0  - NULL
   1  - Kernel PDA
   2  - Kernel CS
   3  - Kernel DS
   4  - User CS
   5  - User DS
   6  - TLS #1
   7  - TLS #2

which moves the user cs/ds, but avoids #8.

J

#16 lore raw
Quoted 3 lines · Jeremy Fitzhardinge

So does this mean that moving the user-visible cs/ds isn't likely to break stuff, if it has been done before?

Yes. I _think_ we could do it. It's been done before, and nobody noticed.

That said, it may actually be that programs have since become much more aware of segments, for a rather perverse reason: the TLS stuff. Old programs are all very much coded and compiled for a totally flat model, and as such they really don't know _anything_ about segments. But with more TLS stuff, it's possible that a modern threded program is at least aware of _some_ of it.

In other words - I _suspect_ we can move things around, but it would require some rather heavy testing, at least. Especially programs like Wine might react badly.

Quoted 6 lines
Quoted 3 lines

And segment #8 (ie 0x40) is special (TLS segment #3), of course. Anybody who wants to emulate windows or use the BIOS needs to use that for their "common BIOS area" thing, iirc.

Do you mean that something like dosemu/Wine needs to be able to use GDT #8? Or is it only used in kernel code?

Both. I think the APM BIOS callbacks use GDT#8 too. As long as it's not one of the really _core_ kernel segments, that's ok (you can swap it around and nobody will care). But it would be a total disaster (I suspect) if GDT#8 was the kernel code segment, for example. Suddenly the "switch things around temporarily" is not as trivial any more, and involves nasty nasty things.

[ BUT! I haven't ever really had much to do with those BIOS callbacks, and
I'm too lazy to check, so this is all from memory. ]

Quoted 6 lines
Quoted 3 lines

See above. The kernel and user segments have to be moved as a block of four, and obviously we'd like to keep them in the same cacheline too. Also, the cacheline that contains segment #8/0x40 is not available,

Why's that? That cacheline (assuming 64 byte line size) already contains the user/kernel/cs/ds descriptors.

Right. That's what I'm saying. We should move them all together, and we should keep them as aligned as they are now.

Quoted 5 lines

I'm thinking of putting together a patch to change the descriptor use to:

   8  - TLS #1
   9  - TLS #2
   10 - TLS #3

So I'd not be surprised if movign the TLS segments around would break something.

Quoted 1 line

11 - Kernel PDA

But you keep the four basic ones in the same place:

Quoted 4 lines

12 - Kernel CS
13 - Kernel DS
14 - User CS
15 - User DS

So that's obviously ok at least for _those_.

Quoted 11 lines

Alternatively, maybe:

   0  - NULL
   1  - Kernel PDA
   2  - Kernel CS
   3  - Kernel DS
   4  - User CS
   5  - User DS
   6  - TLS #1
   7  - TLS #2
Quoted 1 line

which moves the user cs/ds, but avoids #8.

I don't like that one, exactly because now the four most common segments (which get accessed for all system calls) are no longer in the same 32-byte cacheline.

[ Unless we start playing games with offsetting the GDT or something..
Quite frankly, I'd rather keep it simple and obvious. ]

Now, most systems have a 64-byte cacheline these days (and some have a split 128-byte one), and maybe we'll never go back to the "good old days" with 32-byte lines, so maybe this is a total non-issue. But fitting in the same 32-byte aligned thing would still count as a "good thing" in my book.

That said, numbers talk, bullshit walks. If the above just works a lot better for all modern CPU's that all have 64-byte cachelines (because now _everything_ is in that bigger cacheline), and if you can show that with numbers, and nothing breaks in practice, then hey..

Linus

#17 lore raw
Quoted 2 lines · Linus Torvalds

So I'd not be surprised if movign the TLS segments around would break something.

I don't think so. 32-bit code running on x86-64 has different TLS selectors, and everything seems to work there...

Quoted 2 lines

That said, numbers talk, bullshit walks. If the above just works a lot better for all modern CPU's that all have 64-byte cachelines (because now _everything_ is in that bigger cacheline), and if you can show that with numbers, and nothing breaks in practice, then hey..

My goal would be to do a minimal change which packs all the useful stuff together in a 64-byte line. Ideally it would just use two 32-byte lines, but I don't think that's as important.

Caching effects are pretty hard to measure anyway, and with something as deeply x86-microarchitectural as this, I could imagine lots of other CPU cleverness which could obscure any simple measurement. But packing things into a line certainly can't hurt.

I'll put something together, and see how it goes...

J

#18 lore raw
In reply to Jeremy Fitzhardinge
Quoted 2 lines · Jeremy Fitzhardinge

What's the rationale for the current assignment of GDT entries? In particular, this section:

AFAIK it was mostly for APM and various BIOS bugs. IIRC Wine had some special requirements at some point too, but I can't remember them right now. On x86-64 I use all GDT entries, although there are a few special ordering restrictions due to the semantics of SYSCALL. I ignored Wine too and so far nobody has complained, so whatever requirements they have they can't be that important.

Quoted 5 lines

I'm asking because I'd like to use one of these entries for the PDA descriptor, so that it is on the same cache line as the TLS descriptors. That way, the entry/exit segment register reloads would still only need to touch two GDT cache lines. Would there be a real problem in doing this?

The only way to find out would be to do it. It's quite possible that all the systems with APM BIOS that needed it are long beyond their MTBF.

-Andi