Skip to content

Conversation

@fslongjin
Copy link
Member

@fslongjin fslongjin commented Oct 8, 2025

commit bed3298ce95f7fed9e67d4ec1ab3b159525fcbed
Author: longjin <longjin@DragonOS.org>
Date:   Wed Oct 8 22:38:20 2025 +0800

    fix(process): 修复futex和进程ID管理相关问题
    
    - 修正FLAGS_MATCH_NONE常量值为0x00
    - 确保非组长线程的TGID与组长一致
    - 调整clear_child_tid操作顺序以符合Linux语义
    - 优化pid_nr_ns方法实现避免潜在panic
    - 添加futex测试的blocklist和白名单配置
    
    Signed-off-by: longjin <longjin@DragonOS.org>

commit 334685d58deb665dea7dc64731c4bdf3a516fc53
Author: longjin <longjin@DragonOS.org>
Date:   Wed Oct 8 17:42:44 2025 +0800

    fix(futex): 修复futex等待和唤醒机制
    
    - 修正bitset匹配逻辑,使用位与操作而非不等比较
    - 移除wake_up函数的inline(always)属性
    - 实现FUTEX_WAIT_BITSET的绝对超时处理
    - 添加时间合法性检查和时钟选择逻辑
    
    Signed-off-by: longjin <longjin@DragonOS.org>

commit 43b3196d8e911e692284d5328e74a09c96c3fafa
Author: longjin <longjin@DragonOS.org>
Date:   Wed Oct 8 17:23:58 2025 +0800

    feat(runner): 添加输出到控制台的选项
    
    - 添加Config结构体中的output_to_stdout字段
    - 根据配置决定测试输出方式(文件或控制台)
    - 添加--stdout命令行参数以启用控制台输出
    
    Signed-off-by: longjin <longjin@DragonOS.org>

commit 6b93dd93f507b0ad6f8d81eeb23de3fc9695dcaa
Author: longjin <longjin@DragonOS.org>
Date:   Wed Oct 8 16:54:01 2025 +0800

    fix(futex): 修复futex超时处理并增加调试日志
    
    - 修复零超时时间立即返回ETIMEDOUT的逻辑
    - 简化超时检查条件,移除错误的FLAGS_HAS_TIMEOUT检查
    
    Signed-off-by: longjin <longjin@DragonOS.org>


commit 79774c8aa40587354017dc153bf63a555ba58315
Author: longjin <longjin@DragonOS.org>
Date:   Wed Oct 8 15:51:57 2025 +0800

    feat(futex): 完善共享匿名映射的futex支持
    
    - 实现共享匿名映射的futex键生成机制
    - 添加跨进程共享匿名futex的测试用例
    - 修复私有futex键的构建问题
    
    Signed-off-by: longjin <longjin@DragonOS.org>

- 添加VFS层的统一vfs_truncate封装,包含文件类型和只读挂载检查
- 实现truncate系统调用处理,支持路径解析和符号链接跟随
- 修复FAT文件系统resize方法,确保页缓存和元数据同步更新
- 添加全面的用户空间测试用例,覆盖各种边界条件和错误情况
- 优化文件截断流程,统一通过VFS封装处理类型和只读检查

Signed-off-by: longjin <longjin@DragonOS.org>
Signed-off-by: longjin <longjin@DragonOS.org>
Signed-off-by: longjin <longjin@DragonOS.org>
- 实现共享匿名映射的futex键生成机制
- 添加跨进程共享匿名futex的测试用例
- 增加futex操作的调试日志输出
- 修复私有futex键的构建问题

Signed-off-by: longjin <longjin@DragonOS.org>
- 修复零超时时间立即返回ETIMEDOUT的逻辑
- 简化超时检查条件,移除错误的FLAGS_HAS_TIMEOUT检查

Signed-off-by: longjin <longjin@DragonOS.org>
- 添加Config结构体中的output_to_stdout字段
- 根据配置决定测试输出方式(文件或控制台)
- 添加--stdout命令行参数以启用控制台输出

