From patchwork Mon Nov 14 22:12:52 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: 9428509 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 45EBB60755 for ; Mon, 14 Nov 2016 22:15:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4788928AD3 for ; Mon, 14 Nov 2016 22:15:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 387542874C; Mon, 14 Nov 2016 22:15:53 +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 8DE062874C for ; Mon, 14 Nov 2016 22:15:51 +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 1c6PVQ-0006Cs-Ux; Mon, 14 Nov 2016 22:13:36 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c6PVP-0006Ck-Le for xen-devel@lists.xenproject.org; Mon, 14 Nov 2016 22:13:35 +0000 Received: from [85.158.143.35] by server-9.bemta-6.messagelabs.com id 1A/4D-16838-E073A285; Mon, 14 Nov 2016 22:13:34 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFmpnkeJIrShJLcpLzFFi42KZM10+UJfPXCv CYPsidovvWyYzOTB6HP5whSWAMYo1My8pvyKBNePq5q9sBT2KFZs7JzE1MHZIdzFycQgJTGaS ePTyFyOE841R4vrmXvYuRk4gZyOjxNG/URCJXkaJrZ+OsnYxcnCwCZhIvFnlCFIjIhAn8ePrR TYQm1kgX2LmvHdgtrCAj8TXbc/A5rAIqEqc+zqdBcTmFXCTWN35gQnElhCQk9i2ZQ8jiM0p4C 7xZt9UZoi9bhIPT3cyQtQYS7S/vcg2gZFvASPDKkaN4tSistQiXWMjvaSizPSMktzEzBxdQwM zvdzU4uLE9NScxKRiveT83E2MwEBhAIIdjKfXBR5ilORgUhLlVVDVihDiS8pPqcxILM6ILyrN SS0+xCjDwaEkwbvBFCgnWJSanlqRlpkDDFmYtAQHj5II7y2QNG9xQWJucWY6ROoUoy7Hm10vH zAJseTl56VKifPWgBQJgBRllObBjYDFzyVGWSlhXkago4R4ClKLcjNLUOVfMYpzMCoJ8y4Bmc KTmVcCt+kV0BFMQEfsMtcAOaIkESEl1cC4ykxpFb9ufuG+J588/vzdYR9vcm/+heQv1W43Ciq t2t/InNrMorf176tdYc7Tk/+u1gr52HBSt7GDR3lT+7Sq7J/nM4NnC/QWKQvGXstf/5Q7/fKJ hlPZejLre+Q0l355zeMnnl79ykbmalZrrvPCHpaDLF0n9k/XT398ILNzn1rar22/k74psRRnJ BpqMRcVJwIAerBv4poCAAA= X-Env-Sender: konrad.wilk@oracle.com X-Msg-Ref: server-2.tower-21.messagelabs.com!1479161612!29333405!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: 9.0.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 18334 invoked from network); 14 Nov 2016 22:13:33 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-2.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 14 Nov 2016 22:13:33 -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 uAEMD7oT022199 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 14 Nov 2016 22:13:08 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.13.8) with ESMTP id uAEMD7TK031753 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 14 Nov 2016 22:13:07 GMT Received: from abhmp0012.oracle.com (abhmp0012.oracle.com [141.146.116.18]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id uAEMD5Y5024110; Mon, 14 Nov 2016 22:13:06 GMT Received: from x230.dumpdata.com.com (/10.154.98.119) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 14 Nov 2016 14:13:03 -0800 From: Konrad Rzeszutek Wilk To: david.vrabel@citrix.com, xen-devel@lists.xenproject.org, kexec@lists.infradead.org Date: Mon, 14 Nov 2016 17:12:52 -0500 Message-Id: <1479161573-12671-2-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1479161573-12671-1-git-send-email-konrad.wilk@oracle.com> References: <1479161573-12671-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: aserv0022.oracle.com [141.146.126.234] Cc: elena.ufimtseva@oracle.com, daniel.kiper@oracle.com, Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v1 1/2] xen/kexec: Find out whether an kexec type is loaded. 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 tools that use kexec are asynchronous in nature and do not keep state changes. As such provide an hypercall to find out whether an image has been loaded for either type. Note: No need to modify XSM as it has one size fits all check and does not check for subcommands. Signed-off-by: Konrad Rzeszutek Wilk --- v0: Internal version. v1: Dropped Reviewed-by, posting on xen-devel. CC: Elena Ufimtseva CC: Daniel Kiper --- tools/libxc/include/xenctrl.h | 8 ++++++++ tools/libxc/xc_kexec.c | 27 +++++++++++++++++++++++++++ xen/common/kexec.c | 25 +++++++++++++++++++++++++ xen/include/public/kexec.h | 11 +++++++++++ 4 files changed, 71 insertions(+) diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h index 2c83544..aa5d798 100644 --- a/tools/libxc/include/xenctrl.h +++ b/tools/libxc/include/xenctrl.h @@ -2574,6 +2574,14 @@ int xc_kexec_load(xc_interface *xch, uint8_t type, uint16_t arch, */ int xc_kexec_unload(xc_interface *xch, int type); +/* + * Find out whether the image has been succesfully loaded. + * + * The can be either KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH. + * If zero is returned that means the image is loaded for the type. + */ +int xc_kexec_status(xc_interface *xch, int type); + typedef xenpf_resource_entry_t xc_resource_entry_t; /* diff --git a/tools/libxc/xc_kexec.c b/tools/libxc/xc_kexec.c index 1cceb5d..95d36ff 100644 --- a/tools/libxc/xc_kexec.c +++ b/tools/libxc/xc_kexec.c @@ -126,3 +126,30 @@ out: return ret; } + +int xc_kexec_status(xc_interface *xch, int type) +{ + DECLARE_HYPERCALL; + DECLARE_HYPERCALL_BUFFER(xen_kexec_status_t, status); + int ret = -1; + + status = xc_hypercall_buffer_alloc(xch, status, sizeof(*status)); + if ( status == NULL ) + { + PERROR("Count not alloc buffer for kexec status hypercall"); + goto out; + } + + status->type = type; + + hypercall.op = __HYPERVISOR_kexec_op; + hypercall.arg[0] = KEXEC_CMD_kexec_status; + hypercall.arg[1] = HYPERCALL_BUFFER_AS_ARG(status); + + ret = do_xen_hypercall(xch, &hypercall); + +out: + xc_hypercall_buffer_free(xch, status); + + return ret; +} diff --git a/xen/common/kexec.c b/xen/common/kexec.c index c83d48f..1148f85 100644 --- a/xen/common/kexec.c +++ b/xen/common/kexec.c @@ -1169,6 +1169,28 @@ static int kexec_unload(XEN_GUEST_HANDLE_PARAM(void) uarg) return kexec_do_unload(&unload); } +static int kexec_status(XEN_GUEST_HANDLE_PARAM(void) uarg) +{ + xen_kexec_status_t status; + int base, bit, pos; + + if ( unlikely(copy_from_guest(&status, uarg, 1)) ) + return -EFAULT; + + if ( test_bit(KEXEC_FLAG_IN_PROGRESS, &kexec_flags) ) + return -EBUSY; + + if ( kexec_load_get_bits(status.type, &base, &bit) ) + return -EINVAL; + + pos = (test_bit(bit, &kexec_flags) != 0); + + if ( !test_bit(base + pos, &kexec_flags) ) + return -ENOENT; + + return 0; +} + static int do_kexec_op_internal(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) uarg, bool_t compat) @@ -1208,6 +1230,9 @@ static int do_kexec_op_internal(unsigned long op, case KEXEC_CMD_kexec_unload: ret = kexec_unload(uarg); break; + case KEXEC_CMD_kexec_status: + ret = kexec_status(uarg); + break; } return ret; diff --git a/xen/include/public/kexec.h b/xen/include/public/kexec.h index a6a0a88..29dcb5d 100644 --- a/xen/include/public/kexec.h +++ b/xen/include/public/kexec.h @@ -227,6 +227,17 @@ typedef struct xen_kexec_unload { } xen_kexec_unload_t; DEFINE_XEN_GUEST_HANDLE(xen_kexec_unload_t); +/* + * Figure out whether we have an image loaded. An return value of + * zero indicates success while XEN_ENODEV implies no image loaded. + * + * Type must be one of KEXEC_TYPE_DEFAULT or KEXEC_TYPE_CRASH. + */ +#define KEXEC_CMD_kexec_status 6 +typedef struct xen_kexec_status { + uint8_t type; +} xen_kexec_status_t; +DEFINE_XEN_GUEST_HANDLE(xen_kexec_status_t); #else /* __XEN_INTERFACE_VERSION__ < 0x00040400 */ #define KEXEC_CMD_kexec_load KEXEC_CMD_kexec_load_v1