Skip to contentSkip to conversation

Assertion,'hvmemul_cache_disabled(curr)' failed at vmx.c:4380

DISCUSSION Don Slutz 1 participant 1 message Aug 19, 2020

lore
Share & tools
lore

Don Slutz

author Reviewed-by Paul Durrant
#0 lore raw

Currently I only know how to get this assert with debug=y and hvm_fep enabled.  The attached test code should reproduce this. This happens when any guest does the "ud2 xen" inl that uses QEMU.  Port 0x3f1 is what I use to reproduce this.

My understanding is that it is possible to get to the x86 instruction emulator for "inl" instruction without hvm_fep enabled. Here is more info:

(XEN) [2020-08-18 12:33:45.880] Assertion 'hvmemul_cache_disabled(curr)' failed at vmx.c:4380 (XEN) [2020-08-18 12:33:45.905] ----[ Xen-4.15-unstable  x86_64 debug=y   Tainted:  C H ]---- (XEN) [2020-08-18 12:33:45.930] CPU:    3
(XEN) [2020-08-18 12:33:45.941] RIP: e008:[<ffff82d04029d565>]vmx_vmenter_helper+0x3d/0x45d (XEN) [2020-08-18 12:33:45.966] RFLAGS: 0000000000010097 CONTEXT: hypervisor (d1v0)
...

I did track this to:

commit 2efbc2d446b1315de9c6441a4d535b1fb91e1767
Author:     Jan Beulich <[email protected]>
AuthorDate: Thu Apr 23 09:55:00 2020 +0200
Commit:     Jan Beulich <[email protected]>
CommitDate: Thu Apr 23 09:55:00 2020 +0200

    x86/HVM: implement memory read caching for insn emulation
...

...

   -Don Slutz

/* hvm_fep_inl_test $Revision: 1.13 $
*
* gcc -g -Wall -m64 -O6 -o hvm_fep_inl_test64 hvm_fep_inl_test.c *
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <signal.h>
#include <errno.h>
#include <time.h>
#include <sys/time.h>
#define __USE_GNU
#include <sys/ucontext.h>
#include <setjmp.h>
#include <sys/io.h>

/* Local types */

typedef short unsigned          uint16_t;
typedef int unsigned            uint32_t;
typedef long long unsigned      uint64_t;

/* File vars */
static int debug = 0x380000;
static int qemu_port = 0x3f1;

/* VmWare stuff. */

#define VMWARE_PORT32xin(cmd, eax, ebx, ecx, edx)               \
    __asm__(".byte 0xf,0xb,0x78,0x65,0x6e\n\tinl (%%dx)" :      \
            "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) :        \
            "0"(VMWARE_HYPERVISOR_MAGIC),                       \
            "1"(VMWARE_PORT_CMD_##cmd),                         \
            "2"(qemu_port), "3"(ebx) :             \
            "memory");

/* Start of Kernel copy.
* 2.6.18-194.32.1.el5 */

#define VMWARE_HYPERVISOR_MAGIC 0x564D5868

#define VMWARE_PORT_CMD_GETVERSION 10

static inline int vmware_platform32xin(void)

{
    uint32_t eax, ebx, ecx, edx;

    ebx = UINT_MAX;
    VMWARE_PORT32xin(GETVERSION, eax, ebx, ecx, edx);
    if ( debug ) {
        fprintf(stderr, "hvm_fep_inl_test: ver32xin ax=%08x?%08x bx=%08x?%08x\n",
                eax, VMWARE_HYPERVISOR_MAGIC, ebx, UINT_MAX);
        fprintf(stderr, "hvm_fep_inl_test: ver32xin cx=%08x?%08x dx=%08x?%08x\n",
                ecx, VMWARE_PORT_CMD_GETVERSION, edx, qemu_port);
        if ( eax != UINT_MAX && !(eax & 0x80000000) && ebx == VMWARE_HYPERVISOR_MAGIC )
            fprintf(stderr, "hvm_fep_inl_test: VmWare32xin Version %d.%d\n", eax, ecx);
    }
    return eax != UINT_MAX && !(eax & 0x80000000) && ebx == VMWARE_HYPERVISOR_MAGIC;
}

int
main(int argc, char **argv)

{
    char        *version = "$Revision: 1.13 $";
    int          verLen = strlen(version);

    int rc;

    if ( argc > 2 ) {
        qemu_port = strtol(argv[2], NULL, 0);
        fprintf(stderr, "hvm_fep_inl_test%.*s: %d qemu_port=0x%x(%d)\n",
                verLen - 12, version + 10, argc,
                qemu_port, qemu_port);

    }
    if ( argc > 1 ) {
        debug = strtol(argv[1], NULL, 0);
        fprintf(stderr, "hvm_fep_inl_test%.*s: %d debug=0x%x(%d)\n",
                verLen - 12, version + 10, argc, debug, debug);

    }
    if ( debug & 0x700000 ) {
        rc = iopl((debug & 0x700000) >> 20);
        if ( rc )
            fprintf(stderr, "Failed to call iopl(%d) errno=%d(%s)\n",
                    (debug & 0x700000) >> 20, errno, strerror(errno));
        else
            fprintf(stdout, "Call iopl(%d)\n", (debug & 0x700000) >> 20);
    }

    if ( debug & 0x80000 ) {
        int good = vmware_platform32xin();

        fprintf(stderr, "hvm_fep_inl_test: vmware_platform32xin() good=%d\n", good);
    }

    return 0;
}

/*
* Local variables:
* mode: C
* c-file-style: "BSD"
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/