From patchwork Mon Dec 16 00:19:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boqun Feng X-Patchwork-Id: 11293251 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 81F011593 for ; Mon, 16 Dec 2019 00:21:02 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5D47A24681 for ; Mon, 16 Dec 2019 00:21:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UCmY/B2P" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D47A24681 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ige7C-0006mV-N0; Mon, 16 Dec 2019 00:19:58 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ige7B-0006m8-FQ for xen-devel@lists.xenproject.org; Mon, 16 Dec 2019 00:19:57 +0000 X-Inumbo-ID: ca18ce18-1f99-11ea-88e7-bc764e2007e4 Received: from mail-qk1-x744.google.com (unknown [2607:f8b0:4864:20::744]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ca18ce18-1f99-11ea-88e7-bc764e2007e4; Mon, 16 Dec 2019 00:19:56 +0000 (UTC) Received: by mail-qk1-x744.google.com with SMTP id z76so889710qka.2 for ; Sun, 15 Dec 2019 16:19:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qJHTf9gLZO0OmW0oKiFiaoMPD31UWwBIv/AQO8x022Q=; b=UCmY/B2PlCGXERTqtwgVAtc2JqLgwUuUJuM66myj3BI4trxbjf3g0TnSG6nt58tAr5 b6wmX04u6YUR9eii5m+YXMa0EHZfMbtFJz9VgI+Ygal0hewZUXXIVCeMfWObhUfyF884 ccoID02pgYC30wQuv/zvjzzmDqkBrJJHen+E411WY7HJgXTj6Wx6U3NKulvnMa5Govq9 DZ478mLox8WXtHb8Ijf7WIhQI4NskICyGfTV78MMNlQTmCghtj1RoL0rAINJT9xwhXHE TFSowtCHOCjZF2GfjW67JnBz9elQipCHK+6FWG2DnYry+jvTyvmUDGnSXckYfxC8F5D2 F7yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qJHTf9gLZO0OmW0oKiFiaoMPD31UWwBIv/AQO8x022Q=; b=VOxIF20+WVull07q3Guy2LO74xKpbr/rxT49VQw8qyeK8fBZLG3+sYgCWN5xAh5Bg/ hBDGBiO7k0EfeM2+mO3NiuoIFw6756rtiaHTvx2Wz12qxiJOfi4GtdNkGljl4YS5Wnwc utEuLv6mtkNO1xYTPiWd/o92PxsBtE14yTUtHn6iZOBb9puFInfuG6X8Vc3ZHUc4Pd8D 1N0o3nGh4hiFAG6WJewzxcjRSdpfO2b8QskKTVG7TBt5n9JU8wPaGXP/H5HwXDj1/XFV VCEGTnJCo+z/O4GwLB/8fchlwcy53ts41mOwrZqz0yEbjDF407nNwQnNlLTQSnuAeHxp kVyg== X-Gm-Message-State: APjAAAXEBJdM3wUfREZiznVIxW4V3786Rzf4XYrhIekM7iJCjJNmVYlJ StLZltE4/QclcgpnrM2xrLU= X-Google-Smtp-Source: APXvYqziDt2MJepPF60CYkhXmMwNyU7utpHzVQ8iPImbF+lXkZE5ubq26nEL7jVGpgS+wAWhxEIl4A== X-Received: by 2002:a37:a70b:: with SMTP id q11mr24215846qke.393.1576455596683; Sun, 15 Dec 2019 16:19:56 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id i28sm6346240qtc.57.2019.12.15.16.19.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Dec 2019 16:19:56 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id AC2A822434; Sun, 15 Dec 2019 19:19:55 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Sun, 15 Dec 2019 19:19:55 -0500 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedufedrvddtgedgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne goufhorhhtvggutfgvtghiphdvucdlgedtmdenucfjughrpefhvffufffkofgjfhgggfes tdekredtredttdenucfhrhhomhepuehoqhhunhcuhfgvnhhguceosghoqhhunhdrfhgvnh hgsehgmhgrihhlrdgtohhmqeenucffohhmrghinheplhgushdrshgsnecukfhppeehvddr udehhedrudduuddrjedunecurfgrrhgrmhepmhgrihhlfhhrohhmpegsohhquhhnodhmvg hsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdeiledvgeehtdeigedqudejjeekheeh hedvqdgsohhquhhnrdhfvghngheppehgmhgrihhlrdgtohhmsehfihigmhgvrdhnrghmvg enucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from localhost (unknown [52.155.111.71]) by mail.messagingengine.com (Postfix) with ESMTPA id EB795306012F; Sun, 15 Dec 2019 19:19:54 -0500 (EST) From: Boqun Feng To: linux-hyperv@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Date: Mon, 16 Dec 2019 08:19:20 +0800 Message-Id: <20191216001922.23008-5-boqun.feng@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191216001922.23008-1-boqun.feng@gmail.com> References: <20191216001922.23008-1-boqun.feng@gmail.com> MIME-Version: 1.0 Subject: [Xen-devel] [RFC 4/6] arm64: vdso: hyperv: Map tsc page into vDSO if enabled X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Sasha Levin , Vincenzo Frascino , Stephen Hemminger , Greg Kroah-Hartman , Catalin Marinas , Haiyang Zhang , Michael Kelley , Alexios Zavras , Stefano Stabellini , Matteo Croce , xen-devel@lists.xenproject.org, Thomas Gleixner , "K. Y. Srinivasan" , Will Deacon , Boqun Feng , Allison Randal Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On Hyper-V, a tsc page has the data for adjusting cntvct numbers to clocksource cycles, and that's how Hyper-V guest kernel reads the clocksource. In order to allow userspace to read the same clocksource directly, the tsc page has to been mapped into userspace via vDSO. Use the framework for vDSO set-up in __vdso_init() to do this. Note: if HYPERV_TIMER=y but the kernel is using other clocksource or doesn't have the hyperv timer clocksource, tsc page will still be mapped into userspace. Signed-off-by: Boqun Feng (Microsoft) --- arch/arm64/kernel/vdso.c | 12 ++++++++++++ arch/arm64/kernel/vdso/vdso.lds.S | 12 +++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index b9b5ec7a3084..18a634987bdc 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -105,14 +106,22 @@ static int __vdso_init(enum arch_vdso_type arch_index) struct page **vdso_code_pagelist; unsigned long nr_vdso_pages; unsigned long pfn; + struct ms_hyperv_tsc_page *tsc_page; + int tsc_page_idx; if (memcmp(vdso_lookup[arch_index].vdso_code_start, "\177ELF", 4)) { pr_err("vDSO is not a valid ELF object!\n"); return -EINVAL; } + /* One vDSO data page */ vdso_lookup[arch_index].nr_vdso_data_pages = 1; + /* Grab the Hyper-V tsc page, if enabled, add one more page */ + tsc_page = hv_get_tsc_page(); + if (tsc_page) + tsc_page_idx = vdso_lookup[arch_index].nr_vdso_data_pages++; + vdso_lookup[arch_index].nr_vdso_code_pages = ( vdso_lookup[arch_index].vdso_code_end - vdso_lookup[arch_index].vdso_code_start) >> @@ -130,6 +139,9 @@ static int __vdso_init(enum arch_vdso_type arch_index) /* Grab the vDSO data page. */ vdso_pagelist[0] = phys_to_page(__pa_symbol(vdso_data)); + if (tsc_page) + vdso_pagelist[tsc_page_idx] = phys_to_page(__pa(tsc_page)); + /* Grab the vDSO code pages. */ pfn = sym_to_pfn(vdso_lookup[arch_index].vdso_code_start); diff --git a/arch/arm64/kernel/vdso/vdso.lds.S b/arch/arm64/kernel/vdso/vdso.lds.S index 7ad2d3a0cd48..e40a1f5a6d30 100644 --- a/arch/arm64/kernel/vdso/vdso.lds.S +++ b/arch/arm64/kernel/vdso/vdso.lds.S @@ -17,7 +17,17 @@ OUTPUT_ARCH(aarch64) SECTIONS { - PROVIDE(_vdso_data = . - PAGE_SIZE); + /* + * vdso data pages: + * vdso data (1 page) + * hv tsc page (1 page if enabled) + */ + PROVIDE(_vdso_data = _hvclock_page - PAGE_SIZE); +#ifdef CONFIG_HYPERV_TIMER + PROVIDE(_hvclock_page = . - PAGE_SIZE); +#else + PROVIDE(_hvclock_page = .); +#endif . = VDSO_LBASE + SIZEOF_HEADERS; .hash : { *(.hash) } :text