From patchwork Fri Oct 10 14:43:14 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Campbell X-Patchwork-Id: 38589 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4B285205D8 for ; Fri, 10 Oct 2014 14:45:29 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id n3sf918068wiv.8 for ; Fri, 10 Oct 2014 07:45:28 -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 :mime-version:cc:subject:precedence:list-id:list-unsubscribe :list-post:list-help:list-subscribe:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :list-archive:content-type:content-transfer-encoding; bh=GaHVuWbu7FjhpyEriMij5o5PALFB2T9ujAkAG0LUYzA=; b=CLZxkHNY7rjNtc4io5pJgt4tVTPi8LD58Y668ISJsFRGmzQKDdQG8yrxDrsfuCYHCX jMHmfVqRtTDZ9qPxqwe+G96qV0vwtsOecT/zWQj0EWExnWItTrWF4WR9XGYAtluJdQul 34AZIRItTqjWIwbMT+BdhwD37qYhezsbPTWUZx3gWawTpft0iZ/xuQSbarANyaBkcniz czXoGg79Cz4kjj7lS4gMP9iKVwne+2Ed/Kgal8S/OGlPo2CBMgf2Bi2NtglsvORZs+SE 2siV6xWO8iz7xgY9/LVzWtyHm/b/pU25mRizIJ5f8GjBXrCke8wSCgEkAuG9DsNq5VXo x15g== X-Gm-Message-State: ALoCoQlfCHMCBNLQ3sZbNQqtLzfR9XmrCfRFCyorKdc9NtQuAxQmLOJAo8OR7LvDUwiXVJ+CfBEc X-Received: by 10.180.160.169 with SMTP id xl9mr1141116wib.7.1412952328461; Fri, 10 Oct 2014 07:45:28 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.132 with SMTP id ay4ls275716lab.46.gmail; Fri, 10 Oct 2014 07:45:28 -0700 (PDT) X-Received: by 10.112.130.4 with SMTP id oa4mr5212244lbb.37.1412952328107; Fri, 10 Oct 2014 07:45:28 -0700 (PDT) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com [209.85.217.181]) by mx.google.com with ESMTPS id x9si9681971lbb.28.2014.10.10.07.45.27 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 10 Oct 2014 07:45:27 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by mail-lb0-f181.google.com with SMTP id l4so3158365lbv.40 for ; Fri, 10 Oct 2014 07:45:27 -0700 (PDT) X-Received: by 10.112.62.200 with SMTP id a8mr5299693lbs.34.1412952327224; Fri, 10 Oct 2014 07:45:27 -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.112.84.229 with SMTP id c5csp441168lbz; Fri, 10 Oct 2014 07:45:26 -0700 (PDT) X-Received: by 10.220.44.13 with SMTP id y13mr5386015vce.28.1412952324930; Fri, 10 Oct 2014 07:45:24 -0700 (PDT) Received: from lists.xen.org (lists.xen.org. [50.57.142.19]) by mx.google.com with ESMTPS id mh6si7355094vcb.45.2014.10.10.07.45.24 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 10 Oct 2014 07:45:24 -0700 (PDT) Received-SPF: none (google.com: xen-devel-bounces@lists.xen.org does not designate permitted sender hosts) 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 1XcbPs-0001K2-S9; Fri, 10 Oct 2014 14:43:36 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1XcbPr-0001Jt-JH for xen-devel@lists.xen.org; Fri, 10 Oct 2014 14:43:35 +0000 Received: from [85.158.137.68:28272] by server-13.bemta-3.messagelabs.com id 4D/48-01569-690F7345; Fri, 10 Oct 2014 14:43:34 +0000 X-Env-Sender: Ian.Campbell@citrix.com X-Msg-Ref: server-7.tower-31.messagelabs.com!1412952211!12773763!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n X-StarScan-Received: X-StarScan-Version: 6.12.2; banners=-,-,- X-VirusChecked: Checked Received: (qmail 2916 invoked from network); 10 Oct 2014 14:43:34 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-7.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 10 Oct 2014 14:43:34 -0000 X-IronPort-AV: E=Sophos;i="5.04,692,1406592000"; d="scan'208";a="181354846" Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.80) with Microsoft SMTP Server id 14.3.181.6; Fri, 10 Oct 2014 10:43:15 -0400 Received: from drall.uk.xensource.com ([10.80.16.71]) by ukmail1.uk.xensource.com with smtp (Exim 4.69) (envelope-from ) id 1XcbPW-0002Cs-85; Fri, 10 Oct 2014 15:43:15 +0100 Received: by drall.uk.xensource.com (sSMTP sendmail emulation); Fri, 10 Oct 2014 15:43:14 +0100 From: Ian Campbell To: Date: Fri, 10 Oct 2014 15:43:14 +0100 Message-ID: <1412952194-3595-1-git-send-email-ian.campbell@citrix.com> X-Mailer: git-send-email 1.7.10.4 MIME-Version: 1.0 X-DLP: MIA2 Cc: Ian Campbell , Vijay Kilari , stefano.stabellini@eu.citrix.com, julien.grall@linaro.org, tim@xen.org, Roy Franz , Suravee Suthikulanit Subject: [Xen-devel] [PATCH FOR-4.5] xen: arm64: Handle memory banks which are not 1GB aligned 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: , 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: ian.campbell@citrix.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) 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: The code in the arm64 version of setup_xenheap_mappings was making some very confused attempts to handle this but was bogus. As well as adjusting the mapping to start on a 1GB boundary we also need to account for the offset between the start of the mapping and the actual start of the heap when converting between page pointers, virtual addresses and machine addresses. I preferred to do this by explicitly accounting for the offset rather than adding an offset to the frametable because that approach could potentially waste a large amount of frametable (up to just less than 1GB worth) but also because of issues with converting mfns from outside the regions considered for pdx initialisation (which are not 1GB aligned) back and forth. We already have an idea of the distinction between the start of the direct map and the start of the xenheap in the difference between DIRECTMAP_VIRT_START and XENHEAP_VIRT_START. Until now these were the same thing, but now we change XENHEAP_VIRT_START to point to the actual start of heap not the mapping. Surprisingly there was only one place which was using the conceptually wrong value. Also change xenheap_virt_end to a vaddr_t for consistency. We've been lucky so far that most hardware happens to locate memory on a 1GB boundary (we did have reports of a system with memory at a half gig boundary which exhibited failures which I didn't manage to follow up on successfully). The EFI support has exposed this shortcoming by the way it handles reserved memory, which has a similar effect to having memory non-1GB aligned. arm32 does things differently here due to using a small Xen heap and a demand mapped domain heap, so isn't affected. Signed-off-by: Ian Campbell Cc: Suravee Suthikulanit Cc: Roy Franz Cc: Vijay Kilari Reviewed-by: Julien Grall --- FOR-4.5: This is a bug fix. --- xen/arch/arm/mm.c | 36 +++++++++++++++++++++++++----------- xen/include/asm-arm/config.h | 2 +- xen/include/asm-arm/mm.h | 7 +++++-- 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index c5b48ef..97e5bc39 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -138,7 +138,10 @@ static paddr_t phys_offset; /* Limits of the Xen heap */ unsigned long xenheap_mfn_start __read_mostly = ~0UL; unsigned long xenheap_mfn_end __read_mostly; -unsigned long xenheap_virt_end __read_mostly; +vaddr_t xenheap_virt_end __read_mostly; +#ifdef CONFIG_ARM_64 +vaddr_t xenheap_virt_start __read_mostly; +#endif unsigned long frametable_base_pdx __read_mostly; unsigned long frametable_virt_end __read_mostly; @@ -155,7 +158,11 @@ static inline void check_memory_layout_alignment_constraints(void) { BUILD_BUG_ON(FIXMAP_ADDR(0) & ~SECOND_MASK); BUILD_BUG_ON(BOOT_RELOC_VIRT_START & ~SECOND_MASK); /* 1GB aligned regions */ +#ifdef CONFIG_ARM_32 BUILD_BUG_ON(XENHEAP_VIRT_START & ~FIRST_MASK); +#else + BUILD_BUG_ON(DIRECTMAP_VIRT_START & ~FIRST_MASK); +#endif /* Page table structure constraints */ #ifdef CONFIG_ARM_64 BUILD_BUG_ON(zeroeth_table_offset(XEN_VIRT_START)); @@ -665,12 +672,19 @@ void __init setup_xenheap_mappings(unsigned long base_mfn, unsigned long nr_mfns) { lpae_t *first, pte; - unsigned long offset, end_mfn; + unsigned long mfn, end_mfn; vaddr_t vaddr; - /* First call sets the xenheap physical offset. */ + /* Align to previous 1GB boundary */ + mfn = base_mfn & ~((FIRST_SIZE>>PAGE_SHIFT)-1); + + /* First call sets the xenheap physical and virtual offset. */ if ( xenheap_mfn_start == ~0UL ) + { xenheap_mfn_start = base_mfn; + xenheap_virt_start = DIRECTMAP_VIRT_START + + (base_mfn - mfn) * PAGE_SIZE; + } if ( base_mfn < xenheap_mfn_start ) panic("cannot add xenheap mapping at %lx below heap start %lx", @@ -678,13 +692,13 @@ void __init setup_xenheap_mappings(unsigned long base_mfn, end_mfn = base_mfn + nr_mfns; - /* Align to previous 1GB boundary */ - base_mfn &= ~((FIRST_SIZE>>PAGE_SHIFT)-1); - - offset = pfn_to_pdx(base_mfn - xenheap_mfn_start); - vaddr = DIRECTMAP_VIRT_START + offset*PAGE_SIZE; + /* + * Virtual address aligned to previous 1GB to match physical + * address alignment done above. + */ + vaddr = (vaddr_t)mfn_to_virt(base_mfn) & FIRST_MASK; - while ( base_mfn < end_mfn ) + while ( mfn < end_mfn ) { int slot = zeroeth_table_offset(vaddr); lpae_t *p = &xen_pgtable[slot]; @@ -716,11 +730,11 @@ void __init setup_xenheap_mappings(unsigned long base_mfn, first = mfn_to_virt(first_mfn); } - pte = mfn_to_xen_entry(base_mfn, WRITEALLOC); + pte = mfn_to_xen_entry(mfn, WRITEALLOC); /* TODO: Set pte.pt.contig when appropriate. */ write_pte(&first[first_table_offset(vaddr)], pte); - base_mfn += FIRST_SIZE>>PAGE_SHIFT; + mfn += FIRST_SIZE>>PAGE_SHIFT; vaddr += FIRST_SIZE; } diff --git a/xen/include/asm-arm/config.h b/xen/include/asm-arm/config.h index 59b2887..264e2c1 100644 --- a/xen/include/asm-arm/config.h +++ b/xen/include/asm-arm/config.h @@ -162,7 +162,7 @@ #define DIRECTMAP_SIZE (SLOT0_ENTRY_SIZE * (265-256)) #define DIRECTMAP_VIRT_END (DIRECTMAP_VIRT_START + DIRECTMAP_SIZE - 1) -#define XENHEAP_VIRT_START DIRECTMAP_VIRT_START +#define XENHEAP_VIRT_START xenheap_virt_start #define HYPERVISOR_VIRT_END DIRECTMAP_VIRT_END diff --git a/xen/include/asm-arm/mm.h b/xen/include/asm-arm/mm.h index 1e4711c..d25e485 100644 --- a/xen/include/asm-arm/mm.h +++ b/xen/include/asm-arm/mm.h @@ -110,7 +110,10 @@ struct page_info #define PGC_count_mask ((1UL<> PAGE_SHIFT) < (DIRECTMAP_SIZE >> PAGE_SHIFT)); - return (void *)(DIRECTMAP_VIRT_START - + return (void *)(XENHEAP_VIRT_START - pfn_to_paddr(xenheap_mfn_start) + ((ma & ma_va_bottom_mask) | ((ma & ma_top_mask) >> pfn_pdx_hole_shift)));