From patchwork Wed Nov 2 22:07:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Kinsburskii X-Patchwork-Id: 14497 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp168399wru; Wed, 2 Nov 2022 15:09:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7K1eXCRgFJagxlwDj11xhIu1ZlwFN196cpyB3LY7UB5qhXYirU7+RAwcsJkmABO65yZ3SX X-Received: by 2002:a17:906:5dcc:b0:78d:e76a:ef23 with SMTP id p12-20020a1709065dcc00b0078de76aef23mr24958356ejv.317.1667426994940; Wed, 02 Nov 2022 15:09:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667426994; cv=none; d=google.com; s=arc-20160816; b=z1ggNkyxVHighIPoHGguUSoLdsi/tjSm0AnNLhOUl3/vcHWHZq+fYh3B0OzfDRxF2U mHsgJ3ajpus3D7MMpiFdbHFS9X+7DFZEm4DlGSwfInG33o8TB63sbKui1ilQEQISb9dF HW1VX4zg1N1KT1s0Brf2z+3K2rAFgYvmjXN/Jil3sBmsbH6e7Itnw6hyVmWxz9+e5qeI Hn5Ajwcaeb1wd0CZeIOmvhUBvtTFTdL647U40rm6pqKgE9xdLj/59OFnUoyxX75qgAFb cV64f9rof/vO8JuuROiqQ8nOWpQ+iRnssPJuzDDOa5q0N2D1KyLvJACDIgm9FrjFYNPG RW+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:from:subject :dkim-signature:dkim-filter; bh=EWM7ms7b0WbT7d6yAY+HL9LM12Gu9G0ck67VyffGqTc=; b=yKy/UK1pYTcz/MXRvdTXlifoKClA8SPx39Wi4x/PzHZRL2/szzW2X8aMBl0F0LQL1S iZ9le8yesKHNP/wDDKmg0MQyiUplcOj1h833FUP5I86n9uiGbnNJwzSEsCuahk3US+9/ ARv+143vVXuTc1lR8mmSM32EfADiQVhM98USCi5WRg5KUlb6yT2+AnG6kosY+T7zrNCQ pwkzN6AnxM65LYtWiqaJb1AedSfbNyLtJCdL0kneGfX8wDihRgFv+Q/wxJIg/28Zi2bo 9J/Z3CysW0aDew6FbvhNSM4zM/rzxDpeRphFvCAjgX/6wiiVT3I9Wit7xX/dP3cT97St srTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="Fn/1D1Ph"; 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=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s2-20020a50d482000000b00461b8e2c7f4si14655536edi.548.2022.11.02.15.09.26; Wed, 02 Nov 2022 15:09:54 -0700 (PDT) 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=@linux.microsoft.com header.s=default header.b="Fn/1D1Ph"; 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=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231339AbiKBWHg (ORCPT + 99 others); Wed, 2 Nov 2022 18:07:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230478AbiKBWHZ (ORCPT ); Wed, 2 Nov 2022 18:07:25 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 86746A446; Wed, 2 Nov 2022 15:07:24 -0700 (PDT) Received: from skinsburskii-cloud-desktop.internal.cloudapp.net (unknown [20.120.152.163]) by linux.microsoft.com (Postfix) with ESMTPSA id 5583520C3338; Wed, 2 Nov 2022 15:07:24 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 5583520C3338 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667426844; bh=EWM7ms7b0WbT7d6yAY+HL9LM12Gu9G0ck67VyffGqTc=; h=Subject:From:Cc:Date:In-Reply-To:References:From; b=Fn/1D1PhnRyR0LaZcGzkhZteZTh0pQ6zv5ioCtRFHVIaPWFAsR0R0IT6iB7fHX0vR fI1DLf9YDalZaQhuitm7svbHpHZ6yJfVGzTYbdJVL9xdDIuwLlJNyVGdZ4J3wizRf4 p/QyWcPJ57ZFfS4miEQx+ZeafovYZpk44aTm+Esw= Subject: [PATCH v2 1/4] drivers/clocksource/hyper-v: Introduce a pointer to TSC page From: Stanislav Kinsburskii Cc: Stanislav Kinsburskiy , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Daniel Lezcano , Thomas Gleixner , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 02 Nov 2022 22:07:24 +0000 Message-ID: <166742684418.205987.14378848205726386650.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> In-Reply-To: <166742670556.205987.18227942188746093700.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> References: <166742670556.205987.18227942188746093700.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-18.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,MISSING_HEADERS, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748423928422389037?= X-GMAIL-MSGID: =?utf-8?q?1748423928422389037?= From: Stanislav Kinsburskiy Will be used later keep the address of the remapped page for the root partition as it will be Microsoft Hypervisor defined (and thus won't be a static address). Signed-off-by: Stanislav Kinsburskiy CC: "K. Y. Srinivasan" CC: Haiyang Zhang CC: Wei Liu CC: Dexuan Cui CC: Daniel Lezcano CC: Thomas Gleixner CC: linux-hyperv@vger.kernel.org CC: linux-kernel@vger.kernel.org --- drivers/clocksource/hyperv_timer.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c index 11332c82d1af..c4dbf40a3d3e 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -366,9 +366,11 @@ static union { u8 reserved[PAGE_SIZE]; } tsc_pg __aligned(PAGE_SIZE); +static struct ms_hyperv_tsc_page *tsc_page = &tsc_pg.page; + struct ms_hyperv_tsc_page *hv_get_tsc_page(void) { - return &tsc_pg.page; + return tsc_page; } EXPORT_SYMBOL_GPL(hv_get_tsc_page); @@ -406,7 +408,7 @@ static void suspend_hv_clock_tsc(struct clocksource *arg) static void resume_hv_clock_tsc(struct clocksource *arg) { - phys_addr_t phys_addr = virt_to_phys(&tsc_pg); + phys_addr_t phys_addr = virt_to_phys(tsc_page); union hv_reference_tsc_msr tsc_msr; /* Re-enable the TSC page */ From patchwork Wed Nov 2 22:07:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Kinsburskii X-Patchwork-Id: 14498 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp168515wru; Wed, 2 Nov 2022 15:10:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Z5opJKnx9PfrCGzzg3Om9z5JFIqAJQQMZO8sTv5Dt7ax6lGGLb9VGndT/PV2XZUWJJ94G X-Received: by 2002:a17:906:99c5:b0:73d:70c5:1a4f with SMTP id s5-20020a17090699c500b0073d70c51a4fmr25605154ejn.302.1667427010432; Wed, 02 Nov 2022 15:10:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667427010; cv=none; d=google.com; s=arc-20160816; b=QiNjZSnYmcTpPZoKPHSuEYwP2yD7BKjtGxR2ZM2E5XnOq8Zz7CLus9j0/vre6u4ibI 8tOdKelnqE/e5HwglZ/OkuNv2QpDBmTVHuKPRBnWh7RkHHSuDqYq7muzCBE0r3su4aLW sJNsYBjuniDAyUHvY0e4il0+Ee3zjKPI/iM03eckrsASmjcvhjbXcTjrdxlnHfr8zJe8 whdTu7Tba4E6i+JJ3g+0D5Akn1fTw+hmKmDJVXF7zClKDLvMZot8kBNuG9Quel8Ou56p sx0T1ad2fFtJx8Q89yddfHLZfVgs5YyU5T2bQzijg1fskN15j8PTlrCTXrVhaHAU/4M5 tgyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:from:subject :dkim-signature:dkim-filter; bh=kY+BUE9K0z7WzM/4fFPpfyIF7753x1wgzUWR7hXp/x0=; b=OEOkZzUuHoyXr89L2ZnP/dtW/ih+seO0Ece2T3cDjSjO5yLbO4c9v3Pa4ZL8l4z3Bt RZhyUJ4i2cQs9FdsUl1EPDX+Jh5LnNX57j5gqESilGyuGR8CR3BUK+JSaek7a/d18nIf iHonIwaa/g6k9oetOTEld95xTOuKjQhJW7dSsH7iB2f/CLZ44ICAv8Vv4w7/yYUNec8w 2jHBtqxGLkl5O37ZMuQ+aXF9aqLwKLJJvajHs/OZ3ldkCjPxK1KGBhTOHq2ekcbegNFE RE7XnyIhiT2Ir7qW6rSQ+tYbfwbbVeW52pT9LpqtQssTNkMhS2qT/cSxQBOWr/xL/iWR To0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="L4FuYqO/"; 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=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qq17-20020a17090720d100b007ad8bd5a35dsi12621189ejb.348.2022.11.02.15.09.40; Wed, 02 Nov 2022 15:10:10 -0700 (PDT) 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=@linux.microsoft.com header.s=default header.b="L4FuYqO/"; 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=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231358AbiKBWHw (ORCPT + 99 others); Wed, 2 Nov 2022 18:07:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231351AbiKBWHh (ORCPT ); Wed, 2 Nov 2022 18:07:37 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C904495BE; Wed, 2 Nov 2022 15:07:29 -0700 (PDT) Received: from skinsburskii-cloud-desktop.internal.cloudapp.net (unknown [20.120.152.163]) by linux.microsoft.com (Postfix) with ESMTPSA id 9A4E520C3338; Wed, 2 Nov 2022 15:07:29 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 9A4E520C3338 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667426849; bh=kY+BUE9K0z7WzM/4fFPpfyIF7753x1wgzUWR7hXp/x0=; h=Subject:From:Cc:Date:In-Reply-To:References:From; b=L4FuYqO/vqafsHv/73V3g0T0SCIp+a7+bQ8cFrMEbqI37gNSJWXzZFSbzEVb/5Bma SG79tXdxgL2fPsvVMzAvsqTCtUPzjNQ8TCq7lY43flCGio3Tmzt8ae5BEf8dbYymvz fYqtXCOibXzgziqh7Z4BvKaKws7yUvF4OiueZFyk= Subject: [PATCH v2 2/4] drivers/clocksource/hyper-v: Introduce TSC PFN getter From: Stanislav Kinsburskii Cc: Stanislav Kinsburskiy , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Daniel Lezcano , Thomas Gleixner , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 02 Nov 2022 22:07:29 +0000 Message-ID: <166742684944.205987.13495997217797904022.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> In-Reply-To: <166742670556.205987.18227942188746093700.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> References: <166742670556.205987.18227942188746093700.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-18.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,MISSING_HEADERS, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748423944765807250?= X-GMAIL-MSGID: =?utf-8?q?1748423944765807250?= From: Stanislav Kinsburskiy And rework the code to use it instead of the physical address, which isn't required by itself. This is a cleanup and precursor patch for upcoming support for TSC page mapping into Microsoft Hypervisor root partition, where TSC PFN will be defined by the hypervisor and not by the kernel. Signed-off-by: Stanislav Kinsburskiy CC: "K. Y. Srinivasan" CC: Haiyang Zhang CC: Wei Liu CC: Dexuan Cui CC: Daniel Lezcano CC: Thomas Gleixner CC: linux-hyperv@vger.kernel.org CC: linux-kernel@vger.kernel.org --- drivers/clocksource/hyperv_timer.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c index c4dbf40a3d3e..d447bc99a399 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -367,6 +367,12 @@ static union { } tsc_pg __aligned(PAGE_SIZE); static struct ms_hyperv_tsc_page *tsc_page = &tsc_pg.page; +static unsigned long tsc_pfn; + +static unsigned long hv_get_tsc_pfn(void) +{ + return tsc_pfn; +} struct ms_hyperv_tsc_page *hv_get_tsc_page(void) { @@ -408,13 +414,12 @@ static void suspend_hv_clock_tsc(struct clocksource *arg) static void resume_hv_clock_tsc(struct clocksource *arg) { - phys_addr_t phys_addr = virt_to_phys(tsc_page); union hv_reference_tsc_msr tsc_msr; /* Re-enable the TSC page */ tsc_msr.as_uint64 = hv_get_register(HV_REGISTER_REFERENCE_TSC); tsc_msr.enable = 1; - tsc_msr.pfn = __phys_to_pfn(phys_addr); + tsc_msr.pfn = tsc_pfn; hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr.as_uint64); } @@ -498,7 +503,6 @@ static __always_inline void hv_setup_sched_clock(void *sched_clock) {} static bool __init hv_init_tsc_clocksource(void) { union hv_reference_tsc_msr tsc_msr; - phys_addr_t phys_addr; if (!(ms_hyperv.features & HV_MSR_REFERENCE_TSC_AVAILABLE)) return false; @@ -523,7 +527,7 @@ static bool __init hv_init_tsc_clocksource(void) } hv_read_reference_counter = read_hv_clock_tsc; - phys_addr = virt_to_phys(hv_get_tsc_page()); + tsc_pfn = __phys_to_pfn(virt_to_phys(tsc_page)); /* * The Hyper-V TLFS specifies to preserve the value of reserved @@ -534,7 +538,7 @@ static bool __init hv_init_tsc_clocksource(void) */ tsc_msr.as_uint64 = hv_get_register(HV_REGISTER_REFERENCE_TSC); tsc_msr.enable = 1; - tsc_msr.pfn = __phys_to_pfn(phys_addr); + tsc_msr.pfn = tsc_pfn; hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr.as_uint64); clocksource_register_hz(&hyperv_cs_tsc, NSEC_PER_SEC/100); From patchwork Wed Nov 2 22:07:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Kinsburskii X-Patchwork-Id: 14499 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp168532wru; Wed, 2 Nov 2022 15:10:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6lPVs4u9lF6rVh1cqFxSHFTFWDf1ol8qIHfNYSHN/vyJ0ej4oYSwlXV9y76eNseTQZS8++ X-Received: by 2002:a17:907:2bd5:b0:76f:591c:466b with SMTP id gv21-20020a1709072bd500b0076f591c466bmr24961950ejc.504.1667427012757; Wed, 02 Nov 2022 15:10:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667427012; cv=none; d=google.com; s=arc-20160816; b=QlKuFsBtHD2+W1XWjRkLQRMAugsQGCp1L2k0UHBDclCgG6hKdHSJK+TIZOUb57bkpQ Cdr/ffpvWFhIpNQa/5hnuKDdxuzmY/V7o/Uz4Wc67Rnn5cRnohQewNUX2f1WD0IR5GYI IUhIWSVt2CN6E1PSnaXJB/Aky2kjYX0jGpqi2Xge4Dm+dPvloaFI1ZrQ+F9HUEHTacge W7XjnwBqL2KvOzcRzT7XSn9tkh22vKoYaIKdXG4atQemxuhuX0T/tlcB4g31M/wo/T4m TYznqik0YWQSNDZi6CfhcCZKR0jTlC8pgNEq8mxlKoLRn2rUFmZsv+Zy+vF5DMhQh8y2 vIFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:from:subject :dkim-signature:dkim-filter; bh=pAbglJaMPSpg4VSsz2BLMewqFuaTia6tHnF0dX8Qngc=; b=YJTtBm10TKSQ7bJQ7DpSKTl8pNrXI+p6ERuXHpz3zF6UZm+6QEbmdcBJT+oITm8c09 gbuzZ1dWYC3elOT/e1lO4eNI8u9uzzKzTNGVo015mjaZOtbeNlNCtNxJq8MbKTrjVwKo hkKhC2CcO06iJ8ZCFeBrFW1heoA2vCcTpkp0GDG1nvIIeCwjsJCp30UcivuykqBnOum+ 0YQCHtQbkIYcgP9xVXU+36fXAIj43EW1XUGFFAGP9nuzysOWIaPnax2WqMpFaC8pwdbE fg27D6VmLx+QLNOZnwr0hjpbbUrxzHkzMVSVBq4rqL4DfzN3D9mgcO3KswR3CyGyAbzs P4Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=a89uZ9SZ; 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=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y71-20020a50bb4d000000b00461e322ec5dsi15022885ede.294.2022.11.02.15.09.46; Wed, 02 Nov 2022 15:10:12 -0700 (PDT) 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=@linux.microsoft.com header.s=default header.b=a89uZ9SZ; 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=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231444AbiKBWIH (ORCPT + 99 others); Wed, 2 Nov 2022 18:08:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231379AbiKBWHv (ORCPT ); Wed, 2 Nov 2022 18:07:51 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 33D04101DE; Wed, 2 Nov 2022 15:07:35 -0700 (PDT) Received: from skinsburskii-cloud-desktop.internal.cloudapp.net (unknown [20.120.152.163]) by linux.microsoft.com (Postfix) with ESMTPSA id D1B0C20C3338; Wed, 2 Nov 2022 15:07:34 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D1B0C20C3338 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667426854; bh=pAbglJaMPSpg4VSsz2BLMewqFuaTia6tHnF0dX8Qngc=; h=Subject:From:Cc:Date:In-Reply-To:References:From; b=a89uZ9SZdrYi8fjGMkYo24jWukdNB2plQwLTlnp0ispi6zn+uvsKSPK46QjsRj8g/ RNtSnphhHVLYc1ktjER/vLSAOi4b3gdmTn5zaZoVSV8g/i86Cxp/3oqM9aO/21loJW bgXchQVwv6CrG7Hq5hlMEx/Y1PdGG7JzcOjcyrIU= Subject: [PATCH v2 3/4] drivers/clocksource/hyper-v: Use TSC PFN getter to map vvar page From: Stanislav Kinsburskii Cc: Stanislav Kinsburskiy , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Daniel Lezcano , linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org Date: Wed, 02 Nov 2022 22:07:34 +0000 Message-ID: <166742685472.205987.8150649341873398568.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> In-Reply-To: <166742670556.205987.18227942188746093700.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> References: <166742670556.205987.18227942188746093700.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-18.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,MISSING_HEADERS, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748423947506928366?= X-GMAIL-MSGID: =?utf-8?q?1748423947506928366?= From: Stanislav Kinsburskiy Instead of converting the virtual address to physical directly. This is a precursor patch for the upcoming support for TSC page mapping into Microsoft Hypervisor root partition, where TSC PFN will be defined by the hypervisor and thus can't be obtained by linear translation of the physical address. Signed-off-by: Stanislav Kinsburskiy CC: Andy Lutomirski CC: Thomas Gleixner CC: Ingo Molnar CC: Borislav Petkov CC: Dave Hansen CC: x86@kernel.org CC: "H. Peter Anvin" CC: "K. Y. Srinivasan" CC: Haiyang Zhang CC: Wei Liu CC: Dexuan Cui CC: Daniel Lezcano CC: linux-kernel@vger.kernel.org CC: linux-hyperv@vger.kernel.org --- arch/x86/entry/vdso/vma.c | 7 +++---- drivers/clocksource/hyperv_timer.c | 3 ++- include/clocksource/hyperv_timer.h | 6 ++++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/arch/x86/entry/vdso/vma.c b/arch/x86/entry/vdso/vma.c index 311eae30e089..6976416b2c9f 100644 --- a/arch/x86/entry/vdso/vma.c +++ b/arch/x86/entry/vdso/vma.c @@ -210,11 +210,10 @@ static vm_fault_t vvar_fault(const struct vm_special_mapping *sm, pgprot_decrypted(vma->vm_page_prot)); } } else if (sym_offset == image->sym_hvclock_page) { - struct ms_hyperv_tsc_page *tsc_pg = hv_get_tsc_page(); + pfn = hv_get_tsc_pfn(); - if (tsc_pg && vclock_was_used(VDSO_CLOCKMODE_HVCLOCK)) - return vmf_insert_pfn(vma, vmf->address, - virt_to_phys(tsc_pg) >> PAGE_SHIFT); + if (pfn && vclock_was_used(VDSO_CLOCKMODE_HVCLOCK)) + return vmf_insert_pfn(vma, vmf->address, pfn); } else if (sym_offset == image->sym_timens_page) { struct page *timens_page = find_timens_vvar_page(vma); diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c index d447bc99a399..635c14c1e3bf 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -369,10 +369,11 @@ static union { static struct ms_hyperv_tsc_page *tsc_page = &tsc_pg.page; static unsigned long tsc_pfn; -static unsigned long hv_get_tsc_pfn(void) +unsigned long hv_get_tsc_pfn(void) { return tsc_pfn; } +EXPORT_SYMBOL_GPL(hv_get_tsc_pfn); struct ms_hyperv_tsc_page *hv_get_tsc_page(void) { diff --git a/include/clocksource/hyperv_timer.h b/include/clocksource/hyperv_timer.h index b3f5d73ae1d6..3078d23faaea 100644 --- a/include/clocksource/hyperv_timer.h +++ b/include/clocksource/hyperv_timer.h @@ -32,6 +32,7 @@ extern void hv_stimer0_isr(void); extern void hv_init_clocksource(void); +extern unsigned long hv_get_tsc_pfn(void); extern struct ms_hyperv_tsc_page *hv_get_tsc_page(void); static inline notrace u64 @@ -90,6 +91,11 @@ hv_read_tsc_page(const struct ms_hyperv_tsc_page *tsc_pg) } #else /* CONFIG_HYPERV_TIMER */ +static inline unsigned long hv_get_tsc_pfn(void) +{ + return 0; +} + static inline struct ms_hyperv_tsc_page *hv_get_tsc_page(void) { return NULL; From patchwork Wed Nov 2 22:07:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Kinsburskii X-Patchwork-Id: 14500 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp168586wru; Wed, 2 Nov 2022 15:10:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4EGouW23CgnmUNJ2oqVY+Sl1PdAPssZNNhL+kZXramvMKiZwt4xewWjsnWY6Z3njmpmXAt X-Received: by 2002:a17:907:7203:b0:7a5:b062:2338 with SMTP id dr3-20020a170907720300b007a5b0622338mr26472053ejc.8.1667427021145; Wed, 02 Nov 2022 15:10:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667427021; cv=none; d=google.com; s=arc-20160816; b=OTqbxRbMQuNofGvJlb8ewzCKMBjZfBO5IItBYWwcBDhZSnp4oH9qvscr8twNxhLxQh ff2gKi+x2kJyjbTkK1pXLtu3Y2C5K7bxAEWqP/IO8s/zmTOWaBJi3xk/3xtlJ2vFJMhz /54s022T71Vf1HmYWQhJOTHzaqK7cKY1snLgopgP2Th8vtPRMpLEoZH+DZb8PnJRLTaM yZmhtR71UKo7HKLm2GJC8L26BgppKn5KEDr7r/XH+JRFh3LxmurOVuTfVLNoDwlwzc1q ndaC33y+49/HsLq4mcYXfEglfhKTF9NwU1lxQmH+yHTzveTMZMrAqwj0dWQLRFephqSv ofrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:from:subject :dkim-signature:dkim-filter; bh=/w1bIAu1uE35eBnnjmkdkpZrmD4gzFMKCaktzjEiFKw=; b=PFyW/No0x5lwz99Lupdd4AXR7J2WMpE2KOO7epKoAOmWVqm8WNWhZkS919idTefxes KQn8XOyYbZ1vT5BSRyajVGZrmJSHXTZMpbsTUsAqCzuNMM4XGffqM8cj0k8q8hnaDKkm rR5TFmIBlUMmkc+dxdq0WWDtUWvN5SL3qrMvxEjHEwdec2nmMuqfie3paKwG1MyAniKG pMM/M8gYl/nw6D4x8k6KKb3L91IRdyVD5JsPLLg6jY48xgb5Ta0W4a/zC9ahabvhe23P I+ttBIQfVYky13r2dUyXmqZy00QDVwUCu2ZTmLGdVZ4yVifg7kX8nl45yjaz2aWXLLCa PvPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=dkg+2GWG; 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=linux.microsoft.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o13-20020a170906974d00b0078e11e9286csi22163120ejy.195.2022.11.02.15.09.53; Wed, 02 Nov 2022 15:10:21 -0700 (PDT) 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=@linux.microsoft.com header.s=default header.b=dkg+2GWG; 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=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231316AbiKBWIK (ORCPT + 99 others); Wed, 2 Nov 2022 18:08:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231392AbiKBWHw (ORCPT ); Wed, 2 Nov 2022 18:07:52 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6F11D101D5; Wed, 2 Nov 2022 15:07:40 -0700 (PDT) Received: from skinsburskii-cloud-desktop.internal.cloudapp.net (unknown [20.120.152.163]) by linux.microsoft.com (Postfix) with ESMTPSA id 0CA2020C333D; Wed, 2 Nov 2022 15:07:40 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 0CA2020C333D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667426860; bh=/w1bIAu1uE35eBnnjmkdkpZrmD4gzFMKCaktzjEiFKw=; h=Subject:From:Cc:Date:In-Reply-To:References:From; b=dkg+2GWGEEjIBEpdjNlPAVmvIfzWgFYbWZ7tlZ6KiJ2c6xQs604sNbUZsOPJ3IdUI quVV0ndbH7I4T0D0nF02H8a3Nakh1gPhhjLOtABbAQD+sJKyJwGBh2PRkCjTNCCbXX wECnftPwDFChfEWPegi4df+w/XtFPgEcrC/58g9I= Subject: [PATCH v2 4/4] drivers/clocksource/hyper-v: Add TSC page support for root partition From: Stanislav Kinsburskii Cc: Stanislav Kinsburskiy , "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Daniel Lezcano , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Date: Wed, 02 Nov 2022 22:07:39 +0000 Message-ID: <166742685995.205987.1519185062889413335.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> In-Reply-To: <166742670556.205987.18227942188746093700.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> References: <166742670556.205987.18227942188746093700.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-18.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,MISSING_HEADERS, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748423956121264749?= X-GMAIL-MSGID: =?utf-8?q?1748423956121264749?= From: Stanislav Kinsburskiy Microsoft Hypervisor root partition has to map the TSC page specified by the hypervisor, instead of providing the page to the hypervisor like it's done in the guest partitions. However, it's too early to map the page when the clock is initialized, so, the actual mapping is happening later. Signed-off-by: Stanislav Kinsburskiy CC: "K. Y. Srinivasan" CC: Haiyang Zhang CC: Wei Liu CC: Dexuan Cui CC: Thomas Gleixner CC: Ingo Molnar CC: Borislav Petkov CC: Dave Hansen CC: x86@kernel.org CC: "H. Peter Anvin" CC: Daniel Lezcano CC: linux-hyperv@vger.kernel.org CC: linux-kernel@vger.kernel.org --- arch/x86/hyperv/hv_init.c | 2 ++ drivers/clocksource/hyperv_timer.c | 37 +++++++++++++++++++++++++++--------- include/clocksource/hyperv_timer.h | 1 + 3 files changed, 31 insertions(+), 9 deletions(-) diff --git a/arch/x86/hyperv/hv_init.c b/arch/x86/hyperv/hv_init.c index f49bc3ec76e6..89954490af93 100644 --- a/arch/x86/hyperv/hv_init.c +++ b/arch/x86/hyperv/hv_init.c @@ -464,6 +464,8 @@ void __init hyperv_init(void) BUG_ON(!src); memcpy_to_page(pg, 0, src, HV_HYP_PAGE_SIZE); memunmap(src); + + hv_remap_tsc_clocksource(); } else { hypercall_msr.guest_physical_address = vmalloc_to_pfn(hv_hypercall_pg); wrmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); diff --git a/drivers/clocksource/hyperv_timer.c b/drivers/clocksource/hyperv_timer.c index 635c14c1e3bf..ec76303b2a76 100644 --- a/drivers/clocksource/hyperv_timer.c +++ b/drivers/clocksource/hyperv_timer.c @@ -508,9 +508,6 @@ static bool __init hv_init_tsc_clocksource(void) if (!(ms_hyperv.features & HV_MSR_REFERENCE_TSC_AVAILABLE)) return false; - if (hv_root_partition) - return false; - /* * If Hyper-V offers TSC_INVARIANT, then the virtualized TSC correctly * handles frequency and offset changes due to live migration, @@ -528,16 +525,22 @@ static bool __init hv_init_tsc_clocksource(void) } hv_read_reference_counter = read_hv_clock_tsc; - tsc_pfn = __phys_to_pfn(virt_to_phys(tsc_page)); /* - * The Hyper-V TLFS specifies to preserve the value of reserved - * bits in registers. So read the existing value, preserve the - * low order 12 bits, and add in the guest physical address - * (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 page mapping works differently in root and guest partitions. + * - In guest partition the guest PFN has to be passed to the + * hypervisor. + * - In root partition it's other way around: it has to map the PFN + * provided by the hypervisor. + * But it can't be mapped right here as it's too early and MMU isn't + * ready yet. So, we only set the enable bit here and will remap the + * page later in hv_remap_tsc_clocksource(). */ tsc_msr.as_uint64 = hv_get_register(HV_REGISTER_REFERENCE_TSC); + if (hv_root_partition) + tsc_pfn = tsc_msr.pfn; + else + tsc_pfn = __phys_to_pfn(virt_to_phys(tsc_page)); tsc_msr.enable = 1; tsc_msr.pfn = tsc_pfn; hv_set_register(HV_REGISTER_REFERENCE_TSC, tsc_msr.as_uint64); @@ -572,3 +575,19 @@ void __init hv_init_clocksource(void) hv_sched_clock_offset = hv_read_reference_counter(); hv_setup_sched_clock(read_hv_sched_clock_msr); } + +void __init hv_remap_tsc_clocksource(void) +{ + if (!(ms_hyperv.features & HV_MSR_REFERENCE_TSC_AVAILABLE)) + return; + + if (!hv_root_partition) { + WARN(1, "%s: attempt to remap TSC page in guest partition\n", + __func__); + return; + } + + tsc_page = memremap(__pfn_to_phys(tsc_pfn), sizeof(tsc_pg), MEMREMAP_WB); + if (!tsc_page) + pr_err("Failed to remap Hyper-V TSC page.\n"); +} diff --git a/include/clocksource/hyperv_timer.h b/include/clocksource/hyperv_timer.h index 3078d23faaea..783701a2102d 100644 --- a/include/clocksource/hyperv_timer.h +++ b/include/clocksource/hyperv_timer.h @@ -31,6 +31,7 @@ extern void hv_stimer_global_cleanup(void); extern void hv_stimer0_isr(void); extern void hv_init_clocksource(void); +extern void hv_remap_tsc_clocksource(void); extern unsigned long hv_get_tsc_pfn(void); extern struct ms_hyperv_tsc_page *hv_get_tsc_page(void);