All of lore.kernel.org
 help / color / mirror / Atom feed
From: Roman Bolshakov <r.bolshakov@yadro.com>
To: Richard Henderson <richard.henderson@linaro.org>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Cameron Esfahani <dirty@apple.com>,
	John Arbuckle <programmingkidx@gmail.com>,
	Hill Ma <maahiuzeon@gmail.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <rth@twiddle.net>
Subject: Re: [PATCH] hvf: guard xgetbv call.
Date: Mon, 11 Jan 2021 07:31:08 +0300	[thread overview]
Message-ID: <X/vUjHCd81PvEflw@SPB-NB-133.local> (raw)
In-Reply-To: <4a24ae1a-8114-a840-b6bf-ae3a301f6232@linaro.org>

On Sun, Jan 10, 2021 at 08:38:36AM -1000, Richard Henderson wrote:
> On 1/10/21 8:34 AM, Richard Henderson wrote:
> > On 1/9/21 3:46 PM, Roman Bolshakov wrote:
> >> +static int xgetbv(uint32_t cpuid_ecx, uint32_t idx, uint64_t *xcr)
> >>  {
> >> -    uint32_t eax, edx;
> >> +    uint32_t xcrl, xcrh;
> >>
> >> -    __asm__ volatile ("xgetbv"
> >> -                      : "=a" (eax), "=d" (edx)
> >> -                      : "c" (xcr));
> >> +    if (cpuid_ecx && CPUID_EXT_OSXSAVE) {
> >> +        /* The xgetbv instruction is not available to older versions of
> >> +         * the assembler, so we encode the instruction manually.
> >> +         */
> >> +        asm(".byte 0x0f, 0x01, 0xd0" : "=a" (xcrl), "=d" (xcrh) : "c" (idx));
> >>
> >> -    return (((uint64_t)edx) << 32) | eax;
> >> +        *xcr = (((uint64_t)xcrh) << 32) | xcrl;
> >> +        return 0;
> >> +    }
> >> +
> >> +    return 1;
> >>  }
> > 
> > Not to bikeshed too much, but this looks like it should return bool, and true
> > on success, not the other way around.
> 

I agree, it'd better to comprehend (and Hill has already sent v2 with
this).

> Also, if we're going to put this some place common, forcing the caller to do
> the cpuid that feeds this, then we should probably make all of the startup
> cpuid stuff common as well.
> 

I proposed the version because all callers of xgetbv instruction already
call cpuid before invoking inline xgetbv.

> Note that we'd probably have to use constructor priorities to get that right
> for util/bufferiszero.c.
> 

Please correct me if I read this wrong. What you're saying is we should
initialize cpuid in constructors and then use cached cpuid ecx in
xgetbv() (and drop one argument, respectively)?

Thanks,
Roman


  reply	other threads:[~2021-01-11  4:31 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-19  2:13 [PATCH] hvf: guard xgetbv call Hill Ma
2021-01-09  5:48 ` Roman Bolshakov
2021-01-09 11:42   ` Peter Maydell
2021-01-10  1:46     ` Roman Bolshakov
2021-01-10 18:34       ` Richard Henderson
2021-01-10 18:38         ` Richard Henderson
2021-01-11  4:31           ` Roman Bolshakov [this message]
2021-01-11 17:06             ` Richard Henderson
2021-01-12  7:49               ` Roman Bolshakov
2021-01-12 15:28                 ` Richard Henderson

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=X/vUjHCd81PvEflw@SPB-NB-133.local \
    --to=r.bolshakov@yadro.com \
    --cc=dirty@apple.com \
    --cc=maahiuzeon@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=programmingkidx@gmail.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=rth@twiddle.net \
    /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.