From patchwork Mon Nov 25 15:57:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 21747 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f71.google.com (mail-oa0-f71.google.com [209.85.219.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F38DE23A3F for ; Mon, 25 Nov 2013 15:58:08 +0000 (UTC) Received: by mail-oa0-f71.google.com with SMTP id i4sf15164629oah.10 for ; Mon, 25 Nov 2013 07:58:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:mime-version:in-reply-to:references :date:message-id:subject:from:to:cc:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=NRWnfU7lM1jyBLFNDoo72JAioAipglOUb5pl25LSdfY=; b=JpBg9AWamwxjgqRYYqHyAXbePmk/qL9dDAZLC4J6QKAHZp9chsALgNU42Tftdrebej aHJRHaLyvdNfe2DdE3/jrk3AyO4NkRGCTiCc9OKZzCXQ4KEU36Mu15/+Hw8QWmqqtE5t hszeTuMa1v4wkRgFEvU2eAitn+0GI4SabLDQFRxP5r+040hOMS0vW7m4FquaYXU3Vxv7 AiGHB3UE4njYI6JaeeTne/2WWJmCkcSwDRbRHcYNZtOfPf4QXfoPp7f62PLErEk0TY8u oqdvIuqKxTJHyvlWBWOil7I30r/vo1c0pcfVIYnheiMaacVGEGyywpxvkxic3lpg1cQP faTg== X-Gm-Message-State: ALoCoQkIvtIS7nkooOx/og6uDBgkV33+S8neDQc5vPo3C34Yk2xmwkZudzEke9rsFW8KK0sSmDm3 X-Received: by 10.43.128.197 with SMTP id hf5mr7967791icc.2.1385395088117; Mon, 25 Nov 2013 07:58:08 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.82.49 with SMTP id f17ls1391419qey.54.gmail; Mon, 25 Nov 2013 07:58:08 -0800 (PST) X-Received: by 10.53.10.34 with SMTP id dx2mr4293315vdd.13.1385395087949; Mon, 25 Nov 2013 07:58:07 -0800 (PST) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id cp3si18028168vcb.133.2013.11.25.07.58.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Nov 2013 07:58:07 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.169; Received: by mail-ve0-f169.google.com with SMTP id c14so3029853vea.14 for ; Mon, 25 Nov 2013 07:58:07 -0800 (PST) X-Received: by 10.52.121.41 with SMTP id lh9mr641516vdb.37.1385395087818; Mon, 25 Nov 2013 07:58:07 -0800 (PST) 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.220.174.196 with SMTP id u4csp143401vcz; Mon, 25 Nov 2013 07:58:04 -0800 (PST) X-Received: by 10.14.203.70 with SMTP id e46mr9780047eeo.33.1385395084064; Mon, 25 Nov 2013 07:58:04 -0800 (PST) Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com [209.85.212.173]) by mx.google.com with ESMTPS id v2si7388295wie.58.2013.11.25.07.58.03 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Nov 2013 07:58:04 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.173 is neither permitted nor denied by best guess record for domain of anup.patel@linaro.org) client-ip=209.85.212.173; Received: by mail-wi0-f173.google.com with SMTP id hm4so3776264wib.12 for ; Mon, 25 Nov 2013 07:58:03 -0800 (PST) MIME-Version: 1.0 X-Received: by 10.194.80.137 with SMTP id r9mr183436wjx.88.1385395067535; Mon, 25 Nov 2013 07:57:47 -0800 (PST) Received: by 10.194.31.225 with HTTP; Mon, 25 Nov 2013 07:57:46 -0800 (PST) In-Reply-To: <1385394599-15439-1-git-send-email-anup.patel@linaro.org> References: <1385394599-15439-1-git-send-email-anup.patel@linaro.org> Date: Mon, 25 Nov 2013 21:27:46 +0530 Message-ID: Subject: Re: [PATCH 0/2] PSCI system off and reset for KVM ARM/ARM64 From: Anup Patel To: "kvmarm@lists.cs.columbia.edu" Cc: linux-arm-kernel , Patch Tracking , "linaro-kernel@lists.linaro.org" , patches , Christoffer Dall , Marc Zyngier , Rob Herring , Pranavkumar Sawargaonkar , Anup Patel X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: anup.patel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) 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: , On 25 November 2013 21:19, Anup Patel wrote: > The Power State and Coordination Interface (PSCI) specification defines > SYSTEM_OFF and SYSTEM_RESET functions for system poweroff and reboot. > > This patchset adds emulation of PSCI SYSTEM_OFF and SYSTEM_RESET functions > in KVM ARM/ARM64 by forwarding them to user space (QEMU or KVMTOOL) using > KVM_EXIT_SHUTDOWN and KVM_EXIT_RESET exit reasons. > > To try this patch from guest kernel, we will need PSCI-based restart and > poweroff support in the guest kenel for both ARM and ARM64. > > Rob Herring has already submitted patches for PSCI-based restart and > poweroff in ARM kernel but these are not merged yet due unstable device > tree bindings of kernel PSCI support. We will be having similar patches > for PSCI-based restart and poweroff in ARM64 kernel. > (Refer http://www.spinics.net/lists/arm-kernel/msg262217.html) > (Refer http://www.spinics.net/lists/devicetree/msg05348.html) > > Anup Patel (2): > KVM: Add KVM_EXIT_RESET to user space API header > ARM/ARM64: KVM: Forward PSCI SYSTEM_OFF and SYSTEM_RESET to user > space > > arch/arm/include/asm/kvm_psci.h | 2 +- > arch/arm/include/uapi/asm/kvm.h | 2 ++ > arch/arm/kvm/handle_exit.c | 7 ++++++- > arch/arm/kvm/psci.c | 38 +++++++++++++++++++++++++++++-------- > arch/arm64/include/asm/kvm_psci.h | 2 +- > arch/arm64/include/uapi/asm/kvm.h | 2 ++ > arch/arm64/kvm/handle_exit.c | 10 ++++++---- > include/uapi/linux/kvm.h | 1 + > 8 files changed, 49 insertions(+), 15 deletions(-) > > -- > 1.7.9.5 > Hi All, If anyone wants to try this patches using KVMTOOL then they can find guest kernel side PSCI patches and KVMTOOL patch attached here. Regards, Anup diff --git a/tools/kvm/Makefile b/tools/kvm/Makefile index 5df358d..e288731 100644 --- a/tools/kvm/Makefile +++ b/tools/kvm/Makefile @@ -178,7 +178,7 @@ ifeq ($(ARCH), arm64) OBJS += arm/aarch64/kvm-cpu.o ARCH_INCLUDE := $(HDRS_ARM_COMMON) ARCH_INCLUDE += -Iarm/aarch64/include - + CFLAGS += -static ARCH_WANT_LIBFDT := y endif diff --git a/tools/kvm/arm/aarch64/cortex-a57.c b/tools/kvm/arm/aarch64/cortex-a57.c index 0c340fb..d079fd4 100644 --- a/tools/kvm/arm/aarch64/cortex-a57.c +++ b/tools/kvm/arm/aarch64/cortex-a57.c @@ -71,10 +71,17 @@ static struct kvm_arm_target target_cortex_a57 = { .init = cortex_a57__vcpu_init, }; +static struct kvm_arm_target target_xgene_potenza = { + .id = KVM_ARM_TARGET_XGENE_POTENZA, + .compatible = "arm,arm-v8", + .init = cortex_a57__vcpu_init, +}; + static int cortex_a57__core_init(struct kvm *kvm) { return (kvm_cpu__register_kvm_arm_target(&target_aem_v8) || kvm_cpu__register_kvm_arm_target(&target_foundation_v8) || - kvm_cpu__register_kvm_arm_target(&target_cortex_a57)); + kvm_cpu__register_kvm_arm_target(&target_cortex_a57) || + kvm_cpu__register_kvm_arm_target(&target_xgene_potenza)); } core_init(cortex_a57__core_init); diff --git a/tools/kvm/arm/fdt.c b/tools/kvm/arm/fdt.c index 5e18c11..4433829 100644 --- a/tools/kvm/arm/fdt.c +++ b/tools/kvm/arm/fdt.c @@ -160,6 +160,8 @@ static int setup_fdt(struct kvm *kvm) _FDT(fdt_property_cell(fdt, "cpu_off", KVM_PSCI_FN_CPU_OFF)); _FDT(fdt_property_cell(fdt, "cpu_on", KVM_PSCI_FN_CPU_ON)); _FDT(fdt_property_cell(fdt, "migrate", KVM_PSCI_FN_MIGRATE)); + _FDT(fdt_property_cell(fdt, "system_off", KVM_PSCI_FN_SYSTEM_OFF)); + _FDT(fdt_property_cell(fdt, "system_reset", KVM_PSCI_FN_SYSTEM_RESET)); _FDT(fdt_end_node(fdt)); /* Finalise. */ diff --git a/tools/kvm/arm/kvm-cpu.c b/tools/kvm/arm/kvm-cpu.c index d31e7b1..2297b04 100644 --- a/tools/kvm/arm/kvm-cpu.c +++ b/tools/kvm/arm/kvm-cpu.c @@ -33,7 +33,7 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) struct kvm_arm_target *target; struct kvm_cpu *vcpu; int coalesced_offset, mmap_size, err = -1; - unsigned int i; + struct kvm_vcpu_init pinit = { 0 }; struct kvm_vcpu_init vcpu_init = { .features = ARM_VCPU_FEATURE_FLAGS(kvm, cpu_id) }; @@ -55,19 +55,32 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) if (vcpu->kvm_run == MAP_FAILED) die("unable to mmap vcpu fd"); - /* Find an appropriate target CPU type. */ - for (i = 0; i < ARRAY_SIZE(kvm_arm_targets); ++i) { - if (!kvm_arm_targets[i]) - continue; - target = kvm_arm_targets[i]; - vcpu_init.target = target->id; - err = ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_INIT, &vcpu_init); - if (!err) - break; - } + /* Find an preferred target CPU type. */ + err = ioctl(kvm->vm_fd, KVM_ARM_PREFERRED_TARGET, &pinit); + if (err) + die("KVM_ARM_PREFERRED_TARGET ioctl failed (err %d)\n", err); + + /* Sanity check on target type returned by KVM */ + if (ARRAY_SIZE(kvm_arm_targets) <= pinit.target) + die("Unknown vcpu target type %d from KVM\n", pinit.target); + + /* Get a registerd target type */ + target = kvm_arm_targets[pinit.target]; + if (!target) + die("Target type %d not registered\n", pinit.target); + + /* Prepare VCPU init target */ + vcpu_init.target = pinit.target; + vcpu_init.features[0] |= pinit.features[0]; + + /* Call VCPU init ioctl */ + err = ioctl(vcpu->vcpu_fd, KVM_ARM_VCPU_INIT, &vcpu_init); + if (err) + die("KVM_ARM_VCPU_INIT ioctl failed (err %d)\n", err); - if (err || target->init(vcpu)) - die("Unable to initialise ARM vcpu"); + /* Do target specific init */ + if (target->init(vcpu)) + die("Unable to initialise ARM vcpu\n"); coalesced_offset = ioctl(kvm->sys_fd, KVM_CHECK_EXTENSION, KVM_CAP_COALESCED_MMIO); diff --git a/tools/kvm/kvm-cpu.c b/tools/kvm/kvm-cpu.c index be05c49..de33a0a 100644 --- a/tools/kvm/kvm-cpu.c +++ b/tools/kvm/kvm-cpu.c @@ -153,6 +153,10 @@ int kvm_cpu__start(struct kvm_cpu *cpu) break; goto exit_kvm; case KVM_EXIT_SHUTDOWN: + printf("KVMTOOL: got shutdown exit\n"); + goto exit_kvm; + case KVM_EXIT_RESET: + printf("KVMTOOL: got reset exit\n"); goto exit_kvm; default: { bool ret; diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c index cfd30dd..6965fd4 100644 --- a/tools/kvm/kvm.c +++ b/tools/kvm/kvm.c @@ -55,6 +55,7 @@ const char *kvm_exit_reasons[] = { #ifdef CONFIG_PPC64 DEFINE_KVM_EXIT_REASON(KVM_EXIT_PAPR_HCALL), #endif + DEFINE_KVM_EXIT_REASON(KVM_EXIT_RESET), }; static int pause_event;