From nobody Sat Apr 27 16:04:51 2024 Delivered-To: importer@patchew.org Received-SPF: temperror (zoho.com: Error in retrieving data from DNS) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=temperror (zoho.com: Error in retrieving data from DNS) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1511442904324576.8689193886283; Thu, 23 Nov 2017 05:15:04 -0800 (PST) Received: from localhost ([::1]:44290 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHrKw-0001n1-IJ for importer@patchew.org; Thu, 23 Nov 2017 08:14:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48546) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHrK2-0001U3-9K for qemu-devel@nongnu.org; Thu, 23 Nov 2017 08:13:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eHrJy-0005ho-Ax for qemu-devel@nongnu.org; Thu, 23 Nov 2017 08:13:42 -0500 Received: from mail.skyhub.de ([5.9.137.197]:59732) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHrJy-0005gL-4G for qemu-devel@nongnu.org; Thu, 23 Nov 2017 08:13:38 -0500 Received: from mail.skyhub.de ([127.0.0.1]) by localhost (blast.alien8.de [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 0a7w6lvCNhi6; Thu, 23 Nov 2017 14:13:33 +0100 (CET) Received: from pd.tnic (p200300EC2BD187006580DFFA42EB3E64.dip0.t-ipconnect.de [IPv6:2003:ec:2bd1:8700:6580:dffa:42eb:3e64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 92C641EC072D; Thu, 23 Nov 2017 14:13:33 +0100 (CET) X-Virus-Scanned: Nedap ESD1 at mail.skyhub.de Date: Thu, 23 Nov 2017 14:13:31 +0100 From: Borislav Petkov To: qemu-devel@nongnu.org Message-ID: <20171123131331.5jyqwlbgthijqgl7@pd.tnic> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20170609 (1.8.3) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 5.9.137.197 Subject: [Qemu-devel] qemu x86 CPUID leafs override X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: x86-ml , lkml Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_6 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Hi guys, I'm using the hack below to do some quick kernel testing by setting arbitrary feature bits and then make it execute the code for that feature. For example, boot with: -cpu EPYC,cpuid-leaf=3D0x80000007,ebx=3D0xf to set some RAS feature bits and test newer RAS code. Would something like that be of interest to a wider audience? It is rough and ugly but if deemed useful, I could try to clean it up. Thx. --- diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 045d66191f28..249fb23be696 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -2732,6 +2732,13 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, uint32_t limit; uint32_t signature[3]; =20 + /* + * Pull up max xlevel in case the one we've specified on the cmdline is + * higher. + */ + if (cpu->cpuid_leaf && env->cpuid_xlevel < cpu->cpuid_leaf) + env->cpuid_xlevel =3D cpu->cpuid_leaf; + /* Calculate & apply limits for different index ranges */ if (index >=3D 0xC0000000) { limit =3D env->cpuid_xlevel2; @@ -3140,6 +3147,22 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index,= uint32_t count, *edx =3D 0; break; } + + /* Do CPUID overrides: */ + if (cpu->cpuid_leaf && cpu->cpuid_leaf =3D=3D index) { + + if (cpu->eax) + *eax =3D cpu->eax; + + if (cpu->ebx) + *ebx =3D cpu->ebx; + + if (cpu->ecx) + *ecx =3D cpu->ecx; + + if (cpu->edx) + *edx =3D cpu->edx; + } } =20 /* CPUClass::reset() */ @@ -4173,6 +4196,11 @@ static Property x86_cpu_properties[] =3D { * to the specific Windows version being used." */ DEFINE_PROP_INT32("x-hv-max-vps", X86CPU, hv_max_vps, -1), + DEFINE_PROP_UINT32("cpuid-leaf", X86CPU, cpuid_leaf, UINT32_MAX), + DEFINE_PROP_UINT32("eax", X86CPU, eax, UINT32_MAX), + DEFINE_PROP_UINT32("ebx", X86CPU, ebx, UINT32_MAX), + DEFINE_PROP_UINT32("ecx", X86CPU, ecx, UINT32_MAX), + DEFINE_PROP_UINT32("edx", X86CPU, edx, UINT32_MAX), DEFINE_PROP_END_OF_LIST() }; =20 diff --git a/target/i386/cpu.h b/target/i386/cpu.h index b086b1528b89..b336b0849456 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1284,6 +1284,13 @@ struct X86CPU { int32_t thread_id; =20 int32_t hv_max_vps; + + /* + * CPUID overrides: + */ + uint32_t cpuid_leaf; + uint32_t eax, ebx, ecx, edx; + }; =20 static inline X86CPU *x86_env_get_cpu(CPUX86State *env) --=20 Regards/Gruss, Boris. Good mailing practices for 400: avoid top-posting and trim the reply.