Re: [Bug 221820] New: sparc64 mmap() returns EINVAL for non-MAP_FIXED hint within VA_EXCLUDE_START...END

Andrew Morton <[email protected]>
Newsgroups org.kvack.linux-mm,org.kernel.vger.sparclinux
Message-ID <[email protected]>
(switched to email.  Please respond via emailed reply-to-all, not via the
bugzilla web interface).


On Sat, 01 Aug 2026 09:41:47 +0000 [email protected] wrote:

> https://bugzilla.kernel.org/show_bug.cgi?id=221820
> 
>             Bug ID: 221820
>            Summary: sparc64 mmap() returns EINVAL for non-MAP_FIXED hint
>                     within VA_EXCLUDE_START...END
>            Product: Memory Management
>            Version: 2.5
>           Hardware: Sparc64
>                 OS: Linux
>             Status: NEW
>           Severity: normal
>           Priority: P3
>          Component: Other
>           Assignee: [email protected]
>           Reporter: [email protected]
>         Regression: No
> 
> Repro:
> 
>     alexrp@niagara:~$ uname -a
>     Linux niagara 7.1.3.1-sparc64-smp #1 SMP Debian 7.1.3-1+sunvdc (2026-07-12)
> sparc64 GNU/Linux
>     alexrp@niagara:~$ cat bug.c
>     #include <errno.h>
>     #include <stdio.h>
>     #include <string.h>
>     #include <sys/mman.h>
>     #include <unistd.h>
>     int main() {
>         long pgsz = sysconf(_SC_PAGE_SIZE);
>         void *addr = mmap((void *)0xfff80000fffc6000, pgsz, PROT_READ |
> PROT_WRITE, \
>           MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
>         printf("%p (%s)\n", addr, strerror(errno));
>     }
>     alexrp@niagara:~$ cc bug.c
>     alexrp@niagara:~$ ./a.out
>     0xffffffffffffffff (Invalid argument)
> 
> I find this fairly surprising. I could understand if I had specified MAP_FIXED
> because in that case the kernel is unable to satisfy the requirements I've
> specified. But without MAP_FIXED, 0xfff80000fffc6000 is merely a hint and
> should be ignored if it falls within a VA range that the kernel considers
> off-limits.

Thanks.

That does seem wrong.  It works for me on x86_64 so yes, it does appear
to be a sparc thing.

The test code does have a few glitches which I don't think matter here, but below
is chatgpt's fixed-up version.  Could someone in sparcland please take a quick
look?

#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>

int main(void)
{
    long pgsz = sysconf(_SC_PAGE_SIZE);

    void *addr = mmap((void *)0xfff80000fffc6000,
                      pgsz,
                      PROT_READ | PROT_WRITE,
                      MAP_PRIVATE | MAP_ANONYMOUS,
                      -1,
                      0);

    if (addr == MAP_FAILED) {
        fprintf(stderr, "mmap failed: %s\n", strerror(errno));
        return 1;
    }

    printf("mapped at %p\n", addr);

    munmap(addr, pgsz);
    return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.