From nobody Mon Feb 9 21:39:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; 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=1593520551; cv=none; d=zohomail.com; s=zohoarc; b=fB41ck9ShFzP4zH+8YbgWCxj2pv39dBR2eX+P61i1QliuEUIAuO+GD1QCpivU0P8SGlJeppgDgwF6U/p7eYggYqQ2ltYdhSrWLBPPEYa1BgPKCKHay/VQs09MqbH5tNE9FjYDBSfKKxml9CnXrglPb8ZFLuZrD/YXFfxnK+HOmM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1593520551; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=x03QMMIUxxuKxFIGgznHNKUF7mFaV5dUidubG2P3i9U=; b=Gx/E2SDn6OLIEZUpdBwTm7JLpkuMMZm5YCMpaPFA9CR0vRP4ise4vrlmzMqaqjcynrSRsRqvJOv+6uJ5zYHF2/F81m1zKms9XtUUOr4NAMqoLWcT3zJ7p5iiVh/YYtV/NhRnvFyDy9zrudeSIRZNj+qFLdZujs8xUa6FyXtrjCI= 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 1593520551141423.58122714738977; Tue, 30 Jun 2020 05:35: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 1jqFUA-00081C-Lk; Tue, 30 Jun 2020 12:35:38 +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 1jqFU9-0007rV-SP for xen-devel@lists.xenproject.org; Tue, 30 Jun 2020 12:35:37 +0000 Received: from bagnar.nask.net.pl (unknown [195.187.242.196]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2d6897e6-bace-11ea-8610-12813bfff9fa; Tue, 30 Jun 2020 12:35:29 +0000 (UTC) Received: from bagnar.nask.net.pl (unknown [172.16.9.10]) by bagnar.nask.net.pl (Postfix) with ESMTP id 6140EA37F9; Tue, 30 Jun 2020 14:35:28 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id 484D2A37FA; Tue, 30 Jun 2020 14:35:27 +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 ZlCGzAO2pZSL; Tue, 30 Jun 2020 14:35:26 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by bagnar.nask.net.pl (Postfix) with ESMTP id AB7D4A37F8; Tue, 30 Jun 2020 14:35:26 +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 HSr51uoiqUOZ; Tue, 30 Jun 2020 14:35:26 +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 28DAAA37EA; Tue, 30 Jun 2020 14:35:26 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by belindir.nask.net.pl (Postfix) with ESMTP id 13D1622625; Tue, 30 Jun 2020 14:34:45 +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 HP0zBV_9dGFy; Tue, 30 Jun 2020 14:34:39 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by belindir.nask.net.pl (Postfix) with ESMTP id 814842262E; Tue, 30 Jun 2020 14:34:39 +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 MsyLsha6KguP; Tue, 30 Jun 2020 14:34:39 +0200 (CEST) Received: from mq-desktop.cert.pl (unknown [195.187.238.217]) by belindir.nask.net.pl (Postfix) with ESMTPSA id 60E77224C7; Tue, 30 Jun 2020 14:34:39 +0200 (CEST) X-Inumbo-ID: 2d6897e6-bace-11ea-8610-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 v4 05/10] common/domain: allocate vmtrace_pt_buffer Date: Tue, 30 Jun 2020 14:33:48 +0200 Message-Id: <0e02c97054da6e367f740ab8d2574e2d255553c8.1593519420.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 , tamas.lengyel@intel.com, Wei Liu , Andrew Cooper , Michal Leszczynski , Ian Jackson , George Dunlap , Jan Beulich , luwei.kang@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 Allocate processor trace buffer for each vCPU when the domain is created, deallocate trace buffers on domain destruction. Signed-off-by: Michal Leszczynski --- xen/arch/x86/domain.c | 11 +++++++++++ xen/common/domain.c | 32 ++++++++++++++++++++++++++++++++ xen/include/asm-x86/domain.h | 4 ++++ xen/include/xen/sched.h | 4 ++++ 4 files changed, 51 insertions(+) diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index fee6c3931a..0d79fd390c 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -2199,6 +2199,17 @@ int domain_relinquish_resources(struct domain *d) altp2m_vcpu_disable_ve(v); } =20 + for_each_vcpu ( d, v ) + { + if ( !v->arch.vmtrace.pt_buf ) + continue; + + vmtrace_destroy_pt(v); + + free_domheap_pages(v->arch.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 27dcfbac8c..8513659ef8 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -137,6 +137,31 @@ 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; + + if ( size < PAGE_SIZE || size > GB(4) || (size & (size - 1)) ) + { + /* + * 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. + */ + return -EINVAL; + } + + pg =3D alloc_domheap_pages(v->domain, get_order_from_bytes(size), + MEMF_no_refcount); + + if ( !pg ) + return -ENOMEM; + + v->arch.vmtrace.pt_buf =3D pg; + return 0; +} + struct vcpu *vcpu_create(struct domain *d, unsigned int vcpu_id) { struct vcpu *v; @@ -162,6 +187,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); @@ -188,6 +216,9 @@ struct vcpu *vcpu_create(struct domain *d, unsigned int= vcpu_id) if ( arch_vcpu_create(v) !=3D 0 ) goto fail_sched; =20 + if ( d->vmtrace_pt_size && vmtrace_init_pt(v) !=3D 0 ) + goto fail_sched; + d->vcpu[vcpu_id] =3D v; if ( vcpu_id !=3D 0 ) { @@ -422,6 +453,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/domain.h b/xen/include/asm-x86/domain.h index 6fd94c2e14..b01c107f5c 100644 --- a/xen/include/asm-x86/domain.h +++ b/xen/include/asm-x86/domain.h @@ -627,6 +627,10 @@ struct arch_vcpu struct { bool next_interrupt_enabled; } monitor; + + struct { + struct page_info *pt_buf; + } vmtrace; }; =20 struct guest_memory_policy 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.20.1