2022-10-03 04:37:25

by Ira Weiny

[permalink] [raw]
Subject: [PATCH] highmem: Fix kmap_to_page() for kmap_local_page() addresses

From: Ira Weiny <[email protected]>

kmap_to_page() is used to get the page for a virtual address which may
be kmap'ed. Unfortunately, kmap_local_page() stores mappings in a
thread local array separate from kmap(). These mappings were not
checked by the call.

Check the kmap_local_page() mappings and return the page if found.

Because it is intended to remove kmap_to_page() add a warn on once to
the kmap checks to flag potential issues early.

Cc: "Fabio M. De Francesco" <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: Andrew Morton <[email protected]>
Reported-by: Al Viro <[email protected]>
Signed-off-by: Ira Weiny <[email protected]>

---
I'm still working toward getting rid of kmap_to_page.[1] But until then
this fix should be applied.

[1] https://lore.kernel.org/linux-mm/[email protected]/
---
mm/highmem.c | 40 ++++++++++++++++++++++++++++++----------
1 file changed, 30 insertions(+), 10 deletions(-)

diff --git a/mm/highmem.c b/mm/highmem.c
index c707d7202d5f..29423c1afb3e 100644
--- a/mm/highmem.c
+++ b/mm/highmem.c
@@ -140,16 +140,45 @@ pte_t *pkmap_page_table;
do { spin_unlock(&kmap_lock); (void)(flags); } while (0)
#endif

+static inline int kmap_local_calc_idx(int idx)
+{
+ return idx + KM_MAX_IDX * smp_processor_id();
+}
+
+#ifndef arch_kmap_local_map_idx
+#define arch_kmap_local_map_idx(idx, pfn) kmap_local_calc_idx(idx)
+#endif
+
struct page *__kmap_to_page(void *vaddr)
{
+ unsigned long base = (unsigned long) vaddr & PAGE_MASK;
+ struct kmap_ctrl *kctrl = &current->kmap_ctrl;
unsigned long addr = (unsigned long)vaddr;
+ int i;

- if (addr >= PKMAP_ADDR(0) && addr < PKMAP_ADDR(LAST_PKMAP)) {
+ /* kmap() mappings */
+ if (WARN_ON_ONCE(addr >= PKMAP_ADDR(0) &&
+ addr < PKMAP_ADDR(LAST_PKMAP))) {
int i = PKMAP_NR(addr);

return pte_page(pkmap_page_table[i]);
}

+ /* kmap_local_page() mappings */
+ if (WARN_ON_ONCE(base >= __fix_to_virt(FIX_KMAP_END) &&
+ base < __fix_to_virt(FIX_KMAP_BEGIN))) {
+ for (i = 0; i < kctrl->idx; i++) {
+ unsigned long base_addr;
+ int idx;
+
+ idx = arch_kmap_local_map_idx(i, pte_pfn(pteval));
+ base_addr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
+
+ if (base_addr == base)
+ return pte_page(kctrl->pteval[i]);
+ }
+ }
+
return virt_to_page(vaddr);
}
EXPORT_SYMBOL(__kmap_to_page);
@@ -462,10 +491,6 @@ static inline void kmap_local_idx_pop(void)
# define arch_kmap_local_post_unmap(vaddr) do { } while (0)
#endif

-#ifndef arch_kmap_local_map_idx
-#define arch_kmap_local_map_idx(idx, pfn) kmap_local_calc_idx(idx)
-#endif
-
#ifndef arch_kmap_local_unmap_idx
#define arch_kmap_local_unmap_idx(idx, vaddr) kmap_local_calc_idx(idx)
#endif
@@ -494,11 +519,6 @@ static inline bool kmap_high_unmap_local(unsigned long vaddr)
return false;
}

-static inline int kmap_local_calc_idx(int idx)
-{
- return idx + KM_MAX_IDX * smp_processor_id();
-}
-
static pte_t *__kmap_pte;

static pte_t *kmap_get_pte(unsigned long vaddr, int idx)

base-commit: 274d7803837da78dfc911bcda0d593412676fc20
--
2.37.2


2022-10-03 08:20:06

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] highmem: Fix kmap_to_page() for kmap_local_page() addresses

