From patchwork Wed Sep 28 09:42:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 9353671 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 16D5E6077A for ; Wed, 28 Sep 2016 09:45:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9740829478 for ; Wed, 28 Sep 2016 09:45:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8BD422947D; Wed, 28 Sep 2016 09:45:03 +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, UNPARSEABLE_RELAY 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 60AB729478 for ; Wed, 28 Sep 2016 09:45:02 +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 1bpBO7-0000Cm-Gx; Wed, 28 Sep 2016 09:42:51 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bpBO6-0008W4-Iw for xen-devel@lists.xenproject.org; Wed, 28 Sep 2016 09:42:50 +0000 Received: from [85.158.137.68] by server-2.bemta-3.messagelabs.com id 28/FF-01945-8909BE75; Wed, 28 Sep 2016 09:42:48 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrFLMWRWlGSWpSXmKPExsUyZ7p8oO70Ca/ DDZqfGFl83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBlPO58xFrz3rJj3Zx5TA+NV0y5GLg4hgclM Ek9f/maDcL4xSvxb1cfYxcgJ5GxklNh/TA8iMYFR4vLub0AJDg42AROJN6scQWpEBEwltk88y QJSwywwjVHi06kjTCAJYYEQiX+rLzCD2CwCqhKXV74Bs3kF3CT+vt3HCjJHQkBe4tntehCTU8 Bd4v5hX4i1bhLfGx6zgNgSAsYS7W8vsk1g5FvAyLCKUaM4tagstUjX0FgvqSgzPaMkNzEzR9f QwFgvN7W4ODE9NScxqVgvOT93EyMwTBiAYAfjtu2ehxglOZiURHk3h78OF+JLyk+pzEgszogv Ks1JLT7EKMPBoSTBq9APlBMsSk1PrUjLzAEGLExagoNHSYQ3EiTNW1yQmFucmQ6ROsWoKCXOe 7wPKCEAksgozYNrg0XJJUZZKWFeRqBDhHgKUotyM0tQ5V8xinMwKgnzZoKM58nMK4Gb/gpoMR PQ4qUnXoAsLklESEk1MJ55/LnI2cMzYoOj42LXWc9XPniqZlW52DrlsPqTFNWHhotezu+TmWQ r/CbzkKLXAQdduajrtVtLtzR65u5ctG0n43LGPX4a+XoyC1QOMLIHpHxa2iJrf0UnJUao8Lbl 1H+PC+xjTD4qcV7PfRQQ1civInNN8u58lvxJl1dda0j7sGFT+rkpVkosxRmJhlrMRcWJAJrH9 22NAgAA X-Env-Sender: konrad.wilk@oracle.com X-Msg-Ref: server-14.tower-31.messagelabs.com!1475055766!63156173!1 X-Originating-IP: [156.151.31.81] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMTU2LjE1MS4zMS44MSA9PiAyODgzMzk=\n X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 34884 invoked from network); 28 Sep 2016 09:42:47 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-14.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 28 Sep 2016 09:42:47 -0000 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u8S9ggx5021005 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Sep 2016 09:42:42 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id u8S9gg73002709 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Sep 2016 09:42:42 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u8S9gevW019411; Wed, 28 Sep 2016 09:42:41 GMT Received: from localhost.localdomain.com (/209.6.196.81) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 28 Sep 2016 02:42:39 -0700 From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, konrad@kernel.org Date: Wed, 28 Sep 2016 05:42:22 -0400 Message-Id: <1475055746-22401-9-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.4.11 In-Reply-To: <1475055746-22401-1-git-send-email-konrad.wilk@oracle.com> References: <1475055746-22401-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: aserv0022.oracle.com [141.146.126.234] Cc: Wei Liu , Ian Jackson , Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v1 08/12] tmem: Handle 'struct tmem_info' as a seperate field in the 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 the struct tmem_op. No functional change. But it makes the code so much easier to read. Note: We still have to do this awkward 'guest_handle_cast' otherwise it will not compile on ARM - which defines _two_ of these macros (__guest_handle_64_xen_sysctl_tmem_client_t and __guest_handle_xen_sysctl_tmem_client_t). And if cast is not used then a compile error comes up as we use the wrong one. Signed-off-by: Konrad Rzeszutek Wilk Acked-by: Wei Liu --- Cc: Ian Jackson Cc: Wei Liu v1: First submission. --- tools/libxc/xc_tmem.c | 4 +-- xen/common/tmem.c | 8 +++--- xen/common/tmem_control.c | 68 ++++++++++++++++++++++----------------------- xen/include/public/sysctl.h | 11 +++++--- 4 files changed, 46 insertions(+), 45 deletions(-) diff --git a/tools/libxc/xc_tmem.c b/tools/libxc/xc_tmem.c index 74d2d85..cb0dfa1 100644 --- a/tools/libxc/xc_tmem.c +++ b/tools/libxc/xc_tmem.c @@ -87,7 +87,7 @@ int xc_tmem_control(xc_interface *xch, } } - set_xen_guest_handle(sysctl.u.tmem_op.buf, buf); + set_xen_guest_handle(sysctl.u.tmem_op.u.buf, buf); rc = do_sysctl(xch, &sysctl); @@ -133,7 +133,7 @@ int xc_tmem_control_oid(xc_interface *xch, } } - set_xen_guest_handle(sysctl.u.tmem_op.buf, buf); + set_xen_guest_handle(sysctl.u.tmem_op.u.buf, buf); rc = do_sysctl(xch, &sysctl); diff --git a/xen/common/tmem.c b/xen/common/tmem.c index 27164ce..ab354b6 100644 --- a/xen/common/tmem.c +++ b/xen/common/tmem.c @@ -1843,19 +1843,19 @@ int do_tmem_control(struct xen_sysctl_tmem_op *op) case XEN_SYSCTL_TMEM_OP_RESTORE_BEGIN: case XEN_SYSCTL_TMEM_OP_SAVE_END: ret = tmemc_save_subop(op->cli_id, pool_id, cmd, - guest_handle_cast(op->buf, char), op->arg1); + guest_handle_cast(op->u.buf, char), op->arg1); break; case XEN_SYSCTL_TMEM_OP_SAVE_GET_NEXT_PAGE: ret = tmemc_save_get_next_page(op->cli_id, pool_id, - guest_handle_cast(op->buf, char), op->arg1); + guest_handle_cast(op->u.buf, char), op->arg1); break; case XEN_SYSCTL_TMEM_OP_SAVE_GET_NEXT_INV: ret = tmemc_save_get_next_inv(op->cli_id, - guest_handle_cast(op->buf, char), op->arg1); + guest_handle_cast(op->u.buf, char), op->arg1); break; case XEN_SYSCTL_TMEM_OP_RESTORE_PUT_PAGE: ret = tmemc_restore_put_page(op->cli_id, pool_id, oidp, op->arg2, - guest_handle_cast(op->buf, char), op->arg1); + guest_handle_cast(op->u.buf, char), op->arg1); break; case XEN_SYSCTL_TMEM_OP_RESTORE_FLUSH_PAGE: ret = tmemc_restore_flush_page(op->cli_id, pool_id, oidp, op->arg2); diff --git a/xen/common/tmem_control.c b/xen/common/tmem_control.c index 8bb9d48..942d4c9 100644 --- a/xen/common/tmem_control.c +++ b/xen/common/tmem_control.c @@ -258,7 +258,7 @@ static int tmemc_list(domid_t cli_id, tmem_cli_va_param_t buf, uint32_t len, return 0; } -static int __tmemc_set_var(struct client *client, uint32_t subop, +static int __tmemc_set_var(struct client *client, XEN_GUEST_HANDLE_PARAM(xen_sysctl_tmem_client_t) buf) { domid_t cli_id = client->cli_id; @@ -267,11 +267,6 @@ static int __tmemc_set_var(struct client *client, uint32_t subop, ASSERT(client); - if ( subop != XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO ) - { - tmem_client_warn("tmem: unknown subop %d for tmemc_set_var\n", subop); - return -1; - } if ( copy_from_guest(&info, buf, 1) ) return -EFAULT; @@ -296,20 +291,17 @@ static int __tmemc_set_var(struct client *client, uint32_t subop, return 0; } -static int tmemc_set_var(domid_t cli_id, uint32_t subop, - XEN_GUEST_HANDLE_PARAM(void) buf) +static int tmemc_set_client_info(domid_t cli_id, + XEN_GUEST_HANDLE_PARAM(xen_sysctl_tmem_client_t) info) { struct client *client; int ret = -ENOENT; - XEN_GUEST_HANDLE_PARAM(xen_sysctl_tmem_client_t) info; - - info = guest_handle_cast(buf, xen_sysctl_tmem_client_t); if ( cli_id == TMEM_CLI_ID_NULL ) { list_for_each_entry(client,&tmem_global.client_list,client_list) { - ret = __tmemc_set_var(client, subop, info); + ret = __tmemc_set_var(client, info); if (ret) break; } @@ -318,11 +310,32 @@ static int tmemc_set_var(domid_t cli_id, uint32_t subop, { client = tmem_client_from_cli_id(cli_id); if ( client ) - ret = __tmemc_set_var(client, subop, info); + ret = __tmemc_set_var(client, info); } return ret; } +static int tmemc_get_client_info(int cli_id, + XEN_GUEST_HANDLE_PARAM(xen_sysctl_tmem_client_t) info) +{ + struct client *client = tmem_client_from_cli_id(cli_id); + + if ( client ) + { + if ( copy_to_guest(info, &client->info, 1) ) + return -EFAULT; + } + else + { + xen_sysctl_tmem_client_t generic = { .version = TMEM_SPEC_VERSION, + .maxpools = MAX_POOLS_PER_DOMAIN }; + if ( copy_to_guest(info, &generic, 1) ) + return -EFAULT; + } + + return 0; +} + static int tmemc_save_subop(int cli_id, uint32_t pool_id, uint32_t subop, XEN_GUEST_HANDLE_PARAM(void) buf, uint32_t arg1) { @@ -330,27 +343,9 @@ static int tmemc_save_subop(int cli_id, uint32_t pool_id, uint32_t subop, struct tmem_pool *pool = (client == NULL || pool_id >= MAX_POOLS_PER_DOMAIN) ? NULL : client->pools[pool_id]; int rc = -1; - XEN_GUEST_HANDLE_PARAM(xen_sysctl_tmem_client_t) info; switch(subop) { - case XEN_SYSCTL_TMEM_OP_GET_CLIENT_INFO: - rc = 0; - info = guest_handle_cast(buf, xen_sysctl_tmem_client_t); - if ( client ) - { - if ( copy_to_guest(info, &client->info, 1) ) - rc = -EFAULT; - } - else - { - xen_sysctl_tmem_client_t generic = { .version = TMEM_SPEC_VERSION, - .maxpools = MAX_POOLS_PER_DOMAIN }; - - if ( copy_to_guest(info, &generic, 1) ) - rc = -EFAULT; - } - break; case XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_FLAGS: if ( pool == NULL ) break; @@ -400,21 +395,24 @@ int tmem_control(struct xen_sysctl_tmem_op *op) break; case XEN_SYSCTL_TMEM_OP_LIST: ret = tmemc_list(op->cli_id, - guest_handle_cast(op->buf, char), op->arg1, op->arg2); + guest_handle_cast(op->u.buf, char), op->arg1, op->arg2); break; case XEN_SYSCTL_TMEM_OP_SET_CLIENT_INFO: - ret = tmemc_set_var(op->cli_id, cmd, - guest_handle_cast(op->buf, void)); + ret = tmemc_set_client_info(op->cli_id, + guest_handle_cast(op->u.client, xen_sysctl_tmem_client_t)); break; case XEN_SYSCTL_TMEM_OP_QUERY_FREEABLE_MB: ret = tmem_freeable_pages() >> (20 - PAGE_SHIFT); break; case XEN_SYSCTL_TMEM_OP_GET_CLIENT_INFO: + ret = tmemc_get_client_info(op->cli_id, + guest_handle_cast(op->u.client, xen_sysctl_tmem_client_t)); + break; case XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_FLAGS: case XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_NPAGES: case XEN_SYSCTL_TMEM_OP_SAVE_GET_POOL_UUID: ret = tmemc_save_subop(op->cli_id, pool_id, cmd, - guest_handle_cast(op->buf, void), op->arg1); + guest_handle_cast(op->u.buf, void), op->arg1); break; default: ret = do_tmem_control(op); diff --git a/xen/include/public/sysctl.h b/xen/include/public/sysctl.h index 27e051b..52898a7 100644 --- a/xen/include/public/sysctl.h +++ b/xen/include/public/sysctl.h @@ -782,8 +782,8 @@ struct tmem_handle { }; /* - * XEN_SYSCTL_TMEM_OP_[GET,SAVE]_CLIENT overrides the 'buf' in - * xen_sysctl_tmem_op with this structure - and contain data used + * XEN_SYSCTL_TMEM_OP_[GET,SAVE]_CLIENT uses the 'client' in + * xen_sysctl_tmem_op with this structure - which is mostly used * during migration. */ struct tmem_client { @@ -812,8 +812,11 @@ struct xen_sysctl_tmem_op { uint32_t arg2; /* IN: If not applicable to command use 0. */ uint32_t pad; /* Padding so structure is the same under 32 and 64. */ xen_tmem_oid_t oid; /* IN: If not applicable to command use 0s. */ - XEN_GUEST_HANDLE_64(char) buf; /* IN/OUT: Buffer to save/restore, - and set/get ops. */ + union { + XEN_GUEST_HANDLE_64(char) buf; /* IN/OUT: Buffer to save/restore */ + XEN_GUEST_HANDLE_64(xen_sysctl_tmem_client_t) client; /* IN/OUT for */ + /* XEN_SYSCTL_TMEM_OP_[GET,SAVE]_CLIENT. */ + } u; }; typedef struct xen_sysctl_tmem_op xen_sysctl_tmem_op_t; DEFINE_XEN_GUEST_HANDLE(xen_sysctl_tmem_op_t);