Commit Graph

164 Commits

Author SHA1 Message Date
Rob Bradford
7c3110e6d5 arch: x86_64: Use host cpuid information for L2 cache for older KVM
If the KVM version is too old (pre Linux 5.7) then fetch the CPUID
information from the host and use that in the guest. We prefer the KVM
version over the host version as that would use the CPUID for the
running CPU vs the CPU that runs this code which might be different due
to a hybrid topology.

Fixes: #4918

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2022-11-22 09:32:30 +01:00
Wei Liu
f16b57716d arch: modify or add safety comments
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2022-11-18 12:50:01 +00:00
Praveen K Paladugu
59baa29deb arch: Add TPM Address ranges to layouts
Add TPM's CRB Interface specific address ranges to layouts

Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
Co-authored-by: Sean Yoo <t-seanyoo@microsoft.com>
2022-11-15 16:42:21 +00:00
Bo Chen
a9ec0f33c0 misc: Fix clippy issues
Signed-off-by: Bo Chen <chen.bo@intel.com>
2022-11-02 09:41:43 +01:00
Rob Bradford
f32487f8e8 misc: Automatic beta clippy fixes
e.g. cargo clippy --all --tests --all-targets --fix --features=..

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2022-09-20 10:59:48 +01:00
Wei Liu
62f1b6bc61 arch: change typ to r#type in SMBIOS code
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2022-08-08 08:59:19 +01:00
Wei Liu
2afd2f9f52 arch: drop unnecessary pub keywords from code
Those structures are not used outside of smbios.rs.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2022-08-08 08:59:19 +01:00
Wei Liu
57e9b80123 vmm: provide oem_strings option
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2022-08-08 08:59:19 +01:00
Wei Liu
964985bb5c arch: provide OEM strings entry support in SMBIOS
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2022-08-08 08:59:19 +01:00
Wei Liu
cb18edb535 arch: return the correct size for SMBIOS occupied space
The original value didn't include the size of the entry point structure.

The caused the last entry to be corrupted by other code.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2022-08-05 16:34:20 +01:00
Wei Liu
05e0daa411 arch: fix end of table entry in smbios
Previously the code used the SmbiosSysInfo structure for that purpose.

    Handle 0x0003, DMI type 127, 27 bytes
            <TRUNCATED>

    Wrong DMI structures length: 130 bytes announced, structures occupy 131 bytes.

Fix this by using the correct structure and padding.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2022-08-05 16:34:20 +01:00
Wei Liu
a62b611659 arch: improve some structures in smbios code
There is no need to manually implement Clone for some structures.

It is better to explicitly spell out repr(C) to avoid the compiler
reordering the fields.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2022-08-05 16:34:20 +01:00
lizhaoxin1
bc3a276b43 arch, vmm: Expose platform uuid via SMBIOS
Parse and set uuid.

Signed-off-by: lizhaoxin1 <Lxiaoyouling@163.com>
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2022-08-04 09:20:06 +02:00
Wei Liu
ff7773044c tree-wide: drop some unneeded allow clauses
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2022-07-22 14:37:03 +01:00
Wei Liu
05e5106b9b hypervisor x86: provide a generic LapicState structure
This requires making get/set_lapic_reg part of the type.

For the moment we cannot provide a default variant for the new type,
because picking one will be wrong for the other hypervisor, so I just
drop the test cases that requires LapicState::default().

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2022-07-19 09:38:38 +01:00
Wei Liu
6a8c0fc887 hypervisor: provide a generic FpuState structure
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2022-07-18 22:15:30 +01:00
Wei Liu
08135fa085 hypervisor: provide a generic CpudIdEntry structure
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2022-07-18 22:15:30 +01:00
Wei Liu
45fbf840db hypervisor, vmm: move away from CpuId type
CpuId is an alias type for the flexible array structure type over
CpuIdEntry. The type itself and the type of the element in the array
portion are tied to the underlying hypervisor.

Switch to using CpuIdEntry slice or vector directly. The construction of
CpuId type is left to hypervisors.

This allows us to decouple CpuIdEntry from hypervisors more easily.

No functional change intended.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2022-07-18 22:15:30 +01:00
Wei Liu
f1ab86fecb hypervisor: x86: provide a generic SpecialRegisters structure
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2022-07-15 10:21:43 +01:00
Wei Liu
75797827d5 hypervisor: x86: provide a generic SegmentRegister structure
And drop SegmentRegisterOps since it is no longer required.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2022-07-15 10:21:43 +01:00
Wei Liu
8b7781e267 hypervisor: x86: provide a generic StandardRegisters structure
We only need to do this for x86 since MSHV does not have aarch64 support
yet. This reduces unnecessary code churn.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2022-07-15 10:21:43 +01:00
Wei Liu
84bbaf06d1 hypervisor: turn boot_msr_entries into a trait method
This allows dispatching to either KVM or MSHV automatically.

