Skip to content

Commit 98bfc9b

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
x86/mm/cpa: Make cpa_data::vaddr invariant
Currently __change_page_attr_set_clr() will modify cpa->vaddr when !(CPA_ARRAY | CPA_PAGES_ARRAY), whereas in the array cases it will increment cpa->curpage. Change __cpa_addr() such that its @idx argument also works in the !array case and use cpa->curpage increments for all cases. NOTE: since cpa_data::numpages is 'unsigned long' so should cpa_data::curpage be. NOTE: after this only cpa->numpages is still modified. 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.295174892@infradead.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 16ebf03 commit 98bfc9b

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

arch/x86/mm/pageattr.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ struct cpa_data {
3535
pgprot_t mask_set;
3636
pgprot_t mask_clr;
3737
unsigned long numpages;
38-
int flags;
38+
unsigned long curpage;
3939
unsigned long pfn;
40-
unsigned force_split : 1,
40+
unsigned int flags;
41+
unsigned int force_split : 1,
4142
force_static_prot : 1;
42-
int curpage;
4343
struct page **pages;
4444
};
4545

@@ -228,7 +228,7 @@ static bool __cpa_pfn_in_highmap(unsigned long pfn)
228228

229229
#endif
230230

231-
static unsigned long __cpa_addr(struct cpa_data *cpa, int idx)
231+
static unsigned long __cpa_addr(struct cpa_data *cpa, unsigned long idx)
232232
{
233233
if (cpa->flags & CPA_PAGES_ARRAY) {
234234
struct page *page = cpa->pages[idx];
@@ -242,7 +242,7 @@ static unsigned long __cpa_addr(struct cpa_data *cpa, int idx)
242242
if (cpa->flags & CPA_ARRAY)
243243
return cpa->vaddr[idx];
244244

245-
return *cpa->vaddr;
245+
return *cpa->vaddr + idx * PAGE_SIZE;
246246
}
247247

248248
/*
@@ -1581,6 +1581,7 @@ static int cpa_process_alias(struct cpa_data *cpa)
15811581
alias_cpa = *cpa;
15821582
alias_cpa.vaddr = &laddr;
15831583
alias_cpa.flags &= ~(CPA_PAGES_ARRAY | CPA_ARRAY);
1584+
alias_cpa.curpage = 0;
15841585

15851586
ret = __change_page_attr_set_clr(&alias_cpa, 0);
15861587
if (ret)
@@ -1600,6 +1601,7 @@ static int cpa_process_alias(struct cpa_data *cpa)
16001601
alias_cpa = *cpa;
16011602
alias_cpa.vaddr = &temp_cpa_vaddr;
16021603
alias_cpa.flags &= ~(CPA_PAGES_ARRAY | CPA_ARRAY);
1604+
alias_cpa.curpage = 0;
16031605

16041606
/*
16051607
* The high mapping range is imprecise, so ignore the
@@ -1648,11 +1650,7 @@ static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias)
16481650
*/
16491651
BUG_ON(cpa->numpages > numpages || !cpa->numpages);
16501652
numpages -= cpa->numpages;
1651-
if (cpa->flags & (CPA_PAGES_ARRAY | CPA_ARRAY))
1652-
cpa->curpage++;
1653-
else
1654-
*cpa->vaddr += cpa->numpages * PAGE_SIZE;
1655-
1653+
cpa->curpage += cpa->numpages;
16561654
}
16571655
return 0;
16581656
}

0 commit comments

Comments
 (0)