From patchwork Thu Aug 25 13:37:27 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: 9299359 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 D8BD160459 for ; Thu, 25 Aug 2016 13:40:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF8C829335 for ; Thu, 25 Aug 2016 13:40:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B45A229336; Thu, 25 Aug 2016 13:40:17 +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 0D24829336 for ; Thu, 25 Aug 2016 13:40:16 +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 1bcur9-00010a-Ss; Thu, 25 Aug 2016 13:38:07 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bcur8-0000vM-Sq for xen-devel@lists.xenproject.org; Thu, 25 Aug 2016 13:38:06 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id 77/2F-08498-DB4FEB75; Thu, 25 Aug 2016 13:38:05 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRWlGSWpSXmKPExsUyZ7p8oO6eL/v CDT7clbf4vmUykwOjx+EPV1gCGKNYM/OS8isSWDNOTpnNXDBDpuLS9bksDYzLxLsYuTiEBCYz SXybt5cRwvnCKPF2XQsrhLORUWJt/1smCGcao0TjwQdADgcHm4CJxJtVjiBxEYE+RonDRzcxd zFycjCDOPtOg9nCAv4Sc7e9ZASxWQRUJc6s+AJm8wq4S0w8vIAZZI6EgLzEs9v1IGFOoPDvhs 1sILaQgJvE90sdLCC2hICxRPvbi2wTGPkWMDKsYtQoTi0qSy3SNTTVSyrKTM8oyU3MzNE1NDD Ty00tLk5MT81JTCrWS87P3cQIDBUGINjB+G1ZwCFGSQ4mJVFe7RX7woX4kvJTKjMSizPii0pz UosPMcpwcChJ8E75DJQTLEpNT61Iy8wBBi1MWoKDR0mEdx1Imre4IDG3ODMdInWKUVFKnLcKJ CEAksgozYNrg0XKJUZZKWFeRqBDhHgKUotyM0tQ5V8xinMwKgnzVoNM4cnMK4Gb/gpoMRPQ4p b7u0EWlyQipKQaGJmZn03dnfQsWsFPrPfBnNQJVS92h5bPq33HmOXPeV5MPNW06N8xj+nJuWs aTD/E2ywQDkneJLRsXX9x0bkLhf96VLZpprBsK18nz/j47svsPzvm8vxTkm6Sfyh2dh/zmkk1 z08vXLrl/PFd4ub/1UW/l75vW21f3fi42VAvvEJD+ubCjy/W6iuxFGckGmoxFxUnAgCZ7VSxj wIAAA== X-Env-Sender: konrad.wilk@oracle.com X-Msg-Ref: server-15.tower-27.messagelabs.com!1472132283!2907991!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 60983 invoked from network); 25 Aug 2016 13:38:04 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-15.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 25 Aug 2016 13:38:04 -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 u7PDbtZJ030575 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 25 Aug 2016 13:37:56 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id u7PDbtdp009335 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 25 Aug 2016 13:37:55 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u7PDbsHv026079; Thu, 25 Aug 2016 13:37:54 GMT Received: from localhost.event.rightround.com (/75.98.193.200) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 25 Aug 2016 06:37:54 -0700 From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, konrad@kernel.org, ross.lagerwall@citrix.com, sstabellini@kernel.org, julien.grall@arm.com Date: Thu, 25 Aug 2016 09:37:27 -0400 Message-Id: <1472132255-23470-13-git-send-email-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.4.11 In-Reply-To: <1472132255-23470-1-git-send-email-konrad.wilk@oracle.com> References: <1472132255-23470-1-git-send-email-konrad.wilk@oracle.com> X-Source-IP: aserv0022.oracle.com [141.146.126.234] Cc: Andrew Cooper , Jan Beulich , Konrad Rzeszutek Wilk Subject: [Xen-devel] [PATCH v2 12/20] x86, arm: Change arch_livepatch_quiesce() decleration. 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 On ARM we need an alternative VA region to poke in the hypervisor .text data. And since this is setup during runtime we may fail (it uses vmap so most likely error is ENOMEM). As such this error needs to be bubbled up and also abort the livepatching if it occurs. Signed-off-by: Konrad Rzeszutek Wilk Reviewed-by: Andrew Cooper Reviewed-by: Julien Grall --- Cc: Stefano Stabellini Cc: Julien Grall Cc: Jan Beulich Cc: Andrew Cooper v2: Initial submission. Spun of from "livepatch: Initial ARM64 support" --- xen/arch/arm/livepatch.c | 3 ++- xen/arch/x86/livepatch.c | 4 +++- xen/common/livepatch.c | 16 ++++++++++++++-- xen/include/xen/livepatch.h | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/livepatch.c b/xen/arch/arm/livepatch.c index aba1320..755f596 100644 --- a/xen/arch/arm/livepatch.c +++ b/xen/arch/arm/livepatch.c @@ -7,8 +7,9 @@ #include #include -void arch_livepatch_quiesce(void) +int arch_livepatch_quiesce(void) { + return -ENOSYS; } void arch_livepatch_revive(void) diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c index 67dda07..5491c09 100644 --- a/xen/arch/x86/livepatch.c +++ b/xen/arch/x86/livepatch.c @@ -16,10 +16,12 @@ #define PATCH_INSN_SIZE 5 #define MAX_INSN_SIZE 15 -void arch_livepatch_quiesce(void) +int arch_livepatch_quiesce(void) { /* Disable WP to allow changes to read-only pages. */ write_cr0(read_cr0() & ~X86_CR0_WP); + + return 0; } void arch_livepatch_revive(void) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 7e36d97..7d21326 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -1088,6 +1088,7 @@ static int livepatch_list(xen_sysctl_livepatch_list_t *list) static int apply_payload(struct payload *data) { unsigned int i; + int rc; printk(XENLOG_INFO LIVEPATCH "%s: Applying %u functions\n", data->name, data->nfuncs); @@ -1096,7 +1097,12 @@ static int apply_payload(struct payload *data) for ( i = 0; i < data->n_bss; i++ ) memset(data->bss[i], 0, data->bss_size[i]); - arch_livepatch_quiesce(); + rc = arch_livepatch_quiesce(); + if ( rc ) + { + printk(XENLOG_ERR LIVEPATCH "%s: unable to quiesce!\n", data->name); + return rc; + } /* * Since we are running with IRQs disabled and the hooks may call common @@ -1128,10 +1134,16 @@ static int apply_payload(struct payload *data) static int revert_payload(struct payload *data) { unsigned int i; + int rc; printk(XENLOG_INFO LIVEPATCH "%s: Reverting\n", data->name); - arch_livepatch_quiesce(); + rc = arch_livepatch_quiesce(); + if ( rc ) + { + printk(XENLOG_ERR LIVEPATCH "%s: unable to quiesce!\n", data->name); + return rc; + } for ( i = 0; i < data->nfuncs; i++ ) arch_livepatch_revert_jmp(&data->funcs[i]); diff --git a/xen/include/xen/livepatch.h b/xen/include/xen/livepatch.h index 2e64686..6f30c0d 100644 --- a/xen/include/xen/livepatch.h +++ b/xen/include/xen/livepatch.h @@ -72,7 +72,7 @@ int arch_livepatch_verify_func(const struct livepatch_func *func); * These functions are called around the critical region patching live code, * for an architecture to take make appropratie global state adjustments. */ -void arch_livepatch_quiesce(void); +int arch_livepatch_quiesce(void); void arch_livepatch_revive(void); void arch_livepatch_apply_jmp(struct livepatch_func *func);