Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp446179pxb; Thu, 9 Sep 2021 04:47:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypshiIe3tiqrb76QyKIo4E1nCaJ0q85WRdjR7/Q0qGAki/YOpYTrf58qBJZu6vnMgqWirm X-Received: by 2002:a05:6402:401:: with SMTP id q1mr2777038edv.154.1631188040902; Thu, 09 Sep 2021 04:47:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631188040; cv=none; d=google.com; s=arc-20160816; b=ebj56T5uxCwaIfM5rpY5b4a+7RD/J/ZnlN8+9cGPShXr9kBS20Ap+cZUB0kSp+i9nq qa3FVOFbMswasfW7yfbAJwOfNEf31rlY6ya0oxdwM2DUVzyvdyOIKOY03VqQLpeG7gb8 5sWMLRH75LX42o4X2Pos4XQ9Fzu/nULULCpx8IXRSdTHm7l1XA0hCB2Qx0vSwxOYZFrb aoHT/G8uMpwPvWmRTWCPUkWl2mj+sXAr/Dxq309u6Rn1EzOre+I/5t9OIODjWZcZpRCG 6tL/w596RfufmhJljedX2M1yi9LmiuG7c39u/kDkpT22GbEpzFKUGsBHjxg3Yla/1ZDo 5gDw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tGaRN5JDVSPJ4GRTMQj4S7wYmkvubpSPLjD8E6RVE/w=; b=0aBgCHfr7sUkuOI1fNzzq0xr/FABn74KLnwUVZKLosm4yI4p6ZCzs3XX7ivTbbyqCz EFYs2vFFHbJhX7JqENGUY1prm1yQChbNcejOHxMYausJMfAlP8aUueG7kZkdwTSE0O7o JwPctVIu6yHudFnz5/tb43zKMwcfYilN46dgNf3gwI/1/h6XFr2j2XEKpwfVF5LObOlf H2m1w59uVYweQY+AgiLWOIYqGtGtc5/t/Bd3GYt6UxaCEcnRWtY45A24ZHDvyn0qW+sJ KkrZjoTKdDCqAkW+FA++N4MDJ3JFqKY6SWPKMx68HTXgafdG52PdcYJKR8/jUiHAz0xz I+6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="tHfVjze/"; 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 z12si1558849ejc.42.2021.09.09.04.46.54; Thu, 09 Sep 2021 04:47:20 -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=@kernel.org header.s=k20201202 header.b="tHfVjze/"; 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 S238592AbhIILnm (ORCPT + 99 others); Thu, 9 Sep 2021 07:43:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:46150 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236388AbhIILml (ORCPT ); Thu, 9 Sep 2021 07:42:41 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3030C61131; Thu, 9 Sep 2021 11:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631187692; bh=50YXhMmBJBhR55rbNXd7AEWdWQP1PFZ8gTBGr6jGd08=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tHfVjze/iFTwc0PJRkAt7f1hNn+uAPj/ZAVhQH+2Xtbd/4bZhL6S2qnY6nAMN0mfW qcdhtXwpWzlVPz3lskThVV/3QyqVxmx4B3ANELaPO4i7486U1xEuZZdFPipnUbSvx9 yMpCvryycTVZIeFS2JCchvZCuX5xUIPTA/wuPomgrjNDs0Va+97e3wb+tDP0kWwi4g GdhKk46e2LdVSxUqvWqrbYwLM/F03SZ8zLb6dTl779gNVRIMEDEKdW6b6zfMmt7fmn DJwkfipWBFeUwwWdk93O3p2CyNm7aebPPkK7/azZxrQLCObpKiFjzlEKY+PCMI4hl0 4Cc0sOxrwbyPA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ani Sinha , Michael Kelley , Wei Liu , Sasha Levin , linux-hyperv@vger.kernel.org Subject: [PATCH AUTOSEL 5.14 019/252] x86/hyperv: fix for unwanted manipulation of sched_clock when TSC marked unstable Date: Thu, 9 Sep 2021 07:37:13 -0400 Message-Id: <20210909114106.141462-19-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909114106.141462-1-sashal@kernel.org> References: <20210909114106.141462-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 c890d67a64ad..ba54c44a64e2 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -375,8 +375,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"); } /* @@ -437,6 +435,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"); } static bool __init ms_hyperv_x2apic_available(void) -- 2.30.2