CC: [email protected]
CC: Linux Memory Management List <[email protected]>
TO: Steve Sistare <[email protected]>
CC: Alex Williamson <[email protected]>
CC: Cornelia Huck <[email protected]>

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git 
master
head:   37dfbfbdca66834bc0f64ec9b35e09ac6c8898da
commit: 0f53afa12baec8c00f5d1d6afb49325ada105253 [6931/12022] vfio/type1: unmap 
cleanup
:::::: branch date: 5 hours ago
:::::: commit date: 3 weeks ago
config: i386-randconfig-m021-20210222 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
Reported-by: Dan Carpenter <[email protected]>

New smatch warnings:
drivers/vfio/vfio_iommu_type1.c:1093 vfio_dma_do_unmap() warn: impossible 
condition '(size > (~0)) => (0-u32max > u32max)'

Old smatch warnings:
drivers/vfio/vfio_iommu_type1.c:514 vfio_pin_pages_remote() warn: should 'limit 
<< 12' be a 64 bit type?
drivers/vfio/vfio_iommu_type1.c:541 vfio_pin_pages_remote() warn: should 'limit 
<< 12' be a 64 bit type?
drivers/vfio/vfio_iommu_type1.c:2592 vfio_iommu_migration_build_caps() warn: 
should '1 << __ffs(iommu->pgsize_bitmap)' be a 64 bit type?

vim +1093 drivers/vfio/vfio_iommu_type1.c

