mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arjan van de Ven <arjan@infradead.org>
To: Linus Torvalds <torvalds@osdl.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Andrew Morton <akpm@osdl.org>
Subject: Re: [PATCH] Fix mmap_kmem (was: [question] What's the difference between /dev/kmem and /dev/mem)
Date: Sat, 13 Aug 2005 19:25:24 +0200	[thread overview]
Message-ID: <1123953924.3187.22.camel@laptopd505.fenrus.org> (raw)
In-Reply-To: <Pine.LNX.4.58.0508130955010.19049@g5.osdl.org>

[-- Attachment #1: Type: text/plain, Size: 562 bytes --]

On Sat, 2005-08-13 at 09:56 -0700, Linus Torvalds wrote:
> 
> On Sat, 13 Aug 2005, Arjan van de Ven wrote:
> > > 
> > > So I'd be perfectly happy to fix this, but I'd be even happier if we made 
> > > the whole kmem thing a config variable (maybe even default it to "off").
> > 
> > attached is a simple patch that does exactly this...
> 
> Well, you should have fixed the bug that Steven had at the same time. Now 
> his patch won't even apply any more, I suspect ;)

Patch is forgiving ;)

attached is the same patch but now with Steven's change made as well


[-- Attachment #2: mem.patch --]
[-- Type: text/x-patch, Size: 3689 bytes --]

diff -purN linux-before/drivers/char/Kconfig linux-2.6.12/drivers/char/Kconfig
--- linux-before/drivers/char/Kconfig	2005-08-13 18:38:11.210821000 +0200
+++ linux-2.6.12/drivers/char/Kconfig	2005-08-13 18:44:31.182935339 +0200
@@ -1000,6 +1000,12 @@ config MMTIMER
 	  The mmtimer device allows direct userspace access to the
 	  Altix system timer.
 
+config DEVKMEM
+	tristate "Userspace access to virtual kernel memory (/dev/kmem)"
+	help
+	  The /dev/kmem device allows userspace access to kernel virtual
+	  memory, which can be useful for kernel debugging.
+
 source "drivers/char/tpm/Kconfig"
 
 endmenu
diff -purN linux-before/drivers/char/mem.c linux-2.6.12/drivers/char/mem.c
--- linux-before/drivers/char/mem.c	2005-08-13 18:38:11.261815000 +0200
+++ linux-2.6.12/drivers/char/mem.c	2005-08-13 18:41:09.002351297 +0200
@@ -259,22 +259,6 @@ static int mmap_mem(struct file * file, 
 	return 0;
 }
 
-static int mmap_kmem(struct file * file, struct vm_area_struct * vma)
-{
-        unsigned long long val;
-	/*
-	 * RED-PEN: on some architectures there is more mapped memory
-	 * than available in mem_map which pfn_valid checks
-	 * for. Perhaps should add a new macro here.
-	 *
-	 * RED-PEN: vmalloc is not supported right now.
-	 */
-	if (!pfn_valid(vma->vm_pgoff))
-		return -EIO;
-	val = (u64)vma->vm_pgoff << PAGE_SHIFT;
-	vma->vm_pgoff = __pa(val) >> PAGE_SHIFT;
-	return mmap_mem(file, vma);
-}
 
 #ifdef CONFIG_CRASH_DUMP
 /*
@@ -313,6 +297,25 @@ static ssize_t read_oldmem(struct file *
 extern long vread(char *buf, char *addr, unsigned long count);
 extern long vwrite(char *buf, char *addr, unsigned long count);
 
+#ifdef CONFIG_DEVKMEM
+
+static int mmap_kmem(struct file * file, struct vm_area_struct * vma)
+{
+        unsigned long long val;
+	/*
+	 * RED-PEN: on some architectures there is more mapped memory
+	 * than available in mem_map which pfn_valid checks
+	 * for. Perhaps should add a new macro here.
+	 *
+	 * RED-PEN: vmalloc is not supported right now.
+	 */
+	val = (u64)vma->vm_pgoff << PAGE_SHIFT;
+	vma->vm_pgoff = __pa(val) >> PAGE_SHIFT;
+	if (!pfn_valid(vma->vm_pgoff))
+		return -EIO;
+	return mmap_mem(file, vma);
+}
+
 /*
  * This function reads the *virtual* memory as seen by the kernel.
  */
@@ -521,6 +524,8 @@ static ssize_t write_kmem(struct file * 
  	return virtr + wrote;
 }
 
+#endif
+
 #if (defined(CONFIG_ISA) || !defined(__mc68000__)) && (!defined(CONFIG_PPC_ISERIES) || defined(CONFIG_PCI))
 static ssize_t read_port(struct file * file, char __user * buf,
 			 size_t count, loff_t *ppos)
@@ -768,6 +773,7 @@ static struct file_operations mem_fops =
 	.open		= open_mem,
 };
 
