Commit 9fa3ab39 authored by venkatesh.pallipadi@intel.com's avatar venkatesh.pallipadi@intel.com Committed by Ingo Molnar

x86, PAT: Handle faults cleanly in set_memory_ APIs

Handle faults and do proper cleanups in set_memory_*() functions. In
some cases, these functions were not doing proper free on failure paths.

With the changes to tracking memtype of RAM pages in struct page instead
of pat list, we do not need the changes in commits c5e147. This patch
reverts that change.
Signed-off-by: default avatarVenkatesh Pallipadi <venkatesh.pallipadi@intel.com>
Signed-off-by: default avatarSuresh Siddha <suresh.b.siddha@intel.com>
LKML-Reference: <20090409212708.653222000@intel.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent a5593e0b
...@@ -945,52 +945,56 @@ int _set_memory_uc(unsigned long addr, int numpages) ...@@ -945,52 +945,56 @@ int _set_memory_uc(unsigned long addr, int numpages)
int set_memory_uc(unsigned long addr, int numpages) int set_memory_uc(unsigned long addr, int numpages)
{ {
int ret;
/* /*
* for now UC MINUS. see comments in ioremap_nocache() * for now UC MINUS. see comments in ioremap_nocache()
*/ */
if (reserve_memtype(__pa(addr), __pa(addr) + numpages * PAGE_SIZE, ret = reserve_memtype(__pa(addr), __pa(addr) + numpages * PAGE_SIZE,
_PAGE_CACHE_UC_MINUS, NULL)) _PAGE_CACHE_UC_MINUS, NULL);
return -EINVAL; if (ret)
goto out_err;
ret = _set_memory_uc(addr, numpages);
if (ret)
goto out_free;
return 0;
return _set_memory_uc(addr, numpages); out_free:
free_memtype(__pa(addr), __pa(addr) + numpages * PAGE_SIZE);
out_err:
return ret;
} }
EXPORT_SYMBOL(set_memory_uc); EXPORT_SYMBOL(set_memory_uc);
int set_memory_array_uc(unsigned long *addr, int addrinarray) int set_memory_array_uc(unsigned long *addr, int addrinarray)
{ {
unsigned long start; int i, j;
unsigned long end; int ret;
int i;
/* /*
* for now UC MINUS. see comments in ioremap_nocache() * for now UC MINUS. see comments in ioremap_nocache()
*/ */
for (i = 0; i < addrinarray; i++) { for (i = 0; i < addrinarray; i++) {
start = __pa(addr[i]); ret = reserve_memtype(__pa(addr[i]), __pa(addr[i]) + PAGE_SIZE,
for (end = start + PAGE_SIZE; i < addrinarray - 1; end += PAGE_SIZE) { _PAGE_CACHE_UC_MINUS, NULL);
if (end != __pa(addr[i + 1])) if (ret)
break; goto out_free;
i++;
}
if (reserve_memtype(start, end, _PAGE_CACHE_UC_MINUS, NULL))
goto out;
} }
return change_page_attr_set(addr, addrinarray, ret = change_page_attr_set(addr, addrinarray,
__pgprot(_PAGE_CACHE_UC_MINUS), 1); __pgprot(_PAGE_CACHE_UC_MINUS), 1);
out: if (ret)
for (i = 0; i < addrinarray; i++) { goto out_free;
unsigned long tmp = __pa(addr[i]);
return 0;
if (tmp == start)
break; out_free:
for (end = tmp + PAGE_SIZE; i < addrinarray - 1; end += PAGE_SIZE) { for (j = 0; j < i; j++)
if (end != __pa(addr[i + 1])) free_memtype(__pa(addr[j]), __pa(addr[j]) + PAGE_SIZE);
break;
i++; return ret;
}
free_memtype(tmp, end);
}
return -EINVAL;
} }
EXPORT_SYMBOL(set_memory_array_uc); EXPORT_SYMBOL(set_memory_array_uc);
...@@ -1002,14 +1006,26 @@ int _set_memory_wc(unsigned long addr, int numpages) ...@@ -1002,14 +1006,26 @@ int _set_memory_wc(unsigned long addr, int numpages)
int set_memory_wc(unsigned long addr, int numpages) int set_memory_wc(unsigned long addr, int numpages)
{ {
int ret;
if (!pat_enabled) if (!pat_enabled)
return set_memory_uc(addr, numpages); return set_memory_uc(addr, numpages);
if (reserve_memtype(__pa(addr), __pa(addr) + numpages * PAGE_SIZE, ret = reserve_memtype(__pa(addr), __pa(addr) + numpages * PAGE_SIZE,
_PAGE_CACHE_WC, NULL)) _PAGE_CACHE_WC, NULL);
return -EINVAL; if (ret)
goto out_err;
return _set_memory_wc(addr, numpages); ret = _set_memory_wc(addr, numpages);
if (ret)
goto out_free;
return 0;
out_free:
free_memtype(__pa(addr), __pa(addr) + numpages * PAGE_SIZE);
out_err:
return ret;
} }
EXPORT_SYMBOL(set_memory_wc); EXPORT_SYMBOL(set_memory_wc);
...@@ -1021,9 +1037,14 @@ int _set_memory_wb(unsigned long addr, int numpages) ...@@ -1021,9 +1037,14 @@ int _set_memory_wb(unsigned long addr, int numpages)
int set_memory_wb(unsigned long addr, int numpages) int set_memory_wb(unsigned long addr, int numpages)
{ {
int ret = _set_memory_wb(addr, numpages); int ret;
ret = _set_memory_wb(addr, numpages);
if (ret)
return ret;
free_memtype(__pa(addr), __pa(addr) + numpages * PAGE_SIZE); free_memtype(__pa(addr), __pa(addr) + numpages * PAGE_SIZE);
return ret; return 0;
} }
EXPORT_SYMBOL(set_memory_wb); EXPORT_SYMBOL(set_memory_wb);
...@@ -1034,19 +1055,13 @@ int set_memory_array_wb(unsigned long *addr, int addrinarray) ...@@ -1034,19 +1055,13 @@ int set_memory_array_wb(unsigned long *addr, int addrinarray)
ret = change_page_attr_clear(addr, addrinarray, ret = change_page_attr_clear(addr, addrinarray,
__pgprot(_PAGE_CACHE_MASK), 1); __pgprot(_PAGE_CACHE_MASK), 1);
if (ret)
return ret;
for (i = 0; i < addrinarray; i++) { for (i = 0; i < addrinarray; i++)
unsigned long start = __pa(addr[i]); free_memtype(__pa(addr[i]), __pa(addr[i]) + PAGE_SIZE);
unsigned long end;
for (end = start + PAGE_SIZE; i < addrinarray - 1; end += PAGE_SIZE) { return 0;
if (end != __pa(addr[i + 1]))
break;
i++;
}
free_memtype(start, end);
}
return ret;
} }
EXPORT_SYMBOL(set_memory_array_wb); EXPORT_SYMBOL(set_memory_array_wb);
...@@ -1139,6 +1154,8 @@ int set_pages_array_wb(struct page **pages, int addrinarray) ...@@ -1139,6 +1154,8 @@ int set_pages_array_wb(struct page **pages, int addrinarray)
retval = cpa_clear_pages_array(pages, addrinarray, retval = cpa_clear_pages_array(pages, addrinarray,
__pgprot(_PAGE_CACHE_MASK)); __pgprot(_PAGE_CACHE_MASK));
if (retval)
return retval;
for (i = 0; i < addrinarray; i++) { for (i = 0; i < addrinarray; i++) {
start = (unsigned long)page_address(pages[i]); start = (unsigned long)page_address(pages[i]);
...@@ -1146,7 +1163,7 @@ int set_pages_array_wb(struct page **pages, int addrinarray) ...@@ -1146,7 +1163,7 @@ int set_pages_array_wb(struct page **pages, int addrinarray)
free_memtype(start, end); free_memtype(start, end);
} }
return retval; return 0;
} }
EXPORT_SYMBOL(set_pages_array_wb); EXPORT_SYMBOL(set_pages_array_wb);
......
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