mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Ian Rogers' <irogers@google.com>, "hpa@zytor.com" <hpa@zytor.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	x86 <x86@kernel.org>,
	"Peter Zijlstra (Intel)" <peterz@infradead.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	"Josh Poimboeuf" <jpoimboe@redhat.com>,
	LKML <linux-kernel@vger.kernel.org>,
	"Adrian Hunter" <adrian.hunter@intel.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Numfor Mbiziwo-Tiapo <nums@google.com>
Subject: RE: [PATCH v2] x86/insn, tools/x86: Fix some potential undefined behavior.
Date: Fri, 16 Oct 2020 08:24:38 +0000	[thread overview]
Message-ID: <699073ad09bf4882861003a5da6d6b3c@AcuMS.aculab.com> (raw)
In-Reply-To: <CAP-5=fXRBLwui9wdDvqrB0p4TaWVSth4cuH+2TwXTq5TtgL_NQ@mail.gmail.com>

From: Ian Rogers
> Sent: 15 October 2020 22:47
...
> The decoder is a shared code and using unaligned macros makes life
> hard for the other users of the code. Memcpy is the "standard"
> workaround for this kind of undefined behavior.
> https://lore.kernel.org/lkml/e4269cb2-d8e6-da26-6afd-a9df72d4be36@intel.com/

You can't always use memcpy() to copy unaligned data.
If the compiler can find any reason why the misaligned address
should be aligned (eg because it's type prior to some casts
requires alignment) it will use word-sized accesses that will fault.

Now in this specific code the pointers are probably all 'char *'
so have alignment 1 - so memcpy() will DTRT.

But it may generate an expensive function call.

There are 'read unaligned 32bit' (etc) macros out there.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

  reply	other threads:[~2020-10-16  8:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-15 16:12 Ian Rogers
2020-10-15 21:34 ` hpa
2020-10-15 21:47   ` Ian Rogers
2020-10-16  8:24     ` David Laight [this message]
2020-10-16  8:47   ` David Laight
2020-10-16  9:37   ` Peter Zijlstra
2020-10-16  1:33 ` Masami Hiramatsu

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=699073ad09bf4882861003a5da6d6b3c@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.com \
    --cc=irogers@google.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=nums@google.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome