Description
Hi,
Thanks a lot for the codes that you are sharing. It is helping me to understand Linux better. 🐧
(All these experiments are on Ubuntu VM)
I have used linux-kernel-module-cheat/userland/virt_to_phys_user.c to print a physical address of a variable like this
int var = 42;
pid = getpid();//strtoull(argv[1], NULL, 0);
vaddr = (uintptr_t)&var;//strtoull(argv[2], NULL, 0);
and I get some reasonable values for virtual address, page frame number and physical address as
virtual address , Page frame no, physical address
0x55e451c272a0, 0x3d4a27, 0x3d4a272a0
But when I use it for a mmap I am getting 0 as physical address.
(for this I have compiled the kernel 5.9 with enabling CMA and making CONFIG_STRICT_DEVMEM=n
dmesg | cma
[ 0.068544] cma: Reserved 64 MiB at 0x000000021bc00000
)
fd = open("/dev/mem", O_RDWR | O_SYNC);
vaddr = mmap(0, 64*1024*1024, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0x000000021bc00000);
virtual address , Page frame no, physical address
0x7fd5fffb3000, 0x0, 0x0
Does this program needs some modification for mmap's physical address ? or is there something I am missing ?