瀏覽代碼

Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging

* Some hw/isa cleanups
* Fixes for x86 CPUID
* Cleanups for configure, hw/isa and x86

# -----BEGIN PGP SIGNATURE-----
#
# iQFIBAABCAAyFiEE8TM4V0tmI4mGbHaCv/vSX3jHroMFAmXPW5sUHHBib256aW5p
# QHJlZGhhdC5jb20ACgkQv/vSX3jHroO1Mgf/USSqZxAyS1tyutpVslKmQjCyUiNW
# xEuHhAqoTz4Xg/8Q1J9aCcs2hdpBx2ULEQryUiTlH3LPLy3j9lGxMfg9Ma65mPVg
# KOSm/vfnw2VPXav8MJVNbm0gSI5fPmprRYgFi4TrkknmKnDo2TElrCG6Oe6LN/X+
# kiJD9K8PE+OE7xVhNDf7JAxUHt531oX7iM8p6JGGBYQdPOZ8rGf4K5PDrDxnHckG
# dbKHhqkbrSHaX/gu4q0ukgfIprs40ChYQ10vZ95mYyuWgIHOi51PciPmQ/qLPof0
# b/au08F0SpTE5cxx1Rk4cAuhP/PtzVln5lsSl9r9KzJ3Hcv6qnwXUU1nUg==
# =U+N2
# -----END PGP SIGNATURE-----
# gpg: Signature made Fri 16 Feb 2024 12:56:59 GMT
# gpg:                using RSA key F13338574B662389866C7682BFFBD25F78C7AE83
# gpg:                issuer "pbonzini@redhat.com"
# gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>" [full]
# gpg:                 aka "Paolo Bonzini <pbonzini@redhat.com>" [full]
# Primary key fingerprint: 46F5 9FBD 57D6 12E7 BFD4  E2F7 7E15 100C CD36 69B1
#      Subkey fingerprint: F133 3857 4B66 2389 866C  7682 BFFB D25F 78C7 AE83

* tag 'for-upstream' of https://gitlab.com/bonzini/qemu:
  ci: Fix again build-previous-qemu
  usb: inline device creation functions
  target/i386: Generate an illegal opcode exception on cmp instructions with lock prefix
  i386: xen: fix compilation --without-default-devices
  configure: put all symlink creation together
  configure: do not create legacy symlinks
  smc37c669: remove useless is_enabled functions
  isa-superio: validate floppy.count value
  mips: remove unnecessary "select PTIMER"
  i386/cpuid: Move leaf 7 to correct group
  i386/cpuid: Remove subleaf constraint on CPUID leaf 1F
  i386/cpuid: Decrease cpuid_i when skipping CPUID leaf 1F
  physmem: replace function name with __func__ in ram_block_discard_range()
  i386/pc: Drop pc_machine_kvm_type()
  target/i386: Add support of KVM_FEATURE_ASYNC_PF_VMEXIT for guest
  i386/cpu: Mask with XCR0/XSS mask for FEAT_XSAVE_XCR0_HI and FEAT_XSAVE_XSS_HI leafs
  i386/cpu: Clear FEAT_XSAVE_XSS_LO/HI leafs when CPUID_EXT_XSAVE is not available

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Peter Maydell 1 年之前
父節點
當前提交
760b4dcddd
共有 13 個文件被更改,包括 64 次插入103 次删除
  1. 1 1
      .gitlab-ci.d/buildtest.yml
  2. 1 0
      accel/Kconfig
  3. 5 15
      configure
  4. 0 5
      hw/i386/pc.c
  5. 3 1
      hw/isa/isa-superio.c
  6. 0 18
      hw/isa/smc37c669-superio.c
  7. 0 23
      hw/usb/bus.c
  8. 0 3
      include/hw/i386/pc.h
  9. 24 3
      include/hw/usb.h
  10. 17 21
      system/physmem.c
  11. 5 3
      target/i386/cpu.c
  12. 2 5
      target/i386/kvm/kvm.c
  13. 6 5
      target/i386/tcg/translate.c

+ 1 - 1
.gitlab-ci.d/buildtest.yml

