Commit 83b4e391 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

x86/mm/cpa: Make cpa_data::numpages invariant

Make sure __change_page_attr_set_clr() doesn't modify cpa->numpages.
Signed-off-by: default avatarPeter 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.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 935f5839
...@@ -1625,14 +1625,15 @@ static int cpa_process_alias(struct cpa_data *cpa) ...@@ -1625,14 +1625,15 @@ static int cpa_process_alias(struct cpa_data *cpa)
static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias) static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias)
{ {
unsigned long numpages = cpa->numpages; unsigned long numpages = cpa->numpages;
int ret; unsigned long rempages = numpages;
int ret = 0;
while (numpages) { while (rempages) {
/* /*
* Store the remaining nr of pages for the large page * Store the remaining nr of pages for the large page
* preservation check. * preservation check.
*/ */
cpa->numpages = numpages; cpa->numpages = rempages;
/* for array changes, we can't use large page */ /* for array changes, we can't use large page */
if (cpa->flags & (CPA_ARRAY | CPA_PAGES_ARRAY)) if (cpa->flags & (CPA_ARRAY | CPA_PAGES_ARRAY))
cpa->numpages = 1; cpa->numpages = 1;
...@@ -1643,12 +1644,12 @@ static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias) ...@@ -1643,12 +1644,12 @@ static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias)
if (!debug_pagealloc_enabled()) if (!debug_pagealloc_enabled())
spin_unlock(&cpa_lock); spin_unlock(&cpa_lock);
if (ret) if (ret)
return ret; goto out;
if (checkalias) { if (checkalias) {
ret = cpa_process_alias(cpa); ret = cpa_process_alias(cpa);
if (ret) if (ret)
return ret; goto out;
} }
/* /*
...@@ -1656,11 +1657,15 @@ static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias) ...@@ -1656,11 +1657,15 @@ static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias)
* CPA operation. Either a large page has been * CPA operation. Either a large page has been
* preserved or a single page update happened. * preserved or a single page update happened.
*/ */
BUG_ON(cpa->numpages > numpages || !cpa->numpages); BUG_ON(cpa->numpages > rempages || !cpa->numpages);
numpages -= cpa->numpages; rempages -= cpa->numpages;
cpa->curpage += cpa->numpages; cpa->curpage += cpa->numpages;
} }
return 0;
out:
/* Restore the original numpages */
cpa->numpages = numpages;
return ret;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment