diff mbox

[v2,5/6] x86_emulate: Remove dependency on __LINE__ for release builds

Message ID 1488995215-7647-6-git-send-email-ross.lagerwall@citrix.com (mailing list archive)
State New, archived
Headers show

Commit Message

Ross Lagerwall March 8, 2017, 5:46 p.m. UTC
When using LivePatch, use of __LINE__ can generate spurious changes in
functions due to embedded line numbers.  For release builds with
LivePatch enabled, remove the use of these line numbers and print the
current text address instead.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
---
 xen/arch/x86/x86_emulate/x86_emulate.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

Comments

Jan Beulich March 9, 2017, 10:45 a.m. UTC | #1
>>> On 08.03.17 at 18:46, <ross.lagerwall@citrix.com> wrote:
> @@ -791,9 +807,7 @@ do{ asm volatile (                                        
>               \
>                       [stub] "rm" (stub.func) );                         \
>      if ( unlikely(~res_.raw) )                                          \
>      {                                                                   \
> -        gprintk(XENLOG_WARNING,                                         \
> -                "exception %u (ec=%04x) in emulation stub (line %u)\n", \
> -                res_.fields.trapnr, res_.fields.ec, __LINE__);          \
> +        invoke_stub_exception(res_.fields.trapnr, res_.fields.ec);      \

This presumably is the worst of the changes in this series, as
explained in reply to the overview mail: The text address is going
to point into a huge function, and reconstruction of the source
line is going to be rather cumbersome in case line2addr fails
(which afaik it is not unknown for).

Jan
diff mbox

Patch

diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c b/xen/arch/x86/x86_emulate/x86_emulate.c
index 613648e..cf05544 100644
--- a/xen/arch/x86/x86_emulate/x86_emulate.c
+++ b/xen/arch/x86/x86_emulate/x86_emulate.c
@@ -776,6 +776,22 @@  do{ asm volatile (                                                      \
 #define __emulate_1op_8byte(_op, _dst, _eflags)
 #endif /* __i386__ */
 
+#if defined(NDEBUG) && defined(CONFIG_LIVEPATCH)
+#define invoke_stub_exception(trapnr, ec)                                   \
+    do {                                                                    \
+        gprintk(XENLOG_WARNING,                                             \
+                "exception %u (ec=%04x) in emulation stub (address %pS)\n", \
+                trapnr, ec, current_text_addr());                           \
+    } while (0)
+#else
+#define invoke_stub_exception(trapnr, ec)                                   \
+    do {                                                                    \
+        gprintk(XENLOG_WARNING,                                             \
+                "exception %u (ec=%04x) in emulation stub (line %u)\n",     \
+                trapnr, ec, __LINE__);                                      \
+    } while (0)
+#endif
+
 #ifdef __XEN__
 # define invoke_stub(pre, post, constraints...) do {                    \
     union stub_exception_token res_ = { .raw = ~0 };                    \
@@ -791,9 +807,7 @@  do{ asm volatile (                                                      \
                      [stub] "rm" (stub.func) );                         \
     if ( unlikely(~res_.raw) )                                          \
     {                                                                   \
-        gprintk(XENLOG_WARNING,                                         \
-                "exception %u (ec=%04x) in emulation stub (line %u)\n", \
-                res_.fields.trapnr, res_.fields.ec, __LINE__);          \
+        invoke_stub_exception(res_.fields.trapnr, res_.fields.ec);      \
         gprintk(XENLOG_INFO, "stub: %"__stringify(MAX_INST_LEN)"ph\n",  \
                 stub.func);                                             \
         generate_exception_if(res_.fields.trapnr == EXC_UD, EXC_UD);    \