From nobody Mon Nov 23 04:26:17 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=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793124488; cv=none; d=zohomail.com; s=zohoarc; b=H0ScWZC4uoZ8QoTodSjiqjtZekx00pUal3n89oboi4VikdRkXNZiguDpWg/tnn9qxykSRqA8Az4/2k3zb86Z3NPNPHW2z/NbxY7jsEH+NO3jCqlTV3RGfYxtmvWphl0vIkpgQ8+21u7UbzZZP5rHl13Ww9gp4zo3+xuZXrtN7K0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793124488; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=C+PFJ3ZQTqhVffKldgeG8v1KFVYhX7lrUEcl308Tz3Y=; b=AtZQnCLYRkWAOFDZJwDT6ArAlrExdqWWN6Atu562lj4+hhTFzesuyoAH2t7TCnqYkCKhRHDpYKSgaefA7NyKXYjRzd6aoFPsjol0YJE/ksrCjz77I5ULFgjFNMPShZjUyEMI0WnZB94BMNIf5WFL6RTHBeSXPvvo2ITPqLI2LRk= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1793124488026401.58406076739516; Tue, 27 Oct 2026 11:08:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLlaN-00053H-LR; Tue, 27 Oct 2026 14:07:47 -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 1xLlaE-00051Z-Bf for qemu-devel@nongnu.org; Tue, 27 Oct 2026 14:07:39 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLlaC-0002mI-Nu for qemu-devel@nongnu.org; Tue, 27 Oct 2026 14:07:38 -0400 Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69RH0fYM2827886 for ; Tue, 27 Oct 2026 18:07:24 GMT Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hjst1j2g1-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 27 Oct 2026 18:07:24 +0000 (GMT) Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-934963b2bc0so6299585a.3 for ; Tue, 27 Oct 2026 11:07:24 -0700 (PDT) Received: from localhost.localdomain (82-67-153-177.subs.proxad.net. [82.67.153.177]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e3eb8f248sm23628440f8f.6.2026.10.27.11.07.21 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 27 Oct 2026 11:07: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= C+PFJ3ZQTqhVffKldgeG8v1KFVYhX7lrUEcl308Tz3Y=; b=pQdx4073H/QA+g7V 6iILKXsbUD1m2jErY9qIkurs0r85u2qrk5spgqC9QLB0gpk+XncjJwt+NuJSUnpk TM1HB8PleKVhYrkxXij3v+qA3x5PpGUgU/ALERx8b0vYqj7JTPw6L0jENIDsNJFr P26JmbuGj6dB7WQZhn+uz22iHZcMTpZFSD+1JUHsiIXeN2ZYdntNDgVp1C1K7ZuJ I1ByvA0okz7ruWoX5woCDGby7wtLYGY9PpMx3DUypMWaG27JTpQz2PB5r1o82/X4 ciKRJkvRa5KBtkK+pNQRVcPnp47clKydtRpCHnVV10bDJ9zUWAM5nstULarCoX+k lLLjCA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793124443; x=1793729243; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=C+PFJ3ZQTqhVffKldgeG8v1KFVYhX7lrUEcl308Tz3Y=; b=JgZVlETVTUbTMRORRjs00R7hklZ7vzacSN0iqm+tFMPLZeoD3rh8UOs9jTo1U9hasZ kQc6S95dQaIKydUuOMK/jgVfWPPRM6vq38Qnr1YFElkTuLz7Lq9UOVu8jwX0i4Ly0rhT fz3GeeEDTcFV8q2IMGYygwi88OJMiZIuyu9SO4gB8uEleN5qfyr5SJSEe24XakYqDCMR s7WoDUzGAYmpuTgqybYB68HHfRhxeBczcl9LTXa2zWLsOINhCSjw7MZCDajxQHPM2S66 wVedlzQfCDrhiCRTdm0L4Xdl8yBtGqW06JZ3J28zvMB5B7zoMEl8eeU0FUowxnV4N9ZF jjJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793124443; x=1793729243; h=content-transfer-encoding:content-type: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 :content-type; bh=C+PFJ3ZQTqhVffKldgeG8v1KFVYhX7lrUEcl308Tz3Y=; b=xSH9tRgbDQcJWn8+Ji4a7jESvsEivitKpyakrUD7K/Undi5TpPMFGubIoaMMAePIYP L+OZJClTe1qzM2JvqpTWHT7SMBCFY7xx/rfi4qqnc0KWfIJyAU8pd+ldJ80jPhvHkcHa ndLaa2+NBm2dr1/EpbF5GByF4AtcbbVw+/ItQrSUBTFg4P9lZ9pKZOKpyq85FMMZTLzM 9kT5IRH/LJiFT82V7oqO0KJ+h9INsq5RuqL8UIHpXZJXs0mnO0qO3NzDK4Tw6KAFQxRL dAOA4iq/5IKT9ZyI2qL/F+qhrzZeg75L9qcuUysNTgYCWreuAd5jqovL4uP/kk7Ctn0+ S0Dw== X-Gm-Message-State: AFq9FYJw+pBULu0Tu8+ynYF3USZG7N1G8QlmckcdiaUdHedf8q5Wo27A iy+6Q7CUiG8pjOei+CjeDnda/oZgtrukTkjPVciE5PGeE0Hq1+ylCbTOfOmfjrY0Tk7jSR7YGYN YObb+R9MLOALlxCWsKvLZJEqPbSVNntZ3vXb3DqwGwDjsWpBPDJZ6nFHP/4E5sr0WuA== X-Gm-Gg: AYBFou1jmjAIqZajMCH6R2Bl4kmggHW0+7/yAf6Bwj2J85VkQ+h4B+r3MJ9rm8GSI/J 3Rg0bo7t/YpC/D2WObagwittTLJFJ/UMcY0B0xoBsBAxwlDmSRZQlHboliaQ8AYrq1n6sRXycyr va6pCoEGT8HtYYj3CJc4cOSBfM5dxQHZTMh6GnCnho6X+HQQzaRlJPZO0zcOArSfOHTlGeUOtvy +4eWGXOdlzJiGEcH8Ohh/GAPQ2J0bc8dT6uHECvRStOoIDjrz2O0s96TWLz4/q7RBy9aSBQ1YN2 4l9NYODn6z1bhNWxOIMIPtTKZuqv+GTd4p/FWixEvxxQlD2SDeiftSeW9cv/sfXhhZuWcIDNJXg K/sxGo+70OBDXqJchtWnfZe1bwfHGLw7vjRlcLTEm/+2nQ20nUtjIQVyi X-Received: by 2002:a05:620a:444e:b0:93c:6534:d04d with SMTP id af79cd13be357-940ef93faf8mr1608718085a.35.1793124443515; Tue, 27 Oct 2026 11:07:23 -0700 (PDT) X-Received: by 2002:a05:620a:444e:b0:93c:6534:d04d with SMTP id af79cd13be357-940ef93faf8mr1608710585a.35.1793124442973; Tue, 27 Oct 2026 11:07:22 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhao Liu , Laurent Vivier , Richard Henderson , Fabiano Rosas , Paolo Bonzini Subject: [PATCH 1/2] accel/tcg: Extract icount_cpu_reset() helper Date: Tue, 27 Oct 2026 19:07:12 +0100 Message-ID: <20261027180713.2386-2-philmd@oss.qualcomm.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261027180713.2386-1-philmd@oss.qualcomm.com> References: <20261027180713.2386-1-philmd@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=HJ1WhYtv c=1 sm=1 tr=0 ts=6ae0e85c cx=c_pps a=HLyN3IcIa5EE8TELMZ618Q==:117 a=nz36NW0qrpeEijYxj/H2Ew==:17 a=IkcTkHD0fZMA:10 a=660iZSQnnn4A:10 a=M51BFTxLslgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=yOCtJkima9RkubShWh1s:22 a=EUspDBNiAAAA:8 a=jYs2RP2CEQKANlrhWQYA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=bTQJ7kPSJx9SKPbeHEYW:22 X-Proofpoint-ORIG-GUID: lFqW5RgNVc69KZXam1CyO5NMxK7UAPNb X-Proofpoint-Spam-Info: AW1haW4tMjYxMDI3MDA3MiBTYWx0ZWRfX9daHbtXJsOV2 T32uShKVJujYbreJvQR/zkwg3z8p7gjHtIC2CvvSn3Ofpw+V4TRZfLSOo1Wfo4ZXRLNFwxsvwOI cXq2zcScG2Y+ZsAREA8Bdl5wrjgTdos= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDI3MDA3MiBTYWx0ZWRfXyjpvgznaGQlj a5eq1/i2eKf2Gc8mTzdKJrg2DClPmsFpLyYCP3/sF9MuXXhlBK7jFL6kBWiL6vjHaNKGuevkbuX 6NGQuTpmDlTlbguTXDgSj0vKnHKnx3N4Q+dCc/FclXWpnJL7AZCMdN0oMxxtvLINScrdYMnnPPH RylKQkFKxOQmoBNYwcYl3AZ0K3EoppVpyVRKhnuGq5IAuZt/15fAOovtSQoR4OZgGLOxaJdsJ4V cqkc7qM6GUBkpDBskEiUephbXqxGoLGeypa4TX6WadQ6vkZ1TkoupbEiEsSKOajZx98gKaHfgLL W1wTRgR8WWbBVcw8TOo14jPY2vODmER2RpWhTXLp6PMBZpBtdrihamX8ZARTs/9Avq86HbRRARq zxk22wJqECpyHfoTlK+ZMc7TsLvuJVl1fwDTHZ2zPSCL4RA+72BC1amC+iaaXRKfVCCMIDYRxP7 utX6X5FyoHyBuY6nNeQ== X-Proofpoint-GUID: lFqW5RgNVc69KZXam1CyO5NMxK7UAPNb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-10-27_04,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 suspectscore=0 lowpriorityscore=0 impostorscore=0 adultscore=0 spamscore=0 phishscore=0 clxscore=1015 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610270072 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.168.131; envelope-from=philmd@oss.qualcomm.com; helo=mx0a-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, KHOP_DYNAMIC=0.001, 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: 1793124489702154100 Move the icount system-emulation reset code out of cpu_common_reset_hold(). Add stub for user emulation. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/exec/icount.h | 2 ++ accel/tcg/icount-common.c | 6 ++++++ hw/core/cpu-common.c | 4 ++-- stubs/icount.c | 3 +++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/exec/icount.h b/include/exec/icount.h index 7a26b40084db..e97cc4e7a426 100644 --- a/include/exec/icount.h +++ b/include/exec/icount.h @@ -43,6 +43,8 @@ extern ICountMode use_icount; */ void icount_update(CPUState *cpu); =20 +void icount_cpu_reset(CPUState *cpu); + /* get raw icount value */ int64_t icount_get_raw(void); =20 diff --git a/accel/tcg/icount-common.c b/accel/tcg/icount-common.c index b1b6c005fe71..4c8ceafc112b 100644 --- a/accel/tcg/icount-common.c +++ b/accel/tcg/icount-common.c @@ -104,6 +104,12 @@ void icount_update(CPUState *cpu) &timers_state.vm_clock_lock); } =20 +void icount_cpu_reset(CPUState *cpu) +{ + cpu->icount_extra =3D 0; + qatomic_set(&cpu->neg.icount_decr.u32, 0); +} + static int64_t icount_get_raw_locked(void) { CPUState *cpu =3D current_cpu; diff --git a/hw/core/cpu-common.c b/hw/core/cpu-common.c index 4f4c87f33a09..a18f05d26bda 100644 --- a/hw/core/cpu-common.c +++ b/hw/core/cpu-common.c @@ -19,6 +19,7 @@ */ =20 #include "qemu/osdep.h" +#include "exec/icount.h" #include "exec/cpu-common.h" #include "qapi/error.h" #include "hw/core/cpu.h" @@ -110,11 +111,10 @@ static void cpu_common_reset_hold(Object *obj, ResetT= ype type) { CPUState *cpu =3D CPU(obj); =20 + icount_cpu_reset(cpu); cpu->interrupt_request =3D 0; cpu->halted =3D cpu->start_powered_off; cpu->mem_io_pc =3D 0; - cpu->icount_extra =3D 0; - qatomic_set(&cpu->neg.icount_decr.u32, 0); cpu->neg.can_do_io =3D true; cpu->exception_index =3D -1; cpu->crash_occurred =3D false; diff --git a/stubs/icount.c b/stubs/icount.c index ceb73b4fc2ce..1d28bcf7e2bb 100644 --- a/stubs/icount.c +++ b/stubs/icount.c @@ -30,3 +30,6 @@ void icount_notify_exit(void) { abort(); } +void icount_cpu_reset(CPUState *cpu) +{ +} --=20 2.55.0 From nobody Mon Nov 23 04:26:17 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=none dis=none) header.from=oss.qualcomm.com ARC-Seal: i=1; a=rsa-sha256; t=1793124499; cv=none; d=zohomail.com; s=zohoarc; b=natqsV6o9Rl6aIKEv30v+aczncLNWFZiigftszjpwhaqVnzHs8aBMQ7eHAv3eG4fke8mFRKLWcZ0rHkwV6aNDogeNr5wdMRNJXxZrJAQ2G/mmFJnTjRC8+0Qn5JgxqMXj1Z0Y5QvDfUZd3+Aw+7DQd9AVcW7xGsWDfCFVs9kkSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1793124499; 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:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=aanXSZ4ZWlw6/SJLjxWp0fl/adfElI0z2o4nUFLDfno=; b=UW3JyPcyLuTJvzMI+27A3guPZvcBkS7x7MGfmSmgQ6EPgBSfRSVLXBbZwfejGQ+k0+dv7s5CYChdBZA/TiSG3MTNpcG2IsHvlh4dkoPNKE6DrXTu1ZgzO2k24AZUY8v8OQEa7NwUreSHOfrlyAQh6nr/BXlOu+7OgaEJkkJXjJI= 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 lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 179312449966340.377976563179004; Tue, 27 Oct 2026 11:08:19 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xLlaQ-000554-51; Tue, 27 Oct 2026 14:07:50 -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 1xLlaM-000541-TS for qemu-devel@nongnu.org; Tue, 27 Oct 2026 14:07:47 -0400 Received: from mx0a-0031df01.pphosted.com ([205.220.168.131]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xLlaK-0002n2-LA for qemu-devel@nongnu.org; Tue, 27 Oct 2026 14:07:46 -0400 Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 69RH04Kq3861779 for ; Tue, 27 Oct 2026 18:07:34 GMT Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4hjyjpre1c-1 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NOT) for ; Tue, 27 Oct 2026 18:07:32 +0000 (GMT) Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-93cb98809caso9057285a.1 for ; Tue, 27 Oct 2026 11:07:32 -0700 (PDT) Received: from localhost.localdomain (82-67-153-177.subs.proxad.net. [82.67.153.177]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-48e3ebd48eesm24174993f8f.30.2026.10.27.11.07.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 27 Oct 2026 11:07:30 -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= aanXSZ4ZWlw6/SJLjxWp0fl/adfElI0z2o4nUFLDfno=; b=MEG05x8NgVNpUf/e fqBiJ0c9Dolo8M74If7S4KPQ/ZqblOXL20G/eH8WC1/j/y0xZVbX+iT85isOqj57 wtEBFDiSxRv4kRx3lYqPqiGKxxrNMGVV8HPp0QhCwyEofZen0X7awQE5QKxxPsJ5 LtF/XfTUMisFfSJlLRFmi6cgou7CCj0nYdN+McMrAPW0VdPrhFi7Uy4v0rA0NKjl eCQ4IU39oQqfTzWHRTfZls8CRaklNXMXYNLpZujtrcnIF1RfXaLh2blawFuQaVTx rQglnV172aGq+aFa+8ocOXDdjeOY8le0D86j18mChxfSUfGC5ybK+WYaUcvSkwtH 6XVTZw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss.qualcomm.com; s=google; t=1793124451; x=1793729251; darn=nongnu.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=aanXSZ4ZWlw6/SJLjxWp0fl/adfElI0z2o4nUFLDfno=; b=kEr6cbo84mZB9e7sXJJfjMWQ9kNj3b0ie/AgjjUIj8fjQwW3igxdpFd+UV6iWXe2CD rn04YvWSvxytooBrgofnHPfmtaQ1ZqyOTyutkEC2nrdxiErb4gbw+40VpW1QUG1+p7LE 1gKJosDpsyD3LK3c3RX2cYrNV7C1ntx+2QqPwP2P9HDP44w40W3hoWNKOw0SyRLlnHfp FBfUzHUgFKtd2WDGf3xYInTT9letfIKS/6YYGLznbNxu7JuSZYbHxaaDO0/rCtnmL84f LO3bhFZ5DDW5Eoimol8EA3JSz0L4wbbybpvOYee9+DsQjgFNkxPSwdWzh8/QIwtksGJu cBiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793124451; x=1793729251; h=content-transfer-encoding:content-type: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 :content-type; bh=aanXSZ4ZWlw6/SJLjxWp0fl/adfElI0z2o4nUFLDfno=; b=vZxgEVlmTrH082wrwPbYW0ElXvLmecXS1ogTQHIvP61O8z62hECDs/P4qNFCZiPrT+ QAAgzMDx70EGgz7eFcjdV0+fSNLaRuKRD9lrpN2FY1wPZs2O/in0DrqPJ52L1ScyxSoi A6vhmNmqHfe8H0LHkOxoFwOVGS1iAcXekVGFSIE2aXnfL/fVPHnCzPbka2UxKC0qUF7R eE30skPnt1NZjI5ISG4ow9cRb6dY3ttaPRRHfHXifL66z3qoi5P49PGm1ymeNlP2Zgd1 LdjUcD+MthLaFMRDvx96SdUCzS9/iEE6DW/66OF4PEKRu68nxe+3dnGEY8p34/0SLYRd Lvjw== X-Gm-Message-State: AFq9FYK8A6t3jQunULWDJ278tti5Uvge1loCtp2mK1ZHDwkHB8WJnrUC OTbAafEBxog+4oIla6emmCgOKZFk4L8xkkM/ic5rpZBvhLSxKp++feH1slF78j4jUUQFE9mr93j qoe/S09Js3bmmMBH8njLyl1gURx/svVHrXImrCw1rMoztg/1RcWKXbvjnzrEFuUeM1w== X-Gm-Gg: AYBFou1JcWUAJTu7lE0iK1no9E9ZevaP8+69gdpJWaQnY+bYdTEbhqKU2LAPzSUiA+R fmY5tlM88+k1vQ3yxu7yVHXl1NHiseYoqFMlCQW65kXM/ogUap6rED8VxzVdXNlZ+Tu6cCsMVs1 HG2MAQWByVbbtgz8wUWr5ZXEMoWbFZutX9OATMwJVue0lyxm9HgL/gjRQiWPoTIYEueT9luLChy L1DvEizXqLb/0Yw2AVO8gfM14IoNAEfjnPZVsk1y7rqoSABYURFphGFqZbpilmg4nsmdpLGR6NO B8RE4fskOEAsiHhEyYUUV50kqzBv4sKn6F6IAixW0Upo95c2GlwvO7NGuC/WeVDx0lXV5kAnQWY s/A6FdYS5Rxp1BD3mPNOj6eq8tiWv8YuYawoIENaRBS8iww4ZLsNk1V+Y X-Received: by 2002:a05:620a:440d:b0:93f:362a:a893 with SMTP id af79cd13be357-940ef90a714mr1587395885a.50.1793124451400; Tue, 27 Oct 2026 11:07:31 -0700 (PDT) X-Received: by 2002:a05:620a:440d:b0:93f:362a:a893 with SMTP id af79cd13be357-940ef90a714mr1587387885a.50.1793124450721; Tue, 27 Oct 2026 11:07:30 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhao Liu , Laurent Vivier , Richard Henderson , Fabiano Rosas , Paolo Bonzini Subject: [PATCH 2/2] accel/tcg: Fix icount accounting on CPU reset Date: Tue, 27 Oct 2026 19:07:13 +0100 Message-ID: <20261027180713.2386-3-philmd@oss.qualcomm.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261027180713.2386-1-philmd@oss.qualcomm.com> References: <20261027180713.2386-1-philmd@oss.qualcomm.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMDI3MDA3MiBTYWx0ZWRfX7Q8CHP/itgRP myg2X2LfwO/roIQBvPco22+Zo8kSgqvBoDR+wOSteGFANlN/HkHP/VGDAidpg9B0t5XqbdgUuHr U+Nx2gbfdHM/5jGV0FWr0SNDg82KoaWK38340OoiHlXpd5h4D9KSsw+DuQaIeO8meWNh36IGbXF ChSAowDIlFEBEcv0ppGtzct1DYKp+SxqCfX+tdpl1YlfBQMrMRIuhk/1Y60+6H4jXIEIgKHFfmf Q1g5aNN3Q8QxoFYSHRYQ9CMy070r3HQ7EnLcCBD5IW5uEhJx8A8mfwIfCl9b76Lp3eeNkPv3mlF CbHp5pqkPLh7/v3NV0b20J8FUtsdFoS9lkBz6CCZ0x5pLwlevcySyfKvDCsXemSMOS2BsGRtmk4 dZIAtoX7dsB/L+nD1hkFRWukwj7JZtPfXrl47F1i48mD8WXHaonJN3U0Y0MxWdow7TkqaHOD8Ow wXHFjEuRkkSrInJ6dRA== X-Proofpoint-ORIG-GUID: KWzRepRkJ48e0bHCwxNZ5ETNI2iuqxYY X-Proofpoint-GUID: KWzRepRkJ48e0bHCwxNZ5ETNI2iuqxYY X-Proofpoint-Spam-Info: AW1haW4tMjYxMDI3MDA3MiBTYWx0ZWRfX5Dezq/XPJhNx QudMsjSf6rOhKmSxi5DRjq90SKF4frG3/DoGqKYOHUVTx9HuMV8DXkSyn4jIJPQ2sklgNFlbLPf KFEPuvba9uveB5QPAj9YmkWNLgLxWNc= X-Authority-Analysis: v=2.4 cv=JodkP84C c=1 sm=1 tr=0 ts=6ae0e864 cx=c_pps a=HLyN3IcIa5EE8TELMZ618Q==:117 a=nz36NW0qrpeEijYxj/H2Ew==:17 a=IkcTkHD0fZMA:10 a=660iZSQnnn4A:10 a=M51BFTxLslgA:10 a=s4-Qcg_JpJYA:10 a=VkNPw1HP01LnGYTKEx00:22 a=u7WPNUs3qKkmUXheDGA7:22 a=eoimf2acIAo5FJnRuUoq:22 a=EUspDBNiAAAA:8 a=YNFDnrtNBzGGhpLi9QgA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=O8hF6Hzn-FEA:10 a=bTQJ7kPSJx9SKPbeHEYW:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-10-27_04,2026-10-21_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 clxscore=1015 malwarescore=0 bulkscore=0 suspectscore=0 priorityscore=1501 spamscore=0 adultscore=0 lowpriorityscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2610190000 definitions=main-2610270072 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.168.131; envelope-from=philmd@oss.qualcomm.com; helo=mx0a-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, KHOP_DYNAMIC=0.001, 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: 1793124500761158500 A CPU reset from cpu_exec() clears the remaining icount budget, causing it to be counted as executed and advancing virtual time. x86 INIT exposes this as a large TSC jump during AP startup. Account executed instructions before reset and discard the unused budget. Add an x86 qtest covering INIT/SIPI through x2APIC. AI-used-for: qtest reproducer Fixes: e4cd96571f00 ("cpus: don't credit executed instructions before they = have run") Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- accel/tcg/icount-common.c | 10 +++ tests/qtest/icount-x86-test.c | 119 ++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 + 3 files changed, 131 insertions(+) create mode 100644 tests/qtest/icount-x86-test.c diff --git a/accel/tcg/icount-common.c b/accel/tcg/icount-common.c index 4c8ceafc112b..45aadf1416d9 100644 --- a/accel/tcg/icount-common.c +++ b/accel/tcg/icount-common.c @@ -106,6 +106,16 @@ void icount_update(CPUState *cpu) =20 void icount_cpu_reset(CPUState *cpu) { + if (qemu_cpu_is_self(cpu) + && qatomic_read(&cpu->running) + && cpu->icount_budget) { + /* + * Account the instructions executed so far and discard the + * unused part of the current budget before the counters are clear= ed. + */ + icount_update(cpu); + cpu->icount_budget =3D 0; + } cpu->icount_extra =3D 0; qatomic_set(&cpu->neg.icount_decr.u32, 0); } diff --git a/tests/qtest/icount-x86-test.c b/tests/qtest/icount-x86-test.c new file mode 100644 index 000000000000..1138a7535e7c --- /dev/null +++ b/tests/qtest/icount-x86-test.c @@ -0,0 +1,119 @@ +/* + * QTest testcase for TCG instruction counting. + * + * Copyright Qualcomm Innovation Center, Inc. All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "libqtest.h" + +#define AP_VECTOR 0x01 +#define DONE_ADDR 0x50c +#define TSC0_ADDR 0x504 +#define TSC1_ADDR 0x508 +#define ITER_ADDR 0x510 +#define AP_FLAG_ADDR 0x600 + +/* + * The BSP reads the TSC, sends INIT and SIPI to the AP and spins until + * the AP sets a flag, counting iterations. The AP then halts. + */ +static const uint8_t x86_init_sector[] =3D { + /* mov $0, %ax; mov %ax, %ds */ + 0xb8, 0x00, 0x00, 0x8e, 0xd8, + /* AP code at AP_VECTOR << 12: movb $1, flag; cli; 1: hlt; jmp 1b */ + 0xc7, 0x06, 0x00, 0x10, 0xc6, 0x06, + 0xc7, 0x06, 0x02, 0x10, AP_FLAG_ADDR & 0xff, AP_FLAG_ADDR >> 8, + 0xc7, 0x06, 0x04, 0x10, 0x01, 0xfa, + 0xc7, 0x06, 0x06, 0x10, 0xf4, 0xeb, + 0xc6, 0x06, 0x08, 0x10, 0xfd, + /* mov $MSR_IA32_APICBASE, %ecx; rdmsr; or $EXTD, %eax; wrmsr */ + 0x66, 0xb9, 0x1b, 0x00, 0x00, 0x00, 0x0f, 0x32, + 0x66, 0x0d, 0x00, 0x04, 0x00, 0x00, 0x0f, 0x30, + /* xor %esi, %esi; rdtsc; mov %eax, tsc0 */ + 0x66, 0x31, 0xf6, + 0x0f, 0x31, 0x66, 0xa3, TSC0_ADDR & 0xff, TSC0_ADDR >> 8, + /* mov $ICR, %ecx; mov $1, %edx; INIT, then SIPI */ + 0x66, 0xb9, 0x30, 0x08, 0x00, 0x00, + 0x66, 0xba, 0x01, 0x00, 0x00, 0x00, + 0x66, 0xb8, 0x00, 0x45, 0x00, 0x00, 0x0f, 0x30, + 0x66, 0xb8, AP_VECTOR, 0x46, 0x00, 0x00, 0x0f, 0x30, + /* 1: inc %esi; cmpb $0, flag; je 1b: three instructions */ + 0x66, 0x46, + 0x80, 0x3e, AP_FLAG_ADDR & 0xff, AP_FLAG_ADDR >> 8, 0x00, + 0x74, 0xf7, + /* rdtsc; mov %eax, tsc1; mov %esi, iterations; done =3D 1 */ + 0x0f, 0x31, 0x66, 0xa3, TSC1_ADDR & 0xff, TSC1_ADDR >> 8, + 0x66, 0x89, 0x36, ITER_ADDR & 0xff, ITER_ADDR >> 8, + 0xc6, 0x06, DONE_ADDR & 0xff, DONE_ADDR >> 8, 0x01, + /* cli; 1: hlt; jmp 1b */ + 0xfa, 0xf4, 0xeb, 0xfd, +}; + +static char *write_boot_disk(void) +{ + size_t image_size =3D 0x7e000; + g_autofree uint8_t *image =3D g_malloc0(image_size); + char *path =3D g_strdup("/tmp/qemu-icount-XXXXXX"); + ssize_t written; + int fd; + + memcpy(image, x86_init_sector, sizeof(x86_init_sector)); + image[0x1fe] =3D 0x55; + image[0x1ff] =3D 0xaa; + + fd =3D mkstemp(path); + g_assert_cmpint(fd, >=3D, 0); + written =3D write(fd, image, image_size); + close(fd); + g_assert_cmpint(written, =3D=3D, image_size); + return path; +} + +static void wait_for_done(QTestState *qts) +{ + for (unsigned i =3D 0; i < 5000; i++) { + if (qtest_readb(qts, DONE_ADDR)) { + return; + } + g_usleep(1000); + } + g_assert_not_reached(); +} + +static void test_x86_pc_x2apic_fdc(void) +{ + g_autofree char *disk =3D write_boot_disk(); + QTestState *qts; + uint32_t iterations; + uint32_t delta; + + qts =3D qtest_initf("-M pc -m 16M -smp 2 -accel tcg -icount shift=3D0 " + "-cpu max,x2apic=3Don,tsc-frequency=3D1000000000 " + "-drive if=3Dfloppy,format=3Draw,file=3D%s", disk); + wait_for_done(qts); + + delta =3D qtest_readl(qts, TSC1_ADDR) - qtest_readl(qts, TSC0_ADDR); + iterations =3D qtest_readl(qts, ITER_ADDR); + g_test_message("TSC delta %u, %u iterations", delta, iterations); + g_assert_cmpuint(iterations, >, 0); + g_assert_cmpuint(delta, >=3D, 3 * iterations); + g_assert_cmpuint(delta, <=3D, 3 * iterations + 32); + + qtest_quit(qts); + unlink(disk); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + + if (qtest_has_accel("tcg") && qtest_has_machine("pc")) { + qtest_add_func("/icount/x86-pc-x2apic-fdc", + test_x86_pc_x2apic_fdc); + } + + return g_test_run(); +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index 46685d6d46fd..d7ae09313e32 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -57,6 +57,8 @@ qtests_filter =3D \ (get_option('default_devices') and host_os !=3D 'windows' ? ['test-filte= r-redirector'] : []) =20 qtests_i386 =3D \ + (config_all_devices.has_key('CONFIG_I440FX') and + config_all_devices.has_key('CONFIG_FDC_ISA') ? ['icount-x86-test'] : []= ) + \ (slirp.found() ? ['pxe-test'] : []) + \ qtests_filter + \ (config_all_devices.has_key('CONFIG_ACPI_VMGENID') ? ['vmgenid-test'] : = []) + \ --=20 2.55.0