From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.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 5448846EC6C for ; Tue, 11 Aug 2026 23:40:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786491629; cv=none; b=qCII37ytYndSdT3/GqBv+owIZKn3OYVQbduRZZYglkCzgbUesAhwbYYiNkbOlxmSzLyERSq2SwAqfeAZ+4JWtkh5hjew2w15wPt6wymXbRLj5nXxYYOgNGbczZrsvjEG/uNnovXRKSOeI5mgmoUKcCf/sjaYgFSmnn2bKN/qBJA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786491629; c=relaxed/simple; bh=LWX8eDrFpn0O1sl7XVBhLcCVcXXH7HP3dHxQ8HmNZPI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=huKJ2JuE+QKU+5JxiaQjuRLYax6v7lJk49xSAvLm+nYgwMke6gr9B4vKxRgYyNtRbJQunBcTG9N/WQE7LpJvVaHLkXxmm9AymZPRSswi/aT3mA+2JqCzYWHWIlmsEiZy0jYn2ViZuiYucR4MI7+EvM2cg7JkJyexeah6Ue+XNrA= 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=DbQN/Lms; arc=none smtp.client-ip=209.85.210.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="DbQN/Lms" Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-84c4cd31b51so1635882b3a.0 for ; Tue, 11 Aug 2026 16:40:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786491626; x=1787096426; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=45PzVi6GlKpHz3+ZRxW2EDnuD1UWmkJmuMSYxMTtVTA=; b=DbQN/Lmsn3+QG9Nl2qmxu19rr7RgyoGsFsf3YfHCukJMPwAahg9W3eWKbiecoHWQq4 AUowti408mIZjVUU1rotRaydKnWBUA0YOwRjqYPE7BcYxkOHc4HDz0357x9cmNBBU3W5 1aYSdSH65c7a9vf6nJpIHBrtkeF6z6CoOgslH0XefC5WdiXHS5PtkbpfTexFFFKBN6IH 8M23djyBuQFqI7iRQLVa41z10pT5FGBtpBSqUhMaZ0AbUOahzBpk/nNXKFWIsWdjalOD 4XOxegZrxFEO1pU3anz4w4CjrhgIaATIlud3MNAkozFD4SMyrRmWfZ4rvU4Gjzr1N4nP 1PpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786491626; x=1787096426; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=45PzVi6GlKpHz3+ZRxW2EDnuD1UWmkJmuMSYxMTtVTA=; b=S+qo0ilCwtNQTlPkAa8XmfzAF/5ORWWTyDka6G2VW8pa08aNaQAT9H5ueXVaFLeLUY zrZT2LFatU/bMbu19luOxLX7gDnjKW1rWtmcv5RwGh3ORUm6UyFYih+83Wm/JiBmxChP 7y+qHyWmfTYThxlPLJcQA5/NY0pJDVoUdr9b4+Fzw7nQRHe/AwXlVYWCxJeQoB8f1Evu 0xdzBeKfe6CDftrW9D/wjEdPfMc6CE51CetAh/tfbH6G0RH5U+GmzP/1PK0KXN/UlDae 0bJz2MEKAuMUlE6XMgpjUCOaHlXS7YgaqMPMkv4D/l4hJLLPqAUh8bM09srtb1drUApG rxGA== X-Forwarded-Encrypted: i=1; AHgh+RrMntt5axdbLF7vrorSwwVMCPuxUIVRj5EpxSyBbt9vQ0n1mW6BcCf4k/ajv6ouArm1kKIzRaqDwolgngc=@vger.kernel.org X-Gm-Message-State: AOJu0YzcznV5Ob8NMX3sEBZ7G2PxIvDA7taKsotPE/uB1gqVV1xEyY+Z 90LzSsRl8K87bVIieAE4E6y2GUdpks0vRW9XIFDfCtP+X6zrWppcOPJ6veyJ8XbCjApFVCqYZhq bjswPXg== X-Received: from pghr4.prod.google.com ([2002:a63:e504:0:b0:cbe:3df6:a1aa]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:3d1c:b0:3c4:1916:9d44 with SMTP id adf61e73a8af0-3cc3f913cbfmr444625637.16.1786491626070; Tue, 11 Aug 2026 16:40:26 -0700 (PDT) Date: Tue, 11 Aug 2026 16:40:25 -0700 In-Reply-To: <20260728144954.355376-32-dwmw2@infradead.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260728144954.355376-1-dwmw2@infradead.org> <20260728144954.355376-32-dwmw2@infradead.org> Message-ID: Subject: Re: [PATCH v7 31/36] KVM: x86: Add KVM_[GS]ET_CLOCK_GUEST for accurate KVM clock migration From: Sean Christopherson To: David Woodhouse Cc: Paolo Bonzini , Jonathan Corbet , Shuah Khan , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Vitaly Kuznetsov , Juergen Gross , Boris Ostrovsky , Paul Durrant , Jonathan Cameron , Sascha Bischoff , Marc Zyngier , Joey Gouly , Jack Allister , Dongli Zhang , joe.jin@oracle.com, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="us-ascii" On Tue, Jul 28, 2026, David Woodhouse wrote: > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 5c78dd1e4c69..0680332d7d45 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -3435,6 +3435,169 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, > } > } > > +#ifdef CONFIG_X86_64 > +static int kvm_vcpu_ioctl_get_clock_guest(struct kvm_vcpu *v, void __user *argp) > +{ > + struct pvclock_vcpu_time_info hv_clock = {}; > + struct kvm_vcpu_arch *vcpu = &v->arch; > + struct kvm_arch *ka = &v->kvm->arch; > + unsigned int seq; > + > + /* > + * If KVM_REQ_CLOCK_UPDATE is already pending, or if the pvclock > + * has never been generated at all, call kvm_guest_time_update(). > + */ > + if (kvm_check_request(KVM_REQ_CLOCK_UPDATE, v) || !vcpu->hw_tsc_hz) { > + int idx = srcu_read_lock(&v->kvm->srcu); > + int ret = kvm_guest_time_update(v); Invoking kvm_guest_time_update() here is probably a deal-breaker. Updating the master clock and other internal state is far from ideal, but should be ok. However, writing guest memory is not. Specifically, dirtying memory after the last KVM_RUN is a non-starter for many usecases, as is modifying state that is visible via other GET uAPI (though I don't think that applies here?). E.g. see commits: 118964562969 ("KVM: Mark a vCPU as preempted/ready iff it's scheduled out while running") e800decd9c0a ("KVM: x86: Only reset TSC Deadline Timer in apic_timer_expired on KVM_RUN") One idea would be to simply punt to userspace, i.e. return -EBUSY without trying to update guest time. Which is pretty darn ugly, but might be tolerable? And a slightly crazy idea to lessen the pain would be to process select requests in KVM_RUN before bailing for vcpu->run->immediate_exit==true. That doesn't completely solve things as it's still possible for KVM_REQ_CLOCK_UPDATE to be set after KVM_RUN, but I think they're mutually exlusive with the majority of relevant use cases? And we'd probably want to build on my idea to report that KVM_RUN needs completion[*], but that'd be a good thing overall. https://lore.kernel.org/all/20250111012450.1262638-1-seanjc@google.com