-
Notifications
You must be signed in to change notification settings - Fork 126
fix(starry): snapshot thread context in file syscalls #885
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
test-suit/starryos/normal/qemu-smp4/test-openat-umask-smp/c/CMakeLists.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| cmake_minimum_required(VERSION 3.20) | ||
| project(test-openat-umask-smp C) | ||
| set(CMAKE_C_STANDARD 11) | ||
| set(CMAKE_C_STANDARD_REQUIRED ON) | ||
| set(CMAKE_C_EXTENSIONS OFF) | ||
| add_executable(test-openat-umask-smp src/main.c) | ||
| target_compile_options(test-openat-umask-smp PRIVATE -Wall -Wextra -Werror) | ||
| install(TARGETS test-openat-umask-smp RUNTIME DESTINATION usr/bin) |
128 changes: 128 additions & 0 deletions
128
test-suit/starryos/normal/qemu-smp4/test-openat-umask-smp/c/src/main.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| #define _GNU_SOURCE | ||
| #include <errno.h> | ||
| #include <fcntl.h> | ||
| #include <sched.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
| #include <sys/mman.h> | ||
| #include <sys/stat.h> | ||
| #include <sys/wait.h> | ||
| #include <unistd.h> | ||
|
|
||
| #define WORKERS 8 | ||
| #define ITERS 300 | ||
| #define STACK_SIZE (64 * 1024) | ||
|
|
||
| static volatile int g_started; | ||
| static volatile int g_done; | ||
| static volatile int g_failed; | ||
| static volatile int g_progress; | ||
|
|
||
| static int worker(void *arg) | ||
| { | ||
| int id = (int)(long)arg; | ||
| char path[128]; | ||
|
|
||
| __sync_fetch_and_add(&g_started, 1); | ||
|
|
||
| for (int i = 0; i < ITERS && !g_failed; i++) { | ||
| mode_t old = umask((mode_t)((id + i) & 077)); | ||
|
|
||
| snprintf(path, sizeof(path), "/tmp/openat-umask-smp-%d-%d.tmp", id, i); | ||
| int fd = openat(AT_FDCWD, path, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC, 0666); | ||
| (void)umask(old); | ||
| if (fd < 0) { | ||
| printf("FAIL: worker %d openat iter %d errno=%d (%s)\n", id, i, | ||
| errno, strerror(errno)); | ||
| g_failed = 1; | ||
| return 1; | ||
| } | ||
|
|
||
| if (write(fd, "x", 1) != 1) { | ||
| printf("FAIL: worker %d write iter %d errno=%d (%s)\n", id, i, errno, | ||
| strerror(errno)); | ||
| g_failed = 1; | ||
| } | ||
| close(fd); | ||
| unlink(path); | ||
|
|
||
| __sync_fetch_and_add(&g_progress, 1); | ||
| if ((i & 15) == 0) { | ||
| sched_yield(); | ||
| } | ||
| } | ||
|
|
||
| __sync_fetch_and_add(&g_done, 1); | ||
| return g_failed ? 1 : 0; | ||
| } | ||
|
|
||
| int main(void) | ||
| { | ||
| setvbuf(stdout, NULL, _IONBF, 0); | ||
|
|
||
| void *stacks[WORKERS]; | ||
| int tids[WORKERS]; | ||
| memset(stacks, 0, sizeof(stacks)); | ||
| memset(tids, -1, sizeof(tids)); | ||
|
|
||
| int flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND; | ||
| for (int i = 0; i < WORKERS; i++) { | ||
| stacks[i] = mmap(NULL, STACK_SIZE, PROT_READ | PROT_WRITE, | ||
| MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | ||
| if (stacks[i] == MAP_FAILED) { | ||
| printf("FAIL: mmap stack %d errno=%d (%s)\n", i, errno, | ||
| strerror(errno)); | ||
| return 1; | ||
| } | ||
|
|
||
| int tid = clone(worker, (char *)stacks[i] + STACK_SIZE, flags, | ||
| (void *)(long)i); | ||
| if (tid < 0) { | ||
| printf("FAIL: clone worker %d errno=%d (%s)\n", i, errno, | ||
| strerror(errno)); | ||
| return 1; | ||
| } | ||
| tids[i] = tid; | ||
| } | ||
|
|
||
| int last = -1; | ||
| int stalls = 0; | ||
| for (int tick = 0; tick < 600 && g_done < WORKERS && !g_failed; tick++) { | ||
| usleep(100000); | ||
| int progress = __atomic_load_n(&g_progress, __ATOMIC_RELAXED); | ||
| if (progress == last) { | ||
| if (++stalls > 100) { | ||
| printf("FAIL: stalled started=%d done=%d progress=%d\n", g_started, | ||
| g_done, progress); | ||
| g_failed = 1; | ||
| break; | ||
| } | ||
| } else { | ||
| stalls = 0; | ||
| last = progress; | ||
| } | ||
| } | ||
|
|
||
| for (int i = 0; i < WORKERS; i++) { | ||
| if (tids[i] >= 0) { | ||
| int status = 0; | ||
| if (waitpid(tids[i], &status, __WALL) < 0) { | ||
| printf("FAIL: wait worker %d errno=%d (%s)\n", i, errno, | ||
| strerror(errno)); | ||
| g_failed = 1; | ||
| } else if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { | ||
| printf("FAIL: worker %d exit status=0x%x\n", i, status); | ||
| g_failed = 1; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (g_failed || g_done != WORKERS || g_progress != WORKERS * ITERS) { | ||
| printf("FAIL: started=%d done=%d progress=%d expected=%d\n", g_started, | ||
| g_done, g_progress, WORKERS * ITERS); | ||
| return 1; | ||
| } | ||
|
|
||
| printf("PASS: openat_umask_smp workers=%d iterations=%d\n", WORKERS, ITERS); | ||
| return 0; | ||
| } |
17 changes: 17 additions & 0 deletions
17
test-suit/starryos/normal/qemu-smp4/test-openat-umask-smp/qemu-riscv64.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| args = [ | ||
| "-nographic", "-cpu", "rv64", | ||
| "-m", "512M", | ||
| "-smp", "4", | ||
| "-accel", "tcg,thread=single", | ||
| "-device", "virtio-blk-pci,drive=disk0", | ||
| "-drive", "id=disk0,if=none,format=raw,file=${workspace}/tmp/axbuild/rootfs/rootfs-riscv64-alpine.img", | ||
| "-device", "virtio-net-pci,netdev=net0", | ||
| "-netdev", "user,id=net0", | ||
| ] | ||
| uefi = false | ||
| to_bin = true | ||
| shell_prefix = "root@starry:" | ||
| shell_init_cmd = "/usr/bin/test-openat-umask-smp" | ||
| success_regex = ['(?m)^PASS: openat_umask_smp workers=\d+ iterations=\d+\s*$'] | ||
| fail_regex = ['(?i)\bpanic(?:ked)?\b', '(?m)^FAIL:'] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| timeout = 180 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议后续 PR 同步处理
sys_fchownat(ctl.rs:460let cred = current().as_thread().cred())和sys_fchmodat等同类位点——它们也在vm_load_string()/resolve_at()之后二次读取current()。当前 PR 聚焦已观测 crash 路径是合理的。