From nobody Sun Aug 23 23:45:55 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (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 497A8429DDC for ; Wed, 1 Jul 2026 19:33:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782934402; cv=none; b=agz/Nu0cfIFTYxDi0XI6+k6PZg6g0UjHCSlF1ZcGXAQjUAilzvdN0AMZ9rpHXEEMAirSN40cRcMgsWHT3e0mzJDOrf3sKU/mkdrcm6UbxNSMSSDg/i6EH3wFASACDXdYG0xHJr7fNdZqGgrdY8aPtyIZ90bZrBOYKIpb4SsgQvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782934402; c=relaxed/simple; bh=v/jmxMkGYZ/HTlvohOgxWHlLEZvO6K2N4svMiche8Yc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=i4pp1WR33f+q/8VAJUkYaNochTU7Vknnb1pF95Tm7S+3YL3GUNmsJvYFqCaEM/RJOe7g2OIdTny/ncz5zdgC/i2Q13u4vh3BjKKSmI92R818KvqdTQ+/YabTr9CFwD1uMCKZrzeOQuKdRnYdcR6wUWI1+3UL5rSuixRrhABMp6Y= 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=vARzOcPo; arc=none smtp.client-ip=209.85.214.202 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="vARzOcPo" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-2ca0481106cso11583865ad.0 for ; Wed, 01 Jul 2026 12:33:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1782934398; x=1783539198; 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=E0Ky72UXh2AIoPVqIZkO5elKJbkXgXhRlg1eH2WcetI=; b=vARzOcPonbotl5Eu8R7YZwr7DwSNSZllNUakNzDPaa03BrG6Hai/OiNmi6tMe7Y18z KzyPWN8mE9QmO4wQw4spd6qjEkowdg3aMtO7UdtsS6u5NP/K9ITuTpqGMjKolXClE9QN eaYH94/Of+Hei9JF6ItM5ObcsgvKkOeJnmK9W3BP04TwClkAqzN0tEgB99x6Biy4UeGy VW6UNukIfpt16lg6XBFmyJk20BuqgXsWyX40aOHtIIoq1aiO7VkYyifRAlTElGEf8WoV 5qyOxOjNq9pPUryKjmZyG3Ew2PEHk9gO3LCbOGT/s0d52Ir255x+O7cOO0dKrzFW4hiY 6Z1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782934398; x=1783539198; 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=E0Ky72UXh2AIoPVqIZkO5elKJbkXgXhRlg1eH2WcetI=; b=YDV2yTD41iXaFINOph4Q5td5+n6aK0RTcCmtxM9wPwFbs+j+enjpb1MQW8qjpVLcDI cdQQzwGBAbPFiZfKPtncI7bZyzX5C47yoZ6emw2ezMPNaBSz3u9a+gobAshxmHc/xLs5 yK2yOPVyeL29x6klyGApLIlblmeWIk7MHqBbuUsa7bIt9JWyLIH/UbeFp5lKw7ovXRQ3 IaemskpRrrq81nBeznyCB4VoPp5CLeaRrLvyJ4Z4VjXES5GpMhPyhu+y4YO3ThMSmd5j oxPj/a2F5PePZ2epXCFQGhJi1juo5dyyys9YVhD7kYNRaBnWokKO3g+RTI7sqV8HI9TT l+Lg== X-Forwarded-Encrypted: i=1; AHgh+RqSGWrCEmAom/c2oL+jb6X+5kqIAbSH7ydMn+Z5RQmK7SHR82NksYWtCDKfDonktG2kLLtOOD8xQCprL9A=@vger.kernel.org X-Gm-Message-State: AOJu0YzzGKFP8ZjI1ikPEbbjUD3B2lJNixFNHs+V5eJK5r0fkLsgnskT InPUZ6oiUbzTZ5q60yu6jbDLBuW9X98LCSMYOr2emdY40J0rYJJQGnT1bqujBHMQTLvbiAxpAFu BSDIgvA== X-Received: from pleu6.prod.google.com ([2002:a17:903:41c6:b0:2c8:5a:8056]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:903:3885:b0:2ca:17a8:cfce with SMTP id d9443c01a7336-2ca911d341fmr20775345ad.29.1782934398119; Wed, 01 Jul 2026 12:33:18 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 1 Jul 2026 12:32:03 -0700 In-Reply-To: <20260701193212.749551-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: <20260701193212.749551-1-seanjc@google.com> X-Mailer: git-send-email 2.55.0.rc0.799.gd6f94ed593-goog Message-ID: <20260701193212.749551-43-seanjc@google.com> Subject: [PATCH v5 42/51] timekeeping: Resume clocksources before reading persistent clock From: Sean Christopherson To: Jonathan Corbet , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Kiryl Shutsemau , Rick Edgecombe , Sean Christopherson , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Long Li , Ajay Kaher , Alexey Makhalov , Jan Kiszka , Andy Lutomirski , Peter Zijlstra , Juergen Gross , Daniel Lezcano , John Stultz Cc: Shuah Khan , "H. Peter Anvin" , Vitaly Kuznetsov , Broadcom internal kernel review list , Boris Ostrovsky , Stephen Boyd , linux-doc@vger.kernel.org, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-coco@lists.linux.dev, linux-hyperv@vger.kernel.org, virtualization@lists.linux.dev, xen-devel@lists.xenproject.org, Tom Lendacky , Nikunj A Dadhania , David Woodhouse , David Woodhouse , Michael Kelley , Thomas Gleixner Content-Transfer-Encoding: quoted-printable 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 b1b5ec43c0f2..5bc77d36c7a3 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -2180,11 +2180,16 @@ void timekeeping_resume(void) u64 cycle_now, nsec; unsigned long flags; =20 - read_persistent_clock64(&ts_new); - clockevents_resume(); clocksource_resume(); =20 + /* + * 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); =20 /* --=20 2.55.0.rc0.799.gd6f94ed593-goog