From nobody Tue Feb 10 08:27:16 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=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 --- 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