Re: [PATCH v1 05/12] mm: thp: introduce folio_split_queue_lock{_irqsave}()
by kernel test robot
Hi Muchun,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on next-20210813]
[cannot apply to hnaz-linux-mm/master cgroup/for-next linus/master v5.14-rc5 v5.14-rc4 v5.14-rc3 v5.14-rc5]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Muchun-Song/Use-obj_cgroup-APIs-...
base: 4b358aabb93a2c654cd1dcab1a25a589f6e2b153
config: s390-randconfig-r044-20210814 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 1f7b25ea76a925aca690da28de9d78db7ca99d0c)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# install s390 cross compiling tool for clang build
# apt-get install binutils-s390x-linux-gnu
# https://github.com/0day-ci/linux/commit/3460bcf13b968edf6f4621c0e0dcde465...
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Muchun-Song/Use-obj_cgroup-APIs-to-charge-the-LRU-pages/20210814-132844
git checkout 3460bcf13b968edf6f4621c0e0dcde46500957e5
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=s390
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp(a)intel.com>
All warnings (new ones prefixed by >>):
In file included from mm/huge_memory.c:16:
In file included from include/linux/rmap.h:12:
In file included from include/linux/memcontrol.h:22:
In file included from include/linux/writeback.h:14:
In file included from include/linux/blk-cgroup.h:23:
In file included from include/linux/blkdev.h:23:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:464:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __raw_readb(PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:477:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:36:59: note: expanded from macro '__le16_to_cpu'
#define __le16_to_cpu(x) __swab16((__force __u16)(__le16)(x))
^
include/uapi/linux/swab.h:102:54: note: expanded from macro '__swab16'
#define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
^
In file included from mm/huge_memory.c:16:
In file included from include/linux/rmap.h:12:
In file included from include/linux/memcontrol.h:22:
In file included from include/linux/writeback.h:14:
In file included from include/linux/blk-cgroup.h:23:
In file included from include/linux/blkdev.h:23:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:490:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
~~~~~~~~~~ ^
include/uapi/linux/byteorder/big_endian.h:34:59: note: expanded from macro '__le32_to_cpu'
#define __le32_to_cpu(x) __swab32((__force __u32)(__le32)(x))
^
include/uapi/linux/swab.h:115:54: note: expanded from macro '__swab32'
#define __swab32(x) (__u32)__builtin_bswap32((__u32)(x))
^
In file included from mm/huge_memory.c:16:
In file included from include/linux/rmap.h:12:
In file included from include/linux/memcontrol.h:22:
In file included from include/linux/writeback.h:14:
In file included from include/linux/blk-cgroup.h:23:
In file included from include/linux/blkdev.h:23:
In file included from include/linux/scatterlist.h:9:
In file included from arch/s390/include/asm/io.h:75:
include/asm-generic/io.h:501:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writeb(value, PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:511:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:521:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
__raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
~~~~~~~~~~ ^
include/asm-generic/io.h:609:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:617:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:625:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
readsl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:634:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesb(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:643:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesw(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
include/asm-generic/io.h:652:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
writesl(PCI_IOBASE + addr, buffer, count);
~~~~~~~~~~ ^
>> mm/huge_memory.c:2797:21: warning: variable 'memcg' set but not used [-Wunused-but-set-variable]
struct mem_cgroup *memcg;
^
13 warnings generated.
vim +/memcg +2797 mm/huge_memory.c
2793
2794 void deferred_split_huge_page(struct page *page)
2795 {
2796 struct deferred_split *ds_queue;
> 2797 struct mem_cgroup *memcg;
2798 unsigned long flags;
2799
2800 VM_BUG_ON_PAGE(!PageTransHuge(page), page);
2801
2802 /*
2803 * The try_to_unmap() in page reclaim path might reach here too,
2804 * this may cause a race condition to corrupt deferred split queue.
2805 * And, if page reclaim is already handling the same page, it is
2806 * unnecessary to handle it again in shrinker.
2807 *
2808 * Check PageSwapCache to determine if the page is being
2809 * handled by page reclaim since THP swap would add the page into
2810 * swap cache before calling try_to_unmap().
2811 */
2812 if (PageSwapCache(page))
2813 return;
2814
2815 ds_queue = folio_split_queue_lock_irqsave(page_folio(page), &flags);
2816 memcg = split_queue_memcg(ds_queue);
2817 if (list_empty(page_deferred_list(page))) {
2818 count_vm_event(THP_DEFERRED_SPLIT_PAGE);
2819 list_add_tail(page_deferred_list(page), &ds_queue->split_queue);
2820 ds_queue->split_queue_len++;
2821 #ifdef CONFIG_MEMCG
2822 if (memcg)
2823 set_shrinker_bit(memcg, page_to_nid(page),
2824 deferred_split_shrinker.id);
2825 #endif
2826 }
2827 split_queue_unlock_irqrestore(ds_queue, flags);
2828 }
2829
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
1 year, 1 month
[cxl-cxl:pending 34/38] drivers/cxl/acpi.c:185:12: warning: no previous prototype for function 'match_add_root_ports'
by kernel test robot
tree: https://git.kernel.org/pub/scm/linux/kernel/git/cxl/cxl.git pending
head: fa809cc6feedcd2575b63def7135dfaf066266bb
commit: 5885b71419e9e23ff7d404f9c8a8a5c23d42f106 [34/38] tools/testing/cxl: Introduce a mocked-up CXL port hierarchy
config: x86_64-randconfig-a011-20210814 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 1f7b25ea76a925aca690da28de9d78db7ca99d0c)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://git.kernel.org/pub/scm/linux/kernel/git/cxl/cxl.git/commit/?id=58...
git remote add cxl-cxl https://git.kernel.org/pub/scm/linux/kernel/git/cxl/cxl.git
git fetch --no-tags cxl-cxl pending
git checkout 5885b71419e9e23ff7d404f9c8a8a5c23d42f106
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp(a)intel.com>
All warnings (new ones prefixed by >>):
>> drivers/cxl/acpi.c:185:12: warning: no previous prototype for function 'match_add_root_ports' [-Wmissing-prototypes]
__weak int match_add_root_ports(struct pci_dev *pdev, void *data)
^
drivers/cxl/acpi.c:185:8: note: declare 'static' if the function is not intended to be used outside of this translation unit
__weak int match_add_root_ports(struct pci_dev *pdev, void *data)
^
static
>> drivers/cxl/acpi.c:236:28: warning: no previous prototype for function 'to_cxl_host_bridge' [-Wmissing-prototypes]
__weak struct acpi_device *to_cxl_host_bridge(struct device *host,
^
drivers/cxl/acpi.c:236:8: note: declare 'static' if the function is not intended to be used outside of this translation unit
__weak struct acpi_device *to_cxl_host_bridge(struct device *host,
^
static
2 warnings generated.
vim +/match_add_root_ports +185 drivers/cxl/acpi.c
184
> 185 __weak int match_add_root_ports(struct pci_dev *pdev, void *data)
186 {
187 struct cxl_walk_context *ctx = data;
188 struct pci_bus *root_bus = ctx->root;
189 struct cxl_port *port = ctx->port;
190 int type = pci_pcie_type(pdev);
191 struct device *dev = ctx->dev;
192 u32 lnkcap, port_num;
193 int rc;
194
195 if (pdev->bus != root_bus)
196 return 0;
197 if (!pci_is_pcie(pdev))
198 return 0;
199 if (type != PCI_EXP_TYPE_ROOT_PORT)
200 return 0;
201 if (pci_read_config_dword(pdev, pci_pcie_cap(pdev) + PCI_EXP_LNKCAP,
202 &lnkcap) != PCIBIOS_SUCCESSFUL)
203 return 0;
204
205 /* TODO walk DVSEC to find component register base */
206 port_num = FIELD_GET(PCI_EXP_LNKCAP_PN, lnkcap);
207 rc = cxl_add_dport(port, &pdev->dev, port_num, CXL_RESOURCE_NONE);
208 if (rc) {
209 dev_err(dev, "failed to add dport: %s (%d)\n",
210 dev_name(&pdev->dev), rc);
211 ctx->error = rc;
212 return rc;
213 }
214 ctx->count++;
215
216 dev_dbg(dev, "add dport%d: %s\n", port_num, dev_name(&pdev->dev));
217
218 return 0;
219 }
220
221 static struct cxl_dport *find_dport_by_dev(struct cxl_port *port, struct device *dev)
222 {
223 struct cxl_dport *dport;
224
225 device_lock(&port->dev);
226 list_for_each_entry(dport, &port->dports, list)
227 if (dport->dport == dev) {
228 device_unlock(&port->dev);
229 return dport;
230 }
231
232 device_unlock(&port->dev);
233 return NULL;
234 }
235
> 236 __weak struct acpi_device *to_cxl_host_bridge(struct device *host,
237 struct device *dev)
238 {
239 struct acpi_device *adev = to_acpi_device(dev);
240
241 if (strcmp(acpi_device_hid(adev), "ACPI0016") == 0) {
242 dev_dbg(host, "found host bridge %s\n", dev_name(&adev->dev));
243 return adev;
244 }
245 return NULL;
246 }
247
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
1 year, 1 month
[cxl-cxl:pending 31/38] drivers/cxl/pmem.c:66:6: warning: variable 'nvdimm' is used uninitialized whenever 'if' condition is true
by kernel test robot
tree: https://git.kernel.org/pub/scm/linux/kernel/git/cxl/cxl.git pending
head: fa809cc6feedcd2575b63def7135dfaf066266bb
commit: fc6fd550b9f1ada1bdb5e12f83e3794e81a2eb42 [31/38] cxl/mbox: Add exclusive kernel command support
config: x86_64-randconfig-a015-20210814 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 1f7b25ea76a925aca690da28de9d78db7ca99d0c)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://git.kernel.org/pub/scm/linux/kernel/git/cxl/cxl.git/commit/?id=fc...
git remote add cxl-cxl https://git.kernel.org/pub/scm/linux/kernel/git/cxl/cxl.git
git fetch --no-tags cxl-cxl pending
git checkout fc6fd550b9f1ada1bdb5e12f83e3794e81a2eb42
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp(a)intel.com>
All warnings (new ones prefixed by >>):
>> drivers/cxl/pmem.c:66:6: warning: variable 'nvdimm' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
if (!cxl_nvb->nvdimm_bus)
^~~~~~~~~~~~~~~~~~~~
drivers/cxl/pmem.c:80:7: note: uninitialized use occurs here
if (!nvdimm && rc == 0)
^~~~~~
drivers/cxl/pmem.c:66:2: note: remove the 'if' if its condition is always false
if (!cxl_nvb->nvdimm_bus)
^~~~~~~~~~~~~~~~~~~~~~~~~
drivers/cxl/pmem.c:58:23: note: initialize the variable 'nvdimm' to silence this warning
struct nvdimm *nvdimm;
^
= NULL
1 warning generated.
vim +66 drivers/cxl/pmem.c
21083f51521fb0 Dan Williams 2021-06-15 50
21083f51521fb0 Dan Williams 2021-06-15 51 static int cxl_nvdimm_probe(struct device *dev)
21083f51521fb0 Dan Williams 2021-06-15 52 {
21083f51521fb0 Dan Williams 2021-06-15 53 struct cxl_nvdimm *cxl_nvd = to_cxl_nvdimm(dev);
fc6fd550b9f1ad Dan Williams 2021-06-17 54 struct cxl_memdev *cxlmd = cxl_nvd->cxlmd;
fc6fd550b9f1ad Dan Williams 2021-06-17 55 struct cxl_mem *cxlm = cxlmd->cxlm;
21083f51521fb0 Dan Williams 2021-06-15 56 struct cxl_nvdimm_bridge *cxl_nvb;
21083f51521fb0 Dan Williams 2021-06-15 57 unsigned long flags = 0;
21083f51521fb0 Dan Williams 2021-06-15 58 struct nvdimm *nvdimm;
21083f51521fb0 Dan Williams 2021-06-15 59 int rc = -ENXIO;
21083f51521fb0 Dan Williams 2021-06-15 60
21083f51521fb0 Dan Williams 2021-06-15 61 cxl_nvb = cxl_find_nvdimm_bridge();
21083f51521fb0 Dan Williams 2021-06-15 62 if (!cxl_nvb)
21083f51521fb0 Dan Williams 2021-06-15 63 return -ENXIO;
21083f51521fb0 Dan Williams 2021-06-15 64
21083f51521fb0 Dan Williams 2021-06-15 65 device_lock(&cxl_nvb->dev);
21083f51521fb0 Dan Williams 2021-06-15 @66 if (!cxl_nvb->nvdimm_bus)
21083f51521fb0 Dan Williams 2021-06-15 67 goto out;
21083f51521fb0 Dan Williams 2021-06-15 68
fc6fd550b9f1ad Dan Williams 2021-06-17 69 set_exclusive_cxl_commands(cxlm, exclusive_cmds);
fc6fd550b9f1ad Dan Williams 2021-06-17 70
21083f51521fb0 Dan Williams 2021-06-15 71 set_bit(NDD_LABELING, &flags);
21083f51521fb0 Dan Williams 2021-06-15 72 nvdimm = nvdimm_create(cxl_nvb->nvdimm_bus, cxl_nvd, NULL, flags, 0, 0,
21083f51521fb0 Dan Williams 2021-06-15 73 NULL);
fc6fd550b9f1ad Dan Williams 2021-06-17 74 dev_set_drvdata(dev, nvdimm);
fc6fd550b9f1ad Dan Williams 2021-06-17 75 rc = devm_add_action_or_reset(dev, unregister_nvdimm, cxl_nvd);
21083f51521fb0 Dan Williams 2021-06-15 76 out:
21083f51521fb0 Dan Williams 2021-06-15 77 device_unlock(&cxl_nvb->dev);
21083f51521fb0 Dan Williams 2021-06-15 78 put_device(&cxl_nvb->dev);
21083f51521fb0 Dan Williams 2021-06-15 79
fc6fd550b9f1ad Dan Williams 2021-06-17 80 if (!nvdimm && rc == 0)
fc6fd550b9f1ad Dan Williams 2021-06-17 81 rc = -ENOMEM;
fc6fd550b9f1ad Dan Williams 2021-06-17 82
21083f51521fb0 Dan Williams 2021-06-15 83 return rc;
21083f51521fb0 Dan Williams 2021-06-15 84 }
21083f51521fb0 Dan Williams 2021-06-15 85
:::::: The code at line 66 was first introduced by commit
:::::: 21083f51521fb0f60dbac591f175c3ed48435af4 cxl/pmem: Register 'pmem' / cxl_nvdimm devices
:::::: TO: Dan Williams <dan.j.williams(a)intel.com>
:::::: CC: Dan Williams <dan.j.williams(a)intel.com>
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
1 year, 1 month
[android-common:android12-5.4 14/27] fs/userfaultfd.c:1519:9: warning: variable 'ioctls_out' set but not used
by kernel test robot
tree: https://android.googlesource.com/kernel/common android12-5.4
head: 2c6775a89bc167ea4c153db9ffc3b081d34a05b8
commit: b69f713e60d03ae448e5c9fd92e5b0b193dea7be [14/27] BACKPORT: FROMGIT: userfaultfd: add UFFDIO_CONTINUE ioctl
config: x86_64-randconfig-c001-20210814 (attached as .config)
compiler: clang version 14.0.0 (https://github.com/llvm/llvm-project 62df4df41c939205b2dc0a2a3bfb75b8c1ed74fa)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
git remote add android-common https://android.googlesource.com/kernel/common
git fetch --no-tags android-common android12-5.4
git checkout b69f713e60d03ae448e5c9fd92e5b0b193dea7be
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp(a)intel.com>
All warnings (new ones prefixed by >>):
>> fs/userfaultfd.c:1519:9: warning: variable 'ioctls_out' set but not used [-Wunused-but-set-variable]
__u64 ioctls_out;
^
1 warning generated.
vim +/ioctls_out +1519 fs/userfaultfd.c
1311
1312 static int userfaultfd_register(struct userfaultfd_ctx *ctx,
1313 unsigned long arg)
1314 {
1315 struct mm_struct *mm = ctx->mm;
1316 struct vm_area_struct *vma, *prev, *cur;
1317 int ret;
1318 struct uffdio_register uffdio_register;
1319 struct uffdio_register __user *user_uffdio_register;
1320 unsigned long vm_flags, new_flags;
1321 bool found;
1322 bool basic_ioctls;
1323 unsigned long start, end, vma_end;
1324
1325 user_uffdio_register = (struct uffdio_register __user *) arg;
1326
1327 ret = -EFAULT;
1328 if (copy_from_user(&uffdio_register, user_uffdio_register,
1329 sizeof(uffdio_register)-sizeof(__u64)))
1330 goto out;
1331
1332 ret = -EINVAL;
1333 if (!uffdio_register.mode)
1334 goto out;
1335 if (uffdio_register.mode & ~UFFD_API_REGISTER_MODES)
1336 goto out;
1337 vm_flags = 0;
1338 if (uffdio_register.mode & UFFDIO_REGISTER_MODE_MISSING)
1339 vm_flags |= VM_UFFD_MISSING;
1340 if (uffdio_register.mode & UFFDIO_REGISTER_MODE_WP) {
1341 vm_flags |= VM_UFFD_WP;
1342 /*
1343 * FIXME: remove the below error constraint by
1344 * implementing the wprotect tracking mode.
1345 */
1346 ret = -EINVAL;
1347 goto out;
1348 }
1349 if (uffdio_register.mode & UFFDIO_REGISTER_MODE_MINOR) {
1350 #ifndef CONFIG_HAVE_ARCH_USERFAULTFD_MINOR
1351 goto out;
1352 #endif
1353 vm_flags |= VM_UFFD_MINOR;
1354 }
1355
1356 ret = validate_range(mm, &uffdio_register.range.start,
1357 uffdio_register.range.len);
1358 if (ret)
1359 goto out;
1360
1361 start = uffdio_register.range.start;
1362 end = start + uffdio_register.range.len;
1363
1364 ret = -ENOMEM;
1365 if (!mmget_not_zero(mm))
1366 goto out;
1367
1368 down_write(&mm->mmap_sem);
1369 if (!mmget_still_valid(mm))
1370 goto out_unlock;
1371 vma = find_vma_prev(mm, start, &prev);
1372 if (!vma)
1373 goto out_unlock;
1374
1375 /* check that there's at least one vma in the range */
1376 ret = -EINVAL;
1377 if (vma->vm_start >= end)
1378 goto out_unlock;
1379
1380 /*
1381 * If the first vma contains huge pages, make sure start address
1382 * is aligned to huge page size.
1383 */
1384 if (is_vm_hugetlb_page(vma)) {
1385 unsigned long vma_hpagesize = vma_kernel_pagesize(vma);
1386
1387 if (start & (vma_hpagesize - 1))
1388 goto out_unlock;
1389 }
1390
1391 /*
1392 * Search for not compatible vmas.
1393 */
1394 found = false;
1395 basic_ioctls = false;
1396 for (cur = vma; cur && cur->vm_start < end; cur = cur->vm_next) {
1397 cond_resched();
1398
1399 BUG_ON(!!cur->vm_userfaultfd_ctx.ctx ^
1400 !!(cur->vm_flags & __VM_UFFD_FLAGS));
1401
1402 /* check not compatible vmas */
1403 ret = -EINVAL;
1404 if (!vma_can_userfault(cur, vm_flags))
1405 goto out_unlock;
1406
1407 /*
1408 * UFFDIO_COPY will fill file holes even without
1409 * PROT_WRITE. This check enforces that if this is a
1410 * MAP_SHARED, the process has write permission to the backing
1411 * file. If VM_MAYWRITE is set it also enforces that on a
1412 * MAP_SHARED vma: there is no F_WRITE_SEAL and no further
1413 * F_WRITE_SEAL can be taken until the vma is destroyed.
1414 */
1415 ret = -EPERM;
1416 if (unlikely(!(cur->vm_flags & VM_MAYWRITE)))
1417 goto out_unlock;
1418
1419 /*
1420 * If this vma contains ending address, and huge pages
1421 * check alignment.
1422 */
1423 if (is_vm_hugetlb_page(cur) && end <= cur->vm_end &&
1424 end > cur->vm_start) {
1425 unsigned long vma_hpagesize = vma_kernel_pagesize(cur);
1426
1427 ret = -EINVAL;
1428
1429 if (end & (vma_hpagesize - 1))
1430 goto out_unlock;
1431 }
1432
1433 /*
1434 * Check that this vma isn't already owned by a
1435 * different userfaultfd. We can't allow more than one
1436 * userfaultfd to own a single vma simultaneously or we
1437 * wouldn't know which one to deliver the userfaults to.
1438 */
1439 ret = -EBUSY;
1440 if (cur->vm_userfaultfd_ctx.ctx &&
1441 cur->vm_userfaultfd_ctx.ctx != ctx)
1442 goto out_unlock;
1443
1444 /*
1445 * Note vmas containing huge pages
1446 */
1447 if (is_vm_hugetlb_page(cur))
1448 basic_ioctls = true;
1449
1450 found = true;
1451 }
1452 BUG_ON(!found);
1453
1454 if (vma->vm_start < start)
1455 prev = vma;
1456
1457 ret = 0;
1458 do {
1459 cond_resched();
1460
1461 BUG_ON(!vma_can_userfault(vma, vm_flags));
1462 BUG_ON(vma->vm_userfaultfd_ctx.ctx &&
1463 vma->vm_userfaultfd_ctx.ctx != ctx);
1464 WARN_ON(!(vma->vm_flags & VM_MAYWRITE));
1465
1466 /*
1467 * Nothing to do: this vma is already registered into this
1468 * userfaultfd and with the right tracking mode too.
1469 */
1470 if (vma->vm_userfaultfd_ctx.ctx == ctx &&
1471 (vma->vm_flags & vm_flags) == vm_flags)
1472 goto skip;
1473
1474 if (vma->vm_start > start)
1475 start = vma->vm_start;
1476 vma_end = min(end, vma->vm_end);
1477
1478 new_flags = (vma->vm_flags & ~__VM_UFFD_FLAGS) | vm_flags;
1479 prev = vma_merge(mm, prev, start, vma_end, new_flags,
1480 vma->anon_vma, vma->vm_file, vma->vm_pgoff,
1481 vma_policy(vma),
1482 ((struct vm_userfaultfd_ctx){ ctx }),
1483 vma_get_anon_name(vma));
1484 if (prev) {
1485 vma = prev;
1486 goto next;
1487 }
1488 if (vma->vm_start < start) {
1489 ret = split_vma(mm, vma, start, 1);
1490 if (ret)
1491 break;
1492 }
1493 if (vma->vm_end > end) {
1494 ret = split_vma(mm, vma, end, 0);
1495 if (ret)
1496 break;
1497 }
1498 next:
1499 /*
1500 * In the vma_merge() successful mprotect-like case 8:
1501 * the next vma was merged into the current one and
1502 * the current one has not been updated yet.
1503 */
1504 vma->vm_flags = new_flags;
1505 vma->vm_userfaultfd_ctx.ctx = ctx;
1506
1507 if (is_vm_hugetlb_page(vma) && uffd_disable_huge_pmd_share(vma))
1508 hugetlb_unshare_all_pmds(vma);
1509
1510 skip:
1511 prev = vma;
1512 start = vma->vm_end;
1513 vma = vma->vm_next;
1514 } while (vma && vma->vm_start < end);
1515 out_unlock:
1516 up_write(&mm->mmap_sem);
1517 mmput(mm);
1518 if (!ret) {
> 1519 __u64 ioctls_out;
1520
1521 ioctls_out = basic_ioctls ? UFFD_API_RANGE_IOCTLS_BASIC :
1522 UFFD_API_RANGE_IOCTLS;
1523
1524 /* CONTINUE ioctl is only supported for MINOR ranges. */
1525 if (!(uffdio_register.mode & UFFDIO_REGISTER_MODE_MINOR))
1526 ioctls_out &= ~((__u64)1 << _UFFDIO_CONTINUE);
1527
1528 /*
1529 * Now that we scanned all vmas we can already tell
1530 * userland which ioctls methods are guaranteed to
1531 * succeed on this range.
1532 */
1533 if (put_user(basic_ioctls ? UFFD_API_RANGE_IOCTLS_BASIC :
1534 UFFD_API_RANGE_IOCTLS,
1535 &user_uffdio_register->ioctls))
1536 ret = -EFAULT;
1537 }
1538 out:
1539 return ret;
1540 }
1541
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
1 year, 1 month