public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: venkatesh.pallipadi@intel.com
To: ak@muc.de, ebiederm@xmission.com, rdreier@cisco.com,
	torvalds@linux-foundation.org, gregkh@suse.de, airlied@skynet.ie,
	davej@redhat.com, mingo@elte.hu, tglx@linutronix.de,
	hpa@zytor.com, akpm@linux-foundation.org, arjan@infradead.org,
	jesse.barnes@intel.com, davem@davemloft.net
Cc: linux-kernel@vger.kernel.org,
	Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>,
	Suresh Siddha <suresh.b.siddha@intel.com>
Subject: [patch 4/4] x86: PAT followup - use ioremap for devmem read of reserved regions
Date: Tue, 15 Jan 2008 18:39:59 -0800	[thread overview]
Message-ID: <20080116024112.291093000@intel.com> (raw)
In-Reply-To: 20080116023955.597433000@intel.com

[-- Attachment #1: devmem_read.patch --]
[-- Type: text/plain, Size: 4753 bytes --]

map and unmap reserved regions, before accessing through /dev/mem read
interface. This is for full compatibility with existing /dev/mem
usages.
For regions that are mapped in identity map, we use __va().

Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Signed-off-by: Suresh Siddha <suresh.b.siddha@intel.com>

Index: linux-2.6.git/arch/x86/mm/ioremap.c
===================================================================
--- linux-2.6.git.orig/arch/x86/mm/ioremap.c	2008-01-15 10:05:13.000000000 -0800
+++ linux-2.6.git/arch/x86/mm/ioremap.c	2008-01-15 10:39:18.000000000 -0800
@@ -32,6 +32,39 @@
 }
 EXPORT_SYMBOL(ioremap_wc);
 
