public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm: allow RO page when atomic && !write_fault
@ 2011-02-21  3:47 Lai Jiangshan
  2011-02-21  9:47 ` Gleb Natapov
  2011-02-22 19:24 ` Marcelo Tosatti
  0 siblings, 2 replies; 4+ messages in thread
From: Lai Jiangshan @ 2011-02-21  3:47 UTC (permalink / raw)
  To: kvm@vger.kernel.org, LKML, Avi Kivity, Marcelo Tosatti


Atomic-able hva_to_pfn() patches and allow-read-only-page patches
are merged almost the same time. But hva_to_pfn() does not handle
these two issues well together.

When @atomic && !@write_fault && host-is-read-only-page-mapped
the code will return fault_page, actually, it will be better
if we return the pfn of the read-only-page.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 1fa0d29..f49cfc0 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1060,31 +1060,27 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,
 	BUG_ON(!write_fault && !writable);
 
 	if (writable)
-		*writable = true;
+		*writable = write_fault;
 
 	if (atomic || async)
-		npages = __get_user_pages_fast(addr, 1, 1, page);
+		npages = __get_user_pages_fast(addr, 1, write_fault, page);
 
 	if (unlikely(npages != 1) && !atomic) {
 		might_sleep();
-
-		if (writable)
-			*writable = write_fault;
-
 		npages = get_user_pages_fast(addr, 1, write_fault, page);
+	}
 