d6a4c185660cb9 Kirti Wankhede  2020-05-29  1070  
73fa0d10d077d9 Alex Williamson 2012-07-31  1071  static int 
vfio_dma_do_unmap(struct vfio_iommu *iommu,
331e33d2960c82 Kirti Wankhede  2020-05-29  1072                              
struct vfio_iommu_type1_dma_unmap *unmap,
331e33d2960c82 Kirti Wankhede  2020-05-29  1073                              
struct vfio_bitmap *bitmap)
73fa0d10d077d9 Alex Williamson 2012-07-31  1074  {
c086de818dd81c Kirti Wankhede  2016-11-17  1075         struct vfio_dma *dma, 
*dma_last = NULL;
331e33d2960c82 Kirti Wankhede  2020-05-29  1076         size_t unmapped = 0, 
pgsize;
0f53afa12baec8 Steve Sistare   2021-01-29  1077         int ret = -EINVAL, 
retries = 0;
331e33d2960c82 Kirti Wankhede  2020-05-29  1078         unsigned long pgshift;
0f53afa12baec8 Steve Sistare   2021-01-29  1079         dma_addr_t iova = 
unmap->iova;
0f53afa12baec8 Steve Sistare   2021-01-29  1080         unsigned long size = 
unmap->size;
73fa0d10d077d9 Alex Williamson 2012-07-31  1081  
cade075f265b25 Kirti Wankhede  2020-05-29  1082         
mutex_lock(&iommu->lock);
cade075f265b25 Kirti Wankhede  2020-05-29  1083  
331e33d2960c82 Kirti Wankhede  2020-05-29  1084         pgshift = 
__ffs(iommu->pgsize_bitmap);
331e33d2960c82 Kirti Wankhede  2020-05-29  1085         pgsize = (size_t)1 << 
pgshift;
cade075f265b25 Kirti Wankhede  2020-05-29  1086  
0f53afa12baec8 Steve Sistare   2021-01-29  1087         if (iova & (pgsize - 1))
cade075f265b25 Kirti Wankhede  2020-05-29  1088                 goto unlock;
cade075f265b25 Kirti Wankhede  2020-05-29  1089  
0f53afa12baec8 Steve Sistare   2021-01-29  1090         if (!size || size & 
(pgsize - 1))
cade075f265b25 Kirti Wankhede  2020-05-29  1091                 goto unlock;
73fa0d10d077d9 Alex Williamson 2012-07-31  1092  
0f53afa12baec8 Steve Sistare   2021-01-29 @1093         if (iova + size - 1 < 
iova || size > SIZE_MAX)
cade075f265b25 Kirti Wankhede  2020-05-29  1094                 goto unlock;
73fa0d10d077d9 Alex Williamson 2012-07-31  1095  
331e33d2960c82 Kirti Wankhede  2020-05-29  1096         /* When dirty tracking 
is enabled, allow only min supported pgsize */
331e33d2960c82 Kirti Wankhede  2020-05-29  1097         if ((unmap->flags & 
VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP) &&
331e33d2960c82 Kirti Wankhede  2020-05-29  1098             
(!iommu->dirty_page_tracking || (bitmap->pgsize != pgsize))) {
331e33d2960c82 Kirti Wankhede  2020-05-29  1099                 goto unlock;
331e33d2960c82 Kirti Wankhede  2020-05-29  1100         }
73fa0d10d077d9 Alex Williamson 2012-07-31  1101  
331e33d2960c82 Kirti Wankhede  2020-05-29  1102         WARN_ON((pgsize - 1) & 
PAGE_MASK);
331e33d2960c82 Kirti Wankhede  2020-05-29  1103  again:
1ef3e2bc04223f Alex Williamson 2014-02-26  1104         /*
1ef3e2bc04223f Alex Williamson 2014-02-26  1105          * vfio-iommu-type1 
(v1) - User mappings were coalesced together to
1ef3e2bc04223f Alex Williamson 2014-02-26  1106          * avoid tracking 
individual mappings.  This means that the granularity
1ef3e2bc04223f Alex Williamson 2014-02-26  1107          * of the original 
mapping was lost and the user was allowed to attempt
1ef3e2bc04223f Alex Williamson 2014-02-26  1108          * to unmap any range.  
Depending on the contiguousness of physical
1ef3e2bc04223f Alex Williamson 2014-02-26  1109          * memory and page 
sizes supported by the IOMMU, arbitrary unmaps may
1ef3e2bc04223f Alex Williamson 2014-02-26  1110          * or may not have 
worked.  We only guaranteed unmap granularity
1ef3e2bc04223f Alex Williamson 2014-02-26  1111          * matching the 
original mapping; even though it was untracked here,
1ef3e2bc04223f Alex Williamson 2014-02-26  1112          * the original 
mappings are reflected in IOMMU mappings.  This
1ef3e2bc04223f Alex Williamson 2014-02-26  1113          * resulted in a couple 
unusual behaviors.  First, if a range is not
1ef3e2bc04223f Alex Williamson 2014-02-26  1114          * able to be unmapped, 
ex. a set of 4k pages that was mapped as a
1ef3e2bc04223f Alex Williamson 2014-02-26  1115          * 2M hugepage into the 
IOMMU, the unmap ioctl returns success but with
1ef3e2bc04223f Alex Williamson 2014-02-26  1116          * a zero sized unmap.  
Also, if an unmap request overlaps the first
1ef3e2bc04223f Alex Williamson 2014-02-26  1117          * address of a 
hugepage, the IOMMU will unmap the entire hugepage.
1ef3e2bc04223f Alex Williamson 2014-02-26  1118          * This also returns 
success and the returned unmap size reflects the
1ef3e2bc04223f Alex Williamson 2014-02-26  1119          * actual size unmapped.
1ef3e2bc04223f Alex Williamson 2014-02-26  1120          *
1ef3e2bc04223f Alex Williamson 2014-02-26  1121          * We attempt to 
maintain compatibility with this "v1" interface, but
1ef3e2bc04223f Alex Williamson 2014-02-26  1122          * we take control out 
of the hands of the IOMMU.  Therefore, an unmap
1ef3e2bc04223f Alex Williamson 2014-02-26  1123          * request offset from 
the beginning of the original mapping will
1ef3e2bc04223f Alex Williamson 2014-02-26  1124          * return success with 
zero sized unmap.  And an unmap request covering
1ef3e2bc04223f Alex Williamson 2014-02-26  1125          * the first iova of 
mapping will unmap the entire range.
1ef3e2bc04223f Alex Williamson 2014-02-26  1126          *
1ef3e2bc04223f Alex Williamson 2014-02-26  1127          * The v2 version of 
this interface intends to be more deterministic.
1ef3e2bc04223f Alex Williamson 2014-02-26  1128          * Unmap requests must 
fully cover previous mappings.  Multiple
1ef3e2bc04223f Alex Williamson 2014-02-26  1129          * mappings may still 
be unmaped by specifying large ranges, but there
1ef3e2bc04223f Alex Williamson 2014-02-26  1130          * must not be any 
previous mappings bisected by the range.  An error
1ef3e2bc04223f Alex Williamson 2014-02-26  1131          * will be returned if 
these conditions are not met.  The v2 interface
1ef3e2bc04223f Alex Williamson 2014-02-26  1132          * will only return 
success and a size of zero if there were no
1ef3e2bc04223f Alex Williamson 2014-02-26  1133          * mappings within the 
range.
1ef3e2bc04223f Alex Williamson 2014-02-26  1134          */
1ef3e2bc04223f Alex Williamson 2014-02-26  1135         if (iommu->v2) {
0f53afa12baec8 Steve Sistare   2021-01-29  1136                 dma = 
vfio_find_dma(iommu, iova, 1);
0f53afa12baec8 Steve Sistare   2021-01-29  1137                 if (dma && 
dma->iova != iova)
1ef3e2bc04223f Alex Williamson 2014-02-26  1138                         goto 
unlock;
0f53afa12baec8 Steve Sistare   2021-01-29  1139  
0f53afa12baec8 Steve Sistare   2021-01-29  1140                 dma = 
vfio_find_dma(iommu, iova + size - 1, 0);
0f53afa12baec8 Steve Sistare   2021-01-29  1141                 if (dma && 
dma->iova + dma->size != iova + size)
1ef3e2bc04223f Alex Williamson 2014-02-26  1142                         goto 
unlock;
1ef3e2bc04223f Alex Williamson 2014-02-26  1143         }
1ef3e2bc04223f Alex Williamson 2014-02-26  1144  
0f53afa12baec8 Steve Sistare   2021-01-29  1145         ret = 0;
0f53afa12baec8 Steve Sistare   2021-01-29  1146         while ((dma = 
vfio_find_dma(iommu, iova, size))) {
0f53afa12baec8 Steve Sistare   2021-01-29  1147                 if (!iommu->v2 
&& iova > dma->iova)
166fd7d94afdac Alex Williamson 2013-06-21  1148                         break;
8f0d5bb95f763c Kirti Wankhede  2016-11-17  1149                 /*
8f0d5bb95f763c Kirti Wankhede  2016-11-17  1150                  * Task with 
same address space who mapped this iova range is
8f0d5bb95f763c Kirti Wankhede  2016-11-17  1151                  * allowed to 
unmap the iova range.
8f0d5bb95f763c Kirti Wankhede  2016-11-17  1152                  */
8f0d5bb95f763c Kirti Wankhede  2016-11-17  1153                 if 
(dma->task->mm != current->mm)
8f0d5bb95f763c Kirti Wankhede  2016-11-17  1154                         break;
c086de818dd81c Kirti Wankhede  2016-11-17  1155  
c086de818dd81c Kirti Wankhede  2016-11-17  1156                 if 
(!RB_EMPTY_ROOT(&dma->pfn_list)) {
c086de818dd81c Kirti Wankhede  2016-11-17  1157                         struct 
vfio_iommu_type1_dma_unmap nb_unmap;
c086de818dd81c Kirti Wankhede  2016-11-17  1158  
c086de818dd81c Kirti Wankhede  2016-11-17  1159                         if 
(dma_last == dma) {
c086de818dd81c Kirti Wankhede  2016-11-17  1160                                 
BUG_ON(++retries > 10);
c086de818dd81c Kirti Wankhede  2016-11-17  1161                         } else {
c086de818dd81c Kirti Wankhede  2016-11-17  1162                                 
dma_last = dma;
c086de818dd81c Kirti Wankhede  2016-11-17  1163                                 
retries = 0;
c086de818dd81c Kirti Wankhede  2016-11-17  1164                         }
c086de818dd81c Kirti Wankhede  2016-11-17  1165  
c086de818dd81c Kirti Wankhede  2016-11-17  1166                         
nb_unmap.iova = dma->iova;
c086de818dd81c Kirti Wankhede  2016-11-17  1167                         
nb_unmap.size = dma->size;
c086de818dd81c Kirti Wankhede  2016-11-17  1168  
c086de818dd81c Kirti Wankhede  2016-11-17  1169                         /*
c086de818dd81c Kirti Wankhede  2016-11-17  1170                          * 
Notify anyone (mdev vendor drivers) to invalidate and
c086de818dd81c Kirti Wankhede  2016-11-17  1171                          * 
unmap iovas within the range we're about to unmap.
c086de818dd81c Kirti Wankhede  2016-11-17  1172                          * 
Vendor drivers MUST unpin pages in response to an
c086de818dd81c Kirti Wankhede  2016-11-17  1173                          * 
invalidation.
c086de818dd81c Kirti Wankhede  2016-11-17  1174                          */
c086de818dd81c Kirti Wankhede  2016-11-17  1175                         
mutex_unlock(&iommu->lock);
c086de818dd81c Kirti Wankhede  2016-11-17  1176                         
blocking_notifier_call_chain(&iommu->notifier,
c086de818dd81c Kirti Wankhede  2016-11-17  1177                                 
                    VFIO_IOMMU_NOTIFY_DMA_UNMAP,
c086de818dd81c Kirti Wankhede  2016-11-17  1178                                 
                    &nb_unmap);
cade075f265b25 Kirti Wankhede  2020-05-29  1179                         
mutex_lock(&iommu->lock);
c086de818dd81c Kirti Wankhede  2016-11-17  1180                         goto 
again;
c086de818dd81c Kirti Wankhede  2016-11-17  1181                 }
331e33d2960c82 Kirti Wankhede  2020-05-29  1182  
331e33d2960c82 Kirti Wankhede  2020-05-29  1183                 if 
(unmap->flags & VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP) {
95fc87b44104d9 Kirti Wankhede  2020-05-29  1184                         ret = 
update_user_bitmap(bitmap->data, iommu, dma,
0f53afa12baec8 Steve Sistare   2021-01-29  1185                                 
                 iova, pgsize);
331e33d2960c82 Kirti Wankhede  2020-05-29  1186                         if (ret)
331e33d2960c82 Kirti Wankhede  2020-05-29  1187                                 
break;
331e33d2960c82 Kirti Wankhede  2020-05-29  1188                 }
331e33d2960c82 Kirti Wankhede  2020-05-29  1189  
1ef3e2bc04223f Alex Williamson 2014-02-26  1190                 unmapped += 
dma->size;
1ef3e2bc04223f Alex Williamson 2014-02-26  1191                 
vfio_remove_dma(iommu, dma);
166fd7d94afdac Alex Williamson 2013-06-21  1192         }
cd9b22685e4ccd Alex Williamson 2013-06-21  1193  
1ef3e2bc04223f Alex Williamson 2014-02-26  1194  unlock:
73fa0d10d077d9 Alex Williamson 2012-07-31  1195         
mutex_unlock(&iommu->lock);
166fd7d94afdac Alex Williamson 2013-06-21  1196  
1ef3e2bc04223f Alex Williamson 2014-02-26  1197         /* Report how much was 
unmapped */
166fd7d94afdac Alex Williamson 2013-06-21  1198         unmap->size = unmapped;
166fd7d94afdac Alex Williamson 2013-06-21  1199  
166fd7d94afdac Alex Williamson 2013-06-21  1200         return ret;
166fd7d94afdac Alex Williamson 2013-06-21  1201  }
166fd7d94afdac Alex Williamson 2013-06-21  1202  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]

Attachment: .config.gz
Description: application/gzip

_______________________________________________
kbuild mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to