From nobody Tue May 14 13:30:34 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=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1682521233; cv=none; d=zohomail.com; s=zohoarc; b=lCBmjta+UQwt3AOD/SssB4IJm3I8NxfRZ7KKWe4bS+iBK0qdnGgxYmyZY6YfFFzoh10uVzMeCTinl6/4cuBa5RaTMY0BYrivMKs6gb10PZVLeyHIRtdXt7znWtPAV2D8gESBYmbmlb3/kQyrGreVnf27n4s6NgRrsi7t9AiDS2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682521233; h=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=GPXQUFmJANWtRSEJizBlmBuJVzkoyDDxbZ36Iy8xMlY=; b=KtvPEqTPmYWKv7xyvUt/PE+MUXzWwhcyhjTXCz5bXNgTPLfzSrBy+clM2l795bwzeY19CFnYs5n7M1+oumjAuDo9X1zSJgCZv0W/KbcYJ+4FjFgAJBWauSjxmwG64Lt0PtIHRUIZhva+mXDqXeTVD06xFs/8l6epfIJht7iMVwo= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682521233050609.0176087141027; Wed, 26 Apr 2023 08:00:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.526747.818676 (Exim 4.92) (envelope-from ) id 1prgcS-0000rc-C5; Wed, 26 Apr 2023 14:59:44 +0000 Received: by outflank-mailman (output) from mailman id 526747.818676; Wed, 26 Apr 2023 14:59:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1prgcS-0000rR-8t; Wed, 26 Apr 2023 14:59:44 +0000 Received: by outflank-mailman (input) for mailman id 526747; Wed, 26 Apr 2023 14:59:42 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1prgcQ-0000bz-OW for xen-devel@lists.xenproject.org; Wed, 26 Apr 2023 14:59:42 +0000 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [2a00:1450:4864:20::441]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f8656139-e442-11ed-8611-37d641c3527e; Wed, 26 Apr 2023 16:59:41 +0200 (CEST) Received: by mail-wr1-x441.google.com with SMTP id ffacd0b85a97d-2f7a7f9667bso4529552f8f.1 for ; Wed, 26 Apr 2023 07:59:41 -0700 (PDT) Received: from localhost.localdomain (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id v17-20020a5d43d1000000b003047ea78b42sm6654116wrr.43.2023.04.26.07.59.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 07:59:38 -0700 (PDT) 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: f8656139-e442-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1682521179; x=1685113179; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GPXQUFmJANWtRSEJizBlmBuJVzkoyDDxbZ36Iy8xMlY=; b=cQpl9qbpxf7rta6xIMY73ap19qqUEtWRCoT83Xl2dd7h75ijI6RiGAuRvhdMYY2MDA iAX0Ha6+IaSlue/rS2jtE9TQhFEWTNMDKFVgRSY3qIqQqLJcXiASx1ru0stUXI6zeXlx 8JPSwb4AyTkg0WkXjqfdeOSiSTLL99IOZZfds= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682521179; x=1685113179; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GPXQUFmJANWtRSEJizBlmBuJVzkoyDDxbZ36Iy8xMlY=; b=PuqSMXoqrF3h10OQOGo3VuzwbBXAnT9KHFVeQQZjXwtoxsipEYPl+abgJTwdqRWtpu ECNFUn2IHD6nGGbuxAVfgG6kQXJs4B1t+5ZFO302wUmNgGBdlLXDxFvmXJe0QwtIXUbI KpeUkVW1pk3rX2uAtLI/1tyhRoyHJHRbD1XWB2QrRQyGZMFtLqIDNesNPPXx4OGv6F3D hlD3ddVAbF7AFOIxVdeBr6uM5n+chd3GWl1ikYgVj2nkPhYsAX3yfoxQ0SE0JBMRKhbS p1SkRMt6Xuj/U323LABOmzKfXS1QkGmX6z9OhoBIvckXKcfV+Zcdti+MeRtaz9dmji7a bVSA== X-Gm-Message-State: AAQBX9coDEySX5xvNlkONLWaf4itEOKBJz44uLbmQn2KoM9uevmqrYBy 5VtXl+xeYcvOnT1Zn31PncuWL+QOChImMBpSuyOAPQ== X-Google-Smtp-Source: AKy350Yamqi6Z9wNCPW6Nlmb5C/dSHeaLKEaMUxtujLbZj+v6bod9X89zyCRsNhe5eHuw1fRY1Ucfw== X-Received: by 2002:adf:f3d0:0:b0:2ee:fa23:7904 with SMTP id g16-20020adff3d0000000b002eefa237904mr13332616wrp.70.1682521179434; Wed, 26 Apr 2023 07:59:39 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Andrew Cooper , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH 1/7] tools: Make some callers of xc_domain_getinfo use xc_domain_getinfolist Date: Wed, 26 Apr 2023 15:59:26 +0100 Message-Id: <20230426145932.3340-2-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230426145932.3340-1-alejandro.vallejo@cloud.com> References: <20230426145932.3340-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1682521234533100003 Content-Type: text/plain; charset="utf-8" xc_domain_getinfo() is slow and prone to races because N hypercalls are needed to find information about N domains. xc_domain_getinfolist() finds the same information in a single hypercall as long as a big enough buffer is provided. Plus, xc_domain_getinfo() is disappearing on a future patch so migrate the callers interested in more than 1 domain to the the *list() version. Signed-off-by: Alejandro Vallejo --- Cc: Andrew Cooper Cc: Wei Liu Cc: Anthony PERARD Cc: Juergen Gross --- tools/include/xenctrl.h | 5 +++++ tools/python/xen/lowlevel/xc/xc.c | 29 +++++++++++++++-------------- tools/xenmon/xenbaked.c | 6 +++--- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 05967ecc92..90b33aa3a7 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -468,6 +468,11 @@ typedef struct xc_dominfo { =20 typedef xen_domctl_getdomaininfo_t xc_domaininfo_t; =20 +static inline unsigned int dominfo_shutdown_reason(const xc_domaininfo_t *= info) +{ + return (info->flags >> XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdown= mask; +} + typedef union=20 { #if defined(__i386__) || defined(__x86_64__) diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/= xc/xc.c index 35901c2d63..38212e8091 100644 --- a/tools/python/xen/lowlevel/xc/xc.c +++ b/tools/python/xen/lowlevel/xc/xc.c @@ -342,7 +342,7 @@ static PyObject *pyxc_domain_getinfo(XcObject *self, uint32_t first_dom =3D 0; int max_doms =3D 1024, nr_doms, i; size_t j; - xc_dominfo_t *info; + xc_domaininfo_t *info; =20 static char *kwd_list[] =3D { "first_dom", "max_doms", NULL }; =20 @@ -350,11 +350,11 @@ static PyObject *pyxc_domain_getinfo(XcObject *self, &first_dom, &max_doms) ) return NULL; =20 - info =3D calloc(max_doms, sizeof(xc_dominfo_t)); + info =3D calloc(max_doms, sizeof(*info)); if (info =3D=3D NULL) return PyErr_NoMemory(); =20 - nr_doms =3D xc_domain_getinfo(self->xc_handle, first_dom, max_doms, in= fo); + nr_doms =3D xc_domain_getinfolist(self->xc_handle, first_dom, max_doms= , info); =20 if (nr_doms < 0) { @@ -368,21 +368,22 @@ static PyObject *pyxc_domain_getinfo(XcObject *self, info_dict =3D Py_BuildValue( "{s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i,s:i" ",s:L,s:L,s:L,s:i,s:i,s:i}", - "domid", (int)info[i].domid, + "domid", (int)info[i].domain, "online_vcpus", info[i].nr_online_vcpus, "max_vcpu_id", info[i].max_vcpu_id, - "hvm", info[i].hvm, - "dying", info[i].dying, - "crashed", info[i].crashed, - "shutdown", info[i].shutdown, - "paused", info[i].paused, - "blocked", info[i].blocked, - "running", info[i].running, - "mem_kb", (long long)info[i].nr_pages*(XC_PAGE_SIZE/1= 024), + "hvm", !!(info[i].flags & XEN_DOMINF_hvm_guest), + "dying", !!(info[i].flags & XEN_DOMINF_dying), + "crashed", (info[i].flags & XEN_DOMINF_shutdown) && + (dominfo_shutdown_reason(&info[i]) =3D=3D= SHUTDOWN_crash), + "shutdown", !!(info[i].flags & XEN_DOMINF_shutdown), + "paused", !!(info[i].flags & XEN_DOMINF_paused), + "blocked", !!(info[i].flags & XEN_DOMINF_blocked), + "running", !!(info[i].flags & XEN_DOMINF_running), + "mem_kb", (long long)info[i].tot_pages*(XC_PAGE_SIZE/= 1024), "cpu_time", (long long)info[i].cpu_time, - "maxmem_kb", (long long)info[i].max_memkb, + "maxmem_kb", (long long)(info[i].max_pages << (XC_PAGE_S= HIFT - 10)), "ssidref", (int)info[i].ssidref, - "shutdown_reason", info[i].shutdown_reason, + "shutdown_reason", dominfo_shutdown_reason(&info[i]), "cpupool", (int)info[i].cpupool); pyhandle =3D PyList_New(sizeof(xen_domain_handle_t)); if ( (pyhandle =3D=3D NULL) || (info_dict =3D=3D NULL) ) diff --git a/tools/xenmon/xenbaked.c b/tools/xenmon/xenbaked.c index 4dddbd20e2..8632b10ea4 100644 --- a/tools/xenmon/xenbaked.c +++ b/tools/xenmon/xenbaked.c @@ -775,7 +775,7 @@ static void global_init_domain(int domid, int idx) static int indexof(int domid) { int idx; - xc_dominfo_t dominfo[NDOMAINS]; + xc_domaininfo_t dominfo[NDOMAINS]; xc_interface *xc_handle; int ndomains; =20 @@ -797,7 +797,7 @@ static int indexof(int domid) =20 // call domaininfo hypercall to try and garbage collect unused entries xc_handle =3D xc_interface_open(0,0,0); - ndomains =3D xc_domain_getinfo(xc_handle, 0, NDOMAINS, dominfo); + ndomains =3D xc_domain_getinfolist(xc_handle, 0, NDOMAINS, dominfo); xc_interface_close(xc_handle); =20 // for each domain in our data, look for it in the system dominfo stru= cture @@ -808,7 +808,7 @@ static int indexof(int domid) int jdx; =20 for (jdx=3D0; jdx (p=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682521233535306.35376469116693; Wed, 26 Apr 2023 08:00:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.526748.818682 (Exim 4.92) (envelope-from ) id 1prgcS-0000uf-NV; Wed, 26 Apr 2023 14:59:44 +0000 Received: by outflank-mailman (output) from mailman id 526748.818682; Wed, 26 Apr 2023 14:59:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1prgcS-0000uF-Iq; Wed, 26 Apr 2023 14:59:44 +0000 Received: by outflank-mailman (input) for mailman id 526748; Wed, 26 Apr 2023 14:59:43 +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 1prgcR-0000cE-4i for xen-devel@lists.xenproject.org; Wed, 26 Apr 2023 14:59:43 +0000 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [2a00:1450:4864:20::42b]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id f96807f5-e442-11ed-b224-6b7b168915f2; Wed, 26 Apr 2023 16:59:42 +0200 (CEST) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-2f7db354092so4529844f8f.2 for ; Wed, 26 Apr 2023 07:59:42 -0700 (PDT) Received: from localhost.localdomain (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id v17-20020a5d43d1000000b003047ea78b42sm6654116wrr.43.2023.04.26.07.59.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 07:59:40 -0700 (PDT) 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: f96807f5-e442-11ed-b224-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1682521181; x=1685113181; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mmERS2liqEHDrbW1Ycwm/uU3R2wj9QakSk+FoH5C6bM=; b=ilPmWn7nj10VuZmEUluxGvctuWIjxS03O93jjXKqnhTefPbgbOzlLw78W3PZFPE4my c8bBGm6m1WFL0Y1ObwSX+3QNp5ORWDjKO22n461KjhoPhB61kwL6n2NEhe7JxVuh275P qqyYVXkgzuGPU7NqeyXr0wcExx11XL2JspYSw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682521181; x=1685113181; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mmERS2liqEHDrbW1Ycwm/uU3R2wj9QakSk+FoH5C6bM=; b=XXln4e7H2B8ZCA9jqxHJdrSAO7LaRmEiOhJtCmS8hxWfygHvraJQFTjlU+6gBYcvWZ Nc/doUfHJRL8sigqyukHIdYu2ym+2zYK7F4T1cvmR2YBYGlPPNWIvT5xI2215b2G3jRj 24loZkK8L5jlmfCV3M5Qc4hr/BIZxnXLigEjNXNslAfvDtSN50vyE5CsOTcbmtN68GE+ ZB3GIwEowdsdP4+8/Ky3lCPCECPEc518YJZRF9/X0lF4NrJeDi+QX8XyDtjOe7vhc11C ZNYP83GLIWTWUKR2DhwGBQNwptY7E9m9FyFOT6H70sNSGwXT1nrAup7loUq80d8AIEg5 AI5w== X-Gm-Message-State: AAQBX9f1llVT3tvrpCHe+QAnNm5Nx7oBOn3kgryw3D9j+eqA/EtI+RCa xen3R829Wmh8gygnsXo9LxYddP4L3FCXs1w7cHk= X-Google-Smtp-Source: AKy350Zh87+7rMSV0zQ/4l32i4gMVMhSQBMrhTpfpjG0umZMEvTPcYok0gQh6j/HB8qcGkoE4rXcFA== X-Received: by 2002:a5d:4e01:0:b0:304:6715:8728 with SMTP id p1-20020a5d4e01000000b0030467158728mr10762186wrt.18.1682521181193; Wed, 26 Apr 2023 07:59:41 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Andrew Cooper , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH 2/7] tools: Create xc_domain_getinfo_single() Date: Wed, 26 Apr 2023 15:59:27 +0100 Message-Id: <20230426145932.3340-3-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230426145932.3340-1-alejandro.vallejo@cloud.com> References: <20230426145932.3340-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1682521235828100007 Content-Type: text/plain; charset="utf-8" It's a stricter version of xc_domain_getinfo() where the returned domid always matches the requested domid or the error code shows an error instead. A few patches ahead usages of xc_domain_getinfo() are removed until only xc_domain_getinfo_single() and xc_domain_getinfolist() remain. Signed-off-by: Alejandro Vallejo Reviewed-by: Andrew Cooper --- Cc: Andrew Cooper Cc: Wei Liu Cc: Anthony PERARD Cc: Juergen Gross --- tools/include/xenctrl.h | 16 ++++++++++++++++ tools/libs/ctrl/xc_domain.c | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 90b33aa3a7..73b07955c6 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -696,6 +696,22 @@ int xc_vcpu_getaffinity(xc_interface *xch, int xc_domain_get_guest_width(xc_interface *xch, uint32_t domid, unsigned int *guest_width); =20 +/** + * This function will return information about a single domain. It looks + * up the domain by the provided domid and succeeds if the domain exists + * and is accesible by the current domain, or fails otherwise. A buffer + * may optionally passed on the `info` parameter in order to retrieve + * information about the domain. The buffer is ignored if NULL is + * passed instead. + * + * @parm xch a handle to an open hypervisor interface + * @parm domid domid to lookup + * @parm info Optional domain information buffer (may be NULL) + * @return 0 on success, otherwise the call failed and info is undefined + */ +int xc_domain_getinfo_single(xc_interface *xch, + uint32_t domid, + xc_domaininfo_t *info); =20 /** * This function will return information about one or more domains. It is diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c index e939d07157..3ff91023bf 100644 --- a/tools/libs/ctrl/xc_domain.c +++ b/tools/libs/ctrl/xc_domain.c @@ -345,6 +345,28 @@ int xc_dom_vuart_init(xc_interface *xch, return rc; } =20 +int xc_domain_getinfo_single(xc_interface *xch, + uint32_t domid, + xc_domaininfo_t *info) +{ + struct xen_domctl domctl =3D { + .cmd =3D XEN_DOMCTL_getdomaininfo, + .domain =3D domid, + }; + + int rc =3D do_domctl(xch, &domctl); + if (rc < 0) + return rc; + + if (domctl.u.getdomaininfo.domain !=3D domid) + return -ESRCH; + + if (info) + *info =3D domctl.u.getdomaininfo; + + return rc; +} + int xc_domain_getinfo(xc_interface *xch, uint32_t first_domid, unsigned int max_doms, --=20 2.34.1 From nobody Tue May 14 13:30:34 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=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1682521232; cv=none; d=zohomail.com; s=zohoarc; b=mGFS1B6rh0JyBQSiS2L5WkNBWKwL0lwVVVARdggRhufnQHJdjgDJAOCvZl4N7TKOt8/TkG/uaSFTRD22PGu4qm/KN85uuEaB2kxZeF8fb9JgL2I2hhcA2m2iaTXmeFC/iyQZXTYh5tB5jGZvek/SRPcdIPfmFqlu+Z8HqoXkrFU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682521232; h=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=X/n8iDxY+gFzED/faB3xf5M0UlbwG5Zihhb3i4U/Bo0=; b=EMHevKPr8JM5RZJGc9F0N/vrHWNeU15MHHOmZKR9QHPpn73CdiFWzRnjwljkIJJeWlgwOFdFB4PeXKY0mtI+eHJydF9ake9W25RPhajY2/sMQYWuOW+HzRAIz40hpOiaonnp8j6FMNP2RijAzfnjaCemLQ4r+5j56UIAAo8I0GM= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682521232397236.8672673215449; Wed, 26 Apr 2023 08:00:32 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.526749.818696 (Exim 4.92) (envelope-from ) id 1prgcU-0001Nd-3M; Wed, 26 Apr 2023 14:59:46 +0000 Received: by outflank-mailman (output) from mailman id 526749.818696; Wed, 26 Apr 2023 14:59: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 1prgcU-0001NU-0J; Wed, 26 Apr 2023 14:59:46 +0000 Received: by outflank-mailman (input) for mailman id 526749; Wed, 26 Apr 2023 14:59:44 +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 1prgcS-0000cE-KT for xen-devel@lists.xenproject.org; Wed, 26 Apr 2023 14:59:44 +0000 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [2a00:1450:4864:20::430]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fa67221c-e442-11ed-b224-6b7b168915f2; Wed, 26 Apr 2023 16:59:44 +0200 (CEST) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-2f95231618aso4622014f8f.1 for ; Wed, 26 Apr 2023 07:59:44 -0700 (PDT) Received: from localhost.localdomain (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id v17-20020a5d43d1000000b003047ea78b42sm6654116wrr.43.2023.04.26.07.59.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 07:59:42 -0700 (PDT) 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: fa67221c-e442-11ed-b224-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1682521183; x=1685113183; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=X/n8iDxY+gFzED/faB3xf5M0UlbwG5Zihhb3i4U/Bo0=; b=SL13iuQjTgVU85bnRoAsthjqKmb/1hm7tIYLgNQKtfXUyHNkx7wP6IrbLJpQedK0GJ Gh7/nCU/aYrUbDrsVfHLgRuBKx1syn2buHTJS60mKrRbPKZn/mPryg3+xCbpBvXkqPc+ nEqHFC3wqzIfJJBVgdv2sjTOAb3EsSl51OCKs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682521183; x=1685113183; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X/n8iDxY+gFzED/faB3xf5M0UlbwG5Zihhb3i4U/Bo0=; b=Jj1Tp6nKXQnZq4F1QNLlh4ODwZChQ8DLlspz0rQ0NUILM9q1VYs/Rh7Jt8LOQB1Py2 kzGtNgw4u6RAVqiFV9ePpga0HhZC0QB9X8yvoRuKUNqHxUhX/+mHhW7irkf2Qw3AP2ns c/CKIM4kuD2o68yjn6U07PEyVV3iAegAg+wGUCDGjubi9iU9Uv1Z0E4XFUpExsS/8A74 WgQbCjbJ4kS1NysWotb/y8kQiN7K3Gd8vz1Ws6vBFQ+IP7ZqUF8i5wYyk5meHRzbN/D7 RFquYsh+9r9wKxpZ3AtNAbWMb3WA7qG9FaFJFN70zzZaJBzx73hkBXHnqodfFfO6V2oo Fn6g== X-Gm-Message-State: AAQBX9cbItLD2EJCeDZ3JZzev7uYZwzemtdka0xe+DwGKUmq/4r9dD/F KYOFDpXAHHHE7L70vPCU7voCp7HIrZU9Jw5p6D8= X-Google-Smtp-Source: AKy350b7muSWZSZZXgN3C3/C/ZlWpkhbbgWHWwL+RxuioWyLwpejK9lvwcfQqqvtbhaD/R+F0vRCyQ== X-Received: by 2002:adf:dece:0:b0:2d8:47c7:7b52 with SMTP id i14-20020adfdece000000b002d847c77b52mr14977960wrn.9.1682521182906; Wed, 26 Apr 2023 07:59:42 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Andrew Cooper , Wei Liu , Anthony PERARD Subject: [PATCH 3/7] tools: Refactor the console/io.c to avoid using xc_domain_getinfo() Date: Wed, 26 Apr 2023 15:59:28 +0100 Message-Id: <20230426145932.3340-4-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230426145932.3340-1-alejandro.vallejo@cloud.com> References: <20230426145932.3340-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1682521234824100005 Content-Type: text/plain; charset="utf-8" It has 2 avoidable occurences * Check whether a domain is valid, which can be done faster with xc_domain_getinfo_single() * Domain discovery, which can be done much faster with the sysctl interface through xc_domain_getinfolist(). Signed-off-by: Alejandro Vallejo --- Cc: Andrew Cooper Cc: Wei Liu Cc: Anthony PERARD --- tools/console/daemon/io.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/tools/console/daemon/io.c b/tools/console/daemon/io.c index 6bfe96715b..1fc56f6643 100644 --- a/tools/console/daemon/io.c +++ b/tools/console/daemon/io.c @@ -405,13 +405,7 @@ static void buffer_advance(struct buffer *buffer, size= _t len) =20 static bool domain_is_valid(int domid) { - bool ret; - xc_dominfo_t info; - - ret =3D (xc_domain_getinfo(xc, domid, 1, &info) =3D=3D 1 && - info.domid =3D=3D domid); - =09 - return ret; + return xc_domain_getinfo_single(xc, domid, NULL) =3D=3D 0; } =20 static int create_hv_log(void) @@ -959,26 +953,35 @@ static void shutdown_domain(struct domain *d) =20 static unsigned enum_pass =3D 0; =20 +/** + * Memory set aside to query the state of every + * domain in the hypervisor in a single hypercall. + */ +static xc_domaininfo_t domaininfo[DOMID_FIRST_RESERVED - 1]; + static void enum_domains(void) { - int domid =3D 1; - xc_dominfo_t dominfo; + int ret; struct domain *dom; =20 enum_pass++; =20 - while (xc_domain_getinfo(xc, domid, 1, &dominfo) =3D=3D 1) { - dom =3D lookup_domain(dominfo.domid); - if (dominfo.dying) { + /* Fetch info on every valid domain except for dom0 */ + ret =3D xc_domain_getinfolist(xc, 1, DOMID_FIRST_RESERVED - 1, domaininfo= ); + if (ret < 0) + return; + + for (size_t i =3D 0; i < ret; i++) { + dom =3D lookup_domain(domaininfo[i].domain); + if (domaininfo[i].flags & XEN_DOMINF_dying) { if (dom) shutdown_domain(dom); } else { if (dom =3D=3D NULL) - dom =3D create_domain(dominfo.domid); + dom =3D create_domain(domaininfo[i].domain); } if (dom) dom->last_seen =3D enum_pass; - domid =3D dominfo.domid + 1; } } =20 --=20 2.34.1 From nobody Tue May 14 13:30:34 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=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1682521240; cv=none; d=zohomail.com; s=zohoarc; b=lzVkwbK1PPDim0aTfdb4E4WGpI4IyhUxvDzliWYfcOM0nJ6w5VdiIDfq93CyZ/PersOMo8lZ+Puyvc8Y1cyTIoIQxau+dXHzh1Zs8bywC2lPfV3cs7AuX9wDTs9C7yRVHIJ/jqdvm36KHcKum0cwwB6HVjp+M0SnVEwLpC3BsXA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682521240; h=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=7oGcNamzq83RSDTcW0FBMjk99Wl1dp80foK2pDBAN98=; b=Nm+Uk6bTPERYoJknMYlNhMRb1U3HGaSKeBrIE/hZLIo5nhXjDjWL1P7CeeeAmXTPccJn+QCk+Ydn3b8q2wxOQltQzIBbL6JKZLT2I5Md+c8aoI7x5TRPdGESrrJUZzC6/SNfDqwAcvmqWAmtcZ5RLZieA7/DVjHoYgum04xgnLw= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682521240176174.70397280222437; Wed, 26 Apr 2023 08:00:40 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.526750.818707 (Exim 4.92) (envelope-from ) id 1prgcX-0001hR-CS; Wed, 26 Apr 2023 14:59:49 +0000 Received: by outflank-mailman (output) from mailman id 526750.818707; Wed, 26 Apr 2023 14:59:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1prgcX-0001hI-8w; Wed, 26 Apr 2023 14:59:49 +0000 Received: by outflank-mailman (input) for mailman id 526750; Wed, 26 Apr 2023 14:59:47 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1prgcV-0000bz-LF for xen-devel@lists.xenproject.org; Wed, 26 Apr 2023 14:59:47 +0000 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [2a00:1450:4864:20::344]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fb69d864-e442-11ed-8611-37d641c3527e; Wed, 26 Apr 2023 16:59:46 +0200 (CEST) Received: by mail-wm1-x344.google.com with SMTP id 5b1f17b1804b1-3f195b164c4so38226505e9.1 for ; Wed, 26 Apr 2023 07:59:46 -0700 (PDT) Received: from localhost.localdomain (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id v17-20020a5d43d1000000b003047ea78b42sm6654116wrr.43.2023.04.26.07.59.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 07:59:43 -0700 (PDT) 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: fb69d864-e442-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1682521184; x=1685113184; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7oGcNamzq83RSDTcW0FBMjk99Wl1dp80foK2pDBAN98=; b=Hl26xmLqoalAyuUskJWFwA3NyNZTQ4t0E3QRIP/EjrPvqlwP0GA+lZ5HPpxo22DWOk pHhSuN+K9ghqHpKB7yXMaHhl+i220M/gAiv/M5QWyxLBr39B8H0iRdk2SPvXTNyrVhbF T4niznkfbKGC1wFypzTlkqYkA76mF1hKmEGXU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682521184; x=1685113184; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7oGcNamzq83RSDTcW0FBMjk99Wl1dp80foK2pDBAN98=; b=SAJFJlpOw58rTu0mo07Lyxx/Dg+nV1xLxEE6nDSDCQf1aBZPBH+yqVYMkzGxnCUEWg GMbg2NsxUCFWUsP1/Aj3vTLzsFB8qaumgweXuLFURzy/b3+e1Y3nSxiaCfe7pUW+oErA h4zzS0/yUL8twBsHtfc4nII4joF3eEzzf7LRb70plJ7PNpYtknEGhEseyF61O21lk7Yp hjtKJB7Vdid9E9jO3krW6UA94UxTeLoj+s1fWPjHYk2KbSdDDuknCBjQIMYonW8WzxKC 7YwfiNvNaRxXh+b2VQ1CI3tbU6T2gmA9t5yWScqtjarvv423Gyq5EB2GO7Q8wIyPctUu NJXA== X-Gm-Message-State: AAQBX9ft1HIOXr5VFS5MLU8145giN5ET3cx/FUlr+g33YT8FCYKR3Xya 9WBfrSOuTt4PgjXMHJ6yFEAIvRJnuS7UYXIo65rpwQ== X-Google-Smtp-Source: AKy350bcd+UvEAzKLO6obU/iO59tbgHrProju74w+psAGKtSZ6hWKlorVHdNsC37N2u/GIcK0atBMw== X-Received: by 2002:a7b:ce04:0:b0:3f0:f3ee:9e2a with SMTP id m4-20020a7bce04000000b003f0f3ee9e2amr13094550wmc.35.1682521184572; Wed, 26 Apr 2023 07:59:44 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Andrew Cooper , Wei Liu , Juergen Gross Subject: [PATCH 4/7] tools: Make init-xenstore-domain use xc_domain_getinfolist() Date: Wed, 26 Apr 2023 15:59:29 +0100 Message-Id: <20230426145932.3340-5-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230426145932.3340-1-alejandro.vallejo@cloud.com> References: <20230426145932.3340-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1682521242564100001 Content-Type: text/plain; charset="utf-8" It currently relies on xc_domain_getinfo() returning the next available domain past "first_domid", which is a feature that will disappear in a future patch. Furthermore and while at it, make it so the hypercall tries to fetch inform= ation about more than one domain per hypercall so we can (hopefully) get away wit= h a single hypercall in a typical system. Signed-off-by: Alejandro Vallejo Reviewed-by: Juergen Gross --- Cc: Andrew Cooper Cc: Wei Liu Cc: Juergen Gross --- tools/helpers/init-xenstore-domain.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tools/helpers/init-xenstore-domain.c b/tools/helpers/init-xens= tore-domain.c index 0950ba7dc5..5f40901d31 100644 --- a/tools/helpers/init-xenstore-domain.c +++ b/tools/helpers/init-xenstore-domain.c @@ -21,6 +21,7 @@ #define LAPIC_BASE_ADDRESS 0xfee00000UL #define MB(x) ((uint64_t)x << 20) #define GB(x) ((uint64_t)x << 30) +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) =20 static uint32_t domid =3D ~0; static char *kernel; @@ -322,16 +323,19 @@ err: =20 static int check_domain(xc_interface *xch) { - xc_dominfo_t info; + xc_domaininfo_t info[8]; uint32_t dom; int ret; =20 dom =3D 1; - while ( (ret =3D xc_domain_getinfo(xch, dom, 1, &info)) =3D=3D 1 ) + while ( (ret =3D xc_domain_getinfolist(xch, dom, ARRAY_SIZE(info), inf= o)) > 0 ) { - if ( info.xenstore ) - return 1; - dom =3D info.domid + 1; + for ( size_t i =3D 0; i < ret; i++ ) + { + if ( info[i].flags & XEN_DOMINF_xs_domain ) + return 1; + } + dom =3D info[ret - 1].domain + 1; } if ( ret < 0 && errno !=3D ESRCH ) { --=20 2.34.1 From nobody Tue May 14 13:30:34 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=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1682521237; cv=none; d=zohomail.com; s=zohoarc; b=SZQVjrJqu3ROM2OXUnPMKql+37OX8MHK5yZ6WIp3pGKi7Z7X7BKP9dwsDlgRZoTJuzGxlMr45YHdmqRDPy92Xw3InTIHIQIdJdu4aF2g+Oo44bmWAvkyPomYgz2vFI39DgFu0KTyfRx7ZlXRVejKYgsxZ874ubJU9ny7V4z/u/s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682521237; h=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=ZFE69b1k1YkDEEzbAUbLCBpAHxB5+1bvQjqKSxJf1mg=; b=QJ92j1YVVCHcMhnAvMbNUVD43M2xarbp7jl+yzyLIMaGyfbZCROKNCPUi5eCYoTkpBn4Hau2X7nlbm6Xl/QKzNrKzXl2tV2D/pJ+Q5sWdjJzA6UshRHNq55+fEEHDKtobOU9tKxQ1rh4zyTz+zBWMagKqOwNDpZTzaBFjef3IMM= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682521237178794.7177450945; Wed, 26 Apr 2023 08:00:37 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.526751.818713 (Exim 4.92) (envelope-from ) id 1prgcX-0001lI-PE; Wed, 26 Apr 2023 14:59:49 +0000 Received: by outflank-mailman (output) from mailman id 526751.818713; Wed, 26 Apr 2023 14:59:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1prgcX-0001kH-H2; Wed, 26 Apr 2023 14:59:49 +0000 Received: by outflank-mailman (input) for mailman id 526751; Wed, 26 Apr 2023 14:59:48 +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 1prgcW-0000cE-0S for xen-devel@lists.xenproject.org; Wed, 26 Apr 2023 14:59:48 +0000 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [2a00:1450:4864:20::430]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id fc6d5dcd-e442-11ed-b224-6b7b168915f2; Wed, 26 Apr 2023 16:59:47 +0200 (CEST) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-2f4214b430aso4537615f8f.0 for ; Wed, 26 Apr 2023 07:59:47 -0700 (PDT) Received: from localhost.localdomain (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id v17-20020a5d43d1000000b003047ea78b42sm6654116wrr.43.2023.04.26.07.59.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 07:59:45 -0700 (PDT) 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: fc6d5dcd-e442-11ed-b224-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1682521186; x=1685113186; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZFE69b1k1YkDEEzbAUbLCBpAHxB5+1bvQjqKSxJf1mg=; b=A6dfKjRU2kBlkF3k6zFQ5CGUQFNd8y5QcBbh4E1VQLKqfFHCtaP8ChsWRfwc00a3T7 RnIrdBc1q78cIMLoMz1XNyvSpwriRrAPcEdHIzEqYBoJtfYC/sAkNP8dKgn+epyUPc/X 1ezy/xnu+4O+S5R9mGElTM3WZ9moeyIBzRJVI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682521186; x=1685113186; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZFE69b1k1YkDEEzbAUbLCBpAHxB5+1bvQjqKSxJf1mg=; b=UE3GT9tHdIyuyCo7n+p0Jl5co81X3HFIrrY5SKQSb+FxzPuw0Gp4KhZzaGW+nbUCt3 9IkQOHc4RZdGka6nmF4CXdMEg+OVbZYhMVfkqpcAINv4fQeC/5svf7A62BdrSFkjcICI Pvg8gUnWPid8IiUSZeiZaxGHZJ7/ZO+0RlPFXgiDsypbMVdxt6ydOzMxk102so/UmRHg 029/rLaHJ8OCzbf0IrsdDCJIQQcZkWPzZ6iDElcdOu5m++5Jb20lCJHqHZ782BaX3AOm GMUZBLlBlpB01s3pefTDv3tyKFgo6vov2qO9/ACqYnRQORCg1hOIwNSKvWczKODbqxdD UnGw== X-Gm-Message-State: AAQBX9dMwZGSEoQLn/Mn9IJTtjYzXQkV8q2GiWsCWKPe7yukd/5SXce7 mwB95lnZoVK76AvU9Ry+1lF61ZmSfBYg3So7lMs= X-Google-Smtp-Source: AKy350b0GzCrgIs6zTHtQ1zyTrOSU4/QlvDF42ZbSeTg4K3j2ayVq3Lyc4fsir19OKXPyfvR0KyeYg== X-Received: by 2002:a5d:4f81:0:b0:2fe:c0ea:18b4 with SMTP id d1-20020a5d4f81000000b002fec0ea18b4mr14994538wru.24.1682521186330; Wed, 26 Apr 2023 07:59:46 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Andrew Cooper , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH 5/7] tools: Modify single-domid callers of xc_domain_getinfolist Date: Wed, 26 Apr 2023 15:59:30 +0100 Message-Id: <20230426145932.3340-6-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230426145932.3340-1-alejandro.vallejo@cloud.com> References: <20230426145932.3340-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1682521239275100001 Content-Type: text/plain; charset="utf-8" xc_domain_getinfolist() internally relies on a sysctl that performs a linear search for the domids. Many callers of xc_domain_getinfolist() who require information about a precise domid are much better off calling xc_domain_getinfo_single() instead, that will use the getdomaininfo domctl instead and ensure the returned domid matches the requested one. The domtctl will find the domid faster too, because that uses hashed lists. Signed-off-by: Alejandro Vallejo --- Cc: Andrew Cooper Cc: Wei Liu Cc: Anthony PERARD Cc: Juergen Gross --- tools/libs/light/libxl_dom.c | 15 +++++---------- tools/libs/light/libxl_dom_suspend.c | 7 +------ tools/libs/light/libxl_domain.c | 12 ++++-------- tools/libs/light/libxl_mem.c | 4 ++-- tools/libs/light/libxl_sched.c | 12 ++++-------- tools/xenpaging/xenpaging.c | 14 +++++++------- 6 files changed, 23 insertions(+), 41 deletions(-) diff --git a/tools/libs/light/libxl_dom.c b/tools/libs/light/libxl_dom.c index 25fb716084..482e04b38c 100644 --- a/tools/libs/light/libxl_dom.c +++ b/tools/libs/light/libxl_dom.c @@ -32,8 +32,8 @@ libxl_domain_type libxl__domain_type(libxl__gc *gc, uint3= 2_t domid) xc_domaininfo_t info; int ret; =20 - ret =3D xc_domain_getinfolist(ctx->xch, domid, 1, &info); - if (ret !=3D 1 || info.domain !=3D domid) { + ret =3D xc_domain_getinfo_single(ctx->xch, domid, &info); + if (ret < 0) { LOG(ERROR, "unable to get domain type for domid=3D%"PRIu32, domid); return LIBXL_DOMAIN_TYPE_INVALID; } @@ -70,15 +70,10 @@ int libxl__domain_cpupool(libxl__gc *gc, uint32_t domid) xc_domaininfo_t info; int ret; =20 - ret =3D xc_domain_getinfolist(CTX->xch, domid, 1, &info); - if (ret !=3D 1) + ret =3D xc_domain_getinfo_single(CTX->xch, domid, &info); + if (ret < 0) { - LOGE(ERROR, "getinfolist failed %d", ret); - return ERROR_FAIL; - } - if (info.domain !=3D domid) - { - LOGE(ERROR, "got info for dom%d, wanted dom%d\n", info.domain, dom= id); + LOGE(ERROR, "getinfo_single failed %d", ret); return ERROR_FAIL; } return info.cpupool; diff --git a/tools/libs/light/libxl_dom_suspend.c b/tools/libs/light/libxl_= dom_suspend.c index 4fa22bb739..6091a5f3f6 100644 --- a/tools/libs/light/libxl_dom_suspend.c +++ b/tools/libs/light/libxl_dom_suspend.c @@ -332,13 +332,8 @@ static void suspend_common_wait_guest_check(libxl__egc= *egc, /* Convenience aliases */ const uint32_t domid =3D dsps->domid; =20 - ret =3D xc_domain_getinfolist(CTX->xch, domid, 1, &info); + ret =3D xc_domain_getinfo_single(CTX->xch, domid, &info); if (ret < 0) { - LOGED(ERROR, domid, "unable to check for status of guest"); - goto err; - } - - if (!(ret =3D=3D 1 && info.domain =3D=3D domid)) { LOGED(ERROR, domid, "guest we were suspending has been destroyed"); goto err; } diff --git a/tools/libs/light/libxl_domain.c b/tools/libs/light/libxl_domai= n.c index 7f0986c185..33ac8e9ce8 100644 --- a/tools/libs/light/libxl_domain.c +++ b/tools/libs/light/libxl_domain.c @@ -349,16 +349,12 @@ int libxl_domain_info(libxl_ctx *ctx, libxl_dominfo *= info_r, int ret; GC_INIT(ctx); =20 - ret =3D xc_domain_getinfolist(ctx->xch, domid, 1, &xcinfo); + ret =3D xc_domain_getinfo_single(ctx->xch, domid, &xcinfo); if (ret<0) { - LOGED(ERROR, domid, "Getting domain info list"); + LOGED(ERROR, domid, "Getting domain info single"); GC_FREE; return ERROR_FAIL; } - if (ret=3D=3D0 || xcinfo.domain !=3D domid) { - GC_FREE; - return ERROR_DOMAIN_NOTFOUND; - } =20 if (info_r) libxl__xcinfo2xlinfo(ctx, &xcinfo, info_r); @@ -1663,8 +1659,8 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint3= 2_t domid, xc_vcpuinfo_t vcpuinfo; unsigned int nr_vcpus; =20 - if (xc_domain_getinfolist(ctx->xch, domid, 1, &domaininfo) !=3D 1) { - LOGED(ERROR, domid, "Getting infolist"); + if (xc_domain_getinfo_single(ctx->xch, domid, &domaininfo) < 0) { + LOGED(ERROR, domid, "Getting info single"); GC_FREE; return NULL; } diff --git a/tools/libs/light/libxl_mem.c b/tools/libs/light/libxl_mem.c index 92ec09f4cf..44e554adba 100644 --- a/tools/libs/light/libxl_mem.c +++ b/tools/libs/light/libxl_mem.c @@ -323,8 +323,8 @@ retry_transaction: libxl__xs_printf(gc, t, GCSPRINTF("%s/memory/target", dompath), "%"PRIu64, new_target_memkb); =20 - r =3D xc_domain_getinfolist(ctx->xch, domid, 1, &info); - if (r !=3D 1 || info.domain !=3D domid) { + r =3D xc_domain_getinfo_single(ctx->xch, domid, &info); + if (r < 0) { abort_transaction =3D 1; rc =3D ERROR_FAIL; goto out; diff --git a/tools/libs/light/libxl_sched.c b/tools/libs/light/libxl_sched.c index 7c53dc60e6..19da7c49ea 100644 --- a/tools/libs/light/libxl_sched.c +++ b/tools/libs/light/libxl_sched.c @@ -219,13 +219,11 @@ static int sched_credit_domain_set(libxl__gc *gc, uin= t32_t domid, xc_domaininfo_t domaininfo; int rc; =20 - rc =3D xc_domain_getinfolist(CTX->xch, domid, 1, &domaininfo); + rc =3D xc_domain_getinfo_single(CTX->xch, domid, &domaininfo); if (rc < 0) { - LOGED(ERROR, domid, "Getting domain info list"); + LOGED(ERROR, domid, "Getting domain info single"); return ERROR_FAIL; } - if (rc !=3D 1 || domaininfo.domain !=3D domid) - return ERROR_INVAL; =20 rc =3D xc_sched_credit_domain_get(CTX->xch, domid, &sdom); if (rc !=3D 0) { @@ -426,13 +424,11 @@ static int sched_credit2_domain_set(libxl__gc *gc, ui= nt32_t domid, xc_domaininfo_t info; int rc; =20 - rc =3D xc_domain_getinfolist(CTX->xch, domid, 1, &info); + rc =3D xc_domain_getinfo_single(CTX->xch, domid, &info); if (rc < 0) { - LOGED(ERROR, domid, "Getting domain info"); + LOGED(ERROR, domid, "Getting domain info single"); return ERROR_FAIL; } - if (rc !=3D 1 || info.domain !=3D domid) - return ERROR_INVAL; =20 rc =3D xc_sched_credit2_domain_get(CTX->xch, domid, &sdom); if (rc !=3D 0) { diff --git a/tools/xenpaging/xenpaging.c b/tools/xenpaging/xenpaging.c index 6e5490315d..023f2bf295 100644 --- a/tools/xenpaging/xenpaging.c +++ b/tools/xenpaging/xenpaging.c @@ -169,10 +169,10 @@ static int xenpaging_get_tot_pages(struct xenpaging *= paging) xc_domaininfo_t domain_info; int rc; =20 - rc =3D xc_domain_getinfolist(xch, paging->vm_event.domain_id, 1, &doma= in_info); - if ( rc !=3D 1 ) + rc =3D xc_domain_getinfo_single(xch, paging->vm_event.domain_id, &doma= in_info); + if ( rc < 0 ) { - PERROR("Error getting domain info"); + PERROR("Error getting domain info single"); return -1; } return domain_info.tot_pages; @@ -424,11 +424,11 @@ static struct xenpaging *xenpaging_init(int argc, cha= r *argv[]) /* Get max_pages from guest if not provided via cmdline */ if ( !paging->max_pages ) { - rc =3D xc_domain_getinfolist(xch, paging->vm_event.domain_id, 1, - &domain_info); - if ( rc !=3D 1 ) + rc =3D xc_domain_getinfo_single(xch, paging->vm_event.domain_id, + &domain_info); + if ( rc < 0 ) { - PERROR("Error getting domain info"); + PERROR("Error getting domain info single"); goto err; } =20 --=20 2.34.1 From nobody Tue May 14 13:30:34 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=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1682521248; cv=none; d=zohomail.com; s=zohoarc; b=MIDE8GHSWtQYD7Bp3ADVQIUKujpny2CZxbrdh+hXCNTBQsTbnrgsKK4Y5HEyvKzGnSXOP3mESmIw1tmjd4ncH6VBONSMwLtlh/JCosMUdNl3g6qbaodhN34ydK08M4HD4w8NdPCkSCe/ZpPhrPQtv6pRMecWNufI/cVHEIuP58M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682521248; h=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=nX+lMTfE0qojwKcJhtm+OU9TM/2tH0AcbR/b2k6dXSw=; b=Dz29It4XffsGHDycCztZIUxe7FQRFCHeyNmO2TuJ37zGa6x/rFq3u/u6XH1w+YJ23UT4la4lP+Sh0a5jY+pjJMHr6H5jZ3Fx+BmcPqKNyUaQfz5IZ4hIS076kDKjw18z+Qql8IxfFyRg7dnIH/iiosKQJbvB1PGekxfyvxpm/AM= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682521248249405.60535672954177; Wed, 26 Apr 2023 08:00:48 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.526753.818737 (Exim 4.92) (envelope-from ) id 1prgcc-0002bB-JY; Wed, 26 Apr 2023 14:59:54 +0000 Received: by outflank-mailman (output) from mailman id 526753.818737; Wed, 26 Apr 2023 14:59:54 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1prgcc-0002aK-Fb; Wed, 26 Apr 2023 14:59:54 +0000 Received: by outflank-mailman (input) for mailman id 526753; Wed, 26 Apr 2023 14:59:53 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1prgca-0000bz-NK for xen-devel@lists.xenproject.org; Wed, 26 Apr 2023 14:59:52 +0000 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [2a00:1450:4864:20::42b]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id fd9d9dd5-e442-11ed-8611-37d641c3527e; Wed, 26 Apr 2023 16:59:49 +0200 (CEST) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-2febac9cacdso4448943f8f.1 for ; Wed, 26 Apr 2023 07:59:49 -0700 (PDT) Received: from localhost.localdomain (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id v17-20020a5d43d1000000b003047ea78b42sm6654116wrr.43.2023.04.26.07.59.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 07:59:47 -0700 (PDT) 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: fd9d9dd5-e442-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1682521188; x=1685113188; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nX+lMTfE0qojwKcJhtm+OU9TM/2tH0AcbR/b2k6dXSw=; b=G2OIXZ0N2SRLY09CjR90cU8xzJOGWDuxhMCVUdyJH6z03ommfu18W92kRT8JE68tHq x+fB0+B7JoQY6eVADvxxuOMRUxleP74V9fyy3ZQGNzBFuovBPLm2IkY8gMcscLcuGQmT r1rTi6eMoWn3ytg/w9DXTVfC33wOPg2I8NDDM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682521188; x=1685113188; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nX+lMTfE0qojwKcJhtm+OU9TM/2tH0AcbR/b2k6dXSw=; b=R8y0x9uZG+5iPQ+Df1NvZUI/M+8/WZxDtEcdM+Bnl7xJtgGutd4eLzHSm7jASsYfD7 ssgYbLPS69f6gA8MWFg0ZW0oHlju7x3U1iGkbx0SD1Nk2hIXrwk0p3KmrXw9n+cf58ie 6y5m5pewsgfj0lp0LFINSOtEs4rtSqOYPwtj3LPnOGu3Ork7fQBluZdK9w1kDeNTiO7+ Mv8fukO+UMVQrV5P4BrW9lDOnlsgBxlfzl1+BJQBlE+RMIDflZHc2h4xCtU6KOeWKSWc GYCHkcZnGWgPAZBAJWLEHcyJgGmeeKpO6oWEx9/sde7ZMsRY+YI4kIqwG7huS/or+AoD E8SQ== X-Gm-Message-State: AAQBX9f3aTz63QnjA0fNECfqwFpZUS10wpGXDC0WlDzON1LswkqDzuHr A1SkvSnscIg33Dtwjs9Z4DfxVdBOfh+vSySR2MI= X-Google-Smtp-Source: AKy350bztpHyxbUb5Yj+C0bVzBq0y7TMScwNOhKdKKzHusqZyllBJn64fdxR/Kies/st+Jdqf4imqg== X-Received: by 2002:a5d:4f05:0:b0:2ef:baa1:f3fc with SMTP id c5-20020a5d4f05000000b002efbaa1f3fcmr13575143wru.19.1682521188086; Wed, 26 Apr 2023 07:59:48 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Andrew Cooper , Wei Liu , Anthony PERARD , Tim Deegan , George Dunlap , Juergen Gross Subject: [PATCH 6/7] tools: Use new xc function for some xc_domain_getinfo calls Date: Wed, 26 Apr 2023 15:59:31 +0100 Message-Id: <20230426145932.3340-7-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230426145932.3340-1-alejandro.vallejo@cloud.com> References: <20230426145932.3340-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1682521250179100001 Content-Type: text/plain; charset="utf-8" Move calls that require a information about a single precisely identified domain to the new xc_domain_getinfo_single(). Signed-off-by: Alejandro Vallejo --- Cc: Andrew Cooper Cc: Wei Liu Cc: Anthony PERARD Cc: Tim Deegan Cc: George Dunlap Cc: Juergen Gross --- tools/console/client/main.c | 7 +++---- tools/debugger/kdd/kdd-xen.c | 6 ++++-- tools/include/xenctrl.h | 7 +++++++ tools/libs/ctrl/xc_domain.c | 5 ++--- tools/libs/ctrl/xc_pagetab.c | 7 +++---- tools/libs/ctrl/xc_private.c | 7 +++---- tools/libs/ctrl/xc_private.h | 6 +++--- tools/libs/guest/xg_core.c | 21 +++++++------------ tools/libs/guest/xg_core.h | 6 +++--- tools/libs/guest/xg_core_arm.c | 10 ++++----- tools/libs/guest/xg_core_x86.c | 18 ++++++++-------- tools/libs/guest/xg_cpuid_x86.c | 28 +++++++++++++------------ tools/libs/guest/xg_dom_boot.c | 12 ++--------- tools/libs/guest/xg_domain.c | 6 +++--- tools/libs/guest/xg_offline_page.c | 10 ++++----- tools/libs/guest/xg_private.h | 1 + tools/libs/guest/xg_resume.c | 17 +++++++-------- tools/libs/guest/xg_sr_common.h | 2 +- tools/libs/guest/xg_sr_restore.c | 14 +++++-------- tools/libs/guest/xg_sr_restore_x86_pv.c | 2 +- tools/libs/guest/xg_sr_save.c | 26 +++++++++-------------- tools/libs/guest/xg_sr_save_x86_pv.c | 6 +++--- tools/libs/light/libxl_sched.c | 16 +++++++------- tools/libs/light/libxl_x86_acpi.c | 4 ++-- tools/misc/xen-hvmcrash.c | 6 +++--- tools/misc/xen-lowmemd.c | 6 +++--- tools/misc/xen-mfndump.c | 22 ++++++++----------- tools/misc/xen-vmtrace.c | 6 +++--- tools/vchan/vchan-socket-proxy.c | 6 +++--- tools/xenstore/xenstored_domain.c | 15 +++++++------ tools/xentrace/xenctx.c | 8 +++---- 31 files changed, 146 insertions(+), 167 deletions(-) diff --git a/tools/console/client/main.c b/tools/console/client/main.c index 1a6fa162f7..6775006488 100644 --- a/tools/console/client/main.c +++ b/tools/console/client/main.c @@ -408,17 +408,16 @@ int main(int argc, char **argv) if (dom_path =3D=3D NULL) err(errno, "xs_get_domain_path()"); if (type =3D=3D CONSOLE_INVAL) { - xc_dominfo_t xcinfo; + xc_domaininfo_t xcinfo; xc_interface *xc_handle =3D xc_interface_open(0,0,0); if (xc_handle =3D=3D NULL) err(errno, "Could not open xc interface"); - if ( (xc_domain_getinfo(xc_handle, domid, 1, &xcinfo) !=3D 1) || - (xcinfo.domid !=3D domid) ) { + if (xc_domain_getinfo_single(xc_handle, domid, &xcinfo) < 0) { xc_interface_close(xc_handle); err(errno, "Failed to get domain information"); } /* default to pv console for pv guests and serial for hvm guests */ - if (xcinfo.hvm) + if (xcinfo.flags & XEN_DOMINF_hvm_guest) type =3D CONSOLE_SERIAL; else type =3D CONSOLE_PV; diff --git a/tools/debugger/kdd/kdd-xen.c b/tools/debugger/kdd/kdd-xen.c index e78c9311c4..b1a96bf4e2 100644 --- a/tools/debugger/kdd/kdd-xen.c +++ b/tools/debugger/kdd/kdd-xen.c @@ -570,7 +570,7 @@ kdd_guest *kdd_guest_init(char *arg, FILE *log, int ver= bosity) kdd_guest *g =3D NULL; xc_interface *xch =3D NULL; uint32_t domid; - xc_dominfo_t info; + xc_domaininfo_t info; =20 g =3D calloc(1, sizeof (kdd_guest)); if (!g)=20 @@ -590,7 +590,9 @@ kdd_guest *kdd_guest_init(char *arg, FILE *log, int ver= bosity) g->domid =3D domid; =20 /* Check that the domain exists and is HVM */ - if (xc_domain_getinfo(xch, domid, 1, &info) !=3D 1 || !info.hvm) + if (xc_domain_getinfo_single(xch, domid, &info) < 0) + goto err; + if (!(info.flags & XEN_DOMINF_hvm_guest)) goto err; =20 snprintf(g->id, (sizeof g->id) - 1,=20 diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 73b07955c6..755759f0fe 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -473,6 +473,13 @@ static inline unsigned int dominfo_shutdown_reason(con= st xc_domaininfo_t *info) return (info->flags >> XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdown= mask; } =20 +static inline bool dominfo_shutdown_with(xc_domaininfo_t *info, unsigned i= nt expected_reason) +{ + /* The reason doesn't make sense unless the domain is actually shutdow= n */ + return (info->flags & XEN_DOMINF_shutdown) && + (dominfo_shutdown_reason(info) =3D=3D expected_reason); +} + typedef union=20 { #if defined(__i386__) || defined(__x86_64__) diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c index 3ff91023bf..5c37dbe200 100644 --- a/tools/libs/ctrl/xc_domain.c +++ b/tools/libs/ctrl/xc_domain.c @@ -1958,12 +1958,11 @@ int xc_domain_memory_mapping( uint32_t add_mapping) { DECLARE_DOMCTL; - xc_dominfo_t info; + xc_domaininfo_t info; int ret =3D 0, rc; unsigned long done =3D 0, nr, max_batch_sz; =20 - if ( xc_domain_getinfo(xch, domid, 1, &info) !=3D 1 || - info.domid !=3D domid ) + if ( xc_domain_getinfo_single(xch, domid, &info) < 0 ) { PERROR("Could not get info for domain"); return -EINVAL; diff --git a/tools/libs/ctrl/xc_pagetab.c b/tools/libs/ctrl/xc_pagetab.c index db25c20247..d9f886633a 100644 --- a/tools/libs/ctrl/xc_pagetab.c +++ b/tools/libs/ctrl/xc_pagetab.c @@ -29,17 +29,16 @@ unsigned long xc_translate_foreign_address(xc_interface *xch, uint32_t dom, int vcpu, unsigned long long vi= rt) { - xc_dominfo_t dominfo; + xc_domaininfo_t dominfo; uint64_t paddr, mask, pte =3D 0; int size, level, pt_levels =3D 2; void *map; =20 - if (xc_domain_getinfo(xch, dom, 1, &dominfo) !=3D 1=20 - || dominfo.domid !=3D dom) + if (xc_domain_getinfo_single(xch, dom, &dominfo) < 0) return 0; =20 /* What kind of paging are we dealing with? */ - if (dominfo.hvm) { + if (dominfo.flags & XEN_DOMINF_hvm_guest) { struct hvm_hw_cpu ctx; if (xc_domain_hvm_getcontext_partial(xch, dom, HVM_SAVE_CODE(CPU), vcpu, diff --git a/tools/libs/ctrl/xc_private.c b/tools/libs/ctrl/xc_private.c index 2f99a7d2cf..8dcebad401 100644 --- a/tools/libs/ctrl/xc_private.c +++ b/tools/libs/ctrl/xc_private.c @@ -441,11 +441,10 @@ int xc_machphys_mfn_list(xc_interface *xch, =20 long xc_get_tot_pages(xc_interface *xch, uint32_t domid) { - xc_dominfo_t info; - if ( (xc_domain_getinfo(xch, domid, 1, &info) !=3D 1) || - (info.domid !=3D domid) ) + xc_domaininfo_t info; + if ( xc_domain_getinfo_single(xch, domid, &info) < 0 ) return -1; - return info.nr_pages; + return info.tot_pages; } =20 int xc_copy_to_domain_page(xc_interface *xch, diff --git a/tools/libs/ctrl/xc_private.h b/tools/libs/ctrl/xc_private.h index 80dc464c93..abd557e861 100644 --- a/tools/libs/ctrl/xc_private.h +++ b/tools/libs/ctrl/xc_private.h @@ -420,12 +420,12 @@ void *xc_vm_event_enable(xc_interface *xch, uint32_t = domain_id, int param, int do_dm_op(xc_interface *xch, uint32_t domid, unsigned int nr_bufs, ...); =20 #if defined (__i386__) || defined (__x86_64__) -static inline int xc_core_arch_auto_translated_physmap(const xc_dominfo_t = *info) +static inline int xc_core_arch_auto_translated_physmap(const xc_domaininfo= _t *info) { - return info->hvm; + return info->flags & XEN_DOMINF_hvm_guest; } #elif defined (__arm__) || defined(__aarch64__) -static inline int xc_core_arch_auto_translated_physmap(const xc_dominfo_t = *info) +static inline int xc_core_arch_auto_translated_physmap(const xc_domaininfo= _t *info) { return 1; } diff --git a/tools/libs/guest/xg_core.c b/tools/libs/guest/xg_core.c index c52f1161c1..33d35715c9 100644 --- a/tools/libs/guest/xg_core.c +++ b/tools/libs/guest/xg_core.c @@ -349,7 +349,7 @@ elfnote_dump_none(xc_interface *xch, void *args, dumpco= re_rtn_t dump_rtn) static int elfnote_dump_core_header( xc_interface *xch, - void *args, dumpcore_rtn_t dump_rtn, const xc_dominfo_t *info, + void *args, dumpcore_rtn_t dump_rtn, const xc_domaininfo_t *info, int nr_vcpus, unsigned long nr_pages) { int sts; @@ -361,7 +361,8 @@ elfnote_dump_core_header( =20 elfnote.descsz =3D sizeof(header); elfnote.type =3D XEN_ELFNOTE_DUMPCORE_HEADER; - header.xch_magic =3D info->hvm ? XC_CORE_MAGIC_HVM : XC_CORE_MAGIC; + header.xch_magic =3D (info->flags & XEN_DOMINF_hvm_guest) ? XC_CORE_MA= GIC_HVM + : XC_CORE_MAGI= C; header.xch_nr_vcpus =3D nr_vcpus; header.xch_nr_pages =3D nr_pages; header.xch_page_size =3D PAGE_SIZE; @@ -423,7 +424,7 @@ xc_domain_dumpcore_via_callback(xc_interface *xch, void *args, dumpcore_rtn_t dump_rtn) { - xc_dominfo_t info; + xc_domaininfo_t info; shared_info_any_t *live_shinfo =3D NULL; struct domain_info_context _dinfo =3D {}; struct domain_info_context *dinfo =3D &_dinfo; @@ -468,7 +469,7 @@ xc_domain_dumpcore_via_callback(xc_interface *xch, goto out; } =20 - if ( xc_domain_getinfo(xch, domid, 1, &info) !=3D 1 ) + if ( xc_domain_getinfo_single(xch, domid, &info) < 0 ) { PERROR("Could not get info for domain"); goto out; @@ -476,7 +477,7 @@ xc_domain_dumpcore_via_callback(xc_interface *xch, /* Map the shared info frame */ live_shinfo =3D xc_map_foreign_range(xch, domid, PAGE_SIZE, PROT_READ, info.shared_info_frame); - if ( !live_shinfo && !info.hvm ) + if ( !live_shinfo && !(info.flags & XEN_DOMINF_hvm_guest) ) { PERROR("Couldn't map live_shinfo"); goto out; @@ -517,12 +518,6 @@ xc_domain_dumpcore_via_callback(xc_interface *xch, dinfo->guest_width =3D sizeof(unsigned long); } =20 - if ( domid !=3D info.domid ) - { - PERROR("Domain %d does not exist", domid); - goto out; - } - ctxt =3D calloc(sizeof(*ctxt), info.max_vcpu_id + 1); if ( !ctxt ) { @@ -560,9 +555,9 @@ xc_domain_dumpcore_via_callback(xc_interface *xch, * all the array... * * We don't want to use the total potential size of the memory map - * since that is usually much higher than info.nr_pages. + * since that is usually much higher than info.tot_pages. */ - nr_pages =3D info.nr_pages; + nr_pages =3D info.tot_pages; =20 if ( !auto_translated_physmap ) { diff --git a/tools/libs/guest/xg_core.h b/tools/libs/guest/xg_core.h index aaca9e0a8b..ff577dad31 100644 --- a/tools/libs/guest/xg_core.h +++ b/tools/libs/guest/xg_core.h @@ -134,15 +134,15 @@ typedef struct xc_core_memory_map xc_core_memory_map_= t; struct xc_core_arch_context; int xc_core_arch_memory_map_get(xc_interface *xch, struct xc_core_arch_context *arch_ctxt, - xc_dominfo_t *info, shared_info_any_t *liv= e_shinfo, + xc_domaininfo_t *info, shared_info_any_t *= live_shinfo, xc_core_memory_map_t **mapp, unsigned int *nr_entries); int xc_core_arch_map_p2m(xc_interface *xch, struct domain_info_context *di= nfo, - xc_dominfo_t *info, shared_info_any_t *live_shinf= o, + xc_domaininfo_t *info, shared_info_any_t *live_sh= info, xen_pfn_t **live_p2m); =20 int xc_core_arch_map_p2m_writable(xc_interface *xch, struct domain_info_co= ntext *dinfo, - xc_dominfo_t *info, + xc_domaininfo_t *info, shared_info_any_t *live_shinfo, xen_pfn_t **live_p2m); =20 diff --git a/tools/libs/guest/xg_core_arm.c b/tools/libs/guest/xg_core_arm.c index de30cf0c31..34276152da 100644 --- a/tools/libs/guest/xg_core_arm.c +++ b/tools/libs/guest/xg_core_arm.c @@ -33,14 +33,14 @@ xc_core_arch_gpfn_may_present(struct xc_core_arch_conte= xt *arch_ctxt, =20 int xc_core_arch_memory_map_get(xc_interface *xch, struct xc_core_arch_context= *unused, - xc_dominfo_t *info, shared_info_any_t *live_sh= info, + xc_domaininfo_t *info, shared_info_any_t *live= _shinfo, xc_core_memory_map_t **mapp, unsigned int *nr_entries) { xen_pfn_t p2m_size =3D 0; xc_core_memory_map_t *map; =20 - if ( xc_domain_nr_gpfns(xch, info->domid, &p2m_size) < 0 ) + if ( xc_domain_nr_gpfns(xch, info->domain, &p2m_size) < 0 ) return -1; =20 map =3D malloc(sizeof(*map)); @@ -59,7 +59,7 @@ xc_core_arch_memory_map_get(xc_interface *xch, struct xc_= core_arch_context *unus } =20 static int -xc_core_arch_map_p2m_rw(xc_interface *xch, struct domain_info_context *din= fo, xc_dominfo_t *info, +xc_core_arch_map_p2m_rw(xc_interface *xch, struct domain_info_context *din= fo, xc_domaininfo_t *info, shared_info_any_t *live_shinfo, xen_pfn_t **live_p= 2m, int rw) { errno =3D ENOSYS; @@ -67,14 +67,14 @@ xc_core_arch_map_p2m_rw(xc_interface *xch, struct domai= n_info_context *dinfo, xc } =20 int -xc_core_arch_map_p2m(xc_interface *xch, struct domain_info_context *dinfo,= xc_dominfo_t *info, +xc_core_arch_map_p2m(xc_interface *xch, struct domain_info_context *dinfo,= xc_domaininfo_t *info, shared_info_any_t *live_shinfo, xen_pfn_t **live_p= 2m) { return xc_core_arch_map_p2m_rw(xch, dinfo, info, live_shinfo, live_p2m= , 0); } =20 int -xc_core_arch_map_p2m_writable(xc_interface *xch, struct domain_info_contex= t *dinfo, xc_dominfo_t *info, +xc_core_arch_map_p2m_writable(xc_interface *xch, struct domain_info_contex= t *dinfo, xc_domaininfo_t *info, shared_info_any_t *live_shinfo, xen_pfn_t **= live_p2m) { return xc_core_arch_map_p2m_rw(xch, dinfo, info, live_shinfo, live_p2m= , 1); diff --git a/tools/libs/guest/xg_core_x86.c b/tools/libs/guest/xg_core_x86.c index c5e4542ccc..dbd3a440f7 100644 --- a/tools/libs/guest/xg_core_x86.c +++ b/tools/libs/guest/xg_core_x86.c @@ -49,14 +49,14 @@ xc_core_arch_gpfn_may_present(struct xc_core_arch_conte= xt *arch_ctxt, =20 int xc_core_arch_memory_map_get(xc_interface *xch, struct xc_core_arch_context= *unused, - xc_dominfo_t *info, shared_info_any_t *live_sh= info, + xc_domaininfo_t *info, shared_info_any_t *live= _shinfo, xc_core_memory_map_t **mapp, unsigned int *nr_entries) { xen_pfn_t p2m_size =3D 0; xc_core_memory_map_t *map; =20 - if ( xc_domain_nr_gpfns(xch, info->domid, &p2m_size) < 0 ) + if ( xc_domain_nr_gpfns(xch, info->domain, &p2m_size) < 0 ) return -1; =20 map =3D malloc(sizeof(*map)); @@ -314,24 +314,24 @@ xc_core_arch_map_p2m_tree_rw(xc_interface *xch, struc= t domain_info_context *dinf } =20 static int -xc_core_arch_map_p2m_rw(xc_interface *xch, struct domain_info_context *din= fo, xc_dominfo_t *info, +xc_core_arch_map_p2m_rw(xc_interface *xch, struct domain_info_context *din= fo, xc_domaininfo_t *info, shared_info_any_t *live_shinfo, xen_pfn_t **live_p= 2m, int rw) { xen_pfn_t *p2m_frame_list =3D NULL; uint64_t p2m_cr3; - uint32_t dom =3D info->domid; + uint32_t dom =3D info->domain; int ret =3D -1; int err; =20 - if ( xc_domain_nr_gpfns(xch, info->domid, &dinfo->p2m_size) < 0 ) + if ( xc_domain_nr_gpfns(xch, info->domain, &dinfo->p2m_size) < 0 ) { ERROR("Could not get maximum GPFN!"); goto out; } =20 - if ( dinfo->p2m_size < info->nr_pages ) + if ( dinfo->p2m_size < info->tot_pages ) { - ERROR("p2m_size < nr_pages -1 (%lx < %lx", dinfo->p2m_size, info->= nr_pages - 1); + ERROR("p2m_size < nr_pages -1 (%lx < %"PRIx64, dinfo->p2m_size, in= fo->tot_pages - 1); goto out; } =20 @@ -366,14 +366,14 @@ out: } =20 int -xc_core_arch_map_p2m(xc_interface *xch, struct domain_info_context *dinfo,= xc_dominfo_t *info, +xc_core_arch_map_p2m(xc_interface *xch, struct domain_info_context *dinfo,= xc_domaininfo_t *info, shared_info_any_t *live_shinfo, xen_pfn_t **live_p= 2m) { return xc_core_arch_map_p2m_rw(xch, dinfo, info, live_shinfo, live_p2m= , 0); } =20 int -xc_core_arch_map_p2m_writable(xc_interface *xch, struct domain_info_contex= t *dinfo, xc_dominfo_t *info, +xc_core_arch_map_p2m_writable(xc_interface *xch, struct domain_info_contex= t *dinfo, xc_domaininfo_t *info, shared_info_any_t *live_shinfo, xen_pfn_t **= live_p2m) { return xc_core_arch_map_p2m_rw(xch, dinfo, info, live_shinfo, live_p2m= , 1); diff --git a/tools/libs/guest/xg_cpuid_x86.c b/tools/libs/guest/xg_cpuid_x8= 6.c index bd16a87e48..6d260d2cff 100644 --- a/tools/libs/guest/xg_cpuid_x86.c +++ b/tools/libs/guest/xg_cpuid_x86.c @@ -281,7 +281,8 @@ static int xc_cpuid_xend_policy( xc_interface *xch, uint32_t domid, const struct xc_xend_cpuid *xend) { int rc; - xc_dominfo_t di; + bool is_hvm; + xc_domaininfo_t di; unsigned int nr_leaves, nr_msrs; uint32_t err_leaf =3D -1, err_subleaf =3D -1, err_msr =3D -1; /* @@ -291,13 +292,13 @@ static int xc_cpuid_xend_policy( xen_cpuid_leaf_t *host =3D NULL, *def =3D NULL, *cur =3D NULL; unsigned int nr_host, nr_def, nr_cur; =20 - if ( xc_domain_getinfo(xch, domid, 1, &di) !=3D 1 || - di.domid !=3D domid ) + if ( xc_domain_getinfo_single(xch, domid, &di) < 0 ) { ERROR("Failed to obtain d%d info", domid); rc =3D -ESRCH; goto fail; } + is_hvm =3D di.flags & XEN_DOMINF_hvm_guest; =20 rc =3D xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs); if ( rc ) @@ -330,12 +331,12 @@ static int xc_cpuid_xend_policy( /* Get the domain type's default policy. */ nr_msrs =3D 0; nr_def =3D nr_leaves; - rc =3D get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_d= efault + rc =3D get_system_cpu_policy(xch, is_hvm ? XEN_SYSCTL_cpu_policy_hvm_d= efault : XEN_SYSCTL_cpu_policy_pv_defa= ult, &nr_def, def, &nr_msrs, NULL); if ( rc ) { - PERROR("Failed to obtain %s def policy", di.hvm ? "hvm" : "pv"); + PERROR("Failed to obtain %s def policy", is_hvm ? "hvm" : "pv"); rc =3D -errno; goto fail; } @@ -428,7 +429,8 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t d= omid, bool restore, const struct xc_xend_cpuid *xend) { int rc; - xc_dominfo_t di; + bool is_hvm; + xc_domaininfo_t di; unsigned int i, nr_leaves, nr_msrs; xen_cpuid_leaf_t *leaves =3D NULL; struct cpu_policy *p =3D NULL; @@ -436,13 +438,13 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t= domid, bool restore, uint32_t host_featureset[FEATURESET_NR_ENTRIES] =3D {}; uint32_t len =3D ARRAY_SIZE(host_featureset); =20 - if ( xc_domain_getinfo(xch, domid, 1, &di) !=3D 1 || - di.domid !=3D domid ) + if ( xc_domain_getinfo_single(xch, domid, &di) < 0 ) { ERROR("Failed to obtain d%d info", domid); rc =3D -ESRCH; goto out; } + is_hvm =3D di.flags & XEN_DOMINF_hvm_guest; =20 rc =3D xc_cpu_policy_get_size(xch, &nr_leaves, &nr_msrs); if ( rc ) @@ -475,12 +477,12 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t= domid, bool restore, =20 /* Get the domain's default policy. */ nr_msrs =3D 0; - rc =3D get_system_cpu_policy(xch, di.hvm ? XEN_SYSCTL_cpu_policy_hvm_d= efault + rc =3D get_system_cpu_policy(xch, is_hvm ? XEN_SYSCTL_cpu_policy_hvm_d= efault : XEN_SYSCTL_cpu_policy_pv_defa= ult, &nr_leaves, leaves, &nr_msrs, NULL); if ( rc ) { - PERROR("Failed to obtain %s default policy", di.hvm ? "hvm" : "pv"= ); + PERROR("Failed to obtain %s default policy", is_hvm ? "hvm" : "pv"= ); rc =3D -errno; goto out; } @@ -514,7 +516,7 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t d= omid, bool restore, p->feat.hle =3D test_bit(X86_FEATURE_HLE, host_featureset); p->feat.rtm =3D test_bit(X86_FEATURE_RTM, host_featureset); =20 - if ( di.hvm ) + if ( is_hvm ) { p->feat.mpx =3D test_bit(X86_FEATURE_MPX, host_featureset); } @@ -571,7 +573,7 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t d= omid, bool restore, { p->extd.itsc =3D itsc; =20 - if ( di.hvm ) + if ( is_hvm ) { p->basic.pae =3D pae; p->basic.vmx =3D nested_virt; @@ -579,7 +581,7 @@ int xc_cpuid_apply_policy(xc_interface *xch, uint32_t d= omid, bool restore, } } =20 - if ( !di.hvm ) + if ( !is_hvm ) { /* * On hardware without CPUID Faulting, PV guests see real topology. diff --git a/tools/libs/guest/xg_dom_boot.c b/tools/libs/guest/xg_dom_boot.c index 263a3f4c85..59b4d641c9 100644 --- a/tools/libs/guest/xg_dom_boot.c +++ b/tools/libs/guest/xg_dom_boot.c @@ -164,7 +164,7 @@ void *xc_dom_boot_domU_map(struct xc_dom_image *dom, xe= n_pfn_t pfn, =20 int xc_dom_boot_image(struct xc_dom_image *dom) { - xc_dominfo_t info; + xc_domaininfo_t info; int rc; =20 DOMPRINTF_CALLED(dom->xch); @@ -174,21 +174,13 @@ int xc_dom_boot_image(struct xc_dom_image *dom) return rc; =20 /* collect some info */ - rc =3D xc_domain_getinfo(dom->xch, dom->guest_domid, 1, &info); + rc =3D xc_domain_getinfo_single(dom->xch, dom->guest_domid, &info); if ( rc < 0 ) { xc_dom_panic(dom->xch, XC_INTERNAL_ERROR, "%s: getdomaininfo failed (rc=3D%d)", __FUNCTION__, r= c); return rc; } - if ( rc =3D=3D 0 || info.domid !=3D dom->guest_domid ) - { - xc_dom_panic(dom->xch, XC_INTERNAL_ERROR, - "%s: Huh? No domains found (nr_domains=3D%d) " - "or domid mismatch (%d !=3D %d)", __FUNCTION__, - rc, info.domid, dom->guest_domid); - return -1; - } dom->shared_info_mfn =3D info.shared_info_frame; =20 /* initial mm setup */ diff --git a/tools/libs/guest/xg_domain.c b/tools/libs/guest/xg_domain.c index f0e7748449..49e532ee33 100644 --- a/tools/libs/guest/xg_domain.c +++ b/tools/libs/guest/xg_domain.c @@ -37,7 +37,7 @@ int xc_map_domain_meminfo(xc_interface *xch, uint32_t dom= id, { struct domain_info_context _di; =20 - xc_dominfo_t info; + xc_domaininfo_t info; shared_info_any_t *live_shinfo; xen_capabilities_info_t xen_caps =3D ""; unsigned long i; @@ -49,7 +49,7 @@ int xc_map_domain_meminfo(xc_interface *xch, uint32_t dom= id, return -1; } =20 - if ( xc_domain_getinfo(xch, domid, 1, &info) !=3D 1 ) + if ( xc_domain_getinfo_single(xch, domid, &info) < 0 ) { PERROR("Could not get domain info"); return -1; @@ -86,7 +86,7 @@ int xc_map_domain_meminfo(xc_interface *xch, uint32_t dom= id, info.shared_info_frame); if ( !live_shinfo ) { - PERROR("Could not map the shared info frame (MFN 0x%lx)", + PERROR("Could not map the shared info frame (MFN 0x%"PRIx64")", info.shared_info_frame); return -1; } diff --git a/tools/libs/guest/xg_offline_page.c b/tools/libs/guest/xg_offli= ne_page.c index ccd0299f0f..0ca9ca32ef 100644 --- a/tools/libs/guest/xg_offline_page.c +++ b/tools/libs/guest/xg_offline_page.c @@ -370,7 +370,7 @@ static int clear_pte(xc_interface *xch, uint32_t domid, */ =20 static int is_page_exchangable(xc_interface *xch, uint32_t domid, xen_pfn_= t mfn, - xc_dominfo_t *info) + xc_domaininfo_t *info) { uint32_t status; int rc; @@ -381,7 +381,7 @@ static int is_page_exchangable(xc_interface *xch, uint3= 2_t domid, xen_pfn_t mfn, DPRINTF("Dom0's page can't be LM"); return 0; } - if (info->hvm) + if (info->flags & XEN_DOMINF_hvm_guest) { DPRINTF("Currently we can only live change PV guest's page\n"); return 0; @@ -462,7 +462,7 @@ err0: /* The domain should be suspended when called here */ int xc_exchange_page(xc_interface *xch, uint32_t domid, xen_pfn_t mfn) { - xc_dominfo_t info; + xc_domaininfo_t info; struct xc_domain_meminfo minfo; struct xc_mmu *mmu =3D NULL; struct pte_backup old_ptes =3D {NULL, 0, 0}; @@ -477,13 +477,13 @@ int xc_exchange_page(xc_interface *xch, uint32_t domi= d, xen_pfn_t mfn) xen_pfn_t *m2p_table; unsigned long max_mfn; =20 - if ( xc_domain_getinfo(xch, domid, 1, &info) !=3D 1 ) + if ( xc_domain_getinfo_single(xch, domid, &info) < 0 ) { ERROR("Could not get domain info"); return -1; } =20 - if (!info.shutdown || info.shutdown_reason !=3D SHUTDOWN_suspend) + if (!dominfo_shutdown_with(&info, SHUTDOWN_suspend)) { errno =3D EINVAL; ERROR("Can't exchange page unless domain is suspended\n"); diff --git a/tools/libs/guest/xg_private.h b/tools/libs/guest/xg_private.h index e729a8106c..d73947094f 100644 --- a/tools/libs/guest/xg_private.h +++ b/tools/libs/guest/xg_private.h @@ -16,6 +16,7 @@ #ifndef XG_PRIVATE_H #define XG_PRIVATE_H =20 +#include #include #include #include diff --git a/tools/libs/guest/xg_resume.c b/tools/libs/guest/xg_resume.c index 77e2451a3c..60d682c746 100644 --- a/tools/libs/guest/xg_resume.c +++ b/tools/libs/guest/xg_resume.c @@ -26,28 +26,27 @@ static int modify_returncode(xc_interface *xch, uint32_t domid) { vcpu_guest_context_any_t ctxt; - xc_dominfo_t info; + xc_domaininfo_t info; xen_capabilities_info_t caps; struct domain_info_context _dinfo =3D {}; struct domain_info_context *dinfo =3D &_dinfo; int rc; =20 - if ( xc_domain_getinfo(xch, domid, 1, &info) !=3D 1 || - info.domid !=3D domid ) + if ( xc_domain_getinfo_single(xch, domid, &info) < 0 ) { PERROR("Could not get domain info"); return -1; } =20 - if ( !info.shutdown || (info.shutdown_reason !=3D SHUTDOWN_suspend) ) + if ( !dominfo_shutdown_with(&info, SHUTDOWN_suspend)) { ERROR("Dom %d not suspended: (shutdown %d, reason %d)", domid, - info.shutdown, info.shutdown_reason); + info.flags & XEN_DOMINF_shutdown, dominfo_shutdown_reason(&i= nfo)); errno =3D EINVAL; return -1; } =20 - if ( info.hvm ) + if ( info.flags & XEN_DOMINF_hvm_guest ) { /* HVM guests without PV drivers have no return code to modify. */ uint64_t irq =3D 0; @@ -133,7 +132,7 @@ static int xc_domain_resume_hvm(xc_interface *xch, uint= 32_t domid) static int xc_domain_resume_any(xc_interface *xch, uint32_t domid) { DECLARE_DOMCTL; - xc_dominfo_t info; + xc_domaininfo_t info; int i, rc =3D -1; #if defined(__i386__) || defined(__x86_64__) struct domain_info_context _dinfo =3D { .guest_width =3D 0, @@ -146,7 +145,7 @@ static int xc_domain_resume_any(xc_interface *xch, uint= 32_t domid) xen_pfn_t *p2m =3D NULL; #endif =20 - if ( xc_domain_getinfo(xch, domid, 1, &info) !=3D 1 ) + if ( xc_domain_getinfo_single(xch, domid, &info) < 0 ) { PERROR("Could not get domain info"); return rc; @@ -156,7 +155,7 @@ static int xc_domain_resume_any(xc_interface *xch, uint= 32_t domid) * (x86 only) Rewrite store_mfn and console_mfn back to MFN (from PFN). */ #if defined(__i386__) || defined(__x86_64__) - if ( info.hvm ) + if ( info.flags & XEN_DOMINF_hvm_guest ) return xc_domain_resume_hvm(xch, domid); =20 if ( xc_domain_get_guest_width(xch, domid, &dinfo->guest_width) !=3D 0= ) diff --git a/tools/libs/guest/xg_sr_common.h b/tools/libs/guest/xg_sr_commo= n.h index 36d45ef56f..2f058ee3a6 100644 --- a/tools/libs/guest/xg_sr_common.h +++ b/tools/libs/guest/xg_sr_common.h @@ -220,7 +220,7 @@ struct xc_sr_context /* Plain VM, or checkpoints over time. */ xc_stream_type_t stream_type; =20 - xc_dominfo_t dominfo; + xc_domaininfo_t dominfo; =20 union /* Common save or restore data. */ { diff --git a/tools/libs/guest/xg_sr_restore.c b/tools/libs/guest/xg_sr_rest= ore.c index 7314a24cf9..a03183f4b9 100644 --- a/tools/libs/guest/xg_sr_restore.c +++ b/tools/libs/guest/xg_sr_restore.c @@ -852,6 +852,7 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uin= t32_t dom, xc_stream_type_t stream_type, struct restore_callbacks *callbacks, int send_back_f= d) { + bool is_hvm; xen_pfn_t nr_pfns; struct xc_sr_context ctx =3D { .xch =3D xch, @@ -887,20 +888,15 @@ int xc_domain_restore(xc_interface *xch, int io_fd, u= int32_t dom, break; } =20 - if ( xc_domain_getinfo(xch, dom, 1, &ctx.dominfo) !=3D 1 ) + if ( xc_domain_getinfo_single(xch, dom, &ctx.dominfo) < 0 ) { PERROR("Failed to get domain info"); return -1; } =20 - if ( ctx.dominfo.domid !=3D dom ) - { - ERROR("Domain %u does not exist", dom); - return -1; - } - + is_hvm =3D !!(ctx.dominfo.flags & XEN_DOMINF_hvm_guest); DPRINTF("fd %d, dom %u, hvm %u, stream_type %d", - io_fd, dom, ctx.dominfo.hvm, stream_type); + io_fd, dom, is_hvm, stream_type); =20 ctx.domid =3D dom; =20 @@ -914,7 +910,7 @@ int xc_domain_restore(xc_interface *xch, int io_fd, uin= t32_t dom, } =20 ctx.restore.p2m_size =3D nr_pfns; - ctx.restore.ops =3D ctx.dominfo.hvm + ctx.restore.ops =3D is_hvm ? restore_ops_x86_hvm : restore_ops_x86_pv; =20 if ( restore(&ctx) ) diff --git a/tools/libs/guest/xg_sr_restore_x86_pv.c b/tools/libs/guest/xg_= sr_restore_x86_pv.c index dc50b0f5a8..eaeb97f4a0 100644 --- a/tools/libs/guest/xg_sr_restore_x86_pv.c +++ b/tools/libs/guest/xg_sr_restore_x86_pv.c @@ -903,7 +903,7 @@ static int handle_shared_info(struct xc_sr_context *ctx, ctx->dominfo.shared_info_frame); if ( !guest_shinfo ) { - PERROR("Failed to map Shared Info at mfn %#lx", + PERROR("Failed to map Shared Info at mfn %#"PRIx64, ctx->dominfo.shared_info_frame); goto err; } diff --git a/tools/libs/guest/xg_sr_save.c b/tools/libs/guest/xg_sr_save.c index 9853d8d846..8fc8e9d3b2 100644 --- a/tools/libs/guest/xg_sr_save.c +++ b/tools/libs/guest/xg_sr_save.c @@ -336,19 +336,17 @@ static int suspend_domain(struct xc_sr_context *ctx) } =20 /* Refresh domain information. */ - if ( (xc_domain_getinfo(xch, ctx->domid, 1, &ctx->dominfo) !=3D 1) || - (ctx->dominfo.domid !=3D ctx->domid) ) + if ( xc_domain_getinfo_single(xch, ctx->domid, &ctx->dominfo) < 0 ) { PERROR("Unable to refresh domain information"); return -1; } =20 /* Confirm the domain has actually been paused. */ - if ( !ctx->dominfo.shutdown || - (ctx->dominfo.shutdown_reason !=3D SHUTDOWN_suspend) ) + if ( !dominfo_shutdown_with(&ctx->dominfo, SHUTDOWN_suspend) ) { ERROR("Domain has not been suspended: shutdown %d, reason %d", - ctx->dominfo.shutdown, ctx->dominfo.shutdown_reason); + ctx->dominfo.flags & XEN_DOMINF_shutdown, dominfo_shutdown_r= eason(&ctx->dominfo)); return -1; } =20 @@ -893,8 +891,7 @@ static int save(struct xc_sr_context *ctx, uint16_t gue= st_type) if ( rc ) goto err; =20 - if ( !ctx->dominfo.shutdown || - (ctx->dominfo.shutdown_reason !=3D SHUTDOWN_suspend) ) + if ( !dominfo_shutdown_with(&ctx->dominfo, SHUTDOWN_suspend) ) { ERROR("Domain has not been suspended"); rc =3D -1; @@ -989,6 +986,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint32= _t dom, .fd =3D io_fd, .stream_type =3D stream_type, }; + bool is_hvm; =20 /* GCC 4.4 (of CentOS 6.x vintage) can' t initialise anonymous unions.= */ ctx.save.callbacks =3D callbacks; @@ -996,17 +994,13 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint= 32_t dom, ctx.save.debug =3D !!(flags & XCFLAGS_DEBUG); ctx.save.recv_fd =3D recv_fd; =20 - if ( xc_domain_getinfo(xch, dom, 1, &ctx.dominfo) !=3D 1 ) + if ( xc_domain_getinfo_single(xch, dom, &ctx.dominfo) < 0 ) { PERROR("Failed to get domain info"); return -1; } =20 - if ( ctx.dominfo.domid !=3D dom ) - { - ERROR("Domain %u does not exist", dom); - return -1; - } + is_hvm =3D !!(ctx.dominfo.flags & XEN_DOMINF_hvm_guest); =20 /* Sanity check stream_type-related parameters */ switch ( stream_type ) @@ -1018,7 +1012,7 @@ int xc_domain_save(xc_interface *xch, int io_fd, uint= 32_t dom, assert(callbacks->checkpoint && callbacks->postcopy); /* Fallthrough */ case XC_STREAM_PLAIN: - if ( ctx.dominfo.hvm ) + if ( is_hvm ) assert(callbacks->switch_qemu_logdirty); break; =20 @@ -1028,11 +1022,11 @@ int xc_domain_save(xc_interface *xch, int io_fd, ui= nt32_t dom, } =20 DPRINTF("fd %d, dom %u, flags %u, hvm %d", - io_fd, dom, flags, ctx.dominfo.hvm); + io_fd, dom, flags, is_hvm); =20 ctx.domid =3D dom; =20 - if ( ctx.dominfo.hvm ) + if ( is_hvm ) { ctx.save.ops =3D save_ops_x86_hvm; return save(&ctx, DHDR_TYPE_X86_HVM); diff --git a/tools/libs/guest/xg_sr_save_x86_pv.c b/tools/libs/guest/xg_sr_= save_x86_pv.c index 4964f1f7b8..f3d7a7a71a 100644 --- a/tools/libs/guest/xg_sr_save_x86_pv.c +++ b/tools/libs/guest/xg_sr_save_x86_pv.c @@ -20,7 +20,7 @@ static int map_shinfo(struct xc_sr_context *ctx) xch, ctx->domid, PAGE_SIZE, PROT_READ, ctx->dominfo.shared_info_fr= ame); if ( !ctx->x86.pv.shinfo ) { - PERROR("Failed to map shared info frame at mfn %#lx", + PERROR("Failed to map shared info frame at mfn %#"PRIx64, ctx->dominfo.shared_info_frame); return -1; } @@ -943,7 +943,7 @@ static int normalise_pagetable(struct xc_sr_context *ct= x, const uint64_t *src, #ifdef __i386__ if ( mfn =3D=3D INVALID_MFN ) { - if ( !ctx->dominfo.paused ) + if ( !(ctx->dominfo.flags & XEN_DOMINF_paused) ) errno =3D EAGAIN; else { @@ -965,7 +965,7 @@ static int normalise_pagetable(struct xc_sr_context *ct= x, const uint64_t *src, =20 if ( !mfn_in_pseudophysmap(ctx, mfn) ) { - if ( !ctx->dominfo.paused ) + if ( !(ctx->dominfo.flags & XEN_DOMINF_paused) ) errno =3D EAGAIN; else { diff --git a/tools/libs/light/libxl_sched.c b/tools/libs/light/libxl_sched.c index 19da7c49ea..ad81f15a97 100644 --- a/tools/libs/light/libxl_sched.c +++ b/tools/libs/light/libxl_sched.c @@ -498,10 +498,10 @@ static int sched_rtds_vcpu_get(libxl__gc *gc, uint32_= t domid, { uint32_t num_vcpus; int i, r, rc; - xc_dominfo_t info; + xc_domaininfo_t info; struct xen_domctl_schedparam_vcpu *vcpus; =20 - r =3D xc_domain_getinfo(CTX->xch, domid, 1, &info); + r =3D xc_domain_getinfo_single(CTX->xch, domid, &info); if (r < 0) { LOGED(ERROR, domid, "Getting domain info"); rc =3D ERROR_FAIL; @@ -552,10 +552,10 @@ static int sched_rtds_vcpu_get_all(libxl__gc *gc, uin= t32_t domid, { uint32_t num_vcpus; int i, r, rc; - xc_dominfo_t info; + xc_domaininfo_t info; struct xen_domctl_schedparam_vcpu *vcpus; =20 - r =3D xc_domain_getinfo(CTX->xch, domid, 1, &info); + r =3D xc_domain_getinfo_single(CTX->xch, domid, &info); if (r < 0) { LOGED(ERROR, domid, "Getting domain info"); rc =3D ERROR_FAIL; @@ -602,10 +602,10 @@ static int sched_rtds_vcpu_set(libxl__gc *gc, uint32_= t domid, int r, rc; int i; uint16_t max_vcpuid; - xc_dominfo_t info; + xc_domaininfo_t info; struct xen_domctl_schedparam_vcpu *vcpus; =20 - r =3D xc_domain_getinfo(CTX->xch, domid, 1, &info); + r =3D xc_domain_getinfo_single(CTX->xch, domid, &info); if (r < 0) { LOGED(ERROR, domid, "Getting domain info"); rc =3D ERROR_FAIL; @@ -662,11 +662,11 @@ static int sched_rtds_vcpu_set_all(libxl__gc *gc, uin= t32_t domid, int r, rc; int i; uint16_t max_vcpuid; - xc_dominfo_t info; + xc_domaininfo_t info; struct xen_domctl_schedparam_vcpu *vcpus; uint32_t num_vcpus; =20 - r =3D xc_domain_getinfo(CTX->xch, domid, 1, &info); + r =3D xc_domain_getinfo_single(CTX->xch, domid, &info); if (r < 0) { LOGED(ERROR, domid, "Getting domain info"); rc =3D ERROR_FAIL; diff --git a/tools/libs/light/libxl_x86_acpi.c b/tools/libs/light/libxl_x86= _acpi.c index 22eb160659..796b009d0c 100644 --- a/tools/libs/light/libxl_x86_acpi.c +++ b/tools/libs/light/libxl_x86_acpi.c @@ -87,14 +87,14 @@ static int init_acpi_config(libxl__gc *gc, { xc_interface *xch =3D dom->xch; uint32_t domid =3D dom->guest_domid; - xc_dominfo_t info; + xc_domaininfo_t info; struct hvm_info_table *hvminfo; int i, r, rc; =20 config->dsdt_anycpu =3D config->dsdt_15cpu =3D dsdt_pvh; config->dsdt_anycpu_len =3D config->dsdt_15cpu_len =3D dsdt_pvh_len; =20 - r =3D xc_domain_getinfo(xch, domid, 1, &info); + r =3D xc_domain_getinfo_single(xch, domid, &info); if (r < 0) { LOG(ERROR, "getdomaininfo failed (rc=3D%d)", r); rc =3D ERROR_FAIL; diff --git a/tools/misc/xen-hvmcrash.c b/tools/misc/xen-hvmcrash.c index 4f0dabcb18..1d058fa40a 100644 --- a/tools/misc/xen-hvmcrash.c +++ b/tools/misc/xen-hvmcrash.c @@ -48,7 +48,7 @@ main(int argc, char **argv) { int domid; xc_interface *xch; - xc_dominfo_t dominfo; + xc_domaininfo_t dominfo; int ret; uint32_t len; uint8_t *buf; @@ -66,13 +66,13 @@ main(int argc, char **argv) exit(1); } =20 - ret =3D xc_domain_getinfo(xch, domid, 1, &dominfo); + ret =3D xc_domain_getinfo_single(xch, domid, &dominfo); if (ret < 0) { perror("xc_domain_getinfo"); exit(1); } =20 - if (!dominfo.hvm) { + if (!(dominfo.flags & XEN_DOMINF_hvm_guest)) { fprintf(stderr, "domain %d is not HVM\n", domid); exit(1); } diff --git a/tools/misc/xen-lowmemd.c b/tools/misc/xen-lowmemd.c index a3a2741242..b483f63fdc 100644 --- a/tools/misc/xen-lowmemd.c +++ b/tools/misc/xen-lowmemd.c @@ -38,7 +38,7 @@ void cleanup(void) #define BUFSZ 512 void handle_low_mem(void) { - xc_dominfo_t dom0_info; + xc_domaininfo_t dom0_info; xc_physinfo_t info; unsigned long long free_pages, dom0_pages, diff, dom0_target; char data[BUFSZ], error[BUFSZ]; @@ -58,13 +58,13 @@ void handle_low_mem(void) return; diff =3D THRESHOLD_PG - free_pages;=20 =20 - if (xc_domain_getinfo(xch, 0, 1, &dom0_info) < 1) + if (xc_domain_getinfo_single(xch, 0, &dom0_info) < 0) { perror("Failed to get dom0 info"); return; } =20 - dom0_pages =3D (unsigned long long) dom0_info.nr_pages; + dom0_pages =3D (unsigned long long) dom0_info.tot_pages; printf("Dom0 pages: 0x%llx:%llu\n", dom0_pages, dom0_pages); dom0_target =3D dom0_pages - diff; if (dom0_target <=3D DOM0_FLOOR_PG) diff --git a/tools/misc/xen-mfndump.c b/tools/misc/xen-mfndump.c index b32c95e262..8863ece3f5 100644 --- a/tools/misc/xen-mfndump.c +++ b/tools/misc/xen-mfndump.c @@ -74,7 +74,7 @@ int dump_m2p_func(int argc, char *argv[]) int dump_p2m_func(int argc, char *argv[]) { struct xc_domain_meminfo minfo; - xc_dominfo_t info; + xc_domaininfo_t info; unsigned long i; int domid; =20 @@ -85,8 +85,7 @@ int dump_p2m_func(int argc, char *argv[]) } domid =3D atoi(argv[0]); =20 - if ( xc_domain_getinfo(xch, domid, 1, &info) !=3D 1 || - info.domid !=3D domid ) + if ( xc_domain_getinfo_single(xch, domid, &info) < 0 ) { ERROR("Failed to obtain info for domain %d\n", domid); return -1; @@ -158,7 +157,7 @@ int dump_p2m_func(int argc, char *argv[]) int dump_ptes_func(int argc, char *argv[]) { struct xc_domain_meminfo minfo; - xc_dominfo_t info; + xc_domaininfo_t info; void *page =3D NULL; unsigned long i, max_mfn; int domid, pte_num, rc =3D 0; @@ -172,8 +171,7 @@ int dump_ptes_func(int argc, char *argv[]) domid =3D atoi(argv[0]); mfn =3D strtoul(argv[1], NULL, 16); =20 - if ( xc_domain_getinfo(xch, domid, 1, &info) !=3D 1 || - info.domid !=3D domid ) + if ( xc_domain_getinfo_single(xch, domid, &info) < 0 ) { ERROR("Failed to obtain info for domain %d\n", domid); return -1; @@ -266,7 +264,7 @@ int dump_ptes_func(int argc, char *argv[]) int lookup_pte_func(int argc, char *argv[]) { struct xc_domain_meminfo minfo; - xc_dominfo_t info; + xc_domaininfo_t info; void *page =3D NULL; unsigned long i, j; int domid, pte_num; @@ -280,8 +278,7 @@ int lookup_pte_func(int argc, char *argv[]) domid =3D atoi(argv[0]); mfn =3D strtoul(argv[1], NULL, 16); =20 - if ( xc_domain_getinfo(xch, domid, 1, &info) !=3D 1 || - info.domid !=3D domid ) + if ( xc_domain_getinfo_single(xch, domid, &info) < 0 ) { ERROR("Failed to obtain info for domain %d\n", domid); return -1; @@ -336,7 +333,7 @@ int lookup_pte_func(int argc, char *argv[]) =20 int memcmp_mfns_func(int argc, char *argv[]) { - xc_dominfo_t info1, info2; + xc_domaininfo_t info1, info2; void *page1 =3D NULL, *page2 =3D NULL; int domid1, domid2; xen_pfn_t mfn1, mfn2; @@ -352,9 +349,8 @@ int memcmp_mfns_func(int argc, char *argv[]) mfn1 =3D strtoul(argv[1], NULL, 16); mfn2 =3D strtoul(argv[3], NULL, 16); =20 - if ( xc_domain_getinfo(xch, domid1, 1, &info1) !=3D 1 || - xc_domain_getinfo(xch, domid2, 1, &info2) !=3D 1 || - info1.domid !=3D domid1 || info2.domid !=3D domid2) + if ( xc_domain_getinfo_single(xch, domid1, &info1) < 0 || + xc_domain_getinfo_single(xch, domid2, &info2) < 0) { ERROR("Failed to obtain info for domains\n"); return -1; diff --git a/tools/misc/xen-vmtrace.c b/tools/misc/xen-vmtrace.c index 5b688a54af..ba2ce17a17 100644 --- a/tools/misc/xen-vmtrace.c +++ b/tools/misc/xen-vmtrace.c @@ -133,15 +133,15 @@ int main(int argc, char **argv) =20 while ( !interrupted ) { - xc_dominfo_t dominfo; + xc_domaininfo_t dominfo; =20 if ( get_more_data() ) goto out; =20 usleep(1000 * 100); =20 - if ( xc_domain_getinfo(xch, domid, 1, &dominfo) !=3D 1 || - dominfo.domid !=3D domid || dominfo.shutdown ) + if ( xc_domain_getinfo_single(xch, domid, &dominfo) < 0 || + (dominfo.flags & XEN_DOMINF_shutdown) ) { if ( get_more_data() ) goto out; diff --git a/tools/vchan/vchan-socket-proxy.c b/tools/vchan/vchan-socket-pr= oxy.c index e1d959c6d1..9c4c336b03 100644 --- a/tools/vchan/vchan-socket-proxy.c +++ b/tools/vchan/vchan-socket-proxy.c @@ -222,7 +222,7 @@ static struct libxenvchan *connect_vchan(int domid, con= st char *path) { struct libxenvchan *ctrl =3D NULL; struct xs_handle *xs =3D NULL; xc_interface *xc =3D NULL; - xc_dominfo_t dominfo; + xc_domaininfo_t dominfo; char **watch_ret; unsigned int watch_num; int ret; @@ -254,12 +254,12 @@ static struct libxenvchan *connect_vchan(int domid, c= onst char *path) { if (ctrl) break; =20 - ret =3D xc_domain_getinfo(xc, domid, 1, &dominfo); + ret =3D xc_domain_getinfo_single(xc, domid, &dominfo); /* break the loop if domain is definitely not there anymore, but * continue if it is or the call failed (like EPERM) */ if (ret =3D=3D -1 && errno =3D=3D ESRCH) break; - if (ret =3D=3D 1 && (dominfo.domid !=3D (uint32_t)domid || dominfo= .dying)) + if (ret =3D=3D 0 && (dominfo.flags & XEN_DOMINF_dying)) break; } =20 diff --git a/tools/xenstore/xenstored_domain.c b/tools/xenstore/xenstored_d= omain.c index f62be2245c..aeb7595ae1 100644 --- a/tools/xenstore/xenstored_domain.c +++ b/tools/xenstore/xenstored_domain.c @@ -339,15 +339,14 @@ static int destroy_domain(void *_domain) return 0; } =20 -static bool get_domain_info(unsigned int domid, xc_dominfo_t *dominfo) +static bool get_domain_info(unsigned int domid, xc_domaininfo_t *dominfo) { - return xc_domain_getinfo(*xc_handle, domid, 1, dominfo) =3D=3D 1 && - dominfo->domid =3D=3D domid; + return xc_domain_getinfo_single(*xc_handle, domid, dominfo) =3D=3D 0; } =20 static int check_domain(const void *k, void *v, void *arg) { - xc_dominfo_t dominfo; + xc_domaininfo_t dominfo; struct connection *conn; bool dom_valid; struct domain *domain =3D v; @@ -360,12 +359,12 @@ static int check_domain(const void *k, void *v, void = *arg) return 0; } if (dom_valid) { - if ((dominfo.crashed || dominfo.shutdown) + if ((dominfo.flags & XEN_DOMINF_shutdown) && !domain->shutdown) { domain->shutdown =3D true; *notify =3D true; } - if (!dominfo.dying) + if (!(dominfo.flags & XEN_DOMINF_dying)) return 0; } if (domain->conn) { @@ -486,7 +485,7 @@ static struct domain *find_or_alloc_domain(const void *= ctx, unsigned int domid) static struct domain *find_or_alloc_existing_domain(unsigned int domid) { struct domain *domain; - xc_dominfo_t dominfo; + xc_domaininfo_t dominfo; =20 domain =3D find_domain_struct(domid); if (!domain && get_domain_info(domid, &dominfo)) @@ -1010,7 +1009,7 @@ int domain_alloc_permrefs(struct node_perms *perms) { unsigned int i, domid; struct domain *d; - xc_dominfo_t dominfo; + xc_domaininfo_t dominfo; =20 for (i =3D 0; i < perms->num; i++) { domid =3D perms->p[i].id; diff --git a/tools/xentrace/xenctx.c b/tools/xentrace/xenctx.c index 85ba0c0fa6..9acb9db460 100644 --- a/tools/xentrace/xenctx.c +++ b/tools/xentrace/xenctx.c @@ -92,7 +92,7 @@ static struct xenctx { int do_stack; #endif int kernel_start_set; - xc_dominfo_t dominfo; + xc_domaininfo_t dominfo; } xenctx; =20 struct symbol { @@ -989,7 +989,7 @@ static void dump_ctx(int vcpu) =20 #if defined(__i386__) || defined(__x86_64__) { - if (xenctx.dominfo.hvm) { + if (xenctx.dominfo.flags & XEN_DOMINF_hvm_guest) { struct hvm_hw_cpu cpuctx; xen_capabilities_info_t xen_caps =3D ""; if (xc_domain_hvm_getcontext_partial( @@ -1269,9 +1269,9 @@ int main(int argc, char **argv) exit(-1); } =20 - ret =3D xc_domain_getinfo(xenctx.xc_handle, xenctx.domid, 1, &xenctx.d= ominfo); + ret =3D xc_domain_getinfo_single(xenctx.xc_handle, xenctx.domid, &xenc= tx.dominfo); if (ret < 0) { - perror("xc_domain_getinfo"); + perror("xc_domain_getinfo_single"); exit(-1); } =20 --=20 2.34.1 From nobody Tue May 14 13:30:34 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=reject dis=none) header.from=cloud.com ARC-Seal: i=1; a=rsa-sha256; t=1682521243; cv=none; d=zohomail.com; s=zohoarc; b=JRvpP/IU9lWqqrlKkuonJQ180vmOQONDIrduklYcfddbeLDwcs6nJ8GIRQv8H4FaMCYd1s7ucKSmvhJehumJkBxkfgV3OHyzia9SJ26rxA5hK7DRjY1Yasx4f7toV911tSwBS6HhmKiTwsSFoUZwgiAHpsXKgx1k4Oi68V7DC78= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682521243; h=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=QApVxERY829pwt09SvcXdDVUNpQVziPVty5UuwjPEJE=; b=O2Z0JehBmdas8zNXp49/zwlWmLdevdmlQIhreJVQemJIxlgJL020x8xJP6a8tdEilWqDR0fECexy2Hex3XNhDDKUGyuTORsbgpDMX6xEd3dRvb+XFFjvXGC527ynlUyjYSVe08LVm463h2xPRFPoYw5UXXgOo0OGP2dmChxNTso= 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=reject dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1682521243970833.6341854748704; Wed, 26 Apr 2023 08:00:43 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.526752.818727 (Exim 4.92) (envelope-from ) id 1prgcb-0002ID-3n; Wed, 26 Apr 2023 14:59:53 +0000 Received: by outflank-mailman (output) from mailman id 526752.818727; Wed, 26 Apr 2023 14:59:53 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1prgca-0002Hs-V3; Wed, 26 Apr 2023 14:59:52 +0000 Received: by outflank-mailman (input) for mailman id 526752; Wed, 26 Apr 2023 14:59:52 +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 1prgcZ-0000cE-V5 for xen-devel@lists.xenproject.org; Wed, 26 Apr 2023 14:59:51 +0000 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [2a00:1450:4864:20::42a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id febcc53d-e442-11ed-b224-6b7b168915f2; Wed, 26 Apr 2023 16:59:51 +0200 (CEST) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-2fc3f1d6f8cso4615864f8f.3 for ; Wed, 26 Apr 2023 07:59:51 -0700 (PDT) Received: from localhost.localdomain (default-46-102-197-194.interdsl.co.uk. [46.102.197.194]) by smtp.gmail.com with ESMTPSA id v17-20020a5d43d1000000b003047ea78b42sm6654116wrr.43.2023.04.26.07.59.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 07:59:49 -0700 (PDT) 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: febcc53d-e442-11ed-b224-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloud.com; s=cloud; t=1682521190; x=1685113190; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=QApVxERY829pwt09SvcXdDVUNpQVziPVty5UuwjPEJE=; b=DrJGhdhuFSloJuoPn17ICOmSFfPV6/16qhqMZWpLECee5iMuYdheSztwuwoVSLH7jJ iN1Jmm53mlH6y4YCQnzFCQsm52sVtM5aRBa2tHvFyjVJOetCUOgwDzmrXk+CyfKmKkoJ hX7dBsZELH1DglArzkBVwcuAph8RYi853cWaU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682521190; x=1685113190; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QApVxERY829pwt09SvcXdDVUNpQVziPVty5UuwjPEJE=; b=X/LbrXMDVVBuBQRau4+5IC7X3GSKH5A2cYpRzCUGzxsRygZSsCvkTftX3ZulWnS7PZ hgwqHAggd+qBOyih9cCe8/8FYfx2CHYcG9MAyS7T/AeFjTjLueXA9DynDgVRUPeOB1RD hHaA4tEbyN5V3e50wyE80lhhPCHoVc07upYu8HfXyU10sZm8CniMNbHHMl50cp9ReCP8 KZ3Iq7KW5mp1Q9A+k9SIvv9Jm4FXMTyhr4mAUXKw8B6Nm4eQy5CojngAwUvmcfql8R0s vf5qNfJjWRIhHHiU8JuR8eLdzJOpmdJnPlHVFDPYrmDTV1nrUTbrEOCrSN7wCibMczi5 Si7w== X-Gm-Message-State: AAQBX9fqUvxe0koiDUBCS04KDPYLPUoyHgKJ2lsNgci7PY9hGQG0Kkq/ nss/N5TpB+7COXXqNwc6US84ETYq0lTrmE6/gvQ= X-Google-Smtp-Source: AKy350ZPFEg7BYMyAAA5IAz4reDgIUpVGkf02JvvGJlWdWUw0qzWqfhqrAyzU7Dol4vA9JrsFjlt8Q== X-Received: by 2002:a5d:58e3:0:b0:2ee:da1c:381a with SMTP id f3-20020a5d58e3000000b002eeda1c381amr14327620wrd.69.1682521189967; Wed, 26 Apr 2023 07:59:49 -0700 (PDT) From: Alejandro Vallejo To: Xen-devel Cc: Alejandro Vallejo , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Anthony PERARD , Juergen Gross Subject: [PATCH 7/7] domctl: Modify getdomaininfo to fail if domid is not found Date: Wed, 26 Apr 2023 15:59:32 +0100 Message-Id: <20230426145932.3340-8-alejandro.vallejo@cloud.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230426145932.3340-1-alejandro.vallejo@cloud.com> References: <20230426145932.3340-1-alejandro.vallejo@cloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @cloud.com) X-ZM-MESSAGEID: 1682521246025100001 Content-Type: text/plain; charset="utf-8" It previously mimicked the getdomaininfo sysctl semantics by returning the first domid higher than the requested domid that does exist. This unintuitive behaviour causes quite a few mistakes and makes the call needlessly slow in its error path. This patch removes the fallback search, returning -ESRCH if the requested domain doesn't exist. Domain discovery can still be done through the sysctl interface as that performs a linear search on the list of domains. With this modification the xc_domain_getinfo() function is deprecated and removed to make sure it's not mistakenly used expecting the old behaviour. The new xc wrapper is xc_domain_getinfo_single(). All previous callers of xc_domain_getinfo() have been updated to use xc_domain_getinfo_single() or xc_domain_getinfolist() instead. This also means xc_dominfo_t is no longer used by anything and can be purged. Resolves: xen-project/xen#105 Signed-off-by: Alejandro Vallejo Reviewed-by: Andrew Cooper --- Cc: Andrew Cooper Cc: George Dunlap Cc: Jan Beulich Cc: Julien Grall Cc: Stefano Stabellini Cc: Wei Liu Cc: Anthony PERARD Cc: Juergen Gross --- tools/include/xenctrl.h | 43 ----------------------- tools/libs/ctrl/xc_domain.c | 70 ------------------------------------- xen/common/domctl.c | 32 ++--------------- 3 files changed, 2 insertions(+), 143 deletions(-) diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 755759f0fe..7ed22eff0d 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -444,28 +444,6 @@ typedef struct xc_core_header { * DOMAIN MANAGEMENT FUNCTIONS */ =20 -typedef struct xc_dominfo { - uint32_t domid; - uint32_t ssidref; - unsigned int dying:1, crashed:1, shutdown:1, - paused:1, blocked:1, running:1, - hvm:1, debugged:1, xenstore:1, hap:1; - unsigned int shutdown_reason; /* only meaningful if shutdown=3D=3D1 */ - unsigned long nr_pages; /* current number, not maximum */ - unsigned long nr_outstanding_pages; - unsigned long nr_shared_pages; - unsigned long nr_paged_pages; - unsigned long shared_info_frame; - uint64_t cpu_time; - unsigned long max_memkb; - unsigned int nr_online_vcpus; - unsigned int max_vcpu_id; - xen_domain_handle_t handle; - unsigned int cpupool; - uint8_t gpaddr_bits; - struct xen_arch_domainconfig arch_config; -} xc_dominfo_t; - typedef xen_domctl_getdomaininfo_t xc_domaininfo_t; =20 static inline unsigned int dominfo_shutdown_reason(const xc_domaininfo_t *= info) @@ -720,27 +698,6 @@ int xc_domain_getinfo_single(xc_interface *xch, uint32_t domid, xc_domaininfo_t *info); =20 -/** - * This function will return information about one or more domains. It is - * designed to iterate over the list of domains. If a single domain is - * requested, this function will return the next domain in the list - if - * one exists. It is, therefore, important in this case to make sure the - * domain requested was the one returned. - * - * @parm xch a handle to an open hypervisor interface - * @parm first_domid the first domain to enumerate information from. Doma= ins - * are currently enumerate in order of creation. - * @parm max_doms the number of elements in info - * @parm info an array of max_doms size that will contain the information = for - * the enumerated domains. - * @return the number of domains enumerated or -1 on error - */ -int xc_domain_getinfo(xc_interface *xch, - uint32_t first_domid, - unsigned int max_doms, - xc_dominfo_t *info); - - /** * This function will set the execution context for the specified vcpu. * diff --git a/tools/libs/ctrl/xc_domain.c b/tools/libs/ctrl/xc_domain.c index 5c37dbe200..581e7529e5 100644 --- a/tools/libs/ctrl/xc_domain.c +++ b/tools/libs/ctrl/xc_domain.c @@ -358,82 +358,12 @@ int xc_domain_getinfo_single(xc_interface *xch, if (rc < 0) return rc; =20 - if (domctl.u.getdomaininfo.domain !=3D domid) - return -ESRCH; - if (info) *info =3D domctl.u.getdomaininfo; =20 return rc; } =20 -int xc_domain_getinfo(xc_interface *xch, - uint32_t first_domid, - unsigned int max_doms, - xc_dominfo_t *info) -{ - unsigned int nr_doms; - uint32_t next_domid =3D first_domid; - DECLARE_DOMCTL; - int rc =3D 0; - - memset(info, 0, max_doms*sizeof(xc_dominfo_t)); - - for ( nr_doms =3D 0; nr_doms < max_doms; nr_doms++ ) - { - domctl.cmd =3D XEN_DOMCTL_getdomaininfo; - domctl.domain =3D next_domid; - if ( (rc =3D do_domctl(xch, &domctl)) < 0 ) - break; - info->domid =3D domctl.domain; - - info->dying =3D !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_dyin= g); - info->shutdown =3D !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_shut= down); - info->paused =3D !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_paus= ed); - info->blocked =3D !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_bloc= ked); - info->running =3D !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_runn= ing); - info->hvm =3D !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_hvm_= guest); - info->debugged =3D !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_debu= gged); - info->xenstore =3D !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_xs_d= omain); - info->hap =3D !!(domctl.u.getdomaininfo.flags&XEN_DOMINF_hap); - - info->shutdown_reason =3D - (domctl.u.getdomaininfo.flags>>XEN_DOMINF_shutdownshift) & - XEN_DOMINF_shutdownmask; - - if ( info->shutdown && (info->shutdown_reason =3D=3D SHUTDOWN_cras= h) ) - { - info->shutdown =3D 0; - info->crashed =3D 1; - } - - info->ssidref =3D domctl.u.getdomaininfo.ssidref; - info->nr_pages =3D domctl.u.getdomaininfo.tot_pages; - info->nr_outstanding_pages =3D domctl.u.getdomaininfo.outstanding_= pages; - info->nr_shared_pages =3D domctl.u.getdomaininfo.shr_pages; - info->nr_paged_pages =3D domctl.u.getdomaininfo.paged_pages; - info->max_memkb =3D domctl.u.getdomaininfo.max_pages << (PAGE_SHIF= T-10); - info->shared_info_frame =3D domctl.u.getdomaininfo.shared_info_fra= me; - info->cpu_time =3D domctl.u.getdomaininfo.cpu_time; - info->nr_online_vcpus =3D domctl.u.getdomaininfo.nr_online_vcpus; - info->max_vcpu_id =3D domctl.u.getdomaininfo.max_vcpu_id; - info->cpupool =3D domctl.u.getdomaininfo.cpupool; - info->gpaddr_bits =3D domctl.u.getdomaininfo.gpaddr_bits; - info->arch_config =3D domctl.u.getdomaininfo.arch_config; - - memcpy(info->handle, domctl.u.getdomaininfo.handle, - sizeof(xen_domain_handle_t)); - - next_domid =3D (uint16_t)domctl.domain + 1; - info++; - } - - if ( nr_doms =3D=3D 0 ) - return rc; - - return nr_doms; -} - int xc_domain_getinfolist(xc_interface *xch, uint32_t first_domain, unsigned int max_domains, diff --git a/xen/common/domctl.c b/xen/common/domctl.c index ad71ad8a4c..24a14996e6 100644 --- a/xen/common/domctl.c +++ b/xen/common/domctl.c @@ -314,7 +314,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_d= omctl) /* fall through */ default: d =3D rcu_lock_domain_by_id(op->domain); - if ( !d && op->cmd !=3D XEN_DOMCTL_getdomaininfo ) + if ( !d ) return -ESRCH; } =20 @@ -534,42 +534,14 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u= _domctl) =20 case XEN_DOMCTL_getdomaininfo: { - domid_t dom =3D DOMID_INVALID; - - if ( !d ) - { - ret =3D -EINVAL; - if ( op->domain >=3D DOMID_FIRST_RESERVED ) - break; - - rcu_read_lock(&domlist_read_lock); - - dom =3D op->domain; - for_each_domain ( d ) - if ( d->domain_id >=3D dom ) - break; - } - - ret =3D -ESRCH; - if ( d =3D=3D NULL ) - goto getdomaininfo_out; - ret =3D xsm_getdomaininfo(XSM_HOOK, d); if ( ret ) - goto getdomaininfo_out; + break; =20 getdomaininfo(d, &op->u.getdomaininfo); =20 op->domain =3D op->u.getdomaininfo.domain; copyback =3D 1; - - getdomaininfo_out: - /* When d was non-NULL upon entry, no cleanup is needed. */ - if ( dom =3D=3D DOMID_INVALID ) - break; - - rcu_read_unlock(&domlist_read_lock); - d =3D NULL; break; } =20 --=20 2.34.1