From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756243Ab2EKHig (ORCPT ); Fri, 11 May 2012 03:38:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52142 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751770Ab2EKHid (ORCPT ); Fri, 11 May 2012 03:38:33 -0400 Date: Fri, 11 May 2012 10:38:34 +0300 From: "Michael S. Tsirkin" To: x86@kernel.org, kvm@vger.kernel.org Cc: Ingo Molnar , "H. Peter Anvin" , Avi Kivity , Marcelo Tosatti , gleb@redhat.com, Linus Torvalds , linux-kernel@vger.kernel.org Subject: [PATCHv2 6/7] x86/bitops: note on __test_and_clear_bit atomicity Message-ID: <904e4b3e1d908f25ae097d0e2dc556da46c59f78.1336679924.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Mutt-Fcc: =sent Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org __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 --- arch/x86/include/asm/bitops.h | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h index c9c70ea..86f3a1e 100644 --- a/arch/x86/include/asm/bitops.h +++ b/arch/x86/include/asm/bitops.h @@ -264,6 +264,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