lkml.org 
[lkml]   [2022]   [Nov]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/4] KVM: Make cpus_hardware_enabled cpumask_t instead of cpumask_var_t
Date
From: Isaku Yamahata <isaku.yamahata@intel.com>

On kvm module initialization, it dynamically allocates cpumask_var_t.
Remove dynamic allocation by making it cpumask_t as static allocation. It
simplifies module init and exit.

Signed-off-by: Isaku Yamahata <isaku.yamahata@intel.com>
---
virt/kvm/kvm_main.c | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index a8c4e62b29ca..1a21b21ba326 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -103,7 +103,7 @@ DEFINE_MUTEX(kvm_lock);
static DEFINE_RAW_SPINLOCK(kvm_count_lock);
LIST_HEAD(vm_list);

-static cpumask_var_t cpus_hardware_enabled;
+static cpumask_t cpus_hardware_enabled = CPU_MASK_NONE;
static int kvm_usage_count;
static atomic_t hardware_enable_failed;

@@ -5012,15 +5012,15 @@ static void hardware_enable_nolock(void *junk)
int cpu = raw_smp_processor_id();
int r;

- if (cpumask_test_cpu(cpu, cpus_hardware_enabled))
+ if (cpumask_test_cpu(cpu, &cpus_hardware_enabled))
return;

- cpumask_set_cpu(cpu, cpus_hardware_enabled);
+ cpumask_set_cpu(cpu, &cpus_hardware_enabled);

r = kvm_arch_hardware_enable();

if (r) {
- cpumask_clear_cpu(cpu, cpus_hardware_enabled);
+ cpumask_clear_cpu(cpu, &cpus_hardware_enabled);
atomic_inc(&hardware_enable_failed);
pr_info("kvm: enabling virtualization on CPU%d failed\n", cpu);
}
@@ -5039,9 +5039,9 @@ static void hardware_disable_nolock(void *junk)
{
int cpu = raw_smp_processor_id();

- if (!cpumask_test_cpu(cpu, cpus_hardware_enabled))
+ if (!cpumask_test_cpu(cpu, &cpus_hardware_enabled))
return;
- cpumask_clear_cpu(cpu, cpus_hardware_enabled);
+ cpumask_clear_cpu(cpu, &cpus_hardware_enabled);
kvm_arch_hardware_disable();
}

@@ -5849,11 +5849,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
if (r)
goto out_irqfd;

- if (!zalloc_cpumask_var(&cpus_hardware_enabled, GFP_KERNEL)) {
- r = -ENOMEM;
- goto out_free_0;
- }
-
r = kvm_arch_hardware_setup(opaque);
if (r < 0)
goto out_free_1;
@@ -5931,8 +5926,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
out_free_2:
kvm_arch_hardware_unsetup();
out_free_1:
- free_cpumask_var(cpus_hardware_enabled);
-out_free_0:
kvm_irqfd_exit();
out_irqfd:
kvm_arch_exit();
@@ -5959,7 +5952,6 @@ void kvm_exit(void)
kvm_arch_hardware_unsetup();
kvm_arch_exit();
kvm_irqfd_exit();
- free_cpumask_var(cpus_hardware_enabled);
kvm_vfio_ops_exit();
}
EXPORT_SYMBOL_GPL(kvm_exit);
--
2.25.1
\
 
 \ /
  Last update: 2022-11-02 07:25    [W:0.985 / U:0.156 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site