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: 3233021 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7B59EC045B for ; Mon, 25 Nov 2013 15:58:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 74DE4201EF for ; Mon, 25 Nov 2013 15:58:43 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0D1CD201CD for ; Mon, 25 Nov 2013 15:58:38 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VkyYU-00008d-8r; Mon, 25 Nov 2013 15:58:34 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VkyYR-00037n-Ft; Mon, 25 Nov 2013 15:58:31 +0000 Received: from mail-wi0-f176.google.com ([209.85.212.176]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VkyYN-000373-KB for linux-arm-kernel@lists.infradead.org; Mon, 25 Nov 2013 15:58:29 +0000 Received: by mail-wi0-f176.google.com with SMTP id hq4so3786787wib.15 for ; Mon, 25 Nov 2013 07:58:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=NRWnfU7lM1jyBLFNDoo72JAioAipglOUb5pl25LSdfY=; b=Eq5ePw9fOLXtuXPO3XYaCyh4c2EYvO/gqjb9B5RIFInBz3sEwhXmyZZfmoGkbBMpwW vZlQL/5qgvm8SjKFJuo1QyQnD3bH7PGZ8EFjKOkMkGTW2q4RUNe6xpsgoNrhaPnh9E7f iAivdUWsji5KCFyNEKuJSzPTm8HaQtdbSEXf6nkquT7bHVfznW7ZDMNAciWNsw/aOtmJ 1ets2aP8MHBBUC2bxstup9HIKZisEvz1kZIgdfN40Ff6C69/nC1avUYTXpU84izobvZ4 GBFgg3V5/NcJcpCyJSk9RqxcJZqbFBZhSjT00IbsOB0D/HoAh56GAXcBAIi3L+VyYz+k HwaQ== X-Gm-Message-State: ALoCoQkxXBr+FinBBBoK0PiGRXhKjYXOfvTYyL4oqbQn2q/S8lan0oeChKYdeI6kbLfLEwyTa7C0 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" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131125_105827_880421_470878AC X-CRM114-Status: GOOD ( 27.17 ) X-Spam-Score: -2.6 (--) Cc: "linaro-kernel@lists.linaro.org" , Anup Patel , Patch Tracking , Marc Zyngier , patches , linux-arm-kernel , Christoffer Dall , Pranavkumar Sawargaonkar X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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;