Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5725801ybp; Tue, 15 Oct 2019 04:13:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqxaoWVopZBGAgEd5R7vevEcQK23nIj2IuaPbnnsYZLeB/0h60kOhZH7iMctXvR6M71RLpDl X-Received: by 2002:aa7:c24d:: with SMTP id y13mr33195335edo.186.1571138022839; Tue, 15 Oct 2019 04:13:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571138022; cv=none; d=google.com; s=arc-20160816; b=tghUEXWF50eXSOjnCbZFV19fTDm71J+B3ZuF97oU+REixV1D2srO7kLJnR3l6LOdre 9f+u/HZyeTBRUHsqVi8LXIitnupqjI98M13yIS41rPb74vBYGlibIB00Du7zPFpewN3l knePAvsQf+z2HBzE2tuQRD61YrhUQtvdcE97IFVCxPxRFoeDuU+/+9LBFaD+yPBszI76 pOwUMM7uxZH5cbG2fuJyosFxkt88e951b8G40h+UX2aORxTYfoPircSoUYXOWhMx1MRW rCaRdSSzev7vHCz0YySurz7WVENK9XejGzx5OIs6Tt4qhj1bqxWPveJsJfFKPKnEePJ0 BFmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=AqJilFgL4FnU7FTEYnrwYFbssjg64wIXPF6xmLsOmPw=; b=FLep/fj/iAvsgbSGt3u+e+d8f/PUqKskPiAyg91YbLw+VAtdbm4p/lR6K71YL7kWrC 5l/UrgvJfTX+vKjOPLbFeOptsmGHrT+Slt+/HKUkrnHhFjm+YsgpsHwdjBq3O7xk+EYa LpCm50ZEUsXtuxn3lTPzvjeqtcVCXGhKoi7uwIjfvX3t6jBkcMPwzMvQ8sOxAq9iduyT O/i50qMT+1/YMj5IYC1DRbN/1WuZNGpZmMrjyvofoFtxB7kmSWTU0NdC21bv8lzY591e zHE1TQ3DNDJ/lMhhIkja1jBLbKHhhOqufnQ31FslXnxdbsql7dO+hw++qhIcumuWLcqk jU7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="dMv5o/28"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w58si14639482edc.312.2019.10.15.04.13.19; Tue, 15 Oct 2019 04:13:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="dMv5o/28"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729310AbfJOIkI (ORCPT + 99 others); Tue, 15 Oct 2019 04:40:08 -0400 Received: from mail-yw1-f67.google.com ([209.85.161.67]:39215 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726275AbfJOIkI (ORCPT ); Tue, 15 Oct 2019 04:40:08 -0400 Received: by mail-yw1-f67.google.com with SMTP id n11so7052107ywn.6 for ; Tue, 15 Oct 2019 01:40:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=AqJilFgL4FnU7FTEYnrwYFbssjg64wIXPF6xmLsOmPw=; b=dMv5o/28lV5eqQ6bsstF+8kQTU23HpHM7uGA1mQx9OL8DufixiTQBhQczwb9OZFYYd 7W3cA2GyJed1k6hXVr/2rwc3AX6DJgZ3fQkDiaw+7l1yVgu2ZIXaPzA9kX08sm87OeAM FHNxHoazD5b78yRw0zB7eEiE82F/JskUc7JsqDiXies4CyeBbO2EKG4DTSl32NqdhIfx 6h7ICpf2yVbyT4NB4KWkpjk22CMGUG0adfxOhwVuaxE/drTDYt2FMC9CvUWdvcJPn64q H5oj5wSKb/hqXX3KhJalYdybL5MxH3ZboqDcmr0V8yvqmkIGQIMxj1j2P4/8zTvqfjOb zHMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=AqJilFgL4FnU7FTEYnrwYFbssjg64wIXPF6xmLsOmPw=; b=SsR7UMR26cTNVLa4Yh5ajcmLjDoNVS31qfYX55XMs+OZDJyMwVo2yhQfcm2aOOIMV1 XWQEtJC/B5G7kgPic9LusRjkQ6Yjqp0vAIX6afvmFQzwkStR1VuF10BvDyItNSXdurdy gFe3gIMtYUC+vRp45PtDskuP97PujX+FkvhghFnnXFFwvi8xyfLVvqQtxlgXGJJO4xrc 8z1X6lfBB6exvGyT9neW2XMlzkVgbEja+Bali+oxX+s1EvQn6C+xuCGfMbUSEG+E6wC8 ASNLx4eeo+2S1tX1oLdH+IlmqlKbgL0b3RTOMkG074geKBfIAuXsaBSyl6EOlzKiVnYE Vgqw== X-Gm-Message-State: APjAAAVbFqOJHXV6TldleN2+0XGsvYncZN5kDVFVlBfiJDfOev14gJ4v 7HJLXZM+3GwbOIGA4QDytS6V3ZUTbw4PRJ2qrUTwCA== X-Received: by 2002:a81:996:: with SMTP id 144mr16495099ywj.57.1571128807207; Tue, 15 Oct 2019 01:40:07 -0700 (PDT) MIME-Version: 1.0 References: <20191010073055.183635-1-suleiman@google.com> <20191010073055.183635-3-suleiman@google.com> <2e6e5b14-fa68-67bd-1436-293659c8d92c@redhat.com> In-Reply-To: <2e6e5b14-fa68-67bd-1436-293659c8d92c@redhat.com> From: Suleiman Souhlal Date: Tue, 15 Oct 2019 17:39:55 +0900 Message-ID: Subject: Re: [RFC v2 2/2] x86/kvmclock: Introduce kvm-hostclock clocksource. To: Paolo Bonzini Cc: rkrcmar@redhat.com, Thomas Gleixner , John Stultz , sboyd@kernel.org, Linux Kernel , kvm@vger.kernel.org, Suleiman Souhlal , tfiga@chromium.org, Vitaly Kuznetsov Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 10, 2019 at 7:55 PM Paolo Bonzini wrote: > > On 10/10/19 09:30, Suleiman Souhlal wrote: > > +kvm_hostclock_enable(struct clocksource *cs) > > +{ > > + pv_timekeeper_enabled = 1; > > + > > + old_vclock_mode = kvm_clock.archdata.vclock_mode; > > + kvm_clock.archdata.vclock_mode = VCLOCK_TSC; > > + return 0; > > +} > > + > > +static void > > +kvm_hostclock_disable(struct clocksource *cs) > > +{ > > + pv_timekeeper_enabled = 0; > > + kvm_clock.archdata.vclock_mode = old_vclock_mode; > > +} > > + > > Why do you poke at kvm_clock? Instead you should add > > .archdata = { .vclock_mode = VCLOCK_TSC }, > > to the kvm_hostclock declaration. Yeah, what I was doing does not make sense. > Please also check that the invariant TSC CPUID bit > CPUID[0x80000007].EDX[8] is set before enabling this feature. Will do. > > Paolo > > > + pvtk = &pv_timekeeper; > > + do { > > + gen = pvtk_read_begin(pvtk); > > + if (!(pv_timekeeper.flags & PVCLOCK_TIMEKEEPER_ENABLED)) > > + return; > > + > > + pvclock_copy_into_read_base(pvtk, &tk->tkr_mono, > > + &pvtk->tkr_mono); > > + pvclock_copy_into_read_base(pvtk, &tk->tkr_raw, &pvtk->tkr_raw); > > + > > + tk->xtime_sec = pvtk->xtime_sec; > > + tk->ktime_sec = pvtk->ktime_sec; > > + tk->wall_to_monotonic.tv_sec = pvtk->wall_to_monotonic_sec; > > + tk->wall_to_monotonic.tv_nsec = pvtk->wall_to_monotonic_nsec; > > + tk->offs_real = pvtk->offs_real; > > + tk->offs_boot = pvtk->offs_boot; > > + tk->offs_tai = pvtk->offs_tai; > > + tk->raw_sec = pvtk->raw_sec; > > + } while (pvtk_read_retry(pvtk, gen)); > > +} > > + > > Should you write an "enabled value" (basically the flags) into pvtk as well? I think we have that already (pvtk->flags). I'll change the if statement above to use pvtk instead of pv_timekeeper. > > +kvm_hostclock_init(void) > > +{ > > + unsigned long pa; > > + > > + pa = __pa(&pv_timekeeper); > > + wrmsrl(MSR_KVM_TIMEKEEPER_EN, pa); > > > As Vitaly said, a new CPUID bit must be defined in > Documentation/virt/kvm/cpuid.txt, and used here. Also please make bit 0 > an enable bit. I think I might not be able to move the enable bit to 0 because we need the generation count (pvclock_timekeeper.gen) to be the first word of the struct due to the way we copy the data to userspace, similarly to how kvm_setup_pvclock_page() does it. I also noticed the comment in kvm_copy_into_pvtk() references the wrong function, which I will fix in the next revision. Thanks for the feedback. -- Suleiman