Maximum/Minimum physical address - Linux kernel

Maximum/Minimum physical address - Linux kernel

By : Xee Shan
Date : November 20 2020, 01:01 AM
it should still fix some issue PCs have some address spaces which are not related to real RAM. A few days ago, I installed graphics card with 4GB of RAM. But there are other devices in the PC with their own memory which the CPU can still access: RAID controllers, network cards, I/O cards which support DMA.
In pre-64bit times, those memory areas had to be mapped somewhere in the physical address space of the RAM. Which meant you could install more than 3.5GB RAM in your PC but you couldn't use it.
code :

Share : facebook icon twitter icon
How to get the physical address from the logical one in a Linux kernel module?

How to get the physical address from the logical one in a Linux kernel module?

By : Winterskp
Date : March 29 2020, 07:55 AM
hope this fix your issue Well, it might looks as something like that (follow PTE from an virtual address):
code :
void follow_pte(struct mm_struct * mm, unsigned long address, pte_t * entry)
    pgd_t * pgd = pgd_offset(mm, address);

    printk("follow_pte() for %lx\n", address);

    entry->pte = 0;
    if (!pgd_none(*pgd) && !pgd_bad(*pgd)) {
        pud_t * pud = pud_offset(pgd, address);
        struct vm_area_struct * vma = find_vma(mm, address);

        printk(" pgd = %lx\n", pgd_val(*pgd));

        if (pud_none(*pud)) {
            printk("  pud = empty\n");
        if (pud_huge(*pud) && vma->vm_flags & VM_HUGETLB) {
            entry->pte = pud_val(*pud);
            printk("  pud = huge\n");

        if (!pud_bad(*pud)) {
            pmd_t * pmd = pmd_offset(pud, address);

            printk("  pud = %lx\n", pud_val(*pud));

            if (pmd_none(*pmd)) {
                printk("   pmd = empty\n");
            if (pmd_huge(*pmd) && vma->vm_flags & VM_HUGETLB) {
                entry->pte = pmd_val(*pmd);
                printk("   pmd = huge\n");
            if (pmd_trans_huge(*pmd)) {
                entry->pte = pmd_val(*pmd);
                printk("   pmd = trans_huge\n");
            if (!pmd_bad(*pmd)) {
                pte_t * pte = pte_offset_map(pmd, address);

                printk("   pmd = %lx\n", pmd_val(*pmd));

                if (!pte_none(*pte)) {
                    entry->pte = pte_val(*pte);
                    printk("    pte = %lx\n", pte_val(*pte));
                } else {
                    printk("    pte = empty\n");
linux kernel - how to get physical address (memory management)?

linux kernel - how to get physical address (memory management)?

By : keero Quinobi
Date : March 29 2020, 07:55 AM
like below fixes the issue The Linux kernel uses a generic four-page paging model, which is not only suitable for 32-bit systems but also for 64-bit systems. The paging unit is part of the MMU (Memory Management Unit), which converts a linear address into a physical address.
I wrote a kernel module for you to simulate the process of virtual address conversion to physical address. I am assuming you know the principal of paging system.
code :
    static void get_pgtable_macro(void)
        printk("PAGE_OFFSET = 0x%lx\n", PAGE_OFFSET);
        printk("PGDIR_SHIFT = %d\n", PGDIR_SHIFT);
        printk("PUD_SHIFT = %d\n", PUD_SHIFT);
        printk("PMD_SHIFT = %d\n", PMD_SHIFT);
        printk("PAGE_SHIFT = %d\n", PAGE_SHIFT);

        printk("PTRS_PER_PGD = %d\n", PTRS_PER_PGD);
        printk("PTRS_PER_PUD = %d\n", PTRS_PER_PUD);
        printk("PTRS_PER_PMD = %d\n", PTRS_PER_PMD);
        printk("PTRS_PER_PTE = %d\n", PTRS_PER_PTE);

        printk("PAGE_MASK = 0x%lx\n", PAGE_MASK);

    static unsigned long vaddr2paddr(unsigned long vaddr)
        pgd_t *pgd;
        pud_t *pud;
        pmd_t *pmd;
        pte_t *pte;
        unsigned long paddr = 0;
            unsigned long page_addr = 0;
        unsigned long page_offset = 0;

        pgd = pgd_offset(current->mm, vaddr);
        printk("pgd_val = 0x%lx\n", pgd_val(*pgd));
        printk("pgd_index = %lu\n", pgd_index(vaddr));
        if (pgd_none(*pgd)) {
            printk("not mapped in pgd\n");
            return -1;

        pud = pud_offset(pgd, vaddr);
        printk("pud_val = 0x%lx\n", pud_val(*pud));
        if (pud_none(*pud)) {
            printk("not mapped in pud\n");
            return -1;

        pmd = pmd_offset(pud, vaddr);
        printk("pmd_val = 0x%lx\n", pmd_val(*pmd));
        printk("pmd_index = %lu\n", pmd_index(vaddr));
        if (pmd_none(*pmd)) {
            printk("not mapped in pmd\n");
            return -1;

        pte = pte_offset_kernel(pmd, vaddr);
        printk("pte_val = 0x%lx\n", pte_val(*pte));
        printk("pte_index = %lu\n", pte_index(vaddr));
        if (pte_none(*pte)) {
            printk("not mapped in pte\n");
            return -1;

        /* Page frame physical address mechanism | offset */
        page_addr = pte_val(*pte) & PAGE_MASK;
        page_offset = vaddr & ~PAGE_MASK;
        paddr = page_addr | page_offset;
        printk("page_addr = %lx, page_offset = %lx\n", page_addr, page_offset);
            printk("vaddr = %lx, paddr = %lx\n", vaddr, paddr);

        return paddr;

    static int __init v2p_init(void)
        unsigned long vaddr = 0;

        printk("vaddr to paddr module is running..\n");

        vaddr = (unsigned long)vmalloc(1000 * sizeof(char));
        if (vaddr == 0) {
            printk("vmalloc failed..\n");
            return 0;
        printk("vmalloc_vaddr=0x%lx\n", vaddr);

        vaddr = __get_free_page(GFP_KERNEL);
        if (vaddr == 0) {
            printk("__get_free_page failed..\n");
            return 0;
        printk("get_page_vaddr=0x%lx\n", vaddr);

        return 0;

    static void __exit v2p_exit(void)
        printk("vaddr to paddr module is leaving..\n");
            vfree((void *)vaddr);
Virtual address to physical address and reverse in android linux kernel

Virtual address to physical address and reverse in android linux kernel

By : user3035800
Date : March 29 2020, 07:55 AM
should help you out I found fix. ioremap have a check logic for validation of address. This function is for reserved address but it tring to map address that's already mapped to a process. So, I modify the check logic in ioreamp and it works well.
How to acess the physical address from linux kernel space?

How to acess the physical address from linux kernel space?

By : Sergey Dyachenko
Date : March 29 2020, 07:55 AM
To fix this issue Yes.
Get a virtual address mapping setup to the registers in question using ioremap Use readl/writel to manipulate the physical memory.
In linux kernel what is difference between page address, virtual address and physical address

In linux kernel what is difference between page address, virtual address and physical address

By : Arkadij
Date : March 29 2020, 07:55 AM
With these it helps A physical address is the address in RAM. Once you reach the limit of physical memory available, the kernel has to allocate somewhere, and that place is the virtual address space. Virtual memory is mapped such that you have much more available than you have physical memory, and this is done by breaking virtual memory into chunks called pages.
Each virtual address is mapped to a location in physical memory, where there is a 1 to many relationship between physical to virtual addresses i.e., there are many virtual addresses that map to the same physical location. This mapping is done by address translation in the page table.
Related Posts Related Posts :
  • syslog Log/ Event generator linux
  • Ping timeout issues
  • How make /var/www contents editable by IDE
  • Why ordinary user cannot use chgrp/chown
  • Execute a script on startup of SUSE reboot
  • Extracting debugging information from core files
  • linux command to connect to another server using hostname and port number
  • GLib.Settings.changed event not firing
  • What does it mean by code holding semaphore can be preempted
  • Does LD_LIBRARY_PATH really cause inconsistencies?
  • "lsof" shows a file as (deleted) but I can still see it in file system
  • Linux file deleted recovery
  • Exchange columns in bash
  • How to set max file size in Linux CeNTOS to server.log
  • Regular expressions: Search a word and append a new word at the end of the line
  • Compress a set of log files in a folder depending on number of files
  • unexpected behavior of linux malloc
  • relation between init and bash terminal process
  • Matlab VideoReader codec error?
  • How to catch the L3-cache hits and misses by perf tool in Linux
  • Executable Deleting Itself on linux
  • How to change the apache httpd port for serving files
  • Installing Patches in linux
  • Comparative analysis between libkvm on linux and NetBSD
  • How to join multiple txt files into based on column?
  • setting LINK variable in Makefile generated by qmake (5.0)
  • Automake - difficulty with installing version 'automake-1.14.1'
  • How to use Linux Network Namespaces for per processes routing?
  • How can I write a Gruntfile with different shell command behaviour for OS X vs. Linux?
  • Using at command in shell script for scheduling a command
  • Is there a method to figure out the audio channel layout in Linux?
  • Setting environment varilable for daemon / root process
  • string replacement in shell script
  • Add specific column to the end of a CSV file
  • Are there programmable automount/autofs hooks in linux/systemd?
  • Renaming files like 20141207_190822.jpg to "2014-12-07 19.08.22.jpg" in linux or MacOS X
  • undocumented kernel boot parameter?
  • using wget to mirror a website with path and subfolder that have the same name
  • Using awk to find data matching date range in text file
  • Installing xorg-x11-devel package in SLES 11 SP2
  • Setting result of find to variable, which has variables within it
  • Freepbx custom context outbound route
  • memcpy implementation in linux kernel
  • How to reverse a list of words in a shell string?
  • Concatenate and pass as parameter in bash
  • Add user to Docker container
  • How to add a content in a file in linux without opening the file using vi or cat command
  • Which SVN subversion can I use on linux, Mac, Windows?
  • Work with ZIP archive at Bash
  • bash script not running as expected from cron vs. shell.
  • Compare one field, Remove duplicate if value of another field is greater
  • sudoers NOPASSWD: sudo: no tty present and no askpass program specified
  • How do I use pipes and variable substitution in a shell script (for toggling haproxy active server)?
  • Linux/Unix Find Command
  • Not able to copy data in hdfs with hdfs dfs commands
  • Linux : Remove/Delete .txt files ending with exactly five digits
  • ARM assembly "retne" instruction
  • Migrate from LXC to LXD
  • sbt on linux not accepting -jvm-debug 5005
  • Supervisord events only sent to one eventlistener in pool
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org