Skip to content

Commit

Permalink
x86: Use new cache mode type in memtype related functions
Browse files Browse the repository at this point in the history
Instead of directly using the cache mode bits in the pte switch to
using the cache mode type.

Based-on-patch-by: Stefan Bader <stefan.bader@canonical.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stefan.bader@canonical.com
Cc: xen-devel@lists.xensource.com
Cc: konrad.wilk@oracle.com
Cc: ville.syrjala@linux.intel.com
Cc: david.vrabel@citrix.com
Cc: jbeulich@suse.com
Cc: toshi.kani@hp.com
Cc: plagnioj@jcrosoft.com
Cc: tomi.valkeinen@ti.com
Cc: bhelgaas@google.com
Link: http://lkml.kernel.org/r/1415019724-4317-14-git-send-email-jgross@suse.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
Juergen Gross authored and Thomas Gleixner committed Nov 16, 2014
1 parent b14097b commit e00c8cc
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 90 deletions.
38 changes: 24 additions & 14 deletions arch/x86/include/asm/cacheflush.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
/*
* X86 PAT uses page flags WC and Uncached together to keep track of
* memory type of pages that have backing page struct. X86 PAT supports 3
* different memory types, _PAGE_CACHE_WB, _PAGE_CACHE_WC and
* _PAGE_CACHE_UC_MINUS and fourth state where page's memory type has not
* different memory types, _PAGE_CACHE_MODE_WB, _PAGE_CACHE_MODE_WC and
* _PAGE_CACHE_MODE_UC_MINUS and fourth state where page's memory type has not
* been changed from its default (value of -1 used to denote this).
* Note we do not support _PAGE_CACHE_UC here.
* Note we do not support _PAGE_CACHE_MODE_UC here.
*/

#define _PGMT_DEFAULT 0
Expand All @@ -22,36 +22,40 @@
#define _PGMT_MASK (1UL << PG_uncached | 1UL << PG_arch_1)
#define _PGMT_CLEAR_MASK (~_PGMT_MASK)

static inline unsigned long get_page_memtype(struct page *pg)
static inline enum page_cache_mode get_page_memtype(struct page *pg)
{
unsigned long pg_flags = pg->flags & _PGMT_MASK;

if (pg_flags == _PGMT_DEFAULT)
return -1;
else if (pg_flags == _PGMT_WC)
return _PAGE_CACHE_WC;
return _PAGE_CACHE_MODE_WC;
else if (pg_flags == _PGMT_UC_MINUS)
return _PAGE_CACHE_UC_MINUS;
return _PAGE_CACHE_MODE_UC_MINUS;
else
return _PAGE_CACHE_WB;
return _PAGE_CACHE_MODE_WB;
}

static inline void set_page_memtype(struct page *pg, unsigned long memtype)
static inline void set_page_memtype(struct page *pg,
enum page_cache_mode memtype)
{
unsigned long memtype_flags = _PGMT_DEFAULT;
unsigned long memtype_flags;
unsigned long old_flags;
unsigned long new_flags;

switch (memtype) {
case _PAGE_CACHE_WC:
case _PAGE_CACHE_MODE_WC:
memtype_flags = _PGMT_WC;
break;
case _PAGE_CACHE_UC_MINUS:
case _PAGE_CACHE_MODE_UC_MINUS:
memtype_flags = _PGMT_UC_MINUS;
break;
case _PAGE_CACHE_WB:
case _PAGE_CACHE_MODE_WB:
memtype_flags = _PGMT_WB;
break;
default:
memtype_flags = _PGMT_DEFAULT;
break;
}

do {
Expand All @@ -60,8 +64,14 @@ static inline void set_page_memtype(struct page *pg, unsigned long memtype)
} while (cmpxchg(&pg->flags, old_flags, new_flags) != old_flags);
}
#else
static inline unsigned long get_page_memtype(struct page *pg) { return -1; }
static inline void set_page_memtype(struct page *pg, unsigned long memtype) { }
static inline enum page_cache_mode get_page_memtype(struct page *pg)
{
return -1;
}
static inline void set_page_memtype(struct page *pg,
enum page_cache_mode memtype)
{
}
#endif

/*
Expand Down
2 changes: 1 addition & 1 deletion arch/x86/include/asm/pat.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ static const int pat_enabled;
extern void pat_init(void);

extern int reserve_memtype(u64 start, u64 end,
unsigned long req_type, unsigned long *ret_type);
enum page_cache_mode req_pcm, enum page_cache_mode *ret_pcm);
extern int free_memtype(u64 start, u64 end);

extern int kernel_map_sync_memtype(u64 base, unsigned long size,
Expand Down
5 changes: 1 addition & 4 deletions arch/x86/mm/ioremap.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
const unsigned long unaligned_size = size;
struct vm_struct *area;
enum page_cache_mode new_pcm;
unsigned long new_prot_val;
pgprot_t prot;
int retval;
void __iomem *ret_addr;
Expand Down Expand Up @@ -135,14 +134,12 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
size = PAGE_ALIGN(last_addr+1) - phys_addr;

retval = reserve_memtype(phys_addr, (u64)phys_addr + size,
cachemode2protval(pcm), &new_prot_val);
pcm, &new_pcm);
if (retval) {
printk(KERN_ERR "ioremap reserve_memtype failed %d\n", retval);
return NULL;
}

new_pcm = pgprot2cachemode(__pgprot(new_prot_val));

if (pcm != new_pcm) {
if (!is_new_memtype_allowed(phys_addr, size, pcm, new_pcm)) {
printk(KERN_ERR
Expand Down
9 changes: 4 additions & 5 deletions arch/x86/mm/pageattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ int set_memory_uc(unsigned long addr, int numpages)
* for now UC MINUS. see comments in ioremap_nocache()
*/
ret = reserve_memtype(__pa(addr), __pa(addr) + numpages * PAGE_SIZE,
_PAGE_CACHE_UC_MINUS, NULL);
_PAGE_CACHE_MODE_UC_MINUS, NULL);
if (ret)
goto out_err;

Expand Down Expand Up @@ -1479,7 +1479,7 @@ static int _set_memory_array(unsigned long *addr, int addrinarray,
*/
for (i = 0; i < addrinarray; i++) {
ret = reserve_memtype(__pa(addr[i]), __pa(addr[i]) + PAGE_SIZE,
cachemode2protval(new_type), NULL);
new_type, NULL);
if (ret)
goto out_free;
}
Expand Down Expand Up @@ -1544,7 +1544,7 @@ int set_memory_wc(unsigned long addr, int numpages)
return set_memory_uc(addr, numpages);

ret = reserve_memtype(__pa(addr), __pa(addr) + numpages * PAGE_SIZE,
_PAGE_CACHE_WC, NULL);
_PAGE_CACHE_MODE_WC, NULL);
if (ret)
goto out_err;

Expand Down Expand Up @@ -1662,8 +1662,7 @@ static int _set_pages_array(struct page **pages, int addrinarray,
continue;
start = page_to_pfn(pages[i]) << PAGE_SHIFT;
end = start + PAGE_SIZE;
if (reserve_memtype(start, end, cachemode2protval(new_type),
NULL))
if (reserve_memtype(start, end, new_type, NULL))
goto err_out;
}

Expand Down
Loading

0 comments on commit e00c8cc

Please sign in to comment.