-1

I'm running Ubuntu Linux on x86-64 architecture, and I want to enable segmentation (as opposed to paging).
Is there a way to use segmentation instead of paging on x86-64 based Linux systems?
Thanks in advance.

P.S. I've checked a few websites like this but haven't got much information, and searching for "enabling segmentation on Linux" or "enabling segmentation on x86-64" doesn't return much information. I actually think the first answer here might mean that I can't use segmentation anymore, but am not sure.

WannabeArchitect
  • 1,058
  • 2
  • 11
  • 22

1 Answers1

2

You don't have to "enabled" segmentation on x86-64 GNU/Linux, it already uses FS for thread-local storage. But x86-64 segmentation is vestigial and not usable as an alternative to paging. The base and limit of CS/DS/ES/SS are fixed at 0 / unlimited in long mode. It exists mostly as x86 legacy, and as a way to control what mode the CPU is executing in. (By far jump to a CS segment descriptor with the L bit set for 64-bit long mode, or other bits for 32-bit vs. 16-bit compat mode.)

You could possibly write a 64-bit kernel that used segmentation for memory protection of 32-bit processes (with 1G hugepages direct-mapping all the virtual address space you use; you can't disable paging in x86-64, except for "legacy mode" using the CPU as a 32-bit-only CPU).

Of course Linux has no support for this; it's built around a flat memory model with paging, like all modern mainstream x86 OSes. Using segmentation instead would fundamentally change everything about how you manage memory and get new memory from the OS. You'd have to write a new libc at least, and rewrite a bunch of software that knows anything about paging.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Thanks for your answer! I understand that "1G hugepage for direct-mapping" you mentioned comes from the fact that x86 supports 4KB/2MB/1GB pages, but does that mean I'll need 4 of 1G hugepages to map a whole 32bit memory address? – WannabeArchitect Aug 19 '20 at 05:25
  • 1
    @WannabeArchitect: Yes. Note that only PAE / x86-64 page tables use 4k/2M/1G pages ([9 bits per level, 8-byte PTEs](https://stackoverflow.com/q/46509152)); legacy 32-bit mode kernels not using PAE have 4k/4M pages (10 bits per level, 4 byte PTEs), with no option of covering the entire address space with a single 4G page. (You just disable paging if you want that.) – Peter Cordes Aug 19 '20 at 05:32