Partial teardown of a MAP_SHARED overlay detaches the surviving pages from the file

Đang mở
#472 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
c, macos
Lĩnh vực
backend, operating-systems

Hướng nghiên cứu

Start with the failing cases in tests/test-msync.c and trace how partial munmap, MAP_FIXED hole reuse, and mremap update backing IPAs and HVF segments. The report says the fix also affects fork and guest address mapping. Done means the surviving shared pages retain file contents and two way coherence while a replacement anonymous page stays private; all four listed cases should pass.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug

Problem

On Apple Silicon the host page is 16 KiB and the guest page is 4 KiB, so one host file overlay covers four guest pages. Removing only part of that host page (munmap of one guest page, mremap shrink, or moving part of a source range) tears down the whole overlay and restores slab backing under it. The guest pages that are still mapped keep valid PTEs but now read slab memory: they lose the file contents, a host pwrite is no longer visible through them, and their stores no longer reach the file.

Reproduction

char name[] = "/dev/shm/partial-XXXXXX";
int fd = mkstemp(name);
unlink(name);
ftruncate(fd, 16384);
for (int i = 0; i < 4; i++) {
    unsigned char c = 0x31 + i;
    pwrite(fd, &c, 1, i * 4096);
}
unsigned char *p = mmap(NULL, 16384, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
munmap(p, 4096);
/* Linux: p[4096], p[8192], p[12288] read 0x32 0x33 0x34 */

Expected, as on Linux: the removed page faults, the remaining pages read 0x32, 0x33 and 0x34, a pwrite at offset 8192 is visible at p[8192], and a store to p[12288] lands in the file.

Actual on elfuse: the remaining pages read 0x00, and neither direction of coherence holds. The file itself is not modified. mremap shrinking a shared mapping, or moving only part of one, shows the same result.

MAP_FIXED into the hole

A second case remains even if the removal paths keep the overlay alive. After the munmap above, map a different backing into the hole:

unsigned char *q = mmap(p, 4096, PROT_READ | PROT_WRITE,
                        MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
q[0] = 'A';

The anonymous page must not write into the file, and its three neighbors must stay file-backed. One 16 KiB host range cannot carry both backings at once, so keeping the overlay corrupts the file and dropping it detaches the neighbors. Fixing this needs the surviving guest pages moved onto a separate host-aligned backing, which touches how guest addresses map to backing IPAs, HVF segments, fork and mremap.

Environment

  • macOS 27.0.1 (26A434), SDK 27.0, Apple M5
  • elfuse main at e9fdbbb
  • Partial munmap, hole reuse, partial mremap and mremap shrink cases in tests/test-msync.c: all four fail on main

Follow-up to the discussion in #391.

Ngôn ngữ chính
C
Star
287
Fork
33
Merge trung bình
2 ngày 17 giờ
Pull request đã merge (30 ngày)
18

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của sysprog21/elfuse

Tất cả issue của sysprog21/elfuse

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.