Page MenuHomeFreeBSD

amd64/arm64: Eliminate unnecessary demotions in pmap_protect()
ClosedPublic

Authored by alc on Jul 5 2024, 6:55 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Nov 11, 11:27 AM
Unknown Object (File)
Oct 5 2024, 11:02 AM
Unknown Object (File)
Oct 2 2024, 8:14 PM
Unknown Object (File)
Sep 29 2024, 9:17 AM
Unknown Object (File)
Sep 21 2024, 11:15 PM
Unknown Object (File)
Sep 21 2024, 7:00 PM
Unknown Object (File)
Sep 20 2024, 1:33 PM
Unknown Object (File)
Sep 19 2024, 4:08 AM

Details

Summary

In pmap_protect(), when the mapping isn't changing, we don't need to perform a superpage demotion, even though the requested change doesn't cover the entire superpage.

Test Plan

Consider the first of @andrew 's recent test programs:

// panic: pmap_demote_l3c: missing ATTR_CONTIGUOUS

#include <sys/mman.h>

#include <assert.h>
#include <stddef.h>

int
main(int argc, char *argv[])
{
        char *addr;

        addr = mmap(NULL, 0x1000000, PROT_READ | PROT_WRITE,
            MAP_ANON | MAP_PRIVATE, -1, 0);
        assert(addr != MAP_FAILED);

        mlock(addr, 0x800000);
        mprotect(addr, 0x400000, PROT_READ | PROT_WRITE);
        mprotect(addr, 0x2000, PROT_WRITE);
        mprotect(addr, 0x400000, PROT_READ | PROT_WRITE);
        return (0);
}

At first, I was surprised that this program was performing a demotion before crashing on arm64, because vm_map_protect() tries to avoid pointless calls to pmap_protect(). However, the absence of PROT_READ from the second mprotect() is seen by vm_map_protect() as removing read access at the machine-independent level, and so it calls pmap_protect().

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable