xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>,
	Keir Fraser <keir@xen.org>, Jan Beulich <JBeulich@suse.com>
Subject: [Patch 1/3 v2] x86/irq: local_irq_restore() should not blindly popf
Date: Mon, 21 Oct 2013 17:33:36 +0100	[thread overview]
Message-ID: <1382373216-31496-1-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <5265595F02000078000FC78E@nat28.tlf.novell.com>

local_irq_restore() should only be concerned with possibly changing the
interrupt flag.  A blind popf could corrupt other system flags.

While playing in this area, fixup an opencoded use of X86_EFLAGS_IF.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Keir Fraser <keir@xen.org>
CC: Jan Beulich <JBeulich@suse.com>

---

This is rather more RFC.  It boots and runs VMs, so I am fairly sure it is
functionally correct, but I cant help feeling there might be a neater way to
do the inline assembly.  Suggestions welcome.
---
 xen/include/asm-x86/system.h |   11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/xen/include/asm-x86/system.h b/xen/include/asm-x86/system.h
index 6ab7d56..ff52671 100644
--- a/xen/include/asm-x86/system.h
+++ b/xen/include/asm-x86/system.h
@@ -3,6 +3,7 @@
 
 #include <xen/lib.h>
 #include <xen/bitops.h>
+#include <asm/processor.h>
 
 #define read_segment_register(name)                             \
 ({  u16 __sel;                                                  \
@@ -159,15 +160,19 @@ static always_inline unsigned long __cmpxchg(
 #define local_irq_restore(x)                                     \
 ({                                                               \
     BUILD_BUG_ON(sizeof(x) != sizeof(long));                     \
-    asm volatile ( "push" __OS " %0 ; popf" __OS                 \
-                   : : "g" (x) : "memory", "cc" );               \
+    asm volatile (                                               \
+    "pushf" __OS "\n\t"                                          \
+    "and" __OS " %0, (%%" __OP "sp)\n\t"                         \
+    "orw %1, (%%" __OP "sp)\n\t"                                 \
+    "popf" __OS "\n\t" : : "g" ( ~X86_EFLAGS_IF ),               \
+                           "g" ( x & X86_EFLAGS_IF ) );          \
 })
 
 static inline int local_irq_is_enabled(void)
 {
     unsigned long flags;
     local_save_flags(flags);
-    return !!(flags & (1<<9)); /* EFLAGS_IF */
+    return !!(flags & X86_EFLAGS_IF);
 }
 
 #define BROKEN_ACPI_Sx          0x0001
-- 
1.7.10.4

  reply	other threads:[~2013-10-21 16:33 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-21 13:41 [PATCH 0/3] irqsave/restore improvements Andrew Cooper
2013-10-21 13:41 ` [PATCH 1/3] x86/irq: local_irq_restore() should not blindly popf Andrew Cooper
2013-10-21 13:58   ` David Vrabel
2013-10-21 14:09     ` Keir Fraser
2013-10-21 14:32       ` Jan Beulich
2013-10-21 15:24         ` Jan Beulich
2013-10-21 14:42   ` Jan Beulich
2013-10-21 16:33     ` Andrew Cooper [this message]
2013-10-21 18:18       ` [Patch 1/3 v2] " Keir Fraser
2013-10-21 18:30         ` Andrew Cooper
2013-10-21 18:37           ` Keir Fraser
2013-10-22  8:35             ` Jan Beulich
2013-10-22  8:56               ` Andrew Cooper
2013-10-22  9:28                 ` Jan Beulich
2013-10-22 10:14                   ` [PATCH 1/3 v3] " Andrew Cooper
2013-10-22 13:27                     ` Keir Fraser
2013-10-29 14:53                   ` [Patch 1/3 v2] " Jan Beulich
2013-10-21 13:41 ` [PATCH 2/3] xen: Widen flags parameter for spinlock_irqsave() and friends Andrew Cooper
2013-10-21 13:41 ` [PATCH 3/3] common/spinlock: Ensure the flags parameter is wide enough Andrew Cooper
2013-10-21 15:15   ` Ian Campbell
2013-10-21 14:08 ` [PATCH 0/3] irqsave/restore improvements Keir Fraser

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=1382373216-31496-1-git-send-email-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=keir@xen.org \
    --cc=xen-devel@lists.xen.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;
as well as URLs for NNTP newsgroup(s).