diff options
author | Radim Krčmář <rkrcmar@redhat.com> | 2016-03-02 22:56:50 +0100 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2016-03-04 09:30:18 +0100 |
commit | 34f3941c42e22217e39f442e15401ae53a23f8cb (patch) | |
tree | fc8d5b3332e9466cd85e4095090b79070ada9e48 /arch/x86/kvm/x86.c | |
parent | 4a2095df8ab1671078c46d988e1b83baf42db4f6 (diff) | |
download | lwn-34f3941c42e22217e39f442e15401ae53a23f8cb.tar.gz lwn-34f3941c42e22217e39f442e15401ae53a23f8cb.zip |
KVM: i8254: don't assume layout of kvm_kpit_state
channels has offset 0 and correct size now, but that can change.
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r-- | arch/x86/kvm/x86.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 76f9f48898a5..60d6c0036a98 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3604,9 +3604,13 @@ static int kvm_vm_ioctl_set_irqchip(struct kvm *kvm, struct kvm_irqchip *chip) static int kvm_vm_ioctl_get_pit(struct kvm *kvm, struct kvm_pit_state *ps) { - mutex_lock(&kvm->arch.vpit->pit_state.lock); - memcpy(ps, &kvm->arch.vpit->pit_state, sizeof(struct kvm_pit_state)); - mutex_unlock(&kvm->arch.vpit->pit_state.lock); + struct kvm_kpit_state *kps = &kvm->arch.vpit->pit_state; + + BUILD_BUG_ON(sizeof(*ps) != sizeof(kps->channels)); + + mutex_lock(&kps->lock); + memcpy(ps, &kps->channels, sizeof(*ps)); + mutex_unlock(&kps->lock); return 0; } @@ -3616,7 +3620,7 @@ static int kvm_vm_ioctl_set_pit(struct kvm *kvm, struct kvm_pit_state *ps) struct kvm_pit *pit = kvm->arch.vpit; mutex_lock(&pit->pit_state.lock); - memcpy(&pit->pit_state, ps, sizeof(struct kvm_pit_state)); + memcpy(&pit->pit_state.channels, ps, sizeof(*ps)); for (i = 0; i < 3; i++) kvm_pit_load_count(pit, i, ps->channels[i].count, 0); mutex_unlock(&pit->pit_state.lock); |