Commit Graph

2786 Commits

Author SHA1 Message Date
kellito f5baa05d4a v5.3: scheme: honor O_NONBLOCK on open opcode (Design B / initnsmgr fix)
Add O_NONBLOCK handling to UserInner::call_inner for Opcode::OpenAt.
When the caller passes O_NONBLOCK in the open flags and the
provider has not yet responded after one scheduling quantum,
return EAGAIN immediately instead of blocking the caller.

This implements Design B from local/docs/INITNSMGR-CONCURRENCY-DESIGN.md,
enabling the initnsmgr to use O_NONBLOCK on openat to avoid
head-of-line blocking on slow provider daemons.

The mechanism:
1. Detect O_NONBLOCK + OpenAt from sqe.args[3] (flags).
2. For nonblock open, skip the block() call - stay Runnable.
3. Send the SQE and trigger the provider event (same as blocking).
4. Do one context::switch() to give the provider a chance to run
   and respond. If the provider responds within that quantum,
   return Ok(result).
5. If the provider has not responded, cancel the request via
   the existing cancellation path (Cancel SQE + cleanup of
   callee_responsible PageSpan and fds), and return EAGAIN.

The caller treats EAGAIN as 'try again later' and parks the
request; initnsmgr (in local/sources/base) implements the
event-driven deferred retry pattern that uses this signal.

Preserves all existing behavior for non-open opcodes and for
open without O_NONBLOCK. Round-robin scheduler means the provider
gets a fair chance to run after the caller yields.

Per local/AGENTS.md:
- No new branches (work on submodule/kernel)
- No stubs, no todo!/unimplemented!
- Cross-module change: kernel + base (committed separately)

Closes v5.3 Design B (kernel side). Base side is the companion
commit on submodule/base.
2026-07-26 06:09:39 +09:00
vasilito 00da984779 kernel: consume LPIT MWAIT hint in idle_loop via AcpiVerb::SetLpiHint
- acpi.rs: LPI_MWAIT_HINT/LPI_MWAIT_HINT_SET atomics + set/get
  accessors; AcpiVerb::SetLpiHint handler reads the 4-byte LE
  payload and stores the firmware-recommended MWAIT hint.
- interrupt/mod.rs idle_loop(): prefer the LPIT entry_trigger hint
  (set by acpid) for mwait_loop(); fall back to CPUID leaf-5 max
  substate when no LPIT hint is available (no LPIT table, or
  pre-acpid boot).

This is the full Modern Standby integration: the CPU now enters the
firmware-optimal deepest LPI state during s2idle, not merely the
CPUID-reported deepest state.
2026-07-22 22:07:02 +09:00
vasilito bd1b251f70 kernel: fix post-merge compile errors (import dedup + UnmapVec)
Two fixes required for the merged tree to compile (repo cook kernel
--force-rebuild passes with them):

- event.rs: drop EAGAIN/EINTR from the top-level syscall import — the
  crate::syscall::error import further down already brings both names
  into scope (E0252 duplicate-definition).

- scheme/proc.rs: drop UnmapVec from the context::memory import — the
  fork deleted that machinery from context/memory.rs (E0432
  unresolved import); the type's only use site is the import itself.
2026-07-19 07:15:16 +09:00
vasilito 660e3e001d Merge upstream/master into submodule/kernel
Sync the kernel fork with 10 upstream commits (context timer-separation
with unblock_context/wakeup_context, dtb MMIO/bus-address translation
+ tests, event read_with_timeout support, proc wakeup paths, dup2
rewrite with rollback, futex Weak context_lock + unblock_context,
memory/init ordering, and more). Satisfies the verify-fork-functions
gate (11 previously-missing upstream functions now present).

Conflicts resolved (5 files; 9 auto-merged):

- src/syscall/futex.rs: took upstream's version wholesale (Weak
  context_lock, upgrade+unblock_context, TimeSpec::to_nanos,
  get_futex_stat, addr_space strong_count cleanup); re-applied the RB
  FUTEX_WAIT_MULTIPLE/FUTEX_REQUEUE implementations adapted to the
  Weak API, with wake-index bookkeeping preserved
  (Context::futex_wake_index survives in context.rs).

