qemu/target/i386/kvm
Johannes Stoelp 6a8703aecb kvm: Use 'unsigned long' for request argument in functions wrapping ioctl()
Change the data type of the ioctl _request_ argument from 'int' to
'unsigned long' for the various accel/kvm functions which are
essentially wrappers around the ioctl() syscall.

The correct type for ioctl()'s 'request' argument is confused:
 * POSIX defines the request argument as 'int'
 * glibc uses 'unsigned long' in the prototype in sys/ioctl.h
 * the glibc info documentation uses 'int'
 * the Linux manpage uses 'unsigned long'
 * the Linux implementation of the syscall uses 'unsigned int'

If we wrap ioctl() with another function which uses 'int' as the
type for the request argument, then requests with the 0x8000_0000
bit set will be sign-extended when the 'int' is cast to
'unsigned long' for the call to ioctl().

On x86_64 one such example is the KVM_IRQ_LINE_STATUS request.
Bit requests with the _IOC_READ direction bit set, will have the high
bit set.

Fortunately the Linux Kernel truncates the upper 32bit of the request
on 64bit machines (because it uses 'unsigned int', and see also Linus
Torvalds' comments in
  https://sourceware.org/bugzilla/show_bug.cgi?id=14362 )
so this doesn't cause active problems for us.  However it is more
consistent to follow the glibc ioctl() prototype when we define
functions that are essentially wrappers around ioctl().

This resolves a Coverity issue where it points out that in
kvm_get_xsave() we assign a value (KVM_GET_XSAVE or KVM_GET_XSAVE2)
to an 'int' variable which can't hold it without overflow.

Resolves: Coverity CID 1547759
Signed-off-by: Johannes Stoelp <johannes.stoelp@gmail.com>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 20240815122747.3053871-1-peter.maydell@linaro.org
[PMM: Rebased patch, adjusted commit message, included note about
 Coverity fix, updated the type of the local var in kvm_get_xsave,
 updated the comment in the KVMState struct definition]
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2024-09-13 15:31:46 +01:00
..
hyperv-proto.h i386: Hyper-V Direct TLB flush hypercall 2022-05-25 21:26:35 +02:00
hyperv-stub.c vmbus: Print a warning when enabled without the recommended set of features 2024-03-08 14:18:56 +01:00
hyperv.c target-i386: hyper-v: Correct kvm_hv_handle_exit return value 2024-05-22 19:56:28 +02:00
hyperv.h vmbus: Print a warning when enabled without the recommended set of features 2024-03-08 14:18:56 +01:00
kvm_i386.h i386/kvm: Add KVM_EXIT_HYPERCALL handling for KVM_HC_MAP_GPA_RANGE 2024-06-05 11:01:06 +02:00
kvm-cpu.c target/i386: pass X86CPU to x86_cpu_get_supported_feature_word 2024-07-03 18:41:26 +02:00
kvm.c kvm: Use 'unsigned long' for request argument in functions wrapping ioctl() 2024-09-13 15:31:46 +01:00
meson.build Add support for RAPL MSRs in KVM/Qemu 2024-07-22 19:19:37 +02:00
trace-events i386/kvm: Add KVM_EXIT_HYPERCALL handling for KVM_HC_MAP_GPA_RANGE 2024-06-05 11:01:06 +02:00
trace.h
vmsr_energy.c target/i386: Clean up error cases for vmsr_read_thread_stat() 2024-07-31 13:13:31 +02:00
vmsr_energy.h Add support for RAPL MSRs in KVM/Qemu 2024-07-22 19:19:37 +02:00
xen-compat.h i386/xen: Implement HYPERVISOR_physdev_op 2023-03-01 09:08:26 +00:00
xen-emu.c hw/i386/fw_cfg: Add etc/e820 to fw_cfg late 2024-07-03 18:14:06 -04:00
xen-emu.h hw/xen: Support HVM_PARAM_CALLBACK_TYPE_GSI callback 2023-03-01 09:06:44 +00:00