From nobody Mon Apr 29 12:59:10 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; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1593975378; cv=none; d=zohomail.com; s=zohoarc; b=MbgZxIpm1E7bgboSCMgLe8m3iW+uErE6VYx2eNFrE9nCGP4qchPcpNMoHqZCWwYWNvIeLwrHzebkunAUDCXbMvCVGhKybL5Og8y/s2jToJEsO7xTOlVG2j6P0bAJd7pRiuh5VSFmi7DkfI9YA71HisSCJhOGg4VHmCDeMmGvVhI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593975378; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=CUkkQAhhI5xcybLku89uNmcO2dRNCsGV/viGgRgoFUE=; b=jcfAeqV0MVRMdiAtQ0Fa8Q3kJj6Dilm7f0FP+KIppkoOZsMjGbDGF+9H4NCUAt9In7aTfGtN/O41445OGJ09AX1sfRaScUYz3iddT4xcYAvkUGMFQhy7BecuNGB6RcadXdN5qNWWy91U3OmQfx6vLXGf4MewnQ6XfaTPsMkLQE8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 159397537818767.10469121694109; Sun, 5 Jul 2020 11:56:18 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9nz-0005d4-0f; Sun, 05 Jul 2020 18:55:59 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9nx-0005bb-O2 for xen-devel@lists.xenproject.org; Sun, 05 Jul 2020 18:55:57 +0000 Received: from bagnar.nask.net.pl (unknown [195.187.242.196]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2245c091-bef1-11ea-8c02-12813bfff9fa; Sun, 05 Jul 2020 18:55:46 +0000 (UTC) Received: from bagnar.nask.net.pl (unknown [172.16.9.10]) by bagnar.nask.net.pl (Postfix) with ESMTP id 77381A202C; Sun, 5 Jul 2020 20:55:45 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id 66A44A2022; Sun, 5 Jul 2020 20:55:44 +0200 (CEST) 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 6bSkVzviQlTy; Sun, 5 Jul 2020 20:55:43 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id BC2BCA200D; Sun, 5 Jul 2020 20:55:43 +0200 (CEST) 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 zfmRvghhShE3; Sun, 5 Jul 2020 20:55:43 +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 82B4FA1CEA; Sun, 5 Jul 2020 20:55:43 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by belindir.nask.net.pl (Postfix) with ESMTP id 698AC22C2A; Sun, 5 Jul 2020 20:55:13 +0200 (CEST) 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 px1dtBfU7_oa; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by belindir.nask.net.pl (Postfix) with ESMTP id E6A9B22BF6; Sun, 5 Jul 2020 20:55:07 +0200 (CEST) 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 6GIZq3m1Wlkr; Sun, 5 Jul 2020 20:55:07 +0200 (CEST) Received: from mq-desktop.cert.pl (unknown [195.187.238.217]) by belindir.nask.net.pl (Postfix) with ESMTPSA id B921E2295A; Sun, 5 Jul 2020 20:55:07 +0200 (CEST) X-Inumbo-ID: 2245c091-bef1-11ea-8c02-12813bfff9fa X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Virus-Scanned: amavisd-new at bagnar.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Quarantine-ID: <6GIZq3m1Wlkr> X-Virus-Scanned: amavisd-new at belindir.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" From: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= To: xen-devel@lists.xenproject.org Subject: [PATCH v5 01/11] memory: batch processing in acquire_resource() Date: Sun, 5 Jul 2020 20:54:54 +0200 Message-Id: <02415890e4e8211513b495228c790e1d16de767f.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: Julien Grall , Stefano Stabellini , luwei.kang@intel.com, Wei Liu , Andrew Cooper , Michal Leszczynski , Ian Jackson , George Dunlap , Jan Beulich , tamas.lengyel@intel.com Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michal Leszczynski Allow to acquire large resources by allowing acquire_resource() to process items in batches, using hypercall continuation. Be aware that this modifies the behavior of acquire_resource call with frame_list=3DNULL. While previously it would return the size of internal array (32), with this patch it returns the maximal quantity of frames that could be requested at once, i.e. UINT_MAX >> MEMOP_EXTENT_SHIFT. Signed-off-by: Michal Leszczynski --- xen/common/memory.c | 49 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) diff --git a/xen/common/memory.c b/xen/common/memory.c index 714077c1e5..eb42f883df 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1046,10 +1046,12 @@ static int acquire_grant_table(struct domain *d, un= signed int id, } =20 static int acquire_resource( - XEN_GUEST_HANDLE_PARAM(xen_mem_acquire_resource_t) arg) + XEN_GUEST_HANDLE_PARAM(xen_mem_acquire_resource_t) arg, + unsigned long *start_extent) { struct domain *d, *currd =3D current->domain; xen_mem_acquire_resource_t xmar; + uint32_t total_frames; /* * The mfn_list and gfn_list (below) arrays are ok on stack for the * moment since they are small, but if they need to grow in future @@ -1069,7 +1071,7 @@ static int acquire_resource( if ( xmar.nr_frames ) return -EINVAL; =20 - xmar.nr_frames =3D ARRAY_SIZE(mfn_list); + xmar.nr_frames =3D UINT_MAX >> MEMOP_EXTENT_SHIFT; =20 if ( __copy_field_to_guest(arg, &xmar, nr_frames) ) return -EFAULT; @@ -1077,8 +1079,28 @@ static int acquire_resource( return 0; } =20 + total_frames =3D xmar.nr_frames; + + /* Is the size too large for us to encode a continuation? */ + if ( unlikely(xmar.nr_frames > (UINT_MAX >> MEMOP_EXTENT_SHIFT)) ) + return -EINVAL; + + if ( *start_extent ) + { + /* + * Check whether start_extent is in bounds, as this + * value if visible to the calling domain. + */ + if ( *start_extent > xmar.nr_frames ) + return -EINVAL; + + xmar.frame +=3D *start_extent; + xmar.nr_frames -=3D *start_extent; + guest_handle_add_offset(xmar.frame_list, *start_extent); + } + if ( xmar.nr_frames > ARRAY_SIZE(mfn_list) ) - return -E2BIG; + xmar.nr_frames =3D ARRAY_SIZE(mfn_list); =20 rc =3D rcu_lock_remote_domain_by_id(xmar.domid, &d); if ( rc ) @@ -1135,6 +1157,14 @@ static int acquire_resource( } } =20 + if ( !rc ) + { + *start_extent +=3D xmar.nr_frames; + + if ( *start_extent !=3D total_frames ) + rc =3D -ERESTART; + } + out: rcu_unlock_domain(d); =20 @@ -1599,8 +1629,17 @@ long do_memory_op(unsigned long cmd, XEN_GUEST_HANDL= E_PARAM(void) arg) #endif =20 case XENMEM_acquire_resource: - rc =3D acquire_resource( - guest_handle_cast(arg, xen_mem_acquire_resource_t)); + do { + rc =3D acquire_resource( + guest_handle_cast(arg, xen_mem_acquire_resource_t), + &start_extent); + + if ( hypercall_preempt_check() ) + return hypercall_create_continuation( + __HYPERVISOR_memory_op, "lh", + op | (start_extent << MEMOP_EXTENT_SHIFT), arg); + } while ( rc =3D=3D -ERESTART ); + break; =20 default: --=20 2.17.1 From nobody Mon Apr 29 12:59:10 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; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1593975379; cv=none; d=zohomail.com; s=zohoarc; b=B9vggYsCBpL8trNCouOZowah5C0X/SouK+RsuxDvQaWU/oAc49lFq94RnLXvYyRPt3OopAx5TzHnQQ4lbIQN3QPYYsmwX0e1ZqR9SsQG5/akuuxh0F9a1CYTuBRzpU8o0XVs0dB/KGRatLxU2+xhndwPqClqxcbv1kfa/XR0CGs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593975379; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=bpb3y2LW6/MmYGNZwA6mmuHDbH5oG5iHRW9fBvlZyKQ=; b=nJkf4P0m0APqR3WNPMeIWs7UsZ5DsUDY/cmCJug1cHJeNrpY3VSAAAYPJ72PGOAVeFdaWFwFTLeS7joMZSdYtGrn/iDFLBbihNeXakFSpIy6UGrecetU0a1bhGhmhYur/DESHJXlqHToVtrfh9TVYqxWljtf/MGJKzDAGcwrK6k= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1593975379566193.54854490798039; Sun, 5 Jul 2020 11:56:19 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9nu-0005cI-Bq; Sun, 05 Jul 2020 18:55:54 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9ns-0005bb-O1 for xen-devel@lists.xenproject.org; Sun, 05 Jul 2020 18:55:52 +0000 Received: from bagnar.nask.net.pl (unknown [195.187.242.196]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2245c090-bef1-11ea-8c02-12813bfff9fa; Sun, 05 Jul 2020 18:55:46 +0000 (UTC) Received: from bagnar.nask.net.pl (unknown [172.16.9.10]) by bagnar.nask.net.pl (Postfix) with ESMTP id 6676BA2026; Sun, 5 Jul 2020 20:55:45 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id 58BDFA2037; Sun, 5 Jul 2020 20:55:44 +0200 (CEST) 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 1JBZVfExoyvJ; Sun, 5 Jul 2020 20:55:43 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id CC9E8A2022; Sun, 5 Jul 2020 20:55:43 +0200 (CEST) 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 Jc7SFJCbWlUJ; Sun, 5 Jul 2020 20:55:43 +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 9C06EA1F8E; Sun, 5 Jul 2020 20:55:43 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by belindir.nask.net.pl (Postfix) with ESMTP id 7F15522C30; Sun, 5 Jul 2020 20:55:13 +0200 (CEST) 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 zPrEudZ0Ce5r; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by belindir.nask.net.pl (Postfix) with ESMTP id F3DEC22C07; Sun, 5 Jul 2020 20:55:07 +0200 (CEST) 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 GaILWkwrL2jb; Sun, 5 Jul 2020 20:55:07 +0200 (CEST) Received: from mq-desktop.cert.pl (unknown [195.187.238.217]) by belindir.nask.net.pl (Postfix) with ESMTPSA id CD5B322BF3; Sun, 5 Jul 2020 20:55:07 +0200 (CEST) X-Inumbo-ID: 2245c090-bef1-11ea-8c02-12813bfff9fa X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Virus-Scanned: amavisd-new at bagnar.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Quarantine-ID: X-Virus-Scanned: amavisd-new at belindir.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" From: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= To: xen-devel@lists.xenproject.org Subject: [PATCH v5 02/11] x86/vmx: add Intel PT MSR definitions Date: Sun, 5 Jul 2020 20:54:55 +0200 Message-Id: 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, Wei Liu , Andrew Cooper , Michal Leszczynski , Jan Beulich , tamas.lengyel@intel.com, =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michal Leszczynski Define constants related to Intel Processor Trace features. Signed-off-by: Michal Leszczynski Acked-by: Andrew Cooper --- xen/include/asm-x86/msr-index.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/xen/include/asm-x86/msr-index.h b/xen/include/asm-x86/msr-inde= x.h index 0fe98af923..4fd54fb5c9 100644 --- a/xen/include/asm-x86/msr-index.h +++ b/xen/include/asm-x86/msr-index.h @@ -72,7 +72,31 @@ #define MSR_RTIT_OUTPUT_BASE 0x00000560 #define MSR_RTIT_OUTPUT_MASK 0x00000561 #define MSR_RTIT_CTL 0x00000570 +#define RTIT_CTL_TRACE_EN (_AC(1, ULL) << 0) +#define RTIT_CTL_CYC_EN (_AC(1, ULL) << 1) +#define RTIT_CTL_OS (_AC(1, ULL) << 2) +#define RTIT_CTL_USR (_AC(1, ULL) << 3) +#define RTIT_CTL_PWR_EVT_EN (_AC(1, ULL) << 4) +#define RTIT_CTL_FUP_ON_PTW (_AC(1, ULL) << 5) +#define RTIT_CTL_FABRIC_EN (_AC(1, ULL) << 6) +#define RTIT_CTL_CR3_FILTER (_AC(1, ULL) << 7) +#define RTIT_CTL_TOPA (_AC(1, ULL) << 8) +#define RTIT_CTL_MTC_EN (_AC(1, ULL) << 9) +#define RTIT_CTL_TSC_EN (_AC(1, ULL) << 10) +#define RTIT_CTL_DIS_RETC (_AC(1, ULL) << 11) +#define RTIT_CTL_PTW_EN (_AC(1, ULL) << 12) +#define RTIT_CTL_BRANCH_EN (_AC(1, ULL) << 13) +#define RTIT_CTL_MTC_FREQ (_AC(0xf, ULL) << 14) +#define RTIT_CTL_CYC_THRESH (_AC(0xf, ULL) << 19) +#define RTIT_CTL_PSB_FREQ (_AC(0xf, ULL) << 24) +#define RTIT_CTL_ADDR(n) (_AC(0xf, ULL) << (32 + 4 * (n= ))) #define MSR_RTIT_STATUS 0x00000571 +#define RTIT_STATUS_FILTER_EN (_AC(1, ULL) << 0) +#define RTIT_STATUS_CONTEXT_EN (_AC(1, ULL) << 1) +#define RTIT_STATUS_TRIGGER_EN (_AC(1, ULL) << 2) +#define RTIT_STATUS_ERROR (_AC(1, ULL) << 4) +#define RTIT_STATUS_STOPPED (_AC(1, ULL) << 5) +#define RTIT_STATUS_BYTECNT (_AC(0x1ffff, ULL) << 32) #define MSR_RTIT_CR3_MATCH 0x00000572 #define MSR_RTIT_ADDR_A(n) (0x00000580 + (n) * 2) #define MSR_RTIT_ADDR_B(n) (0x00000581 + (n) * 2) --=20 2.17.1 From nobody Mon Apr 29 12:59:10 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; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1593975379; cv=none; d=zohomail.com; s=zohoarc; b=DhN7+LBDxtgNpGpt1DrlfAEFgLfYUoLjjzYlwX2ygExIfILoSNzY6yKFKw5u+tgOkpUXDM1+oYEGT6Kf/kRwhR6m2ubpsfWYdQrnG+ruBVksuIS92ek24RFOlMFuSM8LhtLGN40YCK8Lp46MX+BcaXL2imTRvbgKEKpml5a1HEo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593975379; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=P6Ro8KtbBtok8lDKxy4v7s6TbBzEx6TjNOrlWFM3yrY=; b=WCwgIONFx1JrunzI57jdoUpepiY8EjI+FflGGoe8yZ5AhFVwdm95EbA7EisBvOu6nHMNKhzXrf8ambrGcHKy2WJLU6yMaLtYhB2ZAq5Y3Rg2Ow+2eqRtsuCTSlJq6X5EhPpCtMGLEcvJ91alF6wT0iDETkE16/TIz55LCvQcsRI= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1593975379403754.5584088291719; Sun, 5 Jul 2020 11:56:19 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9nu-0005cQ-KD; Sun, 05 Jul 2020 18:55:54 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9ns-0005bc-Ut for xen-devel@lists.xenproject.org; Sun, 05 Jul 2020 18:55:52 +0000 Received: from bagnar.nask.net.pl (unknown [195.187.242.196]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 226f4e06-bef1-11ea-bca7-bc764e2007e4; Sun, 05 Jul 2020 18:55:46 +0000 (UTC) Received: from bagnar.nask.net.pl (unknown [172.16.9.10]) by bagnar.nask.net.pl (Postfix) with ESMTP id D28CBA1F8E; Sun, 5 Jul 2020 20:55:45 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id BFC7FA201B; Sun, 5 Jul 2020 20:55:44 +0200 (CEST) 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 bsOg5AyN26K4; Sun, 5 Jul 2020 20:55:44 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id 20123A202C; Sun, 5 Jul 2020 20:55:44 +0200 (CEST) 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 EPRksHIMDsRv; Sun, 5 Jul 2020 20:55:44 +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 DF3ADA2026; Sun, 5 Jul 2020 20:55:43 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by belindir.nask.net.pl (Postfix) with ESMTP id CDF0622C31; Sun, 5 Jul 2020 20:55:13 +0200 (CEST) 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 3yV87tbjOx0a; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by belindir.nask.net.pl (Postfix) with ESMTP id 134B322C0A; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) 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 Yo09Q0eUjxyb; Sun, 5 Jul 2020 20:55:07 +0200 (CEST) Received: from mq-desktop.cert.pl (unknown [195.187.238.217]) by belindir.nask.net.pl (Postfix) with ESMTPSA id D88CA22BFF; Sun, 5 Jul 2020 20:55:07 +0200 (CEST) X-Inumbo-ID: 226f4e06-bef1-11ea-bca7-bc764e2007e4 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Virus-Scanned: amavisd-new at bagnar.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Quarantine-ID: X-Virus-Scanned: amavisd-new at belindir.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" From: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= To: xen-devel@lists.xenproject.org Subject: [PATCH v5 03/11] x86/vmx: add IPT cpu feature Date: Sun, 5 Jul 2020 20:54:56 +0200 Message-Id: <4d6eac657d082efaa0e7d141b5c9a07791b31f94.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: Julien Grall , Kevin Tian , Stefano Stabellini , luwei.kang@intel.com, Jun Nakajima , Wei Liu , Andrew Cooper , Michal Leszczynski , Ian Jackson , George Dunlap , Jan Beulich , tamas.lengyel@intel.com, =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michal Leszczynski Check if Intel Processor Trace feature is supported by current processor. Define vmtrace_supported global variable. Signed-off-by: Michal Leszczynski --- xen/arch/x86/hvm/vmx/vmcs.c | 15 ++++++++++++++- xen/common/domain.c | 2 ++ xen/include/asm-x86/cpufeature.h | 1 + xen/include/asm-x86/hvm/vmx/vmcs.h | 1 + xen/include/public/arch-x86/cpufeatureset.h | 1 + xen/include/xen/domain.h | 2 ++ 6 files changed, 21 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/hvm/vmx/vmcs.c b/xen/arch/x86/hvm/vmx/vmcs.c index ca94c2bedc..3a53553f10 100644 --- a/xen/arch/x86/hvm/vmx/vmcs.c +++ b/xen/arch/x86/hvm/vmx/vmcs.c @@ -291,6 +291,20 @@ static int vmx_init_vmcs_config(void) _vmx_cpu_based_exec_control &=3D ~(CPU_BASED_CR8_LOAD_EXITING | CPU_BASED_CR8_STORE_EXITING); =20 + rdmsrl(MSR_IA32_VMX_MISC, _vmx_misc_cap); + + /* Check whether IPT is supported in VMX operation. */ + if ( !smp_processor_id() ) + vmtrace_supported =3D cpu_has_ipt && + (_vmx_misc_cap & VMX_MISC_PROC_TRACE); + else if ( vmtrace_supported && + !(_vmx_misc_cap & VMX_MISC_PROC_TRACE) ) + { + printk("VMX: IPT capabilities fatally differ between CPU%u and CPU= 0\n", + smp_processor_id()); + return -EINVAL; + } + if ( _vmx_cpu_based_exec_control & CPU_BASED_ACTIVATE_SECONDARY_CONTRO= LS ) { min =3D 0; @@ -305,7 +319,6 @@ static int vmx_init_vmcs_config(void) SECONDARY_EXEC_ENABLE_VIRT_EXCEPTIONS | SECONDARY_EXEC_XSAVES | SECONDARY_EXEC_TSC_SCALING); - rdmsrl(MSR_IA32_VMX_MISC, _vmx_misc_cap); if ( _vmx_misc_cap & VMX_MISC_VMWRITE_ALL ) opt |=3D SECONDARY_EXEC_ENABLE_VMCS_SHADOWING; if ( opt_vpid_enabled ) diff --git a/xen/common/domain.c b/xen/common/domain.c index 7cc9526139..a45cf023f7 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -82,6 +82,8 @@ struct vcpu *idle_vcpu[NR_CPUS] __read_mostly; =20 vcpu_info_t dummy_vcpu_info; =20 +bool vmtrace_supported __read_mostly; + static void __domain_finalise_shutdown(struct domain *d) { struct vcpu *v; diff --git a/xen/include/asm-x86/cpufeature.h b/xen/include/asm-x86/cpufeat= ure.h index f790d5c1f8..555f696a26 100644 --- a/xen/include/asm-x86/cpufeature.h +++ b/xen/include/asm-x86/cpufeature.h @@ -104,6 +104,7 @@ #define cpu_has_clwb boot_cpu_has(X86_FEATURE_CLWB) #define cpu_has_avx512er boot_cpu_has(X86_FEATURE_AVX512ER) #define cpu_has_avx512cd boot_cpu_has(X86_FEATURE_AVX512CD) +#define cpu_has_ipt boot_cpu_has(X86_FEATURE_PROC_TRACE) #define cpu_has_sha boot_cpu_has(X86_FEATURE_SHA) #define cpu_has_avx512bw boot_cpu_has(X86_FEATURE_AVX512BW) #define cpu_has_avx512vl boot_cpu_has(X86_FEATURE_AVX512VL) diff --git a/xen/include/asm-x86/hvm/vmx/vmcs.h b/xen/include/asm-x86/hvm/v= mx/vmcs.h index 906810592f..6153ba6769 100644 --- a/xen/include/asm-x86/hvm/vmx/vmcs.h +++ b/xen/include/asm-x86/hvm/vmx/vmcs.h @@ -283,6 +283,7 @@ extern u32 vmx_secondary_exec_control; #define VMX_VPID_INVVPID_SINGLE_CONTEXT_RETAINING_GLOBAL 0x80000000000ULL extern u64 vmx_ept_vpid_cap; =20 +#define VMX_MISC_PROC_TRACE 0x00004000 #define VMX_MISC_CR3_TARGET 0x01ff0000 #define VMX_MISC_VMWRITE_ALL 0x20000000 =20 diff --git a/xen/include/public/arch-x86/cpufeatureset.h b/xen/include/publ= ic/arch-x86/cpufeatureset.h index fe7492a225..2c91862f2d 100644 --- a/xen/include/public/arch-x86/cpufeatureset.h +++ b/xen/include/public/arch-x86/cpufeatureset.h @@ -217,6 +217,7 @@ XEN_CPUFEATURE(SMAP, 5*32+20) /*S Supervisor = Mode Access Prevention */ XEN_CPUFEATURE(AVX512_IFMA, 5*32+21) /*A AVX-512 Integer Fused Multiply= Add */ XEN_CPUFEATURE(CLFLUSHOPT, 5*32+23) /*A CLFLUSHOPT instruction */ XEN_CPUFEATURE(CLWB, 5*32+24) /*A CLWB instruction */ +XEN_CPUFEATURE(PROC_TRACE, 5*32+25) /* Processor Tracing feature */ XEN_CPUFEATURE(AVX512PF, 5*32+26) /*A AVX-512 Prefetch Instructions = */ XEN_CPUFEATURE(AVX512ER, 5*32+27) /*A AVX-512 Exponent & Reciprocal = Instrs */ XEN_CPUFEATURE(AVX512CD, 5*32+28) /*A AVX-512 Conflict Detection Ins= trs */ diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 7e51d361de..61ebc6c24d 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -130,4 +130,6 @@ struct vnuma_info { =20 void vnuma_destroy(struct vnuma_info *vnuma); =20 +extern bool vmtrace_supported; + #endif /* __XEN_DOMAIN_H__ */ --=20 2.17.1 From nobody Mon Apr 29 12:59:10 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; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1593975378; cv=none; d=zohomail.com; s=zohoarc; b=Y0KfxuQJnrf99ulzpUcJhMz7YNovgbgrliGghFxV+WWL9FMOpvyBKun/EEhnKv5qpRRBIJ/TIFOwG1qMYbXrQ3cres0pVxahIbLEIpsOznxcbTNLgymCmH/ORp9kefHdfWGgBBjMhZF2FWTcPcL2YnkT5Uh6eL1Y8bmCA65fsKE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593975378; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=O32IsnVcc3FjMtEYrZdirG7uTxC56WhP8jif0WoUXeE=; b=EEhZLQj9gVlR0Aee9COIHgQd+GnVBoy2Q6Yj9C+I9wNJvgnOwPXAA5F+NFkC0FclWSIJm3wREy6rZJY5ibSVm4OAdXihs48xVMERBM4gKmaTpJp7EVR4NFeJLqbayk+1+pkqUCQX/4cBl6ZE65DXuMmmv+lKDXKPgZp5n0BikYk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1593975378468522.7062880948039; Sun, 5 Jul 2020 11:56:18 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9no-0005bl-S5; Sun, 05 Jul 2020 18:55:48 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9nn-0005bb-Sy for xen-devel@lists.xenproject.org; Sun, 05 Jul 2020 18:55:47 +0000 Received: from bagnar.nask.net.pl (unknown [195.187.242.196]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2245a02e-bef1-11ea-8c02-12813bfff9fa; Sun, 05 Jul 2020 18:55:46 +0000 (UTC) Received: from bagnar.nask.net.pl (unknown [172.16.9.10]) by bagnar.nask.net.pl (Postfix) with ESMTP id 7B4FCA2046; Sun, 5 Jul 2020 20:55:45 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id 71C8EA203D; Sun, 5 Jul 2020 20:55:44 +0200 (CEST) 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 LpZ0XIP1sjKn; Sun, 5 Jul 2020 20:55:44 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id EDFC8A1F8E; Sun, 5 Jul 2020 20:55:43 +0200 (CEST) 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 arBBim_pQi6z; Sun, 5 Jul 2020 20:55:43 +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 B14CFA1FE9; Sun, 5 Jul 2020 20:55:43 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by belindir.nask.net.pl (Postfix) with ESMTP id 9D6C822C09; Sun, 5 Jul 2020 20:55:13 +0200 (CEST) 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 IIeWzElhpfKb; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by belindir.nask.net.pl (Postfix) with ESMTP id 27D5422C11; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) 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 U7Rxn7a5967L; 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 EDAC622C06; Sun, 5 Jul 2020 20:55:07 +0200 (CEST) X-Inumbo-ID: 2245a02e-bef1-11ea-8c02-12813bfff9fa X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Virus-Scanned: amavisd-new at bagnar.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Quarantine-ID: X-Virus-Scanned: amavisd-new at belindir.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" From: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= To: xen-devel@lists.xenproject.org Subject: [PATCH v5 04/11] common: add vmtrace_pt_size domain parameter Date: Sun, 5 Jul 2020 20:54:57 +0200 Message-Id: <5d52b37e391a4165dc3775f77a621d34a33d22c2.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: Julien Grall , Stefano Stabellini , luwei.kang@intel.com, Wei Liu , Andrew Cooper , Michal Leszczynski , Ian Jackson , George Dunlap , Jan Beulich , tamas.lengyel@intel.com Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michal Leszczynski Add vmtrace_pt_size domain parameter in live domain and vmtrace_pt_order parameter in xen_domctl_createdomain. Signed-off-by: Michal Leszczynski --- xen/common/domain.c | 12 ++++++++++++ xen/include/public/domctl.h | 1 + xen/include/xen/sched.h | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/xen/common/domain.c b/xen/common/domain.c index a45cf023f7..25d3359c5b 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -338,6 +338,12 @@ static int sanitise_domain_config(struct xen_domctl_cr= eatedomain *config) return -EINVAL; } =20 + if ( config->vmtrace_pt_order && !vmtrace_supported ) + { + dprintk(XENLOG_INFO, "Processor tracing is not supported\n"); + return -EINVAL; + } + return arch_sanitise_domain_config(config); } =20 @@ -443,6 +449,12 @@ struct domain *domain_create(domid_t domid, d->nr_pirqs =3D min(d->nr_pirqs, nr_irqs); =20 radix_tree_init(&d->pirq_tree); + + if ( config->vmtrace_pt_order ) + { + uint32_t shift_val =3D config->vmtrace_pt_order + PAGE_SHIFT; + d->vmtrace_pt_size =3D (1ULL << shift_val); + } } =20 if ( (err =3D arch_domain_create(d, config)) !=3D 0 ) diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 59bdc28c89..7b8289d436 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -92,6 +92,7 @@ struct xen_domctl_createdomain { uint32_t max_evtchn_port; int32_t max_grant_frames; int32_t max_maptrack_frames; + uint8_t vmtrace_pt_order; =20 struct xen_arch_domainconfig arch; }; diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index ac53519d7f..48f0a61bbd 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -457,6 +457,10 @@ struct domain unsigned pbuf_idx; spinlock_t pbuf_lock; =20 + /* Used by vmtrace features */ + spinlock_t vmtrace_lock; + uint64_t vmtrace_pt_size; + /* OProfile support. */ struct xenoprof *xenoprof; =20 --=20 2.17.1 From nobody Mon Apr 29 12:59:10 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; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1593975399; cv=none; d=zohomail.com; s=zohoarc; b=J6ZGgwTLweOz5RWPoS6zq53jjCEEQM2DyWbzTx2GlXJTysp2/2s6757DGLkFNhvLIFaWngLLbthaez9m7sO1UC+OJKNZ0g077Va34lED+eoDZp+XBktjnBvnehqZ09XaS5G5jmiIBWfy6aodVo3qsNlJCzd/lLsJSsg2Cz5LO1s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593975399; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=vBgeJefaZwechG0z9jlEt8fxaIOjB3U9ofRPqi81ENk=; b=VLF23PamkAoL6Zc2uR4oe+gdcyWgVUXeleKtLE4TEufiVrfWSZwuy2b4CJGZGOUd44897RgyhF2Yqri1myWfL3j6G2DZt+MT87RrLq3/SRCpnqutWGF+BDxyiF4RsAG5cp8qXsaxN9+MPEGxCmChb7PN0O97QHG5CHvwzl0ujTg= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1593975399399327.83294488006777; Sun, 5 Jul 2020 11:56:39 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9oL-0005mp-IV; Sun, 05 Jul 2020 18:56:21 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9oK-0005mD-IN for xen-devel@lists.xenproject.org; Sun, 05 Jul 2020 18:56:20 +0000 Received: from bagnar.nask.net.pl (unknown [195.187.242.196]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 35a11d89-bef1-11ea-8c04-12813bfff9fa; Sun, 05 Jul 2020 18:56:19 +0000 (UTC) Received: from bagnar.nask.net.pl (unknown [172.16.9.10]) by bagnar.nask.net.pl (Postfix) with ESMTP id 97F0EA2022; Sun, 5 Jul 2020 20:56:16 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id 95673A2026; Sun, 5 Jul 2020 20:56:15 +0200 (CEST) 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 c23W13ESr3r9; Sun, 5 Jul 2020 20:56:14 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id 7FDC7A2052; Sun, 5 Jul 2020 20:56:14 +0200 (CEST) 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 isgh7PHF9bSH; 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 C27ACA2022; Sun, 5 Jul 2020 20:56:13 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by belindir.nask.net.pl (Postfix) with ESMTP id 29CF622C3D; Sun, 5 Jul 2020 20:55:19 +0200 (CEST) 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 CrPYSZmT-5fP; 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 3B5CF22C06; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) 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 Rz3LuF7Dh33H; 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 0D31A2295A; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) X-Inumbo-ID: 35a11d89-bef1-11ea-8c04-12813bfff9fa X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Virus-Scanned: amavisd-new at bagnar.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Quarantine-ID: X-Virus-Scanned: amavisd-new at belindir.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" From: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= To: xen-devel@lists.xenproject.org Subject: [PATCH v5 05/11] tools/libxl: add vmtrace_pt_size parameter Date: Sun, 5 Jul 2020 20:54:58 +0200 Message-Id: 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, Wei Liu , Michal Leszczynski , Ian Jackson , George Dunlap , Anthony PERARD , tamas.lengyel@intel.com Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michal Leszczynski Allow to specify the size of per-vCPU trace buffer upon domain creation. This is zero by default (meaning: not enabled). Signed-off-by: Michal Leszczynski --- docs/man/xl.cfg.5.pod.in | 11 +++++++++++ tools/golang/xenlight/helpers.gen.go | 2 ++ tools/golang/xenlight/types.gen.go | 1 + tools/libxl/libxl.h | 8 ++++++++ tools/libxl/libxl_create.c | 1 + tools/libxl/libxl_types.idl | 2 ++ tools/xl/xl_parse.c | 22 ++++++++++++++++++++++ 7 files changed, 47 insertions(+) diff --git a/docs/man/xl.cfg.5.pod.in b/docs/man/xl.cfg.5.pod.in index 0532739c1f..670759f6bd 100644 --- a/docs/man/xl.cfg.5.pod.in +++ b/docs/man/xl.cfg.5.pod.in @@ -278,6 +278,17 @@ memory=3D8096 will report significantly less memory av= ailable for use than a system with maxmem=3D8096 memory=3D8096 due to the memory overhead of having to track the unused pages. =20 +=3Ditem B + +Specifies the size of processor trace buffer that would be allocated +for each vCPU belonging to this domain. Disabled (i.e. +B by default. This must be set to +non-zero value in order to be able to use processor tracing features +with this domain. + +B: The size value must be between 4 kB and 4 GB and it must +be also a power of 2. + =3Dback =20 =3Dhead3 Guest Virtual NUMA Configuration diff --git a/tools/golang/xenlight/helpers.gen.go b/tools/golang/xenlight/h= elpers.gen.go index 152c7e8e6b..bfc37b69c8 100644 --- a/tools/golang/xenlight/helpers.gen.go +++ b/tools/golang/xenlight/helpers.gen.go @@ -1117,6 +1117,7 @@ return fmt.Errorf("invalid union key '%v'", x.Type)} x.ArchArm.GicVersion =3D GicVersion(xc.arch_arm.gic_version) x.ArchArm.Vuart =3D VuartType(xc.arch_arm.vuart) x.Altp2M =3D Altp2MMode(xc.altp2m) +x.VmtracePtOrder =3D int(xc.vmtrace_pt_order) =20 return nil} =20 @@ -1592,6 +1593,7 @@ return fmt.Errorf("invalid union key '%v'", x.Type)} xc.arch_arm.gic_version =3D C.libxl_gic_version(x.ArchArm.GicVersion) xc.arch_arm.vuart =3D C.libxl_vuart_type(x.ArchArm.Vuart) xc.altp2m =3D C.libxl_altp2m_mode(x.Altp2M) +xc.vmtrace_pt_order =3D C.int(x.VmtracePtOrder) =20 return nil } diff --git a/tools/golang/xenlight/types.gen.go b/tools/golang/xenlight/typ= es.gen.go index 663c1e86b4..f9b07ac862 100644 --- a/tools/golang/xenlight/types.gen.go +++ b/tools/golang/xenlight/types.gen.go @@ -516,6 +516,7 @@ GicVersion GicVersion Vuart VuartType } Altp2M Altp2MMode +VmtracePtOrder int } =20 type domainBuildInfoTypeUnion interface { diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 1cd6c38e83..4abb521756 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -438,6 +438,14 @@ */ #define LIBXL_HAVE_CREATEINFO_PASSTHROUGH 1 =20 +/* + * LIBXL_HAVE_VMTRACE_PT_ORDER indicates that + * libxl_domain_create_info has a vmtrace_pt_order parameter, which + * allows to enable pre-allocation of processor tracing buffers + * with the given order of size. + */ +#define LIBXL_HAVE_VMTRACE_PT_ORDER 1 + /* * libxl ABI compatibility * diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 2814818e34..82b595161a 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -608,6 +608,7 @@ int libxl__domain_make(libxl__gc *gc, libxl_domain_conf= ig *d_config, .max_evtchn_port =3D b_info->event_channels, .max_grant_frames =3D b_info->max_grant_frames, .max_maptrack_frames =3D b_info->max_maptrack_frames, + .vmtrace_pt_order =3D b_info->vmtrace_pt_order, }; =20 if (info->type !=3D LIBXL_DOMAIN_TYPE_PV) { diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index 9d3f05f399..1c5dd43e4d 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -645,6 +645,8 @@ libxl_domain_build_info =3D Struct("domain_build_info",[ # supported by x86 HVM and ARM support is planned. ("altp2m", libxl_altp2m_mode), =20 + ("vmtrace_pt_order", integer), + ], dir=3DDIR_IN, copy_deprecated_fn=3D"libxl__domain_build_info_copy_deprecated", ) diff --git a/tools/xl/xl_parse.c b/tools/xl/xl_parse.c index 61b4ef7b7e..279f7c14d3 100644 --- a/tools/xl/xl_parse.c +++ b/tools/xl/xl_parse.c @@ -1861,6 +1861,28 @@ void parse_config_data(const char *config_source, } } =20 + if (!xlu_cfg_get_long(config, "processor_trace_buffer_size", &l, 1) &&= l) { + int32_t shift =3D 0; + + if (l & (l - 1)) + { + fprintf(stderr, "ERROR: processor_trace_buffer_size " + "- must be a power of 2\n"); + exit(1); + } + + while (l >>=3D 1) ++shift; + + if (shift <=3D XEN_PAGE_SHIFT) + { + fprintf(stderr, "ERROR: processor_trace_buffer_size " + "- value is too small\n"); + exit(1); + } + + b_info->vmtrace_pt_order =3D shift - XEN_PAGE_SHIFT; + } + if (!xlu_cfg_get_list(config, "ioports", &ioports, &num_ioports, 0)) { b_info->num_ioports =3D num_ioports; b_info->ioports =3D calloc(num_ioports, sizeof(*b_info->ioports)); --=20 2.17.1 From nobody Mon Apr 29 12:59:10 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; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1593975411; cv=none; d=zohomail.com; s=zohoarc; b=Qf+U4Elk5rb6orIlqjCG7w89gt1RSNMNMiHw9a2IDmJJw1DtDEkeJ7HIozuSskcHETJpju325zaKzCfI5BSWy45O985saQiYYuaDIK5Hdu7C5et2Wignav6C6gdyvdicpvPws3WSKdRcVZPLnKhTNlRXWfx07AU6EnMdETw4asE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593975411; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=psrkUDyhi6V3oYaTzjDk7NwZT3bKQNSjbY9mbwpsFOU=; b=JJjUDYNhmfnaWOxGPSoAxbF8BFYH/QIL7nzT9e6rqJbRFt+IoYSTFmylws6QV9pRekcL0zAFg0/ttIPOYObTKspFFepEyTyff41P++qZAXrpqsJhoBabKE5UX88ot+B/2ZucY3oZ15jB8CMvjppvd1HQ3t52EvEbug8cza0p750= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1593975411095167.8634686919512; Sun, 5 Jul 2020 11:56:51 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9ob-0005zS-1T; Sun, 05 Jul 2020 18:56:37 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9oY-0005m2-VY for xen-devel@lists.xenproject.org; Sun, 05 Jul 2020 18:56:35 +0000 Received: from bagnar.nask.net.pl (unknown [195.187.242.196]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 37200200-bef1-11ea-bb8b-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 A51CAA20CC; Sun, 5 Jul 2020 20:56:16 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id A272FA2037; Sun, 5 Jul 2020 20:56:15 +0200 (CEST) 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 MPZIYhkmTYT3; 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 8DFEBA2058; Sun, 5 Jul 2020 20:56:14 +0200 (CEST) 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 eFOoYfuRpihs; 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 AFA8DA201B; Sun, 5 Jul 2020 20:56:13 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by belindir.nask.net.pl (Postfix) with ESMTP id 1DC0522C1E; Sun, 5 Jul 2020 20:55:19 +0200 (CEST) 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 WWYAtzNBoRq6; 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 58FF622C12; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) 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 aOEGDFEWHkIY; 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 2236B22C0B; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) X-Inumbo-ID: 37200200-bef1-11ea-bb8b-bc764e2007e4 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Virus-Scanned: amavisd-new at bagnar.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Quarantine-ID: X-Virus-Scanned: amavisd-new at belindir.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" From: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= To: xen-devel@lists.xenproject.org Subject: [PATCH v5 06/11] x86/hvm: processor trace interface in HVM Date: Sun, 5 Jul 2020 20:54:59 +0200 Message-Id: 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: Julien Grall , Stefano Stabellini , luwei.kang@intel.com, Wei Liu , Andrew Cooper , Michal Leszczynski , Ian Jackson , George Dunlap , Jan Beulich , tamas.lengyel@intel.com, =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michal Leszczynski Implement necessary changes in common code/HVM to support processor trace features. Define vmtrace_pt_* API and implement trace buffer allocation/deallocation in common code. Signed-off-by: Michal Leszczynski --- xen/arch/x86/domain.c | 19 +++++++++++++++++++ xen/common/domain.c | 19 +++++++++++++++++++ xen/include/asm-x86/hvm/hvm.h | 20 ++++++++++++++++++++ xen/include/xen/sched.h | 4 ++++ 4 files changed, 62 insertions(+) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index fee6c3931a..79c9794408 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -2199,6 +2199,25 @@ int domain_relinquish_resources(struct domain *d) altp2m_vcpu_disable_ve(v); } =20 + for_each_vcpu ( d, v ) + { + unsigned int i; + + if ( !v->vmtrace.pt_buf ) + continue; + + for ( i =3D 0; i < (v->domain->vmtrace_pt_size >> PAGE_SHIFT);= i++ ) + { + struct page_info *pg =3D mfn_to_page( + mfn_add(page_to_mfn(v->vmtrace.pt_buf), i)); + if ( (pg->count_info & PGC_count_mask) !=3D 1 ) + return -EBUSY; + } + + free_domheap_pages(v->vmtrace.pt_buf, + get_order_from_bytes(v->domain->vmtrace_pt_size)); + } + if ( is_pv_domain(d) ) { for_each_vcpu ( d, v ) diff --git a/xen/common/domain.c b/xen/common/domain.c index 25d3359c5b..f480c4e033 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -137,6 +137,21 @@ static void vcpu_destroy(struct vcpu *v) free_vcpu_struct(v); } =20 +static int vmtrace_alloc_buffers(struct vcpu *v) +{ + struct page_info *pg; + uint64_t size =3D v->domain->vmtrace_pt_size; + + pg =3D alloc_domheap_pages(v->domain, get_order_from_bytes(size), + MEMF_no_refcount); + + if ( !pg ) + return -ENOMEM; + + v->vmtrace.pt_buf =3D pg; + return 0; +} + struct vcpu *vcpu_create(struct domain *d, unsigned int vcpu_id) { struct vcpu *v; @@ -162,6 +177,9 @@ struct vcpu *vcpu_create(struct domain *d, unsigned int= vcpu_id) v->vcpu_id =3D vcpu_id; v->dirty_cpu =3D VCPU_CPU_CLEAN; =20 + if ( d->vmtrace_pt_size && vmtrace_alloc_buffers(v) !=3D 0 ) + return NULL; + spin_lock_init(&v->virq_lock); =20 tasklet_init(&v->continue_hypercall_tasklet, NULL, NULL); @@ -422,6 +440,7 @@ struct domain *domain_create(domid_t domid, d->shutdown_code =3D SHUTDOWN_CODE_INVALID; =20 spin_lock_init(&d->pbuf_lock); + spin_lock_init(&d->vmtrace_lock); =20 rwlock_init(&d->vnuma_rwlock); =20 diff --git a/xen/include/asm-x86/hvm/hvm.h b/xen/include/asm-x86/hvm/hvm.h index 1eb377dd82..2d474a4c50 100644 --- a/xen/include/asm-x86/hvm/hvm.h +++ b/xen/include/asm-x86/hvm/hvm.h @@ -214,6 +214,10 @@ struct hvm_function_table { bool_t (*altp2m_vcpu_emulate_ve)(struct vcpu *v); int (*altp2m_vcpu_emulate_vmfunc)(const struct cpu_user_regs *regs); =20 + /* vmtrace */ + int (*vmtrace_control_pt)(struct vcpu *v, bool enable); + int (*vmtrace_get_pt_offset)(struct vcpu *v, uint64_t *offset); + /* * Parameters and callbacks for hardware-assisted TSC scaling, * which are valid only when the hardware feature is available. @@ -655,6 +659,22 @@ static inline bool altp2m_vcpu_emulate_ve(struct vcpu = *v) return false; } =20 +static inline int vmtrace_control_pt(struct vcpu *v, bool enable) +{ + if ( hvm_funcs.vmtrace_control_pt ) + return hvm_funcs.vmtrace_control_pt(v, enable); + + return -EOPNOTSUPP; +} + +static inline int vmtrace_get_pt_offset(struct vcpu *v, uint64_t *offset) +{ + if ( hvm_funcs.vmtrace_get_pt_offset ) + return hvm_funcs.vmtrace_get_pt_offset(v, offset); + + return -EOPNOTSUPP; +} + /* * This must be defined as a macro instead of an inline function, * because it uses 'struct vcpu' and 'struct domain' which have diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index 48f0a61bbd..95ebab0d30 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -253,6 +253,10 @@ struct vcpu /* vPCI per-vCPU area, used to store data for long running operations.= */ struct vpci_vcpu vpci; =20 + struct { + struct page_info *pt_buf; + } vmtrace; + struct arch_vcpu arch; }; =20 --=20 2.17.1 From nobody Mon Apr 29 12:59:10 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; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1593975401; cv=none; d=zohomail.com; s=zohoarc; b=OKMUDnaTVQBYnLcYtCRyRM3fqvQkUEZM4lgBAGfDqG7Z4NCHfzntrBpavmfVahuv+6cjvqmwJmsuKqfoZMk0s2qzgFc8N1q/+5t3nIbHqrdrfoz0wVYwKI6kGmyfjh19ivVn9AZiR+CgMKwCvbDCz8hISQzc5s+5sV8Rw6BS6W0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593975401; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=2agf85PG4AT7yqNpCeunM2btaNgbJ7/to0iXI6/Acw0=; b=mdhSIc8fNY1JdpA5AXqxuTlV2a2G26tFW7AAIbxHBw2d7aQ++C7oc82+1WRVN7Zhnqxp9bOscviwhzNpr0OI8VzMlA/hTJ7cdgqVrLRWI84aZImZ9wDmZTSx5iad+iKcm2w7iFBwRN22dF33dJpsQdVoOhJmwGl675GULhYI6gU= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1593975401750972.654279271221; Sun, 5 Jul 2020 11:56:41 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9oR-0005qK-6f; Sun, 05 Jul 2020 18:56:27 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9oP-0005mD-Gu for xen-devel@lists.xenproject.org; Sun, 05 Jul 2020 18:56:25 +0000 Received: from bagnar.nask.net.pl (unknown [195.187.242.196]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 37249a22-bef1-11ea-8c04-12813bfff9fa; 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 3A8DBA2037; Sun, 5 Jul 2020 20:56:19 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id 4FF6FA20C9; Sun, 5 Jul 2020 20:56:16 +0200 (CEST) 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 B_BcBFl6ja6D; 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 305A0A2022; Sun, 5 Jul 2020 20:56:15 +0200 (CEST) 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 k5rmcILqT4aJ; Sun, 5 Jul 2020 20:56:15 +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 1E197A203D; 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 5A35022C20; Sun, 5 Jul 2020 20:55:19 +0200 (CEST) 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 iL-0WfZ8YBhL; 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 6ADBF22C0B; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) 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 NHfE5Sz6ftCE; 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 3CB5622C0C; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) X-Inumbo-ID: 37249a22-bef1-11ea-8c04-12813bfff9fa X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Virus-Scanned: amavisd-new at bagnar.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Quarantine-ID: X-Virus-Scanned: amavisd-new at belindir.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" From: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= To: xen-devel@lists.xenproject.org Subject: [PATCH v5 07/11] x86/vmx: implement IPT in VMX Date: Sun, 5 Jul 2020 20:55:00 +0200 Message-Id: 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: Kevin Tian , luwei.kang@intel.com, Jun Nakajima , Wei Liu , Andrew Cooper , Michal Leszczynski , Jan Beulich , tamas.lengyel@intel.com, =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michal Leszczynski Use Intel Processor Trace feature to provide vmtrace_pt_* interface for HVM/VMX. Signed-off-by: Michal Leszczynski --- xen/arch/x86/hvm/vmx/vmx.c | 109 +++++++++++++++++++++++++++++ xen/include/asm-x86/hvm/vmx/vmcs.h | 3 + xen/include/asm-x86/hvm/vmx/vmx.h | 14 ++++ 3 files changed, 126 insertions(+) diff --git a/xen/arch/x86/hvm/vmx/vmx.c b/xen/arch/x86/hvm/vmx/vmx.c index cc6d4ece22..4eded2ef84 100644 --- a/xen/arch/x86/hvm/vmx/vmx.c +++ b/xen/arch/x86/hvm/vmx/vmx.c @@ -428,6 +428,56 @@ static void vmx_domain_relinquish_resources(struct dom= ain *d) vmx_free_vlapic_mapping(d); } =20 +static int vmx_init_pt(struct vcpu *v) +{ + int rc; + uint64_t size =3D v->domain->vmtrace_pt_size; + + v->arch.hvm.vmx.ipt_state =3D xzalloc(struct ipt_state); + + if ( !v->arch.hvm.vmx.ipt_state ) + return -ENOMEM; + + if ( !v->vmtrace.pt_buf || !size ) + return -EINVAL; + + /* + * We don't accept trace buffer size smaller than single page + * and the upper bound is defined as 4GB in the specification. + * The buffer size must be also a power of 2. + */ + if ( size < PAGE_SIZE || size > GB(4) || (size & (size - 1)) ) + return -EINVAL; + + v->arch.hvm.vmx.ipt_state->output_base =3D + page_to_maddr(v->vmtrace.pt_buf); + v->arch.hvm.vmx.ipt_state->output_mask.raw =3D size - 1; + + rc =3D vmx_add_host_load_msr(v, MSR_RTIT_CTL, 0); + + if ( rc ) + return rc; + + rc =3D vmx_add_guest_msr(v, MSR_RTIT_CTL, + RTIT_CTL_TRACE_EN | RTIT_CTL_OS | + RTIT_CTL_USR | RTIT_CTL_BRANCH_EN); + + if ( rc ) + return rc; + + return 0; +} + +static int vmx_destroy_pt(struct vcpu* v) +{ + if ( v->arch.hvm.vmx.ipt_state ) + xfree(v->arch.hvm.vmx.ipt_state); + + v->arch.hvm.vmx.ipt_state =3D NULL; + return 0; +} + + static int vmx_vcpu_initialise(struct vcpu *v) { int rc; @@ -471,6 +521,14 @@ static int vmx_vcpu_initialise(struct vcpu *v) =20 vmx_install_vlapic_mapping(v); =20 + if ( v->domain->vmtrace_pt_size ) + { + rc =3D vmx_init_pt(v); + + if ( rc ) + return rc; + } + return 0; } =20 @@ -483,6 +541,7 @@ static void vmx_vcpu_destroy(struct vcpu *v) * prior to vmx_domain_destroy so we need to disable PML for each vcpu * separately here. */ + vmx_destroy_pt(v); vmx_vcpu_disable_pml(v); vmx_destroy_vmcs(v); passive_domain_destroy(v); @@ -513,6 +572,18 @@ static void vmx_save_guest_msrs(struct vcpu *v) * be updated at any time via SWAPGS, which we cannot trap. */ v->arch.hvm.vmx.shadow_gs =3D rdgsshadow(); + + if ( unlikely(v->arch.hvm.vmx.ipt_state && + v->arch.hvm.vmx.ipt_state->active) ) + { + uint64_t rtit_ctl; + rdmsrl(MSR_RTIT_CTL, rtit_ctl); + BUG_ON(rtit_ctl & RTIT_CTL_TRACE_EN); + + rdmsrl(MSR_RTIT_STATUS, v->arch.hvm.vmx.ipt_state->status); + rdmsrl(MSR_RTIT_OUTPUT_MASK, + v->arch.hvm.vmx.ipt_state->output_mask.raw); + } } =20 static void vmx_restore_guest_msrs(struct vcpu *v) @@ -524,6 +595,17 @@ static void vmx_restore_guest_msrs(struct vcpu *v) =20 if ( cpu_has_msr_tsc_aux ) wrmsr_tsc_aux(v->arch.msrs->tsc_aux); + + if ( unlikely(v->arch.hvm.vmx.ipt_state && + v->arch.hvm.vmx.ipt_state->active) ) + { + wrmsrl(MSR_RTIT_OUTPUT_BASE, + v->arch.hvm.vmx.ipt_state->output_base); + wrmsrl(MSR_RTIT_OUTPUT_MASK, + v->arch.hvm.vmx.ipt_state->output_mask.raw); + wrmsrl(MSR_RTIT_STATUS, + v->arch.hvm.vmx.ipt_state->status); + } } =20 void vmx_update_cpu_exec_control(struct vcpu *v) @@ -2240,6 +2322,24 @@ static bool vmx_get_pending_event(struct vcpu *v, st= ruct x86_event *info) return true; } =20 +static int vmx_control_pt(struct vcpu *v, bool enable) +{ + if ( !v->arch.hvm.vmx.ipt_state ) + return -EINVAL; + + v->arch.hvm.vmx.ipt_state->active =3D enable; + return 0; +} + +static int vmx_get_pt_offset(struct vcpu *v, uint64_t *offset) +{ + if ( !v->arch.hvm.vmx.ipt_state ) + return -EINVAL; + + *offset =3D v->arch.hvm.vmx.ipt_state->output_mask.offset; + return 0; +} + static struct hvm_function_table __initdata vmx_function_table =3D { .name =3D "VMX", .cpu_up_prepare =3D vmx_cpu_up_prepare, @@ -2295,6 +2395,8 @@ static struct hvm_function_table __initdata vmx_funct= ion_table =3D { .altp2m_vcpu_update_vmfunc_ve =3D vmx_vcpu_update_vmfunc_ve, .altp2m_vcpu_emulate_ve =3D vmx_vcpu_emulate_ve, .altp2m_vcpu_emulate_vmfunc =3D vmx_vcpu_emulate_vmfunc, + .vmtrace_control_pt =3D vmx_control_pt, + .vmtrace_get_pt_offset =3D vmx_get_pt_offset, .tsc_scaling =3D { .max_ratio =3D VMX_TSC_MULTIPLIER_MAX, }, @@ -3674,6 +3776,13 @@ void vmx_vmexit_handler(struct cpu_user_regs *regs) =20 hvm_invalidate_regs_fields(regs); =20 + if ( unlikely(v->arch.hvm.vmx.ipt_state && + v->arch.hvm.vmx.ipt_state->active) ) + { + rdmsrl(MSR_RTIT_OUTPUT_MASK, + v->arch.hvm.vmx.ipt_state->output_mask.raw); + } + if ( paging_mode_hap(v->domain) ) { /* diff --git a/xen/include/asm-x86/hvm/vmx/vmcs.h b/xen/include/asm-x86/hvm/v= mx/vmcs.h index 6153ba6769..65971fa6ad 100644 --- a/xen/include/asm-x86/hvm/vmx/vmcs.h +++ b/xen/include/asm-x86/hvm/vmx/vmcs.h @@ -186,6 +186,9 @@ struct vmx_vcpu { * pCPU and wakeup the related vCPU. */ struct pi_blocking_vcpu pi_blocking; + + /* State of processor trace feature */ + struct ipt_state *ipt_state; }; =20 int vmx_create_vmcs(struct vcpu *v); diff --git a/xen/include/asm-x86/hvm/vmx/vmx.h b/xen/include/asm-x86/hvm/vm= x/vmx.h index 111ccd7e61..8d7c67e43d 100644 --- a/xen/include/asm-x86/hvm/vmx/vmx.h +++ b/xen/include/asm-x86/hvm/vmx/vmx.h @@ -689,4 +689,18 @@ typedef union ldt_or_tr_instr_info { }; } ldt_or_tr_instr_info_t; =20 +/* Processor Trace state per vCPU */ +struct ipt_state { + bool active; + uint64_t status; + uint64_t output_base; + union { + uint64_t raw; + struct { + uint32_t size; + uint32_t offset; + }; + } output_mask; +}; + #endif /* __ASM_X86_HVM_VMX_VMX_H__ */ --=20 2.17.1 From nobody Mon Apr 29 12:59:10 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; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1593975414; cv=none; d=zohomail.com; s=zohoarc; b=Es0vYzCdP5Bz9zr8nzEoCef13qk0nJrtS8wOYrhWr0z3GdxnsWM9wzckwCm8dEb53szxok/FCDHoZF1U+tlb/xXHn9RPaoN+FJMPLp4WRdKJ1CIUii1PNiZHXrsNx6NGjbhqwuKLZSPYKnOUuJa+zkTfYX3yVuCcCtq/E44rUT0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593975414; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=qzONouutuQ1viTK2Uzwo4zfHb5sB6x46C6igzZn4H+U=; b=AtIIXz8EdxXmh/uXdegSwTSJM9qpXG2VNzSWsrlIdFh6QlKWXbixEgGj8nZy9a9vPwgQTHd76jV+sG3cgXTZ4xXCXp7QHQWyCBO7CQ2xx8zYXN3RJB33X7FU3qKKc4Mws5otOhKA66cvU7E8M0AgzW+8ofpBLzq6EC+qEAylju8= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1593975414433352.69989493998173; Sun, 5 Jul 2020 11:56:54 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9of-00062x-Br; Sun, 05 Jul 2020 18:56:41 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9od-0005m2-Vo for xen-devel@lists.xenproject.org; Sun, 05 Jul 2020 18:56:40 +0000 Received: from bagnar.nask.net.pl (unknown [195.187.242.196]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 377be142-bef1-11ea-bca7-bc764e2007e4; Sun, 05 Jul 2020 18:56:22 +0000 (UTC) Received: from bagnar.nask.net.pl (unknown [172.16.9.10]) by bagnar.nask.net.pl (Postfix) with ESMTP id 2C467A2026; Sun, 5 Jul 2020 20:56:19 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id 097FAA209C; Sun, 5 Jul 2020 20:56:15 +0200 (CEST) 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 GXBBdrOICLwb; 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 D1102A2081; Sun, 5 Jul 2020 20:56:14 +0200 (CEST) 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 xK-_YHP_09Yc; 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 AE4C1A1F8E; Sun, 5 Jul 2020 20:56:13 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by belindir.nask.net.pl (Postfix) with ESMTP id 1240F22C13; Sun, 5 Jul 2020 20:55:19 +0200 (CEST) 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 KA1JC6HJHzTN; 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 8423C22C1E; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) 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 p10_anPoB9eT; 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 538CB2295A; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) X-Inumbo-ID: 377be142-bef1-11ea-bca7-bc764e2007e4 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Virus-Scanned: amavisd-new at bagnar.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Quarantine-ID: X-Virus-Scanned: amavisd-new at belindir.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" From: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= To: xen-devel@lists.xenproject.org Subject: [PATCH v5 08/11] x86/mm: add vmtrace_buf resource type Date: Sun, 5 Jul 2020 20:55:01 +0200 Message-Id: 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: Julien Grall , Stefano Stabellini , luwei.kang@intel.com, Wei Liu , Andrew Cooper , Michal Leszczynski , Ian Jackson , George Dunlap , Jan Beulich , tamas.lengyel@intel.com Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michal Leszczynski Allow to map processor trace buffer using acquire_resource(). Signed-off-by: Michal Leszczynski --- xen/common/memory.c | 28 ++++++++++++++++++++++++++++ xen/include/public/memory.h | 1 + 2 files changed, 29 insertions(+) diff --git a/xen/common/memory.c b/xen/common/memory.c index eb42f883df..04f4e152c0 100644 --- a/xen/common/memory.c +++ b/xen/common/memory.c @@ -1007,6 +1007,29 @@ static long xatp_permission_check(struct domain *d, = unsigned int space) return xsm_add_to_physmap(XSM_TARGET, current->domain, d); } =20 +static int acquire_vmtrace_buf(struct domain *d, unsigned int id, + unsigned long frame, + unsigned int nr_frames, + xen_pfn_t mfn_list[]) +{ + mfn_t mfn; + unsigned int i; + struct vcpu *v =3D domain_vcpu(d, id); + + if ( !v || !v->vmtrace.pt_buf ) + return -EINVAL; + + mfn =3D page_to_mfn(v->vmtrace.pt_buf); + + if ( frame + nr_frames > (v->domain->vmtrace_pt_size >> PAGE_SHIFT) ) + return -EINVAL; + + for ( i =3D 0; i < nr_frames; i++ ) + mfn_list[i] =3D mfn_x(mfn_add(mfn, frame + i)); + + return 0; +} + static int acquire_grant_table(struct domain *d, unsigned int id, unsigned long frame, unsigned int nr_frames, @@ -1117,6 +1140,11 @@ static int acquire_resource( mfn_list); break; =20 + case XENMEM_resource_vmtrace_buf: + rc =3D acquire_vmtrace_buf(d, xmar.id, xmar.frame, xmar.nr_frames, + mfn_list); + break; + default: rc =3D arch_acquire_resource(d, xmar.type, xmar.id, xmar.frame, xmar.nr_frames, mfn_list); diff --git a/xen/include/public/memory.h b/xen/include/public/memory.h index 21057ed78e..f4c905a10e 100644 --- a/xen/include/public/memory.h +++ b/xen/include/public/memory.h @@ -625,6 +625,7 @@ struct xen_mem_acquire_resource { =20 #define XENMEM_resource_ioreq_server 0 #define XENMEM_resource_grant_table 1 +#define XENMEM_resource_vmtrace_buf 2 =20 /* * IN - a type-specific resource identifier, which must be zero --=20 2.17.1 From nobody Mon Apr 29 12:59:10 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; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1593975400; cv=none; d=zohomail.com; s=zohoarc; b=Sx1ilRaBPRrWPgQ05vhnNEh2eLD1QMKNuGtmTP6bknqCI6AVyvBV/jfClqZW1jHoWHC5EF8ZCKRK0a9QNuQzl3jpC5ZzBhdjbOqWnqmCxcC6VYXNVc3KzE/SnmH8RgOuFv4rOtPAXDDsH/8m9kEQrxFsFcxxg0TTEIOJTrItu50= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593975400; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=AW2qsUkXcw8WkviBxVJ7JMIkRyy4mlE3tlFbsUUJUgU=; b=DOKy3wC8NaR/CR4Suj9rrzW6nhOC4RopK0tGLAPZuiZHsZ9ycfGFrVYE0nKqppv69Tqdb2ZyGhJ8/2sbZ1qAy9xBk92QkMigvavO3kpFSLfEuFTlUqc7SqIPT4hj0KQnzOBdGzRCaEhoLUqjTGt/nbMTtTdWqHJwpBuEzBDCLWA= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1593975400202554.9878748187652; Sun, 5 Jul 2020 11:56:40 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9oQ-0005pw-TP; Sun, 05 Jul 2020 18:56:26 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9oO-0005m2-V1 for xen-devel@lists.xenproject.org; Sun, 05 Jul 2020 18:56:24 +0000 Received: from bagnar.nask.net.pl (unknown [195.187.242.196]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 37202e88-bef1-11ea-b7bb-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 5FD30A20CE; 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 24D36A20BB; Sun, 5 Jul 2020 20:56:16 +0200 (CEST) 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 4qVLccuKoIX3; 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 324E6A20AB; Sun, 5 Jul 2020 20:56:15 +0200 (CEST) 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 4DItugEelIB2; Sun, 5 Jul 2020 20:56:15 +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 E8472A2026; Sun, 5 Jul 2020 20:56:13 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by belindir.nask.net.pl (Postfix) with ESMTP id 3428022C37; Sun, 5 Jul 2020 20:55:19 +0200 (CEST) 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 oP-w6INSIyUv; 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 8C7A122C29; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) 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 wHWEk28cd5CO; 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 698F522C20; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) X-Inumbo-ID: 37202e88-bef1-11ea-b7bb-bc764e2007e4 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Virus-Scanned: amavisd-new at bagnar.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Quarantine-ID: X-Virus-Scanned: amavisd-new at belindir.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" From: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= To: xen-devel@lists.xenproject.org Subject: [PATCH v5 09/11] x86/domctl: add XEN_DOMCTL_vmtrace_op Date: Sun, 5 Jul 2020 20:55:02 +0200 Message-Id: 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: Julien Grall , Stefano Stabellini , luwei.kang@intel.com, Wei Liu , Andrew Cooper , Michal Leszczynski , Ian Jackson , George Dunlap , Jan Beulich , tamas.lengyel@intel.com, =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Michal Leszczynski Implement domctl to manage the runtime state of processor trace feature. Signed-off-by: Michal Leszczynski --- xen/arch/x86/domctl.c | 48 +++++++++++++++++++++++++++++++++++++ xen/include/public/domctl.h | 26 ++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c index 6f2c69788d..a041b724d8 100644 --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -322,6 +322,48 @@ void arch_get_domain_info(const struct domain *d, info->arch_config.emulation_flags =3D d->arch.emulation_flags; } =20 +static int do_vmtrace_op(struct domain *d, struct xen_domctl_vmtrace_op *o= p, + XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) +{ + int rc; + struct vcpu *v; + + if ( !vmtrace_supported ) + return -EOPNOTSUPP; + + if ( !is_hvm_domain(d) ) + return -EOPNOTSUPP; + + if ( op->vcpu >=3D d->max_vcpus ) + return -EINVAL; + + v =3D domain_vcpu(d, op->vcpu); + rc =3D 0; + + switch ( op->cmd ) + { + case XEN_DOMCTL_vmtrace_pt_enable: + case XEN_DOMCTL_vmtrace_pt_disable: + vcpu_pause(v); + spin_lock(&d->vmtrace_lock); + + rc =3D vmtrace_control_pt(v, op->cmd =3D=3D XEN_DOMCTL_vmtrace_pt_= enable); + + spin_unlock(&d->vmtrace_lock); + vcpu_unpause(v); + break; + + case XEN_DOMCTL_vmtrace_pt_get_offset: + rc =3D vmtrace_get_pt_offset(v, &op->offset); + break; + + default: + rc =3D -EOPNOTSUPP; + } + + return rc; +} + #define MAX_IOPORTS 0x10000 =20 long arch_do_domctl( @@ -337,6 +379,12 @@ long arch_do_domctl( switch ( domctl->cmd ) { =20 + case XEN_DOMCTL_vmtrace_op: + ret =3D do_vmtrace_op(d, &domctl->u.vmtrace_op, u_domctl); + if ( !ret ) + copyback =3D true; + break; + case XEN_DOMCTL_shadow_op: ret =3D paging_domctl(d, &domctl->u.shadow_op, u_domctl, 0); if ( ret =3D=3D -ERESTART ) diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h index 7b8289d436..f836cb5970 100644 --- a/xen/include/public/domctl.h +++ b/xen/include/public/domctl.h @@ -1136,6 +1136,28 @@ struct xen_domctl_vuart_op { */ }; =20 +/* XEN_DOMCTL_vmtrace_op: Perform VM tracing related operation */ +#if defined(__XEN__) || defined(__XEN_TOOLS__) + +struct xen_domctl_vmtrace_op { + /* IN variable */ + uint32_t cmd; +/* Enable/disable external vmtrace for given domain */ +#define XEN_DOMCTL_vmtrace_pt_enable 1 +#define XEN_DOMCTL_vmtrace_pt_disable 2 +#define XEN_DOMCTL_vmtrace_pt_get_offset 3 + domid_t domain; + uint32_t vcpu; + uint64_aligned_t size; + + /* OUT variable */ + uint64_aligned_t offset; +}; +typedef struct xen_domctl_vmtrace_op xen_domctl_vmtrace_op_t; +DEFINE_XEN_GUEST_HANDLE(xen_domctl_vmtrace_op_t); + +#endif /* defined(__XEN__) || defined(__XEN_TOOLS__) */ + struct xen_domctl { uint32_t cmd; #define XEN_DOMCTL_createdomain 1 @@ -1217,6 +1239,7 @@ struct xen_domctl { #define XEN_DOMCTL_vuart_op 81 #define XEN_DOMCTL_get_cpu_policy 82 #define XEN_DOMCTL_set_cpu_policy 83 +#define XEN_DOMCTL_vmtrace_op 84 #define XEN_DOMCTL_gdbsx_guestmemio 1000 #define XEN_DOMCTL_gdbsx_pausevcpu 1001 #define XEN_DOMCTL_gdbsx_unpausevcpu 1002 @@ -1277,6 +1300,9 @@ struct xen_domctl { struct xen_domctl_monitor_op monitor_op; struct xen_domctl_psr_alloc psr_alloc; struct xen_domctl_vuart_op vuart_op; +#if defined(__XEN__) || defined(__XEN_TOOLS__) + struct xen_domctl_vmtrace_op vmtrace_op; +#endif uint8_t pad[128]; } u; }; --=20 2.17.1 From nobody Mon Apr 29 12:59:10 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; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1593975409; cv=none; d=zohomail.com; s=zohoarc; b=YIzCn4lTP/p+IodVlJ3c+CBZ1iT4892qwdV1Etz7v93NFoCnE9iEd5HiWFNCnVGN0nKyN0j4Uf0soBZdIG0QAKvOqY2RNTpU92PzKvbwiFYlg7a7yZsGRUrMw3s7X6glLT8QPObkHuJXRHOv2X2Btm/BPZ21w7TT3nbz/BPuTlI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593975409; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=zLl2aWmCAsidkMTnOjD5y/ddA5m8jhFyEuIPCIBV+SM=; b=OQTO4jcmIzcOFiYmuvPfzS5EOYi3ImTWJJgao1kjvbyDVltA4JxvYZDALC862yzpFTkG6kbP6NiZjBuYfES3FJ5oc2rwVZmIoV/3R6e4lfFfDNEcZeOQ/Sp+oraKD89Nq7onEHxXaBo2o858CKZKj0j9p+E23hMK+xbefE2fg98= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1593975409597183.99259133794408; Sun, 5 Jul 2020 11:56:49 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 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 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) 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) 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) 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) 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) X-Inumbo-ID: 37203e8c-bef1-11ea-8496-bc764e2007e4 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Virus-Scanned: amavisd-new at bagnar.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Quarantine-ID: <9a2BxL5qECOO> X-Virus-Scanned: amavisd-new at belindir.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" From: =?UTF-8?q?Micha=C5=82=20Leszczy=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" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 +=3D xc_csched2.c CTRL_SRCS-y +=3D xc_arinc653.c CTRL_SRCS-y +=3D xc_rt.c CTRL_SRCS-y +=3D xc_tbuf.c +CTRL_SRCS-y +=3D xc_vmtrace.c CTRL_SRCS-y +=3D xc_pm.c CTRL_SRCS-y +=3D xc_cpu_hotplug.c CTRL_SRCS-y +=3D 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_cpuma= p_t mask); =20 int xc_tbuf_set_evt_mask(xc_interface *xch, uint32_t mask); =20 +/** + * 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); =20 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 =3D XEN_DOMCTL_vmtrace_op; + domctl.domain =3D domid; + domctl.u.vmtrace_op.cmd =3D XEN_DOMCTL_vmtrace_pt_enable; + domctl.u.vmtrace_op.vcpu =3D vcpu; + + rc =3D 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 =3D XEN_DOMCTL_vmtrace_op; + domctl.domain =3D domid; + domctl.u.vmtrace_op.cmd =3D XEN_DOMCTL_vmtrace_pt_get_offset; + domctl.u.vmtrace_op.vcpu =3D vcpu; + + rc =3D do_domctl(xch, &domctl); + if ( !rc ) + *offset =3D 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 =3D XEN_DOMCTL_vmtrace_op; + domctl.domain =3D domid; + domctl.u.vmtrace_op.cmd =3D XEN_DOMCTL_vmtrace_pt_disable; + domctl.u.vmtrace_op.vcpu =3D vcpu; + + rc =3D do_domctl(xch, &domctl); + return rc; +} + --=20 2.17.1 From nobody Mon Apr 29 12:59:10 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; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1593975395; cv=none; d=zohomail.com; s=zohoarc; b=jl/hcTYYqcfzWUFNFc/FOH3lEPUFJmLF5yehWevAs8NfzH1zcuXTnK5QFdoAUiPj/+W1+c3wFHsrkWFMKGTK+WzkHXyP6reHpB3/y5vqoMrh/xOO35JDgHu2OA4eiieFPE3oJbgwwu4You6/pXa1fqvxbnWP1kbeey+AH7nELh0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593975395; 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=9GiAFbc3sMaNpg4BKXRkUlmQV/VnHA+uq93FKEFIhAQ=; b=Y4I73FDzaCdP4B4Sxxoc9rO6Ya1SIL0daXeIDCVsFCKL1nVhWpuIn9IVGvP2ghjOijtIt3RlYjd5J+TE3BHycHt1ksad4V/2ziexX6LgRft9HgHf3UaZjEbXuFTQ4JIAYDlmWNWHmIoCiGp3GrEueZZPo2wNy+1jyASSon3bKDk= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1593975395582369.6142001252181; Sun, 5 Jul 2020 11:56:35 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9oL-0005mX-9L; Sun, 05 Jul 2020 18:56:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1js9oK-0005m2-00 for xen-devel@lists.xenproject.org; Sun, 05 Jul 2020 18:56:20 +0000 Received: from bagnar.nask.net.pl (unknown [195.187.242.196]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 359cef92-bef1-11ea-b7bb-bc764e2007e4; Sun, 05 Jul 2020 18:56:19 +0000 (UTC) Received: from bagnar.nask.net.pl (unknown [172.16.9.10]) by bagnar.nask.net.pl (Postfix) with ESMTP id 2CEB8A20CD; 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 02E85A20C3; Sun, 5 Jul 2020 20:56:16 +0200 (CEST) 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 1I7hzOnL4bmA; 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 D1F3EA209C; Sun, 5 Jul 2020 20:56:14 +0200 (CEST) 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 vSDx68SufYYS; 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 1C8C7A2037; 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 7365222C24; Sun, 5 Jul 2020 20:55:19 +0200 (CEST) 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 2s-5pUYlNWXw; 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 B371B22C22; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) 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 cnal_8Z5apTk; 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 8764A22C24; Sun, 5 Jul 2020 20:55:08 +0200 (CEST) X-Inumbo-ID: 359cef92-bef1-11ea-b7bb-bc764e2007e4 X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Virus-Scanned: amavisd-new at bagnar.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" X-Quarantine-ID: X-Virus-Scanned: amavisd-new at belindir.nask.net.pl X-Amavis-Alert: BAD HEADER SECTION, Duplicate header field: "References" From: =?UTF-8?q?Micha=C5=82=20Leszczy=C5=84ski?= To: xen-devel@lists.xenproject.org Subject: [PATCH v5 11/11] tools/proctrace: add proctrace tool Date: Sun, 5 Jul 2020 20:55:04 +0200 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable 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" Content-Type: text/plain; charset="utf-8" From: Michal Leszczynski Add an demonstration tool that uses xc_vmtrace_* calls in order to manage external IPT monitoring for DomU. Signed-off-by: Michal Leszczynski --- tools/proctrace/Makefile | 48 +++++++++++ tools/proctrace/proctrace.c | 163 ++++++++++++++++++++++++++++++++++++ 2 files changed, 211 insertions(+) create mode 100644 tools/proctrace/Makefile create mode 100644 tools/proctrace/proctrace.c diff --git a/tools/proctrace/Makefile b/tools/proctrace/Makefile new file mode 100644 index 0000000000..2983c477fe --- /dev/null +++ b/tools/proctrace/Makefile @@ -0,0 +1,48 @@ +# Copyright (C) CERT Polska - NASK PIB +# Author: Micha=C5=82 Leszczy=C5=84ski +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; under version 2 of the License. +# +# This program 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 General Public License for more details. + +XEN_ROOT=3D$(CURDIR)/../.. +include $(XEN_ROOT)/tools/Rules.mk + +CFLAGS +=3D -Werror +CFLAGS +=3D $(CFLAGS_libxenevtchn) +CFLAGS +=3D $(CFLAGS_libxenctrl) +LDLIBS +=3D $(LDLIBS_libxenctrl) +LDLIBS +=3D $(LDLIBS_libxenevtchn) +LDLIBS +=3D $(LDLIBS_libxenforeignmemory) + +.PHONY: all +all: build + +.PHONY: build +build: proctrace + +.PHONY: install +install: build + $(INSTALL_DIR) $(DESTDIR)$(sbindir) + $(INSTALL_PROG) proctrace $(DESTDIR)$(sbindir)/proctrace + +.PHONY: uninstall +uninstall: + rm -f $(DESTDIR)$(sbindir)/proctrace + +.PHONY: clean +clean: + $(RM) -f $(DEPS_RM) + +.PHONY: distclean +distclean: clean + +iptlive: iptlive.o Makefile + $(CC) $(LDFLAGS) $< -o $@ $(LDLIBS) $(APPEND_LDFLAGS) + +-include $(DEPS_INCLUDE) diff --git a/tools/proctrace/proctrace.c b/tools/proctrace/proctrace.c new file mode 100644 index 0000000000..22bf91db8d --- /dev/null +++ b/tools/proctrace/proctrace.c @@ -0,0 +1,163 @@ +/*************************************************************************= ***** + * tools/proctrace.c + * + * Demonstrative tool for collecting Intel Processor Trace data from Xen. + * Could be used to externally monitor a given vCPU in given DomU. + * + * Copyright (C) 2020 by CERT Polska - NASK PIB + * + * Authors: Micha=C5=82 Leszczy=C5=84ski, michal.leszczynski@cert.pl + * Date: June, 2020 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 2 of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; If not, see . + */ + +#include +#include +#include +#include + +#include +#include +#include + +#define BUF_SIZE (16384 * XC_PAGE_SIZE) + +volatile int interrupted =3D 0; + +void term_handler(int signum) { + interrupted =3D 1; +} + +int main(int argc, char* argv[]) { + xc_interface *xc; + uint32_t domid; + uint32_t vcpu_id; + + int rc =3D -1; + uint8_t *buf =3D NULL; + uint64_t last_offset =3D 0; + + xenforeignmemory_handle *fmem; + xenforeignmemory_resource_handle *fres; + + if (signal(SIGINT, term_handler) =3D=3D SIG_ERR) + { + fprintf(stderr, "Failed to register signal handler\n"); + return 1; + } + + if (argc !=3D 3) { + fprintf(stderr, "Usage: %s \n", argv[0]); + fprintf(stderr, "It's recommended to redirect this" + "program's output to file\n"); + fprintf(stderr, "or to pipe it's output to xxd or other program.\n= "); + return 1; + } + + domid =3D atoi(argv[1]); + vcpu_id =3D atoi(argv[2]); + + xc =3D xc_interface_open(0, 0, 0); + + fmem =3D xenforeignmemory_open(0, 0); + + if (!xc) { + fprintf(stderr, "Failed to open xc interface\n"); + return 1; + } + + rc =3D xc_vmtrace_pt_enable(xc, domid, vcpu_id); + + if (rc) { + fprintf(stderr, "Failed to call xc_vmtrace_pt_enable\n"); + return 1; + } + + fres =3D xenforeignmemory_map_resource( + fmem, domid, XENMEM_resource_vmtrace_buf, + /* vcpu: */ vcpu_id, + /* frame: */ 0, + /* num_frames: */ BUF_SIZE >> XC_PAGE_SHIFT, + (void **)&buf, + PROT_READ, 0); + + if (!buf) { + fprintf(stderr, "Failed to map trace buffer\n"); + return 1; + } + + while (!interrupted) { + uint64_t offset; + rc =3D xc_vmtrace_pt_get_offset(xc, domid, vcpu_id, &offset); + + if (rc) { + fprintf(stderr, "Failed to call xc_vmtrace_pt_get_offset\n"); + return 1; + } + + if (offset > last_offset) + { + fwrite(buf + last_offset, offset - last_offset, 1, stdout); + } + else if (offset < last_offset) + { + // buffer wrapped + fwrite(buf + last_offset, BUF_SIZE - last_offset, 1, stdout); + fwrite(buf, offset, 1, stdout); + } + + last_offset =3D offset; + usleep(1000 * 100); + } + + rc =3D xenforeignmemory_unmap_resource(fmem, fres); + + if (rc) { + fprintf(stderr, "Failed to unmap resource\n"); + return 1; + } + + rc =3D xenforeignmemory_close(fmem); + + if (rc) { + fprintf(stderr, "Failed to close fmem\n"); + return 1; + } + + rc =3D xc_vmtrace_pt_disable(xc, domid, vcpu_id); + + if (rc) { + fprintf(stderr, "Failed to call xc_vmtrace_pt_disable\n"); + return 1; + } + + rc =3D xc_interface_close(xc); + + if (rc) { + fprintf(stderr, "Failed to close xc interface\n"); + return 1; + } + + return 0; +} + +/* + * Local variables: + * mode: C + * c-file-style: "BSD" + * c-basic-offset: 4 + * tab-width: 4 + * indent-tabs-mode: nil + * End: + */ --=20 2.17.1