-		/* map read fault as writable if possible */
-		if (unlikely(!write_fault) && npages == 1) {
-			struct page *wpage[1];
+	/* map read fault as writable if possible */
+	if (unlikely(!write_fault) && npages == 1) {
+		struct page *wpage[1];
 
-			npages = __get_user_pages_fast(addr, 1, 1, wpage);
-			if (npages == 1) {
-				*writable = true;
-				put_page(page[0]);
-				page[0] = wpage[0];
-			}
-			npages = 1;
+		npages = __get_user_pages_fast(addr, 1, 1, wpage);
+		if (npages == 1) {
+			*writable = true;
+			put_page(page[0]);
+			page[0] = wpage[0];
 		}
+		npages = 1;
 	}
 
 	if (unlikely(npages != 1)) {

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] kvm: allow RO page when atomic && !write_fault
  2011-02-21  3:47 [PATCH] kvm: allow RO page when atomic && !write_fault Lai Jiangshan
@ 2011-02-21  9:47 ` Gleb Natapov
  2011-02-22  8:24   ` Lai Jiangshan
  2011-02-22 19:24 ` Marcelo Tosatti
  1 sibling, 1 reply; 4+ messages in thread
From: Gleb Natapov @ 2011-02-21  9:47 UTC (permalink / raw)
  To: Lai Jiangshan; +Cc: kvm@vger.kernel.org, LKML, Avi Kivity, Marcelo Tosatti

On Mon, Feb 21, 2011 at 11:47:36AM +0800, Lai Jiangshan wrote:
> 
> Atomic-able hva_to_pfn() patches and allow-read-only-page patches
> are merged almost the same time. But hva_to_pfn() does not handle
> these two issues well together.
> 
> When @atomic && !@write_fault && host-is-read-only-page-mapped
> the code will return fault_page, actually, it will be better
> if we return the pfn of the read-only-page.
> 
This patch will conflict with not yet applied https://lkml.org/lkml/2011/2/1/94
What it the status of that patch?

> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
> ---
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 1fa0d29..f49cfc0 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -1060,31 +1060,27 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,
>  	BUG_ON(!write_fault && !writable);
>  
>  	if (writable)
> -		*writable = true;
> +		*writable = write_fault;
>  
>  	if (atomic || async)
> -		npages = __get_user_pages_fast(addr, 1, 1, page);
> +		npages = __get_user_pages_fast(addr, 1, write_fault, page);
>  
>  	if (unlikely(npages != 1) && !atomic) {
>  		might_sleep();
> -
> -		if (writable)
> -			*writable = write_fault;
> -
>  		npages = get_user_pages_fast(addr, 1, write_fault, page);
> +	}
>  
> -		/* map read fault as writable if possible */
> -		if (unlikely(!write_fault) && npages == 1) {
> -			struct page *wpage[1];
> +	/* map read fault as writable if possible */
> +	if (unlikely(!write_fault) && npages == 1) {
> +		struct page *wpage[1];
>  
> -			npages = __get_user_pages_fast(addr, 1, 1, wpage);
> -			if (npages == 1) {
> -				*writable = true;
> -				put_page(page[0]);
> -				page[0] = wpage[0];
> -			}
> -			npages = 1;
> +		npages = __get_user_pages_fast(addr, 1, 1, wpage);
> +		if (npages == 1) {
> +			*writable = true;
> +			put_page(page[0]);
> +			page[0] = wpage[0];
>  		}
> +		npages = 1;
>  	}
>  
>  	if (unlikely(npages != 1)) {
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

--
			Gleb.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kvm: allow RO page when atomic && !write_fault
  2011-02-21  9:47 ` Gleb Natapov
@ 2011-02-22  8:24   ` Lai Jiangshan
  0 siblings, 0 replies; 4+ messages in thread
From: Lai Jiangshan @ 2011-02-22  8:24 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: kvm@vger.kernel.org, LKML, Avi Kivity, Marcelo Tosatti

On 02/21/2011 05:47 PM, Gleb Natapov wrote:
> On Mon, Feb 21, 2011 at 11:47:36AM +0800, Lai Jiangshan wrote:
>>
>> Atomic-able hva_to_pfn() patches and allow-read-only-page patches
>> are merged almost the same time. But hva_to_pfn() does not handle
>> these two issues well together.
>>
>> When @atomic && !@write_fault && host-is-read-only-page-mapped
>> the code will return fault_page, actually, it will be better
>> if we return the pfn of the read-only-page.
>>
> This patch will conflict with not yet applied https://lkml.org/lkml/2011/2/1/94
> What it the status of that patch?

I will update/resend this patch after the patch you referred applied.

Thanks,
Lai

> 
>> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
>> ---
>> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
>> index 1fa0d29..f49cfc0 100644
>> --- a/virt/kvm/kvm_main.c
>> +++ b/virt/kvm/kvm_main.c
>> @@ -1060,31 +1060,27 @@ static pfn_t hva_to_pfn(struct kvm *kvm, unsigned long addr, bool atomic,
>>  	BUG_ON(!write_fault && !writable);
>>  
>>  	if (writable)
>> -		*writable = true;
>> +		*writable = write_fault;
>>  
>>  	if (atomic || async)
>> -		npages = __get_user_pages_fast(addr, 1, 1, page);
>> +		npages = __get_user_pages_fast(addr, 1, write_fault, page);
>>  
>>  	if (unlikely(npages != 1) && !atomic) {
>>  		might_sleep();
>> -
>> -		if (writable)
>> -			*writable = write_fault;
>> -
>>  		npages = get_user_pages_fast(addr, 1, write_fault, page);
>> +	}
>>  
>> -		/* map read fault as writable if possible */
>> -		if (unlikely(!write_fault) && npages == 1) {
>> -			struct page *wpage[1];
>> +	/* map read fault as writable if possible */
>> +	if (unlikely(!write_fault) && npages == 1) {
>> +		struct page *wpage[1];
>>  
>> -			npages = __get_user_pages_fast(addr, 1, 1, wpage);
>> -			if (npages == 1) {
>> -				*writable = true;
>> -				put_page(page[0]);
>> -				page[0] = wpage[0];
>> -			}
>> -			npages = 1;
>> +		npages = __get_user_pages_fast(addr, 1, 1, wpage);
>> +		if (npages == 1) {
>> +			*writable = true;
>> +			put_page(page[0]);
>> +			page[0] = wpage[0];
>>  		}
>> +		npages = 1;
>>  	}
>>  
>>  	if (unlikely(npages != 1)) {
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to majordomo@vger.kernel.org
>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at  http://www.tux.org/lkml/
> 
> --
> 			Gleb.
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kvm: allow RO page when atomic && !write_fault
  2011-02-21  3:47 [PATCH] kvm: allow RO page when atomic && !write_fault Lai Jiangshan
  2011-02-21  9:47 ` Gleb Natapov
@ 2011-02-22 19:24 ` Marcelo Tosatti
  1 sibling, 0 replies; 4+ messages in thread
From: Marcelo Tosatti @ 2011-02-22 19:24 UTC (permalink / raw)
  To: Lai Jiangshan; +Cc: kvm@vger.kernel.org, LKML, Avi Kivity

On Mon, Feb 21, 2011 at 11:47:36AM +0800, Lai Jiangshan wrote:
> 
> Atomic-able hva_to_pfn() patches and allow-read-only-page patches
> are merged almost the same time. But hva_to_pfn() does not handle
> these two issues well together.
> 
> When @atomic && !@write_fault && host-is-read-only-page-mapped
> the code will return fault_page, actually, it will be better
> if we return the pfn of the read-only-page.
> 
> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>

Lai,

For pte prefetch, user of atomic hva_to_pfn, the write_fault parameter
is meaningless (since that information is only available for the pte
being faulted).

Returning fault page for a read-only page is useful so that pte prefetch
is aborted.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-02-22 20:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-21  3:47 [PATCH] kvm: allow RO page when atomic && !write_fault Lai Jiangshan
2011-02-21  9:47 ` Gleb Natapov
2011-02-22  8:24   ` Lai Jiangshan
2011-02-22 19:24 ` Marcelo Tosatti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox