[intel-gvt-linux:topic/gvt-migration-yan 2/3] drivers/gpu/drm/i915/gvt/kvmgt.c:498:43: sparse: incorrect type in argument 1 (different address spaces)
kbuild test robot
lkp at intel.com
Fri Mar 22 13:16:54 UTC 2019
tree: https://github.com/intel/gvt-linux topic/gvt-migration-yan
head: 9fda260e40826923c8bf7ef700b9109b7e89258d
commit: 0c6e67aa4344959c357c6d96bc1c03da463f2899 [2/3] drm/i915/gvt: VFIO device states interfaces
reproduce:
# apt-get install sparse
git checkout 0c6e67aa4344959c357c6d96bc1c03da463f2899
make ARCH=x86_64 allmodconfig
make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'
sparse warnings: (new ones prefixed by >>)
include/uapi/linux/perf_event.h:147:56: sparse: cast truncates bits from constant value (8000000000000000 becomes 0)
include/linux/slab.h:332:43: sparse: dubious: x & !y
include/linux/slab.h:332:43: sparse: dubious: x & !y
drivers/gpu/drm/i915/gvt/kvmgt.c:416:17: sparse: expression using sizeof(void)
drivers/gpu/drm/i915/gvt/kvmgt.c:416:17: sparse: expression using sizeof(void)
>> drivers/gpu/drm/i915/gvt/kvmgt.c:498:43: sparse: incorrect type in argument 1 (different address spaces) @@ expected void [noderef] <asn:1>*to @@ got sn:1>*to @@
drivers/gpu/drm/i915/gvt/kvmgt.c:498:43: expected void [noderef] <asn:1>*to
drivers/gpu/drm/i915/gvt/kvmgt.c:498:43: got char *buf
drivers/gpu/drm/i915/gvt/kvmgt.c:504:43: sparse: incorrect type in argument 1 (different address spaces) @@ expected void [noderef] <asn:1>*to @@ got sn:1>*to @@
drivers/gpu/drm/i915/gvt/kvmgt.c:504:43: expected void [noderef] <asn:1>*to
drivers/gpu/drm/i915/gvt/kvmgt.c:504:43: got char *buf
>> drivers/gpu/drm/i915/gvt/kvmgt.c:510:52: sparse: incorrect type in argument 2 (different address spaces) @@ expected void const [noderef] <asn:1>*from @@ got sn:1>*from @@
drivers/gpu/drm/i915/gvt/kvmgt.c:510:52: expected void const [noderef] <asn:1>*from
drivers/gpu/drm/i915/gvt/kvmgt.c:510:52: got char *buf
drivers/gpu/drm/i915/gvt/kvmgt.c:519:43: sparse: incorrect type in argument 1 (different address spaces) @@ expected void [noderef] <asn:1>*to @@ got sn:1>*to @@
drivers/gpu/drm/i915/gvt/kvmgt.c:519:43: expected void [noderef] <asn:1>*to
drivers/gpu/drm/i915/gvt/kvmgt.c:519:43: got char *buf
drivers/gpu/drm/i915/gvt/kvmgt.c:528:53: sparse: incorrect type in argument 2 (different address spaces) @@ expected void const [noderef] <asn:1>*from @@ got sn:1>*from @@
drivers/gpu/drm/i915/gvt/kvmgt.c:528:53: expected void const [noderef] <asn:1>*from
drivers/gpu/drm/i915/gvt/kvmgt.c:528:53: got char *buf
drivers/gpu/drm/i915/gvt/kvmgt.c:548:43: sparse: incorrect type in argument 1 (different address spaces) @@ expected void [noderef] <asn:1>*to @@ got sn:1>*to @@
drivers/gpu/drm/i915/gvt/kvmgt.c:548:43: expected void [noderef] <asn:1>*to
drivers/gpu/drm/i915/gvt/kvmgt.c:548:43: got char *buf
drivers/gpu/drm/i915/gvt/kvmgt.c:569:60: sparse: incorrect type in argument 2 (different address spaces) @@ expected void const [noderef] <asn:1>*from @@ got sn:1>*from @@
drivers/gpu/drm/i915/gvt/kvmgt.c:569:60: expected void const [noderef] <asn:1>*from
drivers/gpu/drm/i915/gvt/kvmgt.c:569:60: got char *buf
drivers/gpu/drm/i915/gvt/kvmgt.c:607:48: sparse: incorrect type in argument 2 (different address spaces) @@ expected void const [noderef] <asn:1>*from @@ got sn:1>*from @@
drivers/gpu/drm/i915/gvt/kvmgt.c:607:48: expected void const [noderef] <asn:1>*from
drivers/gpu/drm/i915/gvt/kvmgt.c:607:48: got char *buf
drivers/gpu/drm/i915/gvt/kvmgt.c:610:34: sparse: incorrect type in argument 1 (different address spaces) @@ expected void [noderef] <asn:1>*to @@ got sn:1>*to @@
drivers/gpu/drm/i915/gvt/kvmgt.c:610:34: expected void [noderef] <asn:1>*to
drivers/gpu/drm/i915/gvt/kvmgt.c:610:34: got char *buf
drivers/gpu/drm/i915/gvt/kvmgt.c:653:26: sparse: incorrect type in argument 1 (different address spaces) @@ expected void [noderef] <asn:1>*to @@ got sn:1>*to @@
drivers/gpu/drm/i915/gvt/kvmgt.c:653:26: expected void [noderef] <asn:1>*to
drivers/gpu/drm/i915/gvt/kvmgt.c:653:26: got char *buf
drivers/gpu/drm/i915/gvt/kvmgt.c:1119:21: sparse: incorrect type in assignment (different address spaces) @@ expected void *aperture_va @@ got void [noderef] <avoid *aperture_va @@
drivers/gpu/drm/i915/gvt/kvmgt.c:1119:21: expected void *aperture_va
drivers/gpu/drm/i915/gvt/kvmgt.c:1119:21: got void [noderef] <asn:2>*
drivers/gpu/drm/i915/gvt/kvmgt.c:1130:26: sparse: incorrect type in argument 1 (different address spaces) @@ expected void [noderef] <asn:2>*vaddr @@ got sn:2>*vaddr @@
drivers/gpu/drm/i915/gvt/kvmgt.c:1130:26: expected void [noderef] <asn:2>*vaddr
drivers/gpu/drm/i915/gvt/kvmgt.c:1130:26: got void *aperture_va
>> drivers/gpu/drm/i915/gvt/kvmgt.c:1211:45: sparse: cast removes address space of expression
drivers/gpu/drm/i915/gvt/kvmgt.c:1289:45: sparse: cast removes address space of expression
include/linux/slab.h:332:43: sparse: dubious: x & !y
vim +498 drivers/gpu/drm/i915/gvt/kvmgt.c
403
404 static size_t intel_vgpu_reg_rw_opregion(struct intel_vgpu *vgpu, char *buf,
405 size_t count, loff_t *ppos, bool iswrite)
406 {
407 unsigned int i = VFIO_PCI_OFFSET_TO_INDEX(*ppos) -
408 VFIO_PCI_NUM_REGIONS;
409 void *base = vgpu->vdev.region[i].data;
410 loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
411
412 if (pos >= vgpu->vdev.region[i].size || iswrite) {
413 gvt_vgpu_err("invalid op or offset for Intel vgpu OpRegion\n");
414 return -EINVAL;
415 }
> 416 count = min(count, (size_t)(vgpu->vdev.region[i].size - pos));
417 memcpy(buf, base + pos, count);
418
419 return 0;
420 }
421
422 static void intel_vgpu_reg_release_opregion(struct intel_vgpu *vgpu,
423 struct vfio_region *region)
424 {
425 }
426
427 static const struct intel_vgpu_regops intel_vgpu_regops_opregion = {
428 .rw = intel_vgpu_reg_rw_opregion,
429 .release = intel_vgpu_reg_release_opregion,
430 };
431
432 static size_t set_device_state(struct intel_vgpu *vgpu, u32 state)
433 {
434 int rc = 0;
435
436 switch (state) {
437 case VFIO_DEVICE_STATE_STOP:
438 intel_gvt_ops->vgpu_deactivate(vgpu);
439 break;
440 case VFIO_DEVICE_STATE_RUNNING:
441 intel_gvt_ops->vgpu_activate(vgpu);
442 break;
443 case VFIO_DEVICE_STATE_LOGGING | VFIO_DEVICE_STATE_RUNNING:
444 case VFIO_DEVICE_STATE_LOGGING | VFIO_DEVICE_STATE_STOP:
445 break;
446 default:
447 rc = -EFAULT;
448 }
449
450 return rc;
451 }
452
453 static void intel_vgpu_get_dirty_bitmap(struct intel_vgpu *vgpu,
454 u64 start_addr, u64 npage, void *bitmap)
455 {
456 u64 gfn = start_addr >> PAGE_SHIFT;
457 int i;
458
459 memset(bitmap, 0, MIGRATION_DIRTY_BITMAP_SIZE);
460
461 for (i = 0; i < npage; i++) {
462 mutex_lock(&vgpu->vdev.cache_lock);
463 if (__gvt_cache_find_gfn(vgpu, gfn))
464 set_bit(i, bitmap);
465
466 mutex_unlock(&vgpu->vdev.cache_lock);
467 gfn++;
468 }
469 }
470
471 static size_t intel_vgpu_reg_rw_state_ctl(struct intel_vgpu *vgpu,
472 char *buf, size_t count, loff_t *ppos, bool iswrite)
473 {
474 struct vfio_device_state_ctl *state_ctl;
475 loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
476 unsigned int i;
477 int rc = 0;
478 __u64 len;
479
480 state_ctl = vgpu->vdev.state_ctl;
481 if (!state_ctl) {
482 gvt_vgpu_err("invalid rw of state ctl region\n");
483 rc = -EFAULT;
484 goto exit;
485 }
486
487 i = VFIO_PCI_OFFSET_TO_INDEX(*ppos) - VFIO_PCI_NUM_REGIONS;
488 if (pos >= vgpu->vdev.region[i].size) {
489 gvt_vgpu_err("invalid offset for Intel vgpu state ctl region\n");
490 rc = -EINVAL;
491 goto exit;
492 }
493
494 #define CTL_OFFSET(x) offsetof(struct vfio_device_state_ctl, x)
495 switch (pos) {
496 case CTL_OFFSET(version):
497 if (!iswrite)
> 498 rc = copy_to_user(buf,
499 &state_ctl->version,
500 sizeof(state_ctl->version));
501 break;
502 case CTL_OFFSET(device_state):
503 if (!iswrite)
504 rc = copy_to_user(buf,
505 &state_ctl->device_state,
506 sizeof(state_ctl->device_state));
507 else {
508 u32 state;
509
> 510 if (copy_from_user(&state, buf, sizeof(state))) {
511 rc = -EFAULT;
512 goto exit;
513 }
514 set_device_state(vgpu, state);
515 }
516 break;
517 case CTL_OFFSET(caps):
518 if (!iswrite)
519 rc = copy_to_user(buf,
520 &state_ctl->caps,
521 sizeof(state_ctl->caps));
522 break;
523 case CTL_OFFSET(device_config.action):
524 if (iswrite) {
525 u32 action;
526 bool isset;
527
528 if (copy_from_user(&action, buf, sizeof(action))) {
529 rc = -EFAULT;
530 goto exit;
531 }
532 isset = (action ==
533 VFIO_DEVICE_DATA_ACTION_SET_BUFFER);
534 rc = intel_gvt_ops->vgpu_save_restore(vgpu,
535 NULL,
536 MIGRATION_IMG_MAX_SIZE,
537 vgpu->vdev.state_config,
538 0,
539 isset);
540 } else {
541 /* action read is not valid */
542 rc = -EINVAL;
543 }
544 break;
545 case CTL_OFFSET(device_config.size):
546 len = MIGRATION_IMG_MAX_SIZE;
547 if (!iswrite)
548 rc = copy_to_user(buf, &len, sizeof(len));
549 break;
550 case CTL_OFFSET(system_memory):
551 {
552 struct {
553 __u64 start_addr;
554 __u64 page_nr;
555 } system_memory;
556
557 void *bitmap = vgpu->vdev.state_bitmap;
558
559 if (count != sizeof(system_memory)) {
560 /* must write as a whole */
561 rc = -EINVAL;
562 goto exit;
563 }
564 if (!iswrite) {
565 /* action read is not valid */
566 rc = -EINVAL;
567 goto exit;
568 }
569 if (copy_from_user(&system_memory, buf,
570 sizeof(system_memory))) {
571 rc = -EFAULT;
572 goto exit;
573 }
574 intel_vgpu_get_dirty_bitmap(vgpu,
575 system_memory.start_addr,
576 system_memory.page_nr, bitmap);
577 }
578 break;
579 default:
580 break;
581 }
582 exit:
583 return rc;
584 }
585
586 static void intel_vgpu_reg_release_state_ctl(struct intel_vgpu *vgpu,
587 struct vfio_region *region)
588 {
589 vfree(region->data);
590 }
591
592 static size_t intel_vgpu_reg_rw_state_data_config(struct intel_vgpu *vgpu,
593 char *buf, size_t count, loff_t *ppos, bool iswrite)
594 {
595 loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
596 unsigned int i = VFIO_PCI_OFFSET_TO_INDEX(*ppos) - VFIO_PCI_NUM_REGIONS;
597 void *base = vgpu->vdev.region[i].data;
598 int rc = 0;
599
600 if (pos >= vgpu->vdev.region[i].size) {
601 gvt_vgpu_err("invalid offset to rw Intel vgpu state data region\n");
602 rc = -EINVAL;
603 goto exit;
604 }
605
606 if (iswrite) {
607 if (copy_from_user(base + pos, buf, count))
608 rc = -EFAULT;
609 } else {
610 if (copy_to_user(buf, base + pos, count))
611 rc = -EFAULT;
612 }
613
614 exit:
615 return rc;
616 }
617
618 static
619 void intel_vgpu_reg_release_state_data_config(struct intel_vgpu *vgpu,
620 struct vfio_region *region)
621 {
622 vfree(region->data);
623 }
624
625 static
626 int intel_vgpu_reg_mmap_state_data_config(struct intel_vgpu *vgpu,
627 struct vm_area_struct *vma)
628 {
629 unsigned long pgoff = 0;
630 void *base = vgpu->vdev.state_config;
631
632 pgoff = vma->vm_pgoff &
633 ((1U << (VFIO_PCI_OFFSET_SHIFT - PAGE_SHIFT)) - 1);
634
635 if (pgoff != 0)
636 return -EINVAL;
637
638 return remap_vmalloc_range(vma, base, 0);
639 }
640
641 static size_t intel_vgpu_reg_rw_state_bitmap(struct intel_vgpu *vgpu,
642 char *buf, size_t count, loff_t *ppos, bool iswrite)
643 {
644 loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
645 unsigned int i = VFIO_PCI_OFFSET_TO_INDEX(*ppos) -
646 VFIO_PCI_NUM_REGIONS;
647 void *base = vgpu->vdev.region[i].data;
648 int rc = 0;
649
650 if (iswrite || pos != 0)
651 return -EINVAL;
652
> 653 if (copy_to_user(buf, base, count))
654 rc = -EFAULT;
655
656 return 0;
657 }
658
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
More information about the intel-gvt-dev
mailing list