Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5336879ybi; Tue, 4 Jun 2019 05:15:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqxgQfUZW/PDKb64W0tgOZ/eTyT0AmdrcJYGCR/6WZsw1KcKmZU9pOfW9oEKuQMKR43D0vAG X-Received: by 2002:a65:4b88:: with SMTP id t8mr35842919pgq.374.1559650510291; Tue, 04 Jun 2019 05:15:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559650510; cv=none; d=google.com; s=arc-20160816; b=Q5Duq83PqmbX8oXqFRx8KVYI2B8tqZ93zQoIsv9ioH4nN5OXq0hOjlJ4DhXj4Z3UCI rMQAFMUieS64QZfGH048kl3xrA0hQ5DvWV1kWlJ5PMiJj62Cs84u4Ejk429uynokcfuN I0CHFKCuHuQ1ATNoZPaDMgiSpTKl/wy6hLKlkPwgXeoH+VrewngAYS25/Fr94AdbEV1t 7stNjRV/4Fq5lIaVjJY1mDRvXuHG8JPPsK2EFGqi2AG1FbeBdlP0xokOqIwASiDycp9r MnD5h77N6TYd8X60An4pDIgpmK04W/h+7vfX8mFfM2+IB6YdmFYo8qcGPezPJ9v3wqKn lUEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=tw9Y8YMPWl78j6HAYDhDnpDfbXZsIpXWpRYZs39Kky4=; b=03JH+HfY6bqZQYXgpU31FMjcqIO1jw7sR0BnZh1BjwI/TAWugNhtTe8wFQagO+4G5r Bbyh3Vak4b0xBICm2axArg9S4Mki9qcraIBcQcpN4o8dSvaswb5UQRnPGPC4JVEGYQbr Vhj7HfwRWUCZNgdjtkQEOGhGehi1ekFoi9sPAOimR6QTcEu7kpg+WeM61ivYNuc5VX81 6N40Hm60KjNikxCxDEsVbwIvAbe/HKh8tanKUVMO9A1yt07YBycJY++1nwXjGpcKvXdE 76MozQ/v/0oaXOOwPQfDHuBY+tuIIYstixoJMl/w7HdlFqd0AAIHzJZRmSMPGWlWcyre PRMg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u4si19018237pfh.42.2019.06.04.05.14.52; Tue, 04 Jun 2019 05:15:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727652AbfFDMNZ (ORCPT + 99 others); Tue, 4 Jun 2019 08:13:25 -0400 Received: from foss.arm.com ([217.140.101.70]:41718 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726847AbfFDMNY (ORCPT ); Tue, 4 Jun 2019 08:13:24 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2DD5980D; Tue, 4 Jun 2019 05:13:24 -0700 (PDT) Received: from [10.1.196.72] (e119884-lin.cambridge.arm.com [10.1.196.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C1A9C3F690; Tue, 4 Jun 2019 05:13:20 -0700 (PDT) Subject: Re: [PATCH v6 18/19] x86: Add support for generic vDSO To: Michael Kelley , "linux-arch@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , "linux-mips@vger.kernel.org" , "linux-kselftest@vger.kernel.org" Cc: Catalin Marinas , Will Deacon , Arnd Bergmann , Russell King , Ralf Baechle , Paul Burton , Daniel Lezcano , Thomas Gleixner , Mark Salyzyn , Peter Collingbourne , Shuah Khan , Dmitry Safonov <0x7f454c46@gmail.com>, Rasmus Villemoes , Huw Davies References: <20190530141531.43462-1-vincenzo.frascino@arm.com> <20190530141531.43462-19-vincenzo.frascino@arm.com> From: Vincenzo Frascino Message-ID: <97175325-1619-fd38-2a5c-c71b3b161808@arm.com> Date: Tue, 4 Jun 2019 13:13:19 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Michael, On 30/05/2019 16:41, Michael Kelley wrote: > From: Vincenzo Frascino On Thursday, May 30, 2019 7:16 AM >> >> The x86 vDSO library requires some adaptations to take advantage of the >> newly introduced generic vDSO library. >> >> Introduce the following changes: >> - Modification of vdso.c to be compliant with the common vdso datapage >> - Use of lib/vdso for gettimeofday >> >> Cc: Thomas Gleixner >> Signed-off-by: Vincenzo Frascino >> >> >> diff --git a/arch/x86/include/asm/mshyperv-tsc.h b/arch/x86/include/asm/mshyperv-tsc.h >> new file mode 100644 >> index 000000000000..99c98ccea0bf >> --- /dev/null >> +++ b/arch/x86/include/asm/mshyperv-tsc.h >> @@ -0,0 +1,76 @@ >> +/* SPDX-License-Identifier: GPL-2.0 */ >> +#ifndef _ASM_X86_MSHYPER_TSCPAGE_H >> +#define _ASM_X86_MSHYPER_TSCPAGE_H >> + >> +#include >> + >> +#ifdef CONFIG_HYPERV_TSCPAGE >> +struct ms_hyperv_tsc_page *hv_get_tsc_page(void); >> +static inline u64 hv_read_tsc_page_tsc(const struct ms_hyperv_tsc_page *tsc_pg, >> + u64 *cur_tsc) >> +{ >> + u64 scale, offset; >> + u32 sequence; >> + >> + /* >> + * The protocol for reading Hyper-V TSC page is specified in Hypervisor >> + * Top-Level Functional Specification ver. 3.0 and above. To get the >> + * reference time we must do the following: >> + * - READ ReferenceTscSequence >> + * A special '0' value indicates the time source is unreliable and we >> + * need to use something else. The currently published specification >> + * versions (up to 4.0b) contain a mistake and wrongly claim '-1' >> + * instead of '0' as the special value, see commit c35b82ef0294. >> + * - ReferenceTime = >> + * ((RDTSC() * ReferenceTscScale) >> 64) + ReferenceTscOffset >> + * - READ ReferenceTscSequence again. In case its value has changed >> + * since our first reading we need to discard ReferenceTime and repeat >> + * the whole sequence as the hypervisor was updating the page in >> + * between. >> + */ >> + do { >> + sequence = READ_ONCE(tsc_pg->tsc_sequence); >> + if (!sequence) >> + return U64_MAX; >> + /* >> + * Make sure we read sequence before we read other values from >> + * TSC page. >> + */ >> + smp_rmb(); >> + >> + scale = READ_ONCE(tsc_pg->tsc_scale); >> + offset = READ_ONCE(tsc_pg->tsc_offset); >> + *cur_tsc = rdtsc_ordered(); >> + >> + /* >> + * Make sure we read sequence after we read all other values >> + * from TSC page. >> + */ >> + smp_rmb(); >> + >> + } while (READ_ONCE(tsc_pg->tsc_sequence) != sequence); >> + >> + return mul_u64_u64_shr(*cur_tsc, scale, 64) + offset; >> +} >> + >> +static inline u64 hv_read_tsc_page(const struct ms_hyperv_tsc_page *tsc_pg) >> +{ >> + u64 cur_tsc; >> + >> + return hv_read_tsc_page_tsc(tsc_pg, &cur_tsc); >> +} >> + >> +#else >> +static inline struct ms_hyperv_tsc_page *hv_get_tsc_page(void) >> +{ >> + return NULL; >> +} >> + >> +static inline u64 hv_read_tsc_page_tsc(const struct ms_hyperv_tsc_page *tsc_pg, >> + u64 *cur_tsc) >> +{ >> + BUG(); >> + return U64_MAX; >> +} >> +#endif >> +#endif >> diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h >> index cc60e617931c..db095a992f3e 100644 >> --- a/arch/x86/include/asm/mshyperv.h >> +++ b/arch/x86/include/asm/mshyperv.h >> @@ -7,6 +7,7 @@ >> #include >> #include >> #include >> +#include >> #include >> >> #define VP_INVAL U32_MAX >> @@ -387,73 +388,4 @@ static inline int hyperv_flush_guest_mapping_range(u64 as, >> } >> #endif /* CONFIG_HYPERV */ >> >> -#ifdef CONFIG_HYPERV_TSCPAGE >> -struct ms_hyperv_tsc_page *hv_get_tsc_page(void); >> -static inline u64 hv_read_tsc_page_tsc(const struct ms_hyperv_tsc_page *tsc_pg, >> - u64 *cur_tsc) >> -{ >> - u64 scale, offset; >> - u32 sequence; >> - >> - /* >> - * The protocol for reading Hyper-V TSC page is specified in Hypervisor >> - * Top-Level Functional Specification ver. 3.0 and above. To get the >> - * reference time we must do the following: >> - * - READ ReferenceTscSequence >> - * A special '0' value indicates the time source is unreliable and we >> - * need to use something else. The currently published specification >> - * versions (up to 4.0b) contain a mistake and wrongly claim '-1' >> - * instead of '0' as the special value, see commit c35b82ef0294. >> - * - ReferenceTime = >> - * ((RDTSC() * ReferenceTscScale) >> 64) + ReferenceTscOffset >> - * - READ ReferenceTscSequence again. In case its value has changed >> - * since our first reading we need to discard ReferenceTime and repeat >> - * the whole sequence as the hypervisor was updating the page in >> - * between. >> - */ >> - do { >> - sequence = READ_ONCE(tsc_pg->tsc_sequence); >> - if (!sequence) >> - return U64_MAX; >> - /* >> - * Make sure we read sequence before we read other values from >> - * TSC page. >> - */ >> - smp_rmb(); >> - >> - scale = READ_ONCE(tsc_pg->tsc_scale); >> - offset = READ_ONCE(tsc_pg->tsc_offset); >> - *cur_tsc = rdtsc_ordered(); >> - >> - /* >> - * Make sure we read sequence after we read all other values >> - * from TSC page. >> - */ >> - smp_rmb(); >> - >> - } while (READ_ONCE(tsc_pg->tsc_sequence) != sequence); >> - >> - return mul_u64_u64_shr(*cur_tsc, scale, 64) + offset; >> -} >> - >> -static inline u64 hv_read_tsc_page(const struct ms_hyperv_tsc_page *tsc_pg) >> -{ >> - u64 cur_tsc; >> - >> - return hv_read_tsc_page_tsc(tsc_pg, &cur_tsc); >> -} >> - >> -#else >> -static inline struct ms_hyperv_tsc_page *hv_get_tsc_page(void) >> -{ >> - return NULL; >> -} >> - >> -static inline u64 hv_read_tsc_page_tsc(const struct ms_hyperv_tsc_page *tsc_pg, >> - u64 *cur_tsc) >> -{ >> - BUG(); >> - return U64_MAX; >> -} >> -#endif >> #endif > > Vincenzo -- these changes for Hyper-V are a subset of a larger patch set > I have that moves all of the Hyper-V clock/timer code into a separate > clocksource driver in drivers/clocksource, with an include file in > includes/clocksource. That new include file should be able to work > instead of your new mshyperv-tsc.h. It also has the benefit of being > ISA neutral, so it will work with my in-progress patch set to support > Linux on Hyper-V on ARM64. See https://lkml.org/lkml/2019/5/27/231 > for the new clocksource driver patch set. > Thank you for pointing this out, I will rebase my changes on your patches. > Michael > -- Regards, Vincenzo