The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Hans Rosenfeld <hans.rosenfeld@amd.com>
Cc: mingo@redhat.com, "H. Peter Anvin" <hpa@zytor.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] x86: fix pmd_bad and pud_bad to support huge pages
Date: Mon, 18 Feb 2008 19:53:42 +0100 (CET)	[thread overview]
Message-ID: <alpine.LFD.1.00.0802181928270.7583@apollo.tec.linutronix.de> (raw)
In-Reply-To: <20080218171047.GA4091@escobedo.amd.com>

On Mon, 18 Feb 2008, Hans Rosenfeld wrote:
> I recently stumbled upon a problem in the support for huge pages. If a
> program using huge pages does not explicitly unmap them, they remain
> mapped (and therefore, are lost) after the program exits.
> 
> I observed that the free huge page count in /proc/meminfo decreased when
> running my program, and it did not increase after the program exited.
> After running the program a few times, no more huge pages could be
> allocated.
> 
> The reason for this seems to be that the x86 pmd_bad and pud_bad
> consider pmd/pud entries having the PSE bit set invalid. I think there
> is nothing wrong with this bit being set, it just indicates that the
> lowest level of translation has been reached. This bit has to be (and
> is) checked after the basic validity of the entry has been checked, like
> in this fragment from follow_page() in mm/memory.c:
> 
>   if (pmd_none(*pmd) || unlikely(pmd_bad(*pmd)))
>           goto no_page_table;
> 
>   if (pmd_huge(*pmd)) {
>           BUG_ON(flags & FOLL_GET);
>           page = follow_huge_pmd(mm, address, pmd, flags & FOLL_WRITE);
>           goto out;
>   }
> 
> Note that this code currently doesn't work as intended if the pmd refers
> to a huge page, the pmd_huge() check can not be reached if the page is
> huge.
> 
> Extending pmd_bad() (and, for future 1GB page support, pud_bad()) to
> allow for the PSE bit being set fixes this. For similar reasons,
> allowing the NX bit being set is necessary, too. I have seen huge pages
> having the NX bit set in their pmd entry, which would cause the same
> problem.
 
Correct. Seems to be broken since ages. I applied your patch to fix
the primary problem, but ...

> --- a/include/asm-x86/pgtable_32.h
> +++ b/include/asm-x86/pgtable_32.h
> @@ -91,7 +91,9 @@ extern unsigned long pg0[];
>  /* To avoid harmful races, pmd_none(x) should check only the lower when PAE */
>  #define pmd_none(x)	(!(unsigned long)pmd_val(x))
>  #define pmd_present(x)	(pmd_val(x) & _PAGE_PRESENT)
> -#define	pmd_bad(x)	((pmd_val(x) & (~PAGE_MASK & ~_PAGE_USER)) != _KERNPG_TABLE)
> +#define	pmd_bad(x)	((pmd_val(x) \
> +			  & ~(PAGE_MASK | _PAGE_USER | _PAGE_PSE | _PAGE_NX)) \
> +			 != _KERNPG_TABLE)

So here we check for == _KERNPG_TABLE which includes the present bit as
well, so we mark it bad if its not present.
  
>  #define pages_to_mb(x) ((x) >> (20-PAGE_SHIFT))
> diff --git a/include/asm-x86/pgtable_64.h b/include/asm-x86/pgtable_64.h
> index bd4740a..02bd4aa 100644
> --- a/include/asm-x86/pgtable_64.h
> +++ b/include/asm-x86/pgtable_64.h
> @@ -153,12 +153,14 @@ static inline unsigned long pgd_bad(pgd_t pgd)
>  
>  static inline unsigned long pud_bad(pud_t pud)
>  {
> -	return pud_val(pud) & ~(PTE_MASK | _KERNPG_TABLE | _PAGE_USER);
> +	return pud_val(pud) &
> +		~(PTE_MASK | _KERNPG_TABLE | _PAGE_USER | _PAGE_PSE | _PAGE_NX);
>  }

We return 0, when the present bit is 0, but the code which follows
does not check the present bit neither in mm/memory.c nor in
x86/mm/hugetlbpage.c. 

I think the correct solution is to not check the present bit in
pmd/pud_bad for both, but we need to check all the use cases in 32bit
thorougly.
  
Thanks,

	tglx

      reply	other threads:[~2008-02-18 18:54 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-18 17:10 [PATCH] x86: fix pmd_bad and pud_bad to support huge pages Hans Rosenfeld
2008-02-18 18:53 ` Thomas Gleixner [this message]

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.LFD.1.00.0802181928270.7583@apollo.tec.linutronix.de \
    --to=tglx@linutronix.de \
    --cc=hans.rosenfeld@amd.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.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