+/*
+ * Convert a physical pointer to a virtual kernel pointer for /dev/mem
+ * access
+ */
+void *xlate_dev_mem_ptr(unsigned long phys)
+{
+	void *addr;
+	unsigned long start = phys & PAGE_MASK;
+
+	/*
+	 * If any memory in PAGE_SIZE is valid, then we can use __va. Otherwise
+	 * ioremap and unmap the memory.
+	 */
+	if (is_memory_any_valid(start, start + PAGE_SIZE))
+		return __va(phys);
+
+	addr = (void *)ioremap(start, PAGE_SIZE);
+	if (addr)
+		addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));
+
+	return addr;
+}
+
+void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
+{
+	unsigned long start = phys & PAGE_MASK;
+	if (is_memory_any_valid(start, start + PAGE_SIZE))
+		return;
+
+	iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
+	return;
+}
+
 int valid_phys_addr_range(unsigned long addr, size_t count)
 {
 	if (addr + count > __pa(high_memory))
Index: linux-2.6.git/drivers/char/mem.c
===================================================================
--- linux-2.6.git.orig/drivers/char/mem.c	2008-01-15 10:05:13.000000000 -0800
+++ linux-2.6.git/drivers/char/mem.c	2008-01-15 10:05:51.000000000 -0800
@@ -127,9 +127,14 @@
 		 * by the kernel or data corruption may occur
 		 */
 		ptr = xlate_dev_mem_ptr(p);
+		if (!ptr)
+			return -EFAULT;
 
 		if (copy_to_user(buf, ptr, sz))
 			return -EFAULT;
+
+		unxlate_dev_mem_ptr(p, ptr);
+
 		buf += sz;
 		p += sz;
 		count -= sz;
@@ -184,6 +189,11 @@
 		 * by the kernel or data corruption may occur
 		 */
 		ptr = xlate_dev_mem_ptr(p);
+		if (!ptr) {
+			if (written)
+				break;
+			return -EFAULT;
+		}
 
 		copied = copy_from_user(ptr, buf, sz);
 		if (copied) {
@@ -192,6 +202,9 @@
 				break;
 			return -EFAULT;
 		}
+
+		unxlate_dev_mem_ptr(p, ptr);
+
 		buf += sz;
 		p += sz;
 		count -= sz;
Index: linux-2.6.git/include/asm-generic/iomap.h
===================================================================
--- linux-2.6.git.orig/include/asm-generic/iomap.h	2008-01-15 10:05:13.000000000 -0800
+++ linux-2.6.git/include/asm-generic/iomap.h	2008-01-15 10:23:24.000000000 -0800
@@ -69,4 +69,8 @@
 #define ioremap_wc ioremap_nocache
 #endif
 
+#ifndef unxlate_dev_mem_ptr
+static inline void unxlate_dev_mem_ptr(unsigned long phys, void *addr) {}
+#endif
+
 #endif
Index: linux-2.6.git/include/asm-x86/io.h
===================================================================
--- linux-2.6.git.orig/include/asm-x86/io.h	2008-01-15 10:05:13.000000000 -0800
+++ linux-2.6.git/include/asm-x86/io.h	2008-01-15 10:21:42.000000000 -0800
@@ -2,6 +2,7 @@
 #define _ASM_X86_IO_H
 
 #define ioremap_wc ioremap_wc
+#define unxlate_dev_mem_ptr unxlate_dev_mem_ptr
 
 #ifdef CONFIG_X86_32
 # include "io_32.h"
@@ -10,6 +11,8 @@
 #endif
 
 extern void __iomem * ioremap_wc(unsigned long offset, unsigned long size);
+extern void *xlate_dev_mem_ptr(unsigned long phys);
+extern void unxlate_dev_mem_ptr(unsigned long phys, void *addr);
 
 #define ARCH_HAS_VALID_PHYS_ADDR_RANGE
 
Index: linux-2.6.git/include/asm-x86/io_32.h
===================================================================
--- linux-2.6.git.orig/include/asm-x86/io_32.h	2008-01-15 10:05:13.000000000 -0800
+++ linux-2.6.git/include/asm-x86/io_32.h	2008-01-15 10:05:51.000000000 -0800
@@ -49,12 +49,6 @@
 #include <linux/vmalloc.h>
 
 /*
- * Convert a physical pointer to a virtual kernel pointer for /dev/mem
- * access
- */
-#define xlate_dev_mem_ptr(p)	__va(p)
-
-/*
  * Convert a virtual cached pointer to an uncached pointer
  */
 #define xlate_dev_kmem_ptr(p)	p
Index: linux-2.6.git/include/asm-x86/io_64.h
===================================================================
--- linux-2.6.git.orig/include/asm-x86/io_64.h	2008-01-15 10:05:13.000000000 -0800
+++ linux-2.6.git/include/asm-x86/io_64.h	2008-01-15 10:05:51.000000000 -0800
@@ -278,12 +278,6 @@
 #define BIO_VMERGE_BOUNDARY iommu_bio_merge
 
 /*
- * Convert a physical pointer to a virtual kernel pointer for /dev/mem
- * access
- */
-#define xlate_dev_mem_ptr(p)	__va(p)
-
-/*
  * Convert a virtual cached pointer to an uncached pointer
  */
 #define xlate_dev_kmem_ptr(p)	p

-- 

  parent reply	other threads:[~2008-01-16  2:41 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-16  2:39 [patch 0/4] x86: PAT followup - Incremental changes and bug fixes venkatesh.pallipadi
2008-01-16  2:39 ` [patch 1/4] x86: PAT followup - Do not fold two bits in _PAGE_PCD venkatesh.pallipadi
2008-01-16  2:39 ` [patch 2/4] x86: PAT followup - Remove KERNPG_TABLE from pte entry venkatesh.pallipadi
2008-01-16  8:14   ` Mika Penttilä
2008-01-16 18:17     ` Pallipadi, Venkatesh
2008-01-17  0:18     ` Venki Pallipadi
2008-01-16  2:39 ` [patch 3/4] x86: PAT followup - Remove reserved pages mapping to zero page and not map them venkatesh.pallipadi
2008-01-16  2:39 ` venkatesh.pallipadi [this message]
2008-01-16  7:33   ` [patch 4/4] x86: PAT followup - use ioremap for devmem read of reserved regions Ingo Molnar
2008-01-16  7:29 ` [patch 0/4] x86: PAT followup - Incremental changes and bug fixes Ingo Molnar
2008-01-16 18:57 ` Andreas Herrmann
2008-01-16 19:05   ` Pallipadi, Venkatesh
2008-01-16 19:37   ` Pallipadi, Venkatesh
2008-01-16 20:24   ` Ingo Molnar
2008-01-16 20:33   ` Venki Pallipadi
2008-01-16 22:01     ` Andi Kleen
2008-01-16 22:14       ` Pallipadi, Venkatesh
2008-01-16 22:29         ` Andi Kleen
2008-01-17 19:12     ` Andreas Herrmann3
2008-01-17 19:54       ` Andreas Herrmann3
2008-01-17 20:36       ` Ingo Molnar
2008-01-17 20:33         ` H. Peter Anvin
2008-01-17 20:56           ` Ingo Molnar
2008-01-17 20:57           ` Linus Torvalds
2008-01-17 20:44         ` Ingo Molnar
2008-01-17 21:03         ` Andreas Herrmann3
2008-01-17 21:13           ` Ingo Molnar
2008-01-17 21:22             ` Ingo Molnar
2008-01-17 21:31             ` Siddha, Suresh B
2008-01-17 21:38               ` H. Peter Anvin
2008-01-24 20:22                 ` Eric W. Biederman
2008-01-24 21:36                   ` H. Peter Anvin
2008-01-17 21:42               ` Ingo Molnar
2008-01-17 22:06                 ` Andreas Herrmann3
2008-01-17 22:05                   ` H. Peter Anvin
2008-01-17 22:15                   ` Ingo Molnar
2008-01-17 22:52                     ` Andreas Herrmann3
2008-01-17 23:04                       ` Venki Pallipadi
2008-01-17 23:24                         ` Andreas Herrmann3
2008-01-17 23:42                           ` Pallipadi, Venkatesh
2008-01-18 16:10                         ` Andreas Herrmann3
2008-01-18 17:13                           ` Pallipadi, Venkatesh
2008-01-18 17:33                             ` Balbir Singh
2008-01-18  4:25               ` Andi Kleen
2008-01-17 21:42             ` Andreas Herrmann3
2008-01-17 22:13               ` Ingo Molnar
2008-01-17 22:16               ` Andreas Herrmann3
2008-01-17 22:26               ` Andreas Herrmann3
2008-01-17 22:35                 ` Ingo Molnar
2008-01-17 23:06                   ` Andreas Herrmann3

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=20080116024112.291093000@intel.com \
    --to=venkatesh.pallipadi@intel.com \
    --cc=airlied@skynet.ie \
    --cc=ak@muc.de \
    --cc=akpm@linux-foundation.org \
    --cc=arjan@infradead.org \
    --cc=davej@redhat.com \
    --cc=davem@davemloft.net \
    --cc=ebiederm@xmission.com \
    --cc=gregkh@suse.de \
    --cc=hpa@zytor.com \
    --cc=jesse.barnes@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=rdreier@cisco.com \
    --cc=suresh.b.siddha@intel.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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