Rings 1 and 2

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Rings 1 and 2

Post by bewing »

It would allow me to set the IOPL above ring 3, permanently -- just to provide that much extra security between userland and things it shouldn't have access to.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Rings 1 and 2

Post by Love4Boobies »

jal wrote:The guest OS is running in ring 1. And I suppose the guest code is still running in ring 3, supposing also that the guest OS uses only ring 0 (now 1) and 3.
You didn't understand what I was asking. I got that guest ring 0 stuff goes at ring 1 on the physical machine. But if the guest OS also uses ring 1, where does that go? Ring 1 (that could trash the guest OS), ring 2 (that would be bad as the guest machine wouldn't have as many rings if you tried to run Virtual PC in Virtual PC; you'd run out of rings) or ring 3 (would that work?)?
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: Rings 1 and 2

Post by AndrewAPrice »

About the only practical use I see for Ring 1-2 is in a microkernel if you wish to place memory management completely outside of the kernel.

But in the majority of microkernels, even the device drivers can run in ring 3 because you can grant access to certain IO ports in ring 3, and with with sufficient IPC (messenges, pipes, and/or shared memory) you have everything required for a device to communicate with the hardware and with user applications. Then it is up to your kernel what processors are given driver (IO, DMA mapping, etc) privileges and the like.
My OS is Perception.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Rings 1 and 2

Post by Love4Boobies »

MessiahAndrw wrote:About the only practical use I see for Ring 1-2 is in a microkernel if you wish to place memory management completely outside of the kernel.
Memory managers can be implemented in userspace without any problems. You only need 2 API calls in the kernel: one for granting pages and one for flushing them. If you're looking for something a bit more complex, you could add a third - for mapping pages from one process to another (shared pages, anyone?).
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
AndrewAPrice
Member
Member
Posts: 2299
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: Rings 1 and 2

Post by AndrewAPrice »

I know, I was trying to find a reason to use Ring 1/2.
My OS is Perception.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Rings 1 and 2

Post by jal »

Love4Boobies wrote:You didn't understand what I was asking.
I did, you just didn't understand my answer :).
I got that guest ring 0 stuff goes at ring 1 on the physical machine. But if the guest OS also uses ring 1, where does that go? Ring 1 (that could trash the guest OS)
Still ring 1, most likely. Yes, that could theoretically trash the guest OS, but only rather theoretically. Besides, ring 1 is not used anyway by any main OS, so who cares?


JAL
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: Rings 1 and 2

Post by Owen »

OS/2 uses ring 1 and 2 (I don't have a clue what for).

It dies on almost every emulator because none of them implement them, as nothing else uses them
User avatar
quanganht
Member
Member
Posts: 301
Joined: Fri May 16, 2008 7:13 pm
Location: Hanoi, Vietnam

Re: Rings 1 and 2

Post by quanganht »

Drivers and service in Windows run in ring 0 to lower the switching overhead.
"Programmers are tools for converting caffeine into code."
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Rings 1 and 2

Post by Love4Boobies »

quanganht wrote:Drivers and service in Windows run in ring 0 to lower the switching overhead.
That's what's called a monolithic kernel. Your point?

P.S: for anyone who's gonna start saying anything about hybrid kernels, that's BS IMO :)
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: Rings 1 and 2

Post by JAAman »

quanganht wrote:Drivers and service in Windows run in ring 0 to lower the switching overhead.
... but thats just not true...

in windows, most drivers run in ring3 not ring0...

and MS has been fighting with the driver writers to get them all in ring3... but 3rd party developers arnt very good at cooperating... (actually, these days, its mostly just old drivers which are still running in ring0)

MS does use a ring0 disk driver for accessing the swap file though, iirc
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Rings 1 and 2

Post by Love4Boobies »

JAAman wrote:in windows, most drivers run in ring3 not ring0...
Well, since you brought it up, yeah, there are two types of drivers in windows: kernel-mode drivers and user-mode drivers. My guess is that kernel-mode drivers are here to stay for a while, unfortunately.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re: Rings 1 and 2

Post by Colonel Kernel »

JAAman wrote:MS does use a ring0 disk driver for accessing the swap file though, iirc
AFAIK, all file system, fixed disk, and network drivers run in ring 0 for performance reasons. Plus, there is at least part of the video driver framework that runs in ring 0.

This applies only to Vista and (I think) Windows Server 2008. Older versions run nearly all drivers in ring 0.
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: Rings 1 and 2

Post by neon »

Love4Boobies wrote:P.S: for anyone who's gonna start saying anything about hybrid kernels, that's BS IMO :)
Perhaps saying that Windows has a microkernel design but built as a monolithic kernel is better then saying it has a "hybrid" kernel.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Colonel Kernel
Member
Member
Posts: 1437
Joined: Tue Oct 17, 2006 6:06 pm
Location: Vancouver, BC, Canada
Contact:

Re: Rings 1 and 2

Post by Colonel Kernel »

neon wrote:
Love4Boobies wrote:P.S: for anyone who's gonna start saying anything about hybrid kernels, that's BS IMO :)
Perhaps saying that Windows has a microkernel design but built as a monolithic kernel is better then saying it has a "hybrid" kernel.
That would be a true statement if you're talking about Mac OS X, but not so much about Windows. Other than the "sub-system servers" that allowed for different OS personalities, the original NT design was modeled after VMS, which is definitely not a microkernel.
Top three reasons why my OS project died:
  1. Too much overtime at work
  2. Got married
  3. My brain got stuck in an infinite loop while trying to design the memory manager
Don't let this happen to you!
xlq
Member
Member
Posts: 36
Joined: Mon Dec 11, 2006 7:51 am

Re: Rings 1 and 2

Post by xlq »

As I see it, rings 1 and 2 were designed to run code at a privilege level that could have absolute power over ring 3 processes but keeping the kernel protected from it. But if you're going to run drivers outside ring 0, then it's worth providing a simple API to the kernel rather than letting ring 1 code mess around with ring 3 bits itself.

With paging, there's probably only one privilege bit because rings 1 and 2 were so rarely used. Now, if page table entries had a user-id-like field, and a switchable current-user-id, that'd be good news for microkernels: several small user processes can remain in the same address space, without being able to tamper with other processes. It means that same-privilege processes could communicate with each other with no page directory switches. I haven't a clue how complex that'd be to implement in hardware though.
Marionette the flexible kernel
Post Reply