From nobody Wed Nov 12 11:49:57 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=1570208887; cv=none; d=zoho.com; s=zohoarc; b=bSLxqI1QWTJBx7UiLgM+6jv4iIwY7hbX3sHzYVQSYR9uRcth6QnMGgE4t/TuLz74uWkJ0cRSYfpird9FY4mv88qtljfIjDZGR8v0vEVseLVuY2I9zKh0hyNLaokZazhfJtXM0FZFaX0KGKjXQb1r9nmpfzXsbMNMcXNphWdyKt0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570208887; 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=ENyllfGZkEo7zYLWR0n6K+bmlcFkTFrnASUR8ihWMqE=; b=k8/FzBl7+5wGcJD8o4yNHmgvGmOPB+1Lhi7bEw4AMU42S8qXu30eDUTQtaF8xxcErno/Zw5BwXPX9ZdRRb/UR/lAUpZ7/FNCFLWizhQ70tAEWp0zqaGv+I33SIQ0xGdi2LoU9U6GjP8z2OH++EISO+wZ/MKOITeqfYMj43ANwzE= 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 1570208887002264.69946105133806; Fri, 4 Oct 2019 10:08:07 -0700 (PDT) Received: from localhost ([::1]:50660 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iGR3l-0003Tg-IT for importer@patchew.org; Fri, 04 Oct 2019 13:08:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51082) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iGQvU-0007Mg-2C 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-0001ta-Mr for qemu-devel@nongnu.org; Fri, 04 Oct 2019 12:59:31 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:39670) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iGQvS-0001ss-7Q for qemu-devel@nongnu.org; Fri, 04 Oct 2019 12:59:30 -0400 Received: by mail-wr1-x441.google.com with SMTP id r3so8091459wrj.6 for ; Fri, 04 Oct 2019 09:59:29 -0700 (PDT) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id u7sm7041270wrp.19.2019.10.04.09.59.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 04 Oct 2019 09:59:26 -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=ENyllfGZkEo7zYLWR0n6K+bmlcFkTFrnASUR8ihWMqE=; b=nqccnty7ksBxLKCFiLX2OGBce1x6BVWqnWL1Y9nlliPP9+mSO4m1awwUZnHwgEh0aB MdQEg0ccgbVQLJn+J+rSwB3LPNxQzIWhscybVHuSh8EgUeI068Xe6zzR0O8RPe3XI+Xm myjcJ3Aan8foHbvm+Pe55HGOYD+NXoQweXX1p6GtusM6yF1b4/M9LyBcbgg4yiNYGa1b L35B5keAI5VKjG9ZHkiLEuigQr0f71kXupXr8xAccEqDXk1UIp9uAefj9hYWAv1vTrOQ q5tHEXm5+Kcjg59f1UOfLlEuiDgoEX80288t8OOo93MI+NtzYfc6zoh6HOJ9ltM4KRWT xqgw== 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=ENyllfGZkEo7zYLWR0n6K+bmlcFkTFrnASUR8ihWMqE=; b=C7a7aUZc8xfR+nVrQuwHWwN+EntDtwZAoaSpyXKQz9zj17XJKemucoRLe5NPPD1BFs AlR1wtf6aZLLHm4J+ZVdIY6eYi8isSY2RdS22WedsEZ5n5XAiz6UJA7WhzaYkxqMRbw0 8y4W62Xup+oiEs7VdWojIFurZIzhodCMUod2OssgqczpuFcdUNeqCuSkXKexL8ExEmeQ 2pFcxjHQBF7Q13qO9a0JWPez7OENCFgKpw06dXIf27dU11yTbQ2BMk0QSLx/WqKeT9mx azJe/A9Ms7SApDEbzZHXwm6uZa+SHFHW875+Lf3+GBwtO/KntpnlBDP+6MSokWb/iLb1 X2ZQ== X-Gm-Message-State: APjAAAVLMd5tlB4KS6w5MfW8wdHV76Yq1B0guF/lPNfE+ezNpxRPfiyi 250LnO95FMRp5lRdlZelCtFauKYD X-Google-Smtp-Source: APXvYqwoOlY22GQUnea/wndo5ciU7LKDLDCtHEf2+vOLJbaDBIQMLzkTMtEgo4jIlJyPGJR1dHTlNQ== X-Received: by 2002:a5d:44d2:: with SMTP id z18mr12761375wrr.122.1570208367673; Fri, 04 Oct 2019 09:59:27 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Subject: [PULL 22/29] target/i386: handle filtered_features in a new function mark_unavailable_features Date: Fri, 4 Oct 2019 18:59:16 +0200 Message-Id: <1570208363-11948-2-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::441 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" The next patch will add a different reason for filtering features, unrelated to host feature support. Extract a new function that takes care of disabli= ng the features and optionally reporting them. Signed-off-by: Paolo Bonzini --- target/i386/cpu.c | 87 ++++++++++++++++++++++++++++++---------------------= ---- 1 file changed, 48 insertions(+), 39 deletions(-) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 80cfab0..83f8981 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -3096,17 +3096,41 @@ static char *feature_word_description(FeatureWordIn= fo *f, uint32_t bit) return NULL; } =20 -static void report_unavailable_features(FeatureWord w, uint32_t mask) +static bool x86_cpu_have_filtered_features(X86CPU *cpu) { + FeatureWord w; + + for (w =3D 0; w < FEATURE_WORDS; w++) { + if (cpu->filtered_features[w]) { + return true; + } + } + + return false; +} + +static void mark_unavailable_features(X86CPU *cpu, FeatureWord w, uint32_t= mask, + const char *verbose_prefix) +{ + CPUX86State *env =3D &cpu->env; FeatureWordInfo *f =3D &feature_word_info[w]; int i; char *feat_word_str; =20 + if (!cpu->force_features) { + env->features[w] &=3D ~mask; + } + cpu->filtered_features[w] |=3D mask; + + if (!verbose_prefix) { + return; + } + for (i =3D 0; i < 32; ++i) { if ((1UL << i) & mask) { feat_word_str =3D feature_word_description(f, i); - warn_report("%s doesn't support requested feature: %s%s%s [bit= %d]", - accel_uses_host_cpuid() ? "host" : "TCG", + warn_report("%s: %s%s%s [bit %d]", + verbose_prefix, feat_word_str, f->feat_names[i] ? "." : "", f->feat_names[i] ? f->feat_names[i] : "", i); @@ -3511,7 +3535,7 @@ static void x86_cpu_parse_featurestr(const char *type= name, char *features, } =20 static void x86_cpu_expand_features(X86CPU *cpu, Error **errp); -static int x86_cpu_filter_features(X86CPU *cpu); +static void x86_cpu_filter_features(X86CPU *cpu, bool verbose); =20 /* Build a list with the name of all features on a feature word array */ static void x86_cpu_list_feature_names(FeatureWordArray features, @@ -3576,7 +3600,7 @@ static void x86_cpu_class_check_missing_features(X86C= PUClass *xcc, next =3D &new->next; } =20 - x86_cpu_filter_features(xc); + x86_cpu_filter_features(xc, false); =20 x86_cpu_list_feature_names(xc->filtered_features, next); =20 @@ -3784,15 +3808,6 @@ static uint32_t x86_cpu_get_supported_feature_word(F= eatureWord w, return r; } =20 -static void x86_cpu_report_filtered_features(X86CPU *cpu) -{ - FeatureWord w; - - for (w =3D 0; w < FEATURE_WORDS; w++) { - report_unavailable_features(w, cpu->filtered_features[w]); - } -} - static void x86_cpu_apply_props(X86CPU *cpu, PropValue *props) { PropValue *pv; @@ -5154,24 +5169,24 @@ out: * * Returns: 0 if all flags are supported by the host, non-zero otherwise. */ -static int x86_cpu_filter_features(X86CPU *cpu) +static void x86_cpu_filter_features(X86CPU *cpu, bool verbose) { CPUX86State *env =3D &cpu->env; FeatureWord w; - int rv =3D 0; + const char *prefix =3D NULL; + + if (verbose) { + prefix =3D accel_uses_host_cpuid() + ? "host doesn't support requested feature" + : "TCG doesn't support requested feature"; + } =20 for (w =3D 0; w < FEATURE_WORDS; w++) { uint32_t host_feat =3D x86_cpu_get_supported_feature_word(w, false); uint32_t requested_features =3D env->features[w]; - uint32_t available_features =3D requested_features & host_feat; - if (!cpu->force_features) { - env->features[w] =3D available_features; - } - cpu->filtered_features[w] =3D requested_features & ~available_feat= ures; - if (cpu->filtered_features[w]) { - rv =3D 1; - } + uint32_t unavailable_features =3D requested_features & ~host_feat; + mark_unavailable_features(cpu, w, unavailable_features, prefix); } =20 if ((env->features[FEAT_7_0_EBX] & CPUID_7_0_EBX_INTEL_PT) && @@ -5197,13 +5212,9 @@ static int x86_cpu_filter_features(X86CPU *cpu) * host can't emulate the capabilities we report on * cpu_x86_cpuid(), intel-pt can't be enabled on the current h= ost. */ - env->features[FEAT_7_0_EBX] &=3D ~CPUID_7_0_EBX_INTEL_PT; - cpu->filtered_features[FEAT_7_0_EBX] |=3D CPUID_7_0_EBX_INTEL_= PT; - rv =3D 1; + mark_unavailable_features(cpu, FEAT_7_0_EBX, CPUID_7_0_EBX_INT= EL_PT, prefix); } } - - return rv; } =20 static void x86_cpu_realizefn(DeviceState *dev, Error **errp) @@ -5244,16 +5255,14 @@ static void x86_cpu_realizefn(DeviceState *dev, Err= or **errp) goto out; } =20 - if (x86_cpu_filter_features(cpu) && - (cpu->check_cpuid || cpu->enforce_cpuid)) { - x86_cpu_report_filtered_features(cpu); - if (cpu->enforce_cpuid) { - error_setg(&local_err, - accel_uses_host_cpuid() ? - "Host doesn't support requested features" : - "TCG doesn't support requested features"); - goto out; - } + x86_cpu_filter_features(cpu, cpu->check_cpuid || cpu->enforce_cpuid); + + if (cpu->enforce_cpuid && x86_cpu_have_filtered_features(cpu)) { + error_setg(&local_err, + accel_uses_host_cpuid() ? + "Host doesn't support requested features" : + "TCG doesn't support requested features"); + goto out; } =20 /* On AMD CPUs, some CPUID[8000_0001].EDX bits must match the bits on --=20 1.8.3.1