Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1424599rwb; Fri, 18 Nov 2022 18:55:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf4ksczfvD64ZA3sY+hM927EIyD8SAPjkbJsPLZEKAE63OagG3+98COnOz/xXgxfpdszPd/Z X-Received: by 2002:aa7:d4cf:0:b0:461:a9ce:5408 with SMTP id t15-20020aa7d4cf000000b00461a9ce5408mr8574102edr.201.1668826555955; Fri, 18 Nov 2022 18:55:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668826555; cv=none; d=google.com; s=arc-20160816; b=rObpPpSY1GAQnCpkku1VSYjtzjJsD4EiUERXbVmCRF9cHrSRMsd3Zokth21H7Qg5+y 378Bbj4bZdi5944OrMFUMExQar5Fdup5bpGnLaXAlylSfe6J7MhdoUeSNeXef7VrJnYA cId+mzTfISJbeFwdIk7bQx3b2uweXN2bM4K41e3SP+L8TtSt5HvOk+nqraOZlj47Vdkq Av3u79Y3VvLM83BNrvfwPGYQe62k48APWLxbEBY9mAcc2ifGvwK69OMO2l4do3HiY0E4 e9A/cIH1U5AmA05oRqN2YgqBiEQP/CaGYjSne4+NNz2/bdOiYCO8UKct/scYr7ODbhjW 6xtw== 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=Sv2hXAcLqkYJTA59i6qnj0ja3tVRYJ5Qgz+S5hs9K7Q=; b=0RiqsO87SzcO6iIfumEwekgtkun1jq58io39JW+Fnw+OCXQW+SHYDn4XlN0/KdwIRW oVE2p04EqiKp8wbnd6A/JfHmawYjDkvXx8OotqJE/CB0QoWpcggMfrjzpclXHxRaPmSQ xVblVFauoL8ZYHvEqmX7XS5kOylbcX0aaFbDStvY88+huvT1NkkgoowbyWlwOfMZQ17L CipBqBBVf9GTok/RBuUXmympX+SWn8bGb3XOV0L4dyGyYAC2gMuNfAi2/79a4OOY3YEd ZoMyfQAH/ImBwCl5USzcWPoUfYyKAm7IUHnBEWkMYfJgeoO2ogCuTH5Yrlt1hehgnn3i MOUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Hx9RC44b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t1-20020a056402524100b00461f7a7a797si4797364edd.292.2022.11.18.18.55.34; Fri, 18 Nov 2022 18:55:55 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Hx9RC44b; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S234269AbiKSCND (ORCPT + 90 others); Fri, 18 Nov 2022 21:13:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232230AbiKSCMM (ORCPT ); Fri, 18 Nov 2022 21:12:12 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 363567118C; Fri, 18 Nov 2022 18:11:54 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C1AEC62832; Sat, 19 Nov 2022 02:11:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E4E8CC433D7; Sat, 19 Nov 2022 02:11:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1668823913; bh=XiX+Ep7dbAOGNF6oQIJOeyAKQjrnd2qOY8+7kYrI3oA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hx9RC44bmjHWoyn6R4rKnas5qCe4od2GIHm4uU2BuRifRO7EwR6CNE58N/WLgl7wu sY+Q/Reu0piqZJ7U3RxKXNYRrtshwmz9mGVRaMRdGfDLuLIfFTlDb/LsPHfcyp6K7q pATY0Yc2LzpQet5ymeaCjw2VQN2/pHG0BWljF1x5yWSBsMGD2HTUNgk6T/hmpEDoxa okgk8x5cpASYjPB4QDsxULg6dyycfaXX9PTovbmMlXg95QhE4o1stFGVZHlzwebHtI x4O+mVun7Ucy9j/8D8sNzOD123KUEEn6C9zWBoHiMUMiY5fdc4ptP5UNbkQp44N1SG /sg0bxBV39EfA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Anirudh Rayabharam , Michael Kelley , Wei Liu , Sasha Levin , kys@microsoft.com, haiyangz@microsoft.com, decui@microsoft.com, daniel.lezcano@linaro.org, tglx@linutronix.de, linux-hyperv@vger.kernel.org, linux-arch@vger.kernel.org Subject: [PATCH AUTOSEL 6.0 13/44] clocksource/drivers/hyperv: add data structure for reference TSC MSR Date: Fri, 18 Nov 2022 21:10:53 -0500 Message-Id: <20221119021124.1773699-13-sashal@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221119021124.1773699-1-sashal@kernel.org> References: <20221119021124.1773699-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Anirudh Rayabharam [ Upstream commit 4ad1aa571214e8d6468a1806794d987b374b5a08 ] Add a data structure to represent the reference TSC MSR similar to other MSRs. This simplifies the code for updating the MSR. Signed-off-by: Anirudh Rayabharam Reviewed-by: Michael Kelley Link: https://lore.kernel.org/r/20221027095729.1676394-2-anrayabh@linux.microsoft.com Signed-off-by: Wei Liu Signed-off-by: Sasha Levin --- drivers/clocksource/hyperv_timer.c | 29 +++++++++++++++-------------- include/asm-generic/hyperv-tlfs.h | 9 +++++++++ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c index bb47610bbd1c..18de1f439ffd 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -395,25 +396,25 @@ static u64 notrace read_hv_sched_clock_tsc(void) static void suspend_hv_clock_tsc(struct clocksource *arg) { - u64 tsc_msr; + union hv_reference_tsc_msr tsc_msr; /* Disable the TSC page */ - tsc_msr = hv_get_register(HV_REGISTER_REFERENCE_TSC); - tsc_msr &= ~BIT_ULL(0); - hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr); + tsc_msr.as_uint64 = hv_get_register(HV_REGISTER_REFERENCE_TSC); + tsc_msr.enable = 0; + hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr.as_uint64); } static void resume_hv_clock_tsc(struct clocksource *arg) { phys_addr_t phys_addr = virt_to_phys(&tsc_pg); - u64 tsc_msr; + union hv_reference_tsc_msr tsc_msr; /* Re-enable the TSC page */ - tsc_msr = hv_get_register(HV_REGISTER_REFERENCE_TSC); - tsc_msr &= GENMASK_ULL(11, 0); - tsc_msr |= BIT_ULL(0) | (u64)phys_addr; - hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr); + tsc_msr.as_uint64 = hv_get_register(HV_REGISTER_REFERENCE_TSC); + tsc_msr.enable = 1; + tsc_msr.pfn = HVPFN_DOWN(phys_addr); + hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr.as_uint64); } #ifdef HAVE_VDSO_CLOCKMODE_HVCLOCK @@ -495,7 +496,7 @@ static __always_inline void hv_setup_sched_clock(void *sched_clock) {} static bool __init hv_init_tsc_clocksource(void) { - u64 tsc_msr; + union hv_reference_tsc_msr tsc_msr; phys_addr_t phys_addr; if (!(ms_hyperv.features & HV_MSR_REFERENCE_TSC_AVAILABLE)) @@ -530,10 +531,10 @@ static bool __init hv_init_tsc_clocksource(void) * (which already has at least the low 12 bits set to zero since * it is page aligned). Also set the "enable" bit, which is bit 0. */ - tsc_msr = hv_get_register(HV_REGISTER_REFERENCE_TSC); - tsc_msr &= GENMASK_ULL(11, 0); - tsc_msr = tsc_msr | 0x1 | (u64)phys_addr; - hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr); + tsc_msr.as_uint64 = hv_get_register(HV_REGISTER_REFERENCE_TSC); + tsc_msr.enable = 1; + tsc_msr.pfn = HVPFN_DOWN(phys_addr); + hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr.as_uint64); clocksource_register_hz(&hyperv_cs_tsc, NSEC_PER_SEC/100); diff --git a/include/asm-generic/hyperv-tlfs.h b/include/asm-generic/hyperv-tlfs.h index fdce7a4cfc6f..b17c6eeb9afa 100644 --- a/include/asm-generic/hyperv-tlfs.h +++ b/include/asm-generic/hyperv-tlfs.h @@ -102,6 +102,15 @@ struct ms_hyperv_tsc_page { volatile s64 tsc_offset; } __packed; +union hv_reference_tsc_msr { + u64 as_uint64; + struct { + u64 enable:1; + u64 reserved:11; + u64 pfn:52; + } __packed; +}; + /* * The guest OS needs to register the guest ID with the hypervisor. * The guest ID is a 64 bit entity and the structure of this ID is -- 2.35.1