Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7644305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:39:18+00:00 2026-05-31T09:39:18+00:00

I have a setup with 2GB of memory and I would like to map

  • 0

I have a setup with 2GB of memory and I would like to map 1GB (or more) of physical memory into user space virtual address. It is in theory possible since with 32-bit setup, 3GB of virtual address is available to user land apps.

I updated the kernel command line with the following parameters: mem=1G memmap=1G$1G
to force the kernel to see 1GB of RAM and to reserve the last 1GB.

I have my custom driver that will handle the user space mmap() call and map the physical address 0x40000000 (1G) to user space address with the function remap_pfn_range().

But the function triggers a kernel BUG() in remap_pte_range(). The same call used to work with a 300MB remap instead of 1GB.

I usually used to call ioremap() in my driver to map physical address into kernel virtual address. In this case, I can’t because of 1G/3G virtual addresses split (1G for kernel, 3G for apps). So I was wondering if it is possible to map physical address into user space virtual address without mapping these physical address in the kernel?

This is a 32-bit x86 kernel, i.e. "i386" architecture.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:39:20+00:00Added an answer on May 31, 2026 at 9:39 am

    Why does your remap_pfn_range call trigger a kernel BUG()

    The call to the BUG_ON macro in remap_pfn_range as per here

    2277 BUG_ON(addr >= end);

    remap_pfn_range calls remap_pud_range which calls remap_pmd_range which calls remap_pte_range.

    Subsequent calls to BUG_ON or VM_BUG_ON from remap_pmd_range here

    2191 VM_BUG_ON(pmd_trans_huge(*pmd));

    and from remap_pte_range here

    2171 BUG_ON(!pte_none(*pte));

    BUG_ON macro is defined here

    as

    #define BUG_ON(condition) do { if (unlikely(condition)) BUG(); } while(0)

    where BUG macro is defined above it to print a message and panic.

    unlikely macro is defined here

    as # define unlikely(x) (__builtin_expect(!!(x), 0)).

    So when the target user address to start at addr is greater than or equal to end which is defined as end = addr + PAGE_ALIGN(size);, BUG_ON returns 1 and calls BUG.

    Or when pmd_trans_huge as defined here

    153 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
    154 static inline int pmd_trans_splitting(pmd_t pmd)
    155 {
    156         return pmd_val(pmd) & _PAGE_SPLITTING;
    157 }
    158 
    159 static inline int pmd_trans_huge(pmd_t pmd)
    160 {
    161         return pmd_val(pmd) & _PAGE_PSE;
    162 }
    163 
    164 static inline int has_transparent_hugepage(void)
    165 {
    166         return cpu_has_pse;
    167 }
    

    returns 0, this occurs when CONFIG_TRANSPARENT_HUGEPAGE isn’t configured in the kernel or if
    the pmd (Page Metadate) value or & _PAGE_PSE

    Or whenpte_none returns 1 if the corresponding entry does not exist and 0 if it exists.

    Therefore !pte_none returns 0 when the corresponding page table entry does not exist and 1 other wise as the condition passed into BUG_ON.

    If the page table entry already exists then the call to BUG macro occurs.

    What happens if you specify a lower a amount of memory than !GB that is greater than 300MB , say 500MB or 800MB ?

    So either your starting address is greater than your ending address, or you CONFIG_TRANSPARENT_HUGEPAGE isn’t configured in the kernel or you are referring to Page Metadata doesn’t exist or Page Table entries that already exist.

    Clarifying from the comments, your call to remap_pfn_range references Page Table Entry pointers or *ptethat are already pointing to a page table entry or pte.

    This means that set_pte_at(mm, addr, pte, pte_mkspecial(pfn_pte(pfn, prot))); would fail as the pte pointer already points to a page table entry and hence can’t be set to the pte that is pte_mkspecial(pfn_pte(pfn, prot)).

    Bypassing the 1G /3G virtual address split

    See the following article High Memory In The Linux Kernel

    See the following mailing list post, which discusses some additional information about HIGHMEM with a minimum of 1GB of RAM.

    Information on mapping kernel and non kernel virtual address space to user land

    One way to map kernel virtual addresses and non kernel (returned by vmalloc()) virtual addresses to userspace is using remap_pfn_range. See Linux Memory Mapping for additional information.

    Another way that replaced the usage of the nopage handler on older kernels is the vm_insert_page function

    Additional Resources include:

    • Kernel Space – User Space Interfaces
    • DeviceDriverMmap Linux Memory Management Wiki
    • The evolution of driver page remapping
    • Faulting out populate(), nopfn(), and nopage()
    • Understanding the Linux Virtual Memory Manager
    • Mmap for Linux Drivers
    • Linux Device Drivers 3rd Edition Chapter 15.1. Memory Management in Linux
    • Linux Device Drivers 3rd Edition Chapter 15.2. The mmap Device Operation
    • Linux Device Drivers 3rd Edition Chapter 15.4. Direct Memory Access
    • Linux Device Drivers 3rd Edition Chapter 9.4. Using I/O Memory
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have setup an anonymous cvs user to be able to check out my
I have setup my versioned API like this with only a small tweak for
I have setup a property and implement INotifyPropertyChanged like so... public event PropertyChangedEventHandler PropertyChanged;
I have setup a Symfony 2 Data Transformer that will allow the user to
I have setup svnserve and for now now I am testing a repository with
I have setup multiple SQL Service Broker Queues in a database but have not
I have setup coredata in my appDelegate, but it first loads the mainWindow.xib and
I have setup file of winform. but i want to change my icon how
I have setup a git repository in a linux server, and installed the latest
I have setup a network of brokers in activemq, how do i connect to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.