linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Li Yang <leoli@freescale.com>
To: benh@kernel.crashing.org, linuxppc-dev@ozlabs.org
Subject: [PATCH] powerpc/mm: honor O_SYNC flag for memory mapping
Date: Thu, 26 Nov 2009 16:02:09 +0800	[thread overview]
Message-ID: <1259222529-27645-1-git-send-email-leoli@freescale.com> (raw)

There was no way to set mapped memory as cacheable if the memory
is not managed by Linux kernel.  It's not rare in real system to
allocate some dedicated memory to a certain application which is not
managed by kernel and then mmap'ed the memory to the application.
The memory should be cacheable but we can't map it to be cacheable
due to the intelligent setting of cacheability.

The patch makes the cacheability depend on O_SYNC flag of the file
mapped for non-kernel managed memory.  Also prints a deprecation
warning for mmap users without using O_SYNC.

Signed-off-by: Li Yang <leoli@freescale.com>
---
 arch/powerpc/mm/mem.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/mm/mem.c b/arch/powerpc/mm/mem.c
index 579382c..b9ef77a 100644
--- a/arch/powerpc/mm/mem.c
+++ b/arch/powerpc/mm/mem.c
@@ -101,8 +101,17 @@ pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
 	if (ppc_md.phys_mem_access_prot)
 		return ppc_md.phys_mem_access_prot(file, pfn, size, vma_prot);
 
-	if (!page_is_ram(pfn))
-		vma_prot = pgprot_noncached(vma_prot);
+	/* kernel managed memory is always cacheable, otherwise is controlled
+	 * by O_SYNC flag of open() */
+	if (!page_is_ram(pfn)) {
+		if (file->f_flags & O_SYNC)
+			vma_prot = pgprot_noncached(vma_prot);
+		else
+			printk(KERN_WARNING
+				"Warning: mmap on file without O_SYNC will be "
+				"mapped as cacheable.  Make sure it is desired."
+				"\n");
+	}
 
 	return vma_prot;
 }
-- 
1.6.4

             reply	other threads:[~2009-11-26  8:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-26  8:02 Li Yang [this message]
2009-11-27  2:40 ` [PATCH] powerpc/mm: honor O_SYNC flag for memory mapping Paul Mackerras

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=1259222529-27645-1-git-send-email-leoli@freescale.com \
    --to=leoli@freescale.com \
    --cc=benh@kernel.crashing.org \
    --cc=linuxppc-dev@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).