From: kbuild test robot <lkp@intel.com>
To: kbuild@lists.01.org
Subject: Re: [PATCH v3 3/3] vfio-pci: Invalidate mmaps and block MMIO access on disabled memory
Date: Mon, 25 May 2020 18:09:07 +0800 [thread overview]
Message-ID: <202005251817.h2rt0LjL%lkp@intel.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 49807 bytes --]
CC: kbuild-all(a)lists.01.org
In-Reply-To: <159017506369.18853.17306023099999811263.stgit@gimli.home>
References: <159017506369.18853.17306023099999811263.stgit@gimli.home>
TO: Alex Williamson <alex.williamson@redhat.com>
Hi Alex,
I love your patch! Perhaps something to improve:
[auto build test WARNING on linus/master]
[also build test WARNING on v5.7-rc7]
[cannot apply to vfio/next linux/master next-20200522]
[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/Alex-Williamson/vfio-pci-Block-user-access-to-disabled-device-MMIO/20200523-031907
base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 4286d192c803571e8ca43b0f1f8ea04d663a278a
:::::: branch date: 3 days ago
:::::: commit date: 3 days ago
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce (this is a W=1 build):
# save the attached .config to linux build tree
make W=1 ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>
cppcheck warnings: (new ones prefixed by >>)
>> drivers/vfio/pci/vfio_pci.c:820:8: warning: Local variable 'cmd' shadows outer argument [shadowArgument]
u16 cmd;
^
drivers/vfio/pci/vfio_pci.c:748:20: note: Shadowed declaration
unsigned int cmd, unsigned long arg)
^
drivers/vfio/pci/vfio_pci.c:820:8: note: Shadow variable
u16 cmd;
^
>> drivers/vfio/vfio_iommu_type1.c:1226:12: warning: Local variable 'n' shadows outer variable [shadowVariable]
size_t n = dma->iova + dma->size - iova;
^
drivers/vfio/vfio_iommu_type1.c:1183:18: note: Shadowed declaration
struct rb_node *n;
^
drivers/vfio/vfio_iommu_type1.c:1226:12: note: Shadow variable
size_t n = dma->iova + dma->size - iova;
^
# https://github.com/0day-ci/linux/commit/3c9d9870c815814c4891775ab2950062e014a85c
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 3c9d9870c815814c4891775ab2950062e014a85c
vim +/cmd +820 drivers/vfio/pci/vfio_pci.c
3c9d9870c81581 Alex Williamson 2020-05-22 746
89e1f7d4c66d85 Alex Williamson 2012-07-31 747 static long vfio_pci_ioctl(void *device_data,
89e1f7d4c66d85 Alex Williamson 2012-07-31 748 unsigned int cmd, unsigned long arg)
89e1f7d4c66d85 Alex Williamson 2012-07-31 749 {
89e1f7d4c66d85 Alex Williamson 2012-07-31 750 struct vfio_pci_device *vdev = device_data;
89e1f7d4c66d85 Alex Williamson 2012-07-31 751 unsigned long minsz;
89e1f7d4c66d85 Alex Williamson 2012-07-31 752
89e1f7d4c66d85 Alex Williamson 2012-07-31 753 if (cmd == VFIO_DEVICE_GET_INFO) {
89e1f7d4c66d85 Alex Williamson 2012-07-31 754 struct vfio_device_info info;
89e1f7d4c66d85 Alex Williamson 2012-07-31 755
89e1f7d4c66d85 Alex Williamson 2012-07-31 756 minsz = offsetofend(struct vfio_device_info, num_irqs);
89e1f7d4c66d85 Alex Williamson 2012-07-31 757
89e1f7d4c66d85 Alex Williamson 2012-07-31 758 if (copy_from_user(&info, (void __user *)arg, minsz))
89e1f7d4c66d85 Alex Williamson 2012-07-31 759 return -EFAULT;
89e1f7d4c66d85 Alex Williamson 2012-07-31 760
89e1f7d4c66d85 Alex Williamson 2012-07-31 761 if (info.argsz < minsz)
89e1f7d4c66d85 Alex Williamson 2012-07-31 762 return -EINVAL;
89e1f7d4c66d85 Alex Williamson 2012-07-31 763
89e1f7d4c66d85 Alex Williamson 2012-07-31 764 info.flags = VFIO_DEVICE_FLAGS_PCI;
89e1f7d4c66d85 Alex Williamson 2012-07-31 765
89e1f7d4c66d85 Alex Williamson 2012-07-31 766 if (vdev->reset_works)
89e1f7d4c66d85 Alex Williamson 2012-07-31 767 info.flags |= VFIO_DEVICE_FLAGS_RESET;
89e1f7d4c66d85 Alex Williamson 2012-07-31 768
28541d41c9e04c Alex Williamson 2016-02-22 769 info.num_regions = VFIO_PCI_NUM_REGIONS + vdev->num_regions;
89e1f7d4c66d85 Alex Williamson 2012-07-31 770 info.num_irqs = VFIO_PCI_NUM_IRQS;
89e1f7d4c66d85 Alex Williamson 2012-07-31 771
8160c4e455820d Michael S. Tsirkin 2016-02-28 772 return copy_to_user((void __user *)arg, &info, minsz) ?
8160c4e455820d Michael S. Tsirkin 2016-02-28 773 -EFAULT : 0;
89e1f7d4c66d85 Alex Williamson 2012-07-31 774
89e1f7d4c66d85 Alex Williamson 2012-07-31 775 } else if (cmd == VFIO_DEVICE_GET_REGION_INFO) {
89e1f7d4c66d85 Alex Williamson 2012-07-31 776 struct pci_dev *pdev = vdev->pdev;
89e1f7d4c66d85 Alex Williamson 2012-07-31 777 struct vfio_region_info info;
188ad9d6cbbce4 Alex Williamson 2016-02-22 778 struct vfio_info_cap caps = { .buf = NULL, .size = 0 };
28541d41c9e04c Alex Williamson 2016-02-22 779 int i, ret;
89e1f7d4c66d85 Alex Williamson 2012-07-31 780
89e1f7d4c66d85 Alex Williamson 2012-07-31 781 minsz = offsetofend(struct vfio_region_info, offset);
89e1f7d4c66d85 Alex Williamson 2012-07-31 782
89e1f7d4c66d85 Alex Williamson 2012-07-31 783 if (copy_from_user(&info, (void __user *)arg, minsz))
89e1f7d4c66d85 Alex Williamson 2012-07-31 784 return -EFAULT;
89e1f7d4c66d85 Alex Williamson 2012-07-31 785
89e1f7d4c66d85 Alex Williamson 2012-07-31 786 if (info.argsz < minsz)
89e1f7d4c66d85 Alex Williamson 2012-07-31 787 return -EINVAL;
89e1f7d4c66d85 Alex Williamson 2012-07-31 788
89e1f7d4c66d85 Alex Williamson 2012-07-31 789 switch (info.index) {
89e1f7d4c66d85 Alex Williamson 2012-07-31 790 case VFIO_PCI_CONFIG_REGION_INDEX:
89e1f7d4c66d85 Alex Williamson 2012-07-31 791 info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
89e1f7d4c66d85 Alex Williamson 2012-07-31 792 info.size = pdev->cfg_size;
89e1f7d4c66d85 Alex Williamson 2012-07-31 793 info.flags = VFIO_REGION_INFO_FLAG_READ |
89e1f7d4c66d85 Alex Williamson 2012-07-31 794 VFIO_REGION_INFO_FLAG_WRITE;
89e1f7d4c66d85 Alex Williamson 2012-07-31 795 break;
89e1f7d4c66d85 Alex Williamson 2012-07-31 796 case VFIO_PCI_BAR0_REGION_INDEX ... VFIO_PCI_BAR5_REGION_INDEX:
89e1f7d4c66d85 Alex Williamson 2012-07-31 797 info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
89e1f7d4c66d85 Alex Williamson 2012-07-31 798 info.size = pci_resource_len(pdev, info.index);
89e1f7d4c66d85 Alex Williamson 2012-07-31 799 if (!info.size) {
89e1f7d4c66d85 Alex Williamson 2012-07-31 800 info.flags = 0;
89e1f7d4c66d85 Alex Williamson 2012-07-31 801 break;
89e1f7d4c66d85 Alex Williamson 2012-07-31 802 }
89e1f7d4c66d85 Alex Williamson 2012-07-31 803
89e1f7d4c66d85 Alex Williamson 2012-07-31 804 info.flags = VFIO_REGION_INFO_FLAG_READ |
89e1f7d4c66d85 Alex Williamson 2012-07-31 805 VFIO_REGION_INFO_FLAG_WRITE;
05f0c03fbac181 Yongji Xie 2016-06-30 806 if (vdev->bar_mmap_supported[info.index]) {
89e1f7d4c66d85 Alex Williamson 2012-07-31 807 info.flags |= VFIO_REGION_INFO_FLAG_MMAP;
188ad9d6cbbce4 Alex Williamson 2016-02-22 808 if (info.index == vdev->msix_bar) {
a32295c612c579 Alexey Kardashevskiy 2017-12-13 809 ret = msix_mmappable_cap(vdev, &caps);
188ad9d6cbbce4 Alex Williamson 2016-02-22 810 if (ret)
188ad9d6cbbce4 Alex Williamson 2016-02-22 811 return ret;
188ad9d6cbbce4 Alex Williamson 2016-02-22 812 }
188ad9d6cbbce4 Alex Williamson 2016-02-22 813 }
188ad9d6cbbce4 Alex Williamson 2016-02-22 814
89e1f7d4c66d85 Alex Williamson 2012-07-31 815 break;
89e1f7d4c66d85 Alex Williamson 2012-07-31 816 case VFIO_PCI_ROM_REGION_INDEX:
89e1f7d4c66d85 Alex Williamson 2012-07-31 817 {
89e1f7d4c66d85 Alex Williamson 2012-07-31 818 void __iomem *io;
89e1f7d4c66d85 Alex Williamson 2012-07-31 819 size_t size;
3c9d9870c81581 Alex Williamson 2020-05-22 @820 u16 cmd;
89e1f7d4c66d85 Alex Williamson 2012-07-31 821
89e1f7d4c66d85 Alex Williamson 2012-07-31 822 info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
89e1f7d4c66d85 Alex Williamson 2012-07-31 823 info.flags = 0;
89e1f7d4c66d85 Alex Williamson 2012-07-31 824
89e1f7d4c66d85 Alex Williamson 2012-07-31 825 /* Report the BAR size, not the ROM size */
89e1f7d4c66d85 Alex Williamson 2012-07-31 826 info.size = pci_resource_len(pdev, info.index);
a13b64591747e8 Alex Williamson 2016-02-22 827 if (!info.size) {
a13b64591747e8 Alex Williamson 2016-02-22 828 /* Shadow ROMs appear as PCI option ROMs */
a13b64591747e8 Alex Williamson 2016-02-22 829 if (pdev->resource[PCI_ROM_RESOURCE].flags &
a13b64591747e8 Alex Williamson 2016-02-22 830 IORESOURCE_ROM_SHADOW)
a13b64591747e8 Alex Williamson 2016-02-22 831 info.size = 0x20000;
a13b64591747e8 Alex Williamson 2016-02-22 832 else
89e1f7d4c66d85 Alex Williamson 2012-07-31 833 break;
a13b64591747e8 Alex Williamson 2016-02-22 834 }
89e1f7d4c66d85 Alex Williamson 2012-07-31 835
0cfd027be1d6de Eric Auger 2019-02-15 836 /*
0cfd027be1d6de Eric Auger 2019-02-15 837 * Is it really there? Enable memory decode for
0cfd027be1d6de Eric Auger 2019-02-15 838 * implicit access in pci_map_rom().
0cfd027be1d6de Eric Auger 2019-02-15 839 */
3c9d9870c81581 Alex Williamson 2020-05-22 840 cmd = vfio_pci_memory_lock_and_enable(vdev);
89e1f7d4c66d85 Alex Williamson 2012-07-31 841 io = pci_map_rom(pdev, &size);
0cfd027be1d6de Eric Auger 2019-02-15 842 if (io) {
0cfd027be1d6de Eric Auger 2019-02-15 843 info.flags = VFIO_REGION_INFO_FLAG_READ;
0cfd027be1d6de Eric Auger 2019-02-15 844 pci_unmap_rom(pdev, io);
0cfd027be1d6de Eric Auger 2019-02-15 845 } else {
89e1f7d4c66d85 Alex Williamson 2012-07-31 846 info.size = 0;
89e1f7d4c66d85 Alex Williamson 2012-07-31 847 }
3c9d9870c81581 Alex Williamson 2020-05-22 848 vfio_pci_memory_unlock_and_restore(vdev, cmd);
89e1f7d4c66d85 Alex Williamson 2012-07-31 849
89e1f7d4c66d85 Alex Williamson 2012-07-31 850 break;
89e1f7d4c66d85 Alex Williamson 2012-07-31 851 }
84237a826b261d Alex Williamson 2013-02-18 852 case VFIO_PCI_VGA_REGION_INDEX:
84237a826b261d Alex Williamson 2013-02-18 853 if (!vdev->has_vga)
84237a826b261d Alex Williamson 2013-02-18 854 return -EINVAL;
84237a826b261d Alex Williamson 2013-02-18 855
84237a826b261d Alex Williamson 2013-02-18 856 info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
84237a826b261d Alex Williamson 2013-02-18 857 info.size = 0xc0000;
84237a826b261d Alex Williamson 2013-02-18 858 info.flags = VFIO_REGION_INFO_FLAG_READ |
84237a826b261d Alex Williamson 2013-02-18 859 VFIO_REGION_INFO_FLAG_WRITE;
84237a826b261d Alex Williamson 2013-02-18 860
84237a826b261d Alex Williamson 2013-02-18 861 break;
89e1f7d4c66d85 Alex Williamson 2012-07-31 862 default:
c535d34569bbc6 Kirti Wankhede 2016-11-17 863 {
dda01f787df9f9 Alex Williamson 2017-12-12 864 struct vfio_region_info_cap_type cap_type = {
dda01f787df9f9 Alex Williamson 2017-12-12 865 .header.id = VFIO_REGION_INFO_CAP_TYPE,
dda01f787df9f9 Alex Williamson 2017-12-12 866 .header.version = 1 };
c535d34569bbc6 Kirti Wankhede 2016-11-17 867
28541d41c9e04c Alex Williamson 2016-02-22 868 if (info.index >=
28541d41c9e04c Alex Williamson 2016-02-22 869 VFIO_PCI_NUM_REGIONS + vdev->num_regions)
89e1f7d4c66d85 Alex Williamson 2012-07-31 870 return -EINVAL;
0e714d27786ce1 Gustavo A. R. Silva 2018-07-17 871 info.index = array_index_nospec(info.index,
0e714d27786ce1 Gustavo A. R. Silva 2018-07-17 872 VFIO_PCI_NUM_REGIONS +
0e714d27786ce1 Gustavo A. R. Silva 2018-07-17 873 vdev->num_regions);
28541d41c9e04c Alex Williamson 2016-02-22 874
28541d41c9e04c Alex Williamson 2016-02-22 875 i = info.index - VFIO_PCI_NUM_REGIONS;
28541d41c9e04c Alex Williamson 2016-02-22 876
28541d41c9e04c Alex Williamson 2016-02-22 877 info.offset = VFIO_PCI_INDEX_TO_OFFSET(info.index);
28541d41c9e04c Alex Williamson 2016-02-22 878 info.size = vdev->region[i].size;
28541d41c9e04c Alex Williamson 2016-02-22 879 info.flags = vdev->region[i].flags;
28541d41c9e04c Alex Williamson 2016-02-22 880
c535d34569bbc6 Kirti Wankhede 2016-11-17 881 cap_type.type = vdev->region[i].type;
c535d34569bbc6 Kirti Wankhede 2016-11-17 882 cap_type.subtype = vdev->region[i].subtype;
c535d34569bbc6 Kirti Wankhede 2016-11-17 883
dda01f787df9f9 Alex Williamson 2017-12-12 884 ret = vfio_info_add_capability(&caps, &cap_type.header,
dda01f787df9f9 Alex Williamson 2017-12-12 885 sizeof(cap_type));
28541d41c9e04c Alex Williamson 2016-02-22 886 if (ret)
28541d41c9e04c Alex Williamson 2016-02-22 887 return ret;
c535d34569bbc6 Kirti Wankhede 2016-11-17 888
c2c0f1cde0ef56 Alexey Kardashevskiy 2018-12-19 889 if (vdev->region[i].ops->add_capability) {
c2c0f1cde0ef56 Alexey Kardashevskiy 2018-12-19 890 ret = vdev->region[i].ops->add_capability(vdev,
c2c0f1cde0ef56 Alexey Kardashevskiy 2018-12-19 891 &vdev->region[i], &caps);
c2c0f1cde0ef56 Alexey Kardashevskiy 2018-12-19 892 if (ret)
c2c0f1cde0ef56 Alexey Kardashevskiy 2018-12-19 893 return ret;
c2c0f1cde0ef56 Alexey Kardashevskiy 2018-12-19 894 }
c535d34569bbc6 Kirti Wankhede 2016-11-17 895 }
89e1f7d4c66d85 Alex Williamson 2012-07-31 896 }
89e1f7d4c66d85 Alex Williamson 2012-07-31 897
188ad9d6cbbce4 Alex Williamson 2016-02-22 898 if (caps.size) {
188ad9d6cbbce4 Alex Williamson 2016-02-22 899 info.flags |= VFIO_REGION_INFO_FLAG_CAPS;
188ad9d6cbbce4 Alex Williamson 2016-02-22 900 if (info.argsz < sizeof(info) + caps.size) {
188ad9d6cbbce4 Alex Williamson 2016-02-22 901 info.argsz = sizeof(info) + caps.size;
188ad9d6cbbce4 Alex Williamson 2016-02-22 902 info.cap_offset = 0;
188ad9d6cbbce4 Alex Williamson 2016-02-22 903 } else {
188ad9d6cbbce4 Alex Williamson 2016-02-22 904 vfio_info_cap_shift(&caps, sizeof(info));
c4aec3101319f8 Dan Carpenter 2016-02-25 905 if (copy_to_user((void __user *)arg +
188ad9d6cbbce4 Alex Williamson 2016-02-22 906 sizeof(info), caps.buf,
c4aec3101319f8 Dan Carpenter 2016-02-25 907 caps.size)) {
188ad9d6cbbce4 Alex Williamson 2016-02-22 908 kfree(caps.buf);
c4aec3101319f8 Dan Carpenter 2016-02-25 909 return -EFAULT;
188ad9d6cbbce4 Alex Williamson 2016-02-22 910 }
188ad9d6cbbce4 Alex Williamson 2016-02-22 911 info.cap_offset = sizeof(info);
188ad9d6cbbce4 Alex Williamson 2016-02-22 912 }
188ad9d6cbbce4 Alex Williamson 2016-02-22 913
188ad9d6cbbce4 Alex Williamson 2016-02-22 914 kfree(caps.buf);
89e1f7d4c66d85 Alex Williamson 2012-07-31 915 }
89e1f7d4c66d85 Alex Williamson 2012-07-31 916
8160c4e455820d Michael S. Tsirkin 2016-02-28 917 return copy_to_user((void __user *)arg, &info, minsz) ?
8160c4e455820d Michael S. Tsirkin 2016-02-28 918 -EFAULT : 0;
89e1f7d4c66d85 Alex Williamson 2012-07-31 919
89e1f7d4c66d85 Alex Williamson 2012-07-31 920 } else if (cmd == VFIO_DEVICE_GET_IRQ_INFO) {
89e1f7d4c66d85 Alex Williamson 2012-07-31 921 struct vfio_irq_info info;
89e1f7d4c66d85 Alex Williamson 2012-07-31 922
89e1f7d4c66d85 Alex Williamson 2012-07-31 923 minsz = offsetofend(struct vfio_irq_info, count);
89e1f7d4c66d85 Alex Williamson 2012-07-31 924
89e1f7d4c66d85 Alex Williamson 2012-07-31 925 if (copy_from_user(&info, (void __user *)arg, minsz))
89e1f7d4c66d85 Alex Williamson 2012-07-31 926 return -EFAULT;
89e1f7d4c66d85 Alex Williamson 2012-07-31 927
89e1f7d4c66d85 Alex Williamson 2012-07-31 928 if (info.argsz < minsz || info.index >= VFIO_PCI_NUM_IRQS)
89e1f7d4c66d85 Alex Williamson 2012-07-31 929 return -EINVAL;
89e1f7d4c66d85 Alex Williamson 2012-07-31 930
dad9f8972e04cd Vijay Mohan Pandarathil 2013-03-11 931 switch (info.index) {
dad9f8972e04cd Vijay Mohan Pandarathil 2013-03-11 932 case VFIO_PCI_INTX_IRQ_INDEX ... VFIO_PCI_MSIX_IRQ_INDEX:
6140a8f5623820 Alex Williamson 2015-02-06 933 case VFIO_PCI_REQ_IRQ_INDEX:
dad9f8972e04cd Vijay Mohan Pandarathil 2013-03-11 934 break;
dad9f8972e04cd Vijay Mohan Pandarathil 2013-03-11 935 case VFIO_PCI_ERR_IRQ_INDEX:
dad9f8972e04cd Vijay Mohan Pandarathil 2013-03-11 936 if (pci_is_pcie(vdev->pdev))
dad9f8972e04cd Vijay Mohan Pandarathil 2013-03-11 937 break;
544c05a60aef7d Gustavo A. R. Silva 2018-07-09 938 /* fall through */
dad9f8972e04cd Vijay Mohan Pandarathil 2013-03-11 939 default:
dad9f8972e04cd Vijay Mohan Pandarathil 2013-03-11 940 return -EINVAL;
dad9f8972e04cd Vijay Mohan Pandarathil 2013-03-11 941 }
dad9f8972e04cd Vijay Mohan Pandarathil 2013-03-11 942
89e1f7d4c66d85 Alex Williamson 2012-07-31 943 info.flags = VFIO_IRQ_INFO_EVENTFD;
89e1f7d4c66d85 Alex Williamson 2012-07-31 944
89e1f7d4c66d85 Alex Williamson 2012-07-31 945 info.count = vfio_pci_get_irq_count(vdev, info.index);
89e1f7d4c66d85 Alex Williamson 2012-07-31 946
89e1f7d4c66d85 Alex Williamson 2012-07-31 947 if (info.index == VFIO_PCI_INTX_IRQ_INDEX)
89e1f7d4c66d85 Alex Williamson 2012-07-31 948 info.flags |= (VFIO_IRQ_INFO_MASKABLE |
89e1f7d4c66d85 Alex Williamson 2012-07-31 949 VFIO_IRQ_INFO_AUTOMASKED);
89e1f7d4c66d85 Alex Williamson 2012-07-31 950 else
89e1f7d4c66d85 Alex Williamson 2012-07-31 951 info.flags |= VFIO_IRQ_INFO_NORESIZE;
89e1f7d4c66d85 Alex Williamson 2012-07-31 952
8160c4e455820d Michael S. Tsirkin 2016-02-28 953 return copy_to_user((void __user *)arg, &info, minsz) ?
8160c4e455820d Michael S. Tsirkin 2016-02-28 954 -EFAULT : 0;
89e1f7d4c66d85 Alex Williamson 2012-07-31 955
89e1f7d4c66d85 Alex Williamson 2012-07-31 956 } else if (cmd == VFIO_DEVICE_SET_IRQS) {
89e1f7d4c66d85 Alex Williamson 2012-07-31 957 struct vfio_irq_set hdr;
89e1f7d4c66d85 Alex Williamson 2012-07-31 958 u8 *data = NULL;
05692d7005a364 Vlad Tsyrklevich 2016-10-12 959 int max, ret = 0;
ef198aaa169c61 Kirti Wankhede 2016-11-17 960 size_t data_size = 0;
89e1f7d4c66d85 Alex Williamson 2012-07-31 961
89e1f7d4c66d85 Alex Williamson 2012-07-31 962 minsz = offsetofend(struct vfio_irq_set, count);
89e1f7d4c66d85 Alex Williamson 2012-07-31 963
89e1f7d4c66d85 Alex Williamson 2012-07-31 964 if (copy_from_user(&hdr, (void __user *)arg, minsz))
89e1f7d4c66d85 Alex Williamson 2012-07-31 965 return -EFAULT;
89e1f7d4c66d85 Alex Williamson 2012-07-31 966
05692d7005a364 Vlad Tsyrklevich 2016-10-12 967 max = vfio_pci_get_irq_count(vdev, hdr.index);
89e1f7d4c66d85 Alex Williamson 2012-07-31 968
ef198aaa169c61 Kirti Wankhede 2016-11-17 969 ret = vfio_set_irqs_validate_and_prepare(&hdr, max,
ef198aaa169c61 Kirti Wankhede 2016-11-17 970 VFIO_PCI_NUM_IRQS, &data_size);
ef198aaa169c61 Kirti Wankhede 2016-11-17 971 if (ret)
ef198aaa169c61 Kirti Wankhede 2016-11-17 972 return ret;
89e1f7d4c66d85 Alex Williamson 2012-07-31 973
ef198aaa169c61 Kirti Wankhede 2016-11-17 974 if (data_size) {
3a1f7041ddd59e Fengguang Wu 2012-12-07 975 data = memdup_user((void __user *)(arg + minsz),
ef198aaa169c61 Kirti Wankhede 2016-11-17 976 data_size);
3a1f7041ddd59e Fengguang Wu 2012-12-07 977 if (IS_ERR(data))
3a1f7041ddd59e Fengguang Wu 2012-12-07 978 return PTR_ERR(data);
89e1f7d4c66d85 Alex Williamson 2012-07-31 979 }
89e1f7d4c66d85 Alex Williamson 2012-07-31 980
89e1f7d4c66d85 Alex Williamson 2012-07-31 981 mutex_lock(&vdev->igate);
89e1f7d4c66d85 Alex Williamson 2012-07-31 982
89e1f7d4c66d85 Alex Williamson 2012-07-31 983 ret = vfio_pci_set_irqs_ioctl(vdev, hdr.flags, hdr.index,
89e1f7d4c66d85 Alex Williamson 2012-07-31 984 hdr.start, hdr.count, data);
89e1f7d4c66d85 Alex Williamson 2012-07-31 985
89e1f7d4c66d85 Alex Williamson 2012-07-31 986 mutex_unlock(&vdev->igate);
89e1f7d4c66d85 Alex Williamson 2012-07-31 987 kfree(data);
89e1f7d4c66d85 Alex Williamson 2012-07-31 988
89e1f7d4c66d85 Alex Williamson 2012-07-31 989 return ret;
89e1f7d4c66d85 Alex Williamson 2012-07-31 990
8b27ee60bfd6bb Alex Williamson 2013-09-04 991 } else if (cmd == VFIO_DEVICE_RESET) {
3c9d9870c81581 Alex Williamson 2020-05-22 992 int ret;
3c9d9870c81581 Alex Williamson 2020-05-22 993
3c9d9870c81581 Alex Williamson 2020-05-22 994 if (!vdev->reset_works)
3c9d9870c81581 Alex Williamson 2020-05-22 995 return -EINVAL;
3c9d9870c81581 Alex Williamson 2020-05-22 996
3c9d9870c81581 Alex Williamson 2020-05-22 997 vfio_pci_zap_and_down_write_memory_lock(vdev);
3c9d9870c81581 Alex Williamson 2020-05-22 998 ret = pci_try_reset_function(vdev->pdev);
3c9d9870c81581 Alex Williamson 2020-05-22 999 up_write(&vdev->memory_lock);
3c9d9870c81581 Alex Williamson 2020-05-22 1000
3c9d9870c81581 Alex Williamson 2020-05-22 1001 return ret;
89e1f7d4c66d85 Alex Williamson 2012-07-31 1002
8b27ee60bfd6bb Alex Williamson 2013-09-04 1003 } else if (cmd == VFIO_DEVICE_GET_PCI_HOT_RESET_INFO) {
8b27ee60bfd6bb Alex Williamson 2013-09-04 1004 struct vfio_pci_hot_reset_info hdr;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1005 struct vfio_pci_fill_info fill = { 0 };
8b27ee60bfd6bb Alex Williamson 2013-09-04 1006 struct vfio_pci_dependent_device *devices = NULL;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1007 bool slot = false;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1008 int ret = 0;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1009
8b27ee60bfd6bb Alex Williamson 2013-09-04 1010 minsz = offsetofend(struct vfio_pci_hot_reset_info, count);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1011
8b27ee60bfd6bb Alex Williamson 2013-09-04 1012 if (copy_from_user(&hdr, (void __user *)arg, minsz))
8b27ee60bfd6bb Alex Williamson 2013-09-04 1013 return -EFAULT;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1014
8b27ee60bfd6bb Alex Williamson 2013-09-04 1015 if (hdr.argsz < minsz)
8b27ee60bfd6bb Alex Williamson 2013-09-04 1016 return -EINVAL;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1017
8b27ee60bfd6bb Alex Williamson 2013-09-04 1018 hdr.flags = 0;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1019
8b27ee60bfd6bb Alex Williamson 2013-09-04 1020 /* Can we do a slot or bus reset or neither? */
8b27ee60bfd6bb Alex Williamson 2013-09-04 1021 if (!pci_probe_reset_slot(vdev->pdev->slot))
8b27ee60bfd6bb Alex Williamson 2013-09-04 1022 slot = true;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1023 else if (pci_probe_reset_bus(vdev->pdev->bus))
8b27ee60bfd6bb Alex Williamson 2013-09-04 1024 return -ENODEV;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1025
8b27ee60bfd6bb Alex Williamson 2013-09-04 1026 /* How many devices are affected? */
8b27ee60bfd6bb Alex Williamson 2013-09-04 1027 ret = vfio_pci_for_each_slot_or_bus(vdev->pdev,
8b27ee60bfd6bb Alex Williamson 2013-09-04 1028 vfio_pci_count_devs,
8b27ee60bfd6bb Alex Williamson 2013-09-04 1029 &fill.max, slot);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1030 if (ret)
8b27ee60bfd6bb Alex Williamson 2013-09-04 1031 return ret;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1032
8b27ee60bfd6bb Alex Williamson 2013-09-04 1033 WARN_ON(!fill.max); /* Should always be at least one */
8b27ee60bfd6bb Alex Williamson 2013-09-04 1034
8b27ee60bfd6bb Alex Williamson 2013-09-04 1035 /*
8b27ee60bfd6bb Alex Williamson 2013-09-04 1036 * If there's enough space, fill it now, otherwise return
8b27ee60bfd6bb Alex Williamson 2013-09-04 1037 * -ENOSPC and the number of devices affected.
8b27ee60bfd6bb Alex Williamson 2013-09-04 1038 */
8b27ee60bfd6bb Alex Williamson 2013-09-04 1039 if (hdr.argsz < sizeof(hdr) + (fill.max * sizeof(*devices))) {
8b27ee60bfd6bb Alex Williamson 2013-09-04 1040 ret = -ENOSPC;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1041 hdr.count = fill.max;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1042 goto reset_info_exit;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1043 }
8b27ee60bfd6bb Alex Williamson 2013-09-04 1044
8b27ee60bfd6bb Alex Williamson 2013-09-04 1045 devices = kcalloc(fill.max, sizeof(*devices), GFP_KERNEL);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1046 if (!devices)
8b27ee60bfd6bb Alex Williamson 2013-09-04 1047 return -ENOMEM;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1048
8b27ee60bfd6bb Alex Williamson 2013-09-04 1049 fill.devices = devices;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1050
8b27ee60bfd6bb Alex Williamson 2013-09-04 1051 ret = vfio_pci_for_each_slot_or_bus(vdev->pdev,
8b27ee60bfd6bb Alex Williamson 2013-09-04 1052 vfio_pci_fill_devs,
8b27ee60bfd6bb Alex Williamson 2013-09-04 1053 &fill, slot);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1054
8b27ee60bfd6bb Alex Williamson 2013-09-04 1055 /*
8b27ee60bfd6bb Alex Williamson 2013-09-04 1056 * If a device was removed between counting and filling,
8b27ee60bfd6bb Alex Williamson 2013-09-04 1057 * we may come up short of fill.max. If a device was
8b27ee60bfd6bb Alex Williamson 2013-09-04 1058 * added, we'll have a return of -EAGAIN above.
8b27ee60bfd6bb Alex Williamson 2013-09-04 1059 */
8b27ee60bfd6bb Alex Williamson 2013-09-04 1060 if (!ret)
8b27ee60bfd6bb Alex Williamson 2013-09-04 1061 hdr.count = fill.cur;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1062
8b27ee60bfd6bb Alex Williamson 2013-09-04 1063 reset_info_exit:
8b27ee60bfd6bb Alex Williamson 2013-09-04 1064 if (copy_to_user((void __user *)arg, &hdr, minsz))
8b27ee60bfd6bb Alex Williamson 2013-09-04 1065 ret = -EFAULT;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1066
8b27ee60bfd6bb Alex Williamson 2013-09-04 1067 if (!ret) {
8b27ee60bfd6bb Alex Williamson 2013-09-04 1068 if (copy_to_user((void __user *)(arg + minsz), devices,
8b27ee60bfd6bb Alex Williamson 2013-09-04 1069 hdr.count * sizeof(*devices)))
8b27ee60bfd6bb Alex Williamson 2013-09-04 1070 ret = -EFAULT;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1071 }
8b27ee60bfd6bb Alex Williamson 2013-09-04 1072
8b27ee60bfd6bb Alex Williamson 2013-09-04 1073 kfree(devices);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1074 return ret;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1075
8b27ee60bfd6bb Alex Williamson 2013-09-04 1076 } else if (cmd == VFIO_DEVICE_PCI_HOT_RESET) {
8b27ee60bfd6bb Alex Williamson 2013-09-04 1077 struct vfio_pci_hot_reset hdr;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1078 int32_t *group_fds;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1079 struct vfio_pci_group_entry *groups;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1080 struct vfio_pci_group_info info;
3c9d9870c81581 Alex Williamson 2020-05-22 1081 struct vfio_devices devs = { .cur_index = 0 };
8b27ee60bfd6bb Alex Williamson 2013-09-04 1082 bool slot = false;
3c9d9870c81581 Alex Williamson 2020-05-22 1083 int i, group_idx, mem_idx = 0, count = 0, ret = 0;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1084
8b27ee60bfd6bb Alex Williamson 2013-09-04 1085 minsz = offsetofend(struct vfio_pci_hot_reset, count);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1086
8b27ee60bfd6bb Alex Williamson 2013-09-04 1087 if (copy_from_user(&hdr, (void __user *)arg, minsz))
8b27ee60bfd6bb Alex Williamson 2013-09-04 1088 return -EFAULT;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1089
8b27ee60bfd6bb Alex Williamson 2013-09-04 1090 if (hdr.argsz < minsz || hdr.flags)
8b27ee60bfd6bb Alex Williamson 2013-09-04 1091 return -EINVAL;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1092
8b27ee60bfd6bb Alex Williamson 2013-09-04 1093 /* Can we do a slot or bus reset or neither? */
8b27ee60bfd6bb Alex Williamson 2013-09-04 1094 if (!pci_probe_reset_slot(vdev->pdev->slot))
8b27ee60bfd6bb Alex Williamson 2013-09-04 1095 slot = true;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1096 else if (pci_probe_reset_bus(vdev->pdev->bus))
8b27ee60bfd6bb Alex Williamson 2013-09-04 1097 return -ENODEV;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1098
8b27ee60bfd6bb Alex Williamson 2013-09-04 1099 /*
8b27ee60bfd6bb Alex Williamson 2013-09-04 1100 * We can't let userspace give us an arbitrarily large
8b27ee60bfd6bb Alex Williamson 2013-09-04 1101 * buffer to copy, so verify how many we think there
8b27ee60bfd6bb Alex Williamson 2013-09-04 1102 * could be. Note groups can have multiple devices so
8b27ee60bfd6bb Alex Williamson 2013-09-04 1103 * one group per device is the max.
8b27ee60bfd6bb Alex Williamson 2013-09-04 1104 */
8b27ee60bfd6bb Alex Williamson 2013-09-04 1105 ret = vfio_pci_for_each_slot_or_bus(vdev->pdev,
8b27ee60bfd6bb Alex Williamson 2013-09-04 1106 vfio_pci_count_devs,
8b27ee60bfd6bb Alex Williamson 2013-09-04 1107 &count, slot);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1108 if (ret)
8b27ee60bfd6bb Alex Williamson 2013-09-04 1109 return ret;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1110
8b27ee60bfd6bb Alex Williamson 2013-09-04 1111 /* Somewhere between 1 and count is OK */
8b27ee60bfd6bb Alex Williamson 2013-09-04 1112 if (!hdr.count || hdr.count > count)
8b27ee60bfd6bb Alex Williamson 2013-09-04 1113 return -EINVAL;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1114
8b27ee60bfd6bb Alex Williamson 2013-09-04 1115 group_fds = kcalloc(hdr.count, sizeof(*group_fds), GFP_KERNEL);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1116 groups = kcalloc(hdr.count, sizeof(*groups), GFP_KERNEL);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1117 if (!group_fds || !groups) {
8b27ee60bfd6bb Alex Williamson 2013-09-04 1118 kfree(group_fds);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1119 kfree(groups);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1120 return -ENOMEM;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1121 }
8b27ee60bfd6bb Alex Williamson 2013-09-04 1122
8b27ee60bfd6bb Alex Williamson 2013-09-04 1123 if (copy_from_user(group_fds, (void __user *)(arg + minsz),
8b27ee60bfd6bb Alex Williamson 2013-09-04 1124 hdr.count * sizeof(*group_fds))) {
8b27ee60bfd6bb Alex Williamson 2013-09-04 1125 kfree(group_fds);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1126 kfree(groups);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1127 return -EFAULT;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1128 }
8b27ee60bfd6bb Alex Williamson 2013-09-04 1129
8b27ee60bfd6bb Alex Williamson 2013-09-04 1130 /*
8b27ee60bfd6bb Alex Williamson 2013-09-04 1131 * For each group_fd, get the group through the vfio external
8b27ee60bfd6bb Alex Williamson 2013-09-04 1132 * user interface and store the group and iommu ID. This
8b27ee60bfd6bb Alex Williamson 2013-09-04 1133 * ensures the group is held across the reset.
8b27ee60bfd6bb Alex Williamson 2013-09-04 1134 */
3c9d9870c81581 Alex Williamson 2020-05-22 1135 for (group_idx = 0; group_idx < hdr.count; group_idx++) {
8b27ee60bfd6bb Alex Williamson 2013-09-04 1136 struct vfio_group *group;
3c9d9870c81581 Alex Williamson 2020-05-22 1137 struct fd f = fdget(group_fds[group_idx]);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1138 if (!f.file) {
8b27ee60bfd6bb Alex Williamson 2013-09-04 1139 ret = -EBADF;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1140 break;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1141 }
8b27ee60bfd6bb Alex Williamson 2013-09-04 1142
8b27ee60bfd6bb Alex Williamson 2013-09-04 1143 group = vfio_group_get_external_user(f.file);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1144 fdput(f);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1145 if (IS_ERR(group)) {
8b27ee60bfd6bb Alex Williamson 2013-09-04 1146 ret = PTR_ERR(group);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1147 break;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1148 }
8b27ee60bfd6bb Alex Williamson 2013-09-04 1149
3c9d9870c81581 Alex Williamson 2020-05-22 1150 groups[group_idx].group = group;
3c9d9870c81581 Alex Williamson 2020-05-22 1151 groups[group_idx].id =
3c9d9870c81581 Alex Williamson 2020-05-22 1152 vfio_external_user_iommu_id(group);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1153 }
8b27ee60bfd6bb Alex Williamson 2013-09-04 1154
8b27ee60bfd6bb Alex Williamson 2013-09-04 1155 kfree(group_fds);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1156
8b27ee60bfd6bb Alex Williamson 2013-09-04 1157 /* release reference to groups on error */
8b27ee60bfd6bb Alex Williamson 2013-09-04 1158 if (ret)
8b27ee60bfd6bb Alex Williamson 2013-09-04 1159 goto hot_reset_release;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1160
8b27ee60bfd6bb Alex Williamson 2013-09-04 1161 info.count = hdr.count;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1162 info.groups = groups;
8b27ee60bfd6bb Alex Williamson 2013-09-04 1163
8b27ee60bfd6bb Alex Williamson 2013-09-04 1164 /*
8b27ee60bfd6bb Alex Williamson 2013-09-04 1165 * Test whether all the affected devices are contained
8b27ee60bfd6bb Alex Williamson 2013-09-04 1166 * by the set of groups provided by the user.
8b27ee60bfd6bb Alex Williamson 2013-09-04 1167 */
8b27ee60bfd6bb Alex Williamson 2013-09-04 1168 ret = vfio_pci_for_each_slot_or_bus(vdev->pdev,
8b27ee60bfd6bb Alex Williamson 2013-09-04 1169 vfio_pci_validate_devs,
8b27ee60bfd6bb Alex Williamson 2013-09-04 1170 &info, slot);
3c9d9870c81581 Alex Williamson 2020-05-22 1171 if (ret)
3c9d9870c81581 Alex Williamson 2020-05-22 1172 goto hot_reset_release;
3c9d9870c81581 Alex Williamson 2020-05-22 1173
3c9d9870c81581 Alex Williamson 2020-05-22 1174 devs.max_index = count;
3c9d9870c81581 Alex Williamson 2020-05-22 1175 devs.devices = kcalloc(count, sizeof(struct vfio_device *),
3c9d9870c81581 Alex Williamson 2020-05-22 1176 GFP_KERNEL);
3c9d9870c81581 Alex Williamson 2020-05-22 1177 if (!devs.devices) {
3c9d9870c81581 Alex Williamson 2020-05-22 1178 ret = -ENOMEM;
3c9d9870c81581 Alex Williamson 2020-05-22 1179 goto hot_reset_release;
3c9d9870c81581 Alex Williamson 2020-05-22 1180 }
3c9d9870c81581 Alex Williamson 2020-05-22 1181
3c9d9870c81581 Alex Williamson 2020-05-22 1182 /*
3c9d9870c81581 Alex Williamson 2020-05-22 1183 * We need to get memory_lock for each device, but devices
3c9d9870c81581 Alex Williamson 2020-05-22 1184 * can share mmap_sem, therefore we need to zap and hold
3c9d9870c81581 Alex Williamson 2020-05-22 1185 * the vma_lock for each device, and only then get each
3c9d9870c81581 Alex Williamson 2020-05-22 1186 * memory_lock.
3c9d9870c81581 Alex Williamson 2020-05-22 1187 */
3c9d9870c81581 Alex Williamson 2020-05-22 1188 ret = vfio_pci_for_each_slot_or_bus(vdev->pdev,
3c9d9870c81581 Alex Williamson 2020-05-22 1189 vfio_pci_try_zap_and_vma_lock_cb,
3c9d9870c81581 Alex Williamson 2020-05-22 1190 &devs, slot);
3c9d9870c81581 Alex Williamson 2020-05-22 1191 if (ret)
3c9d9870c81581 Alex Williamson 2020-05-22 1192 goto hot_reset_release;
3c9d9870c81581 Alex Williamson 2020-05-22 1193
3c9d9870c81581 Alex Williamson 2020-05-22 1194 for (; mem_idx < devs.cur_index; mem_idx++) {
3c9d9870c81581 Alex Williamson 2020-05-22 1195 struct vfio_pci_device *tmp;
3c9d9870c81581 Alex Williamson 2020-05-22 1196
3c9d9870c81581 Alex Williamson 2020-05-22 1197 tmp = vfio_device_data(devs.devices[mem_idx]);
3c9d9870c81581 Alex Williamson 2020-05-22 1198
3c9d9870c81581 Alex Williamson 2020-05-22 1199 ret = down_write_trylock(&tmp->memory_lock);
3c9d9870c81581 Alex Williamson 2020-05-22 1200 if (!ret) {
3c9d9870c81581 Alex Williamson 2020-05-22 1201 ret = -EBUSY;
3c9d9870c81581 Alex Williamson 2020-05-22 1202 goto hot_reset_release;
3c9d9870c81581 Alex Williamson 2020-05-22 1203 }
3c9d9870c81581 Alex Williamson 2020-05-22 1204 mutex_unlock(&tmp->vma_lock);
3c9d9870c81581 Alex Williamson 2020-05-22 1205 }
3c9d9870c81581 Alex Williamson 2020-05-22 1206
8b27ee60bfd6bb Alex Williamson 2013-09-04 1207 /* User has access, do the reset */
c6a44ba950d147 Sinan Kaya 2018-07-19 1208 ret = pci_reset_bus(vdev->pdev);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1209
8b27ee60bfd6bb Alex Williamson 2013-09-04 1210 hot_reset_release:
3c9d9870c81581 Alex Williamson 2020-05-22 1211 for (i = 0; i < devs.cur_index; i++) {
3c9d9870c81581 Alex Williamson 2020-05-22 1212 struct vfio_device *device;
3c9d9870c81581 Alex Williamson 2020-05-22 1213 struct vfio_pci_device *tmp;
3c9d9870c81581 Alex Williamson 2020-05-22 1214
3c9d9870c81581 Alex Williamson 2020-05-22 1215 device = devs.devices[i];
3c9d9870c81581 Alex Williamson 2020-05-22 1216 tmp = vfio_device_data(device);
3c9d9870c81581 Alex Williamson 2020-05-22 1217
3c9d9870c81581 Alex Williamson 2020-05-22 1218 if (i < mem_idx)
3c9d9870c81581 Alex Williamson 2020-05-22 1219 up_write(&tmp->memory_lock);
3c9d9870c81581 Alex Williamson 2020-05-22 1220 else
3c9d9870c81581 Alex Williamson 2020-05-22 1221 mutex_unlock(&tmp->vma_lock);
3c9d9870c81581 Alex Williamson 2020-05-22 1222 vfio_device_put(device);
3c9d9870c81581 Alex Williamson 2020-05-22 1223 }
3c9d9870c81581 Alex Williamson 2020-05-22 1224 kfree(devs.devices);
3c9d9870c81581 Alex Williamson 2020-05-22 1225
3c9d9870c81581 Alex Williamson 2020-05-22 1226 for (group_idx--; group_idx >= 0; group_idx--)
3c9d9870c81581 Alex Williamson 2020-05-22 1227 vfio_group_put_external_user(groups[group_idx].group);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1228
8b27ee60bfd6bb Alex Williamson 2013-09-04 1229 kfree(groups);
8b27ee60bfd6bb Alex Williamson 2013-09-04 1230 return ret;
30656177c40804 Alex Williamson 2018-03-21 1231 } else if (cmd == VFIO_DEVICE_IOEVENTFD) {
30656177c40804 Alex Williamson 2018-03-21 1232 struct vfio_device_ioeventfd ioeventfd;
30656177c40804 Alex Williamson 2018-03-21 1233 int count;
30656177c40804 Alex Williamson 2018-03-21 1234
30656177c40804 Alex Williamson 2018-03-21 1235 minsz = offsetofend(struct vfio_device_ioeventfd, fd);
30656177c40804 Alex Williamson 2018-03-21 1236
30656177c40804 Alex Williamson 2018-03-21 1237 if (copy_from_user(&ioeventfd, (void __user *)arg, minsz))
30656177c40804 Alex Williamson 2018-03-21 1238 return -EFAULT;
30656177c40804 Alex Williamson 2018-03-21 1239
30656177c40804 Alex Williamson 2018-03-21 1240 if (ioeventfd.argsz < minsz)
30656177c40804 Alex Williamson 2018-03-21 1241 return -EINVAL;
30656177c40804 Alex Williamson 2018-03-21 1242
30656177c40804 Alex Williamson 2018-03-21 1243 if (ioeventfd.flags & ~VFIO_DEVICE_IOEVENTFD_SIZE_MASK)
30656177c40804 Alex Williamson 2018-03-21 1244 return -EINVAL;
30656177c40804 Alex Williamson 2018-03-21 1245
30656177c40804 Alex Williamson 2018-03-21 1246 count = ioeventfd.flags & VFIO_DEVICE_IOEVENTFD_SIZE_MASK;
30656177c40804 Alex Williamson 2018-03-21 1247
30656177c40804 Alex Williamson 2018-03-21 1248 if (hweight8(count) != 1 || ioeventfd.fd < -1)
30656177c40804 Alex Williamson 2018-03-21 1249 return -EINVAL;
30656177c40804 Alex Williamson 2018-03-21 1250
30656177c40804 Alex Williamson 2018-03-21 1251 return vfio_pci_ioeventfd(vdev, ioeventfd.offset,
30656177c40804 Alex Williamson 2018-03-21 1252 ioeventfd.data, count, ioeventfd.fd);
43eeeecc8ed5fa Alex Williamson 2020-03-24 1253 } else if (cmd == VFIO_DEVICE_FEATURE) {
43eeeecc8ed5fa Alex Williamson 2020-03-24 1254 struct vfio_device_feature feature;
43eeeecc8ed5fa Alex Williamson 2020-03-24 1255 uuid_t uuid;
43eeeecc8ed5fa Alex Williamson 2020-03-24 1256
43eeeecc8ed5fa Alex Williamson 2020-03-24 1257 minsz = offsetofend(struct vfio_device_feature, flags);
43eeeecc8ed5fa Alex Williamson 2020-03-24 1258
43eeeecc8ed5fa Alex Williamson 2020-03-24 1259 if (copy_from_user(&feature, (void __user *)arg, minsz))
43eeeecc8ed5fa Alex Williamson 2020-03-24 1260 return -EFAULT;
43eeeecc8ed5fa Alex Williamson 2020-03-24 1261
43eeeecc8ed5fa Alex Williamson 2020-03-24 1262 if (feature.argsz < minsz)
43eeeecc8ed5fa Alex Williamson 2020-03-24 1263 return -EINVAL;
43eeeecc8ed5fa Alex Williamson 2020-03-24 1264
43eeeecc8ed5fa Alex Williamson 2020-03-24 1265 /* Check unknown flags */
43eeeecc8ed5fa Alex Williamson 2020-03-24 1266 if (feature.flags & ~(VFIO_DEVICE_FEATURE_MASK |
43eeeecc8ed5fa Alex Williamson 2020-03-24 1267 VFIO_DEVICE_FEATURE_SET |
43eeeecc8ed5fa Alex Williamson 2020-03-24 1268 VFIO_DEVICE_FEATURE_GET |
43eeeecc8ed5fa Alex Williamson 2020-03-24 1269 VFIO_DEVICE_FEATURE_PROBE))
43eeeecc8ed5fa Alex Williamson 2020-03-24 1270 return -EINVAL;
43eeeecc8ed5fa Alex Williamson 2020-03-24 1271
43eeeecc8ed5fa Alex Williamson 2020-03-24 1272 /* GET & SET are mutually exclusive except with PROBE */
43eeeecc8ed5fa Alex Williamson 2020-03-24 1273 if (!(feature.flags & VFIO_DEVICE_FEATURE_PROBE) &&
43eeeecc8ed5fa Alex Williamson 2020-03-24 1274 (feature.flags & VFIO_DEVICE_FEATURE_SET) &&
43eeeecc8ed5fa Alex Williamson 2020-03-24 1275 (feature.flags & VFIO_DEVICE_FEATURE_GET))
43eeeecc8ed5fa Alex Williamson 2020-03-24 1276 return -EINVAL;
43eeeecc8ed5fa Alex Williamson 2020-03-24 1277
43eeeecc8ed5fa Alex Williamson 2020-03-24 1278 switch (feature.flags & VFIO_DEVICE_FEATURE_MASK) {
43eeeecc8ed5fa Alex Williamson 2020-03-24 1279 case VFIO_DEVICE_FEATURE_PCI_VF_TOKEN:
43eeeecc8ed5fa Alex Williamson 2020-03-24 1280 if (!vdev->vf_token)
43eeeecc8ed5fa Alex Williamson 2020-03-24 1281 return -ENOTTY;
43eeeecc8ed5fa Alex Williamson 2020-03-24 1282
43eeeecc8ed5fa Alex Williamson 2020-03-24 1283 /*
43eeeecc8ed5fa Alex Williamson 2020-03-24 1284 * We do not support GET of the VF Token UUID as this
43eeeecc8ed5fa Alex Williamson 2020-03-24 1285 * could expose the token of the previous device user.
43eeeecc8ed5fa Alex Williamson 2020-03-24 1286 */
43eeeecc8ed5fa Alex Williamson 2020-03-24 1287 if (feature.flags & VFIO_DEVICE_FEATURE_GET)
43eeeecc8ed5fa Alex Williamson 2020-03-24 1288 return -EINVAL;
43eeeecc8ed5fa Alex Williamson 2020-03-24 1289
43eeeecc8ed5fa Alex Williamson 2020-03-24 1290 if (feature.flags & VFIO_DEVICE_FEATURE_PROBE)
43eeeecc8ed5fa Alex Williamson 2020-03-24 1291 return 0;
43eeeecc8ed5fa Alex Williamson 2020-03-24 1292
43eeeecc8ed5fa Alex Williamson 2020-03-24 1293 /* Don't SET unless told to do so */
43eeeecc8ed5fa Alex Williamson 2020-03-24 1294 if (!(feature.flags & VFIO_DEVICE_FEATURE_SET))
43eeeecc8ed5fa Alex Williamson 2020-03-24 1295 return -EINVAL;
43eeeecc8ed5fa Alex Williamson 2020-03-24 1296
43eeeecc8ed5fa Alex Williamson 2020-03-24 1297 if (feature.argsz < minsz + sizeof(uuid))
43eeeecc8ed5fa Alex Williamson 2020-03-24 1298 return -EINVAL;
43eeeecc8ed5fa Alex Williamson 2020-03-24 1299
43eeeecc8ed5fa Alex Williamson 2020-03-24 1300 if (copy_from_user(&uuid, (void __user *)(arg + minsz),
43eeeecc8ed5fa Alex Williamson 2020-03-24 1301 sizeof(uuid)))
43eeeecc8ed5fa Alex Williamson 2020-03-24 1302 return -EFAULT;
43eeeecc8ed5fa Alex Williamson 2020-03-24 1303
43eeeecc8ed5fa Alex Williamson 2020-03-24 1304 mutex_lock(&vdev->vf_token->lock);
43eeeecc8ed5fa Alex Williamson 2020-03-24 1305 uuid_copy(&vdev->vf_token->uuid, &uuid);
43eeeecc8ed5fa Alex Williamson 2020-03-24 1306 mutex_unlock(&vdev->vf_token->lock);
43eeeecc8ed5fa Alex Williamson 2020-03-24 1307
43eeeecc8ed5fa Alex Williamson 2020-03-24 1308 return 0;
43eeeecc8ed5fa Alex Williamson 2020-03-24 1309 default:
43eeeecc8ed5fa Alex Williamson 2020-03-24 1310 return -ENOTTY;
43eeeecc8ed5fa Alex Williamson 2020-03-24 1311 }
8b27ee60bfd6bb Alex Williamson 2013-09-04 1312 }
8b27ee60bfd6bb Alex Williamson 2013-09-04 1313
89e1f7d4c66d85 Alex Williamson 2012-07-31 1314 return -ENOTTY;
89e1f7d4c66d85 Alex Williamson 2012-07-31 1315 }
89e1f7d4c66d85 Alex Williamson 2012-07-31 1316
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
next reply other threads:[~2020-05-25 10:09 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-25 10:09 kbuild test robot [this message]
-- strict thread matches above, loose matches on Subject: below --
2020-05-22 19:17 [PATCH v3 0/3] vfio-pci: Block user access to disabled device MMIO Alex Williamson
2020-05-22 19:17 ` [PATCH v3 3/3] vfio-pci: Invalidate mmaps and block MMIO access on disabled memory Alex Williamson
2020-05-23 19:34 ` Peter Xu
2020-05-23 23:06 ` Alex Williamson
2020-05-23 23:52 ` Peter Xu
2020-05-24 0:02 ` Peter Xu
2020-05-25 12:26 ` Jason Gunthorpe
2020-05-25 14:28 ` Peter Xu
2020-05-25 14:46 ` Jason Gunthorpe
2020-05-25 15:11 ` Peter Xu
2020-05-25 16:56 ` Jason Gunthorpe
2020-05-25 20:56 ` John Hubbard
2020-05-26 0:37 ` Jason Gunthorpe
2020-05-26 0:46 ` John Hubbard
2020-05-26 13:49 ` Peter Xu
2020-05-26 14:32 ` Alex Williamson
2020-05-26 14:46 ` Peter Xu
2020-05-26 15:53 ` Jason Gunthorpe
2020-05-26 15:57 ` Alex Williamson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202005251817.h2rt0LjL%lkp@intel.com \
--to=lkp@intel.com \
--cc=kbuild@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.