All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Biggers <ebiggers@kernel.org>
To: qemu-devel@nongnu.org
Cc: Ard Biesheuvel <ardb@kernel.org>,
	"Jason A. Donenfeld" <Jason@zx2c4.com>,
	Guenter Roeck <linux@roeck-us.net>
Subject: [QEMU bug] [x86_64] Incorrect emulation of vinserti128 instruction
Date: Thu, 24 Jul 2025 15:50:31 -0700	[thread overview]
Message-ID: <20250724225031.GA1409@quark> (raw)

Another QEMU bug found by the Linux kernel's crypto tests
(https://lore.kernel.org/linux-crypto/20250724173657.GB26800@sol/):

When KVM is disabled, QEMU's implementation of the AVX2 instruction
'vinserti128' with a memory source operand incorrectly reads 32 bytes
from memory.  This differs from the real CPUs which read only 16 bytes,
as per the spec
(https://www.felixcloutier.com/x86/vinserti128:vinserti32x4:vinserti64x2:vinserti32x8:vinserti64x4)
which defines the operand as xmm3/m128.

This can be reproduced by the recently-added poly1305_kunit test in
linux-next, or alternatively by the following userspace program:

    #include <stddef.h>
    #include <sys/mman.h>
    int main()
    {
            unsigned char *buf = mmap(NULL, 8192, PROT_READ|PROT_WRITE,
                                      MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);

            munmap(buf + 4096, 4096);
            asm volatile("vinserti128 $1, %0, %%ymm0, %%ymm0\n"
                         :: "m" (buf[4080]));
    }

That executes vinserti128 with a memory operand with 16 valid bytes
followed by an unmapped page.  This works fine on the real CPUs, but it
segfaults when run with qemu-x86_64.  To avoid the segfault in QEMU, we
have to go down to buf[4064], which implies it reads 32 bytes.

This bug exists on the master branch of QEMU as well as v8.2.10 and
v7.2.19.  So probably it's not new.

- Eric


             reply	other threads:[~2025-07-24 22:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-24 22:50 Eric Biggers [this message]
2025-07-24 23:16 ` [QEMU bug] [x86_64] Incorrect emulation of vinserti128 instruction Eric Biggers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250724225031.GA1409@quark \
    --to=ebiggers@kernel.org \
    --cc=Jason@zx2c4.com \
    --cc=ardb@kernel.org \
    --cc=linux@roeck-us.net \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.