From nobody Wed Nov 12 11:49:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1570208883; cv=none; d=zoho.com; s=zohoarc; b=nmWon335KDAPPoD9vvnBDwEuL+3Yvelog7YFGvul1q/bJSFk2TN0Y0cusB/Ad95mlhkOoyeBeXjg4Gx/hSSP9a0i9sq81l4dYzvBVRV3+1kY5dBoV3gbXTiIPRWV4JIOTxxFPtxZXk2fwDe4qeepcC9hxwqrKJkGSe8yPcOpKTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570208883; h=Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=qws3AYzCutn9xQ5O+LYFZoPZNCpiVmvp4O0IhNmQG3Y=; b=FTvRmX12tdsQm8CS6Goa5B/BiDjLiEKXLmH75bSGuSM3b39U/1QD+mP/VtWBzG/jObd/biGtMhGt+EcjUqEZ05B+cY5u5uLNFO9eNWnqbOKUOsUp2g4Wll9aFX3IDAJQ20cynSvIC1GjOmuZaPcgLoZP1J2HcF+MYtqgoiAgyTM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1570208883412426.5187667009127; Fri, 4 Oct 2019 10:08:03 -0700 (PDT) Received: from localhost ([::1]:50658 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iGR3c-0003NY-FN for importer@patchew.org; Fri, 04 Oct 2019 13:07:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51083) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iGQvU-0007Mh-3B for qemu-devel@nongnu.org; Fri, 04 Oct 2019 12:59:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iGQvS-0001tg-S0 for qemu-devel@nongnu.org; Fri, 04 Oct 2019 12:59:31 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]:36369) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iGQvS-0001tG-M4 for qemu-devel@nongnu.org; Fri, 04 Oct 2019 12:59:30 -0400 Received: by mail-wr1-x430.google.com with SMTP id y19so8098544wrd.3 for ; Fri, 04 Oct 2019 09:59:30 -0700 (PDT) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id u7sm7041270wrp.19.2019.10.04.09.59.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 09:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=qws3AYzCutn9xQ5O+LYFZoPZNCpiVmvp4O0IhNmQG3Y=; b=jk1oh+XIQ3vWNX+vthQbuG2uuOF6nzv7bA2OKv4OQXfzWmNHQlVQquTKTurvEhCWKS Z4jd68HmxmVz94frarP0ur+6rXNRZLPMBw6gUbe9h9+OG4RyjRS0DQco0tofJQsQfBq+ AWPN5pOZ5oUIjxOZxw4nrUPCJdB1esQiNC2ksmJopk89POtC9nGug+68iDvsArUh4oCq uM8VIvejCuME2Q64lmqVKb0Oh0isrsI4FS9J17I9a2x1UnwmGv99IEc2XaBNZ3e9lERU wOpoEbZi+uG8CdSi8NlnRjfQvcV3ifTL0/WaiDISEWtzxZLl/Yz0YOixjXGuWvLoTiBC 6pZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=qws3AYzCutn9xQ5O+LYFZoPZNCpiVmvp4O0IhNmQG3Y=; b=gZCsQR+k98huJsyCQkQahoMbRIlA9gvfg5YWXznjEhuCHTOq0+AI5FWKNot2l5316d /Ku0lwtxLIeemM5y8yMMetRrTxr92gXtP/HYPkoRIHqZm3ep8VDBose0xbTK4AN+gVJS SrzW4yY+sMq8fHTxLyURaEvuggmkTOlsOifryRanQXsFqOiQGiq2/GrZrbrobCWb6xwx xU4eUkhOpA4aFPnbGiR2y7HakNZqTooW3tulfNUmQV8KfJEOBbsv0zu2sJh4AeRwXFlB OFzTCI9PW1a8sV3ReDn1Njl296KM8vkajy+6SlAdeIygn8bdsP/dVaGbbJ/a0QJcnf2n MG4A== X-Gm-Message-State: APjAAAUdICNAh0i6+V56ggR4p/w4Dp9Lnp9arn/58tbp1BvmXmPWABCV Xx8PVsVmkVRrernXOF6VVIrGLP9b X-Google-Smtp-Source: APXvYqyPrOc2LfmuUk76U/dkURDUt5+zmPxh5z8TZVN4pV5ubZ/zMTFqG7OxFcAF+aYWN/N8370n7A== X-Received: by 2002:a5d:4c45:: with SMTP id n5mr13329839wrt.100.1570208369009; Fri, 04 Oct 2019 09:59:29 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 23/29] target/i386: introduce generic feature dependency mechanism Date: Fri, 4 Oct 2019 18:59:17 +0200 Message-Id: <1570208363-11948-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1570208363-11948-1-git-send-email-pbonzini@redhat.com> References: <1570208363-11948-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::430 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Sometimes a CPU feature does not make sense unless another is present. In the case of VMX features, KVM does not even allow setting the VMX controls to some invalid combinations. Therefore, this patch adds a generic mechanism that looks for bits that the user explicitly cleared, and uses them to remove other bits from the expanded CPU definition. If these dependent bits were also explicitly *set* by the user, this will be a warning for "-cpu check" and an error for "-cpu enforce". If not, then the dependent bits are cleared silently, for convenience. With VMX features, this will be used so that for example "-cpu host,-rdrand" will also hide support for RDRAND exiting. Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 72 ++++++++++++++++++++++++++++++++++++---------------= ---- 1 file changed, 48 insertions(+), 24 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 83f8981..35d868d 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -801,10 +801,6 @@ typedef struct FeatureWordInfo { /* If type=3D=3DMSR_FEATURE_WORD */ struct { uint32_t index; - struct { /*CPUID that enumerate this MSR*/ - FeatureWord cpuid_class; - uint32_t cpuid_flag; - } cpuid_dep; } msr; }; uint32_t tcg_features; /* Feature flags supported by TCG */ @@ -1218,10 +1214,6 @@ static FeatureWordInfo feature_word_info[FEATURE_WOR= DS] =3D { }, .msr =3D { .index =3D MSR_IA32_ARCH_CAPABILITIES, - .cpuid_dep =3D { - FEAT_7_0_EDX, - CPUID_7_0_EDX_ARCH_CAPABILITIES - } }, }, [FEAT_CORE_CAPABILITY] =3D { @@ -1238,14 +1230,30 @@ static FeatureWordInfo feature_word_info[FEATURE_WO= RDS] =3D { }, .msr =3D { .index =3D MSR_IA32_CORE_CAPABILITY, - .cpuid_dep =3D { - FEAT_7_0_EDX, - CPUID_7_0_EDX_CORE_CAPABILITY, - }, }, }, }; =20 +typedef struct FeatureMask { + FeatureWord index; + uint32_t mask; +} FeatureMask; + +typedef struct FeatureDep { + FeatureMask from, to; +} FeatureDep; + +static FeatureDep feature_dependencies[] =3D { + { + .from =3D { FEAT_7_0_EDX, CPUID_7_0_EDX_ARCH_CAPABILIT= IES }, + .to =3D { FEAT_ARCH_CAPABILITIES, ~0u }, + }, + { + .from =3D { FEAT_7_0_EDX, CPUID_7_0_EDX_CORE_CAPABILIT= Y }, + .to =3D { FEAT_CORE_CAPABILITY, ~0u }, + }, +}; + typedef struct X86RegisterInfo32 { /* Name of register */ const char *name; @@ -5063,9 +5071,26 @@ static void x86_cpu_expand_features(X86CPU *cpu, Err= or **errp) { CPUX86State *env =3D &cpu->env; FeatureWord w; + int i; GList *l; Error *local_err =3D NULL; =20 + for (l =3D plus_features; l; l =3D l->next) { + const char *prop =3D l->data; + object_property_set_bool(OBJECT(cpu), true, prop, &local_err); + if (local_err) { + goto out; + } + } + + for (l =3D minus_features; l; l =3D l->next) { + const char *prop =3D l->data; + object_property_set_bool(OBJECT(cpu), false, prop, &local_err); + if (local_err) { + goto out; + } + } + /*TODO: Now cpu->max_features doesn't overwrite features * set using QOM properties, and we can convert * plus_features & minus_features to global properties @@ -5083,19 +5108,18 @@ static void x86_cpu_expand_features(X86CPU *cpu, Er= ror **errp) } } =20 - for (l =3D plus_features; l; l =3D l->next) { - const char *prop =3D l->data; - object_property_set_bool(OBJECT(cpu), true, prop, &local_err); - if (local_err) { - goto out; - } - } + for (i =3D 0; i < ARRAY_SIZE(feature_dependencies); i++) { + FeatureDep *d =3D &feature_dependencies[i]; + if (!(env->features[d->from.index] & d->from.mask)) { + uint32_t unavailable_features =3D env->features[d->to.index] &= d->to.mask; =20 - for (l =3D minus_features; l; l =3D l->next) { - const char *prop =3D l->data; - object_property_set_bool(OBJECT(cpu), false, prop, &local_err); - if (local_err) { - goto out; + /* Not an error unless the dependent feature was added explici= tly. */ + mark_unavailable_features(cpu, d->to.index, + unavailable_features & env->user_fea= tures[d->to.index], + "This feature depends on other featu= res that were not requested"); + + env->user_features[d->to.index] |=3D unavailable_features; + env->features[d->to.index] &=3D ~unavailable_features; } } =20 --=20 1.8.3.1