mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>
Subject: Re: [Xen-devel] [PATCH 4/7] xen/mmu: Recycle the Xen provided L4, L3, and L2 pages
Date: Fri, 27 Jul 2012 12:45:38 +0100	[thread overview]
Message-ID: <alpine.DEB.2.02.1207271241580.26163@kaball.uk.xensource.com> (raw)
In-Reply-To: <1343335652-5659-5-git-send-email-konrad.wilk@oracle.com>

On Thu, 26 Jul 2012, Konrad Rzeszutek Wilk wrote:
> As we are not using them. We end up only using the L1 pagetables
> and grafting those to our page-tables.
> 
> Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> ---
>  arch/x86/xen/mmu.c |   38 ++++++++++++++++++++++++++++++++------
>  1 files changed, 32 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
> index 48bdc9f..7f54b75 100644
> --- a/arch/x86/xen/mmu.c
> +++ b/arch/x86/xen/mmu.c
> @@ -1724,6 +1724,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
>  {
>  	pud_t *l3;
>  	pmd_t *l2;
> +	unsigned long addr[3];
> +	unsigned long pt_base, pt_end;
> +	unsigned i;
>  
>  	/* max_pfn_mapped is the last pfn mapped in the initial memory
>  	 * mappings. Considering that on Xen after the kernel mappings we
> @@ -1731,6 +1734,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
>  	 * set max_pfn_mapped to the last real pfn mapped. */
>  	max_pfn_mapped = PFN_DOWN(__pa(xen_start_info->mfn_list));
>  
> +	pt_base = PFN_DOWN(__pa(xen_start_info->pt_base));
> +	pt_end = PFN_DOWN(__pa(xen_start_info->pt_base + (xen_start_info->nr_pt_frames * PAGE_SIZE)));
> +
>  	/* Zap identity mapping */
>  	init_level4_pgt[0] = __pgd(0);
>  
> @@ -1749,6 +1755,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
>  	l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
>  	l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
>  
> +	addr[0] = (unsigned long)pgd;
> +	addr[1] = (unsigned long)l2;
> +	addr[2] = (unsigned long)l3;
>  	/* Graft it onto L4[272][0]. Note that we creating an aliasing problem:
>  	 * Both L4[272][0] and L4[511][511] have entries that point to the same
>  	 * L2 (PMD) tables. Meaning that if you modify it in __va space
> @@ -1791,12 +1800,29 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
>  	__xen_write_cr3(true, __pa(init_level4_pgt));
>  	xen_mc_issue(PARAVIRT_LAZY_CPU);
>  
> -	/* Offset by one page since the original pgd is going bye bye */
> -	memblock_reserve(__pa(xen_start_info->pt_base + PAGE_SIZE),
> -			 (xen_start_info->nr_pt_frames * PAGE_SIZE) - PAGE_SIZE);
> -	/* and also RW it so it can actually be used. */
> -	set_page_prot(pgd, PAGE_KERNEL);
> -	clear_page(pgd);
> +	/* We can't that easily rip out L3 and L2, as the Xen pagetables are
> +	 * set out this way: [L4], [L1], [L2], [L3], [L1], [L1] ...  for
> +	 * the initial domain. For guests using the toolstack, they are in:
> +	 * [L4], [L3], [L2], [L1], [L1], order .. */
> +	for (i = 0; i < ARRAY_SIZE(addr); i++) {
> +		unsigned j;
> +		/* No idea about the order the addr are in, so just do them twice. */
> +		for (j = 0; j < ARRAY_SIZE(addr); j++) {

I don't think I understand this double loop.
Shouldn't we be looping on pt_base or pt_end?


> +			if (pt_base == PFN_DOWN(__pa(addr[j]))) {
> +				set_page_prot((void *)addr[j], PAGE_KERNEL);
> +				clear_page((void *)addr[j]);
> +				pt_base++;
> +
> +			}
> +			if (pt_end == PFN_DOWN(__pa(addr[j]))) {
> +				set_page_prot((void *)addr[j], PAGE_KERNEL);
> +				clear_page((void *)addr[j]);
> +				pt_end--;
> +			}
> +		}
> +	}
> +	/* Our (by three pages) smaller Xen pagetable that we are using */
> +	memblock_reserve(PFN_PHYS(pt_base), (pt_end - pt_base) * PAGE_SIZE);



  reply	other threads:[~2012-07-27 11:46 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-26 20:47 [RFC PATCH] Boot PV guests with more than 128GB (v1) for 3.7 Konrad Rzeszutek Wilk
2012-07-26 20:47 ` [PATCH 1/7] xen/mmu: use copy_page instead of memcpy Konrad Rzeszutek Wilk
2012-07-27  7:35   ` [Xen-devel] " Jan Beulich
2012-07-26 20:47 ` [PATCH 2/7] xen/mmu: For 64-bit do not call xen_map_identity_early Konrad Rzeszutek Wilk
2012-07-26 20:47 ` [PATCH 3/7] xen/mmu: Release the Xen provided L4 (PGD) back Konrad Rzeszutek Wilk
2012-07-27 11:37   ` [Xen-devel] " Stefano Stabellini
2012-07-27 17:35     ` Konrad Rzeszutek Wilk
2012-07-26 20:47 ` [PATCH 4/7] xen/mmu: Recycle the Xen provided L4, L3, and L2 pages Konrad Rzeszutek Wilk
2012-07-27 11:45   ` Stefano Stabellini [this message]
2012-07-27 17:38     ` [Xen-devel] " Konrad Rzeszutek Wilk
2012-07-31 14:39       ` Konrad Rzeszutek Wilk
2012-07-26 20:47 ` [PATCH 5/7] xen/p2m: Add logic to revector a P2M tree to use __va leafs Konrad Rzeszutek Wilk
2012-07-27 11:18   ` [Xen-devel] " Stefano Stabellini
2012-07-27 11:47     ` Jan Beulich
2012-07-27 17:34       ` Konrad Rzeszutek Wilk
2012-07-30  7:10         ` Jan Beulich
2012-07-26 20:47 ` [PATCH 6/7] xen/mmu: Copy and revector the P2M tree Konrad Rzeszutek Wilk
2012-07-26 20:47 ` [PATCH 7/7] xen/mmu: Remove from __ka space PMD entries for pagetables Konrad Rzeszutek Wilk
2012-07-27 11:31   ` [Xen-devel] " Stefano Stabellini
2012-07-27 17:42     ` Konrad Rzeszutek Wilk
2012-07-31 14:37       ` Konrad Rzeszutek Wilk
2012-07-27  7:34 ` [Xen-devel] [RFC PATCH] Boot PV guests with more than 128GB (v1) for 3.7 Jan Beulich
2012-07-27 10:00   ` Ian Campbell
2012-07-27 10:17     ` Jan Beulich
2012-07-27 10:21       ` Ian Campbell
2012-07-27 10:33         ` Jan Beulich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.DEB.2.02.1207271241580.26163@kaball.uk.xensource.com \
    --to=stefano.stabellini@eu.citrix.com \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®