Skip to content

Commit bb64da9

Browse files
committed
KVM: s390: mark irq_state.flags as non-usable
Old kernels did not check for zero in the irq_state.flags field and old QEMUs did not zero the flag/reserved fields when calling KVM_S390_*_IRQ_STATE. Let's add comments to prevent future uses of these fields. Signed-off-by: Christian Borntraeger <[email protected]> Reviewed-by: Thomas Huth <[email protected]> Reviewed-by: Cornelia Huck <[email protected]> Reviewed-by: David Hildenbrand <[email protected]> Signed-off-by: Christian Borntraeger <[email protected]>
1 parent 940f89a commit bb64da9

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

Documentation/virtual/kvm/api.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2901,14 +2901,19 @@ userspace buffer and its length:
29012901

29022902
struct kvm_s390_irq_state {
29032903
__u64 buf;
2904-
__u32 flags;
2904+
__u32 flags; /* will stay unused for compatibility reasons */
29052905
__u32 len;
2906-
__u32 reserved[4];
2906+
__u32 reserved[4]; /* will stay unused for compatibility reasons */
29072907
};
29082908

29092909
Userspace passes in the above struct and for each pending interrupt a
29102910
struct kvm_s390_irq is copied to the provided buffer.
29112911

2912+
The structure contains a flags and a reserved field for future extensions. As
2913+
the kernel never checked for flags == 0 and QEMU never pre-zeroed flags and
2914+
reserved, these fields can not be used in the future without breaking
2915+
compatibility.
2916+
29122917
If -ENOBUFS is returned the buffer provided was too small and userspace
29132918
may retry with a bigger buffer.
29142919

@@ -2932,10 +2937,14 @@ containing a struct kvm_s390_irq_state:
29322937

29332938
struct kvm_s390_irq_state {
29342939
__u64 buf;
2940+
__u32 flags; /* will stay unused for compatibility reasons */
29352941
__u32 len;
2936-
__u32 pad;
2942+
__u32 reserved[4]; /* will stay unused for compatibility reasons */
29372943
};
29382944

2945+
The restrictions for flags and reserved apply as well.
2946+
(see KVM_S390_GET_IRQ_STATE)
2947+
29392948
The userspace memory referenced by buf contains a struct kvm_s390_irq
29402949
for each interrupt to be injected into the guest.
29412950
If one of the interrupts could not be injected for some reason the

arch/s390/kvm/kvm-s390.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// SPDX-License-Identifier: GPL-2.0
22
/*
3-
* hosting zSeries kernel virtual machines
3+
* hosting IBM Z kernel virtual machines (s390x)
44
*
5-
* Copyright IBM Corp. 2008, 2009
5+
* Copyright IBM Corp. 2008, 2017
66
*
77
* Author(s): Carsten Otte <[email protected]>
88
* Christian Borntraeger <[email protected]>
@@ -3808,6 +3808,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
38083808
r = -EINVAL;
38093809
break;
38103810
}
3811+
/* do not use irq_state.flags, it will break old QEMUs */
38113812
r = kvm_s390_set_irq_state(vcpu,
38123813
(void __user *) irq_state.buf,
38133814
irq_state.len);
@@ -3823,6 +3824,7 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
38233824
r = -EINVAL;
38243825
break;
38253826
}
3827+
/* do not use irq_state.flags, it will break old QEMUs */
38263828
r = kvm_s390_get_irq_state(vcpu,
38273829
(__u8 __user *) irq_state.buf,
38283830
irq_state.len);

include/uapi/linux/kvm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,9 @@ struct kvm_s390_irq {
630630

631631
struct kvm_s390_irq_state {
632632
__u64 buf;
633-
__u32 flags;
633+
__u32 flags; /* will stay unused for compatibility reasons */
634634
__u32 len;
635-
__u32 reserved[4];
635+
__u32 reserved[4]; /* will stay unused for compatibility reasons */
636636
};
637637

638638
/* for KVM_SET_GUEST_DEBUG */

0 commit comments

Comments
 (0)