From mboxrd@z Thu Jan 1 00:00:00 1970 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 49E3213CA97 for ; Fri, 24 Jan 2025 14:58:40 +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=1737730722; cv=none; b=YWj+lE/EOm9aJusp8kFCDxkp2JoDKCZKrL90p3f3NFK5j1cJ+OqvF9l1Ikeji/dpCrGuspyd1UALPy4rOfp8/69u+5Ez9omNhTPaagy9qHm1HJp8aHu5TZ/MWd/gjZIg27jGIr0QaxToU0mJ3viRbGy35cVrpQ6oyorv1akp6W4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737730722; c=relaxed/simple; bh=5q8o3VAK616DYEUCQ3uFljyadi/KAlDBISFIOCLp0i4=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=U039S563W4GWLVt9aipHir37ZGA2nRz1sv5wC4REoGka1Pu5avg7LsKZSwc74QIUQkCRaK2EhX90Y4rboULQGoRFaY/HLHw6a27aQdbx0JRz2NvbNORLoMkYXlVODf7f/rOtvPerx4g9QTRFg285CAMAWEZwAt4gLqO0BodtoE0= 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=Gm3+Btif; 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="Gm3+Btif" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ef9e4c5343so6268625a91.0 for ; Fri, 24 Jan 2025 06:58:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737730720; x=1738335520; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ih7bo1+rSYUrkrU5DiFx25AwH0aJw31nW73F+nUU4y4=; b=Gm3+Btifp22nE4fcdCK8oTXNaKjlg3+UWeZtUT8D8+oQtue6VTa4PlW1jvm3oak1EM KGsd3v0283LXGK4ywtYJXjPC0PvbvZzpKrtFsuxrGGy9MLWqLVN+djrr/+QmaKDbJJnB NlA6qdtxtOZJlepXYcseTrNObw4YZmQ4hpSXu/hVEL5fktfWMUBdecb8XCV8h9222cIe XulXvHZNsxFZipAnhOBwz9p3af7ySSq3oqzyZIF732rYngO/IssoxiuoUUT6saN5rLBf LptlObogH6q4OhyAf4vTVM2HTS+gbboUe1/SKQP1z6ErAQ5T/z7M03KMBWp+2sLsqT2J kzhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737730720; x=1738335520; h=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; bh=ih7bo1+rSYUrkrU5DiFx25AwH0aJw31nW73F+nUU4y4=; b=QFQeqk3RumTTNhAMWx0j5vE7KzoBXUqk3UkDRIc2/6JkXDW67L8x7/WW/pLZWIrVb3 eHsaHrOpvMVkJIBQ4gPIc3YdVqbkKRlKiYLbOZQbDHMPm0w17FJ9yYqg5Fu/kACJ/fSG FdtVsGvY0xmNItc6ohkOUYa6WHcF8Y9y44hfoCFxTL2bCZabmBVvfnhRMXzyEAgJZ3mZ 6JAct+wAQOyowdeQ9eg/DAQAoC0gkfBAXEr4pUKQq55p8T4xdAdbnGGpknj2d0225gG2 6VwU64SzTEsetUqZp53izsZK4uFyaRFNgt9EsmrSqAuqqSZCGhnbHUOM72c+tnsHFqfh 4Uow== X-Forwarded-Encrypted: i=1; AJvYcCW50lZVSbbIyu6CIw7U6c4GSu/FARWUQZ/BQIgZVS94zPIu5MfIWSKj8MaqHhiuR7/0BDNocNn4ZQRZqco=@vger.kernel.org X-Gm-Message-State: AOJu0YzNRSbmnEHX4GcJCVa520pLhYnC1gSn7T9EWfUzifJBDD/5pYHm HPz7L4CXNBXbjT4n/3nKHM4DXz5Dn1PmnwFxCB/xKqmXwPGR4F4VR4kY8MjFLLx0SXSwpnlU2S9 bDA== X-Google-Smtp-Source: AGHT+IHa1p2TF87YFX31sUH+Hu1nj4ZRj5xHn8y5p9wW1NWIW8o8jywZsKH5M1XqNH6o7ecFj0zSrd2m+WM= X-Received: from pfbf7.prod.google.com ([2002:a05:6a00:ad87:b0:725:f376:f548]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:300a:b0:729:597:4fa9 with SMTP id d2e1a72fcca58-72dafba344amr41396483b3a.22.1737730720516; Fri, 24 Jan 2025 06:58:40 -0800 (PST) Date: Fri, 24 Jan 2025 06:58:38 -0800 In-Reply-To: <336f5623-b380-49e4-8dbe-ffa98f5aee19@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20250123190253.25891-1-fgriffo@amazon.co.uk> <336f5623-b380-49e4-8dbe-ffa98f5aee19@gmail.com> Message-ID: Subject: Re: [PATCH] KVM: x86: Update Xen TSC leaves during CPUID emulation From: Sean Christopherson To: paul@xen.org Cc: David Woodhouse , Fred Griffoul , kvm@vger.kernel.org, griffoul@gmail.com, vkuznets@redhat.com, Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="us-ascii" On Fri, Jan 24, 2025, Paul Durrant wrote: > This LGTM. My only concern is whether vcpu->arch.hv_clock will be updated by > anything other than a KVM_REQ_CLOCK_UPDATE? Once the "full" vcpu->arch.hv_clock is gone and only the multiplier+shift are left behind, the probability of rogue changes to those fields should go down. I'll also add a comment explaining the relationship between hw_tsc_khz, pvclock_tsc_shift, and pvclock_tsc_mul, which I should have done it for v1. https://lore.kernel.org/all/20250118005552.2626804-9-seanjc@google.com > I don't think so but the crucial thing is that the values match what is in > the vcpu_info struct... so maybe a safer option is to pull the values > directly from that. But that relies on the XEN PV clock to be active, which I don't think can be guaranteed. And even if that isn't a concern, I think we're doomed either way if any of the relevant fields get clobbered. Hah, actually we're doomed, period. E.g. if KVM emulates CPUID, and then before resuming the guest reacts to a TSC frequency change, the values returned by CPUID will diverge from what gets stored into the PV clock. In general, if the TSC isn't stable, using the info from CPUID instead of the PV clock itself is a guest bug, because only the PV clock provides a sequence counter to ensure reading time is consistent.