Hi,

I love your patch! Yet something to improve:

[auto build test ERROR on 274d7803837da78dfc911bcda0d593412676fc20]

url: https://github.com/intel-lab-lkp/linux/commits/ira-weiny-intel-com/highmem-Fix-kmap_to_page-for-kmap_local_page-addresses/20221003-120524
base: 274d7803837da78dfc911bcda0d593412676fc20
config: i386-tinyconfig
compiler: gcc-11 (Debian 11.3.0-5) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/cd2106b2845310f5ee6e1a754c09e7caeabf3e01
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review ira-weiny-intel-com/highmem-Fix-kmap_to_page-for-kmap_local_page-addresses/20221003-120524
git checkout cd2106b2845310f5ee6e1a754c09e7caeabf3e01
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

mm/highmem.c: In function '__kmap_local_pfn_prot':
>> mm/highmem.c:549:15: error: implicit declaration of function 'arch_kmap_local_map_idx'; did you mean 'arch_kmap_local_unmap_idx'? [-Werror=implicit-function-declaration]
549 | idx = arch_kmap_local_map_idx(kmap_local_idx_push(), pfn);
| ^~~~~~~~~~~~~~~~~~~~~~~
| arch_kmap_local_unmap_idx
mm/highmem.c: In function 'kunmap_local_indexed':
>> mm/highmem.c:495:49: error: implicit declaration of function 'kmap_local_calc_idx'; did you mean 'kmap_local_idx'? [-Werror=implicit-function-declaration]
495 | #define arch_kmap_local_unmap_idx(idx, vaddr) kmap_local_calc_idx(idx)
| ^~~~~~~~~~~~~~~~~~~
mm/highmem.c:609:15: note: in expansion of macro 'arch_kmap_local_unmap_idx'
609 | idx = arch_kmap_local_unmap_idx(kmap_local_idx(), addr);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
cc1: some warnings being treated as errors


vim +549 mm/highmem.c

