History

Merge branch 'akpm' (patches from Andrew)

Merge misc fixes from Andrew Morton: "16 fixes" * emailed patches from Andrew Morton <akpm@linux-foundation.org>: mm/devm_memremap_pages: fix final page put race PCI/P2PDMA: track pgmap references per resource, not globally lib/genalloc: introduce chunk owners PCI/P2PDMA: fix the gen_pool_add_virt() failure path mm/devm_memremap_pages: introduce devm_memunmap_pages drivers/base/devres: introduce devm_release_action() mm/vmscan.c: fix trying to reclaim unevictable LRU page coredump: fix race condition between collapse_huge_page() and core dumping mm/mlock.c: change count_mm_mlocked_page_nr return type mm: mmu_gather: remove __tlb_reset_range() for force flush fs/ocfs2: fix race in ocfs2_dentry_attach_lock() mm/vmscan.c: fix recent_rotated history mm/mlock.c: mlockall error for flag MCL_ONFAULT scripts/decode_stacktrace.sh: prefix addr2line with $CROSS_COMPILE mm/list_lru.c: fix memory leak in __memcg_init_list_lru_node mm: memcontrol: don't batch updates of local VM stats and events

Linus Torvalds committed 7 years ago

Commit fd6b99f2 parents c78ad1b 50f44ee21 files · +310 −140Browse files

Unified · Split

21 files
  1. drivers/base/devres.c +23 −1
  2. drivers/dax/device.c +3 −10
  3. drivers/nvdimm/pmem.c +13 −4
  4. drivers/pci/p2pdma.c +72 −43
  5. fs/ocfs2/dcache.c +12 −0
  6. include/linux/device.h +1 −0
  7. include/linux/genalloc.h +49 −6
  8. include/linux/memcontrol.h +18 −8
  9. include/linux/memremap.h +8 −0
  10. include/linux/sched/mm.h +4 −0
  11. kernel/memremap.c +18 −5
  12. lib/genalloc.c +25 −26
  13. mm/hmm.c +3 −11
  14. mm/khugepaged.c +3 −0
  15. mm/list_lru.c +1 −1
  16. mm/memcontrol.c +28 −13
  17. mm/mlock.c +4 −3
  18. mm/mmu_gather.c +19 −5
  19. mm/vmscan.c +3 −3
  20. scripts/decode_stacktrace.sh +1 −1
  21. tools/testing/nvdimm/test/iomap.c +2 −0
