Re: [BUG?] x86_64 : Can not read /dev/kmem ?

2005-03-22 Thread Andi Kleen
On Mon, Mar 14, 2005 at 11:37:19AM +0100, Eric Dumazet wrote:
> 
> Hi Andi
> 
> I tried to mmap /dev/kmem on x86_64 (linux-2.6.11) and got no success.
> 

Here's a patch that fixes the problem to me.


Fix mmap of /dev/kmem. It cannot ever have worked before.

vmalloc is still not supported because that would be more
complicated.

Signed-off-by: Andi Kleen <[EMAIL PROTECTED]>


diff -u linux-2.6.11/drivers/char/mem.c-o linux-2.6.11/drivers/char/mem.c
--- linux-2.6.11/drivers/char/mem.c-o   2004-12-24 22:34:47.0 +0100
+++ linux-2.6.11/drivers/char/mem.c 2005-03-22 12:36:33.852319000 +0100
@@ -211,6 +211,23 @@
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);
+}
+
 extern long vread(char *buf, char *addr, unsigned long count);
 extern long vwrite(char *buf, char *addr, unsigned long count);
 
@@ -567,7 +584,6 @@
return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
 }
 
-#define mmap_kmem  mmap_mem
 #define zero_lseek null_lseek
 #define full_lseek  null_lseek
 #define write_zero write_null
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [BUG?] x86_64 : Can not read /dev/kmem ?

2005-03-22 Thread Andi Kleen
On Mon, Mar 14, 2005 at 11:37:19AM +0100, Eric Dumazet wrote:
 
 Hi Andi
 
 I tried to mmap /dev/kmem on x86_64 (linux-2.6.11) and got no success.
 

Here's a patch that fixes the problem to me.


Fix mmap of /dev/kmem. It cannot ever have worked before.

vmalloc is still not supported because that would be more
complicated.

Signed-off-by: Andi Kleen [EMAIL PROTECTED]


diff -u linux-2.6.11/drivers/char/mem.c-o linux-2.6.11/drivers/char/mem.c
--- linux-2.6.11/drivers/char/mem.c-o   2004-12-24 22:34:47.0 +0100
+++ linux-2.6.11/drivers/char/mem.c 2005-03-22 12:36:33.852319000 +0100
@@ -211,6 +211,23 @@
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);
+}
+
 extern long vread(char *buf, char *addr, unsigned long count);
 extern long vwrite(char *buf, char *addr, unsigned long count);
 
@@ -567,7 +584,6 @@
return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
 }
 
-#define mmap_kmem  mmap_mem
 #define zero_lseek null_lseek
 #define full_lseek  null_lseek
 #define write_zero write_null
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [BUG?] x86_64 : Can not read /dev/kmem ?

2005-03-21 Thread Andi Kleen
Sorry for the late answer.

On Mon, Mar 14, 2005 at 11:37:19AM +0100, Eric Dumazet wrote:
> 
> Hi Andi
> 
> I tried to read /dev/kmem on x86_64 (linux-2.6.11) and got no success.
> 
> read() or pread() returns EINVAL

Yes. I fixed this once for 2.4, but somehow the changes never made 
it into 2.6. The VFS code doesn't like negative offsets, and the kernel
addresses are negative.

> 
> I tried mmap() too : mmap() calls succeed, but as soon the user process 
> dereference memory, we get :

Hmm, looks like a bug yes. I can reproduce it. Thanks for the report.
Will investigate later.

-Andi


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [BUG?] x86_64 : Can not read /dev/kmem ?

2005-03-21 Thread Andi Kleen
Sorry for the late answer.

On Mon, Mar 14, 2005 at 11:37:19AM +0100, Eric Dumazet wrote:
 
 Hi Andi
 
 I tried to read /dev/kmem on x86_64 (linux-2.6.11) and got no success.
 
 read() or pread() returns EINVAL

Yes. I fixed this once for 2.4, but somehow the changes never made 
it into 2.6. The VFS code doesn't like negative offsets, and the kernel
addresses are negative.

 
 I tried mmap() too : mmap() calls succeed, but as soon the user process 
 dereference memory, we get :

Hmm, looks like a bug yes. I can reproduce it. Thanks for the report.
Will investigate later.

-Andi


-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[BUG?] x86_64 : Can not read /dev/kmem ?

2005-03-14 Thread Eric Dumazet
Hi Andi
I tried to read /dev/kmem on x86_64 (linux-2.6.11) and got no success.
read() or pread() returns EINVAL
I tried mmap() too : mmap() calls succeed, but as soon the user process 
dereference memory, we get :

