Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openhcl/tdx: debug register query on HW_INTERRUPT exit is expensive #876

Open
chris-oo opened this issue Feb 20, 2025 · 6 comments
Open
Assignees
Labels
tdx TDX specific bugs or features

Comments

@chris-oo
Copy link
Member

chris-oo commented Feb 20, 2025

Querying these debug registers via hypercall is expensive on this exit. We should not do the hypercall if not required. I think they're shared registers between L1 and L2, but need to confirm via spec / only do this if gdb-stub is enabled?

Specifically this call:

fn debug_regs(&mut self) -> Result<vp::DebugRegisters, Self::Error> {
        let mut values = [0u64.into(); 5];
        self.vp
            .runner
            .get_vp_registers(
                self.vtl,
&[
                    HvX64RegisterName::Dr0,
                    HvX64RegisterName::Dr1,
                    HvX64RegisterName::Dr2,
                    HvX64RegisterName::Dr3,
                    HvX64RegisterName::Dr6,
                ],
&mut values,
            )
            .map_err(vp_state::Error::GetRegisters)?;
@chris-oo chris-oo added the tdx TDX specific bugs or features label Feb 20, 2025
@chris-oo chris-oo self-assigned this Feb 20, 2025
@smalis-msft
Copy link
Contributor

smalis-msft commented Feb 20, 2025

Dr0-3 should be marked as vtl-shared already, and so should be going to the kernel. Dr6 wasn't marked shared until just the other day, but it should be going through the kernel on tdx now too. See is_kernel_managed and is_vtl_shared_reg

@chris-oo
Copy link
Member Author

Interesting, it must have been dr6 that was causing the hypercall. I've asked Niranjan to retest to confirm with latest main.

@jstarks
Copy link
Member

jstarks commented Feb 20, 2025

Structurally, do we need to fix the kernel to never use a hypercall for CVMs? This seems like a possible security issue.

@chris-oo
Copy link
Member Author

I'm not even sure the hypervisor can set anything unless the hardware debug flag is set for the TD, right? Otherwise the hypervisor shouldn't be able to mess with any state?

@jstarks
Copy link
Member

jstarks commented Feb 20, 2025

My concern is that we have paths that will call into the hypervisor to access random registers. Whether the hypervisor can actually do anything on writes, it can return arbitrary data for reads.

We should never be querying lower VTL registers from the hypervisor with CVM. That code should be blocked.

@chris-oo
Copy link
Member Author

That's true. We should probably make that change, i'll file it as a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tdx TDX specific bugs or features
Projects
None yet
Development

No branches or pull requests

3 participants