From patchwork Sun Apr 2 12:24:24 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhang X-Patchwork-Id: 9658443 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 8B28D602BA for ; Sun, 2 Apr 2017 12:46:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AD9F2845B for ; Sun, 2 Apr 2017 12:46:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F091284BC; Sun, 2 Apr 2017 12:46:14 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 CE3452845B for ; Sun, 2 Apr 2017 12:46:11 +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 1cuerW-00037A-0c; Sun, 02 Apr 2017 12:44:06 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cuerU-00036t-Sw for xen-devel@lists.xen.org; Sun, 02 Apr 2017 12:44:04 +0000 Received: from [85.158.137.68] by server-12.bemta-3.messagelabs.com id 88/7F-12861-412F0E85; Sun, 02 Apr 2017 12:44:04 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRWlGSWpSXmKPExsVywNwkVlf404M Ig3M3dC2WfFzM4sDocXT3b6YAxijWzLyk/IoE1oyna7pYCg4aVhxd8ZS5gbFTo4uRi4NF4BaT RGPPWmYQR0hgGqPE9K2NTF2MnBwSArwSR5bNYIWw/SQmPtrJClHUzijxZnsTWBGbgLbEj9W/G UFsEQFpiWufLzOCFDELdDNKrLw7ix0kISwQKPHowxs2EJtFQFViY/dyoCIODl4BD4mOG0oQC+ QkTh6bDLaMU8BT4unyDWC2EFDJjv+L2Scw8i1gZFjFqFGcWlSWWqRraKKXVJSZnlGSm5iZo2t oYKyXm1pcnJiempOYVKyXnJ+7iREYKgxAsINxxXbPQ4ySHExKorzfi+9FCPEl5adUZiQWZ8QX leakFh9ilOHgUJLgnfzhQYSQYFFqempFWmYOMGhh0hIcPEoivIUgad7igsTc4sx0iNQpRkUpc d4qkIQASCKjNA+uDRYplxhlpYR5GYEOEeIpSC3KzSxBlX/FKM7BqCTMOwFkCk9mXgnc9FdAi5 mAFlt8vQuyuCQRISXVwKjP/lkmoVQrdN7xEkmlJa9K2n9cW+++PmIPv/UZfssrEb9++N5YcDZ 3iuKdhtq6hC0hgqtfxj9b0TPlRfBpydvuJvsFe7L/dmcrcS4zmLese8WNXT6rE50vnrqfJ3DG bYZIlI1d8DzeWSeyN4TIz7+oI/FmQ/DVndd+p5mWlURGLprxY6Hdwm9KLMUZiYZazEXFiQBpY q1bjwIAAA== X-Env-Sender: yu.c.zhang@linux.intel.com X-Msg-Ref: server-16.tower-31.messagelabs.com!1491137041!85969287!1 X-Originating-IP: [192.55.52.93] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTkyLjU1LjUyLjkzID0+IDMyNDY2NQ==\n X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 6274 invoked from network); 2 Apr 2017 12:44:03 -0000 Received: from mga11.intel.com (HELO mga11.intel.com) (192.55.52.93) by server-16.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 2 Apr 2017 12:44:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=intel.com; i=@intel.com; q=dns/txt; s=intel; t=1491137043; x=1522673043; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=YpyWpQZgUWW0T/Uz4YCcZEgPOwESbL+quSajGxqNKo8=; b=GzuO6M0TnbAsL7/bM3R7Ocw8VRSSzumnyjCPDV5gXathovkD7YDN3C3u yC/pC6Gs+NiDciNMfQI9YhWaAX5t6Q==; Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Apr 2017 05:44:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.36,263,1486454400"; d="scan'208";a="81958916" Received: from zhangyu-optiplex-9020.bj.intel.com ([10.238.135.159]) by orsmga005.jf.intel.com with ESMTP; 02 Apr 2017 05:43:59 -0700 From: Yu Zhang To: xen-devel@lists.xen.org Date: Sun, 2 Apr 2017 20:24:24 +0800 Message-Id: <1491135867-623-4-git-send-email-yu.c.zhang@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1491135867-623-1-git-send-email-yu.c.zhang@linux.intel.com> References: <1491135867-623-1-git-send-email-yu.c.zhang@linux.intel.com> Cc: Wei Liu , Paul Durrant , Ian Jackson , zhiyuan.lv@intel.com Subject: [Xen-devel] [PATCH v10 3/6] x86/ioreq server: Add device model wrappers for new DMOP 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 A new device model wrapper is added for the newly introduced DMOP - XEN_DMOP_map_mem_type_to_ioreq_server. Since currently this DMOP only supports the emulation of write operations, attempts to trigger the DMOP with values other than XEN_DMOP_IOREQ_MEM_ACCESS_WRITE or 0(to unmap the ioreq server) shall fail. The wrapper shall be updated once read operations are also to be emulated in the future. Also note currently this DMOP only supports one memory type, and can be extended in the future to map multiple memory types to multiple ioreq servers, e.g. mapping HVMMEM_ioreq_serverX to ioreq server X, This wrapper shall be updated when such change is made. Signed-off-by: Yu Zhang Reviewed-by: Paul Durrant --- Cc: Paul Durrant Cc: Ian Jackson Cc: Wei Liu --- tools/libs/devicemodel/core.c | 25 +++++++++++++++++++++++++ tools/libs/devicemodel/include/xendevicemodel.h | 18 ++++++++++++++++++ tools/libs/devicemodel/libxendevicemodel.map | 1 + tools/libxc/include/xenctrl_compat.h | 5 +++++ tools/libxc/xc_devicemodel_compat.c | 17 +++++++++++++++++ 5 files changed, 66 insertions(+) diff --git a/tools/libs/devicemodel/core.c b/tools/libs/devicemodel/core.c index a85cb49..ff09819 100644 --- a/tools/libs/devicemodel/core.c +++ b/tools/libs/devicemodel/core.c @@ -244,6 +244,31 @@ int xendevicemodel_unmap_io_range_from_ioreq_server( return xendevicemodel_op(dmod, domid, 1, &op, sizeof(op)); } +int xendevicemodel_map_mem_type_to_ioreq_server( + xendevicemodel_handle *dmod, domid_t domid, ioservid_t id, uint16_t type, + uint32_t flags) +{ + struct xen_dm_op op; + struct xen_dm_op_map_mem_type_to_ioreq_server *data; + + if (type != HVMMEM_ioreq_server || + flags & ~XEN_DMOP_IOREQ_MEM_ACCESS_WRITE) { + errno = EINVAL; + return -1; + } + + memset(&op, 0, sizeof(op)); + + op.op = XEN_DMOP_map_mem_type_to_ioreq_server; + data = &op.u.map_mem_type_to_ioreq_server; + + data->id = id; + data->type = type; + data->flags = flags; + + return xendevicemodel_op(dmod, domid, 1, &op, sizeof(op)); +} + int xendevicemodel_map_pcidev_to_ioreq_server( xendevicemodel_handle *dmod, domid_t domid, ioservid_t id, uint16_t segment, uint8_t bus, uint8_t device, uint8_t function) diff --git a/tools/libs/devicemodel/include/xendevicemodel.h b/tools/libs/devicemodel/include/xendevicemodel.h index b3f600e..1da216f 100644 --- a/tools/libs/devicemodel/include/xendevicemodel.h +++ b/tools/libs/devicemodel/include/xendevicemodel.h @@ -104,6 +104,24 @@ int xendevicemodel_unmap_io_range_from_ioreq_server( uint64_t start, uint64_t end); /** + * This function registers/deregisters a memory type for emulation. + * + * @parm dmod a handle to an open devicemodel interface. + * @parm domid the domain id to be serviced. + * @parm id the IOREQ Server id. + * @parm type the memory type to be emulated. For now, only HVMMEM_ioreq_server + * is supported, and in the future new types can be introduced, e.g. + * HVMMEM_ioreq_serverX mapped to ioreq server X. + * @parm flags operations to be emulated; 0 for unmap. For now, only write + * operations will be emulated and can be extended to emulate + * read ones in the future. + * @return 0 on success, -1 on failure. + */ +int xendevicemodel_map_mem_type_to_ioreq_server( + xendevicemodel_handle *dmod, domid_t domid, ioservid_t id, uint16_t type, + uint32_t flags); + +/** * This function registers a PCI device for config space emulation. * * @parm dmod a handle to an open devicemodel interface. diff --git a/tools/libs/devicemodel/libxendevicemodel.map b/tools/libs/devicemodel/libxendevicemodel.map index 45c773e..130222c 100644 --- a/tools/libs/devicemodel/libxendevicemodel.map +++ b/tools/libs/devicemodel/libxendevicemodel.map @@ -5,6 +5,7 @@ VERS_1.0 { xendevicemodel_get_ioreq_server_info; xendevicemodel_map_io_range_to_ioreq_server; xendevicemodel_unmap_io_range_from_ioreq_server; + xendevicemodel_map_mem_type_to_ioreq_server; xendevicemodel_map_pcidev_to_ioreq_server; xendevicemodel_unmap_pcidev_from_ioreq_server; xendevicemodel_destroy_ioreq_server; diff --git a/tools/libxc/include/xenctrl_compat.h b/tools/libxc/include/xenctrl_compat.h index 040e7b2..173c08c 100644 --- a/tools/libxc/include/xenctrl_compat.h +++ b/tools/libxc/include/xenctrl_compat.h @@ -134,6 +134,11 @@ int xc_hvm_map_io_range_to_ioreq_server( int xc_hvm_unmap_io_range_from_ioreq_server( xc_interface *xch, domid_t domid, ioservid_t id, int is_mmio, uint64_t start, uint64_t end); +int xc_hvm_map_mem_type_to_ioreq_server( + xc_interface * xch, domid_t domid, ioservid_t id, + uint16_t type, uint32_t flags); +int xc_hvm_unmap_mem_type_from_ioreq_server( + xc_interface * xch, domid_t domid, ioservid_t id, uint16_t type); int xc_hvm_map_pcidev_to_ioreq_server( xc_interface *xch, domid_t domid, ioservid_t id, uint16_t segment, uint8_t bus, uint8_t device, uint8_t function); diff --git a/tools/libxc/xc_devicemodel_compat.c b/tools/libxc/xc_devicemodel_compat.c index e4edeea..ea2496b 100644 --- a/tools/libxc/xc_devicemodel_compat.c +++ b/tools/libxc/xc_devicemodel_compat.c @@ -41,6 +41,23 @@ int xc_hvm_unmap_io_range_from_ioreq_server( start, end); } +int xc_hvm_map_mem_type_to_ioreq_server( + xc_interface *xch, domid_t domid, ioservid_t id, uint16_t type, + uint32_t flags) +{ + return xendevicemodel_map_mem_type_to_ioreq_server(xch->dmod, domid, + id, type, + flags); +} + +int xc_hvm_unmap_mem_type_from_ioreq_server( + xc_interface *xch, domid_t domid, ioservid_t id, uint16_t type) +{ + return xendevicemodel_map_mem_type_to_ioreq_server(xch->dmod, domid, + id, type, + 0); +} + int xc_hvm_map_pcidev_to_ioreq_server( xc_interface *xch, domid_t domid, ioservid_t id, uint16_t segment, uint8_t bus, uint8_t device, uint8_t function)