2 * Copyright IBM Corp. 2007, 2011
3 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
6 #include <linux/sched.h>
7 #include <linux/kernel.h>
8 #include <linux/errno.h>
11 #include <linux/swap.h>
12 #include <linux/smp.h>
13 #include <linux/highmem.h>
14 #include <linux/pagemap.h>
15 #include <linux/spinlock.h>
16 #include <linux/module.h>
17 #include <linux/quicklist.h>
18 #include <linux/rcupdate.h>
19 #include <linux/slab.h>
21 #include <asm/pgtable.h>
22 #include <asm/pgalloc.h>
24 #include <asm/tlbflush.h>
25 #include <asm/mmu_context.h>
29 #define FRAG_MASK 0x0f
32 #define FRAG_MASK 0x03
36 unsigned long *crst_table_alloc(struct mm_struct *mm)
38 struct page *page = alloc_pages(GFP_KERNEL, ALLOC_ORDER);
42 return (unsigned long *) page_to_phys(page);
45 void crst_table_free(struct mm_struct *mm, unsigned long *table)
47 free_pages((unsigned long) table, ALLOC_ORDER);
51 int crst_table_upgrade(struct mm_struct *mm, unsigned long limit)
53 unsigned long *table, *pgd;
56 BUG_ON(limit > (1UL << 53));
58 table = crst_table_alloc(mm);
61 spin_lock_bh(&mm->page_table_lock);
62 if (mm->context.asce_limit < limit) {
63 pgd = (unsigned long *) mm->pgd;
64 if (mm->context.asce_limit <= (1UL << 31)) {
65 entry = _REGION3_ENTRY_EMPTY;
66 mm->context.asce_limit = 1UL << 42;
67 mm->context.asce_bits = _ASCE_TABLE_LENGTH |
71 entry = _REGION2_ENTRY_EMPTY;
72 mm->context.asce_limit = 1UL << 53;
73 mm->context.asce_bits = _ASCE_TABLE_LENGTH |
77 crst_table_init(table, entry);
78 pgd_populate(mm, (pgd_t *) table, (pud_t *) pgd);
79 mm->pgd = (pgd_t *) table;
80 mm->task_size = mm->context.asce_limit;
83 spin_unlock_bh(&mm->page_table_lock);
85 crst_table_free(mm, table);
86 if (mm->context.asce_limit < limit)
88 update_mm(mm, current);
92 void crst_table_downgrade(struct mm_struct *mm, unsigned long limit)
96 if (mm->context.asce_limit <= limit)
99 while (mm->context.asce_limit > limit) {
101 switch (pgd_val(*pgd) & _REGION_ENTRY_TYPE_MASK) {
102 case _REGION_ENTRY_TYPE_R2:
103 mm->context.asce_limit = 1UL << 42;
104 mm->context.asce_bits = _ASCE_TABLE_LENGTH |
108 case _REGION_ENTRY_TYPE_R3:
109 mm->context.asce_limit = 1UL << 31;
110 mm->context.asce_bits = _ASCE_TABLE_LENGTH |
117 mm->pgd = (pgd_t *) (pgd_val(*pgd) & _REGION_ENTRY_ORIGIN);
118 mm->task_size = mm->context.asce_limit;
119 crst_table_free(mm, (unsigned long *) pgd);
121 update_mm(mm, current);
128 * gmap_alloc - allocate a guest address space
129 * @mm: pointer to the parent mm_struct
131 * Returns a guest address space structure.
133 struct gmap *gmap_alloc(struct mm_struct *mm)
137 unsigned long *table;
139 gmap = kzalloc(sizeof(struct gmap), GFP_KERNEL);
142 INIT_LIST_HEAD(&gmap->crst_list);
144 page = alloc_pages(GFP_KERNEL, ALLOC_ORDER);
147 list_add(&page->lru, &gmap->crst_list);
148 table = (unsigned long *) page_to_phys(page);
149 crst_table_init(table, _REGION1_ENTRY_EMPTY);
151 gmap->asce = _ASCE_TYPE_REGION1 | _ASCE_TABLE_LENGTH |
152 _ASCE_USER_BITS | __pa(table);
153 list_add(&gmap->list, &mm->context.gmap_list);
161 EXPORT_SYMBOL_GPL(gmap_alloc);
163 static int gmap_unlink_segment(struct gmap *gmap, unsigned long *table)
165 struct gmap_pgtable *mp;
166 struct gmap_rmap *rmap;
169 if (*table & _SEGMENT_ENTRY_INV)
171 page = pfn_to_page(*table >> PAGE_SHIFT);
172 mp = (struct gmap_pgtable *) page->index;
173 list_for_each_entry(rmap, &mp->mapper, list) {
174 if (rmap->entry != table)
176 list_del(&rmap->list);
180 *table = _SEGMENT_ENTRY_INV | _SEGMENT_ENTRY_RO | mp->vmaddr;
184 static void gmap_flush_tlb(struct gmap *gmap)
186 if (MACHINE_HAS_IDTE)
187 __tlb_flush_idte((unsigned long) gmap->table |
190 __tlb_flush_global();
194 * gmap_free - free a guest address space
195 * @gmap: pointer to the guest address space structure
197 void gmap_free(struct gmap *gmap)
199 struct page *page, *next;
200 unsigned long *table;
205 if (MACHINE_HAS_IDTE)
206 __tlb_flush_idte((unsigned long) gmap->table |
209 __tlb_flush_global();
211 /* Free all segment & region tables. */
212 down_read(&gmap->mm->mmap_sem);
213 spin_lock(&gmap->mm->page_table_lock);
214 list_for_each_entry_safe(page, next, &gmap->crst_list, lru) {
215 table = (unsigned long *) page_to_phys(page);
216 if ((*table & _REGION_ENTRY_TYPE_MASK) == 0)
217 /* Remove gmap rmap structures for segment table. */
218 for (i = 0; i < PTRS_PER_PMD; i++, table++)
219 gmap_unlink_segment(gmap, table);
220 __free_pages(page, ALLOC_ORDER);
222 spin_unlock(&gmap->mm->page_table_lock);
223 up_read(&gmap->mm->mmap_sem);
224 list_del(&gmap->list);
227 EXPORT_SYMBOL_GPL(gmap_free);
230 * gmap_enable - switch primary space to the guest address space
231 * @gmap: pointer to the guest address space structure
233 void gmap_enable(struct gmap *gmap)
235 S390_lowcore.gmap = (unsigned long) gmap;
237 EXPORT_SYMBOL_GPL(gmap_enable);
240 * gmap_disable - switch back to the standard primary address space
241 * @gmap: pointer to the guest address space structure
243 void gmap_disable(struct gmap *gmap)
245 S390_lowcore.gmap = 0UL;
247 EXPORT_SYMBOL_GPL(gmap_disable);
250 * gmap_alloc_table is assumed to be called with mmap_sem held
252 static int gmap_alloc_table(struct gmap *gmap,
253 unsigned long *table, unsigned long init)
258 /* since we dont free the gmap table until gmap_free we can unlock */
259 spin_unlock(&gmap->mm->page_table_lock);
260 page = alloc_pages(GFP_KERNEL, ALLOC_ORDER);
261 spin_lock(&gmap->mm->page_table_lock);
264 new = (unsigned long *) page_to_phys(page);
265 crst_table_init(new, init);
266 if (*table & _REGION_ENTRY_INV) {
267 list_add(&page->lru, &gmap->crst_list);
268 *table = (unsigned long) new | _REGION_ENTRY_LENGTH |
269 (*table & _REGION_ENTRY_TYPE_MASK);
271 __free_pages(page, ALLOC_ORDER);
276 * gmap_unmap_segment - unmap segment from the guest address space
277 * @gmap: pointer to the guest address space structure
278 * @addr: address in the guest address space
279 * @len: length of the memory area to unmap
281 * Returns 0 if the unmap succeded, -EINVAL if not.
283 int gmap_unmap_segment(struct gmap *gmap, unsigned long to, unsigned long len)
285 unsigned long *table;
289 if ((to | len) & (PMD_SIZE - 1))
291 if (len == 0 || to + len < to)
295 down_read(&gmap->mm->mmap_sem);
296 spin_lock(&gmap->mm->page_table_lock);
297 for (off = 0; off < len; off += PMD_SIZE) {
298 /* Walk the guest addr space page table */
299 table = gmap->table + (((to + off) >> 53) & 0x7ff);
300 if (*table & _REGION_ENTRY_INV)
302 table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
303 table = table + (((to + off) >> 42) & 0x7ff);
304 if (*table & _REGION_ENTRY_INV)
306 table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
307 table = table + (((to + off) >> 31) & 0x7ff);
308 if (*table & _REGION_ENTRY_INV)
310 table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
311 table = table + (((to + off) >> 20) & 0x7ff);
313 /* Clear segment table entry in guest address space. */
314 flush |= gmap_unlink_segment(gmap, table);
315 *table = _SEGMENT_ENTRY_INV;
318 spin_unlock(&gmap->mm->page_table_lock);
319 up_read(&gmap->mm->mmap_sem);
321 gmap_flush_tlb(gmap);
324 EXPORT_SYMBOL_GPL(gmap_unmap_segment);
327 * gmap_mmap_segment - map a segment to the guest address space
328 * @gmap: pointer to the guest address space structure
329 * @from: source address in the parent address space
330 * @to: target address in the guest address space
332 * Returns 0 if the mmap succeded, -EINVAL or -ENOMEM if not.
334 int gmap_map_segment(struct gmap *gmap, unsigned long from,
335 unsigned long to, unsigned long len)
337 unsigned long *table;
341 if ((from | to | len) & (PMD_SIZE - 1))
343 if (len == 0 || from + len > PGDIR_SIZE ||
344 from + len < from || to + len < to)
348 down_read(&gmap->mm->mmap_sem);
349 spin_lock(&gmap->mm->page_table_lock);
350 for (off = 0; off < len; off += PMD_SIZE) {
351 /* Walk the gmap address space page table */
352 table = gmap->table + (((to + off) >> 53) & 0x7ff);
353 if ((*table & _REGION_ENTRY_INV) &&
354 gmap_alloc_table(gmap, table, _REGION2_ENTRY_EMPTY))
356 table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
357 table = table + (((to + off) >> 42) & 0x7ff);
358 if ((*table & _REGION_ENTRY_INV) &&
359 gmap_alloc_table(gmap, table, _REGION3_ENTRY_EMPTY))
361 table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
362 table = table + (((to + off) >> 31) & 0x7ff);
363 if ((*table & _REGION_ENTRY_INV) &&
364 gmap_alloc_table(gmap, table, _SEGMENT_ENTRY_EMPTY))
366 table = (unsigned long *) (*table & _REGION_ENTRY_ORIGIN);
367 table = table + (((to + off) >> 20) & 0x7ff);
369 /* Store 'from' address in an invalid segment table entry. */
370 flush |= gmap_unlink_segment(gmap, table);
371 *table = _SEGMENT_ENTRY_INV | _SEGMENT_ENTRY_RO | (from + off);
373 spin_unlock(&gmap->mm->page_table_lock);
374 up_read(&gmap->mm->mmap_sem);
376 gmap_flush_tlb(gmap);
380 spin_unlock(&gmap->mm->page_table_lock);
381 up_read(&gmap->mm->mmap_sem);
382 gmap_unmap_segment(gmap, to, len);
385 EXPORT_SYMBOL_GPL(gmap_map_segment);
388 * this function is assumed to be called with mmap_sem held
390 unsigned long __gmap_fault(unsigned long address, struct gmap *gmap)
392 unsigned long *table, vmaddr, segment;
393 struct mm_struct *mm;
394 struct gmap_pgtable *mp;
395 struct gmap_rmap *rmap;
396 struct vm_area_struct *vma;
402 current->thread.gmap_addr = address;
404 /* Walk the gmap address space page table */
405 table = gmap->table + ((address >> 53) & 0x7ff);
406 if (unlikely(*table & _REGION_ENTRY_INV))
408 table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
409 table = table + ((address >> 42) & 0x7ff);
410 if (unlikely(*table & _REGION_ENTRY_INV))
412 table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
413 table = table + ((address >> 31) & 0x7ff);
414 if (unlikely(*table & _REGION_ENTRY_INV))
416 table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
417 table = table + ((address >> 20) & 0x7ff);
419 /* Convert the gmap address to an mm address. */
421 if (likely(!(segment & _SEGMENT_ENTRY_INV))) {
422 page = pfn_to_page(segment >> PAGE_SHIFT);
423 mp = (struct gmap_pgtable *) page->index;
424 return mp->vmaddr | (address & ~PMD_MASK);
425 } else if (segment & _SEGMENT_ENTRY_RO) {
426 vmaddr = segment & _SEGMENT_ENTRY_ORIGIN;
427 vma = find_vma(mm, vmaddr);
428 if (!vma || vma->vm_start > vmaddr)
431 /* Walk the parent mm page table */
432 pgd = pgd_offset(mm, vmaddr);
433 pud = pud_alloc(mm, pgd, vmaddr);
436 pmd = pmd_alloc(mm, pud, vmaddr);
439 if (!pmd_present(*pmd) &&
440 __pte_alloc(mm, vma, pmd, vmaddr))
442 /* pmd now points to a valid segment table entry. */
443 rmap = kmalloc(sizeof(*rmap), GFP_KERNEL|__GFP_REPEAT);
446 /* Link gmap segment table entry location to page table. */
447 page = pmd_page(*pmd);
448 mp = (struct gmap_pgtable *) page->index;
450 spin_lock(&mm->page_table_lock);
451 list_add(&rmap->list, &mp->mapper);
452 spin_unlock(&mm->page_table_lock);
453 /* Set gmap segment table entry to page table. */
454 *table = pmd_val(*pmd) & PAGE_MASK;
455 return vmaddr | (address & ~PMD_MASK);
460 unsigned long gmap_fault(unsigned long address, struct gmap *gmap)
464 down_read(&gmap->mm->mmap_sem);
465 rc = __gmap_fault(address, gmap);
466 up_read(&gmap->mm->mmap_sem);
470 EXPORT_SYMBOL_GPL(gmap_fault);
472 void gmap_discard(unsigned long from, unsigned long to, struct gmap *gmap)
475 unsigned long *table, address, size;
476 struct vm_area_struct *vma;
477 struct gmap_pgtable *mp;
480 down_read(&gmap->mm->mmap_sem);
482 while (address < to) {
483 /* Walk the gmap address space page table */
484 table = gmap->table + ((address >> 53) & 0x7ff);
485 if (unlikely(*table & _REGION_ENTRY_INV)) {
486 address = (address + PMD_SIZE) & PMD_MASK;
489 table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
490 table = table + ((address >> 42) & 0x7ff);
491 if (unlikely(*table & _REGION_ENTRY_INV)) {
492 address = (address + PMD_SIZE) & PMD_MASK;
495 table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
496 table = table + ((address >> 31) & 0x7ff);
497 if (unlikely(*table & _REGION_ENTRY_INV)) {
498 address = (address + PMD_SIZE) & PMD_MASK;
501 table = (unsigned long *)(*table & _REGION_ENTRY_ORIGIN);
502 table = table + ((address >> 20) & 0x7ff);
503 if (unlikely(*table & _SEGMENT_ENTRY_INV)) {
504 address = (address + PMD_SIZE) & PMD_MASK;
507 page = pfn_to_page(*table >> PAGE_SHIFT);
508 mp = (struct gmap_pgtable *) page->index;
509 vma = find_vma(gmap->mm, mp->vmaddr);
510 size = min(to - address, PMD_SIZE - (address & ~PMD_MASK));
511 zap_page_range(vma, mp->vmaddr | (address & ~PMD_MASK),
513 address = (address + PMD_SIZE) & PMD_MASK;
515 up_read(&gmap->mm->mmap_sem);
517 EXPORT_SYMBOL_GPL(gmap_discard);
519 void gmap_unmap_notifier(struct mm_struct *mm, unsigned long *table)
521 struct gmap_rmap *rmap, *next;
522 struct gmap_pgtable *mp;
527 spin_lock(&mm->page_table_lock);
528 page = pfn_to_page(__pa(table) >> PAGE_SHIFT);
529 mp = (struct gmap_pgtable *) page->index;
530 list_for_each_entry_safe(rmap, next, &mp->mapper, list) {
532 _SEGMENT_ENTRY_INV | _SEGMENT_ENTRY_RO | mp->vmaddr;
533 list_del(&rmap->list);
537 spin_unlock(&mm->page_table_lock);
539 __tlb_flush_global();
542 static inline unsigned long *page_table_alloc_pgste(struct mm_struct *mm,
543 unsigned long vmaddr)
546 unsigned long *table;
547 struct gmap_pgtable *mp;
549 page = alloc_page(GFP_KERNEL|__GFP_REPEAT);
552 mp = kmalloc(sizeof(*mp), GFP_KERNEL|__GFP_REPEAT);
557 pgtable_page_ctor(page);
558 mp->vmaddr = vmaddr & PMD_MASK;
559 INIT_LIST_HEAD(&mp->mapper);
560 page->index = (unsigned long) mp;
561 atomic_set(&page->_mapcount, 3);
562 table = (unsigned long *) page_to_phys(page);
563 clear_table(table, _PAGE_TYPE_EMPTY, PAGE_SIZE/2);
564 clear_table(table + PTRS_PER_PTE, 0, PAGE_SIZE/2);
568 static inline void page_table_free_pgste(unsigned long *table)
571 struct gmap_pgtable *mp;
573 page = pfn_to_page(__pa(table) >> PAGE_SHIFT);
574 mp = (struct gmap_pgtable *) page->index;
575 BUG_ON(!list_empty(&mp->mapper));
576 pgtable_page_dtor(page);
577 atomic_set(&page->_mapcount, -1);
582 #else /* CONFIG_PGSTE */
584 static inline unsigned long *page_table_alloc_pgste(struct mm_struct *mm,
585 unsigned long vmaddr)
590 static inline void page_table_free_pgste(unsigned long *table)
594 static inline void gmap_unmap_notifier(struct mm_struct *mm,
595 unsigned long *table)
599 #endif /* CONFIG_PGSTE */
601 static inline unsigned int atomic_xor_bits(atomic_t *v, unsigned int bits)
603 unsigned int old, new;
606 old = atomic_read(v);
608 } while (atomic_cmpxchg(v, old, new) != old);
613 * page table entry allocation/free routines.
615 unsigned long *page_table_alloc(struct mm_struct *mm, unsigned long vmaddr)
618 unsigned long *table;
619 unsigned int mask, bit;
621 if (mm_has_pgste(mm))
622 return page_table_alloc_pgste(mm, vmaddr);
623 /* Allocate fragments of a 4K page as 1K/2K page table */
624 spin_lock_bh(&mm->context.list_lock);
626 if (!list_empty(&mm->context.pgtable_list)) {
627 page = list_first_entry(&mm->context.pgtable_list,
629 table = (unsigned long *) page_to_phys(page);
630 mask = atomic_read(&page->_mapcount);
631 mask = mask | (mask >> 4);
633 if ((mask & FRAG_MASK) == FRAG_MASK) {
634 spin_unlock_bh(&mm->context.list_lock);
635 page = alloc_page(GFP_KERNEL|__GFP_REPEAT);
638 pgtable_page_ctor(page);
639 atomic_set(&page->_mapcount, 1);
640 table = (unsigned long *) page_to_phys(page);
641 clear_table(table, _PAGE_TYPE_EMPTY, PAGE_SIZE);
642 spin_lock_bh(&mm->context.list_lock);
643 list_add(&page->lru, &mm->context.pgtable_list);
645 for (bit = 1; mask & bit; bit <<= 1)
646 table += PTRS_PER_PTE;
647 mask = atomic_xor_bits(&page->_mapcount, bit);
648 if ((mask & FRAG_MASK) == FRAG_MASK)
649 list_del(&page->lru);
651 spin_unlock_bh(&mm->context.list_lock);
655 void page_table_free(struct mm_struct *mm, unsigned long *table)
658 unsigned int bit, mask;
660 if (mm_has_pgste(mm)) {
661 gmap_unmap_notifier(mm, table);
662 return page_table_free_pgste(table);
664 /* Free 1K/2K page table fragment of a 4K page */
665 page = pfn_to_page(__pa(table) >> PAGE_SHIFT);
666 bit = 1 << ((__pa(table) & ~PAGE_MASK)/(PTRS_PER_PTE*sizeof(pte_t)));
667 spin_lock_bh(&mm->context.list_lock);
668 if ((atomic_read(&page->_mapcount) & FRAG_MASK) != FRAG_MASK)
669 list_del(&page->lru);
670 mask = atomic_xor_bits(&page->_mapcount, bit);
671 if (mask & FRAG_MASK)
672 list_add(&page->lru, &mm->context.pgtable_list);
673 spin_unlock_bh(&mm->context.list_lock);
675 pgtable_page_dtor(page);
676 atomic_set(&page->_mapcount, -1);
681 static void __page_table_free_rcu(void *table, unsigned bit)
685 if (bit == FRAG_MASK)
686 return page_table_free_pgste(table);
687 /* Free 1K/2K page table fragment of a 4K page */
688 page = pfn_to_page(__pa(table) >> PAGE_SHIFT);
689 if (atomic_xor_bits(&page->_mapcount, bit) == 0) {
690 pgtable_page_dtor(page);
691 atomic_set(&page->_mapcount, -1);
696 void page_table_free_rcu(struct mmu_gather *tlb, unsigned long *table)
698 struct mm_struct *mm;
700 unsigned int bit, mask;
703 if (mm_has_pgste(mm)) {
704 gmap_unmap_notifier(mm, table);
705 table = (unsigned long *) (__pa(table) | FRAG_MASK);
706 tlb_remove_table(tlb, table);
709 bit = 1 << ((__pa(table) & ~PAGE_MASK) / (PTRS_PER_PTE*sizeof(pte_t)));
710 page = pfn_to_page(__pa(table) >> PAGE_SHIFT);
711 spin_lock_bh(&mm->context.list_lock);
712 if ((atomic_read(&page->_mapcount) & FRAG_MASK) != FRAG_MASK)
713 list_del(&page->lru);
714 mask = atomic_xor_bits(&page->_mapcount, bit | (bit << 4));
715 if (mask & FRAG_MASK)
716 list_add_tail(&page->lru, &mm->context.pgtable_list);
717 spin_unlock_bh(&mm->context.list_lock);
718 table = (unsigned long *) (__pa(table) | (bit << 4));
719 tlb_remove_table(tlb, table);
722 void __tlb_remove_table(void *_table)
724 const unsigned long mask = (FRAG_MASK << 4) | FRAG_MASK;
725 void *table = (void *)((unsigned long) _table & ~mask);
726 unsigned type = (unsigned long) _table & mask;
729 __page_table_free_rcu(table, type);
731 free_pages((unsigned long) table, ALLOC_ORDER);
734 static void tlb_remove_table_smp_sync(void *arg)
736 /* Simply deliver the interrupt */
739 static void tlb_remove_table_one(void *table)
742 * This isn't an RCU grace period and hence the page-tables cannot be
743 * assumed to be actually RCU-freed.
745 * It is however sufficient for software page-table walkers that rely
746 * on IRQ disabling. See the comment near struct mmu_table_batch.
748 smp_call_function(tlb_remove_table_smp_sync, NULL, 1);
749 __tlb_remove_table(table);
752 static void tlb_remove_table_rcu(struct rcu_head *head)
754 struct mmu_table_batch *batch;
757 batch = container_of(head, struct mmu_table_batch, rcu);
759 for (i = 0; i < batch->nr; i++)
760 __tlb_remove_table(batch->tables[i]);
762 free_page((unsigned long)batch);
765 void tlb_table_flush(struct mmu_gather *tlb)
767 struct mmu_table_batch **batch = &tlb->batch;
770 __tlb_flush_mm(tlb->mm);
771 call_rcu_sched(&(*batch)->rcu, tlb_remove_table_rcu);
776 void tlb_remove_table(struct mmu_gather *tlb, void *table)
778 struct mmu_table_batch **batch = &tlb->batch;
780 if (*batch == NULL) {
781 *batch = (struct mmu_table_batch *)
782 __get_free_page(GFP_NOWAIT | __GFP_NOWARN);
783 if (*batch == NULL) {
784 __tlb_flush_mm(tlb->mm);
785 tlb_remove_table_one(table);
790 (*batch)->tables[(*batch)->nr++] = table;
791 if ((*batch)->nr == MAX_TABLE_BATCH)
792 tlb_table_flush(tlb);
796 * switch on pgstes for its userspace process (for kvm)
798 int s390_enable_sie(void)
800 struct task_struct *tsk = current;
801 struct mm_struct *mm, *old_mm;
803 /* Do we have switched amode? If no, we cannot do sie */
804 if (user_mode == HOME_SPACE_MODE)
807 /* Do we have pgstes? if yes, we are done */
808 if (mm_has_pgste(tsk->mm))
811 /* lets check if we are allowed to replace the mm */
813 if (!tsk->mm || atomic_read(&tsk->mm->mm_users) > 1 ||
815 !hlist_empty(&tsk->mm->ioctx_list) ||
817 tsk->mm != tsk->active_mm) {
823 /* we copy the mm and let dup_mm create the page tables with_pgstes */
824 tsk->mm->context.alloc_pgste = 1;
825 /* make sure that both mms have a correct rss state */
826 sync_mm_rss(tsk->mm);
828 tsk->mm->context.alloc_pgste = 0;
832 /* Now lets check again if something happened */
834 if (!tsk->mm || atomic_read(&tsk->mm->mm_users) > 1 ||
836 !hlist_empty(&tsk->mm->ioctx_list) ||
838 tsk->mm != tsk->active_mm) {
844 /* ok, we are alone. No ptrace, no threads, etc. */
846 tsk->mm = tsk->active_mm = mm;
849 atomic_inc(&mm->context.attach_count);
850 atomic_dec(&old_mm->context.attach_count);
851 cpumask_set_cpu(smp_processor_id(), mm_cpumask(mm));
857 EXPORT_SYMBOL_GPL(s390_enable_sie);
859 #if defined(CONFIG_DEBUG_PAGEALLOC) && defined(CONFIG_HIBERNATION)
860 bool kernel_page_present(struct page *page)
865 addr = page_to_phys(page);
870 : "=d" (cc), "+a" (addr) : : "cc");
873 #endif /* CONFIG_HIBERNATION && CONFIG_DEBUG_PAGEALLOC */