From patchwork Tue Nov 1 17:31:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Kinsburskii X-Patchwork-Id: 13818 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3107857wru; Tue, 1 Nov 2022 10:36:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4R4st+XF2uwPQ4UASyyJcjc71C2hT4jyLXPzn/yzj6MGPlVW5M3ny5NygqhttY59JsVUD0 X-Received: by 2002:a17:902:a502:b0:186:aed2:f69d with SMTP id s2-20020a170902a50200b00186aed2f69dmr20811126plq.46.1667324187215; Tue, 01 Nov 2022 10:36:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667324187; cv=none; d=google.com; s=arc-20160816; b=wl2dfmzkaIxFQDF6lKYQUqpHKP27HJn46MlzOyAMybg7KkIlLioZuBSvPCggrY28Em lBaTtACP9DE/WN2Z4wi81mxQOpA+k0CLEHsc38puCp/MmAoa0XHbn8hcrWnkfvbzZycL wI2idKaLlXi+UdC6crbj8OpxnvhKiLA8xSMN38bNFGlX63bXmXpYqwFb/fXFJuljqRyh MAaRcZmcx1CvR6I8KGPAxghGIxjlEIsotEmRYLfM0aW4uzu28Fn++u3fxjGLns02EMmL VIaTaYQ3kQp95zFePX5W/nPVobLnGymW2jauR+z9P6SLgwR1FNHCrF6jjIcwbuvxv1UU QPbw== 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=VzS0zv6W20Ej0nTKmhHcYF4peM529wVUYDvHRYTK7Zc=; b=S7DEzKDA4pgTX1+ORrgXeYEJNrrBMCZf8RULcmUhEvWI7d104CPdLdaHN2+EttYelp 6SK+A+J8aRpYCQlcIZ8E6bgPGL9KW/K+L5tanz2jYV8SocfqV5Zk2MTEmo46e3Z9nnOr WcVmRZ0MApza7mUgAN5N29a7qp9xKj/iS85JKiF6g+ft2lTxqRPOGfQPNufYMRp4nrS5 EmU2MZBQZVdYoNSb9FvjfdxiHBNSOMYTBjeYVOr8FvDvxWt98tNKXOHLoOSbporgd7PO MrPhRzZKreuGwWYXwBr1fSBprZs7lkYo3FdKiD3P6yt7m28/Ho7fHkZ4luRK6DCU69kI Ve7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=OyhwJotS; 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 y7-20020a17090322c700b0016dc27fb9fbsi15230243plg.117.2022.11.01.10.36.12; Tue, 01 Nov 2022 10:36:27 -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=OyhwJotS; 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 S229517AbiKARbI (ORCPT + 99 others); Tue, 1 Nov 2022 13:31:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229566AbiKARbF (ORCPT ); Tue, 1 Nov 2022 13:31:05 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id F0C1B1C12E; Tue, 1 Nov 2022 10:31:04 -0700 (PDT) Received: from skinsburskii-cloud-desktop.internal.cloudapp.net (unknown [20.120.152.163]) by linux.microsoft.com (Postfix) with ESMTPSA id BA3F720B929F; Tue, 1 Nov 2022 10:31:04 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com BA3F720B929F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667323864; bh=VzS0zv6W20Ej0nTKmhHcYF4peM529wVUYDvHRYTK7Zc=; h=Subject:From:Cc:Date:In-Reply-To:References:From; b=OyhwJotSpjmdF+Oolz000h3Z0kXNjN6e/hid2wcKbrphgqXY6so+O9uyRXTZvDsHk bz4agA5yLzbTOoB5abTL+ykPmlkTgFOYZRIo+MNGwnatX9ygaMEXpsdltXiTK2IJO+ 7VnnAPds0Vrvx7hWsYI/94joKNq4piiP0uOjusvQ= Subject: [PATCH 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: Tue, 01 Nov 2022 17:31:04 +0000 Message-ID: <166732386464.9827.16622091938453285710.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> In-Reply-To: <166732356767.9827.4925884794177179249.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> References: <166732356767.9827.4925884794177179249.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?1748316127108871044?= X-GMAIL-MSGID: =?utf-8?q?1748316127108871044?= From: Stanislav Kinsburskiy Will be used later keep the address of the remapped page for the root partition. 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 Tue Nov 1 17:31:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Kinsburskii X-Patchwork-Id: 13816 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3107523wru; Tue, 1 Nov 2022 10:35:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6lOL3Kuiz+pFZMRmEpxG7tDFFODYcu9b0a3B4m83veCmoXAznIwD+A6UWAiPV6EOHREvg8 X-Received: by 2002:a17:90b:4a04:b0:213:587b:204e with SMTP id kk4-20020a17090b4a0400b00213587b204emr21134514pjb.98.1667324144579; Tue, 01 Nov 2022 10:35:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667324144; cv=none; d=google.com; s=arc-20160816; b=UE47Hhg9nl5wYO96o8ON1SZxMewloqFkjvIfxLpzueNiHdlUhOBl/qEztBBSGFCqUh cKCVa2JMvmJLE0gdwuiFW/wbf/ZdQB9n/+kwJrupzVCiKIcHvWAXUWAbmXnjkUhEjQpM wzi9FuLL6F2vzlVLbBCz0bmMPyjeXAV+ZoRTkoBoqtl7sPpYd38YnHiWloMPmiTx03nA pR0DkkqrA+buUkNMW6RMoXJdSzMayi6WJcMZOplEqn24kc/3lDxskeb8K3WrkI+8DxQW yNug+OUyTlsueyX1rdhftbrLFLJQu4PW0/TIQvGdOdi/O3DaJN9OI5/Qpx6M4S+vuoYH f/SQ== 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=bFl7hxOTym7GqSMmVRUZEZkOBSvYSKk8SZ3l7c9kTt0=; b=XMSI14Ng3OclvBOKbN4QwC5dVcX2lkzPfusQS5iTQcnmD85+OvcJMGiBPKe8SIv6p/ 6aXhNC4L3o8tGWUi7DEMnX1KZEuSo9kzqTUjw7NGdKkdbTKZr81hRAAJqmNg0aMoniuV yxBJSFfpVRM+3mAOs4Xf9eR7Bfa/RvbMNt+Xlk/LEtQ7kV37N9F8s46MJZkkLvkWOOyB Hx4nPUsw4Bgu6aEcMds32xogXIWC0zpXON6iuVADyrNl+tO63mW3DQAXRK18sGtgiOkZ OVxTwwhJBFd7gw7mPIYOeKwejuIO9nHzcs3Ysz9jqQ18LQnzIIeu9+9iiVJmZ0rhFf7p PWpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=deE016wC; 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 mu17-20020a17090b389100b00213b01e42adsi14837758pjb.42.2022.11.01.10.35.26; Tue, 01 Nov 2022 10:35:44 -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=deE016wC; 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 S230384AbiKARbO (ORCPT + 99 others); Tue, 1 Nov 2022 13:31:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230336AbiKARbK (ORCPT ); Tue, 1 Nov 2022 13:31:10 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 37BA81C12E; Tue, 1 Nov 2022 10:31:10 -0700 (PDT) Received: from skinsburskii-cloud-desktop.internal.cloudapp.net (unknown [20.120.152.163]) by linux.microsoft.com (Postfix) with ESMTPSA id 015D020B9F80; Tue, 1 Nov 2022 10:31:10 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 015D020B9F80 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667323870; bh=bFl7hxOTym7GqSMmVRUZEZkOBSvYSKk8SZ3l7c9kTt0=; h=Subject:From:Cc:Date:In-Reply-To:References:From; b=deE016wC5+YZS1tkfB6MHf6jU2aGMN8r/UhID9NTOJTMryK/FiDlGWJs5UkTizutP 6wKGTwsglpOa2Jt1Qn+bwUopxVBWRSqUkJrw70WULOF4cnK5DeOpjphyApNwtJNPCt ziWczGn7W8uQ1zWo0OrkGg2kHrDIGD2ljKfo5fP4= Subject: [PATCH 2/4] drivers/clocksource/hyper-v: Introduce TSC MSR register structure 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: Tue, 01 Nov 2022 17:31:09 +0000 Message-ID: <166732386986.9827.12356845572628674464.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> In-Reply-To: <166732356767.9827.4925884794177179249.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> References: <166732356767.9827.4925884794177179249.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?1748316081935747927?= X-GMAIL-MSGID: =?utf-8?q?1748316081935747927?= From: Stanislav Kinsburskiy And rework the code to use it instead of the physical address. This is a cleanup and precursor patch for upcoming support for TSC page mapping into hyper-v root partition. 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 Tue Nov 1 17:31:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Kinsburskii X-Patchwork-Id: 13815 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3107451wru; Tue, 1 Nov 2022 10:35:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4U89+ClKCGK6RTUTAwViW3a0YLPLZ4/XbNUBCIjVlzlDXas8aGVZbMad/vktuOfA0xo/VF X-Received: by 2002:a63:f307:0:b0:46f:eca1:df7d with SMTP id l7-20020a63f307000000b0046feca1df7dmr4035498pgh.449.1667324136811; Tue, 01 Nov 2022 10:35:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667324136; cv=none; d=google.com; s=arc-20160816; b=a9AW1BNbL0inYP0fp+VqjNBvqLKTFgD1XfSl2BiZdWp9Shpdfi27QtRPRyQYtf0FLb TT6je0fz4DEkEvmGYAJ7iaiH2FjSgYLmmgyZtN+6GSaJW2321eU/mjVR0tXU2iJJ9ZAR y1eNlQ9KuMtHlB1B8VZy/taWLcAw9LyTLABZhm/TsQOMjM9hyQ01o65XzdkabMzUl/F2 WMVjVU9vym01i4pentU6Tcac+onbrhzk27iwKYbPrrcNp8kqHMf1rVVZoyG2GcDofp/T xynMoO/EzapbodgUl7yxHJYNtys71io3NxVeI72wzCqs8eVs7yxh6knX+NocBtzg9i8q gRwA== 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=gzbi2cZL78wkI/YYwutmnQjWwUdGs2YRrCc1CbsM23M=; b=tu2EopJxYFZDfgMelak8CVs4cZtvm/5z8z6ETeq3eaMM2V5VTzOTFOawzBNA/E5grH iwoMzqc24bkGlauBZDqS8rs13zn9/uVNBXgoIDRDBdUUn+cfCXcBrIR1jgOIO1VRi5dz G1N6RTvrL8yjrkQ3E1PzZssRKM3ukBExgJ0bi2I3nhCrfJMkr0aO0JEee1KlkwlP7qXG eN5fKh+q12y63XWtv4ZRK8/kezjB1gY8Ch/v/z/ueZ5rNYLN0ZqEr6pF7VHfr65ZnxJg /hAMyBZfvf7RxpybrXkePU1HhITZkO9iXf+vqoc9vC2MB/SL16ygX0LT3/OyTpS9LdTu CmRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Dp8fRevR; 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 w189-20020a6382c6000000b0047005e8d874si272242pgd.9.2022.11.01.10.35.23; Tue, 01 Nov 2022 10:35:36 -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=Dp8fRevR; 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 S230253AbiKARbX (ORCPT + 99 others); Tue, 1 Nov 2022 13:31:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230219AbiKARbQ (ORCPT ); Tue, 1 Nov 2022 13:31:16 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7A0821C134; Tue, 1 Nov 2022 10:31:15 -0700 (PDT) Received: from skinsburskii-cloud-desktop.internal.cloudapp.net (unknown [20.120.152.163]) by linux.microsoft.com (Postfix) with ESMTPSA id 4008D20B9F80; Tue, 1 Nov 2022 10:31:15 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4008D20B9F80 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667323875; bh=gzbi2cZL78wkI/YYwutmnQjWwUdGs2YRrCc1CbsM23M=; h=Subject:From:Cc:Date:In-Reply-To:References:From; b=Dp8fRevRUiByRldOLyNZVh3jh0kTfvjocg7HEKUIBtW5U6i32+7W9R6yp9Hp8K4Aa IEz5Ysl9V4PNsmYUWX9CrT+2gUJCmhqJ8k2/fLRLUT6jAFztmV0FuRAY3D5JiIegpV wS5aGv8KQovg4fkkfW6BNdMHQxpF7Sx7g5rH9LYM= Subject: [PATCH 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: Tue, 01 Nov 2022 17:31:15 +0000 Message-ID: <166732387510.9827.8987757583900408743.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> In-Reply-To: <166732356767.9827.4925884794177179249.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> References: <166732356767.9827.4925884794177179249.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?1748316074160833435?= X-GMAIL-MSGID: =?utf-8?q?1748316074160833435?= 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 hyper-v root partition, which address will be defined by the hypervisor and mapped into the kernel. 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 Tue Nov 1 17:31:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislav Kinsburskii X-Patchwork-Id: 13817 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3107610wru; Tue, 1 Nov 2022 10:35:56 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Nkccd3xmj23zhWzpICFA1Pij8bsvuWrAbxjfksF5ZDw/HVxdeLnHo8/gjE7vaORTm6tGd X-Received: by 2002:a05:6a00:4206:b0:56c:2e49:ca0d with SMTP id cd6-20020a056a00420600b0056c2e49ca0dmr20964524pfb.22.1667324155941; Tue, 01 Nov 2022 10:35:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667324155; cv=none; d=google.com; s=arc-20160816; b=mnoxZlcrckFI7VRBMCHkUNhSlc4UO/Ptx7x8FQ8mo1EmLdBcoIes/V2riTQOsxnWBC saCZdw9XTYQhfjOMeQNFztrPxhI7AYRHCEOqlmI0fdBDex+zqqv8Z83+s9DzoxWpWBV3 YROHmBICciX/HV3dK8GTvmE1qY0IGPQ22AfgkkO0bzne3xgPZspT5jY+fuE3de/mqhng tWnPyWAb4gLeGfakjs0AI9MF+UCQg5KTapY15bpx6Cz1Hs2hICy3o4jCWl6yWFKN5prg xnuIrvg+pi4YT9m4QqN0+lIffyJf1/iprIV3gdWq2nXSeVS9aAg+4G0KaX/jGY2+GSxD EVoA== 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=sOlQY2pUyFWi2wENkJfU10G+u5gRwNzGxceW9GYqOpg=; b=n+L2PpXmaA+xnyr+S+PfHFYr+lJaDc4cuKh/6l+BL/0+5oeUWqFSxkB43K80pMor7j p3V4EMmcD3GsQwqIgfy9mDBXynrCv5XkmRMi4FzN/DMIuX+SPAvVpNshZJBY0yuHDDdZ Aw3YY6xjjGcaWLxJA046zRI5zUN1xDpT+VQR7Clcb3/fQFaRHwSbREfu0z9KfSdFC1m+ Q+6qAC3GwrSd7VDBhkA7Zll5loJ1u8BHYAdZ0wGLxIb0PYifiSUcY6p92on4KydK6Wib EWZZQi3IMmBiOcXUuYLG7zwiVIJHbwcm+eGC5+SR7agN7d4VM7tzFqj7MCkQFez3q2WM Nm1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=GhH3juOS; 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 fu10-20020a17090ad18a00b00212e91e621csi11787248pjb.144.2022.11.01.10.35.42; Tue, 01 Nov 2022 10:35:55 -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=GhH3juOS; 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 S231169AbiKARbh (ORCPT + 99 others); Tue, 1 Nov 2022 13:31:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231132AbiKARbW (ORCPT ); Tue, 1 Nov 2022 13:31:22 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B0C0F1D31C; Tue, 1 Nov 2022 10:31:20 -0700 (PDT) Received: from skinsburskii-cloud-desktop.internal.cloudapp.net (unknown [20.120.152.163]) by linux.microsoft.com (Postfix) with ESMTPSA id 71D84205D3EB; Tue, 1 Nov 2022 10:31:20 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 71D84205D3EB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1667323880; bh=sOlQY2pUyFWi2wENkJfU10G+u5gRwNzGxceW9GYqOpg=; h=Subject:From:Cc:Date:In-Reply-To:References:From; b=GhH3juOSsp29jZ7OcIQ3lO2/LaU6A71FAtNf4jw0odfaQA3obTDa4r3TWcYI/VUES 1DcpI4yw0UeUiVgA5RCrLZRmtprO5L2OcRXsqWz8e/IkfkmJtVifwyiRRNe/KD4iTD LNcT1cU8e2ChnxXhIqIvKNZMilA+2iimbLm18JDM= Subject: [PATCH 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: Tue, 01 Nov 2022 17:31:20 +0000 Message-ID: <166732388036.9827.17503191387873469301.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> In-Reply-To: <166732356767.9827.4925884794177179249.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> References: <166732356767.9827.4925884794177179249.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?1748316094341269591?= X-GMAIL-MSGID: =?utf-8?q?1748316094341269591?= From: Stanislav Kinsburskiy It hyper-v root partition guest has to map the 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 | 34 +++++++++++++++++++++++++--------- include/clocksource/hyperv_timer.h | 1 + 3 files changed, 28 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..4118e4bc9194 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: the guest 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,16 @@ 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) + return; + + tsc_page = memremap(__pfn_to_phys(tsc_pfn), PAGE_SIZE, 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);