@@ -190,7 +190,7 @@ build-previous-qemu:
   before_script:
   before_script:
     - export QEMU_PREV_VERSION="$(sed 's/\([0-9.]*\)\.[0-9]*/v\1.0/' VERSION)"
     - export QEMU_PREV_VERSION="$(sed 's/\([0-9.]*\)\.[0-9]*/v\1.0/' VERSION)"
     - git remote add upstream https://gitlab.com/qemu-project/qemu
     - git remote add upstream https://gitlab.com/qemu-project/qemu
-    - git fetch upstream $QEMU_PREV_VERSION
+    - git fetch upstream refs/tags/$QEMU_PREV_VERSION:refs/tags/$QEMU_PREV_VERSION
     - git checkout $QEMU_PREV_VERSION
     - git checkout $QEMU_PREV_VERSION
   after_script:
   after_script:
     - mv build build-previous
     - mv build build-previous

+ 1 - 0
accel/Kconfig

@@ -16,3 +16,4 @@ config KVM
 config XEN
 config XEN
     bool
     bool
     select FSDEV_9P if VIRTFS
     select FSDEV_9P if VIRTFS
+    select XEN_BUS

+ 5 - 15
configure

@@ -1538,6 +1538,11 @@ for f in $LINKS ; do
     fi
     fi
 done
 done
 
 
+# use included Linux headers for KVM architectures
+if test "$host_os" = "linux" && test -n "$linux_arch"; then
+  symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
+fi
+
 echo "# Automatically generated by configure - do not modify" > Makefile.prereqs
 echo "# Automatically generated by configure - do not modify" > Makefile.prereqs
 
 
 # Mac OS X ships with a broken assembler
 # Mac OS X ships with a broken assembler
@@ -1605,21 +1610,6 @@ echo "GENISOIMAGE=$genisoimage" >> $config_host_mak
 echo "MESON=$meson" >> $config_host_mak
 echo "MESON=$meson" >> $config_host_mak
 echo "NINJA=$ninja" >> $config_host_mak
 echo "NINJA=$ninja" >> $config_host_mak
 echo "EXESUF=$EXESUF" >> $config_host_mak
 echo "EXESUF=$EXESUF" >> $config_host_mak
-
-# use included Linux headers for KVM architectures
-if test "$host_os" = "linux" && test -n "$linux_arch"; then
-  symlink "$source_path/linux-headers/asm-$linux_arch" linux-headers/asm
-fi
-
-for target in $target_list; do
-    target_dir="$target"
-    target_name=$(echo $target | cut -d '-' -f 1)$EXESUF
-    case $target in
-        *-user) symlink "../qemu-$target_name" "$target_dir/qemu-$target_name" ;;
-        *) symlink "../qemu-system-$target_name" "$target_dir/qemu-system-$target_name" ;;
-    esac
-done
-
 if test "$default_targets" = "yes"; then
 if test "$default_targets" = "yes"; then
   echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
   echo "CONFIG_DEFAULT_TARGETS=y" >> $config_host_mak
 fi
 fi

+ 0 - 5
hw/i386/pc.c

@@ -1756,11 +1756,6 @@ static void pc_machine_initfn(Object *obj)
     cxl_machine_init(obj, &pcms->cxl_devices_state);
     cxl_machine_init(obj, &pcms->cxl_devices_state);
 }
 }
 
 
-int pc_machine_kvm_type(MachineState *machine, const char *kvm_type)
-{
-    return 0;
-}
-
 static void pc_machine_reset(MachineState *machine, ShutdownCause reason)
 static void pc_machine_reset(MachineState *machine, ShutdownCause reason)
 {
 {
     CPUState *cs;
     CPUState *cs;

+ 3 - 1
hw/isa/isa-superio.c

@@ -116,7 +116,9 @@ static void isa_superio_realize(DeviceState *dev, Error **errp)
     }
     }
 
 
     /* Floppy disc */
     /* Floppy disc */
