From patchwork Tue Jul 16 02:47:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11045163 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF7246C5 for ; Tue, 16 Jul 2019 02:48:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FAF32857F for ; Tue, 16 Jul 2019 02:48:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93FC728585; Tue, 16 Jul 2019 02:48:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0BD7428581 for ; Tue, 16 Jul 2019 02:48:18 +0000 (UTC) Received: from localhost ([::1]:44964 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnDVo-0003rK-ON for patchwork-qemu-devel@patchwork.kernel.org; Mon, 15 Jul 2019 22:48:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44275) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnDVQ-0002Ao-GC for qemu-devel@nongnu.org; Mon, 15 Jul 2019 22:47:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnDVP-0004Tm-4F for qemu-devel@nongnu.org; Mon, 15 Jul 2019 22:47:52 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:38216) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hnDVM-0004P8-8F; Mon, 15 Jul 2019 22:47:48 -0400 Received: by mail-pg1-x533.google.com with SMTP id z75so8654541pgz.5; Mon, 15 Jul 2019 19:47:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PzwK4vtv/PDyhfXpJbiQNfSLcteSs1hAR52r+MzvdUY=; b=Clsy1lqvQ+brPUaCagfqXzIwQJaFkktO9aUTxPdv9UhYJbfFsOdQtX9kioO06xuHVO tIx/VKgzOeCyD0YkYQdlk4x5GAr75YC4evYSM7bZKxJvZlzAzTd9riEKTs9BSayP2agi QOADGyoE+sCxnA6h9TwB+I+Y8ZsLvMIbXUYxiEjdyvdUfUrpTtQqyIu2qX+l/FFrqVMi qmUyWqW0PVb2u+sdksZ2C5DtanuFrrU+G16QtPnorzTn3eWdIBPXTWxCTSbWzmUpbQIT CKw68X3NB1gBjkFazZT27t9EyrHuBt8cYibGxyw0bpdCpd52srVZxANC/hQ2j9xLKGo0 XgAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PzwK4vtv/PDyhfXpJbiQNfSLcteSs1hAR52r+MzvdUY=; b=oQSOG2BnWjX2lcNslt3krlBvsdRpX4Q6mQgr55JCW2H+dLR/ikSUPyAyH7RT+aesdg HTULwIMYlPyFR7ZvW5vlXjhfPscrZn+skww8FIQeNww7UXoI/OOYWE2eXsmEKPpEELFe uKOGHfa00q3CsqD2cLpYxd3q2HiDpuHQd4v6vcDXQmh/jpopjS4kyaIFZFN1n1wmd8bK 4tqvzXI1VDVF6F7VAc1CGoyD7McYiVkvXkATGipTGE4Dvvt3odSi1SbEz5++misyicKH t2WFJ61IF1YHPViE6JMUVZTQDjE0CyHXU83XQIwfN88XC7UxGphCIgXy001O8QWcyvb5 RJow== X-Gm-Message-State: APjAAAW1125NhwEvp+D+eX+xYOVuU2kSuN9zF0ZXvjPOvMJjPi77iHpv f1y3p0HWKlUiFUTnUDmSDlA= X-Google-Smtp-Source: APXvYqz4FtsMJsXeoozSjP+Sm7fdcXk32s8SfYRkIKSI8idPKlU0d54sZ+YB/T87XeW3K67tlf33Zw== X-Received: by 2002:a63:5550:: with SMTP id f16mr11661981pgm.426.1563245263688; Mon, 15 Jul 2019 19:47:43 -0700 (PDT) Received: from bobo.local0.net ([203.220.8.141]) by smtp.gmail.com with ESMTPSA id x8sm16557837pfa.46.2019.07.15.19.47.39 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 15 Jul 2019 19:47:43 -0700 (PDT) From: Nicholas Piggin To: David Gibson Date: Tue, 16 Jul 2019 12:47:22 +1000 Message-Id: <20190716024726.17864-2-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190716024726.17864-1-npiggin@gmail.com> References: <20190716024726.17864-1-npiggin@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::533 Subject: [Qemu-devel] [PATCH v4 1/5] spapr: Implement dispatch counter and prod bit on tcg X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg Kurz , Nicholas Piggin , qemu-devel@nongnu.org, qemu-ppc@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Implement cpu_exec_enter/exit on ppc which calls into new methods of the same name in PPCVirtualHypervisorClass. These are used by spapr to implement these splpar elements, used in subsequent changes. Signed-off-by: Nicholas Piggin --- hw/ppc/spapr.c | 25 +++++++++++++++++++++++++ hw/ppc/spapr_cpu_core.c | 5 ++++- hw/ppc/spapr_hcall.c | 5 ----- include/hw/ppc/spapr.h | 7 +++++++ include/hw/ppc/spapr_cpu_core.h | 2 ++ target/ppc/cpu.h | 2 ++ target/ppc/translate_init.inc.c | 25 +++++++++++++++++++++++++ 7 files changed, 65 insertions(+), 6 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 821f0d4a49..87b11e2484 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -4302,6 +4302,29 @@ PowerPCCPU *spapr_find_cpu(int vcpu_id) return NULL; } +static void spapr_cpu_exec_enter(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu) +{ + SpaprCpuState *spapr_cpu = spapr_cpu_state(cpu); + + /* These are only called by TCG, KVM maintains dispatch state */ + + spapr_cpu->prod = false; + spapr_cpu->dispatch_counter++; + assert((spapr_cpu->dispatch_counter & 1) == 0); + if (spapr_cpu->vpa_addr) { + CPUState *cs = CPU(cpu); + stl_be_phys(cs->as, spapr_cpu->vpa_addr + VPA_DISPATCH_COUNTER, spapr_cpu->dispatch_counter); + } +} + +static void spapr_cpu_exec_exit(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu) +{ + SpaprCpuState *spapr_cpu = spapr_cpu_state(cpu); + + spapr_cpu->dispatch_counter++; + assert((spapr_cpu->dispatch_counter & 1) == 1); +} + static void spapr_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); @@ -4358,6 +4381,8 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) vhc->hpte_set_r = spapr_hpte_set_r; vhc->get_pate = spapr_get_pate; vhc->encode_hpt_for_kvm_pr = spapr_encode_hpt_for_kvm_pr; + vhc->cpu_exec_enter = spapr_cpu_exec_enter; + vhc->cpu_exec_exit = spapr_cpu_exec_exit; xic->ics_get = spapr_ics_get; xic->ics_resend = spapr_ics_resend; xic->icp_get = spapr_icp_get; diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index 5621fb9a3d..fb2ed9e95d 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -261,6 +261,7 @@ error: static PowerPCCPU *spapr_create_vcpu(SpaprCpuCore *sc, int i, Error **errp) { SpaprCpuCoreClass *scc = SPAPR_CPU_CORE_GET_CLASS(sc); + SpaprCpuState *spapr_cpu; CPUCore *cc = CPU_CORE(sc); Object *obj; char *id; @@ -287,7 +288,9 @@ static PowerPCCPU *spapr_create_vcpu(SpaprCpuCore *sc, int i, Error **errp) goto err; } - cpu->machine_data = g_new0(SpaprCpuState, 1); + spapr_cpu = g_new0(SpaprCpuState, 1); + spapr_cpu->dispatch_counter = 1; + cpu->machine_data = spapr_cpu; object_unref(obj); return cpu; diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 6808d4cda8..e615881ac4 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -874,11 +874,6 @@ unmap_out: #define FLAGS_DEREGISTER_DTL 0x0000c00000000000ULL #define FLAGS_DEREGISTER_SLBSHADOW 0x0000e00000000000ULL -#define VPA_MIN_SIZE 640 -#define VPA_SIZE_OFFSET 0x4 -#define VPA_SHARED_PROC_OFFSET 0x9 -#define VPA_SHARED_PROC_VAL 0x2 - static target_ulong register_vpa(PowerPCCPU *cpu, target_ulong vpa) { CPUState *cs = CPU(cpu); diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 60553d32c4..5d36eec9d0 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -525,6 +525,13 @@ void spapr_register_hypercall(target_ulong opcode, spapr_hcall_fn fn); target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode, target_ulong *args); +/* Virtual Processor Area structure constants */ +#define VPA_MIN_SIZE 640 +#define VPA_SIZE_OFFSET 0x4 +#define VPA_SHARED_PROC_OFFSET 0x9 +#define VPA_SHARED_PROC_VAL 0x2 +#define VPA_DISPATCH_COUNTER 0x100 + /* ibm,set-eeh-option */ #define RTAS_EEH_DISABLE 0 #define RTAS_EEH_ENABLE 1 diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_core.h index f9645a7290..3032dfa7ee 100644 --- a/include/hw/ppc/spapr_cpu_core.h +++ b/include/hw/ppc/spapr_cpu_core.h @@ -46,6 +46,8 @@ typedef struct SpaprCpuState { uint64_t vpa_addr; uint64_t slb_shadow_addr, slb_shadow_size; uint64_t dtl_addr, dtl_size; + uint32_t dispatch_counter; + bool prod; struct ICPState *icp; struct XiveTCTX *tctx; } SpaprCpuState; diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index c9beba2a5c..78d6504acb 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1224,6 +1224,8 @@ struct PPCVirtualHypervisorClass { void (*hpte_set_r)(PPCVirtualHypervisor *vhyp, hwaddr ptex, uint64_t pte1); void (*get_pate)(PPCVirtualHypervisor *vhyp, ppc_v3_pate_t *entry); target_ulong (*encode_hpt_for_kvm_pr)(PPCVirtualHypervisor *vhyp); + void (*cpu_exec_enter)(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu); + void (*cpu_exec_exit)(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu); }; #define TYPE_PPC_VIRTUAL_HYPERVISOR "ppc-virtual-hypervisor" diff --git a/target/ppc/translate_init.inc.c b/target/ppc/translate_init.inc.c index 86fc8f2e31..58d4a93b23 100644 --- a/target/ppc/translate_init.inc.c +++ b/target/ppc/translate_init.inc.c @@ -10473,6 +10473,28 @@ static bool ppc_cpu_is_big_endian(CPUState *cs) } #endif +static void ppc_cpu_exec_enter(CPUState *cs) +{ + PowerPCCPU *cpu = POWERPC_CPU(cs); + + if (cpu->vhyp) { + PPCVirtualHypervisorClass *vhc = + PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp); + vhc->cpu_exec_enter(cpu->vhyp, cpu); + } +} + +static void ppc_cpu_exec_exit(CPUState *cs) +{ + PowerPCCPU *cpu = POWERPC_CPU(cs); + + if (cpu->vhyp) { + PPCVirtualHypervisorClass *vhc = + PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp); + vhc->cpu_exec_exit(cpu->vhyp, cpu); + } +} + static void ppc_cpu_instance_init(Object *obj) { PowerPCCPU *cpu = POWERPC_CPU(obj); @@ -10624,6 +10646,9 @@ static void ppc_cpu_class_init(ObjectClass *oc, void *data) cc->tcg_initialize = ppc_translate_init; cc->tlb_fill = ppc_cpu_tlb_fill; #endif + cc->cpu_exec_enter = ppc_cpu_exec_enter; + cc->cpu_exec_exit = ppc_cpu_exec_exit; + cc->disas_set_info = ppc_disas_set_info; dc->fw_name = "PowerPC,UNKNOWN"; From patchwork Tue Jul 16 02:47:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11045161 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4E936138D for ; Tue, 16 Jul 2019 02:48:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E7102857F for ; Tue, 16 Jul 2019 02:48:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31DC5285A2; Tue, 16 Jul 2019 02:48:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D22172857F for ; Tue, 16 Jul 2019 02:48:17 +0000 (UTC) Received: from localhost ([::1]:44962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnDVo-0003qV-J7 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 15 Jul 2019 22:48:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44256) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnDVP-000264-Mu for qemu-devel@nongnu.org; Mon, 15 Jul 2019 22:47:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnDVO-0004TR-Km for qemu-devel@nongnu.org; Mon, 15 Jul 2019 22:47:51 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:33398) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hnDVM-0004Qj-Ek; Mon, 15 Jul 2019 22:47:48 -0400 Received: by mail-pl1-x644.google.com with SMTP id c14so9278874plo.0; Mon, 15 Jul 2019 19:47:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aspJFmRkiuGl98ZZpfTk4UAxRVGqt3PVQT6yVoIbn6Q=; b=BKX56AuBGgyx61xd76VALGoghvtPYsdpPunNIhrOhrZO6PT7+F0A/FcT4zr8Ji/Dn+ uMcGUj1L11CVPEgTxBnraY/X8N8BhXzh0m9zzA/2RqmdJhxzHb3JfYkScFB7rZHnLaFL 4zG7oWBHEclgwysCSRIJfqA9WwPmSUp3hA0jC2V8Cnl4cwOptrInvGpy/aEXgtSjQ9Y5 dorpi5MnxTxrjJTYT067NLPkHkMwhKwGqBMXCnFyack+41KTBLkR5K81PJ+y3qG0BR7q Omp4Y3pnLzBmE4g8WSTgytbbpZCH4hVXQ0+b93cGnK+BkZC/yWi1AbZqxiNVFCs/u8d3 d3HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aspJFmRkiuGl98ZZpfTk4UAxRVGqt3PVQT6yVoIbn6Q=; b=tgkUo0JFpio1Dyhh6e1SDaw/qkj8Rg9Yf9X81WkzR5ayR8x6pcX1+OO0kbbhNkHgq7 5kH5t3a15dZzDmjYZQqsNr1Tm97+wiDG0Y1YbqXY6lGcp1JTNKtRBJV+qOiKqXNoB3zi 4IKvUqh362JVwZlgp4wdRe+hNUrijYCvhxq2RNKQolej9Bh3pBG7+nio9b+h/Xk7SVex IV5+/SwcQqzy3xi7h2xAviVn/SMN9Q4Q4X8RpFHJ/bjgNdw9BimJrtpa+WLRRklj+hM/ zs/d0BJCElFETkz3wI2IY+DoR1zzwL3ka+iN780p2nCl8EWLXmdxjQUjvICINFgpkbhE xAlA== X-Gm-Message-State: APjAAAWfHUBpkS2kqmWeCeyuqq/RE49kL8wnXaJSbOt/gOfJ2Yx2V8NK 8wNiFIz2zNZQ2ulhkPHE2WQ= X-Google-Smtp-Source: APXvYqz7u4Sfb++ZR0r6HA7JvgJecqVTPvQO0vDgY6Esj/PAY1mWowkMO5+ojotTEOYGJHm/bAflSA== X-Received: by 2002:a17:902:f082:: with SMTP id go2mr33697942plb.25.1563245267578; Mon, 15 Jul 2019 19:47:47 -0700 (PDT) Received: from bobo.local0.net ([203.220.8.141]) by smtp.gmail.com with ESMTPSA id x8sm16557837pfa.46.2019.07.15.19.47.44 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 15 Jul 2019 19:47:47 -0700 (PDT) From: Nicholas Piggin To: David Gibson Date: Tue, 16 Jul 2019 12:47:23 +1000 Message-Id: <20190716024726.17864-3-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190716024726.17864-1-npiggin@gmail.com> References: <20190716024726.17864-1-npiggin@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::644 Subject: [Qemu-devel] [PATCH v4 2/5] spapr: Implement H_PROD X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg Kurz , Nicholas Piggin , qemu-devel@nongnu.org, qemu-ppc@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP H_PROD is added, and H_CEDE is modified to test the prod bit according to PAPR. Signed-off-by: Nicholas Piggin --- hw/ppc/spapr_hcall.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index e615881ac4..8b208ab259 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1050,14 +1050,41 @@ static target_ulong h_cede(PowerPCCPU *cpu, SpaprMachineState *spapr, { CPUPPCState *env = &cpu->env; CPUState *cs = CPU(cpu); + SpaprCpuState *spapr_cpu = spapr_cpu_state(cpu); env->msr |= (1ULL << MSR_EE); hreg_compute_hflags(env); + + if (spapr_cpu->prod) { + spapr_cpu->prod = false; + return H_SUCCESS; + } + if (!cpu_has_work(cs)) { cs->halted = 1; cs->exception_index = EXCP_HLT; cs->exit_request = 1; } + + return H_SUCCESS; +} + +static target_ulong h_prod(PowerPCCPU *cpu, SpaprMachineState *spapr, + target_ulong opcode, target_ulong *args) +{ + target_long target = args[0]; + CPUState *cs; + SpaprCpuState *spapr_cpu = spapr_cpu_state(cpu); + + cs = CPU(spapr_find_cpu(target)); + if (!cs) { + return H_PARAMETER; + } + + spapr_cpu->prod = true; + cs->halted = 0; + qemu_cpu_kick(cs); + return H_SUCCESS; } @@ -1882,6 +1909,8 @@ static void hypercall_register_types(void) /* hcall-splpar */ spapr_register_hypercall(H_REGISTER_VPA, h_register_vpa); spapr_register_hypercall(H_CEDE, h_cede); + spapr_register_hypercall(H_PROD, h_prod); + spapr_register_hypercall(H_SIGNAL_SYS_RESET, h_signal_sys_reset); /* processor register resource access h-calls */ From patchwork Tue Jul 16 02:47:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11045169 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5073A6C5 for ; Tue, 16 Jul 2019 02:48:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 407872857B for ; Tue, 16 Jul 2019 02:48:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3378528585; Tue, 16 Jul 2019 02:48:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CC91D2857B for ; Tue, 16 Jul 2019 02:48:57 +0000 (UTC) Received: from localhost ([::1]:44986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnDWS-0006pe-Rw for patchwork-qemu-devel@patchwork.kernel.org; Mon, 15 Jul 2019 22:48:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44321) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnDVU-0002TK-Hh for qemu-devel@nongnu.org; Mon, 15 Jul 2019 22:47:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnDVT-0004Wi-B3 for qemu-devel@nongnu.org; Mon, 15 Jul 2019 22:47:56 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:44995) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hnDVR-0004UY-3W; Mon, 15 Jul 2019 22:47:53 -0400 Received: by mail-pl1-x642.google.com with SMTP id t14so9271263plr.11; Mon, 15 Jul 2019 19:47:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MdtW8CuvYdkhDUoUgf1LxOsNkRLOuv7x20g9x/4mLVg=; b=Kkg+t5l/JSXrrd4G1WmWSklPmahpG1n7pTy+67V3HxNO4JdsLoO3JTicKcReljIakV Lqn8sXxaMV/eZieMNc8bTaUKNwEvfeKEOhPprKpAsl+YmikKWLA6mb9V89kCRfihl7oq KhVnQqhNnGiSSA0wZYJsFZt/fh4Cf+GJD8vye8ewU9gjlUl8ZZ/+QTzqPGQZO8v7cX/V fJ8MXZQWPthRg9jq3R8OIwazaR7ttYearCcjeVbxr5KoRFey2SadWPP9O4P+eyCh9yxy pFr8c8PyT4EIDb0eqd5jQlH8O6q4l3kYjfxmgD8wtdML8pGvFxeXLio+PHv2l3soAlod xIog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MdtW8CuvYdkhDUoUgf1LxOsNkRLOuv7x20g9x/4mLVg=; b=YXcf6ndYMiciuc679tmqe11VuuZJPzx51A8NP9e1NyVLVRN10iQCQ6s16RJXSl0/JW VZ3jXU0J0spgWC5zLSEfMNLEvRayWMOBae0ygtL7xwf/tspTgT9UfdRBRvLcme83D0Op CO5jX32zG4PHwL7n9RoTeW2MTbrRaD/OLIhW8DkueBxEAZ1nHPWtyuK7/zyCoA4AmoT8 pY+fD4L7kBCWS76ygopEU6NqlaT7ivnhXqGp0e/1XuEZ+tWSWEXuNqwnNarboNiMDGH3 i8EFi2vTFIISny2I5MBIrBk4hrRSNXAKS7bWSUveTEtP4h3698fePlvG2L0VjK3+ec6K PQEw== X-Gm-Message-State: APjAAAVc4axexW5vhgVZY853xnJcfA+zcjp+5ZuhpkfxbRGWQK92Cj/S kvNGJLQcZu2ve4SHoiysNq8= X-Google-Smtp-Source: APXvYqyDkuMUoZflY9Z/M2w/Bx0ALzYnQwOJ0Uv8KYdzrJXchaqWjKZnQEb2FnXtMvBcLv/s9FeslQ== X-Received: by 2002:a17:902:7c05:: with SMTP id x5mr32390317pll.321.1563245271705; Mon, 15 Jul 2019 19:47:51 -0700 (PDT) Received: from bobo.local0.net ([203.220.8.141]) by smtp.gmail.com with ESMTPSA id x8sm16557837pfa.46.2019.07.15.19.47.48 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 15 Jul 2019 19:47:51 -0700 (PDT) From: Nicholas Piggin To: David Gibson Date: Tue, 16 Jul 2019 12:47:24 +1000 Message-Id: <20190716024726.17864-4-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190716024726.17864-1-npiggin@gmail.com> References: <20190716024726.17864-1-npiggin@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::642 Subject: [Qemu-devel] [PATCH v4 3/5] spapr: Implement H_CONFER X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg Kurz , Nicholas Piggin , qemu-devel@nongnu.org, qemu-ppc@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This does not do directed yielding and is not quite as strict as PAPR specifies in terms of precise dispatch behaviour. This generally will mean suboptimal performance, rather than guest misbehaviour. Linux does not rely on exact dispatch behaviour. Signed-off-by: Nicholas Piggin --- hw/ppc/spapr_hcall.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 8b208ab259..28d58113be 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1069,6 +1069,53 @@ static target_ulong h_cede(PowerPCCPU *cpu, SpaprMachineState *spapr, return H_SUCCESS; } +static target_ulong h_confer(PowerPCCPU *cpu, SpaprMachineState *spapr, + target_ulong opcode, target_ulong *args) +{ + target_long target = args[0]; + uint32_t dispatch = args[1]; + PowerPCCPU *target_cpu = spapr_find_cpu(target); + CPUState *target_cs = CPU(target_cpu); + CPUState *cs = CPU(cpu); + SpaprCpuState *spapr_cpu; + + /* + * This does not do a targeted yield or confer, but check the parameter + * anyway. -1 means confer to all/any other CPUs. + */ + if (target != -1 && !target_cs) { + return H_PARAMETER; + } + + spapr_cpu = spapr_cpu_state(target_cpu); + + /* + * PAPR specifies waiting until proded in this case, without dispatch + * counter check. + */ + if (cpu == target_cpu) { + if (spapr_cpu->prod) { + spapr_cpu->prod = false; + return H_SUCCESS; + } + + cs->halted = 1; + cs->exception_index = EXCP_HALTED; + cs->exit_request = 1; + + return H_SUCCESS; + } + + if (spapr_cpu->dispatch_counter != dispatch || (dispatch & 1) == 0) { + return H_SUCCESS; + } + + cs->exception_index = EXCP_YIELD; + cpu_loop_exit(cs); + + return H_SUCCESS; +} + static target_ulong h_prod(PowerPCCPU *cpu, SpaprMachineState *spapr, target_ulong opcode, target_ulong *args) { @@ -1909,6 +1956,7 @@ static void hypercall_register_types(void) /* hcall-splpar */ spapr_register_hypercall(H_REGISTER_VPA, h_register_vpa); spapr_register_hypercall(H_CEDE, h_cede); + spapr_register_hypercall(H_CONFER, h_confer); spapr_register_hypercall(H_PROD, h_prod); spapr_register_hypercall(H_SIGNAL_SYS_RESET, h_signal_sys_reset); From patchwork Tue Jul 16 02:47:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11045167 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7004D6C5 for ; Tue, 16 Jul 2019 02:48:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F3D62857B for ; Tue, 16 Jul 2019 02:48:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 52CBA28585; Tue, 16 Jul 2019 02:48:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DA9432857B for ; Tue, 16 Jul 2019 02:48:54 +0000 (UTC) Received: from localhost ([::1]:44984 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnDWQ-0006ax-0r for patchwork-qemu-devel@patchwork.kernel.org; Mon, 15 Jul 2019 22:48:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44362) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnDVZ-0002lZ-Nu for qemu-devel@nongnu.org; Mon, 15 Jul 2019 22:48:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnDVX-0004b0-2k for qemu-devel@nongnu.org; Mon, 15 Jul 2019 22:48:00 -0400 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:38206) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hnDVU-0004XG-ML; Mon, 15 Jul 2019 22:47:56 -0400 Received: by mail-pl1-x641.google.com with SMTP id az7so9289493plb.5; Mon, 15 Jul 2019 19:47:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=De2i1fnAfzCHclgXYbgQlJSwI5p8Wu3AzTld5je3ygM=; b=rJ0BBJcTKHXpHUeCqj8mOMroI0K/XgKGBrYK/VukClXRzN2Zamzl77g9HZbULHIdmO TX4vd6vDP9V/wy1b6gEh/GuPAMiFKStuIm0H222UoRzwFku0VpUiuvfhdzXaVSjjNOqH T7axs8iL6bWd7K7b5ekClPHD/ywazp38f9qK5+a+SgBkxE3zmrr/RAG+XLjJsPBgihKm ekhEUxyflwqTWkbl9dCr7w/nJGtcK1Eaj0tkoHjnDF1GswG5T+S5bj6eWzVv1u5MxOVB I+Ho/ImbMSBvsglJDSuUyt2AUHl7KIq6xTb4c+ylrggLSA+sx+nroWaNYPXkWCHbYzS9 JfDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=De2i1fnAfzCHclgXYbgQlJSwI5p8Wu3AzTld5je3ygM=; b=cxmifrsaoc+BZDMiOLsmsE+E+uq5eH2RsX/4BmavdDBdLi+ZcP8W3LY+1trWHGKkN3 AZUyOjNcTB3hRMutjduGmjldh2oNhtT8Gxpilh+ORCcqHZ8ZLEhg9hkMiVX1jvUWCTKf DMdYbVdc2PZ1JlW8a1LiG6dUTcF/jOG2MJNJm3NtPDgBKg3z0xS4IDeRpbzMcQvGEu6A sKBvjeJmmFMyJQ1Y8sueOnbXl/9CHecUnwqqHxLEQXvYhh7VKTv4zbS0WnxZpcJ4byNg 0ucniVRCKGWgp3nHW3Yr3VkGUWeYSjIPTOMbYZx5lbnf5vZC7ewfTzN9PP4JNj0IO9+X KWmQ== X-Gm-Message-State: APjAAAVyhcZ4RPgdx1AIlb24JtS+GC6CSmZsuSUMgnHhTrUHF2Cu/mEX mfJuQ6vp3AOhEl/rtpBkXNM= X-Google-Smtp-Source: APXvYqwRlDATVV1lxvR8Qb0O4+geDHpG6AeK5ZXZKjk9Z+4SsbItqXhenuzApA4kEWAL1EZHn4C0WQ== X-Received: by 2002:a17:902:9a85:: with SMTP id w5mr32208781plp.221.1563245275880; Mon, 15 Jul 2019 19:47:55 -0700 (PDT) Received: from bobo.local0.net ([203.220.8.141]) by smtp.gmail.com with ESMTPSA id x8sm16557837pfa.46.2019.07.15.19.47.52 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 15 Jul 2019 19:47:55 -0700 (PDT) From: Nicholas Piggin To: David Gibson Date: Tue, 16 Jul 2019 12:47:25 +1000 Message-Id: <20190716024726.17864-5-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190716024726.17864-1-npiggin@gmail.com> References: <20190716024726.17864-1-npiggin@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::641 Subject: [Qemu-devel] [PATCH v4 4/5] spapr: Implement H_JOIN X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg Kurz , Nicholas Piggin , qemu-devel@nongnu.org, qemu-ppc@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This has been useful to modify and test the Linux pseries suspend code but it requires modification to the guest to call it (due to being gated by other unimplemented features). It is not otherwise used by Linux yet, but work is slowly progressing there. Signed-off-by: Nicholas Piggin --- hw/ppc/spapr.c | 1 + hw/ppc/spapr_hcall.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 87b11e2484..5c54e1cb9a 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1066,6 +1066,7 @@ static void spapr_dt_rtas(SpaprMachineState *spapr, void *fdt) add_str(hypertas, "hcall-tce"); add_str(hypertas, "hcall-vio"); add_str(hypertas, "hcall-splpar"); + add_str(hypertas, "hcall-join"); add_str(hypertas, "hcall-bulk"); add_str(hypertas, "hcall-set-mode"); add_str(hypertas, "hcall-sprg0"); diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 28d58113be..52847a7047 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1069,6 +1069,47 @@ static target_ulong h_cede(PowerPCCPU *cpu, SpaprMachineState *spapr, return H_SUCCESS; } +static target_ulong h_join(PowerPCCPU *cpu, SpaprMachineState *spapr, + target_ulong opcode, target_ulong *args) +{ + CPUPPCState *env = &cpu->env; + CPUState *cs; + SpaprCpuState *spapr_cpu = spapr_cpu_state(cpu); + bool last_unjoined = true; + + if (env->msr & (1ULL << MSR_EE)) { + return H_BAD_MODE; + } + + if (spapr_cpu->prod) { + spapr_cpu->prod = false; + return H_SUCCESS; + } + + CPU_FOREACH(cs) { + PowerPCCPU *c = POWERPC_CPU(cs); + CPUPPCState *e = &c->env; + if (c == cpu) + continue; + + /* Don't have a way to indicate joined, so use halted && MSR[EE]=0 */ + if (!cs->halted || (e->msr & (1ULL << MSR_EE))) { + last_unjoined = false; + break; + } + } + if (last_unjoined) { + return H_CONTINUE; + } + + cs = CPU(cpu); + cs->halted = 1; + cs->exception_index = EXCP_HALTED; + cs->exit_request = 1; + + return H_SUCCESS; +} + static target_ulong h_confer(PowerPCCPU *cpu, SpaprMachineState *spapr, target_ulong opcode, target_ulong *args) { @@ -1959,6 +2000,9 @@ static void hypercall_register_types(void) spapr_register_hypercall(H_CONFER, h_confer); spapr_register_hypercall(H_PROD, h_prod); + /* hcall-join */ + spapr_register_hypercall(H_JOIN, h_join); + spapr_register_hypercall(H_SIGNAL_SYS_RESET, h_signal_sys_reset); /* processor register resource access h-calls */ From patchwork Tue Jul 16 02:47:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11045165 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D183138D for ; Tue, 16 Jul 2019 02:48:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B7B82857F for ; Tue, 16 Jul 2019 02:48:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B1B128585; Tue, 16 Jul 2019 02:48:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D42442857F for ; Tue, 16 Jul 2019 02:48:35 +0000 (UTC) Received: from localhost ([::1]:44968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnDW6-0005BN-Ox for patchwork-qemu-devel@patchwork.kernel.org; Mon, 15 Jul 2019 22:48:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44428) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hnDVd-00035F-BL for qemu-devel@nongnu.org; Mon, 15 Jul 2019 22:48:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hnDVb-0004df-Vm for qemu-devel@nongnu.org; Mon, 15 Jul 2019 22:48:05 -0400 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:38770) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hnDVY-0004be-S1; Mon, 15 Jul 2019 22:48:01 -0400 Received: by mail-pf1-x442.google.com with SMTP id y15so8347672pfn.5; Mon, 15 Jul 2019 19:48:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e2dPud5PCxHxMG9QDmjQcp4vS6NKyFk8d+yIr1hiXRY=; b=majXZKOd789jiH8CvODQrazuiZotMNH4anIlPhsXdMnJSMFKeYBndaHINWFjhvveC5 wGldN1idZc0fzjCTflgOajT9lyINsx0/UiGteY/kyqr9Y6X+0r5qdx0rgEPivz03phM9 dVSwdqUhfdzvBMK3eWjurVStvrAuSUgLSsSaHOL7pmMHLLQ95Ot5+9GnSybFdIPsh6b9 121dWZwnW9xQKSj7Xt6EyY9P0Vxrp7f7pDYd3BASXE8UJQaZ+b/mW1tF6V0YsUnapOWQ 5FiM/L5D6mCN62+Mi8HG02lQbB2uZdHxhNWsAHRJPNnQbQ0QSx+K1UPtlNNZbgn7F/BP 1E1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=e2dPud5PCxHxMG9QDmjQcp4vS6NKyFk8d+yIr1hiXRY=; b=oDMD6Q46hZ/YtA2Vfkrg8+ylhXgba2abxRwDraDH0dbF33neCUHDWS42Y3pFtbheO9 MDw6WhI/xmdfRO6wecW8un3Ene4OtsNeC4O6WKIuO7Mb5T/47U/wVwMy1rSFhnCM8SrH ZJ5e33i0IVWhPda75+MUB6IM6mg12iyn7kF7YhTl+tSIY5x5PA66lZBus7GvEoDAy7Br q4oiYmH1Cm0V+ryck+hYlMMyX5A8kj4xaIXzmQktCgi9ti9VBxUrganhggEUNM1kJUKO OysbrBorK2vnc9D+AwW9GNMswwfNBcsfbMaLYQMxVDimbv6QH5icQkqa0iUaL89HVtps FPLA== X-Gm-Message-State: APjAAAU4fH2WE5Mn/BXctSkjQKSyNxYwIcyef2BqohaRd5k1zlgc3Tlv 3ocTtTUcBoApaDMdNy81EKE= X-Google-Smtp-Source: APXvYqxsepVTxOnFpMTLu8zaAj4mzscjX+tukDPBMiz9uecGaonsbAmyelq7glsgRf7VH9qAB+nCrA== X-Received: by 2002:a63:4e60:: with SMTP id o32mr31065659pgl.68.1563245279762; Mon, 15 Jul 2019 19:47:59 -0700 (PDT) Received: from bobo.local0.net ([203.220.8.141]) by smtp.gmail.com with ESMTPSA id x8sm16557837pfa.46.2019.07.15.19.47.56 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 15 Jul 2019 19:47:59 -0700 (PDT) From: Nicholas Piggin To: David Gibson Date: Tue, 16 Jul 2019 12:47:26 +1000 Message-Id: <20190716024726.17864-6-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190716024726.17864-1-npiggin@gmail.com> References: <20190716024726.17864-1-npiggin@gmail.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 Subject: [Qemu-devel] [PATCH v4 5/5] spapr: Implement ibm,suspend-me X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Greg Kurz , Nicholas Piggin , qemu-devel@nongnu.org, qemu-ppc@nongnu.org, =?utf-8?q?C=C3=A9dric_Le_Goater?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP This has been useful to modify and test the Linux pseries suspend code but it requires modification to the guest to call it (due to being gated by other unimplemented features). It is not otherwise used by Linux yet, but work is slowly progressing there. This allows a (lightly modified) guest kernel to suspend with `echo mem > /sys/power/state` and be resumed with system_wakeup monitor command. Signed-off-by: Nicholas Piggin --- hw/ppc/spapr.c | 26 ++++++++++++++++++++++++++ hw/ppc/spapr_rtas.c | 32 ++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 7 ++++++- 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 5c54e1cb9a..b85d41bb1e 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1710,6 +1710,11 @@ static void spapr_machine_reset(MachineState *machine) void *fdt; int rc; + if (spapr->suspend_reset) { + spapr->suspend_reset = false; + return; + } + spapr_caps_apply(spapr); first_ppc_cpu = POWERPC_CPU(first_cpu); @@ -2721,6 +2726,23 @@ static PCIHostState *spapr_create_default_phb(void) return PCI_HOST_BRIDGE(dev); } +static Notifier wakeup; +static void spapr_notify_wakeup(Notifier *notifier, void *data) +{ + WakeupReason *reason = data; + + switch (*reason) { + case QEMU_WAKEUP_REASON_RTC: + break; + case QEMU_WAKEUP_REASON_PMTIMER: + break; + case QEMU_WAKEUP_REASON_OTHER: + break; + default: + break; + } +} + /* pSeries LPAR / sPAPR hardware init */ static void spapr_machine_init(MachineState *machine) { @@ -3078,6 +3100,10 @@ static void spapr_machine_init(MachineState *machine) qemu_register_boot_set(spapr_boot_set, spapr); + wakeup.notify = spapr_notify_wakeup; + qemu_register_wakeup_notifier(&wakeup); + qemu_register_wakeup_support(); + if (kvm_enabled()) { /* to stop and start vmclock */ qemu_add_vm_change_state_handler(cpu_ppc_clock_vm_state_change, diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c index a618a2ac0f..60a007ec38 100644 --- a/hw/ppc/spapr_rtas.c +++ b/hw/ppc/spapr_rtas.c @@ -216,6 +216,36 @@ static void rtas_stop_self(PowerPCCPU *cpu, SpaprMachineState *spapr, qemu_cpu_kick(cs); } +static void rtas_ibm_suspend_me(PowerPCCPU *cpu, SpaprMachineState *spapr, + uint32_t token, uint32_t nargs, + target_ulong args, + uint32_t nret, target_ulong rets) +{ + CPUState *cs; + + if (nargs != 0 || nret != 1) { + rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); + return; + } + + CPU_FOREACH(cs) { + PowerPCCPU *c = POWERPC_CPU(cs); + CPUPPCState *e = &c->env; + if (c == cpu) + continue; + + /* See h_join */ + if (!cs->halted || (e->msr & (1ULL << MSR_EE))) { + rtas_st(rets, 0, H_MULTI_THREADS_ACTIVE); + return; + } + } + + spapr->suspend_reset = true; + qemu_system_suspend_request(); + rtas_st(rets, 0, RTAS_OUT_SUCCESS); +} + static inline int sysparm_st(target_ulong addr, target_ulong len, const void *val, uint16_t vallen) { @@ -483,6 +513,8 @@ static void core_rtas_register_types(void) rtas_query_cpu_stopped_state); spapr_rtas_register(RTAS_START_CPU, "start-cpu", rtas_start_cpu); spapr_rtas_register(RTAS_STOP_SELF, "stop-self", rtas_stop_self); + spapr_rtas_register(RTAS_IBM_SUSPEND_ME, "ibm,suspend-me", + rtas_ibm_suspend_me); spapr_rtas_register(RTAS_IBM_GET_SYSTEM_PARAMETER, "ibm,get-system-parameter", rtas_ibm_get_system_parameter); diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 5d36eec9d0..df0b0c15da 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -171,6 +171,10 @@ struct SpaprMachineState { bool use_hotplug_event_source; SpaprEventSource *event_sources; + /* Machine has been suspended, so the next machine_reset should not + * reset state, but just return and allow execution to resume. */ + bool suspend_reset; + /* ibm,client-architecture-support option negotiation */ bool cas_reboot; bool cas_legacy_guest_workaround; @@ -631,8 +635,9 @@ target_ulong spapr_hypercall(PowerPCCPU *cpu, target_ulong opcode, #define RTAS_IBM_CREATE_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x27) #define RTAS_IBM_REMOVE_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x28) #define RTAS_IBM_RESET_PE_DMA_WINDOW (RTAS_TOKEN_BASE + 0x29) +#define RTAS_IBM_SUSPEND_ME (RTAS_TOKEN_BASE + 0x2A) -#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2A) +#define RTAS_TOKEN_MAX (RTAS_TOKEN_BASE + 0x2B) /* RTAS ibm,get-system-parameter token values */ #define RTAS_SYSPARM_SPLPAR_CHARACTERISTICS 20