From nobody Sat May 18 18:12:59 2024 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=1650893322; cv=none; d=zohomail.com; s=zohoarc; b=JKx8Mv9yHMPUbh161Vd17Wh8SDlwz6RHIU+4JzkssZHpn0PjTj6AeGvY2+uGMMj5kiMZuK5892wXIN7PnQboOTg9BvoBGqW1cz7xuj08aAkP7R7tykpm4DjOEPzt1i2jbQyYH64tBKHPSisYFf6n0BxBC7x4CHS7tqrws1a/Dao= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650893322; 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=WnmPJeMg8Ur31CnX62yOK5ktCf3ZGphMT2yEPAVXSC0=; b=le33f7lLTPBCPW9MF1uNCd6UkuHF0xBE7Exn9X/k4JVeGBhxiOEsloTN9pXOs82nPXc7kgb9w4XP6KrgJYiljLLgFj65tjjD3XHBjy7qkrBNDBwjZzTkJDWCqYTr3QFm2MA7ROCPIjWrowGwhOBsF5wUzjFz3PFGUPVFhqpklK0= 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 1650893322232457.3448688719134; Mon, 25 Apr 2022 06:28:42 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-145-FBn8WcexOZ6I_711J6tR-A-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 C022B85A5BC; Mon, 25 Apr 2022 13:28:36 +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 75E1CC27EA2; Mon, 25 Apr 2022 13:28:36 +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 520DC194035A; Mon, 25 Apr 2022 13:28:35 +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 55DFD1947BBE for ; Mon, 25 Apr 2022 13:28:34 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 38A6754C747; Mon, 25 Apr 2022 13:28:34 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC21454C74B for ; Mon, 25 Apr 2022 13:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650893321; 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=WnmPJeMg8Ur31CnX62yOK5ktCf3ZGphMT2yEPAVXSC0=; b=Q8DMHZKEl1FldUqw3s5crNwWaJVk3erDonOmd4bf4sFjLZoCSeVGI8F4YP5tGlVlYtwLmy UL/QS+xKyEl1/pMRuty1BzIVz8giflp7UJX4aOvUowZuqf6tzKkYMXjSYB/2jzVlQVy+wJ foqgtHaaFmrwMJdZSSWTn/wyL5z3IpE= X-MC-Unique: FBn8WcexOZ6I_711J6tR-A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/7] virCPUx86DataIsIdentical: Add debug output Date: Mon, 25 Apr 2022 15:28:25 +0200 Message-Id: <224bf16860b335607194ca47fa7f237037402819.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: 1650893323967100003 Content-Type: text/plain; charset="utf-8" Without this it's impossible to debug scenarios when this function returns a mismatch but the formatted data looks identical. Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark Reviewed-by: Michal Privoznik --- src/cpu/cpu_x86.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 9826ec6190..18e9cacfd0 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -3309,14 +3309,20 @@ virCPUx86DataIsIdentical(const virCPUData *a, if (!a || !b) return VIR_CPU_COMPARE_ERROR; - if (a->arch !=3D b->arch) + if (a->arch !=3D b->arch) { + VIR_DEBUG("incompatible architecture a:%u b:%u", a->arch, b->arch); return VIR_CPU_COMPARE_INCOMPATIBLE; + } - if (!((adata =3D &a->data.x86) && (bdata =3D &b->data.x86))) + if (!((adata =3D &a->data.x86) && (bdata =3D &b->data.x86))) { + VIR_DEBUG("missing x86 data: a:%p b:%p", adata, bdata); return VIR_CPU_COMPARE_ERROR; + } - if (adata->len !=3D bdata->len) + if (adata->len !=3D bdata->len) { + VIR_DEBUG("unequal length a:%zu b:%zu", adata->len, bdata->len); return VIR_CPU_COMPARE_INCOMPATIBLE; + } for (i =3D 0; i < adata->len; ++i) { bool found =3D false; @@ -3330,8 +3336,10 @@ virCPUx86DataIsIdentical(const virCPUData *a, break; } - if (!found) + if (!found) { + VIR_DEBUG("mismatched data"); return VIR_CPU_COMPARE_INCOMPATIBLE; + } } return VIR_CPU_COMPARE_IDENTICAL; --=20 2.35.1 From nobody Sat May 18 18:12:59 2024 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 Reviewed-by: Jiri Denemark Reviewed-by: Michal Privoznik --- 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 From nobody Sat May 18 18:12:59 2024 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=1650893326; cv=none; d=zohomail.com; s=zohoarc; b=fu9Ix2oXeMsEl5DntLCp4zIUDPyT4mpE9echhooKVKmoRIi5mhSlIQ/w9ga0X4JFGUHv70HIjOCMeZWeXV7QUsTouEpbQ8wKwG3WBqPJczRm4mosOxo3ZtnbXX3BW37qDPNKsZvSo6S0+7DXNF02SBiq99tLAnReCcnIPkHf9IQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650893326; 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=LXJjVDKurC6oUkCvuCbZUK/s2WCXHr4udQtz5F6i0kg=; b=WRPoSD26XRNaxV4lZPi7tv0SCHuXETCB2lupDj1lRTfnokF8Ry+SINEZ/CvJio01M777pFGy3enyTFFaSlmxHMcmmVfRt3nMDjHVoUToWYLxahcwcvakp396HEZJpfhI/aPOkbMD/fIgK18FZPE45OAow+DiRiAQnx9d233JtkI= 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 1650893326232513.9069813606108; Mon, 25 Apr 2022 06:28:46 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-413-LXaxhIeCNPC6NdSMKfsWDQ-1; Mon, 25 Apr 2022 09:28:43 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0361B8339BE; 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 A30E940CFD04; 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 537231940345; 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 40D121947BBE for ; Mon, 25 Apr 2022 13:28:36 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3400F54C74E; Mon, 25 Apr 2022 13:28:36 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id B51C454C759 for ; Mon, 25 Apr 2022 13:28:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650893325; 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=LXJjVDKurC6oUkCvuCbZUK/s2WCXHr4udQtz5F6i0kg=; b=hn0r5GBBmF3l1w70u2m9iv765Pa6LkUDlwauHxH2y0OmvE2uIgyczwJZwhAJ6PxgrrZJ/s Uw/s+m6+lW17tOZshFTjTYNPnTIs9RjaKZNPLJRl8OaPdEEhox9x4BvR+mEvsynVvUk1ZJ aXq+OiFr+l8paxBYXH0L+cQ9JfsAXYE= X-MC-Unique: LXaxhIeCNPC6NdSMKfsWDQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/7] virHostCPUGetCPUID: Add comment on how KVM_GET_SUPPORTED_CPUID works Date: Mon, 25 Apr 2022 15:28:27 +0200 Message-Id: <553d89cd61a3849a7d6de0c7cdaedb4048908a87.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.84 on 10.11.54.1 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: 1650893327983100007 Content-Type: text/plain; charset="utf-8" The commit adding the code fetching host CPU flags via the KVM_GET_SUPPORTED_CPUID didn't describe at all why such an alghorithm is needed. Add a comment from the documentation outlining how the userspace function is expected to allocate memory here. Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark Reviewed-by: Michal Privoznik --- src/util/virhostcpu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 011ef8a153..6be00a5b76 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -1327,6 +1327,13 @@ virHostCPUGetCPUID(void) return NULL; } + /* Userspace invokes KVM_GET_SUPPORTED_CPUID by passing a kvm_cpuid2 s= tructure + * with the 'nent' field indicating the number of entries in the varia= ble-size + * array 'entries'. If the number of entries is too low to describe t= he cpu + * capabilities, an error (E2BIG) is returned. If the number is too h= igh, + * the 'nent' field is adjusted and an error (ENOMEM) is returned. If= the + * number is just right, the 'nent' field is adjusted to the number of= valid + * entries in the 'entries' array, which is then filled. */ for (i =3D 1; i < INT32_MAX; i *=3D 2) { g_autofree struct kvm_cpuid2 *kvm_cpuid =3D NULL; kvm_cpuid =3D g_malloc0(sizeof(struct kvm_cpuid2) + --=20 2.35.1 From nobody Sat May 18 18:12:59 2024 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=1650893325; cv=none; d=zohomail.com; s=zohoarc; b=iy9i+B67TMDfHRznhCy/YtggbYoXuBMIIrI1hWBazCuyM0vkIRB6x7cx0/uAjkwi+jMNavDIZ3y69l6y8OoaUbYxs73jOVEDcwrvy+2n3nzt79xwuCDhc7uahAuHMxkYkc0eZuNrb6d1wxzh1qXSRTNuQeec72ifS7Hm3IJlUlI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650893325; 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=zzVnwYP9J6HFFQY6PjzMkohZZxustHrd+jCezDPlEl4=; b=BSoPlIcsocMEnlJGyVOaH8Sfa+p4jejmCnKWyoRuihh6fjTvOR+vvNmGh1LbXSDFaXrVgUiq9fqr80mqs83PEr0cH/3gkq27gZW106feinyuhKOnOPWEyM4gPa+PXPTbqXf268k4OklpkNXnYfZDbq/O1QSPI3tbgKcr2VDYQnw= 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 1650893325165596.396642373315; Mon, 25 Apr 2022 06:28:45 -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-35-1Rqa4fpFOnqKbBRh5Fdz6w-1; Mon, 25 Apr 2022 09:28:42 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F22A51E18004; Mon, 25 Apr 2022 13:28:39 +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 E0950463E04; Mon, 25 Apr 2022 13:28:38 +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 A16F61949762; Mon, 25 Apr 2022 13:28:38 +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 3CE6D1949762 for ; Mon, 25 Apr 2022 13:28:37 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 1C81154C753; Mon, 25 Apr 2022 13:28:37 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8400654C74D for ; Mon, 25 Apr 2022 13:28:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650893324; 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=zzVnwYP9J6HFFQY6PjzMkohZZxustHrd+jCezDPlEl4=; b=QLyMI9460+aq+0O9gdkdooG2vBSaRyRXZ585CFM0DmWy5T9VZD9rFr/l/kx3F4kuNG0frv vpJTLp4QWDiTq9ZBPGzZQxrDKcXGukOxWdc49DeYVCwnUwK5yE3nFeZga5BzlS8yoKSeTe 8V0EaTWFht4r9yFeHTRtJd+SaTe65Fc= X-MC-Unique: 1Rqa4fpFOnqKbBRh5Fdz6w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/7] util: virhostcpu: Extract filtering of the returned data from virHostCPUGetCPUID Date: Mon, 25 Apr 2022 15:28:28 +0200 Message-Id: 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.10 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: 1650893325991100005 Content-Type: text/plain; charset="utf-8" Move the filtering code into virHostCPUGetCPUIDFilterVolatile. This also removes a safe but very questionable reuse of 'i' iterator in the both the top level and nested loop. It's safe for now as the to level loop will not iterate any more in the current state. Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark Reviewed-by: Michal Privoznik --- src/util/virhostcpu.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 6be00a5b76..f07514a11b 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -1316,6 +1316,32 @@ virHostCPUGetMSR(unsigned long index, } +/** + * virHostCPUGetCPUIDFilterVolatile: + * + * Filters the 'kvm_cpuid2' struct and removes data which may change depen= ding + * on the CPU core this was run on. + * + * Currently filtered fields: + * - local APIC ID + */ +static void +virHostCPUGetCPUIDFilterVolatile(struct kvm_cpuid2 *kvm_cpuid) +{ + size_t i; + + for (i =3D 0; i < kvm_cpuid->nent; ++i) { + struct kvm_cpuid_entry2 *entry =3D &kvm_cpuid->entries[i]; + + /* filter out local apic id */ + if (entry->function =3D=3D 0x01 && entry->index =3D=3D 0x00) + entry->ebx &=3D 0x00ffffff; + if (entry->function =3D=3D 0x0b) + entry->edx &=3D 0xffffff00; + } +} + + struct kvm_cpuid2 * virHostCPUGetCPUID(void) { @@ -1341,15 +1367,7 @@ virHostCPUGetCPUID(void) kvm_cpuid->nent =3D i; if (ioctl(fd, KVM_GET_SUPPORTED_CPUID, kvm_cpuid) =3D=3D 0) { - /* filter out local apic id */ - for (i =3D 0; i < kvm_cpuid->nent; ++i) { - struct kvm_cpuid_entry2 *entry =3D &kvm_cpuid->entries[i]; - if (entry->function =3D=3D 0x01 && entry->index =3D=3D 0x0= 0) - entry->ebx &=3D 0x00ffffff; - if (entry->function =3D=3D 0x0b) - entry->edx &=3D 0xffffff00; - } - + virHostCPUGetCPUIDFilterVolatile(kvm_cpuid); return g_steal_pointer(&kvm_cpuid); } } --=20 2.35.1 From nobody Sat May 18 18:12:59 2024 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=1650893352; cv=none; d=zohomail.com; s=zohoarc; b=T6cZTllXGMdbuPZDQwcJULA9/lv7J7XYHTmGydgsZTRMIiVZ24jGwjdhaQzHFEioedr3QxourKzs1NA54/yOPXgAOqEp08zaoWvqqeY4f6jO/B/38nBGg+tS7dSnA26nEShZlT7PcdmWT3QKgN9Dgm6XhrsYKzat7rjj1ACMOh8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650893352; 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=oAze424QqLxgg3u1JVLl9uRWPx2cR7Wb3FpGi9pCJeI=; b=lkfUPOmhdmmtWxdVa2zQbQIzLtNuMKj8IsygSmoMkW31tv75KVd5qipr1uCulfQYFDJfSkxdlhwfsXnECE4N7a+XFxn/li9iLqE1aFi1RIYXuF+31VxkOzJQZ1+0nABtmdNNKOclolZ2nfhaw8hO/GzoTYkRD/fZNq9pW9s97/M= 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 16508933527507.371416632033402; Mon, 25 Apr 2022 06:29:12 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-357-YjHEGI7rOveDTFfIV8chuA-1; Mon, 25 Apr 2022 09:28:44 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 43D1286B8A6; Mon, 25 Apr 2022 13:28:41 +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 2FBD754ACB1; Mon, 25 Apr 2022 13:28:41 +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 E83F11947BBF; Mon, 25 Apr 2022 13:28:40 +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 10F8B1947BBE for ; Mon, 25 Apr 2022 13:28:38 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id F24BD54C754; Mon, 25 Apr 2022 13:28:37 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 79B6554C747 for ; Mon, 25 Apr 2022 13:28:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650893351; 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=oAze424QqLxgg3u1JVLl9uRWPx2cR7Wb3FpGi9pCJeI=; b=PhfmXAhMKv6y/zcDaAKOVpVJ1/Q1h8+CmH/z1bALh62TcV4TnAynmFVINOKyW97m/47Eod ej+pJzvRU48539e39K0Q93LKSUwevO3jXMUTcBI9s5GKgNTqENCv33reO+hccO3x94LT3n hZyZCNG08Z7kD8fCJ/fLRCjdLPRdBGU= X-MC-Unique: YjHEGI7rOveDTFfIV8chuA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 5/7] virHostCPUGetCPUID: Fix possible allocation of huge amount of memory Date: Mon, 25 Apr 2022 15:28:29 +0200 Message-Id: <1c53203bb98ca628763fb89bc60c372f795fb9e0.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.9 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: 1650893354135100001 Content-Type: text/plain; charset="utf-8" In case when the 'KVM_GET_SUPPORTED_CPUID' ioctl on /dev/kvm would fail for other reason than the documented E2BIG, our code would continue looping and calling it while always increasing the memory buffer even when that will not help. Rewrite the function to allow another iteration only with the correct errno. Additionally rename the 'i' variable to 'alloc_size' as it's not a pure iterator. Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark Reviewed-by: Michal Privoznik --- src/util/virhostcpu.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index f07514a11b..aa21c567be 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -1345,7 +1345,7 @@ virHostCPUGetCPUIDFilterVolatile(struct kvm_cpuid2 *k= vm_cpuid) struct kvm_cpuid2 * virHostCPUGetCPUID(void) { - size_t i; + size_t alloc_size; VIR_AUTOCLOSE fd =3D open(KVM_DEVICE, O_RDONLY); if (fd < 0) { @@ -1360,16 +1360,26 @@ virHostCPUGetCPUID(void) * the 'nent' field is adjusted and an error (ENOMEM) is returned. If= the * number is just right, the 'nent' field is adjusted to the number of= valid * entries in the 'entries' array, which is then filled. */ - for (i =3D 1; i < INT32_MAX; i *=3D 2) { + for (alloc_size =3D 1; alloc_size < INT32_MAX; alloc_size *=3D 2) { g_autofree struct kvm_cpuid2 *kvm_cpuid =3D NULL; + kvm_cpuid =3D g_malloc0(sizeof(struct kvm_cpuid2) + - sizeof(struct kvm_cpuid_entry2) * i); - kvm_cpuid->nent =3D i; + sizeof(struct kvm_cpuid_entry2) * alloc_size= ); + kvm_cpuid->nent =3D alloc_size; if (ioctl(fd, KVM_GET_SUPPORTED_CPUID, kvm_cpuid) =3D=3D 0) { virHostCPUGetCPUIDFilterVolatile(kvm_cpuid); return g_steal_pointer(&kvm_cpuid); } + + /* enlarge the buffer and try again */ + if (errno =3D=3D E2BIG) { + VIR_DEBUG("looping %zu", alloc_size); + continue; + } + + /* we fail on any other error code to prevent pointless looping */ + break; } virReportSystemError(errno, "%s", _("Cannot read host CPUID")); --=20 2.35.1 From nobody Sat May 18 18:12:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1650893330; cv=none; d=zohomail.com; s=zohoarc; b=H6J1h92J2lKx3Vfto/9NikOtQHkxUVkx9dsXvmjfrqfqr6FFA7H5igac3ihcOi/1NSKQ95J+yIUlXCxGEyw/1Yrc7s1QbQTjmymmS6m/aLJXuy8PnmcCAFHemwgyrqervzUSFk+wbQMf3J+WKOdG+sHxnc7bTouhC+1UtIoD8zY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650893330; 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=bH0Y0otnEm/Nb37lQoBFR5ED82qjYtBPmFN+0j4rrm4=; b=Co7NMcFL/32rCybdi+kFQHa9DatkOmbpWTx6Emo445pJDwFohJIR8TL4mRxf9QTZrj1A9wwMMHFS3qv2obLHh87kF28ZEk3wnQ8e2iqDdtQ6Gl85LaYGJxxWRaidTTtyDm/wNlKGS7gfm97IZxo5mEsUv2U51wjSElasxSO59Iw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 16508933303471023.4392353234558; Mon, 25 Apr 2022 06:28:50 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-470-yqYMNP82O2GHn2jp79n-7w-1; Mon, 25 Apr 2022 09:28:44 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8935B8339A7; Mon, 25 Apr 2022 13:28:41 +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 70C1A404E4AC; Mon, 25 Apr 2022 13:28:41 +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 414AA194035C; Mon, 25 Apr 2022 13:28:41 +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 DD387194035C for ; Mon, 25 Apr 2022 13:28:38 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id C26CC54C74B; Mon, 25 Apr 2022 13:28:38 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 479ED54C756 for ; Mon, 25 Apr 2022 13:28:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650893328; 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=bH0Y0otnEm/Nb37lQoBFR5ED82qjYtBPmFN+0j4rrm4=; b=UpWg93ABYdNoG8u/y7Y8c91ctPiVrV0tWW5wzM421HptwPYiwh5lFxb1o378cFQN/Cv0yg HmkDQHAuCgMRu7TR6l6ClQNKsCnka0hBDqJFcrDzgrkwtC/LYtNCF2ZxtSzF2fRl5P4gVp +F5mrdLWS6g8tzJsDBZUdXxXZRlGL1Q= X-MC-Unique: yqYMNP82O2GHn2jp79n-7w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 6/7] virHostCPUGetCPUID: Limit the buffer size ranges Date: Mon, 25 Apr 2022 15:28:30 +0200 Message-Id: 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.84 on 10.11.54.2 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: 1650893332003100001 Content-Type: text/plain; charset="utf-8" Raise the lower bound to '64' as that seems to currently be the first size that can fit the CPU data for a modern cpu. Lower the upper bound to an arbitrary 65536. So many cpu features ougth to be enough for everyone. Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark Reviewed-by: Michal Privoznik --- src/util/virhostcpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index aa21c567be..9a9fcf11c0 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -1360,7 +1360,7 @@ virHostCPUGetCPUID(void) * the 'nent' field is adjusted and an error (ENOMEM) is returned. If= the * number is just right, the 'nent' field is adjusted to the number of= valid * entries in the 'entries' array, which is then filled. */ - for (alloc_size =3D 1; alloc_size < INT32_MAX; alloc_size *=3D 2) { + for (alloc_size =3D 64; alloc_size <=3D 65536; alloc_size *=3D 2) { g_autofree struct kvm_cpuid2 *kvm_cpuid =3D NULL; kvm_cpuid =3D g_malloc0(sizeof(struct kvm_cpuid2) + --=20 2.35.1 From nobody Sat May 18 18:12:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1650893334; cv=none; d=zohomail.com; s=zohoarc; b=eXYvD3J+u5yzoxK641kexfbNTvoUj4CMC/oZL++Fj9ErYM3qQnQ6BYkybjpjHjyc+IHSB2IQ32flXwQ02km5sygDIW/RGKzTerjTTNmtLHTrx9hoPuBi0zr1r59orTgjQFUJGYLPN8wH5pe1Wqum77bR9UyjtDZUW6ykLgUhYQU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1650893334; 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=40dXmvaMNySJvGWmrRYfTyfy4VR/XKtm+J5gsoa0OKc=; b=nsD0IIiEPyBmnGV3lsnh4OYu9K6l6KPcODiYqWLh75+Rs8rENmQpWRqtsjGvmsx0X8IvmGIKO+OwS3xV1HdMs02ltAR3swK8z/AW3K2mvm+cmPwkwpIGEw7WcOUU1ivgiAzDyqVQbjBmKMZvg+TQ0cHms+u6x2mpH+LakqTx7aI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1650893334062935.1856644341843; Mon, 25 Apr 2022 06:28:54 -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-252-X_XY1AkLNzWxuhLlf6wsOw-1; Mon, 25 Apr 2022 09:28:45 -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 DA1563C025AF; Mon, 25 Apr 2022 13:28:42 +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 C42AEC44AE4; Mon, 25 Apr 2022 13:28:42 +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 9278D1940346; Mon, 25 Apr 2022 13:28:42 +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 AD3FE1947BBF for ; Mon, 25 Apr 2022 13:28:39 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id A04C154C74B; Mon, 25 Apr 2022 13:28:39 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 295C454CAEC for ; Mon, 25 Apr 2022 13:28:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650893333; 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=40dXmvaMNySJvGWmrRYfTyfy4VR/XKtm+J5gsoa0OKc=; b=gLg6CVpny+mnMTOy9F2vSbsDA+VPfk37KUziTnE3StTfzLSAP82xGl8Ayv2CLobLvSZF8v opKyxs2HB/gVkRbtYs+dstWYEc/6c9ebCdOmSw+4QY6mLHjc6yb8kXIe2boUYJqoR4yVkl zu9ZfrVU55DoYUAPVtRsRyKroBNN6/k= X-MC-Unique: X_XY1AkLNzWxuhLlf6wsOw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 7/7] virHostCPUGetCPUIDFilterVolatile: Filter out topology data on AMD Date: Mon, 25 Apr 2022 15:28:31 +0200 Message-Id: <0b6a198b83e5aad4137a0126b0d6393f8f642a9b.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: 1650893336030100001 Content-Type: text/plain; charset="utf-8" AMD cpus report Core (compute unit) identifiers of the cpu running the instruction under leaf 0x8000001e. This data is not needed for libvirt and actually breaks caching of the qemu capabilities where we check that all of the CPU flags to be identical. Mask out all of leaf 0x8000001e. Signed-off-by: Peter Krempa Reviewed-by: Jiri Denemark Reviewed-by: Michal Privoznik --- src/util/virhostcpu.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c index 9a9fcf11c0..e3f2d6d4b7 100644 --- a/src/util/virhostcpu.c +++ b/src/util/virhostcpu.c @@ -1324,11 +1324,13 @@ virHostCPUGetMSR(unsigned long index, * * Currently filtered fields: * - local APIC ID + * - topology ids and information on AMD cpus */ static void virHostCPUGetCPUIDFilterVolatile(struct kvm_cpuid2 *kvm_cpuid) { size_t i; + bool isAMD =3D false; for (i =3D 0; i < kvm_cpuid->nent; ++i) { struct kvm_cpuid_entry2 *entry =3D &kvm_cpuid->entries[i]; @@ -1338,6 +1340,47 @@ virHostCPUGetCPUIDFilterVolatile(struct kvm_cpuid2 *= kvm_cpuid) entry->ebx &=3D 0x00ffffff; if (entry->function =3D=3D 0x0b) entry->edx &=3D 0xffffff00; + + /* Match AMD hosts */ + if (entry->function =3D=3D 0x00 && entry->index =3D=3D 0x00 && + entry->ebx =3D=3D 0x68747541 && /* Auth */ + entry->edx =3D=3D 0x69746e65 && /* enti */ + entry->ecx =3D=3D 0x444d4163) /* cAMD */ + isAMD =3D true; + + /* AMD APIC ID and topology information: + * + * Leaf 0x8000001e + * + * CPUID Fn8000_001E_EAX Extended APIC ID + * 31:0 ExtendedApicId: extended APIC ID. + * + * CPUID Fn8000_001E_EBX Compute Unit Identifiers + * 31:10 Reserved. + * 9:8 CoresPerComputeUnit: cores per compute unit. + * The number of cores per compute unit is CoresPerComputeU= nit+1. + * 7:0 ComputeUnitId: compute unit ID. Identifies the processor= compute unit ID. + * + * CPUID Fn8000_001E_ECX Node Identifiers + * 31:11 Reserved. + * 10:8 NodesPerProcessor. Specifies the number of nodes per pro= cessor. + * 000b 1 node per processor + * 001b 2 nodes per processor + * 111b-010b Reserved + * 7:0 NodeId. Specifies the node ID. + * + * CPUID Fn8000_001E_EDX Reserved + * 31:0 Reserved. + * + * For libvirt none of this information seems to be interesting, t= hus + * we clear all of it including reserved bits for future-proofing. + */ + if (isAMD && entry->function =3D=3D 0x8000001e) { + entry->eax =3D 0x00; + entry->ebx =3D 0x00; + entry->ecx =3D 0x00; + entry->edx =3D 0x00; + } } } --=20 2.35.1