^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * High memory handling common code and variables.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * (C) 1999 Andrea Arcangeli, SuSE GmbH, andrea@suse.de
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Gerhard Wichert, Siemens AG, Gerhard.Wichert@pdb.siemens.de
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Redesigned the x86 32-bit VM architecture to deal with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * 64-bit physical space. With current x86 CPUs this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * means up to 64 Gigabytes physical RAM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * Rewrote high memory support to move the page cache into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * high memory. Implemented permanent (schedulable) kmaps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * based on Linus' idea.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Copyright (C) 1999 Ingo Molnar <mingo@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/swap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/bio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/mempool.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/highmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/kgdb.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <asm/tlbflush.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #if defined(CONFIG_HIGHMEM) || defined(CONFIG_X86_32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) DEFINE_PER_CPU(int, __kmap_atomic_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * Virtual_count is not a pure "count".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * 0 means that it is not mapped, and has not been mapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * since a TLB flush - it is usable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * 1 means that there are no users, but it has been mapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * since the last TLB flush - so we can't use it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * n means that there are (n-1) current users of it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #ifdef CONFIG_HIGHMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * Architecture with aliasing data cache may define the following family of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * helper functions in its asm/highmem.h to control cache color of virtual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * addresses where physical memory pages are mapped by kmap.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #ifndef get_pkmap_color
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * Determine color of virtual address where the page should be mapped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static inline unsigned int get_pkmap_color(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define get_pkmap_color get_pkmap_color
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * Get next index for mapping inside PKMAP region for page with given color.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static inline unsigned int get_next_pkmap_nr(unsigned int color)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static unsigned int last_pkmap_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) last_pkmap_nr = (last_pkmap_nr + 1) & LAST_PKMAP_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return last_pkmap_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * Determine if page index inside PKMAP region (pkmap_nr) of given color
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * has wrapped around PKMAP region end. When this happens an attempt to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * flush all unused PKMAP slots is made.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static inline int no_more_pkmaps(unsigned int pkmap_nr, unsigned int color)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return pkmap_nr == 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * Get the number of PKMAP entries of the given color. If no free slot is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * found after checking that many entries, kmap will sleep waiting for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * someone to call kunmap and free PKMAP slot.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static inline int get_pkmap_entries_count(unsigned int color)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) return LAST_PKMAP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * Get head of a wait queue for PKMAP entries of the given color.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * Wait queues for different mapping colors should be independent to avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * unnecessary wakeups caused by freeing of slots of other colors.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static inline wait_queue_head_t *get_pkmap_wait_queue_head(unsigned int color)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) static DECLARE_WAIT_QUEUE_HEAD(pkmap_map_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return &pkmap_map_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) atomic_long_t _totalhigh_pages __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) EXPORT_SYMBOL(_totalhigh_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) EXPORT_PER_CPU_SYMBOL(__kmap_atomic_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) unsigned int nr_free_highpages (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct zone *zone;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) unsigned int pages = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) for_each_populated_zone(zone) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (is_highmem(zone))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) pages += zone_page_state(zone, NR_FREE_PAGES);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static int pkmap_count[LAST_PKMAP];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static __cacheline_aligned_in_smp DEFINE_SPINLOCK(kmap_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) pte_t * pkmap_page_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * Most architectures have no use for kmap_high_get(), so let's abstract
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * the disabling of IRQ out of the locking in that case to save on a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * potential useless overhead.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #ifdef ARCH_NEEDS_KMAP_HIGH_GET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) #define lock_kmap() spin_lock_irq(&kmap_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) #define unlock_kmap() spin_unlock_irq(&kmap_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) #define lock_kmap_any(flags) spin_lock_irqsave(&kmap_lock, flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #define unlock_kmap_any(flags) spin_unlock_irqrestore(&kmap_lock, flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #define lock_kmap() spin_lock(&kmap_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) #define unlock_kmap() spin_unlock(&kmap_lock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #define lock_kmap_any(flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) do { spin_lock(&kmap_lock); (void)(flags); } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) #define unlock_kmap_any(flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) do { spin_unlock(&kmap_lock); (void)(flags); } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) struct page *kmap_to_page(void *vaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) unsigned long addr = (unsigned long)vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) if (addr >= PKMAP_ADDR(0) && addr < PKMAP_ADDR(LAST_PKMAP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) int i = PKMAP_NR(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) return pte_page(pkmap_page_table[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) return virt_to_page(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) EXPORT_SYMBOL(kmap_to_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) static void flush_all_zero_pkmaps(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) int need_flush = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) flush_cache_kmaps();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) for (i = 0; i < LAST_PKMAP; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * zero means we don't have anything to do,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * >1 means that it is still in use. Only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * a count of 1 means that it is free but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * needs to be unmapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (pkmap_count[i] != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) pkmap_count[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) /* sanity check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) BUG_ON(pte_none(pkmap_page_table[i]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * Don't need an atomic fetch-and-clear op here;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) * no-one has the page mapped, and cannot get at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) * its virtual address (and hence PTE) without first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * getting the kmap_lock (which is held here).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * So no dangers, even with speculative execution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) page = pte_page(pkmap_page_table[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) set_page_address(page, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) need_flush = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (need_flush)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) flush_tlb_kernel_range(PKMAP_ADDR(0), PKMAP_ADDR(LAST_PKMAP));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * kmap_flush_unused - flush all unused kmap mappings in order to remove stray mappings
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) void kmap_flush_unused(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) lock_kmap();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) flush_all_zero_pkmaps();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) unlock_kmap();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static inline unsigned long map_new_virtual(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) unsigned long vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) unsigned int last_pkmap_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) unsigned int color = get_pkmap_color(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) start:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) count = get_pkmap_entries_count(color);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /* Find an empty entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) last_pkmap_nr = get_next_pkmap_nr(color);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (no_more_pkmaps(last_pkmap_nr, color)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) flush_all_zero_pkmaps();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) count = get_pkmap_entries_count(color);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (!pkmap_count[last_pkmap_nr])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) break; /* Found a usable entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (--count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * Sleep for somebody else to unmap their entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) DECLARE_WAITQUEUE(wait, current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) wait_queue_head_t *pkmap_map_wait =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) get_pkmap_wait_queue_head(color);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) __set_current_state(TASK_UNINTERRUPTIBLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) add_wait_queue(pkmap_map_wait, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) unlock_kmap();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) schedule();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) remove_wait_queue(pkmap_map_wait, &wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) lock_kmap();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) /* Somebody else might have mapped it while we slept */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) if (page_address(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return (unsigned long)page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) /* Re-start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) goto start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) vaddr = PKMAP_ADDR(last_pkmap_nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) set_pte_at(&init_mm, vaddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) pkmap_count[last_pkmap_nr] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) set_page_address(page, (void *)vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * kmap_high - map a highmem page into memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * @page: &struct page to map
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * Returns the page's virtual memory address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * We cannot call this from interrupts, as it may block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) void *kmap_high(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) unsigned long vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * For highmem pages, we can't trust "virtual" until
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * after we have the lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) lock_kmap();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) vaddr = (unsigned long)page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (!vaddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) vaddr = map_new_virtual(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) pkmap_count[PKMAP_NR(vaddr)]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) BUG_ON(pkmap_count[PKMAP_NR(vaddr)] < 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) unlock_kmap();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return (void*) vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) EXPORT_SYMBOL(kmap_high);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) #ifdef ARCH_NEEDS_KMAP_HIGH_GET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * kmap_high_get - pin a highmem page into memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) * @page: &struct page to pin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) * Returns the page's current virtual memory address, or NULL if no mapping
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) * exists. If and only if a non null address is returned then a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) * matching call to kunmap_high() is necessary.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * This can be called from any context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) void *kmap_high_get(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) unsigned long vaddr, flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) lock_kmap_any(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) vaddr = (unsigned long)page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) if (vaddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) BUG_ON(pkmap_count[PKMAP_NR(vaddr)] < 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) pkmap_count[PKMAP_NR(vaddr)]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) unlock_kmap_any(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) return (void*) vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) * kunmap_high - unmap a highmem page into memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) * @page: &struct page to unmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) * If ARCH_NEEDS_KMAP_HIGH_GET is not defined then this may be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) * only from user context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) void kunmap_high(struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) unsigned long vaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) unsigned long nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) int need_wakeup;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) unsigned int color = get_pkmap_color(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) wait_queue_head_t *pkmap_map_wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) lock_kmap_any(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) vaddr = (unsigned long)page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) BUG_ON(!vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) nr = PKMAP_NR(vaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * A count must never go down to zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) * without a TLB flush!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) need_wakeup = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) switch (--pkmap_count[nr]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) * Avoid an unnecessary wake_up() function call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) * The common case is pkmap_count[] == 1, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) * no waiters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) * The tasks queued in the wait-queue are guarded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * by both the lock in the wait-queue-head and by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * the kmap_lock. As the kmap_lock is held here,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * no need for the wait-queue-head's lock. Simply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * test if the queue is empty.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) pkmap_map_wait = get_pkmap_wait_queue_head(color);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) need_wakeup = waitqueue_active(pkmap_map_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) unlock_kmap_any(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) /* do wake-up, if needed, race-free outside of the spin lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (need_wakeup)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) wake_up(pkmap_map_wait);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) EXPORT_SYMBOL(kunmap_high);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) #endif /* CONFIG_HIGHMEM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) #if defined(HASHED_PAGE_VIRTUAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) #define PA_HASH_ORDER 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) * Describes one page->virtual association
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) struct page_address_map {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) void *virtual;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) struct list_head list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) static struct page_address_map page_address_maps[LAST_PKMAP];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) * Hash table bucket
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) static struct page_address_slot {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) struct list_head lh; /* List of page_address_maps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) spinlock_t lock; /* Protect this bucket's list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) } ____cacheline_aligned_in_smp page_address_htable[1<<PA_HASH_ORDER];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) static struct page_address_slot *page_slot(const struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) return &page_address_htable[hash_ptr(page, PA_HASH_ORDER)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) * page_address - get the mapped virtual address of a page
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) * @page: &struct page to get the virtual address of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) * Returns the page's virtual address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) void *page_address(const struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) void *ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) struct page_address_slot *pas;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) if (!PageHighMem(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) return lowmem_page_address(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) pas = page_slot(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) ret = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) spin_lock_irqsave(&pas->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) if (!list_empty(&pas->lh)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) struct page_address_map *pam;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) list_for_each_entry(pam, &pas->lh, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) if (pam->page == page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) ret = pam->virtual;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) spin_unlock_irqrestore(&pas->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) EXPORT_SYMBOL(page_address);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) * set_page_address - set a page's virtual address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) * @page: &struct page to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) * @virtual: virtual address to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) void set_page_address(struct page *page, void *virtual)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) struct page_address_slot *pas;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) struct page_address_map *pam;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) BUG_ON(!PageHighMem(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) pas = page_slot(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) if (virtual) { /* Add */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) pam = &page_address_maps[PKMAP_NR((unsigned long)virtual)];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) pam->page = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) pam->virtual = virtual;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) spin_lock_irqsave(&pas->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) list_add_tail(&pam->list, &pas->lh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) spin_unlock_irqrestore(&pas->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) } else { /* Remove */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) spin_lock_irqsave(&pas->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) list_for_each_entry(pam, &pas->lh, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) if (pam->page == page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) list_del(&pam->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) spin_unlock_irqrestore(&pas->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) goto done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) spin_unlock_irqrestore(&pas->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) done:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) void __init page_address_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) for (i = 0; i < ARRAY_SIZE(page_address_htable); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) INIT_LIST_HEAD(&page_address_htable[i].lh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) spin_lock_init(&page_address_htable[i].lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) #endif /* defined(HASHED_PAGE_VIRTUAL) */