From: Petr Tesarik <ptesarik@suse.cz>
To: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 03/10] x86: translate highmem /dev/mem pointers
Date: Fri, 17 Jun 2011 10:45:01 +0200 [thread overview]
Message-ID: <201106171045.01928.ptesarik@suse.cz> (raw)
In-Reply-To: <201106171038.25988.ptesarik@suse.cz>
On 32-bit x86, it is necessary to kmap/kunmap /dev/mem pointers in
the high memory area.
Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
---
arch/x86/include/asm/io.h | 4 ++--
arch/x86/mm/ioremap.c | 24 ++++++++++++++++++------
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index d02804d..9b994dd 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -311,8 +311,8 @@ BUILDIO(b, b, char)
BUILDIO(w, w, short)
BUILDIO(l, , int)
-extern void *xlate_dev_mem_ptr(unsigned long phys);
-extern void unxlate_dev_mem_ptr(unsigned long phys, void *addr);
+extern void *xlate_dev_mem_ptr(phys_addr_t phys);
+extern void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr);
extern int ioremap_change_attr(unsigned long vaddr, unsigned long size,
unsigned long prot_val);
diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
index be1ef57..fb566d7 100644
--- a/arch/x86/mm/ioremap.c
+++ b/arch/x86/mm/ioremap.c
@@ -308,26 +308,38 @@ EXPORT_SYMBOL(iounmap);
* Convert a physical pointer to a virtual kernel pointer for /dev/mem
* access
*/
-void *xlate_dev_mem_ptr(unsigned long phys)
+void *xlate_dev_mem_ptr(phys_addr_t phys)
{
void *addr;
- unsigned long start = phys & PAGE_MASK;
+ unsigned long pfn = phys >> PAGE_SHIFT;
+ phys_addr_t start = phys & ~((phys_addr_t)PAGE_SIZE-1);
/* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
- if (page_is_ram(start >> PAGE_SHIFT))
+ if (page_is_ram(pfn)) {
+ if (phys >= __pa(high_memory))
+ return pfn_valid(pfn)
+ ? kmap(pfn_to_page(pfn))
+ : NULL;
return __va(phys);
+ }
addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
if (addr)
- addr = (void *)((unsigned long)addr | (phys & ~PAGE_MASK));
+ addr = (void *)((unsigned long)addr |
+ ((unsigned long)phys & ~PAGE_MASK));
return addr;
}
-void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
+void unxlate_dev_mem_ptr(phys_addr_t phys, void *addr)
{
- if (page_is_ram(phys >> PAGE_SHIFT))
+ unsigned long pfn = phys >> PAGE_SHIFT;
+
+ if (page_is_ram(pfn)) {
+ if (phys >= __pa(high_memory))
+ kunmap(pfn_to_page(pfn));
return;
+ }
iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
return;
--
1.7.3.4
next prev parent reply other threads:[~2011-06-17 8:58 UTC|newest]
Thread overview: 128+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-17 8:38 [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Petr Tesarik
2011-06-17 8:38 ` Petr Tesarik
2011-06-17 8:38 ` Petr Tesarik
2011-06-17 8:43 ` [PATCH 01/10] Return EOF on out-of-bounds read from /dev/mem Petr Tesarik
2011-06-17 8:44 ` [PATCH 02/10] (un)xlate_dev_mem_ptr: use phys_addr_t for the @phys parameter Petr Tesarik
2011-06-17 8:45 ` Petr Tesarik [this message]
2011-06-17 8:45 ` [PATCH 04/10] ia64: change xlate_dev_mem_ptr's argument to phys_addr_t Petr Tesarik
2011-06-17 8:45 ` Petr Tesarik
2011-06-17 8:45 ` [PATCH 05/10] valid_phys_addr_range: use phys_addr_t for the @addr parameter Petr Tesarik
2011-06-17 8:46 ` [PATCH 06/10] sh: change valid_phys_addr_range's @addr param to phys_addr_t Petr Tesarik
2011-06-17 8:46 ` Petr Tesarik
2011-06-17 8:46 ` [PATCH 07/10] arm: " Petr Tesarik
2011-06-17 8:46 ` Petr Tesarik
2011-06-17 8:47 ` [PATCH 08/10] ia64: " Petr Tesarik
2011-06-17 8:47 ` Petr Tesarik
2011-06-17 8:48 ` [PATCH 09/10] x86: provide arch-specific valid_phys_addr_range() Petr Tesarik
2011-06-17 8:48 ` [PATCH 10/10] Allow reading/writing all memory through /dev/mem Petr Tesarik
2011-06-17 9:30 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Ingo Molnar
2011-06-17 9:30 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Ingo Molnar
2011-06-17 9:30 ` Ingo Molnar
2011-06-17 9:41 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of Russell King - ARM Linux
2011-06-17 9:41 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Russell King - ARM Linux
2011-06-17 9:41 ` Russell King - ARM Linux
2011-06-17 9:55 ` Petr Tesarik
2011-06-17 9:55 ` Petr Tesarik
2011-06-17 9:55 ` Petr Tesarik
2011-06-20 2:42 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Américo Wang
2011-06-20 2:42 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Américo Wang
2011-06-20 2:42 ` Américo Wang
2011-06-27 7:46 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of Petr Tesarik
2011-06-27 7:46 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Petr Tesarik
2011-06-27 7:46 ` Petr Tesarik
2011-06-19 23:02 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Ryan Mallon
2011-06-19 23:02 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Ryan Mallon
2011-06-19 23:02 ` Ryan Mallon
2011-06-19 23:44 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary H. Peter Anvin
2011-06-19 23:44 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses H. Peter Anvin
2011-06-19 23:44 ` H. Peter Anvin
2011-06-20 7:41 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Ingo Molnar
2011-06-20 7:41 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Ingo Molnar
2011-06-20 7:41 ` Ingo Molnar
2011-06-20 15:59 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary H. Peter Anvin
2011-06-20 15:59 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses H. Peter Anvin
2011-06-20 15:59 ` H. Peter Anvin
2011-06-20 16:40 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Ingo Molnar
2011-06-20 16:40 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Ingo Molnar
2011-06-20 16:40 ` Ingo Molnar
2011-06-20 16:44 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary H. Peter Anvin
2011-06-20 16:44 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses H. Peter Anvin
2011-06-20 16:44 ` H. Peter Anvin
2011-06-21 6:55 ` Srivatsa Vaddagiri
2011-06-21 6:56 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of Srivatsa Vaddagiri
2011-06-21 6:55 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Srivatsa Vaddagiri
2011-06-20 0:42 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of Matthew Wilcox
2011-06-20 0:42 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Matthew Wilcox
2011-06-20 0:42 ` Matthew Wilcox
2011-06-20 0:46 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Ryan Mallon
2011-06-20 0:46 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Ryan Mallon
2011-06-20 0:46 ` Ryan Mallon
2011-06-20 0:52 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of Matthew Wilcox
2011-06-20 0:52 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Matthew Wilcox
2011-06-20 0:52 ` Matthew Wilcox
2011-06-20 1:02 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Ryan Mallon
2011-06-20 1:02 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Ryan Mallon
2011-06-20 1:02 ` Ryan Mallon
2011-06-20 7:31 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Ingo Molnar
2011-06-20 7:31 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Ingo Molnar
2011-06-20 7:31 ` Ingo Molnar
2011-06-20 8:03 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Ryan Mallon
2011-06-20 8:03 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Ryan Mallon
2011-06-20 8:03 ` Ryan Mallon
2011-06-20 17:10 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Ray Lee
2011-06-20 17:10 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Ray Lee
2011-06-20 17:10 ` Ray Lee
2011-06-29 9:05 ` Petr Tesarik
2011-06-29 9:05 ` Petr Tesarik
2011-06-29 9:05 ` Petr Tesarik
2011-07-01 12:58 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Ingo Molnar
2011-07-01 12:58 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Ingo Molnar
2011-07-01 12:58 ` Ingo Molnar
2011-07-01 13:43 ` Petr Tesarik
2011-07-01 13:43 ` Petr Tesarik
2011-07-01 13:43 ` Petr Tesarik
2011-07-01 13:47 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Christoph Hellwig
2011-07-01 13:47 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Christoph Hellwig
2011-07-01 13:47 ` Christoph Hellwig
2011-07-01 14:37 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Ingo Molnar
2011-07-01 14:37 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Ingo Molnar
2011-07-01 14:37 ` Ingo Molnar
2011-07-01 14:41 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Christoph Hellwig
2011-07-01 14:41 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Christoph Hellwig
2011-07-01 14:41 ` Christoph Hellwig
2011-07-01 14:46 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Ingo Molnar
2011-07-01 14:46 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Ingo Molnar
2011-07-01 14:46 ` Ingo Molnar
2011-07-01 14:54 ` Petr Tesarik
2011-07-01 14:54 ` Petr Tesarik
2011-07-01 14:54 ` Petr Tesarik
2011-07-01 15:36 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Ingo Molnar
2011-07-01 15:36 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Ingo Molnar
2011-07-01 15:36 ` Ingo Molnar
2011-07-01 16:00 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary H. Peter Anvin
2011-07-01 16:00 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses H. Peter Anvin
2011-07-01 16:00 ` H. Peter Anvin
2011-07-01 16:13 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Ingo Molnar
2011-07-01 16:13 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Ingo Molnar
2011-07-01 16:13 ` Ingo Molnar
2011-07-01 19:34 ` Petr Tesarik
2011-07-01 19:34 ` Petr Tesarik
2011-07-01 19:34 ` Petr Tesarik
2011-07-01 19:56 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Ingo Molnar
2011-07-01 19:56 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Ingo Molnar
2011-07-01 19:56 ` Ingo Molnar
2011-07-01 20:44 ` Petr Tesarik
2011-07-01 20:44 ` Petr Tesarik
2011-07-01 20:44 ` Petr Tesarik
2011-07-03 19:46 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary Ingo Molnar
2011-07-03 19:46 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Ingo Molnar
2011-07-03 19:46 ` Ingo Molnar
2011-07-05 17:49 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of Matthew Garrett
2011-07-05 17:49 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses Matthew Garrett
2011-07-05 17:49 ` Matthew Garrett
2011-07-05 17:56 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary H. Peter Anvin
2011-07-05 17:56 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses H. Peter Anvin
2011-07-05 17:56 ` H. Peter Anvin
2011-07-05 22:34 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary H. Peter Anvin
2011-07-05 22:34 ` [PATCH 00/10] Enhance /dev/mem to allow read/write of arbitrary physical addresses H. Peter Anvin
2011-07-05 22:34 ` H. Peter Anvin
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=201106171045.01928.ptesarik@suse.cz \
--to=ptesarik@suse.cz \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.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.