kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Jacob Xu <jacobhxu@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Jim Mattson <jmattson@google.com>, kvm list <kvm@vger.kernel.org>
Subject: Re: [kvm-unit-tests PATCH v2] x86: Do not assign values to unaligned pointer to 128 bits
Date: Thu, 6 May 2021 19:25:26 +0000	[thread overview]
Message-ID: <YJRCpv9O/Q24DKmZ@google.com> (raw)
In-Reply-To: <CAJ5mJ6gYmwXEQZASk8A_Ozt6asW6ZDTnDs83nCfLNTa62x7n+g@mail.gmail.com>

On Thu, May 06, 2021, Jacob Xu wrote:
> > memset() takes a void *, which it casts to an char, i.e. it works on one byte at
> a time.
> Huh, TIL. Based on this I'd thought that I don't need a cast at all,
> but doing so actually results in a movaps instruction.

Ewwww.  That's likely because emulator.c does:

  #define memset __builtin_memset

and the compiler is clever enough to know that __attribute__((vector_size(16)))
means the variable is (supposed to be) aligned.

> I've changed the cast back to (uint8_t *).

I assume removing the above #define and grabbing memset() from string.c fixes
the movaps generation?  If so, that has my vote, as opposed to fudging around
the compiler by casting to uint8_t *.

As evidenced by this issue, using the compiler's memset() in kvm-unit-tests seems
inherently dangerous since the tests are often doing intentionally stupid things.

  reply	other threads:[~2021-05-06 19:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-06 18:49 [kvm-unit-tests PATCH v2] x86: Do not assign values to unaligned pointer to 128 bits Jacob Xu
2021-05-06 18:57 ` Sean Christopherson
2021-05-06 19:13   ` Jacob Xu
2021-05-06 19:25     ` Sean Christopherson [this message]
2021-05-06 20:11     ` Jim Mattson
2021-05-11  1:47       ` Jacob Xu

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=YJRCpv9O/Q24DKmZ@google.com \
    --to=seanjc@google.com \
    --cc=jacobhxu@google.com \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).