From: "Jan Beulich" Subject: [PATCH] x86/HVM: 32-bit IN result must be zero-extended to 64 bits Date: Tue, 05 Nov 2013 08:46:53 +0000 Message-ID: <5278BE8D02000078000FF631@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part9FACB86D.0__=" Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VdcHs-00040L-AC for xen-devel@lists.xenproject.org; Tue, 05 Nov 2013 08:47:00 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Keir Fraser List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part9FACB86D.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Just like for all other operations with 32-bit operand size. Signed-off-by: Jan Beulich --- a/xen/arch/x86/hvm/io.c +++ b/xen/arch/x86/hvm/io.c @@ -221,13 +221,15 @@ int handle_mmio_with_translation(unsigne return handle_mmio(); } =20 -int handle_pio(uint16_t port, int size, int dir) +int handle_pio(uint16_t port, unsigned int size, int dir) { struct vcpu *curr =3D current; struct hvm_vcpu_io *vio =3D &curr->arch.hvm_vcpu.hvm_io; unsigned long data, reps =3D 1; int rc; =20 + ASSERT((size - 1) < 4 && size !=3D 3); + if ( dir =3D=3D IOREQ_WRITE ) data =3D guest_cpu_user_regs()->eax; =20 @@ -237,7 +239,12 @@ int handle_pio(uint16_t port, int size,=20 { case X86EMUL_OKAY: if ( dir =3D=3D IOREQ_READ ) - memcpy(&guest_cpu_user_regs()->eax, &data, vio->io_size); + { + if ( size =3D=3D 4 ) /* Needs zero extension. */ + guest_cpu_user_regs()->eax =3D (uint32_t)data; + else + memcpy(&guest_cpu_user_regs()->eax, &data, size); + } break; case X86EMUL_RETRY: if ( vio->io_state !=3D HVMIO_awaiting_completion ) --- a/xen/include/asm-x86/hvm/io.h +++ b/xen/include/asm-x86/hvm/io.h @@ -119,7 +119,7 @@ void send_timeoffset_req(unsigned long t void send_invalidate_req(void); int handle_mmio(void); int handle_mmio_with_translation(unsigned long gva, unsigned long gpfn); -int handle_pio(uint16_t port, int size, int dir); +int handle_pio(uint16_t port, unsigned int size, int dir); void hvm_interrupt_post(struct vcpu *v, int vector, int type); void hvm_io_assist(void); void hvm_dpci_eoi(struct domain *d, unsigned int guest_irq, --=__Part9FACB86D.0__= Content-Type: text/plain; name="x86-HVM-PIO-zero-extend.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-HVM-PIO-zero-extend.patch" x86/HVM: 32-bit IN result must be zero-extended to 64 bits=0A=0AJust like = for all other operations with 32-bit operand size.=0A=0ASigned-off-by: Jan = Beulich =0A=0A--- a/xen/arch/x86/hvm/io.c=0A+++ = b/xen/arch/x86/hvm/io.c=0A@@ -221,13 +221,15 @@ int handle_mmio_with_transl= ation(unsigne=0A return handle_mmio();=0A }=0A =0A-int handle_pio(uint1= 6_t port, int size, int dir)=0A+int handle_pio(uint16_t port, unsigned int = size, int dir)=0A {=0A struct vcpu *curr =3D current;=0A struct = hvm_vcpu_io *vio =3D &curr->arch.hvm_vcpu.hvm_io;=0A unsigned long = data, reps =3D 1;=0A int rc;=0A =0A+ ASSERT((size - 1) < 4 && size = !=3D 3);=0A+=0A if ( dir =3D=3D IOREQ_WRITE )=0A data =3D = guest_cpu_user_regs()->eax;=0A =0A@@ -237,7 +239,12 @@ int handle_pio(uint1= 6_t port, int size, =0A {=0A case X86EMUL_OKAY:=0A if ( = dir =3D=3D IOREQ_READ )=0A- memcpy(&guest_cpu_user_regs()->eax, = &data, vio->io_size);=0A+ {=0A+ if ( size =3D=3D 4 ) /* = Needs zero extension. */=0A+ guest_cpu_user_regs()->eax =3D = (uint32_t)data;=0A+ else=0A+ memcpy(&guest_cpu_us= er_regs()->eax, &data, size);=0A+ }=0A break;=0A case = X86EMUL_RETRY:=0A if ( vio->io_state !=3D HVMIO_awaiting_completion= )=0A--- a/xen/include/asm-x86/hvm/io.h=0A+++ b/xen/include/asm-x86/hvm/io.= h=0A@@ -119,7 +119,7 @@ void send_timeoffset_req(unsigned long t=0A void = send_invalidate_req(void);=0A int handle_mmio(void);=0A int handle_mmio_wit= h_translation(unsigned long gva, unsigned long gpfn);=0A-int handle_pio(uin= t16_t port, int size, int dir);=0A+int handle_pio(uint16_t port, unsigned = int size, int dir);=0A void hvm_interrupt_post(struct vcpu *v, int vector, = int type);=0A void hvm_io_assist(void);=0A void hvm_dpci_eoi(struct domain = *d, unsigned int guest_irq,=0A --=__Part9FACB86D.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part9FACB86D.0__=--