General protection in 64bit mode (Intel)

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.
nulik
Member
Member
Posts: 46
Joined: Thu Oct 20, 2011 2:07 pm

General protection in 64bit mode (Intel)

Post by nulik »

Hi,
I would like to know if it is possible to achieve general protection (like SIGSEGV interrupt for example) on intel architecture when the processor is in 64 bit mode, with absolute addressing mode (without using paging mechanism enabled).
I have been reading the manuals and Intel Developers 3a volume says that the processor does not perform any limit checking on DS or CS register in 64bit mode (page 5-7)
As I understand Linux kernel uses Virtual Memory and if you use paging mechanism you can easily check limits with page fault interrupt. But in my case, I will not be using virtual memory, I will be using real addressing. Then how would I perform the limit check for processes in userland?

Will appreciate any ideas or pointers to the docs.
Nulik
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: General protection in 64bit mode (Intel)

Post by gerryg400 »

You can't enter long mode without enabling paging. So therefore you can use the same mechanism Linux uses.
If a trainstation is where trains stop, what is a workstation ?
User avatar
Velko
Member
Member
Posts: 153
Joined: Fri Oct 03, 2008 4:13 am
Location: Ogre, Latvia, EU

Re: General protection in 64bit mode (Intel)

Post by Velko »

First of all: You CAN NOT use processor in 64-bit mode without paging.
If something looks overcomplicated, most likely it is.
nulik
Member
Member
Posts: 46
Joined: Thu Oct 20, 2011 2:07 pm

Re: General protection in 64bit mode (Intel)

Post by nulik »

gerryg400 wrote:You can't enter long mode without enabling paging. So therefore you can use the same mechanism Linux uses.
but I don't need it. Paging wastes a lot of cpu cycles for address translation. Why would I use this thing if I have a lot of memory? And also I don't allocate large memory blocks, so contiguous allocation is not a problem for my OS.

I need to avoid paging somehow , but be able to use 64 bit capabilities of the processor.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: General protection in 64bit mode (Intel)

Post by bluemoon »

nulik wrote:but I don't need it. Paging wastes a lot of cpu cycles for address translation.
Any benchmark?

Paging, when used properly, avoid memory fragmentation, provide consistent address spaces, and enable you to adopt better algorithm like page sharing, copy-on-write, swap, etc.
These features and performance boost should be considered.

However, a poorly written software may keep generating TLB miss, but that's the software problem to be fixed, not paging.
rdos
Member
Member
Posts: 3310
Joined: Wed Oct 01, 2008 1:55 pm

Re: General protection in 64bit mode (Intel)

Post by rdos »

64-bit long mode has 4 (!) paging levels, and that this would not degrade performance could not be true. At the least, it wastes a lot of silicon if it manages to keep performance somewhat similar to a non-paged design. Of course, we cannot test this as it is not possible to turn off paging in long-mode.

Paging in 32-bit also has a performance penalty. It was quite considerable on the first CPUs like 386 CPUs. But it only contains 2 levels, not 4.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: General protection in 64bit mode (Intel)

Post by Combuster »

64-bit long mode has 4 (!) paging levels, and that this would not degrade performance could not be true.
It has been experimentally established that 64-bit mode (paging required) is faster than 32-bit mode (with paging).
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
rdos
Member
Member
Posts: 3310
Joined: Wed Oct 01, 2008 1:55 pm

Re: General protection in 64bit mode (Intel)

Post by rdos »

Combuster wrote:
64-bit long mode has 4 (!) paging levels, and that this would not degrade performance could not be true.
It has been experimentally established that 64-bit mode (paging required) is faster than 32-bit mode (with paging).
If it has, it is not because of a faster design, but that the CPU chips have been made in such a way that optimizes 64-bit mode over 32-bit mode. Besides, with which CPUs was this estabilshed so I can avoid them in the future?

Does this mean that x64 is just another Itanium-like design that has not implemented x86 properly?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: General protection in 64bit mode (Intel)

Post by Combuster »

History shows there's no way your brain would be able to deal with the explanation, so I'm not going to answer and derail the thread in your honour. I hope the OP did get the point first time around.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: General protection in 64bit mode (Intel)

Post by Casm »

bluemoon wrote:but I don't need it. Paging wastes a lot of cpu cycles for address translation.
Whether you need it or not, AMD decided to disable segmentation in 64 bit mode, which would be the only other way of implementing memory protection.

