From patchwork Fri Mar 17 11:27:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "lan,Tianyu" X-Patchwork-Id: 9630439 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ECEEA60249 for ; Fri, 17 Mar 2017 11:37:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D459028616 for ; Fri, 17 Mar 2017 11:37:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C86D32862B; Fri, 17 Mar 2017 11:37:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 34A2A284E9 for ; Fri, 17 Mar 2017 11:37:37 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coqA8-0003fi-Pv; Fri, 17 Mar 2017 11:35:16 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1coqA7-0003ef-2C for xen-devel@lists.xen.org; Fri, 17 Mar 2017 11:35:15 +0000 Received: from [85.158.139.211] by server-3.bemta-5.messagelabs.com id E4/C7-01936-2F9CBC85; Fri, 17 Mar 2017 11:35:14 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrLLMWRWlGSWpSXmKPExsXS1tYhr/vx5Ok Ig8vbTCyWfFzM4sDocXT3b6YAxijWzLyk/IoE1oyZ3X8YC/6aVnR/eMvYwHhOp4uRg0NIoEKi syG4i5GTQ0KAV+LIshmsELafxJcrM1m6GLmASvoZJV4tWs8IkmATUJc4sXgimC0iIC1x7fNlR pAiZoFmRolpLxezgCSEBVwlFrQvAJvEIqAq8bhxHROIzSvgIrGg8TAjyGIJAQWJOZNsQMKcQO V32x6wg9hCQCX3uq6wTGDkXcDIsIpRozi1qCy1SNfQRC+pKDM9oyQ3MTNH19DAVC83tbg4MT0 1JzGpWC85P3cTIzAYGIBgB+PZ056HGCU5mJREeV+sOB0hxJeUn1KZkVicEV9UmpNafIhRhoND SYL3zgmgnGBRanpqRVpmDjAsYdISHDxKIrwCwNAU4i0uSMwtzkyHSJ1iVJQS5+0H6RMASWSU5 sG1wWLhEqOslDAvI9AhQjwFqUW5mSWo8q8YxTkYlYR5JUHG82TmlcBNfwW0mAlo8dsPJ0AWly QipKQaGIuv343vvjdFxvStr/nTxvgmj2+6PP/KGqfG5Go1/P8aYnE0aXfM5UPpWVNXbp38qjt og05i380ZQr4T3+XoW7XnbpxlLxqgtDNJ5K7JPsP1XZ4MWjMn5q5bF8sq4366o9j/eqHX3F+J Oc80Wp+L7t8axnj+9f91L52Wa+54l/JWetovpZ0ttkosxRmJhlrMRcWJAO2fgCCAAgAA X-Env-Sender: tianyu.lan@intel.com X-Msg-Ref: server-2.tower-206.messagelabs.com!1489750510!69368109!2 X-Originating-IP: [134.134.136.31] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 52880 invoked from network); 17 Mar 2017 11:35:13 -0000 Received: from mga06.intel.com (HELO mga06.intel.com) (134.134.136.31) by server-2.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 17 Mar 2017 11:35:13 -0000 Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP; 17 Mar 2017 04:35:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,176,1486454400"; d="scan'208";a="68334683" Received: from lantianyu-ws.sh.intel.com (HELO localhost) ([10.239.159.159]) by orsmga004.jf.intel.com with ESMTP; 17 Mar 2017 04:35:11 -0700 From: Lan Tianyu To: xen-devel@lists.xen.org Date: Fri, 17 Mar 2017 19:27:05 +0800 Message-Id: <1489750043-17260-6-git-send-email-tianyu.lan@intel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1489750043-17260-1-git-send-email-tianyu.lan@intel.com> References: <1489750043-17260-1-git-send-email-tianyu.lan@intel.com> Cc: Lan Tianyu , wei.liu2@citrix.com, kevin.tian@intel.com, ian.jackson@eu.citrix.com, chao.gao@intel.com Subject: [Xen-devel] [RFC PATCH 5/23] Tools/libxc: Add viommu operations in libxc X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Chao Gao In previous patch, we introduce a common vIOMMU layer. In our design, we create/destroy vIOMMU through DMOP interface instead of creating it according to a config flag of domain. It makes it is possible to create vIOMMU in device model or in tool stack. The following toolstack code is to add XEN_DMOP_viommu_XXX syscalls: - query capabilities of vIOMMU emulated by Xen - create vIOMMU in Xen hypervisor with base address, capability - destroy vIOMMU specified by viommu_id Signed-off-by: Chao Gao Signed-off-by: Lan Tianyu --- tools/libs/devicemodel/core.c | 69 +++++++++++++++++++++++++ tools/libs/devicemodel/include/xendevicemodel.h | 35 +++++++++++++ tools/libs/devicemodel/libxendevicemodel.map | 3 ++ tools/libxc/include/xenctrl_compat.h | 5 ++ tools/libxc/xc_devicemodel_compat.c | 18 +++++++ 5 files changed, 130 insertions(+) diff --git a/tools/libs/devicemodel/core.c b/tools/libs/devicemodel/core.c index a85cb49..aee1150 100644 --- a/tools/libs/devicemodel/core.c +++ b/tools/libs/devicemodel/core.c @@ -498,6 +498,75 @@ int xendevicemodel_restrict(xendevicemodel_handle *dmod, domid_t domid) return osdep_xendevicemodel_restrict(dmod, domid); } +int xendevicemodel_viommu_query_cap( + xendevicemodel_handle *dmod, domid_t dom, uint64_t *cap) +{ + struct xen_dm_op op; + struct xen_dm_op_query_viommu_caps *data; + int rc; + + if ( !cap ) + return -EINVAL; + + memset(&op, 0, sizeof(op)); + + op.op = XEN_DMOP_query_viommu_caps; + data = &op.u.query_viommu_caps; + + rc = xendevicemodel_op(dmod, dom, 1, &op, sizeof(op)); + if ( rc ) + return rc; + + *cap = data->caps; + return 0; +} + +int xendevicemodel_viommu_create( + xendevicemodel_handle *dmod, domid_t dom, uint64_t base_addr, + uint64_t cap, uint32_t *viommu_id) +{ + struct xen_dm_op op; + struct xen_dm_op_create_viommu *data; + int rc; + + if ( !viommu_id ) + return -EINVAL; + + memset(&op, 0, sizeof(op)); + + op.op = XEN_DMOP_create_viommu; + data = &op.u.create_viommu; + + data->base_address = base_addr; + data->capabilities = cap; + + rc = xendevicemodel_op(dmod, dom, 1, &op, sizeof(op)); + if ( rc ) + return rc; + + *viommu_id = data->viommu_id; + return 0; +} + +int xendevicemodel_viommu_destroy( + xendevicemodel_handle *dmod, domid_t dom, uint32_t viommu_id) +{ + struct xen_dm_op op; + struct xen_dm_op_destroy_viommu *data; + + if ( !viommu_id ) + return -EINVAL; + + memset(&op, 0, sizeof(op)); + + op.op = XEN_DMOP_destroy_viommu; + data = &op.u.destroy_viommu; + + data->viommu_id = viommu_id; + + return xendevicemodel_op(dmod, dom, 1, &op, sizeof(op)); +} + /* * Local variables: * mode: C diff --git a/tools/libs/devicemodel/include/xendevicemodel.h b/tools/libs/devicemodel/include/xendevicemodel.h index b3f600e..e133dd5 100644 --- a/tools/libs/devicemodel/include/xendevicemodel.h +++ b/tools/libs/devicemodel/include/xendevicemodel.h @@ -293,6 +293,41 @@ int xendevicemodel_inject_event( */ int xendevicemodel_restrict(xendevicemodel_handle *dmod, domid_t domid); +/** + * This function queries the capabilitites of vIOMMU emulated by Xen. + * + * @parm dmod a handle to an open devicemodel interface. + * @parm dom the domain id to be serviced. + * @parm cap points to memory to store the capability. + * @return 0 on success, -1 on failure. + */ +int xendevicemodel_viommu_query_cap( + xendevicemodel_handle *dmod, domid_t dom, uint64_t *cap); + +/** + * This function creates vIOMMU in Xen hypervisor with base_addr, capability. + * + * @parm dmod a handle to an open devicemodel interface. + * @parm dom the domain id to be serviced. + * @parm base_addr base address of register set of the vIOMMU. + * @parm cap the capability owned by the vIOMMU to be created. + * @parm viommu_id points to memory to store the vIOMMU id. + * @return 0 on success, -1 on failure. + */ +int xendevicemodel_viommu_create( + xendevicemodel_handle *dmod, domid_t dom, uint64_t base_addr, + uint64_t cap, uint32_t *viommu_id); + +/** + * This function destroies vIOMMU specified by viommu_id. + * + * @parm dmod a handle to an open devicemodel interface. + * @parm dom the domain id to be serviced. + * @parm viommu_id spcifies the id of the vIOMMU to be destroied. + * @return 0 on success, -1 on failure. + */ +int xendevicemodel_viommu_destroy( + xendevicemodel_handle *dmod, domid_t dom, uint32_t viommu_id); #endif /* __XEN_TOOLS__ */ #endif /* XENDEVICEMODEL_H */ diff --git a/tools/libs/devicemodel/libxendevicemodel.map b/tools/libs/devicemodel/libxendevicemodel.map index 45c773e..c2e0968 100644 --- a/tools/libs/devicemodel/libxendevicemodel.map +++ b/tools/libs/devicemodel/libxendevicemodel.map @@ -17,6 +17,9 @@ VERS_1.0 { xendevicemodel_modified_memory; xendevicemodel_set_mem_type; xendevicemodel_inject_event; + xendevicemodel_viommu_query_cap; + xendevicemodel_viommu_create; + xendevicemodel_viommu_destroy; xendevicemodel_restrict; xendevicemodel_close; local: *; /* Do not expose anything by default */ diff --git a/tools/libxc/include/xenctrl_compat.h b/tools/libxc/include/xenctrl_compat.h index 040e7b2..315c45d 100644 --- a/tools/libxc/include/xenctrl_compat.h +++ b/tools/libxc/include/xenctrl_compat.h @@ -164,6 +164,11 @@ int xc_hvm_set_mem_type( int xc_hvm_inject_trap( xc_interface *xch, domid_t domid, int vcpu, uint8_t vector, uint8_t type, uint32_t error_code, uint8_t insn_len, uint64_t cr2); +int xc_viommu_query_cap(xc_interface *xch, domid_t dom, uint64_t *cap); +int xc_viommu_create( + xc_interface *xch, domid_t dom, uint64_t base_addr, uint64_t cap, + uint32_t *viommu_id); +int xc_viommu_destroy(xc_interface *xch, domid_t dom, uint32_t viommu_id); #endif /* XC_WANT_COMPAT_DEVICEMODEL_API */ diff --git a/tools/libxc/xc_devicemodel_compat.c b/tools/libxc/xc_devicemodel_compat.c index e4edeea..62f703a 100644 --- a/tools/libxc/xc_devicemodel_compat.c +++ b/tools/libxc/xc_devicemodel_compat.c @@ -128,6 +128,24 @@ int xc_hvm_inject_trap( type, error_code, insn_len, cr2); } +int xc_viommu_query_cap(xc_interface *xch, domid_t dom, uint64_t *cap) +{ + return xendevicemodel_viommu_query_cap(xch->dmod, dom, cap); +} + +int xc_viommu_create( + xc_interface *xch, domid_t dom, uint64_t base_addr, uint64_t cap, + uint32_t *viommu_id) +{ + return xendevicemodel_viommu_create(xch->dmod, dom, base_addr, cap, + viommu_id); +} + +int xc_viommu_destroy(xc_interface *xch, domid_t dom, uint32_t viommu_id) +{ + return xendevicemodel_viommu_destroy(xch->dmod, dom, viommu_id); +} + /* * Local variables: * mode: C