From nobody Fri Mar 29 08:44:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1642005733; cv=none; d=zohomail.com; s=zohoarc; b=iXOlessZvDMaY/Wx4eDNrtrAt/LUxUauhSrCqJvdm2hSXLP5jQm2MAyhCKjoabdjsEjkCnhFP6iYD//COoZUd3JvRavJI7vuA+wwgujaoxbOLcBUwa+aNRZVr5atu9O80U8NyMqVag7mAEKlhe4mEkFoUkSbJafk886rVyW8u3Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642005733; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=2SkX3v3mYWj0hVWfhFsLKlW92IvOMYnJLJq6xEKXvBs=; b=F5M9/etZqfZVZqNC2PDUT5zZQ3gx5ULpWE3tRAjyGOK5/gL3jeC2q3xt7lpZ1V71DXJc6AfhTm4wflaBxTpZKDaFAgGzgzQEQeXKU/kEChV74ZMAQOiwU8/B2qXymHMo2SZUXC5/T3SLxMT9lL1JpdiIn2LYM7HxY092r/CCLjs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1642005733414425.44620211911206; Wed, 12 Jan 2022 08:42:13 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.256746.440756 (Exim 4.92) (envelope-from ) id 1n7ggv-0006az-SW; Wed, 12 Jan 2022 16:41:41 +0000 Received: by outflank-mailman (output) from mailman id 256746.440756; Wed, 12 Jan 2022 16:41:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7ggv-0006as-PD; Wed, 12 Jan 2022 16:41:41 +0000 Received: by outflank-mailman (input) for mailman id 256746; Wed, 12 Jan 2022 16:41:40 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7ggu-0006Zx-9B for xen-devel@lists.xenproject.org; Wed, 12 Jan 2022 16:41:40 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 82e896d7-73c6-11ec-bd6f-bfb69f65cdc7; Wed, 12 Jan 2022 17:41:38 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B16181F3A3; Wed, 12 Jan 2022 16:41:37 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6EF8D13BE6; Wed, 12 Jan 2022 16:41:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id WQijGMEE32GwTAAAMHmgww (envelope-from ); Wed, 12 Jan 2022 16:41:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 82e896d7-73c6-11ec-bd6f-bfb69f65cdc7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642005697; h=from:from:reply-to: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=2SkX3v3mYWj0hVWfhFsLKlW92IvOMYnJLJq6xEKXvBs=; b=g8R7gRhSAvTrJ7gXaVTbgAaWBQ7D7n+192qXGrp2qakBz+tV3XWT+O8oGm5HsKfb27a1Pv i7KM3t8baWau7KfLLUztrO5HCh77yonWKnu0kUzZS3wkngGBJ8/X8BKLUz5RfWOmooROL4 5AOe7VDyE39RyyxyJem5mi156BV/jPk= Subject: [PATCH 1/2] tools/libs/light: numa placement: don't try to free a NULL list of vcpus From: Dario Faggioli To: xen-devel@lists.xenproject.org Cc: James Fehlig , Wei Liu , Anthony PERARD , Juergen Gross Date: Wed, 12 Jan 2022 17:41:36 +0100 Message-ID: <164200569629.24755.2980883411590685040.stgit@work> In-Reply-To: <164200566223.24755.262723784847161301.stgit@work> References: <164200566223.24755.262723784847161301.stgit@work> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642005734531100001 If libxl_vcpu_list() returned NULL, we should not call libxl_numainfo_list_free() as: 1) it'll fail trying to (double) free() *list 2) there should be nothing to free anyway Signed-off-by: Dario Faggioli Tested-by: James Fehlig --- Cc: Wei Liu Cc: Anthony PERARD Cc: Juergen Gross --- tools/libs/light/libxl_numa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/libs/light/libxl_numa.c b/tools/libs/light/libxl_numa.c index a8a75f89e9..3679028c79 100644 --- a/tools/libs/light/libxl_numa.c +++ b/tools/libs/light/libxl_numa.c @@ -253,9 +253,9 @@ static int nr_vcpus_on_nodes(libxl__gc *gc, libxl_cputo= pology *tinfo, } } =20 + libxl_vcpuinfo_list_free(vinfo, nr_dom_vcpus); next: libxl_cpupoolinfo_dispose(&cpupool_info); - libxl_vcpuinfo_list_free(vinfo, nr_dom_vcpus); } =20 libxl_bitmap_dispose(&dom_nodemap); From nobody Fri Mar 29 08:44:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1642005741; cv=none; d=zohomail.com; s=zohoarc; b=AHUfW8+vviHD/RZF+aHPdFUaGUO/XQZmuJciHhd8l8qgNr70inSRlhkQ6LX3e8nnK3fMd5RaiPCzx35htRV2x0wL9OYx96sYGBTUtx5uvx77FV4ER8KQfkWSTv364cv2sbuDWecAoyIr0AL2WAnCue7jw9qSswbQoXCQrC2tCCU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642005741; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=oqPxnpqVpg7+ZYnFXNDLlT5wDVvRC/DohNLeViPfz9I=; b=dwqFYm1CXmyiHwVrrNXKefoN4p8uG+UQEP5LKg2W8E7+4wp9zbpckgyXsOP5Xh7x37VwRvjrasvfpo0Ccyz0dCKIesnGxJ6TNbCuX9qCEUvNzCmHENBo1AwzWMgJZLm8tZ8ETGrtkllkMEDO2VfGyXdBHULtXqeN4loQfDo997A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1642005741553801.1540894523318; Wed, 12 Jan 2022 08:42:21 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.256747.440768 (Exim 4.92) (envelope-from ) id 1n7gh0-0006tx-4i; Wed, 12 Jan 2022 16:41:46 +0000 Received: by outflank-mailman (output) from mailman id 256747.440768; Wed, 12 Jan 2022 16:41:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7gh0-0006to-12; Wed, 12 Jan 2022 16:41:46 +0000 Received: by outflank-mailman (input) for mailman id 256747; Wed, 12 Jan 2022 16:41:45 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1n7ggz-0006Zx-1p for xen-devel@lists.xenproject.org; Wed, 12 Jan 2022 16:41:45 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 86aa41ae-73c6-11ec-bd6f-bfb69f65cdc7; Wed, 12 Jan 2022 17:41:44 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 17D161F3A3; Wed, 12 Jan 2022 16:41:44 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id CDBB813BE6; Wed, 12 Jan 2022 16:41:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id FLEHMMcE32HATAAAMHmgww (envelope-from ); Wed, 12 Jan 2022 16:41:43 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 86aa41ae-73c6-11ec-bd6f-bfb69f65cdc7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1642005704; h=from:from:reply-to: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=oqPxnpqVpg7+ZYnFXNDLlT5wDVvRC/DohNLeViPfz9I=; b=o7UjMZMAn2RHLUfPI7b6G/Phj+NqEBug1EBKWEpZqDAukpIwTKmIC0Q8X9NPgz4DwevFIW yZgHuKNFEkkGSlFyej1THoCNs/NVFXV+RdhdNIYl7X63T1WisCwfrzv9kP5GivIGYWz3DI E0rhY8HZaqdnpONpYnkeKux48PuUWwU= Subject: [PATCH 2/2] tools/libs/light: don't touch nr_vcpus_out if listing vcpus and returning NULL From: Dario Faggioli To: xen-devel@lists.xenproject.org Cc: James Fehlig , Wei Liu , Anthony PERARD , Juergen Gross Date: Wed, 12 Jan 2022 17:41:42 +0100 Message-ID: <164200570276.24755.1849386285622380597.stgit@work> In-Reply-To: <164200566223.24755.262723784847161301.stgit@work> References: <164200566223.24755.262723784847161301.stgit@work> User-Agent: StGit/0.23 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1642005743940100001 If we are in libvxl_list_vcpu() and we are returning NULL, let's avoid touching the output parameter *nr_vcpus_out (which should contain the number of vcpus in the list). Ideally, the caller initialized it to 0, which is therefore consistent with us returning NULL (or, as an alternative, we can explicitly set it to 0 if we're returning null... But just not touching it seems the best behavior). In fact, the current behavior is especially problematic if, for instance, a domain is destroyed after we have done some steps of the for() loop. In which case, calls like xc_vcpu_getinfo() or xc_vcpu_getaffinity() will start to fail, and we return back to the caller inconsistent information, such as a NULL list of vcpus, but a modified and not 0 any longer, number of vcpus in the list. Signed-off-by: Dario Faggioli Tested-by: James Fehlig --- Cc: Wei Liu Cc: Anthony PERARD Cc: Juergen Gross --- tools/libs/light/libxl_domain.c | 14 ++++++++------ tools/libs/light/libxl_numa.c | 4 +++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tools/libs/light/libxl_domain.c b/tools/libs/light/libxl_domai= n.c index 544a9bf59d..aabc264e16 100644 --- a/tools/libs/light/libxl_domain.c +++ b/tools/libs/light/libxl_domain.c @@ -1661,6 +1661,7 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint3= 2_t domid, libxl_vcpuinfo *ptr, *ret; xc_domaininfo_t domaininfo; xc_vcpuinfo_t vcpuinfo; + int nr_vcpus; =20 if (xc_domain_getinfolist(ctx->xch, domid, 1, &domaininfo) !=3D 1) { LOGED(ERROR, domid, "Getting infolist"); @@ -1677,27 +1678,27 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uin= t32_t domid, ret =3D ptr =3D libxl__calloc(NOGC, domaininfo.max_vcpu_id + 1, sizeof(libxl_vcpuinfo)); =20 - for (*nr_vcpus_out =3D 0; - *nr_vcpus_out <=3D domaininfo.max_vcpu_id; - ++*nr_vcpus_out, ++ptr) { + for (nr_vcpus =3D 0; + nr_vcpus <=3D domaininfo.max_vcpu_id; + ++nr_vcpus, ++ptr) { libxl_bitmap_init(&ptr->cpumap); if (libxl_cpu_bitmap_alloc(ctx, &ptr->cpumap, 0)) goto err; libxl_bitmap_init(&ptr->cpumap_soft); if (libxl_cpu_bitmap_alloc(ctx, &ptr->cpumap_soft, 0)) goto err; - if (xc_vcpu_getinfo(ctx->xch, domid, *nr_vcpus_out, &vcpuinfo) =3D= =3D -1) { + if (xc_vcpu_getinfo(ctx->xch, domid, nr_vcpus, &vcpuinfo) =3D=3D -= 1) { LOGED(ERROR, domid, "Getting vcpu info"); goto err; } =20 - if (xc_vcpu_getaffinity(ctx->xch, domid, *nr_vcpus_out, + if (xc_vcpu_getaffinity(ctx->xch, domid, nr_vcpus, ptr->cpumap.map, ptr->cpumap_soft.map, XEN_VCPUAFFINITY_SOFT|XEN_VCPUAFFINITY_HAR= D) =3D=3D -1) { LOGED(ERROR, domid, "Getting vcpu affinity"); goto err; } - ptr->vcpuid =3D *nr_vcpus_out; + ptr->vcpuid =3D nr_vcpus; ptr->cpu =3D vcpuinfo.cpu; ptr->online =3D !!vcpuinfo.online; ptr->blocked =3D !!vcpuinfo.blocked; @@ -1705,6 +1706,7 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint3= 2_t domid, ptr->vcpu_time =3D vcpuinfo.cpu_time; } GC_FREE; + *nr_vcpus_out =3D nr_vcpus; return ret; =20 err: diff --git a/tools/libs/light/libxl_numa.c b/tools/libs/light/libxl_numa.c index 3679028c79..b04e3917a0 100644 --- a/tools/libs/light/libxl_numa.c +++ b/tools/libs/light/libxl_numa.c @@ -219,8 +219,10 @@ static int nr_vcpus_on_nodes(libxl__gc *gc, libxl_cput= opology *tinfo, goto next; =20 vinfo =3D libxl_list_vcpu(CTX, dinfo[i].domid, &nr_dom_vcpus, &nr_= cpus); - if (vinfo =3D=3D NULL) + if (vinfo =3D=3D NULL) { + assert(nr_dom_vcpus =3D=3D 0); goto next; + } =20 /* Retrieve the domain's node-affinity map */ libxl_domain_get_nodeaffinity(CTX, dinfo[i].domid, &dom_nodemap);