From nobody Wed Dec 17 15:34:26 2025 Received: from mx1.zhaoxin.com (MX1.ZHAOXIN.COM [210.0.225.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 01BDE221710 for ; Mon, 17 Mar 2025 09:41:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.0.225.12 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742204479; cv=none; b=KdYp3CtqiAgKtseLJ+LNPjrIJHL7Na5swZgms6nFWvaqgNxrK4QIyLvoPXKRRWtg9Rf6Ayp4bnHVS1DIXTmZjnoh+VVPbUSClCbDRm1OBgobjoWRBj4kq9V6EoSFD+7tCqGiFxddOMkkOm6/7HXUKsd+Yd/jVUVePpOhH1C3lGE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742204479; c=relaxed/simple; bh=H4siteXWed7GW9piyVqsqPjXCiIV2tIw/PyQTp4yIaU=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=b6dv3wRaz4taNC3vE8ZQaiRHL/4Dyd4PaWA8LAP5I/iFLuMKw6+JSNeXk8vkP3kRI+jl5TLh8HKagqd6WfW9gMj69KI9VdpxsIrbvEP8NQ+3XgMXVe2S946t6cwaY27/2qbcK0tQHut6/7GrtnUg276wtYfZ7YmektRRglkKGWs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zhaoxin.com; spf=pass smtp.mailfrom=zhaoxin.com; arc=none smtp.client-ip=210.0.225.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=zhaoxin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zhaoxin.com X-ASG-Debug-ID: 1742203375-086e236018216fa0001-xx1T2L Received: from ZXSHMBX1.zhaoxin.com (ZXSHMBX1.zhaoxin.com [10.28.252.163]) by mx1.zhaoxin.com with ESMTP id bApEZBNfsL8tVL9C (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Mon, 17 Mar 2025 17:22:55 +0800 (CST) X-Barracuda-Envelope-From: LiamNi-oc@zhaoxin.com X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.163 Received: from ZXSHMBX2.zhaoxin.com (10.28.252.164) by ZXSHMBX1.zhaoxin.com (10.28.252.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.44; Mon, 17 Mar 2025 17:22:55 +0800 Received: from ZXSHMBX2.zhaoxin.com ([fe80::4dfc:4f6a:c0cf:4298]) by ZXSHMBX2.zhaoxin.com ([fe80::4dfc:4f6a:c0cf:4298%4]) with mapi id 15.01.2507.044; Mon, 17 Mar 2025 17:22:55 +0800 X-Barracuda-RBL-Trusted-Forwarder: 10.28.252.163 Received: from aa-VirtualBox.zhaoxin.com (10.28.64.121) by ZXBJMBX02.zhaoxin.com (10.29.252.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.44; Mon, 17 Mar 2025 17:19:17 +0800 From: Liam Ni To: , , CC: , , , , , , , , , , , Subject: [PATCH] KVM: x86:Cancel hrtimer in the process of saving PIT state to reduce the performance overhead caused by hrtimer during guest stop. Date: Mon, 17 Mar 2025 17:19:17 +0800 X-ASG-Orig-Subj: [PATCH] KVM: x86:Cancel hrtimer in the process of saving PIT state to reduce the performance overhead caused by hrtimer during guest stop. Message-ID: <20250317091917.72477-1-liamni-oc@zhaoxin.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: zxbjmbx1.zhaoxin.com (10.29.252.163) To ZXBJMBX02.zhaoxin.com (10.29.252.6) X-Moderation-Data: 3/17/2025 5:22:54 PM X-Barracuda-Connect: ZXSHMBX1.zhaoxin.com[10.28.252.163] X-Barracuda-Start-Time: 1742203375 X-Barracuda-Encrypted: ECDHE-RSA-AES128-GCM-SHA256 X-Barracuda-URL: https://10.28.252.35:4443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at zhaoxin.com X-Barracuda-Scan-Msg-Size: 1876 X-Barracuda-BRTS-Status: 1 X-Barracuda-Bayes: INNOCENT GLOBAL 0.0000 1.0000 -2.0210 X-Barracuda-Spam-Score: -2.02 X-Barracuda-Spam-Status: No, SCORE=-2.02 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.138618 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- Content-Type: text/plain; charset="utf-8" When using the dump-guest-memory command in QEMU to dump the virtual machine's memory,the virtual machine will be paused for a period of time.If the guest (i.e., UEFI) uses the PIT as the system clock,it will be observed that the HRTIMER used by the PIT continues to run during the guest stop process, imposing an additional burden on the system. Moreover, during the guest restart process,the previously established HRTIMER will be canceled,and the accumulated timer events will be flushed.However, before the old HRTIMER is canceled,the accumulated timer events will "surreptitiously" inject interrupts into the guest. SO during the process of saving the KVM PIT state, the HRTIMER need to be canceled to reduce the performance overhead caused by HRTIMER during the guest stop process. i.e. if guest Signed-off-by: Liam Ni --- arch/x86/kvm/x86.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 045c61cc7e54..75355b315aca 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6405,6 +6405,8 @@ static int kvm_vm_ioctl_get_pit(struct kvm *kvm, stru= ct kvm_pit_state *ps) =20 mutex_lock(&kps->lock); memcpy(ps, &kps->channels, sizeof(*ps)); + hrtimer_cancel(&kvm->arch.vpit->pit_state.timer); + kthread_flush_work(&kvm->arch.vpit->expired); mutex_unlock(&kps->lock); return 0; } @@ -6428,6 +6430,8 @@ static int kvm_vm_ioctl_get_pit2(struct kvm *kvm, str= uct kvm_pit_state2 *ps) memcpy(ps->channels, &kvm->arch.vpit->pit_state.channels, sizeof(ps->channels)); ps->flags =3D kvm->arch.vpit->pit_state.flags; + hrtimer_cancel(&kvm->arch.vpit->pit_state.timer); + kthread_flush_work(&kvm->arch.vpit->expired); mutex_unlock(&kvm->arch.vpit->pit_state.lock); memset(&ps->reserved, 0, sizeof(ps->reserved)); return 0; --=20 2.25.1