It should be at least a little while before anybody needs more than the 64Gb they can get with physical address extension in 32 bit mode.
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: General protection in 64bit mode (Intel)

Post by Casm »

rdos wrote:64-bit long mode has 4 (!) paging levels
The days of 4kb pages have got to be numbered, otherwise we will end up with twenty levels of page tables. Maybe I exaggerate a bit.
nulik
Member
Member
Posts: 46
Joined: Thu Oct 20, 2011 2:07 pm

Re: General protection in 64bit mode (Intel)

Post by nulik »

bluemoon wrote:Any benchmark?
Yes! I did not do it myself but here is a presentation claiming that:

"Even assuming 100% HIT rate in Main Memory the penalty of using virtual memory is 2X"
http://6004.csail.mit.edu/Spring98/Lect ... sld013.htm

MIT teachers must know something aren't they?

Paging, when used properly, avoid memory fragmentation, provide consistent address spaces, and enable you to adopt better algorithm like page sharing, copy-on-write, swap, etc.
These features and performance boost should be considered.

However, a poorly written software may keep generating TLB miss, but that's the software problem to be fixed, not paging.
Well, I don't need this really. In my OS you will have a memory partition table (just like disks do), where each application will have a fixed code and data size. So I won't have a problem with fragmentation.

Just think about it, TLB only can cache about 1K of pages, how much cache is this compared to a physical RAM of a 32GB machine? And on every TLB miss, you have to read DRAM and scan for pages, the speed of DRAM is about 200 clock cycles because of inefficiency of dynamic ram design. If theoretically paging is a waste of resources, themn practically it will certainly be, you won't even need a proof.

So, back to my question...
If paging can't be disabled, I could enable the largest page size and every process will have to have a minimum of MAX_PAGE_SIZE size data segment .... crappy solution but what can you do?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: General protection in 64bit mode (Intel)

Post by Combuster »

nulik wrote:MIT teachers must know something aren't they?
They probably did, 13 years ago. :wink:

In my OS you will have a memory partition table (just like disks do), where each application will have a fixed code and data size.
That's probably your real problem. A program's code size will be fixed, but it's memory size will change depending on what open files and tasks you have. Basically, your assumption only holds for simple embedded devices, it's not workable on any desktop/server configuration.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: General protection in 64bit mode (Intel)

Post by gerryg400 »

Yes! I did not do it myself but here is a presentation claiming that:

"Even assuming 100% HIT rate in Main Memory the penalty of using virtual memory is 2X"
http://6004.csail.mit.edu/Spring98/Lect ... sld013.htm

MIT teachers must know something aren't they?
That presentation looks like complete guesswork to me. It doesn't describe how the time measurements were made nor does it say which particular microprocessors were benchmarked. Also as Combuster pointed out is completely out of date. 13 years is an eternity.
Just think about it, TLB only can cache about 1K of pages, how much cache is this compared to a physical RAM of a 32GB machine? And on every TLB miss, you have to read DRAM and scan for pages, the speed of DRAM is about 200 clock cycles because of inefficiency of dynamic ram design. If theoretically paging is a waste of resources, themn practically it will certainly be, you won't even need a proof.
You're guessing. But if you're worried stick with 32bit and don't enable paging or switch chip vendors.
.... crappy solution but what can you do?
Read the Intel documentation, including the application notes, follow all the performance hints that they give. There's a lot of information around about how to optimise for their chips.
If a trainstation is where trains stop, what is a workstation ?
rdos
Member
Member
Posts: 3310
Joined: Wed Oct 01, 2008 1:55 pm

Re: General protection in 64bit mode (Intel)

Post by rdos »

gerryg400 wrote:
Yes! I did not do it myself but here is a presentation claiming that:

"Even assuming 100% HIT rate in Main Memory the penalty of using virtual memory is 2X"
http://6004.csail.mit.edu/Spring98/Lect ... sld013.htm

MIT teachers must know something aren't they?
That presentation looks like complete guesswork to me. It doesn't describe how the time measurements were made nor does it say which particular microprocessors were benchmarked. Also as Combuster pointed out is completely out of date. 13 years is an eternity.
Even if it were 30 years old it would still show the obvious that a system without paging is faster than a system with paging. I don't understand how anybody can argue otherwise. And a system that uses 4 levels of paging and has double the size of the page-entries MUST be slower than a system with 2 levels. That's common sense. If that does not hold, chip-vendors are favoring 64-bit over 32-bit in their silicon-solutions in order to make them move to 64-bit.
Post Reply