Hello, (I''m not sure if this is an appropriate place to ask this question. I apologize, if it''s not) 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. Regards, Steve _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
On Tue, 2007-11-20 at 18:30 -0600, Steven Y. Ko wrote:> Hello, > > (I''m not sure if this is an appropriate place to ask this question. I > apologize, if it''s not) > > 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 = 1; # else ring = 3; # endif #else ring = 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 -- Daniel Stodden LRR - Lehrstuhl für Rechnertechnik und Rechnerorganisation Institut für Informatik der TU München D-85748 Garching http://www.lrr.in.tum.de/~stodden mailto:stodden@cs.tum.edu PGP Fingerprint: F5A4 1575 4C56 E26A 0B33 3D80 457E 82AE B0D8 735B _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
> Hello, > > (I''m not sure if this is an appropriate place to ask this question. I > apologize, if it''s not) > > 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.There may or may not be a CPU instruction to tell you what RING you are running in. As for telling if you are running under Xen, have a look at /unmodified_drivers/linux-2.6/platform-pci/platform-pci.c in the function init_hypercall_stubs. The first thing it does is execute a CPUID instruction. If Xen is running, a signature will be encoded into EBX, ECX, and EDX. You might be able to make use of that? James _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Since this code will be x86-specific anyway, you can use inline asm: unsigned long ring; asm ( "push %cs; pop %0; and $3,%0" : "=r" (ring) ); Or perhaps just look at the KERNEL_CS macro. -- Keir On 21/11/07 00:30, "Steven Y. Ko" <sko@cs.uiuc.edu> wrote:> Hello, > > (I''m not sure if this is an appropriate place to ask this question. I > apologize, if it''s not) > > 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. > > Regards, > Steve > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Thank you all for the great tips! - Steve On Nov 21, 2007 1:54 AM, Keir Fraser <Keir.Fraser@cl.cam.ac.uk> wrote:> Since this code will be x86-specific anyway, you can use inline asm: > > unsigned long ring; > asm ( "push %cs; pop %0; and $3,%0" : "=r" (ring) ); > > Or perhaps just look at the KERNEL_CS macro. > > -- Keir > > > On 21/11/07 00:30, "Steven Y. Ko" <sko@cs.uiuc.edu> wrote: > > > Hello, > > > > (I''m not sure if this is an appropriate place to ask this question. I > > apologize, if it''s not) > > > > 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. > > > > Regards, > > Steve > > > > _______________________________________________ > > Xen-devel mailing list > > Xen-devel@lists.xensource.com > > http://lists.xensource.com/xen-devel > > >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel