From patchwork Sun Jul 5 18:55:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Micha=C5=82_Leszczy=C5=84ski?= X-Patchwork-Id: 11644611 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 491CE6C1 for ; Sun, 5 Jul 2020 18:58:06 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3015C2073E for ; Sun, 5 Jul 2020 18:58:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3015C2073E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=cert.pl Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9oV-0005ub-Mo; Sun, 05 Jul 2020 18:56:31 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9oT-0005m2-VJ for xen-devel@lists.xenproject.org; Sun, 05 Jul 2020 18:56:29 +0000 X-Inumbo-ID: 37203e8c-bef1-11ea-8496-bc764e2007e4 Received: from bagnar.nask.net.pl (unknown [195.187.242.196]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 37203e8c-bef1-11ea-8496-bc764e2007e4; Sun, 05 Jul 2020 18:56:21 +0000 (UTC) Received: from bagnar.nask.net.pl (unknown [172.16.9.10]) by bagnar.nask.net.pl (Postfix) with ESMTP id 17C21A2081; Sun, 5 Jul 2020 20:56:17 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id CE085A2047; Sun, 5 Jul 2020 20:56:15 +0200 (CEST) X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from bagnar.nask.net.pl ([127.0.0.1]) by localhost (bagnar.nask.net.pl [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id lMswJV0Qiirr; Sun, 5 Jul 2020 20:56:15 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id CBE51A207F; Sun, 5 Jul 2020 20:56:14 +0200 (CEST) X-Virus-Scanned: amavisd-new at bagnar.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from bagnar.nask.net.pl ([127.0.0.1]) by localhost (bagnar.nask.net.pl [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id sJXl2t2dRER2; Sun, 5 Jul 2020 20:56:14 +0200 (CEST) Received: from belindir.nask.net.pl (belindir-ext.nask.net.pl [195.187.242.210]) by bagnar.nask.net.pl (Postfix) with ESMTP id 16632A202C; Sun, 5 Jul 2020 20:56:14 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by belindir.nask.net.pl (Postfix) with ESMTP id 422F022C3A; Sun, 5 Jul 2020 20:55:19 +0200 (CEST) X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from belindir.nask.net.pl ([127.0.0.1]) by localhost (belindir.nask.net.pl [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id yPJWs7im3KH7; Sun, 5 Jul 2020 20:55:13 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by belindir.nask.net.pl (Postfix) with ESMTP id 9E30D22C20; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) X-Quarantine-ID: <9a2BxL5qECOO> X-Virus-Scanned: amavisd-new at belindir.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" Received: from belindir.nask.net.pl ([127.0.0.1]) by localhost (belindir.nask.net.pl [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 9a2BxL5qECOO; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) Received: from mq-desktop.cert.pl (unknown [195.187.238.217]) by belindir.nask.net.pl (Postfix) with ESMTPSA id 7412D22C1A; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) From: =?utf-8?q?Micha=C5=82_Leszczy=C5=84ski?= To: xen-devel@lists.xenproject.org Subject: [PATCH v5 10/11] tools/libxc: add xc_vmtrace_* functions Date: Sun, 5 Jul 2020 20:55:03 +0200 Message-Id: <07343a2258d2db7dab24653edab84b825103e63d.1593974333.git.michal.leszczynski@cert.pl> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: In-Reply-To: References: X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: luwei.kang@intel.com, Michal Leszczynski , tamas.lengyel@intel.com, Ian Jackson , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Michal Leszczynski Add functions in libxc that use the new XEN_DOMCTL_vmtrace interface. Signed-off-by: Michal Leszczynski --- tools/libxc/Makefile | 1 + tools/libxc/include/xenctrl.h | 39 +++++++++++++++++++ tools/libxc/xc_vmtrace.c | 73 +++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 tools/libxc/xc_vmtrace.c diff --git a/tools/libxc/Makefile b/tools/libxc/Makefile index fae5969a73..605e44501d 100644 --- a/tools/libxc/Makefile +++ b/tools/libxc/Makefile @@ -27,6 +27,7 @@ CTRL_SRCS-y += xc_csched2.c CTRL_SRCS-y += xc_arinc653.c CTRL_SRCS-y += xc_rt.c CTRL_SRCS-y += xc_tbuf.c +CTRL_SRCS-y += xc_vmtrace.c CTRL_SRCS-y += xc_pm.c CTRL_SRCS-y += xc_cpu_hotplug.c CTRL_SRCS-y += xc_resume.c diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 4c89b7294c..34f27fd7d4 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -1585,6 +1585,45 @@ int xc_tbuf_set_cpu_mask(xc_interface *xch, xc_cpumap_t mask); int xc_tbuf_set_evt_mask(xc_interface *xch, uint32_t mask); +/** + * Enable processor trace for given vCPU in given DomU. + * Allocate the trace ringbuffer with given size. + * + * @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_pt_enable(xc_interface *xch, uint32_t domid, + uint32_t vcpu); + +/** + * Disable processor trace for given vCPU in given DomU. + * Deallocate the trace ringbuffer. + * + * @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_pt_disable(xc_interface *xch, uint32_t domid, + uint32_t vcpu); + +/** + * Get current offset inside the trace ringbuffer. + * This allows to determine how much data was written into the buffer. + * Once buffer overflows, the offset will reset to 0 and the previous + * data will be overriden. + * + * @parm xch a handle to an open hypervisor interface + * @parm domid domain identifier + * @parm vcpu vcpu identifier + * @parm offset current offset inside trace buffer will be written there + * @return 0 on success, -1 on failure + */ +int xc_vmtrace_pt_get_offset(xc_interface *xch, uint32_t domid, + uint32_t vcpu, uint64_t *offset); + int xc_domctl(xc_interface *xch, struct xen_domctl *domctl); int xc_sysctl(xc_interface *xch, struct xen_sysctl *sysctl); diff --git a/tools/libxc/xc_vmtrace.c b/tools/libxc/xc_vmtrace.c new file mode 100644 index 0000000000..32f90a6203 --- /dev/null +++ b/tools/libxc/xc_vmtrace.c @@ -0,0 +1,73 @@ +/****************************************************************************** + * 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" +#include + +int xc_vmtrace_pt_enable( + xc_interface *xch, uint32_t domid, uint32_t vcpu) +{ + DECLARE_DOMCTL; + int rc; + + domctl.cmd = XEN_DOMCTL_vmtrace_op; + domctl.domain = domid; + domctl.u.vmtrace_op.cmd = XEN_DOMCTL_vmtrace_pt_enable; + domctl.u.vmtrace_op.vcpu = vcpu; + + rc = do_domctl(xch, &domctl); + return rc; +} + +int xc_vmtrace_pt_get_offset( + xc_interface *xch, uint32_t domid, uint32_t vcpu, uint64_t *offset) +{ + DECLARE_DOMCTL; + int rc; + + domctl.cmd = XEN_DOMCTL_vmtrace_op; + domctl.domain = domid; + domctl.u.vmtrace_op.cmd = XEN_DOMCTL_vmtrace_pt_get_offset; + domctl.u.vmtrace_op.vcpu = vcpu; + + rc = do_domctl(xch, &domctl); + if ( !rc ) + *offset = domctl.u.vmtrace_op.offset; + return rc; +} + +int xc_vmtrace_pt_disable(xc_interface *xch, uint32_t domid, uint32_t vcpu) +{ + DECLARE_DOMCTL; + int rc; + + domctl.cmd = XEN_DOMCTL_vmtrace_op; + domctl.domain = domid; + domctl.u.vmtrace_op.cmd = XEN_DOMCTL_vmtrace_pt_disable; + domctl.u.vmtrace_op.vcpu = vcpu; + + rc = do_domctl(xch, &domctl); + return rc; +} +