[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3 14/70] target/i386: Implement mc->kvm_type() to get VM typ
From: |
Daniel P . Berrangé |
Subject: |
Re: [PATCH v3 14/70] target/i386: Implement mc->kvm_type() to get VM type |
Date: |
Wed, 15 Nov 2023 10:49:47 +0000 |
User-agent: |
Mutt/2.2.10 (2023-03-25) |
On Wed, Nov 15, 2023 at 02:14:23AM -0500, Xiaoyao Li wrote:
> Implement mc->kvm_type() for i386 machines. It provides a way for user
> to create SW_PROTECTE_VM.
Small typo there missing final 'D' in 'PROTECTED'
>
> Also store the vm_type in machinestate to other code to query what the
> VM type is.
>
> Signed-off-by: Xiaoyao Li <xiaoyao.li@intel.com>
> ---
> hw/i386/x86.c | 12 ++++++++++++
> include/hw/i386/x86.h | 1 +
> target/i386/kvm/kvm.c | 25 +++++++++++++++++++++++++
> target/i386/kvm/kvm_i386.h | 1 +
> 4 files changed, 39 insertions(+)
>
> diff --git a/hw/i386/x86.c b/hw/i386/x86.c
> index b3d054889bba..55678279bf3b 100644
> --- a/hw/i386/x86.c
> +++ b/hw/i386/x86.c
> @@ -1377,6 +1377,17 @@ static void machine_set_sgx_epc(Object *obj, Visitor
> *v, const char *name,
> qapi_free_SgxEPCList(list);
> }
>
> +static int x86_kvm_type(MachineState *ms, const char *vm_type)
> +{
> + X86MachineState *x86ms = X86_MACHINE(ms);
> + int kvm_type;
> +
> + kvm_type = kvm_get_vm_type(ms, vm_type);
> + x86ms->vm_type = kvm_type;
> +
> + return kvm_type;
> +}
> +
> static void x86_machine_initfn(Object *obj)
> {
> X86MachineState *x86ms = X86_MACHINE(obj);
> @@ -1401,6 +1412,7 @@ static void x86_machine_class_init(ObjectClass *oc,
> void *data)
> mc->cpu_index_to_instance_props = x86_cpu_index_to_props;
> mc->get_default_cpu_node_id = x86_get_default_cpu_node_id;
> mc->possible_cpu_arch_ids = x86_possible_cpu_arch_ids;
> + mc->kvm_type = x86_kvm_type;
> x86mc->save_tsc_khz = true;
> x86mc->fwcfg_dma_enabled = true;
> nc->nmi_monitor_handler = x86_nmi;
> diff --git a/include/hw/i386/x86.h b/include/hw/i386/x86.h
> index da19ae15463a..ab1d38569019 100644
> --- a/include/hw/i386/x86.h
> +++ b/include/hw/i386/x86.h
> @@ -41,6 +41,7 @@ struct X86MachineState {
> MachineState parent;
>
> /*< public >*/
> + unsigned int vm_type;
>
> /* Pointers to devices and objects: */
> ISADevice *rtc;
> diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c
> index b4b9ce89842f..2e47fda25f95 100644
> --- a/target/i386/kvm/kvm.c
> +++ b/target/i386/kvm/kvm.c
> @@ -161,6 +161,31 @@ static KVMMSRHandlers
> msr_handlers[KVM_MSR_FILTER_MAX_RANGES];
> static RateLimit bus_lock_ratelimit_ctrl;
> static int kvm_get_one_msr(X86CPU *cpu, int index, uint64_t *value);
>
> +static const char* vm_type_name[] = {
nitpick 'char *vm_type_name[]', is normal style
> + [KVM_X86_DEFAULT_VM] = "default",
> + [KVM_X86_SW_PROTECTED_VM] = "sw-protected-vm",
> +};
> +
> +int kvm_get_vm_type(MachineState *ms, const char *vm_type)
> +{
> + int kvm_type = KVM_X86_DEFAULT_VM;
> +
> + /*
> + * old KVM doesn't support KVM_CAP_VM_TYPES and KVM_X86_DEFAULT_VM
> + * is always supported
> + */
> + if (kvm_type == KVM_X86_DEFAULT_VM) {
> + return kvm_type;
> + }
> +
> + if (!(kvm_check_extension(KVM_STATE(ms->accelerator), KVM_CAP_VM_TYPES)
> & BIT(kvm_type))) {
> + error_report("vm-type %s not supported by KVM",
> vm_type_name[kvm_type]);
> + exit(1);
> + }
> +
> + return kvm_type;
> +}
> +
> bool kvm_has_smm(void)
> {
> return kvm_vm_check_extension(kvm_state, KVM_CAP_X86_SMM);
> diff --git a/target/i386/kvm/kvm_i386.h b/target/i386/kvm/kvm_i386.h
> index 30fedcffea3e..55fb25fa8e2e 100644
> --- a/target/i386/kvm/kvm_i386.h
> +++ b/target/i386/kvm/kvm_i386.h
> @@ -37,6 +37,7 @@ bool kvm_hv_vpindex_settable(void);
> bool kvm_enable_sgx_provisioning(KVMState *s);
> bool kvm_hyperv_expand_features(X86CPU *cpu, Error **errp);
>
> +int kvm_get_vm_type(MachineState *ms, const char *vm_type);
> void kvm_arch_reset_vcpu(X86CPU *cs);
> void kvm_arch_after_reset_vcpu(X86CPU *cpu);
> void kvm_arch_do_init_vcpu(X86CPU *cs);
> --
> 2.34.1
>
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
- Re: [PATCH v3 06/70] kvm: Introduce support for memory_attributes, (continued)
- [PATCH v3 08/70] physmem: replace function name with __func__ in ram_block_discard_range(), Xiaoyao Li, 2023/11/15
- [PATCH v3 10/70] kvm: handle KVM_EXIT_MEMORY_FAULT, Xiaoyao Li, 2023/11/15
- [PATCH v3 12/70] *** HACK *** linux-headers: Update headers to pull in TDX API changes, Xiaoyao Li, 2023/11/15
- [PATCH v3 13/70] i386: Introduce tdx-guest object, Xiaoyao Li, 2023/11/15
- [PATCH v3 14/70] target/i386: Implement mc->kvm_type() to get VM type, Xiaoyao Li, 2023/11/15
- Re: [PATCH v3 14/70] target/i386: Implement mc->kvm_type() to get VM type,
Daniel P . Berrangé <=
- [PATCH v3 15/70] target/i386: Parse TDX vm type, Xiaoyao Li, 2023/11/15
- [PATCH v3 11/70] trace/kvm: Add trace for page convertion between shared and private, Xiaoyao Li, 2023/11/15
- [PATCH v3 16/70] target/i386: Introduce kvm_confidential_guest_init(), Xiaoyao Li, 2023/11/15
- [PATCH v3 17/70] i386/tdx: Implement tdx_kvm_init() to initialize TDX VM context, Xiaoyao Li, 2023/11/15
- [PATCH v3 18/70] i386/tdx: Get tdx_capabilities via KVM_TDX_CAPABILITIES, Xiaoyao Li, 2023/11/15
- [PATCH v3 19/70] i386/tdx: Introduce is_tdx_vm() helper and cache tdx_guest object, Xiaoyao Li, 2023/11/15