Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp27453lqj; Wed, 10 Apr 2024 02:53:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWWQ/AQaGjjeb2sRW/RRUxjt93gAWGL2CgpKdmY+yAHjQBYDmuQIokpsZMATWL7wbZxEr9tvXZ2/HORMqHtHYeow/4ZQb3RDnEY2KhumQ== X-Google-Smtp-Source: AGHT+IHojnbYS53bCH3LHA5+yjliKP210fkOEM1i5yQ1nKlbiO7RqnDlloOgWnVhdP5yLE6FzRtu X-Received: by 2002:a05:6218:288b:b0:183:f0e8:b632 with SMTP id vw11-20020a056218288b00b00183f0e8b632mr2628621rwc.11.1712742796241; Wed, 10 Apr 2024 02:53:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712742796; cv=pass; d=google.com; s=arc-20160816; b=WoOI3xks0QDu9Djy5CuENYIFtgJ7MFnhQKwuqW2gTnEOMDs18xc5egnKoWA74y25FG bJ8fqbXfX89uE2SlG0uylHuxngDHXwZmGcAvPOcPu4Z40e95kPJOWcNwQCrN8GGDTrrC GQuNFxg05L062bGjjm70Bm/sestNUrsloZUbzAXUrj0dcGpeF5effm1HiiWXNNyPTQmU sA7jizh3uz3w+vjhtuMR8R6UKyDXrJwP1npgsplpWDAYg5OY7TFCqbDvGLPRPpq5LUKK 69T3iQeKn+zXLjz6u2oa4boYqJs6S28LUDMUjAdzzvteqETH2YEcaF+3xzTkEBr2AZ0w GKeg== 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:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=sPon1mXI+9ynIGKH9frtzwF2RXP9ZgEapOTvbd3zMzg=; fh=JuXCW1KEO1MM8tcYFZXOCT7c1nzdpRvVVoX6RIMtevY=; b=DIpp8RLiklztlNeE5irYuV2CaF2cCdemDTF2A+7bJEUj3R3jBxDwLQNGaUrfZqUNdp uwgTwwk79dmQrXpTTD6rtdGbQQfAKKJHnkmV+j761h8bmnROvz9iSM/67Hjgmlonfs84 1GpUEmT5qH/phpn+Zb/4u9kqh2p4IwP80qvxHxVeq5kxHvegtKUqDn22THrNpCSvlr0V Xcd9yDRuRxhwPPVcvvG+KIhSBXKEJxdbbulNr67zmn8bVvKOkuZXaMUi84o4PERLZ5+d AweF7h8Ql7xxSwfKfjQ/4P5pJ42FmRln13VcwX4GWmi5Gqi72YU3DxAxnC+jCtyUaoFk Gxag==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=j1KKqWsG; 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-138284-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138284-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 g4-20020a63f404000000b005dc962cfb59si10657102pgi.350.2024.04.10.02.53.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 02:53:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-138284-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=j1KKqWsG; 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-138284-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138284-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 BCD2A282130 for ; Wed, 10 Apr 2024 09:53:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 24F94156F2F; Wed, 10 Apr 2024 09:52:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amazon.com header.i=@amazon.com header.b="j1KKqWsG" Received: from smtp-fw-80009.amazon.com (smtp-fw-80009.amazon.com [99.78.197.220]) (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 ADF8E156C67; Wed, 10 Apr 2024 09:52:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=99.78.197.220 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712742775; cv=none; b=YBtAdjsF+Nov/1Q16HS/S3TQLxYMzkM6y+mJwmGOJW1Jf9zC8nJ0bWgLEVmQqBNkzpn44G/XB3El6HCnBdirkh6yRtIZiU5mb0I9K+8WTfJesLYaae3UxFFFBNo5seN3AmaTR9AAei7/2h8scfc19TzXfucuO8PStjby+H/Y7Vo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712742775; c=relaxed/simple; bh=ALOoJxUUYtcFrIKDN0P9vAhj1e860/PKGwkGEawya54=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=upn/Ybnk8x4QMmlSyk8bXGQvFl/OHuA0IoOSoHJ9s23YyQKbZ9Ss9qUSXg/RxFBGZL4W+yGVZ8sQBX9AWV9S2cIr/6oosAtIMFHoe1zQS7WmKMtD9m2k12fcS+5W0shOhsmCHiCZYHltzgGbybCKVUrNIlRRUrNV0X2q2v34N1I= 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=j1KKqWsG; arc=none smtp.client-ip=99.78.197.220 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=1712742773; x=1744278773; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=sPon1mXI+9ynIGKH9frtzwF2RXP9ZgEapOTvbd3zMzg=; b=j1KKqWsGPHdhu+wiQzgdEdyRiu/xEjWD9lU6wI3Nh9vwL8I/zb7IvL4e tLc+OKtU/JL4L165vrOJJbP0Tn0ypW4/eoMcsd+lB1UMa1qMWBvcdzD9L 9fErvf7kobcLz2LlVAmlgjp1kqo8NXLEXEjIyyiGlOmEGA/6mgeul6F0Q E=; X-IronPort-AV: E=Sophos;i="6.07,190,1708387200"; d="scan'208";a="80126940" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO smtpout.prod.us-west-2.prod.farcaster.email.amazon.dev) ([10.25.36.210]) by smtp-border-fw-80009.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Apr 2024 09:52:50 +0000 Received: from EX19MTAEUA002.ant.amazon.com [10.0.10.100:58373] by smtpin.naws.eu-west-1.prod.farcaster.email.amazon.dev [10.0.47.234:2525] with esmtp (Farcaster) id 693a12aa-a827-4eff-bc1b-4460d40d8f1c; Wed, 10 Apr 2024 09:52:50 +0000 (UTC) X-Farcaster-Flow-ID: 693a12aa-a827-4eff-bc1b-4460d40d8f1c Received: from EX19D033EUC001.ant.amazon.com (10.252.61.132) by EX19MTAEUA002.ant.amazon.com (10.252.50.126) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Wed, 10 Apr 2024 09:52:49 +0000 Received: from EX19MTAUEB001.ant.amazon.com (10.252.135.35) by EX19D033EUC001.ant.amazon.com (10.252.61.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.28; Wed, 10 Apr 2024 09:52:49 +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; Wed, 10 Apr 2024 09:52:48 +0000 From: Jack Allister To: CC: , , , , , , , , , , , , , Subject: [PATCH v2 0/2] Add API for accurate KVM/PV clock migration Date: Wed, 10 Apr 2024 09:52:42 +0000 Message-ID: <20240410095244.77109-1-jalliste@amazon.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240408220705.7637-1-jalliste@amazon.com> References: <20240408220705.7637-1-jalliste@amazon.com> 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. Upon a live-update of a host or live-migration of an instance the PVTI may be recalculated by KVM. Using the existing KVM_[GS]ET_CLOCK functionality the relationship between the TSC and PV clock cannot be precisely saved and restored by userspace. This series adds in two patches, one to add in a new interface to allow a VMM/userspace to perform a correction of the PVTI structure. Then a second to verify the imprecision after a simulation of a live-update/migration and then to verify the correction is to within ±1ns. v1: https://lore.kernel.org/all/20240408220705.7637-1-jalliste@amazon.com/ v2: - Moved new IOCTLs from vm to vcpu level. - Adds extra error checks as suggested by Dongli Zhang / David Woodhouse. - Adds on-demand calculation of PVTI if non currently present in vcpu. - Adds proper synchronization for PV clock during correction. - Added option to test without TSC scaling in sefltest. - Updated commit messages to better explain the situation (thanks David). Jack Allister (2): KVM: x86: Add KVM_[GS]ET_CLOCK_GUEST for accurate KVM clock migration KVM: selftests: Add KVM/PV clock selftest to prove timer correction Documentation/virt/kvm/api.rst | 37 ++++ arch/x86/kvm/x86.c | 124 +++++++++++ include/uapi/linux/kvm.h | 3 + tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/x86_64/pvclock_test.c | 192 ++++++++++++++++++ 5 files changed, 357 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86_64/pvclock_test.c base-commit: 8cb4a9a82b21623dbb4b3051dd30d98356cf95bc -- 2.40.1