Skip to content

Add arch-specific provider; remove PunchthroughProvider#806

Open
jaybosamiya-ms wants to merge 1 commit into
mainfrom
jayb/arch-specific-provider
Open

Add arch-specific provider; remove PunchthroughProvider#806
jaybosamiya-ms wants to merge 1 commit into
mainfrom
jayb/arch-specific-provider

Conversation

@jaybosamiya-ms
Copy link
Copy Markdown
Member

This PR removes the last vestiges of the PunchthroughProvider, moving out architecture-specific register management into its own trait. For now, I've only added support for x86-64's fsbase/gsbase, with platforms deciding which ones they'd like to support and which ones they do not want to support. This slightly expands beyond the only-fsbase behavior that existed in the old code, but acts as a way to improve clarity on usability (indeed, handling these generically will be needed if/when we want a proper WinNT shim, so might as well generalize right now).

@jaybosamiya-ms jaybosamiya-ms marked this pull request as ready for review April 24, 2026 01:27
@jaybosamiya-ms jaybosamiya-ms force-pushed the jayb/arch-specific-provider branch 2 times, most recently from e9dffae to 2542f06 Compare April 24, 2026 01:29
@jaybosamiya-ms jaybosamiya-ms force-pushed the jayb/arch-specific-provider branch from 2542f06 to 8f4da91 Compare April 24, 2026 01:31
@github-actions
Copy link
Copy Markdown

🤖 SemverChecks 🤖 ⚠️ Potential breaking API changes detected ⚠️

Click for details
--- failure enum_missing: pub enum removed or renamed ---

Description:
A publicly-visible enum cannot be imported by its prior path. A `pub use` may have been removed, or the enum itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/enum_missing.ron

Failed in:
  enum litebox::platform::EitherError, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/c6d47943dd9d45d7a9bc9ab6caef4e1969bca0fd/litebox/src/platform/mod.rs:209
  enum litebox::platform::trivial_providers::ImpossiblePunchthroughToken, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/c6d47943dd9d45d7a9bc9ab6caef4e1969bca0fd/litebox/src/platform/trivial_providers.rs:48
  enum litebox::platform::trivial_providers::ImpossiblePunchthrough, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/c6d47943dd9d45d7a9bc9ab6caef4e1969bca0fd/litebox/src/platform/trivial_providers.rs:40
  enum litebox::platform::PunchthroughError, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/c6d47943dd9d45d7a9bc9ab6caef4e1969bca0fd/litebox/src/platform/mod.rs:198

--- failure struct_missing: pub struct removed or renamed ---

Description:
A publicly-visible struct cannot be imported by its prior path. A `pub use` may have been removed, or the struct itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/struct_missing.ron

Failed in:
  struct litebox::platform::trivial_providers::IgnoredPunchthroughProvider, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/c6d47943dd9d45d7a9bc9ab6caef4e1969bca0fd/litebox/src/platform/trivial_providers.rs:66
  struct litebox::platform::trivial_providers::IgnoredPunchthrough, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/c6d47943dd9d45d7a9bc9ab6caef4e1969bca0fd/litebox/src/platform/trivial_providers.rs:77
  struct litebox::platform::trivial_providers::ImpossiblePunchthroughProvider, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/c6d47943dd9d45d7a9bc9ab6caef4e1969bca0fd/litebox/src/platform/trivial_providers.rs:26
  struct litebox::platform::trivial_providers::IgnoredPunchthroughToken, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/c6d47943dd9d45d7a9bc9ab6caef4e1969bca0fd/litebox/src/platform/trivial_providers.rs:85

--- failure trait_added_supertrait: non-sealed trait added new supertraits ---

Description:
A non-sealed trait added one or more supertraits, which breaks downstream implementations of the trait
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#generic-bounds-tighten
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/trait_added_supertrait.ron

Failed in:
  trait litebox::platform::Provider gained ArchSpecificProvider in file /home/runner/work/litebox/litebox/litebox/src/platform/mod.rs:29

--- failure trait_method_missing: pub trait method removed or renamed ---

Description:
A trait method is no longer callable, and may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#trait-item-signature
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/trait_method_missing.ron

Failed in:
  method clear_guest_thread_local_storage of trait ThreadLocalStorageProvider, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/c6d47943dd9d45d7a9bc9ab6caef4e1969bca0fd/litebox/src/platform/mod.rs:678

--- failure trait_missing: pub trait removed or renamed ---

Description:
A publicly-visible trait cannot be imported by its prior path. A `pub use` may have been removed, or the trait itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/trait_missing.ron

Failed in:
  trait litebox::platform::PunchthroughToken, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/c6d47943dd9d45d7a9bc9ab6caef4e1969bca0fd/litebox/src/platform/mod.rs:173
  trait litebox::platform::PunchthroughProvider, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/c6d47943dd9d45d7a9bc9ab6caef4e1969bca0fd/litebox/src/platform/mod.rs:156
  trait litebox::platform::Punchthrough, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/c6d47943dd9d45d7a9bc9ab6caef4e1969bca0fd/litebox/src/platform/mod.rs:191

--- failure trait_removed_supertrait: supertrait removed or renamed ---

