Re: [PATCH] Fix kunmap() argument in sg_miter_stop

Jeremy Fitzhardinge
2008-11-17T17:35:20Z

Linus Torvalds wrote:
> On Mon, 17 Nov 2008, Jeremy Fitzhardinge wrote:
>
>
>> Pass the struct page * to kunmap, not the vaddr of the mapping itself.
>>
>> Pointed out by Jens Axboe <jens.axboe@oracle.com>
>>
>> Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
>> ---
>> drivers/xen/balloon.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> ===================================================================
>> --- a/drivers/xen/balloon.c
>> +++ b/drivers/xen/balloon.c
>> @@ -120,7 +120,7 @@
>> if (PageHighMem(page)) {
>> void *v = kmap(page);
>> clear_page(v);
>> - kunmap(v);
>> + kunmap(page);
>> } else {
>> void *v = page_address(page);
>> clear_page(v);
>>
>
> Well, quite frankly, the whole thing looks like crud.
>
> First off, 'kmap/kunmap' work on regular pages too. So if you're highmem
> aware, you should just do
>
> void *v = kmap(page);
> clear_page(v);
> kunmap(page);
>
> and be done with it.
>
> Secondly, we actually have a function called "clear_highpage()" that does
> this, except it uses kmap_atomic(page, KM_USER0). Which is _probably
> better anyway, but I didn't check if there is some magical reason why it
> wouldn't work.
>

OK.

Subject: xen/balloon: use clear_highpage()

Just use clear_highpage() rather than reimplementing it poorly.

Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
---
drivers/xen/balloon.c | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)

===================================================================
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -122,14 +122,7 @@
static void scrub_page(struct page *page)
{
#ifdef CONFIG_XEN_SCRUB_PAGES
- if (PageHighMem(page)) {
- void *v = kmap(page);
- clear_page(v);
- kunmap(v);
- } else {
- void *v = page_address(page);
- clear_page(v);
- }
+ clear_highpage(page);
#endif
}