From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CC25C433E2 for ; Wed, 15 Jul 2020 17:32:55 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F3C8B2065D for ; Wed, 15 Jul 2020 17:32:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=citrix.com header.i=@citrix.com header.b="Td41bDWm" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F3C8B2065D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=citrix.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jvlGY-0001qw-Je; Wed, 15 Jul 2020 17:32:22 +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 1jvlGX-0001qr-MN for xen-devel@lists.xenproject.org; Wed, 15 Jul 2020 17:32:21 +0000 X-Inumbo-ID: 21f1f443-c6c1-11ea-942e-12813bfff9fa Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 21f1f443-c6c1-11ea-942e-12813bfff9fa; Wed, 15 Jul 2020 17:32:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1594834340; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=LBDx2QqeDw9WZ96RcUl126PhE18mwDrNiy8GsGKJWF8=; b=Td41bDWm5PrUR4zbUiAuYHhiCmwACtafDcRD7CrlaABDUtP0fOZhcHy7 mr7vwZuvQrAsfUr1PxT7oKAKQHzB3EDj3e3QxEFd/yPCfPA9XhEUIquQI gEuWNIy30u72wznhoPMJZS95/+xoNNdBUSIZ29HAGPZBw9eOnHsAKrQKO o=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none IronPort-SDR: 8nwuYvLGVw1/QLgYMNx9F8v9aXiQsE//zWNPJxkmi1eXbDbPrfqC6zEoBrWi4qUAKZJUbrvnsf vShPtRYnzglJonkrogX2ItiioYpy48kfsfvJCYGl12rxL30ulBWQn9BgZkJy4SWZF3gOiDsU80 OMf+yzp30IaxkWRJg6bfolDV9sES/++gTNFSIgdna7CI1eHQSMqtRKqVwhj0+cZQg7UVRmTrFx Crl4r1YNCMiZlUxkwbpSsFjtESpnIpwaqK8U8XpzzLvyRcA4EoNrs+m8lAMl9o0zWwHtKHryBx OWw= X-SBRS: 2.7 X-MesageID: 22655873 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.75,356,1589256000"; d="scan'208";a="22655873" Date: Wed, 15 Jul 2020 19:32:02 +0200 From: Roger Pau =?utf-8?B?TW9ubsOp?= To: =?utf-8?Q?Micha=C5=82_Leszczy=C5=84ski?= Subject: Re: [PATCH v6 09/11] x86/domctl: add XEN_DOMCTL_vmtrace_op Message-ID: <20200715173202.GG7191@Air-de-Roger> References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-ClientProxiedBy: AMSPEX02CAS01.citrite.net (10.69.22.112) To AMSPEX02CL02.citrite.net (10.69.22.126) 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 , Ian Jackson , George Dunlap , luwei.kang@intel.com, Jan Beulich , xen-devel@lists.xenproject.org Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On Tue, Jul 07, 2020 at 09:39:48PM +0200, Michał Leszczyński wrote: > From: Michal Leszczynski > > Implement domctl to manage the runtime state of > processor trace feature. > > Signed-off-by: Michal Leszczynski > --- > xen/arch/x86/domctl.c | 50 +++++++++++++++++++++++++++++++++++++ > xen/include/public/domctl.h | 28 +++++++++++++++++++++ > 2 files changed, 78 insertions(+) > > diff --git a/xen/arch/x86/domctl.c b/xen/arch/x86/domctl.c > index 6f2c69788d..6132499db4 100644 > --- a/xen/arch/x86/domctl.c > +++ b/xen/arch/x86/domctl.c > @@ -322,6 +322,50 @@ void arch_get_domain_info(const struct domain *d, > info->arch_config.emulation_flags = d->arch.emulation_flags; > } > > +static int do_vmtrace_op(struct domain *d, struct xen_domctl_vmtrace_op *op, > + XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) > +{ > + int rc; > + struct vcpu *v; > + > + if ( op->pad1 || op->pad2 ) > + return -EINVAL; > + > + if ( !vmtrace_supported ) > + return -EOPNOTSUPP; > + > + if ( !is_hvm_domain(d) ) > + return -EOPNOTSUPP; You can join both if into a single one if they both return -EOPNOTSUPP. > + > + if ( op->vcpu >= d->max_vcpus ) > + return -EINVAL; You can remove this check and just use the return value of domain_vcpu instead, if it's NULL the vCPU ID is wrong. > + > + v = domain_vcpu(d, op->vcpu); > + rc = 0; No need to init rc to 0, as it would be unconditionally initialized in the switch below due to the default case. > + > + switch ( op->cmd ) > + { > + case XEN_DOMCTL_vmtrace_pt_enable: > + case XEN_DOMCTL_vmtrace_pt_disable: > + vcpu_pause(v); > + rc = vmtrace_control_pt(v, op->cmd == XEN_DOMCTL_vmtrace_pt_enable); > + vcpu_unpause(v); > + break; > + > + case XEN_DOMCTL_vmtrace_pt_get_offset: > + rc = vmtrace_get_pt_offset(v, &op->offset, &op->size); In order to get consistent values here the vCPU should be paused, or else you just get stale values from the last vmexit? Maybe that's fine for your use case? > + > + if ( !rc && d->is_dying ) > + rc = ENODATA; This check here seems weird, if this is really required shouldn't it be done before attempting to fetch the data? > + break; > + > + default: > + rc = -EOPNOTSUPP; > + } > + > + return rc; > +} > + > #define MAX_IOPORTS 0x10000 > > long arch_do_domctl( > @@ -337,6 +381,12 @@ long arch_do_domctl( > switch ( domctl->cmd ) > { > > + case XEN_DOMCTL_vmtrace_op: > + ret = do_vmtrace_op(d, &domctl->u.vmtrace_op, u_domctl); > + if ( !ret ) > + copyback = true; > + break; Nit: new additions would usually got at the end of the switch. > + > case XEN_DOMCTL_shadow_op: > ret = paging_domctl(d, &domctl->u.shadow_op, u_domctl, 0); > if ( ret == -ERESTART ) > diff --git a/xen/include/public/domctl.h b/xen/include/public/domctl.h > index 7681675a94..73c7ccbd16 100644 > --- a/xen/include/public/domctl.h > +++ b/xen/include/public/domctl.h > @@ -1136,6 +1136,30 @@ struct xen_domctl_vuart_op { > */ > }; > > +/* 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; > + uint16_t pad1; > + uint32_t vcpu; > + uint16_t pad2; pad2 should be a uint32_t? Or else there's a padding field added by the compiler? (maybe I'm missing something, I haven't checked with pahole). > + > + /* OUT variable */ > + uint64_aligned_t size; > + 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 +1241,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 +1302,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 No need for the preprocessor conditionals here, the whole domctl.h is only to be used by the tools or Xen, and is already properly guarded (see the #error at the top of the file). Thanks.