Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

virtio/s390: use DMA memory for ccw I/O and classic notifiers

Before virtio-ccw could get away with not using DMA API for the pieces of
memory it does ccw I/O with. With protected virtualization this has to
change, since the hypervisor needs to read and sometimes also write these
pieces of memory.

The hypervisor is supposed to poke the classic notifiers, if these are
used, out of band with regards to ccw I/O. So these need to be allocated
as DMA memory (which is shared memory for protected virtualization
guests).

Let us factor out everything from struct virtio_ccw_device that needs to
be DMA memory in a satellite that is allocated as such.

Note: The control blocks of I/O instructions do not need to be shared.
These are marshalled by the ultravisor.

Signed-off-by: Halil Pasic <pasic@linux.ibm.com>
Reviewed-by: Pierre Morel <pmorel@linux.ibm.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Reviewed-by: Michael Mueller <mimu@linux.ibm.com>
Tested-by: Michael Mueller <mimu@linux.ibm.com>
Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com>

authored by

Halil Pasic and committed by
Heiko Carstens
48720ba5 22a4a639

+89 -80
+89 -80
drivers/s390/virtio/virtio_ccw.c
··· 46 46 #define VIRTIO_CCW_CONFIG_SIZE 0x100 47 47 /* same as PCI config space size, should be enough for all drivers */ 48 48 49 + struct vcdev_dma_area { 50 + unsigned long indicators; 51 + unsigned long indicators2; 52 + struct vq_config_block config_block; 53 + __u8 status; 54 + }; 55 + 49 56 struct virtio_ccw_device { 50 57 struct virtio_device vdev; 51 - __u8 *status; 52 58 __u8 config[VIRTIO_CCW_CONFIG_SIZE]; 53 59 struct ccw_device *cdev; 54 60 __u32 curr_io; ··· 64 58 spinlock_t lock; 65 59 struct mutex io_lock; /* Serializes I/O requests */ 66 60 struct list_head virtqueues; 67 - unsigned long indicators; 68 - unsigned long indicators2; 69 - struct vq_config_block *config_block; 70 61 bool is_thinint; 71 62 bool going_away; 72 63 bool device_lost; 73 64 unsigned int config_ready; 74 65 void *airq_info; 66 + struct vcdev_dma_area *dma_area; 75 67 }; 76 68 77 69 static inline unsigned long *indicators(struct virtio_ccw_device *vcdev) 78 70 { 79 - return &vcdev->indicators; 71 + return &vcdev->dma_area->indicators; 80 72 } 81 73 82 74 static inline unsigned long *indicators2(struct virtio_ccw_device *vcdev) 83 75 { 84 - return &vcdev->indicators2; 76 + return &vcdev->dma_area->indicators2; 85 77 } 86 78 87 79 struct vq_info_block_legacy { ··· 340 336 struct airq_info *airq_info = vcdev->airq_info; 341 337 342 338 if (vcdev->is_thinint) { 343 - thinint_area = kzalloc(sizeof(*thinint_area), 344 - GFP_DMA | GFP_KERNEL); 339 + thinint_area = ccw_device_dma_zalloc(vcdev->cdev, 340 + sizeof(*thinint_area)); 345 341 if (!thinint_area) 346 342 return; 347 343 thinint_area->summary_indicator = ··· 352 348 ccw->cda = (__u32)(unsigned long) thinint_area; 353 349 } else { 354 350 /* payload is the address of the indicators */ 355 - indicatorp = kmalloc(sizeof(indicators(vcdev)), 356 - GFP_DMA | GFP_KERNEL); 351 + indicatorp = ccw_device_dma_zalloc(vcdev->cdev, 352 + sizeof(indicators(vcdev))); 357 353 if (!indicatorp) 358 354 return; 359 355 *indicatorp = 0; ··· 373 369 "Failed to deregister indicators (%d)\n", ret); 374 370 else if (vcdev->is_thinint) 375 371 virtio_ccw_drop_indicators(vcdev); 376 - kfree(indicatorp); 377 - kfree(thinint_area); 372 + ccw_device_dma_free(vcdev->cdev, indicatorp, sizeof(indicators(vcdev))); 373 + ccw_device_dma_free(vcdev->cdev, thinint_area, sizeof(*thinint_area)); 378 374 } 379 375 380 376 static inline long __do_kvm_notify(struct subchannel_id schid, ··· 421 417 { 422 418 int ret; 423 419 424 - vcdev->config_block->index = index; 420 + vcdev->dma_area->config_block.index = index; 425 421 ccw->cmd_code = CCW_CMD_READ_VQ_CONF; 426 422 ccw->flags = 0; 427 423 ccw->count = sizeof(struct vq_config_block); 428 - ccw->cda = (__u32)(unsigned long)(vcdev->config_block); 424 + ccw->cda = (__u32)(unsigned long)(&vcdev->dma_area->config_block); 429 425 ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_READ_VQ_CONF); 430 426 if (ret) 431 427 return ret; 432 - return vcdev->config_block->num ?: -ENOENT; 428 + return vcdev->dma_area->config_block.num ?: -ENOENT; 433 429 } 434 430 435 431 static void virtio_ccw_del_vq(struct virtqueue *vq, struct ccw1 *ccw) ··· 474 470 ret, index); 475 471 476 472 vring_del_virtqueue(vq); 477 - kfree(info->info_block); 473 + ccw_device_dma_free(vcdev->cdev, info->info_block, 474 + sizeof(*info->info_block)); 478 475 kfree(info); 479 476 } 480 477 ··· 485 480 struct ccw1 *ccw; 486 481 struct virtio_ccw_device *vcdev = to_vc_device(vdev); 487 482 488 - ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); 483 + ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw)); 489 484 if (!ccw) 490 485 return; 491 486 ··· 494 489 list_for_each_entry_safe(vq, n, &vdev->vqs, list) 495 490 virtio_ccw_del_vq(vq, ccw); 496 491 497 - kfree(ccw); 492 + ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw)); 498 493 } 499 494 500 495 static struct virtqueue *virtio_ccw_setup_vq(struct virtio_device *vdev, ··· 517 512 err = -ENOMEM; 518 513 goto out_err; 519 514 } 520 - info->info_block = kzalloc(sizeof(*info->info_block), 521 - GFP_DMA | GFP_KERNEL); 515 + info->info_block = ccw_device_dma_zalloc(vcdev->cdev, 516 + sizeof(*info->info_block)); 522 517 if (!info->info_block) { 523 518 dev_warn(&vcdev->cdev->dev, "no info block\n"); 524 519 err = -ENOMEM; ··· 582 577 if (vq) 583 578 vring_del_virtqueue(vq); 584 579 if (info) { 585 - kfree(info->info_block); 580 + ccw_device_dma_free(vcdev->cdev, info->info_block, 581 + sizeof(*info->info_block)); 586 582 } 587 583 kfree(info); 588 584 return ERR_PTR(err); ··· 597 591 struct virtio_thinint_area *thinint_area = NULL; 598 592 struct airq_info *info; 599 593 600 - thinint_area = kzalloc(sizeof(*thinint_area), GFP_DMA | GFP_KERNEL); 594 + thinint_area = ccw_device_dma_zalloc(vcdev->cdev, 595 + sizeof(*thinint_area)); 601 596 if (!thinint_area) { 602 597 ret = -ENOMEM; 603 598 goto out; ··· 634 627 virtio_ccw_drop_indicators(vcdev); 635 628 } 636 629 out: 637 - kfree(thinint_area); 630 + ccw_device_dma_free(vcdev->cdev, thinint_area, sizeof(*thinint_area)); 638 631 return ret; 639 632 } 640 633 ··· 650 643 int ret, i, queue_idx = 0; 651 644 struct ccw1 *ccw; 652 645 653 - ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); 646 + ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw)); 654 647 if (!ccw) 655 648 return -ENOMEM; 656 649 ··· 674 667 * We need a data area under 2G to communicate. Our payload is 675 668 * the address of the indicators. 676 669 */ 677 - indicatorp = kmalloc(sizeof(indicators(vcdev)), GFP_DMA | GFP_KERNEL); 670 + indicatorp = ccw_device_dma_zalloc(vcdev->cdev, 671 + sizeof(indicators(vcdev))); 678 672 if (!indicatorp) 679 673 goto out; 680 674 *indicatorp = (unsigned long) indicators(vcdev); ··· 707 699 if (ret) 708 700 goto out; 709 701 710 - kfree(indicatorp); 711 - kfree(ccw); 702 + if (indicatorp) 703 + ccw_device_dma_free(vcdev->cdev, indicatorp, 704 + sizeof(indicators(vcdev))); 705 + ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw)); 712 706 return 0; 713 707 out: 714 - kfree(indicatorp); 715 - kfree(ccw); 708 + if (indicatorp) 709 + ccw_device_dma_free(vcdev->cdev, indicatorp, 710 + sizeof(indicators(vcdev))); 711 + ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw)); 716 712 virtio_ccw_del_vqs(vdev); 717 713 return ret; 718 714 } ··· 726 714 struct virtio_ccw_device *vcdev = to_vc_device(vdev); 727 715 struct ccw1 *ccw; 728 716 729 - ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); 717 + ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw)); 730 718 if (!ccw) 731 719 return; 732 720 733 721 /* Zero status bits. */ 734 - *vcdev->status = 0; 722 + vcdev->dma_area->status = 0; 735 723 736 724 /* Send a reset ccw on device. */ 737 725 ccw->cmd_code = CCW_CMD_VDEV_RESET; ··· 739 727 ccw->count = 0; 740 728 ccw->cda = 0; 741 729 ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_RESET); 742 - kfree(ccw); 730 + ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw)); 743 731 } 744 732 745 733 static u64 virtio_ccw_get_features(struct virtio_device *vdev) ··· 750 738 u64 rc; 751 739 struct ccw1 *ccw; 752 740 753 - ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); 741 + ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw)); 754 742 if (!ccw) 755 743 return 0; 756 744 757 - features = kzalloc(sizeof(*features), GFP_DMA | GFP_KERNEL); 745 + features = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*features)); 758 746 if (!features) { 759 747 rc = 0; 760 748 goto out_free; ··· 787 775 rc |= (u64)le32_to_cpu(features->features) << 32; 788 776 789 777 out_free: 790 - kfree(features); 791 - kfree(ccw); 778 + ccw_device_dma_free(vcdev->cdev, features, sizeof(*features)); 779 + ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw)); 792 780 return rc; 793 781 } 794 782 ··· 813 801 return -EINVAL; 814 802 } 815 803 816 - ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); 804 + ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw)); 817 805 if (!ccw) 818 806 return -ENOMEM; 819 807 820 - features = kzalloc(sizeof(*features), GFP_DMA | GFP_KERNEL); 808 + features = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*features)); 821 809 if (!features) { 822 810 ret = -ENOMEM; 823 811 goto out_free; ··· 852 840 ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_FEAT); 853 841 854 842 out_free: 855 - kfree(features); 856 - kfree(ccw); 843 + ccw_device_dma_free(vcdev->cdev, features, sizeof(*features)); 844 + ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw)); 857 845 858 846 return ret; 859 847 } ··· 867 855 void *config_area; 868 856 unsigned long flags; 869 857 870 - ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); 858 + ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw)); 871 859 if (!ccw) 872 860 return; 873 861 874 - config_area = kzalloc(VIRTIO_CCW_CONFIG_SIZE, GFP_DMA | GFP_KERNEL); 862 + config_area = ccw_device_dma_zalloc(vcdev->cdev, 863 + VIRTIO_CCW_CONFIG_SIZE); 875 864 if (!config_area) 876 865 goto out_free; 877 866 ··· 894 881 memcpy(buf, config_area + offset, len); 895 882 896 883 out_free: 897 - kfree(config_area); 898 - kfree(ccw); 884 + ccw_device_dma_free(vcdev->cdev, config_area, VIRTIO_CCW_CONFIG_SIZE); 885 + ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw)); 899 886 } 900 887 901 888 static void virtio_ccw_set_config(struct virtio_device *vdev, ··· 907 894 void *config_area; 908 895 unsigned long flags; 909 896 910 - ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); 897 + ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw)); 911 898 if (!ccw) 912 899 return; 913 900 914 - config_area = kzalloc(VIRTIO_CCW_CONFIG_SIZE, GFP_DMA | GFP_KERNEL); 901 + config_area = ccw_device_dma_zalloc(vcdev->cdev, 902 + VIRTIO_CCW_CONFIG_SIZE); 915 903 if (!config_area) 916 904 goto out_free; 917 905 ··· 931 917 ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_CONFIG); 932 918 933 919 out_free: 934 - kfree(config_area); 935 - kfree(ccw); 920 + ccw_device_dma_free(vcdev->cdev, config_area, VIRTIO_CCW_CONFIG_SIZE); 921 + ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw)); 936 922 } 937 923 938 924 static u8 virtio_ccw_get_status(struct virtio_device *vdev) 939 925 { 940 926 struct virtio_ccw_device *vcdev = to_vc_device(vdev); 941 - u8 old_status = *vcdev->status; 927 + u8 old_status = vcdev->dma_area->status; 942 928 struct ccw1 *ccw; 943 929 944 930 if (vcdev->revision < 1) 945 - return *vcdev->status; 931 + return vcdev->dma_area->status; 946 932 947 - ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); 933 + ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw)); 948 934 if (!ccw) 949 935 return old_status; 950 936 951 937 ccw->cmd_code = CCW_CMD_READ_STATUS; 952 938 ccw->flags = 0; 953 - ccw->count = sizeof(*vcdev->status); 954 - ccw->cda = (__u32)(unsigned long)vcdev->status; 939 + ccw->count = sizeof(vcdev->dma_area->status); 940 + ccw->cda = (__u32)(unsigned long)&vcdev->dma_area->status; 955 941 ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_READ_STATUS); 956 942 /* 957 943 * If the channel program failed (should only happen if the device 958 944 * was hotunplugged, and then we clean up via the machine check 959 - * handler anyway), vcdev->status was not overwritten and we just 945 + * handler anyway), vcdev->dma_area->status was not overwritten and we just 960 946 * return the old status, which is fine. 961 947 */ 962 - kfree(ccw); 948 + ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw)); 963 949 964 - return *vcdev->status; 950 + return vcdev->dma_area->status; 965 951 } 966 952 967 953 static void virtio_ccw_set_status(struct virtio_device *vdev, u8 status) 968 954 { 969 955 struct virtio_ccw_device *vcdev = to_vc_device(vdev); 970 - u8 old_status = *vcdev->status; 956 + u8 old_status = vcdev->dma_area->status; 971 957 struct ccw1 *ccw; 972 958 int ret; 973 959 974 - ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); 960 + ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw)); 975 961 if (!ccw) 976 962 return; 977 963 978 964 /* Write the status to the host. */ 979 - *vcdev->status = status; 965 + vcdev->dma_area->status = status; 980 966 ccw->cmd_code = CCW_CMD_WRITE_STATUS; 981 967 ccw->flags = 0; 982 968 ccw->count = sizeof(status); 983 - ccw->cda = (__u32)(unsigned long)vcdev->status; 969 + ccw->cda = (__u32)(unsigned long)&vcdev->dma_area->status; 984 970 ret = ccw_io_helper(vcdev, ccw, VIRTIO_CCW_DOING_WRITE_STATUS); 985 971 /* Write failed? We assume status is unchanged. */ 986 972 if (ret) 987 - *vcdev->status = old_status; 988 - kfree(ccw); 973 + vcdev->dma_area->status = old_status; 974 + ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw)); 989 975 } 990 976 991 977 static const char *virtio_ccw_bus_name(struct virtio_device *vdev) ··· 1018 1004 struct virtio_device *dev = dev_to_virtio(_d); 1019 1005 struct virtio_ccw_device *vcdev = to_vc_device(dev); 1020 1006 1021 - kfree(vcdev->status); 1022 - kfree(vcdev->config_block); 1007 + ccw_device_dma_free(vcdev->cdev, vcdev->dma_area, 1008 + sizeof(*vcdev->dma_area)); 1023 1009 kfree(vcdev); 1024 1010 } 1025 1011 ··· 1227 1213 struct ccw1 *ccw; 1228 1214 int ret; 1229 1215 1230 - ccw = kzalloc(sizeof(*ccw), GFP_DMA | GFP_KERNEL); 1216 + ccw = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*ccw)); 1231 1217 if (!ccw) 1232 1218 return -ENOMEM; 1233 - rev = kzalloc(sizeof(*rev), GFP_DMA | GFP_KERNEL); 1219 + rev = ccw_device_dma_zalloc(vcdev->cdev, sizeof(*rev)); 1234 1220 if (!rev) { 1235 - kfree(ccw); 1221 + ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw)); 1236 1222 return -ENOMEM; 1237 1223 } 1238 1224 ··· 1262 1248 } 1263 1249 } while (ret == -EOPNOTSUPP); 1264 1250 1265 - kfree(ccw); 1266 - kfree(rev); 1251 + ccw_device_dma_free(vcdev->cdev, ccw, sizeof(*ccw)); 1252 + ccw_device_dma_free(vcdev->cdev, rev, sizeof(*rev)); 1267 1253 return ret; 1268 1254 } 1269 1255 ··· 1280 1266 goto out_free; 1281 1267 } 1282 1268 vcdev->vdev.dev.parent = &cdev->dev; 1283 - vcdev->config_block = kzalloc(sizeof(*vcdev->config_block), 1284 - GFP_DMA | GFP_KERNEL); 1285 - if (!vcdev->config_block) { 1286 - ret = -ENOMEM; 1287 - goto out_free; 1288 - } 1289 - vcdev->status = kzalloc(sizeof(*vcdev->status), GFP_DMA | GFP_KERNEL); 1290 - if (!vcdev->status) { 1269 + vcdev->cdev = cdev; 1270 + vcdev->dma_area = ccw_device_dma_zalloc(vcdev->cdev, 1271 + sizeof(*vcdev->dma_area)); 1272 + if (!vcdev->dma_area) { 1291 1273 ret = -ENOMEM; 1292 1274 goto out_free; 1293 1275 } ··· 1292 1282 1293 1283 vcdev->vdev.dev.release = virtio_ccw_release_dev; 1294 1284 vcdev->vdev.config = &virtio_ccw_config_ops; 1295 - vcdev->cdev = cdev; 1296 1285 init_waitqueue_head(&vcdev->wait_q); 1297 1286 INIT_LIST_HEAD(&vcdev->virtqueues); 1298 1287 spin_lock_init(&vcdev->lock); ··· 1322 1313 return ret; 1323 1314 out_free: 1324 1315 if (vcdev) { 1325 - kfree(vcdev->status); 1326 - kfree(vcdev->config_block); 1316 + ccw_device_dma_free(vcdev->cdev, vcdev->dma_area, 1317 + sizeof(*vcdev->dma_area)); 1327 1318 } 1328 1319 kfree(vcdev); 1329 1320 return ret;