kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jim Mattson <jmattson@google.com>
To: Jacob Xu <jacobhxu@google.com>
Cc: Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.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 13:11:14 -0700	[thread overview]
Message-ID: <CALMp9eQoscqr9p5ayzYkKXHNMcQthntJr_BJ+egEdriEQUqSTw@mail.gmail.com> (raw)
In-Reply-To: <CAJ5mJ6gYmwXEQZASk8A_Ozt6asW6ZDTnDs83nCfLNTa62x7n+g@mail.gmail.com>

On Thu, May 6, 2021 at 12:14 PM Jacob Xu <jacobhxu@google.com> 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.
> I've changed the cast back to (uint8_t *).

I'm pretty sure you're just getting lucky. If 'mem' is not 16-byte
aligned, the behavior of the code is undefined. The compiler does not
have to discard what it can infer about the alignment just because you
cast 'mem' to a type with weaker alignment constraints.

Why does 'mem' need to have type 'sse_union *'? Why can't it just be
declared as 'uint8_t *'? Just add a "memory" clobbers to the inline
asm statements that use 'mem' as an SSE operand.

Of course, passing it as an argument to sseeq() also implies 16-byte
alignment. Perhaps sseeq should take uint32_t pointers as arguments
rather than sse_union pointers. I'm not convinced that the sse_union
buys us anything other than trouble.

  parent reply	other threads:[~2021-05-06 20:11 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
2021-05-06 20:11     ` Jim Mattson [this message]
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=CALMp9eQoscqr9p5ayzYkKXHNMcQthntJr_BJ+egEdriEQUqSTw@mail.gmail.com \
    --to=jmattson@google.com \
    --cc=jacobhxu@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.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).