From patchwork Mon Apr 13 12:29:29 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 47116 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7987A20553 for ; Mon, 13 Apr 2015 12:33:16 +0000 (UTC) Received: by lbdc7 with SMTP id c7sf15229249lbd.2 for ; Mon, 13 Apr 2015 05:33:15 -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=Rq6aFm9JIl6KU6kBl/g5C/stY4ut2/I80fSnzhXqx0/cyIf/NUsuFtXThYmiGFgd4g Y6/cDJYRbQc9c5H51j/LVMnbqZA+Bg8NsM3N0Eku8BGPbnEWaKj3FargnUOkwLOfsXcQ rqBFKZAqCyZOqRY7J5enimuYkvHptQ9KZwwS8MlY539X4Un5DedNcu4zx18VEIZ/LQva 7s+pV60EHPwfjMs/85nulQmx/LgLvwEBgkcsv+Oyy/AZjAuvnUMIXA7ZcgKTcz4o9IDB 9bVSaiMAecuiAmVWudJUZiUXnZQdILC2XwzHMA0UVjYH5Z7HPAKOEtJ83L1YiNaPYYZI EGMA== X-Gm-Message-State: ALoCoQkbFKByqVGdFkLU4A/nbxOu/R1SmT/bU55I1PDsDvrO0R5K3noelGopi1g2zTMWt7s9bR5K X-Received: by 10.112.181.166 with SMTP id dx6mr2103965lbc.17.1428928395204; Mon, 13 Apr 2015 05:33:15 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.37.162 with SMTP id z2ls659025laj.75.gmail; Mon, 13 Apr 2015 05:33:15 -0700 (PDT) X-Received: by 10.152.6.136 with SMTP id b8mr12929709laa.93.1428928395050; Mon, 13 Apr 2015 05:33:15 -0700 (PDT) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id df12si8304325lac.57.2015.04.13.05.33.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Apr 2015 05:33:14 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by lbbzk7 with SMTP id zk7so57335719lbb.0 for ; Mon, 13 Apr 2015 05:33:14 -0700 (PDT) X-Received: by 10.112.204.6 with SMTP id ku6mr12958156lbc.73.1428928394919; Mon, 13 Apr 2015 05:33:14 -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.67.65 with SMTP id l1csp1175325lbt; Mon, 13 Apr 2015 05:33:14 -0700 (PDT) X-Received: by 10.180.87.101 with SMTP id w5mr21107088wiz.18.1428928383668; Mon, 13 Apr 2015 05:33:03 -0700 (PDT) Received: from mail-wg0-f51.google.com (mail-wg0-f51.google.com. [74.125.82.51]) by mx.google.com with ESMTPS id kw4si17382944wjb.84.2015.04.13.05.33.03 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Apr 2015 05:33:03 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.51 as permitted sender) client-ip=74.125.82.51; Received: by wgin8 with SMTP id n8so78917865wgi.0 for ; Mon, 13 Apr 2015 05:33:03 -0700 (PDT) X-Received: by 10.180.80.105 with SMTP id q9mr2123051wix.52.1428928378898; Mon, 13 Apr 2015 05:32:58 -0700 (PDT) Received: from gnx2579.gnb.st.com (LCaen-156-56-7-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by mx.google.com with ESMTPSA id fl14sm2879910wjc.11.2015.04.13.05.32.56 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 Apr 2015 05:32:56 -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, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, alex.williamson@redhat.com, pbonzini@redhat.com Cc: linux-kernel@vger.kernel.org, patches@linaro.org, feng.wu@intel.com, b.reynal@virtualopensystems.com Subject: [RFC v6 14/16] kvm: arm/arm64: implement kvm_arch_halt_guest and kvm_arch_resume_guest Date: Mon, 13 Apr 2015 14:29:29 +0200 Message-Id: <1428928171-18884-15-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1428928171-18884-1-git-send-email-eric.auger@linaro.org> References: <1428928171-18884-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.182 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;