From patchwork Mon Sep 19 17:02:33 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: 9339933 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 A8297607D0 for ; Mon, 19 Sep 2016 17:05:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9256128577 for ; Mon, 19 Sep 2016 17:05:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8480E29391; Mon, 19 Sep 2016 17:05:23 +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 7A4F228577 for ; Mon, 19 Sep 2016 17:05:22 +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 1bm1xx-0004TE-AP; Mon, 19 Sep 2016 17:02:49 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bm1xw-0004T8-A6 for xen-devel@lists.xenproject.org; Mon, 19 Sep 2016 17:02:48 +0000 Received: from [85.158.137.68] by server-7.bemta-3.messagelabs.com id CF/1A-03271-73A10E75; Mon, 19 Sep 2016 17:02:47 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMIsWRWlGSWpSXmKPExsUyZ7p8oK6Z1IN wg1O7LC2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyWrxsYC6bqVHz91sPawNis0sXIxSEkMJFJ 4uf0fnYI5y+jxIalE1ggnI2MEuvO3IRyehklHj74yNjFyMnBIqAqsXH7DaAWDg42AROJN6scQ cIiAsoSvb9+s4DYzALFEht+bgIrFxZwlfhx+RwriM0rYCVx795xqG0zmST2dm9ngkgISpyc+Q SqWUvixr+XTCDzmQWkJZb/4wAJcwrYS/x9vwxsjijQroYZD5hBbAkBQ4nPG5cyT2AUnIVk0iw kk2YhTFrAyLyKUaM4tagstUjX0EQvqSgzPaMkNzEzR9fQwFgvN7W4ODE9NScxqVgvOT93EyMw cBmAYAfjiu2ehxglOZiURHnl+B6EC/El5adUZiQWZ8QXleakFh9ilOHgUJLgXSIBlBMsSk1Pr UjLzAHGEExagoNHSYRXUBIozVtckJhbnJkOkTrFqCglznsGpE8AJJFRmgfXBovbS4yyUsK8jE CHCPEUpBblZpagyr9iFOdgVBLmvQcyhSczrwRu+iugxUxAixl77oMsLklESEk1MB75VyItJhD xjHur1vcDW3d65seXLvG4K3NY5aao4Uu/DO5f19hYdm1dei/ydGqaadODM0wWHrt/Js4IucFf kMecvoBlH7+U0iqD+Q9OhDWu2m4qqxqyWNT/b2wjF99LmWZXvrSyaeWOL47v2hjkXyaYubyov fPX3rlMl1wrmYrb1k5qPan9QYmlOCPRUIu5qDgRANy+dLzWAgAA X-Env-Sender: konrad.wilk@oracle.com X-Msg-Ref: server-14.tower-31.messagelabs.com!1474304565!61542706!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 41268 invoked from network); 19 Sep 2016 17:02:46 -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; 19 Sep 2016 17:02:46 -0000 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u8JH2c7N026470 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Sep 2016 17:02:38 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u8JH2bbp014820 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 19 Sep 2016 17:02:37 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id u8JH2acl032259; Mon, 19 Sep 2016 17:02:36 GMT Received: from localhost.localdomain (/172.58.217.56) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 19 Sep 2016 10:02:36 -0700 Date: Mon, 19 Sep 2016 13:02:33 -0400 From: Konrad Rzeszutek Wilk To: Jan Beulich Message-ID: <20160919170233.GC30790@localhost.localdomain> References: <1474039754-25816-1-git-send-email-konrad.wilk@oracle.com> <1474039754-25816-4-git-send-email-konrad.wilk@oracle.com> <57DFC514020000780010FDBF@prv-mh.provo.novell.com> <20160919161158.GC9860@localhost.localdomain> <57E02EFB020000780011041A@prv-mh.provo.novell.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <57E02EFB020000780011041A@prv-mh.provo.novell.com> User-Agent: Mutt/1.6.1 (2016-04-27) X-Source-IP: userv0022.oracle.com [156.151.31.74] Cc: andrew.cooper3@citrix.com, xen-devel@lists.xenproject.org, ross.lagerwall@citrix.com Subject: Re: [Xen-devel] [PATCH v6 3/6] livepatch: NOP if func->new_addr is zero. 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Mon, Sep 19, 2016 at 10:31:23AM -0600, Jan Beulich wrote: > >>> On 19.09.16 at 18:11, wrote: > > On Mon, Sep 19, 2016 at 02:59:32AM -0600, Jan Beulich wrote: > >> >>> On 16.09.16 at 17:29, wrote: > >> > @@ -31,11 +30,11 @@ void arch_livepatch_revive(void) > >> > > >> > int arch_livepatch_verify_func(const struct livepatch_func *func) > >> > { > >> > - /* No NOP patching yet. */ > >> > - if ( !func->new_size ) > >> > + /* If NOPing only do up to maximum amount we can put in the ->opaque. */ > >> > + if ( !func->new_addr && func->new_size > sizeof(func->opaque) ) > >> > return -EOPNOTSUPP; > >> > > >> > - if ( func->old_size < PATCH_INSN_SIZE ) > >> > + if ( func->old_size < ARCH_PATCH_INSN_SIZE ) > >> > return -EINVAL; > >> > >> Is that indeed a requirement when NOPing? You can easily NOP out > >> just a single byte on x86. Or shouldn't in that case old_size == new_size > >> anyway? In which case the comment further down stating that new_size > > > > The original intent behind .old_size was to guard against patching > > functions that were less than our relative jump. > > > > (The tools end up computing the .old_size as the size of the whole function > > which is fine). > > > > But with this NOPing support, you are right - we could have now an > > function that is say 4 bytes long and we only need to NOP three bytes > > out of it (the last instruction I assume would be 'ret'). > > > > So perhaps this check needs just needs an 'else if' , like so: > > > > int arch_livepatch_verify_func(const struct livepatch_func *func) > > { > > /* If NOPing.. */ > > if ( !func->new_addr ) > > { > > /* Only do up to maximum amount we can put in the ->opaque. */ > > if ( func->new_size > sizeof(func->opaque) ) > > return -EOPNOTSUPP; > > > > /* One instruction for 'ret' and the other to NOP. */ > > if ( func->old_size < 2 ) > > return -EINVAL; > > } > > else if ( func->old_size < ARCH_PATCH_INSN_SIZE ) > > return -EINVAL; > > > > return 0; > > } > > Except that I wouldn't use 2, to not exclude patching out some > single byte in the middle of a function, without regard to what the > function's actual size is. Uh-uh. The _new_size_ determines how many bytes to NOP (in the context of this patch). The old_size (where we check to be at min 2) is a safety valve to make sure we don't NOP something outside the function. ..snip.. > >> NOP addition here, perhaps worth dropping the _jmp from the > >> function name (and its revert counterpart)? > > > > Ooh, good idea. But I think it maybe better as a seperate patch (as it > > also touches the ARM code). > > That's in the other series, isn't it? It expands the existing ones. Right now in 'staging' branch we have an arch/arm/livepatch.c which has these functions in it. Granted nothing compiles them, so I could break it in this patch. But I already cobbled up the patch so may as well use it? From 45abdd6a0c3a6a2ca7180c7340032ac5b2b186a4 Mon Sep 17 00:00:00 2001 From: Konrad Rzeszutek Wilk Date: Mon, 19 Sep 2016 12:20:27 -0400 Subject: [PATCH] livepatch: Drop _jmp from arch_livepatch_[apply,revert]_jmp With "livepatch: NOP if func->new_addr is zero." that name makes no more sense. Suggested-by: Jan Beulich Signed-off-by: Konrad Rzeszutek Wilk --- v7: New submission --- xen/arch/arm/livepatch.c | 4 ++-- xen/arch/x86/livepatch.c | 4 ++-- xen/include/xen/livepatch.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/livepatch.c b/xen/arch/arm/livepatch.c index 755f596..7f067a0 100644 --- a/xen/arch/arm/livepatch.c +++ b/xen/arch/arm/livepatch.c @@ -21,11 +21,11 @@ int arch_livepatch_verify_func(const struct livepatch_func *func) return -ENOSYS; } -void arch_livepatch_apply_jmp(struct livepatch_func *func) +void arch_livepatch_apply(struct livepatch_func *func) { } -void arch_livepatch_revert_jmp(const struct livepatch_func *func) +void arch_livepatch_revert(const struct livepatch_func *func) { } diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c index 118770e..36bbc5f 100644 --- a/xen/arch/x86/livepatch.c +++ b/xen/arch/x86/livepatch.c @@ -47,7 +47,7 @@ int arch_livepatch_verify_func(const struct livepatch_func *func) return 0; } -void arch_livepatch_apply_jmp(struct livepatch_func *func) +void arch_livepatch_apply(struct livepatch_func *func) { uint8_t *old_ptr; uint8_t insn[sizeof(func->opaque)]; @@ -76,7 +76,7 @@ void arch_livepatch_apply_jmp(struct livepatch_func *func) memcpy(old_ptr, insn, len); } -void arch_livepatch_revert_jmp(const struct livepatch_func *func) +void arch_livepatch_revert(const struct livepatch_func *func) { memcpy(func->old_addr, func->opaque, livepatch_insn_len(func)); } diff --git a/xen/include/xen/livepatch.h b/xen/include/xen/livepatch.h index 174af06..b7f66d4 100644 --- a/xen/include/xen/livepatch.h +++ b/xen/include/xen/livepatch.h @@ -86,8 +86,8 @@ unsigned int livepatch_insn_len(const struct livepatch_func *func) int arch_livepatch_quiesce(void); void arch_livepatch_revive(void); -void arch_livepatch_apply_jmp(struct livepatch_func *func); -void arch_livepatch_revert_jmp(const struct livepatch_func *func); +void arch_livepatch_apply(struct livepatch_func *func); +void arch_livepatch_revert(const struct livepatch_func *func); void arch_livepatch_post_action(void); void arch_livepatch_mask(void);