Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp4066908rwi; Wed, 2 Nov 2022 06:32:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM41rCJjhrv8FyGaspiuH2C9Kg6VoE3S3bgwW6SmZxKC9z3Yl5AKvB+SbSWu4uY8g7liGpZJ X-Received: by 2002:a17:907:6e90:b0:7ad:8ba7:6640 with SMTP id sh16-20020a1709076e9000b007ad8ba76640mr24477653ejc.142.1667395933919; Wed, 02 Nov 2022 06:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667395933; cv=none; d=google.com; s=arc-20160816; b=Gzh2nCZcELcY+Q9hQqjYysRDPxkILgGjkOj1RigR9A/xBwhVy/qaDSt5mA4QS1wFtA gkQ7+l1HBB8g8QFp9lG9kyqW+7Nk27kxUSj8SnkmyLm1skB7MGPTxixvj4gjOfCspYJy szUSHGJC/wIoWx0DRGvP1SavR/olooqw/X/MXrb759cKmZomhiNWa6Syr9ZpwJcfaL+F ZllJeTGhy24vjPiSJFEgvJvZsQuu3FNhAJmpc0GrvItt717DzvHWeFTYAX0xvChDCvLu akLCOH0W8A8KnueNv90Bb+cLMENSdeHMhqHSmLhhAKVZvZlnIUU+20swF/pv2/0AinLD DoZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=FYSGjCBJjK1FjuLHWeKpyY1fs1Dib8GQvBgPpz9GX5A=; b=NziH2+at83XYiNGKITUq0bu94/bqRKLiFNNlSu6ck2+P9kz4FNtorUUfc0sk5pqIf7 zG4bNE/Ik/T3QroGo2TebzUMFEHSfLO6xtPk1gLZQ2oE1AZFVdjr3XnuIxyMZT8yJ3QR KaZRapFuW74eY4d+mewCs4z9jMcAoSL99gBlkc9D9JSWL8UXrNWJoCCETSek+8qpiim/ R4UQIAlJPfSOezxQlNGOdwOPPRFvUZRXdo2aC91yhpwzPfpDOZwZV4lMGXkFRvyeFJzp o7Jd5YsskcZI5CoAYP65ZE4RFw9PSL31qI2TVp/FbwSdmF+fHXtBUF2tUgK4eezWJxR2 CqUQ== ARC-Authentication-Results: i=1; mx.google.com; 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 gt41-20020a1709072da900b0078d2a84f2f8si19086543ejc.645.2022.11.02.06.31.49; Wed, 02 Nov 2022 06:32:13 -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; 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 S230513AbiKBMpp (ORCPT + 98 others); Wed, 2 Nov 2022 08:45:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230256AbiKBMpo (ORCPT ); Wed, 2 Nov 2022 08:45:44 -0400 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E797829C9D; Wed, 2 Nov 2022 05:45:41 -0700 (PDT) Received: by mail-wm1-f47.google.com with SMTP id a11-20020a05600c2d4b00b003cf6f5fd9f1so1198780wmg.2; Wed, 02 Nov 2022 05:45:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=FYSGjCBJjK1FjuLHWeKpyY1fs1Dib8GQvBgPpz9GX5A=; b=1he3GESyidvLiL9z1hfFW5urexgMO3Ymh/FlhJNZKwE8z6ixi9MqVC+lmkKWgEOJeh On3ktN9OOIM8iOF3ViR8uDwHSMKf335KdIjx0bWvaVLae6DnIqUctaI9Ub5DmtjcfR4J pvL/9n/e1FwmMr+pFe5GWjmL0+efA5j0WJn+9ZLIAfyZcjdtjhmRd9E39mE0dvQ0xwAA W8LsCBzg/EkRtaWflO6U4UPLQ56Hr9GS9rcFJIvbwLtArH1fWv2uQRM8tkeMBXB2v4Fq ajIaTnibPrLJqeMk3nZ2NdIDmwBtJ0a3Zp/ylav8s3rBw5Ox3nfyVLs8LpwAJlrHUOEN u4Uw== X-Gm-Message-State: ACrzQf2ZxnmaJB5yc3ZkLDxhnOEZQQWH2dtkdSqd7Pr2oXTWSbkLUL3K qGHjOHuTCkn9kX53h6UsAxo= X-Received: by 2002:a05:600c:4588:b0:3c6:f8b2:dd34 with SMTP id r8-20020a05600c458800b003c6f8b2dd34mr25239602wmo.178.1667393140347; Wed, 02 Nov 2022 05:45:40 -0700 (PDT) Received: from liuwe-devbox-debian-v2 ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id m36-20020a05600c3b2400b003cf47556f21sm2258584wms.2.2022.11.02.05.45.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 05:45:39 -0700 (PDT) Date: Wed, 2 Nov 2022 12:45:32 +0000 From: Wei Liu To: 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 Subject: Re: [PATCH 3/4] drivers/clocksource/hyper-v: Use TSC PFN getter to map vvar page Message-ID: References: <166732356767.9827.4925884794177179249.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> <166732387510.9827.8987757583900408743.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <166732387510.9827.8987757583900408743.stgit@skinsburskii-cloud-desktop.internal.cloudapp.net> X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no 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 On Tue, Nov 01, 2022 at 05:31:15PM +0000, Stanislav Kinsburskii wrote: > 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 Please use "Microsoft Hypervisor" instead of "hyper-v". Also, it should be "Hyper-V" not "hyper-v" in the future. > 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); hv_get_tsc_pfn() can return 0. You will insert PFN 0 into the page table. I think you should check if the PFN is valid. > } 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; > >