xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] x86/emul: Split exception handling out of invoke_stub()
@ 2018-01-31 12:50 Andrew Cooper
  2018-02-01  9:20 ` Jan Beulich
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Cooper @ 2018-01-31 12:50 UTC (permalink / raw)
  To: Xen-devel; +Cc: Andrew Cooper, Jan Beulich

For a release build, bloat-o-meter reports:

  add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-5111 (-5111)
  function                                     old     new   delta
  x86_emulate                               126458  121347   -5111

or in other words, a 4% redunction in code size from this change alone.

The use of __LINE__ is a concern with livepatching, but any livepatch touching
this file is overwhemlingly likely to alter x86_emulate() anyway.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>

v2:
 * Retain __LINE__.  It can't be embedded in union stub_exception_token as the
   full token gets written by the exception hanlder.
---
 xen/arch/x86/x86_emulate/x86_emulate.c | 37 +++++++++++++++++++++-------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c b/xen/arch/x86/x86_emulate/x86_emulate.c
index 4cc51ea..c9221c8 100644
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -866,7 +866,8 @@ static inline int mkec(uint8_t e, int32_t ec, ...)
 
 #ifdef __XEN__
 # define invoke_stub(pre, post, constraints...) do {                    \
-    union stub_exception_token res_ = { .raw = ~0 };                    \
+    stub_exn_info = (union stub_exception_token) { .raw = ~0 };         \
+    stub_exn_line = __LINE__; /* Utility outweighs livepatching cost */ \
     asm volatile ( pre "\n\tINDIRECT_CALL %[stub]\n\t" post "\n"        \
                    ".Lret%=:\n\t"                                       \
                    ".pushsection .fixup,\"ax\"\n"                       \
@@ -875,21 +876,11 @@ static inline int mkec(uint8_t e, int32_t ec, ...)
                    "jmp .Lret%=\n\t"                                    \
                    ".popsection\n\t"                                    \
                    _ASM_EXTABLE(.Lret%=, .Lfix%=)                       \
-                   : [exn] "+g" (res_), constraints,                    \
+                   : [exn] "+g" (stub_exn_info), constraints,           \
                      [stub] "r" (stub.func),                            \
                      "m" (*(uint8_t(*)[MAX_INST_LEN + 1])stub.ptr) );   \
-    if ( unlikely(~res_.raw) )                                          \
-    {                                                                   \
-        gprintk(XENLOG_WARNING,                                         \
-                "exception %u (ec=%04x) in emulation stub (line %u)\n", \
-                res_.fields.trapnr, res_.fields.ec, __LINE__);          \
-        gprintk(XENLOG_INFO, "stub: %"__stringify(MAX_INST_LEN)"ph\n",  \
-                stub.func);                                             \
-        generate_exception_if(res_.fields.trapnr == EXC_UD, EXC_UD);    \
-        domain_crash(current->domain);                                  \
-        rc = X86EMUL_UNHANDLEABLE;                                      \
-        goto done;                                                      \
-    }                                                                   \
+    if ( unlikely(~stub_exn_info.raw) )                                 \
+        goto emulation_stub_failure;                                    \
 } while (0)
 #else
 # define invoke_stub(pre, post, constraints...)                         \
@@ -3017,6 +3008,10 @@ x86_emulate(
     struct fpu_insn_ctxt fic = { .type = X86EMUL_FPU_none, .exn_raised = -1 };
     struct x86_emulate_stub stub = {};
     DECLARE_ALIGNED(mmval_t, mmval);
+#ifdef __XEN__
+    union stub_exception_token stub_exn_info;
+    unsigned int stub_exn_line;
+#endif
 
     ASSERT(ops->read);
 
@@ -8023,6 +8018,20 @@ x86_emulate(
     put_stub(stub);
     return rc;
 #undef state
+
+#ifdef __XEN__
+ emulation_stub_failure:
+    gprintk(XENLOG_WARNING,
+            "exception %u (ec=%04x) in emulation stub (line %u)\n",
+            stub_exn_info.fields.trapnr, stub_exn_info.fields.ec,
+            stub_exn_line);
+    gprintk(XENLOG_INFO, "  stub: %"__stringify(MAX_INST_LEN)"ph\n",
+            stub.func);
+    generate_exception_if(stub_exn_info.fields.trapnr == EXC_UD, EXC_UD);
+    domain_crash(current->domain);
+    rc = X86EMUL_UNHANDLEABLE;
+    goto done;
+#endif
 }
 
 #undef op_bytes
-- 
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 v2] x86/emul: Split exception handling out of invoke_stub()
  2018-01-31 12:50 [PATCH v2] x86/emul: Split exception handling out of invoke_stub() Andrew Cooper
@ 2018-02-01  9:20 ` Jan Beulich
  2018-02-01  9:41   ` Andrew Cooper
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Beulich @ 2018-02-01  9:20 UTC (permalink / raw)
  To: Andrew Cooper; +Cc: Xen-devel

>>> On 31.01.18 at 13:50, <andrew.cooper3@citrix.com> wrote:
> For a release build, bloat-o-meter reports:
> 
>   add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-5111 (-5111)
>   function                                     old     new   delta
>   x86_emulate                               126458  121347   -5111
> 
> or in other words, a 4% redunction in code size from this change alone.
> 
> The use of __LINE__ is a concern with livepatching, but any livepatch touching
> this file is overwhemlingly likely to alter x86_emulate() anyway.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: Jan Beulich <JBeulich@suse.com>
> 
> v2:
>  * Retain __LINE__.  It can't be embedded in union stub_exception_token as the
>    full token gets written by the exception hanlder.

And that's not what I had in mind. Instead I had thought of ...

> @@ -3017,6 +3008,10 @@ x86_emulate(
>      struct fpu_insn_ctxt fic = { .type = X86EMUL_FPU_none, .exn_raised = -1 
> };
>      struct x86_emulate_stub stub = {};
>      DECLARE_ALIGNED(mmval_t, mmval);
> +#ifdef __XEN__
> +    union stub_exception_token stub_exn_info;
> +    unsigned int stub_exn_line;
> +#endif

    struct {
        union stub_exception_token info;
        unsigned int line;
    } stub_exn;

Either way
Reviewed-by: Jan Beulich <jbeulich@suse.com>

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 v2] x86/emul: Split exception handling out of invoke_stub()
  2018-02-01  9:20 ` Jan Beulich
