linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* arch/x86/kvm/x86.c:10408:32: sparse: sparse: Using plain integer as NULL pointer
@ 2021-02-27 20:25 kernel test robot
  2021-03-01 13:34 ` [PATCH] KVM: X86: Fix __x86_set_memory_region() sparse warning Peter Xu
  0 siblings, 1 reply; 2+ messages in thread
From: kernel test robot @ 2021-02-27 20:25 UTC (permalink / raw)
  To: Peter Xu; +Cc: kbuild-all, linux-kernel, Paolo Bonzini, Sean Christopherson

[-- Attachment #1: Type: text/plain, Size: 9244 bytes --]

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head:   5695e51619745d4fe3ec2506a2f0cd982c5e27a4
commit: ff5a983cbb3746d371de2cc95ea7dcfd982b4084 KVM: X86: Don't track dirty for KVM_SET_[TSS_ADDR|IDENTITY_MAP_ADDR]
date:   3 months ago
config: x86_64-randconfig-s022-20210228 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.3-241-geaceeafa-dirty
        # https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=ff5a983cbb3746d371de2cc95ea7dcfd982b4084
        git remote add linus https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
        git fetch --no-tags linus master
        git checkout ff5a983cbb3746d371de2cc95ea7dcfd982b4084
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


"sparse warnings: (new ones prefixed by >>)"
   arch/x86/kvm/x86.c:2859:38: sparse: sparse: incorrect type in argument 1 (different address spaces) @@     expected void const [noderef] __user * @@     got unsigned char [usertype] * @@
   arch/x86/kvm/x86.c:2859:38: sparse:     expected void const [noderef] __user *
   arch/x86/kvm/x86.c:2859:38: sparse:     got unsigned char [usertype] *
   arch/x86/kvm/x86.c:8058:15: sparse: sparse: incompatible types in comparison expression (different address spaces):
   arch/x86/kvm/x86.c:8058:15: sparse:    struct kvm_apic_map [noderef] __rcu *
   arch/x86/kvm/x86.c:8058:15: sparse:    struct kvm_apic_map *
>> arch/x86/kvm/x86.c:10408:32: sparse: sparse: Using plain integer as NULL pointer
   arch/x86/kvm/x86.c:10464:16: sparse: sparse: incompatible types in comparison expression (different address spaces):
   arch/x86/kvm/x86.c:10464:16: sparse:    struct kvm_apic_map [noderef] __rcu *
   arch/x86/kvm/x86.c:10464:16: sparse:    struct kvm_apic_map *
   arch/x86/kvm/x86.c:10465:15: sparse: sparse: incompatible types in comparison expression (different address spaces):
   arch/x86/kvm/x86.c:10465:15: sparse:    struct kvm_pmu_event_filter [noderef] __rcu *
   arch/x86/kvm/x86.c:10465:15: sparse:    struct kvm_pmu_event_filter *
   arch/x86/kvm/x86.c: note: in included file (through include/linux/notifier.h, include/linux/memory_hotplug.h, include/linux/mmzone.h, ...):
   include/linux/srcu.h:179:9: sparse: sparse: context imbalance in 'vcpu_enter_guest' - unexpected unlock

vim +10408 arch/x86/kvm/x86.c

ff5a983cbb3746 Peter Xu            2020-09-30  10358  
ff5a983cbb3746 Peter Xu            2020-09-30  10359  /**
ff5a983cbb3746 Peter Xu            2020-09-30  10360   * __x86_set_memory_region: Setup KVM internal memory slot
ff5a983cbb3746 Peter Xu            2020-09-30  10361   *
ff5a983cbb3746 Peter Xu            2020-09-30  10362   * @kvm: the kvm pointer to the VM.
ff5a983cbb3746 Peter Xu            2020-09-30  10363   * @id: the slot ID to setup.
ff5a983cbb3746 Peter Xu            2020-09-30  10364   * @gpa: the GPA to install the slot (unused when @size == 0).
ff5a983cbb3746 Peter Xu            2020-09-30  10365   * @size: the size of the slot. Set to zero to uninstall a slot.
ff5a983cbb3746 Peter Xu            2020-09-30  10366   *
ff5a983cbb3746 Peter Xu            2020-09-30  10367   * This function helps to setup a KVM internal memory slot.  Specify
ff5a983cbb3746 Peter Xu            2020-09-30  10368   * @size > 0 to install a new slot, while @size == 0 to uninstall a
ff5a983cbb3746 Peter Xu            2020-09-30  10369   * slot.  The return code can be one of the following:
ff5a983cbb3746 Peter Xu            2020-09-30  10370   *
ff5a983cbb3746 Peter Xu            2020-09-30  10371   *   HVA:           on success (uninstall will return a bogus HVA)
ff5a983cbb3746 Peter Xu            2020-09-30  10372   *   -errno:        on error
ff5a983cbb3746 Peter Xu            2020-09-30  10373   *
ff5a983cbb3746 Peter Xu            2020-09-30  10374   * The caller should always use IS_ERR() to check the return value
ff5a983cbb3746 Peter Xu            2020-09-30  10375   * before use.  Note, the KVM internal memory slots are guaranteed to
ff5a983cbb3746 Peter Xu            2020-09-30  10376   * remain valid and unchanged until the VM is destroyed, i.e., the
ff5a983cbb3746 Peter Xu            2020-09-30  10377   * GPA->HVA translation will not change.  However, the HVA is a user
ff5a983cbb3746 Peter Xu            2020-09-30  10378   * address, i.e. its accessibility is not guaranteed, and must be
ff5a983cbb3746 Peter Xu            2020-09-30  10379   * accessed via __copy_{to,from}_user().
ff5a983cbb3746 Peter Xu            2020-09-30  10380   */
ff5a983cbb3746 Peter Xu            2020-09-30  10381  void __user * __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa,
ff5a983cbb3746 Peter Xu            2020-09-30  10382  				      u32 size)
9da0e4d5ac9699 Paolo Bonzini       2015-05-18  10383  {
9da0e4d5ac9699 Paolo Bonzini       2015-05-18  10384  	int i, r;
3f649ab728cda8 Kees Cook           2020-06-03  10385  	unsigned long hva, old_npages;
f0d648bdf0a5bb Paolo Bonzini       2015-10-12  10386  	struct kvm_memslots *slots = kvm_memslots(kvm);
0577d1abe704c3 Sean Christopherson 2020-02-18  10387  	struct kvm_memory_slot *slot;
9da0e4d5ac9699 Paolo Bonzini       2015-05-18  10388  
9da0e4d5ac9699 Paolo Bonzini       2015-05-18  10389  	/* Called with kvm->slots_lock held.  */
1d8007bdee074f Paolo Bonzini       2015-10-12  10390  	if (WARN_ON(id >= KVM_MEM_SLOTS_NUM))
ff5a983cbb3746 Peter Xu            2020-09-30  10391  		return ERR_PTR_USR(-EINVAL);
9da0e4d5ac9699 Paolo Bonzini       2015-05-18  10392  
f0d648bdf0a5bb Paolo Bonzini       2015-10-12  10393  	slot = id_to_memslot(slots, id);
f0d648bdf0a5bb Paolo Bonzini       2015-10-12  10394  	if (size) {
0577d1abe704c3 Sean Christopherson 2020-02-18  10395  		if (slot && slot->npages)
ff5a983cbb3746 Peter Xu            2020-09-30  10396  			return ERR_PTR_USR(-EEXIST);
f0d648bdf0a5bb Paolo Bonzini       2015-10-12  10397  
f0d648bdf0a5bb Paolo Bonzini       2015-10-12  10398  		/*
f0d648bdf0a5bb Paolo Bonzini       2015-10-12  10399  		 * MAP_SHARED to prevent internal slot pages from being moved
f0d648bdf0a5bb Paolo Bonzini       2015-10-12  10400  		 * by fork()/COW.
f0d648bdf0a5bb Paolo Bonzini       2015-10-12  10401  		 */
f0d648bdf0a5bb Paolo Bonzini       2015-10-12  10402  		hva = vm_mmap(NULL, 0, size, PROT_READ | PROT_WRITE,
f0d648bdf0a5bb Paolo Bonzini       2015-10-12  10403  			      MAP_SHARED | MAP_ANONYMOUS, 0);
f0d648bdf0a5bb Paolo Bonzini       2015-10-12  10404  		if (IS_ERR((void *)hva))
ff5a983cbb3746 Peter Xu            2020-09-30  10405  			return (void __user *)hva;
f0d648bdf0a5bb Paolo Bonzini       2015-10-12  10406  	} else {
0577d1abe704c3 Sean Christopherson 2020-02-18  10407  		if (!slot || !slot->npages)
f0d648bdf0a5bb Paolo Bonzini       2015-10-12 @10408  			return 0;
f0d648bdf0a5bb Paolo Bonzini       2015-10-12  10409  
0577d1abe704c3 Sean Christopherson 2020-02-18  10410  		old_npages = slot->npages;
e0135a104c52cc Paolo Bonzini       2020-06-11  10411  		hva = 0;
f0d648bdf0a5bb Paolo Bonzini       2015-10-12  10412  	}
f0d648bdf0a5bb Paolo Bonzini       2015-10-12  10413  
9da0e4d5ac9699 Paolo Bonzini       2015-05-18  10414  	for (i = 0; i < KVM_ADDRESS_SPACE_NUM; i++) {
1d8007bdee074f Paolo Bonzini       2015-10-12  10415  		struct kvm_userspace_memory_region m;
9da0e4d5ac9699 Paolo Bonzini       2015-05-18  10416  
1d8007bdee074f Paolo Bonzini       2015-10-12  10417  		m.slot = id | (i << 16);
1d8007bdee074f Paolo Bonzini       2015-10-12  10418  		m.flags = 0;
1d8007bdee074f Paolo Bonzini       2015-10-12  10419  		m.guest_phys_addr = gpa;
f0d648bdf0a5bb Paolo Bonzini       2015-10-12  10420  		m.userspace_addr = hva;
1d8007bdee074f Paolo Bonzini       2015-10-12  10421  		m.memory_size = size;
9da0e4d5ac9699 Paolo Bonzini       2015-05-18  10422  		r = __kvm_set_memory_region(kvm, &m);
9da0e4d5ac9699 Paolo Bonzini       2015-05-18  10423  		if (r < 0)
ff5a983cbb3746 Peter Xu            2020-09-30  10424  			return ERR_PTR_USR(r);
9da0e4d5ac9699 Paolo Bonzini       2015-05-18  10425  	}
9da0e4d5ac9699 Paolo Bonzini       2015-05-18  10426  
103c763c72dd2d Eric Biggers        2018-01-31  10427  	if (!size)
0577d1abe704c3 Sean Christopherson 2020-02-18  10428  		vm_munmap(hva, old_npages * PAGE_SIZE);
f0d648bdf0a5bb Paolo Bonzini       2015-10-12  10429  
ff5a983cbb3746 Peter Xu            2020-09-30  10430  	return (void __user *)hva;
9da0e4d5ac9699 Paolo Bonzini       2015-05-18  10431  }
9da0e4d5ac9699 Paolo Bonzini       2015-05-18  10432  EXPORT_SYMBOL_GPL(__x86_set_memory_region);
9da0e4d5ac9699 Paolo Bonzini       2015-05-18  10433  

:::::: The code at line 10408 was first introduced by commit
:::::: f0d648bdf0a5bbc91da6099d5282f77996558ea4 KVM: x86: map/unmap private slots in __x86_set_memory_region

:::::: TO: Paolo Bonzini <pbonzini@redhat.com>
:::::: CC: Paolo Bonzini <pbonzini@redhat.com>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 35995 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] KVM: X86: Fix __x86_set_memory_region() sparse warning
  2021-02-27 20:25 arch/x86/kvm/x86.c:10408:32: sparse: sparse: Using plain integer as NULL pointer kernel test robot
@ 2021-03-01 13:34 ` Peter Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Xu @ 2021-03-01 13:34 UTC (permalink / raw)
  To: kvm, linux-kernel
  Cc: peterx, Paolo Bonzini, Sean Christopherson, kernel test robot

Force ERR_PTR_USR() cast even if the return value is meaningless when deleting
slots, just to pass the sparse check.

Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Sean Christopherson <sean.j.christopherson@intel.com>
Fixes: ff5a983cbb3746d371de2cc95ea7dcfd982b4084
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
 arch/x86/kvm/x86.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 1b404e4d7dd8..44de71995a34 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -10502,7 +10502,7 @@ void __user * __x86_set_memory_region(struct kvm *kvm, int id, gpa_t gpa,
 			return (void __user *)hva;
 	} else {
 		if (!slot || !slot->npages)
-			return 0;
+			return ERR_PTR_USR(0);
 
 		old_npages = slot->npages;
 		hva = slot->userspace_addr;
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-01 13:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-27 20:25 arch/x86/kvm/x86.c:10408:32: sparse: sparse: Using plain integer as NULL pointer kernel test robot
2021-03-01 13:34 ` [PATCH] KVM: X86: Fix __x86_set_memory_region() sparse warning Peter Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).