Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1638546 > unrolled thread

[PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior

Started byJuergen Gross <jgross@suse.com>
First post2017-05-10 06:10 +0200
Last post2017-05-10 16:30 +0200
Articles 5 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior Juergen Gross <jgross@suse.com> - 2017-05-10 06:10 +0200
    Re: [Xen-devel] [PATCH] xen: adjust early dom0 p2m handling to  xen hypervisor behavior "Jan Beulich" <JBeulich@suse.com> - 2017-05-10 10:10 +0200
      Re: [Xen-devel] [PATCH] xen: adjust early dom0 p2m handling to xen  hypervisor behavior Juergen Gross <jgross@suse.com> - 2017-05-10 10:20 +0200
    Re: [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor  behavior Boris Ostrovsky <boris.ostrovsky@oracle.com> - 2017-05-10 15:50 +0200
      Re: [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor  behavior Juergen Gross <jgross@suse.com> - 2017-05-10 16:30 +0200

#1638546 — [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior

FromJuergen Gross <jgross@suse.com>
Date2017-05-10 06:10 +0200
Subject[PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior
Message-ID<tFr6N-3LM-1@gated-at.bofh.it>
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.

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 <jgross@suse.com>
---
 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);
 
-- 
2.12.0

[toc] | [next] | [standalone]


#1638639 — Re: [Xen-devel] [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior

From"Jan Beulich" <JBeulich@suse.com>
Date2017-05-10 10:10 +0200
SubjectRe: [Xen-devel] [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior
Message-ID<tFuR4-6F7-21@gated-at.bofh.it>
In reply to#1638546
>>> On 10.05.17 at 06:08, <jgross@suse.com> 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.
> 
> 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 <jgross@suse.com>

Reviewed-by: Jan Beulich <jbeulich@suse.com>

Perhaps worth Cc-ing stable@ ?

Jan

[toc] | [prev] | [next] | [standalone]


#1638644 — Re: [Xen-devel] [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior

FromJuergen Gross <jgross@suse.com>
Date2017-05-10 10:20 +0200
SubjectRe: [Xen-devel] [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior
Message-ID<tFv0K-6Kh-3@gated-at.bofh.it>
In reply to#1638639
On 10/05/17 10:02, Jan Beulich wrote:
>>>> On 10.05.17 at 06:08, <jgross@suse.com> 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.
>>
>> 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 <jgross@suse.com>
> 
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
> 
> Perhaps worth Cc-ing stable@ ?

Any backport needs to be done manually, as mmu_pv.c has been introduced
in 4.12 only.

As soon as the patch is upstream I'm planning to do that (trivial)
backport and send it to stable.


Juergen

[toc] | [prev] | [next] | [standalone]


#1638853 — Re: [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior

FromBoris Ostrovsky <boris.ostrovsky@oracle.com>
Date2017-05-10 15:50 +0200
SubjectRe: [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior
Message-ID<tFAa7-1mz-49@gated-at.bofh.it>
In reply to#1638546
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 <jgross@suse.com>
> ---
>  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);
>  

[toc] | [prev] | [next] | [standalone]


#1638870 — Re: [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior

FromJuergen Gross <jgross@suse.com>
Date2017-05-10 16:30 +0200
SubjectRe: [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior
Message-ID<tFAMN-1Qr-11@gated-at.bofh.it>
In reply to#1638853
On 10/05/17 15:45, Boris Ostrovsky wrote:
> 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)?

It is the only case requiring a change. xen_cleanmfnmap_*() already does
this correctly via the same mechanism I used in this patch.

I'm not aware of any other large pages set up by Xen for pv guests than
the ones for the initial p2m list. And these large pages are freed (via
xen_cleanmfnmap_*()) after setting up the final p2m list in kernel
virtual space.


Juergen

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web