qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <rth@twiddle.net>,
	Eduardo Habkost <ehabkost@redhat.com>,
	"Richard W.M. Jones" <rjones@redhat.com>,
	"Daniel P. Berrange" <berrange@redhat.com>
Subject: [Qemu-devel] [PATCH RFC] i386: expose "TCGTCGTCGTCG" in the 0x40000000 CPUID leaf
Date: Thu,  4 May 2017 15:56:58 +0100	[thread overview]
Message-ID: <20170504145658.5506-1-berrange@redhat.com> (raw)

Currently when running KVM, we expose "KVMKVMKVM\0\0\0" in
the 0x40000000 CPUID leaf. Other hypervisors (VMWare,
HyperV, Xen, BHyve) all do the same thing, which leaves
TCG as the odd one out.

The CPUID is used by software to detect when running in a
virtual environment and change behaviour in certain ways.
For example, systemd supports a ConditionVirtualization=
setting in unit files. Currently they have to resort to
custom hacks like looking for 'fw-cfg' entry in the
/proc/device-tree file. The virt-what command has the
same hacks & needs.

This change thus proposes a signature TCGTCGTCGTCG to be
reported when running under TCG.

NB1, for reasons I don't undersatnd 'cpu_x86_cpuid' function
clamps the requested CPUID leaf based on env->cpuid_level.
The latter comes from the CPU model definitions, and is
lower than 0x40000000, so the CPUID signature request just
gets turned into a completely different request. eg when
using '-cpu qemu64', the 0x40000000 request from the guest
gets clamped to 0xD and thus returns totally bogus data.
I just removed the clamping code, but someone who understands
this might have a better suggestion.

NB2, for KVM, we added a flag for '-cpu kvm=off' to let you
hide the KVMKVMKVM signature from guests. Presumably we should
add a 'tcg=off' flag for the same reason ?

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
---
 target/i386/cpu.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 13c0985..ac2776e 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -2626,6 +2626,7 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
     X86CPU *cpu = x86_env_get_cpu(env);
     CPUState *cs = CPU(cpu);
     uint32_t pkg_offset;
+    uint32_t signature[3];
 
     /* test if maximum index reached */
     if (index & 0x80000000) {
@@ -2646,8 +2647,13 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
             }
         }
     } else {
-        if (index > env->cpuid_level)
+        /* XXX this just breaks CPUID turning guest requests
+         * into something totally different, thus returning
+         * garbage data
+         */
+        if (0 && index > env->cpuid_level) {
             index = env->cpuid_level;
+        }
     }
 
     switch(index) {
@@ -2872,6 +2878,14 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
         }
         break;
     }
+    case 0x40000000:
+        /* XXX add flag to let us hide this */
+        memcpy(signature, "TCGTCGTCGTCG", 12);
+        *eax = 0x40000001;
+        *ebx = signature[0];
+        *ecx = signature[1];
+        *edx = signature[2];
+        break;
     case 0x80000000:
         *eax = env->cpuid_xlevel;
         *ebx = env->cpuid_vendor1;
-- 
2.9.3

             reply	other threads:[~2017-05-04 14:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-04 14:56 Daniel P. Berrange [this message]
2017-05-04 18:42 ` [Qemu-devel] [PATCH RFC] i386: expose "TCGTCGTCGTCG" in the 0x40000000 CPUID leaf Eduardo Habkost
2017-05-05  7:45   ` Paolo Bonzini
2017-05-05 11:46   ` Daniel P. Berrange
2017-05-05 16:46     ` Eduardo Habkost

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=20170504145658.5506-1-berrange@redhat.com \
    --to=berrange@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rjones@redhat.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 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).