From patchwork Tue Nov 1 14:53:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 13704 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3020643wru; Tue, 1 Nov 2022 07:58:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM70VYJJky/TfJ2wCPIPGJejvf3zlC2zNJoNSJvWkHp4MLPZeLs5NQjk3830Oui7XrG7Qnf9 X-Received: by 2002:a17:907:97d6:b0:7ad:b962:33e8 with SMTP id js22-20020a17090797d600b007adb96233e8mr16388934ejc.27.1667314679747; Tue, 01 Nov 2022 07:57:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667314679; cv=none; d=google.com; s=arc-20160816; b=EwdHxiRVAcaZhpP+L04vhkj/1dWS+ksyCgktp6Di0Lzn4jsy+4wOg8+jzIrSiSB7tm EUyH4OidXhnhfivgDIVGCdQ1yzoI4GcX4dM/6AjBmD+drIzY5EL1ZbL9P6x72ZmayKsJ x0icn/DYiTe8U8WrBLQjAKTX9ceLLwuf4z6eG0gMJDm8cEEdpzN4H7VRuny2BmJjWGgT 7sH9BjlAwku+aIWpTPpUJxGEWLM5bdDC6XSxbapduK2Md36iuJidCqbWRzZubChJqa5m IAEZgO6/f+9WZ01nc+rJ4uUBpjZUAmMhfTd/Qc/iHTv8GORXPQdnFUqYD9iCmQemnAK7 zTxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IPqmbtMjqZfKzFP9MzV66ZQWszXNyLlaAaOh0M/Oekw=; b=wTio3jpHBnBK/aRfOfTYlt1cLa1V3/yb7Bxjjp/5fiLNVxdjMnWcSljmiz6PJw7wUC s1ZxJZiH9UGi1Dw8WL6u/MZMFN8VTs6i8zEbtOnXkMpqewE69LolgN3A43+WloUAI+6o eLLMXZyV9/L64PQI/9wCPp9NclCui+aNFkTylvcWkC28RmsTBFfD+fNYa9ymFrU5c9qE qAI4IfjNXp+IQG6mrEoXp9wSDa79BGxU+ERut0to2fvA48MaJPr8wppOBq1sa0klk7iA H6kRVM+jf4BboE+cDVC6X3qyNAv+6abzvEKjOhzojUenLA1T8gua5BxvX/Bs1nxqwYsa oi2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IRcY+6Ga; 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=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w4-20020a05640234c400b0045807f73ad5si13835063edc.570.2022.11.01.07.57.34; Tue, 01 Nov 2022 07:57:59 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IRcY+6Ga; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231195AbiKAO4t (ORCPT + 99 others); Tue, 1 Nov 2022 10:56:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230515AbiKAO4P (ORCPT ); Tue, 1 Nov 2022 10:56:15 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52FDBA190 for ; Tue, 1 Nov 2022 07:55:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667314515; 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=IPqmbtMjqZfKzFP9MzV66ZQWszXNyLlaAaOh0M/Oekw=; b=IRcY+6GaeRsH8S2wNtyW4qIFDE5vB7zQwtSAwx3YacYjBaAMe62nQ4gqizPVxWAffTokHn yC/3U5DCQQB1IVPo1Wsrpvjhj0MC2YAfsBISMQsYveznpY+BM6qHp/m1S4ydcUbbnBFE+L QxSypym73xiNe0Eei7UeDOlDazo0Daw= 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-384-uuksaXBWPvG563I_gITtwQ-1; Tue, 01 Nov 2022 10:55:11 -0400 X-MC-Unique: uuksaXBWPvG563I_gITtwQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3EA4F803D4A; Tue, 1 Nov 2022 14:55:10 +0000 (UTC) Received: from ovpn-194-149.brq.redhat.com (ovpn-194-149.brq.redhat.com [10.40.194.149]) by smtp.corp.redhat.com (Postfix) with ESMTP id C89C1C15BA5; Tue, 1 Nov 2022 14:55:07 +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 v13 15/48] KVM: x86: hyper-v: Use HV_MAX_SPARSE_VCPU_BANKS/HV_VCPUS_PER_SPARSE_BANK instead of raw '64' Date: Tue, 1 Nov 2022 15:53:53 +0100 Message-Id: <20221101145426.251680-16-vkuznets@redhat.com> In-Reply-To: <20221101145426.251680-1-vkuznets@redhat.com> References: <20221101145426.251680-1-vkuznets@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748306157653542646?= X-GMAIL-MSGID: =?utf-8?q?1748306157653542646?= It may not be clear from where the '64' limit for the maximum sparse bank number comes from, use HV_MAX_SPARSE_VCPU_BANKS define instead. Use HV_VCPUS_PER_SPARSE_BANK in KVM_HV_MAX_SPARSE_VCPU_SET_BITS's definition. Opportunistically adjust the comment around BUILD_BUG_ON(). No functional change. Suggested-by: Sean Christopherson Reviewed-by: Maxim Levitsky Reviewed-by: Sean Christopherson Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/hyperv.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index cb145987f5b8..2fceb85687c1 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -40,7 +40,7 @@ #include "irq.h" #include "fpu.h" -#define KVM_HV_MAX_SPARSE_VCPU_SET_BITS DIV_ROUND_UP(KVM_MAX_VCPUS, 64) +#define KVM_HV_MAX_SPARSE_VCPU_SET_BITS DIV_ROUND_UP(KVM_MAX_VCPUS, HV_VCPUS_PER_SPARSE_BANK) static void stimer_mark_pending(struct kvm_vcpu_hv_stimer *stimer, bool vcpu_kick); @@ -1793,7 +1793,7 @@ static u64 kvm_get_sparse_vp_set(struct kvm *kvm, struct kvm_hv_hcall *hc, u64 *sparse_banks, int consumed_xmm_halves, gpa_t offset) { - if (hc->var_cnt > 64) + if (hc->var_cnt > HV_MAX_SPARSE_VCPU_BANKS) return -EINVAL; /* Cap var_cnt to ignore banks that cannot contain a legal VP index. */ @@ -1902,12 +1902,11 @@ static u64 kvm_hv_flush_tlb(struct kvm_vcpu *vcpu, struct kvm_hv_hcall *hc) gpa_t data_offset; /* - * The Hyper-V TLFS doesn't allow more than 64 sparse banks, e.g. the - * valid mask is a u64. Fail the build if KVM's max allowed number of - * vCPUs (>4096) would exceed this limit, KVM will additional changes - * for Hyper-V support to avoid setting the guest up to fail. + * The Hyper-V TLFS doesn't allow more than HV_MAX_SPARSE_VCPU_BANKS + * sparse banks. Fail the build if KVM's max allowed number of + * vCPUs (>4096) exceeds this limit. */ - BUILD_BUG_ON(KVM_HV_MAX_SPARSE_VCPU_SET_BITS > 64); + BUILD_BUG_ON(KVM_HV_MAX_SPARSE_VCPU_SET_BITS > HV_MAX_SPARSE_VCPU_BANKS); /* * 'Slow' hypercall's first parameter is the address in guest's memory