No functional change.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2022-07-08 16:49:58 +01:00
Rob Bradford
12f11b5619 arch: x86_64: Remove glob import from hypervisor regs module
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2022-05-13 15:39:22 +02:00
Rob Bradford
2caf5e3b2b arch: Use more descriptive name for hypervisor::Vcpu than fd
This variable name is residual from when these functions acted directly
on the vCPU fd rather than the hypervisor wrapper.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2022-05-13 15:39:22 +02:00
Rob Bradford
cd0df05808 vmm, arch: CpuId is x86_64 specific so import from the x86_64 module
It will be removed as a top-level export from the hypervisor crate.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2022-05-13 15:39:22 +02:00
Rob Bradford
47529796d0 arch: Improve arch::Error
Remove unused error enum entries, improve wording and derive
thiserror::Error.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2022-04-22 17:46:41 +01:00
Rob Bradford
e972eb7c74 arch, vmm: Expose platform serial_number via SMBIOS
Fixes: #4002

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2022-04-21 17:17:08 +02:00
Sebastien Boeuf
dae77d8d43 arch: x86_64: tdx: Update EFI HOB attribute
Based on latest QEMU patches from branch tdx-qemu-2022.03.29-v7.0.0-rc1
we don't need EFI_RESOURCE_ATTRIBUTE_ENCRYPTED as part of the attributes
we must enable with EFI_RESOURCE_SYSTEM_MEMORY and
EFI_RESOURCE_MEMORY_RESERVED resource types.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2022-04-01 18:24:32 +01:00
Sebastien Boeuf
db06c31305 arch: x86_64: Patch CPUID based on TDX capabilities
Based on the XFAM masks retrieved from the TDX capabilities, the CPUID
must be patched.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2022-03-30 14:57:23 +01:00
Rob Bradford
64b32841a3 arch: x86_64: Write EBDA address to BIOS data area
This allows ACPICA to find the EBDA and load the ACPI tables when
scanning for them.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2022-03-09 15:47:01 +01:00
Sebastien Boeuf
2f0073544a arch: x86_64: tdx: Add a payload helper to TdHob
Adding a new method to the TdHob structure so that we can easily insert
a HOB_PAYLOAD_INFO_TABLE into the HOB.

Signed-off-by: Jiaqi Gao <jiaqi.gao@intel.com>
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2022-02-04 13:57:56 +01:00
Sebastien Boeuf
2198baa547 arch: x86_64: tdx: Extend TDVF section types
Based on the recent updates of the TDVF specification introducing new
types of TDVF sections, let's extend the enum in our code.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2022-02-04 13:57:56 +01:00
Sebastien Boeuf
2acb50f752 arch: x86_64: tdx: Add ACPI table helper to TdHob
Adding a new method to the TdHob structure so that we can easily insert
a ACPI_TABLE_HOB into the HOB.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2022-01-20 16:50:55 +00:00
Sebastien Boeuf
4fda4ad6c9 arch, vmm: tdx: Remove TD_VMM_DATA mechanism
It's been decided the ACPI tables will be passed to the firmware in a
different way, rather than using TD_VMM_DATA. Since TD_VMM_DATA was
introduced for this purpose, there's no reason to keep it in our
codebase.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2022-01-20 16:50:55 +00:00
Rob Bradford
3baebc1af0 arch: x86_64: Fix clippy (needless_late_init) issue
warning: unneeded late initalization
   --> arch/src/x86_64/mod.rs:318:17
    |
318 |                 let reg_val: u32;
    |                 ^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(clippy::needless_late_init)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_late_init
help: declare `reg_val` here
    |
319 |                 let reg_val: u32 = match reg {
    |                 ++++++++++++++++++
help: remove the assignments from the `match` arms
    |
321 ~                         entry.eax
322 |                     }
323 |                     CpuidReg::EBX => {
324 ~                         entry.ebx
325 |                     }
326 |                     CpuidReg::ECX => {
  ...
help: add a semicolon after the `match` expression
    |
332 |                 };
    |                  +

warning: unneeded late initalization
   --> arch/src/x86_64/mod.rs:525:13
    |
525 |             let entry_compatible;
    |             ^^^^^^^^^^^^^^^^^^^^^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_late_init
help: declare `entry_compatible` here
    |
