All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lscpu: clean up vmware inline asm
@ 2014-08-05 22:59 Mike Frysinger
  2014-08-11 12:54 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Frysinger @ 2014-08-05 22:59 UTC (permalink / raw)
  To: util-linux

This code is not PIC clean which means it fails to build on hardened
32bit x86 systems (i.e. building as PIE).

While here, optimize the existing cpuid logic slightly.

URL: https://bugs.gentoo.org/518936
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 sys-utils/lscpu.c | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 062dff5..9965eeb 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -546,10 +546,9 @@ cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx,
 	__asm__(
 #if defined(__PIC__) && defined(__i386__)
 		/* x86 PIC cannot clobber ebx -- gcc bitches */
-		"pushl %%ebx;"
+		"xchg %%ebx, %%esi;"
 		"cpuid;"
-		"movl %%ebx, %%esi;"
-		"popl %%ebx;"
+		"xchg %%esi, %%ebx;"
 		: "=S" (*ebx),
 #else
 		"cpuid;"
@@ -656,12 +655,29 @@ read_hypervisor_powerpc(struct lscpu_desc *desc)
 #define VMWARE_BDOOR_PORT           0x5658
 #define VMWARE_BDOOR_CMD_GETVERSION 10
 
-#define VMWARE_BDOOR(eax, ebx, ecx, edx)                                  \
-        __asm__("inl (%%dx), %%eax" :                                     \
-               "=a"(eax), "=c"(ecx), "=d"(edx), "=b"(ebx) :               \
-               "0"(VMWARE_BDOOR_MAGIC), "1"(VMWARE_BDOOR_CMD_GETVERSION), \
-               "2"(VMWARE_BDOOR_PORT), "3"(0) :                           \
-               "memory");
+static inline
+void vmware_bdoor(uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
+{
+	__asm__(
+#if defined(__PIC__) && defined(__i386__)
+		/* x86 PIC cannot clobber ebx -- gcc bitches */
+		"xchg %%ebx, %%esi;"
+		"inl (%%dx), %%eax;"
+		"xchg %%esi, %%ebx;"
+		: "=S" (*ebx),
+#else
+		"inl (%%dx), %%eax;"
+		: "=b" (*ebx),
+#endif
+		  "=a" (*eax),
+		  "=c" (*ecx),
+		  "=d" (*edx)
+		: "0" (VMWARE_BDOOR_MAGIC),
+		  "1" (VMWARE_BDOOR_CMD_GETVERSION),
+		  "2" (VMWARE_BDOOR_PORT),
+		  "3" (0)
+		: "memory");
+}
 
 static jmp_buf segv_handler_env;
 
@@ -697,7 +713,7 @@ is_vmware_platform(void)
 	if (sigaction(SIGSEGV, &act, &oact))
 		err(EXIT_FAILURE, _("error: can not set signal handler"));
 
-	VMWARE_BDOOR(eax, ebx, ecx, edx);
+	vmware_bdoor(&eax, &ebx, &ecx, &edx);
 
 	if (sigaction(SIGSEGV, &oact, NULL))
 		err(EXIT_FAILURE, _("error: can not restore signal handler"));
-- 
2.0.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] lscpu: clean up vmware inline asm
  2014-08-05 22:59 [PATCH] lscpu: clean up vmware inline asm Mike Frysinger
@ 2014-08-11 12:54 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2014-08-11 12:54 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: util-linux

On Tue, Aug 05, 2014 at 06:59:50PM -0400, Mike Frysinger wrote:
>  sys-utils/lscpu.c | 36 ++++++++++++++++++++++++++----------
>  1 file changed, 26 insertions(+), 10 deletions(-)

 Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-08-11 12:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-05 22:59 [PATCH] lscpu: clean up vmware inline asm Mike Frysinger
2014-08-11 12:54 ` Karel Zak

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.