From nobody Tue Feb 10 13:16:18 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1650893331; cv=none; d=zohomail.com; s=zohoarc; b=PtfvPpfXVWp0JEBv40HjM6G+Yp0gVhHKVcZ6qktNb6LtB7GuNlYTxvdwRlh9N1+UiBXI2JAYas8uqug6cEVgxG3XpfULnk5xMveyzfk2F8E3kAnMvSifmmyNxuDPkx04MrzjrNWgM/lRzDzVsbT0phoCjGLJq6hGKH5vfA2LShk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650893331; 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=xQYlbbpOIw4CcFIEOC3GdUjgyH03dkdHhQwAHxTgWhM=; b=HCJocHJnGPMjqLucARm2tvKJpW8NFPP4WlHNizZ0V/WprMZgUnZ1v61n94RTRiLO5IH0aYHXWVCfl5EqlvqVN3d7utGdt5hNQt0FR0l/9i1lYrb0gxdbTevXwzO2aNEy2kq5U8c+bmyHYJKyTa/hXuTqxtZ3rzf8KW7/lpdJXuE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1650893330866494.5234290481934; Mon, 25 Apr 2022 06:28:50 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-397-zqg3_pP2PwiamCeySTrMFA-1; Mon, 25 Apr 2022 09:28:40 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 059FC299E76C; Mon, 25 Apr 2022 13:28:38 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2F37C28122; Mon, 25 Apr 2022 13:28:37 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 97A881940354; Mon, 25 Apr 2022 13:28:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6F95D1940362 for ; Mon, 25 Apr 2022 13:28:35 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 5446454C74B; Mon, 25 Apr 2022 13:28:35 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id A678954C747 for ; Mon, 25 Apr 2022 13:28:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650893329; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=xQYlbbpOIw4CcFIEOC3GdUjgyH03dkdHhQwAHxTgWhM=; b=KAkMJ7JpsX0rd14wi8/9/qEQx8hQtuATRi5dQEpfwEx+PsUxfBGzUS7POHnWEIfmkHG2fx NOCuMMr50IZh52d6CIqwZnSgW782AwIgDQNAzl0siAnItsnUIuCrkXZDtp+IkbSmOiug7T xbGH7mLcI1IfD4Ucwvu1Uj/uA9r49I8= X-MC-Unique: zqg3_pP2PwiamCeySTrMFA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/7] virCPUx86DataGetHost: Fix construction of the returned data Date: Mon, 25 Apr 2022 15:28:26 +0200 Message-Id: <2033f382aeb1138370b8cf270931aac1cb6c4118.1650893125.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1650893332027100002 Content-Type: text/plain; charset="utf-8" The function returns 'virCPUData' but doesn't do two important steps which other code takes: 1) leaves with all-zero data is stripped from the XML output 2) the data is expected to be sorted in the array Now the 'virHostCPUGetCPUID' helper returns both all 0 leaves and doesn't order them as we expect. If this is then used in conjunction with 'virCPUx86DataIsIdentical' together with data which made a roundtrip to XML and back the result will be always false even if the data itself is identical. Signed-off-by: Peter Krempa --- src/cpu/cpu_x86.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 18e9cacfd0..7e9d1cea47 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -3354,16 +3354,17 @@ virCPUx86DataGetHost(void) size_t i; virCPUData *cpuid; g_autofree struct kvm_cpuid2 *kvm_cpuid =3D NULL; + virCPUx86DataItem zero =3D { 0 }; if ((kvm_cpuid =3D virHostCPUGetCPUID()) =3D=3D NULL) return NULL; cpuid =3D virCPUDataNew(virArchFromHost()); - cpuid->data.x86.len =3D kvm_cpuid->nent; + cpuid->data.x86.len =3D 0; cpuid->data.x86.items =3D g_new0(virCPUx86DataItem, kvm_cpuid->nent); for (i =3D 0; i < kvm_cpuid->nent; ++i) { - virCPUx86DataItem *item =3D &cpuid->data.x86.items[i]; + virCPUx86DataItem *item =3D &cpuid->data.x86.items[cpuid->data.x86= .len]; item->type =3D VIR_CPU_X86_DATA_CPUID; item->data.cpuid.eax_in =3D kvm_cpuid->entries[i].function; item->data.cpuid.ecx_in =3D kvm_cpuid->entries[i].index; @@ -3371,8 +3372,18 @@ virCPUx86DataGetHost(void) item->data.cpuid.ebx =3D kvm_cpuid->entries[i].ebx; item->data.cpuid.ecx =3D kvm_cpuid->entries[i].ecx; item->data.cpuid.edx =3D kvm_cpuid->entries[i].edx; + + /* skip all-zero leaves same as we do in the XML formatter */ + if (virCPUx86DataItemMatch(item, &zero)) + continue; + + cpuid->data.x86.len++; } + /* the rest of the code expects the function to be in order */ + qsort(cpuid->data.x86.items, cpuid->data.x86.len, + sizeof(virCPUx86DataItem), virCPUx86DataSorter); + return cpuid; } #endif --=20 2.35.1