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

vfio: Move vfio_spapr_iommu_eeh_ioctl into vfio_iommu_spapr_tce.c

As with the previous patch EEH is always enabled if SPAPR_TCE_IOMMU, so
move this last bit of code into the main module.

Now that this function only processes VFIO_EEH_PE_OP remove a level of
indenting as well, it is only called by a case statement that already
checked VFIO_EEH_PE_OP.

This eliminates an unnecessary module and SPAPR code in a global header.

Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Link: https://lore.kernel.org/r/3-v5-fc5346cacfd4+4c482-vfio_modules_jgg@nvidia.com
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>

authored by

Jason Gunthorpe and committed by
Alex Williamson
e276e258 e5c38a20

+53 -103
-1
drivers/vfio/Makefile
··· 10 10 obj-$(CONFIG_VFIO_VIRQFD) += vfio_virqfd.o 11 11 obj-$(CONFIG_VFIO_IOMMU_TYPE1) += vfio_iommu_type1.o 12 12 obj-$(CONFIG_VFIO_IOMMU_SPAPR_TCE) += vfio_iommu_spapr_tce.o 13 - obj-$(CONFIG_VFIO_SPAPR_EEH) += vfio_spapr_eeh.o 14 13 obj-$(CONFIG_VFIO_PCI) += pci/ 15 14 obj-$(CONFIG_VFIO_PLATFORM) += platform/ 16 15 obj-$(CONFIG_VFIO_MDEV) += mdev/
+53 -2
drivers/vfio/vfio_iommu_spapr_tce.c
··· 4 4 * 5 5 * Copyright (C) 2013 IBM Corp. All rights reserved. 6 6 * Author: Alexey Kardashevskiy <aik@ozlabs.ru> 7 + * Copyright Gavin Shan, IBM Corporation 2014. 7 8 * 8 9 * Derived from original vfio_iommu_type1.c: 9 10 * Copyright (C) 2012 Red Hat, Inc. All rights reserved. ··· 774 773 return ret; 775 774 } 776 775 776 + static long vfio_spapr_ioctl_eeh_pe_op(struct iommu_group *group, 777 + unsigned long arg) 778 + { 779 + struct eeh_pe *pe; 780 + struct vfio_eeh_pe_op op; 781 + unsigned long minsz; 782 + 783 + pe = eeh_iommu_group_to_pe(group); 784 + if (!pe) 785 + return -ENODEV; 786 + 787 + minsz = offsetofend(struct vfio_eeh_pe_op, op); 788 + if (copy_from_user(&op, (void __user *)arg, minsz)) 789 + return -EFAULT; 790 + if (op.argsz < minsz || op.flags) 791 + return -EINVAL; 792 + 793 + switch (op.op) { 794 + case VFIO_EEH_PE_DISABLE: 795 + return eeh_pe_set_option(pe, EEH_OPT_DISABLE); 796 + case VFIO_EEH_PE_ENABLE: 797 + return eeh_pe_set_option(pe, EEH_OPT_ENABLE); 798 + case VFIO_EEH_PE_UNFREEZE_IO: 799 + return eeh_pe_set_option(pe, EEH_OPT_THAW_MMIO); 800 + case VFIO_EEH_PE_UNFREEZE_DMA: 801 + return eeh_pe_set_option(pe, EEH_OPT_THAW_DMA); 802 + case VFIO_EEH_PE_GET_STATE: 803 + return eeh_pe_get_state(pe); 804 + break; 805 + case VFIO_EEH_PE_RESET_DEACTIVATE: 806 + return eeh_pe_reset(pe, EEH_RESET_DEACTIVATE, true); 807 + case VFIO_EEH_PE_RESET_HOT: 808 + return eeh_pe_reset(pe, EEH_RESET_HOT, true); 809 + case VFIO_EEH_PE_RESET_FUNDAMENTAL: 810 + return eeh_pe_reset(pe, EEH_RESET_FUNDAMENTAL, true); 811 + case VFIO_EEH_PE_CONFIGURE: 812 + return eeh_pe_configure(pe); 813 + case VFIO_EEH_PE_INJECT_ERR: 814 + minsz = offsetofend(struct vfio_eeh_pe_op, err.mask); 815 + if (op.argsz < minsz) 816 + return -EINVAL; 817 + if (copy_from_user(&op, (void __user *)arg, minsz)) 818 + return -EFAULT; 819 + 820 + return eeh_pe_inject_err(pe, op.err.type, op.err.func, 821 + op.err.addr, op.err.mask); 822 + default: 823 + return -EINVAL; 824 + } 825 + } 826 + 777 827 static long tce_iommu_ioctl(void *iommu_data, 778 828 unsigned int cmd, unsigned long arg) 779 829 { ··· 1096 1044 1097 1045 ret = 0; 1098 1046 list_for_each_entry(tcegrp, &container->group_list, next) { 1099 - ret = vfio_spapr_iommu_eeh_ioctl(tcegrp->grp, 1100 - cmd, arg); 1047 + ret = vfio_spapr_ioctl_eeh_pe_op(tcegrp->grp, arg); 1101 1048 if (ret) 1102 1049 return ret; 1103 1050 }
-88
drivers/vfio/vfio_spapr_eeh.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * EEH functionality support for VFIO devices. The feature is only 4 - * available on sPAPR compatible platforms. 5 - * 6 - * Copyright Gavin Shan, IBM Corporation 2014. 7 - */ 8 - 9 - #include <linux/module.h> 10 - #include <linux/uaccess.h> 11 - #include <linux/vfio.h> 12 - #include <asm/eeh.h> 13 - 14 - #define DRIVER_VERSION "0.1" 15 - #define DRIVER_AUTHOR "Gavin Shan, IBM Corporation" 16 - #define DRIVER_DESC "VFIO IOMMU SPAPR EEH" 17 - 18 - long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group, 19 - unsigned int cmd, unsigned long arg) 20 - { 21 - struct eeh_pe *pe; 22 - struct vfio_eeh_pe_op op; 23 - unsigned long minsz; 24 - long ret = -EINVAL; 25 - 26 - switch (cmd) { 27 - case VFIO_EEH_PE_OP: 28 - pe = eeh_iommu_group_to_pe(group); 29 - if (!pe) 30 - return -ENODEV; 31 - 32 - minsz = offsetofend(struct vfio_eeh_pe_op, op); 33 - if (copy_from_user(&op, (void __user *)arg, minsz)) 34 - return -EFAULT; 35 - if (op.argsz < minsz || op.flags) 36 - return -EINVAL; 37 - 38 - switch (op.op) { 39 - case VFIO_EEH_PE_DISABLE: 40 - ret = eeh_pe_set_option(pe, EEH_OPT_DISABLE); 41 - break; 42 - case VFIO_EEH_PE_ENABLE: 43 - ret = eeh_pe_set_option(pe, EEH_OPT_ENABLE); 44 - break; 45 - case VFIO_EEH_PE_UNFREEZE_IO: 46 - ret = eeh_pe_set_option(pe, EEH_OPT_THAW_MMIO); 47 - break; 48 - case VFIO_EEH_PE_UNFREEZE_DMA: 49 - ret = eeh_pe_set_option(pe, EEH_OPT_THAW_DMA); 50 - break; 51 - case VFIO_EEH_PE_GET_STATE: 52 - ret = eeh_pe_get_state(pe); 53 - break; 54 - case VFIO_EEH_PE_RESET_DEACTIVATE: 55 - ret = eeh_pe_reset(pe, EEH_RESET_DEACTIVATE, true); 56 - break; 57 - case VFIO_EEH_PE_RESET_HOT: 58 - ret = eeh_pe_reset(pe, EEH_RESET_HOT, true); 59 - break; 60 - case VFIO_EEH_PE_RESET_FUNDAMENTAL: 61 - ret = eeh_pe_reset(pe, EEH_RESET_FUNDAMENTAL, true); 62 - break; 63 - case VFIO_EEH_PE_CONFIGURE: 64 - ret = eeh_pe_configure(pe); 65 - break; 66 - case VFIO_EEH_PE_INJECT_ERR: 67 - minsz = offsetofend(struct vfio_eeh_pe_op, err.mask); 68 - if (op.argsz < minsz) 69 - return -EINVAL; 70 - if (copy_from_user(&op, (void __user *)arg, minsz)) 71 - return -EFAULT; 72 - 73 - ret = eeh_pe_inject_err(pe, op.err.type, op.err.func, 74 - op.err.addr, op.err.mask); 75 - break; 76 - default: 77 - ret = -EINVAL; 78 - } 79 - } 80 - 81 - return ret; 82 - } 83 - EXPORT_SYMBOL_GPL(vfio_spapr_iommu_eeh_ioctl); 84 - 85 - MODULE_VERSION(DRIVER_VERSION); 86 - MODULE_LICENSE("GPL v2"); 87 - MODULE_AUTHOR(DRIVER_AUTHOR); 88 - MODULE_DESCRIPTION(DRIVER_DESC);
-12
include/linux/vfio.h
··· 233 233 int num_irqs, int max_irq_type, 234 234 size_t *data_size); 235 235 236 - #if IS_ENABLED(CONFIG_VFIO_SPAPR_EEH) 237 - long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group, unsigned int cmd, 238 - unsigned long arg); 239 - #else 240 - static inline long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group, 241 - unsigned int cmd, 242 - unsigned long arg) 243 - { 244 - return -ENOTTY; 245 - } 246 - #endif /* CONFIG_VFIO_SPAPR_EEH */ 247 - 248 236 /* 249 237 * IRQfd - generic 250 238 */