public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Terry Barnaby <terry@beam.demon.co.uk>
To: linux-kernel@vger.kernel.org
Subject: Question on mmap(2) with kernel alocated memory
Date: Fri, 04 May 2001 13:57:22 +0100	[thread overview]
Message-ID: <3AF2A732.5D4BF81F@beam.demon.co.uk> (raw)

I am trying to mmap() into user space a kernel buffer  and am having
problems.
I have a simple test example, can someone please tell me what I have got
wrong ?

In a driver I do:
    uint*    kva;

    kva = (uint*)kmalloc(4096, GFP_KERNEL);
    *kva = 0x11223344;
    printk("Address: %p %lx %x\n", kva, virt_to_phys(kva), *kva);

Now in some simple user program I do:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <fcntl.h>

int main(int argc, char** argv){
 int fm;
 char* p;
 uint* pi;
 uint v;
 uint add = 0x74b000;

 if((fm = open("/dev/mem", O_RDWR)) < 0)
  return 1;

 p = mmap(0, 128 * 1024 * 1024, PROT_READ|PROT_WRITE, MAP_SHARED, fm,
0);
 printf("Mapped: %p\n", p);

 lseek(fm, add, SEEK_SET);
 read(fm, &v, sizeof(v));
 printf("V: %x\n", v);

 pi = (uint*)(p + add);
 printf("Vmmap: %p %x\n", pi, *pi);

 close(fm);
 return 0;
}

The value of add is hardcoded to the value printed for the physical
address in the drivers prink routine.
The lseek/read from the /dev/mem device yields the value 0x11223344.
However the mmap method also on /dev/mem yields the value 0.

Whats wrong with my mmap() or kalloc() ?

Terry

--
  Dr Terry Barnaby                     BEAM Ltd
  Phone: +44 1454 324512               Northavon Business Center, Dean Rd
  Fax:   +44 1454 313172               Yate, Bristol, BS37 5NH, UK
  Email: terry@beam.demon.co.uk        Web: www.beam.demon.co.uk
  BEAM for: Visually Impaired X-Terminals, Parallel Processing, Software Dev
                         "Tandems are twice the fun !"




             reply	other threads:[~2001-05-04 12:57 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-04 12:57 Terry Barnaby [this message]
2001-05-05 20:18 ` Question on mmap(2) with kernel alocated memory Pete Wyckoff

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=3AF2A732.5D4BF81F@beam.demon.co.uk \
    --to=terry@beam.demon.co.uk \
    --cc=linux-kernel@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox