From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753525AbdEJNqA (ORCPT ); Wed, 10 May 2017 09:46:00 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:28088 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753211AbdEJNp5 (ORCPT ); Wed, 10 May 2017 09:45:57 -0400 Subject: Re: [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior To: Juergen Gross , linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org References: <20170510040844.24355-1-jgross@suse.com> From: Boris Ostrovsky Message-ID: <9c434080-8b23-8bc5-1560-9352b9c1e55a@oracle.com> Date: Wed, 10 May 2017 09:45:33 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <20170510040844.24355-1-jgross@suse.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Source-IP: aserv0022.oracle.com [141.146.126.234] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05/10/2017 12:08 AM, Juergen Gross wrote: > When booted as pv-guest the p2m list presented by the Xen is already > mapped to virtual addresses. In dom0 case the hypervisor might make use > of 2M- or 1G-pages for this mapping. Unfortunately while being properly > aligned in virtual and machine address space, those pages might not be > aligned properly in guest physical address space. Is this the only place where we shouldn't assume that large page is properly aligned (in pfn space)? -boris > > So when trying to obtain the guest physical address of such a page > pud_pfn() and pmd_pfn() must be avoided as those will mask away guest > physical address bits not being zero in this special case. > > Signed-off-by: Juergen Gross > --- > arch/x86/xen/mmu_pv.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c > index 9d9ae6650aa1..7397d8b8459d 100644 > --- a/arch/x86/xen/mmu_pv.c > +++ b/arch/x86/xen/mmu_pv.c > @@ -2025,7 +2025,8 @@ static unsigned long __init xen_read_phys_ulong(phys_addr_t addr) > > /* > * Translate a virtual address to a physical one without relying on mapped > - * page tables. > + * page tables. Don't rely on big pages being aligned in (guest) physical > + * space! > */ > static phys_addr_t __init xen_early_virt_to_phys(unsigned long vaddr) > { > @@ -2046,7 +2047,7 @@ static phys_addr_t __init xen_early_virt_to_phys(unsigned long vaddr) > sizeof(pud))); > if (!pud_present(pud)) > return 0; > - pa = pud_pfn(pud) << PAGE_SHIFT; > + pa = pud_val(pud) & PTE_PFN_MASK; > if (pud_large(pud)) > return pa + (vaddr & ~PUD_MASK); > > @@ -2054,7 +2055,7 @@ static phys_addr_t __init xen_early_virt_to_phys(unsigned long vaddr) > sizeof(pmd))); > if (!pmd_present(pmd)) > return 0; > - pa = pmd_pfn(pmd) << PAGE_SHIFT; > + pa = pmd_val(pmd) & PTE_PFN_MASK; > if (pmd_large(pmd)) > return pa + (vaddr & ~PMD_MASK); >