From: Paolo Bonzini <pbonzini@redhat.com>
To: Kamil Rytarowski <n54@gmx.com>, qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org
Subject: Re: [Qemu-devel] [PATCH] target-i386: Enhance the stub for kvm_arch_get_supported_cpuid()
Date: Wed, 20 Feb 2019 18:29:27 +0100 [thread overview]
Message-ID: <39f61014-bde0-bcbe-67ec-e479b8ab14ec@redhat.com> (raw)
In-Reply-To: <4e7b8587-02a4-4ad2-c297-db7a1231f0b6@gmx.com>
[-- Attachment #1: Type: text/plain, Size: 3487 bytes --]
On 20/02/19 12:59, Kamil Rytarowski wrote:
> Ping, still valid.
Sorry, I missed your email.
> On 15.02.2019 00:38, Kamil Rytarowski wrote:
>> I consider it as fragile hack and certainly not something to depend on.
>> Also in some circumstances of such code, especially "if (zero0)" we want
>> to enable disabled code under a debugger.
That's a good objection, but certainly does not apply to KVM on NetBSD.
>> There were also kernel backdoors due to this optimization.
Citation please?
>> Requested cpu.i (hopefully correctly generated)
>>
>> http://netbsd.org/~kamil/qemu/cpu.i.bz2
So, first thing first I can reproduce clang's behavior with this .i file
and also with this reduced test case.
extern void f(void);
int i, j;
int main()
{
if (0 && i) f();
if (j && 0) f();
}
The first is eliminated but the second is not, just like in QEMU where
this works:
if (kvm_enabled() && cpu->enable_pmu) {
KVMState *s = cs->kvm_state;
*eax = kvm_arch_get_supported_cpuid(s, 0xA, count, R_EAX);
*ebx = kvm_arch_get_supported_cpuid(s, 0xA, count, R_EBX);
*ecx = kvm_arch_get_supported_cpuid(s, 0xA, count, R_ECX);
*edx = kvm_arch_get_supported_cpuid(s, 0xA, count, R_EDX);
} else if (hvf_enabled() && cpu->enable_pmu) {
*eax = hvf_get_supported_cpuid(0xA, count, R_EAX);
*ebx = hvf_get_supported_cpuid(0xA, count, R_EBX);
*ecx = hvf_get_supported_cpuid(0xA, count, R_ECX);
*edx = hvf_get_supported_cpuid(0xA, count, R_EDX);
while this doesn't:
if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_INTEL_PT) &&
kvm_enabled()) {
KVMState *s = CPU(cpu)->kvm_state;
uint32_t eax_0 = kvm_arch_get_supported_cpuid(s, 0x14, 0, R_EAX);
uint32_t ebx_0 = kvm_arch_get_supported_cpuid(s, 0x14, 0, R_EBX);
uint32_t ecx_0 = kvm_arch_get_supported_cpuid(s, 0x14, 0, R_ECX);
uint32_t eax_1 = kvm_arch_get_supported_cpuid(s, 0x14, 1, R_EAX);
uint32_t ebx_1 = kvm_arch_get_supported_cpuid(s, 0x14, 1, R_EBX);
But, that's okay, it's -O0 so we give clang a pass for that Note that
clang does do the optimization even in more complex cases like
extern _Bool f(void);
int main()
{
if (!0) return 0;
if (!f()) return 0;
}
The problem is that there is a kvm-stub.c entry for that, and in fact
my compilation passes and the symbol is resolved correctly:
$ nm target/i386/cpu.o |grep kvm_.*get_sup
U kvm_arch_get_supported_cpuid
$ nm target/i386/kvm-stub.o|grep kvm_.*get_sup
0000000000000030 T kvm_arch_get_supported_cpuid
$ nm qemu-system-x86_64 |grep kvm_.*get_sup
000000000046eab0 T kvm_arch_get_supported_cpuid
As expected, something much less obvious is going on for you, in
particular __OPTIMIZE__seems not to be working properly. However,
that would also be very surprising.
Please:
1) run the last two "nm" commands on your build (wthout grep).
2) do the same exercise to get a .i for target/i386/kvm-stub.c
3) try removing the "#ifndef __OPTIMIZE__" and leave everything else as is,
see if it works. No need to play with macros, which also goes to show that
you didn't really understand what's going on---that's fine, but then please
refrain from making summary judgments which only lengthen the discussion.
Thanks,
Paolo
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2019-02-20 17:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-02 14:45 [Qemu-devel] [PATCH] target-i386: Enhance the stub for kvm_arch_get_supported_cpuid() Kamil Rytarowski
2019-02-03 17:31 ` no-reply
2019-02-14 18:43 ` Kamil Rytarowski
2019-02-14 18:44 ` Paolo Bonzini
2019-02-14 19:41 ` Kamil Rytarowski
2019-02-14 20:51 ` Paolo Bonzini
2019-02-14 23:38 ` Kamil Rytarowski
2019-02-20 11:59 ` Kamil Rytarowski
2019-02-20 17:29 ` Paolo Bonzini [this message]
2019-02-21 2:08 ` Kamil Rytarowski
2019-02-21 17:41 ` Paolo Bonzini
2019-02-25 6:26 ` Kamil Rytarowski
[not found] ` <CABgObfb22erktrGeOArTvF=0YMG3W8vHQT1+s0p9iRAMa4BvMA@mail.gmail.com>
2019-02-25 8:31 ` Kamil Rytarowski
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=39f61014-bde0-bcbe-67ec-e479b8ab14ec@redhat.com \
--to=pbonzini@redhat.com \
--cc=n54@gmx.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).