From nobody Sun Nov 24 22:53:55 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=1720087220; cv=none; d=zohomail.com; s=zohoarc; b=O2XIl3kBqBRYqZ45ZDS9oDATr+NFHXEtZQGtFf/yWA+5IbYdDB1740kGweHg+Si+k+TWS9t6Vg48F4gqJa/3vycx8DMB46SHHfMIw6wFEtwPDezKyCHLPz6JTSeYX1XVJgM8DdmVWtiboLbZMt8hS6GceIibV8Qd7mI1lefvFoI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720087220; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VfZ2gFIZh1S09Ups+9rXVB9WcHJZ9HitC1LvQrZFclA=; b=dMQ3bxr8xerS34hIiqop9l+acoo5mfEMDzimiAZjsTwuPrGvjg2O+M0QeU83ijerceG4Nb2svwbTgMlg8VHIG+vc/4quj/LSQlE5QHX5HojpW83HZq3xz4XVNboE+LHAlD6tphBEbht4C8ImGq7gpRCIh6jnV9x/VIGZWl08/4o= 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 1720087219909995.9305841871893; Thu, 4 Jul 2024 03:00:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sPJEd-0006dL-Cy; Thu, 04 Jul 2024 05:58:39 -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 1sPJEa-0006Yy-1C for qemu-devel@nongnu.org; Thu, 04 Jul 2024 05:58:36 -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 1sPJEX-00087O-CJ for qemu-devel@nongnu.org; Thu, 04 Jul 2024 05:58:35 -0400 Received: from mail-lf1-f70.google.com (mail-lf1-f70.google.com [209.85.167.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-675-u2LzLw-5PGWxaQqbLdBdww-1; Thu, 04 Jul 2024 05:58:27 -0400 Received: by mail-lf1-f70.google.com with SMTP id 2adb3069b0e04-52e9d91ec1bso487769e87.0 for ; Thu, 04 Jul 2024 02:58:27 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4264a1d0b24sm17477465e9.3.2024.07.04.02.58.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jul 2024 02:58:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720087112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VfZ2gFIZh1S09Ups+9rXVB9WcHJZ9HitC1LvQrZFclA=; b=i/+4LkISHEj+opPmudgwEI47PBpeBNgw9qhTh3iGVSBcGC9P3xJApM1Xm2Txd1Emb0/p45 7Ne2YL1VAOyqTJ4rNCZLG4EAFdIpfPKr54u179qWUk7EBajEARFwqBC0ob2ztDTGJ27T4Y L7rcfVeF8HBUj2g14Y3yKmZrnS04eCA= X-MC-Unique: u2LzLw-5PGWxaQqbLdBdww-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720087105; x=1720691905; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VfZ2gFIZh1S09Ups+9rXVB9WcHJZ9HitC1LvQrZFclA=; b=qDKDtbhcl82VIgvC7TdFZAs5HWCL8BUfY97sE/fZQYgCary5rjawWrKEdVJU8Zco1I eu0yOb+DR50cukB+mJSNx8uOuKcmlld0esNLbk5ZyuDyeVIlsvmfhBilcAm0pHlCcS8H u16JwTM1+d3wHx0XHbczEthvnQdIoTN7EPdx8pnKODduHZ5oV/sEKqBjAMiQ7bZzjzCb PJsnOd9SeBgfdx6lD0IDH4sojAqi4bKG/0wEAdVLrw+R2CpDGL5AIIcSpPmkkNrKP1dk D6JHZztSIcVHCrzmmVTpGLSklTBlPYrO7comA6pbyH1pEQRsazD5PM8VqDrqVlS8ERUo xUQw== X-Gm-Message-State: AOJu0YxPV5S7ftPf7Fj3Q8J1l6uqQ0QRvGOwJrd3GdOd/TeTrm3PEDDC W9mblVOwiVYU/VkD+Rp5I6Nrm6t1L/KkLTc/xQw/G63DaZ1+7Ny4bUu03/FWCzqo9yHOGN7GJtI LvUB7A0X+9NOjK+Fq5LamMfg6ONd+R6UMF1yo3i/HiunWeIA06K2bBOTm8EuI26S9Vsw42Ki12K r8zK0lpuuXlnJFshPwmN77MkIFvBuKWxA6STBX X-Received: by 2002:ac2:4989:0:b0:52c:d56f:b2cc with SMTP id 2adb3069b0e04-52ea06d30d0mr766943e87.58.1720087104848; Thu, 04 Jul 2024 02:58:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG3bmQY33yW7swpFbJJSb20ZXaYGeQclin5q1WsVn9Ns0+1S6l52VFMFdImicXPMxM3cAs/JA== X-Received: by 2002:ac2:4989:0:b0:52c:d56f:b2cc with SMTP id 2adb3069b0e04-52ea06d30d0mr766929e87.58.1720087104484; Thu, 04 Jul 2024 02:58:24 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Xiaoyao Li , John Allen Subject: [PULL 07/16] target/i386: pass X86CPU to x86_cpu_get_supported_feature_word Date: Thu, 4 Jul 2024 11:57:57 +0200 Message-ID: <20240704095806.1780273-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240704095806.1780273-1-pbonzini@redhat.com> References: <20240704095806.1780273-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, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: 1720087222231100006 Content-Type: text/plain; charset="utf-8" This allows modifying the bits in "-cpu max"/"-cpu host" depending on the guest CPU vendor (which, at least by default, is the host vendor in the case of KVM). For example, machine check architecture differs between Intel and AMD, and bits from AMD should be dropped when configuring the guest for an Intel model. Cc: Xiaoyao Li Cc: John Allen Signed-off-by: Paolo Bonzini --- target/i386/cpu.h | 3 +-- target/i386/cpu.c | 11 +++++------ target/i386/kvm/kvm-cpu.c | 2 +- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 29daf370485..9bea7142bf4 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -666,8 +666,7 @@ typedef enum FeatureWord { } FeatureWord; =20 typedef uint64_t FeatureWordArray[FEATURE_WORDS]; -uint64_t x86_cpu_get_supported_feature_word(FeatureWord w, - bool migratable_only); +uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w); =20 /* cpuid_features bits */ #define CPUID_FP87 (1U << 0) diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 4c2e6f3a71e..4364cb0f8e3 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6035,8 +6035,7 @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Erro= r **errp) =20 #endif /* !CONFIG_USER_ONLY */ =20 -uint64_t x86_cpu_get_supported_feature_word(FeatureWord w, - bool migratable_only) +uint64_t x86_cpu_get_supported_feature_word(X86CPU *cpu, FeatureWord w) { FeatureWordInfo *wi =3D &feature_word_info[w]; uint64_t r =3D 0; @@ -6078,7 +6077,7 @@ uint64_t x86_cpu_get_supported_feature_word(FeatureWo= rd w, r &=3D ~unavail; } #endif - if (migratable_only) { + if (cpu && cpu->migratable) { r &=3D x86_cpu_get_migratable_flags(w); } return r; @@ -7371,7 +7370,7 @@ void x86_cpu_expand_features(X86CPU *cpu, Error **err= p) * by the user. */ env->features[w] |=3D - x86_cpu_get_supported_feature_word(w, cpu->migratable) & + x86_cpu_get_supported_feature_word(cpu, w) & ~env->user_features[w] & ~feature_word_info[w].no_autoenable_flags; } @@ -7497,7 +7496,7 @@ static void x86_cpu_filter_features(X86CPU *cpu, bool= verbose) =20 for (w =3D 0; w < FEATURE_WORDS; w++) { uint64_t host_feat =3D - x86_cpu_get_supported_feature_word(w, false); + x86_cpu_get_supported_feature_word(NULL, w); uint64_t requested_features =3D env->features[w]; uint64_t unavailable_features =3D requested_features & ~host_feat; mark_unavailable_features(cpu, w, unavailable_features, prefix); @@ -7617,7 +7616,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error= **errp) env->features[FEAT_PERF_CAPABILITIES] & PERF_CAP_LBR_FMT; if (requested_lbr_fmt && kvm_enabled()) { uint64_t host_perf_cap =3D - x86_cpu_get_supported_feature_word(FEAT_PERF_CAPABILITIES, fal= se); + x86_cpu_get_supported_feature_word(NULL, FEAT_PERF_CAPABILITIE= S); unsigned host_lbr_fmt =3D host_perf_cap & PERF_CAP_LBR_FMT; =20 if (!cpu->enable_pmu) { diff --git a/target/i386/kvm/kvm-cpu.c b/target/i386/kvm/kvm-cpu.c index d57a68a301e..6bf8dcfc607 100644 --- a/target/i386/kvm/kvm-cpu.c +++ b/target/i386/kvm/kvm-cpu.c @@ -143,7 +143,7 @@ static void kvm_cpu_xsave_init(void) if (!esa->size) { continue; } - if ((x86_cpu_get_supported_feature_word(esa->feature, false) & esa= ->bits) + if ((x86_cpu_get_supported_feature_word(NULL, esa->feature) & esa-= >bits) !=3D esa->bits) { continue; } --=20 2.45.2