Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1628823lqe; Mon, 8 Apr 2024 15:08:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWYMfsj3sEjsnFEoVgyDkERUVz/xUfSZCfU03a9qsx+FY7UnpFjiqtJuA6o0V9swQTQuqeRLsZEfRQd7+LnmJyy9W1VBrYTPGROMg830A== X-Google-Smtp-Source: AGHT+IE0zjTiMNzYyOfo25rKsOka9IhIe3AtkFaxzIz2QYgRrAS798fWtby0SePEnK5CI1DXdzSL X-Received: by 2002:a05:6a20:320c:b0:1a5:6f21:f8a8 with SMTP id hl12-20020a056a20320c00b001a56f21f8a8mr7502668pzc.15.1712614088936; Mon, 08 Apr 2024 15:08:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712614088; cv=pass; d=google.com; s=arc-20160816; b=uZRp8zbXGijOv1xggfK1qLNtMcjwpK556fEiejXTs4NaXhjwBjsqIezFt19lsFatZj h6CH0NZkqm/5ajHZxli01Flh/gn3Hn5SH1QAa/mejP9oXOXFcZ/72QEHZahjH7Pgm5id wjX4gFf0CnQLDrep45o1si1hdGt/GAs50yUmYLli+c+VUfKRd3wVYxfELyyffiBrDrpC VTrQrGspervXuXxHEx+IV9pLDjZQN/dO2iP88bBrmozOfXVeMz5I4SfMb5+MYMyAm03h gFMXy/Pt1sYQHWz82s4EMRlLv1HogR/owdm5p1FnKLOjMax2veXDmf1CJnVdIjt1dAju tehw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=BNWghUNyuV6Lk+YyDToi8Tsw6HLVZtok1GuBByD/mfA=; fh=qFbFrHQK5AkECBiUC4f6j0L4mgNvJ/4qZOq+z7unf0I=; b=v8lmxZVExzBgrziLwbdbSZY5RrATIY+z0BmPBkYIkNb6QX8Q714U6s4wZYjPDs7alZ eY/EMWi3615WAESQxQdLkrXyVKP1fGbk6r+PftSP2KSKgZp5dWzY3jzq0jhfGMnmgQaZ 20R4OG6UKdXTjARPikB3iq9aFTigNr0Hn2Cw2R9xA0fOvxpNPsvKhMJehBMpvgqrwyvo jviBHXjXogqoFuPE8+TY/BOEXlyF7cugtYfXL3b/8YjC/BOCH5MUpQOMdqaEDvTeTueR I5WCJbAYYnb4G8+j2FLH/dgV0b+KW29yZQBkUd9OFF+Ode/kKmfHHz5OBntoncjJjKxo bWvw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=moo4OuYb; arc=pass (i=1 spf=pass spfdomain=amazon.co.uk dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-135961-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135961-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d135-20020a63368d000000b005dc4a79c282si7073477pga.530.2024.04.08.15.08.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 15:08:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-135961-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=moo4OuYb; arc=pass (i=1 spf=pass spfdomain=amazon.co.uk dkim=pass dkdomain=amazon.com dmarc=pass fromdomain=amazon.com); spf=pass (google.com: domain of linux-kernel+bounces-135961-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-135961-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 9AB56284C72 for ; Mon, 8 Apr 2024 22:08:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3CA21149C70; Mon, 8 Apr 2024 22:08:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="moo4OuYb" Received: from smtp-fw-9106.amazon.com (smtp-fw-9106.amazon.com [207.171.188.206]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAF0B146A74; Mon, 8 Apr 2024 22:07:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=207.171.188.206 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712614079; cv=none; b=UWeV0m4LWh4F1Xv43NPVEmCESAHtIQyjBSeP6wczpOD1xqgM7EIN3mV/VT8VtbkOWnkd6g/aFHeiqauR8/zehoSAkmyruSC9w5wVbMh1RmiWjon/rusjqAR3QgO5J6knnGxZMV0ROlzhHVSuQKMTLJh+7CxNGAEUe/nF/VyEyM4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712614079; c=relaxed/simple; bh=P5hRDy1wg+C00YeG8BTUnFaiaw3vCXyKjsGOdD10sf4=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=TtjdI8xYqSI7sY/GFqof5KhtI+8KoP/HMFroS1eZbz7WPbifmdyi6cmGmtrVZ4Elk3NXl1rq2QFONRrdZ7LfHso/BWlxO7NUAsjvUQOVNXkTpA7xN/vZRPE11OmtjUmL3+s3XsYPbev9kElaGMJv0wVvI4oKUHd1ebDYY2xfrdQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com; spf=pass smtp.mailfrom=amazon.co.uk; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b=moo4OuYb; arc=none smtp.client-ip=207.171.188.206 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.co.uk DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1712614078; x=1744150078; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=BNWghUNyuV6Lk+YyDToi8Tsw6HLVZtok1GuBByD/mfA=; b=moo4OuYbI4mRHszXvSW5YzqcXxBnWbqrWfmewPhXBDX3GGnCeT0Xu6MP 6ejV2XG0i4e3B07jlSqiDunLaa5a9QjvW0w62P7VqiWnocQAiJz335O2S mrX0t0ata1LS0yE151bsqqTcvi63E2Vy0vfDZUTPIqeajm9NNk5iP6kZv w=; X-IronPort-AV: E=Sophos;i="6.07,187,1708387200"; d="scan'208";a="717029174" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-east-1.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-9106.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Apr 2024 22:07:51 +0000 Received: from EX19MTAEUA001.ant.amazon.com [10.0.17.79:39488] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.35.41:2525] with esmtp (Farcaster) id 3f231b9f-fb77-49ec-83b1-2a4b83555169; Mon, 8 Apr 2024 22:07:49 +0000 (UTC) X-Farcaster-Flow-ID: 3f231b9f-fb77-49ec-83b1-2a4b83555169 Received: from EX19D033EUC002.ant.amazon.com (10.252.61.215) by EX19MTAEUA001.ant.amazon.com (10.252.50.192) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 8 Apr 2024 22:07:43 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D033EUC002.ant.amazon.com (10.252.61.215) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Mon, 8 Apr 2024 22:07:43 +0000 Received: from dev-dsk-jalliste-1c-e3349c3e.eu-west-1.amazon.com (10.13.244.142) by mail-relay.amazon.com (10.252.135.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28 via Frontend Transport; Mon, 8 Apr 2024 22:07:42 +0000 From: Jack Allister To: Paolo Bonzini , Jonathan Corbet , Sean Christopherson , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , , "H. Peter Anvin" CC: David Woodhouse , Paul Durrant , "Jack Allister" , , , Subject: [PATCH 0/2] Add API to correct KVM/PV clock drift Date: Mon, 8 Apr 2024 22:07:02 +0000 Message-ID: <20240408220705.7637-1-jalliste@amazon.com> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit Guest VMs can be provided with a para-virtualized clock source to perform timekeeping. A KVM guest can map in a PV clock via the MSR_KVM_SYSTEM_TIME/MSR_KVM_SYSTEM_TIME_NEW virtualized MSRs. Where as on a Xen guest this can be provided via the vcpu/shared info pages. These PV clocks both use a common structure which is mapped between host <-> guest to provide the PVTI (paravirtual time information) for the clock. This reference information is a guest TSC timestamp and a host system time at a SINGULAR point in time. If KVM decides to update the reference information due to a KVM_REQ_MASTERCLOCK_UPDATE, a drift between the guest TSC and the PV clock can be observed, this is exascerbated when the guest TSC is also scaled too. If the reference guest TSC & system time within the structure stay the same there is no potential for a drift between the TSC and PV clock. This series adds in two patches, one to add in API/ioctl to allow a VMM to perform a correction/fixup of the PVTI structure when it knows that KVM may have updated the KVM clock information and a second one to verify that the drift is present & corrected. Jack Allister (2): KVM: x86: Add KVM_[GS]ET_CLOCK_GUEST for KVM clock drift fixup KVM: selftests: Add KVM/PV clock selftest to prove timer drift correction Documentation/virt/kvm/api.rst | 43 ++++ arch/x86/kvm/x86.c | 87 +++++++ include/uapi/linux/kvm.h | 3 + tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/x86_64/pvclock_test.c | 223 ++++++++++++++++++ 5 files changed, 357 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86_64/pvclock_test.c base-commit: 8cb4a9a82b21623dbb4b3051dd30d98356cf95bc -- 2.40.1