xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/HVM: 32-bit IN result must be zero-extended to 64 bits
@ 2013-11-05  8:46 Jan Beulich
  2013-11-05  9:53 ` Andrew Cooper
  2013-11-05 13:24 ` Keir Fraser
  0 siblings, 2 replies; 4+ messages in thread
From: Jan Beulich @ 2013-11-05  8:46 UTC (permalink / raw)
  To: xen-devel; +Cc: Keir Fraser

[-- Attachment #1: Type: text/plain, Size: 1742 bytes --]

Just like for all other operations with 32-bit operand size.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- 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();
 }
 
-int handle_pio(uint16_t port, int size, int dir)
+int handle_pio(uint16_t port, unsigned int size, int dir)
 {
     struct vcpu *curr = current;
     struct hvm_vcpu_io *vio = &curr->arch.hvm_vcpu.hvm_io;
     unsigned long data, reps = 1;
     int rc;
 
+    ASSERT((size - 1) < 4 && size != 3);
+
     if ( dir == IOREQ_WRITE )
         data = guest_cpu_user_regs()->eax;
 
@@ -237,7 +239,12 @@ int handle_pio(uint16_t port, int size, 
     {
     case X86EMUL_OKAY:
         if ( dir == IOREQ_READ )
-            memcpy(&guest_cpu_user_regs()->eax, &data, vio->io_size);
+        {
+            if ( size == 4 ) /* Needs zero extension. */
+                guest_cpu_user_regs()->eax = (uint32_t)data;
+            else
+                memcpy(&guest_cpu_user_regs()->eax, &data, size);
+        }
         break;
     case X86EMUL_RETRY:
         if ( vio->io_state != 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,




[-- Attachment #2: x86-HVM-PIO-zero-extend.patch --]
[-- Type: text/plain, Size: 1798 bytes --]

x86/HVM: 32-bit IN result must be zero-extended to 64 bits

Just like for all other operations with 32-bit operand size.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- 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();
 }
 
-int handle_pio(uint16_t port, int size, int dir)
+int handle_pio(uint16_t port, unsigned int size, int dir)
 {
     struct vcpu *curr = current;
     struct hvm_vcpu_io *vio = &curr->arch.hvm_vcpu.hvm_io;
     unsigned long data, reps = 1;
     int rc;
 
+    ASSERT((size - 1) < 4 && size != 3);
+
     if ( dir == IOREQ_WRITE )
         data = guest_cpu_user_regs()->eax;
 
@@ -237,7 +239,12 @@ int handle_pio(uint16_t port, int size, 
     {
     case X86EMUL_OKAY:
         if ( dir == IOREQ_READ )
-            memcpy(&guest_cpu_user_regs()->eax, &data, vio->io_size);
+        {
+            if ( size == 4 ) /* Needs zero extension. */
+                guest_cpu_user_regs()->eax = (uint32_t)data;
+            else
+                memcpy(&guest_cpu_user_regs()->eax, &data, size);
+        }
         break;
     case X86EMUL_RETRY:
         if ( vio->io_state != 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,

[-- Attachment #3: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/HVM: 32-bit IN result must be zero-extended to 64 bits
  2013-11-05  8:46 [PATCH] x86/HVM: 32-bit IN result must be zero-extended to 64 bits Jan Beulich
@ 2013-11-05  9:53 ` Andrew Cooper
  2013-11-05 10:07   ` Jan Beulich
  2013-11-05 13:24 ` Keir Fraser
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Cooper @ 2013-11-05  9:53 UTC (permalink / raw)
  To: Jan Beulich; +Cc: xen-devel, Keir Fraser


[-- Attachment #1.1: Type: text/plain, Size: 2296 bytes --]

On 05/11/13 08:46, Jan Beulich wrote:
> Just like for all other operations with 32-bit operand size.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
>
> --- 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();
>  }
>  
> -int handle_pio(uint16_t port, int size, int dir)
> +int handle_pio(uint16_t port, unsigned int size, int dir)
>  {
>      struct vcpu *curr = current;
>      struct hvm_vcpu_io *vio = &curr->arch.hvm_vcpu.hvm_io;
>      unsigned long data, reps = 1;
>      int rc;
>  
> +    ASSERT((size - 1) < 4 && size != 3);
> +
>      if ( dir == IOREQ_WRITE )
>          data = guest_cpu_user_regs()->eax;
>  
> @@ -237,7 +239,12 @@ int handle_pio(uint16_t port, int size, 
>      {
>      case X86EMUL_OKAY:
>          if ( dir == IOREQ_READ )
> -            memcpy(&guest_cpu_user_regs()->eax, &data, vio->io_size);
> +        {
> +            if ( size == 4 ) /* Needs zero extension. */
> +                guest_cpu_user_regs()->eax = (uint32_t)data;

This would be a rather more clear as guest_cpu_user_regs()->rax, with
makes the 0-extension more obvious than remembering that eax is a 64bit
value in Xen.  However, I guess consistency with the surrounding code is
important, and it is spelt out in a comment.

Either way,

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

> +            else
> +                memcpy(&guest_cpu_user_regs()->eax, &data, size);
> +        }
>          break;
>      case X86EMUL_RETRY:
>          if ( vio->io_state != 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,
>
>
>
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel


[-- Attachment #1.2: Type: text/html, Size: 3228 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/HVM: 32-bit IN result must be zero-extended to 64 bits
  2013-11-05  9:53 ` Andrew Cooper
@ 2013-11-05 10:07   ` Jan Beulich
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Beulich @ 2013-11-05 10:07 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: xen-devel, Keir Fraser

>>> On 05.11.13 at 10:53, Andrew Cooper <andrew.cooper3@citrix.com> wrote:
> On 05/11/13 08:46, Jan Beulich wrote:
>> @@ -237,7 +239,12 @@ int handle_pio(uint16_t port, int size, 
>>      {
>>      case X86EMUL_OKAY:
>>          if ( dir == IOREQ_READ )
>> -            memcpy(&guest_cpu_user_regs()->eax, &data, vio->io_size);
>> +        {
>> +            if ( size == 4 ) /* Needs zero extension. */
>> +                guest_cpu_user_regs()->eax = (uint32_t)data;
> 
> This would be a rather more clear as guest_cpu_user_regs()->rax, with
> makes the 0-extension more obvious than remembering that eax is a 64bit
> value in Xen.  However, I guess consistency with the surrounding code is
> important, and it is spelt out in a comment.

In fact I agree - I coded it that way with backportability in mind,
but am inclined to change _both_ instances to "rax" here (which
will cause obvious build breakage if not adjusted accordingly for
4.2 and earlier).

> Either way,
> 
> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>

Thanks.

Jan

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] x86/HVM: 32-bit IN result must be zero-extended to 64 bits
  2013-11-05  8:46 [PATCH] x86/HVM: 32-bit IN result must be zero-extended to 64 bits Jan Beulich
  2013-11-05  9:53 ` Andrew Cooper
@ 2013-11-05 13:24 ` Keir Fraser
  1 sibling, 0 replies; 4+ messages in thread
From: Keir Fraser @ 2013-11-05 13:24 UTC (permalink / raw)
  To: Jan Beulich, xen-devel

On 05/11/2013 08:46, "Jan Beulich" <JBeulich@suse.com> wrote:

> Just like for all other operations with 32-bit operand size.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Acked-by: Keir Fraser <keir@xen.org>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-11-05 13:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-05  8:46 [PATCH] x86/HVM: 32-bit IN result must be zero-extended to 64 bits Jan Beulich
2013-11-05  9:53 ` Andrew Cooper
2013-11-05 10:07   ` Jan Beulich
2013-11-05 13:24 ` Keir Fraser

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).