From nobody Sun Jul 26 12:33:36 2026 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=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1781702290; cv=none; d=zohomail.com; s=zohoarc; b=KvYVua97dAryNjeDIwY93Em08obQdfa1g4g2CUI+Vzex8M6I8pTCvrlidpFuM2ZjVeCTgpPcxmSdh1HxRbxTPOzFP0EEO3Lb+VH56aQz/cXkB8pxuH9bNz3VM0eMzj0n5aFdOak0aayWn1g7VLpl1kCIzOatAWg12IKZUKHw2pE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781702290; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=8GztL1Elr1qdIuEyXh8KObvYDmXHW9cI0PCqtZBYkx8=; b=cRNmMhsG78OyN8CNzGJ1lAeo+F56WF7JajQzUVgcvgzk4dBiEqEosW+wW8erSWMSCEOOFQiUcjVADadNx8or3FG7RnwWOYtBCgeM9MEYs3Bhds0shc05L5Io+0B9y5BrJWTtmH16cjmM+rkXc7ysNa7sLKE66JA2I1/ST25wJh4= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178170229038883.47631735070252; Wed, 17 Jun 2026 06:18:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wZq90-0006G2-70; Wed, 17 Jun 2026 09:17:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wZq8y-0006FL-OK for qemu-devel@nongnu.org; Wed, 17 Jun 2026 09:17:24 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wZq8u-0002yV-3a for qemu-devel@nongnu.org; Wed, 17 Jun 2026 09:17:23 -0400 Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 65H8V60v2291351 for ; Wed, 17 Jun 2026 13:17:19 GMT Received: from mail-yw1-f198.google.com (mail-yw1-f198.google.com [209.85.128.198]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4eueevkb1a-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 17 Jun 2026 13:17:18 +0000 (GMT) Received: by mail-yw1-f198.google.com with SMTP id 00721157ae682-7ff705a4289so710377b3.2 for ; Wed, 17 Jun 2026 06:17:18 -0700 (PDT) Received: from QCOM-UWl2o8bcGT.qualcomm.com ([177.170.117.62]) by smtp.gmail.com with ESMTPSA id 00721157ae682-7fcd345a5fesm44861707b3.36.2026.06.17.06.17.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2026 06:17:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= 8GztL1Elr1qdIuEyXh8KObvYDmXHW9cI0PCqtZBYkx8=; b=TWkQyaRHzN+Jn+Qp 1IuPF+AYkdywPZfEi36qCi3wEY6zcVIf9OhLuy7JCx2wigcxD9hPopNJpe0G0bJv L//sj7rRwUfosxjnVD+CDYpi0rC0zn2DjtUbfICO71GX/9xLRzreWLPtOlbOaIzD KDOil+LJO46fkKiJ14GH1R2GNgm+XyZAt5h7ChBW9GJcB6UxAIUOdrKs2yAPVA/e U5zlj5R1YMhxNaS2cQdB1nErl1c0/P1deR235tyEWe8Pz1ugfhDbRp6yRNef10EF nMA1y84oN2Ijtkm1NaQo+z1U7gIq9Otubrezq6pWKsEwOXz89MhZfPXwgxLkuZce LHPOGA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1781702238; x=1782307038; darn=nongnu.org; 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=8GztL1Elr1qdIuEyXh8KObvYDmXHW9cI0PCqtZBYkx8=; b=hN9IWE4uaPLHuC4geIsZEQdwwb94ML++Pa53/y/ryHMrdSmSAhF2Xnm6UzCKk4GGd7 dmWL26q1N3vjMi6nBV37ay6az100iqymGdr7oqWHjJEhVDu6L4DOlHygzOWErXE0FZT3 fBiJ2zqvIbRFKl4GH48pyInHJ3p4r2nOMGOQSV1DLLqXfl7ZV9XNPmVfCDWjBfiUl7mK KnGcaltRm1xa0IN++c3gmZZ1LlGRrDQbOUznFCi6DLjFl4b4Ukp+Vih2euOw9ZSGZnPm jalKBd4ducOKIfeGI4W+9KDDHpACuuOEU4aUGpjOxy0zTkaFRQd7LgmJ/Svqb2kB+Ed7 zdeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781702238; x=1782307038; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=8GztL1Elr1qdIuEyXh8KObvYDmXHW9cI0PCqtZBYkx8=; b=fnQ4i0HnsCYEkxTL4NzZls5a8nEqc/fzjWaWGjKGxO9KMYiI8Med7boj+tAd1Cwnwr HMl3limqR8ch5YOy/UfeKtL74+NDS5UeKBTsTJ3C4GLcjAQPIjqfnzZKUCYMfatf1Pq9 88EQNYkKuXfqfoYQsFG9BwGd6fZNDyisvmLeMya0bB3wRJjCQShjYYrdbFWjBzwZh3j3 MZYyXGkTKpgYDGl3NPqZKPFQ6M1rIDfPxRfSbWP1++5yWNXwdMZuIKEP25AWuhWT+IKV V4tx6uH4jC0AvwBXMwyThFjxzOPwvWQjThKNqMJce4RcaCLohq0LGAysFGLEgf22qCds FDhQ== X-Gm-Message-State: AOJu0Ywq74JNwnB1Ndr+AtQWBCaTpvU+qIvFa6O4Igfsq4WX/SE7EDoa 8xwUYBYT57usNX68IRxr65kGbsVnXkiutfDzOIXjUnpINrS3+aBjJ4mTJHFvPaVcYnF8qTimcYU Z973KFmCqmfnALsQtfOHhDxOx6rwwWk8aUkP/V4Jp+vcz+P8rRuuvFGl+o2GjySD90w== X-Gm-Gg: AfdE7cnJzJmnGMpyeBE1MclYXyn7yPVOyXfJDvfQDpQnSvlUFzoGTXZuH10z7GvVQQp FAZ3rP7yaqOQyiqJK0ldbSQFBMiCV+8v+AUN8LgmVqnS+LOtJUs9cBSr3ZdvK6xNlX+JVJyMCnA asXqIlOS/MAvtnwDplENbfLuP8/33+H/UkfKkyNHDqoKk4h0RfmBQKt11D2hIazfMiMzPY4Z6Sn p2PbiBjriy5HEmuYBEugMjhlLs5DoG/HFRjRr8i0X+w1iD5ugp1PKVYMtHkuyNCyzcL1kZi6u0V zBqytjHgS7iIMwJaEi74o8HYbEnVbT6fqIrIddw37tUzvm6CJwdd4OZq+8Jh7tCb1EgeoBmjs0Y n4Tp0Ozoxj6yMJpNKaoX0mgoGrB8IA0LXPlOEPUz5F/PJLwEk X-Received: by 2002:a05:690c:7403:b0:7dd:3f36:59e3 with SMTP id 00721157ae682-7fe5de9ccfemr36529477b3.36.1781702238292; Wed, 17 Jun 2026 06:17:18 -0700 (PDT) X-Received: by 2002:a05:690c:7403:b0:7dd:3f36:59e3 with SMTP id 00721157ae682-7fe5de9ccfemr36528877b3.36.1781702237809; Wed, 17 Jun 2026 06:17:17 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, chao.liu.zevorn@gmail.com, Daniel Henrique Barboza , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Palmer Dabbelt Subject: [PATCH v4 1/3] target/riscv/cpu: add CPU unrealize callback Date: Wed, 17 Jun 2026 10:17:08 -0300 Message-ID: <20260617131710.1855353-2-daniel.barboza@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260617131710.1855353-1-daniel.barboza@oss.qualcomm.com> References: <20260617131710.1855353-1-daniel.barboza@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjE3MDEyNiBTYWx0ZWRfX6x3hHLtRYsdI BOi4V1ppUb+TYh9AnKDYDbSG/NqcFYvgFVUch0gDeyyDJPLYWZZHWGjPDhoUl6DzbG/EVixXRhy Mlw6A2gmuE9GwD+TDg1aqeq3K/Ck5avjlPbKbk9CIWsRWglM12OO7XUPV59ZbIUp+BOxYSffp11 mZ3/tWGXuPHmYdsEYf3CyhG9j6ukFD1fyZor8nAbEwNDvxSOUHG9p1JZmmwI+tunyvzQb/JLNuF 3dc9blB8bKbnbC4RUe9VUkrzekCdoDqSHbZ87TwHi/GYtdHPRNr2243IOxXqDuFr3uTzAuSn0Fo R0IUnOwDM1UVtBfHTf4kjlD6LHDl7vmSUZjKKWvgWNptFoCk/zIS0r+rV7460idNkPocSlyj5dr K8h8YoowM8cCoGF36oMYvuKaaH+oORxe1vBdeVJC9nBfZXWR5Hlsf6N9HY2/N8PBVi+F/aDEHpA bFxPtzoDkRe0TCI/uXw== X-Authority-Analysis: v=2.4 cv=LM1WhpW9 c=1 sm=1 tr=0 ts=6a329e5e cx=c_pps a=g1v0Z557R90hA0UpD/5Yag==:117 a=gdiugJE53z4H+vvYeRBHqw==:17 a=IkcTkHD0fZMA:10 a=FelO9ux0wxsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=gowsoOTTUOVcmtlkKump:22 a=EUspDBNiAAAA:8 a=JF9118EUAAAA:8 a=-V4TLcwJ7WInddZtJMgA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=MFSWADHSvvjO3QEy5MdX:22 a=xVlTc564ipvMDusKsbsT:22 X-Proofpoint-GUID: cDKIRaDAexzNkM5i5-TqwPTxwHQ3oHqN X-Proofpoint-Spam-Info: AW1haW4tMjYwNjE3MDEyNiBTYWx0ZWRfXyYK5uRMFJKVB uZYTbp2MukXRcuGR+0bo00JYoWBCpLU14xTmwhb36cPk/vcX/y7/uVWjgvvlY3Hv6e5nTDAePZQ YxtPJ+mCOSNIvwOC5wBb/H7r/rhgfa0= X-Proofpoint-ORIG-GUID: cDKIRaDAexzNkM5i5-TqwPTxwHQ3oHqN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-06-17_01,2026-06-16_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 suspectscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 adultscore=0 malwarescore=0 priorityscore=1501 spamscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2606170126 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=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=daniel.barboza@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @qualcomm.com) X-ZM-MESSAGEID: 1781702293031158500 Next patch is going to dynamically allocate debug trigger arrays during realize() time. We need a way of freeing them during unrealize(), which doesn't exist at this moment. There's a lot going on in that patch already so we're adding the callback infrastructure beforehand. Suggested-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Daniel Henrique Barboza Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 9 +++++++++ target/riscv/cpu.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index fa497e5e8a..b47e2b41c8 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1009,6 +1009,13 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) mcc->parent_realize(dev, errp); } =20 +static void riscv_cpu_unrealize(DeviceState *dev) +{ + RISCVCPUClass *mcc =3D RISCV_CPU_GET_CLASS(dev); + + mcc->parent_unrealize(dev); +} + bool riscv_cpu_accelerator_compatible(RISCVCPU *cpu) { if (tcg_enabled()) { @@ -2664,6 +2671,8 @@ static void riscv_cpu_common_class_init(ObjectClass *= c, const void *data) =20 device_class_set_parent_realize(dc, riscv_cpu_realize, &mcc->parent_realize); + device_class_set_parent_unrealize(dc, riscv_cpu_unrealize, + &mcc->parent_unrealize); =20 resettable_class_set_parent_phases(rc, NULL, riscv_cpu_reset_hold, NUL= L, &mcc->parent_phases); diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 7582874c35..16e9f87b83 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -576,6 +576,7 @@ typedef struct RISCVCPUDef { /** * RISCVCPUClass: * @parent_realize: The parent class' realize handler. + * @parent_unrealize: The parent class' unrealize handler. * @parent_phases: The parent class' reset phase handlers. * * A RISCV CPU model. @@ -584,6 +585,7 @@ struct RISCVCPUClass { CPUClass parent_class; =20 DeviceRealize parent_realize; + DeviceUnrealize parent_unrealize; ResettablePhases parent_phases; RISCVCPUDef *def; }; --=20 2.43.0 From nobody Sun Jul 26 12:33:36 2026 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=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1781702290; cv=none; d=zohomail.com; s=zohoarc; b=ZbjnYQSBSQ50oUFyVv+Vxjrd27ChKKDSvCP4z7ZUZbDyCw1Wf6QErhC4Y32UrKggGWziX91Kic+ySYlo/U6HYH2FxtIBI2ZMz7z5VVxv5UW/yAqVleI3vA/GkcGf7w1sgPnuWCOzVNCfpsHH0YZnlUcOeVbwwLHblgj3uy37xlo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781702290; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=LaLnccJXwxVmIPAFAKsOEWNSj4MsI0S6SZFZlfFSfNI=; b=EAX4+veaUXJg/L2muPXs71dPDq7Ne0hYywueSRwDv3CbqKahWvjRQs1MFRqhQVenL+JfxFSn9TM0rFkfLPJ+jp5ZxRElyOdV5Hjk9T5qi2IGTgukUFehPY2JGEQRO/Rf1uVU6cC1bcKMzsb/1jV17Z6+gvSdKKQOrYnEZWGK83I= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1781702290452680.9013551466948; Wed, 17 Jun 2026 06:18:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wZq93-0006Gx-PF; Wed, 17 Jun 2026 09:17:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wZq91-0006GO-8j for qemu-devel@nongnu.org; Wed, 17 Jun 2026 09:17:27 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wZq8x-0002zL-75 for qemu-devel@nongnu.org; Wed, 17 Jun 2026 09:17:25 -0400 Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 65H8W0WL2056645 for ; Wed, 17 Jun 2026 13:17:22 GMT Received: from mail-yw1-f199.google.com (mail-yw1-f199.google.com [209.85.128.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4eueesb9us-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 17 Jun 2026 13:17:22 +0000 (GMT) Received: by mail-yw1-f199.google.com with SMTP id 00721157ae682-7fefbbeed32so6301367b3.0 for ; Wed, 17 Jun 2026 06:17:22 -0700 (PDT) Received: from QCOM-UWl2o8bcGT.qualcomm.com ([177.170.117.62]) by smtp.gmail.com with ESMTPSA id 00721157ae682-7fcd345a5fesm44861707b3.36.2026.06.17.06.17.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2026 06:17:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= LaLnccJXwxVmIPAFAKsOEWNSj4MsI0S6SZFZlfFSfNI=; b=gSHeZCoUeQkd1sZV H48BxGqZBmIUg47XBAE9Q2YFNALZ8MXTLgZ5Ny2m72tY8jSHG2012bZzbva8estl oXaVwNcQeMRCK3DL+UH0q23BrVjt+avdgy5wgekZlBQc4nXETRjBPt1yVcWmOpyd W9F+CPoyK7iV5z4B1eEIhAR4cQzIFih1+fETluKL5nYnUPHEPxdfQd2VKNIVIgKS a8b7RYA9A86thrxVRhJGJ3RmHFL0JzYSXzb77Vp+RhSQKfdP/zZ0FtuGXJuy0KfD fYZLhiQ+Hr4a8/pC7j0zfVHWu/r29nrc5rddSdvnHS+xny7+SHbMiLzsYq9M0Wbs t1WnYQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1781702241; x=1782307041; darn=nongnu.org; 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=LaLnccJXwxVmIPAFAKsOEWNSj4MsI0S6SZFZlfFSfNI=; b=D7XIsCQF3NTQv/K6BAIBRGGWYMexu55q79ToLQkeBxtHHXjoa0vuof8MiTmc3esNWk wrY0azSq/cF3mx11wyC7dBo2DHlh9OldCry0hMFLoTcl05q0fzOtVKlYaciSoeGYPggA wsJgBV4dNtyqpfiv7PkRNXP88RpWPU/+SrPFMlRCs40JqCjeKXiCXfBsiQc/mG/X8BrV j0vBlsQmvBgzMuIvQf0wJ9jXyrS2tA8++TpW0Ogg74vFv20175U7sam/CXh+PTpSprNw /8Q3bIZQ1XJigS8Qxg21gJMq39z6jkztTRR0xb2uK/h8aA6lJxw1H2L2JczrUOV5rTMV jFgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781702241; x=1782307041; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=LaLnccJXwxVmIPAFAKsOEWNSj4MsI0S6SZFZlfFSfNI=; b=G4tPZhsFbn3qNPuIrKxEBfQwoP9+PNRLlixxOHimH3jj/Sn/md9/GDl5m9OCdzTowt jqdkSWksTbnHyJ2vRbr5jpCuox/LHHRZqJgyyMybajcK/mc75gyk3uWM3JuMsohSGY18 8Y0k7JZgzWxV/jAjGXiNisrH7ZxIOILGgGpMAsaNLtbBmMyRswkENL/4PUpHC2U7iu0s YzyOxuu2gNIGYvSSQ/pq0CqnmNBPnn5XtS6EtCld9kCUkW/P2zVSOxvPKVsFYIC9pkHq DyG249w7Jg4pyEkA/8HXLAnLX5zl3RWUM8RWj1GfDo50c6ZC0HVcomfspa4fVd3mi41f aUGQ== X-Gm-Message-State: AOJu0YxWWq4n6U42wRBdG/iDmeimxP2I2fQLNeubyesY8CyzSItUAy+T FFDK71BJXB2Bvo4IWSxvdQGCjiYcxHVviiWcHwTZCq476sPLrswGAQcJ+BjCUNiYTXbB+EFTjbZ bl4oc6fLX24oouOPyOZ9sOmuD9BH8+yhb3qav+BRMMT7qPLVp9C8tKf8Qzh0rvDMzNA== X-Gm-Gg: AfdE7cnCrzLcy40fjhf2XJNhMBQjwKJnFdSzN/jqe1Y8IsC4pihSnJsIMGr074UJ0jf /dAUavzgIN1Mpw6XoIWlBu+zIZfAzGFkCE/Ez/0iHfQ1Pt7O+Yb01R/77YhWLBUr3HrxGOPzGW1 hu60i5CEa9peIvEFQ5rSJP7ueOWEWZe1iLKXFjaeavgLN4I2NVzF5AXwT3gsBGxFvo9INsljLsC Q5F+gVTeo9NpJwWc4pADXynnsANdYwgmyaYGupqbb9yblXobHZud31t0GTIl3CDVSbFoIOnOvkl ze1/LX69YTpSn/sG2Vz3v5xqw8YHh51G4rYV3hAhFjg3AYQXKPPuEwGOO2T0fUmJqcCUHOxOvqp JVfiDlBI8QVxazhLq4tdos7tV1KA8hPR0DskhNyM7HdkHB4Vt X-Received: by 2002:a05:690c:6209:b0:7dc:7b3:6326 with SMTP id 00721157ae682-7fe5d5a452cmr32865997b3.33.1781702241254; Wed, 17 Jun 2026 06:17:21 -0700 (PDT) X-Received: by 2002:a05:690c:6209:b0:7dc:7b3:6326 with SMTP id 00721157ae682-7fe5d5a452cmr32865127b3.33.1781702240504; Wed, 17 Jun 2026 06:17:20 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, chao.liu.zevorn@gmail.com, Daniel Henrique Barboza , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Palmer Dabbelt Subject: [PATCH v4 2/3] target/riscv: dynamic alloc of debug trigger arrays Date: Wed, 17 Jun 2026 10:17:09 -0300 Message-ID: <20260617131710.1855353-3-daniel.barboza@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260617131710.1855353-1-daniel.barboza@oss.qualcomm.com> References: <20260617131710.1855353-1-daniel.barboza@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Info: AW1haW4tMjYwNjE3MDEyNiBTYWx0ZWRfX+uJARrvlRFCp KZAzB97F3KUlOnayZRHAcC6lMKSo7o6EA9sfNt16OUWjOJ55pGiYR7pW4HJs7zQNbRBRU3JVviH L3YghJRKtbZ8ZvfktzBW3KiC6r6OwAA= X-Proofpoint-ORIG-GUID: lX-7qXUthUXZyZpMgd4Zs7HG_o_ecdtK X-Authority-Analysis: v=2.4 cv=R6oz39RX c=1 sm=1 tr=0 ts=6a329e62 cx=c_pps a=72HoHk1woDtn7btP4rdmlg==:117 a=gdiugJE53z4H+vvYeRBHqw==:17 a=IkcTkHD0fZMA:10 a=FelO9ux0wxsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=ZpdpYltYx_vBUK5n70dp:22 a=VwQbUJbxAAAA:8 a=EUspDBNiAAAA:8 a=JF9118EUAAAA:8 a=3hYV-RIbpzt_YiHVFz4A:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=kA6IBgd4cpdPkAWqgNAz:22 a=xVlTc564ipvMDusKsbsT:22 X-Proofpoint-GUID: lX-7qXUthUXZyZpMgd4Zs7HG_o_ecdtK X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjE3MDEyNiBTYWx0ZWRfX0x3VFw19a3yW l+4LPqXuewTDya4v7bJwrLs5Gmof4aowgSCPJIz4Q9ZgSihGuOj+OLqvR9I2e5CF6GMqQCa6Beh clRKYYkHw94BFTsCC5pXWuHl5DYOQMZM6f51Jlae58xv+1ckSqgGdseV3QDH7UO7Gv7ahDktXBX Lm9zPMWrVW+9RAyPA8jbWg302PxNVI9iPveYvuOrTsLIKJBQmTsUj3G/HDRv8hQgMFdoC/pU9Tq 4Jgve5d5Ld/AtjQUC2muiW+LNn6CIVPuF0t/nMbp8MK8nqh9t+i331DA/tvQ/EPODldRM1k7ISg 3j/u7OE7FhtNjulXCfTT8bYylMmWgaYC3opQ4+wEItP24wA4puJ2P8zX7P/xIxtHgrEhQPYUHiU zzsdhXCm1eyBEZ8OatIOD38+gDFRtFx2ZpfULc2ccJHSqLECS2nRPm1mwgobYLMqeNFMUtvdWzr iiNhZMPYKfPhefuAGBA== X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-06-17_01,2026-06-16_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 clxscore=1015 impostorscore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 malwarescore=0 adultscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2606170126 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=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=daniel.barboza@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development 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 @qualcomm.com) X-ZM-MESSAGEID: 1781702293114158500 The debug trigger facility consists of a set of arrays: tdata1-3, cpu_breakpoint, cpu_watchpoint and itrigger_timer. All of them are static allocated with RV_MAX_TRIGGERS (2). This means that all RISC-V cpus will have 2 triggers per hart. The RISC-V Server Ref demands at least 11 triggers per hart, and several CPUs in the wild works with 4+ triggers. We need more flexibility, ergo we need to parametrize the amount of triggers and make it configurable. Before doing that we need to handle a situation faced in a previous attempt [1]. We were unable to set the tdataN array length in vmstate_debug, meaning that we would always migrate RV_MAX_TRIGGERS regardless of the actual amount of triggers in play. To fix that we need to change the tdata arrays from static to dynamic, allowing us to use VMSTATE_VARRAY_UINT32(). This also means that, in contrast with [1], we have the opportunity to turn all trigger arrays into dynamic allocation and reduce the amount of stuff being carried by CPURISCVState, or in other words, we can carry just what we're using instead of a static max value. All the forementioned trigger facility arrays are now dynamic. They are allocated and freed during realize/unrealize, and their size is expressed by env->num_triggers. All relevant code is changed to use env->num_triggers instead of the RV_MAX_TRIGGERS to loop through each array. This will make it easier for the next patch to parametrize env->num_triggers. [1] https://lore.kernel.org/qemu-devel/94c772b0-5231-40e4-9cab-6ac39b9e4d45= @oss.qualcomm.com/ Signed-off-by: Daniel Henrique Barboza Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 6 ++++++ target/riscv/cpu.h | 18 +++++++++++------ target/riscv/csr.c | 2 +- target/riscv/debug.c | 46 ++++++++++++++++++++++++++++++++++-------- target/riscv/debug.h | 1 + target/riscv/machine.c | 16 ++++++++++----- 6 files changed, 69 insertions(+), 20 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index b47e2b41c8..e7318fe9f9 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1012,7 +1012,13 @@ static void riscv_cpu_realize(DeviceState *dev, Erro= r **errp) static void riscv_cpu_unrealize(DeviceState *dev) { RISCVCPUClass *mcc =3D RISCV_CPU_GET_CLASS(dev); +#ifndef CONFIG_USER_ONLY + RISCVCPU *cpu =3D RISCV_CPU(dev); =20 + if (cpu->cfg.debug) { + riscv_trigger_unrealize(&cpu->env); + } +#endif mcc->parent_unrealize(dev); } =20 diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index 16e9f87b83..af246a56ed 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -467,12 +467,18 @@ struct CPUArchState { /* trigger module */ uint16_t mcontext; uint8_t trigger_cur; - uint64_t tdata1[RV_MAX_TRIGGERS]; - uint64_t tdata2[RV_MAX_TRIGGERS]; - uint64_t tdata3[RV_MAX_TRIGGERS]; - struct CPUBreakpoint *cpu_breakpoint[RV_MAX_TRIGGERS]; - struct CPUWatchpoint *cpu_watchpoint[RV_MAX_TRIGGERS]; - QEMUTimer *itrigger_timer[RV_MAX_TRIGGERS]; + /* + * num_triggers is the length of tdata1, tdata2, tdata3, + * cpu_breakpoint, cpu_watchpoint and itrigger_timer + * arrays. + */ + uint32_t num_triggers; + uint64_t *tdata1; + uint64_t *tdata2; + uint64_t *tdata3; + struct CPUBreakpoint **cpu_breakpoint; + struct CPUWatchpoint **cpu_watchpoint; + QEMUTimer **itrigger_timer; int64_t last_icount; bool itrigger_enabled; =20 diff --git a/target/riscv/csr.c b/target/riscv/csr.c index ec931a8c3d..82afad82db 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -5436,7 +5436,7 @@ static RISCVException read_tdata(CPURISCVState *env, = int csrno, target_ulong *val) { /* return 0 in tdata1 to end the trigger enumeration */ - if (env->trigger_cur >=3D RV_MAX_TRIGGERS && csrno =3D=3D CSR_TDATA1) { + if (env->trigger_cur >=3D env->num_triggers && csrno =3D=3D CSR_TDATA1= ) { *val =3D 0; return RISCV_EXCP_NONE; } diff --git a/target/riscv/debug.c b/target/riscv/debug.c index 30d39ee5cd..9a4910c431 100644 --- a/target/riscv/debug.c +++ b/target/riscv/debug.c @@ -172,7 +172,7 @@ target_ulong tselect_csr_read(CPURISCVState *env) =20 void tselect_csr_write(CPURISCVState *env, target_ulong val) { - if (val < RV_MAX_TRIGGERS) { + if (val < env->num_triggers) { env->trigger_cur =3D val; } } @@ -701,7 +701,7 @@ static bool check_itrigger_priv(CPURISCVState *env, int= index) bool riscv_itrigger_enabled(CPURISCVState *env) { int count; - for (int i =3D 0; i < RV_MAX_TRIGGERS; i++) { + for (int i =3D 0; i < env->num_triggers; i++) { if (get_trigger_type(env, i) !=3D TRIGGER_TYPE_INST_CNT) { continue; } @@ -721,7 +721,7 @@ bool riscv_itrigger_enabled(CPURISCVState *env) void helper_itrigger_match(CPURISCVState *env) { int count; - for (int i =3D 0; i < RV_MAX_TRIGGERS; i++) { + for (int i =3D 0; i < env->num_triggers; i++) { if (get_trigger_type(env, i) !=3D TRIGGER_TYPE_INST_CNT) { continue; } @@ -750,7 +750,7 @@ static void riscv_itrigger_update_count(CPURISCVState *= env) int64_t last_icount =3D env->last_icount, current_icount; current_icount =3D env->last_icount =3D icount_get_raw(); =20 - for (int i =3D 0; i < RV_MAX_TRIGGERS; i++) { + for (int i =3D 0; i < env->num_triggers; i++) { if (get_trigger_type(env, i) !=3D TRIGGER_TYPE_INST_CNT) { continue; } @@ -950,7 +950,7 @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs) int i; =20 QTAILQ_FOREACH(bp, &cs->breakpoints, entry) { - for (i =3D 0; i < RV_MAX_TRIGGERS; i++) { + for (i =3D 0; i < env->num_triggers; i++) { trigger_type =3D get_trigger_type(env, i); =20 if (!trigger_common_match(env, trigger_type, i)) { @@ -996,7 +996,7 @@ bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPU= Watchpoint *wp) int flags; int i; =20 - for (i =3D 0; i < RV_MAX_TRIGGERS; i++) { + for (i =3D 0; i < env->num_triggers; i++) { trigger_type =3D get_trigger_type(env, i); =20 if (!trigger_common_match(env, trigger_type, i)) { @@ -1049,19 +1049,49 @@ void riscv_trigger_realize(CPURISCVState *env) { int i; =20 - for (i =3D 0; i < RV_MAX_TRIGGERS; i++) { + /* + * Alloc env->tdata1/2/3, cpu_breakpoint, cpu_watchpoint and + * itrigger_timer dynamically. This is overkill now + * given that they could be static arrays with RV_MAX_TRIGGERS + * but we'll parametrize the trigger number later, i.e. the + * array length won't be static. + */ + env->num_triggers =3D RV_MAX_TRIGGERS; + env->tdata1 =3D g_new0(uint64_t, env->num_triggers); + env->tdata2 =3D g_new0(uint64_t, env->num_triggers); + env->tdata3 =3D g_new0(uint64_t, env->num_triggers); + env->cpu_breakpoint =3D g_new0(struct CPUBreakpoint *, env->num_trigge= rs); + env->cpu_watchpoint =3D g_new0(struct CPUWatchpoint *, env->num_trigge= rs); + env->itrigger_timer =3D g_new0(QEMUTimer *, env->num_triggers); + + for (i =3D 0; i < env->num_triggers; i++) { env->itrigger_timer[i] =3D timer_new_ns(QEMU_CLOCK_VIRTUAL, riscv_itrigger_timer_cb, env= ); } } =20 +void riscv_trigger_unrealize(CPURISCVState *env) +{ + g_free(env->tdata1); + g_free(env->tdata2); + g_free(env->tdata3); + + g_free(env->cpu_breakpoint); + g_free(env->cpu_watchpoint); + + for (int i =3D 0; i < env->num_triggers; i++) { + timer_del(env->itrigger_timer[i]); + } + g_free(env->itrigger_timer); +} + void riscv_trigger_reset_hold(CPURISCVState *env) { target_ulong tdata1 =3D build_tdata1(env, TRIGGER_TYPE_AD_MATCH, 0, 0); int i; =20 /* init to type 2 triggers */ - for (i =3D 0; i < RV_MAX_TRIGGERS; i++) { + for (i =3D 0; i < env->num_triggers; i++) { /* * type =3D TRIGGER_TYPE_AD_MATCH * dmode =3D 0 (both debug and M-mode can write tdata) diff --git a/target/riscv/debug.h b/target/riscv/debug.h index 55a3ac72e6..a25d099b37 100644 --- a/target/riscv/debug.h +++ b/target/riscv/debug.h @@ -148,6 +148,7 @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs); bool riscv_cpu_debug_check_watchpoint(CPUState *cs, CPUWatchpoint *wp); =20 void riscv_trigger_realize(CPURISCVState *env); +void riscv_trigger_unrealize(CPURISCVState *env); void riscv_trigger_reset_hold(CPURISCVState *env); =20 bool riscv_itrigger_enabled(CPURISCVState *env); diff --git a/target/riscv/machine.c b/target/riscv/machine.c index 6e70b145a5..ba96ceceef 100644 --- a/target/riscv/machine.c +++ b/target/riscv/machine.c @@ -240,16 +240,22 @@ static int debug_post_load(void *opaque, int version_= id) =20 static const VMStateDescription vmstate_debug =3D { .name =3D "cpu/debug", - .version_id =3D 3, - .minimum_version_id =3D 3, + .version_id =3D 4, + .minimum_version_id =3D 4, .needed =3D debug_needed, .post_load =3D debug_post_load, .fields =3D (const VMStateField[]) { VMSTATE_UINT16(env.mcontext, RISCVCPU), VMSTATE_UINT8(env.trigger_cur, RISCVCPU), - VMSTATE_UINT64_ARRAY(env.tdata1, RISCVCPU, RV_MAX_TRIGGERS), - VMSTATE_UINT64_ARRAY(env.tdata2, RISCVCPU, RV_MAX_TRIGGERS), - VMSTATE_UINT64_ARRAY(env.tdata3, RISCVCPU, RV_MAX_TRIGGERS), + VMSTATE_VARRAY_UINT32(env.tdata1, RISCVCPU, + env.num_triggers, 0, + vmstate_info_uint64, uint64_t), + VMSTATE_VARRAY_UINT32(env.tdata2, RISCVCPU, + env.num_triggers, 0, + vmstate_info_uint64, uint64_t), + VMSTATE_VARRAY_UINT32(env.tdata3, RISCVCPU, + env.num_triggers, 0, + vmstate_info_uint64, uint64_t), VMSTATE_END_OF_LIST() } }; --=20 2.43.0 From nobody Sun Jul 26 12:33:36 2026 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=reject dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1781702321; cv=none; d=zohomail.com; s=zohoarc; b=Darnz8SRnsP0KVtnUNdlksLKnTntXwbDG7pr520A5T31W2f6t8fPvIlXruIyNhrJpripDBRnQTkzGfUPJMkCGbqoJuaMKU3fqoYYRKaWqb83EWuU6kfZfO+NsG6AZ0rLXTlW+/9YlBdA/dfSQy2xDJ9hM5QOB0IIpAlccdtXveI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781702321; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=I1vkX42dLPWzlx1/akBQJD0lpDlJlCiCwqb90advl6Y=; b=RPblM/AiomSGDrUO786ZBi9w3zOTjn8UedYko0jzf/BL2iaeZrUuS+/zXaaQRA7qQk8CmrNaJ7XcOWXbfDwUs/1r8E4QJ9BfF4SVXE8d7dMa7SH0ff+zS5u4KLDkJXZC5oIOKydN3wflKeoNA1bVK9Xp8NW56jqOy7jEv7icajI= 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=reject dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1781702321049358.1502932431058; Wed, 17 Jun 2026 06:18:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wZq95-0006HU-54; Wed, 17 Jun 2026 09:17:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wZq93-0006Gp-3j for qemu-devel@nongnu.org; Wed, 17 Jun 2026 09:17:29 -0400 Received: from mx0b-0031df01.pphosted.com ([205.220.180.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wZq8z-0002zk-B4 for qemu-devel@nongnu.org; Wed, 17 Jun 2026 09:17:27 -0400 Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 65H8UhUa2219571 for ; Wed, 17 Jun 2026 13:17:24 GMT Received: from mail-yw1-f200.google.com (mail-yw1-f200.google.com [209.85.128.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4eueerbb5g-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Wed, 17 Jun 2026 13:17:24 +0000 (GMT) Received: by mail-yw1-f200.google.com with SMTP id 00721157ae682-7ddd34a6336so97150137b3.2 for ; Wed, 17 Jun 2026 06:17:24 -0700 (PDT) Received: from QCOM-UWl2o8bcGT.qualcomm.com ([177.170.117.62]) by smtp.gmail.com with ESMTPSA id 00721157ae682-7fcd345a5fesm44861707b3.36.2026.06.17.06.17.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2026 06:17:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= I1vkX42dLPWzlx1/akBQJD0lpDlJlCiCwqb90advl6Y=; b=eLNGZ++XAAwfCKZ3 8akkI0hqFPpTDwXtnsdD8ofkXNnNtMCW7BS2orU1tRll3xqbBuJZl4S4Bnea5xy1 DlUlH/2Ijp6sf2gNNi0qvbcwfjQiSMH/+rKUXuMY0n7+wh7FhPxVgY79dK3UsN2R aX5Deu7OqIdClULALfyqX81/2z/VYe9uAHLOMtZJ/Za/xB5Yl5J56d6QgoyhPwos 1C9Ne8OMYpQ/XrDn7vFt1aGBsOX3XYBUcZS8Y0i29wF5MDu7TIfP11IS390Zl5OZ 9aVXkdLebVBb1QuM0beFm2/tX4xPPVuStCxLk9mXWm1aTqJhXuAA+puaPP/V706f khwRNA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1781702244; x=1782307044; darn=nongnu.org; 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=I1vkX42dLPWzlx1/akBQJD0lpDlJlCiCwqb90advl6Y=; b=bDjUpe1048cV3lloVA2lQbnkIWLgsBH9LgT2SBwPIl3N3OnDHEEL9ZzcHN7qnT8jH1 UKotBhIwXB3gIjWclkkSJMxB0akYamh9Pj3EWRGr34MXDpiOgVHS/eO/dmh5sCet4iOJ XKZPnXtC2cVTkK4bM5eJF8xzfkl+Azj3VDILgqQCbFZ2KaKyQtwu/SH/OkbFMdPiaCR+ PAzprDZQ8smFC6Lw1HmSWg5XQDOQl4o1/GtNNFDj0p46yOv/mrg/A+1jwpJrUdnQ/jq3 kg6hFPnYzzo1gfCpS1tIoeCiQpostqM7tBVt7u//FFJEYvxpiY4fkM7+nkcg46Q3GffY 7phA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781702244; x=1782307044; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=I1vkX42dLPWzlx1/akBQJD0lpDlJlCiCwqb90advl6Y=; b=k+lE/2ilys42caL4LJzmd2h3QzJ8Vexl65SYfKASeu1rBNJr4ZODSp/ocR/A3c3JbX KqZU9k+5Th0OSIoiDoDtTURueTa78+7OpZJ2aJ6X2XkRbAu1OAqZ+bzCjV2dhL6pySTz Da05a+2bCa4VTU4KGCafQXU71z/nyZnvA9KVZ504OXB54z6CvqMcBIAcO9tMc6V3vmV6 Ri2v6AL8JrlXPc7vu9OakJiiyOAR2tO/U7UrQRkMPP0tgJUUkRF59NBkpOSBnUEqCi/o XZf6BZVebo48mom5gliZ1gQzlMLlm/jCmOuDrXlplQTNj2NteFfKt0L/vaahCTSbVZvn wa9g== X-Gm-Message-State: AOJu0Yy+ZUOD1Q415mpzjgJUlx42UByW+H/KuJrm/ASz8G9HHCgrbZVe H+KOgqZvQxsQRQWHoJAldza4s5OE84/Ml/gkP+TW+FGaGmm2k+nsdK/4LpH1I/+/7ZrfUEJHOBF keXsqLCVI0rOd1bjFYyMuLDClqq1IrFB/LUjxc8D/B2n8d7qdlhxr7dXr/z8awPecgg== X-Gm-Gg: AfdE7cnbTJ+s+zfXKNaWPLFxhHAze+Ivt5p8Fa8KAMZO2YA4AUm19lxTnGYRCLHTgrZ TNd3cLLScfDtLRSWkm7UnKvImEHwWt0VshI8dVxw6YH4g09n7ochF1xrO5BCTHcLVF4pUEBYM9F AEFhsuCoXO+EltxkqD15e2cyxuNw+1ICEdvGNDcyoK0tRkLl9OwMkYLO9/hqk7pgckm6UGuF5gF 0GMTs1penVuke03cCwQ0LYEQvE5iOLnccKeAV/fR+WdSOEBAnHazobhup4mb7NvB8tesFGAwSsM uVF09D6RAQBzshrW3hY2r5TYxFL691a69bNwwS0lmaWVrSPU323eFHCv0+5nqNPlv18UIxVYjKG 4yXdSs6DZbGJNS3tT+xzJqiHtWzSygAIfYTpPlDNyflpHyk6s X-Received: by 2002:a05:690c:4d01:b0:7d1:c256:b5a8 with SMTP id 00721157ae682-7fe5e39c0c8mr34761007b3.40.1781702243782; Wed, 17 Jun 2026 06:17:23 -0700 (PDT) X-Received: by 2002:a05:690c:4d01:b0:7d1:c256:b5a8 with SMTP id 00721157ae682-7fe5e39c0c8mr34760357b3.40.1781702243163; Wed, 17 Jun 2026 06:17:23 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, alistair.francis@wdc.com, liwei1518@gmail.com, zhiwei_liu@linux.alibaba.com, chao.liu.zevorn@gmail.com, Daniel Henrique Barboza , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Palmer Dabbelt Subject: [PATCH v4 3/3] target/riscv: add 'num-triggers' debug property Date: Wed, 17 Jun 2026 10:17:10 -0300 Message-ID: <20260617131710.1855353-4-daniel.barboza@oss.qualcomm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260617131710.1855353-1-daniel.barboza@oss.qualcomm.com> References: <20260617131710.1855353-1-daniel.barboza@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Info: AW1haW4tMjYwNjE3MDEyNiBTYWx0ZWRfX8Uxh2smDxhI5 MT5dX9v+fpz/M0VOzfyYoTAsrRyfascRUp+kCVmHXZXHOoMA6DRHXqrkPlt3F31U+lpClD4y+s3 3O7mWKF8da3C0v80bEsEYZGwAT+TrDM= X-Proofpoint-GUID: gMEGJvp_95mmvaRxNVAkiZ6pMoKt85N5 X-Authority-Analysis: v=2.4 cv=d4fFDxjE c=1 sm=1 tr=0 ts=6a329e64 cx=c_pps a=NMvoxGxYzVyQPkMeJjVPKg==:117 a=gdiugJE53z4H+vvYeRBHqw==:17 a=IkcTkHD0fZMA:10 a=FelO9ux0wxsA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=rJkE3RaqiGZ5pbrm-msn:22 a=EUspDBNiAAAA:8 a=JF9118EUAAAA:8 a=KJWeSTv_TiI39BqBT3cA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=kLokIza1BN8a-hAJ3hfR:22 a=xVlTc564ipvMDusKsbsT:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNjE3MDEyNiBTYWx0ZWRfX6+lpgErarnoy hHMs1sdx70dgUcyErt8eF3WIHsb7VzBC60/ehha8BedMWWKTqYgkddvhjFzV9joBIr0EfhpZFoA rKoAQM9T4/Nss482zVIpREZWmiGIQMcxK9ulGMT/IWMn0qU+/FUXHp+RcVhiQpWkPBbVlxCKLql 5m8lvFdptlW+RrvU9k8OsZdswMCgq0coGuJkRa5mgV3yZmhli51KR3pfqvMYty1xMV3G6fBboZW AfM41wJCzcbsw2Bf+2/+zQDFQ17s5+X1H2aYlbI0d3T2cBmF/9VvFXKkCPZCI8RrgCzzjKQZMGy STOoej1nbvHL/U52vEy+aC4millnxo94idjjjjhewwtScQJO6ZkDgdJCtDjay1qraIYYg7ahbpU ipFERRyC9G3dFCBNmgpt8lG82ehb4cMZEZ71LvgdfgLh5B9yGMIJqIBTB0j2WDm62OxjtCAdXsu 0dgoovCiI/Gorx0zlog== X-Proofpoint-ORIG-GUID: gMEGJvp_95mmvaRxNVAkiZ6pMoKt85N5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.125,FMLib:17.12.100.49 definitions=2026-06-17_01,2026-06-16_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 malwarescore=0 lowpriorityscore=0 phishscore=0 bulkscore=0 clxscore=1015 adultscore=0 spamscore=0 impostorscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2606150000 definitions=main-2606170126 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=lists1p.gnu.org; Received-SPF: pass client-ip=205.220.180.131; envelope-from=daniel.barboza@oss.qualcomm.com; helo=mx0b-0031df01.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, RCVD_IN_DNSWL_LOW=-0.7, 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: qemu development 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 @qualcomm.com) X-ZM-MESSAGEID: 1781702322711158500 All CPUs have the same amount of triggers: 2 triggers per hart, set via RV_MAX_TRIGGERS. This is not enough anymore: we'll have at least one future CPU that will demand more triggers per hart when implementing the RISC-V Server Ref Platform, requiring at least 11 triggers per hart. Parametrize the trigger amount using a new 'num_triggers' property. The default amount is kept at 2 for backwards compatibility. The new maximum is bumped to a generous 1024 triggers per hart, which hopefully will be enough for the foreseeable future. The property can be set in two ways: - a '.num_triggers' CPU definition flag, allowing CPUs to set a custom amount inside the CPU def in DEFINE_RISCV_CPU(); - a new 'num-triggers' user property. The user property has a higher priority than an existing '.num_triggers' CPU def setting. Assuming a hypothetical case where a CPU 'X' is defined with '.num_triggers =3D 8': - -cpu X,num-triggers=3D30 =3D> num_triggers set to 30 - -cpu X (...) =3D> num_triggers set to 8 For a CPU that doesn't set '.num_triggers': - -cpu rv64,num-triggers=3D30 =3D> num_triggers set to 30 - -cpu rv64 (...) =3D> num_triggers set to 2 Signed-off-by: Daniel Henrique Barboza Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alistair Francis --- target/riscv/cpu.c | 11 +++++++++++ target/riscv/cpu.h | 19 ++++++++++++++++++- target/riscv/debug.c | 16 ++++++++-------- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c index e7318fe9f9..e16608bbbe 100644 --- a/target/riscv/cpu.c +++ b/target/riscv/cpu.c @@ -1164,6 +1164,11 @@ static void riscv_cpu_init(Object *obj) IRQ_LOCAL_MAX + IRQ_LOCAL_GUEST_MAX); qdev_init_gpio_in_named(DEVICE(cpu), riscv_cpu_set_nmi, "riscv.cpu.rnmi", RNMI_MAX); + + if (mcc->def->num_triggers) { + env->num_triggers =3D mcc->def->num_triggers; + } + #endif /* CONFIG_USER_ONLY */ =20 cpu->user_options =3D g_hash_table_new(g_str_hash, g_str_equal); @@ -2616,6 +2621,8 @@ static const Property riscv_cpu_properties[] =3D { DEFAULT_RNMI_IRQVEC), DEFINE_PROP_UINT64("rnmi-exception-vector", RISCVCPU, env.rnmi_excpvec, DEFAULT_RNMI_EXCPVEC), + DEFINE_PROP_UINT32("num-triggers", RISCVCPU, env.num_triggers, + RV_DEFAULT_NUM_TRIGGERS), #endif =20 DEFINE_PROP_BOOL("short-isa-string", RISCVCPU, cfg.short_isa_string, f= alse), @@ -2761,6 +2768,10 @@ static void riscv_cpu_class_base_init(ObjectClass *c= , const void *data) !valid_vm_1_10_32[mcc->def->cfg.max_satp_mode]) { mcc->def->cfg.max_satp_mode =3D VM_1_10_SV32; } + + if (def->num_triggers) { + mcc->def->num_triggers =3D def->num_triggers; + } #endif } if (def->priv_spec !=3D RISCV_PROFILE_ATTR_UNUSED) { diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h index af246a56ed..bdd28d329b 100644 --- a/target/riscv/cpu.h +++ b/target/riscv/cpu.h @@ -189,7 +189,22 @@ extern RISCVCPUImpliedExtsRule *riscv_multi_ext_implie= d_rules[]; #define RV_VLEN_MAX 1024 #define RV_MAX_MHPMEVENTS 32 #define RV_MAX_MHPMCOUNTERS 32 -#define RV_MAX_TRIGGERS 2 + +/* + * The Debug 1.0 spec allows a humongous amount of triggers. Section + * "Enumeration" says: "The above algorithm reads back tselect so that + * implementations which have 2^n triggers only need to implement n + * bits of tselect.". tselect can have up to XLEN bits, so the max + * theoretical RV_MAX_TRIGGERS value is 2^XLEN. + * + * Allowing 2^XLEN triggers per hart is silly so we'll set a max to a + * modest 1024 triggers, which is way more than what we see current + * hardware use (most chips uses 2-4 triggers per hart, RISC-V Server + * Ref requires at least 11). With a 1024 max per hart we'll be set + * for a long time ... hopefully. + */ +#define RV_MAX_TRIGGERS 1024 +#define RV_DEFAULT_NUM_TRIGGERS 2 =20 FIELD(VTYPE, VLMUL, 0, 3) FIELD(VTYPE, VSEW, 3, 3) @@ -577,6 +592,8 @@ typedef struct RISCVCPUDef { RISCVCPUConfig cfg; bool bare; const RISCVCSR *custom_csrs; + /* This is just a setter for env->num_triggers. */ + uint32_t num_triggers; } RISCVCPUDef; =20 /** diff --git a/target/riscv/debug.c b/target/riscv/debug.c index 9a4910c431..ba5bc6ae13 100644 --- a/target/riscv/debug.c +++ b/target/riscv/debug.c @@ -26,6 +26,7 @@ #include "qemu/osdep.h" #include "qemu/log.h" #include "qapi/error.h" +#include "qemu/error-report.h" #include "cpu.h" #include "target/riscv/debug.h" #include "trace.h" @@ -1049,14 +1050,13 @@ void riscv_trigger_realize(CPURISCVState *env) { int i; =20 - /* - * Alloc env->tdata1/2/3, cpu_breakpoint, cpu_watchpoint and - * itrigger_timer dynamically. This is overkill now - * given that they could be static arrays with RV_MAX_TRIGGERS - * but we'll parametrize the trigger number later, i.e. the - * array length won't be static. - */ - env->num_triggers =3D RV_MAX_TRIGGERS; + if (env->num_triggers > RV_MAX_TRIGGERS) { + error_report( + "Invalid configuration: 'num-triggers' must be less than %= u", + RV_MAX_TRIGGERS); + exit(1); + } + env->tdata1 =3D g_new0(uint64_t, env->num_triggers); env->tdata2 =3D g_new0(uint64_t, env->num_triggers); env->tdata3 =3D g_new0(uint64_t, env->num_triggers); --=20 2.43.0