From: tip-bot for David Woodhouse <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org,
dwmw2@infradead.org, tglx@linutronix.de, hpa@linux.intel.com,
David.Woodhouse@intel.com
Subject: [tip:x86/build] x86, boot: Fix word-size assumptions in has_eflag () inline asm
Date: Thu, 30 Jan 2014 08:10:17 -0800 [thread overview]
Message-ID: <tip-5fbbc25a99d680feca99a3095f0440f65d4307cc@git.kernel.org> (raw)
In-Reply-To: <1391079628.26079.82.camel@shinybook.infradead.org>
Commit-ID: 5fbbc25a99d680feca99a3095f0440f65d4307cc
Gitweb: http://git.kernel.org/tip/5fbbc25a99d680feca99a3095f0440f65d4307cc
Author: David Woodhouse <dwmw2@infradead.org>
AuthorDate: Thu, 30 Jan 2014 11:00:28 +0000
Committer: H. Peter Anvin <hpa@linux.intel.com>
CommitDate: Thu, 30 Jan 2014 08:04:32 -0800
x86, boot: Fix word-size assumptions in has_eflag() inline asm
Commit dd78b97367bd575918204cc89107c1479d3fc1a7 ("x86, boot: Move CPU
flags out of cpucheck") introduced ambiguous inline asm in the
has_eflag() function. In 16-bit mode want the instruction to be
'pushfl', but we just say 'pushf' and hope the compiler does what we
wanted.
When building with 'clang -m16', it won't, because clang doesn't use
the horrid '.code16gcc' hack that even 'gcc -m16' uses internally.
Say what we mean and don't make the compiler make assumptions.
[ hpa: ideally we would be able to use the gcc %zN construct here, but
that is broken for 64-bit integers in gcc < 4.5.
The code with plain "pushf/popf" is fine for 32- or 64-bit mode, but
not for 16-bit mode; in 16-bit mode those are 16-bit instructions in
.code16 mode, and 32-bit instructions in .code16gcc mode. ]
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Link: http://lkml.kernel.org/r/1391079628.26079.82.camel@shinybook.infradead.org
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
---
arch/x86/boot/cpuflags.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/arch/x86/boot/cpuflags.c b/arch/x86/boot/cpuflags.c
index a9fcb7c..431fa5f 100644
--- a/arch/x86/boot/cpuflags.c
+++ b/arch/x86/boot/cpuflags.c
@@ -28,20 +28,35 @@ static int has_fpu(void)
return fsw == 0 && (fcw & 0x103f) == 0x003f;
}
+/*
+ * For building the 16-bit code we want to explicitly specify 32-bit
+ * push/pop operations, rather than just saying 'pushf' or 'popf' and
+ * letting the compiler choose. But this is also included from the
+ * compressed/ directory where it may be 64-bit code, and thus needs
+ * to be 'pushfq' or 'popfq' in that case.
+ */
+#ifdef __x86_64__
+#define PUSHF "pushfq"
+#define POPF "popfq"
+#else
+#define PUSHF "pushfl"
+#define POPF "popfl"
+#endif
+
int has_eflag(unsigned long mask)
{
unsigned long f0, f1;
- asm volatile("pushf \n\t"
- "pushf \n\t"
+ asm volatile(PUSHF " \n\t"
+ PUSHF " \n\t"
"pop %0 \n\t"
"mov %0,%1 \n\t"
"xor %2,%1 \n\t"
"push %1 \n\t"
- "popf \n\t"
- "pushf \n\t"
+ POPF " \n\t"
+ PUSHF " \n\t"
"pop %1 \n\t"
- "popf"
+ POPF
: "=&r" (f0), "=&r" (f1)
: "ri" (mask));
next prev parent reply other threads:[~2014-01-30 16:11 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-03 20:53 [kernel-hardening] [PATCH v7 0/7] Kernel base address randomization on x86 Kees Cook
2013-10-03 20:53 ` Kees Cook
2013-10-03 20:53 ` [kernel-hardening] [PATCH 1/7] x86, boot: move CPU flags out of cpucheck Kees Cook
2013-10-03 20:53 ` Kees Cook
2014-01-29 12:01 ` [kernel-hardening] [PATCH] x86, boot: fix word-size assumptions in has_eflag() inline asm David Woodhouse
2014-01-29 12:01 ` David Woodhouse
2014-01-29 16:57 ` [kernel-hardening] " Kees Cook
2014-01-29 16:57 ` Kees Cook
2014-01-29 17:13 ` [tip:x86/build] x86, boot: Fix word-size assumptions in has_eflag () " tip-bot for David Woodhouse
2014-01-30 9:09 ` Ingo Molnar
2014-01-30 10:28 ` Woodhouse, David
2014-01-30 11:00 ` [PATCH v2] " David Woodhouse
2014-01-30 13:45 ` H. Peter Anvin
2014-01-30 14:08 ` David Woodhouse
2014-01-30 16:10 ` tip-bot for David Woodhouse [this message]
2014-01-30 23:01 ` David Rientjes
2013-10-03 20:53 ` [kernel-hardening] [PATCH 2/7] x86, kaslr: return location from decompress_kernel Kees Cook
2013-10-03 20:53 ` Kees Cook
2013-10-03 20:53 ` [kernel-hardening] [PATCH 3/7] x86, kaslr: find minimum safe relocation position Kees Cook
2013-10-03 20:53 ` Kees Cook
2013-10-03 22:23 ` [kernel-hardening] " H. Peter Anvin
2013-10-03 22:23 ` H. Peter Anvin
2013-10-03 22:43 ` [kernel-hardening] " Kees Cook
2013-10-03 22:43 ` Kees Cook
2013-10-03 22:46 ` [kernel-hardening] " H. Peter Anvin
2013-10-03 22:46 ` H. Peter Anvin
2013-10-03 20:53 ` [kernel-hardening] [PATCH 4/7] x86, kaslr: select random base offset Kees Cook
2013-10-03 20:53 ` Kees Cook
2013-10-03 20:53 ` [kernel-hardening] [PATCH 5/7] x86, kaslr: select memory region from e820 maps Kees Cook
2013-10-03 20:53 ` Kees Cook
2013-10-03 20:53 ` [kernel-hardening] [PATCH 6/7] x86, kaslr: report kernel offset on panic Kees Cook
2013-10-03 20:53 ` Kees Cook
2013-10-03 20:53 ` [kernel-hardening] [PATCH 7/7] x86, kaslr: raise max positions to 1GiB on x86_64 Kees Cook
2013-10-03 20:53 ` Kees Cook
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=tip-5fbbc25a99d680feca99a3095f0440f65d4307cc@git.kernel.org \
--to=tipbot@zytor.com \
--cc=David.Woodhouse@intel.com \
--cc=dwmw2@infradead.org \
--cc=hpa@linux.intel.com \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=tglx@linutronix.de \
/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.