tinfo: Corrupted page table at address 2aabf800
PGD 8a983067 PUD c7e5a067 PMD 91588067 PTE 8048a025
Bad pagetable: 000d [1] SMP
CPU 0
Modules linked in: ipt_REJECT
Pid: 10892, comm: tinfo Not tainted 2.6.11
RIP: 0033:[<00100562>] [<00100562>]
RSP: 002b:7790  EFLAGS: 00010217
RAX: 2aabf000 RBX: 2abbe000 RCX: 2ac8fc0c
RDX: 0001 RSI: 1000 RDI: 
RBP: 77f8 R08: 0003 R09: 8048a000
R10: 0001 R11: 0206 R12: 001005b0
R13: 0001 R14: 2adfdfe8 R15: 00100530
FS:  2abcb970() GS:804866c0() knlGS:
CS:  0010 DS:  ES:  CR0: 8005003b
CR2: 2aabf800 CR3: 90368000 CR4: 06e0
Process tinfo (pid: 10892, threadinfo 8100901b, task 
8100c7d976c0)

RIP [<00100562>] RSP <7790>

Thank you
Eric Dumazet

# cat tinfo.c
#define _XOPEN_SOURCE 500
#include 
#include 
#include 
struct tcp_hashinfo {
struct tcp_ehash_bucket *__tcp_ehash;
struct tcp_bind_hashbucket *__tcp_bhash;
int __tcp_bhash_size;
int __tcp_ehash_size;
} tcp_hashinfo;
#define TCPINFO_ADDR 0x8048a000 /* tcp_hashinfo */
int main()
{
int fd = open("/dev/kmem", O_RDONLY) ;
if (pread(fd, _hashinfo, sizeof(tcp_hashinfo), TCPINFO_ADDR) == -1) {
lseek(fd, TCPINFO_ADDR, 0) ;
if (read(fd, _hashinfo, sizeof(tcp_hashinfo)) == -1) {
perror("Can not read /dev/kmem ?") ;
return 1 ;
}
}
printf("ehash=%p esize=%d bhash=%p bsize=%d\n",
tcp_hashinfo.__tcp_ehash,
tcp_hashinfo.__tcp_ehash_size,
tcp_hashinfo.__tcp_bhash,
tcp_hashinfo.__tcp_bhash_size) ;
return 0 ;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[BUG?] x86_64 : Can not read /dev/kmem ?

2005-03-14 Thread Eric Dumazet
Hi Andi
I tried to read /dev/kmem on x86_64 (linux-2.6.11) and got no success.
read() or pread() returns EINVAL
I tried mmap() too : mmap() calls succeed, but as soon the user process 
dereference memory, we get :

tinfo: Corrupted page table at address 2aabf800
PGD 8a983067 PUD c7e5a067 PMD 91588067 PTE 8048a025
Bad pagetable: 000d [1] SMP
CPU 0
Modules linked in: ipt_REJECT
Pid: 10892, comm: tinfo Not tainted 2.6.11
RIP: 0033:[00100562] [00100562]
RSP: 002b:7790  EFLAGS: 00010217
RAX: 2aabf000 RBX: 2abbe000 RCX: 2ac8fc0c
RDX: 0001 RSI: 1000 RDI: 
RBP: 77f8 R08: 0003 R09: 8048a000
R10: 0001 R11: 0206 R12: 001005b0
R13: 0001 R14: 2adfdfe8 R15: 00100530
FS:  2abcb970() GS:804866c0() knlGS:
CS:  0010 DS:  ES:  CR0: 8005003b
CR2: 2aabf800 CR3: 90368000 CR4: 06e0
Process tinfo (pid: 10892, threadinfo 8100901b, task 
8100c7d976c0)

RIP [00100562] RSP 7790

Thank you
Eric Dumazet

# cat tinfo.c
#define _XOPEN_SOURCE 500
#include unistd.h
#include stdio.h
#include fcntl.h
struct tcp_hashinfo {
struct tcp_ehash_bucket *__tcp_ehash;
struct tcp_bind_hashbucket *__tcp_bhash;
int __tcp_bhash_size;
int __tcp_ehash_size;
} tcp_hashinfo;
#define TCPINFO_ADDR 0x8048a000 /* tcp_hashinfo */
int main()
{
int fd = open(/dev/kmem, O_RDONLY) ;
if (pread(fd, tcp_hashinfo, sizeof(tcp_hashinfo), TCPINFO_ADDR) == -1) {
lseek(fd, TCPINFO_ADDR, 0) ;
if (read(fd, tcp_hashinfo, sizeof(tcp_hashinfo)) == -1) {
perror(Can not read /dev/kmem ?) ;
return 1 ;
}
}
printf(ehash=%p esize=%d bhash=%p bsize=%d\n,
tcp_hashinfo.__tcp_ehash,
tcp_hashinfo.__tcp_ehash_size,
tcp_hashinfo.__tcp_bhash,
tcp_hashinfo.__tcp_bhash_size) ;
return 0 ;
}
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/