accel/kvm: Simplify few functions that can use global kvm_state
cover accel/kvm: Simplify few functions that can use global kvm_state
Following Paolo's idea on kvm_check_extension():
https://www.mail-archive.com/[email protected]/msg713794.html
CI:
https://travis-ci.org/github/philmd/qemu/builds/701213438
Philippe Mathieu-Daudé (7):
accel/kvm: Let kvm_check_extension use global KVM state accel/kvm: Simplify kvm_check_extension() accel/kvm: Simplify kvm_check_extension_list() accel/kvm: Simplify kvm_set_sigmask_len() target/i386/kvm: Simplify get_para_features() target/i386/kvm: Simplify kvm_get_mce_cap_supported() target/i386/kvm: Simplify kvm_get_supported_[feature]_msrs()
include/sysemu/kvm.h | 4 +- accel/kvm/kvm-all.c | 76 +++++++++++++++---------------- hw/hyperv/hyperv.c | 2 +- hw/i386/kvm/clock.c | 2 +- hw/i386/kvm/i8254.c | 4 +- hw/i386/kvm/ioapic.c | 2 +- hw/intc/arm_gic_kvm.c | 2 +- hw/intc/openpic_kvm.c | 2 +- hw/intc/xics_kvm.c | 2 +- hw/s390x/s390-stattrib-kvm.c | 2 +- target/arm/kvm.c | 13 +++--- target/arm/kvm32.c | 2 +- target/arm/kvm64.c | 15 +++--- target/i386/kvm.c | 88 +++++++++++++++++------------------- target/mips/kvm.c | 6 +-- target/ppc/kvm.c | 34 +++++++------- target/s390x/cpu_models.c | 3 +- target/s390x/kvm.c | 30 ++++++------ 18 files changed, 141 insertions(+), 148 deletions(-)
Signature · 1 line
2.21.3
PATCH 1/7 accel/kvm: Let kvm_check_extension use global KVM state
As KVM supported extentions those should be the same for all VMs, it is safe to directly use the global kvm_state in kvm_check_extension().
--- accel/kvm/kvm-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
accel/kvm/kvm-all.c +1 -1
@@ -913,7 +913,7 @@ int kvm_check_extension(KVMState *s, unsigned int extension) {int ret; - ret =kvm_ioctl (s,KVM_CHECK_EXTENSION , extension); + ret =kvm_ioctl (kvm_state,KVM_CHECK_EXTENSION , extension);if (ret <0 ) { ret =0 ; }
Signature · 1 line
2.21.3
Re: [PATCH 1/7] accel/kvm: Let kvm_check_extension use global KVM state
Quoted 15 lines · On Tue, 23 Jun 2020 12:50:46 +0200 Philippe Mathieu-Daudé <[email protected]>…
As KVM supported extentions those should be the same for all VMs, it is safe to directly use the global
kvm_stateinkvm_check_extension().Suggested-by Paolo Bonzini <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- accel/kvm/kvm-all.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)accel/kvm/kvm-all.c +0
-0
accel/kvm/kvm-all.c int kvm_check_extension(KVMState *s, unsigned int extension) · line 919
Quoted 8 lines
accel/kvm/kvm-all.c +1
-1@@ -913,7 +913,7 @@ int kvm_check_extension(KVMState *s, unsigned int extension) {int ret; - ret =kvm_ioctl (s,KVM_CHECK_EXTENSION , extension); + ret =kvm_ioctl (kvm_state,KVM_CHECK_EXTENSION , extension);if (ret <0 ) { ret =0 ; }
PATCH 2/7 accel/kvm: Simplify kvm_check_extension()
In reply to Philippe Mathieu-DaudéIn previous commit we let kvm_check_extension() use the global kvm_state. Since the KVMState* argument is now unused, drop it.
Convert callers with this Coccinelle script:
@@
expression kvm_state, extension;
@@
- kvm_check_extension(kvm_state, extension)
+ kvm_check_extension(extension)
Unused variables manually removed:
- CPUState* in hyperv_enabled()
- KVMState* in kvm_arm_get_max_vm_ipa_size()
--- include/sysemu/kvm.h | 2 +- accel/kvm/kvm-all.c | 64 ++++++++++++++++++------------------ hw/hyperv/hyperv.c | 2 +- hw/i386/kvm/clock.c | 2 +- hw/i386/kvm/i8254.c | 4 +-- hw/i386/kvm/ioapic.c | 2 +- hw/intc/arm_gic_kvm.c | 2 +- hw/intc/openpic_kvm.c | 2 +- hw/intc/xics_kvm.c | 2 +- hw/s390x/s390-stattrib-kvm.c | 2 +- target/arm/kvm.c | 13 ++++---- target/arm/kvm32.c | 2 +- target/arm/kvm64.c | 15 ++++----- target/i386/kvm.c | 61 ++++++++++++++++------------------ target/mips/kvm.c | 4 +-- target/ppc/kvm.c | 34 +++++++++---------- target/s390x/cpu_models.c | 3 +- target/s390x/kvm.c | 30 ++++++++--------- 18 files changed, 119 insertions(+), 127 deletions(-)
include/sysemu/kvm.h +1 -1
@@ -436,7 +436,7 @@ void kvm_arch_update_guest_debug(CPUState *cpu, struct kvm_guest_debug *dbg);bool kvm_arch_stop_on_emulation_error (CPUState *cpu); -int kvm_check_extension (KVMState *s,unsigned int extension); +int kvm_check_extension (unsigned int extension);int kvm_vm_check_extension (KVMState *s,unsigned int extension);
accel/kvm/kvm-all.c +32 -32
190 lines not on this page · raw message
hw/hyperv/hyperv.c +1 -1
@@ -605,7 +605,7 @@ static bool process_event_flags_userspace;int hyperv_set_event_flag_handler (uint32_t conn_id,EventNotifier *notifier) {if (!process_event_flags_userspace && - !kvm_check_extension (kvm_state,KVM_CAP_HYPERV_EVENTFD )) { + !kvm_check_extension (KVM_CAP_HYPERV_EVENTFD )) { process_event_flags_userspace = true; warn_report("Hyper-V event signaling is not supported by this kernel; "
hw/i386/kvm/clock.c +1 -1
@@ -166,7 +166,7 @@ static void kvmclock_vm_state_change(void *opaque, int running, {KVMClockState *s = opaque;CPUState *cpu; -int cap_clock_ctrl =kvm_check_extension (kvm_state,KVM_CAP_KVMCLOCK_CTRL ); +int cap_clock_ctrl =kvm_check_extension (KVM_CAP_KVMCLOCK_CTRL );int ret;if (running) {
hw/i386/kvm/i8254.c +2 -2
@@ -264,7 +264,7 @@ static void kvm_pit_realizefn(DeviceState *dev, Error **errp) };int ret; -if (kvm_check_extension (kvm_state,KVM_CAP_PIT2 )) { +if (kvm_check_extension (KVM_CAP_PIT2 )) { ret =kvm_vm_ioctl (kvm_state,KVM_CREATE_PIT2 , &config); }else { ret =kvm_vm_ioctl (kvm_state,KVM_CREATE_PIT );
@@ -278,7 +278,7 @@ static void kvm_pit_realizefn(DeviceState *dev, Error **errp)case LOST_TICK_POLICY_DELAY :break ;/* enabled by default */ case LOST_TICK_POLICY_DISCARD : -if (kvm_check_extension (kvm_state,KVM_CAP_REINJECT_CONTROL )) { +if (kvm_check_extension (KVM_CAP_REINJECT_CONTROL )) {struct kvm_reinject_control control = { .pit_reinject =0 }; ret =kvm_vm_ioctl (kvm_state,KVM_REINJECT_CONTROL , &control);
hw/i386/kvm/ioapic.c +1 -1
@@ -25,7 +25,7 @@ void kvm_pc_setup_irq_routing(bool pci_enabled)KVMState *s = kvm_state;int i; -if (kvm_check_extension (s,KVM_CAP_IRQ_ROUTING )) { +if (kvm_check_extension (KVM_CAP_IRQ_ROUTING )) {for (i =0 ; i <8 ; ++i) {if (i ==2 ) {continue ;
hw/intc/arm_gic_kvm.c +1 -1
@@ -551,7 +551,7 @@ static void kvm_arm_gic_realize(DeviceState *dev, Error **errp)KVM_DEV_ARM_VGIC_CTRL_INIT ,NULL , true, &error_abort); } - }else if (kvm_check_extension (kvm_state,KVM_CAP_DEVICE_CTRL )) { + }else if (kvm_check_extension (KVM_CAP_DEVICE_CTRL )) {error_setg_errno (errp, -ret,"error creating in-kernel VGIC" );error_append_hint (errp,"Perhaps the host CPU does not support GICv2?\n" );
hw/intc/openpic_kvm.c +1 -1
@@ -203,7 +203,7 @@ static void kvm_openpic_realize(DeviceState *dev, Error **errp)struct kvm_create_device cd = {0 };int ret, i; -if (!kvm_check_extension (s,KVM_CAP_DEVICE_CTRL )) { +if (!kvm_check_extension (KVM_CAP_DEVICE_CTRL )) {error_setg (errp,"Kernel is lacking Device Control API" );return ; }
hw/intc/xics_kvm.c +1 -1
@@ -365,7 +365,7 @@ int xics_kvm_connect(SpaprInterruptController *intc, uint32_t nr_servers,return 0 ; } -if (!kvm_enabled () || !kvm_check_extension (kvm_state,KVM_CAP_IRQ_XICS )) { +if (!kvm_enabled () || !kvm_check_extension (KVM_CAP_IRQ_XICS )) {error_setg (errp,"KVM and IRQ_XICS capability must be present for in-kernel XICS" );return -1 ;
hw/s390x/s390-stattrib-kvm.c +1 -1
@@ -22,7 +22,7 @@Object *kvm_s390_stattrib_create (void ) {if (kvm_enabled () && -kvm_check_extension (kvm_state,KVM_CAP_S390_CMMA_MIGRATION )) { +kvm_check_extension (KVM_CAP_S390_CMMA_MIGRATION )) {return object_new (TYPE_KVM_S390_STATTRIB ); }return NULL ;
target/arm/kvm.c +6 -7
@@ -60,7 +60,7 @@ int kvm_arm_vcpu_finalize(CPUState *cs, int feature)void kvm_arm_init_serror_injection (CPUState *cs) { - cap_has_inject_serror_esr =kvm_check_extension (cs->kvm_state, + cap_has_inject_serror_esr =kvm_check_extension (KVM_CAP_ARM_INJECT_SERROR_ESR ); }
@@ -210,15 +210,14 @@ void kvm_arm_add_vcpu_properties(Object *obj)bool kvm_arm_pmu_supported (void ) { -return kvm_check_extension (kvm_state,KVM_CAP_ARM_PMU_V3 ); +return kvm_check_extension (KVM_CAP_ARM_PMU_V3 ); }int kvm_arm_get_max_vm_ipa_size (MachineState *ms) { -KVMState *s =KVM_STATE (ms->accelerator);int ret; - ret =kvm_check_extension (s,KVM_CAP_ARM_VM_IPA_SIZE ); + ret =kvm_check_extension (KVM_CAP_ARM_VM_IPA_SIZE );return ret >0 ? ret :40 ; }
@@ -236,10 +235,10 @@ int kvm_arch_init(MachineState *ms, KVMState *s)*/ kvm_halt_in_kernel_allowed = true; - cap_has_mp_state =kvm_check_extension (s,KVM_CAP_MP_STATE ); + cap_has_mp_state =kvm_check_extension (KVM_CAP_MP_STATE );if (ms->smp.cpus >256 && - !kvm_check_extension (s,KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 )) { + !kvm_check_extension (KVM_CAP_ARM_IRQ_LINE_LAYOUT_2 )) {error_report ("Using more than 256 vcpus requires a host kernel " "with KVM_CAP_ARM_IRQ_LINE_LAYOUT_2" ); ret = -EINVAL ;
@@ -870,7 +869,7 @@ int kvm_arch_irqchip_create(KVMState *s)/* If we can create the VGIC using the newer device control API, we * let the device do this when it initializes itself, otherwise we * fall back to the old API */ -return kvm_check_extension (s,KVM_CAP_DEVICE_CTRL ); +return kvm_check_extension (KVM_CAP_DEVICE_CTRL ); }int kvm_arm_vgic_probe (void )
target/arm/kvm32.c +1 -1
@@ -221,7 +221,7 @@ int kvm_arch_init_vcpu(CPUState *cs)if (cpu->start_powered_off) { cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_POWER_OFF ; } -if (kvm_check_extension (cs->kvm_state,KVM_CAP_ARM_PSCI_0_2 )) { +if (kvm_check_extension (KVM_CAP_ARM_PSCI_0_2 )) { cpu->psci_version =2 ; cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_PSCI_0_2 ; }
target/arm/kvm64.c +7 -8
@@ -84,14 +84,13 @@ GArray *hw_breakpoints, *hw_watchpoints;*/ static void kvm_arm_init_debug (CPUState *cs) { - have_guest_debug =kvm_check_extension (cs->kvm_state, -KVM_CAP_SET_GUEST_DEBUG ); + have_guest_debug =kvm_check_extension (KVM_CAP_SET_GUEST_DEBUG ); - max_hw_wps =kvm_check_extension (cs->kvm_state,KVM_CAP_GUEST_DEBUG_HW_WPS ); + max_hw_wps =kvm_check_extension (KVM_CAP_GUEST_DEBUG_HW_WPS ); hw_watchpoints =g_array_sized_new (true, true,sizeof (HWWatchpoint), max_hw_wps); - max_hw_bps =kvm_check_extension (cs->kvm_state,KVM_CAP_GUEST_DEBUG_HW_BPS ); + max_hw_bps =kvm_check_extension (KVM_CAP_GUEST_DEBUG_HW_BPS ); hw_breakpoints =g_array_sized_new (true, true,sizeof (HWBreakpoint), max_hw_bps);return ;
@@ -654,12 +653,12 @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)bool kvm_arm_aarch32_supported (void ) { -return kvm_check_extension (kvm_state,KVM_CAP_ARM_EL1_32BIT ); +return kvm_check_extension (KVM_CAP_ARM_EL1_32BIT ); }bool kvm_arm_sve_supported (void ) { -return kvm_check_extension (kvm_state,KVM_CAP_ARM_SVE ); +return kvm_check_extension (KVM_CAP_ARM_SVE ); }QEMU_BUILD_BUG_ON (KVM_ARM64_SVE_VQ_MIN !=1 );
@@ -778,14 +777,14 @@ int kvm_arch_init_vcpu(CPUState *cs)if (cpu->start_powered_off) { cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_POWER_OFF ; } -if (kvm_check_extension (cs->kvm_state,KVM_CAP_ARM_PSCI_0_2 )) { +if (kvm_check_extension (KVM_CAP_ARM_PSCI_0_2 )) { cpu->psci_version =2 ; cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_PSCI_0_2 ; }if (!arm_feature (&cpu->env,ARM_FEATURE_AARCH64 )) { cpu->kvm_init_features[0 ] |=1 <<KVM_ARM_VCPU_EL1_32BIT ; } -if (!kvm_check_extension (cs->kvm_state,KVM_CAP_ARM_PMU_V3 )) { +if (!kvm_check_extension (KVM_CAP_ARM_PMU_V3 )) { cpu->has_pmu = false; }if (cpu->has_pmu) {
target/i386/kvm.c +28 -33
200 lines not on this page · raw message
target/mips/kvm.c +2 -2
@@ -50,8 +50,8 @@ int kvm_arch_init(MachineState *ms, KVMState *s)/* MIPS has 128 signals */ kvm_set_sigmask_len (s,16 ); - kvm_mips_fpu_cap =kvm_check_extension (s,KVM_CAP_MIPS_FPU ); - kvm_mips_msa_cap =kvm_check_extension (s,KVM_CAP_MIPS_MSA ); + kvm_mips_fpu_cap =kvm_check_extension (KVM_CAP_MIPS_FPU ); + kvm_mips_msa_cap =kvm_check_extension (KVM_CAP_MIPS_MSA );DPRINTF ("%s\n" , __func__);return 0 ;
target/ppc/kvm.c +17 -17
@@ -110,24 +110,24 @@ static int kvmppc_get_dec_bits(void);int kvm_arch_init (MachineState *ms,KVMState *s) { - cap_interrupt_unset =kvm_check_extension (s,KVM_CAP_PPC_UNSET_IRQ ); - cap_segstate =kvm_check_extension (s,KVM_CAP_PPC_SEGSTATE ); - cap_booke_sregs =kvm_check_extension (s,KVM_CAP_PPC_BOOKE_SREGS ); + cap_interrupt_unset =kvm_check_extension (KVM_CAP_PPC_UNSET_IRQ ); + cap_segstate =kvm_check_extension (KVM_CAP_PPC_SEGSTATE ); + cap_booke_sregs =kvm_check_extension (KVM_CAP_PPC_BOOKE_SREGS ); cap_ppc_smt_possible =kvm_vm_check_extension (s,KVM_CAP_PPC_SMT_POSSIBLE ); - cap_spapr_tce =kvm_check_extension (s,KVM_CAP_SPAPR_TCE ); - cap_spapr_tce_64 =kvm_check_extension (s,KVM_CAP_SPAPR_TCE_64 ); - cap_spapr_multitce =kvm_check_extension (s,KVM_CAP_SPAPR_MULTITCE ); + cap_spapr_tce =kvm_check_extension (KVM_CAP_SPAPR_TCE ); + cap_spapr_tce_64 =kvm_check_extension (KVM_CAP_SPAPR_TCE_64 ); + cap_spapr_multitce =kvm_check_extension (KVM_CAP_SPAPR_MULTITCE ); cap_spapr_vfio =kvm_vm_check_extension (s,KVM_CAP_SPAPR_TCE_VFIO ); - cap_one_reg =kvm_check_extension (s,KVM_CAP_ONE_REG ); - cap_hior =kvm_check_extension (s,KVM_CAP_PPC_HIOR ); - cap_epr =kvm_check_extension (s,KVM_CAP_PPC_EPR ); - cap_ppc_watchdog =kvm_check_extension (s,KVM_CAP_PPC_BOOKE_WATCHDOG ); + cap_one_reg =kvm_check_extension (KVM_CAP_ONE_REG ); + cap_hior =kvm_check_extension (KVM_CAP_PPC_HIOR ); + cap_epr =kvm_check_extension (KVM_CAP_PPC_EPR ); + cap_ppc_watchdog =kvm_check_extension (KVM_CAP_PPC_BOOKE_WATCHDOG );/* * Note: we don't set cap_papr here, because this capability is * only activated after this by kvmppc_set_papr() */ cap_htab_fd =kvm_vm_check_extension (s,KVM_CAP_PPC_HTAB_FD ); - cap_fixup_hcalls =kvm_check_extension (s,KVM_CAP_PPC_FIXUP_HCALL ); + cap_fixup_hcalls =kvm_check_extension (KVM_CAP_PPC_FIXUP_HCALL ); cap_ppc_smt =kvm_vm_check_extension (s,KVM_CAP_PPC_SMT ); cap_htm =kvm_vm_check_extension (s,KVM_CAP_PPC_HTM ); cap_mmu_radix =kvm_vm_check_extension (s,KVM_CAP_PPC_MMU_RADIX );
@@ -147,7 +147,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)*/ cap_ppc_pvr_compat = false; -if (!kvm_check_extension (s,KVM_CAP_PPC_IRQ_LEVEL )) { +if (!kvm_check_extension (KVM_CAP_PPC_IRQ_LEVEL )) {error_report ("KVM: Host kernel doesn't have level irq capability" );exit (1 ); }
@@ -205,7 +205,7 @@ static int kvm_booke206_tlb_init(PowerPCCPU *cpu)int ret, i;if (!kvm_enabled () || - !kvm_check_extension (cs->kvm_state,KVM_CAP_SW_TLB )) { + !kvm_check_extension (KVM_CAP_SW_TLB )) {return 0 ; }
@@ -246,7 +246,7 @@ static void kvm_get_smmu_info(struct kvm_ppc_smmu_info *info, Error **errp)assert (kvm_state !=NULL ); -if (!kvm_check_extension (kvm_state,KVM_CAP_PPC_GET_SMMU_INFO )) { +if (!kvm_check_extension (KVM_CAP_PPC_GET_SMMU_INFO )) {error_setg (errp,"KVM doesn't expose the MMU features it supports" );error_append_hint (errp,"Consider switching to a newer KVM\n" );return ;
@@ -268,7 +268,7 @@ struct ppc_radix_page_info *kvm_get_radix_page_info(void)struct kvm_ppc_rmmu_info rmmu_info;int i; -if (!kvm_check_extension (s,KVM_CAP_PPC_MMU_RADIX )) { +if (!kvm_check_extension (KVM_CAP_PPC_MMU_RADIX )) {return NULL ; }if (kvm_vm_ioctl (s,KVM_PPC_GET_RMMU_INFO , &rmmu_info)) {
@@ -2611,7 +2611,7 @@ int kvmppc_define_rtas_kernel_token(uint32_t token, const char *function) .token = token, }; -if (!kvm_check_extension (kvm_state,KVM_CAP_PPC_RTAS )) { +if (!kvm_check_extension (KVM_CAP_PPC_RTAS )) {return -ENOENT ; }
@@ -2828,7 +2828,7 @@ int kvm_handle_nmi(PowerPCCPU *cpu, struct kvm_run *run)int kvmppc_enable_hwrng (void ) { -if (!kvm_enabled () || !kvm_check_extension (kvm_state,KVM_CAP_PPC_HWRNG )) { +if (!kvm_enabled () || !kvm_check_extension (KVM_CAP_PPC_HWRNG )) {return -1 ; }
target/s390x/cpu_models.c +1 -2
@@ -222,8 +222,7 @@ bool s390_has_feat(S390Feat feat)#ifdef CONFIG_KVM if (kvm_enabled ()) {if (feat ==S390_FEAT_VECTOR ) { -return kvm_check_extension (kvm_state, -KVM_CAP_S390_VECTOR_REGISTERS ); +return kvm_check_extension (KVM_CAP_S390_VECTOR_REGISTERS ); }if (feat ==S390_FEAT_RUNTIME_INSTRUMENTATION ) {return kvm_s390_get_ri ();
target/s390x/kvm.c +15 -15
@@ -342,21 +342,21 @@ int kvm_arch_init(MachineState *ms, KVMState *s)object_class_foreach (ccw_machine_class_foreach,TYPE_S390_CCW_MACHINE , false,NULL ); -if (!kvm_check_extension (kvm_state,KVM_CAP_DEVICE_CTRL )) { +if (!kvm_check_extension (KVM_CAP_DEVICE_CTRL )) {error_report ("KVM is missing capability KVM_CAP_DEVICE_CTRL - " "please use kernel 3.15 or newer" );return -1 ; } - cap_sync_regs =kvm_check_extension (s,KVM_CAP_SYNC_REGS ); - cap_async_pf =kvm_check_extension (s,KVM_CAP_ASYNC_PF ); - cap_mem_op =kvm_check_extension (s,KVM_CAP_S390_MEM_OP ); - cap_s390_irq =kvm_check_extension (s,KVM_CAP_S390_INJECT_IRQ ); - cap_vcpu_resets =kvm_check_extension (s,KVM_CAP_S390_VCPU_RESETS ); - cap_protected =kvm_check_extension (s,KVM_CAP_S390_PROTECTED ); + cap_sync_regs =kvm_check_extension (KVM_CAP_SYNC_REGS ); + cap_async_pf =kvm_check_extension (KVM_CAP_ASYNC_PF ); + cap_mem_op =kvm_check_extension (KVM_CAP_S390_MEM_OP ); + cap_s390_irq =kvm_check_extension (KVM_CAP_S390_INJECT_IRQ ); + cap_vcpu_resets =kvm_check_extension (KVM_CAP_S390_VCPU_RESETS ); + cap_protected =kvm_check_extension (KVM_CAP_S390_PROTECTED ); -if (!kvm_check_extension (s,KVM_CAP_S390_GMAP ) - || !kvm_check_extension (s,KVM_CAP_S390_COW )) { +if (!kvm_check_extension (KVM_CAP_S390_GMAP ) + || !kvm_check_extension (KVM_CAP_S390_COW )) {phys_mem_set_alloc (legacy_s390_alloc); }
@@ -381,7 +381,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s)* newer machine types if KVM_CAP_S390_AIS_MIGRATION is available. */ if (cpu_model_allowed () &&kvm_kernel_irqchip_allowed () && -kvm_check_extension (s,KVM_CAP_S390_AIS_MIGRATION )) { +kvm_check_extension (KVM_CAP_S390_AIS_MIGRATION )) {kvm_vm_enable_cap (s,KVM_CAP_S390_AIS ,0 ); }
@@ -1996,7 +1996,7 @@ void kvm_arch_init_irq_routing(KVMState *s)* are handled in-kernel, it is not true for s390 (yet); therefore, we * have to override the common code kvm_halt_in_kernel_allowed setting. */ -if (kvm_check_extension (s,KVM_CAP_IRQ_ROUTING )) { +if (kvm_check_extension (KVM_CAP_IRQ_ROUTING )) { kvm_gsi_routing_allowed = true; kvm_halt_in_kernel_allowed = false; }
@@ -2015,7 +2015,7 @@ int kvm_s390_assign_subch_ioeventfd(EventNotifier *notifier, uint32_t sch, };trace_kvm_assign_subch_ioeventfd (kick.fd, kick.addr, assign, kick.datamatch); -if (!kvm_check_extension (kvm_state,KVM_CAP_IOEVENTFD )) { +if (!kvm_check_extension (KVM_CAP_IOEVENTFD )) {return -ENOSYS ; }if (!assign) {
@@ -2082,7 +2082,7 @@ void kvm_s390_vcpu_interrupt_pre_save(S390CPU *cpu)CPUState *cs =CPU (cpu);int32_t bytes; -if (!kvm_check_extension (kvm_state,KVM_CAP_S390_IRQ_STATE )) { +if (!kvm_check_extension (KVM_CAP_S390_IRQ_STATE )) {return ; }
@@ -2109,7 +2109,7 @@ int kvm_s390_vcpu_interrupt_post_load(S390CPU *cpu)return 0 ; } -if (!kvm_check_extension (kvm_state,KVM_CAP_S390_IRQ_STATE )) { +if (!kvm_check_extension (KVM_CAP_S390_IRQ_STATE )) {return -ENOSYS ; }
@@ -2421,7 +2421,7 @@ void kvm_s390_get_host_cpu_model(S390CPUModel *model, Error **errp) }/* bpb needs kernel support for migration, VSIE and reset */ -if (!kvm_check_extension (kvm_state,KVM_CAP_S390_BPB )) { +if (!kvm_check_extension (KVM_CAP_S390_BPB )) {clear_bit (S390_FEAT_BPB , model->features); }
Signature · 1 line
2.21.3
Re: [PATCH 2/7] accel/kvm: Simplify kvm_check_extension()
Quoted 12 lines · On Tue, 23 Jun 2020 12:50:47 +0200 Philippe Mathieu-Daudé <[email protected]>…
In previous commit we let
kvm_check_extension()use the globalkvm_state. Since the KVMState* argument is now unused, drop it.Convert callers with this Coccinelle script:
@@
expressionkvm_state, extension;
@@
-kvm_check_extension(kvm_state, extension)
+kvm_check_extension(extension)
Quoted 5 lines
Unused variables manually removed:
- CPUState* inhyperv_enabled()
- KVMState* inkvm_arm_get_max_vm_ipa_size()Inspired-by Paolo Bonzini <[email protected]>
🌟💡🌟
Quoted 13 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/sysemu/kvm.h | 2 +- accel/kvm/kvm-all.c | 64 ++++++++++++++++++------------------ hw/hyperv/hyperv.c | 2 +- hw/i386/kvm/clock.c | 2 +- hw/i386/kvm/i8254.c | 4 +-- hw/i386/kvm/ioapic.c | 2 +- hw/intc/arm_gic_kvm.c | 2 +- hw/intc/openpic_kvm.c | 2 +- hw/intc/xics_kvm.c | 2 +- hw/s390x/s390-stattrib-kvm.c | 2 +- target/arm/kvm.c | 13 ++++----
Quoted 8 lines
target/arm/kvm32.c | 2 +- target/arm/kvm64.c | 15 ++++----- target/i386/kvm.c | 61 ++++++++++++++++------------------ target/mips/kvm.c | 4 +-- target/ppc/kvm.c | 34 +++++++++---------- target/s390x/cpu_models.c | 3 +- target/s390x/kvm.c | 30 ++++++++--------- 18 files changed, 119 insertions(+), 127 deletions(-)
PATCH 3/7 accel/kvm: Simplify kvm_check_extension_list()
In reply to Philippe Mathieu-DaudéThe KVMState* argument is now unused, drop it.
--- accel/kvm/kvm-all.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
accel/kvm/kvm-all.c +3 -3
@@ -1088,7 +1088,7 @@ static int kvm_check_many_ioeventfds(void) }static const KVMCapabilityInfo * -kvm_check_extension_list (KVMState *s,const KVMCapabilityInfo *list) +kvm_check_extension_list (const KVMCapabilityInfo *list) {while (list->name) {if (!kvm_check_extension (list->value)) {
@@ -2104,10 +2104,10 @@ static int kvm_init(MachineState *ms) nc++; } - missing_cap =kvm_check_extension_list (s, kvm_required_capabilites); + missing_cap =kvm_check_extension_list (kvm_required_capabilites);if (!missing_cap) { missing_cap = -kvm_check_extension_list (s, kvm_arch_required_capabilities); +kvm_check_extension_list (kvm_arch_required_capabilities); }if (missing_cap) { ret = -EINVAL ;
Signature · 1 line
2.21.3
Re: [PATCH 3/7] accel/kvm: Simplify kvm_check_extension_list()
Quoted 6 lines · On Tue, 23 Jun 2020 12:50:48 +0200 Philippe Mathieu-Daudé <[email protected]>…
The KVMState* argument is now unused, drop it.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- accel/kvm/kvm-all.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
RFC PATCH 4/7 accel/kvm: Simplify kvm_set_sigmask_len()
In reply to Philippe Mathieu-DaudéThe sigmask_len is a property of the accelerator, not the VM. Simplify by directly using the global kvm_state, remove the unnecessary KVMState* argument.
--- include/sysemu/kvm.h | 2 +- accel/kvm/kvm-all.c | 4 ++-- target/mips/kvm.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
include/sysemu/kvm.h +1 -1
@@ -469,7 +469,7 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,uint64_t kvm_arch_get_supported_msr_feature (KVMState *s,uint32_t index); -void kvm_set_sigmask_len (KVMState *s,unsigned int sigmask_len); +void kvm_set_sigmask_len (unsigned int sigmask_len);#if !defined(CONFIG_USER_ONLY ) int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr,
accel/kvm/kvm-all.c +2 -2
@@ -2240,9 +2240,9 @@ err:return ret; } -void kvm_set_sigmask_len (KVMState *s,unsigned int sigmask_len) +void kvm_set_sigmask_len (unsigned int sigmask_len) { - s->sigmask_len = sigmask_len; + kvm_state->sigmask_len = sigmask_len; } static void kvm_handle_io(uint16_t port, MemTxAttrs attrs, void *data, int direction,
target/mips/kvm.c +1 -1
@@ -48,7 +48,7 @@ unsigned long kvm_arch_vcpu_id(CPUState *cs)int kvm_arch_init (MachineState *ms,KVMState *s) {/* MIPS has 128 signals */ -kvm_set_sigmask_len (s,16 ); +kvm_set_sigmask_len (16 ); kvm_mips_fpu_cap =kvm_check_extension (KVM_CAP_MIPS_FPU ); kvm_mips_msa_cap =kvm_check_extension (KVM_CAP_MIPS_MSA );
Signature · 1 line
2.21.3
Paolo Bonzini
maintainerRe: [RFC PATCH 4/7] accel/kvm: Simplify kvm_set_sigmask_len()
Quoted 3 lines · Philippe Mathieu-Daudé
The
sigmask_lenis a property of the accelerator, not the VM. Simplify by directly using the globalkvm_state, remove the unnecessary KVMState* argument.
This is not entirely true, if there were multiple KVMStates how would you know which one to read from? So it would have to be a global variable.
Paolo
Quoted 50 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/sysemu/kvm.h | 2 +- accel/kvm/kvm-all.c | 4 ++-- target/mips/kvm.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)include/sysemu/kvm.h +1
-1@@ -469,7 +469,7 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,uint64_t kvm_arch_get_supported_msr_feature (KVMState *s,uint32_t index); -void kvm_set_sigmask_len (KVMState *s,unsigned int sigmask_len); +void kvm_set_sigmask_len (unsigned int sigmask_len);#if !defined(CONFIG_USER_ONLY ) int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr,accel/kvm/kvm-all.c +2
-2@@ -2240,9 +2240,9 @@ err:return ret; } -void kvm_set_sigmask_len (KVMState *s,unsigned int sigmask_len) +void kvm_set_sigmask_len (unsigned int sigmask_len) { - s->sigmask_len = sigmask_len; + kvm_state->sigmask_len = sigmask_len; } static void kvm_handle_io(uint16_t port, MemTxAttrs attrs, void *data, int direction,target/mips/kvm.c +1
-1@@ -48,7 +48,7 @@ unsigned long kvm_arch_vcpu_id(CPUState *cs)int kvm_arch_init (MachineState *ms,KVMState *s) {/* MIPS has 128 signals */ -kvm_set_sigmask_len (s,16 ); +kvm_set_sigmask_len (16 ); kvm_mips_fpu_cap =kvm_check_extension (KVM_CAP_MIPS_FPU ); kvm_mips_msa_cap =kvm_check_extension (KVM_CAP_MIPS_MSA );
Re: [RFC PATCH 4/7] accel/kvm: Simplify kvm_set_sigmask_len()
Quoted 7 lines · Paolo Bonzini
Quoted 3 lines · Philippe Mathieu-Daudé
The
sigmask_lenis a property of the accelerator, not the VM. Simplify by directly using the globalkvm_state, remove the unnecessary KVMState* argument.This is not entirely true, if there were multiple KVMStates how would you know which one to read from? So it would have to be a global variable.
Ah I guess I understand. Thanks for reviewing and queuing the rest!
Quoted 54 lines
Paolo
Quoted 50 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/sysemu/kvm.h | 2 +- accel/kvm/kvm-all.c | 4 ++-- target/mips/kvm.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)include/sysemu/kvm.h +1
-1@@ -469,7 +469,7 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *env, uint32_t function,uint64_t kvm_arch_get_supported_msr_feature (KVMState *s,uint32_t index); -void kvm_set_sigmask_len (KVMState *s,unsigned int sigmask_len); +void kvm_set_sigmask_len (unsigned int sigmask_len);#if !defined(CONFIG_USER_ONLY ) int kvm_physical_memory_addr_from_host(KVMState *s, void *ram_addr,accel/kvm/kvm-all.c +2
-2@@ -2240,9 +2240,9 @@ err:return ret; } -void kvm_set_sigmask_len (KVMState *s,unsigned int sigmask_len) +void kvm_set_sigmask_len (unsigned int sigmask_len) { - s->sigmask_len = sigmask_len; + kvm_state->sigmask_len = sigmask_len; } static void kvm_handle_io(uint16_t port, MemTxAttrs attrs, void *data, int direction,target/mips/kvm.c +1
-1@@ -48,7 +48,7 @@ unsigned long kvm_arch_vcpu_id(CPUState *cs)int kvm_arch_init (MachineState *ms,KVMState *s) {/* MIPS has 128 signals */ -kvm_set_sigmask_len (s,16 ); +kvm_set_sigmask_len (16 ); kvm_mips_fpu_cap =kvm_check_extension (KVM_CAP_MIPS_FPU ); kvm_mips_msa_cap =kvm_check_extension (KVM_CAP_MIPS_MSA );
PATCH 5/7 target/i386/kvm: Simplify get_para_features()
In reply to Philippe Mathieu-DaudéThe KVMState* argument is now unused, drop it.
--- target/i386/kvm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
target/i386/kvm.c +2 -2
@@ -289,7 +289,7 @@ static const struct kvm_para_features { { KVM_CAP_ASYNC_PF, KVM_FEATURE_ASYNC_PF }, }; -static int get_para_features (KVMState *s) +static int get_para_features (void ) {int i, features =0 ;
@@ -452,7 +452,7 @@ uint32_t kvm_arch_get_supported_cpuid(KVMState *s, uint32_t function,/* fallback for older kernels */ if ((function ==KVM_CPUID_FEATURES ) && !found) { - ret =get_para_features (s); + ret =get_para_features (); }return ret;
Signature · 1 line
2.21.3
Re: [PATCH 5/7] target/i386/kvm: Simplify get_para_features()
Quoted 6 lines · On Tue, 23 Jun 2020 12:50:50 +0200 Philippe Mathieu-Daudé <[email protected]>…
The KVMState* argument is now unused, drop it.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- target/i386/kvm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
RFC PATCH 6/7 target/i386/kvm: Simplify kvm_get_mce_cap_supported()
In reply to Philippe Mathieu-DaudéAs the MCE supported capabilities should be the same for all VMs, it is safe to directly use the global kvm_state. Remove the unnecessary KVMState* argument.
--- target/i386/kvm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
target/i386/kvm.c +3 -3
@@ -536,7 +536,7 @@ uint64_t kvm_arch_get_supported_msr_feature(KVMState *s, uint32_t index) } } -static int kvm_get_mce_cap_supported (KVMState *s,uint64_t *mce_cap, +static int kvm_get_mce_cap_supported (uint64_t *mce_cap,int *max_banks) {int r;
@@ -544,7 +544,7 @@ static int kvm_get_mce_cap_supported(KVMState *s, uint64_t *mce_cap, r =kvm_check_extension (KVM_CAP_MCE );if (r >0 ) { *max_banks = r; -return kvm_ioctl (s,KVM_X86_GET_MCE_CAP_SUPPORTED , mce_cap); +return kvm_ioctl (kvm_state,KVM_X86_GET_MCE_CAP_SUPPORTED , mce_cap); }return -ENOSYS ; }
@@ -1707,7 +1707,7 @@ int kvm_arch_init_vcpu(CPUState *cs)int banks;int ret; - ret =kvm_get_mce_cap_supported (cs->kvm_state, &mcg_cap, &banks); + ret =kvm_get_mce_cap_supported (&mcg_cap, &banks);if (ret <0 ) {fprintf (stderr,"kvm_get_mce_cap_supported: %s" ,strerror (-ret));return ret;
Signature · 1 line
2.21.3
RFC PATCH 7/7 target/i386/kvm: Simplify kvm_get_supported_[feature]_msrs()
In reply to Philippe Mathieu-DaudéAs the MSR supported features should be the same for all VMs, it is safe to directly use the global kvm_state. Remove the unnecessary KVMState* argument.
--- target/i386/kvm.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
target/i386/kvm.c +9 -8
@@ -1887,7 +1887,7 @@ void kvm_arch_do_init_vcpu(X86CPU *cpu) } } -static int kvm_get_supported_feature_msrs (KVMState *s) +static int kvm_get_supported_feature_msrs (void ) {int ret =0 ;
@@ -1902,7 +1902,7 @@ static int kvm_get_supported_feature_msrs(KVMState *s)struct kvm_msr_list msr_list; msr_list.nmsrs =0 ; - ret =kvm_ioctl (s,KVM_GET_MSR_FEATURE_INDEX_LIST , &msr_list); + ret =kvm_ioctl (kvm_state,KVM_GET_MSR_FEATURE_INDEX_LIST , &msr_list);if (ret <0 && ret != -E2BIG ) {error_report ("Fetch KVM feature MSR list failed: %s" ,strerror (-ret));
@@ -1915,7 +1915,8 @@ static int kvm_get_supported_feature_msrs(KVMState *s) msr_list.nmsrs * sizeof(msr_list.indices[0])); kvm_feature_msrs->nmsrs = msr_list.nmsrs; - ret =kvm_ioctl (s,KVM_GET_MSR_FEATURE_INDEX_LIST , kvm_feature_msrs); + ret =kvm_ioctl (kvm_state,KVM_GET_MSR_FEATURE_INDEX_LIST , + kvm_feature_msrs);if (ret <0 ) { error_report("Fetch KVM feature MSR list failed: %s",
@@ -1928,7 +1929,7 @@ static int kvm_get_supported_feature_msrs(KVMState *s)return 0 ; } -static int kvm_get_supported_msrs (KVMState *s) +static int kvm_get_supported_msrs (void ) {int ret =0 ;struct kvm_msr_list msr_list, *kvm_msr_list;
@@ -1938,7 +1939,7 @@ static int kvm_get_supported_msrs(KVMState *s)* save/restore. */ msr_list.nmsrs =0 ; - ret =kvm_ioctl (s,KVM_GET_MSR_INDEX_LIST , &msr_list); + ret =kvm_ioctl (kvm_state,KVM_GET_MSR_INDEX_LIST , &msr_list);if (ret <0 && ret != -E2BIG ) {return ret; }
@@ -1951,7 +1952,7 @@ static int kvm_get_supported_msrs(KVMState *s) sizeof(msr_list.indices[0]))); kvm_msr_list->nmsrs = msr_list.nmsrs; - ret =kvm_ioctl (s,KVM_GET_MSR_INDEX_LIST , kvm_msr_list); + ret =kvm_ioctl (kvm_state,KVM_GET_MSR_INDEX_LIST , kvm_msr_list);if (ret >=0 ) {int i;
@@ -2107,12 +2108,12 @@ int kvm_arch_init(MachineState *ms, KVMState *s) } } - ret =kvm_get_supported_msrs (s); + ret =kvm_get_supported_msrs ();if (ret <0 ) {return ret; } -kvm_get_supported_feature_msrs (s); +kvm_get_supported_feature_msrs ();uname (&utsname); lm_capable_kernel =strcmp (utsname.machine,"x86_64" ) ==0 ;
Signature · 1 line
2.21.3
kind ping :)
Quoted 35 lines · Philippe Mathieu-Daudé
Following Paolo's idea on
kvm_check_extension():
https://www.mail-archive.com/[email protected]/msg713794.htmlCI:
https://travis-ci.org/github/philmd/qemu/builds/701213438Philippe Mathieu-Daudé (7):
accel/kvm: Letkvm_check_extensionuse global KVM state accel/kvm: Simplifykvm_check_extension()accel/kvm: Simplifykvm_check_extension_list()accel/kvm: Simplifykvm_set_sigmask_len()target/i386/kvm: Simplifyget_para_features()target/i386/kvm: Simplifykvm_get_mce_cap_supported()target/i386/kvm: Simplify kvm_get_supported_[feature]_msrs()include/sysemu/kvm.h | 4 +- accel/kvm/kvm-all.c | 76 +++++++++++++++---------------- hw/hyperv/hyperv.c | 2 +- hw/i386/kvm/clock.c | 2 +- hw/i386/kvm/i8254.c | 4 +- hw/i386/kvm/ioapic.c | 2 +- hw/intc/arm_gic_kvm.c | 2 +- hw/intc/openpic_kvm.c | 2 +- hw/intc/xics_kvm.c | 2 +- hw/s390x/s390-stattrib-kvm.c | 2 +- target/arm/kvm.c | 13 +++--- target/arm/kvm32.c | 2 +- target/arm/kvm64.c | 15 +++--- target/i386/kvm.c | 88 +++++++++++++++++------------------- target/mips/kvm.c | 6 +-- target/ppc/kvm.c | 34 +++++++------- target/s390x/cpu_models.c | 3 +- target/s390x/kvm.c | 30 ++++++------ 18 files changed, 141 insertions(+), 148 deletions(-)
Paolo Bonzini
maintainerQuoted 1 line · Philippe Mathieu-Daudé
kind ping :)
Queued all except 4.
Paolo
Quoted 37 lines · Philippe Mathieu-Daudé
Quoted 35 lines
Following Paolo's idea on
kvm_check_extension():
https://www.mail-archive.com/[email protected]/msg713794.htmlCI:
https://travis-ci.org/github/philmd/qemu/builds/701213438Philippe Mathieu-Daudé (7):
accel/kvm: Letkvm_check_extensionuse global KVM state accel/kvm: Simplifykvm_check_extension()accel/kvm: Simplifykvm_check_extension_list()accel/kvm: Simplifykvm_set_sigmask_len()target/i386/kvm: Simplifyget_para_features()target/i386/kvm: Simplifykvm_get_mce_cap_supported()target/i386/kvm: Simplify kvm_get_supported_[feature]_msrs()include/sysemu/kvm.h | 4 +- accel/kvm/kvm-all.c | 76 +++++++++++++++---------------- hw/hyperv/hyperv.c | 2 +- hw/i386/kvm/clock.c | 2 +- hw/i386/kvm/i8254.c | 4 +- hw/i386/kvm/ioapic.c | 2 +- hw/intc/arm_gic_kvm.c | 2 +- hw/intc/openpic_kvm.c | 2 +- hw/intc/xics_kvm.c | 2 +- hw/s390x/s390-stattrib-kvm.c | 2 +- target/arm/kvm.c | 13 +++--- target/arm/kvm32.c | 2 +- target/arm/kvm64.c | 15 +++--- target/i386/kvm.c | 88 +++++++++++++++++------------------- target/mips/kvm.c | 6 +-- target/ppc/kvm.c | 34 +++++++------- target/s390x/cpu_models.c | 3 +- target/s390x/kvm.c | 30 ++++++------ 18 files changed, 141 insertions(+), 148 deletions(-)