Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2519209rdf; Mon, 6 Nov 2023 17:46:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRuwTTspSbF1fDK9f6UPKQR0Qi16gv4DFaXwnUC2dSd5cpxOePmkXnMfss6FqK/dMKHh4a X-Received: by 2002:a05:6870:d90:b0:1ef:3916:2d80 with SMTP id mj16-20020a0568700d9000b001ef39162d80mr1587944oab.46.1699321611170; Mon, 06 Nov 2023 17:46:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699321611; cv=pass; d=google.com; s=arc-20160816; b=eswVT/My12rc3nDIm2qrYyV7iCe2J7hK8CWGF3lJWsKXmGy+9jxpyWiJuZW6/t2xVi SPQ/VLLq4nRKKrFG0+NmRE6PDJckWJ71+RwloIktAqiJqlmysHNR9LRp53CZ2eN2aqPH wzy4yMaQvWmXyIrKL2X2p9QcpokURVMGI9Y0mqYTtTTdlTsSkq3mq9senkKHilsQtYRD TQUNtmqM1jYnCRQrE3nJlme38iZFcbXUPCmk0IuUalCJexPjRYvNVtz7aHIAObZeb5eO 2PZnC80Rj6FTKmrcDRmnbuSOuMce+HvUUHWK2RQZ1fGWuTIl1hb2BOPNpL8xj0bUCXwo Jb1w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:content-language:references:cc:to:subject :user-agent:date:message-id:dkim-signature:dkim-signature; bh=agTvBHR02OeyygRZgLboqrzt5YRrjSlw0lxXJ2iVB60=; fh=NVZZogljzoVbcCylqsB3oFtAUnn4z6j82EoBt3HrwOk=; b=MK9V8hIa4sjcprqQGEdbFmXF3QwTpcqrm/dP9Z04SeM0wU7OppV14KZFNnzAjQIIqQ FXvcUfFuCN/btdf904ApoChGqJpmDhPk9ICPmScjyOr0EGf1IAZCXD3jq2Vm7Hd1DgLX PW1h7Y9bTTB8Ogjoy6Qi0OBX2+5qCtOihN+3XN72t6SXuSXB/UyUxuVxOH6p6SW2tT0v WGvX4ft1npuNlt5HRm+JXyAnhjRK7mGwYLlQyQB7auKy5hp20RmFKEil1Bo9iSGghMS7 0tB7+tfsHzMr86pp/MhJGHQKx5tIstDJaiW1bTQG6pm8ZCEMQAL9AfntXFMUTcC4Mfp4 XbgA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=fHVChFJj; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=u67HN2Aq; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id m65-20020a633f44000000b005b22561c968si1011202pga.499.2023.11.06.17.46.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 17:46:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=fHVChFJj; dkim=pass header.i=@oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=u67HN2Aq; arc=pass (i=1 spf=pass spfdomain=oracle.com dkim=pass dkdomain=oracle.com dmarc=pass fromdomain=oracle.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 3516C806CC1A; Mon, 6 Nov 2023 17:45:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233243AbjKGBp4 (ORCPT + 99 others); Mon, 6 Nov 2023 20:45:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230208AbjKGBpy (ORCPT ); Mon, 6 Nov 2023 20:45:54 -0500 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 480751BF; Mon, 6 Nov 2023 17:45:50 -0800 (PST) Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A6MJ1te022015; Tue, 7 Nov 2023 01:45:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=message-id : date : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2023-03-30; bh=agTvBHR02OeyygRZgLboqrzt5YRrjSlw0lxXJ2iVB60=; b=fHVChFJjqsDU9jgUT78oLXeVn82moyk5/qiGg+53VnHOZ19uDfQlp1fXMliOvBzfnizA DzemhQVJyJS50qrH0IALWSCEuzvaGYW9ww4JdFCuoO1MAhCEysVLPOe1RsFdpNnIJTSh nxz9gpZnEndWWTtQGSb4/H+BSKLgz2SquqEjcgi+zvDONh0HjKuL5RJzvI4dnZpffRtB TO/KXvlFuBN4CMb+LPcSXZLlPLnCPJpyjFvYfCN0LMzak+UYInC9zxEffrVw79z7eVcE lAMuDA0Kx1C7IyyZWx5v3uuWh/45BJLRQnw3EL3VhUVacAEac8Q/Ip9IkaIDJyawhRaf jg== Received: from phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta03.appoci.oracle.com [138.1.37.129]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3u5e0dvux0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 07 Nov 2023 01:45:00 +0000 Received: from pps.filterd (phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 3A6NskFb026788; Tue, 7 Nov 2023 01:44:59 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2169.outbound.protection.outlook.com [104.47.56.169]) by phxpaimrmta03.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3u5cd62a6j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 07 Nov 2023 01:44:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jgM6ZTq058oJTLvchLcwpwJQwaS1wG81tV4viBPwdj7xoVUGSOXpOGndWvfdGRpzpatpBlqajAcxH5uNH+fuhtDRrp7e6TIoAEZwaSV7pJa1+iBToE6cNLvBrJDsgmKbpG5uWjbJ6kb0fQd0qwpG+8+Xt4fnF4tf7dOqMtyeLcbczfuhKBe//ZZgmqFNpT6i2su2Q3l18FqB0+KTLX+FBdoTTqRhZIcIsRD1NNGR5ai8VtlmiJ8dFHaXbD5m66TXkw95CSg3LBMxToyv6yQ/XJ7lsGDkRW4gdWx+yoVX7qH89jr0kTkdAW+YnBQIzZfwZgTiJx1U+FiP7uyyclZbuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=agTvBHR02OeyygRZgLboqrzt5YRrjSlw0lxXJ2iVB60=; b=HdTXgGO0hkIk5wdmjwkyTM85RbyyyHM9ItIRlIETYzasa+u3baWpEwAvgchqtXxnVY4IcwbTkni7KBw8G5KvXmSYKZP6IGmDTLfwEZB7O4G45B41qmp8Amc0yhV4XlpUicmlPSkBgrhDVtWKwCqT6gpke4nnTvwqZq5iyHo7it31wVe//FTSnZaWUM9gAosy1MEXjr4yyNo64qYWV2aD1rS4n9ZPQ/64vwb7Idj1b3WygTDRhoH6/wDO8WTNRf31PqMoPOnIfdQ0ZKNo3nyIxnptqB9fWzJ4haj4nYXIMztQ1A33HMI5UH+iEOqHcN7mUdYke27QcCOA8xBw4joqyQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=agTvBHR02OeyygRZgLboqrzt5YRrjSlw0lxXJ2iVB60=; b=u67HN2AqupUezbp+inUb6kiWQo1Ks0uhL0PVPovEZZSatSIk3dTUQyAW3C3QQwwi5f9dStX5U9/6HF8sJ3ygRxObm1Hpfe+tKbmaZp1k2qGN/j8+6hK7UcYQk9sORRHsEgxlACU5l7PjnMN192lqkCU4eA2k88yleJWLrvZwMfU= Received: from BN7PR10MB2659.namprd10.prod.outlook.com (2603:10b6:406:c5::18) by CH2PR10MB4293.namprd10.prod.outlook.com (2603:10b6:610:7f::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.28; Tue, 7 Nov 2023 01:44:54 +0000 Received: from BN7PR10MB2659.namprd10.prod.outlook.com ([fe80::2ee7:8dce:dd6f:4b5]) by BN7PR10MB2659.namprd10.prod.outlook.com ([fe80::2ee7:8dce:dd6f:4b5%7]) with mapi id 15.20.6954.029; Tue, 7 Nov 2023 01:44:54 +0000 Message-ID: <2bd5d543-08a0-a0f6-0f59-b8724a2d8d75@oracle.com> Date: Mon, 6 Nov 2023 17:44:47 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH v2] KVM: x86/xen: improve accuracy of Xen timers To: David Woodhouse , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Paul Durrant , Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" References: <96da7273adfff2a346de9a4a27ce064f6fe0d0a1.camel@infradead.org> <74f32bfae7243a78d0e74b1ba3a2d1ea4a4a7518.camel@infradead.org> Content-Language: en-US From: Dongli Zhang In-Reply-To: <74f32bfae7243a78d0e74b1ba3a2d1ea4a4a7518.camel@infradead.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: SJ0PR05CA0100.namprd05.prod.outlook.com (2603:10b6:a03:334::15) To BN7PR10MB2659.namprd10.prod.outlook.com (2603:10b6:406:c5::18) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN7PR10MB2659:EE_|CH2PR10MB4293:EE_ X-MS-Office365-Filtering-Correlation-Id: 174b6b13-d1df-4034-bb4c-08dbdf3323f3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HWJFNFUZ2M1S6sL9tT89k3lo6EmX3hCHO/WEaURJnf8T78/f24pGxw+u5UiFbofdvY5sbh4W0LHJ4RH/RCJaRqxM+5ty8rCxIWcmzbR4drEt4h0Nmw88VplyF4An5+tWQXHB6qlDIBtrfQ78JEHnGHFK3O/Cd5COIRzOjSMSqy+EHxWi/SJhoXEVjg/9f57wYY3J97sqXyTjLAew1q5woG1/93+/Y5zhMbd4V8NG14RZDKrlJgjVTYKj1FVH5/oRq/kQmbiRuUSsopmNFNJ1gCszEnozPRua3LiMMi++pKQwjahfV+N5saQvodPT6mM5DOWXIZrdKqc63KHKAAu5f7nJoC7nUevoi2ZFsN0gwppsRyZFgu9CCPaj8u/Q28uACiOr5qs7ST95L9OvzVPba8bV3yYHTc6iaVwCjtRhQM7SmfyJHFzA912reK8+ucyhY1fy4k3XUrp1Eonk10toyAAdJKfckPwV706CjkHtH/1luIdneJcR3bXIX2GRFO2xeg3osZE6e5loXwINGaXGoUclfmpl8wICktj3U3BI+R3w0MN1HeIzJN5dZ7dWFlXzkd6V4lDpUUDYKybiwp0lQkYc432fV10/gawF2OB6sHsAa4IPQ4+g7aw4Pkon83G/OLvL6NWeIzPACBBdiCy7Iw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN7PR10MB2659.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(39860400002)(136003)(396003)(346002)(366004)(230922051799003)(1800799009)(64100799003)(451199024)(186009)(31686004)(6486002)(66556008)(6506007)(6512007)(6666004)(53546011)(478600001)(66946007)(66476007)(36756003)(31696002)(86362001)(26005)(38100700002)(2616005)(83380400001)(8676002)(30864003)(2906002)(7416002)(5660300002)(54906003)(41300700001)(316002)(4326008)(966005)(8936002)(44832011)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?YUFKTGpwdGRqTHJoenljQWkvS2dvRSs0U1FJMCtQSVNodk1nVE42ZGJLc3NT?= =?utf-8?B?dEY1VVpIWnM2LzVuejNTK0RUQVcwQUVjTVdKOUdGYjNQcFk2S3RXcHRqclR3?= =?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-4034-bb4c-08dbdf3323f3 X-MS-Exchange-CrossTenant-AuthSource: BN7PR10MB2659.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Nov 2023 01:44:54.4989 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 0mv7+LBfOqHwq4Ky2Xp+es3tHZIxmEBLoY9Nh5md8C74dsBzh6SbawoSLRtzbb8742o6gp5H8BDo+WEV8IjpFg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR10MB4293 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-06_15,2023-11-02_03,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 malwarescore=0 spamscore=0 suspectscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2310240000 definitions=main-2311070013 X-Proofpoint-GUID: z_MNbGls7wEOhqE0UXaWJXgKyTxD2t_w X-Proofpoint-ORIG-GUID: z_MNbGls7wEOhqE0UXaWJXgKyTxD2t_w X-Spam-Status: No, score=-5.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 06 Nov 2023 17:45:57 -0800 (PST) Hi David, On 10/31/23 16:13, David Woodhouse wrote: > From: David Woodhouse > > A test program such as http://david.woodhou.se/timerlat.c confirms user > reports that timers are increasingly inaccurate as the lifetime of a > guest increases. Reporting the actual delay observed when asking for > 100µs of sleep, it starts off OK on a newly-launched guest but gets > worse over time, giving incorrect sleep times: > > root@ip-10-0-193-21:~# ./timerlat -c -n 5 > 00000000 latency 103243/100000 (3.2430%) > 00000001 latency 103243/100000 (3.2430%) > 00000002 latency 103242/100000 (3.2420%) > 00000003 latency 103245/100000 (3.2450%) > 00000004 latency 103245/100000 (3.2450%) > > The biggest problem is that get_kvmclock_ns() returns inaccurate values > when the guest TSC is scaled. The guest sees a TSC value scaled from the > host TSC by a mul/shift conversion (hopefully done in hardware). The > guest then converts that guest TSC value into nanoseconds using the > mul/shift conversion given to it by the KVM pvclock information. > > But get_kvmclock_ns() performs only a single conversion directly from > host TSC to nanoseconds, giving a different result. A test program at > http://david.woodhou.se/tsdrift.c demonstrates the cumulative error > over a day. > > It's non-trivial to fix get_kvmclock_ns(), although I'll come back to > that. The actual guest hv_clock is per-CPU, and *theoretically* each > vCPU could be running at a *different* frequency. But this patch is > needed anyway because... > > The other issue with Xen timers was that the code would snapshot the > host CLOCK_MONOTONIC at some point in time, and then... after a few > interrupts may have occurred, some preemption perhaps... would also read > the guest's kvmclock. Then it would proceed under the false assumption > that those two happened at the *same* time. Any time which *actually* > elapsed between reading the two clocks was introduced as inaccuracies > in the time at which the timer fired. > > Fix it to use a variant of kvm_get_time_and_clockread(), which reads the > host TSC just *once*, then use the returned TSC value to calculate the > kvmclock (making sure to do that the way the guest would instead of > making the same mistake get_kvmclock_ns() does). > > Sadly, hrtimers based on CLOCK_MONOTONIC_RAW are not supported, so Xen > timers still have to use CLOCK_MONOTONIC. In practice the difference > between the two won't matter over the timescales involved, as the > *absolute* values don't matter; just the delta. > > This does mean a new variant of kvm_get_time_and_clockread() is needed; > called kvm_get_monotonic_and_clockread() because that's what it does. > > Signed-off-by: David Woodhouse > Reviewed-by: Paul Durrant > > --- > v2:  > • Fall back to get_kvmclock_ns() if vcpu-arch.hv_clock isn't set up > yet, with a big comment explaining why that's actually OK. > • Fix do_monotonic() *not* to add the boot time offset. > • Rename do_monotonic_raw() → do_kvmclock_base() and add a comment > to make it clear that it *does* add the boot time offset. That > was just left as a bear trap for the unwary developer, wasn't it? > > arch/x86/kvm/x86.c | 61 +++++++++++++++++++++-- > arch/x86/kvm/x86.h | 1 + > arch/x86/kvm/xen.c | 121 ++++++++++++++++++++++++++++++++++----------- > 3 files changed, 149 insertions(+), 34 deletions(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 6eaab714d90a..e479637af42c 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -2844,7 +2844,11 @@ static inline u64 vgettsc(struct pvclock_clock *clock, u64 *tsc_timestamp, > return v * clock->mult; > } > > -static int do_monotonic_raw(s64 *t, u64 *tsc_timestamp) > +/* > + * As with get_kvmclock_base_ns(), this counts from boot time, at the > + * frequency of CLOCK_MONOTONIC_RAW (hence adding gtos->offs_boot). > + */ > +static int do_kvmclock_base(s64 *t, u64 *tsc_timestamp) > { > struct pvclock_gtod_data *gtod = &pvclock_gtod_data; > unsigned long seq; > @@ -2863,6 +2867,29 @@ static int do_monotonic_raw(s64 *t, u64 *tsc_timestamp) > return mode; > } > > +/* > + * This calculates CLOCK_MONOTONIC at the time of the TSC snapshot, with > + * no boot time offset. > + */ > +static int do_monotonic(s64 *t, u64 *tsc_timestamp) > +{ > + struct pvclock_gtod_data *gtod = &pvclock_gtod_data; > + unsigned long seq; > + int mode; > + u64 ns; > + > + do { > + seq = read_seqcount_begin(>od->seq); > + ns = gtod->clock.base_cycles; > + ns += vgettsc(>od->clock, tsc_timestamp, &mode); > + ns >>= gtod->clock.shift; > + ns += ktime_to_ns(gtod->clock.offset); > + } while (unlikely(read_seqcount_retry(>od->seq, seq))); > + *t = ns; > + > + return mode; > +} > + > static int do_realtime(struct timespec64 *ts, u64 *tsc_timestamp) > { > struct pvclock_gtod_data *gtod = &pvclock_gtod_data; > @@ -2884,18 +2911,42 @@ static int do_realtime(struct timespec64 *ts, u64 *tsc_timestamp) > return mode; > } > > -/* returns true if host is using TSC based clocksource */ > +/* > + * Calculates the kvmclock_base_ns (CLOCK_MONOTONIC_RAW + boot time) and > + * reports the TSC value from which it do so. Returns true if host is > + * using TSC based clocksource. > + */ > static bool kvm_get_time_and_clockread(s64 *kernel_ns, u64 *tsc_timestamp) > { > /* checked again under seqlock below */ > if (!gtod_is_based_on_tsc(pvclock_gtod_data.clock.vclock_mode)) > return false; > > - return gtod_is_based_on_tsc(do_monotonic_raw(kernel_ns, > - tsc_timestamp)); > + return gtod_is_based_on_tsc(do_kvmclock_base(kernel_ns, > + tsc_timestamp)); > } > > -/* returns true if host is using TSC based clocksource */ > +/* > + * Calculates CLOCK_MONOTONIC and reports the TSC value from which it did > + * so. Returns true if host is using TSC based clocksource. > + */ > +bool kvm_get_monotonic_and_clockread(s64 *kernel_ns, u64 *tsc_timestamp) > +{ > + /* checked again under seqlock below */ > + if (!gtod_is_based_on_tsc(pvclock_gtod_data.clock.vclock_mode)) > + return false; > + > + return gtod_is_based_on_tsc(do_monotonic(kernel_ns, > + tsc_timestamp)); > +} > + > +/* > + * Calculates CLOCK_REALTIME and reports the TSC value from which it did > + * so. Returns true if host is using TSC based clocksource. > + * > + * DO NOT USE this for anything related to migration. You want CLOCK_TAI > + * for that. > + */ > static bool kvm_get_walltime_and_clockread(struct timespec64 *ts, > u64 *tsc_timestamp) > { > diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h > index 1e7be1f6ab29..c08c6f729965 100644 > --- a/arch/x86/kvm/x86.h > +++ b/arch/x86/kvm/x86.h > @@ -293,6 +293,7 @@ static inline bool kvm_check_has_quirk(struct kvm *kvm, u64 quirk) > void kvm_inject_realmode_interrupt(struct kvm_vcpu *vcpu, int irq, int inc_eip); > > u64 get_kvmclock_ns(struct kvm *kvm); > +bool kvm_get_monotonic_and_clockread(s64 *kernel_ns, u64 *tsc_timestamp); > > int kvm_read_guest_virt(struct kvm_vcpu *vcpu, > gva_t addr, void *val, unsigned int bytes, > diff --git a/arch/x86/kvm/xen.c b/arch/x86/kvm/xen.c > index 751d9a984668..e3d2d63eef34 100644 > --- a/arch/x86/kvm/xen.c > +++ b/arch/x86/kvm/xen.c > @@ -24,6 +24,7 @@ > #include > > #include > +#include > > #include "cpuid.h" > #include "trace.h" > @@ -158,8 +159,93 @@ static enum hrtimer_restart xen_timer_callback(struct hrtimer *timer) > return HRTIMER_NORESTART; > } > > -static void kvm_xen_start_timer(struct kvm_vcpu *vcpu, u64 guest_abs, s64 delta_ns) > +static void kvm_xen_start_timer(struct kvm_vcpu *vcpu, u64 guest_abs, > + bool linux_wa) > { > + uint64_t guest_now; > + int64_t kernel_now, delta; > + > + /* > + * The guest provides the requested timeout in absolute nanoseconds > + * of the KVM clock — as *it* sees it, based on the scaled TSC and > + * the pvclock information provided by KVM. > + * > + * The kernel doesn't support hrtimers based on CLOCK_MONOTONIC_RAW > + * so use CLOCK_MONOTONIC. In the timescales covered by timers, the > + * difference won't matter much as there is no cumulative effect. > + * > + * Calculate the time for some arbitrary point in time around "now" > + * in terms of both kvmclock and CLOCK_MONOTONIC. Calculate the > + * delta between the kvmclock "now" value and the guest's requested > + * timeout, apply the "Linux workaround" described below, and add > + * the resulting delta to the CLOCK_MONOTONIC "now" value, to get > + * the absolute CLOCK_MONOTONIC time at which the timer should > + * fire. > + */ > + if (vcpu->arch.hv_clock.version && vcpu->kvm->arch.use_master_clock && > + static_cpu_has(X86_FEATURE_CONSTANT_TSC)) { If there any reason to use both vcpu->kvm->arch.use_master_clock and X86_FEATURE_CONSTANT_TSC? I think even __get_kvmclock() would not require both cases at the same time? 3071 if (ka->use_master_clock && 3072 (static_cpu_has(X86_FEATURE_CONSTANT_TSC) || __this_cpu_read(cpu_tsc_khz))) { > + uint64_t host_tsc, guest_tsc; > + > + if (!IS_ENABLED(CONFIG_64BIT) || > + !kvm_get_monotonic_and_clockread(&kernel_now, &host_tsc)) { > + /* > + * Don't fall back to get_kvmclock_ns() because it's > + * broken; it has a systemic error in its results > + * because it scales directly from host TSC to > + * nanoseconds, and doesn't scale first to guest TSC > + * and then* to nanoseconds as the guest does. > + * > + * There is a small error introduced here because time > + * continues to elapse between the ktime_get() and the > + * subsequent rdtsc(). But not the systemic drift due > + * to get_kvmclock_ns(). > + */ > + kernel_now = ktime_get(); /* This is CLOCK_MONOTONIC */ > + host_tsc = rdtsc(); > + } > + > + /* Calculate the guest kvmclock as the guest would do it. */ > + guest_tsc = kvm_read_l1_tsc(vcpu, host_tsc); > + guest_now = __pvclock_read_cycles(&vcpu->arch.hv_clock, > + guest_tsc); > + } else { > + /* > + * Without CONSTANT_TSC, get_kvmclock_ns() is the only option. > + * > + * Also if the guest PV clock hasn't been set up yet, as is > + * likely to be the case during migration when the vCPU has > + * not been run yet. It would be possible to calculate the > + * scaling factors properly in that case but there's not much > + * point in doing so. The get_kvmclock_ns() drift accumulates > + * over time, so it's OK to use it at startup. Besides, on > + * migration there's going to be a little bit of skew in the > + * precise moment at which timers fire anyway. Often they'll > + * be in the "past" by the time the VM is running again after > + * migration. > + */ > + guest_now = get_kvmclock_ns(vcpu->kvm); > + kernel_now = ktime_get(); 1. Can I assume the issue is still there if we fall into the "else" case? That is, the increasing inaccuracy as the VM has been up for longer and longer time? If that is the case, which may be better? (1) get_kvmclock_ns(), or (2) always get_kvmclock_base_ns() + ka->kvmclock_offset, when pvclock is not enabled, regardless whether master clock is used. At least, the inaccurary is not going to increase over guest time? 2. I see 3 scenarios here: (1) vcpu->arch.hv_clock.version and master clock is used. In this case, the bugfix looks good. (2) The master clock is used. However, pv clock is not enabled. In this case, the bug is not resolved? ... even the master clock is used. (3) The master clock is not used. We fall into get_kvmclock_base_ns() + ka->kvmclock_offset. The behavior is not changed. This looks good. Just from my own point: as this patch involves relatively complex changes, I would suggest resolve the issue, but not use a temporary solution :) (I see you mentioned that you will be back with get_kvmclock_ns()) Based on your bug fix, I see the below cases: If master clock is not used: get_kvmclock_base_ns() + ka->kvmclock_offset If master clock is used: If pvclock is enabled: use the &vcpu->arch.hv_clock to get current guest time Else create a temporary hv_clock, based on masterclock. Regarding the temporary solution, I would suggest create a new API to encapsulate and fulfill above scenarios, if we are not going to touch __get_kvmclock() at this time point. Thank you very much! Dongli Zhang > + } > + > + delta = guest_abs - guest_now; > + > + /* Xen has a 'Linux workaround' in do_set_timer_op() which > + * checks for negative absolute timeout values (caused by > + * integer overflow), and for values about 13 days in the > + * future (2^50ns) which would be caused by jiffies > + * overflow. For those cases, it sets the timeout 100ms in > + * the future (not *too* soon, since if a guest really did > + * set a long timeout on purpose we don't want to keep > + * churning CPU time by waking it up). > + */ > + if (linux_wa) { > + if ((unlikely((int64_t)guest_abs < 0 || > + (delta > 0 && (uint32_t) (delta >> 50) != 0)))) { > + delta = 100 * NSEC_PER_MSEC; > + guest_abs = guest_now + delta; > + } > + } > + > /* > * Avoid races with the old timer firing. Checking timer_expires > * to avoid calling hrtimer_cancel() will only have false positives > @@ -171,12 +257,11 @@ static void kvm_xen_start_timer(struct kvm_vcpu *vcpu, u64 guest_abs, s64 delta_ > atomic_set(&vcpu->arch.xen.timer_pending, 0); > vcpu->arch.xen.timer_expires = guest_abs; > > - if (delta_ns <= 0) { > + if (delta <= 0) { > xen_timer_callback(&vcpu->arch.xen.timer); > } else { > - ktime_t ktime_now = ktime_get(); > hrtimer_start(&vcpu->arch.xen.timer, > - ktime_add_ns(ktime_now, delta_ns), > + ktime_add_ns(kernel_now, delta), > HRTIMER_MODE_ABS_HARD); > } > } > @@ -945,8 +1030,7 @@ int kvm_xen_vcpu_set_attr(struct kvm_vcpu *vcpu, struct kvm_xen_vcpu_attr *data) > /* Start the timer if the new value has a valid vector+expiry. */ > if (data->u.timer.port && data->u.timer.expires_ns) > kvm_xen_start_timer(vcpu, data->u.timer.expires_ns, > - data->u.timer.expires_ns - > - get_kvmclock_ns(vcpu->kvm)); > + false); > > r = 0; > break; > @@ -1389,7 +1473,6 @@ static bool kvm_xen_hcall_vcpu_op(struct kvm_vcpu *vcpu, bool longmode, int cmd, > { > struct vcpu_set_singleshot_timer oneshot; > struct x86_exception e; > - s64 delta; > > if (!kvm_xen_timer_enabled(vcpu)) > return false; > @@ -1423,9 +1506,7 @@ static bool kvm_xen_hcall_vcpu_op(struct kvm_vcpu *vcpu, bool longmode, int cmd, > return true; > } > > - /* A delta <= 0 results in an immediate callback, which is what we want */ > - delta = oneshot.timeout_abs_ns - get_kvmclock_ns(vcpu->kvm); > - kvm_xen_start_timer(vcpu, oneshot.timeout_abs_ns, delta); > + kvm_xen_start_timer(vcpu, oneshot.timeout_abs_ns, false); > *r = 0; > return true; > > @@ -1449,25 +1530,7 @@ static bool kvm_xen_hcall_set_timer_op(struct kvm_vcpu *vcpu, uint64_t timeout, > return false; > > if (timeout) { > - uint64_t guest_now = get_kvmclock_ns(vcpu->kvm); > - int64_t delta = timeout - guest_now; > - > - /* Xen has a 'Linux workaround' in do_set_timer_op() which > - * checks for negative absolute timeout values (caused by > - * integer overflow), and for values about 13 days in the > - * future (2^50ns) which would be caused by jiffies > - * overflow. For those cases, it sets the timeout 100ms in > - * the future (not *too* soon, since if a guest really did > - * set a long timeout on purpose we don't want to keep > - * churning CPU time by waking it up). > - */ > - if (unlikely((int64_t)timeout < 0 || > - (delta > 0 && (uint32_t) (delta >> 50) != 0))) { > - delta = 100 * NSEC_PER_MSEC; > - timeout = guest_now + delta; > - } > - > - kvm_xen_start_timer(vcpu, timeout, delta); > + kvm_xen_start_timer(vcpu, timeout, true); > } else { > kvm_xen_stop_timer(vcpu); > }