All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Roman Bolshakov <r.bolshakov@yadro.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	Hill Ma <maahiuzeon@gmail.com>
Cc: John Arbuckle <programmingkidx@gmail.com>,
	Richard Henderson <rth@twiddle.net>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Cameron Esfahani <dirty@apple.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH] hvf: guard xgetbv call.
Date: Sun, 10 Jan 2021 08:38:36 -1000	[thread overview]
Message-ID: <4a24ae1a-8114-a840-b6bf-ae3a301f6232@linaro.org> (raw)
In-Reply-To: <8da22f7f-7379-cffe-5fdd-94fd5ddece32@linaro.org>

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.

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.

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


r~


  reply	other threads:[~2021-01-10 18:40 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 [this message]
2021-01-11  4:31           ` Roman Bolshakov
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=4a24ae1a-8114-a840-b6bf-ae3a301f6232@linaro.org \
    --to=richard.henderson@linaro.org \
    --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=r.bolshakov@yadro.com \
    --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.