Commit 16ebf031 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

x86/mm/cpa: Add __cpa_addr() helper

The code to compute the virtual address of a cpa_data is duplicated;
introduce a helper before more copies happen.
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.229119497@infradead.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent ecc729f1
...@@ -228,6 +228,23 @@ static bool __cpa_pfn_in_highmap(unsigned long pfn) ...@@ -228,6 +228,23 @@ static bool __cpa_pfn_in_highmap(unsigned long pfn)
#endif #endif
static unsigned long __cpa_addr(struct cpa_data *cpa, int idx)
{
if (cpa->flags & CPA_PAGES_ARRAY) {
struct page *page = cpa->pages[idx];
if (unlikely(PageHighMem(page)))
return 0;
return (unsigned long)page_address(page);
}
if (cpa->flags & CPA_ARRAY)
return cpa->vaddr[idx];
return *cpa->vaddr;
}
/* /*
* Flushing functions * Flushing functions
*/ */
...@@ -1476,15 +1493,7 @@ static int __change_page_attr(struct cpa_data *cpa, int primary) ...@@ -1476,15 +1493,7 @@ static int __change_page_attr(struct cpa_data *cpa, int primary)
unsigned int level; unsigned int level;
pte_t *kpte, old_pte; pte_t *kpte, old_pte;
if (cpa->flags & CPA_PAGES_ARRAY) { address = __cpa_addr(cpa, cpa->curpage);
struct page *page = cpa->pages[cpa->curpage];
if (unlikely(PageHighMem(page)))
return 0;
address = (unsigned long)page_address(page);
} else if (cpa->flags & CPA_ARRAY)
address = cpa->vaddr[cpa->curpage];
else
address = *cpa->vaddr;
repeat: repeat:
kpte = _lookup_address_cpa(cpa, address, &level); kpte = _lookup_address_cpa(cpa, address, &level);
if (!kpte) if (!kpte)
...@@ -1565,16 +1574,7 @@ static int cpa_process_alias(struct cpa_data *cpa) ...@@ -1565,16 +1574,7 @@ static int cpa_process_alias(struct cpa_data *cpa)
* No need to redo, when the primary call touched the direct * No need to redo, when the primary call touched the direct
* mapping already: * mapping already:
*/ */
if (cpa->flags & CPA_PAGES_ARRAY) { vaddr = __cpa_addr(cpa, cpa->curpage);
struct page *page = cpa->pages[cpa->curpage];
if (unlikely(PageHighMem(page)))
return 0;
vaddr = (unsigned long)page_address(page);
} else if (cpa->flags & CPA_ARRAY)
vaddr = cpa->vaddr[cpa->curpage];
else
vaddr = *cpa->vaddr;
if (!(within(vaddr, PAGE_OFFSET, if (!(within(vaddr, PAGE_OFFSET,
PAGE_OFFSET + (max_pfn_mapped << PAGE_SHIFT)))) { PAGE_OFFSET + (max_pfn_mapped << PAGE_SHIFT)))) {
......
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