This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
Home Products Support Community News


[Xen-devel] [patch] do_multicall_call abi violation? (x86_64)

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [patch] do_multicall_call abi violation? (x86_64)
From: "Scott Parish" <srparish@xxxxxxxxxx>
Date: Thu, 9 Jun 2005 10:29:18 +0000
Delivery-date: Thu, 09 Jun 2005 11:12:11 +0000
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/
Booting dom0 and running xend spews quite a number of:

 (XEN) (file=multicall.c, line=50) Error writing result back to multicall block.

To jump right to the end of a long story, i think that
do_multicall_call() is in x86_64 abi violation. 

   #define do_multicall_call(_call)                         \
       do {                                                 \
           __asm__ __volatile__ (                           \
               "movq  "STR(MULTICALL_op)"(%0),%%rax; "      \
               "movq  "STR(MULTICALL_arg4)"(%0),%%r8; "     \
               "callq *(%%rax); "                           \
               "movq  %%rax,"STR(MULTICALL_result)"(%0); "  \
               : : "b" (_call)                              \
               : "rax", "rdi", "rsi", "rdx", "rcx", "r8");  \
       } while ( 0 )

The abi says the following (v0.95, page 16):

       Registers %rbp, %rbx and %r12 through %r15 "belong" to the
       calling function and the called function is required to preserve
       their values. In other words, a called function must preserve
       these registers' values for its caller. Remaining registers
       "belong" to the called function. If a calling function wants to
       preserve such a register value across a function call, it must
       save the value in its local stack frame.

do_multicall_call() is doing a call, who does who knows what with
registers, but doesn't advertise clobbering all the abi's volatile

I tried searching for documentation, as it seems to me that gcc should
have some magic flag since it has to know the abi anyway, but i couldn't
find anything. Assuming that this isn't a compiler bug and there aren't
any such flags, the attached patch should make things abi compliant, and
fixes the problem i was seeing.


If you're curious the exact connection between the abi violation and
the error messages...

do_multicall() looks somewhat like (pseudo-code):

   do_multicall(...) {
      if ( asm("inline-asm-1") )

      if ( asm("inline-asm-2") ) {

the result of inline-asm-1 is in some register X. the "if" turns into a
jnz on X to a "ret". gcc realizes if we didn't jump, then X has to be 0,
so it's going to use that value for initialization of the __pu_err in

the problem is that the call in do_multicall_call() stomps on X, as it
isn't advertised to clobber X.

inline-asm-2 is the __put_user code, which uses the fixup/exception-
table trick:

                "1:     mov"itype" %"rtype"1,%2\n"                      \
                "2:\n"                                                  \
                ".section .fixup,\"ax\"\n"                              \
                "3:     mov %3,%0\n"                                    \
                "       jmp 2b\n"                                       \
                ".previous\n"                                           \
                ".section __ex_table,\"a\"\n"                           \
                "       "__FIXUP_ALIGN"\n"                              \
                "       "__FIXUP_WORD" 1b,3b\n"                         \
                ".previous"                                             \
                : "=r"(err)                                             \
                : ltype (x), "m"(__m(addr)), "i"(errret), "0"(err))

so "err" (in register X) is uninitialized if we don't fault. finally
depending on what the call did with X if could be a non-zero value.


Scott Parish
Signed-off-by: srparish@xxxxxxxxxx

Attachment: register-ditty.diff
Description: Text document

Xen-devel mailing list
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [patch] do_multicall_call abi violation? (x86_64), Scott Parish <=