Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3881188pxv; Tue, 13 Jul 2021 06:06:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLytc7Dh+EYue61bv4dq4wNbP0Vq9ucHO8voDkhJIIGkpfIrjQJ8OI72srZ//xHyGvlCbQ X-Received: by 2002:a05:6602:188:: with SMTP id m8mr3133065ioo.201.1626181578907; Tue, 13 Jul 2021 06:06:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626181578; cv=none; d=google.com; s=arc-20160816; b=x+MKQg6SAL8juwmevMr+ER1FVPdpg1i5yqC8WYH1Jeixi37mtDOwOiWagBBUlgx76J rDpXE5jhUFF+3WYWA8VnKLntdlCa7JiJ5SCPTHi9EC+/njJamHHfdxTfFZuxhaHYOCXh Mir4cCKWRuEGNyOB3CS1ln9bq7NSAo+9qBDfOw+oM7Og70/j/6+kRtVD6VA450e1fZiK fXfobKml7hq4Z4IvASWEjt2KxD+04yIGQM7UPtDnJo2jkDSZFEdOZbhRnc2spOrJhuu+ 4dCG6APHCQ5uinW2tgdWyF4u7Yyxbs0i+oQrdWu9R6EhBXO3dnfYFQ+ABSnL2MkYwwCk Wqhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=iMwcKZl2eGecVWJGoui9ncs6auLmuusIIosF9nJ4JOY=; b=OYdxK9dd0vJp53IPgCZywq7bbFLrrHyAN2VRyp2MGUBkfPmQGjG6xksybGDdeYaCqz Tab6NrtVq7YXLaCDA2gszUTg5LtHBKhL0CqkFa5ZyzkHYkoPpo5jRqz+/GHaClVKCxml 8l/uXmoA+bDKCsRvcmHeq8b4/EV7IXoU6tvK9hQ508uKE1PjSip4bDpG/4SHJvBxHDr6 igOnUULEsPTG6fnW0xTXCxW1NtIb1IuzVJsozsddMEP9psl4SffHAXlO2/EUXbPaUtDx JqAqRIefGmpRe4vYKBN/Ou7H9EDMDEkEzbUp0cSU3kCEmAwwunHsUl57bZSw/f6fHOAN VWHw== ARC-Authentication-Results: i=1; mx.google.com; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d6si20739928ilm.75.2021.07.13.06.06.03; Tue, 13 Jul 2021 06:06:18 -0700 (PDT) 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; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236531AbhGMNHk (ORCPT + 99 others); Tue, 13 Jul 2021 09:07:40 -0400 Received: from mail-wr1-f49.google.com ([209.85.221.49]:34471 "EHLO mail-wr1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236383AbhGMNHk (ORCPT ); Tue, 13 Jul 2021 09:07:40 -0400 Received: by mail-wr1-f49.google.com with SMTP id p8so30370727wrr.1; Tue, 13 Jul 2021 06:04:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=iMwcKZl2eGecVWJGoui9ncs6auLmuusIIosF9nJ4JOY=; b=FJ0aoAeMUqVa6Cpknnf3emtIUZDjIUvai/fLGYRJEnmGX/jI5e29E7lVQA+FUUW7Pb LqPz2F9EyYdSmhGXmSzM7Zuh88D8jt1xvTRwrB4lr3bJtHrCQ2c5SEudPjDC1qB50M2b Xvn8C9ixbgDLZrIg8VaEPZgoUffwxkcgRJtBiWTg5dObh7Mc6tzXB7Z7z3sMk+TGYhJQ bccmtCjdY/7wmzjbP7HN71w40PBi9516o0RmY98fMvH6GfxNH5P4SI5/ytbwNCldsa1p cw+nTrZbkqnO2ivgDsIziCut9UgcHin8Lv5DovUMRqioF9em0vDtNUvryVyxxsf9Cry7 uxdA== X-Gm-Message-State: AOAM530kRdu1DD9uINUKJla+kdC3MkQsy6pmR5/GC1UMIlbjCSIgzGrH Y0/ZYP9CSguthscRg7WfpmQ= X-Received: by 2002:adf:ea4c:: with SMTP id j12mr5529925wrn.138.1626181489176; Tue, 13 Jul 2021 06:04:49 -0700 (PDT) Received: from liuwe-devbox-debian-v2 ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id e15sm17621509wrp.29.2021.07.13.06.04.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jul 2021 06:04:48 -0700 (PDT) Date: Tue, 13 Jul 2021 13:04:46 +0000 From: Wei Liu To: Ani Sinha Cc: linux-kernel@vger.kernel.org, anirban.sinha@nokia.com, mikelley@microsoft.com, "K. Y. Srinivasan" , Haiyang Zhang , Stephen Hemminger , Wei Liu , Dexuan Cui , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , linux-hyperv@vger.kernel.org Subject: Re: [PATCH] Hyper-V: fix for unwanted manipulation of sched_clock when TSC marked unstable Message-ID: <20210713130446.gt7k3cwlmhsxtltw@liuwe-devbox-debian-v2> References: <20210713030522.1714803-1-ani@anisinha.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210713030522.1714803-1-ani@anisinha.ca> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 13, 2021 at 08:35:21AM +0530, Ani Sinha wrote: > Marking TSC as unstable has a side effect of marking sched_clock as > unstable when TSC is still being used as the sched_clock. This is not > desirable. Hyper-V ultimately uses a paravirtualized clock source that > provides a stable scheduler clock even on systems without TscInvariant > CPU capability. Hence, mark_tsc_unstable() call should be called _after_ > scheduler clock has been changed to the paravirtualized clocksource. This > will prevent any unwanted manipulation of the sched_clock. Only TSC will > be correctly marked as unstable. Correct me if I'm wrong, what you're trying to address is that sched_clock remains marked as unstable even after Linux has switched to a stable clock source. I think a better approach will be to mark the sched_clock as stable when we switch to the paravirtualized clock source. See hyperv_timer.c:hv_setup_sched_clock. Wei. > > Signed-off-by: Ani Sinha > --- > arch/x86/kernel/cpu/mshyperv.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c > index 22f13343b5da..715458b7729a 100644 > --- a/arch/x86/kernel/cpu/mshyperv.c > +++ b/arch/x86/kernel/cpu/mshyperv.c > @@ -370,8 +370,6 @@ static void __init ms_hyperv_init_platform(void) > if (ms_hyperv.features & HV_ACCESS_TSC_INVARIANT) { > wrmsrl(HV_X64_MSR_TSC_INVARIANT_CONTROL, 0x1); > setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE); > - } else { > - mark_tsc_unstable("running on Hyper-V"); > } > > /* > @@ -432,6 +430,12 @@ static void __init ms_hyperv_init_platform(void) > /* Register Hyper-V specific clocksource */ > hv_init_clocksource(); > #endif > + /* TSC should be marked as unstable only after Hyper-V > + * clocksource has been initialized. This ensures that the > + * stability of the sched_clock is not altered. > + */ > + if (!(ms_hyperv.features & HV_ACCESS_TSC_INVARIANT)) > + mark_tsc_unstable("running on Hyper-V"); > } > > static bool __init ms_hyperv_x2apic_available(void) > -- > 2.25.1 >