-    if (!k->floppy.is_enabled || k->floppy.is_enabled(sio, 0)) {
+    assert(k->floppy.count <= 1);
+    if (k->floppy.count &&
+        (!k->floppy.is_enabled || k->floppy.is_enabled(sio, 0))) {
         isa = isa_new(TYPE_ISA_FDC);
         isa = isa_new(TYPE_ISA_FDC);
         d = DEVICE(isa);
         d = DEVICE(isa);
         if (k->floppy.get_iobase) {
         if (k->floppy.get_iobase) {

+ 0 - 18
hw/isa/smc37c669-superio.c

@@ -14,11 +14,6 @@
 
 
 /* UARTs (compatible with NS16450 or PC16550) */
 /* UARTs (compatible with NS16450 or PC16550) */
 
 
-static bool is_serial_enabled(ISASuperIODevice *sio, uint8_t index)
-{
-    return index < 2;
-}
-
 static uint16_t get_serial_iobase(ISASuperIODevice *sio, uint8_t index)
 static uint16_t get_serial_iobase(ISASuperIODevice *sio, uint8_t index)
 {
 {
     return index ? 0x2f8 : 0x3f8;
     return index ? 0x2f8 : 0x3f8;
@@ -31,11 +26,6 @@ static unsigned int get_serial_irq(ISASuperIODevice *sio, uint8_t index)
 
 
 /* Parallel port */
 /* Parallel port */
 
 
-static bool is_parallel_enabled(ISASuperIODevice *sio, uint8_t index)
-{
-    return index < 1;
-}
-
 static uint16_t get_parallel_iobase(ISASuperIODevice *sio, uint8_t index)
 static uint16_t get_parallel_iobase(ISASuperIODevice *sio, uint8_t index)
 {
 {
     return 0x378;
     return 0x378;
@@ -53,11 +43,6 @@ static unsigned int get_parallel_dma(ISASuperIODevice *sio, uint8_t index)
 
 
 /* Diskette controller (Software compatible with the Intel PC8477) */
 /* Diskette controller (Software compatible with the Intel PC8477) */
 
 
-static bool is_fdc_enabled(ISASuperIODevice *sio, uint8_t index)
-{
-    return index < 1;
-}
-
 static uint16_t get_fdc_iobase(ISASuperIODevice *sio, uint8_t index)
 static uint16_t get_fdc_iobase(ISASuperIODevice *sio, uint8_t index)
 {
 {
     return 0x3f0;
     return 0x3f0;
@@ -79,20 +64,17 @@ static void smc37c669_class_init(ObjectClass *klass, void *data)
 
 
     sc->parallel = (ISASuperIOFuncs){
     sc->parallel = (ISASuperIOFuncs){
         .count = 1,
         .count = 1,
-        .is_enabled = is_parallel_enabled,
         .get_iobase = get_parallel_iobase,
         .get_iobase = get_parallel_iobase,
         .get_irq    = get_parallel_irq,
         .get_irq    = get_parallel_irq,
         .get_dma    = get_parallel_dma,
         .get_dma    = get_parallel_dma,
     };
     };
     sc->serial = (ISASuperIOFuncs){
     sc->serial = (ISASuperIOFuncs){
         .count = 2,
         .count = 2,
-        .is_enabled = is_serial_enabled,
         .get_iobase = get_serial_iobase,
         .get_iobase = get_serial_iobase,
         .get_irq    = get_serial_irq,
         .get_irq    = get_serial_irq,
     };
     };
     sc->floppy = (ISASuperIOFuncs){
     sc->floppy = (ISASuperIOFuncs){
         .count = 1,
         .count = 1,
-        .is_enabled = is_fdc_enabled,
         .get_iobase = get_fdc_iobase,
         .get_iobase = get_fdc_iobase,
         .get_irq    = get_fdc_irq,
         .get_irq    = get_fdc_irq,
         .get_dma    = get_fdc_dma,
         .get_dma    = get_fdc_dma,

+ 0 - 23
hw/usb/bus.c

@@ -329,29 +329,6 @@ void usb_legacy_register(const char *typename, const char *usbdevice_name,
     }
     }
 }
 }
 
 
-USBDevice *usb_new(const char *name)
-{
-    return USB_DEVICE(qdev_new(name));
-}
-
-static USBDevice *usb_try_new(const char *name)
-{
-    return USB_DEVICE(qdev_try_new(name));
-}
-
-bool usb_realize_and_unref(USBDevice *dev, USBBus *bus, Error **errp)
-{
-    return qdev_realize_and_unref(&dev->qdev, &bus->qbus, errp);
-}
-
-USBDevice *usb_create_simple(USBBus *bus, const char *name)
-{
-    USBDevice *dev = usb_new(name);
-
-    usb_realize_and_unref(dev, bus, &error_abort);
-    return dev;
-}
-
 static void usb_fill_port(USBPort *port, void *opaque, int index,
 static void usb_fill_port(USBPort *port, void *opaque, int index,
                           USBPortOps *ops, int speedmask)
                           USBPortOps *ops, int speedmask)
 {
 {

+ 0 - 3
include/hw/i386/pc.h

@@ -310,15 +310,12 @@ extern const size_t pc_compat_1_5_len;
 extern GlobalProperty pc_compat_1_4[];
 extern GlobalProperty pc_compat_1_4[];
 extern const size_t pc_compat_1_4_len;
 extern const size_t pc_compat_1_4_len;
 
 
-int pc_machine_kvm_type(MachineState *machine, const char *vm_type);
-
 #define DEFINE_PC_MACHINE(suffix, namestr, initfn, optsfn) \
 #define DEFINE_PC_MACHINE(suffix, namestr, initfn, optsfn) \
     static void pc_machine_##suffix##_class_init(ObjectClass *oc, void *data) \
     static void pc_machine_##suffix##_class_init(ObjectClass *oc, void *data) \
     { \
     { \
         MachineClass *mc = MACHINE_CLASS(oc); \
         MachineClass *mc = MACHINE_CLASS(oc); \
         optsfn(mc); \
         optsfn(mc); \
         mc->init = initfn; \
         mc->init = initfn; \
-        mc->kvm_type = pc_machine_kvm_type; \
     } \
     } \
     static const TypeInfo pc_machine_type_##suffix = { \
     static const TypeInfo pc_machine_type_##suffix = { \
         .name       = namestr TYPE_MACHINE_SUFFIX, \
         .name       = namestr TYPE_MACHINE_SUFFIX, \

+ 24 - 3
include/hw/usb.h

@@ -30,6 +30,7 @@
 #include "qemu/iov.h"
 #include "qemu/iov.h"
 #include "qemu/queue.h"
 #include "qemu/queue.h"
 #include "qom/object.h"
 #include "qom/object.h"
+#include "qapi/error.h"
 
 
 /* Constants related to the USB / PCI interaction */
 /* Constants related to the USB / PCI interaction */
 #define USB_SBRN    0x60 /* Serial Bus Release Number Register */
 #define USB_SBRN    0x60 /* Serial Bus Release Number Register */
@@ -500,9 +501,6 @@ void usb_bus_release(USBBus *bus);
 USBBus *usb_bus_find(int busnr);
 USBBus *usb_bus_find(int busnr);
 void usb_legacy_register(const char *typename, const char *usbdevice_name,
 void usb_legacy_register(const char *typename, const char *usbdevice_name,
                          USBDevice *(*usbdevice_init)(void));
                          USBDevice *(*usbdevice_init)(void));
-USBDevice *usb_new(const char *name);
-bool usb_realize_and_unref(USBDevice *dev, USBBus *bus, Error **errp);
-USBDevice *usb_create_simple(USBBus *bus, const char *name);
 USBDevice *usbdevice_create(const char *cmdline);
 USBDevice *usbdevice_create(const char *cmdline);
 void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index,
 void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index,
                        USBPortOps *ops, int speedmask);
                        USBPortOps *ops, int speedmask);
@@ -582,4 +580,27 @@ void usb_pcap_init(FILE *fp);
 void usb_pcap_ctrl(USBPacket *p, bool setup);
 void usb_pcap_ctrl(USBPacket *p, bool setup);
 void usb_pcap_data(USBPacket *p, bool setup);
 void usb_pcap_data(USBPacket *p, bool setup);
 
 
+static inline USBDevice *usb_new(const char *name)
+{
+    return USB_DEVICE(qdev_new(name));
+}
+
+static inline USBDevice *usb_try_new(const char *name)
+{
+    return USB_DEVICE(qdev_try_new(name));
+}
+
+static inline bool usb_realize_and_unref(USBDevice *dev, USBBus *bus, Error **errp)
+{
+    return qdev_realize_and_unref(&dev->qdev, &bus->qbus, errp);
+}
+
+static inline USBDevice *usb_create_simple(USBBus *bus, const char *name)
+{
+    USBDevice *dev = usb_new(name);
+
+    usb_realize_and_unref(dev, bus, &error_abort);
+    return dev;
+}
+
 #endif
 #endif

+ 17 - 21
system/physmem.c

@@ -3495,16 +3495,15 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
     uint8_t *host_startaddr = rb->host + start;
     uint8_t *host_startaddr = rb->host + start;
 
 
     if (!QEMU_PTR_IS_ALIGNED(host_startaddr, rb->page_size)) {
     if (!QEMU_PTR_IS_ALIGNED(host_startaddr, rb->page_size)) {
-        error_report("ram_block_discard_range: Unaligned start address: %p",
-                     host_startaddr);
+        error_report("%s: Unaligned start address: %p",
+                     __func__, host_startaddr);
         goto err;
         goto err;
     }
     }
 
 
     if ((start + length) <= rb->max_length) {
     if ((start + length) <= rb->max_length) {
         bool need_madvise, need_fallocate;
         bool need_madvise, need_fallocate;
         if (!QEMU_IS_ALIGNED(length, rb->page_size)) {
         if (!QEMU_IS_ALIGNED(length, rb->page_size)) {
-            error_report("ram_block_discard_range: Unaligned length: %zx",
-                         length);
+            error_report("%s: Unaligned length: %zx", __func__, length);
             goto err;
             goto err;
         }
         }
 
 
@@ -3528,8 +3527,8 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
              * proper error message.
              * proper error message.
              */
              */
             if (rb->flags & RAM_READONLY_FD) {
             if (rb->flags & RAM_READONLY_FD) {
-                error_report("ram_block_discard_range: Discarding RAM"
-                             " with readonly files is not supported");
+                error_report("%s: Discarding RAM with readonly files is not"
+                             " supported", __func__);
                 goto err;
                 goto err;
 
 
             }
             }
@@ -3544,27 +3543,26 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
              * file.
              * file.
              */
              */
             if (!qemu_ram_is_shared(rb)) {
             if (!qemu_ram_is_shared(rb)) {
-                warn_report_once("ram_block_discard_range: Discarding RAM"
+                warn_report_once("%s: Discarding RAM"
                                  " in private file mappings is possibly"
                                  " in private file mappings is possibly"
                                  " dangerous, because it will modify the"
                                  " dangerous, because it will modify the"
                                  " underlying file and will affect other"
                                  " underlying file and will affect other"
-                                 " users of the file");
+                                 " users of the file", __func__);
             }
             }
 
 
             ret = fallocate(rb->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
             ret = fallocate(rb->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
                             start, length);
                             start, length);
             if (ret) {
             if (ret) {
                 ret = -errno;
                 ret = -errno;
-                error_report("ram_block_discard_range: Failed to fallocate "
-                             "%s:%" PRIx64 " +%zx (%d)",
-                             rb->idstr, start, length, ret);
+                error_report("%s: Failed to fallocate %s:%" PRIx64 " +%zx (%d)",
+                             __func__, rb->idstr, start, length, ret);
                 goto err;
                 goto err;
             }
             }
 #else
 #else
             ret = -ENOSYS;
             ret = -ENOSYS;
-            error_report("ram_block_discard_range: fallocate not available/file"
+            error_report("%s: fallocate not available/file"
                          "%s:%" PRIx64 " +%zx (%d)",
                          "%s:%" PRIx64 " +%zx (%d)",
-                         rb->idstr, start, length, ret);
+                         __func__, rb->idstr, start, length, ret);
             goto err;
             goto err;
 #endif
 #endif
         }
         }
@@ -3582,25 +3580,23 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t start, size_t length)
             }
             }
             if (ret) {
             if (ret) {
                 ret = -errno;
                 ret = -errno;
-                error_report("ram_block_discard_range: Failed to discard range "
+                error_report("%s: Failed to discard range "
                              "%s:%" PRIx64 " +%zx (%d)",
                              "%s:%" PRIx64 " +%zx (%d)",
-                             rb->idstr, start, length, ret);
+                             __func__, rb->idstr, start, length, ret);
                 goto err;
                 goto err;
             }
             }
 #else
 #else
             ret = -ENOSYS;
             ret = -ENOSYS;
-            error_report("ram_block_discard_range: MADVISE not available"
-                         "%s:%" PRIx64 " +%zx (%d)",
-                         rb->idstr, start, length, ret);
+            error_report("%s: MADVISE not available %s:%" PRIx64 " +%zx (%d)",
+                         __func__, rb->idstr, start, length, ret);
             goto err;
             goto err;
 #endif
 #endif
         }
         }
         trace_ram_block_discard_range(rb->idstr, host_startaddr, length,
         trace_ram_block_discard_range(rb->idstr, host_startaddr, length,
                                       need_madvise, need_fallocate, ret);
                                       need_madvise, need_fallocate, ret);
     } else {
     } else {
-        error_report("ram_block_discard_range: Overrun block '%s' (%" PRIu64
-                     "/%zx/" RAM_ADDR_FMT")",
-                     rb->idstr, start, length, rb->max_length);
+        error_report("%s: Overrun block '%s' (%" PRIu64 "/%zx/" RAM_ADDR_FMT")",
+                     __func__, rb->idstr, start, length, rb->max_length);
     }
     }
 
 
 err:
 err:

+ 5 - 3
target/i386/cpu.c

@@ -857,7 +857,7 @@ FeatureWordInfo feature_word_info[FEATURE_WORDS] = {
         .feat_names = {
         .feat_names = {
             "kvmclock", "kvm-nopiodelay", "kvm-mmu", "kvmclock",
             "kvmclock", "kvm-nopiodelay", "kvm-mmu", "kvmclock",
             "kvm-asyncpf", "kvm-steal-time", "kvm-pv-eoi", "kvm-pv-unhalt",
             "kvm-asyncpf", "kvm-steal-time", "kvm-pv-eoi", "kvm-pv-unhalt",
-            NULL, "kvm-pv-tlb-flush", NULL, "kvm-pv-ipi",
+            NULL, "kvm-pv-tlb-flush", "kvm-asyncpf-vmexit", "kvm-pv-ipi",
             "kvm-poll-control", "kvm-pv-sched-yield", "kvm-asyncpf-int", "kvm-msi-ext-dest-id",
             "kvm-poll-control", "kvm-pv-sched-yield", "kvm-asyncpf-int", "kvm-msi-ext-dest-id",
             NULL, NULL, NULL, NULL,
             NULL, NULL, NULL, NULL,
             NULL, NULL, NULL, NULL,
             NULL, NULL, NULL, NULL,
@@ -6927,6 +6927,8 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu)
     if (!(env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE)) {
     if (!(env->features[FEAT_1_ECX] & CPUID_EXT_XSAVE)) {
         env->features[FEAT_XSAVE_XCR0_LO] = 0;
         env->features[FEAT_XSAVE_XCR0_LO] = 0;
         env->features[FEAT_XSAVE_XCR0_HI] = 0;
         env->features[FEAT_XSAVE_XCR0_HI] = 0;
+        env->features[FEAT_XSAVE_XSS_LO] = 0;
+        env->features[FEAT_XSAVE_XSS_HI] = 0;
         return;
         return;
     }
     }
 
 
@@ -6945,9 +6947,9 @@ static void x86_cpu_enable_xsave_components(X86CPU *cpu)
     }
     }
 
 
     env->features[FEAT_XSAVE_XCR0_LO] = mask & CPUID_XSTATE_XCR0_MASK;
     env->features[FEAT_XSAVE_XCR0_LO] = mask & CPUID_XSTATE_XCR0_MASK;
-    env->features[FEAT_XSAVE_XCR0_HI] = mask >> 32;
+    env->features[FEAT_XSAVE_XCR0_HI] = (mask & CPUID_XSTATE_XCR0_MASK) >> 32;
     env->features[FEAT_XSAVE_XSS_LO] = mask & CPUID_XSTATE_XSS_MASK;
     env->features[FEAT_XSAVE_XSS_LO] = mask & CPUID_XSTATE_XSS_MASK;
-    env->features[FEAT_XSAVE_XSS_HI] = mask >> 32;
+    env->features[FEAT_XSAVE_XSS_HI] = (mask & CPUID_XSTATE_XSS_MASK) >> 32;
 }
 }
 
 
 /***** Steps involved on loading and filtering CPUID data
 /***** Steps involved on loading and filtering CPUID data

+ 2 - 5
target/i386/kvm/kvm.c

@@ -1914,6 +1914,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
         }
         }
         case 0x1f:
         case 0x1f:
             if (env->nr_dies < 2) {
             if (env->nr_dies < 2) {
+                cpuid_i--;
                 break;
                 break;
             }
             }
             /* fallthrough */
             /* fallthrough */
