From patchwork Thu Aug 23 01:03:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Wood X-Patchwork-Id: 1363911 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id DE4FC3FD40 for ; Thu, 23 Aug 2012 01:04:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751475Ab2HWBEC (ORCPT ); Wed, 22 Aug 2012 21:04:02 -0400 Received: from co1ehsobe005.messaging.microsoft.com ([216.32.180.188]:47574 "EHLO co1outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751333Ab2HWBEA (ORCPT ); Wed, 22 Aug 2012 21:04:00 -0400 Received: from mail58-co1-R.bigfish.com (10.243.78.237) by CO1EHSOBE004.bigfish.com (10.243.66.67) with Microsoft SMTP Server id 14.1.225.23; Thu, 23 Aug 2012 01:03:59 +0000 Received: from mail58-co1 (localhost [127.0.0.1]) by mail58-co1-R.bigfish.com (Postfix) with ESMTP id 5BFBC4600D7; Thu, 23 Aug 2012 01:03:59 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bhz2dh2a8h668h839hd24he5bhf0ah107ah1155h) Received: from mail58-co1 (localhost.localdomain [127.0.0.1]) by mail58-co1 (MessageSwitch) id 1345683836915478_25663; Thu, 23 Aug 2012 01:03:56 +0000 (UTC) Received: from CO1EHSMHS027.bigfish.com (unknown [10.243.78.238]) by mail58-co1.bigfish.com (Postfix) with ESMTP id DC271440047; Thu, 23 Aug 2012 01:03:56 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CO1EHSMHS027.bigfish.com (10.243.66.37) with Microsoft SMTP Server (TLS) id 14.1.225.23; Thu, 23 Aug 2012 01:03:54 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-004.039d.mgd.msft.net (10.84.1.14) with Microsoft SMTP Server (TLS) id 14.2.309.3; Wed, 22 Aug 2012 20:03:53 -0500 Received: from snotra.am.freescale.net ([10.214.84.21]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id q7N13pdL004708; Wed, 22 Aug 2012 18:03:51 -0700 From: Scott Wood To: Alexander Graf CC: , Subject: [PATCH] KVM: PPC: set IN_GUEST_MODE before checking requests Date: Wed, 22 Aug 2012 20:03:50 -0500 Message-ID: <1345683830-10768-1-git-send-email-scottwood@freescale.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-OriginatorOrg: freescale.com Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Avoid a race as described in the code comment. Also remove a related smp_wmb() from booke's kvmppc_prepare_to_enter(). I can't see any reason for it, and the book3s_pr version doesn't have it. Signed-off-by: Scott Wood --- arch/powerpc/kvm/booke.c | 1 - arch/powerpc/kvm/powerpc.c | 14 +++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index 5f0476a..88711f8 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c @@ -674,7 +674,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu) out: vcpu->mode = OUTSIDE_GUEST_MODE; - smp_wmb(); return ret; } diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index 32d217c..3d460a0 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -78,7 +78,16 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu) break; } + vcpu->mode = IN_GUEST_MODE; + + /* + * Reading vcpu->requests must happen after setting vcpu->mode, + * so we don't miss a request because the requester sees + * OUTSIDE_GUEST_MODE and assumes we'll be checking requests + * before next entering the guest (and thus doesn't IPI). + */ smp_mb(); + if (vcpu->requests) { /* Make sure we process requests preemptable */ local_irq_enable(); @@ -111,11 +120,6 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu) #endif kvm_guest_enter(); - - /* Going into guest context! Yay! */ - vcpu->mode = IN_GUEST_MODE; - smp_wmb(); - break; }