* [PATCH] KVM: x86/xen: fix 32-bit pointer cast
@ 2024-02-22 10:03 Arnd Bergmann
2024-02-22 10:14 ` Paul Durrant
0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2024-02-22 10:03 UTC (permalink / raw)
To: David Woodhouse, Paul Durrant, Sean Christopherson, Paolo Bonzini
Cc: Arnd Bergmann, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin, Jens Axboe, Jan Kara,
Christian Brauner, kvm, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
shared_info.hva is a 64-bit variable, so casting to a pointer causes
a warning in 32-bit builds:
arch/x86/kvm/xen.c: In function 'kvm_xen_hvm_set_attr':
arch/x86/kvm/xen.c:660:45: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
660 | void __user * hva = (void *)data->u.shared_info.hva;
Replace the cast with a u64_to_user_ptr() call that does the right thing.
Fixes: 01a871852b11 ("KVM: x86/xen: allow shared_info to be mapped by fixed HVA")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
arch/x86/kvm/xen.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
index 01c0fd138d2f..8a04e0ae9245 100644
--- a/arch/x86/kvm/xen.c
+++ b/arch/x86/kvm/xen.c
@@ -657,7 +657,7 @@ int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data)
gfn_to_gpa(gfn), PAGE_SIZE);
}
} else {
- void __user * hva = (void *)data->u.shared_info.hva;
+ void __user * hva = u64_to_user_ptr(data->u.shared_info.hva);
if (!PAGE_ALIGNED(hva) || !access_ok(hva, PAGE_SIZE)) {
r = -EINVAL;
--
2.39.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: x86/xen: fix 32-bit pointer cast
2024-02-22 10:03 [PATCH] KVM: x86/xen: fix 32-bit pointer cast Arnd Bergmann
@ 2024-02-22 10:14 ` Paul Durrant
2024-02-22 15:04 ` Sean Christopherson
0 siblings, 1 reply; 3+ messages in thread
From: Paul Durrant @ 2024-02-22 10:14 UTC (permalink / raw)
To: Arnd Bergmann, David Woodhouse, Sean Christopherson,
Paolo Bonzini
Cc: Arnd Bergmann, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, x86, H. Peter Anvin, Jens Axboe, Jan Kara,
Christian Brauner, kvm, linux-kernel
On 22/02/2024 10:03, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> shared_info.hva is a 64-bit variable, so casting to a pointer causes
> a warning in 32-bit builds:
>
> arch/x86/kvm/xen.c: In function 'kvm_xen_hvm_set_attr':
> arch/x86/kvm/xen.c:660:45: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
> 660 | void __user * hva = (void *)data->u.shared_info.hva;
>
> Replace the cast with a u64_to_user_ptr() call that does the right thing.
Thanks Arnd. I'd just got a ping from kernel test robot for lack of
__user qualifier in the cast
(https://lore.kernel.org/oe-kbuild-all/202402221721.mhF8MNVh-lkp@intel.com/),
which this should also fix.
>
> Fixes: 01a871852b11 ("KVM: x86/xen: allow shared_info to be mapped by fixed HVA")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
> arch/x86/kvm/xen.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
Reviewed-by: Paul Durrant <paul@xen.org>
> diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c
> index 01c0fd138d2f..8a04e0ae9245 100644
> --- a/arch/x86/kvm/xen.c
> +++ b/arch/x86/kvm/xen.c
> @@ -657,7 +657,7 @@ int kvm_xen_hvm_set_attr(struct kvm *kvm, struct kvm_xen_hvm_attr *data)
> gfn_to_gpa(gfn), PAGE_SIZE);
> }
> } else {
> - void __user * hva = (void *)data->u.shared_info.hva;
> + void __user * hva = u64_to_user_ptr(data->u.shared_info.hva);
>
> if (!PAGE_ALIGNED(hva) || !access_ok(hva, PAGE_SIZE)) {
> r = -EINVAL;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: x86/xen: fix 32-bit pointer cast
2024-02-22 10:14 ` Paul Durrant
@ 2024-02-22 15:04 ` Sean Christopherson
0 siblings, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2024-02-22 15:04 UTC (permalink / raw)
To: paul
Cc: Arnd Bergmann, David Woodhouse, Paolo Bonzini, Arnd Bergmann,
Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
H. Peter Anvin, Jens Axboe, Jan Kara, Christian Brauner, kvm,
linux-kernel
On Thu, Feb 22, 2024, Paul Durrant wrote:
> On 22/02/2024 10:03, Arnd Bergmann wrote:
> > From: Arnd Bergmann <arnd@arndb.de>
> >
> > shared_info.hva is a 64-bit variable, so casting to a pointer causes
> > a warning in 32-bit builds:
> >
> > arch/x86/kvm/xen.c: In function 'kvm_xen_hvm_set_attr':
> > arch/x86/kvm/xen.c:660:45: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
> > 660 | void __user * hva = (void *)data->u.shared_info.hva;
> >
> > Replace the cast with a u64_to_user_ptr() call that does the right thing.
>
> Thanks Arnd. I'd just got a ping from kernel test robot for lack of __user
> qualifier in the cast
> (https://lore.kernel.org/oe-kbuild-all/202402221721.mhF8MNVh-lkp@intel.com/),
> which this should also fix.
Ya, 'tis a good bot. I squashed this in. Paul/David, new hashes for the
affected commits are below.
Thanks Arnd!
KVM: x86/xen: allow shared_info to be mapped by fixed HVA
https://github.com/kvm-x86/linux/commit/b9220d32799a
KVM: x86/xen: allow vcpu_info to be mapped by fixed HVA
https://github.com/kvm-x86/linux/commit/3991f35805d0
KVM: selftests: map Xen's shared_info page using HVA rather than GFN
https://github.com/kvm-x86/linux/commit/9397b5334af1
KVM: selftests: re-map Xen's vcpu_info using HVA rather than GPA
https://github.com/kvm-x86/linux/commit/b4dfbfdc9538
KVM: x86/xen: advertize the KVM_XEN_HVM_CONFIG_SHARED_INFO_HVA capability
https://github.com/kvm-x86/linux/commit/615451d8cb3f
KVM: pfncache: check the need for invalidation under read lock first
https://github.com/kvm-x86/linux/commit/9fa336e343b2
KVM: x86/xen: allow vcpu_info content to be 'safely' copied
https://github.com/kvm-x86/linux/commit/003d914220c9
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-02-22 15:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-22 10:03 [PATCH] KVM: x86/xen: fix 32-bit pointer cast Arnd Bergmann
2024-02-22 10:14 ` Paul Durrant
2024-02-22 15:04 ` Sean Christopherson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).