Signed-off-by: longjin <longjin@DragonOS.org>
- 修正bitset匹配逻辑,使用位与操作而非不等比较
- 移除wake_up函数的inline(always)属性
- 实现FUTEX_WAIT_BITSET的绝对超时处理
- 添加时间合法性检查和时钟选择逻辑

Signed-off-by: longjin <longjin@DragonOS.org>
- 修正FLAGS_MATCH_NONE常量值为0x00
- 确保非组长线程的TGID与组长一致
- 调整clear_child_tid操作顺序以符合Linux语义
- 优化pid_nr_ns方法实现避免潜在panic
- 添加futex测试的blocklist和白名单配置

Signed-off-by: longjin <longjin@DragonOS.org>
Copilot AI review requested due to automatic review settings October 8, 2025 14:48
@github-actions github-actions bot added the Bug fix A bug is fixed in this pull request label Oct 8, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes various bugs in the futex implementation to improve cross-process synchronization functionality.

  • Fixed futex timeout handling for FUTEX_WAIT_BITSET to use absolute time semantics
  • Enhanced futex key generation to properly support shared anonymous mappings across processes
  • Corrected process lifecycle management including TID clearing order and thread group ID assignment

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
user/apps/tests/syscall/gvisor/whitelist.txt Enabled futex_test in the test suite
user/apps/tests/syscall/gvisor/runner/src/main.rs Added --stdout flag for direct console output
user/apps/tests/syscall/gvisor/runner/src/lib_sync.rs Implemented stdout output mode and refactored file handling
user/apps/tests/syscall/gvisor/blocklists/futex_test Added blocklist for problematic futex test cases
user/apps/c_unitest/test_cross_process_futex_shared_anon.c Added test for cross-process futex with shared anonymous memory
kernel/src/syscall/mod.rs Removed timeout flag check to allow timeouts for all futex operations
kernel/src/process/pid.rs Fixed potential panic in pid_nr_ns by adding bounds checking
kernel/src/process/mod.rs Fixed TID clearing order in process cleanup
kernel/src/process/fork.rs Added proper TGID assignment for thread group members
kernel/src/mm/ucontext.rs Added shared anonymous mapping identity for futex key generation
kernel/src/libs/futex/syscall.rs Implemented absolute timeout handling for FUTEX_WAIT_BITSET
kernel/src/libs/futex/futex.rs Enhanced futex key generation and added debug logging
kernel/src/libs/futex/constant.rs Fixed FLAGS_MATCH_NONE constant value

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 240 to 250
// Debug: 打印futex_wait信息
let current_pid = ProcessManager::current_pcb().raw_pid().data();
let is_shared = flags.contains(FutexFlag::FLAGS_SHARED);
warn!(
"[FUTEX_DEBUG] futex_wait: pid={}, uaddr=0x{:x}, val={}, is_shared={}, key={:?}",
current_pid,
uaddr.data(),
val,
is_shared,
key
);
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug logging statements using warn!() macro should be conditionally compiled or use a debug!() macro instead to avoid performance impact in production builds.

