Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6419C28CBC for ; Wed, 6 May 2020 09:38:01 +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 7722E2075E for ; Wed, 6 May 2020 09:38:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=xen.org header.i=@xen.org header.b="ljaSZaEW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7722E2075E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org Authentication-Results: mail.kernel.org; spf=pass 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.92) (envelope-from ) id 1jWGUw-0007eW-IV; Wed, 06 May 2020 09:37:50 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jWGUu-0007eJ-Oj for xen-devel@lists.xenproject.org; Wed, 06 May 2020 09:37:48 +0000 X-Inumbo-ID: 3f51dbe0-8f7d-11ea-9e29-12813bfff9fa Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 3f51dbe0-8f7d-11ea-9e29-12813bfff9fa; Wed, 06 May 2020 09:37:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=AiuIkPHt3//36IVZTKF7/3+gbZ6ov+Qa2jsC3AwA2hA=; b=ljaSZaEWRBJ7gqe4JfVcfMe6j9 guPjBgeZrrxnVC4blPUKfxmcwOV7hkYOk/idRCcKewjpACaAbEigAfErkEwMUgQFXs97dJjQdn2+A SKSvifHsjknlPRs7GhIYwL56fRMoUcktEO/TxAaYTNpZ2MaNA2RwcahX69U7fz5MJUgY=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jWGUs-0000mz-MC; Wed, 06 May 2020 09:37:46 +0000 Received: from 44.142.6.51.dyn.plus.net ([51.6.142.44] helo=debian) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1jWGUs-0008PF-Db; Wed, 06 May 2020 09:37:46 +0000 Date: Wed, 6 May 2020 10:37:43 +0100 From: Wei Liu To: Roger Pau =?utf-8?B?TW9ubsOp?= Subject: Re: [PATCH] x86/hyperv: stash and use the configured max VP index Message-ID: <20200506093743.ztkvh5fwv2c4hw2r@debian> References: <20200429104144.17816-1-liuwe@microsoft.com> <20200429114718.zclpy6r6sbxuo6ph@liuwe-devbox-debian-v2.j3c5onc20sse1dnehy4noqpfcg.zx.internal.cloudapp.net> <20200430101558.GA28601@Air-de-Roger> <20200430102118.GB28601@Air-de-Roger> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200430102118.GB28601@Air-de-Roger> User-Agent: NeoMutt/20180716 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Wei Liu , Wei Liu , Paul Durrant , Andrew Cooper , Michael Kelley , Jan Beulich , Xen Development List Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" On Thu, Apr 30, 2020 at 12:21:18PM +0200, Roger Pau Monné wrote: > On Thu, Apr 30, 2020 at 12:15:58PM +0200, Roger Pau Monné wrote: > > On Wed, Apr 29, 2020 at 11:47:18AM +0000, Wei Liu wrote: > > > On Wed, Apr 29, 2020 at 11:41:44AM +0100, Wei Liu wrote: > > > > The value returned from CPUID is the maximum number for virtual > > > > processors supported by Hyper-V. It could be larger than the maximum > > > > number of virtual processors configured. > > > > > > > > Stash the configured number into a variable and use it in calculations. > > > > > > > > Signed-off-by: Wei Liu > > > > --- > > > > xen/arch/x86/guest/hyperv/hyperv.c | 4 ++++ > > > > xen/arch/x86/guest/hyperv/private.h | 1 + > > > > xen/arch/x86/guest/hyperv/tlb.c | 2 +- > > > > xen/arch/x86/guest/hyperv/util.c | 2 +- > > > > 4 files changed, 7 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/xen/arch/x86/guest/hyperv/hyperv.c b/xen/arch/x86/guest/hyperv/hyperv.c > > > > index 91a6782cd986..84221b751453 100644 > > > > --- a/xen/arch/x86/guest/hyperv/hyperv.c > > > > +++ b/xen/arch/x86/guest/hyperv/hyperv.c > > > > @@ -33,6 +33,7 @@ DEFINE_PER_CPU_READ_MOSTLY(void *, hv_input_page); > > > > DEFINE_PER_CPU_READ_MOSTLY(void *, hv_vp_assist); > > > > DEFINE_PER_CPU_READ_MOSTLY(unsigned int, hv_vp_index); > > > > > > > > +unsigned int __read_mostly hv_max_vp_index; > > > > static bool __read_mostly hcall_page_ready; > > > > > > > > static uint64_t generate_guest_id(void) > > > > @@ -143,6 +144,9 @@ static int setup_hypercall_pcpu_arg(void) > > > > rdmsrl(HV_X64_MSR_VP_INDEX, vp_index_msr); > > > > this_cpu(hv_vp_index) = vp_index_msr; > > > > > > > > + if ( vp_index_msr > hv_max_vp_index ) > > > > + hv_max_vp_index = vp_index_msr; > > > > + > > > > return 0; > > > > } > > > > > > > > diff --git a/xen/arch/x86/guest/hyperv/private.h b/xen/arch/x86/guest/hyperv/private.h > > > > index 354fc7f685a7..fea3e291e944 100644 > > > > --- a/xen/arch/x86/guest/hyperv/private.h > > > > +++ b/xen/arch/x86/guest/hyperv/private.h > > > > @@ -28,6 +28,7 @@ > > > > DECLARE_PER_CPU(void *, hv_input_page); > > > > DECLARE_PER_CPU(void *, hv_vp_assist); > > > > DECLARE_PER_CPU(unsigned int, hv_vp_index); > > > > +extern unsigned int hv_max_vp_index; > > > > > > > > static inline unsigned int hv_vp_index(unsigned int cpu) > > > > { > > > > diff --git a/xen/arch/x86/guest/hyperv/tlb.c b/xen/arch/x86/guest/hyperv/tlb.c > > > > index 1d723d6ee679..0a44071481bd 100644 > > > > --- a/xen/arch/x86/guest/hyperv/tlb.c > > > > +++ b/xen/arch/x86/guest/hyperv/tlb.c > > > > @@ -166,7 +166,7 @@ int hyperv_flush_tlb(const cpumask_t *mask, const void *va, > > > > { > > > > unsigned int vpid = hv_vp_index(cpu); > > > > > > > > - if ( vpid >= ms_hyperv.max_vp_index ) > > > > + if ( vpid >= hv_max_vp_index ) > > > > > > I think the >= should be changed to > here. > > > > I agree. With this fixed: > > > > Reviewed-by: Roger Pau Monné > > FWIW, I think it should also be nice to add an ASSERT_UNREACHABLE in > the if body, as now it shouldn't be possible for vpid to be greater > than hv_max_vp_index unless something has gone really wrong? At some point I will initialise vpid to (uint32_t)-1 so it could go over hv_max_vp_index if there is a bug in code. Wei. > > Roger.