- src/event.rs: merged EventQueue with both RB's fd-refcount refs and
  upstream's timeout_opt (init in new()); kept RB's EventCounter/
  eventfd block; added upstream's read_with_timeout +
  EVENT_TIMEOUT_ID write handling; deduplicated EAGAIN/EINTR imports.

- src/scheme/proc.rs: upstream imports minus UnmapVec (RB deleted that
  machinery from context/memory.rs — import-only dependency);
  ContextHandle::Start keeps RB's require_zero_offset + upstream's
  wakeup_context; FORCEKILL region takes upstream's
  is_dead()/being_sigkilled form.

- src/syscall/fs.rs: took upstream's dup2 structure (natural
  self-dup-with-buf handling — preserves the relibc dup2(ft,ft,
  "refresh") semantic — plus rollback on insert failure), adapted to
  the fork's 4-arg duplicate_file and read/token_split conventions.

- src/arch/aarch64/start.rs: kept upstream's new PageMapper/
  acpi::init_before_mem/memory::init_mm init block.

Verified: repo cook kernel --force-rebuild successful;
verify-fork-functions.sh --no-fetch kernel passes.
2026-07-19 07:02:19 +09:00
R Aadarsh eaf50894aa * Do not use KernelMapper for ACPI SDT mapping
* Clarify doc comment
2026-07-18 17:25:02 +05:30
vasilito eccee97b39 Revert DIAG dup2 logging (refresh confirmed working euid=0) 2026-07-18 17:29:32 +09:00
vasilito 4e63456776 DIAG: log dup2 self-buf (filetable refresh) euid + duplicate_file result 2026-07-18 17:21:56 +09:00
vasilito 32715cbd95 proc/fs: make dup2 refresh conservative (preserve original non-self dup2 path)
The previous backport rewrote the whole dup2 (duplicate-first, remove/insert)
which perturbed ordinary dup2 used by process-spawn stdio setup and could
break exec (ENOENT). Restrict the new behavior to the self-dup-with-buffer
case (dup2(ft, ft, 'refresh')); the normal fd!=new_fd path is byte-for-byte
the original.
2026-07-18 15:58:48 +09:00
vasilito 72be9f9f46 proc/fs: allow refreshing filetable data via dup2 (fix O_CLOEXEC / stale inherited fds)
Backport of upstream kernel 37ffa2e2. The proc scheme's filetable dup2
only accepted 'copy'; a 'refresh' buffer now re-materializes the
filetable's descriptor list in place. dup2() no longer short-circuits a
self-dup (fd==new_fd) when a buffer is supplied, and duplicates before
replacing the target descriptor. Together with relibc's
FdTbl::from_binary_fd issuing dup2(ft, ft, 'refresh'), an exec'd process
(e.g. a login shell) rebuilds its fd table from the CURRENT parent state
instead of a stale snapshot -- fixing interactive shells whose pty-slave
stdin returned nothing while writes to fd 1/2 worked. fs.rs dup2 adapted
to the local duplicate_file(cloexec) signature.
2026-07-18 14:58:46 +09:00
Wildan M 4251102f0b Partially solve missing wakeups after separate timers 2026-07-17 20:02:37 -06:00
Luiz Fernando Becher de Araujo eb51898177 AArch64: Map diagnostic UART and root GIC MMIO
Device memory registration currently stops when /soc or its ranges
property is absent and only considers direct /soc children. Some
devicetrees place the interrupt controller at the root and the
selected UART below nested buses.

Register the exact translated range of the diagnostic UART and the
register ranges of root interrupt controllers. Use the hierarchical
translator when initializing GICv2 and GICv3 registers.

This keeps the translation change limited to the selected console
and interrupt controllers while preserving the existing behavior for
other devices.

Signed-off-by: Luiz Fernando Becher de Araujo <luiz.becher.araujo@gmail.com>
2026-07-17 20:00:40 -06:00
Luiz Fernando Becher de Araujo 20800bd2c7 DTB: Translate MMIO addresses through nested buses
The existing MMIO helper only translates addresses through the /soc
ranges property. This does not handle devices below nested buses,
such as the UART in the devicetree used by the Meson boards.

Add an address translator that walks each ancestor bus and applies
its ranges property until reaching the CPU address space. Treat
empty ranges as an identity mapping and reject regions that cross a
range boundary.

Keep the existing helper’s behavior unchanged for other devices to
limit the scope of the behavioral change.