Copilot uses AI. Check for mistakes.
Comment on lines 285 to 305
log::warn!("[FUTEX_DEBUG] futex_wait: abs_time={:?}", abs_time);
if let Some(time) = abs_time {
let wakeup_helper = WakeUpHelper::new(pcb.clone());

let sec = time.tv_sec;
let nsec = time.tv_nsec;
let jiffies = next_n_us_timer_jiffies((nsec / 1000 + sec * 1_000_000) as u64);
let total_us = (nsec / 1000 + sec * 1_000_000) as u64;

warn!(
"[FUTEX_DEBUG] timeout: sec={}, nsec={}, total_us={}",
sec, nsec, total_us
);

// 如果超时时间为0,直接返回ETIMEDOUT
if total_us == 0 {
warn!("[FUTEX_DEBUG] zero timeout, returning ETIMEDOUT immediately");
return Err(SystemError::ETIMEDOUT);
}

let wakeup_helper = WakeUpHelper::new(pcb.clone());
let jiffies = next_n_us_timer_jiffies(total_us);

warn!("[FUTEX_DEBUG] creating timer with jiffies={}", jiffies);
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug logging statements using warn!() macro should be conditionally compiled or use a debug!() macro instead to avoid performance impact in production builds.

Copilot uses AI. Check for mistakes.
Comment on lines 285 to 305
log::warn!("[FUTEX_DEBUG] futex_wait: abs_time={:?}", abs_time);
if let Some(time) = abs_time {
let wakeup_helper = WakeUpHelper::new(pcb.clone());

let sec = time.tv_sec;
let nsec = time.tv_nsec;
let jiffies = next_n_us_timer_jiffies((nsec / 1000 + sec * 1_000_000) as u64);
let total_us = (nsec / 1000 + sec * 1_000_000) as u64;

warn!(
"[FUTEX_DEBUG] timeout: sec={}, nsec={}, total_us={}",
sec, nsec, total_us
);

// 如果超时时间为0,直接返回ETIMEDOUT
if total_us == 0 {
warn!("[FUTEX_DEBUG] zero timeout, returning ETIMEDOUT immediately");
return Err(SystemError::ETIMEDOUT);
}

let wakeup_helper = WakeUpHelper::new(pcb.clone());
let jiffies = next_n_us_timer_jiffies(total_us);

warn!("[FUTEX_DEBUG] creating timer with jiffies={}", jiffies);
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug logging statements using warn!() macro should be conditionally compiled or use a debug!() macro instead to avoid performance impact in production builds.

Copilot uses AI. Check for mistakes.
Comment on lines 291 to 305
warn!(
"[FUTEX_DEBUG] timeout: sec={}, nsec={}, total_us={}",
sec, nsec, total_us
);

// 如果超时时间为0,直接返回ETIMEDOUT
if total_us == 0 {
warn!("[FUTEX_DEBUG] zero timeout, returning ETIMEDOUT immediately");
return Err(SystemError::ETIMEDOUT);
}

let wakeup_helper = WakeUpHelper::new(pcb.clone());
let jiffies = next_n_us_timer_jiffies(total_us);

warn!("[FUTEX_DEBUG] creating timer with jiffies={}", jiffies);
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug logging statements using warn!() macro should be conditionally compiled or use a debug!() macro instead to avoid performance impact in production builds.

Suggested change
warn!(
"[FUTEX_DEBUG] timeout: sec={}, nsec={}, total_us={}",
sec, nsec, total_us
);
// 如果超时时间为0,直接返回ETIMEDOUT
if total_us == 0 {
warn!("[FUTEX_DEBUG] zero timeout, returning ETIMEDOUT immediately");
return Err(SystemError::ETIMEDOUT);
}
let wakeup_helper = WakeUpHelper::new(pcb.clone());
let jiffies = next_n_us_timer_jiffies(total_us);
warn!("[FUTEX_DEBUG] creating timer with jiffies={}", jiffies);
debug!(
"[FUTEX_DEBUG] timeout: sec={}, nsec={}, total_us={}",
sec, nsec, total_us
);
// 如果超时时间为0,直接返回ETIMEDOUT
if total_us == 0 {
debug!("[FUTEX_DEBUG] zero timeout, returning ETIMEDOUT immediately");
return Err(SystemError::ETIMEDOUT);
}
let wakeup_helper = WakeUpHelper::new(pcb.clone());
let jiffies = next_n_us_timer_jiffies(total_us);
debug!("[FUTEX_DEBUG] creating timer with jiffies={}", jiffies);

Copilot uses AI. Check for mistakes.
Comment on lines 291 to 305
warn!(
"[FUTEX_DEBUG] timeout: sec={}, nsec={}, total_us={}",
sec, nsec, total_us
);

// 如果超时时间为0,直接返回ETIMEDOUT
if total_us == 0 {
warn!("[FUTEX_DEBUG] zero timeout, returning ETIMEDOUT immediately");
return Err(SystemError::ETIMEDOUT);
}

let wakeup_helper = WakeUpHelper::new(pcb.clone());
let jiffies = next_n_us_timer_jiffies(total_us);

warn!("[FUTEX_DEBUG] creating timer with jiffies={}", jiffies);
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug logging statements using warn!() macro should be conditionally compiled or use a debug!() macro instead to avoid performance impact in production builds.

Suggested change
warn!(
"[FUTEX_DEBUG] timeout: sec={}, nsec={}, total_us={}",
sec, nsec, total_us
);
// 如果超时时间为0,直接返回ETIMEDOUT
if total_us == 0 {
warn!("[FUTEX_DEBUG] zero timeout, returning ETIMEDOUT immediately");
return Err(SystemError::ETIMEDOUT);
}
let wakeup_helper = WakeUpHelper::new(pcb.clone());
let jiffies = next_n_us_timer_jiffies(total_us);
warn!("[FUTEX_DEBUG] creating timer with jiffies={}", jiffies);
debug!(
"[FUTEX_DEBUG] timeout: sec={}, nsec={}, total_us={}",
sec, nsec, total_us
);
// 如果超时时间为0,直接返回ETIMEDOUT
if total_us == 0 {
debug!("[FUTEX_DEBUG] zero timeout, returning ETIMEDOUT immediately");
return Err(SystemError::ETIMEDOUT);
}
let wakeup_helper = WakeUpHelper::new(pcb.clone());
let jiffies = next_n_us_timer_jiffies(total_us);
debug!("[FUTEX_DEBUG] creating timer with jiffies={}", jiffies);

Copilot uses AI. Check for mistakes.
// 从队列中唤醒
let count = bucket_mut.wake_up(key.clone(), Some(bitset), nr_wake)?;

warn!("[FUTEX_DEBUG] futex_wake: woke up {} processes", count);
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug logging statements using warn!() macro should be conditionally compiled or use a debug!() macro instead to avoid performance impact in production builds.

Copilot uses AI. Check for mistakes.
}),
});
};
warn!("[FUTEX_DEBUG] get_futex_key: private futex, key={:?}", key);
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug logging statements using warn!() macro should be conditionally compiled or use a debug!() macro instead to avoid performance impact in production builds.

