All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: x86/mmu: Avoid mixing gpa_t with gfn_t in walk_addr_generic()
@ 2020-06-22 15:14 Vitaly Kuznetsov
  2020-06-22 17:04 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Vitaly Kuznetsov @ 2020-06-22 15:14 UTC (permalink / raw)
  To: kvm
  Cc: Paolo Bonzini, Sean Christopherson, Wanpeng Li, Jim Mattson,
	linux-kernel

translate_gpa() returns a GPA, assigning it to 'real_gfn' seems obviously
wrong. There is no real issue because both 'gpa_t' and 'gfn_t' are u64 and
we don't use the value in 'real_gfn' as a GFN, we do

 real_gfn = gpa_to_gfn(real_gfn);

instead. 'If you see a "buffalo" sign on an elephant's cage, do not trust
your eyes', but let's fix it for good.

No functional change intended.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
---
 arch/x86/kvm/mmu/paging_tmpl.h | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h
index a6d484ea110b..58234bfaca07 100644
--- a/arch/x86/kvm/mmu/paging_tmpl.h
+++ b/arch/x86/kvm/mmu/paging_tmpl.h
@@ -360,7 +360,6 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
 	++walker->level;
 
 	do {
-		gfn_t real_gfn;
 		unsigned long host_addr;
 
 		pt_access = pte_access;
@@ -375,7 +374,7 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
 		walker->table_gfn[walker->level - 1] = table_gfn;
 		walker->pte_gpa[walker->level - 1] = pte_gpa;
 
-		real_gfn = mmu->translate_gpa(vcpu, gfn_to_gpa(table_gfn),
+		real_gpa = mmu->translate_gpa(vcpu, gfn_to_gpa(table_gfn),
 					      nested_access,
 					      &walker->fault);
 
@@ -389,12 +388,10 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
 		 * information to fix the exit_qualification or exit_info_1
 		 * fields.
 		 */
-		if (unlikely(real_gfn == UNMAPPED_GVA))
+		if (unlikely(real_gpa == UNMAPPED_GVA))
 			return 0;
 
-		real_gfn = gpa_to_gfn(real_gfn);
-
-		host_addr = kvm_vcpu_gfn_to_hva_prot(vcpu, real_gfn,
+		host_addr = kvm_vcpu_gfn_to_hva_prot(vcpu, gpa_to_gfn(real_gpa),
 					    &walker->pte_writable[walker->level - 1]);
 		if (unlikely(kvm_is_error_hva(host_addr)))
 			goto error;
-- 
2.25.4


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

* Re: [PATCH] KVM: x86/mmu: Avoid mixing gpa_t with gfn_t in walk_addr_generic()
  2020-06-22 15:14 [PATCH] KVM: x86/mmu: Avoid mixing gpa_t with gfn_t in walk_addr_generic() Vitaly Kuznetsov
@ 2020-06-22 17:04 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2020-06-22 17:04 UTC (permalink / raw)
  To: Vitaly Kuznetsov, kvm
  Cc: Sean Christopherson, Wanpeng Li, Jim Mattson, linux-kernel

On 22/06/20 17:14, Vitaly Kuznetsov wrote:
> translate_gpa() returns a GPA, assigning it to 'real_gfn' seems obviously
> wrong. There is no real issue because both 'gpa_t' and 'gfn_t' are u64 and
> we don't use the value in 'real_gfn' as a GFN, we do
> 
>  real_gfn = gpa_to_gfn(real_gfn);
> 
> instead. 'If you see a "buffalo" sign on an elephant's cage, do not trust
> your eyes', but let's fix it for good.
> 
> No functional change intended.
> 
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> ---
>  arch/x86/kvm/mmu/paging_tmpl.h | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h
> index a6d484ea110b..58234bfaca07 100644
> --- a/arch/x86/kvm/mmu/paging_tmpl.h
> +++ b/arch/x86/kvm/mmu/paging_tmpl.h
> @@ -360,7 +360,6 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
>  	++walker->level;
>  
>  	do {
> -		gfn_t real_gfn;
>  		unsigned long host_addr;
>  
>  		pt_access = pte_access;
> @@ -375,7 +374,7 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
>  		walker->table_gfn[walker->level - 1] = table_gfn;
>  		walker->pte_gpa[walker->level - 1] = pte_gpa;
>  
> -		real_gfn = mmu->translate_gpa(vcpu, gfn_to_gpa(table_gfn),
> +		real_gpa = mmu->translate_gpa(vcpu, gfn_to_gpa(table_gfn),
>  					      nested_access,
>  					      &walker->fault);
>  
> @@ -389,12 +388,10 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
>  		 * information to fix the exit_qualification or exit_info_1
>  		 * fields.
>  		 */
> -		if (unlikely(real_gfn == UNMAPPED_GVA))
> +		if (unlikely(real_gpa == UNMAPPED_GVA))
>  			return 0;
>  
> -		real_gfn = gpa_to_gfn(real_gfn);
> -
> -		host_addr = kvm_vcpu_gfn_to_hva_prot(vcpu, real_gfn,
> +		host_addr = kvm_vcpu_gfn_to_hva_prot(vcpu, gpa_to_gfn(real_gpa),
>  					    &walker->pte_writable[walker->level - 1]);
>  		if (unlikely(kvm_is_error_hva(host_addr)))
>  			goto error;
> 

Queued, thanks.

Paolo


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

end of thread, other threads:[~2020-06-22 17:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-22 15:14 [PATCH] KVM: x86/mmu: Avoid mixing gpa_t with gfn_t in walk_addr_generic() Vitaly Kuznetsov
2020-06-22 17:04 ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.