From patchwork Thu Nov 23 13:13:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Borislav Petkov X-Patchwork-Id: 10072777 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DDADB602DC for ; Thu, 23 Nov 2017 13:14:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD13F2A044 for ; Thu, 23 Nov 2017 13:14:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C02532A051; Thu, 23 Nov 2017 13:14:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7C5F22A044 for ; Thu, 23 Nov 2017 13:14:22 +0000 (UTC) Received: from localhost ([::1]:44289 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHrKf-0001UQ-PN for patchwork-qemu-devel@patchwork.kernel.org; Thu, 23 Nov 2017 08:14:21 -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 X-Virus-Scanned: Nedap ESD1 at mail.skyhub.de 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) 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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=0x80000007,ebx=0xf 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]; + /* + * 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 = cpu->cpuid_leaf; + /* Calculate & apply limits for different index ranges */ if (index >= 0xC0000000) { limit = env->cpuid_xlevel2; @@ -3140,6 +3147,22 @@ void cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count, *edx = 0; break; } + + /* Do CPUID overrides: */ + if (cpu->cpuid_leaf && cpu->cpuid_leaf == index) { + + if (cpu->eax) + *eax = cpu->eax; + + if (cpu->ebx) + *ebx = cpu->ebx; + + if (cpu->ecx) + *ecx = cpu->ecx; + + if (cpu->edx) + *edx = cpu->edx; + } } /* CPUClass::reset() */ @@ -4173,6 +4196,11 @@ static Property x86_cpu_properties[] = { * 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() }; 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; int32_t hv_max_vps; + + /* + * CPUID overrides: + */ + uint32_t cpuid_leaf; + uint32_t eax, ebx, ecx, edx; + }; static inline X86CPU *x86_env_get_cpu(CPUX86State *env)