From nobody Fri May 3 02:52:38 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=atech.media ARC-Seal: i=1; a=rsa-sha256; t=1582196519; cv=none; d=zohomail.com; s=zohoarc; b=n+YB0rhggRej50YFe1OgPgDaOvCz69HkdWsVT941ywFmK5dpplBLxVG3x2ihp/UiFOeFeOMPHB+/Cv+w5ekPGV6n8TDLBlkGNI269lQ8qsc2M4YPubqcl+uX30wfw0bhpczb9XDXSZRY31tykTxKcx7sjYUs+2Yok8tlWmuN0WQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582196519; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=GsbfAPLCPPP9cfsS52j9aZ0Ic0KjDAcq+hL/Ho2HtZA=; b=IYmIU/SgluGYYq5hfCcbhOzJaxq5QMl5oRGCUkNfcqqv/yGKEuWA3BMkGsa63XdCJzHZE/0/fM+VqTebrUKyn/CnLqWiA5891R93fWGLGMjfhgwsoMDWL34mu1XfSBx0we9yuK8SznnB4sj1xeDwNDFyuXy3SBddS40/0a8/7Bs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1582196519627461.1892701368603; Thu, 20 Feb 2020 03:01:59 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-163-zD3QV8nNN_mst6fbzb7_gg-1; Thu, 20 Feb 2020 06:01:55 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id CF4CE800D53; Thu, 20 Feb 2020 11:01:48 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7758E8AC45; Thu, 20 Feb 2020 11:01:46 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BD4A24EBDE; Thu, 20 Feb 2020 11:01:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 01KB1gQX009927 for ; Thu, 20 Feb 2020 06:01:42 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1444A2038B82; Thu, 20 Feb 2020 11:01:42 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0EBD92038B80 for ; Thu, 20 Feb 2020 11:01:40 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F086380030A for ; Thu, 20 Feb 2020 11:01:39 +0000 (UTC) Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-464-5GSQWcd_PzOwUboIGDl5zA-1; Thu, 20 Feb 2020 06:01:36 -0500 Received: by mail-wr1-f68.google.com with SMTP id w12so4135594wrt.2 for ; Thu, 20 Feb 2020 03:01:36 -0800 (PST) Received: from [10.210.1.11] ([185.102.133.45]) by smtp.gmail.com with ESMTPSA id w13sm3922619wru.38.2020.02.20.03.01.33 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Feb 2020 03:01:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582196518; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=GsbfAPLCPPP9cfsS52j9aZ0Ic0KjDAcq+hL/Ho2HtZA=; b=MMEJu1pYWD2AlecHp5A1kHGBMkPI7xnGKz8QvStVe3c/rgepbJxZbXVH574r68QiB7zdS4 dC+1WpsJDU1c3xpZ5Hn+ZLDTUJ+K5Ums5veu6mqJNXd3FctgIrgkaA4Dy98KJxnKvPb14/ AFkiV61UKU+m/142uuBKlQIc0XM4aAw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version:content-transfer-encoding:content-language; bh=GsbfAPLCPPP9cfsS52j9aZ0Ic0KjDAcq+hL/Ho2HtZA=; b=LtrZWbAmIZf+8vBzDdpWyD8qsYNuYIotYs+q8esBf9gfHaK9Uorv6okM/H+C8tJfTs EZCRp7nZKJRbkh554dNzXuvy0spAyiBoJI9LM5HbP3hbmf2a7MuKWTZ5dRQL5vCzS2vR GM/1s+b8g8R9enQxURi7HdshYInEQBpgPjp31jUMvSLcUpW/UwR2EEVOFhpwVNw2SoxC y3c14VtkWkf1vitutHePsACrDmUlRD4Im3IGVWcg1vYUJ4khR9YM1BM9HFLiR/CBBGJK j8s7WhzEQEH8hZQ1Ia1y2P9tCxTVbU2sNMetgwmaHoZaOqyIui0bMIMhPlgvm0gudNeo ymVw== X-Gm-Message-State: APjAAAXztSnzxsHLH44/WGTwjb1b91tx8EHoCa99xRj1/BBq6G2uNDJq yNBrykB/XLmJ6+fWAGoEiZ/JhB5QUtMbTFZhf1UZ3jsXWldfRrTi7oF4wfemp0gRG7QZwkKTmzJ oOjrIFmAuWxcL0Dep492vxwmexSaAjRXpnsEwn84OiEGMecGqJvqqn/X1eJNC1U/5 X-Google-Smtp-Source: APXvYqyZK+uBnmtFpFRv8/iKZ8CROEhOy6S/na8A5fOosiQkbYjdx8XXWeKM1xgVayjKwsZegfgnzw== X-Received: by 2002:adf:cd92:: with SMTP id q18mr41059175wrj.261.1582196495042; Thu, 20 Feb 2020 03:01:35 -0800 (PST) From: Charlie Smurthwaite Subject: [ruby PATCH] Fix cpumap allocation for virDomainGetVcpus and use return value To: libvir-list@redhat.com Message-ID: <1b45d314-717d-2adc-0b3b-15ed019678d0@atech.media> Date: Thu, 20 Feb 2020 11:01:32 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 Content-Language: en-US X-MC-Unique: 5GSQWcd_PzOwUboIGDl5zA-1 X-MC-Unique: zD3QV8nNN_mst6fbzb7_gg-1 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8"; format="flowed" This patch fixes a bug in which only enough memory for one cpumap is=20 allocated for virDomainGetVcpus instead of one per virtual CPU. This Fixes an=20 overflow. Additionally, it uses the return value of virDomainGetVcpus to determine how many cpuinfo structs were actually populated rather than assuming they=20 all are. Finally, it uses the logical CPU number from the cpuinfo struct in the=20 retrurn data instead of assuming CPU numbers are sequential. This should handle=20 cases where arbitrary CPUs are offline. Signed-off-by: Charlie Smurthwaite Reviewed-by: J=C3=A1n Tomko --- ext/libvirt/domain.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ext/libvirt/domain.c b/ext/libvirt/domain.c index d665907..c6de1bf 100644 --- a/ext/libvirt/domain.c +++ b/ext/libvirt/domain.c @@ -803,7 +803,7 @@ static VALUE libvirt_domain_vcpus(VALUE d) cpumaplen =3D VIR_CPU_MAPLEN(maxcpus); - cpumap =3D alloca(sizeof(unsigned char) * cpumaplen); + cpumap =3D alloca(sizeof(unsigned char) * cpumaplen * dominfo.nrVirtCpu); r =3D virDomainGetVcpus(ruby_libvirt_domain_get(d), cpuinfo, dominfo.nrVirtCpu, cpumap, cpumaplen); @@ -832,15 +832,16 @@ static VALUE libvirt_domain_vcpus(VALUE d) result =3D rb_ary_new(); - for (i =3D 0; i < dominfo.nrVirtCpu; i++) { + for (i =3D 0; i < r; i++) { vcpuinfo =3D rb_class_new_instance(0, NULL, c_domain_vcpuinfo); - rb_iv_set(vcpuinfo, "@number", UINT2NUM(i)); if (cpuinfo !=3D NULL) { + rb_iv_set(vcpuinfo, "@number", INT2NUM(cpuinfo[i].number)); rb_iv_set(vcpuinfo, "@state", INT2NUM(cpuinfo[i].state)); rb_iv_set(vcpuinfo, "@cpu_time", ULL2NUM(cpuinfo[i].cpuTime)); rb_iv_set(vcpuinfo, "@cpu", INT2NUM(cpuinfo[i].cpu)); } else { + rb_iv_set(vcpuinfo, "@number", Qnil); rb_iv_set(vcpuinfo, "@state", Qnil); rb_iv_set(vcpuinfo, "@cpu_time", Qnil); rb_iv_set(vcpuinfo, "@cpu", Qnil); --=20 2.25.0