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: Keir Fraser <keir@xen.org>,
	Ian Campbell <ian.campbell@citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Tim Deegan <tim@xen.org>,
	Stefano Stabellini <stefano.stabellini@citrix.com>,
	Jan Beulich <JBeulich@suse.com>
Subject: [PATCH 3/3] common/spinlock: Ensure the flags parameter is wide enough
Date: Mon, 21 Oct 2013 14:41:33 +0100	[thread overview]
Message-ID: <1382362893-12603-4-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1382362893-12603-1-git-send-email-andrew.cooper3@citrix.com>

Because of the construction of spin_lock_irq() (and varients), the flags
parameter could be trucated.  Use a BUILD_BUG_ON() to verify the width of the
parameter.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
CC: Keir Fraser <keir@xen.org>
CC: Jan Beulich <JBeulich@suse.com>
CC: Ian Campbell <ian.campbell@citrix.com>
CC: Stefano Stabellini <stefano.stabellini@citrix.com>
CC: Tim Deegan <tim@xen.org>

---

The previous patch in the series fixes the compilation issues I found as a
result of this patch, but I have not tested on arm.  I therefore request an
explicit ack from an arm maintainer before this is committed.
---
 xen/include/xen/spinlock.h |   18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h
index 76581c5..12b0a89 100644
--- a/xen/include/xen/spinlock.h
+++ b/xen/include/xen/spinlock.h
@@ -188,7 +188,11 @@ int _rw_is_write_locked(rwlock_t *lock);
 
 #define spin_lock(l)                  _spin_lock(l)
 #define spin_lock_irq(l)              _spin_lock_irq(l)
-#define spin_lock_irqsave(l, f)       ((f) = _spin_lock_irqsave(l))
+#define spin_lock_irqsave(l, f)                                 \
+    ({                                                          \
+        BUILD_BUG_ON(sizeof(f) != sizeof(unsigned long));       \
+        ((f) = _spin_lock_irqsave(l));                          \
+    })
 
 #define spin_unlock(l)                _spin_unlock(l)
 #define spin_unlock_irq(l)            _spin_unlock_irq(l)
@@ -220,7 +224,11 @@ int _rw_is_write_locked(rwlock_t *lock);
 
 #define read_lock(l)                  _read_lock(l)
 #define read_lock_irq(l)              _read_lock_irq(l)
-#define read_lock_irqsave(l, f)       ((f) = _read_lock_irqsave(l))
+#define read_lock_irqsave(l, f)                                 \
+    ({                                                          \
+        BUILD_BUG_ON(sizeof(f) != sizeof(unsigned long));       \
+        ((f) = _read_lock_irqsave(l));                          \
+    })
 
 #define read_unlock(l)                _read_unlock(l)
 #define read_unlock_irq(l)            _read_unlock_irq(l)
@@ -229,7 +237,11 @@ int _rw_is_write_locked(rwlock_t *lock);
 
 #define write_lock(l)                 _write_lock(l)
 #define write_lock_irq(l)             _write_lock_irq(l)
-#define write_lock_irqsave(l, f)      ((f) = _write_lock_irqsave(l))
+#define write_lock_irqsave(l, f)                                \
+    ({                                                          \
+        BUILD_BUG_ON(sizeof(f) != sizeof(unsigned long));       \
+        ((f) = _write_lock_irqsave(l));                         \
+    })
 #define write_trylock(l)              _write_trylock(l)
 
 #define write_unlock(l)               _write_unlock(l)
-- 
1.7.10.4

  parent reply	other threads:[~2013-10-21 13:41 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     ` [Patch 1/3 v2] " Andrew Cooper
2013-10-21 18:18       ` 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 ` Andrew Cooper [this message]
2013-10-21 15:15   ` [PATCH 3/3] common/spinlock: Ensure the flags parameter is wide enough 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=1382362893-12603-4-git-send-email-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=ian.campbell@citrix.com \
    --cc=keir@xen.org \
    --cc=stefano.stabellini@citrix.com \
    --cc=tim@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).