From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PATCH v2 13/14] KVM: x86: don't assume layout of kvm_kpit_state Date: Wed, 17 Feb 2016 20:14:55 +0100 Message-ID: <1455736496-374-14-git-send-email-rkrcmar@redhat.com> References: <1455736496-374-1-git-send-email-rkrcmar@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: kvm@vger.kernel.org, Paolo Bonzini , Yuki Shibuya To: linux-kernel@vger.kernel.org Return-path: In-Reply-To: <1455736496-374-1-git-send-email-rkrcmar@redhat.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org channels has offset 0 and correct size now, but that can change. Signed-off-by: Radim Kr=C4=8Dm=C3=A1=C5=99 --- v2: new arch/x86/kvm/x86.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 785cc781673d..c688a99da5ba 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3628,9 +3628,13 @@ static int kvm_vm_ioctl_set_irqchip(struct kvm *= kvm, struct kvm_irqchip *chip) =20 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 =3D &kvm->arch.vpit->pit_state; + + BUILD_BUG_ON(sizeof(*ps) !=3D sizeof(kps->channels)); + + mutex_lock(&kps->lock); + memcpy(ps, &kps->channels, sizeof(*ps)); + mutex_unlock(&kps->lock); return 0; } =20 @@ -3640,7 +3644,7 @@ static int kvm_vm_ioctl_set_pit(struct kvm *kvm, = struct kvm_pit_state *ps) struct kvm_pit *pit =3D kvm->arch.vpit; =20 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 =3D 0; i < 3; i++) kvm_pit_load_count(pit, i, ps->channels[i].count, 0); mutex_unlock(&pit->pit_state.lock); --=20 2.7.1