Skip to contentSkip to conversation

xenoprof passive profiling and "mode" setting

DISCUSSION Ray Bryant 2 participants 2 messages Jul 5, 2006

lore
Share & tools
lore

Ray Bryant

author
#0 lore raw

Xiaowei,

I'm puzzled by the following bit of code in p4_check_ctrs():

       if (guest_kernel_mode(current, regs))
                mode = 1;
        else if (ring_0(regs))
                mode = 2;

If I look at the definition for guest_kernel_mode() it is:

include/asm-x86/x86_64/regs.h:

#define guest_kernel_mode(v, r)   \
    (ring_3(r) && ((v)->arch.flags & TF_kernel_mode))

(Note well:  I am running a 64 bit guest and a 64 bit host.)

So, how is that possibly true for the kernel in an HVM guest? (Wouldn't guest_kernel_mode(regs) be false in that case since it is not running ring_3()?)

Also, wouldn't ring_0(regs) be true if we are running in kernel mode in an HVM guest?    This code appears to assign such a sample to being part of xen, right?

So I'm unsure as to whether the above snippet of code sets the mode correctly.

Signature · 3 lines
Ray Bryant
AMD Performance Labs                   Austin, Tx
512-602-0038 (o)                 512-507-7807 (c)
#1 lore raw
Quoted 3 lines · Ray Bryant

So, how is that possibly true for the kernel in an HVM guest? (Wouldn't guest_kernel_mode(regs) be false in that case since it is not running ring_3()?)

guest_kernel_mode() does not work for HVM guests. It may need to be fixed -- it had previously only been used in paravirtual-only contexts.

It might make sense to invert[*] the predicate and rename to user_mode(). Then definition is simply ring_3(regs) for x86/32 and (ring_3(regs) && !((v)->arch.flags & TF_kernel_mode)) for x86/64.

Quoted 3 lines

Also, wouldn't ring_0(regs) be true if we are running in kernel mode in an HVM guest?    This code appears to assign such a sample to being part of xen, right?

ring_0(regs) should be replaced by !guest_mode(regs).

So maybe:
int mode = 2;
if (guest_mode(regs))

      mode = user_mode(current, regs) ? 0 : 1;

-- Keir

[*] Not really inversion, as neither guest_kernel_mode() nor user_mode() are true for hypervisor mode.