@ 2018-02-01  9:41   ` Andrew Cooper
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Cooper @ 2018-02-01  9:41 UTC (permalink / raw)
  To: Jan Beulich; +Cc: Xen-devel

On 01/02/2018 09:20, Jan Beulich wrote:
>>>> On 31.01.18 at 13:50, <andrew.cooper3@citrix.com> wrote:
>> For a release build, bloat-o-meter reports:
>>
>>   add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-5111 (-5111)
>>   function                                     old     new   delta
>>   x86_emulate                               126458  121347   -5111
>>
>> or in other words, a 4% redunction in code size from this change alone.
>>
>> The use of __LINE__ is a concern with livepatching, but any livepatch touching
>> this file is overwhemlingly likely to alter x86_emulate() anyway.
>>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
>> ---
>> CC: Jan Beulich <JBeulich@suse.com>
>>
>> v2:
>>  * Retain __LINE__.  It can't be embedded in union stub_exception_token as the
>>    full token gets written by the exception hanlder.
> And that's not what I had in mind. Instead I had thought of ...
>
>> @@ -3017,6 +3008,10 @@ x86_emulate(
>>      struct fpu_insn_ctxt fic = { .type = X86EMUL_FPU_none, .exn_raised = -1 
>> };
>>      struct x86_emulate_stub stub = {};
>>      DECLARE_ALIGNED(mmval_t, mmval);
>> +#ifdef __XEN__
>> +    union stub_exception_token stub_exn_info;
>> +    unsigned int stub_exn_line;
>> +#endif
>     struct {
>         union stub_exception_token info;
>         unsigned int line;
>     } stub_exn;
>
> Either way
> Reviewed-by: Jan Beulich <jbeulich@suse.com>

Ah ok - I'll switch to this model.

~Andrew

_______________________________________________
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-02-01  9:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-31 12:50 [PATCH v2] x86/emul: Split exception handling out of invoke_stub() Andrew Cooper
2018-02-01  9:20 ` Jan Beulich
2018-02-01  9:41   ` Andrew Cooper

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).