Add tests for nested buses, empty ranges, exact range boundaries,
and regions crossing a boundary.

Signed-off-by: Luiz Fernando Becher de Araujo <luiz.becher.araujo@gmail.com>
2026-07-17 20:00:40 -06:00
Wildan M cd369993d9 Fix EOF using EVENT_TIMEOUT_ID 2026-07-17 19:56:28 -06:00
Ibuki Omatsu 37ffa2e29e refactor: Allow refreshing filetable data using dup2 to fix O_CLOEXEC 2026-07-17 19:49:20 -06:00
vasilito 229046c634 fix(debug): report EVENT_READ in fevent when serial input is queued
The debug scheme's fevent always returned empty, relying solely on the
edge-triggered debug_notify(). A reader that registers with an event queue after
input has already arrived (fbcond's serial console) would miss it. Report
readable when the input queue is non-empty.
2026-07-18 07:23:29 +09:00
vasilito 40e3c4911a event: implement kdup so epoll fds can be duplicated (fixes tokio on Redox)
The event scheme (scheme:event, Redox's epoll backend) implemented
open/read/write/fpath/fevent but NOT dup, so dup() of an event-queue fd
fell through to the default kdup and returned EINVAL. tokio/mio's I/O
reactor construction does exactly this: Poll::new() opens the queue, then
registry.try_clone() dups it (registrations go through the clone, polling
through the original). The EINVAL made every tokio Runtime::build() with an
I/O driver fail — killing all zbus daemons (sessiond/polkit/udisks/upower)
and the brush login shell ("failed to create tokio runtime: Invalid
argument"), which is why text login never worked.

Implement kdup: duping an event-queue fd returns a second handle to the
SAME queue (shared registrations + delivered events, as epoll requires),
reference-counted on EventQueue so the queue survives until the last fd
closes. eventfd counters are not dup-able (unused: mio's Redox waker uses a
pipe). Verified: cargo check --target x86_64-unknown-kernel passes.
2026-07-17 21:45:34 +09:00
Wildan M e100dd5a71 Fix RISCV init memory 2026-07-16 16:04:31 +07:00
Akshit Gaur f5fe18b23c Finish the work on separating timers 2026-07-16 07:48:54 -06:00
vasilito 155d01b11e kernel(x86_64): make /scheme/sys/msr MSR access #GP-safe
The MSR R/W scheme lets root request an arbitrary wrmsr/rdmsr on any CPU
(used by cpufreqd/thermald). A bad MSR number or reserved-bit value raises
#GP; on the raw wrmsr/rdmsr that is a kernel-mode fault that panics the
whole machine at exit_this_context (unreachable!) — i.e. root userspace can
crash the kernel. Observed on KVM: cpufreqd writing a legacy P-state MSR
(#GP in the msr IPI handler) halted the boot right before the console/login.

Add wrmsr_safe/rdmsr_safe (arch/x86_64): the faulting instruction sits in a
__wrmsr_safe_start/end (resp. rdmsr) region, and the #GP handler recognises a
fault inside those bounds and returns an error via recover_and_efault — the
same fault-recovery mechanism already used for usercopy page faults. The MSR
scheme (local path) and the cross-CPU msr IPI handler now use these and
surface EIO to the caller (IPI failures propagated via a new MsrMailbox
faulted flag) instead of panicking. 32-bit x86 keeps the raw path (untested).
2026-07-16 12:11:34 +09:00
Wildan M ee4a5602a6 Implement make install and test targets 2026-07-16 01:27:47 +07:00
vasilito 887552f251 remove temporary openat/openat_into/write kernel diagnostics 2026-07-15 21:38:38 +09:00
vasilito 22de233c1a diag(kernel): log non-ENOENT openat + openat_into failures 2026-07-15 19:16:55 +09:00
vasilito b5a7bf5581 fix(kernel): FileTableVerb::Resize no-op + ProcUptime soft-float
Two fixes on the clean base (all boot-investigation diagnostics removed):

1. ProcScheme::kcall now accepts FileTableVerb::Resize on filetable
   handles as a no-op instead of returning EBADF. After the upstream
   'move fd allocation into userspace' relibc refactor, FILETABLE
   pre-syncs its size via a Resize call before growing; the kernel
   already grows posix_fdtbl on insert. Returning EBADF broke add_posix
   once a process's fd table grew (notably the bootstrap process manager
   proxying child thread ops), making the child's regs/env dup fail and
   its ld.so panic, crashing initfs daemons (randd) at boot.

2. ProcUptime uses integer arithmetic instead of f64 (the kernel is
   built with +soft-float; f64 in format!() breaks the build).
2026-07-15 15:27:55 +09:00
vasilito 2086faecb0 rb: reapply Red Bear patches on upstream 00cfa2d2 2026-07-12 16:55:28 +03:00
R Aadarsh a5ae1ff3b0 Use Mutex for round robin index allocation 2026-07-12 12:56:51 +05:30
R Aadarsh 00cfa2d225 Add support for querying dom-node map 2026-07-11 08:33:17 +05:30
MJ Pooladkhay 985bc2623f Fix a race in get_round_robin_index. 2026-07-10 18:13:36 -06:00
R Aadarsh bb06db93ce Add support for querying numa info from userspace 2026-07-10 15:46:02 +05:30
R Aadarsh fbfe439451 Fix riscv and x86 compilation failure 2026-07-09 19:26:01 +05:30
R Aadarsh bfbbec47a9 Create seperate free lists for each NUMA memory regions 2026-07-08 21:33:02 +05:30
R Aadarsh 621a0f4be9 * Split free areas at NUMA memory boundaries
* Fix incorrect name usage in ACPI ARM parsing code
2026-07-08 21:32:37 +05:30
Akshit Gaur 38642377f3 Separate timers 2026-07-07 06:43:41 -06:00
4lDO2 c83b38eb70 Remove obsolete TODO, run rustfmt. 2026-07-06 19:30:05 +02:00
R Aadarsh 4d5d36d44e Extract code that is common to both x86 and ARM to srat::init 2026-07-05 20:16:00 +05:30
R Aadarsh 35340a80c4 * Add ACPI-NUMA parsing code for ARM
* Fix bug in the x86 code that caused incorrect cpu-node mapping

* Remove the usage of page mappers. Instead use the already existing
  linear mapping
2026-07-05 15:01:48 +05:30
R Aadarsh cb88ed59a2 Parse ACPI tables for NUMA information without allocating from the heap 2026-07-03 20:19:46 +05:30
Wildan M 372cd19b6f Remove irq from handles on close 2026-07-02 08:41:11 +07:00
R Aadarsh aa7e7d2f44 Fix the bug in RxsdtIter that caused u32 pointers to be used regardless of ACPI table kind 2026-07-01 10:36:07 -06:00
R Aadarsh a03c545f3c Fix build failure for ARM 2026-07-01 10:36:07 -06:00
R Aadarsh a2a3df33c6 Split acpi::init to perform two stage initialisation 2026-07-01 10:36:07 -06:00
Ibuki Omatsu 6c3d5d28c6 refactor: Move fd allocation logic into userspace 2026-07-01 08:02:47 -06:00
R Aadarsh 8171dc616b Fix panic due to using uninitialised NUMA_NODES 2026-06-21 14:30:07 +05:30
R Aadarsh 2ad76496c4 * Store addresses as pointers
* Remove lots of unsafe code by initialising in the closure passed to
  `call_once`

* Remove `NUMBER_OF_DOMAINS` as size can always be inferred from the
  hashmap's len
2026-06-21 14:03:49 +05:30
R Aadarsh 4106dcbbfa Gate behind a feature flag 2026-06-21 14:03:49 +05:30
R Aadarsh 969c905d8e Account for the case when distance information is not available 2026-06-21 14:03:49 +05:30
R Aadarsh 9ecc75029c * Correctly put cpus and memories for adoption
* Test on x86_64 (works)
2026-06-21 14:03:49 +05:30
R Aadarsh 16c59588b0 * Fix endianness
* Remove ITS affinity and numa
2026-06-21 14:03:49 +05:30
R Aadarsh ee2a61088e * Parse SLIT for distance information
* Order by distance, reorganise domains into nodes
2026-06-21 14:03:49 +05:30
R Aadarsh 63d1171ffb Initial commit 2026-06-21 14:03:49 +05:30
Wildan M 002fff546d Clear cloexec flag on Dup2 2026-06-20 06:35:01 +07:00