Separate lock-free fields from Zone and make fields private#270
Merged
li041 merged 1 commit intosyswonder:devfrom Mar 19, 2026
Merged
Separate lock-free fields from Zone and make fields private#270li041 merged 1 commit intosyswonder:devfrom
Zone and make fields private#270li041 merged 1 commit intosyswonder:devfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors zone state management by splitting Zone into lock-free fields and synchronized state (ZoneInner) behind an RwLock, and updates call sites to use accessor methods instead of direct public field access.
Changes:
- Introduce
ZoneInner(locked) and move mutable/shared state fromZoneinto it; keepid/name/is_errlock-free (atomic/immutable). - Replace
Arc<RwLock<Zone>>withArc<Zone>and update zone interactions across PCI, MMIO, hypercalls, and irqchip/device/arch code to useZone::read()/Zone::write(). - Adjust PCI APIs for more read-only access (e.g.,
VirtualRootComplex::get_device_by_base(&self, ...)).
Reviewed changes
Copilot reviewed 33 out of 33 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/zone.rs | Introduces ZoneInner behind RwLock, makes fields private, updates zone list types and zone lifecycle helpers. |
| src/pci/pci_test.rs | Updates PCI tests to access vpci_bus via ZoneInner guards + accessors. |
| src/pci/pci_struct.rs | Makes get_device_by_base take &self (read-only lookup). |
| src/pci/pci_handler.rs | Updates zone access patterns to use ZoneInner accessors; reduces write-lock usage where possible. |
| src/pci/pci_config.rs | Uses a ZoneInner write guard (inner) to mutate PCI/MMIO-related zone state. |
| src/memory/mmio.rs | Switches to zone.id() and uses ZoneInner::find_mmio_region via zone.read(). |
| src/hypercall/mod.rs | Updates cpu_set access via accessors; changes irqchip reset call site to avoid relying on ZoneInner guard. |
| src/device/sifive_ccache/mod.rs | Registers MMIO regions via self.write().mmio_region_register(...). |
| src/device/irqchip/plic/mod.rs | Removes outer zone lock usage and updates irq_bitmap/cpu_* access via ZoneInner methods. |
| src/device/irqchip/pic/mod.rs | Updates to self.id() for DMA table clearing. |
| src/device/irqchip/pic/ioapic.rs | Updates IOAPIC MMIO registration to go through ZoneInner write guard. |
| src/device/irqchip/gicv3/vgic.rs | Updates MMIO registration and IRQ bitmap init to use ZoneInner guards/accessors; updates GPM queries. |
| src/device/irqchip/gicv3/mod.rs | Updates irq bitmap iteration and uses self.id() for ITS reset. |
| src/device/irqchip/gicv3/gits.rs | Updates GPM access and cpu_set accessors for command analysis and address translation. |
| src/device/irqchip/gicv2/vgic.rs | Updates MMIO registration, GPM insertion, and irq bitmap init to use ZoneInner guards/accessors. |
| src/device/irqchip/aia/vimsic.rs | Updates to accessor-based cpu_set and GPM mutation through ZoneInner guard. |
| src/device/irqchip/aia/vaplic.rs | Updates cpu_set access to use accessor methods. |
| src/device/irqchip/aia/mod.rs | Removes outer .read() usage (zone now Arc<Zone>), updates id usage and IRQ bitmap iteration via ZoneInner. |
| src/device/eic7700_syscrg.rs | Registers syscon MMIO regions via a single ZoneInner write guard. |
| src/cpu_data.rs | Changes per-cpu zone handle to Option<Arc<Zone>> and updates GPM activation access pattern. |
| src/arch/x86_64/zone.rs | Updates PT init and arch configuration to mutate/query through ZoneInner guards/accessors. |
| src/arch/x86_64/mmio.rs | Updates GPM queries to use gpm() accessor. |
| src/arch/x86_64/ipi.rs | Uses Zone::cpu_set() accessor (no direct field access). |
| src/arch/x86_64/hypercall.rs | Updates GPM queries to use gpm() accessor. |
| src/arch/riscv64/zone.rs | Uses ZoneInner guard/accessors for GPM insertion and MMIO registration; updates logging. |
| src/arch/riscv64/cpu.rs | Updates cpu_set access to use accessor method. |
| src/arch/loongarch64/zone.rs | Uses ZoneInner guard/accessors for GPM insertion/deletion and MMIO registration; updates logging and queries. |
| src/arch/loongarch64/trap.rs | Updates zone id access to id() (no outer lock). |
| src/arch/aarch64/zone.rs | Uses ZoneInner guard/accessors for PT init and IOMMU PT init; improves non-root error handling for unsupported mem types. |
| src/arch/aarch64/trap.rs | Updates zone id / cpu_set access to accessors. |
| src/arch/aarch64/ivc.rs | Uses ZoneInner guard/accessors for GPM insertion and MMIO registration; updates zone id usage. |
| src/arch/aarch64/hypercall.rs | Updates GPM queries to use gpm() accessor. |
| src/arch/aarch64/cpu.rs | Updates cpu_set access to use accessor method. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
5501906 to
9f9c2cc
Compare
liulog
reviewed
Mar 16, 2026
liulog
approved these changes
Mar 17, 2026
Contributor
|
Has this PR been tested on any development board so far? |
Contributor
Contributor
Author
Yeah, this PR has been tested on qemu platform and Rk3588. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Overview
This PR refactors the
Zonestructure to clearly separate fields that require synchronization from fields that do not, and improves encapsulation by removing direct public field access.Changes
1. Separate lock-free fields
Previously, all fields were stored directly inside
Zone, even though some fields do not require synchronization.This PR introduces a new structure:
which contains fields that require synchronization.
ZoneInneris protected by anRwLockinsideZone.Fields that do not require whole locking remain directly in
Zone, such as:nameidis_errThis separation makes it explicit which fields require locking and avoids unnecessary locking for immutable or atomic data.
2. Make struct fields private
All fields in
ZoneandZoneInnerwere previously declared aspub.They are now made private and accessed through accessor methods.
This prevents external code from directly mutating internal state and ensures that access patterns follow the intended synchronization model.
Result
After this change: