Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756795AbcJNTpC (ORCPT ); Fri, 14 Oct 2016 15:45:02 -0400 Received: from mail-pf0-f196.google.com ([209.85.192.196]:32979 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754025AbcJNTo4 (ORCPT ); Fri, 14 Oct 2016 15:44:56 -0400 Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 10.0 \(3226\)) Subject: Re: [PATCH 1/5] KVM: x86: avoid atomic operations on APICv vmentry From: Nadav Amit In-Reply-To: <770436977.3704467.1476471398385.JavaMail.zimbra@redhat.com> Date: Fri, 14 Oct 2016 12:44:53 -0700 Cc: LKML , KVM , =?utf-8?B?UmFkaW0gS3LEjW3DocWZ?= , Yang Zhang , feng wu , mst@redhat.com Message-Id: <9B7F4808-2294-426D-B463-CEB188CED2E0@gmail.com> References: <1476469291-5039-1-git-send-email-pbonzini@redhat.com> <1476469291-5039-2-git-send-email-pbonzini@redhat.com> <4B0C832B-BB75-40BD-85A9-9DC84DEB44E2@gmail.com> <770436977.3704467.1476471398385.JavaMail.zimbra@redhat.com> To: Paolo Bonzini X-Mailer: Apple Mail (2.3226) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by mail.home.local id u9EJj6ri026186 Content-Length: 680 Lines: 20 > On Oct 14, 2016, at 11:56 AM, Paolo Bonzini wrote: >>> >>> for (i = 0; i <= 7; i++) { >>> - pir_val = xchg(&pir[i], 0); >>> - if (pir_val) >>> + pir_val = READ_ONCE(pir[i]); >> >> Out of curiosity, do you really need this READ_ONCE? > > The answer can only be "depends on the compiler's whims". :) > If you think of READ_ONCE as a C11 relaxed atomic load, then yes. Hm.. So the idea is to make the code "race-free” in the sense that every concurrent memory access is done using READ_ONCE/WRITE_ONCE? If that is the case, I think there are many other cases that need to be changed, for example apic->irr_pending and vcpu->arch.pv.pv_unhalted.