Linux mmap'ed access with memset() gives an alignment issue on the newer Linux kernels


I have a memory area that is marked reserved in the Linux kernel, and I use that area as a shared buffer. I have registered that region in drivers/char/mem.c file and I do mmap'ed to the user.

On 5.4 kernel, I do a GNU C memset() to that region and all works fine. if I upgrade  to 5.10 or 5.15 there is a bus error when accessing byte 3  (byte 0, 1, 2 OK) memset() with count 3 fails. If I avoid to write  to areas ( ! i % 3)  then memset() works. Something has changed, same story with memcpy()

I try to figure out what may have changed in 5.15 kernel and the memset() fails.

Has anyone seen something similar before?

  • I have managed to find the cause of the problem - The latest kernels have shuffled the contents of the MAIR register. I had a hard coded page configuration using a wrong index in the MAIR register. It was pointing to other things rather NORMAL memory.