Commit 07f53dba authored by Kalesh Singh's avatar Kalesh Singh
Browse files

ANDROID: 16K: Fix SIGBUS semantics and document __filemap_fixup()



Currently is a file backed mapping extends past the end of the file,
the entire region after the first 4KiB boundary after the file's end
is replaced with an anonymous mapping in the 16KiB emulated page size
mode.

Illustrated below the offsets are in KiB.

Given the mapping below of 48KiB backed by a file of size 18KiB, the
faulting behaviour on a 4KiB page size system is as shown below:

                    Access OK (4KiB page paritially backed by file)
                                │
    ┌──────────────────────────┬┼─┬─────────────────────────────────────────┐
    │                          │▼ │                                         │
    │       File backed        │  │     SIGBUS (Invalid filemap_fault)      │
    │                          │  │                                         │
    └──────────────────────────┴──┴─────────────────────────────────────────┘

    └─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
    0     4     8     12   16    20    24    28    32    36    40    44    48

Currently, given the same mapping in a x86_64 emulated 16KiB page size
the behavior is as shown below:

                    Access OK (4KiB page paritially backed by file)
                                │
    ┌──────────────────────────┬┼─┬─────────────────────────────────────────┐
    │                          │▼ │                                         │
    │       File backed        │  │     Anon Mapping (Access OK)            │
    │                          │  │                                         │
    └──────────────────────────┴──┴─────────────────────────────────────────┘

    └─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
    0     4     8     12   16    20    24    28    32    36    40    44    48

This behavior isn't entirely inline with the 4KiB page size system since
it replaces the entire region after the end of the file with an
anonymous mapping and therefore allows access to the entire region.

Generate a SIGBUS if the fault is beyond the first 16KiB boundary
after the end of the file; instead of allowing access to the entire
region as before. IOW access is only permitted to the 16KiB emulated
page if it is partially backed by the file.

                    Access OK (4KiB page paritially backed by file)
                                │
    ┌──────────────────────────┬┼─┬─────────────────┬───────────────────────┐
    │                          │▼ │   Access OK     │      SIGBUS           │
    │       File backed        │  │  (Anon Mapping) │(Invalid filemap fault)│
    │                          │  │                 │                       │
    └──────────────────────────┴──┴─────────────────┴───────────────────────┘

    └─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┴─────┘
    0     4     8     12   16    20    24    28    32    36    40    44    48

Bug: 366098040
Test: atest vts_ltp_test_x86_64
Change-Id: Idf8fb352cb587978b361c9fa1f03242de4ec782c
Signed-off-by: default avatarKalesh Singh <kaleshsingh@google.com>
parent 111f59ee
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment