From patchwork Tue Sep 12 00:37:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Konrad Rzeszutek Wilk X-Patchwork-Id: 9948235 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 C705A603F4 for ; Tue, 12 Sep 2017 00:41:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B920228D5E for ; Tue, 12 Sep 2017 00:41:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA4C928DA2; Tue, 12 Sep 2017 00:41:10 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RCVD_IN_SORBS_SPAM,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 24B6228D5E for ; Tue, 12 Sep 2017 00:41:04 +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 1drZDI-0000mC-0M; Tue, 12 Sep 2017 00:38:04 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drZDH-0000kt-5r for xen-devel@lists.xenproject.org; Tue, 12 Sep 2017 00:38:03 +0000 Received: from [85.158.143.35] by server-7.bemta-6.messagelabs.com id 4F/E6-03610-A6C27B95; Tue, 12 Sep 2017 00:38:02 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrAIsWRWlGSWpSXmKPExsVyMfTOId0Mne2 RBtO6DCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyvF7+wFMyUqdja7tLA+Fq8i5GLQ0hgBqPE lV+n2UEcFoEPLBJ77q5kBnEkBKaxSizctAbI4QRy4iQevV7PCGGnSay9uIENwq6WWLBuP1hcS EBJYsvkx4wQYw8ySex5M4sVJCEsoCcx+dttsCI2AX2Jp2uvAQ3lAGp2k/h0jQukXkSgnVFi9p VfYPXMAoYSrW+PskH0+ku83NwBdgSLgKpE//ZbYHFeASuJ1h13oQ6Sl5jYOw3M5gSK//4xjxX iIEuJjgVXmCYwCi9gZFjFqFGcWlSWWqRraKGXVJSZnlGSm5iZo2toYKaXm1pcnJiempOYVKyX nJ+7iREYogxAsIPx5saAQ4ySHExKory/hbdHCvEl5adUZiQWZ8QXleakFh9ilOHgUJLgfaEFl BMsSk1PrUjLzAFGC0xagoNHSYSXCxgxQrzFBYm5xZnpEKlTjJYcF+5c+sPEcWDPLSDZcfPuHy Yhlrz8vFQpcd4ibaAGAZCGjNI8uHGwiL7EKCslzMsIdKAQT0FqUW5mCar8K0ZxDkYlYd5kkCk 8mXklcFtfAR3EBHQQz6UtIAeVJCKkpBoYbXhOcmyZF/izV1nijuY98WJlo8P2y25tzDj2e8+M P0kL7WqsvxufWblz6deqw70dP9wWJR/hW+L/pWpGTrDnJvGeNR5XBMT38K5/pWSy9wK73baSj maJH+brL3fvDGAs2im1sm11/4+aG3trs97Wqzir659JefR3j9MON8eNa9+/YpmxWifigxJLcU aioRZzUXEiANXjKgPjAgAA X-Env-Sender: ketuzsezr@gmail.com X-Msg-Ref: server-12.tower-21.messagelabs.com!1505176679!82315270!1 X-Originating-IP: [209.85.220.194] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 46270 invoked from network); 12 Sep 2017 00:38:00 -0000 Received: from mail-qk0-f194.google.com (HELO mail-qk0-f194.google.com) (209.85.220.194) by server-12.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 12 Sep 2017 00:38:00 -0000 Received: by mail-qk0-f194.google.com with SMTP id c69so6371777qke.5 for ; Mon, 11 Sep 2017 17:38:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=PE0n1vPL+dQHzPklf+NKUwzYOdpd8u3ZBe3Fp793YTA=; b=V/gDVZNHiDZZTjX6RFF1q1pBF6HdpoVDg4sq1ot13emcRcsHCSCHiuuAqtRijSTqPl mjdPJmF6hQzUyG8DgiarPKbuMOm07bEQW1UysnnzWMBOBtTR1jgjX+Ks7IZj/uRIwa7Y cmoNeQmaBqMW2PBsmnCKNto1A4dVleEslbOMwgI53cRrcXUFNVac3cq5MnXMjWxlzLqe JJXpoxYLr9UzhGBnFaEJBfOp9T+uhfaPPiviNJMMUfERnYrTS8FX1qt3oNbeUN0JeEt/ /VAsiOmrwbNQuZSldFb7wVh35GCviq8Dnkm6nY3i4hBA+BEfSOfS5GllcZgRp1G916n9 Jk6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=PE0n1vPL+dQHzPklf+NKUwzYOdpd8u3ZBe3Fp793YTA=; b=o2d1sO+nY3kIByzTbljOgxkgph+tZa/qlOqFN8Vv2goTlBcSs3cq60BcBpXiYzbtBs P9QbKIttnS+wyBQaT5SugZy/PA0haIHROLR6dpMBjDhc7YmMJmld61W4U4pFStAbLe4p XU95eEfgvAOg7DGdp3HWsmqgkgyoMKLLLzMwCAK/oHTqHaup3S1cyjNbeWIrN/jVeMnk sZ96FXzkl0DNzfp1Ayfb27rXTsDqYBPU++K1wOTB3XtBmbpVxa8mIUrtHIIcE0JuvngG 9XjKp+PcBZJYcRG5HOsPm+/Ro9/WDLDwBj3xJ4gDmoO0OGkTGhIs/OdT/+b8cutamSDY fI8w== X-Gm-Message-State: AHPjjUjOOU2p3UM82FqCfxn6aiHYTAHdvphBASBWXDlRMmS/AUi/PTIH +NEFiie8jYUr2T8L X-Google-Smtp-Source: AOwi7QBCIT0cmz9FCfcSQW10uO9lgeXXHddI2xQfZss631iaRXrkgphZmCq3Ke81KVPEKYj1ISxDtw== X-Received: by 10.55.146.195 with SMTP id u186mr16810885qkd.14.1505176679393; Mon, 11 Sep 2017 17:37:59 -0700 (PDT) Received: from localhost.localdomain (209-6-200-48.s4398.c3-0.smr-ubr2.sbo-smr.ma.cable.rcncustomer.com. [209.6.200.48]) by smtp.gmail.com with ESMTPSA id z75sm6771034qkb.71.2017.09.11.17.37.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Sep 2017 17:37:58 -0700 (PDT) From: Konrad Rzeszutek Wilk X-Google-Original-From: Konrad Rzeszutek Wilk To: xen-devel@lists.xenproject.org, ross.lagerwall@citrix.com, konrad.wilk@oracle.com, julien.grall@arm.com, sstabellini@kernel.org Date: Mon, 11 Sep 2017 20:37:21 -0400 Message-Id: <20170912003726.368-13-konrad.wilk@oracle.com> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170912003726.368-1-konrad.wilk@oracle.com> References: <20170912003726.368-1-konrad.wilk@oracle.com> Cc: andrew.cooper3@citrix.com, jbeulich@suse.com Subject: [Xen-devel] [PATCH v3 12/17] livepatch/x86/arm[32, 64]: Unify arch_livepatch_revert 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 arch_livepatch_revert is very similar between the platforms. Lets unify it as much as possible. Signed-off-by: Konrad Rzeszutek Wilk --- xen/arch/arm/livepatch.c | 10 +--------- xen/arch/x86/livepatch.c | 10 ++-------- xen/common/livepatch.c | 14 +++++++++++++- xen/include/xen/livepatch.h | 3 +-- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/xen/arch/arm/livepatch.c b/xen/arch/arm/livepatch.c index 2debb5368c..e1d5d58f97 100644 --- a/xen/arch/arm/livepatch.c +++ b/xen/arch/arm/livepatch.c @@ -39,16 +39,8 @@ int arch_livepatch_verify_func(const struct livepatch_func *func) return 0; } -void arch_livepatch_revert(const struct livepatch_func *func) +void arch_livepatch_revert(uint32_t *new_ptr, unsigned int len) { - uint32_t *new_ptr; - unsigned int len; - - new_ptr = func->old_addr - (void *)_start + livepatch_vmap.text; - - len = livepatch_insn_len(func); - memcpy(new_ptr, func->opaque, len); - clean_and_invalidate_dcache_va_range(new_ptr, len); } diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c index 5273f5a176..12287d445f 100644 --- a/xen/arch/x86/livepatch.c +++ b/xen/arch/x86/livepatch.c @@ -81,15 +81,9 @@ void noinline arch_livepatch_apply(struct livepatch_func *func) * "noinline" to cause control flow change and thus invalidate I$ and * cause refetch after modification. */ -void noinline arch_livepatch_revert(const struct livepatch_func *func) +void noinline arch_livepatch_revert(uint32_t *new_ptr, unsigned int len) { - uint32_t *new_ptr; - unsigned int len; - - new_ptr = func->old_addr - (void *)_start + livepatch_vmap.text; - - len = livepatch_insn_len(func); - memcpy(new_ptr, func->opaque, len); + /* Nothing to do. */ } /* diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index eb7d4098fd..93083cda1a 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -1128,6 +1128,18 @@ static void livepatch_revive(void) livepatch_vmap.offset = 0; } +static void livepatch_revert(const struct livepatch_func *func) +{ + uint32_t *new_ptr; + unsigned int len; + + new_ptr = func->old_addr - (void *)_start + livepatch_vmap.text; + + len = livepatch_insn_len(func); + memcpy(new_ptr, func->opaque, len); + + arch_livepatch_revert(new_ptr, len); +} /* * The following functions get the CPUs into an appropriate state and * apply (or revert) each of the payload's functions. This is needed @@ -1191,7 +1203,7 @@ static int revert_payload(struct payload *data) } for ( i = 0; i < data->nfuncs; i++ ) - arch_livepatch_revert(&data->funcs[i]); + livepatch_revert(&data->funcs[i]); /* * Since we are running with IRQs disabled and the hooks may call common diff --git a/xen/include/xen/livepatch.h b/xen/include/xen/livepatch.h index 1659ffcdf0..065c1a323a 100644 --- a/xen/include/xen/livepatch.h +++ b/xen/include/xen/livepatch.h @@ -117,11 +117,10 @@ extern struct livepatch_vmap_stash livepatch_vmap; * These functions are called around the critical region patching live code, * for an architecture to take make appropratie global state adjustments. */ -int arch_livepatch_quiesce(struct livepatch_func *func, unsigned int nfuncs); void arch_livepatch_revive(void); void arch_livepatch_apply(struct livepatch_func *func); -void arch_livepatch_revert(const struct livepatch_func *func); +void arch_livepatch_revert(uint32_t *new_ptr, unsigned int len); void arch_livepatch_post_action(void); void arch_livepatch_mask(void);