From: "Michael S. Tsirkin" <mst@redhat.com>
To: x86@kernel.org, kvm@vger.kernel.org
Cc: Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
Avi Kivity <avi@redhat.com>,
Marcelo Tosatti <mtosatti@redhat.com>,
gleb@redhat.com, Linus Torvalds <torvalds@linux-foundation.org>,
linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCHv7 4/8] x86/bitops: note on __test_and_clear_bit atomicity
Date: Thu, 14 Jun 2012 16:53:21 +0300 [thread overview]
Message-ID: <ea455fcb519d918cbda44926bca5c4d45cc04ffb.1339681762.git.mst@redhat.com> (raw)
In-Reply-To: <cover.1339681762.git.mst@redhat.com>
__test_and_clear_bit is actually atomic with respect
to the local CPU. Add a note saying that KVM on x86
relies on this behaviour so people don't accidentaly break it.
Also warn not to rely on this in portable code.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
arch/x86/include/asm/bitops.h | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
index 47f9eff..75e3787 100644
--- a/arch/x86/include/asm/bitops.h
+++ b/arch/x86/include/asm/bitops.h
@@ -266,6 +266,13 @@ static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
* This operation is non-atomic and can be reordered.
* If two examples of this operation race, one can appear to succeed
* but actually fail. You must protect multiple accesses with a lock.
+ *
+ * Note: the operation is performed atomically with respect to
+ * the local CPU, but not other CPUs. Portable code should not
+ * rely on this behaviour.
+ * KVM relies on this behaviour on x86 for modifying memory that is also
+ * accessed from a hypervisor on the same CPU if running in a VM: don't change
+ * this without also updating arch/x86/kernel/kvm.c
*/
static inline int __test_and_clear_bit(int nr, volatile unsigned long *addr)
{
--
MST
next prev parent reply other threads:[~2012-06-14 13:52 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-14 13:52 [PATCHv7 0/8] kvm: eoi optimization support Michael S. Tsirkin
2012-06-14 13:52 ` [PATCHv7 1/8] kvm: document lapic regs field Michael S. Tsirkin
2012-06-14 13:53 ` [PATCHv7 2/8] kvm: optimize ISR lookups Michael S. Tsirkin
2012-06-14 13:53 ` [PATCHv7 3/8] kvm_para: guest side for eoi avoidance Michael S. Tsirkin
2012-06-18 14:17 ` Avi Kivity
2012-06-18 14:50 ` Michael S. Tsirkin
2012-06-18 15:01 ` Avi Kivity
2012-06-18 17:15 ` Michael S. Tsirkin
2012-06-14 13:53 ` Michael S. Tsirkin [this message]
2012-06-14 13:53 ` [PATCHv7 5/8] kvm: eoi msi documentation Michael S. Tsirkin
2012-06-18 14:20 ` Avi Kivity
2012-06-18 14:56 ` Michael S. Tsirkin
2012-06-18 15:03 ` Avi Kivity
2012-06-18 16:01 ` Michael S. Tsirkin
2012-06-18 15:00 ` Michael S. Tsirkin
2012-06-14 13:53 ` [PATCHv7 6/8] kvm: only sync when attention bits set Michael S. Tsirkin
2012-06-14 13:53 ` [PATCHv7 7/8] kvm: rearrange injection cancelling code Michael S. Tsirkin
2012-06-14 13:53 ` [PATCHv7 8/8] kvm: host side for eoi optimization Michael S. Tsirkin
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=ea455fcb519d918cbda44926bca5c4d45cc04ffb.1339681762.git.mst@redhat.com \
--to=mst@redhat.com \
--cc=avi@redhat.com \
--cc=gleb@redhat.com \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mtosatti@redhat.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--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
all inboxes | Powered by JetHome®