From patchwork Mon Sep 19 14:33:43 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: 9339571 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 9D67D6077A for ; Mon, 19 Sep 2016 14:36:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C8B529258 for ; Mon, 19 Sep 2016 14:36:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C67B29332; Mon, 19 Sep 2016 14:36:15 +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 17BA629258 for ; Mon, 19 Sep 2016 14:36:12 +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 1blzdz-000571-Cy; Mon, 19 Sep 2016 14:34:03 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1blzdy-00056n-HT for xen-devel@lists.xenproject.org; Mon, 19 Sep 2016 14:34:02 +0000 Received: from [193.109.254.147] by server-2.bemta-6.messagelabs.com id E5/D8-13744-957FFD75; Mon, 19 Sep 2016 14:34:01 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrAIsWRWlGSWpSXmKPExsUyZ7p8oG7k9/v hBovaeCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1ozTnauZCjoFK56c+svUwPiDt4uRi0NIoI1J 4u2phWwQzhdGid+bf7JDOBsZJU58P8TUxcgJ5PQySmx9YNXFyMHBIqAqsafVHcRkEzCReLPKE aRCREBd4s+FCYwgrcwCixklJmxsYQapERbwlug+IANSwytgKXFo3TFWiImbGCWmfTSHiAtKnJ z5hAXEZhbQkrjx7yUTSCuzgLTE8n8cIGFOAWuJN7tPsoHYogLKEg0zHjCD2BIChhKnH25jnMA oOAvJpFlIJs1CmLSAkXkVo0ZxalFZapGusZFeUlFmekZJbmJmjq6hgZlebmpxcWJ6ak5iUrFe cn7uJkZgyDIAwQ7G0+sCDzFKcjApifIunn0/XIgvKT+lMiOxOCO+qDQntfgQowwHh5IE7+SvQ DnBotT01Iq0zBxg9MCkJTh4lER454GkeYsLEnOLM9MhUqcYFaXEeVm/ASUEQBIZpXlwbbCIvc QoKyXMywh0iBBPQWpRbmYJqvwrRnEORiVh3psg43ky80rgpr8CWswEtJixB2xxSSJCSqqBUSX uaNKzkwGLlHfI5TI4LE164Xjyb8kdHcE54vuazt259yhgfkrRxXQV1pIO8VlXmHZnC5j9ZP5p f7L3/GQPTQOH3plRuzarG023E7NliP3wNGbLlbXKVxL89pgGqy+8d6Zq9eqXBfHTO06fdl6Ub Wq99mCST6ra9nuVac9/fSgL93zM2Snho8RSnJFoqMVcVJwIABKdRk3TAgAA X-Env-Sender: konrad.wilk@oracle.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1474295639!7541284!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 52466 invoked from network); 19 Sep 2016 14:34:00 -0000 Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by server-2.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 19 Sep 2016 14:34:00 -0000 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u8JEXqNx016342 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 19 Sep 2016 14:33:52 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u8JEXqnO029429 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 19 Sep 2016 14:33:52 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u8JEXkVg021313; Mon, 19 Sep 2016 14:33:51 GMT Received: from localhost.localdomain (/172.58.217.56) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 19 Sep 2016 07:33:45 -0700 Date: Mon, 19 Sep 2016 10:33:43 -0400 From: Konrad Rzeszutek Wilk To: Julien Grall Message-ID: <20160919143343.GB9860@localhost.localdomain> References: <1474043908-12101-1-git-send-email-konrad.wilk@oracle.com> <1474043908-12101-5-git-send-email-konrad.wilk@oracle.com> <4979af71-18ca-4c53-b37f-901e7fc4a75b@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4979af71-18ca-4c53-b37f-901e7fc4a75b@arm.com> User-Agent: Mutt/1.6.1 (2016-04-27) X-Source-IP: userv0021.oracle.com [156.151.31.71] Cc: xen-devel@lists.xenproject.org, ross.lagerwall@citrix.com, Andrew Cooper , sstabellini@kernel.org Subject: Re: [Xen-devel] [PATCH v4 04/16] livepatch: Initial ARM64 support. 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 > > > void arch_livepatch_revive(void) > > { > > + /* > > + * Nuke the instruction cache. Data cache has been cleaned before in > > + * arch_livepatch_apply_jmp. > > I think you forgot to clean text region from the payload. Without that, you > may receive a crash if you have a separate cache for data and instruction. Help me out here please. Why would we need to call clean_and_invalidate_dcache_va_range on the payload .text area (the func->new_addr and func->new_size)? We don't modify that .text area and after this function is done (arch_livepatch_revive) it would be very first time that code would be called. Hence there would not be any cache remains at all? Or did you mean the old_addr (the one we just patched?) If we are reverting it then we just clear at func->old_addr for one instruction? We could drop the dcache for the func->new_addr (so new .text code), to explicitly tell the CPU to not waste cache space for those instructions? Is that what you meant? Anyhow did this: And added the invalidation of dcache at old_addr (so the function we patched). diff --git a/xen/arch/arm/arm64/livepatch.c b/xen/arch/arm/arm64/livepatch.c index 49eb69b..07f0ce7 100644 --- a/xen/arch/arm/arm64/livepatch.c +++ b/xen/arch/arm/arm64/livepatch.c @@ -49,7 +49,10 @@ void arch_livepatch_apply_jmp(struct livepatch_func *func) for ( i = 0; i < len; i++ ) *(new_ptr + i) = insn; + /* There should not be _any_ aliasing using vmap's, but just in case. */ clean_and_invalidate_dcache_va_range(new_ptr, sizeof(*new_ptr) * len); + /* And definitly clear the old code. */ + clean_and_invalidate_dcache_va_range(func->old_addr, sizeof(*new_ptr) * len); } void arch_livepatch_revert_jmp(const struct livepatch_func *func) @@ -68,6 +71,9 @@ void arch_livepatch_revert_jmp(const struct livepatch_func *func) *(new_ptr + i) = insn; } + /* There should not be _any_ aliasing using vmap's, but just in case. */ + clean_and_invalidate_dcache_va_range(new_ptr, sizeof(*new_ptr) * len); + /* And definitly clear the old code. */ clean_and_invalidate_dcache_va_range(func->old_addr, sizeof(*new_ptr) * len); }