linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
To: linuxppc-dev@lists.ozlabs.org
Cc: Jeremy Kerr <jeremy.kerr@au1.ibm.com>
Subject: Re: [PATCH] powerpc/powernv: Fix vma page prot flags in opal-prd driver
Date: Thu, 25 Jun 2015 11:45:46 +0530	[thread overview]
Message-ID: <20150625061546.GA4233@dirshya.in.ibm.com> (raw)
In-Reply-To: <20150621182616.9866.16633.stgit@drishya>

* Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com> [2015-06-21 23:56:16]:

> opal-prd driver will mmap() firmware code/data area as private
> mapping to prd user space daemon.  Write to this page will
> trigger COW faults.  The new COW pages are normal kernel RAM
> pages accounted by the kernel and are not special.
> 
> vma->vm_page_prot value will be used at page fault time
> for the new COW pages, while pgprot_t value passed in
> remap_pfn_range() is used for the initial page table entry.
> 
> Hence:
> * Do not add _PAGE_SPECIAL in vma, but only for remap_pfn_range()
> * Also remap_pfn_range() will add the _PAGE_SPECIAL flag using
>   pte_mkspecial() call, hence no need to specify in the driver
> 
> This fix resolves the page accounting warning shown below:
> BUG: Bad rss-counter state mm:c0000007d34ac600 idx:1 val:19
> 
> The above warning is triggered since _PAGE_SPECIAL was incorrectly
> being set for the normal kernel COW pages.
> 
> Signed-off-by: Vaidyanathan Srinivasan <svaidy@linux.vnet.ibm.com>
> ---
>  arch/powerpc/platforms/powernv/opal-prd.c |    9 ++++-----
>  1 file changed, 4 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/powernv/opal-prd.c b/arch/powerpc/platforms/powernv/opal-prd.c
> index 46cb3fe..4ece8e4 100644
> --- a/arch/powerpc/platforms/powernv/opal-prd.c
> +++ b/arch/powerpc/platforms/powernv/opal-prd.c
> @@ -112,6 +112,7 @@ static int opal_prd_open(struct inode *inode, struct file *file)
>  static int opal_prd_mmap(struct file *file, struct vm_area_struct *vma)
>  {
>  	size_t addr, size;
> +	pgprot_t page_prot;
>  	int rc;
>  
>  	pr_devel("opal_prd_mmap(0x%016lx, 0x%016lx, 0x%lx, 0x%lx)\n",
> @@ -125,13 +126,11 @@ static int opal_prd_mmap(struct file *file, struct vm_area_struct *vma)
>  	if (!opal_prd_range_is_valid(addr, size))
>  		return -EINVAL;
>  
> -	vma->vm_page_prot = __pgprot(pgprot_val(phys_mem_access_prot(file,
> -						vma->vm_pgoff,
> -						 size, vma->vm_page_prot))
> -					| _PAGE_SPECIAL);
> +	page_prot = phys_mem_access_prot(file, vma->vm_pgoff,
> +					 size, vma->vm_page_prot);
>  
>  	rc = remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, size,
> -			vma->vm_page_prot);
> +				page_prot);

Hi Ben,

remap_pfn_range() is the correct method to map the firmware pages
because we will not have struct page associated with this RAM area.

We do a memblock_reserve() in early boot and take out this memory from
kernel and avoid struct page allocation/init for these.

vm_insert_page() is an alternative that would have worked if kernel
allocated the memory, in which case we can bump up the page count and
map the page to user space.  This is already done by vm_insert_page()
and we will not need to make the page special.

However, this use case fits remap_pfn_range() and page special
mechanism since there is no struct page associate with this physical
pages.

--Vaidy

  reply	other threads:[~2015-06-25  6:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-21 18:26 [PATCH] powerpc/powernv: Fix vma page prot flags in opal-prd driver Vaidyanathan Srinivasan
2015-06-25  6:15 ` Vaidyanathan Srinivasan [this message]
2015-06-25  7:43   ` Vaidyanathan Srinivasan

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=20150625061546.GA4233@dirshya.in.ibm.com \
    --to=svaidy@linux.vnet.ibm.com \
    --cc=jeremy.kerr@au1.ibm.com \
    --cc=linuxppc-dev@lists.ozlabs.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).