Skip to content

Commit ef9ab81

Browse files
Peter Zijlstrahansendc
authored andcommitted
x86/mm: Untangle __change_page_attr_set_clr(.checkalias)
The .checkalias argument to __change_page_attr_set_clr() is overloaded and serves two different purposes: - it inhibits the call to cpa_process_alias() -- as suggested by the name; however, - it also serves as 'primary' indicator for __change_page_attr() ( which in turn also serves as a recursion terminator for cpa_process_alias() ). Untangle these by extending the use of CPA_NO_CHECK_ALIAS to all callsites that currently use .checkalias=0 for this purpose. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/20221110125544.527267183%40infradead.org
1 parent 5ceeee7 commit ef9ab81

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

arch/x86/mm/pat/set_memory.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,7 @@ static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias)
17271727
if (ret)
17281728
goto out;
17291729

1730-
if (checkalias) {
1730+
if (checkalias && !(cpa->flags & CPA_NO_CHECK_ALIAS)) {
17311731
ret = cpa_process_alias(cpa);
17321732
if (ret)
17331733
goto out;
@@ -1801,18 +1801,12 @@ static int change_page_attr_set_clr(unsigned long *addr, int numpages,
18011801
cpa.numpages = numpages;
18021802
cpa.mask_set = mask_set;
18031803
cpa.mask_clr = mask_clr;
1804-
cpa.flags = 0;
1804+
cpa.flags = in_flag;
18051805
cpa.curpage = 0;
18061806
cpa.force_split = force_split;
18071807

1808-
if (in_flag & (CPA_ARRAY | CPA_PAGES_ARRAY))
1809-
cpa.flags |= in_flag;
1810-
18111808
/* No alias checking for _NX bit modifications */
18121809
checkalias = (pgprot_val(mask_set) | pgprot_val(mask_clr)) != _PAGE_NX;
1813-
/* Has caller explicitly disabled alias checking? */
1814-
if (in_flag & CPA_NO_CHECK_ALIAS)
1815-
checkalias = 0;
18161810

18171811
ret = __change_page_attr_set_clr(&cpa, checkalias);
18181812

@@ -2067,11 +2061,9 @@ int set_memory_np(unsigned long addr, int numpages)
20672061

20682062
int set_memory_np_noalias(unsigned long addr, int numpages)
20692063
{
2070-
int cpa_flags = CPA_NO_CHECK_ALIAS;
2071-
20722064
return change_page_attr_set_clr(&addr, numpages, __pgprot(0),
20732065
__pgprot(_PAGE_PRESENT), 0,
2074-
cpa_flags, NULL);
2066+
CPA_NO_CHECK_ALIAS, NULL);
20752067
}
20762068

20772069
int set_memory_4k(unsigned long addr, int numpages)
@@ -2288,15 +2280,15 @@ static int __set_pages_p(struct page *page, int numpages)
22882280
.numpages = numpages,
22892281
.mask_set = __pgprot(_PAGE_PRESENT | _PAGE_RW),
22902282
.mask_clr = __pgprot(0),
2291-
.flags = 0};
2283+
.flags = CPA_NO_CHECK_ALIAS };
22922284

22932285
/*
22942286
* No alias checking needed for setting present flag. otherwise,
22952287
* we may need to break large pages for 64-bit kernel text
22962288
* mappings (this adds to complexity if we want to do this from
22972289
* atomic context especially). Let's keep it simple!
22982290
*/
2299-
return __change_page_attr_set_clr(&cpa, 0);
2291+
return __change_page_attr_set_clr(&cpa, 1);
23002292
}
23012293

23022294
static int __set_pages_np(struct page *page, int numpages)
@@ -2307,15 +2299,15 @@ static int __set_pages_np(struct page *page, int numpages)
23072299
.numpages = numpages,
23082300
.mask_set = __pgprot(0),
23092301
.mask_clr = __pgprot(_PAGE_PRESENT | _PAGE_RW),
2310-
.flags = 0};
2302+
.flags = CPA_NO_CHECK_ALIAS };
23112303

23122304
/*
23132305
* No alias checking needed for setting not present flag. otherwise,
23142306
* we may need to break large pages for 64-bit kernel text
23152307
* mappings (this adds to complexity if we want to do this from
23162308
* atomic context especially). Let's keep it simple!
23172309
*/
2318-
return __change_page_attr_set_clr(&cpa, 0);
2310+
return __change_page_attr_set_clr(&cpa, 1);
23192311
}
23202312

23212313
int set_direct_map_invalid_noflush(struct page *page)
@@ -2386,7 +2378,7 @@ int __init kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, unsigned long address,
23862378
.numpages = numpages,
23872379
.mask_set = __pgprot(0),
23882380
.mask_clr = __pgprot(~page_flags & (_PAGE_NX|_PAGE_RW)),
2389-
.flags = 0,
2381+
.flags = CPA_NO_CHECK_ALIAS,
23902382
};
23912383

23922384
WARN_ONCE(num_online_cpus() > 1, "Don't call after initializing SMP");
@@ -2399,7 +2391,7 @@ int __init kernel_map_pages_in_pgd(pgd_t *pgd, u64 pfn, unsigned long address,
23992391

24002392
cpa.mask_set = __pgprot(_PAGE_PRESENT | page_flags);
24012393

2402-
retval = __change_page_attr_set_clr(&cpa, 0);
2394+
retval = __change_page_attr_set_clr(&cpa, 1);
24032395
__flush_tlb_all();
24042396

24052397
out:
@@ -2429,12 +2421,12 @@ int __init kernel_unmap_pages_in_pgd(pgd_t *pgd, unsigned long address,
24292421
.numpages = numpages,
24302422
.mask_set = __pgprot(0),
24312423
.mask_clr = __pgprot(_PAGE_PRESENT | _PAGE_RW),
2432-
.flags = 0,
2424+
.flags = CPA_NO_CHECK_ALIAS,
24332425
};
24342426

24352427
WARN_ONCE(num_online_cpus() > 1, "Don't call after initializing SMP");
24362428

2437-
retval = __change_page_attr_set_clr(&cpa, 0);
2429+
retval = __change_page_attr_set_clr(&cpa, 1);
24382430
__flush_tlb_all();
24392431

24402432
return retval;

0 commit comments

Comments
 (0)