From: Daniel Stodden Subject: Re: Xen-aware kernel module Date: Wed, 21 Nov 2007 05:48:03 +0100 Message-ID: <1195620483.15545.168.camel@thinkpad.localdomain> References: <5fa100fd0711201630y668d0846ufd5a6de2e065a17e@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <5fa100fd0711201630y668d0846ufd5a6de2e065a17e@mail.gmail.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "Steven Y. Ko" Cc: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org On Tue, 2007-11-20 at 18:30 -0600, Steven Y. Ko wrote: > Hello, >=20 > (I'm not sure if this is an appropriate place to ask this question. I > apologize, if it's not) >=20 > I'm trying to write a kernel module, that's sort of Xen-aware (or > virtualisation-aware). I say "sort of", because what I actually need > is checking the ring. Specifically, in my kernel module, I want to > check which ring the code is running on (ring0, ring1, or even ring > 3!), and behave differently. Does Xen provide any interface to do it? > or is there any way to do it in a kernel module? Thanks for any help. well, if you had a xen interface to check it, then you already know you're not running on ring0, right? i suppose you will not consider HVM in your equation, because the ring idea makes only sense with pv. so, the solution may be: #ifdef CONFIG_X86_XEN # ifdef CONFIG_X86_32 ring =3D 1; # else ring =3D 3; # endif #else ring =3D 0; #endif amounts to a minumum of runtime overhead <:). i forgot: add tests for XENFEAT_supervisor_mode_kernel, but I believe it that never really got into vogue (someone correct me if i'm wrong). CPL is stored only internally. If it should look smarter, one might consider following the %cs selector, but strictly speaking this isn't bulletproof as the descriptor might have altered in the meanwhile (on linux, it's usually safe). There may be some alternatives I'm admittedly rather unaware of. checking privilege levels that way will, if at all, only work on PV. full virtualization (because you mentioned 'virtualization-aware' vs. xen-only) will do its best to assure you you're running on cpl 0. similar applies to VT-x root vs. non-root mode. hth, daniel --=20 Daniel Stodden LRR - Lehrstuhl f=C3=BCr Rechnertechnik und Rechnerorganisation Institut f=C3=BCr Informatik der TU M=C3=BCnchen D-85748 Garc= hing http://www.lrr.in.tum.de/~stodden mailto:stodden@cs.tum.edu PGP Fingerprint: F5A4 1575 4C56 E26A 0B33 3D80 457E 82AE B0D8 735B