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