298fa1ad5571f5 Thomas Gleixner 2020-11-03 493
298fa1ad5571f5 Thomas Gleixner 2020-11-03 494 #ifndef arch_kmap_local_unmap_idx
298fa1ad5571f5 Thomas Gleixner 2020-11-03 @495 #define arch_kmap_local_unmap_idx(idx, vaddr) kmap_local_calc_idx(idx)
298fa1ad5571f5 Thomas Gleixner 2020-11-03 496 #endif
298fa1ad5571f5 Thomas Gleixner 2020-11-03 497
298fa1ad5571f5 Thomas Gleixner 2020-11-03 498 #ifndef arch_kmap_local_high_get
298fa1ad5571f5 Thomas Gleixner 2020-11-03 499 static inline void *arch_kmap_local_high_get(struct page *page)
298fa1ad5571f5 Thomas Gleixner 2020-11-03 500 {
298fa1ad5571f5 Thomas Gleixner 2020-11-03 501 return NULL;
298fa1ad5571f5 Thomas Gleixner 2020-11-03 502 }
298fa1ad5571f5 Thomas Gleixner 2020-11-03 503 #endif
298fa1ad5571f5 Thomas Gleixner 2020-11-03 504
a1dce7fd2ade8e Thomas Gleixner 2021-01-23 505 #ifndef arch_kmap_local_set_pte
a1dce7fd2ade8e Thomas Gleixner 2021-01-23 506 #define arch_kmap_local_set_pte(mm, vaddr, ptep, ptev) \
a1dce7fd2ade8e Thomas Gleixner 2021-01-23 507 set_pte_at(mm, vaddr, ptep, ptev)
a1dce7fd2ade8e Thomas Gleixner 2021-01-23 508 #endif
a1dce7fd2ade8e Thomas Gleixner 2021-01-23 509
298fa1ad5571f5 Thomas Gleixner 2020-11-03 510 /* Unmap a local mapping which was obtained by kmap_high_get() */
2a656cad337e0e Thomas Gleixner 2020-11-12 511 static inline bool kmap_high_unmap_local(unsigned long vaddr)
298fa1ad5571f5 Thomas Gleixner 2020-11-03 512 {
298fa1ad5571f5 Thomas Gleixner 2020-11-03 513 #ifdef ARCH_NEEDS_KMAP_HIGH_GET
2a656cad337e0e Thomas Gleixner 2020-11-12 514 if (vaddr >= PKMAP_ADDR(0) && vaddr < PKMAP_ADDR(LAST_PKMAP)) {
298fa1ad5571f5 Thomas Gleixner 2020-11-03 515 kunmap_high(pte_page(pkmap_page_table[PKMAP_NR(vaddr)]));
2a656cad337e0e Thomas Gleixner 2020-11-12 516 return true;
2a656cad337e0e Thomas Gleixner 2020-11-12 517 }
298fa1ad5571f5 Thomas Gleixner 2020-11-03 518 #endif
2a656cad337e0e Thomas Gleixner 2020-11-12 519 return false;
298fa1ad5571f5 Thomas Gleixner 2020-11-03 520 }
298fa1ad5571f5 Thomas Gleixner 2020-11-03 521
298fa1ad5571f5 Thomas Gleixner 2020-11-03 522 static pte_t *__kmap_pte;
298fa1ad5571f5 Thomas Gleixner 2020-11-03 523
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 524 static pte_t *kmap_get_pte(unsigned long vaddr, int idx)
298fa1ad5571f5 Thomas Gleixner 2020-11-03 525 {
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 526 if (IS_ENABLED(CONFIG_KMAP_LOCAL_NON_LINEAR_PTE_ARRAY))
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 527 /*
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 528 * Set by the arch if __kmap_pte[-idx] does not produce
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 529 * the correct entry.
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 530 */
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 531 return virt_to_kpte(vaddr);
298fa1ad5571f5 Thomas Gleixner 2020-11-03 532 if (!__kmap_pte)
298fa1ad5571f5 Thomas Gleixner 2020-11-03 533 __kmap_pte = virt_to_kpte(__fix_to_virt(FIX_KMAP_BEGIN));
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 534 return &__kmap_pte[-idx];
298fa1ad5571f5 Thomas Gleixner 2020-11-03 535 }
298fa1ad5571f5 Thomas Gleixner 2020-11-03 536
298fa1ad5571f5 Thomas Gleixner 2020-11-03 537 void *__kmap_local_pfn_prot(unsigned long pfn, pgprot_t prot)
298fa1ad5571f5 Thomas Gleixner 2020-11-03 538 {
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 539 pte_t pteval, *kmap_pte;
298fa1ad5571f5 Thomas Gleixner 2020-11-03 540 unsigned long vaddr;
298fa1ad5571f5 Thomas Gleixner 2020-11-03 541 int idx;
298fa1ad5571f5 Thomas Gleixner 2020-11-03 542
f3ba3c710ac5a3 Thomas Gleixner 2020-11-18 543 /*
f3ba3c710ac5a3 Thomas Gleixner 2020-11-18 544 * Disable migration so resulting virtual address is stable
f0953a1bbaca71 Ingo Molnar 2021-05-06 545 * across preemption.
f3ba3c710ac5a3 Thomas Gleixner 2020-11-18 546 */
f3ba3c710ac5a3 Thomas Gleixner 2020-11-18 547 migrate_disable();
298fa1ad5571f5 Thomas Gleixner 2020-11-03 548 preempt_disable();
298fa1ad5571f5 Thomas Gleixner 2020-11-03 @549 idx = arch_kmap_local_map_idx(kmap_local_idx_push(), pfn);
298fa1ad5571f5 Thomas Gleixner 2020-11-03 550 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 551 kmap_pte = kmap_get_pte(vaddr, idx);
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 552 BUG_ON(!pte_none(*kmap_pte));
298fa1ad5571f5 Thomas Gleixner 2020-11-03 553 pteval = pfn_pte(pfn, prot);
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 554 arch_kmap_local_set_pte(&init_mm, vaddr, kmap_pte, pteval);
298fa1ad5571f5 Thomas Gleixner 2020-11-03 555 arch_kmap_local_post_map(vaddr, pteval);
5fbda3ecd14a53 Thomas Gleixner 2020-11-18 556 current->kmap_ctrl.pteval[kmap_local_idx()] = pteval;
298fa1ad5571f5 Thomas Gleixner 2020-11-03 557 preempt_enable();
298fa1ad5571f5 Thomas Gleixner 2020-11-03 558
298fa1ad5571f5 Thomas Gleixner 2020-11-03 559 return (void *)vaddr;
298fa1ad5571f5 Thomas Gleixner 2020-11-03 560 }
298fa1ad5571f5 Thomas Gleixner 2020-11-03 561 EXPORT_SYMBOL_GPL(__kmap_local_pfn_prot);
298fa1ad5571f5 Thomas Gleixner 2020-11-03 562

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (7.27 kB)
config (29.96 kB)
Download all attachments

