Skip to content

Commit 83b4e39

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
x86/mm/cpa: Make cpa_data::numpages invariant
Make sure __change_page_attr_set_clr() doesn't modify cpa->numpages. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@surriel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tom.StDenis@amd.com Cc: dave.hansen@intel.com Link: http://lkml.kernel.org/r/20181203171043.493000228@infradead.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 935f583 commit 83b4e39

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

arch/x86/mm/pageattr.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,14 +1625,15 @@ static int cpa_process_alias(struct cpa_data *cpa)
16251625
static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias)
16261626
{
16271627
unsigned long numpages = cpa->numpages;
1628-
int ret;
1628+
unsigned long rempages = numpages;
1629+
int ret = 0;
16291630

1630-
while (numpages) {
1631+
while (rempages) {
16311632
/*
16321633
* Store the remaining nr of pages for the large page
16331634
* preservation check.
16341635
*/
1635-
cpa->numpages = numpages;
1636+
cpa->numpages = rempages;
16361637
/* for array changes, we can't use large page */
16371638
if (cpa->flags & (CPA_ARRAY | CPA_PAGES_ARRAY))
16381639
cpa->numpages = 1;
@@ -1643,24 +1644,28 @@ static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias)
16431644
if (!debug_pagealloc_enabled())
16441645
spin_unlock(&cpa_lock);
16451646
if (ret)
1646-
return ret;
1647+
goto out;
16471648

16481649
if (checkalias) {
16491650
ret = cpa_process_alias(cpa);
16501651
if (ret)
1651-
return ret;
1652+
goto out;
16521653
}
16531654

16541655
/*
16551656
* Adjust the number of pages with the result of the
16561657
* CPA operation. Either a large page has been
16571658
* preserved or a single page update happened.
16581659
*/
1659-
BUG_ON(cpa->numpages > numpages || !cpa->numpages);
1660-
numpages -= cpa->numpages;
1660+
BUG_ON(cpa->numpages > rempages || !cpa->numpages);
1661+
rempages -= cpa->numpages;
16611662
cpa->curpage += cpa->numpages;
16621663
}
1663-
return 0;
1664+
1665+
out:
1666+
/* Restore the original numpages */
1667+
cpa->numpages = numpages;
1668+
return ret;
16641669
}
16651670

16661671
/*

0 commit comments

Comments
 (0)