Re: [PATCH] KVM: x86: avoid some unnecessary copy in __x86_set_memory_region()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi linmiaohe,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on kvm/linux-next]
[also build test WARNING on v5.5-rc7 next-20200124]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/linmiaohe/KVM-x86-avoid-some-unnecessary-copy-in-__x86_set_memory_region/20200125-020112
base:   https://git.kernel.org/pub/scm/virt/kvm/kvm.git linux-next
config: i386-allyesconfig (attached as .config)
compiler: gcc-7 (Debian 7.5.0-3) 7.5.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

If you fix the issue, kindly add following tag
Reported-by: kbuild test robot <lkp@xxxxxxxxx>

Note: it may well be a FALSE warning. FWIW you are at least aware of it now.
http://gcc.gnu.org/wiki/Better_Uninitialized_Warnings

All warnings (new ones prefixed by >>):

   In file included from arch/x86/kvm/x86.c:25:0:
   arch/x86/kvm/x86.h: In function 'kvm_dr7_valid':
   arch/x86/kvm/x86.h:363:16: warning: right shift count >= width of type [-Wshift-count-overflow]
     return !(data >> 32);
                   ^~
   arch/x86/kvm/x86.c: In function '__x86_set_memory_region':
>> arch/x86/kvm/x86.c:9730:27: warning: 'npages' may be used uninitialized in this function [-Wmaybe-uninitialized]
      vm_munmap(uaddr, npages * PAGE_SIZE);
>> arch/x86/kvm/x86.c:9730:3: warning: 'uaddr' may be used uninitialized in this function [-Wmaybe-uninitialized]
      vm_munmap(uaddr, npages * PAGE_SIZE);
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

vim +/npages +9730 arch/x86/kvm/x86.c

  9682	
  9683	int __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa, u32 size)
  9684	{
  9685		int i, r;
  9686		unsigned long hva, uaddr, npages;
  9687		struct kvm_memslots *slots = kvm_memslots(kvm);
  9688		struct kvm_memory_slot *slot;
  9689	
  9690		/* Called with kvm->slots_lock held.  */
  9691		if (WARN_ON(id >= KVM_MEM_SLOTS_NUM))
  9692			return -EINVAL;
  9693	
  9694		slot = id_to_memslot(slots, id);
  9695		if (size) {
  9696			if (slot->npages)
  9697				return -EEXIST;
  9698	
  9699			/*
  9700			 * MAP_SHARED to prevent internal slot pages from being moved
  9701			 * by fork()/COW.
  9702			 */
  9703			hva = vm_mmap(NULL, 0, size, PROT_READ | PROT_WRITE,
  9704				      MAP_SHARED | MAP_ANONYMOUS, 0);
  9705			if (IS_ERR((void *)hva))
  9706				return PTR_ERR((void *)hva);
  9707		} else {
  9708			if (!slot->npages)
  9709				return 0;
  9710	
  9711			hva = 0;
  9712			uaddr = slot->userspace_addr;
  9713			npages = slot->npages;
  9714		}
  9715	
  9716		for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) {
  9717			struct kvm_userspace_memory_region m;
  9718	
  9719			m.slot = id | (i << 16);
  9720			m.flags = 0;
  9721			m.guest_phys_addr = gpa;
  9722			m.userspace_addr = hva;
  9723			m.memory_size = size;
  9724			r = __kvm_set_memory_region(kvm, &m);
  9725			if (r < 0)
  9726				return r;
  9727		}
  9728	
  9729		if (!size)
> 9730			vm_munmap(uaddr, npages * PAGE_SIZE);
  9731	
  9732		return 0;
  9733	}
  9734	EXPORT_SYMBOL_GPL(__x86_set_memory_region);
  9735	

---
0-DAY kernel test infrastructure                 Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx Intel Corporation

Attachment: .config.gz
Description: application/gzip


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux