All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior
@ 2017-05-10  4:08 Juergen Gross
  2017-05-10  8:02 ` [Xen-devel] " Jan Beulich
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Juergen Gross @ 2017-05-10  4:08 UTC (permalink / raw)
  To: linux-kernel, xen-devel; +Cc: boris.ostrovsky, Juergen Gross

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

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Xen-devel] [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior
  2017-05-10  4:08 [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior Juergen Gross
@ 2017-05-10  8:02 ` Jan Beulich
  2017-05-10  8:08   ` Juergen Gross
  2017-05-10  8:08   ` [Xen-devel] " Juergen Gross
  2017-05-10  8:02 ` Jan Beulich
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 10+ messages in thread
From: Jan Beulich @ 2017-05-10  8:02 UTC (permalink / raw)
  To: Juergen Gross; +Cc: xen-devel, boris.ostrovsky, linux-kernel

>>> 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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior
  2017-05-10  4:08 [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior Juergen Gross
  2017-05-10  8:02 ` [Xen-devel] " Jan Beulich
@ 2017-05-10  8:02 ` Jan Beulich
  2017-05-10 13:45 ` Boris Ostrovsky
  2017-05-10 13:45 ` Boris Ostrovsky
  3 siblings, 0 replies; 10+ messages in thread
From: Jan Beulich @ 2017-05-10  8:02 UTC (permalink / raw)
  To: Juergen Gross; +Cc: xen-devel, boris.ostrovsky, linux-kernel

>>> 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


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Xen-devel] [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior
  2017-05-10  8:02 ` [Xen-devel] " Jan Beulich
  2017-05-10  8:08   ` Juergen Gross
@ 2017-05-10  8:08   ` Juergen Gross
  1 sibling, 0 replies; 10+ messages in thread
From: Juergen Gross @ 2017-05-10  8:08 UTC (permalink / raw)
  To: Jan Beulich; +Cc: xen-devel, boris.ostrovsky, linux-kernel

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior
  2017-05-10  8:02 ` [Xen-devel] " Jan Beulich
@ 2017-05-10  8:08   ` Juergen Gross
  2017-05-10  8:08   ` [Xen-devel] " Juergen Gross
  1 sibling, 0 replies; 10+ messages in thread
From: Juergen Gross @ 2017-05-10  8:08 UTC (permalink / raw)
  To: Jan Beulich; +Cc: xen-devel, boris.ostrovsky, linux-kernel

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

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior
  2017-05-10  4:08 [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior Juergen Gross
                   ` (2 preceding siblings ...)
  2017-05-10 13:45 ` Boris Ostrovsky
@ 2017-05-10 13:45 ` Boris Ostrovsky
  2017-05-10 14:19   ` Juergen Gross
  2017-05-10 14:19   ` Juergen Gross
  3 siblings, 2 replies; 10+ messages in thread
From: Boris Ostrovsky @ 2017-05-10 13:45 UTC (permalink / raw)
  To: Juergen Gross, linux-kernel, xen-devel

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);
>  

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior
  2017-05-10  4:08 [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior Juergen Gross
  2017-05-10  8:02 ` [Xen-devel] " Jan Beulich
  2017-05-10  8:02 ` Jan Beulich
@ 2017-05-10 13:45 ` Boris Ostrovsky
  2017-05-10 13:45 ` Boris Ostrovsky
  3 siblings, 0 replies; 10+ messages in thread
From: Boris Ostrovsky @ 2017-05-10 13:45 UTC (permalink / raw)
  To: Juergen Gross, linux-kernel, xen-devel

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);
>  


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior
  2017-05-10 13:45 ` Boris Ostrovsky
  2017-05-10 14:19   ` Juergen Gross
@ 2017-05-10 14:19   ` Juergen Gross
  1 sibling, 0 replies; 10+ messages in thread
From: Juergen Gross @ 2017-05-10 14:19 UTC (permalink / raw)
  To: Boris Ostrovsky, linux-kernel, xen-devel

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior
  2017-05-10 13:45 ` Boris Ostrovsky
@ 2017-05-10 14:19   ` Juergen Gross
  2017-05-10 14:19   ` Juergen Gross
  1 sibling, 0 replies; 10+ messages in thread
From: Juergen Gross @ 2017-05-10 14:19 UTC (permalink / raw)
  To: Boris Ostrovsky, linux-kernel, xen-devel

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


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior
@ 2017-05-10  4:08 Juergen Gross
  0 siblings, 0 replies; 10+ messages in thread
From: Juergen Gross @ 2017-05-10  4:08 UTC (permalink / raw)
  To: linux-kernel, xen-devel; +Cc: Juergen Gross, boris.ostrovsky

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


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-05-10 14:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-10  4:08 [PATCH] xen: adjust early dom0 p2m handling to xen hypervisor behavior Juergen Gross
2017-05-10  8:02 ` [Xen-devel] " Jan Beulich
2017-05-10  8:08   ` Juergen Gross
2017-05-10  8:08   ` [Xen-devel] " Juergen Gross
2017-05-10  8:02 ` Jan Beulich
2017-05-10 13:45 ` Boris Ostrovsky
2017-05-10 13:45 ` Boris Ostrovsky
2017-05-10 14:19   ` Juergen Gross
2017-05-10 14:19   ` Juergen Gross
  -- strict thread matches above, loose matches on Subject: below --
2017-05-10  4:08 Juergen Gross

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.