From patchwork Thu Mar 19 14:55:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 46047 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7935A21515 for ; Thu, 19 Mar 2015 14:58:53 +0000 (UTC) Received: by labgm9 with SMTP id gm9sf13054411lab.1 for ; Thu, 19 Mar 2015 07:58:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=VSym4etqAWMiBi9lYOggCeo0zimEWaLNGYeQNI7S5ZY=; b=HWiyoamdyRGct6gx1ku5NihXXVDhPMV+hXEe7P9jkcEdB0Tb0aRjGSyawRPj2asu0G 7aFKVaCzUUTp+T3F163oFvgb4cPurvdXTsYHLbHerQ/yQpkbMJLae5RDVVYNQ5G0asUI LgA5syINsMXXUwkKOUCKlw/iYGHIcEQFTnpTdWf+osyjI83Eu4C4i1YqMz8PRkvoGs9B CD1kXB/vnjYbYcpot5GAewvi6LDakEOPL5fImNaXoG9ydCZORkU2UH0CgC0vlwJTB3OI S5uQ2elDyEDOWrBu+iRoRmJQwNMyGbDgrjSsN/a5c9igzhsW2bl6hXNCVxjNW5Y1klLc s1AQ== X-Gm-Message-State: ALoCoQnjIciWzpTke90f1DbINrMujU/QD4WQN7/KiWmLJOCBW+MDUacPjuwv89QXb1JA3vqd+DXo X-Received: by 10.194.221.65 with SMTP id qc1mr12162257wjc.7.1426777132439; Thu, 19 Mar 2015 07:58:52 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.9.168 with SMTP id a8ls285983lab.14.gmail; Thu, 19 Mar 2015 07:58:52 -0700 (PDT) X-Received: by 10.112.185.66 with SMTP id fa2mr67908469lbc.117.1426777132249; Thu, 19 Mar 2015 07:58:52 -0700 (PDT) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id g4si1116069lbm.172.2015.03.19.07.58.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 07:58:52 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by lbnq5 with SMTP id q5so26636397lbn.0 for ; Thu, 19 Mar 2015 07:58:52 -0700 (PDT) X-Received: by 10.112.162.167 with SMTP id yb7mr67515468lbb.76.1426777132159; Thu, 19 Mar 2015 07:58:52 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.35.133 with SMTP id h5csp441594lbj; Thu, 19 Mar 2015 07:58:51 -0700 (PDT) X-Received: by 10.194.23.39 with SMTP id j7mr156081737wjf.9.1426777125911; Thu, 19 Mar 2015 07:58:45 -0700 (PDT) Received: from mail-wg0-f53.google.com (mail-wg0-f53.google.com. [74.125.82.53]) by mx.google.com with ESMTPS id dg1si3595370wib.3.2015.03.19.07.58.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Mar 2015 07:58:45 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.53 as permitted sender) client-ip=74.125.82.53; Received: by wgbcc7 with SMTP id cc7so64738524wgb.0 for ; Thu, 19 Mar 2015 07:58:45 -0700 (PDT) X-Received: by 10.180.216.38 with SMTP id on6mr9190672wic.15.1426777125548; Thu, 19 Mar 2015 07:58:45 -0700 (PDT) Received: from gnx2579.gnb.st.com (weg38-3-78-232-41-119.fbx.proxad.net. [78.232.41.119]) by mx.google.com with ESMTPSA id a6sm1695350wiy.17.2015.03.19.07.58.43 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Mar 2015 07:58:44 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, christoffer.dall@linaro.org, marc.zyngier@arm.com, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, alex.williamson@redhat.com Cc: linux-kernel@vger.kernel.org, patches@linaro.org, pbonzini@redhat.com, kim.phillips@freescale.com, b.reynal@virtualopensystems.com, feng.wu@intel.com Subject: [RFC v5 11/13] kvm: arm/arm64: implement kvm_arch_halt_guest and kvm_arch_resume_guest Date: Thu, 19 Mar 2015 15:55:49 +0100 Message-Id: <1426776951-24901-12-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1426776951-24901-1-git-send-email-eric.auger@linaro.org> References: <1426776951-24901-1-git-send-email-eric.auger@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This patch defines __KVM_HAVE_ARCH_HALT_GUEST and implements kvm_arch_halt_guest and kvm_arch_resume_guest for ARM. On halt, the guest is forced to exit and prevented from being re-entered. Signed-off-by: Eric Auger --- v4 -> v5: add arm64 support - also defines __KVM_HAVE_ARCH_HALT_GUEST for arm64 - add pause field --- arch/arm/include/asm/kvm_host.h | 4 ++++ arch/arm/kvm/arm.c | 32 +++++++++++++++++++++++++++++--- arch/arm64/include/asm/kvm_host.h | 4 ++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index 79a919c..b829f93 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -28,6 +28,7 @@ #include #define __KVM_HAVE_ARCH_INTC_INITIALIZED +#define __KVM_HAVE_ARCH_HALT_GUEST #if defined(CONFIG_KVM_ARM_MAX_VCPUS) #define KVM_MAX_VCPUS CONFIG_KVM_ARM_MAX_VCPUS @@ -132,6 +133,9 @@ struct kvm_vcpu_arch { /* vcpu power-off state */ bool power_off; + /* Don't run the guest */ + bool pause; + /* IO related fields */ struct kvm_decode mmio_decode; diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index 08e12dc..ebc0b55 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -454,11 +454,36 @@ bool kvm_arch_intc_initialized(struct kvm *kvm) return vgic_initialized(kvm); } +void kvm_arch_halt_guest(struct kvm *kvm) +{ + int i; + struct kvm_vcpu *vcpu; + + kvm_for_each_vcpu(i, vcpu, kvm) + vcpu->arch.pause = true; + force_vm_exit(cpu_all_mask); +} + +void kvm_arch_resume_guest(struct kvm *kvm) +{ + int i; + struct kvm_vcpu *vcpu; + + kvm_for_each_vcpu(i, vcpu, kvm) { + wait_queue_head_t *wq = kvm_arch_vcpu_wq(vcpu); + + vcpu->arch.pause = false; + wake_up_interruptible(wq); + } +} + + static void vcpu_pause(struct kvm_vcpu *vcpu) { wait_queue_head_t *wq = kvm_arch_vcpu_wq(vcpu); - wait_event_interruptible(*wq, !vcpu->arch.power_off); + wait_event_interruptible(*wq, ((!vcpu->arch.power_off) && + (!vcpu->arch.pause))); } static int kvm_vcpu_initialized(struct kvm_vcpu *vcpu) @@ -508,7 +533,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) update_vttbr(vcpu->kvm); - if (vcpu->arch.power_off) + if (vcpu->arch.power_off || vcpu->arch.pause) vcpu_pause(vcpu); kvm_vgic_flush_hwstate(vcpu); @@ -526,7 +551,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run) run->exit_reason = KVM_EXIT_INTR; } - if (ret <= 0 || need_new_vmid_gen(vcpu->kvm)) { + if (ret <= 0 || need_new_vmid_gen(vcpu->kvm) || + vcpu->arch.pause) { kvm_timer_sync_hwstate(vcpu); local_irq_enable(); kvm_timer_finish_sync(vcpu); diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index a713b0c..ffcc698 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -29,6 +29,7 @@ #include #define __KVM_HAVE_ARCH_INTC_INITIALIZED +#define __KVM_HAVE_ARCH_HALT_GUEST #if defined(CONFIG_KVM_ARM_MAX_VCPUS) #define KVM_MAX_VCPUS CONFIG_KVM_ARM_MAX_VCPUS @@ -125,6 +126,9 @@ struct kvm_vcpu_arch { /* vcpu power-off state */ bool power_off; + /* Don't run the guest */ + bool pause; + /* IO related fields */ struct kvm_decode mmio_decode;