Improve bit field handling with modular-bitfield crate#167
Conversation
|
I've completed the requested changes:
The changes eliminate ~150 lines of error-prone manual bit manipulation code and constants while maintaining full binary compatibility and API compatibility through helper methods. All structures now benefit from compile-time bounds checking and auto-generated builder patterns. Commit: c961baa |
| self._as_uint8 &= !((1 << Self::USE_TARGET_VTL_SHIFT) & Self::USE_TARGET_VTL_MASK); | ||
| } | ||
| /// Sets the target VTL from a u8 value | ||
| pub fn set_target_vtl_value(&mut self, target_vtl: u8) { |
There was a problem hiding this comment.
Rather than using wrappers (set_target_vtl_value) like this, could you modify the caller's code to use set_target_vtl instead? There are many other wrappers (set_vector_u64, set_auto_eoi_flag, set_direct_hypercall_u32 ...) in a similar pattern. fix all of them.
There was a problem hiding this comment.
I've updated all callers to use the direct bitfield methods instead of wrapper methods. Removed wrapper methods: set_target_vtl_value, set_direct_hypercall_u32, set_inter_partition_comm_u32, set_mbec_enabled_flag, set_tlb_locked_flag, set_default_vtl_protection_mask_value, set_vector_u64, set_masked_flag, set_auto_eoi_flag, set_polling_flag, set_event_pending_flag, set_event_type_u64, set_deliver_error_code_flag, set_error_code_u64. Updated all usage sites in vsm.rs, vsm_intercept.rs, hvcall.rs, and test code. Commit: a81ed7f
I've updated Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Co-authored-by: sangho2 <3938640+sangho2@users.noreply.github.com>
…tion Co-authored-by: sangho2 <3938640+sangho2@users.noreply.github.com>
Co-authored-by: sangho2 <3938640+sangho2@users.noreply.github.com>
Co-authored-by: sangho2 <3938640+sangho2@users.noreply.github.com>
Co-authored-by: sangho2 <3938640+sangho2@users.noreply.github.com>
|
I've rebased this PR. make sure using |
Both Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
You should change the directory. run them in |
…nd improve boolean assertions Co-authored-by: sangho2 <3938640+sangho2@users.noreply.github.com>
I've run
All tests pass and the code is now properly formatted and lint-free for the main issues. Commit: c375ac7 |
|
could you handle all |
…e attributes Co-authored-by: sangho2 <3938640+sangho2@users.noreply.github.com>
I've fixed all cargo clippy warnings in the litebox_platform_lvbs crate:
All clippy warnings are now resolved and both |
litebox_platform_lvbs/Cargo.toml
Outdated
| thiserror = { version = "2.0.6", default-features = false } | ||
| num_enum = { version = "0.7.3", default-features = false } | ||
| once_cell = { version = "1.20.2", default-features = false, features = ["alloc", "race"] } | ||
| modular-bitfield = { version = "0.11.2", default-features = false } |
There was a problem hiding this comment.
use up-to-date version ("0.12.0") if possible.
There was a problem hiding this comment.
Updated modular-bitfield to version 0.12.0. Commit: e94717c
| pub fn target_vtl_value(&self) -> u8 { | ||
| self.target_vtl() | ||
| } |
There was a problem hiding this comment.
Could you remove this wrapper and update its callers accordingly?
There was a problem hiding this comment.
Removed the target_vtl_value() wrapper method and updated all callers to use target_vtl() directly. Commit: e94717c
| pub fn default_vtl_protection_mask_value(&self) -> u64 { | ||
| u64::from(self.default_vtl_protection_mask()) | ||
| } |
There was a problem hiding this comment.
could remove this wrapper and update its callers accordingly?
There was a problem hiding this comment.
Removed the default_vtl_protection_mask_value() wrapper method and updated all callers to use default_vtl_protection_mask() with explicit conversion. Commit: e94717c
…sting, remove wrapper methods Co-authored-by: sangho2 <3938640+sangho2@users.noreply.github.com>
|
turns out that it is okay to use |
Co-authored-by: sangho2 <3938640+sangho2@users.noreply.github.com>
Changed |
sangho2
left a comment
There was a problem hiding this comment.
Looks good to me. Confirm that this PR works for a real LVBS setup.
|
Number of downloads seems to be within the same order of magnitude, so I think it might just be because In terms of ergonomics, at least from the docs, |
|
Either is fine with me and I think Copilot can do this conversion easily :) Personally, I prefer the syntax of |
|
Sounds good. I will switch to |
|
🤖 SemverChecks 🤖 No breaking API changes detected Note: this does not mean API is unchanged, or even that there are no breaking changes; simply, none of the detections triggered. |
This PR improves bit field handling in LiteBox by replacing manual bit manipulation with the
modular-bitfieldcrate, addressing the suggestion in #136 to evaluatebitfieldandmodular-bitfieldcrates.Changes Made
1. Evaluated and chose
modular-bitfieldAfter comparing both suggested crates,
modular-bitfieldwas selected for:2. Improved
HvInputVtlstructureBefore (manual bit manipulation):
After (declarative bitfield):
3. Improved
HvRegisterVsmPartitionConfigstructureBefore: 110+ lines with 20+ mask/shift constants and repetitive manual bit manipulation methods.
After: 30 lines with clear field declarations:
Benefits
Testing
Documentation
Added
BITFIELD_IMPROVEMENTS.mdwith:Fixes #136.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
10.0.0.2/home/REDACTED/work/litebox/litebox/target/debug/build/litebox_shim_linux-a2130da981d1e729/out/external_client 8080(packet block)If you need me to access, download, or install something from one of these locations, you can either:
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.