From nobody Sun May 19 05:00:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1687126942; cv=none; d=zohomail.com; s=zohoarc; b=WrmDM1eglpk2SkOYMnURGkfzd1njw7czFR0HAId0e7+nIrrtM3v0gJT5WGQYY7PR1P7UM4ZxXzGe/PO3nlQ05Dy+cBU7kwB+O3DjvxTDK917bUFtJVsNocl5uD6yFNvHfHLNpFi5gq/9Fkr0IBqbnnt11xEJmxFRLNep3yHbauo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687126942; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SUEMlH5Vi9AGcf6+yYyykWVYaFzccZ57zOHtQD3Xf7Q=; b=Y6So3cZydrU8QFEHGDdZ40UBV8iyhmWdZ5T1Obl9kan5g63yzun03+TuQmIwzxRUssq2KSPBACjIdwdtAqQnMto2W3R95WOB6lhEJUB0RUXL/C0R9T+0TAp3rEniF7iMfCEPaEX9u0+fg/Wr3HyMA07H+GuMH00xlQx8Ff3Q21k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1687126942051721.0978984232037; Sun, 18 Jun 2023 15:22:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qB0ls-0002lv-JC; Sun, 18 Jun 2023 18:21:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qB0lr-0002lk-Ky for qemu-devel@nongnu.org; Sun, 18 Jun 2023 18:21:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qB0lq-0004V3-66 for qemu-devel@nongnu.org; Sun, 18 Jun 2023 18:21:19 -0400 Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-567-oZ3V_eapMu2Ad5mDr2n2mg-1; Sun, 18 Jun 2023 18:21:15 -0400 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-94a35b0d4ceso161957866b.3 for ; Sun, 18 Jun 2023 15:21:14 -0700 (PDT) Received: from [192.168.60.219] (server.hotelpassage.eu. [88.146.207.194]) by smtp.gmail.com with ESMTPSA id bk4-20020a170906b0c400b0096f675ce45csm13722542ejb.182.2023.06.18.15.21.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jun 2023 15:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687126876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=SUEMlH5Vi9AGcf6+yYyykWVYaFzccZ57zOHtQD3Xf7Q=; b=FKIfrS03sjHo3WcgtrYvRkD9e3vkNHOPmv4gsBXLBdzSRc4P+IMdOYnMtol0gqmgbizHH9 bgNq6j+Ok/BE1O+ZM1FwmBzmuTTI1/NMlizriU2D9beBB0Xl9kKm4H1N2RAPSljWa7gGfr fZEzH1xJgFQm3Fi9m8z0F7XB95ahITI= X-MC-Unique: oZ3V_eapMu2Ad5mDr2n2mg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687126873; x=1689718873; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SUEMlH5Vi9AGcf6+yYyykWVYaFzccZ57zOHtQD3Xf7Q=; b=fgNG1+FmmWMySExPHn9aP60kIv1PTaqWO1WYs9g5o/f5KgB+f8mPx2rJ9RUtv89oEk vz6bLr6BpKWGoH8xZ08p/8a924gP3EcT0oBVCbiWmFz/nZeswCIBRZvLNFt0MsU0L3CQ t52NkDjLBSsgbKuonP3JsONSkmc6E70uRxU9XZifndMpghI3LLRJDGiUjZ9b295jWCfO skPcgV5nWSIpR4ssBm/mu9xOT5l9Ud0nMQG7nVPBd6P9I4Drp1F+VvzM9Y4aN0aQIywP tpxJx8JiEZ0b23Jxb9+MS/avi56XV5xQopaZ29qOlk6W9IgXXKSaljezIlUr6wshmZcX Eiow== X-Gm-Message-State: AC+VfDwHo2TcY7D+1RCXknt4V9Y4mkRHr7YY3XrCCpHMUNQX4neWXq2J Qk3LflQxaqUxMNR4cF2qtLNP+U2imSQ0SZZi3JamdG9GBZK3VAjQQ1jBD1YJusuP0qXQwT1hldh bqExrKlrrgvD57olrb5M63UVHZix3sfomKdP+IzxDs8fQDE8e656zWbrmh9Y+FvpRZxyP2U4zqG MCTA== X-Received: by 2002:a17:906:d542:b0:982:7505:fafa with SMTP id cr2-20020a170906d54200b009827505fafamr6679770ejc.47.1687126873715; Sun, 18 Jun 2023 15:21:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ76wxnfo/uCq1LSJUX2D/1R8dOpwt1o86Nq+uqpfj1HFViaC5r6hrqEZr+cRgqWSWwESYHz/g== X-Received: by 2002:a17:906:d542:b0:982:7505:fafa with SMTP id cr2-20020a170906d54200b009827505fafamr6679766ejc.47.1687126873314; Sun, 18 Jun 2023 15:21:13 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 1/2] target/i386: ignore ARCH_CAPABILITIES features in user mode emulation Date: Mon, 19 Jun 2023 00:21:08 +0200 Message-Id: <20230618222109.110843-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230618222109.110843-1-pbonzini@redhat.com> References: <20230618222109.110843-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1687126943477100004 Content-Type: text/plain; charset="utf-8" ARCH_CAPABILITIES is only accessible through a read-only MSR, so it has no impact on any user-mode operation (user-mode cannot read the MSR). So do not bother printing warnings about it in user mode emulation. Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index dec376ab56d..f4ad6d58609 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -1069,6 +1069,13 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] =3D= { .msr =3D { .index =3D MSR_IA32_ARCH_CAPABILITIES, }, + /* + * FEAT_ARCH_CAPABILITIES only affects a read-only MSR, which + * cannot be read from user mode. Therefore, it has no impact + > on any user-mode operation, and warnings about unsupported + * features do not matter. + */ + .tcg_features =3D ~0U, }, [FEAT_CORE_CAPABILITY] =3D { .type =3D MSR_FEATURE_WORD, --=20 2.40.1 From nobody Sun May 19 05:00:19 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1687126942; cv=none; d=zohomail.com; s=zohoarc; b=dPoAkpHpToP6/sHB5sKLXPoP62cEVFvA6IhRJoLCo5eaLrMrDxG1bLWEGU4v1ugRlhSCLd1HRxDQuc1GminYkk7zmPZCqPFNL9ygD6UOshv+W6eurN4cPpQ5duz5hWUBxOcui6b7wyvus+0BoGM5SRN8kydiWC2BrBrlLQ8AOxQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1687126942; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XVJPd5EiR4cU0nWZ/oi6is30khRgS/W/gWxn+4Hdo/U=; b=g6CS4T+jBna1VwN68qJ8ptg6kzQ+kGlB+kBJoickrtqm4YKms8jL5DENUac1hEYpCmvJPapET1sQOuqAUyp7pUhcg53nUOubLxYtEFTPIQ3yUAnwG/hZORw81OMuFN5LJw8pf17epDceBFleDs5XHUwZ09Um2po7mqgU4IZUnXY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1687126942113926.9935315950083; Sun, 18 Jun 2023 15:22:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qB0lw-0002mQ-52; Sun, 18 Jun 2023 18:21:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qB0lu-0002mI-ET for qemu-devel@nongnu.org; Sun, 18 Jun 2023 18:21:22 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qB0ls-0004WY-I0 for qemu-devel@nongnu.org; Sun, 18 Jun 2023 18:21:22 -0400 Received: from mail-lj1-f198.google.com (mail-lj1-f198.google.com [209.85.208.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-198-1M-sLUSAMK6E8r68_3r3yw-1; Sun, 18 Jun 2023 18:21:17 -0400 Received: by mail-lj1-f198.google.com with SMTP id 38308e7fff4ca-2b45bf52675so15320021fa.3 for ; Sun, 18 Jun 2023 15:21:17 -0700 (PDT) Received: from [192.168.60.219] (server.hotelpassage.eu. [88.146.207.194]) by smtp.gmail.com with ESMTPSA id s8-20020a1709066c8800b0098877b10de7sm1344962ejr.193.2023.06.18.15.21.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jun 2023 15:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687126879; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XVJPd5EiR4cU0nWZ/oi6is30khRgS/W/gWxn+4Hdo/U=; b=UJAJP5dftpSoj5Vp4qDjqIkz9thSGwPo2nArK/00aKEQ3Udrq0WkYmdcsWR5n00J04lgBc 8pKR06zv6Z3KcpbYF3G8ejn3XYvLJvPmqvyo1haEoQivHy1o82DHNIFv83jxj7I6HzoxaE v8BKNL1ENX/R0jrhwKcEgo5wSBSibeU= X-MC-Unique: 1M-sLUSAMK6E8r68_3r3yw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687126876; x=1689718876; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XVJPd5EiR4cU0nWZ/oi6is30khRgS/W/gWxn+4Hdo/U=; b=Xe+wNsKRgSA1aJ1OJ5nLp5ci4J/GZtoS2gn/UkL6tVAEWuB4EMUyr0nALzI6An+2uo q4LEd0OxgwwbtU9kJCXQQfTXppS475NEi98ZvHH1ARWGFrqlmRFr/lvUJ/hdv+tV5eHt kd/VWj/bzwHyAKS48TuJ19UPLehVwxdfRpDWCsrpX+Ny5/5RcODTA1ZHmEevu1f7eelT KQkAbd3YS5b1rdacj+/6al6SACfGIbZk2JR+8QJgbpjbF8hZ5uuZCGL65TRovCgTTMU8 5p2VECKtO0wdk+HCUg8jOCVyFsKyjoIuknw9pmX2hOBHjO0rlM9ublnVl4mpBLwmi6ga DeWg== X-Gm-Message-State: AC+VfDzTVnEbWRYvM9k//NRXXAMrIGFAJYwb5Ji8LC9GVq4sKY5TJtNh LyaWScjp6ktEdi863jP/mNHumqD3om4T/pGP8iBGmBXOBK+hlecONZiCN4oXXl7WZxVjy9hLGYk tVw3J5b/tHZasA/7rKuy0AXMSB4hNF7iXJPDXVbLkZgGPEoVnrtl4oIPzGeY2jKw2zaXk0bGLIt CiIQ== X-Received: by 2002:a2e:8315:0:b0:2b3:44bb:2180 with SMTP id a21-20020a2e8315000000b002b344bb2180mr4135139ljh.40.1687126875813; Sun, 18 Jun 2023 15:21:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6FvmsvltftojXC+Jej6gocWq+QF4SC2ZeXJUH176jHHPAFTR6s7D7kSqb6H4jnpgIgn9Lq/g== X-Received: by 2002:a2e:8315:0:b0:2b3:44bb:2180 with SMTP id a21-20020a2e8315000000b002b344bb2180mr4135130ljh.40.1687126875299; Sun, 18 Jun 2023 15:21:15 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PATCH 2/2] target/i386: ignore CPL0-specific features in user mode emulation Date: Mon, 19 Jun 2023 00:21:09 +0200 Message-Id: <20230618222109.110843-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230618222109.110843-1-pbonzini@redhat.com> References: <20230618222109.110843-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1687126943100100001 Content-Type: text/plain; charset="utf-8" Features such as PCID are only accessible through privileged operations, and therefore have no impact on any user-mode operation. Allow reporting them to programs running under user mode emulation, so that "-cpu" can be used with more named CPU models. XSAVES would be similar, but it doesn't make sense to provide it until XSAVEC is implemented. With this change, all CPUs up to Broadwell-v4 can be specified on the command line without producing warnings. Skylake-Client requires XSAVEC (as well as hiding XSAVES). In addition to XSAVEC and XSAVES, EPYC also requires SHA-NI, MISALIGNSSE and TOPOEXT. MISALIGNSSE is not hard to implement, but I am not sure it is worth using a precious hflags bit for it. TOPOEXT is related to CPUID 0x8000001E which is implemented, but I am not sure it makes much sense to add it as long as apic_id is always zero in user-mode emulation. Perhaps, instead of cpu->apic_id, user-mode emulation could use the host CPU number from getcpu(2). Fixes: https://gitlab.com/qemu-project/qemu/-/issues/1517 Fixes: https://gitlab.com/qemu-project/qemu/-/issues/1534 Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 88 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 9 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index f4ad6d58609..35b85c086b2 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -623,41 +623,94 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t ven= dor1, CPUID_MTRR, CPUID_MCA, CPUID_CLFLUSH (needed for Win64) */ /* missing: CPUID_VME, CPUID_DTS, CPUID_SS, CPUID_HT, CPUID_TM, CPUID_PBE */ + +/* + * Kernel-only features that can be shown to usermode programs even if + * they aren't actually supported by TCG, because qemu-user only runs + * in CPL=3D3; remove them if they are ever implemented for system emulati= on. + */ +#if defined CONFIG_USER_ONLY +#define CPUID_EXT_KERNEL_FEATURES (CPUID_EXT_PCID | CPUID_EXT_TSC_DEADLINE= _TIMER | \ + CPUID_EXT_X2APIC) +#else +#define CPUID_EXT_KERNEL_FEATURES 0 +#endif #define TCG_EXT_FEATURES (CPUID_EXT_SSE3 | CPUID_EXT_PCLMULQDQ | \ CPUID_EXT_MONITOR | CPUID_EXT_SSSE3 | CPUID_EXT_CX16 | \ CPUID_EXT_SSE41 | CPUID_EXT_SSE42 | CPUID_EXT_POPCNT | \ CPUID_EXT_XSAVE | /* CPUID_EXT_OSXSAVE is dynamic */ \ CPUID_EXT_MOVBE | CPUID_EXT_AES | CPUID_EXT_HYPERVISOR | \ CPUID_EXT_RDRAND | CPUID_EXT_AVX | CPUID_EXT_F16C | \ - CPUID_EXT_FMA) + CPUID_EXT_FMA | CPUID_EXT_KERNEL_FEATURES) /* missing: CPUID_EXT_DTES64, CPUID_EXT_DSCPL, CPUID_EXT_VMX, CPUID_EXT_SMX, CPUID_EXT_EST, CPUID_EXT_TM2, CPUID_EXT_CID, CPUID_EXT_XTPR, CPUID_EXT_PDCM, CPUID_EXT_PCID, CPUID_EXT_DCA, CPUID_EXT_X2APIC, CPUID_EXT_TSC_DEADLINE_TIMER */ =20 #ifdef TARGET_X86_64 #define TCG_EXT2_X86_64_FEATURES CPUID_EXT2_LM #else #define TCG_EXT2_X86_64_FEATURES 0 #endif =20 +/* + * CPUID_*_KERNEL_FEATURES denotes bits and features that are not usable + * in usermode or by 32-bit programs. Those are added to supported + * TCG features unconditionally in user-mode emulation mode. This may + * indeed seem strange or incorrect, but it works because code running + * under usermode emulation cannot access them. + * + * Even for long mode, qemu-i386 is not running "a userspace program on a + * 32-bit CPU"; it's running "a userspace program with a 32-bit code segme= nt" + * and therefore using the 32-bit ABI; the CPU itself might be 64-bit + * but again the difference is only visible in kernel mode. + */ +#if defined CONFIG_USER_ONLY +#define CPUID_EXT2_KERNEL_FEATURES (CPUID_EXT2_LM | CPUID_EXT2_FFXSR) +#else +#define CPUID_EXT2_KERNEL_FEATURES 0 +#endif + #define TCG_EXT2_FEATURES ((TCG_FEATURES & CPUID_EXT2_AMD_ALIASES) | \ CPUID_EXT2_NX | CPUID_EXT2_MMXEXT | CPUID_EXT2_RDTSCP | \ CPUID_EXT2_3DNOW | CPUID_EXT2_3DNOWEXT | CPUID_EXT2_PDPE1GB | \ - CPUID_EXT2_SYSCALL | TCG_EXT2_X86_64_FEATURES) + CPUID_EXT2_SYSCALL | TCG_EXT2_X86_64_FEATURES | \ + CPUID_EXT2_KERNEL_FEATURES) + +#if defined CONFIG_USER_ONLY +#define CPUID_EXT3_KERNEL_FEATURES CPUID_EXT3_OSVW +#else +#define CPUID_EXT3_KERNEL_FEATURES 0 +#endif + #define TCG_EXT3_FEATURES (CPUID_EXT3_LAHF_LM | CPUID_EXT3_SVM | \ CPUID_EXT3_CR8LEG | CPUID_EXT3_ABM | CPUID_EXT3_SSE4A | \ - CPUID_EXT3_3DNOWPREFETCH) + CPUID_EXT3_3DNOWPREFETCH | CPUID_EXT3_KERNEL_FEATURES) + #define TCG_EXT4_FEATURES 0 + +#if defined CONFIG_USER_ONLY +#define CPUID_SVM_KERNEL_FEATURES (CPUID_SVM_NRIPSAVE | CPUID_SVM_VNMI) +#else +#define CPUID_SVM_KERNEL_FEATURES 0 +#endif #define TCG_SVM_FEATURES (CPUID_SVM_NPT | CPUID_SVM_VGIF | \ - CPUID_SVM_SVME_ADDR_CHK) + CPUID_SVM_SVME_ADDR_CHK | CPUID_SVM_KERNEL_FEATURES) + #define TCG_KVM_FEATURES 0 + +#if defined CONFIG_USER_ONLY +#define CPUID_7_0_EBX_KERNEL_FEATURES CPUID_7_0_EBX_INVPCID +#else +#define CPUID_7_0_EBX_KERNEL_FEATURES 0 +#endif #define TCG_7_0_EBX_FEATURES (CPUID_7_0_EBX_SMEP | CPUID_7_0_EBX_SMAP | \ CPUID_7_0_EBX_BMI1 | CPUID_7_0_EBX_BMI2 | CPUID_7_0_EBX_ADX | \ CPUID_7_0_EBX_PCOMMIT | CPUID_7_0_EBX_CLFLUSHOPT | \ CPUID_7_0_EBX_CLWB | CPUID_7_0_EBX_MPX | CPUID_7_0_EBX_FSGSBASE = | \ - CPUID_7_0_EBX_ERMS | CPUID_7_0_EBX_AVX2 | CPUID_7_0_EBX_RDSEED) + CPUID_7_0_EBX_ERMS | CPUID_7_0_EBX_AVX2 | CPUID_7_0_EBX_RDSEED |= \ + CPUID_7_0_EBX_KERNEL_FEATURES) /* missing: CPUID_7_0_EBX_HLE CPUID_7_0_EBX_INVPCID, CPUID_7_0_EBX_RTM */ @@ -672,7 +725,14 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vend= or1, CPUID_7_0_ECX_LA57 | CPUID_7_0_ECX_PKS | CPUID_7_0_ECX_VAES | \ TCG_7_0_ECX_RDPID) =20 -#define TCG_7_0_EDX_FEATURES CPUID_7_0_EDX_FSRM +#if defined CONFIG_USER_ONLY +#define CPUID_7_0_EDX_KERNEL_FEATURES (CPUID_7_0_EDX_SPEC_CTRL | \ + CPUID_7_0_EDX_ARCH_CAPABILITIES | CPUID_7_0_EDX_SPEC_CTRL_SSBD) +#else +#define CPUID_7_0_EDX_KERNEL_FEATURES 0 +#endif +#define TCG_7_0_EDX_FEATURES (CPUID_7_0_EDX_FSRM | CPUID_7_0_EDX_KERNEL_FE= ATURES) + #define TCG_7_1_EAX_FEATURES (CPUID_7_1_EAX_FZRM | CPUID_7_1_EAX_FSRS | \ CPUID_7_1_EAX_FSRC) #define TCG_7_1_EDX_FEATURES 0 @@ -686,8 +746,17 @@ void x86_cpu_vendor_words2str(char *dst, uint32_t vend= or1, #define TCG_SGX_12_0_EBX_FEATURES 0 #define TCG_SGX_12_1_EAX_FEATURES 0 =20 +#if defined CONFIG_USER_ONLY +#define CPUID_8000_0008_EBX_KERNEL_FEATURES (CPUID_8000_0008_EBX_IBPB | \ + CPUID_8000_0008_EBX_IBRS | CPUID_8000_0008_EBX_STIBP | \ + CPUID_8000_0008_EBX_STIBP_ALWAYS_ON | CPUID_8000_0008_EBX_AMD_SS= BD | \ + CPUID_8000_0008_EBX_AMD_PSFD) +#else +#define CPUID_8000_0008_EBX_KERNEL_FEATURES 0 +#endif + #define TCG_8000_0008_EBX (CPUID_8000_0008_EBX_XSAVEERPTR | \ - CPUID_8000_0008_EBX_WBNOINVD) + CPUID_8000_0008_EBX_WBNOINVD | CPUID_8000_0008_EBX_KERNEL_FEATUR= ES) =20 FeatureWordInfo feature_word_info[FEATURE_WORDS] =3D { [FEAT_1_EDX] =3D { @@ -5469,7 +5538,8 @@ uint64_t x86_cpu_get_supported_feature_word(FeatureWo= rd w, return ~0; } #ifndef TARGET_X86_64 - if (w =3D=3D FEAT_8000_0001_EDX) { + if (w =3D=3D FEAT_8000_0001_EDX + && (!tcg_enabled() || !CPUID_EXT2_KERNEL_FEATURES)) { r &=3D ~CPUID_EXT2_LM; } #endif --=20 2.40.1