From patchwork Wed Jul 17 05:39:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11047165 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 1E299138B for ; Wed, 17 Jul 2019 05:40:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CBB6285F2 for ; Wed, 17 Jul 2019 05:40:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 00FD328708; Wed, 17 Jul 2019 05:40:32 +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 64FE9285F2 for ; Wed, 17 Jul 2019 05:40:32 +0000 (UTC) Received: from localhost ([::1]:54160 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hncg3-0002vL-53 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 17 Jul 2019 01:40:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50082) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hncfm-0001jU-Fd for qemu-devel@nongnu.org; Wed, 17 Jul 2019 01:40:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hncfl-0005BV-1H for qemu-devel@nongnu.org; Wed, 17 Jul 2019 01:40:14 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:40578) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hncfh-00057i-TD; Wed, 17 Jul 2019 01:40:10 -0400 Received: by mail-pl1-x633.google.com with SMTP id a93so11323910pla.7; Tue, 16 Jul 2019 22:40:09 -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=atW5I4YD/hFTgJhT3+aIQwl9ooO+YMNr7JDDvzKgaMs=; b=Y8YGip2taz5pqSqtiZlZ3elzi7BmnpvTf9SDogawqj8SYN/JxZiyz5kqam3FOevzg+ R74YQiqJrmsIYYFPHpdlVKVSsApYZvRTK4A45iLVf0Av45I4IJQpZnX0cN38AU5uOuFJ jKzyGJQ6WNgI+yXALmcX5Gr6gNBzQnzgNADevUeAkJYbKc0Lda53u0ufaWN6efR0PyF2 H9NCVN1Y/bXhI+M7RxDj1ToFuEMwkH3NcQgZMcQKvWQXuaMQ86t1Q0NVHhBMdZFxRuPa 9KUgEv7ZvBrxSSySGTI+tZfjBawqhsRUOq/Oybj/A3Jj14Sz/23YEVsqXG39kGWNAJmJ Mjaw== 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=atW5I4YD/hFTgJhT3+aIQwl9ooO+YMNr7JDDvzKgaMs=; b=uBY8MZlzjQloPz+9AVed5NXMS6E84grbCz42KsuQHqcstfl1h5awPJlSrdmJqn8E1h QlwGB2g9+HAhN0n22JQv+Xvk2hpqxA5yInW0JJlHCAUeqQ5vd32mHHvciIIUZMOyy67g PG791WMNM0dgkQSJIB65TXv9I6M53OWjRS+Gu4G4NY79c1SBg8YWAnqLkI/llouKAIDU wdKmOTqy2jqWLEdSggCG/ymkd8nKhoA+UUMmE/22Ai6IuKpNoLJahnkeoUNZ3gsen0BL J6kRQycKw3PVPQI8c6FHNmnP7LiN2yr788Z9aAZwA0++0Po9Wem6tP2A3fyNdw82mWxc CEfw== X-Gm-Message-State: APjAAAWATDELqkap8iBphIRWBLI9BjSRnohKDDmgSiuwu4GYtvrBw4bY HifFNBR9hewbCCkim2PCQQM= X-Google-Smtp-Source: APXvYqwuURFtr74gcAdxuhdOUMJT8Mw0FVcPIAOmsEx09f3Es7Yny0i9Cs0ALvPBBKyP2FQHEdEIIQ== X-Received: by 2002:a17:902:28e9:: with SMTP id f96mr39314127plb.114.1563342008884; Tue, 16 Jul 2019 22:40:08 -0700 (PDT) Received: from bobo.local0.net ([203.220.8.141]) by smtp.gmail.com with ESMTPSA id g18sm39322656pgm.9.2019.07.16.22.40.05 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 16 Jul 2019 22:40:08 -0700 (PDT) From: Nicholas Piggin To: David Gibson Date: Wed, 17 Jul 2019 15:39:49 +1000 Message-Id: <20190717053952.13729-2-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190717053952.13729-1-npiggin@gmail.com> References: <20190717053952.13729-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::633 Subject: [Qemu-devel] [PATCH v5 1/4] spapr: Implement VPA 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 Reviewed-by: Cédric Le Goater --- Changes since v4: - Store to VPA on the way out as well. - Increment the dispatch counter directly in the VPA, which means it will migrate with guest memory the same as KVM. - Prod need not be migrated, add a comment. hw/ppc/spapr.c | 41 +++++++++++++++++++++++++++++++++ hw/ppc/spapr_cpu_core.c | 4 +++- hw/ppc/spapr_hcall.c | 5 ---- include/hw/ppc/spapr.h | 7 ++++++ include/hw/ppc/spapr_cpu_core.h | 1 + target/ppc/cpu.h | 2 ++ target/ppc/translate_init.inc.c | 25 ++++++++++++++++++++ 7 files changed, 79 insertions(+), 6 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 821f0d4a49..13c423347e 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -4302,6 +4302,45 @@ 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; + if (spapr_cpu->vpa_addr) { + CPUState *cs = CPU(cpu); + unsigned int dispatch; + + dispatch = ldl_be_phys(cs->as, + spapr_cpu->vpa_addr + VPA_DISPATCH_COUNTER); + dispatch++; + if ((dispatch & 1) != 0) /* guest set the "wrong" value */ + dispatch++; + stl_be_phys(cs->as, + spapr_cpu->vpa_addr + VPA_DISPATCH_COUNTER, dispatch); + } +} + +static void spapr_cpu_exec_exit(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu) +{ + SpaprCpuState *spapr_cpu = spapr_cpu_state(cpu); + + if (spapr_cpu->vpa_addr) { + CPUState *cs = CPU(cpu); + unsigned int dispatch; + + dispatch = ldl_be_phys(cs->as, + spapr_cpu->vpa_addr + VPA_DISPATCH_COUNTER); + dispatch++; + if ((dispatch & 1) != 1) /* guest set the "wrong" value */ + dispatch++; + stl_be_phys(cs->as, + spapr_cpu->vpa_addr + VPA_DISPATCH_COUNTER, dispatch); + } +} + static void spapr_machine_class_init(ObjectClass *oc, void *data) { MachineClass *mc = MACHINE_CLASS(oc); @@ -4358,6 +4397,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..54abf5308c 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,8 @@ 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); + 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..a40cd08ea0 100644 --- a/include/hw/ppc/spapr_cpu_core.h +++ b/include/hw/ppc/spapr_cpu_core.h @@ -46,6 +46,7 @@ typedef struct SpaprCpuState { uint64_t vpa_addr; uint64_t slb_shadow_addr, slb_shadow_size; uint64_t dtl_addr, dtl_size; + bool prod; /* not migrated, only used to improve dispatch latencies */ 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 Wed Jul 17 05:39:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11047171 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 D478814DB for ; Wed, 17 Jul 2019 05:41:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C452E284DC for ; Wed, 17 Jul 2019 05:41:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B688F28708; Wed, 17 Jul 2019 05:41:09 +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 662D9284DC for ; Wed, 17 Jul 2019 05:41:09 +0000 (UTC) Received: from localhost ([::1]:54184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hncge-0005h9-IH for patchwork-qemu-devel@patchwork.kernel.org; Wed, 17 Jul 2019 01:41:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50113) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hncfq-00021B-2p for qemu-devel@nongnu.org; Wed, 17 Jul 2019 01:40:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hncfp-0005GQ-05 for qemu-devel@nongnu.org; Wed, 17 Jul 2019 01:40:17 -0400 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]:38936) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hncfl-0005Bf-Rg; Wed, 17 Jul 2019 01:40:13 -0400 Received: by mail-pf1-x444.google.com with SMTP id f17so6266297pfn.6; Tue, 16 Jul 2019 22:40:13 -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=FdXjsO5mRmokaFRmbwR/DaaQqePC8CSAjMzr9fCK1JTZS5QUBEbVgTP1qCEHlVoQhb en/nb6cw3bYR2G6ixAkmHLyNZdhhq5MIHpyHfcebIM8CbNM8PyMrusztOfpxhH7ZfFJd EkG+Iia1TuaxC4F0R3E5p+QfubJSOz/fgvL36/svz4hAIFxyXL1L8/sjJWdKTp3acari uwFVo1X2ZyoMxWsThoJEvVciVP94/bK/2GZD9ktrgeN1ggFKMFffv+7+v+h/ebZSkjwb 7c9BX4Ji0euILO37F+EA+9IZYdBr82la4XcHMy4ndexh0LfFKbxm23WLXRahrB4IKSd8 X4og== 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=PmaQuFQsw3NyHcE5ircPM1OipIQOu70DkdciNRRiuVOvsIB/DJABAD8FnyGDfSMRW4 wVtiPq2ugD9vEonb8dg6zKIirCrNrTb4pKELYdReCVaNl6YnbY0+6nhWJiAqIgK+fi3d Bhv+AbR3+wbLDJ1Mz3UOsJSdujKUDQizLPvVEM9eJmgkcshM68AySF+biNC49+1fmHBC dkbDzJHirSYjX9+1Fz7712NFO0EzFDK9GMjfcQs7zfWD6a3yFJ4zXmp4IIp0lotkr3ZO PTIQdmnQ6Oox2atJ8zbGD4FCEtGDIzzg6Fnbzd1UtojNaQETKIe10AFJUsPHuVPFS7AK gIqg== X-Gm-Message-State: APjAAAUlUN+Zs+IilIVMBrmNV+ctMvrqF7JUPXos3dmUuxnULpHlYkT+ lNXHBvzDGPj2ufRhX+o9cks= X-Google-Smtp-Source: APXvYqyRqAdRjQuTCq0nXyBslfjQ3C2ahv49npfxSv4hCG6uRpz6iBO9AICbO2M4gc+jJ+7lNGIN4w== X-Received: by 2002:a63:9e43:: with SMTP id r3mr13698802pgo.148.1563342013018; Tue, 16 Jul 2019 22:40:13 -0700 (PDT) Received: from bobo.local0.net ([203.220.8.141]) by smtp.gmail.com with ESMTPSA id g18sm39322656pgm.9.2019.07.16.22.40.09 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 16 Jul 2019 22:40:12 -0700 (PDT) From: Nicholas Piggin To: David Gibson Date: Wed, 17 Jul 2019 15:39:50 +1000 Message-Id: <20190717053952.13729-3-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190717053952.13729-1-npiggin@gmail.com> References: <20190717053952.13729-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::444 Subject: [Qemu-devel] [PATCH v5 2/4] 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 Wed Jul 17 05:39:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11047167 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 4715A138B for ; Wed, 17 Jul 2019 05:40:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3638328179 for ; Wed, 17 Jul 2019 05:40:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29C82285F9; Wed, 17 Jul 2019 05:40:50 +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 BEC3B28179 for ; Wed, 17 Jul 2019 05:40:49 +0000 (UTC) Received: from localhost ([::1]:54172 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hncgK-0004Ad-EF for patchwork-qemu-devel@patchwork.kernel.org; Wed, 17 Jul 2019 01:40:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50221) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hncfy-0002dn-CT for qemu-devel@nongnu.org; Wed, 17 Jul 2019 01:40:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hncfw-0005Ps-Vy for qemu-devel@nongnu.org; Wed, 17 Jul 2019 01:40:26 -0400 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]:36587) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hncfq-0005Gr-0H; Wed, 17 Jul 2019 01:40:19 -0400 Received: by mail-pl1-x644.google.com with SMTP id k8so11351807plt.3; Tue, 16 Jul 2019 22:40:17 -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=4ymRbbQ1EIHFO3Mw1nCIQEG1l7W4bUNAte9gP14Oo18=; b=YW6w6fONBsPOOw922YFEe1rvDVqhZF0Zjs0BQ/x9yNLJZXWkgN7CtzAqt0xnb9QLpJ t1TMNjvKbAx8nKiNzfMDeC1LFQcMkT2brPab+mJVZs1NDvaxx03+X4TSXP5r9YGYCsbI AEYXCboaNsdjESRQmZiNFzL/TDWNo/k4WsG9y7U6vX96YmYcrUO+TxTO9tVJ09TCiMN1 wjpFljiTjevTkImj27eZ3zzHGuJpd0Lbu7Y485+T/Fq7s4KRA0d1P6VU6I7N8+SXIEFY 9JGtHvSmf5DWYD006DTcgLt1+O7vmH3oLq7QLPKs66nPyLhVU1QImm4DPXkEXp93tysv AQtA== 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=4ymRbbQ1EIHFO3Mw1nCIQEG1l7W4bUNAte9gP14Oo18=; b=k23yV5vNe2vnRTVUgVBBIFGfu8qzIRH95bRry8y4FEdejG5nrmjRFFPl3bnQ7i2wnG lYSvwa0RoesGAlZZtc+fZpCTyQerO5hl1TlXEJyaE+Rwf4mNnCUSdoRqPEseNqtU58nC OKk1N5h734sthEFUUcj5NiRjaivSkNAQLf3wPbOcAU5HNRtPppNyCIhqi1fBuivSych1 k18kVxGASOBq3GJpu3UYQSEzes3lainsU0bZEwomJzrbYW4kx8lWWxZB/zVEshHxDX4k bmtGgdOv4hRkDkijgl5Gfs8FstHSDU4ncoZFDgdD6/E8KOKk7hcYMo3TyxFZ8MKRvylC uGYg== X-Gm-Message-State: APjAAAUuqkUaOG/wp7C/mdUT8GK+/WJ5WBvOIJxYPODw9DmdReN1Wt7c GYnShaD8fw6+KTbxh84qV9k2AnOR X-Google-Smtp-Source: APXvYqxskJ6fxN864Ec3dZPi4jRkAUj84m4cmIYyBMsGVww3hSPXm0D5zHrsvRqWgvClzXjxcUSoWQ== X-Received: by 2002:a17:902:28e9:: with SMTP id f96mr39314755plb.114.1563342017145; Tue, 16 Jul 2019 22:40:17 -0700 (PDT) Received: from bobo.local0.net ([203.220.8.141]) by smtp.gmail.com with ESMTPSA id g18sm39322656pgm.9.2019.07.16.22.40.13 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 16 Jul 2019 22:40:16 -0700 (PDT) From: Nicholas Piggin To: David Gibson Date: Wed, 17 Jul 2019 15:39:51 +1000 Message-Id: <20190717053952.13729-4-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190717053952.13729-1-npiggin@gmail.com> References: <20190717053952.13729-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 v5 3/4] 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 Reviewed-by: Greg Kurz --- Changes since v4: - Style, added justification comments, spelling. - Fixed trying to dereference spapr_cpu for a -1 target. hw/ppc/spapr_hcall.c | 68 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/hw/ppc/spapr_hcall.c b/hw/ppc/spapr_hcall.c index 8b208ab259..5e655172b2 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1069,6 +1069,73 @@ 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]; + CPUState *cs = CPU(cpu); + SpaprCpuState *spapr_cpu; + + /* + * -1 means confer to all other CPUs without dispatch counter check, + * otherwise it's a targeted confer. + */ + if (target != -1) { + PowerPCCPU *target_cpu = spapr_find_cpu(target); + CPUState *target_cs = CPU(target_cpu); + unsigned int target_dispatch; + + if (!target_cs) { + return H_PARAMETER; + } + + spapr_cpu = spapr_cpu_state(target_cpu); + + /* + * target == self is a special case, we wait until prodded, 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->vpa_addr || ((dispatch & 1) == 0)) { + return H_SUCCESS; + } + + target_dispatch = ldl_be_phys(cs->as, + spapr_cpu->vpa_addr + VPA_DISPATCH_COUNTER); + if (target_dispatch != dispatch) { + return H_SUCCESS; + } + + /* + * The targeted confer does not do anything special beyond yielding + * the current vCPU, but even this should be better than nothing. + * At least for single-threaded tcg, it gives the target a chance to + * run before we run again. Multi-threaded tcg does not really do + * anything with EXCP_YIELD yet. + */ + } + + cs->exception_index = EXCP_YIELD; + cs->exit_request = 1; + cpu_loop_exit(cs); + + return H_SUCCESS; +} + static target_ulong h_prod(PowerPCCPU *cpu, SpaprMachineState *spapr, target_ulong opcode, target_ulong *args) { @@ -1909,6 +1976,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 Wed Jul 17 05:39:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 11047169 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 D3E5614DB for ; Wed, 17 Jul 2019 05:40:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C319D28179 for ; Wed, 17 Jul 2019 05:40:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B68F3285F2; Wed, 17 Jul 2019 05:40:57 +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 5656B28179 for ; Wed, 17 Jul 2019 05:40:57 +0000 (UTC) Received: from localhost ([::1]:54180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hncgS-0004kJ-6b for patchwork-qemu-devel@patchwork.kernel.org; Wed, 17 Jul 2019 01:40:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50236) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hncfy-0002gc-Ub for qemu-devel@nongnu.org; Wed, 17 Jul 2019 01:40:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hncfx-0005Qx-QP for qemu-devel@nongnu.org; Wed, 17 Jul 2019 01:40:26 -0400 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]:36553) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hncfu-0005KX-2w; Wed, 17 Jul 2019 01:40:22 -0400 Received: by mail-pg1-x544.google.com with SMTP id l21so10580276pgm.3; Tue, 16 Jul 2019 22:40:21 -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=BR3uMip3p9rnfFlWfUdS1X+rAUOUHyRPq5JXUGBoDVk=; b=JZuKTF1NofW84NPlqpyLlE2jvAzxTfaIVkrLKspqqEi8tI/OY7PJiQKogecFs4xZpr EtmCMnphmqodt9fdLYNv3HxldWnE+pg1mAQyrME3SvzbYftPcRMXp1NyXo2GNvznG6TE 6QyJH3CFLDwZm7MwioqlchxigqOjFeLeLlkz1VbDB5ZxB1Mu1c8FfZV0SXJ3uWQsBWS2 qxLv13MLavT9aLa2EA2qex+um2EIB/OpWSpElKOydKc8+kjlsEe3LDYMp/kXFuRlrmFA eqZbgK9wQsPGwwWfA7J3A8Og+3a3gP9JihV70/VmegZhoPhYqzBIybLjU+T2fqh9jAAG zPPQ== 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=BR3uMip3p9rnfFlWfUdS1X+rAUOUHyRPq5JXUGBoDVk=; b=YptT89oZqMlqQ29T9P7zvhyy5tpGWf+GIHKvfKcQ3tdJb2QIU8kS2kgl+5+lCD43M4 IzAdNoYcD6c7JiuPKwuKT02sq/0aGK2uLCd+oRxSyiiWnhZcpcjzrq/8unTglL8Z7IWu 8/PovUWqKKSKQX7SzEwjjdWig42JCcTk0L/+FNjwyWsdqjL8dqTcNAKMTfEwBNqz3iwY Gwxu9oACphBbxXUekX5hyzuG8SDIbIhN9zk6iSSyqAN7wMkDLp0/QKFS3xlibXoCQ5es z3/Slan/7klvAfCWhxA3mKTSsufxSwy7YH8pfeL+93O6cBTSvFU+RXeTH6ASQEuvMb/+ 9Scw== X-Gm-Message-State: APjAAAVmtWd/fBxKmGQ0jR+ToRIKpq8W4vfX6OMS7WtDm7OiXiqZVxZf QRhXMZVeREEq176EJB3zDQs= X-Google-Smtp-Source: APXvYqxbz/xx7B65KB1HmeUsREU5sZOiaV4Z3iKyF9JK/pn+3JtnhvHhIaQ73rG2ze8c7596DJHu+g== X-Received: by 2002:a63:4846:: with SMTP id x6mr2161685pgk.332.1563342021085; Tue, 16 Jul 2019 22:40:21 -0700 (PDT) Received: from bobo.local0.net ([203.220.8.141]) by smtp.gmail.com with ESMTPSA id g18sm39322656pgm.9.2019.07.16.22.40.17 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 16 Jul 2019 22:40:20 -0700 (PDT) From: Nicholas Piggin To: David Gibson Date: Wed, 17 Jul 2019 15:39:52 +1000 Message-Id: <20190717053952.13729-5-npiggin@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190717053952.13729-1-npiggin@gmail.com> References: <20190717053952.13729-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::544 Subject: [Qemu-devel] [PATCH v5 4/4] 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 --- Changes since v4: - Style hw/ppc/spapr.c | 1 + hw/ppc/spapr_hcall.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 13c423347e..59cd24f9c3 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 5e655172b2..57c1ee0fe1 100644 --- a/hw/ppc/spapr_hcall.c +++ b/hw/ppc/spapr_hcall.c @@ -1069,6 +1069,48 @@ 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) { @@ -1979,6 +2021,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 */