All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: "Aneesh Kumar K.V" <aneesh.kumar@linux.vnet.ibm.com>
Cc: paulus@samba.org, linuxppc-dev@lists.ozlabs.org,
	david@gibson.dropbear.id.au
Subject: Re: [RFC PATCH] powerpc/mm: Return NULL for not present hugetlb page
Date: Thu, 07 May 2015 18:17:26 +1000	[thread overview]
Message-ID: <1430986646.3453.34.camel@kernel.crashing.org> (raw)
In-Reply-To: <1430982981-23700-1-git-send-email-aneesh.kumar@linux.vnet.ibm.com>

On Thu, 2015-05-07 at 12:46 +0530, Aneesh Kumar K.V wrote:
> We need to check whether pte is present in follow_huge_addr and
> properly return NULL if mapping is not present. Also use READ_ONCE
> when dereferencing pte_t address.

Do that need to go to stable as well ?

> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
> ---
>  arch/powerpc/mm/hugetlbpage.c | 25 ++++++++++++++++---------
>  1 file changed, 16 insertions(+), 9 deletions(-)
> 
> diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c
> index 0ce968b00b7c..f5688423bc69 100644
> --- a/arch/powerpc/mm/hugetlbpage.c
> +++ b/arch/powerpc/mm/hugetlbpage.c
> @@ -689,27 +689,34 @@ void hugetlb_free_pgd_range(struct mmu_gather *tlb,
>  struct page *
>  follow_huge_addr(struct mm_struct *mm, unsigned long address, int write)
>  {
> -	pte_t *ptep;
> -	struct page *page;
> +	pte_t *ptep, pte;
>  	unsigned shift;
>  	unsigned long mask, flags;
> +	struct page *page = ERR_PTR(-EINVAL);
> +
> +	local_irq_save(flags);
> +	ptep = find_linux_pte_or_hugepte(mm->pgd, address, &shift);
> +	if (!ptep)
> +		goto no_page;
> +	pte = READ_ONCE(*ptep);
>  	/*
> +	 * Verify it is a huge page else bail.
>  	 * Transparent hugepages are handled by generic code. We can skip them
>  	 * here.
>  	 */
> -	local_irq_save(flags);
> -	ptep = find_linux_pte_or_hugepte(mm->pgd, address, &shift);
> +	if (!shift || pmd_trans_huge((pmd_t)pte))
> +		goto no_page;
>  
> -	/* Verify it is a huge page else bail. */
> -	if (!ptep || !shift || pmd_trans_huge(*(pmd_t *)ptep)) {
> -		local_irq_restore(flags);
> -		return ERR_PTR(-EINVAL);
> +	if (!pte_present(pte)) {
> +		page = NULL;
> +		goto no_page;
>  	}
>  	mask = (1UL << shift) - 1;
> -	page = pte_page(*ptep);
> +	page = pte_page(pte);
>  	if (page)
>  		page += (address & mask) / PAGE_SIZE;
>  
> +no_page:
>  	local_irq_restore(flags);
>  	return page;
>  }

  reply	other threads:[~2015-05-07  8:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-07  7:16 [RFC PATCH] powerpc/mm: Return NULL for not present hugetlb page Aneesh Kumar K.V
2015-05-07  8:17 ` Benjamin Herrenschmidt [this message]
2015-05-07 10:56   ` Aneesh Kumar K.V
2015-05-07 23:44 ` David Gibson

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=1430986646.3453.34.camel@kernel.crashing.org \
    --to=benh@kernel.crashing.org \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=paulus@samba.org \
    /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 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.