linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] powerpc/mm: honor O_SYNC flag for memory mapping
@ 2009-11-26  8:02 Li Yang
  2009-11-27  2:40 ` Paul Mackerras
  0 siblings, 1 reply; 2+ messages in thread
From: Li Yang @ 2009-11-26  8:02 UTC (permalink / raw)
  To: benh, linuxppc-dev

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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] powerpc/mm: honor O_SYNC flag for memory mapping
  2009-11-26  8:02 [PATCH] powerpc/mm: honor O_SYNC flag for memory mapping Li Yang
@ 2009-11-27  2:40 ` Paul Mackerras
  0 siblings, 0 replies; 2+ messages in thread
From: Paul Mackerras @ 2009-11-27  2:40 UTC (permalink / raw)
  To: Li Yang; +Cc: linuxppc-dev

Li Yang writes:

> 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.

NAK, since it is an incompatible change to the kernel ABI.

What sort of memory is this that you want to map as cacheable?  Is it
normal system RAM that your platform code reserves, or is it some
other kind of memory?

If it's the normal system RAM, you could make phys_mem_access_prot()
smart enough to recognize that (by looking in the lmb array or the
device tree).

If it's another kind of memory, it should be described in the device
tree, and you could have a platform-specific phys_mem_access_prot
function for your platform that looks in the device tree to see if the
memory being mapped is this special sort of memory.

Paul.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-11-27  2:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-26  8:02 [PATCH] powerpc/mm: honor O_SYNC flag for memory mapping Li Yang
2009-11-27  2:40 ` Paul Mackerras

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).