From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796407474; b=ariuqcKdqT6nw5w+s1xUzcvg0R1EZmgklx3niR731owa8f0NjtnfSjCSOhKuS6yLYtbK 0sM4XsrakqSgWEs3ut6ucH9FNcPwKvmsEWf0Tp/tDNc3erFvPf1MRE/2q509C276C050t ytCuuaUuqjmxjfP0HsZta/f7XZGiSryoIxef7cfMSO4mcqxWUfX8yDiOCm6VQBi51EYwl Qs7IG0+e8jBJf1h6AokI8IVpovx2lUJYZHgQ3yO3u9RIW4JEFdco1MVsd5fRCpgx+6yOb LhIAwteaNeuJueP09aKUqAeW6Xp6iGA3cF4mD62YGaeiLGnNll4GBZVOeQsatdVOmWQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796407474; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=mwmro3jclyB3WMmSSN/+lA8nJz6q4apfjntly8gA3t0=; b=Lnsct+yToza7tW0FbRMTX8hk+LfkfMIZbsohX9ovN/8U1f7u1zC5nsOpLDSu/o4FXGKW lIIwPtL8WPbgRv3fWyQEJ5ryrx/hApjwctPsL+XulZcDyyEJl+OgDGLl/G7/5BY62YFOw u3D8MOosbD6J/8AkXSY0WvHzGltpq+zum1Yom6b9NYuW/NyL+0idQweNJNCsU1QiBSlaQ M6rfYqYEcS0bVzSVYCSgpt4G5I8gE5OjLfFQFZrxqKmNknMNPwouy4h9Sp/J8hkdnlPxM OhpzY8gKPMP/Q7xNz2hF4PEAmd+trcYuIe/6yfqx7qfEIFYRLaMZ7zqDZLobBHOtICA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WfFK3QAR; arc=none smtp.remote-ip=170.10.129.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A98F606BB50 for ; Fri, 4 Dec 2026 18:04:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1A98F606BB50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=WfFK3QAR DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796407474; 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=mwmro3jclyB3WMmSSN/+lA8nJz6q4apfjntly8gA3t0=; b=WfFK3QARtfy/kxWtIayaUxanZQG6BaN6mLSgzvLh1Y2/adpPq+5BPt8bbQyNclRUTSXZ/g /3Oftht3l4PpJCZp2Ha8S4hPMj/zQ4vCWCg/0QjH3h1dugRsSzvMkRVnGjjU+99x6ydq1f igsp4fdUF3XsddIlwTGxq/X1pe/1/kM= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS with 8BITMIME (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-203-iEULgB6FOJ6CvZO8MuvB4g-1; Fri, 4 Dec 2026 18:04:29 +0000 X-MC-Unique: iEULgB6FOJ6CvZO8MuvB4g-1 X-Mimecast-MFC-AGG-ID: iEULgB6FOJ6CvZO8MuvB4g_1796407469 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D4B66188C37A; Fri, 4 Dec 2026 18:04:28 +0000 (UTC) Received: from pbonzini-thinkpadx1carbon6th.rmtit.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C59EB3003EAA; Fri, 4 Dec 2026 18:04:27 +0000 (UTC) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Sean Christopherson Subject: [PATCH 6.1.y 02/24] KVM: x86: Grab lapic_timer in a local variable to cleanup periodic code Date: Fri, 4 Dec 2026 19:04:01 +0100 Message-ID: <20261204180423.2168641-3-pbonzini@redhat.com> In-Reply-To: <20261204180423.2168641-1-pbonzini@redhat.com> References: <20261204180423.2168641-1-pbonzini@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 From: Sean Christopherson [ Upstream commit a091fe60c2d3943b058132a64682a509d55bd325 ] Stash apic->lapic_timer in a local "ktimer" variable in advance_periodic_target_expiration() to eliminate a few unaligned wraps, and to make the code easier to read overall. No functional change intended. Link: https://patch.msgid.link/20251113205114.1647493-5-seanjc@google.com Signed-off-by: Sean Christopherson Signed-off-by: Paolo Bonzini --- arch/x86/kvm/lapic.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index bfac2a1ea066..ad98e4f725e6 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -1886,6 +1886,7 @@ static bool set_target_expiration(struct kvm_lapic *apic, u32 count_reg) static void advance_periodic_target_expiration(struct kvm_lapic *apic) { + struct kvm_timer *ktimer = &apic->lapic_timer; ktime_t now = ktime_get(); u64 tscl = rdtsc(); ktime_t delta; @@ -1897,9 +1898,8 @@ static void advance_periodic_target_expiration(struct kvm_lapic *apic) * over time as differences in the periods accumulate, e.g. due to * differences in the underlying clocks or numerical approximation errors. */ - apic->lapic_timer.target_expiration = - ktime_add_ns(apic->lapic_timer.target_expiration, - apic->lapic_timer.period); + ktimer->target_expiration = ktime_add_ns(ktimer->target_expiration, + ktimer->period); /* * If the new expiration is in the past, e.g. because userspace stopped @@ -1910,17 +1910,17 @@ static void advance_periodic_target_expiration(struct kvm_lapic *apic) * past will do nothing more than waste host cycles, and can even lead * to a hard lockup in extreme cases. */ - if (ktime_before(apic->lapic_timer.target_expiration, now)) - apic->lapic_timer.target_expiration = now; + if (ktime_before(ktimer->target_expiration, now)) + ktimer->target_expiration = now; /* * Note, ensuring the expiration isn't in the past also prevents delta * from going negative, which could cause the TSC deadline to become * excessively large due to it an unsigned value. */ - delta = ktime_sub(apic->lapic_timer.target_expiration, now); - apic->lapic_timer.tscdeadline = kvm_read_l1_tsc(apic->vcpu, tscl) + - nsec_to_cycles(apic->vcpu, delta); + delta = ktime_sub(ktimer->target_expiration, now); + ktimer->tscdeadline = kvm_read_l1_tsc(apic->vcpu, tscl) + + nsec_to_cycles(apic->vcpu, delta); } static void start_sw_period(struct kvm_lapic *apic) -- 2.56.1