From nobody Mon Feb 9 23:15:56 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85031322DD1 for ; Thu, 13 Nov 2025 20:51:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763067083; cv=none; b=t2nx5rNPzqiMLI5K01mSzHdAhIgK620NS5Cgm3AYrIo9lq/b7DdCBwGGWB6DowOm3rbprdOO2F4s6lPF0ouS9hiGSpWKHuZm+G1IyS3OsCeDSRdJgAX5Q++F/ln2hg10qNkwZEaqHBl81Omgf0bpmb2/qkXE6cJlm7ElyYEmPNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763067083; c=relaxed/simple; bh=eRxbYe0kdGcrEUUzVBzWT3I5r2UPd2pYTMvZwRdDYDE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=XQoOfrWfF8sCmVr7cJSGQpQgAbvOLpdC5JvsgSdGWvgmmyuJHhUmbDJUXmYCNPeCLbZfHftSCWm1dVQVS57AuKP3F6Wp9rTRNSOTj+HFpADUh9lyAFIhLEnoL8lDKCa5nTldDt0kS94+EssSNLYQOmj5yLAI69DS0ftEnd+MD8A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=S2WOwPl4; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="S2WOwPl4" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-343daf0f38aso1566380a91.3 for ; Thu, 13 Nov 2025 12:51:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763067081; x=1763671881; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=ejzuboDQw4w6apP9VylzMSB0PpTSFQoCGewPZ8H3aC4=; b=S2WOwPl4funA8D19HbpXcxxTMwQvggXHddqKq901H+DOtDdR+If4H68JmnGQKbwL4F tEzzhsc/F3zlpzyyoYD7PNyGGsQMCp5Ho02RoAIMAAwFQQtbTuISWsb+6a+mmITuHMZY H8KByCEf2hILyygXmnXnJqD9TPbFtwviPAhfi/gEbQI2RyEsviSD1O82cai4x+BY0XSX nRHhoCzz7uEK3xwgb9ZjCXoFhX7S/Q32fqtrLuXRuSjqLIjxwtsrEPRJWh+xfEHh/Pt6 sXYh+WbV0tUVrnTvD95waL7Jv2U2FUs+6YDssXGrIU3OzxLd4XJrbHp9eENw2ea2PJPu 4PZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763067081; x=1763671881; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ejzuboDQw4w6apP9VylzMSB0PpTSFQoCGewPZ8H3aC4=; b=WjX3CKYCZnT/fEFS5xGY0QTF2NfdeNFkzm66itf+2n2E1bGlSFSKxyETtmcjrNYvCU fjBLKWUA9LM5zDJsxR/LuND4uLXeCUCK7tFHJFWl41i2TqJAVqcM0ET4D8rOygAXHMKX LBbvEFRs2aHRN/XhP06PzvlNra3JQToIJSk62c65Cb/+kd5IVOzevGtsBU6P5osalqUc bNvYD73yo4FtOvb57yhNksCrjoHCOTW5syO/nFuhpZrd0VAczLQ/l8FVZrPwVXC7O5LF 5RHwZXBjFjHegqRvYbavq2ZW7KRpp0irAfocpXeJCcFZXx3slKrzf9Zkv7+HZHVSqZ0e OXgg== X-Forwarded-Encrypted: i=1; AJvYcCUSIlcVvaU3z7nifZqdYQODLEJee/stC26K3FaCiI0MI0bSqE5yebYoMp5Iiq0S+Uvq4RvA95VxhStxcM8=@vger.kernel.org X-Gm-Message-State: AOJu0YyG3cWbDrWowbr68PBjCgXh2GGQFgymFH4wKd6qrdNNonZxp7ni 95YvzCymR0796PhwehJLYMx1+YZgehfEDZbsAHEMwPIE7iul4y85Et/R9ZkLqAe0E3qlewzA13d fLPqQxA== X-Google-Smtp-Source: AGHT+IE3TMMnlHBn6B8nmXmxM49hbBVHnKcvO72C9SKjgOi/6oqv7jleyJZlT7nXdmHE1UQkaFzpJLxKqGI= X-Received: from pjbnk9.prod.google.com ([2002:a17:90b:1949:b0:343:7133:ea30]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:2890:b0:340:bb5c:7dd7 with SMTP id 98e67ed59e1d1-343f9e92771mr605020a91.5.1763067080876; Thu, 13 Nov 2025 12:51:20 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 13 Nov 2025 12:51:12 -0800 In-Reply-To: <20251113205114.1647493-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251113205114.1647493-1-seanjc@google.com> X-Mailer: git-send-email 2.52.0.rc1.455.g30608eb744-goog Message-ID: <20251113205114.1647493-3-seanjc@google.com> Subject: [PATCH v6 2/4] KVM: x86: Explicitly set new periodic hrtimer expiration in apic_timer_fn() From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, fuqiang wang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: fuqiang wang When restarting an hrtimer to emulate a the guest's APIC timer in periodic mode, explicitly set the expiration using the target expiration computed by advance_periodic_target_expiration() instead of adding the period to the existing timer. This will allow making adjustments to the expiration, e.g. to deal with expirations far in the past, without having to implement the same logic in both advance_periodic_target_expiration() and apic_timer_fn(). Cc: stable@vger.kernel.org Signed-off-by: fuqiang wang [sean: split to separate patch, write changelog] Signed-off-by: Sean Christopherson --- arch/x86/kvm/lapic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c index 78b74ba17592..a5c927e7bae6 100644 --- a/arch/x86/kvm/lapic.c +++ b/arch/x86/kvm/lapic.c @@ -2972,7 +2972,7 @@ static enum hrtimer_restart apic_timer_fn(struct hrti= mer *data) =20 if (lapic_is_periodic(apic) && !WARN_ON_ONCE(!apic->lapic_timer.period)) { advance_periodic_target_expiration(apic); - hrtimer_add_expires_ns(&ktimer->timer, ktimer->period); + hrtimer_set_expires(&ktimer->timer, ktimer->target_expiration); return HRTIMER_RESTART; } else return HRTIMER_NORESTART; --=20 2.52.0.rc1.455.g30608eb744-goog