Skip to content

Commit d597416

Browse files
Peter Zijlstrahansendc
authored andcommitted
x86/mm: Inhibit _PAGE_NX changes from cpa_process_alias()
There is a cludge in change_page_attr_set_clr() that inhibits propagating NX changes to the aliases (directmap and highmap) -- this is a cludge twofold: - it also inhibits the primary checks in __change_page_attr(); - it hard depends on single bit changes. The introduction of set_memory_rox() triggered this last issue for clearing both _PAGE_RW and _PAGE_NX. Explicitly ignore _PAGE_NX in cpa_process_alias() instead. Fixes: b389949 ("x86/mm: Implement native set_memory_rox()") Reported-by: kernel test robot <[email protected]> Debugged-by: Dave Hansen <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/20221110125544.594991716%40infradead.org
1 parent ef9ab81 commit d597416

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

arch/x86/mm/pat/set_memory.c

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1669,6 +1669,12 @@ static int cpa_process_alias(struct cpa_data *cpa)
16691669
alias_cpa.flags &= ~(CPA_PAGES_ARRAY | CPA_ARRAY);
16701670
alias_cpa.curpage = 0;
16711671

1672+
/* Directmap always has NX set, do not modify. */
1673+
if (__supported_pte_mask & _PAGE_NX) {
1674+
alias_cpa.mask_clr.pgprot &= ~_PAGE_NX;
1675+
alias_cpa.mask_set.pgprot &= ~_PAGE_NX;
1676+
}
1677+
16721678
cpa->force_flush_all = 1;
16731679

16741680
ret = __change_page_attr_set_clr(&alias_cpa, 0);
@@ -1691,6 +1697,15 @@ static int cpa_process_alias(struct cpa_data *cpa)
16911697
alias_cpa.flags &= ~(CPA_PAGES_ARRAY | CPA_ARRAY);
16921698
alias_cpa.curpage = 0;
16931699

1700+
/*
1701+
* [_text, _brk_end) also covers data, do not modify NX except
1702+
* in cases where the highmap is the primary target.
1703+
*/
1704+
if (__supported_pte_mask & _PAGE_NX) {
1705+
alias_cpa.mask_clr.pgprot &= ~_PAGE_NX;
1706+
alias_cpa.mask_set.pgprot &= ~_PAGE_NX;
1707+
}
1708+
16941709
cpa->force_flush_all = 1;
16951710
/*
16961711
* The high mapping range is imprecise, so ignore the
@@ -1709,6 +1724,12 @@ static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias)
17091724
unsigned long rempages = numpages;
17101725
int ret = 0;
17111726

1727+
/*
1728+
* No changes, easy!
1729+
*/
1730+
if (!(pgprot_val(cpa->mask_set) | pgprot_val(cpa->mask_clr)))
1731+
return ret;
1732+
17121733
while (rempages) {
17131734
/*
17141735
* Store the remaining nr of pages for the large page
@@ -1755,7 +1776,7 @@ static int change_page_attr_set_clr(unsigned long *addr, int numpages,
17551776
struct page **pages)
17561777
{
17571778
struct cpa_data cpa;
1758-
int ret, cache, checkalias;
1779+
int ret, cache;
17591780

17601781
memset(&cpa, 0, sizeof(cpa));
17611782

@@ -1805,10 +1826,7 @@ static int change_page_attr_set_clr(unsigned long *addr, int numpages,
18051826
cpa.curpage = 0;
18061827
cpa.force_split = force_split;
18071828

1808-
/* No alias checking for _NX bit modifications */
1809-
checkalias = (pgprot_val(mask_set) | pgprot_val(mask_clr)) != _PAGE_NX;
1810-
1811-
ret = __change_page_attr_set_clr(&cpa, checkalias);
1829+
ret = __change_page_attr_set_clr(&cpa, 1);
18121830

18131831
/*
18141832
* Check whether we really changed something:

0 commit comments

Comments
 (0)