526 |             let entry_compatible = match entry.compatible_check {
    |             ++++++++++++++++++++++
help: remove the assignments from the `match` arms
    |
530 ~                     src_vm_feature_bits_only == 0
531 |                 }
532 |                 CpuidCompatibleCheck::Equal => {
533 ~                     src_vm_feature == dest_vm_feature
534 |                 }
535 |                 CpuidCompatibleCheck::NumNotGreater => {

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2022-01-07 08:16:26 -08:00
Henry Wang
2f8540da70 vmm: Rename PCI_MMIO_CONFIG_SIZE and move it to arch
The constant `PCI_MMIO_CONFIG_SIZE` defined in `vmm/pci_segment.rs`
describes the MMIO configuation size for each PCI segment. However,
this name conflicts with the `PCI_MMCONFIG_SIZE` defined in `layout.rs`
in the `arch` crate, which describes the memory size of the PCI MMIO
configuration region.

Therefore, this commit renames the `PCI_MMIO_CONFIG_SIZE` to
`PCI_MMIO_CONFIG_SIZE_PER_SEGMENT` and moves this constant from `vmm`
crate to `arch` crate.

Signed-off-by: Henry Wang <Henry.Wang@arm.com>
2021-12-06 09:29:49 +00:00
Sebastien Boeuf
03a606c7ec arch, vmm: Place KVM identity map region after TSS region
In order to avoid the identity map region to conflict with a possible
firmware being placed in the last 4MiB of the 4GiB range, we must set
the address to a chosen location. And it makes the most sense to have
this region placed right after the TSS region.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-12-04 19:33:34 +00:00
Rob Bradford
348def9dfb arch, hypervisor, vmm: Explicitly place the TSS in the 32-bit space
Place the 3 page TSS at an explicit location in the 32-bit address space
to avoid conflicting with the loaded raw firmware.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-12-03 16:53:56 +01:00
Rob Bradford
4f4eb3f6b8 arch: x86_64: Only reserve used 32-bit address space
Reduce the size of the reserved 32-bit address space to the range used
by both the PCI MMIO config data and the 32-bit PCI device space.

This avoids issues when using firmware that is loaded into the very top
of the 32-bit address space as the RAM conflicts with the reserved
memory.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-12-02 16:42:01 +01:00
Rob Bradford
82d06c0efa vmm: Add support for booting raw binary (e.g. firmware) on x86-64
If the provided binary isn't an ELF binary assume that it is a firmware
to be loaded in directly. In this case we shouldn't program any of the
registers as KVM starts in that state.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
2021-11-30 13:39:36 +01:00
Wei Liu
03862314eb arch: x86_64: add safety comments for impl ByteValued
Group impl clauses together to avoid repetition.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2021-11-17 14:40:51 +00:00
Wei Liu
5813ce0307 arch: x86_64: drop test_apic_delivery_mode
This test generates an array of random numbers and then applies the same
trivial algorithm twice -- once in set_apic_delivery_mode and another
time in an anonymous function.

Its usefulness is limited. Drop it to remove one unsafe in code.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2021-11-16 13:49:36 +00:00
Wei Liu
a4d8616676 arch: x86_64: tdx: drop one unsafe call in code
Implement Default trait for TdvfDescriptor and drop one unsafe in code.

No functional change.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2021-11-10 17:46:21 +01:00
Sebastien Boeuf
84a741a3fa arch: x86_64: tdx: Add TD_VMM_DATA support
Adding the definitions and helpers to build TD_VMM_DATA regions as part
of the TD_HOB.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-09-30 06:35:55 -07:00
Bo Chen
2723995cfa arch: Support fine-grained CPUID compatibility check
To support different CPUID entry semantics, we now allow to
specify the compatible condition for each feature entry. Most entries
are considered compatible when they are "bitwise subset", with few
exceptions: 1. "equal", e.g. EBX/ECX/EDX of leaf `0x4000_0000` (KVM
CPUID SIGNATURE); 2. "smaller or equal as a number", e.g. EAX of leaf
`0x7` and leaf `0x4000_0000`;

Signed-off-by: Bo Chen <chen.bo@intel.com>
2021-07-28 09:26:02 +02:00
Bo Chen
6d9c1eb638 arch, vmm: Add CPUID check to the 'Config' step of live migration
We now send not only the 'VmConfig' at the 'Command::Config' step of
live migration, but also send the 'common CPUID'. In this way, we can
check the compatibility of CPUID features between the source and
destination VMs, and abort live migration early if needed.

Signed-off-by: Bo Chen <chen.bo@intel.com>
2021-07-28 09:26:02 +02:00
Bo Chen
569be6e706 arch, vmm: Move "generate_common_cpuid" from "CpuManager" to "arch"
This refactoring ensures all CPUID related operations are centralized in
`arch::x86_64` module, and exposes only two related public functions to
the vmm crate, e.g. `generate_common_cpuid` and `configure_vcpu`.

Signed-off-by: Bo Chen <chen.bo@intel.com>
2021-07-19 09:59:34 -07:00
Sebastien Boeuf
7f507dd77d arch: x86_64: tdx: Fix HobHandoffInfoTable
The handoff table was missing the boot_mode field.

Suggested-by: Jiaqi Gao <jiaqi.gao@intel.com>
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-07-09 14:56:28 -07:00
Sebastien Boeuf
9aedabe11e sgx: Add mandatory id field to SgxEpcConfig
In order to uniquely identify each SGX EPC section, we introduce a
mandatory option `id` to the `--sgx-epc` parameter.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-07-09 14:45:30 +02:00
Sebastien Boeuf
5b6d424a77 arch, vmm: Fix TDVF section handling
This patch fixes a few things to support TDVF correctly.

The HOB memory resources must contain EFI_RESOURCE_ATTRIBUTE_ENCRYPTED
attribute.

Any section with a base address within the already allocated guest RAM
must not be allocated.

The list of TD_HOB memory resources should contain both TempMem and
TdHob sections as well.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-07-06 11:47:43 +02:00