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

Add hypervisor field to IgvmParamBlock #609

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jxu023
Copy link

@jxu023 jxu023 commented Feb 7, 2025

This PR intends to suppress interrupts on Vanadium, and also enable the use of TestDev on Vanadium. To do this, it also disambiguates the IgvmParamBlock.is_qemu field as described in #608

Jacob Xu added 2 commits February 6, 2025 06:10
The is_qemu field in IgvmParamBlock as used right now has two meanings.
One is that we can assume access to qemu fw services such as TestDev as
checked by is_qemu_test_env(). The other meaning is that we're running
on top of qemu as checked in stage2 for determining
suppress_svsm_interrupts.

We'd like to suppress_svsm_interrupts for Vanadium and may want to
toggle enabling/disabling options separately per hypervisor, so let's
add a more generic hypervisor field to IgvmParamBlock to check in
general. Then we can leave the is_qemu field to only signify
accessibility to qemu_fw_services.

A hypervisor enum already exists in
igvmbuilder::cmd_options::Hypervisor. Unfortunately this is not directly
usable in bootlib::igvm_params::IgvmParamBlock for two reasons. One is
that bootlib is a dependency of igvmbuilder, this could be moved if not
for reason two which is that the clap parser derivations used by
CmdOptions don't support no_std which bootlib is built for. Thus it
seems simplest to create a second enum type and convert between the two.

Having disambiguated the is_qemu field, we then set is_qemu to true for
Vanadium to ensure that all the tests making use of TestDev will also
run for Vanadium. Since interrupts aren't yet support in Vanadium, we
also set suppress_svsm_interrupts to accordingly.

Signed-off-by: Jacob Xu <jacobhxu@google.com>
Now that there's a hypervisor field in IgvmParamBlock, let's rename
is_qemu to reduce ambiguity.

Signed-off-by: Jacob Xu <jacobhxu@google.com>
@jxu023 jxu023 changed the title Two enums Add hypervisor field to IgvmParamBlock Feb 7, 2025
@AdamCDunlap
Copy link
Contributor

has_qemu_fw_services is still too generic for us. The "qemu fw sevices" come from both the pc-testdev device (installed in scripts/launch-guest.sh) and some code in the scripts/test-in-svsm.sh file. Vanadium supports a device similar to pc-testdev, but not the IORequests from the script. I think it'd make sense to split up the "qemu fw services" into 2 different flags.

I'm also a bit confused about having both the hypervisor enum and a boolean (qemu fw services) that solely depends on the enum. IMO it'd be better to have a bunch of booleans in the IgvmParamBlock that specify behavior rather than the hypervisor enum. So in that case we'd have "has_qemu_testdev", "has_test_iorequests", and "suppress_svsm_interrupts". Igvmbuilder would specify which of these to set based on the hypervisor.

@jxu023
Copy link
Author

jxu023 commented Feb 7, 2025

For suppress_svsm_interrupts, it's currently conditioned on both SNP and the hypervisor. Since IGVM is arch-agnostic for snp/tdx, it seems the determination of this may be necessary to do at runtime instead of igvm build time.

I'm also a bit confused about having both the hypervisor enum and a boolean (qemu fw services) that solely depends on the enum.

Perhaps it's better to remove the qemu_fw_services/is_qemu field entirely from IgvmParamsBlock then and just make do with the hypervisor field? Then we can make those checks based on hypervisor.

@AdamCDunlap
Copy link
Contributor

For suppress_svsm_interrupts, it's currently conditioned on both SNP and the hypervisor. Since IGVM is arch-agnostic for snp/tdx, it seems the determination of this may be necessary to do at runtime instead of igvm build time.

Name it supress_svsm_interrupts_on_snp?

Then we can make those checks based on hypervisor.

That would be better than having both, but IMO individual bools are more "morally correct" than a hypervisor enum. The idea should be that the IGVM could boot on any hypervisor even if practically there are different requirements from each hypervisor.

@jxu023
Copy link
Author

jxu023 commented Feb 7, 2025

The idea should be that the IGVM could boot on any hypervisor even if practically there are different requirements from each hypervisor.

Ah I see, that makes sense; I was initially confused since we're building different IGVM files for each hypervisor; but this makes sense if we're moving towards that direction.

I'll write up a separate PR and then close this one.

}
}

pub fn hypervisor(&self) -> bootlib::igvm_params::Hypervisor {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the only definition of Hypervisor that is usable by the kernel environment is the one in bootlib::igvm_params, can we just use bootlib::igvm_params::Hypervisor and avoid the need for explicit namespace decoration here and in other uses?

self.igvm_param_block.has_qemu_fw_services != 0
}

pub fn hypervisor(&self) -> bootlib::igvm_params::Hypervisor {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Above comment about use bootlib::igvm_params::Hypervisor applies here as well.

// This is required when running SNP under KVM/QEMU.
let suppress_svsm_interrupts = match platform_type {
SvsmPlatformType::Snp => config.is_qemu(),
SvsmPlatformType::Snp => {
config.hypervisor() == Hypervisor::Vanadium || config.hypervisor() == Hypervisor::Qemu
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we define a method like SvsmConfig::can_use_svsm_interrupts so that all of the per-hypervisor logic can exist in the config object instead of having decisions leak out to other places like this one?

@msft-jlange msft-jlange added the in-review PR is under active review and not yet approved label Feb 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in-review PR is under active review and not yet approved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants