From nobody Mon Apr 29 15:48:20 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=fail; 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 ARC-Seal: i=1; a=rsa-sha256; t=1590666515; cv=none; d=zohomail.com; s=zohoarc; b=RT+/RJJNvQKF59PfwGkfJNM8ARhYZc5Tm5DoMnxuTZ2Lnmm/zx+urC6wKYOApCSnSlDHoaK+JENBKYHkm0XrrHtnTDayt1SbrF+obcmlr9dvO7SEJPhLuASDDxqG3HZpny3+TeQQxzbR8S6fYngZh2D6DVKep2k5QwzdLEyNVQ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590666515; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=jYFHpVCBp2KPyT07SJt1PsTQ64YTGLrO0WCrYprMmDI=; b=JbPjtLjfc6h4RckUh8IYNO8O2b3AYWxVBGlA7Kfw+TS/PuM2LyGTIy+la7MB38IAzgfSBDqUsgjm9IcDmbC4t3UP+Wfs1+xcRz5WZi/O83/Xf6tGMme8AfMtkusvc5ghHbNd1CmtTakNNwDahbldQMI4bWtuyLQPwkm6xYlqN30= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1590666515710266.36217122183325; Thu, 28 May 2020 04:48:35 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jeH14-00085V-Mx; Thu, 28 May 2020 11:48:06 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jeH13-00085P-Vx for xen-devel@lists.xenproject.org; Thu, 28 May 2020 11:48:06 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 177a73d1-a0d9-11ea-a7b3-12813bfff9fa; Thu, 28 May 2020 11:48:05 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jeH12-000298-Kk; Thu, 28 May 2020 11:48:04 +0000 Received: from [54.239.6.188] (helo=CBG-R90WXYV0.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jeH12-0007xu-Aa; Thu, 28 May 2020 11:48:04 +0000 X-Inumbo-ID: 177a73d1-a0d9-11ea-a7b3-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=jYFHpVCBp2KPyT07SJt1PsTQ64YTGLrO0WCrYprMmDI=; b=6JuK3sKqeektckDMmR+apcdh9L QmAQZ6+XfRSWIERqkfJwMPqbDVdaVAAx+eF7BvizAW3uslTcSD9zivivQuZj7NaH3zh/ngYfH4RLZ ASry70kAj6fGqxMfapm8bqIIb3gN+woKh1dAtg+7p2HNMSZTvyfjchl6D5uFBk7zLM8A=; From: Paul Durrant To: xen-devel@lists.xenproject.org Subject: [PATCH] libxl: stop libxl_domain_info() consuming massive amounts of stack Date: Thu, 28 May 2020 12:48:01 +0100 Message-Id: <20200528114801.20241-1-paul@xen.org> X-Mailer: git-send-email 2.17.1 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Anthony PERARD , Paul Durrant , Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Paul Durrant Currently an array of 1024 xc_domaininfo_t is declared on stack. That alone consumes ~112k. Since libxl_domain_info() creates a new gc this patch simply uses it to allocate the array instead. Signed-off-by: Paul Durrant --- Cc: Ian Jackson Cc: Wei Liu Cc: Anthony PERARD This is small and IMO it would be nice to have this in 4.14 but I'd like an opinion from a maintainer too. --- tools/libxl/libxl_domain.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/libxl/libxl_domain.c b/tools/libxl/libxl_domain.c index fef2cd4e13..c07ec8fd3a 100644 --- a/tools/libxl/libxl_domain.c +++ b/tools/libxl/libxl_domain.c @@ -314,11 +314,13 @@ libxl_dominfo * libxl_list_domain(libxl_ctx *ctx, int= *nb_domain_out) { libxl_dominfo *ptr =3D NULL; int i, ret; - xc_domaininfo_t info[1024]; + xc_domaininfo_t *info; int size =3D 0; uint32_t domid =3D 0; GC_INIT(ctx); =20 + info =3D libxl__calloc(gc, 1024, sizeof(*info)); + while ((ret =3D xc_domain_getinfolist(ctx->xch, domid, 1024, info)) > = 0) { ptr =3D libxl__realloc(NOGC, ptr, (size + ret) * sizeof(libxl_domi= nfo)); for (i =3D 0; i < ret; i++) { --=20 2.17.1