* [linux-next:master 5808/8581] arch/x86/kvm/svm/sev.c:369 sev_pin_memory() warn: passing zero to 'ERR_PTR'
@ 2020-07-16 13:25 kernel test robot
0 siblings, 0 replies; only message in thread
From: kernel test robot @ 2020-07-16 13:25 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 6286 bytes --]
CC: kbuild-all(a)lists.01.org
TO: Paolo Bonzini <pbonzini@redhat.com>
tree: https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
head: 4c43049f19a280329c1d01699f3cc8ad6910cbbe
commit: a8d908b5873cad212b0f74569f5a23b804e694ce [5808/8581] KVM: x86: report sev_pin_memory errors with PTR_ERR
:::::: branch date: 5 hours ago
:::::: commit date: 8 days ago
config: x86_64-randconfig-m001-20200716 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-14) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
New smatch warnings:
arch/x86/kvm/svm/sev.c:369 sev_pin_memory() warn: passing zero to 'ERR_PTR'
Old smatch warnings:
arch/x86/kvm/svm/sev.c:988 svm_register_enc_region() warn: impossible condition '(range->addr > (~0)) => (0-u64max > u64max)'
arch/x86/kvm/svm/sev.c:988 svm_register_enc_region() warn: impossible condition '(range->size > (~0)) => (0-u64max > u64max)'
# https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/?id=a8d908b5873cad212b0f74569f5a23b804e694ce
git remote add linux-next https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
git remote update linux-next
git checkout a8d908b5873cad212b0f74569f5a23b804e694ce
vim +/ERR_PTR +369 arch/x86/kvm/svm/sev.c
eaf78265a4ab339 Joerg Roedel 2020-03-24 310
eaf78265a4ab339 Joerg Roedel 2020-03-24 311 static struct page **sev_pin_memory(struct kvm *kvm, unsigned long uaddr,
eaf78265a4ab339 Joerg Roedel 2020-03-24 312 unsigned long ulen, unsigned long *n,
eaf78265a4ab339 Joerg Roedel 2020-03-24 313 int write)
eaf78265a4ab339 Joerg Roedel 2020-03-24 314 {
eaf78265a4ab339 Joerg Roedel 2020-03-24 315 struct kvm_sev_info *sev = &to_kvm_svm(kvm)->sev_info;
78824fabc72e5e3 John Hubbard 2020-05-25 316 unsigned long npages, size;
78824fabc72e5e3 John Hubbard 2020-05-25 317 int npinned;
eaf78265a4ab339 Joerg Roedel 2020-03-24 318 unsigned long locked, lock_limit;
eaf78265a4ab339 Joerg Roedel 2020-03-24 319 struct page **pages;
eaf78265a4ab339 Joerg Roedel 2020-03-24 320 unsigned long first, last;
eaf78265a4ab339 Joerg Roedel 2020-03-24 321
eaf78265a4ab339 Joerg Roedel 2020-03-24 322 if (ulen == 0 || uaddr + ulen < uaddr)
a8d908b5873cad2 Paolo Bonzini 2020-06-23 323 return ERR_PTR(-EINVAL);
eaf78265a4ab339 Joerg Roedel 2020-03-24 324
eaf78265a4ab339 Joerg Roedel 2020-03-24 325 /* Calculate number of pages. */
eaf78265a4ab339 Joerg Roedel 2020-03-24 326 first = (uaddr & PAGE_MASK) >> PAGE_SHIFT;
eaf78265a4ab339 Joerg Roedel 2020-03-24 327 last = ((uaddr + ulen - 1) & PAGE_MASK) >> PAGE_SHIFT;
eaf78265a4ab339 Joerg Roedel 2020-03-24 328 npages = (last - first + 1);
eaf78265a4ab339 Joerg Roedel 2020-03-24 329
eaf78265a4ab339 Joerg Roedel 2020-03-24 330 locked = sev->pages_locked + npages;
eaf78265a4ab339 Joerg Roedel 2020-03-24 331 lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
eaf78265a4ab339 Joerg Roedel 2020-03-24 332 if (locked > lock_limit && !capable(CAP_IPC_LOCK)) {
eaf78265a4ab339 Joerg Roedel 2020-03-24 333 pr_err("SEV: %lu locked pages exceed the lock limit of %lu.\n", locked, lock_limit);
a8d908b5873cad2 Paolo Bonzini 2020-06-23 334 return ERR_PTR(-ENOMEM);
eaf78265a4ab339 Joerg Roedel 2020-03-24 335 }
eaf78265a4ab339 Joerg Roedel 2020-03-24 336
78824fabc72e5e3 John Hubbard 2020-05-25 337 if (WARN_ON_ONCE(npages > INT_MAX))
a8d908b5873cad2 Paolo Bonzini 2020-06-23 338 return ERR_PTR(-EINVAL);
78824fabc72e5e3 John Hubbard 2020-05-25 339
eaf78265a4ab339 Joerg Roedel 2020-03-24 340 /* Avoid using vmalloc for smaller buffers. */
eaf78265a4ab339 Joerg Roedel 2020-03-24 341 size = npages * sizeof(struct page *);
eaf78265a4ab339 Joerg Roedel 2020-03-24 342 if (size > PAGE_SIZE)
88dca4ca5a93d2c Christoph Hellwig 2020-06-01 343 pages = __vmalloc(size, GFP_KERNEL_ACCOUNT | __GFP_ZERO);
eaf78265a4ab339 Joerg Roedel 2020-03-24 344 else
eaf78265a4ab339 Joerg Roedel 2020-03-24 345 pages = kmalloc(size, GFP_KERNEL_ACCOUNT);
eaf78265a4ab339 Joerg Roedel 2020-03-24 346
eaf78265a4ab339 Joerg Roedel 2020-03-24 347 if (!pages)
a8d908b5873cad2 Paolo Bonzini 2020-06-23 348 return ERR_PTR(-ENOMEM);
eaf78265a4ab339 Joerg Roedel 2020-03-24 349
eaf78265a4ab339 Joerg Roedel 2020-03-24 350 /* Pin the user virtual address. */
dc42c8ae0a77623 John Hubbard 2020-05-25 351 npinned = pin_user_pages_fast(uaddr, npages, write ? FOLL_WRITE : 0, pages);
eaf78265a4ab339 Joerg Roedel 2020-03-24 352 if (npinned != npages) {
eaf78265a4ab339 Joerg Roedel 2020-03-24 353 pr_err("SEV: Failure locking %lu pages.\n", npages);
eaf78265a4ab339 Joerg Roedel 2020-03-24 354 goto err;
eaf78265a4ab339 Joerg Roedel 2020-03-24 355 }
eaf78265a4ab339 Joerg Roedel 2020-03-24 356
eaf78265a4ab339 Joerg Roedel 2020-03-24 357 *n = npages;
eaf78265a4ab339 Joerg Roedel 2020-03-24 358 sev->pages_locked = locked;
eaf78265a4ab339 Joerg Roedel 2020-03-24 359
eaf78265a4ab339 Joerg Roedel 2020-03-24 360 return pages;
eaf78265a4ab339 Joerg Roedel 2020-03-24 361
eaf78265a4ab339 Joerg Roedel 2020-03-24 362 err:
a8d908b5873cad2 Paolo Bonzini 2020-06-23 363 if (npinned > 0) {
dc42c8ae0a77623 John Hubbard 2020-05-25 364 unpin_user_pages(pages, npinned);
a8d908b5873cad2 Paolo Bonzini 2020-06-23 365 npinned = -ENOMEM;
a8d908b5873cad2 Paolo Bonzini 2020-06-23 366 }
eaf78265a4ab339 Joerg Roedel 2020-03-24 367
eaf78265a4ab339 Joerg Roedel 2020-03-24 368 kvfree(pages);
a8d908b5873cad2 Paolo Bonzini 2020-06-23 @369 return ERR_PTR(npinned);
eaf78265a4ab339 Joerg Roedel 2020-03-24 370 }
eaf78265a4ab339 Joerg Roedel 2020-03-24 371
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
[-- Attachment #2: config.gz --]
[-- Type: application/gzip, Size: 35218 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-07-16 13:25 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-16 13:25 [linux-next:master 5808/8581] arch/x86/kvm/svm/sev.c:369 sev_pin_memory() warn: passing zero to 'ERR_PTR' kernel test robot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.