Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp3604327pxu; Tue, 8 Dec 2020 17:05:07 -0800 (PST) X-Google-Smtp-Source: ABdhPJz3ipDflnOlUwV13+k8jZ7PjrAV3nPccXF1dShL49BI688hCG3XNpZ/4YMuOt+Z2Q28CHQE X-Received: by 2002:a50:ed17:: with SMTP id j23mr596440eds.218.1607475907419; Tue, 08 Dec 2020 17:05:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607475907; cv=none; d=google.com; s=arc-20160816; b=cimRfniQMBHlcs6cTYdRsJvN5TEPZw1qBeo9gDAEn2GW333X23ZYbFxizWGtcgCTWR KOx28gO6NVQByL/1YwfKTLg4TQN41OM2KO4entAbOAkQi2Ku1gbISTrcGQgfvC9jHRsV XnPW/CabQdje+6UhI7nsPAk9dNNjU9271+phk24JChpumIBDway4FBjfERdU6kqQH9IL a0+RZJWdn0p5XAXOFRLd2dOcgUS7PYTZKyqrM2j9QPyfPrIgfVqdd2PEgSsRrDjk30AC G8if+kTi6aqyiaW4ZTAjzoiB4xeKIpIx9m4xHCW02Xog570J5YOVALxlrZP7dGNLyTIl WUEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=M9T5kVr+CAbU/Pqq1HubTPf8M564HNxJMPku0hKIlCY=; b=JG5aCRz50DbuYyEy2feJQDw4INTBV3bsm+pBIyzKhg9tBVBhwC9NsLCKDqa1CK+H4r K/BVUENxwj2eTgEu3QXufy8BJeVYUcURagpaoNSkb8U2+T/c3UxmPFmgLQsMjaZ+uFmC uwJDV/QsX4gkarV++0B45mfF/UQE0bVuDgIdPPxuciVXjA2Weh3D8xkrsG2YDHL7h2Mp HHZiuUkhUiohhAkMrfGabqJ5fIBfcaF5Sd76U+1AHT3rHbx56So4bEsc1ocQdu1T98vB uHD9TTwuDW9ZGmC7+e9q0c6qdsXkcjf8kov3pyyXI7tK1arTKLbLpul0VuwTWJsqnqFx 4NnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CONGvZf+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt15si77508ejc.661.2020.12.08.17.04.45; Tue, 08 Dec 2020 17:05:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=CONGvZf+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730964AbgLHSQL (ORCPT + 99 others); Tue, 8 Dec 2020 13:16:11 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:40774 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730468AbgLHSQK (ORCPT ); Tue, 8 Dec 2020 13:16:10 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1607451284; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=M9T5kVr+CAbU/Pqq1HubTPf8M564HNxJMPku0hKIlCY=; b=CONGvZf+gnY0rtarZdEzrEQHSNLbM5MN9JRhzPoAtAiFVoC4XKZHmNvkBsIJyWVfRfA7NZ F8529mw/8c2anZVbp/HdYPQd/6HA7uJkuFkBrfYGprAGyABMnMS372zDUyTpiEY+sfbenP mGa77Dn/eOdCbwgVQ1sLuyRvSCCO2b0= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-149-pdftyMXzODOmvHNI7kaGyA-1; Tue, 08 Dec 2020 13:14:42 -0500 X-MC-Unique: pdftyMXzODOmvHNI7kaGyA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4D8B8804002; Tue, 8 Dec 2020 18:14:40 +0000 (UTC) Received: from fuller.cnet (ovpn-112-8.gru2.redhat.com [10.97.112.8]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8D5D160877; Tue, 8 Dec 2020 18:14:39 +0000 (UTC) Received: by fuller.cnet (Postfix, from userid 1000) id 51416405CBC7; Tue, 8 Dec 2020 15:11:07 -0300 (-03) Date: Tue, 8 Dec 2020 15:11:07 -0300 From: Marcelo Tosatti To: Thomas Gleixner Cc: Maxim Levitsky , kvm@vger.kernel.org, "H. Peter Anvin" , Paolo Bonzini , Jonathan Corbet , Jim Mattson , Wanpeng Li , "open list:KERNEL SELFTEST FRAMEWORK" , Vitaly Kuznetsov , Sean Christopherson , open list , Ingo Molnar , "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" , Joerg Roedel , Borislav Petkov , Shuah Khan , Andrew Jones , Oliver Upton , "open list:DOCUMENTATION" Subject: Re: [PATCH v2 1/3] KVM: x86: implement KVM_{GET|SET}_TSC_STATE Message-ID: <20201208181107.GA31442@fuller.cnet> References: <20201203171118.372391-1-mlevitsk@redhat.com> <20201203171118.372391-2-mlevitsk@redhat.com> <20201207232920.GD27492@fuller.cnet> <05aaabedd4aac7d3bce81d338988108885a19d29.camel@redhat.com> <87sg8g2sn4.fsf@nanos.tec.linutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87sg8g2sn4.fsf@nanos.tec.linutronix.de> User-Agent: Mutt/1.10.1 (2018-07-13) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 08, 2020 at 05:02:07PM +0100, Thomas Gleixner wrote: > On Tue, Dec 08 2020 at 16:50, Maxim Levitsky wrote: > > On Mon, 2020-12-07 at 20:29 -0300, Marcelo Tosatti wrote: > >> > +This ioctl allows to reconstruct the guest's IA32_TSC and TSC_ADJUST value > >> > +from the state obtained in the past by KVM_GET_TSC_STATE on the same vCPU. > >> > + > >> > +If 'KVM_TSC_STATE_TIMESTAMP_VALID' is set in flags, > >> > +KVM will adjust the guest TSC value by the time that passed since the moment > >> > +CLOCK_REALTIME timestamp was saved in the struct and current value of > >> > +CLOCK_REALTIME, and set the guest's TSC to the new value. > >> > >> This introduces the wraparound bug in Linux timekeeping, doesnt it? > > Which bug? max_cycles overflow. Sent a message to Maxim describing it. > > > It does. > > Could you prepare a reproducer for this bug so I get a better idea about > > what are you talking about? > > > > I assume you need very long (like days worth) jump to trigger this bug > > and for such case we can either work around it in qemu / kernel > > or fix it in the guest kernel and I strongly prefer the latter. > > > > Thomas, what do you think about it? > > For one I have no idea which bug you are talking about and if the bug is > caused by the VMM then why would you "fix" it in the guest kernel. 1) Stop guest, save TSC value of cpu-0 = V. 2) Wait for some amount of time = W. 3) Start guest, load TSC value with V+W. Can cause an overflow on Linux timekeeping. > Aside of that I think I made it pretty clear what the right thing to do > is. Sure: the notion of a "unique TSC offset" already exists (it is detected by write TSC logic, and not explicit in the interface, though). But AFAIK it works pretty well. Exposing a single TSC value on the interface level seems alright to me...