From nobody Sun Apr 12 02:47:03 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45CCEC19F28 for ; Wed, 3 Aug 2022 13:42:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238248AbiHCNmT (ORCPT ); Wed, 3 Aug 2022 09:42:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238150AbiHCNlx (ORCPT ); Wed, 3 Aug 2022 09:41:53 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1B3471CFFE for ; Wed, 3 Aug 2022 06:41:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659534097; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1qI/FHY/T1HazJ0T9yjqCenNeZJbi2H7HBUgnno5W+A=; b=ANqs7VaWDNCLokr7Jldxc2iqJooP2g+H96e1fiQikNoz+OLOhge8mqEqq/oBYIQ3+VbCCG xgiiW0tB4+XHJDyqz6MoDAh3GuXNT2v9n+l/YFz/mS1LWcPj8l6/Ns/W29CA2SUPJ9ZvOC mqEM5ldnYCpTMNujUEBlVo/Ugfo50CY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-547-C9jRyydoPhSRuyOHq-okAg-1; Wed, 03 Aug 2022 09:41:34 -0400 X-MC-Unique: C9jRyydoPhSRuyOHq-okAg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9728F8037B3; Wed, 3 Aug 2022 13:41:33 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id AF9A7492C3B; Wed, 3 Aug 2022 13:41:31 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Sean Christopherson Cc: Wanpeng Li , Jim Mattson , Michael Kelley , Siddharth Chandrasekaran , Yuan Yao , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v9 08/40] x86/hyperv: Introduce HV_MAX_SPARSE_VCPU_BANKS/HV_VCPUS_PER_SPARSE_BANK constants Date: Wed, 3 Aug 2022 15:40:38 +0200 Message-Id: <20220803134110.397885-9-vkuznets@redhat.com> In-Reply-To: <20220803134110.397885-1-vkuznets@redhat.com> References: <20220803134110.397885-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" It may not come clear from where the magical '64' value used in __cpumask_to_vpset() come from. Moreover, '64' means both the maximum sparse bank number as well as the number of vCPUs per bank. Add defines to make things clear. These defines are also going to be used by KVM. No functional change. Reviewed-by: Maxim Levitsky Signed-off-by: Vitaly Kuznetsov --- include/asm-generic/hyperv-tlfs.h | 5 +++++ include/asm-generic/mshyperv.h | 11 ++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/asm-generic/hyperv-tlfs.h b/include/asm-generic/hyperv= -tlfs.h index fdce7a4cfc6f..020ca9bdbb79 100644 --- a/include/asm-generic/hyperv-tlfs.h +++ b/include/asm-generic/hyperv-tlfs.h @@ -399,6 +399,11 @@ struct hv_vpset { u64 bank_contents[]; } __packed; =20 +/* The maximum number of sparse vCPU banks which can be encoded by 'struct= hv_vpset' */ +#define HV_MAX_SPARSE_VCPU_BANKS (64) +/* The number of vCPUs in one sparse bank */ +#define HV_VCPUS_PER_SPARSE_BANK (64) + /* HvCallSendSyntheticClusterIpi hypercall */ struct hv_send_ipi { u32 vector; diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index c05d2ce9b6cd..89a529093042 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -214,9 +214,10 @@ static inline int __cpumask_to_vpset(struct hv_vpset *= vpset, { int cpu, vcpu, vcpu_bank, vcpu_offset, nr_bank =3D 1; int this_cpu =3D smp_processor_id(); + int max_vcpu_bank =3D hv_max_vp_index / HV_VCPUS_PER_SPARSE_BANK; =20 - /* valid_bank_mask can represent up to 64 banks */ - if (hv_max_vp_index / 64 >=3D 64) + /* vpset.valid_bank_mask can represent up to HV_MAX_SPARSE_VCPU_BANKS ban= ks */ + if (max_vcpu_bank >=3D HV_MAX_SPARSE_VCPU_BANKS) return 0; =20 /* @@ -224,7 +225,7 @@ static inline int __cpumask_to_vpset(struct hv_vpset *v= pset, * structs are not cleared between calls, we risk flushing unneeded * vCPUs otherwise. */ - for (vcpu_bank =3D 0; vcpu_bank <=3D hv_max_vp_index / 64; vcpu_bank++) + for (vcpu_bank =3D 0; vcpu_bank <=3D max_vcpu_bank; vcpu_bank++) vpset->bank_contents[vcpu_bank] =3D 0; =20 /* @@ -236,8 +237,8 @@ static inline int __cpumask_to_vpset(struct hv_vpset *v= pset, vcpu =3D hv_cpu_number_to_vp_number(cpu); if (vcpu =3D=3D VP_INVAL) return -1; - vcpu_bank =3D vcpu / 64; - vcpu_offset =3D vcpu % 64; + vcpu_bank =3D vcpu / HV_VCPUS_PER_SPARSE_BANK; + vcpu_offset =3D vcpu % HV_VCPUS_PER_SPARSE_BANK; __set_bit(vcpu_offset, (unsigned long *) &vpset->bank_contents[vcpu_bank]); if (vcpu_bank >=3D nr_bank) --=20 2.35.3