From nobody Tue Feb 10 06:25:01 2026 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=1562080137; cv=none; d=zoho.com; s=zohoarc; b=h8aKwZak/51CCNWRWY+JEQBmYGgNx+vNm2f/wFcmm+G7KhaaFstzYIid78k+l2Ln5/QpBY0ftlOku8NwVI7XeqkUNdTfovwrncMD4hMr0JgUN5jg0N85/H3ro7A4Lxh1UR5jUFKbUDHRMUh+JeVNHpeZyV+R06TALJMAIkkqM+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562080137; h=Cc: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=l+HvfXgsR2im8E+Ar9XqWafF5GI151pZVuknRW+lRlo=; b=EY8k3aasfSbkJBQShBSY1DwfPAS/tiuQIT6P/ToJyUJ/4mnK9Tr2yeYeqS/otMGxVGq1wZgM5P3iO9FofrkCjz+7oRZjc52Cl5SC7gyBDYguAtBt005006lG/rO/XKhOhkhid0F8COfM4jmHS8uHiNaiv0oRtP3buHlLgXCENbc= 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 1562080137335858.7737581228107; Tue, 2 Jul 2019 08:08:57 -0700 (PDT) Received: from localhost ([::1]:54320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hiKOs-0006vo-Br for importer@patchew.org; Tue, 02 Jul 2019 11:08:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57008) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hiKI7-0001hN-QD for qemu-devel@nongnu.org; Tue, 02 Jul 2019 11:02:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hiKI5-0004hf-TU for qemu-devel@nongnu.org; Tue, 02 Jul 2019 11:01:55 -0400 Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]:37170) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hiKI3-0004QQ-Rc for qemu-devel@nongnu.org; Tue, 02 Jul 2019 11:01:52 -0400 Received: by mail-wm1-x341.google.com with SMTP id f17so1402680wme.2 for ; Tue, 02 Jul 2019 08:01:27 -0700 (PDT) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id m24sm3006262wmi.39.2019.07.02.08.01.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Jul 2019 08:01:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=l+HvfXgsR2im8E+Ar9XqWafF5GI151pZVuknRW+lRlo=; b=Cin77Rru8tOXgrIIlyH1HATi306+b2U/7Oh5x+Jij5UbXwF/fz3hbM0b32RAuzkUQ2 sxNGCHczs3BHpi1jlvwNW1GBTQu4NMmc5nNfWNERY97qzu6ptXwOsmT1JmO5quGHQyOy tyPBY3UMTAY1UZ5zXBhPNUYxvIDOGDhe71N1KL2b8IjAUbmOIKvrbS8zMBtLvfs9VK+W tLUGecaebSbFey2VBV8wfEuwfen+zEQSRmD8Rwkrxl/T8rkEKuyabMdNjxAmE7XDuD9d xYNr0TYaO8loJCYCOtEVb8nXdwjOxV7vmPYQAoECMnqNKJ4/nLtCL/sQKaKm789rtCj6 30xg== 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:cc:subject:date:message-id :in-reply-to:references; bh=l+HvfXgsR2im8E+Ar9XqWafF5GI151pZVuknRW+lRlo=; b=PxKypkdy2atgH9zvpNjzP8slDf+9kXHPR1GOu13hQUaSgRPyyhA6n2KTi8w9pJkg// MuT5PolmP0C19xkh4k28wtTplXgkteDEOvakyw5Os9qFZMJe+asAMPaxaveDcslGunlT JUKqPisWYJ2pCldfA8NtqJY5rLT1yOCxEtIvw9TwxwKqX6CSj35b0XZOitcP+7D9C7b2 RFIWnDgJJPDdACxObZMlRrb+jdQg9ZGGNvoxS44OJrrmUBy3IYEN+52zxt+2IzW5B8i6 RUztXshAjv5BO0MOidTv5BKOyVSoQ+JP7TU7Udsj9WRUVMLtVCzYgttGRcU+IWtLTT+/ O9ag== X-Gm-Message-State: APjAAAULP83ee8sYOi39NRfHevN/51VdQv/+Y1EAPovQSPqdQcRv/Twk Z9OzF+Q4kgUZ+LCxkCWh4Dcx8npy+kk= X-Google-Smtp-Source: APXvYqxzEKHqYLvOz6ocgRZV/yBrEgZwTzHO/SThXrAwIWesyUZ7QW/8ODhmMGoBBcGt9g/nkZafbA== X-Received: by 2002:a1c:7d4e:: with SMTP id y75mr3784875wmc.169.1562079685626; Tue, 02 Jul 2019 08:01:25 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 2 Jul 2019 17:01:16 +0200 Message-Id: <1562079681-19204-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1562079681-19204-1-git-send-email-pbonzini@redhat.com> References: <1562079681-19204-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::341 Subject: [Qemu-devel] [PATCH 2/7] target/i386: introduce generic feature dependency mechanism 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: , Cc: Liran Alon , Eduardo Habkost 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 | 77 +++++++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 49 insertions(+), 28 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 9149d0d..412e834 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -799,10 +799,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 */ @@ -1197,10 +1193,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 { @@ -1217,14 +1209,26 @@ 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 FeatureDep { + uint16_t from, to; + uint64_t from_flag, to_flags; +} FeatureDep; + +static FeatureDep feature_dependencies[] =3D { + { + .from =3D FEAT_7_0_EDX, .from_flag =3D CPUID_7_0_EDX_AR= CH_CAPABILITIES, + .to =3D FEAT_ARCH_CAPABILITIES, .to_flags =3D ~0ull, + }, + { + .from =3D FEAT_7_0_EDX, .from_flag =3D CPUID_7_0_EDX_CO= RE_CAPABILITY, + .to =3D FEAT_CORE_CAPABILITY, .to_flags =3D ~0ull, + }, +}; + typedef struct X86RegisterInfo32 { /* Name of register */ const char *name; @@ -5086,9 +5090,42 @@ 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; + } + } + + for (i =3D 0; i < ARRAY_SIZE(feature_dependencies); i++) { + FeatureDep *d =3D &feature_dependencies[i]; + if ((env->user_features[d->from] & d->from_flag) && + !(env->features[d->from] & d->from_flag)) { + uint64_t unavailable_features =3D env->features[d->to] & d->to= _flags; + + /* Not an error unless the dependent feature was added explici= tly. */ + mark_unavailable_features(cpu, d->to, unavailable_features & e= nv->user_features[d->to], + "This feature depends on other featu= res that were not requested"); + + /* Prevent adding the feature in the loop below. */ + env->user_features[d->to] |=3D d->to_flags; + env->features[d->to] &=3D ~d->to_flags; + } + } + /*TODO: Now cpu->max_features doesn't overwrite features * set using QOM properties, and we can convert * plus_features & minus_features to global properties @@ -5106,22 +5143,6 @@ static void x86_cpu_expand_features(X86CPU *cpu, Err= or **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 (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; - } - } - if (!kvm_enabled() || !cpu->expose_kvm) { env->features[FEAT_KVM] =3D 0; } --=20 1.8.3.1