@@ -1925,10 +1926,6 @@ int kvm_arch_init_vcpu(CPUState *cs)
                     break;
                     break;
                 }
                 }
 
 
-                if (i == 0x1f && j == 64) {
-                    break;
-                }
-
                 c->function = i;
                 c->function = i;
                 c->flags = KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
                 c->flags = KVM_CPUID_FLAG_SIGNIFCANT_INDEX;
                 c->index = j;
                 c->index = j;
@@ -1954,7 +1951,6 @@ int kvm_arch_init_vcpu(CPUState *cs)
                 c = &cpuid_data.entries[cpuid_i++];
                 c = &cpuid_data.entries[cpuid_i++];
             }
             }
             break;
             break;
-        case 0x7:
         case 0x12:
         case 0x12:
             for (j = 0; ; j++) {
             for (j = 0; ; j++) {
                 c->function = i;
                 c->function = i;
@@ -1974,6 +1970,7 @@ int kvm_arch_init_vcpu(CPUState *cs)
                 c = &cpuid_data.entries[cpuid_i++];
                 c = &cpuid_data.entries[cpuid_i++];
             }
             }
             break;
             break;
+        case 0x7:
         case 0x14:
         case 0x14:
         case 0x1d:
         case 0x1d:
         case 0x1e: {
         case 0x1e: {

+ 6 - 5
target/i386/tcg/translate.c

@@ -1507,12 +1507,13 @@ static bool check_iopl(DisasContext *s)
 /* if d == OR_TMP0, it means memory operand (address in A0) */
 /* if d == OR_TMP0, it means memory operand (address in A0) */
 static void gen_op(DisasContext *s1, int op, MemOp ot, int d)
 static void gen_op(DisasContext *s1, int op, MemOp ot, int d)
 {
 {
+    /* Invalid lock prefix when destination is not memory or OP_CMPL. */
+    if ((d != OR_TMP0 || op == OP_CMPL) && s1->prefix & PREFIX_LOCK) {
+        gen_illegal_opcode(s1);
+        return;
+    }
+
     if (d != OR_TMP0) {
     if (d != OR_TMP0) {
-        if (s1->prefix & PREFIX_LOCK) {
-            /* Lock prefix when destination is not memory.  */
-            gen_illegal_opcode(s1);
-            return;
-        }
         gen_op_mov_v_reg(s1, ot, s1->T0, d);
         gen_op_mov_v_reg(s1, ot, s1->T0, d);
     } else if (!(s1->prefix & PREFIX_LOCK)) {
     } else if (!(s1->prefix & PREFIX_LOCK)) {
         gen_op_ld_v(s1, ot, s1->T0, s1->A0);
         gen_op_ld_v(s1, ot, s1->T0, s1->A0);