Skip to content

Commit

Permalink
x86/clear_page: add clear_page_uncached()
Browse files Browse the repository at this point in the history
Define clear_page_uncached() as an alternative_call() to clear_page_nt()
if the CPU sets X86_FEATURE_NT_GOOD and fallback to clear_page() if it
doesn't.

Similarly define clear_page_uncached_flush() which provides an SFENCE
if the CPU sets X86_FEATURE_NT_GOOD.

Also, add the glue interface clear_user_highpage_uncached().

Signed-off-by: Ankur Arora <ankur.a.arora@oracle.com>
  • Loading branch information
terminus authored and intel-lab-lkp committed Oct 14, 2020
1 parent a2d5921 commit 6a1ec80
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions arch/x86/include/asm/page.h
Expand Up @@ -28,6 +28,12 @@ static inline void clear_user_page(void *page, unsigned long vaddr,
clear_page(page);
}

static inline void clear_user_page_uncached(void *page, unsigned long vaddr,
struct page *pg)
{
clear_page_uncached(page);
}

static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
struct page *topage)
{
Expand Down
9 changes: 9 additions & 0 deletions arch/x86/include/asm/page_32.h
Expand Up @@ -39,6 +39,15 @@ static inline void clear_page(void *page)
memset(page, 0, PAGE_SIZE);
}

static inline void clear_page_uncached(void *page)
{
clear_page(page);
}

static inline void clear_page_uncached_flush(void)
{
}

static inline void copy_page(void *to, void *from)
{
memcpy(to, from, PAGE_SIZE);
Expand Down
14 changes: 14 additions & 0 deletions arch/x86/include/asm/page_64.h
Expand Up @@ -55,6 +55,20 @@ static inline void clear_page(void *page)
: "cc", "memory", "rax", "rcx");
}

static inline void clear_page_uncached(void *page)
{
alternative_call(clear_page,
clear_page_nt, X86_FEATURE_NT_GOOD,
"=D" (page),
"0" (page)
: "cc", "memory", "rax", "rcx");
}

static inline void clear_page_uncached_flush(void)
{
alternative("", "sfence", X86_FEATURE_NT_GOOD);
}

void copy_page(void *to, void *from);

#endif /* !__ASSEMBLY__ */
Expand Down
3 changes: 3 additions & 0 deletions include/asm-generic/page.h
Expand Up @@ -26,6 +26,9 @@
#ifndef __ASSEMBLY__

#define clear_page(page) memset((page), 0, PAGE_SIZE)
#define clear_page_uncached(page) clear_page(page)
#define clear_page_uncached_flush() do { } while (0)

#define copy_page(to,from) memcpy((to), (from), PAGE_SIZE)

#define clear_user_page(page, vaddr, pg) clear_page(page)
Expand Down
10 changes: 10 additions & 0 deletions include/linux/highmem.h
Expand Up @@ -232,6 +232,16 @@ static inline void clear_user_highpage(struct page *page, unsigned long vaddr)
}
#endif

#ifndef clear_user_highpage_uncached
static inline void clear_user_highpage_uncached(struct page *page, unsigned long vaddr)
{
void *addr = kmap_atomic(page);

clear_user_page_uncached(addr, vaddr, page);
kunmap_atomic(addr);
}
#endif

#ifndef __HAVE_ARCH_ALLOC_ZEROED_USER_HIGHPAGE
/**
* __alloc_zeroed_user_highpage - Allocate a zeroed HIGHMEM page for a VMA with caller-specified movable GFP flags
Expand Down

0 comments on commit 6a1ec80

Please sign in to comment.