Suggested change
warn!("[FUTEX_DEBUG] get_futex_key: private futex, key={:?}", key);
debug!("[FUTEX_DEBUG] get_futex_key: private futex, key={:?}", key);

Copilot uses AI. Check for mistakes.
Comment on lines 616 to 619
warn!(
"[FUTEX_DEBUG] get_futex_key: shared file, dev=0x{:x}, ino=0x{:x}, pgoff={}, page_index={}, key={:?}",
dev, ino, base_pgoff, page_index, key
);
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug logging statements using warn!() macro should be conditionally compiled or use a debug!() macro instead to avoid performance impact in production builds.

Copilot uses AI. Check for mistakes.
Comment on lines 635 to 638
warn!(
"[FUTEX_DEBUG] get_futex_key: shared anon, anon_id=0x{:x}, page_index={}, key={:?}",
i_seq, page_index, key
);
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug logging statements using warn!() macro should be conditionally compiled or use a debug!() macro instead to avoid performance impact in production builds.

Copilot uses AI. Check for mistakes.
return Ok(key);
} else {
// 理论上不会发生;为安全起见,退化为私有键(不跨进程匹配)
warn!("[FUTEX_DEBUG] get_futex_key: shared anon without id; fallback to private");
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug logging statements using warn!() macro should be conditionally compiled or use a debug!() macro instead to avoid performance impact in production builds.

Suggested change
warn!("[FUTEX_DEBUG] get_futex_key: shared anon without id; fallback to private");
debug!("[FUTEX_DEBUG] get_futex_key: shared anon without id; fallback to private");

Copilot uses AI. Check for mistakes.
@github-actions github-actions bot added the enhancement New feature or request label Oct 8, 2025
@fslongjin fslongjin merged commit 3b3b55b into DragonOS-Community:master Oct 10, 2025
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug fix A bug is fixed in this pull request enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant