From nobody Mon Feb 9 03:45:41 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 5D234126F1E for ; Sat, 1 Feb 2025 01:38:38 +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=1738373919; cv=none; b=qxmOK/g9lAkprZ+w9mMmF5DoXaOf9p2LqPV5oZEiaXYZg63XR+myZtqHpaXzBuSu1AmFF9ktoGUWxwN1It2Nth5vzOhxp8FXMQ7/8mdYn0t6UhK2dv0CrnQjgj7CJOsjqYhHmfttfR+bOCxAvWUWkhj+CoxqFYAIx6NmIKWfcjM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738373919; c=relaxed/simple; bh=UUzVxW+A0LbHvQamjiSSU35WtkGq3vbu9aNxHkZpIfs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=ADtZg/86ogHtZrsGfHUdFmY9kSrER3luQPZiTS7aJ3Ib1DwagJivgrCmVCTMOwX5ksR+sZEZkCk0NeT9PSjo/rVVMc+xBQ1KPJZq26fn7LOVJGmldxYH7WoA/5p/NTx87KFMhMcwb8psz6pQECjKXPJ3bWC68bk39f3RlfcHhdg= 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=Kb7PG6ND; 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="Kb7PG6ND" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-21681a2c0d5so45891015ad.2 for ; Fri, 31 Jan 2025 17:38:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738373918; x=1738978718; 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=P0Rg1qN67xtOrW9/3acldXp82KHWRVyhcuyhp0qB1L0=; b=Kb7PG6NDBXebuirdoki52DwwkYmWRLS5NQ8FznNZkZeXvDJZ0shaltjsow8Jqo/lGx cLrVWJu+8bin4NZZZpgfpIbJag2boYx6PzYJE2eosU9pGXyhq95Kc3cuTmBohSA7BZkG ogvnQ81TLMOBejkAlJu7+I3qtp4pU4GC3EEhZKFODt71LoYaj+Tfwnp+/Dy2zU97iQef docm99OHbcAQ0kAcO5MeDvThYXpe8xqHnRslhBEHOknLStx/lBI5GDYPLsZ941Up5dOP 1cOXS4ECCdAewkWRuTBwAM1sQtEIr8I+gR9Cm0Bx8e1U901fQlHnLOciUH37gnuuSRon Kuwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738373918; x=1738978718; 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=P0Rg1qN67xtOrW9/3acldXp82KHWRVyhcuyhp0qB1L0=; b=AsK7tt9E5aNE4gTW0yfmIDGDoik3NZPxwx4GFdRCxXv9161nqkersxkMKOdV/jPGvD Wgy6WrsMYQvqs9gIsJc92ugpeM3v9Q//SFC4fn+t4l4lyHDZP2nGQgnDUEQnXifiZgLf iYcJbS2VCg94urz2fEI8/DXDAf0AOrhBYF11+d+y2HyRW66K/n05KoaUe8qyXpqCw7t4 eMczcaJwqQ4Y5IPJm8EEFxdLXx0iQzaHOe2qm2biLqb5A6sTd8k+w3vKqBnqbselqkHG LCwBCO/80CBV7qj0Y/2D5sv7lv0szor7wvG6kJP9axDC7kjRxEzn2KJqzDweJ4PP+5oZ yZBQ== X-Forwarded-Encrypted: i=1; AJvYcCVwQAf6cQ6Cu1yTmoWMKJa9ExBCnv8j/VNfeYjIHLqzsoTbGr5zg3/9KRA9Hi/eUrTjLreOgdTH3yU4B1Y=@vger.kernel.org X-Gm-Message-State: AOJu0YxBctSP4V8mRGAU/e6G0gtQvQzrAEIJp5Ysz3QuxKOE+HweAnad 84e/S/NLQYY2/LND9Hn8gr7EqqKK5EwtRSPJ1Qu41n5p+2ZJdzcsWEvQauvRDEnIBcxHAqQoTL9 agQ== X-Google-Smtp-Source: AGHT+IHzrvrAtIazL7DuI5S6zMGK5azT035sFwOHSFpiw0QSUrMFD83Pit1/KumxCWsWadgyJWwokGOlwp0= X-Received: from pgc25.prod.google.com ([2002:a05:6a02:2f99:b0:7fd:40dd:86a5]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:d049:b0:1e0:cf9a:87b1 with SMTP id adf61e73a8af0-1ed7a49a2d8mr21514926637.6.1738373917669; Fri, 31 Jan 2025 17:38:37 -0800 (PST) Reply-To: Sean Christopherson Date: Fri, 31 Jan 2025 17:38:20 -0800 In-Reply-To: <20250201013827.680235-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: <20250201013827.680235-1-seanjc@google.com> X-Mailer: git-send-email 2.48.1.362.g079036d154-goog Message-ID: <20250201013827.680235-5-seanjc@google.com> Subject: [PATCH v2 04/11] KVM: x86: Process "guest stopped request" once per guest time update From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini , David Woodhouse , Paul Durrant Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+352e553a86e0d75f5120@syzkaller.appspotmail.com, Paul Durrant , David Woodhouse , Vitaly Kuznetsov Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Handle "guest stopped" requests once per guest time update in preparation of restoring KVM's historical behavior of setting PVCLOCK_GUEST_STOPPED for kvmclock and only kvmclock. For now, simply move the code to minimize the probability of an unintentional change in functionally. Note, in practice, all clocks are guaranteed to see the request (or not) even though each PV clock processes the request individual, as KVM holds vcpu->mutex (blocks KVM_KVMCLOCK_CTRL) and it should be impossible for KVM's suspend notifier to run while KVM is handling requests. And because the helper updates the reference flags, all subsequent PV clock updates will pick up PVCLOCK_GUEST_STOPPED. Note #2, once PVCLOCK_GUEST_STOPPED is restricted to kvmclock, the horrific #ifdef will go away. Cc: Paul Durrant Cc: David Woodhouse Signed-off-by: Sean Christopherson Reviewed-by: Paul Durrant --- arch/x86/kvm/x86.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index d8ee37dd2b57..de281c328cb1 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -3150,11 +3150,6 @@ static void kvm_setup_guest_pvclock(struct kvm_vcpu = *v, /* retain PVCLOCK_GUEST_STOPPED if set in guest copy */ vcpu->hv_clock.flags |=3D (guest_hv_clock->flags & PVCLOCK_GUEST_STOPPED); =20 - if (vcpu->pvclock_set_guest_stopped_request) { - vcpu->hv_clock.flags |=3D PVCLOCK_GUEST_STOPPED; - vcpu->pvclock_set_guest_stopped_request =3D false; - } - memcpy(guest_hv_clock, &vcpu->hv_clock, sizeof(*guest_hv_clock)); =20 if (force_tsc_unstable) @@ -3264,6 +3259,18 @@ static int kvm_guest_time_update(struct kvm_vcpu *v) if (use_master_clock) vcpu->hv_clock.flags |=3D PVCLOCK_TSC_STABLE_BIT; =20 + if (vcpu->pv_time.active +#ifdef CONFIG_KVM_XEN + || vcpu->xen.vcpu_info_cache.active + || vcpu->xen.vcpu_time_info_cache.active +#endif + ) { + if (vcpu->pvclock_set_guest_stopped_request) { + vcpu->hv_clock.flags |=3D PVCLOCK_GUEST_STOPPED; + vcpu->pvclock_set_guest_stopped_request =3D false; + } + } + if (vcpu->pv_time.active) kvm_setup_guest_pvclock(v, &vcpu->pv_time, 0, false); #ifdef CONFIG_KVM_XEN --=20 2.48.1.362.g079036d154-goog