drivers/base/devres.c+23−1
@@ -755,10 +755,32 @@ void devm_remove_action(struct device *dev, void (*action)(void *), void *data) · 754 unmodified lines
755755
756756 WARN_ON(devres_destroy(dev, devm_action_release, devm_action_match,
757757 &devres));
758−
759758 }
760759 EXPORT_SYMBOL_GPL(devm_remove_action);
761760
761+/**
762+ * devm_release_action() - release previously added custom action
763+ * @dev: Device that owns the action
764+ * @action: Function implementing the action
765+ * @data: Pointer to data passed to @action implementation
766+ *
767+ * Releases and removes instance of @action previously added by
768+ * devm_add_action(). Both action and data should match one of the
769+ * existing entries.
770+ */
771+void devm_release_action(struct device *dev, void (*action)(void *), void *data)
772+{
773+ struct action_devres devres = {
774+ .data = data,
775+ .action = action,
776+ };
777+
778+ WARN_ON(devres_release(dev, devm_action_release, devm_action_match,
779+ &devres));
780+
781+}
782+EXPORT_SYMBOL_GPL(devm_release_action);
783+
762784 /*
763785 * Managed kmalloc/kfree
764786 */
drivers/dax/device.c+3−10
@@ -27,9 +27,8 @@ static void dev_dax_percpu_release(struct percpu_ref *ref) · 26 unmodified lines
2727 complete(&dev_dax->cmp);
2828 }
2929
30−static void dev_dax_percpu_exit(void *data)
30+static void dev_dax_percpu_exit(struct percpu_ref *ref)
3131 {
32− struct percpu_ref *ref = data;
3332 struct dev_dax *dev_dax = ref_to_dev_dax(ref);
3433
3534 dev_dbg(&dev_dax->dev, "%s\n", __func__);
@@ -466,18 +465,12 @@ int dev_dax_probe(struct device *dev) · 430 unmodified lines
466465 if (rc)
467466 return rc;
468467
469− rc = devm_add_action_or_reset(dev, dev_dax_percpu_exit, &dev_dax->ref);
470− if (rc)
471− return rc;
472−
473468 dev_dax->pgmap.ref = &dev_dax->ref;
474469 dev_dax->pgmap.kill = dev_dax_percpu_kill;
470+ dev_dax->pgmap.cleanup = dev_dax_percpu_exit;
475471 addr = devm_memremap_pages(dev, &dev_dax->pgmap);
476− if (IS_ERR(addr)) {
477− devm_remove_action(dev, dev_dax_percpu_exit, &dev_dax->ref);
478− percpu_ref_exit(&dev_dax->ref);
472+ if (IS_ERR(addr))
479473 return PTR_ERR(addr);
480− }
481474
482475 inode = dax_inode(dax_dev);
483476 cdev = inode->i_cdev;
drivers/nvdimm/pmem.c+13−4
@@ -303,11 +303,19 @@ static const struct attribute_group *pmem_attribute_groups[] = { · 302 unmodified lines
303303 NULL,
304304 };
305305
306−static void pmem_release_queue(void *q)
306+static void __pmem_release_queue(struct percpu_ref *ref)
307307 {
308+ struct request_queue *q;
309+
310+ q = container_of(ref, typeof(*q), q_usage_counter);
308311 blk_cleanup_queue(q);
309312 }
310313
314+static void pmem_release_queue(void *ref)
315+{
316+ __pmem_release_queue(ref);
317+}
318+
311319 static void pmem_freeze_queue(struct percpu_ref *ref)
312320 {
313321 struct request_queue *q;
@@ -399,12 +407,10 @@ static int pmem_attach_disk(struct device *dev, · 85 unmodified lines
399407 if (!q)
400408 return -ENOMEM;
401409
402− if (devm_add_action_or_reset(dev, pmem_release_queue, q))
403− return -ENOMEM;
404−
405410 pmem->pfn_flags = PFN_DEV;
406411 pmem->pgmap.ref = &q->q_usage_counter;
407412 pmem->pgmap.kill = pmem_freeze_queue;
413+ pmem->pgmap.cleanup = __pmem_release_queue;
408414 if (is_nd_pfn(dev)) {
409415 if (setup_pagemap_fsdax(dev, &pmem->pgmap))
410416 return -ENOMEM;
@@ -425,6 +431,9 @@ static int pmem_attach_disk(struct device *dev, · 14 unmodified lines
425431 pmem->pfn_flags |= PFN_MAP;
426432 memcpy(&bb_res, &pmem->pgmap.res, sizeof(bb_res));
427433 } else {
434+ if (devm_add_action_or_reset(dev, pmem_release_queue,
435+ &q->q_usage_counter))
436+ return -ENOMEM;
428437 addr = devm_memremap(dev, pmem->phys_addr,
429438 pmem->size, ARCH_MEMREMAP_PMEM);
430439 memcpy(&bb_res, &nsio->res, sizeof(bb_res));
drivers/pci/p2pdma.c+72−43
@@ -20,12 +20,16 @@ · 19 unmodified lines
2020 #include <linux/seq_buf.h>
2121
2222 struct pci_p2pdma {
23− struct percpu_ref devmap_ref;
24− struct completion devmap_ref_done;
2523 struct gen_pool *pool;
2624 bool p2pmem_published;
2725 };
2826
27+struct p2pdma_pagemap {
28+ struct dev_pagemap pgmap;
29+ struct percpu_ref ref;
30+ struct completion ref_done;
31+};
32+
2933 static ssize_t size_show(struct device *dev, struct device_attribute *attr,
3034 char *buf)
3135 {
@@ -74,41 +78,45 @@ static const struct attribute_group p2pmem_group = { · 42 unmodified lines
7478 .name = "p2pmem",
7579 };
7680
81+static struct p2pdma_pagemap *to_p2p_pgmap(struct percpu_ref *ref)
82+{
83+ return container_of(ref, struct p2pdma_pagemap, ref);
84+}
85+
7786 static void pci_p2pdma_percpu_release(struct percpu_ref *ref)
7887 {
79− struct pci_p2pdma *p2p =
80− container_of(ref, struct pci_p2pdma, devmap_ref);
88+ struct p2pdma_pagemap *p2p_pgmap = to_p2p_pgmap(ref);
8189
82− complete_all(&p2p->devmap_ref_done);
90+ complete(&p2p_pgmap->ref_done);
8391 }
8492
8593 static void pci_p2pdma_percpu_kill(struct percpu_ref *ref)
8694 {
87− /*
88− * pci_p2pdma_add_resource() may be called multiple times
89− * by a driver and may register the percpu_kill devm action multiple
90− * times. We only want the first action to actually kill the
91− * percpu_ref.
92− */
93− if (percpu_ref_is_dying(ref))
94− return;
95−
9695 percpu_ref_kill(ref);
9796 }
9897
98+static void pci_p2pdma_percpu_cleanup(struct percpu_ref *ref)
99+{
100+ struct p2pdma_pagemap *p2p_pgmap = to_p2p_pgmap(ref);
101+
102+ wait_for_completion(&p2p_pgmap->ref_done);
103+ percpu_ref_exit(&p2p_pgmap->ref);
104+}
105+
99106 static void pci_p2pdma_release(void *data)
100107 {
101108 struct pci_dev *pdev = data;
109+ struct pci_p2pdma *p2pdma = pdev->p2pdma;
102110
103− if (!pdev->p2pdma)
111+ if (!p2pdma)
104112 return;
105113
106− wait_for_completion(&pdev->p2pdma->devmap_ref_done);
107− percpu_ref_exit(&pdev->p2pdma->devmap_ref);
114+ /* Flush and disable pci_alloc_p2p_mem() */
115+ pdev->p2pdma = NULL;
116+ synchronize_rcu();
108117
109− gen_pool_destroy(pdev->p2pdma->pool);
118+ gen_pool_destroy(p2pdma->pool);
110119 sysfs_remove_group(&pdev->dev.kobj, &p2pmem_group);
111− pdev->p2pdma = NULL;
112120 }
113121
114122 static int pci_p2pdma_setup(struct pci_dev *pdev)
@@ -124,12 +132,6 @@ static int pci_p2pdma_setup(struct pci_dev *pdev) · 9 unmodified lines
124132 if (!p2p->pool)
125133 goto out;
126134
127− init_completion(&p2p->devmap_ref_done);
128− error = percpu_ref_init(&p2p->devmap_ref,
129− pci_p2pdma_percpu_release, 0, GFP_KERNEL);
130− if (error)
131− goto out_pool_destroy;
132−
133135 error = devm_add_action_or_reset(&pdev->dev, pci_p2pdma_release, pdev);
134136 if (error)
135137 goto out_pool_destroy;
@@ -163,6 +165,7 @@ out: · 27 unmodified lines
163165 int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size,
164166 u64 offset)
165167 {
168+ struct p2pdma_pagemap *p2p_pgmap;
166169 struct dev_pagemap *pgmap;
167170 void *addr;
168171 int error;
@@ -185,18 +188,27 @@ int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size, · 16 unmodified lines
185188 return error;
186189 }
187190
188− pgmap = devm_kzalloc(&pdev->dev, sizeof(*pgmap), GFP_KERNEL);
189− if (!pgmap)
191+ p2p_pgmap = devm_kzalloc(&pdev->dev, sizeof(*p2p_pgmap), GFP_KERNEL);
192+ if (!p2p_pgmap)
190193 return -ENOMEM;
191194
195+ init_completion(&p2p_pgmap->ref_done);
196+ error = percpu_ref_init(&p2p_pgmap->ref,
197+ pci_p2pdma_percpu_release, 0, GFP_KERNEL);
198+ if (error)
199+ goto pgmap_free;
200+
201+ pgmap = &p2p_pgmap->pgmap;
202+
192203 pgmap->res.start = pci_resource_start(pdev, bar) + offset;
193204 pgmap->res.end = pgmap->res.start + size - 1;
194205 pgmap->res.flags = pci_resource_flags(pdev, bar);
195− pgmap->ref = &pdev->p2pdma->devmap_ref;
206+ pgmap->ref = &p2p_pgmap->ref;
196207 pgmap->type = MEMORY_DEVICE_PCI_P2PDMA;
197208 pgmap->pci_p2pdma_bus_offset = pci_bus_address(pdev, bar) -
198209 pci_resource_start(pdev, bar);
199210 pgmap->kill = pci_p2pdma_percpu_kill;
211+ pgmap->cleanup = pci_p2pdma_percpu_cleanup;
200212
201213 addr = devm_memremap_pages(&pdev->dev, pgmap);
202214 if (IS_ERR(addr)) {
@@ -204,19 +216,22 @@ int pci_p2pdma_add_resource(struct pci_dev *pdev, int bar, size_t size, · 1 unmodified line
204216 goto pgmap_free;
205217 }
206218
207− error = gen_pool_add_virt(pdev->p2pdma->pool, (unsigned long)addr,
219+ error = gen_pool_add_owner(pdev->p2pdma->pool, (unsigned long)addr,
208220 pci_bus_address(pdev, bar) + offset,
209− resource_size(&pgmap->res), dev_to_node(&pdev->dev));
221+ resource_size(&pgmap->res), dev_to_node(&pdev->dev),
222+ &p2p_pgmap->ref);
210223 if (error)
211− goto pgmap_free;
224+ goto pages_free;
212225
213226 pci_info(pdev, "added peer-to-peer DMA memory %pR\n",
214227 &pgmap->res);
215228
216229 return 0;
217230
231+pages_free:
232+ devm_memunmap_pages(&pdev->dev, pgmap);
218233 pgmap_free:
219− devm_kfree(&pdev->dev, pgmap);
234+ devm_kfree(&pdev->dev, p2p_pgmap);
220235 return error;
221236 }
222237 EXPORT_SYMBOL_GPL(pci_p2pdma_add_resource);
@@ -585,19 +600,30 @@ EXPORT_SYMBOL_GPL(pci_p2pmem_find_many); · 362 unmodified lines
585600 */
586601 void *pci_alloc_p2pmem(struct pci_dev *pdev, size_t size)
587602 {
588− void *ret;
603+ void *ret = NULL;
604+ struct percpu_ref *ref;
589605
606+ /*
607+ * Pairs with synchronize_rcu() in pci_p2pdma_release() to
608+ * ensure pdev->p2pdma is non-NULL for the duration of the
609+ * read-lock.
610+ */
611+ rcu_read_lock();
590612 if (unlikely(!pdev->p2pdma))
591− return NULL;
592−
593− if (unlikely(!percpu_ref_tryget_live(&pdev->p2pdma->devmap_ref)))
594− return NULL;
595−
596− ret = (void *)gen_pool_alloc(pdev->p2pdma->pool, size);
613+ goto out;
597614
598− if (unlikely(!ret))
599− percpu_ref_put(&pdev->p2pdma->devmap_ref);
615+ ret = (void *)gen_pool_alloc_owner(pdev->p2pdma->pool, size,
616+ (void **) &ref);
617+ if (!ret)
618+ goto out;
600619
620+ if (unlikely(!percpu_ref_tryget_live(ref))) {
621+ gen_pool_free(pdev->p2pdma->pool, (unsigned long) ret, size);
622+ ret = NULL;
623+ goto out;
624+ }
625+out:
626+ rcu_read_unlock();
601627 return ret;
602628 }
603629 EXPORT_SYMBOL_GPL(pci_alloc_p2pmem);
@@ -610,8 +636,11 @@ EXPORT_SYMBOL_GPL(pci_alloc_p2pmem); · 6 unmodified lines
610636 */
611637 void pci_free_p2pmem(struct pci_dev *pdev, void *addr, size_t size)
612638 {
613− gen_pool_free(pdev->p2pdma->pool, (uintptr_t)addr, size);
614− percpu_ref_put(&pdev->p2pdma->devmap_ref);
639+ struct percpu_ref *ref;
640+
641+ gen_pool_free_owner(pdev->p2pdma->pool, (uintptr_t)addr, size,
642+ (void **) &ref);
643+ percpu_ref_put(ref);
615644 }
616645 EXPORT_SYMBOL_GPL(pci_free_p2pmem);
617646
fs/ocfs2/dcache.c+12−0
@@ -296,6 +296,18 @@ int ocfs2_dentry_attach_lock(struct dentry *dentry, · 295 unmodified lines
296296
297297 out_attach:
298298 spin_lock(&dentry_attach_lock);
299+ if (unlikely(dentry->d_fsdata && !alias)) {
300+ /* d_fsdata is set by a racing thread which is doing
301+ * the same thing as this thread is doing. Leave the racing
302+ * thread going ahead and we return here.
303+ */
304+ spin_unlock(&dentry_attach_lock);
305+ iput(dl->dl_inode);
306+ ocfs2_lock_res_free(&dl->dl_lockres);
307+ kfree(dl);
308+ return 0;
309+ }
310+
299311 dentry->d_fsdata = dl;
300312 dl->dl_count++;
301313 spin_unlock(&dentry_attach_lock);
include/linux/device.h+1−0
@@ -713,6 +713,7 @@ void __iomem *devm_of_iomap(struct device *dev, · 712 unmodified lines
713713 /* allows to add/remove a custom action to devres stack */
714714 int devm_add_action(struct device *dev, void (*action)(void *), void *data);
715715 void devm_remove_action(struct device *dev, void (*action)(void *), void *data);
716+void devm_release_action(struct device *dev, void (*action)(void *), void *data);
716717
717718 static inline int devm_add_action_or_reset(struct device *dev,
718719 void (*action)(void *), void *data)
include/linux/genalloc.h+49−6
@@ -75,6 +75,7 @@ struct gen_pool_chunk { · 74 unmodified lines
7575 struct list_head next_chunk; /* next chunk in pool */
7676 atomic_long_t avail;
7777 phys_addr_t phys_addr; /* physical starting address of memory chunk */
78+ void *owner; /* private data to retrieve at alloc time */
7879 unsigned long start_addr; /* start address of memory chunk */
7980 unsigned long end_addr; /* end address of memory chunk (inclusive) */
8081 unsigned long bits[0]; /* bitmap for allocating memory chunk */
@@ -96,8 +97,15 @@ struct genpool_data_fixed { · 15 unmodified lines
9697
9798 extern struct gen_pool *gen_pool_create(int, int);
9899 extern phys_addr_t gen_pool_virt_to_phys(struct gen_pool *pool, unsigned long);
99−extern int gen_pool_add_virt(struct gen_pool *, unsigned long, phys_addr_t,
100− size_t, int);
100+extern int gen_pool_add_owner(struct gen_pool *, unsigned long, phys_addr_t,
101+ size_t, int, void *);
102+
103+static inline int gen_pool_add_virt(struct gen_pool *pool, unsigned long addr,
104+ phys_addr_t phys, size_t size, int nid)
105+{
106+ return gen_pool_add_owner(pool, addr, phys, size, nid, NULL);
107+}
108+
101109 /**
102110 * gen_pool_add - add a new chunk of special memory to the pool
103111 * @pool: pool to add new memory chunk to
@@ -116,12 +124,47 @@ static inline int gen_pool_add(struct gen_pool *pool, unsigned long addr, · 12 unmodified lines
116124 return gen_pool_add_virt(pool, addr, -1, size, nid);
117125 }
118126 extern void gen_pool_destroy(struct gen_pool *);
119−extern unsigned long gen_pool_alloc(struct gen_pool *, size_t);
120−extern unsigned long gen_pool_alloc_algo(struct gen_pool *, size_t,
121− genpool_algo_t algo, void *data);
127+unsigned long gen_pool_alloc_algo_owner(struct gen_pool *pool, size_t size,
128+ genpool_algo_t algo, void *data, void **owner);
129+
130+static inline unsigned long gen_pool_alloc_owner(struct gen_pool *pool,
131+ size_t size, void **owner)
132+{
133+ return gen_pool_alloc_algo_owner(pool, size, pool->algo, pool->data,
134+ owner);
135+}
136+
137+static inline unsigned long gen_pool_alloc_algo(struct gen_pool *pool,
138+ size_t size, genpool_algo_t algo, void *data)
139+{
140+ return gen_pool_alloc_algo_owner(pool, size, algo, data, NULL);
141+}
142+
143+/**
144+ * gen_pool_alloc - allocate special memory from the pool
145+ * @pool: pool to allocate from
146+ * @size: number of bytes to allocate from the pool
147+ *
148+ * Allocate the requested number of bytes from the specified pool.
149+ * Uses the pool allocation function (with first-fit algorithm by default).
150+ * Can not be used in NMI handler on architectures without
151+ * NMI-safe cmpxchg implementation.
152+ */
153+static inline unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size)
154+{
155+ return gen_pool_alloc_algo(pool, size, pool->algo, pool->data);
156+}
157+
122158 extern void *gen_pool_dma_alloc(struct gen_pool *pool, size_t size,
123159 dma_addr_t *dma);
124−extern void gen_pool_free(struct gen_pool *, unsigned long, size_t);
160+extern void gen_pool_free_owner(struct gen_pool *pool, unsigned long addr,
161+ size_t size, void **owner);
162+static inline void gen_pool_free(struct gen_pool *pool, unsigned long addr,
163+ size_t size)
164+{
165+ gen_pool_free_owner(pool, addr, size, NULL);
166+}
167+
125168 extern void gen_pool_for_each_chunk(struct gen_pool *,
126169 void (*)(struct gen_pool *, struct gen_pool_chunk *, void *), void *);
127170 extern size_t gen_pool_avail(struct gen_pool *);
include/linux/memcontrol.h+18−8
@@ -117,9 +117,12 @@ struct memcg_shrinker_map { · 116 unmodified lines
117117 struct mem_cgroup_per_node {
118118 struct lruvec lruvec;
119119
120+ /* Legacy local VM stats */
121+ struct lruvec_stat __percpu *lruvec_stat_local;
122+
123+ /* Subtree VM stats (batched updates) */
120124 struct lruvec_stat __percpu *lruvec_stat_cpu;
121125 atomic_long_t lruvec_stat[NR_VM_NODE_STAT_ITEMS];
122− atomic_long_t lruvec_stat_local[NR_VM_NODE_STAT_ITEMS];
123126
124127 unsigned long lru_zone_size[MAX_NR_ZONES][NR_LRU_LISTS];
125128
@@ -265,17 +268,18 @@ struct mem_cgroup { · 139 unmodified lines
265268 atomic_t moving_account;
266269 struct task_struct *move_lock_task;
267270
268− /* memory.stat */
271+ /* Legacy local VM stats and events */
272+ struct memcg_vmstats_percpu __percpu *vmstats_local;
273+
274+ /* Subtree VM stats and events (batched updates) */
269275 struct memcg_vmstats_percpu __percpu *vmstats_percpu;
270276
271277 MEMCG_PADDING(_pad2_);
272278
273279 atomic_long_t vmstats[MEMCG_NR_STAT];
274− atomic_long_t vmstats_local[MEMCG_NR_STAT];
275−
276280 atomic_long_t vmevents[NR_VM_EVENT_ITEMS];
277− atomic_long_t vmevents_local[NR_VM_EVENT_ITEMS];
278281
282+ /* memory.events */
279283 atomic_long_t memory_events[MEMCG_NR_MEMORY_EVENTS];
280284
281285 unsigned long socket_pressure;
@@ -567,7 +571,11 @@ static inline unsigned long memcg_page_state(struct mem_cgroup *memcg, int idx) · 285 unmodified lines
567571 static inline unsigned long memcg_page_state_local(struct mem_cgroup *memcg,
568572 int idx)
569573 {
570− long x = atomic_long_read(&memcg->vmstats_local[idx]);
574+ long x = 0;
575+ int cpu;
576+
577+ for_each_possible_cpu(cpu)
578+ x += per_cpu(memcg->vmstats_local->stat[idx], cpu);
571579 #ifdef CONFIG_SMP
572580 if (x < 0)
573581 x = 0;
@@ -641,13 +649,15 @@ static inline unsigned long lruvec_page_state_local(struct lruvec *lruvec, · 67 unmodified lines
641649 enum node_stat_item idx)
642650 {
643651 struct mem_cgroup_per_node *pn;
644− long x;
652+ long x = 0;
653+ int cpu;
645654
646655 if (mem_cgroup_disabled())
647656 return node_page_state(lruvec_pgdat(lruvec), idx);
648657
649658 pn = container_of(lruvec, struct mem_cgroup_per_node, lruvec);
650− x = atomic_long_read(&pn->lruvec_stat_local[idx]);
659+ for_each_possible_cpu(cpu)
660+ x += per_cpu(pn->lruvec_stat_local->count[idx], cpu);
651661 #ifdef CONFIG_SMP
652662 if (x < 0)
653663 x = 0;
include/linux/memremap.h+8−0
@@ -81,6 +81,7 @@ typedef void (*dev_page_free_t)(struct page *page, void *data); · 80 unmodified lines
8181 * @res: physical address range covered by @ref
8282 * @ref: reference count that pins the devm_memremap_pages() mapping
8383 * @kill: callback to transition @ref to the dead state
84+ * @cleanup: callback to wait for @ref to be idle and reap it
8485 * @dev: host device of the mapping for debug
8586 * @data: private data pointer for page_free()
8687 * @type: memory type: see MEMORY_* in memory_hotplug.h
@@ -92,6 +93,7 @@ struct dev_pagemap { · 5 unmodified lines
9293 struct resource res;
9394 struct percpu_ref *ref;
9495 void (*kill)(struct percpu_ref *ref);
96+ void (*cleanup)(struct percpu_ref *ref);
9597 struct device *dev;
9698 void *data;
9799 enum memory_type type;
@@ -100,6 +102,7 @@ struct dev_pagemap { · 2 unmodified lines
100102
101103 #ifdef CONFIG_ZONE_DEVICE
102104 void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap);
105+void devm_memunmap_pages(struct device *dev, struct dev_pagemap *pgmap);
103106 struct dev_pagemap *get_dev_pagemap(unsigned long pfn,
104107 struct dev_pagemap *pgmap);
105108
@@ -118,6 +121,11 @@ static inline void *devm_memremap_pages(struct device *dev, · 12 unmodified lines
118121 return ERR_PTR(-ENXIO);
119122 }
120123
124+static inline void devm_memunmap_pages(struct device *dev,
125+ struct dev_pagemap *pgmap)
126+{
127+}
128+
121129 static inline struct dev_pagemap *get_dev_pagemap(unsigned long pfn,
122130 struct dev_pagemap *pgmap)
123131 {
include/linux/sched/mm.h+4−0
@@ -54,6 +54,10 @@ static inline void mmdrop(struct mm_struct *mm) · 53 unmodified lines
5454 * followed by taking the mmap_sem for writing before modifying the
5555 * vmas or anything the coredump pretends not to change from under it.
5656 *
57+ * It also has to be called when mmgrab() is used in the context of
58+ * the process, but then the mm_count refcount is transferred outside
59+ * the context of the process to run down_write() on that pinned mm.
60+ *
5761 * NOTE: find_extend_vma() called from GUP context is the only place
5862 * that can modify the "mm" (notably the vm_start/end) under mmap_sem
5963 * for reading and outside the context of the process, so it is also
kernel/memremap.c+18−5
@@ -95,6 +95,7 @@ static void devm_memremap_pages_release(void *data) · 94 unmodified lines
9595 pgmap->kill(pgmap->ref);
9696 for_each_device_pfn(pfn, pgmap)
9797 put_page(pfn_to_page(pfn));
98+ pgmap->cleanup(pgmap->ref);
9899
99100 /* pages are dead and unused, undo the arch mapping */
100101 align_start = res->start & ~(SECTION_SIZE - 1);
@@ -133,8 +134,8 @@ static void devm_memremap_pages_release(void *data) · 32 unmodified lines
133134 * 2/ The altmap field may optionally be initialized, in which case altmap_valid
134135 * must be set to true
135136 *
136− * 3/ pgmap->ref must be 'live' on entry and will be killed at
137− * devm_memremap_pages_release() time, or if this routine fails.
137+ * 3/ pgmap->ref must be 'live' on entry and will be killed and reaped
138+ * at devm_memremap_pages_release() time, or if this routine fails.
138139 *
139140 * 4/ res is expected to be a host memory range that could feasibly be
140141 * treated as a "System RAM" range, i.e. not a device mmio range, but
@@ -156,8 +157,10 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) · 15 unmodified lines
156157 pgprot_t pgprot = PAGE_KERNEL;
157158 int error, nid, is_ram;
158159
159− if (!pgmap->ref || !pgmap->kill)
160+ if (!pgmap->ref || !pgmap->kill || !pgmap->cleanup) {
161+ WARN(1, "Missing reference count teardown definition\n");
160162 return ERR_PTR(-EINVAL);
163+ }
161164
162165 align_start = res->start & ~(SECTION_SIZE - 1);
163166 align_size = ALIGN(res->start + resource_size(res), SECTION_SIZE)
@@ -168,14 +171,16 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) · 4 unmodified lines
168171 if (conflict_pgmap) {
169172 dev_WARN(dev, "Conflicting mapping in same section\n");
170173 put_dev_pagemap(conflict_pgmap);
171− return ERR_PTR(-ENOMEM);
174+ error = -ENOMEM;
175+ goto err_array;
172176 }
173177
174178 conflict_pgmap = get_dev_pagemap(PHYS_PFN(align_end), NULL);
175179 if (conflict_pgmap) {
176180 dev_WARN(dev, "Conflicting mapping in same section\n");
177181 put_dev_pagemap(conflict_pgmap);
178− return ERR_PTR(-ENOMEM);
182+ error = -ENOMEM;
183+ goto err_array;
179184 }
180185
181186 is_ram = region_intersects(align_start, align_size,
@@ -267,10 +272,18 @@ void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap) · 85 unmodified lines
267272 pgmap_array_delete(res);
268273 err_array:
269274 pgmap->kill(pgmap->ref);
275+ pgmap->cleanup(pgmap->ref);
276+
270277 return ERR_PTR(error);
271278 }
272279 EXPORT_SYMBOL_GPL(devm_memremap_pages);
273280
281+void devm_memunmap_pages(struct device *dev, struct dev_pagemap *pgmap)
282+{
283+ devm_release_action(dev, devm_memremap_pages_release, pgmap);
284+}
285+EXPORT_SYMBOL_GPL(devm_memunmap_pages);
286+
274287 unsigned long vmem_altmap_offset(struct vmem_altmap *altmap)
275288 {
276289 /* number of pfns from base where pfn_to_page() is valid */
lib/genalloc.c+25−26
@@ -168,20 +168,21 @@ struct gen_pool *gen_pool_create(int min_alloc_order, int nid) · 167 unmodified lines
168168 EXPORT_SYMBOL(gen_pool_create);
169169
170170 /**
171− * gen_pool_add_virt - add a new chunk of special memory to the pool
171+ * gen_pool_add_owner- add a new chunk of special memory to the pool
172172 * @pool: pool to add new memory chunk to
173173 * @virt: virtual starting address of memory chunk to add to pool
174174 * @phys: physical starting address of memory chunk to add to pool
175175 * @size: size in bytes of the memory chunk to add to pool
176176 * @nid: node id of the node the chunk structure and bitmap should be
177177 * allocated on, or -1
178+ * @owner: private data the publisher would like to recall at alloc time
178179 *
179180 * Add a new chunk of special memory to the specified pool.
180181 *
181182 * Returns 0 on success or a -ve errno on failure.
182183 */
183−int gen_pool_add_virt(struct gen_pool *pool, unsigned long virt, phys_addr_t phys,
184− size_t size, int nid)
184+int gen_pool_add_owner(struct gen_pool *pool, unsigned long virt, phys_addr_t phys,
185+ size_t size, int nid, void *owner)
185186 {
186187 struct gen_pool_chunk *chunk;
187188 int nbits = size >> pool->min_alloc_order;
@@ -195,6 +196,7 @@ int gen_pool_add_virt(struct gen_pool *pool, unsigned long virt, phys_addr_t phy · 7 unmodified lines
195196 chunk->phys_addr = phys;
196197 chunk->start_addr = virt;
197198 chunk->end_addr = virt + size - 1;
199+ chunk->owner = owner;
198200 atomic_long_set(&chunk->avail, size);
199201
200202 spin_lock(&pool->lock);
@@ -203,7 +205,7 @@ int gen_pool_add_virt(struct gen_pool *pool, unsigned long virt, phys_addr_t phy · 2 unmodified lines
203205
204206 return 0;
205207 }
206−EXPORT_SYMBOL(gen_pool_add_virt);
208+EXPORT_SYMBOL(gen_pool_add_owner);
207209
208210 /**
209211 * gen_pool_virt_to_phys - return the physical address of memory
@@ -260,35 +262,20 @@ void gen_pool_destroy(struct gen_pool *pool) · 50 unmodified lines
260262 EXPORT_SYMBOL(gen_pool_destroy);
261263
262264 /**
263− * gen_pool_alloc - allocate special memory from the pool
264− * @pool: pool to allocate from
265− * @size: number of bytes to allocate from the pool
266− *
267− * Allocate the requested number of bytes from the specified pool.
268− * Uses the pool allocation function (with first-fit algorithm by default).
269− * Can not be used in NMI handler on architectures without
270− * NMI-safe cmpxchg implementation.
271− */
272−unsigned long gen_pool_alloc(struct gen_pool *pool, size_t size)
273−{
274− return gen_pool_alloc_algo(pool, size, pool->algo, pool->data);
275−}
276−EXPORT_SYMBOL(gen_pool_alloc);
277−
278−/**
279− * gen_pool_alloc_algo - allocate special memory from the pool
265+ * gen_pool_alloc_algo_owner - allocate special memory from the pool
280266 * @pool: pool to allocate from
281267 * @size: number of bytes to allocate from the pool
282268 * @algo: algorithm passed from caller
283269 * @data: data passed to algorithm
270+ * @owner: optionally retrieve the chunk owner
284271 *
285272 * Allocate the requested number of bytes from the specified pool.
286273 * Uses the pool allocation function (with first-fit algorithm by default).
287274 * Can not be used in NMI handler on architectures without
288275 * NMI-safe cmpxchg implementation.
289276 */
290−unsigned long gen_pool_alloc_algo(struct gen_pool *pool, size_t size,
291− genpool_algo_t algo, void *data)
277+unsigned long gen_pool_alloc_algo_owner(struct gen_pool *pool, size_t size,
278+ genpool_algo_t algo, void *data, void **owner)
292279 {
293280 struct gen_pool_chunk *chunk;
294281 unsigned long addr = 0;
@@ -299,6 +286,9 @@ unsigned long gen_pool_alloc_algo(struct gen_pool *pool, size_t size, · 4 unmodified lines
299286 BUG_ON(in_nmi());
300287 #endif
301288
289+ if (owner)
290+ *owner = NULL;
291+
302292 if (size == 0)
303293 return 0;
304294
@@ -326,12 +316,14 @@ retry: · 21 unmodified lines
326316 addr = chunk->start_addr + ((unsigned long)start_bit << order);
327317 size = nbits << order;
328318 atomic_long_sub(size, &chunk->avail);
319+ if (owner)
320+ *owner = chunk->owner;
329321 break;
330322 }
331323 rcu_read_unlock();
332324 return addr;
333325 }
334−EXPORT_SYMBOL(gen_pool_alloc_algo);
326+EXPORT_SYMBOL(gen_pool_alloc_algo_owner);
335327
336328 /**
337329 * gen_pool_dma_alloc - allocate special memory from the pool for DMA usage
@@ -367,12 +359,14 @@ EXPORT_SYMBOL(gen_pool_dma_alloc); · 29 unmodified lines
367359 * @pool: pool to free to
368360 * @addr: starting address of memory to free back to pool
369361 * @size: size in bytes of memory to free
362+ * @owner: private data stashed at gen_pool_add() time
370363 *
371364 * Free previously allocated special memory back to the specified
372365 * pool. Can not be used in NMI handler on architectures without
373366 * NMI-safe cmpxchg implementation.
374367 */
375−void gen_pool_free(struct gen_pool *pool, unsigned long addr, size_t size)
368+void gen_pool_free_owner(struct gen_pool *pool, unsigned long addr, size_t size,
369+ void **owner)
376370 {
377371 struct gen_pool_chunk *chunk;
378372 int order = pool->min_alloc_order;
@@ -382,6 +376,9 @@ void gen_pool_free(struct gen_pool *pool, unsigned long addr, size_t size) · 3 unmodified lines
382376 BUG_ON(in_nmi());
383377 #endif
384378
379+ if (owner)
380+ *owner = NULL;
381+
385382 nbits = (size + (1UL << order) - 1) >> order;
386383 rcu_read_lock();
387384 list_for_each_entry_rcu(chunk, &pool->chunks, next_chunk) {
@@ -392,6 +389,8 @@ void gen_pool_free(struct gen_pool *pool, unsigned long addr, size_t size) · 4 unmodified lines
392389 BUG_ON(remain);
393390 size = nbits << order;
394391 atomic_long_add(size, &chunk->avail);
392+ if (owner)
393+ *owner = chunk->owner;
395394 rcu_read_unlock();
396395 return;
397396 }
@@ -399,7 +398,7 @@ void gen_pool_free(struct gen_pool *pool, unsigned long addr, size_t size) · 1 unmodified line
399398 rcu_read_unlock();
400399 BUG();
401400 }
402−EXPORT_SYMBOL(gen_pool_free);
401+EXPORT_SYMBOL(gen_pool_free_owner);
403402
404403 /**
405404 * gen_pool_for_each_chunk - call func for every chunk of generic memory pool
mm/hmm.c+3−11
@@ -1354,9 +1354,8 @@ static void hmm_devmem_ref_release(struct percpu_ref *ref) · 1353 unmodified lines
13541354 complete(&devmem->completion);
13551355 }
13561356
1357−static void hmm_devmem_ref_exit(void *data)
1357+static void hmm_devmem_ref_exit(struct percpu_ref *ref)
13581358 {
1359− struct percpu_ref *ref = data;
13601359 struct hmm_devmem *devmem;
13611360
13621361 devmem = container_of(ref, struct hmm_devmem, ref);
@@ -1433,10 +1432,6 @@ struct hmm_devmem *hmm_devmem_add(const struct hmm_devmem_ops *ops, · 70 unmodified lines
14331432 if (ret)
14341433 return ERR_PTR(ret);
14351434
1436− ret = devm_add_action_or_reset(device, hmm_devmem_ref_exit, &devmem->ref);
1437− if (ret)
1438− return ERR_PTR(ret);
1439−
14401435 size = ALIGN(size, PA_SECTION_SIZE);
14411436 addr = min((unsigned long)iomem_resource.end,
14421437 (1UL << MAX_PHYSMEM_BITS) - 1);
@@ -1475,6 +1470,7 @@ struct hmm_devmem *hmm_devmem_add(const struct hmm_devmem_ops *ops, · 32 unmodified lines
14751470 devmem->pagemap.ref = &devmem->ref;
14761471 devmem->pagemap.data = devmem;
14771472 devmem->pagemap.kill = hmm_devmem_ref_kill;
1473+ devmem->pagemap.cleanup = hmm_devmem_ref_exit;
14781474
14791475 result = devm_memremap_pages(devmem->device, &devmem->pagemap);
14801476 if (IS_ERR(result))
@@ -1512,11 +1508,6 @@ struct hmm_devmem *hmm_devmem_add_resource(const struct hmm_devmem_ops *ops, · 31 unmodified lines
15121508 if (ret)
15131509 return ERR_PTR(ret);
15141510
1515− ret = devm_add_action_or_reset(device, hmm_devmem_ref_exit,
1516− &devmem->ref);
1517− if (ret)
1518− return ERR_PTR(ret);
1519−
15201511 devmem->pfn_first = devmem->resource->start >> PAGE_SHIFT;
15211512 devmem->pfn_last = devmem->pfn_first +
15221513 (resource_size(devmem->resource) >> PAGE_SHIFT);
@@ -1529,6 +1520,7 @@ struct hmm_devmem *hmm_devmem_add_resource(const struct hmm_devmem_ops *ops, · 6 unmodified lines
15291520 devmem->pagemap.ref = &devmem->ref;
15301521 devmem->pagemap.data = devmem;
15311522 devmem->pagemap.kill = hmm_devmem_ref_kill;
1523+ devmem->pagemap.cleanup = hmm_devmem_ref_exit;
15321524
15331525 result = devm_memremap_pages(devmem->device, &devmem->pagemap);
15341526 if (IS_ERR(result))
mm/khugepaged.c+3−0
@@ -1004,6 +1004,9 @@ static void collapse_huge_page(struct mm_struct *mm, · 1003 unmodified lines
10041004 * handled by the anon_vma lock + PG_lock.
10051005 */
10061006 down_write(&mm->mmap_sem);
1007+ result = SCAN_ANY_PROCESS;
1008+ if (!mmget_still_valid(mm))
1009+ goto out;
10071010 result = hugepage_vma_revalidate(mm, address, &vma);
10081011 if (result)
10091012 goto out;
mm/list_lru.c+1−1
@@ -354,7 +354,7 @@ static int __memcg_init_list_lru_node(struct list_lru_memcg *memcg_lrus, · 353 unmodified lines
354354 }
355355 return 0;
356356 fail:
357− __memcg_destroy_list_lru_node(memcg_lrus, begin, i - 1);
357+ __memcg_destroy_list_lru_node(memcg_lrus, begin, i);
358358 return -ENOMEM;
359359 }
360360
mm/memcontrol.c+28−13
@@ -691,11 +691,12 @@ void __mod_memcg_state(struct mem_cgroup *memcg, int idx, int val) · 690 unmodified lines
691691 if (mem_cgroup_disabled())
692692 return;
693693
694+ __this_cpu_add(memcg->vmstats_local->stat[idx], val);
695+
694696 x = val + __this_cpu_read(memcg->vmstats_percpu->stat[idx]);
695697 if (unlikely(abs(x) > MEMCG_CHARGE_BATCH)) {
696698 struct mem_cgroup *mi;
697699
698− atomic_long_add(x, &memcg->vmstats_local[idx]);
699700 for (mi = memcg; mi; mi = parent_mem_cgroup(mi))
700701 atomic_long_add(x, &mi->vmstats[idx]);
701702 x = 0;
@@ -745,11 +746,12 @@ void __mod_lruvec_state(struct lruvec *lruvec, enum node_stat_item idx, · 43 unmodified lines
745746 __mod_memcg_state(memcg, idx, val);
746747
747748 /* Update lruvec */
749+ __this_cpu_add(pn->lruvec_stat_local->count[idx], val);
750+
748751 x = val + __this_cpu_read(pn->lruvec_stat_cpu->count[idx]);
749752 if (unlikely(abs(x) > MEMCG_CHARGE_BATCH)) {
750753 struct mem_cgroup_per_node *pi;
751754
752− atomic_long_add(x, &pn->lruvec_stat_local[idx]);
753755 for (pi = pn; pi; pi = parent_nodeinfo(pi, pgdat->node_id))
754756 atomic_long_add(x, &pi->lruvec_stat[idx]);
755757 x = 0;
@@ -771,11 +773,12 @@ void __count_memcg_events(struct mem_cgroup *memcg, enum vm_event_item idx, · 15 unmodified lines
771773 if (mem_cgroup_disabled())
772774 return;
773775
776+ __this_cpu_add(memcg->vmstats_local->events[idx], count);
777+
774778 x = count + __this_cpu_read(memcg->vmstats_percpu->events[idx]);
775779 if (unlikely(x > MEMCG_CHARGE_BATCH)) {
776780 struct mem_cgroup *mi;
777781
778− atomic_long_add(x, &memcg->vmevents_local[idx]);
779782 for (mi = memcg; mi; mi = parent_mem_cgroup(mi))
780783 atomic_long_add(x, &mi->vmevents[idx]);
781784 x = 0;
@@ -790,7 +793,12 @@ static unsigned long memcg_events(struct mem_cgroup *memcg, int event) · 8 unmodified lines
790793
791794 static unsigned long memcg_events_local(struct mem_cgroup *memcg, int event)
792795 {
793− return atomic_long_read(&memcg->vmevents_local[event]);
796+ long x = 0;
797+ int cpu;
798+
799+ for_each_possible_cpu(cpu)
800+ x += per_cpu(memcg->vmstats_local->events[event], cpu);
801+ return x;
794802 }
795803
796804 static void mem_cgroup_charge_statistics(struct mem_cgroup *memcg,
@@ -2191,11 +2199,9 @@ static int memcg_hotplug_cpu_dead(unsigned int cpu) · 1394 unmodified lines
21912199 long x;
21922200
21932201 x = this_cpu_xchg(memcg->vmstats_percpu->stat[i], 0);
2194− if (x) {
2195− atomic_long_add(x, &memcg->vmstats_local[i]);
2202+ if (x)
21962203 for (mi = memcg; mi; mi = parent_mem_cgroup(mi))
21972204 atomic_long_add(x, &memcg->vmstats[i]);
2198− }
21992205
22002206 if (i >= NR_VM_NODE_STAT_ITEMS)
22012207 continue;
@@ -2205,12 +2211,10 @@ static int memcg_hotplug_cpu_dead(unsigned int cpu) · 3 unmodified lines
22052211
22062212 pn = mem_cgroup_nodeinfo(memcg, nid);
22072213 x = this_cpu_xchg(pn->lruvec_stat_cpu->count[i], 0);
2208− if (x) {
2209− atomic_long_add(x, &pn->lruvec_stat_local[i]);
2214+ if (x)
22102215 do {
22112216 atomic_long_add(x, &pn->lruvec_stat[i]);
22122217 } while ((pn = parent_nodeinfo(pn, nid)));
2213− }
22142218 }
22152219 }
22162220
@@ -2218,11 +2222,9 @@ static int memcg_hotplug_cpu_dead(unsigned int cpu) · 1 unmodified line
22182222 long x;
22192223
22202224 x = this_cpu_xchg(memcg->vmstats_percpu->events[i], 0);
2221− if (x) {
2222− atomic_long_add(x, &memcg->vmevents_local[i]);
2225+ if (x)
22232226 for (mi = memcg; mi; mi = parent_mem_cgroup(mi))
22242227 atomic_long_add(x, &memcg->vmevents[i]);
2225− }
22262228 }
22272229 }
22282230
@@ -4483,8 +4485,15 @@ static int alloc_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node) · 2254 unmodified lines
44834485 if (!pn)
44844486 return 1;
44854487
4488+ pn->lruvec_stat_local = alloc_percpu(struct lruvec_stat);
4489+ if (!pn->lruvec_stat_local) {
4490+ kfree(pn);
4491+ return 1;
4492+ }
4493+
44864494 pn->lruvec_stat_cpu = alloc_percpu(struct lruvec_stat);
44874495 if (!pn->lruvec_stat_cpu) {
4496+ free_percpu(pn->lruvec_stat_local);
44884497 kfree(pn);
44894498 return 1;
44904499 }
@@ -4506,6 +4515,7 @@ static void free_mem_cgroup_per_node_info(struct mem_cgroup *memcg, int node) · 15 unmodified lines
45064515 return;
45074516
45084517 free_percpu(pn->lruvec_stat_cpu);
4518+ free_percpu(pn->lruvec_stat_local);
45094519 kfree(pn);
45104520 }
45114521
@@ -4516,6 +4526,7 @@ static void __mem_cgroup_free(struct mem_cgroup *memcg) · 4 unmodified lines
45164526 for_each_node(node)
45174527 free_mem_cgroup_per_node_info(memcg, node);
45184528 free_percpu(memcg->vmstats_percpu);
4529+ free_percpu(memcg->vmstats_local);
45194530 kfree(memcg);
45204531 }
45214532
@@ -4544,6 +4555,10 @@ static struct mem_cgroup *mem_cgroup_alloc(void) · 22 unmodified lines
45444555 if (memcg->id.id < 0)
45454556 goto fail;
45464557
4558+ memcg->vmstats_local = alloc_percpu(struct memcg_vmstats_percpu);
4559+ if (!memcg->vmstats_local)
4560+ goto fail;
4561+
45474562 memcg->vmstats_percpu = alloc_percpu(struct memcg_vmstats_percpu);
45484563 if (!memcg->vmstats_percpu)
45494564 goto fail;
mm/mlock.c+4−3
@@ -636,11 +636,11 @@ static int apply_vma_lock_flags(unsigned long start, size_t len, · 635 unmodified lines
636636 * is also counted.
637637 * Return value: previously mlocked page counts
638638 */
639−static int count_mm_mlocked_page_nr(struct mm_struct *mm,
639+static unsigned long count_mm_mlocked_page_nr(struct mm_struct *mm,
640640 unsigned long start, size_t len)
641641 {
642642 struct vm_area_struct *vma;
643− int count = 0;
643+ unsigned long count = 0;
644644
645645 if (mm == NULL)
646646 mm = current->mm;
@@ -797,7 +797,8 @@ SYSCALL_DEFINE1(mlockall, int, flags) · 150 unmodified lines
797797 unsigned long lock_limit;
798798 int ret;
799799
800− if (!flags || (flags & ~(MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT)))
800+ if (!flags || (flags & ~(MCL_CURRENT | MCL_FUTURE | MCL_ONFAULT)) ||
801+ flags == MCL_ONFAULT)
801802 return -EINVAL;
802803
803804 if (!can_do_mlock())
mm/mmu_gather.c+19−5
@@ -245,14 +245,28 @@ void tlb_finish_mmu(struct mmu_gather *tlb, · 244 unmodified lines
245245 {
246246 /*
247247 * If there are parallel threads are doing PTE changes on same range
248− * under non-exclusive lock(e.g., mmap_sem read-side) but defer TLB
249− * flush by batching, a thread has stable TLB entry can fail to flush
250− * the TLB by observing pte_none|!pte_dirty, for example so flush TLB
251− * forcefully if we detect parallel PTE batching threads.
248+ * under non-exclusive lock (e.g., mmap_sem read-side) but defer TLB
249+ * flush by batching, one thread may end up seeing inconsistent PTEs
250+ * and result in having stale TLB entries. So flush TLB forcefully
251+ * if we detect parallel PTE batching threads.
252+ *
253+ * However, some syscalls, e.g. munmap(), may free page tables, this
254+ * needs force flush everything in the given range. Otherwise this
255+ * may result in having stale TLB entries for some architectures,
256+ * e.g. aarch64, that could specify flush what level TLB.
252257 */
253258 if (mm_tlb_flush_nested(tlb->mm)) {
259+ /*
260+ * The aarch64 yields better performance with fullmm by
261+ * avoiding multiple CPUs spamming TLBI messages at the
262+ * same time.
263+ *
264+ * On x86 non-fullmm doesn't yield significant difference
265+ * against fullmm.
266+ */
267+ tlb->fullmm = 1;
254268 __tlb_reset_range(tlb);
255− __tlb_adjust_range(tlb, start, end - start);
269+ tlb->freed_tables = 1;
256270 }
257271
258272 tlb_flush_mmu(tlb);
mm/vmscan.c+3−3
@@ -1505,7 +1505,7 @@ unsigned long reclaim_clean_pages_from_list(struct zone *zone, · 1504 unmodified lines
15051505
15061506 list_for_each_entry_safe(page, next, page_list, lru) {
15071507 if (page_is_file_cache(page) && !PageDirty(page) &&
1508− !__PageMovable(page)) {
1508+ !__PageMovable(page) && !PageUnevictable(page)) {
15091509 ClearPageActive(page);
15101510 list_move(&page->lru, &clean_pages);
15111511 }
@@ -1953,8 +1953,8 @@ shrink_inactive_list(unsigned long nr_to_scan, struct lruvec *lruvec, · 441 unmodified lines
19531953 if (global_reclaim(sc))
19541954 __count_vm_events(item, nr_reclaimed);
19551955 __count_memcg_events(lruvec_memcg(lruvec), item, nr_reclaimed);
1956− reclaim_stat->recent_rotated[0] = stat.nr_activate[0];
1957− reclaim_stat->recent_rotated[1] = stat.nr_activate[1];
1956+ reclaim_stat->recent_rotated[0] += stat.nr_activate[0];
1957+ reclaim_stat->recent_rotated[1] += stat.nr_activate[1];
19581958
19591959 move_pages_to_lru(lruvec, &page_list);
19601960
scripts/decode_stacktrace.sh+1−1
@@ -73,7 +73,7 @@ parse_symbol() { · 72 unmodified lines
7373 if [[ "${cache[$module,$address]+isset}" == "isset" ]]; then
7474 local code=${cache[$module,$address]}
7575 else
76− local code=$(addr2line -i -e "$objfile" "$address")
76+ local code=$(${CROSS_COMPILE}addr2line -i -e "$objfile" "$address")
7777 cache[$module,$address]=$code
7878 fi
7979
tools/testing/nvdimm/test/iomap.c+2−0
@@ -100,7 +100,9 @@ static void nfit_test_kill(void *_pgmap) · 99 unmodified lines
100100 {
101101 struct dev_pagemap *pgmap = _pgmap;
102102
103+ WARN_ON(!pgmap || !pgmap->ref || !pgmap->kill || !pgmap->cleanup);
103104 pgmap->kill(pgmap->ref);
105+ pgmap->cleanup(pgmap->ref);
104106 }
105107
106108 void *__wrap_devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap)