From nobody Sun May 5 04:30:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1574074966; cv=none; d=zoho.com; s=zohoarc; b=i7aKLKru/9FdYU9qeqiaeQI8ozxlNEwR319v9rF69h7wieVlynqWVazduVHemWHPga212i2mSIkEb+KuqS6Y2cmhgBup3cfvzX5ZH6mOIr+H6a5w57VXnEv8HRgjqq5HIdnB+gCuj/3gV+KwrRSFTOYI1LTVwmq3+QWnHnrRcHw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574074966; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GzS3Az8wk5urPTvK4sepmO4IZ0GOL+RERqiJYhBPr/w=; b=OLvwWQL0QEmJhx1aARiv2eDJqcvpulN59mEMdXsVYUCWYtEl7/RWSDEeyvx3apfxLoJGRPtO6R75OrcY+n5VmrK+++tKbvAUZPHrgkctPm11/Q1bBtXIu+q4b3I/6SE13uzZXrmfuGkkHGlcWJ1Cizwn7kKvPPEU15hvszVlX5w= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1574074966173558.540496194587; Mon, 18 Nov 2019 03:02:46 -0800 (PST) Received: from localhost ([::1]:60586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iWens-0002PS-Dw for importer@patchew.org; Mon, 18 Nov 2019 06:02:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42360) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iWeez-0001S4-N8 for qemu-devel@nongnu.org; Mon, 18 Nov 2019 05:53:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iWeex-0004P6-Ls for qemu-devel@nongnu.org; Mon, 18 Nov 2019 05:53:33 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:39516 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iWeex-0004Or-GZ for qemu-devel@nongnu.org; Mon, 18 Nov 2019 05:53:31 -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-51-VoUuKl0yMFWOmhjQCLzxBw-1; Mon, 18 Nov 2019 05:53:27 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B919FDB20; Mon, 18 Nov 2019 10:53:25 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-117-32.ams2.redhat.com [10.36.117.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1DA26090C; Mon, 18 Nov 2019 10:53:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574074410; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GzS3Az8wk5urPTvK4sepmO4IZ0GOL+RERqiJYhBPr/w=; b=i6Iu/ZwUYmJBGgVKtHY9pmsUICpSuF7ERwyQibgAeP4P3DFmmvdZcudxec02fJjdrtegE9 AXF29B6LOyKAXEfFs7k/clEghRQZ7D73n0p1u87bQCF8BS06HMYQ2VuTy1LWBKaOPhhyYC qeZiST0Tpwh4Q40qM+UK5bqU24vhH+I= From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v2 1/6] ppc: Add intc_destroy() handlers to SpaprInterruptController/PnvChip Date: Mon, 18 Nov 2019 11:53:14 +0100 Message-Id: <20191118105319.7658-2-lvivier@redhat.com> In-Reply-To: <20191118105319.7658-1-lvivier@redhat.com> References: <20191118105319.7658-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: VoUuKl0yMFWOmhjQCLzxBw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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: Laurent Vivier , Mark Cave-Ayland , Greg Kurz , qemu-ppc@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Greg Kurz SpaprInterruptControllerClass and PnvChipClass have an intc_create() method that calls the appropriate routine, ie. icp_create() or xive_tctx_create(), to establish the link between the VCPU and the presenter component of the interrupt controller during realize. There aren't any symmetrical call to be called when the VCPU gets unrealized though. It is assumed that object_unparent() is the only thing to do. This is questionable because the parenting logic around the CPU and presenter objects is really an implementation detail of the interrupt controller. It shouldn't be open-coded in the machine code. Fix this by adding an intc_destroy() method that undoes what was done in intc_create(). Also NULLify the presenter pointers to avoid having stale pointers around. This will allow to reliably check if a vCPU has a valid presenter. Signed-off-by: Greg Kurz Message-Id: <157192724208.3146912.7254684777515287626.stgit@bahia.lan> Signed-off-by: David Gibson Signed-off-by: Laurent Vivier --- hw/intc/spapr_xive.c | 10 ++++++++++ hw/intc/xics.c | 5 +++++ hw/intc/xics_spapr.c | 10 ++++++++++ hw/intc/xive.c | 5 +++++ hw/ppc/pnv.c | 21 +++++++++++++++++++++ hw/ppc/pnv_core.c | 7 ++++--- hw/ppc/spapr_cpu_core.c | 7 +------ hw/ppc/spapr_irq.c | 14 ++++++++++++++ include/hw/ppc/pnv.h | 1 + include/hw/ppc/spapr_irq.h | 2 ++ include/hw/ppc/xics.h | 1 + include/hw/ppc/xive.h | 1 + 12 files changed, 75 insertions(+), 9 deletions(-) diff --git a/hw/intc/spapr_xive.c b/hw/intc/spapr_xive.c index d8e1291905c3..9cb8d38a3bab 100644 --- a/hw/intc/spapr_xive.c +++ b/hw/intc/spapr_xive.c @@ -555,6 +555,15 @@ static void spapr_xive_cpu_intc_reset(SpaprInterruptCo= ntroller *intc, xive_tctx_set_os_cam(tctx, xive_nvt_cam_line(nvt_blk, nvt_idx)); } =20 +static void spapr_xive_cpu_intc_destroy(SpaprInterruptController *intc, + PowerPCCPU *cpu) +{ + SpaprCpuState *spapr_cpu =3D spapr_cpu_state(cpu); + + xive_tctx_destroy(spapr_cpu->tctx); + spapr_cpu->tctx =3D NULL; +} + static void spapr_xive_set_irq(SpaprInterruptController *intc, int irq, in= t val) { SpaprXive *xive =3D SPAPR_XIVE(intc); @@ -692,6 +701,7 @@ static void spapr_xive_class_init(ObjectClass *klass, v= oid *data) sicc->deactivate =3D spapr_xive_deactivate; sicc->cpu_intc_create =3D spapr_xive_cpu_intc_create; sicc->cpu_intc_reset =3D spapr_xive_cpu_intc_reset; + sicc->cpu_intc_destroy =3D spapr_xive_cpu_intc_destroy; sicc->claim_irq =3D spapr_xive_claim_irq; sicc->free_irq =3D spapr_xive_free_irq; sicc->set_irq =3D spapr_xive_set_irq; diff --git a/hw/intc/xics.c b/hw/intc/xics.c index 6da05763f9db..935f325749cb 100644 --- a/hw/intc/xics.c +++ b/hw/intc/xics.c @@ -401,6 +401,11 @@ Object *icp_create(Object *cpu, const char *type, XICS= Fabric *xi, Error **errp) return obj; } =20 +void icp_destroy(ICPState *icp) +{ + object_unparent(OBJECT(icp)); +} + /* * ICS: Source layer */ diff --git a/hw/intc/xics_spapr.c b/hw/intc/xics_spapr.c index 7418fb9f370c..b3705dab0e8a 100644 --- a/hw/intc/xics_spapr.c +++ b/hw/intc/xics_spapr.c @@ -352,6 +352,15 @@ static void xics_spapr_cpu_intc_reset(SpaprInterruptCo= ntroller *intc, icp_reset(spapr_cpu_state(cpu)->icp); } =20 +static void xics_spapr_cpu_intc_destroy(SpaprInterruptController *intc, + PowerPCCPU *cpu) +{ + SpaprCpuState *spapr_cpu =3D spapr_cpu_state(cpu); + + icp_destroy(spapr_cpu->icp); + spapr_cpu->icp =3D NULL; +} + static int xics_spapr_claim_irq(SpaprInterruptController *intc, int irq, bool lsi, Error **errp) { @@ -440,6 +449,7 @@ static void ics_spapr_class_init(ObjectClass *klass, vo= id *data) sicc->deactivate =3D xics_spapr_deactivate; sicc->cpu_intc_create =3D xics_spapr_cpu_intc_create; sicc->cpu_intc_reset =3D xics_spapr_cpu_intc_reset; + sicc->cpu_intc_destroy =3D xics_spapr_cpu_intc_destroy; sicc->claim_irq =3D xics_spapr_claim_irq; sicc->free_irq =3D xics_spapr_free_irq; sicc->set_irq =3D xics_spapr_set_irq; diff --git a/hw/intc/xive.c b/hw/intc/xive.c index f066be5eb5e3..38257aa02083 100644 --- a/hw/intc/xive.c +++ b/hw/intc/xive.c @@ -696,6 +696,11 @@ error: return NULL; } =20 +void xive_tctx_destroy(XiveTCTX *tctx) +{ + object_unparent(OBJECT(tctx)); +} + /* * XIVE ESB helpers */ diff --git a/hw/ppc/pnv.c b/hw/ppc/pnv.c index 60632720ef6f..627c08e5b985 100644 --- a/hw/ppc/pnv.c +++ b/hw/ppc/pnv.c @@ -778,6 +778,7 @@ static void pnv_chip_power8_intc_create(PnvChip *chip, = PowerPCCPU *cpu, pnv_cpu->intc =3D obj; } =20 + static void pnv_chip_power8_intc_reset(PnvChip *chip, PowerPCCPU *cpu) { PnvCPUState *pnv_cpu =3D pnv_cpu_state(cpu); @@ -785,6 +786,14 @@ static void pnv_chip_power8_intc_reset(PnvChip *chip, = PowerPCCPU *cpu) icp_reset(ICP(pnv_cpu->intc)); } =20 +static void pnv_chip_power8_intc_destroy(PnvChip *chip, PowerPCCPU *cpu) +{ + PnvCPUState *pnv_cpu =3D pnv_cpu_state(cpu); + + icp_destroy(ICP(pnv_cpu->intc)); + pnv_cpu->intc =3D NULL; +} + /* * 0:48 Reserved - Read as zeroes * 49:52 Node ID @@ -829,6 +838,14 @@ static void pnv_chip_power9_intc_reset(PnvChip *chip, = PowerPCCPU *cpu) xive_tctx_reset(XIVE_TCTX(pnv_cpu->intc)); } =20 +static void pnv_chip_power9_intc_destroy(PnvChip *chip, PowerPCCPU *cpu) +{ + PnvCPUState *pnv_cpu =3D pnv_cpu_state(cpu); + + xive_tctx_destroy(XIVE_TCTX(pnv_cpu->intc)); + pnv_cpu->intc =3D NULL; +} + /* * Allowed core identifiers on a POWER8 Processor Chip : * @@ -999,6 +1016,7 @@ static void pnv_chip_power8e_class_init(ObjectClass *k= lass, void *data) k->core_pir =3D pnv_chip_core_pir_p8; k->intc_create =3D pnv_chip_power8_intc_create; k->intc_reset =3D pnv_chip_power8_intc_reset; + k->intc_destroy =3D pnv_chip_power8_intc_destroy; k->isa_create =3D pnv_chip_power8_isa_create; k->dt_populate =3D pnv_chip_power8_dt_populate; k->pic_print_info =3D pnv_chip_power8_pic_print_info; @@ -1019,6 +1037,7 @@ static void pnv_chip_power8_class_init(ObjectClass *k= lass, void *data) k->core_pir =3D pnv_chip_core_pir_p8; k->intc_create =3D pnv_chip_power8_intc_create; k->intc_reset =3D pnv_chip_power8_intc_reset; + k->intc_destroy =3D pnv_chip_power8_intc_destroy; k->isa_create =3D pnv_chip_power8_isa_create; k->dt_populate =3D pnv_chip_power8_dt_populate; k->pic_print_info =3D pnv_chip_power8_pic_print_info; @@ -1039,6 +1058,7 @@ static void pnv_chip_power8nvl_class_init(ObjectClass= *klass, void *data) k->core_pir =3D pnv_chip_core_pir_p8; k->intc_create =3D pnv_chip_power8_intc_create; k->intc_reset =3D pnv_chip_power8_intc_reset; + k->intc_destroy =3D pnv_chip_power8_intc_destroy; k->isa_create =3D pnv_chip_power8nvl_isa_create; k->dt_populate =3D pnv_chip_power8_dt_populate; k->pic_print_info =3D pnv_chip_power8_pic_print_info; @@ -1209,6 +1229,7 @@ static void pnv_chip_power9_class_init(ObjectClass *k= lass, void *data) k->core_pir =3D pnv_chip_core_pir_p9; k->intc_create =3D pnv_chip_power9_intc_create; k->intc_reset =3D pnv_chip_power9_intc_reset; + k->intc_destroy =3D pnv_chip_power9_intc_destroy; k->isa_create =3D pnv_chip_power9_isa_create; k->dt_populate =3D pnv_chip_power9_dt_populate; k->pic_print_info =3D pnv_chip_power9_pic_print_info; diff --git a/hw/ppc/pnv_core.c b/hw/ppc/pnv_core.c index e81cd3a3e047..61b3d3ce2250 100644 --- a/hw/ppc/pnv_core.c +++ b/hw/ppc/pnv_core.c @@ -269,11 +269,12 @@ err: error_propagate(errp, local_err); } =20 -static void pnv_core_cpu_unrealize(PowerPCCPU *cpu) +static void pnv_core_cpu_unrealize(PowerPCCPU *cpu, PnvChip *chip) { PnvCPUState *pnv_cpu =3D pnv_cpu_state(cpu); + PnvChipClass *pcc =3D PNV_CHIP_GET_CLASS(chip); =20 - object_unparent(OBJECT(pnv_cpu_state(cpu)->intc)); + pcc->intc_destroy(chip, cpu); cpu_remove_sync(CPU(cpu)); cpu->machine_data =3D NULL; g_free(pnv_cpu); @@ -289,7 +290,7 @@ static void pnv_core_unrealize(DeviceState *dev, Error = **errp) qemu_unregister_reset(pnv_core_reset, pc); =20 for (i =3D 0; i < cc->nr_threads; i++) { - pnv_core_cpu_unrealize(pc->threads[i]); + pnv_core_cpu_unrealize(pc->threads[i], pc->chip); } g_free(pc->threads); } diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index ef7b27a66d56..8339c4c0f86b 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -195,12 +195,7 @@ static void spapr_unrealize_vcpu(PowerPCCPU *cpu, Spap= rCpuCore *sc) if (!sc->pre_3_0_migration) { vmstate_unregister(NULL, &vmstate_spapr_cpu_state, cpu->machine_da= ta); } - if (spapr_cpu_state(cpu)->icp) { - object_unparent(OBJECT(spapr_cpu_state(cpu)->icp)); - } - if (spapr_cpu_state(cpu)->tctx) { - object_unparent(OBJECT(spapr_cpu_state(cpu)->tctx)); - } + spapr_irq_cpu_intc_destroy(SPAPR_MACHINE(qdev_get_machine()), cpu); cpu_remove_sync(CPU(cpu)); object_unparent(OBJECT(cpu)); } diff --git a/hw/ppc/spapr_irq.c b/hw/ppc/spapr_irq.c index b941608b69ba..168044be853a 100644 --- a/hw/ppc/spapr_irq.c +++ b/hw/ppc/spapr_irq.c @@ -234,6 +234,20 @@ void spapr_irq_cpu_intc_reset(SpaprMachineState *spapr= , PowerPCCPU *cpu) } } =20 +void spapr_irq_cpu_intc_destroy(SpaprMachineState *spapr, PowerPCCPU *cpu) +{ + SpaprInterruptController *intcs[] =3D ALL_INTCS(spapr); + int i; + + for (i =3D 0; i < ARRAY_SIZE(intcs); i++) { + SpaprInterruptController *intc =3D intcs[i]; + if (intc) { + SpaprInterruptControllerClass *sicc =3D SPAPR_INTC_GET_CLASS(i= ntc); + sicc->cpu_intc_destroy(intc, cpu); + } + } +} + static void spapr_set_irq(void *opaque, int irq, int level) { SpaprMachineState *spapr =3D SPAPR_MACHINE(opaque); diff --git a/include/hw/ppc/pnv.h b/include/hw/ppc/pnv.h index 2a780e633f23..0b4c722e6b48 100644 --- a/include/hw/ppc/pnv.h +++ b/include/hw/ppc/pnv.h @@ -112,6 +112,7 @@ typedef struct PnvChipClass { uint32_t (*core_pir)(PnvChip *chip, uint32_t core_id); void (*intc_create)(PnvChip *chip, PowerPCCPU *cpu, Error **errp); void (*intc_reset)(PnvChip *chip, PowerPCCPU *cpu); + void (*intc_destroy)(PnvChip *chip, PowerPCCPU *cpu); ISABus *(*isa_create)(PnvChip *chip, Error **errp); void (*dt_populate)(PnvChip *chip, void *fdt); void (*pic_print_info)(PnvChip *chip, Monitor *mon); diff --git a/include/hw/ppc/spapr_irq.h b/include/hw/ppc/spapr_irq.h index 09232999b07e..ff814d13de37 100644 --- a/include/hw/ppc/spapr_irq.h +++ b/include/hw/ppc/spapr_irq.h @@ -53,6 +53,7 @@ typedef struct SpaprInterruptControllerClass { int (*cpu_intc_create)(SpaprInterruptController *intc, PowerPCCPU *cpu, Error **errp); void (*cpu_intc_reset)(SpaprInterruptController *intc, PowerPCCPU *cpu= ); + void (*cpu_intc_destroy)(SpaprInterruptController *intc, PowerPCCPU *c= pu); int (*claim_irq)(SpaprInterruptController *intc, int irq, bool lsi, Error **errp); void (*free_irq)(SpaprInterruptController *intc, int irq); @@ -70,6 +71,7 @@ void spapr_irq_update_active_intc(SpaprMachineState *spap= r); int spapr_irq_cpu_intc_create(SpaprMachineState *spapr, PowerPCCPU *cpu, Error **errp); void spapr_irq_cpu_intc_reset(SpaprMachineState *spapr, PowerPCCPU *cpu); +void spapr_irq_cpu_intc_destroy(SpaprMachineState *spapr, PowerPCCPU *cpu); void spapr_irq_print_info(SpaprMachineState *spapr, Monitor *mon); void spapr_irq_dt(SpaprMachineState *spapr, uint32_t nr_servers, void *fdt, uint32_t phandle); diff --git a/include/hw/ppc/xics.h b/include/hw/ppc/xics.h index 602173c12250..48a75aa4ab75 100644 --- a/include/hw/ppc/xics.h +++ b/include/hw/ppc/xics.h @@ -181,6 +181,7 @@ void icp_resend(ICPState *ss); =20 Object *icp_create(Object *cpu, const char *type, XICSFabric *xi, Error **errp); +void icp_destroy(ICPState *icp); =20 /* KVM */ void icp_get_kvm_state(ICPState *icp); diff --git a/include/hw/ppc/xive.h b/include/hw/ppc/xive.h index 99381639f50c..8fd439ec9bba 100644 --- a/include/hw/ppc/xive.h +++ b/include/hw/ppc/xive.h @@ -416,6 +416,7 @@ uint64_t xive_tctx_tm_read(XiveTCTX *tctx, hwaddr offse= t, unsigned size); void xive_tctx_pic_print_info(XiveTCTX *tctx, Monitor *mon); Object *xive_tctx_create(Object *cpu, XiveRouter *xrtr, Error **errp); void xive_tctx_reset(XiveTCTX *tctx); +void xive_tctx_destroy(XiveTCTX *tctx); =20 static inline uint32_t xive_nvt_cam_line(uint8_t nvt_blk, uint32_t nvt_idx) { --=20 2.23.0 From nobody Sun May 5 04:30:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1574074525; cv=none; d=zoho.com; s=zohoarc; b=dmGI0qEuoyXp9/CN9w/ZPoetuRYdsrW78y52BfbA6R/pToRsgje8JAEyTxAZxUZdNVN+RDfu+Cc4xngKejU/ibza78fozBM+kouzCvxy2fQyk6n/SaEvKPkax9DPkDy4QBBFaZcEtwxNrkzTkjoXW4zxGrGeI9GwPRxhUhCaXgc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574074525; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pLrU9p2DhgfzE1DkGTpdrKbhTRnMgTbOYODJyOf3fEw=; b=NnOg1XxeU+aWLej13IAwAr5q7lvCDIYbzHOlUFKroV42I5ZU8rIOUKsFL6bTVgYpEMM1FjhcbKgkImqcn7GnqeDTzQUdashLnFjlwXPPlX5HM1svPEx0zbSbhtVcgpb3J4AOU63DFcXU6UKRikuQAKbWTOEW4tKtH7KbPvSYpe8= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1574074525585788.9188676751437; Mon, 18 Nov 2019 02:55:25 -0800 (PST) Received: from localhost ([::1]:60480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iWegm-0003I6-7b for importer@patchew.org; Mon, 18 Nov 2019 05:55:24 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42381) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iWef1-0001Uc-Sx for qemu-devel@nongnu.org; Mon, 18 Nov 2019 05:53:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iWef0-0004Q2-MT for qemu-devel@nongnu.org; Mon, 18 Nov 2019 05:53:35 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:58077 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iWef0-0004Pk-IH for qemu-devel@nongnu.org; Mon, 18 Nov 2019 05:53:34 -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-355-KMEOusV4Mh2lGGDBIrOphw-1; Mon, 18 Nov 2019 05:53:29 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 70FF6801FD2; Mon, 18 Nov 2019 10:53:28 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-117-32.ams2.redhat.com [10.36.117.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1AE5A60856; Mon, 18 Nov 2019 10:53:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574074414; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pLrU9p2DhgfzE1DkGTpdrKbhTRnMgTbOYODJyOf3fEw=; b=K8HC60UYwuxTI7PEAqDt47hCc9TqeGPF4Cdf7VOBHNaAaLatWm5pIK7QzLJf+8rV0IUo42 Hrrqmd4JvJcePZXdC8iic/IL+5TWxRf3Hx3xCFeHWFXNOznqEQaVPpoHEO1mJY9GFscXkd Jl7HUh3c+poAIlcwEmJM4yklX/EULt4= From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v2 2/6] xive, xics: Fix reference counting on CPU objects Date: Mon, 18 Nov 2019 11:53:15 +0100 Message-Id: <20191118105319.7658-3-lvivier@redhat.com> In-Reply-To: <20191118105319.7658-1-lvivier@redhat.com> References: <20191118105319.7658-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: KMEOusV4Mh2lGGDBIrOphw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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: Laurent Vivier , Mark Cave-Ayland , Greg Kurz , qemu-ppc@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Greg Kurz When a VCPU gets connected to the XIVE interrupt controller, we add a const link targetting the CPU object to the TCTX object. Similar links are added to the ICP object when using the XICS interrupt controller. As explained in : * The caller must ensure that @target stays alive as long as * this property exists. In the case @target is a child of @obj, * this will be the case. Otherwise, the caller is responsible for * taking a reference. We're in the latter case for both XICS and XIVE. Add the missing calls to object_ref() and object_unref(). This doesn't fix any known issue because the life cycle of the TCTX or ICP happens to be shorter than the one of the CPU or XICS fabric, but better safe than sorry. Signed-off-by: Greg Kurz Reviewed-by: David Gibson Message-Id: <157192724770.3146912.15400869269097231255.stgit@bahia.lan> Signed-off-by: David Gibson Signed-off-by: Laurent Vivier --- hw/intc/xics.c | 8 +++++++- hw/intc/xive.c | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/hw/intc/xics.c b/hw/intc/xics.c index 935f325749cb..5f746079be46 100644 --- a/hw/intc/xics.c +++ b/hw/intc/xics.c @@ -388,8 +388,10 @@ Object *icp_create(Object *cpu, const char *type, XICS= Fabric *xi, Error **errp) obj =3D object_new(type); object_property_add_child(cpu, type, obj, &error_abort); object_unref(obj); + object_ref(OBJECT(xi)); object_property_add_const_link(obj, ICP_PROP_XICS, OBJECT(xi), &error_abort); + object_ref(cpu); object_property_add_const_link(obj, ICP_PROP_CPU, cpu, &error_abort); object_property_set_bool(obj, true, "realized", &local_err); if (local_err) { @@ -403,7 +405,11 @@ Object *icp_create(Object *cpu, const char *type, XICS= Fabric *xi, Error **errp) =20 void icp_destroy(ICPState *icp) { - object_unparent(OBJECT(icp)); + Object *obj =3D OBJECT(icp); + + object_unref(object_property_get_link(obj, ICP_PROP_CPU, &error_abort)= ); + object_unref(object_property_get_link(obj, ICP_PROP_XICS, &error_abort= )); + object_unparent(obj); } =20 /* diff --git a/hw/intc/xive.c b/hw/intc/xive.c index 38257aa02083..952a461d5329 100644 --- a/hw/intc/xive.c +++ b/hw/intc/xive.c @@ -682,6 +682,7 @@ Object *xive_tctx_create(Object *cpu, XiveRouter *xrtr,= Error **errp) obj =3D object_new(TYPE_XIVE_TCTX); object_property_add_child(cpu, TYPE_XIVE_TCTX, obj, &error_abort); object_unref(obj); + object_ref(cpu); object_property_add_const_link(obj, "cpu", cpu, &error_abort); object_property_set_bool(obj, true, "realized", &local_err); if (local_err) { @@ -698,7 +699,10 @@ error: =20 void xive_tctx_destroy(XiveTCTX *tctx) { - object_unparent(OBJECT(tctx)); + Object *obj =3D OBJECT(tctx); + + object_unref(object_property_get_link(obj, "cpu", &error_abort)); + object_unparent(obj); } =20 /* --=20 2.23.0 From nobody Sun May 5 04:30:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1574074522; cv=none; d=zoho.com; s=zohoarc; b=BFnSqUUK9deShq9wc+GCpf+bHih5tFQgKOAqC+juKYSQVP1IxN+h7wQrah9yYLVmw1AtAZimDnlTvfTMzQAgBSPgQlhRJH4C3wl0dYljUpK5txDJwDzpnoau0FZplKhEdj2LmiK6dddfjP0xeaNtxWorOdWUihZIuWdrV7RIO6Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574074522; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=152F3VsBW27j1IFKoVLVwCYJGK5KIGmsJlQ2TDMp0a8=; b=lIyMtDe2VAQuYVa5nmNxV+bMt2vFiNFQt+FMQ1u7+dUiUYUqA2VA8EO7Ox3a/9KSBph4HqjIJs9VjJLvweuc21VfFkZ5barVJSdMCzMLTQIimCrcciExfVMh5VmIe5klc8Y4D6XWtlQxqkPdaWdnbFUUTN7070GBPedwFc4X8CI= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1574074522851647.1488642543397; Mon, 18 Nov 2019 02:55:22 -0800 (PST) Received: from localhost ([::1]:60478 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iWegg-00038c-IC for importer@patchew.org; Mon, 18 Nov 2019 05:55:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42403) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iWef3-0001X0-Lb for qemu-devel@nongnu.org; Mon, 18 Nov 2019 05:53:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iWef2-0004Qg-Ks for qemu-devel@nongnu.org; Mon, 18 Nov 2019 05:53:37 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:39296 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iWef2-0004QS-Gk for qemu-devel@nongnu.org; Mon, 18 Nov 2019 05:53:36 -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-46-D9zpYNcJPm-cycoKrSRBNA-1; Mon, 18 Nov 2019 05:53:31 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 84CC7802688; Mon, 18 Nov 2019 10:53:30 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-117-32.ams2.redhat.com [10.36.117.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6D5660856; Mon, 18 Nov 2019 10:53:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574074416; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=152F3VsBW27j1IFKoVLVwCYJGK5KIGmsJlQ2TDMp0a8=; b=dxIWL68QRqTdmH+cc9oQHXjwniL4a7MCLomyLAnstO35kRNXtDMJILui9eMKsTRqivdkDa 1P+Wf1zxgqKWw+mxLWIdZ2QvqU0P7pWiya7nfB9NfVgL1qoSY+EaKc+6hxLbQ7TW/dHwFl EtBwmvKoD4lHRPaomQWh2mUQuu14+eE= From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v2 3/6] ppc: Skip partially initialized vCPUs in 'info pic' Date: Mon, 18 Nov 2019 11:53:16 +0100 Message-Id: <20191118105319.7658-4-lvivier@redhat.com> In-Reply-To: <20191118105319.7658-1-lvivier@redhat.com> References: <20191118105319.7658-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: D9zpYNcJPm-cycoKrSRBNA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 205.139.110.61 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: Laurent Vivier , Mark Cave-Ayland , Greg Kurz , qemu-ppc@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Greg Kurz CPU_FOREACH() can race with vCPU hotplug/unplug on sPAPR machines, ie. we may try to print out info about a vCPU with a NULL presenter pointer. Check that in order to prevent QEMU from crashing. Signed-off-by: Greg Kurz Message-Id: <157192725327.3146912.12047076483178652551.stgit@bahia.lan> Signed-off-by: David Gibson Signed-off-by: Laurent Vivier --- hw/intc/xics.c | 11 ++++++++++- hw/intc/xive.c | 11 ++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/hw/intc/xics.c b/hw/intc/xics.c index 5f746079be46..e7ac9ba618fa 100644 --- a/hw/intc/xics.c +++ b/hw/intc/xics.c @@ -44,7 +44,16 @@ =20 void icp_pic_print_info(ICPState *icp, Monitor *mon) { - int cpu_index =3D icp->cs ? icp->cs->cpu_index : -1; + int cpu_index; + + /* Skip partially initialized vCPUs. This can happen on sPAPR when vCP= Us + * are hot plugged or unplugged. + */ + if (!icp) { + return; + } + + cpu_index =3D icp->cs ? icp->cs->cpu_index : -1; =20 if (!icp->output) { return; diff --git a/hw/intc/xive.c b/hw/intc/xive.c index 952a461d5329..75dce82fb205 100644 --- a/hw/intc/xive.c +++ b/hw/intc/xive.c @@ -523,9 +523,18 @@ static const char * const xive_tctx_ring_names[] =3D { =20 void xive_tctx_pic_print_info(XiveTCTX *tctx, Monitor *mon) { - int cpu_index =3D tctx->cs ? tctx->cs->cpu_index : -1; + int cpu_index; int i; =20 + /* Skip partially initialized vCPUs. This can happen on sPAPR when vCP= Us + * are hot plugged or unplugged. + */ + if (!tctx) { + return; + } + + cpu_index =3D tctx->cs ? tctx->cs->cpu_index : -1; + if (kvm_irqchip_in_kernel()) { Error *local_err =3D NULL; =20 --=20 2.23.0 From nobody Sun May 5 04:30:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1574074644; cv=none; d=zoho.com; s=zohoarc; b=Un8SQAl7GYeaFSUgb1vIjwUJUQihvcI0grhmHjRZqotufod+mNKBjY/ReWbvL9y6WJbHa/tgY6NHI1V8Y4jboGttKCQO1O63/jzoA5MBibVd4iEC38RBsycuORiTBr62HQlAdd1IIiEDa+3uJ9vcbzz9N2kHa5gYXnjkvzPWQec= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574074644; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AnX5Bp7pofx0wLQCrap7/m/Bi3qK71qWPkamm5SYI2Q=; b=eS5VVswHK0HbMOKist5P3zilk6ElEWtt7jBBcG/jumVpfsBP0YeHiSnoU5V/lrkOfTStKSqHjE5D7hJiUuw9n7R58Im+sxmyxY2E29ynMyiXYfZWmP6z+uxnbFwtZf/GNBQ2D2UJpW2f8zbm1gDaOuB+J5lwIdxTXDnE5oR4Dxs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1574074644246850.5623478129442; Mon, 18 Nov 2019 02:57:24 -0800 (PST) Received: from localhost ([::1]:60516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iWeif-00060H-Df for importer@patchew.org; Mon, 18 Nov 2019 05:57:21 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42432) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iWef6-0001bT-II for qemu-devel@nongnu.org; Mon, 18 Nov 2019 05:53:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iWef5-0004RY-9F for qemu-devel@nongnu.org; Mon, 18 Nov 2019 05:53:40 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:21989 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iWef5-0004RM-59 for qemu-devel@nongnu.org; Mon, 18 Nov 2019 05:53:39 -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-371-xi8x2q9eNPi_H_AgQm4XkQ-1; Mon, 18 Nov 2019 05:53:35 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 52DBA80268B; Mon, 18 Nov 2019 10:53:33 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-117-32.ams2.redhat.com [10.36.117.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id D702260856; Mon, 18 Nov 2019 10:53:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574074418; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AnX5Bp7pofx0wLQCrap7/m/Bi3qK71qWPkamm5SYI2Q=; b=hcPOfFNBF3LI1qREKLjKG9GwAVi3DobdG0EOLyiNDcpdQEb8kUrvMWdkUe1fT7eJSp8M80 Z0ENuS4IksarKpQY2ViWX0fq9g3dRZo+uZchLe7yyd+qZ5JY8UWaz8B9sV8Wjxu+o6u3be Qk0ZkPrcKJkXRLaWKIT+dSn9Nu9EAE8= From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v2 4/6] spapr: Add /chosen to FDT only at reset time to preserve kernel and initramdisk Date: Mon, 18 Nov 2019 11:53:17 +0100 Message-Id: <20191118105319.7658-5-lvivier@redhat.com> In-Reply-To: <20191118105319.7658-1-lvivier@redhat.com> References: <20191118105319.7658-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: xi8x2q9eNPi_H_AgQm4XkQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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: Laurent Vivier , Alexey Kardashevskiy , Mark Cave-Ayland , qemu-ppc@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Alexey Kardashevskiy Since "spapr: Render full FDT on ibm,client-architecture-support" we build the entire flatten device tree (FDT) twice - at the reset time and when "ibm,client-architecture-support" (CAS) is called. The full FDT from CAS is then applied on top of the SLOF internal device tree. This is mostly ok, however there is a case when the QEMU is started with -initrd and for some reason the guest decided to move/unpack the init RAM disk image - the guest correctly notifies SLOF about the change but at CAS it is overridden with the QEMU initial location addresses and the guest may fail to boot if the original initrd memory was changed. This fixes the problem by only adding the /chosen node at the reset time to prevent the original QEMU's linux,initrd-start/linux,initrd-end to override the updated addresses. This only treats /chosen differently as we know there is a special case already and it is unlikely anything else will need to change /chosen at CAS we are better off not touching /chosen after we handed it over to SLOF. Signed-off-by: Alexey Kardashevskiy Message-Id: <20191024041308.5673-1-aik@ozlabs.ru> Signed-off-by: David Gibson Signed-off-by: Laurent Vivier --- hw/ppc/spapr.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 94f9d27096af..e076f6023c73 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -917,7 +917,7 @@ static bool spapr_hotplugged_dev_before_cas(void) return false; } =20 -static void *spapr_build_fdt(SpaprMachineState *spapr); +static void *spapr_build_fdt(SpaprMachineState *spapr, bool reset); =20 int spapr_h_cas_compose_response(SpaprMachineState *spapr, target_ulong addr, target_ulong size, @@ -939,7 +939,7 @@ int spapr_h_cas_compose_response(SpaprMachineState *spa= pr, =20 size -=3D sizeof(hdr); =20 - fdt =3D spapr_build_fdt(spapr); + fdt =3D spapr_build_fdt(spapr, false); _FDT((fdt_pack(fdt))); =20 if (fdt_totalsize(fdt) + sizeof(hdr) > size) { @@ -1197,7 +1197,7 @@ static void spapr_dt_hypervisor(SpaprMachineState *sp= apr, void *fdt) } } =20 -static void *spapr_build_fdt(SpaprMachineState *spapr) +static void *spapr_build_fdt(SpaprMachineState *spapr, bool reset) { MachineState *machine =3D MACHINE(spapr); MachineClass *mc =3D MACHINE_GET_CLASS(machine); @@ -1297,7 +1297,9 @@ static void *spapr_build_fdt(SpaprMachineState *spapr) spapr_dt_rtas(spapr, fdt); =20 /* /chosen */ - spapr_dt_chosen(spapr, fdt); + if (reset) { + spapr_dt_chosen(spapr, fdt); + } =20 /* /hypervisor */ if (kvm_enabled()) { @@ -1305,11 +1307,14 @@ static void *spapr_build_fdt(SpaprMachineState *spa= pr) } =20 /* Build memory reserve map */ - if (spapr->kernel_size) { - _FDT((fdt_add_mem_rsv(fdt, KERNEL_LOAD_ADDR, spapr->kernel_size))); - } - if (spapr->initrd_size) { - _FDT((fdt_add_mem_rsv(fdt, spapr->initrd_base, spapr->initrd_size)= )); + if (reset) { + if (spapr->kernel_size) { + _FDT((fdt_add_mem_rsv(fdt, KERNEL_LOAD_ADDR, spapr->kernel_siz= e))); + } + if (spapr->initrd_size) { + _FDT((fdt_add_mem_rsv(fdt, spapr->initrd_base, + spapr->initrd_size))); + } } =20 /* ibm,client-architecture-support updates */ @@ -1718,7 +1723,7 @@ static void spapr_machine_reset(MachineState *machine) */ fdt_addr =3D MIN(spapr->rma_size, RTAS_MAX_ADDR) - FDT_MAX_SIZE; =20 - fdt =3D spapr_build_fdt(spapr); + fdt =3D spapr_build_fdt(spapr, true); =20 rc =3D fdt_pack(fdt); =20 --=20 2.23.0 From nobody Sun May 5 04:30:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1574075138; cv=none; d=zoho.com; s=zohoarc; b=KiC3aBjxUEH1GjAIqypBZGKvBY9dSFy123E2fmo7G20atzmkt67AxmTFCDOabvuYtA8X/hCDp2KpcAH9d22wxzhAWCcsTN+v6uKQckg62cS5oayfdKtTp0UKMzZDN2yHJ78aEd0MuPq0bOoZw2DmV5ALlGTp0scn/oNrfEf+15U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574075138; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=scq1ubOSxmLdVogCgvwQOfRvMjTF09H8qOIZIA2ZHLw=; b=cIwAX2hBUcYA56DmP1j74OEFaUAc9G4TAvpVOaYZfupz+GW99YOTi0Ce5ZiaZvpwjuJ6xk+4p/uHjwbw63kqCXFPm1ynabjN5884A7s2JLgReXUc2yCDH8XZQ00j10WEpqnhq50omZZfFDNqqAUnKcb8vlD7ZKJNxyr2hEOJfEM= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1574075138288446.5076447462899; Mon, 18 Nov 2019 03:05:38 -0800 (PST) Received: from localhost ([::1]:60620 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iWeqe-0005LK-Iw for importer@patchew.org; Mon, 18 Nov 2019 06:05:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42452) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iWefA-0001h8-25 for qemu-devel@nongnu.org; Mon, 18 Nov 2019 05:53:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iWef8-0004TS-Oq for qemu-devel@nongnu.org; Mon, 18 Nov 2019 05:53:43 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:23035) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iWef8-0004TO-KO for qemu-devel@nongnu.org; Mon, 18 Nov 2019 05:53:42 -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-13-1p5fjQpvNnmgyL1THb3trA-1; Mon, 18 Nov 2019 05:53:40 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9DDAE1883521; Mon, 18 Nov 2019 10:53:38 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-117-32.ams2.redhat.com [10.36.117.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id A9B896918E; Mon, 18 Nov 2019 10:53:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574074422; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=scq1ubOSxmLdVogCgvwQOfRvMjTF09H8qOIZIA2ZHLw=; b=fEPBejhiX5r26lF3fvOf81dPwFiF2nw6NQ+oo2KNHUYyvOj4th8OvYwpEILRRTKAwZgcvi M7GMdC2kq8Pwd64M4hBJ77geVtHMQ3BYRckbo2M23FwzCW/crUzFj8BkdmGw1o33UqoSdb H5LAgiAy9lw9lW1DsRk3rZDH1oVGiv4= From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v2 5/6] spapr/kvm: Set default cpu model for all machine classes Date: Mon, 18 Nov 2019 11:53:18 +0100 Message-Id: <20191118105319.7658-6-lvivier@redhat.com> In-Reply-To: <20191118105319.7658-1-lvivier@redhat.com> References: <20191118105319.7658-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: 1p5fjQpvNnmgyL1THb3trA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 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: Laurent Vivier , David Hildenbrand , Mark Cave-Ayland , Greg Kurz , qemu-ppc@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Igor Mammedov , =?UTF-8?q?Ji=C5=99i=20Denemark?= , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: David Gibson We have to set the default model of all machine classes, not just for the active one. Otherwise, "query-machines" will indicate the wrong CPU model (e.g. "power9_v2.0-powerpc64-cpu" instead of "host-powerpc64-cpu") as "default-cpu-type". s390x already fixed this in de60a92e "s390x/kvm: Set default cpu model for all machine classes". This patch applies a similar fix for the pseries-* machine types on ppc64. Doing a {"execute":"query-machines"} under KVM now results in { "hotpluggable-cpus": true, "name": "pseries-4.2", "numa-mem-supported": true, "default-cpu-type": "host-powerpc64-cpu", "is-default": true, "cpu-max": 1024, "deprecated": false, "alias": "pseries" }, { "hotpluggable-cpus": true, "name": "pseries-4.1", "numa-mem-supported": true, "default-cpu-type": "host-powerpc64-cpu", "cpu-max": 1024, "deprecated": false }, ... Libvirt probes all machines via "-machine none,accel=3Dkvm:tcg" and will currently see the wrong CPU model under KVM. Reported-by: Ji=C5=99i Denemark Cc: David Hildenbrand Cc: Igor Mammedov Signed-off-by: David Gibson Reviewed-by: David Hildenbrand Reviewed-by: Greg Kurz Tested-by: Jiri Denemark Signed-off-by: Laurent Vivier --- target/ppc/kvm.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 7d2e8969ac5f..c77f9848ec38 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -100,7 +100,7 @@ static bool kvmppc_is_pr(KVMState *ks) return kvm_vm_check_extension(ks, KVM_CAP_PPC_GET_PVINFO) !=3D 0; } =20 -static int kvm_ppc_register_host_cpu_type(MachineState *ms); +static int kvm_ppc_register_host_cpu_type(void); static void kvmppc_get_cpu_characteristics(KVMState *s); static int kvmppc_get_dec_bits(void); =20 @@ -147,7 +147,7 @@ int kvm_arch_init(MachineState *ms, KVMState *s) exit(1); } =20 - kvm_ppc_register_host_cpu_type(ms); + kvm_ppc_register_host_cpu_type(); =20 return 0; } @@ -2534,13 +2534,19 @@ PowerPCCPUClass *kvm_ppc_get_host_cpu_class(void) return pvr_pcc; } =20 -static int kvm_ppc_register_host_cpu_type(MachineState *ms) +static void pseries_machine_class_fixup(ObjectClass *oc, void *opaque) +{ + MachineClass *mc =3D MACHINE_CLASS(oc); + + mc->default_cpu_type =3D TYPE_HOST_POWERPC_CPU; +} + +static int kvm_ppc_register_host_cpu_type(void) { TypeInfo type_info =3D { .name =3D TYPE_HOST_POWERPC_CPU, .class_init =3D kvmppc_host_cpu_class_init, }; - MachineClass *mc =3D MACHINE_GET_CLASS(ms); PowerPCCPUClass *pvr_pcc; ObjectClass *oc; DeviceClass *dc; @@ -2552,10 +2558,9 @@ static int kvm_ppc_register_host_cpu_type(MachineSta= te *ms) } type_info.parent =3D object_class_get_name(OBJECT_CLASS(pvr_pcc)); type_register(&type_info); - if (object_dynamic_cast(OBJECT(ms), TYPE_SPAPR_MACHINE)) { - /* override TCG default cpu type with 'host' cpu model */ - mc->default_cpu_type =3D TYPE_HOST_POWERPC_CPU; - } + /* override TCG default cpu type with 'host' cpu model */ + object_class_foreach(pseries_machine_class_fixup, TYPE_SPAPR_MACHINE, + false, NULL); =20 oc =3D object_class_by_name(type_info.name); g_assert(oc); --=20 2.23.0 From nobody Sun May 5 04:30:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1574074706; cv=none; d=zoho.com; s=zohoarc; b=DW445YFBr4FtWqK8JoP7aSgXmmkMKEWOFBeKRdi9QFJgnt1A63rjTKIcdO1zY9zjARA/vsmrXlprItFGmzBLakV63GmZA3ZqTnZqQS5EZNR2yzqpVFA/G5zxhdb+kxdh/XfAOdwBNMnMnvBDvD7iKSNjh1VlkX0YrLj8XFF197A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574074706; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=3MZMBksKQ4RUbBl1WGfm1llnPtwEZ4SD2P8rjb9Hpew=; b=Q/W/ldbvxYBmNvsKXzStoogD0XWcPs+PFbPuFuq9piOZ6Q/Lr/nbcVIEEEv/IJ6c+WSI9+k6Whc9Q2b3bxvUveoglhn3hib87qDEELCbqDSvPczMVm/38exLG1HncflBccF/iiwwfJKSSsLe81ZPLDG3wsHgFf/5Xy7YNhCluUk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1574074706753799.7756444801383; Mon, 18 Nov 2019 02:58:26 -0800 (PST) Received: from localhost ([::1]:60518 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iWejh-0006mG-Dr for importer@patchew.org; Mon, 18 Nov 2019 05:58:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42544) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iWefF-0001ph-QX for qemu-devel@nongnu.org; Mon, 18 Nov 2019 05:53:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iWefD-0004VS-A9 for qemu-devel@nongnu.org; Mon, 18 Nov 2019 05:53:49 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:20320 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iWefD-0004VH-5b for qemu-devel@nongnu.org; Mon, 18 Nov 2019 05:53:47 -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-103-gWIJ_IueOuWNhFowkG2JGA-1; Mon, 18 Nov 2019 05:53:42 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C59BB477; Mon, 18 Nov 2019 10:53:40 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-117-32.ams2.redhat.com [10.36.117.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id F35AE60856; Mon, 18 Nov 2019 10:53:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1574074426; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3MZMBksKQ4RUbBl1WGfm1llnPtwEZ4SD2P8rjb9Hpew=; b=MAvypaDcaG8RGv9RNnWpjpEMjoEXa/seOWQdO4KeZThlNY7AJpcxlkxF9T2uZ/zu57M3Mt A4WEXjHI6XwKbyaR8jcL5ooFLBqe2PQj9ioismFMMUzg3fK63vaGYZU3NgFMBYgiolEQag BCMW6eDjnSmE1Uk2fY+pxsbN/s0pFPM= From: Laurent Vivier To: qemu-devel@nongnu.org Subject: [PULL v2 6/6] mos6522: fix T1 and T2 timers Date: Mon, 18 Nov 2019 11:53:19 +0100 Message-Id: <20191118105319.7658-7-lvivier@redhat.com> In-Reply-To: <20191118105319.7658-1-lvivier@redhat.com> References: <20191118105319.7658-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: gWIJ_IueOuWNhFowkG2JGA-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 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: Laurent Vivier , Mark Cave-Ayland , Laurent Vivier , qemu-ppc@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" From: Laurent Vivier With the Quadra 800 emulation, mos6522 timers processing can consume until 70% of the host CPU time with an idle guest (I guess the problem should also happen with PowerMac emulation). On a recent system, it can be painless (except if you look at top), but on an old host like a PowerMac G5 the guest kernel can be terribly slow during the boot sequence (for instance, unpacking initramfs can take 15 seconds rather than only 3 seconds). We can avoid this CPU overload by enabling QEMU internal timers only if the mos6522 counter interrupts are enabled. Sometime the guest kernel wants to read the counters values, but we don't need the timers to update the counters. With this patch applied, an idle Q800 consumes only 3% of host CPU time (and the guest can boot in a decent time). Signed-off-by: Laurent Vivier Message-Id: <20191102154919.17775-1-laurent@vivier.eu> Signed-off-by: David Gibson Signed-off-by: Laurent Vivier --- hw/misc/mos6522.c | 67 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/hw/misc/mos6522.c b/hw/misc/mos6522.c index 57f13db266b4..aa3bfe1afddd 100644 --- a/hw/misc/mos6522.c +++ b/hw/misc/mos6522.c @@ -38,8 +38,10 @@ =20 /* XXX: implement all timer modes */ =20 -static void mos6522_timer_update(MOS6522State *s, MOS6522Timer *ti, - int64_t current_time); +static void mos6522_timer1_update(MOS6522State *s, MOS6522Timer *ti, + int64_t current_time); +static void mos6522_timer2_update(MOS6522State *s, MOS6522Timer *ti, + int64_t current_time); =20 static void mos6522_update_irq(MOS6522State *s) { @@ -98,7 +100,11 @@ static void set_counter(MOS6522State *s, MOS6522Timer *= ti, unsigned int val) trace_mos6522_set_counter(1 + ti->index, val); ti->load_time =3D get_load_time(s, ti); ti->counter_value =3D val; - mos6522_timer_update(s, ti, ti->load_time); + if (ti->index =3D=3D 0) { + mos6522_timer1_update(s, ti, ti->load_time); + } else { + mos6522_timer2_update(s, ti, ti->load_time); + } } =20 static int64_t get_next_irq_time(MOS6522State *s, MOS6522Timer *ti, @@ -130,19 +136,34 @@ static int64_t get_next_irq_time(MOS6522State *s, MOS= 6522Timer *ti, trace_mos6522_get_next_irq_time(ti->latch, d, next_time - d); next_time =3D muldiv64(next_time, NANOSECONDS_PER_SECOND, ti->frequenc= y) + ti->load_time; + if (next_time <=3D current_time) { next_time =3D current_time + 1; } return next_time; } =20 -static void mos6522_timer_update(MOS6522State *s, MOS6522Timer *ti, +static void mos6522_timer1_update(MOS6522State *s, MOS6522Timer *ti, + int64_t current_time) +{ + if (!ti->timer) { + return; + } + if ((s->ier & T1_INT) =3D=3D 0 || (s->acr & T1MODE) !=3D T1MODE_CONT) { + timer_del(ti->timer); + } else { + ti->next_irq_time =3D get_next_irq_time(s, ti, current_time); + timer_mod(ti->timer, ti->next_irq_time); + } +} + +static void mos6522_timer2_update(MOS6522State *s, MOS6522Timer *ti, int64_t current_time) { if (!ti->timer) { return; } - if (ti->index =3D=3D 0 && (s->acr & T1MODE) !=3D T1MODE_CONT) { + if ((s->ier & T2_INT) =3D=3D 0) { timer_del(ti->timer); } else { ti->next_irq_time =3D get_next_irq_time(s, ti, current_time); @@ -155,7 +176,7 @@ static void mos6522_timer1(void *opaque) MOS6522State *s =3D opaque; MOS6522Timer *ti =3D &s->timers[0]; =20 - mos6522_timer_update(s, ti, ti->next_irq_time); + mos6522_timer1_update(s, ti, ti->next_irq_time); s->ifr |=3D T1_INT; mos6522_update_irq(s); } @@ -165,7 +186,7 @@ static void mos6522_timer2(void *opaque) MOS6522State *s =3D opaque; MOS6522Timer *ti =3D &s->timers[1]; =20 - mos6522_timer_update(s, ti, ti->next_irq_time); + mos6522_timer2_update(s, ti, ti->next_irq_time); s->ifr |=3D T2_INT; mos6522_update_irq(s); } @@ -204,7 +225,16 @@ uint64_t mos6522_read(void *opaque, hwaddr addr, unsig= ned size) { MOS6522State *s =3D opaque; uint32_t val; + int64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); =20 + if (now >=3D s->timers[0].next_irq_time) { + mos6522_timer1_update(s, &s->timers[0], now); + s->ifr |=3D T1_INT; + } + if (now >=3D s->timers[1].next_irq_time) { + mos6522_timer2_update(s, &s->timers[1], now); + s->ifr |=3D T2_INT; + } switch (addr) { case VIA_REG_B: val =3D s->b; @@ -299,8 +329,8 @@ void mos6522_write(void *opaque, hwaddr addr, uint64_t = val, unsigned size) break; case VIA_REG_T1CL: s->timers[0].latch =3D (s->timers[0].latch & 0xff00) | val; - mos6522_timer_update(s, &s->timers[0], - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); + mos6522_timer1_update(s, &s->timers[0], + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); break; case VIA_REG_T1CH: s->timers[0].latch =3D (s->timers[0].latch & 0xff) | (val << 8); @@ -309,14 +339,14 @@ void mos6522_write(void *opaque, hwaddr addr, uint64_= t val, unsigned size) break; case VIA_REG_T1LL: s->timers[0].latch =3D (s->timers[0].latch & 0xff00) | val; - mos6522_timer_update(s, &s->timers[0], - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); + mos6522_timer1_update(s, &s->timers[0], + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); break; case VIA_REG_T1LH: s->timers[0].latch =3D (s->timers[0].latch & 0xff) | (val << 8); s->ifr &=3D ~T1_INT; - mos6522_timer_update(s, &s->timers[0], - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); + mos6522_timer1_update(s, &s->timers[0], + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); break; case VIA_REG_T2CL: s->timers[1].latch =3D (s->timers[1].latch & 0xff00) | val; @@ -334,8 +364,8 @@ void mos6522_write(void *opaque, hwaddr addr, uint64_t = val, unsigned size) break; case VIA_REG_ACR: s->acr =3D val; - mos6522_timer_update(s, &s->timers[0], - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); + mos6522_timer1_update(s, &s->timers[0], + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); break; case VIA_REG_PCR: s->pcr =3D val; @@ -354,6 +384,11 @@ void mos6522_write(void *opaque, hwaddr addr, uint64_t= val, unsigned size) s->ier &=3D ~val; } mos6522_update_irq(s); + /* if IER is modified starts needed timers */ + mos6522_timer1_update(s, &s->timers[0], + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); + mos6522_timer2_update(s, &s->timers[1], + qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); break; default: case VIA_REG_ANH: @@ -426,9 +461,11 @@ static void mos6522_reset(DeviceState *dev) s->timers[0].frequency =3D s->frequency; s->timers[0].latch =3D 0xffff; set_counter(s, &s->timers[0], 0xffff); + timer_del(s->timers[0].timer); =20 s->timers[1].frequency =3D s->frequency; s->timers[1].latch =3D 0xffff; + timer_del(s->timers[1].timer); } =20 static void mos6522_init(Object *obj) --=20 2.23.0