2022-10-03 13:06:50

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] highmem: Fix kmap_to_page() for kmap_local_page() addresses

Hi,

I love your patch! Yet something to improve:

[auto build test ERROR on 274d7803837da78dfc911bcda0d593412676fc20]

url: https://github.com/intel-lab-lkp/linux/commits/ira-weiny-intel-com/highmem-Fix-kmap_to_page-for-kmap_local_page-addresses/20221003-120524
base: 274d7803837da78dfc911bcda0d593412676fc20
config: x86_64-randconfig-a003-20221003
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/cd2106b2845310f5ee6e1a754c09e7caeabf3e01
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review ira-weiny-intel-com/highmem-Fix-kmap_to_page-for-kmap_local_page-addresses/20221003-120524
git checkout cd2106b2845310f5ee6e1a754c09e7caeabf3e01
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

>> mm/highmem.c:549:8: error: implicit declaration of function 'arch_kmap_local_map_idx' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
idx = arch_kmap_local_map_idx(kmap_local_idx_push(), pfn);
^
mm/highmem.c:549:8: note: did you mean 'arch_kmap_local_high_get'?
mm/highmem.c:499:21: note: 'arch_kmap_local_high_get' declared here
static inline void *arch_kmap_local_high_get(struct page *page)
^
>> mm/highmem.c:609:8: error: implicit declaration of function 'kmap_local_calc_idx' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
idx = arch_kmap_local_unmap_idx(kmap_local_idx(), addr);
^
mm/highmem.c:495:47: note: expanded from macro 'arch_kmap_local_unmap_idx'
#define arch_kmap_local_unmap_idx(idx, vaddr) kmap_local_calc_idx(idx)
^
mm/highmem.c:609:8: note: did you mean 'kmap_local_idx'?
mm/highmem.c:495:47: note: expanded from macro 'arch_kmap_local_unmap_idx'
#define arch_kmap_local_unmap_idx(idx, vaddr) kmap_local_calc_idx(idx)
^
mm/highmem.c:471:19: note: 'kmap_local_idx' declared here
static inline int kmap_local_idx(void)
^
mm/highmem.c:660:9: error: implicit declaration of function 'arch_kmap_local_map_idx' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
idx = arch_kmap_local_map_idx(i, pte_pfn(pteval));
^
mm/highmem.c:691:9: error: implicit declaration of function 'arch_kmap_local_map_idx' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
idx = arch_kmap_local_map_idx(i, pte_pfn(pteval));
^
4 errors generated.


vim +/arch_kmap_local_map_idx +549 mm/highmem.c

