Skip to contentSkip to conversation

KVM: x86/xen: Use hva_t for holding hypercall page address

PATCH Applied Sean Christopherson 4 participants 4 messages Feb 8, 2021 – Feb 9, 2021

Subsystems (4)
lore
Share & tools
lore

Sean Christopherson

author maintainer
#0 lore raw

PATCH 1/1 KVM: x86/xen: Use hva_t for holding hypercall page address

Use hva_t, a.k.a. unsigned long, for the local variable that holds the hypercall page address. On 32-bit KVM, gcc complains about using a u64 due to the implicit cast from a 64-bit value to a 32-bit pointer.

arch/x86/kvm/xen.c: In function ‘kvm_xen_write_hypercall_page’:
arch/x86/kvm/xen.c:300:22: error: cast to pointer from integer of
different size [-Werror=int-to-pointer-cast]
300 | page = memdup_user((u8 __user *)blob_addr, PAGE_SIZE);

Cc Joao Martins <[email protected]>
Cc David Woodhouse <[email protected]>
Fixes 23200b7a30de ("KVM: x86/xen: intercept xen hypercalls if enabled")
---
 arch/x86/kvm/xen.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/x86/kvm/xen.c +6 -2
index 2cee0376455c..deda1ba8c18a 100644
@@ -286,8 +286,12 @@ int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data)
 				return 1;
 		}
 	} else {
-		u64 blob_addr = lm ? kvm->arch.xen_hvm_config.blob_addr_64
-				   : kvm->arch.xen_hvm_config.blob_addr_32;
+		/*
+		 * Note, truncation is a non-issue as 'lm' is guaranteed to be
+		 * false for a 32-bit kernel, i.e. when hva_t is only 4 bytes.
+		 */
+		hva_t blob_addr = lm ? kvm->arch.xen_hvm_config.blob_addr_64
+				     : kvm->arch.xen_hvm_config.blob_addr_32;
 		u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
 				  : kvm->arch.xen_hvm_config.blob_size_32;
 		u8 *page;
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Sean Christopherson

Use hva_t, a.k.a. unsigned long, for the local variable that holds the hypercall page address. On 32-bit KVM, gcc complains about using a u64 due to the implicit cast from a 64-bit value to a 32-bit pointer.

arch/x86/kvm/xen.c: In function ‘kvm_xen_write_hypercall_page’:
arch/x86/kvm/xen.c:300:22: error: cast to pointer from integer of
different size [-Werror=int-to-pointer-cast]
300 | page = memdup_user((u8 __user *)blob_addr, PAGE_SIZE);

Thanks.

Quoted 28 lines
Cc Joao Martins <[email protected]>
Cc David Woodhouse <[email protected]>
Fixes 23200b7a30de ("KVM: x86/xen: intercept xen hypercalls if enabled")
---
 arch/x86/kvm/xen.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/x86/kvm/xen.c +6 -3
index 2cee0376455c..deda1ba8c18a 100644
@@ -286,8 +286,12 @@ int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data)
                                return 1;
                }
        } else {
-               u64 blob_addr = lm ? kvm->arch.xen_hvm_config.blob_addr_64
-                                  : kvm->arch.xen_hvm_config.blob_addr_32;
+               /*
+                * Note, truncation is a non-issue as 'lm' is guaranteed to be
+                * false for a 32-bit kernel, i.e. when hva_t is only 4 bytes.
+                */
+               hva_t blob_addr = lm ? kvm->arch.xen_hvm_config.blob_addr_64
+                                    : kvm->arch.xen_hvm_config.blob_addr_32;
                u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
                                  : kvm->arch.xen_hvm_config.blob_size_32;
                u8 *page;
--
Quoted 2 lines

2.30.0.478.g8a0d178c01-goog

Amazon Development Centre (London) Ltd. Registered in England and Wales with registration number 04543232 with its registered office at 1 Principal Place, Worship Street, London EC2A 2FA, United Kingdom.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Sean Christopherson
Quoted 9 lines · Sean Christopherson

Use hva_t, a.k.a. unsigned long, for the local variable that holds the hypercall page address. On 32-bit KVM, gcc complains about using a u64 due to the implicit cast from a 64-bit value to a 32-bit pointer.

arch/x86/kvm/xen.c: In function ‘kvm_xen_write_hypercall_page’:
arch/x86/kvm/xen.c:300:22: error: cast to pointer from integer of
different size [-Werror=int-to-pointer-cast]
300 | page = memdup_user((u8 __user *)blob_addr, PAGE_SIZE);

Quoted 4 lines
Cc Joao Martins <[email protected]>
Cc David Woodhouse <[email protected]>
Fixes 23200b7a30de ("KVM: x86/xen: intercept xen hypercalls if enabled")
Quoted 24 lines
---
 arch/x86/kvm/xen.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
arch/x86/kvm/xen.c +6 -2
index 2cee0376455c..deda1ba8c18a 100644
@@ -286,8 +286,12 @@ int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data)
 				return 1;
 		}
 	} else {
-		u64 blob_addr = lm ? kvm->arch.xen_hvm_config.blob_addr_64
-				   : kvm->arch.xen_hvm_config.blob_addr_32;
+		/*
+		 * Note, truncation is a non-issue as 'lm' is guaranteed to be
+		 * false for a 32-bit kernel, i.e. when hva_t is only 4 bytes.
+		 */
+		hva_t blob_addr = lm ? kvm->arch.xen_hvm_config.blob_addr_64
+				     : kvm->arch.xen_hvm_config.blob_addr_32;
 		u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
 				  : kvm->arch.xen_hvm_config.blob_size_32;
 		u8 *page;
maintainer Applied
#3 lore raw
In reply to Sean Christopherson
Quoted 27 lines · Sean Christopherson

Use hva_t, a.k.a. unsigned long, for the local variable that holds the hypercall page address. On 32-bit KVM, gcc complains about using a u64 due to the implicit cast from a 64-bit value to a 32-bit pointer.

arch/x86/kvm/xen.c: In function ‘kvm_xen_write_hypercall_page’:
arch/x86/kvm/xen.c:300:22: error: cast to pointer from integer of
different size [-Werror=int-to-pointer-cast]
300 | page = memdup_user((u8 __user *)blob_addr, PAGE_SIZE);

Cc Joao Martins <[email protected]>
Cc David Woodhouse <[email protected]>
Fixes 23200b7a30de ("KVM: x86/xen: intercept xen hypercalls if enabled")
---
  arch/x86/kvm/xen.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
arch/x86/kvm/xen.c +0 -1
index 2cee0376455c..deda1ba8c18a 100644
@@ -286,8 +286,12 @@ int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data)
  				return 1;
  		}
  	} else {
-		u64 blob_addr = lm ? kvm->arch.xen_hvm_config.blob_addr_64

arch/x86/kvm/xen.c int kvm_xen_write_hypercall_page(struct kvm_vcpu *vcpu, u64 data) · line 297

Quoted 10 lines
arch/x86/kvm/xen.c +6 -1
-				   : kvm->arch.xen_hvm_config.blob_addr_32;
+		/*
+		 * Note, truncation is a non-issue as 'lm' is guaranteed to be
+		 * false for a 32-bit kernel, i.e. when hva_t is only 4 bytes.
+		 */
+		hva_t blob_addr = lm ? kvm->arch.xen_hvm_config.blob_addr_64
+				     : kvm->arch.xen_hvm_config.blob_addr_32;
  		u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
  				  : kvm->arch.xen_hvm_config.blob_size_32;
  		u8 *page;

Queued, thanks.

Paolo