Description:
A supertrait was removed from a trait. Users of the trait can no longer assume it can also be used like its supertrait.
        ref: https://doc.rust-lang.org/reference/items/traits.html#supertraits
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/trait_removed_supertrait.ron

Failed in:
  supertrait litebox::platform::PunchthroughProvider of trait Provider in file /home/runner/work/litebox/litebox/litebox/src/platform/mod.rs:29

--- failure enum_missing: pub enum removed or renamed ---

Description:
A publicly-visible enum cannot be imported by its prior path. A `pub use` may have been removed, or the enum itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/enum_missing.ron

Failed in:
  enum litebox_common_linux::PunchthroughSyscall, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/c6d47943dd9d45d7a9bc9ab6caef4e1969bca0fd/litebox_common_linux/src/lib.rs:2662

--- failure struct_missing: pub struct removed or renamed ---

Description:
A publicly-visible struct cannot be imported by its prior path. A `pub use` may have been removed, or the struct itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/struct_missing.ron

Failed in:
  struct litebox_common_linux::UserDescFlags, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/c6d47943dd9d45d7a9bc9ab6caef4e1969bca0fd/litebox_common_linux/src/lib.rs:948
  struct litebox_common_linux::UserDesc, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/c6d47943dd9d45d7a9bc9ab6caef4e1969bca0fd/litebox_common_linux/src/lib.rs:941

--- failure struct_missing: pub struct removed or renamed ---

Description:
A publicly-visible struct cannot be imported by its prior path. A `pub use` may have been removed, or the struct itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/struct_missing.ron

Failed in:
  struct litebox_platform_linux_kernel::LinuxPunchthroughToken, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/c6d47943dd9d45d7a9bc9ab6caef4e1969bca0fd/litebox_platform_linux_kernel/src/lib.rs:57

--- failure struct_missing: pub struct removed or renamed ---

Description:
A publicly-visible struct cannot be imported by its prior path. A `pub use` may have been removed, or the struct itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/struct_missing.ron

Failed in:
  struct litebox_platform_linux_userland::PunchthroughToken, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/c6d47943dd9d45d7a9bc9ab6caef4e1969bca0fd/litebox_platform_linux_userland/src/lib.rs:1196

--- failure struct_missing: pub struct removed or renamed ---

Description:
A publicly-visible struct cannot be imported by its prior path. A `pub use` may have been removed, or the struct itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.47.0/src/lints/struct_missing.ron

Failed in:
  struct litebox_platform_lvbs::LinuxPunchthroughToken, previously in file /home/runner/work/litebox/litebox/target/semver-checks/git-main/c6d47943dd9d45d7a9bc9ab6caef4e1969bca0fd/litebox_platform_lvbs/src/lib.rs:398

Ok(())
}
ArchSpecificRegister::GsBase => {
unsafe { litebox_common_linux::wrgsbase(val) };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In kernel mode, we call swapgs at the entry and exit of a syscall. At this point, userspace gsbase is stored in MSR (see https://elixir.bootlin.com/linux/v5.19.17/source/arch/x86/kernel/process_64.c#L763).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note the issue was found by GPT-5.5

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But it depends on when/where this function is called, right? If the caller is after swapgs and it actually knows that it wants to access which register, this function is correct, right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, I see the issue. When this kernel platform code executes, if we do wrfsbase or wrgsbase, it actually directly affects the current gsbase used by the kernel. Is my understanding correct?

) -> Result<usize, ArchSpecificError> {
match reg {
ArchSpecificRegister::FsBase => Ok(unsafe { litebox_common_linux::rdfsbase() }),
ArchSpecificRegister::GsBase => Ok(unsafe { litebox_common_linux::rdgsbase() }),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similar

Ok(v) => Ok(v),
Err(e) => Err(litebox::platform::PunchthroughError::Failure(e)),
ArchSpecificRegister::GsBase => {
unsafe { litebox_common_linux::wrgsbase(val) };
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

probably same

) -> Result<usize, ArchSpecificError> {
match reg {
ArchSpecificRegister::FsBase => Ok(unsafe { litebox_common_linux::rdfsbase() }),
ArchSpecificRegister::GsBase => Ok(unsafe { litebox_common_linux::rdgsbase() }),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same

Copy link
Copy Markdown
Member

@wdcui wdcui left a comment

Choose a reason for hiding this comment

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

I left some comments below. Will have some offline discussion with you.

// Reaching here means that a shim is attempting to easily run on a platform that
// fully disallows it. There is no reasonable handling here, so we panic.
// XXX: should this be ENOSYS?
panic!()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I wouldn't expect an error code conversion function to panic?

Ok(())
}
ArchSpecificRegister::GsBase => {
unsafe { litebox_common_linux::wrgsbase(val) };
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But it depends on when/where this function is called, right? If the caller is after swapgs and it actually knows that it wants to access which register, this function is correct, right?

litebox::platform::ArchSpecificRegister::GsBase => {
// GS base is used internally by this platform to hold the host
// TLS base across the guest/host fs-gs swap, so it is not
// directly programmable by the guest.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why would you expect the guest to call this platform trait?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants