From nobody Mon Feb 9 17:37:02 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=1612222073; cv=none; d=zohomail.com; s=zohoarc; b=RQCE/ENRzMH8WqNfk7XfY669d+TQNjnHorywA/OoaeJV4+RhLGYV1nFwSj0NgzA75JP7eeX2OBdhVBSa3+uYNXk9t6MBe2DkXksTojQajQJjBXP2BaEIVFsX6aQUEr/0AKZVkeXb6/8t+5zWi8e96XmshtAdw/8ytSPxfjRo80Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612222073; 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=OOl+6dOz/GKWfeNJufTbWMNfyQTCiliRW7mWG3IpAtU=; b=CDsd99zbfZTSmbYnr604gWpjOKcuswO5AE8AdbtH8g6I6BBzLm//VmvneAREbGohpt3Z4+aSC8Ryx2QvqVWxJ9+f+0kxZn3APxLkYiJkjRbaQGhRY9zLFfcuqXMQAOcgDN+3dxP6oi5VncaXMFmOOX9l4yJzB1Hav1La+qAwMfE= 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 1612222073249179.6249732457071; Mon, 1 Feb 2021 15:27:53 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.80189.146493 (Exim 4.92) (envelope-from ) id 1l6ibX-0007QH-AZ; Mon, 01 Feb 2021 23:27:35 +0000 Received: by outflank-mailman (output) from mailman id 80189.146493; Mon, 01 Feb 2021 23:27:35 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l6ibX-0007QA-7Z; Mon, 01 Feb 2021 23:27:35 +0000 Received: by outflank-mailman (input) for mailman id 80189; Mon, 01 Feb 2021 23:27:34 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l6ibW-0007PB-0l for xen-devel@lists.xenproject.org; Mon, 01 Feb 2021 23:27:34 +0000 Received: from esa6.hc3370-68.iphmx.com (unknown [216.71.155.175]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 5bda2d77-d5a5-4294-9fd1-d4c2be43d2e3; Mon, 01 Feb 2021 23:27:32 +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: 5bda2d77-d5a5-4294-9fd1-d4c2be43d2e3 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1612222052; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EvfjqR50MUjZfV+wJxte5vJxLsTztJ8urztBWoZwrE4=; b=a64ywfGPWzZrgGIZ9nz5YSx5JWVPNBK9O+cLzYjkjQ0XabURaXYhTRRE YqibgUDpj+qcAeC6ObSohMbGGtMzC8aLnsjcasW6qcG5UbLQWwA/3t6// llOg3BnNbSBN1hAWoUx8FNUPmD1VV/efdFecmW76lA7vZvtXdcpEcBfqR c=; Authentication-Results: esa6.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: p+bwOS9yhAo0dKZ1+LmmyuytD6afidLE/c6n6GRnIcBSgmr0eDty1Gtj6MxTt4mjmczbooMOYP U8rfJeV3iX3LGukV840Cc9jx8pL50wshDUT/vR4nxdOdMCYbLVAWa8066eaRYUDU7k1WhQ3m2U Vb5TxY/FC4fFeJR7F1oB40hFd4ohKIziSaAhvJPZPjvW1FiFy1rSNEJEhd4BoXWMtXZQQTi/mx Zt9tJLlcB6Xfx/vz09iN1F0ae8yvRdQnQwJ8Qpo6/KP5xliDfdWxsWlsW3WIh+TnTn+txqSZvu +jk= X-SBRS: 5.1 X-MesageID: 36523027 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,393,1602561600"; d="scan'208";a="36523027" 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 v9 07/11] tools/libxc: Add xc_vmtrace_* functions Date: Mon, 1 Feb 2021 23:26:59 +0000 Message-ID: <20210201232703.29275-8-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210201232703.29275-1-andrew.cooper3@citrix.com> References: <20210201232703.29275-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 6106e36c49..ce9ecae710 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