From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468525; cv=none; d=zohomail.com; s=zohoarc; b=K6WAYF2n7Dtvz8mPO2Mv/QXasha+ELzQcM1GTOUyjpFNdEmxvmOMrbD5vSOlTogqOYeOpqRLIzTaQ1U5qlnIG9Gpo70uZ2b62hZke+b+tXkqN/fpOTe9DAAqq2lTD5rZoRgMlP7a2GtSt5l3wNWN+CTPzbzNN3Oo5IXO/qSvrDc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468525; h=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=hT9GJ/9VV0KpWK9H30KM7vb3aR/pgNelxHTyGEtKvI0=; b=a89A4zqepNilFvDT49VgeNTQe7yIttbt3stWuFQ2TsKtT189QtGwebSxl5pGpXBE1FVyx3i0suBiJkJGM3+W+mHx3NANDwtI3rrweHQIyBHhHLXxpqqeS+lFTTXsFENdkVEifIRUkWr9dtdB9W8/LIM1Mt3e9lVHWpm3451sSbs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691468525977340.98867448382975; Mon, 7 Aug 2023 21:22:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTECh-0006CT-2w; Tue, 08 Aug 2023 00:20:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTECf-0006C5-6y; Tue, 08 Aug 2023 00:20:17 -0400 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTECd-0007Mw-Od; Tue, 08 Aug 2023 00:20:16 -0400 Received: by mail-oi1-x231.google.com with SMTP id 5614622812f47-3a37909a64eso3643776b6e.1; Mon, 07 Aug 2023 21:20:15 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.20.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468414; x=1692073214; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=hT9GJ/9VV0KpWK9H30KM7vb3aR/pgNelxHTyGEtKvI0=; b=AqG+PFqH1HL0zDCM4A2pfG52bzVZB5M+acXC3R108ErFGS11MJj3PK/UT81g33OaQO qglWQ70ZChzArkY6pOe/rIl6ttfTNrmVACEG04ozQh2yTLShqmtkTkL2G7s4E2S7A8JN hTf+FuOE1g1IV12HTc/4uzZ2QuTqNPw6GRL/M1bEstE3GQPTD/sWfbr7+8/VTS7zNEoB PXg+55MBFXYDoYjFVJ4u2P8ylpEQrLfkO6DfS5dE3Nk5UhLZpFbSv93V4LVM60TDEjkB IObKo3BABBQStq1V7FSsqZ7Qqga/Omie3epoqlTUPXKjJ+9/Flwy6vIl/B33CpeZaFdP QpDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468414; x=1692073214; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hT9GJ/9VV0KpWK9H30KM7vb3aR/pgNelxHTyGEtKvI0=; b=HPe9wWl+PuDkst3cRCKbb8y4UJb5k7kZXaM9vtoiE8hbrQS3g9Gl2O1DUHERnz+lVo 8fLeCVVwalcE8pBd//RT0Ei5ewZMFTfS6CXuMUoynz9ilIoRobBNYWDknT5LmY2NLHTr IIRLA7TIQbPt+0Duhhki2uw4eG88TI+f842eW2BQ4+UQP1qre1TSOpwenLcFcMIhzV23 QYLjc/hi7J0Pd6bddCktUHhaNeKAf1sBAxxF5qfUq6hBzQ0WZPKW6kBuiE8SoYv6RBPX ZoG1ZbU1pc/A5f7D0XXFA8QrnNRRNYTlARCaWWBXzRddwtVWrEO2NojEeBYJbaEn+n6z WgZQ== X-Gm-Message-State: AOJu0YwsAWFesrWDwBi5a98CFHUQd+g9frWi/joGAiILA23P+iem3Eab LY45lbIi0jFSyhOVzIXj4Bc= X-Google-Smtp-Source: AGHT+IHLokgpulhYYVTWISKthhPb91H750vIfMp/6+BSRYp5YnmEbwOgx2OH0wHaoDQ5yLxLaRQc4w== X-Received: by 2002:a05:6808:213:b0:3a7:56a1:9bbe with SMTP id l19-20020a056808021300b003a756a19bbemr11013329oie.45.1691468414320; Mon, 07 Aug 2023 21:20:14 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 01/19] ppc/vhyp: reset exception state when handling vhyp hcall Date: Tue, 8 Aug 2023 14:19:43 +1000 Message-Id: <20230808042001.411094-2-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::231; envelope-from=npiggin@gmail.com; helo=mail-oi1-x231.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468526481100001 Content-Type: text/plain; charset="utf-8" Convention is to reset the exception_index and error_code after handling an interrupt. The vhyp hcall handler fails to do this. This does not appear to have ill effects because cpu_handle_exception() clears exception_index later, but it is fragile and inconsistent. Reset the exception state after handling vhyp hcall like other handlers. Signed-off-by: Nicholas Piggin --- target/ppc/excp_helper.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/target/ppc/excp_helper.c b/target/ppc/excp_helper.c index 32e46e56b3..72ec2be92e 100644 --- a/target/ppc/excp_helper.c +++ b/target/ppc/excp_helper.c @@ -843,6 +843,7 @@ static void powerpc_excp_7xx(PowerPCCPU *cpu, int excp) PPCVirtualHypervisorClass *vhc =3D PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp); vhc->hypercall(cpu->vhyp, cpu); + powerpc_reset_excp_state(cpu); return; } =20 @@ -1014,6 +1015,7 @@ static void powerpc_excp_74xx(PowerPCCPU *cpu, int ex= cp) PPCVirtualHypervisorClass *vhc =3D PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp); vhc->hypercall(cpu->vhyp, cpu); + powerpc_reset_excp_state(cpu); return; } =20 @@ -1526,6 +1528,7 @@ static void powerpc_excp_books(PowerPCCPU *cpu, int e= xcp) PPCVirtualHypervisorClass *vhc =3D PPC_VIRTUAL_HYPERVISOR_GET_CLASS(cpu->vhyp); vhc->hypercall(cpu->vhyp, cpu); + powerpc_reset_excp_state(cpu); return; } if (env->insns_flags2 & PPC2_ISA310) { --=20 2.40.1 From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468476; cv=none; d=zohomail.com; s=zohoarc; b=EJ4XifvczpH/XgNnSaBn4osDcmYR5ABx0F1a8vXDZuStEpHV9V/MtD9oBUMbv5gYYS4Z7bA5e3pq/EQsP+fqAFa7ohpOhEp16sUGYojDqsk/hMBB5Dc32rV9N9VpDHwyKzwkemrlERiTn/HUx55bVmbstEaR1PogevN2TotdJv8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468476; h=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=7NkBpMBe9n8g61NkrM9I4iqzckfo5RUNpu9gQwNEYYs=; b=fP19RUe+mNvY0/QUEhtE0E0mOipmpucsixgCGOX4qEdUSzYosxu7UO+RBz4bVbfhSJxsP/yCkfgguPnBbKcnw6idPt8EolF+OgsBf1p2v8PiDylBgm3jv++Q0dwpdfrRDfjYgvQncqr2PAjr5QI1Pvz4iZJ4Q4L6vb29Jfv4QC8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691468476437141.03824713631138; Mon, 7 Aug 2023 21:21:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTECm-0006J0-BC; Tue, 08 Aug 2023 00:20:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTECk-0006Fd-8t; Tue, 08 Aug 2023 00:20:22 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTECi-0007Ol-Qv; Tue, 08 Aug 2023 00:20:21 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-686d8c8fc65so3583747b3a.0; Mon, 07 Aug 2023 21:20:20 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:20:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468419; x=1692073219; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7NkBpMBe9n8g61NkrM9I4iqzckfo5RUNpu9gQwNEYYs=; b=AuKP4fNMZw9PdNYpsMNWfJVw5sP0EH/YDQ0KFIfhJfUyj5QGj3sWCG/cql0ahMpAJZ lYJj+SexriE1hvxBZpwa1ejiDKMsKPWjktGooLb/BTwCHCdSnSvgovtCNMyAKe9R6VZC rTPQNbDnPl0YnVoIQ25YVe0+49NrOWREDVM7EB3D5u4yJk9Gw6wyMnI1xeDcS6bnnhTO G4YHQHbs+tFekYAE7QZnSTinp5fPCyV8pdcHkapIzqUNEDDSZTL5nwK4ZR6fyc2Ohsu2 QhXUnSE/TVp/Mw7bUqZ82EglpALzkP1Nik2VJEaHNeje1seczR1MuZa1gLD4vQzqgyGR Sl0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468419; x=1692073219; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7NkBpMBe9n8g61NkrM9I4iqzckfo5RUNpu9gQwNEYYs=; b=VNpPzyZF9fNkkfFQAxiGivI9d15eXHZYN340XyR2CN3l4ogKVZ/EksRCOYE6iKJFNR dktBfNSrZ2OqRH1v01DzRUFYahmC0GVlPu+6I1o8fy3MekxREJubTb5L6sA7vBQ8Nloc PUt39G4E6bG6nb0Sfud+Oy/FCvfR/rmKceBJW7uuT7eN5osgt9U1gcQt04911+384MTV okmkjc9mha6U+Yz7evPeSrxWt6We+uJuri+RmzxZR4UOoWBIz72613Aflne5bc2sQxoR mZyYz5JcXh3aQ4c7l+DVUdxZHJ5PDK1DsbXeJbLTQyReFWp4WbA7Tmp0A+HB1OE4f1wO +DbA== X-Gm-Message-State: AOJu0Yz8MsOu4oq8IxaC4kDIxfzbbumXrMF01XCi2adoq4GSvbL3JP2c M8d8wv2JdfMTansWDt/BpBQ= X-Google-Smtp-Source: AGHT+IGeCsKU8suknRBw1yuVyzr4F+D0xLM3/kNAKSyBcv94R5PRAzqSSTaWWpB2BPxr8z+Fi/X19A== X-Received: by 2002:a05:6a20:8428:b0:13e:e450:f4c9 with SMTP id c40-20020a056a20842800b0013ee450f4c9mr12577530pzd.44.1691468419140; Mon, 07 Aug 2023 21:20:19 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Alexey Kardashevskiy Subject: [PATCH v2 02/19] ppc/vof: Fix missed fields in VOF cleanup Date: Tue, 8 Aug 2023 14:19:44 +1000 Message-Id: <20230808042001.411094-3-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=npiggin@gmail.com; helo=mail-pf1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468477626100018 Content-Type: text/plain; charset="utf-8" Failing to reset the of_instance_last makes ihandle allocation continue to increase, which causes record-replay replay fail to match the recorded trace. Not resetting claimed_base makes VOF eventually run out of memory after some resets. Cc: Alexey Kardashevskiy Fixes: fc8c745d501 ("spapr: Implement Open Firmware client interface") Signed-off-by: Nicholas Piggin Reviewed-by: Alexey Kardashevskiy --- hw/ppc/vof.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/ppc/vof.c b/hw/ppc/vof.c index 18c3f92317..e3b430a81f 100644 --- a/hw/ppc/vof.c +++ b/hw/ppc/vof.c @@ -1024,6 +1024,8 @@ void vof_cleanup(Vof *vof) } vof->claimed =3D NULL; vof->of_instances =3D NULL; + vof->of_instance_last =3D 0; + vof->claimed_base =3D 0; } =20 void vof_build_dt(void *fdt, Vof *vof) --=20 2.40.1 From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468489; cv=none; d=zohomail.com; s=zohoarc; b=nSkedaeVjMPTkVxiix1cjkN/fSpZGLTS0L1hmRuNFSeUMEky9KnL+dbvWf6qn9qV7U4t0ZZoTkzxLseXp6YvSvH7W9ni6IlVqNvr9LqBORaJtLwQ3dpdySSBqCDvNPX5YykjHTdk3irn8us+Q5kpxGOIyTHsQXgFPndSUH30zgE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468489; h=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=GMSPw1YJzvyEAaF+rCTAxiMhu0TUhZrG1Yi0ZviLL+w=; b=QQZzogFCWOsIcMTsWSjlKRcAkzMOX0t5hlVPpHjXcxh9gyNpX5t054Rrc0msk1zZFXfp6x0at1ITCJLUsFfmTnad1QEX1YnaViaH7ioqX7UmTMitzskbJDCqismhDH+L5gWhuCSmgrq+yDL2pKz7MkbRoOSlX582gR+r4Pp0pkE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691468489804950.6575138740853; Mon, 7 Aug 2023 21:21:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTECs-0006TA-8f; Tue, 08 Aug 2023 00:20:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTECp-0006LQ-B4; Tue, 08 Aug 2023 00:20:27 -0400 Received: from mail-oi1-x234.google.com ([2607:f8b0:4864:20::234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTECn-0007ck-LY; Tue, 08 Aug 2023 00:20:27 -0400 Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3a37909a64eso3643823b6e.1; Mon, 07 Aug 2023 21:20:24 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:20:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468424; x=1692073224; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GMSPw1YJzvyEAaF+rCTAxiMhu0TUhZrG1Yi0ZviLL+w=; b=bwvMhkoYYB+xWB4twPpgGGAff2eP3cAP7bB8zhWv26M7BHmBmwtkXCFy+VEXkzpdDq ttRatqxhnT29I/DFCz9SLi09//AsQVT0de8/wAuJlgTC4LAFQ0vcL0C6ysnuMGnpixcR xd4c8BBe8zg2UWanw7rWD+htAoITclSol40PKwk7LwzeFLpI2I7f5mI2V2Qhx4+WK9Ta kwx87jGE/fYEl2PcRzxw9QTmwRX1CBHZi7PmSADpi3iJ9PaBYVVvMxdsQH+pSQM4CAAd bmnGZFxVMwFHVXCbU7KPaT9EWc4ufd67gFdL9QdEqp+OGAbH/gzRx6zghXENl7wxjB5x CzSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468424; x=1692073224; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GMSPw1YJzvyEAaF+rCTAxiMhu0TUhZrG1Yi0ZviLL+w=; b=XOocV5teynB74X7qisnDSVFrZFxMmYq+tQCUpMIURoOfU67kM7yUM/L3ttCtfdzL3V nTYbkOvXf6b9jNjKVTG0/ONfrWSM3p5lhBrtpFEe9Adxrdit/JHUpJ4ZcVdwt/1hbuyt laP+4hLv+6MUZReOhSiMogm8imuHUaIep0M8XBwSgPyGY9NAx4lEnsNjF0uJkucdrnyH ez3QqRDvzHmq5XparJ6i1ZLFB5eN5FimVBiN0WYFiCcmWmrYnHemZT/pyRwGJ1u3zMTx va+IdwExDfZJckA3iOFCk50Lz4bqKG6yd/QLb/KXzYSQY8/tg736wtbeqc0Z3/CrMo/V Zzhg== X-Gm-Message-State: AOJu0YxUN7QBMKtT4S++UYFW3i2ALN9CM4AEyxtvIxkTt08o05mZ7GG5 DCt2GlZQR/a9/y9+VV7DH58= X-Google-Smtp-Source: AGHT+IH24Iv1u29suC0RjAdzpxIBr8U8FJdOK5z5gmnC3Qxyd7H6pGf9xs9+G3JtH8liSa49TuUY0g== X-Received: by 2002:a05:6808:3090:b0:3a7:3100:f8b9 with SMTP id bl16-20020a056808309000b003a73100f8b9mr13914274oib.31.1691468423940; Mon, 07 Aug 2023 21:20:23 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 03/19] hw/ppc/ppc.c: Tidy over-long lines Date: Tue, 8 Aug 2023 14:19:45 +1000 Message-Id: <20230808042001.411094-4-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::234; envelope-from=npiggin@gmail.com; helo=mail-oi1-x234.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468491262100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Nicholas Piggin --- hw/ppc/ppc.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index 0e0a3d93c3..09b82f68a8 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -497,7 +497,8 @@ uint64_t cpu_ppc_load_tbl (CPUPPCState *env) return env->spr[SPR_TBL]; } =20 - tb =3D cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), t= b_env->tb_offset); + tb =3D cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), + tb_env->tb_offset); trace_ppc_tb_load(tb); =20 return tb; @@ -508,7 +509,8 @@ static inline uint32_t _cpu_ppc_load_tbu(CPUPPCState *e= nv) ppc_tb_t *tb_env =3D env->tb_env; uint64_t tb; =20 - tb =3D cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), t= b_env->tb_offset); + tb =3D cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), + tb_env->tb_offset); trace_ppc_tb_load(tb); =20 return tb >> 32; @@ -565,7 +567,8 @@ uint64_t cpu_ppc_load_atbl (CPUPPCState *env) ppc_tb_t *tb_env =3D env->tb_env; uint64_t tb; =20 - tb =3D cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), t= b_env->atb_offset); + tb =3D cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), + tb_env->atb_offset); trace_ppc_tb_load(tb); =20 return tb; @@ -576,7 +579,8 @@ uint32_t cpu_ppc_load_atbu (CPUPPCState *env) ppc_tb_t *tb_env =3D env->tb_env; uint64_t tb; =20 - tb =3D cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), t= b_env->atb_offset); + tb =3D cpu_ppc_get_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), + tb_env->atb_offset); trace_ppc_tb_load(tb); =20 return tb >> 32; @@ -1040,10 +1044,11 @@ clk_setup_cb cpu_ppc_tb_init (CPUPPCState *env, uin= t32_t freq) tb_env->flags |=3D PPC_DECR_UNDERFLOW_LEVEL; } /* Create new timer */ - tb_env->decr_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, &cpu_ppc_decr_= cb, cpu); + tb_env->decr_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, + &cpu_ppc_decr_cb, cpu); if (env->has_hv_mode && !cpu->vhyp) { - tb_env->hdecr_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, &cpu_ppc_= hdecr_cb, - cpu); + tb_env->hdecr_timer =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, + &cpu_ppc_hdecr_cb, cpu); } else { tb_env->hdecr_timer =3D NULL; } --=20 2.40.1 From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468475; cv=none; d=zohomail.com; s=zohoarc; b=SG1XTA0e/hYEWk17KDs1AwZrRu+OrDEfUIEJR2J6SlIXXrP4AdBt5Y2MdnWGA0R80pfPY7+Bt0bl1ZOLLcTkjGfguXtiof4n1GSKqkeQXyXr23seEaxl8+mWmtEDo/E942wWW/dRojB9bLXH5PI4kq86gpaVK98yha3uF0fh7V0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468475; h=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=U9ouVweL8lLdZYVLMOSmjhorKuJ+xhwD5JToKTQsGl0=; b=OK0FT76B0Arx+hsggS93G5zaCw0T4/4jUbHTa9AfEDEWieBl9FkYtvTyrhOo1jR1YdIVxiQoodrDWPsVrUCgmM61DLs7kaw0UH22P2Ij/hKo05koTBHs2HEXuXn+OhTqwT8dVJfDp0fTPYlgWO4HgVQwCQ0ctD34Ws4W604fvzk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691468475976817.6201171981185; Mon, 7 Aug 2023 21:21:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTECw-0006hj-Q1; Tue, 08 Aug 2023 00:20:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTECv-0006ee-2k; Tue, 08 Aug 2023 00:20:33 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTECs-0007fc-Hm; Tue, 08 Aug 2023 00:20:32 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-686f0d66652so4981920b3a.2; Mon, 07 Aug 2023 21:20:29 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:20:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468429; x=1692073229; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=U9ouVweL8lLdZYVLMOSmjhorKuJ+xhwD5JToKTQsGl0=; b=YwRHbU88+Vv8mUeDEVN/4iM8uNC4tB9ELbCY6kX0szPpMHJhVqxXchQ+9caUeiSkKB 9f2nE+6gV1x+zSFD5a/CeYUHwUbroYefju2oxM7Ez0eBvBO4y/NoId0bdfaN32I5iz1y rChVUKubj+PTNWLd2w6O3S+/0OynQmnTZDeqZVj4qaDhRI0U7FqAlqdMtTDt01KtyQhc SUqz57JGp4jBU534zNaEJzbVNbK4lI4foYdCnMl/R9wDhhh9+2xW60pDo9++euVKIou/ VfZwtJqkmv20nQUHbewGPQIRnWe9kOPxv4nBy4ere23Owk+Zxew81INDkIrQYU9F6gmD uj6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468429; x=1692073229; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=U9ouVweL8lLdZYVLMOSmjhorKuJ+xhwD5JToKTQsGl0=; b=Bcf0P3EwSe+4ke8+iDlGCm2eO78Blz1Hmfy8K3Ajvxd6dsCbJS+IlNNARHRKeUZhoe P+hNRPts+2p7n7Pj3lnaG/p6cGXg+mHOmdc9fL5bxOPCEww2p4Ukxh3vYXvsBueLfEg6 y/SqyiYGzMcVrIHn87PuOFtKq+pUPQTdD9QxpHW5MLsXvmt3xwtseMyuqMQ1Hp384vn9 RMt05LL8CoKjdRGZUxHNCGP4S9FkCGVx47aoWCl5fDtdEj9cGYSqfeuHLB111pL7bRIK ybxtOH5iT+tcbkE7OeZ8SgnT3RajnPtoWJtG5B1jSdqwgyTKEzxsC6F8foOrhFEJduRz Kz4g== X-Gm-Message-State: AOJu0Ywa6huZgGJKM+ZBkJSAzGccnyH5oc6Q71OyNUiZq4MV7tM9l9xi EQXmaS3RypcvdZF0xlE1eS0= X-Google-Smtp-Source: AGHT+IE3oOcNvkacK4pTZIlP9sUV2SLjKR8Bm5LcCOu9LTxyBw47E670T7Jfo7H70JQWUrqQQPcrAQ== X-Received: by 2002:a05:6a00:15c9:b0:686:babd:f5c1 with SMTP id o9-20020a056a0015c900b00686babdf5c1mr13856907pfu.25.1691468428895; Mon, 07 Aug 2023 21:20:28 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 04/19] hw/ppc: Introduce functions for conversion between timebase and nanoseconds Date: Tue, 8 Aug 2023 14:19:46 +1000 Message-Id: <20230808042001.411094-5-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=npiggin@gmail.com; helo=mail-pf1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468477186100006 Content-Type: text/plain; charset="utf-8" These calculations are repeated several times, and they will become a little more complicated with subsequent changes. Signed-off-by: Nicholas Piggin --- hw/ppc/ppc.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index 09b82f68a8..423a3a117a 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -482,10 +482,20 @@ void ppce500_set_mpic_proxy(bool enabled) /*************************************************************************= ****/ /* PowerPC time base and decrementer emulation */ =20 +static uint64_t ns_to_tb(uint32_t freq, int64_t clock) +{ + return muldiv64(clock, freq, NANOSECONDS_PER_SECOND); +} + +static int64_t tb_to_ns(uint32_t freq, uint64_t tb) +{ + return muldiv64(tb, NANOSECONDS_PER_SECOND, freq); +} + uint64_t cpu_ppc_get_tb(ppc_tb_t *tb_env, uint64_t vmclk, int64_t tb_offse= t) { /* TB time in tb periods */ - return muldiv64(vmclk, tb_env->tb_freq, NANOSECONDS_PER_SECOND) + tb_o= ffset; + return ns_to_tb(tb_env->tb_freq, vmclk) + tb_offset; } =20 uint64_t cpu_ppc_load_tbl (CPUPPCState *env) @@ -528,8 +538,7 @@ uint32_t cpu_ppc_load_tbu (CPUPPCState *env) static inline void cpu_ppc_store_tb(ppc_tb_t *tb_env, uint64_t vmclk, int64_t *tb_offsetp, uint64_t value) { - *tb_offsetp =3D value - - muldiv64(vmclk, tb_env->tb_freq, NANOSECONDS_PER_SECOND); + *tb_offsetp =3D value - ns_to_tb(tb_env->tb_freq, vmclk); =20 trace_ppc_tb_store(value, *tb_offsetp); } @@ -694,11 +703,11 @@ static inline int64_t _cpu_ppc_load_decr(CPUPPCState = *env, uint64_t next) =20 diff =3D next - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); if (diff >=3D 0) { - decr =3D muldiv64(diff, tb_env->decr_freq, NANOSECONDS_PER_SECOND); + decr =3D ns_to_tb(tb_env->decr_freq, diff); } else if (tb_env->flags & PPC_TIMER_BOOKE) { decr =3D 0; } else { - decr =3D -muldiv64(-diff, tb_env->decr_freq, NANOSECONDS_PER_SECON= D); + decr =3D -ns_to_tb(tb_env->decr_freq, -diff); } trace_ppc_decr_load(decr); =20 @@ -838,7 +847,7 @@ static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uint6= 4_t *nextp, =20 /* Calculate the next timer event */ now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - next =3D now + muldiv64(value, NANOSECONDS_PER_SECOND, tb_env->decr_fr= eq); + next =3D now + tb_to_ns(tb_env->decr_freq, value); *nextp =3D next; =20 /* Adjust timer */ @@ -1130,7 +1139,7 @@ static void cpu_4xx_fit_cb (void *opaque) /* Cannot occur, but makes gcc happy */ return; } - next =3D now + muldiv64(next, NANOSECONDS_PER_SECOND, tb_env->tb_freq); + next =3D now + tb_to_ns(tb_env->tb_freq, next); if (next =3D=3D now) next++; timer_mod(ppc40x_timer->fit_timer, next); @@ -1158,8 +1167,7 @@ static void start_stop_pit (CPUPPCState *env, ppc_tb_= t *tb_env, int is_excp) } else { trace_ppc4xx_pit_start(ppc40x_timer->pit_reload); now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - next =3D now + muldiv64(ppc40x_timer->pit_reload, - NANOSECONDS_PER_SECOND, tb_env->decr_freq); + next =3D now + tb_to_ns(tb_env->decr_freq, ppc40x_timer->pit_reloa= d); if (is_excp) next +=3D tb_env->decr_next - now; if (next =3D=3D now) @@ -1218,7 +1226,7 @@ static void cpu_4xx_wdt_cb (void *opaque) /* Cannot occur, but makes gcc happy */ return; } - next =3D now + muldiv64(next, NANOSECONDS_PER_SECOND, tb_env->decr_fre= q); + next =3D now + tb_to_ns(tb_env->decr_freq, next); if (next =3D=3D now) next++; trace_ppc4xx_wdt(env->spr[SPR_40x_TCR], env->spr[SPR_40x_TSR]); --=20 2.40.1 From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468575; cv=none; d=zohomail.com; s=zohoarc; b=WM7vptgkUtsXLa/73YRcMW6MpDVHemHedPn5JzYWUWJxVPD72aKegM2Zo/kEzMrU6J4N073eUzzyJMrELm6/XUmwXqYdwatHT8fxPJYQ+7jFCk/FZFh+rJqcoPfh525gVh+rUCpHQq2e2gu52DxDdiA9taMT9CeeDgOEBIhHwbU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468575; h=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=VCYW5Fbo8ML/tCCBvqIHvoVVLyR1VjX2xindXtEVGn0=; b=X6RTWewybVbGjO+yovdWMJYiATkNPf5I71Afw4MxhQsaBkB/j6JOQ4jdmWIAOT5ub2tezc0YHhCSYERaGUDLr5q+bV96PPR1uDh2jrw+OQrTdwjuDmYeBjr+c/xpfg5qCNcRa0uNxNo63ad7Vq5bruDtOqYd3cyTGPMUJNfPqQY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691468575199764.2647744614337; Mon, 7 Aug 2023 21:22:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTED2-0006kt-Gl; Tue, 08 Aug 2023 00:20:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTED0-0006k6-F4; Tue, 08 Aug 2023 00:20:38 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTECy-0007h2-TB; Tue, 08 Aug 2023 00:20:38 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-686f38692b3so5215126b3a.2; Mon, 07 Aug 2023 21:20:35 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.20.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:20:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468434; x=1692073234; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VCYW5Fbo8ML/tCCBvqIHvoVVLyR1VjX2xindXtEVGn0=; b=pQS7Uhaol4yK6lpKGsrxh0z/cFfH91XrS5oQqUjfLxqIKb7BB9pPyvaVANxwgVG3NT cnGyDla8rNeajIfMMAiJosgi9oHxTkm22vSHrIJ6u3MBvxi+gsCSBrweGJ3uxnUUIHsd TtaTYEfNvdMuX+K4JHoEPBEVQ0YJxG4DJWGsZb9X6e4NzLis8z/1KWNgYNebbiG9hJSn nsqod7KBvHRu2H+xGBQoaXedbnDtiJLBzSXrHm+0T3XRqI6/y7S1ySm6UQ5AVUMfqSje Mn6Fy8zglcI31sFd0gnbqlXvoX1WCn/UcGieQt44X8ylnDWzRiUWz+3tpLnKI6xcfDCI hM1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468434; x=1692073234; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VCYW5Fbo8ML/tCCBvqIHvoVVLyR1VjX2xindXtEVGn0=; b=ga94geyqM/Ir9Sqtqx5RYx9DZl/XtnswYreMTtwaSAsglKSkgbzv39DErZ2FVqJZyr U2m1/OP9bvMweGkeDkOFeukJuUcwG/YfJGr8QOKh8rN0qI61U769aC/7aNMaJK+SzmOP yZNv3rG8LxmtW3qe1XeiI2pcRrVDgr2XuqbxWtGhKoXvXQyehir2d4nRJiZmHUcRVYTk EW2E5B7y3p3zeQIzL/eVGfJSTpyYOQj5BICSsxT3Nzldp43uzravWpgbH9MUwICXNrR1 sZc15Hn66UjewWOGdKVN8104mn1+m+RvQD5LBZfyO3dVQ9JdqXM0gi9CJxF5KDZkezdF M04w== X-Gm-Message-State: AOJu0YwZ3VCXB8ZdUYtZx/LEHN2n/0j1zxrKhOmHqUK+8QIWeVrUCCM3 3Hiw3/zRIpC6AuFrjt9O9cXJAZqVL0M= X-Google-Smtp-Source: AGHT+IHMw/YKVwyF1vcufk4rQmthzA5F27qV8KqBczVBhuXHVzKbk0OQ8yqB7R/VpJ3DdHZgD6x0bg== X-Received: by 2002:aa7:88c2:0:b0:686:2fde:4d6 with SMTP id k2-20020aa788c2000000b006862fde04d6mr14317971pff.6.1691468433947; Mon, 07 Aug 2023 21:20:33 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 05/19] host-utils: Add muldiv64_round_up Date: Tue, 8 Aug 2023 14:19:47 +1000 Message-Id: <20230808042001.411094-6-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=npiggin@gmail.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468575908100003 Content-Type: text/plain; charset="utf-8" This will be used for converting time intervals in different base units to host units, for the purpose of scheduling timers to emulate target timers. Timers typically must not fire before their requested expiry time but may fire some time afterward, so rounding up is the right way to implement these. Signed-off-by: Nicholas Piggin Reviewed-by: Richard Henderson --- include/qemu/host-utils.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/include/qemu/host-utils.h b/include/qemu/host-utils.h index 011618373e..e2a50a567f 100644 --- a/include/qemu/host-utils.h +++ b/include/qemu/host-utils.h @@ -56,6 +56,11 @@ static inline uint64_t muldiv64(uint64_t a, uint32_t b, = uint32_t c) return (__int128_t)a * b / c; } =20 +static inline uint64_t muldiv64_round_up(uint64_t a, uint32_t b, uint32_t = c) +{ + return ((__int128_t)a * b + c - 1) / c; +} + static inline uint64_t divu128(uint64_t *plow, uint64_t *phigh, uint64_t divisor) { @@ -83,7 +88,8 @@ void mulu64(uint64_t *plow, uint64_t *phigh, uint64_t a, = uint64_t b); uint64_t divu128(uint64_t *plow, uint64_t *phigh, uint64_t divisor); int64_t divs128(uint64_t *plow, int64_t *phigh, int64_t divisor); =20 -static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) +static inline uint64_t __muldiv64(uint64_t a, uint32_t b, uint32_t c, + bool round_up) { union { uint64_t ll; @@ -99,12 +105,25 @@ static inline uint64_t muldiv64(uint64_t a, uint32_t b= , uint32_t c) =20 u.ll =3D a; rl =3D (uint64_t)u.l.low * (uint64_t)b; + if (round_up) { + rl +=3D c - 1; + } rh =3D (uint64_t)u.l.high * (uint64_t)b; rh +=3D (rl >> 32); res.l.high =3D rh / c; res.l.low =3D (((rh % c) << 32) + (rl & 0xffffffff)) / c; return res.ll; } + +static inline uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) +{ + return __muldiv64(a, b, c, false); +} + +static inline uint64_t muldiv64_round_up(uint64_t a, uint32_t b, uint32_t = c) +{ + return __muldiv64(a, b, c, true); +} #endif =20 /** --=20 2.40.1 From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468476; cv=none; d=zohomail.com; s=zohoarc; b=gXiSyb0yHRMylq77FA2RDmrwn1oqtCAEIHjihZPjc3k+VsQtV3Re3LqJr3O+AyaFOWarSU19btTbgTFFRK0tNkAm/kNNH3RpxJH9yxo6v7NVxQoJh6EV/fsRx+Hsa17K3Hnect/fjqmUSfQPNZeUqImnAYaF3lyJyX2GlPTxo8k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468476; h=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=1XWtaCCtPGQ8JFN+IlgusaRfj73rKbgISkOsjU+Yu/I=; b=ViVRaqrdBWBxB0DuUh0laVEIgsRJCFKsm1btqd1l7pdBuINh4rqGYV36TT13dzRoUuMdz9j3rOj+Reh/AJokNS29kzIhdx5Z4h/vQwhbzKUvR0LCYhx6k8vRUUSJ4JtN8APFi7TobBYEr+IUGXp510jtDdi9hTOXjq2UIzLtz8s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691468476537225.13702095654776; Mon, 7 Aug 2023 21:21:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTED5-0006lp-N1; Tue, 08 Aug 2023 00:20:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTED4-0006lS-Lx; Tue, 08 Aug 2023 00:20:42 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTED3-0007hr-1R; Tue, 08 Aug 2023 00:20:42 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6874d1c8610so3713466b3a.0; Mon, 07 Aug 2023 21:20:40 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.20.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468438; x=1692073238; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1XWtaCCtPGQ8JFN+IlgusaRfj73rKbgISkOsjU+Yu/I=; b=Ap+DfBVyLGM9d2GrA1yq7ta7tM7WMBYQ33sAluIAXdl2g5xaAnVK6WZ7o17AHC2978 scoP1wLcOIkGonMGk6rwEs/xz3wugh4jw8N21ZFoHkb380hAjzD23ufbn9sNrtn1PMsG JuG3zicHVsd+pbgZokAeOurtoDdei2fyB2sHPdWjm8Q+eRNaJfcKrtt1o5TcnB7cBVQ2 e1o3P7CzSfUCDqlEszhJNAqYrLyVAYt2a8cCcVSjCWySGcKZH3qcA5lwS5nx9dOgquV0 p1/rlCn5oRMCJA4nL4sACTNGCAB5toYzBY/zkveoZRn5OLQgXEtPF2NLpnwJ34zpFeLx PmBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468438; x=1692073238; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1XWtaCCtPGQ8JFN+IlgusaRfj73rKbgISkOsjU+Yu/I=; b=RAcaG+ZfSVghzvQzZwaqj6Qun1aIie95ajPRwfR2h8Q9u0CN2I7rx0uK6cI0AZa5LX DoDCNYPyvCwYIPMi5JXB5SmvGTKDUMgjkhZLqwTd6XnRNM/tuHiXWZxxkSrTEh8TzPr8 Or0Zre1BsLt9VX05b/xQGfs5+8z9VmC6u/QR987sEp8n2lT6e26JRwMZOdpjZdnyHF9J pos8Y/jb2oNw7LE8ixPP9i3FA1AxQ6E1a/6sBTZNVFGQEqKRUChRlr2OJhbamh2yMUS8 7qUTjzsLT+FcMsztS8VhwrXsZ+jV+wz4Lm+fJHMbdCoFcQfHglsiRVz6Q+9//QVWs6WQ jhEA== X-Gm-Message-State: AOJu0YxWlUGi81BcbRta9uFgYyQ/5KlARjIlet+MfW6Hi/K45d79BFKf uxJz1QaW3GoHjcD+pR3GP4U= X-Google-Smtp-Source: AGHT+IEfrSJrQHlssy9wkipkSnoPo7Mv/VJ8Z5nLLd63HCWKRzDitaRfvkzX36BSRWv/zQeHTQo/ig== X-Received: by 2002:a05:6a00:2351:b0:661:4a00:1ea5 with SMTP id j17-20020a056a00235100b006614a001ea5mr10959152pfj.20.1691468438409; Mon, 07 Aug 2023 21:20:38 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 06/19] hw/ppc: Round up the decrementer interval when converting to ns Date: Tue, 8 Aug 2023 14:19:48 +1000 Message-Id: <20230808042001.411094-7-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=npiggin@gmail.com; helo=mail-pf1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468477203100008 Content-Type: text/plain; charset="utf-8" The rule of timers is typically that they should never expire before the timeout, but some time afterward. Rounding timer intervals up when doing conversion is the right thing to do. Under most circumstances it is impossible observe the decrementer interrupt before the dec register has triggered. However with icount timing, problems can arise. For example setting DEC to 0 can schedule the timer for now, causing it to fire before any more instructions have been executed and DEC is still 0. Signed-off-by: Nicholas Piggin --- hw/ppc/ppc.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index 423a3a117a..13eb45f4b7 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -482,14 +482,26 @@ void ppce500_set_mpic_proxy(bool enabled) /*************************************************************************= ****/ /* PowerPC time base and decrementer emulation */ =20 +/* + * Conversion between QEMU_CLOCK_VIRTUAL ns and timebase (TB) ticks: + * TB ticks are arrived at by multiplying tb_freq then dividing by + * ns per second, and rounding down. TB ticks drive all clocks and + * timers in the target machine. + * + * Converting TB intervals to ns for the purpose of setting a + * QEMU_CLOCK_VIRTUAL timer should go the other way, but rounding + * up. Rounding down could cause the timer to fire before the TB + * value has been reached. + */ static uint64_t ns_to_tb(uint32_t freq, int64_t clock) { return muldiv64(clock, freq, NANOSECONDS_PER_SECOND); } =20 -static int64_t tb_to_ns(uint32_t freq, uint64_t tb) +/* virtual clock in TB ticks, not adjusted by TB offset */ +static int64_t tb_to_ns_round_up(uint32_t freq, uint64_t tb) { - return muldiv64(tb, NANOSECONDS_PER_SECOND, freq); + return muldiv64_round_up(tb, NANOSECONDS_PER_SECOND, freq); } =20 uint64_t cpu_ppc_get_tb(ppc_tb_t *tb_env, uint64_t vmclk, int64_t tb_offse= t) @@ -847,7 +859,7 @@ static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uint6= 4_t *nextp, =20 /* Calculate the next timer event */ now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - next =3D now + tb_to_ns(tb_env->decr_freq, value); + next =3D now + tb_to_ns_round_up(tb_env->decr_freq, value); *nextp =3D next; =20 /* Adjust timer */ @@ -1139,9 +1151,7 @@ static void cpu_4xx_fit_cb (void *opaque) /* Cannot occur, but makes gcc happy */ return; } - next =3D now + tb_to_ns(tb_env->tb_freq, next); - if (next =3D=3D now) - next++; + next =3D now + tb_to_ns_round_up(tb_env->tb_freq, next); timer_mod(ppc40x_timer->fit_timer, next); env->spr[SPR_40x_TSR] |=3D 1 << 26; if ((env->spr[SPR_40x_TCR] >> 23) & 0x1) { @@ -1167,11 +1177,10 @@ static void start_stop_pit (CPUPPCState *env, ppc_t= b_t *tb_env, int is_excp) } else { trace_ppc4xx_pit_start(ppc40x_timer->pit_reload); now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - next =3D now + tb_to_ns(tb_env->decr_freq, ppc40x_timer->pit_reloa= d); + next =3D now + tb_to_ns_round_up(tb_env->decr_freq, + ppc40x_timer->pit_reload); if (is_excp) next +=3D tb_env->decr_next - now; - if (next =3D=3D now) - next++; timer_mod(tb_env->decr_timer, next); tb_env->decr_next =3D next; } @@ -1226,9 +1235,7 @@ static void cpu_4xx_wdt_cb (void *opaque) /* Cannot occur, but makes gcc happy */ return; } - next =3D now + tb_to_ns(tb_env->decr_freq, next); - if (next =3D=3D now) - next++; + next =3D now + tb_to_ns_round_up(tb_env->decr_freq, next); trace_ppc4xx_wdt(env->spr[SPR_40x_TCR], env->spr[SPR_40x_TSR]); switch ((env->spr[SPR_40x_TSR] >> 30) & 0x3) { case 0x0: --=20 2.40.1 From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468475; cv=none; d=zohomail.com; s=zohoarc; b=VOOkcAmdUXKy3Sd+ustMQ3IKDKbaOiRLZrSgXIU3MrjNyT4JOfuE2+N2+whCWrofctjf2IAVyR282X/d3k+/yIgdTAs9dbyH//UH8olR9toXl89gB1LwFGUUqkbBzi2wo0xDhwkMUKMTdZNWcm9HNmLhC52KKbCnN3vLuRhqo5Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468475; h=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=w7224617qU4aowjj8pMFVGiu1BetDjMqd9SnzR+pOz8=; b=Mo0W5FwsaTbot201OxCI6nXvkZw80JMZ9D1MsL0SdKxUEGkPbU4LLPNCktoZch1b0aD9FoaW/G8Y9K58V0QmNE2EtFgWtoyyZ+vaaVZd51+hthQtMp2tBz3ndHTDaEnCkjRAA2k5aZF+kX8l5MH4JuR25coSzR04E1D31/tcdh8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16914684759057.410442115882574; Mon, 7 Aug 2023 21:21:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTEDA-0006sG-8v; Tue, 08 Aug 2023 00:20:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTED8-0006oC-C8; Tue, 08 Aug 2023 00:20:46 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTED6-0007ie-ML; Tue, 08 Aug 2023 00:20:46 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-686b9920362so3464496b3a.1; Mon, 07 Aug 2023 21:20:43 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.20.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:20:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468443; x=1692073243; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=w7224617qU4aowjj8pMFVGiu1BetDjMqd9SnzR+pOz8=; b=dMIhJvZErVbCnpo1A6b2OyLR9YijVduT8VivHvftvPzh0ZA1hNmOJ2c4/LmArnhvoH JoLkrRF782Fc4lhkeFdypeqU9JyCA7g0LTSHViUxqGsC9q0hWBsVCjTfPPCNF0+z7xpx rDNqMnubMjvkHoOQnISZww5h9VDDLV8EmUXMaVEEpBVJWRXnq1gRb2vTRsSXO8blE+uA 3mKCuNyFAipe9pSxGrkO/Tnszk+u6kySRlfPukiC993OqERnSTfe9QIU3MWnr7iuVOOV gtV45adqVKhY8v7scOZ/4UzHLotNqLWXWsN3hx9e/9jeel4zJ2FDT2c8Jhdro+5GBylr 2yoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468443; x=1692073243; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w7224617qU4aowjj8pMFVGiu1BetDjMqd9SnzR+pOz8=; b=CADmkMjNpOs2q6IswsNRSqEhB0/Mwv996N+S1CpYtcA0sQ3YiABwxmr5Qz9kTyc753 CSTfhHRNkbyvJKwXeFiDgGdqIi9NUtmtjggHXfF8oU+DqRWsj2YRKdyMKVuyWQw0V1yt OFhmifFUBvC2UMlBefW5RCuj24LmD0MxYvhFnX+1lqC2KrVfG+VyLgUW4Jj7ScewTixA dwGH6naKveButan68gOQRg1z4IeK4ypGGad3eipa3mPGBbKpo3xDfBm+KPGc+lt3y90y KkZGMk1E5O0gJkb64onZu9dw2WC77KgAElEKPVMdXBx8Twb0WnIi/yxmk3HsOOogCkIx Jb6g== X-Gm-Message-State: AOJu0YyCQflhVk14u0anJwna2JBrG2PWR2d1VRetuJXWoozwFTTg4slJ uuYV7BkYTuTna/8mMKvjg04= X-Google-Smtp-Source: AGHT+IHgHFPiZm50v96aW3L69A61gdReu6iE3XJ0WcfIVjcDPTxL/L/Cbi/aOJnODsyXVMddUJMzIg== X-Received: by 2002:a05:6a20:3c8e:b0:134:16a3:83ad with SMTP id b14-20020a056a203c8e00b0013416a383admr10697319pzj.57.1691468443111; Mon, 07 Aug 2023 21:20:43 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 07/19] hw/ppc: Avoid decrementer rounding errors Date: Tue, 8 Aug 2023 14:19:49 +1000 Message-Id: <20230808042001.411094-8-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=npiggin@gmail.com; helo=mail-pf1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468476779100001 Content-Type: text/plain; charset="utf-8" The decrementer register contains a relative time in timebase units. When writing to DECR this is converted and stored as an absolute value in nanosecond units, reading DECR converts back to relative timebase. The tb<->ns conversion of the relative part can cause rounding such that a value writen to the decrementer can read back a different, with time held constant. This is a particular problem for a deterministic icount and record-replay trace. Fix this by storing the absolute value in timebase units rather than nanoseconds. The math before: store: decr_next =3D now_ns + decr * ns_per_sec / tb_per_sec load: decr =3D (decr_next - now_ns) * tb_per_sec / ns_per_sec load(store): decr =3D decr * ns_per_sec / tb_per_sec * tb_per_sec / ns_per_sec After: store: decr_next =3D now_ns * tb_per_sec / ns_per_sec + decr load: decr =3D decr_next - now_ns * tb_per_sec / ns_per_sec load(store): decr =3D decr Fixes: 9fddaa0c0cab ("PowerPC merge: real time TB and decrementer - faster = and simpler exception handling (Jocelyn Mayer)") Signed-off-by: Nicholas Piggin --- hw/ppc/ppc.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index 13eb45f4b7..a397820d9c 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -711,16 +711,17 @@ bool ppc_decr_clear_on_delivery(CPUPPCState *env) static inline int64_t _cpu_ppc_load_decr(CPUPPCState *env, uint64_t next) { ppc_tb_t *tb_env =3D env->tb_env; - int64_t decr, diff; + uint64_t now, n; + int64_t decr; =20 - diff =3D next - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - if (diff >=3D 0) { - decr =3D ns_to_tb(tb_env->decr_freq, diff); - } else if (tb_env->flags & PPC_TIMER_BOOKE) { + now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + n =3D ns_to_tb(tb_env->decr_freq, now); + if (next > n && tb_env->flags & PPC_TIMER_BOOKE) { decr =3D 0; - } else { - decr =3D -ns_to_tb(tb_env->decr_freq, -diff); + } else { + decr =3D next - n; } + trace_ppc_decr_load(decr); =20 return decr; @@ -857,13 +858,18 @@ static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uin= t64_t *nextp, (*lower_excp)(cpu); } =20 - /* Calculate the next timer event */ + /* + * Calculate the next decrementer event and set a timer. + * decr_next is in timebase units to keep rounding simple. Note it is + * not adjusted by tb_offset because if TB changes via tb_offset chang= ing, + * decrementer does not change, so not directly comparable with TB. + */ now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - next =3D now + tb_to_ns_round_up(tb_env->decr_freq, value); + next =3D ns_to_tb(tb_env->decr_freq, now) + value; *nextp =3D next; =20 /* Adjust timer */ - timer_mod(timer, next); + timer_mod(timer, tb_to_ns_round_up(tb_env->decr_freq, next)); } =20 static inline void _cpu_ppc_store_decr(PowerPCCPU *cpu, target_ulong decr, @@ -1177,12 +1183,15 @@ static void start_stop_pit (CPUPPCState *env, ppc_t= b_t *tb_env, int is_excp) } else { trace_ppc4xx_pit_start(ppc40x_timer->pit_reload); now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - next =3D now + tb_to_ns_round_up(tb_env->decr_freq, - ppc40x_timer->pit_reload); - if (is_excp) - next +=3D tb_env->decr_next - now; + + if (is_excp) { + tb_env->decr_next +=3D ppc40x_timer->pit_reload; + } else { + tb_env->decr_next =3D ns_to_tb(tb_env->decr_freq, now) + + ppc40x_timer->pit_reload; + } + next =3D tb_to_ns_round_up(tb_env->decr_freq, tb_env->decr_next); timer_mod(tb_env->decr_timer, next); - tb_env->decr_next =3D next; } } =20 --=20 2.40.1 From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468518; cv=none; d=zohomail.com; s=zohoarc; b=bk0cKM3pLNWuK+dRkIlzqQH1yWYCOwWhWufuIJ5f+L7oxQtzHXpjCUXHbIaqyapzZN6n+TECGmTBpdoY89OkvUbSX0TLtuLvz66SYt94jsL9m9hJOLZ55M6vd0Y9SSrPxvravd9NolZBTS2wIvgmA5Wa72sS4CAcSl9sQQZ7Pdc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468518; h=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=q7dhfUcwpc4jAqyrup5K9pjejMt9A7JsRyG2tDSr+mc=; b=ZTy3j85/YIgoIz6H2ZtfsNG162JmvsNyA4z5DAhQQVKv+SFRKM9wgP7m78q0yN1AG48xgAmWoOfuc+phLUmIMJGlr3/1SFH6A89SjmDZi3uliGP8PZG3qrqtMX+cQ+xKFXm3o2LsyPr2s1KcmCcDf1f7dlzO6E6/HJOej3izvT0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691468518340227.44851819259543; Mon, 7 Aug 2023 21:21:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTEDF-0006w3-29; Tue, 08 Aug 2023 00:20:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTEDD-0006uW-D6; Tue, 08 Aug 2023 00:20:51 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTEDB-0007jJ-Tt; Tue, 08 Aug 2023 00:20:51 -0400 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-686be28e1a8so3638101b3a.0; Mon, 07 Aug 2023 21:20:49 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.20.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:20:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468448; x=1692073248; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=q7dhfUcwpc4jAqyrup5K9pjejMt9A7JsRyG2tDSr+mc=; b=dXTJ942WVDwt2ktLti46QlUaN+plR7QbZjmi+9zkANKkG06vHE7jyrh7+WwDkcpYRu pmynt/e52XQQ1pY4f8I6JphxOOC+mGxrzAQwc9n6V4qt5oNoDWKjz65F4h0yxmIfTUjG xc4x9xBnYLeov1VOf4SLt0P9jKNDo/Mch9jHSRi454Kw+TdnUoWE91Z9OzbtI73GosU8 2RW/njN4zkCgkVidf7pHZKkSoHBwD5YiGsty5/TGUM5XGP5Broi+Dj0ZqtYMcPxhFIGm KG3Go++JwNGRpTRRD5SG+4quCSqPw72k/sIQmZvB9xV5nknVvDSZZDuY9V026oDPo3Ke tWMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468448; x=1692073248; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q7dhfUcwpc4jAqyrup5K9pjejMt9A7JsRyG2tDSr+mc=; b=enOzt0HLwrA2TSCA3a2Lp8xkZkCp/gvXYhA2seQKz3P1teHso0yE517fPgRhhjHfEG I1TMTAy57tO01i/VgzGN3hhKTkoS8JAHYgsmFLpox7V3Q5Ig7ZAECj8tBkQ7CXNQ2wDn N0EC50GQS0Csi6HnqeOo8eIZLmmdDkA0ZMjsppjATsG2qhhw2FWOzpZwC2arjcswuIaz j0wUN5ywU+0lzuVAtFvdxOXC3gK5xon0B/6h4gaW3/aE1fRRvUQ3QJfhU4GFtpJR/Sbl 6TYsDC0PGqjnRyKJz+peiSPIzj4esks7NTDmDdraJp69BKGmLM5V4w06Py6btl+BXRJZ cIqg== X-Gm-Message-State: AOJu0YwudKpuDFO2sy+YFMLyHuIhj4GCbmQSIKn6ICEQlvSs4NJxyPST 3Xfydh+B7S3oCe19BMnm6bUr2mpPLVY= X-Google-Smtp-Source: AGHT+IErzqNXPEStJAUDHZy5a3q0GtY3cdNTEQDOwxLeP/+EW4ODFLh76ciTEMiqMWc8JA8QfuUdxg== X-Received: by 2002:a05:6a00:1306:b0:668:73f5:dce0 with SMTP id j6-20020a056a00130600b0066873f5dce0mr10076311pfu.29.1691468447971; Mon, 07 Aug 2023 21:20:47 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 08/19] target/ppc: Sign-extend large decrementer to 64-bits Date: Tue, 8 Aug 2023 14:19:50 +1000 Message-Id: <20230808042001.411094-9-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=npiggin@gmail.com; helo=mail-pf1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468520474100003 Content-Type: text/plain; charset="utf-8" When storing a large decrementer value with the most significant implemented bit set, it is to be treated as a negative and sign extended. This isn't hit for book3s DEC because of another bug, fixing it in the next patch exposes this one and can cause additional problems, so fix this first. It can be hit with HDECR and other edge triggered types. Fixes: a8dafa52518 ("target/ppc: Implement large decrementer support for TC= G") Signed-off-by: Nicholas Piggin --- hw/ppc/ppc.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index a397820d9c..fb4784793c 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -743,7 +743,9 @@ target_ulong cpu_ppc_load_decr(CPUPPCState *env) * to 64 bits, otherwise it is a 32 bit value. */ if (env->spr[SPR_LPCR] & LPCR_LD) { - return decr; + PowerPCCPU *cpu =3D env_archcpu(env); + PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(cpu); + return sextract64(decr, 0, pcc->lrg_decr_bits); } return (uint32_t) decr; } @@ -762,7 +764,9 @@ target_ulong cpu_ppc_load_hdecr(CPUPPCState *env) * extended to 64 bits, otherwise it is 32 bits. */ if (pcc->lrg_decr_bits > 32) { - return hdecr; + PowerPCCPU *cpu =3D env_archcpu(env); + PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(cpu); + return sextract64(hdecr, 0, pcc->lrg_decr_bits); } return (uint32_t) hdecr; } --=20 2.40.1 From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468476; cv=none; d=zohomail.com; s=zohoarc; b=OLNW345+UZ9dPefsVqH8mTRLW6zd1bpDAJMUSjsUVE2MFJNrxYgh4YfVS3nUomJG8uY2XDXpk1WKoUgsu+p8Gum3PbjKdCep1et2Kp0BPzMAu4z4NZcrY7wlJO5+e4hwYtKjQd4BdarCp86cn6WT56TpP0Ep3alWsyKdV+YwMUA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468476; h=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=EPClgIZ1e7ypLFEW8b3J7zgdfUJQG0EgyV1eca3pY7g=; b=Lf8J96tN1sZch+lei+vzPfugreWwCqXVjbSujBRjCL9Dc9GLmSZjrkrRnDaplhIDpImTA/mdqTRZ3ee17pkN8FHUbxG5ghuia8Lcom8TNe+DSvQB2Mi2KxtbAKQfVINxqSRqBjS7Jj5a8AJkjT8CS69ivprFTqTPDCbzHkcsulM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691468476535861.6432746228372; Mon, 7 Aug 2023 21:21:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTEDJ-0006zm-3m; Tue, 08 Aug 2023 00:20:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTEDH-0006zV-Pg; Tue, 08 Aug 2023 00:20:55 -0400 Received: from mail-oi1-x22d.google.com ([2607:f8b0:4864:20::22d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTEDG-0007k2-7Z; Tue, 08 Aug 2023 00:20:55 -0400 Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-3a37909a64eso3643974b6e.1; Mon, 07 Aug 2023 21:20:53 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.20.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:20:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468453; x=1692073253; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EPClgIZ1e7ypLFEW8b3J7zgdfUJQG0EgyV1eca3pY7g=; b=IBje1fsKw1oDIn/kFbtz5Y+w6KNu5Vz7g2+PrxvTKTmgBoRI6895O0p8XU44Hzw4nZ XQZpNO3K5oWpTYVpfnPXBK0GyJTz4PZ3kCBps65mPoMEl59RMl1YP5k5+tPL02k37UOT uD32B8OMJT2pnOw6/2H2kUtB8RoXpPe7Y4oQXrIwzzAsn9UsznajoA8IqsB/rxMB6mJR QFmlpXPEZ6C6+VI75C7Ay4+sbQdz8uDKR4ZVf1U4W/eDZ/XitYvaxdgmL68/OxwJ7Om0 HGh6fopaCaznZfl9V0FjokSQBR9Y11MJx8TbGkgXw7QPpMHpC3+J5qdr3lmHuQdMuPhx pj7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468453; x=1692073253; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EPClgIZ1e7ypLFEW8b3J7zgdfUJQG0EgyV1eca3pY7g=; b=NkjY9+3jx/mgu3dnz6LTO1wJnEHuuoIu4/e5wjYoMtcGB3+fKfGxO+60Dtn/rePVvq vfsbwzPIHTXjSwh+rYmnjMHQbV3ZxzpXbxLBTpQnvxi0vFxkwDhCSIEfj/SDmHZe3h3H wqSm/4joJyqYqhoDZEDiAzVP3rwbBAV4q2XCD+uqDPTCxR/dtKWVo/mypw3EQ+TNqE3+ A64EKQYmWq2d91XTzwLPaooUuQ1rNU+WRFEjU3hONrT9wcwWcqfYcwKsq1znGbC+G63h OlbCdBCHxnyf+bcG0k+uj5C9sClcr/P6D8XhbetlXIR8yc6BaATvHyS3a98+eczCCtKx 4iuw== X-Gm-Message-State: AOJu0YzEZEQhRNTyOCd+6yzGGZB0WL0EuodcOawRNML6DW0MFpfCcFa6 Zsi/+yMm4eObOGHzvqp0w7U= X-Google-Smtp-Source: AGHT+IE39aaQQsdUqzud7qgIWpboLpXiqn2y4oaQ1caBP+1B1ixX3SaWhgdMBo9TGc+hYJZbjUrUOA== X-Received: by 2002:a05:6808:bd5:b0:3a7:3ce0:1ae5 with SMTP id o21-20020a0568080bd500b003a73ce01ae5mr15162302oik.47.1691468452745; Mon, 07 Aug 2023 21:20:52 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 09/19] hw/ppc: Always store the decrementer value Date: Tue, 8 Aug 2023 14:19:51 +1000 Message-Id: <20230808042001.411094-10-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::22d; envelope-from=npiggin@gmail.com; helo=mail-oi1-x22d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468478161100022 Content-Type: text/plain; charset="utf-8" When writing a value to the decrementer that raises an exception, the irq is raised, but the value is not stored so the store doesn't appear to have changed the register when it is read again. Always store the write value to the register. Fixes: e81a982aa53 ("PPC: Clean up DECR implementation") Signed-off-by: Nicholas Piggin --- hw/ppc/ppc.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index fb4784793c..d9a1cfbf91 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -841,6 +841,16 @@ static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uint= 64_t *nextp, return; } =20 + /* + * Calculate the next decrementer event and set a timer. + * decr_next is in timebase units to keep rounding simple. Note it is + * not adjusted by tb_offset because if TB changes via tb_offset chang= ing, + * decrementer does not change, so not directly comparable with TB. + */ + now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + next =3D ns_to_tb(tb_env->decr_freq, now) + value; + *nextp =3D next; /* nextp is in timebase units */ + /* * Going from 1 -> 0 or 0 -> -1 is the event to generate a DEC interru= pt. * @@ -862,16 +872,6 @@ static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uint= 64_t *nextp, (*lower_excp)(cpu); } =20 - /* - * Calculate the next decrementer event and set a timer. - * decr_next is in timebase units to keep rounding simple. Note it is - * not adjusted by tb_offset because if TB changes via tb_offset chang= ing, - * decrementer does not change, so not directly comparable with TB. - */ - now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - next =3D ns_to_tb(tb_env->decr_freq, now) + value; - *nextp =3D next; - /* Adjust timer */ timer_mod(timer, tb_to_ns_round_up(tb_env->decr_freq, next)); } --=20 2.40.1 From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468531; cv=none; d=zohomail.com; s=zohoarc; b=YE2gAjF2Fs6Cr+gEFl02E3EqzwBCXwMGmpHK7JW/Benh9RF+o7luLkLGfyZN+CBia6bZHnTRTRJHd3IsI61Gwu2jsjAPHry+MvfCIEnLPsvmKN/ZPtIwYSk2586HYmLWUuW7k4Sq78OUb4K7sriCzf38Fc4gie/DrRxrumzLXOM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468531; h=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=IXQlPOmsz3SjSWtdP/kN0DEGncm9HuckmpRysy+KsOg=; b=RdsBuEpq83Y1Gh2UNoAII36R/8z92W0/evG/ORipw+afkullpV3139EdjxJan0MSVAet+IdOuevLka+ttgkyVtfFrxTncQJEVZ6DZSliSzSLXhn9uQJsniDWrRzypug4fE1nFW/swccVyWeB7Cumv5VaoGozphfY3o/5MzDQfuk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691468531336242.9755774228845; Mon, 7 Aug 2023 21:22:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTEDO-00077L-SX; Tue, 08 Aug 2023 00:21:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTEDM-00073U-Fy; Tue, 08 Aug 2023 00:21:00 -0400 Received: from mail-oi1-x22c.google.com ([2607:f8b0:4864:20::22c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTEDK-0007m6-TL; Tue, 08 Aug 2023 00:21:00 -0400 Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-3a6f87b2993so3890699b6e.3; Mon, 07 Aug 2023 21:20:58 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.20.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:20:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468457; x=1692073257; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IXQlPOmsz3SjSWtdP/kN0DEGncm9HuckmpRysy+KsOg=; b=iXon6G0ynGcFtSWGwdyaNAyFNOLiKE1vMtijB0k9CXWGk1wWgtlP3o0brORxAOZNio AtGTQKPbC6WXCMJ4qyPTkdBGUK4lnm7CDYApmv5vVZgAklitGoe8GdzQPchsHRiAhK5I EF1iKw/fLJId1Gg6v2xdxzzP0ptI573kHs+rH2QLYR5ufBCsBveTCaNv+u7Sf88hG/gy WCx7a4yfKgOGTYn0fCChCKVVMrTbki86G3j55StTdb6ZOXFF7AktIUfhi4GeiuuxM5HU jrBKMjf1qbkJIo45k6AcIgt9KgV7WMFxSyidP9urlGvw4MlXIg5Bfh7H6Jmvmk5v3yAd aAzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468457; x=1692073257; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IXQlPOmsz3SjSWtdP/kN0DEGncm9HuckmpRysy+KsOg=; b=F2HkeF2p22o/K8MUlgSs0hs8I94Yu/ct5KC3X6aLN+5mg2CpfCh96ToUWl8kUWjjBM QreiBwMOawb3OJKNGf+dA/ua82uWhmlwcH9mu6aYzPZtW1tlvFiJ3Oa3dmtcni1yDpjz zX/p4njKE+X22bNTDoTMd1iDcLawycO0WW088tOKOf0Ca+IIbbGlUS2kIRjFjrLCTxrw ZNGe6nmt70bhIYHkji7ZbbADjAEMy5owXNWls6lxz1LmKSFxXkjIofBdq0j97nk2smIe 0IcxkvbGxzzCtBcmkYWVbctInW3nLkRsNWWNjg5YBfG3RFJnrSvRr6hyP70jrNCMxksV W55g== X-Gm-Message-State: AOJu0YyezUwv2Aqd61tZvfbNnm17sxWZVYkwN5t2x9leCY+u+qCboCm5 nCDi8P/XqL/E8LvVwcLoDdk= X-Google-Smtp-Source: AGHT+IFO3M/gUCOgAh3u7XWMFCibEM5Aj7UIOnwtuE3iuoF/LCsOkUvhZ8eFEHoABDjaN1jzsfcZIg== X-Received: by 2002:a05:6808:180a:b0:3a7:44da:d5e6 with SMTP id bh10-20020a056808180a00b003a744dad5e6mr14946928oib.38.1691468457418; Mon, 07 Aug 2023 21:20:57 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 10/19] target/ppc: Migrate DECR SPR Date: Tue, 8 Aug 2023 14:19:52 +1000 Message-Id: <20230808042001.411094-11-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::22c; envelope-from=npiggin@gmail.com; helo=mail-oi1-x22c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468532546100001 Content-Type: text/plain; charset="utf-8" TCG does not maintain the DEC reigster in the SPR array, so it does get migrated. TCG also needs to re-start the decrementer timer on the destination machine. Load and store the decrementer into the SPR when migrating. This works for the level-triggered (book3s) decrementer, and should be compatible with existing KVM machines that do keep the DEC value there. This fixes lost decrementer interrupt on migration that can cause hangs, as well as other problems including record-replay bugs. Signed-off-by: Nicholas Piggin --- target/ppc/machine.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/target/ppc/machine.c b/target/ppc/machine.c index 8234e35d69..8a190c4853 100644 --- a/target/ppc/machine.c +++ b/target/ppc/machine.c @@ -209,6 +209,14 @@ static int cpu_pre_save(void *opaque) /* Used to retain migration compatibility for pre 6.0 for 601 machines= . */ env->hflags_compat_nmsr =3D 0; =20 + if (tcg_enabled()) { + /* + * TCG does not maintain the DECR spr (unlike KVM) so have to save + * it here. + */ + env->spr[SPR_DECR] =3D cpu_ppc_load_decr(env); + } + return 0; } =20 @@ -319,6 +327,12 @@ static int cpu_post_load(void *opaque, int version_id) ppc_update_ciabr(env); ppc_update_daw0(env); #endif + /* + * TCG needs to re-start the decrementer timer and/or raise the + * interrupt. This works for level-triggered decrementer. Edge + * triggered types (including HDEC) would need to carry more state. + */ + cpu_ppc_store_decr(env, env->spr[SPR_DECR]); pmu_mmcr01_updated(env); } =20 --=20 2.40.1 From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468544; cv=none; d=zohomail.com; s=zohoarc; b=ZPdH3/m/SydTaGa9Ota/zt2VIF/O9fOBopCl2MPMx59VXQ6yA37NLHpzyvB9zgUytKk893aILpDXuRf7bj2YJo3SxY9XikwdlvLa06Aq0ilBJSym+84HiCJGcV6rMmzf/SLhaa05wKGiH88PoThcRvB20shmYmfm4xPL+kpvXBI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468544; h=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=4E2HOZjazPZHARfPvsKQ/WSbla5XrPKfruoE7y4VFWg=; b=ciG2BDSSQF1lXQg9SJkT9XltO+EA7zeaOn8VEQWqfOSrrbNJxN/UPmuruQ+RmrPo+tui6ltub9WYrHEI8MyYDG6JHeF0GhUhuylSxfJezYaUkn+ixwegeMOmDCFyIlBxi9KDMlAOsiID7Q1rchVeaCl7jdCyXd0jefGgDyDsIW0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169146854439471.6924983032203; Mon, 7 Aug 2023 21:22:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTEDT-000789-Mn; Tue, 08 Aug 2023 00:21:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTEDS-00077g-4Z; Tue, 08 Aug 2023 00:21:06 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTEDQ-0007ml-DC; Tue, 08 Aug 2023 00:21:05 -0400 Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-687ca37628eso798907b3a.1; Mon, 07 Aug 2023 21:21:03 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.20.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:21:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468463; x=1692073263; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4E2HOZjazPZHARfPvsKQ/WSbla5XrPKfruoE7y4VFWg=; b=Vhy9EVvi/2EeLXYpJAysbLLbrrqruoJkLs31XrB+ubay8RxDLkofDi8enQKWnchyZR aRN7qGJ9fOaEjJm1a7dl+tfweXMqpQXlCO77KoT75gp/pwxwB82VipexZ+x5/36CTAB9 rPrFyyYiLHvdt4G1uijXROIW8Qsnj3ELRL8J9xLB+7Kj31dZksdzPilXC6UT5cndJBkI 1V1Xg8vrzddTgNa/sEwLw7jdhbI3L9m3abYMRfMjhT/SZd91XI95orn+Yi/68F0CLJ1M DvwnMG3JyUGEL0Vv3DJ2HYhFQg7qkHZE80jjMNXWofW0oR4t2tFtai/BA4lYeTT/540E xaXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468463; x=1692073263; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4E2HOZjazPZHARfPvsKQ/WSbla5XrPKfruoE7y4VFWg=; b=L/OMtaDQb7jjXLVRkVHSQ+Rp1xpCHhZGQHlvsNeP2WP1yEfvbHWTl8aaADbRjza01w YBKDaLgAFzrSLHJ1gT7gha2t95AYt18FxQFRV66z6pRsxwCF80DRfhop04Q9YJSoBIDb SREeg+1634WkAulfqPjrVRbGTWvjWf5WMsu0lWGf9oomOpluR6Mzkw7YATpsg69RIw4e tqGZE3dnkdUB+j5QDIIlrjNVZtDJoCf6PrC1zcJu7srX/z29Xg94T3KTplCpfLae+lqj qky0ux2vn+0zk3rWz70KnYqwcoag6PwzQakm+t1GDJxj4m1/DSfuInhzinCNCHNWCOkE eFbA== X-Gm-Message-State: AOJu0YwREy5o5hlnAltvRiZQo6ptGtW8ipE9EOo/tIVq8LT58i2ce3SS htr8af8MNmsh/HEnmq7Ad+c= X-Google-Smtp-Source: AGHT+IHdw1TjEAx++ylXkfWcODFEWRN8r73/dqPFCE4T/hdLTeDdZ4G+tAM7siWGLFzvo4CPkUL8oQ== X-Received: by 2002:a05:6a20:7495:b0:130:f6bc:9146 with SMTP id p21-20020a056a20749500b00130f6bc9146mr13925261pzd.14.1691468462867; Mon, 07 Aug 2023 21:21:02 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Mark Cave-Ayland , BALATON Zoltan Subject: [PATCH v2 11/19] hw/ppc: Reset timebase facilities on machine reset Date: Tue, 8 Aug 2023 14:19:53 +1000 Message-Id: <20230808042001.411094-12-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=npiggin@gmail.com; helo=mail-pf1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468546355100003 Content-Type: text/plain; charset="utf-8" Lower interrupts, delete timers, and set time facility registers back to initial state on machine reset. This is not so important for record-replay since timebase and decrementer are migrated, but it gives a cleaner reset state. Cc: Mark Cave-Ayland Cc: BALATON Zoltan Signed-off-by: Nicholas Piggin --- hw/ppc/mac_oldworld.c | 1 + hw/ppc/pegasos2.c | 1 + hw/ppc/pnv_core.c | 2 ++ hw/ppc/ppc.c | 46 +++++++++++++++++++++++------------------ hw/ppc/prep.c | 1 + hw/ppc/spapr_cpu_core.c | 2 ++ include/hw/ppc/ppc.h | 3 ++- 7 files changed, 35 insertions(+), 21 deletions(-) diff --git a/hw/ppc/mac_oldworld.c b/hw/ppc/mac_oldworld.c index 510ff0eaaf..9acc7adfc9 100644 --- a/hw/ppc/mac_oldworld.c +++ b/hw/ppc/mac_oldworld.c @@ -81,6 +81,7 @@ static void ppc_heathrow_reset(void *opaque) { PowerPCCPU *cpu =3D opaque; =20 + cpu_ppc_tb_reset(&cpu->env); cpu_reset(CPU(cpu)); } =20 diff --git a/hw/ppc/pegasos2.c b/hw/ppc/pegasos2.c index 075367d94d..bd397cf2b5 100644 --- a/hw/ppc/pegasos2.c +++ b/hw/ppc/pegasos2.c @@ -99,6 +99,7 @@ static void pegasos2_cpu_reset(void *opaque) cpu->env.gpr[1] =3D 2 * VOF_STACK_SIZE - 0x20; cpu->env.nip =3D 0x100; } + cpu_ppc_tb_reset(&cpu->env); } =20 static void pegasos2_pci_irq(void *opaque, int n, int level) diff --git a/hw/ppc/pnv_core.c b/hw/ppc/pnv_core.c index 9b39d527de..8c7afe037f 100644 --- a/hw/ppc/pnv_core.c +++ b/hw/ppc/pnv_core.c @@ -61,6 +61,8 @@ static void pnv_core_cpu_reset(PnvCore *pc, PowerPCCPU *c= pu) hreg_compute_hflags(env); ppc_maybe_interrupt(env); =20 + cpu_ppc_tb_reset(env); + pcc->intc_reset(pc->chip, cpu); } =20 diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index d9a1cfbf91..f391acc39e 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -944,23 +944,6 @@ void cpu_ppc_store_purr(CPUPPCState *env, uint64_t val= ue) &tb_env->purr_offset, value); } =20 -static void cpu_ppc_set_tb_clk (void *opaque, uint32_t freq) -{ - CPUPPCState *env =3D opaque; - PowerPCCPU *cpu =3D env_archcpu(env); - ppc_tb_t *tb_env =3D env->tb_env; - - tb_env->tb_freq =3D freq; - tb_env->decr_freq =3D freq; - /* There is a bug in Linux 2.4 kernels: - * if a decrementer exception is pending when it enables msr_ee at sta= rtup, - * it's not ready to handle it... - */ - _cpu_ppc_store_decr(cpu, 0xFFFFFFFF, 0xFFFFFFFF, 32); - _cpu_ppc_store_hdecr(cpu, 0xFFFFFFFF, 0xFFFFFFFF, 32); - cpu_ppc_store_purr(env, 0x0000000000000000ULL); -} - static void timebase_save(PPCTimebase *tb) { uint64_t ticks =3D cpu_get_host_ticks(); @@ -1062,7 +1045,7 @@ const VMStateDescription vmstate_ppc_timebase =3D { }; =20 /* Set up (once) timebase frequency (in Hz) */ -clk_setup_cb cpu_ppc_tb_init (CPUPPCState *env, uint32_t freq) +void cpu_ppc_tb_init(CPUPPCState *env, uint32_t freq) { PowerPCCPU *cpu =3D env_archcpu(env); ppc_tb_t *tb_env; @@ -1083,9 +1066,32 @@ clk_setup_cb cpu_ppc_tb_init (CPUPPCState *env, uint= 32_t freq) } else { tb_env->hdecr_timer =3D NULL; } - cpu_ppc_set_tb_clk(env, freq); =20 - return &cpu_ppc_set_tb_clk; + tb_env->tb_freq =3D freq; + tb_env->decr_freq =3D freq; +} + +void cpu_ppc_tb_reset(CPUPPCState *env) +{ + PowerPCCPU *cpu =3D env_archcpu(env); + ppc_tb_t *tb_env =3D env->tb_env; + + timer_del(tb_env->decr_timer); + ppc_set_irq(cpu, PPC_INTERRUPT_DECR, 0); + tb_env->decr_next =3D 0; + if (tb_env->hdecr_timer !=3D NULL) { + timer_del(tb_env->hdecr_timer); + ppc_set_irq(cpu, PPC_INTERRUPT_HDECR, 0); + tb_env->hdecr_next =3D 0; + } + + /* There is a bug in Linux 2.4 kernels: + * if a decrementer exception is pending when it enables msr_ee at sta= rtup, + * it's not ready to handle it... + */ + cpu_ppc_store_decr(env, -1); + cpu_ppc_store_hdecr(env, -1); + cpu_ppc_store_purr(env, 0x0000000000000000ULL); } =20 void cpu_ppc_tb_free(CPUPPCState *env) diff --git a/hw/ppc/prep.c b/hw/ppc/prep.c index d9231c7317..f6fd35fcb9 100644 --- a/hw/ppc/prep.c +++ b/hw/ppc/prep.c @@ -67,6 +67,7 @@ static void ppc_prep_reset(void *opaque) PowerPCCPU *cpu =3D opaque; =20 cpu_reset(CPU(cpu)); + cpu_ppc_tb_reset(&cpu->env); } =20 =20 diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c index b482d9754a..91fae56573 100644 --- a/hw/ppc/spapr_cpu_core.c +++ b/hw/ppc/spapr_cpu_core.c @@ -74,6 +74,8 @@ static void spapr_reset_vcpu(PowerPCCPU *cpu) =20 kvm_check_mmu(cpu, &error_fatal); =20 + cpu_ppc_tb_reset(env); + spapr_irq_cpu_intc_reset(spapr, cpu); } =20 diff --git a/include/hw/ppc/ppc.h b/include/hw/ppc/ppc.h index e095c002dc..17a8dfc107 100644 --- a/include/hw/ppc/ppc.h +++ b/include/hw/ppc/ppc.h @@ -54,7 +54,8 @@ struct ppc_tb_t { */ =20 uint64_t cpu_ppc_get_tb(ppc_tb_t *tb_env, uint64_t vmclk, int64_t tb_offse= t); -clk_setup_cb cpu_ppc_tb_init (CPUPPCState *env, uint32_t freq); +void cpu_ppc_tb_init(CPUPPCState *env, uint32_t freq); +void cpu_ppc_tb_reset(CPUPPCState *env); void cpu_ppc_tb_free(CPUPPCState *env); void cpu_ppc_hdecr_init(CPUPPCState *env); void cpu_ppc_hdecr_exit(CPUPPCState *env); --=20 2.40.1 From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468556; cv=none; d=zohomail.com; s=zohoarc; b=mOdDlWzvN3w6tYmA6AmSvjxk1Ve9ag2X3CdN9I02NhhXKtBjly0hUtyvM6NOU1dS/tmLUeh8tQ4epyx1TvfTD1CPJqve1n3o2e+suhGcmR/eOo2a6SJbBaqNcPAedF3Wl3DWM27hIaPcpRxkM/Y0rzh4IGRS9r2a+gl2pliUKvg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468556; h=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=UCnCdFj9EuliCkE/oMkl/TySBNxO/JoW1C8ZeaibWDg=; b=X/6J4JxDJGAcUZSuZb9bdjBPY33IDhxoSYMjEQB7HdsZTa/JlWT1UGUcq861JsofAKjpEvY6TXaWyyS2BIEFAMhk+YzBe3mBoFTFEUMSJ2UnKk59+82D6qy5qBZ4555UeIoODyBb/OCQJnkjvQjUz6bnLnu3EQZ9pExqxLECyM4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691468556630126.52745403309586; Mon, 7 Aug 2023 21:22:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTEDZ-00079F-9V; Tue, 08 Aug 2023 00:21:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTEDX-00078x-57; Tue, 08 Aug 2023 00:21:11 -0400 Received: from mail-oi1-x230.google.com ([2607:f8b0:4864:20::230]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTEDV-0007nP-AE; Tue, 08 Aug 2023 00:21:10 -0400 Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3a4875e65a3so3641896b6e.2; Mon, 07 Aug 2023 21:21:08 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.21.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:21:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468467; x=1692073267; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UCnCdFj9EuliCkE/oMkl/TySBNxO/JoW1C8ZeaibWDg=; b=iXECEEG+QZVy5rAtkW/kmbtBGE15pkDa2nDAO2WOqQR+cTK4skh8bnKBodBAYK+ac1 LD++KTt7VDb1wMWNXaGoJ0RRBuz+x75cmhp7EP+grbnvZBZ2QHrrtj/hNRIkaHQ+CqZd wMa1cjtXrixqVgS2TRepaKJkHB1bhxTQBBWheKAYCa2IgsRw6rHB0Qe2Xc5wr8/ndqHW OJBOnxCirNUEmnSE2yssPPP+Bj57ISMqP7yiJfShsUb9OlvIyY/PmZSOavm8tIS+EAJM /eh55uPTNGtHJuUyH+F/5EzG5nSGM5+2dJuS6hSGRXCnXZBrF50euv/KBzF5wuvUc5jj lnWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468467; x=1692073267; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UCnCdFj9EuliCkE/oMkl/TySBNxO/JoW1C8ZeaibWDg=; b=BVNbK2VBWgW1TD0vn7nU5o5bIcOrVh6pHL7dlin/fSvOJ1av17nJZdc7Td2PjruIp/ letbCYLE7q7f6e091VuTeQNzlbqHFXqbah2lVw/2lCO1NBSUXzYbbZ9t2uqKSPbWWQ5s pOPaFYNFMUK8Xad/5vPXbmvcISPhFQwj1SFd5jmqlgXdPWLMO41cZkOcsGqtwpjl9wsu mCPSyBl/QVz45gmDre0QJnmzdstvXyWelVSagKjJPmDLUyLuIaTgl6tVI74UBltvjPwe ZtCXG3B/TbBAvM6FjGhRGXk1jtia2OL0F2KmmbllgjghU7xN5fU328/F5B2r2D/AyZiU alkg== X-Gm-Message-State: AOJu0YxZ/LMzsqS3whOn/LSjwDqQYqZ26xi3m7ORKP2MTOCtJlMaHweP 7ET7qZQnnluhCmpkGpN1M40= X-Google-Smtp-Source: AGHT+IFzAfKVf2yM7fO5eJWk4udIsyh6rXjOdPzaDJFrSbp/bq9k9BngCcZ9yjAOPI7hS32ErM6L0w== X-Received: by 2002:a05:6808:bd5:b0:3a7:3ce0:1ae5 with SMTP id o21-20020a0568080bd500b003a73ce01ae5mr15162867oik.47.1691468467467; Mon, 07 Aug 2023 21:21:07 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH v2 12/19] hw/ppc: Read time only once to perform decrementer write Date: Tue, 8 Aug 2023 14:19:54 +1000 Message-Id: <20230808042001.411094-13-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::230; envelope-from=npiggin@gmail.com; helo=mail-oi1-x230.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468558766100003 Content-Type: text/plain; charset="utf-8" Reading the time more than once to perform an operation always increases complexity and fragility due to introduced deltas. Simplify the decrementer write by reading the clock once for the operation. Signed-off-by: Nicholas Piggin --- hw/ppc/ppc.c | 84 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 31 deletions(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index f391acc39e..a0ee064b1d 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -708,13 +708,13 @@ bool ppc_decr_clear_on_delivery(CPUPPCState *env) return ((tb_env->flags & flags) =3D=3D PPC_DECR_UNDERFLOW_TRIGGERED); } =20 -static inline int64_t _cpu_ppc_load_decr(CPUPPCState *env, uint64_t next) +static inline int64_t __cpu_ppc_load_decr(CPUPPCState *env, int64_t now, + uint64_t next) { ppc_tb_t *tb_env =3D env->tb_env; - uint64_t now, n; + uint64_t n; int64_t decr; =20 - now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); n =3D ns_to_tb(tb_env->decr_freq, now); if (next > n && tb_env->flags & PPC_TIMER_BOOKE) { decr =3D 0; @@ -727,16 +727,12 @@ static inline int64_t _cpu_ppc_load_decr(CPUPPCState = *env, uint64_t next) return decr; } =20 -target_ulong cpu_ppc_load_decr(CPUPPCState *env) +static target_ulong _cpu_ppc_load_decr(CPUPPCState *env, int64_t now) { ppc_tb_t *tb_env =3D env->tb_env; uint64_t decr; =20 - if (kvm_enabled()) { - return env->spr[SPR_DECR]; - } - - decr =3D _cpu_ppc_load_decr(env, tb_env->decr_next); + decr =3D __cpu_ppc_load_decr(env, now, tb_env->decr_next); =20 /* * If large decrementer is enabled then the decrementer is signed exte= ned @@ -750,14 +746,23 @@ target_ulong cpu_ppc_load_decr(CPUPPCState *env) return (uint32_t) decr; } =20 -target_ulong cpu_ppc_load_hdecr(CPUPPCState *env) +target_ulong cpu_ppc_load_decr(CPUPPCState *env) +{ + if (kvm_enabled()) { + return env->spr[SPR_DECR]; + } else { + return _cpu_ppc_load_decr(env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUA= L)); + } +} + +static target_ulong _cpu_ppc_load_hdecr(CPUPPCState *env, int64_t now) { PowerPCCPU *cpu =3D env_archcpu(env); PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(cpu); ppc_tb_t *tb_env =3D env->tb_env; uint64_t hdecr; =20 - hdecr =3D _cpu_ppc_load_decr(env, tb_env->hdecr_next); + hdecr =3D __cpu_ppc_load_decr(env, now, tb_env->hdecr_next); =20 /* * If we have a large decrementer (POWER9 or later) then hdecr is sign @@ -771,6 +776,11 @@ target_ulong cpu_ppc_load_hdecr(CPUPPCState *env) return (uint32_t) hdecr; } =20 +target_ulong cpu_ppc_load_hdecr(CPUPPCState *env) +{ + return _cpu_ppc_load_hdecr(env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)); +} + uint64_t cpu_ppc_load_purr (CPUPPCState *env) { ppc_tb_t *tb_env =3D env->tb_env; @@ -815,7 +825,7 @@ static inline void cpu_ppc_hdecr_lower(PowerPCCPU *cpu) ppc_set_irq(cpu, PPC_INTERRUPT_HDECR, 0); } =20 -static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uint64_t *nextp, +static void __cpu_ppc_store_decr(PowerPCCPU *cpu, int64_t now, uint64_t *n= extp, QEMUTimer *timer, void (*raise_excp)(void *), void (*lower_excp)(PowerPCCPU *), @@ -824,7 +834,7 @@ static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uint6= 4_t *nextp, { CPUPPCState *env =3D &cpu->env; ppc_tb_t *tb_env =3D env->tb_env; - uint64_t now, next; + uint64_t next; int64_t signed_value; int64_t signed_decr; =20 @@ -836,18 +846,12 @@ static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uin= t64_t *nextp, =20 trace_ppc_decr_store(nr_bits, decr, value); =20 - if (kvm_enabled()) { - /* KVM handles decrementer exceptions, we don't need our own timer= */ - return; - } - /* * Calculate the next decrementer event and set a timer. * decr_next is in timebase units to keep rounding simple. Note it is * not adjusted by tb_offset because if TB changes via tb_offset chang= ing, * decrementer does not change, so not directly comparable with TB. */ - now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); next =3D ns_to_tb(tb_env->decr_freq, now) + value; *nextp =3D next; /* nextp is in timebase units */ =20 @@ -876,12 +880,13 @@ static void __cpu_ppc_store_decr(PowerPCCPU *cpu, uin= t64_t *nextp, timer_mod(timer, tb_to_ns_round_up(tb_env->decr_freq, next)); } =20 -static inline void _cpu_ppc_store_decr(PowerPCCPU *cpu, target_ulong decr, - target_ulong value, int nr_bits) +static inline void _cpu_ppc_store_decr(PowerPCCPU *cpu, int64_t now, + target_ulong decr, target_ulong val= ue, + int nr_bits) { ppc_tb_t *tb_env =3D cpu->env.tb_env; =20 - __cpu_ppc_store_decr(cpu, &tb_env->decr_next, tb_env->decr_timer, + __cpu_ppc_store_decr(cpu, now, &tb_env->decr_next, tb_env->decr_timer, tb_env->decr_timer->cb, &cpu_ppc_decr_lower, tb_env->flags, decr, value, nr_bits); } @@ -890,13 +895,22 @@ void cpu_ppc_store_decr(CPUPPCState *env, target_ulon= g value) { PowerPCCPU *cpu =3D env_archcpu(env); PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(cpu); + int64_t now; + target_ulong decr; int nr_bits =3D 32; =20 + if (kvm_enabled()) { + /* KVM handles decrementer exceptions, we don't need our own timer= */ + return; + } + if (env->spr[SPR_LPCR] & LPCR_LD) { nr_bits =3D pcc->lrg_decr_bits; } =20 - _cpu_ppc_store_decr(cpu, cpu_ppc_load_decr(env), value, nr_bits); + now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + decr =3D _cpu_ppc_load_decr(env, now); + _cpu_ppc_store_decr(cpu, now, decr, value, nr_bits); } =20 static void cpu_ppc_decr_cb(void *opaque) @@ -906,14 +920,15 @@ static void cpu_ppc_decr_cb(void *opaque) cpu_ppc_decr_excp(cpu); } =20 -static inline void _cpu_ppc_store_hdecr(PowerPCCPU *cpu, target_ulong hdec= r, - target_ulong value, int nr_bits) +static inline void _cpu_ppc_store_hdecr(PowerPCCPU *cpu, int64_t now, + target_ulong hdecr, target_ulong v= alue, + int nr_bits) { ppc_tb_t *tb_env =3D cpu->env.tb_env; =20 if (tb_env->hdecr_timer !=3D NULL) { /* HDECR (Book3S 64bit) is edge-based, not level like DECR */ - __cpu_ppc_store_decr(cpu, &tb_env->hdecr_next, tb_env->hdecr_timer, + __cpu_ppc_store_decr(cpu, now, &tb_env->hdecr_next, tb_env->hdecr_= timer, tb_env->hdecr_timer->cb, &cpu_ppc_hdecr_lower, PPC_DECR_UNDERFLOW_TRIGGERED, hdecr, value, nr_bits); @@ -924,9 +939,12 @@ void cpu_ppc_store_hdecr(CPUPPCState *env, target_ulon= g value) { PowerPCCPU *cpu =3D env_archcpu(env); PowerPCCPUClass *pcc =3D POWERPC_CPU_GET_CLASS(cpu); + int64_t now; + target_ulong hdecr; =20 - _cpu_ppc_store_hdecr(cpu, cpu_ppc_load_hdecr(env), value, - pcc->lrg_decr_bits); + now =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + hdecr =3D _cpu_ppc_load_hdecr(env, now); + _cpu_ppc_store_hdecr(cpu, now, hdecr, value, pcc->lrg_decr_bits); } =20 static void cpu_ppc_hdecr_cb(void *opaque) @@ -936,12 +954,16 @@ static void cpu_ppc_hdecr_cb(void *opaque) cpu_ppc_hdecr_excp(cpu); } =20 -void cpu_ppc_store_purr(CPUPPCState *env, uint64_t value) +static void _cpu_ppc_store_purr(CPUPPCState *env, int64_t now, uint64_t va= lue) { ppc_tb_t *tb_env =3D env->tb_env; =20 - cpu_ppc_store_tb(tb_env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), - &tb_env->purr_offset, value); + cpu_ppc_store_tb(tb_env, now, &tb_env->purr_offset, value); +} + +void cpu_ppc_store_purr(CPUPPCState *env, uint64_t value) +{ + _cpu_ppc_store_purr(env, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), value); } =20 static void timebase_save(PPCTimebase *tb) --=20 2.40.1 From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468579; cv=none; d=zohomail.com; s=zohoarc; b=dc0Fe5knbaMgpbJpMPh0p07MNfr8VXs9Al3sEqOEefBK3tqdsT0vzt74YI4MZdzgwPBiOIZB3lnfgpfvT0qKk4rTxY0zx+I0EXl4bXqFUzroNJHRlVNR22vggC4UHuZPTRaBnKLvyNipypXheWmZUmnswFwUK1Ya24I58yRPXek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468579; h=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=NDoBnWU9nJFYhYMaJ09B/DrZ52b50Hn/a9GD0l2GXqY=; b=S0JtCI6cAem9dbjya3DBBUI3ooh5tQ5n8kITBWfVWE71ISor0XLcOcB/PwmW7MJ0fzLBjvRips56ZslzhnmqgJybdZuNvaXUHTcepqwrITx0hQMHvnXH0plHuldU1l6GoUvDKx2el/1jExSex4C6hXOtqIz144EwlcbhQ/qu03M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691468579340585.5225664154889; Mon, 7 Aug 2023 21:22:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTEDd-0007QI-Mj; Tue, 08 Aug 2023 00:21:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTEDb-0007In-RQ; Tue, 08 Aug 2023 00:21:15 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTEDZ-0007ns-W0; Tue, 08 Aug 2023 00:21:15 -0400 Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-686ed1d2594so5052976b3a.2; Mon, 07 Aug 2023 21:21:13 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.21.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:21:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468472; x=1692073272; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NDoBnWU9nJFYhYMaJ09B/DrZ52b50Hn/a9GD0l2GXqY=; b=B6F5OWDlr3SS1m/25MhItVOWNPkUVZk8ePecvD4fAl6iNKUWWv1sWkfZ9ZUxGyPQPY UCcT0Y71VwE4Hp1aOJmrBdFlIGGfDvs5KVrlZw1Vpfcfon+1uGnkObdONf/RjIwpmOuP QhKZ1JXDLjEO+Y4zuJ6kuKEwuPWntaRlLHRhKiovF1/gMvJEARkotTBaoZauTJD8JeVw LoDi5vaiEB03HFpiSGDNljsiCBuah6VtPuB9xOVrkTzvmzVkoUPwcrJqwU9wRjqsQ7Kk N/nTJxDA6QecTqskqM3Stc7d7u1GnVU8H97/06obb7Up9QBsOXFr7A05zzDtzteD7l7H 6tkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468472; x=1692073272; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NDoBnWU9nJFYhYMaJ09B/DrZ52b50Hn/a9GD0l2GXqY=; b=kp0CnggcqKfF05BS8hyMkRUhQGa6KOob7Cw4q36xG0sjc1HHjN5W1YI+PJm0KdbYd6 fX7Yck1U7pOEc0yweaaygswxhLCvfDLeYKD2SpA2s7cydKqHsi6skg3RCRKzYhDB/nyB VDGN51yp9StjhO1yDLWlBnisosVZgA9U5WZcw35iqiUZNXZPVJ87V4jivxpiBA6EHQzk SEQPk0hC6wyS4IlL7h+Cws2rsVDf3ZTiZQCIPrg6MujTI5NQftXXejF5PpWsDuQ0zTVp +l7yR7m7KC4OvZEruHqXBPhB7nPU5BxgLbLqRymH7nMVou92C4A16ejXT1HBr07Vxd57 a1GA== X-Gm-Message-State: AOJu0YztAtfOO0suwHnljLa6JL8HPlB7xEl+Nva+QOyr1jmvkWchQ6JN dgttPpPTsYykHaFTtcdpXCQ= X-Google-Smtp-Source: AGHT+IEOzlImFZwx5jXiTGocVHuE5KhDCeNbspIYwLowcLK0tb1bgByDZ+SZ2xxHiNu5wVuLcP3RHQ== X-Received: by 2002:aa7:88c1:0:b0:682:537f:2cb8 with SMTP id k1-20020aa788c1000000b00682537f2cb8mr14957489pff.26.1691468472262; Mon, 07 Aug 2023 21:21:12 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Pavel Dovgalyuk Subject: [PATCH v2 13/19] target/ppc: Fix CPU reservation migration for record-replay Date: Tue, 8 Aug 2023 14:19:55 +1000 Message-Id: <20230808042001.411094-14-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=npiggin@gmail.com; helo=mail-pf1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468580226100001 Content-Type: text/plain; charset="utf-8" ppc only migrates reserve_addr, so the destination machine can get a valid reservation with an incorrect reservation value of 0. Prior to commit 392d328abe753 ("target/ppc: Ensure stcx size matches larx"), this could permit a stcx. to incorrectly succeed. That commit inadvertently fixed that bug because the target machine starts with an impossible reservation size of 0, so any stcx. will fail. This behaviour is permitted by the ISA because reservation loss may have implementation-dependent cause. What's more, with KVM machines it is impossible save or reasonably restore reservation state. However if the vmstate is being used for record-replay, the reservation must be saved and restored exactly in order for execution from snapshot to match the record. This patch deprecates the existing incomplete reserve_addr vmstate, and adds a new vmstate subsection with complete reservation state. The new vmstate is needed only when record-replay mode is active. Acked-by: Pavel Dovgalyuk Signed-off-by: Nicholas Piggin --- target/ppc/cpu.h | 2 ++ target/ppc/machine.c | 26 ++++++++++++++++++++++++-- target/ppc/translate.c | 4 ++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 2777ea3110..9e491e05eb 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1121,7 +1121,9 @@ struct CPUArchState { target_ulong reserve_addr; /* Reservation address */ target_ulong reserve_length; /* Reservation larx op size (bytes) */ target_ulong reserve_val; /* Reservation value */ +#if defined(TARGET_PPC64) target_ulong reserve_val2; +#endif =20 /* These are used in supervisor mode only */ target_ulong msr; /* machine state register */ diff --git a/target/ppc/machine.c b/target/ppc/machine.c index 8a190c4853..ad7b4f6338 100644 --- a/target/ppc/machine.c +++ b/target/ppc/machine.c @@ -10,6 +10,7 @@ #include "qemu/main-loop.h" #include "kvm_ppc.h" #include "power8-pmu.h" +#include "sysemu/replay.h" =20 static void post_load_update_msr(CPUPPCState *env) { @@ -690,6 +691,27 @@ static const VMStateDescription vmstate_compat =3D { } }; =20 +static bool reservation_needed(void *opaque) +{ + return (replay_mode !=3D REPLAY_MODE_NONE); +} + +static const VMStateDescription vmstate_reservation =3D { + .name =3D "cpu/reservation", + .version_id =3D 1, + .minimum_version_id =3D 1, + .needed =3D reservation_needed, + .fields =3D (VMStateField[]) { + VMSTATE_UINTTL(env.reserve_addr, PowerPCCPU), + VMSTATE_UINTTL(env.reserve_length, PowerPCCPU), + VMSTATE_UINTTL(env.reserve_val, PowerPCCPU), +#if defined(TARGET_PPC64) + VMSTATE_UINTTL(env.reserve_val2, PowerPCCPU), +#endif + VMSTATE_END_OF_LIST() + } +}; + const VMStateDescription vmstate_ppc_cpu =3D { .name =3D "cpu", .version_id =3D 5, @@ -711,8 +733,7 @@ const VMStateDescription vmstate_ppc_cpu =3D { VMSTATE_UINTTL_ARRAY(env.spr, PowerPCCPU, 1024), VMSTATE_UINT64(env.spe_acc, PowerPCCPU), =20 - /* Reservation */ - VMSTATE_UINTTL(env.reserve_addr, PowerPCCPU), + VMSTATE_UNUSED(sizeof(target_ulong)), /* was env.reserve_addr */ =20 /* Supervisor mode architected state */ VMSTATE_UINTTL(env.msr, PowerPCCPU), @@ -741,6 +762,7 @@ const VMStateDescription vmstate_ppc_cpu =3D { &vmstate_tlbemb, &vmstate_tlbmas, &vmstate_compat, + &vmstate_reservation, NULL } }; diff --git a/target/ppc/translate.c b/target/ppc/translate.c index b8c7f38ccd..4a60aefd8f 100644 --- a/target/ppc/translate.c +++ b/target/ppc/translate.c @@ -77,7 +77,9 @@ static TCGv cpu_xer, cpu_so, cpu_ov, cpu_ca, cpu_ov32, cp= u_ca32; static TCGv cpu_reserve; static TCGv cpu_reserve_length; static TCGv cpu_reserve_val; +#if defined(TARGET_PPC64) static TCGv cpu_reserve_val2; +#endif static TCGv cpu_fpscr; static TCGv_i32 cpu_access_type; =20 @@ -151,9 +153,11 @@ void ppc_translate_init(void) cpu_reserve_val =3D tcg_global_mem_new(cpu_env, offsetof(CPUPPCState, reserve_val= ), "reserve_val"); +#if defined(TARGET_PPC64) cpu_reserve_val2 =3D tcg_global_mem_new(cpu_env, offsetof(CPUPPCState, reserve_va= l2), "reserve_val2"); +#endif =20 cpu_fpscr =3D tcg_global_mem_new(cpu_env, offsetof(CPUPPCState, fpscr), "fpscr"); --=20 2.40.1 From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468568; cv=none; d=zohomail.com; s=zohoarc; b=iPeAbskIPxv3itNNkf7N7ynr7nZX1j4N95SDMWjomFuYTyg91bxpNOUu7uAakyVGY+77zYM4NwHleFTIPqL8Bu805WYu4vtGf8dW8mctyDGhx05IPC84futArmzbDtwBgwEyiaTGJj4gVZzxsup3m6wkTZGkiFrmbquVxYxlSFo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468568; h=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=7hlH2LR6sixLF4V7zBys/ieYFlsDwDyLaEsz5PY7Muc=; b=VfZpYEnZmBBUn1oRQGoL8ZC/yUkGm9nn8/PQAc6QfnBt4QDA1hyD+cce4jb4nAP2AspvS4r8SWpemTWUDyKQ2CQG0Cz3YExrtW4ubxw4XPwv5kmL5sVkwpTTUddch18TXWpHETsTUkqQ1izVe7CDEqkC2y+Y2qHGc10Ml/WqUok= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691468568651403.2857704501745; Mon, 7 Aug 2023 21:22:48 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTEDj-0007v9-8W; Tue, 08 Aug 2023 00:21:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTEDg-0007oZ-V3; Tue, 08 Aug 2023 00:21:20 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTEDf-0007p4-B1; Tue, 08 Aug 2023 00:21:20 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-686fc0d3c92so3476060b3a.0; Mon, 07 Aug 2023 21:21:18 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.21.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:21:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468477; x=1692073277; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7hlH2LR6sixLF4V7zBys/ieYFlsDwDyLaEsz5PY7Muc=; b=DTb9lJPo9SeRwaMOb7/gYmj/f9MeFq45kW2nrM2SpxRCXYYuhfEtTgOCNSx+DVPZLM 69xpl/3dkX7hiTXhO/cNZ67tEZLgV41Iqx06SBjiukPxKAuPABx61FN0kSG0EfyOlVpb QaS8x/CRvn/OyeQ/i3YNqzcCPJAgHUf5Qp++HlVlo+w/pZ/DhBKX4gWs5Qpj+nHuIjV0 e2aAa6Nm5xkUaIFGiBD50jXfQ1ePrMToCqvRoqwtW0VOzR6Rn1KbEMdNyGeU7SKvhxSh nyiJj98+CWFp5uLWwG+5uhgbWWhv+DYJDGzJ0c/pXYPeb8fJzxFcHSuuhvnJrUsoFdKG RkaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468477; x=1692073277; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7hlH2LR6sixLF4V7zBys/ieYFlsDwDyLaEsz5PY7Muc=; b=NVJPJSPCb5m13/LNW8Ez63hfxzXjruh/gTr8on2a0NpMp5dUV1Lew27FwAAarYo85r qN0vM0v6g1bBzQokaXnNgSqFGCuiOyY2RUcoiTaz+Rwt9n2KuGq8WvTOpu9DGbMlIkzx W0Std3t3kLSU5Drqknm4Ai2G+uCDxFWLIiXQn+iAWBA39rY534hn3apJkMvXPnAjGb+m j41Cpvf4t1MNOwq2X8TQbuGfKNPqs4nSsyExPL2+eEHnxGk3toB2gh2tyQYRzQtGIHtK 6SSwHidCJDRMjKmJSoE0YEd2PoLdiPE/gFIqmb4Lk+P+hfd4g6QF5MMkgIzelJkbrVVa Z5mw== X-Gm-Message-State: AOJu0Yz/c1IF+nbl0B5MCAm0DpSOo8USGt8FoGxgZ27vMMjEQmAk3sGX UTQVrpjyFE7AhzY+SiLMmVU= X-Google-Smtp-Source: AGHT+IGpMvUMrMRCeZeEIYpHqKdvdM3To54ACaPmaveKGnU+8zwvYhDvadQHMyAgF8578JnihS1clw== X-Received: by 2002:a05:6a00:841:b0:666:a25b:3788 with SMTP id q1-20020a056a00084100b00666a25b3788mr10637967pfk.34.1691468477397; Mon, 07 Aug 2023 21:21:17 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Pavel Dovgalyuk Subject: [PATCH v2 14/19] target/ppc: Fix timebase reset with record-replay Date: Tue, 8 Aug 2023 14:19:56 +1000 Message-Id: <20230808042001.411094-15-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=npiggin@gmail.com; helo=mail-pf1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468570490100005 Content-Type: text/plain; charset="utf-8" Timebase save uses a random number for a legacy vmstate field, which makes rr snapshot loading unbalanced. The easiest way to deal with this is just to skip the rng if record-replay is active. Reviewed-by: Pavel Dovgalyuk Signed-off-by: Nicholas Piggin --- hw/ppc/ppc.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c index a0ee064b1d..87df914600 100644 --- a/hw/ppc/ppc.c +++ b/hw/ppc/ppc.c @@ -32,6 +32,7 @@ #include "qemu/main-loop.h" #include "qemu/error-report.h" #include "sysemu/kvm.h" +#include "sysemu/replay.h" #include "sysemu/runstate.h" #include "kvm_ppc.h" #include "migration/vmstate.h" @@ -976,8 +977,14 @@ static void timebase_save(PPCTimebase *tb) return; } =20 - /* not used anymore, we keep it for compatibility */ - tb->time_of_the_day_ns =3D qemu_clock_get_ns(QEMU_CLOCK_HOST); + if (replay_mode =3D=3D REPLAY_MODE_NONE) { + /* not used anymore, we keep it for compatibility */ + tb->time_of_the_day_ns =3D qemu_clock_get_ns(QEMU_CLOCK_HOST); + } else { + /* simpler for record-replay to avoid this event, compat not neede= d */ + tb->time_of_the_day_ns =3D 0; + } + /* * tb_offset is only expected to be changed by QEMU so * there is no need to update it from KVM here --=20 2.40.1 From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468538; cv=none; d=zohomail.com; s=zohoarc; b=JsoySIPtp++TscNEcNEGkk215k0Sk2nL7d0WzNfsHeGolsBXeX0kkDQfc2sM5iAs0BuyqAorAE4x5vCzGG3+JxvLtRkJe/D6ZqfjmQYCD4O2OnEzNFP3Gtt7v84GubPB0gHvd92AUTmIFeLm5eXjLspck1daPG//jjIgjl4HU2U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468538; h=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=+zhYuU1LPhkk5c/LHJ1SKaslbsMf0uSaFlo7cbMkXb4=; b=ODp+N4KxwV/Da3JS0+2G67vlIok+4e8a3FT4PtWpQxfOM2Y3ZyHroCzLUqk/fgOz979NuaoztVYxvcJSKrTXv1Cpn4fLSW+pasd5JvX3lQPxTFLm5CzwavIjq5Asa47imqUb0oPrfwDGSnfCarP9GFIp93CT6q6wHJmML69lZV0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691468538951257.6747516610826; Mon, 7 Aug 2023 21:22:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTEDm-00082a-TC; Tue, 08 Aug 2023 00:21:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTEDl-0007zF-Sy; Tue, 08 Aug 2023 00:21:25 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTEDk-0007pd-4u; Tue, 08 Aug 2023 00:21:25 -0400 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-686f19b6dd2so3560067b3a.2; Mon, 07 Aug 2023 21:21:23 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.21.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:21:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468482; x=1692073282; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+zhYuU1LPhkk5c/LHJ1SKaslbsMf0uSaFlo7cbMkXb4=; b=nxaQ9OT80N1SOxZYG09EDuFjJ3DcUB4qlOfKKKiTL3ZWLfLyHz/rJ/wm09GF0AycYD apjVZpztRbSIqaiuoiBrD+57SJiQwOc0jXSjrUBS+Ewu+HftM1vHN+vAYbiH2ASyUkpL ps8OM35PywL1eux8W5dMieR1iX1wZSdMY3KMw1LffbrwONsfoSKVKg87RcBFj2LCP9EX SCtYeZCI35mwT0MVdrVpYoCEIj7Z7D/LWJ8W3IGhu43M8/3V2/fRhjon2U4gWF83G9jY OfF9dT8auz0j9mqPqwux+kkcTDB667CkPuTLJip9dHqMnho7rZtCT3NDKbvA7Ch8aTDU JRvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468482; x=1692073282; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+zhYuU1LPhkk5c/LHJ1SKaslbsMf0uSaFlo7cbMkXb4=; b=TEw6aFUi/t/zJOlrXw0JAy8PzDIodcm8SN5W3OZmSVFgbo+Wx9jtxi72O4cZzgmiX2 Vh1bmVuuILXAKFmTVzigwD4JGVW2s0MF5hozWISGNKZF1RjcbtHJWsBPxhJoK5bOuEn2 CTc27cbL1jqTJoYi9tgOEVV6Q1WDyRNUfmDeCS/kAfSYrHqzs8UbTJnoFO6M+7iK7fPz YFHVqr0ip+V22hRh9qhk1HqS7YbseYOXXS7jedec6v6YpqswIe5kcLCy49FNBlA9Ez8t NpJHMheShCXCob6Ca1biJ8gf5jKYrhMEi7voClEa+pE6QHjFvdIKp38wU6vKF/NuZntj BqDA== X-Gm-Message-State: AOJu0YxHkfDgfJ02xbL1eTwwfghoXkJroP6Vq9ME3nYmLIQV1kHRlcpE lapkVScDYe1JvLRUlkI+UVQ= X-Google-Smtp-Source: AGHT+IGwC/NipY6A6yji07yq4FAPm/suS09zvRxseHqE6p27WpYA76BEbHzkvsCx+I/XEJda7hQhiw== X-Received: by 2002:a05:6a21:7888:b0:140:4efb:1c09 with SMTP id bf8-20020a056a21788800b001404efb1c09mr8210786pzc.55.1691468482268; Mon, 07 Aug 2023 21:21:22 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Pavel Dovgalyuk Subject: [PATCH v2 15/19] spapr: Fix machine reset deadlock from replay-record Date: Tue, 8 Aug 2023 14:19:57 +1000 Message-Id: <20230808042001.411094-16-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=npiggin@gmail.com; helo=mail-pf1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468540067100001 Content-Type: text/plain; charset="utf-8" When the machine is reset to load a new snapshot while being debugged with replay-record, it is done from another thread, so the CPU does not run the register setting operations. Set CPU registers directly in machine reset. Cc: Pavel Dovgalyuk Signed-off-by: Nicholas Piggin --- hw/ppc/spapr.c | 20 ++++++++++++++++++-- include/hw/ppc/spapr.h | 1 + target/ppc/compat.c | 19 +++++++++++++++++++ target/ppc/cpu.h | 1 + 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 1c8b8d57a7..7d84244f03 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1322,6 +1322,22 @@ void spapr_set_all_lpcrs(target_ulong value, target_= ulong mask) } } =20 +/* May be used when the machine is not running */ +void spapr_init_all_lpcrs(target_ulong value, target_ulong mask) +{ + CPUState *cs; + CPU_FOREACH(cs) { + PowerPCCPU *cpu =3D POWERPC_CPU(cs); + CPUPPCState *env =3D &cpu->env; + target_ulong lpcr; + + lpcr =3D env->spr[SPR_LPCR]; + lpcr &=3D ~(LPCR_HR | LPCR_UPRT); + ppc_store_lpcr(cpu, lpcr); + } +} + + static bool spapr_get_pate(PPCVirtualHypervisor *vhyp, PowerPCCPU *cpu, target_ulong lpid, ppc_v3_pate_t *entry) { @@ -1583,7 +1599,7 @@ int spapr_reallocate_hpt(SpaprMachineState *spapr, in= t shift, Error **errp) } /* We're setting up a hash table, so that means we're not radix */ spapr->patb_entry =3D 0; - spapr_set_all_lpcrs(0, LPCR_HR | LPCR_UPRT); + spapr_init_all_lpcrs(0, LPCR_HR | LPCR_UPRT); return 0; } =20 @@ -1661,7 +1677,7 @@ static void spapr_machine_reset(MachineState *machine= , ShutdownCause reason) spapr_ovec_cleanup(spapr->ov5_cas); spapr->ov5_cas =3D spapr_ovec_new(); =20 - ppc_set_compat_all(spapr->max_compat_pvr, &error_fatal); + ppc_init_compat_all(spapr->max_compat_pvr, &error_fatal); =20 /* * This is fixing some of the default configuration of the XIVE diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 538b2dfb89..f47e8419a5 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -1012,6 +1012,7 @@ bool spapr_check_pagesize(SpaprMachineState *spapr, h= waddr pagesize, #define SPAPR_OV5_XIVE_BOTH 0x80 /* Only to advertise on the platform = */ =20 void spapr_set_all_lpcrs(target_ulong value, target_ulong mask); +void spapr_init_all_lpcrs(target_ulong value, target_ulong mask); hwaddr spapr_get_rtas_addr(void); bool spapr_memory_hot_unplug_supported(SpaprMachineState *spapr); =20 diff --git a/target/ppc/compat.c b/target/ppc/compat.c index 7949a24f5a..ebef2cccec 100644 --- a/target/ppc/compat.c +++ b/target/ppc/compat.c @@ -229,6 +229,25 @@ int ppc_set_compat_all(uint32_t compat_pvr, Error **er= rp) return 0; } =20 +/* To be used when the machine is not running */ +int ppc_init_compat_all(uint32_t compat_pvr, Error **errp) +{ + CPUState *cs; + + CPU_FOREACH(cs) { + PowerPCCPU *cpu =3D POWERPC_CPU(cs); + int ret; + + ret =3D ppc_set_compat(cpu, compat_pvr, errp); + + if (ret < 0) { + return ret; + } + } + + return 0; +} + int ppc_compat_max_vthreads(PowerPCCPU *cpu) { const CompatInfo *compat =3D compat_by_pvr(cpu->compat_pvr); diff --git a/target/ppc/cpu.h b/target/ppc/cpu.h index 9e491e05eb..f8fe0db5cd 100644 --- a/target/ppc/cpu.h +++ b/target/ppc/cpu.h @@ -1504,6 +1504,7 @@ int ppc_set_compat(PowerPCCPU *cpu, uint32_t compat_p= vr, Error **errp); =20 #if !defined(CONFIG_USER_ONLY) int ppc_set_compat_all(uint32_t compat_pvr, Error **errp); +int ppc_init_compat_all(uint32_t compat_pvr, Error **errp); #endif int ppc_compat_max_vthreads(PowerPCCPU *cpu); void ppc_compat_add_property(Object *obj, const char *name, --=20 2.40.1 From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468569; cv=none; d=zohomail.com; s=zohoarc; b=TtObohXpz2C9X4sUjSOC6uvnjQTimTEV2S1Ju1Csn/YUoEEzoXiGg+DSEW1+10kkesCa0RTazlXmg7Emm52K8uKgTJkesPh/TSGETtAXuOIwY9rPv10Ftq2H89xTy09IOEf9Bm6cv6pj0wA6MNFmR6Eg0qI21yoXPdf2fzqDSqg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468569; h=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=F4nIyoBZpzkLWiOsMGF0XETST9Jt61px+DBqOx+1JmI=; b=OsAvWsNpwQjFbmoWwpb2ntx47dX8rfLmsrurwUmfPG0HYsuB9Vn0p0KbmCdoV9OZRcpnLyWsgY1BZ76jXPdxzWohmRMjTUpVW/7xD+CYRADNGJi4Viw+5lrNaXgMyIkV0OST8oYqOSk7nucxi76ShknpFAZaOPgj2ElEkQPYTpE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691468569379230.1046795891599; Mon, 7 Aug 2023 21:22:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTEDs-0008Gd-Ov; Tue, 08 Aug 2023 00:21:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTEDq-0008Et-Oe; Tue, 08 Aug 2023 00:21:30 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTEDo-0007q4-Vu; Tue, 08 Aug 2023 00:21:30 -0400 Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-686f8614ce5so5213028b3a.3; Mon, 07 Aug 2023 21:21:28 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.21.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:21:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468487; x=1692073287; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=F4nIyoBZpzkLWiOsMGF0XETST9Jt61px+DBqOx+1JmI=; b=AHNFvaLiOzcccjTlzZHfQvOnZx3LGPeK7aUog+oLbmwckPThrHZIVqMWGFGp+vDZD8 Gd1v9AWUEP+PvRwcmCs81hbD/o3dM4a2iTDwSnWvuYl41W2RcBqVEUylBCSc7EzCa7Sp zfuQa1JN/Rqw6L1klU+4+MNkmck+jr567eVNcDICc4dhZCND5u8PAdLJsFQOPMzibcka HwoVLDlZZFHZD308tchBMiPEtQWOJe6rd2coUpFaX4k4u17BJAV+/QxEF0PQw0Tp8Ymp v/XXbLv6t3BThtfaHb1BkXwNxUXvtQ8rUSn+l2fKWn+2Brg7p8lCfpymlOctH3Tut78Q XCRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468487; x=1692073287; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=F4nIyoBZpzkLWiOsMGF0XETST9Jt61px+DBqOx+1JmI=; b=hHoD5srqdp59in+zLC5I8A/goW+4AcbocMIEaXtne1N8haY690kdcjcZ1AaRxUXGC/ gbiefRddil2D5Ui4fLFCVwTgs9/gOOi0Ijyzfd2jpVuvBI0Xs7PwL44Po7rN6nmNFoyX OZ101togB0LBmwRv/LQpBdGMXN30TAiZU2DG9reK+u1l89vCCOdK+jTcCiP2pfJgzzjq eTP6joyzO3FExvXlvErV6/UlLZNLH0/pOYFB4GNc437TAmdjgh9osNGvPATx38XFH15p DSWY2DMd5tvi4zFgHKV7mpEa0fv24Gzv54rLzkfkz4Ke/Ka7I7eSMUbCBTH1PGkXbHV2 Tavg== X-Gm-Message-State: AOJu0YxCgDugZs0M6lJkXTbIVOyiOv4vNYVj6qOg0z92FceGdF/24f0s T1aDnvwyV044mde0m5RGR2U= X-Google-Smtp-Source: AGHT+IGs2n/QcuZbzImQ3aG9hapkyszjtcJbpcruzm6mG3kKhdSoK3/Ajej7HGulM471bub/iIs2Vw== X-Received: by 2002:a05:6a20:449:b0:12f:a373:ba8d with SMTP id b9-20020a056a20044900b0012fa373ba8dmr11431731pzb.24.1691468487191; Mon, 07 Aug 2023 21:21:27 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Pavel Dovgalyuk Subject: [PATCH v2 16/19] spapr: Fix record-replay machine reset consuming too many events Date: Tue, 8 Aug 2023 14:19:58 +1000 Message-Id: <20230808042001.411094-17-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=npiggin@gmail.com; helo=mail-pf1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468572552100011 Content-Type: text/plain; charset="utf-8" spapr_machine_reset gets a random number to populate the device-tree rng seed with. When loading a snapshot for record-replay, the machine is reset again, and that tries to consume the random event record again, crashing due to inconsistent record Fix this by saving the seed to populate the device tree with, and skipping the rng on snapshot load. Acked-by: Pavel Dovgalyuk Signed-off-by: Nicholas Piggin --- hw/ppc/spapr.c | 12 +++++++++--- include/hw/ppc/spapr.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c index 7d84244f03..ecfbdb0030 100644 --- a/hw/ppc/spapr.c +++ b/hw/ppc/spapr.c @@ -1022,7 +1022,6 @@ static void spapr_dt_chosen(SpaprMachineState *spapr,= void *fdt, bool reset) { MachineState *machine =3D MACHINE(spapr); SpaprMachineClass *smc =3D SPAPR_MACHINE_GET_CLASS(machine); - uint8_t rng_seed[32]; int chosen; =20 _FDT(chosen =3D fdt_add_subnode(fdt, 0, "chosen")); @@ -1100,8 +1099,7 @@ static void spapr_dt_chosen(SpaprMachineState *spapr,= void *fdt, bool reset) spapr_dt_ov5_platform_support(spapr, fdt, chosen); } =20 - qemu_guest_getrandom_nofail(rng_seed, sizeof(rng_seed)); - _FDT(fdt_setprop(fdt, chosen, "rng-seed", rng_seed, sizeof(rng_seed))); + _FDT(fdt_setprop(fdt, chosen, "rng-seed", spapr->fdt_rng_seed, 32)); =20 _FDT(spapr_dt_ovec(fdt, chosen, spapr->ov5_cas, "ibm,architecture-vec-= 5")); } @@ -1654,6 +1652,14 @@ static void spapr_machine_reset(MachineState *machin= e, ShutdownCause reason) void *fdt; int rc; =20 + if (reason !=3D SHUTDOWN_CAUSE_SNAPSHOT_LOAD) { + /* + * Record-replay snapshot load must not consume random, this was + * already replayed from initial machine reset. + */ + qemu_guest_getrandom_nofail(spapr->fdt_rng_seed, 32); + } + pef_kvm_reset(machine->cgs, &error_fatal); spapr_caps_apply(spapr); =20 diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index f47e8419a5..f4bd204d86 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -204,6 +204,7 @@ struct SpaprMachineState { uint32_t fdt_size; uint32_t fdt_initial_size; void *fdt_blob; + uint8_t fdt_rng_seed[32]; long kernel_size; bool kernel_le; uint64_t kernel_addr; --=20 2.40.1 From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468569; cv=none; d=zohomail.com; s=zohoarc; b=l8HgllHvxt48z8IhuaI0Yxcg42jIKkCqGruo3HEkhvMrr5uBeh2bmq6lyol2gZypx0PjFoPijVsLRMIQUZPZcnZ8k5Kf3+vDmY/7Zh73F5Osi7vxPxJHFIjS18QXm033iP/ioWcbC5PKyVjJfcbrqWfw8IKGI/mFGHQizirgwiI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468569; h=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=oe5890oGRPS+euqSPniLxD+ePYVnJf70zsSY1/DG20s=; b=WKVfY0enV4y6Qog0qQGTgmXGGFuVInXuxS5QJIcF+LQvmF6s1hxNt3QRMT6J+DGIByT7XE/4n22ZYodDUlXZGN5RiLpgDof8kGhPPYk+j0VWzrG3xNxzMBb01dJ//9UV/onhpL/Ds/tFmJHxy3KWuTcB4bHWU0ktq3L7KjK0xXc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 169146856915827.78088596578573; Mon, 7 Aug 2023 21:22:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTEDx-00008Q-D8; Tue, 08 Aug 2023 00:21:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTEDv-0008NU-Nh; Tue, 08 Aug 2023 00:21:35 -0400 Received: from mail-oi1-x232.google.com ([2607:f8b0:4864:20::232]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTEDu-0007ql-4f; Tue, 08 Aug 2023 00:21:35 -0400 Received: by mail-oi1-x232.google.com with SMTP id 5614622812f47-3a78604f47fso2644033b6e.1; Mon, 07 Aug 2023 21:21:33 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.21.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:21:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468492; x=1692073292; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=oe5890oGRPS+euqSPniLxD+ePYVnJf70zsSY1/DG20s=; b=QCC2P45G5UjYHNJRNRlIn+jC6BjgA4mImpAqVsmg8LWSMpniLJXhP7PCqS71wDNJpd usUxZu5z1Ftd/gD23tcURNaA7hOLweXMiClRysslmiyYxv/MurrFoCC8Cbo93VMLhos1 H5i07+R4v7IMvnijyxIvbsyFaiSQjeLjJqRNvC2a6uyLusFvOqtqLhPZ3B6rg/hM/AGL R7FNyZettE4x6RXISvNolx7pyIth5rYH8gTy5cp6jIPxwjewx0E68905ir0AOmlnNA/4 3OvJfJ+BlRGgj+vDXacoaeWNwQOopd01Rbq1ExDHGLkX8rtgx1yqxUjoySdiCOOboJlG 9FVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468492; x=1692073292; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oe5890oGRPS+euqSPniLxD+ePYVnJf70zsSY1/DG20s=; b=cDAYhciPzCg+vMbkRHIBNslWgjbdE47xoIhZRENKRPvJXVDPGBqXJx1FvvaN/6zHSE Z+YFpQBL8lzvP1PM0s0i5N1ksxJ91nZSTV9fd7TDO3zZ42zMJfrL090hGZDAyL0V5ciB GeOimUf8gf8rdZksAER+L0fiJPyJ4i+JU/yvPjfENq3JWVBl46zvx5BpdWAmSIOjkKKT N9Me/etcC5zGb02eVhtVpjAsw/1TM8yT3GY266LxdbVOVe3QGpcH2Nf1FdDxYwAaWHls +qfwM5zeSR1l/7fRhDz3kf/0cQUB15EcbWhP6DuF7pRet7+KVk2D0uTfHiSb3WpJ1fPO S1ag== X-Gm-Message-State: AOJu0YwbiUzdFwlBK54eBztKzVwoLBjaNRsEaxKWZ5NA9J/a6V6ntQFn xDicnjOE0THVV7KTHyXxzds= X-Google-Smtp-Source: AGHT+IGRuRSBOIC8T4NG6fHADVNd9ju2J3yHn74cjjZkrAuNfFuccRlvQ/fQEnniXi3uWyEq6YWl7w== X-Received: by 2002:a05:6808:2218:b0:3a7:a00b:f725 with SMTP id bd24-20020a056808221800b003a7a00bf725mr5714279oib.47.1691468492433; Mon, 07 Aug 2023 21:21:32 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Pavel Dovgalyuk Subject: [PATCH v2 17/19] tests/avocado: boot ppc64 pseries replay-record test to Linux VFS mount Date: Tue, 8 Aug 2023 14:19:59 +1000 Message-Id: <20230808042001.411094-18-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::232; envelope-from=npiggin@gmail.com; helo=mail-oi1-x232.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468570867100007 Content-Type: text/plain; charset="utf-8" This the ppc64 record-replay test is able to replay the full kernel boot so try enabling it. Acked-by: Pavel Dovgalyuk Signed-off-by: Nicholas Piggin --- tests/avocado/replay_kernel.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/avocado/replay_kernel.py b/tests/avocado/replay_kernel.py index 79c607b0e7..a18610542e 100644 --- a/tests/avocado/replay_kernel.py +++ b/tests/avocado/replay_kernel.py @@ -255,8 +255,7 @@ def test_ppc64_pseries(self): kernel_path =3D self.fetch_asset(kernel_url, asset_hash=3Dkernel_h= ash) =20 kernel_command_line =3D self.KERNEL_COMMON_COMMAND_LINE + 'console= =3Dhvc0' - # icount is not good enough for PPC64 for complete boot yet - console_pattern =3D 'Kernel command line: %s' % kernel_command_line + console_pattern =3D 'VFS: Cannot open root device' self.run_rr(kernel_path, kernel_command_line, console_pattern) =20 def test_ppc64_powernv(self): --=20 2.40.1 From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468536; cv=none; d=zohomail.com; s=zohoarc; b=GODhV3xPVSuHPHPwjb2ArTKsPzOTNp+3bxmY7+yzo2W5EvYXRtQ28Nvff29vi0xjwTmrL/yL/TZWpqKwgsK4PsjF1WTU9K8MivWilXMb3Y7XyeNnER77aCGwHZ84GXXHHQNFB3PgxBClvpng5pj7HTzW/HM/yRK30Tsg49nZi60= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468536; h=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=eUxtws3efJ/zcMLuM2mcZXvJskxwLw3PDsxQvmIrbn0=; b=QO/pemc2doDn1EluRuBZ9MTKZpQKucOOoyxxiJR6KMBc8Wc4UpDNulJf38FfDQqJkop84136pmbRtVRunPOckx1NsXGGDeCK5jC6cFyY5mg0f7qKNt1ckLZLEmzJFh/c0m0jLqeYTbkqyIB+hwTzHqDOFiAlRkcOlLsDoxyE9RQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691468536699750.3428630375669; Mon, 7 Aug 2023 21:22:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTEE3-0000yx-BT; Tue, 08 Aug 2023 00:21:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTEE0-0000eP-OH; Tue, 08 Aug 2023 00:21:40 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTEDz-0007rH-0X; Tue, 08 Aug 2023 00:21:40 -0400 Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-686f1240a22so5071786b3a.0; Mon, 07 Aug 2023 21:21:38 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.21.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:21:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468497; x=1692073297; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eUxtws3efJ/zcMLuM2mcZXvJskxwLw3PDsxQvmIrbn0=; b=LjM2pNRekJYwK7hy7FKjtTZ1riuTzOeLtC3XJOXWIEM/Gsa6d8s/Q/dt2UElkSWoS0 1Ak8/Q/5qxK51YT/0/X80zaVfCnZIK/Nm+RQ0KGF4ma06g/0GZOtOHLO3tUe39+8oNAB IJunZ56aHV+LBedhV/1cOfzxA3U7LTnYXYrNiYm+TREB3P4l7fQTGMIrVRUUQN1eCxqX +UCjf0inpxpQvRlDiK1Oth1br+KB0F/BDoiYXyFGHPaQAhYLcrYM8l86PLC7+baj9S9c q6rb4b/uMnLlWItPOp3mJ8huJ9JM14Z86Jl0AxM+tRcgt+yW5RmNIlA0ZU0eXfWoqIdj SXmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468497; x=1692073297; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eUxtws3efJ/zcMLuM2mcZXvJskxwLw3PDsxQvmIrbn0=; b=FGs2LVPYzC80M7FeKrIHgho3IH4eGX66LWcw0didlNjVu3KSFD4bVMbU5062P3saF7 7vW/RA2Ehr3EFkso7MU24TamwiAQknjNRXcKncU084VIjLrLAbfX6od42AgmPqckBFhz MZPTWuEDaEahoWqdFO/eECYWRbf4EWyyJT1XMmb+gXTunc4KF52HvmaHJsqfU/PeBuqq kJGE9vKoprsT2JQDpdle+90OKNJtvk6T9PCzP6vCtr+GEdAyagyCZZjHk8W9wApCwDS0 4h+nWU+XUVHcUdh31lbpRgFoNe6rtvyCZkCLXXge3xXCKNw/7JBOgUuPo63EV7D/+X9B l5OQ== X-Gm-Message-State: AOJu0YxV68hTaB+U0pc/RaHDKId9ywhl708ESi3W7Y6xWXYhCYBmBCFj N6t/cROWle+Lp3Qf4ScTNu8= X-Google-Smtp-Source: AGHT+IHjv4Gc16NkZgpaPjtLvgzcVJ/gFSkDdV7hiAqvJ+ypUA/RfGOHEbNdBGzP+bkBDqbRpY1/5g== X-Received: by 2002:a05:6a00:b90:b0:681:50fd:2b98 with SMTP id g16-20020a056a000b9000b0068150fd2b98mr14446971pfj.31.1691468497333; Mon, 07 Aug 2023 21:21:37 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Pavel Dovgalyuk Subject: [PATCH v2 18/19] tests/avocado: reverse-debugging cope with re-executing breakpoints Date: Tue, 8 Aug 2023 14:20:00 +1000 Message-Id: <20230808042001.411094-19-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=npiggin@gmail.com; helo=mail-pf1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468537999100003 Content-Type: text/plain; charset="utf-8" The reverse-debugging test creates a trace, then replays it and: 1. Steps the first 10 instructions and records their addresses. 2. Steps backward and verifies their addresses match. 3. Runs to (near) the end of the trace. 4. Sets breakpoints on the first 10 instructions. 5. Continues backward and verifies execution stops at the last breakpoint. Step 5 breaks if any of the other 9 breakpoints are re-executed in the trace after the 10th instruction is run, because those will be unexpectedly hit when reverse continuing. This situation does arise with the ppc pseries machine, the SLOF bios branches to its own entry point. Deal with this by switching steps 3 and 4, so the trace will be run to the end *or* one of the breakpoints being re-executed. Step 5 then reverses from there to the 10th instruction will not hit a breakpoint in between, by definition. Another step is added between steps 2 and 3, which steps forward over the first 10 instructions and verifies their addresses, to support this. Reviewed-by: Pavel Dovgalyuk Signed-off-by: Nicholas Piggin --- tests/avocado/reverse_debugging.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/tests/avocado/reverse_debugging.py b/tests/avocado/reverse_deb= ugging.py index 680c314cfc..7d1a478df1 100644 --- a/tests/avocado/reverse_debugging.py +++ b/tests/avocado/reverse_debugging.py @@ -150,16 +150,33 @@ def reverse_debugging(self, shift=3D7, args=3DNone): self.check_pc(g, addr) logger.info('found position %x' % addr) =20 - logger.info('seeking to the end (icount %s)' % (last_icount - 1)) - vm.qmp('replay-break', icount=3Dlast_icount - 1) - # continue - will return after pausing - g.cmd(b'c', b'T02thread:01;') + # visit the recorded instruction in forward order + logger.info('stepping forward') + for addr in steps: + self.check_pc(g, addr) + self.gdb_step(g) + logger.info('found position %x' % addr) =20 + # set breakpoints for the instructions just stepped over logger.info('setting breakpoints') for addr in steps: # hardware breakpoint at addr with len=3D1 g.cmd(b'Z1,%x,1' % addr, b'OK') =20 + # this may hit a breakpoint if first instructions are executed + # again + logger.info('continuing execution') + vm.qmp('replay-break', icount=3Dlast_icount - 1) + # continue - will return after pausing + # This could stop at the end and get a T02 return, or by + # re-executing one of the breakpoints and get a T05 return. + g.cmd(b'c') + if self.vm_get_icount(vm) =3D=3D last_icount - 1: + logger.info('reached the end (icount %s)' % (last_icount - 1)) + else: + logger.info('hit a breakpoint again at %x (icount %s)' % + (self.get_pc(g), self.vm_get_icount(vm))) + logger.info('running reverse continue to reach %x' % steps[-1]) # reverse continue - will return after stopping at the breakpoint g.cmd(b'bc', b'T05thread:01;') --=20 2.40.1 From nobody Thu Nov 28 13:34:44 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1691468532; cv=none; d=zohomail.com; s=zohoarc; b=GC3TP94ISsslO77aQYImiaxUvwG4qQHH8zRe2QMzOEZF81YwRpiZPWXYayebbtg3OfCLsU9OemKRj3Xh5/a/9DVxW0de+0PKOksA+TiPa8q/UnuhNpeTGiP4PoEgB+c+fhG7BD8qgkXdBtOaAzZDOY43pkqEv6rosMnHBMfLW2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691468532; h=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=2Jfr1QqEwPHm/0cW4fOVkjgbOw65i5uezh4p2+HDHZI=; b=hdQWyDXMNQ+ce/ON7r14jqyUyafkSH1413Zw/pDGLHrJBXPxugFrX/95so1rsx7aTjHHLf7ew3fNEjcBzDK07lbBscB5LQ9I3DklpKB+kyyvq318QwMZQs8XQDKB+TE/mOO5UcDlRs4w3Hww+JYDmtUpFqKnf+TFhzCk6EVDlUc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691468532895440.67297938037984; Mon, 7 Aug 2023 21:22:12 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qTEEK-0001d3-Ep; Tue, 08 Aug 2023 00:22:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qTEE5-0001JQ-Q1; Tue, 08 Aug 2023 00:21:47 -0400 Received: from mail-oo1-xc31.google.com ([2607:f8b0:4864:20::c31]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qTEE4-0007rq-5s; Tue, 08 Aug 2023 00:21:45 -0400 Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-56c711a88e8so3477443eaf.2; Mon, 07 Aug 2023 21:21:43 -0700 (PDT) Received: from wheely.local0.net (61-68-137-140.tpgi.com.au. [61.68.137.140]) by smtp.gmail.com with ESMTPSA id fk10-20020a056a003a8a00b0068718f6a035sm6979207pfb.33.2023.08.07.21.21.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 21:21:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691468502; x=1692073302; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=2Jfr1QqEwPHm/0cW4fOVkjgbOw65i5uezh4p2+HDHZI=; b=YsJ3bJbM7+RAQ0J2QtR2MEsk6G1lUdNdwjuXa8m0wHqdKBVar2NCeSIWDX9vcU1glg yBo1lp+NAkaxyU0BS99jiWMd+VTSGqr6V39L8NzCdTg95lCB9Fm6kAchLTe3EKDMBRBM /JdD2baQfZSVSBnB+yFQYiaVvHY37RstOFWW4QWhooNbCwFvlL536BD4D6RgZaYLHGbf cRhBkNMfXeVLtulO6UK96oYPbceUKR/dItC8lmOGTM1q+nfs86NA2NdzXZWYZooNYqe0 oJWVc359eC8MmgSOcTpgKz02di/apTpJJrWjbKzhQD71oUISRjiPrWWBXR4qiSyl6N1h J5og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691468502; x=1692073302; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2Jfr1QqEwPHm/0cW4fOVkjgbOw65i5uezh4p2+HDHZI=; b=IDK1nsihzwK5jMt3v+UPhPUGEPpSVghfrkVgF2CDpsut//3QDupS/A1eacrCTedSNR 6C9fANdFs1aNWRINfTn1bwBigqBUB2Mhdg8+a6BVaBrCrO/gL3T+t6X8baeS+8F6Z7f+ CnYp25H4YNPiX7xqqTDGM0LhyOT3x6bApmNMrXs+OFO8cnhynQzvc2zqmMZpm86vzzxB bSui90MgR+lggc2BKfnWA+gJvlTAV3dDqYx7G0FhXkpMUtTiAjFMrha8D7CfGncMIrZs taPeJNKBsm7Ol/2LoD/nW06xgduIyXTzHNpOhBVgkQ5/24fBTBgbzkTZo6qF/lNDY8OG JTag== X-Gm-Message-State: AOJu0YyiY2br0tAhSj5TGXQWkGyVtABaU+JFE2tXWoSddgzyiT9Fi7pc O3ekV6yH60YFjyt+s3fsVFE= X-Google-Smtp-Source: AGHT+IEdsElLzT9blUAn29xmVZSXyFAjFTOKXiv5mT2it5pJrGDbuABbKHq5LAhny10QDfJwIXGbWg== X-Received: by 2002:a05:6358:9041:b0:135:4003:784a with SMTP id f1-20020a056358904100b001354003784amr9497659rwf.19.1691468502168; Mon, 07 Aug 2023 21:21:42 -0700 (PDT) From: Nicholas Piggin To: Daniel Henrique Barboza Cc: Nicholas Piggin , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , David Gibson , Greg Kurz , Harsh Prateek Bora , Pavel Dovgalyuk , Paolo Bonzini , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, Pavel Dovgalyuk Subject: [PATCH v2 19/19] tests/avocado: ppc64 reverse debugging tests for pseries and powernv Date: Tue, 8 Aug 2023 14:20:01 +1000 Message-Id: <20230808042001.411094-20-npiggin@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230808042001.411094-1-npiggin@gmail.com> References: <20230808042001.411094-1-npiggin@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=2607:f8b0:4864:20::c31; envelope-from=npiggin@gmail.com; helo=mail-oo1-xc31.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691468534311100007 Content-Type: text/plain; charset="utf-8" These machines run reverse-debugging well enough to pass basic tests. Wire them up. Reviewed-by: Pavel Dovgalyuk Signed-off-by: Nicholas Piggin --- tests/avocado/reverse_debugging.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/tests/avocado/reverse_debugging.py b/tests/avocado/reverse_deb= ugging.py index 7d1a478df1..fc47874eda 100644 --- a/tests/avocado/reverse_debugging.py +++ b/tests/avocado/reverse_debugging.py @@ -233,3 +233,32 @@ def test_aarch64_virt(self): =20 self.reverse_debugging( args=3D('-kernel', kernel_path)) + +class ReverseDebugging_ppc64(ReverseDebugging): + """ + :avocado: tags=3Daccel:tcg + """ + + REG_PC =3D 0x40 + + # unidentified gitlab timeout problem + @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab') + def test_ppc64_pseries(self): + """ + :avocado: tags=3Darch:ppc64 + :avocado: tags=3Dmachine:pseries + """ + # SLOF branches back to its entry point, which causes this test + # to take the 'hit a breakpoint again' path. That's not a problem, + # just slightly different than the other machines. + self.endian_is_le =3D False + self.reverse_debugging() + + @skipIf(os.getenv('GITLAB_CI'), 'Running on GitLab') + def test_ppc64_powernv(self): + """ + :avocado: tags=3Darch:ppc64 + :avocado: tags=3Dmachine:powernv + """ + self.endian_is_le =3D False + self.reverse_debugging() --=20 2.40.1