How do you register a region of user space memory in a kernel module?

charlesw

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.

Prabhakar Lad

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Memory layout and kernel space - user space

How do I directly access reserved memory with a kernel module?

Memory-Debuging: How to get locked pages information in user space/kernel space in linux

How do you register a new user in flutter and firebase?

How can I Execute/Call a user-space defined function from Linux kernel space module?

Large shared memory between Kernel space and user space

Where is the memory of direct buffer allocated by netty, kernel space or user space?

How to make communication between user space program and Linux kernel module in order to print a message sent from user program to the kernel

How to communicate with a Linux kernel module from user space without littering /dev with new nodes?

mapping a memory region from kernel

How do you import a user module in D3?

How to mmap a Linux kernel buffer to user space?

How to allow access to memory in a kernel module?

Kernel space memory layout

What is the best way to communicate a kernel module with a user space program?

Can kernel module take initiative to send message to user space with netlink?

map a buffer from Kernel to User space allocated by another module

Linux kernel module communicate with user space through UNIX socket

How to access(if possible) kernel space from user space?

How to correctly extract a string from a user space pointer in kernel space?

How do you register a new user (with attributes) in Hyperledger Fabric Client (HFC)?

Memory usage of a kernel module

Kernel module memory access

How do you register private DICOM tags?

How do you write a parameterized delay register?

How to access Physical memory from user space?

Do page fault, page replacement, and paging happen to the kernel or just to processes, and to the kernel space or the user space?

How do I Register Autofac Module with Configuration

How to access PCI memory from Linux kernel space by memory mapping (Kernel 3.14)