+#ifdef CONFIG_DEVKMEM
 static struct file_operations kmem_fops = {
 	.llseek		= memory_lseek,
 	.read		= read_kmem,
@@ -775,6 +781,7 @@ static struct file_operations kmem_fops 
 	.mmap		= mmap_kmem,
 	.open		= open_kmem,
 };
+#endif
 
 static struct file_operations null_fops = {
 	.llseek		= null_lseek,
@@ -843,9 +850,11 @@ static int memory_open(struct inode * in
 		case 1:
 			filp->f_op = &mem_fops;
 			break;
+#ifdef CONFIG_DEVKMEM
 		case 2:
 			filp->f_op = &kmem_fops;
 			break;
+#endif
 		case 3:
 			filp->f_op = &null_fops;
 			break;
@@ -894,7 +903,9 @@ static const struct {
 	struct file_operations	*fops;
 } devlist[] = { /* list of minor devices */
 	{1, "mem",     S_IRUSR | S_IWUSR | S_IRGRP, &mem_fops},
+#ifdef CONFIG_DEVKMEM
 	{2, "kmem",    S_IRUSR | S_IWUSR | S_IRGRP, &kmem_fops},
+#endif
 	{3, "null",    S_IRUGO | S_IWUGO,           &null_fops},
 #if (defined(CONFIG_ISA) || !defined(__mc68000__)) && (!defined(CONFIG_PPC_ISERIES) || defined(CONFIG_PCI))
 	{4, "port",    S_IRUSR | S_IWUSR | S_IRGRP, &port_fops},

  reply	other threads:[~2005-08-13 17:25 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-11 21:36 [question] What's the difference between /dev/kmem and /dev/mem Steven Rostedt
2005-08-12  1:15 ` [PATCH] Fix mmap_kmem (was: [question] What's the difference between /dev/kmem and /dev/mem) Steven Rostedt
2005-08-12 14:25   ` Hugh Dickins
2005-08-12 16:35   ` Linus Torvalds
2005-08-12 16:56     ` Dave Jones
2005-08-12 17:07       ` Steven Rostedt
2005-08-12 17:16         ` Arjan van de Ven
2005-08-12 17:32           ` Steven Rostedt
2005-08-12 17:01     ` Steven Rostedt
2005-08-13 13:39     ` [PATCH] Fix mmap kmem " Nicolas George
2005-08-13 16:50     ` [PATCH] Fix mmap_kmem " Arjan van de Ven
2005-08-13 16:56       ` Linus Torvalds
2005-08-13 17:25         ` Arjan van de Ven [this message]
2005-08-13 17:37           ` Linus Torvalds
2005-08-13 18:18             ` Arjan van de Ven
2005-08-16 22:12               ` Greg Edwards
2005-08-16 23:33                 ` Alan Cox
2005-08-16 23:47                   ` Steven Rostedt
2005-08-15 19:33             ` Olaf Hering
2005-08-15 21:14               ` Jeff Dike
2005-08-15 21:50                 ` Olaf Hering
2005-08-15 22:41               ` Linus Torvalds
2005-08-16  1:16             ` Steven Rostedt
2005-08-16  1:22               ` Steven Rostedt
2005-08-16  1:36                 ` Linus Torvalds
2005-08-13 16:57       ` Joshua Hudson
2005-08-13 17:27         ` Arjan van de Ven
2005-08-14 14:50       ` Martin J. Bligh
2005-08-18 14:07         ` Arjan van de Ven
2005-08-18 14:18           ` Steven Rostedt
     [not found] <1123796188.17269.127.camel@localhost.localdomain.suse.lists.linux.kernel>
     [not found] ` <1123809302.17269.139.camel@localhost.localdomain.suse.lists.linux.kernel>
     [not found]   ` <Pine.LNX.4.58.0508120930150.3295@g5.osdl.org.suse.lists.linux.kernel>
2005-08-12 16:54     ` Andi Kleen
2005-08-12 17:56       ` Arjan van de Ven
2005-08-12 18:26         ` Andi Kleen
2005-08-13  9:56       ` Ingo Oeser
2005-08-13 12:40         ` Andi Kleen

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=1123953924.3187.22.camel@laptopd505.fenrus.org \
    --to=arjan@infradead.org \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@osdl.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

all inboxes | Powered by JetHome®