All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/ioemul: Misc improvements to ioport_emulate.c
@ 2018-01-26 14:48 Andrew Cooper
  2018-01-29 11:23 ` Jan Beulich
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Cooper @ 2018-01-26 14:48 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Jan Beulich

Put the opcode into an array and use memcpy.  This allows the compiled code to
be written with two movs, rather than 10 mov $imm8's.  Also, drop trailing
whitespace in the file.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
---
 xen/arch/x86/ioport_emulate.c | 34 +++++++++++++---------------------
 1 file changed, 13 insertions(+), 21 deletions(-)

diff --git a/xen/arch/x86/ioport_emulate.c b/xen/arch/x86/ioport_emulate.c
index e80993a..c2aded7 100644
--- a/xen/arch/x86/ioport_emulate.c
+++ b/xen/arch/x86/ioport_emulate.c
@@ -1,6 +1,6 @@
 /******************************************************************************
  * ioport_emulate.c
- * 
+ *
  * Handle I/O port access quirks of various platforms.
  */
 
@@ -11,32 +11,24 @@
 static bool ioemul_handle_proliant_quirk(
     u8 opcode, char *io_emul_stub, struct cpu_user_regs *regs)
 {
+    static const char stub[] = {
+        0x9c,       /*    pushf           */
+        0xfa,       /*    cli             */
+        0xee,       /*    out %al, %dx    */
+        0xec,       /* 1: in %dx, %al     */
+        0xa8, 0x80, /*    test $0x80, %al */
+        0x75, 0xfb, /*    jnz 1b          */
+        0x9d,       /*    popf            */
+        0xc3,       /*    ret             */
+    };
     uint16_t port = regs->dx;
     uint8_t value = regs->al;
 
     if ( (opcode != 0xee) || (port != 0xcd4) || !(value & 0x80) )
         return false;
 
-    /*    pushf */
-    io_emul_stub[0] = 0x9c;
-    /*    cli */
-    io_emul_stub[1] = 0xfa;
-    /*    out %al,%dx */
-    io_emul_stub[2] = 0xee;
-    /* 1: in %dx,%al */
-    io_emul_stub[3] = 0xec;
-    /*    test $0x80,%al */
-    io_emul_stub[4] = 0xa8;
-    io_emul_stub[5] = 0x80;
-    /*    jnz 1b */
-    io_emul_stub[6] = 0x75;
-    io_emul_stub[7] = 0xfb;
-    /*    popf */
-    io_emul_stub[8] = 0x9d;
-    /*    ret */
-    io_emul_stub[9] = 0xc3;
-
-    BUILD_BUG_ON(IOEMUL_QUIRK_STUB_BYTES < 10);
+    memcpy(io_emul_stub, stub, sizeof(stub));
+    BUILD_BUG_ON(IOEMUL_QUIRK_STUB_BYTES < sizeof(stub));
 
     return true;
 }
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [PATCH] x86/ioemul: Misc improvements to ioport_emulate.c
  2018-01-26 14:48 [PATCH] x86/ioemul: Misc improvements to ioport_emulate.c Andrew Cooper
@ 2018-01-29 11:23 ` Jan Beulich
  2018-01-29 11:37   ` Andrew Cooper
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Beulich @ 2018-01-29 11:23 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: Xen-devel

>>> On 26.01.18 at 15:48, <andrew.cooper3@citrix.com> wrote:
> Put the opcode into an array and use memcpy.  This allows the compiled code to
> be written with two movs, rather than 10 mov $imm8's.  Also, drop trailing
> whitespace in the file.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

It's a clear improvement, so
Reviewed-by: Jan Beulich <jbeulich@suse.com>
but ...

> @@ -11,32 +11,24 @@
>  static bool ioemul_handle_proliant_quirk(
>      u8 opcode, char *io_emul_stub, struct cpu_user_regs *regs)
>  {
> +    static const char stub[] = {
> +        0x9c,       /*    pushf           */
> +        0xfa,       /*    cli             */
> +        0xee,       /*    out %al, %dx    */
> +        0xec,       /* 1: in %dx, %al     */
> +        0xa8, 0x80, /*    test $0x80, %al */
> +        0x75, 0xfb, /*    jnz 1b          */
> +        0x9d,       /*    popf            */
> +        0xc3,       /*    ret             */
> +    };

... could you go even further and avoid this hex encoding of insns
altogether, but using a file scope asm(), or a function scope one
putting this into e.g. .fixup via .pushsection/.popsection?

Jan


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [PATCH] x86/ioemul: Misc improvements to ioport_emulate.c
  2018-01-29 11:23 ` Jan Beulich
@ 2018-01-29 11:37   ` Andrew Cooper
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Cooper @ 2018-01-29 11:37 UTC (permalink / raw)
  To: Jan Beulich; +Cc: Xen-devel

On 29/01/18 11:23, Jan Beulich wrote:
>>>> On 26.01.18 at 15:48, <andrew.cooper3@citrix.com> wrote:
>> Put the opcode into an array and use memcpy.  This allows the compiled code to
>> be written with two movs, rather than 10 mov $imm8's.  Also, drop trailing
>> whitespace in the file.
>>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> It's a clear improvement, so
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
> but ...
>
>> @@ -11,32 +11,24 @@
>>  static bool ioemul_handle_proliant_quirk(
>>      u8 opcode, char *io_emul_stub, struct cpu_user_regs *regs)
>>  {
>> +    static const char stub[] = {
>> +        0x9c,       /*    pushf           */
>> +        0xfa,       /*    cli             */
>> +        0xee,       /*    out %al, %dx    */
>> +        0xec,       /* 1: in %dx, %al     */
>> +        0xa8, 0x80, /*    test $0x80, %al */
>> +        0x75, 0xfb, /*    jnz 1b          */
>> +        0x9d,       /*    popf            */
>> +        0xc3,       /*    ret             */
>> +    };
> ... could you go even further and avoid this hex encoding of insns
> altogether, but using a file scope asm(), or a function scope one
> putting this into e.g. .fixup via .pushsection/.popsection?

I tried that, but couldn't find a way of creating the blob as a static
in C's eyes, or the size out as a build-time constant.

~Andre

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

end of thread, other threads:[~2018-01-29 11:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-26 14:48 [PATCH] x86/ioemul: Misc improvements to ioport_emulate.c Andrew Cooper
2018-01-29 11:23 ` Jan Beulich
2018-01-29 11:37   ` Andrew Cooper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.