All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Beulich <jbeulich@suse.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
	Wei Liu <wl@xen.org>, Roger Pau Monne <roger.pau@citrix.com>
Subject: Re: [Xen-devel] [PATCH v3 7/8] x86emul: support RDPRU
Date: Tue, 3 Sep 2019 15:05:58 +0200	[thread overview]
Message-ID: <3e5a4cfc-0d44-221a-d732-d1995c9f916a@suse.com> (raw)
In-Reply-To: <c0e34ad1-746b-6520-2d6a-f069e3107755@citrix.com>

On 03.09.2019 14:34, Andrew Cooper wrote:
> On 03/09/2019 10:41, Jan Beulich wrote:
>> While the PM doesn't say so, this assumes that the MPERF value read this
>> way gets scaled similarly to its reading through RDMSR.
>>
>> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> 
> This wants the following hunks merged, to at least keep the
> intercept/exit codes up to date.  This is from my alternative series
> which intercepted and terminated RDPRU with #UD.
> 
> diff --git a/xen/include/asm-x86/hvm/svm/vmcb.h
> b/xen/include/asm-x86/hvm/svm/vmcb.h
> index 5c710286f7..2bf0d50f6d 100644
> --- a/xen/include/asm-x86/hvm/svm/vmcb.h
> +++ b/xen/include/asm-x86/hvm/svm/vmcb.h
> @@ -76,7 +76,8 @@ enum GenericIntercept2bits
>      GENERAL2_INTERCEPT_MONITOR = 1 << 10,
>      GENERAL2_INTERCEPT_MWAIT   = 1 << 11,
>      GENERAL2_INTERCEPT_MWAIT_CONDITIONAL = 1 << 12,
> -    GENERAL2_INTERCEPT_XSETBV  = 1 << 13
> +    GENERAL2_INTERCEPT_XSETBV  = 1 << 13,
> +    GENERAL2_INTERCEPT_RDPRU   = 1 << 14,
>  };
> 
> 
> @@ -300,6 +301,7 @@ enum VMEXIT_EXITCODE
>      VMEXIT_MWAIT            = 139, /* 0x8b */
>      VMEXIT_MWAIT_CONDITIONAL= 140, /* 0x8c */
>      VMEXIT_XSETBV           = 141, /* 0x8d */
> +    VMEXIT_RDPRU            = 142, /* 0x8e */
>      VMEXIT_NPF              = 1024, /* 0x400, nested paging fault */
>      VMEXIT_INVALID          =  -1
>  };

I wouldn't think this belongs here, but since you ask for it, I
can fold it in.

>> --- a/xen/arch/x86/cpuid.c
>> +++ b/xen/arch/x86/cpuid.c
>> @@ -545,6 +545,11 @@ void recalculate_cpuid_policy(struct dom
>>  
>>      p->extd.maxlinaddr = p->extd.lm ? 48 : 32;
>>  
>> +    if ( p->extd.rdpru )
>> +        p->extd.rdpru_max = min(p->extd.rdpru_max, max->extd.rdpru_max);
>> +    else
>> +        p->extd.rdpru_max = 0;
>> +
>>      recalculate_xstate(p);
>>      recalculate_misc(p);
> 
> The CPUID logic needs quite a bit more than this, and to be safe on
> migrate.  For one, recalculate_xstate() unilaterally clobbers this to 0.

Oh, recalculate_misc() - yes, I see this now. And I have to admit
I don't see the migration-unsafety, so ...

> Shall I do a prep patch getting the CPUID side of things in order?

... yes, I'd appreciate you doing so.

>> --- a/xen/arch/x86/x86_emulate/x86_emulate.c
>> +++ b/xen/arch/x86/x86_emulate/x86_emulate.c
>> @@ -5670,6 +5671,52 @@ x86_emulate(
>>                  limit -= sizeof(zero);
>>              }
>>              break;
>> +
>> +        case 0xfd: /* rdpru */
>> +            vcpu_must_have(rdpru);
>> +
>> +            if ( !mode_ring0() )
>> +            {
>> +                fail_if(!ops->read_cr);
>> +                if ( (rc = ops->read_cr(4, &cr4, ctxt)) != X86EMUL_OKAY )
>> +                    goto done;
>> +                generate_exception_if(cr4 & X86_CR4_TSD, EXC_UD);
>> +            }
>> +
>> +            switch ( _regs.ecx )
>> +            {
>> +            case 0:  n = MSR_IA32_MPERF; break;
>> +            case 1:  n = MSR_IA32_APERF; break;
>> +            default: n = 0; break;
>> +            }
>> +            if ( _regs.ecx > ctxt->cpuid->extd.rdpru_max )
>> +                n = 0;
> 
> This can be folded into the switch statement.  Something like (
> _regs.ecx | -(_regs.ecx > ctxt->cpuid->extd.rdpru_max) )

Will do.

> Also, the sentinel might better be -1, which is not in a defined MSR
> block.  MSR 0 is a P5-compat MCE MSR, even on AMD hardware.

I did consider this, but decided there's a vanishingly small risk
for them to expose this MSR (and if they did we could still change
the code along the lines of what you say). A sentinel of zero is
slightly cheaper to have, after all.

Jan

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2019-09-03 13:06 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-03  9:35 [Xen-devel] [PATCH v3 0/8] x86emul: further work Jan Beulich
2019-09-03  9:37 ` [Xen-devel] [PATCH v3 1/8] x86emul: support WBNOINVD Jan Beulich
2019-09-03 10:17   ` Andrew Cooper
2019-09-03  9:37 ` [Xen-devel] [PATCH v3 2/8] x86/HVM: ignore guest INVD uses Jan Beulich
2019-09-03  9:43   ` Paul Durrant
2019-09-03 10:18   ` Andrew Cooper
2019-09-03 12:22     ` Jan Beulich
2019-09-03  9:39 ` [Xen-devel] [PATCH v3 3/8] x86emul: generalize invlpg() hook Jan Beulich
2019-09-03  9:39 ` [Xen-devel] [PATCH v3 4/8] x86emul: support INVPCID Jan Beulich
2019-09-03  9:39 ` [Xen-devel] [PATCH v3 5/8] x86emul: support MOVDIR{I,64B} insns Jan Beulich
2019-09-03 10:28   ` [Xen-devel] [PATCH v3 5/8] x86emul: support MOVDIR{I, 64B} insns Andrew Cooper
2019-09-03 12:25     ` Jan Beulich
2019-09-04 10:19       ` Andrew Cooper
2019-09-04 11:52         ` Jan Beulich
2019-09-03  9:40 ` [Xen-devel] [PATCH v3 6/8] x86/HVM: scale MPERF values reported to guests (on AMD) Jan Beulich
2019-09-03  9:41 ` [Xen-devel] [PATCH v3 7/8] x86emul: support RDPRU Jan Beulich
2019-09-03 12:34   ` Andrew Cooper
2019-09-03 13:05     ` Jan Beulich [this message]
2019-09-04  9:26     ` Jan Beulich
2019-09-04  9:46       ` Andrew Cooper
2019-09-03  9:42 ` [Xen-devel] [PATCH v3 8/8] x86/HVM: don't needlessly intercept APERF/MPERF/TSC MSR reads Jan Beulich
2019-09-04 23:16   ` Boris Ostrovsky
2019-09-05  6:31     ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3e5a4cfc-0d44-221a-d732-d1995c9f916a@suse.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=roger.pau@citrix.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.