CPU 特权环:为什么不使用环 1 和 2? [英] CPU Privilege Rings: Why rings 1 and 2 aren't used?

查看:34
本文介绍了CPU 特权环:为什么不使用环 1 和 2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于 x86 CPU 特权环的几个问题:

  • 为什么大多数操作系统不使用环 1 和环 2?只是为了保持代码与其他架构的兼容性,还是有更好的理由?

  • 是否有实际使用这些环的操作系统?或者它们完全没有使用?

解决方案

作为一个业余的操作系统编写者,我发现因为分页(现代保护模型的主要部分)只有特权(ring 0,1,2) 和非特权,环 1 和环 2 的收益大大减少.

英特尔采用环 1 和环 2 的目的是让操作系统将设备驱动程序置于该级别,因此它们具有特权,但与内核代码的其余部分有些分离.

环 1 和环 2 在某种程度上主要"享有特权.他们可以访问主管页面,但是如果他们尝试使用特权指令,他们仍然会像环 3 那样进行 GPF.因此,对于英特尔计划的驱动程序来说,这不是一个糟糕的地方......

也就是说,它们在某些设计中确实有用.事实上,并不总是由操作系统直接执行.例如,VirtualBoxVirtual Machine,将客户内核代码放在环 1 中.我也确定某些操作系统确实使用它们,我只是不认为它是目前流行的设计.>

A couple of questions regarding the x86 CPU privilege rings:

  • Why aren't rings 1 and 2 used by most operating systems? Is it just to maintain code compatibility with other architectures, or is there a better reason?

  • Are there any operating systems which actually use those rings? Or are they completely unused?

解决方案

As a hobbyist operating system writer, I found that because paging (a major part of the modern protection model) only has a concept of privileged (ring 0,1,2) and unprivileged, the benefit to rings 1 and 2 were diminished greatly.

The intent by Intel in having rings 1 and 2 is for the OS to put device drivers at that level, so they are privileged, but somewhat separated from the rest of the kernel code.

Rings 1 and 2 are in a way, "mostly" privileged. They can access supervisor pages, but if they attempt to use a privileged instruction, they still GPF like ring 3 would. So it is not a bad place for drivers as Intel planned...

That said, they definitely do have use in some designs. In fact, not always directly by the OS. For example, VirtualBox, a Virtual Machine, puts the guest kernel code in ring 1. I am also sure some operating systems do make use of them, I just don't think it is a popular design at the moment.

这篇关于CPU 特权环:为什么不使用环 1 和 2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