From nobody Tue Feb 10 02:49:03 2026 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=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1611264485; cv=none; d=zohomail.com; s=zohoarc; b=CEZkMUdXNQk9ElkbMxkBGPOtqeGpG1y1vSe7zn/9LgiSGKdap4eojIo1FIAFD/HQcqRFdJKqHf6AC2ItlimJyXSPwHdFrwTEZqcFpvK1vpcA0xYZnsXNRu8QLeC2UdSOKnS/UVrFuMVG2WjCt7WxeKh12CeZbaqAaUCobq/GfN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611264485; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=590oI3ygSc4wbvCd6v+UbdTAv68ZcP37508QTvucQjc=; b=TE4jfy1x8jSWkWuqokETkh+wNC/MiGf5qGV4MO1pBzsrkvKhAN3beXyfnfGU7PKmXahLRa7WEDPwOkbrNkjwsxJIzUd45SLVQjuC00wWN6IRyAh2wT15mCy5Avy7oRcG7XZ+S0qZ8D9zLzXwwvY6NstF3dV7vBvXpIvndWuiwF0= 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) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1611264485272773.5111437677788; Thu, 21 Jan 2021 13:28:05 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.72427.130430 (Exim 4.92) (envelope-from ) id 1l2hUd-0005CV-9f; Thu, 21 Jan 2021 21:27:51 +0000 Received: by outflank-mailman (output) from mailman id 72427.130430; Thu, 21 Jan 2021 21:27:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2hUc-0005By-VZ; Thu, 21 Jan 2021 21:27:50 +0000 Received: by outflank-mailman (input) for mailman id 72427; Thu, 21 Jan 2021 21:27:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l2hUb-0004xo-QD for xen-devel@lists.xenproject.org; Thu, 21 Jan 2021 21:27:49 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 375bebc6-b808-405d-9366-9079a2fcb42e; Thu, 21 Jan 2021 21:27:39 +0000 (UTC) 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: 375bebc6-b808-405d-9366-9079a2fcb42e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1611264458; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BoP/rfsovnNtQ8ibuYb5LfKyC6U90NDoKfh3PcApORE=; b=C/NB7nW1QOtiRnZHxlxkCU6PabzItyY562WXYRUvc7/CgEv8W3V+CcwR cmWQJkYUIe1JnYAoVyqLflQ1sw6Kfi3XKIoeQHReO09ZJciOUVv+ZFIFK jOhvdFdgGulL/eyY6u01Xs5wYGquRgWgfogivdHW/Ab7zCFy4xIo5mJxp w=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: hEJkToRs80NOlG7G50aqfGmIoekXoev5dlNXRccxGlRsPOfz/mYw2svrxzHQU/vHfbRdZvNVYY stDBZrWwf4raZ/aUKLZb650XFRwB75NslribDjzupdv3zMm+allu3ZqF/ZD68wNc1LE0y3lFEv d4MNeoxLVxu5fFBa+r8IIjM4+P92z1fewLrYstgUo+lZ9NMhjXTiRcYXjBiw8F6tqEfGZrKN1u yV8FG6M3B9rhlH/bFeCgAu3t7UPd21SUTq7gd35g/KUKapAjREg+SfUssw+ujVdRNwWJsd8XXK wRE= X-SBRS: 5.1 X-MesageID: 35815969 X-Ironport-Server: esa6.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.79,365,1602561600"; d="scan'208";a="35815969" From: Andrew Cooper To: Xen-devel CC: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= , Andrew Cooper , Ian Jackson , Wei Liu , Tamas K Lengyel Subject: [PATCH v7 07/10] tools/libxc: Add xc_vmtrace_* functions Date: Thu, 21 Jan 2021 21:27:15 +0000 Message-ID: <20210121212718.2441-8-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210121212718.2441-1-andrew.cooper3@citrix.com> References: <20210121212718.2441-1-andrew.cooper3@citrix.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @citrix.com) From: Micha=C5=82 Leszczy=C5=84ski Add functions in libxc that use the new XEN_DOMCTL_vmtrace interface. Signed-off-by: Micha=C5=82 Leszczy=C5=84ski Signed-off-by: Andrew Cooper Acked-by: Ian Jackson --- CC: Ian Jackson CC: Wei Liu CC: Micha=C5=82 Leszczy=C5=84ski CC: Tamas K Lengyel v7: * Use the name 'vmtrace' consistently. --- tools/include/xenctrl.h | 73 ++++++++++++++++++++++++ tools/libs/ctrl/Makefile | 1 + tools/libs/ctrl/xc_vmtrace.c | 128 +++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 202 insertions(+) create mode 100644 tools/libs/ctrl/xc_vmtrace.c diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h index 3796425e1e..0efcdae8b4 100644 --- a/tools/include/xenctrl.h +++ b/tools/include/xenctrl.h @@ -1583,6 +1583,79 @@ int xc_tbuf_set_cpu_mask(xc_interface *xch, xc_cpuma= p_t mask); =20 int xc_tbuf_set_evt_mask(xc_interface *xch, uint32_t mask); =20 +/** + * Enable vmtrace for given vCPU. + * + * @parm xch a handle to an open hypervisor interface + * @parm domid domain identifier + * @parm vcpu vcpu identifier + * @return 0 on success, -1 on failure + */ +int xc_vmtrace_enable(xc_interface *xch, uint32_t domid, uint32_t vcpu); + +/** + * Enable vmtrace for given vCPU. + * + * @parm xch a handle to an open hypervisor interface + * @parm domid domain identifier + * @parm vcpu vcpu identifier + * @return 0 on success, -1 on failure + */ +int xc_vmtrace_disable(xc_interface *xch, uint32_t domid, uint32_t vcpu); + +/** + * Enable vmtrace for a given vCPU, along with resetting status/offset + * details. + * + * @parm xch a handle to an open hypervisor interface + * @parm domid domain identifier + * @parm vcpu vcpu identifier + * @return 0 on success, -1 on failure + */ +int xc_vmtrace_reset_and_enable(xc_interface *xch, uint32_t domid, + uint32_t vcpu); + +/** + * Get current output position inside the trace buffer. + * + * Repeated calls will return different values if tracing is enabled. It = is + * platform specific what happens when the buffer fills completely. + * + * @parm xch a handle to an open hypervisor interface + * @parm domid domain identifier + * @parm vcpu vcpu identifier + * @parm pos current output position in bytes + * @return 0 on success, -1 on failure + */ +int xc_vmtrace_output_position(xc_interface *xch, uint32_t domid, + uint32_t vcpu, uint64_t *pos); + +/** + * Get platform specific vmtrace options. + * + * @parm xch a handle to an open hypervisor interface + * @parm domid domain identifier + * @parm vcpu vcpu identifier + * @parm key platform-specific input + * @parm value platform-specific output + * @return 0 on success, -1 on failure + */ +int xc_vmtrace_get_option(xc_interface *xch, uint32_t domid, + uint32_t vcpu, uint64_t key, uint64_t *value); + +/** + * Set platform specific vntvmtrace options. + * + * @parm xch a handle to an open hypervisor interface + * @parm domid domain identifier + * @parm vcpu vcpu identifier + * @parm key platform-specific input + * @parm value platform-specific input + * @return 0 on success, -1 on failure + */ +int xc_vmtrace_set_option(xc_interface *xch, uint32_t domid, + uint32_t vcpu, uint64_t key, uint64_t value); + int xc_domctl(xc_interface *xch, struct xen_domctl *domctl); int xc_sysctl(xc_interface *xch, struct xen_sysctl *sysctl); =20 diff --git a/tools/libs/ctrl/Makefile b/tools/libs/ctrl/Makefile index 4185dc3f22..449c89f440 100644 --- a/tools/libs/ctrl/Makefile +++ b/tools/libs/ctrl/Makefile @@ -22,6 +22,7 @@ SRCS-y +=3D xc_pm.c SRCS-y +=3D xc_cpu_hotplug.c SRCS-y +=3D xc_resume.c SRCS-y +=3D xc_vm_event.c +SRCS-y +=3D xc_vmtrace.c SRCS-y +=3D xc_monitor.c SRCS-y +=3D xc_mem_paging.c SRCS-y +=3D xc_mem_access.c diff --git a/tools/libs/ctrl/xc_vmtrace.c b/tools/libs/ctrl/xc_vmtrace.c new file mode 100644 index 0000000000..602502367f --- /dev/null +++ b/tools/libs/ctrl/xc_vmtrace.c @@ -0,0 +1,128 @@ +/*************************************************************************= ***** + * xc_vmtrace.c + * + * API for manipulating hardware tracing features + * + * Copyright (c) 2020, Michal Leszczynski + * + * Copyright 2020 CERT Polska. All rights reserved. + * Use is subject to license terms. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; If not, see . + */ + +#include "xc_private.h" + +int xc_vmtrace_enable( + xc_interface *xch, uint32_t domid, uint32_t vcpu) +{ + struct xen_domctl domctl =3D { + .cmd =3D XEN_DOMCTL_vmtrace_op, + .domain =3D domid, + .u.vmtrace_op =3D { + .cmd =3D XEN_DOMCTL_vmtrace_enable, + .vcpu =3D vcpu, + }, + }; + + return do_domctl(xch, &domctl); +} + +int xc_vmtrace_disable( + xc_interface *xch, uint32_t domid, uint32_t vcpu) +{ + struct xen_domctl domctl =3D { + .cmd =3D XEN_DOMCTL_vmtrace_op, + .domain =3D domid, + .u.vmtrace_op =3D { + .cmd =3D XEN_DOMCTL_vmtrace_disable, + .vcpu =3D vcpu, + }, + }; + + return do_domctl(xch, &domctl); +} + +int xc_vmtrace_reset_and_enable( + xc_interface *xch, uint32_t domid, uint32_t vcpu) +{ + struct xen_domctl domctl =3D { + .cmd =3D XEN_DOMCTL_vmtrace_op, + .domain =3D domid, + .u.vmtrace_op =3D { + .cmd =3D XEN_DOMCTL_vmtrace_reset_and_enable, + .vcpu =3D vcpu, + }, + }; + + return do_domctl(xch, &domctl); +} + +int xc_vmtrace_output_position( + xc_interface *xch, uint32_t domid, uint32_t vcpu, uint64_t *pos) +{ + struct xen_domctl domctl =3D { + .cmd =3D XEN_DOMCTL_vmtrace_op, + .domain =3D domid, + .u.vmtrace_op =3D { + .cmd =3D XEN_DOMCTL_vmtrace_output_position, + .vcpu =3D vcpu, + }, + }; + int rc =3D do_domctl(xch, &domctl); + + if ( !rc ) + *pos =3D domctl.u.vmtrace_op.value; + + return rc; +} + +int xc_vmtrace_get_option( + xc_interface *xch, uint32_t domid, uint32_t vcpu, + uint64_t key, uint64_t *value) +{ + struct xen_domctl domctl =3D { + .cmd =3D XEN_DOMCTL_vmtrace_op, + .domain =3D domid, + .u.vmtrace_op =3D { + .cmd =3D XEN_DOMCTL_vmtrace_get_option, + .vcpu =3D vcpu, + .key =3D key, + }, + }; + int rc =3D do_domctl(xch, &domctl); + + if ( !rc ) + *value =3D domctl.u.vmtrace_op.value; + + return rc; +} + +int xc_vmtrace_set_option( + xc_interface *xch, uint32_t domid, uint32_t vcpu, + uint64_t key, uint64_t value) +{ + struct xen_domctl domctl =3D { + .cmd =3D XEN_DOMCTL_vmtrace_op, + .domain =3D domid, + .u.vmtrace_op =3D { + .cmd =3D XEN_DOMCTL_vmtrace_set_option, + .vcpu =3D vcpu, + .key =3D key, + .value =3D value, + }, + }; + + return do_domctl(xch, &domctl); +} --=20 2.11.0