mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dave Hansen <dave@sr71.net>
To: linux-kernel@vger.kernel.org
Cc: tglx@linutronix.de, x86@kernel.org, Dave Hansen <dave@sr71.net>,
	dave.hansen@linux.intel.com
Subject: [PATCH 1/2] x86, mpx: update documentation
Date: Fri, 12 Dec 2014 10:38:35 -0800	[thread overview]
Message-ID: <20141212183835.8C581B3E@viggo.jf.intel.com> (raw)
In-Reply-To: <20141212183834.1F8D01E5@viggo.jf.intel.com>


From: Dave Hansen <dave.hansen@linux.intel.com>

I was writing some MPX test programs and realized that the
current design makes it tricky.  I did something like:

	bndcfgu |= bnd_dir | BNDCFGU_ENABLE;
	xrstor();
	printf("xrstor done");
	// #BR bounds exception here
	prctl(MPX_ENABLE_MANAGEMENT);

and then compiled the app with "-fcheck-pointer-bounds -mmpx"
to enable MPX instrumentation.

The problem is that there is MPX instrumentation inserted in
to the area of the printf().  The kernel gets a bounds exception
and since management isn't yet enabled, it SIGSEGV's.

Add a bit to the documentation to explain a way around this and
where apps need to be careful.

Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com>
---

 b/Documentation/x86/intel_mpx.txt |   12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff -puN Documentation/x86/intel_mpx.txt~mpx-doc-update Documentation/x86/intel_mpx.txt
--- a/Documentation/x86/intel_mpx.txt~mpx-doc-update	2014-12-12 10:12:53.179922346 -0800
+++ b/Documentation/x86/intel_mpx.txt	2014-12-12 10:12:53.183922527 -0800
@@ -30,9 +30,15 @@ is how we expect the compiler, applicati
    instrumentation as well as some setup code called early after the app
    starts. New instruction prefixes are noops for old CPUs.
 2) That setup code allocates (virtual) space for the "bounds directory",
-   points the "bndcfgu" register to the directory and notifies the kernel
-   (via the new prctl(PR_MPX_ENABLE_MANAGEMENT)) that the app will be using
-   MPX.
+   points the "bndcfgu" register to the directory (must also set the valid
+   bit) and notifies the kernel (via the new prctl(PR_MPX_ENABLE_MANAGEMENT))
+   that the app will be using MPX.  The app must be careful not to access
+   the bounds tables between the time when it populates "bndcfgu" and
+   when it calls the prctl().  This might be hard to guarantee if the app
+   is compiled with MPX.  You can add "__attribute__((bnd_legacy))" to
+   the function to disable MPX instrumentation to help guarantee this.
+   Also be careful not to call out to any other code which might be
+   MPX-instrumented.
 3) The kernel detects that the CPU has MPX, allows the new prctl() to
    succeed, and notes the location of the bounds directory. Userspace is
    expected to keep the bounds directory at that locationWe note it
_

  reply	other threads:[~2014-12-12 18:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-12 18:38 [PATCH 0/2] x86, mpx: Updates for 3.19 Dave Hansen
2014-12-12 18:38 ` Dave Hansen [this message]
2014-12-15 15:01   ` [tip:x86/mpx] x86, mpx: Update documentation tip-bot for Dave Hansen
2014-12-12 18:38 ` [PATCH 2/2] x86, mpx: Give MPX a real config option prompt Dave Hansen
2014-12-15 15:02   ` [tip:x86/mpx] " tip-bot for Dave Hansen

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=20141212183835.8C581B3E@viggo.jf.intel.com \
    --to=dave@sr71.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.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