Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1531779pxb; Thu, 16 Sep 2021 09:21:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjHpIJzYrhdYxsCd4rhe+ZdWRYSwzeZkIqAeR5CIY0PypaDraSIfDHP5AETOs8DBp6U0kz X-Received: by 2002:a17:906:f15:: with SMTP id z21mr7122852eji.177.1631809267100; Thu, 16 Sep 2021 09:21:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631809267; cv=none; d=google.com; s=arc-20160816; b=JvW153xcVKLNTl731J3dEuA+PEoZ/pib3J3lBfUPJvMWHr/VRS59Yls5wEgSVsBwhC ClNuNJ8pwqCKEvSqkSoga2buESFoe0ATTyAeL4BfIgAXwXabJkDeiv5lPhtADONwCvjd sVdhQS8fQe9iAuxo5bN//xOMvXTK02PqdHVHtqzFkPcCnBGe2uYkLsIevvR214Q0ajqa u4zpEN3nZfmz52GTFWpKlWfgyhpZIYxAs9DyEVCPKzRXFHJJRFKhYR6EiFQrQ0LR9ci8 vWee39+77UY6ePuLC7o5tgJLiYSsvzPTxA0AxX+uN16MghvR7r0xGJv6XWa5bXbB0BLM Hs/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tshUKJUp6FJ3LdHNuEiqcE3s/6mxM0S/8kzZPMlqdhQ=; b=Pl4c3LItX+7cE69jhvt4WQHw7YKpYRB542JrnT4zBXfq4LNYnOze/RRZtIPNaJYMyV ZNr7tSbW+1Aepl2v2EoPc/N1nJS+D2SJbs3cU1Vrn4CVR6LHPhpkMgaOMlkcUwlNq4MG Qv7BRAPOjKGrSmpexT2VzrtpHKQQAUjazvW8BphSiV5Oat22f78e2o8qLU5L9djj4U7i 3jC6PIW6wxD8WkYEuXdfWw8bmnU/uibti3xJGToBbMtpPSgXiMOfvgqQdlSptyvXZG6a NEOlyz2Db47wm7N4remWWfGsXtg+XhHTMnLYaEqn5vDwGM1oU+uWJaDWmk18ojjedvcw 3i+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DtpEp9qu; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u4si4402984ejt.53.2021.09.16.09.20.38; Thu, 16 Sep 2021 09:21:07 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DtpEp9qu; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237650AbhIPQRQ (ORCPT + 99 others); Thu, 16 Sep 2021 12:17:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:49222 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234707AbhIPQKA (ORCPT ); Thu, 16 Sep 2021 12:10:00 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D38D060698; Thu, 16 Sep 2021 16:08:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808501; bh=UWOSj+0dV3ODPeSKP/0a/hFg/2YrWllal63cm9OEM6I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DtpEp9quPkLKL5uZS0+HzyHUxc9y87KtIctTz2KaNdWLSuqGTLG2sPJByQzLcyFYL 4aU8VW39jnb+J4KKjSed08O9mhS7eqJ2t96Z7rWx02X5e63kEuxDM9swgBdyEYLNHI 0qjNtTrW3ieshVJ5jm/BOTn4k+AjN7/Gtb71s+O4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ani Sinha , Michael Kelley , Wei Liu , Sasha Levin Subject: [PATCH 5.10 115/306] x86/hyperv: fix for unwanted manipulation of sched_clock when TSC marked unstable Date: Thu, 16 Sep 2021 17:57:40 +0200 Message-Id: <20210916155757.990424904@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ani Sinha [ Upstream commit c445535c3efbfb8cb42d098e624d46ab149664b7 ] 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. Signed-off-by: Ani Sinha Reviewed-by: Michael Kelley Tested-by: Michael Kelley Link: https://lore.kernel.org/r/20210713030522.1714803-1-ani@anisinha.ca Signed-off-by: Wei Liu Signed-off-by: Sasha Levin --- arch/x86/kernel/cpu/mshyperv.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index 6cc50ab07bde..65d11711cd7b 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -322,8 +322,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"); } /* @@ -382,6 +380,13 @@ 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"); } const __initconst struct hypervisor_x86 x86_hyper_ms_hyperv = { -- 2.30.2