298fa1ad5571f5 Thomas Gleixner 2020-11-03 536
298fa1ad5571f5 Thomas Gleixner 2020-11-03 537 void *__kmap_local_pfn_prot(unsigned long pfn, pgprot_t prot)
298fa1ad5571f5 Thomas Gleixner 2020-11-03 538 {
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 539 pte_t pteval, *kmap_pte;
298fa1ad5571f5 Thomas Gleixner 2020-11-03 540 unsigned long vaddr;
298fa1ad5571f5 Thomas Gleixner 2020-11-03 541 int idx;
298fa1ad5571f5 Thomas Gleixner 2020-11-03 542
f3ba3c710ac5a3 Thomas Gleixner 2020-11-18 543 /*
f3ba3c710ac5a3 Thomas Gleixner 2020-11-18 544 * Disable migration so resulting virtual address is stable
f0953a1bbaca71 Ingo Molnar 2021-05-06 545 * across preemption.
f3ba3c710ac5a3 Thomas Gleixner 2020-11-18 546 */
f3ba3c710ac5a3 Thomas Gleixner 2020-11-18 547 migrate_disable();
298fa1ad5571f5 Thomas Gleixner 2020-11-03 548 preempt_disable();
298fa1ad5571f5 Thomas Gleixner 2020-11-03 @549 idx = arch_kmap_local_map_idx(kmap_local_idx_push(), pfn);
298fa1ad5571f5 Thomas Gleixner 2020-11-03 550 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 551 kmap_pte = kmap_get_pte(vaddr, idx);
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 552 BUG_ON(!pte_none(*kmap_pte));
298fa1ad5571f5 Thomas Gleixner 2020-11-03 553 pteval = pfn_pte(pfn, prot);
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 554 arch_kmap_local_set_pte(&init_mm, vaddr, kmap_pte, pteval);
298fa1ad5571f5 Thomas Gleixner 2020-11-03 555 arch_kmap_local_post_map(vaddr, pteval);
5fbda3ecd14a53 Thomas Gleixner 2020-11-18 556 current->kmap_ctrl.pteval[kmap_local_idx()] = pteval;
298fa1ad5571f5 Thomas Gleixner 2020-11-03 557 preempt_enable();
298fa1ad5571f5 Thomas Gleixner 2020-11-03 558
298fa1ad5571f5 Thomas Gleixner 2020-11-03 559 return (void *)vaddr;
298fa1ad5571f5 Thomas Gleixner 2020-11-03 560 }
298fa1ad5571f5 Thomas Gleixner 2020-11-03 561 EXPORT_SYMBOL_GPL(__kmap_local_pfn_prot);
298fa1ad5571f5 Thomas Gleixner 2020-11-03 562
298fa1ad5571f5 Thomas Gleixner 2020-11-03 563 void *__kmap_local_page_prot(struct page *page, pgprot_t prot)
298fa1ad5571f5 Thomas Gleixner 2020-11-03 564 {
298fa1ad5571f5 Thomas Gleixner 2020-11-03 565 void *kmap;
298fa1ad5571f5 Thomas Gleixner 2020-11-03 566
0e91a0c6984c83 Thomas Gleixner 2020-11-18 567 /*
0e91a0c6984c83 Thomas Gleixner 2020-11-18 568 * To broaden the usage of the actual kmap_local() machinery always map
0e91a0c6984c83 Thomas Gleixner 2020-11-18 569 * pages when debugging is enabled and the architecture has no problems
0e91a0c6984c83 Thomas Gleixner 2020-11-18 570 * with alias mappings.
0e91a0c6984c83 Thomas Gleixner 2020-11-18 571 */
0e91a0c6984c83 Thomas Gleixner 2020-11-18 572 if (!IS_ENABLED(CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP) && !PageHighMem(page))
298fa1ad5571f5 Thomas Gleixner 2020-11-03 573 return page_address(page);
298fa1ad5571f5 Thomas Gleixner 2020-11-03 574
298fa1ad5571f5 Thomas Gleixner 2020-11-03 575 /* Try kmap_high_get() if architecture has it enabled */
298fa1ad5571f5 Thomas Gleixner 2020-11-03 576 kmap = arch_kmap_local_high_get(page);
298fa1ad5571f5 Thomas Gleixner 2020-11-03 577 if (kmap)
298fa1ad5571f5 Thomas Gleixner 2020-11-03 578 return kmap;
298fa1ad5571f5 Thomas Gleixner 2020-11-03 579
298fa1ad5571f5 Thomas Gleixner 2020-11-03 580 return __kmap_local_pfn_prot(page_to_pfn(page), prot);
298fa1ad5571f5 Thomas Gleixner 2020-11-03 581 }
298fa1ad5571f5 Thomas Gleixner 2020-11-03 582 EXPORT_SYMBOL(__kmap_local_page_prot);
298fa1ad5571f5 Thomas Gleixner 2020-11-03 583
39ade048a32ea6 Fabio M. De Francesco 2022-07-06 584 void kunmap_local_indexed(const void *vaddr)
298fa1ad5571f5 Thomas Gleixner 2020-11-03 585 {
298fa1ad5571f5 Thomas Gleixner 2020-11-03 586 unsigned long addr = (unsigned long) vaddr & PAGE_MASK;
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 587 pte_t *kmap_pte;
298fa1ad5571f5 Thomas Gleixner 2020-11-03 588 int idx;
298fa1ad5571f5 Thomas Gleixner 2020-11-03 589
298fa1ad5571f5 Thomas Gleixner 2020-11-03 590 if (addr < __fix_to_virt(FIX_KMAP_END) ||
298fa1ad5571f5 Thomas Gleixner 2020-11-03 591 addr > __fix_to_virt(FIX_KMAP_BEGIN)) {
0e91a0c6984c83 Thomas Gleixner 2020-11-18 592 if (IS_ENABLED(CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP)) {
0e91a0c6984c83 Thomas Gleixner 2020-11-18 593 /* This _should_ never happen! See above. */
0e91a0c6984c83 Thomas Gleixner 2020-11-18 594 WARN_ON_ONCE(1);
0e91a0c6984c83 Thomas Gleixner 2020-11-18 595 return;
0e91a0c6984c83 Thomas Gleixner 2020-11-18 596 }
2a656cad337e0e Thomas Gleixner 2020-11-12 597 /*
2a656cad337e0e Thomas Gleixner 2020-11-12 598 * Handle mappings which were obtained by kmap_high_get()
2a656cad337e0e Thomas Gleixner 2020-11-12 599 * first as the virtual address of such mappings is below
2a656cad337e0e Thomas Gleixner 2020-11-12 600 * PAGE_OFFSET. Warn for all other addresses which are in
2a656cad337e0e Thomas Gleixner 2020-11-12 601 * the user space part of the virtual address space.
2a656cad337e0e Thomas Gleixner 2020-11-12 602 */
2a656cad337e0e Thomas Gleixner 2020-11-12 603 if (!kmap_high_unmap_local(addr))
298fa1ad5571f5 Thomas Gleixner 2020-11-03 604 WARN_ON_ONCE(addr < PAGE_OFFSET);
298fa1ad5571f5 Thomas Gleixner 2020-11-03 605 return;
298fa1ad5571f5 Thomas Gleixner 2020-11-03 606 }
298fa1ad5571f5 Thomas Gleixner 2020-11-03 607
298fa1ad5571f5 Thomas Gleixner 2020-11-03 608 preempt_disable();
298fa1ad5571f5 Thomas Gleixner 2020-11-03 @609 idx = arch_kmap_local_unmap_idx(kmap_local_idx(), addr);
298fa1ad5571f5 Thomas Gleixner 2020-11-03 610 WARN_ON_ONCE(addr != __fix_to_virt(FIX_KMAP_BEGIN + idx));
298fa1ad5571f5 Thomas Gleixner 2020-11-03 611
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 612 kmap_pte = kmap_get_pte(addr, idx);
298fa1ad5571f5 Thomas Gleixner 2020-11-03 613 arch_kmap_local_pre_unmap(addr);
825c43f50e3aa8 Ard Biesheuvel 2021-11-19 614 pte_clear(&init_mm, addr, kmap_pte);
298fa1ad5571f5 Thomas Gleixner 2020-11-03 615 arch_kmap_local_post_unmap(addr);
5fbda3ecd14a53 Thomas Gleixner 2020-11-18 616 current->kmap_ctrl.pteval[kmap_local_idx()] = __pte(0);
298fa1ad5571f5 Thomas Gleixner 2020-11-03 617 kmap_local_idx_pop();
298fa1ad5571f5 Thomas Gleixner 2020-11-03 618 preempt_enable();
f3ba3c710ac5a3 Thomas Gleixner 2020-11-18 619 migrate_enable();
298fa1ad5571f5 Thomas Gleixner 2020-11-03 620 }
298fa1ad5571f5 Thomas Gleixner 2020-11-03 621 EXPORT_SYMBOL(kunmap_local_indexed);
5fbda3ecd14a53 Thomas Gleixner 2020-11-18 622

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (10.30 kB)
config (139.85 kB)
Download all attachments