From: Ian Campbell Subject: [PATCH] xen: arm: avoid truncation in mfn to paddr conversions Date: Mon, 2 Dec 2013 11:11:40 +0000 Message-ID: <1385982701-14352-1-git-send-email-ian.campbell@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: julien.grall@linaro.org, tim@xen.org, Ian Campbell , andre.przywara@linaro.org, stefano.stabellini@eu.citrix.com List-Id: xen-devel@lists.xenproject.org Although MFNs are 64-bit in the hypercall ABI they are most often unsigned long internally, and therefore be 32-bit on arm32. Physical addresses are always 64-bit via paddr_t. This means that the common "mfn << PAGE_SHIFT" pattern risks losing some of the top bits of the address is high enough. This need not imply a high amount of RAM, just a sparse physical address map. The correct form is ((paddr_t)mfn)< --- xen/arch/arm/domain_build.c | 4 ++-- xen/arch/arm/mm.c | 4 ++-- xen/arch/arm/p2m.c | 16 +++++++++------- xen/arch/arm/setup.c | 8 ++++---- xen/include/asm-arm/mm.h | 4 ++-- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 90fe88e..6c2fd3c 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -84,8 +84,8 @@ static void allocate_memory_11(struct domain *d, struct kernel_info *kinfo) panic("Failed to allocate contiguous memory for dom0\n"); spfn = page_to_mfn(pg); - start = spfn << PAGE_SHIFT; - size = (1 << order) << PAGE_SHIFT; + start = pfn_to_paddr(spfn); + size = pfn_to_paddr((1 << order)); // 1:1 mapping printk("Populate P2M %#"PRIx64"->%#"PRIx64" (1:1 mapping for dom0)\n", diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 2de7dc7..8189915 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -1032,10 +1032,10 @@ static int xenmem_add_to_physmap_one( return rc; } - maddr = p2m_lookup(od, idx << PAGE_SHIFT); + maddr = p2m_lookup(od, pfn_to_paddr(idx)); if ( maddr == INVALID_PADDR ) { - dump_p2m_lookup(od, idx << PAGE_SHIFT); + dump_p2m_lookup(od, pfn_to_paddr(idx)); rcu_unlock_domain(od); return -EINVAL; } diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index af32511..1d5c841 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -296,18 +296,20 @@ int guest_physmap_add_page(struct domain *d, unsigned long mfn, unsigned int page_order) { - return create_p2m_entries(d, INSERT, gpfn << PAGE_SHIFT, - (gpfn + (1<> PAGE_SHIFT; } diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 6834813..e640d81 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -456,7 +456,7 @@ static void __init setup_mm(unsigned long dtb_paddr, size_t dtb_size) { /* xenheap is always in the initial contiguous region */ e = consider_modules(contig_start, contig_end, - xenheap_pages<= virt_to_maddr(&_start)) && \ - (((mfn) << PAGE_SHIFT) <= virt_to_maddr(&_end))) + ((pfn_to_paddr(mfn) >= virt_to_maddr(&_start)) && \ + (pfn_to_paddr(mfn) <= virt_to_maddr(&_end))) #define page_get_owner(_p) (_p)->v.inuse.domain #define page_set_owner(_p,_d) ((_p)->v.inuse.domain = (_d)) -- 1.7.10.4