From nobody Sun Apr 12 05:51:32 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1771100392; cv=none; d=zohomail.com; s=zohoarc; b=f/sL3qy8D/s7BAQj550vXECSgMxwwy8KSnGY/a5JTn092ApQdcmQBCDGJ6DVdQYbaP98z6arN0yUONIfhtXWpjoUf8ZmhMstQzV9YWu7OVBQMiGhl10zm1IiaVU77g1m1cFtQb9q0ZtOSriqpIFw6w/6fIMw0uAfzxvVx4LSgfM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771100392; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From: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=xYWEyjpYVY2l7pzkthPd8PINyDJVvlVJRdS43y6R8B0=; b=conmz+LYeFTdYMGrrb6czeB1KUAWXkIOvgQr3lLe49E+PNPJCe6aLfbMlDIYb8zAB3PV26nrghFniPuyxiOuWFf0gn1xrutOzmREZdmcGm3iJoDqRY3pg7Z02SrbNkO6l2DM+/1Ub7BqiN7DpGCVlGkOr5dUEKFSXng1wqjgVrk= 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 1771100392130679.7335881954249; Sat, 14 Feb 2026 12:19:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vrM6j-0004eC-Tb; Sat, 14 Feb 2026 15:19:13 -0500 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 1vrKw3-0003Iz-65 for qemu-devel@nongnu.org; Sat, 14 Feb 2026 14:04:07 -0500 Received: from mail-ot1-x32a.google.com ([2607:f8b0:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vrKw1-00042X-Mr for qemu-devel@nongnu.org; Sat, 14 Feb 2026 14:04:06 -0500 Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-7d195166b2cso1377607a34.3 for ; Sat, 14 Feb 2026 11:04:04 -0800 (PST) Received: from localhost.localdomain ([47.227.2.18]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-7d4a76e1e59sm8853025a34.17.2026.02.14.11.04.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Feb 2026 11:04:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771095843; x=1771700643; darn=nongnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xYWEyjpYVY2l7pzkthPd8PINyDJVvlVJRdS43y6R8B0=; b=COeD+XbZYPHOVhAM6/y+rYJ2HuKP280ICxVZHz3MysEqqaatsHNa+77VK9LqIW1Ryh DuI0gEX5Wwa16CofRE+zftb4Gw0KcluXq2hW/KCVgzLLMc6BMIAadmJYbusay+AItfCs S1wFcTlU/RU96sDw6Febx5vLJ7mx4E5PoL6tfwzGVXaVJPUgW6fFrS9+c0Rs/TV9QJLG i8DlKHn0X00u5D4iZYTUBBqIpWE+wiZnzOrV7dnAmvXrU/zYlCLT6EzsgiUWhj8LWMZq p42Ts/7KKXwNx7gDaGuhcC2B/00e6vtEKsJktEJIRiAibOeCjHWo64g7uzNvWW6rJHY/ GcDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771095843; x=1771700643; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=xYWEyjpYVY2l7pzkthPd8PINyDJVvlVJRdS43y6R8B0=; b=kaNGvxi+brhX4BPFcyxj3DcdfFPqFz+GGwk2/HUa6O2eviML55gQ2a92Cqo0j8nYuC QNFi161ndTy8noTOotX9X7p0cwXNLpJg0+cXIY7f2pUu0BwhYfBHBlyHCw2NpnydAyvT esbK8ObaY2VJyITn1QhDDY5OjwpDhSW6W9o6G8PAQNwZsqaE7D90r7ujSnvFyTBVXNlV q+vYrqXv0oeDrgJPxroNMTWT7BZvDh4ZO0xxzW/cjMzVaQ6ctv6XcPeQjTF7hv2y7QAw JFWCZnTu9ceXGFD+Gu21cSaX2CNiMTb6vVUk0kQItGyMCqWquLvnlAEnNWzNBY4uxEHv E4/Q== X-Gm-Message-State: AOJu0YwonuoBf30y/asQJkO3tGDXXAlkinAWdUqIZOLz1C6YdS5+Kyg6 9kzJnRkX9yGPhsLX4ULgpqSKlNCCrbEMDPHVOYgBuhJtPbcaZ7IpbBYVGJt69SjF X-Gm-Gg: AZuq6aLG0OKlVWip5+sAtrslo4pYhxa5WSU4pu28vFuW3fiBiRSOX0TdVNpg6SqldkN 8Qx36c+Jpj71NaFb1GXxG6A6bthQisd2Q6FvnoP5NW4PmPgJRLoPWYTDt6/mvKFPGpxx4X9Xeme NH4jpFqddmM81vRy6AuzD9LmmMasBFAsO0Bsm8Frwgns0MGAklMkG5YKpQ0AdiV8dgxKJTx4XkX vakaCItM+Y/lRNciPwpF/N2h2XXd9XuvnBNVwIYwhwjPC36P8MI1ujLDNwNVzlmAfFqEHcp3Tuz PnCnZfmb5K60VLrcMWajyND9x0oylcKCRynIoEiMUuskOukaZebi/WM+CCh4EpCyaKcYhRZlB62 O0ARwNEJRjUlUVa7cVNFXNKcnT3oP+DZ+5wvCIXcccM3XNRfE1eENcofnWLqDcNpmuAy2d23vKK XOheZmdIM14BYMGkUU8blRvLUuGTW56ciL6IgNHYU= X-Received: by 2002:a05:6830:240a:b0:7d1:569d:ce7b with SMTP id 46e09a7af769-7d4c31cc549mr3704142a34.29.1771095842831; Sat, 14 Feb 2026 11:04:02 -0800 (PST) From: ChaseKnowlden To: qemu-devel@nongnu.org Cc: Marcelo Tosatti , kvm@vger.kernel.org, Paolo Bonzini , ChaseKnowlden , GitHub Copilot , Copilot <223556219+Copilot@users.noreply.github.com> Subject: [PATCH] target/i386/kvm: Reset PMU state in kvm_init_pmu_info Date: Sat, 14 Feb 2026 14:03:53 -0500 Message-ID: <20260214190353.29337-1-haroldknowlden@gmail.com> X-Mailer: git-send-email 2.53.0 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::32a; envelope-from=haroldknowlden@gmail.com; helo=mail-ot1-x32a.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-Mailman-Approved-At: Sat, 14 Feb 2026 15:19:10 -0500 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 @gmail.com) X-ZM-MESSAGEID: 1771100394351158500 Content-Type: text/plain; charset="utf-8" The static variables pmu_version, num_pmu_gp_counters, and num_pmu_fixed_counters persist across different VCPU initializations. When kvm_init_pmu_info() returns early (e.g., when PMU is disabled or there's a vendor mismatch), these variables retain stale values from previous initializations. This causes crashes during guest reboots, particularly with Windows XP, when kvm_put_msrs() attempts to write PMU MSRs based on the stale pmu_version value for a CPU that doesn't actually support PMU. Fix this by resetting the PMU state variables to 0 at the start of kvm_init_pmu_info() to ensure clean initialization for each VCPU. Fixes: 4c7f05232c ("target/i386/kvm: reset AMD PMU registers during VM rese= t") Signed-off-by: GitHub Copilot Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- target/i386/kvm/kvm.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index 9f1a4d4cbb..c636f1f487 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -2193,6 +2193,14 @@ static void kvm_init_pmu_info(struct kvm_cpuid2 *cpu= id, X86CPU *cpu) { CPUX86State *env =3D &cpu->env; =20 + /* + * Reset PMU state to avoid stale values from previous VCPU + * initializations affecting subsequent ones. + */ + pmu_version =3D 0; + num_pmu_gp_counters =3D 0; + num_pmu_fixed_counters =3D 0; + /* * If KVM_CAP_PMU_CAPABILITY is not supported, there is no way to * disable the AMD PMU virtualization. --=20 2.53.0