From patchwork Wed Dec 9 17:00:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 11961949 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CAD6C433FE for ; Wed, 9 Dec 2020 17:10:35 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0249123C30 for ; Wed, 9 Dec 2020 17:10:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0249123C30 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kaod.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:36910 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kn2z4-0006Pv-3e for qemu-devel@archiver.kernel.org; Wed, 09 Dec 2020 12:10:34 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36184) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kn2pz-0006Th-8m for qemu-devel@nongnu.org; Wed, 09 Dec 2020 12:01:11 -0500 Received: from us-smtp-delivery-44.mimecast.com ([205.139.111.44]:54004) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kn2pw-0000qa-VB for qemu-devel@nongnu.org; Wed, 09 Dec 2020 12:01:10 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-326-7YL6mpyEP3KxcjVP4aScNA-1; Wed, 09 Dec 2020 12:01:04 -0500 X-MC-Unique: 7YL6mpyEP3KxcjVP4aScNA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D2BFE803627; Wed, 9 Dec 2020 17:01:02 +0000 (UTC) Received: from bahia.redhat.com (ovpn-113-78.ams2.redhat.com [10.36.113.78]) by smtp.corp.redhat.com (Postfix) with ESMTP id C8BDF5D6CF; Wed, 9 Dec 2020 17:01:01 +0000 (UTC) From: Greg Kurz To: qemu-devel@nongnu.org Subject: [PATCH 6/6] target/ppc: Add mce_req_event() handler to PPCVirtualHypervisorClass Date: Wed, 9 Dec 2020 18:00:52 +0100 Message-Id: <20201209170052.1431440-7-groug@kaod.org> In-Reply-To: <20201209170052.1431440-1-groug@kaod.org> References: <20201209170052.1431440-1-groug@kaod.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=groug@kaod.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kaod.org Received-SPF: softfail client-ip=205.139.111.44; envelope-from=groug@kaod.org; helo=us-smtp-delivery-44.mimecast.com X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_SOFTFAIL=0.665 autolearn=no autolearn_force=no X-Spam_action: no action 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: qemu-ppc@nongnu.org, Greg Kurz , David Gibson Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" kvm_handle_nmi() directly calls spapr_mce_req_event() which is machine level code. Apart from being ugly, this forces spapr_mce_req_event() to rely on qdev_get_machine() to get a pointer to the machine state. This is a bit unfortunate since POWER CPUs have a backlink to the virtual hypervisor, which happens to be the machine itself with sPAPR. Turn spapr_mce_req_event() into a PPC virtual hypervisor operation, and adapt kvm_handle_nmi() to call it as such. Signed-off-by: Greg Kurz --- include/hw/ppc/spapr.h | 3 ++- target/ppc/cpu.h | 2 ++ hw/ppc/spapr.c | 1 + hw/ppc/spapr_events.c | 5 +++-- target/ppc/kvm.c | 9 +++++++-- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index e0f10f252c08..476c5b809794 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -852,7 +852,8 @@ void spapr_clear_pending_hotplug_events(SpaprMachineState *spapr); int spapr_max_server_number(SpaprMachineState *spapr); void spapr_store_hpte(PowerPCCPU *cpu, hwaddr ptex, uint64_t pte0, uint64_t pte1); -void spapr_mce_req_event(PowerPCCPU *cpu, bool recovered); +void spapr_mce_req_event(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu, + bool recovered); bool spapr_machine_using_legacy_numa(SpaprMachineState *spapr); /* DRC callbacks. */ diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 2609e4082ed8..5bac68aec826 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1219,6 +1219,8 @@ struct PPCVirtualHypervisorClass { 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); + void (*mce_req_event)(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu, + bool recovered); }; #define TYPE_PPC_VIRTUAL_HYPERVISOR "ppc-virtual-hypervisor" diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index aca7d7af283a..09fc605f11ba 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -4441,6 +4441,7 @@ static void spapr_machine_class_init(ObjectClass *oc, void *data) 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; + vhc->mce_req_event = spapr_mce_req_event; xic->ics_get = spapr_ics_get; xic->ics_resend = spapr_ics_resend; xic->icp_get = spapr_icp_get; diff --git a/hw/ppc/spapr_events.c b/hw/ppc/spapr_events.c index 3f37b49fd8ad..8e988eb939da 100644 --- a/hw/ppc/spapr_events.c +++ b/hw/ppc/spapr_events.c @@ -868,9 +868,10 @@ static void spapr_mce_dispatch_elog(SpaprMachineState *spapr, PowerPCCPU *cpu, ppc_cpu_do_fwnmi_machine_check(cs, spapr->fwnmi_machine_check_addr); } -void spapr_mce_req_event(PowerPCCPU *cpu, bool recovered) +void spapr_mce_req_event(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu, + bool recovered) { - SpaprMachineState *spapr = SPAPR_MACHINE(qdev_get_machine()); + SpaprMachineState *spapr = SPAPR_MACHINE(vhyp); CPUState *cs = CPU(cpu); int ret; Error *local_err = NULL; diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index daf690a67820..ba6edf178a39 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -2816,10 +2816,15 @@ int kvm_handle_nmi(PowerPCCPU *cpu, struct kvm_run *run) { uint16_t flags = run->flags & KVM_RUN_PPC_NMI_DISP_MASK; - cpu_synchronize_state(CPU(cpu)); + if (cpu->vhyp) { + PPCVirtualHypervisorClass *vhc = + PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp); - spapr_mce_req_event(cpu, flags == KVM_RUN_PPC_NMI_DISP_FULLY_RECOV); + cpu_synchronize_state(CPU(cpu)); + vhc->mce_req_event(cpu->vhyp, cpu, + flags == KVM_RUN_PPC_NMI_DISP_FULLY_RECOV); + } return 0; } #endif