From patchwork Tue Apr 15 21:05:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Huang X-Patchwork-Id: 28427 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 35D0C2057C for ; Tue, 15 Apr 2014 21:09:31 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rd18sf55344198iec.4 for ; Tue, 15 Apr 2014 14:09:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:cc:subject:precedence:list-id:list-unsubscribe:list-post :list-help:list-subscribe:mime-version:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=g1FjGPEKirtE6SB1hH2UAJg4j1Lv1QstgRFwWlOYbH0=; b=HH16TQmRtsxb86gm+ORA12CC1KiCRGk+9SnvQWRXyTFPs08GWQiF/PMJBL3P5lsurw M1V/PnJT10lheVhDxsxQ4HtjI2J6E5yqB47pr7cOFHN+Q3+bfCpnRnI07d3Y2i2H6YQ6 GPJfsu+ix5MzXEbmGRht5bw1RvlE5OF+OWfxG53W2KTkLHAaR5XM/o3WvVyHYuGSMN7e 5AB37wmf8qz8ow5iQoNVsz5sD+2+p9geWc2ljLRT0weSX70aaP3zIlIgMA9P5pFtixB/ eidcWyU3J1njYwmT7zR+C1IHQTY/bSrUv6GO873vJOPZHUJfy03ZY95+0qmt2xtxnsBP KPwg== X-Gm-Message-State: ALoCoQmzqcqP7vvO7Nyn7jm5wuSvK/dUy6w/TSZDihp4wd/ejjlm8gj6L0CUzQIbQbg6BpJUp5wH X-Received: by 10.182.105.1 with SMTP id gi1mr1922767obb.6.1397596170642; Tue, 15 Apr 2014 14:09:30 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.38.177 with SMTP id t46ls335142qgt.16.gmail; Tue, 15 Apr 2014 14:09:30 -0700 (PDT) X-Received: by 10.52.15.132 with SMTP id x4mr2560814vdc.31.1397596170508; Tue, 15 Apr 2014 14:09:30 -0700 (PDT) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by mx.google.com with ESMTPS id o2si3623854vew.115.2014.04.15.14.09.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 15 Apr 2014 14:09:30 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.179; Received: by mail-ve0-f179.google.com with SMTP id db12so9998408veb.10 for ; Tue, 15 Apr 2014 14:09:30 -0700 (PDT) X-Received: by 10.220.81.194 with SMTP id y2mr3047765vck.29.1397596170410; Tue, 15 Apr 2014 14:09:30 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp262216vcb; Tue, 15 Apr 2014 14:09:30 -0700 (PDT) X-Received: by 10.224.64.132 with SMTP id e4mr746154qai.16.1397596169590; Tue, 15 Apr 2014 14:09:29 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id u15si8679182qge.103.2014.04.15.14.09.28 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 15 Apr 2014 14:09:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xen.org designates 50.57.142.19 as permitted sender) client-ip=50.57.142.19; Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WaAaB-000560-E6; Tue, 15 Apr 2014 21:07:55 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WaAaA-00055W-93 for xen-devel@lists.xen.org; Tue, 15 Apr 2014 21:07:54 +0000 Received: from [85.158.139.211:3273] by server-1.bemta-5.messagelabs.com id 74/C5-10259-9AF9D435; Tue, 15 Apr 2014 21:07:53 +0000 X-Env-Sender: w1.huang@samsung.com X-Msg-Ref: server-4.tower-206.messagelabs.com!1397596070!7665228!1 X-Originating-IP: [203.254.224.25] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMjAzLjI1NC4yMjQuMjUgPT4gMzcxMzg3\n X-StarScan-Received: X-StarScan-Version: 6.11.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3742 invoked from network); 15 Apr 2014 21:07:52 -0000 Received: from mailout2.samsung.com (HELO mailout2.samsung.com) (203.254.224.25) by server-4.tower-206.messagelabs.com with DES-CBC3-SHA encrypted SMTP; 15 Apr 2014 21:07:52 -0000 Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0N43006A9C11FWB0@mailout2.samsung.com> for xen-devel@lists.xen.org; Wed, 16 Apr 2014 06:07:49 +0900 (KST) X-AuditID: cbfee61b-b7f456d000006dfd-2d-534d9fa58862 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 03.8D.28157.5AF9D435; Wed, 16 Apr 2014 06:07:49 +0900 (KST) Received: from weihp.spa.sarc.sas ([105.140.31.10]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0N43002SLC0INC00@mmp2.samsung.com>; Wed, 16 Apr 2014 06:07:49 +0900 (KST) From: Wei Huang To: xen-devel@lists.xen.org Date: Tue, 15 Apr 2014 16:05:09 -0500 Message-id: <1397595918-30419-5-git-send-email-w1.huang@samsung.com> X-Mailer: git-send-email 1.7.9.5 In-reply-to: <1397595918-30419-1-git-send-email-w1.huang@samsung.com> References: <1397595918-30419-1-git-send-email-w1.huang@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprGLMWRmVeSWpSXmKPExsVy+t9jQd2l832DDX7Pk7VY/HgXu8Wb3g4W ixu9t9gspv+5w2bx885FRovX5z4yWyz5uJjFouPfNDYHDo/Xkycwemx/IuJx59oeNo+ju38z efRtWcUYwBrFZZOSmpNZllqkb5fAlbG8dyN7QadbxaqXxg2MX0y7GDk5JARMJJZ+38YCYYtJ XLi3nq2LkYtDSGA6o0Trzy2MIAkhgWYmiQlPi0FsNgE1iVMX/4M1iAhIS1z7fJkRpIFZYA+j RMPuPmaQhLBAuMSSM3/BmlkEVCUebTgAZHNw8Aq4SBxZYgpiSggoSMyZZANSwSngKjG5YTfU qliJD11zmCYw8i5gZFjFKJpakFxQnJSea6RXnJhbXJqXrpecn7uJERxaz6R3MK5qsDjEKMDB qMTDOzPHN1iINbGsuDL3EKMEB7OSCO+GFqAQb0piZVVqUX58UWlOavEhRmkOFiVx3oOt1oFC AumJJanZqakFqUUwWSYOTqkGxpzZoUFPjq5wtGWtUD71e0tL9V9Tq0lZ0q3hQb7r5jz4ECK1 +N2Z1NgVew91Fc3KmPBc6iHb6obuXYyTX5k/TWJp7o5z+7yG/ZerkH5mcbHiNm5PDh7xrt4U ns9bb7Wx/Vp4n53j/WsDV+7F7RMkL+2bK+sUJdbEd8KRIbb59k4n5gifrgVrlViKMxINtZiL ihMBUNYZuykCAAA= Cc: w1.huang@samsung.com, ian.campbell@citrix.com, stefano.stabellini@eu.citrix.com, andrew.cooper3@citrix.com, julien.grall@linaro.org, jaeyong.yoo@samsung.com, yjhyun.yoo@samsung.com Subject: [Xen-devel] [RFC v2 4/6] xen/arm: Implement VLPT for guest p2m mapping in live migration X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: List-Unsubscribe: , List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: w1.huang@samsung.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Archive: From: Jaeyong Yoo Thsi patch implements VLPT (virtual-linear page table) for fast accessing of 3rd PTE of guest P2M. For more info about VLPT, please see http://www.technovelty.org/linux/virtual-linear-page-table.html. When creating a mapping for VLPT, just copy the 1st level PTE of guest p2m to xen's 2nd level PTE. Then the mapping becomes the following: xen's 1st PTE --> xen's 2nd PTE (which is the same as 1st PTE of guest p2m) --> guest p2m's 2nd PTE --> guest p2m's 3rd PTE (the memory contents where the vlpt points) This function is used in dirty-page tracing. When domU write-fault is trapped by xen, xen can immediately locate the 3rd PTE of guest p2m. The following link shows the performance comparison for handling a dirty-page between vlpt and typical page table walking. http://lists.xen.org/archives/html/xen-devel/2013-08/msg01503.html Signed-off-by: Jaeyong Yoo --- xen/arch/arm/domain.c | 5 ++ xen/arch/arm/mm.c | 116 ++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/config.h | 7 +++ xen/include/asm-arm/domain.h | 7 +++ xen/include/asm-arm/mm.h | 17 +++++++ 5 files changed, 152 insertions(+) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index b125857..3f04a77 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -502,6 +502,11 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags) /* Default the virtual ID to match the physical */ d->arch.vpidr = boot_cpu_data.midr.bits; + d->arch.dirty.second_lvl_start = 0; + d->arch.dirty.second_lvl_end = 0; + d->arch.dirty.second_lvl[0] = NULL; + d->arch.dirty.second_lvl[1] = NULL; + clear_page(d->shared_info); share_xen_page_with_guest( virt_to_page(d->shared_info), d, XENSHARE_writable); diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 473ad04..a315752 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -750,6 +750,122 @@ void *__init arch_vmap_virt_end(void) return (void *)VMAP_VIRT_END; } +/* Flush the vlpt area */ +void flush_vlpt(struct domain *d) +{ + int flush_size; + + flush_size = (d->arch.dirty.second_lvl_end - + d->arch.dirty.second_lvl_start) << SECOND_SHIFT; + + /* flushing the 3rd level mapping */ + flush_xen_data_tlb_range_va(d->arch.dirty.second_lvl_start << SECOND_SHIFT, + flush_size); +} + +/* Restore the xen page table for vlpt mapping for domain */ +void restore_vlpt(struct domain *d) +{ + int i; + + dsb(sy); + + for ( i = d->arch.dirty.second_lvl_start; i < d->arch.dirty.second_lvl_end; + ++i ) + { + int k = i % LPAE_ENTRIES; + int l = i / LPAE_ENTRIES; + + if ( xen_second[i].bits != d->arch.dirty.second_lvl[l][k].bits ) + { + write_pte(&xen_second[i], d->arch.dirty.second_lvl[l][k]); + flush_xen_data_tlb_range_va(i << SECOND_SHIFT, 1 << SECOND_SHIFT); + } + } + + dsb(sy); + isb(); +} + +/* Set up the xen page table for vlpt mapping for domain */ +int prepare_vlpt(struct domain *d) +{ + int xen_second_linear_base; + int gp2m_start_index, gp2m_end_index; + struct p2m_domain *p2m = &d->arch.p2m; + struct page_info *second_lvl_page; + paddr_t gma_start = 0; + paddr_t gma_end = 0; + lpae_t *first[2]; + int i; + uint64_t required, avail = VIRT_LIN_P2M_END - VIRT_LIN_P2M_START; + + domain_get_gpfn_range(d, &gma_start, &gma_end); + required = (gma_end - gma_start) >> LPAE_SHIFT; + + if ( required > avail ) + { + dprintk(XENLOG_ERR, "Available VLPT is small for domU guest" + "(avail: %llx, required: %llx)\n", (unsigned long long)avail, + (unsigned long long)required); + return -ENOMEM; + } + + xen_second_linear_base = second_linear_offset(VIRT_LIN_P2M_START); + + gp2m_start_index = gma_start >> FIRST_SHIFT; + gp2m_end_index = (gma_end >> FIRST_SHIFT) + 1; + + if ( xen_second_linear_base + gp2m_end_index >= LPAE_ENTRIES * 2 ) + { + dprintk(XENLOG_ERR, "xen second page is small for VLPT for domU"); + return -ENOMEM; + } + + second_lvl_page = alloc_domheap_pages(NULL, 1, 0); + if ( second_lvl_page == NULL ) + return -ENOMEM; + + /* First level p2m is 2 consecutive pages */ + d->arch.dirty.second_lvl[0] = map_domain_page_global( + page_to_mfn(second_lvl_page) ); + d->arch.dirty.second_lvl[1] = map_domain_page_global( + page_to_mfn(second_lvl_page+1) ); + + first[0] = __map_domain_page(p2m->first_level); + first[1] = __map_domain_page(p2m->first_level+1); + + for ( i = gp2m_start_index; i < gp2m_end_index; ++i ) + { + int k = i % LPAE_ENTRIES; + int l = i / LPAE_ENTRIES; + int k2 = (xen_second_linear_base + i) % LPAE_ENTRIES; + int l2 = (xen_second_linear_base + i) / LPAE_ENTRIES; + + write_pte(&xen_second[xen_second_linear_base+i], first[l][k]); + + /* we copy the mapping into domain's structure as a reference + * in case of the context switch (used in restore_vlpt) */ + d->arch.dirty.second_lvl[l2][k2] = first[l][k]; + } + unmap_domain_page(first[0]); + unmap_domain_page(first[1]); + + /* storing the start and end index */ + d->arch.dirty.second_lvl_start = xen_second_linear_base + gp2m_start_index; + d->arch.dirty.second_lvl_end = xen_second_linear_base + gp2m_end_index; + + flush_vlpt(d); + + return 0; +} + +void cleanup_vlpt(struct domain *d) +{ + /* First level p2m is 2 consecutive pages */ + unmap_domain_page_global(d->arch.dirty.second_lvl[0]); + unmap_domain_page_global(d->arch.dirty.second_lvl[1]); +} /* * This function should only be used to remap device address ranges * TODO: add a check to verify this assumption diff --git a/xen/include/asm-arm/config.h b/xen/include/asm-arm/config.h index ef291ff..47d1bce 100644 --- a/xen/include/asm-arm/config.h +++ b/xen/include/asm-arm/config.h @@ -87,6 +87,7 @@ * 0 - 8M * * 32M - 128M Frametable: 24 bytes per page for 16GB of RAM + * 128M - 256M Virtual-linear mapping to P2M table * 256M - 1G VMAP: ioremap and early_ioremap use this virtual address * space * @@ -124,7 +125,9 @@ #define CONFIG_SEPARATE_XENHEAP 1 #define FRAMETABLE_VIRT_START _AT(vaddr_t,0x02000000) +#define VIRT_LIN_P2M_START _AT(vaddr_t,0x08000000) #define VMAP_VIRT_START _AT(vaddr_t,0x10000000) +#define VIRT_LIN_P2M_END VMAP_VIRT_START #define XENHEAP_VIRT_START _AT(vaddr_t,0x40000000) #define XENHEAP_VIRT_END _AT(vaddr_t,0x7fffffff) #define DOMHEAP_VIRT_START _AT(vaddr_t,0x80000000) @@ -157,6 +160,10 @@ #define HYPERVISOR_VIRT_END DIRECTMAP_VIRT_END +/* VIRT_LIN_P2M_START and VIRT_LIN_P2M_END for vlpt */ +#define VIRT_LIN_P2M_START _AT(vaddr_t, 0x08000000) +#define VIRT_LIN_P2M_END VMAP_VIRT_START + #endif /* Fixmap slots */ diff --git a/xen/include/asm-arm/domain.h b/xen/include/asm-arm/domain.h index 28c359a..5321bd6 100644 --- a/xen/include/asm-arm/domain.h +++ b/xen/include/asm-arm/domain.h @@ -161,6 +161,13 @@ struct arch_domain spinlock_t lock; } vuart; + /* dirty-page tracing */ + struct { + volatile int second_lvl_start; /* for context switch */ + volatile int second_lvl_end; + lpae_t *second_lvl[2]; /* copy of guest p2m's first */ + } dirty; + unsigned int evtchn_irq; } __cacheline_aligned; diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h index 8347524..5fd684f 100644 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -4,6 +4,7 @@ #include #include #include +#include #include /* Align Xen to a 2 MiB boundary. */ @@ -342,6 +343,22 @@ static inline void put_page_and_type(struct page_info *page) put_page(page); } +int prepare_vlpt(struct domain *d); +void cleanup_vlpt(struct domain *d); +void restore_vlpt(struct domain *d); + +/* calculate the xen's virtual address for accessing the leaf PTE of + * a given address (GPA) */ +static inline lpae_t * get_vlpt_3lvl_pte(paddr_t addr) +{ + lpae_t *table = (lpae_t *)VIRT_LIN_P2M_START; + + /* Since we slotted the guest's first p2m page table to xen's + * second page table, one shift is enough for calculating the + * index of guest p2m table entry */ + return &table[addr >> PAGE_SHIFT]; +} + #endif /* __ARCH_ARM_MM__ */ /* * Local variables: