From patchwork Thu Oct 31 15:14:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nam Cao X-Patchwork-Id: 13859081 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A86DCE6B240 for ; Fri, 1 Nov 2024 10:08:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A9AD710E970; Fri, 1 Nov 2024 10:08:03 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; secure) header.d=linutronix.de header.i=@linutronix.de header.b="D8R3JnkO"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="vSyDZ/mN"; dkim-atps=neutral Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1B13410E079 for ; Thu, 31 Oct 2024 15:15:04 +0000 (UTC) From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1730387702; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HdVqhgFUx4wGhiyBVzB1j0RExe8nGmkufQErz8orPxA=; b=D8R3JnkO+m2baGKosWMEPCCgHEh93eEj3i5YM9IrL8ArYpE8sw2m3aMJr+wEoCSXY8Sk0o cNAwkYpIWaFLG/Hq2XJiVUcS+2TwzoEBxaJdnGTgTdUNaZDYPxCUahyT1R1Q2ZLKgAtlkC RGS4x58PXmjWRlEO06mYDbfjn42Bl5gCV5yLqmk+XU+l7pzFjdQcD1DB4hvBdhkbxvKYVn VQIs9hdbp/4lysS0E9Lr73R3hrjyUE0TZ1qUF3uy/S4GxCdrvN8y8ONJx8mE8TcNJpaftx o+H+v+lYJ5bnvSf7068cGQ9ReuPpyPFB2jhD2I6tEYa4wi9D8UuYsg7tL5wujQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1730387702; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HdVqhgFUx4wGhiyBVzB1j0RExe8nGmkufQErz8orPxA=; b=vSyDZ/mNZsHFwmAZ5X6uDDFZnl5blvdtESX/4yICVSJ/nHMJu3Ss4nFWwbP39h1ewJkXLG oKAz3ELATfAAFmAA== To: Anna-Maria Behnsen , Frederic Weisbecker , Thomas Gleixner , Andreas Hindborg , Alice Ryhl , Miguel Ojeda , Kees Cook , linux-kernel@vger.kernel.org Cc: Jani Nikula , intel-gfx@lists.freedesktop.org, Sean Christopherson , Paolo Bonzini , x86@kernel.org, Jakub Kicinski , Kalle Valo , Jens Axboe , Christian Brauner , Peter Zijlstra , John Stultz , Nam Cao , Oliver Hartkopp , kvm@vger.kernel.org Subject: [RESEND PATCH v2 03/19] KVM: x86/xen: Initialize hrtimer in kvm_xen_init_vcpu() Date: Thu, 31 Oct 2024 16:14:17 +0100 Message-Id: <9c33c7224d97d08f4fa30d3cc8687981c1d3e953.1730386209.git.namcao@linutronix.de> In-Reply-To: References: MIME-Version: 1.0 X-Mailman-Approved-At: Fri, 01 Nov 2024 10:08:01 +0000 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" The hrtimer is initialized in the KVM_XEN_VCPU_SET_ATTR ioctl. That caused problem in the past, because the hrtimer can be initialized multiple times, which was fixed by commit af735db31285 ("KVM: x86/xen: Initialize Xen timer only once"). This commit avoids initializing the timer multiple times by checking the field 'function' of struct hrtimer to determine if it has already been initialized. This is not required and in the way to make the function field private. Move the hrtimer initialization into kvm_xen_init_vcpu() so that it will only be initialized once. Signed-off-by: Nam Cao Acked-by: Sean Christopherson Cc: Paolo Bonzini Cc: x86@kernel.org Cc: kvm@vger.kernel.org --- arch/x86/kvm/xen.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c index 622fe24da910..a909b817b9c0 100644 --- a/arch/x86/kvm/xen.c +++ b/arch/x86/kvm/xen.c @@ -263,13 +263,6 @@ static void kvm_xen_stop_timer(struct kvm_vcpu *vcpu) atomic_set(&vcpu->arch.xen.timer_pending, 0); } -static void kvm_xen_init_timer(struct kvm_vcpu *vcpu) -{ - hrtimer_init(&vcpu->arch.xen.timer, CLOCK_MONOTONIC, - HRTIMER_MODE_ABS_HARD); - vcpu->arch.xen.timer.function = xen_timer_callback; -} - static void kvm_xen_update_runstate_guest(struct kvm_vcpu *v, bool atomic) { struct kvm_vcpu_xen *vx = &v->arch.xen; @@ -1070,9 +1063,6 @@ int kvm_xen_vcpu_set_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data) break; } - if (!vcpu->arch.xen.timer.function) - kvm_xen_init_timer(vcpu); - /* Stop the timer (if it's running) before changing the vector */ kvm_xen_stop_timer(vcpu); vcpu->arch.xen.timer_virq = data->u.timer.port; @@ -2235,6 +2225,8 @@ void kvm_xen_init_vcpu(struct kvm_vcpu *vcpu) vcpu->arch.xen.poll_evtchn = 0; timer_setup(&vcpu->arch.xen.poll_timer, cancel_evtchn_poll, 0); + hrtimer_init(&vcpu->arch.xen.timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS_HARD); + vcpu->arch.xen.timer.function = xen_timer_callback; kvm_gpc_init(&vcpu->arch.xen.runstate_cache, vcpu->kvm); kvm_gpc_init(&vcpu->arch.xen.runstate2_cache, vcpu->kvm);