From patchwork Tue Sep 12 00:37:24 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: 9948223 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 CAA046038F for ; Tue, 12 Sep 2017 00:41:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F71D28D9E for ; Tue, 12 Sep 2017 00:41:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E17228D9D; Tue, 12 Sep 2017 00:41:09 +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 19EB428D32 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 1drZDJ-0000rQ-Mt; Tue, 12 Sep 2017 00:38:05 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drZDI-0000kt-JV for xen-devel@lists.xenproject.org; Tue, 12 Sep 2017 00:38:04 +0000 Received: from [193.109.254.147] by server-7.bemta-6.messagelabs.com id 67/F6-03610-C6C27B95; Tue, 12 Sep 2017 00:38:04 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrAIsWRWlGSWpSXmKPExsVyMfTOId1sne2 RBqcva1p83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBlrjn1hKugTqPi4fz57A+N03i5GLg4hgRmM Ei/mnmAGcVgEPrBI/F9xjAXEkRCYxiqx9Os/1i5GTiAnTuLztR1sEHaaxIuty4BsDiC7UuLSZ z6QsJCAksSWyY8ZIaYeZJKY+/c3WK+wgJ7E5G+3GUFsNgF9iadrrzFD9LpJfLrGBVIvItDOKD H7yi+wemYBQ4nWt0fZIHqDJCZ9eA8WZxFQlfj5YgULiM0rYCXxdtpcZoh75CUm9k4Dm88JFP/ 9Yx4rxEGWEh0LrjBNYBRewMiwilGjOLWoLLVI19BQL6koMz2jJDcxM0fX0MBMLze1uDgxPTUn MalYLzk/dxMjMEQZgGAH46dlAYcYJTmYlER5fwtvjxTiS8pPqcxILM6ILyrNSS0+xCjDwaEkw btCCygnWJSanlqRlpkDjBaYtAQHj5IIbxZImre4IDG3ODMdInWK0ZLjwp1Lf5g4Duy5BSQ7bt 79wyTEkpeflyolzlukDdQgANKQUZoHNw4W0ZcYZaWEeRmBDhTiKUgtys0sQZV/xSjOwagkzLs OZC1PZl4J3NZXQAcxAR3Ec2kLyEEliQgpqQbGtIbM+s1G57U8S66EVH1bF7HooUXssUsp+k0H zJVFzp45/WFnkrhnlDuvjrzwr5vcl3oyn25UjOUvdUuv2rHtx2KJoJxpWsbFd+b23Jm+1z6n0 /xt8gfNxf/vhvAv/B0z7b/dbYlF9xc/r900d62yes+b+WWirzTt/oX9Ytsnn3v0vuCGLwL/lV iKMxINtZiLihMBUv1vIeMCAAA= X-Env-Sender: ketuzsezr@gmail.com X-Msg-Ref: server-4.tower-27.messagelabs.com!1505176682!115441470!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 6259 invoked from network); 12 Sep 2017 00:38:03 -0000 Received: from mail-qk0-f194.google.com (HELO mail-qk0-f194.google.com) (209.85.220.194) by server-4.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 12 Sep 2017 00:38:03 -0000 Received: by mail-qk0-f194.google.com with SMTP id i14so6376473qke.3 for ; Mon, 11 Sep 2017 17:38:03 -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=U41trst35JbFxYdTkgQlMEJL0z65SLfGgsckZPwjruE=; b=rqdJKwYoEj4Du6UoHQ+WlQyRLnrJXEDAO3PBGojeeUv/p7fvcw6yKcfMk2m6jrOqqN DgIp4R0CKk75QUzrjiz38IWn9/qaMDswPJyx4ZJNnn3VFvKv4z6su/yTR1oHxkhTovpv 4y0A2ThPzfQYKDw+gDlLb/Nhs7D+H29NZcO4yBoZxsvL2Kqd8rPLoBw0NgbyKc06u1ad ihKTJ3A0f8Qa/ryhNcGcPfz2rupHxdNf1cFS34o/5wgRSRkTE7+eWspfkoIfjmYRP78z iFh3xeMfzlY1CuhW8toCua7q1GAqUvBqBMaykNrWU3lmPek6NgXbcBeIup598scCRRTX NcNw== 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=U41trst35JbFxYdTkgQlMEJL0z65SLfGgsckZPwjruE=; b=mv41dRuQtsALV4PddyCItl4jNtnCxwHxTtUvY5270WG8tIoaHZq3UEUpl2fbT2cgeo me4gYjuZRE9LZMeiURB8YMxkEoWT2CGl14oaP9kCyM9XqTzVZVGbkUnPtVsEJZBHPE1E XLeTHKiS1g0YCDcTJ0XLdJaFM4zSfkwhePlw4mU/31VaeBws8p6zXLn+aJNZBHjT+aCy arK8VYsH5GLVIjoPR6t90Rzz5xqZzMVyYvDZ79Ow+nvawS5nNwy9ngZG+C2JV/wwtp1M qJmm7vLMujzQiKcNIwJ12k7NlcN0cho4y3SwiCi3tk0sNUgMTXDMNtFwqIL64eIGyFFA /6eQ== X-Gm-Message-State: AHPjjUj1SXovUvNP8yAyZo7qGqVy1S+v65SK1x3qUeP2HZtVahzBKrxC RXIwAQ//Cu2ObOQS X-Google-Smtp-Source: AOwi7QDxCQrNev4dvKgar/RSmKuc5n1EL5rxe1CMSssaB9eRgl93VDFH5KpbSJrhMQEAcGLWxuipdQ== X-Received: by 10.55.75.75 with SMTP id y72mr17282745qka.118.1505176682424; Mon, 11 Sep 2017 17:38:02 -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.38.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Sep 2017 17:38:01 -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:24 -0400 Message-Id: <20170912003726.368-16-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 15/17] livepatch/x86/arm: Utilize the arch_livepatch_lookup_mfn 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 Without this patch on x86 we would get a DOUBLE FAULT as the virt_to_mfn does not lookup virtual addresses that are in vmap region. This means that the livepatch_vmap.funcs would point to an incorrect MFN (with either garbage or all zeros). We only use the livepatch_vmap.funcs to save the old contents of the instruction (f->opaque) so during patching all works fine. But when we revert and copy the contents of f->opaque we would either get the right values, or zeros (again, depending on where the MFN is) - and then starting instructions in the unpatched function would end up with 00000000 .. causing a double fault. Using the arch_livepatch_lookup_mfn solves the problem and the applying/reverting works on all platforms properly. Signed-off-by: Konrad Rzeszutek Wilk --- xen/common/livepatch.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c index 2f5ee1ae75..2526d3a0ca 100644 --- a/xen/common/livepatch.c +++ b/xen/common/livepatch.c @@ -1073,7 +1073,10 @@ static int livepatch_quiesce(struct livepatch_func *funcs, unsigned int nfuncs) if ( livepatch_vmap.text || livepatch_vmap.funcs ) return -EINVAL; - text_mfn = _mfn(virt_to_mfn(_start)); + text_mfn = arch_livepatch_lookup_mfn((unsigned long)_start); + if ( mfn_eq(text_mfn, INVALID_MFN) ) + return -EINVAL; + text_order = get_order_from_bytes(_end - _start); /* @@ -1093,7 +1096,14 @@ static int livepatch_quiesce(struct livepatch_func *funcs, unsigned int nfuncs) livepatch_vmap.text = vmap_addr; livepatch_vmap.offset = offs; - rodata_mfn = _mfn(virt_to_mfn(va & PAGE_MASK)); + rodata_mfn = arch_livepatch_lookup_mfn(va & PAGE_MASK); + if ( mfn_eq(rodata_mfn, INVALID_MFN) ) + { + vunmap(livepatch_vmap.text); + livepatch_vmap.text = NULL; + return -EINVAL; + } + vmap_addr = __vmap(&rodata_mfn, size, 1, 1, PAGE_HYPERVISOR, VMAP_DEFAULT); if ( !vmap_addr ) {