x86/kvm: handle the failure of __pv_cpu_mask allocation
Subsystems (3)
PATCH 1/1 x86/kvm: handle the failure of __pv_cpu_mask allocation
From: Wanpeng Li <[email protected]>
Fallback to native ipis/tlb flush if fails to allocate __pv_cpu_mask.
Signed-off-by Wanpeng Li <[email protected]>
--- arch/x86/kernel/kvm.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-)
arch/x86/kernel/kvm.c +24 -2
@@ -46,6 +46,7 @@DEFINE_STATIC_KEY_FALSE (kvm_async_pf_enabled); +static struct apic orig_apic;static int kvmapf =1 ;static int __init parse_no_kvmapf (char *arg)
@@ -542,6 +543,11 @@ static void __send_ipi_mask(const struct cpumask *mask, int vector)static void kvm_send_ipi_mask (const struct cpumask *mask,int vector) { +if (unlikely (!this_cpu_cpumask_var_ptr (__pv_cpu_mask))) { + orig_apic.send_IPI_mask (mask, vector); +return ; + } +__send_ipi_mask (mask, vector); }
@@ -551,6 +557,11 @@ static void kvm_send_ipi_mask_allbutself(const struct cpumask *mask, int vector)struct cpumask *new_mask =this_cpu_cpumask_var_ptr (__pv_cpu_mask);const struct cpumask *local_mask; +if (unlikely (!new_mask)) { + orig_apic.send_IPI_mask_allbutself (mask, vector); +return ; + } +cpumask_copy (new_mask, mask);cpumask_clear_cpu (this_cpu, new_mask); local_mask = new_mask;
@@ -611,6 +622,7 @@ late_initcall(setup_efi_kvm_sev_migration);*/ static void kvm_setup_pv_ipi (void ) { + orig_apic = *apic; apic->send_IPI_mask = kvm_send_ipi_mask; apic->send_IPI_mask_allbutself = kvm_send_ipi_mask_allbutself;pr_info ("setup PV IPIs\n" );
@@ -639,6 +651,11 @@ static void kvm_flush_tlb_multi(const struct cpumask *cpumask,struct kvm_steal_time *src;struct cpumask *flushmask =this_cpu_cpumask_var_ptr (__pv_cpu_mask); +if (unlikely (!flushmask)) { +native_flush_tlb_multi (cpumask, info); +return ; + } +cpumask_copy (flushmask, cpumask);/* * We have to call flush only on online vCPUs. And
@@ -671,11 +688,16 @@ static __init int kvm_alloc_cpumask(void)if (pv_tlb_flush_supported () ||pv_ipi_supported ())for_each_possible_cpu (cpu) { -zalloc_cpumask_var_node (per_cpu_ptr (&__pv_cpu_mask, cpu), -GFP_KERNEL ,cpu_to_node (cpu)); +if (!zalloc_cpumask_var_node (&per_cpu (__pv_cpu_mask, cpu), +GFP_KERNEL ,cpu_to_node (cpu))) + goto err_out; }return 0 ; +err_out: +for_each_possible_cpu (cpu) +free_cpumask_var (per_cpu (__pv_cpu_mask, cpu)); +return -ENOMEM ; }arch_initcall (kvm_alloc_cpumask);
Signature · 1 line
2.25.1
kernel test robot
build botI love your patch! Perhaps something to improve:
Hi Wanpeng,
I love your patch! Perhaps something to improve:
[auto build test WARNING on kvm/master]
[also build test WARNING on tip/master linus/master linux/master v5.18-rc6 next-20220509] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/intel-lab-lkp/linux/commits/Wanpeng-Li/x86-kvm-handle-the-failure-of-__pv_cpu_mask-allocation/20220422-175106 base: https://git.kernel.org/pub/scm/virt/kvm/kvm.git master config: i386-randconfig-a004-20220502 (https://download.01.org/0day-ci/archive/20220510/[email protected]/config) compiler: gcc-11 (Debian 11.2.0-20) 11.2.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/329f0c869cf176505509f65e95e47999a9e97b3b git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review Wanpeng-Li/x86-kvm-handle-the-failure-of-__pv_cpu_mask-allocation/20220422-175106 git checkout 329f0c869cf176505509f65e95e47999a9e97b3b # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash arch/x86/kernel/
If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>
All warnings (new ones prefixed by >>):
>> arch/x86/kernel/kvm.c:49:20: warning: 'orig_apic' defined but not used [-Wunused-variable]
49 | static struct apic orig_apic;
| ^~~~~~~~~vim +/orig_apic +49 arch/x86/kernel/kvm.c
48
> 49 static struct apic orig_apic;
50 static int kvmapf = 1;
51 Signature · 2 lines
0-DAY CI Kernel Test Service https://01.org/lkp