From patchwork Tue Sep 12 00:37:23 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: 9948239 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 35EA36038F for ; Tue, 12 Sep 2017 00:41:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27AD928D33 for ; Tue, 12 Sep 2017 00:41:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C58828D5D; Tue, 12 Sep 2017 00:41:11 +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 267AE28D5F for ; Tue, 12 Sep 2017 00:41:05 +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-0000s9-UH; Tue, 12 Sep 2017 00:38:05 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drZDI-0000mN-Jr for xen-devel@lists.xenproject.org; Tue, 12 Sep 2017 00:38:04 +0000 Received: from [85.158.139.211] by server-17.bemta-5.messagelabs.com id E2/AA-01791-B6C27B95; Tue, 12 Sep 2017 00:38:03 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrPIsWRWlGSWpSXmKPExsVyMfTGYd1sne2 RBpdlLL5vmczkwOhx+MMVlgDGKNbMvKT8igTWjLd7zrIWPNSoaJ95g62B8YZiFyMnh5DAdEaJ Vf/lQWwWgQ8sEs+vqnQxcnFICExjlZjfcYsJJCEhECdxZ85Ndgg7TaJ79UVmCLtKYtal56wQg 5Qktkx+zAjSLCRwkEli1v5XYAlhAT2Jyd9uM4LYbAL6Ek/XXgNq5gBqdpP4dI0LpF5EoJ1RYv aVX6wgDrNAN6PEjPsLoZqrJebMPcMCcZ6qxI8nk9lAbF4BK4k1qyGGSgjIS0zsnQZmcwLFf/+ YB3WRpUTHgitMExiFFzAyrGLUKE4tKkst0jU01ksqykzPKMlNzMzRNTQw1ctNLS5OTE/NSUwq 1kvOz93ECAxQBiDYwfhvm+chRkkOJiVR3t/C2yOF+JLyUyozEosz4otKc1KLDzHKcHAoSfAaa gPlBItS01Mr0jJzgLECk5bg4FES4c3SAkrzFhck5hZnpkOkTjFacly4c+kPE8eBPbeAZMfNu3 +YhFjy8vNSpcR5f4M0CIA0ZJTmwY2DxfMlRlkpYV5GoAOFeApSi3IzS1DlXzGKczAqCfOuA5n Ck5lXArf1FdBBTEAH8VzaAnJQSSJCSqqB0TX5666+9S435D5869FabnBt5s8UJ3/nXL0q8SnH jbI+vA3z5dwonH7t3jTXKatWZ4u8O3vu8+G8xdwcKwp+8vz8sZQtRUp0ytS7zo5eJiL/815Ur 5h/8HPFX63WhIsJzHe51ctCvT5bRrAmLHcJ3hDy4NHkCoekX0aht1q6zxcU/Ym7vKtwghJLcU aioRZzUXEiAJGPfyHiAgAA X-Env-Sender: ketuzsezr@gmail.com X-Msg-Ref: server-4.tower-206.messagelabs.com!1505176682!111009638!1 X-Originating-IP: [209.85.216.195] 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 58056 invoked from network); 12 Sep 2017 00:38:02 -0000 Received: from mail-qt0-f195.google.com (HELO mail-qt0-f195.google.com) (209.85.216.195) by server-4.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 12 Sep 2017 00:38:02 -0000 Received: by mail-qt0-f195.google.com with SMTP id b1so4187933qtc.0 for ; Mon, 11 Sep 2017 17:38:02 -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=L4bfU/zXqxdaorV/6a9v8ZKti6/akFietGZleRI8+As=; b=qYk4bRxJoWRxRMjGIKncCFfUyWvUO9drWP6HvgIPUFWnlCYwVycOLLVMFml1GY7FNH UH0mCnzuCgMw04G8HeGWNsnjrVqJkTJ7TIUpkBZstd/Tj0KLKz4ucS7HPYwM2jiixkRq yD6td+dLVRwrQM4o62BqovzONylVvna/ybKi6IJ9uogYb4CTcy/AHvjD28ebR8NvJB+I PyvMjjJi18RykRTgp3fdUQxOpeeYvYFZJQtX3rACM2HmUXG8mC8LV3u3fEVyaDqUBeyT qK+hT0DsMa2v92MzfJXsyX//90MA65LsOxv73sxFc2Pn0/rVuF36vd+Rv2gglgJRJLLw R5hQ== 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=L4bfU/zXqxdaorV/6a9v8ZKti6/akFietGZleRI8+As=; b=szl/LBvwmugYmg+GJNmBKeyR8myR6RhS1IO7XXOfgXn8MkRfPPIkITDwpnRGHWDyAO 7tIdRBF48ns14acCud4V1juTZks+lK3P0q/ovjL7jaRUZZomfmjx87aDadttGgEosTKX 6BCbvHOWwJM+y0dGBTAQvqMjKm7u055w2bfbAOT6dHrjDvDSBavRuY7BAUw8nl+rRRdF UxLNmKVDFX7zu33KmBTqdxRM6hsL9Dl9W/55gU+egVYXrwBmkdSEhU8/hnWs6h4VXZGj S8+yl13QNjFPCnltmOamD3ELviCH7/MgwBuLJzw+kbADXAVw35FvbiDQkryC5nR3+r1N aglQ== X-Gm-Message-State: AHPjjUjY4nUyWWUk3JpO+NgH77sSPbgq+GdPezf47BjqcC1ih81ZG2eW 22vZk5g5x0lOrd02 X-Google-Smtp-Source: AOwi7QDbYcFig7IXEknVxsnCk4OWaqeifhtQIqZ2zShKTU99GmS5PFhfCqZ9dNfiahkXW1y44J0o+Q== X-Received: by 10.200.4.158 with SMTP id s30mr19557890qtg.311.1505176681479; Mon, 11 Sep 2017 17:38:01 -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.00 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 11 Sep 2017 17:38:00 -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:23 -0400 Message-Id: <20170912003726.368-15-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, Blaise Boscaccy , Vegard Nossum , jbeulich@suse.com Subject: [Xen-devel] [PATCH v3 14/17] livepatch/x86/arm: arch/x86/mm: generalize do_page_walk() and implement 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 With this change we can use _do_page_walk() to implement arch_livepatch_lookup_mfn() which can be used to find out vmap virtual addresses (as under x86 virt_to_mfn won't work for vmap, but it does for arm!). Signed-off-by: Blaise Boscaccy Signed-off-by: Vegard Nossum Signed-off-by: Konrad Rzeszutek Wilk --- xen/arch/arm/livepatch.c | 7 ++++--- xen/arch/x86/livepatch.c | 10 ++++++++++ xen/arch/x86/x86_64/mm.c | 33 ++++++++++++++++++++++++--------- xen/include/asm-x86/mm.h | 1 + xen/include/xen/livepatch.h | 3 +++ 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/xen/arch/arm/livepatch.c b/xen/arch/arm/livepatch.c index e1d5d58f97..1771b3c558 100644 --- a/xen/arch/arm/livepatch.c +++ b/xen/arch/arm/livepatch.c @@ -13,9 +13,10 @@ #include #include -/* Override macros from asm/page.h to make them work with mfn_t */ -#undef virt_to_mfn -#define virt_to_mfn(va) _mfn(__virt_to_mfn(va)) +mfn_t arch_livepatch_lookup_mfn(unsigned long addr) +{ + return _mfn(__virt_to_mfn(addr)); +} void arch_livepatch_revive(void) { diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c index 12287d445f..667573c6de 100644 --- a/xen/arch/x86/livepatch.c +++ b/xen/arch/x86/livepatch.c @@ -14,6 +14,16 @@ #include #include +mfn_t arch_livepatch_lookup_mfn(unsigned long addr) +{ + unsigned long cr3 = read_cr3() >> PAGE_SHIFT; + + if ( !mfn_valid(_mfn(cr3)) ) + return INVALID_MFN; + + return _do_page_walk(cr3, addr); +} + void arch_livepatch_revive(void) { /* Nothing to do. */ diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index 11746730b4..f8a963bbba 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -44,29 +44,28 @@ unsigned int __read_mostly m2p_compat_vstart = __HYPERVISOR_COMPAT_VIRT_START; l2_pgentry_t *compat_idle_pg_table_l2; -void *do_page_walk(struct vcpu *v, unsigned long addr) +mfn_t _do_page_walk(unsigned long mfn, unsigned long addr) { - unsigned long mfn = pagetable_get_pfn(v->arch.guest_table); l4_pgentry_t l4e, *l4t; l3_pgentry_t l3e, *l3t; l2_pgentry_t l2e, *l2t; l1_pgentry_t l1e, *l1t; - if ( !is_pv_vcpu(v) || !is_canonical_address(addr) ) - return NULL; + if ( !is_canonical_address(addr) ) + return INVALID_MFN; l4t = map_domain_page(_mfn(mfn)); l4e = l4t[l4_table_offset(addr)]; unmap_domain_page(l4t); if ( !(l4e_get_flags(l4e) & _PAGE_PRESENT) ) - return NULL; + return INVALID_MFN; l3t = map_l3t_from_l4e(l4e); l3e = l3t[l3_table_offset(addr)]; unmap_domain_page(l3t); mfn = l3e_get_pfn(l3e); if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) || !mfn_valid(_mfn(mfn)) ) - return NULL; + return INVALID_MFN; if ( (l3e_get_flags(l3e) & _PAGE_PSE) ) { mfn += PFN_DOWN(addr & ((1UL << L3_PAGETABLE_SHIFT) - 1)); @@ -78,7 +77,7 @@ void *do_page_walk(struct vcpu *v, unsigned long addr) unmap_domain_page(l2t); mfn = l2e_get_pfn(l2e); if ( !(l2e_get_flags(l2e) & _PAGE_PRESENT) || !mfn_valid(_mfn(mfn)) ) - return NULL; + return INVALID_MFN; if ( (l2e_get_flags(l2e) & _PAGE_PSE) ) { mfn += PFN_DOWN(addr & ((1UL << L2_PAGETABLE_SHIFT) - 1)); @@ -90,10 +89,26 @@ void *do_page_walk(struct vcpu *v, unsigned long addr) unmap_domain_page(l1t); mfn = l1e_get_pfn(l1e); if ( !(l1e_get_flags(l1e) & _PAGE_PRESENT) || !mfn_valid(_mfn(mfn)) ) - return NULL; + return INVALID_MFN; ret: - return map_domain_page(_mfn(mfn)) + (addr & ~PAGE_MASK); + return _mfn(mfn); +} + +void *do_page_walk(struct vcpu *v, unsigned long addr) +{ + mfn_t mfn; + unsigned long cr3; + + if ( !is_pv_vcpu(v) ) + return NULL; + + cr3 = pagetable_get_pfn(v->arch.guest_table); + mfn = _do_page_walk(cr3, addr); + if ( mfn_eq(mfn, INVALID_MFN) ) + return NULL; + + return map_domain_page(mfn) + (addr & ~PAGE_MASK); } /* diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index bef45e8e9f..224a94494a 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -540,6 +540,7 @@ int new_guest_cr3(mfn_t mfn); void make_cr3(struct vcpu *v, mfn_t mfn); void update_cr3(struct vcpu *v); int vcpu_destroy_pagetables(struct vcpu *); +mfn_t _do_page_walk(unsigned long mfn, unsigned long addr); void *do_page_walk(struct vcpu *v, unsigned long addr); int __sync_local_execstate(void); diff --git a/xen/include/xen/livepatch.h b/xen/include/xen/livepatch.h index 065c1a323a..e529f0e7c3 100644 --- a/xen/include/xen/livepatch.h +++ b/xen/include/xen/livepatch.h @@ -72,6 +72,9 @@ int arch_livepatch_secure(const void *va, unsigned int pages, enum va_type types void arch_livepatch_init(void); +#include /* For mfn_t decleration. */ +mfn_t arch_livepatch_lookup_mfn(unsigned long addr); + #include /* For struct livepatch_func. */ #include int arch_livepatch_verify_func(const struct livepatch_func *func);