0

I am working on a Linux module to interface with a third-party device. When this device is ready to give my module information, it writes directly to the RAM memory address 0x900000.

When I check /proc/iomem, I get:

00000000-3fffffff: System Ram
   00008000-00700fff: Kernel code
   00742000-007a27b3: Kernel datat

From, my understanding, this means that it is writing to an address that is floating out in the middle of user-space.

I know that this is not an optimal situation and it would be better to be able to use memory-mapped addresses/registers, but I don’t have the option of changing the way it works right now.

How do I have my kernel module safely claim the user space memory space from 0x900000 to 0x901000?

I tried mmap and ioremap but those are really for memory-mapped registers, not accessing memory that already ‘exists’ in userspace. I believe that I can read/write from the address by just using the pointer, but that doesn’t prevent corruption if that region is allocated to another process.

charlesw
  • 572
  • 6
  • 25
  • 1
    *"it writes directly to the RAM memory address 0x900000"* -- Unless your system has an IOMMU, this address is very likely to be a physical memory address, rather than a virtual address as you presume. Your failure to distinguish between different types of *"addresses"* is going to cause you a lot of confusion. – sawdust Mar 07 '18 at 02:26
  • 1
    Possible duplicate of [get the physical address of a buffer under Linux](https://stackoverflow.com/questions/17075005/get-the-physical-address-of-a-buffer-under-linux) – sawdust Mar 07 '18 at 02:45

1 Answers1

1

You can tell the kernel to restrict the address for kernel space by setting the mem parameter in the bootargs :

mem=1M@0x900000 --> instructs to use 1M starting from 0x900000

you can have multiple mem in boot args example: mem=1M@0x900000 mem=1M@0xA00000

Following command should tell you the memory region allocated to the kernel:

cat /proc/iomem | grep System
Prabhakar Lad
  • 1,248
  • 1
  • 8
  • 12