From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) (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 857274AB829 for ; Thu, 6 Aug 2026 23:37:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786059439; cv=none; b=CNHGwe714pm4CMRWZDU6m9DYd7sx6Gk5r42ksAisQ7KG4e7MBn/SxCuydokQeZS2eMFeQLSSALVzaT+MYNAAgKZdJ8QO0Vk/XMGzEenujLZopc21zBupgt+uKEStjiGxG5ucB+WeE3hBeVxHL1zN2vebQA+iuySevJVufflM8r4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786059439; c=relaxed/simple; bh=CMNPpn663VblKppKKu5nFjYj1HkUy1nnfJebT2ynUYY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MaHF2la1xVdeYyB+q0TBvYojVWEUvh7VpGiy+9EomaVKCUEh3j1Ga8CHgOoIB8paYKSxjNUsSERWJR2oSuxtqRyh4wjTf7s9riNq8uT7Z1vRMsb9b+UxXG/xBZnk+g8Rm9SETFHdEht6RRyIFH1Q03clAofbMdFIAMDXTwvpm0Y= 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=AW4CMHyS; arc=none smtp.client-ip=209.85.215.200 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="AW4CMHyS" Received: by mail-pg1-f200.google.com with SMTP id 41be03b00d2f7-cb5cc1e139bso1976183a12.3 for ; Thu, 06 Aug 2026 16:37:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786059437; x=1786664237; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:reply-to:from:to:cc:subject:date:message-id :reply-to:content-type; bh=qISz6FBmFt+Rjc4N/P+Kp805/IDsq2ZStMxtEE1uDRQ=; b=AW4CMHySlmhYrT72DTxH1CFaADGEcb+OsB0Lv2jWisdK+ZVBA4B3YpJmonI8tQ6U8p hTjQFu2SPZNNKmGS4geXikr94xBv5k6rs3HIy7U5EYhAripWLlB6VUnNJQtVTYlfj9s6 cBn/XWXt5CgApEOr7lklGVdX/+OIefFTn0MbkSmCyCEDYkIUJyjO3EnMe7I7k7+9qO8g O8TVRLSK5NN5mVqeSmmhs3F/XAgk0bQWX6Y/amidPpMrWq/yu8GNmVYVcP+uoTCR6UMD kDdaNifv9iQ4C1oFhRSzMKmLNtIRbkl7Q6EFW73m/uR62MYvYwHwox43zievt5H7LRbw N1EA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786059437; x=1786664237; h=content-type: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:content-type; bh=qISz6FBmFt+Rjc4N/P+Kp805/IDsq2ZStMxtEE1uDRQ=; b=EYyi4ZykkTqKEYCmLujDIgtFEN/WJRMGv6d1Tm8agaCuxd/kV8vYXODUQjtg+q48xv fhilwvZ+HkdkvvA44nkNes2VOTNFHcVjTSml87HnqX6nIn9/SJB9S/rB2HctRK+/LsFZ 4qLVYkiMPxRWUUY0k6t9BUBsYbTzupbVoj8rLj9y9pOE5jCQ9MNNFeHXdkxYA0xHzf+b GzFpn5i7J6GaaITgeIZ7N8pKPqjHxedaUIlCOuJKWDItE1gcUqPo70xqqJsIw9mGItaH QTvLPPAirga0gQ1ZTV3cP4s2ZIgoMQG/a6r3YnGbZIlVMs1Bj5S8kIWYJxhrgPKhttZZ OdYw== X-Forwarded-Encrypted: i=1; AHgh+Ro4kyNG01+u0jCSfRHy3c2qhSyRXN/xOrufaj0Pew0+QVji/NxwGhvxKgAMJs1Idf4GM3txtrf0FPOIdFs=@vger.kernel.org X-Gm-Message-State: AOJu0YxBA4CLgNMNaFojtwDEWRtVLti/pHGAcoVGZQo6JRd66k/Z5BZm y6fLlL+r3lr6VbCC7iTASX2zNWJMlAOJwM2CidpYDUov/lsR1VhdBGmPaN8u+1IJTAsdY5Qwr3n a2f3Trw== X-Received: from pgbep6.prod.google.com ([2002:a05:6a02:2646:b0:c99:90dc:7b3f]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:6112:b0:3b4:e4f6:4f15 with SMTP id adf61e73a8af0-3cb85e9922cmr22668021637.5.1786059436589; Thu, 06 Aug 2026 16:37:16 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 6 Aug 2026 16:35:59 -0700 In-Reply-To: <20260806233609.212337-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: <20260806233609.212337-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.679.g6767b8d81c-goog Message-ID: <20260806233609.212337-43-seanjc@google.com> Subject: [PATCH v6 42/51] timekeeping: Resume clocksources before reading persistent clock From: Sean Christopherson To: Kiryl Shutsemau , Rick Edgecombe , Sean Christopherson , Paolo Bonzini , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Ajay Kaher , Alexey Makhalov , Jan Kiszka , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Juergen Gross , Daniel Lezcano , Thomas Gleixner , John Stultz Cc: Vitaly Kuznetsov , Broadcom internal kernel review list , Boris Ostrovsky , Stephen Boyd , Miroslav Lichvar , x86@kernel.org, linux-coco@lists.linux.dev, kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, Michael Kelley , Tom Lendacky , Nikunj A Dadhania , David Woodhouse , David Woodhouse , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" When resuming timekeeping after suspend, restore clocksources prior to reading the persistent clock. Paravirt clocks, e.g. kvmclock, tie the validity of a PV persistent clock to a clocksource, i.e. reading the PV persistent clock will return garbage if the underlying PV clocksource hasn't been enabled. The flaw has gone unnoticed because kvmclock is a mess and uses its own suspend/resume hooks instead of the clocksource suspend/resume hooks, which happens to work by sheer dumb luck (the kvmclock resume hook runs before timekeeping_resume()). Note, there is no evidence that any clocksource supported by the kernel depends on a persistent clock. Reviewed-by: Thomas Gleixner Reviewed-by: David Woodhouse Signed-off-by: Sean Christopherson --- kernel/time/timekeeping.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 97db2e9393f9..585525f5c1f6 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -2226,11 +2226,16 @@ void timekeeping_resume(void) u64 cycle_now, nsec; unsigned long flags; - read_persistent_clock64(&ts_new); - clockevents_resume(); clocksource_resume(); + /* + * Read persistent time after clocksources have been resumed. Paravirt + * clocks have a nasty habit of piggybacking a persistent clock on a + * system clock, and may return garbage if the system clock is suspended. + */ + read_persistent_clock64(&ts_new); + raw_spin_lock_irqsave(&tk_core.lock, flags); /* -- 2.55.0.679.g6767b8d81c-goog