diff mbox

x86/Viridian: don't depend on undefined register state

Message ID 5800C37F02000078001174F3@prv-mh.provo.novell.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jan Beulich Oct. 14, 2016, 9:37 a.m. UTC
The high halves of all GPRs are undefined in 32-bit and compat modes,
and the dependency is being obfuscated by our structure field names not
matching architectural register names (it was actually while putting
together a patch to correct this when I noticed the issue here).

For consistency also use the architecturally correct names on the
output side.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
x86/Viridian: don't depend on undefined register state

The high halves of all GPRs are undefined in 32-bit and compat modes,
and the dependency is being obfuscated by our structure field names not
matching architectural register names (it was actually while putting
together a patch to correct this when I noticed the issue here).

For consistency also use the architecturally correct names on the
output side.

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

--- a/xen/arch/x86/hvm/viridian.c
+++ b/xen/arch/x86/hvm/viridian.c
@@ -667,9 +667,9 @@ int viridian_hypercall(struct cpu_user_r
         output_params_gpa = regs->r8;
         break;
     case 4:
-        input.raw = ((uint64_t)regs->edx << 32) | regs->eax;
-        input_params_gpa = ((uint64_t)regs->ebx << 32) | regs->ecx;
-        output_params_gpa = ((uint64_t)regs->edi << 32) | regs->esi;
+        input.raw = (regs->rdx << 32) | regs->_eax;
+        input_params_gpa = (regs->rbx << 32) | regs->_ecx;
+        output_params_gpa = (regs->rdi << 32) | regs->_esi;
         break;
     default:
         goto out;
@@ -770,8 +770,8 @@ out:
         regs->rax = output.raw;
         break;
     default:
-        regs->edx = output.raw >> 32;
-        regs->eax = output.raw;
+        regs->rdx = output.raw >> 32;
+        regs->rax = (uint32_t)output.raw;
         break;
     }

Comments

Andrew Cooper Oct. 14, 2016, 9:52 a.m. UTC | #1
On 14/10/16 10:37, Jan Beulich wrote:
> The high halves of all GPRs are undefined in 32-bit and compat modes,
> and the dependency is being obfuscated by our structure field names not
> matching architectural register names (it was actually while putting
> together a patch to correct this when I noticed the issue here).
>
> For consistency also use the architecturally correct names on the
> output side.
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Paul Durrant Oct. 14, 2016, 10:53 a.m. UTC | #2
> -----Original Message-----
> From: Jan Beulich [mailto:JBeulich@suse.com]
> Sent: 14 October 2016 05:38
> To: xen-devel <xen-devel@lists.xenproject.org>
> Cc: Paul Durrant <Paul.Durrant@citrix.com>
> Subject: [PATCH] x86/Viridian: don't depend on undefined register state
> 
> The high halves of all GPRs are undefined in 32-bit and compat modes,
> and the dependency is being obfuscated by our structure field names not
> matching architectural register names (it was actually while putting
> together a patch to correct this when I noticed the issue here).
> 
> For consistency also use the architecturally correct names on the
> output side.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Paul Durrant <paul.durrant@citrix.com>

> 
> --- a/xen/arch/x86/hvm/viridian.c
> +++ b/xen/arch/x86/hvm/viridian.c
> @@ -667,9 +667,9 @@ int viridian_hypercall(struct cpu_user_r
>          output_params_gpa = regs->r8;
>          break;
>      case 4:
> -        input.raw = ((uint64_t)regs->edx << 32) | regs->eax;
> -        input_params_gpa = ((uint64_t)regs->ebx << 32) | regs->ecx;
> -        output_params_gpa = ((uint64_t)regs->edi << 32) | regs->esi;
> +        input.raw = (regs->rdx << 32) | regs->_eax;
> +        input_params_gpa = (regs->rbx << 32) | regs->_ecx;
> +        output_params_gpa = (regs->rdi << 32) | regs->_esi;
>          break;
>      default:
>          goto out;
> @@ -770,8 +770,8 @@ out:
>          regs->rax = output.raw;
>          break;
>      default:
> -        regs->edx = output.raw >> 32;
> -        regs->eax = output.raw;
> +        regs->rdx = output.raw >> 32;
> +        regs->rax = (uint32_t)output.raw;
>          break;
>      }
> 
> 
>
diff mbox

Patch

--- a/xen/arch/x86/hvm/viridian.c
+++ b/xen/arch/x86/hvm/viridian.c
@@ -667,9 +667,9 @@  int viridian_hypercall(struct cpu_user_r
         output_params_gpa = regs->r8;
         break;
     case 4:
-        input.raw = ((uint64_t)regs->edx << 32) | regs->eax;
-        input_params_gpa = ((uint64_t)regs->ebx << 32) | regs->ecx;
-        output_params_gpa = ((uint64_t)regs->edi << 32) | regs->esi;
+        input.raw = (regs->rdx << 32) | regs->_eax;
+        input_params_gpa = (regs->rbx << 32) | regs->_ecx;
+        output_params_gpa = (regs->rdi << 32) | regs->_esi;
         break;
     default:
         goto out;
@@ -770,8 +770,8 @@  out:
         regs->rax = output.raw;
         break;
     default:
-        regs->edx = output.raw >> 32;
-        regs->eax = output.raw;
+        regs->rdx = output.raw >> 32;
+        regs->rax = (uint32_t)output.raw;
         break;
     }